1 //===-- sanitizer_platform_interceptors.h -----------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
26 #if !SANITIZER_WINDOWS
32 #if SI_WINDOWS && SI_POSIX
33 #error "Windows is not 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"
43 #if SANITIZER_LINUX && !SANITIZER_ANDROID
44 #define SI_LINUX_NOT_ANDROID 1
46 #define SI_LINUX_NOT_ANDROID 0
111 #if SANITIZER_FUCHSIA
112 #define SI_NOT_FUCHSIA 0
114 #define SI_NOT_FUCHSIA 1
117 #if SANITIZER_SOLARIS
123 #if SANITIZER_SOLARIS32
124 #define SI_SOLARIS32 1
126 #define SI_SOLARIS32 0
129 #if SANITIZER_POSIX && !SANITIZER_APPLE
130 #define SI_POSIX_NOT_MAC 1
132 #define SI_POSIX_NOT_MAC 0
135 #if SANITIZER_LINUX && !SANITIZER_FREEBSD
136 #define SI_LINUX_NOT_FREEBSD 1
138 #define SI_LINUX_NOT_FREEBSD 0
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
167 #define SI_MAC_DEPLOYMENT_BELOW_10_7 0
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)
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
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
186 #define SANITIZER_INTERCEPT_PREAD64 (SI_GLIBC || SI_SOLARIS32)
187 #define SANITIZER_INTERCEPT_PWRITE64 (SI_GLIBC || SI_SOLARIS32)
189 #define SANITIZER_INTERCEPT_READV SI_POSIX
190 #define SANITIZER_INTERCEPT_WRITEV SI_POSIX
192 #define SANITIZER_INTERCEPT_PREADV \
193 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
194 #define SANITIZER_INTERCEPT_PWRITEV SI_LINUX_NOT_ANDROID
195 #define SANITIZER_INTERCEPT_PREADV64 SI_GLIBC
196 #define SANITIZER_INTERCEPT_PWRITEV64 SI_GLIBC
198 #define SANITIZER_INTERCEPT_PRCTL SI_LINUX
200 #define SANITIZER_INTERCEPT_LOCALTIME_AND_FRIENDS SI_POSIX
201 #define SANITIZER_INTERCEPT_STRPTIME SI_POSIX
203 #define SANITIZER_INTERCEPT_SCANF SI_POSIX
204 #define SANITIZER_INTERCEPT_ISOC99_SCANF SI_GLIBC
206 #ifndef SANITIZER_INTERCEPT_PRINTF
207 #define SANITIZER_INTERCEPT_PRINTF SI_POSIX
208 #define SANITIZER_INTERCEPT_PRINTF_L (SI_FREEBSD || SI_NETBSD)
209 #define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_GLIBC
212 #define SANITIZER_INTERCEPT___PRINTF_CHK \
213 (SANITIZER_INTERCEPT_PRINTF && SI_GLIBC)
215 #define SANITIZER_INTERCEPT_FREXP SI_NOT_FUCHSIA
216 #define SANITIZER_INTERCEPT_FREXPF_FREXPL SI_POSIX
218 #define SANITIZER_INTERCEPT_GETPWNAM_AND_FRIENDS SI_POSIX
219 #define SANITIZER_INTERCEPT_GETPWNAM_R_AND_FRIENDS \
220 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
221 #define SANITIZER_INTERCEPT_GETPWENT \
222 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
223 #define SANITIZER_INTERCEPT_FGETGRENT_R (SI_GLIBC || SI_SOLARIS)
224 #define SANITIZER_INTERCEPT_FGETPWENT SI_LINUX_NOT_ANDROID || SI_SOLARIS
225 #define SANITIZER_INTERCEPT_GETPWENT_R \
226 (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS)
227 #define SANITIZER_INTERCEPT_FGETPWENT_R (SI_FREEBSD || SI_GLIBC || SI_SOLARIS)
228 #define SANITIZER_INTERCEPT_SETPWENT \
229 (SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
230 #define SANITIZER_INTERCEPT_CLOCK_GETTIME \
231 (SI_FREEBSD || SI_NETBSD || SI_LINUX || SI_SOLARIS)
232 #define SANITIZER_INTERCEPT_CLOCK_GETCPUCLOCKID \
233 (SI_LINUX || SI_FREEBSD || SI_NETBSD)
234 #define SANITIZER_INTERCEPT_GETITIMER SI_POSIX
235 #define SANITIZER_INTERCEPT_TIME SI_POSIX
236 #define SANITIZER_INTERCEPT_GLOB (SI_GLIBC || SI_SOLARIS)
237 #define SANITIZER_INTERCEPT_GLOB64 SI_GLIBC
238 #define SANITIZER_INTERCEPT___B64_TO SI_LINUX_NOT_ANDROID
239 #define SANITIZER_INTERCEPT_DN_COMP_EXPAND SI_LINUX_NOT_ANDROID
240 #define SANITIZER_INTERCEPT_POSIX_SPAWN SI_POSIX
241 #define SANITIZER_INTERCEPT_WAIT SI_POSIX
242 #define SANITIZER_INTERCEPT_INET SI_POSIX
243 #define SANITIZER_INTERCEPT_PTHREAD_GETSCHEDPARAM SI_POSIX
244 #define SANITIZER_INTERCEPT_GETADDRINFO SI_POSIX
245 #define SANITIZER_INTERCEPT_GETNAMEINFO SI_POSIX
246 #define SANITIZER_INTERCEPT_GETSOCKNAME SI_POSIX
247 #define SANITIZER_INTERCEPT_GETHOSTBYNAME SI_POSIX
248 #define SANITIZER_INTERCEPT_GETHOSTBYNAME2 SI_POSIX && !SI_SOLARIS
249 #define SANITIZER_INTERCEPT_GETHOSTBYNAME_R \
250 (SI_FREEBSD || SI_LINUX || SI_SOLARIS)
251 #define SANITIZER_INTERCEPT_GETHOSTBYNAME2_R \
252 (SI_FREEBSD || SI_LINUX_NOT_ANDROID)
253 #define SANITIZER_INTERCEPT_GETHOSTBYADDR_R \
254 (SI_FREEBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
255 #define SANITIZER_INTERCEPT_GETHOSTENT_R (SI_FREEBSD || SI_GLIBC || SI_SOLARIS)
256 #define SANITIZER_INTERCEPT_GETSOCKOPT SI_POSIX
257 #define SANITIZER_INTERCEPT_ACCEPT SI_POSIX
258 #define SANITIZER_INTERCEPT_ACCEPT4 \
259 (SI_LINUX_NOT_ANDROID || SI_NETBSD || SI_FREEBSD)
260 #define SANITIZER_INTERCEPT_PACCEPT SI_NETBSD
261 #define SANITIZER_INTERCEPT_MODF SI_POSIX
262 #define SANITIZER_INTERCEPT_RECVMSG SI_POSIX
263 #define SANITIZER_INTERCEPT_SENDMSG SI_POSIX
264 #define SANITIZER_INTERCEPT_RECVMMSG SI_LINUX
265 #define SANITIZER_INTERCEPT_SENDMMSG SI_LINUX
266 #define SANITIZER_INTERCEPT_SYSMSG SI_LINUX_NOT_ANDROID
267 #define SANITIZER_INTERCEPT_GETPEERNAME SI_POSIX
268 #define SANITIZER_INTERCEPT_IOCTL SI_POSIX
269 #define SANITIZER_INTERCEPT_INET_ATON SI_POSIX
270 #define SANITIZER_INTERCEPT_SYSINFO SI_LINUX
271 #define SANITIZER_INTERCEPT_READDIR SI_POSIX
272 #define SANITIZER_INTERCEPT_READDIR64 SI_GLIBC || SI_SOLARIS32
273 #if SI_LINUX_NOT_ANDROID && \
274 (defined(__i386) || defined(__x86_64) || defined(__mips64) || \
275 defined(__powerpc64__) || defined(__aarch64__) || defined(__arm__) || \
276 defined(__s390__) || defined(__loongarch__) || SANITIZER_RISCV64)
277 #define SANITIZER_INTERCEPT_PTRACE 1
279 #define SANITIZER_INTERCEPT_PTRACE 0
281 #define SANITIZER_INTERCEPT_SETLOCALE SI_POSIX
282 #define SANITIZER_INTERCEPT_GETCWD SI_POSIX
283 #define SANITIZER_INTERCEPT_GET_CURRENT_DIR_NAME SI_LINUX_NOT_ANDROID
284 #define SANITIZER_INTERCEPT_STRTOIMAX SI_POSIX
285 #define SANITIZER_INTERCEPT_MBSTOWCS SI_POSIX
286 #define SANITIZER_INTERCEPT_MBSNRTOWCS \
287 (SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
288 #define SANITIZER_INTERCEPT_WCSTOMBS SI_POSIX
289 #define SANITIZER_INTERCEPT_STRXFRM SI_POSIX
290 #define SANITIZER_INTERCEPT___STRXFRM_L SI_LINUX
291 #define SANITIZER_INTERCEPT_WCSXFRM SI_POSIX
292 #define SANITIZER_INTERCEPT___WCSXFRM_L SI_LINUX
293 #define SANITIZER_INTERCEPT_WCSNRTOMBS \
294 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
295 #define SANITIZER_INTERCEPT_WCRTOMB \
296 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
297 #define SANITIZER_INTERCEPT_WCTOMB \
298 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
299 #define SANITIZER_INTERCEPT_TCGETATTR SI_LINUX_NOT_ANDROID || SI_SOLARIS
300 #define SANITIZER_INTERCEPT_REALPATH SI_POSIX
301 #define SANITIZER_INTERCEPT_CANONICALIZE_FILE_NAME (SI_GLIBC || SI_SOLARIS)
302 #define SANITIZER_INTERCEPT_CONFSTR \
303 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
304 #define SANITIZER_INTERCEPT_SCHED_GETAFFINITY SI_LINUX_NOT_ANDROID
305 #define SANITIZER_INTERCEPT_SCHED_GETPARAM SI_LINUX_NOT_ANDROID || SI_SOLARIS
306 #define SANITIZER_INTERCEPT_STRERROR SI_POSIX
307 #define SANITIZER_INTERCEPT_STRERROR_R SI_POSIX
308 #define SANITIZER_INTERCEPT_XPG_STRERROR_R SI_LINUX_NOT_ANDROID
309 #define SANITIZER_INTERCEPT_SCANDIR \
310 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
311 #define SANITIZER_INTERCEPT_SCANDIR64 SI_GLIBC || SI_SOLARIS32
312 #define SANITIZER_INTERCEPT_GETGROUPS SI_POSIX
313 #define SANITIZER_INTERCEPT_POLL SI_POSIX
314 #define SANITIZER_INTERCEPT_PPOLL SI_LINUX_NOT_ANDROID || SI_SOLARIS
315 #define SANITIZER_INTERCEPT_WORDEXP \
316 (SI_FREEBSD || SI_NETBSD || (SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID || \
318 #define SANITIZER_INTERCEPT_SIGWAIT SI_POSIX
319 #define SANITIZER_INTERCEPT_SIGWAITINFO SI_LINUX_NOT_ANDROID || SI_SOLARIS
320 #define SANITIZER_INTERCEPT_SIGTIMEDWAIT SI_LINUX_NOT_ANDROID || SI_SOLARIS
321 #define SANITIZER_INTERCEPT_SIGSETOPS \
322 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
323 #define SANITIZER_INTERCEPT_SIGSET_LOGICOPS SI_LINUX_NOT_ANDROID
324 #define SANITIZER_INTERCEPT_SIGPENDING SI_POSIX
325 #define SANITIZER_INTERCEPT_SIGPROCMASK SI_POSIX
326 #define SANITIZER_INTERCEPT_PTHREAD_SIGMASK SI_POSIX
327 #define SANITIZER_INTERCEPT_BACKTRACE \
328 (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS)
329 #define SANITIZER_INTERCEPT_GETMNTENT SI_LINUX
330 #define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID
331 #define SANITIZER_INTERCEPT_STATFS \
332 (SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
333 #define SANITIZER_INTERCEPT_STATFS64 SI_GLIBC && SANITIZER_HAS_STATFS64
334 #define SANITIZER_INTERCEPT_STATVFS \
335 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
336 #define SANITIZER_INTERCEPT_STATVFS64 SI_GLIBC
337 #define SANITIZER_INTERCEPT_INITGROUPS SI_POSIX
338 #define SANITIZER_INTERCEPT_ETHER_NTOA_ATON SI_POSIX
339 #define SANITIZER_INTERCEPT_ETHER_HOST \
340 (SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID)
341 #define SANITIZER_INTERCEPT_ETHER_R (SI_FREEBSD || SI_LINUX_NOT_ANDROID)
342 #define SANITIZER_INTERCEPT_SHMCTL \
343 (((SI_FREEBSD || SI_LINUX_NOT_ANDROID) && SANITIZER_WORDSIZE == 64) || \
344 SI_NETBSD || SI_SOLARIS)
345 #define SANITIZER_INTERCEPT_RANDOM_R SI_GLIBC
346 #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GET SI_POSIX
347 #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSCHED \
348 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
349 #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETAFFINITY_NP SI_GLIBC
350 #define SANITIZER_INTERCEPT_PTHREAD_GETAFFINITY_NP SI_LINUX_NOT_ANDROID
351 #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GET_SCHED SI_POSIX
352 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPSHARED \
353 (SI_POSIX && !SI_NETBSD)
354 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETTYPE SI_POSIX
355 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPROTOCOL \
356 (SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
357 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPRIOCEILING \
358 (SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
359 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST \
360 (SI_LINUX_NOT_ANDROID || SI_SOLARIS)
361 #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST_NP SI_LINUX_NOT_ANDROID
362 #define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETPSHARED \
363 (SI_POSIX && !SI_NETBSD)
364 #define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETKIND_NP SI_GLIBC
365 #define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETPSHARED (SI_POSIX && !SI_NETBSD)
366 #define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETCLOCK \
367 (SI_LINUX_NOT_ANDROID || SI_SOLARIS)
368 #define SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GETPSHARED \
369 (SI_LINUX_NOT_ANDROID && !SI_NETBSD)
370 #define SANITIZER_INTERCEPT_THR_EXIT SI_FREEBSD
371 #define SANITIZER_INTERCEPT_TMPNAM SI_POSIX
372 #define SANITIZER_INTERCEPT_TMPNAM_R (SI_GLIBC || SI_SOLARIS)
373 #define SANITIZER_INTERCEPT_PTSNAME SI_LINUX
374 #define SANITIZER_INTERCEPT_PTSNAME_R SI_LINUX
375 #define SANITIZER_INTERCEPT_TTYNAME SI_POSIX
376 #define SANITIZER_INTERCEPT_TTYNAME_R SI_POSIX
377 #define SANITIZER_INTERCEPT_TEMPNAM SI_POSIX
378 #define SANITIZER_INTERCEPT_SINCOS SI_LINUX || SI_SOLARIS
379 #define SANITIZER_INTERCEPT_REMQUO SI_POSIX
380 #define SANITIZER_INTERCEPT_REMQUOL (SI_POSIX && !SI_NETBSD)
381 #define SANITIZER_INTERCEPT_LGAMMA SI_POSIX
382 #define SANITIZER_INTERCEPT_LGAMMAL (SI_POSIX && !SI_NETBSD)
383 #define SANITIZER_INTERCEPT_LGAMMA_R (SI_FREEBSD || SI_LINUX || SI_SOLARIS)
384 #define SANITIZER_INTERCEPT_LGAMMAL_R SI_LINUX_NOT_ANDROID || SI_SOLARIS
385 #define SANITIZER_INTERCEPT_DRAND48_R SI_GLIBC
386 #define SANITIZER_INTERCEPT_RAND_R \
387 (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
388 #define SANITIZER_INTERCEPT_ICONV \
389 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
390 #define SANITIZER_INTERCEPT_TIMES SI_POSIX
392 // FIXME: getline seems to be available on OSX 10.7
393 #define SANITIZER_INTERCEPT_GETLINE \
394 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
396 #define SANITIZER_INTERCEPT__EXIT \
397 (SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_MAC || SI_SOLARIS)
399 #define SANITIZER_INTERCEPT___LIBC_MUTEX SI_NETBSD
400 #define SANITIZER_INTERCEPT_PTHREAD_SETNAME_NP \
401 (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS)
402 #define SANITIZER_INTERCEPT_PTHREAD_GETNAME_NP \
403 (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS)
405 #define SANITIZER_INTERCEPT_TLS_GET_ADDR \
406 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
408 #define SANITIZER_INTERCEPT_LISTXATTR SI_LINUX
409 #define SANITIZER_INTERCEPT_GETXATTR SI_LINUX
410 #define SANITIZER_INTERCEPT_GETRESID SI_LINUX
411 #define SANITIZER_INTERCEPT_GETIFADDRS \
412 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS)
413 #define SANITIZER_INTERCEPT_IF_INDEXTONAME \
414 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS)
415 #define SANITIZER_INTERCEPT_CAPGET SI_LINUX_NOT_ANDROID
416 #if SI_LINUX && defined(__arm__)
417 #define SANITIZER_INTERCEPT_AEABI_MEM 1
419 #define SANITIZER_INTERCEPT_AEABI_MEM 0
421 #define SANITIZER_INTERCEPT___BZERO SI_MAC || SI_GLIBC
422 #define SANITIZER_INTERCEPT_BZERO SI_LINUX_NOT_ANDROID
423 #define SANITIZER_INTERCEPT_FTIME (!SI_FREEBSD && !SI_NETBSD && SI_POSIX)
424 #define SANITIZER_INTERCEPT_XDR (SI_GLIBC || SI_SOLARIS)
425 #define SANITIZER_INTERCEPT_XDRREC SI_GLIBC
426 #define SANITIZER_INTERCEPT_TSEARCH \
427 (SI_LINUX_NOT_ANDROID || SI_MAC || SI_NETBSD || SI_SOLARIS)
428 #define SANITIZER_INTERCEPT_LIBIO_INTERNALS SI_GLIBC
429 #define SANITIZER_INTERCEPT_FOPEN SI_POSIX
430 #define SANITIZER_INTERCEPT_FOPEN64 (SI_GLIBC || SI_SOLARIS32)
431 #define SANITIZER_INTERCEPT_OPEN_MEMSTREAM \
432 (SI_LINUX_NOT_ANDROID || SI_NETBSD || SI_SOLARIS)
433 #define SANITIZER_INTERCEPT_OBSTACK SI_GLIBC
434 #define SANITIZER_INTERCEPT_FFLUSH SI_POSIX
435 #define SANITIZER_INTERCEPT_FCLOSE SI_POSIX
437 #ifndef SANITIZER_INTERCEPT_DLOPEN_DLCLOSE
438 #define SANITIZER_INTERCEPT_DLOPEN_DLCLOSE \
439 (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS)
442 #define SANITIZER_INTERCEPT_GETPASS \
443 (SI_LINUX_NOT_ANDROID || SI_MAC || SI_NETBSD)
444 #define SANITIZER_INTERCEPT_TIMERFD SI_LINUX_NOT_ANDROID
446 #define SANITIZER_INTERCEPT_MLOCKX SI_POSIX
447 #define SANITIZER_INTERCEPT_FOPENCOOKIE SI_LINUX_NOT_ANDROID
448 #define SANITIZER_INTERCEPT_SEM \
449 (SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_SOLARIS)
450 #define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL SI_POSIX
451 #define SANITIZER_INTERCEPT_MINCORE \
452 (SI_LINUX || SI_NETBSD || SI_FREEBSD || SI_SOLARIS)
453 #define SANITIZER_INTERCEPT_PROCESS_VM_READV SI_LINUX
454 #define SANITIZER_INTERCEPT_CTERMID \
455 (SI_LINUX || SI_MAC || SI_FREEBSD || SI_NETBSD || SI_SOLARIS)
456 #define SANITIZER_INTERCEPT_CTERMID_R (SI_MAC || SI_FREEBSD || SI_SOLARIS)
458 #define SANITIZER_INTERCEPTOR_HOOKS \
459 (SI_LINUX || SI_MAC || SI_WINDOWS || SI_FREEBSD || SI_NETBSD || SI_SOLARIS)
460 #define SANITIZER_INTERCEPT_RECV_RECVFROM SI_POSIX
461 #define SANITIZER_INTERCEPT_SEND_SENDTO SI_POSIX
462 #define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE SI_LINUX
464 #define SI_STAT_LINUX (SI_LINUX && __GLIBC_PREREQ(2, 33))
465 #define SANITIZER_INTERCEPT_STAT \
466 (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS || \
468 #define SANITIZER_INTERCEPT_STAT64 SI_STAT_LINUX && SANITIZER_HAS_STAT64
469 #define SANITIZER_INTERCEPT_LSTAT (SI_NETBSD || SI_FREEBSD || SI_STAT_LINUX)
470 #define SANITIZER_INTERCEPT___XSTAT \
471 ((!SANITIZER_INTERCEPT_STAT && SI_POSIX) || SI_STAT_LINUX)
472 #define SANITIZER_INTERCEPT___XSTAT64 SI_GLIBC
473 #define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT
474 #define SANITIZER_INTERCEPT___LXSTAT64 SI_GLIBC
476 #define SANITIZER_INTERCEPT_UTMP \
477 (SI_POSIX && !SI_MAC && !SI_FREEBSD && !SI_NETBSD)
478 #define SANITIZER_INTERCEPT_UTMPX \
479 (SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD)
481 #define SANITIZER_INTERCEPT_GETLOADAVG \
482 (SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD)
484 #define SANITIZER_INTERCEPT_MMAP SI_POSIX
485 #define SANITIZER_INTERCEPT_MMAP64 SI_GLIBC || SI_SOLARIS
486 #define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO (SI_GLIBC || SI_ANDROID)
487 #define SANITIZER_INTERCEPT_MEMALIGN (!SI_FREEBSD && !SI_MAC && !SI_NETBSD)
488 #define SANITIZER_INTERCEPT___LIBC_MEMALIGN SI_GLIBC
489 #define SANITIZER_INTERCEPT_PVALLOC (SI_GLIBC || SI_ANDROID)
490 #define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64)
491 #define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX
492 #define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC)
493 #define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD)
494 #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
495 #define SANITIZER_INTERCEPT_WCSCAT SI_POSIX
496 #define SANITIZER_INTERCEPT_WCSDUP SI_POSIX
497 #define SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION (!SI_WINDOWS && SI_NOT_FUCHSIA)
498 #define SANITIZER_INTERCEPT_BSD_SIGNAL SI_ANDROID
500 #define SANITIZER_INTERCEPT_ACCT (SI_NETBSD || SI_FREEBSD)
501 #define SANITIZER_INTERCEPT_USER_FROM_UID SI_NETBSD
502 #define SANITIZER_INTERCEPT_UID_FROM_USER SI_NETBSD
503 #define SANITIZER_INTERCEPT_GROUP_FROM_GID SI_NETBSD
504 #define SANITIZER_INTERCEPT_GID_FROM_GROUP SI_NETBSD
505 #define SANITIZER_INTERCEPT_ACCESS (SI_NETBSD || SI_FREEBSD)
506 #define SANITIZER_INTERCEPT_FACCESSAT (SI_NETBSD || SI_FREEBSD)
507 #define SANITIZER_INTERCEPT_GETGROUPLIST \
508 (SI_NETBSD || SI_FREEBSD || SI_LINUX)
509 #define SANITIZER_INTERCEPT_STRLCPY \
510 (SI_NETBSD || SI_FREEBSD || SI_MAC || SI_ANDROID)
512 #define SANITIZER_INTERCEPT_NAME_TO_HANDLE_AT SI_LINUX_NOT_ANDROID
513 #define SANITIZER_INTERCEPT_OPEN_BY_HANDLE_AT SI_LINUX_NOT_ANDROID
515 #define SANITIZER_INTERCEPT_READLINK SI_POSIX
516 #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
517 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101000
518 #define SI_MAC_DEPLOYMENT_BELOW_10_10 1
520 #define SI_MAC_DEPLOYMENT_BELOW_10_10 0
522 #define SANITIZER_INTERCEPT_READLINKAT \
523 (SI_POSIX && !SI_MAC_DEPLOYMENT_BELOW_10_10)
525 #define SANITIZER_INTERCEPT_DEVNAME (SI_NETBSD || SI_FREEBSD)
526 #define SANITIZER_INTERCEPT_DEVNAME_R (SI_NETBSD || SI_FREEBSD)
527 #define SANITIZER_INTERCEPT_FGETLN (SI_NETBSD || SI_FREEBSD)
528 #define SANITIZER_INTERCEPT_STRMODE (SI_NETBSD || SI_FREEBSD)
529 #define SANITIZER_INTERCEPT_TTYENT (SI_NETBSD || SI_FREEBSD)
530 #define SANITIZER_INTERCEPT_TTYENTPATH SI_NETBSD
531 #define SANITIZER_INTERCEPT_PROTOENT (SI_LINUX || SI_NETBSD || SI_FREEBSD)
532 #define SANITIZER_INTERCEPT_PROTOENT_R SI_GLIBC
533 #define SANITIZER_INTERCEPT_NETENT (SI_LINUX || SI_NETBSD || SI_FREEBSD)
534 #define SANITIZER_INTERCEPT_SETVBUF \
535 (SI_NETBSD || SI_FREEBSD || SI_LINUX || SI_MAC)
536 #define SANITIZER_INTERCEPT_GETMNTINFO (SI_NETBSD || SI_FREEBSD || SI_MAC)
537 #define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
538 #define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD
539 #define SANITIZER_INTERCEPT_REGEX (SI_NETBSD || SI_FREEBSD || SI_LINUX)
540 #define SANITIZER_INTERCEPT_REGEXSUB SI_NETBSD
541 #define SANITIZER_INTERCEPT_FTS (SI_NETBSD || SI_FREEBSD)
542 #define SANITIZER_INTERCEPT_SYSCTL (SI_NETBSD || SI_FREEBSD || SI_MAC)
543 #define SANITIZER_INTERCEPT_ASYSCTL SI_NETBSD
544 #define SANITIZER_INTERCEPT_SYSCTLGETMIBINFO SI_NETBSD
545 #define SANITIZER_INTERCEPT_NL_LANGINFO (SI_NETBSD || SI_FREEBSD || SI_MAC)
546 #define SANITIZER_INTERCEPT_MODCTL SI_NETBSD
547 #define SANITIZER_INTERCEPT_CAPSICUM SI_FREEBSD
548 #define SANITIZER_INTERCEPT_STRTONUM (SI_NETBSD || SI_FREEBSD)
549 #define SANITIZER_INTERCEPT_FPARSELN (SI_NETBSD || SI_FREEBSD)
550 #define SANITIZER_INTERCEPT_STATVFS1 SI_NETBSD
551 #define SANITIZER_INTERCEPT_STRTOI SI_NETBSD
552 #define SANITIZER_INTERCEPT_CAPSICUM SI_FREEBSD
553 #define SANITIZER_INTERCEPT_SHA1 SI_NETBSD
554 #define SANITIZER_INTERCEPT_MD4 SI_NETBSD
555 #define SANITIZER_INTERCEPT_RMD160 SI_NETBSD
556 #define SANITIZER_INTERCEPT_MD5 (SI_NETBSD || SI_FREEBSD)
557 #define SANITIZER_INTERCEPT_FSEEK (SI_NETBSD || SI_FREEBSD)
558 #define SANITIZER_INTERCEPT_MD2 SI_NETBSD
559 #define SANITIZER_INTERCEPT_SHA2 (SI_NETBSD || SI_FREEBSD)
560 #define SANITIZER_INTERCEPT_CDB SI_NETBSD
561 #define SANITIZER_INTERCEPT_VIS (SI_NETBSD || SI_FREEBSD)
562 #define SANITIZER_INTERCEPT_POPEN SI_POSIX
563 #define SANITIZER_INTERCEPT_POPENVE SI_NETBSD
564 #define SANITIZER_INTERCEPT_PCLOSE SI_POSIX
565 #define SANITIZER_INTERCEPT_FUNOPEN (SI_NETBSD || SI_FREEBSD)
566 #define SANITIZER_INTERCEPT_FUNOPEN2 SI_NETBSD
567 #define SANITIZER_INTERCEPT_GETFSENT (SI_FREEBSD || SI_NETBSD || SI_MAC)
568 #define SANITIZER_INTERCEPT_ARC4RANDOM (SI_FREEBSD || SI_NETBSD || SI_MAC)
569 #define SANITIZER_INTERCEPT_FDEVNAME SI_FREEBSD
570 #define SANITIZER_INTERCEPT_GETUSERSHELL (SI_POSIX && !SI_ANDROID)
571 #define SANITIZER_INTERCEPT_SL_INIT (SI_FREEBSD || SI_NETBSD)
573 #define SANITIZER_INTERCEPT_GETRANDOM \
574 ((SI_LINUX && __GLIBC_PREREQ(2, 25)) || SI_FREEBSD)
575 #define SANITIZER_INTERCEPT___CXA_ATEXIT SI_NETBSD
576 #define SANITIZER_INTERCEPT_ATEXIT SI_NETBSD
577 #define SANITIZER_INTERCEPT_PTHREAD_ATFORK SI_NETBSD
578 #define SANITIZER_INTERCEPT_GETENTROPY SI_FREEBSD
579 #define SANITIZER_INTERCEPT_QSORT \
580 (SI_POSIX && !SI_IOSSIM && !SI_WATCHOS && !SI_TVOS && !SI_ANDROID)
581 #define SANITIZER_INTERCEPT_QSORT_R SI_GLIBC
582 #define SANITIZER_INTERCEPT_BSEARCH \
583 (SI_POSIX && !SI_IOSSIM && !SI_WATCHOS && !SI_TVOS && !SI_ANDROID)
584 // sigaltstack on i386 macOS cannot be intercepted due to setjmp()
585 // calling it and assuming that it does not clobber registers.
586 #define SANITIZER_INTERCEPT_SIGALTSTACK \
587 (SI_POSIX && !(SANITIZER_APPLE && SANITIZER_I386))
588 #define SANITIZER_INTERCEPT_UNAME (SI_POSIX && !SI_FREEBSD)
589 #define SANITIZER_INTERCEPT___XUNAME SI_FREEBSD
590 #define SANITIZER_INTERCEPT_FLOPEN SI_FREEBSD
591 #define SANITIZER_INTERCEPT_PROCCTL SI_FREEBSD
592 #define SANITIZER_INTERCEPT_HEXDUMP SI_FREEBSD
593 #define SANITIZER_INTERCEPT_ARGP_PARSE SI_GLIBC
595 // This macro gives a way for downstream users to override the above
596 // interceptor macros irrespective of the platform they are on. They have
598 // 1. Build compiler-rt with -DSANITIZER_OVERRIDE_INTERCEPTORS.
599 // 2. Provide a header file named sanitizer_intercept_overriders.h in the
600 // include path for their compiler-rt build.
601 // An example of an overrider for strlen interceptor that one can list in
602 // sanitizer_intercept_overriders.h is as follows:
604 // #ifdef SANITIZER_INTERCEPT_STRLEN
605 // #undef SANITIZER_INTERCEPT_STRLEN
606 // #define SANITIZER_INTERCEPT_STRLEN <value of choice>
609 // This "feature" is useful for downstream users who do not want some of
610 // their libc funtions to be intercepted. They can selectively disable
611 // interception of those functions.
612 #ifdef SANITIZER_OVERRIDE_INTERCEPTORS
613 #include <sanitizer_intercept_overriders.h>
616 #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H