diff options
Diffstat (limited to 'lib/interception')
| -rw-r--r-- | lib/interception/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | lib/interception/interception.h | 13 | ||||
| -rw-r--r-- | lib/interception/interception_linux.cc | 8 | ||||
| -rw-r--r-- | lib/interception/interception_linux.h | 10 | ||||
| -rw-r--r-- | lib/interception/interception_mac.h | 1 | ||||
| -rw-r--r-- | lib/interception/interception_win.h | 3 |
6 files changed, 38 insertions, 7 deletions
diff --git a/lib/interception/CMakeLists.txt b/lib/interception/CMakeLists.txt index cd9e6e75504f..1dfdaffb6dc1 100644 --- a/lib/interception/CMakeLists.txt +++ b/lib/interception/CMakeLists.txt @@ -13,10 +13,12 @@ set(INTERCEPTION_CFLAGS ${SANITIZER_COMMON_CFLAGS}) if(APPLE) # Build universal binary on APPLE. - add_compiler_rt_osx_object_library(RTInterception - ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH} - SOURCES ${INTERCEPTION_SOURCES} - CFLAGS ${INTERCEPTION_CFLAGS}) + foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS}) + add_compiler_rt_darwin_object_library(RTInterception ${os} + ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH} + SOURCES ${INTERCEPTION_SOURCES} + CFLAGS ${INTERCEPTION_CFLAGS}) + endforeach() elseif(ANDROID) add_library(RTInterception.arm.android OBJECT ${INTERCEPTION_SOURCES}) set_target_compile_flags(RTInterception.arm.android diff --git a/lib/interception/interception.h b/lib/interception/interception.h index d50af35415d6..baddd6c132c9 100644 --- a/lib/interception/interception.h +++ b/lib/interception/interception.h @@ -130,7 +130,10 @@ const interpose_substitution substitution_##func_name[] \ # define WRAPPER_NAME(x) "wrap_"#x # define INTERCEPTOR_ATTRIBUTE # endif -# define DECLARE_WRAPPER(ret_type, func, ...) +# define DECLARE_WRAPPER(ret_type, func, ...) \ + extern "C" ret_type func(__VA_ARGS__); +# define DECLARE_WRAPPER_WINAPI(ret_type, func, ...) \ + extern "C" __declspec(dllimport) ret_type __stdcall func(__VA_ARGS__); #else # define WRAP(x) __interceptor_ ## x # define WRAPPER_NAME(x) "__interceptor_" #x @@ -211,7 +214,7 @@ const interpose_substitution substitution_##func_name[] \ namespace __interception { \ FUNC_TYPE(func) PTR_TO_REAL(func); \ } \ - DECLARE_WRAPPER(ret_type, func, __VA_ARGS__) \ + DECLARE_WRAPPER_WINAPI(ret_type, func, __VA_ARGS__) \ extern "C" \ INTERCEPTOR_ATTRIBUTE \ ret_type __stdcall WRAP(func)(__VA_ARGS__) @@ -235,12 +238,18 @@ typedef unsigned long uptr; // NOLINT #if defined(__linux__) # include "interception_linux.h" # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX(func) +# define INTERCEPT_FUNCTION_VER(func, symver) \ + INTERCEPT_FUNCTION_VER_LINUX(func, symver) #elif defined(__APPLE__) # include "interception_mac.h" # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_MAC(func) +# define INTERCEPT_FUNCTION_VER(func, symver) \ + INTERCEPT_FUNCTION_VER_MAC(func, symver) #else // defined(_WIN32) # include "interception_win.h" # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_WIN(func) +# define INTERCEPT_FUNCTION_VER(func, symver) \ + INTERCEPT_FUNCTION_VER_WIN(func, symver) #endif #undef INCLUDED_FROM_INTERCEPTION_LIB diff --git a/lib/interception/interception_linux.cc b/lib/interception/interception_linux.cc index 009098fbd657..53f42881016c 100644 --- a/lib/interception/interception_linux.cc +++ b/lib/interception/interception_linux.cc @@ -15,7 +15,6 @@ #ifdef __linux__ #include "interception.h" -#include <stddef.h> // for NULL #include <dlfcn.h> // for dlsym namespace __interception { @@ -24,6 +23,13 @@ bool GetRealFunctionAddress(const char *func_name, uptr *func_addr, *func_addr = (uptr)dlsym(RTLD_NEXT, func_name); return real == wrapper; } + +#if !defined(__ANDROID__) // android does not have dlvsym +void *GetFuncAddrVer(const char *func_name, const char *ver) { + return dlvsym(RTLD_NEXT, func_name, ver); +} +#endif // !defined(__ANDROID__) + } // namespace __interception diff --git a/lib/interception/interception_linux.h b/lib/interception/interception_linux.h index dba60bf7315e..cea957320d05 100644 --- a/lib/interception/interception_linux.h +++ b/lib/interception/interception_linux.h @@ -25,6 +25,7 @@ namespace __interception { // returns true if a function with the given name was found. bool GetRealFunctionAddress(const char *func_name, uptr *func_addr, uptr real, uptr wrapper); +void *GetFuncAddrVer(const char *func_name, const char *ver); } // namespace __interception #define INTERCEPT_FUNCTION_LINUX(func) \ @@ -33,5 +34,14 @@ bool GetRealFunctionAddress(const char *func_name, uptr *func_addr, (::__interception::uptr)&(func), \ (::__interception::uptr)&WRAP(func)) +#if !defined(__ANDROID__) // android does not have dlvsym +# define INTERCEPT_FUNCTION_VER_LINUX(func, symver) \ + ::__interception::real_##func = (func##_f)(unsigned long) \ + ::__interception::GetFuncAddrVer(#func, symver) +#else +# define INTERCEPT_FUNCTION_VER_LINUX(func, symver) \ + INTERCEPT_FUNCTION_LINUX(func) +#endif // !defined(__ANDROID__) + #endif // INTERCEPTION_LINUX_H #endif // __linux__ diff --git a/lib/interception/interception_mac.h b/lib/interception/interception_mac.h index 5059489831ec..e5a35c6971cd 100644 --- a/lib/interception/interception_mac.h +++ b/lib/interception/interception_mac.h @@ -22,6 +22,7 @@ #define INTERCEPTION_MAC_H #define INTERCEPT_FUNCTION_MAC(func) +#define INTERCEPT_FUNCTION_VER_MAC(func, symver) #endif // INTERCEPTION_MAC_H #endif // __APPLE__ diff --git a/lib/interception/interception_win.h b/lib/interception/interception_win.h index c64af1baffe7..f2727c9241d3 100644 --- a/lib/interception/interception_win.h +++ b/lib/interception/interception_win.h @@ -41,5 +41,8 @@ bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func); (::__interception::uptr*)&REAL(func)) #endif +#define INTERCEPT_FUNCTION_VER_WIN(func, symver) \ + INTERCEPT_FUNCTION_WIN(func) + #endif // INTERCEPTION_WIN_H #endif // _WIN32 |
