diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h --- a/compiler-rt/lib/scudo/standalone/combined.h +++ b/compiler-rt/lib/scudo/standalone/combined.h @@ -330,8 +330,6 @@ #ifdef GWP_ASAN_HOOKS if (UNLIKELY(GuardedAlloc.shouldSample())) { if (void *Ptr = GuardedAlloc.allocate(Size, Alignment)) { - if (UNLIKELY(&__scudo_allocate_hook)) - __scudo_allocate_hook(Ptr, Size); Stats.lock(); Stats.add(StatAllocated, GuardedAllocSlotSize); Stats.sub(StatFree, GuardedAllocSlotSize); @@ -536,9 +534,6 @@ Chunk::SizeOrUnusedBytesMask; Chunk::storeHeader(Cookie, Ptr, &Header); - if (UNLIKELY(&__scudo_allocate_hook)) - __scudo_allocate_hook(TaggedPtr, Size); - return TaggedPtr; } @@ -552,9 +547,6 @@ // being destroyed properly. Any other heap operation will do a full init. initThreadMaybe(/*MinimalInit=*/true); - if (UNLIKELY(&__scudo_deallocate_hook)) - __scudo_deallocate_hook(Ptr); - if (UNLIKELY(!Ptr)) return; @@ -698,8 +690,6 @@ void *NewPtr = allocate(NewSize, Chunk::Origin::Malloc, Alignment); if (LIKELY(NewPtr)) { memcpy(NewPtr, OldTaggedPtr, Min(NewSize, OldSize)); - if (UNLIKELY(&__scudo_deallocate_hook)) - __scudo_deallocate_hook(OldTaggedPtr); quarantineOrDeallocateChunk(Options, OldTaggedPtr, &OldHeader, OldSize); } return NewPtr; diff --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt @@ -131,11 +131,3 @@ add_scudo_unittest(ScudoCxxUnitTest SOURCES ${SCUDO_CXX_UNIT_TEST_SOURCES} ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers RTScudoStandaloneCxxWrappers) - -set(SCUDO_HOOKS_UNIT_TEST_SOURCES - scudo_hooks_test.cpp - scudo_unit_test_main.cpp - ) - -add_scudo_unittest(ScudoHooksUnitTest - SOURCES ${SCUDO_HOOKS_UNIT_TEST_SOURCES}) diff --git a/compiler-rt/lib/scudo/standalone/tests/scudo_hooks_test.cpp b/compiler-rt/lib/scudo/standalone/tests/scudo_hooks_test.cpp deleted file mode 100644 --- a/compiler-rt/lib/scudo/standalone/tests/scudo_hooks_test.cpp +++ /dev/null @@ -1,114 +0,0 @@ -//===-- scudo_hooks_test.cpp ------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "tests/scudo_unit_test.h" - -#include "allocator_config.h" -#include "combined.h" - -namespace { -void *LastAllocatedPtr = nullptr; -size_t LastRequestSize = 0; -void *LastDeallocatedPtr = nullptr; -} // namespace - -// Scudo defines weak symbols that can be defined by a client binary -// to register callbacks at key points in the allocation timeline. In -// order to enforce those invariants, we provide definitions that -// update some global state every time they are called, so that tests -// can inspect their effects. An unfortunate side effect of this -// setup is that because those symbols are part of the binary, they -// can't be selectively enabled; that means that they will get called -// on unrelated tests in the same compilation unit. To mitigate this -// issue, we insulate those tests in a separate compilation unit. -extern "C" { -__attribute__((visibility("default"))) void __scudo_allocate_hook(void *Ptr, - size_t Size) { - LastAllocatedPtr = Ptr; - LastRequestSize = Size; -} -__attribute__((visibility("default"))) void __scudo_deallocate_hook(void *Ptr) { - LastDeallocatedPtr = Ptr; -} -} - -// Simple check that allocation callbacks, when registered, are called: -// 1) __scudo_allocate_hook is called when allocating. -// 2) __scudo_deallocate_hook is called when deallocating. -// 3) Both hooks are called when reallocating. -// 4) Neither are called for a no-op reallocation. -TEST(ScudoHooksTest, AllocateHooks) { - scudo::Allocator Allocator; - constexpr scudo::uptr DefaultSize = 16U; - constexpr scudo::Chunk::Origin Origin = scudo::Chunk::Origin::Malloc; - - // Simple allocation and deallocation. - { - LastAllocatedPtr = nullptr; - LastRequestSize = 0; - - void *Ptr = Allocator.allocate(DefaultSize, Origin); - - EXPECT_EQ(Ptr, LastAllocatedPtr); - EXPECT_EQ(DefaultSize, LastRequestSize); - - LastDeallocatedPtr = nullptr; - - Allocator.deallocate(Ptr, Origin); - - EXPECT_EQ(Ptr, LastDeallocatedPtr); - } - - // Simple no-op, same size reallocation. - { - void *Ptr = Allocator.allocate(DefaultSize, Origin); - - LastAllocatedPtr = nullptr; - LastRequestSize = 0; - LastDeallocatedPtr = nullptr; - - void *NewPtr = Allocator.reallocate(Ptr, DefaultSize); - - EXPECT_EQ(Ptr, NewPtr); - EXPECT_EQ(nullptr, LastAllocatedPtr); - EXPECT_EQ(0U, LastRequestSize); - EXPECT_EQ(nullptr, LastDeallocatedPtr); - } - - // Reallocation in increasing size classes. This ensures that at - // least one of the reallocations will be meaningful. - { - void *Ptr = Allocator.allocate(0, Origin); - - for (scudo::uptr ClassId = 1U; - ClassId <= scudo::DefaultConfig::Primary::SizeClassMap::LargestClassId; - ++ClassId) { - const scudo::uptr Size = - scudo::DefaultConfig::Primary::SizeClassMap::getSizeByClassId( - ClassId); - - LastAllocatedPtr = nullptr; - LastRequestSize = 0; - LastDeallocatedPtr = nullptr; - - void *NewPtr = Allocator.reallocate(Ptr, Size); - - if (NewPtr != Ptr) { - EXPECT_EQ(NewPtr, LastAllocatedPtr); - EXPECT_EQ(Size, LastRequestSize); - EXPECT_EQ(Ptr, LastDeallocatedPtr); - } else { - EXPECT_EQ(nullptr, LastAllocatedPtr); - EXPECT_EQ(0U, LastRequestSize); - EXPECT_EQ(nullptr, LastDeallocatedPtr); - } - - Ptr = NewPtr; - } - } -} diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp @@ -20,6 +20,16 @@ #define __GLIBC_PREREQ(x, y) 0 #endif +struct AllocContext { + void *Ptr; + size_t Size; +}; +struct DeallocContext { + void *Ptr; +}; +static AllocContext AC; +static DeallocContext DC; + extern "C" { void malloc_enable(void); void malloc_disable(void); @@ -28,6 +38,15 @@ void *arg); void *valloc(size_t size); void *pvalloc(size_t size); + +__attribute__((visibility("default"))) void __scudo_allocate_hook(void *Ptr, + size_t Size) { + AC.Ptr = Ptr; + AC.Size = Size; +} +__attribute__((visibility("default"))) void __scudo_deallocate_hook(void *Ptr) { + DC.Ptr = Ptr; +} } // Note that every C allocation function in the test binary will be fulfilled @@ -47,6 +66,8 @@ EXPECT_NE(P, nullptr); EXPECT_LE(Size, malloc_usable_size(P)); EXPECT_EQ(reinterpret_cast(P) % FIRST_32_SECOND_64(8U, 16U), 0U); + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(Size, AC.Size); // An update to this warning in Clang now triggers in this line, but it's ok // because the check is expecting a bad pointer and should fail. @@ -61,6 +82,7 @@ #endif free(P); + EXPECT_EQ(P, DC.Ptr); EXPECT_DEATH(free(P), ""); P = malloc(0U); @@ -76,9 +98,12 @@ void *P = calloc(1U, Size); EXPECT_NE(P, nullptr); EXPECT_LE(Size, malloc_usable_size(P)); + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(Size, AC.Size); for (size_t I = 0; I < Size; I++) EXPECT_EQ((reinterpret_cast(P))[I], 0U); free(P); + EXPECT_EQ(P, DC.Ptr); P = calloc(1U, 0U); EXPECT_NE(P, nullptr); @@ -120,14 +145,20 @@ EXPECT_NE(P, nullptr); EXPECT_LE(Size, malloc_usable_size(P)); EXPECT_EQ(reinterpret_cast(P) % Alignment, 0U); + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(Size, AC.Size); free(P); + EXPECT_EQ(P, DC.Ptr); P = nullptr; EXPECT_EQ(posix_memalign(&P, Alignment, Size), 0); EXPECT_NE(P, nullptr); EXPECT_LE(Size, malloc_usable_size(P)); EXPECT_EQ(reinterpret_cast(P) % Alignment, 0U); + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(Size, AC.Size); free(P); + EXPECT_EQ(P, DC.Ptr); } EXPECT_EQ(memalign(4096U, SIZE_MAX), nullptr); @@ -139,7 +170,10 @@ for (size_t Alignment = 0U; Alignment <= 128U; Alignment++) { P = memalign(Alignment, 1024U); EXPECT_NE(P, nullptr); + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(Size, AC.Size); free(P); + EXPECT_EQ(P, DC.Ptr); } } } @@ -150,7 +184,10 @@ EXPECT_NE(P, nullptr); EXPECT_LE(Alignment * 4U, malloc_usable_size(P)); EXPECT_EQ(reinterpret_cast(P) % Alignment, 0U); + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(Alignment * 4U, AC.Size); free(P); + EXPECT_EQ(P, DC.Ptr); errno = 0; P = aligned_alloc(Alignment, Size); @@ -160,31 +197,52 @@ TEST(ScudoWrappersCDeathTest, Realloc) { // realloc(nullptr, N) is malloc(N) - void *P = realloc(nullptr, 0U); + void *P = realloc(nullptr, Size); EXPECT_NE(P, nullptr); + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(Size, AC.Size); free(P); + EXPECT_EQ(P, DC.Ptr); P = malloc(Size); EXPECT_NE(P, nullptr); // realloc(P, 0U) is free(P) and returns nullptr EXPECT_EQ(realloc(P, 0U), nullptr); + EXPECT_EQ(P, DC.Ptr); P = malloc(Size); EXPECT_NE(P, nullptr); EXPECT_LE(Size, malloc_usable_size(P)); memset(P, 0x42, Size); + AC.Ptr = reinterpret_cast(0xdeadbeef); + void *OldP = P; P = realloc(P, Size * 2U); EXPECT_NE(P, nullptr); EXPECT_LE(Size * 2U, malloc_usable_size(P)); for (size_t I = 0; I < Size; I++) EXPECT_EQ(0x42, (reinterpret_cast(P))[I]); + if (OldP == P) { + EXPECT_EQ(AC.Ptr, reinterpret_cast(0xdeadbeef)); + } else { + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(Size * 2U, AC.Size); + EXPECT_EQ(OldP, DC.Ptr); + } + AC.Ptr = reinterpret_cast(0xdeadbeef); + OldP = P; P = realloc(P, Size / 2U); EXPECT_NE(P, nullptr); EXPECT_LE(Size / 2U, malloc_usable_size(P)); for (size_t I = 0; I < Size / 2U; I++) EXPECT_EQ(0x42, (reinterpret_cast(P))[I]); + if (OldP == P) { + EXPECT_EQ(AC.Ptr, reinterpret_cast(0xdeadbeef)); + } else { + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(Size / 2U, AC.Size); + } free(P); EXPECT_DEATH(P = realloc(P, Size), ""); @@ -247,7 +305,11 @@ EXPECT_NE(P, nullptr); EXPECT_EQ(reinterpret_cast(P) & (PageSize - 1), 0U); EXPECT_LE(PageSize, malloc_usable_size(P)); + EXPECT_EQ(P, AC.Ptr); + // Size will be rounded up to PageSize. + EXPECT_EQ(PageSize, AC.Size); free(P); + EXPECT_EQ(P, DC.Ptr); EXPECT_EQ(pvalloc(SIZE_MAX), nullptr); diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp @@ -17,47 +17,81 @@ #include #include +struct AllocContext { + void *Ptr; + size_t Size; +}; +struct DeallocContext { + void *Ptr; +}; +static AllocContext AC; +static DeallocContext DC; + void operator delete(void *, size_t) noexcept; void operator delete[](void *, size_t) noexcept; +extern "C" { +__attribute__((visibility("default"))) void __scudo_allocate_hook(void *Ptr, + size_t Size) { + AC.Ptr = Ptr; + AC.Size = Size; +} +__attribute__((visibility("default"))) void __scudo_deallocate_hook(void *Ptr) { + DC.Ptr = Ptr; +} +} // Note that every Cxx allocation function in the test binary will be fulfilled // by Scudo. See the comment in the C counterpart of this file. template static void testCxxNew() { T *P = new T; EXPECT_NE(P, nullptr); + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(sizeof(T), AC.Size); memset(P, 0x42, sizeof(T)); EXPECT_DEATH(delete[] P, ""); delete P; + EXPECT_EQ(P, DC.Ptr); EXPECT_DEATH(delete P, ""); P = new T; EXPECT_NE(P, nullptr); memset(P, 0x42, sizeof(T)); operator delete(P, sizeof(T)); + EXPECT_EQ(P, DC.Ptr); P = new (std::nothrow) T; + EXPECT_EQ(P, AC.Ptr); + EXPECT_EQ(sizeof(T), AC.Size); EXPECT_NE(P, nullptr); memset(P, 0x42, sizeof(T)); delete P; + EXPECT_EQ(P, DC.Ptr); const size_t N = 16U; T *A = new T[N]; EXPECT_NE(A, nullptr); + EXPECT_EQ(A, AC.Ptr); + EXPECT_EQ(sizeof(T) * N, AC.Size); memset(A, 0x42, sizeof(T) * N); EXPECT_DEATH(delete A, ""); delete[] A; + EXPECT_EQ(A, DC.Ptr); EXPECT_DEATH(delete[] A, ""); A = new T[N]; EXPECT_NE(A, nullptr); memset(A, 0x42, sizeof(T) * N); operator delete[](A, sizeof(T) * N); + EXPECT_EQ(A, DC.Ptr); A = new (std::nothrow) T[N]; + EXPECT_EQ(A, AC.Ptr); + EXPECT_EQ(sizeof(T) * N, AC.Size); EXPECT_NE(A, nullptr); memset(A, 0x42, sizeof(T) * N); delete[] A; + EXPECT_EQ(A, DC.Ptr); } class Pixel { diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c.cpp b/compiler-rt/lib/scudo/standalone/wrappers_c.cpp --- a/compiler-rt/lib/scudo/standalone/wrappers_c.cpp +++ b/compiler-rt/lib/scudo/standalone/wrappers_c.cpp @@ -12,6 +12,7 @@ #if !SCUDO_ANDROID || !_BIONIC #include "allocator_config.h" +#include "scudo/interface.h" #include "wrappers_c.h" #include "wrappers_c_checks.h" diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c.inc b/compiler-rt/lib/scudo/standalone/wrappers_c.inc --- a/compiler-rt/lib/scudo/standalone/wrappers_c.inc +++ b/compiler-rt/lib/scudo/standalone/wrappers_c.inc @@ -17,6 +17,16 @@ #define SCUDO_MALLOC_ALIGNMENT FIRST_32_SECOND_64(8U, 16U) #endif +static void reportAllocation(void *ptr, size_t size) { + if (__scudo_allocate_hook && ptr) + __scudo_allocate_hook(ptr, size); +} + +static void reportDeallocation(void *ptr) { + if (__scudo_deallocate_hook) + __scudo_deallocate_hook(ptr); +} + extern "C" { INTERFACE WEAK void *SCUDO_PREFIX(calloc)(size_t nmemb, size_t size) { @@ -28,11 +38,14 @@ } scudo::reportCallocOverflow(nmemb, size); } - return scudo::setErrnoOnNull(SCUDO_ALLOCATOR.allocate( - Product, scudo::Chunk::Origin::Malloc, SCUDO_MALLOC_ALIGNMENT, true)); + void *Ptr = SCUDO_ALLOCATOR.allocate(Product, scudo::Chunk::Origin::Malloc, + SCUDO_MALLOC_ALIGNMENT, true); + reportAllocation(Ptr, Product); + return scudo::setErrnoOnNull(Ptr); } INTERFACE WEAK void SCUDO_PREFIX(free)(void *ptr) { + reportDeallocation(ptr); SCUDO_ALLOCATOR.deallocate(ptr, scudo::Chunk::Origin::Malloc); } @@ -75,8 +88,10 @@ #endif INTERFACE WEAK void *SCUDO_PREFIX(malloc)(size_t size) { - return scudo::setErrnoOnNull(SCUDO_ALLOCATOR.allocate( - size, scudo::Chunk::Origin::Malloc, SCUDO_MALLOC_ALIGNMENT)); + void *Ptr = SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Malloc, + SCUDO_MALLOC_ALIGNMENT); + reportAllocation(Ptr, size); + return scudo::setErrnoOnNull(Ptr); } #if SCUDO_ANDROID @@ -105,8 +120,10 @@ scudo::reportAlignmentNotPowerOfTwo(alignment); } } - return SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Memalign, - alignment); + void *Ptr = + SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Memalign, alignment); + reportAllocation(Ptr, size); + return Ptr; } INTERFACE WEAK int SCUDO_PREFIX(posix_memalign)(void **memptr, size_t alignment, @@ -120,6 +137,8 @@ SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Memalign, alignment); if (UNLIKELY(!Ptr)) return ENOMEM; + reportAllocation(Ptr, size); + *memptr = Ptr; return 0; } @@ -134,26 +153,42 @@ scudo::reportPvallocOverflow(size); } // pvalloc(0) should allocate one page. - return scudo::setErrnoOnNull( + void *Ptr = SCUDO_ALLOCATOR.allocate(size ? scudo::roundUp(size, PageSize) : PageSize, - scudo::Chunk::Origin::Memalign, PageSize)); + scudo::Chunk::Origin::Memalign, PageSize); + reportAllocation(Ptr, scudo::roundUp(size, PageSize)); + + return scudo::setErrnoOnNull(Ptr); } INTERFACE WEAK void *SCUDO_PREFIX(realloc)(void *ptr, size_t size) { - if (!ptr) - return scudo::setErrnoOnNull(SCUDO_ALLOCATOR.allocate( - size, scudo::Chunk::Origin::Malloc, SCUDO_MALLOC_ALIGNMENT)); + if (!ptr) { + void *Ptr = SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Malloc, + SCUDO_MALLOC_ALIGNMENT); + reportAllocation(Ptr, size); + return scudo::setErrnoOnNull(Ptr); + } if (size == 0) { + reportDeallocation(ptr); SCUDO_ALLOCATOR.deallocate(ptr, scudo::Chunk::Origin::Malloc); return nullptr; } - return scudo::setErrnoOnNull( - SCUDO_ALLOCATOR.reallocate(ptr, size, SCUDO_MALLOC_ALIGNMENT)); + + void *NewPtr = SCUDO_ALLOCATOR.reallocate(ptr, size, SCUDO_MALLOC_ALIGNMENT); + if (NewPtr != ptr) { + reportAllocation(NewPtr, size); + reportDeallocation(ptr); + } + + return scudo::setErrnoOnNull(NewPtr); } INTERFACE WEAK void *SCUDO_PREFIX(valloc)(size_t size) { - return scudo::setErrnoOnNull(SCUDO_ALLOCATOR.allocate( - size, scudo::Chunk::Origin::Memalign, scudo::getPageSizeCached())); + void *Ptr = SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Memalign, + scudo::getPageSizeCached()); + reportAllocation(Ptr, size); + + return scudo::setErrnoOnNull(Ptr); } INTERFACE WEAK int SCUDO_PREFIX(malloc_iterate)( @@ -230,8 +265,12 @@ } scudo::reportInvalidAlignedAllocAlignment(alignment, size); } - return scudo::setErrnoOnNull( - SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Malloc, alignment)); + + void *Ptr = + SCUDO_ALLOCATOR.allocate(size, scudo::Chunk::Origin::Malloc, alignment); + reportAllocation(Ptr, size); + + return scudo::setErrnoOnNull(Ptr); } INTERFACE WEAK int SCUDO_PREFIX(malloc_info)(UNUSED int options, FILE *stream) { diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp b/compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp --- a/compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp +++ b/compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp @@ -12,6 +12,7 @@ #if SCUDO_ANDROID && _BIONIC #include "allocator_config.h" +#include "scudo/interface.h" #include "wrappers_c.h" #include "wrappers_c_checks.h" diff --git a/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp b/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp --- a/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp +++ b/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp @@ -12,6 +12,7 @@ #if !SCUDO_ANDROID || !_BIONIC #include "allocator_config.h" +#include "scudo/interface.h" #include "wrappers_c.h" #include @@ -21,86 +22,124 @@ enum class align_val_t : size_t {}; } // namespace std +static void reportAllocation(void *ptr, size_t size) { + if (__scudo_allocate_hook && ptr) + __scudo_allocate_hook(ptr, size); +} + +static void reportDeallocation(void *ptr) { + if (__scudo_deallocate_hook) + __scudo_deallocate_hook(ptr); +} + INTERFACE WEAK void *operator new(size_t size) { - return Allocator.allocate(size, scudo::Chunk::Origin::New); + void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::New); + reportAllocation(Ptr, size); + return Ptr; } INTERFACE WEAK void *operator new[](size_t size) { - return Allocator.allocate(size, scudo::Chunk::Origin::NewArray); + void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::NewArray); + reportAllocation(Ptr, size); + return Ptr; } INTERFACE WEAK void *operator new(size_t size, std::nothrow_t const &) NOEXCEPT { - return Allocator.allocate(size, scudo::Chunk::Origin::New); + void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::New); + reportAllocation(Ptr, size); + return Ptr; } INTERFACE WEAK void *operator new[](size_t size, std::nothrow_t const &) NOEXCEPT { - return Allocator.allocate(size, scudo::Chunk::Origin::NewArray); + void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::NewArray); + reportAllocation(Ptr, size); + return Ptr; } INTERFACE WEAK void *operator new(size_t size, std::align_val_t align) { - return Allocator.allocate(size, scudo::Chunk::Origin::New, - static_cast(align)); + void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::New, + static_cast(align)); + reportAllocation(Ptr, size); + return Ptr; } INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align) { - return Allocator.allocate(size, scudo::Chunk::Origin::NewArray, - static_cast(align)); + void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::NewArray, + static_cast(align)); + reportAllocation(Ptr, size); + return Ptr; } INTERFACE WEAK void *operator new(size_t size, std::align_val_t align, std::nothrow_t const &) NOEXCEPT { - return Allocator.allocate(size, scudo::Chunk::Origin::New, - static_cast(align)); + void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::New, + static_cast(align)); + reportAllocation(Ptr, size); + return Ptr; } INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align, std::nothrow_t const &) NOEXCEPT { - return Allocator.allocate(size, scudo::Chunk::Origin::NewArray, - static_cast(align)); + void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::NewArray, + static_cast(align)); + reportAllocation(Ptr, size); + return Ptr; } INTERFACE WEAK void operator delete(void *ptr) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::New); } INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray); } INTERFACE WEAK void operator delete(void *ptr, std::nothrow_t const &) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::New); } INTERFACE WEAK void operator delete[](void *ptr, std::nothrow_t const &) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray); } INTERFACE WEAK void operator delete(void *ptr, size_t size) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size); } INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size); } INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0, static_cast(align)); } INTERFACE WEAK void operator delete[](void *ptr, std::align_val_t align) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0, static_cast(align)); } INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align, std::nothrow_t const &) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0, static_cast(align)); } INTERFACE WEAK void operator delete[](void *ptr, std::align_val_t align, std::nothrow_t const &) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0, static_cast(align)); } INTERFACE WEAK void operator delete(void *ptr, size_t size, std::align_val_t align) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size, static_cast(align)); } INTERFACE WEAK void operator delete[](void *ptr, size_t size, std::align_val_t align) NOEXCEPT { + reportDeallocation(ptr); Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size, static_cast(align)); }