xref: /freebsd/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc (revision ba3c1f5972d7b90feb6e6da47905ff2757e0fe57)
1//===-- sanitizer_common_syscalls.inc ---------------------------*- 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// Common syscalls handlers for tools like AddressSanitizer,
10// ThreadSanitizer, MemorySanitizer, etc.
11//
12// This file should be included into the tool's interceptor file,
13// which has to define it's own macros:
14//   COMMON_SYSCALL_PRE_READ_RANGE
15//          Called in prehook for regions that will be read by the kernel and
16//          must be initialized.
17//   COMMON_SYSCALL_PRE_WRITE_RANGE
18//          Called in prehook for regions that will be written to by the kernel
19//          and must be addressable. The actual write range may be smaller than
20//          reported in the prehook. See POST_WRITE_RANGE.
21//   COMMON_SYSCALL_POST_READ_RANGE
22//          Called in posthook for regions that were read by the kernel. Does
23//          not make much sense.
24//   COMMON_SYSCALL_POST_WRITE_RANGE
25//          Called in posthook for regions that were written to by the kernel
26//          and are now initialized.
27//   COMMON_SYSCALL_ACQUIRE(addr)
28//          Acquire memory visibility from addr.
29//   COMMON_SYSCALL_RELEASE(addr)
30//          Release memory visibility to addr.
31//   COMMON_SYSCALL_FD_CLOSE(fd)
32//          Called before closing file descriptor fd.
33//   COMMON_SYSCALL_FD_ACQUIRE(fd)
34//          Acquire memory visibility from fd.
35//   COMMON_SYSCALL_FD_RELEASE(fd)
36//          Release memory visibility to fd.
37//   COMMON_SYSCALL_PRE_FORK()
38//          Called before fork syscall.
39//   COMMON_SYSCALL_POST_FORK(long res)
40//          Called after fork syscall.
41//===----------------------------------------------------------------------===//
42
43#include "sanitizer_platform.h"
44#if SANITIZER_LINUX
45
46#  include "sanitizer_libc.h"
47
48#  define PRE_SYSCALL(name) \
49    SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_syscall_pre_impl_##name
50#  define PRE_READ(p, s) COMMON_SYSCALL_PRE_READ_RANGE(p, s)
51#  define PRE_WRITE(p, s) COMMON_SYSCALL_PRE_WRITE_RANGE(p, s)
52
53#  define POST_SYSCALL(name) \
54    SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_syscall_post_impl_##name
55#  define POST_READ(p, s) COMMON_SYSCALL_POST_READ_RANGE(p, s)
56#  define POST_WRITE(p, s) COMMON_SYSCALL_POST_WRITE_RANGE(p, s)
57
58#  ifndef COMMON_SYSCALL_ACQUIRE
59#    define COMMON_SYSCALL_ACQUIRE(addr) ((void)(addr))
60#  endif
61
62#  ifndef COMMON_SYSCALL_RELEASE
63#    define COMMON_SYSCALL_RELEASE(addr) ((void)(addr))
64#  endif
65
66#  ifndef COMMON_SYSCALL_FD_CLOSE
67#    define COMMON_SYSCALL_FD_CLOSE(fd) ((void)(fd))
68#  endif
69
70#  ifndef COMMON_SYSCALL_FD_ACQUIRE
71#    define COMMON_SYSCALL_FD_ACQUIRE(fd) ((void)(fd))
72#  endif
73
74#  ifndef COMMON_SYSCALL_FD_RELEASE
75#    define COMMON_SYSCALL_FD_RELEASE(fd) ((void)(fd))
76#  endif
77
78#  ifndef COMMON_SYSCALL_PRE_FORK
79#    define COMMON_SYSCALL_PRE_FORK() \
80      {}
81#  endif
82
83#  ifndef COMMON_SYSCALL_POST_FORK
84#    define COMMON_SYSCALL_POST_FORK(res) \
85      {}
86#  endif
87
88// FIXME: do some kind of PRE_READ for all syscall arguments (int(s) and such).
89
90extern "C" {
91struct sanitizer_kernel_iovec {
92  void *iov_base;
93  unsigned long iov_len;
94};
95
96struct sanitizer_kernel_msghdr {
97  void *msg_name;
98  int msg_namelen;
99  struct sanitizer_kernel_iovec *msg_iov;
100  unsigned long msg_iovlen;
101  void *msg_control;
102  unsigned long msg_controllen;
103  unsigned msg_flags;
104};
105
106struct sanitizer_kernel_mmsghdr {
107  struct sanitizer_kernel_msghdr msg_hdr;
108  unsigned msg_len;
109};
110
111struct sanitizer_kernel_timespec {
112  long tv_sec;
113  long tv_nsec;
114};
115
116struct sanitizer_kernel_timeval {
117  long tv_sec;
118  long tv_usec;
119};
120
121struct sanitizer_kernel_rusage {
122  struct sanitizer_kernel_timeval ru_timeval[2];
123  long ru_long[14];
124};
125
126struct sanitizer_kernel_sockaddr {
127  unsigned short sa_family;
128  char sa_data[14];
129};
130
131// Real sigset size is always passed as a syscall argument.
132// Declare it "void" to catch sizeof(kernel_sigset_t).
133typedef void kernel_sigset_t;
134
135static void kernel_write_iovec(const __sanitizer_iovec *iovec, SIZE_T iovlen,
136                               SIZE_T maxlen) {
137  for (SIZE_T i = 0; i < iovlen && maxlen; ++i) {
138    SSIZE_T sz = Min(iovec[i].iov_len, maxlen);
139    POST_WRITE(iovec[i].iov_base, sz);
140    maxlen -= sz;
141  }
142}
143
144// This functions uses POST_READ, because it needs to run after syscall to know
145// the real read range.
146static void kernel_read_iovec(const __sanitizer_iovec *iovec, SIZE_T iovlen,
147                              SIZE_T maxlen) {
148  POST_READ(iovec, sizeof(*iovec) * iovlen);
149  for (SIZE_T i = 0; i < iovlen && maxlen; ++i) {
150    SSIZE_T sz = Min(iovec[i].iov_len, maxlen);
151    POST_READ(iovec[i].iov_base, sz);
152    maxlen -= sz;
153  }
154}
155
156PRE_SYSCALL(recvmsg)(long sockfd, sanitizer_kernel_msghdr *msg, long flags) {
157  PRE_READ(msg, sizeof(*msg));
158}
159
160POST_SYSCALL(recvmsg)
161(long res, long sockfd, sanitizer_kernel_msghdr *msg, long flags) {
162  if (res >= 0) {
163    if (msg) {
164      for (unsigned long i = 0; i < msg->msg_iovlen; ++i) {
165        POST_WRITE(msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len);
166      }
167      POST_WRITE(msg->msg_control, msg->msg_controllen);
168    }
169  }
170}
171
172PRE_SYSCALL(recvmmsg)
173(long fd, sanitizer_kernel_mmsghdr *msg, long vlen, long flags, void *timeout) {
174  PRE_READ(msg, vlen * sizeof(*msg));
175}
176
177POST_SYSCALL(recvmmsg)
178(long res, long fd, sanitizer_kernel_mmsghdr *msg, long vlen, long flags,
179 void *timeout) {
180  if (res >= 0) {
181    if (msg) {
182      for (unsigned long i = 0; i < msg->msg_hdr.msg_iovlen; ++i) {
183        POST_WRITE(msg->msg_hdr.msg_iov[i].iov_base,
184                   msg->msg_hdr.msg_iov[i].iov_len);
185      }
186      POST_WRITE(msg->msg_hdr.msg_control, msg->msg_hdr.msg_controllen);
187      POST_WRITE(&msg->msg_len, sizeof(msg->msg_len));
188    }
189    if (timeout)
190      POST_WRITE(timeout, struct_timespec_sz);
191  }
192}
193
194PRE_SYSCALL(read)(long fd, void *buf, uptr count) {
195  if (buf) {
196    PRE_WRITE(buf, count);
197  }
198}
199
200POST_SYSCALL(read)(long res, long fd, void *buf, uptr count) {
201  if (res > 0 && buf) {
202    POST_WRITE(buf, res);
203  }
204}
205
206PRE_SYSCALL(time)(void *tloc) {}
207
208POST_SYSCALL(time)(long res, void *tloc) {
209  if (res >= 0) {
210    if (tloc)
211      POST_WRITE(tloc, sizeof(long));
212  }
213}
214
215PRE_SYSCALL(stime)(void *tptr) {}
216
217POST_SYSCALL(stime)(long res, void *tptr) {
218  if (res >= 0) {
219    if (tptr)
220      POST_WRITE(tptr, sizeof(long));
221  }
222}
223
224PRE_SYSCALL(gettimeofday)(void *tv, void *tz) {}
225
226POST_SYSCALL(gettimeofday)(long res, void *tv, void *tz) {
227  if (res >= 0) {
228    if (tv)
229      POST_WRITE(tv, timeval_sz);
230    if (tz)
231      POST_WRITE(tz, struct_timezone_sz);
232  }
233}
234
235PRE_SYSCALL(settimeofday)(void *tv, void *tz) {}
236
237POST_SYSCALL(settimeofday)(long res, void *tv, void *tz) {
238  if (res >= 0) {
239    if (tv)
240      POST_WRITE(tv, timeval_sz);
241    if (tz)
242      POST_WRITE(tz, struct_timezone_sz);
243  }
244}
245
246#  if !SANITIZER_ANDROID
247PRE_SYSCALL(adjtimex)(void *txc_p) {}
248
249POST_SYSCALL(adjtimex)(long res, void *txc_p) {
250  if (res >= 0) {
251    if (txc_p)
252      POST_WRITE(txc_p, struct_timex_sz);
253  }
254}
255#  endif
256
257PRE_SYSCALL(times)(void *tbuf) {}
258
259POST_SYSCALL(times)(long res, void *tbuf) {
260  if (res >= 0) {
261    if (tbuf)
262      POST_WRITE(tbuf, struct_tms_sz);
263  }
264}
265
266PRE_SYSCALL(gettid)() {}
267
268POST_SYSCALL(gettid)(long res) {}
269
270PRE_SYSCALL(nanosleep)(void *rqtp, void *rmtp) {}
271
272POST_SYSCALL(nanosleep)(long res, void *rqtp, void *rmtp) {
273  if (res >= 0) {
274    if (rqtp)
275      POST_WRITE(rqtp, struct_timespec_sz);
276    if (rmtp)
277      POST_WRITE(rmtp, struct_timespec_sz);
278  }
279}
280
281PRE_SYSCALL(alarm)(long seconds) {}
282
283POST_SYSCALL(alarm)(long res, long seconds) {}
284
285PRE_SYSCALL(getpid)() {}
286
287POST_SYSCALL(getpid)(long res) {}
288
289PRE_SYSCALL(getppid)() {}
290
291POST_SYSCALL(getppid)(long res) {}
292
293PRE_SYSCALL(getuid)() {}
294
295POST_SYSCALL(getuid)(long res) {}
296
297PRE_SYSCALL(geteuid)() {}
298
299POST_SYSCALL(geteuid)(long res) {}
300
301PRE_SYSCALL(getgid)() {}
302
303POST_SYSCALL(getgid)(long res) {}
304
305PRE_SYSCALL(getegid)() {}
306
307POST_SYSCALL(getegid)(long res) {}
308
309PRE_SYSCALL(getresuid)(void *ruid, void *euid, void *suid) {}
310
311POST_SYSCALL(getresuid)(long res, void *ruid, void *euid, void *suid) {
312  if (res >= 0) {
313    if (ruid)
314      POST_WRITE(ruid, sizeof(unsigned));
315    if (euid)
316      POST_WRITE(euid, sizeof(unsigned));
317    if (suid)
318      POST_WRITE(suid, sizeof(unsigned));
319  }
320}
321
322PRE_SYSCALL(getresgid)(void *rgid, void *egid, void *sgid) {}
323
324POST_SYSCALL(getresgid)(long res, void *rgid, void *egid, void *sgid) {
325  if (res >= 0) {
326    if (rgid)
327      POST_WRITE(rgid, sizeof(unsigned));
328    if (egid)
329      POST_WRITE(egid, sizeof(unsigned));
330    if (sgid)
331      POST_WRITE(sgid, sizeof(unsigned));
332  }
333}
334
335PRE_SYSCALL(getpgid)(long pid) {}
336
337POST_SYSCALL(getpgid)(long res, long pid) {}
338
339PRE_SYSCALL(getpgrp)() {}
340
341POST_SYSCALL(getpgrp)(long res) {}
342
343PRE_SYSCALL(getsid)(long pid) {}
344
345POST_SYSCALL(getsid)(long res, long pid) {}
346
347PRE_SYSCALL(getgroups)(long gidsetsize, void *grouplist) {}
348
349POST_SYSCALL(getgroups)
350(long res, long gidsetsize, __sanitizer___kernel_gid_t *grouplist) {
351  if (res >= 0) {
352    if (grouplist)
353      POST_WRITE(grouplist, res * sizeof(*grouplist));
354  }
355}
356
357PRE_SYSCALL(setregid)(long rgid, long egid) {}
358
359POST_SYSCALL(setregid)(long res, long rgid, long egid) {}
360
361PRE_SYSCALL(setgid)(long gid) {}
362
363POST_SYSCALL(setgid)(long res, long gid) {}
364
365PRE_SYSCALL(setreuid)(long ruid, long euid) {}
366
367POST_SYSCALL(setreuid)(long res, long ruid, long euid) {}
368
369PRE_SYSCALL(setuid)(long uid) {}
370
371POST_SYSCALL(setuid)(long res, long uid) {}
372
373PRE_SYSCALL(setresuid)(long ruid, long euid, long suid) {}
374
375POST_SYSCALL(setresuid)(long res, long ruid, long euid, long suid) {}
376
377PRE_SYSCALL(setresgid)(long rgid, long egid, long sgid) {}
378
379POST_SYSCALL(setresgid)(long res, long rgid, long egid, long sgid) {}
380
381PRE_SYSCALL(setfsuid)(long uid) {}
382
383POST_SYSCALL(setfsuid)(long res, long uid) {}
384
385PRE_SYSCALL(setfsgid)(long gid) {}
386
387POST_SYSCALL(setfsgid)(long res, long gid) {}
388
389PRE_SYSCALL(setpgid)(long pid, long pgid) {}
390
391POST_SYSCALL(setpgid)(long res, long pid, long pgid) {}
392
393PRE_SYSCALL(setsid)() {}
394
395POST_SYSCALL(setsid)(long res) {}
396
397PRE_SYSCALL(setgroups)(long gidsetsize, __sanitizer___kernel_gid_t *grouplist) {
398  if (grouplist)
399    POST_WRITE(grouplist, gidsetsize * sizeof(*grouplist));
400}
401
402POST_SYSCALL(setgroups)
403(long res, long gidsetsize, __sanitizer___kernel_gid_t *grouplist) {}
404
405PRE_SYSCALL(acct)(const void *name) {
406  if (name)
407    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
408}
409
410POST_SYSCALL(acct)(long res, const void *name) {}
411
412PRE_SYSCALL(capget)(void *header, void *dataptr) {
413  if (header)
414    PRE_READ(header, __user_cap_header_struct_sz);
415}
416
417POST_SYSCALL(capget)(long res, void *header, void *dataptr) {
418  if (res >= 0)
419    if (dataptr)
420      POST_WRITE(dataptr, __user_cap_data_struct_sz);
421}
422
423PRE_SYSCALL(capset)(void *header, const void *data) {
424  if (header)
425    PRE_READ(header, __user_cap_header_struct_sz);
426  if (data)
427    PRE_READ(data, __user_cap_data_struct_sz);
428}
429
430POST_SYSCALL(capset)(long res, void *header, const void *data) {}
431
432PRE_SYSCALL(personality)(long personality) {}
433
434POST_SYSCALL(personality)(long res, long personality) {}
435
436PRE_SYSCALL(sigpending)(void *set) {}
437
438POST_SYSCALL(sigpending)(long res, void *set) {
439  if (res >= 0) {
440    if (set)
441      POST_WRITE(set, old_sigset_t_sz);
442  }
443}
444
445PRE_SYSCALL(sigprocmask)(long how, void *set, void *oset) {}
446
447POST_SYSCALL(sigprocmask)(long res, long how, void *set, void *oset) {
448  if (res >= 0) {
449    if (set)
450      POST_WRITE(set, old_sigset_t_sz);
451    if (oset)
452      POST_WRITE(oset, old_sigset_t_sz);
453  }
454}
455
456PRE_SYSCALL(getitimer)(long which, void *value) {}
457
458POST_SYSCALL(getitimer)(long res, long which, void *value) {
459  if (res >= 0) {
460    if (value)
461      POST_WRITE(value, struct_itimerval_sz);
462  }
463}
464
465PRE_SYSCALL(setitimer)(long which, void *value, void *ovalue) {}
466
467POST_SYSCALL(setitimer)(long res, long which, void *value, void *ovalue) {
468  if (res >= 0) {
469    if (value)
470      POST_WRITE(value, struct_itimerval_sz);
471    if (ovalue)
472      POST_WRITE(ovalue, struct_itimerval_sz);
473  }
474}
475
476PRE_SYSCALL(timer_create)
477(long which_clock, void *timer_event_spec, void *created_timer_id) {}
478
479POST_SYSCALL(timer_create)
480(long res, long which_clock, void *timer_event_spec, void *created_timer_id) {
481  if (res >= 0) {
482    if (timer_event_spec)
483      POST_WRITE(timer_event_spec, struct_sigevent_sz);
484    if (created_timer_id)
485      POST_WRITE(created_timer_id, sizeof(long));
486  }
487}
488
489PRE_SYSCALL(timer_gettime)(long timer_id, void *setting) {}
490
491POST_SYSCALL(timer_gettime)(long res, long timer_id, void *setting) {
492  if (res >= 0) {
493    if (setting)
494      POST_WRITE(setting, struct_itimerspec_sz);
495  }
496}
497
498PRE_SYSCALL(timer_getoverrun)(long timer_id) {}
499
500POST_SYSCALL(timer_getoverrun)(long res, long timer_id) {}
501
502PRE_SYSCALL(timer_settime)
503(long timer_id, long flags, const void *new_setting, void *old_setting) {
504  if (new_setting)
505    PRE_READ(new_setting, struct_itimerspec_sz);
506}
507
508POST_SYSCALL(timer_settime)
509(long res, long timer_id, long flags, const void *new_setting,
510 void *old_setting) {
511  if (res >= 0) {
512    if (old_setting)
513      POST_WRITE(old_setting, struct_itimerspec_sz);
514  }
515}
516
517PRE_SYSCALL(timer_delete)(long timer_id) {}
518
519POST_SYSCALL(timer_delete)(long res, long timer_id) {}
520
521PRE_SYSCALL(clock_settime)(long which_clock, const void *tp) {
522  if (tp)
523    PRE_READ(tp, struct_timespec_sz);
524}
525
526POST_SYSCALL(clock_settime)(long res, long which_clock, const void *tp) {}
527
528PRE_SYSCALL(clock_gettime)(long which_clock, void *tp) {}
529
530POST_SYSCALL(clock_gettime)(long res, long which_clock, void *tp) {
531  if (res >= 0) {
532    if (tp)
533      POST_WRITE(tp, struct_timespec_sz);
534  }
535}
536
537#  if !SANITIZER_ANDROID
538PRE_SYSCALL(clock_adjtime)(long which_clock, void *tx) {}
539
540POST_SYSCALL(clock_adjtime)(long res, long which_clock, void *tx) {
541  if (res >= 0) {
542    if (tx)
543      POST_WRITE(tx, struct_timex_sz);
544  }
545}
546#  endif
547
548PRE_SYSCALL(clock_getres)(long which_clock, void *tp) {}
549
550POST_SYSCALL(clock_getres)(long res, long which_clock, void *tp) {
551  if (res >= 0) {
552    if (tp)
553      POST_WRITE(tp, struct_timespec_sz);
554  }
555}
556
557PRE_SYSCALL(clock_nanosleep)
558(long which_clock, long flags, const void *rqtp, void *rmtp) {
559  if (rqtp)
560    PRE_READ(rqtp, struct_timespec_sz);
561}
562
563POST_SYSCALL(clock_nanosleep)
564(long res, long which_clock, long flags, const void *rqtp, void *rmtp) {
565  if (res >= 0) {
566    if (rmtp)
567      POST_WRITE(rmtp, struct_timespec_sz);
568  }
569}
570
571PRE_SYSCALL(nice)(long increment) {}
572
573POST_SYSCALL(nice)(long res, long increment) {}
574
575PRE_SYSCALL(sched_setscheduler)(long pid, long policy, void *param) {}
576
577POST_SYSCALL(sched_setscheduler)(long res, long pid, long policy, void *param) {
578  if (res >= 0) {
579    if (param)
580      POST_WRITE(param, struct_sched_param_sz);
581  }
582}
583
584PRE_SYSCALL(sched_setparam)(long pid, void *param) {
585  if (param)
586    PRE_READ(param, struct_sched_param_sz);
587}
588
589POST_SYSCALL(sched_setparam)(long res, long pid, void *param) {}
590
591PRE_SYSCALL(sched_getscheduler)(long pid) {}
592
593POST_SYSCALL(sched_getscheduler)(long res, long pid) {}
594
595PRE_SYSCALL(sched_getparam)(long pid, void *param) {}
596
597POST_SYSCALL(sched_getparam)(long res, long pid, void *param) {
598  if (res >= 0) {
599    if (param)
600      POST_WRITE(param, struct_sched_param_sz);
601  }
602}
603
604PRE_SYSCALL(sched_setaffinity)(long pid, long len, void *user_mask_ptr) {
605  if (user_mask_ptr)
606    PRE_READ(user_mask_ptr, len);
607}
608
609POST_SYSCALL(sched_setaffinity)
610(long res, long pid, long len, void *user_mask_ptr) {}
611
612PRE_SYSCALL(sched_getaffinity)(long pid, long len, void *user_mask_ptr) {}
613
614POST_SYSCALL(sched_getaffinity)
615(long res, long pid, long len, void *user_mask_ptr) {
616  if (res >= 0) {
617    if (user_mask_ptr)
618      POST_WRITE(user_mask_ptr, len);
619  }
620}
621
622PRE_SYSCALL(sched_yield)() {}
623
624POST_SYSCALL(sched_yield)(long res) {}
625
626PRE_SYSCALL(sched_get_priority_max)(long policy) {}
627
628POST_SYSCALL(sched_get_priority_max)(long res, long policy) {}
629
630PRE_SYSCALL(sched_get_priority_min)(long policy) {}
631
632POST_SYSCALL(sched_get_priority_min)(long res, long policy) {}
633
634PRE_SYSCALL(sched_rr_get_interval)(long pid, void *interval) {}
635
636POST_SYSCALL(sched_rr_get_interval)(long res, long pid, void *interval) {
637  if (res >= 0) {
638    if (interval)
639      POST_WRITE(interval, struct_timespec_sz);
640  }
641}
642
643PRE_SYSCALL(setpriority)(long which, long who, long niceval) {}
644
645POST_SYSCALL(setpriority)(long res, long which, long who, long niceval) {}
646
647PRE_SYSCALL(getpriority)(long which, long who) {}
648
649POST_SYSCALL(getpriority)(long res, long which, long who) {}
650
651PRE_SYSCALL(shutdown)(long arg0, long arg1) {}
652
653POST_SYSCALL(shutdown)(long res, long arg0, long arg1) {}
654
655PRE_SYSCALL(reboot)(long magic1, long magic2, long cmd, void *arg) {}
656
657POST_SYSCALL(reboot)(long res, long magic1, long magic2, long cmd, void *arg) {}
658
659PRE_SYSCALL(restart_syscall)() {}
660
661POST_SYSCALL(restart_syscall)(long res) {}
662
663PRE_SYSCALL(kexec_load)
664(long entry, long nr_segments, void *segments, long flags) {}
665
666POST_SYSCALL(kexec_load)
667(long res, long entry, long nr_segments, void *segments, long flags) {
668  if (res >= 0) {
669    if (segments)
670      POST_WRITE(segments, struct_kexec_segment_sz);
671  }
672}
673
674PRE_SYSCALL(exit)(long error_code) {}
675
676POST_SYSCALL(exit)(long res, long error_code) {}
677
678PRE_SYSCALL(exit_group)(long error_code) {}
679
680POST_SYSCALL(exit_group)(long res, long error_code) {}
681
682PRE_SYSCALL(wait4)(long pid, void *stat_addr, long options, void *ru) {}
683
684POST_SYSCALL(wait4)
685(long res, long pid, void *stat_addr, long options, void *ru) {
686  if (res >= 0) {
687    if (stat_addr)
688      POST_WRITE(stat_addr, sizeof(int));
689    if (ru)
690      POST_WRITE(ru, struct_rusage_sz);
691  }
692}
693
694PRE_SYSCALL(waitid)
695(long which, long pid, void *infop, long options, void *ru) {}
696
697POST_SYSCALL(waitid)
698(long res, long which, long pid, void *infop, long options, void *ru) {
699  if (res >= 0) {
700    if (infop)
701      POST_WRITE(infop, siginfo_t_sz);
702    if (ru)
703      POST_WRITE(ru, struct_rusage_sz);
704  }
705}
706
707PRE_SYSCALL(waitpid)(long pid, void *stat_addr, long options) {}
708
709POST_SYSCALL(waitpid)(long res, long pid, void *stat_addr, long options) {
710  if (res >= 0) {
711    if (stat_addr)
712      POST_WRITE(stat_addr, sizeof(int));
713  }
714}
715
716PRE_SYSCALL(set_tid_address)(void *tidptr) {}
717
718POST_SYSCALL(set_tid_address)(long res, void *tidptr) {
719  if (res >= 0) {
720    if (tidptr)
721      POST_WRITE(tidptr, sizeof(int));
722  }
723}
724
725PRE_SYSCALL(init_module)(void *umod, long len, const void *uargs) {
726  if (uargs)
727    PRE_READ(uargs, __sanitizer::internal_strlen((const char *)uargs) + 1);
728}
729
730POST_SYSCALL(init_module)(long res, void *umod, long len, const void *uargs) {}
731
732PRE_SYSCALL(delete_module)(const void *name_user, long flags) {
733  if (name_user)
734    PRE_READ(name_user,
735             __sanitizer::internal_strlen((const char *)name_user) + 1);
736}
737
738POST_SYSCALL(delete_module)(long res, const void *name_user, long flags) {}
739
740PRE_SYSCALL(rt_sigprocmask)(long how, void *set, void *oset, long sigsetsize) {}
741
742POST_SYSCALL(rt_sigprocmask)
743(long res, long how, kernel_sigset_t *set, kernel_sigset_t *oset,
744 long sigsetsize) {
745  if (res >= 0) {
746    if (set)
747      POST_WRITE(set, sigsetsize);
748    if (oset)
749      POST_WRITE(oset, sigsetsize);
750  }
751}
752
753PRE_SYSCALL(rt_sigpending)(void *set, long sigsetsize) {}
754
755POST_SYSCALL(rt_sigpending)(long res, kernel_sigset_t *set, long sigsetsize) {
756  if (res >= 0) {
757    if (set)
758      POST_WRITE(set, sigsetsize);
759  }
760}
761
762PRE_SYSCALL(rt_sigtimedwait)
763(const kernel_sigset_t *uthese, void *uinfo, const void *uts, long sigsetsize) {
764  if (uthese)
765    PRE_READ(uthese, sigsetsize);
766  if (uts)
767    PRE_READ(uts, struct_timespec_sz);
768}
769
770POST_SYSCALL(rt_sigtimedwait)
771(long res, const void *uthese, void *uinfo, const void *uts, long sigsetsize) {
772  if (res >= 0) {
773    if (uinfo)
774      POST_WRITE(uinfo, siginfo_t_sz);
775  }
776}
777
778PRE_SYSCALL(rt_tgsigqueueinfo)(long tgid, long pid, long sig, void *uinfo) {}
779
780POST_SYSCALL(rt_tgsigqueueinfo)
781(long res, long tgid, long pid, long sig, void *uinfo) {
782  if (res >= 0) {
783    if (uinfo)
784      POST_WRITE(uinfo, siginfo_t_sz);
785  }
786}
787
788PRE_SYSCALL(kill)(long pid, long sig) {}
789
790POST_SYSCALL(kill)(long res, long pid, long sig) {}
791
792PRE_SYSCALL(tgkill)(long tgid, long pid, long sig) {}
793
794POST_SYSCALL(tgkill)(long res, long tgid, long pid, long sig) {}
795
796PRE_SYSCALL(tkill)(long pid, long sig) {}
797
798POST_SYSCALL(tkill)(long res, long pid, long sig) {}
799
800PRE_SYSCALL(rt_sigqueueinfo)(long pid, long sig, void *uinfo) {}
801
802POST_SYSCALL(rt_sigqueueinfo)(long res, long pid, long sig, void *uinfo) {
803  if (res >= 0) {
804    if (uinfo)
805      POST_WRITE(uinfo, siginfo_t_sz);
806  }
807}
808
809PRE_SYSCALL(sgetmask)() {}
810
811POST_SYSCALL(sgetmask)(long res) {}
812
813PRE_SYSCALL(ssetmask)(long newmask) {}
814
815POST_SYSCALL(ssetmask)(long res, long newmask) {}
816
817PRE_SYSCALL(signal)(long sig, long handler) {}
818
819POST_SYSCALL(signal)(long res, long sig, long handler) {}
820
821PRE_SYSCALL(pause)() {}
822
823POST_SYSCALL(pause)(long res) {}
824
825PRE_SYSCALL(sync)() {}
826
827POST_SYSCALL(sync)(long res) {}
828
829PRE_SYSCALL(fsync)(long fd) {}
830
831POST_SYSCALL(fsync)(long res, long fd) {}
832
833PRE_SYSCALL(fdatasync)(long fd) {}
834
835POST_SYSCALL(fdatasync)(long res, long fd) {}
836
837PRE_SYSCALL(bdflush)(long func, long data) {}
838
839POST_SYSCALL(bdflush)(long res, long func, long data) {}
840
841PRE_SYSCALL(mount)
842(void *dev_name, void *dir_name, void *type, long flags, void *data) {}
843
844POST_SYSCALL(mount)
845(long res, void *dev_name, void *dir_name, void *type, long flags, void *data) {
846  if (res >= 0) {
847    if (dev_name)
848      POST_WRITE(dev_name,
849                 __sanitizer::internal_strlen((const char *)dev_name) + 1);
850    if (dir_name)
851      POST_WRITE(dir_name,
852                 __sanitizer::internal_strlen((const char *)dir_name) + 1);
853    if (type)
854      POST_WRITE(type, __sanitizer::internal_strlen((const char *)type) + 1);
855  }
856}
857
858PRE_SYSCALL(umount)(void *name, long flags) {}
859
860POST_SYSCALL(umount)(long res, void *name, long flags) {
861  if (res >= 0) {
862    if (name)
863      POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
864  }
865}
866
867PRE_SYSCALL(oldumount)(void *name) {}
868
869POST_SYSCALL(oldumount)(long res, void *name) {
870  if (res >= 0) {
871    if (name)
872      POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
873  }
874}
875
876PRE_SYSCALL(truncate)(const void *path, long length) {
877  if (path)
878    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
879}
880
881POST_SYSCALL(truncate)(long res, const void *path, long length) {}
882
883PRE_SYSCALL(ftruncate)(long fd, long length) {}
884
885POST_SYSCALL(ftruncate)(long res, long fd, long length) {}
886
887PRE_SYSCALL(stat)(const void *filename, void *statbuf) {
888  if (filename)
889    PRE_READ(filename,
890             __sanitizer::internal_strlen((const char *)filename) + 1);
891}
892
893POST_SYSCALL(stat)(long res, const void *filename, void *statbuf) {
894  if (res >= 0) {
895    if (statbuf)
896      POST_WRITE(statbuf, struct___old_kernel_stat_sz);
897  }
898}
899
900#  if !SANITIZER_ANDROID
901PRE_SYSCALL(statfs)(const void *path, void *buf) {
902  if (path)
903    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
904}
905
906POST_SYSCALL(statfs)(long res, const void *path, void *buf) {
907  if (res >= 0) {
908    if (buf)
909      POST_WRITE(buf, struct_statfs_sz);
910  }
911}
912
913PRE_SYSCALL(fstatfs)(long fd, void *buf) {}
914
915POST_SYSCALL(fstatfs)(long res, long fd, void *buf) {
916  if (res >= 0) {
917    if (buf)
918      POST_WRITE(buf, struct_statfs_sz);
919  }
920}
921#  endif  // !SANITIZER_ANDROID
922
923#  if SANITIZER_GLIBC
924PRE_SYSCALL(statfs64)(const void *path, long sz, void *buf) {
925  if (path)
926    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
927}
928
929POST_SYSCALL(statfs64)(long res, const void *path, long sz, void *buf) {
930  if (res >= 0) {
931    if (buf)
932      POST_WRITE(buf, struct_statfs64_sz);
933  }
934}
935
936PRE_SYSCALL(fstatfs64)(long fd, long sz, void *buf) {}
937
938POST_SYSCALL(fstatfs64)(long res, long fd, long sz, void *buf) {
939  if (res >= 0) {
940    if (buf)
941      POST_WRITE(buf, struct_statfs64_sz);
942  }
943}
944#  endif  // SANITIZER_GLIBC
945
946PRE_SYSCALL(lstat)(const void *filename, void *statbuf) {
947  if (filename)
948    PRE_READ(filename,
949             __sanitizer::internal_strlen((const char *)filename) + 1);
950}
951
952POST_SYSCALL(lstat)(long res, const void *filename, void *statbuf) {
953  if (res >= 0) {
954    if (statbuf)
955      POST_WRITE(statbuf, struct___old_kernel_stat_sz);
956  }
957}
958
959PRE_SYSCALL(fstat)(long fd, void *statbuf) {}
960
961POST_SYSCALL(fstat)(long res, long fd, void *statbuf) {
962  if (res >= 0) {
963    if (statbuf)
964      POST_WRITE(statbuf, struct___old_kernel_stat_sz);
965  }
966}
967
968PRE_SYSCALL(newstat)(const void *filename, void *statbuf) {
969  if (filename)
970    PRE_READ(filename,
971             __sanitizer::internal_strlen((const char *)filename) + 1);
972}
973
974POST_SYSCALL(newstat)(long res, const void *filename, void *statbuf) {
975  if (res >= 0) {
976    if (statbuf)
977      POST_WRITE(statbuf, struct_kernel_stat_sz);
978  }
979}
980
981PRE_SYSCALL(newlstat)(const void *filename, void *statbuf) {
982  if (filename)
983    PRE_READ(filename,
984             __sanitizer::internal_strlen((const char *)filename) + 1);
985}
986
987POST_SYSCALL(newlstat)(long res, const void *filename, void *statbuf) {
988  if (res >= 0) {
989    if (statbuf)
990      POST_WRITE(statbuf, struct_kernel_stat_sz);
991  }
992}
993
994PRE_SYSCALL(newfstat)(long fd, void *statbuf) {}
995
996POST_SYSCALL(newfstat)(long res, long fd, void *statbuf) {
997  if (res >= 0) {
998    if (statbuf)
999      POST_WRITE(statbuf, struct_kernel_stat_sz);
1000  }
1001}
1002
1003#  if SANITIZER_GLIBC
1004PRE_SYSCALL(ustat)(long dev, void *ubuf) {}
1005
1006POST_SYSCALL(ustat)(long res, long dev, void *ubuf) {
1007  if (res >= 0) {
1008    if (ubuf)
1009      POST_WRITE(ubuf, struct_ustat_sz);
1010  }
1011}
1012#  endif  // SANITIZER_GLIBC
1013
1014PRE_SYSCALL(stat64)(const void *filename, void *statbuf) {
1015  if (filename)
1016    PRE_READ(filename,
1017             __sanitizer::internal_strlen((const char *)filename) + 1);
1018}
1019
1020POST_SYSCALL(stat64)(long res, const void *filename, void *statbuf) {
1021  if (res >= 0) {
1022    if (statbuf)
1023      POST_WRITE(statbuf, struct_kernel_stat64_sz);
1024  }
1025}
1026
1027PRE_SYSCALL(fstat64)(long fd, void *statbuf) {}
1028
1029POST_SYSCALL(fstat64)(long res, long fd, void *statbuf) {
1030  if (res >= 0) {
1031    if (statbuf)
1032      POST_WRITE(statbuf, struct_kernel_stat64_sz);
1033  }
1034}
1035
1036PRE_SYSCALL(lstat64)(const void *filename, void *statbuf) {
1037  if (filename)
1038    PRE_READ(filename,
1039             __sanitizer::internal_strlen((const char *)filename) + 1);
1040}
1041
1042POST_SYSCALL(lstat64)(long res, const void *filename, void *statbuf) {
1043  if (res >= 0) {
1044    if (statbuf)
1045      POST_WRITE(statbuf, struct_kernel_stat64_sz);
1046  }
1047}
1048
1049PRE_SYSCALL(setxattr)
1050(const void *path, const void *name, const void *value, long size, long flags) {
1051  if (path)
1052    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
1053  if (name)
1054    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
1055  if (value)
1056    PRE_READ(value, size);
1057}
1058
1059POST_SYSCALL(setxattr)
1060(long res, const void *path, const void *name, const void *value, long size,
1061 long flags) {}
1062
1063PRE_SYSCALL(lsetxattr)
1064(const void *path, const void *name, const void *value, long size, long flags) {
1065  if (path)
1066    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
1067  if (name)
1068    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
1069  if (value)
1070    PRE_READ(value, size);
1071}
1072
1073POST_SYSCALL(lsetxattr)
1074(long res, const void *path, const void *name, const void *value, long size,
1075 long flags) {}
1076
1077PRE_SYSCALL(fsetxattr)
1078(long fd, const void *name, const void *value, long size, long flags) {
1079  if (name)
1080    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
1081  if (value)
1082    PRE_READ(value, size);
1083}
1084
1085POST_SYSCALL(fsetxattr)
1086(long res, long fd, const void *name, const void *value, long size,
1087 long flags) {}
1088
1089PRE_SYSCALL(getxattr)
1090(const void *path, const void *name, void *value, long size) {
1091  if (path)
1092    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
1093  if (name)
1094    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
1095}
1096
1097POST_SYSCALL(getxattr)
1098(long res, const void *path, const void *name, void *value, long size) {
1099  if (size && res > 0) {
1100    if (value)
1101      POST_WRITE(value, res);
1102  }
1103}
1104
1105PRE_SYSCALL(lgetxattr)
1106(const void *path, const void *name, void *value, long size) {
1107  if (path)
1108    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
1109  if (name)
1110    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
1111}
1112
1113POST_SYSCALL(lgetxattr)
1114(long res, const void *path, const void *name, void *value, long size) {
1115  if (size && res > 0) {
1116    if (value)
1117      POST_WRITE(value, res);
1118  }
1119}
1120
1121PRE_SYSCALL(fgetxattr)(long fd, const void *name, void *value, long size) {
1122  if (name)
1123    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
1124}
1125
1126POST_SYSCALL(fgetxattr)
1127(long res, long fd, const void *name, void *value, long size) {
1128  if (size && res > 0) {
1129    if (value)
1130      POST_WRITE(value, res);
1131  }
1132}
1133
1134PRE_SYSCALL(listxattr)(const void *path, void *list, long size) {
1135  if (path)
1136    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
1137}
1138
1139POST_SYSCALL(listxattr)(long res, const void *path, void *list, long size) {
1140  if (size && res > 0) {
1141    if (list)
1142      POST_WRITE(list, res);
1143  }
1144}
1145
1146PRE_SYSCALL(llistxattr)(const void *path, void *list, long size) {
1147  if (path)
1148    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
1149}
1150
1151POST_SYSCALL(llistxattr)(long res, const void *path, void *list, long size) {
1152  if (size && res > 0) {
1153    if (list)
1154      POST_WRITE(list, res);
1155  }
1156}
1157
1158PRE_SYSCALL(flistxattr)(long fd, void *list, long size) {}
1159
1160POST_SYSCALL(flistxattr)(long res, long fd, void *list, long size) {
1161  if (size && res > 0) {
1162    if (list)
1163      POST_WRITE(list, res);
1164  }
1165}
1166
1167PRE_SYSCALL(removexattr)(const void *path, const void *name) {
1168  if (path)
1169    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
1170  if (name)
1171    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
1172}
1173
1174POST_SYSCALL(removexattr)(long res, const void *path, const void *name) {}
1175
1176PRE_SYSCALL(lremovexattr)(const void *path, const void *name) {
1177  if (path)
1178    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
1179  if (name)
1180    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
1181}
1182
1183POST_SYSCALL(lremovexattr)(long res, const void *path, const void *name) {}
1184
1185PRE_SYSCALL(fremovexattr)(long fd, const void *name) {
1186  if (name)
1187    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
1188}
1189
1190POST_SYSCALL(fremovexattr)(long res, long fd, const void *name) {}
1191
1192PRE_SYSCALL(brk)(long brk) {}
1193
1194POST_SYSCALL(brk)(long res, long brk) {}
1195
1196PRE_SYSCALL(mprotect)(long start, long len, long prot) {}
1197
1198POST_SYSCALL(mprotect)(long res, long start, long len, long prot) {}
1199
1200PRE_SYSCALL(mremap)
1201(long addr, long old_len, long new_len, long flags, long new_addr) {}
1202
1203POST_SYSCALL(mremap)
1204(long res, long addr, long old_len, long new_len, long flags, long new_addr) {}
1205
1206PRE_SYSCALL(remap_file_pages)
1207(long start, long size, long prot, long pgoff, long flags) {}
1208
1209POST_SYSCALL(remap_file_pages)
1210(long res, long start, long size, long prot, long pgoff, long flags) {}
1211
1212PRE_SYSCALL(msync)(long start, long len, long flags) {}
1213
1214POST_SYSCALL(msync)(long res, long start, long len, long flags) {}
1215
1216PRE_SYSCALL(munmap)(long addr, long len) {}
1217
1218POST_SYSCALL(munmap)(long res, long addr, long len) {}
1219
1220PRE_SYSCALL(mlock)(long start, long len) {}
1221
1222POST_SYSCALL(mlock)(long res, long start, long len) {}
1223
1224PRE_SYSCALL(munlock)(long start, long len) {}
1225
1226POST_SYSCALL(munlock)(long res, long start, long len) {}
1227
1228PRE_SYSCALL(mlockall)(long flags) {}
1229
1230POST_SYSCALL(mlockall)(long res, long flags) {}
1231
1232PRE_SYSCALL(munlockall)() {}
1233
1234POST_SYSCALL(munlockall)(long res) {}
1235
1236PRE_SYSCALL(madvise)(long start, long len, long behavior) {}
1237
1238POST_SYSCALL(madvise)(long res, long start, long len, long behavior) {}
1239
1240PRE_SYSCALL(mincore)(long start, long len, void *vec) {}
1241
1242POST_SYSCALL(mincore)(long res, long start, long len, void *vec) {
1243  if (res >= 0) {
1244    if (vec) {
1245      POST_WRITE(vec, (len + GetPageSizeCached() - 1) / GetPageSizeCached());
1246    }
1247  }
1248}
1249
1250PRE_SYSCALL(pivot_root)(const void *new_root, const void *put_old) {
1251  if (new_root)
1252    PRE_READ(new_root,
1253             __sanitizer::internal_strlen((const char *)new_root) + 1);
1254  if (put_old)
1255    PRE_READ(put_old, __sanitizer::internal_strlen((const char *)put_old) + 1);
1256}
1257
1258POST_SYSCALL(pivot_root)(long res, const void *new_root, const void *put_old) {}
1259
1260PRE_SYSCALL(chroot)(const void *filename) {
1261  if (filename)
1262    PRE_READ(filename,
1263             __sanitizer::internal_strlen((const char *)filename) + 1);
1264}
1265
1266POST_SYSCALL(chroot)(long res, const void *filename) {}
1267
1268PRE_SYSCALL(mknod)(const void *filename, long mode, long dev) {
1269  if (filename)
1270    PRE_READ(filename,
1271             __sanitizer::internal_strlen((const char *)filename) + 1);
1272}
1273
1274POST_SYSCALL(mknod)(long res, const void *filename, long mode, long dev) {}
1275
1276PRE_SYSCALL(link)(const void *oldname, const void *newname) {
1277  if (oldname)
1278    PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
1279  if (newname)
1280    PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
1281}
1282
1283POST_SYSCALL(link)(long res, const void *oldname, const void *newname) {}
1284
1285PRE_SYSCALL(symlink)(const void *old, const void *new_) {
1286  if (old)
1287    PRE_READ(old, __sanitizer::internal_strlen((const char *)old) + 1);
1288  if (new_)
1289    PRE_READ(new_, __sanitizer::internal_strlen((const char *)new_) + 1);
1290}
1291
1292POST_SYSCALL(symlink)(long res, const void *old, const void *new_) {}
1293
1294PRE_SYSCALL(unlink)(const void *pathname) {
1295  if (pathname)
1296    PRE_READ(pathname,
1297             __sanitizer::internal_strlen((const char *)pathname) + 1);
1298}
1299
1300POST_SYSCALL(unlink)(long res, const void *pathname) {}
1301
1302PRE_SYSCALL(rename)(const void *oldname, const void *newname) {
1303  if (oldname)
1304    PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
1305  if (newname)
1306    PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
1307}
1308
1309POST_SYSCALL(rename)(long res, const void *oldname, const void *newname) {}
1310
1311PRE_SYSCALL(chmod)(const void *filename, long mode) {
1312  if (filename)
1313    PRE_READ(filename,
1314             __sanitizer::internal_strlen((const char *)filename) + 1);
1315}
1316
1317POST_SYSCALL(chmod)(long res, const void *filename, long mode) {}
1318
1319PRE_SYSCALL(fchmod)(long fd, long mode) {}
1320
1321POST_SYSCALL(fchmod)(long res, long fd, long mode) {}
1322
1323PRE_SYSCALL(fcntl)(long fd, long cmd, long arg) {}
1324
1325POST_SYSCALL(fcntl)(long res, long fd, long cmd, long arg) {}
1326
1327PRE_SYSCALL(fcntl64)(long fd, long cmd, long arg) {}
1328
1329POST_SYSCALL(fcntl64)(long res, long fd, long cmd, long arg) {}
1330
1331PRE_SYSCALL(pipe)(void *fildes) {}
1332
1333POST_SYSCALL(pipe)(long res, void *fildes) {
1334  if (res >= 0)
1335    if (fildes)
1336      POST_WRITE(fildes, sizeof(int) * 2);
1337}
1338
1339PRE_SYSCALL(pipe2)(void *fildes, long flags) {}
1340
1341POST_SYSCALL(pipe2)(long res, void *fildes, long flags) {
1342  if (res >= 0)
1343    if (fildes)
1344      POST_WRITE(fildes, sizeof(int) * 2);
1345}
1346
1347PRE_SYSCALL(dup)(long fildes) {}
1348
1349POST_SYSCALL(dup)(long res, long fildes) {}
1350
1351PRE_SYSCALL(dup2)(long oldfd, long newfd) {}
1352
1353POST_SYSCALL(dup2)(long res, long oldfd, long newfd) {}
1354
1355PRE_SYSCALL(dup3)(long oldfd, long newfd, long flags) {}
1356
1357POST_SYSCALL(dup3)(long res, long oldfd, long newfd, long flags) {}
1358
1359PRE_SYSCALL(ioperm)(long from, long num, long on) {}
1360
1361POST_SYSCALL(ioperm)(long res, long from, long num, long on) {}
1362
1363PRE_SYSCALL(ioctl)(long fd, long cmd, long arg) {}
1364
1365POST_SYSCALL(ioctl)(long res, long fd, long cmd, long arg) {}
1366
1367PRE_SYSCALL(flock)(long fd, long cmd) {}
1368
1369POST_SYSCALL(flock)(long res, long fd, long cmd) {}
1370
1371PRE_SYSCALL(io_setup)(long nr_reqs, void **ctx) {
1372  if (ctx)
1373    PRE_WRITE(ctx, sizeof(*ctx));
1374}
1375
1376POST_SYSCALL(io_setup)(long res, long nr_reqs, void **ctx) {
1377  if (res >= 0) {
1378    if (ctx)
1379      POST_WRITE(ctx, sizeof(*ctx));
1380    // (*ctx) is actually a pointer to a kernel mapped page, and there are
1381    // people out there who are crazy enough to peek into that page's 32-byte
1382    // header.
1383    if (*ctx)
1384      POST_WRITE(*ctx, 32);
1385  }
1386}
1387
1388PRE_SYSCALL(io_destroy)(long ctx) {}
1389
1390POST_SYSCALL(io_destroy)(long res, long ctx) {}
1391
1392PRE_SYSCALL(io_getevents)
1393(long ctx_id, long min_nr, long nr, __sanitizer_io_event *ioevpp,
1394 void *timeout) {
1395  if (timeout)
1396    PRE_READ(timeout, struct_timespec_sz);
1397}
1398
1399POST_SYSCALL(io_getevents)
1400(long res, long ctx_id, long min_nr, long nr, __sanitizer_io_event *ioevpp,
1401 void *timeout) {
1402  if (res >= 0) {
1403    if (ioevpp)
1404      POST_WRITE(ioevpp, res * sizeof(*ioevpp));
1405    if (timeout)
1406      POST_WRITE(timeout, struct_timespec_sz);
1407  }
1408  for (long i = 0; i < res; i++) {
1409    // We synchronize io_submit -> io_getevents/io_cancel using the
1410    // user-provided data context. Data is not necessary a pointer, it can be
1411    // an int, 0 or whatever; acquire/release will correctly handle this.
1412    // This scheme can lead to false negatives, e.g. when all operations
1413    // synchronize on 0. But there does not seem to be a better solution
1414    // (except wrapping all operations in own context, which is unreliable).
1415    // We can not reliably extract fildes in io_getevents.
1416    COMMON_SYSCALL_ACQUIRE((void *)ioevpp[i].data);
1417  }
1418}
1419
1420PRE_SYSCALL(io_submit)(long ctx_id, long nr, __sanitizer_iocb **iocbpp) {
1421  for (long i = 0; i < nr; ++i) {
1422    uptr op = iocbpp[i]->aio_lio_opcode;
1423    void *data = (void *)iocbpp[i]->aio_data;
1424    void *buf = (void *)iocbpp[i]->aio_buf;
1425    uptr len = (uptr)iocbpp[i]->aio_nbytes;
1426    if (op == iocb_cmd_pwrite && buf && len) {
1427      PRE_READ(buf, len);
1428    } else if (op == iocb_cmd_pread && buf && len) {
1429      POST_WRITE(buf, len);
1430    } else if (op == iocb_cmd_pwritev) {
1431      __sanitizer_iovec *iovec = (__sanitizer_iovec *)buf;
1432      for (uptr v = 0; v < len; v++)
1433        PRE_READ(iovec[v].iov_base, iovec[v].iov_len);
1434    } else if (op == iocb_cmd_preadv) {
1435      __sanitizer_iovec *iovec = (__sanitizer_iovec *)buf;
1436      for (uptr v = 0; v < len; v++)
1437        POST_WRITE(iovec[v].iov_base, iovec[v].iov_len);
1438    }
1439    // See comment in io_getevents.
1440    COMMON_SYSCALL_RELEASE(data);
1441  }
1442}
1443
1444POST_SYSCALL(io_submit)
1445(long res, long ctx_id, long nr, __sanitizer_iocb **iocbpp) {}
1446
1447PRE_SYSCALL(io_cancel)
1448(long ctx_id, __sanitizer_iocb *iocb, __sanitizer_io_event *result) {}
1449
1450POST_SYSCALL(io_cancel)
1451(long res, long ctx_id, __sanitizer_iocb *iocb, __sanitizer_io_event *result) {
1452  if (res == 0) {
1453    if (result) {
1454      // See comment in io_getevents.
1455      COMMON_SYSCALL_ACQUIRE((void *)result->data);
1456      POST_WRITE(result, sizeof(*result));
1457    }
1458    if (iocb)
1459      POST_WRITE(iocb, sizeof(*iocb));
1460  }
1461}
1462
1463PRE_SYSCALL(sendfile)(long out_fd, long in_fd, void *offset, long count) {}
1464
1465POST_SYSCALL(sendfile)
1466(long res, long out_fd, long in_fd, __sanitizer___kernel_off_t *offset,
1467 long count) {
1468  if (res >= 0) {
1469    if (offset)
1470      POST_WRITE(offset, sizeof(*offset));
1471  }
1472}
1473
1474PRE_SYSCALL(sendfile64)(long out_fd, long in_fd, void *offset, long count) {}
1475
1476POST_SYSCALL(sendfile64)
1477(long res, long out_fd, long in_fd, __sanitizer___kernel_loff_t *offset,
1478 long count) {
1479  if (res >= 0) {
1480    if (offset)
1481      POST_WRITE(offset, sizeof(*offset));
1482  }
1483}
1484
1485PRE_SYSCALL(readlink)(const void *path, void *buf, long bufsiz) {
1486  if (path)
1487    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
1488}
1489
1490POST_SYSCALL(readlink)(long res, const void *path, void *buf, long bufsiz) {
1491  if (res >= 0) {
1492    if (buf)
1493      POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
1494  }
1495}
1496
1497PRE_SYSCALL(creat)(const void *pathname, long mode) {
1498  if (pathname)
1499    PRE_READ(pathname,
1500             __sanitizer::internal_strlen((const char *)pathname) + 1);
1501}
1502
1503POST_SYSCALL(creat)(long res, const void *pathname, long mode) {}
1504
1505PRE_SYSCALL(open)(const void *filename, long flags, long mode) {
1506  if (filename)
1507    PRE_READ(filename,
1508             __sanitizer::internal_strlen((const char *)filename) + 1);
1509}
1510
1511POST_SYSCALL(open)(long res, const void *filename, long flags, long mode) {}
1512
1513PRE_SYSCALL(close)(long fd) { COMMON_SYSCALL_FD_CLOSE((int)fd); }
1514
1515POST_SYSCALL(close)(long res, long fd) {}
1516
1517PRE_SYSCALL(access)(const void *filename, long mode) {
1518  if (filename)
1519    PRE_READ(filename,
1520             __sanitizer::internal_strlen((const char *)filename) + 1);
1521}
1522
1523POST_SYSCALL(access)(long res, const void *filename, long mode) {}
1524
1525PRE_SYSCALL(vhangup)() {}
1526
1527POST_SYSCALL(vhangup)(long res) {}
1528
1529PRE_SYSCALL(chown)(const void *filename, long user, long group) {
1530  if (filename)
1531    PRE_READ(filename,
1532             __sanitizer::internal_strlen((const char *)filename) + 1);
1533}
1534
1535POST_SYSCALL(chown)(long res, const void *filename, long user, long group) {}
1536
1537PRE_SYSCALL(lchown)(const void *filename, long user, long group) {
1538  if (filename)
1539    PRE_READ(filename,
1540             __sanitizer::internal_strlen((const char *)filename) + 1);
1541}
1542
1543POST_SYSCALL(lchown)(long res, const void *filename, long user, long group) {}
1544
1545PRE_SYSCALL(fchown)(long fd, long user, long group) {}
1546
1547POST_SYSCALL(fchown)(long res, long fd, long user, long group) {}
1548
1549#  if SANITIZER_USES_UID16_SYSCALLS
1550PRE_SYSCALL(chown16)(const void *filename, long user, long group) {
1551  if (filename)
1552    PRE_READ(filename,
1553             __sanitizer::internal_strlen((const char *)filename) + 1);
1554}
1555
1556POST_SYSCALL(chown16)(long res, const void *filename, long user, long group) {}
1557
1558PRE_SYSCALL(lchown16)(const void *filename, long user, long group) {
1559  if (filename)
1560    PRE_READ(filename,
1561             __sanitizer::internal_strlen((const char *)filename) + 1);
1562}
1563
1564POST_SYSCALL(lchown16)(long res, const void *filename, long user, long group) {}
1565
1566PRE_SYSCALL(fchown16)(long fd, long user, long group) {}
1567
1568POST_SYSCALL(fchown16)(long res, long fd, long user, long group) {}
1569
1570PRE_SYSCALL(setregid16)(long rgid, long egid) {}
1571
1572POST_SYSCALL(setregid16)(long res, long rgid, long egid) {}
1573
1574PRE_SYSCALL(setgid16)(long gid) {}
1575
1576POST_SYSCALL(setgid16)(long res, long gid) {}
1577
1578PRE_SYSCALL(setreuid16)(long ruid, long euid) {}
1579
1580POST_SYSCALL(setreuid16)(long res, long ruid, long euid) {}
1581
1582PRE_SYSCALL(setuid16)(long uid) {}
1583
1584POST_SYSCALL(setuid16)(long res, long uid) {}
1585
1586PRE_SYSCALL(setresuid16)(long ruid, long euid, long suid) {}
1587
1588POST_SYSCALL(setresuid16)(long res, long ruid, long euid, long suid) {}
1589
1590PRE_SYSCALL(getresuid16)(void *ruid, void *euid, void *suid) {}
1591
1592POST_SYSCALL(getresuid16)
1593(long res, __sanitizer___kernel_old_uid_t *ruid,
1594 __sanitizer___kernel_old_uid_t *euid, __sanitizer___kernel_old_uid_t *suid) {
1595  if (res >= 0) {
1596    if (ruid)
1597      POST_WRITE(ruid, sizeof(*ruid));
1598    if (euid)
1599      POST_WRITE(euid, sizeof(*euid));
1600    if (suid)
1601      POST_WRITE(suid, sizeof(*suid));
1602  }
1603}
1604
1605PRE_SYSCALL(setresgid16)(long rgid, long egid, long sgid) {}
1606
1607POST_SYSCALL(setresgid16)(long res, long rgid, long egid, long sgid) {}
1608
1609PRE_SYSCALL(getresgid16)(void *rgid, void *egid, void *sgid) {}
1610
1611POST_SYSCALL(getresgid16)
1612(long res, __sanitizer___kernel_old_gid_t *rgid,
1613 __sanitizer___kernel_old_gid_t *egid, __sanitizer___kernel_old_gid_t *sgid) {
1614  if (res >= 0) {
1615    if (rgid)
1616      POST_WRITE(rgid, sizeof(*rgid));
1617    if (egid)
1618      POST_WRITE(egid, sizeof(*egid));
1619    if (sgid)
1620      POST_WRITE(sgid, sizeof(*sgid));
1621  }
1622}
1623
1624PRE_SYSCALL(setfsuid16)(long uid) {}
1625
1626POST_SYSCALL(setfsuid16)(long res, long uid) {}
1627
1628PRE_SYSCALL(setfsgid16)(long gid) {}
1629
1630POST_SYSCALL(setfsgid16)(long res, long gid) {}
1631
1632PRE_SYSCALL(getgroups16)
1633(long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {}
1634
1635POST_SYSCALL(getgroups16)
1636(long res, long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {
1637  if (res >= 0) {
1638    if (grouplist)
1639      POST_WRITE(grouplist, res * sizeof(*grouplist));
1640  }
1641}
1642
1643PRE_SYSCALL(setgroups16)
1644(long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {
1645  if (grouplist)
1646    POST_WRITE(grouplist, gidsetsize * sizeof(*grouplist));
1647}
1648
1649POST_SYSCALL(setgroups16)
1650(long res, long gidsetsize, __sanitizer___kernel_old_gid_t *grouplist) {}
1651
1652PRE_SYSCALL(getuid16)() {}
1653
1654POST_SYSCALL(getuid16)(long res) {}
1655
1656PRE_SYSCALL(geteuid16)() {}
1657
1658POST_SYSCALL(geteuid16)(long res) {}
1659
1660PRE_SYSCALL(getgid16)() {}
1661
1662POST_SYSCALL(getgid16)(long res) {}
1663
1664PRE_SYSCALL(getegid16)() {}
1665
1666POST_SYSCALL(getegid16)(long res) {}
1667#  endif  // SANITIZER_USES_UID16_SYSCALLS
1668
1669PRE_SYSCALL(utime)(void *filename, void *times) {}
1670
1671POST_SYSCALL(utime)(long res, void *filename, void *times) {
1672  if (res >= 0) {
1673    if (filename)
1674      POST_WRITE(filename,
1675                 __sanitizer::internal_strlen((const char *)filename) + 1);
1676    if (times)
1677      POST_WRITE(times, struct_utimbuf_sz);
1678  }
1679}
1680
1681PRE_SYSCALL(utimes)(void *filename, void *utimes) {}
1682
1683POST_SYSCALL(utimes)(long res, void *filename, void *utimes) {
1684  if (res >= 0) {
1685    if (filename)
1686      POST_WRITE(filename,
1687                 __sanitizer::internal_strlen((const char *)filename) + 1);
1688    if (utimes)
1689      POST_WRITE(utimes, timeval_sz);
1690  }
1691}
1692
1693PRE_SYSCALL(lseek)(long fd, long offset, long origin) {}
1694
1695POST_SYSCALL(lseek)(long res, long fd, long offset, long origin) {}
1696
1697PRE_SYSCALL(llseek)
1698(long fd, long offset_high, long offset_low, void *result, long origin) {}
1699
1700POST_SYSCALL(llseek)
1701(long res, long fd, long offset_high, long offset_low, void *result,
1702 long origin) {
1703  if (res >= 0) {
1704    if (result)
1705      POST_WRITE(result, sizeof(long long));
1706  }
1707}
1708
1709PRE_SYSCALL(readv)(long fd, const __sanitizer_iovec *vec, long vlen) {}
1710
1711POST_SYSCALL(readv)
1712(long res, long fd, const __sanitizer_iovec *vec, long vlen) {
1713  if (res >= 0) {
1714    if (vec)
1715      kernel_write_iovec(vec, vlen, res);
1716  }
1717}
1718
1719PRE_SYSCALL(write)(long fd, const void *buf, long count) {
1720  if (buf)
1721    PRE_READ(buf, count);
1722}
1723
1724POST_SYSCALL(write)(long res, long fd, const void *buf, long count) {}
1725
1726PRE_SYSCALL(writev)(long fd, const __sanitizer_iovec *vec, long vlen) {}
1727
1728POST_SYSCALL(writev)
1729(long res, long fd, const __sanitizer_iovec *vec, long vlen) {
1730  if (res >= 0) {
1731    if (vec)
1732      kernel_read_iovec(vec, vlen, res);
1733  }
1734}
1735
1736#  ifdef _LP64
1737PRE_SYSCALL(pread64)(long fd, void *buf, long count, long pos) {}
1738
1739POST_SYSCALL(pread64)(long res, long fd, void *buf, long count, long pos) {
1740  if (res >= 0) {
1741    if (buf)
1742      POST_WRITE(buf, res);
1743  }
1744}
1745
1746PRE_SYSCALL(pwrite64)(long fd, const void *buf, long count, long pos) {
1747  if (buf)
1748    PRE_READ(buf, count);
1749}
1750
1751POST_SYSCALL(pwrite64)
1752(long res, long fd, const void *buf, long count, long pos) {}
1753#  else
1754PRE_SYSCALL(pread64)(long fd, void *buf, long count, long pos0, long pos1) {}
1755
1756POST_SYSCALL(pread64)
1757(long res, long fd, void *buf, long count, long pos0, long pos1) {
1758  if (res >= 0) {
1759    if (buf)
1760      POST_WRITE(buf, res);
1761  }
1762}
1763
1764PRE_SYSCALL(pwrite64)
1765(long fd, const void *buf, long count, long pos0, long pos1) {
1766  if (buf)
1767    PRE_READ(buf, count);
1768}
1769
1770POST_SYSCALL(pwrite64)
1771(long res, long fd, const void *buf, long count, long pos0, long pos1) {}
1772#  endif
1773
1774PRE_SYSCALL(preadv)
1775(long fd, const __sanitizer_iovec *vec, long vlen, long pos_l, long pos_h) {}
1776
1777POST_SYSCALL(preadv)
1778(long res, long fd, const __sanitizer_iovec *vec, long vlen, long pos_l,
1779 long pos_h) {
1780  if (res >= 0) {
1781    if (vec)
1782      kernel_write_iovec(vec, vlen, res);
1783  }
1784}
1785
1786PRE_SYSCALL(pwritev)
1787(long fd, const __sanitizer_iovec *vec, long vlen, long pos_l, long pos_h) {}
1788
1789POST_SYSCALL(pwritev)
1790(long res, long fd, const __sanitizer_iovec *vec, long vlen, long pos_l,
1791 long pos_h) {
1792  if (res >= 0) {
1793    if (vec)
1794      kernel_read_iovec(vec, vlen, res);
1795  }
1796}
1797
1798PRE_SYSCALL(getcwd)(void *buf, long size) {}
1799
1800POST_SYSCALL(getcwd)(long res, void *buf, long size) {
1801  if (res >= 0) {
1802    if (buf)
1803      POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
1804  }
1805}
1806
1807PRE_SYSCALL(mkdir)(const void *pathname, long mode) {
1808  if (pathname)
1809    PRE_READ(pathname,
1810             __sanitizer::internal_strlen((const char *)pathname) + 1);
1811}
1812
1813POST_SYSCALL(mkdir)(long res, const void *pathname, long mode) {}
1814
1815PRE_SYSCALL(chdir)(const void *filename) {
1816  if (filename)
1817    PRE_READ(filename,
1818             __sanitizer::internal_strlen((const char *)filename) + 1);
1819}
1820
1821POST_SYSCALL(chdir)(long res, const void *filename) {}
1822
1823PRE_SYSCALL(fchdir)(long fd) {}
1824
1825POST_SYSCALL(fchdir)(long res, long fd) {}
1826
1827PRE_SYSCALL(rmdir)(const void *pathname) {
1828  if (pathname)
1829    PRE_READ(pathname,
1830             __sanitizer::internal_strlen((const char *)pathname) + 1);
1831}
1832
1833POST_SYSCALL(rmdir)(long res, const void *pathname) {}
1834
1835PRE_SYSCALL(lookup_dcookie)(u64 cookie64, void *buf, long len) {}
1836
1837POST_SYSCALL(lookup_dcookie)(long res, u64 cookie64, void *buf, long len) {
1838  if (res >= 0) {
1839    if (buf)
1840      POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
1841  }
1842}
1843
1844PRE_SYSCALL(quotactl)(long cmd, const void *special, long id, void *addr) {
1845  if (special)
1846    PRE_READ(special, __sanitizer::internal_strlen((const char *)special) + 1);
1847}
1848
1849POST_SYSCALL(quotactl)
1850(long res, long cmd, const void *special, long id, void *addr) {}
1851
1852PRE_SYSCALL(getdents)(long fd, void *dirent, long count) {}
1853
1854POST_SYSCALL(getdents)(long res, long fd, void *dirent, long count) {
1855  if (res >= 0) {
1856    if (dirent)
1857      POST_WRITE(dirent, res);
1858  }
1859}
1860
1861PRE_SYSCALL(getdents64)(long fd, void *dirent, long count) {}
1862
1863POST_SYSCALL(getdents64)(long res, long fd, void *dirent, long count) {
1864  if (res >= 0) {
1865    if (dirent)
1866      POST_WRITE(dirent, res);
1867  }
1868}
1869
1870PRE_SYSCALL(setsockopt)
1871(long fd, long level, long optname, void *optval, long optlen) {}
1872
1873POST_SYSCALL(setsockopt)
1874(long res, long fd, long level, long optname, void *optval, long optlen) {
1875  if (res >= 0) {
1876    if (optval)
1877      POST_WRITE(optval,
1878                 __sanitizer::internal_strlen((const char *)optval) + 1);
1879  }
1880}
1881
1882PRE_SYSCALL(getsockopt)
1883(long fd, long level, long optname, void *optval, void *optlen) {}
1884
1885POST_SYSCALL(getsockopt)
1886(long res, long fd, long level, long optname, void *optval, void *optlen) {
1887  if (res >= 0) {
1888    if (optval)
1889      POST_WRITE(optval,
1890                 __sanitizer::internal_strlen((const char *)optval) + 1);
1891    if (optlen)
1892      POST_WRITE(optlen, sizeof(int));
1893  }
1894}
1895
1896PRE_SYSCALL(bind)(long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {}
1897
1898POST_SYSCALL(bind)
1899(long res, long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {
1900  if (res >= 0) {
1901    if (arg1)
1902      POST_WRITE(arg1, sizeof(*arg1));
1903  }
1904}
1905
1906PRE_SYSCALL(connect)(long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {}
1907
1908POST_SYSCALL(connect)
1909(long res, long arg0, sanitizer_kernel_sockaddr *arg1, long arg2) {
1910  if (res >= 0) {
1911    if (arg1)
1912      POST_WRITE(arg1, sizeof(*arg1));
1913  }
1914}
1915
1916PRE_SYSCALL(accept)(long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {}
1917
1918POST_SYSCALL(accept)
1919(long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {
1920  if (res >= 0) {
1921    if (arg1)
1922      POST_WRITE(arg1, sizeof(*arg1));
1923    if (arg2)
1924      POST_WRITE(arg2, sizeof(unsigned));
1925  }
1926}
1927
1928PRE_SYSCALL(accept4)
1929(long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2, long arg3) {}
1930
1931POST_SYSCALL(accept4)
1932(long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2, long arg3) {
1933  if (res >= 0) {
1934    if (arg1)
1935      POST_WRITE(arg1, sizeof(*arg1));
1936    if (arg2)
1937      POST_WRITE(arg2, sizeof(unsigned));
1938  }
1939}
1940
1941PRE_SYSCALL(getsockname)
1942(long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {}
1943
1944POST_SYSCALL(getsockname)
1945(long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {
1946  if (res >= 0) {
1947    if (arg1)
1948      POST_WRITE(arg1, sizeof(*arg1));
1949    if (arg2)
1950      POST_WRITE(arg2, sizeof(unsigned));
1951  }
1952}
1953
1954PRE_SYSCALL(getpeername)
1955(long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {}
1956
1957POST_SYSCALL(getpeername)
1958(long res, long arg0, sanitizer_kernel_sockaddr *arg1, void *arg2) {
1959  if (res >= 0) {
1960    if (arg1)
1961      POST_WRITE(arg1, sizeof(*arg1));
1962    if (arg2)
1963      POST_WRITE(arg2, sizeof(unsigned));
1964  }
1965}
1966
1967PRE_SYSCALL(send)(long arg0, void *arg1, long arg2, long arg3) {}
1968
1969POST_SYSCALL(send)(long res, long arg0, void *arg1, long arg2, long arg3) {
1970  if (res) {
1971    if (arg1)
1972      POST_READ(arg1, res);
1973  }
1974}
1975
1976PRE_SYSCALL(sendto)
1977(long arg0, void *arg1, long arg2, long arg3, sanitizer_kernel_sockaddr *arg4,
1978 long arg5) {}
1979
1980POST_SYSCALL(sendto)
1981(long res, long arg0, void *arg1, long arg2, long arg3,
1982 sanitizer_kernel_sockaddr *arg4, long arg5) {
1983  if (res >= 0) {
1984    if (arg1)
1985      POST_READ(arg1, res);
1986    if (arg4)
1987      POST_WRITE(arg4, sizeof(*arg4));
1988  }
1989}
1990
1991PRE_SYSCALL(sendmsg)(long fd, void *msg, long flags) {}
1992
1993POST_SYSCALL(sendmsg)(long res, long fd, void *msg, long flags) {
1994  // FIXME: POST_READ
1995}
1996
1997PRE_SYSCALL(sendmmsg)(long fd, void *msg, long vlen, long flags) {}
1998
1999POST_SYSCALL(sendmmsg)(long res, long fd, void *msg, long vlen, long flags) {
2000  // FIXME: POST_READ
2001}
2002
2003PRE_SYSCALL(recv)(long arg0, void *buf, long len, long flags) {}
2004
2005POST_SYSCALL(recv)(long res, void *buf, long len, long flags) {
2006  if (res >= 0) {
2007    if (buf)
2008      POST_WRITE(buf, res);
2009  }
2010}
2011
2012PRE_SYSCALL(recvfrom)
2013(long arg0, void *buf, long len, long flags, sanitizer_kernel_sockaddr *arg4,
2014 void *arg5) {}
2015
2016POST_SYSCALL(recvfrom)
2017(long res, long arg0, void *buf, long len, long flags,
2018 sanitizer_kernel_sockaddr *arg4, void *arg5) {
2019  if (res >= 0) {
2020    if (buf)
2021      POST_WRITE(buf, res);
2022    if (arg4)
2023      POST_WRITE(arg4, sizeof(*arg4));
2024    if (arg5)
2025      POST_WRITE(arg5, sizeof(int));
2026  }
2027}
2028
2029PRE_SYSCALL(socket)(long arg0, long arg1, long arg2) {}
2030
2031POST_SYSCALL(socket)(long res, long arg0, long arg1, long arg2) {}
2032
2033PRE_SYSCALL(socketpair)(long arg0, long arg1, long arg2, int *sv) {}
2034
2035POST_SYSCALL(socketpair)(long res, long arg0, long arg1, long arg2, int *sv) {
2036  if (res >= 0)
2037    if (sv)
2038      POST_WRITE(sv, sizeof(int) * 2);
2039}
2040
2041PRE_SYSCALL(socketcall)(long call, void *args) {}
2042
2043POST_SYSCALL(socketcall)(long res, long call, void *args) {
2044  if (res >= 0) {
2045    if (args)
2046      POST_WRITE(args, sizeof(long));
2047  }
2048}
2049
2050PRE_SYSCALL(listen)(long arg0, long arg1) {}
2051
2052POST_SYSCALL(listen)(long res, long arg0, long arg1) {}
2053
2054PRE_SYSCALL(poll)(void *ufds, long nfds, long timeout) {}
2055
2056POST_SYSCALL(poll)
2057(long res, __sanitizer_pollfd *ufds, long nfds, long timeout) {
2058  if (res >= 0) {
2059    if (ufds)
2060      POST_WRITE(ufds, nfds * sizeof(*ufds));
2061  }
2062}
2063
2064PRE_SYSCALL(select)
2065(long n, __sanitizer___kernel_fd_set *inp, __sanitizer___kernel_fd_set *outp,
2066 __sanitizer___kernel_fd_set *exp, void *tvp) {}
2067
2068POST_SYSCALL(select)
2069(long res, long n, __sanitizer___kernel_fd_set *inp,
2070 __sanitizer___kernel_fd_set *outp, __sanitizer___kernel_fd_set *exp,
2071 void *tvp) {
2072  if (res >= 0) {
2073    if (inp)
2074      POST_WRITE(inp, sizeof(*inp));
2075    if (outp)
2076      POST_WRITE(outp, sizeof(*outp));
2077    if (exp)
2078      POST_WRITE(exp, sizeof(*exp));
2079    if (tvp)
2080      POST_WRITE(tvp, timeval_sz);
2081  }
2082}
2083
2084PRE_SYSCALL(old_select)(void *arg) {}
2085
2086POST_SYSCALL(old_select)(long res, void *arg) {}
2087
2088PRE_SYSCALL(epoll_create)(long size) {}
2089
2090POST_SYSCALL(epoll_create)(long res, long size) {}
2091
2092PRE_SYSCALL(epoll_create1)(long flags) {}
2093
2094POST_SYSCALL(epoll_create1)(long res, long flags) {}
2095
2096PRE_SYSCALL(epoll_ctl)(long epfd, long op, long fd, void *event) {}
2097
2098POST_SYSCALL(epoll_ctl)(long res, long epfd, long op, long fd, void *event) {
2099  if (res >= 0) {
2100    if (event)
2101      POST_WRITE(event, struct_epoll_event_sz);
2102  }
2103}
2104
2105PRE_SYSCALL(epoll_wait)
2106(long epfd, void *events, long maxevents, long timeout) {}
2107
2108POST_SYSCALL(epoll_wait)
2109(long res, long epfd, void *events, long maxevents, long timeout) {
2110  if (res >= 0) {
2111    COMMON_SYSCALL_FD_ACQUIRE(epfd);
2112    if (events)
2113      POST_WRITE(events, res * struct_epoll_event_sz);
2114  }
2115}
2116
2117PRE_SYSCALL(epoll_pwait)
2118(long epfd, void *events, long maxevents, long timeout,
2119 const kernel_sigset_t *sigmask, long sigsetsize) {
2120  if (sigmask)
2121    PRE_READ(sigmask, sigsetsize);
2122}
2123
2124POST_SYSCALL(epoll_pwait)
2125(long res, long epfd, void *events, long maxevents, long timeout,
2126 const void *sigmask, long sigsetsize) {
2127  if (res >= 0) {
2128    COMMON_SYSCALL_FD_ACQUIRE(epfd);
2129    if (events)
2130      POST_WRITE(events, res * struct_epoll_event_sz);
2131  }
2132}
2133
2134PRE_SYSCALL(epoll_pwait2)
2135(long epfd, void *events, long maxevents,
2136 const sanitizer_kernel_timespec *timeout, const kernel_sigset_t *sigmask,
2137 long sigsetsize) {
2138  if (timeout)
2139    PRE_READ(timeout, sizeof(timeout));
2140  if (sigmask)
2141    PRE_READ(sigmask, sigsetsize);
2142}
2143
2144POST_SYSCALL(epoll_pwait2)
2145(long res, long epfd, void *events, long maxevents,
2146 const sanitizer_kernel_timespec *timeout, const void *sigmask,
2147 long sigsetsize) {
2148  if (res >= 0) {
2149    COMMON_SYSCALL_FD_ACQUIRE(epfd);
2150    if (events)
2151      POST_WRITE(events, res * struct_epoll_event_sz);
2152  }
2153}
2154
2155PRE_SYSCALL(gethostname)(void *name, long len) {}
2156
2157POST_SYSCALL(gethostname)(long res, void *name, long len) {
2158  if (res >= 0) {
2159    if (name)
2160      POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
2161  }
2162}
2163
2164PRE_SYSCALL(sethostname)(void *name, long len) {}
2165
2166POST_SYSCALL(sethostname)(long res, void *name, long len) {
2167  if (res >= 0) {
2168    if (name)
2169      POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
2170  }
2171}
2172
2173PRE_SYSCALL(setdomainname)(void *name, long len) {}
2174
2175POST_SYSCALL(setdomainname)(long res, void *name, long len) {
2176  if (res >= 0) {
2177    if (name)
2178      POST_WRITE(name, __sanitizer::internal_strlen((const char *)name) + 1);
2179  }
2180}
2181
2182PRE_SYSCALL(newuname)(void *name) {}
2183
2184POST_SYSCALL(newuname)(long res, void *name) {
2185  if (res >= 0) {
2186    if (name)
2187      POST_WRITE(name, struct_new_utsname_sz);
2188  }
2189}
2190
2191PRE_SYSCALL(uname)(void *arg0) {}
2192
2193POST_SYSCALL(uname)(long res, void *arg0) {
2194  if (res >= 0) {
2195    if (arg0)
2196      POST_WRITE(arg0, struct_old_utsname_sz);
2197  }
2198}
2199
2200PRE_SYSCALL(olduname)(void *arg0) {}
2201
2202POST_SYSCALL(olduname)(long res, void *arg0) {
2203  if (res >= 0) {
2204    if (arg0)
2205      POST_WRITE(arg0, struct_oldold_utsname_sz);
2206  }
2207}
2208
2209PRE_SYSCALL(getrlimit)(long resource, void *rlim) {}
2210
2211POST_SYSCALL(getrlimit)(long res, long resource, void *rlim) {
2212  if (res >= 0) {
2213    if (rlim)
2214      POST_WRITE(rlim, struct_rlimit_sz);
2215  }
2216}
2217
2218PRE_SYSCALL(old_getrlimit)(long resource, void *rlim) {}
2219
2220POST_SYSCALL(old_getrlimit)(long res, long resource, void *rlim) {
2221  if (res >= 0) {
2222    if (rlim)
2223      POST_WRITE(rlim, struct_rlimit_sz);
2224  }
2225}
2226
2227PRE_SYSCALL(setrlimit)(long resource, void *rlim) {}
2228
2229POST_SYSCALL(setrlimit)(long res, long resource, void *rlim) {
2230  if (res >= 0) {
2231    if (rlim)
2232      POST_WRITE(rlim, struct_rlimit_sz);
2233  }
2234}
2235
2236#  if SANITIZER_GLIBC
2237PRE_SYSCALL(prlimit64)
2238(long pid, long resource, const void *new_rlim, void *old_rlim) {
2239  if (new_rlim)
2240    PRE_READ(new_rlim, struct_rlimit64_sz);
2241}
2242
2243POST_SYSCALL(prlimit64)
2244(long res, long pid, long resource, const void *new_rlim, void *old_rlim) {
2245  if (res >= 0) {
2246    if (old_rlim)
2247      POST_WRITE(old_rlim, struct_rlimit64_sz);
2248  }
2249}
2250#  endif
2251
2252PRE_SYSCALL(getrusage)(long who, void *ru) {}
2253
2254POST_SYSCALL(getrusage)(long res, long who, void *ru) {
2255  if (res >= 0) {
2256    if (ru)
2257      POST_WRITE(ru, struct_rusage_sz);
2258  }
2259}
2260
2261PRE_SYSCALL(umask)(long mask) {}
2262
2263POST_SYSCALL(umask)(long res, long mask) {}
2264
2265PRE_SYSCALL(msgget)(long key, long msgflg) {}
2266
2267POST_SYSCALL(msgget)(long res, long key, long msgflg) {}
2268
2269PRE_SYSCALL(msgsnd)(long msqid, void *msgp, long msgsz, long msgflg) {
2270  if (msgp)
2271    PRE_READ(msgp, msgsz);
2272}
2273
2274POST_SYSCALL(msgsnd)
2275(long res, long msqid, void *msgp, long msgsz, long msgflg) {}
2276
2277PRE_SYSCALL(msgrcv)
2278(long msqid, void *msgp, long msgsz, long msgtyp, long msgflg) {}
2279
2280POST_SYSCALL(msgrcv)
2281(long res, long msqid, void *msgp, long msgsz, long msgtyp, long msgflg) {
2282  if (res >= 0) {
2283    if (msgp)
2284      POST_WRITE(msgp, res);
2285  }
2286}
2287
2288#  if !SANITIZER_ANDROID
2289PRE_SYSCALL(msgctl)(long msqid, long cmd, void *buf) {}
2290
2291POST_SYSCALL(msgctl)(long res, long msqid, long cmd, void *buf) {
2292  if (res >= 0) {
2293    if (buf)
2294      POST_WRITE(buf, struct_msqid_ds_sz);
2295  }
2296}
2297#  endif
2298
2299PRE_SYSCALL(semget)(long key, long nsems, long semflg) {}
2300
2301POST_SYSCALL(semget)(long res, long key, long nsems, long semflg) {}
2302
2303PRE_SYSCALL(semop)(long semid, void *sops, long nsops) {}
2304
2305POST_SYSCALL(semop)(long res, long semid, void *sops, long nsops) {}
2306
2307PRE_SYSCALL(semctl)(long semid, long semnum, long cmd, void *arg) {}
2308
2309POST_SYSCALL(semctl)(long res, long semid, long semnum, long cmd, void *arg) {}
2310
2311PRE_SYSCALL(semtimedop)
2312(long semid, void *sops, long nsops, const void *timeout) {
2313  if (timeout)
2314    PRE_READ(timeout, struct_timespec_sz);
2315}
2316
2317POST_SYSCALL(semtimedop)
2318(long res, long semid, void *sops, long nsops, const void *timeout) {}
2319
2320PRE_SYSCALL(shmat)(long shmid, void *shmaddr, long shmflg) {}
2321
2322POST_SYSCALL(shmat)(long res, long shmid, void *shmaddr, long shmflg) {
2323  if (res >= 0) {
2324    if (shmaddr)
2325      POST_WRITE(shmaddr,
2326                 __sanitizer::internal_strlen((const char *)shmaddr) + 1);
2327  }
2328}
2329
2330PRE_SYSCALL(shmget)(long key, long size, long flag) {}
2331
2332POST_SYSCALL(shmget)(long res, long key, long size, long flag) {}
2333
2334PRE_SYSCALL(shmdt)(void *shmaddr) {}
2335
2336POST_SYSCALL(shmdt)(long res, void *shmaddr) {
2337  if (res >= 0) {
2338    if (shmaddr)
2339      POST_WRITE(shmaddr,
2340                 __sanitizer::internal_strlen((const char *)shmaddr) + 1);
2341  }
2342}
2343
2344PRE_SYSCALL(ipc)
2345(long call, long first, long second, long third, void *ptr, long fifth) {}
2346
2347POST_SYSCALL(ipc)
2348(long res, long call, long first, long second, long third, void *ptr,
2349 long fifth) {}
2350
2351#  if !SANITIZER_ANDROID
2352PRE_SYSCALL(shmctl)(long shmid, long cmd, void *buf) {}
2353
2354POST_SYSCALL(shmctl)(long res, long shmid, long cmd, void *buf) {
2355  if (res >= 0) {
2356    if (buf)
2357      POST_WRITE(buf, sizeof(__sanitizer_shmid_ds));
2358  }
2359}
2360
2361PRE_SYSCALL(mq_open)(const void *name, long oflag, long mode, void *attr) {
2362  if (name)
2363    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
2364}
2365
2366POST_SYSCALL(mq_open)
2367(long res, const void *name, long oflag, long mode, void *attr) {
2368  if (res >= 0) {
2369    if (attr)
2370      POST_WRITE(attr, struct_mq_attr_sz);
2371  }
2372}
2373
2374PRE_SYSCALL(mq_unlink)(const void *name) {
2375  if (name)
2376    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
2377}
2378
2379POST_SYSCALL(mq_unlink)(long res, const void *name) {}
2380
2381PRE_SYSCALL(mq_timedsend)
2382(long mqdes, const void *msg_ptr, long msg_len, long msg_prio,
2383 const void *abs_timeout) {
2384  if (msg_ptr)
2385    PRE_READ(msg_ptr, msg_len);
2386  if (abs_timeout)
2387    PRE_READ(abs_timeout, struct_timespec_sz);
2388}
2389
2390POST_SYSCALL(mq_timedsend)
2391(long res, long mqdes, const void *msg_ptr, long msg_len, long msg_prio,
2392 const void *abs_timeout) {}
2393
2394PRE_SYSCALL(mq_timedreceive)
2395(long mqdes, void *msg_ptr, long msg_len, void *msg_prio,
2396 const void *abs_timeout) {
2397  if (abs_timeout)
2398    PRE_READ(abs_timeout, struct_timespec_sz);
2399}
2400
2401POST_SYSCALL(mq_timedreceive)
2402(long res, long mqdes, void *msg_ptr, long msg_len, int *msg_prio,
2403 const void *abs_timeout) {
2404  if (res >= 0) {
2405    if (msg_ptr)
2406      POST_WRITE(msg_ptr, res);
2407    if (msg_prio)
2408      POST_WRITE(msg_prio, sizeof(*msg_prio));
2409  }
2410}
2411
2412PRE_SYSCALL(mq_notify)(long mqdes, const void *notification) {
2413  if (notification)
2414    PRE_READ(notification, struct_sigevent_sz);
2415}
2416
2417POST_SYSCALL(mq_notify)(long res, long mqdes, const void *notification) {}
2418
2419PRE_SYSCALL(mq_getsetattr)(long mqdes, const void *mqstat, void *omqstat) {
2420  if (mqstat)
2421    PRE_READ(mqstat, struct_mq_attr_sz);
2422}
2423
2424POST_SYSCALL(mq_getsetattr)
2425(long res, long mqdes, const void *mqstat, void *omqstat) {
2426  if (res >= 0) {
2427    if (omqstat)
2428      POST_WRITE(omqstat, struct_mq_attr_sz);
2429  }
2430}
2431#  endif  // SANITIZER_ANDROID
2432
2433PRE_SYSCALL(pciconfig_iobase)(long which, long bus, long devfn) {}
2434
2435POST_SYSCALL(pciconfig_iobase)(long res, long which, long bus, long devfn) {}
2436
2437PRE_SYSCALL(pciconfig_read)
2438(long bus, long dfn, long off, long len, void *buf) {}
2439
2440POST_SYSCALL(pciconfig_read)
2441(long res, long bus, long dfn, long off, long len, void *buf) {}
2442
2443PRE_SYSCALL(pciconfig_write)
2444(long bus, long dfn, long off, long len, void *buf) {}
2445
2446POST_SYSCALL(pciconfig_write)
2447(long res, long bus, long dfn, long off, long len, void *buf) {}
2448
2449PRE_SYSCALL(swapon)(const void *specialfile, long swap_flags) {
2450  if (specialfile)
2451    PRE_READ(specialfile,
2452             __sanitizer::internal_strlen((const char *)specialfile) + 1);
2453}
2454
2455POST_SYSCALL(swapon)(long res, const void *specialfile, long swap_flags) {}
2456
2457PRE_SYSCALL(swapoff)(const void *specialfile) {
2458  if (specialfile)
2459    PRE_READ(specialfile,
2460             __sanitizer::internal_strlen((const char *)specialfile) + 1);
2461}
2462
2463POST_SYSCALL(swapoff)(long res, const void *specialfile) {}
2464
2465PRE_SYSCALL(sysctl)(__sanitizer___sysctl_args *args) {
2466  if (args) {
2467    if (args->name)
2468      PRE_READ(args->name, args->nlen * sizeof(*args->name));
2469    if (args->newval)
2470      PRE_READ(args->name, args->newlen);
2471  }
2472}
2473
2474POST_SYSCALL(sysctl)(long res, __sanitizer___sysctl_args *args) {
2475  if (res >= 0) {
2476    if (args && args->oldval && args->oldlenp) {
2477      POST_WRITE(args->oldlenp, sizeof(*args->oldlenp));
2478      POST_WRITE(args->oldval, *args->oldlenp);
2479    }
2480  }
2481}
2482
2483PRE_SYSCALL(sysinfo)(void *info) {}
2484
2485POST_SYSCALL(sysinfo)(long res, void *info) {
2486  if (res >= 0) {
2487    if (info)
2488      POST_WRITE(info, struct_sysinfo_sz);
2489  }
2490}
2491
2492PRE_SYSCALL(sysfs)(long option, long arg1, long arg2) {}
2493
2494POST_SYSCALL(sysfs)(long res, long option, long arg1, long arg2) {}
2495
2496PRE_SYSCALL(syslog)(long type, void *buf, long len) {}
2497
2498POST_SYSCALL(syslog)(long res, long type, void *buf, long len) {
2499  if (res >= 0) {
2500    if (buf)
2501      POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
2502  }
2503}
2504
2505PRE_SYSCALL(uselib)(const void *library) {
2506  if (library)
2507    PRE_READ(library, __sanitizer::internal_strlen((const char *)library) + 1);
2508}
2509
2510POST_SYSCALL(uselib)(long res, const void *library) {}
2511
2512PRE_SYSCALL(ni_syscall)() {}
2513
2514POST_SYSCALL(ni_syscall)(long res) {}
2515
2516PRE_SYSCALL(ptrace)(long request, long pid, long addr, long data) {
2517#  if !SANITIZER_ANDROID &&                                                   \
2518      (defined(__i386) || defined(__x86_64) || defined(__mips64) ||           \
2519       defined(__powerpc64__) || defined(__aarch64__) || defined(__s390__) || \
2520       defined(__loongarch__) || SANITIZER_RISCV64)
2521  if (data) {
2522    if (request == ptrace_setregs) {
2523      PRE_READ((void *)data, struct_user_regs_struct_sz);
2524    } else if (request == ptrace_setfpregs) {
2525      PRE_READ((void *)data, struct_user_fpregs_struct_sz);
2526    } else if (request == ptrace_setfpxregs) {
2527      PRE_READ((void *)data, struct_user_fpxregs_struct_sz);
2528    } else if (request == ptrace_setsiginfo) {
2529      PRE_READ((void *)data, siginfo_t_sz);
2530    } else if (request == ptrace_setregset) {
2531      __sanitizer_iovec *iov = (__sanitizer_iovec *)data;
2532      PRE_READ(iov->iov_base, iov->iov_len);
2533    }
2534  }
2535#  endif
2536}
2537
2538POST_SYSCALL(ptrace)(long res, long request, long pid, long addr, long data) {
2539#  if !SANITIZER_ANDROID &&                                                   \
2540      (defined(__i386) || defined(__x86_64) || defined(__mips64) ||           \
2541       defined(__powerpc64__) || defined(__aarch64__) || defined(__s390__) || \
2542       defined(__loongarch__) || SANITIZER_RISCV64)
2543  if (res >= 0 && data) {
2544    // Note that this is different from the interceptor in
2545    // sanitizer_common_interceptors.inc.
2546    // PEEK* requests return resulting values through data pointer.
2547    if (request == ptrace_getregs) {
2548      POST_WRITE((void *)data, struct_user_regs_struct_sz);
2549    } else if (request == ptrace_getfpregs) {
2550      POST_WRITE((void *)data, struct_user_fpregs_struct_sz);
2551    } else if (request == ptrace_getfpxregs) {
2552      POST_WRITE((void *)data, struct_user_fpxregs_struct_sz);
2553    } else if (request == ptrace_getsiginfo) {
2554      POST_WRITE((void *)data, siginfo_t_sz);
2555    } else if (request == ptrace_getregset) {
2556      __sanitizer_iovec *iov = (__sanitizer_iovec *)data;
2557      POST_WRITE(iov->iov_base, iov->iov_len);
2558    } else if (request == ptrace_peekdata || request == ptrace_peektext ||
2559               request == ptrace_peekuser) {
2560      POST_WRITE((void *)data, sizeof(void *));
2561    }
2562  }
2563#  endif
2564}
2565
2566PRE_SYSCALL(add_key)
2567(const void *_type, const void *_description, const void *_payload, long plen,
2568 long destringid) {
2569  if (_type)
2570    PRE_READ(_type, __sanitizer::internal_strlen((const char *)_type) + 1);
2571  if (_description)
2572    PRE_READ(_description,
2573             __sanitizer::internal_strlen((const char *)_description) + 1);
2574}
2575
2576POST_SYSCALL(add_key)
2577(long res, const void *_type, const void *_description, const void *_payload,
2578 long plen, long destringid) {}
2579
2580PRE_SYSCALL(request_key)
2581(const void *_type, const void *_description, const void *_callout_info,
2582 long destringid) {
2583  if (_type)
2584    PRE_READ(_type, __sanitizer::internal_strlen((const char *)_type) + 1);
2585  if (_description)
2586    PRE_READ(_description,
2587             __sanitizer::internal_strlen((const char *)_description) + 1);
2588  if (_callout_info)
2589    PRE_READ(_callout_info,
2590             __sanitizer::internal_strlen((const char *)_callout_info) + 1);
2591}
2592
2593POST_SYSCALL(request_key)
2594(long res, const void *_type, const void *_description,
2595 const void *_callout_info, long destringid) {}
2596
2597PRE_SYSCALL(keyctl)(long cmd, long arg2, long arg3, long arg4, long arg5) {}
2598
2599POST_SYSCALL(keyctl)
2600(long res, long cmd, long arg2, long arg3, long arg4, long arg5) {}
2601
2602PRE_SYSCALL(ioprio_set)(long which, long who, long ioprio) {}
2603
2604POST_SYSCALL(ioprio_set)(long res, long which, long who, long ioprio) {}
2605
2606PRE_SYSCALL(ioprio_get)(long which, long who) {}
2607
2608POST_SYSCALL(ioprio_get)(long res, long which, long who) {}
2609
2610PRE_SYSCALL(set_mempolicy)(long mode, void *nmask, long maxnode) {}
2611
2612POST_SYSCALL(set_mempolicy)(long res, long mode, void *nmask, long maxnode) {
2613  if (res >= 0) {
2614    if (nmask)
2615      POST_WRITE(nmask, sizeof(long));
2616  }
2617}
2618
2619PRE_SYSCALL(migrate_pages)
2620(long pid, long maxnode, const void *from, const void *to) {
2621  if (from)
2622    PRE_READ(from, sizeof(long));
2623  if (to)
2624    PRE_READ(to, sizeof(long));
2625}
2626
2627POST_SYSCALL(migrate_pages)
2628(long res, long pid, long maxnode, const void *from, const void *to) {}
2629
2630PRE_SYSCALL(move_pages)
2631(long pid, long nr_pages, const void **pages, const int *nodes, int *status,
2632 long flags) {
2633  if (pages)
2634    PRE_READ(pages, nr_pages * sizeof(*pages));
2635  if (nodes)
2636    PRE_READ(nodes, nr_pages * sizeof(*nodes));
2637}
2638
2639POST_SYSCALL(move_pages)
2640(long res, long pid, long nr_pages, const void **pages, const int *nodes,
2641 int *status, long flags) {
2642  if (res >= 0) {
2643    if (status)
2644      POST_WRITE(status, nr_pages * sizeof(*status));
2645  }
2646}
2647
2648PRE_SYSCALL(mbind)
2649(long start, long len, long mode, void *nmask, long maxnode, long flags) {}
2650
2651POST_SYSCALL(mbind)
2652(long res, long start, long len, long mode, void *nmask, long maxnode,
2653 long flags) {
2654  if (res >= 0) {
2655    if (nmask)
2656      POST_WRITE(nmask, sizeof(long));
2657  }
2658}
2659
2660PRE_SYSCALL(get_mempolicy)
2661(void *policy, void *nmask, long maxnode, long addr, long flags) {}
2662
2663POST_SYSCALL(get_mempolicy)
2664(long res, void *policy, void *nmask, long maxnode, long addr, long flags) {
2665  if (res >= 0) {
2666    if (policy)
2667      POST_WRITE(policy, sizeof(int));
2668    if (nmask)
2669      POST_WRITE(nmask, sizeof(long));
2670  }
2671}
2672
2673PRE_SYSCALL(inotify_init)() {}
2674
2675POST_SYSCALL(inotify_init)(long res) {}
2676
2677PRE_SYSCALL(inotify_init1)(long flags) {}
2678
2679POST_SYSCALL(inotify_init1)(long res, long flags) {}
2680
2681PRE_SYSCALL(inotify_add_watch)(long fd, const void *path, long mask) {
2682  if (path)
2683    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
2684}
2685
2686POST_SYSCALL(inotify_add_watch)
2687(long res, long fd, const void *path, long mask) {}
2688
2689PRE_SYSCALL(inotify_rm_watch)(long fd, long wd) {}
2690
2691POST_SYSCALL(inotify_rm_watch)(long res, long fd, long wd) {}
2692
2693PRE_SYSCALL(spu_run)(long fd, void *unpc, void *ustatus) {}
2694
2695POST_SYSCALL(spu_run)(long res, long fd, unsigned *unpc, unsigned *ustatus) {
2696  if (res >= 0) {
2697    if (unpc)
2698      POST_WRITE(unpc, sizeof(*unpc));
2699    if (ustatus)
2700      POST_WRITE(ustatus, sizeof(*ustatus));
2701  }
2702}
2703
2704PRE_SYSCALL(spu_create)(const void *name, long flags, long mode, long fd) {
2705  if (name)
2706    PRE_READ(name, __sanitizer::internal_strlen((const char *)name) + 1);
2707}
2708
2709POST_SYSCALL(spu_create)
2710(long res, const void *name, long flags, long mode, long fd) {}
2711
2712PRE_SYSCALL(mknodat)(long dfd, const void *filename, long mode, long dev) {
2713  if (filename)
2714    PRE_READ(filename,
2715             __sanitizer::internal_strlen((const char *)filename) + 1);
2716}
2717
2718POST_SYSCALL(mknodat)
2719(long res, long dfd, const void *filename, long mode, long dev) {}
2720
2721PRE_SYSCALL(mkdirat)(long dfd, const void *pathname, long mode) {
2722  if (pathname)
2723    PRE_READ(pathname,
2724             __sanitizer::internal_strlen((const char *)pathname) + 1);
2725}
2726
2727POST_SYSCALL(mkdirat)(long res, long dfd, const void *pathname, long mode) {}
2728
2729PRE_SYSCALL(unlinkat)(long dfd, const void *pathname, long flag) {
2730  if (pathname)
2731    PRE_READ(pathname,
2732             __sanitizer::internal_strlen((const char *)pathname) + 1);
2733}
2734
2735POST_SYSCALL(unlinkat)(long res, long dfd, const void *pathname, long flag) {}
2736
2737PRE_SYSCALL(symlinkat)(const void *oldname, long newdfd, const void *newname) {
2738  if (oldname)
2739    PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
2740  if (newname)
2741    PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
2742}
2743
2744POST_SYSCALL(symlinkat)
2745(long res, const void *oldname, long newdfd, const void *newname) {}
2746
2747PRE_SYSCALL(linkat)
2748(long olddfd, const void *oldname, long newdfd, const void *newname,
2749 long flags) {
2750  if (oldname)
2751    PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
2752  if (newname)
2753    PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
2754}
2755
2756POST_SYSCALL(linkat)
2757(long res, long olddfd, const void *oldname, long newdfd, const void *newname,
2758 long flags) {}
2759
2760PRE_SYSCALL(renameat)
2761(long olddfd, const void *oldname, long newdfd, const void *newname) {
2762  if (oldname)
2763    PRE_READ(oldname, __sanitizer::internal_strlen((const char *)oldname) + 1);
2764  if (newname)
2765    PRE_READ(newname, __sanitizer::internal_strlen((const char *)newname) + 1);
2766}
2767
2768POST_SYSCALL(renameat)
2769(long res, long olddfd, const void *oldname, long newdfd, const void *newname) {
2770}
2771
2772PRE_SYSCALL(futimesat)(long dfd, const void *filename, void *utimes) {
2773  if (filename)
2774    PRE_READ(filename,
2775             __sanitizer::internal_strlen((const char *)filename) + 1);
2776}
2777
2778POST_SYSCALL(futimesat)
2779(long res, long dfd, const void *filename, void *utimes) {
2780  if (res >= 0) {
2781    if (utimes)
2782      POST_WRITE(utimes, timeval_sz);
2783  }
2784}
2785
2786PRE_SYSCALL(faccessat)(long dfd, const void *filename, long mode) {
2787  if (filename)
2788    PRE_READ(filename,
2789             __sanitizer::internal_strlen((const char *)filename) + 1);
2790}
2791
2792POST_SYSCALL(faccessat)(long res, long dfd, const void *filename, long mode) {}
2793
2794PRE_SYSCALL(fchmodat)(long dfd, const void *filename, long mode) {
2795  if (filename)
2796    PRE_READ(filename,
2797             __sanitizer::internal_strlen((const char *)filename) + 1);
2798}
2799
2800POST_SYSCALL(fchmodat)(long res, long dfd, const void *filename, long mode) {}
2801
2802PRE_SYSCALL(fchownat)
2803(long dfd, const void *filename, long user, long group, long flag) {
2804  if (filename)
2805    PRE_READ(filename,
2806             __sanitizer::internal_strlen((const char *)filename) + 1);
2807}
2808
2809POST_SYSCALL(fchownat)
2810(long res, long dfd, const void *filename, long user, long group, long flag) {}
2811
2812PRE_SYSCALL(openat)(long dfd, const void *filename, long flags, long mode) {
2813  if (filename)
2814    PRE_READ(filename,
2815             __sanitizer::internal_strlen((const char *)filename) + 1);
2816}
2817
2818POST_SYSCALL(openat)
2819(long res, long dfd, const void *filename, long flags, long mode) {}
2820
2821PRE_SYSCALL(newfstatat)
2822(long dfd, const void *filename, void *statbuf, long flag) {
2823  if (filename)
2824    PRE_READ(filename,
2825             __sanitizer::internal_strlen((const char *)filename) + 1);
2826}
2827
2828POST_SYSCALL(newfstatat)
2829(long res, long dfd, const void *filename, void *statbuf, long flag) {
2830  if (res >= 0) {
2831    if (statbuf)
2832      POST_WRITE(statbuf, struct_kernel_stat_sz);
2833  }
2834}
2835
2836PRE_SYSCALL(fstatat64)
2837(long dfd, const void *filename, void *statbuf, long flag) {
2838  if (filename)
2839    PRE_READ(filename,
2840             __sanitizer::internal_strlen((const char *)filename) + 1);
2841}
2842
2843POST_SYSCALL(fstatat64)
2844(long res, long dfd, const void *filename, void *statbuf, long flag) {
2845  if (res >= 0) {
2846    if (statbuf)
2847      POST_WRITE(statbuf, struct_kernel_stat64_sz);
2848  }
2849}
2850
2851PRE_SYSCALL(readlinkat)(long dfd, const void *path, void *buf, long bufsiz) {
2852  if (path)
2853    PRE_READ(path, __sanitizer::internal_strlen((const char *)path) + 1);
2854}
2855
2856POST_SYSCALL(readlinkat)
2857(long res, long dfd, const void *path, void *buf, long bufsiz) {
2858  if (res >= 0) {
2859    if (buf)
2860      POST_WRITE(buf, __sanitizer::internal_strlen((const char *)buf) + 1);
2861  }
2862}
2863
2864PRE_SYSCALL(utimensat)
2865(long dfd, const void *filename, void *utimes, long flags) {
2866  if (filename)
2867    PRE_READ(filename,
2868             __sanitizer::internal_strlen((const char *)filename) + 1);
2869}
2870
2871POST_SYSCALL(utimensat)
2872(long res, long dfd, const void *filename, void *utimes, long flags) {
2873  if (res >= 0) {
2874    if (utimes)
2875      POST_WRITE(utimes, struct_timespec_sz);
2876  }
2877}
2878
2879PRE_SYSCALL(unshare)(long unshare_flags) {}
2880
2881POST_SYSCALL(unshare)(long res, long unshare_flags) {}
2882
2883PRE_SYSCALL(splice)
2884(long fd_in, void *off_in, long fd_out, void *off_out, long len, long flags) {}
2885
2886POST_SYSCALL(splice)
2887(long res, long fd_in, void *off_in, long fd_out, void *off_out, long len,
2888 long flags) {
2889  if (res >= 0) {
2890    if (off_in)
2891      POST_WRITE(off_in, sizeof(long long));
2892    if (off_out)
2893      POST_WRITE(off_out, sizeof(long long));
2894  }
2895}
2896
2897PRE_SYSCALL(vmsplice)
2898(long fd, const __sanitizer_iovec *iov, long nr_segs, long flags) {}
2899
2900POST_SYSCALL(vmsplice)
2901(long res, long fd, const __sanitizer_iovec *iov, long nr_segs, long flags) {
2902  if (res >= 0) {
2903    if (iov)
2904      kernel_read_iovec(iov, nr_segs, res);
2905  }
2906}
2907
2908PRE_SYSCALL(tee)(long fdin, long fdout, long len, long flags) {}
2909
2910POST_SYSCALL(tee)(long res, long fdin, long fdout, long len, long flags) {}
2911
2912PRE_SYSCALL(get_robust_list)(long pid, void *head_ptr, void *len_ptr) {}
2913
2914POST_SYSCALL(get_robust_list)
2915(long res, long pid, void *head_ptr, void *len_ptr) {}
2916
2917PRE_SYSCALL(set_robust_list)(void *head, long len) {}
2918
2919POST_SYSCALL(set_robust_list)(long res, void *head, long len) {}
2920
2921PRE_SYSCALL(getcpu)(void *cpu, void *node, void *cache) {}
2922
2923POST_SYSCALL(getcpu)(long res, void *cpu, void *node, void *cache) {
2924  if (res >= 0) {
2925    if (cpu)
2926      POST_WRITE(cpu, sizeof(unsigned));
2927    if (node)
2928      POST_WRITE(node, sizeof(unsigned));
2929    // The third argument to this system call is nowadays unused.
2930  }
2931}
2932
2933PRE_SYSCALL(signalfd)(long ufd, void *user_mask, long sizemask) {}
2934
2935POST_SYSCALL(signalfd)
2936(long res, long ufd, kernel_sigset_t *user_mask, long sizemask) {
2937  if (res >= 0) {
2938    if (user_mask)
2939      POST_WRITE(user_mask, sizemask);
2940  }
2941}
2942
2943PRE_SYSCALL(signalfd4)(long ufd, void *user_mask, long sizemask, long flags) {}
2944
2945POST_SYSCALL(signalfd4)
2946(long res, long ufd, kernel_sigset_t *user_mask, long sizemask, long flags) {
2947  if (res >= 0) {
2948    if (user_mask)
2949      POST_WRITE(user_mask, sizemask);
2950  }
2951}
2952
2953PRE_SYSCALL(timerfd_create)(long clockid, long flags) {}
2954
2955POST_SYSCALL(timerfd_create)(long res, long clockid, long flags) {}
2956
2957PRE_SYSCALL(timerfd_settime)
2958(long ufd, long flags, const void *utmr, void *otmr) {
2959  if (utmr)
2960    PRE_READ(utmr, struct_itimerspec_sz);
2961}
2962
2963POST_SYSCALL(timerfd_settime)
2964(long res, long ufd, long flags, const void *utmr, void *otmr) {
2965  if (res >= 0) {
2966    if (otmr)
2967      POST_WRITE(otmr, struct_itimerspec_sz);
2968  }
2969}
2970
2971PRE_SYSCALL(timerfd_gettime)(long ufd, void *otmr) {}
2972
2973POST_SYSCALL(timerfd_gettime)(long res, long ufd, void *otmr) {
2974  if (res >= 0) {
2975    if (otmr)
2976      POST_WRITE(otmr, struct_itimerspec_sz);
2977  }
2978}
2979
2980PRE_SYSCALL(eventfd)(long count) {}
2981
2982POST_SYSCALL(eventfd)(long res, long count) {}
2983
2984PRE_SYSCALL(eventfd2)(long count, long flags) {}
2985
2986POST_SYSCALL(eventfd2)(long res, long count, long flags) {}
2987
2988PRE_SYSCALL(old_readdir)(long arg0, void *arg1, long arg2) {}
2989
2990POST_SYSCALL(old_readdir)(long res, long arg0, void *arg1, long arg2) {
2991  // Missing definition of 'struct old_linux_dirent'.
2992}
2993
2994PRE_SYSCALL(pselect6)
2995(long arg0, __sanitizer___kernel_fd_set *arg1,
2996 __sanitizer___kernel_fd_set *arg2, __sanitizer___kernel_fd_set *arg3,
2997 void *arg4, void *arg5) {}
2998
2999POST_SYSCALL(pselect6)
3000(long res, long arg0, __sanitizer___kernel_fd_set *arg1,
3001 __sanitizer___kernel_fd_set *arg2, __sanitizer___kernel_fd_set *arg3,
3002 void *arg4, void *arg5) {
3003  if (res >= 0) {
3004    if (arg1)
3005      POST_WRITE(arg1, sizeof(*arg1));
3006    if (arg2)
3007      POST_WRITE(arg2, sizeof(*arg2));
3008    if (arg3)
3009      POST_WRITE(arg3, sizeof(*arg3));
3010    if (arg4)
3011      POST_WRITE(arg4, struct_timespec_sz);
3012  }
3013}
3014
3015PRE_SYSCALL(ppoll)
3016(__sanitizer_pollfd *arg0, long arg1, void *arg2, const kernel_sigset_t *arg3,
3017 long arg4) {
3018  if (arg3)
3019    PRE_READ(arg3, arg4);
3020}
3021
3022POST_SYSCALL(ppoll)
3023(long res, __sanitizer_pollfd *arg0, long arg1, void *arg2, const void *arg3,
3024 long arg4) {
3025  if (res >= 0) {
3026    if (arg0)
3027      POST_WRITE(arg0, sizeof(*arg0));
3028    if (arg2)
3029      POST_WRITE(arg2, struct_timespec_sz);
3030  }
3031}
3032
3033PRE_SYSCALL(syncfs)(long fd) {}
3034
3035POST_SYSCALL(syncfs)(long res, long fd) {}
3036
3037PRE_SYSCALL(perf_event_open)
3038(__sanitizer_perf_event_attr *attr_uptr, long pid, long cpu, long group_fd,
3039 long flags) {
3040  if (attr_uptr)
3041    PRE_READ(attr_uptr, attr_uptr->size);
3042}
3043
3044POST_SYSCALL(perf_event_open)
3045(long res, __sanitizer_perf_event_attr *attr_uptr, long pid, long cpu,
3046 long group_fd, long flags) {}
3047
3048PRE_SYSCALL(mmap_pgoff)
3049(long addr, long len, long prot, long flags, long fd, long pgoff) {}
3050
3051POST_SYSCALL(mmap_pgoff)
3052(long res, long addr, long len, long prot, long flags, long fd, long pgoff) {}
3053
3054PRE_SYSCALL(old_mmap)(void *arg) {}
3055
3056POST_SYSCALL(old_mmap)(long res, void *arg) {}
3057
3058PRE_SYSCALL(name_to_handle_at)
3059(long dfd, const void *name, void *handle, void *mnt_id, long flag) {}
3060
3061POST_SYSCALL(name_to_handle_at)
3062(long res, long dfd, const void *name, void *handle, void *mnt_id, long flag) {}
3063
3064PRE_SYSCALL(open_by_handle_at)(long mountdirfd, void *handle, long flags) {}
3065
3066POST_SYSCALL(open_by_handle_at)
3067(long res, long mountdirfd, void *handle, long flags) {}
3068
3069PRE_SYSCALL(setns)(long fd, long nstype) {}
3070
3071POST_SYSCALL(setns)(long res, long fd, long nstype) {}
3072
3073PRE_SYSCALL(process_vm_readv)
3074(long pid, const __sanitizer_iovec *lvec, long liovcnt, const void *rvec,
3075 long riovcnt, long flags) {}
3076
3077POST_SYSCALL(process_vm_readv)
3078(long res, long pid, const __sanitizer_iovec *lvec, long liovcnt,
3079 const void *rvec, long riovcnt, long flags) {
3080  if (res >= 0) {
3081    if (lvec)
3082      kernel_write_iovec(lvec, liovcnt, res);
3083  }
3084}
3085
3086PRE_SYSCALL(process_vm_writev)
3087(long pid, const __sanitizer_iovec *lvec, long liovcnt, const void *rvec,
3088 long riovcnt, long flags) {}
3089
3090POST_SYSCALL(process_vm_writev)
3091(long res, long pid, const __sanitizer_iovec *lvec, long liovcnt,
3092 const void *rvec, long riovcnt, long flags) {
3093  if (res >= 0) {
3094    if (lvec)
3095      kernel_read_iovec(lvec, liovcnt, res);
3096  }
3097}
3098
3099PRE_SYSCALL(fork)() { COMMON_SYSCALL_PRE_FORK(); }
3100
3101POST_SYSCALL(fork)(long res) { COMMON_SYSCALL_POST_FORK(res); }
3102
3103PRE_SYSCALL(vfork)() { COMMON_SYSCALL_PRE_FORK(); }
3104
3105POST_SYSCALL(vfork)(long res) { COMMON_SYSCALL_POST_FORK(res); }
3106
3107PRE_SYSCALL(sigaction)
3108(long signum, const __sanitizer_kernel_sigaction_t *act,
3109 __sanitizer_kernel_sigaction_t *oldact) {
3110  if (act) {
3111    PRE_READ(&act->sigaction, sizeof(act->sigaction));
3112    PRE_READ(&act->sa_flags, sizeof(act->sa_flags));
3113    PRE_READ(&act->sa_mask, sizeof(act->sa_mask));
3114  }
3115}
3116
3117POST_SYSCALL(sigaction)
3118(long res, long signum, const __sanitizer_kernel_sigaction_t *act,
3119 __sanitizer_kernel_sigaction_t *oldact) {
3120  if (res >= 0 && oldact)
3121    POST_WRITE(oldact, sizeof(*oldact));
3122}
3123
3124PRE_SYSCALL(rt_sigaction)
3125(long signum, const __sanitizer_kernel_sigaction_t *act,
3126 __sanitizer_kernel_sigaction_t *oldact, SIZE_T sz) {
3127  if (act) {
3128    PRE_READ(&act->sigaction, sizeof(act->sigaction));
3129    PRE_READ(&act->sa_flags, sizeof(act->sa_flags));
3130    PRE_READ(&act->sa_mask, sz);
3131  }
3132}
3133
3134POST_SYSCALL(rt_sigaction)
3135(long res, long signum, const __sanitizer_kernel_sigaction_t *act,
3136 __sanitizer_kernel_sigaction_t *oldact, SIZE_T sz) {
3137  if (res >= 0 && oldact) {
3138    SIZE_T oldact_sz = ((char *)&oldact->sa_mask) - ((char *)oldact) + sz;
3139    POST_WRITE(oldact, oldact_sz);
3140  }
3141}
3142
3143PRE_SYSCALL(getrandom)(void *buf, uptr count, long flags) {
3144  if (buf) {
3145    PRE_WRITE(buf, count);
3146  }
3147}
3148
3149POST_SYSCALL(getrandom)(long res, void *buf, uptr count, long flags) {
3150  if (res > 0 && buf) {
3151    POST_WRITE(buf, res);
3152  }
3153}
3154
3155PRE_SYSCALL(sigaltstack)(const void *ss, void *oss) {
3156  if (ss != nullptr) {
3157    PRE_READ(ss, struct_stack_t_sz);
3158  }
3159  if (oss != nullptr) {
3160    PRE_WRITE(oss, struct_stack_t_sz);
3161  }
3162}
3163
3164POST_SYSCALL(sigaltstack)(long res, void *ss, void *oss) {
3165  if (res == 0) {
3166    if (oss != nullptr) {
3167      POST_WRITE(oss, struct_stack_t_sz);
3168    }
3169  }
3170}
3171}  // extern "C"
3172
3173#  undef PRE_SYSCALL
3174#  undef PRE_READ
3175#  undef PRE_WRITE
3176#  undef POST_SYSCALL
3177#  undef POST_READ
3178#  undef POST_WRITE
3179
3180#endif  // SANITIZER_LINUX
3181