[lsan] Use SANITIZER_WORDSIZE when selecting ByteMap

Originally this code was added for 64-bit platform and it was never update.
Add static_assert to validate type of ByteMap.

llvm-svn: 359286
This commit is contained in:
Vitaly Buka 2019-04-26 08:24:38 +00:00
parent 5be69bc68a
commit 1a607ff043
5 changed files with 34 additions and 13 deletions

View File

@ -53,9 +53,15 @@ struct ChunkMetadata {
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 {

View File

@ -27,7 +27,7 @@ static const uptr kInternalAllocatorNumRegions =
SANITIZER_MMAP_RANGE_SIZE >> kInternalAllocatorRegionSizeLog;
#if SANITIZER_WORDSIZE == 32
typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap;
#else
#elif SANITIZER_WORDSIZE == 64
typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
#endif
struct AP32 {

View File

@ -41,6 +41,7 @@ struct SizeClassAllocator32FlagMasks { // Bit masks.
enum {
kRandomShuffleChunks = 1,
kUseSeparateSizeClassForBatch = 2,
kForTest = 4,
};
};
@ -56,7 +57,20 @@ class SizeClassAllocator32 {
typedef typename Params::ByteMap ByteMap;
typedef typename Params::MapUnmapCallback MapUnmapCallback;
#if SANITIZER_WORDSIZE == 32
using BM = FlatByteMap<(Params::kSpaceSize >> Params::kRegionSizeLog),
AddressSpaceView>;
#elif SANITIZER_WORDSIZE == 64
using BM =
TwoLevelByteMap<((Params::kSpaceSize >> Params::kRegionSizeLog) >> 12),
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");

View File

@ -59,7 +59,7 @@ struct AP64 { // Allocator Params. Short name for shorter demangled names..
static const uptr kMetadataSize = 16;
typedef ::SizeClassMap SizeClassMap;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
using AddressSpaceView = AddressSpaceViewTy;
};
@ -70,7 +70,7 @@ struct AP64Dyn {
static const uptr kMetadataSize = 16;
typedef ::SizeClassMap SizeClassMap;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
using AddressSpaceView = AddressSpaceViewTy;
};
@ -81,7 +81,7 @@ struct AP64Compact {
static const uptr kMetadataSize = 16;
typedef CompactSizeClassMap SizeClassMap;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
using AddressSpaceView = AddressSpaceViewTy;
};
@ -92,7 +92,7 @@ struct AP64VeryCompact {
static const uptr kMetadataSize = 16;
typedef VeryCompactSizeClassMap SizeClassMap;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
using AddressSpaceView = AddressSpaceViewTy;
};
@ -103,7 +103,7 @@ struct AP64Dense {
static const uptr kMetadataSize = 16;
typedef DenseSizeClassMap SizeClassMap;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
using AddressSpaceView = AddressSpaceViewTy;
};
@ -155,7 +155,7 @@ struct AP32Compact {
using AddressSpaceView = AddressSpaceViewTy;
using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
};
template <typename AddressSpaceView>
using Allocator32CompactASVT =
@ -302,7 +302,8 @@ struct AP32SeparateBatches {
using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags =
SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch;
SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch |
SizeClassAllocator32FlagMasks::kForTest;
};
template <typename AddressSpaceView>
using Allocator32SeparateBatchesASVT =
@ -438,7 +439,7 @@ struct AP64WithCallback {
static const uptr kMetadataSize = 16;
typedef ::SizeClassMap SizeClassMap;
typedef TestMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
using AddressSpaceView = AddressSpaceViewTy;
};
@ -476,7 +477,7 @@ struct AP32WithCallback {
using AddressSpaceView = AddressSpaceViewTy;
using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
typedef TestMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
};
TEST(SanitizerCommon, SizeClassAllocator32MapUnmapCallback) {
@ -1039,7 +1040,7 @@ struct AP64_SpecialSizeClassMap {
static const uptr kMetadataSize = 0;
typedef SpecialSizeClassMap SizeClassMap;
typedef NoOpMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
using AddressSpaceView = AddressSpaceViewTy;
};

View File

@ -69,7 +69,7 @@ struct AP32 {
using AddressSpaceView = LocalAddressSpaceView;
using ByteMap = __tsan::ByteMap;
typedef __tsan::MapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
};
typedef SizeClassAllocator32<AP32> PrimaryAllocator;
#else
@ -79,7 +79,7 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name.
static const uptr kMetadataSize = 0;
typedef DefaultSizeClassMap SizeClassMap;
typedef __tsan::MapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
using AddressSpaceView = LocalAddressSpaceView;
};
typedef SizeClassAllocator64<AP64> PrimaryAllocator;