[llvm-commits] PATCH: AddressSanitizer: Make GetOSVersion available on all platforms (issue 5702060)
samsonov at google.com
samsonov at google.com
Wed Feb 29 06:08:42 PST 2012
Reviewers: timurrrr_at_google_com, kcc, ramosian.glider,
Please review this at http://codereview.appspot.com/5702060/
Affected files:
M asan_interceptors.cc
M asan_internal.h
M asan_linux.cc
M asan_mac.cc
M asan_mac.h
M asan_win.cc
-------------- next part --------------
Index: asan_mac.h
===================================================================
--- asan_mac.h (revision 151711)
+++ asan_mac.h (working copy)
@@ -21,17 +21,6 @@
#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;
Index: asan_internal.h
===================================================================
--- asan_internal.h (revision 151711)
+++ asan_internal.h (working copy)
@@ -246,6 +246,18 @@
void Exit(int exitcode);
int Atexit(void (*function)(void));
+enum OSVersion {
+ LINUX_UNKNOWN = 0,
+ LINUX_ANDROID,
+ WINDOWS_UNKNOWN,
+ MACOS_UNKNOWN,
+ MACOS_LEOPARD,
+ MACOS_SNOW_LEOPARD,
+ MACOS_LION
+};
+
+OSVersion GetOSVersion();
+
#define CHECK(cond) do { if (!(cond)) { \
CheckFailed(#cond, __FILE__, __LINE__); \
}}while(0)
Index: asan_interceptors.cc
===================================================================
--- asan_interceptors.cc (revision 151711)
+++ asan_interceptors.cc (working copy)
@@ -614,21 +614,17 @@
CHECK(INTERCEPT_FUNCTION(memcmp));
CHECK(INTERCEPT_FUNCTION(memmove));
CHECK(INTERCEPT_FUNCTION(memset));
-#ifdef __APPLE__
- // Wrap memcpy() on OS X 10.6 only, because on 10.7 memcpy() and memmove()
- // are resolved into memmove$VARIANT$sse42.
+
+ // Don't wrap memcpy() on OS X 10.7, because on 10.7 memcpy() and memmove()
+ // are both resolved into memmove$VARIANT$sse42.
// See also http://code.google.com/p/address-sanitizer/issues/detail?id=34.
// TODO(glider): need to check dynamically that memcpy() and memmove() are
// actually the same function.
- if (GetMacosVersion() == MACOS_VERSION_SNOW_LEOPARD) {
- CHECK(INTERCEPT_FUNCTION(memcpy));
- } else {
+ if (GetOSVersion() == MACOS_LION) {
REAL(memcpy) = REAL(memmove);
+ } else {
+ CHECK(INTERCEPT_FUNCTION(memcpy));
}
-#else
- // Always wrap memcpy() on non-Darwin platforms.
- CHECK(INTERCEPT_FUNCTION(memcpy));
-#endif
// Intercept str* functions.
CHECK(INTERCEPT_FUNCTION(strcat)); // NOLINT
Index: asan_win.cc
===================================================================
--- asan_win.cc (revision 151711)
+++ asan_win.cc (working copy)
@@ -28,6 +28,10 @@
namespace __asan {
+OSVersion GetOSVersion() {
+ return WINDOWS_UNKNOWN;
+}
+
// ---------------------- Memory management ---------------- {{{1
void *AsanMmapFixedNoReserve(uintptr_t fixed_addr, size_t size) {
return VirtualAlloc((LPVOID)fixed_addr, size,
Index: asan_linux.cc
===================================================================
--- asan_linux.cc (revision 151711)
+++ asan_linux.cc (working copy)
@@ -38,6 +38,14 @@
namespace __asan {
+OSVersion GetOSVersion() {
+#ifdef ANDROID
+ return LINUX_ANDROID;
+#else
+ return LINUX_UNKNOWN;
+#endif
+}
+
void *AsanDoesNotSupportStaticLinkage() {
// This will fail to link with -static.
return &_DYNAMIC; // defined in link.h
Index: asan_mac.cc
===================================================================
--- asan_mac.cc (revision 151711)
+++ asan_mac.cc (working copy)
@@ -50,7 +50,7 @@
# endif // __WORDSIZE
}
-int GetMacosVersion() {
+OSVersion GetOSVersion() {
int mib[2] = { CTL_KERN, KERN_OSRELEASE };
char version[100];
size_t len = 0, maxlen = sizeof(version) / sizeof(version[0]);
@@ -60,15 +60,15 @@
CHECK(len < maxlen);
CHECK(sysctl(mib, 2, version, &len, NULL, 0) != -1);
switch (version[0]) {
- case '9': return MACOS_VERSION_LEOPARD;
+ case '9': return MACOS_LEOPARD;
case '1': {
switch (version[1]) {
- case '0': return MACOS_VERSION_SNOW_LEOPARD;
- case '1': return MACOS_VERSION_LION;
- default: return MACOS_VERSION_UNKNOWN;
+ case '0': return MACOS_SNOW_LEOPARD;
+ case '1': return MACOS_LION;
+ default: return MACOS_UNKNOWN;
}
}
- default: return MACOS_VERSION_UNKNOWN;
+ default: return MACOS_UNKNOWN;
}
}
More information about the llvm-commits
mailing list