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