Skip to content

[sanitizer] Warn if allocator size exceeds max user virtual address #152428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ class SizeClassAllocator64 {
// ~(uptr)0.
void Init(s32 release_to_os_interval_ms, uptr heap_start = 0) {
uptr TotalSpaceSize = kSpaceSize + AdditionalSize();

uptr MaxAddr = GetMaxUserVirtualAddress();
// VReport does not call the sanitizer allocator.
VReport(3, "Max user virtual address: 0x%zx\n", MaxAddr);
VReport(3, "Total space size for primary allocator: 0x%zx\n",
TotalSpaceSize);
// TODO: revise the check if we ever configure sanitizers to deliberately
// map beyond the 2**48 barrier (note that Linux pretends the VMA is
// limited to 48-bit for backwards compatibility, but allows apps to
// explicitly specify an address beyond that).
if (heap_start + TotalSpaceSize >= MaxAddr) {
// We can't easily adjust the requested heap size, because kSpaceSize is
// const (for optimization) and used throughout the code.
VReport(0, "Error: heap size %zx exceeds max user virtual address %zx\n",
TotalSpaceSize, MaxAddr);
VReport(
0, "Try using a kernel that allows a larger virtual address space\n");
}
PremappedHeap = heap_start != 0;
if (PremappedHeap) {
CHECK(!kUsingConstantSpaceBeg);
Expand Down
Loading