xref: /netbsd-src/external/gpl3/gcc.old/dist/libsanitizer/interception/interception_linux.h (revision c0a68be459da21030695f60d10265c2fc49758f8)
1 //===-- interception_linux.h ------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of AddressSanitizer, an address sanity checker.
9 //
10 // Linux-specific interception methods.
11 //===----------------------------------------------------------------------===//
12 
13 #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
14     SANITIZER_OPENBSD || SANITIZER_SOLARIS
15 
16 #if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
17 # error "interception_linux.h should be included from interception library only"
18 #endif
19 
20 #ifndef INTERCEPTION_LINUX_H
21 #define INTERCEPTION_LINUX_H
22 
23 namespace __interception {
24 // returns true if a function with the given name was found.
25 bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
26     uptr real, uptr wrapper);
27 void *GetFuncAddrVer(const char *func_name, const char *ver);
28 }  // namespace __interception
29 
30 #define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)                          \
31   ::__interception::GetRealFunctionAddress(                                \
32       #func, (::__interception::uptr *)&__interception::PTR_TO_REAL(func), \
33       (::__interception::uptr) & (func),                                   \
34       (::__interception::uptr) & WRAP(func))
35 
36 // Android,  Solaris and OpenBSD do not have dlvsym
37 #if !SANITIZER_ANDROID && !SANITIZER_SOLARIS && !SANITIZER_OPENBSD
38 #define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
39   (::__interception::real_##func = (func##_type)(                \
40        unsigned long)::__interception::GetFuncAddrVer(#func, symver))
41 #else
42 #define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
43   INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
44 #endif  // !SANITIZER_ANDROID && !SANITIZER_SOLARIS
45 
46 #endif  // INTERCEPTION_LINUX_H
47 #endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
48         // SANITIZER_OPENBSD || SANITIZER_SOLARIS
49