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