[llvm-commits] [compiler-rt] r149382 - in /compiler-rt/trunk/lib/asan: asan_mac.cc asan_mac.h
Alexander Potapenko
glider at google.com
Tue Jan 31 05:19:18 PST 2012
Author: glider
Date: Tue Jan 31 07:19:18 2012
New Revision: 149382
URL: http://llvm.org/viewvc/llvm-project?rev=149382&view=rev
Log:
Implement GetMacosVersion() to obtain the OS X version at runtime.
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=149382&r1=149381&r2=149382&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Tue Jan 31 07:19:18 2012
@@ -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 @@
# 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;
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=149382&r1=149381&r2=149382&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.h (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.h Tue Jan 31 07:19:18 2012
@@ -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;
More information about the llvm-commits
mailing list