Path: blob/main/contrib/llvm-project/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
213766 views
//===--- rtsan_interceptors.cpp - Realtime Sanitizer ------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8//===----------------------------------------------------------------------===//910#include "sanitizer_common/sanitizer_platform.h"11#if SANITIZER_POSIX1213#include "rtsan/rtsan_interceptors.h"1415#include "interception/interception.h"16#include "sanitizer_common/sanitizer_allocator_dlsym.h"17#include "sanitizer_common/sanitizer_platform_interceptors.h"1819#include "interception/interception.h"20#include "rtsan/rtsan.h"2122#if SANITIZER_APPLE23#include <libkern/OSAtomic.h>24#include <os/lock.h>25#endif // SANITIZER_APPLE2627#if SANITIZER_INTERCEPT_MEMALIGN || SANITIZER_INTERCEPT_PVALLOC28#include <malloc.h>29#endif3031#include <fcntl.h>32#include <poll.h>33#include <pthread.h>34#include <stdarg.h>35#include <stdio.h>36#if SANITIZER_LINUX37#include <linux/mman.h>38#include <sys/inotify.h>39#endif40#include <sys/select.h>41#include <sys/socket.h>42#include <sys/stat.h>43#include <time.h>44#include <unistd.h>4546using namespace __sanitizer;4748namespace {49struct DlsymAlloc : public DlSymAllocator<DlsymAlloc> {50static bool UseImpl() { return !__rtsan_is_initialized(); }51};52} // namespace5354// Filesystem5556INTERCEPTOR(int, open, const char *path, int oflag, ...) {57// We do not early exit if O_NONBLOCK is set.58// O_NONBLOCK **does not prevent the syscall** it simply sets the FD to be in59// nonblocking mode, which is a different concept than our60// [[clang::nonblocking]], and is not rt-safe. This behavior was confirmed61// using Instruments on Darwin with a simple test program62__rtsan_notify_intercepted_call("open");6364if (OpenReadsVaArgs(oflag)) {65va_list args;66va_start(args, oflag);67const mode_t mode = va_arg(args, int);68va_end(args);69return REAL(open)(path, oflag, mode);70}7172return REAL(open)(path, oflag);73}7475#if SANITIZER_INTERCEPT_OPEN6476INTERCEPTOR(int, open64, const char *path, int oflag, ...) {77// See comment above about O_NONBLOCK78__rtsan_notify_intercepted_call("open64");7980if (OpenReadsVaArgs(oflag)) {81va_list args;82va_start(args, oflag);83const mode_t mode = va_arg(args, int);84va_end(args);85return REAL(open64)(path, oflag, mode);86}8788return REAL(open64)(path, oflag);89}90#define RTSAN_MAYBE_INTERCEPT_OPEN64 INTERCEPT_FUNCTION(open64)91#else92#define RTSAN_MAYBE_INTERCEPT_OPEN6493#endif // SANITIZER_INTERCEPT_OPEN649495INTERCEPTOR(int, openat, int fd, const char *path, int oflag, ...) {96// See comment above about O_NONBLOCK97__rtsan_notify_intercepted_call("openat");9899if (OpenReadsVaArgs(oflag)) {100va_list args;101va_start(args, oflag);102const mode_t mode = va_arg(args, int);103va_end(args);104return REAL(openat)(fd, path, oflag, mode);105}106107return REAL(openat)(fd, path, oflag);108}109110#if SANITIZER_INTERCEPT_OPENAT64111INTERCEPTOR(int, openat64, int fd, const char *path, int oflag, ...) {112// See comment above about O_NONBLOCK113__rtsan_notify_intercepted_call("openat64");114115if (OpenReadsVaArgs(oflag)) {116va_list args;117va_start(args, oflag);118const mode_t mode = va_arg(args, int);119va_end(args);120return REAL(openat64)(fd, path, oflag, mode);121}122123return REAL(openat64)(fd, path, oflag);124}125#define RTSAN_MAYBE_INTERCEPT_OPENAT64 INTERCEPT_FUNCTION(openat64)126#else127#define RTSAN_MAYBE_INTERCEPT_OPENAT64128#endif // SANITIZER_INTERCEPT_OPENAT64129130INTERCEPTOR(int, creat, const char *path, mode_t mode) {131// See comment above about O_NONBLOCK132__rtsan_notify_intercepted_call("creat");133const int result = REAL(creat)(path, mode);134return result;135}136137#if SANITIZER_INTERCEPT_CREAT64138INTERCEPTOR(int, creat64, const char *path, mode_t mode) {139// See comment above about O_NONBLOCK140__rtsan_notify_intercepted_call("creat64");141const int result = REAL(creat64)(path, mode);142return result;143}144#define RTSAN_MAYBE_INTERCEPT_CREAT64 INTERCEPT_FUNCTION(creat64)145#else146#define RTSAN_MAYBE_INTERCEPT_CREAT64147#endif // SANITIZER_INTERCEPT_CREAT64148149INTERCEPTOR(int, fcntl, int filedes, int cmd, ...) {150__rtsan_notify_intercepted_call("fcntl");151152// Following precedent here. The linux source (fcntl.c, do_fcntl) accepts the153// final argument in a variable that will hold the largest of the possible154// argument types. It is then assumed that the implementation of fcntl will155// cast it properly depending on cmd.156//157// The two types we expect for possible args are `struct flock*` and `int`158// we will cast to `intptr_t` which should hold both comfortably.159// Why `intptr_t`? It should fit both types, and it follows the freeBSD160// approach linked below.161using arg_type = intptr_t;162static_assert(sizeof(arg_type) >= sizeof(struct flock *));163static_assert(sizeof(arg_type) >= sizeof(int));164165// Some cmds will not actually have an argument passed in this va_list.166// Calling va_arg when no arg exists is UB, however all currently167// supported architectures will give us a result in all three cases168// (no arg/int arg/struct flock* arg)169// va_arg() will generally read the next argument register or the170// stack. If we ever support an arch like CHERI with bounds checking, we171// may have to re-evaluate this approach.172//173// More discussion, and other examples following this approach174// https://discourse.llvm.org/t/how-to-write-an-interceptor-for-fcntl/81203175// https://reviews.freebsd.org/D46403176// https://github.com/bminor/glibc/blob/c444cc1d8335243c5c4e636d6a26c472df85522c/sysdeps/unix/sysv/linux/fcntl64.c#L37-L46177178va_list args;179va_start(args, cmd);180const arg_type arg = va_arg(args, arg_type);181va_end(args);182183return REAL(fcntl)(filedes, cmd, arg);184}185186#if SANITIZER_MUSL187INTERCEPTOR(int, ioctl, int filedes, int request, ...) {188#else189INTERCEPTOR(int, ioctl, int filedes, unsigned long request, ...) {190#endif191__rtsan_notify_intercepted_call("ioctl");192193// See fcntl for discussion on why we use intptr_t194// And why we read from va_args on all request types195using arg_type = intptr_t;196static_assert(sizeof(arg_type) >= sizeof(struct ifreq *));197static_assert(sizeof(arg_type) >= sizeof(int));198199va_list args;200va_start(args, request);201arg_type arg = va_arg(args, arg_type);202va_end(args);203204return REAL(ioctl)(filedes, request, arg);205}206207#if SANITIZER_INTERCEPT_FCNTL64208INTERCEPTOR(int, fcntl64, int filedes, int cmd, ...) {209__rtsan_notify_intercepted_call("fcntl64");210211va_list args;212va_start(args, cmd);213214// Following precedent here. The linux source (fcntl.c, do_fcntl) accepts the215// final argument in a variable that will hold the largest of the possible216// argument types (pointers and ints are typical in fcntl) It is then assumed217// that the implementation of fcntl will cast it properly depending on cmd.218//219// This is also similar to what is done in220// sanitizer_common/sanitizer_common_syscalls.inc221const unsigned long arg = va_arg(args, unsigned long);222int result = REAL(fcntl64)(filedes, cmd, arg);223224va_end(args);225226return result;227}228#define RTSAN_MAYBE_INTERCEPT_FCNTL64 INTERCEPT_FUNCTION(fcntl64)229#else230#define RTSAN_MAYBE_INTERCEPT_FCNTL64231#endif // SANITIZER_INTERCEPT_FCNTL64232233INTERCEPTOR(int, close, int filedes) {234__rtsan_notify_intercepted_call("close");235return REAL(close)(filedes);236}237238INTERCEPTOR(int, chdir, const char *path) {239__rtsan_notify_intercepted_call("chdir");240return REAL(chdir)(path);241}242243INTERCEPTOR(int, fchdir, int fd) {244__rtsan_notify_intercepted_call("fchdir");245return REAL(fchdir)(fd);246}247248#if SANITIZER_INTERCEPT_READLINK249INTERCEPTOR(ssize_t, readlink, const char *pathname, char *buf, size_t size) {250__rtsan_notify_intercepted_call("readlink");251return REAL(readlink)(pathname, buf, size);252}253#define RTSAN_MAYBE_INTERCEPT_READLINK INTERCEPT_FUNCTION(readlink)254#else255#define RTSAN_MAYBE_INTERCEPT_READLINK256#endif257258#if SANITIZER_INTERCEPT_READLINKAT259INTERCEPTOR(ssize_t, readlinkat, int dirfd, const char *pathname, char *buf,260size_t size) {261__rtsan_notify_intercepted_call("readlinkat");262return REAL(readlinkat)(dirfd, pathname, buf, size);263}264#define RTSAN_MAYBE_INTERCEPT_READLINKAT INTERCEPT_FUNCTION(readlinkat)265#else266#define RTSAN_MAYBE_INTERCEPT_READLINKAT267#endif268269INTERCEPTOR(int, unlink, const char *pathname) {270__rtsan_notify_intercepted_call("unlink");271return REAL(unlink)(pathname);272}273274INTERCEPTOR(int, unlinkat, int fd, const char *pathname, int flag) {275__rtsan_notify_intercepted_call("unlinkat");276return REAL(unlinkat)(fd, pathname, flag);277}278279INTERCEPTOR(int, truncate, const char *pathname, off_t length) {280__rtsan_notify_intercepted_call("truncate");281return REAL(truncate)(pathname, length);282}283284INTERCEPTOR(int, ftruncate, int fd, off_t length) {285__rtsan_notify_intercepted_call("ftruncate");286return REAL(ftruncate)(fd, length);287}288289#if SANITIZER_LINUX && !SANITIZER_MUSL290INTERCEPTOR(int, truncate64, const char *pathname, off64_t length) {291__rtsan_notify_intercepted_call("truncate64");292return REAL(truncate64)(pathname, length);293}294295INTERCEPTOR(int, ftruncate64, int fd, off64_t length) {296__rtsan_notify_intercepted_call("ftruncate64");297return REAL(ftruncate64)(fd, length);298}299#define RTSAN_MAYBE_INTERCEPT_TRUNCATE64 INTERCEPT_FUNCTION(truncate64)300#define RTSAN_MAYBE_INTERCEPT_FTRUNCATE64 INTERCEPT_FUNCTION(ftruncate64)301#else302#define RTSAN_MAYBE_INTERCEPT_TRUNCATE64303#define RTSAN_MAYBE_INTERCEPT_FTRUNCATE64304#endif305306INTERCEPTOR(int, symlink, const char *target, const char *linkpath) {307__rtsan_notify_intercepted_call("symlink");308return REAL(symlink)(target, linkpath);309}310311INTERCEPTOR(int, symlinkat, const char *target, int newdirfd,312const char *linkpath) {313__rtsan_notify_intercepted_call("symlinkat");314return REAL(symlinkat)(target, newdirfd, linkpath);315}316317// Streams318319INTERCEPTOR(FILE *, fopen, const char *path, const char *mode) {320__rtsan_notify_intercepted_call("fopen");321return REAL(fopen)(path, mode);322}323324INTERCEPTOR(FILE *, freopen, const char *path, const char *mode, FILE *stream) {325__rtsan_notify_intercepted_call("freopen");326return REAL(freopen)(path, mode, stream);327}328329#if SANITIZER_INTERCEPT_FOPEN64330INTERCEPTOR(FILE *, fopen64, const char *path, const char *mode) {331__rtsan_notify_intercepted_call("fopen64");332return REAL(fopen64)(path, mode);333}334335INTERCEPTOR(FILE *, freopen64, const char *path, const char *mode,336FILE *stream) {337__rtsan_notify_intercepted_call("freopen64");338return REAL(freopen64)(path, mode, stream);339}340#define RTSAN_MAYBE_INTERCEPT_FOPEN64 INTERCEPT_FUNCTION(fopen64);341#define RTSAN_MAYBE_INTERCEPT_FREOPEN64 INTERCEPT_FUNCTION(freopen64);342#else343#define RTSAN_MAYBE_INTERCEPT_FOPEN64344#define RTSAN_MAYBE_INTERCEPT_FREOPEN64345#endif // SANITIZER_INTERCEPT_FOPEN64346347INTERCEPTOR(size_t, fread, void *ptr, size_t size, size_t nitems,348FILE *stream) {349__rtsan_notify_intercepted_call("fread");350return REAL(fread)(ptr, size, nitems, stream);351}352353INTERCEPTOR(size_t, fwrite, const void *ptr, size_t size, size_t nitems,354FILE *stream) {355__rtsan_notify_intercepted_call("fwrite");356return REAL(fwrite)(ptr, size, nitems, stream);357}358359INTERCEPTOR(int, fclose, FILE *stream) {360__rtsan_notify_intercepted_call("fclose");361return REAL(fclose)(stream);362}363364INTERCEPTOR(int, fputs, const char *s, FILE *stream) {365__rtsan_notify_intercepted_call("fputs");366return REAL(fputs)(s, stream);367}368369INTERCEPTOR(int, fflush, FILE *stream) {370__rtsan_notify_intercepted_call("fflush");371return REAL(fflush)(stream);372}373374#if SANITIZER_APPLE375INTERCEPTOR(int, fpurge, FILE *stream) {376__rtsan_notify_intercepted_call("fpurge");377return REAL(fpurge)(stream);378}379#define RTSAN_MAYBE_INTERCEPT_FPURGE INTERCEPT_FUNCTION(fpurge)380#else381#define RTSAN_MAYBE_INTERCEPT_FPURGE382#endif383384INTERCEPTOR(FILE *, fdopen, int fd, const char *mode) {385__rtsan_notify_intercepted_call("fdopen");386return REAL(fdopen)(fd, mode);387}388389#if SANITIZER_INTERCEPT_FOPENCOOKIE390INTERCEPTOR(FILE *, fopencookie, void *cookie, const char *mode,391cookie_io_functions_t funcs) {392__rtsan_notify_intercepted_call("fopencookie");393return REAL(fopencookie)(cookie, mode, funcs);394}395#define RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE INTERCEPT_FUNCTION(fopencookie)396#else397#define RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE398#endif399400#if SANITIZER_INTERCEPT_OPEN_MEMSTREAM401INTERCEPTOR(FILE *, open_memstream, char **buf, size_t *size) {402__rtsan_notify_intercepted_call("open_memstream");403return REAL(open_memstream)(buf, size);404}405406INTERCEPTOR(FILE *, fmemopen, void *buf, size_t size, const char *mode) {407__rtsan_notify_intercepted_call("fmemopen");408return REAL(fmemopen)(buf, size, mode);409}410#define RTSAN_MAYBE_INTERCEPT_OPEN_MEMSTREAM INTERCEPT_FUNCTION(open_memstream)411#define RTSAN_MAYBE_INTERCEPT_FMEMOPEN INTERCEPT_FUNCTION(fmemopen)412#else413#define RTSAN_MAYBE_INTERCEPT_OPEN_MEMSTREAM414#define RTSAN_MAYBE_INTERCEPT_FMEMOPEN415#endif416417#if SANITIZER_INTERCEPT_SETVBUF418INTERCEPTOR(void, setbuf, FILE *stream, char *buf) {419__rtsan_notify_intercepted_call("setbuf");420return REAL(setbuf)(stream, buf);421}422423INTERCEPTOR(int, setvbuf, FILE *stream, char *buf, int mode, size_t size) {424__rtsan_notify_intercepted_call("setvbuf");425return REAL(setvbuf)(stream, buf, mode, size);426}427428#if SANITIZER_LINUX429INTERCEPTOR(void, setlinebuf, FILE *stream) {430#else431INTERCEPTOR(int, setlinebuf, FILE *stream) {432#endif433__rtsan_notify_intercepted_call("setlinebuf");434return REAL(setlinebuf)(stream);435}436437#if SANITIZER_LINUX438INTERCEPTOR(void, setbuffer, FILE *stream, char *buf, size_t size) {439#else440INTERCEPTOR(void, setbuffer, FILE *stream, char *buf, int size) {441#endif442__rtsan_notify_intercepted_call("setbuffer");443return REAL(setbuffer)(stream, buf, size);444}445#define RTSAN_MAYBE_INTERCEPT_SETBUF INTERCEPT_FUNCTION(setbuf)446#define RTSAN_MAYBE_INTERCEPT_SETVBUF INTERCEPT_FUNCTION(setvbuf)447#define RTSAN_MAYBE_INTERCEPT_SETLINEBUF INTERCEPT_FUNCTION(setlinebuf)448#define RTSAN_MAYBE_INTERCEPT_SETBUFFER INTERCEPT_FUNCTION(setbuffer)449#else450#define RTSAN_MAYBE_INTERCEPT_SETBUF451#define RTSAN_MAYBE_INTERCEPT_SETVBUF452#define RTSAN_MAYBE_INTERCEPT_SETLINEBUF453#define RTSAN_MAYBE_INTERCEPT_SETBUFFER454#endif455456#if SANITIZER_INTERCEPT_FSEEK457INTERCEPTOR(int, fgetpos, FILE *stream, fpos_t *pos) {458__rtsan_notify_intercepted_call("fgetpos");459return REAL(fgetpos)(stream, pos);460}461462INTERCEPTOR(int, fseek, FILE *stream, long offset, int whence) {463__rtsan_notify_intercepted_call("fseek");464return REAL(fseek)(stream, offset, whence);465}466467INTERCEPTOR(int, fseeko, FILE *stream, off_t offset, int whence) {468__rtsan_notify_intercepted_call("fseeko");469return REAL(fseeko)(stream, offset, whence);470}471472INTERCEPTOR(int, fsetpos, FILE *stream, const fpos_t *pos) {473__rtsan_notify_intercepted_call("fsetpos");474return REAL(fsetpos)(stream, pos);475}476477INTERCEPTOR(long, ftell, FILE *stream) {478__rtsan_notify_intercepted_call("ftell");479return REAL(ftell)(stream);480}481482INTERCEPTOR(off_t, ftello, FILE *stream) {483__rtsan_notify_intercepted_call("ftello");484return REAL(ftello)(stream);485}486487#if SANITIZER_LINUX && !SANITIZER_MUSL488INTERCEPTOR(int, fgetpos64, FILE *stream, fpos64_t *pos) {489__rtsan_notify_intercepted_call("fgetpos64");490return REAL(fgetpos64)(stream, pos);491}492493INTERCEPTOR(int, fseeko64, FILE *stream, off64_t offset, int whence) {494__rtsan_notify_intercepted_call("fseeko64");495return REAL(fseeko64)(stream, offset, whence);496}497498INTERCEPTOR(int, fsetpos64, FILE *stream, const fpos64_t *pos) {499__rtsan_notify_intercepted_call("fsetpos64");500return REAL(fsetpos64)(stream, pos);501}502503INTERCEPTOR(off64_t, ftello64, FILE *stream) {504__rtsan_notify_intercepted_call("ftello64");505return REAL(ftello64)(stream);506}507#endif508509INTERCEPTOR(void, rewind, FILE *stream) {510__rtsan_notify_intercepted_call("rewind");511return REAL(rewind)(stream);512}513#define RTSAN_MAYBE_INTERCEPT_FGETPOS INTERCEPT_FUNCTION(fgetpos)514#define RTSAN_MAYBE_INTERCEPT_FSEEK INTERCEPT_FUNCTION(fseek)515#define RTSAN_MAYBE_INTERCEPT_FSEEKO INTERCEPT_FUNCTION(fseeko)516#define RTSAN_MAYBE_INTERCEPT_FSETPOS INTERCEPT_FUNCTION(fsetpos)517#define RTSAN_MAYBE_INTERCEPT_FTELL INTERCEPT_FUNCTION(ftell)518#define RTSAN_MAYBE_INTERCEPT_FTELLO INTERCEPT_FUNCTION(ftello)519#define RTSAN_MAYBE_INTERCEPT_REWIND INTERCEPT_FUNCTION(rewind)520#if SANITIZER_LINUX && !SANITIZER_MUSL521#define RTSAN_MAYBE_INTERCEPT_FGETPOS64 INTERCEPT_FUNCTION(fgetpos64)522#define RTSAN_MAYBE_INTERCEPT_FSEEKO64 INTERCEPT_FUNCTION(fseeko64)523#define RTSAN_MAYBE_INTERCEPT_FSETPOS64 INTERCEPT_FUNCTION(fsetpos64)524#define RTSAN_MAYBE_INTERCEPT_FTELLO64 INTERCEPT_FUNCTION(ftello64)525#else526#define RTSAN_MAYBE_INTERCEPT_FGETPOS64527#define RTSAN_MAYBE_INTERCEPT_FSEEKO64528#define RTSAN_MAYBE_INTERCEPT_FSETPOS64529#define RTSAN_MAYBE_INTERCEPT_FTELLO64530#endif531#else532#define RTSAN_MAYBE_INTERCEPT_FGETPOS533#define RTSAN_MAYBE_INTERCEPT_FSEEK534#define RTSAN_MAYBE_INTERCEPT_FSEEKO535#define RTSAN_MAYBE_INTERCEPT_FSETPOS536#define RTSAN_MAYBE_INTERCEPT_FTELL537#define RTSAN_MAYBE_INTERCEPT_FTELLO538#define RTSAN_MAYBE_INTERCEPT_REWIND539#define RTSAN_MAYBE_INTERCEPT_FGETPOS64540#define RTSAN_MAYBE_INTERCEPT_FSEEKO64541#define RTSAN_MAYBE_INTERCEPT_FSETPOS64542#define RTSAN_MAYBE_INTERCEPT_FTELLO64543#endif544545INTERCEPTOR(int, puts, const char *s) {546__rtsan_notify_intercepted_call("puts");547return REAL(puts)(s);548}549550INTERCEPTOR(ssize_t, read, int fd, void *buf, size_t count) {551__rtsan_notify_intercepted_call("read");552return REAL(read)(fd, buf, count);553}554555INTERCEPTOR(ssize_t, write, int fd, const void *buf, size_t count) {556__rtsan_notify_intercepted_call("write");557return REAL(write)(fd, buf, count);558}559560INTERCEPTOR(ssize_t, pread, int fd, void *buf, size_t count, off_t offset) {561__rtsan_notify_intercepted_call("pread");562return REAL(pread)(fd, buf, count, offset);563}564565#if SANITIZER_INTERCEPT_PREAD64566INTERCEPTOR(ssize_t, pread64, int fd, void *buf, size_t count, off_t offset) {567__rtsan_notify_intercepted_call("pread64");568return REAL(pread64)(fd, buf, count, offset);569}570#define RTSAN_MAYBE_INTERCEPT_PREAD64 INTERCEPT_FUNCTION(pread64)571#else572#define RTSAN_MAYBE_INTERCEPT_PREAD64573#endif // SANITIZER_INTERCEPT_PREAD64574575INTERCEPTOR(ssize_t, readv, int fd, const struct iovec *iov, int iovcnt) {576__rtsan_notify_intercepted_call("readv");577return REAL(readv)(fd, iov, iovcnt);578}579580INTERCEPTOR(ssize_t, pwrite, int fd, const void *buf, size_t count,581off_t offset) {582__rtsan_notify_intercepted_call("pwrite");583return REAL(pwrite)(fd, buf, count, offset);584}585586#if SANITIZER_INTERCEPT_PWRITE64587INTERCEPTOR(ssize_t, pwrite64, int fd, const void *buf, size_t count,588off_t offset) {589__rtsan_notify_intercepted_call("pwrite64");590return REAL(pwrite64)(fd, buf, count, offset);591}592#define RTSAN_MAYBE_INTERCEPT_PWRITE64 INTERCEPT_FUNCTION(pwrite64)593#else594#define RTSAN_MAYBE_INTERCEPT_PWRITE64595#endif // SANITIZER_INTERCEPT_PWRITE64596597#if SANITIZER_INTERCEPT_PREADV598INTERCEPTOR(ssize_t, preadv, int fd, const struct iovec *iov, int count,599off_t offset) {600__rtsan_notify_intercepted_call("preadv");601return REAL(preadv)(fd, iov, count, offset);602}603#define RTSAN_MAYBE_INTERCEPT_PREADV INTERCEPT_FUNCTION(preadv)604#else605#define RTSAN_MAYBE_INTERCEPT_PREADV606#endif607608#if SANITIZER_INTERCEPT_PREADV64609INTERCEPTOR(ssize_t, preadv64, int fd, const struct iovec *iov, int count,610off_t offset) {611__rtsan_notify_intercepted_call("preadv64");612return REAL(preadv)(fd, iov, count, offset);613}614#define RTSAN_MAYBE_INTERCEPT_PREADV64 INTERCEPT_FUNCTION(preadv64)615#else616#define RTSAN_MAYBE_INTERCEPT_PREADV64617#endif618619#if SANITIZER_INTERCEPT_PWRITEV620INTERCEPTOR(ssize_t, pwritev, int fd, const struct iovec *iov, int count,621off_t offset) {622__rtsan_notify_intercepted_call("pwritev");623return REAL(pwritev)(fd, iov, count, offset);624}625#define RTSAN_MAYBE_INTERCEPT_PWRITEV INTERCEPT_FUNCTION(pwritev)626#else627#define RTSAN_MAYBE_INTERCEPT_PWRITEV628#endif629630#if SANITIZER_INTERCEPT_PWRITEV64631INTERCEPTOR(ssize_t, pwritev64, int fd, const struct iovec *iov, int count,632off_t offset) {633__rtsan_notify_intercepted_call("pwritev64");634return REAL(pwritev64)(fd, iov, count, offset);635}636#define RTSAN_MAYBE_INTERCEPT_PWRITEV64 INTERCEPT_FUNCTION(pwritev64)637#else638#define RTSAN_MAYBE_INTERCEPT_PWRITEV64639#endif640641INTERCEPTOR(ssize_t, writev, int fd, const struct iovec *iov, int iovcnt) {642__rtsan_notify_intercepted_call("writev");643return REAL(writev)(fd, iov, iovcnt);644}645646INTERCEPTOR(off_t, lseek, int fd, off_t offset, int whence) {647__rtsan_notify_intercepted_call("lseek");648return REAL(lseek)(fd, offset, whence);649}650651#if SANITIZER_INTERCEPT_LSEEK64652INTERCEPTOR(off64_t, lseek64, int fd, off64_t offset, int whence) {653__rtsan_notify_intercepted_call("lseek64");654return REAL(lseek64)(fd, offset, whence);655}656#define RTSAN_MAYBE_INTERCEPT_LSEEK64 INTERCEPT_FUNCTION(lseek64)657#else658#define RTSAN_MAYBE_INTERCEPT_LSEEK64659#endif // SANITIZER_INTERCEPT_LSEEK64660661INTERCEPTOR(int, dup, int oldfd) {662__rtsan_notify_intercepted_call("dup");663return REAL(dup)(oldfd);664}665666INTERCEPTOR(int, dup2, int oldfd, int newfd) {667__rtsan_notify_intercepted_call("dup2");668return REAL(dup2)(oldfd, newfd);669}670671INTERCEPTOR(int, chmod, const char *path, mode_t mode) {672__rtsan_notify_intercepted_call("chmod");673return REAL(chmod)(path, mode);674}675676INTERCEPTOR(int, fchmod, int fd, mode_t mode) {677__rtsan_notify_intercepted_call("fchmod");678return REAL(fchmod)(fd, mode);679}680681INTERCEPTOR(int, mkdir, const char *path, mode_t mode) {682__rtsan_notify_intercepted_call("mkdir");683return REAL(mkdir)(path, mode);684}685686INTERCEPTOR(int, rmdir, const char *path) {687__rtsan_notify_intercepted_call("rmdir");688return REAL(rmdir)(path);689}690691INTERCEPTOR(mode_t, umask, mode_t cmask) {692__rtsan_notify_intercepted_call("umask");693return REAL(umask)(cmask);694}695696// Concurrency697#if SANITIZER_APPLE698#pragma clang diagnostic push699// OSSpinLockLock is deprecated, but still in use in libc++700#pragma clang diagnostic ignored "-Wdeprecated-declarations"701#undef OSSpinLockLock702703INTERCEPTOR(void, OSSpinLockLock, volatile OSSpinLock *lock) {704__rtsan_notify_intercepted_call("OSSpinLockLock");705return REAL(OSSpinLockLock)(lock);706}707708#define RTSAN_MAYBE_INTERCEPT_OSSPINLOCKLOCK INTERCEPT_FUNCTION(OSSpinLockLock)709#else710#define RTSAN_MAYBE_INTERCEPT_OSSPINLOCKLOCK711#endif // SANITIZER_APPLE712713#if SANITIZER_APPLE714// _os_nospin_lock_lock may replace OSSpinLockLock due to deprecation macro.715typedef volatile OSSpinLock *_os_nospin_lock_t;716717INTERCEPTOR(void, _os_nospin_lock_lock, _os_nospin_lock_t lock) {718__rtsan_notify_intercepted_call("_os_nospin_lock_lock");719return REAL(_os_nospin_lock_lock)(lock);720}721#pragma clang diagnostic pop // "-Wdeprecated-declarations"722#endif // SANITIZER_APPLE723724#if SANITIZER_APPLE725INTERCEPTOR(void, os_unfair_lock_lock, os_unfair_lock_t lock) {726__rtsan_notify_intercepted_call("os_unfair_lock_lock");727return REAL(os_unfair_lock_lock)(lock);728}729730#define RTSAN_MAYBE_INTERCEPT_OS_UNFAIR_LOCK_LOCK \731INTERCEPT_FUNCTION(os_unfair_lock_lock)732#else733#define RTSAN_MAYBE_INTERCEPT_OS_UNFAIR_LOCK_LOCK734#endif // SANITIZER_APPLE735736#if SANITIZER_LINUX737INTERCEPTOR(int, pthread_spin_lock, pthread_spinlock_t *spinlock) {738__rtsan_notify_intercepted_call("pthread_spin_lock");739return REAL(pthread_spin_lock)(spinlock);740}741#define RTSAN_MAYBE_INTERCEPT_PTHREAD_SPIN_LOCK \742INTERCEPT_FUNCTION(pthread_spin_lock)743#else744#define RTSAN_MAYBE_INTERCEPT_PTHREAD_SPIN_LOCK745#endif // SANITIZER_LINUX746747INTERCEPTOR(int, pthread_create, pthread_t *thread, const pthread_attr_t *attr,748void *(*start_routine)(void *), void *arg) {749__rtsan_notify_intercepted_call("pthread_create");750return REAL(pthread_create)(thread, attr, start_routine, arg);751}752753INTERCEPTOR(int, pthread_mutex_lock, pthread_mutex_t *mutex) {754__rtsan_notify_intercepted_call("pthread_mutex_lock");755return REAL(pthread_mutex_lock)(mutex);756}757758INTERCEPTOR(int, pthread_mutex_unlock, pthread_mutex_t *mutex) {759__rtsan_notify_intercepted_call("pthread_mutex_unlock");760return REAL(pthread_mutex_unlock)(mutex);761}762763INTERCEPTOR(int, pthread_join, pthread_t thread, void **value_ptr) {764__rtsan_notify_intercepted_call("pthread_join");765return REAL(pthread_join)(thread, value_ptr);766}767768INTERCEPTOR(int, pthread_cond_signal, pthread_cond_t *cond) {769__rtsan_notify_intercepted_call("pthread_cond_signal");770return REAL(pthread_cond_signal)(cond);771}772773INTERCEPTOR(int, pthread_cond_broadcast, pthread_cond_t *cond) {774__rtsan_notify_intercepted_call("pthread_cond_broadcast");775return REAL(pthread_cond_broadcast)(cond);776}777778INTERCEPTOR(int, pthread_cond_wait, pthread_cond_t *cond,779pthread_mutex_t *mutex) {780__rtsan_notify_intercepted_call("pthread_cond_wait");781return REAL(pthread_cond_wait)(cond, mutex);782}783784INTERCEPTOR(int, pthread_cond_timedwait, pthread_cond_t *cond,785pthread_mutex_t *mutex, const timespec *ts) {786__rtsan_notify_intercepted_call("pthread_cond_timedwait");787return REAL(pthread_cond_timedwait)(cond, mutex, ts);788}789790INTERCEPTOR(int, pthread_rwlock_rdlock, pthread_rwlock_t *lock) {791__rtsan_notify_intercepted_call("pthread_rwlock_rdlock");792return REAL(pthread_rwlock_rdlock)(lock);793}794795INTERCEPTOR(int, pthread_rwlock_unlock, pthread_rwlock_t *lock) {796__rtsan_notify_intercepted_call("pthread_rwlock_unlock");797return REAL(pthread_rwlock_unlock)(lock);798}799800INTERCEPTOR(int, pthread_rwlock_wrlock, pthread_rwlock_t *lock) {801__rtsan_notify_intercepted_call("pthread_rwlock_wrlock");802return REAL(pthread_rwlock_wrlock)(lock);803}804805// Sleeping806807INTERCEPTOR(unsigned int, sleep, unsigned int s) {808__rtsan_notify_intercepted_call("sleep");809return REAL(sleep)(s);810}811812INTERCEPTOR(int, usleep, useconds_t u) {813__rtsan_notify_intercepted_call("usleep");814return REAL(usleep)(u);815}816817INTERCEPTOR(int, nanosleep, const struct timespec *rqtp,818struct timespec *rmtp) {819__rtsan_notify_intercepted_call("nanosleep");820return REAL(nanosleep)(rqtp, rmtp);821}822823INTERCEPTOR(int, sched_yield, void) {824__rtsan_notify_intercepted_call("sched_yield");825return REAL(sched_yield)();826}827828#if SANITIZER_LINUX829INTERCEPTOR(int, sched_getaffinity, pid_t pid, size_t len, cpu_set_t *set) {830__rtsan_notify_intercepted_call("sched_getaffinity");831return REAL(sched_getaffinity)(pid, len, set);832}833834INTERCEPTOR(int, sched_setaffinity, pid_t pid, size_t len,835const cpu_set_t *set) {836__rtsan_notify_intercepted_call("sched_setaffinity");837return REAL(sched_setaffinity)(pid, len, set);838}839#define RTSAN_MAYBE_INTERCEPT_SCHED_GETAFFINITY \840INTERCEPT_FUNCTION(sched_getaffinity)841#define RTSAN_MAYBE_INTERCEPT_SCHED_SETAFFINITY \842INTERCEPT_FUNCTION(sched_setaffinity)843#else844#define RTSAN_MAYBE_INTERCEPT_SCHED_GETAFFINITY845#define RTSAN_MAYBE_INTERCEPT_SCHED_SETAFFINITY846#endif847848// Memory849850INTERCEPTOR(void *, calloc, SIZE_T num, SIZE_T size) {851if (DlsymAlloc::Use())852return DlsymAlloc::Callocate(num, size);853854__rtsan_notify_intercepted_call("calloc");855return REAL(calloc)(num, size);856}857858INTERCEPTOR(void, free, void *ptr) {859if (DlsymAlloc::PointerIsMine(ptr))860return DlsymAlloc::Free(ptr);861862// According to the C and C++ standard, freeing a nullptr is guaranteed to be863// a no-op (and thus real-time safe). This can be confirmed for looking at864// __libc_free in the glibc source.865if (ptr != nullptr)866__rtsan_notify_intercepted_call("free");867868return REAL(free)(ptr);869}870871#if SANITIZER_INTERCEPT_FREE_SIZED872INTERCEPTOR(void, free_sized, void *ptr, SIZE_T size) {873if (DlsymAlloc::PointerIsMine(ptr))874return DlsymAlloc::Free(ptr);875876// According to the C and C++ standard, freeing a nullptr is guaranteed to be877// a no-op (and thus real-time safe). This can be confirmed for looking at878// __libc_free in the glibc source.879if (ptr != nullptr)880__rtsan_notify_intercepted_call("free_sized");881882if (REAL(free_sized))883return REAL(free_sized)(ptr, size);884return REAL(free)(ptr);885}886#define RTSAN_MAYBE_INTERCEPT_FREE_SIZED INTERCEPT_FUNCTION(free_sized)887#else888#define RTSAN_MAYBE_INTERCEPT_FREE_SIZED889#endif890891#if SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED892INTERCEPTOR(void, free_aligned_sized, void *ptr, SIZE_T alignment,893SIZE_T size) {894if (DlsymAlloc::PointerIsMine(ptr))895return DlsymAlloc::Free(ptr);896897// According to the C and C++ standard, freeing a nullptr is guaranteed to be898// a no-op (and thus real-time safe). This can be confirmed for looking at899// __libc_free in the glibc source.900if (ptr != nullptr)901__rtsan_notify_intercepted_call("free_aligned_sized");902903if (REAL(free_aligned_sized))904return REAL(free_aligned_sized)(ptr, alignment, size);905return REAL(free)(ptr);906}907#define RTSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED \908INTERCEPT_FUNCTION(free_aligned_sized)909#else910#define RTSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED911#endif912913INTERCEPTOR(void *, malloc, SIZE_T size) {914if (DlsymAlloc::Use())915return DlsymAlloc::Allocate(size);916917__rtsan_notify_intercepted_call("malloc");918return REAL(malloc)(size);919}920921INTERCEPTOR(void *, realloc, void *ptr, SIZE_T size) {922if (DlsymAlloc::Use() || DlsymAlloc::PointerIsMine(ptr))923return DlsymAlloc::Realloc(ptr, size);924925__rtsan_notify_intercepted_call("realloc");926return REAL(realloc)(ptr, size);927}928929INTERCEPTOR(void *, reallocf, void *ptr, SIZE_T size) {930__rtsan_notify_intercepted_call("reallocf");931return REAL(reallocf)(ptr, size);932}933934INTERCEPTOR(void *, valloc, SIZE_T size) {935__rtsan_notify_intercepted_call("valloc");936return REAL(valloc)(size);937}938939#if SANITIZER_INTERCEPT_ALIGNED_ALLOC940941// In some cases, when targeting older Darwin versions, this warning may pop up.942// Because we are providing a wrapper, the client is responsible to check943// whether aligned_alloc is available, not us. We still succeed linking on an944// old OS, because we are using a weak symbol (see aligned_alloc in945// sanitizer_platform_interceptors.h)946#pragma clang diagnostic push947#pragma clang diagnostic ignored "-Wunguarded-availability-new"948INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {949__rtsan_notify_intercepted_call("aligned_alloc");950return REAL(aligned_alloc)(alignment, size);951}952#pragma clang diagnostic pop953#define RTSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC INTERCEPT_FUNCTION(aligned_alloc)954#else955#define RTSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC956#endif957958INTERCEPTOR(int, posix_memalign, void **memptr, size_t alignment, size_t size) {959__rtsan_notify_intercepted_call("posix_memalign");960return REAL(posix_memalign)(memptr, alignment, size);961}962963#if SANITIZER_INTERCEPT_MEMALIGN964INTERCEPTOR(void *, memalign, size_t alignment, size_t size) {965__rtsan_notify_intercepted_call("memalign");966return REAL(memalign)(alignment, size);967}968#define RTSAN_MAYBE_INTERCEPT_MEMALIGN INTERCEPT_FUNCTION(memalign)969#else970#define RTSAN_MAYBE_INTERCEPT_MEMALIGN971#endif972973#if SANITIZER_INTERCEPT_PVALLOC974INTERCEPTOR(void *, pvalloc, size_t size) {975__rtsan_notify_intercepted_call("pvalloc");976return REAL(pvalloc)(size);977}978#define RTSAN_MAYBE_INTERCEPT_PVALLOC INTERCEPT_FUNCTION(pvalloc)979#else980#define RTSAN_MAYBE_INTERCEPT_PVALLOC981#endif982983INTERCEPTOR(void *, mmap, void *addr, size_t length, int prot, int flags,984int fd, off_t offset) {985__rtsan_notify_intercepted_call("mmap");986return REAL(mmap)(addr, length, prot, flags, fd, offset);987}988989#if SANITIZER_INTERCEPT_MMAP64990INTERCEPTOR(void *, mmap64, void *addr, size_t length, int prot, int flags,991int fd, off64_t offset) {992__rtsan_notify_intercepted_call("mmap64");993return REAL(mmap64)(addr, length, prot, flags, fd, offset);994}995#define RTSAN_MAYBE_INTERCEPT_MMAP64 INTERCEPT_FUNCTION(mmap64)996#else997#define RTSAN_MAYBE_INTERCEPT_MMAP64998#endif // SANITIZER_INTERCEPT_MMAP649991000#if SANITIZER_LINUX1001// Note that even if rtsan is ported to netbsd, it has a slighty different1002// and non-variadic signature1003INTERCEPTOR(void *, mremap, void *oaddr, size_t olength, size_t nlength,1004int flags, ...) {1005__rtsan_notify_intercepted_call("mremap");10061007// the last optional argument is only used in this case1008// as the new page region will be assigned to. Is ignored otherwise.1009if (flags & MREMAP_FIXED) {1010va_list args;10111012va_start(args, flags);1013void *naddr = va_arg(args, void *);1014va_end(args);10151016return REAL(mremap)(oaddr, olength, nlength, flags, naddr);1017}10181019return REAL(mremap)(oaddr, olength, nlength, flags);1020}1021#define RTSAN_MAYBE_INTERCEPT_MREMAP INTERCEPT_FUNCTION(mremap)1022#else1023#define RTSAN_MAYBE_INTERCEPT_MREMAP1024#endif10251026INTERCEPTOR(int, munmap, void *addr, size_t length) {1027__rtsan_notify_intercepted_call("munmap");1028return REAL(munmap)(addr, length);1029}10301031#if !SANITIZER_APPLE1032INTERCEPTOR(int, madvise, void *addr, size_t length, int flag) {1033__rtsan_notify_intercepted_call("madvise");1034return REAL(madvise)(addr, length, flag);1035}10361037INTERCEPTOR(int, posix_madvise, void *addr, size_t length, int flag) {1038__rtsan_notify_intercepted_call("posix_madvise");1039return REAL(posix_madvise)(addr, length, flag);1040}1041#define RTSAN_MAYBE_INTERCEPT_MADVISE INTERCEPT_FUNCTION(madvise)1042#define RTSAN_MAYBE_INTERCEPT_POSIX_MADVISE INTERCEPT_FUNCTION(posix_madvise)1043#else1044#define RTSAN_MAYBE_INTERCEPT_MADVISE1045#define RTSAN_MAYBE_INTERCEPT_POSIX_MADVISE1046#endif10471048INTERCEPTOR(int, mprotect, void *addr, size_t length, int prot) {1049__rtsan_notify_intercepted_call("mprotect");1050return REAL(mprotect)(addr, length, prot);1051}10521053INTERCEPTOR(int, msync, void *addr, size_t length, int flag) {1054__rtsan_notify_intercepted_call("msync");1055return REAL(msync)(addr, length, flag);1056}10571058#if SANITIZER_APPLE1059INTERCEPTOR(int, mincore, const void *addr, size_t length, char *vec) {1060#else1061INTERCEPTOR(int, mincore, void *addr, size_t length, unsigned char *vec) {1062#endif1063__rtsan_notify_intercepted_call("mincore");1064return REAL(mincore)(addr, length, vec);1065}10661067INTERCEPTOR(int, shm_open, const char *name, int oflag, mode_t mode) {1068__rtsan_notify_intercepted_call("shm_open");1069return REAL(shm_open)(name, oflag, mode);1070}10711072INTERCEPTOR(int, shm_unlink, const char *name) {1073__rtsan_notify_intercepted_call("shm_unlink");1074return REAL(shm_unlink)(name);1075}10761077#if !SANITIZER_APPLE1078// is supported by freebsd too1079INTERCEPTOR(int, memfd_create, const char *path, unsigned int flags) {1080__rtsan_notify_intercepted_call("memfd_create");1081return REAL(memfd_create)(path, flags);1082}1083#define RTSAN_MAYBE_INTERCEPT_MEMFD_CREATE INTERCEPT_FUNCTION(memfd_create)1084#else1085#define RTSAN_MAYBE_INTERCEPT_MEMFD_CREATE1086#endif10871088// Sockets1089INTERCEPTOR(int, getaddrinfo, const char *node, const char *service,1090const struct addrinfo *hints, struct addrinfo **res) {1091__rtsan_notify_intercepted_call("getaddrinfo");1092return REAL(getaddrinfo)(node, service, hints, res);1093}10941095INTERCEPTOR(int, getnameinfo, const struct sockaddr *sa, socklen_t salen,1096char *host, socklen_t hostlen, char *serv, socklen_t servlen,1097int flags) {1098__rtsan_notify_intercepted_call("getnameinfo");1099return REAL(getnameinfo)(sa, salen, host, hostlen, serv, servlen, flags);1100}11011102#if SANITIZER_INTERCEPT_GETSOCKNAME1103INTERCEPTOR(int, getsockname, int socket, struct sockaddr *sa,1104socklen_t *salen) {1105__rtsan_notify_intercepted_call("getsockname");1106return REAL(getsockname)(socket, sa, salen);1107}1108#define RTSAN_MAYBE_INTERCEPT_GETSOCKNAME INTERCEPT_FUNCTION(getsockname)1109#else1110#define RTSAN_MAYBE_INTERCEPT_GETSOCKNAME1111#endif11121113#if SANITIZER_INTERCEPT_GETPEERNAME1114INTERCEPTOR(int, getpeername, int socket, struct sockaddr *sa,1115socklen_t *salen) {1116__rtsan_notify_intercepted_call("getpeername");1117return REAL(getpeername)(socket, sa, salen);1118}1119#define RTSAN_MAYBE_INTERCEPT_GETPEERNAME INTERCEPT_FUNCTION(getpeername)1120#else1121#define RTSAN_MAYBE_INTERCEPT_GETPEERNAME1122#endif11231124INTERCEPTOR(int, bind, int socket, const struct sockaddr *address,1125socklen_t address_len) {1126__rtsan_notify_intercepted_call("bind");1127return REAL(bind)(socket, address, address_len);1128}11291130INTERCEPTOR(int, listen, int socket, int backlog) {1131__rtsan_notify_intercepted_call("listen");1132return REAL(listen)(socket, backlog);1133}11341135INTERCEPTOR(int, accept, int socket, struct sockaddr *address,1136socklen_t *address_len) {1137__rtsan_notify_intercepted_call("accept");1138return REAL(accept)(socket, address, address_len);1139}11401141INTERCEPTOR(int, connect, int socket, const struct sockaddr *address,1142socklen_t address_len) {1143__rtsan_notify_intercepted_call("connect");1144return REAL(connect)(socket, address, address_len);1145}11461147INTERCEPTOR(int, socket, int domain, int type, int protocol) {1148__rtsan_notify_intercepted_call("socket");1149return REAL(socket)(domain, type, protocol);1150}11511152INTERCEPTOR(ssize_t, send, int sockfd, const void *buf, size_t len, int flags) {1153__rtsan_notify_intercepted_call("send");1154return REAL(send)(sockfd, buf, len, flags);1155}11561157INTERCEPTOR(ssize_t, sendmsg, int socket, const struct msghdr *message,1158int flags) {1159__rtsan_notify_intercepted_call("sendmsg");1160return REAL(sendmsg)(socket, message, flags);1161}11621163#if SANITIZER_INTERCEPT_SENDMMSG1164#if SANITIZER_MUSL1165INTERCEPTOR(int, sendmmsg, int socket, struct mmsghdr *message,1166unsigned int len, unsigned int flags) {1167#else1168INTERCEPTOR(int, sendmmsg, int socket, struct mmsghdr *message,1169unsigned int len, int flags) {1170#endif1171__rtsan_notify_intercepted_call("sendmmsg");1172return REAL(sendmmsg)(socket, message, len, flags);1173}1174#define RTSAN_MAYBE_INTERCEPT_SENDMMSG INTERCEPT_FUNCTION(sendmmsg)1175#else1176#define RTSAN_MAYBE_INTERCEPT_SENDMMSG1177#endif11781179INTERCEPTOR(ssize_t, sendto, int socket, const void *buffer, size_t length,1180int flags, const struct sockaddr *dest_addr, socklen_t dest_len) {1181__rtsan_notify_intercepted_call("sendto");1182return REAL(sendto)(socket, buffer, length, flags, dest_addr, dest_len);1183}11841185INTERCEPTOR(ssize_t, recv, int socket, void *buffer, size_t length, int flags) {1186__rtsan_notify_intercepted_call("recv");1187return REAL(recv)(socket, buffer, length, flags);1188}11891190INTERCEPTOR(ssize_t, recvfrom, int socket, void *buffer, size_t length,1191int flags, struct sockaddr *address, socklen_t *address_len) {1192__rtsan_notify_intercepted_call("recvfrom");1193return REAL(recvfrom)(socket, buffer, length, flags, address, address_len);1194}11951196INTERCEPTOR(ssize_t, recvmsg, int socket, struct msghdr *message, int flags) {1197__rtsan_notify_intercepted_call("recvmsg");1198return REAL(recvmsg)(socket, message, flags);1199}12001201#if SANITIZER_INTERCEPT_RECVMMSG1202#if SANITIZER_MUSL1203INTERCEPTOR(int, recvmmsg, int socket, struct mmsghdr *message,1204unsigned int len, unsigned int flags, struct timespec *timeout) {1205#elif defined(__GLIBC_MINOR__) && __GLIBC_MINOR__ < 211206INTERCEPTOR(int, recvmmsg, int socket, struct mmsghdr *message,1207unsigned int len, int flags, const struct timespec *timeout) {1208#else1209INTERCEPTOR(int, recvmmsg, int socket, struct mmsghdr *message,1210unsigned int len, int flags, struct timespec *timeout) {1211#endif // defined(__GLIBC_MINOR) && __GLIBC_MINOR__ < 211212__rtsan_notify_intercepted_call("recvmmsg");1213return REAL(recvmmsg)(socket, message, len, flags, timeout);1214}1215#define RTSAN_MAYBE_INTERCEPT_RECVMMSG INTERCEPT_FUNCTION(recvmmsg)1216#else1217#define RTSAN_MAYBE_INTERCEPT_RECVMMSG1218#endif12191220INTERCEPTOR(int, shutdown, int socket, int how) {1221__rtsan_notify_intercepted_call("shutdown");1222return REAL(shutdown)(socket, how);1223}12241225#if SANITIZER_INTERCEPT_ACCEPT41226INTERCEPTOR(int, accept4, int socket, struct sockaddr *address,1227socklen_t *address_len, int flags) {1228__rtsan_notify_intercepted_call("accept4");1229return REAL(accept4)(socket, address, address_len, flags);1230}1231#define RTSAN_MAYBE_INTERCEPT_ACCEPT4 INTERCEPT_FUNCTION(accept4)1232#else1233#define RTSAN_MAYBE_INTERCEPT_ACCEPT41234#endif12351236#if SANITIZER_INTERCEPT_GETSOCKOPT1237INTERCEPTOR(int, getsockopt, int socket, int level, int option, void *value,1238socklen_t *len) {1239__rtsan_notify_intercepted_call("getsockopt");1240return REAL(getsockopt)(socket, level, option, value, len);1241}12421243INTERCEPTOR(int, setsockopt, int socket, int level, int option,1244const void *value, socklen_t len) {1245__rtsan_notify_intercepted_call("setsockopt");1246return REAL(setsockopt)(socket, level, option, value, len);1247}1248#define RTSAN_MAYBE_INTERCEPT_GETSOCKOPT INTERCEPT_FUNCTION(getsockopt)1249#define RTSAN_MAYBE_INTERCEPT_SETSOCKOPT INTERCEPT_FUNCTION(setsockopt)1250#else1251#define RTSAN_MAYBE_INTERCEPT_GETSOCKOPT1252#define RTSAN_MAYBE_INTERCEPT_SETSOCKOPT1253#endif12541255INTERCEPTOR(int, socketpair, int domain, int type, int protocol, int pair[2]) {1256__rtsan_notify_intercepted_call("socketpair");1257return REAL(socketpair)(domain, type, protocol, pair);1258}12591260// I/O Multiplexing12611262INTERCEPTOR(int, poll, struct pollfd *fds, nfds_t nfds, int timeout) {1263__rtsan_notify_intercepted_call("poll");1264return REAL(poll)(fds, nfds, timeout);1265}12661267#if !SANITIZER_APPLE1268// FIXME: This should work on all unix systems, even Mac, but currently1269// it is showing some weird error while linking1270// error: declaration of 'select' has a different language linkage1271INTERCEPTOR(int, select, int nfds, fd_set *readfds, fd_set *writefds,1272fd_set *exceptfds, struct timeval *timeout) {1273__rtsan_notify_intercepted_call("select");1274return REAL(select)(nfds, readfds, writefds, exceptfds, timeout);1275}1276#define RTSAN_MAYBE_INTERCEPT_SELECT INTERCEPT_FUNCTION(select)1277#else1278#define RTSAN_MAYBE_INTERCEPT_SELECT1279#endif // !SANITIZER_APPLE12801281INTERCEPTOR(int, pselect, int nfds, fd_set *readfds, fd_set *writefds,1282fd_set *exceptfds, const struct timespec *timeout,1283const sigset_t *sigmask) {1284__rtsan_notify_intercepted_call("pselect");1285return REAL(pselect)(nfds, readfds, writefds, exceptfds, timeout, sigmask);1286}12871288#if SANITIZER_INTERCEPT_EPOLL1289INTERCEPTOR(int, epoll_create, int size) {1290__rtsan_notify_intercepted_call("epoll_create");1291return REAL(epoll_create)(size);1292}12931294INTERCEPTOR(int, epoll_create1, int flags) {1295__rtsan_notify_intercepted_call("epoll_create1");1296return REAL(epoll_create1)(flags);1297}12981299INTERCEPTOR(int, epoll_ctl, int epfd, int op, int fd,1300struct epoll_event *event) {1301__rtsan_notify_intercepted_call("epoll_ctl");1302return REAL(epoll_ctl)(epfd, op, fd, event);1303}13041305INTERCEPTOR(int, epoll_wait, int epfd, struct epoll_event *events,1306int maxevents, int timeout) {1307__rtsan_notify_intercepted_call("epoll_wait");1308return REAL(epoll_wait)(epfd, events, maxevents, timeout);1309}13101311INTERCEPTOR(int, epoll_pwait, int epfd, struct epoll_event *events,1312int maxevents, int timeout, const sigset_t *sigmask) {1313__rtsan_notify_intercepted_call("epoll_pwait");1314return REAL(epoll_pwait)(epfd, events, maxevents, timeout, sigmask);1315}1316#define RTSAN_MAYBE_INTERCEPT_EPOLL_CREATE INTERCEPT_FUNCTION(epoll_create)1317#define RTSAN_MAYBE_INTERCEPT_EPOLL_CREATE1 INTERCEPT_FUNCTION(epoll_create1)1318#define RTSAN_MAYBE_INTERCEPT_EPOLL_CTL INTERCEPT_FUNCTION(epoll_ctl)1319#define RTSAN_MAYBE_INTERCEPT_EPOLL_WAIT INTERCEPT_FUNCTION(epoll_wait)1320#define RTSAN_MAYBE_INTERCEPT_EPOLL_PWAIT INTERCEPT_FUNCTION(epoll_pwait)1321#else1322#define RTSAN_MAYBE_INTERCEPT_EPOLL_CREATE1323#define RTSAN_MAYBE_INTERCEPT_EPOLL_CREATE11324#define RTSAN_MAYBE_INTERCEPT_EPOLL_CTL1325#define RTSAN_MAYBE_INTERCEPT_EPOLL_WAIT1326#define RTSAN_MAYBE_INTERCEPT_EPOLL_PWAIT1327#endif // SANITIZER_INTERCEPT_EPOLL13281329#if SANITIZER_INTERCEPT_PPOLL1330INTERCEPTOR(int, ppoll, struct pollfd *fds, nfds_t n, const struct timespec *ts,1331const sigset_t *set) {1332__rtsan_notify_intercepted_call("ppoll");1333return REAL(ppoll)(fds, n, ts, set);1334}1335#define RTSAN_MAYBE_INTERCEPT_PPOLL INTERCEPT_FUNCTION(ppoll)1336#else1337#define RTSAN_MAYBE_INTERCEPT_PPOLL1338#endif13391340#if SANITIZER_INTERCEPT_KQUEUE1341INTERCEPTOR(int, kqueue, void) {1342__rtsan_notify_intercepted_call("kqueue");1343return REAL(kqueue)();1344}13451346INTERCEPTOR(int, kevent, int kq, const struct kevent *changelist, int nchanges,1347struct kevent *eventlist, int nevents,1348const struct timespec *timeout) {1349__rtsan_notify_intercepted_call("kevent");1350return REAL(kevent)(kq, changelist, nchanges, eventlist, nevents, timeout);1351}13521353INTERCEPTOR(int, kevent64, int kq, const struct kevent64_s *changelist,1354int nchanges, struct kevent64_s *eventlist, int nevents,1355unsigned int flags, const struct timespec *timeout) {1356__rtsan_notify_intercepted_call("kevent64");1357return REAL(kevent64)(kq, changelist, nchanges, eventlist, nevents, flags,1358timeout);1359}1360#define RTSAN_MAYBE_INTERCEPT_KQUEUE INTERCEPT_FUNCTION(kqueue)1361#define RTSAN_MAYBE_INTERCEPT_KEVENT INTERCEPT_FUNCTION(kevent)1362#define RTSAN_MAYBE_INTERCEPT_KEVENT64 INTERCEPT_FUNCTION(kevent64)1363#else1364#define RTSAN_MAYBE_INTERCEPT_KQUEUE1365#define RTSAN_MAYBE_INTERCEPT_KEVENT1366#define RTSAN_MAYBE_INTERCEPT_KEVENT641367#endif // SANITIZER_INTERCEPT_KQUEUE13681369#if SANITIZER_LINUX1370INTERCEPTOR(int, inotify_init) {1371__rtsan_notify_intercepted_call("inotify_init");1372return REAL(inotify_init)();1373}13741375INTERCEPTOR(int, inotify_init1, int flags) {1376__rtsan_notify_intercepted_call("inotify_init1");1377return REAL(inotify_init1)(flags);1378}13791380INTERCEPTOR(int, inotify_add_watch, int fd, const char *path, uint32_t mask) {1381__rtsan_notify_intercepted_call("inotify_add_watch");1382return REAL(inotify_add_watch)(fd, path, mask);1383}13841385INTERCEPTOR(int, inotify_rm_watch, int fd, int wd) {1386__rtsan_notify_intercepted_call("inotify_rm_watch");1387return REAL(inotify_rm_watch)(fd, wd);1388}13891390INTERCEPTOR(int, timerfd_create, int clockid, int flags) {1391__rtsan_notify_intercepted_call("timerfd_create");1392return REAL(timerfd_create)(clockid, flags);1393}13941395INTERCEPTOR(int, timerfd_settime, int fd, int flags, const itimerspec *newval,1396struct itimerspec *oldval) {1397__rtsan_notify_intercepted_call("timerfd_settime");1398return REAL(timerfd_settime)(fd, flags, newval, oldval);1399}14001401INTERCEPTOR(int, timerfd_gettime, int fd, struct itimerspec *val) {1402__rtsan_notify_intercepted_call("timerfd_gettime");1403return REAL(timerfd_gettime)(fd, val);1404}14051406/* eventfd wrappers calls SYS_eventfd2 down the line */1407INTERCEPTOR(int, eventfd, unsigned int count, int flags) {1408__rtsan_notify_intercepted_call("eventfd");1409return REAL(eventfd)(count, flags);1410}1411#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT INTERCEPT_FUNCTION(inotify_init)1412#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1 INTERCEPT_FUNCTION(inotify_init1)1413#define RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH \1414INTERCEPT_FUNCTION(inotify_add_watch)1415#define RTSAN_MAYBE_INTERCEPT_INOTIFY_RM_WATCH \1416INTERCEPT_FUNCTION(inotify_rm_watch)1417#define RTSAN_MAYBE_INTERCEPT_TIMERFD_CREATE INTERCEPT_FUNCTION(timerfd_create)1418#define RTSAN_MAYBE_INTERCEPT_TIMERFD_SETTIME \1419INTERCEPT_FUNCTION(timerfd_settime)1420#define RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME \1421INTERCEPT_FUNCTION(timerfd_gettime)1422#define RTSAN_MAYBE_INTERCEPT_EVENTFD INTERCEPT_FUNCTION(eventfd)1423#else1424#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1425#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT11426#define RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH1427#define RTSAN_MAYBE_INTERCEPT_INOTIFY_RM_WATCH1428#define RTSAN_MAYBE_INTERCEPT_TIMERFD_CREATE1429#define RTSAN_MAYBE_INTERCEPT_TIMERFD_SETTIME1430#define RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME1431#define RTSAN_MAYBE_INTERCEPT_EVENTFD1432#endif14331434INTERCEPTOR(int, pipe, int pipefd[2]) {1435__rtsan_notify_intercepted_call("pipe");1436return REAL(pipe)(pipefd);1437}14381439#if !SANITIZER_APPLE1440INTERCEPTOR(int, pipe2, int pipefd[2], int flags) {1441__rtsan_notify_intercepted_call("pipe2");1442return REAL(pipe2)(pipefd, flags);1443}1444#define RTSAN_MAYBE_INTERCEPT_PIPE2 INTERCEPT_FUNCTION(pipe2)1445#else1446#define RTSAN_MAYBE_INTERCEPT_PIPE21447#endif14481449INTERCEPTOR(int, mkfifo, const char *pathname, mode_t mode) {1450__rtsan_notify_intercepted_call("mkfifo");1451return REAL(mkfifo)(pathname, mode);1452}14531454INTERCEPTOR(pid_t, fork, void) {1455__rtsan_notify_intercepted_call("fork");1456return REAL(fork)();1457}14581459INTERCEPTOR(int, execve, const char *filename, char *const argv[],1460char *const envp[]) {1461__rtsan_notify_intercepted_call("execve");1462return REAL(execve)(filename, argv, envp);1463}14641465#if SANITIZER_INTERCEPT_PROCESS_VM_READV1466INTERCEPTOR(ssize_t, process_vm_readv, pid_t pid, const struct iovec *local_iov,1467unsigned long liovcnt, const struct iovec *remote_iov,1468unsigned long riovcnt, unsigned long flags) {1469__rtsan_notify_intercepted_call("process_vm_readv");1470return REAL(process_vm_readv)(pid, local_iov, liovcnt, remote_iov, riovcnt,1471flags);1472}14731474INTERCEPTOR(ssize_t, process_vm_writev, pid_t pid,1475const struct iovec *local_iov, unsigned long liovcnt,1476const struct iovec *remote_iov, unsigned long riovcnt,1477unsigned long flags) {1478__rtsan_notify_intercepted_call("process_vm_writev");1479return REAL(process_vm_writev)(pid, local_iov, liovcnt, remote_iov, riovcnt,1480flags);1481}1482#define RTSAN_MAYBE_INTERCEPT_PROCESS_VM_READV \1483INTERCEPT_FUNCTION(process_vm_readv)1484#define RTSAN_MAYBE_INTERCEPT_PROCESS_VM_WRITEV \1485INTERCEPT_FUNCTION(process_vm_writev)1486#else1487#define RTSAN_MAYBE_INTERCEPT_PROCESS_VM_READV1488#define RTSAN_MAYBE_INTERCEPT_PROCESS_VM_WRITEV1489#endif14901491// TODO: the `wait` family of functions is an oddity. In testing, if you1492// intercept them, Darwin seemingly ignores them, and linux never returns from1493// the test. Revisit this in the future, but hopefully intercepting fork/exec is1494// enough to dissuade usage of wait by proxy.14951496#if SANITIZER_APPLE1497#define INT_TYPE_SYSCALL int1498#else1499#define INT_TYPE_SYSCALL long1500#endif15011502#pragma clang diagnostic push1503#pragma clang diagnostic ignored "-Wdeprecated-declarations"1504INTERCEPTOR(INT_TYPE_SYSCALL, syscall, INT_TYPE_SYSCALL number, ...) {1505__rtsan_notify_intercepted_call("syscall");15061507va_list args;1508va_start(args, number);15091510// the goal is to pick something large enough to hold all syscall args1511// see fcntl for more discussion and why we always pull all 6 args1512using arg_type = unsigned long;1513arg_type arg1 = va_arg(args, arg_type);1514arg_type arg2 = va_arg(args, arg_type);1515arg_type arg3 = va_arg(args, arg_type);1516arg_type arg4 = va_arg(args, arg_type);1517arg_type arg5 = va_arg(args, arg_type);1518arg_type arg6 = va_arg(args, arg_type);15191520// these are various examples of things that COULD be passed1521static_assert(sizeof(arg_type) >= sizeof(off_t));1522static_assert(sizeof(arg_type) >= sizeof(struct flock *));1523static_assert(sizeof(arg_type) >= sizeof(const char *));1524static_assert(sizeof(arg_type) >= sizeof(int));1525static_assert(sizeof(arg_type) >= sizeof(unsigned long));15261527va_end(args);15281529return REAL(syscall)(number, arg1, arg2, arg3, arg4, arg5, arg6);1530}1531#pragma clang diagnostic pop15321533// Preinit1534void __rtsan::InitializeInterceptors() {1535INTERCEPT_FUNCTION(calloc);1536INTERCEPT_FUNCTION(free);1537RTSAN_MAYBE_INTERCEPT_FREE_SIZED;1538RTSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED;1539INTERCEPT_FUNCTION(malloc);1540INTERCEPT_FUNCTION(realloc);1541INTERCEPT_FUNCTION(reallocf);1542INTERCEPT_FUNCTION(valloc);1543RTSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC;1544INTERCEPT_FUNCTION(posix_memalign);1545INTERCEPT_FUNCTION(mmap);1546RTSAN_MAYBE_INTERCEPT_MMAP64;1547RTSAN_MAYBE_INTERCEPT_MREMAP;1548INTERCEPT_FUNCTION(munmap);1549RTSAN_MAYBE_INTERCEPT_MADVISE;1550RTSAN_MAYBE_INTERCEPT_POSIX_MADVISE;1551INTERCEPT_FUNCTION(mprotect);1552INTERCEPT_FUNCTION(msync);1553INTERCEPT_FUNCTION(mincore);1554INTERCEPT_FUNCTION(shm_open);1555INTERCEPT_FUNCTION(shm_unlink);1556RTSAN_MAYBE_INTERCEPT_MEMFD_CREATE;1557RTSAN_MAYBE_INTERCEPT_MEMALIGN;1558RTSAN_MAYBE_INTERCEPT_PVALLOC;15591560INTERCEPT_FUNCTION(open);1561RTSAN_MAYBE_INTERCEPT_OPEN64;1562INTERCEPT_FUNCTION(openat);1563RTSAN_MAYBE_INTERCEPT_OPENAT64;1564INTERCEPT_FUNCTION(close);1565INTERCEPT_FUNCTION(chdir);1566INTERCEPT_FUNCTION(fchdir);1567RTSAN_MAYBE_INTERCEPT_READLINK;1568RTSAN_MAYBE_INTERCEPT_READLINKAT;1569INTERCEPT_FUNCTION(unlink);1570INTERCEPT_FUNCTION(unlinkat);1571INTERCEPT_FUNCTION(symlink);1572INTERCEPT_FUNCTION(symlinkat);1573INTERCEPT_FUNCTION(truncate);1574INTERCEPT_FUNCTION(ftruncate);1575RTSAN_MAYBE_INTERCEPT_TRUNCATE64;1576RTSAN_MAYBE_INTERCEPT_FTRUNCATE64;1577INTERCEPT_FUNCTION(fopen);1578RTSAN_MAYBE_INTERCEPT_FOPEN64;1579RTSAN_MAYBE_INTERCEPT_FREOPEN64;1580INTERCEPT_FUNCTION(fread);1581INTERCEPT_FUNCTION(read);1582INTERCEPT_FUNCTION(write);1583INTERCEPT_FUNCTION(pread);1584RTSAN_MAYBE_INTERCEPT_PREAD64;1585RTSAN_MAYBE_INTERCEPT_PREADV;1586RTSAN_MAYBE_INTERCEPT_PREADV64;1587INTERCEPT_FUNCTION(readv);1588INTERCEPT_FUNCTION(pwrite);1589RTSAN_MAYBE_INTERCEPT_PWRITE64;1590RTSAN_MAYBE_INTERCEPT_PWRITEV;1591RTSAN_MAYBE_INTERCEPT_PWRITEV64;1592INTERCEPT_FUNCTION(writev);1593INTERCEPT_FUNCTION(fwrite);1594INTERCEPT_FUNCTION(fclose);1595INTERCEPT_FUNCTION(fcntl);1596RTSAN_MAYBE_INTERCEPT_FCNTL64;1597INTERCEPT_FUNCTION(creat);1598RTSAN_MAYBE_INTERCEPT_CREAT64;1599INTERCEPT_FUNCTION(puts);1600INTERCEPT_FUNCTION(fputs);1601INTERCEPT_FUNCTION(fflush);1602RTSAN_MAYBE_INTERCEPT_FPURGE;1603RTSAN_MAYBE_INTERCEPT_PIPE2;1604INTERCEPT_FUNCTION(fdopen);1605INTERCEPT_FUNCTION(freopen);1606RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE;1607RTSAN_MAYBE_INTERCEPT_OPEN_MEMSTREAM;1608RTSAN_MAYBE_INTERCEPT_FMEMOPEN;1609RTSAN_MAYBE_INTERCEPT_SETBUF;1610RTSAN_MAYBE_INTERCEPT_SETVBUF;1611RTSAN_MAYBE_INTERCEPT_SETLINEBUF;1612RTSAN_MAYBE_INTERCEPT_SETBUFFER;1613RTSAN_MAYBE_INTERCEPT_FGETPOS;1614RTSAN_MAYBE_INTERCEPT_FSEEK;1615RTSAN_MAYBE_INTERCEPT_FSEEKO;1616RTSAN_MAYBE_INTERCEPT_FSETPOS;1617RTSAN_MAYBE_INTERCEPT_FTELL;1618RTSAN_MAYBE_INTERCEPT_FTELLO;1619RTSAN_MAYBE_INTERCEPT_REWIND;1620RTSAN_MAYBE_INTERCEPT_FGETPOS64;1621RTSAN_MAYBE_INTERCEPT_FSEEKO64;1622RTSAN_MAYBE_INTERCEPT_FSETPOS64;1623RTSAN_MAYBE_INTERCEPT_FTELLO64;1624INTERCEPT_FUNCTION(lseek);1625RTSAN_MAYBE_INTERCEPT_LSEEK64;1626INTERCEPT_FUNCTION(dup);1627INTERCEPT_FUNCTION(dup2);1628INTERCEPT_FUNCTION(chmod);1629INTERCEPT_FUNCTION(fchmod);1630INTERCEPT_FUNCTION(mkdir);1631INTERCEPT_FUNCTION(rmdir);1632INTERCEPT_FUNCTION(umask);1633INTERCEPT_FUNCTION(ioctl);16341635RTSAN_MAYBE_INTERCEPT_OSSPINLOCKLOCK;1636RTSAN_MAYBE_INTERCEPT_OS_UNFAIR_LOCK_LOCK;1637RTSAN_MAYBE_INTERCEPT_PTHREAD_SPIN_LOCK;16381639INTERCEPT_FUNCTION(pthread_create);1640INTERCEPT_FUNCTION(pthread_mutex_lock);1641INTERCEPT_FUNCTION(pthread_mutex_unlock);1642INTERCEPT_FUNCTION(pthread_join);1643INTERCEPT_FUNCTION(pthread_cond_signal);1644INTERCEPT_FUNCTION(pthread_cond_broadcast);1645INTERCEPT_FUNCTION(pthread_cond_wait);1646INTERCEPT_FUNCTION(pthread_cond_timedwait);1647INTERCEPT_FUNCTION(pthread_rwlock_rdlock);1648INTERCEPT_FUNCTION(pthread_rwlock_unlock);1649INTERCEPT_FUNCTION(pthread_rwlock_wrlock);16501651INTERCEPT_FUNCTION(sleep);1652INTERCEPT_FUNCTION(usleep);1653INTERCEPT_FUNCTION(nanosleep);1654INTERCEPT_FUNCTION(sched_yield);1655RTSAN_MAYBE_INTERCEPT_SCHED_GETAFFINITY;1656RTSAN_MAYBE_INTERCEPT_SCHED_SETAFFINITY;16571658INTERCEPT_FUNCTION(accept);1659INTERCEPT_FUNCTION(bind);1660INTERCEPT_FUNCTION(connect);1661INTERCEPT_FUNCTION(getaddrinfo);1662INTERCEPT_FUNCTION(getnameinfo);1663INTERCEPT_FUNCTION(listen);1664INTERCEPT_FUNCTION(recv);1665INTERCEPT_FUNCTION(recvfrom);1666INTERCEPT_FUNCTION(recvmsg);1667RTSAN_MAYBE_INTERCEPT_RECVMMSG;1668INTERCEPT_FUNCTION(send);1669INTERCEPT_FUNCTION(sendmsg);1670RTSAN_MAYBE_INTERCEPT_SENDMMSG;1671INTERCEPT_FUNCTION(sendto);1672INTERCEPT_FUNCTION(shutdown);1673INTERCEPT_FUNCTION(socket);1674RTSAN_MAYBE_INTERCEPT_ACCEPT4;1675RTSAN_MAYBE_INTERCEPT_GETSOCKNAME;1676RTSAN_MAYBE_INTERCEPT_GETPEERNAME;1677RTSAN_MAYBE_INTERCEPT_GETSOCKOPT;1678RTSAN_MAYBE_INTERCEPT_SETSOCKOPT;1679INTERCEPT_FUNCTION(socketpair);16801681RTSAN_MAYBE_INTERCEPT_SELECT;1682INTERCEPT_FUNCTION(pselect);1683INTERCEPT_FUNCTION(poll);1684RTSAN_MAYBE_INTERCEPT_EPOLL_CREATE;1685RTSAN_MAYBE_INTERCEPT_EPOLL_CREATE1;1686RTSAN_MAYBE_INTERCEPT_EPOLL_CTL;1687RTSAN_MAYBE_INTERCEPT_EPOLL_WAIT;1688RTSAN_MAYBE_INTERCEPT_EPOLL_PWAIT;1689RTSAN_MAYBE_INTERCEPT_PPOLL;1690RTSAN_MAYBE_INTERCEPT_KQUEUE;1691RTSAN_MAYBE_INTERCEPT_KEVENT;1692RTSAN_MAYBE_INTERCEPT_KEVENT64;16931694RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT;1695RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1;1696RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH;1697RTSAN_MAYBE_INTERCEPT_INOTIFY_RM_WATCH;16981699RTSAN_MAYBE_INTERCEPT_TIMERFD_CREATE;1700RTSAN_MAYBE_INTERCEPT_TIMERFD_SETTIME;1701RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME;1702RTSAN_MAYBE_INTERCEPT_EVENTFD;17031704INTERCEPT_FUNCTION(pipe);1705INTERCEPT_FUNCTION(mkfifo);17061707INTERCEPT_FUNCTION(fork);1708INTERCEPT_FUNCTION(execve);17091710RTSAN_MAYBE_INTERCEPT_PROCESS_VM_READV;1711RTSAN_MAYBE_INTERCEPT_PROCESS_VM_WRITEV;17121713INTERCEPT_FUNCTION(syscall);1714}17151716#endif // SANITIZER_POSIX171717181719