Skip to content

Commit 9faac93

Browse files
authored
[sanitizer] Warn if allocator size exceeds max user virtual address (llvm#152428)
This warns the user of incompatible configurations, such as 39-bit and 42-bit VMAs for AArch64 non-Android Linux ASan (llvm#145259).
1 parent 72bc1be commit 9faac93

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ 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+
// TODO: revise the check if we ever configure sanitizers to deliberately
123+
// map beyond the 2**48 barrier (note that Linux pretends the VMA is
124+
// limited to 48-bit for backwards compatibility, but allows apps to
125+
// explicitly specify an address beyond that).
126+
if (heap_start + TotalSpaceSize >= MaxAddr) {
127+
// We can't easily adjust the requested heap size, because kSpaceSize is
128+
// const (for optimization) and used throughout the code.
129+
VReport(0, "Error: heap size %zx exceeds max user virtual address %zx\n",
130+
TotalSpaceSize, MaxAddr);
131+
VReport(
132+
0, "Try using a kernel that allows a larger virtual address space\n");
133+
}
116134
PremappedHeap = heap_start != 0;
117135
if (PremappedHeap) {
118136
CHECK(!kUsingConstantSpaceBeg);

0 commit comments

Comments
 (0)