[compiler-rt] r186389 - [ASan] Cache the OSX version to avoid calling sysctl() on every GetMacosVersion() call.
Alexander Potapenko
glider at google.com
Tue Jul 16 02:29:48 PDT 2013
Author: glider
Date: Tue Jul 16 04:29:48 2013
New Revision: 186389
URL: http://llvm.org/viewvc/llvm-project?rev=186389&view=rev
Log:
[ASan] Cache the OSX version to avoid calling sysctl() on every GetMacosVersion() call.
Modified:
compiler-rt/trunk/lib/asan/asan_mac.cc
compiler-rt/trunk/lib/asan/asan_mac.h
Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=186389&r1=186388&r2=186389&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Tue Jul 16 04:29:48 2013
@@ -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,
# 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.
Modified: compiler-rt/trunk/lib/asan/asan_mac.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.h?rev=186389&r1=186388&r2=186389&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.h (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.h Tue Jul 16 04:29:48 2013
@@ -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
More information about the llvm-commits
mailing list