diff --git a/src/snmalloc/mem/localalloc.h b/src/snmalloc/mem/localalloc.h index 236be946a..664f2ba2e 100644 --- a/src/snmalloc/mem/localalloc.h +++ b/src/snmalloc/mem/localalloc.h @@ -768,6 +768,9 @@ namespace snmalloc #ifdef SNMALLOC_PASS_THROUGH return external_alloc::malloc_usable_size(const_cast(p_raw)); #else + + if (SecondaryAllocator::has_secondary_ownership(p_raw)) + return SecondaryAllocator::alloc_size(p_raw); // TODO What's the domestication policy here? At the moment we just // probe the pagemap with the raw address, without checks. There could // be implicit domestication through the `Config::Pagemap` or diff --git a/src/snmalloc/mem/secondary/default.h b/src/snmalloc/mem/secondary/default.h index a0cbcd5b6..d4a272a4d 100644 --- a/src/snmalloc/mem/secondary/default.h +++ b/src/snmalloc/mem/secondary/default.h @@ -32,9 +32,18 @@ namespace snmalloc } SNMALLOC_FAST_PATH - static bool has_secondary_ownership([[maybe_unused]] void* pointer) + static bool has_secondary_ownership([[maybe_unused]] const void* pointer) { return false; } + + SNMALLOC_FAST_PATH + static size_t alloc_size([[maybe_unused]] const void* pointer) + { + SNMALLOC_ASSERT( + false && + "secondary alloc_size should never be invoked with default setup"); + return 0; + } }; } // namespace snmalloc diff --git a/src/snmalloc/mem/secondary/gwp_asan.h b/src/snmalloc/mem/secondary/gwp_asan.h index a0bce0c0f..0d50e91d0 100644 --- a/src/snmalloc/mem/secondary/gwp_asan.h +++ b/src/snmalloc/mem/secondary/gwp_asan.h @@ -14,11 +14,6 @@ namespace snmalloc static inline gwp_asan::GuardedPoolAllocator singleton; static inline size_t max_allocation_size; - static gwp_asan::GuardedPoolAllocator& get() - { - return singleton; - } - public: static void initialize() noexcept { @@ -38,13 +33,12 @@ namespace snmalloc SNMALLOC_FAST_PATH static void* allocate(size_t size) { - auto& inner = get(); - if (SNMALLOC_UNLIKELY(inner.shouldSample())) + if (SNMALLOC_UNLIKELY(singleton.shouldSample())) { if (size > max_allocation_size) return nullptr; auto alignment = natural_alignment(size); - return get().allocate(size, alignment); + return singleton.allocate(size, alignment); } return nullptr; } @@ -55,19 +49,24 @@ namespace snmalloc if (SNMALLOC_LIKELY(pointer == nullptr)) return; - auto& inner = get(); snmalloc_check_client( mitigations(sanity_checks), - inner.pointerIsMine(pointer), + singleton.pointerIsMine(pointer), "Not allocated by snmalloc or secondary allocator"); - inner.deallocate(pointer); + singleton.deallocate(pointer); + } + + SNMALLOC_FAST_PATH + static bool has_secondary_ownership([[maybe_unused]] const void* pointer) + { + return singleton.pointerIsMine(pointer); } SNMALLOC_FAST_PATH - static bool has_secondary_ownership([[maybe_unused]] void* pointer) + static size_t alloc_size(const void* pointer) { - return get().pointerIsMine(pointer); + return singleton.getSize(pointer); } }; } // namespace snmalloc