Skip to content

Commit 7925732

Browse files
committed
[sanitizer] Warn if allocator size exceeds max user virtual address
This warns the user of incompatible configurations, such as 39-bit and 42-bit VMAs for AArch64 non-Android Linux ASan (#145259).
1 parent 01472d8 commit 7925732

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ class SizeClassAllocator64 {
113113
// ~(uptr)0.
114114
void Init(s32 release_to_os_interval_ms, uptr heap_start = 0) {
115115
uptr TotalSpaceSize = kSpaceSize + AdditionalSize();
116+
117+
uptr MaxAddr = GetMaxUserVirtualAddress();
118+
// VReport does not call the sanitizer allocator.
119+
VReport(3, "Max user virtual address: 0x%zx\n", MaxAddr);
120+
VReport(3, "Total space size for primary allocator: 0x%zx\n",
121+
TotalSpaceSize);
122+
if (TotalSpaceSize >= MaxAddr)
123+
VReport(0, "Error: heap size %zx exceeds max user virtual address %zx\n",
124+
TotalSpaceSize, MaxAddr);
125+
// We can't easily adjust the requested heap size, because kSpaceSize is
126+
// const (for optimization) and used throughout the code.
127+
116128
PremappedHeap = heap_start != 0;
117129
if (PremappedHeap) {
118130
CHECK(!kUsingConstantSpaceBeg);

0 commit comments

Comments
 (0)