From 14e0d9ed89ac50b885ef6419aa3128090d85fe3c Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Fri, 21 Dec 2018 21:22:27 +0000 Subject: [PATCH] Introduce `AddressSpaceView` template parameter to `CombinedAllocator`. Summary: This is a follow up to https://reviews.llvm.org/D55764 . For the ASan and LSan allocatorsthe type declarations have been modified so that it's possible to create a combined allocator type that consistently uses a different type of `AddressSpaceView`. We intend to use this in future patches. For the other sanitizers they just use `LocalAddressSpaceView` by default because we have no plans to use these allocators in an out-of-process manner. rdar://problem/45284065 Reviewers: kcc, dvyukov, vitalybuka, cryptoad, eugenis, kubamracek, george.karpenkov, yln Subscribers: #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D55766 llvm-svn: 349957 --- compiler-rt/lib/asan/asan_allocator.h | 18 ++++++++++++++---- compiler-rt/lib/lsan/lsan_allocator.cc | 3 --- compiler-rt/lib/lsan/lsan_allocator.h | 18 +++++++++++++++++- .../sanitizer_common/sanitizer_allocator_combined.h | 11 +++++++++-- .../sanitizer_common/sanitizer_allocator_secondary.h | 3 ++- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/compiler-rt/lib/asan/asan_allocator.h b/compiler-rt/lib/asan/asan_allocator.h index 209532e..c9b37dc 100644 --- a/compiler-rt/lib/asan/asan_allocator.h +++ b/compiler-rt/lib/asan/asan_allocator.h @@ -192,11 +192,21 @@ using PrimaryAllocator = PrimaryAllocatorASVT; #endif // SANITIZER_CAN_USE_ALLOCATOR64 static const uptr kNumberOfSizeClasses = SizeClassMap::kNumClasses; -typedef SizeClassAllocatorLocalCache AllocatorCache; -typedef LargeMmapAllocator SecondaryAllocator; -typedef CombinedAllocator AsanAllocator; +template +using AllocatorCacheASVT = + SizeClassAllocatorLocalCache>; +using AllocatorCache = AllocatorCacheASVT; +template +using SecondaryAllocatorASVT = + LargeMmapAllocator; +template +using AsanAllocatorASVT = + CombinedAllocator, + AllocatorCacheASVT, + SecondaryAllocatorASVT>; +using AsanAllocator = AsanAllocatorASVT; struct AsanThreadLocalMallocStorage { uptr quarantine_cache[16]; diff --git a/compiler-rt/lib/lsan/lsan_allocator.cc b/compiler-rt/lib/lsan/lsan_allocator.cc index c58c354..1b338bd 100644 --- a/compiler-rt/lib/lsan/lsan_allocator.cc +++ b/compiler-rt/lib/lsan/lsan_allocator.cc @@ -34,9 +34,6 @@ static const uptr kMaxAllowedMallocSize = 4UL << 30; #else static const uptr kMaxAllowedMallocSize = 8UL << 30; #endif -typedef LargeMmapAllocator<> SecondaryAllocator; -typedef CombinedAllocator Allocator; static Allocator allocator; diff --git a/compiler-rt/lib/lsan/lsan_allocator.h b/compiler-rt/lib/lsan/lsan_allocator.h index 29ea2b6..4c4e02f 100644 --- a/compiler-rt/lib/lsan/lsan_allocator.h +++ b/compiler-rt/lib/lsan/lsan_allocator.h @@ -96,7 +96,23 @@ template using PrimaryAllocatorASVT = SizeClassAllocator64>; using PrimaryAllocator = PrimaryAllocatorASVT; #endif -typedef SizeClassAllocatorLocalCache AllocatorCache; + +template +using AllocatorCacheASVT = + SizeClassAllocatorLocalCache>; +using AllocatorCache = AllocatorCacheASVT; + +template +using SecondaryAllocatorASVT = + LargeMmapAllocator; + +template +using AllocatorASVT = + CombinedAllocator, + AllocatorCacheASVT, + SecondaryAllocatorASVT>; +using Allocator = AllocatorASVT; AllocatorCache *GetAllocatorCache(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h index 1f874d6..2dec5d8 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h @@ -21,9 +21,11 @@ // PrimaryAllocator is used via a local AllocatorCache. // SecondaryAllocator can allocate anything, but is not efficient. template // NOLINT + class SecondaryAllocator, + typename AddressSpaceViewTy = LocalAddressSpaceView> // NOLINT class CombinedAllocator { public: + using AddressSpaceView = AddressSpaceViewTy; void InitLinkerInitialized(s32 release_to_os_interval_ms) { primary_.Init(release_to_os_interval_ms); secondary_.InitLinkerInitialized(); @@ -31,6 +33,12 @@ class CombinedAllocator { } void Init(s32 release_to_os_interval_ms) { + static_assert(is_same::value, + "PrimaryAllocator is using wrong AddressSpaceView"); + static_assert(is_same::value, + "SecondaryAllocator is using wrong AddressSpaceView"); primary_.Init(release_to_os_interval_ms); secondary_.Init(); stats_.Init(); @@ -194,4 +202,3 @@ class CombinedAllocator { SecondaryAllocator secondary_; AllocatorGlobalStats stats_; }; - diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h index 455fcf3..e628a79 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h @@ -69,9 +69,10 @@ typedef LargeMmapAllocatorPtrArrayDynamic DefaultLargeMmapAllocatorPtrArray; // sizes not covered by more efficient allocators (e.g. SizeClassAllocator64). template + class AddressSpaceViewTy = LocalAddressSpaceView> class LargeMmapAllocator { public: + using AddressSpaceView = AddressSpaceViewTy; void InitLinkerInitialized() { page_size_ = GetPageSizeCached(); chunks_ = reinterpret_cast(ptr_array_.Init()); -- 2.7.4