mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 19:26:45 +00:00
[Sanitizer] Workaround for a compiler warning - ISO C++ forbids casting pointer-to-function to pointer-to-object, so we use cast via integral type
llvm-svn: 161168
This commit is contained in:
parent
33824c54f6
commit
0f840bd240
@ -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__)
|
||||
|
@ -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
|
||||
|
@ -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__
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user