Bug 480052 - WARNING: unhandled amd64-freebsd syscall: 580
[valgrind.git] / coregrind / m_syswrap / syswrap-freebsd.c
blobbfb1cf876e8cc798e999751f240a0e5f0577fde3
1 /*--------------------------------------------------------------------*/
2 /*--- FreeBSD-specific syscalls, etc. syswrap-freebsd.c ---*/
3 /*--------------------------------------------------------------------*/
5 /*
6 This file is part of Valgrind, a dynamic binary instrumentation
7 framework.
9 Copyright (C) 2000-2008 Nicholas Nethercote
10 njn@valgrind.org
11 Copyright (C) 2018-2021 Paul Floyd
12 pjfloyd@wanadoo.fr
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, see <http://www.gnu.org/licenses/>.
27 The GNU General Public License is contained in the file COPYING.
30 #if defined(VGO_freebsd)
32 #include "pub_core_basics.h"
33 #include "pub_core_vki.h"
34 #include "pub_core_vkiscnums.h"
35 #include "pub_core_threadstate.h"
36 #include "pub_core_aspacemgr.h"
37 #include "pub_core_debuginfo.h" // VG_(di_notify_*)
38 #include "pub_core_transtab.h" // VG_(discard_translations)
39 #include "pub_core_xarray.h"
40 #include "pub_core_clientstate.h"
41 #include "pub_core_debuglog.h"
42 #include "pub_core_libcbase.h"
43 #include "pub_core_libcassert.h"
44 #include "pub_core_libcfile.h"
45 #include "pub_core_libcprint.h"
46 #include "pub_core_libcproc.h"
47 #include "pub_core_libcsignal.h"
48 #include "pub_core_machine.h"
49 #include "pub_core_mallocfree.h"
50 #include "pub_core_tooliface.h"
51 #include "pub_core_options.h"
52 #include "pub_core_scheduler.h"
53 #include "pub_core_signals.h"
54 #include "pub_core_stacks.h"
55 #include "pub_core_syscall.h"
56 #include "pub_core_syswrap.h"
57 #include "pub_core_inner.h"
58 #include "pub_core_pathscan.h"
59 #include "pub_core_oset.h"
60 #if defined(ENABLE_INNER_CLIENT_REQUEST)
61 #include "pub_core_clreq.h"
62 #endif
64 #include "priv_types_n_macros.h"
65 #include "priv_syswrap-generic.h"
66 #include "priv_syswrap-main.h"
67 #include "priv_syswrap-freebsd.h"
69 static Bool capabiltyMode = False;
71 Bool VG_(get_capability_mode)(void)
73 return capabiltyMode;
77 // Run a thread from beginning to end and return the thread's
78 // scheduler-return-code.
79 static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW)
81 VgSchedReturnCode ret;
82 ThreadId tid = (ThreadId)tidW;
83 Int lwpid = VG_(gettid)();
84 ThreadState* tst = VG_(get_ThreadState)(tid);
86 VG_(debugLog)(1, "syswrap-freebsd",
87 "thread_wrapper(tid=%u,lwpid=%d): entry\n",
88 tid, lwpid);
90 vg_assert(tst->status == VgTs_Init);
92 /* make sure we get the CPU lock before doing anything significant */
93 VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)");
95 if (0) {
96 VG_(printf)("thread tid %u started: stack = %p\n",
97 tid, (void*)&tid);
100 /* Make sure error reporting is enabled in the new thread. */
101 tst->err_disablement_level = 0;
103 VG_TRACK(pre_thread_first_insn, tid);
105 tst->os_state.lwpid = lwpid;
106 /* Set the threadgroup for real. This overwrites the provisional value set
107 in do_clone(). See comments in do_clone for background, also #226116. */
108 tst->os_state.threadgroup = VG_(getpid)();
110 /* Thread created with all signals blocked; scheduler will set the
111 appropriate mask */
113 ret = VG_(scheduler)(tid);
115 vg_assert(VG_(is_exiting)(tid));
117 vg_assert(tst->status == VgTs_Runnable);
118 vg_assert(VG_(is_running_thread)(tid));
120 VG_(debugLog)(1, "syswrap-freebsd",
121 "thread_wrapper(tid=%u,lwpid=%d): exit, schedreturncode %s\n",
122 tid, lwpid, VG_(name_of_VgSchedReturnCode)(ret));
124 /* Return to caller, still holding the lock. */
125 return ret;
129 /* ---------------------------------------------------------------------
130 clone-related stuff
131 ------------------------------------------------------------------ */
133 /* Run a thread all the way to the end, then do appropriate exit actions
134 * (this is the last-one-out-turn-off-the-lights bit).
136 * This is marked as __attribute__((noreturn)). That has the effect of
137 * making clang++ no longer emit the function prologue and epilogue
138 * to save the base pointer.
140 * As far as I can tell clang -O2 does not include -fomit-frame-pointer
141 * However, since from here on the saved base pointer values are
142 * junk tools like FreeBSD pstack that only rely on base pointer
143 * walking will not work. FreeBSD bstack does work, based on GDB and
144 * reading debuginfo.
146 * If you really need a working base pointer modify Makefile.all.am
147 * and add -fno-omit-frame-pointer to AM_CFLAGS_BASE.
149 __attribute__((noreturn))
150 static void run_a_thread_NORETURN ( Word tidW )
152 ThreadId tid = (ThreadId)tidW;
153 VgSchedReturnCode src;
154 Int c;
155 ThreadState* tst;
156 #ifdef ENABLE_INNER_CLIENT_REQUEST
157 Int registered_vgstack_id;
158 #endif
160 VG_(debugLog)(1, "syswrap-freebsd",
161 "run_a_thread_NORETURN(tid=%u): pre-thread_wrapper\n",
162 tid);
164 tst = VG_(get_ThreadState)(tid);
165 vg_assert(tst);
167 /* An thread has two stacks:
168 * the simulated stack (used by the synthetic cpu. Guest process
169 is using this stack).
170 * the valgrind stack (used by the real cpu. Valgrind code is running
171 on this stack).
172 When Valgrind runs as an inner, it must signals that its (real) stack
173 is the stack to use by the outer to e.g. do stacktraces.
175 INNER_REQUEST
176 (registered_vgstack_id
177 = VALGRIND_STACK_REGISTER (tst->os_state.valgrind_stack_base,
178 tst->os_state.valgrind_stack_init_SP));
180 /* Run the thread all the way through. */
181 src = thread_wrapper(tid);
183 VG_(debugLog)(1, "syswrap-freebsd",
184 "run_a_thread_NORETURN(tid=%u): post-thread_wrapper\n",
185 tid);
187 c = VG_(count_living_threads)();
188 vg_assert(c >= 1); /* stay sane */
190 /* Deregister thread's stack. */
191 if (tst->os_state.stk_id != NULL_STK_ID) {
192 VG_(deregister_stack)(tst->os_state.stk_id);
195 // Tell the tool this thread is exiting
196 VG_TRACK( pre_thread_ll_exit, tid );
198 /* If the thread is exiting with errors disabled, complain loudly;
199 doing so is bad (does the user know this has happened?) Also,
200 in all cases, be paranoid and clear the flag anyway so that the
201 thread slot is safe in this respect if later reallocated. This
202 should be unnecessary since the flag should be cleared when the
203 slot is reallocated, in thread_wrapper(). */
204 if (tst->err_disablement_level > 0) {
205 VG_(umsg)(
206 "WARNING: exiting thread has error reporting disabled.\n"
207 "WARNING: possibly as a result of some mistake in the use\n"
208 "WARNING: of the VALGRIND_DISABLE_ERROR_REPORTING macros.\n"
210 VG_(debugLog)(
211 1, "syswrap-freebsd",
212 "run_a_thread_NORETURN(tid=%u): "
213 "WARNING: exiting thread has err_disablement_level = %u\n",
214 tid, tst->err_disablement_level
217 tst->err_disablement_level = 0;
219 if (c == 1) {
221 VG_(debugLog)(1, "syswrap-freebsd",
222 "run_a_thread_NORETURN(tid=%u): "
223 "last one standing\n",
224 tid);
226 /* We are the last one standing. Keep hold of the lock and
227 carry on to show final tool results, then exit the entire system.
228 Use the continuation pointer set at startup in m_main. */
229 ( * VG_(address_of_m_main_shutdown_actions_NORETURN) ) (tid, src);
230 } else {
232 VG_(debugLog)(1, "syswrap-freebsd",
233 "run_a_thread_NORETURN(tid=%u): "
234 "not last one standing\n",
235 tid);
237 /* OK, thread is dead, but others still exist. Just exit. */
239 /* This releases the run lock */
240 VG_(exit_thread)(tid);
241 vg_assert(tst->status == VgTs_Zombie);
242 vg_assert(sizeof(tst->status) == 4);
243 vg_assert(sizeof(tst->os_state.exitcode) == sizeof(Word));
245 INNER_REQUEST (VALGRIND_STACK_DEREGISTER (registered_vgstack_id));
247 /* We have to use this sequence to terminate the thread to
248 prevent a subtle race. If VG_(exit_thread)() had left the
249 ThreadState as Empty, then it could have been reallocated,
250 reusing the stack while we're doing these last cleanups.
251 Instead, VG_(exit_thread) leaves it as Zombie to prevent
252 reallocation. We need to make sure we don't touch the stack
253 between marking it Empty and exiting. Hence the
254 assembler. */
255 #if defined(VGP_x86_freebsd) /* FreeBSD has args on the stack */
256 __asm__ volatile (
257 "movl %1, %0\n" /* set tst->status = VgTs_Empty */
258 "movl %2, %%eax\n" /* set %eax = __NR_thr_exit */
259 "movl %3, %%ebx\n" /* set %ebx = tst->os_state.exitcode */
260 "pushl %%ebx\n" /* arg on stack */
261 "pushl %%ebx\n" /* fake return address */
262 "int $0x80\n" /* thr_exit(tst->os_state.exitcode) */
263 "popl %%ebx\n" /* fake return address */
264 "popl %%ebx\n" /* arg off stack */
265 : "=m" (tst->status)
266 : "n" (VgTs_Empty), "n" (__NR_thr_exit), "m" (tst->os_state.exitcode)
267 : "eax", "ebx"
269 #elif defined(VGP_amd64_freebsd)
270 __asm__ volatile (
271 "movl %1, %0\n" /* set tst->status = VgTs_Empty */
272 "movq %2, %%rax\n" /* set %rax = __NR_thr_exit */
273 "movq %3, %%rdi\n" /* set %rdi = tst->os_state.exitcode */
274 "pushq %%rdi\n" /* fake return address */
275 "syscall\n" /* thr_exit(tst->os_state.exitcode) */
276 "popq %%rdi\n" /* fake return address */
277 : "=m" (tst->status)
278 : "n" (VgTs_Empty), "n" (__NR_thr_exit), "m" (tst->os_state.exitcode)
279 : "rax", "rdi"
281 #else
282 # error Unknown platform
283 #endif
285 VG_(core_panic)("Thread exit failed?\n");
288 /*NOTREACHED*/
289 vg_assert(0);
292 Word ML_(start_thread_NORETURN) ( void* arg )
294 ThreadState* tst = (ThreadState*)arg;
295 ThreadId tid = tst->tid;
297 run_a_thread_NORETURN ( (Word)tid );
298 /*NOTREACHED*/
299 vg_assert(0);
302 /* Allocate a stack for this thread, if it doesn't already have one.
303 They're allocated lazily, and never freed. Returns the initial stack
304 pointer value to use, or 0 if allocation failed. */
305 Addr ML_(allocstack)(ThreadId tid)
307 ThreadState* tst = VG_(get_ThreadState)(tid);
308 VgStack* stack;
309 Addr initial_SP;
311 /* Either the stack_base and stack_init_SP are both zero (in which
312 case a stack hasn't been allocated) or they are both non-zero,
313 in which case it has. */
315 if (tst->os_state.valgrind_stack_base == 0) {
316 vg_assert(tst->os_state.valgrind_stack_init_SP == 0);
319 if (tst->os_state.valgrind_stack_base != 0) {
320 vg_assert(tst->os_state.valgrind_stack_init_SP != 0);
323 /* If no stack is present, allocate one. */
325 if (tst->os_state.valgrind_stack_base == 0) {
326 stack = VG_(am_alloc_VgStack)( &initial_SP );
327 if (stack) {
328 tst->os_state.valgrind_stack_base = (Addr)stack;
329 tst->os_state.valgrind_stack_init_SP = initial_SP;
333 if (0) {
334 VG_(printf)( "stack for tid %u at %p; init_SP=%p\n",
335 tid,
336 (void*)tst->os_state.valgrind_stack_base,
337 (void*)tst->os_state.valgrind_stack_init_SP );
340 return tst->os_state.valgrind_stack_init_SP;
343 /* Allocate a stack for the main thread, and run it all the way to the
344 end. Although we already have a working VgStack
345 (VG_(interim_stack)) it's better to allocate a new one, so that
346 overflow detection works uniformly for all threads.
348 __attribute__((noreturn))
349 void VG_(main_thread_wrapper_NORETURN)(ThreadId tid)
351 Addr sp;
352 VG_(debugLog)(1, "syswrap-freebsd",
353 "entering VG_(main_thread_wrapper_NORETURN)\n");
355 sp = ML_(allocstack)(tid);
356 #if defined(ENABLE_INNER_CLIENT_REQUEST)
358 // we must register the main thread stack before the call
359 // to ML_(call_on_new_stack_0_1), otherwise the outer valgrind
360 // reports 'write error' on the non registered stack.
361 ThreadState* tst = VG_(get_ThreadState)(tid);
362 INNER_REQUEST
363 ((void)
364 VALGRIND_STACK_REGISTER (tst->os_state.valgrind_stack_base,
365 tst->os_state.valgrind_stack_init_SP));
367 #endif
369 /* If we can't even allocate the first thread's stack, we're hosed.
370 Give up. */
371 vg_assert2(sp != 0, "%s", "Cannot allocate main thread's stack.");
373 /* shouldn't be any other threads around yet */
374 vg_assert( VG_(count_living_threads)() == 1 );
376 ML_(call_on_new_stack_0_1)(
377 (Addr)sp, /* stack */
378 0, /* bogus return address */
379 run_a_thread_NORETURN, /* fn to call */
380 (Word)tid /* arg to give it */
383 /*NOTREACHED*/
384 vg_assert(0);
388 /* Do a fork() */
389 SysRes ML_(do_fork) ( ThreadId tid )
391 vki_sigset_t fork_saved_mask;
392 vki_sigset_t mask;
393 SysRes res;
395 /* Block all signals during fork, so that we can fix things up in
396 the child without being interrupted. */
397 VG_(sigfillset)(&mask);
398 VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &fork_saved_mask);
400 VG_(do_atfork_pre)(tid);
402 res = VG_(do_syscall0)( __NR_fork );
404 if (!sr_isError(res)) {
405 if (sr_Res(res) == 0) {
406 /* child */
407 VG_(do_atfork_child)(tid);
409 /* restore signal mask */
410 VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
412 } else {
413 /* parent */
414 VG_(do_atfork_parent)(tid);
416 if (VG_(clo_trace_syscalls)) {
417 VG_(printf)(" clone(fork): process %d created child %lu\n",
418 VG_(getpid)(), sr_Res(res));
421 /* restore signal mask */
422 VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
426 return res;
429 static Addr ML_(make_safe_mask) ( const HChar* malloc_message, Addr mask_pointer )
431 vki_sigset_t* new_mask;
432 const vki_sigset_t* old_mask = (vki_sigset_t *)mask_pointer;
434 if (!ML_(safe_to_deref)(old_mask, sizeof(vki_sigset_t))) {
435 new_mask = (vki_sigset_t*)1; /* Something recognisable to POST() hook. */
436 } else {
437 new_mask = VG_(malloc)(malloc_message, sizeof(vki_sigset_t));
438 *new_mask = *old_mask;
439 VG_(sanitize_client_sigmask)(new_mask);
442 return (Addr)new_mask;
445 static void ML_(free_safe_mask) ( Addr mask_pointer )
447 if (mask_pointer != 0 && mask_pointer != 1) {
448 VG_(free)((vki_sigset_t *) mask_pointer);
453 /* ---------------------------------------------------------------------
454 PRE/POST wrappers for arch-generic, FreeBSD-specific syscalls
455 ------------------------------------------------------------------ */
457 // Nb: See the comment above the generic PRE/POST wrappers in
458 // m_syswrap/syswrap-generic.c for notes about how they work.
460 #define PRE(name) DEFN_PRE_TEMPLATE(freebsd, name)
461 #define POST(name) DEFN_POST_TEMPLATE(freebsd, name)
463 /* On FreeBSD, if any thread calls exit(2), then they are all shut down, pretty
464 * much like linux's exit_group().
466 // SYS_exit 1
467 // void exit(int status);
468 PRE(sys_exit)
470 ThreadId t;
472 PRINT("exit( %" FMT_REGWORD "u )", ARG1);
473 PRE_REG_READ1(void, "exit", int, status);
475 /* Mark all threads (including this one) to exit. */
476 for (t = 1; t < VG_N_THREADS; t++) {
477 if ( /* not alive */ VG_(threads)[t].status == VgTs_Empty ) {
478 continue;
481 //VG_(threads)[t].exitreason = VgSrc_ExitThread;
482 VG_(threads)[t].os_state.exitcode = ARG1;
484 // if (t != tid)
485 // VG_(get_thread_out_of_syscall)(t); /* unblock it, if blocked */
488 VG_(nuke_all_threads_except)( tid, VgSrc_ExitProcess );
489 VG_(reap_threads)(tid);
490 VG_(threads)[tid].exitreason = VgSrc_ExitThread;
492 /* We have to claim the syscall already succeeded. */
493 SET_STATUS_Success(0);
496 // SYS_fork 2
497 // pid_t fork(void);
498 PRE(sys_fork)
500 PRINT("%s", "sys_fork ()");
501 PRE_REG_READ0(pid_t, "fork");
503 SET_STATUS_from_SysRes( ML_(do_fork)(tid) );
504 if (SUCCESS) {
505 /* Thread creation was successful; let the child have the chance
506 to run */
507 *flags |= SfYieldAfter;
511 // SYS_read 3
512 // generic
514 // SYS_write 4
515 // generic
517 // SYS_open 5
518 // generic
520 // SYS_close 6
521 // generic
523 // SYS_wait4 7
524 // generic
526 // SYS_link 9
527 // generic
529 // SYS_unlink 10
530 // generic
532 // SYS_chdir 12
534 // SYS_fchdir 13
535 // generic
537 // SYS_freebsd11_mknod 14
538 // generic
540 // SYS_chmod 15
541 // generic
543 // SYS_chown 16
544 // generic
546 // SYS_break 17
547 // generic
549 // SYS_getpid 20
550 // generic
552 // SYS_mount 21
553 // int mount(const char *type, const char *dir, int flags, void *data);
554 PRE(sys_mount)
556 // Nb: depending on 'flags', the 'type' and 'data' args may be ignored.
557 // We are conservative and check everything, except the memory pointed to
558 // by 'data'.
559 *flags |= SfMayBlock;
560 PRINT( "sys_mount( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
561 PRE_REG_READ4(int, "mount",
562 const char *, type, char *, dir, int, flags,
563 void *, data);
564 PRE_MEM_RASCIIZ( "mount(type)", ARG1);
565 PRE_MEM_RASCIIZ( "mount(path)", ARG2);
568 // SYS_unmount 22
569 // int unmount(const char *dir, int flags);
570 PRE(sys_unmount)
572 PRINT("sys_umount( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
573 PRE_REG_READ2(int, "unmount", const char *, dir, int, flags);
574 PRE_MEM_RASCIIZ( "unmount(path)", ARG1);
577 // SYS_setuid 23
578 // generic
580 // SYS_getuid 24
581 // generic
583 // SYS_geteuid 25
584 // generic
586 // SYS_ptrace 26
587 // int ptrace(int request, pid_t pid, caddr_t addr, int data);
588 PRE(sys_ptrace)
590 struct vki_ptrace_io_desc *io_desc;
591 PRINT("sys_ptrace ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, 0x%" FMT_REGWORD "x, %" FMT_REGWORD "u)", ARG1, ARG2, ARG3, ARG4);
593 PRE_REG_READ4(int, "ptrace", int, request, pid_t, pid, caddr_t, addr, int, data);
595 switch (ARG1) {
596 case VKI_PTRACE_TRACEME:
597 case VKI_PTRACE_READ_I:
598 case VKI_PTRACE_READ_D:
599 case VKI_PTRACE_WRITE_I:
600 case VKI_PTRACE_WRITE_D:
601 break;
603 case VKI_PTRACE_IO:
604 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_ptrace_io_desc));
605 io_desc = (struct vki_ptrace_io_desc *)ARG3;
606 switch (io_desc->piod_op) {
607 case VKI_PIOD_READ_D:
608 case VKI_PIOD_READ_I:
609 PRE_MEM_WRITE( "ptrace", (UWord)io_desc->piod_addr, io_desc->piod_len);
610 break;
611 case VKI_PIOD_WRITE_D:
612 case VKI_PIOD_WRITE_I:
613 PRE_MEM_READ( "ptrace", (UWord)io_desc->piod_addr, io_desc->piod_len);
614 break;
616 break;
618 case VKI_PTRACE_CONTINUE:
619 case VKI_PTRACE_STEP:
620 case VKI_PTRACE_KILL:
621 case VKI_PTRACE_ATTACH:
622 case VKI_PTRACE_DETACH:
623 break;
625 case VKI_PTRACE_GETREGS:
626 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_user_regs_struct));
627 break;
629 case VKI_PTRACE_SETREGS:
630 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_user_regs_struct));
631 break;
633 case VKI_PTRACE_GETFPREGS:
634 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_fpreg));
635 break;
637 case VKI_PTRACE_SETFPREGS:
638 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_fpreg));
639 break;
641 case VKI_PTRACE_GETDBREGS:
642 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_dbreg));
643 break;
645 case VKI_PTRACE_SETDBREGS:
646 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_dbreg));
647 break;
649 case VKI_PTRACE_LWPINFO:
650 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_ptrace_lwpinfo));
651 break;
653 case VKI_PTRACE_GETNUMLWPS:
654 break;
656 case VKI_PTRACE_GETLWPLIST:
657 PRE_MEM_WRITE( "ptrace", ARG3, sizeof(vki_lwpid_t) * ARG4);
658 break;
660 case VKI_PTRACE_SETSTEP:
661 case VKI_PTRACE_CLEARSTEP:
662 case VKI_PTRACE_SUSPEND:
663 case VKI_PTRACE_RESUME:
664 case VKI_PTRACE_TO_SCE:
665 case VKI_PTRACE_TO_SCX:
666 case VKI_PTRACE_SYSCALL:
667 case VKI_PTRACE_VM_TIMESTAMP:
668 break;
669 case VKI_PTRACE_VM_ENTRY:
670 PRE_MEM_WRITE( "ptrace", ARG3, sizeof(struct vki_ptrace_vm_entry));
671 break;
675 POST(sys_ptrace)
677 struct vki_ptrace_io_desc *io_desc;
679 switch (ARG1) {
680 case VKI_PTRACE_TRACEME:
681 case VKI_PTRACE_READ_I:
682 case VKI_PTRACE_READ_D:
683 case VKI_PTRACE_WRITE_I:
684 case VKI_PTRACE_WRITE_D:
685 break;
687 case VKI_PTRACE_IO:
688 io_desc = (struct vki_ptrace_io_desc *)ARG3;
689 switch (io_desc->piod_op) {
690 case VKI_PIOD_READ_D:
691 case VKI_PIOD_READ_I:
692 if ((Word)RES != -1) {
693 POST_MEM_WRITE((UWord)io_desc->piod_addr, io_desc->piod_len);
695 break;
696 case VKI_PIOD_WRITE_D:
697 case VKI_PIOD_WRITE_I:
698 break;
700 break;
702 case VKI_PTRACE_CONTINUE:
703 case VKI_PTRACE_STEP:
704 case VKI_PTRACE_KILL:
705 case VKI_PTRACE_ATTACH:
706 case VKI_PTRACE_DETACH:
707 break;
709 case VKI_PTRACE_GETREGS:
710 if ((Word)RES != -1) {
711 POST_MEM_WRITE(ARG3, sizeof(struct vki_user_regs_struct));
713 break;
715 case VKI_PTRACE_SETREGS:
716 break;
718 case VKI_PTRACE_GETFPREGS:
719 if ((Word)RES != -1) {
720 POST_MEM_WRITE(ARG3, sizeof(struct vki_fpreg));
722 break;
724 case VKI_PTRACE_SETFPREGS:
725 break;
727 case VKI_PTRACE_GETDBREGS:
728 if ((Word)RES != -1) {
729 POST_MEM_WRITE(ARG3, sizeof(struct vki_dbreg));
731 break;
733 case VKI_PTRACE_SETDBREGS:
734 break;
736 case VKI_PTRACE_LWPINFO:
737 if ((Word)RES != -1) {
738 POST_MEM_WRITE(ARG3, sizeof(struct vki_ptrace_lwpinfo));
740 break;
742 case VKI_PTRACE_GETNUMLWPS:
743 break;
745 case VKI_PTRACE_GETLWPLIST:
746 if ((Word)RES != -1) {
747 POST_MEM_WRITE(ARG3, sizeof(vki_lwpid_t) * RES);
749 break;
751 case VKI_PTRACE_SETSTEP:
752 case VKI_PTRACE_CLEARSTEP:
753 case VKI_PTRACE_SUSPEND:
754 case VKI_PTRACE_RESUME:
755 case VKI_PTRACE_TO_SCE:
756 case VKI_PTRACE_TO_SCX:
757 case VKI_PTRACE_SYSCALL:
758 case VKI_PTRACE_VM_TIMESTAMP:
759 break;
761 case VKI_PTRACE_VM_ENTRY:
762 if ((Word)RES != -1) {
763 POST_MEM_WRITE(ARG3, sizeof(struct vki_ptrace_vm_entry));
765 break;
769 // SYS_recvmsg 27
770 // ssize_t recvmsg(int s, struct msghdr *msg, int flags);
771 PRE(sys_recvmsg)
773 *flags |= SfMayBlock;
774 PRINT("sys_recvmsg ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )",SARG1,ARG2,SARG3);
775 PRE_REG_READ3(vki_ssize_t, "recvmsg", int, s, struct msghdr *, msg, int, flags);
776 ML_(generic_PRE_sys_recvmsg)(tid, "recvmsg", (struct vki_msghdr *)ARG2);
779 POST(sys_recvmsg)
782 ML_(generic_POST_sys_recvmsg)(tid, "recvmsg", (struct vki_msghdr *)ARG2, RES);
785 // SYS_sendmsg 28
786 // ssize_t sendmsg(int s, const struct msghdr *msg, int flags);
787 PRE(sys_sendmsg)
789 *flags |= SfMayBlock;
790 PRINT("sys_sendmsg ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
791 PRE_REG_READ3(ssize_t, "sendmsg",
792 int, s, const struct msghdr *, msg, int, flags);
793 ML_(generic_PRE_sys_sendmsg)(tid, "sendmsg", (struct vki_msghdr *)ARG2);
796 // SYS_recvfrom 29
797 // ssize_t recvfrom(int s, void *buf, size_t len, int flags,
798 // struct sockaddr * restrict from, socklen_t * restrict fromlen);
799 PRE(sys_recvfrom)
801 *flags |= SfMayBlock;
802 PRINT("sys_recvfrom ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",SARG1,ARG2,ARG3,SARG4,ARG5,ARG6);
803 PRE_REG_READ6(ssize_t, "recvfrom",
804 int, s, void *, buf, size_t, len, int, flags,
805 struct sockaddr *, from, int *, fromlen);
806 ML_(generic_PRE_sys_recvfrom)(tid, ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
809 POST(sys_recvfrom)
811 vg_assert(SUCCESS);
812 ML_(generic_POST_sys_recvfrom)(tid, VG_(mk_SysRes_Success)(RES),
813 ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
816 // SYS_accept 30
817 // int accept(int s, struct sockaddr * restrict addr,
818 // socklen_t * restrict addrlen);
819 PRE(sys_accept)
821 *flags |= SfMayBlock;
822 PRINT("sys_accept ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
823 PRE_REG_READ3(int, "accept",
824 int, s, struct sockaddr *, addr, int, *addrlen);
825 ML_(generic_PRE_sys_accept)(tid, ARG1,ARG2,ARG3);
828 POST(sys_accept)
830 SysRes r;
831 vg_assert(SUCCESS);
832 r = ML_(generic_POST_sys_accept)(tid, VG_(mk_SysRes_Success)(RES),
833 ARG1,ARG2,ARG3);
834 SET_STATUS_from_SysRes(r);
837 // SYS_getpeername 31
838 // int getpeername(int s, struct sockaddr * restrict name,
839 // socklen_t * restrict namelen);
840 PRE(sys_getpeername)
842 PRINT("sys_getpeername ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3);
843 PRE_REG_READ3(int, "getpeername",
844 int, s, struct sockaddr *, name, socklen_t *, namelen);
845 ML_(generic_PRE_sys_getpeername)(tid, ARG1,ARG2,ARG3);
848 POST(sys_getpeername)
850 vg_assert(SUCCESS);
851 ML_(generic_POST_sys_getpeername)(tid, VG_(mk_SysRes_Success)(RES),
852 ARG1,ARG2,ARG3);
855 // SYS_getsockname 32
856 // int getsockname(int s, struct sockaddr * restrict name,
857 // socklen_t * restrict namelen);
858 PRE(sys_getsockname)
860 PRINT("sys_getsockname ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",SARG1,ARG2,ARG3);
861 PRE_REG_READ3(long, "getsockname",
862 int, s, struct sockaddr *, name, int *, namelen);
863 ML_(generic_PRE_sys_getsockname)(tid, ARG1,ARG2,ARG3);
866 POST(sys_getsockname)
868 vg_assert(SUCCESS);
869 ML_(generic_POST_sys_getsockname)(tid, VG_(mk_SysRes_Success)(RES),
870 ARG1,ARG2,ARG3);
873 // SYS_access 33
874 // generic
876 // SYS_chflags 34
877 // int chflags(const char *path, unsigned long flags)
878 PRE(sys_chflags)
880 PRINT("sys_chflags ( %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2);
881 PRE_REG_READ2(int, "chflags",
882 const char *, path, unsigned long, flags);
883 PRE_MEM_RASCIIZ( "chflags(path)", ARG1 );
886 // SYS_fchflags 35
887 // int fchflags(int fd, unsigned long flags);
888 PRE(sys_fchflags)
890 PRINT("sys_fchflags ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2);
891 PRE_REG_READ2(int, "fchflags", int, fd, unsigned long, flags);
894 // SYS_sync 36
895 // generic
897 // SYS_kill 37
898 // generic
900 // SYS_getppid 39
901 // generic
903 // SYS_dup 41
904 // generic
906 // Pipe on freebsd doesn't have args, and uses dual returns!
907 // SYS_freebsd10_pipe 42
908 // int pipe(void);
909 PRE(sys_pipe)
911 PRINT("%s", "sys_pipe ()");
914 POST(sys_pipe)
916 if (!ML_(fd_allowed)(RES, "pipe", tid, True) ||
917 !ML_(fd_allowed)(RESHI, "pipe", tid, True)) {
918 VG_(close)(RES);
919 VG_(close)(RESHI);
920 SET_STATUS_Failure( VKI_EMFILE );
921 } else {
922 if (VG_(clo_track_fds)) {
923 ML_(record_fd_open_nameless)(tid, RES);
924 ML_(record_fd_open_nameless)(tid, RESHI);
929 // SYS_getegid 43
930 // generic
932 // SYS_profil 44
933 // generic
935 // SYS_ktrace 45
936 // generic
938 // SYS_getgid 47
939 // generic
941 // SYS_getlogin 49
942 // syscall.master refers to namelen and namebuf for the argument names
943 // man getlogin has just getlogin(void) but also
944 // int getlogin_r(char *name, int len);
945 // so let's go with those names
946 PRE(sys_getlogin)
948 PRINT("sys_getlogin ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2);
949 PRE_REG_READ2(int, "getlogin", char *, buf, u_int, len);
950 PRE_MEM_WRITE( "getlogin(name)", ARG1, ARG2 );
953 POST(sys_getlogin)
955 POST_MEM_WRITE(ARG1, ARG2 );
958 // SYS_setlogin 50
959 // int setlogin(const char *name);
960 PRE(sys_setlogin)
962 PRINT("sys_setlogin ( %#" FMT_REGWORD "x )",ARG1);
963 PRE_REG_READ1(long, "setlogin", char *, buf);
964 PRE_MEM_RASCIIZ( "setlogin(buf)", ARG1 );
967 // SYS_acct 51
968 // generic
970 // SYS_sigaltstack 53
971 // generic
973 // SYS_ioctl 54
974 // int ioctl(int fd, unsigned long request, ...);
975 PRE(sys_ioctl)
977 UInt dir = _VKI_IOC_DIR(ARG2);
978 UInt size = _VKI_IOC_SIZE(ARG2);
979 *flags |= SfMayBlock;
980 // @todo PJF presumably the presence of ARG3 depends on ARG2
981 PRINT("sys_ioctl ( %" FMT_REGWORD "u, 0x%" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3);
982 PRE_REG_READ3(int, "ioctl",
983 int, fd, unsigned long, request, unsigned long, arg);
985 /* On FreeBSD, ALL ioctl's are IOR/IOW encoded. Just use the default decoder */
986 if (SimHintiS(SimHint_lax_ioctls, VG_(clo_sim_hints))) {
988 * Be very lax about ioctl handling; the only
989 * assumption is that the size is correct. Doesn't
990 * require the full buffer to be initialized when
991 * writing. Without this, using some device
992 * drivers with a large number of strange ioctl
993 * commands becomes very tiresome.
995 } else if (dir == _VKI_IOC_NONE && size > 0) {
996 static UWord unknown_ioctl[10];
997 static Int moans = sizeof(unknown_ioctl) / sizeof(unknown_ioctl[0]);
998 if (moans > 0 && !VG_(clo_xml)) {
999 /* Check if have not already moaned for this request. */
1000 UInt i;
1001 for (i = 0; i < sizeof(unknown_ioctl)/sizeof(unknown_ioctl[0]); i++) {
1002 if (unknown_ioctl[i] == ARG2) {
1003 break;
1005 if (unknown_ioctl[i] == 0) {
1006 unknown_ioctl[i] = ARG2;
1007 moans--;
1008 VG_(umsg)("Warning: noted but unhandled ioctl 0x%lx"
1009 " with no direction hints.\n", ARG2);
1010 VG_(umsg)(" This could cause spurious value errors to appear.\n");
1011 VG_(umsg)(" See README_MISSING_SYSCALL_OR_IOCTL for "
1012 "guidance on writing a proper wrapper.\n" );
1013 return;
1017 } else {
1018 if ((dir & _VKI_IOC_WRITE) && size > 0) {
1019 PRE_MEM_READ( "ioctl(generic)", ARG3, size);
1021 if ((dir & _VKI_IOC_READ) && size > 0) {
1022 PRE_MEM_WRITE( "ioctl(generic)", ARG3, size);
1026 // The block below is from Ryan Stone
1027 // https://bitbucket.org/rysto32/valgrind-freebsd/commits/5323c22be9f6c71a00e842c3ddfa1fa8a7feb279
1028 // however it drags in hundreds of lines of headers into vki-freebsd.h.
1029 // How stable are these structures? -> maintainability is a concern
1030 // Also there are no testcases for this.
1031 // Hence #if 0
1032 #if 0
1033 /* Handle specific ioctls which pass structures which may have pointers to other
1034 buffers */
1035 switch (ARG2 /* request */) {
1036 case VKI_SIOCGIFMEDIA:
1037 if (ARG3) {
1038 struct vki_ifmediareq* imr = (struct vki_ifmediareq*)ARG3;
1039 if (imr->ifm_ulist) {
1040 PRE_MEM_WRITE("ioctl(SIOCGIFMEDIA).ifm_ulist",
1041 (Addr)(imr->ifm_ulist), imr->ifm_count * sizeof(int));
1044 break;
1046 case VKI_PCIOCGETCONF:
1047 if (ARG3) {
1048 struct vki_pci_conf_io* pci = (struct vki_pci_conf_io*)ARG3;
1049 PRE_MEM_READ("ioctl(PCIOCGETCONF).patterns",
1050 (Addr)(pci->patterns), pci->pat_buf_len);
1051 PRE_MEM_WRITE("ioctl(PCIOCGETCONF).matches",
1052 (Addr)(pci->matches), pci->match_buf_len);
1054 break;
1056 case VKI_CAMIOCOMMAND:
1057 if (ARG3) {
1058 union vki_ccb* ccb = (union vki_ccb*)ARG3;
1059 if (ccb->ccb_h.func_code == VKI_XPT_DEV_MATCH) {
1060 PRE_MEM_WRITE("ioctl(CAMIOCOMMAND:XPT_DEV_MATCH).matches",
1061 (Addr)(ccb->cdm.matches), ccb->cdm.match_buf_len);
1062 } else if (ccb->ccb_h.func_code == VKI_XPT_SCSI_IO) {
1063 struct vki_ccb_scsiio* scsiio = (struct vki_ccb_scsiio*)ccb;
1064 if (scsiio->dxfer_len) {
1065 if ((scsiio->ccb_h.flags & VKI_CAM_DIR_MASK) == VKI_CAM_DIR_IN) {
1066 PRE_MEM_WRITE("ioctl(CAMIOCOMMAND:XPT_SCSI_IO).data_ptr",
1067 (Addr)(scsiio->data_ptr), scsiio->dxfer_len);
1068 } else if ((scsiio->ccb_h.flags & VKI_CAM_DIR_MASK) == VKI_CAM_DIR_OUT) {
1069 PRE_MEM_READ("ioctl(CAMIOCOMMAND:XPT_SCSI_IO).data_ptr",
1070 (Addr)(scsiio->data_ptr), scsiio->dxfer_len);
1073 } else if (ccb->ccb_h.func_code == VKI_XPT_GDEV_TYPE ||
1074 ccb->ccb_h.func_code == VKI_XPT_PATH_INQ ||
1075 ccb->ccb_h.func_code == VKI_XPT_GET_TRAN_SETTINGS) {
1076 // do nothing
1077 } else {
1078 VG_(message)(Vg_UserMsg,
1079 "Warning: unhandled ioctl CAMIOCOMMAND function 0x%lx\n",
1080 ccb->ccb_h.func_code);
1083 break;
1085 #endif
1088 POST(sys_ioctl)
1090 UInt dir = _VKI_IOC_DIR(ARG2);
1091 UInt size = _VKI_IOC_SIZE(ARG2);
1092 vg_assert(SUCCESS);
1093 if (size > 0 && (dir & _VKI_IOC_READ)
1094 && RES == 0 && ARG3 != (Addr)NULL) {
1095 POST_MEM_WRITE(ARG3, size);
1098 #if 0
1099 /* Handle specific ioctls which pass structures which may have pointers to other
1100 buffers */
1101 switch (ARG2 /* request */) {
1102 case VKI_SIOCGIFMEDIA:
1103 if (ARG3) {
1104 struct vki_ifmediareq* imr = (struct vki_ifmediareq*)ARG3;
1105 if (imr->ifm_ulist) {
1106 POST_MEM_WRITE((Addr)(imr->ifm_ulist), imr->ifm_count * sizeof(int));
1109 break;
1111 case VKI_PCIOCGETCONF:
1112 if (ARG3) {
1113 struct vki_pci_conf_io* pci = (struct vki_pci_conf_io*)ARG3;
1114 POST_MEM_WRITE((Addr)(pci->matches), pci->num_matches * sizeof(struct vki_pci_conf));
1116 break;
1118 case VKI_CAMIOCOMMAND:
1119 if (ARG3) {
1120 union vki_ccb* ccb = (union vki_ccb*)ARG3;
1121 if (ccb->ccb_h.func_code == VKI_XPT_DEV_MATCH) {
1122 POST_MEM_WRITE((Addr)(ccb->cdm.matches), ccb->cdm.num_matches*sizeof(struct vki_dev_match_result));
1123 } else if (ccb->ccb_h.func_code == VKI_XPT_SCSI_IO) {
1124 struct vki_ccb_scsiio* scsiio = (struct vki_ccb_scsiio*)ccb;
1125 if (scsiio->dxfer_len) {
1126 if ((scsiio->ccb_h.flags & VKI_CAM_DIR_MASK) == VKI_CAM_DIR_IN) {
1127 POST_MEM_WRITE((Addr)(scsiio->data_ptr), scsiio->dxfer_len);
1132 break;
1134 #endif
1137 // SYS_reboot 55
1138 // int reboot(int howto);
1139 PRE(sys_reboot)
1141 PRINT("sys_reboot ( %" FMT_REGWORD "d )", SARG1);
1142 PRE_REG_READ1(int, "reboot", int, howto);
1145 // SYS_revoke 56
1146 // int revoke(const char *path);
1147 PRE(sys_revoke)
1149 PRINT("sys_revoke ( %#" FMT_REGWORD "x(%s) )", ARG1, (char*)ARG1);
1150 PRE_REG_READ1(long, "revoke", const char *, path);
1151 PRE_MEM_RASCIIZ( "revoke(path)", ARG1);
1154 // SYS_symlink 57
1155 // generic
1157 static void do_readlink(const HChar* path, HChar *buf, SizeT bufsize, SyscallStatus* status, Bool* curproc_file)
1159 HChar name[30];
1160 VG_(sprintf)(name, "/proc/%d/file", VG_(getpid)());
1161 if (ML_(safe_to_deref)(path, 1)
1162 && (VG_(strcmp)(path, name) == 0
1163 || VG_(strcmp)(path, "/proc/curproc/file") == 0)) {
1164 vg_assert(VG_(resolved_exename));
1165 Int len = VG_(snprintf)(buf, bufsize, "%s", VG_(resolved_exename));
1166 SET_STATUS_Success(len);
1167 *curproc_file = True;
1171 // SYS_readlink 58
1172 // ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsiz);
1173 PRE(sys_readlink)
1175 FUSE_COMPATIBLE_MAY_BLOCK();
1176 Word saved = SYSNO;
1177 Bool curproc_file = False;
1179 PRINT("sys_readlink ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %llu )",
1180 ARG1, (char*)(Addr)ARG1, ARG2, (ULong)ARG3);
1181 PRE_REG_READ3(long, "readlink",
1182 const char *, path, char *, buf, int, bufsiz);
1183 PRE_MEM_RASCIIZ( "readlink(path)", ARG1 );
1184 PRE_MEM_WRITE( "readlink(buf)", ARG2,ARG3 );
1186 if (VG_(have_slash_proc) == True)
1189 * Handle the case where readlink is looking at /proc/curproc/file or
1190 * /proc/<pid>/file
1192 do_readlink((const HChar *)ARG1, (HChar *)ARG2, (SizeT)ARG3, status, &curproc_file);
1195 if (!curproc_file) {
1196 /* Normal case */
1197 SET_STATUS_from_SysRes( VG_(do_syscall3)(saved, ARG1, ARG2, ARG3));
1199 if (SUCCESS && RES > 0) {
1200 POST_MEM_WRITE( ARG2, RES );
1204 // SYS_execve 59
1205 // generic
1207 // SYS_umask 60
1208 // generic
1210 // SYS_chroot 61
1211 // generic
1213 // SYS_msync 65
1214 // generic
1216 // SYS_vfork 66
1217 // pid_t vfork(void);
1218 PRE(sys_vfork)
1220 PRINT("%s", "sys_vfork ()");
1221 PRE_REG_READ0(pid_t, "vfork");
1223 /* Pretend vfork == fork. Not true, but will have to do. */
1224 SET_STATUS_from_SysRes( ML_(do_fork)(tid) );
1225 if (SUCCESS) {
1226 /* Thread creation was successful; let the child have the chance
1227 to run */
1228 *flags |= SfYieldAfter;
1232 // SYS_sbrk 69
1233 // void * sbrk(intptr_t incr);
1234 PRE(sys_sbrk)
1236 PRINT("sys_sbrk ( %#" FMT_REGWORD "x )",ARG1);
1237 PRE_REG_READ1(void*, "sbrk", vki_intptr_t, incr);
1240 // SYS_freebsd11_vadvise 72
1241 // @todo maybe
1243 // SYS_munmap 73
1244 // generic
1246 // SYS_mprotect 74
1247 // generic
1249 // SYS_madvise 75
1250 // generic
1252 // SYS_mincore 78
1253 // generic
1255 // SYS_getgroups 79
1256 // generic
1258 // SYS_setgroups 80
1259 // generic
1261 // SYS_getpgrp 81
1262 // generic
1264 // SYS_setpgid 82
1265 // generic
1267 // SYS_setitimer 83
1268 // generic
1270 // SYS_swapon 85
1271 // int swapon(const char *special);
1272 PRE(sys_swapon)
1274 PRINT("sys_swapon ( %#" FMT_REGWORD "x(%s) )", ARG1,(char*)ARG1);
1275 PRE_REG_READ1(int, "swapon", const char*, special );
1276 PRE_MEM_RASCIIZ( "swapon(special)", ARG1 );
1279 // SYS_getitimer 86
1280 // generic
1282 // SYS_getdtablesize 89
1283 // int getdtablesize(void);
1284 PRE(sys_getdtablesize)
1286 PRINT("%s", "sys_getdtablesize ( )");
1287 PRE_REG_READ0(long, "getdtablesize");
1290 // SYS_dup2 90
1291 // generic
1293 // SYS_fcntl 92
1294 // int fcntl(int fd, int cmd, ...);
1295 PRE(sys_fcntl)
1297 switch (ARG2) {
1298 // These ones ignore ARG3.
1299 case VKI_F_GETFD:
1300 case VKI_F_GETFL:
1301 case VKI_F_GETOWN:
1302 case VKI_F_GET_SEALS:
1303 case VKI_F_ISUNIONSTACK:
1304 PRINT("sys_fcntl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,SARG2);
1305 PRE_REG_READ2(int, "fcntl", int, fd, int, cmd);
1306 break;
1308 // These ones use ARG3 as "arg".
1309 case VKI_F_DUPFD:
1310 case VKI_F_DUPFD_CLOEXEC:
1311 case VKI_F_SETFD:
1312 case VKI_F_SETFL:
1313 case VKI_F_SETOWN:
1314 case VKI_F_READAHEAD:
1315 case VKI_F_RDAHEAD:
1316 case VKI_F_ADD_SEALS:
1317 PRINT("sys_fcntl[ARG3=='arg'] ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,SARG2,SARG3);
1318 PRE_REG_READ3(int, "fcntl",
1319 int, fd, int, cmd, int, arg);
1320 break;
1322 // These ones use ARG3 as "lock" - obsolete.
1323 case VKI_F_OSETLKW:
1324 *flags |= SfMayBlock;
1325 /* FALLTHROUGH */
1326 case VKI_F_OGETLK:
1327 case VKI_F_OSETLK:
1328 PRINT("sys_fcntl[ARG3=='lock'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
1329 PRE_REG_READ3(int, "fcntl",
1330 int, fd, int, cmd,
1331 struct oflock *, lock);
1332 break;
1334 // This one uses ARG3 as "oldd" and ARG4 as "newd".
1335 case VKI_F_DUP2FD:
1336 case VKI_F_DUP2FD_CLOEXEC:
1337 PRINT("sys_fcntl[ARG3=='oldd', ARG4=='newd'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",
1338 ARG1,ARG2,ARG3,ARG4);
1339 PRE_REG_READ4(int, "fcntl",
1340 int, fd, int, cmd,
1341 unsigned long, oldd, unsigned long, newd);
1342 break;
1344 // These ones use ARG3 as "lock".
1345 case VKI_F_SETLKW:
1346 *flags |= SfMayBlock;
1347 /* FALLTHROUGH */
1348 case VKI_F_GETLK:
1349 case VKI_F_SETLK:
1350 case VKI_F_SETLK_REMOTE:
1351 PRINT("sys_fcntl[ARG3=='lock'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
1352 PRE_REG_READ3(int, "fcntl",
1353 int, fd, int, cmd,
1354 struct flock *, lock);
1355 break;
1356 case VKI_F_KINFO:
1357 PRINT("sys_fcntl[ARG3=='kinfo_file'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
1358 PRE_REG_READ3(int, "fcntl",
1359 int, fd, int, cmd,
1360 struct vki_kinfo_file *, kinfo);
1361 if (ARG3) {
1362 struct vki_kinfo_file* p_kinfo_file = (struct vki_kinfo_file*)ARG3;
1363 PRE_MEM_WRITE("fcntl(ARG3=='kinfo_file)", ARG3, p_kinfo_file->vki_kf_structsize);
1365 break;
1367 default:
1368 PRINT("sys_fcntl[UNKNOWN] ( %lu, %lu, %lu )", ARG1,ARG2,ARG3);
1369 I_die_here;
1373 POST(sys_fcntl)
1375 vg_assert(SUCCESS);
1376 if (ARG2 == VKI_F_DUPFD) {
1377 if (!ML_(fd_allowed)(RES, "fcntl(DUPFD)", tid, True)) {
1378 VG_(close)(RES);
1379 SET_STATUS_Failure( VKI_EMFILE );
1380 } else {
1381 if (VG_(clo_track_fds)) {
1382 ML_(record_fd_open_named)(tid, RES);
1385 } else if (ARG2 == VKI_F_DUPFD_CLOEXEC) {
1386 if (!ML_(fd_allowed)(RES, "fcntl(DUPFD_CLOEXEC)", tid, True)) {
1387 VG_(close)(RES);
1388 SET_STATUS_Failure( VKI_EMFILE );
1389 } else {
1390 if (VG_(clo_track_fds)) {
1391 ML_(record_fd_open_named)(tid, RES);
1397 // SYS_select 93
1398 // generic
1400 // SYS_fsync 95
1401 // generic
1403 // SYS_setpriority 9
1404 // generic
1406 // SYS_socket 97
1407 // int socket(int domain, int type, int protocol);
1408 PRE(sys_socket)
1410 PRINT("sys_socket ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %" FMT_REGWORD "d )",SARG1,SARG2,SARG3);
1411 PRE_REG_READ3(int, "socket", int, domain, int, type, int, protocol);
1414 POST(sys_socket)
1416 SysRes r;
1417 vg_assert(SUCCESS);
1418 r = ML_(generic_POST_sys_socket)(tid, VG_(mk_SysRes_Success)(RES));
1419 SET_STATUS_from_SysRes(r);
1422 // SYS_connect 98
1423 // int connect(int s, const struct sockaddr *name, socklen_t namelen);
1424 PRE(sys_connect)
1426 *flags |= SfMayBlock;
1427 PRINT("sys_connect ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
1428 PRE_REG_READ3(int, "connect",
1429 int, s, const struct sockaddr *, name, int, namelen);
1430 ML_(generic_PRE_sys_connect)(tid, ARG1,ARG2,ARG3);
1433 // SYS_getpriority 100
1434 // generic
1436 // SYS_bind 104
1437 // int bind(int s, const struct sockaddr *addr, socklen_t addrlen);
1438 PRE(sys_bind)
1440 PRINT("sys_bind ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
1441 PRE_REG_READ3(int, "bind",
1442 int, s, struct sockaddr *, addr, int, addrlen);
1443 ML_(generic_PRE_sys_bind)(tid, ARG1,ARG2,ARG3);
1446 // SYS_setsockopt 105
1447 // int setsockopt(int s, int level, int optname, const void *optval,
1448 // socklen_t optlen);
1449 PRE(sys_setsockopt)
1451 PRINT("sys_setsockopt ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",SARG1,SARG2,SARG3,ARG4,ARG5);
1452 PRE_REG_READ5(int, "setsockopt",
1453 int, s, int, level, int, optname,
1454 const void *, optval, vki_socklen_t, optlen);
1455 ML_(generic_PRE_sys_setsockopt)(tid, ARG1,ARG2,ARG3,ARG4,ARG5);
1458 // SYS_listen 106
1459 // int listen(int s, int backlog);
1460 PRE(sys_listen)
1462 PRINT("sys_listen ( %" FMT_REGWORD "d, %" FMT_REGWORD "d )",SARG1,SARG2);
1463 PRE_REG_READ2(int, "listen", int, s, int, backlog);
1466 //SYS_gettimeofday 116
1467 // generic
1469 // SYS_getrusage 117
1470 // generic
1472 // SYS_getsockopt 118
1473 // int getsockopt(int s, int level, int optname, void * restrict optval,
1474 // socklen_t * restrict optlen);
1475 PRE(sys_getsockopt)
1477 Addr optval_p = ARG4;
1478 Addr optlen_p = ARG5;
1479 PRINT("sys_getsockopt ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4,ARG5);
1480 PRE_REG_READ5(int, "getsockopt",
1481 int, s, int, level, int, optname,
1482 void *, optval, int, *optlen);
1483 if (optval_p != (Addr)NULL) {
1484 ML_(buf_and_len_pre_check) ( tid, optval_p, optlen_p,
1485 "getsockopt(optval)",
1486 "getsockopt(optlen)" );
1490 POST(sys_getsockopt)
1492 Addr optval_p = ARG4;
1493 Addr optlen_p = ARG5;
1494 vg_assert(SUCCESS);
1495 if (optval_p != (Addr)NULL) {
1496 ML_(buf_and_len_post_check) ( tid, VG_(mk_SysRes_Success)(RES),
1497 optval_p, optlen_p,
1498 "getsockopt(optlen_out)" );
1502 // SYS_readv 120
1503 // generic
1505 // SYS_writev 121
1506 // generic
1508 // SYS_settimeofday 122
1509 // generic
1511 // SYS_fchown 123
1512 // generic
1514 // SYS_fchmod 124
1515 // generic
1517 // SYS_setreuid 126
1518 // generic
1520 // SYS_setregid 127
1521 // generic
1523 // SYS_rename 128
1524 // generic
1526 // SYS_flock 131
1527 // generic
1529 // SYS_mkfifo 132
1530 // int mkfifo(const char *path, mode_t mode);
1531 PRE(sys_mkfifo)
1533 PRINT("sys_mkfifo ( %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x, 0x%" FMT_REGWORD "x )", ARG1, (char *)ARG1, ARG2, ARG3 );
1534 PRE_REG_READ2(int, "mkfifo", const char *, path, int, mode);
1535 PRE_MEM_RASCIIZ( "mkfifo(path)", ARG1 );
1538 // SYS_sendto 133
1539 // ssize_t sendto(int s, const void *msg, size_t len, int flags,
1540 // const struct sockaddr *to, socklen_t tolen);
1541 PRE(sys_sendto)
1543 *flags |= SfMayBlock;
1544 PRINT("sys_sendto ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
1545 PRE_REG_READ6(ssize_t, "sendto",
1546 int, s, const void *, msg, int, len,
1547 int, flags,
1548 const struct sockaddr *, to, socklen_t, tolen);
1549 ML_(generic_PRE_sys_sendto)(tid, ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
1552 // SYS_shutdown 134
1553 // int shutdown(int s, int how);
1554 PRE(sys_shutdown)
1556 *flags |= SfMayBlock;
1557 PRINT("sys_shutdown ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2);
1558 PRE_REG_READ2(int, "shutdown", int, s, int, how);
1561 // SYS_socketpair 135
1562 // int socketpair(int domain, int type, int protocol, int *sv);
1563 PRE(sys_socketpair)
1565 PRINT("sys_socketpair ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
1566 PRE_REG_READ4(int, "socketpair",
1567 int, domain, int, type, int, protocol, int *, sv);
1568 ML_(generic_PRE_sys_socketpair)(tid, ARG1,ARG2,ARG3,ARG4);
1571 POST(sys_socketpair)
1573 vg_assert(SUCCESS);
1574 ML_(generic_POST_sys_socketpair)(tid, VG_(mk_SysRes_Success)(RES),
1575 ARG1,ARG2,ARG3,ARG4);
1578 // SYS_mkdir 136
1579 // generic
1581 // SYS_rmdir 137
1582 // generic
1584 // SYS_utimes 138
1585 // generic
1587 // SYS_adjtime 140
1588 // int adjtime(const struct timeval *delta, struct timeval *olddelta);
1589 PRE(sys_adjtime)
1591 PRINT("sys_adjtime ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
1592 PRE_REG_READ2(int, "adjtime",
1593 const struct vki_timeval *, delta, struct vki_timeval *, olddelta);
1594 PRE_MEM_READ("adjtime(delta)", ARG1, sizeof(struct vki_timeval));
1595 if (ARG2) {
1596 PRE_MEM_WRITE("adjtime(olddelta)", ARG1, sizeof(struct vki_timeval));
1600 POST(sys_adjtime)
1602 if (ARG2) {
1603 POST_MEM_WRITE(ARG1, sizeof(struct vki_timeval));
1607 // SYS_setsid 147
1608 // generic
1610 // SYS_quotactl 148
1611 /* int quotactl(const char *path, int cmd, int id, void *addr); */
1612 PRE(sys_quotactl)
1614 PRINT("sys_quotactl ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3, ARG4);
1615 switch (ARG2) {
1616 case VKI_Q_QUOTAON:
1617 case VKI_Q_SETQUOTA:
1618 case VKI_Q_SETUSE:
1620 case VKI_Q_GETQUOTASIZE:
1621 PRE_REG_READ4(int, "quotactl",
1622 const char *, path, int, cmd, int, id,
1623 void *, addr);
1624 PRE_MEM_RASCIIZ( "quotactl(path)", ARG1 );
1625 break;
1626 case VKI_Q_GETQUOTA:
1627 if (VG_(tdict).track_pre_reg_read) {
1629 PRRSN;
1630 PRA1("quotactl",const char*,path);
1631 PRA2("quotactl",int,cmd);
1632 PRA4("quotactl",void*,addr);
1634 break;
1635 case VKI_Q_QUOTAOFF:
1636 case VKI_Q_SYNC:
1637 PRE_REG_READ2(int, "quotactl",
1638 const char *, path, int, cmd);
1639 break;
1640 default:
1641 break;
1645 // SYS_nlm_syscall 154
1646 // syscall.master says ; 154 is initialised by the NLM code, if present.
1647 // @todo
1649 // SYS_nfssvc 155
1650 // int nfssvc(int flags, void *argstructp);
1651 // lengthy manpage, at least 3 types of struct that argstructp can point to
1652 // @todo
1654 // SYS_lgetfh 160
1655 // int lgetfh(const char *path, fhandle_t *fhp);
1656 PRE(sys_lgetfh)
1658 PRINT("sys_lgetfh ( %#" FMT_REGWORD "x, %" FMT_REGWORD "x ", ARG1, ARG2);
1659 PRE_REG_READ2(int, "lgetfh", const char*, path, vki_fhandle_t*, fhp);
1660 PRE_MEM_RASCIIZ( "lgetfh(path)", ARG1 );
1661 PRE_MEM_WRITE("lgetfh(fhp)", ARG2, sizeof(vki_fhandle_t));
1664 POST(sys_lgetfh)
1666 POST_MEM_WRITE(ARG2, sizeof(vki_fhandle_t));
1669 // SYS_getfh 161
1670 // int getfh(const char *path, fhandle_t *fhp);
1671 PRE(sys_getfh)
1673 PRINT("sys_getfh ( %#" FMT_REGWORD "x, %" FMT_REGWORD "x ", ARG1, ARG2);
1674 PRE_REG_READ2(int, "getfh", const char*, path, vki_fhandle_t*, fhp);
1675 PRE_MEM_RASCIIZ( "getfh(path)", ARG1 );
1676 PRE_MEM_WRITE("getfh(fhp)", ARG2, sizeof(vki_fhandle_t));
1679 POST(sys_getfh)
1681 POST_MEM_WRITE(ARG2, sizeof(vki_fhandle_t));
1684 #if (FREEBSD_VERS <= FREEBSD_10)
1685 // 162
1686 // int getdomainname(char *domainname, int len);
1687 PRE(sys_freebsd4_getdomainname)
1689 PRINT("sys_freebsd4_getdomainname ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2);
1690 PRE_REG_READ2(int, "getdomainname",
1691 char *, domainname, int, len);
1692 PRE_MEM_WRITE( "getdomainname(domainname)", ARG1, ARG2 );
1695 POST(sys_freebsd4_getdomainname)
1697 if (ARG1 != 0) {
1698 POST_MEM_WRITE( ARG1, ARG2 );
1702 // 163
1703 // int setdomainname(char *domainname, int len);
1704 PRE(sys_freebsd4_setdomainname)
1706 PRINT("sys_freebsd4_setdomainname ( %#" FMT_REGWORD "x )",ARG1);
1707 PRE_REG_READ2(int, "setdomainname", char *, domainname, int, len);
1708 PRE_MEM_RASCIIZ( "setdomainname(domainname)", ARG1 );
1711 // 164
1712 // int uname(struct utsname *name);
1713 PRE(sys_freebsd4_uname)
1715 PRINT("sys_freebsd4_uname ( %#" FMT_REGWORD "x )", ARG1);
1716 PRE_REG_READ1(int, "uname", struct utsname *, name);
1717 PRE_MEM_WRITE( "uname(name)", ARG1, sizeof(struct vki_utsname) );
1720 POST(sys_freebsd4_uname)
1722 if (ARG1 != 0) {
1723 POST_MEM_WRITE( ARG1, sizeof(struct vki_utsname) );
1726 #endif
1728 // SYS_sysarch 165
1729 // x86/amd64
1731 // SYS_rtprio 166
1732 PRE(sys_rtprio)
1734 PRINT( "sys_rtprio ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1, ARG2, ARG3 );
1735 PRE_REG_READ3(int, "rtprio",
1736 int, function, pid_t, pid, struct rtprio *, rtp);
1737 if (ARG1 == VKI_RTP_SET) {
1738 PRE_MEM_READ( "rtprio(rtp#set)", ARG3, sizeof(struct vki_rtprio));
1739 } else if (ARG1 == VKI_RTP_LOOKUP) {
1740 PRE_MEM_WRITE( "rtprio(rtp#lookup)", ARG3, sizeof(struct vki_rtprio));
1741 } else {
1742 /* PHK ?? */
1746 POST(sys_rtprio)
1748 if (ARG1 == VKI_RTP_LOOKUP && RES == 0) {
1749 POST_MEM_WRITE( ARG3, sizeof(struct vki_rtprio));
1753 // freebsd6_pread 173 FREEBSD_VERS <= 10
1754 // x86/amd64
1756 // freebsd6_pwrite 174 FREEBSD_VERS <= 10
1757 // x86/amd64
1759 // SYS_setfib 175
1760 // int setfib(int fib);
1761 PRE(sys_setfib)
1763 PRINT("sys_setfib ( %" FMT_REGWORD "d )", SARG1);
1764 PRE_REG_READ1(int, "setfib", int, fib);
1767 // SYS_ntp_adjtime 176
1768 // int ntp_adjtime(struct timex *);
1769 // @todo
1771 // SYS_setgid 181
1772 // generic
1774 // SYS_setegid 182
1775 // int setegid(gid_t egid);
1776 PRE(sys_setegid)
1778 PRINT("sys_setegid ( %" FMT_REGWORD "u )", ARG1);
1779 PRE_REG_READ1(int, "setegid", vki_gid_t, gid);
1782 // SYS_seteuid 183
1783 // int seteuid(uid_t euid);
1784 PRE(sys_seteuid)
1786 PRINT("sys_seteuid ( %" FMT_REGWORD "u )", ARG1);
1787 PRE_REG_READ1(long, "seteuid", vki_uid_t, uid);
1791 #if (FREEBSD_VERS >= FREEBSD_12)
1793 // SYS_freebsd11_stat 188
1794 // int stat(char *path, struct freebsd11_stat *sb);
1795 PRE(sys_freebsd11_stat)
1797 PRINT("sys_freebsd11_stat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1798 PRE_REG_READ2(int, "stat", char *, path, struct freebsd11_stat *, sb);
1799 PRE_MEM_RASCIIZ( "stat(path)", ARG1 );
1800 PRE_MEM_WRITE( "stat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1803 POST(sys_freebsd11_stat)
1805 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1808 // SYS_freebsd11_fstat 189
1809 // int fstat(int fd, struct stat *sb);
1810 PRE(sys_freebsd11_fstat)
1812 PRINT("sys_freebsd11_fstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
1813 PRE_REG_READ2(int, "fstat", int, fd, struct stat *, sb);
1814 PRE_MEM_WRITE( "fstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1817 POST(sys_freebsd11_fstat)
1819 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1822 // SYS_freebsd11_lstat 190
1823 // int lstat(const char * restrict path, struct stat * restrict sb);
1824 PRE(sys_freebsd11_lstat)
1826 PRINT("sys_freebsd11_lstat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1827 PRE_REG_READ2(sb, "lstat", const char *, path, struct freebsd11_stat *, sb);
1828 PRE_MEM_RASCIIZ( "lstat(path)", ARG1 );
1829 PRE_MEM_WRITE( "lstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1832 POST(sys_freebsd11_lstat)
1834 vg_assert(SUCCESS);
1835 if (RES == 0) {
1836 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1840 #else
1842 PRE(sys_stat)
1844 PRINT("sys_stat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1845 PRE_REG_READ2(int, "stat", char *, path, struct stat *, sb);
1846 PRE_MEM_RASCIIZ( "stat(path)", ARG1 );
1847 PRE_MEM_WRITE( "stat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1850 POST(sys_stat)
1852 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1856 PRE(sys_fstat)
1858 PRINT("sys_fstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
1859 PRE_REG_READ2(int, "fstat", int, fd, struct stat *, sb);
1860 PRE_MEM_WRITE( "fstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1863 POST(sys_fstat)
1865 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1868 PRE(sys_lstat)
1870 PRINT("sys_lstat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1871 PRE_REG_READ2(int, "lstat", const char *, path, struct stat *, sb);
1872 PRE_MEM_RASCIIZ( "lstat(path)", ARG1 );
1873 PRE_MEM_WRITE( "lstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1876 POST(sys_lstat)
1878 vg_assert(SUCCESS);
1879 if (RES == 0) {
1880 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1884 #endif
1886 // SYS_pathconf 191
1887 // long pathconf(const char *path, int name);
1888 PRE(sys_pathconf)
1890 PRINT("sys_pathconf ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )",ARG1,(char *)ARG1,ARG2);
1891 PRE_REG_READ2(long, "pathconf", char *, path, int, name);
1892 PRE_MEM_RASCIIZ( "pathconf(path)", ARG1 );
1895 // SYS_fpathconf 192
1896 // long fpathconf(int fd, int name);
1897 PRE(sys_fpathconf)
1899 PRINT("sys_fpathconf ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2);
1900 PRE_REG_READ2(long, "fpathconf", int, fd, int, name);
1903 // SYS_getrlimit 194
1904 // generic
1906 // SYS_setrlimit 195
1907 // generic
1910 // SYS_freebsd11_getdirentries 196
1911 // int getdirentries(int fd, char *buf, int nbytes, long *basep);
1912 #if (FREEBSD_VERS >= FREEBSD_12)
1913 PRE(sys_freebsd11_getdirentries)
1915 *flags |= SfMayBlock;
1916 PRINT("sys_freebsd11_getdirentries ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
1917 PRE_REG_READ4(int, "getdirentries",
1918 int, fd, char *, buf,
1919 int, nbytes,
1920 long *, basep);
1921 PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 );
1922 if (ARG4) {
1923 PRE_MEM_WRITE( "getdirentries(basep)", ARG4, sizeof(long) );
1927 POST(sys_freebsd11_getdirentries)
1929 vg_assert(SUCCESS);
1930 if (RES > 0) {
1931 POST_MEM_WRITE( ARG2, RES );
1932 if ( ARG4 != 0 ) {
1933 POST_MEM_WRITE( ARG4, sizeof (long));
1937 #else
1938 PRE(sys_getdirentries)
1940 *flags |= SfMayBlock;
1941 PRINT("sys_getdirentries ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
1942 PRE_REG_READ4(int, "getdirentries",
1943 int, fd, char *, buf,
1944 int, nbytes,
1945 long *, basep);
1946 PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 );
1947 if (ARG4)
1948 PRE_MEM_WRITE( "getdirentries(basep)", ARG4, sizeof(long) );
1951 POST(sys_getdirentries)
1953 vg_assert(SUCCESS);
1954 if (RES > 0) {
1955 POST_MEM_WRITE( ARG2, RES );
1956 if ( ARG4 != 0 )
1957 POST_MEM_WRITE( ARG4, sizeof (long));
1960 #endif
1962 // SYS_freebsd6_mmap 197
1963 // amd64 / x86
1966 // SYS___syscall 198
1967 // special handling
1969 // freebsd6_lseek 199 FREEBSD_VERS <= 10
1970 // x86/amd64
1972 // freebsd6_truncate 200 FREEBSD_VERS <= 10
1973 // x86/amd64
1975 // freebsd6_ftruncate 201 FREEBSD_VERS <= 10
1976 // x86/amd64
1978 static Bool sysctl_kern_ps_strings(SizeT* out, SizeT* outlen)
1980 Word tmp = -1;
1981 const struct auxv *cauxv;
1983 for (cauxv = (struct auxv*)VG_(client_auxv); cauxv->a_type != VKI_AT_NULL; cauxv++) {
1984 if (cauxv->a_type == VKI_AT_PS_STRINGS) {
1985 tmp = (Word)cauxv->u.a_ptr;
1987 *out = tmp;
1988 *outlen = sizeof(size_t);
1989 return True;
1992 return False;
1995 static void sysctl_kern_usrstack(SizeT* out, SizeT* outlen)
1997 *out = VG_(get_usrstack)();
1998 *outlen = sizeof(ULong);
2001 static Bool sysctl_kern_proc_pathname(HChar *out, SizeT *len)
2003 const HChar *exe_name = VG_(resolved_exename);
2005 if (!len) {
2006 return False;
2009 if (!out) {
2010 HChar tmp[VKI_PATH_MAX];
2011 if (!VG_(realpath)(exe_name, tmp)) {
2012 return False;
2014 *len = VG_(strlen)(tmp)+1;
2015 return True;
2018 if (!VG_(realpath)(exe_name, out)) {
2019 return False;
2022 *len = VG_(strlen)(out)+1;
2023 return True;
2026 // SYS___sysctl 202
2027 /* int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen); */
2028 /* ARG1 ARG2 ARG3 ARG4 ARG5 ARG6 */
2029 PRE(sys___sysctl)
2031 PRINT("sys_sysctl ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,SARG2,ARG3,ARG4,ARG5,ARG6 );
2033 int* name = (int*)ARG1;
2034 if (ML_(safe_to_deref)(name, sizeof(int))) {
2035 PRINT("\nmib[0]: ");
2036 if (SARG2 >= 1) {
2037 switch (name[0]) {
2038 case 0: // CTL_UNSPEC
2039 PRINT("unspec");
2040 break;
2041 case 1: // CTL_KERN
2042 PRINT("kern");
2043 break;
2044 case 2: // CTL_VM
2045 PRINT("vm");
2046 break;
2047 case 3: // CTL_VFS
2048 PRINT("vfs");
2049 break;
2050 case 4: // CTL_NET
2051 PRINT("net");
2052 break;
2053 case 5: // CTL_DEBUG
2054 PRINT("debug");
2055 break;
2056 case 6: // CTL_HW
2057 PRINT("hw");
2058 break;
2059 case 7: // CTL_MACHDEP
2060 PRINT("machdep");
2061 break;
2062 case 8: // CTL _USER
2063 PRINT("user");
2064 break;
2065 case 9: //CTL_P1003_1B
2066 PRINT("p1003_b1b");
2067 break;
2068 default:
2069 PRINT("unrecognized (%d)", ((int*)ARG1)[0]);
2070 break;
2073 if (SARG2 >= 2 && ML_(safe_to_deref)(name, 2*sizeof(int))) {
2074 PRINT(" mib[1]: %d\n", name[1]);
2079 * Special handling cases
2081 * 1. kern.usrstack
2082 * This sysctl returns the address of the bottom of the user stack
2083 * (that is the highest user stack address, since the stack grows
2084 * downwards). Without any special handling this would return the
2085 * address of the host userstack. We have created a stack for the
2086 * guest (in aspacemgr) and that is the one that we want the guest
2087 * to see. Aspacemgr is setup in m_main.c with the adresses and sizes
2088 * saved to file static variables in that file, so we call
2089 * VG_(get_usrstack)() to retrieve them from there.
2091 if (SARG2 == 2 && ML_(safe_to_deref)(name, 2*sizeof(int))) {
2092 if (name[0] == 1 && name[1] == 33) {
2093 // kern.usrstack
2094 sysctl_kern_usrstack((SizeT*)ARG3, (SizeT*)ARG4);
2095 SET_STATUS_Success(0);
2100 * 2. kern.ps_strings
2102 if (SARG2 == 2 && ML_(safe_to_deref)(name, 2*sizeof(int))) {
2103 if (name[0] == 1 && name[1] == 32) {
2104 if (sysctl_kern_ps_strings((SizeT*)ARG3, (SizeT*)ARG4)) {
2105 SET_STATUS_Success(0);
2111 * 3. kern.proc.pathname
2113 if (SARG2 == 4 && ML_(safe_to_deref)(name, 4*sizeof(int))) {
2114 if (name[0] == 1 && name[1] == 14 && name[2] == 12) {
2115 vki_pid_t pid = (vki_pid_t)name[3];
2116 if (pid == -1 || pid == VG_(getpid)()) {
2117 sysctl_kern_proc_pathname((HChar *)ARG3, (SizeT *)ARG4);
2118 SET_STATUS_Success(0);
2123 PRE_REG_READ6(int, "__sysctl", int *, name, vki_u_int32_t, namelen, void *, oldp,
2124 vki_size_t *, oldlenp, void *, newp, vki_size_t, newlen);
2126 // read number of ints specified in ARG2 from mem pointed to by ARG1
2127 PRE_MEM_READ("sysctl(name)", (Addr)ARG1, ARG2 * sizeof(int));
2129 // if 'newp' is not NULL can read namelen bytes from that address
2130 if (ARG5 != (UWord)NULL) {
2131 PRE_MEM_READ("sysctl(newp)", (Addr)ARG5, ARG6);
2134 // there are two scenarios for oldlenp/oldp
2135 // 1. oldval is NULL and oldlenp is non-NULL
2136 // this is a query of oldlenp so oldlenp will be written
2137 // 2. Both are non-NULL
2138 // this is a query of oldp, oldlenp will be read and oldp will
2139 // be written
2141 // More thoughts on this
2142 // if say oldp is a string buffer
2143 // oldlenp will point to the length of the buffer
2145 // but on return does oldlenp also get updated?
2147 // is oldlenp is not NULL, can write
2148 if (ARG4 != (UWord)NULL) {
2149 if (ARG3 != (UWord)NULL) {
2150 // case 2 above
2151 PRE_MEM_READ("sysctl(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
2152 PRE_MEM_WRITE("sysctl(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
2153 if (ML_(safe_to_deref)((void*)(Addr)ARG4, sizeof(vki_size_t))) {
2154 PRE_MEM_WRITE("sysctl(oldp)", (Addr)ARG3, *(vki_size_t *)ARG4);
2155 } else {
2156 VG_(dmsg)("Warning: Bad oldlenp address %p in sysctl\n",
2157 (void *)(Addr)ARG4);
2158 SET_STATUS_Failure ( VKI_EFAULT );
2160 } else {
2161 // case 1 above
2162 PRE_MEM_WRITE("sysctl(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
2167 POST(sys___sysctl)
2169 if (ARG4 != (UWord)NULL) {
2170 if (ARG3 != (UWord)NULL) {
2171 POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
2172 POST_MEM_WRITE((Addr)ARG3, *(vki_size_t *)ARG4);
2173 } else {
2174 POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
2179 // SYS_mlock 203
2180 // generic
2182 // SYS_munlock 204
2183 // generic
2185 // SYS_undelete 205
2186 // int undelete(const char *path);
2187 PRE(sys_undelete)
2189 *flags |= SfMayBlock;
2190 PRINT("sys_undelete ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
2191 PRE_REG_READ1(int, "undelete", const char *, path);
2192 PRE_MEM_RASCIIZ( "undelete(path)", ARG1 );
2195 // SYS_futimes 206
2196 // int futimes(int fd, const struct timeval *times);
2197 PRE(sys_futimes)
2199 PRINT("sys_lutimes ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2200 PRE_REG_READ2(long, "futimes", int, fd, struct timeval *, times);
2201 if (ARG2 != 0) {
2202 PRE_MEM_READ( "futimes(times)", ARG2, sizeof(struct vki_timeval) );
2206 // SYS_getpgid 207
2207 // generic
2209 // SYS_poll 209
2210 // generic
2212 // SYS_freebsd7___semctl 220
2213 // int semctl(int semid, int semnum, int cmd, ...);
2214 PRE(sys_freebsd7___semctl)
2216 switch (ARG3) {
2217 case VKI_IPC_INFO:
2218 case VKI_SEM_INFO:
2219 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
2220 PRE_REG_READ4(int, "semctl",
2221 int, semid, int, semnum, int, cmd, struct seminfo *, arg);
2222 break;
2223 case VKI_IPC_STAT:
2224 case VKI_SEM_STAT:
2225 case VKI_IPC_SET:
2226 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
2227 PRE_REG_READ4(int, "semctl",
2228 int, semid, int, semnum, int, cmd, struct vki_semid_ds_old *, arg);
2229 break;
2230 case VKI_GETALL:
2231 case VKI_SETALL:
2232 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
2233 PRE_REG_READ4(int, "semctl",
2234 int, semid, int, semnum, int, cmd, unsigned short *, arg);
2235 break;
2236 default:
2237 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2238 PRE_REG_READ3(long, "semctl",
2239 int, semid, int, semnum, int, cmd);
2240 break;
2242 ML_(generic_PRE_sys_semctl)(tid, ARG1,ARG2,ARG3,ARG4);
2245 POST(sys_freebsd7___semctl)
2247 ML_(generic_POST_sys_semctl)(tid, RES,ARG1,ARG2,ARG3,ARG4);
2250 // SYS_semget 221
2251 // int semget(key_t key, int nsems, int flag);
2252 PRE(sys_semget)
2254 PRINT("sys_semget ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2255 PRE_REG_READ3(int, "semget", vki_key_t, key, int, nsems, int, flag);
2258 // SYS_semop 222
2259 // int semop(int semid, struct sembuf *array, size_t nops);
2260 PRE(sys_semop)
2262 *flags |= SfMayBlock;
2263 PRINT("sys_semop ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2264 PRE_REG_READ3(int, "semop",
2265 int, semid, struct sembuf *, array, unsigned, nops);
2266 ML_(generic_PRE_sys_semop)(tid, ARG1,ARG2,ARG3);
2269 // SYS_freebsd7_msgctl 224
2270 // int msgctl(int msqid, int cmd, struct msqid_ds_old *buf);
2271 PRE(sys_freebsd7_msgctl)
2273 PRINT("sys_freebsd7_msgctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3 );
2275 PRE_REG_READ3(int, "msgctl", int, msqid, int, cmd, struct msqid_ds_old *, buf);
2277 switch (ARG2 /* cmd */) {
2278 case VKI_IPC_STAT:
2279 PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)",
2280 ARG3, sizeof(struct vki_msqid_ds_old) );
2281 break;
2282 case VKI_IPC_SET:
2283 PRE_MEM_READ( "msgctl(IPC_SET, buf)",
2284 ARG3, sizeof(struct vki_msqid_ds_old) );
2285 break;
2289 POST(sys_freebsd7_msgctl)
2291 switch (ARG2 /* cmd */) {
2292 case VKI_IPC_STAT:
2293 POST_MEM_WRITE( ARG3, sizeof(struct vki_msqid_ds_old) );
2294 break;
2298 // SYS_msgget 225
2299 // int msgget(key_t key, int msgflg);
2300 PRE(sys_msgget)
2302 PRINT("sys_msgget ( %" FMT_REGWORD"d, %" FMT_REGWORD"d )",SARG1,SARG2);
2303 PRE_REG_READ2(int, "msgget", key_t, key, int, msgflg);
2306 // SYS_msgsnd 226
2307 // int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg);
2308 PRE(sys_msgsnd)
2310 PRINT("sys_msgsnd ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,ARG2,SARG3,SARG4 );
2311 PRE_REG_READ4(int, "msgsnd", int, msqid, struct msgbuf *, msgp, size_t, msgsz, int, msgflg);
2312 struct vki_msgbuf *msgp = (struct vki_msgbuf *)ARG2;
2313 PRE_MEM_READ( "msgsnd(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) );
2314 PRE_MEM_READ( "msgsnd(msgp->mtext)", (Addr)&msgp->mtext, ARG3 );
2316 // SYS_msgrcv 227
2317 // ssize_t msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int msgflg);
2318 PRE(sys_msgrcv)
2320 *flags |= SfMayBlock;
2322 PRINT("sys_msgrcv ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,ARG2,ARG3,SARG4,SARG5 );
2323 PRE_REG_READ5(ssize_t, "msgrcv", int, msqid, struct msgbuf *, msgp, size_t, msgsz,
2324 long, msgtyp, int, msgflg);
2325 struct vki_msgbuf *msgp = (struct vki_msgbuf *)ARG2;
2326 PRE_MEM_WRITE( "msgrcv(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) );
2327 PRE_MEM_WRITE( "msgrcv(msgp->mtext)", (Addr)&msgp->mtext, ARG3 );
2330 POST(sys_msgrcv)
2332 struct vki_msgbuf *msgp = (struct vki_msgbuf *)ARG2;
2333 POST_MEM_WRITE( (Addr)&msgp->mtype, sizeof(msgp->mtype) );
2334 POST_MEM_WRITE( (Addr)&msgp->mtext, RES );
2337 // SYS_shmat 228
2338 // void * shmat(int shmid, const void *addr, int flag);
2339 PRE(sys_shmat)
2341 UWord arg2tmp;
2342 PRINT("sys_shmat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2343 PRE_REG_READ3(void *, "shmat",
2344 int, shmid, const void *, addr, int, flag);
2345 arg2tmp = ML_(generic_PRE_sys_shmat)(tid, ARG1,ARG2,ARG3);
2346 if (arg2tmp == 0) {
2347 SET_STATUS_Failure( VKI_EINVAL );
2348 } else {
2349 ARG2 = arg2tmp;
2353 POST(sys_shmat)
2355 ML_(generic_POST_sys_shmat)(tid, RES,ARG1,ARG2,ARG3);
2358 // SYS_freebsd7_shmctl 229
2359 // int shmctl(int shmid, int cmd, struct shmid_ds *buf);
2360 PRE(sys_freebsd7_shmctl)
2362 PRINT("sys_freebsd7_shmctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,SARG2,ARG3);
2363 PRE_REG_READ3(int, "shmctl",
2364 int, shmid, int, cmd, struct vki_shmid_ds_old *, buf);
2365 switch (ARG2 /* cmd */) {
2366 case VKI_IPC_STAT:
2367 PRE_MEM_WRITE( "shmctl7(IPC_STAT, buf)",
2368 ARG3, sizeof(struct vki_shmid_ds_old) );
2369 break;
2370 case VKI_IPC_SET:
2371 PRE_MEM_READ( "shmctl7(IPC_SET, buf)",
2372 ARG3, sizeof(struct vki_shmid_ds_old) );
2373 break;
2377 POST(sys_freebsd7_shmctl)
2379 if (ARG2 == VKI_IPC_STAT) {
2380 POST_MEM_WRITE( ARG3, sizeof(struct vki_shmid_ds_old) );
2384 // SYS_shmdt 230
2385 // int shmdt(const void *addr);
2386 PRE(sys_shmdt)
2388 PRINT("sys_shmdt ( %#" FMT_REGWORD "x )",ARG1);
2389 PRE_REG_READ1(int, "shmdt", const void *, addr);
2390 if (!ML_(generic_PRE_sys_shmdt)(tid, ARG1)) {
2391 SET_STATUS_Failure( VKI_EINVAL );
2395 POST(sys_shmdt)
2397 ML_(generic_POST_sys_shmdt)(tid, RES,ARG1);
2400 // SYS_shmget 231
2401 // int shmget(key_t key, size_t size, int flag);
2402 PRE(sys_shmget)
2404 PRINT("sys_shmget ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2405 PRE_REG_READ3(int, "shmget", vki_key_t, key, vki_size_t, size, int, flag);
2409 // SYS_clock_gettime 232
2410 // int clock_gettime(clockid_t clock_id, struct timespec *tp);
2411 PRE(sys_clock_gettime)
2413 PRINT("sys_clock_gettime( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2414 PRE_REG_READ2(int, "clock_gettime",
2415 vki_clockid_t, clk_id, struct timespec *, tp);
2416 PRE_MEM_WRITE( "clock_gettime(tp)", ARG2, sizeof(struct vki_timespec) );
2419 POST(sys_clock_gettime)
2421 POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) );
2424 // SYS_clock_settime 233
2425 // int clock_settime(clockid_t clock_id, const struct timespec *tp);
2426 PRE(sys_clock_settime)
2428 PRINT("sys_clock_settime( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2429 PRE_REG_READ2(int, "clock_settime",
2430 vki_clockid_t, clk_id, const struct timespec *, tp);
2431 PRE_MEM_READ( "clock_settime(tp)", ARG2, sizeof(struct vki_timespec) );
2434 // SYS_clock_getres 234
2435 // int clock_getres(clockid_t clock_id, struct timespec *tp);
2436 PRE(sys_clock_getres)
2438 PRINT("sys_clock_getres( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2439 // Nb: we can't use "RES" as the param name because that's a macro
2440 // defined above!
2441 PRE_REG_READ2(int, "clock_getres",
2442 vki_clockid_t, clock_id, struct timespec *, tp);
2443 if (ARG2 != 0) {
2444 PRE_MEM_WRITE( "clock_getres(tp)", ARG2, sizeof(struct vki_timespec) );
2448 POST(sys_clock_getres)
2450 if (ARG2 != 0) {
2451 POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) );
2455 // SYS_ktimer_create 235
2456 // int timer_create(clockid_t clockid, struct sigevent *restrict evp,
2457 // timer_t *restrict timerid);
2458 PRE(sys_timer_create)
2460 PRINT("sys_timer_create( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", SARG1,ARG2,ARG3);
2461 PRE_REG_READ3(int, "timer_create",
2462 vki_clockid_t, clockid, struct sigevent *, evp,
2463 vki_timer_t *, timerid);
2464 if (ARG2 != 0) {
2465 PRE_MEM_READ( "timer_create(evp)", ARG2, sizeof(struct vki_sigevent) );
2467 PRE_MEM_WRITE( "timer_create(timerid)", ARG3, sizeof(vki_timer_t) );
2470 POST(sys_timer_create)
2472 POST_MEM_WRITE( ARG3, sizeof(vki_timer_t) );
2475 // SYS_ktimer_delete 236
2476 // int timer_delete(timer_t timerid);
2477 PRE(sys_timer_delete)
2479 PRINT("sys_timer_delete( %#" FMT_REGWORD "x )", ARG1);
2480 PRE_REG_READ1(long, "timer_delete", vki_timer_t, timerid);
2483 // SYS_ktimer_settime 237
2484 // int timer_settime(timer_t timerid, int flags,
2485 // const struct itimerspec *restrict value,
2486 // struct itimerspec *restrict ovalue);
2487 PRE(sys_timer_settime)
2489 PRINT("sys_timer_settime( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3,ARG4);
2490 PRE_REG_READ4(int, "timer_settime",
2491 vki_timer_t, timerid, int, flags,
2492 const struct itimerspec *, value,
2493 struct itimerspec *, ovalue);
2494 PRE_MEM_READ( "timer_settime(value)", ARG3,
2495 sizeof(struct vki_itimerspec) );
2496 if (ARG4 != 0) {
2497 PRE_MEM_WRITE( "timer_settime(ovalue)", ARG4,
2498 sizeof(struct vki_itimerspec) );
2502 POST(sys_timer_settime)
2504 if (ARG4 != 0) {
2505 POST_MEM_WRITE( ARG4, sizeof(struct vki_itimerspec) );
2509 // SYS_ktimer_gettime 238
2510 // int timer_gettime(timer_t timerid, struct itimerspec *value);
2511 PRE(sys_timer_gettime)
2513 PRINT("sys_timer_gettime( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2);
2514 PRE_REG_READ2(long, "timer_gettime",
2515 vki_timer_t, timerid, struct itimerspec *, value);
2516 PRE_MEM_WRITE( "timer_gettime(value)", ARG2,
2517 sizeof(struct vki_itimerspec));
2520 POST(sys_timer_gettime)
2522 POST_MEM_WRITE( ARG2, sizeof(struct vki_itimerspec) );
2525 // SYS_ktimer_getoverrun 239
2526 // int timer_getoverrun(timer_t timerid);
2527 PRE(sys_timer_getoverrun)
2529 PRINT("sys_timer_getoverrun( %#" FMT_REGWORD "x )", ARG1);
2530 PRE_REG_READ1(int, "timer_getoverrun", vki_timer_t, timerid);
2533 // SYS_nanosleep 240
2534 // generic
2536 // SYS_ffclock_getcounter 241
2537 // int ffclock_getcounter(ffcounter *ffcount);
2538 // @todo
2540 // SYS_ffclock_setestimate 242
2541 // int ffclock_setestimate(struct ffclock_estimate *cest);
2542 // @todo
2544 // SYS_ffclock_getestimate 243
2545 // int ffclock_getestimate(struct ffclock_estimate *cest);
2546 // @todo
2548 // SYS_clock_nanosleep 244
2549 // int clock_nanosleep(clockid_t clock_id, int flags,
2550 // const struct timespec *rqtp, struct timespec *rmtp);
2551 PRE(sys_clock_nanosleep)
2553 *flags |= SfMayBlock|SfPostOnFail;
2554 PRINT("sys_clock_nanosleep ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
2555 SARG1, SARG2, ARG3, ARG4);
2556 PRE_REG_READ4(int, "clock_nanosleep", clockid_t, clock_id, int, flags,
2557 const struct timespec *, rqtp, struct timespec *, rmtp);
2558 PRE_MEM_READ("clock_nanosleep(rqtp)", ARG1, sizeof(struct vki_timespec));
2559 if (ARG2 != 0) {
2560 PRE_MEM_WRITE( "clock_nanosleep(rmtp)", ARG2, sizeof(struct vki_timespec) );
2564 POST(sys_clock_nanosleep)
2566 if (ARG2 != 0) {
2567 POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) );
2571 // SYS_clock_getcpuclockid2 247
2572 // x86/amd64
2574 POST(sys_clock_getcpuclockid2)
2576 POST_MEM_WRITE(ARG3, sizeof(vki_clockid_t));
2580 // SYS_ntp_gettime 248
2581 // int ntp_gettime(struct ntptimeval *);
2582 // @todo
2584 // SYS_minherit 250
2585 // int minherit(void *addr, size_t len, int inherit);
2586 PRE(sys_minherit)
2588 PRINT("sys_minherit( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
2589 PRE_REG_READ3(int, "minherit",
2590 void *, addr, vki_size_t, len, int, inherit);
2591 if (ARG2 != 0) {
2592 PRE_MEM_WRITE( "minherit(addr)", ARG1,ARG2 );
2596 POST(sys_minherit)
2598 if (ARG2 != 0) {
2599 POST_MEM_WRITE( ARG1, ARG2 );
2603 // SYS_rfork 251
2604 // x86/amd64 not functional
2606 // SYS_issetugid 253
2607 // int issetugid(void);
2608 PRE(sys_issetugid)
2610 PRINT("%s", "sys_issetugid ()");
2611 PRE_REG_READ0(long, "issetugid");
2614 // SYS_lchown 254
2615 // generic
2617 // We must record the iocb for each aio_read() in a table so that when
2618 // aio_return() is called we can mark the memory written asynchronously by
2619 // aio_read() as having been written. We don't have to do this for
2620 // aio_write(). See bug 197227 for more details.
2621 static OSet* iocb_table = NULL;
2622 static Bool aio_init_done = False;
2624 static void aio_init(void)
2626 iocb_table = VG_(OSetWord_Create)(VG_(malloc), "syswrap.aio", VG_(free));
2627 aio_init_done = True;
2630 // and the same thing for vector reads
2631 static OSet* iocbv_table = NULL;
2632 static Bool aiov_init_done = False;
2634 static void aiov_init(void)
2636 iocbv_table = VG_(OSetWord_Create)(VG_(malloc), "syswrap.aiov", VG_(free));
2637 aiov_init_done = True;
2641 // SYS_aio_read 255
2642 // int aio_read(struct aiocb *iocb);
2643 PRE(sys_aio_read)
2645 PRINT("sys_aio_read ( %#" FMT_REGWORD "x )", ARG1);
2646 PRE_REG_READ1(int, "aio_read", struct vki_aiocb *, iocb);
2647 PRE_MEM_READ("aio_read(iocb)", ARG1, sizeof(struct vki_aiocb));
2648 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
2649 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
2650 if (!ML_(fd_allowed)(iocb->aio_fildes, "aio_read", tid, False)) {
2651 SET_STATUS_Failure(VKI_EBADF);
2652 } else {
2653 PRE_MEM_WRITE("aio_read(aiocbp->aio_buf)",
2654 (Addr)iocb->aio_buf, iocb->aio_nbytes);
2655 // @todo PJF there is a difference between FreeBSD and
2656 // Darwin here. On Darwin, if aio_buf is NULL the syscall
2657 // will fail, on FreeBSD it doesn't fail.
2659 } else {
2660 SET_STATUS_Failure(VKI_EINVAL);
2664 POST(sys_aio_read)
2666 struct vki_aiocb* iocb = (struct vki_aiocb*)ARG1;
2668 if (iocb->aio_buf) {
2669 if (!aio_init_done) {
2670 aio_init();
2672 // see also POST(sys_aio_readv)
2673 if (!VG_(OSetWord_Contains)(iocb_table, (UWord)iocb)) {
2674 VG_(OSetWord_Insert)(iocb_table, (UWord)iocb);
2675 } else {
2676 // @todo PJF this warns without callstack
2677 VG_(dmsg)("Warning: Duplicate control block %p in aio_read\n",
2678 (void *)(Addr)ARG1);
2679 VG_(dmsg)("Warning: Ensure 'aio_return' is called when 'aio_read' has completed\n");
2684 // SYS_aio_write 256
2685 // int aio_write(struct aiocb *iocb);
2686 PRE(sys_aio_write)
2688 PRINT("sys_aio_write ( %#" FMT_REGWORD "x )", ARG1);
2689 PRE_REG_READ1(int, "aio_write", struct vki_aiocb *, iocb);
2690 PRE_MEM_READ("aio_write(iocb)", ARG1, sizeof(struct vki_aiocb));
2691 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
2692 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
2693 if (!ML_(fd_allowed)(iocb->aio_fildes, "aio_write", tid, False)) {
2694 SET_STATUS_Failure( VKI_EBADF );
2695 } else {
2696 PRE_MEM_READ("aio_write(iocb->aio_buf)",
2697 (Addr)iocb->aio_buf, iocb->aio_nbytes);
2698 // @todo PJF there is a difference between FreeBSD and
2699 // Darwin here. On Darwin, if aio_buf is NULL the syscall
2700 // will fail, on FreeBSD it doesn't fail.
2702 } else {
2703 SET_STATUS_Failure(VKI_EINVAL);
2707 // SYS_lio_listio 257
2708 // int lio_listio(int mode, struct aiocb * const list[], int nent,
2709 // struct sigevent *sig);
2710 PRE(sys_lio_listio)
2712 PRINT("sys_lio_listio ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",
2713 SARG1, ARG2, SARG3, ARG4);
2714 PRE_REG_READ4(int, "lio_listio", int, mode, struct aiocb * const *, list, int, nent,
2715 struct sigevent *,sig);
2716 PRE_MEM_READ("lio_listio(list)", ARG2, ARG3*sizeof(struct vki_aiocb *));
2717 // loop check elements
2718 if (ML_(safe_to_deref)((struct vki_aiocb **)ARG2, ARG3*sizeof(struct vki_aiocb *))) {
2719 struct vki_aiocb** list = (struct vki_aiocb **)ARG2;
2720 for (int i = 0; i < (int)ARG3; ++i) {
2721 if (list[i]) {
2722 PRE_MEM_READ("lio_listio(list[?])", (Addr)list[i], ARG3*sizeof(struct vki_aiocb));
2724 // @todo
2725 // figure out what gets read/written
2726 // when list[i]->aio_lio_opcode == VKI_LIO_READ and
2727 // when list[i]->aio_lio_opcode == VKI_LIO_WRITE
2728 //if (ML_(safe_to_deref)(list[i], ARG3*sizeof(struct vki_aiocb))) {
2733 if (ARG1 & VKI_LIO_WAIT) {
2734 *flags |= SfMayBlock;
2737 if (ARG4 && (ARG1 == VKI_LIO_NOWAIT)) {
2738 PRE_MEM_READ("lio_listio(sig)", ARG4, sizeof(struct vki_sigevent));
2742 // SYS_freebsd11_getdents 272
2743 // generic
2745 // SYS_lchmod 274
2746 // int lchmod(const char *path, mode_t mode);
2747 PRE(sys_lchmod)
2749 PRINT("sys_lchmod ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char *)ARG1,ARG2);
2750 PRE_REG_READ2(int, "lchmod", const char *, path, vki_mode_t, mode);
2751 PRE_MEM_RASCIIZ( "lchmod(path)", ARG1 );
2754 // SYS_lutimes 276
2755 // int lutimes(const char *path, const struct timeval *times);
2756 PRE(sys_lutimes)
2758 PRINT("sys_lutimes ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2);
2759 PRE_REG_READ2(int, "lutimes", char *, path, struct timeval *, times);
2760 PRE_MEM_RASCIIZ( "lutimes(path)", ARG1 );
2761 if (ARG2 != 0) {
2762 PRE_MEM_READ( "lutimes(times)", ARG2, sizeof(struct vki_timeval) );
2766 // SYS_freebsd11_nstat 278
2767 // @todo, maybe
2769 // SYS_freebsd11_nfstat 279
2770 // @todo, maybe
2772 // SYS_freebsd11_nlstat 280
2773 // @todo, maybe
2775 // SYS_preadv 289
2776 // amd64 / x86
2778 // SYS_pwritev 290
2779 // amd64 / x86
2781 // SYS_fhopen 298
2782 // int fhopen(const fhandle_t *fhp, int flags);
2783 PRE(sys_fhopen)
2785 PRINT("sys_open ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2);
2786 PRE_REG_READ2(int, "fhopen",
2787 struct fhandle_t *, fhp, int, flags);
2788 PRE_MEM_READ( "fhopen(fhp)", ARG1, sizeof(struct vki_fhandle) );
2790 /* Otherwise handle normally */
2791 *flags |= SfMayBlock;
2794 POST(sys_fhopen)
2796 vg_assert(SUCCESS);
2797 if (!ML_(fd_allowed)(RES, "fhopen", tid, True)) {
2798 VG_(close)(RES);
2799 SET_STATUS_Failure( VKI_EMFILE );
2800 } else {
2801 if (VG_(clo_track_fds)) {
2802 ML_(record_fd_open_nameless)(tid, RES);
2807 // SYS_freebsd11_fhstat 299
2808 // int fhstat(const fhandle_t *fhp, struct stat *sb);
2809 #if (FREEBSD_VERS >= FREEBSD_12)
2810 PRE(sys_freebsd11_fhstat)
2812 PRINT("sys_freebsd11_fhstat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
2813 PRE_REG_READ2(int, "fhstat", struct fhandle *, fhp, struct freebd11_stat *, sb);
2814 PRE_MEM_READ( "fhstat(fhp)", ARG1, sizeof(struct vki_fhandle) );
2815 PRE_MEM_WRITE( "fhstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
2818 POST(sys_freebsd11_fhstat)
2820 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
2822 #else
2823 PRE(sys_fhstat)
2825 PRINT("sys_fhstat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
2826 PRE_REG_READ2(int, "fhstat", struct fhandle *, fhp, struct stat *, sb);
2827 PRE_MEM_READ( "fhstat(fhp)", ARG1, sizeof(struct vki_fhandle) );
2828 PRE_MEM_WRITE( "fhstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
2831 POST(sys_fhstat)
2833 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
2836 #endif
2838 // SYS_modnext 300
2839 // int modnext(int modid);
2840 PRE(sys_modnext)
2842 PRINT("sys_modnext ( %" FMT_REGWORD "d )",SARG1);
2843 PRE_REG_READ1(int, "modnext", int, modid);
2846 // SYS_modstat 301
2847 // int modstat(int modid, struct module_stat *stat);
2848 PRE(sys_modstat)
2850 PRINT("sys_modstat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2);
2851 PRE_REG_READ2(int, "modstat", int, modid, struct module_stat *, buf);
2852 PRE_MEM_WRITE( "modstat(stat)", ARG2, sizeof(struct vki_module_stat) );
2855 POST(sys_modstat)
2857 POST_MEM_WRITE( ARG2, sizeof(struct vki_module_stat) );
2860 // SYS_modfnext 302
2861 // int modfnext(int modid);
2862 PRE(sys_modfnext)
2864 PRINT("sys_modfnext ( %" FMT_REGWORD "d )",SARG1);
2865 PRE_REG_READ1(int, "modfnext", int, modid);
2868 // SYS_modfind 303
2869 // int modfind(const char *modname);
2870 PRE(sys_modfind)
2872 PRINT("sys_modfind ( %#" FMT_REGWORD "x )",ARG1);
2873 PRE_REG_READ1(long, "modfind", char *, modname);
2874 PRE_MEM_RASCIIZ( "modfind(modname)", ARG1 );
2877 // SYS_kldload 304
2878 // int kldload(const char *file);
2879 PRE(sys_kldload)
2881 PRINT("sys_kldload ( %#" FMT_REGWORD "x(%s) )", ARG1, (char *)ARG1);
2882 PRE_REG_READ1(int, "kldload", const char *, "file");
2883 PRE_MEM_RASCIIZ( "kldload(file)", ARG1 );
2886 // SYS_kldunload 305
2887 // int kldunload(int fileid);
2888 PRE(sys_kldunload)
2890 PRINT("sys_kldunload ( %" FMT_REGWORD "u )", ARG1);
2891 PRE_REG_READ1(int, "kldunload", int, "fileid");
2894 // SYS_kldfind 306
2895 // int kldfind(const char *file);
2896 PRE(sys_kldfind)
2898 PRINT("sys_kldfind ( %#" FMT_REGWORD "x(%s) )", ARG1, (char *)ARG1);
2899 PRE_REG_READ1(int, "kldfind", const char *, file);
2900 PRE_MEM_RASCIIZ( "kldfind(file)", ARG1 );
2903 // SYS_kldnext 307
2904 // int kldnext(int fileid);
2905 PRE(sys_kldnext)
2907 PRINT("sys_kldnext ( %" FMT_REGWORD "u )", ARG1);
2908 PRE_REG_READ1(int, "kldnext", int, fileid);
2911 // SYS_kldstat 308
2912 // int kldstat(int fileid, struct kld_file_stat *stat);
2913 PRE(sys_kldstat)
2915 PRINT("sys_kldstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
2916 PRE_REG_READ2(int, "kldstat", int, fileid, struct kld_file_stat*, stat);
2917 PRE_MEM_WRITE("kldstat(stat)", ARG2, sizeof(struct vki_kld_file_stat));
2920 POST(sys_kldstat)
2922 POST_MEM_WRITE(ARG2, sizeof(struct vki_kld_file_stat));
2925 // SYS_kldfirstmod 309
2926 // int kldfirstmod(int fileid);
2927 PRE(sys_kldfirstmod)
2929 PRINT("sys_kldfirstmod ( %" FMT_REGWORD "u )", ARG1);
2930 PRE_REG_READ1(int, "kldfirstmod", int, fileid);
2933 // SYS_setresuid 311
2934 // int setresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
2935 PRE(sys_setresuid)
2937 PRINT("sys_setresuid ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
2938 PRE_REG_READ3(int, "setresuid",
2939 vki_uid_t, ruid, vki_uid_t, euid, vki_uid_t, suid);
2942 // SYS_setresgid 312
2943 // int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
2944 PRE(sys_setresgid)
2946 PRINT("sys_setresgid ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
2947 PRE_REG_READ3(int, "setresgid",
2948 vki_gid_t, rgid, vki_gid_t, egid, vki_gid_t, sgid);
2951 // SYS_aio_return 314
2952 // ssize_t aio_return(struct aiocb *iocb);
2953 PRE(sys_aio_return)
2955 PRINT("sys_aio_return ( %#" FMT_REGWORD "x )", ARG1);
2956 PRE_REG_READ1(ssize_t, "aio_return", struct aiocb *, iocb);
2957 PRE_MEM_READ("aio_return(iocb)", ARG1, sizeof(struct vki_aiocb));
2958 // read or write?
2959 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
2960 SET_STATUS_from_SysRes(VG_(do_syscall1)(SYSNO, ARG1));
2961 /*if (SUCCESS)*/ {
2962 struct vki_aiocb* iocb = (struct vki_aiocb*)ARG1;
2963 if (!aio_init_done) {
2964 aio_init();
2966 if (!aiov_init_done) {
2967 aiov_init();
2970 // for the happy path aio_return is supposed to be called
2971 // after the io has completed (as determined by aio_error,
2972 // aio_suspend or a signal).
2974 // but what if the aio_read failed or hasn't completed?
2975 // we want to remove the read from the iocb(v)_table
2976 // in the case of aio_read failing
2977 // if the read hasn't completed that's a user error
2978 // I don't know if it's possible to recover in that case
2979 // the iocb will have been removed from the table
2980 // so if the user does recover and call aio_return
2981 // 'correctly' we won't do the POST_MEM_WRITE
2982 // I don't think that we can tell apart a failing
2983 // read from a premature aio_return
2985 // check if it was a plain read
2986 if (VG_(OSetWord_Remove)(iocb_table, (UWord)iocb) && SUCCESS) {
2987 POST_MEM_WRITE((Addr)iocb->aio_buf, iocb->aio_nbytes);
2989 if (VG_(OSetWord_Remove)(iocbv_table, (UWord)iocb) && SUCCESS) {
2990 SizeT vec_count = (SizeT)iocb->aio_nbytes;
2991 // assume that id the read succeded p_iovec is accessible
2992 volatile struct vki_iovec* p_iovec = (volatile struct vki_iovec*)iocb->aio_buf;
2993 for (SizeT i = 0U; i < vec_count; ++i) {
2994 POST_MEM_WRITE((Addr)p_iovec[i].iov_base, p_iovec[i].iov_len);
2998 } else {
2999 SET_STATUS_Failure(VKI_EINVAL);
3003 // SYS_aio_suspend 315
3004 // int aio_suspend(const struct aiocb *const iocbs[], int niocb,
3005 // const struct timespec *timeout);
3006 PRE(sys_aio_suspend)
3008 PRINT("sys_aio_suspend ( %#" FMT_REGWORD "x )", ARG1);
3009 PRE_REG_READ3(int, "aio_suspend", const struct aiocb * const *, iocbs, int, nbiocb, const struct timespec*, timeout);
3010 if (ARG2 > 0) {
3011 PRE_MEM_READ("aio_suspend(iocbs)", ARG1, ARG2*sizeof(struct vki_aiocb*));
3013 if (ARG3) {
3014 PRE_MEM_READ("aio_suspend(timeout)", ARG3, sizeof(struct vki_timespec));
3018 // SYS_aio_cancel 316
3019 // int aio_cancel(int fildes, struct aiocb *iocb);
3020 PRE(sys_aio_cancel)
3022 PRINT("sys_aio_cancel ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
3023 PRE_REG_READ2(int, "aio_cancel", int, fildes, struct iocb *, iocb);
3024 if (ARG2) {
3025 PRE_MEM_READ("aio_cancel(iocb)", ARG2, sizeof(struct vki_aiocb));
3027 if (!ML_(fd_allowed)(ARG1, "aio_cancel", tid, False)) {
3028 SET_STATUS_Failure(VKI_EBADF);
3029 } else {
3030 if (ARG2) {
3031 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG2, sizeof(struct vki_aiocb))) {
3032 // struct vki_aiocb *iocb = (struct vki_aiocb *)ARG2;
3033 // @todo PJF cancel only requests associated with
3034 // fildes and iocb
3035 // Do I need to remove pending reads from iocb(v)_table
3036 // or should the user always call aio_return even after
3037 // aio_cancel?
3038 } else {
3039 SET_STATUS_Failure(VKI_EINVAL);
3041 } else {
3042 // @todo PJF cancel all requests associated with fildes, see above
3047 // SYS_aio_error 317
3048 // int aio_error(const struct aiocb *iocb);
3049 PRE(sys_aio_error)
3051 PRINT("sys_aio_error ( %#" FMT_REGWORD "x )", ARG1);
3052 PRE_REG_READ1(ssize_t, "aio_error", struct aiocb *, iocb);
3053 PRE_MEM_READ("aio_error(iocb)", ARG1, sizeof(struct vki_aiocb));
3056 // SYS_yield 321
3057 int yield(void);
3058 PRE(sys_yield)
3060 *flags |= SfMayBlock;
3061 PRINT("%s", "yield()");
3062 PRE_REG_READ0(long, "yield");
3065 // SYS_mlockall 324
3066 // generic
3068 // SYS_munlockall 325
3069 // int munlockall(void);
3070 PRE(sys_munlockall)
3072 *flags |= SfMayBlock;
3073 PRINT("%s", "sys_munlockall ( )");
3074 PRE_REG_READ0(int, "munlockall");
3077 // SYS___getcwd 326
3078 // int __getcwd(char *buf, size_t buflen);
3079 PRE(sys___getcwd)
3081 PRINT("sys___getcwd ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2);
3082 PRE_REG_READ2(long, "__getcwd", char *, buf, unsigned int, buflen);
3083 PRE_MEM_WRITE( "__getcwd(buf)", ARG1, ARG2 );
3086 POST(sys___getcwd)
3088 vg_assert(SUCCESS);
3089 if (RES == 0) {
3090 // QQQ it is unclear if this is legal or not, but the
3091 // QQQ kernel just wrote it there...
3092 // QQQ Why oh why didn't phk return the length from __getcwd()?
3093 UInt len = VG_(strlen) ( (char *)ARG1 ) + 1;
3094 POST_MEM_WRITE( ARG1, len );
3098 //SYS_sched_setparam 327
3099 // int sched_setparam(pid_t pid, const struct sched_param *param);
3100 PRE(sys_sched_setparam)
3102 PRINT("sched_setparam ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2 );
3103 PRE_REG_READ2(int, "sched_setparam",
3104 vki_pid_t, pid, struct sched_param *, param);
3105 PRE_MEM_READ( "sched_setparam(param)", ARG2, sizeof(struct vki_sched_param) );
3108 POST(sys_sched_setparam)
3110 POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) );
3113 // SYS_sched_getparam 328
3114 // int sched_getparam(pid_t pid, struct sched_param *param);
3115 PRE(sys_sched_getparam)
3117 PRINT("sched_getparam ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2 );
3118 PRE_REG_READ2(int, "sched_getparam",
3119 vki_pid_t, pid, struct sched_param *, param);
3120 PRE_MEM_WRITE( "sched_getparam(param)", ARG2, sizeof(struct vki_sched_param) );
3123 POST(sys_sched_getparam)
3125 POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) );
3128 // SYS_sched_setscheduler 329
3129 // int sched_setscheduler(pid_t pid, int policy,
3130 // const struct sched_param *param);
3131 PRE(sys_sched_setscheduler)
3133 PRINT("sys_sched_setscheduler ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3);
3134 PRE_REG_READ3(int, "sched_setscheduler",
3135 vki_pid_t, pid, int, policy, struct sched_param *, param);
3136 if (ARG3 != 0) {
3137 PRE_MEM_READ("sched_setscheduler(param)",
3138 ARG3, sizeof(struct vki_sched_param));
3142 // SYS_sched_getscheduler 330
3143 // int sched_getscheduler(pid_t pid);
3144 PRE(sys_sched_getscheduler)
3146 PRINT("sys_sched_getscheduler ( %" FMT_REGWORD "d )", SARG1);
3147 PRE_REG_READ1(int, "sched_getscheduler", vki_pid_t, pid);
3150 // SYS_sched_yield 331
3151 // int sched_yield(void);
3152 PRE(sys_sched_yield)
3154 *flags |= SfMayBlock;
3155 PRINT("sched_yield()");
3156 PRE_REG_READ0(int, "sched_yield");
3159 // SYS_sched_get_priority_max 332
3160 // int sched_get_priority_max(int policy);
3161 PRE(sys_sched_get_priority_max)
3163 PRINT("sched_get_priority_max ( %" FMT_REGWORD "u )", ARG1);
3164 PRE_REG_READ1(long, "sched_get_priority_max", int, policy);
3167 // SYS_sched_get_priority_min 333
3168 // int sched_get_priority_min(int policy);
3169 PRE(sys_sched_get_priority_min)
3171 PRINT("sched_get_priority_min ( %" FMT_REGWORD "u )", ARG1);
3172 PRE_REG_READ1(long, "sched_get_priority_min", int, policy);
3175 // SYS_sched_rr_get_interval 334
3176 // int sched_rr_get_interval(pid_t pid, struct timespec *interval);
3177 PRE(sys_sched_rr_get_interval)
3179 PRINT("sys_sched_rr_get_interval ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
3180 PRE_REG_READ2(int, "sched_rr_get_interval", vki_pid_t, pid, struct vki_timespec *,interval);
3181 PRE_MEM_WRITE("sys_sched_rr_get_interval(interval)", ARG2, sizeof(struct vki_timespec));
3184 POST(sys_sched_rr_get_interval)
3186 POST_MEM_WRITE(ARG2, sizeof(struct vki_timespec));
3189 // SYS_utrace 335
3190 // int utrace(const void *addr, size_t len);
3191 PRE(sys_utrace)
3193 PRINT("sys_utrace ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
3194 PRE_REG_READ2(int, "utrace", const void *, addr, vki_size_t, len);
3195 PRE_MEM_READ( "utrace(addr)", ARG2, ARG3 );
3198 // SYS_kldsym 337
3199 // int kldsym(int fileid, int cmd, void *data);
3200 PRE(sys_kldsym)
3202 PRINT("sys_kldsym ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3 );
3203 PRE_REG_READ3(int, "kldsym", int, fileid, int, cmd, void*, data);
3204 PRE_MEM_READ( "kldsym(data)", ARG3, sizeof(struct vki_kld_sym_lookup) );
3205 struct vki_kld_sym_lookup *kslp = (struct vki_kld_sym_lookup *)ARG3;
3206 if (ML_(safe_to_deref)(kslp, sizeof(struct vki_kld_sym_lookup))) {
3207 PRE_MEM_RASCIIZ( "kldsym(data.symname)", (Addr)kslp->symname );
3211 POST(sys_kldsym)
3213 struct vki_kld_sym_lookup *kslp = (struct vki_kld_sym_lookup *)ARG3;
3214 POST_MEM_WRITE( (Addr)&kslp->symvalue, sizeof(kslp->symvalue) );
3215 POST_MEM_WRITE( (Addr)&kslp->symsize, sizeof(kslp->symsize) );
3218 // SYS_jail 338
3219 // int jail(struct jail *jail);
3220 PRE(sys_jail)
3222 PRINT("sys_jail ( %#" FMT_REGWORD "x )", ARG1);
3223 PRE_REG_READ1(int, "jail", struct jail *, jail);
3224 PRE_MEM_READ( "jail(jail)", ARG1, sizeof(struct vki_jail) );
3227 // SYS_nnpfs_syscall 338
3228 // @todo
3230 // SYS_sigprocmask 340
3231 // int sigprocmask(int how, const sigset_t * restrict set,
3232 // sigset_t * restrict oset);
3233 PRE(sys_sigprocmask)
3235 PRINT("sys_sigprocmask ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3);
3236 PRE_REG_READ3(int, "sigprocmask",
3237 int, how, vki_sigset_t *, set, vki_sigset_t *, oset);
3238 if (ARG2 != 0) {
3239 PRE_MEM_READ( "sigprocmask(set)", ARG2, sizeof(vki_sigset_t));
3241 if (ARG3 != 0) {
3242 PRE_MEM_WRITE( "sigprocmask(oset)", ARG3, sizeof(vki_sigset_t));
3245 if (ARG2 != 0 &&
3246 !ML_(safe_to_deref)((void *)(Addr)ARG2, sizeof(vki_sigset_t))) {
3247 VG_(dmsg)("Warning: Bad set handler address %p in sigprocmask\n",
3248 (void *)(Addr)ARG2);
3249 SET_STATUS_Failure ( VKI_EFAULT );
3250 } else if (ARG3 != 0 &&
3251 !ML_(safe_to_deref)((void *)(Addr)ARG3, sizeof(vki_sigset_t))) {
3252 VG_(dmsg)("Warning: Bad oldset address %p in sigprocmask\n",
3253 (void *)(Addr)ARG3);
3254 SET_STATUS_Failure ( VKI_EFAULT );
3255 } else {
3256 SET_STATUS_from_SysRes(VG_(do_sys_sigprocmask)(tid, ARG1 /*how*/,
3257 (vki_sigset_t*)(Addr)ARG2,
3258 (vki_sigset_t*)(Addr)ARG3));
3261 if (SUCCESS) {
3262 *flags |= SfPollAfter;
3266 POST(sys_sigprocmask)
3268 vg_assert(SUCCESS);
3269 if (RES == 0 && ARG3 != 0) {
3270 POST_MEM_WRITE( ARG3, sizeof(vki_sigset_t));
3274 // SYS_sigsuspend 341
3275 // int sigsuspend(const sigset_t *sigmask);
3276 PRE(sys_sigsuspend)
3278 *flags |= SfMayBlock;
3279 PRINT("sys_sigsuspend ( %#" FMT_REGWORD "x )", ARG1 );
3280 PRE_REG_READ1(int, "sigsuspend", const vki_sigset_t *, sigmask);
3281 PRE_MEM_READ( "sigsuspend(sigmask)", ARG1, sizeof(vki_sigset_t) );
3282 if (ARG1) {
3283 ARG1 = ML_(make_safe_mask)("syswrap.sigsuspend.1", (Addr)ARG1);
3287 POST(sys_sigsuspend)
3289 ML_(free_safe_mask) ( (Addr)ARG1 );
3292 // SYS_sigpending 343
3293 // int sigpending(sigset_t *set);
3294 PRE(sys_sigpending)
3296 PRINT( "sys_sigpending ( %#" FMT_REGWORD "x )", ARG1 );
3297 PRE_REG_READ1(int, "sigpending", vki_sigset_t *, set);
3298 PRE_MEM_WRITE( "sigpending(set)", ARG1, sizeof(vki_sigset_t));
3301 POST(sys_sigpending)
3303 POST_MEM_WRITE( ARG1, sizeof(vki_sigset_t) ) ;
3307 // SYS_sigtimedwait 345
3308 // int sigtimedwait(const sigset_t *restrict set, siginfo_t *restrict info,
3309 // const struct timespec *restrict timeout);
3310 PRE(sys_sigtimedwait)
3312 *flags |= SfMayBlock;
3313 PRINT("sys_sigtimedwait ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
3314 ARG1,ARG2,ARG3);
3315 PRE_REG_READ3(int, "sigtimedwait",
3316 const vki_sigset_t *, set, vki_siginfo_t *, info,
3317 const struct timespec *, timeout);
3318 if (ARG1 != 0) {
3319 PRE_MEM_READ( "sigtimedwait(set)", ARG1, sizeof(vki_sigset_t));
3321 if (ARG2 != 0) {
3322 PRE_MEM_WRITE( "sigtimedwait(info)", ARG2, sizeof(vki_siginfo_t) );
3324 if (ARG3 != 0) {
3325 PRE_MEM_READ( "sigtimedwait(timeout)",
3326 ARG3, sizeof(struct vki_timespec) );
3330 POST(sys_sigtimedwait)
3332 if (ARG2 != 0) {
3333 POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) );
3337 // SYS_sigwaitinfo 346
3338 // int sigwaitinfo(const sigset_t * restrict set, siginfo_t * restrict info);
3339 PRE(sys_sigwaitinfo)
3341 *flags |= SfMayBlock;
3342 PRINT("sys_sigwaitinfo ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
3343 ARG1,ARG2);
3344 PRE_REG_READ2(int, "sigwaitinfo",
3345 const vki_sigset_t *, set, vki_siginfo_t *, info);
3346 if (ARG1 != 0) {
3347 PRE_MEM_READ( "sigwaitinfo(set)", ARG1, sizeof(vki_sigset_t));
3349 if (ARG2 != 0) {
3350 PRE_MEM_WRITE( "sigwaitinfo(info)", ARG2, sizeof(vki_siginfo_t) );
3354 POST(sys_sigwaitinfo)
3356 if (ARG2 != 0) {
3357 POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) );
3361 // SYS___acl_get_file 347
3362 // int __acl_get_file(const char *path, acl_type_t type, struct acl *aclp);
3363 PRE(sys___acl_get_file)
3365 PRINT("sys___acl_get_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
3366 PRE_REG_READ3(int, "acl_get_file",
3367 const char *, path, int, type, struct vki_acl *, aclp);
3368 PRE_MEM_RASCIIZ("acl_get_file(path", ARG1);
3369 PRE_MEM_WRITE( "acl_get_file(aclp)", ARG3, sizeof(struct vki_acl) );
3372 POST(sys___acl_get_file)
3374 vg_assert(SUCCESS);
3375 if (RES == 0) {
3376 POST_MEM_WRITE( ARG3, sizeof(struct vki_acl) );
3380 // SYS___acl_set_file 348
3381 // int __acl_set_file(const char *path, acl_type_t type, struct acl *aclp);
3382 PRE(sys___acl_set_file)
3384 PRINT("sys___acl_set_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
3385 PRE_REG_READ3(int, "acl_set_file",
3386 const char *, path, int, type, struct vki_acl *, aclp);
3387 PRE_MEM_RASCIIZ("acl_set_file(path", ARG1);
3388 PRE_MEM_READ("acl_set_file(aclp)", ARG3, sizeof(struct vki_acl) );
3391 // SYS___acl_get_fd 349
3392 // int __acl_get_fd(int filedes, acl_type_t type, struct acl *aclp);
3393 PRE(sys___acl_get_fd)
3395 PRINT("sys___acl_get_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3396 PRE_REG_READ3(int, "acl_get_fd",
3397 int, fd, int, type, struct vki_acl *, aclp);
3398 PRE_MEM_WRITE( "acl_get_file(aclp)", ARG3, sizeof(struct vki_acl) );
3401 POST(sys___acl_get_fd)
3403 vg_assert(SUCCESS);
3404 if (RES == 0) {
3405 POST_MEM_WRITE( ARG3, sizeof(struct vki_acl) );
3409 // SYS___acl_set_fd 350
3410 // int __acl_set_fd(int filedes, acl_type_t type, struct acl *aclp);
3411 PRE(sys___acl_set_fd)
3413 PRINT("sys___acl_set_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3414 PRE_REG_READ3(int, "acl_set_fd",
3415 int, filedes, int, type, struct vki_acl *, aclp);
3416 PRE_MEM_READ( "acl_get_file(aclp)", ARG3, sizeof(struct vki_acl) );
3419 // SYS___acl_delete_file 351
3420 // int __acl_delete_file(const char *path, acl_type_t type);
3421 PRE(sys___acl_delete_file)
3423 PRINT("sys___acl_delete_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char *)ARG1,ARG2);
3424 PRE_MEM_RASCIIZ("acl_set_file(path", ARG1);
3425 PRE_REG_READ2(int, "acl_delete_file",
3426 const char *, path, int, type);
3428 // SYS___acl_delete_fd 352
3429 // int __acl_delete_fd(int filedes, acl_type_t type);
3430 PRE(sys___acl_delete_fd)
3432 PRINT("sys___acl_delete_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2);
3433 PRE_REG_READ2(int, "acl_delete_fd",
3434 int, filedes, int, acltype);
3437 // SYS___acl_aclcheck_file 353
3438 // int __acl_aclcheck_file(const char *path, acl_type_t type, struct acl *aclp);
3439 PRE(sys___acl_aclcheck_file)
3441 PRINT("sys___acl_aclcheck_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
3442 PRE_REG_READ3(int, "acl_aclcheck_file",
3443 const char *, path, int, type, struct vki_acl *, aclp);
3444 PRE_MEM_RASCIIZ("acl_set_file(path", ARG1);
3445 PRE_MEM_READ( "acl_aclcheck_file(aclp)", ARG3, sizeof(struct vki_acl) );
3448 // SYS___acl_aclcheck_fd 354
3449 // int __acl_aclcheck_fd(int filedes, acl_type_t type, struct acl *aclp);
3450 PRE(sys___acl_aclcheck_fd)
3452 PRINT("sys___acl_aclcheck_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3453 PRE_REG_READ3(int, "acl_aclcheck_fd",
3454 int, fd, int, type, struct vki_acl *, aclp);
3455 PRE_MEM_READ( "acl_aclcheck_fd(aclp)", ARG3, sizeof(struct vki_acl) );
3458 // SYS_extattrctl 355
3459 // no manpage?
3460 // syscalls.master: int extattrctl(_In_z_ const char *path, int cmd, _In_z_opt_ const char *filename, int attrnamespace, _In_z_ const char *attrname);
3461 PRE(sys_extattrctl)
3463 PRINT("sys_extattrctl ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3,SARG4,ARG5);
3464 PRE_REG_READ5(ssize_t, "extattrctl",
3465 const char *, path, int, cmd, const char *, filename, int, attrnamespace, const char *, attrname);
3466 PRE_MEM_RASCIIZ("extattrctl(path)", ARG1);
3467 PRE_MEM_RASCIIZ("extattrctl(filename)", ARG3);
3468 PRE_MEM_RASCIIZ("extattrctl(attrname)", ARG5);
3471 // SYS_extattr_set_file 356
3472 // ssize_t extattr_set_file(const char *path, int attrnamespace,
3473 // const char *attrname, const void *data, size_t nbytes);
3474 PRE(sys_extattr_set_file)
3476 PRINT("sys_extattr_set_file ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,SARG2,ARG3,ARG4,ARG5);
3477 PRE_REG_READ5(ssize_t, "extattr_set_file",
3478 const char *, path, int, attrnamespace, const char *, attrname, const void *, data, size_t, nbytes);
3479 PRE_MEM_RASCIIZ("extattr_set_file(path)", ARG1);
3480 PRE_MEM_RASCIIZ("extattr_set_file(attrname)", ARG3);
3481 PRE_MEM_READ("extattr_set_file(data)", ARG4, ARG5);
3484 // SYS_extattr_get_file 357
3485 // ssize_t extattr_get_file(const char *path, int attrnamespace,
3486 // const char *attrname, void *data, size_t nbytes);
3487 PRE(sys_extattr_get_file)
3489 PRINT("sys_extattr_get_file ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,SARG2,ARG3,ARG4,ARG5);
3490 PRE_REG_READ5(ssize_t, "extattr_get_file",
3491 const char *, path, int, attrnamespace, const char *, attrname, void *, data, size_t, nbytes);
3492 PRE_MEM_RASCIIZ("extattr_get_file(path)", ARG1);
3493 PRE_MEM_RASCIIZ("extattr_get_file(attrname)", ARG3);
3494 if (ARG4) {
3495 PRE_MEM_WRITE("extattr_get_file(data)", ARG4, ARG5);
3499 POST(sys_extattr_get_file)
3501 if (ARG4) {
3502 POST_MEM_WRITE(ARG4, ARG5);
3506 // SYS_extattr_delete_file 358
3507 // int extattr_delete_file(const char *path, int attrnamespace,
3508 // const char *attrname);
3509 PRE(sys_extattr_delete_file)
3511 PRINT("sys_extattr_delete_file ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3);
3512 PRE_REG_READ3(ssize_t, "extattr_delete_file",
3513 const char *, path, int, attrnamespace, const char *, attrname);
3514 PRE_MEM_RASCIIZ("extattr_delete_file(path)", ARG1);
3515 PRE_MEM_RASCIIZ("extattr_delete_file(attrname)", ARG3);
3518 // SYS_aio_waitcomplete 359
3519 // ssize_t aio_waitcomplete(struct aiocb **iocbp, struct timespec *timeout);
3520 PRE(sys_aio_waitcomplete)
3522 *flags |= SfMayBlock;
3523 PRINT("sys_aio_waitcomplete ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2);
3524 PRE_REG_READ2(ssize_t, "aio_waitcomplete", struct aiocb **, iocbp, struct timespec *, timeout);
3525 if (ARG2) {
3526 PRE_MEM_READ("aio_waitcomplete(timeout", ARG2, sizeof(struct vki_timespec));
3528 PRE_MEM_WRITE( "aio_waitcomplete(iocbp)", ARG1, sizeof(struct aiocb *));
3531 POST(sys_aio_waitcomplete)
3533 POST_MEM_WRITE(ARG1, sizeof(struct aiocb *));
3536 // SYS_getresuid 360
3537 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
3538 PRE(sys_getresuid)
3540 PRINT("sys_getresuid ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3541 PRE_REG_READ3(long, "getresuid",
3542 vki_uid_t *, ruid, vki_uid_t *, euid, vki_uid_t *, suid);
3543 PRE_MEM_WRITE( "getresuid(ruid)", ARG1, sizeof(vki_uid_t) );
3544 PRE_MEM_WRITE( "getresuid(euid)", ARG2, sizeof(vki_uid_t) );
3545 PRE_MEM_WRITE( "getresuid(suid)", ARG3, sizeof(vki_uid_t) );
3548 POST(sys_getresuid)
3550 vg_assert(SUCCESS);
3551 if (RES == 0) {
3552 POST_MEM_WRITE( ARG1, sizeof(vki_uid_t) );
3553 POST_MEM_WRITE( ARG2, sizeof(vki_uid_t) );
3554 POST_MEM_WRITE( ARG3, sizeof(vki_uid_t) );
3558 // SYS_getresgid 361
3559 // int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid);
3560 PRE(sys_getresgid)
3562 PRINT("sys_getresgid ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3563 PRE_REG_READ3(long, "getresgid",
3564 vki_gid_t *, rgid, vki_gid_t *, egid, vki_gid_t *, sgid);
3565 PRE_MEM_WRITE( "getresgid(rgid)", ARG1, sizeof(vki_gid_t) );
3566 PRE_MEM_WRITE( "getresgid(egid)", ARG2, sizeof(vki_gid_t) );
3567 PRE_MEM_WRITE( "getresgid(sgid)", ARG3, sizeof(vki_gid_t) );
3570 POST(sys_getresgid)
3572 vg_assert(SUCCESS);
3573 if (RES == 0) {
3574 POST_MEM_WRITE( ARG1, sizeof(vki_gid_t) );
3575 POST_MEM_WRITE( ARG2, sizeof(vki_gid_t) );
3576 POST_MEM_WRITE( ARG3, sizeof(vki_gid_t) );
3580 // SYS_kqueue 362
3581 // int kqueue(void);
3582 PRE(sys_kqueue)
3584 PRINT("%s", "sys_kqueue(void)");
3585 PRE_REG_READ0(int, "kqueue");
3588 POST(sys_kqueue)
3590 if (!ML_(fd_allowed)(RES, "kqueue", tid, True)) {
3591 VG_(close)(RES);
3592 SET_STATUS_Failure( VKI_EMFILE );
3593 } else {
3594 if (VG_(clo_track_fds)) {
3595 ML_(record_fd_open_nameless)(tid, RES);
3600 // SYS_freebsd11_kevent 363
3601 // int kevent(int kq, const struct kevent *changelist, int nchanges,
3602 // struct kevent *eventlist, int nevents,
3603 // const struct timespec *timeout);
3604 #if (FREEBSD_VERS >= FREEBSD_12)
3605 PRE(sys_freebsd11_kevent)
3607 PRINT("sys_freebsd11_kevent ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )\n", ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
3608 PRE_REG_READ6(int, "kevent",
3609 int, fd, const struct vki_kevent_freebsd11 *, changelist, int, nchanges,
3610 struct vki_kevent_freebsd11 *, eventlist, int, nevents,
3611 struct timespec *, timeout);
3612 if (ARG2 != 0 && ARG3 != 0) {
3613 PRE_MEM_READ( "kevent(changelist)", ARG2, sizeof(struct vki_kevent_freebsd11)*ARG3 );
3615 if (ARG4 != 0 && ARG5 != 0) {
3616 PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent_freebsd11)*ARG5);
3618 if (ARG5 != 0) {
3619 *flags |= SfMayBlock;
3621 if (ARG6 != 0) {
3622 PRE_MEM_READ( "kevent(timeout)",
3623 ARG6, sizeof(struct vki_timespec));
3627 POST(sys_freebsd11_kevent)
3629 vg_assert(SUCCESS);
3630 if ((Word)RES != -1) {
3631 if (ARG4 != 0) {
3632 POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent_freebsd11)*RES) ;
3636 #else
3637 PRE(sys_kevent)
3639 *flags |= SfMayBlock;
3640 PRINT("sys_kevent ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )\n", ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
3641 PRE_REG_READ6(int, "kevent",
3642 int, fd, struct vki_kevent_freebsd11 *, changelist, int, nchanges,
3643 struct vki_kevent_freebsd11 *, eventlist, int, nevents,
3644 struct timespec *, timeout);
3645 if (ARG2 != 0 && ARG3 != 0)
3646 PRE_MEM_READ( "kevent(changelist)", ARG2, sizeof(struct vki_kevent_freebsd11)*ARG3 );
3647 if (ARG4 != 0 && ARG5 != 0)
3648 PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent_freebsd11)*ARG5);
3649 if (ARG6 != 0)
3650 PRE_MEM_READ( "kevent(timeout)",
3651 ARG6, sizeof(struct vki_timespec));
3654 POST(sys_kevent)
3656 vg_assert(SUCCESS);
3657 if ((Word)RES != -1) {
3658 if (ARG4 != 0)
3659 POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent_freebsd11)*RES) ;
3662 #endif
3664 // SYS_extattr_set_fd 371
3665 // ssize_t extattr_set_fd(int fd, int attrnamespace, const char *attrname,
3666 // const void *data, size_t nbytes);
3667 PRE(sys_extattr_set_fd)
3669 PRINT("sys_extattr_set_fd ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", SARG1,SARG2,ARG3,ARG4,ARG5);
3670 PRE_REG_READ5(int, "extattr_set_fd", int, fd, int, attrnamespace, const char *,attrname, const void *,data, size_t, nbytes);
3671 PRE_MEM_RASCIIZ( "extattr_set_fd(attrname)", ARG3 );
3672 PRE_MEM_READ("extattr_set_fd(data)", ARG4, ARG5);
3675 // SYS_extattr_get_fd 372
3676 // ssize_t extattr_get_fd(int fd, int attrnamespace, const char *attrname,
3677 // void *data, size_t nbytes);
3678 PRE(sys_extattr_get_fd)
3680 PRINT("sys_extattr_get_fd ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", SARG1,SARG2,ARG3,ARG4,ARG5);
3681 PRE_REG_READ5(int, "extattr_get_fd", int, fd, int, attrnamespace, const char *,attrname, const void *,data, size_t, nbytes);
3682 PRE_MEM_RASCIIZ( "extattr_get_fd(attrname)", ARG3 );
3683 PRE_MEM_WRITE("extattr_get_fd(data)", ARG4, ARG5);
3686 POST(sys_extattr_get_fd)
3688 POST_MEM_WRITE(ARG4, ARG5);
3691 // SYS_extattr_delete_fd 373
3692 // int extattr_delete_fd(int fd, int attrnamespace, const char *attrname);
3693 PRE(sys_extattr_delete_fd)
3695 PRINT("sys_extattr_delete_fd ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3);
3696 PRE_REG_READ3(int, "extattr_delete_fd", int, fd, int, attrnamespace, const char *,attrname);
3697 PRE_MEM_RASCIIZ( "extattr_delete_fd(attrname)", ARG3 );
3700 // SYS___setugid 374
3701 // no manpage?
3702 // syscalls.master: int __setugid(int flag);
3703 PRE(sys___setugid)
3705 PRINT("sys___setugid ( %" FMT_REGWORD "d )", SARG1);
3706 PRE_REG_READ1(int, "__setugid", int, flag);
3709 // SYS_eaccess 376
3710 // int eaccess(const char *path, int mode);
3711 PRE(sys_eaccess)
3713 PRINT("sys_eaccess ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char*)ARG1,ARG2);
3714 PRE_REG_READ2(int, "eaccess", const char *, path, int, mode);
3715 PRE_MEM_RASCIIZ( "eaccess(path)", ARG1 );
3718 // SYS_afs3_syscall 377
3719 // @todo
3721 // SYS_nmount 378
3722 // int nmount(struct iovec *iov, u_int niov, int flags);
3723 PRE(sys_nmount)
3725 PRINT("sys_nmount ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d )", ARG1, ARG2, SARG3);
3726 PRE_REG_READ3(int, "nmount", struct iovec *, iov, u_int, niov, int, flags);
3727 PRE_MEM_READ( "nmount(pathname)", ARG1, ARG2*sizeof(struct vki_iovec) );
3730 // SYS___mac_get_proc 384
3731 // @todo
3733 // SYS___mac_set_proc 385
3734 // @todo
3736 // SYS___mac_get_fd 386
3737 // @todo
3739 // SYS___mac_get_file 387
3740 // @todo
3742 // SYS___mac_set_fd 388
3743 // @todo
3745 // SYS___mac_set_file 389
3746 // @todo
3748 // SYS_kenv 390
3749 // int kenv(int action, const char *name, char *value, int len);
3750 PRE(sys_kenv)
3752 PRINT("sys_kenv ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3,ARG4);
3753 PRE_REG_READ4(int, "kenv",
3754 int, action, const char *, name, char *, value, int, len);
3755 switch (ARG1) {
3756 case VKI_KENV_GET:
3757 case VKI_KENV_SET:
3758 case VKI_KENV_UNSET:
3759 PRE_MEM_RASCIIZ("kenv(name)", ARG2);
3760 /* FALLTHROUGH */
3761 case VKI_KENV_DUMP:
3762 break;
3763 default:
3764 VG_(dmsg)("Warning: Bad action %" FMT_REGWORD "u in kenv\n", ARG1);
3768 POST(sys_kenv)
3770 if (SUCCESS) {
3771 switch (ARG1) {
3772 case VKI_KENV_GET:
3773 POST_MEM_WRITE(ARG3, ARG4);
3774 break;
3775 case VKI_KENV_DUMP:
3776 if (ARG3 != (Addr)NULL) {
3777 POST_MEM_WRITE(ARG3, ARG4);
3779 break;
3784 // SYS_lchflags 391
3785 // int lchflags(const char *path, unsigned long flags);
3786 PRE(sys_lchflags)
3788 PRINT("sys_lchflags ( %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2);
3789 PRE_REG_READ2(int, "lchflags",
3790 const char *, path, unsigned long, flags);
3791 PRE_MEM_RASCIIZ( "lchflags(path)", ARG1 );
3794 // SYS_uuidgen 392
3795 // int uuidgen(struct uuid *store, int count);
3796 PRE(sys_uuidgen)
3798 PRINT("sys_uuidgen ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2);
3799 PRE_REG_READ2(int, "uuidgen",
3800 struct vki_uuid *, store, int, count);
3801 PRE_MEM_WRITE( "uuidgen(store)", ARG1, ARG2 * sizeof(struct vki_uuid));
3804 POST(sys_uuidgen)
3806 if (SUCCESS) {
3807 POST_MEM_WRITE( ARG1, ARG2 * sizeof(struct vki_uuid) );
3811 // SYS_sendfile 393
3812 // x86/amd64
3814 // SYS_mac_syscall 394
3815 // @todo
3817 #if (FREEBSD_VERS >= FREEBSD_12)
3819 // SYS_freebsd11_getfsstat 395
3820 // int getfsstat(struct freebsd11_statfs *buf, long bufsize, int mode);
3822 PRE(sys_freebsd11_getfsstat)
3824 PRINT("sys_freebsd11_getfsstat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
3825 PRE_REG_READ3(int, "getfsstat", struct vki_freebsd11_statfs *, buf, long, bufsize, int, mode);
3826 PRE_MEM_WRITE( "getfsstat(buf)", ARG1, ARG2 );
3829 POST(sys_freebsd11_getfsstat)
3831 vg_assert(SUCCESS);
3832 if ((Word)RES != -1) {
3833 POST_MEM_WRITE( ARG1, RES * sizeof(struct vki_freebsd11_statfs) );
3837 // SYS_freebsd11_statfs 396
3838 // int statfs(const char *path, struct statfs *buf);
3839 PRE(sys_freebsd11_statfs)
3841 PRINT("sys_statfs ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
3842 PRE_REG_READ2(int, "statfs", const char *, path, struct statfs *, buf);
3843 PRE_MEM_RASCIIZ( "statfs(path)", ARG1 );
3844 PRE_MEM_WRITE( "statfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3847 POST(sys_freebsd11_statfs)
3849 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3852 // SYS_freebsd11_fstatfs 397
3853 // int fstatfs(int fd, struct statfs *buf);
3854 PRE(sys_freebsd11_fstatfs)
3856 PRINT("sys_fstatfs ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2);
3857 PRE_REG_READ2(int, "fstatfs",
3858 unsigned int, fd, struct statfs *, buf);
3859 PRE_MEM_WRITE( "fstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3862 POST(sys_freebsd11_fstatfs)
3864 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3867 // SYS_freebsd11_fhstatfs 398
3868 // int fhstatfs(const fhandle_t *fhp, struct statfs *buf);
3869 PRE(sys_freebsd11_fhstatfs)
3871 PRINT("sys_fhstatfs ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
3872 PRE_REG_READ2(int, "fhstatfs",
3873 struct fhandle *, fhp, struct statfs *, buf);
3874 PRE_MEM_READ( "fhstatfs(fhp)", ARG1, sizeof(struct vki_fhandle) );
3875 PRE_MEM_WRITE( "fhstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3878 POST(sys_freebsd11_fhstatfs)
3880 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3884 #else
3886 PRE(sys_getfsstat)
3888 PRINT("sys_getfsstat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
3889 PRE_REG_READ3(int, "getfsstat", struct vki_freebsd11_statfs *, buf, long, bufsize, int, mode);
3890 PRE_MEM_WRITE( "getfsstat(buf)", ARG1, ARG2 );
3893 POST(sys_getfsstat)
3895 vg_assert(SUCCESS);
3896 if ((Word)RES != -1) {
3897 POST_MEM_WRITE( ARG1, RES * sizeof(struct vki_freebsd11_statfs) );
3901 PRE(sys_statfs)
3903 PRINT("sys_statfs ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
3904 PRE_REG_READ2(int, "statfs", const char *, path, struct statfs *, buf);
3905 PRE_MEM_RASCIIZ( "statfs(path)", ARG1 );
3906 PRE_MEM_WRITE( "statfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3909 POST(sys_statfs)
3911 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3914 PRE(sys_fstatfs)
3916 PRINT("sys_fstatfs ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2);
3917 PRE_REG_READ2(int, "fstatfs",
3918 unsigned int, fd, struct statfs *, buf);
3919 PRE_MEM_WRITE( "fstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3922 POST(sys_fstatfs)
3924 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3927 PRE(sys_fhstatfs)
3929 PRINT("sys_fhstatfs ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
3930 PRE_REG_READ2(int, "fhstatfs",
3931 struct fhandle *, fhp, struct statfs *, buf);
3932 PRE_MEM_READ( "fhstatfs(fhp)", ARG1, sizeof(struct vki_fhandle) );
3933 PRE_MEM_WRITE( "fhstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3936 POST(sys_fhstatfs)
3938 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3942 #endif
3944 // SYS_ksem_close 400
3945 // @todo
3947 // SYS_ksem_post 401
3948 // @todo
3950 // SYS_ksem_wait 402
3951 // @todo
3953 // SYS_ksem_trywait 403
3954 // @todo
3956 // SYS_ksem_init 404
3957 // @todo
3959 // SYS_ksem_open 405
3960 // @todo
3962 // SYS_ksem_unlink 406
3963 // @todo
3965 // SYS_ksem_getvalue 407
3966 // @todo
3968 // SYS_ksem_destroy 408
3969 // @todo
3971 // SYS___mac_get_pid 409
3972 // @todo
3974 // SYS___mac_get_link 410
3975 // @todo
3977 // SYS___mac_set_link 411
3978 // @todo
3980 // SYS_extattr_set_link 412
3981 // ssize_t extattr_set_link(const char *path, int attrnamespace,
3982 // const char *attrname, const void *data, size_t nbytes);
3983 PRE(sys_extattr_set_link)
3985 PRINT("sys_extattr_set_link ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,SARG2,ARG3,ARG4,ARG5);
3986 PRE_REG_READ5(ssize_t, "extattr_set_link",
3987 const char *, path, int, attrnamespace, const char *, attrname, const void *, data, size_t, nbytes);
3988 PRE_MEM_RASCIIZ("extattr_set_link(path)", ARG1);
3989 PRE_MEM_RASCIIZ("extattr_set_link(attrname)", ARG3);
3990 PRE_MEM_READ("extattr_set_link(data)", ARG4, ARG5);
3993 // SYS_extattr_get_link 413
3994 // ssize_t extattr_get_link(const char *path, int attrnamespace,
3995 // const char *attrname, void *data, size_t nbytes);
3996 PRE(sys_extattr_get_link)
3998 PRINT("sys_extattr_get_link ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,SARG2,ARG3,ARG4,ARG5);
3999 PRE_REG_READ5(ssize_t, "extattr_get_link",
4000 const char *, path, int, attrnamespace, const char *, attrname, void *, data, size_t, nbytes);
4001 PRE_MEM_RASCIIZ("extattr_get_link(path)", ARG1);
4002 PRE_MEM_RASCIIZ("extattr_get_link(attrname)", ARG3);
4003 if (ARG4) {
4004 PRE_MEM_WRITE("extattr_get_link(data)", ARG4, ARG5);
4008 POST(sys_extattr_get_link)
4010 if (ARG4) {
4011 POST_MEM_WRITE(ARG4, ARG5);
4015 // SYS_extattr_delete_link 414
4016 // int extattr_delete_link(const char *path, int attrnamespace,
4017 // const char *attrname);
4018 PRE(sys_extattr_delete_link)
4020 PRINT("sys_extattr_delete_link ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3);
4021 PRE_REG_READ3(ssize_t, "extattr_delete_link",
4022 const char *, path, int, attrnamespace, const char *, attrname);
4023 PRE_MEM_RASCIIZ("extattr_delete_link(path)", ARG1);
4024 PRE_MEM_RASCIIZ("extattr_delete_link(attrname)", ARG3);
4027 // SYS___mac_execve 415
4028 // @todo
4030 // SYS_sigaction 416
4031 //int sigaction(int sig, const struct sigaction * restrict act,
4032 // struct sigaction * restrict oact);
4033 PRE(sys_sigaction)
4035 vki_sigaction_toK_t new;
4036 vki_sigaction_toK_t *newp;
4037 vki_sigaction_fromK_t old;
4038 vki_sigaction_fromK_t *oldp;
4040 PRINT("sys_sigaction ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
4041 SARG1,ARG2,ARG3);
4042 PRE_REG_READ3(long, "sigaction",
4043 int, sign, const struct sigaction *, act,
4044 struct sigaction *, oact);
4046 newp = oldp = NULL;
4048 if (ARG2 != 0) {
4049 struct vki_sigaction *sa = (struct vki_sigaction *)ARG2;
4050 PRE_MEM_READ( "sigaction(act->sa_handler)", (Addr)&sa->ksa_handler, sizeof(sa->ksa_handler));
4051 PRE_MEM_READ( "sigaction(act->sa_mask)", (Addr)&sa->sa_mask, sizeof(sa->sa_mask));
4052 PRE_MEM_READ( "sigaction(act->sa_flags)", (Addr)&sa->sa_flags, sizeof(sa->sa_flags));
4055 if (ARG3 != 0) {
4056 PRE_MEM_WRITE( "sigaction(oact)", ARG3, sizeof(struct vki_sigaction));
4057 oldp = &old;
4060 if (ARG2 != 0
4061 && ! ML_(safe_to_deref)((void *)(Addr)ARG2,
4062 sizeof(struct vki_sigaction))) {
4063 VG_(umsg)("Warning: bad act handler address %p in sigaction()\n",
4064 (void *)(Addr)ARG2);
4065 SET_STATUS_Failure ( VKI_EFAULT );
4066 } else if ((ARG3 != 0
4067 && ! ML_(safe_to_deref)((void *)(Addr)ARG3,
4068 sizeof(struct vki_sigaction)))) {
4069 VG_(umsg)("Warning: bad oact handler address %p in sigaction()\n",
4070 (void *)(Addr)ARG3);
4071 SET_STATUS_Failure ( VKI_EFAULT );
4072 } else {
4073 if (ARG2 != 0) {
4074 struct vki_sigaction *oldnew =
4075 (struct vki_sigaction *)(Addr)ARG2;
4077 new.ksa_handler = oldnew->ksa_handler;
4078 new.sa_flags = oldnew->sa_flags;
4079 new.sa_mask = oldnew->sa_mask;
4080 newp = &new;
4083 SET_STATUS_from_SysRes( VG_(do_sys_sigaction)(ARG1, newp, oldp) );
4085 if (ARG3 != 0 && SUCCESS && RES == 0) {
4086 struct vki_sigaction *oldold =
4087 (struct vki_sigaction *)(Addr)ARG3;
4089 oldold->ksa_handler = oldp->ksa_handler;
4090 oldold->sa_flags = oldp->sa_flags;
4091 oldold->sa_mask = oldp->sa_mask;
4096 POST(sys_sigaction)
4098 vg_assert(SUCCESS);
4099 if (RES == 0 && ARG3 != 0) {
4100 POST_MEM_WRITE( ARG3, sizeof(struct vki_sigaction));
4104 // SYS_sigreturn 417
4105 // x86/amd64
4107 // SYS_getcontext 421
4108 // SYS_setcontext 422
4109 // SYS_swapcontext 423
4110 // PRE in x86/amd64
4112 POST(sys_getcontext)
4114 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucontext) );
4117 POST(sys_swapcontext)
4119 if (SUCCESS) {
4120 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucontext) );
4124 #if (FREEBSD_VERS >= FREEBSD_13_1)
4125 // SYS_freebsd13_swapoff 424
4126 // int swapoff(const char *special);
4127 PRE(sys_freebsd13_swapoff)
4129 PRINT("sys_freebsd13_swapoff ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
4130 PRE_REG_READ1(int, "swapoff", const char *, special);
4131 PRE_MEM_RASCIIZ( "swapoff(special)", ARG1 );
4133 #else
4134 // SYS_swapoff 424
4135 // int swapoff(const char *special);
4136 PRE(sys_swapoff)
4138 PRINT("sys_swapoff ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
4139 PRE_REG_READ1(int, "swapoff", const char *, special);
4140 PRE_MEM_RASCIIZ( "swapoff(special)", ARG1 );
4142 #endif
4144 // SYS___acl_get_link 425
4145 // int __acl_get_link(const char *path, acl_type_t type, struct acl *aclp);
4146 PRE(sys___acl_get_link)
4148 PRINT("sys___acl_get_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
4149 PRE_REG_READ3(int, "__acl_get_link",
4150 const char *, path, int, acltype, struct vki_acl *, aclp);
4151 PRE_MEM_RASCIIZ( "__acl_get_link(path)", ARG1 );
4152 PRE_MEM_WRITE( "__acl_get_link(aclp)", ARG3, sizeof(struct vki_acl) );
4155 POST(sys___acl_get_link)
4157 vg_assert(SUCCESS);
4158 if (RES == 0) {
4159 POST_MEM_WRITE( ARG3, sizeof(struct vki_acl) );
4163 // SYS___acl_set_link 426
4164 // int __acl_set_link(const char *path, acl_type_t type, struct acl *aclp);
4165 PRE(sys___acl_set_link)
4167 PRINT("sys___acl_set_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
4168 PRE_REG_READ3(int, "__acl_set_link",
4169 const char *, path, int, acltype, struct vki_acl *, aclp);
4170 PRE_MEM_RASCIIZ( "__acl_set_link(path)", ARG1 );
4171 PRE_MEM_READ( "__acl_set_link(aclp)", ARG3, sizeof(struct vki_acl) );
4173 // SYS___acl_delete_link 427
4174 // int __acl_delete_link(const char *path, acl_type_t type);
4175 PRE(sys___acl_delete_link)
4177 PRINT("sys___acl_delete_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char *)ARG1,ARG2);
4178 PRE_MEM_RASCIIZ( "__acl_delete_link(path)", ARG1 );
4179 PRE_REG_READ2(int, "__acl_delete_link",
4180 const char *, path, int, acltype);
4183 // SYS___acl_aclcheck_link 428
4184 // int __acl_aclcheck_link(const char *path, acl_type_t type, struct acl *aclp);
4185 PRE(sys___acl_aclcheck_link)
4187 PRINT("sys___acl_aclcheck_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
4188 PRE_REG_READ3(long, "__acl_aclcheck_link",
4189 const char *, path, int, acltype, struct vki_acl *, aclp);
4190 PRE_MEM_RASCIIZ( "__acl_check_link(path)", ARG1 );
4191 PRE_MEM_READ( "__acl_aclcheck_link(aclp)", ARG3, sizeof(struct vki_acl) );
4194 // SYS_sigwait 429
4195 // int sigwait(const sigset_t * restrict set, int * restrict sig);
4196 PRE(sys_sigwait)
4198 *flags |= SfMayBlock;
4199 PRINT("sys_sigwait ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
4200 ARG1,ARG2);
4201 PRE_REG_READ2(int, "sigwait",
4202 const vki_sigset_t *, set, int *, sig);
4203 if (ARG1 != 0) {
4204 PRE_MEM_READ( "sigwait(set)", ARG1, sizeof(vki_sigset_t));
4206 if (ARG2 != 0) {
4207 PRE_MEM_WRITE( "sigwait(sig)", ARG2, sizeof(int));
4211 POST(sys_sigwait)
4213 if (ARG2 != 0) {
4214 POST_MEM_WRITE( ARG2, sizeof(int));
4218 // SYS_thr_create 430
4219 // no manpage?
4220 // syscalls.master: int thr_create(_In_ ucontext_t *ctx, _Out_ long *id, int flags );
4221 PRE(sys_thr_create)
4223 PRINT( "sys_thr_create ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )", ARG1, ARG2, SARG3 );
4224 PRE_REG_READ3(int, "thr_create", /*ucontext_t*/void *, ctx, long *, id, int, flags );
4226 VG_(message)(Vg_UserMsg, "thr_create() not implemented");
4227 VG_(unimplemented)("Valgrind does not support thr_create().");
4229 SET_STATUS_Failure(VKI_ENOSYS);
4232 // SYS_thr_exit 431
4233 // void thr_exit(long *state);
4234 PRE(sys_thr_exit)
4236 ThreadState *tst;
4238 PRINT( "sys_thr_exit ( %#" FMT_REGWORD "x )", ARG1 );
4239 PRE_REG_READ1(void, "thr_exit", long *, state);
4241 if (ARG1) {
4242 PRE_MEM_WRITE( "thr_exit(state)", ARG1, sizeof(long) );
4245 tst = VG_(get_ThreadState)(tid);
4246 tst->exitreason = VgSrc_ExitThread;
4247 tst->os_state.exitcode = ARG1;
4248 SET_STATUS_Success(0);
4251 // SYS_thr_self 432
4252 // int thr_self(long *id);
4253 PRE(sys_thr_self)
4255 PRINT( "sys_thr_self ( %#" FMT_REGWORD "x )", ARG1 );
4256 PRE_REG_READ1(int, "thr_self", long *, id);
4257 PRE_MEM_WRITE( "thr_self()", ARG1, sizeof(long));
4260 POST(sys_thr_self)
4262 POST_MEM_WRITE( ARG1, sizeof(long));
4265 // SYS_thr_kill 433
4266 // int thr_kill(long id, int sig);
4267 PRE(sys_thr_kill)
4269 PRINT("sys_thr_kill ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2);
4270 PRE_REG_READ2(long, "thr_kill", long, id, int, sig);
4271 if (!ML_(client_signal_OK)(ARG2)) {
4272 SET_STATUS_Failure( VKI_EINVAL );
4273 return;
4276 /* Check to see if this kill gave us a pending signal */
4277 *flags |= SfPollAfter;
4279 if (VG_(clo_trace_signals)) {
4280 VG_(message)(Vg_DebugMsg, "thr_kill: sending signal %lu to tid %lu\n",
4281 ARG2, ARG1);
4284 /* If we're sending SIGKILL, check to see if the target is one of
4285 our threads and handle it specially. */
4286 if (ARG2 == VKI_SIGKILL && ML_(do_sigkill)(ARG1, -1)) {
4287 SET_STATUS_Success(0);
4288 return;
4291 /* Ask to handle this syscall via the slow route, since that's the
4292 only one that sets tst->status to VgTs_WaitSys. If the result
4293 of doing the syscall is an immediate run of
4294 async_signalhandler() in m_signals, then we need the thread to
4295 be properly tidied away. I have the impression the previous
4296 version of this wrapper worked on x86/amd64 only because the
4297 kernel did not immediately deliver the async signal to this
4298 thread (on ppc it did, which broke the assertion re tst->status
4299 at the top of async_signalhandler()). */
4300 *flags |= SfMayBlock;
4303 POST(sys_thr_kill)
4305 if (VG_(clo_trace_signals)) {
4306 VG_(message)(Vg_DebugMsg, "thr_kill: sent signal %lu to tid %lu\n",
4307 ARG2, ARG1);
4311 #if (FREEBSD_VERS <= FREEBSD_10)
4312 // SYS__umtx_lock 434
4313 PRE(sys__umtx_lock)
4315 PRINT( "sys__umtx_lock ( %#" FMT_REGWORD "x )", ARG1);
4316 PRE_REG_READ1(long, "_umtx_lock", struct vki_umtx *, umtx);
4317 PRE_MEM_READ( "_umtx_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4318 PRE_MEM_WRITE( "_umtx_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4321 POST(sys__umtx_lock)
4323 if (SUCCESS) {
4324 POST_MEM_WRITE(ARG1, sizeof(struct vki_umtx));
4328 // SYS__umtx_unlock 434
4329 PRE(sys__umtx_unlock)
4331 PRINT( "sys__umtx_unlock ( %#" FMT_REGWORD "x )", ARG1);
4332 PRE_REG_READ1(long, "_umtx_unlock", struct vki_umtx *, umtx);
4333 PRE_MEM_READ( "_umtx_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4334 PRE_MEM_WRITE( "_umtx_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4337 POST(sys__umtx_unlock)
4339 if (SUCCESS) {
4340 POST_MEM_WRITE(ARG1, sizeof(struct vki_umtx));
4343 #endif
4345 // SYS_jail_attach 436
4346 // int jail_attach(int jid);
4347 PRE(sys_jail_attach)
4349 PRINT("sys_jail_attach ( %" FMT_REGWORD "d )", SARG1);
4350 PRE_REG_READ1(int, "jail_attach", int, jid);
4353 // SYS_extattr_list_fd 437
4354 // ssize_t extattr_list_fd(int fd, int attrnamespace, void *data, size_t nbytes);
4355 PRE(sys_extattr_list_fd)
4357 PRINT("extattr_list_fd ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", SARG1, SARG2, ARG3, ARG4);
4358 PRE_REG_READ4(ssize_t, "extattr_list_fd", int, id, int, attrnamespace, void *,data, size_t, nbytes);
4359 PRE_MEM_WRITE("extattr_list_fd(data)", ARG3, ARG4);
4362 POST(sys_extattr_list_fd)
4364 POST_MEM_WRITE(ARG3, ARG4);
4367 // SYS_extattr_list_file 438
4368 // ssize_t extattr_list_file(const char *path, int attrnamespace, void *data,
4369 // size_t nbytes);
4370 PRE(sys_extattr_list_file)
4372 PRINT("extattr_list_file ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, SARG2, ARG3, ARG4);
4373 PRE_REG_READ4(ssize_t, "extattr_list_file", const char *, path, int, attrnamespace, void *,data, size_t, nbytes);
4374 PRE_MEM_RASCIIZ("extattr_list_file(path)", ARG1);
4375 PRE_MEM_WRITE("extattr_list_file(data)", ARG3, ARG4);
4378 POST(sys_extattr_list_file)
4380 POST_MEM_WRITE(ARG3, ARG4);
4383 // SYS_extattr_list_link 439
4384 // ssize_t extattr_get_link(const char *path, int attrnamespace,
4385 // const char *attrname, void *data, size_t nbytes);
4386 PRE(sys_extattr_list_link)
4388 PRINT("extattr_list_link ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, SARG2, ARG3, ARG4);
4389 PRE_REG_READ4(ssize_t, "extattr_list_link", const char *, path, int, attrnamespace, void *,data, size_t, nbytes);
4390 PRE_MEM_RASCIIZ("extattr_list_link(path)", ARG1);
4391 PRE_MEM_WRITE("extattr_list_link(data)", ARG3, ARG4);
4394 POST(sys_extattr_list_link)
4396 POST_MEM_WRITE(ARG3, ARG4);
4399 // SYS_ksem_timedwait 441
4400 // @todo
4402 // SYS_thr_suspend 442
4403 // int thr_suspend(struct timespec *timeout);
4404 PRE(sys_thr_suspend)
4406 PRINT("sys_thr_suspend ( %#" FMT_REGWORD "x )", ARG1);
4407 PRE_REG_READ1(int, "thr_suspend", struct timespec *, timeout);
4408 PRE_MEM_READ("thr_suspend(timeout)", ARG1, sizeof(struct vki_timespec));
4410 VG_(message)(Vg_UserMsg, "thr_supend() not implemented");
4411 VG_(unimplemented)("Valgrind does not support thr_suspend().");
4413 SET_STATUS_Failure(VKI_ENOSYS);
4416 // SYS_thr_wake 443
4417 // int thr_wake(long id);
4418 PRE(sys_thr_wake)
4420 PRINT("sys_thr_wake ( %" FMT_REGWORD "d )", SARG1);
4421 PRE_REG_READ1(long, "thr_wake", long, id);
4423 if (VG_(is_valid_tid)(ARG1)) {
4424 VG_(threads)[ARG1].status = VgTs_Runnable;
4425 } else {
4426 SET_STATUS_Failure( VKI_ESRCH );
4431 // SYS_kldunloadf 444
4432 // int kldunloadf(int fileid, int flags);
4433 PRE(sys_kldunloadf)
4435 PRINT("sys_kldunloadf ( %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1, SARG2);
4436 PRE_REG_READ2(int, "kldunloadf", int, fileid, int, flags);
4439 // SYS_audit 445
4440 // int audit(const char *record, u_int length);
4441 // @todo
4443 // SYS_auditon 446
4444 // int auditon(int cmd, void *data, u_int length);
4445 // @todo
4447 // SYS_getauid 447
4448 // int getauid(au_id_t *auid);
4449 // @todo
4451 // SYS_setauid 448
4452 // int setauid(au_id_t *auid);
4453 // @todo
4455 // SYS_getaudit 449
4456 // int getaudit(auditinfo_t *auditinfo);
4457 // @todo
4459 // SYS_setaudit 450
4460 // int setaudit(auditinfo_t *auditinfo);
4461 // @todo
4463 // SYS_getaudit_addr 451
4464 // int getaudit_addr(auditinfo_addr_t *auditinfo_addr, u_int length);
4465 // @todo
4467 // SYS_setaudit_addr 452
4468 // int setaudit_addr(auditinfo_addr_t *auditinfo_addr, u_int length);
4469 // @todo
4471 // SYS_auditctl 453
4472 // @todo
4474 // SYS__umtx_op 454
4475 // int _umtx_op(void *obj, int op, u_long val, void *uaddr, void *uaddr2);
4476 PRE(sys__umtx_op)
4478 /* 5 args are always passed through. The last two can vary, but
4479 they're always pointers. They may not be used though. */
4480 switch(ARG2) {
4481 case VKI_UMTX_OP_LOCK:
4482 // marked as COMPAT10
4483 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, LOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4484 PRE_REG_READ5(long, "_umtx_op_lock",
4485 struct umtx *, obj, int, op, unsigned long, id,
4486 size_t, timeout_size, struct vki_timespec *, timeout);
4487 PRE_MEM_READ( "_umtx_op_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4488 if (ARG5) {
4489 PRE_MEM_READ( "_umtx_op_lock(timespec)", ARG5, ARG4 );
4491 PRE_MEM_WRITE( "_umtx_op_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4492 *flags |= SfMayBlock;
4493 break;
4494 case VKI_UMTX_OP_UNLOCK:
4495 // marked as COMPAT10
4496 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, UNLOCK, %" FMT_REGWORD "u)", ARG1, ARG3);
4497 PRE_REG_READ3(long, "_umtx_op_unlock",
4498 struct umtx *, obj, int, op, unsigned long, id);
4499 PRE_MEM_READ( "_umtx_op_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4500 PRE_MEM_WRITE( "_umtx_op_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4501 break;
4502 case VKI_UMTX_OP_WAIT:
4503 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4504 PRE_REG_READ5(long, "_umtx_op_wait",
4505 long *, obj, int, op, unsigned long, val,
4506 size_t, timeout_size, struct vki_timespec *, timeout);
4507 if (ARG1) {
4508 PRE_MEM_READ( "_umtx_op_wait(val)", ARG1, sizeof(long) );
4509 if (*(long*)ARG1 == (long)ARG3) {
4510 *flags |= SfMayBlock;
4514 if (ARG5) {
4515 PRE_MEM_READ( "_umtx_op_wait(timeout)", ARG5, ARG4 );
4518 break;
4519 case VKI_UMTX_OP_WAKE:
4520 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, WAKE, %" FMT_REGWORD "u)", ARG1, ARG3);
4521 PRE_REG_READ3(long, "_umtx_op_wake",
4522 vki_uintptr_t *, obj, int, op, int, val);
4523 // PJF I don't think that the value of obj gets read, the address is being used as a key
4524 //PRE_MEM_READ("_umtx_op_wake(obj)", ARG1, sizeof(vki_uintptr_t));
4525 break;
4526 case VKI_UMTX_OP_MUTEX_TRYLOCK:
4527 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_TRYLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4528 PRE_REG_READ2(long, "_umtx_op_mutex_trylock", struct umutex *, obj, int, op);
4529 PRE_MEM_READ( "_umtx_op_mutex_trylock(mutex)", ARG1, sizeof(struct vki_umutex) );
4530 PRE_MEM_WRITE( "_umtx_op_mutex_trylock(mutex)", ARG1, sizeof(struct vki_umutex) );
4531 /* not too sure about the restart here
4532 * it's hard to test as if the mutex is locked this returns EBUSY
4533 * so there is only a small window where the syscall could be interrupted */
4534 *flags |= SfMayBlock | SfKernelRestart;
4535 break;
4536 case VKI_UMTX_OP_MUTEX_LOCK:
4537 // called by pthread_mutex_lock
4538 // when the atribute UMUTEX_PRIO_PROTECT or UMUTEX_PRIO_INHERIT is set
4539 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_LOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4540 PRE_REG_READ5(long, "_umtx_op_mutex_lock",
4541 struct umutex *, obj, int, op, unsigned long, noid,
4542 size_t, timeout_size, struct vki_timespec *, timeout);
4543 PRE_MEM_READ( "_umtx_op_mutex_lock(mutex)", ARG1, sizeof(struct vki_umutex) );
4544 if (ARG5) {
4545 PRE_MEM_READ( "_umtx_op_mutex_lock(timespec)", ARG5, ARG4 );
4546 } else {
4547 *flags |= SfKernelRestart;
4549 PRE_MEM_WRITE( "_umtx_op_mutex_lock(mutex)", ARG1, sizeof(struct vki_umutex) );
4550 *flags |= SfMayBlock;
4551 break;
4552 case VKI_UMTX_OP_MUTEX_UNLOCK:
4553 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_UNLOCK)", ARG1);
4554 PRE_REG_READ2(long, "_umtx_op_mutex_unlock",
4555 struct umutex *, obj, int, op);
4556 PRE_MEM_READ( "_umtx_op_mutex_unlock(mutex)", ARG1, sizeof(struct vki_umutex) );
4557 PRE_MEM_WRITE( "_umtx_op_mutex_unlock(mutex)", ARG1, sizeof(struct vki_umutex) );
4558 break;
4559 case VKI_UMTX_OP_SET_CEILING:
4560 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SET_CEILING, %" FMT_REGWORD "u, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4);
4561 PRE_REG_READ4(long, "_umtx_op_set_ceiling",
4562 struct umutex *, obj, int, op, unsigned int, ceiling,
4563 unsigned int *, old_ceiling);
4564 PRE_MEM_READ( "_umtx_op_set_ceiling(mutex)", ARG1, sizeof(struct vki_umutex) );
4565 PRE_MEM_WRITE( "_umtx_op_set_ceiling(mutex)", ARG1, sizeof(struct vki_umutex) );
4566 if (ARG4) {
4567 PRE_MEM_WRITE( "_umtx_op_set_ceiling(old_ceiling)", ARG4, sizeof(vki_uint32_t) );
4569 break;
4570 case VKI_UMTX_OP_CV_WAIT:
4571 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4572 PRE_REG_READ5(long, "_umtx_op_cv_wait",
4573 struct ucond *, obj, int, op, unsigned long, wflags,
4574 struct umutex *, umtx, struct vki_timespec *, timeout);
4575 PRE_MEM_READ( "_umtx_op_cv_wait(cond)", ARG1, sizeof(struct vki_ucond) );
4576 PRE_MEM_WRITE( "_umtx_op_cv_wait(cond)", ARG1, sizeof(struct vki_ucond) );
4577 PRE_MEM_READ( "_umtx_op_cv_wait(mutex)", ARG4, sizeof(struct vki_umutex) );
4578 PRE_MEM_WRITE( "_umtx_op_cv_wait(mutex)", ARG4, sizeof(struct vki_umutex) );
4579 if (ARG5) {
4580 PRE_MEM_READ( "_umtx_op_cv_wait(timespec)", ARG5, sizeof(struct vki_timespec) );
4582 *flags |= SfMayBlock;
4583 break;
4584 case VKI_UMTX_OP_CV_SIGNAL:
4585 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_SIGNAL)", ARG1);
4586 PRE_REG_READ2(long, "_umtx_op_cv_signal",
4587 struct ucond *, obj, int, op);
4588 PRE_MEM_READ( "_umtx_op_cv_signal(cond)", ARG1, sizeof(struct vki_ucond) );
4589 PRE_MEM_WRITE( "_umtx_op_cv_signal(cond)", ARG1, sizeof(struct vki_ucond) );
4590 break;
4591 case VKI_UMTX_OP_CV_BROADCAST:
4592 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_BROADCAST, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4593 PRE_REG_READ2(long, "_umtx_op_cv_broadcast",
4594 struct ucond *, obj, int, op);
4595 PRE_MEM_READ( "_umtx_op_cv_broadcast(cond)", ARG1, sizeof(struct vki_ucond) );
4596 PRE_MEM_WRITE( "_umtx_op_cv_broadcast(cond)", ARG1, sizeof(struct vki_ucond) );
4597 break;
4598 case VKI_UMTX_OP_WAIT_UINT:
4599 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAIT_UINT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4600 PRE_REG_READ5(long, "_umtx_op_wait_uint",
4601 int *, obj, int, op, unsigned long, id,
4602 size_t, timeout_wait, struct vki_timespec *, timeout);
4603 PRE_MEM_READ( "_umtx_op_wait(uint)", ARG1, sizeof(int) );
4604 if (ARG5) {
4605 PRE_MEM_READ( "_umtx_op_wait(timespec)", ARG5, ARG4 );
4607 *flags |= SfMayBlock;
4608 break;
4609 case VKI_UMTX_OP_RW_RDLOCK:
4610 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, RW_RDLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4611 PRE_REG_READ5(long, "_umtx_op_rw_rdlock",
4612 struct urwlock *, obj, int, op, unsigned long, noid,
4613 void *, zero, struct vki_timespec *, timeout);
4614 PRE_MEM_READ( "_umtx_op_rw_rdlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4615 PRE_MEM_WRITE( "_umtx_op_rw_rdlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4616 *flags |= SfMayBlock;
4617 break;
4618 case VKI_UMTX_OP_RW_WRLOCK:
4619 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, RW_WRLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4620 PRE_REG_READ5(long, "_umtx_op_rw_wrlock",
4621 struct urwlock *, obj, int, op, unsigned long, noid,
4622 void *, zero, struct vki_timespec *, timeout);
4623 PRE_MEM_READ( "_umtx_op_rw_wrlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4624 PRE_MEM_WRITE( "_umtx_op_rw_wrlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4625 *flags |= SfMayBlock;
4626 break;
4627 case VKI_UMTX_OP_RW_UNLOCK:
4628 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, RW_UNLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4629 PRE_REG_READ2(long, "_umtx_op_rw_unlock",
4630 struct urwlock *, obj, int, op);
4631 PRE_MEM_READ( "_umtx_op_rw_unlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4632 PRE_MEM_WRITE( "_umtx_op_rw_unlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4633 break;
4634 case VKI_UMTX_OP_WAIT_UINT_PRIVATE:
4635 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAIT_UINT_PRIVATE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4636 PRE_REG_READ5(long, "_umtx_op_wait_uint_private",
4637 int *, obj, int, op, unsigned long, id,
4638 size_t, timeout_size, struct vki_timespec *, timeout);
4639 PRE_MEM_READ( "_umtx_op_wait_private(uint)", ARG1, sizeof(int) );
4640 if (ARG5) {
4641 PRE_MEM_READ( "_umtx_op_wait_private(umtx_time)", ARG5, ARG4 );
4643 *flags |= SfMayBlock;
4644 break;
4645 case VKI_UMTX_OP_WAKE_PRIVATE:
4646 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAKE_PRIVATE, %" FMT_REGWORD "u)", ARG1, ARG3);
4647 PRE_REG_READ3(long, "_umtx_op_wake_private",
4648 vki_uintptr_t *, obj, int, op, int, val);
4649 // PJF like OP_WAKE contents of obj not read
4650 //PRE_MEM_READ("_umtx_op_wake_private(obj)", ARG1, sizeof(vki_uintptr_t));
4651 break;
4652 case VKI_UMTX_OP_MUTEX_WAIT:
4653 // pthread_mutex_lock without prio flags
4654 // does not need to be restarted
4655 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4656 PRE_REG_READ2(long, "_umtx_op_mutex_wait",
4657 struct umutex *, obj, int, op);
4658 PRE_MEM_READ( "_umtx_op_mutex_wait(mutex)", ARG1, sizeof(struct vki_umutex) );
4659 PRE_MEM_WRITE( "_umtx_op_mutex_wait(mutex)", ARG1, sizeof(struct vki_umutex) );
4660 *flags |= SfMayBlock;
4661 break;
4662 case VKI_UMTX_OP_MUTEX_WAKE:
4663 // marked as deprecated
4664 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_WAKE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4665 PRE_REG_READ2(long, "_umtx_op_mutex_wake",
4666 struct umutex *, obj, int, op);
4667 PRE_MEM_READ( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4668 PRE_MEM_WRITE( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4669 break;
4670 case VKI_UMTX_OP_SEM_WAIT:
4671 // marked as deprecated
4672 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4673 PRE_REG_READ5(long, "_umtx_op_sem_wait",
4674 struct usem *, obj, int, op, unsigned long, id,
4675 size_t, timeout_size, struct vki_timespec *, timeout);
4676 PRE_MEM_READ( "_umtx_op_sem_wait(usem)", ARG1, sizeof(struct vki_usem) );
4677 PRE_MEM_WRITE( "_umtx_op_sem_wait(usem)", ARG1, sizeof(struct vki_usem) );
4678 if (ARG5) {
4679 PRE_MEM_READ( "_umtx_op_sem_wait(umtx_time)", ARG5, ARG4 );
4681 *flags |= SfMayBlock;
4682 break;
4683 case VKI_UMTX_OP_SEM_WAKE:
4684 // marked as deprecated
4685 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM_WAKE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4686 PRE_REG_READ2(long, "_umtx_op_sem_wake",
4687 struct umutex *, obj, int, op);
4688 PRE_MEM_READ( "_umtx_op_sem_wake(mutex)", ARG1, sizeof(struct vki_usem) );
4689 PRE_MEM_WRITE( "_umtx_op_sem_wake(mutex)", ARG1, sizeof(struct vki_usem) );
4690 break;
4691 case VKI_UMTX_OP_NWAKE_PRIVATE:
4692 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, NWAKE_PRIVATE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4693 PRE_REG_READ3(long, "_umtx_op_nwake_private",
4694 struct umutex *, obj, int, op, int, count);
4695 PRE_MEM_READ( "_umtx_op_nwake_private(mtxs)", ARG1, ARG3 * sizeof(void *) );
4696 PRE_MEM_WRITE( "_umtx_op_mutex_wake(mtxs)", ARG1, sizeof(struct vki_umutex) );
4697 break;
4698 case VKI_UMTX_OP_MUTEX_WAKE2:
4699 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_WAKE2, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4700 PRE_REG_READ3(long, "_umtx_op_mutex_wake2",
4701 struct umutex *, obj, int, op, unsigned long, flags);
4702 PRE_MEM_READ( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4703 PRE_MEM_WRITE( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4704 break;
4705 case VKI_UMTX_OP_SEM2_WAIT:
4706 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM2_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4707 PRE_REG_READ3(long, "_umtx_op_sem2_wake",
4708 struct _usem2 *, obj, int, op, unsigned long, flags);
4709 PRE_MEM_READ( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4710 PRE_MEM_WRITE( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4711 *flags |= SfMayBlock;
4712 break;
4713 case VKI_UMTX_OP_SEM2_WAKE:
4714 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM2_WAKE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4715 PRE_REG_READ3(long, "_umtx_op_sem2_wake",
4716 struct _usem2 *, obj, int, op, unsigned long, flags);
4717 PRE_MEM_READ( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4718 PRE_MEM_WRITE( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4719 break;
4720 case VKI_UMTX_OP_SHM:
4721 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SHM, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4722 PRE_REG_READ4(long, "_umtx_op_shm",
4723 void *, obj, int, op, unsigned long, val, void*, uaddr);
4724 break;
4725 case VKI_UMTX_OP_ROBUST_LISTS:
4726 // val (ARG2) ought to be the same as sizeof(struct vki_umtx_robust_lists_params)
4727 // then the structure contains a pointer to mutex structures
4728 if (ARG1 != sizeof(struct vki_umtx_robust_lists_params)) {
4729 SET_STATUS_Failure( VKI_ENOSYS );
4731 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, ROBUST_LISTS, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4732 PRE_REG_READ3(long, "_umtx_op_robust_lists",
4733 struct umtx_robust_lists_params *, obj, int, op, unsigned long, flags);
4734 PRE_MEM_READ( "_umtx_op_robust_lists(mutex)", ARG3, sizeof(struct vki_umtx_robust_lists_params) );
4735 break;
4736 #if (FREEBSD_VERS >= FREEBSD_14)
4737 case VKI_UMTX_OP_GET_MIN_TIMEOUT:
4738 PRINT( "sys__umtx_op ( GET_MIN_TIMEOUT, %#" FMT_REGWORD "x)", ARG4);
4739 // bit of a pain just reads args 2 and 4
4740 if (VG_(tdict).track_pre_reg_read) {
4741 PRRSN;
4742 PRA2("_umtx_op_get_min_timeout",int,op);
4743 PRA4("_umtx_op_get_min_timeout",long int*,timeout);
4745 PRE_MEM_WRITE( "_umtx_op_get_min_timout(uaddr)", ARG4, sizeof(long int) );
4746 break;
4747 case VKI_UMTX_OP_SET_MIN_TIMEOUT:
4748 PRINT( "sys__umtx_op ( SET_MIN_TIMEOUT, %" FMT_REGWORD "u)", ARG3);
4749 // bit of a pain just reads args 2 and 3
4750 if (VG_(tdict).track_pre_reg_read) {
4751 PRRSN;
4752 PRA2("_umtx_op_set_min_timeout",int,op);
4753 PRA3("_umtx_op_set_min_timeout",unsigned long,timeout);
4755 break;
4756 #endif
4757 default:
4758 VG_(umsg)("WARNING: _umtx_op unsupported value.\n");
4759 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u(UNKNOWN), %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1, ARG2, ARG3, ARG4, ARG5);
4760 break;
4764 POST(sys__umtx_op)
4766 switch(ARG2) {
4767 case VKI_UMTX_OP_LOCK:
4768 case VKI_UMTX_OP_UNLOCK:
4769 if (SUCCESS) {
4770 POST_MEM_WRITE( ARG1, sizeof(struct vki_umtx) );
4772 break;
4773 case VKI_UMTX_OP_WAIT:
4774 case VKI_UMTX_OP_WAKE:
4775 case VKI_UMTX_OP_WAIT_UINT:
4776 case VKI_UMTX_OP_WAIT_UINT_PRIVATE:
4777 case VKI_UMTX_OP_WAKE_PRIVATE:
4778 break;
4779 case VKI_UMTX_OP_MUTEX_TRYLOCK:
4780 case VKI_UMTX_OP_MUTEX_LOCK:
4781 case VKI_UMTX_OP_MUTEX_UNLOCK:
4782 case VKI_UMTX_OP_MUTEX_WAIT: /* Sets/clears contested bits */
4783 case VKI_UMTX_OP_MUTEX_WAKE: /* Sets/clears contested bits */
4784 if (SUCCESS) {
4785 POST_MEM_WRITE( ARG1, sizeof(vki_uintptr_t) );
4787 break;
4788 case VKI_UMTX_OP_SET_CEILING:
4789 if (SUCCESS) {
4790 POST_MEM_WRITE( ARG1, sizeof(struct vki_umutex) );
4791 if (ARG4) {
4792 POST_MEM_WRITE( ARG4, sizeof(vki_uint32_t) );
4795 break;
4796 case VKI_UMTX_OP_CV_WAIT:
4797 if (SUCCESS) {
4798 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucond) );
4799 POST_MEM_WRITE( ARG4, sizeof(struct vki_umutex) );
4801 break;
4802 case VKI_UMTX_OP_CV_SIGNAL:
4803 case VKI_UMTX_OP_CV_BROADCAST:
4804 if (SUCCESS) {
4805 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucond) );
4807 break;
4808 case VKI_UMTX_OP_RW_RDLOCK:
4809 case VKI_UMTX_OP_RW_WRLOCK:
4810 case VKI_UMTX_OP_RW_UNLOCK:
4811 if (SUCCESS) {
4812 POST_MEM_WRITE( ARG1, sizeof(struct vki_urwlock) );
4814 break;
4815 case VKI_UMTX_OP_SEM2_WAIT:
4816 case VKI_UMTX_OP_SEM2_WAKE:
4817 if (SUCCESS) {
4818 POST_MEM_WRITE( ARG1, sizeof(struct vki_usem2) );
4820 break;
4821 case VKI_UMTX_OP_SHM:
4822 case VKI_UMTX_OP_ROBUST_LISTS:
4823 break;
4824 #if (FREEBSD_VERS >= FREEBSD_14)
4825 case VKI_UMTX_OP_GET_MIN_TIMEOUT:
4826 POST_MEM_WRITE( ARG4, sizeof(long int) );
4827 break;
4828 case VKI_UMTX_OP_SET_MIN_TIMEOUT:
4829 break;
4830 #endif
4831 default:
4832 break;
4836 // SYS_thr_new 455
4837 // x86/amd64
4839 // SYS_sigqueue 456
4840 // int sigqueue(pid_t pid, int signo, const union sigval value);
4841 PRE(sys_sigqueue)
4843 PRINT("sys_sigqueue ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",
4844 SARG1,SARG2,ARG3);
4845 PRE_REG_READ3(int, "sigqueue", vki_pid_t, pid, int, signo, const union vki_sigval, value);
4848 // SYS_kmq_open 457
4849 // mqd_t mq_open(const char *name, int oflag, ...);
4850 // int kmq_open(_In_z_ const char *path, int flags, mode_t mode, _In_opt_ const struct mq_attr *attr);
4851 PRE(sys_kmq_open)
4853 if (ARG2 & VKI_O_CREAT) {
4854 PRINT("sys_kmq_open( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu, %#" FMT_REGWORD "x )",
4855 ARG1,(char *)ARG1,ARG2,(vki_mode_t)ARG3,ARG4);
4856 PRE_REG_READ4(long, "mq_open",
4857 const char *, name, int, oflag, vki_mode_t, mode,
4858 struct mq_attr *, attr);
4859 } else {
4860 PRINT("sys_kmq_open( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu)",
4861 ARG1,(char *)ARG1,ARG2,(vki_mode_t)ARG3);
4862 PRE_REG_READ3(long, "mq_open",
4863 const char *, name, int, oflag, vki_mode_t, mode);
4865 PRE_MEM_RASCIIZ( "mq_open(name)", ARG1 );
4866 if (ARG2 & VKI_O_CREAT) {
4867 PRE_MEM_READ("mq_open(attr)", ARG4, sizeof(struct vki_mq_attr));
4868 if (ML_(safe_to_deref)((struct vki_mq_attr *)ARG4, sizeof(struct vki_mq_attr))) {
4869 const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG4;
4870 PRE_MEM_READ("mq_open(attr->mq_maxmsg)",
4871 (Addr)&attr->mq_maxmsg, sizeof(attr->mq_maxmsg) );
4872 PRE_MEM_READ("mq_open(attr->mq_msgsize)",
4873 (Addr)&attr->mq_msgsize, sizeof(attr->mq_msgsize) );
4878 POST(sys_kmq_open)
4880 vg_assert(SUCCESS);
4881 if (!ML_(fd_allowed)(RES, "mq_open", tid, True)) {
4882 VG_(close)(RES);
4883 SET_STATUS_Failure( VKI_EMFILE );
4884 } else {
4885 if (VG_(clo_track_fds)) {
4886 ML_(record_fd_open_with_given_name)(tid, RES, (const HChar*)ARG1);
4891 // SYS_kmq_setattr 458
4892 // int mq_setattr(mqd_t mqdes, const struct mq_attr *restrict mqstat,
4893 // struct mq_attr *restrict omqstat);
4894 PRE(sys_kmq_setattr)
4896 PRINT("sys_kmq_getattr( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3 );
4897 PRE_REG_READ3(int, "mq_setattr",
4898 vki_mqd_t, mqdes, const struct mq_attr *, mqstat,
4899 struct mq_attr *, omqstat);
4900 if (!ML_(fd_allowed)(ARG1, "mq_getattr", tid, False)) {
4901 SET_STATUS_Failure( VKI_EBADF );
4902 } else {
4903 if (ML_(safe_to_deref)((struct vki_mq_attr *)ARG2, sizeof(struct vki_mq_attr))) {
4904 const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG2;
4905 PRE_MEM_READ( "mq_setattr(mqstat->mq_flags)",
4906 (Addr)&attr->mq_flags, sizeof(attr->mq_flags) );
4908 PRE_MEM_WRITE( "mq_setattr(omqstat)", ARG3,
4909 sizeof(struct vki_mq_attr) );
4913 // SYS_kmq_timedreceive 459
4914 // ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
4915 // unsigned *msg_prio, const struct timespec *abs_timeout);
4916 PRE(sys_kmq_timedreceive)
4918 *flags |= SfMayBlock;
4919 PRINT("sys_kmq_timedreceive( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %llu, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
4920 ARG1,ARG2,(ULong)ARG3,ARG4,ARG5);
4921 PRE_REG_READ5(ssize_t, "mq_timedreceive",
4922 vki_mqd_t, mqdes, char *, msg_ptr, vki_size_t, msg_len,
4923 unsigned int *, msg_prio,
4924 const struct timespec *, abs_timeout);
4925 if (!ML_(fd_allowed)(ARG1, "mq_timedreceive", tid, False)) {
4926 SET_STATUS_Failure( VKI_EBADF );
4927 } else {
4928 PRE_MEM_WRITE( "mq_timedreceive(msg_ptr)", ARG2, ARG3 );
4929 if (ARG4 != 0) {
4930 PRE_MEM_WRITE( "mq_timedreceive(msg_prio)",
4931 ARG4, sizeof(unsigned int) );
4933 if (ARG5 != 0) {
4934 PRE_MEM_READ( "mq_timedreceive(abs_timeout)",
4935 ARG5, sizeof(struct vki_timespec) );
4940 POST(sys_kmq_timedreceive)
4942 POST_MEM_WRITE( ARG2, ARG3 );
4943 if (ARG4 != 0) {
4944 POST_MEM_WRITE( ARG4, sizeof(unsigned int) );
4948 // SYS_kmq_timedsend 460
4949 // int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
4950 // unsigned msg_prio, const struct timespec *abs_timeout);
4951 PRE(sys_kmq_timedsend)
4953 *flags |= SfMayBlock;
4954 PRINT("sys_kmq_timedsend ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %llu, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",
4955 ARG1,ARG2,(ULong)ARG3,ARG4,ARG5);
4956 PRE_REG_READ5(int, "mq_timedsend",
4957 vki_mqd_t, mqdes, const char *, msg_ptr, vki_size_t, msg_len,
4958 unsigned int, msg_prio, const struct timespec *, abs_timeout);
4959 if (!ML_(fd_allowed)(ARG1, "mq_timedsend", tid, False)) {
4960 SET_STATUS_Failure( VKI_EBADF );
4961 } else {
4962 PRE_MEM_READ( "mq_timedsend(msg_ptr)", ARG2, ARG3 );
4963 if (ARG5 != 0) {
4964 PRE_MEM_READ( "mq_timedsend(abs_timeout)", ARG5,
4965 sizeof(struct vki_timespec) );
4970 // SYS_kmq_notify 461
4971 // int mq_notify(mqd_t mqdes, const struct sigevent *notification);
4972 PRE(sys_kmq_notify)
4974 PRINT("sys_kmq_notify( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2 );
4975 PRE_REG_READ2(int, "mq_notify",
4976 vki_mqd_t, mqdes, const struct sigevent *, notification);
4977 if (!ML_(fd_allowed)(ARG1, "mq_notify", tid, False)) {
4978 SET_STATUS_Failure( VKI_EBADF );
4980 else if (ARG2 != 0) {
4981 PRE_MEM_READ( "mq_notify(notification)",
4982 ARG2, sizeof(struct vki_sigevent) );
4986 // SYS_kmq_unlink 462
4987 // int kmq_unlink(const char *path);
4988 PRE(sys_kmq_unlink)
4990 PRINT("sys_kmq_unlink ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
4991 PRE_REG_READ1(int, "mq_unlink", const char *, name);
4992 PRE_MEM_RASCIIZ( "mq_unlink(name)", ARG1 );
4995 // SYS_abort2 463
4996 // void abort2(const char *why, int nargs, void **args);
4997 PRE(sys_abort2)
4999 PRINT( "sys_abort2 ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1, SARG2, ARG3 );
5000 PRE_REG_READ3(void, "abort2", const char *, why, int, nargs, void **, args);
5001 // max length of 'why' is 128
5002 PRE_MEM_RASCIIZ( "abort2(why)", ARG2);
5003 // max val for nargs is 16
5004 PRE_MEM_READ("abort2(args", ARG3, ARG2*sizeof(void*));
5007 // SYS_thr_set_name 464
5008 // int thr_set_name(long id, const char *name);
5009 PRE(sys_thr_set_name)
5011 PRINT( "sys_thr_set_name ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1, ARG2 );
5012 PRE_REG_READ2(int, "thr_set_name", long, id, const char *, name);
5013 PRE_MEM_RASCIIZ( "thr_set_name(name)", ARG2);
5015 if (ML_(safe_to_deref)((void*)ARG2, 1)) {
5016 const HChar* new_name = (const HChar*) (Addr)ARG2;
5017 ThreadState* tst = VG_(get_ThreadState)(tid);
5018 SizeT new_len = VG_(strnlen)(new_name, VKI_MAXCOMLEN+1);
5019 tst->thread_name = VG_(realloc)("syswrap.thr_set_name", tst->thread_name, new_len + 1);
5020 VG_(strlcpy)(tst->thread_name, new_name, new_len + 1);
5024 // SYS_aio_fsync 465
5025 // int aio_fsync(int op, struct aiocb *iocb);
5026 PRE(sys_aio_fsync)
5028 PRINT("aio_fsync ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,ARG2);
5029 PRE_REG_READ2(int, "aio_fsync", int, op, struct vki_aiocb *, iocb);
5030 PRE_MEM_READ( "aio_fsync(iocb)", ARG2, sizeof(struct vki_aiocb) );
5033 // SYS_rtprio_thread 466
5034 // int rtprio_thread(int function, lwpid_t lwpid, struct rtprio *rtp);
5035 PRE(sys_rtprio_thread)
5037 PRINT( "sys_rtprio_thread ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1, ARG2, ARG3 );
5038 PRE_REG_READ3(int, "rtprio_thread",
5039 int, function, __vki_lwpid_t, lwpid, struct vki_rtprio *, rtp);
5040 if (ARG1 == VKI_RTP_SET) {
5041 PRE_MEM_READ( "rtprio_thread(rtp#set)", ARG3, sizeof(struct vki_rtprio));
5042 } else if (ARG1 == VKI_RTP_LOOKUP) {
5043 PRE_MEM_WRITE( "rtprio_thread(rtp#lookup)", ARG3, sizeof(struct vki_rtprio));
5044 } else {
5045 /* PHK ?? */
5049 POST(sys_rtprio_thread)
5051 if (ARG1 == VKI_RTP_LOOKUP && RES == 0) {
5052 POST_MEM_WRITE( ARG3, sizeof(struct vki_rtprio));
5056 // SYS_sctp_peeloff 471
5057 // int sctp_peeloff(int s, sctp_assoc_t id);
5058 // @todo
5061 // SYS_sctp_generic_sendmsg 472
5062 // int sctp_generic_sendmsg(int s, void *msg, int msglen, struct sockaddr *to,
5063 // socklen_t len, struct sctp_sndrcvinfo *sinfo, int flags);
5065 // Not called directly from libc
5066 PRE(sys_sctp_generic_sendmsg)
5068 *flags |= SfMayBlock;
5069 PRINT("sys_sctp_generic_sendmsg ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )",SARG1,ARG2,SARG3,ARG4,SARG5,ARG6,SARG7);
5070 PRE_REG_READ7(ssize_t, "sctp_generic_sendmsg",
5071 int, s, void *, msg, int, msglen,
5072 struct sockaddr *, to, socklen_t, len,
5073 struct sctp_sndrcvinfo *, sinfo, int, flags);
5075 PRE_MEM_READ( "sctp_generic_sendmsg(msg)", ARG2, ARG3);
5077 ML_(pre_mem_read_sockaddr) (tid, "sctp_generic_sendmsg(to)", (struct vki_sockaddr *)ARG4, ARG5);
5079 if (ARG6 != (Addr)NULL) {
5080 PRE_MEM_READ( "sctp_generic_sendmsg(sinfo)", ARG6, sizeof(struct vki_sctp_sndrcvinfo));
5084 // SYS_sctp_generic_sendmsg_iov 473
5085 // int sctp_generic_sendmsg_iov(int s, struct iovec *iov, int iovlen,
5086 // struct sockaddr *to, struct sctp_sndrcvinfo *sinfo, int flags);
5087 // @todo
5089 // SYS_sctp_generic_recvmsg 474
5090 // int sctp_generic_recvmsg(int s, struct iovec *iov, int iovlen,
5091 // struct sockaddr *from, socklen_t *fromlen,
5092 // struct sctp_sndrcvinfo *sinfo, int *msgflags);
5094 // Not called directly from libc
5095 PRE(sys_sctp_generic_recvmsg)
5097 *flags |= SfMayBlock;
5098 PRINT("sys_sctp_generic_recvmsg ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",SARG1,ARG2,SARG3,ARG4,ARG5,ARG6,ARG7);
5099 PRE_REG_READ7(ssize_t, "sctp_generic_recvmsg",
5100 int, s, struct iovec *, iov, int, iovlen,
5101 struct sockaddr *, from, socklen_t *, fromlen,
5102 struct sctp_sndrcvinfo *, sinfo, int *, msgflags);
5104 // in the sctp_recvmsg libc wrapper this is always 1
5105 if ((Int)ARG3 > 0) {
5106 PRE_MEM_READ( "sctp_generic_recvmsg(iov)", ARG2, ARG3 * sizeof(struct vki_iovec) );
5108 if (ML_(safe_to_deref)((const void*)ARG2, ARG3 * sizeof(struct vki_iovec))) {
5109 struct vki_iovec* iovec = (struct vki_iovec*)ARG2;
5110 PRE_MEM_WRITE("sctp_generic_recvmsg(iov.iov_base)", (Addr)iovec->iov_base, iovec->iov_len);
5113 if (ARG4 != (Addr)NULL) {
5114 ML_(buf_and_len_pre_check) (tid, ARG4, ARG5,
5115 "sctp_generic_recvmsg(from)",
5116 "sctp_generic_recvmsg(fromlen_in)");
5119 if (ARG6 != (Addr)NULL) {
5120 PRE_MEM_WRITE("sctp_generic_recvmsg(sinfo)", ARG6, sizeof(struct vki_sctp_sndrcvinfo));
5123 if (ARG7 != (Addr)NULL) {
5124 PRE_MEM_WRITE("sctp_generic_recvmsg(msgflags)", ARG7, sizeof(int));
5128 POST(sys_sctp_generic_recvmsg)
5130 vg_assert(SUCCESS);
5131 struct vki_iovec* iovec = (struct vki_iovec*)ARG2;
5132 POST_MEM_WRITE((Addr)iovec->iov_base, iovec->iov_len);
5134 POST_MEM_WRITE( ARG2, ARG3*sizeof(struct vki_iovec) );
5136 if (ARG4 != (Addr)NULL) {
5137 ML_(buf_and_len_post_check) (tid, VG_(mk_SysRes_Success)(RES), ARG4, ARG5,
5138 "sctp_generic_recvmsg(fromlen_out)");
5141 if (ARG6 != (Addr)NULL) {
5142 POST_MEM_WRITE(ARG6, sizeof(struct vki_sctp_sndrcvinfo));
5145 if (ARG7 != (Addr)NULL) {
5146 POST_MEM_WRITE(ARG7, sizeof(int));
5150 // SYS_pread 475
5151 // x86/amd64
5153 // SYS_pwrite 476
5154 // x86/amd64
5156 // SYS_mmap 477
5157 // x86/amd64
5159 // SYS_lseek 478
5160 // x86/amd64
5162 //SYS_truncate 479
5163 // x86/amd64
5165 // SYS_ftruncate 480
5166 // x86/amd64
5168 // SYS_thr_kill2 481
5169 // int thr_kill2(pid_t pid, long id, int sig);
5170 PRE(sys_thr_kill2)
5172 PRINT("sys_thr_kill2 ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
5173 PRE_REG_READ3(int, "thr_kill2", pid_t, pid, long, tid, int, sig);
5174 if (!ML_(client_signal_OK)(ARG3)) {
5175 SET_STATUS_Failure( VKI_EINVAL );
5176 return;
5179 /* Check to see if this kill gave us a pending signal */
5180 *flags |= SfPollAfter;
5182 if (VG_(clo_trace_signals)) {
5183 VG_(message)(Vg_DebugMsg, "thr_kill2: sending signal %lu to pid %lu/%lu\n",
5184 ARG3, ARG1, ARG2);
5187 /* If we're sending SIGKILL, check to see if the target is one of
5188 our threads and handle it specially. */
5189 if (ARG3 == VKI_SIGKILL && ML_(do_sigkill)(ARG2, ARG1)) {
5190 SET_STATUS_Success(0);
5191 return;
5194 /* Ask to handle this syscall via the slow route, since that's the
5195 only one that sets tst->status to VgTs_WaitSys. If the result
5196 of doing the syscall is an immediate run of
5197 async_signalhandler() in m_signals, then we need the thread to
5198 be properly tidied away. I have the impression the previous
5199 version of this wrapper worked on x86/amd64 only because the
5200 kernel did not immediately deliver the async signal to this
5201 thread (on ppc it did, which broke the assertion re tst->status
5202 at the top of async_signalhandler()). */
5203 *flags |= SfMayBlock;
5206 POST(sys_thr_kill2)
5208 if (VG_(clo_trace_signals)) {
5209 VG_(message)(Vg_DebugMsg, "thr_kill2: sent signal %lu to pid %lu/%lu\n",
5210 ARG3, ARG1, ARG2);
5214 // SYS_shm_open 482
5215 // int shm_open(const char *path, int flags, mode_t mode);
5216 PRE(sys_shm_open)
5218 PRE_REG_READ3(int, "shm_open",
5219 const char *, path, int, flags, vki_mode_t, mode);
5220 if (ARG1 == VKI_SHM_ANON) {
5221 PRINT("sys_shm_open(%#" FMT_REGWORD "x(SHM_ANON), %" FMT_REGWORD "u, %hu)", ARG1, ARG2, (vki_mode_t)ARG3);
5222 } else {
5223 PRINT("sys_shm_open(%#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu)", ARG1, (HChar *)ARG1, ARG2, (vki_mode_t)ARG3);
5224 PRE_MEM_RASCIIZ( "shm_open(path)", ARG1 );
5226 *flags |= SfMayBlock;
5229 POST(sys_shm_open)
5231 vg_assert(SUCCESS);
5232 if (!ML_(fd_allowed)(RES, "shm_open", tid, True)) {
5233 VG_(close)(RES);
5234 SET_STATUS_Failure( VKI_EMFILE );
5235 } else {
5236 if (VG_(clo_track_fds)) {
5237 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1);
5242 // SYS_shm_unlink 483
5243 // int shm_unlink(const char *path);
5244 PRE(sys_shm_unlink)
5246 PRINT("sys_shm_unlink(%#" FMT_REGWORD "x(%s))", ARG1, (char *)ARG1);
5247 PRE_REG_READ1(int, "shm_unlink",
5248 const char *, path);
5250 PRE_MEM_RASCIIZ( "shm_unlink(path)", ARG1 );
5252 *flags |= SfMayBlock;
5255 // SYS_cpuset 484
5256 // int cpuset(cpusetid_t *setid);
5257 PRE(sys_cpuset)
5259 PRINT("sys_cpuset ( %#" FMT_REGWORD "x )", ARG1);
5260 PRE_REG_READ1(int, "cpuset", vki_cpusetid_t *, setid);
5261 PRE_MEM_WRITE("cpuset(setid)", ARG1, sizeof(vki_cpusetid_t));
5264 POST(sys_cpuset)
5266 POST_MEM_WRITE(ARG1, sizeof(vki_cpusetid_t));
5269 // SYS_cpuset_setid 485
5270 // amd64 / x86
5272 // SYS_cpuset_getid 486
5273 // amd64 / x86
5275 // SYS_cpuset_getaffinity 487
5276 // amd64 / x86
5278 // SYS_cpuset_setaffinity 488
5279 // amd64 / x86
5281 // SYS_faccessat 489
5282 // int faccessat(int fd, const char *path, int mode, int flag);
5283 PRE(sys_faccessat)
5285 PRINT("sys_faccessat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,ARG2,(char*)ARG2,ARG3);
5286 PRE_REG_READ3(int, "faccessat",
5287 int, fd, const char *, path, int, flag);
5288 PRE_MEM_RASCIIZ( "faccessat(path)", ARG2 );
5291 // SYS_fchmodat 490
5292 // int fchmodat(int fd, const char *path, mode_t mode, int flag);
5293 PRE(sys_fchmodat)
5295 PRINT("sys_fchmodat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,ARG2,(char*)ARG2,ARG3);
5296 PRE_REG_READ4(int, "fchmodat",
5297 int, fd, const char *, path, vki_mode_t, mode, int, flag);
5298 PRE_MEM_RASCIIZ( "fchmodat(path)", ARG2 );
5301 // SYS_fchownat 491
5302 // int fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag);
5303 PRE(sys_fchownat)
5305 PRINT("sys_fchownat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x, 0x%" FMT_REGWORD "x, %" FMT_REGWORD "d )",
5306 ARG1,ARG2,(char*)ARG2,ARG3,ARG4, SARG5);
5307 PRE_REG_READ5(int, "fchownat",
5308 int, fd, const char *, path,
5309 vki_uid_t, owner, vki_gid_t, group, int, flag);
5310 PRE_MEM_RASCIIZ( "fchownat(path)", ARG2 );
5313 // SYS_fexecve 492
5314 // int fexecve(int fd, char *const argv[], char *const envp[]);
5315 PRE(sys_fexecve)
5317 PRINT("sys_fexecve ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
5318 SARG1,ARG2,ARG3);
5319 PRE_REG_READ3(int, "fexecve",
5320 int, fd, char * const *, argv,
5321 char * const *, envp);
5323 if (!ML_(fd_allowed)(ARG1, "fexecve", tid, False)) {
5324 SET_STATUS_Failure(VKI_EBADF);
5325 return;
5328 const HChar *fname;
5330 if (VG_(resolve_filename)(ARG1, &fname) == False) {
5331 SET_STATUS_Failure(VKI_ENOENT);
5332 return;
5335 struct vg_stat stats;
5336 if (VG_(fstat)(ARG1, &stats) != 0) {
5337 SET_STATUS_Failure(VKI_EACCES);
5338 return;
5341 Int openFlags;
5343 if (VG_(resolve_filemode)(ARG1, &openFlags) == False) {
5344 SET_STATUS_Failure(VKI_ENOENT);
5345 return;
5349 * openFlags is in kernel FFLAGS format
5350 * (see /usr/include/sys/fcntl.h)
5351 * which alllows us to tell if RDONLY is set
5355 Bool isScript = False;
5357 SysRes res;
5358 res = VG_(open)(fname, VKI_O_RDONLY,
5359 VKI_S_IRUSR|VKI_S_IRGRP|VKI_S_IROTH);
5360 if (sr_isError(res)) {
5361 SET_STATUS_Failure(VKI_ENOENT);
5362 return;
5365 char buf[2];
5366 VG_(read)((Int)sr_Res(res), buf, 2);
5367 VG_(close)((Int)sr_Res(res));
5368 if (buf[0] == '#' && buf[1] == '!') {
5369 isScript = True;
5372 if (isScript) {
5373 if (!(openFlags & VKI_FREAD)) {
5374 SET_STATUS_Failure(VKI_EACCES);
5375 return;
5377 } else {
5378 if (!((openFlags & VKI_O_EXEC) ||
5379 (stats.mode & (VKI_S_IXUSR|VKI_S_IXGRP|VKI_S_IXOTH)))) {
5380 SET_STATUS_Failure(VKI_EACCES);
5381 return;
5385 Addr arg_2 = (Addr)ARG2;
5386 Addr arg_3 = (Addr)ARG3;
5388 handle_pre_sys_execve(tid, status, (Addr)fname, arg_2, arg_3, FEXECVE, False);
5391 // SYS_freebsd11_fstatat 493
5392 // int fstatat(int fd, const char *path, struct stat *sb, int flag);
5393 #if (FREEBSD_VERS >= FREEBSD_12)
5394 PRE(sys_freebsd11_fstatat)
5396 PRINT("sys_freebsd11_fstatat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3);
5397 PRE_REG_READ4(int, "fstatat",
5398 int, fd, const char *, path, struct freebsd11_stat *, buf, int, flag);
5399 PRE_MEM_RASCIIZ( "fstatat(path)", ARG2 );
5400 PRE_MEM_WRITE( "fstatat(sb)", ARG3, sizeof(struct vki_freebsd11_stat) );
5403 POST(sys_freebsd11_fstatat)
5405 POST_MEM_WRITE( ARG3, sizeof(struct vki_freebsd11_stat) );
5407 #else
5408 PRE(sys_fstatat)
5410 PRINT("sys_fstatat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3);
5411 PRE_REG_READ4(int, "fstatat",
5412 int, fd, const char *, path, struct stat *, buf, int, flag);
5413 PRE_MEM_RASCIIZ( "fstatat(path)", ARG2 );
5414 PRE_MEM_WRITE( "fstatat(sb)", ARG3, sizeof(struct vki_freebsd11_stat) );
5417 POST(sys_fstatat)
5419 POST_MEM_WRITE( ARG3, sizeof(struct vki_freebsd11_stat) );
5421 #endif
5423 // SYS_futimesat 494
5424 // int futimesat(int fd, const char *path, const struct timeval times[2]);
5425 PRE(sys_futimesat)
5427 PRINT("sys_futimesat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3);
5428 PRE_REG_READ3(int, "futimesat",
5429 int, fd, const char *, path, struct timeval *, times);
5430 if (ARG2 != 0) {
5431 PRE_MEM_RASCIIZ( "futimesat(path)", ARG2 );
5433 if (ARG3 != 0) {
5434 PRE_MEM_READ( "futimesat(times)", ARG3, 2 * sizeof(struct vki_timeval) );
5438 // SYS_linkat 495
5439 // int linkat(int fd1, const char *name1, int fd2, const char *name2, int flag);
5440 PRE(sys_linkat)
5442 *flags |= SfMayBlock;
5443 PRINT("sys_linkat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )",ARG1,ARG2,(char*)ARG2,ARG3,ARG4,(char*)ARG4,ARG5);
5444 PRE_REG_READ5(int, "linkat",
5445 int, fd1, const char *, name1,
5446 int, fd2, const char *, name2,
5447 int, flag);
5448 PRE_MEM_RASCIIZ( "linkat(name1)", ARG2);
5449 PRE_MEM_RASCIIZ( "linkat(name2)", ARG4);
5452 // SYS_mkdirat 496
5453 // int mkdirat(int fd, const char *path, mode_t mode);
5454 PRE(sys_mkdirat)
5456 *flags |= SfMayBlock;
5457 PRINT("sys_mkdirat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,ARG2,(char*)ARG2,ARG3);
5458 PRE_REG_READ3(int, "mkdirat",
5459 int, fd, const char *, path, int, mode);
5460 PRE_MEM_RASCIIZ( "mkdirat(path)", ARG2 );
5463 // SYS_mkfifoat 497
5464 // int mkfifoat(int fd, const char *path, mode_t mode);
5465 PRE(sys_mkfifoat)
5467 PRINT("sys_mkfifoat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x )",
5468 SARG1,ARG2,(HChar*)ARG2,ARG3 );
5469 PRE_REG_READ3(int, "mkfifoat",
5470 int, fd, const char *, path, vki_mode_t, mode);
5471 PRE_MEM_RASCIIZ( "mkfifoat(path)", ARG2 );
5474 // SYS_freebsd11_mknodat 498
5475 // int mknodat(int fd, const char *path, mode_t mode, dev_t dev);
5476 #if (FREEBSD_VERS >= FREEBSD_12)
5477 PRE(sys_freebsd11_mknodat)
5479 PRINT("sys_freebsd11_mknodat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x, 0x%" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4 );
5480 PRE_REG_READ4(long, "mknodat",
5481 int, dfd, const char *, pathname, int, mode, unsigned, dev);
5482 PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2 );
5484 #else
5485 PRE(sys_mknodat)
5487 PRINT("sys_mknodat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x, 0x%" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4 );
5488 PRE_REG_READ4(long, "mknodat",
5489 int, dfd, const char *, pathname, int, mode, unsigned, dev);
5490 PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2 );
5492 #endif
5494 // SYS_openat 499
5495 // int openat(int fd, const char *path, int flags, ...);
5496 PRE(sys_openat)
5499 if (ARG3 & VKI_O_CREAT) {
5500 // 4-arg version
5501 PRINT("sys_openat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,(char*)ARG2,ARG3,ARG4);
5502 PRE_REG_READ4(int, "openat",
5503 int, fd, const char *, path, int, flags, vki_mode_t, mode);
5504 } else {
5505 // 3-arg version
5506 PRINT("sys_openat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )",ARG1,ARG2,(char*)ARG2,ARG3);
5507 PRE_REG_READ3(int, "openat",
5508 int, fd, const char *, path, int, flags);
5511 if (ARG1 != (unsigned)VKI_AT_FDCWD && !ML_(fd_allowed)(ARG1, "openat", tid, False)) {
5512 SET_STATUS_Failure( VKI_EBADF );
5513 } else {
5514 PRE_MEM_RASCIIZ( "openat(path)", ARG2 );
5517 /* Otherwise handle normally */
5518 *flags |= SfMayBlock;
5521 POST(sys_openat)
5523 vg_assert(SUCCESS);
5524 if (!ML_(fd_allowed)(RES, "openat", tid, True)) {
5525 VG_(close)(RES);
5526 SET_STATUS_Failure( VKI_EMFILE );
5527 } else {
5528 if (VG_(clo_track_fds)) {
5529 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG2);
5534 // SYS_readlinkat 500
5535 // ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf,
5536 // size_t bufsize);
5537 PRE(sys_readlinkat)
5539 Word saved = SYSNO;
5540 Bool curproc_file = False;
5542 PRINT("sys_readlinkat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %llu )", ARG1,ARG2,(char*)ARG2,ARG3,(ULong)ARG4);
5543 PRE_REG_READ4(ssize_t, "readlinkat",
5544 int, fd, const char *, path, char *, buf, int, bufsize);
5545 PRE_MEM_RASCIIZ( "readlinkat(path)", ARG2 );
5546 PRE_MEM_WRITE( "readlinkat(buf)", ARG3,ARG4 );
5548 if (VG_(have_slash_proc) == True && (Int)ARG1 == VKI_AT_FDCWD) {
5550 * Handle the case where readlinkat is looking at /proc/curproc/file or
5551 * /proc/<pid>/file.
5553 do_readlink((const HChar *)ARG2, (HChar *)ARG3, (SizeT)ARG4, status, &curproc_file);
5556 // @todo PJF there is still the case where fd refers to /proc or /proc/pid
5557 // or /proc/curproc and path is relative pid/file, curptoc/file or just file
5559 if (!curproc_file) {
5560 /* Normal case */
5561 SET_STATUS_from_SysRes( VG_(do_syscall4)(saved, ARG1, ARG2, ARG3, ARG4));
5563 if (SUCCESS && RES > 0) {
5564 POST_MEM_WRITE( ARG3, RES );
5568 POST(sys_readlinkat)
5570 POST_MEM_WRITE( ARG3, RES );
5573 // SYS_renameat 501
5574 // int renameat(int fromfd, const char *from, int tofd, const char *to);
5575 PRE(sys_renameat)
5577 PRINT("sys_renameat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s) )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4,(char*)ARG4);
5578 PRE_REG_READ4(int, "renameat",
5579 int, fromfd, const char *, from,
5580 int, tofd, const char *, to);
5581 PRE_MEM_RASCIIZ( "renameat(oldpath)", ARG2 );
5582 PRE_MEM_RASCIIZ( "renameat(newpath)", ARG4 );
5585 // SYS_symlinkat 502
5586 // int symlinkat(const char *name1, int fd, const char *name2);
5587 PRE(sys_symlinkat)
5589 *flags |= SfMayBlock;
5590 PRINT("sys_symlinkat ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s) )",ARG1,(char*)ARG1,ARG2,ARG3,(char*)ARG3);
5591 PRE_REG_READ3(int, "symlinkat",
5592 const char *, name1, int, fd, const char *, name2);
5593 PRE_MEM_RASCIIZ( "symlinkat(name1)", ARG1 );
5594 PRE_MEM_RASCIIZ( "symlinkat(name2)", ARG3 );
5597 // SYS_unlinkat 503
5598 // int unlinkat(int fd, const char *path, int flag);
5599 PRE(sys_unlinkat)
5601 *flags |= SfMayBlock;
5602 PRINT("sys_unlinkat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u ",
5603 ARG1, ARG2, (char*)ARG2, ARG3);
5604 PRE_REG_READ3(int, "unlinkat", int, fd, const char *, path, int, flag);
5605 PRE_MEM_RASCIIZ( "unlinkat(path)", ARG2 );
5608 // SYS_posix_openpt 504
5609 // int posix_openpt(int oflag);
5610 PRE(sys_posix_openpt)
5612 PRINT("sys_posix_openpt ( %" FMT_REGWORD "d )", SARG1);
5613 PRE_REG_READ1(int, "posix_openpt", int, oflag);
5616 // SYS_gssd_syscall 505
5617 // @todo
5618 // see https://www.freebsd.org/cgi/man.cgi?format=html&query=gssapi(3)
5619 // syscalls.master says ; 505 is initialised by the kgssapi code, if present.
5621 // SYS_jail_get 506
5622 // int jail_get(struct iovec *iov, u_int niov, int flags);
5623 PRE(sys_jail_get)
5625 PRINT("sys_jail_get ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
5626 PRE_REG_READ3(int, "jail_get", struct vki_iovec *, iov, unsigned int,
5627 niov, int, flags);
5628 PRE_MEM_READ("jail_get(iov)", ARG1, ARG2 * sizeof(struct vki_iovec));
5631 // SYS_jail_set 507
5632 // int jail_set(struct iovec *iov, u_int niov, int flags);
5633 PRE(sys_jail_set)
5635 PRINT("sys_jail_set ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
5636 PRE_REG_READ3(int, "jail_set", struct vki_iovec *, iov, unsigned int,
5637 niov, int, flags);
5638 PRE_MEM_READ("jail_set(iovs)", ARG1, ARG2 * sizeof(struct vki_iovec));
5641 // SYS_jail_remove 508
5642 // int jail_remove(int jid);
5643 PRE(sys_jail_remove)
5645 PRINT("sys_jail_remove ( %" FMT_REGWORD "d )", SARG1);
5646 PRE_REG_READ1(int, "jail_remove", int, jid);
5649 // SYS_closefrom 509
5650 // void closefrom(int lowfd);
5651 PRE(sys_closefrom)
5653 PRINT("sys_closefrom ( %" FMT_REGWORD "dx )", SARG1);
5654 PRE_REG_READ1(int, "closefrom", int, lowfd);
5657 * Can't pass this on to the kernel otherwise it will close
5658 * all of the host files like the log
5661 for (int i = ARG1; i < VG_(fd_soft_limit); ++i) {
5662 VG_(close)(i);
5665 SET_STATUS_Success(0);
5668 // SYS___semctl 510
5669 // int semctl(int semid, int semnum, int cmd, ...);
5670 // int __semctl(int semid, int semnum, int cmd, _Inout_ union semun *arg);
5671 PRE(sys___semctl)
5673 switch (ARG3) {
5674 case VKI_IPC_INFO:
5675 case VKI_SEM_INFO:
5676 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
5677 PRE_REG_READ4(int, "semctl",
5678 int, semid, int, semnum, int, cmd, struct seminfo *, arg);
5679 break;
5680 case VKI_IPC_STAT:
5681 case VKI_SEM_STAT:
5682 case VKI_IPC_SET:
5683 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
5684 PRE_REG_READ4(long, "semctl",
5685 int, semid, int, semnum, int, cmd, struct semid_ds *, arg);
5686 break;
5687 case VKI_GETALL:
5688 case VKI_SETALL:
5689 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
5690 PRE_REG_READ4(long, "semctl",
5691 int, semid, int, semnum, int, cmd, unsigned short *, arg);
5692 break;
5693 default:
5694 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
5695 PRE_REG_READ3(long, "semctl",
5696 int, semid, int, semnum, int, cmd);
5697 break;
5699 ML_(generic_PRE_sys_semctl)(tid, ARG1,ARG2,ARG3,ARG4);
5702 POST(sys___semctl)
5704 ML_(generic_POST_sys_semctl)(tid, RES,ARG1,ARG2,ARG3,ARG4);
5707 // SYS_msgctl 511
5708 // int msgctl(int msqid, int cmd, struct msqid_ds *buf);
5709 PRE(sys_msgctl)
5711 PRINT("sys_msgctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3 );
5713 PRE_REG_READ3(int, "msgctl", int, msqid, int, cmd, struct msqid_ds *, buf);
5715 switch (ARG2 /* cmd */) {
5716 case VKI_IPC_STAT:
5717 PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)",
5718 ARG3, sizeof(struct vki_msqid_ds) );
5719 break;
5720 case VKI_IPC_SET:
5721 PRE_MEM_READ( "msgctl(IPC_SET, buf)",
5722 ARG3, sizeof(struct vki_msqid_ds) );
5723 break;
5727 POST(sys_msgctl)
5729 switch (ARG2 /* cmd */) {
5730 case VKI_IPC_STAT:
5731 POST_MEM_WRITE( ARG3, sizeof(struct vki_msqid_ds) );
5732 break;
5737 // SYS_shmctl 512
5738 // int shmctl(int shmid, int cmd, struct shmid_ds *buf);
5739 PRE(sys_shmctl)
5741 PRINT("sys_shmctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,SARG2,ARG3);
5742 PRE_REG_READ3(int, "shmctl",
5743 int, shmid, int, cmd, struct vki_shmid_ds *, buf);
5744 switch (ARG2 /* cmd */) {
5745 case VKI_IPC_STAT:
5746 PRE_MEM_WRITE( "shmctl(IPC_STAT, buf)",
5747 ARG3, sizeof(struct vki_shmid_ds) );
5748 break;
5749 case VKI_IPC_SET:
5750 PRE_MEM_READ( "shmctl(IPC_SET, buf)",
5751 ARG3, sizeof(struct vki_shmid_ds) );
5752 break;
5756 POST(sys_shmctl)
5758 if (ARG2 == VKI_IPC_STAT) {
5759 POST_MEM_WRITE( ARG3, sizeof(struct vki_shmid_ds) );
5763 // SYS_lpathconf 513
5764 // long lpathconf(const char *path, int name);
5765 PRE(sys_lpathconf)
5767 PRINT("sys_lpathconf ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d)", ARG1, SARG2);
5768 PRE_REG_READ2(long, "lpathconf", const char *, path, int, name);
5769 PRE_MEM_RASCIIZ("lpathconf(path)", ARG1);
5772 // SYS___cap_rights_get 515
5773 // note extra 1st argument for the internal function which is not present
5774 // in the public interface
5775 // int __cap_rights_get(int version, int fd, cap_rights_t *rights);
5776 PRE(sys_cap_rights_get)
5778 PRINT("sys_cap_rights_get ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, SARG2, ARG3);
5779 PRE_REG_READ3(long, "cap_rights_get", int, version, int, fd, vki_cap_rights_t*, rights);
5780 PRE_MEM_WRITE("cap_rights_get(rights)", ARG3, sizeof(vki_cap_rights_t));
5783 POST(sys_cap_rights_get)
5785 POST_MEM_WRITE(ARG2, sizeof(vki_cap_rights_t));
5788 // SYS_cap_enter 516
5789 // int cap_enter(void);
5790 PRE(sys_cap_enter)
5792 PRINT("%s", "sys_cap_enter ( )");
5793 PRE_REG_READ0(int, "cap_enter");
5794 static Bool warning_given = False;
5795 if (!warning_given) {
5796 warning_given = True;
5797 capabiltyMode = True;
5798 VG_(umsg)(
5799 "WARNING: Valgrind may not operate correctly in capability mode.\n"
5800 " Please consider disabling capability by using the RUNNING_ON_VALGRIND mechanism.\n"
5801 " See http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq\n");
5803 /* now complete loading debuginfo since it is not allowed after entering cap mode */
5804 VG_(load_all_debuginfo)();
5807 // SYS_cap_getmode 517
5808 // int cap_getmode(u_int *modep);
5809 PRE(sys_cap_getmode)
5811 PRINT("sys_cap_getmode ( %#" FMT_REGWORD "x )", ARG1);
5812 PRE_REG_READ1(int, "cap_getmode", u_int*, modep);
5813 PRE_MEM_WRITE("cap_getmode(modep)", ARG1, sizeof(u_int));
5816 POST(sys_cap_getmode)
5818 POST_MEM_WRITE(ARG1, sizeof(u_int));
5821 static vki_sigset_t pdfork_saved_mask;
5823 // SYS_pdfork 518
5824 // pid_t pdfork(int *fdp, int flags);
5825 PRE(sys_pdfork)
5827 Bool is_child;
5828 Int child_pid;
5829 vki_sigset_t mask;
5831 PRINT("sys_pdfork ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1, ARG2);
5832 PRE_REG_READ2(pid_t, "pdfork", int*, fdp, int, flags);
5834 /* Block all signals during fork, so that we can fix things up in
5835 the child without being interrupted. */
5836 VG_(sigfillset)(&mask);
5837 VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &pdfork_saved_mask);
5839 VG_(do_atfork_pre)(tid);
5841 SET_STATUS_from_SysRes( VG_(do_syscall2)(__NR_pdfork, ARG1, ARG2) );
5843 if (!SUCCESS) {
5844 return;
5847 // RES is 0 for child, non-0 (the child's PID) for parent.
5848 is_child = ( RES == 0 ? True : False );
5849 child_pid = ( is_child ? -1 : (Int)RES );
5851 if (is_child) {
5852 VG_(do_atfork_child)(tid);
5854 /* restore signal mask */
5855 VG_(sigprocmask)(VKI_SIG_SETMASK, &pdfork_saved_mask, NULL);
5856 } else {
5857 VG_(do_atfork_parent)(tid);
5859 PRINT(" fork: process %d created child %d\n", VG_(getpid)(), child_pid);
5861 /* restore signal mask */
5862 VG_(sigprocmask)(VKI_SIG_SETMASK, &pdfork_saved_mask, NULL);
5865 if (ARG1) {
5866 PRE_MEM_WRITE( "pdfork(fdp)", ARG1, sizeof(int) );
5870 POST(sys_pdfork)
5872 if (ARG1) {
5873 POST_MEM_WRITE( ARG1, sizeof(int) );
5877 // pdkill 519
5878 //int pdkill(int fd, int signum)
5879 PRE(sys_pdkill)
5881 PRINT("sys_pdkill ( %" FMT_REGWORD "u, %" FMT_REGWORD "d )", ARG1, SARG2);
5882 PRE_REG_READ2(int, "pdkill", int, fd, int, signum);
5884 if (!ML_(client_signal_OK)(ARG2)) {
5885 SET_STATUS_Failure( VKI_EINVAL );
5886 return;
5889 /* Ther was some code here to check if the kill is to this process
5891 * But it was totally wrong
5893 * It was calling ML_(do_sigkill)(Int pid, Int tgid)
5895 * With a file descriptor
5897 * Fortunately this will never match a real process otherwise
5898 * it might have accidentally killed us.
5900 * For a start we need the pid, obtained with pdgetpid
5901 * Next ML_(do_sigkill) doesn't map to FreeBSD. It takes a
5902 * pid (lwpid) and a tgid (threadgroup)
5904 * On FreeBSD lwpid is the tid and threadgroup is the pid
5905 * The kill functions operate on pids, not tids.
5907 * One last thing, I don't see how pdkill could do a self
5908 * kill 9. It neads an fd which implied pdfork whichimplies
5909 * that the fd/pid are for a child process
5912 SET_STATUS_from_SysRes(VG_(do_syscall2)(SYSNO, ARG1, ARG2));
5914 if (VG_(clo_trace_signals)) {
5915 VG_(message)(Vg_DebugMsg, "pdkill: sent signal %ld to fd %ld\n",
5916 SARG2, SARG1);
5919 /* This kill might have given us a pending signal. Ask for a check once
5920 the syscall is done. */
5921 *flags |= SfPollAfter;
5925 // SYS_pdgetpid 520
5926 // int pdgetpid(int fd, pid_t *pidp);
5927 PRE(sys_pdgetpid)
5929 PRINT("pdgetpid ( %" FMT_REGWORD "d, %#lx )", SARG1, ARG2);
5930 PRE_REG_READ2(int, "pdgetpid",
5931 int, fd, pid_t*, pidp);
5932 PRE_MEM_WRITE( "pdgetpid(pidp))", ARG2, sizeof(vki_pid_t) );
5935 POST(sys_pdgetpid)
5937 POST_MEM_WRITE( ARG2, sizeof(vki_pid_t) );
5940 // SYS_pselect 522
5942 // int pselect(int nfds, fd_set * restrict readfds, fd_set * restrict writefds,
5943 // fd_set * restrict exceptfds,
5944 // const struct timespec * restrict timeout,
5945 // const sigset_t * restrict newsigmask);
5946 PRE(sys_pselect)
5948 *flags |= SfMayBlock | SfPostOnFail;
5949 PRINT("sys_pselect ( %ld, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#"
5950 FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
5951 SARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5952 PRE_REG_READ6(int, "pselect",
5953 int, nfds, vki_fd_set *, readfds, vki_fd_set *, writefds,
5954 vki_fd_set *, exceptfds, struct vki_timespec *, timeout,
5955 const sigset_t *, newsigmask);
5956 // XXX: this possibly understates how much memory is read.
5957 if (ARG2 != 0) {
5958 PRE_MEM_READ( "pselect(readfds)",
5959 ARG2, ARG1/8 /* __FD_SETSIZE/8 */ );
5961 if (ARG3 != 0) {
5962 PRE_MEM_READ( "pselect(writefds)",
5963 ARG3, ARG1/8 /* __FD_SETSIZE/8 */ );
5965 if (ARG4 != 0) {
5966 PRE_MEM_READ( "pselect(exceptfds)",
5967 ARG4, ARG1/8 /* __FD_SETSIZE/8 */ );
5969 if (ARG5 != 0) {
5970 PRE_MEM_READ( "pselect(timeout)", ARG5, sizeof(struct vki_timeval) );
5973 if (ARG6 != 0) {
5974 PRE_MEM_READ( "pselect(sig)", ARG6, sizeof(vki_sigset_t) );
5975 ARG6 = ML_(make_safe_mask)("syswrap.pselect.1", (Addr)ARG6);
5979 POST(sys_pselect)
5981 ML_(free_safe_mask) ( (Addr)ARG6 );
5984 // SYS_getloginclass 523
5985 // int getloginclass(char *name, size_t len);
5986 PRE(sys_getloginclass)
5988 PRINT("sys_getloginclass ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
5989 PRE_REG_READ2(int, "getloginclass", char *, name, size_t, len);
5990 // The buffer should be at least MAXLOGNAME bytes in length.
5991 PRE_MEM_WRITE("getloginclass(name)", ARG1, ARG2);
5994 POST(sys_getloginclass)
5996 POST_MEM_WRITE(ARG1, ARG2);
5999 // SYS_setloginclass 524
6000 // int setloginclass(const char *name);
6001 PRE(sys_setloginclass)
6003 PRINT("sys_setloginclass ( %#" FMT_REGWORD "x(%s) )", ARG1, (HChar*)ARG1);
6004 PRE_REG_READ1(int, "setloginclass", const char *, name);
6005 PRE_MEM_RASCIIZ("rctl_setloginclass(name)", ARG1);
6008 // SYS_rctl_get_racct 525
6009 // int rctl_get_racct(const char *inbufp, size_t inbuflen, char *outbufp,
6010 // size_t outbuflen);
6011 PRE(sys_rctl_get_racct)
6013 PRINT("sys_rctl_get_racct ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
6014 PRE_REG_READ4(int, "rctl_get_racct", const char *, inbufp, size_t, inbuflen, char *, outbufp,
6015 size_t, outbuflen);
6016 PRE_MEM_READ("rctl_get_racct(inbufp)", ARG1, ARG2);
6017 PRE_MEM_WRITE("rctl_get_racct(outbufp)", ARG3, ARG4);
6020 POST(sys_rctl_get_racct)
6022 POST_MEM_WRITE(ARG3, ARG4);
6025 // SYS_rctl_get_rules 526
6026 // int rctl_get_rules(const char *inbufp, size_t inbuflen, char *outbufp,
6027 // size_t outbuflen);
6028 PRE(sys_rctl_get_rules)
6030 PRINT("sys_rctl_get_rules ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
6031 PRE_REG_READ4(int, "rctl_get_rules", const char *, inbufp, size_t, inbuflen, char *, outbufp,
6032 size_t, outbuflen);
6033 PRE_MEM_READ("rctl_get_rules(inbufp)", ARG1, ARG2);
6034 PRE_MEM_WRITE("rctl_get_rules(outbufp)", ARG3, ARG4);
6037 POST(sys_rctl_get_rules)
6039 POST_MEM_WRITE(ARG3, ARG4);
6042 // SYS_rctl_get_limits 527
6043 // int rctl_get_limits(const char *inbufp, size_t inbuflen, char *outbufp,
6044 // size_t outbuflen);
6045 PRE(sys_rctl_get_limits)
6047 PRINT("sys_rctl_get_limits ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
6048 PRE_REG_READ4(int, "rctl_get_limits", const char *, inbufp, size_t, inbuflen, char *, outbufp,
6049 size_t, outbuflen);
6050 PRE_MEM_READ("rctl_get_limits(inbufp)", ARG1, ARG2);
6051 PRE_MEM_WRITE("rctl_get_limits(outbufp)", ARG3, ARG4);
6054 POST(sys_rctl_get_limits)
6056 POST_MEM_WRITE(ARG3, ARG4);
6059 // SYS_rctl_add_rule 528
6060 // int rctl_add_rule(const char *inbufp, size_t inbuflen, char *outbufp,
6061 // size_t outbuflen);
6062 PRE(sys_rctl_add_rule)
6064 PRINT("sys_rctl_add_rule ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
6065 PRE_REG_READ2(int, "rctl_add_rule", const char *, inbufp, size_t, inbuflen);
6066 PRE_MEM_READ("rctl_add_rule(inbufp)", ARG1, ARG2);
6067 // man page says
6068 // The outbufp and outbuflen arguments are unused
6069 //PRE_MEM_WRITE("rctl_add_rule(outbufp)", ARG3, ARG4);
6072 POST(sys_rctl_add_rule)
6074 //POST_MEM_WRITE(ARG3, ARG4);
6077 // SYS_rctl_remove_rule 529
6078 // int rctl_remove_rule(const char *inbufp, size_t inbuflen, char *outbufp,
6079 // size_t outbuflen);
6080 PRE(sys_rctl_remove_rule)
6082 PRINT("sys_rctl_remove_rule ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
6083 PRE_REG_READ2(int, "rctl_remove_rule", const char *, inbufp, size_t, inbuflen);
6084 PRE_MEM_READ("rctl_remove_rule(inbufp)", ARG1, ARG2);
6085 // man page says
6086 // The outbufp and outbuflen arguments are unused
6087 //PRE_MEM_WRITE("rctl_remove_rule(outbufp)", ARG3, ARG4);
6090 POST(sys_rctl_remove_rule)
6092 //POST_MEM_WRITE(ARG3, ARG4);
6095 // SYS_posix_fallocate 530
6096 // x86/amd64
6098 // SYS_posix_fadvise 531
6099 // x86/amd64
6101 // SYS_wait6 532
6102 // amd64 / x86
6104 // SYS_cap_rights_limit 533
6105 //int cap_rights_limit(int fd, const cap_rights_t *rights);
6106 PRE(sys_cap_rights_limit)
6108 PRINT("sys_cap_rights_limit ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6109 PRE_REG_READ2(int, "cap_rights_limit",
6110 int, fd, const cap_rights_t *, rights);
6111 PRE_MEM_READ( "cap_rights_limit(rights)", ARG2, sizeof(struct vki_cap_rights) );
6114 // SYS_cap_ioctls_limit 534
6115 // int cap_ioctls_limit(int fd, const unsigned long *cmds, size_t ncmds);
6116 PRE(sys_cap_ioctls_limit)
6118 PRINT("cap_ioctls_limit ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
6119 PRE_REG_READ3(int, "cap_ioctls_limit",
6120 int, fd, unsigned long*, rights, vki_size_t, ncmds);
6121 // "can be up to 256" taking that to not be inclusive
6122 if (ARG3 < 256 ) {
6123 PRE_MEM_READ( "cap_ioctls_limit(cmds))", ARG2, ARG3*sizeof(unsigned long) );
6125 // else fail?
6128 // SYS_cap_ioctls_get 535
6129 // int cap_ioctls_get(int fd, unsigned long *cmds, size_t maxcmds);
6130 PRE(sys_cap_ioctls_get)
6132 PRINT("sys_cap_ioctls_get ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", SARG1, ARG2, ARG3);
6133 PRE_REG_READ3(int, "cap_ioctls_get", int, fd, unsigned long *, cmds, size_t, maxcmds);
6134 if (ARG3 < 256) {
6135 PRE_MEM_WRITE("cap_ioctls_get(cmds)", ARG2, ARG3*sizeof(unsigned long));
6139 POST(sys_cap_ioctls_get)
6141 if (ARG3 < 256) {
6142 POST_MEM_WRITE(ARG2, ARG3*sizeof(unsigned long));
6147 // SYS_cap_fcntls_limit 536
6148 //int cap_fcntls_limit(int fd, uint32_t fcntlrights);
6149 PRE(sys_cap_fcntls_limit)
6151 PRINT("cap_fcntls_limit ( %" FMT_REGWORD "d, %" FMT_REGWORD "u )", SARG1, ARG2);
6152 PRE_REG_READ2(long, "cap_fcntls_limit",
6153 int, fd, vki_uint32_t, fcntlrights);
6156 // SYS_cap_fcntls_get 537
6157 // int cap_fcntls_get(int fd, uint32_t *fcntlrightsp);
6158 PRE(sys_cap_fcntls_get)
6160 PRINT("sys_cap_fcntls_get ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6161 PRE_REG_READ2(int, "cap_fcntls_get", int, fd, uint32_t *, fcntlrightsp);
6162 PRE_MEM_WRITE("cap_fcntls_get(fcntlrightsp)", ARG2, sizeof(uint32_t));
6165 POST(sys_cap_fcntls_get)
6167 POST_MEM_WRITE(ARG2, sizeof(uint32_t));
6170 // SYS_bindat 538
6171 // int bindat(int fd, int s, const struct sockaddr *addr, socklen_t addrlen);
6172 PRE(sys_bindat)
6174 PRINT("sys_bindat ( %" FMT_REGWORD "d, %" FMT_REGWORD "dx, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",
6175 SARG1, SARG2, ARG3, ARG4);
6176 PRE_REG_READ4(int, "bindat", int, fd, int, s, const struct vki_sockaddr *, name, vki_socklen_t, namelen);
6177 PRE_MEM_READ("bindat(name)", ARG3, ARG4);
6180 // SYS_connectat 539
6181 // int connectat(int fd, int s, const struct sockaddr *name, socklen_t namelen);
6182 PRE(sys_connectat)
6184 PRINT("sys_connectat ( %" FMT_REGWORD "d, %" FMT_REGWORD "dx, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",
6185 SARG1, SARG2, ARG3, ARG4);
6186 PRE_REG_READ4(int, "connectat", int, fd, int, s, const struct vki_sockaddr *, name, vki_socklen_t, namelen);
6187 PRE_MEM_READ("connectat(name)", ARG3, ARG4);
6190 // SYS_chflagsat 540
6191 // int chflagsat(int fd, const char *path, unsigned long flags, int atflag);
6192 PRE(sys_chflagsat)
6194 PRINT("sys_chglagsat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d )",
6195 SARG1, ARG2, ARG3, SARG4);
6196 PRE_REG_READ4(int, "chflagsat", int, fd, const char *, path, unsigned long, flags, int, atflag);
6197 PRE_MEM_RASCIIZ("chflagsat(path)", ARG2);
6200 // SYS_accept4 541
6201 // int accept4(int s, struct sockaddr * restrict addr,
6202 // socklen_t * restrict addrlen, int flags);
6203 PRE(sys_accept4)
6205 *flags |= SfMayBlock;
6206 PRINT("sys_accept4 ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u)",ARG1,ARG2,ARG3,ARG4);
6207 PRE_REG_READ4(int, "accept4",
6208 int, s, struct sockaddr *, addr, int, *addrlen, int, flags);
6209 ML_(generic_PRE_sys_accept)(tid, ARG1,ARG2,ARG3);
6212 POST(sys_accept4)
6214 SysRes r;
6215 vg_assert(SUCCESS);
6216 r = ML_(generic_POST_sys_accept)(tid, VG_(mk_SysRes_Success)(RES),
6217 ARG1,ARG2,ARG3);
6218 SET_STATUS_from_SysRes(r);
6221 // SYS_pipe2 542
6222 // int pipe2(int fildes[2], int flags);
6223 PRE(sys_pipe2)
6225 PRINT("sys_pipe2 ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
6226 PRE_REG_READ2(int, "pipe2",
6227 int *, fildes, int, flags);
6228 PRE_MEM_WRITE("pipe2(fildes)", ARG1, 2 * sizeof(int));
6232 POST(sys_pipe2)
6234 int *fildes;
6236 if (RES != 0) {
6237 return;
6240 POST_MEM_WRITE(ARG1, 2 * sizeof(int));
6241 fildes = (int *)ARG1;
6243 if (!ML_(fd_allowed)(fildes[0], "pipe2", tid, True) ||
6244 !ML_(fd_allowed)(fildes[1], "pipe2", tid, True)) {
6245 VG_(close)(fildes[0]);
6246 VG_(close)(fildes[1]);
6247 SET_STATUS_Failure( VKI_EMFILE );
6248 } else if (VG_(clo_track_fds)) {
6249 ML_(record_fd_open_nameless)(tid, fildes[0]);
6250 ML_(record_fd_open_nameless)(tid, fildes[1]);
6254 // SYS_aio_mlock 543
6255 // int aio_mlock(struct aiocb *iocb);
6256 PRE(sys_aio_mlock)
6258 PRINT("sys_aio_mlock ( %#" FMT_REGWORD "x )", ARG1);
6259 PRE_REG_READ1(int, "aio_mlock", struct vki_aiocb *, iocb);
6260 PRE_MEM_READ("aio_mlock(iocb", ARG1, sizeof(struct vki_aiocb));
6261 // this locks memory into RAM, don't think that we need to do
6262 // anything extra
6265 // SYS_procctl 544
6266 // amd64 / x86
6268 // SYS_ppoll 545
6269 // int ppoll(struct pollfd fds[], nfds_t nfds,
6270 // const struct timespec * restrict timeout,
6271 // const sigset_t * restrict newsigmask);
6272 PRE(sys_ppoll)
6274 PRINT("sys_ppoll ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD
6275 "x, %#" FMT_REGWORD "x )",
6276 ARG1, ARG2, ARG3, ARG4);
6277 UInt i;
6278 struct vki_pollfd* fds = (struct vki_pollfd *)(Addr)ARG1;
6279 *flags |= SfMayBlock | SfPostOnFail;
6280 PRE_REG_READ4(long, "ppoll",
6281 struct vki_pollfd *, fds, unsigned int, nfds,
6282 struct vki_timespec *, timeout, vki_sigset_t *, newsigmask);
6284 for (i = 0; i < ARG2; i++) {
6285 PRE_MEM_READ( "ppoll(fds.fd)",
6286 (Addr)(&fds[i].fd), sizeof(fds[i].fd) );
6287 if (ML_(safe_to_deref)(&fds[i].fd, sizeof(fds[i].fd)) && fds[i].fd >= 0) {
6288 PRE_MEM_READ( "ppoll(fds.events)",
6289 (Addr)(&fds[i].events), sizeof(fds[i].events) );
6291 PRE_MEM_WRITE( "ppoll(fds.revents)",
6292 (Addr)(&fds[i].revents), sizeof(fds[i].revents) );
6295 if (ARG3) {
6296 PRE_MEM_READ( "ppoll(timeout)", ARG3,
6297 sizeof(struct vki_timespec) );
6299 if (ARG4) {
6300 PRE_MEM_READ( "ppoll(newsigmask)", ARG4, sizeof(vki_sigset_t));
6301 ARG4 = ML_(make_safe_mask)("syswrap.ppoll.1", (Addr)ARG4);
6305 POST(sys_ppoll)
6307 if (SUCCESS && ((Word)RES != -1)) {
6308 UInt i;
6309 struct vki_pollfd* ufds = (struct vki_pollfd *)(Addr)ARG1;
6310 for (i = 0; i < ARG2; i++) {
6311 POST_MEM_WRITE( (Addr)(&ufds[i].revents), sizeof(ufds[i].revents) );
6314 ML_(free_safe_mask) ( (Addr)ARG4 );
6317 // SYS_futimens 546
6318 // int futimens(int fd, const struct timespec times[2]);
6319 PRE(sys_futimens)
6321 PRINT("sys_futimens ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6322 PRE_REG_READ2(int, "futimens", int, fd, const struct timespec *, times);
6323 PRE_MEM_READ("futimens(times)", ARG2, 2*sizeof(struct vki_timespec));
6326 // SYS_utimensat 547
6327 // int utimensat(int fd, const char *path, const struct timespec times[2],
6328 // int flag);
6329 PRE(sys_utimensat)
6331 PRINT("sys_utimensat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )",
6332 SARG1, ARG2, ARG3, SARG4);
6333 PRE_REG_READ4(int, "utimensat", int, fd, const char *,path, const struct timespec *, times,
6334 int, flag);
6335 PRE_MEM_RASCIIZ("utimensat(path)", ARG2);
6336 PRE_MEM_READ("utimensat(times)", ARG3, 2*sizeof(struct vki_timespec));
6339 // SYS_fdatasync 550
6340 // int fdatasync(int fd);
6341 PRE(sys_fdatasync)
6343 PRINT("sys_fdatasync ( %" FMT_REGWORD "d )",SARG1);
6344 PRE_REG_READ1(int, "fdatasync", int, fd);
6347 #if (FREEBSD_VERS >= FREEBSD_12)
6348 // SYS_fstat 551
6349 // int fstat(int fd, struct stat *sb);
6350 PRE(sys_fstat)
6352 PRINT("sys_fstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
6353 PRE_REG_READ2(int, "fstat", int, fd, struct stat *, sb);
6354 PRE_MEM_WRITE( "fstat(sb)", ARG2, sizeof(struct vki_stat) );
6357 POST(sys_fstat)
6359 POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) );
6362 // SYS_fstatat 552
6363 // int fstatat(int fd, const char *path, struct stat *sb, int flag);
6364 PRE(sys_fstatat)
6366 PRINT("sys_fstatat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %" FMT_REGWORD "d )", SARG1,ARG2,(char*)ARG2,ARG3,SARG4);
6367 PRE_REG_READ4(int, "fstatat",
6368 int, fd, const char *, path, struct stat *, sb, int, flag);
6369 PRE_MEM_RASCIIZ( "fstatat(path)", ARG2 );
6370 PRE_MEM_WRITE( "fstatat(sb)", ARG3, sizeof(struct vki_stat) );
6373 POST(sys_fstatat)
6375 POST_MEM_WRITE( ARG3, sizeof(struct vki_stat) );
6377 // SYS_fhstat 553
6378 // int fhstat(const fhandle_t *fhp, struct stat *sb);
6379 PRE(sys_fhstat)
6381 PRINT("sys_fhstat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
6382 PRE_REG_READ2(long, "fhstat", const vki_fhandle_t *, fhp, struct stat *, sb);
6383 PRE_MEM_READ( "fhstat(fhp)", ARG1, sizeof(struct vki_fhandle) );
6384 PRE_MEM_WRITE( "fhstat(sb)", ARG2, sizeof(struct vki_stat) );
6387 POST(sys_fhstat)
6389 POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) );
6392 // SYS_getdirentries 554
6393 // ssize_t getdirentries(int fd, char *buf, size_t nbytes, off_t *basep);
6394 PRE(sys_getdirentries)
6396 *flags |= SfMayBlock;
6397 PRINT("sys_getdirentries ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", SARG1,ARG2,ARG3,ARG4);
6398 PRE_REG_READ4(ssize_t, "getdirentries",
6399 int, fd, char *, buf,
6400 size_t, nbytes,
6401 off_t *, basep);
6402 PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 );
6403 if (ARG4) {
6404 PRE_MEM_WRITE("getdirentries(basep)", ARG4, sizeof (vki_off_t));
6408 POST(sys_getdirentries)
6410 vg_assert(SUCCESS);
6411 if (RES > 0) {
6412 POST_MEM_WRITE( ARG2, RES );
6413 if ( ARG4 != 0 ) {
6414 POST_MEM_WRITE( ARG4, sizeof (vki_off_t));
6419 // SYS_statfs 555
6420 // int statfs(const char *path, struct statfs *buf);
6421 PRE(sys_statfs)
6423 PRINT("sys_statfs ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
6424 PRE_REG_READ2(int, "statfs", const char *, path, struct statfs *, buf);
6425 PRE_MEM_RASCIIZ( "statfs(path)", ARG1 );
6426 PRE_MEM_WRITE( "statfs(buf)", ARG2, sizeof(struct vki_statfs) );
6429 POST(sys_statfs)
6431 POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) );
6434 // SYS_fstatfs 556
6435 // int fstatfs(int fd, struct statfs *buf);
6436 PRE(sys_fstatfs)
6438 PRINT("sys_fstatfs ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
6439 PRE_REG_READ2(int, "fstatfs",
6440 int, fd, struct vki_statfs *, buf);
6441 PRE_MEM_WRITE( "fstatfs(buf)", ARG2, sizeof(struct vki_statfs) );
6444 POST(sys_fstatfs)
6446 POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) );
6449 // SYS_getfsstat 557
6450 // int getfsstat(struct statfs *buf, long bufsize, int mode);
6451 PRE(sys_getfsstat)
6453 PRINT("sys_getfsstat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
6454 PRE_REG_READ3(long, "getfsstat", struct vki_statfs *, buf, long, len, int, flags);
6455 PRE_MEM_WRITE( "getfsstat(buf)", ARG1, ARG2 );
6458 POST(sys_getfsstat)
6460 vg_assert(SUCCESS);
6461 if ((Word)RES != -1) {
6462 POST_MEM_WRITE( ARG1, RES * sizeof(struct vki_statfs) );
6466 // SYS_fhstatfs 558
6467 // int fhstatfs(const fhandle_t *fhp, struct statfs *buf);
6468 PRE(sys_fhstatfs)
6470 PRINT("sys_fhstatfs ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
6471 PRE_REG_READ2(long, "fhstatfs",
6472 struct fhandle *, fhp, struct statfs *, buf);
6473 PRE_MEM_READ( "fhstatfs(fhp)", ARG1, sizeof(struct vki_fhandle) );
6474 PRE_MEM_WRITE( "fhstatfs(buf)", ARG2, sizeof(struct vki_statfs) );
6477 POST(sys_fhstatfs)
6479 POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) );
6482 // SYS_mknodat 559
6483 // x86 / amd64
6485 // SYS_kevent 560
6486 // int kevent(int kq, const struct kevent *changelist, int nchanges,
6487 // struct kevent *eventlist, int nevents,
6488 // const struct timespec *timeout);
6489 PRE(sys_kevent)
6491 PRINT("sys_kevent ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )\n", ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
6492 PRE_REG_READ6(int, "kevent",
6493 int, kq, struct vki_kevent *, changelist, int, nchanges,
6494 struct vki_kevent *, eventlist, int, nevents,
6495 struct timespec *, timeout);
6496 if (ARG2 != 0 && ARG3 != 0) {
6497 PRE_MEM_READ( "kevent(changelist)", ARG2, sizeof(struct vki_kevent)*ARG3 );
6499 if (ARG4 != 0 && ARG5 != 0) {
6500 PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent)*ARG5);
6502 if (ARG5 != 0) {
6503 *flags |= SfMayBlock;
6505 if (ARG6 != 0) {
6506 PRE_MEM_READ( "kevent(timeout)",
6507 ARG6, sizeof(struct vki_timespec));
6511 POST(sys_kevent)
6513 vg_assert(SUCCESS);
6514 if ((Word)RES != -1) {
6515 if (ARG4 != 0) {
6516 POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent)*RES) ;
6521 // SYS_cpuset_getdomain 561
6522 // x86 / amd64
6524 // SYS_cpuset_setdomain 562
6525 // x86 / amd64
6527 // SYS_getrandom 563
6528 // ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
6529 PRE(sys_getrandom)
6531 PRINT("sys_getrandom ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
6532 PRE_REG_READ3(ssize_t, "getrandom",
6533 void *, buf, vki_size_t, buflen, unsigned int, flags);
6534 PRE_MEM_WRITE( "getrandom(buf)", ARG1, ARG2 );
6535 if ((ARG3 & VKI_GRND_NONBLOCK) == 0) {
6536 *flags |= SfMayBlock;
6540 POST(sys_getrandom)
6542 POST_MEM_WRITE( ARG1, ARG2 );
6545 // SYS_getfhat 564
6546 // int getfhat(int fd, const char *path, fhandle_t *fhp, int flag);
6547 PRE(sys_getfhat)
6549 PRINT("sys_getfhat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "x, %" FMT_REGWORD "d ", SARG1, ARG2, ARG3, SARG4);
6550 PRE_REG_READ4(int, "getfhat", int, fd, const char*, path, vki_fhandle_t*, fhp, int, flag);
6551 PRE_MEM_RASCIIZ( "getfhat(path)", ARG2 );
6552 PRE_MEM_WRITE("getfhat(fhp)", ARG3, sizeof(vki_fhandle_t));
6555 POST(sys_getfhat)
6557 POST_MEM_WRITE(ARG3, sizeof(vki_fhandle_t));
6560 // SYS_fhlink 565
6561 // int fhlink(fhandle_t *fhp, const char *to);
6562 PRE(sys_fhlink)
6564 PRINT("sys_fhlink ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1, ARG2);
6565 PRE_REG_READ2(int, "fhlink", vki_fhandle_t *, fhp, const char *, to);
6566 PRE_MEM_READ( "fhlink(fhp)", ARG1, sizeof(vki_fhandle_t));
6567 PRE_MEM_RASCIIZ("fhlink(buf)", ARG2);
6570 // SYS_fhlinkat 566
6571 // int fhlinkat(fhandle_t *fhp, int tofd, const char *to);
6572 PRE(sys_fhlinkat)
6574 PRINT("sys_fhlinkat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "xu ", ARG1, SARG2, ARG3);
6575 PRE_REG_READ3(int, "fhlinkat", vki_fhandle_t *, fhp, int, tofd, const char *, to);
6576 PRE_MEM_READ( "fhlinkat(fhp)", ARG1, sizeof(vki_fhandle_t));
6577 PRE_MEM_RASCIIZ("fhreadlink(to)", ARG3);
6580 // SYS_fhreadlink 567
6581 // int fhreadlink(fhandle_t *fhp, char *buf, size_t bufsize);
6582 PRE(sys_fhreadlink)
6584 PRINT("sys_fhreadlink ( %#" FMT_REGWORD "x, %" FMT_REGWORD "x, %" FMT_REGWORD "u ", ARG1, ARG2, ARG3);
6585 PRE_REG_READ3(int, "fhreadlink", vki_fhandle_t *, fhp, char *, buf, size_t, bufsize);
6586 PRE_MEM_READ( "fhreadlink(fhp)", ARG1, sizeof(vki_fhandle_t));
6587 PRE_MEM_WRITE("fhreadlink(buf)", ARG2, ARG3);
6590 POST(sys_fhreadlink)
6592 POST_MEM_WRITE(ARG2, ARG3);
6595 #endif
6597 #if (FREEBSD_VERS >= FREEBSD_12_2)
6599 // SYS_unlinkat 568
6600 // int funlinkat(int dfd, const char *path, int fd, int flag);
6601 PRE(sys_funlinkat)
6603 *flags |= SfMayBlock;
6604 PRINT("sys_funlinkat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %" FMT_REGWORD"u )",
6605 SARG1, ARG2, (char*)ARG2, ARG4, ARG5);
6606 PRE_REG_READ4(int, "funlinkat", int, dfd, const char *, path, int, fd, int, flag);
6607 PRE_MEM_RASCIIZ( "funlinkat(path)", ARG2 );
6610 // SYS_copy_file_range 569
6611 // ssize_t copy_file_range(int infd, off_t *inoffp, int outfd, off_t *outoffp,
6612 // size_t len, unsigned int flags);
6613 PRE(sys_copy_file_range)
6615 PRINT("sys_copy_file_range (%" FMT_REGWORD"d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "d, %" FMT_REGWORD "d)",
6616 SARG1, ARG2, SARG3, ARG4, (char*)ARG4, SARG5, SARG6);
6618 PRE_REG_READ6(vki_ssize_t, "copy_file_range",
6619 int, "infd",
6620 vki_off_t *, "inoffp",
6621 int, "outfd",
6622 vki_off_t *, "outoffp",
6623 vki_size_t, "len",
6624 unsigned int, "flags");
6626 /* File descriptors are "specially" tracked by valgrind.
6627 valgrind itself uses some, so make sure someone didn't
6628 put in one of our own... */
6629 if (!ML_(fd_allowed)(ARG1, "copy_file_range(infd)", tid, False) ||
6630 !ML_(fd_allowed)(ARG3, "copy_file_range(infd)", tid, False)) {
6631 SET_STATUS_Failure( VKI_EBADF );
6632 } else {
6633 /* Now see if the offsets are defined. PRE_MEM_READ will
6634 double check it can dereference them. */
6635 if (ARG2 != 0) {
6636 PRE_MEM_READ( "copy_file_range(inoffp)", ARG2, sizeof(vki_off_t));
6638 if (ARG4 != 0) {
6639 PRE_MEM_READ( "copy_file_range(outoffp)", ARG4, sizeof(vki_off_t));
6645 // SYS___sysctlbyname 570
6646 // int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
6647 // const void *newp, size_t newlen);
6648 // syscalls.master:
6649 // int __sysctlbyname(_In_reads_(namelen) const char *name, size_t namelen,
6650 // _Out_writes_bytes_opt_(*oldlenp) void *old,
6651 // _Inout_opt_ size_t *oldlenp, _In_reads_bytes_opt_(newlen) void *new,
6652 // size_t newlen );
6653 PRE(sys___sysctlbyname)
6655 // this is very much like SYS___sysctl, instead of having an OID with length
6656 // here threre is an ascii string with length
6657 // @todo PJF factor out the common functionality of the two
6658 PRINT("sys___sysctlbyname ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,(const char*)ARG1,ARG2,ARG3,ARG4,ARG5 );
6659 PRE_REG_READ6(int, "__sysctlbyname", const char *, name, vki_size_t, namelen,
6660 void *, oldp, vki_size_t *, oldlenp,
6661 void *, newp, vki_size_t, newlen);
6664 const char* name = (const char*)ARG1;
6665 if (ML_(safe_to_deref)(name, sizeof("kern.ps_strings")) &&
6666 VG_(strcmp)(name, "kern.ps_strings") == 0) {
6667 if (sysctl_kern_ps_strings((SizeT*)ARG3, (SizeT*)ARG4)) {
6668 SET_STATUS_Success(0);
6672 if (ML_(safe_to_deref)(name, sizeof("kern.usrstack")) &&
6673 VG_(strcmp)(name, "kern.usrstack") == 0) {
6674 sysctl_kern_usrstack((SizeT*)ARG3, (SizeT*)ARG4);
6675 SET_STATUS_Success(0);
6678 // kern.proc.pathname doesn't seem to be handled
6679 // makes sense as the pid is variable and using
6680 // a MIB is easier than generating a string
6682 // read number of ints specified in ARG2 from mem pointed to by ARG1
6683 PRE_MEM_READ("__sysctlbyname(name)", (Addr)ARG1, ARG2 * sizeof(int));
6685 // if 'newp' is not NULL can read namelen bytes from that addess
6686 if (ARG5 != (UWord)NULL) {
6687 PRE_MEM_READ("__sysctlbyname(newp)", (Addr)ARG5, ARG6);
6690 // there are two scenarios for oldlenp/oldp
6691 // 1. oldval is NULL and oldlenp is non-NULL
6692 // this is a query of oldlenp so oldlenp will be written
6693 // 2. Both are non-NULL
6694 // this is a query of oldp, oldlenp will be read and oldp will
6695 // be written
6697 // is oldlenp is not NULL, can write
6698 if (ARG4 != (UWord)NULL) {
6699 if (ARG3 != (UWord)NULL) {
6700 // case 2 above
6701 PRE_MEM_READ("__sysctlbyname(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
6702 if (ML_(safe_to_deref)((void*)(Addr)ARG4, sizeof(vki_size_t))) {
6703 PRE_MEM_WRITE("__sysctlbyname(oldp)", (Addr)ARG3, *(vki_size_t *)ARG4);
6704 } else {
6705 VG_(dmsg)("Warning: Bad oldlenp address %p in sysctlbyname\n",
6706 (void *)(Addr)ARG4);
6707 SET_STATUS_Failure ( VKI_EFAULT );
6709 } else {
6710 // case 1 above
6711 PRE_MEM_WRITE("__sysctlbyname(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
6716 POST(sys___sysctlbyname)
6718 if (ARG4 != (UWord)NULL) {
6719 if (ARG3 != (UWord)NULL) {
6720 //POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
6721 POST_MEM_WRITE((Addr)ARG3, *(vki_size_t *)ARG4);
6722 } else {
6723 POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
6728 #endif // (FREEBSD_VERS >= FREEBSD_12_2)
6730 #if (FREEBSD_VERS >= FREEBSD_13_0)
6732 // SYS_shm_open2 571
6733 // from syscalls.master
6734 // int shm_open2(_In_z_ const char *path,
6735 // int flags,
6736 // mode_t mode,
6737 // int shmflags,
6738 // _In_z_ const char *name);
6739 PRE(sys_shm_open2)
6741 PRE_REG_READ5(int, "shm_open2",
6742 const char *, path, int, flags, vki_mode_t, mode, int, shmflags, const char*, name);
6743 if (ARG1 == VKI_SHM_ANON) {
6744 PRINT("sys_shm_open2(%#" FMT_REGWORD "x(SHM_ANON), %" FMT_REGWORD "u, %hu, %d, %#" FMT_REGWORD "x(%s))",
6745 ARG1, ARG2, (vki_mode_t)ARG3, (Int)ARG4, ARG5, (HChar*)ARG5);
6746 } else {
6747 PRINT("sys_shm_open2(%#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu, %d, %#" FMT_REGWORD "x(%s))",
6748 ARG1, (HChar *)ARG1, ARG2, (vki_mode_t)ARG3, (Int)ARG4, ARG5, (HChar*)ARG5);
6749 PRE_MEM_RASCIIZ( "shm_open2(path)", ARG1 );
6752 if (ARG5) {
6753 PRE_MEM_RASCIIZ( "shm_open2(name)", ARG5 );
6755 *flags |= SfMayBlock;
6758 POST(sys_shm_open2)
6760 vg_assert(SUCCESS);
6761 if (!ML_(fd_allowed)(RES, "shm_open2", tid, True)) {
6762 VG_(close)(RES);
6763 SET_STATUS_Failure( VKI_EMFILE );
6764 } else {
6765 if (VG_(clo_track_fds)) {
6766 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1);
6771 // SYS_sigfastblock 573
6772 // int sigfastblock(int cmd, void *ptr);
6773 PRE(sys_sigfastblock)
6775 PRINT("sys_sigfastblock ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6776 PRE_REG_READ2(int, "sigfasblock", int, cmd, void*, ptr);
6779 // SYS___realpathat 574
6780 // from syscalls.master
6781 // int __realpathat(int fd,
6782 // _In_z_ const char *path,
6783 // _Out_writes_z_(size) char *buf,
6784 // size_t size,
6785 // int flags)
6786 PRE(sys___realpathat)
6788 PRINT("sys___realpathat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %" FMT_REGWORD "u %" FMT_REGWORD "d )",
6789 SARG1,ARG2,(const char*)ARG2,ARG3,ARG4,SARG5 );
6790 PRE_REG_READ5(int, "__realpathat", int, fd, const char *, path,
6791 char *, buf, vki_size_t, size, int, flags);
6792 PRE_MEM_RASCIIZ("__realpathat(path)", (Addr)ARG2);
6793 PRE_MEM_WRITE("__realpathat(buf)", (Addr)ARG3, ARG4);
6796 POST(sys___realpathat)
6798 POST_MEM_WRITE((Addr)ARG3, ARG4);
6801 #endif
6803 #if (FREEBSD_VERS >= FREEBSD_12_2)
6805 // SYS_sys_close_range 575
6806 // int close_range(close_range(u_int lowfd, u_int highfd, int flags);
6807 PRE(sys_close_range)
6809 SysRes res = VG_(mk_SysRes_Success)(0);
6810 unsigned int lowfd = ARG1;
6811 unsigned int fd_counter; // will count from lowfd to highfd
6812 unsigned int highfd = ARG2;
6814 /* on linux the may lock if futexes are used
6815 * there is a lock in the kernel but I assume it's just
6816 * a spinlock */
6817 PRINT("sys_close_range ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %"
6818 FMT_REGWORD "d )", ARG1, ARG2, SARG3);
6819 PRE_REG_READ3(int, "close_range",
6820 unsigned int, lowfd, unsigned int, highfd,
6821 int, flags);
6823 if (lowfd > highfd) {
6824 SET_STATUS_Failure( VKI_EINVAL );
6825 return;
6828 if (highfd >= VG_(fd_hard_limit))
6829 highfd = VG_(fd_hard_limit) - 1;
6831 if (lowfd > highfd) {
6832 SET_STATUS_Success ( 0 );
6833 return;
6836 fd_counter = lowfd;
6837 do {
6838 if (fd_counter > highfd
6839 || (fd_counter == 2U/*stderr*/ && VG_(debugLog_getLevel)() > 0)
6840 || fd_counter == VG_(log_output_sink).fd
6841 || fd_counter == VG_(xml_output_sink).fd) {
6842 /* Split the range if it contains a file descriptor we're not
6843 * supposed to close. */
6844 if (fd_counter - 1 >= lowfd) {
6845 res = VG_(do_syscall3)(__NR_close_range, (UWord)lowfd, (UWord)fd_counter - 1, ARG3 );
6847 lowfd = fd_counter + 1;
6849 } while (fd_counter++ <= highfd);
6851 /* If it failed along the way, it's presumably the flags being wrong. */
6852 SET_STATUS_from_SysRes (res);
6855 POST(sys_close_range)
6857 unsigned int fd;
6858 unsigned int last = ARG2;
6860 if (!VG_(clo_track_fds)
6861 || (ARG3 & VKI_CLOSE_RANGE_CLOEXEC) != 0)
6862 return;
6864 if (last >= VG_(fd_hard_limit))
6865 last = VG_(fd_hard_limit) - 1;
6867 for (fd = ARG1; fd <= last; fd++)
6868 if ((fd != 2/*stderr*/ || VG_(debugLog_getLevel)() == 0)
6869 && fd != VG_(log_output_sink).fd
6870 && fd != VG_(xml_output_sink).fd)
6871 ML_(record_fd_close)(fd);
6873 #endif
6875 #if (FREEBSD_VERS >= FREEBSD_13_0)
6877 // SYS___specialfd 577
6878 // syscalls.master
6879 // int __specialfd(int type,
6880 // _In_reads_bytes_(len) const void *req,
6881 // size_t len);
6882 PRE(sys___specialfd)
6884 PRINT("sys___specialfd ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )",
6885 SARG1,ARG2,(const char*)ARG2,ARG3 );
6886 PRE_REG_READ3(int, "__specialfd", int, type, const void *, req, vki_size_t, len);
6887 PRE_MEM_READ("__specialfd(req)", (Addr)ARG2, ARG3);
6890 // SYS_aio_writev 578
6891 // int aio_writev(struct aiocb *iocb);
6892 PRE(sys_aio_writev)
6894 PRINT("sys_aio_writev ( %#" FMT_REGWORD "x )", ARG1);
6895 PRE_REG_READ1(int, "aio_writev", struct vki_aiocb *, iocb);
6896 PRE_MEM_READ("aio_writev(iocb)", ARG1, sizeof(struct vki_aiocb));
6897 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
6898 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
6899 if (!ML_(fd_allowed)(iocb->aio_fildes, "aio_writev", tid, False)) {
6900 SET_STATUS_Failure( VKI_EBADF );
6901 } else {
6902 // aio_writev() gathers the data from the iocb->aio_iovcnt buffers specified
6903 // by the members of the iocb->aio_iov array
6904 // FreeBSD headers #define define this to aio_iovcnt
6905 SizeT vec_count = (SizeT)iocb->aio_nbytes;
6906 #if defined(__clang__)
6907 #pragma clang diagnostic push
6908 // yes, I know it is volatile
6909 #pragma clang diagnostic ignored "-Wcast-qual"
6910 #endif
6911 struct vki_iovec* p_iovec = (struct vki_iovec*)iocb->aio_buf;
6912 #if defined(__clang__)
6913 #pragma clang diagnostic pop
6914 #endif
6915 PRE_MEM_READ("aio_writev(iocb->aio_iov)", (Addr)p_iovec, vec_count*sizeof(struct vki_iovec));
6916 // and this to aio_iov
6918 if (ML_(safe_to_deref)(p_iovec, vec_count*sizeof(struct vki_iovec))) {
6919 for (SizeT i = 0U; i < vec_count; ++i) {
6920 PRE_MEM_READ("aio_writev(iocb->iov[...])",
6921 (Addr)p_iovec[i].iov_base, p_iovec[i].iov_len);
6925 } else {
6926 SET_STATUS_Failure(VKI_EINVAL);
6930 // SYS_aio_readv 579
6931 // int aio_readv(struct aiocb *iocb);
6932 PRE(sys_aio_readv)
6934 PRINT("sys_aio_readv ( %#" FMT_REGWORD "x )", ARG1);
6935 PRE_REG_READ1(int, "aio_readv", struct vki_aiocb *, iocb);
6936 PRE_MEM_READ("aio_readv(iocb)", ARG1, sizeof(struct vki_aiocb));
6937 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
6938 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
6939 if (!ML_(fd_allowed)(iocb->aio_fildes, "aio_readv", tid, False)) {
6940 SET_STATUS_Failure( VKI_EBADF );
6941 } else {
6942 SizeT vec_count = (SizeT)iocb->aio_nbytes;
6943 #if defined(__clang__)
6944 #pragma clang diagnostic push
6945 // yes, I know it is volatile
6946 #pragma clang diagnostic ignored "-Wcast-qual"
6947 #endif
6948 struct vki_iovec* p_iovec = (struct vki_iovec*)iocb->aio_buf;
6949 #if defined(__clang__)
6950 #pragma clang diagnostic pop
6951 #endif
6952 PRE_MEM_READ("aio_readv(iocb->aio_iov)", (Addr)p_iovec, vec_count*sizeof(struct vki_iovec));
6953 if (ML_(safe_to_deref)(p_iovec, vec_count*sizeof(struct vki_iovec))) {
6954 for (SizeT i = 0U; i < vec_count; ++i) {
6955 PRE_MEM_WRITE("aio_writev(iocb->aio_iov[...])",
6956 (Addr)p_iovec[i].iov_base, p_iovec[i].iov_len);
6960 } else {
6961 SET_STATUS_Failure(VKI_EINVAL);
6965 POST(sys_aio_readv)
6967 struct vki_aiocb* iocbv = (struct vki_aiocb*)ARG1;
6968 if (iocbv->aio_buf) {
6969 if (!aiov_init_done) {
6970 aiov_init();
6973 if (!VG_(OSetWord_Contains)(iocbv_table, (UWord)iocbv)) {
6974 VG_(OSetWord_Insert)(iocbv_table, (UWord)iocbv);
6975 } else {
6976 // @todo PJF this warns without callstack
6977 VG_(dmsg)("Warning: Duplicate control block %p in aio_readv\n",
6978 (void *)(Addr)ARG1);
6979 VG_(dmsg)("Warning: Ensure 'aio_return' is called when 'aio_readv' has completed\n");
6984 #endif // (FREEBSD_VERS >= FREEBSD_13_0)
6986 #if (FREEBSD_VERS >= FREEBSD_13_1)
6988 #if (FREEBSD_VERS >= FREEBSD_14)
6989 // SYS_fspacectl 580
6990 // int fspacectl(int fd, int cmd, const struct spacectl_range *rqsr, int flags,
6991 // struct spacectl_range *rmsr);
6992 PRE(sys_fspacectl)
6994 PRINT("fspacectl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, SARG2, ARG3, SARG4, ARG5);
6995 PRE_REG_READ5(int, "fspacectl", int, fd, int, cmd, const struct spacectl_range *, rqsr, int, flags, struct spacectl_range *, rmsr);
6996 PRE_MEM_READ("fspacectl(rqsr)", (Addr)ARG3, sizeof(struct vki_spacectl_range));
6997 if (ARG5) {
6998 PRE_MEM_WRITE("fspacectl(rmsr)", (Addr)ARG5, sizeof(struct vki_spacectl_range));
7002 POST(sys_fspacectl)
7004 if (ARG5) {
7005 POST_MEM_WRITE((Addr)ARG5, sizeof(struct vki_spacectl_range));
7008 #endif
7010 // SYS_swapoff 582
7011 // int swapoff(const char *special, u_int flags);
7012 PRE(sys_swapoff)
7014 PRINT("sys_swapoff(%#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u)", ARG1,(char *)ARG1, ARG2);
7015 PRE_REG_READ2(int, "swapoff", const char *, special, u_int, flags);
7016 PRE_MEM_RASCIIZ( "swapoff(special)", ARG1 );
7019 #endif
7021 #if (FREEBSD_VERS >= FREEBSD_15)
7023 // SYS_kqueuex 583
7024 // int kqueuex(u_int flags);
7025 PRE(sys_kqueuex)
7027 PRINT("sys_kqueuex(%#" FMT_REGWORD "x)", ARG1);
7028 PRE_REG_READ1(int, "kqueuex", u_int, flags);
7031 POST(sys_kqueuex)
7033 if (!ML_(fd_allowed)(RES, "kqueuex", tid, True)) {
7034 VG_(close)(RES);
7035 SET_STATUS_Failure(VKI_EMFILE);
7036 } else {
7037 if (VG_(clo_track_fds)) {
7038 ML_(record_fd_open_nameless)(tid, RES);
7043 // SYS_membarrier 584
7044 // syscalls.master
7045 // int membarrier(int cmd, unsigned flags, int cpu_id);
7046 PRE(sys_membarrier)
7048 // cmd is signed int but the constants in the headers
7049 // are hex so print in hex
7050 PRINT("sys_membarrier(%#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "d)",
7051 ARG1, ARG2, SARG3);
7052 PRE_REG_READ3(int, "membarrier", int, cmd, unsigned, flags, int, cpu_id);
7055 // SYS_timerfd_create 585
7056 // int timerfd_create(int clockid, int flags);
7057 PRE(sys_timerfd_create)
7059 PRINT("sys_timerfd_create (%ld, %ld )", SARG1, SARG2);
7060 PRE_REG_READ2(int, "timerfd_create", int, clockid, int, flags);
7063 POST(sys_timerfd_create)
7065 if (!ML_(fd_allowed)(RES, "timerfd_create", tid, True)) {
7066 VG_(close)(RES);
7067 SET_STATUS_Failure( VKI_EMFILE );
7068 } else {
7069 if (VG_(clo_track_fds))
7070 ML_(record_fd_open_nameless) (tid, RES);
7074 // SYS_timerfd_gettime 586
7075 // int timerfd_gettime(int fd, struct itimerspec *curr_value);
7076 PRE(sys_timerfd_gettime)
7078 PRINT("sys_timerfd_gettime ( %ld, %#" FMT_REGWORD "x )", SARG1, ARG2);
7079 PRE_REG_READ2(int, "timerfd_gettime",
7080 int, fd,
7081 struct vki_itimerspec*, curr_value);
7082 if (!ML_(fd_allowed)(ARG1, "timerfd_gettime", tid, False))
7083 SET_STATUS_Failure(VKI_EBADF);
7084 else
7085 PRE_MEM_WRITE("timerfd_gettime(curr_value)",
7086 ARG2, sizeof(struct vki_itimerspec));
7089 POST(sys_timerfd_gettime)
7091 if (RES == 0)
7092 POST_MEM_WRITE(ARG2, sizeof(struct vki_itimerspec));
7095 // SYS_timerfd_gettime 587
7096 // int timerfd_settime(int fd, int flags, const struct itimerspec *new_value,
7097 // struct itimerspec *old_value);
7098 PRE(sys_timerfd_settime)
7100 PRINT("sys_timerfd_settime(%" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#"
7101 FMT_REGWORD "x )", SARG1, SARG2, ARG3, ARG4);
7102 PRE_REG_READ4(int, "timerfd_settime",
7103 int, fd,
7104 int, flags,
7105 const struct vki_itimerspec*, new_value,
7106 struct vki_itimerspec*, old_value);
7107 if (!ML_(fd_allowed)(ARG1, "timerfd_settime", tid, False))
7108 SET_STATUS_Failure(VKI_EBADF);
7109 else
7111 PRE_MEM_READ("timerfd_settime(new_value)",
7112 ARG3, sizeof(struct vki_itimerspec));
7113 if (ARG4)
7115 PRE_MEM_WRITE("timerfd_settime(old_value)",
7116 ARG4, sizeof(struct vki_itimerspec));
7121 POST(sys_timerfd_settime)
7123 if (RES == 0 && ARG4 != 0) {
7124 POST_MEM_WRITE(ARG4, sizeof(struct vki_itimerspec));
7127 #endif
7129 #undef PRE
7130 #undef POST
7132 const SyscallTableEntry ML_(syscall_table)[] = {
7133 // syscall (handled specially) // 0
7134 BSDX_(__NR_exit, sys_exit), // 1
7135 BSDX_(__NR_fork, sys_fork), // 2
7136 GENXY(__NR_read, sys_read), // 3
7138 GENX_(__NR_write, sys_write), // 4
7139 GENXY(__NR_open, sys_open), // 5
7140 GENXY(__NR_close, sys_close), // 6
7141 GENXY(__NR_wait4, sys_wait4), // 7
7143 // 4.3 creat 8
7144 GENX_(__NR_link, sys_link), // 9
7145 GENX_(__NR_unlink, sys_unlink), // 10
7146 // obsol execv 11
7148 GENX_(__NR_chdir, sys_chdir), // 12
7149 GENX_(__NR_fchdir, sys_fchdir), // 13
7150 GENX_(__NR_freebsd11_mknod, sys_mknod), // 14
7151 GENX_(__NR_chmod, sys_chmod), // 15
7153 GENX_(__NR_chown, sys_chown), // 16
7154 GENX_(__NR_break, sys_brk), // 17
7155 // freebsd 4 getfsstat 18
7156 // 4.3 lseek 19
7158 GENX_(__NR_getpid, sys_getpid), // 20
7159 BSDX_(__NR_mount, sys_mount), // 21
7160 BSDX_(__NR_unmount, sys_unmount), // 22
7161 GENX_(__NR_setuid, sys_setuid), // 23
7163 GENX_(__NR_getuid, sys_getuid), // 24
7164 GENX_(__NR_geteuid, sys_geteuid), // 25
7165 BSDXY(__NR_ptrace, sys_ptrace), // 26
7166 BSDXY(__NR_recvmsg, sys_recvmsg), // 27
7168 BSDX_(__NR_sendmsg, sys_sendmsg), // 28
7169 BSDXY(__NR_recvfrom, sys_recvfrom), // 29
7170 BSDXY(__NR_accept, sys_accept), // 30
7171 BSDXY(__NR_getpeername, sys_getpeername), // 31
7173 BSDXY(__NR_getsockname, sys_getsockname), // 32
7174 GENX_(__NR_access, sys_access), // 33
7175 BSDX_(__NR_chflags, sys_chflags), // 34
7176 BSDX_(__NR_fchflags, sys_fchflags), // 35
7178 GENX_(__NR_sync, sys_sync), // 36
7179 GENX_(__NR_kill, sys_kill), // 37
7180 // 4.3 stat 38
7181 GENX_(__NR_getppid, sys_getppid), // 39
7183 // 4.3 lstat 40
7184 GENXY(__NR_dup, sys_dup), // 41
7186 BSDXY(__NR_freebsd10_pipe, sys_pipe), // 42
7187 GENX_(__NR_getegid, sys_getegid), // 43
7189 GENX_(__NR_profil, sys_ni_syscall), // 44
7190 GENX_(__NR_ktrace, sys_ni_syscall), // 45
7191 // 4.3 sigaction 46
7192 GENX_(__NR_getgid, sys_getgid), // 47
7194 // 4.3 sigaction (int sigset) 48
7195 BSDXY(__NR_getlogin, sys_getlogin), // 49
7196 BSDX_(__NR_setlogin, sys_setlogin), // 50
7197 GENX_(__NR_acct, sys_acct), // 51
7199 // 4.3 sigpending 52
7200 GENXY(__NR_sigaltstack, sys_sigaltstack), // 53
7201 BSDXY(__NR_ioctl, sys_ioctl), // 54
7202 BSDX_(__NR_reboot, sys_reboot), // 55
7204 BSDX_(__NR_revoke, sys_revoke), // 56
7205 GENX_(__NR_symlink, sys_symlink), // 57
7206 BSDX_(__NR_readlink, sys_readlink), // 58
7207 GENX_(__NR_execve, sys_execve), // 59
7209 GENX_(__NR_umask, sys_umask), // 60
7210 GENX_(__NR_chroot, sys_chroot), // 61
7211 // 4.3 fstat 62
7212 // 4.3 getgerninfo 63
7214 // 4.3 getpagesize 64
7215 GENX_(__NR_msync, sys_msync), // 65
7216 BSDX_(__NR_vfork, sys_vfork), // 66
7217 // obsol vread 67
7219 // obsol vwrite 68
7220 BSDX_(__NR_sbrk, sys_sbrk), // 69
7221 // not implemented in OS sstk 70
7222 // 4.3 mmap 71
7224 // freebsd11 vadvise 72
7225 GENXY(__NR_munmap, sys_munmap), // 73
7226 GENXY(__NR_mprotect, sys_mprotect), // 74
7227 GENX_(__NR_madvise, sys_madvise), // 75
7229 // obsol vhangup 76
7230 // obsol vlimit 77
7231 GENXY(__NR_mincore, sys_mincore), // 78
7232 GENXY(__NR_getgroups, sys_getgroups), // 79
7234 GENX_(__NR_setgroups, sys_setgroups), // 80
7235 GENX_(__NR_getpgrp, sys_getpgrp), // 81
7236 GENX_(__NR_setpgid, sys_setpgid), // 82
7237 GENXY(__NR_setitimer, sys_setitimer), // 83
7239 // 4.3 wait 84
7240 BSDX_(__NR_swapon, sys_swapon), // 85
7241 GENXY(__NR_getitimer, sys_getitimer), // 86
7242 // 4.3 gethostname 87
7244 // 4.3 sethostname 88
7245 BSDX_(__NR_getdtablesize, sys_getdtablesize), // 89
7246 GENXY(__NR_dup2, sys_dup2), // 90
7248 BSDXY(__NR_fcntl, sys_fcntl), // 92
7249 GENX_(__NR_select, sys_select), // 93
7250 GENX_(__NR_fsync, sys_fsync), // 95
7252 GENX_(__NR_setpriority, sys_setpriority), // 96
7253 BSDXY(__NR_socket, sys_socket), // 97
7254 BSDX_(__NR_connect, sys_connect), // 98
7255 // 4.3 accept 99
7257 GENX_(__NR_getpriority, sys_getpriority), // 100
7258 // 4.3 send 101
7259 // 4.3 recv 102
7260 // 4.3 sigreturn 103
7262 BSDX_(__NR_bind, sys_bind), // 104
7263 BSDX_(__NR_setsockopt, sys_setsockopt), // 105
7264 BSDX_(__NR_listen, sys_listen), // 106
7265 // obsol vtimes 107
7267 // 4.3 sigvec 108
7268 // 4.3 sigblock 109
7269 // 4.3 sigsetmask 110
7270 // 4.3 sigsuspend 111
7272 // 4.3 sigstack 112
7273 // 4.3 recvmsg 113
7274 // 4.3 sendmsg 114
7275 // 4.3 vtrace 115
7277 GENXY(__NR_gettimeofday, sys_gettimeofday), // 116
7278 GENXY(__NR_getrusage, sys_getrusage), // 117
7279 BSDXY(__NR_getsockopt, sys_getsockopt), // 118
7281 GENXY(__NR_readv, sys_readv), // 120
7282 GENX_(__NR_writev, sys_writev), // 121
7283 GENX_(__NR_settimeofday, sys_settimeofday), // 122
7284 GENX_(__NR_fchown, sys_fchown), // 123
7286 GENX_(__NR_fchmod, sys_fchmod), // 124
7287 // 4.3 recvfrom 125
7288 GENX_(__NR_setreuid, sys_setreuid), // 126
7289 GENX_(__NR_setregid, sys_setregid), // 127
7291 GENX_(__NR_rename, sys_rename), // 128
7292 // 4.3 truncate 129
7293 // 4.3 ftruncate 130
7294 GENX_(__NR_flock, sys_flock), // 131
7296 BSDX_(__NR_mkfifo, sys_mkfifo), // 132
7297 BSDX_(__NR_sendto, sys_sendto), // 133
7298 BSDX_(__NR_shutdown, sys_shutdown), // 134
7299 BSDXY(__NR_socketpair, sys_socketpair), // 135
7301 GENX_(__NR_mkdir, sys_mkdir), // 136
7302 GENX_(__NR_rmdir, sys_rmdir), // 137
7303 GENX_(__NR_utimes, sys_utimes), // 138
7304 // 4.2 sigreturn 139
7306 BSDXY(__NR_adjtime, sys_adjtime), // 140
7307 // 4.3 getpeername 141
7308 // 4.3 gethostid 142
7309 // 4.3 sethostid 143
7311 // 4.3 getrlimit` 144
7312 // 4.3 setrlimit 145
7313 // 4.3 killpg 146
7314 GENX_(__NR_setsid, sys_setsid), // 147
7316 BSDX_(__NR_quotactl, sys_quotactl), // 148
7317 // 4.3 quota 149
7318 // 4.3 getsockname 150
7319 // bsd/os sem_lock 151
7321 // bsd/os sem_wakeup 152
7322 // bsd/os asyncdaemon 153
7324 // no idea what the following syscall does
7325 // unimp SYS_nlm_syscall 154
7327 // a somewhat complicated NFS API
7328 // takes a flag and a void* that can point to one of
7329 // three different types of struct depending on the flag
7330 // unimp SYS_nfssvc 155
7332 // 4.3 getdirentries 156
7333 // freebsd 4 statfs 157
7334 // freebsd 4 fstatfs 158
7336 BSDXY(__NR_lgetfh, sys_lgetfh), // 160
7337 BSDXY(__NR_getfh, sys_getfh), // 161
7338 #if (FREEBSD_VERS <= FREEBSD_10)
7339 BSDXY(__NR_freebsd4_getdomainname, sys_freebsd4_getdomainname), // 162
7340 BSDX_(__NR_freebsd4_setdomainname, sys_freebsd4_setdomainname), // 163
7341 BSDXY(__NR_freebsd4_uname, sys_freebsd4_uname), // 164
7342 #endif
7343 BSDXY(__NR_sysarch, sys_sysarch), // 165
7344 BSDXY(__NR_rtprio, sys_rtprio), // 166
7346 // the following 3 seem only to be defines in a header
7347 // semsys 169
7348 // msgsys 170
7349 // shmsys 171
7351 #if (FREEBSD_VERS <= FREEBSD_10)
7352 BSDXY(__NR_freebsd6_pread, sys_freebsd6_pread), // 173
7353 BSDX_(__NR_freebsd6_pwrite, sys_freebsd6_pwrite), // 174
7354 #endif
7355 BSDX_(__NR_setfib, sys_setfib), // 175
7357 // @todo PJF this exists on Darwin and Solaris as well
7358 // and it isn't implememented on either
7359 // looking at the manpage there is a rather fearsome
7360 // timex struct with a mixture of ro and rw fields
7361 // BSDXY(__NR_ntp_adjtime, sys_ntp_adjtime), // 176
7363 // bsd/os sfork 177
7364 // bsd/os getdescriptor 178
7365 // bsd/os setdescriptor 179
7367 GENX_(__NR_setgid, sys_setgid), // 181
7368 BSDX_(__NR_setegid, sys_setegid), // 182
7369 BSDX_(__NR_seteuid, sys_seteuid), // 183
7371 // obs lfs_bmapv 184
7372 // obs lfs_markv 185
7373 // obs lfs_segclean 186
7374 // obs lfs_segwait 187
7376 #if (FREEBSD_VERS >= FREEBSD_12)
7377 BSDXY(__NR_freebsd11_stat, sys_freebsd11_stat), // 188
7378 BSDXY(__NR_freebsd11_fstat, sys_freebsd11_fstat), // 189
7379 BSDXY(__NR_freebsd11_lstat, sys_freebsd11_lstat), // 190
7380 #else
7381 BSDXY(__NR_stat, sys_stat), // 188
7382 BSDXY(__NR_fstat, sys_fstat), // 189
7383 BSDXY(__NR_lstat, sys_lstat), // 190
7384 #endif
7385 BSDX_(__NR_pathconf, sys_pathconf), // 191
7386 BSDX_(__NR_fpathconf, sys_fpathconf), // 192
7387 GENXY(__NR_getrlimit, sys_getrlimit), // 194
7388 GENX_(__NR_setrlimit, sys_setrlimit), // 195
7389 #if (FREEBSD_VERS >= FREEBSD_12)
7390 BSDXY(__NR_freebsd11_getdirentries, sys_freebsd11_getdirentries), // 196
7391 #else
7392 BSDXY(__NR_getdirentries, sys_getdirentries), // 196
7393 #endif
7394 #if (FREEBSD_VERS <= FREEBSD_10)
7395 BSDX_(__NR_freebsd6_mmap, sys_freebsd6_mmap), // 197
7396 #endif
7397 // __syscall (handled specially) // 198
7398 #if (FREEBSD_VERS <= FREEBSD_10)
7399 BSDX_(__NR_freebsd6_lseek, sys_freebsd6_lseek), // 199
7400 BSDX_(__NR_freebsd6_truncate, sys_freebsd6_truncate), // 200
7401 BSDX_(__NR_freebsd6_ftruncate, sys_freebsd6_ftruncate), // 201
7402 #endif
7403 BSDXY(__NR___sysctl, sys___sysctl), // 202
7404 GENX_(__NR_mlock, sys_mlock), // 203
7406 GENX_(__NR_munlock, sys_munlock), // 204
7407 BSDX_(__NR_undelete, sys_undelete), // 205
7408 BSDX_(__NR_futimes, sys_futimes), // 206
7409 GENX_(__NR_getpgid, sys_getpgid), // 207
7411 // netbsd newreboot 208
7412 GENXY(__NR_poll, sys_poll), // 209
7414 BSDXY(__NR_freebsd7___semctl, sys_freebsd7___semctl), // 220
7415 BSDX_(__NR_semget, sys_semget), // 221
7416 BSDX_(__NR_semop, sys_semop), // 222
7417 // obs semconfig 223
7419 BSDXY(__NR_freebsd7_msgctl, sys_freebsd7_msgctl), // 224
7420 BSDX_(__NR_msgget, sys_msgget), // 225
7421 BSDX_(__NR_msgsnd, sys_msgsnd), // 226
7422 BSDXY(__NR_msgrcv, sys_msgrcv), // 227
7424 BSDXY(__NR_shmat, sys_shmat), // 228
7425 BSDXY(__NR_freebsd7_shmctl, sys_freebsd7_shmctl), // 229
7426 BSDXY(__NR_shmdt, sys_shmdt), // 230
7427 BSDX_(__NR_shmget, sys_shmget), // 231
7429 BSDXY(__NR_clock_gettime, sys_clock_gettime), // 232
7430 BSDX_(__NR_clock_settime, sys_clock_settime), // 233
7431 BSDXY(__NR_clock_getres, sys_clock_getres), // 234
7432 BSDXY(__NR_ktimer_create, sys_timer_create), // 235
7433 BSDX_(__NR_ktimer_delete, sys_timer_delete), // 236
7434 BSDXY(__NR_ktimer_settime, sys_timer_settime), // 237
7435 BSDXY(__NR_ktimer_gettime, sys_timer_gettime), // 238
7436 BSDX_(__NR_ktimer_getoverrun, sys_timer_getoverrun), // 239
7438 GENXY(__NR_nanosleep, sys_nanosleep), // 240
7439 // unimpl SYS_ffclock_getcounter 241
7440 // unimpl SYS_ffclock_setestimate 242
7441 // unimpl SYS_ffclock_getestimate 243
7443 BSDXY(__NR_clock_nanosleep, sys_clock_nanosleep), // 244
7444 BSDXY(__NR_clock_getcpuclockid2, sys_clock_getcpuclockid2), // 247
7446 // unimpl SYS_ntp_gettime 248
7447 BSDXY(__NR_minherit, sys_minherit), // 250
7448 BSDX_(__NR_rfork, sys_rfork), // 251
7450 // openbsd_poll // 252
7451 BSDX_(__NR_issetugid, sys_issetugid), // 253
7452 GENX_(__NR_lchown, sys_lchown), // 254
7453 BSDXY(__NR_aio_read, sys_aio_read), // 255
7454 BSDX_(__NR_aio_write, sys_aio_write), // 256
7455 BSDX_(__NR_lio_listio, sys_lio_listio), // 257
7457 GENXY(__NR_freebsd11_getdents, sys_getdents), // 272
7458 BSDX_(__NR_lchmod, sys_lchmod), // 274
7459 // netbsd_lchown // 275
7461 BSDX_(__NR_lutimes, sys_lutimes), // 276
7462 // netbsd msync 277
7463 // unimpl SYS_freebsd11_nstat 278
7464 // unimpl SYS_freebsd11_nfstat 279
7466 // unimpl SYS_freebsd11_nlstat 280
7468 BSDXY(__NR_preadv, sys_preadv), // 289
7469 BSDX_(__NR_pwritev, sys_pwritev), // 290
7471 // freebsd 4 fhstatfs 297
7472 BSDXY(__NR_fhopen, sys_fhopen), // 298
7473 #if (FREEBSD_VERS >= FREEBSD_12)
7474 BSDXY(__NR_freebsd11_fhstat, sys_freebsd11_fhstat), // 299
7475 #else
7476 BSDXY(__NR_fhstat, sys_fhstat), // 299
7477 #endif
7479 BSDX_(__NR_modnext, sys_modnext), // 300
7480 BSDXY(__NR_modstat, sys_modstat), // 301
7481 BSDX_(__NR_modfnext, sys_modfnext), // 302
7482 BSDX_(__NR_modfind, sys_modfind), // 303
7484 BSDX_(__NR_kldload, sys_kldload), // 304
7485 BSDX_(__NR_kldunload, sys_kldunload), // 305
7486 BSDX_(__NR_kldfind, sys_kldfind), // 306
7487 BSDX_(__NR_kldnext, sys_kldnext), // 307
7489 BSDXY(__NR_kldstat, sys_kldstat), // 308
7490 BSDX_(__NR_kldfirstmod, sys_kldfirstmod), // 309
7491 GENX_(__NR_getsid, sys_getsid), // 310
7492 BSDX_(__NR_setresuid, sys_setresuid), // 311
7494 BSDX_(__NR_setresgid, sys_setresgid), // 312
7495 // obsol signanosleep 313
7496 BSDX_(__NR_aio_return, sys_aio_return), // 314
7497 BSDX_(__NR_aio_suspend, sys_aio_suspend), // 315
7499 BSDX_(__NR_aio_cancel, sys_aio_cancel), // 316
7500 BSDX_(__NR_aio_error, sys_aio_error), // 317
7501 // freebsd 6 aio_read 318
7502 // freebsd 6 aio_write 319
7503 // freebsd 6 lio_listio 320
7504 BSDX_(__NR_yield, sys_yield), // 321
7505 // obs thr_sleep 322
7506 // obs thr_wakeup 323
7508 GENX_(__NR_mlockall, sys_mlockall), // 324
7509 BSDX_(__NR_munlockall, sys_munlockall), // 325
7510 BSDXY(__NR___getcwd, sys___getcwd), // 326
7511 BSDX_(__NR_sched_setparam, sys_sched_setparam), // 327
7512 BSDXY(__NR_sched_getparam, sys_sched_getparam), // 328
7513 BSDX_(__NR_sched_setscheduler, sys_sched_setscheduler), // 329
7514 BSDX_(__NR_sched_getscheduler, sys_sched_getscheduler), // 330
7515 BSDX_(__NR_sched_yield, sys_sched_yield), // 331
7517 BSDX_(__NR_sched_get_priority_max, sys_sched_get_priority_max), // 332
7518 BSDX_(__NR_sched_get_priority_min, sys_sched_get_priority_min), // 333
7519 BSDXY(__NR_sched_rr_get_interval, sys_sched_rr_get_interval), // 334
7520 BSDX_(__NR_utrace, sys_utrace), // 335
7522 // freebsd 4 sendfile 336
7523 BSDXY(__NR_kldsym, sys_kldsym), // 337
7524 BSDX_(__NR_jail, sys_jail), // 338
7525 // unimpl SYS_nnpfs_syscall 339
7527 BSDXY(__NR_sigprocmask, sys_sigprocmask), // 340
7528 BSDXY(__NR_sigsuspend, sys_sigsuspend), // 341
7529 // freebsd 4 sigaction 342
7530 BSDXY(__NR_sigpending, sys_sigpending), // 343
7532 // freebsd 4 sigreturn 344
7533 BSDXY(__NR_sigtimedwait, sys_sigtimedwait), // 345
7534 BSDXY(__NR_sigwaitinfo, sys_sigwaitinfo), // 346
7535 BSDXY(__NR___acl_get_file, sys___acl_get_file), // 347
7537 BSDX_(__NR___acl_set_file, sys___acl_set_file), // 348
7538 BSDXY(__NR___acl_get_fd, sys___acl_get_fd), // 349
7539 BSDX_(__NR___acl_set_fd, sys___acl_set_fd), // 350
7540 BSDX_(__NR___acl_delete_file, sys___acl_delete_file), // 351
7542 BSDX_(__NR___acl_delete_fd, sys___acl_delete_fd), // 352
7543 BSDX_(__NR___acl_aclcheck_file, sys___acl_aclcheck_file), // 353
7544 BSDX_(__NR___acl_aclcheck_fd, sys___acl_aclcheck_fd), // 354
7545 BSDX_(__NR_extattrctl, sys_extattrctl), // 355
7546 BSDX_(__NR_extattr_set_file, sys_extattr_set_file), // 356
7547 BSDXY(__NR_extattr_get_file, sys_extattr_get_file), // 357
7548 BSDX_(__NR_extattr_delete_file, sys_extattr_delete_file), // 358
7549 BSDXY(__NR_aio_waitcomplete, sys_aio_waitcomplete), // 359
7551 BSDXY(__NR_getresuid, sys_getresuid), // 360
7552 BSDXY(__NR_getresgid, sys_getresgid), // 361
7553 BSDXY(__NR_kqueue, sys_kqueue), // 362
7554 #if (FREEBSD_VERS >= FREEBSD_12)
7555 BSDXY(__NR_freebsd11_kevent, sys_freebsd11_kevent), // 363
7556 #else
7557 BSDXY(__NR_kevent, sys_kevent), // 363
7558 #endif
7559 // obs __cap_get_proc 364
7560 // obs __cap_set_proc 365
7561 // obs __cap_get_fd 366
7562 // obs __cap_get_file 367
7563 // obs __cap_set_fd 368
7564 // obs __cap_set_file 369
7566 BSDX_(__NR_extattr_set_fd, sys_extattr_set_fd), // 371
7567 BSDXY(__NR_extattr_get_fd, sys_extattr_get_fd), // 372
7568 BSDX_(__NR_extattr_delete_fd, sys_extattr_delete_fd), // 373
7569 BSDX_(__NR___setugid, sys___setugid), // 374
7570 // obs nfsclnt 375
7572 BSDX_(__NR_eaccess, sys_eaccess), // 376
7573 // unimpl afs3_syscall 377
7574 BSDX_(__NR_nmount, sys_nmount), // 378
7575 // obs kse_exit 379
7576 // obs kse_wakeup 380
7577 // obs kse_create 381
7578 // obs kse_thr_interrupt 382
7579 // obs kse_release 383
7581 // unimpl __mac_get_proc 384
7582 // unimpl __mac_set_proc 385
7583 // unimpl __mac_get_fd 386
7584 // unimpl __mac_get_file 387
7585 // unimpl __mac_set_fd 388
7586 // unimpl __mac_set_file 389
7587 BSDXY(__NR_kenv, sys_kenv), // 390
7588 BSDX_(__NR_lchflags, sys_lchflags), // 391
7590 BSDXY(__NR_uuidgen, sys_uuidgen), // 392
7591 BSDXY(__NR_sendfile, sys_sendfile), // 393
7592 // unimpl mac_syscall 394
7594 #if (FREEBSD_VERS >= FREEBSD_12)
7595 BSDXY(__NR_freebsd11_getfsstat, sys_freebsd11_getfsstat), // 395
7596 BSDXY(__NR_freebsd11_statfs, sys_statfs), // 396
7597 BSDXY(__NR_freebsd11_fstatfs, sys_fstatfs), // 397
7598 BSDXY(__NR_freebsd11_fhstatfs, sys_fhstatfs), // 398
7599 #else
7600 BSDXY(__NR_getfsstat, sys_getfsstat), // 395
7601 BSDXY(__NR_statfs, sys_statfs), // 396
7602 BSDXY(__NR_fstatfs, sys_fstatfs), // 397
7603 BSDXY(__NR_fhstatfs, sys_fhstatfs), // 398
7604 #endif
7606 // unimpl ksem_close 400
7607 // unimpl ksem_post 401
7608 // unimpl ksem_wait 402
7609 // unimpl ksem_trywait 403
7611 // unimpl ksem_init 404
7612 // unimpl ksem_open 405
7613 // unimpl ksem_unlink 406
7614 // unimpl ksem_getvalue 407
7616 // unimpl ksem_destroy 408
7617 // unimpl __mac_get_pid 409
7618 // unimpl __mac_get_link 410
7619 // unimpl __mac_set_link 411
7621 BSDX_(__NR_extattr_set_link, sys_extattr_set_link), // 412
7622 BSDXY(__NR_extattr_get_link, sys_extattr_get_link), // 413
7623 BSDX_(__NR_extattr_delete_link, sys_extattr_delete_link), // 414
7624 // unimpl __mac_execve 415
7626 BSDXY(__NR_sigaction, sys_sigaction), // 416
7627 BSDX_(__NR_sigreturn, sys_sigreturn), // 417
7629 BSDXY(__NR_getcontext, sys_getcontext), // 421
7630 BSDX_(__NR_setcontext, sys_setcontext), // 422
7631 BSDXY(__NR_swapcontext, sys_swapcontext), // 423
7633 #if (FREEBSD_VERS >= FREEBSD_13_1)
7634 BSDX_(__NR_freebsd13_swapoff, sys_freebsd13_swapoff), // 424
7635 #else
7636 BSDX_(__NR_swapoff, sys_swapoff), // 424
7637 #endif
7638 BSDXY(__NR___acl_get_link, sys___acl_get_link), // 425
7639 BSDX_(__NR___acl_set_link, sys___acl_set_link), // 426
7640 BSDX_(__NR___acl_delete_link, sys___acl_delete_link), // 427
7642 BSDX_(__NR___acl_aclcheck_link, sys___acl_aclcheck_link), // 428
7643 BSDXY(__NR_sigwait, sys_sigwait), // 429
7644 BSDX_(__NR_thr_create, sys_thr_create), // 430
7645 BSDX_(__NR_thr_exit, sys_thr_exit), // 431
7647 BSDXY(__NR_thr_self, sys_thr_self), // 432
7648 BSDXY(__NR_thr_kill, sys_thr_kill), // 433
7649 #if (FREEBSD_VERS <= FREEBSD_10)
7650 BSDXY(__NR__umtx_lock, sys__umtx_lock), // 434
7651 BSDXY(__NR__umtx_unlock, sys__umtx_unlock), // 435
7652 #endif
7654 BSDX_(__NR_jail_attach, sys_jail_attach), // 436
7655 BSDXY(__NR_extattr_list_fd, sys_extattr_list_fd), // 437
7656 BSDXY(__NR_extattr_list_file, sys_extattr_list_file), // 438
7657 BSDXY(__NR_extattr_list_link, sys_extattr_list_link), // 439
7659 // obs kse_switchin 440
7660 // unimpl ksem_timedwait 441
7661 BSDX_(__NR_thr_suspend, sys_thr_suspend), // 442
7662 BSDX_(__NR_thr_wake, sys_thr_wake), // 443
7663 BSDX_(__NR_kldunloadf, sys_kldunloadf), // 444
7664 // unimpl audit 445
7665 // unimpl auditon 446
7666 // unimpl getauid 447
7668 // unimpl setauid 448
7669 // unimpl getaudit 449
7670 // unimpl setaudit 450
7671 // unimpl getaudit_addr 451
7672 // unimpl setaudit_addr 452
7673 // unimpl auditctl 453
7674 BSDXY(__NR__umtx_op, sys__umtx_op), // 454
7675 BSDX_(__NR_thr_new, sys_thr_new), // 455
7677 BSDX_(__NR_sigqueue, sys_sigqueue), // 456
7678 BSDXY(__NR_kmq_open, sys_kmq_open), // 457
7679 BSDX_(__NR_kmq_setattr, sys_kmq_setattr), // 458
7680 BSDXY(__NR_kmq_timedreceive, sys_kmq_timedreceive), // 459
7682 BSDX_(__NR_kmq_timedsend, sys_kmq_timedsend), // 460
7683 BSDX_(__NR_kmq_notify, sys_kmq_notify), // 461
7684 BSDX_(__NR_kmq_unlink, sys_kmq_unlink), // 462
7685 BSDX_(__NR_abort2, sys_abort2), // 463
7687 BSDX_(__NR_thr_set_name, sys_thr_set_name), // 464
7688 BSDX_(__NR_aio_fsync, sys_aio_fsync), // 465
7689 BSDXY(__NR_rtprio_thread, sys_rtprio_thread), // 466
7691 // unimpl sctp_peeloff 471
7692 BSDX_(__NR_sctp_generic_sendmsg, sys_sctp_generic_sendmsg), // 472
7693 // unimpl sctp_generic_sendmsg_iov 473
7694 BSDXY(__NR_sctp_generic_recvmsg, sys_sctp_generic_recvmsg), // 474
7695 BSDXY(__NR_pread, sys_pread), // 475
7697 BSDX_(__NR_pwrite, sys_pwrite), // 476
7698 BSDX_(__NR_mmap, sys_mmap), // 477
7699 BSDX_(__NR_lseek, sys_lseek), // 478
7700 BSDX_(__NR_truncate, sys_truncate), // 479
7701 BSDX_(__NR_ftruncate, sys_ftruncate), // 480
7702 BSDXY(__NR_thr_kill2, sys_thr_kill2), // 481
7703 BSDXY(__NR_shm_open, sys_shm_open), // 482
7704 BSDX_(__NR_shm_unlink, sys_shm_unlink), // 483
7706 BSDXY(__NR_cpuset, sys_cpuset), // 484
7707 BSDX_(__NR_cpuset_setid, sys_cpuset_setid), // 485
7708 BSDXY(__NR_cpuset_getid, sys_cpuset_getid), // 486
7710 BSDXY(__NR_cpuset_getaffinity, sys_cpuset_getaffinity), // 487
7711 BSDX_(__NR_cpuset_setaffinity, sys_cpuset_setaffinity), // 488
7712 BSDX_(__NR_faccessat, sys_faccessat), // 489
7713 BSDX_(__NR_fchmodat, sys_fchmodat), // 490
7714 BSDX_(__NR_fchownat, sys_fchownat), // 491
7716 BSDX_(__NR_fexecve, sys_fexecve), // 492
7717 #if (FREEBSD_VERS >= FREEBSD_12)
7718 BSDXY(__NR_freebsd11_fstatat, sys_freebsd11_fstatat), // 493
7719 #else
7720 BSDXY(__NR_fstatat, sys_fstatat), // 493
7721 #endif
7722 BSDX_(__NR_futimesat, sys_futimesat), // 494
7723 BSDX_(__NR_linkat, sys_linkat), // 495
7725 BSDX_(__NR_mkdirat, sys_mkdirat), // 496
7726 BSDX_(__NR_mkfifoat, sys_mkfifoat), // 497
7728 #if (FREEBSD_VERS >= FREEBSD_12)
7729 BSDX_(__NR_freebsd11_mknodat, sys_freebsd11_mknodat), // 498
7730 #else
7731 BSDX_(__NR_mknodat, sys_mknodat), // 498
7732 #endif
7734 BSDXY(__NR_openat, sys_openat), // 499
7736 BSDXY(__NR_readlinkat, sys_readlinkat), // 500
7737 BSDX_(__NR_renameat, sys_renameat), // 501
7738 BSDX_(__NR_symlinkat, sys_symlinkat), // 502
7739 BSDX_(__NR_unlinkat, sys_unlinkat), // 503
7741 BSDX_(__NR_posix_openpt, sys_posix_openpt), // 504
7742 // unimp gssd_syscall 505
7743 BSDX_(__NR_jail_get, sys_jail_get), // 506
7744 BSDX_(__NR_jail_set, sys_jail_set), // 507
7745 BSDX_(__NR_jail_remove, sys_jail_remove), // 508
7746 BSDX_(__NR_closefrom, sys_closefrom), // 509
7747 BSDXY(__NR___semctl, sys___semctl), // 510
7748 BSDXY(__NR_msgctl, sys_msgctl), // 511
7749 BSDXY(__NR_shmctl, sys_shmctl), // 512
7750 BSDX_(__NR_lpathconf, sys_lpathconf), // 513
7751 /* 514 is obsolete cap_new */
7752 BSDXY(__NR___cap_rights_get, sys_cap_rights_get), // 515
7753 BSDX_(__NR_cap_enter, sys_cap_enter), // 516
7754 BSDXY(__NR_cap_getmode, sys_cap_getmode), // 517
7755 BSDXY(__NR_pdfork, sys_pdfork), // 518
7756 BSDX_(__NR_pdkill, sys_pdkill), // 519
7757 BSDXY(__NR_pdgetpid, sys_pdgetpid), // 520
7758 BSDXY(__NR_pselect, sys_pselect), // 522
7759 BSDXY(__NR_getloginclass, sys_getloginclass), // 523
7760 BSDX_(__NR_setloginclass, sys_setloginclass), // 524
7761 BSDXY(__NR_rctl_get_racct, sys_rctl_get_racct), // 525
7762 BSDXY(__NR_rctl_get_rules, sys_rctl_get_rules), // 526
7763 BSDXY(__NR_rctl_get_limits, sys_rctl_get_limits), // 527
7764 BSDXY(__NR_rctl_add_rule, sys_rctl_add_rule), // 528
7765 BSDXY(__NR_rctl_remove_rule, sys_rctl_remove_rule), // 529
7766 BSDX_(__NR_posix_fallocate, sys_posix_fallocate), // 530
7767 BSDX_(__NR_posix_fadvise, sys_posix_fadvise), // 531
7768 BSDXY(__NR_wait6, sys_wait6), // 532
7769 BSDX_(__NR_cap_rights_limit, sys_cap_rights_limit), // 533
7770 BSDX_(__NR_cap_ioctls_limit, sys_cap_ioctls_limit), // 534
7771 BSDXY(__NR_cap_ioctls_get, sys_cap_ioctls_get), // 535
7772 BSDX_(__NR_cap_fcntls_limit, sys_cap_fcntls_limit), // 536
7773 BSDXY(__NR_cap_fcntls_get, sys_cap_fcntls_get), // 537
7774 BSDX_(__NR_bindat, sys_bindat), // 538
7775 BSDX_(__NR_connectat, sys_connectat), // 539
7776 BSDX_(__NR_chflagsat, sys_chflagsat), // 540
7777 BSDXY(__NR_accept4, sys_accept4), // 541
7778 BSDXY(__NR_pipe2, sys_pipe2), // 542
7779 BSDX_(__NR_aio_mlock, sys_aio_mlock), // 543
7780 BSDXY(__NR_procctl, sys_procctl), // 544
7782 // 544 is the highest syscall on FreeBSD 9
7784 #if (FREEBSD_VERS >= FREEBSD_10)
7786 BSDXY(__NR_ppoll, sys_ppoll), // 545
7787 BSDX_(__NR_futimens, sys_futimens), // 546
7788 BSDX_(__NR_utimensat, sys_utimensat), // 547
7790 #endif // FREEBSD_VERS >= FREEBSD_10
7792 #if (FREEBSD_VERS >= FREEBSD_11)
7794 /* 548 is obsolete numa_getaffinity */
7795 /* 549 is obsolete numa_setaffinity */
7796 BSDX_(__NR_fdatasync, sys_fdatasync), // 550
7798 #endif // FREEBSD_VERS >= FREEBSD_11
7800 #if (FREEBSD_VERS >= FREEBSD_12)
7801 BSDXY(__NR_fstat, sys_fstat), // 551
7802 BSDXY(__NR_fstatat, sys_fstatat), // 552
7803 BSDXY(__NR_fhstat, sys_fhstat), // 553
7804 BSDXY(__NR_getdirentries, sys_getdirentries), // 554
7805 BSDXY(__NR_statfs, sys_statfs), // 555
7806 BSDXY(__NR_fstatfs, sys_fstatfs), // 556
7807 BSDXY(__NR_getfsstat, sys_getfsstat), // 557
7808 BSDXY(__NR_fhstatfs, sys_fhstatfs), // 558
7809 BSDX_(__NR_mknodat, sys_mknodat), // 559
7810 BSDXY(__NR_kevent, sys_kevent), // 560
7811 BSDXY(__NR_cpuset_getdomain, sys_cpuset_getdomain), // 561
7812 BSDX_(__NR_cpuset_setdomain, sys_cpuset_setdomain), // 562
7813 BSDXY(__NR_getrandom, sys_getrandom), // 563
7814 BSDXY(__NR_getfhat, sys_getfhat), // 564
7815 BSDX_(__NR_fhlink, sys_fhlink), // 565
7816 BSDX_(__NR_fhlinkat, sys_fhlinkat), // 566
7817 BSDXY(__NR_fhreadlink, sys_fhreadlink), // 567
7818 #endif // FREEBSD_VERS >= FREEBSD_12
7820 #if (FREEBSD_VERS >= FREEBSD_12_2)
7821 BSDX_(__NR_funlinkat, sys_funlinkat), // 568
7822 BSDX_(__NR_copy_file_range, sys_copy_file_range), // 569
7823 BSDXY(__NR___sysctlbyname, sys___sysctlbyname), // 570
7825 #if (FREEBSD_VERS >= FREEBSD_13_0)
7826 BSDXY(__NR_shm_open2, sys_shm_open2), // 571
7827 // unimpl __NR_shm_rename 572
7828 BSDX_(__NR_sigfastblock, sys_sigfastblock), // 573
7829 BSDXY( __NR___realpathat, sys___realpathat), // 574
7830 #endif
7831 BSDXY(__NR_close_range, sys_close_range), // 575
7832 #endif
7834 #if (FREEBSD_VERS >= FREEBSD_13_0)
7835 // unimpl __NR_rpctls_syscall 576
7836 BSDX_(__NR___specialfd, sys___specialfd), // 577
7837 BSDX_(__NR_aio_writev, sys_aio_writev), // 578
7838 BSDXY(__NR_aio_readv, sys_aio_readv), // 579
7839 #endif
7841 #if (FREEBSD_VERS >= FREEBSD_13_1)
7843 #if (FREEBSD_VERS >= FREEBSD_14)
7844 BSDXY(__NR_fspacectl, sys_fspacectl), // 580
7845 #endif
7846 // unimpl __NR_sched_getcpu 581
7847 BSDX_(__NR_swapoff, sys_swapoff), // 582
7848 #endif
7850 #if (FREEBSD_VERS >= FREEBSD_15)
7851 BSDXY(__NR_kqueuex, sys_kqueuex), // 583
7852 BSDX_(__NR_membarrier, sys_membarrier), // 584
7853 BSDXY(__NR_timerfd_create, sys_timerfd_create), // 585
7854 BSDXY(__NR_timerfd_settime, sys_timerfd_settime), // 586
7855 BSDXY(__NR_timerfd_gettime, sys_timerfd_gettime), // 587
7856 #endif
7859 BSDX_(__NR_fake_sigreturn, sys_fake_sigreturn), // 1000, fake sigreturn
7863 const SyscallTableEntry* ML_(get_freebsd_syscall_entry) ( UInt sysno )
7865 const UInt syscall_table_size
7866 = sizeof(ML_(syscall_table)) / sizeof(ML_(syscall_table)[0]);
7868 /* Is it in the contiguous initial section of the table? */
7869 if (sysno < syscall_table_size) {
7870 const SyscallTableEntry* sys = &ML_(syscall_table)[sysno];
7871 if (sys->before == NULL) {
7872 return NULL; /* no entry */
7874 return sys;
7877 /* Can't find a wrapper */
7878 return NULL;
7881 /*--------------------------------------------------------------------*/
7882 /*--- end ---*/
7883 /*--------------------------------------------------------------------*/
7885 #endif // defined(VGO_freebsd)