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