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