From 08344cfa94fd4d8ca351f2db315f498264d3ae48 Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Fri, 5 Mar 2021 16:52:40 +0000 Subject: [PATCH] NFC: external_pointer s/size/chunkmap_slab_kind/ While here, SNMALLOC_ASSERT() that large allocs end up with sensible slab kind values. --- src/mem/alloc.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 35184b3..e6ea74d 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -363,10 +363,10 @@ namespace snmalloc error("Unsupported"); UNUSED(p); #else - uint8_t size = ChunkMap::get(address_cast(p)); + uint8_t chunkmap_slab_kind = ChunkMap::get(address_cast(p)); Superslab* super = Superslab::get(p); - if (size == CMSuperslab) + if (chunkmap_slab_kind == CMSuperslab) { Slab* slab = Metaslab::get_slab(p); Metaslab& meta = super->get_meta(slab); @@ -376,7 +376,7 @@ namespace snmalloc return external_pointer(p, sc, slab_end); } - if (size == CMMediumslab) + if (chunkmap_slab_kind == CMMediumslab) { Mediumslab* slab = Mediumslab::get(p); @@ -388,17 +388,17 @@ namespace snmalloc auto ss = super; - while (size >= CMLargeRangeMin) + while (chunkmap_slab_kind >= CMLargeRangeMin) { // This is a large alloc redirect. ss = pointer_offset_signed( ss, -(static_cast(1) - << (size - CMLargeRangeMin + SUPERSLAB_BITS))); - size = ChunkMap::get(ss); + << (chunkmap_slab_kind - CMLargeRangeMin + SUPERSLAB_BITS))); + chunkmap_slab_kind = ChunkMap::get(ss); } - if (size == 0) + if (chunkmap_slab_kind == CMNotOurs) { if constexpr ((location == End) || (location == OnePastEnd)) // We don't know the End, so return MAX_PTR @@ -408,13 +408,17 @@ namespace snmalloc return nullptr; } + SNMALLOC_ASSERT( + (chunkmap_slab_kind >= CMLargeMin) && + (chunkmap_slab_kind <= CMLargeMax)); + // This is a large alloc, mask off to the slab size. if constexpr (location == Start) return ss; else if constexpr (location == End) - return pointer_offset(ss, (bits::one_at_bit(size)) - 1); + return pointer_offset(ss, (bits::one_at_bit(chunkmap_slab_kind)) - 1); else - return pointer_offset(ss, bits::one_at_bit(size)); + return pointer_offset(ss, bits::one_at_bit(chunkmap_slab_kind)); #endif }