diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-08-02 11:19:13 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-08-02 11:19:13 +0000 |
commit | 592d3f707e02968c75fd6e90d06d24f5df99c8b9 (patch) | |
tree | 9d8bfb9cf12e0cfb273ae50b44451b98023ea7b9 | |
parent | 37b3fcd6fdec5740fe51fc1315c5d4d54313de98 (diff) |
[Sanitizer] Workaround for a compiler warning - ISO C++ forbids casting pointer-to-function to pointer-to-object, so we use cast via integral type
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@161168 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/interception/interception.h | 9 | ||||
-rw-r--r-- | lib/interception/interception_linux.cc | 7 | ||||
-rw-r--r-- | lib/interception/interception_linux.h | 10 | ||||
-rw-r--r-- | lib/interception/interception_mac.cc | 14 | ||||
-rw-r--r-- | lib/interception/interception_mac.h | 8 |
5 files changed, 30 insertions, 18 deletions
diff --git a/lib/interception/interception.h b/lib/interception/interception.h index b72bff2a6..d05052370 100644 --- a/lib/interception/interception.h +++ b/lib/interception/interception.h @@ -148,6 +148,15 @@ INTERCEPTOR_EX(ret_type, __stdcall, func, __VA_ARGS__) #endif +// ISO C++ forbids casting between pointer-to-function and pointer-to-object, +// so we use casting via an integral type __interception::uptr, +// assuming that system is POSIX-compliant. Using other hacks seem +// challenging, as we don't even pass function type to +// INTERCEPT_FUNCTION macro, only its name. +namespace __interception { +typedef unsigned long uptr; // NOLINT +} // namespace __interception + #define INCLUDED_FROM_INTERCEPTION_LIB #if defined(__linux__) diff --git a/lib/interception/interception_linux.cc b/lib/interception/interception_linux.cc index 37e593323..009098fbd 100644 --- a/lib/interception/interception_linux.cc +++ b/lib/interception/interception_linux.cc @@ -13,14 +13,15 @@ //===----------------------------------------------------------------------===// #ifdef __linux__ +#include "interception.h" #include <stddef.h> // for NULL #include <dlfcn.h> // for dlsym namespace __interception { -bool GetRealFunctionAddress(const char *func_name, void **func_addr, - void *real, void *wrapper) { - *func_addr = dlsym(RTLD_NEXT, func_name); +bool GetRealFunctionAddress(const char *func_name, uptr *func_addr, + uptr real, uptr wrapper) { + *func_addr = (uptr)dlsym(RTLD_NEXT, func_name); return real == wrapper; } } // namespace __interception diff --git a/lib/interception/interception_linux.h b/lib/interception/interception_linux.h index 76a29c6a9..dba60bf73 100644 --- a/lib/interception/interception_linux.h +++ b/lib/interception/interception_linux.h @@ -23,13 +23,15 @@ namespace __interception { // returns true if a function with the given name was found. -bool GetRealFunctionAddress(const char *func_name, void **func_addr, - void *real, void *wrapper); +bool GetRealFunctionAddress(const char *func_name, uptr *func_addr, + uptr real, uptr wrapper); } // namespace __interception #define INTERCEPT_FUNCTION_LINUX(func) \ - ::__interception::GetRealFunctionAddress(#func, (void**)&REAL(func), \ - (void*)&(func), (void*)&WRAP(func)) + ::__interception::GetRealFunctionAddress( \ + #func, (::__interception::uptr*)&REAL(func), \ + (::__interception::uptr)&(func), \ + (::__interception::uptr)&WRAP(func)) #endif // INTERCEPTION_LINUX_H #endif // __linux__ diff --git a/lib/interception/interception_mac.cc b/lib/interception/interception_mac.cc index cc9e4a70d..2c10a7121 100644 --- a/lib/interception/interception_mac.cc +++ b/lib/interception/interception_mac.cc @@ -14,19 +14,17 @@ #ifdef __APPLE__ -#define INCLUDED_FROM_INTERCEPTION_LIB -#include "interception_mac.h" -#undef INCLUDED_FROM_INTERCEPTION_LIB +#include "interception.h" #include "mach_override/mach_override.h" namespace __interception { -bool OverrideFunction(void *old_func, void *new_func, void **orig_old_func) { - *orig_old_func = NULL; - int res = __asan_mach_override_ptr_custom(old_func, new_func, - orig_old_func, +bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func) { + *orig_old_func = 0; + int res = __asan_mach_override_ptr_custom((void*)old_func, (void*)new_func, + (void**)orig_old_func, __interception_allocate_island, __interception_deallocate_island); - return (res == 0) && (*orig_old_func != NULL); + return (res == 0) && (*orig_old_func != 0); } } // namespace __interception diff --git a/lib/interception/interception_mac.h b/lib/interception/interception_mac.h index 224d961ee..31fd7b399 100644 --- a/lib/interception/interception_mac.h +++ b/lib/interception/interception_mac.h @@ -35,12 +35,14 @@ mach_error_t __interception_deallocate_island(void *ptr); namespace __interception { // returns true if the old function existed. -bool OverrideFunction(void *old_func, void *new_func, void **orig_old_func); +bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func); } // namespace __interception # define OVERRIDE_FUNCTION_MAC(old_func, new_func) \ - ::__interception::OverrideFunction((void*)old_func, (void*)new_func, \ - (void**)&REAL(old_func)) + ::__interception::OverrideFunction( \ + (::__interception::uptr)old_func, \ + (::__interception::uptr)new_func, \ + (::__interception::uptr*)&REAL(old_func)) # define INTERCEPT_FUNCTION_MAC(func) OVERRIDE_FUNCTION_MAC(func, WRAP(func)) #endif // INTERCEPTION_MAC_H |