Skip to content

Commit 3db2a7a

Browse files
committed
[lsan] Use SANITIZER_WORDSIZE when selecting ByteMap
Originally this code as added for 64-bit platform and was never changed. Add static_assert to make sure that we have correct map on all platforms. llvm-svn: 359269
1 parent 98b70f6 commit 3db2a7a

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

compiler-rt/lib/lsan/lsan_allocator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,15 @@ struct ChunkMetadata {
5353
defined(__arm__)
5454
static const uptr kRegionSizeLog = 20;
5555
static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;
56+
57+
#if SANITIZER_WORDSIZE == 32
58+
template <typename AddressSpaceView>
59+
using ByteMapASVT = FlatByteMap<kNumRegions, AddressSpaceView>;
60+
#elif SANITIZER_WORDSIZE == 64
5661
template <typename AddressSpaceView>
5762
using ByteMapASVT =
5863
TwoLevelByteMap<(kNumRegions >> 12), 1 << 12, AddressSpaceView>;
64+
#endif
5965

6066
template <typename AddressSpaceViewTy>
6167
struct AP32 {

compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static const uptr kInternalAllocatorNumRegions =
2727
SANITIZER_MMAP_RANGE_SIZE >> kInternalAllocatorRegionSizeLog;
2828
#if SANITIZER_WORDSIZE == 32
2929
typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap;
30-
#else
30+
#elif SANITIZER_WORDSIZE == 64
3131
typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
3232
#endif
3333
struct AP32 {

compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct SizeClassAllocator32FlagMasks { // Bit masks.
4141
enum {
4242
kRandomShuffleChunks = 1,
4343
kUseSeparateSizeClassForBatch = 2,
44+
kForTest = 4,
4445
};
4546
};
4647

@@ -56,7 +57,20 @@ class SizeClassAllocator32 {
5657
typedef typename Params::ByteMap ByteMap;
5758
typedef typename Params::MapUnmapCallback MapUnmapCallback;
5859

60+
#if SANITIZER_WORDSIZE == 32
61+
using BM = FlatByteMap<(Params::kSpaceSize >> Params::kRegionSizeLog),
62+
AddressSpaceView>;
63+
#elif SANITIZER_WORDSIZE == 64
64+
using BM =
65+
TwoLevelByteMap<((Params::kSpaceSize >> Params::kRegionSizeLog) >> 12),
66+
1 << 12, AddressSpaceView, MapUnmapCallback>;
67+
#endif
68+
static_assert((Params::kFlags & SizeClassAllocator32FlagMasks::kForTest) ||
69+
is_same<BM, ByteMap>::value,
70+
"Unexpected ByteMap type");
71+
5972
static_assert(
73+
6074
is_same<typename ByteMap::AddressSpaceView, AddressSpaceView>::value,
6175
"AddressSpaceView type mismatch");
6276

compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct AP64 { // Allocator Params. Short name for shorter demangled names..
5959
static const uptr kMetadataSize = 16;
6060
typedef ::SizeClassMap SizeClassMap;
6161
typedef NoOpMapUnmapCallback MapUnmapCallback;
62-
static const uptr kFlags = 0;
62+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
6363
using AddressSpaceView = AddressSpaceViewTy;
6464
};
6565

@@ -70,7 +70,7 @@ struct AP64Dyn {
7070
static const uptr kMetadataSize = 16;
7171
typedef ::SizeClassMap SizeClassMap;
7272
typedef NoOpMapUnmapCallback MapUnmapCallback;
73-
static const uptr kFlags = 0;
73+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
7474
using AddressSpaceView = AddressSpaceViewTy;
7575
};
7676

@@ -81,7 +81,7 @@ struct AP64Compact {
8181
static const uptr kMetadataSize = 16;
8282
typedef CompactSizeClassMap SizeClassMap;
8383
typedef NoOpMapUnmapCallback MapUnmapCallback;
84-
static const uptr kFlags = 0;
84+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
8585
using AddressSpaceView = AddressSpaceViewTy;
8686
};
8787

@@ -92,7 +92,7 @@ struct AP64VeryCompact {
9292
static const uptr kMetadataSize = 16;
9393
typedef VeryCompactSizeClassMap SizeClassMap;
9494
typedef NoOpMapUnmapCallback MapUnmapCallback;
95-
static const uptr kFlags = 0;
95+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
9696
using AddressSpaceView = AddressSpaceViewTy;
9797
};
9898

@@ -103,7 +103,7 @@ struct AP64Dense {
103103
static const uptr kMetadataSize = 16;
104104
typedef DenseSizeClassMap SizeClassMap;
105105
typedef NoOpMapUnmapCallback MapUnmapCallback;
106-
static const uptr kFlags = 0;
106+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
107107
using AddressSpaceView = AddressSpaceViewTy;
108108
};
109109

@@ -155,7 +155,7 @@ struct AP32Compact {
155155
using AddressSpaceView = AddressSpaceViewTy;
156156
using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
157157
typedef NoOpMapUnmapCallback MapUnmapCallback;
158-
static const uptr kFlags = 0;
158+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
159159
};
160160
template <typename AddressSpaceView>
161161
using Allocator32CompactASVT =
@@ -302,7 +302,8 @@ struct AP32SeparateBatches {
302302
using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
303303
typedef NoOpMapUnmapCallback MapUnmapCallback;
304304
static const uptr kFlags =
305-
SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch;
305+
SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch |
306+
SizeClassAllocator32FlagMasks::kForTest;
306307
};
307308
template <typename AddressSpaceView>
308309
using Allocator32SeparateBatchesASVT =
@@ -438,7 +439,7 @@ struct AP64WithCallback {
438439
static const uptr kMetadataSize = 16;
439440
typedef ::SizeClassMap SizeClassMap;
440441
typedef TestMapUnmapCallback MapUnmapCallback;
441-
static const uptr kFlags = 0;
442+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
442443
using AddressSpaceView = AddressSpaceViewTy;
443444
};
444445

@@ -476,7 +477,7 @@ struct AP32WithCallback {
476477
using AddressSpaceView = AddressSpaceViewTy;
477478
using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
478479
typedef TestMapUnmapCallback MapUnmapCallback;
479-
static const uptr kFlags = 0;
480+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
480481
};
481482

482483
TEST(SanitizerCommon, SizeClassAllocator32MapUnmapCallback) {
@@ -1039,7 +1040,7 @@ struct AP64_SpecialSizeClassMap {
10391040
static const uptr kMetadataSize = 0;
10401041
typedef SpecialSizeClassMap SizeClassMap;
10411042
typedef NoOpMapUnmapCallback MapUnmapCallback;
1042-
static const uptr kFlags = 0;
1043+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
10431044
using AddressSpaceView = AddressSpaceViewTy;
10441045
};
10451046

compiler-rt/lib/tsan/rtl/tsan_rtl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct AP32 {
6969
using AddressSpaceView = LocalAddressSpaceView;
7070
using ByteMap = __tsan::ByteMap;
7171
typedef __tsan::MapUnmapCallback MapUnmapCallback;
72-
static const uptr kFlags = 0;
72+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
7373
};
7474
typedef SizeClassAllocator32<AP32> PrimaryAllocator;
7575
#else
@@ -79,7 +79,7 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name.
7979
static const uptr kMetadataSize = 0;
8080
typedef DefaultSizeClassMap SizeClassMap;
8181
typedef __tsan::MapUnmapCallback MapUnmapCallback;
82-
static const uptr kFlags = 0;
82+
static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
8383
using AddressSpaceView = LocalAddressSpaceView;
8484
};
8585
typedef SizeClassAllocator64<AP64> PrimaryAllocator;

0 commit comments

Comments
 (0)