diff options
-rw-r--r-- | compiler-rt/lib/asan/asan_mac.cc | 23 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_mac.h | 11 |
2 files changed, 34 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/asan_mac.cc b/compiler-rt/lib/asan/asan_mac.cc index 0d5d25c5afd..d4042d2849c 100644 --- a/compiler-rt/lib/asan/asan_mac.cc +++ b/compiler-rt/lib/asan/asan_mac.cc @@ -27,6 +27,7 @@ #include <mach-o/loader.h> #include <sys/mman.h> #include <sys/resource.h> +#include <sys/sysctl.h> #include <sys/ucontext.h> #include <pthread.h> #include <fcntl.h> @@ -58,6 +59,28 @@ void GetPcSpBp(void *context, uintptr_t *pc, uintptr_t *sp, uintptr_t *bp) { # endif // __WORDSIZE } +int GetMacosVersion() { + int mib[2] = { CTL_KERN, KERN_OSRELEASE }; + char version[100]; + size_t len = 0, maxlen = sizeof(version) / sizeof(version[0]); + for (int i = 0; i < maxlen; i++) version[i] = '\0'; + // Get the version length. + CHECK(sysctl(mib, 2, NULL, &len, NULL, 0) != -1); + CHECK(len < maxlen); + CHECK(sysctl(mib, 2, version, &len, NULL, 0) != -1); + switch (version[0]) { + case '9': return MACOS_VERSION_LEOPARD; + case '1': { + switch (version[1]) { + case '0': return MACOS_VERSION_SNOW_LEOPARD; + case '1': return MACOS_VERSION_LION; + default: return MACOS_VERSION_UNKNOWN; + } + } + default: return MACOS_VERSION_UNKNOWN; + } +} + // No-op. Mac does not support static linkage anyway. void *AsanDoesNotSupportStaticLinkage() { return NULL; diff --git a/compiler-rt/lib/asan/asan_mac.h b/compiler-rt/lib/asan/asan_mac.h index bb39f8206b4..e0ac5f6b7dd 100644 --- a/compiler-rt/lib/asan/asan_mac.h +++ b/compiler-rt/lib/asan/asan_mac.h @@ -24,6 +24,17 @@ #include <setjmp.h> #include <CoreFoundation/CFString.h> +enum { + MACOS_VERSION_UNKNOWN = 0, + MACOS_VERSION_LEOPARD, + MACOS_VERSION_SNOW_LEOPARD, + MACOS_VERSION_LION, +}; + +namespace __asan { +int GetMacosVersion(); +} + typedef void* pthread_workqueue_t; typedef void* pthread_workitem_handle_t; |