]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/interception/interception_linux.cc
Do not include float interfaces when using libsa.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / interception / interception_linux.cc
1 //===-- interception_linux.cc -----------------------------------*- 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
15 #include "interception.h"
16
17 #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
18     SANITIZER_SOLARIS
19
20 #include <dlfcn.h>   // for dlsym() and dlvsym()
21
22 #if SANITIZER_NETBSD
23 #include "sanitizer_common/sanitizer_libc.h"
24 #endif
25
26 namespace __interception {
27 bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
28     uptr real, uptr wrapper) {
29 #if SANITIZER_NETBSD
30   // XXX: Find a better way to handle renames
31   if (internal_strcmp(func_name, "sigaction") == 0) func_name = "__sigaction14";
32 #endif
33   *func_addr = (uptr)dlsym(RTLD_NEXT, func_name);
34   if (!*func_addr) {
35     // If the lookup using RTLD_NEXT failed, the sanitizer runtime library is
36     // later in the library search order than the DSO that we are trying to
37     // intercept, which means that we cannot intercept this function. We still
38     // want the address of the real definition, though, so look it up using
39     // RTLD_DEFAULT.
40     *func_addr = (uptr)dlsym(RTLD_DEFAULT, func_name);
41   }
42   return real == wrapper;
43 }
44
45 // Android and Solaris do not have dlvsym
46 #if !SANITIZER_ANDROID && !SANITIZER_SOLARIS
47 void *GetFuncAddrVer(const char *func_name, const char *ver) {
48   return dlvsym(RTLD_NEXT, func_name, ver);
49 }
50 #endif  // !SANITIZER_ANDROID
51
52 }  // namespace __interception
53
54 #endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
55         // SANITIZER_SOLARIS