diff options
-rw-r--r-- | compiler-rt/lib/asan/asan_allocator.h | 6 | ||||
-rw-r--r-- | compiler-rt/lib/lsan/lsan_allocator.h | 6 | ||||
-rw-r--r-- | compiler-rt/lib/msan/msan_allocator.cc | 2 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h | 5 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc | 46 | ||||
-rw-r--r-- | compiler-rt/lib/scudo/scudo_allocator.h | 1 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl.h | 1 |
7 files changed, 57 insertions, 10 deletions
diff --git a/compiler-rt/lib/asan/asan_allocator.h b/compiler-rt/lib/asan/asan_allocator.h index 51fba254a5a..209532e1fe4 100644 --- a/compiler-rt/lib/asan/asan_allocator.h +++ b/compiler-rt/lib/asan/asan_allocator.h @@ -148,6 +148,7 @@ const uptr kAllocatorSpace = 0x600000000000ULL; const uptr kAllocatorSize = 0x40000000000ULL; // 4T. typedef DefaultSizeClassMap SizeClassMap; # endif +template <typename AddressSpaceViewTy> struct AP64 { // Allocator64 parameters. Deliberately using a short name. static const uptr kSpaceBeg = kAllocatorSpace; static const uptr kSpaceSize = kAllocatorSize; @@ -155,9 +156,12 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name. typedef __asan::SizeClassMap SizeClassMap; typedef AsanMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = AddressSpaceViewTy; }; -typedef SizeClassAllocator64<AP64> PrimaryAllocator; +template <typename AddressSpaceView> +using PrimaryAllocatorASVT = SizeClassAllocator64<AP64<AddressSpaceView>>; +using PrimaryAllocator = PrimaryAllocatorASVT<LocalAddressSpaceView>; #else // Fallback to SizeClassAllocator32. static const uptr kRegionSizeLog = 20; static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog; diff --git a/compiler-rt/lib/lsan/lsan_allocator.h b/compiler-rt/lib/lsan/lsan_allocator.h index 23ebc11f609..29ea2b6d9c2 100644 --- a/compiler-rt/lib/lsan/lsan_allocator.h +++ b/compiler-rt/lib/lsan/lsan_allocator.h @@ -81,6 +81,7 @@ const uptr kAllocatorSize = 0x20000000000ULL; // 2T. const uptr kAllocatorSpace = 0x600000000000ULL; const uptr kAllocatorSize = 0x40000000000ULL; // 4T. # endif +template <typename AddressSpaceViewTy> struct AP64 { // Allocator64 parameters. Deliberately using a short name. static const uptr kSpaceBeg = kAllocatorSpace; static const uptr kSpaceSize = kAllocatorSize; @@ -88,9 +89,12 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name. typedef DefaultSizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = AddressSpaceViewTy; }; -typedef SizeClassAllocator64<AP64> PrimaryAllocator; +template <typename AddressSpaceView> +using PrimaryAllocatorASVT = SizeClassAllocator64<AP64<AddressSpaceView>>; +using PrimaryAllocator = PrimaryAllocatorASVT<LocalAddressSpaceView>; #endif typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache; diff --git a/compiler-rt/lib/msan/msan_allocator.cc b/compiler-rt/lib/msan/msan_allocator.cc index 8b9fa65065f..053ab028039 100644 --- a/compiler-rt/lib/msan/msan_allocator.cc +++ b/compiler-rt/lib/msan/msan_allocator.cc @@ -79,6 +79,7 @@ struct MsanMapUnmapCallback { typedef DefaultSizeClassMap SizeClassMap; typedef MsanMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = LocalAddressSpaceView; }; typedef SizeClassAllocator64<AP64> PrimaryAllocator; @@ -93,6 +94,7 @@ struct MsanMapUnmapCallback { typedef DefaultSizeClassMap SizeClassMap; typedef MsanMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = LocalAddressSpaceView; }; typedef SizeClassAllocator64<AP64> PrimaryAllocator; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h index 6acb4f8bc56..b063bf0d302 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h @@ -46,6 +46,7 @@ struct SizeClassAllocator64FlagMasks { // Bit masks. template <class Params> class SizeClassAllocator64 { public: + using AddressSpaceView = typename Params::AddressSpaceView; static const uptr kSpaceBeg = Params::kSpaceBeg; static const uptr kSpaceSize = Params::kSpaceSize; static const uptr kMetadataSize = Params::kMetadataSize; @@ -294,8 +295,10 @@ class SizeClassAllocator64 { RegionInfo *region = GetRegionInfo(class_id); uptr chunk_size = ClassIdToSize(class_id); uptr region_beg = SpaceBeg() + class_id * kRegionSize; + uptr region_allocated_user_size = + AddressSpaceView::Load(region)->allocated_user; for (uptr chunk = region_beg; - chunk < region_beg + region->allocated_user; + chunk < region_beg + region_allocated_user_size; chunk += chunk_size) { // Too slow: CHECK_EQ((void *)chunk, GetBlockBegin((void *)chunk)); callback(chunk, arg); diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc index f12b70e7b67..3123a1d5abf 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -53,6 +53,7 @@ static const u64 kAddressSpaceSize = 1ULL << 47; typedef DefaultSizeClassMap SizeClassMap; #endif +template <typename AddressSpaceViewTy> struct AP64 { // Allocator Params. Short name for shorter demangled names.. static const uptr kSpaceBeg = kAllocatorSpace; static const uptr kSpaceSize = kAllocatorSize; @@ -60,8 +61,10 @@ struct AP64 { // Allocator Params. Short name for shorter demangled names.. typedef ::SizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = AddressSpaceViewTy; }; +template <typename AddressSpaceViewTy> struct AP64Dyn { static const uptr kSpaceBeg = ~(uptr)0; static const uptr kSpaceSize = kAllocatorSize; @@ -69,8 +72,10 @@ struct AP64Dyn { typedef ::SizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = AddressSpaceViewTy; }; +template <typename AddressSpaceViewTy> struct AP64Compact { static const uptr kSpaceBeg = ~(uptr)0; static const uptr kSpaceSize = kAllocatorSize; @@ -78,8 +83,10 @@ struct AP64Compact { typedef CompactSizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = AddressSpaceViewTy; }; +template <typename AddressSpaceViewTy> struct AP64VeryCompact { static const uptr kSpaceBeg = ~(uptr)0; static const uptr kSpaceSize = 1ULL << 37; @@ -87,8 +94,10 @@ struct AP64VeryCompact { typedef VeryCompactSizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = AddressSpaceViewTy; }; +template <typename AddressSpaceViewTy> struct AP64Dense { static const uptr kSpaceBeg = kAllocatorSpace; static const uptr kSpaceSize = kAllocatorSize; @@ -96,13 +105,32 @@ struct AP64Dense { typedef DenseSizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = AddressSpaceViewTy; }; -typedef SizeClassAllocator64<AP64> Allocator64; -typedef SizeClassAllocator64<AP64Dyn> Allocator64Dynamic; -typedef SizeClassAllocator64<AP64Compact> Allocator64Compact; -typedef SizeClassAllocator64<AP64VeryCompact> Allocator64VeryCompact; -typedef SizeClassAllocator64<AP64Dense> Allocator64Dense; +template <typename AddressSpaceView> +using Allocator64ASVT = SizeClassAllocator64<AP64<AddressSpaceView>>; +using Allocator64 = Allocator64ASVT<LocalAddressSpaceView>; + +template <typename AddressSpaceView> +using Allocator64DynamicASVT = SizeClassAllocator64<AP64Dyn<AddressSpaceView>>; +using Allocator64Dynamic = Allocator64DynamicASVT<LocalAddressSpaceView>; + +template <typename AddressSpaceView> +using Allocator64CompactASVT = + SizeClassAllocator64<AP64Compact<AddressSpaceView>>; +using Allocator64Compact = Allocator64CompactASVT<LocalAddressSpaceView>; + +template <typename AddressSpaceView> +using Allocator64VeryCompactASVT = + SizeClassAllocator64<AP64VeryCompact<AddressSpaceView>>; +using Allocator64VeryCompact = + Allocator64VeryCompactASVT<LocalAddressSpaceView>; + +template <typename AddressSpaceView> +using Allocator64DenseASVT = SizeClassAllocator64<AP64Dense<AddressSpaceView>>; +using Allocator64Dense = Allocator64DenseASVT<LocalAddressSpaceView>; + #elif defined(__mips64) static const u64 kAddressSpaceSize = 1ULL << 40; #elif defined(__aarch64__) @@ -404,6 +432,7 @@ int TestMapUnmapCallback::unmap_count; // to run them all at the same time. FIXME: Make them not flaky and reenable. #if !SANITIZER_WINDOWS +template <typename AddressSpaceViewTy = LocalAddressSpaceView> struct AP64WithCallback { static const uptr kSpaceBeg = kAllocatorSpace; static const uptr kSpaceSize = kAllocatorSize; @@ -411,12 +440,13 @@ struct AP64WithCallback { typedef ::SizeClassMap SizeClassMap; typedef TestMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = AddressSpaceViewTy; }; TEST(SanitizerCommon, SizeClassAllocator64MapUnmapCallback) { TestMapUnmapCallback::map_count = 0; TestMapUnmapCallback::unmap_count = 0; - typedef SizeClassAllocator64<AP64WithCallback> Allocator64WithCallBack; + typedef SizeClassAllocator64<AP64WithCallback<>> Allocator64WithCallBack; Allocator64WithCallBack *a = new Allocator64WithCallBack; a->Init(kReleaseToOSIntervalNever); EXPECT_EQ(TestMapUnmapCallback::map_count, 1); // Allocator state. @@ -1003,6 +1033,7 @@ TEST(SanitizerCommon, LargeMmapAllocatorBlockBegin) { // machine to OOM. #if SANITIZER_CAN_USE_ALLOCATOR64 && !SANITIZER_WINDOWS64 && !SANITIZER_ANDROID typedef SizeClassMap<3, 4, 8, 63, 128, 16> SpecialSizeClassMap; +template <typename AddressSpaceViewTy = LocalAddressSpaceView> struct AP64_SpecialSizeClassMap { static const uptr kSpaceBeg = kAllocatorSpace; static const uptr kSpaceSize = kAllocatorSize; @@ -1010,12 +1041,13 @@ struct AP64_SpecialSizeClassMap { typedef SpecialSizeClassMap SizeClassMap; typedef NoOpMapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = AddressSpaceViewTy; }; // Regression test for out-of-memory condition in PopulateFreeList(). TEST(SanitizerCommon, SizeClassAllocator64PopulateFreeListOOM) { // In a world where regions are small and chunks are huge... - typedef SizeClassAllocator64<AP64_SpecialSizeClassMap> SpecialAllocator64; + typedef SizeClassAllocator64<AP64_SpecialSizeClassMap<>> SpecialAllocator64; const uptr kRegionSize = kAllocatorSize / SpecialSizeClassMap::kNumClassesRounded; SpecialAllocator64 *a = new SpecialAllocator64; diff --git a/compiler-rt/lib/scudo/scudo_allocator.h b/compiler-rt/lib/scudo/scudo_allocator.h index 869e74a5ef2..814bb08ab01 100644 --- a/compiler-rt/lib/scudo/scudo_allocator.h +++ b/compiler-rt/lib/scudo/scudo_allocator.h @@ -81,6 +81,7 @@ struct AP64 { typedef NoOpMapUnmapCallback MapUnmapCallback; static const uptr kFlags = SizeClassAllocator64FlagMasks::kRandomShuffleChunks; + using AddressSpaceView = LocalAddressSpaceView; }; typedef SizeClassAllocator64<AP64> PrimaryT; #else diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index 60e6f82f72e..3410be29450 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -81,6 +81,7 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name. typedef DefaultSizeClassMap SizeClassMap; typedef __tsan::MapUnmapCallback MapUnmapCallback; static const uptr kFlags = 0; + using AddressSpaceView = LocalAddressSpaceView; }; typedef SizeClassAllocator64<AP64> PrimaryAllocator; #endif |