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