Index: lib/sanitizer_common/sanitizer_mac.cc =================================================================== --- lib/sanitizer_common/sanitizer_mac.cc +++ lib/sanitizer_common/sanitizer_mac.cc @@ -798,13 +798,32 @@ char **GetArgv() { return *_NSGetArgv(); } + +// These constants are normally provided by the macOS SDK, but only in 10.12+. +// We want to be able to build against older SDKs, so declare them manually. +static const int kTaskVmInfoCount = 42; +static const int kTaskVmInfoMaxAddressOffset = 40; + +uptr GetTaskInfoMaxAddress() { + integer_t vm_info[kTaskVmInfoCount] = {0}; + mach_msg_type_number_t count = kTaskVmInfoCount; + int err = task_info(mach_task_self(), TASK_VM_INFO, vm_info, &count); + if (err == 0) { + return *(uptr *)(&vm_info[kTaskVmInfoMaxAddressOffset]) - 1; + } else { + // xnu cannot provide vm address limit + return 0x200000000 - 1; + } +} uptr GetMaxVirtualAddress() { #if SANITIZER_WORDSIZE == 64 # if defined(__aarch64__) && SANITIZER_IOS && !SANITIZER_IOSSIM - // Ideally, we would derive the upper bound from MACH_VM_MAX_ADDRESS. The - // upper bound can change depending on the device. - return 0x200000000 - 1; + // Get the maximum VM address + static uptr max_vm = 0; + if (max_vm == 0) max_vm = GetTaskInfoMaxAddress(); + CHECK(max_vm); + return max_vm; # else return (1ULL << 47) - 1; // 0x00007fffffffffffUL; # endif