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 @@ -196,6 +196,10 @@ #endif // GWP_ASAN_HOOKS } + ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) { + TSDRegistry.initThreadMaybe(this, MinimalInit); + } + void reset() { memset(this, 0, sizeof(*this)); } void unmapTestOnly() { @@ -977,10 +981,6 @@ reinterpret_cast(Ptr) - SizeOrUnusedBytes; } - ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) { - TSDRegistry.initThreadMaybe(this, MinimalInit); - } - void quarantineOrDeallocateChunk(void *Ptr, Chunk::UnpackedHeader *Header, uptr Size) { Chunk::UnpackedHeader NewHeader = *Header; diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp @@ -67,15 +67,17 @@ ""); } +template struct TestAllocator : scudo::Allocator { + TestAllocator() { + this->reset(); + this->initThreadMaybe(); + } + ~TestAllocator() { this->unmapTestOnly(); } +}; + template static void testAllocator() { - using AllocatorT = scudo::Allocator; - auto Deleter = [](AllocatorT *A) { - A->unmapTestOnly(); - delete A; - }; - std::unique_ptr Allocator(new AllocatorT, - Deleter); - Allocator->reset(); + using AllocatorT = TestAllocator; + auto Allocator = std::make_unique(); EXPECT_FALSE(Allocator->isOwned(&Mutex)); EXPECT_FALSE(Allocator->isOwned(&Allocator)); @@ -348,14 +350,8 @@ } template static void testAllocatorThreaded() { - using AllocatorT = scudo::Allocator; - auto Deleter = [](AllocatorT *A) { - A->unmapTestOnly(); - delete A; - }; - std::unique_ptr Allocator(new AllocatorT, - Deleter); - Allocator->reset(); + using AllocatorT = TestAllocator; + auto Allocator = std::make_unique(); std::thread Threads[32]; for (scudo::uptr I = 0; I < ARRAY_SIZE(Threads); I++) Threads[I] = std::thread(stressAllocator, Allocator.get()); @@ -401,14 +397,8 @@ }; TEST(ScudoCombinedTest, DeathCombined) { - using AllocatorT = scudo::Allocator; - auto Deleter = [](AllocatorT *A) { - A->unmapTestOnly(); - delete A; - }; - std::unique_ptr Allocator(new AllocatorT, - Deleter); - Allocator->reset(); + using AllocatorT = TestAllocator; + auto Allocator = std::make_unique(); const scudo::uptr Size = 1000U; void *P = Allocator->allocate(Size, Origin); @@ -442,14 +432,8 @@ // Ensure that releaseToOS can be called prior to any other allocator // operation without issue. TEST(ScudoCombinedTest, ReleaseToOS) { - using AllocatorT = scudo::Allocator; - auto Deleter = [](AllocatorT *A) { - A->unmapTestOnly(); - delete A; - }; - std::unique_ptr Allocator(new AllocatorT, - Deleter); - Allocator->reset(); + using AllocatorT = TestAllocator; + auto Allocator = std::make_unique(); Allocator->releaseToOS(); } @@ -457,14 +441,8 @@ // Verify that when a region gets full, the allocator will still manage to // fulfill the allocation through a larger size class. TEST(ScudoCombinedTest, FullRegion) { - using AllocatorT = scudo::Allocator; - auto Deleter = [](AllocatorT *A) { - A->unmapTestOnly(); - delete A; - }; - std::unique_ptr Allocator(new AllocatorT, - Deleter); - Allocator->reset(); + using AllocatorT = TestAllocator; + auto Allocator = std::make_unique(); std::vector V; scudo::uptr FailedAllocationsCount = 0;