[PATCH] D35032: [sanitizer] Use TASK_VM_INFO to get the maximum VM address on iOS/AArch64
Kuba (Brecka) Mracek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 5 13:59:54 PDT 2017
kubamracek created this revision.
kubamracek added a project: Sanitizers.
Herald added subscribers: kristof.beyls, rengolin, aemerson.
We currently hardcode the maximum VM address on iOS/AArch64, which is not really correct and this value changes between device configurations. Let's use TASK_VM_INFO to retrieve the maximum VM address dynamically.
The patch manually declares some constants, which would normally be provided in a header file by the SDK, but since this API is only declared in a recent SDK and we want to continue supporting building against older SDKs, the patch declares the constants manually.
Repository:
rL LLVM
https://reviews.llvm.org/D35032
Files:
lib/sanitizer_common/sanitizer_mac.cc
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35032.105333.patch
Type: text/x-patch
Size: 1416 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170705/f73e973e/attachment.bin>
More information about the llvm-commits
mailing list