diff options
author | Alexander Potapenko <glider@google.com> | 2013-07-16 09:29:48 +0000 |
---|---|---|
committer | Alexander Potapenko <glider@google.com> | 2013-07-16 09:29:48 +0000 |
commit | 27155281db3c8edd12f300bc6d2657eb0ec564ba (patch) | |
tree | 00f416b6ba08b9d172241b64069e5cadb2a4846c /compiler-rt/lib | |
parent | 75429adb4d02432471c0625892c798ca775dd0a4 (diff) | |
download | bcm5719-llvm-27155281db3c8edd12f300bc6d2657eb0ec564ba.tar.gz bcm5719-llvm-27155281db3c8edd12f300bc6d2657eb0ec564ba.zip |
[ASan] Cache the OSX version to avoid calling sysctl() on every GetMacosVersion() call.
llvm-svn: 186389
Diffstat (limited to 'compiler-rt/lib')
-rw-r--r-- | compiler-rt/lib/asan/asan_mac.cc | 17 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_mac.h | 7 |
2 files changed, 20 insertions, 4 deletions
diff --git a/compiler-rt/lib/asan/asan_mac.cc b/compiler-rt/lib/asan/asan_mac.cc index f78453686d4..920083765f3 100644 --- a/compiler-rt/lib/asan/asan_mac.cc +++ b/compiler-rt/lib/asan/asan_mac.cc @@ -21,6 +21,7 @@ #include "asan_mapping.h" #include "asan_stack.h" #include "asan_thread.h" +#include "sanitizer_common/sanitizer_atomic.h" #include "sanitizer_common/sanitizer_libc.h" #include <crt_externs.h> // for _NSGetArgv @@ -52,7 +53,9 @@ void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) { # endif // SANITIZER_WORDSIZE } -int GetMacosVersion() { +MacosVersion cached_macos_version = MACOS_VERSION_UNINITIALIZED; + +MacosVersion GetMacosVersionInternal() { int mib[2] = { CTL_KERN, KERN_OSRELEASE }; char version[100]; uptr len = 0, maxlen = sizeof(version) / sizeof(version[0]); @@ -76,6 +79,18 @@ int GetMacosVersion() { } } +MacosVersion GetMacosVersion() { + atomic_uint32_t *cache = + reinterpret_cast<atomic_uint32_t*>(&cached_macos_version); + MacosVersion result = + static_cast<MacosVersion>(atomic_load(cache, memory_order_acquire)); + if (result == MACOS_VERSION_UNINITIALIZED) { + result = GetMacosVersionInternal(); + atomic_store(cache, result, memory_order_release); + } + return result; +} + bool PlatformHasDifferentMemcpyAndMemmove() { // On OS X 10.7 memcpy() and memmove() are both resolved // into memmove$VARIANT$sse42. diff --git a/compiler-rt/lib/asan/asan_mac.h b/compiler-rt/lib/asan/asan_mac.h index c0063e05deb..827b8b00169 100644 --- a/compiler-rt/lib/asan/asan_mac.h +++ b/compiler-rt/lib/asan/asan_mac.h @@ -36,8 +36,9 @@ typedef struct __CFRuntimeBase { #endif } CFRuntimeBase; -enum { - MACOS_VERSION_UNKNOWN = 0, +enum MacosVersion { + MACOS_VERSION_UNINITIALIZED = 0, + MACOS_VERSION_UNKNOWN, MACOS_VERSION_LEOPARD, MACOS_VERSION_SNOW_LEOPARD, MACOS_VERSION_LION, @@ -50,7 +51,7 @@ extern "C" void __CFInitialize(); namespace __asan { -int GetMacosVersion(); +MacosVersion GetMacosVersion(); void MaybeReplaceCFAllocator(); } // namespace __asan |