[OpenACC] Enable 'attach' clause for combined constructs
[llvm-project.git] / compiler-rt / lib / sanitizer_common / sanitizer_platform_interceptors.h
blob190cad7cf7c3f7ed36465de8985eb3e0b1c8ba52
1 //===-- sanitizer_platform_interceptors.h -----------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines macro telling whether sanitizer tools can/should intercept
10 // given library functions on a given platform.
12 //===----------------------------------------------------------------------===//
13 #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
14 #define SANITIZER_PLATFORM_INTERCEPTORS_H
16 #include "sanitizer_glibc_version.h"
17 #include "sanitizer_internal_defs.h"
18 #include "sanitizer_platform.h"
20 #if SANITIZER_POSIX
21 #define SI_POSIX 1
22 #else
23 #define SI_POSIX 0
24 #endif
26 #if !SANITIZER_WINDOWS
27 #define SI_WINDOWS 0
28 #else
29 #define SI_WINDOWS 1
30 #endif
32 #if SI_WINDOWS && SI_POSIX
33 #error "Windows is not POSIX!"
34 #endif
36 #if SI_POSIX
37 #include "sanitizer_platform_limits_freebsd.h"
38 #include "sanitizer_platform_limits_netbsd.h"
39 #include "sanitizer_platform_limits_posix.h"
40 #include "sanitizer_platform_limits_solaris.h"
41 #endif
43 #if SANITIZER_LINUX && !SANITIZER_ANDROID
44 #define SI_LINUX_NOT_ANDROID 1
45 #else
46 #define SI_LINUX_NOT_ANDROID 0
47 #endif
49 #if SANITIZER_GLIBC
50 #define SI_GLIBC 1
51 #else
52 #define SI_GLIBC 0
53 #endif
55 #if SANITIZER_ANDROID
56 #define SI_ANDROID 1
57 #else
58 #define SI_ANDROID 0
59 #endif
61 #if SANITIZER_FREEBSD
62 #define SI_FREEBSD 1
63 #else
64 #define SI_FREEBSD 0
65 #endif
67 #if SANITIZER_NETBSD
68 #define SI_NETBSD 1
69 #else
70 #define SI_NETBSD 0
71 #endif
73 #if SANITIZER_LINUX
74 #define SI_LINUX 1
75 #else
76 #define SI_LINUX 0
77 #endif
79 #if SANITIZER_APPLE
80 #define SI_MAC 1
81 #define SI_NOT_MAC 0
82 #else
83 #define SI_MAC 0
84 #define SI_NOT_MAC 1
85 #endif
87 #if SANITIZER_APPLE
88 # include <Availability.h>
90 // aligned_alloc was introduced in OSX 10.15
91 // Linking will fail when using an older SDK
92 # if defined(__MAC_10_15)
93 // macOS 10.15 is greater than our minimal deployment target. To ensure we
94 // generate a weak reference so the dylib continues to work on older
95 // systems, we need to forward declare the intercepted function as "weak
96 // imports".
97 SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
98 __sanitizer::usize __size);
99 # define SI_MAC_SDK_10_15_AVAILABLE 1
100 # else
101 # define SI_MAC_SDK_10_15_AVAILABLE 0
102 # endif // defined(__MAC_10_15)
104 #endif // SANITIZER_APPLE
106 #if SANITIZER_IOS
107 #define SI_IOS 1
108 #else
109 #define SI_IOS 0
110 #endif
112 #if SANITIZER_IOSSIM
113 #define SI_IOSSIM 1
114 #else
115 #define SI_IOSSIM 0
116 #endif
118 #if SANITIZER_WATCHOS
119 #define SI_WATCHOS 1
120 #else
121 #define SI_WATCHOS 0
122 #endif
124 #if SANITIZER_TVOS
125 #define SI_TVOS 1
126 #else
127 #define SI_TVOS 0
128 #endif
130 #if SANITIZER_FUCHSIA
131 #define SI_NOT_FUCHSIA 0
132 #else
133 #define SI_NOT_FUCHSIA 1
134 #endif
136 #if SANITIZER_SOLARIS
137 #define SI_SOLARIS 1
138 #else
139 #define SI_SOLARIS 0
140 #endif
142 #if SANITIZER_SOLARIS32
143 #define SI_SOLARIS32 1
144 #else
145 #define SI_SOLARIS32 0
146 #endif
148 #if SANITIZER_POSIX && !SANITIZER_APPLE
149 #define SI_POSIX_NOT_MAC 1
150 #else
151 #define SI_POSIX_NOT_MAC 0
152 #endif
154 #if SANITIZER_LINUX && !SANITIZER_FREEBSD
155 #define SI_LINUX_NOT_FREEBSD 1
156 #else
157 #define SI_LINUX_NOT_FREEBSD 0
158 #endif
160 #define SANITIZER_INTERCEPT_STRLEN SI_NOT_FUCHSIA
161 #define SANITIZER_INTERCEPT_STRNLEN (SI_NOT_MAC && SI_NOT_FUCHSIA)
162 #define SANITIZER_INTERCEPT_STRCMP SI_NOT_FUCHSIA
163 #define SANITIZER_INTERCEPT_STRSTR SI_NOT_FUCHSIA
164 #define SANITIZER_INTERCEPT_STRCASESTR SI_POSIX
165 #define SANITIZER_INTERCEPT_STRTOK SI_NOT_FUCHSIA
166 #define SANITIZER_INTERCEPT_STRCHR SI_NOT_FUCHSIA
167 #define SANITIZER_INTERCEPT_STRCHRNUL SI_POSIX_NOT_MAC
168 #define SANITIZER_INTERCEPT_STRRCHR SI_NOT_FUCHSIA
169 #define SANITIZER_INTERCEPT_STRSPN SI_NOT_FUCHSIA
170 #define SANITIZER_INTERCEPT_STRPBRK SI_NOT_FUCHSIA
171 #define SANITIZER_INTERCEPT_TEXTDOMAIN SI_LINUX_NOT_ANDROID || SI_SOLARIS
172 #define SANITIZER_INTERCEPT_STRCASECMP SI_POSIX
173 #define SANITIZER_INTERCEPT_MEMSET 1
174 #define SANITIZER_INTERCEPT_MEMMOVE 1
175 #define SANITIZER_INTERCEPT_MEMCPY 1
176 #define SANITIZER_INTERCEPT_MEMCMP SI_NOT_FUCHSIA
177 #define SANITIZER_INTERCEPT_BCMP \
178 SANITIZER_INTERCEPT_MEMCMP && \
179 ((SI_POSIX && _GNU_SOURCE) || SI_NETBSD || SI_FREEBSD)
180 #define SANITIZER_INTERCEPT_STRNDUP SI_POSIX
181 #define SANITIZER_INTERCEPT___STRNDUP SI_GLIBC
182 #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
183 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070
184 #define SI_MAC_DEPLOYMENT_BELOW_10_7 1
185 #else
186 #define SI_MAC_DEPLOYMENT_BELOW_10_7 0
187 #endif
188 // memmem on Darwin doesn't exist on 10.6
189 // FIXME: enable memmem on Windows.
190 #define SANITIZER_INTERCEPT_MEMMEM (SI_POSIX && !SI_MAC_DEPLOYMENT_BELOW_10_7)
191 #define SANITIZER_INTERCEPT_MEMCHR SI_NOT_FUCHSIA
192 #define SANITIZER_INTERCEPT_MEMRCHR (SI_FREEBSD || SI_LINUX || SI_NETBSD)
194 #define SANITIZER_INTERCEPT_READ SI_POSIX
195 #define SANITIZER_INTERCEPT_PREAD SI_POSIX
196 #define SANITIZER_INTERCEPT_WRITE SI_POSIX
197 #define SANITIZER_INTERCEPT_PWRITE SI_POSIX
199 #define SANITIZER_INTERCEPT_FREAD SI_POSIX
200 #define SANITIZER_INTERCEPT_FWRITE SI_POSIX
201 #define SANITIZER_INTERCEPT_FGETS SI_POSIX
202 #define SANITIZER_INTERCEPT_FPUTS SI_POSIX
203 #define SANITIZER_INTERCEPT_PUTS SI_POSIX
205 #define SANITIZER_INTERCEPT_CREAT64 (SI_GLIBC || SI_SOLARIS32)
206 #define SANITIZER_INTERCEPT_FCNTL64 (SI_GLIBC || SI_SOLARIS32)
207 #define SANITIZER_INTERCEPT_OPEN64 (SI_GLIBC || SI_SOLARIS32)
208 #define SANITIZER_INTERCEPT_OPENAT64 (SI_GLIBC || SI_SOLARIS32)
210 #define SANITIZER_INTERCEPT_PREAD64 (SI_GLIBC || SI_SOLARIS32)
211 #define SANITIZER_INTERCEPT_PWRITE64 (SI_GLIBC || SI_SOLARIS32)
213 #define SANITIZER_INTERCEPT_LSEEK64 (SI_GLIBC || SI_SOLARIS32)
215 #define SANITIZER_INTERCEPT_READV SI_POSIX
216 #define SANITIZER_INTERCEPT_WRITEV SI_POSIX
218 #define SANITIZER_INTERCEPT_PREADV \
219 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
220 #define SANITIZER_INTERCEPT_PWRITEV \
221 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
222 #define SANITIZER_INTERCEPT_PREADV64 SI_GLIBC
223 #define SANITIZER_INTERCEPT_PWRITEV64 SI_GLIBC
225 #define SANITIZER_INTERCEPT_PRCTL SI_LINUX
227 #define SANITIZER_INTERCEPT_LOCALTIME_AND_FRIENDS SI_POSIX
228 #define SANITIZER_INTERCEPT_STRPTIME SI_POSIX
230 #define SANITIZER_INTERCEPT_SCANF SI_POSIX
231 #define SANITIZER_INTERCEPT_ISOC99_SCANF SI_GLIBC
233 #ifndef SANITIZER_INTERCEPT_PRINTF
234 #define SANITIZER_INTERCEPT_PRINTF SI_POSIX
235 #define SANITIZER_INTERCEPT_PRINTF_L (SI_FREEBSD || SI_NETBSD)
236 #define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_GLIBC
237 #endif
239 #define SANITIZER_INTERCEPT___PRINTF_CHK \
240 (SANITIZER_INTERCEPT_PRINTF && SI_GLIBC)
242 #define SANITIZER_INTERCEPT_FREXP SI_NOT_FUCHSIA
243 #define SANITIZER_INTERCEPT_FREXPF_FREXPL SI_POSIX
245 #define SANITIZER_INTERCEPT_GETPWNAM_AND_FRIENDS SI_POSIX
246 #define SANITIZER_INTERCEPT_GETPWNAM_R_AND_FRIENDS \
247 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
248 #define SANITIZER_INTERCEPT_GETPWENT \
249 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
250 #define SANITIZER_INTERCEPT_FGETGRENT_R (SI_GLIBC || SI_SOLARIS)
251 #define SANITIZER_INTERCEPT_FGETPWENT SI_LINUX_NOT_ANDROID || SI_SOLARIS
252 #define SANITIZER_INTERCEPT_GETPWENT_R \
253 (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS)
254 #define SANITIZER_INTERCEPT_FGETPWENT_R (SI_FREEBSD || SI_GLIBC || SI_SOLARIS)
255 #define SANITIZER_INTERCEPT_SETPWENT \
256 (SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
257 #define SANITIZER_INTERCEPT_CLOCK_GETTIME \
258 (SI_FREEBSD || SI_NETBSD || SI_LINUX || SI_SOLARIS)
259 #define SANITIZER_INTERCEPT_CLOCK_GETCPUCLOCKID \
260 (SI_LINUX || SI_FREEBSD || SI_NETBSD)
261 // TODO: This should be SI_POSIX, adding glibc first until I have time
262 // to verify all timer_t typedefs on other platforms.
263 #define SANITIZER_INTERCEPT_TIMER_CREATE SI_GLIBC
264 #define SANITIZER_INTERCEPT_GETITIMER SI_POSIX
265 #define SANITIZER_INTERCEPT_TIME SI_POSIX
266 #define SANITIZER_INTERCEPT_TIMESPEC_GET SI_LINUX
267 #define SANITIZER_INTERCEPT_GLOB (SI_GLIBC || SI_SOLARIS)
268 #define SANITIZER_INTERCEPT_GLOB64 SI_GLIBC
269 #define SANITIZER_INTERCEPT___B64_TO SI_LINUX_NOT_ANDROID
270 #define SANITIZER_INTERCEPT_DN_COMP_EXPAND SI_LINUX_NOT_ANDROID
271 #define SANITIZER_INTERCEPT_POSIX_SPAWN SI_POSIX
272 #define SANITIZER_INTERCEPT_WAIT SI_POSIX
273 #define SANITIZER_INTERCEPT_INET SI_POSIX
274 #define SANITIZER_INTERCEPT_PTHREAD_GETSCHEDPARAM SI_POSIX
275 #define SANITIZER_INTERCEPT_GETADDRINFO SI_POSIX
276 #define SANITIZER_INTERCEPT_GETNAMEINFO SI_POSIX
277 #define SANITIZER_INTERCEPT_GETSOCKNAME SI_POSIX
278 #define SANITIZER_INTERCEPT_GETHOSTBYNAME SI_POSIX
279 #define SANITIZER_INTERCEPT_GETHOSTBYNAME2 SI_POSIX && !SI_SOLARIS
280 #define SANITIZER_INTERCEPT_GETHOSTBYNAME_R \
281 (SI_FREEBSD || SI_LINUX || SI_SOLARIS)
282 #define SANITIZER_INTERCEPT_GETHOSTBYNAME2_R \
283 (SI_FREEBSD || SI_LINUX_NOT_ANDROID)
284 #define SANITIZER_INTERCEPT_GETHOSTBYADDR_R \
285 (SI_FREEBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
286 #define SANITIZER_INTERCEPT_GETHOSTENT_R (SI_FREEBSD || SI_GLIBC || SI_SOLARIS)
287 #define SANITIZER_INTERCEPT_GETSOCKOPT SI_POSIX
288 #define SANITIZER_INTERCEPT_ACCEPT SI_POSIX
289 #define SANITIZER_INTERCEPT_ACCEPT4 \
290 (SI_LINUX_NOT_ANDROID || SI_NETBSD || SI_FREEBSD)
291 #define SANITIZER_INTERCEPT_PACCEPT SI_NETBSD
292 #define SANITIZER_INTERCEPT_MODF SI_POSIX
293 #define SANITIZER_INTERCEPT_RECVMSG SI_POSIX
294 #define SANITIZER_INTERCEPT_SENDMSG SI_POSIX
295 #define SANITIZER_INTERCEPT_RECVMMSG SI_LINUX
296 #define SANITIZER_INTERCEPT_SENDMMSG SI_LINUX
297 #define SANITIZER_INTERCEPT_SYSMSG SI_LINUX_NOT_ANDROID
298 #define SANITIZER_INTERCEPT_GETPEERNAME SI_POSIX
299 #define SANITIZER_INTERCEPT_IOCTL SI_POSIX
300 #define SANITIZER_INTERCEPT_INET_ATON SI_POSIX
301 #define SANITIZER_INTERCEPT_SYSINFO SI_LINUX
302 #define SANITIZER_INTERCEPT_READDIR SI_POSIX
303 #define SANITIZER_INTERCEPT_READDIR64 SI_GLIBC || SI_SOLARIS32
304 #if SI_LINUX_NOT_ANDROID && \
305 (defined(__i386) || defined(__x86_64) || defined(__mips64) || \
306 defined(__powerpc64__) || defined(__aarch64__) || defined(__arm__) || \
307 defined(__s390__) || defined(__loongarch__) || SANITIZER_RISCV64 || \
308 defined(__sparc__))
309 # define SANITIZER_INTERCEPT_PTRACE 1
310 #else
311 #define SANITIZER_INTERCEPT_PTRACE 0
312 #endif
313 #define SANITIZER_INTERCEPT_SETLOCALE SI_POSIX
314 #define SANITIZER_INTERCEPT_GETCWD SI_POSIX
315 #define SANITIZER_INTERCEPT_GET_CURRENT_DIR_NAME SI_LINUX_NOT_ANDROID
316 #define SANITIZER_INTERCEPT_STRTOIMAX SI_POSIX
317 #define SANITIZER_INTERCEPT_MBSTOWCS SI_POSIX
318 #define SANITIZER_INTERCEPT_MBSNRTOWCS \
319 (SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
320 #define SANITIZER_INTERCEPT_WCSTOMBS SI_POSIX
321 #define SANITIZER_INTERCEPT_STRXFRM SI_POSIX
322 #define SANITIZER_INTERCEPT___STRXFRM_L SI_LINUX
323 #define SANITIZER_INTERCEPT_WCSXFRM SI_POSIX
324 #define SANITIZER_INTERCEPT___WCSXFRM_L SI_LINUX
325 #define SANITIZER_INTERCEPT_WCSNRTOMBS \
326 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
327 #define SANITIZER_INTERCEPT_WCRTOMB \
328 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
329 #define SANITIZER_INTERCEPT_WCTOMB \
330 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
331 #define SANITIZER_INTERCEPT_TCGETATTR SI_LINUX_NOT_ANDROID || SI_SOLARIS
332 #define SANITIZER_INTERCEPT_REALPATH SI_POSIX
333 #define SANITIZER_INTERCEPT_CANONICALIZE_FILE_NAME (SI_GLIBC || SI_SOLARIS)
334 #define SANITIZER_INTERCEPT_CONFSTR \
335 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
336 #define SANITIZER_INTERCEPT_SCHED_GETAFFINITY \
337 (SI_LINUX_NOT_ANDROID || SI_FREEBSD)
338 #define SANITIZER_INTERCEPT_SCHED_GETPARAM SI_LINUX_NOT_ANDROID || SI_SOLARIS
339 #define SANITIZER_INTERCEPT_STRERROR SI_POSIX
340 #define SANITIZER_INTERCEPT_STRERROR_R SI_POSIX
341 #define SANITIZER_INTERCEPT_XPG_STRERROR_R SI_LINUX_NOT_ANDROID
342 #define SANITIZER_INTERCEPT_SCANDIR \
343 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
344 #define SANITIZER_INTERCEPT_SCANDIR64 SI_GLIBC || SI_SOLARIS32
345 #define SANITIZER_INTERCEPT_GETGROUPS SI_POSIX
346 #define SANITIZER_INTERCEPT_POLL SI_POSIX
347 #define SANITIZER_INTERCEPT_PPOLL SI_LINUX_NOT_ANDROID || SI_SOLARIS
348 #define SANITIZER_INTERCEPT_EPOLL (SI_LINUX)
349 #define SANITIZER_INTERCEPT_KQUEUE (SI_FREEBSD || SI_NETBSD || SI_MAC)
350 #define SANITIZER_INTERCEPT_WORDEXP \
351 (SI_FREEBSD || SI_NETBSD || (SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID || \
352 SI_SOLARIS)
353 #define SANITIZER_INTERCEPT_SIGWAIT SI_POSIX
354 #define SANITIZER_INTERCEPT_SIGWAITINFO SI_LINUX_NOT_ANDROID || SI_SOLARIS
355 #define SANITIZER_INTERCEPT_SIGTIMEDWAIT SI_LINUX_NOT_ANDROID || SI_SOLARIS
356 #define SANITIZER_INTERCEPT_SIGSETOPS \
357 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
358 #define SANITIZER_INTERCEPT_SIGSET_LOGICOPS SI_LINUX_NOT_ANDROID
359 #define SANITIZER_INTERCEPT_SIGPENDING SI_POSIX
360 #define SANITIZER_INTERCEPT_SIGPROCMASK SI_POSIX
361 #define SANITIZER_INTERCEPT_PTHREAD_SIGMASK SI_POSIX
362 #define SANITIZER_INTERCEPT_BACKTRACE \
363 (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS)
364 #define SANITIZER_INTERCEPT_GETMNTENT SI_LINUX
365 #define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID
366 #define SANITIZER_INTERCEPT_STATFS \
367 (SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
368 #define SANITIZER_INTERCEPT_STATFS64 SI_GLIBC && SANITIZER_HAS_STATFS64
369 #define SANITIZER_INTERCEPT_STATVFS \
370 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
371 #define SANITIZER_INTERCEPT_STATVFS64 SI_GLIBC
372 #define SANITIZER_INTERCEPT_INITGROUPS SI_POSIX
373 #define SANITIZER_INTERCEPT_ETHER_NTOA_ATON SI_POSIX
374 #define SANITIZER_INTERCEPT_ETHER_HOST \
375 (SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID)
376 #define SANITIZER_INTERCEPT_ETHER_R (SI_FREEBSD || SI_LINUX_NOT_ANDROID)
377 #define SANITIZER_INTERCEPT_SHMCTL \
378 (((SI_FREEBSD || SI_LINUX_NOT_ANDROID) && SANITIZER_WORDSIZE == 64) || \
379 SI_NETBSD || SI_SOLARIS)
380 #define SANITIZER_INTERCEPT_RANDOM_R SI_GLIBC
381 #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GET SI_POSIX
382 #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSCHED \
383 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
384 #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETAFFINITY_NP SI_GLIBC
385 #define SANITIZER_INTERCEPT_PTHREAD_GETAFFINITY_NP \
386 (SI_LINUX_NOT_ANDROID || SI_FREEBSD)
387 #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GET_SCHED SI_POSIX
388 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPSHARED \
389 (SI_POSIX && !SI_NETBSD)
390 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETTYPE SI_POSIX
391 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPROTOCOL \
392 (SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
393 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPRIOCEILING \
394 (SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
395 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST \
396 (SI_LINUX_NOT_ANDROID || SI_SOLARIS)
397 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST_NP SI_LINUX_NOT_ANDROID
398 #define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETPSHARED \
399 (SI_POSIX && !SI_NETBSD)
400 #define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETKIND_NP SI_GLIBC
401 #define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETPSHARED (SI_POSIX && !SI_NETBSD)
402 #define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETCLOCK \
403 (SI_LINUX_NOT_ANDROID || SI_SOLARIS)
404 #define SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GETPSHARED \
405 (SI_LINUX_NOT_ANDROID && !SI_NETBSD)
406 #define SANITIZER_INTERCEPT_TRYJOIN SI_GLIBC
407 #define SANITIZER_INTERCEPT_TIMEDJOIN SI_GLIBC
408 #define SANITIZER_INTERCEPT_THR_EXIT SI_FREEBSD
409 #define SANITIZER_INTERCEPT_TMPNAM SI_POSIX
410 #define SANITIZER_INTERCEPT_TMPNAM_R (SI_GLIBC || SI_SOLARIS)
411 #define SANITIZER_INTERCEPT_PTSNAME SI_LINUX
412 #define SANITIZER_INTERCEPT_PTSNAME_R SI_LINUX
413 #define SANITIZER_INTERCEPT_TTYNAME SI_POSIX
414 #define SANITIZER_INTERCEPT_TTYNAME_R SI_POSIX
415 #define SANITIZER_INTERCEPT_TEMPNAM SI_POSIX
416 #define SANITIZER_INTERCEPT_SINCOS SI_LINUX || SI_SOLARIS
417 #define SANITIZER_INTERCEPT_REMQUO SI_POSIX
418 #define SANITIZER_INTERCEPT_REMQUOL (SI_POSIX && !SI_NETBSD)
419 #define SANITIZER_INTERCEPT_LGAMMA SI_POSIX
420 #define SANITIZER_INTERCEPT_LGAMMAL (SI_POSIX && !SI_NETBSD)
421 #define SANITIZER_INTERCEPT_LGAMMA_R (SI_FREEBSD || SI_LINUX || SI_SOLARIS)
422 #define SANITIZER_INTERCEPT_LGAMMAL_R SI_LINUX_NOT_ANDROID || SI_SOLARIS
423 #define SANITIZER_INTERCEPT_DRAND48_R SI_GLIBC
424 #define SANITIZER_INTERCEPT_RAND_R \
425 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
426 #define SANITIZER_INTERCEPT_ICONV \
427 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
428 #define SANITIZER_INTERCEPT_TIMES SI_POSIX
430 // FIXME: getline seems to be available on OSX 10.7
431 #define SANITIZER_INTERCEPT_GETLINE \
432 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
434 #define SANITIZER_INTERCEPT__EXIT \
435 (SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_MAC || SI_SOLARIS)
437 #define SANITIZER_INTERCEPT___LIBC_MUTEX SI_NETBSD
438 #define SANITIZER_INTERCEPT_PTHREAD_SETNAME_NP \
439 (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS)
440 #define SANITIZER_INTERCEPT_PTHREAD_GETNAME_NP \
441 (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS)
443 #define SANITIZER_INTERCEPT_TLS_GET_ADDR \
444 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
446 #define SANITIZER_INTERCEPT_LISTXATTR SI_LINUX
447 #define SANITIZER_INTERCEPT_GETXATTR SI_LINUX
448 #define SANITIZER_INTERCEPT_GETRESID SI_LINUX
449 #define SANITIZER_INTERCEPT_GETIFADDRS \
450 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS)
451 #define SANITIZER_INTERCEPT_IF_INDEXTONAME \
452 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS)
453 #define SANITIZER_INTERCEPT_CAPGET SI_LINUX_NOT_ANDROID
454 #if SI_LINUX && defined(__arm__)
455 #define SANITIZER_INTERCEPT_AEABI_MEM 1
456 #else
457 #define SANITIZER_INTERCEPT_AEABI_MEM 0
458 #endif
459 #define SANITIZER_INTERCEPT___BZERO SI_MAC || SI_GLIBC
460 #define SANITIZER_INTERCEPT_BZERO SI_LINUX_NOT_ANDROID
461 #define SANITIZER_INTERCEPT_FTIME (!SI_FREEBSD && !SI_NETBSD && SI_POSIX)
462 #define SANITIZER_INTERCEPT_XDR (SI_GLIBC || SI_SOLARIS)
463 #define SANITIZER_INTERCEPT_XDRREC SI_GLIBC
464 #define SANITIZER_INTERCEPT_TSEARCH \
465 (SI_LINUX_NOT_ANDROID || SI_MAC || SI_NETBSD || SI_SOLARIS)
466 #define SANITIZER_INTERCEPT_LIBIO_INTERNALS SI_GLIBC
467 #define SANITIZER_INTERCEPT_FOPEN SI_POSIX
468 #define SANITIZER_INTERCEPT_FOPEN64 (SI_GLIBC || SI_SOLARIS32)
469 #define SANITIZER_INTERCEPT_OPEN_MEMSTREAM \
470 (SI_LINUX_NOT_ANDROID || SI_NETBSD || SI_SOLARIS)
471 #define SANITIZER_INTERCEPT_OBSTACK SI_GLIBC
472 #define SANITIZER_INTERCEPT_FFLUSH SI_POSIX
473 #define SANITIZER_INTERCEPT_FCLOSE SI_POSIX
475 #ifndef SANITIZER_INTERCEPT_DLOPEN_DLCLOSE
476 #define SANITIZER_INTERCEPT_DLOPEN_DLCLOSE \
477 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS)
478 #endif
480 #define SANITIZER_INTERCEPT_GETPASS \
481 (SI_LINUX_NOT_ANDROID || SI_MAC || SI_NETBSD)
482 #define SANITIZER_INTERCEPT_TIMERFD SI_LINUX_NOT_ANDROID
484 #define SANITIZER_INTERCEPT_MLOCKX SI_POSIX
485 #define SANITIZER_INTERCEPT_FOPENCOOKIE SI_LINUX_NOT_ANDROID
486 #define SANITIZER_INTERCEPT_SEM \
487 (SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_SOLARIS)
488 #define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL SI_POSIX
489 #define SANITIZER_INTERCEPT_MINCORE \
490 (SI_LINUX || SI_NETBSD || SI_FREEBSD || SI_SOLARIS)
491 #define SANITIZER_INTERCEPT_PROCESS_VM_READV SI_LINUX
492 #define SANITIZER_INTERCEPT_CTERMID \
493 (SI_LINUX || SI_MAC || SI_FREEBSD || SI_NETBSD || SI_SOLARIS)
494 #define SANITIZER_INTERCEPT_CTERMID_R (SI_MAC || SI_FREEBSD || SI_SOLARIS)
496 #define SANITIZER_INTERCEPTOR_HOOKS \
497 (SI_LINUX || SI_MAC || SI_WINDOWS || SI_FREEBSD || SI_NETBSD || SI_SOLARIS)
498 #define SANITIZER_INTERCEPT_RECV_RECVFROM SI_POSIX
499 #define SANITIZER_INTERCEPT_SEND_SENDTO SI_POSIX
500 #define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE (SI_LINUX || SI_FREEBSD)
502 #define SI_STAT_LINUX (SI_LINUX && __GLIBC_PREREQ(2, 33))
503 #define SANITIZER_INTERCEPT_STAT \
504 (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS || \
505 SI_STAT_LINUX)
506 #define SANITIZER_INTERCEPT_STAT64 SI_STAT_LINUX && SANITIZER_HAS_STAT64
507 #define SANITIZER_INTERCEPT_LSTAT (SI_NETBSD || SI_FREEBSD || SI_STAT_LINUX)
508 #define SANITIZER_INTERCEPT___XSTAT \
509 ((!SANITIZER_INTERCEPT_STAT && SI_POSIX) || SI_STAT_LINUX)
510 #define SANITIZER_INTERCEPT___XSTAT64 SI_GLIBC
511 #define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT
512 #define SANITIZER_INTERCEPT___LXSTAT64 SI_GLIBC
514 #define SANITIZER_INTERCEPT_UTMP \
515 (SI_POSIX && !SI_MAC && !SI_FREEBSD && !SI_NETBSD)
516 #define SANITIZER_INTERCEPT_UTMPX \
517 (SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD)
519 #define SANITIZER_INTERCEPT_GETLOADAVG \
520 (SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD)
522 #define SANITIZER_INTERCEPT_MMAP SI_POSIX
523 #define SANITIZER_INTERCEPT_MMAP64 SI_GLIBC || SI_SOLARIS
524 #define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO (SI_GLIBC || SI_ANDROID)
525 #define SANITIZER_INTERCEPT_MEMALIGN (!SI_FREEBSD && !SI_MAC && !SI_NETBSD)
526 #define SANITIZER_INTERCEPT___LIBC_MEMALIGN SI_GLIBC
527 #define SANITIZER_INTERCEPT_PVALLOC (SI_GLIBC || SI_ANDROID)
528 #define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64)
529 #define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX
530 #define SANITIZER_INTERCEPT_ALIGNED_ALLOC \
531 (!SI_MAC || SI_MAC_SDK_10_15_AVAILABLE)
532 #define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD)
533 #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
534 #define SANITIZER_INTERCEPT_WCSLEN 1
535 #define SANITIZER_INTERCEPT_WCSCAT SI_POSIX
536 #define SANITIZER_INTERCEPT_WCSDUP SI_POSIX
537 #define SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION (!SI_WINDOWS && SI_NOT_FUCHSIA)
538 #define SANITIZER_INTERCEPT_BSD_SIGNAL SI_ANDROID
540 #define SANITIZER_INTERCEPT_ACCT (SI_NETBSD || SI_FREEBSD)
541 #define SANITIZER_INTERCEPT_USER_FROM_UID SI_NETBSD
542 #define SANITIZER_INTERCEPT_UID_FROM_USER SI_NETBSD
543 #define SANITIZER_INTERCEPT_GROUP_FROM_GID SI_NETBSD
544 #define SANITIZER_INTERCEPT_GID_FROM_GROUP SI_NETBSD
545 #define SANITIZER_INTERCEPT_ACCESS (SI_NETBSD || SI_FREEBSD)
546 #define SANITIZER_INTERCEPT_FACCESSAT (SI_NETBSD || SI_FREEBSD)
547 #define SANITIZER_INTERCEPT_GETGROUPLIST \
548 (SI_NETBSD || SI_FREEBSD || SI_LINUX)
549 #define SANITIZER_INTERCEPT_STRLCPY \
550 (SI_NETBSD || SI_FREEBSD || SI_MAC || SI_ANDROID)
552 #define SANITIZER_INTERCEPT_NAME_TO_HANDLE_AT SI_LINUX_NOT_ANDROID
553 #define SANITIZER_INTERCEPT_OPEN_BY_HANDLE_AT SI_LINUX_NOT_ANDROID
555 #define SANITIZER_INTERCEPT_READLINK SI_POSIX
556 #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
557 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101000
558 #define SI_MAC_DEPLOYMENT_BELOW_10_10 1
559 #else
560 #define SI_MAC_DEPLOYMENT_BELOW_10_10 0
561 #endif
562 #define SANITIZER_INTERCEPT_READLINKAT \
563 (SI_POSIX && !SI_MAC_DEPLOYMENT_BELOW_10_10)
565 #define SANITIZER_INTERCEPT_DEVNAME (SI_NETBSD || SI_FREEBSD)
566 #define SANITIZER_INTERCEPT_DEVNAME_R (SI_NETBSD || SI_FREEBSD)
567 #define SANITIZER_INTERCEPT_FGETLN (SI_NETBSD || SI_FREEBSD)
568 #define SANITIZER_INTERCEPT_STRMODE (SI_NETBSD || SI_FREEBSD)
569 #define SANITIZER_INTERCEPT_TTYENT (SI_NETBSD || SI_FREEBSD)
570 #define SANITIZER_INTERCEPT_TTYENTPATH SI_NETBSD
571 #define SANITIZER_INTERCEPT_PROTOENT (SI_LINUX || SI_NETBSD || SI_FREEBSD)
572 #define SANITIZER_INTERCEPT_PROTOENT_R SI_GLIBC
573 #define SANITIZER_INTERCEPT_NETENT (SI_LINUX || SI_NETBSD || SI_FREEBSD)
574 #define SANITIZER_INTERCEPT_SETVBUF \
575 (SI_NETBSD || SI_FREEBSD || SI_LINUX || SI_MAC)
576 #define SANITIZER_INTERCEPT_GETMNTINFO (SI_NETBSD || SI_FREEBSD || SI_MAC)
577 #define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
578 #define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD
579 #define SANITIZER_INTERCEPT_REGEX (SI_NETBSD || SI_FREEBSD || SI_LINUX)
580 #define SANITIZER_INTERCEPT_REGEXSUB SI_NETBSD
581 #define SANITIZER_INTERCEPT_FTS (SI_NETBSD || SI_FREEBSD)
582 #define SANITIZER_INTERCEPT_SYSCTL (SI_NETBSD || SI_FREEBSD || SI_MAC)
583 #define SANITIZER_INTERCEPT_ASYSCTL SI_NETBSD
584 #define SANITIZER_INTERCEPT_SYSCTLGETMIBINFO SI_NETBSD
585 #define SANITIZER_INTERCEPT_NL_LANGINFO (SI_NETBSD || SI_FREEBSD || SI_MAC)
586 #define SANITIZER_INTERCEPT_MODCTL SI_NETBSD
587 #define SANITIZER_INTERCEPT_CAPSICUM SI_FREEBSD
588 #define SANITIZER_INTERCEPT_STRTONUM (SI_NETBSD || SI_FREEBSD)
589 #define SANITIZER_INTERCEPT_FPARSELN (SI_NETBSD || SI_FREEBSD)
590 #define SANITIZER_INTERCEPT_STATVFS1 SI_NETBSD
591 #define SANITIZER_INTERCEPT_STRTOI SI_NETBSD
592 #define SANITIZER_INTERCEPT_CAPSICUM SI_FREEBSD
593 #define SANITIZER_INTERCEPT_SHA1 SI_NETBSD
594 #define SANITIZER_INTERCEPT_MD4 SI_NETBSD
595 #define SANITIZER_INTERCEPT_RMD160 SI_NETBSD
596 #define SANITIZER_INTERCEPT_FSEEK (SI_NETBSD || SI_FREEBSD)
597 #define SANITIZER_INTERCEPT_MD2 SI_NETBSD
598 #define SANITIZER_INTERCEPT_CDB SI_NETBSD
599 #define SANITIZER_INTERCEPT_VIS (SI_NETBSD || SI_FREEBSD)
600 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
601 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
602 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
603 #define SANITIZER_INTERCEPT_FUNOPEN (SI_NETBSD || SI_FREEBSD)
604 #define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
605 #define SANITIZER_INTERCEPT_GETFSENT (SI_FREEBSD || SI_NETBSD || SI_MAC)
606 #define SANITIZER_INTERCEPT_ARC4RANDOM (SI_FREEBSD || SI_NETBSD || SI_MAC)
607 #define SANITIZER_INTERCEPT_FDEVNAME SI_FREEBSD
608 #define SANITIZER_INTERCEPT_GETUSERSHELL (SI_POSIX && !SI_ANDROID)
609 #define SANITIZER_INTERCEPT_SL_INIT (SI_FREEBSD || SI_NETBSD)
611 #define SANITIZER_INTERCEPT_GETRANDOM \
612 ((SI_LINUX && __GLIBC_PREREQ(2, 25)) || SI_FREEBSD || SI_SOLARIS)
613 #define SANITIZER_INTERCEPT___CXA_ATEXIT SI_NETBSD
614 #define SANITIZER_INTERCEPT_ATEXIT SI_NETBSD
615 #define SANITIZER_INTERCEPT_PTHREAD_ATFORK SI_NETBSD
616 #define SANITIZER_INTERCEPT_GETENTROPY \
617 ((SI_LINUX && __GLIBC_PREREQ(2, 25)) || SI_FREEBSD || SI_SOLARIS)
618 #define SANITIZER_INTERCEPT_QSORT \
619 (SI_POSIX && !SI_IOSSIM && !SI_WATCHOS && !SI_TVOS && !SI_ANDROID)
620 #define SANITIZER_INTERCEPT_QSORT_R SI_GLIBC
621 #define SANITIZER_INTERCEPT_BSEARCH \
622 (SI_POSIX && !SI_IOSSIM && !SI_WATCHOS && !SI_TVOS && !SI_ANDROID)
623 // sigaltstack on i386 macOS cannot be intercepted due to setjmp()
624 // calling it and assuming that it does not clobber registers.
625 #define SANITIZER_INTERCEPT_SIGALTSTACK \
626 (SI_POSIX && !(SANITIZER_APPLE && SANITIZER_I386))
627 #define SANITIZER_INTERCEPT_UNAME (SI_POSIX && !SI_FREEBSD)
628 #define SANITIZER_INTERCEPT___XUNAME SI_FREEBSD
629 #define SANITIZER_INTERCEPT_FLOPEN SI_FREEBSD
630 #define SANITIZER_INTERCEPT_PROCCTL SI_FREEBSD
631 #define SANITIZER_INTERCEPT_ARGP_PARSE SI_GLIBC
632 #define SANITIZER_INTERCEPT_CPUSET_GETAFFINITY SI_FREEBSD
633 // FIXME: also available from musl 1.2.5
634 #define SANITIZER_INTERCEPT_PREADV2 (SI_LINUX && __GLIBC_PREREQ(2, 26))
635 #define SANITIZER_INTERCEPT_PWRITEV2 (SI_LINUX && __GLIBC_PREREQ(2, 26))
636 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
637 __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000
638 # define SI_MAC_OS_DEPLOYMENT_MIN_13_00 1
639 #else
640 # define SI_MAC_OS_DEPLOYMENT_MIN_13_00 0
641 #endif
642 #define SANITIZER_INTERCEPT_FREADLINK (SI_MAC && SI_MAC_OS_DEPLOYMENT_MIN_13_00)
643 // This macro gives a way for downstream users to override the above
644 // interceptor macros irrespective of the platform they are on. They have
645 // to do two things:
646 // 1. Build compiler-rt with -DSANITIZER_OVERRIDE_INTERCEPTORS.
647 // 2. Provide a header file named sanitizer_intercept_overriders.h in the
648 // include path for their compiler-rt build.
649 // An example of an overrider for strlen interceptor that one can list in
650 // sanitizer_intercept_overriders.h is as follows:
652 // #ifdef SANITIZER_INTERCEPT_STRLEN
653 // #undef SANITIZER_INTERCEPT_STRLEN
654 // #define SANITIZER_INTERCEPT_STRLEN <value of choice>
655 // #endif
657 // This "feature" is useful for downstream users who do not want some of
658 // their libc funtions to be intercepted. They can selectively disable
659 // interception of those functions.
660 #ifdef SANITIZER_OVERRIDE_INTERCEPTORS
661 #include <sanitizer_intercept_overriders.h>
662 #endif
664 #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H