summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2019-04-27 06:30:52 +0000
committerVitaly Buka <vitalybuka@google.com>2019-04-27 06:30:52 +0000
commitf87d73402ed5e8f4de24441dce25b808df1cd73f (patch)
tree1a3dff124cc3aa4aa5b4c9144f224e3a821c29a0 /lib
parent308ab63c0c1fe152d323dde2bf877dc58ce0d0d8 (diff)
downloadcompiler-rt-f87d73402ed5e8f4de24441dce25b808df1cd73f.tar.gz
[sanitizer] Calculate SizeClassAllocator32::ByteMap type from Params::kSpaceSize and Params::kRegionSizeLog
Reviewers: eugenis Subscribers: kubamracek, cryptoad, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D61206 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@359374 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/asan/asan_allocator.h13
-rw-r--r--lib/lsan/lsan_allocator.h15
-rw-r--r--lib/msan/msan_allocator.cc12
-rw-r--r--lib/sanitizer_common/sanitizer_allocator_internal.h11
-rw-r--r--lib/sanitizer_common/sanitizer_allocator_primary32.h39
-rw-r--r--lib/sanitizer_common/tests/sanitizer_allocator_test.cc11
-rw-r--r--lib/scudo/scudo_allocator.h7
-rw-r--r--lib/tsan/rtl/tsan_rtl.h11
8 files changed, 17 insertions, 102 deletions
diff --git a/lib/asan/asan_allocator.h b/lib/asan/asan_allocator.h
index f00776c94..7b9e73066 100644
--- a/lib/asan/asan_allocator.h
+++ b/lib/asan/asan_allocator.h
@@ -166,16 +166,6 @@ 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;
-# if SANITIZER_WORDSIZE == 32
-template <typename AddressSpaceView>
-using ByteMapASVT = FlatByteMap<kNumRegions, AddressSpaceView>;
-# elif SANITIZER_WORDSIZE == 64
-template <typename AddressSpaceView>
-using ByteMapASVT =
- TwoLevelByteMap<(kNumRegions >> 12), 1 << 12, AddressSpaceView>;
-# endif
typedef CompactSizeClassMap SizeClassMap;
template <typename AddressSpaceViewTy>
struct AP32 {
@@ -183,9 +173,8 @@ struct AP32 {
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
static const uptr kMetadataSize = 16;
typedef __asan::SizeClassMap SizeClassMap;
- static const uptr kRegionSizeLog = __asan::kRegionSizeLog;
+ static const uptr kRegionSizeLog = 20;
using AddressSpaceView = AddressSpaceViewTy;
- using ByteMap = __asan::ByteMapASVT<AddressSpaceView>;
typedef AsanMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
};
diff --git a/lib/lsan/lsan_allocator.h b/lib/lsan/lsan_allocator.h
index e3bdfe8fe..f3888b944 100644
--- a/lib/lsan/lsan_allocator.h
+++ b/lib/lsan/lsan_allocator.h
@@ -51,27 +51,14 @@ struct ChunkMetadata {
#if defined(__mips64) || defined(__aarch64__) || defined(__i386__) || \
defined(__arm__)
-static const uptr kRegionSizeLog = 20;
-static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;
-
-#if SANITIZER_WORDSIZE == 32
-template <typename AddressSpaceView>
-using ByteMapASVT = FlatByteMap<kNumRegions, AddressSpaceView>;
-#elif SANITIZER_WORDSIZE == 64
-template <typename AddressSpaceView>
-using ByteMapASVT =
- TwoLevelByteMap<(kNumRegions >> 12), 1 << 12, AddressSpaceView>;
-#endif
-
template <typename AddressSpaceViewTy>
struct AP32 {
static const uptr kSpaceBeg = 0;
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
static const uptr kMetadataSize = sizeof(ChunkMetadata);
typedef __sanitizer::CompactSizeClassMap SizeClassMap;
- static const uptr kRegionSizeLog = __lsan::kRegionSizeLog;
+ static const uptr kRegionSizeLog = 20;
using AddressSpaceView = AddressSpaceViewTy;
- using ByteMap = __lsan::ByteMapASVT<AddressSpaceView>;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
};
diff --git a/lib/msan/msan_allocator.cc b/lib/msan/msan_allocator.cc
index 51e8704f1..48430b621 100644
--- a/lib/msan/msan_allocator.cc
+++ b/lib/msan/msan_allocator.cc
@@ -46,18 +46,14 @@ struct MsanMapUnmapCallback {
#if defined(__mips64)
static const uptr kMaxAllowedMallocSize = 2UL << 30;
-static const uptr kRegionSizeLog = 20;
-static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;
-typedef TwoLevelByteMap<(kNumRegions >> 12), 1 << 12> ByteMap;
struct AP32 {
static const uptr kSpaceBeg = 0;
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
static const uptr kMetadataSize = sizeof(Metadata);
typedef __sanitizer::CompactSizeClassMap SizeClassMap;
- static const uptr kRegionSizeLog = __msan::kRegionSizeLog;
+ static const uptr kRegionSizeLog = 20;
using AddressSpaceView = LocalAddressSpaceView;
- using ByteMap = __msan::ByteMap;
typedef MsanMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
};
@@ -99,18 +95,14 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name.
typedef SizeClassAllocator64<AP64> PrimaryAllocator;
#elif defined(__aarch64__)
static const uptr kMaxAllowedMallocSize = 2UL << 30; // 2G
-static const uptr kRegionSizeLog = 20;
-static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;
-typedef TwoLevelByteMap<(kNumRegions >> 12), 1 << 12> ByteMap;
struct AP32 {
static const uptr kSpaceBeg = 0;
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
static const uptr kMetadataSize = sizeof(Metadata);
typedef __sanitizer::CompactSizeClassMap SizeClassMap;
- static const uptr kRegionSizeLog = __msan::kRegionSizeLog;
+ static const uptr kRegionSizeLog = 20;
using AddressSpaceView = LocalAddressSpaceView;
- using ByteMap = __msan::ByteMap;
typedef MsanMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
};
diff --git a/lib/sanitizer_common/sanitizer_allocator_internal.h b/lib/sanitizer_common/sanitizer_allocator_internal.h
index 7066e3581..1b122f1bd 100644
--- a/lib/sanitizer_common/sanitizer_allocator_internal.h
+++ b/lib/sanitizer_common/sanitizer_allocator_internal.h
@@ -22,22 +22,13 @@ namespace __sanitizer {
// purposes.
typedef CompactSizeClassMap InternalSizeClassMap;
-static const uptr kInternalAllocatorRegionSizeLog = 20;
-static const uptr kInternalAllocatorNumRegions =
- SANITIZER_MMAP_RANGE_SIZE >> kInternalAllocatorRegionSizeLog;
-#if SANITIZER_WORDSIZE == 32
-typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap;
-#elif SANITIZER_WORDSIZE == 64
-typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
-#endif
struct AP32 {
static const uptr kSpaceBeg = 0;
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
static const uptr kMetadataSize = 0;
typedef InternalSizeClassMap SizeClassMap;
- static const uptr kRegionSizeLog = kInternalAllocatorRegionSizeLog;
+ static const uptr kRegionSizeLog = 20;
using AddressSpaceView = LocalAddressSpaceView;
- using ByteMap = __sanitizer::ByteMap;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
};
diff --git a/lib/sanitizer_common/sanitizer_allocator_primary32.h b/lib/sanitizer_common/sanitizer_allocator_primary32.h
index cb0cdbe1a..47dc45a47 100644
--- a/lib/sanitizer_common/sanitizer_allocator_primary32.h
+++ b/lib/sanitizer_common/sanitizer_allocator_primary32.h
@@ -41,23 +41,13 @@ struct SizeClassAllocator32FlagMasks { // Bit masks.
enum {
kRandomShuffleChunks = 1,
kUseSeparateSizeClassForBatch = 2,
- kForTest = 4,
};
};
-// This template is not necessary but t helps to see values if static_assert
-// fails.
-// FIXME: Replace check with automatic type detection. D61206
-template <bool Expected, u64 MinSize, u64 ActualSize>
-struct CheckTwoLevelByteMapSize {
- static_assert((ActualSize >= MinSize) == Expected,
- "Unexpected ByteMap type for the size");
-};
-
template <class Params>
class SizeClassAllocator32 {
private:
- static const u64 TwoLevelByteMapSize1 =
+ static const u64 kTwoLevelByteMapSize1 =
(Params::kSpaceSize >> Params::kRegionSizeLog) >> 12;
static const u64 kMinFirstMapSizeTwoLevelByteMap = 4;
@@ -68,29 +58,12 @@ class SizeClassAllocator32 {
static const uptr kMetadataSize = Params::kMetadataSize;
typedef typename Params::SizeClassMap SizeClassMap;
static const uptr kRegionSizeLog = Params::kRegionSizeLog;
- typedef typename Params::ByteMap ByteMap;
typedef typename Params::MapUnmapCallback MapUnmapCallback;
-
-#if SANITIZER_WORDSIZE == 32
- CheckTwoLevelByteMapSize<false, kMinFirstMapSizeTwoLevelByteMap,
- TwoLevelByteMapSize1>
- Check;
- using BM = FlatByteMap<(Params::kSpaceSize >> Params::kRegionSizeLog),
- AddressSpaceView>;
-#elif SANITIZER_WORDSIZE == 64
- CheckTwoLevelByteMapSize<true, kMinFirstMapSizeTwoLevelByteMap,
- TwoLevelByteMapSize1>
- Check;
- using BM = TwoLevelByteMap<TwoLevelByteMapSize1, 1 << 12, AddressSpaceView>;
-#endif
- static_assert((Params::kFlags & SizeClassAllocator32FlagMasks::kForTest) ||
- is_same<BM, ByteMap>::value,
- "Unexpected ByteMap type");
-
- static_assert(
-
- is_same<typename ByteMap::AddressSpaceView, AddressSpaceView>::value,
- "AddressSpaceView type mismatch");
+ using ByteMap = typename conditional<
+ (kTwoLevelByteMapSize1 < kMinFirstMapSizeTwoLevelByteMap),
+ FlatByteMap<(Params::kSpaceSize >> Params::kRegionSizeLog),
+ AddressSpaceView>,
+ TwoLevelByteMap<kTwoLevelByteMapSize1, 1 << 12, AddressSpaceView>>::type;
COMPILER_CHECK(!SANITIZER_SIGN_EXTENDED_ADDRESSES ||
(kSpaceSize & (kSpaceSize - 1)) == 0);
diff --git a/lib/sanitizer_common/tests/sanitizer_allocator_test.cc b/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
index dcbe46f6f..d19b37609 100644
--- a/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
+++ b/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
@@ -143,7 +143,6 @@ static const u64 kAddressSpaceSize = 1ULL << 32;
#endif
static const uptr kRegionSizeLog = FIRST_32_SECOND_64(20, 24);
-static const uptr kFlatByteMapSize = kAddressSpaceSize >> kRegionSizeLog;
template <typename AddressSpaceViewTy>
struct AP32Compact {
@@ -153,9 +152,8 @@ struct AP32Compact {
typedef CompactSizeClassMap SizeClassMap;
static const uptr kRegionSizeLog = ::kRegionSizeLog;
using AddressSpaceView = AddressSpaceViewTy;
- using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
typedef NoOpMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
+ static const uptr kFlags = 0;
};
template <typename AddressSpaceView>
using Allocator32CompactASVT =
@@ -299,11 +297,9 @@ struct AP32SeparateBatches {
typedef DefaultSizeClassMap SizeClassMap;
static const uptr kRegionSizeLog = ::kRegionSizeLog;
using AddressSpaceView = AddressSpaceViewTy;
- using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags =
- SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch |
- SizeClassAllocator32FlagMasks::kForTest;
+ SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch;
};
template <typename AddressSpaceView>
using Allocator32SeparateBatchesASVT =
@@ -475,9 +471,8 @@ struct AP32WithCallback {
typedef CompactSizeClassMap SizeClassMap;
static const uptr kRegionSizeLog = ::kRegionSizeLog;
using AddressSpaceView = AddressSpaceViewTy;
- using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
typedef TestMapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
+ static const uptr kFlags = 0;
};
TEST(SanitizerCommon, SizeClassAllocator32MapUnmapCallback) {
diff --git a/lib/scudo/scudo_allocator.h b/lib/scudo/scudo_allocator.h
index 0edcd120c..59225b681 100644
--- a/lib/scudo/scudo_allocator.h
+++ b/lib/scudo/scudo_allocator.h
@@ -84,12 +84,6 @@ struct AP64 {
};
typedef SizeClassAllocator64<AP64> PrimaryT;
#else
-static const uptr NumRegions = SANITIZER_MMAP_RANGE_SIZE >> RegionSizeLog;
-# if SANITIZER_WORDSIZE == 32
-typedef FlatByteMap<NumRegions> ByteMap;
-# elif SANITIZER_WORDSIZE == 64
-typedef TwoLevelByteMap<(NumRegions >> 12), 1 << 12> ByteMap;
-# endif // SANITIZER_WORDSIZE
struct AP32 {
static const uptr kSpaceBeg = 0;
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
@@ -97,7 +91,6 @@ struct AP32 {
typedef __scudo::SizeClassMap SizeClassMap;
static const uptr kRegionSizeLog = RegionSizeLog;
using AddressSpaceView = LocalAddressSpaceView;
- using ByteMap = __scudo::ByteMap;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags =
SizeClassAllocator32FlagMasks::kRandomShuffleChunks |
diff --git a/lib/tsan/rtl/tsan_rtl.h b/lib/tsan/rtl/tsan_rtl.h
index 033eb11c5..2c8ae29f3 100644
--- a/lib/tsan/rtl/tsan_rtl.h
+++ b/lib/tsan/rtl/tsan_rtl.h
@@ -55,21 +55,16 @@ namespace __tsan {
#if !SANITIZER_GO
struct MapUnmapCallback;
#if defined(__mips64) || defined(__aarch64__) || defined(__powerpc__)
-static const uptr kAllocatorRegionSizeLog = 20;
-static const uptr kAllocatorNumRegions =
- SANITIZER_MMAP_RANGE_SIZE >> kAllocatorRegionSizeLog;
-using ByteMap = TwoLevelByteMap<(kAllocatorNumRegions >> 12), 1 << 12,
- LocalAddressSpaceView, MapUnmapCallback>;
+
struct AP32 {
static const uptr kSpaceBeg = 0;
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
static const uptr kMetadataSize = 0;
typedef __sanitizer::CompactSizeClassMap SizeClassMap;
- static const uptr kRegionSizeLog = kAllocatorRegionSizeLog;
+ static const uptr kRegionSizeLog = 20;
using AddressSpaceView = LocalAddressSpaceView;
- using ByteMap = __tsan::ByteMap;
typedef __tsan::MapUnmapCallback MapUnmapCallback;
- static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
+ static const uptr kFlags = 0;
};
typedef SizeClassAllocator32<AP32> PrimaryAllocator;
#else