[llvm-commits] [compiler-rt] r145826 - /compiler-rt/trunk/lib/asan/asan_interceptors.cc
Kostya Serebryany
kcc at google.com
Mon Dec 5 10:56:29 PST 2011
Author: kcc
Date: Mon Dec 5 12:56:29 2011
New Revision: 145826
URL: http://llvm.org/viewvc/llvm-project?rev=145826&view=rev
Log:
[asan] cleanup memset/memmove/memcpy interceptors and enable them on Mac. Patch by samsonov at google.com
Modified:
compiler-rt/trunk/lib/asan/asan_interceptors.cc
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=145826&r1=145825&r2=145826&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Mon Dec 5 12:56:29 2011
@@ -62,15 +62,15 @@
AccessAddress(ptr, isWrite); \
AccessAddress(ptr + (size) - 1, isWrite); \
} \
-} while (0);
+} while (0)
#define ASAN_READ_RANGE(offset, size) do { \
ACCESS_MEMORY_RANGE(offset, size, false); \
-} while (0);
+} while (0)
#define ASAN_WRITE_RANGE(offset, size) do { \
ACCESS_MEMORY_RANGE(offset, size, true); \
-} while (0);
+} while (0)
// Behavior of functions like "memcpy" or "strcpy" is undefined
// if memory intervals overlap. We report error in this case.
@@ -90,15 +90,14 @@
PRINT_CURRENT_STACK(); \
ShowStatsAndAbort(); \
} \
-} while (0);
-
-static inline void ensure_asan_inited() {
- CHECK(!asan_init_is_running);
- if (!asan_inited) {
- __asan_init();
- }
-}
+} while (0)
+#define ENSURE_ASAN_INITED() do { \
+ CHECK(!asan_init_is_running); \
+ if (!asan_inited) { \
+ __asan_init(); \
+ } \
+} while (0)
size_t internal_strlen(const char *s) {
size_t i = 0;
@@ -121,15 +120,9 @@
#else
OVERRIDE_FUNCTION(index, WRAP(strchr));
#endif
-#ifndef __APPLE__
INTERCEPT_FUNCTION(memcpy);
INTERCEPT_FUNCTION(memmove);
INTERCEPT_FUNCTION(memset);
-#else
- real_memcpy = memcpy;
- real_memmove = memmove;
- real_memset = memset;
-#endif
INTERCEPT_FUNCTION(strchr);
INTERCEPT_FUNCTION(strcmp);
INTERCEPT_FUNCTION(strcpy); // NOLINT
@@ -156,7 +149,7 @@
if (asan_init_is_running) {
return real_memcpy(to, from, size);
}
- ensure_asan_inited();
+ ENSURE_ASAN_INITED();
if (FLAG_replace_intrin) {
CHECK_RANGES_OVERLAP(to, from, size);
ASAN_WRITE_RANGE(from, size);
@@ -166,7 +159,7 @@
}
void *WRAP(memmove)(void *to, const void *from, size_t size) {
- ensure_asan_inited();
+ ENSURE_ASAN_INITED();
if (FLAG_replace_intrin) {
ASAN_WRITE_RANGE(from, size);
ASAN_READ_RANGE(to, size);
@@ -175,7 +168,11 @@
}
void *WRAP(memset)(void *block, int c, size_t size) {
- ensure_asan_inited();
+ // memset is called inside INTERCEPT_FUNCTION on Mac.
+ if (asan_init_is_running) {
+ return real_memset(block, c, size);
+ }
+ ENSURE_ASAN_INITED();
if (FLAG_replace_intrin) {
ASAN_WRITE_RANGE(block, size);
}
@@ -192,7 +189,7 @@
#endif
char *WRAP(strchr)(const char *str, int c) {
- ensure_asan_inited();
+ ENSURE_ASAN_INITED();
char *result = real_strchr(str, c);
if (FLAG_replace_str) {
size_t bytes_read = (result ? result - str : real_strlen(str)) + 1;
@@ -229,7 +226,7 @@
if (asan_init_is_running) {
return real_strcpy(to, from);
}
- ensure_asan_inited();
+ ENSURE_ASAN_INITED();
if (FLAG_replace_str) {
size_t from_size = real_strlen(from) + 1;
CHECK_RANGES_OVERLAP(to, from, from_size);
@@ -240,7 +237,7 @@
}
char *WRAP(strdup)(const char *s) {
- ensure_asan_inited();
+ ENSURE_ASAN_INITED();
if (FLAG_replace_str) {
size_t length = real_strlen(s);
ASAN_READ_RANGE(s, length + 1);
@@ -254,7 +251,7 @@
if (asan_init_is_running) {
return real_strlen(s);
}
- ensure_asan_inited();
+ ENSURE_ASAN_INITED();
size_t length = real_strlen(s);
if (FLAG_replace_str) {
ASAN_READ_RANGE(s, length + 1);
@@ -281,7 +278,7 @@
}
char *WRAP(strncpy)(char *to, const char *from, size_t size) {
- ensure_asan_inited();
+ ENSURE_ASAN_INITED();
if (FLAG_replace_str) {
size_t from_size = Min(size, internal_strnlen(from, size) + 1);
CHECK_RANGES_OVERLAP(to, from, from_size);
@@ -293,7 +290,7 @@
#ifndef __APPLE__
size_t WRAP(strnlen)(const char *s, size_t maxlen) {
- ensure_asan_inited();
+ ENSURE_ASAN_INITED();
size_t length = real_strnlen(s, maxlen);
if (FLAG_replace_str) {
ASAN_READ_RANGE(s, Min(length + 1, maxlen));
More information about the llvm-commits
mailing list