1 //===-- asan_interceptors.h -------------------------------------*- 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 // ASan-private header for asan_interceptors.cc
13 //===----------------------------------------------------------------------===//
14 #ifndef ASAN_INTERCEPTORS_H
15 #define ASAN_INTERCEPTORS_H
16
17 #include "asan_internal.h"
18 #include "sanitizer_common/sanitizer_interception.h"
19 #include "sanitizer_common/sanitizer_platform_interceptors.h"
20
21 // Use macro to describe if specific function should be
22 // intercepted on a given platform.
23 #if !SANITIZER_WINDOWS
24 # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 1
25 # define ASAN_INTERCEPT__LONGJMP 1
26 # define ASAN_INTERCEPT_STRDUP 1
27 # define ASAN_INTERCEPT_INDEX 1
28 # define ASAN_INTERCEPT_PTHREAD_CREATE 1
29 # define ASAN_INTERCEPT_MLOCKX 1
30 # define ASAN_INTERCEPT_FORK 1
31 #else
32 # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 0
33 # define ASAN_INTERCEPT__LONGJMP 0
34 # define ASAN_INTERCEPT_STRDUP 0
35 # define ASAN_INTERCEPT_INDEX 0
36 # define ASAN_INTERCEPT_PTHREAD_CREATE 0
37 # define ASAN_INTERCEPT_MLOCKX 0
38 # define ASAN_INTERCEPT_FORK 0
39 #endif
40
41 #if SANITIZER_FREEBSD || SANITIZER_LINUX
42 # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1
43 #else
44 # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0
45 #endif
46
47 #if !SANITIZER_MAC
48 # define ASAN_INTERCEPT_STRNLEN 1
49 #else
50 # define ASAN_INTERCEPT_STRNLEN 0
51 #endif
52
53 #if SANITIZER_LINUX && !SANITIZER_ANDROID
54 # define ASAN_INTERCEPT_SWAPCONTEXT 1
55 #else
56 # define ASAN_INTERCEPT_SWAPCONTEXT 0
57 #endif
58
59 #if !SANITIZER_WINDOWS
60 # define ASAN_INTERCEPT_SIGNAL_AND_SIGACTION 1
61 #else
62 # define ASAN_INTERCEPT_SIGNAL_AND_SIGACTION 0
63 #endif
64
65 #if !SANITIZER_WINDOWS
66 # define ASAN_INTERCEPT_SIGLONGJMP 1
67 #else
68 # define ASAN_INTERCEPT_SIGLONGJMP 0
69 #endif
70
71 // Android bug: https://code.google.com/p/android/issues/detail?id=61799
72 #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && \
73 !(SANITIZER_ANDROID && defined(__i386))
74 # define ASAN_INTERCEPT___CXA_THROW 1
75 #else
76 # define ASAN_INTERCEPT___CXA_THROW 0
77 #endif
78
79 #if !SANITIZER_WINDOWS
80 # define ASAN_INTERCEPT___CXA_ATEXIT 1
81 #else
82 # define ASAN_INTERCEPT___CXA_ATEXIT 0
83 #endif
84
85 DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)
86 DECLARE_REAL(void*, memcpy, void *to, const void *from, uptr size)
87 DECLARE_REAL(void*, memset, void *block, int c, uptr size)
88 DECLARE_REAL(char*, strchr, const char *str, int c)
89 DECLARE_REAL(uptr, strlen, const char *s)
90 DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size)
91 DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)
92 DECLARE_REAL(char*, strstr, const char *s1, const char *s2)
93 struct sigaction;
DECLARE_REAL(int,sigaction,int signum,const struct sigaction * act,struct sigaction * oldact)94 DECLARE_REAL(int, sigaction, int signum, const struct sigaction *act,
95 struct sigaction *oldact)
96
97 namespace __asan {
98
99 void InitializeAsanInterceptors();
100
101 #define ENSURE_ASAN_INITED() do { \
102 CHECK(!asan_init_is_running); \
103 if (UNLIKELY(!asan_inited)) { \
104 AsanInitFromRtl(); \
105 } \
106 } while (0)
107
108 } // namespace __asan
109
110 #endif // ASAN_INTERCEPTORS_H
111