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