[llvm-commits] Asan interception library patch (issue 6010049)

dvyukov at google.com dvyukov at google.com
Thu Apr 12 06:37:08 PDT 2012


Reviewers: samsonov, kcc1,



Please review this at http://codereview.appspot.com/6010049/

Affected files:
   M     interception.h
   M     interception_linux.cc
   M     interception_linux.h


Index: interception_linux.cc
===================================================================
--- interception_linux.cc	(revision 154588)
+++ interception_linux.cc	(working copy)
@@ -18,9 +18,10 @@
  #include <dlfcn.h>   // for dlsym

  namespace __interception {
-bool GetRealFunctionAddress(const char *func_name, void **func_addr) {
+bool GetRealFunctionAddress(const char *func_name, void **func_addr,
+    void *real, void *wrapper) {
    *func_addr = dlsym(RTLD_NEXT, func_name);
-  return (*func_addr != NULL);
+  return (*func_addr != NULL) && (real == wrapper);
  }
  }  // namespace __interception

Index: interception_linux.h
===================================================================
--- interception_linux.h	(revision 154588)
+++ interception_linux.h	(working copy)
@@ -23,11 +23,13 @@

  namespace __interception {
  // returns true if a function with the given name was found.
-bool GetRealFunctionAddress(const char *func_name, void **func_addr);
+bool GetRealFunctionAddress(const char *func_name, void **func_addr,
+    void *real, void *wrapper);
  }  // namespace __interception

  #define INTERCEPT_FUNCTION_LINUX(func) \
-    ::__interception::GetRealFunctionAddress(#func, (void**)&REAL(func))
+    ::__interception::GetRealFunctionAddress(#func, (void**)&REAL(func), \
+      (void*)&func, (void*)&WRAP(func))

  #endif  // INTERCEPTION_LINUX_H
  #endif  // __linux__
Index: interception.h
===================================================================
--- interception.h	(revision 154588)
+++ interception.h	(working copy)
@@ -75,6 +75,7 @@
  # define WRAP(x) wrap_##x
  # define WRAPPER_NAME(x) "wrap_"#x
  # define INTERCEPTOR_ATTRIBUTE
+# define DECLARE_WRAPPER(ret_type, convention, func, ...)
  #elif defined(_WIN32)
  # if defined(_DLL)  // DLL CRT
  #  define WRAP(x) x
@@ -85,10 +86,15 @@
  #  define WRAPPER_NAME(x) "wrap_"#x
  #  define INTERCEPTOR_ATTRIBUTE
  # endif
+# define DECLARE_WRAPPER(ret_type, convention, func, ...)
  #else
-# define WRAP(x) x
-# define WRAPPER_NAME(x) #x
+# define WRAP(x) interception_wrap_##x
+# define WRAPPER_NAME(x) "interception_wrap_"#x
  # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
+# define DECLARE_WRAPPER(ret_type, convention, func, ...) \
+  extern "C" ret_type convention func(__VA_ARGS__) \
+  __attribute__((weak, alias("interception_wrap_"#func), \
+      visibility("default")))
  #endif

  #define PTR_TO_REAL(x) real_##x
@@ -125,6 +131,7 @@

  #define INTERCEPTOR_EX(ret_type, convention, func, ...) \
    DEFINE_REAL_EX(ret_type, convention, func, __VA_ARGS__); \
+  DECLARE_WRAPPER(ret_type, convention, func, __VA_ARGS__); \
    extern "C" \
    INTERCEPTOR_ATTRIBUTE \
    ret_type convention WRAP(func)(__VA_ARGS__)





More information about the llvm-commits mailing list