diff --git a/compiler-rt/lib/asan/asan_allocator.h b/compiler-rt/lib/asan/asan_allocator.h --- a/compiler-rt/lib/asan/asan_allocator.h +++ b/compiler-rt/lib/asan/asan_allocator.h @@ -158,6 +158,7 @@ static const uptr kMetadataSize = 0; typedef __asan::SizeClassMap SizeClassMap; typedef AsanMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; using AddressSpaceView = AddressSpaceViewTy; }; @@ -187,6 +188,7 @@ using AddressSpaceView = AddressSpaceViewTy; using ByteMap = __asan::ByteMapASVT; typedef AsanMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; }; template @@ -196,15 +198,9 @@ static const uptr kNumberOfSizeClasses = SizeClassMap::kNumClasses; -template -using SecondaryAllocatorASVT = - LargeMmapAllocator; template using AsanAllocatorASVT = - CombinedAllocator, - SecondaryAllocatorASVT, - AddressSpaceView>; + CombinedAllocator>; using AsanAllocator = AsanAllocatorASVT; using AllocatorCache = AsanAllocator::AllocatorCache; diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.h b/compiler-rt/lib/hwasan/hwasan_allocator.h --- a/compiler-rt/lib/hwasan/hwasan_allocator.h +++ b/compiler-rt/lib/hwasan/hwasan_allocator.h @@ -58,11 +58,11 @@ typedef __sanitizer::VeryDenseSizeClassMap SizeClassMap; using AddressSpaceView = LocalAddressSpaceView; typedef HwasanMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; }; typedef SizeClassAllocator64 PrimaryAllocator; -typedef LargeMmapAllocator SecondaryAllocator; -typedef CombinedAllocator Allocator; +typedef CombinedAllocator Allocator; typedef Allocator::AllocatorCache AllocatorCache; void AllocatorSwallowThreadLocalCache(AllocatorCache *cache); diff --git a/compiler-rt/lib/lsan/lsan_allocator.h b/compiler-rt/lib/lsan/lsan_allocator.h --- a/compiler-rt/lib/lsan/lsan_allocator.h +++ b/compiler-rt/lib/lsan/lsan_allocator.h @@ -67,6 +67,7 @@ using AddressSpaceView = AddressSpaceViewTy; using ByteMap = __lsan::ByteMapASVT; typedef NoOpMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; }; template @@ -87,6 +88,7 @@ static const uptr kMetadataSize = sizeof(ChunkMetadata); typedef DefaultSizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; using AddressSpaceView = AddressSpaceViewTy; }; @@ -97,15 +99,7 @@ #endif template -using SecondaryAllocatorASVT = - LargeMmapAllocator; - -template -using AllocatorASVT = - CombinedAllocator, - SecondaryAllocatorASVT, - AddressSpaceView>; +using AllocatorASVT = CombinedAllocator>; using Allocator = AllocatorASVT; using AllocatorCache = Allocator::AllocatorCache; diff --git a/compiler-rt/lib/msan/msan_allocator.cc b/compiler-rt/lib/msan/msan_allocator.cc --- a/compiler-rt/lib/msan/msan_allocator.cc +++ b/compiler-rt/lib/msan/msan_allocator.cc @@ -59,6 +59,7 @@ using AddressSpaceView = LocalAddressSpaceView; using ByteMap = __msan::ByteMap; typedef MsanMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; }; typedef SizeClassAllocator32 PrimaryAllocator; @@ -77,6 +78,7 @@ static const uptr kMetadataSize = sizeof(Metadata); typedef DefaultSizeClassMap SizeClassMap; typedef MsanMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; using AddressSpaceView = LocalAddressSpaceView; }; @@ -92,6 +94,7 @@ static const uptr kMetadataSize = sizeof(Metadata); typedef DefaultSizeClassMap SizeClassMap; typedef MsanMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; using AddressSpaceView = LocalAddressSpaceView; }; @@ -112,12 +115,12 @@ using AddressSpaceView = LocalAddressSpaceView; using ByteMap = __msan::ByteMap; typedef MsanMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; }; typedef SizeClassAllocator32 PrimaryAllocator; #endif -typedef LargeMmapAllocator SecondaryAllocator; -typedef CombinedAllocator Allocator; +typedef CombinedAllocator Allocator; typedef Allocator::AllocatorCache AllocatorCache; static Allocator allocator; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h @@ -19,18 +19,15 @@ // When allocating 2^x bytes it should return 2^x aligned chunk. // PrimaryAllocator is used via a local AllocatorCache. // SecondaryAllocator can allocate anything, but is not efficient. -template // NOLINT +template class CombinedAllocator { public: + using SecondaryAllocator = + LargeMmapAllocator; + using AllocatorCache = SizeClassAllocatorLocalCache; - using AddressSpaceView = AddressSpaceViewTy; - static_assert(is_same::value, - "PrimaryAllocator is using wrong AddressSpaceView"); - static_assert(is_same::value, - "SecondaryAllocator is using wrong AddressSpaceView"); void InitLinkerInitialized(s32 release_to_os_interval_ms) { stats_.InitLinkerInitialized(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h @@ -39,16 +39,12 @@ using AddressSpaceView = LocalAddressSpaceView; using ByteMap = __sanitizer::ByteMap; typedef NoOpMapUnmapCallback MapUnmapCallback; + using PtrArray = LargeMmapAllocatorPtrArrayStatic; static const uptr kFlags = 0; }; typedef SizeClassAllocator32 PrimaryInternalAllocator; -typedef LargeMmapAllocator - SecondaryInternalAllocator; - -typedef CombinedAllocator - InternalAllocator; +typedef CombinedAllocator InternalAllocator; typedef InternalAllocator::AllocatorCache InternalAllocatorCache; void *InternalAlloc(uptr size, InternalAllocatorCache *cache = nullptr, diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h @@ -47,6 +47,7 @@ template class SizeClassAllocator32 { public: + using ParamsTy = Params; using AddressSpaceView = typename Params::AddressSpaceView; static const uptr kSpaceBeg = Params::kSpaceBeg; static const u64 kSpaceSize = Params::kSpaceSize; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h @@ -45,6 +45,7 @@ template class SizeClassAllocator64 { public: + using ParamsTy = Params; using AddressSpaceView = typename Params::AddressSpaceView; static const uptr kSpaceBeg = Params::kSpaceBeg; static const uptr kSpaceSize = Params::kSpaceSize; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h @@ -66,9 +66,7 @@ // This class can (de)allocate only large chunks of memory using mmap/unmap. // The main purpose of this allocator is to cover large and rare allocation // sizes not covered by more efficient allocators (e.g. SizeClassAllocator64). -template +template class LargeMmapAllocator { public: using AddressSpaceView = AddressSpaceViewTy; diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -59,6 +59,7 @@ static const uptr kMetadataSize = 16; typedef ::SizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; using AddressSpaceView = AddressSpaceViewTy; }; @@ -70,6 +71,7 @@ static const uptr kMetadataSize = 16; typedef ::SizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; using AddressSpaceView = AddressSpaceViewTy; }; @@ -81,6 +83,7 @@ static const uptr kMetadataSize = 16; typedef CompactSizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; using AddressSpaceView = AddressSpaceViewTy; }; @@ -92,6 +95,7 @@ static const uptr kMetadataSize = 16; typedef VeryCompactSizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; using AddressSpaceView = AddressSpaceViewTy; }; @@ -103,6 +107,7 @@ static const uptr kMetadataSize = 16; typedef DenseSizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; using AddressSpaceView = AddressSpaceViewTy; }; @@ -155,6 +160,7 @@ using AddressSpaceView = AddressSpaceViewTy; using ByteMap = FlatByteMap; typedef NoOpMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; }; template @@ -501,10 +507,15 @@ // TestMapUnmapCallback::unmap_count); } +template +using TestLargeMmapAllocator = + LargeMmapAllocator; + TEST(SanitizerCommon, LargeMmapAllocatorMapUnmapCallback) { TestMapUnmapCallback::map_count = 0; TestMapUnmapCallback::unmap_count = 0; - LargeMmapAllocator a; + TestLargeMmapAllocator a; a.Init(); AllocatorStats stats; stats.Init(); @@ -542,7 +553,7 @@ #endif TEST(SanitizerCommon, LargeMmapAllocator) { - LargeMmapAllocator a; + TestLargeMmapAllocator a; a.Init(); AllocatorStats stats; stats.Init(); @@ -619,9 +630,9 @@ a.Deallocate(&stats, p); } -template +template void TestCombinedAllocator() { - typedef CombinedAllocator Allocator; + typedef CombinedAllocator Allocator; Allocator *a = new Allocator; a->Init(kReleaseToOSIntervalNever); std::mt19937 r; @@ -687,26 +698,26 @@ #if SANITIZER_CAN_USE_ALLOCATOR64 TEST(SanitizerCommon, CombinedAllocator64) { - TestCombinedAllocator>(); + TestCombinedAllocator(); } TEST(SanitizerCommon, CombinedAllocator64Dynamic) { - TestCombinedAllocator>(); + TestCombinedAllocator(); } #if !SANITIZER_ANDROID TEST(SanitizerCommon, CombinedAllocator64Compact) { - TestCombinedAllocator>(); + TestCombinedAllocator(); } #endif TEST(SanitizerCommon, CombinedAllocator64VeryCompact) { - TestCombinedAllocator>(); + TestCombinedAllocator(); } #endif TEST(SanitizerCommon, CombinedAllocator32Compact) { - TestCombinedAllocator>(); + TestCombinedAllocator(); } template @@ -951,7 +962,7 @@ } TEST(SanitizerCommon, LargeMmapAllocatorIteration) { - LargeMmapAllocator a; + TestLargeMmapAllocator a; a.Init(); AllocatorStats stats; stats.Init(); @@ -978,7 +989,7 @@ } TEST(SanitizerCommon, LargeMmapAllocatorBlockBegin) { - LargeMmapAllocator a; + TestLargeMmapAllocator a; a.Init(); AllocatorStats stats; stats.Init(); diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc @@ -42,6 +42,7 @@ static const uptr kMetadataSize = 0; typedef CompactSizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = SizeClassAllocator64FlagMasks::kRandomShuffleChunks; }; @@ -49,8 +50,7 @@ namespace { typedef SizeClassAllocator64<__AP64> PrimaryAllocator; -typedef LargeMmapAllocator<> SecondaryAllocator; -typedef CombinedAllocator Allocator; +typedef CombinedAllocator Allocator; typedef Allocator::AllocatorCache AllocatorCache; static Allocator allocator; diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -79,13 +79,13 @@ static const uptr kMetadataSize = 0; typedef DefaultSizeClassMap SizeClassMap; typedef __tsan::MapUnmapCallback MapUnmapCallback; + using PtrArray = DefaultLargeMmapAllocatorPtrArray; static const uptr kFlags = 0; using AddressSpaceView = LocalAddressSpaceView; }; typedef SizeClassAllocator64 PrimaryAllocator; #endif -typedef LargeMmapAllocator SecondaryAllocator; -typedef CombinedAllocator Allocator; +typedef CombinedAllocator Allocator; typedef Allocator::AllocatorCache AllocatorCache; Allocator *allocator(); #endif