Skip to content

Commit 4563b78

Browse files
author
Kostya Kortchinsky
committedApr 13, 2018
[sanitizer] Allow for the allocator "names" to be set by the tools
Summary: In the same spirit of SanitizerToolName, allow the Primary & Secondary allocators to have names that can be set by the tools via PrimaryAllocatorName and SecondaryAllocatorName. Additionally, set a non-default name for Scudo. Reviewers: alekseyshl, vitalybuka Reviewed By: alekseyshl, vitalybuka Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D45600 llvm-svn: 330055
1 parent 3ede11b commit 4563b78

7 files changed

+20
-9
lines changed
 

‎compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
namespace __sanitizer {
2323

24+
// Default allocator names.
25+
const char *PrimaryAllocatorName = "SizeClassAllocator";
26+
const char *SecondaryAllocatorName = "LargeMmapAllocator";
27+
2428
// ThreadSanitizer for Go uses libc malloc/free.
2529
#if SANITIZER_GO || defined(SANITIZER_USE_MALLOC)
2630
# if SANITIZER_LINUX && !SANITIZER_ANDROID

‎compiler-rt/lib/sanitizer_common/sanitizer_allocator.h

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
namespace __sanitizer {
2626

27+
// Allows the tools to name their allocations appropriately.
28+
extern const char *PrimaryAllocatorName;
29+
extern const char *SecondaryAllocatorName;
30+
2731
// Since flags are immutable and allocator behavior can be changed at runtime
2832
// (unit tests or ASan on Android are some examples), allocator_may_return_null
2933
// flag value is cached here and can be altered later.

‎compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class SizeClassAllocator32 {
125125
}
126126

127127
void *MapWithCallback(uptr size) {
128-
void *res = MmapOrDie(size, "SizeClassAllocator32");
128+
void *res = MmapOrDie(size, PrimaryAllocatorName);
129129
MapUnmapCallback().OnMap((uptr)res, size);
130130
return res;
131131
}
@@ -286,7 +286,7 @@ class SizeClassAllocator32 {
286286
uptr AllocateRegion(AllocatorStats *stat, uptr class_id) {
287287
CHECK_LT(class_id, kNumClasses);
288288
uptr res = reinterpret_cast<uptr>(MmapAlignedOrDieOnFatalError(
289-
kRegionSize, kRegionSize, "SizeClassAllocator32"));
289+
kRegionSize, kRegionSize, PrimaryAllocatorName));
290290
if (UNLIKELY(!res))
291291
return 0;
292292
MapUnmapCallback().OnMap(res, kRegionSize);

‎compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ class SizeClassAllocator64 {
7272
void Init(s32 release_to_os_interval_ms) {
7373
uptr TotalSpaceSize = kSpaceSize + AdditionalSize();
7474
if (kUsingConstantSpaceBeg) {
75-
CHECK_EQ(kSpaceBeg, address_range.Init(TotalSpaceSize, AllocatorName(),
76-
kSpaceBeg));
75+
CHECK_EQ(kSpaceBeg, address_range.Init(TotalSpaceSize,
76+
PrimaryAllocatorName, kSpaceBeg));
7777
} else {
78-
NonConstSpaceBeg = address_range.Init(TotalSpaceSize, AllocatorName());
78+
NonConstSpaceBeg = address_range.Init(TotalSpaceSize,
79+
PrimaryAllocatorName);
7980
CHECK_NE(NonConstSpaceBeg, ~(uptr)0);
8081
}
8182
SetReleaseToOSIntervalMs(release_to_os_interval_ms);
@@ -546,7 +547,6 @@ class SizeClassAllocator64 {
546547
friend class MemoryMapper;
547548

548549
ReservedAddressRange address_range;
549-
static const char *AllocatorName() { return "sanitizer_allocator"; }
550550

551551
static const uptr kRegionSize = kSpaceSize / kNumClassesRounded;
552552
// FreeArray is the array of free-d chunks (stored as 4-byte offsets).

‎compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class LargeMmapAllocatorPtrArrayDynamic {
3434
public:
3535
INLINE void *Init() {
3636
uptr p = address_range_.Init(kMaxNumChunks * sizeof(uptr),
37-
"sanitizer_large_allocator");
37+
SecondaryAllocatorName);
3838
CHECK(p);
3939
return reinterpret_cast<void*>(p);
4040
}
@@ -94,7 +94,7 @@ class LargeMmapAllocator {
9494
return nullptr;
9595
}
9696
uptr map_beg = reinterpret_cast<uptr>(
97-
MmapOrDieOnFatalError(map_size, "LargeMmapAllocator"));
97+
MmapOrDieOnFatalError(map_size, SecondaryAllocatorName));
9898
if (!map_beg)
9999
return nullptr;
100100
CHECK(IsAligned(map_beg, page_size_));

‎compiler-rt/lib/scudo/scudo_allocator.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ struct ScudoAllocator {
278278

279279
void init() {
280280
SanitizerToolName = "Scudo";
281+
PrimaryAllocatorName = "ScudoPrimary";
282+
SecondaryAllocatorName = "ScudoSecondary";
283+
281284
initFlags();
282285

283286
performSanityChecks();

‎compiler-rt/lib/scudo/scudo_allocator_secondary.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ScudoLargeMmapAllocator {
8989
ReservedSize += 2 * PageSize;
9090

9191
ReservedAddressRange AddressRange;
92-
uptr ReservedBeg = AddressRange.Init(ReservedSize);
92+
uptr ReservedBeg = AddressRange.Init(ReservedSize, SecondaryAllocatorName);
9393
if (UNLIKELY(ReservedBeg == ~static_cast<uptr>(0)))
9494
return ReturnNullOrDieOnFailure::OnOOM();
9595
// A page-aligned pointer is assumed after that, so check it now.

0 commit comments

Comments
 (0)
Please sign in to comment.