Skip to content

Commit 79ea987

Browse files
committed
[compiler-rt] assert max virtual address is <= mmap range size
If these sizes do not match, asan will not work as expected. If possible, assert at compile time that the vm size is less than or equal to mmap range. If a compile time assert is not possible, check at run time (for iOS) rdar://76477969 Reviewed By: delcypher, yln Differential Revision: https://reviews.llvm.org/D100239 (cherry picked from commit cc2b62a)
1 parent 4a196a0 commit 79ea987

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,26 +1178,33 @@ static uptr GetTaskInfoMaxAddress() {
11781178

11791179
uptr GetMaxUserVirtualAddress() {
11801180
static uptr max_vm = GetTaskInfoMaxAddress();
1181-
if (max_vm != 0)
1181+
if (max_vm != 0) {
11821182
return max_vm - 1;
1183+
}
11831184

11841185
// xnu cannot provide vm address limit
11851186
# if SANITIZER_WORDSIZE == 32
1186-
return 0xffe00000 - 1;
1187+
constexpr uptr fallback_max_vm = 0xffe00000 - 1;
11871188
# else
1188-
return 0x200000000 - 1;
1189+
constexpr uptr fallback_max_vm = 0x200000000 - 1;
11891190
# endif
1191+
static_assert(fallback_max_vm <= SANITIZER_MMAP_RANGE_SIZE,
1192+
"Max virtual address must be less than mmap range size.");
1193+
return fallback_max_vm;
11901194
}
11911195

11921196
#else // !SANITIZER_IOS
11931197

11941198
uptr GetMaxUserVirtualAddress() {
11951199
# if SANITIZER_WORDSIZE == 64
1196-
return (1ULL << 47) - 1; // 0x00007fffffffffffUL;
1200+
constexpr uptr max_vm = (1ULL << 47) - 1; // 0x00007fffffffffffUL;
11971201
# else // SANITIZER_WORDSIZE == 32
11981202
static_assert(SANITIZER_WORDSIZE == 32, "Wrong wordsize");
1199-
return (1ULL << 32) - 1; // 0xffffffff;
1203+
constexpr uptr max_vm = (1ULL << 32) - 1; // 0xffffffff;
12001204
# endif
1205+
static_assert(max_vm <= SANITIZER_MMAP_RANGE_SIZE,
1206+
"Max virtual address must be less than mmap range size.");
1207+
return max_vm;
12011208
}
12021209
#endif
12031210

0 commit comments

Comments
 (0)