Alexey Samsonov | 5b29018 | 2012-02-08 19:52:01 +0000 | [diff] [blame] | 1 | //===-- interception_linux.h ------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is a part of AddressSanitizer, an address sanity checker. |
| 11 | // |
| 12 | // Linux-specific interception methods. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 15 | #if defined(__linux__) || defined(__FreeBSD__) |
Alexey Samsonov | 5b29018 | 2012-02-08 19:52:01 +0000 | [diff] [blame] | 16 | |
| 17 | #if !defined(INCLUDED_FROM_INTERCEPTION_LIB) |
Timur Iskhodzhanov | e6b9ebb | 2012-02-22 08:56:25 +0000 | [diff] [blame] | 18 | # error "interception_linux.h should be included from interception library only" |
Alexey Samsonov | 5b29018 | 2012-02-08 19:52:01 +0000 | [diff] [blame] | 19 | #endif |
| 20 | |
| 21 | #ifndef INTERCEPTION_LINUX_H |
| 22 | #define INTERCEPTION_LINUX_H |
| 23 | |
| 24 | namespace __interception { |
| 25 | // returns true if a function with the given name was found. |
Alexey Samsonov | 592d3f7 | 2012-08-02 11:19:13 +0000 | [diff] [blame] | 26 | bool GetRealFunctionAddress(const char *func_name, uptr *func_addr, |
| 27 | uptr real, uptr wrapper); |
Dmitry Vyukov | f061554 | 2013-09-02 18:06:28 +0000 | [diff] [blame] | 28 | void *GetFuncAddrVer(const char *func_name, const char *ver); |
Alexey Samsonov | 5b29018 | 2012-02-08 19:52:01 +0000 | [diff] [blame] | 29 | } // namespace __interception |
| 30 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 31 | #define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \ |
| 32 | ::__interception::GetRealFunctionAddress( \ |
| 33 | #func, (::__interception::uptr *)&__interception::PTR_TO_REAL(func), \ |
| 34 | (::__interception::uptr) & (func), \ |
| 35 | (::__interception::uptr) & WRAP(func)) |
Alexey Samsonov | 5b29018 | 2012-02-08 19:52:01 +0000 | [diff] [blame] | 36 | |
Dmitry Vyukov | 2f913ee | 2013-09-03 07:53:49 +0000 | [diff] [blame] | 37 | #if !defined(__ANDROID__) // android does not have dlvsym |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 38 | #define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \ |
| 39 | (::__interception::real_##func = (func##_f)( \ |
| 40 | unsigned long)::__interception::GetFuncAddrVer(#func, symver)) |
Alexey Samsonov | 5e2d377 | 2013-10-16 08:20:31 +0000 | [diff] [blame] | 41 | #else |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 42 | #define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \ |
| 43 | INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) |
Dmitry Vyukov | 2f913ee | 2013-09-03 07:53:49 +0000 | [diff] [blame] | 44 | #endif // !defined(__ANDROID__) |
Dmitry Vyukov | f061554 | 2013-09-02 18:06:28 +0000 | [diff] [blame] | 45 | |
Alexey Samsonov | 5b29018 | 2012-02-08 19:52:01 +0000 | [diff] [blame] | 46 | #endif // INTERCEPTION_LINUX_H |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 47 | #endif // __linux__ || __FreeBSD__ |