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

source code of compiler-rt/lib/sanitizer_common/sanitizer_common_syscalls.inc