]>
Commit | Line | Data |
---|---|---|
f35db108 WM |
1 | //===-- asan_interceptors.h -------------------------------------*- C++ -*-===// |
2 | // | |
b667dd70 ML |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. | |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
f35db108 WM |
6 | // |
7 | //===----------------------------------------------------------------------===// | |
8 | // | |
9 | // This file is a part of AddressSanitizer, an address sanity checker. | |
10 | // | |
b667dd70 | 11 | // ASan-private header for asan_interceptors.cpp |
f35db108 WM |
12 | //===----------------------------------------------------------------------===// |
13 | #ifndef ASAN_INTERCEPTORS_H | |
14 | #define ASAN_INTERCEPTORS_H | |
15 | ||
5d3805fc | 16 | #include "asan_interceptors_memintrinsics.h" |
0b997f6e | 17 | #include "asan_internal.h" |
696d846a | 18 | #include "interception/interception.h" |
0b997f6e | 19 | #include "sanitizer_common/sanitizer_platform.h" |
dee5ea7a KS |
20 | #include "sanitizer_common/sanitizer_platform_interceptors.h" |
21 | ||
5d3805fc JJ |
22 | namespace __asan { |
23 | ||
24 | void InitializeAsanInterceptors(); | |
25 | void InitializePlatformInterceptors(); | |
26 | ||
27 | #define ENSURE_ASAN_INITED() \ | |
28 | do { \ | |
29 | CHECK(!asan_init_is_running); \ | |
30 | if (UNLIKELY(!asan_inited)) { \ | |
31 | AsanInitFromRtl(); \ | |
32 | } \ | |
33 | } while (0) | |
34 | ||
35 | } // namespace __asan | |
36 | ||
90e46074 | 37 | // There is no general interception at all on Fuchsia. |
5d3805fc JJ |
38 | // Only the functions in asan_interceptors_memintrinsics.h are |
39 | // really defined to replace libc functions. | |
90e46074 | 40 | #if !SANITIZER_FUCHSIA |
5d3805fc | 41 | |
dee5ea7a KS |
42 | // Use macro to describe if specific function should be |
43 | // intercepted on a given platform. | |
44 | #if !SANITIZER_WINDOWS | |
45 | # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 1 | |
46 | # define ASAN_INTERCEPT__LONGJMP 1 | |
dee5ea7a KS |
47 | # define ASAN_INTERCEPT_INDEX 1 |
48 | # define ASAN_INTERCEPT_PTHREAD_CREATE 1 | |
dee5ea7a KS |
49 | #else |
50 | # define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 0 | |
51 | # define ASAN_INTERCEPT__LONGJMP 0 | |
dee5ea7a KS |
52 | # define ASAN_INTERCEPT_INDEX 0 |
53 | # define ASAN_INTERCEPT_PTHREAD_CREATE 0 | |
dee5ea7a KS |
54 | #endif |
55 | ||
eac97531 ML |
56 | #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \ |
57 | SANITIZER_SOLARIS | |
dee5ea7a KS |
58 | # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1 |
59 | #else | |
60 | # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0 | |
61 | #endif | |
62 | ||
d0fee87e | 63 | #if SANITIZER_GLIBC || SANITIZER_SOLARIS |
dee5ea7a KS |
64 | # define ASAN_INTERCEPT_SWAPCONTEXT 1 |
65 | #else | |
66 | # define ASAN_INTERCEPT_SWAPCONTEXT 0 | |
67 | #endif | |
68 | ||
69 | #if !SANITIZER_WINDOWS | |
5d3805fc | 70 | # define ASAN_INTERCEPT_SIGLONGJMP 1 |
dee5ea7a | 71 | #else |
5d3805fc | 72 | # define ASAN_INTERCEPT_SIGLONGJMP 0 |
dee5ea7a KS |
73 | #endif |
74 | ||
d0fee87e | 75 | #if SANITIZER_GLIBC |
5d3805fc | 76 | # define ASAN_INTERCEPT___LONGJMP_CHK 1 |
dee5ea7a | 77 | #else |
5d3805fc | 78 | # define ASAN_INTERCEPT___LONGJMP_CHK 0 |
dee5ea7a KS |
79 | #endif |
80 | ||
eac97531 ML |
81 | #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \ |
82 | !SANITIZER_NETBSD | |
dee5ea7a | 83 | # define ASAN_INTERCEPT___CXA_THROW 1 |
d53b3d94 | 84 | # define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1 |
eac97531 ML |
85 | # if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__)) |
86 | # define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1 | |
87 | # else | |
88 | # define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 1 | |
89 | # endif | |
dee5ea7a KS |
90 | #else |
91 | # define ASAN_INTERCEPT___CXA_THROW 0 | |
eac97531 ML |
92 | # define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0 |
93 | # define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 0 | |
94 | # define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 0 | |
dee5ea7a KS |
95 | #endif |
96 | ||
97 | #if !SANITIZER_WINDOWS | |
98 | # define ASAN_INTERCEPT___CXA_ATEXIT 1 | |
99 | #else | |
100 | # define ASAN_INTERCEPT___CXA_ATEXIT 0 | |
101 | #endif | |
f35db108 | 102 | |
3ca75cd5 ML |
103 | #if SANITIZER_NETBSD |
104 | # define ASAN_INTERCEPT_ATEXIT 1 | |
105 | #else | |
106 | # define ASAN_INTERCEPT_ATEXIT 0 | |
107 | #endif | |
108 | ||
d0fee87e | 109 | #if SANITIZER_GLIBC |
10189819 MO |
110 | # define ASAN_INTERCEPT___STRDUP 1 |
111 | #else | |
112 | # define ASAN_INTERCEPT___STRDUP 0 | |
113 | #endif | |
114 | ||
0b997f6e ML |
115 | #if SANITIZER_LINUX && \ |
116 | (defined(__arm__) || defined(__aarch64__) || defined(__i386__) || \ | |
5f3fa265 | 117 | defined(__x86_64__) || SANITIZER_RISCV64 || SANITIZER_LOONGARCH64) |
b667dd70 ML |
118 | # define ASAN_INTERCEPT_VFORK 1 |
119 | #else | |
120 | # define ASAN_INTERCEPT_VFORK 0 | |
121 | #endif | |
122 | ||
3ca75cd5 ML |
123 | #if SANITIZER_NETBSD |
124 | # define ASAN_INTERCEPT_PTHREAD_ATFORK 1 | |
125 | #else | |
126 | # define ASAN_INTERCEPT_PTHREAD_ATFORK 0 | |
127 | #endif | |
128 | ||
f35db108 | 129 | DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size) |
f35db108 | 130 | DECLARE_REAL(char*, strchr, const char *str, int c) |
866e32ad | 131 | DECLARE_REAL(SIZE_T, strlen, const char *s) |
f35db108 WM |
132 | DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size) |
133 | DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen) | |
134 | DECLARE_REAL(char*, strstr, const char *s1, const char *s2) | |
f35db108 | 135 | |
600413c4 | 136 | # if !SANITIZER_APPLE |
76288e1c L |
137 | # define ASAN_INTERCEPT_FUNC(name) \ |
138 | do { \ | |
139 | if (!INTERCEPT_FUNCTION(name)) \ | |
140 | VReport(1, "AddressSanitizer: failed to intercept '%s'\n", #name); \ | |
141 | } while (0) | |
142 | # define ASAN_INTERCEPT_FUNC_VER(name, ver) \ | |
143 | do { \ | |
144 | if (!INTERCEPT_FUNCTION_VER(name, ver)) \ | |
145 | VReport(1, "AddressSanitizer: failed to intercept '%s@@%s'\n", \ | |
146 | #name, ver); \ | |
147 | } while (0) | |
148 | # define ASAN_INTERCEPT_FUNC_VER_UNVERSIONED_FALLBACK(name, ver) \ | |
149 | do { \ | |
150 | if (!INTERCEPT_FUNCTION_VER(name, ver) && !INTERCEPT_FUNCTION(name)) \ | |
151 | VReport(1, \ | |
152 | "AddressSanitizer: failed to intercept '%s@@%s' or '%s'\n", \ | |
153 | #name, ver, #name); \ | |
154 | } while (0) | |
155 | ||
156 | # else | |
696d846a | 157 | // OS X interceptors don't need to be initialized with INTERCEPT_FUNCTION. |
76288e1c | 158 | # define ASAN_INTERCEPT_FUNC(name) |
600413c4 | 159 | # endif // SANITIZER_APPLE |
696d846a | 160 | |
5d3805fc | 161 | #endif // !SANITIZER_FUCHSIA |
f35db108 WM |
162 | |
163 | #endif // ASAN_INTERCEPTORS_H |