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