]>
git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/lib/interception/interception_linux.cc
1 //===-- interception_linux.cc -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of AddressSanitizer, an address sanity checker.
12 // Linux-specific interception methods.
13 //===----------------------------------------------------------------------===//
15 #include "interception.h"
17 #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
20 #include <dlfcn.h> // for dlsym() and dlvsym()
23 #include "sanitizer_common/sanitizer_libc.h"
26 namespace __interception
{
27 bool GetRealFunctionAddress(const char *func_name
, uptr
*func_addr
,
28 uptr real
, uptr wrapper
) {
30 // XXX: Find a better way to handle renames
31 if (internal_strcmp(func_name
, "sigaction") == 0) func_name
= "__sigaction14";
33 *func_addr
= (uptr
)dlsym(RTLD_NEXT
, func_name
);
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
40 *func_addr
= (uptr
)dlsym(RTLD_DEFAULT
, func_name
);
42 return real
== wrapper
;
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
);
50 #endif // !SANITIZER_ANDROID
52 } // namespace __interception
54 #endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||