xref: /netbsd-src/external/gpl3/gcc.old/dist/libsanitizer/interception/interception_linux.cc (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
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 //===----------------------------------------------------------------------===//
12 
13 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
14 #include "interception.h"
15 
16 #include <dlfcn.h>   // for dlsym() and dlvsym()
17 
18 #ifdef __NetBSD__
19 static int mystrcmp(const char *s1, const char *s2) {
20   while (*s1 == *s2++)
21     if (*s1++ == 0)
22       return (0);
23   return (*(const unsigned char *)s1 - *(const unsigned char *)--s2);
24 }
25 #endif
26 
27 
28 namespace __interception {
29 bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
30     uptr real, uptr wrapper) {
31 #ifdef __NetBSD__
32   // XXX: Until I come up with something better to deal with renames.
33   if (mystrcmp(func_name, "sigaction") == 0)
34     func_name = "__sigaction14";
35 #endif
36   *func_addr = (uptr)dlsym(RTLD_NEXT, func_name);
37   return real == wrapper;
38 }
39 
40 #if !defined(__ANDROID__)  // android does not have dlvsym
41 void *GetFuncAddrVer(const char *func_name, const char *ver) {
42   return dlvsym(RTLD_NEXT, func_name, ver);
43 }
44 #endif  // !defined(__ANDROID__)
45 
46 }  // namespace __interception
47 
48 
49 #endif  // __linux__ || __FreeBSD__ || __NetBSD__
50