summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_mac.cc
diff options
context:
space:
mode:
authorKuba Mracek <mracek@apple.com>2017-07-06 20:30:09 +0000
committerKuba Mracek <mracek@apple.com>2017-07-06 20:30:09 +0000
commit501c0c7048cfaecb5ef02c34a5c38daac73f413c (patch)
treed6e932d5cba3a39649505b561d4ed717436ed2c3 /lib/sanitizer_common/sanitizer_mac.cc
parentb3b4445f1acf7a28712a0b36d973265512ca68fc (diff)
[sanitizer] Use TASK_VM_INFO to get the maximum VM address on iOS/AArch64
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. Differential Revision: https://reviews.llvm.org/D35032 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307307 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_mac.cc')
-rw-r--r--lib/sanitizer_common/sanitizer_mac.cc30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/sanitizer_common/sanitizer_mac.cc b/lib/sanitizer_common/sanitizer_mac.cc
index 7d027130d..70f6daeee 100644
--- a/lib/sanitizer_common/sanitizer_mac.cc
+++ b/lib/sanitizer_common/sanitizer_mac.cc
@@ -799,13 +799,37 @@ void MaybeReexec() {
char **GetArgv() {
return *_NSGetArgv();
}
+
+#if defined(__aarch64__) && SANITIZER_IOS && !SANITIZER_IOSSIM
+// The task_vm_info struct is normally provided by the macOS SDK, but we need
+// fields only available in 10.12+. Declare the struct manually to be able to
+// build against older SDKs.
+struct __sanitizer_task_vm_info {
+ uptr _unused[(SANITIZER_WORDSIZE == 32) ? 20 : 19];
+ uptr min_address;
+ uptr max_address;
+};
+
+uptr GetTaskInfoMaxAddress() {
+ __sanitizer_task_vm_info vm_info = {{0}, 0, 0};
+ mach_msg_type_number_t count = sizeof(vm_info) / sizeof(int);
+ int err = task_info(mach_task_self(), TASK_VM_INFO, (int *)&vm_info, &count);
+ if (err == 0) {
+ return vm_info.max_address;
+ } else {
+ // xnu cannot provide vm address limit
+ return 0x200000000 - 1;
+ }
+}
+#endif
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 = GetTaskInfoMaxAddress();
+ CHECK(max_vm);
+ return max_vm;
# else
return (1ULL << 47) - 1; // 0x00007fffffffffffUL;
# endif