special case division for page size slabs

pull/50/head
Daniel Micay 2018-08-25 15:21:50 -04:00
parent ec78add6ab
commit 4777ee0c85
1 changed files with 6 additions and 1 deletions

View File

@ -292,7 +292,12 @@ static void *get_slab(struct size_class *c, size_t slab_size, struct slab_metada
static struct slab_metadata *get_metadata(struct size_class *c, size_t slab_size, void *p) { static struct slab_metadata *get_metadata(struct size_class *c, size_t slab_size, void *p) {
size_t offset = (char *)p - (char *)c->class_region_start; size_t offset = (char *)p - (char *)c->class_region_start;
size_t index = offset / slab_size; size_t index;
if (slab_size == PAGE_SIZE) {
index = offset >> PAGE_SHIFT;
} else {
index = offset / slab_size;
}
// still caught without this check either as a read access violation or "double free" // still caught without this check either as a read access violation or "double free"
if (index >= c->metadata_allocated) { if (index >= c->metadata_allocated) {
fatal_error("invalid free within a slab yet to be used"); fatal_error("invalid free within a slab yet to be used");