diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-02-08 19:52:01 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-02-08 19:52:01 +0000 |
commit | 5b29018cf422e7711fb760b733c32127397a43fc (patch) | |
tree | b479bf26ebce0810189992a3e4cc41927c1c97f0 /lib/asan/asan_interceptors.h | |
parent | 71d3b398a39663c771918747762142215a1dc87d (diff) | |
download | compiler-rt-5b29018cf422e7711fb760b733c32127397a43fc.tar.gz compiler-rt-5b29018cf422e7711fb760b733c32127397a43fc.tar.bz2 compiler-rt-5b29018cf422e7711fb760b733c32127397a43fc.tar.xz |
AddressSanitizer: start factoring out interception machinery
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@150083 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/asan_interceptors.h')
-rw-r--r-- | lib/asan/asan_interceptors.h | 61 |
1 files changed, 1 insertions, 60 deletions
diff --git a/lib/asan/asan_interceptors.h b/lib/asan/asan_interceptors.h index 665339ab..93ec87b0 100644 --- a/lib/asan/asan_interceptors.h +++ b/lib/asan/asan_interceptors.h @@ -15,66 +15,7 @@ #define ASAN_INTERCEPTORS_H #include "asan_internal.h" - -// Suppose you need to wrap/replace system function (generally, from libc): -// int foo(const char *bar, double baz); -// You'll need to: -// 1) define INTERCEPT(int, foo, const char *bar, double baz) { ... } -// 2) add a line "INTERCEPT_FUNCTION(foo)" to InitializeAsanInterceptors() -// You can access original function by calling __asan::real_foo(bar, baz). -// By defualt, real_foo will be visible only inside your interceptor, and if -// you want to use it in other parts of RTL, you'll need to: -// 3a) add DECLARE_REAL(int, foo, const char*, double); to a -// header file. -// However, if you want to implement your interceptor somewhere outside -// asan_interceptors.cc, you'll instead need to: -// 3b) add DECLARE_REAL_AND_INTERCEPTOR(int, foo, const char*, double); -// to a header. - -#if defined(__APPLE__) -# define WRAP(x) wrap_##x -# define WRAPPER_NAME(x) "wrap_"#x -# define INTERCEPTOR_ATTRIBUTE -#elif defined(_WIN32) -// TODO(timurrrr): we're likely to use something else later on Windows. -# define WRAP(x) wrap_##x -# define WRAPPER_NAME(x) #x -# define INTERCEPTOR_ATTRIBUTE -#else -# define WRAP(x) x -# define WRAPPER_NAME(x) #x -# define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default"))) -#endif - -#define REAL(x) real_##x -#define FUNC_TYPE(x) x##_f - -#define DECLARE_REAL(ret_type, func, ...); \ - typedef ret_type (*FUNC_TYPE(func))(__VA_ARGS__); \ - namespace __asan { \ - extern FUNC_TYPE(func) REAL(func); \ - } - -#define DECLARE_REAL_AND_INTERCEPTOR(ret_type, func, ...); \ - DECLARE_REAL(ret_type, func, ##__VA_ARGS__); \ - extern "C" \ - ret_type WRAP(func)(__VA_ARGS__); - -// Generally, you don't need to use DEFINE_REAL by itself, as INTERCEPTOR -// macros does its job. In exceptional cases you may need to call REAL(foo) -// without defining INTERCEPTOR(..., foo, ...). For example, if you override -// foo with interceptor for other function. -#define DEFINE_REAL(ret_type, func, ...); \ - typedef ret_type (*FUNC_TYPE(func))(__VA_ARGS__); \ - namespace __asan { \ - FUNC_TYPE(func) REAL(func); \ - } - -#define INTERCEPTOR(ret_type, func, ...); \ - DEFINE_REAL(ret_type, func, __VA_ARGS__); \ - extern "C" \ - INTERCEPTOR_ATTRIBUTE \ - ret_type WRAP(func)(__VA_ARGS__) +#include "interception/interception.h" DECLARE_REAL(int, memcmp, const void *a1, const void *a2, size_t size); DECLARE_REAL(void*, memcpy, void *to, const void *from, size_t size); |