PR tree-optimization/82929
[official-gcc.git] / libsanitizer / interception / interception_linux.cc
blob888b2ceac13eb3584786c844cc25a181b8912ec1
1 //===-- interception_linux.cc -----------------------------------*- 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 //===----------------------------------------------------------------------===//
13 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
14 #include "interception.h"
16 #include <dlfcn.h> // for dlsym() and dlvsym()
18 #ifdef __NetBSD__
19 #include "sanitizer_common/sanitizer_libc.h"
20 #endif
22 namespace __interception {
23 bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
24 uptr real, uptr wrapper) {
25 #ifdef __NetBSD__
26 // XXX: Find a better way to handle renames
27 if (internal_strcmp(func_name, "sigaction") == 0) func_name = "__sigaction14";
28 #endif
29 *func_addr = (uptr)dlsym(RTLD_NEXT, func_name);
30 return real == wrapper;
33 #if !defined(__ANDROID__) // android does not have dlvsym
34 void *GetFuncAddrVer(const char *func_name, const char *ver) {
35 return dlvsym(RTLD_NEXT, func_name, ver);
37 #endif // !defined(__ANDROID__)
39 } // namespace __interception
41 #endif // __linux__ || __FreeBSD__ || __NetBSD__