[llvm-commits] [compiler-rt] r147916 - in /compiler-rt/trunk/lib/asan: asan_interceptors.cc asan_interceptors.h asan_rtl.cc
Kostya Serebryany
kcc at google.com
Tue Jan 10 18:32:41 PST 2012
Author: kcc
Date: Tue Jan 10 20:32:40 2012
New Revision: 147916
URL: http://llvm.org/viewvc/llvm-project?rev=147916&view=rev
Log:
[asan] remove OS-dependent includes from asan_interceptors.h
Modified:
compiler-rt/trunk/lib/asan/asan_interceptors.cc
compiler-rt/trunk/lib/asan/asan_interceptors.h
compiler-rt/trunk/lib/asan/asan_rtl.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=147916&r1=147915&r2=147916&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Tue Jan 10 20:32:40 2012
@@ -9,7 +9,7 @@
//
// This file is a part of AddressSanitizer, an address sanity checker.
//
-// Intercept various libc functions to catch buggy memory accesses there.
+// Intercept various libc functions.
//===----------------------------------------------------------------------===//
#include "asan_interceptors.h"
@@ -30,6 +30,54 @@
#include <strings.h>
#include <pthread.h>
+// To replace weak system functions on Linux we just need to declare functions
+// with same names in our library and then obtain the real function pointers
+// using dlsym(). This is not so on Mac OS, where the two-level namespace makes
+// our replacement functions invisible to other libraries. This may be overcomed
+// using the DYLD_FORCE_FLAT_NAMESPACE, but some errors loading the shared
+// libraries in Chromium were noticed when doing so.
+// Instead we use mach_override, a handy framework for patching functions at
+// runtime. To avoid possible name clashes, our replacement functions have
+// the "wrap_" prefix on Mac.
+//
+// After interception, the calls to system functions will be substituted by
+// calls to our interceptors. We store pointers to system function f()
+// in __asan::real_f().
+//
+// TODO(glider): mach_override_ptr() tends to spend too much time
+// in allocateBranchIsland(). This should be ok for real-word
+// application, but slows down our tests which fork too many children.
+#ifdef __APPLE__
+#include "mach_override/mach_override.h"
+#define WRAPPER_NAME(x) "wrap_"#x
+
+#define OVERRIDE_FUNCTION(oldfunc, newfunc) \
+ CHECK(0 == __asan_mach_override_ptr((void*)(oldfunc), \
+ (void*)(newfunc), \
+ (void**)&real_##oldfunc)); \
+ CHECK(real_##oldfunc != NULL);
+
+#define OVERRIDE_FUNCTION_IF_EXISTS(oldfunc, newfunc) \
+ do { __asan_mach_override_ptr((void*)(oldfunc), \
+ (void*)(newfunc), \
+ (void**)&real_##oldfunc); } while (0)
+
+#define INTERCEPT_FUNCTION(func) \
+ OVERRIDE_FUNCTION(func, WRAP(func))
+
+#define INTERCEPT_FUNCTION_IF_EXISTS(func) \
+ OVERRIDE_FUNCTION_IF_EXISTS(func, WRAP(func))
+
+#else // __linux__
+#define WRAPPER_NAME(x) #x
+
+#define INTERCEPT_FUNCTION(func) \
+ CHECK((real_##func = (func##_f)dlsym(RTLD_NEXT, #func)));
+
+#define INTERCEPT_FUNCTION_IF_EXISTS(func) \
+ do { real_##func = (func##_f)dlsym(RTLD_NEXT, #func); } while (0)
+#endif
+
namespace __asan {
typedef void (*longjmp_f)(void *env, int val);
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.h?rev=147916&r1=147915&r2=147916&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.h (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.h Tue Jan 10 20:32:40 2012
@@ -16,57 +16,12 @@
#include "asan_internal.h"
-// To replace weak system functions on Linux we just need to declare functions
-// with same names in our library and then obtain the real function pointers
-// using dlsym(). This is not so on Mac OS, where the two-level namespace makes
-// our replacement functions invisible to other libraries. This may be overcomed
-// using the DYLD_FORCE_FLAT_NAMESPACE, but some errors loading the shared
-// libraries in Chromium were noticed when doing so.
-// Instead we use mach_override, a handy framework for patching functions at
-// runtime. To avoid possible name clashes, our replacement functions have
-// the "wrap_" prefix on Mac.
-//
-// After interception, the calls to system functions will be substituted by
-// calls to our interceptors. We store pointers to system function f()
-// in __asan::real_f().
-//
-// TODO(glider): mach_override_ptr() tends to spend too much time
-// in allocateBranchIsland(). This should be ok for real-word
-// application, but slows down our tests which fork too many children.
#ifdef __APPLE__
-#include "mach_override/mach_override.h"
-#define WRAP(x) wrap_##x
-#define WRAPPER_NAME(x) "wrap_"#x
-
-#define OVERRIDE_FUNCTION(oldfunc, newfunc) \
- CHECK(0 == __asan_mach_override_ptr((void*)(oldfunc), \
- (void*)(newfunc), \
- (void**)&real_##oldfunc)); \
- CHECK(real_##oldfunc != NULL);
-
-#define OVERRIDE_FUNCTION_IF_EXISTS(oldfunc, newfunc) \
- do { __asan_mach_override_ptr((void*)(oldfunc), \
- (void*)(newfunc), \
- (void**)&real_##oldfunc); } while (0)
-
-#define INTERCEPT_FUNCTION(func) \
- OVERRIDE_FUNCTION(func, WRAP(func))
-
-#define INTERCEPT_FUNCTION_IF_EXISTS(func) \
- OVERRIDE_FUNCTION_IF_EXISTS(func, WRAP(func))
-
-#else // __linux__
-#define WRAP(x) x
-#define WRAPPER_NAME(x) #x
-
-#define INTERCEPT_FUNCTION(func) \
- CHECK((real_##func = (func##_f)dlsym(RTLD_NEXT, #func)));
-
-#define INTERCEPT_FUNCTION_IF_EXISTS(func) \
- do { real_##func = (func##_f)dlsym(RTLD_NEXT, #func); } while (0)
+# define WRAP(x) wrap_##x
+#else
+# define WRAP(x) x
#endif
-
namespace __asan {
typedef void* (*index_f)(const char *string, int c);
@@ -116,8 +71,6 @@
char *internal_strstr(const char *haystack, const char *needle);
char *internal_strncat(char *dst, const char *src, size_t n);
-
-// Initializes pointers to str*/mem* functions.
void InitializeAsanInterceptors();
} // namespace __asan
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=147916&r1=147915&r2=147916&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Tue Jan 10 20:32:40 2012
@@ -95,7 +95,7 @@
// This function should be called first inside __asan_init.
static const char* GetEnvFromProcSelfEnviron(const char* name) {
static char *environ;
- static ssize_t len;
+ static size_t len;
static bool inited;
if (!inited) {
inited = true;
@@ -103,7 +103,7 @@
len = ReadFileToBuffer("/proc/self/environ",
&environ, &environ_size, 1 << 20);
}
- if (!environ || len <= 0) return NULL;
+ if (!environ || len == 0) return NULL;
size_t namelen = internal_strlen(name);
const char *p = environ;
while (*p != '\0') { // will happen at the \0\0 that terminates the buffer
More information about the llvm-commits
mailing list