diff --git a/src/mem/alloc.h b/src/mem/alloc.h index a344ec8..1abe554 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -445,7 +445,7 @@ namespace snmalloc } else if (size == PMMediumslab) { - Mediumslab* slab = (Mediumslab*)super; + Mediumslab* slab = Mediumslab::get(p); RemoteAllocator* target = slab->get_allocator(); // Reading a remote sizeclass won't fail, since the other allocator @@ -460,7 +460,7 @@ namespace snmalloc } # ifndef SNMALLOC_SAFE_CLIENT - if (size > 64 || (void*)super != p) + if (size > 64 || (uintptr_t)super != (uintptr_t)p) { error("Not deallocating start of an object"); } @@ -491,7 +491,7 @@ namespace snmalloc } else if (size == PMMediumslab) { - Mediumslab* slab = (Mediumslab*)super; + Mediumslab* slab = Mediumslab::get(p); uint8_t sc = slab->get_sizeclass(); size_t slab_end = (size_t)slab + SUPERSLAB_SIZE; @@ -550,11 +550,9 @@ namespace snmalloc } else if (size == PMMediumslab) { - Superslab* super = Superslab::get(p); + Mediumslab * slab = Mediumslab::get(p); // Reading a remote sizeclass won't fail, since the other allocator // can't reuse the slab, as we have no yet deallocated this pointer. - Mediumslab* slab = (Mediumslab*)super; - return sizeclass_to_size(slab->get_sizeclass()); } @@ -972,7 +970,7 @@ namespace snmalloc SlabLink* link = sc->get_head(); Slab* slab; - if (link != (SlabLink*)~0) + if ((uintptr_t)link != ~0ULL) { slab = link->get_slab(); } diff --git a/src/mem/allocconfig.h b/src/mem/allocconfig.h index ec38b90..48c0552 100644 --- a/src/mem/allocconfig.h +++ b/src/mem/allocconfig.h @@ -84,6 +84,8 @@ namespace snmalloc ; // The remaining values are derived, not configurable. + static constexpr size_t POINTER_BITS = + bits::next_pow2_bits_const(sizeof(uintptr_t)); // Used to isolate values on cache lines to prevent false sharing. static constexpr size_t CACHELINE_SIZE = 64; diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index 6ac38cf..de01af4 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -67,8 +67,8 @@ namespace snmalloc if (size < SUPERSLAB_SIZE) error("out of memory"); - ((PAL*)this)->template notify_using(r, OS_PAGE_SIZE); - + PAL::template notify_using(r, OS_PAGE_SIZE); + bump = (size_t)r; remaining = size; } @@ -166,8 +166,7 @@ namespace snmalloc auto page_start = bits::align_down((size_t)p, OS_PAGE_SIZE); auto page_end = bits::align_up((size_t)p + size, OS_PAGE_SIZE); - ((PAL*)this) - ->template notify_using( + PAL::template notify_using( (void*)page_start, page_end - page_start); return p; diff --git a/src/override/malloc.cc b/src/override/malloc.cc index 18ddab6..ce4973e 100644 --- a/src/override/malloc.cc +++ b/src/override/malloc.cc @@ -158,7 +158,7 @@ extern "C" void** memptr, size_t alignment, size_t size) { if ( - ((alignment % sizeof(void*)) != 0) || + ((alignment % sizeof(uintptr_t)) != 0) || ((alignment & (alignment - 1)) != 0) || (alignment == 0)) { return EINVAL;