FreeBSD syscall: add wrapper for kcmp
[valgrind.git] / coregrind / m_syswrap / syswrap-freebsd.c
blob0a937d37fdd98feafcdd5bdaf312c331e9336c6a
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 #elif defined(VGP_arm64_freebsd)
282 __asm__ volatile (
283 "str %w1, %0\n" /* set tst->status = VgTs_Empty (32-bit store) */
284 "mov x8, %2\n" /* set %x8 = __NR_thr_exit */
285 "ldr x0, %3\n" /* set %x0 = tst->os_state.exitcode */
286 "svc 0x00000000\n" /* exit(tst->os_state.exitcode) */
287 : "=m" (tst->status)
288 : "r" (VgTs_Empty), "n" (__NR_thr_exit), "m" (tst->os_state.exitcode)
289 : "x0", "x8"
291 #else
292 # error Unknown platform
293 #endif
295 VG_(core_panic)("Thread exit failed?\n");
298 /*NOTREACHED*/
299 vg_assert(0);
302 Word ML_(start_thread_NORETURN) ( void* arg )
304 ThreadState* tst = (ThreadState*)arg;
305 ThreadId tid = tst->tid;
307 run_a_thread_NORETURN ( (Word)tid );
308 /*NOTREACHED*/
309 vg_assert(0);
312 /* Allocate a stack for this thread, if it doesn't already have one.
313 They're allocated lazily, and never freed. Returns the initial stack
314 pointer value to use, or 0 if allocation failed. */
315 Addr ML_(allocstack)(ThreadId tid)
317 ThreadState* tst = VG_(get_ThreadState)(tid);
318 VgStack* stack;
319 Addr initial_SP;
321 /* Either the stack_base and stack_init_SP are both zero (in which
322 case a stack hasn't been allocated) or they are both non-zero,
323 in which case it has. */
325 if (tst->os_state.valgrind_stack_base == 0) {
326 vg_assert(tst->os_state.valgrind_stack_init_SP == 0);
329 if (tst->os_state.valgrind_stack_base != 0) {
330 vg_assert(tst->os_state.valgrind_stack_init_SP != 0);
333 /* If no stack is present, allocate one. */
335 if (tst->os_state.valgrind_stack_base == 0) {
336 stack = VG_(am_alloc_VgStack)( &initial_SP );
337 if (stack) {
338 tst->os_state.valgrind_stack_base = (Addr)stack;
339 tst->os_state.valgrind_stack_init_SP = initial_SP;
343 if (0) {
344 VG_(printf)( "stack for tid %u at %p; init_SP=%p\n",
345 tid,
346 (void*)tst->os_state.valgrind_stack_base,
347 (void*)tst->os_state.valgrind_stack_init_SP );
350 return tst->os_state.valgrind_stack_init_SP;
353 /* Allocate a stack for the main thread, and run it all the way to the
354 end. Although we already have a working VgStack
355 (VG_(interim_stack)) it's better to allocate a new one, so that
356 overflow detection works uniformly for all threads.
358 __attribute__((noreturn))
359 void VG_(main_thread_wrapper_NORETURN)(ThreadId tid)
361 Addr sp;
362 VG_(debugLog)(1, "syswrap-freebsd",
363 "entering VG_(main_thread_wrapper_NORETURN)\n");
365 sp = ML_(allocstack)(tid);
366 #if defined(ENABLE_INNER_CLIENT_REQUEST)
368 // we must register the main thread stack before the call
369 // to ML_(call_on_new_stack_0_1), otherwise the outer valgrind
370 // reports 'write error' on the non registered stack.
371 ThreadState* tst = VG_(get_ThreadState)(tid);
372 INNER_REQUEST
373 ((void)
374 VALGRIND_STACK_REGISTER (tst->os_state.valgrind_stack_base,
375 tst->os_state.valgrind_stack_init_SP));
377 #endif
379 /* If we can't even allocate the first thread's stack, we're hosed.
380 Give up. */
381 vg_assert2(sp != 0, "%s", "Cannot allocate main thread's stack.");
383 /* shouldn't be any other threads around yet */
384 vg_assert( VG_(count_living_threads)() == 1 );
386 ML_(call_on_new_stack_0_1)(
387 (Addr)sp, /* stack */
388 0, /* bogus return address */
389 run_a_thread_NORETURN, /* fn to call */
390 (Word)tid /* arg to give it */
393 /*NOTREACHED*/
394 vg_assert(0);
398 /* Do a fork() */
399 SysRes ML_(do_fork) ( ThreadId tid )
401 vki_sigset_t fork_saved_mask;
402 vki_sigset_t mask;
403 SysRes res;
405 /* Block all signals during fork, so that we can fix things up in
406 the child without being interrupted. */
407 VG_(sigfillset)(&mask);
408 VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &fork_saved_mask);
410 VG_(do_atfork_pre)(tid);
412 res = VG_(do_syscall0)( __NR_fork );
414 if (!sr_isError(res)) {
415 if (sr_Res(res) == 0) {
416 /* child */
417 VG_(do_atfork_child)(tid);
419 /* restore signal mask */
420 VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
422 } else {
423 /* parent */
424 VG_(do_atfork_parent)(tid);
426 if (VG_(clo_trace_syscalls)) {
427 VG_(printf)(" clone(fork): process %d created child %lu\n",
428 VG_(getpid)(), sr_Res(res));
431 /* restore signal mask */
432 VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
436 return res;
439 static Addr ML_(make_safe_mask) ( const HChar* malloc_message, Addr mask_pointer )
441 vki_sigset_t* new_mask;
442 const vki_sigset_t* old_mask = (vki_sigset_t *)mask_pointer;
444 if (!ML_(safe_to_deref)(old_mask, sizeof(vki_sigset_t))) {
445 new_mask = (vki_sigset_t*)1; /* Something recognisable to POST() hook. */
446 } else {
447 new_mask = VG_(malloc)(malloc_message, sizeof(vki_sigset_t));
448 *new_mask = *old_mask;
449 VG_(sanitize_client_sigmask)(new_mask);
452 return (Addr)new_mask;
455 static void ML_(free_safe_mask) ( Addr mask_pointer )
457 if (mask_pointer != 0 && mask_pointer != 1) {
458 VG_(free)((vki_sigset_t *) mask_pointer);
463 /* ---------------------------------------------------------------------
464 PRE/POST wrappers for arch-generic, FreeBSD-specific syscalls
465 ------------------------------------------------------------------ */
467 // Nb: See the comment above the generic PRE/POST wrappers in
468 // m_syswrap/syswrap-generic.c for notes about how they work.
470 #define PRE(name) DEFN_PRE_TEMPLATE(freebsd, name)
471 #define POST(name) DEFN_POST_TEMPLATE(freebsd, name)
473 /* On FreeBSD, if any thread calls exit(2), then they are all shut down, pretty
474 * much like linux's exit_group().
476 // SYS_exit 1
477 // void exit(int status);
478 PRE(sys_exit)
480 ThreadId t;
482 PRINT("exit( %" FMT_REGWORD "u )", ARG1);
483 PRE_REG_READ1(void, "exit", int, status);
485 /* Mark all threads (including this one) to exit. */
486 for (t = 1; t < VG_N_THREADS; t++) {
487 if ( /* not alive */ VG_(threads)[t].status == VgTs_Empty ) {
488 continue;
491 //VG_(threads)[t].exitreason = VgSrc_ExitThread;
492 VG_(threads)[t].os_state.exitcode = ARG1;
494 // if (t != tid)
495 // VG_(get_thread_out_of_syscall)(t); /* unblock it, if blocked */
498 VG_(nuke_all_threads_except)( tid, VgSrc_ExitProcess );
499 VG_(reap_threads)(tid);
500 VG_(threads)[tid].exitreason = VgSrc_ExitThread;
502 /* We have to claim the syscall already succeeded. */
503 SET_STATUS_Success(0);
506 // SYS_fork 2
507 // pid_t fork(void);
508 PRE(sys_fork)
510 PRINT("%s", "sys_fork ()");
511 PRE_REG_READ0(pid_t, "fork");
513 SET_STATUS_from_SysRes( ML_(do_fork)(tid) );
514 if (SUCCESS) {
515 /* Thread creation was successful; let the child have the chance
516 to run */
517 *flags |= SfYieldAfter;
521 // SYS_read 3
522 // generic
524 // SYS_write 4
525 // generic
527 // SYS_open 5
528 // generic
530 // SYS_close 6
531 // generic
533 // SYS_wait4 7
534 // generic
536 // SYS_link 9
537 // generic
539 // SYS_unlink 10
540 // generic
542 // SYS_chdir 12
544 // SYS_fchdir 13
545 // generic
547 // SYS_freebsd11_mknod 14
548 // generic
550 // SYS_chmod 15
551 // generic
553 // SYS_chown 16
554 // generic
556 // SYS_break 17
557 // generic
559 // SYS_getpid 20
560 // generic
562 // SYS_mount 21
563 // int mount(const char *type, const char *dir, int flags, void *data);
564 PRE(sys_mount)
566 // Nb: depending on 'flags', the 'type' and 'data' args may be ignored.
567 // We are conservative and check everything, except the memory pointed to
568 // by 'data'.
569 *flags |= SfMayBlock;
570 PRINT( "sys_mount( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
571 PRE_REG_READ4(int, "mount",
572 const char *, type, char *, dir, int, flags,
573 void *, data);
574 PRE_MEM_RASCIIZ( "mount(type)", ARG1);
575 PRE_MEM_RASCIIZ( "mount(path)", ARG2);
578 // SYS_unmount 22
579 // int unmount(const char *dir, int flags);
580 PRE(sys_unmount)
582 PRINT("sys_umount( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
583 PRE_REG_READ2(int, "unmount", const char *, dir, int, flags);
584 PRE_MEM_RASCIIZ( "unmount(path)", ARG1);
587 // SYS_setuid 23
588 // generic
590 // SYS_getuid 24
591 // generic
593 // SYS_geteuid 25
594 // generic
596 // SYS_ptrace 26
597 // int ptrace(int request, pid_t pid, caddr_t addr, int data);
598 PRE(sys_ptrace)
600 struct vki_ptrace_io_desc *io_desc;
601 PRINT("sys_ptrace ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, 0x%" FMT_REGWORD "x, %" FMT_REGWORD "u)", ARG1, ARG2, ARG3, ARG4);
603 PRE_REG_READ4(int, "ptrace", int, request, pid_t, pid, caddr_t, addr, int, data);
605 switch (ARG1) {
606 case VKI_PTRACE_TRACEME:
607 case VKI_PTRACE_READ_I:
608 case VKI_PTRACE_READ_D:
609 case VKI_PTRACE_WRITE_I:
610 case VKI_PTRACE_WRITE_D:
611 break;
613 case VKI_PTRACE_IO:
614 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_ptrace_io_desc));
615 io_desc = (struct vki_ptrace_io_desc *)ARG3;
616 switch (io_desc->piod_op) {
617 case VKI_PIOD_READ_D:
618 case VKI_PIOD_READ_I:
619 PRE_MEM_WRITE( "ptrace", (UWord)io_desc->piod_addr, io_desc->piod_len);
620 break;
621 case VKI_PIOD_WRITE_D:
622 case VKI_PIOD_WRITE_I:
623 PRE_MEM_READ( "ptrace", (UWord)io_desc->piod_addr, io_desc->piod_len);
624 break;
626 break;
628 case VKI_PTRACE_CONTINUE:
629 case VKI_PTRACE_STEP:
630 case VKI_PTRACE_KILL:
631 case VKI_PTRACE_ATTACH:
632 case VKI_PTRACE_DETACH:
633 break;
635 case VKI_PTRACE_GETREGS:
636 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_user_regs_struct));
637 break;
639 case VKI_PTRACE_SETREGS:
640 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_user_regs_struct));
641 break;
643 case VKI_PTRACE_GETFPREGS:
644 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_fpreg));
645 break;
647 case VKI_PTRACE_SETFPREGS:
648 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_fpreg));
649 break;
651 case VKI_PTRACE_GETDBREGS:
652 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_dbreg));
653 break;
655 case VKI_PTRACE_SETDBREGS:
656 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_dbreg));
657 break;
659 case VKI_PTRACE_LWPINFO:
660 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_ptrace_lwpinfo));
661 break;
663 case VKI_PTRACE_GETNUMLWPS:
664 break;
666 case VKI_PTRACE_GETLWPLIST:
667 PRE_MEM_WRITE( "ptrace", ARG3, sizeof(vki_lwpid_t) * ARG4);
668 break;
670 case VKI_PTRACE_SETSTEP:
671 case VKI_PTRACE_CLEARSTEP:
672 case VKI_PTRACE_SUSPEND:
673 case VKI_PTRACE_RESUME:
674 case VKI_PTRACE_TO_SCE:
675 case VKI_PTRACE_TO_SCX:
676 case VKI_PTRACE_SYSCALL:
677 case VKI_PTRACE_VM_TIMESTAMP:
678 break;
679 case VKI_PTRACE_VM_ENTRY:
680 PRE_MEM_WRITE( "ptrace", ARG3, sizeof(struct vki_ptrace_vm_entry));
681 break;
685 POST(sys_ptrace)
687 struct vki_ptrace_io_desc *io_desc;
689 switch (ARG1) {
690 case VKI_PTRACE_TRACEME:
691 case VKI_PTRACE_READ_I:
692 case VKI_PTRACE_READ_D:
693 case VKI_PTRACE_WRITE_I:
694 case VKI_PTRACE_WRITE_D:
695 break;
697 case VKI_PTRACE_IO:
698 io_desc = (struct vki_ptrace_io_desc *)ARG3;
699 switch (io_desc->piod_op) {
700 case VKI_PIOD_READ_D:
701 case VKI_PIOD_READ_I:
702 if ((Word)RES != -1) {
703 POST_MEM_WRITE((UWord)io_desc->piod_addr, io_desc->piod_len);
705 break;
706 case VKI_PIOD_WRITE_D:
707 case VKI_PIOD_WRITE_I:
708 break;
710 break;
712 case VKI_PTRACE_CONTINUE:
713 case VKI_PTRACE_STEP:
714 case VKI_PTRACE_KILL:
715 case VKI_PTRACE_ATTACH:
716 case VKI_PTRACE_DETACH:
717 break;
719 case VKI_PTRACE_GETREGS:
720 if ((Word)RES != -1) {
721 POST_MEM_WRITE(ARG3, sizeof(struct vki_user_regs_struct));
723 break;
725 case VKI_PTRACE_SETREGS:
726 break;
728 case VKI_PTRACE_GETFPREGS:
729 if ((Word)RES != -1) {
730 POST_MEM_WRITE(ARG3, sizeof(struct vki_fpreg));
732 break;
734 case VKI_PTRACE_SETFPREGS:
735 break;
737 case VKI_PTRACE_GETDBREGS:
738 if ((Word)RES != -1) {
739 POST_MEM_WRITE(ARG3, sizeof(struct vki_dbreg));
741 break;
743 case VKI_PTRACE_SETDBREGS:
744 break;
746 case VKI_PTRACE_LWPINFO:
747 if ((Word)RES != -1) {
748 POST_MEM_WRITE(ARG3, sizeof(struct vki_ptrace_lwpinfo));
750 break;
752 case VKI_PTRACE_GETNUMLWPS:
753 break;
755 case VKI_PTRACE_GETLWPLIST:
756 if ((Word)RES != -1) {
757 POST_MEM_WRITE(ARG3, sizeof(vki_lwpid_t) * RES);
759 break;
761 case VKI_PTRACE_SETSTEP:
762 case VKI_PTRACE_CLEARSTEP:
763 case VKI_PTRACE_SUSPEND:
764 case VKI_PTRACE_RESUME:
765 case VKI_PTRACE_TO_SCE:
766 case VKI_PTRACE_TO_SCX:
767 case VKI_PTRACE_SYSCALL:
768 case VKI_PTRACE_VM_TIMESTAMP:
769 break;
771 case VKI_PTRACE_VM_ENTRY:
772 if ((Word)RES != -1) {
773 POST_MEM_WRITE(ARG3, sizeof(struct vki_ptrace_vm_entry));
775 break;
779 // SYS_recvmsg 27
780 // ssize_t recvmsg(int s, struct msghdr *msg, int flags);
781 PRE(sys_recvmsg)
783 *flags |= SfMayBlock;
784 PRINT("sys_recvmsg ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )",SARG1,ARG2,SARG3);
785 PRE_REG_READ3(vki_ssize_t, "recvmsg", int, s, struct msghdr *, msg, int, flags);
786 ML_(generic_PRE_sys_recvmsg)(tid, "recvmsg", (struct vki_msghdr *)ARG2);
789 POST(sys_recvmsg)
792 ML_(generic_POST_sys_recvmsg)(tid, "recvmsg", (struct vki_msghdr *)ARG2, RES);
795 // SYS_sendmsg 28
796 // ssize_t sendmsg(int s, const struct msghdr *msg, int flags);
797 PRE(sys_sendmsg)
799 *flags |= SfMayBlock;
800 PRINT("sys_sendmsg ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
801 PRE_REG_READ3(ssize_t, "sendmsg",
802 int, s, const struct msghdr *, msg, int, flags);
803 ML_(generic_PRE_sys_sendmsg)(tid, "sendmsg", (struct vki_msghdr *)ARG2);
806 // SYS_recvfrom 29
807 // ssize_t recvfrom(int s, void *buf, size_t len, int flags,
808 // struct sockaddr * restrict from, socklen_t * restrict fromlen);
809 PRE(sys_recvfrom)
811 *flags |= SfMayBlock;
812 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);
813 PRE_REG_READ6(ssize_t, "recvfrom",
814 int, s, void *, buf, size_t, len, int, flags,
815 struct sockaddr *, from, int *, fromlen);
816 ML_(generic_PRE_sys_recvfrom)(tid, ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
819 POST(sys_recvfrom)
821 vg_assert(SUCCESS);
822 ML_(generic_POST_sys_recvfrom)(tid, VG_(mk_SysRes_Success)(RES),
823 ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
826 // SYS_accept 30
827 // int accept(int s, struct sockaddr * restrict addr,
828 // socklen_t * restrict addrlen);
829 PRE(sys_accept)
831 *flags |= SfMayBlock;
832 PRINT("sys_accept ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
833 PRE_REG_READ3(int, "accept",
834 int, s, struct sockaddr *, addr, int, *addrlen);
835 ML_(generic_PRE_sys_accept)(tid, ARG1,ARG2,ARG3);
838 POST(sys_accept)
840 SysRes r;
841 vg_assert(SUCCESS);
842 r = ML_(generic_POST_sys_accept)(tid, VG_(mk_SysRes_Success)(RES),
843 ARG1,ARG2,ARG3);
844 SET_STATUS_from_SysRes(r);
847 // SYS_getpeername 31
848 // int getpeername(int s, struct sockaddr * restrict name,
849 // socklen_t * restrict namelen);
850 PRE(sys_getpeername)
852 PRINT("sys_getpeername ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3);
853 PRE_REG_READ3(int, "getpeername",
854 int, s, struct sockaddr *, name, socklen_t *, namelen);
855 ML_(generic_PRE_sys_getpeername)(tid, ARG1,ARG2,ARG3);
858 POST(sys_getpeername)
860 vg_assert(SUCCESS);
861 ML_(generic_POST_sys_getpeername)(tid, VG_(mk_SysRes_Success)(RES),
862 ARG1,ARG2,ARG3);
865 // SYS_getsockname 32
866 // int getsockname(int s, struct sockaddr * restrict name,
867 // socklen_t * restrict namelen);
868 PRE(sys_getsockname)
870 PRINT("sys_getsockname ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",SARG1,ARG2,ARG3);
871 PRE_REG_READ3(long, "getsockname",
872 int, s, struct sockaddr *, name, int *, namelen);
873 ML_(generic_PRE_sys_getsockname)(tid, ARG1,ARG2,ARG3);
876 POST(sys_getsockname)
878 vg_assert(SUCCESS);
879 ML_(generic_POST_sys_getsockname)(tid, VG_(mk_SysRes_Success)(RES),
880 ARG1,ARG2,ARG3);
883 // SYS_access 33
884 // generic
886 // SYS_chflags 34
887 // int chflags(const char *path, unsigned long flags)
888 PRE(sys_chflags)
890 PRINT("sys_chflags ( %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2);
891 PRE_REG_READ2(int, "chflags",
892 const char *, path, unsigned long, flags);
893 PRE_MEM_RASCIIZ( "chflags(path)", ARG1 );
896 // SYS_fchflags 35
897 // int fchflags(int fd, unsigned long flags);
898 PRE(sys_fchflags)
900 PRINT("sys_fchflags ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2);
901 PRE_REG_READ2(int, "fchflags", int, fd, unsigned long, flags);
904 // SYS_sync 36
905 // generic
907 // SYS_kill 37
908 // generic
910 // SYS_getppid 39
911 // generic
913 // SYS_dup 41
914 // generic
916 // Pipe on freebsd doesn't have args, and uses dual returns!
917 // SYS_freebsd10_pipe 42
918 // int pipe(void);
919 PRE(sys_pipe)
921 PRINT("%s", "sys_pipe ()");
924 POST(sys_pipe)
926 if (!ML_(fd_allowed)(RES, "pipe", tid, True) ||
927 !ML_(fd_allowed)(RESHI, "pipe", tid, True)) {
928 VG_(close)(RES);
929 VG_(close)(RESHI);
930 SET_STATUS_Failure( VKI_EMFILE );
931 } else {
932 if (VG_(clo_track_fds)) {
933 ML_(record_fd_open_nameless)(tid, RES);
934 ML_(record_fd_open_nameless)(tid, RESHI);
939 // SYS_getegid 43
940 // generic
942 // SYS_profil 44
943 // generic
945 // SYS_ktrace 45
946 // generic
948 // SYS_getgid 47
949 // generic
951 // SYS_getlogin 49
952 // syscall.master refers to namelen and namebuf for the argument names
953 // man getlogin has just getlogin(void) but also
954 // int getlogin_r(char *name, int len);
955 // so let's go with those names
956 PRE(sys_getlogin)
958 PRINT("sys_getlogin ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2);
959 PRE_REG_READ2(int, "getlogin", char *, buf, u_int, len);
960 PRE_MEM_WRITE( "getlogin(name)", ARG1, ARG2 );
963 POST(sys_getlogin)
965 POST_MEM_WRITE(ARG1, ARG2 );
968 // SYS_setlogin 50
969 // int setlogin(const char *name);
970 PRE(sys_setlogin)
972 PRINT("sys_setlogin ( %#" FMT_REGWORD "x )",ARG1);
973 PRE_REG_READ1(long, "setlogin", char *, buf);
974 PRE_MEM_RASCIIZ( "setlogin(buf)", ARG1 );
977 // SYS_acct 51
978 // generic
980 // SYS_sigaltstack 53
981 // generic
983 // SYS_ioctl 54
984 // int ioctl(int fd, unsigned long request, ...);
985 PRE(sys_ioctl)
987 *flags |= SfMayBlock;
988 // @todo PJF presumably the presence of ARG3 depends on ARG2
989 PRINT("sys_ioctl ( %" FMT_REGWORD "u, 0x%" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3);
990 PRE_REG_READ3(int, "ioctl",
991 int, fd, unsigned long, request, unsigned long, arg);
993 switch (ARG2) {
994 case VKI_FIODGNAME: {
995 struct vki_fiodgname_arg* data = (struct vki_fiodgname_arg*)(Addr)ARG3;
996 PRE_FIELD_READ("ioctl(FIODGNAME).len", data->len);
997 PRE_FIELD_READ("ioctl(FIODGNAME).buf", data->buf);
998 PRE_MEM_WRITE("ioctl(FIODGNAME).buf", (Addr)data->buf, data->len);
999 break;
1001 default:
1002 ML_(PRE_unknown_ioctl)(tid, ARG2, ARG3);
1003 break;
1006 // The block below is from Ryan Stone
1007 // https://bitbucket.org/rysto32/valgrind-freebsd/commits/5323c22be9f6c71a00e842c3ddfa1fa8a7feb279
1008 // however it drags in hundreds of lines of headers into vki-freebsd.h.
1009 // How stable are these structures? -> maintainability is a concern
1010 // Also there are no testcases for this.
1011 // Hence #if 0
1012 #if 0
1013 /* Handle specific ioctls which pass structures which may have pointers to other
1014 buffers */
1015 switch (ARG2 /* request */) {
1016 case VKI_SIOCGIFMEDIA:
1017 if (ARG3) {
1018 struct vki_ifmediareq* imr = (struct vki_ifmediareq*)ARG3;
1019 if (imr->ifm_ulist) {
1020 PRE_MEM_WRITE("ioctl(SIOCGIFMEDIA).ifm_ulist",
1021 (Addr)(imr->ifm_ulist), imr->ifm_count * sizeof(int));
1024 break;
1026 case VKI_PCIOCGETCONF:
1027 if (ARG3) {
1028 struct vki_pci_conf_io* pci = (struct vki_pci_conf_io*)ARG3;
1029 PRE_MEM_READ("ioctl(PCIOCGETCONF).patterns",
1030 (Addr)(pci->patterns), pci->pat_buf_len);
1031 PRE_MEM_WRITE("ioctl(PCIOCGETCONF).matches",
1032 (Addr)(pci->matches), pci->match_buf_len);
1034 break;
1036 case VKI_CAMIOCOMMAND:
1037 if (ARG3) {
1038 union vki_ccb* ccb = (union vki_ccb*)ARG3;
1039 if (ccb->ccb_h.func_code == VKI_XPT_DEV_MATCH) {
1040 PRE_MEM_WRITE("ioctl(CAMIOCOMMAND:XPT_DEV_MATCH).matches",
1041 (Addr)(ccb->cdm.matches), ccb->cdm.match_buf_len);
1042 } else if (ccb->ccb_h.func_code == VKI_XPT_SCSI_IO) {
1043 struct vki_ccb_scsiio* scsiio = (struct vki_ccb_scsiio*)ccb;
1044 if (scsiio->dxfer_len) {
1045 if ((scsiio->ccb_h.flags & VKI_CAM_DIR_MASK) == VKI_CAM_DIR_IN) {
1046 PRE_MEM_WRITE("ioctl(CAMIOCOMMAND:XPT_SCSI_IO).data_ptr",
1047 (Addr)(scsiio->data_ptr), scsiio->dxfer_len);
1048 } else if ((scsiio->ccb_h.flags & VKI_CAM_DIR_MASK) == VKI_CAM_DIR_OUT) {
1049 PRE_MEM_READ("ioctl(CAMIOCOMMAND:XPT_SCSI_IO).data_ptr",
1050 (Addr)(scsiio->data_ptr), scsiio->dxfer_len);
1053 } else if (ccb->ccb_h.func_code == VKI_XPT_GDEV_TYPE ||
1054 ccb->ccb_h.func_code == VKI_XPT_PATH_INQ ||
1055 ccb->ccb_h.func_code == VKI_XPT_GET_TRAN_SETTINGS) {
1056 // do nothing
1057 } else {
1058 VG_(message)(Vg_UserMsg,
1059 "Warning: unhandled ioctl CAMIOCOMMAND function 0x%lx\n",
1060 ccb->ccb_h.func_code);
1063 break;
1065 #endif
1068 POST(sys_ioctl)
1070 switch (ARG2) {
1071 case VKI_FIODGNAME: {
1072 struct vki_fiodgname_arg* data = (struct vki_fiodgname_arg*)(Addr)ARG3;
1073 POST_MEM_WRITE((Addr)data->buf, data->len);
1074 break;
1076 default:
1077 ML_(POST_unknown_ioctl)(tid, RES, ARG2, ARG3);
1078 break;
1081 #if 0
1082 /* Handle specific ioctls which pass structures which may have pointers to other
1083 buffers */
1084 switch (ARG2 /* request */) {
1085 case VKI_SIOCGIFMEDIA:
1086 if (ARG3) {
1087 struct vki_ifmediareq* imr = (struct vki_ifmediareq*)ARG3;
1088 if (imr->ifm_ulist) {
1089 POST_MEM_WRITE((Addr)(imr->ifm_ulist), imr->ifm_count * sizeof(int));
1092 break;
1094 case VKI_PCIOCGETCONF:
1095 if (ARG3) {
1096 struct vki_pci_conf_io* pci = (struct vki_pci_conf_io*)ARG3;
1097 POST_MEM_WRITE((Addr)(pci->matches), pci->num_matches * sizeof(struct vki_pci_conf));
1099 break;
1101 case VKI_CAMIOCOMMAND:
1102 if (ARG3) {
1103 union vki_ccb* ccb = (union vki_ccb*)ARG3;
1104 if (ccb->ccb_h.func_code == VKI_XPT_DEV_MATCH) {
1105 POST_MEM_WRITE((Addr)(ccb->cdm.matches), ccb->cdm.num_matches*sizeof(struct vki_dev_match_result));
1106 } else if (ccb->ccb_h.func_code == VKI_XPT_SCSI_IO) {
1107 struct vki_ccb_scsiio* scsiio = (struct vki_ccb_scsiio*)ccb;
1108 if (scsiio->dxfer_len) {
1109 if ((scsiio->ccb_h.flags & VKI_CAM_DIR_MASK) == VKI_CAM_DIR_IN) {
1110 POST_MEM_WRITE((Addr)(scsiio->data_ptr), scsiio->dxfer_len);
1115 break;
1117 #endif
1120 // SYS_reboot 55
1121 // int reboot(int howto);
1122 PRE(sys_reboot)
1124 PRINT("sys_reboot ( %" FMT_REGWORD "d )", SARG1);
1125 PRE_REG_READ1(int, "reboot", int, howto);
1128 // SYS_revoke 56
1129 // int revoke(const char *path);
1130 PRE(sys_revoke)
1132 PRINT("sys_revoke ( %#" FMT_REGWORD "x(%s) )", ARG1, (char*)ARG1);
1133 PRE_REG_READ1(long, "revoke", const char *, path);
1134 PRE_MEM_RASCIIZ( "revoke(path)", ARG1);
1137 // SYS_symlink 57
1138 // generic
1140 static void do_readlink(const HChar* path, HChar *buf, SizeT bufsize, SyscallStatus* status, Bool* curproc_file)
1142 HChar name[30];
1143 VG_(sprintf)(name, "/proc/%d/file", VG_(getpid)());
1144 if (ML_(safe_to_deref)(path, 1)
1145 && (VG_(strcmp)(path, name) == 0
1146 || VG_(strcmp)(path, "/proc/curproc/file") == 0)) {
1147 vg_assert(VG_(resolved_exename));
1148 Int len = VG_(snprintf)(buf, bufsize, "%s", VG_(resolved_exename));
1149 SET_STATUS_Success(len);
1150 *curproc_file = True;
1154 // SYS_readlink 58
1155 // ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsiz);
1156 PRE(sys_readlink)
1158 FUSE_COMPATIBLE_MAY_BLOCK();
1159 Word saved = SYSNO;
1160 Bool curproc_file = False;
1162 PRINT("sys_readlink ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %llu )",
1163 ARG1, (char*)(Addr)ARG1, ARG2, (ULong)ARG3);
1164 PRE_REG_READ3(long, "readlink",
1165 const char *, path, char *, buf, int, bufsiz);
1166 PRE_MEM_RASCIIZ( "readlink(path)", ARG1 );
1167 PRE_MEM_WRITE( "readlink(buf)", ARG2,ARG3 );
1169 if (VG_(have_slash_proc) == True)
1172 * Handle the case where readlink is looking at /proc/curproc/file or
1173 * /proc/<pid>/file
1175 do_readlink((const HChar *)ARG1, (HChar *)ARG2, (SizeT)ARG3, status, &curproc_file);
1178 if (!curproc_file) {
1179 /* Normal case */
1180 SET_STATUS_from_SysRes( VG_(do_syscall3)(saved, ARG1, ARG2, ARG3));
1182 if (SUCCESS && RES > 0) {
1183 POST_MEM_WRITE( ARG2, RES );
1187 // SYS_execve 59
1188 // generic
1190 // SYS_umask 60
1191 // generic
1193 // SYS_chroot 61
1194 // generic
1196 // SYS_msync 65
1197 // generic
1199 // SYS_vfork 66
1200 // pid_t vfork(void);
1201 PRE(sys_vfork)
1203 PRINT("%s", "sys_vfork ()");
1204 PRE_REG_READ0(pid_t, "vfork");
1206 /* Pretend vfork == fork. Not true, but will have to do. */
1207 SET_STATUS_from_SysRes( ML_(do_fork)(tid) );
1208 if (SUCCESS) {
1209 /* Thread creation was successful; let the child have the chance
1210 to run */
1211 *flags |= SfYieldAfter;
1215 // SYS_sbrk 69
1216 // void * sbrk(intptr_t incr);
1217 PRE(sys_sbrk)
1219 PRINT("sys_sbrk ( %#" FMT_REGWORD "x )",ARG1);
1220 PRE_REG_READ1(void*, "sbrk", vki_intptr_t, incr);
1223 // SYS_freebsd11_vadvise 72
1224 // @todo maybe
1226 // SYS_munmap 73
1227 // generic
1229 // SYS_mprotect 74
1230 // generic
1232 // SYS_madvise 75
1233 // generic
1235 // SYS_mincore 78
1236 // generic
1238 // SYS_getgroups 79
1239 // generic
1241 // SYS_setgroups 80
1242 // generic
1244 // SYS_getpgrp 81
1245 // generic
1247 // SYS_setpgid 82
1248 // generic
1250 // SYS_setitimer 83
1251 // generic
1253 // SYS_swapon 85
1254 // int swapon(const char *special);
1255 PRE(sys_swapon)
1257 PRINT("sys_swapon ( %#" FMT_REGWORD "x(%s) )", ARG1,(char*)ARG1);
1258 PRE_REG_READ1(int, "swapon", const char*, special );
1259 PRE_MEM_RASCIIZ( "swapon(special)", ARG1 );
1262 // SYS_getitimer 86
1263 // generic
1265 // SYS_getdtablesize 89
1266 // int getdtablesize(void);
1267 PRE(sys_getdtablesize)
1269 PRINT("%s", "sys_getdtablesize ( )");
1270 PRE_REG_READ0(long, "getdtablesize");
1273 // SYS_dup2 90
1274 // generic
1276 // SYS_fcntl 92
1277 // int fcntl(int fd, int cmd, ...);
1278 PRE(sys_fcntl)
1280 switch (ARG2) {
1281 // These ones ignore ARG3.
1282 case VKI_F_GETFD:
1283 case VKI_F_GETFL:
1284 case VKI_F_GETOWN:
1285 case VKI_F_GET_SEALS:
1286 case VKI_F_ISUNIONSTACK:
1287 PRINT("sys_fcntl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,SARG2);
1288 PRE_REG_READ2(int, "fcntl", int, fd, int, cmd);
1289 break;
1291 // These ones use ARG3 as "arg".
1292 case VKI_F_DUPFD:
1293 case VKI_F_DUPFD_CLOEXEC:
1294 case VKI_F_SETFD:
1295 case VKI_F_SETFL:
1296 case VKI_F_SETOWN:
1297 case VKI_F_READAHEAD:
1298 case VKI_F_RDAHEAD:
1299 case VKI_F_ADD_SEALS:
1300 PRINT("sys_fcntl[ARG3=='arg'] ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,SARG2,SARG3);
1301 PRE_REG_READ3(int, "fcntl",
1302 int, fd, int, cmd, int, arg);
1303 break;
1305 // These ones use ARG3 as "lock" - obsolete.
1306 case VKI_F_OSETLKW:
1307 *flags |= SfMayBlock;
1308 /* FALLTHROUGH */
1309 case VKI_F_OGETLK:
1310 case VKI_F_OSETLK:
1311 PRINT("sys_fcntl[ARG3=='lock'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
1312 PRE_REG_READ3(int, "fcntl",
1313 int, fd, int, cmd,
1314 struct oflock *, lock);
1315 break;
1317 // This one uses ARG3 as "oldd" and ARG4 as "newd".
1318 case VKI_F_DUP2FD:
1319 case VKI_F_DUP2FD_CLOEXEC:
1320 PRINT("sys_fcntl[ARG3=='oldd', ARG4=='newd'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",
1321 ARG1,ARG2,ARG3,ARG4);
1322 PRE_REG_READ4(int, "fcntl",
1323 int, fd, int, cmd,
1324 unsigned long, oldd, unsigned long, newd);
1325 break;
1327 // These ones use ARG3 as "lock".
1328 case VKI_F_SETLKW:
1329 *flags |= SfMayBlock;
1330 /* FALLTHROUGH */
1331 case VKI_F_GETLK:
1332 case VKI_F_SETLK:
1333 case VKI_F_SETLK_REMOTE:
1334 PRINT("sys_fcntl[ARG3=='lock'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
1335 PRE_REG_READ3(int, "fcntl",
1336 int, fd, int, cmd,
1337 struct flock *, lock);
1338 break;
1339 case VKI_F_KINFO:
1340 PRINT("sys_fcntl[ARG3=='kinfo_file'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
1341 PRE_REG_READ3(int, "fcntl",
1342 int, fd, int, cmd,
1343 struct vki_kinfo_file *, kinfo);
1344 if (ARG3) {
1345 struct vki_kinfo_file* p_kinfo_file = (struct vki_kinfo_file*)ARG3;
1346 PRE_MEM_WRITE("fcntl(ARG3=='kinfo_file)", ARG3, p_kinfo_file->vki_kf_structsize);
1348 break;
1350 default:
1351 PRINT("sys_fcntl[UNKNOWN] ( %lu, %lu, %lu )", ARG1,ARG2,ARG3);
1352 I_die_here;
1356 POST(sys_fcntl)
1358 vg_assert(SUCCESS);
1359 if (ARG2 == VKI_F_DUPFD) {
1360 if (!ML_(fd_allowed)(RES, "fcntl(DUPFD)", tid, True)) {
1361 VG_(close)(RES);
1362 SET_STATUS_Failure( VKI_EMFILE );
1363 } else {
1364 if (VG_(clo_track_fds)) {
1365 ML_(record_fd_open_named)(tid, RES);
1368 } else if (ARG2 == VKI_F_DUPFD_CLOEXEC) {
1369 if (!ML_(fd_allowed)(RES, "fcntl(DUPFD_CLOEXEC)", tid, True)) {
1370 VG_(close)(RES);
1371 SET_STATUS_Failure( VKI_EMFILE );
1372 } else {
1373 if (VG_(clo_track_fds)) {
1374 ML_(record_fd_open_named)(tid, RES);
1380 // SYS_select 93
1381 // generic
1383 // SYS_fsync 95
1384 // generic
1386 // SYS_setpriority 9
1387 // generic
1389 // SYS_socket 97
1390 // int socket(int domain, int type, int protocol);
1391 PRE(sys_socket)
1393 PRINT("sys_socket ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %" FMT_REGWORD "d )",SARG1,SARG2,SARG3);
1394 PRE_REG_READ3(int, "socket", int, domain, int, type, int, protocol);
1397 POST(sys_socket)
1399 SysRes r;
1400 vg_assert(SUCCESS);
1401 r = ML_(generic_POST_sys_socket)(tid, VG_(mk_SysRes_Success)(RES));
1402 SET_STATUS_from_SysRes(r);
1405 // SYS_connect 98
1406 // int connect(int s, const struct sockaddr *name, socklen_t namelen);
1407 PRE(sys_connect)
1409 *flags |= SfMayBlock;
1410 PRINT("sys_connect ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
1411 PRE_REG_READ3(int, "connect",
1412 int, s, const struct sockaddr *, name, int, namelen);
1413 ML_(generic_PRE_sys_connect)(tid, ARG1,ARG2,ARG3);
1416 // SYS_getpriority 100
1417 // generic
1419 // SYS_bind 104
1420 // int bind(int s, const struct sockaddr *addr, socklen_t addrlen);
1421 PRE(sys_bind)
1423 PRINT("sys_bind ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
1424 PRE_REG_READ3(int, "bind",
1425 int, s, struct sockaddr *, addr, int, addrlen);
1426 ML_(generic_PRE_sys_bind)(tid, ARG1,ARG2,ARG3);
1429 // SYS_setsockopt 105
1430 // int setsockopt(int s, int level, int optname, const void *optval,
1431 // socklen_t optlen);
1432 PRE(sys_setsockopt)
1434 PRINT("sys_setsockopt ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",SARG1,SARG2,SARG3,ARG4,ARG5);
1435 PRE_REG_READ5(int, "setsockopt",
1436 int, s, int, level, int, optname,
1437 const void *, optval, vki_socklen_t, optlen);
1438 ML_(generic_PRE_sys_setsockopt)(tid, ARG1,ARG2,ARG3,ARG4,ARG5);
1441 // SYS_listen 106
1442 // int listen(int s, int backlog);
1443 PRE(sys_listen)
1445 PRINT("sys_listen ( %" FMT_REGWORD "d, %" FMT_REGWORD "d )",SARG1,SARG2);
1446 PRE_REG_READ2(int, "listen", int, s, int, backlog);
1449 //SYS_gettimeofday 116
1450 // generic
1452 // SYS_getrusage 117
1453 // generic
1455 // SYS_getsockopt 118
1456 // int getsockopt(int s, int level, int optname, void * restrict optval,
1457 // socklen_t * restrict optlen);
1458 PRE(sys_getsockopt)
1460 Addr optval_p = ARG4;
1461 Addr optlen_p = ARG5;
1462 PRINT("sys_getsockopt ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4,ARG5);
1463 PRE_REG_READ5(int, "getsockopt",
1464 int, s, int, level, int, optname,
1465 void *, optval, int, *optlen);
1466 if (optval_p != (Addr)NULL) {
1467 ML_(buf_and_len_pre_check) ( tid, optval_p, optlen_p,
1468 "getsockopt(optval)",
1469 "getsockopt(optlen)" );
1473 POST(sys_getsockopt)
1475 Addr optval_p = ARG4;
1476 Addr optlen_p = ARG5;
1477 vg_assert(SUCCESS);
1478 if (optval_p != (Addr)NULL) {
1479 ML_(buf_and_len_post_check) ( tid, VG_(mk_SysRes_Success)(RES),
1480 optval_p, optlen_p,
1481 "getsockopt(optlen_out)" );
1485 // SYS_readv 120
1486 // generic
1488 // SYS_writev 121
1489 // generic
1491 // SYS_settimeofday 122
1492 // generic
1494 // SYS_fchown 123
1495 // generic
1497 // SYS_fchmod 124
1498 // generic
1500 // SYS_setreuid 126
1501 // generic
1503 // SYS_setregid 127
1504 // generic
1506 // SYS_rename 128
1507 // generic
1509 // SYS_flock 131
1510 // generic
1512 // SYS_mkfifo 132
1513 // int mkfifo(const char *path, mode_t mode);
1514 PRE(sys_mkfifo)
1516 PRINT("sys_mkfifo ( %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x, 0x%" FMT_REGWORD "x )", ARG1, (char *)ARG1, ARG2, ARG3 );
1517 PRE_REG_READ2(int, "mkfifo", const char *, path, int, mode);
1518 PRE_MEM_RASCIIZ( "mkfifo(path)", ARG1 );
1521 // SYS_sendto 133
1522 // ssize_t sendto(int s, const void *msg, size_t len, int flags,
1523 // const struct sockaddr *to, socklen_t tolen);
1524 PRE(sys_sendto)
1526 *flags |= SfMayBlock;
1527 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);
1528 PRE_REG_READ6(ssize_t, "sendto",
1529 int, s, const void *, msg, int, len,
1530 int, flags,
1531 const struct sockaddr *, to, socklen_t, tolen);
1532 ML_(generic_PRE_sys_sendto)(tid, ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
1535 // SYS_shutdown 134
1536 // int shutdown(int s, int how);
1537 PRE(sys_shutdown)
1539 *flags |= SfMayBlock;
1540 PRINT("sys_shutdown ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2);
1541 PRE_REG_READ2(int, "shutdown", int, s, int, how);
1544 // SYS_socketpair 135
1545 // int socketpair(int domain, int type, int protocol, int *sv);
1546 PRE(sys_socketpair)
1548 PRINT("sys_socketpair ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
1549 PRE_REG_READ4(int, "socketpair",
1550 int, domain, int, type, int, protocol, int *, sv);
1551 ML_(generic_PRE_sys_socketpair)(tid, ARG1,ARG2,ARG3,ARG4);
1554 POST(sys_socketpair)
1556 vg_assert(SUCCESS);
1557 ML_(generic_POST_sys_socketpair)(tid, VG_(mk_SysRes_Success)(RES),
1558 ARG1,ARG2,ARG3,ARG4);
1561 // SYS_mkdir 136
1562 // generic
1564 // SYS_rmdir 137
1565 // generic
1567 // SYS_utimes 138
1568 // generic
1570 // SYS_adjtime 140
1571 // int adjtime(const struct timeval *delta, struct timeval *olddelta);
1572 PRE(sys_adjtime)
1574 PRINT("sys_adjtime ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
1575 PRE_REG_READ2(int, "adjtime",
1576 const struct vki_timeval *, delta, struct vki_timeval *, olddelta);
1577 PRE_MEM_READ("adjtime(delta)", ARG1, sizeof(struct vki_timeval));
1578 if (ARG2) {
1579 PRE_MEM_WRITE("adjtime(olddelta)", ARG1, sizeof(struct vki_timeval));
1583 POST(sys_adjtime)
1585 if (ARG2) {
1586 POST_MEM_WRITE(ARG1, sizeof(struct vki_timeval));
1590 // SYS_setsid 147
1591 // generic
1593 // SYS_quotactl 148
1594 /* int quotactl(const char *path, int cmd, int id, void *addr); */
1595 PRE(sys_quotactl)
1597 PRINT("sys_quotactl ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3, ARG4);
1598 switch (ARG2) {
1599 case VKI_Q_QUOTAON:
1600 case VKI_Q_SETQUOTA:
1601 case VKI_Q_SETUSE:
1603 case VKI_Q_GETQUOTASIZE:
1604 PRE_REG_READ4(int, "quotactl",
1605 const char *, path, int, cmd, int, id,
1606 void *, addr);
1607 PRE_MEM_RASCIIZ( "quotactl(path)", ARG1 );
1608 break;
1609 case VKI_Q_GETQUOTA:
1610 if (VG_(tdict).track_pre_reg_read) {
1612 PRRSN;
1613 PRA1("quotactl",const char*,path);
1614 PRA2("quotactl",int,cmd);
1615 PRA4("quotactl",void*,addr);
1617 break;
1618 case VKI_Q_QUOTAOFF:
1619 case VKI_Q_SYNC:
1620 PRE_REG_READ2(int, "quotactl",
1621 const char *, path, int, cmd);
1622 break;
1623 default:
1624 break;
1628 // SYS_nlm_syscall 154
1629 // syscall.master says ; 154 is initialised by the NLM code, if present.
1630 // @todo
1632 // SYS_nfssvc 155
1633 // int nfssvc(int flags, void *argstructp);
1634 // lengthy manpage, at least 3 types of struct that argstructp can point to
1635 // @todo
1637 // SYS_lgetfh 160
1638 // int lgetfh(const char *path, fhandle_t *fhp);
1639 PRE(sys_lgetfh)
1641 PRINT("sys_lgetfh ( %#" FMT_REGWORD "x, %" FMT_REGWORD "x ", ARG1, ARG2);
1642 PRE_REG_READ2(int, "lgetfh", const char*, path, vki_fhandle_t*, fhp);
1643 PRE_MEM_RASCIIZ( "lgetfh(path)", ARG1 );
1644 PRE_MEM_WRITE("lgetfh(fhp)", ARG2, sizeof(vki_fhandle_t));
1647 POST(sys_lgetfh)
1649 POST_MEM_WRITE(ARG2, sizeof(vki_fhandle_t));
1652 // SYS_getfh 161
1653 // int getfh(const char *path, fhandle_t *fhp);
1654 PRE(sys_getfh)
1656 PRINT("sys_getfh ( %#" FMT_REGWORD "x, %" FMT_REGWORD "x ", ARG1, ARG2);
1657 PRE_REG_READ2(int, "getfh", const char*, path, vki_fhandle_t*, fhp);
1658 PRE_MEM_RASCIIZ( "getfh(path)", ARG1 );
1659 PRE_MEM_WRITE("getfh(fhp)", ARG2, sizeof(vki_fhandle_t));
1662 POST(sys_getfh)
1664 POST_MEM_WRITE(ARG2, sizeof(vki_fhandle_t));
1667 #if (FREEBSD_VERS <= FREEBSD_10)
1668 // 162
1669 // int getdomainname(char *domainname, int len);
1670 PRE(sys_freebsd4_getdomainname)
1672 PRINT("sys_freebsd4_getdomainname ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2);
1673 PRE_REG_READ2(int, "getdomainname",
1674 char *, domainname, int, len);
1675 PRE_MEM_WRITE( "getdomainname(domainname)", ARG1, ARG2 );
1678 POST(sys_freebsd4_getdomainname)
1680 if (ARG1 != 0) {
1681 POST_MEM_WRITE( ARG1, ARG2 );
1685 // 163
1686 // int setdomainname(char *domainname, int len);
1687 PRE(sys_freebsd4_setdomainname)
1689 PRINT("sys_freebsd4_setdomainname ( %#" FMT_REGWORD "x )",ARG1);
1690 PRE_REG_READ2(int, "setdomainname", char *, domainname, int, len);
1691 PRE_MEM_RASCIIZ( "setdomainname(domainname)", ARG1 );
1694 // 164
1695 // int uname(struct utsname *name);
1696 PRE(sys_freebsd4_uname)
1698 PRINT("sys_freebsd4_uname ( %#" FMT_REGWORD "x )", ARG1);
1699 PRE_REG_READ1(int, "uname", struct utsname *, name);
1700 PRE_MEM_WRITE( "uname(name)", ARG1, sizeof(struct vki_utsname) );
1703 POST(sys_freebsd4_uname)
1705 if (ARG1 != 0) {
1706 POST_MEM_WRITE( ARG1, sizeof(struct vki_utsname) );
1709 #endif
1711 // SYS_sysarch 165
1712 // x86/amd64
1714 // SYS_rtprio 166
1715 PRE(sys_rtprio)
1717 PRINT( "sys_rtprio ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1, ARG2, ARG3 );
1718 PRE_REG_READ3(int, "rtprio",
1719 int, function, pid_t, pid, struct rtprio *, rtp);
1720 if (ARG1 == VKI_RTP_SET) {
1721 PRE_MEM_READ( "rtprio(rtp#set)", ARG3, sizeof(struct vki_rtprio));
1722 } else if (ARG1 == VKI_RTP_LOOKUP) {
1723 PRE_MEM_WRITE( "rtprio(rtp#lookup)", ARG3, sizeof(struct vki_rtprio));
1724 } else {
1725 /* PHK ?? */
1729 POST(sys_rtprio)
1731 if (ARG1 == VKI_RTP_LOOKUP && RES == 0) {
1732 POST_MEM_WRITE( ARG3, sizeof(struct vki_rtprio));
1736 // freebsd6_pread 173 FREEBSD_VERS <= 10
1737 // x86/amd64
1739 // freebsd6_pwrite 174 FREEBSD_VERS <= 10
1740 // x86/amd64
1742 // SYS_setfib 175
1743 // int setfib(int fib);
1744 PRE(sys_setfib)
1746 PRINT("sys_setfib ( %" FMT_REGWORD "d )", SARG1);
1747 PRE_REG_READ1(int, "setfib", int, fib);
1750 // SYS_ntp_adjtime 176
1751 // int ntp_adjtime(struct timex *);
1752 // @todo
1754 // SYS_setgid 181
1755 // generic
1757 // SYS_setegid 182
1758 // int setegid(gid_t egid);
1759 PRE(sys_setegid)
1761 PRINT("sys_setegid ( %" FMT_REGWORD "u )", ARG1);
1762 PRE_REG_READ1(int, "setegid", vki_gid_t, gid);
1765 // SYS_seteuid 183
1766 // int seteuid(uid_t euid);
1767 PRE(sys_seteuid)
1769 PRINT("sys_seteuid ( %" FMT_REGWORD "u )", ARG1);
1770 PRE_REG_READ1(long, "seteuid", vki_uid_t, uid);
1774 #if (FREEBSD_VERS >= FREEBSD_12)
1776 // SYS_freebsd11_stat 188
1777 // int stat(char *path, struct freebsd11_stat *sb);
1778 PRE(sys_freebsd11_stat)
1780 PRINT("sys_freebsd11_stat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1781 PRE_REG_READ2(int, "stat", char *, path, struct freebsd11_stat *, sb);
1782 PRE_MEM_RASCIIZ( "stat(path)", ARG1 );
1783 PRE_MEM_WRITE( "stat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1786 POST(sys_freebsd11_stat)
1788 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1791 // SYS_freebsd11_fstat 189
1792 // int fstat(int fd, struct stat *sb);
1793 PRE(sys_freebsd11_fstat)
1795 PRINT("sys_freebsd11_fstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
1796 PRE_REG_READ2(int, "fstat", int, fd, struct stat *, sb);
1797 PRE_MEM_WRITE( "fstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1800 POST(sys_freebsd11_fstat)
1802 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1805 // SYS_freebsd11_lstat 190
1806 // int lstat(const char * restrict path, struct stat * restrict sb);
1807 PRE(sys_freebsd11_lstat)
1809 PRINT("sys_freebsd11_lstat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1810 PRE_REG_READ2(sb, "lstat", const char *, path, struct freebsd11_stat *, sb);
1811 PRE_MEM_RASCIIZ( "lstat(path)", ARG1 );
1812 PRE_MEM_WRITE( "lstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1815 POST(sys_freebsd11_lstat)
1817 vg_assert(SUCCESS);
1818 if (RES == 0) {
1819 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1823 #else
1825 PRE(sys_stat)
1827 PRINT("sys_stat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1828 PRE_REG_READ2(int, "stat", char *, path, struct stat *, sb);
1829 PRE_MEM_RASCIIZ( "stat(path)", ARG1 );
1830 PRE_MEM_WRITE( "stat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1833 POST(sys_stat)
1835 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1839 PRE(sys_fstat)
1841 PRINT("sys_fstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
1842 PRE_REG_READ2(int, "fstat", int, fd, struct stat *, sb);
1843 PRE_MEM_WRITE( "fstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1846 POST(sys_fstat)
1848 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1851 PRE(sys_lstat)
1853 PRINT("sys_lstat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1854 PRE_REG_READ2(int, "lstat", const char *, path, struct stat *, sb);
1855 PRE_MEM_RASCIIZ( "lstat(path)", ARG1 );
1856 PRE_MEM_WRITE( "lstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1859 POST(sys_lstat)
1861 vg_assert(SUCCESS);
1862 if (RES == 0) {
1863 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1867 #endif
1869 // SYS_pathconf 191
1870 // long pathconf(const char *path, int name);
1871 PRE(sys_pathconf)
1873 PRINT("sys_pathconf ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )",ARG1,(char *)ARG1,ARG2);
1874 PRE_REG_READ2(long, "pathconf", char *, path, int, name);
1875 PRE_MEM_RASCIIZ( "pathconf(path)", ARG1 );
1878 // SYS_fpathconf 192
1879 // long fpathconf(int fd, int name);
1880 PRE(sys_fpathconf)
1882 PRINT("sys_fpathconf ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2);
1883 PRE_REG_READ2(long, "fpathconf", int, fd, int, name);
1886 // SYS_getrlimit 194
1887 // generic
1889 // SYS_setrlimit 195
1890 // generic
1893 // SYS_freebsd11_getdirentries 196
1894 // int getdirentries(int fd, char *buf, int nbytes, long *basep);
1895 #if (FREEBSD_VERS >= FREEBSD_12)
1896 PRE(sys_freebsd11_getdirentries)
1898 *flags |= SfMayBlock;
1899 PRINT("sys_freebsd11_getdirentries ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
1900 PRE_REG_READ4(int, "getdirentries",
1901 int, fd, char *, buf,
1902 int, nbytes,
1903 long *, basep);
1904 PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 );
1905 if (ARG4) {
1906 PRE_MEM_WRITE( "getdirentries(basep)", ARG4, sizeof(long) );
1910 POST(sys_freebsd11_getdirentries)
1912 vg_assert(SUCCESS);
1913 if (RES > 0) {
1914 POST_MEM_WRITE( ARG2, RES );
1915 if ( ARG4 != 0 ) {
1916 POST_MEM_WRITE( ARG4, sizeof (long));
1920 #else
1921 PRE(sys_getdirentries)
1923 *flags |= SfMayBlock;
1924 PRINT("sys_getdirentries ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
1925 PRE_REG_READ4(int, "getdirentries",
1926 int, fd, char *, buf,
1927 int, nbytes,
1928 long *, basep);
1929 PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 );
1930 if (ARG4)
1931 PRE_MEM_WRITE( "getdirentries(basep)", ARG4, sizeof(long) );
1934 POST(sys_getdirentries)
1936 vg_assert(SUCCESS);
1937 if (RES > 0) {
1938 POST_MEM_WRITE( ARG2, RES );
1939 if ( ARG4 != 0 )
1940 POST_MEM_WRITE( ARG4, sizeof (long));
1943 #endif
1945 // SYS_freebsd6_mmap 197
1946 // amd64 / x86
1949 // SYS___syscall 198
1950 // special handling
1952 // freebsd6_lseek 199 FREEBSD_VERS <= 10
1953 // x86/amd64
1955 // freebsd6_truncate 200 FREEBSD_VERS <= 10
1956 // x86/amd64
1958 // freebsd6_ftruncate 201 FREEBSD_VERS <= 10
1959 // x86/amd64
1961 static Bool sysctl_kern_ps_strings(SizeT* out, SizeT* outlen)
1963 Word tmp = -1;
1964 const struct auxv *cauxv;
1966 for (cauxv = (struct auxv*)VG_(client_auxv); cauxv->a_type != VKI_AT_NULL; cauxv++) {
1967 if (cauxv->a_type == VKI_AT_PS_STRINGS) {
1968 tmp = (Word)cauxv->u.a_ptr;
1970 *out = tmp;
1971 *outlen = sizeof(size_t);
1972 return True;
1975 return False;
1978 static void sysctl_kern_usrstack(SizeT* out, SizeT* outlen)
1980 *out = VG_(get_usrstack)();
1981 *outlen = sizeof(ULong);
1984 static Bool sysctl_kern_proc_pathname(HChar *out, SizeT *len)
1986 const HChar *exe_name = VG_(resolved_exename);
1988 if (!len) {
1989 return False;
1992 if (!out) {
1993 HChar tmp[VKI_PATH_MAX];
1994 if (!VG_(realpath)(exe_name, tmp)) {
1995 return False;
1997 *len = VG_(strlen)(tmp)+1;
1998 return True;
2001 if (!VG_(realpath)(exe_name, out)) {
2002 return False;
2005 *len = VG_(strlen)(out)+1;
2006 return True;
2009 // SYS___sysctl 202
2010 /* int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen); */
2011 /* ARG1 ARG2 ARG3 ARG4 ARG5 ARG6 */
2012 PRE(sys___sysctl)
2014 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 );
2016 int* name = (int*)ARG1;
2017 if (ML_(safe_to_deref)(name, sizeof(int))) {
2018 PRINT("\nmib[0]: ");
2019 if (SARG2 >= 1) {
2020 switch (name[0]) {
2021 case 0: // CTL_UNSPEC
2022 PRINT("unspec");
2023 break;
2024 case 1: // CTL_KERN
2025 PRINT("kern");
2026 break;
2027 case 2: // CTL_VM
2028 PRINT("vm");
2029 break;
2030 case 3: // CTL_VFS
2031 PRINT("vfs");
2032 break;
2033 case 4: // CTL_NET
2034 PRINT("net");
2035 break;
2036 case 5: // CTL_DEBUG
2037 PRINT("debug");
2038 break;
2039 case 6: // CTL_HW
2040 PRINT("hw");
2041 break;
2042 case 7: // CTL_MACHDEP
2043 PRINT("machdep");
2044 break;
2045 case 8: // CTL _USER
2046 PRINT("user");
2047 break;
2048 case 9: //CTL_P1003_1B
2049 PRINT("p1003_b1b");
2050 break;
2051 default:
2052 PRINT("unrecognized (%d)", ((int*)ARG1)[0]);
2053 break;
2056 if (SARG2 >= 2 && ML_(safe_to_deref)(name, 2*sizeof(int))) {
2057 PRINT(" mib[1]: %d\n", name[1]);
2062 * Special handling cases
2064 * 1. kern.usrstack
2065 * This sysctl returns the address of the bottom of the user stack
2066 * (that is the highest user stack address, since the stack grows
2067 * downwards). Without any special handling this would return the
2068 * address of the host userstack. We have created a stack for the
2069 * guest (in aspacemgr) and that is the one that we want the guest
2070 * to see. Aspacemgr is setup in m_main.c with the adresses and sizes
2071 * saved to file static variables in that file, so we call
2072 * VG_(get_usrstack)() to retrieve them from there.
2074 if (SARG2 == 2 && ML_(safe_to_deref)(name, 2*sizeof(int))) {
2075 if (name[0] == 1 && name[1] == 33) {
2076 // kern.usrstack
2077 sysctl_kern_usrstack((SizeT*)ARG3, (SizeT*)ARG4);
2078 SET_STATUS_Success(0);
2083 * 2. kern.ps_strings
2085 if (SARG2 == 2 && ML_(safe_to_deref)(name, 2*sizeof(int))) {
2086 if (name[0] == 1 && name[1] == 32) {
2087 if (sysctl_kern_ps_strings((SizeT*)ARG3, (SizeT*)ARG4)) {
2088 SET_STATUS_Success(0);
2094 * 3. kern.proc.pathname
2096 if (SARG2 == 4 && ML_(safe_to_deref)(name, 4*sizeof(int))) {
2097 if (name[0] == 1 && name[1] == 14 && name[2] == 12) {
2098 vki_pid_t pid = (vki_pid_t)name[3];
2099 if (pid == -1 || pid == VG_(getpid)()) {
2100 sysctl_kern_proc_pathname((HChar *)ARG3, (SizeT *)ARG4);
2101 SET_STATUS_Success(0);
2106 PRE_REG_READ6(int, "__sysctl", int *, name, vki_u_int32_t, namelen, void *, oldp,
2107 vki_size_t *, oldlenp, void *, newp, vki_size_t, newlen);
2109 // read number of ints specified in ARG2 from mem pointed to by ARG1
2110 PRE_MEM_READ("sysctl(name)", (Addr)ARG1, ARG2 * sizeof(int));
2112 // if 'newp' is not NULL can read namelen bytes from that address
2113 if (ARG5 != (UWord)NULL) {
2114 PRE_MEM_READ("sysctl(newp)", (Addr)ARG5, ARG6);
2117 // there are two scenarios for oldlenp/oldp
2118 // 1. oldval is NULL and oldlenp is non-NULL
2119 // this is a query of oldlenp so oldlenp will be written
2120 // 2. Both are non-NULL
2121 // this is a query of oldp, oldlenp will be read and oldp will
2122 // be written
2124 // More thoughts on this
2125 // if say oldp is a string buffer
2126 // oldlenp will point to the length of the buffer
2128 // but on return does oldlenp also get updated?
2130 // is oldlenp is not NULL, can write
2131 if (ARG4 != (UWord)NULL) {
2132 if (ARG3 != (UWord)NULL) {
2133 // case 2 above
2134 PRE_MEM_READ("sysctl(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
2135 PRE_MEM_WRITE("sysctl(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
2136 if (ML_(safe_to_deref)((void*)(Addr)ARG4, sizeof(vki_size_t))) {
2137 PRE_MEM_WRITE("sysctl(oldp)", (Addr)ARG3, *(vki_size_t *)ARG4);
2138 } else {
2139 VG_(dmsg)("Warning: Bad oldlenp address %p in sysctl\n",
2140 (void *)(Addr)ARG4);
2141 SET_STATUS_Failure ( VKI_EFAULT );
2143 } else {
2144 // case 1 above
2145 PRE_MEM_WRITE("sysctl(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
2150 POST(sys___sysctl)
2152 if (ARG4 != (UWord)NULL) {
2153 if (ARG3 != (UWord)NULL) {
2154 POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
2155 POST_MEM_WRITE((Addr)ARG3, *(vki_size_t *)ARG4);
2156 } else {
2157 POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
2162 // SYS_mlock 203
2163 // generic
2165 // SYS_munlock 204
2166 // generic
2168 // SYS_undelete 205
2169 // int undelete(const char *path);
2170 PRE(sys_undelete)
2172 *flags |= SfMayBlock;
2173 PRINT("sys_undelete ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
2174 PRE_REG_READ1(int, "undelete", const char *, path);
2175 PRE_MEM_RASCIIZ( "undelete(path)", ARG1 );
2178 // SYS_futimes 206
2179 // int futimes(int fd, const struct timeval *times);
2180 PRE(sys_futimes)
2182 PRINT("sys_lutimes ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2183 PRE_REG_READ2(long, "futimes", int, fd, struct timeval *, times);
2184 if (ARG2 != 0) {
2185 PRE_MEM_READ( "futimes(times)", ARG2, sizeof(struct vki_timeval) );
2189 // SYS_getpgid 207
2190 // generic
2192 // SYS_poll 209
2193 // generic
2195 // SYS_freebsd7___semctl 220
2196 // int semctl(int semid, int semnum, int cmd, ...);
2197 PRE(sys_freebsd7___semctl)
2199 union vki_semun* semun;
2200 switch (ARG3) {
2201 case VKI_IPC_STAT:
2202 case VKI_SEM_STAT:
2203 case VKI_IPC_SET:
2204 case VKI_GETALL:
2205 case VKI_SETALL:
2206 PRINT("sys_freebsd7___semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
2207 PRE_REG_READ4(int, "semctl",
2208 int, semid, int, semnum, int, cmd, union vki_semun *, arg);
2209 PRE_MEM_READ("sys_freebsd7___semctl(arg)", ARG4, sizeof(union vki_semun));
2210 semun = (union vki_semun*)ARG4;
2211 if (ML_(safe_to_deref)(semun, sizeof(*semun))) {
2212 ARG4 = (RegWord)semun;
2213 ML_(generic_PRE_sys_semctl)(tid, ARG1,ARG2,ARG3,ARG4);
2215 break;
2216 default:
2217 PRINT("sys_freebsd7___semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2218 PRE_REG_READ3(long, "semctl",
2219 int, semid, int, semnum, int, cmd);
2220 break;
2224 POST(sys_freebsd7___semctl)
2226 union vki_semun* semun = (union vki_semun*)ARG4;
2227 if (ML_(safe_to_deref)(semun, sizeof(*semun))) {
2228 ARG4 = (RegWord)semun;
2229 ML_(generic_POST_sys_semctl)(tid, RES, ARG1,ARG2,ARG3,ARG4);
2233 // SYS_semget 221
2234 // int semget(key_t key, int nsems, int flag);
2235 PRE(sys_semget)
2237 PRINT("sys_semget ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2238 PRE_REG_READ3(int, "semget", vki_key_t, key, int, nsems, int, flag);
2241 // SYS_semop 222
2242 // int semop(int semid, struct sembuf *array, size_t nops);
2243 PRE(sys_semop)
2245 *flags |= SfMayBlock;
2246 PRINT("sys_semop ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2247 PRE_REG_READ3(int, "semop",
2248 int, semid, struct sembuf *, array, unsigned, nops);
2249 ML_(generic_PRE_sys_semop)(tid, ARG1,ARG2,ARG3);
2252 // SYS_freebsd7_msgctl 224
2253 // int msgctl(int msqid, int cmd, struct msqid_ds_old *buf);
2254 PRE(sys_freebsd7_msgctl)
2256 PRINT("sys_freebsd7_msgctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3 );
2258 PRE_REG_READ3(int, "msgctl", int, msqid, int, cmd, struct msqid_ds_old *, buf);
2260 switch (ARG2 /* cmd */) {
2261 case VKI_IPC_STAT:
2262 PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)",
2263 ARG3, sizeof(struct vki_msqid_ds_old) );
2264 break;
2265 case VKI_IPC_SET:
2266 PRE_MEM_READ( "msgctl(IPC_SET, buf)",
2267 ARG3, sizeof(struct vki_msqid_ds_old) );
2268 break;
2272 POST(sys_freebsd7_msgctl)
2274 switch (ARG2 /* cmd */) {
2275 case VKI_IPC_STAT:
2276 POST_MEM_WRITE( ARG3, sizeof(struct vki_msqid_ds_old) );
2277 break;
2281 // SYS_msgget 225
2282 // int msgget(key_t key, int msgflg);
2283 PRE(sys_msgget)
2285 PRINT("sys_msgget ( %" FMT_REGWORD"d, %" FMT_REGWORD"d )",SARG1,SARG2);
2286 PRE_REG_READ2(int, "msgget", key_t, key, int, msgflg);
2289 // SYS_msgsnd 226
2290 // int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg);
2291 PRE(sys_msgsnd)
2293 PRINT("sys_msgsnd ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,ARG2,SARG3,SARG4 );
2294 PRE_REG_READ4(int, "msgsnd", int, msqid, struct msgbuf *, msgp, size_t, msgsz, int, msgflg);
2295 struct vki_msgbuf *msgp = (struct vki_msgbuf *)ARG2;
2296 PRE_MEM_READ( "msgsnd(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) );
2297 PRE_MEM_READ( "msgsnd(msgp->mtext)", (Addr)&msgp->mtext, ARG3 );
2299 // SYS_msgrcv 227
2300 // ssize_t msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int msgflg);
2301 PRE(sys_msgrcv)
2303 *flags |= SfMayBlock;
2305 PRINT("sys_msgrcv ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,ARG2,ARG3,SARG4,SARG5 );
2306 PRE_REG_READ5(ssize_t, "msgrcv", int, msqid, struct msgbuf *, msgp, size_t, msgsz,
2307 long, msgtyp, int, msgflg);
2308 struct vki_msgbuf *msgp = (struct vki_msgbuf *)ARG2;
2309 PRE_MEM_WRITE( "msgrcv(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) );
2310 PRE_MEM_WRITE( "msgrcv(msgp->mtext)", (Addr)&msgp->mtext, ARG3 );
2313 POST(sys_msgrcv)
2315 struct vki_msgbuf *msgp = (struct vki_msgbuf *)ARG2;
2316 POST_MEM_WRITE( (Addr)&msgp->mtype, sizeof(msgp->mtype) );
2317 POST_MEM_WRITE( (Addr)&msgp->mtext, RES );
2320 // SYS_shmat 228
2321 // void * shmat(int shmid, const void *addr, int flag);
2322 PRE(sys_shmat)
2324 UWord arg2tmp;
2325 PRINT("sys_shmat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2326 PRE_REG_READ3(void *, "shmat",
2327 int, shmid, const void *, addr, int, flag);
2328 arg2tmp = ML_(generic_PRE_sys_shmat)(tid, ARG1,ARG2,ARG3);
2329 if (arg2tmp == 0) {
2330 SET_STATUS_Failure( VKI_EINVAL );
2331 } else {
2332 ARG2 = arg2tmp;
2336 POST(sys_shmat)
2338 ML_(generic_POST_sys_shmat)(tid, RES,ARG1,ARG2,ARG3);
2341 // SYS_freebsd7_shmctl 229
2342 // int shmctl(int shmid, int cmd, struct shmid_ds *buf);
2343 PRE(sys_freebsd7_shmctl)
2345 PRINT("sys_freebsd7_shmctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,SARG2,ARG3);
2346 PRE_REG_READ3(int, "shmctl",
2347 int, shmid, int, cmd, struct vki_shmid_ds_old *, buf);
2348 switch (ARG2 /* cmd */) {
2349 case VKI_IPC_STAT:
2350 PRE_MEM_WRITE( "shmctl7(IPC_STAT, buf)",
2351 ARG3, sizeof(struct vki_shmid_ds_old) );
2352 break;
2353 case VKI_IPC_SET:
2354 PRE_MEM_READ( "shmctl7(IPC_SET, buf)",
2355 ARG3, sizeof(struct vki_shmid_ds_old) );
2356 break;
2360 POST(sys_freebsd7_shmctl)
2362 if (ARG2 == VKI_IPC_STAT) {
2363 POST_MEM_WRITE( ARG3, sizeof(struct vki_shmid_ds_old) );
2367 // SYS_shmdt 230
2368 // int shmdt(const void *addr);
2369 PRE(sys_shmdt)
2371 PRINT("sys_shmdt ( %#" FMT_REGWORD "x )",ARG1);
2372 PRE_REG_READ1(int, "shmdt", const void *, addr);
2373 if (!ML_(generic_PRE_sys_shmdt)(tid, ARG1)) {
2374 SET_STATUS_Failure( VKI_EINVAL );
2378 POST(sys_shmdt)
2380 ML_(generic_POST_sys_shmdt)(tid, RES,ARG1);
2383 // SYS_shmget 231
2384 // int shmget(key_t key, size_t size, int flag);
2385 PRE(sys_shmget)
2387 PRINT("sys_shmget ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2388 PRE_REG_READ3(int, "shmget", vki_key_t, key, vki_size_t, size, int, flag);
2392 // SYS_clock_gettime 232
2393 // int clock_gettime(clockid_t clock_id, struct timespec *tp);
2394 PRE(sys_clock_gettime)
2396 PRINT("sys_clock_gettime( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2397 PRE_REG_READ2(int, "clock_gettime",
2398 vki_clockid_t, clk_id, struct timespec *, tp);
2399 PRE_MEM_WRITE( "clock_gettime(tp)", ARG2, sizeof(struct vki_timespec) );
2402 POST(sys_clock_gettime)
2404 POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) );
2407 // SYS_clock_settime 233
2408 // int clock_settime(clockid_t clock_id, const struct timespec *tp);
2409 PRE(sys_clock_settime)
2411 PRINT("sys_clock_settime( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2412 PRE_REG_READ2(int, "clock_settime",
2413 vki_clockid_t, clk_id, const struct timespec *, tp);
2414 PRE_MEM_READ( "clock_settime(tp)", ARG2, sizeof(struct vki_timespec) );
2417 // SYS_clock_getres 234
2418 // int clock_getres(clockid_t clock_id, struct timespec *tp);
2419 PRE(sys_clock_getres)
2421 PRINT("sys_clock_getres( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2422 // Nb: we can't use "RES" as the param name because that's a macro
2423 // defined above!
2424 PRE_REG_READ2(int, "clock_getres",
2425 vki_clockid_t, clock_id, struct timespec *, tp);
2426 if (ARG2 != 0) {
2427 PRE_MEM_WRITE( "clock_getres(tp)", ARG2, sizeof(struct vki_timespec) );
2431 POST(sys_clock_getres)
2433 if (ARG2 != 0) {
2434 POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) );
2438 // SYS_ktimer_create 235
2439 // int timer_create(clockid_t clockid, struct sigevent *restrict evp,
2440 // timer_t *restrict timerid);
2441 PRE(sys_timer_create)
2443 PRINT("sys_timer_create( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", SARG1,ARG2,ARG3);
2444 PRE_REG_READ3(int, "timer_create",
2445 vki_clockid_t, clockid, struct sigevent *, evp,
2446 vki_timer_t *, timerid);
2447 if (ARG2 != 0) {
2448 PRE_MEM_READ( "timer_create(evp)", ARG2, sizeof(struct vki_sigevent) );
2450 PRE_MEM_WRITE( "timer_create(timerid)", ARG3, sizeof(vki_timer_t) );
2453 POST(sys_timer_create)
2455 POST_MEM_WRITE( ARG3, sizeof(vki_timer_t) );
2458 // SYS_ktimer_delete 236
2459 // int timer_delete(timer_t timerid);
2460 PRE(sys_timer_delete)
2462 PRINT("sys_timer_delete( %#" FMT_REGWORD "x )", ARG1);
2463 PRE_REG_READ1(long, "timer_delete", vki_timer_t, timerid);
2466 // SYS_ktimer_settime 237
2467 // int timer_settime(timer_t timerid, int flags,
2468 // const struct itimerspec *restrict value,
2469 // struct itimerspec *restrict ovalue);
2470 PRE(sys_timer_settime)
2472 PRINT("sys_timer_settime( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3,ARG4);
2473 PRE_REG_READ4(int, "timer_settime",
2474 vki_timer_t, timerid, int, flags,
2475 const struct itimerspec *, value,
2476 struct itimerspec *, ovalue);
2477 PRE_MEM_READ( "timer_settime(value)", ARG3,
2478 sizeof(struct vki_itimerspec) );
2479 if (ARG4 != 0) {
2480 PRE_MEM_WRITE( "timer_settime(ovalue)", ARG4,
2481 sizeof(struct vki_itimerspec) );
2485 POST(sys_timer_settime)
2487 if (ARG4 != 0) {
2488 POST_MEM_WRITE( ARG4, sizeof(struct vki_itimerspec) );
2492 // SYS_ktimer_gettime 238
2493 // int timer_gettime(timer_t timerid, struct itimerspec *value);
2494 PRE(sys_timer_gettime)
2496 PRINT("sys_timer_gettime( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2);
2497 PRE_REG_READ2(long, "timer_gettime",
2498 vki_timer_t, timerid, struct itimerspec *, value);
2499 PRE_MEM_WRITE( "timer_gettime(value)", ARG2,
2500 sizeof(struct vki_itimerspec));
2503 POST(sys_timer_gettime)
2505 POST_MEM_WRITE( ARG2, sizeof(struct vki_itimerspec) );
2508 // SYS_ktimer_getoverrun 239
2509 // int timer_getoverrun(timer_t timerid);
2510 PRE(sys_timer_getoverrun)
2512 PRINT("sys_timer_getoverrun( %#" FMT_REGWORD "x )", ARG1);
2513 PRE_REG_READ1(int, "timer_getoverrun", vki_timer_t, timerid);
2516 // SYS_nanosleep 240
2517 // generic
2519 // SYS_ffclock_getcounter 241
2520 // int ffclock_getcounter(ffcounter *ffcount);
2521 // @todo
2523 // SYS_ffclock_setestimate 242
2524 // int ffclock_setestimate(struct ffclock_estimate *cest);
2525 // @todo
2527 // SYS_ffclock_getestimate 243
2528 // int ffclock_getestimate(struct ffclock_estimate *cest);
2529 // @todo
2531 // SYS_clock_nanosleep 244
2532 // int clock_nanosleep(clockid_t clock_id, int flags,
2533 // const struct timespec *rqtp, struct timespec *rmtp);
2534 PRE(sys_clock_nanosleep)
2536 *flags |= SfMayBlock|SfPostOnFail;
2537 PRINT("sys_clock_nanosleep ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
2538 SARG1, SARG2, ARG3, ARG4);
2539 PRE_REG_READ4(int, "clock_nanosleep", vki_clockid_t, clock_id, int, flags,
2540 const struct timespec *, rqtp, struct timespec *, rmtp);
2541 PRE_MEM_READ("clock_nanosleep(rqtp)", ARG3, sizeof(struct vki_timespec));
2542 if (ARG4 != 0) {
2543 PRE_MEM_WRITE( "clock_nanosleep(rmtp)", ARG4, sizeof(struct vki_timespec) );
2547 POST(sys_clock_nanosleep)
2549 if (ARG4 != 0 && FAILURE && ERR == VKI_EINTR) {
2550 POST_MEM_WRITE( ARG4, sizeof(struct vki_timespec) );
2554 // SYS_clock_getcpuclockid2 247
2555 // x86/amd64
2557 POST(sys_clock_getcpuclockid2)
2559 POST_MEM_WRITE(ARG3, sizeof(vki_clockid_t));
2563 // SYS_ntp_gettime 248
2564 // int ntp_gettime(struct ntptimeval *);
2565 // @todo
2567 // SYS_minherit 250
2568 // int minherit(void *addr, size_t len, int inherit);
2569 PRE(sys_minherit)
2571 PRINT("sys_minherit( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
2572 PRE_REG_READ3(int, "minherit",
2573 void *, addr, vki_size_t, len, int, inherit);
2574 if (ARG2 != 0) {
2575 PRE_MEM_WRITE( "minherit(addr)", ARG1,ARG2 );
2579 POST(sys_minherit)
2581 if (ARG2 != 0) {
2582 POST_MEM_WRITE( ARG1, ARG2 );
2586 // SYS_rfork 251
2587 // x86/amd64 not functional
2589 // SYS_issetugid 253
2590 // int issetugid(void);
2591 PRE(sys_issetugid)
2593 PRINT("%s", "sys_issetugid ()");
2594 PRE_REG_READ0(long, "issetugid");
2597 // SYS_lchown 254
2598 // generic
2600 // We must record the iocb for each aio_read() in a table so that when
2601 // aio_return() is called we can mark the memory written asynchronously by
2602 // aio_read() as having been written. We don't have to do this for
2603 // aio_write(). See bug 197227 for more details.
2604 static OSet* iocb_table = NULL;
2605 static Bool aio_init_done = False;
2607 static void aio_init(void)
2609 iocb_table = VG_(OSetWord_Create)(VG_(malloc), "syswrap.aio", VG_(free));
2610 aio_init_done = True;
2613 // and the same thing for vector reads
2614 static OSet* iocbv_table = NULL;
2615 static Bool aiov_init_done = False;
2617 static void aiov_init(void)
2619 iocbv_table = VG_(OSetWord_Create)(VG_(malloc), "syswrap.aiov", VG_(free));
2620 aiov_init_done = True;
2624 // SYS_aio_read 255
2625 // int aio_read(struct aiocb *iocb);
2626 PRE(sys_aio_read)
2628 PRINT("sys_aio_read ( %#" FMT_REGWORD "x )", ARG1);
2629 PRE_REG_READ1(int, "aio_read", struct vki_aiocb *, iocb);
2630 PRE_MEM_READ("aio_read(iocb)", ARG1, sizeof(struct vki_aiocb));
2631 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
2632 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
2633 if (!ML_(fd_allowed)(iocb->aio_fildes, "aio_read", tid, False)) {
2634 SET_STATUS_Failure(VKI_EBADF);
2635 } else {
2636 PRE_MEM_WRITE("aio_read(aiocbp->aio_buf)",
2637 (Addr)iocb->aio_buf, iocb->aio_nbytes);
2638 // @todo PJF there is a difference between FreeBSD and
2639 // Darwin here. On Darwin, if aio_buf is NULL the syscall
2640 // will fail, on FreeBSD it doesn't fail.
2642 } else {
2643 SET_STATUS_Failure(VKI_EINVAL);
2647 POST(sys_aio_read)
2649 struct vki_aiocb* iocb = (struct vki_aiocb*)ARG1;
2651 if (iocb->aio_buf) {
2652 if (!aio_init_done) {
2653 aio_init();
2655 // see also POST(sys_aio_readv)
2656 if (!VG_(OSetWord_Contains)(iocb_table, (UWord)iocb)) {
2657 VG_(OSetWord_Insert)(iocb_table, (UWord)iocb);
2658 } else {
2659 // @todo PJF this warns without callstack
2660 VG_(dmsg)("Warning: Duplicate control block %p in aio_read\n",
2661 (void *)(Addr)ARG1);
2662 VG_(dmsg)("Warning: Ensure 'aio_return' is called when 'aio_read' has completed\n");
2667 // SYS_aio_write 256
2668 // int aio_write(struct aiocb *iocb);
2669 PRE(sys_aio_write)
2671 PRINT("sys_aio_write ( %#" FMT_REGWORD "x )", ARG1);
2672 PRE_REG_READ1(int, "aio_write", struct vki_aiocb *, iocb);
2673 PRE_MEM_READ("aio_write(iocb)", ARG1, sizeof(struct vki_aiocb));
2674 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
2675 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
2676 if (!ML_(fd_allowed)(iocb->aio_fildes, "aio_write", tid, False)) {
2677 SET_STATUS_Failure( VKI_EBADF );
2678 } else {
2679 PRE_MEM_READ("aio_write(iocb->aio_buf)",
2680 (Addr)iocb->aio_buf, iocb->aio_nbytes);
2681 // @todo PJF there is a difference between FreeBSD and
2682 // Darwin here. On Darwin, if aio_buf is NULL the syscall
2683 // will fail, on FreeBSD it doesn't fail.
2685 } else {
2686 SET_STATUS_Failure(VKI_EINVAL);
2690 // SYS_lio_listio 257
2691 // int lio_listio(int mode, struct aiocb * const list[], int nent,
2692 // struct sigevent *sig);
2693 PRE(sys_lio_listio)
2695 PRINT("sys_lio_listio ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",
2696 SARG1, ARG2, SARG3, ARG4);
2697 PRE_REG_READ4(int, "lio_listio", int, mode, struct aiocb * const *, list, int, nent,
2698 struct sigevent *,sig);
2699 PRE_MEM_READ("lio_listio(list)", ARG2, ARG3*sizeof(struct vki_aiocb *));
2700 // loop check elements
2701 if (ML_(safe_to_deref)((struct vki_aiocb **)ARG2, ARG3*sizeof(struct vki_aiocb *))) {
2702 struct vki_aiocb** list = (struct vki_aiocb **)ARG2;
2703 for (int i = 0; i < (int)ARG3; ++i) {
2704 if (list[i]) {
2705 PRE_MEM_READ("lio_listio(list[?])", (Addr)list[i], ARG3*sizeof(struct vki_aiocb));
2707 // @todo
2708 // figure out what gets read/written
2709 // when list[i]->aio_lio_opcode == VKI_LIO_READ and
2710 // when list[i]->aio_lio_opcode == VKI_LIO_WRITE
2711 //if (ML_(safe_to_deref)(list[i], ARG3*sizeof(struct vki_aiocb))) {
2716 if (ARG1 & VKI_LIO_WAIT) {
2717 *flags |= SfMayBlock;
2720 if (ARG4 && (ARG1 == VKI_LIO_NOWAIT)) {
2721 PRE_MEM_READ("lio_listio(sig)", ARG4, sizeof(struct vki_sigevent));
2725 // SYS_freebsd11_getdents 272
2726 // generic
2728 // SYS_lchmod 274
2729 // int lchmod(const char *path, mode_t mode);
2730 PRE(sys_lchmod)
2732 PRINT("sys_lchmod ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char *)ARG1,ARG2);
2733 PRE_REG_READ2(int, "lchmod", const char *, path, vki_mode_t, mode);
2734 PRE_MEM_RASCIIZ( "lchmod(path)", ARG1 );
2737 // SYS_lutimes 276
2738 // int lutimes(const char *path, const struct timeval *times);
2739 PRE(sys_lutimes)
2741 PRINT("sys_lutimes ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2);
2742 PRE_REG_READ2(int, "lutimes", char *, path, struct timeval *, times);
2743 PRE_MEM_RASCIIZ( "lutimes(path)", ARG1 );
2744 if (ARG2 != 0) {
2745 PRE_MEM_READ( "lutimes(times)", ARG2, sizeof(struct vki_timeval) );
2749 // SYS_freebsd11_nstat 278
2750 // @todo, maybe
2752 // SYS_freebsd11_nfstat 279
2753 // @todo, maybe
2755 // SYS_freebsd11_nlstat 280
2756 // @todo, maybe
2758 // SYS_preadv 289
2759 // amd64 / x86
2761 // SYS_pwritev 290
2762 // amd64 / x86
2764 // SYS_fhopen 298
2765 // int fhopen(const fhandle_t *fhp, int flags);
2766 PRE(sys_fhopen)
2768 PRINT("sys_open ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2);
2769 PRE_REG_READ2(int, "fhopen",
2770 struct fhandle_t *, fhp, int, flags);
2771 PRE_MEM_READ( "fhopen(fhp)", ARG1, sizeof(struct vki_fhandle) );
2773 /* Otherwise handle normally */
2774 *flags |= SfMayBlock;
2777 POST(sys_fhopen)
2779 vg_assert(SUCCESS);
2780 if (!ML_(fd_allowed)(RES, "fhopen", tid, True)) {
2781 VG_(close)(RES);
2782 SET_STATUS_Failure( VKI_EMFILE );
2783 } else {
2784 if (VG_(clo_track_fds)) {
2785 ML_(record_fd_open_nameless)(tid, RES);
2790 // SYS_freebsd11_fhstat 299
2791 // int fhstat(const fhandle_t *fhp, struct stat *sb);
2792 #if (FREEBSD_VERS >= FREEBSD_12)
2793 PRE(sys_freebsd11_fhstat)
2795 PRINT("sys_freebsd11_fhstat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
2796 PRE_REG_READ2(int, "fhstat", struct fhandle *, fhp, struct freebd11_stat *, sb);
2797 PRE_MEM_READ( "fhstat(fhp)", ARG1, sizeof(struct vki_fhandle) );
2798 PRE_MEM_WRITE( "fhstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
2801 POST(sys_freebsd11_fhstat)
2803 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
2805 #else
2806 PRE(sys_fhstat)
2808 PRINT("sys_fhstat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
2809 PRE_REG_READ2(int, "fhstat", struct fhandle *, fhp, struct stat *, sb);
2810 PRE_MEM_READ( "fhstat(fhp)", ARG1, sizeof(struct vki_fhandle) );
2811 PRE_MEM_WRITE( "fhstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
2814 POST(sys_fhstat)
2816 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
2819 #endif
2821 // SYS_modnext 300
2822 // int modnext(int modid);
2823 PRE(sys_modnext)
2825 PRINT("sys_modnext ( %" FMT_REGWORD "d )",SARG1);
2826 PRE_REG_READ1(int, "modnext", int, modid);
2829 // SYS_modstat 301
2830 // int modstat(int modid, struct module_stat *stat);
2831 PRE(sys_modstat)
2833 PRINT("sys_modstat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2);
2834 PRE_REG_READ2(int, "modstat", int, modid, struct module_stat *, buf);
2835 PRE_MEM_WRITE( "modstat(stat)", ARG2, sizeof(struct vki_module_stat) );
2838 POST(sys_modstat)
2840 POST_MEM_WRITE( ARG2, sizeof(struct vki_module_stat) );
2843 // SYS_modfnext 302
2844 // int modfnext(int modid);
2845 PRE(sys_modfnext)
2847 PRINT("sys_modfnext ( %" FMT_REGWORD "d )",SARG1);
2848 PRE_REG_READ1(int, "modfnext", int, modid);
2851 // SYS_modfind 303
2852 // int modfind(const char *modname);
2853 PRE(sys_modfind)
2855 PRINT("sys_modfind ( %#" FMT_REGWORD "x )",ARG1);
2856 PRE_REG_READ1(long, "modfind", char *, modname);
2857 PRE_MEM_RASCIIZ( "modfind(modname)", ARG1 );
2860 // SYS_kldload 304
2861 // int kldload(const char *file);
2862 PRE(sys_kldload)
2864 PRINT("sys_kldload ( %#" FMT_REGWORD "x(%s) )", ARG1, (char *)ARG1);
2865 PRE_REG_READ1(int, "kldload", const char *, "file");
2866 PRE_MEM_RASCIIZ( "kldload(file)", ARG1 );
2869 // SYS_kldunload 305
2870 // int kldunload(int fileid);
2871 PRE(sys_kldunload)
2873 PRINT("sys_kldunload ( %" FMT_REGWORD "u )", ARG1);
2874 PRE_REG_READ1(int, "kldunload", int, "fileid");
2877 // SYS_kldfind 306
2878 // int kldfind(const char *file);
2879 PRE(sys_kldfind)
2881 PRINT("sys_kldfind ( %#" FMT_REGWORD "x(%s) )", ARG1, (char *)ARG1);
2882 PRE_REG_READ1(int, "kldfind", const char *, file);
2883 PRE_MEM_RASCIIZ( "kldfind(file)", ARG1 );
2886 // SYS_kldnext 307
2887 // int kldnext(int fileid);
2888 PRE(sys_kldnext)
2890 PRINT("sys_kldnext ( %" FMT_REGWORD "u )", ARG1);
2891 PRE_REG_READ1(int, "kldnext", int, fileid);
2894 // SYS_kldstat 308
2895 // int kldstat(int fileid, struct kld_file_stat *stat);
2896 PRE(sys_kldstat)
2898 PRINT("sys_kldstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
2899 PRE_REG_READ2(int, "kldstat", int, fileid, struct kld_file_stat*, stat);
2900 PRE_MEM_WRITE("kldstat(stat)", ARG2, sizeof(struct vki_kld_file_stat));
2903 POST(sys_kldstat)
2905 POST_MEM_WRITE(ARG2, sizeof(struct vki_kld_file_stat));
2908 // SYS_kldfirstmod 309
2909 // int kldfirstmod(int fileid);
2910 PRE(sys_kldfirstmod)
2912 PRINT("sys_kldfirstmod ( %" FMT_REGWORD "u )", ARG1);
2913 PRE_REG_READ1(int, "kldfirstmod", int, fileid);
2916 // SYS_setresuid 311
2917 // int setresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
2918 PRE(sys_setresuid)
2920 PRINT("sys_setresuid ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
2921 PRE_REG_READ3(int, "setresuid",
2922 vki_uid_t, ruid, vki_uid_t, euid, vki_uid_t, suid);
2925 // SYS_setresgid 312
2926 // int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
2927 PRE(sys_setresgid)
2929 PRINT("sys_setresgid ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
2930 PRE_REG_READ3(int, "setresgid",
2931 vki_gid_t, rgid, vki_gid_t, egid, vki_gid_t, sgid);
2934 // SYS_aio_return 314
2935 // ssize_t aio_return(struct aiocb *iocb);
2936 PRE(sys_aio_return)
2938 PRINT("sys_aio_return ( %#" FMT_REGWORD "x )", ARG1);
2939 PRE_REG_READ1(ssize_t, "aio_return", struct aiocb *, iocb);
2940 PRE_MEM_READ("aio_return(iocb)", ARG1, sizeof(struct vki_aiocb));
2941 // read or write?
2942 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
2943 SET_STATUS_from_SysRes(VG_(do_syscall1)(SYSNO, ARG1));
2944 /*if (SUCCESS)*/ {
2945 struct vki_aiocb* iocb = (struct vki_aiocb*)ARG1;
2946 if (!aio_init_done) {
2947 aio_init();
2949 if (!aiov_init_done) {
2950 aiov_init();
2953 // for the happy path aio_return is supposed to be called
2954 // after the io has completed (as determined by aio_error,
2955 // aio_suspend or a signal).
2957 // but what if the aio_read failed or hasn't completed?
2958 // we want to remove the read from the iocb(v)_table
2959 // in the case of aio_read failing
2960 // if the read hasn't completed that's a user error
2961 // I don't know if it's possible to recover in that case
2962 // the iocb will have been removed from the table
2963 // so if the user does recover and call aio_return
2964 // 'correctly' we won't do the POST_MEM_WRITE
2965 // I don't think that we can tell apart a failing
2966 // read from a premature aio_return
2968 // check if it was a plain read
2969 if (VG_(OSetWord_Remove)(iocb_table, (UWord)iocb) && SUCCESS) {
2970 POST_MEM_WRITE((Addr)iocb->aio_buf, iocb->aio_nbytes);
2972 if (VG_(OSetWord_Remove)(iocbv_table, (UWord)iocb) && SUCCESS) {
2973 SizeT vec_count = (SizeT)iocb->aio_nbytes;
2974 // assume that id the read succeded p_iovec is accessible
2975 volatile struct vki_iovec* p_iovec = (volatile struct vki_iovec*)iocb->aio_buf;
2976 for (SizeT i = 0U; i < vec_count; ++i) {
2977 POST_MEM_WRITE((Addr)p_iovec[i].iov_base, p_iovec[i].iov_len);
2981 } else {
2982 SET_STATUS_Failure(VKI_EINVAL);
2986 // SYS_aio_suspend 315
2987 // int aio_suspend(const struct aiocb *const iocbs[], int niocb,
2988 // const struct timespec *timeout);
2989 PRE(sys_aio_suspend)
2991 PRINT("sys_aio_suspend ( %#" FMT_REGWORD "x )", ARG1);
2992 PRE_REG_READ3(int, "aio_suspend", const struct aiocb * const *, iocbs, int, nbiocb, const struct timespec*, timeout);
2993 if (ARG2 > 0) {
2994 PRE_MEM_READ("aio_suspend(iocbs)", ARG1, ARG2*sizeof(struct vki_aiocb*));
2996 if (ARG3) {
2997 PRE_MEM_READ("aio_suspend(timeout)", ARG3, sizeof(struct vki_timespec));
3001 // SYS_aio_cancel 316
3002 // int aio_cancel(int fildes, struct aiocb *iocb);
3003 PRE(sys_aio_cancel)
3005 PRINT("sys_aio_cancel ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
3006 PRE_REG_READ2(int, "aio_cancel", int, fildes, struct iocb *, iocb);
3007 if (ARG2) {
3008 PRE_MEM_READ("aio_cancel(iocb)", ARG2, sizeof(struct vki_aiocb));
3010 if (!ML_(fd_allowed)(ARG1, "aio_cancel", tid, False)) {
3011 SET_STATUS_Failure(VKI_EBADF);
3012 } else {
3013 if (ARG2) {
3014 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG2, sizeof(struct vki_aiocb))) {
3015 // struct vki_aiocb *iocb = (struct vki_aiocb *)ARG2;
3016 // @todo PJF cancel only requests associated with
3017 // fildes and iocb
3018 // Do I need to remove pending reads from iocb(v)_table
3019 // or should the user always call aio_return even after
3020 // aio_cancel?
3021 } else {
3022 SET_STATUS_Failure(VKI_EINVAL);
3024 } else {
3025 // @todo PJF cancel all requests associated with fildes, see above
3030 // SYS_aio_error 317
3031 // int aio_error(const struct aiocb *iocb);
3032 PRE(sys_aio_error)
3034 PRINT("sys_aio_error ( %#" FMT_REGWORD "x )", ARG1);
3035 PRE_REG_READ1(ssize_t, "aio_error", struct aiocb *, iocb);
3036 PRE_MEM_READ("aio_error(iocb)", ARG1, sizeof(struct vki_aiocb));
3037 if (ARG1) {
3038 if (!ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
3039 SET_STATUS_Failure(VKI_EINVAL);
3044 // SYS_yield 321
3045 int yield(void);
3046 PRE(sys_yield)
3048 *flags |= SfMayBlock;
3049 PRINT("%s", "yield()");
3050 PRE_REG_READ0(long, "yield");
3053 // SYS_mlockall 324
3054 // generic
3056 // SYS_munlockall 325
3057 // int munlockall(void);
3058 PRE(sys_munlockall)
3060 *flags |= SfMayBlock;
3061 PRINT("%s", "sys_munlockall ( )");
3062 PRE_REG_READ0(int, "munlockall");
3065 // SYS___getcwd 326
3066 // int __getcwd(char *buf, size_t buflen);
3067 PRE(sys___getcwd)
3069 PRINT("sys___getcwd ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2);
3070 PRE_REG_READ2(long, "__getcwd", char *, buf, unsigned int, buflen);
3071 PRE_MEM_WRITE( "__getcwd(buf)", ARG1, ARG2 );
3074 POST(sys___getcwd)
3076 vg_assert(SUCCESS);
3077 if (RES == 0) {
3078 // QQQ it is unclear if this is legal or not, but the
3079 // QQQ kernel just wrote it there...
3080 // QQQ Why oh why didn't phk return the length from __getcwd()?
3081 UInt len = VG_(strlen) ( (char *)ARG1 ) + 1;
3082 POST_MEM_WRITE( ARG1, len );
3086 //SYS_sched_setparam 327
3087 // int sched_setparam(pid_t pid, const struct sched_param *param);
3088 PRE(sys_sched_setparam)
3090 PRINT("sched_setparam ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2 );
3091 PRE_REG_READ2(int, "sched_setparam",
3092 vki_pid_t, pid, struct sched_param *, param);
3093 PRE_MEM_READ( "sched_setparam(param)", ARG2, sizeof(struct vki_sched_param) );
3096 POST(sys_sched_setparam)
3098 POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) );
3101 // SYS_sched_getparam 328
3102 // int sched_getparam(pid_t pid, struct sched_param *param);
3103 PRE(sys_sched_getparam)
3105 PRINT("sched_getparam ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2 );
3106 PRE_REG_READ2(int, "sched_getparam",
3107 vki_pid_t, pid, struct sched_param *, param);
3108 PRE_MEM_WRITE( "sched_getparam(param)", ARG2, sizeof(struct vki_sched_param) );
3111 POST(sys_sched_getparam)
3113 POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) );
3116 // SYS_sched_setscheduler 329
3117 // int sched_setscheduler(pid_t pid, int policy,
3118 // const struct sched_param *param);
3119 PRE(sys_sched_setscheduler)
3121 PRINT("sys_sched_setscheduler ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3);
3122 PRE_REG_READ3(int, "sched_setscheduler",
3123 vki_pid_t, pid, int, policy, struct sched_param *, param);
3124 if (ARG3 != 0) {
3125 PRE_MEM_READ("sched_setscheduler(param)",
3126 ARG3, sizeof(struct vki_sched_param));
3130 // SYS_sched_getscheduler 330
3131 // int sched_getscheduler(pid_t pid);
3132 PRE(sys_sched_getscheduler)
3134 PRINT("sys_sched_getscheduler ( %" FMT_REGWORD "d )", SARG1);
3135 PRE_REG_READ1(int, "sched_getscheduler", vki_pid_t, pid);
3138 // SYS_sched_yield 331
3139 // int sched_yield(void);
3140 PRE(sys_sched_yield)
3142 *flags |= SfMayBlock;
3143 PRINT("sched_yield()");
3144 PRE_REG_READ0(int, "sched_yield");
3147 // SYS_sched_get_priority_max 332
3148 // int sched_get_priority_max(int policy);
3149 PRE(sys_sched_get_priority_max)
3151 PRINT("sched_get_priority_max ( %" FMT_REGWORD "u )", ARG1);
3152 PRE_REG_READ1(long, "sched_get_priority_max", int, policy);
3155 // SYS_sched_get_priority_min 333
3156 // int sched_get_priority_min(int policy);
3157 PRE(sys_sched_get_priority_min)
3159 PRINT("sched_get_priority_min ( %" FMT_REGWORD "u )", ARG1);
3160 PRE_REG_READ1(long, "sched_get_priority_min", int, policy);
3163 // SYS_sched_rr_get_interval 334
3164 // int sched_rr_get_interval(pid_t pid, struct timespec *interval);
3165 PRE(sys_sched_rr_get_interval)
3167 PRINT("sys_sched_rr_get_interval ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
3168 PRE_REG_READ2(int, "sched_rr_get_interval", vki_pid_t, pid, struct vki_timespec *,interval);
3169 PRE_MEM_WRITE("sys_sched_rr_get_interval(interval)", ARG2, sizeof(struct vki_timespec));
3172 POST(sys_sched_rr_get_interval)
3174 POST_MEM_WRITE(ARG2, sizeof(struct vki_timespec));
3177 // SYS_utrace 335
3178 // int utrace(const void *addr, size_t len);
3179 PRE(sys_utrace)
3181 PRINT("sys_utrace ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
3182 PRE_REG_READ2(int, "utrace", const void *, addr, vki_size_t, len);
3183 PRE_MEM_READ( "utrace(addr)", ARG1, ARG2 );
3186 // SYS_kldsym 337
3187 // int kldsym(int fileid, int cmd, void *data);
3188 PRE(sys_kldsym)
3190 PRINT("sys_kldsym ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3 );
3191 PRE_REG_READ3(int, "kldsym", int, fileid, int, cmd, void*, data);
3192 PRE_MEM_READ( "kldsym(data)", ARG3, sizeof(struct vki_kld_sym_lookup) );
3193 struct vki_kld_sym_lookup *kslp = (struct vki_kld_sym_lookup *)ARG3;
3194 if (ML_(safe_to_deref)(kslp, sizeof(struct vki_kld_sym_lookup))) {
3195 PRE_MEM_RASCIIZ( "kldsym(data.symname)", (Addr)kslp->symname );
3199 POST(sys_kldsym)
3201 struct vki_kld_sym_lookup *kslp = (struct vki_kld_sym_lookup *)ARG3;
3202 POST_MEM_WRITE( (Addr)&kslp->symvalue, sizeof(kslp->symvalue) );
3203 POST_MEM_WRITE( (Addr)&kslp->symsize, sizeof(kslp->symsize) );
3206 // SYS_jail 338
3207 // int jail(struct jail *jail);
3208 PRE(sys_jail)
3210 PRINT("sys_jail ( %#" FMT_REGWORD "x )", ARG1);
3211 PRE_REG_READ1(int, "jail", struct jail *, jail);
3212 PRE_MEM_READ( "jail(jail)", ARG1, sizeof(struct vki_jail) );
3215 // SYS_nnpfs_syscall 338
3216 // @todo
3218 // SYS_sigprocmask 340
3219 // int sigprocmask(int how, const sigset_t * restrict set,
3220 // sigset_t * restrict oset);
3221 PRE(sys_sigprocmask)
3223 PRINT("sys_sigprocmask ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3);
3224 PRE_REG_READ3(int, "sigprocmask",
3225 int, how, vki_sigset_t *, set, vki_sigset_t *, oset);
3226 if (ARG2 != 0) {
3227 PRE_MEM_READ( "sigprocmask(set)", ARG2, sizeof(vki_sigset_t));
3229 if (ARG3 != 0) {
3230 PRE_MEM_WRITE( "sigprocmask(oset)", ARG3, sizeof(vki_sigset_t));
3233 if (ARG2 != 0 &&
3234 !ML_(safe_to_deref)((void *)(Addr)ARG2, sizeof(vki_sigset_t))) {
3235 VG_(dmsg)("Warning: Bad set handler address %p in sigprocmask\n",
3236 (void *)(Addr)ARG2);
3237 SET_STATUS_Failure ( VKI_EFAULT );
3238 } else if (ARG3 != 0 &&
3239 !ML_(safe_to_deref)((void *)(Addr)ARG3, sizeof(vki_sigset_t))) {
3240 VG_(dmsg)("Warning: Bad oldset address %p in sigprocmask\n",
3241 (void *)(Addr)ARG3);
3242 SET_STATUS_Failure ( VKI_EFAULT );
3243 } else {
3244 SET_STATUS_from_SysRes(VG_(do_sys_sigprocmask)(tid, ARG1 /*how*/,
3245 (vki_sigset_t*)(Addr)ARG2,
3246 (vki_sigset_t*)(Addr)ARG3));
3249 if (SUCCESS) {
3250 *flags |= SfPollAfter;
3254 POST(sys_sigprocmask)
3256 vg_assert(SUCCESS);
3257 if (RES == 0 && ARG3 != 0) {
3258 POST_MEM_WRITE( ARG3, sizeof(vki_sigset_t));
3262 // SYS_sigsuspend 341
3263 // int sigsuspend(const sigset_t *sigmask);
3264 PRE(sys_sigsuspend)
3266 *flags |= SfMayBlock;
3267 PRINT("sys_sigsuspend ( %#" FMT_REGWORD "x )", ARG1 );
3268 PRE_REG_READ1(int, "sigsuspend", const vki_sigset_t *, sigmask);
3269 PRE_MEM_READ( "sigsuspend(sigmask)", ARG1, sizeof(vki_sigset_t) );
3270 if (ARG1) {
3271 ARG1 = ML_(make_safe_mask)("syswrap.sigsuspend.1", (Addr)ARG1);
3275 POST(sys_sigsuspend)
3277 ML_(free_safe_mask) ( (Addr)ARG1 );
3280 // SYS_sigpending 343
3281 // int sigpending(sigset_t *set);
3282 PRE(sys_sigpending)
3284 PRINT( "sys_sigpending ( %#" FMT_REGWORD "x )", ARG1 );
3285 PRE_REG_READ1(int, "sigpending", vki_sigset_t *, set);
3286 PRE_MEM_WRITE( "sigpending(set)", ARG1, sizeof(vki_sigset_t));
3289 POST(sys_sigpending)
3291 POST_MEM_WRITE( ARG1, sizeof(vki_sigset_t) ) ;
3295 // SYS_sigtimedwait 345
3296 // int sigtimedwait(const sigset_t *restrict set, siginfo_t *restrict info,
3297 // const struct timespec *restrict timeout);
3298 PRE(sys_sigtimedwait)
3300 *flags |= SfMayBlock;
3301 PRINT("sys_sigtimedwait ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
3302 ARG1,ARG2,ARG3);
3303 PRE_REG_READ3(int, "sigtimedwait",
3304 const vki_sigset_t *, set, vki_siginfo_t *, info,
3305 const struct timespec *, timeout);
3306 if (ARG1 != 0) {
3307 PRE_MEM_READ( "sigtimedwait(set)", ARG1, sizeof(vki_sigset_t));
3309 if (ARG2 != 0) {
3310 PRE_MEM_WRITE( "sigtimedwait(info)", ARG2, sizeof(vki_siginfo_t) );
3312 if (ARG3 != 0) {
3313 PRE_MEM_READ( "sigtimedwait(timeout)",
3314 ARG3, sizeof(struct vki_timespec) );
3318 POST(sys_sigtimedwait)
3320 if (ARG2 != 0) {
3321 POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) );
3325 // SYS_sigwaitinfo 346
3326 // int sigwaitinfo(const sigset_t * restrict set, siginfo_t * restrict info);
3327 PRE(sys_sigwaitinfo)
3329 *flags |= SfMayBlock;
3330 PRINT("sys_sigwaitinfo ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
3331 ARG1,ARG2);
3332 PRE_REG_READ2(int, "sigwaitinfo",
3333 const vki_sigset_t *, set, vki_siginfo_t *, info);
3334 if (ARG1 != 0) {
3335 PRE_MEM_READ( "sigwaitinfo(set)", ARG1, sizeof(vki_sigset_t));
3337 if (ARG2 != 0) {
3338 PRE_MEM_WRITE( "sigwaitinfo(info)", ARG2, sizeof(vki_siginfo_t) );
3342 POST(sys_sigwaitinfo)
3344 if (ARG2 != 0) {
3345 POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) );
3349 // SYS___acl_get_file 347
3350 // int __acl_get_file(const char *path, acl_type_t type, struct acl *aclp);
3351 PRE(sys___acl_get_file)
3353 PRINT("sys___acl_get_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
3354 PRE_REG_READ3(int, "acl_get_file",
3355 const char *, path, int, type, struct vki_acl *, aclp);
3356 PRE_MEM_RASCIIZ("acl_get_file(path", ARG1);
3357 PRE_MEM_WRITE( "acl_get_file(aclp)", ARG3, sizeof(struct vki_acl) );
3360 POST(sys___acl_get_file)
3362 vg_assert(SUCCESS);
3363 if (RES == 0) {
3364 POST_MEM_WRITE( ARG3, sizeof(struct vki_acl) );
3368 // SYS___acl_set_file 348
3369 // int __acl_set_file(const char *path, acl_type_t type, struct acl *aclp);
3370 PRE(sys___acl_set_file)
3372 PRINT("sys___acl_set_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
3373 PRE_REG_READ3(int, "acl_set_file",
3374 const char *, path, int, type, struct vki_acl *, aclp);
3375 PRE_MEM_RASCIIZ("acl_set_file(path", ARG1);
3376 PRE_MEM_READ("acl_set_file(aclp)", ARG3, sizeof(struct vki_acl) );
3379 // SYS___acl_get_fd 349
3380 // int __acl_get_fd(int filedes, acl_type_t type, struct acl *aclp);
3381 PRE(sys___acl_get_fd)
3383 PRINT("sys___acl_get_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3384 PRE_REG_READ3(int, "acl_get_fd",
3385 int, fd, int, type, struct vki_acl *, aclp);
3386 PRE_MEM_WRITE( "acl_get_file(aclp)", ARG3, sizeof(struct vki_acl) );
3389 POST(sys___acl_get_fd)
3391 vg_assert(SUCCESS);
3392 if (RES == 0) {
3393 POST_MEM_WRITE( ARG3, sizeof(struct vki_acl) );
3397 // SYS___acl_set_fd 350
3398 // int __acl_set_fd(int filedes, acl_type_t type, struct acl *aclp);
3399 PRE(sys___acl_set_fd)
3401 PRINT("sys___acl_set_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3402 PRE_REG_READ3(int, "acl_set_fd",
3403 int, filedes, int, type, struct vki_acl *, aclp);
3404 PRE_MEM_READ( "acl_get_file(aclp)", ARG3, sizeof(struct vki_acl) );
3407 // SYS___acl_delete_file 351
3408 // int __acl_delete_file(const char *path, acl_type_t type);
3409 PRE(sys___acl_delete_file)
3411 PRINT("sys___acl_delete_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char *)ARG1,ARG2);
3412 PRE_MEM_RASCIIZ("acl_set_file(path", ARG1);
3413 PRE_REG_READ2(int, "acl_delete_file",
3414 const char *, path, int, type);
3416 // SYS___acl_delete_fd 352
3417 // int __acl_delete_fd(int filedes, acl_type_t type);
3418 PRE(sys___acl_delete_fd)
3420 PRINT("sys___acl_delete_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2);
3421 PRE_REG_READ2(int, "acl_delete_fd",
3422 int, filedes, int, acltype);
3425 // SYS___acl_aclcheck_file 353
3426 // int __acl_aclcheck_file(const char *path, acl_type_t type, struct acl *aclp);
3427 PRE(sys___acl_aclcheck_file)
3429 PRINT("sys___acl_aclcheck_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
3430 PRE_REG_READ3(int, "acl_aclcheck_file",
3431 const char *, path, int, type, struct vki_acl *, aclp);
3432 PRE_MEM_RASCIIZ("acl_set_file(path", ARG1);
3433 PRE_MEM_READ( "acl_aclcheck_file(aclp)", ARG3, sizeof(struct vki_acl) );
3436 // SYS___acl_aclcheck_fd 354
3437 // int __acl_aclcheck_fd(int filedes, acl_type_t type, struct acl *aclp);
3438 PRE(sys___acl_aclcheck_fd)
3440 PRINT("sys___acl_aclcheck_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3441 PRE_REG_READ3(int, "acl_aclcheck_fd",
3442 int, fd, int, type, struct vki_acl *, aclp);
3443 PRE_MEM_READ( "acl_aclcheck_fd(aclp)", ARG3, sizeof(struct vki_acl) );
3446 // SYS_extattrctl 355
3447 // no manpage?
3448 // syscalls.master: int extattrctl(_In_z_ const char *path, int cmd, _In_z_opt_ const char *filename, int attrnamespace, _In_z_ const char *attrname);
3449 PRE(sys_extattrctl)
3451 PRINT("sys_extattrctl ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3,SARG4,ARG5);
3452 PRE_REG_READ5(ssize_t, "extattrctl",
3453 const char *, path, int, cmd, const char *, filename, int, attrnamespace, const char *, attrname);
3454 PRE_MEM_RASCIIZ("extattrctl(path)", ARG1);
3455 PRE_MEM_RASCIIZ("extattrctl(filename)", ARG3);
3456 PRE_MEM_RASCIIZ("extattrctl(attrname)", ARG5);
3459 // SYS_extattr_set_file 356
3460 // ssize_t extattr_set_file(const char *path, int attrnamespace,
3461 // const char *attrname, const void *data, size_t nbytes);
3462 PRE(sys_extattr_set_file)
3464 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);
3465 PRE_REG_READ5(ssize_t, "extattr_set_file",
3466 const char *, path, int, attrnamespace, const char *, attrname, const void *, data, size_t, nbytes);
3467 PRE_MEM_RASCIIZ("extattr_set_file(path)", ARG1);
3468 PRE_MEM_RASCIIZ("extattr_set_file(attrname)", ARG3);
3469 PRE_MEM_READ("extattr_set_file(data)", ARG4, ARG5);
3472 // SYS_extattr_get_file 357
3473 // ssize_t extattr_get_file(const char *path, int attrnamespace,
3474 // const char *attrname, void *data, size_t nbytes);
3475 PRE(sys_extattr_get_file)
3477 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);
3478 PRE_REG_READ5(ssize_t, "extattr_get_file",
3479 const char *, path, int, attrnamespace, const char *, attrname, void *, data, size_t, nbytes);
3480 PRE_MEM_RASCIIZ("extattr_get_file(path)", ARG1);
3481 PRE_MEM_RASCIIZ("extattr_get_file(attrname)", ARG3);
3482 if (ARG4) {
3483 PRE_MEM_WRITE("extattr_get_file(data)", ARG4, ARG5);
3487 POST(sys_extattr_get_file)
3489 if (ARG4) {
3490 POST_MEM_WRITE(ARG4, ARG5);
3494 // SYS_extattr_delete_file 358
3495 // int extattr_delete_file(const char *path, int attrnamespace,
3496 // const char *attrname);
3497 PRE(sys_extattr_delete_file)
3499 PRINT("sys_extattr_delete_file ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3);
3500 PRE_REG_READ3(ssize_t, "extattr_delete_file",
3501 const char *, path, int, attrnamespace, const char *, attrname);
3502 PRE_MEM_RASCIIZ("extattr_delete_file(path)", ARG1);
3503 PRE_MEM_RASCIIZ("extattr_delete_file(attrname)", ARG3);
3506 // SYS_aio_waitcomplete 359
3507 // ssize_t aio_waitcomplete(struct aiocb **iocbp, struct timespec *timeout);
3508 PRE(sys_aio_waitcomplete)
3510 *flags |= SfMayBlock;
3511 PRINT("sys_aio_waitcomplete ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2);
3512 PRE_REG_READ2(ssize_t, "aio_waitcomplete", struct aiocb **, iocbp, struct timespec *, timeout);
3513 if (ARG2) {
3514 PRE_MEM_READ("aio_waitcomplete(timeout", ARG2, sizeof(struct vki_timespec));
3516 PRE_MEM_WRITE( "aio_waitcomplete(iocbp)", ARG1, sizeof(struct aiocb *));
3519 POST(sys_aio_waitcomplete)
3521 POST_MEM_WRITE(ARG1, sizeof(struct aiocb *));
3524 // SYS_getresuid 360
3525 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
3526 PRE(sys_getresuid)
3528 PRINT("sys_getresuid ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3529 PRE_REG_READ3(long, "getresuid",
3530 vki_uid_t *, ruid, vki_uid_t *, euid, vki_uid_t *, suid);
3531 PRE_MEM_WRITE( "getresuid(ruid)", ARG1, sizeof(vki_uid_t) );
3532 PRE_MEM_WRITE( "getresuid(euid)", ARG2, sizeof(vki_uid_t) );
3533 PRE_MEM_WRITE( "getresuid(suid)", ARG3, sizeof(vki_uid_t) );
3536 POST(sys_getresuid)
3538 vg_assert(SUCCESS);
3539 if (RES == 0) {
3540 POST_MEM_WRITE( ARG1, sizeof(vki_uid_t) );
3541 POST_MEM_WRITE( ARG2, sizeof(vki_uid_t) );
3542 POST_MEM_WRITE( ARG3, sizeof(vki_uid_t) );
3546 // SYS_getresgid 361
3547 // int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid);
3548 PRE(sys_getresgid)
3550 PRINT("sys_getresgid ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3551 PRE_REG_READ3(long, "getresgid",
3552 vki_gid_t *, rgid, vki_gid_t *, egid, vki_gid_t *, sgid);
3553 PRE_MEM_WRITE( "getresgid(rgid)", ARG1, sizeof(vki_gid_t) );
3554 PRE_MEM_WRITE( "getresgid(egid)", ARG2, sizeof(vki_gid_t) );
3555 PRE_MEM_WRITE( "getresgid(sgid)", ARG3, sizeof(vki_gid_t) );
3558 POST(sys_getresgid)
3560 vg_assert(SUCCESS);
3561 if (RES == 0) {
3562 POST_MEM_WRITE( ARG1, sizeof(vki_gid_t) );
3563 POST_MEM_WRITE( ARG2, sizeof(vki_gid_t) );
3564 POST_MEM_WRITE( ARG3, sizeof(vki_gid_t) );
3568 // SYS_kqueue 362
3569 // int kqueue(void);
3570 PRE(sys_kqueue)
3572 PRINT("%s", "sys_kqueue(void)");
3573 PRE_REG_READ0(int, "kqueue");
3576 POST(sys_kqueue)
3578 if (!ML_(fd_allowed)(RES, "kqueue", tid, True)) {
3579 VG_(close)(RES);
3580 SET_STATUS_Failure( VKI_EMFILE );
3581 } else {
3582 if (VG_(clo_track_fds)) {
3583 ML_(record_fd_open_nameless)(tid, RES);
3588 // SYS_freebsd11_kevent 363
3589 // int kevent(int kq, const struct kevent *changelist, int nchanges,
3590 // struct kevent *eventlist, int nevents,
3591 // const struct timespec *timeout);
3592 #if (FREEBSD_VERS >= FREEBSD_12)
3593 PRE(sys_freebsd11_kevent)
3595 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);
3596 PRE_REG_READ6(int, "kevent",
3597 int, fd, const struct vki_kevent_freebsd11 *, changelist, int, nchanges,
3598 struct vki_kevent_freebsd11 *, eventlist, int, nevents,
3599 struct timespec *, timeout);
3600 if (ARG2 != 0 && ARG3 != 0) {
3601 PRE_MEM_READ( "kevent(changelist)", ARG2, sizeof(struct vki_kevent_freebsd11)*ARG3 );
3603 if (ARG4 != 0 && ARG5 != 0) {
3604 PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent_freebsd11)*ARG5);
3606 if (ARG5 != 0) {
3607 *flags |= SfMayBlock;
3609 if (ARG6 != 0) {
3610 PRE_MEM_READ( "kevent(timeout)",
3611 ARG6, sizeof(struct vki_timespec));
3615 POST(sys_freebsd11_kevent)
3617 vg_assert(SUCCESS);
3618 if ((Word)RES != -1) {
3619 if (ARG4 != 0) {
3620 POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent_freebsd11)*RES) ;
3624 #else
3625 PRE(sys_kevent)
3627 *flags |= SfMayBlock;
3628 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);
3629 PRE_REG_READ6(int, "kevent",
3630 int, fd, struct vki_kevent_freebsd11 *, changelist, int, nchanges,
3631 struct vki_kevent_freebsd11 *, eventlist, int, nevents,
3632 struct timespec *, timeout);
3633 if (ARG2 != 0 && ARG3 != 0)
3634 PRE_MEM_READ( "kevent(changelist)", ARG2, sizeof(struct vki_kevent_freebsd11)*ARG3 );
3635 if (ARG4 != 0 && ARG5 != 0)
3636 PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent_freebsd11)*ARG5);
3637 if (ARG6 != 0)
3638 PRE_MEM_READ( "kevent(timeout)",
3639 ARG6, sizeof(struct vki_timespec));
3642 POST(sys_kevent)
3644 vg_assert(SUCCESS);
3645 if ((Word)RES != -1) {
3646 if (ARG4 != 0)
3647 POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent_freebsd11)*RES) ;
3650 #endif
3652 // SYS_extattr_set_fd 371
3653 // ssize_t extattr_set_fd(int fd, int attrnamespace, const char *attrname,
3654 // const void *data, size_t nbytes);
3655 PRE(sys_extattr_set_fd)
3657 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);
3658 PRE_REG_READ5(int, "extattr_set_fd", int, fd, int, attrnamespace, const char *,attrname, const void *,data, size_t, nbytes);
3659 PRE_MEM_RASCIIZ( "extattr_set_fd(attrname)", ARG3 );
3660 PRE_MEM_READ("extattr_set_fd(data)", ARG4, ARG5);
3663 // SYS_extattr_get_fd 372
3664 // ssize_t extattr_get_fd(int fd, int attrnamespace, const char *attrname,
3665 // void *data, size_t nbytes);
3666 PRE(sys_extattr_get_fd)
3668 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);
3669 PRE_REG_READ5(int, "extattr_get_fd", int, fd, int, attrnamespace, const char *,attrname, const void *,data, size_t, nbytes);
3670 PRE_MEM_RASCIIZ( "extattr_get_fd(attrname)", ARG3 );
3671 PRE_MEM_WRITE("extattr_get_fd(data)", ARG4, ARG5);
3674 POST(sys_extattr_get_fd)
3676 POST_MEM_WRITE(ARG4, ARG5);
3679 // SYS_extattr_delete_fd 373
3680 // int extattr_delete_fd(int fd, int attrnamespace, const char *attrname);
3681 PRE(sys_extattr_delete_fd)
3683 PRINT("sys_extattr_delete_fd ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3);
3684 PRE_REG_READ3(int, "extattr_delete_fd", int, fd, int, attrnamespace, const char *,attrname);
3685 PRE_MEM_RASCIIZ( "extattr_delete_fd(attrname)", ARG3 );
3688 // SYS___setugid 374
3689 // no manpage?
3690 // syscalls.master: int __setugid(int flag);
3691 PRE(sys___setugid)
3693 PRINT("sys___setugid ( %" FMT_REGWORD "d )", SARG1);
3694 PRE_REG_READ1(int, "__setugid", int, flag);
3697 // SYS_eaccess 376
3698 // int eaccess(const char *path, int mode);
3699 PRE(sys_eaccess)
3701 PRINT("sys_eaccess ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char*)ARG1,ARG2);
3702 PRE_REG_READ2(int, "eaccess", const char *, path, int, mode);
3703 PRE_MEM_RASCIIZ( "eaccess(path)", ARG1 );
3706 // SYS_afs3_syscall 377
3707 // @todo
3709 // SYS_nmount 378
3710 // int nmount(struct iovec *iov, u_int niov, int flags);
3711 PRE(sys_nmount)
3713 PRINT("sys_nmount ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d )", ARG1, ARG2, SARG3);
3714 PRE_REG_READ3(int, "nmount", struct iovec *, iov, u_int, niov, int, flags);
3715 PRE_MEM_READ( "nmount(pathname)", ARG1, ARG2*sizeof(struct vki_iovec) );
3718 // SYS___mac_get_proc 384
3719 // @todo
3721 // SYS___mac_set_proc 385
3722 // @todo
3724 // SYS___mac_get_fd 386
3725 // @todo
3727 // SYS___mac_get_file 387
3728 // @todo
3730 // SYS___mac_set_fd 388
3731 // @todo
3733 // SYS___mac_set_file 389
3734 // @todo
3736 // SYS_kenv 390
3737 // int kenv(int action, const char *name, char *value, int len);
3738 PRE(sys_kenv)
3740 PRINT("sys_kenv ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3,ARG4);
3741 PRE_REG_READ4(int, "kenv",
3742 int, action, const char *, name, char *, value, int, len);
3743 switch (ARG1) {
3744 case VKI_KENV_GET:
3745 case VKI_KENV_SET:
3746 case VKI_KENV_UNSET:
3747 PRE_MEM_RASCIIZ("kenv(name)", ARG2);
3748 /* FALLTHROUGH */
3749 case VKI_KENV_DUMP:
3750 break;
3751 default:
3752 VG_(dmsg)("Warning: Bad action %" FMT_REGWORD "u in kenv\n", ARG1);
3756 POST(sys_kenv)
3758 if (SUCCESS) {
3759 switch (ARG1) {
3760 case VKI_KENV_GET:
3761 POST_MEM_WRITE(ARG3, ARG4);
3762 break;
3763 case VKI_KENV_DUMP:
3764 if (ARG3 != (Addr)NULL) {
3765 POST_MEM_WRITE(ARG3, ARG4);
3767 break;
3772 // SYS_lchflags 391
3773 // int lchflags(const char *path, unsigned long flags);
3774 PRE(sys_lchflags)
3776 PRINT("sys_lchflags ( %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2);
3777 PRE_REG_READ2(int, "lchflags",
3778 const char *, path, unsigned long, flags);
3779 PRE_MEM_RASCIIZ( "lchflags(path)", ARG1 );
3782 // SYS_uuidgen 392
3783 // int uuidgen(struct uuid *store, int count);
3784 PRE(sys_uuidgen)
3786 PRINT("sys_uuidgen ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2);
3787 PRE_REG_READ2(int, "uuidgen",
3788 struct vki_uuid *, store, int, count);
3789 PRE_MEM_WRITE( "uuidgen(store)", ARG1, ARG2 * sizeof(struct vki_uuid));
3792 POST(sys_uuidgen)
3794 if (SUCCESS) {
3795 POST_MEM_WRITE( ARG1, ARG2 * sizeof(struct vki_uuid) );
3799 // SYS_sendfile 393
3800 // x86/amd64
3802 // SYS_mac_syscall 394
3803 // @todo
3805 #if (FREEBSD_VERS >= FREEBSD_12)
3807 // SYS_freebsd11_getfsstat 395
3808 // int getfsstat(struct freebsd11_statfs *buf, long bufsize, int mode);
3810 PRE(sys_freebsd11_getfsstat)
3812 PRINT("sys_freebsd11_getfsstat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
3813 PRE_REG_READ3(int, "getfsstat", struct vki_freebsd11_statfs *, buf, long, bufsize, int, mode);
3814 PRE_MEM_WRITE( "getfsstat(buf)", ARG1, ARG2 );
3817 POST(sys_freebsd11_getfsstat)
3819 vg_assert(SUCCESS);
3820 if ((Word)RES != -1) {
3821 POST_MEM_WRITE( ARG1, RES * sizeof(struct vki_freebsd11_statfs) );
3825 // SYS_freebsd11_statfs 396
3826 // int statfs(const char *path, struct statfs *buf);
3827 PRE(sys_freebsd11_statfs)
3829 PRINT("sys_statfs ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
3830 PRE_REG_READ2(int, "statfs", const char *, path, struct statfs *, buf);
3831 PRE_MEM_RASCIIZ( "statfs(path)", ARG1 );
3832 PRE_MEM_WRITE( "statfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3835 POST(sys_freebsd11_statfs)
3837 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3840 // SYS_freebsd11_fstatfs 397
3841 // int fstatfs(int fd, struct statfs *buf);
3842 PRE(sys_freebsd11_fstatfs)
3844 PRINT("sys_fstatfs ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2);
3845 PRE_REG_READ2(int, "fstatfs",
3846 unsigned int, fd, struct statfs *, buf);
3847 PRE_MEM_WRITE( "fstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3850 POST(sys_freebsd11_fstatfs)
3852 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3855 // SYS_freebsd11_fhstatfs 398
3856 // int fhstatfs(const fhandle_t *fhp, struct statfs *buf);
3857 PRE(sys_freebsd11_fhstatfs)
3859 PRINT("sys_fhstatfs ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
3860 PRE_REG_READ2(int, "fhstatfs",
3861 struct fhandle *, fhp, struct statfs *, buf);
3862 PRE_MEM_READ( "fhstatfs(fhp)", ARG1, sizeof(struct vki_fhandle) );
3863 PRE_MEM_WRITE( "fhstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3866 POST(sys_freebsd11_fhstatfs)
3868 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3872 #else
3874 PRE(sys_getfsstat)
3876 PRINT("sys_getfsstat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
3877 PRE_REG_READ3(int, "getfsstat", struct vki_freebsd11_statfs *, buf, long, bufsize, int, mode);
3878 PRE_MEM_WRITE( "getfsstat(buf)", ARG1, ARG2 );
3881 POST(sys_getfsstat)
3883 vg_assert(SUCCESS);
3884 if ((Word)RES != -1) {
3885 POST_MEM_WRITE( ARG1, RES * sizeof(struct vki_freebsd11_statfs) );
3889 PRE(sys_statfs)
3891 PRINT("sys_statfs ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
3892 PRE_REG_READ2(int, "statfs", const char *, path, struct statfs *, buf);
3893 PRE_MEM_RASCIIZ( "statfs(path)", ARG1 );
3894 PRE_MEM_WRITE( "statfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3897 POST(sys_statfs)
3899 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3902 PRE(sys_fstatfs)
3904 PRINT("sys_fstatfs ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2);
3905 PRE_REG_READ2(int, "fstatfs",
3906 unsigned int, fd, struct statfs *, buf);
3907 PRE_MEM_WRITE( "fstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3910 POST(sys_fstatfs)
3912 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3915 PRE(sys_fhstatfs)
3917 PRINT("sys_fhstatfs ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
3918 PRE_REG_READ2(int, "fhstatfs",
3919 struct fhandle *, fhp, struct statfs *, buf);
3920 PRE_MEM_READ( "fhstatfs(fhp)", ARG1, sizeof(struct vki_fhandle) );
3921 PRE_MEM_WRITE( "fhstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3924 POST(sys_fhstatfs)
3926 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3930 #endif
3932 // SYS_ksem_close 400
3933 // @todo
3935 // SYS_ksem_post 401
3936 // @todo
3938 // SYS_ksem_wait 402
3939 // @todo
3941 // SYS_ksem_trywait 403
3942 // @todo
3944 // SYS_ksem_init 404
3945 // @todo
3947 // SYS_ksem_open 405
3948 // @todo
3950 // SYS_ksem_unlink 406
3951 // @todo
3953 // SYS_ksem_getvalue 407
3954 // @todo
3956 // SYS_ksem_destroy 408
3957 // @todo
3959 // SYS___mac_get_pid 409
3960 // @todo
3962 // SYS___mac_get_link 410
3963 // @todo
3965 // SYS___mac_set_link 411
3966 // @todo
3968 // SYS_extattr_set_link 412
3969 // ssize_t extattr_set_link(const char *path, int attrnamespace,
3970 // const char *attrname, const void *data, size_t nbytes);
3971 PRE(sys_extattr_set_link)
3973 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);
3974 PRE_REG_READ5(ssize_t, "extattr_set_link",
3975 const char *, path, int, attrnamespace, const char *, attrname, const void *, data, size_t, nbytes);
3976 PRE_MEM_RASCIIZ("extattr_set_link(path)", ARG1);
3977 PRE_MEM_RASCIIZ("extattr_set_link(attrname)", ARG3);
3978 PRE_MEM_READ("extattr_set_link(data)", ARG4, ARG5);
3981 // SYS_extattr_get_link 413
3982 // ssize_t extattr_get_link(const char *path, int attrnamespace,
3983 // const char *attrname, void *data, size_t nbytes);
3984 PRE(sys_extattr_get_link)
3986 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);
3987 PRE_REG_READ5(ssize_t, "extattr_get_link",
3988 const char *, path, int, attrnamespace, const char *, attrname, void *, data, size_t, nbytes);
3989 PRE_MEM_RASCIIZ("extattr_get_link(path)", ARG1);
3990 PRE_MEM_RASCIIZ("extattr_get_link(attrname)", ARG3);
3991 if (ARG4) {
3992 PRE_MEM_WRITE("extattr_get_link(data)", ARG4, ARG5);
3996 POST(sys_extattr_get_link)
3998 if (ARG4) {
3999 POST_MEM_WRITE(ARG4, ARG5);
4003 // SYS_extattr_delete_link 414
4004 // int extattr_delete_link(const char *path, int attrnamespace,
4005 // const char *attrname);
4006 PRE(sys_extattr_delete_link)
4008 PRINT("sys_extattr_delete_link ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3);
4009 PRE_REG_READ3(ssize_t, "extattr_delete_link",
4010 const char *, path, int, attrnamespace, const char *, attrname);
4011 PRE_MEM_RASCIIZ("extattr_delete_link(path)", ARG1);
4012 PRE_MEM_RASCIIZ("extattr_delete_link(attrname)", ARG3);
4015 // SYS___mac_execve 415
4016 // @todo
4018 // SYS_sigaction 416
4019 //int sigaction(int sig, const struct sigaction * restrict act,
4020 // struct sigaction * restrict oact);
4021 PRE(sys_sigaction)
4023 vki_sigaction_toK_t new;
4024 vki_sigaction_toK_t *newp;
4025 vki_sigaction_fromK_t old;
4026 vki_sigaction_fromK_t *oldp;
4028 PRINT("sys_sigaction ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
4029 SARG1,ARG2,ARG3);
4030 PRE_REG_READ3(long, "sigaction",
4031 int, sign, const struct sigaction *, act,
4032 struct sigaction *, oact);
4034 newp = oldp = NULL;
4036 if (ARG2 != 0) {
4037 struct vki_sigaction *sa = (struct vki_sigaction *)ARG2;
4038 PRE_MEM_READ( "sigaction(act->sa_handler)", (Addr)&sa->ksa_handler, sizeof(sa->ksa_handler));
4039 PRE_MEM_READ( "sigaction(act->sa_mask)", (Addr)&sa->sa_mask, sizeof(sa->sa_mask));
4040 PRE_MEM_READ( "sigaction(act->sa_flags)", (Addr)&sa->sa_flags, sizeof(sa->sa_flags));
4043 if (ARG3 != 0) {
4044 PRE_MEM_WRITE( "sigaction(oact)", ARG3, sizeof(struct vki_sigaction));
4045 oldp = &old;
4048 if (ARG2 != 0
4049 && ! ML_(safe_to_deref)((void *)(Addr)ARG2,
4050 sizeof(struct vki_sigaction))) {
4051 VG_(umsg)("Warning: bad act handler address %p in sigaction()\n",
4052 (void *)(Addr)ARG2);
4053 SET_STATUS_Failure ( VKI_EFAULT );
4054 } else if ((ARG3 != 0
4055 && ! ML_(safe_to_deref)((void *)(Addr)ARG3,
4056 sizeof(struct vki_sigaction)))) {
4057 VG_(umsg)("Warning: bad oact handler address %p in sigaction()\n",
4058 (void *)(Addr)ARG3);
4059 SET_STATUS_Failure ( VKI_EFAULT );
4060 } else {
4061 if (ARG2 != 0) {
4062 struct vki_sigaction *oldnew =
4063 (struct vki_sigaction *)(Addr)ARG2;
4065 new.ksa_handler = oldnew->ksa_handler;
4066 new.sa_flags = oldnew->sa_flags;
4067 new.sa_mask = oldnew->sa_mask;
4068 newp = &new;
4071 SET_STATUS_from_SysRes( VG_(do_sys_sigaction)(ARG1, newp, oldp) );
4073 if (ARG3 != 0 && SUCCESS && RES == 0) {
4074 struct vki_sigaction *oldold =
4075 (struct vki_sigaction *)(Addr)ARG3;
4077 oldold->ksa_handler = oldp->ksa_handler;
4078 oldold->sa_flags = oldp->sa_flags;
4079 oldold->sa_mask = oldp->sa_mask;
4084 POST(sys_sigaction)
4086 vg_assert(SUCCESS);
4087 if (RES == 0 && ARG3 != 0) {
4088 POST_MEM_WRITE( ARG3, sizeof(struct vki_sigaction));
4092 // SYS_sigreturn 417
4093 // x86/amd64
4095 // SYS_getcontext 421
4096 // SYS_setcontext 422
4097 // SYS_swapcontext 423
4098 // PRE in x86/amd64
4100 POST(sys_getcontext)
4102 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucontext) );
4105 POST(sys_swapcontext)
4107 if (SUCCESS) {
4108 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucontext) );
4112 #if (FREEBSD_VERS >= FREEBSD_13_1)
4113 // SYS_freebsd13_swapoff 424
4114 // int swapoff(const char *special);
4115 PRE(sys_freebsd13_swapoff)
4117 PRINT("sys_freebsd13_swapoff ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
4118 PRE_REG_READ1(int, "swapoff", const char *, special);
4119 PRE_MEM_RASCIIZ( "swapoff(special)", ARG1 );
4121 #else
4122 // SYS_swapoff 424
4123 // int swapoff(const char *special);
4124 PRE(sys_swapoff)
4126 PRINT("sys_swapoff ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
4127 PRE_REG_READ1(int, "swapoff", const char *, special);
4128 PRE_MEM_RASCIIZ( "swapoff(special)", ARG1 );
4130 #endif
4132 // SYS___acl_get_link 425
4133 // int __acl_get_link(const char *path, acl_type_t type, struct acl *aclp);
4134 PRE(sys___acl_get_link)
4136 PRINT("sys___acl_get_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
4137 PRE_REG_READ3(int, "__acl_get_link",
4138 const char *, path, int, acltype, struct vki_acl *, aclp);
4139 PRE_MEM_RASCIIZ( "__acl_get_link(path)", ARG1 );
4140 PRE_MEM_WRITE( "__acl_get_link(aclp)", ARG3, sizeof(struct vki_acl) );
4143 POST(sys___acl_get_link)
4145 vg_assert(SUCCESS);
4146 if (RES == 0) {
4147 POST_MEM_WRITE( ARG3, sizeof(struct vki_acl) );
4151 // SYS___acl_set_link 426
4152 // int __acl_set_link(const char *path, acl_type_t type, struct acl *aclp);
4153 PRE(sys___acl_set_link)
4155 PRINT("sys___acl_set_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
4156 PRE_REG_READ3(int, "__acl_set_link",
4157 const char *, path, int, acltype, struct vki_acl *, aclp);
4158 PRE_MEM_RASCIIZ( "__acl_set_link(path)", ARG1 );
4159 PRE_MEM_READ( "__acl_set_link(aclp)", ARG3, sizeof(struct vki_acl) );
4161 // SYS___acl_delete_link 427
4162 // int __acl_delete_link(const char *path, acl_type_t type);
4163 PRE(sys___acl_delete_link)
4165 PRINT("sys___acl_delete_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char *)ARG1,ARG2);
4166 PRE_MEM_RASCIIZ( "__acl_delete_link(path)", ARG1 );
4167 PRE_REG_READ2(int, "__acl_delete_link",
4168 const char *, path, int, acltype);
4171 // SYS___acl_aclcheck_link 428
4172 // int __acl_aclcheck_link(const char *path, acl_type_t type, struct acl *aclp);
4173 PRE(sys___acl_aclcheck_link)
4175 PRINT("sys___acl_aclcheck_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
4176 PRE_REG_READ3(long, "__acl_aclcheck_link",
4177 const char *, path, int, acltype, struct vki_acl *, aclp);
4178 PRE_MEM_RASCIIZ( "__acl_check_link(path)", ARG1 );
4179 PRE_MEM_READ( "__acl_aclcheck_link(aclp)", ARG3, sizeof(struct vki_acl) );
4182 // SYS_sigwait 429
4183 // int sigwait(const sigset_t * restrict set, int * restrict sig);
4184 PRE(sys_sigwait)
4186 *flags |= SfMayBlock;
4187 PRINT("sys_sigwait ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
4188 ARG1,ARG2);
4189 PRE_REG_READ2(int, "sigwait",
4190 const vki_sigset_t *, set, int *, sig);
4191 if (ARG1 != 0) {
4192 PRE_MEM_READ( "sigwait(set)", ARG1, sizeof(vki_sigset_t));
4194 if (ARG2 != 0) {
4195 PRE_MEM_WRITE( "sigwait(sig)", ARG2, sizeof(int));
4199 POST(sys_sigwait)
4201 if (ARG2 != 0) {
4202 POST_MEM_WRITE( ARG2, sizeof(int));
4206 // SYS_thr_create 430
4207 // no manpage?
4208 // syscalls.master: int thr_create(_In_ ucontext_t *ctx, _Out_ long *id, int flags );
4209 PRE(sys_thr_create)
4211 PRINT( "sys_thr_create ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )", ARG1, ARG2, SARG3 );
4212 PRE_REG_READ3(int, "thr_create", /*ucontext_t*/void *, ctx, long *, id, int, flags );
4214 VG_(message)(Vg_UserMsg, "thr_create() not implemented");
4215 VG_(unimplemented)("Valgrind does not support thr_create().");
4217 SET_STATUS_Failure(VKI_ENOSYS);
4220 // SYS_thr_exit 431
4221 // void thr_exit(long *state);
4222 PRE(sys_thr_exit)
4224 ThreadState *tst;
4226 PRINT( "sys_thr_exit ( %#" FMT_REGWORD "x )", ARG1 );
4227 PRE_REG_READ1(void, "thr_exit", long *, state);
4229 if (ARG1) {
4230 PRE_MEM_WRITE( "thr_exit(state)", ARG1, sizeof(long) );
4233 tst = VG_(get_ThreadState)(tid);
4234 tst->exitreason = VgSrc_ExitThread;
4235 tst->os_state.exitcode = ARG1;
4236 SET_STATUS_Success(0);
4239 // SYS_thr_self 432
4240 // int thr_self(long *id);
4241 PRE(sys_thr_self)
4243 PRINT( "sys_thr_self ( %#" FMT_REGWORD "x )", ARG1 );
4244 PRE_REG_READ1(int, "thr_self", long *, id);
4245 PRE_MEM_WRITE( "thr_self()", ARG1, sizeof(long));
4248 POST(sys_thr_self)
4250 POST_MEM_WRITE( ARG1, sizeof(long));
4253 // SYS_thr_kill 433
4254 // int thr_kill(long id, int sig);
4255 PRE(sys_thr_kill)
4257 PRINT("sys_thr_kill ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2);
4258 PRE_REG_READ2(long, "thr_kill", long, id, int, sig);
4259 if (!ML_(client_signal_OK)(ARG2)) {
4260 SET_STATUS_Failure( VKI_EINVAL );
4261 return;
4264 /* Check to see if this kill gave us a pending signal */
4265 *flags |= SfPollAfter;
4267 if (VG_(clo_trace_signals)) {
4268 VG_(message)(Vg_DebugMsg, "thr_kill: sending signal %lu to tid %lu\n",
4269 ARG2, ARG1);
4272 /* If we're sending SIGKILL, check to see if the target is one of
4273 our threads and handle it specially. */
4274 if (ARG2 == VKI_SIGKILL && ML_(do_sigkill)(ARG1, -1)) {
4275 SET_STATUS_Success(0);
4276 return;
4279 /* Ask to handle this syscall via the slow route, since that's the
4280 only one that sets tst->status to VgTs_WaitSys. If the result
4281 of doing the syscall is an immediate run of
4282 async_signalhandler() in m_signals, then we need the thread to
4283 be properly tidied away. I have the impression the previous
4284 version of this wrapper worked on x86/amd64 only because the
4285 kernel did not immediately deliver the async signal to this
4286 thread (on ppc it did, which broke the assertion re tst->status
4287 at the top of async_signalhandler()). */
4288 *flags |= SfMayBlock;
4291 POST(sys_thr_kill)
4293 if (VG_(clo_trace_signals)) {
4294 VG_(message)(Vg_DebugMsg, "thr_kill: sent signal %lu to tid %lu\n",
4295 ARG2, ARG1);
4299 #if (FREEBSD_VERS <= FREEBSD_10)
4300 // SYS__umtx_lock 434
4301 PRE(sys__umtx_lock)
4303 PRINT( "sys__umtx_lock ( %#" FMT_REGWORD "x )", ARG1);
4304 PRE_REG_READ1(long, "_umtx_lock", struct vki_umtx *, umtx);
4305 PRE_MEM_READ( "_umtx_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4306 PRE_MEM_WRITE( "_umtx_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4309 POST(sys__umtx_lock)
4311 if (SUCCESS) {
4312 POST_MEM_WRITE(ARG1, sizeof(struct vki_umtx));
4316 // SYS__umtx_unlock 434
4317 PRE(sys__umtx_unlock)
4319 PRINT( "sys__umtx_unlock ( %#" FMT_REGWORD "x )", ARG1);
4320 PRE_REG_READ1(long, "_umtx_unlock", struct vki_umtx *, umtx);
4321 PRE_MEM_READ( "_umtx_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4322 PRE_MEM_WRITE( "_umtx_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4325 POST(sys__umtx_unlock)
4327 if (SUCCESS) {
4328 POST_MEM_WRITE(ARG1, sizeof(struct vki_umtx));
4331 #endif
4333 // SYS_jail_attach 436
4334 // int jail_attach(int jid);
4335 PRE(sys_jail_attach)
4337 PRINT("sys_jail_attach ( %" FMT_REGWORD "d )", SARG1);
4338 PRE_REG_READ1(int, "jail_attach", int, jid);
4341 // SYS_extattr_list_fd 437
4342 // ssize_t extattr_list_fd(int fd, int attrnamespace, void *data, size_t nbytes);
4343 PRE(sys_extattr_list_fd)
4345 PRINT("extattr_list_fd ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", SARG1, SARG2, ARG3, ARG4);
4346 PRE_REG_READ4(ssize_t, "extattr_list_fd", int, id, int, attrnamespace, void *,data, size_t, nbytes);
4347 PRE_MEM_WRITE("extattr_list_fd(data)", ARG3, ARG4);
4350 POST(sys_extattr_list_fd)
4352 POST_MEM_WRITE(ARG3, ARG4);
4355 // SYS_extattr_list_file 438
4356 // ssize_t extattr_list_file(const char *path, int attrnamespace, void *data,
4357 // size_t nbytes);
4358 PRE(sys_extattr_list_file)
4360 PRINT("extattr_list_file ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, SARG2, ARG3, ARG4);
4361 PRE_REG_READ4(ssize_t, "extattr_list_file", const char *, path, int, attrnamespace, void *,data, size_t, nbytes);
4362 PRE_MEM_RASCIIZ("extattr_list_file(path)", ARG1);
4363 PRE_MEM_WRITE("extattr_list_file(data)", ARG3, ARG4);
4366 POST(sys_extattr_list_file)
4368 POST_MEM_WRITE(ARG3, ARG4);
4371 // SYS_extattr_list_link 439
4372 // ssize_t extattr_get_link(const char *path, int attrnamespace,
4373 // const char *attrname, void *data, size_t nbytes);
4374 PRE(sys_extattr_list_link)
4376 PRINT("extattr_list_link ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, SARG2, ARG3, ARG4);
4377 PRE_REG_READ4(ssize_t, "extattr_list_link", const char *, path, int, attrnamespace, void *,data, size_t, nbytes);
4378 PRE_MEM_RASCIIZ("extattr_list_link(path)", ARG1);
4379 PRE_MEM_WRITE("extattr_list_link(data)", ARG3, ARG4);
4382 POST(sys_extattr_list_link)
4384 POST_MEM_WRITE(ARG3, ARG4);
4387 // SYS_ksem_timedwait 441
4388 // @todo
4390 // SYS_thr_suspend 442
4391 // int thr_suspend(struct timespec *timeout);
4392 PRE(sys_thr_suspend)
4394 PRINT("sys_thr_suspend ( %#" FMT_REGWORD "x )", ARG1);
4395 PRE_REG_READ1(int, "thr_suspend", struct timespec *, timeout);
4396 PRE_MEM_READ("thr_suspend(timeout)", ARG1, sizeof(struct vki_timespec));
4398 VG_(message)(Vg_UserMsg, "thr_supend() not implemented");
4399 VG_(unimplemented)("Valgrind does not support thr_suspend().");
4401 SET_STATUS_Failure(VKI_ENOSYS);
4404 // SYS_thr_wake 443
4405 // int thr_wake(long id);
4406 PRE(sys_thr_wake)
4408 PRINT("sys_thr_wake ( %" FMT_REGWORD "d )", SARG1);
4409 PRE_REG_READ1(long, "thr_wake", long, id);
4411 if (VG_(is_valid_tid)(ARG1)) {
4412 VG_(threads)[ARG1].status = VgTs_Runnable;
4413 } else {
4414 SET_STATUS_Failure( VKI_ESRCH );
4419 // SYS_kldunloadf 444
4420 // int kldunloadf(int fileid, int flags);
4421 PRE(sys_kldunloadf)
4423 PRINT("sys_kldunloadf ( %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1, SARG2);
4424 PRE_REG_READ2(int, "kldunloadf", int, fileid, int, flags);
4427 // SYS_audit 445
4428 // int audit(const char *record, u_int length);
4429 // @todo
4431 // SYS_auditon 446
4432 // int auditon(int cmd, void *data, u_int length);
4433 // @todo
4435 // SYS_getauid 447
4436 // int getauid(au_id_t *auid);
4437 // @todo
4439 // SYS_setauid 448
4440 // int setauid(au_id_t *auid);
4441 // @todo
4443 // SYS_getaudit 449
4444 // int getaudit(auditinfo_t *auditinfo);
4445 // @todo
4447 // SYS_setaudit 450
4448 // int setaudit(auditinfo_t *auditinfo);
4449 // @todo
4451 // SYS_getaudit_addr 451
4452 // int getaudit_addr(auditinfo_addr_t *auditinfo_addr, u_int length);
4453 // @todo
4455 // SYS_setaudit_addr 452
4456 // int setaudit_addr(auditinfo_addr_t *auditinfo_addr, u_int length);
4457 // @todo
4459 // SYS_auditctl 453
4460 // @todo
4462 // SYS__umtx_op 454
4463 // int _umtx_op(void *obj, int op, u_long val, void *uaddr, void *uaddr2);
4464 PRE(sys__umtx_op)
4466 /* 5 args are always passed through. The last two can vary, but
4467 they're always pointers. They may not be used though. */
4468 switch(ARG2) {
4469 case VKI_UMTX_OP_LOCK:
4470 // marked as COMPAT10
4471 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, LOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4472 PRE_REG_READ5(long, "_umtx_op_lock",
4473 struct umtx *, obj, int, op, unsigned long, id,
4474 size_t, timeout_size, struct vki_timespec *, timeout);
4475 PRE_MEM_READ( "_umtx_op_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4476 if (ARG5) {
4477 PRE_MEM_READ( "_umtx_op_lock(timespec)", ARG5, ARG4 );
4479 PRE_MEM_WRITE( "_umtx_op_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4480 *flags |= SfMayBlock;
4481 break;
4482 case VKI_UMTX_OP_UNLOCK:
4483 // marked as COMPAT10
4484 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, UNLOCK, %" FMT_REGWORD "u)", ARG1, ARG3);
4485 PRE_REG_READ3(long, "_umtx_op_unlock",
4486 struct umtx *, obj, int, op, unsigned long, id);
4487 PRE_MEM_READ( "_umtx_op_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4488 PRE_MEM_WRITE( "_umtx_op_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4489 break;
4490 case VKI_UMTX_OP_WAIT:
4491 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4492 PRE_REG_READ5(long, "_umtx_op_wait",
4493 long *, obj, int, op, unsigned long, val,
4494 size_t, timeout_size, struct vki_timespec *, timeout);
4495 if (ARG1) {
4496 PRE_MEM_READ( "_umtx_op_wait(val)", ARG1, sizeof(long) );
4497 if (*(long*)ARG1 == (long)ARG3) {
4498 *flags |= SfMayBlock;
4502 if (ARG5) {
4503 PRE_MEM_READ( "_umtx_op_wait(timeout)", ARG5, ARG4 );
4506 break;
4507 case VKI_UMTX_OP_WAKE:
4508 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, WAKE, %" FMT_REGWORD "u)", ARG1, ARG3);
4509 PRE_REG_READ3(long, "_umtx_op_wake",
4510 vki_uintptr_t *, obj, int, op, int, val);
4511 // PJF I don't think that the value of obj gets read, the address is being used as a key
4512 //PRE_MEM_READ("_umtx_op_wake(obj)", ARG1, sizeof(vki_uintptr_t));
4513 break;
4514 case VKI_UMTX_OP_MUTEX_TRYLOCK:
4515 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_TRYLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4516 PRE_REG_READ2(long, "_umtx_op_mutex_trylock", struct umutex *, obj, int, op);
4517 PRE_MEM_READ( "_umtx_op_mutex_trylock(mutex)", ARG1, sizeof(struct vki_umutex) );
4518 PRE_MEM_WRITE( "_umtx_op_mutex_trylock(mutex)", ARG1, sizeof(struct vki_umutex) );
4519 /* not too sure about the restart here
4520 * it's hard to test as if the mutex is locked this returns EBUSY
4521 * so there is only a small window where the syscall could be interrupted */
4522 *flags |= SfMayBlock | SfKernelRestart;
4523 break;
4524 case VKI_UMTX_OP_MUTEX_LOCK:
4525 // called by pthread_mutex_lock
4526 // when the atribute UMUTEX_PRIO_PROTECT or UMUTEX_PRIO_INHERIT is set
4527 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_LOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4528 PRE_REG_READ5(long, "_umtx_op_mutex_lock",
4529 struct umutex *, obj, int, op, unsigned long, noid,
4530 size_t, timeout_size, struct vki_timespec *, timeout);
4531 PRE_MEM_READ( "_umtx_op_mutex_lock(mutex)", ARG1, sizeof(struct vki_umutex) );
4532 if (ARG5) {
4533 PRE_MEM_READ( "_umtx_op_mutex_lock(timespec)", ARG5, ARG4 );
4534 } else {
4535 *flags |= SfKernelRestart;
4537 PRE_MEM_WRITE( "_umtx_op_mutex_lock(mutex)", ARG1, sizeof(struct vki_umutex) );
4538 *flags |= SfMayBlock;
4539 break;
4540 case VKI_UMTX_OP_MUTEX_UNLOCK:
4541 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_UNLOCK)", ARG1);
4542 PRE_REG_READ2(long, "_umtx_op_mutex_unlock",
4543 struct umutex *, obj, int, op);
4544 PRE_MEM_READ( "_umtx_op_mutex_unlock(mutex)", ARG1, sizeof(struct vki_umutex) );
4545 PRE_MEM_WRITE( "_umtx_op_mutex_unlock(mutex)", ARG1, sizeof(struct vki_umutex) );
4546 break;
4547 case VKI_UMTX_OP_SET_CEILING:
4548 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SET_CEILING, %" FMT_REGWORD "u, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4);
4549 PRE_REG_READ4(long, "_umtx_op_set_ceiling",
4550 struct umutex *, obj, int, op, unsigned int, ceiling,
4551 unsigned int *, old_ceiling);
4552 PRE_MEM_READ( "_umtx_op_set_ceiling(mutex)", ARG1, sizeof(struct vki_umutex) );
4553 PRE_MEM_WRITE( "_umtx_op_set_ceiling(mutex)", ARG1, sizeof(struct vki_umutex) );
4554 if (ARG4) {
4555 PRE_MEM_WRITE( "_umtx_op_set_ceiling(old_ceiling)", ARG4, sizeof(vki_uint32_t) );
4557 break;
4558 case VKI_UMTX_OP_CV_WAIT:
4559 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4560 PRE_REG_READ5(long, "_umtx_op_cv_wait",
4561 struct ucond *, obj, int, op, unsigned long, wflags,
4562 struct umutex *, umtx, struct vki_timespec *, timeout);
4563 PRE_MEM_READ( "_umtx_op_cv_wait(cond)", ARG1, sizeof(struct vki_ucond) );
4564 PRE_MEM_WRITE( "_umtx_op_cv_wait(cond)", ARG1, sizeof(struct vki_ucond) );
4565 PRE_MEM_READ( "_umtx_op_cv_wait(mutex)", ARG4, sizeof(struct vki_umutex) );
4566 PRE_MEM_WRITE( "_umtx_op_cv_wait(mutex)", ARG4, sizeof(struct vki_umutex) );
4567 if (ARG5) {
4568 PRE_MEM_READ( "_umtx_op_cv_wait(timespec)", ARG5, sizeof(struct vki_timespec) );
4570 *flags |= SfMayBlock;
4571 break;
4572 case VKI_UMTX_OP_CV_SIGNAL:
4573 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_SIGNAL)", ARG1);
4574 PRE_REG_READ2(long, "_umtx_op_cv_signal",
4575 struct ucond *, obj, int, op);
4576 PRE_MEM_READ( "_umtx_op_cv_signal(cond)", ARG1, sizeof(struct vki_ucond) );
4577 PRE_MEM_WRITE( "_umtx_op_cv_signal(cond)", ARG1, sizeof(struct vki_ucond) );
4578 break;
4579 case VKI_UMTX_OP_CV_BROADCAST:
4580 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_BROADCAST, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4581 PRE_REG_READ2(long, "_umtx_op_cv_broadcast",
4582 struct ucond *, obj, int, op);
4583 PRE_MEM_READ( "_umtx_op_cv_broadcast(cond)", ARG1, sizeof(struct vki_ucond) );
4584 PRE_MEM_WRITE( "_umtx_op_cv_broadcast(cond)", ARG1, sizeof(struct vki_ucond) );
4585 break;
4586 case VKI_UMTX_OP_WAIT_UINT:
4587 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAIT_UINT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4588 PRE_REG_READ5(long, "_umtx_op_wait_uint",
4589 int *, obj, int, op, unsigned long, id,
4590 size_t, timeout_wait, struct vki_timespec *, timeout);
4591 PRE_MEM_READ( "_umtx_op_wait(uint)", ARG1, sizeof(int) );
4592 if (ARG5) {
4593 PRE_MEM_READ( "_umtx_op_wait(timespec)", ARG5, ARG4 );
4595 *flags |= SfMayBlock;
4596 break;
4597 case VKI_UMTX_OP_RW_RDLOCK:
4598 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, RW_RDLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4599 PRE_REG_READ5(long, "_umtx_op_rw_rdlock",
4600 struct urwlock *, obj, int, op, unsigned long, noid,
4601 void *, zero, struct vki_timespec *, timeout);
4602 PRE_MEM_READ( "_umtx_op_rw_rdlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4603 PRE_MEM_WRITE( "_umtx_op_rw_rdlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4604 *flags |= SfMayBlock;
4605 break;
4606 case VKI_UMTX_OP_RW_WRLOCK:
4607 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, RW_WRLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4608 PRE_REG_READ5(long, "_umtx_op_rw_wrlock",
4609 struct urwlock *, obj, int, op, unsigned long, noid,
4610 void *, zero, struct vki_timespec *, timeout);
4611 PRE_MEM_READ( "_umtx_op_rw_wrlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4612 PRE_MEM_WRITE( "_umtx_op_rw_wrlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4613 *flags |= SfMayBlock;
4614 break;
4615 case VKI_UMTX_OP_RW_UNLOCK:
4616 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, RW_UNLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4617 PRE_REG_READ2(long, "_umtx_op_rw_unlock",
4618 struct urwlock *, obj, int, op);
4619 PRE_MEM_READ( "_umtx_op_rw_unlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4620 PRE_MEM_WRITE( "_umtx_op_rw_unlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4621 break;
4622 case VKI_UMTX_OP_WAIT_UINT_PRIVATE:
4623 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAIT_UINT_PRIVATE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4624 PRE_REG_READ5(long, "_umtx_op_wait_uint_private",
4625 int *, obj, int, op, unsigned long, id,
4626 size_t, timeout_size, struct vki_timespec *, timeout);
4627 PRE_MEM_READ( "_umtx_op_wait_private(uint)", ARG1, sizeof(int) );
4628 if (ARG5) {
4629 PRE_MEM_READ( "_umtx_op_wait_private(umtx_time)", ARG5, ARG4 );
4631 *flags |= SfMayBlock;
4632 break;
4633 case VKI_UMTX_OP_WAKE_PRIVATE:
4634 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAKE_PRIVATE, %" FMT_REGWORD "u)", ARG1, ARG3);
4635 PRE_REG_READ3(long, "_umtx_op_wake_private",
4636 vki_uintptr_t *, obj, int, op, int, val);
4637 // PJF like OP_WAKE contents of obj not read
4638 //PRE_MEM_READ("_umtx_op_wake_private(obj)", ARG1, sizeof(vki_uintptr_t));
4639 break;
4640 case VKI_UMTX_OP_MUTEX_WAIT:
4641 // pthread_mutex_lock without prio flags
4642 // does not need to be restarted
4643 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4644 PRE_REG_READ2(long, "_umtx_op_mutex_wait",
4645 struct umutex *, obj, int, op);
4646 PRE_MEM_READ( "_umtx_op_mutex_wait(mutex)", ARG1, sizeof(struct vki_umutex) );
4647 PRE_MEM_WRITE( "_umtx_op_mutex_wait(mutex)", ARG1, sizeof(struct vki_umutex) );
4648 *flags |= SfMayBlock;
4649 break;
4650 case VKI_UMTX_OP_MUTEX_WAKE:
4651 // marked as deprecated
4652 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_WAKE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4653 PRE_REG_READ2(long, "_umtx_op_mutex_wake",
4654 struct umutex *, obj, int, op);
4655 PRE_MEM_READ( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4656 PRE_MEM_WRITE( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4657 break;
4658 case VKI_UMTX_OP_SEM_WAIT:
4659 // marked as deprecated
4660 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4661 PRE_REG_READ5(long, "_umtx_op_sem_wait",
4662 struct usem *, obj, int, op, unsigned long, id,
4663 size_t, timeout_size, struct vki_timespec *, timeout);
4664 PRE_MEM_READ( "_umtx_op_sem_wait(usem)", ARG1, sizeof(struct vki_usem) );
4665 PRE_MEM_WRITE( "_umtx_op_sem_wait(usem)", ARG1, sizeof(struct vki_usem) );
4666 if (ARG5) {
4667 PRE_MEM_READ( "_umtx_op_sem_wait(umtx_time)", ARG5, ARG4 );
4669 *flags |= SfMayBlock;
4670 break;
4671 case VKI_UMTX_OP_SEM_WAKE:
4672 // marked as deprecated
4673 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM_WAKE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4674 PRE_REG_READ2(long, "_umtx_op_sem_wake",
4675 struct umutex *, obj, int, op);
4676 PRE_MEM_READ( "_umtx_op_sem_wake(mutex)", ARG1, sizeof(struct vki_usem) );
4677 PRE_MEM_WRITE( "_umtx_op_sem_wake(mutex)", ARG1, sizeof(struct vki_usem) );
4678 break;
4679 case VKI_UMTX_OP_NWAKE_PRIVATE:
4680 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, NWAKE_PRIVATE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4681 PRE_REG_READ3(long, "_umtx_op_nwake_private",
4682 struct umutex *, obj, int, op, int, count);
4683 PRE_MEM_READ( "_umtx_op_nwake_private(mtxs)", ARG1, ARG3 * sizeof(void *) );
4684 PRE_MEM_WRITE( "_umtx_op_mutex_wake(mtxs)", ARG1, sizeof(struct vki_umutex) );
4685 break;
4686 case VKI_UMTX_OP_MUTEX_WAKE2:
4687 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_WAKE2, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4688 PRE_REG_READ3(long, "_umtx_op_mutex_wake2",
4689 struct umutex *, obj, int, op, unsigned long, flags);
4690 PRE_MEM_READ( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4691 PRE_MEM_WRITE( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4692 break;
4693 case VKI_UMTX_OP_SEM2_WAIT:
4694 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM2_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4695 PRE_REG_READ3(long, "_umtx_op_sem2_wake",
4696 struct _usem2 *, obj, int, op, unsigned long, flags);
4697 PRE_MEM_READ( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4698 PRE_MEM_WRITE( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4699 *flags |= SfMayBlock;
4700 break;
4701 case VKI_UMTX_OP_SEM2_WAKE:
4702 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM2_WAKE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4703 PRE_REG_READ3(long, "_umtx_op_sem2_wake",
4704 struct _usem2 *, obj, int, op, unsigned long, flags);
4705 PRE_MEM_READ( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4706 PRE_MEM_WRITE( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4707 break;
4708 case VKI_UMTX_OP_SHM:
4709 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SHM, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4710 PRE_REG_READ4(long, "_umtx_op_shm",
4711 void *, obj, int, op, unsigned long, val, void*, uaddr);
4712 break;
4713 case VKI_UMTX_OP_ROBUST_LISTS:
4714 // strangely the obj pointer ARG1 isn't used, for instance lin libc
4715 // libthr/thread/thr_mutex.c: _umtx_op(NULL, UMTX_OP_ROBUST_LISTS, sizeof(rb), &rb, NULL);
4716 // val (ARG3) ought to be the same as sizeof(struct vki_umtx_robust_lists_params)
4717 // strangely the kernel returns EINVAL if size is larger than sizeof(struct vki_umtx_robust_lists_params)
4718 // (which seems relatively harmless)
4719 // but not if it is smaller (definitely dangerous, probably an overrun)
4720 if (ARG3 < sizeof(struct vki_umtx_robust_lists_params)) {
4721 VG_(umsg)("WARNING: _umtx_op_tobust_lists size is smaller than sizeof(struct umtx_robust_lists_params).\n");
4723 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, ROBUST_LISTS, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4724 PRE_REG_READ4(long, "_umtx_op_robust_lists",
4725 void*, obj, int, op, unsigned long, val, struct umtx_robust_lists*, uaddr);
4726 PRE_MEM_READ( "_umtx_op_robust_lists(robust_lists)", ARG4, ARG3 );
4727 break;
4728 #if (FREEBSD_VERS >= FREEBSD_13_3)
4729 case VKI_UMTX_OP_GET_MIN_TIMEOUT:
4730 PRINT( "sys__umtx_op ( GET_MIN_TIMEOUT, %#" FMT_REGWORD "x)", ARG4);
4731 // bit of a pain just reads args 2 and 4
4732 if (VG_(tdict).track_pre_reg_read) {
4733 PRRSN;
4734 PRA2("_umtx_op_get_min_timeout",int,op);
4735 PRA4("_umtx_op_get_min_timeout",long int*,timeout);
4737 PRE_MEM_WRITE( "_umtx_op_get_min_timout(uaddr)", ARG4, sizeof(long int) );
4738 break;
4739 case VKI_UMTX_OP_SET_MIN_TIMEOUT:
4740 PRINT( "sys__umtx_op ( SET_MIN_TIMEOUT, %" FMT_REGWORD "u)", ARG3);
4741 // bit of a pain just reads args 2 and 3
4742 if (VG_(tdict).track_pre_reg_read) {
4743 PRRSN;
4744 PRA2("_umtx_op_set_min_timeout",int,op);
4745 PRA3("_umtx_op_set_min_timeout",unsigned long,timeout);
4747 break;
4748 #endif
4749 default:
4750 VG_(umsg)("WARNING: _umtx_op unsupported value.\n");
4751 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);
4752 break;
4756 POST(sys__umtx_op)
4758 switch(ARG2) {
4759 case VKI_UMTX_OP_LOCK:
4760 case VKI_UMTX_OP_UNLOCK:
4761 if (SUCCESS) {
4762 POST_MEM_WRITE( ARG1, sizeof(struct vki_umtx) );
4764 break;
4765 case VKI_UMTX_OP_WAIT:
4766 case VKI_UMTX_OP_WAKE:
4767 case VKI_UMTX_OP_WAIT_UINT:
4768 case VKI_UMTX_OP_WAIT_UINT_PRIVATE:
4769 case VKI_UMTX_OP_WAKE_PRIVATE:
4770 break;
4771 case VKI_UMTX_OP_MUTEX_TRYLOCK:
4772 case VKI_UMTX_OP_MUTEX_LOCK:
4773 case VKI_UMTX_OP_MUTEX_UNLOCK:
4774 case VKI_UMTX_OP_MUTEX_WAIT: /* Sets/clears contested bits */
4775 case VKI_UMTX_OP_MUTEX_WAKE: /* Sets/clears contested bits */
4776 if (SUCCESS) {
4777 POST_MEM_WRITE( ARG1, sizeof(vki_uintptr_t) );
4779 break;
4780 case VKI_UMTX_OP_SET_CEILING:
4781 if (SUCCESS) {
4782 POST_MEM_WRITE( ARG1, sizeof(struct vki_umutex) );
4783 if (ARG4) {
4784 POST_MEM_WRITE( ARG4, sizeof(vki_uint32_t) );
4787 break;
4788 case VKI_UMTX_OP_CV_WAIT:
4789 if (SUCCESS) {
4790 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucond) );
4791 POST_MEM_WRITE( ARG4, sizeof(struct vki_umutex) );
4793 break;
4794 case VKI_UMTX_OP_CV_SIGNAL:
4795 case VKI_UMTX_OP_CV_BROADCAST:
4796 if (SUCCESS) {
4797 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucond) );
4799 break;
4800 case VKI_UMTX_OP_RW_RDLOCK:
4801 case VKI_UMTX_OP_RW_WRLOCK:
4802 case VKI_UMTX_OP_RW_UNLOCK:
4803 if (SUCCESS) {
4804 POST_MEM_WRITE( ARG1, sizeof(struct vki_urwlock) );
4806 break;
4807 case VKI_UMTX_OP_SEM2_WAIT:
4808 case VKI_UMTX_OP_SEM2_WAKE:
4809 if (SUCCESS) {
4810 POST_MEM_WRITE( ARG1, sizeof(struct vki_usem2) );
4812 break;
4813 case VKI_UMTX_OP_SHM:
4814 case VKI_UMTX_OP_ROBUST_LISTS:
4815 break;
4816 #if (FREEBSD_VERS >= FREEBSD_13_3)
4817 case VKI_UMTX_OP_GET_MIN_TIMEOUT:
4818 POST_MEM_WRITE( ARG4, sizeof(long int) );
4819 break;
4820 case VKI_UMTX_OP_SET_MIN_TIMEOUT:
4821 break;
4822 #endif
4823 default:
4824 break;
4828 // SYS_thr_new 455
4829 // x86/amd64
4831 // SYS_sigqueue 456
4832 // int sigqueue(pid_t pid, int signo, const union sigval value);
4833 PRE(sys_sigqueue)
4835 PRINT("sys_sigqueue ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",
4836 SARG1,SARG2,ARG3);
4837 PRE_REG_READ3(int, "sigqueue", vki_pid_t, pid, int, signo, const union vki_sigval, value);
4840 // SYS_kmq_open 457
4841 // mqd_t mq_open(const char *name, int oflag, ...);
4842 // int kmq_open(_In_z_ const char *path, int flags, mode_t mode, _In_opt_ const struct mq_attr *attr);
4843 PRE(sys_kmq_open)
4845 if (ARG2 & VKI_O_CREAT) {
4846 PRINT("sys_kmq_open( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu, %#" FMT_REGWORD "x )",
4847 ARG1,(char *)ARG1,ARG2,(vki_mode_t)ARG3,ARG4);
4848 PRE_REG_READ4(long, "mq_open",
4849 const char *, name, int, oflag, vki_mode_t, mode,
4850 struct mq_attr *, attr);
4851 } else {
4852 PRINT("sys_kmq_open( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu)",
4853 ARG1,(char *)ARG1,ARG2,(vki_mode_t)ARG3);
4854 PRE_REG_READ3(long, "mq_open",
4855 const char *, name, int, oflag, vki_mode_t, mode);
4857 PRE_MEM_RASCIIZ( "mq_open(name)", ARG1 );
4858 if (ARG2 & VKI_O_CREAT) {
4859 PRE_MEM_READ("mq_open(attr)", ARG4, sizeof(struct vki_mq_attr));
4860 if (ML_(safe_to_deref)((struct vki_mq_attr *)ARG4, sizeof(struct vki_mq_attr))) {
4861 const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG4;
4862 PRE_MEM_READ("mq_open(attr->mq_maxmsg)",
4863 (Addr)&attr->mq_maxmsg, sizeof(attr->mq_maxmsg) );
4864 PRE_MEM_READ("mq_open(attr->mq_msgsize)",
4865 (Addr)&attr->mq_msgsize, sizeof(attr->mq_msgsize) );
4870 POST(sys_kmq_open)
4872 vg_assert(SUCCESS);
4873 if (!ML_(fd_allowed)(RES, "mq_open", tid, True)) {
4874 VG_(close)(RES);
4875 SET_STATUS_Failure( VKI_EMFILE );
4876 } else {
4877 if (VG_(clo_track_fds)) {
4878 ML_(record_fd_open_with_given_name)(tid, RES, (const HChar*)ARG1);
4883 // SYS_kmq_setattr 458
4884 // int mq_setattr(mqd_t mqdes, const struct mq_attr *restrict mqstat,
4885 // struct mq_attr *restrict omqstat);
4886 PRE(sys_kmq_setattr)
4888 PRINT("sys_kmq_getattr( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3 );
4889 PRE_REG_READ3(int, "mq_setattr",
4890 vki_mqd_t, mqdes, const struct mq_attr *, mqstat,
4891 struct mq_attr *, omqstat);
4892 if (!ML_(fd_allowed)(ARG1, "mq_getattr", tid, False)) {
4893 SET_STATUS_Failure( VKI_EBADF );
4894 } else {
4895 if (ML_(safe_to_deref)((struct vki_mq_attr *)ARG2, sizeof(struct vki_mq_attr))) {
4896 const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG2;
4897 PRE_MEM_READ( "mq_setattr(mqstat->mq_flags)",
4898 (Addr)&attr->mq_flags, sizeof(attr->mq_flags) );
4900 PRE_MEM_WRITE( "mq_setattr(omqstat)", ARG3,
4901 sizeof(struct vki_mq_attr) );
4905 // SYS_kmq_timedreceive 459
4906 // ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
4907 // unsigned *msg_prio, const struct timespec *abs_timeout);
4908 PRE(sys_kmq_timedreceive)
4910 *flags |= SfMayBlock;
4911 PRINT("sys_kmq_timedreceive( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %llu, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
4912 ARG1,ARG2,(ULong)ARG3,ARG4,ARG5);
4913 PRE_REG_READ5(ssize_t, "mq_timedreceive",
4914 vki_mqd_t, mqdes, char *, msg_ptr, vki_size_t, msg_len,
4915 unsigned int *, msg_prio,
4916 const struct timespec *, abs_timeout);
4917 if (!ML_(fd_allowed)(ARG1, "mq_timedreceive", tid, False)) {
4918 SET_STATUS_Failure( VKI_EBADF );
4919 } else {
4920 PRE_MEM_WRITE( "mq_timedreceive(msg_ptr)", ARG2, ARG3 );
4921 if (ARG4 != 0) {
4922 PRE_MEM_WRITE( "mq_timedreceive(msg_prio)",
4923 ARG4, sizeof(unsigned int) );
4925 if (ARG5 != 0) {
4926 PRE_MEM_READ( "mq_timedreceive(abs_timeout)",
4927 ARG5, sizeof(struct vki_timespec) );
4932 POST(sys_kmq_timedreceive)
4934 POST_MEM_WRITE( ARG2, ARG3 );
4935 if (ARG4 != 0) {
4936 POST_MEM_WRITE( ARG4, sizeof(unsigned int) );
4940 // SYS_kmq_timedsend 460
4941 // int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
4942 // unsigned msg_prio, const struct timespec *abs_timeout);
4943 PRE(sys_kmq_timedsend)
4945 *flags |= SfMayBlock;
4946 PRINT("sys_kmq_timedsend ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %llu, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",
4947 ARG1,ARG2,(ULong)ARG3,ARG4,ARG5);
4948 PRE_REG_READ5(int, "mq_timedsend",
4949 vki_mqd_t, mqdes, const char *, msg_ptr, vki_size_t, msg_len,
4950 unsigned int, msg_prio, const struct timespec *, abs_timeout);
4951 if (!ML_(fd_allowed)(ARG1, "mq_timedsend", tid, False)) {
4952 SET_STATUS_Failure( VKI_EBADF );
4953 } else {
4954 PRE_MEM_READ( "mq_timedsend(msg_ptr)", ARG2, ARG3 );
4955 if (ARG5 != 0) {
4956 PRE_MEM_READ( "mq_timedsend(abs_timeout)", ARG5,
4957 sizeof(struct vki_timespec) );
4962 // SYS_kmq_notify 461
4963 // int mq_notify(mqd_t mqdes, const struct sigevent *notification);
4964 PRE(sys_kmq_notify)
4966 PRINT("sys_kmq_notify( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2 );
4967 PRE_REG_READ2(int, "mq_notify",
4968 vki_mqd_t, mqdes, const struct sigevent *, notification);
4969 if (!ML_(fd_allowed)(ARG1, "mq_notify", tid, False)) {
4970 SET_STATUS_Failure( VKI_EBADF );
4972 else if (ARG2 != 0) {
4973 PRE_MEM_READ( "mq_notify(notification)",
4974 ARG2, sizeof(struct vki_sigevent) );
4978 // SYS_kmq_unlink 462
4979 // int kmq_unlink(const char *path);
4980 PRE(sys_kmq_unlink)
4982 PRINT("sys_kmq_unlink ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
4983 PRE_REG_READ1(int, "mq_unlink", const char *, name);
4984 PRE_MEM_RASCIIZ( "mq_unlink(name)", ARG1 );
4987 // SYS_abort2 463
4988 // void abort2(const char *why, int nargs, void **args);
4989 PRE(sys_abort2)
4991 PRINT( "sys_abort2 ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1, SARG2, ARG3 );
4992 PRE_REG_READ3(void, "abort2", const char *, why, int, nargs, void **, args);
4993 // max length of 'why' is 128
4994 PRE_MEM_RASCIIZ( "abort2(why)", ARG2);
4995 // max val for nargs is 16
4996 PRE_MEM_READ("abort2(args", ARG3, ARG2*sizeof(void*));
4999 // SYS_thr_set_name 464
5000 // int thr_set_name(long id, const char *name);
5001 PRE(sys_thr_set_name)
5003 PRINT( "sys_thr_set_name ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1, ARG2 );
5004 PRE_REG_READ2(int, "thr_set_name", long, id, const char *, name);
5005 PRE_MEM_RASCIIZ( "thr_set_name(name)", ARG2);
5007 if (ML_(safe_to_deref)((void*)ARG2, 1)) {
5008 const HChar* new_name = (const HChar*) (Addr)ARG2;
5009 ThreadState* tst = VG_(get_ThreadState)(tid);
5010 SizeT new_len = VG_(strnlen)(new_name, VKI_MAXCOMLEN+1);
5011 tst->thread_name = VG_(realloc)("syswrap.thr_set_name", tst->thread_name, new_len + 1);
5012 VG_(strlcpy)(tst->thread_name, new_name, new_len + 1);
5016 // SYS_aio_fsync 465
5017 // int aio_fsync(int op, struct aiocb *iocb);
5018 PRE(sys_aio_fsync)
5020 PRINT("aio_fsync ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,ARG2);
5021 PRE_REG_READ2(int, "aio_fsync", int, op, struct vki_aiocb *, iocb);
5022 PRE_MEM_READ( "aio_fsync(iocb)", ARG2, sizeof(struct vki_aiocb) );
5025 // SYS_rtprio_thread 466
5026 // int rtprio_thread(int function, lwpid_t lwpid, struct rtprio *rtp);
5027 PRE(sys_rtprio_thread)
5029 PRINT( "sys_rtprio_thread ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1, ARG2, ARG3 );
5030 PRE_REG_READ3(int, "rtprio_thread",
5031 int, function, __vki_lwpid_t, lwpid, struct vki_rtprio *, rtp);
5032 if (ARG1 == VKI_RTP_SET) {
5033 PRE_MEM_READ( "rtprio_thread(rtp#set)", ARG3, sizeof(struct vki_rtprio));
5034 } else if (ARG1 == VKI_RTP_LOOKUP) {
5035 PRE_MEM_WRITE( "rtprio_thread(rtp#lookup)", ARG3, sizeof(struct vki_rtprio));
5036 } else {
5037 /* PHK ?? */
5041 POST(sys_rtprio_thread)
5043 if (ARG1 == VKI_RTP_LOOKUP && RES == 0) {
5044 POST_MEM_WRITE( ARG3, sizeof(struct vki_rtprio));
5048 // SYS_sctp_peeloff 471
5049 // int sctp_peeloff(int s, sctp_assoc_t id);
5050 // @todo
5053 // SYS_sctp_generic_sendmsg 472
5054 // int sctp_generic_sendmsg(int s, void *msg, int msglen, struct sockaddr *to,
5055 // socklen_t len, struct sctp_sndrcvinfo *sinfo, int flags);
5057 // Not called directly from libc
5058 PRE(sys_sctp_generic_sendmsg)
5060 *flags |= SfMayBlock;
5061 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);
5062 PRE_REG_READ7(ssize_t, "sctp_generic_sendmsg",
5063 int, s, void *, msg, int, msglen,
5064 struct sockaddr *, to, socklen_t, len,
5065 struct sctp_sndrcvinfo *, sinfo, int, flags);
5067 PRE_MEM_READ( "sctp_generic_sendmsg(msg)", ARG2, ARG3);
5069 ML_(pre_mem_read_sockaddr) (tid, "sctp_generic_sendmsg(to)", (struct vki_sockaddr *)ARG4, ARG5);
5071 if (ARG6 != (Addr)NULL) {
5072 PRE_MEM_READ( "sctp_generic_sendmsg(sinfo)", ARG6, sizeof(struct vki_sctp_sndrcvinfo));
5076 // SYS_sctp_generic_sendmsg_iov 473
5077 // int sctp_generic_sendmsg_iov(int s, struct iovec *iov, int iovlen,
5078 // struct sockaddr *to, struct sctp_sndrcvinfo *sinfo, int flags);
5079 // @todo
5081 // SYS_sctp_generic_recvmsg 474
5082 // int sctp_generic_recvmsg(int s, struct iovec *iov, int iovlen,
5083 // struct sockaddr *from, socklen_t *fromlen,
5084 // struct sctp_sndrcvinfo *sinfo, int *msgflags);
5086 // Not called directly from libc
5087 PRE(sys_sctp_generic_recvmsg)
5089 *flags |= SfMayBlock;
5090 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);
5091 PRE_REG_READ7(ssize_t, "sctp_generic_recvmsg",
5092 int, s, struct iovec *, iov, int, iovlen,
5093 struct sockaddr *, from, socklen_t *, fromlen,
5094 struct sctp_sndrcvinfo *, sinfo, int *, msgflags);
5096 // in the sctp_recvmsg libc wrapper this is always 1
5097 if ((Int)ARG3 > 0) {
5098 PRE_MEM_READ( "sctp_generic_recvmsg(iov)", ARG2, ARG3 * sizeof(struct vki_iovec) );
5100 if (ML_(safe_to_deref)((const void*)ARG2, ARG3 * sizeof(struct vki_iovec))) {
5101 struct vki_iovec* iovec = (struct vki_iovec*)ARG2;
5102 PRE_MEM_WRITE("sctp_generic_recvmsg(iov.iov_base)", (Addr)iovec->iov_base, iovec->iov_len);
5105 if (ARG4 != (Addr)NULL) {
5106 ML_(buf_and_len_pre_check) (tid, ARG4, ARG5,
5107 "sctp_generic_recvmsg(from)",
5108 "sctp_generic_recvmsg(fromlen_in)");
5111 if (ARG6 != (Addr)NULL) {
5112 PRE_MEM_WRITE("sctp_generic_recvmsg(sinfo)", ARG6, sizeof(struct vki_sctp_sndrcvinfo));
5115 if (ARG7 != (Addr)NULL) {
5116 PRE_MEM_WRITE("sctp_generic_recvmsg(msgflags)", ARG7, sizeof(int));
5120 POST(sys_sctp_generic_recvmsg)
5122 vg_assert(SUCCESS);
5123 struct vki_iovec* iovec = (struct vki_iovec*)ARG2;
5124 POST_MEM_WRITE((Addr)iovec->iov_base, iovec->iov_len);
5126 POST_MEM_WRITE( ARG2, ARG3*sizeof(struct vki_iovec) );
5128 if (ARG4 != (Addr)NULL) {
5129 ML_(buf_and_len_post_check) (tid, VG_(mk_SysRes_Success)(RES), ARG4, ARG5,
5130 "sctp_generic_recvmsg(fromlen_out)");
5133 if (ARG6 != (Addr)NULL) {
5134 POST_MEM_WRITE(ARG6, sizeof(struct vki_sctp_sndrcvinfo));
5137 if (ARG7 != (Addr)NULL) {
5138 POST_MEM_WRITE(ARG7, sizeof(int));
5142 // SYS_pread 475
5143 // x86/amd64
5145 // SYS_pwrite 476
5146 // x86/amd64
5148 // SYS_mmap 477
5149 // x86/amd64
5151 // SYS_lseek 478
5152 // x86/amd64
5154 //SYS_truncate 479
5155 // x86/amd64
5157 // SYS_ftruncate 480
5158 // x86/amd64
5160 // SYS_thr_kill2 481
5161 // int thr_kill2(pid_t pid, long id, int sig);
5162 PRE(sys_thr_kill2)
5164 PRINT("sys_thr_kill2 ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
5165 PRE_REG_READ3(int, "thr_kill2", pid_t, pid, long, tid, int, sig);
5166 if (!ML_(client_signal_OK)(ARG3)) {
5167 SET_STATUS_Failure( VKI_EINVAL );
5168 return;
5171 /* Check to see if this kill gave us a pending signal */
5172 *flags |= SfPollAfter;
5174 if (VG_(clo_trace_signals)) {
5175 VG_(message)(Vg_DebugMsg, "thr_kill2: sending signal %lu to pid %lu/%lu\n",
5176 ARG3, ARG1, ARG2);
5179 /* If we're sending SIGKILL, check to see if the target is one of
5180 our threads and handle it specially. */
5181 if (ARG3 == VKI_SIGKILL && ML_(do_sigkill)(ARG2, ARG1)) {
5182 SET_STATUS_Success(0);
5183 return;
5186 /* Ask to handle this syscall via the slow route, since that's the
5187 only one that sets tst->status to VgTs_WaitSys. If the result
5188 of doing the syscall is an immediate run of
5189 async_signalhandler() in m_signals, then we need the thread to
5190 be properly tidied away. I have the impression the previous
5191 version of this wrapper worked on x86/amd64 only because the
5192 kernel did not immediately deliver the async signal to this
5193 thread (on ppc it did, which broke the assertion re tst->status
5194 at the top of async_signalhandler()). */
5195 *flags |= SfMayBlock;
5198 POST(sys_thr_kill2)
5200 if (VG_(clo_trace_signals)) {
5201 VG_(message)(Vg_DebugMsg, "thr_kill2: sent signal %lu to pid %lu/%lu\n",
5202 ARG3, ARG1, ARG2);
5206 // SYS_shm_open 482
5207 // int shm_open(const char *path, int flags, mode_t mode);
5208 PRE(sys_shm_open)
5210 PRE_REG_READ3(int, "shm_open",
5211 const char *, path, int, flags, vki_mode_t, mode);
5212 if (ARG1 == VKI_SHM_ANON) {
5213 PRINT("sys_shm_open(%#" FMT_REGWORD "x(SHM_ANON), %" FMT_REGWORD "u, %hu)", ARG1, ARG2, (vki_mode_t)ARG3);
5214 } else {
5215 PRINT("sys_shm_open(%#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu)", ARG1, (HChar *)ARG1, ARG2, (vki_mode_t)ARG3);
5216 PRE_MEM_RASCIIZ( "shm_open(path)", ARG1 );
5218 *flags |= SfMayBlock;
5221 POST(sys_shm_open)
5223 vg_assert(SUCCESS);
5224 if (!ML_(fd_allowed)(RES, "shm_open", tid, True)) {
5225 VG_(close)(RES);
5226 SET_STATUS_Failure( VKI_EMFILE );
5227 } else {
5228 if (VG_(clo_track_fds)) {
5229 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1);
5234 // SYS_shm_unlink 483
5235 // int shm_unlink(const char *path);
5236 PRE(sys_shm_unlink)
5238 PRINT("sys_shm_unlink(%#" FMT_REGWORD "x(%s))", ARG1, (char *)ARG1);
5239 PRE_REG_READ1(int, "shm_unlink",
5240 const char *, path);
5242 PRE_MEM_RASCIIZ( "shm_unlink(path)", ARG1 );
5244 *flags |= SfMayBlock;
5247 // SYS_cpuset 484
5248 // int cpuset(cpusetid_t *setid);
5249 PRE(sys_cpuset)
5251 PRINT("sys_cpuset ( %#" FMT_REGWORD "x )", ARG1);
5252 PRE_REG_READ1(int, "cpuset", vki_cpusetid_t *, setid);
5253 PRE_MEM_WRITE("cpuset(setid)", ARG1, sizeof(vki_cpusetid_t));
5256 POST(sys_cpuset)
5258 POST_MEM_WRITE(ARG1, sizeof(vki_cpusetid_t));
5261 // SYS_cpuset_setid 485
5262 // amd64 / x86
5264 // SYS_cpuset_getid 486
5265 // amd64 / x86
5267 // SYS_cpuset_getaffinity 487
5268 // amd64 / x86
5270 // SYS_cpuset_setaffinity 488
5271 // amd64 / x86
5273 // SYS_faccessat 489
5274 // int faccessat(int fd, const char *path, int mode, int flag);
5275 PRE(sys_faccessat)
5277 PRINT("sys_faccessat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,ARG2,(char*)ARG2,ARG3);
5278 PRE_REG_READ3(int, "faccessat",
5279 int, fd, const char *, path, int, flag);
5280 PRE_MEM_RASCIIZ( "faccessat(path)", ARG2 );
5283 // SYS_fchmodat 490
5284 // int fchmodat(int fd, const char *path, mode_t mode, int flag);
5285 PRE(sys_fchmodat)
5287 PRINT("sys_fchmodat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,ARG2,(char*)ARG2,ARG3);
5288 PRE_REG_READ4(int, "fchmodat",
5289 int, fd, const char *, path, vki_mode_t, mode, int, flag);
5290 PRE_MEM_RASCIIZ( "fchmodat(path)", ARG2 );
5293 // SYS_fchownat 491
5294 // int fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag);
5295 PRE(sys_fchownat)
5297 PRINT("sys_fchownat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x, 0x%" FMT_REGWORD "x, %" FMT_REGWORD "d )",
5298 ARG1,ARG2,(char*)ARG2,ARG3,ARG4, SARG5);
5299 PRE_REG_READ5(int, "fchownat",
5300 int, fd, const char *, path,
5301 vki_uid_t, owner, vki_gid_t, group, int, flag);
5302 PRE_MEM_RASCIIZ( "fchownat(path)", ARG2 );
5305 // SYS_fexecve 492
5306 // int fexecve(int fd, char *const argv[], char *const envp[]);
5307 PRE(sys_fexecve)
5309 PRINT("sys_fexecve ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
5310 SARG1,ARG2,ARG3);
5311 PRE_REG_READ3(int, "fexecve",
5312 int, fd, char * const *, argv,
5313 char * const *, envp);
5315 if (!ML_(fd_allowed)(ARG1, "fexecve", tid, False)) {
5316 SET_STATUS_Failure(VKI_EBADF);
5317 return;
5320 const HChar *fname;
5322 if (VG_(resolve_filename)(ARG1, &fname) == False) {
5323 SET_STATUS_Failure(VKI_ENOENT);
5324 return;
5327 struct vg_stat stats;
5328 if (VG_(fstat)(ARG1, &stats) != 0) {
5329 SET_STATUS_Failure(VKI_EACCES);
5330 return;
5333 Int openFlags;
5335 if (VG_(resolve_filemode)(ARG1, &openFlags) == False) {
5336 SET_STATUS_Failure(VKI_ENOENT);
5337 return;
5341 * openFlags is in kernel FFLAGS format
5342 * (see /usr/include/sys/fcntl.h)
5343 * which alllows us to tell if RDONLY is set
5347 Bool isScript = False;
5349 SysRes res;
5350 res = VG_(open)(fname, VKI_O_RDONLY,
5351 VKI_S_IRUSR|VKI_S_IRGRP|VKI_S_IROTH);
5352 if (sr_isError(res)) {
5353 SET_STATUS_Failure(VKI_ENOENT);
5354 return;
5357 char buf[2];
5358 VG_(read)((Int)sr_Res(res), buf, 2);
5359 VG_(close)((Int)sr_Res(res));
5360 if (buf[0] == '#' && buf[1] == '!') {
5361 isScript = True;
5364 if (isScript) {
5365 if (!(openFlags & VKI_FREAD)) {
5366 SET_STATUS_Failure(VKI_EACCES);
5367 return;
5369 } else {
5370 if (!((openFlags & VKI_O_EXEC) ||
5371 (stats.mode & (VKI_S_IXUSR|VKI_S_IXGRP|VKI_S_IXOTH)))) {
5372 SET_STATUS_Failure(VKI_EACCES);
5373 return;
5377 Addr arg_2 = (Addr)ARG2;
5378 Addr arg_3 = (Addr)ARG3;
5380 handle_pre_sys_execve(tid, status, (Addr)fname, arg_2, arg_3, FEXECVE, False);
5383 // SYS_freebsd11_fstatat 493
5384 // int fstatat(int fd, const char *path, struct stat *sb, int flag);
5385 #if (FREEBSD_VERS >= FREEBSD_12)
5386 PRE(sys_freebsd11_fstatat)
5388 PRINT("sys_freebsd11_fstatat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3);
5389 PRE_REG_READ4(int, "fstatat",
5390 int, fd, const char *, path, struct freebsd11_stat *, buf, int, flag);
5391 PRE_MEM_RASCIIZ( "fstatat(path)", ARG2 );
5392 PRE_MEM_WRITE( "fstatat(sb)", ARG3, sizeof(struct vki_freebsd11_stat) );
5395 POST(sys_freebsd11_fstatat)
5397 POST_MEM_WRITE( ARG3, sizeof(struct vki_freebsd11_stat) );
5399 #else
5400 PRE(sys_fstatat)
5402 PRINT("sys_fstatat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3);
5403 PRE_REG_READ4(int, "fstatat",
5404 int, fd, const char *, path, struct stat *, buf, int, flag);
5405 PRE_MEM_RASCIIZ( "fstatat(path)", ARG2 );
5406 PRE_MEM_WRITE( "fstatat(sb)", ARG3, sizeof(struct vki_freebsd11_stat) );
5409 POST(sys_fstatat)
5411 POST_MEM_WRITE( ARG3, sizeof(struct vki_freebsd11_stat) );
5413 #endif
5415 // SYS_futimesat 494
5416 // int futimesat(int fd, const char *path, const struct timeval times[2]);
5417 PRE(sys_futimesat)
5419 PRINT("sys_futimesat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3);
5420 PRE_REG_READ3(int, "futimesat",
5421 int, fd, const char *, path, struct timeval *, times);
5422 if (ARG2 != 0) {
5423 PRE_MEM_RASCIIZ( "futimesat(path)", ARG2 );
5425 if (ARG3 != 0) {
5426 PRE_MEM_READ( "futimesat(times)", ARG3, 2 * sizeof(struct vki_timeval) );
5430 // SYS_linkat 495
5431 // int linkat(int fd1, const char *name1, int fd2, const char *name2, int flag);
5432 PRE(sys_linkat)
5434 *flags |= SfMayBlock;
5435 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);
5436 PRE_REG_READ5(int, "linkat",
5437 int, fd1, const char *, name1,
5438 int, fd2, const char *, name2,
5439 int, flag);
5440 PRE_MEM_RASCIIZ( "linkat(name1)", ARG2);
5441 PRE_MEM_RASCIIZ( "linkat(name2)", ARG4);
5444 // SYS_mkdirat 496
5445 // int mkdirat(int fd, const char *path, mode_t mode);
5446 PRE(sys_mkdirat)
5448 *flags |= SfMayBlock;
5449 PRINT("sys_mkdirat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,ARG2,(char*)ARG2,ARG3);
5450 PRE_REG_READ3(int, "mkdirat",
5451 int, fd, const char *, path, unsigned int, mode);
5452 PRE_MEM_RASCIIZ( "mkdirat(path)", ARG2 );
5455 // SYS_mkfifoat 497
5456 // int mkfifoat(int fd, const char *path, mode_t mode);
5457 PRE(sys_mkfifoat)
5459 PRINT("sys_mkfifoat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x )",
5460 SARG1,ARG2,(HChar*)ARG2,ARG3 );
5461 PRE_REG_READ3(int, "mkfifoat",
5462 int, fd, const char *, path, vki_mode_t, mode);
5463 PRE_MEM_RASCIIZ( "mkfifoat(path)", ARG2 );
5466 // SYS_freebsd11_mknodat 498
5467 // int mknodat(int fd, const char *path, mode_t mode, dev_t dev);
5468 #if (FREEBSD_VERS >= FREEBSD_12)
5469 PRE(sys_freebsd11_mknodat)
5471 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 );
5472 PRE_REG_READ4(long, "mknodat",
5473 int, dfd, const char *, pathname, int, mode, unsigned, dev);
5474 PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2 );
5476 #else
5477 PRE(sys_mknodat)
5479 PRINT("sys_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 #endif
5486 // SYS_openat 499
5487 // int openat(int fd, const char *path, int flags, ...);
5488 PRE(sys_openat)
5490 if (ARG3 & VKI_O_CREAT) {
5491 // 4-arg version
5492 PRINT("sys_openat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,(char*)ARG2,ARG3,ARG4);
5493 PRE_REG_READ4(int, "openat",
5494 int, fd, const char *, path, int, flags, vki_mode_t, mode);
5495 } else {
5496 // 3-arg version
5497 PRINT("sys_openat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )",ARG1,ARG2,(char*)ARG2,ARG3);
5498 PRE_REG_READ3(int, "openat",
5499 int, fd, const char *, path, int, flags);
5502 if (ARG1 != (unsigned)VKI_AT_FDCWD && !ML_(fd_allowed)(ARG1, "openat", tid, False)) {
5503 SET_STATUS_Failure( VKI_EBADF );
5504 } else {
5505 PRE_MEM_RASCIIZ( "openat(path)", ARG2 );
5508 /* Otherwise handle normally */
5509 *flags |= SfMayBlock;
5512 POST(sys_openat)
5514 vg_assert(SUCCESS);
5515 if (!ML_(fd_allowed)(RES, "openat", tid, True)) {
5516 VG_(close)(RES);
5517 SET_STATUS_Failure( VKI_EMFILE );
5518 } else {
5519 if (VG_(clo_track_fds)) {
5520 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG2);
5525 // SYS_readlinkat 500
5526 // ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf,
5527 // size_t bufsize);
5528 PRE(sys_readlinkat)
5530 Word saved = SYSNO;
5531 Bool curproc_file = False;
5533 PRINT("sys_readlinkat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %llu )", ARG1,ARG2,(char*)ARG2,ARG3,(ULong)ARG4);
5534 PRE_REG_READ4(ssize_t, "readlinkat",
5535 int, fd, const char *, path, char *, buf, int, bufsize);
5536 PRE_MEM_RASCIIZ( "readlinkat(path)", ARG2 );
5537 PRE_MEM_WRITE( "readlinkat(buf)", ARG3,ARG4 );
5539 if (VG_(have_slash_proc) == True && (Int)ARG1 == VKI_AT_FDCWD) {
5541 * Handle the case where readlinkat is looking at /proc/curproc/file or
5542 * /proc/<pid>/file.
5544 do_readlink((const HChar *)ARG2, (HChar *)ARG3, (SizeT)ARG4, status, &curproc_file);
5547 // @todo PJF there is still the case where fd refers to /proc or /proc/pid
5548 // or /proc/curproc and path is relative pid/file, curptoc/file or just file
5550 if (!curproc_file) {
5551 /* Normal case */
5552 SET_STATUS_from_SysRes( VG_(do_syscall4)(saved, ARG1, ARG2, ARG3, ARG4));
5554 if (SUCCESS && RES > 0) {
5555 POST_MEM_WRITE( ARG3, RES );
5559 POST(sys_readlinkat)
5561 POST_MEM_WRITE( ARG3, RES );
5564 // SYS_renameat 501
5565 // int renameat(int fromfd, const char *from, int tofd, const char *to);
5566 PRE(sys_renameat)
5568 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);
5569 PRE_REG_READ4(int, "renameat",
5570 int, fromfd, const char *, from,
5571 int, tofd, const char *, to);
5572 PRE_MEM_RASCIIZ( "renameat(oldpath)", ARG2 );
5573 PRE_MEM_RASCIIZ( "renameat(newpath)", ARG4 );
5576 // SYS_symlinkat 502
5577 // int symlinkat(const char *name1, int fd, const char *name2);
5578 PRE(sys_symlinkat)
5580 *flags |= SfMayBlock;
5581 PRINT("sys_symlinkat ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s) )",ARG1,(char*)ARG1,ARG2,ARG3,(char*)ARG3);
5582 PRE_REG_READ3(int, "symlinkat",
5583 const char *, name1, int, fd, const char *, name2);
5584 PRE_MEM_RASCIIZ( "symlinkat(name1)", ARG1 );
5585 PRE_MEM_RASCIIZ( "symlinkat(name2)", ARG3 );
5588 // SYS_unlinkat 503
5589 // int unlinkat(int fd, const char *path, int flag);
5590 PRE(sys_unlinkat)
5592 *flags |= SfMayBlock;
5593 PRINT("sys_unlinkat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u ",
5594 ARG1, ARG2, (char*)ARG2, ARG3);
5595 PRE_REG_READ3(int, "unlinkat", int, fd, const char *, path, int, flag);
5596 PRE_MEM_RASCIIZ( "unlinkat(path)", ARG2 );
5599 // SYS_posix_openpt 504
5600 // int posix_openpt(int oflag);
5601 PRE(sys_posix_openpt)
5603 PRINT("sys_posix_openpt ( %" FMT_REGWORD "d )", SARG1);
5604 PRE_REG_READ1(int, "posix_openpt", int, oflag);
5607 // SYS_gssd_syscall 505
5608 // @todo
5609 // see https://www.freebsd.org/cgi/man.cgi?format=html&query=gssapi(3)
5610 // syscalls.master says ; 505 is initialised by the kgssapi code, if present.
5612 // SYS_jail_get 506
5613 // int jail_get(struct iovec *iov, u_int niov, int flags);
5614 PRE(sys_jail_get)
5616 PRINT("sys_jail_get ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
5617 PRE_REG_READ3(int, "jail_get", struct vki_iovec *, iov, unsigned int,
5618 niov, int, flags);
5619 PRE_MEM_READ("jail_get(iov)", ARG1, ARG2 * sizeof(struct vki_iovec));
5622 // SYS_jail_set 507
5623 // int jail_set(struct iovec *iov, u_int niov, int flags);
5624 PRE(sys_jail_set)
5626 PRINT("sys_jail_set ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
5627 PRE_REG_READ3(int, "jail_set", struct vki_iovec *, iov, unsigned int,
5628 niov, int, flags);
5629 PRE_MEM_READ("jail_set(iovs)", ARG1, ARG2 * sizeof(struct vki_iovec));
5632 // SYS_jail_remove 508
5633 // int jail_remove(int jid);
5634 PRE(sys_jail_remove)
5636 PRINT("sys_jail_remove ( %" FMT_REGWORD "d )", SARG1);
5637 PRE_REG_READ1(int, "jail_remove", int, jid);
5640 // SYS_closefrom 509
5641 // void closefrom(int lowfd);
5642 PRE(sys_closefrom)
5644 PRINT("sys_closefrom ( %" FMT_REGWORD "dx )", SARG1);
5645 PRE_REG_READ1(int, "closefrom", int, lowfd);
5648 * Can't pass this on to the kernel otherwise it will close
5649 * all of the host files like the log
5652 for (int fd = ARG1; fd < VG_(fd_hard_limit); ++fd) {
5653 if ((fd != 2/*stderr*/ || VG_(debugLog_getLevel)() == 0)
5654 && fd != VG_(log_output_sink).fd
5655 && fd != VG_(xml_output_sink).fd)
5656 VG_(close)(fd);
5659 SET_STATUS_Success(0);
5662 POST(sys_closefrom)
5664 unsigned int fd;
5665 unsigned int last = VG_(fd_hard_limit);
5667 if (!VG_(clo_track_fds))
5668 return;
5670 for (fd = ARG1; fd <= last; fd++)
5671 if ((fd != 2/*stderr*/ || VG_(debugLog_getLevel)() == 0)
5672 && fd != VG_(log_output_sink).fd
5673 && fd != VG_(xml_output_sink).fd)
5674 ML_(record_fd_close)(tid, fd);
5677 // SYS___semctl 510
5678 // int semctl(int semid, int semnum, int cmd, ...);
5679 // int __semctl(int semid, int semnum, int cmd, _Inout_ union semun *arg);
5680 PRE(sys___semctl)
5682 union vki_semun* semun;
5684 switch (ARG3) {
5685 case VKI_IPC_STAT:
5686 case VKI_SEM_STAT:
5687 case VKI_IPC_SET:
5688 case VKI_GETALL:
5689 case VKI_SETALL:
5690 PRINT("sys___semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
5691 PRE_REG_READ4(long, "semctl",
5692 int, semid, int, semnum, int, cmd, union vki_semun *, arg);
5693 PRE_MEM_READ("sys___sysctl(arg)", ARG4, sizeof(union vki_semun));
5694 semun = (union vki_semun*)ARG4;
5695 if (ML_(safe_to_deref)(semun, sizeof(*semun))) {
5696 ARG4 = (RegWord)semun;
5697 ML_(generic_PRE_sys_semctl)(tid, ARG1,ARG2,ARG3,ARG4);
5699 break;
5700 default:
5701 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
5702 PRE_REG_READ3(long, "semctl",
5703 int, semid, int, semnum, int, cmd);
5704 break;
5708 POST(sys___semctl)
5710 union vki_semun* semun = (union vki_semun*)ARG4;
5711 if (ML_(safe_to_deref)(semun, sizeof(*semun))) {
5712 ARG4 = (RegWord)semun;
5713 ML_(generic_POST_sys_semctl)(tid, RES, ARG1,ARG2,ARG3,ARG4);
5717 // SYS_msgctl 511
5718 // int msgctl(int msqid, int cmd, struct msqid_ds *buf);
5719 PRE(sys_msgctl)
5721 PRINT("sys_msgctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3 );
5723 PRE_REG_READ3(int, "msgctl", int, msqid, int, cmd, struct msqid_ds *, buf);
5725 switch (ARG2 /* cmd */) {
5726 case VKI_IPC_STAT:
5727 PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)",
5728 ARG3, sizeof(struct vki_msqid_ds) );
5729 break;
5730 case VKI_IPC_SET:
5731 PRE_MEM_READ( "msgctl(IPC_SET, buf)",
5732 ARG3, sizeof(struct vki_msqid_ds) );
5733 break;
5737 POST(sys_msgctl)
5739 switch (ARG2 /* cmd */) {
5740 case VKI_IPC_STAT:
5741 POST_MEM_WRITE( ARG3, sizeof(struct vki_msqid_ds) );
5742 break;
5747 // SYS_shmctl 512
5748 // int shmctl(int shmid, int cmd, struct shmid_ds *buf);
5749 PRE(sys_shmctl)
5751 PRINT("sys_shmctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,SARG2,ARG3);
5752 PRE_REG_READ3(int, "shmctl",
5753 int, shmid, int, cmd, struct vki_shmid_ds *, buf);
5754 switch (ARG2 /* cmd */) {
5755 case VKI_IPC_STAT:
5756 PRE_MEM_WRITE( "shmctl(IPC_STAT, buf)",
5757 ARG3, sizeof(struct vki_shmid_ds) );
5758 break;
5759 case VKI_IPC_SET:
5760 PRE_MEM_READ( "shmctl(IPC_SET, buf)",
5761 ARG3, sizeof(struct vki_shmid_ds) );
5762 break;
5766 POST(sys_shmctl)
5768 if (ARG2 == VKI_IPC_STAT) {
5769 POST_MEM_WRITE( ARG3, sizeof(struct vki_shmid_ds) );
5773 // SYS_lpathconf 513
5774 // long lpathconf(const char *path, int name);
5775 PRE(sys_lpathconf)
5777 PRINT("sys_lpathconf ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d)", ARG1, SARG2);
5778 PRE_REG_READ2(long, "lpathconf", const char *, path, int, name);
5779 PRE_MEM_RASCIIZ("lpathconf(path)", ARG1);
5782 // SYS___cap_rights_get 515
5783 // note extra 1st argument for the internal function which is not present
5784 // in the public interface
5785 // int __cap_rights_get(int version, int fd, cap_rights_t *rights);
5786 PRE(sys_cap_rights_get)
5788 PRINT("sys_cap_rights_get ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, SARG2, ARG3);
5789 PRE_REG_READ3(long, "cap_rights_get", int, version, int, fd, vki_cap_rights_t*, rights);
5790 PRE_MEM_WRITE("cap_rights_get(rights)", ARG3, sizeof(vki_cap_rights_t));
5793 POST(sys_cap_rights_get)
5795 POST_MEM_WRITE(ARG2, sizeof(vki_cap_rights_t));
5798 // SYS_cap_enter 516
5799 // int cap_enter(void);
5800 PRE(sys_cap_enter)
5802 PRINT("%s", "sys_cap_enter ( )");
5803 PRE_REG_READ0(int, "cap_enter");
5804 static Bool warning_given = False;
5805 if (!warning_given) {
5806 warning_given = True;
5807 capabiltyMode = True;
5808 VG_(umsg)(
5809 "WARNING: Valgrind may not operate correctly in capability mode.\n"
5810 " Please consider disabling capability by using the RUNNING_ON_VALGRIND mechanism.\n"
5811 " See http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq\n");
5813 /* now complete loading debuginfo since it is not allowed after entering cap mode */
5814 VG_(load_all_debuginfo)();
5817 // SYS_cap_getmode 517
5818 // int cap_getmode(u_int *modep);
5819 PRE(sys_cap_getmode)
5821 PRINT("sys_cap_getmode ( %#" FMT_REGWORD "x )", ARG1);
5822 PRE_REG_READ1(int, "cap_getmode", u_int*, modep);
5823 PRE_MEM_WRITE("cap_getmode(modep)", ARG1, sizeof(u_int));
5826 POST(sys_cap_getmode)
5828 POST_MEM_WRITE(ARG1, sizeof(u_int));
5831 static vki_sigset_t pdfork_saved_mask;
5833 // SYS_pdfork 518
5834 // pid_t pdfork(int *fdp, int flags);
5835 PRE(sys_pdfork)
5837 Bool is_child;
5838 Int child_pid;
5839 vki_sigset_t mask;
5841 PRINT("sys_pdfork ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1, ARG2);
5842 PRE_REG_READ2(pid_t, "pdfork", int*, fdp, int, flags);
5844 /* Block all signals during fork, so that we can fix things up in
5845 the child without being interrupted. */
5846 VG_(sigfillset)(&mask);
5847 VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &pdfork_saved_mask);
5849 VG_(do_atfork_pre)(tid);
5851 SET_STATUS_from_SysRes( VG_(do_syscall2)(__NR_pdfork, ARG1, ARG2) );
5853 if (!SUCCESS) {
5854 return;
5857 // RES is 0 for child, non-0 (the child's PID) for parent.
5858 is_child = ( RES == 0 ? True : False );
5859 child_pid = ( is_child ? -1 : (Int)RES );
5861 if (is_child) {
5862 VG_(do_atfork_child)(tid);
5864 /* restore signal mask */
5865 VG_(sigprocmask)(VKI_SIG_SETMASK, &pdfork_saved_mask, NULL);
5866 } else {
5867 VG_(do_atfork_parent)(tid);
5869 PRINT(" fork: process %d created child %d\n", VG_(getpid)(), child_pid);
5871 /* restore signal mask */
5872 VG_(sigprocmask)(VKI_SIG_SETMASK, &pdfork_saved_mask, NULL);
5875 if (ARG1) {
5876 PRE_MEM_WRITE( "pdfork(fdp)", ARG1, sizeof(int) );
5880 POST(sys_pdfork)
5882 if (ARG1) {
5883 POST_MEM_WRITE( ARG1, sizeof(int) );
5887 // pdkill 519
5888 //int pdkill(int fd, int signum)
5889 PRE(sys_pdkill)
5891 PRINT("sys_pdkill ( %" FMT_REGWORD "u, %" FMT_REGWORD "d )", ARG1, SARG2);
5892 PRE_REG_READ2(int, "pdkill", int, fd, int, signum);
5894 if (!ML_(client_signal_OK)(ARG2)) {
5895 SET_STATUS_Failure( VKI_EINVAL );
5896 return;
5899 /* Ther was some code here to check if the kill is to this process
5901 * But it was totally wrong
5903 * It was calling ML_(do_sigkill)(Int pid, Int tgid)
5905 * With a file descriptor
5907 * Fortunately this will never match a real process otherwise
5908 * it might have accidentally killed us.
5910 * For a start we need the pid, obtained with pdgetpid
5911 * Next ML_(do_sigkill) doesn't map to FreeBSD. It takes a
5912 * pid (lwpid) and a tgid (threadgroup)
5914 * On FreeBSD lwpid is the tid and threadgroup is the pid
5915 * The kill functions operate on pids, not tids.
5917 * One last thing, I don't see how pdkill could do a self
5918 * kill 9. It neads an fd which implied pdfork whichimplies
5919 * that the fd/pid are for a child process
5922 SET_STATUS_from_SysRes(VG_(do_syscall2)(SYSNO, ARG1, ARG2));
5924 if (VG_(clo_trace_signals)) {
5925 VG_(message)(Vg_DebugMsg, "pdkill: sent signal %ld to fd %ld\n",
5926 SARG2, SARG1);
5929 /* This kill might have given us a pending signal. Ask for a check once
5930 the syscall is done. */
5931 *flags |= SfPollAfter;
5935 // SYS_pdgetpid 520
5936 // int pdgetpid(int fd, pid_t *pidp);
5937 PRE(sys_pdgetpid)
5939 PRINT("pdgetpid ( %" FMT_REGWORD "d, %#lx )", SARG1, ARG2);
5940 PRE_REG_READ2(int, "pdgetpid",
5941 int, fd, pid_t*, pidp);
5942 PRE_MEM_WRITE( "pdgetpid(pidp))", ARG2, sizeof(vki_pid_t) );
5945 POST(sys_pdgetpid)
5947 POST_MEM_WRITE( ARG2, sizeof(vki_pid_t) );
5950 // SYS_pselect 522
5952 // int pselect(int nfds, fd_set * restrict readfds, fd_set * restrict writefds,
5953 // fd_set * restrict exceptfds,
5954 // const struct timespec * restrict timeout,
5955 // const sigset_t * restrict newsigmask);
5956 PRE(sys_pselect)
5958 *flags |= SfMayBlock | SfPostOnFail;
5959 PRINT("sys_pselect ( %ld, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#"
5960 FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
5961 SARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5962 PRE_REG_READ6(int, "pselect",
5963 int, nfds, vki_fd_set *, readfds, vki_fd_set *, writefds,
5964 vki_fd_set *, exceptfds, struct vki_timespec *, timeout,
5965 const sigset_t *, newsigmask);
5966 // XXX: this possibly understates how much memory is read.
5967 if (ARG2 != 0) {
5968 PRE_MEM_READ( "pselect(readfds)",
5969 ARG2, ARG1/8 /* __FD_SETSIZE/8 */ );
5971 if (ARG3 != 0) {
5972 PRE_MEM_READ( "pselect(writefds)",
5973 ARG3, ARG1/8 /* __FD_SETSIZE/8 */ );
5975 if (ARG4 != 0) {
5976 PRE_MEM_READ( "pselect(exceptfds)",
5977 ARG4, ARG1/8 /* __FD_SETSIZE/8 */ );
5979 if (ARG5 != 0) {
5980 PRE_MEM_READ( "pselect(timeout)", ARG5, sizeof(struct vki_timeval) );
5983 if (ARG6 != 0) {
5984 PRE_MEM_READ( "pselect(sig)", ARG6, sizeof(vki_sigset_t) );
5985 ARG6 = ML_(make_safe_mask)("syswrap.pselect.1", (Addr)ARG6);
5989 POST(sys_pselect)
5991 ML_(free_safe_mask) ( (Addr)ARG6 );
5994 // SYS_getloginclass 523
5995 // int getloginclass(char *name, size_t len);
5996 PRE(sys_getloginclass)
5998 PRINT("sys_getloginclass ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
5999 PRE_REG_READ2(int, "getloginclass", char *, name, size_t, len);
6000 // The buffer should be at least MAXLOGNAME bytes in length.
6001 PRE_MEM_WRITE("getloginclass(name)", ARG1, ARG2);
6004 POST(sys_getloginclass)
6006 POST_MEM_WRITE(ARG1, ARG2);
6009 // SYS_setloginclass 524
6010 // int setloginclass(const char *name);
6011 PRE(sys_setloginclass)
6013 PRINT("sys_setloginclass ( %#" FMT_REGWORD "x(%s) )", ARG1, (HChar*)ARG1);
6014 PRE_REG_READ1(int, "setloginclass", const char *, name);
6015 PRE_MEM_RASCIIZ("rctl_setloginclass(name)", ARG1);
6018 // SYS_rctl_get_racct 525
6019 // int rctl_get_racct(const char *inbufp, size_t inbuflen, char *outbufp,
6020 // size_t outbuflen);
6021 PRE(sys_rctl_get_racct)
6023 PRINT("sys_rctl_get_racct ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
6024 PRE_REG_READ4(int, "rctl_get_racct", const char *, inbufp, size_t, inbuflen, char *, outbufp,
6025 size_t, outbuflen);
6026 PRE_MEM_READ("rctl_get_racct(inbufp)", ARG1, ARG2);
6027 PRE_MEM_WRITE("rctl_get_racct(outbufp)", ARG3, ARG4);
6030 POST(sys_rctl_get_racct)
6032 POST_MEM_WRITE(ARG3, ARG4);
6035 // SYS_rctl_get_rules 526
6036 // int rctl_get_rules(const char *inbufp, size_t inbuflen, char *outbufp,
6037 // size_t outbuflen);
6038 PRE(sys_rctl_get_rules)
6040 PRINT("sys_rctl_get_rules ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
6041 PRE_REG_READ4(int, "rctl_get_rules", const char *, inbufp, size_t, inbuflen, char *, outbufp,
6042 size_t, outbuflen);
6043 PRE_MEM_READ("rctl_get_rules(inbufp)", ARG1, ARG2);
6044 PRE_MEM_WRITE("rctl_get_rules(outbufp)", ARG3, ARG4);
6047 POST(sys_rctl_get_rules)
6049 POST_MEM_WRITE(ARG3, ARG4);
6052 // SYS_rctl_get_limits 527
6053 // int rctl_get_limits(const char *inbufp, size_t inbuflen, char *outbufp,
6054 // size_t outbuflen);
6055 PRE(sys_rctl_get_limits)
6057 PRINT("sys_rctl_get_limits ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
6058 PRE_REG_READ4(int, "rctl_get_limits", const char *, inbufp, size_t, inbuflen, char *, outbufp,
6059 size_t, outbuflen);
6060 PRE_MEM_READ("rctl_get_limits(inbufp)", ARG1, ARG2);
6061 PRE_MEM_WRITE("rctl_get_limits(outbufp)", ARG3, ARG4);
6064 POST(sys_rctl_get_limits)
6066 POST_MEM_WRITE(ARG3, ARG4);
6069 // SYS_rctl_add_rule 528
6070 // int rctl_add_rule(const char *inbufp, size_t inbuflen, char *outbufp,
6071 // size_t outbuflen);
6072 PRE(sys_rctl_add_rule)
6074 PRINT("sys_rctl_add_rule ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
6075 PRE_REG_READ2(int, "rctl_add_rule", const char *, inbufp, size_t, inbuflen);
6076 PRE_MEM_READ("rctl_add_rule(inbufp)", ARG1, ARG2);
6077 // man page says
6078 // The outbufp and outbuflen arguments are unused
6079 //PRE_MEM_WRITE("rctl_add_rule(outbufp)", ARG3, ARG4);
6082 POST(sys_rctl_add_rule)
6084 //POST_MEM_WRITE(ARG3, ARG4);
6087 // SYS_rctl_remove_rule 529
6088 // int rctl_remove_rule(const char *inbufp, size_t inbuflen, char *outbufp,
6089 // size_t outbuflen);
6090 PRE(sys_rctl_remove_rule)
6092 PRINT("sys_rctl_remove_rule ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
6093 PRE_REG_READ2(int, "rctl_remove_rule", const char *, inbufp, size_t, inbuflen);
6094 PRE_MEM_READ("rctl_remove_rule(inbufp)", ARG1, ARG2);
6095 // man page says
6096 // The outbufp and outbuflen arguments are unused
6097 //PRE_MEM_WRITE("rctl_remove_rule(outbufp)", ARG3, ARG4);
6100 POST(sys_rctl_remove_rule)
6102 //POST_MEM_WRITE(ARG3, ARG4);
6105 // SYS_posix_fallocate 530
6106 // x86/amd64
6108 // SYS_posix_fadvise 531
6109 // x86/amd64
6111 // SYS_wait6 532
6112 // amd64 / x86
6114 // SYS_cap_rights_limit 533
6115 //int cap_rights_limit(int fd, const cap_rights_t *rights);
6116 PRE(sys_cap_rights_limit)
6118 PRINT("sys_cap_rights_limit ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6119 PRE_REG_READ2(int, "cap_rights_limit",
6120 int, fd, const cap_rights_t *, rights);
6121 PRE_MEM_READ( "cap_rights_limit(rights)", ARG2, sizeof(struct vki_cap_rights) );
6124 // SYS_cap_ioctls_limit 534
6125 // int cap_ioctls_limit(int fd, const unsigned long *cmds, size_t ncmds);
6126 PRE(sys_cap_ioctls_limit)
6128 PRINT("cap_ioctls_limit ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
6129 PRE_REG_READ3(int, "cap_ioctls_limit",
6130 int, fd, unsigned long*, rights, vki_size_t, ncmds);
6131 // "can be up to 256" taking that to not be inclusive
6132 if (ARG3 < 256 ) {
6133 PRE_MEM_READ( "cap_ioctls_limit(cmds))", ARG2, ARG3*sizeof(unsigned long) );
6135 // else fail?
6138 // SYS_cap_ioctls_get 535
6139 // int cap_ioctls_get(int fd, unsigned long *cmds, size_t maxcmds);
6140 PRE(sys_cap_ioctls_get)
6142 PRINT("sys_cap_ioctls_get ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", SARG1, ARG2, ARG3);
6143 PRE_REG_READ3(int, "cap_ioctls_get", int, fd, unsigned long *, cmds, size_t, maxcmds);
6144 if (ARG3 < 256) {
6145 PRE_MEM_WRITE("cap_ioctls_get(cmds)", ARG2, ARG3*sizeof(unsigned long));
6149 POST(sys_cap_ioctls_get)
6151 if (ARG3 < 256) {
6152 POST_MEM_WRITE(ARG2, ARG3*sizeof(unsigned long));
6157 // SYS_cap_fcntls_limit 536
6158 //int cap_fcntls_limit(int fd, uint32_t fcntlrights);
6159 PRE(sys_cap_fcntls_limit)
6161 PRINT("cap_fcntls_limit ( %" FMT_REGWORD "d, %" FMT_REGWORD "u )", SARG1, ARG2);
6162 PRE_REG_READ2(long, "cap_fcntls_limit",
6163 int, fd, vki_uint32_t, fcntlrights);
6166 // SYS_cap_fcntls_get 537
6167 // int cap_fcntls_get(int fd, uint32_t *fcntlrightsp);
6168 PRE(sys_cap_fcntls_get)
6170 PRINT("sys_cap_fcntls_get ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6171 PRE_REG_READ2(int, "cap_fcntls_get", int, fd, uint32_t *, fcntlrightsp);
6172 PRE_MEM_WRITE("cap_fcntls_get(fcntlrightsp)", ARG2, sizeof(uint32_t));
6175 POST(sys_cap_fcntls_get)
6177 POST_MEM_WRITE(ARG2, sizeof(uint32_t));
6180 // SYS_bindat 538
6181 // int bindat(int fd, int s, const struct sockaddr *addr, socklen_t addrlen);
6182 PRE(sys_bindat)
6184 PRINT("sys_bindat ( %" FMT_REGWORD "d, %" FMT_REGWORD "dx, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",
6185 SARG1, SARG2, ARG3, ARG4);
6186 PRE_REG_READ4(int, "bindat", int, fd, int, s, const struct vki_sockaddr *, name, vki_socklen_t, namelen);
6187 PRE_MEM_READ("bindat(name)", ARG3, ARG4);
6190 // SYS_connectat 539
6191 // int connectat(int fd, int s, const struct sockaddr *name, socklen_t namelen);
6192 PRE(sys_connectat)
6194 PRINT("sys_connectat ( %" FMT_REGWORD "d, %" FMT_REGWORD "dx, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",
6195 SARG1, SARG2, ARG3, ARG4);
6196 PRE_REG_READ4(int, "connectat", int, fd, int, s, const struct vki_sockaddr *, name, vki_socklen_t, namelen);
6197 PRE_MEM_READ("connectat(name)", ARG3, ARG4);
6200 // SYS_chflagsat 540
6201 // int chflagsat(int fd, const char *path, unsigned long flags, int atflag);
6202 PRE(sys_chflagsat)
6204 PRINT("sys_chglagsat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d )",
6205 SARG1, ARG2, ARG3, SARG4);
6206 PRE_REG_READ4(int, "chflagsat", int, fd, const char *, path, unsigned long, flags, int, atflag);
6207 PRE_MEM_RASCIIZ("chflagsat(path)", ARG2);
6210 // SYS_accept4 541
6211 // int accept4(int s, struct sockaddr * restrict addr,
6212 // socklen_t * restrict addrlen, int flags);
6213 PRE(sys_accept4)
6215 *flags |= SfMayBlock;
6216 PRINT("sys_accept4 ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u)",ARG1,ARG2,ARG3,ARG4);
6217 PRE_REG_READ4(int, "accept4",
6218 int, s, struct sockaddr *, addr, int, *addrlen, int, flags);
6219 ML_(generic_PRE_sys_accept)(tid, ARG1,ARG2,ARG3);
6222 POST(sys_accept4)
6224 SysRes r;
6225 vg_assert(SUCCESS);
6226 r = ML_(generic_POST_sys_accept)(tid, VG_(mk_SysRes_Success)(RES),
6227 ARG1,ARG2,ARG3);
6228 SET_STATUS_from_SysRes(r);
6231 // SYS_pipe2 542
6232 // int pipe2(int fildes[2], int flags);
6233 PRE(sys_pipe2)
6235 PRINT("sys_pipe2 ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
6236 PRE_REG_READ2(int, "pipe2",
6237 int *, fildes, int, flags);
6238 PRE_MEM_WRITE("pipe2(fildes)", ARG1, 2 * sizeof(int));
6242 POST(sys_pipe2)
6244 int *fildes;
6246 if (RES != 0) {
6247 return;
6250 POST_MEM_WRITE(ARG1, 2 * sizeof(int));
6251 fildes = (int *)ARG1;
6253 if (!ML_(fd_allowed)(fildes[0], "pipe2", tid, True) ||
6254 !ML_(fd_allowed)(fildes[1], "pipe2", tid, True)) {
6255 VG_(close)(fildes[0]);
6256 VG_(close)(fildes[1]);
6257 SET_STATUS_Failure( VKI_EMFILE );
6258 } else if (VG_(clo_track_fds)) {
6259 ML_(record_fd_open_nameless)(tid, fildes[0]);
6260 ML_(record_fd_open_nameless)(tid, fildes[1]);
6264 // SYS_aio_mlock 543
6265 // int aio_mlock(struct aiocb *iocb);
6266 PRE(sys_aio_mlock)
6268 PRINT("sys_aio_mlock ( %#" FMT_REGWORD "x )", ARG1);
6269 PRE_REG_READ1(int, "aio_mlock", struct vki_aiocb *, iocb);
6270 PRE_MEM_READ("aio_mlock(iocb", ARG1, sizeof(struct vki_aiocb));
6271 // this locks memory into RAM, don't think that we need to do
6272 // anything extra
6275 // SYS_procctl 544
6276 // amd64 / x86
6278 // SYS_ppoll 545
6279 // int ppoll(struct pollfd fds[], nfds_t nfds,
6280 // const struct timespec * restrict timeout,
6281 // const sigset_t * restrict newsigmask);
6282 PRE(sys_ppoll)
6284 PRINT("sys_ppoll ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD
6285 "x, %#" FMT_REGWORD "x )",
6286 ARG1, ARG2, ARG3, ARG4);
6287 UInt i;
6288 struct vki_pollfd* fds = (struct vki_pollfd *)(Addr)ARG1;
6289 *flags |= SfMayBlock | SfPostOnFail;
6290 PRE_REG_READ4(long, "ppoll",
6291 struct vki_pollfd *, fds, unsigned int, nfds,
6292 struct vki_timespec *, timeout, vki_sigset_t *, newsigmask);
6294 for (i = 0; i < ARG2; i++) {
6295 PRE_MEM_READ( "ppoll(fds.fd)",
6296 (Addr)(&fds[i].fd), sizeof(fds[i].fd) );
6297 if (ML_(safe_to_deref)(&fds[i].fd, sizeof(fds[i].fd)) && fds[i].fd >= 0) {
6298 PRE_MEM_READ( "ppoll(fds.events)",
6299 (Addr)(&fds[i].events), sizeof(fds[i].events) );
6301 PRE_MEM_WRITE( "ppoll(fds.revents)",
6302 (Addr)(&fds[i].revents), sizeof(fds[i].revents) );
6305 if (ARG3) {
6306 PRE_MEM_READ( "ppoll(timeout)", ARG3,
6307 sizeof(struct vki_timespec) );
6309 if (ARG4) {
6310 PRE_MEM_READ( "ppoll(newsigmask)", ARG4, sizeof(vki_sigset_t));
6311 ARG4 = ML_(make_safe_mask)("syswrap.ppoll.1", (Addr)ARG4);
6315 POST(sys_ppoll)
6317 if (SUCCESS && ((Word)RES != -1)) {
6318 UInt i;
6319 struct vki_pollfd* ufds = (struct vki_pollfd *)(Addr)ARG1;
6320 for (i = 0; i < ARG2; i++) {
6321 POST_MEM_WRITE( (Addr)(&ufds[i].revents), sizeof(ufds[i].revents) );
6324 ML_(free_safe_mask) ( (Addr)ARG4 );
6327 // SYS_futimens 546
6328 // int futimens(int fd, const struct timespec times[2]);
6329 PRE(sys_futimens)
6331 PRINT("sys_futimens ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6332 PRE_REG_READ2(int, "futimens", int, fd, const struct timespec *, times);
6333 PRE_MEM_READ("futimens(times)", ARG2, 2*sizeof(struct vki_timespec));
6336 // SYS_utimensat 547
6337 // int utimensat(int fd, const char *path, const struct timespec times[2],
6338 // int flag);
6339 PRE(sys_utimensat)
6341 PRINT("sys_utimensat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )",
6342 SARG1, ARG2, ARG3, SARG4);
6343 PRE_REG_READ4(int, "utimensat", int, fd, const char *,path, const struct timespec *, times,
6344 int, flag);
6345 PRE_MEM_RASCIIZ("utimensat(path)", ARG2);
6346 PRE_MEM_READ("utimensat(times)", ARG3, 2*sizeof(struct vki_timespec));
6349 // SYS_fdatasync 550
6350 // int fdatasync(int fd);
6351 PRE(sys_fdatasync)
6353 PRINT("sys_fdatasync ( %" FMT_REGWORD "d )",SARG1);
6354 PRE_REG_READ1(int, "fdatasync", int, fd);
6357 #if (FREEBSD_VERS >= FREEBSD_12)
6358 // SYS_fstat 551
6359 // int fstat(int fd, struct stat *sb);
6360 PRE(sys_fstat)
6362 PRINT("sys_fstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
6363 PRE_REG_READ2(int, "fstat", int, fd, struct stat *, sb);
6364 PRE_MEM_WRITE( "fstat(sb)", ARG2, sizeof(struct vki_stat) );
6367 POST(sys_fstat)
6369 POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) );
6372 // SYS_fstatat 552
6373 // int fstatat(int fd, const char *path, struct stat *sb, int flag);
6374 PRE(sys_fstatat)
6376 PRINT("sys_fstatat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %" FMT_REGWORD "d )", SARG1,ARG2,(char*)ARG2,ARG3,SARG4);
6377 PRE_REG_READ4(int, "fstatat",
6378 int, fd, const char *, path, struct stat *, sb, int, flag);
6379 PRE_MEM_RASCIIZ( "fstatat(path)", ARG2 );
6380 PRE_MEM_WRITE( "fstatat(sb)", ARG3, sizeof(struct vki_stat) );
6383 POST(sys_fstatat)
6385 POST_MEM_WRITE( ARG3, sizeof(struct vki_stat) );
6387 // SYS_fhstat 553
6388 // int fhstat(const fhandle_t *fhp, struct stat *sb);
6389 PRE(sys_fhstat)
6391 PRINT("sys_fhstat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
6392 PRE_REG_READ2(long, "fhstat", const vki_fhandle_t *, fhp, struct stat *, sb);
6393 PRE_MEM_READ( "fhstat(fhp)", ARG1, sizeof(struct vki_fhandle) );
6394 PRE_MEM_WRITE( "fhstat(sb)", ARG2, sizeof(struct vki_stat) );
6397 POST(sys_fhstat)
6399 POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) );
6402 // SYS_getdirentries 554
6403 // ssize_t getdirentries(int fd, char *buf, size_t nbytes, off_t *basep);
6404 PRE(sys_getdirentries)
6406 *flags |= SfMayBlock;
6407 PRINT("sys_getdirentries ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", SARG1,ARG2,ARG3,ARG4);
6408 PRE_REG_READ4(ssize_t, "getdirentries",
6409 int, fd, char *, buf,
6410 size_t, nbytes,
6411 off_t *, basep);
6412 PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 );
6413 if (ARG4) {
6414 PRE_MEM_WRITE("getdirentries(basep)", ARG4, sizeof (vki_off_t));
6418 POST(sys_getdirentries)
6420 vg_assert(SUCCESS);
6421 if (RES > 0) {
6422 POST_MEM_WRITE( ARG2, RES );
6423 if ( ARG4 != 0 ) {
6424 POST_MEM_WRITE( ARG4, sizeof (vki_off_t));
6429 // SYS_statfs 555
6430 // int statfs(const char *path, struct statfs *buf);
6431 PRE(sys_statfs)
6433 PRINT("sys_statfs ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
6434 PRE_REG_READ2(int, "statfs", const char *, path, struct statfs *, buf);
6435 PRE_MEM_RASCIIZ( "statfs(path)", ARG1 );
6436 PRE_MEM_WRITE( "statfs(buf)", ARG2, sizeof(struct vki_statfs) );
6439 POST(sys_statfs)
6441 POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) );
6444 // SYS_fstatfs 556
6445 // int fstatfs(int fd, struct statfs *buf);
6446 PRE(sys_fstatfs)
6448 PRINT("sys_fstatfs ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
6449 PRE_REG_READ2(int, "fstatfs",
6450 int, fd, struct vki_statfs *, buf);
6451 PRE_MEM_WRITE( "fstatfs(buf)", ARG2, sizeof(struct vki_statfs) );
6454 POST(sys_fstatfs)
6456 POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) );
6459 // SYS_getfsstat 557
6460 // int getfsstat(struct statfs *buf, long bufsize, int mode);
6461 PRE(sys_getfsstat)
6463 PRINT("sys_getfsstat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
6464 PRE_REG_READ3(long, "getfsstat", struct vki_statfs *, buf, long, len, int, flags);
6465 PRE_MEM_WRITE( "getfsstat(buf)", ARG1, ARG2 );
6468 POST(sys_getfsstat)
6470 vg_assert(SUCCESS);
6471 if ((Word)RES != -1) {
6472 POST_MEM_WRITE( ARG1, RES * sizeof(struct vki_statfs) );
6476 // SYS_fhstatfs 558
6477 // int fhstatfs(const fhandle_t *fhp, struct statfs *buf);
6478 PRE(sys_fhstatfs)
6480 PRINT("sys_fhstatfs ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
6481 PRE_REG_READ2(long, "fhstatfs",
6482 struct fhandle *, fhp, struct statfs *, buf);
6483 PRE_MEM_READ( "fhstatfs(fhp)", ARG1, sizeof(struct vki_fhandle) );
6484 PRE_MEM_WRITE( "fhstatfs(buf)", ARG2, sizeof(struct vki_statfs) );
6487 POST(sys_fhstatfs)
6489 POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) );
6492 // SYS_mknodat 559
6493 // x86 / amd64
6495 // SYS_kevent 560
6496 // int kevent(int kq, const struct kevent *changelist, int nchanges,
6497 // struct kevent *eventlist, int nevents,
6498 // const struct timespec *timeout);
6499 PRE(sys_kevent)
6501 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);
6502 PRE_REG_READ6(int, "kevent",
6503 int, kq, struct vki_kevent *, changelist, int, nchanges,
6504 struct vki_kevent *, eventlist, int, nevents,
6505 struct timespec *, timeout);
6506 if (ARG2 != 0 && ARG3 != 0) {
6507 PRE_MEM_READ( "kevent(changelist)", ARG2, sizeof(struct vki_kevent)*ARG3 );
6509 if (ARG4 != 0 && ARG5 != 0) {
6510 PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent)*ARG5);
6512 if (ARG5 != 0) {
6513 *flags |= SfMayBlock;
6515 if (ARG6 != 0) {
6516 PRE_MEM_READ( "kevent(timeout)",
6517 ARG6, sizeof(struct vki_timespec));
6521 POST(sys_kevent)
6523 vg_assert(SUCCESS);
6524 if ((Word)RES != -1) {
6525 if (ARG4 != 0) {
6526 POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent)*RES) ;
6531 // SYS_cpuset_getdomain 561
6532 // x86 / amd64
6534 // SYS_cpuset_setdomain 562
6535 // x86 / amd64
6537 // SYS_getrandom 563
6538 // ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
6539 PRE(sys_getrandom)
6541 PRINT("sys_getrandom ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
6542 PRE_REG_READ3(ssize_t, "getrandom",
6543 void *, buf, vki_size_t, buflen, unsigned int, flags);
6544 PRE_MEM_WRITE( "getrandom(buf)", ARG1, ARG2 );
6545 if ((ARG3 & VKI_GRND_NONBLOCK) == 0) {
6546 *flags |= SfMayBlock;
6550 POST(sys_getrandom)
6552 POST_MEM_WRITE( ARG1, ARG2 );
6555 // SYS_getfhat 564
6556 // int getfhat(int fd, const char *path, fhandle_t *fhp, int flag);
6557 PRE(sys_getfhat)
6559 PRINT("sys_getfhat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "x, %" FMT_REGWORD "d ", SARG1, ARG2, ARG3, SARG4);
6560 PRE_REG_READ4(int, "getfhat", int, fd, const char*, path, vki_fhandle_t*, fhp, int, flag);
6561 PRE_MEM_RASCIIZ( "getfhat(path)", ARG2 );
6562 PRE_MEM_WRITE("getfhat(fhp)", ARG3, sizeof(vki_fhandle_t));
6565 POST(sys_getfhat)
6567 POST_MEM_WRITE(ARG3, sizeof(vki_fhandle_t));
6570 // SYS_fhlink 565
6571 // int fhlink(fhandle_t *fhp, const char *to);
6572 PRE(sys_fhlink)
6574 PRINT("sys_fhlink ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1, ARG2);
6575 PRE_REG_READ2(int, "fhlink", vki_fhandle_t *, fhp, const char *, to);
6576 PRE_MEM_READ( "fhlink(fhp)", ARG1, sizeof(vki_fhandle_t));
6577 PRE_MEM_RASCIIZ("fhlink(buf)", ARG2);
6580 // SYS_fhlinkat 566
6581 // int fhlinkat(fhandle_t *fhp, int tofd, const char *to);
6582 PRE(sys_fhlinkat)
6584 PRINT("sys_fhlinkat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "xu ", ARG1, SARG2, ARG3);
6585 PRE_REG_READ3(int, "fhlinkat", vki_fhandle_t *, fhp, int, tofd, const char *, to);
6586 PRE_MEM_READ( "fhlinkat(fhp)", ARG1, sizeof(vki_fhandle_t));
6587 PRE_MEM_RASCIIZ("fhreadlink(to)", ARG3);
6590 // SYS_fhreadlink 567
6591 // int fhreadlink(fhandle_t *fhp, char *buf, size_t bufsize);
6592 PRE(sys_fhreadlink)
6594 PRINT("sys_fhreadlink ( %#" FMT_REGWORD "x, %" FMT_REGWORD "x, %" FMT_REGWORD "u ", ARG1, ARG2, ARG3);
6595 PRE_REG_READ3(int, "fhreadlink", vki_fhandle_t *, fhp, char *, buf, size_t, bufsize);
6596 PRE_MEM_READ( "fhreadlink(fhp)", ARG1, sizeof(vki_fhandle_t));
6597 PRE_MEM_WRITE("fhreadlink(buf)", ARG2, ARG3);
6600 POST(sys_fhreadlink)
6602 POST_MEM_WRITE(ARG2, ARG3);
6605 #endif
6607 #if (FREEBSD_VERS >= FREEBSD_12_2)
6609 // SYS_unlinkat 568
6610 // int funlinkat(int dfd, const char *path, int fd, int flag);
6611 PRE(sys_funlinkat)
6613 *flags |= SfMayBlock;
6614 PRINT("sys_funlinkat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %" FMT_REGWORD"u )",
6615 SARG1, ARG2, (char*)ARG2, ARG4, ARG5);
6616 PRE_REG_READ4(int, "funlinkat", int, dfd, const char *, path, int, fd, int, flag);
6617 PRE_MEM_RASCIIZ( "funlinkat(path)", ARG2 );
6620 // SYS_copy_file_range 569
6621 // ssize_t copy_file_range(int infd, off_t *inoffp, int outfd, off_t *outoffp,
6622 // size_t len, unsigned int flags);
6623 PRE(sys_copy_file_range)
6625 PRINT("sys_copy_file_range (%" FMT_REGWORD"d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "d, %" FMT_REGWORD "d)",
6626 SARG1, ARG2, SARG3, ARG4, (char*)ARG4, SARG5, SARG6);
6628 PRE_REG_READ6(vki_ssize_t, "copy_file_range",
6629 int, "infd",
6630 vki_off_t *, "inoffp",
6631 int, "outfd",
6632 vki_off_t *, "outoffp",
6633 vki_size_t, "len",
6634 unsigned int, "flags");
6636 /* File descriptors are "specially" tracked by valgrind.
6637 valgrind itself uses some, so make sure someone didn't
6638 put in one of our own... */
6639 if (!ML_(fd_allowed)(ARG1, "copy_file_range(infd)", tid, False) ||
6640 !ML_(fd_allowed)(ARG3, "copy_file_range(infd)", tid, False)) {
6641 SET_STATUS_Failure( VKI_EBADF );
6642 } else {
6643 /* Now see if the offsets are defined. PRE_MEM_READ will
6644 double check it can dereference them. */
6645 if (ARG2 != 0) {
6646 PRE_MEM_READ( "copy_file_range(inoffp)", ARG2, sizeof(vki_off_t));
6648 if (ARG4 != 0) {
6649 PRE_MEM_READ( "copy_file_range(outoffp)", ARG4, sizeof(vki_off_t));
6655 // SYS___sysctlbyname 570
6656 // int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
6657 // const void *newp, size_t newlen);
6658 // syscalls.master:
6659 // int __sysctlbyname(_In_reads_(namelen) const char *name, size_t namelen,
6660 // _Out_writes_bytes_opt_(*oldlenp) void *old,
6661 // _Inout_opt_ size_t *oldlenp, _In_reads_bytes_opt_(newlen) void *new,
6662 // size_t newlen );
6663 PRE(sys___sysctlbyname)
6665 // this is very much like SYS___sysctl, instead of having an OID with length
6666 // here threre is an ascii string with length
6667 // @todo PJF factor out the common functionality of the two
6668 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 );
6669 PRE_REG_READ6(int, "__sysctlbyname", const char *, name, vki_size_t, namelen,
6670 void *, oldp, vki_size_t *, oldlenp,
6671 void *, newp, vki_size_t, newlen);
6674 const char* name = (const char*)ARG1;
6675 if (ML_(safe_to_deref)(name, sizeof("kern.ps_strings")) &&
6676 VG_(strcmp)(name, "kern.ps_strings") == 0) {
6677 if (sysctl_kern_ps_strings((SizeT*)ARG3, (SizeT*)ARG4)) {
6678 SET_STATUS_Success(0);
6682 if (ML_(safe_to_deref)(name, sizeof("kern.usrstack")) &&
6683 VG_(strcmp)(name, "kern.usrstack") == 0) {
6684 sysctl_kern_usrstack((SizeT*)ARG3, (SizeT*)ARG4);
6685 SET_STATUS_Success(0);
6688 // kern.proc.pathname doesn't seem to be handled
6689 // makes sense as the pid is variable and using
6690 // a MIB is easier than generating a string
6692 // string length specified in ARG2 from mem pointed to by ARG1
6693 PRE_MEM_READ("__sysctlbyname(name)", (Addr)ARG1, ARG2);
6695 // if 'newp' is not NULL can read namelen bytes from that addess
6696 if (ARG5 != (UWord)NULL) {
6697 PRE_MEM_READ("__sysctlbyname(newp)", (Addr)ARG5, ARG6);
6700 // there are two scenarios for oldlenp/oldp
6701 // 1. oldval is NULL and oldlenp is non-NULL
6702 // this is a query of oldlenp so oldlenp will be written
6703 // 2. Both are non-NULL
6704 // this is a query of oldp, oldlenp will be read and oldp will
6705 // be written
6707 // is oldlenp is not NULL, can write
6708 if (ARG4 != (UWord)NULL) {
6709 if (ARG3 != (UWord)NULL) {
6710 // case 2 above
6711 PRE_MEM_READ("__sysctlbyname(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
6712 if (ML_(safe_to_deref)((void*)(Addr)ARG4, sizeof(vki_size_t))) {
6713 PRE_MEM_WRITE("__sysctlbyname(oldp)", (Addr)ARG3, *(vki_size_t *)ARG4);
6714 } else {
6715 VG_(dmsg)("Warning: Bad oldlenp address %p in sysctlbyname\n",
6716 (void *)(Addr)ARG4);
6717 SET_STATUS_Failure ( VKI_EFAULT );
6719 } else {
6720 // case 1 above
6721 PRE_MEM_WRITE("__sysctlbyname(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
6726 POST(sys___sysctlbyname)
6728 if (ARG4 != (UWord)NULL) {
6729 if (ARG3 != (UWord)NULL) {
6730 //POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
6731 POST_MEM_WRITE((Addr)ARG3, *(vki_size_t *)ARG4);
6732 } else {
6733 POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
6738 #endif // (FREEBSD_VERS >= FREEBSD_12_2)
6740 #if (FREEBSD_VERS >= FREEBSD_13_0)
6742 // SYS_shm_open2 571
6743 // from syscalls.master
6744 // int shm_open2(_In_z_ const char *path,
6745 // int flags,
6746 // mode_t mode,
6747 // int shmflags,
6748 // _In_z_ const char *name);
6749 PRE(sys_shm_open2)
6751 PRE_REG_READ5(int, "shm_open2",
6752 const char *, path, int, flags, vki_mode_t, mode, int, shmflags, const char*, name);
6753 if (ARG1 == VKI_SHM_ANON) {
6754 PRINT("sys_shm_open2(%#" FMT_REGWORD "x(SHM_ANON), %" FMT_REGWORD "u, %hu, %d, %#" FMT_REGWORD "x(%s))",
6755 ARG1, ARG2, (vki_mode_t)ARG3, (Int)ARG4, ARG5, (HChar*)ARG5);
6756 } else {
6757 PRINT("sys_shm_open2(%#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu, %d, %#" FMT_REGWORD "x(%s))",
6758 ARG1, (HChar *)ARG1, ARG2, (vki_mode_t)ARG3, (Int)ARG4, ARG5, (HChar*)ARG5);
6759 PRE_MEM_RASCIIZ( "shm_open2(path)", ARG1 );
6762 if (ARG5) {
6763 PRE_MEM_RASCIIZ( "shm_open2(name)", ARG5 );
6765 *flags |= SfMayBlock;
6768 POST(sys_shm_open2)
6770 vg_assert(SUCCESS);
6771 if (!ML_(fd_allowed)(RES, "shm_open2", tid, True)) {
6772 VG_(close)(RES);
6773 SET_STATUS_Failure( VKI_EMFILE );
6774 } else {
6775 if (VG_(clo_track_fds)) {
6776 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1);
6781 // SYS_sigfastblock 573
6782 // int sigfastblock(int cmd, void *ptr);
6783 PRE(sys_sigfastblock)
6785 PRINT("sys_sigfastblock ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6786 PRE_REG_READ2(int, "sigfasblock", int, cmd, void*, ptr);
6789 // SYS___realpathat 574
6790 // from syscalls.master
6791 // int __realpathat(int fd,
6792 // _In_z_ const char *path,
6793 // _Out_writes_z_(size) char *buf,
6794 // size_t size,
6795 // int flags)
6796 PRE(sys___realpathat)
6798 PRINT("sys___realpathat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %" FMT_REGWORD "u %" FMT_REGWORD "d )",
6799 SARG1,ARG2,(const char*)ARG2,ARG3,ARG4,SARG5 );
6800 PRE_REG_READ5(int, "__realpathat", int, fd, const char *, path,
6801 char *, buf, vki_size_t, size, int, flags);
6802 PRE_MEM_RASCIIZ("__realpathat(path)", (Addr)ARG2);
6803 PRE_MEM_WRITE("__realpathat(buf)", (Addr)ARG3, ARG4);
6806 POST(sys___realpathat)
6808 POST_MEM_WRITE((Addr)ARG3, ARG4);
6811 #endif
6813 #if (FREEBSD_VERS >= FREEBSD_12_2)
6815 // SYS_sys_close_range 575
6816 // int close_range(close_range(u_int lowfd, u_int highfd, int flags);
6817 PRE(sys_close_range)
6819 SysRes res = VG_(mk_SysRes_Success)(0);
6820 unsigned int lowfd = ARG1;
6821 unsigned int fd_counter; // will count from lowfd to highfd
6822 unsigned int highfd = ARG2;
6824 /* on linux the may lock if futexes are used
6825 * there is a lock in the kernel but I assume it's just
6826 * a spinlock */
6827 PRINT("sys_close_range ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %"
6828 FMT_REGWORD "d )", ARG1, ARG2, SARG3);
6829 PRE_REG_READ3(int, "close_range",
6830 unsigned int, lowfd, unsigned int, highfd,
6831 int, flags);
6833 if (lowfd > highfd) {
6834 SET_STATUS_Failure( VKI_EINVAL );
6835 return;
6838 if (highfd >= VG_(fd_hard_limit))
6839 highfd = VG_(fd_hard_limit) - 1;
6841 if (lowfd > highfd) {
6842 SET_STATUS_Success ( 0 );
6843 return;
6846 fd_counter = lowfd;
6847 do {
6848 if (fd_counter > highfd
6849 || (fd_counter == 2U/*stderr*/ && VG_(debugLog_getLevel)() > 0)
6850 || fd_counter == VG_(log_output_sink).fd
6851 || fd_counter == VG_(xml_output_sink).fd) {
6852 /* Split the range if it contains a file descriptor we're not
6853 * supposed to close. */
6854 if (fd_counter - 1 >= lowfd) {
6855 res = VG_(do_syscall3)(__NR_close_range, (UWord)lowfd, (UWord)fd_counter - 1, ARG3 );
6857 lowfd = fd_counter + 1;
6859 } while (fd_counter++ <= highfd);
6861 /* If it failed along the way, it's presumably the flags being wrong. */
6862 SET_STATUS_from_SysRes (res);
6865 POST(sys_close_range)
6867 unsigned int fd;
6868 unsigned int last = ARG2;
6870 if (!VG_(clo_track_fds)
6871 || (ARG3 & VKI_CLOSE_RANGE_CLOEXEC) != 0)
6872 return;
6874 if (last >= VG_(fd_hard_limit))
6875 last = VG_(fd_hard_limit) - 1;
6877 for (fd = ARG1; fd <= last; fd++)
6878 if ((fd != 2/*stderr*/ || VG_(debugLog_getLevel)() == 0)
6879 && fd != VG_(log_output_sink).fd
6880 && fd != VG_(xml_output_sink).fd)
6881 ML_(record_fd_close)(tid, fd);
6883 #endif
6885 #if (FREEBSD_VERS >= FREEBSD_13_0)
6887 // SYS___specialfd 577
6888 // syscalls.master
6889 // int __specialfd(int type,
6890 // _In_reads_bytes_(len) const void *req,
6891 // size_t len);
6892 PRE(sys___specialfd)
6894 PRINT("sys___specialfd ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )",
6895 SARG1,ARG2,(const char*)ARG2,ARG3 );
6896 PRE_REG_READ3(int, "__specialfd", int, type, const void *, req, vki_size_t, len);
6897 PRE_MEM_READ("__specialfd(req)", (Addr)ARG2, ARG3);
6900 // SYS_aio_writev 578
6901 // int aio_writev(struct aiocb *iocb);
6902 PRE(sys_aio_writev)
6904 PRINT("sys_aio_writev ( %#" FMT_REGWORD "x )", ARG1);
6905 PRE_REG_READ1(int, "aio_writev", struct vki_aiocb *, iocb);
6906 PRE_MEM_READ("aio_writev(iocb)", ARG1, sizeof(struct vki_aiocb));
6907 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
6908 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
6909 if (!ML_(fd_allowed)(iocb->aio_fildes, "aio_writev", tid, False)) {
6910 SET_STATUS_Failure( VKI_EBADF );
6911 } else {
6912 // aio_writev() gathers the data from the iocb->aio_iovcnt buffers specified
6913 // by the members of the iocb->aio_iov array
6914 // FreeBSD headers #define define this to aio_iovcnt
6915 SizeT vec_count = (SizeT)iocb->aio_nbytes;
6916 #if defined(__clang__)
6917 #pragma clang diagnostic push
6918 // yes, I know it is volatile
6919 #pragma clang diagnostic ignored "-Wcast-qual"
6920 #endif
6921 struct vki_iovec* p_iovec = (struct vki_iovec*)iocb->aio_buf;
6922 #if defined(__clang__)
6923 #pragma clang diagnostic pop
6924 #endif
6925 PRE_MEM_READ("aio_writev(iocb->aio_iov)", (Addr)p_iovec, vec_count*sizeof(struct vki_iovec));
6926 // and this to aio_iov
6928 if (ML_(safe_to_deref)(p_iovec, vec_count*sizeof(struct vki_iovec))) {
6929 for (SizeT i = 0U; i < vec_count; ++i) {
6930 PRE_MEM_READ("aio_writev(iocb->iov[...])",
6931 (Addr)p_iovec[i].iov_base, p_iovec[i].iov_len);
6935 } else {
6936 SET_STATUS_Failure(VKI_EINVAL);
6940 // SYS_aio_readv 579
6941 // int aio_readv(struct aiocb *iocb);
6942 PRE(sys_aio_readv)
6944 PRINT("sys_aio_readv ( %#" FMT_REGWORD "x )", ARG1);
6945 PRE_REG_READ1(int, "aio_readv", struct vki_aiocb *, iocb);
6946 PRE_MEM_READ("aio_readv(iocb)", ARG1, sizeof(struct vki_aiocb));
6947 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
6948 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
6949 if (!ML_(fd_allowed)(iocb->aio_fildes, "aio_readv", tid, False)) {
6950 SET_STATUS_Failure( VKI_EBADF );
6951 } else {
6952 SizeT vec_count = (SizeT)iocb->aio_nbytes;
6953 #if defined(__clang__)
6954 #pragma clang diagnostic push
6955 // yes, I know it is volatile
6956 #pragma clang diagnostic ignored "-Wcast-qual"
6957 #endif
6958 struct vki_iovec* p_iovec = (struct vki_iovec*)iocb->aio_buf;
6959 #if defined(__clang__)
6960 #pragma clang diagnostic pop
6961 #endif
6962 PRE_MEM_READ("aio_readv(iocb->aio_iov)", (Addr)p_iovec, vec_count*sizeof(struct vki_iovec));
6963 if (ML_(safe_to_deref)(p_iovec, vec_count*sizeof(struct vki_iovec))) {
6964 for (SizeT i = 0U; i < vec_count; ++i) {
6965 PRE_MEM_WRITE("aio_writev(iocb->aio_iov[...])",
6966 (Addr)p_iovec[i].iov_base, p_iovec[i].iov_len);
6970 } else {
6971 SET_STATUS_Failure(VKI_EINVAL);
6975 POST(sys_aio_readv)
6977 struct vki_aiocb* iocbv = (struct vki_aiocb*)ARG1;
6978 if (iocbv->aio_buf) {
6979 if (!aiov_init_done) {
6980 aiov_init();
6983 if (!VG_(OSetWord_Contains)(iocbv_table, (UWord)iocbv)) {
6984 VG_(OSetWord_Insert)(iocbv_table, (UWord)iocbv);
6985 } else {
6986 // @todo PJF this warns without callstack
6987 VG_(dmsg)("Warning: Duplicate control block %p in aio_readv\n",
6988 (void *)(Addr)ARG1);
6989 VG_(dmsg)("Warning: Ensure 'aio_return' is called when 'aio_readv' has completed\n");
6994 #endif // (FREEBSD_VERS >= FREEBSD_13_0)
6996 #if (FREEBSD_VERS >= FREEBSD_13_1)
6998 #if (FREEBSD_VERS >= FREEBSD_14)
6999 // SYS_fspacectl 580
7000 // int fspacectl(int fd, int cmd, const struct spacectl_range *rqsr, int flags,
7001 // struct spacectl_range *rmsr);
7002 PRE(sys_fspacectl)
7004 PRINT("fspacectl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, SARG2, ARG3, SARG4, ARG5);
7005 PRE_REG_READ5(int, "fspacectl", int, fd, int, cmd, const struct spacectl_range *, rqsr, int, flags, struct spacectl_range *, rmsr);
7006 PRE_MEM_READ("fspacectl(rqsr)", (Addr)ARG3, sizeof(struct vki_spacectl_range));
7007 if (ARG5) {
7008 PRE_MEM_WRITE("fspacectl(rmsr)", (Addr)ARG5, sizeof(struct vki_spacectl_range));
7012 POST(sys_fspacectl)
7014 if (ARG5) {
7015 POST_MEM_WRITE((Addr)ARG5, sizeof(struct vki_spacectl_range));
7018 #endif
7020 // SYS_swapoff 582
7021 // int swapoff(const char *special, u_int flags);
7022 PRE(sys_swapoff)
7024 PRINT("sys_swapoff(%#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u)", ARG1,(char *)ARG1, ARG2);
7025 PRE_REG_READ2(int, "swapoff", const char *, special, u_int, flags);
7026 PRE_MEM_RASCIIZ( "swapoff(special)", ARG1 );
7029 #endif
7031 #if (FREEBSD_VERS >= FREEBSD_15) || (FREEBSD_VERS >= FREEBSD_13_3)
7033 // SYS_kqueuex 583
7034 // int kqueuex(u_int flags);
7035 PRE(sys_kqueuex)
7037 PRINT("sys_kqueuex(%#" FMT_REGWORD "x)", ARG1);
7038 PRE_REG_READ1(int, "kqueuex", u_int, flags);
7041 POST(sys_kqueuex)
7043 if (!ML_(fd_allowed)(RES, "kqueuex", tid, True)) {
7044 VG_(close)(RES);
7045 SET_STATUS_Failure(VKI_EMFILE);
7046 } else {
7047 if (VG_(clo_track_fds)) {
7048 ML_(record_fd_open_nameless)(tid, RES);
7053 // SYS_membarrier 584
7054 // syscalls.master
7055 // int membarrier(int cmd, unsigned flags, int cpu_id);
7056 PRE(sys_membarrier)
7058 // cmd is signed int but the constants in the headers
7059 // are hex so print in hex
7060 PRINT("sys_membarrier(%#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "d)",
7061 ARG1, ARG2, SARG3);
7062 PRE_REG_READ3(int, "membarrier", int, cmd, unsigned, flags, int, cpu_id);
7065 #endif
7067 #if (FREEBSD_VERS >= FREEBSD_15)
7069 // SYS_timerfd_create 585
7070 // int timerfd_create(int clockid, int flags);
7071 PRE(sys_timerfd_create)
7073 PRINT("sys_timerfd_create (%ld, %ld )", SARG1, SARG2);
7074 PRE_REG_READ2(int, "timerfd_create", int, clockid, int, flags);
7077 POST(sys_timerfd_create)
7079 if (!ML_(fd_allowed)(RES, "timerfd_create", tid, True)) {
7080 VG_(close)(RES);
7081 SET_STATUS_Failure( VKI_EMFILE );
7082 } else {
7083 if (VG_(clo_track_fds))
7084 ML_(record_fd_open_nameless) (tid, RES);
7088 // SYS_timerfd_gettime 586
7089 // int timerfd_gettime(int fd, struct itimerspec *curr_value);
7090 PRE(sys_timerfd_gettime)
7092 PRINT("sys_timerfd_gettime ( %ld, %#" FMT_REGWORD "x )", SARG1, ARG2);
7093 PRE_REG_READ2(int, "timerfd_gettime",
7094 int, fd,
7095 struct vki_itimerspec*, curr_value);
7096 if (!ML_(fd_allowed)(ARG1, "timerfd_gettime", tid, False))
7097 SET_STATUS_Failure(VKI_EBADF);
7098 else
7099 PRE_MEM_WRITE("timerfd_gettime(curr_value)",
7100 ARG2, sizeof(struct vki_itimerspec));
7103 POST(sys_timerfd_gettime)
7105 if (RES == 0)
7106 POST_MEM_WRITE(ARG2, sizeof(struct vki_itimerspec));
7109 // SYS_timerfd_gettime 587
7110 // int timerfd_settime(int fd, int flags, const struct itimerspec *new_value,
7111 // struct itimerspec *old_value);
7112 PRE(sys_timerfd_settime)
7114 PRINT("sys_timerfd_settime(%" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#"
7115 FMT_REGWORD "x )", SARG1, SARG2, ARG3, ARG4);
7116 PRE_REG_READ4(int, "timerfd_settime",
7117 int, fd,
7118 int, flags,
7119 const struct vki_itimerspec*, new_value,
7120 struct vki_itimerspec*, old_value);
7121 if (!ML_(fd_allowed)(ARG1, "timerfd_settime", tid, False))
7122 SET_STATUS_Failure(VKI_EBADF);
7123 else
7125 PRE_MEM_READ("timerfd_settime(new_value)",
7126 ARG3, sizeof(struct vki_itimerspec));
7127 if (ARG4)
7129 PRE_MEM_WRITE("timerfd_settime(old_value)",
7130 ARG4, sizeof(struct vki_itimerspec));
7135 POST(sys_timerfd_settime)
7137 if (RES == 0 && ARG4 != 0) {
7138 POST_MEM_WRITE(ARG4, sizeof(struct vki_itimerspec));
7142 // SYS_kcmp 588
7143 // int kcmp(pid_t pid1, pid_t pid2, int type, uintptr_t idx1, uintptr_t idx2);
7144 PRE(sys_kcmp)
7146 PRINT("kcmp(%ld, %ld, %ld, %" FMT_REGWORD "u, %" FMT_REGWORD "u)",
7147 SARG1, SARG2, SARG3, ARG4, ARG5);
7148 switch (ARG3) {
7149 case VKI_KCMP_FILES:
7150 case VKI_KCMP_VM:
7151 case VKI_KCMP_SIGHAND:
7152 /* Most of the comparison types don't look at |idx1| or |idx2|. */
7153 PRE_REG_READ3(int, "kcmp",
7154 vki_pid_t, pid1, vki_pid_t, pid2, int, type);
7155 break;
7156 case VKI_KCMP_FILE:
7157 case VKI_KCMP_FILEOBJ:
7158 default:
7159 PRE_REG_READ5(int, "kcmp",
7160 vki_pid_t, pid1, vki_pid_t, pid2, int, type,
7161 unsigned long, idx1, unsigned long, idx2);
7162 break;
7167 #endif
7169 #undef PRE
7170 #undef POST
7172 const SyscallTableEntry ML_(syscall_table)[] = {
7173 // syscall (handled specially) // 0
7174 BSDX_(__NR_exit, sys_exit), // 1
7175 BSDX_(__NR_fork, sys_fork), // 2
7176 GENXY(__NR_read, sys_read), // 3
7178 GENX_(__NR_write, sys_write), // 4
7179 GENXY(__NR_open, sys_open), // 5
7180 GENX_(__NR_close, sys_close), // 6
7181 GENXY(__NR_wait4, sys_wait4), // 7
7183 // 4.3 creat 8
7184 GENX_(__NR_link, sys_link), // 9
7185 GENX_(__NR_unlink, sys_unlink), // 10
7186 // obsol execv 11
7188 GENX_(__NR_chdir, sys_chdir), // 12
7189 GENX_(__NR_fchdir, sys_fchdir), // 13
7190 GENX_(__NR_freebsd11_mknod, sys_mknod), // 14
7191 GENX_(__NR_chmod, sys_chmod), // 15
7193 GENX_(__NR_chown, sys_chown), // 16
7194 GENX_(__NR_break, sys_brk), // 17
7195 // freebsd 4 getfsstat 18
7196 // 4.3 lseek 19
7198 GENX_(__NR_getpid, sys_getpid), // 20
7199 BSDX_(__NR_mount, sys_mount), // 21
7200 BSDX_(__NR_unmount, sys_unmount), // 22
7201 GENX_(__NR_setuid, sys_setuid), // 23
7203 GENX_(__NR_getuid, sys_getuid), // 24
7204 GENX_(__NR_geteuid, sys_geteuid), // 25
7205 BSDXY(__NR_ptrace, sys_ptrace), // 26
7206 BSDXY(__NR_recvmsg, sys_recvmsg), // 27
7208 BSDX_(__NR_sendmsg, sys_sendmsg), // 28
7209 BSDXY(__NR_recvfrom, sys_recvfrom), // 29
7210 BSDXY(__NR_accept, sys_accept), // 30
7211 BSDXY(__NR_getpeername, sys_getpeername), // 31
7213 BSDXY(__NR_getsockname, sys_getsockname), // 32
7214 GENX_(__NR_access, sys_access), // 33
7215 BSDX_(__NR_chflags, sys_chflags), // 34
7216 BSDX_(__NR_fchflags, sys_fchflags), // 35
7218 GENX_(__NR_sync, sys_sync), // 36
7219 GENX_(__NR_kill, sys_kill), // 37
7220 // 4.3 stat 38
7221 GENX_(__NR_getppid, sys_getppid), // 39
7223 // 4.3 lstat 40
7224 GENXY(__NR_dup, sys_dup), // 41
7226 #if defined(VGP_arm64_freebsd)
7227 GENX_(__NR_freebsd10_pipe, sys_ni_syscall), // 42
7228 #else
7229 BSDXY(__NR_freebsd10_pipe, sys_pipe), // 42
7230 #endif
7231 GENX_(__NR_getegid, sys_getegid), // 43
7233 GENX_(__NR_profil, sys_ni_syscall), // 44
7234 GENX_(__NR_ktrace, sys_ni_syscall), // 45
7235 // 4.3 sigaction 46
7236 GENX_(__NR_getgid, sys_getgid), // 47
7238 // 4.3 sigaction (int sigset) 48
7239 BSDXY(__NR_getlogin, sys_getlogin), // 49
7240 BSDX_(__NR_setlogin, sys_setlogin), // 50
7241 GENX_(__NR_acct, sys_acct), // 51
7243 // 4.3 sigpending 52
7244 GENXY(__NR_sigaltstack, sys_sigaltstack), // 53
7245 BSDXY(__NR_ioctl, sys_ioctl), // 54
7246 BSDX_(__NR_reboot, sys_reboot), // 55
7248 BSDX_(__NR_revoke, sys_revoke), // 56
7249 GENX_(__NR_symlink, sys_symlink), // 57
7250 BSDX_(__NR_readlink, sys_readlink), // 58
7251 GENX_(__NR_execve, sys_execve), // 59
7253 GENX_(__NR_umask, sys_umask), // 60
7254 GENX_(__NR_chroot, sys_chroot), // 61
7255 // 4.3 fstat 62
7256 // 4.3 getgerninfo 63
7258 // 4.3 getpagesize 64
7259 GENX_(__NR_msync, sys_msync), // 65
7260 BSDX_(__NR_vfork, sys_vfork), // 66
7261 // obsol vread 67
7263 // obsol vwrite 68
7264 BSDX_(__NR_sbrk, sys_sbrk), // 69
7265 // not implemented in OS sstk 70
7266 // 4.3 mmap 71
7268 // freebsd11 vadvise 72
7269 GENXY(__NR_munmap, sys_munmap), // 73
7270 GENXY(__NR_mprotect, sys_mprotect), // 74
7271 GENX_(__NR_madvise, sys_madvise), // 75
7273 // obsol vhangup 76
7274 // obsol vlimit 77
7275 GENXY(__NR_mincore, sys_mincore), // 78
7276 GENXY(__NR_getgroups, sys_getgroups), // 79
7278 GENX_(__NR_setgroups, sys_setgroups), // 80
7279 GENX_(__NR_getpgrp, sys_getpgrp), // 81
7280 GENX_(__NR_setpgid, sys_setpgid), // 82
7281 GENXY(__NR_setitimer, sys_setitimer), // 83
7283 // 4.3 wait 84
7284 BSDX_(__NR_swapon, sys_swapon), // 85
7285 GENXY(__NR_getitimer, sys_getitimer), // 86
7286 // 4.3 gethostname 87
7288 // 4.3 sethostname 88
7289 BSDX_(__NR_getdtablesize, sys_getdtablesize), // 89
7290 GENXY(__NR_dup2, sys_dup2), // 90
7292 BSDXY(__NR_fcntl, sys_fcntl), // 92
7293 GENX_(__NR_select, sys_select), // 93
7294 GENX_(__NR_fsync, sys_fsync), // 95
7296 GENX_(__NR_setpriority, sys_setpriority), // 96
7297 BSDXY(__NR_socket, sys_socket), // 97
7298 BSDX_(__NR_connect, sys_connect), // 98
7299 // 4.3 accept 99
7301 GENX_(__NR_getpriority, sys_getpriority), // 100
7302 // 4.3 send 101
7303 // 4.3 recv 102
7304 // 4.3 sigreturn 103
7306 BSDX_(__NR_bind, sys_bind), // 104
7307 BSDX_(__NR_setsockopt, sys_setsockopt), // 105
7308 BSDX_(__NR_listen, sys_listen), // 106
7309 // obsol vtimes 107
7311 // 4.3 sigvec 108
7312 // 4.3 sigblock 109
7313 // 4.3 sigsetmask 110
7314 // 4.3 sigsuspend 111
7316 // 4.3 sigstack 112
7317 // 4.3 recvmsg 113
7318 // 4.3 sendmsg 114
7319 // 4.3 vtrace 115
7321 GENXY(__NR_gettimeofday, sys_gettimeofday), // 116
7322 GENXY(__NR_getrusage, sys_getrusage), // 117
7323 BSDXY(__NR_getsockopt, sys_getsockopt), // 118
7325 GENXY(__NR_readv, sys_readv), // 120
7326 GENX_(__NR_writev, sys_writev), // 121
7327 GENX_(__NR_settimeofday, sys_settimeofday), // 122
7328 GENX_(__NR_fchown, sys_fchown), // 123
7330 GENX_(__NR_fchmod, sys_fchmod), // 124
7331 // 4.3 recvfrom 125
7332 GENX_(__NR_setreuid, sys_setreuid), // 126
7333 GENX_(__NR_setregid, sys_setregid), // 127
7335 GENX_(__NR_rename, sys_rename), // 128
7336 // 4.3 truncate 129
7337 // 4.3 ftruncate 130
7338 GENX_(__NR_flock, sys_flock), // 131
7340 BSDX_(__NR_mkfifo, sys_mkfifo), // 132
7341 BSDX_(__NR_sendto, sys_sendto), // 133
7342 BSDX_(__NR_shutdown, sys_shutdown), // 134
7343 BSDXY(__NR_socketpair, sys_socketpair), // 135
7345 GENX_(__NR_mkdir, sys_mkdir), // 136
7346 GENX_(__NR_rmdir, sys_rmdir), // 137
7347 GENX_(__NR_utimes, sys_utimes), // 138
7348 // 4.2 sigreturn 139
7350 BSDXY(__NR_adjtime, sys_adjtime), // 140
7351 // 4.3 getpeername 141
7352 // 4.3 gethostid 142
7353 // 4.3 sethostid 143
7355 // 4.3 getrlimit` 144
7356 // 4.3 setrlimit 145
7357 // 4.3 killpg 146
7358 GENX_(__NR_setsid, sys_setsid), // 147
7360 BSDX_(__NR_quotactl, sys_quotactl), // 148
7361 // 4.3 quota 149
7362 // 4.3 getsockname 150
7363 // bsd/os sem_lock 151
7365 // bsd/os sem_wakeup 152
7366 // bsd/os asyncdaemon 153
7368 // no idea what the following syscall does
7369 // unimp SYS_nlm_syscall 154
7371 // a somewhat complicated NFS API
7372 // takes a flag and a void* that can point to one of
7373 // three different types of struct depending on the flag
7374 // unimp SYS_nfssvc 155
7376 // 4.3 getdirentries 156
7377 // freebsd 4 statfs 157
7378 // freebsd 4 fstatfs 158
7380 BSDXY(__NR_lgetfh, sys_lgetfh), // 160
7381 BSDXY(__NR_getfh, sys_getfh), // 161
7382 #if (FREEBSD_VERS <= FREEBSD_10)
7383 BSDXY(__NR_freebsd4_getdomainname, sys_freebsd4_getdomainname), // 162
7384 BSDX_(__NR_freebsd4_setdomainname, sys_freebsd4_setdomainname), // 163
7385 BSDXY(__NR_freebsd4_uname, sys_freebsd4_uname), // 164
7386 #endif
7387 BSDXY(__NR_sysarch, sys_sysarch), // 165
7388 BSDXY(__NR_rtprio, sys_rtprio), // 166
7390 // the following 3 seem only to be defines in a header
7391 // semsys 169
7392 // msgsys 170
7393 // shmsys 171
7395 #if (FREEBSD_VERS <= FREEBSD_10)
7396 BSDXY(__NR_freebsd6_pread, sys_freebsd6_pread), // 173
7397 BSDX_(__NR_freebsd6_pwrite, sys_freebsd6_pwrite), // 174
7398 #endif
7399 BSDX_(__NR_setfib, sys_setfib), // 175
7401 // @todo PJF this exists on Darwin and Solaris as well
7402 // and it isn't implememented on either
7403 // looking at the manpage there is a rather fearsome
7404 // timex struct with a mixture of ro and rw fields
7405 // BSDXY(__NR_ntp_adjtime, sys_ntp_adjtime), // 176
7407 // bsd/os sfork 177
7408 // bsd/os getdescriptor 178
7409 // bsd/os setdescriptor 179
7411 GENX_(__NR_setgid, sys_setgid), // 181
7412 BSDX_(__NR_setegid, sys_setegid), // 182
7413 BSDX_(__NR_seteuid, sys_seteuid), // 183
7415 // obs lfs_bmapv 184
7416 // obs lfs_markv 185
7417 // obs lfs_segclean 186
7418 // obs lfs_segwait 187
7420 #if (FREEBSD_VERS >= FREEBSD_12)
7421 BSDXY(__NR_freebsd11_stat, sys_freebsd11_stat), // 188
7422 BSDXY(__NR_freebsd11_fstat, sys_freebsd11_fstat), // 189
7423 BSDXY(__NR_freebsd11_lstat, sys_freebsd11_lstat), // 190
7424 #else
7425 BSDXY(__NR_stat, sys_stat), // 188
7426 BSDXY(__NR_fstat, sys_fstat), // 189
7427 BSDXY(__NR_lstat, sys_lstat), // 190
7428 #endif
7429 BSDX_(__NR_pathconf, sys_pathconf), // 191
7430 BSDX_(__NR_fpathconf, sys_fpathconf), // 192
7431 GENXY(__NR_getrlimit, sys_getrlimit), // 194
7432 GENX_(__NR_setrlimit, sys_setrlimit), // 195
7433 #if (FREEBSD_VERS >= FREEBSD_12)
7434 BSDXY(__NR_freebsd11_getdirentries, sys_freebsd11_getdirentries), // 196
7435 #else
7436 BSDXY(__NR_getdirentries, sys_getdirentries), // 196
7437 #endif
7438 #if (FREEBSD_VERS <= FREEBSD_10)
7439 BSDX_(__NR_freebsd6_mmap, sys_freebsd6_mmap), // 197
7440 #endif
7441 // __syscall (handled specially) // 198
7442 #if (FREEBSD_VERS <= FREEBSD_10)
7443 BSDX_(__NR_freebsd6_lseek, sys_freebsd6_lseek), // 199
7444 BSDX_(__NR_freebsd6_truncate, sys_freebsd6_truncate), // 200
7445 BSDX_(__NR_freebsd6_ftruncate, sys_freebsd6_ftruncate), // 201
7446 #endif
7447 BSDXY(__NR___sysctl, sys___sysctl), // 202
7448 GENX_(__NR_mlock, sys_mlock), // 203
7450 GENX_(__NR_munlock, sys_munlock), // 204
7451 BSDX_(__NR_undelete, sys_undelete), // 205
7452 BSDX_(__NR_futimes, sys_futimes), // 206
7453 GENX_(__NR_getpgid, sys_getpgid), // 207
7455 // netbsd newreboot 208
7456 GENXY(__NR_poll, sys_poll), // 209
7458 BSDXY(__NR_freebsd7___semctl, sys_freebsd7___semctl), // 220
7459 BSDX_(__NR_semget, sys_semget), // 221
7460 BSDX_(__NR_semop, sys_semop), // 222
7461 // obs semconfig 223
7463 BSDXY(__NR_freebsd7_msgctl, sys_freebsd7_msgctl), // 224
7464 BSDX_(__NR_msgget, sys_msgget), // 225
7465 BSDX_(__NR_msgsnd, sys_msgsnd), // 226
7466 BSDXY(__NR_msgrcv, sys_msgrcv), // 227
7468 BSDXY(__NR_shmat, sys_shmat), // 228
7469 BSDXY(__NR_freebsd7_shmctl, sys_freebsd7_shmctl), // 229
7470 BSDXY(__NR_shmdt, sys_shmdt), // 230
7471 BSDX_(__NR_shmget, sys_shmget), // 231
7473 BSDXY(__NR_clock_gettime, sys_clock_gettime), // 232
7474 BSDX_(__NR_clock_settime, sys_clock_settime), // 233
7475 BSDXY(__NR_clock_getres, sys_clock_getres), // 234
7476 BSDXY(__NR_ktimer_create, sys_timer_create), // 235
7477 BSDX_(__NR_ktimer_delete, sys_timer_delete), // 236
7478 BSDXY(__NR_ktimer_settime, sys_timer_settime), // 237
7479 BSDXY(__NR_ktimer_gettime, sys_timer_gettime), // 238
7480 BSDX_(__NR_ktimer_getoverrun, sys_timer_getoverrun), // 239
7482 GENXY(__NR_nanosleep, sys_nanosleep), // 240
7483 // unimpl SYS_ffclock_getcounter 241
7484 // unimpl SYS_ffclock_setestimate 242
7485 // unimpl SYS_ffclock_getestimate 243
7487 BSDXY(__NR_clock_nanosleep, sys_clock_nanosleep), // 244
7488 BSDXY(__NR_clock_getcpuclockid2, sys_clock_getcpuclockid2), // 247
7490 // unimpl SYS_ntp_gettime 248
7491 BSDXY(__NR_minherit, sys_minherit), // 250
7492 BSDX_(__NR_rfork, sys_rfork), // 251
7494 // openbsd_poll // 252
7495 BSDX_(__NR_issetugid, sys_issetugid), // 253
7496 GENX_(__NR_lchown, sys_lchown), // 254
7497 BSDXY(__NR_aio_read, sys_aio_read), // 255
7498 BSDX_(__NR_aio_write, sys_aio_write), // 256
7499 BSDX_(__NR_lio_listio, sys_lio_listio), // 257
7501 GENXY(__NR_freebsd11_getdents, sys_getdents), // 272
7502 BSDX_(__NR_lchmod, sys_lchmod), // 274
7503 // netbsd_lchown // 275
7505 BSDX_(__NR_lutimes, sys_lutimes), // 276
7506 // netbsd msync 277
7507 // unimpl SYS_freebsd11_nstat 278
7508 // unimpl SYS_freebsd11_nfstat 279
7510 // unimpl SYS_freebsd11_nlstat 280
7512 BSDXY(__NR_preadv, sys_preadv), // 289
7513 BSDX_(__NR_pwritev, sys_pwritev), // 290
7515 // freebsd 4 fhstatfs 297
7516 BSDXY(__NR_fhopen, sys_fhopen), // 298
7517 #if (FREEBSD_VERS >= FREEBSD_12)
7518 BSDXY(__NR_freebsd11_fhstat, sys_freebsd11_fhstat), // 299
7519 #else
7520 BSDXY(__NR_fhstat, sys_fhstat), // 299
7521 #endif
7523 BSDX_(__NR_modnext, sys_modnext), // 300
7524 BSDXY(__NR_modstat, sys_modstat), // 301
7525 BSDX_(__NR_modfnext, sys_modfnext), // 302
7526 BSDX_(__NR_modfind, sys_modfind), // 303
7528 BSDX_(__NR_kldload, sys_kldload), // 304
7529 BSDX_(__NR_kldunload, sys_kldunload), // 305
7530 BSDX_(__NR_kldfind, sys_kldfind), // 306
7531 BSDX_(__NR_kldnext, sys_kldnext), // 307
7533 BSDXY(__NR_kldstat, sys_kldstat), // 308
7534 BSDX_(__NR_kldfirstmod, sys_kldfirstmod), // 309
7535 GENX_(__NR_getsid, sys_getsid), // 310
7536 BSDX_(__NR_setresuid, sys_setresuid), // 311
7538 BSDX_(__NR_setresgid, sys_setresgid), // 312
7539 // obsol signanosleep 313
7540 BSDX_(__NR_aio_return, sys_aio_return), // 314
7541 BSDX_(__NR_aio_suspend, sys_aio_suspend), // 315
7543 BSDX_(__NR_aio_cancel, sys_aio_cancel), // 316
7544 BSDX_(__NR_aio_error, sys_aio_error), // 317
7545 // freebsd 6 aio_read 318
7546 // freebsd 6 aio_write 319
7547 // freebsd 6 lio_listio 320
7548 BSDX_(__NR_yield, sys_yield), // 321
7549 // obs thr_sleep 322
7550 // obs thr_wakeup 323
7552 GENX_(__NR_mlockall, sys_mlockall), // 324
7553 BSDX_(__NR_munlockall, sys_munlockall), // 325
7554 BSDXY(__NR___getcwd, sys___getcwd), // 326
7555 BSDX_(__NR_sched_setparam, sys_sched_setparam), // 327
7556 BSDXY(__NR_sched_getparam, sys_sched_getparam), // 328
7557 BSDX_(__NR_sched_setscheduler, sys_sched_setscheduler), // 329
7558 BSDX_(__NR_sched_getscheduler, sys_sched_getscheduler), // 330
7559 BSDX_(__NR_sched_yield, sys_sched_yield), // 331
7561 BSDX_(__NR_sched_get_priority_max, sys_sched_get_priority_max), // 332
7562 BSDX_(__NR_sched_get_priority_min, sys_sched_get_priority_min), // 333
7563 BSDXY(__NR_sched_rr_get_interval, sys_sched_rr_get_interval), // 334
7564 BSDX_(__NR_utrace, sys_utrace), // 335
7566 // freebsd 4 sendfile 336
7567 BSDXY(__NR_kldsym, sys_kldsym), // 337
7568 BSDX_(__NR_jail, sys_jail), // 338
7569 // unimpl SYS_nnpfs_syscall 339
7571 BSDXY(__NR_sigprocmask, sys_sigprocmask), // 340
7572 BSDXY(__NR_sigsuspend, sys_sigsuspend), // 341
7573 // freebsd 4 sigaction 342
7574 BSDXY(__NR_sigpending, sys_sigpending), // 343
7576 // freebsd 4 sigreturn 344
7577 BSDXY(__NR_sigtimedwait, sys_sigtimedwait), // 345
7578 BSDXY(__NR_sigwaitinfo, sys_sigwaitinfo), // 346
7579 BSDXY(__NR___acl_get_file, sys___acl_get_file), // 347
7581 BSDX_(__NR___acl_set_file, sys___acl_set_file), // 348
7582 BSDXY(__NR___acl_get_fd, sys___acl_get_fd), // 349
7583 BSDX_(__NR___acl_set_fd, sys___acl_set_fd), // 350
7584 BSDX_(__NR___acl_delete_file, sys___acl_delete_file), // 351
7586 BSDX_(__NR___acl_delete_fd, sys___acl_delete_fd), // 352
7587 BSDX_(__NR___acl_aclcheck_file, sys___acl_aclcheck_file), // 353
7588 BSDX_(__NR___acl_aclcheck_fd, sys___acl_aclcheck_fd), // 354
7589 BSDX_(__NR_extattrctl, sys_extattrctl), // 355
7590 BSDX_(__NR_extattr_set_file, sys_extattr_set_file), // 356
7591 BSDXY(__NR_extattr_get_file, sys_extattr_get_file), // 357
7592 BSDX_(__NR_extattr_delete_file, sys_extattr_delete_file), // 358
7593 BSDXY(__NR_aio_waitcomplete, sys_aio_waitcomplete), // 359
7595 BSDXY(__NR_getresuid, sys_getresuid), // 360
7596 BSDXY(__NR_getresgid, sys_getresgid), // 361
7597 BSDXY(__NR_kqueue, sys_kqueue), // 362
7598 #if (FREEBSD_VERS >= FREEBSD_12)
7599 BSDXY(__NR_freebsd11_kevent, sys_freebsd11_kevent), // 363
7600 #else
7601 BSDXY(__NR_kevent, sys_kevent), // 363
7602 #endif
7603 // obs __cap_get_proc 364
7604 // obs __cap_set_proc 365
7605 // obs __cap_get_fd 366
7606 // obs __cap_get_file 367
7607 // obs __cap_set_fd 368
7608 // obs __cap_set_file 369
7610 BSDX_(__NR_extattr_set_fd, sys_extattr_set_fd), // 371
7611 BSDXY(__NR_extattr_get_fd, sys_extattr_get_fd), // 372
7612 BSDX_(__NR_extattr_delete_fd, sys_extattr_delete_fd), // 373
7613 BSDX_(__NR___setugid, sys___setugid), // 374
7614 // obs nfsclnt 375
7616 BSDX_(__NR_eaccess, sys_eaccess), // 376
7617 // unimpl afs3_syscall 377
7618 BSDX_(__NR_nmount, sys_nmount), // 378
7619 // obs kse_exit 379
7620 // obs kse_wakeup 380
7621 // obs kse_create 381
7622 // obs kse_thr_interrupt 382
7623 // obs kse_release 383
7625 // unimpl __mac_get_proc 384
7626 // unimpl __mac_set_proc 385
7627 // unimpl __mac_get_fd 386
7628 // unimpl __mac_get_file 387
7629 // unimpl __mac_set_fd 388
7630 // unimpl __mac_set_file 389
7631 BSDXY(__NR_kenv, sys_kenv), // 390
7632 BSDX_(__NR_lchflags, sys_lchflags), // 391
7634 BSDXY(__NR_uuidgen, sys_uuidgen), // 392
7635 BSDXY(__NR_sendfile, sys_sendfile), // 393
7636 // unimpl mac_syscall 394
7638 #if (FREEBSD_VERS >= FREEBSD_12)
7639 BSDXY(__NR_freebsd11_getfsstat, sys_freebsd11_getfsstat), // 395
7640 BSDXY(__NR_freebsd11_statfs, sys_statfs), // 396
7641 BSDXY(__NR_freebsd11_fstatfs, sys_fstatfs), // 397
7642 BSDXY(__NR_freebsd11_fhstatfs, sys_fhstatfs), // 398
7643 #else
7644 BSDXY(__NR_getfsstat, sys_getfsstat), // 395
7645 BSDXY(__NR_statfs, sys_statfs), // 396
7646 BSDXY(__NR_fstatfs, sys_fstatfs), // 397
7647 BSDXY(__NR_fhstatfs, sys_fhstatfs), // 398
7648 #endif
7650 // unimpl ksem_close 400
7651 // unimpl ksem_post 401
7652 // unimpl ksem_wait 402
7653 // unimpl ksem_trywait 403
7655 // unimpl ksem_init 404
7656 // unimpl ksem_open 405
7657 // unimpl ksem_unlink 406
7658 // unimpl ksem_getvalue 407
7660 // unimpl ksem_destroy 408
7661 // unimpl __mac_get_pid 409
7662 // unimpl __mac_get_link 410
7663 // unimpl __mac_set_link 411
7665 BSDX_(__NR_extattr_set_link, sys_extattr_set_link), // 412
7666 BSDXY(__NR_extattr_get_link, sys_extattr_get_link), // 413
7667 BSDX_(__NR_extattr_delete_link, sys_extattr_delete_link), // 414
7668 // unimpl __mac_execve 415
7670 BSDXY(__NR_sigaction, sys_sigaction), // 416
7671 BSDX_(__NR_sigreturn, sys_sigreturn), // 417
7673 BSDXY(__NR_getcontext, sys_getcontext), // 421
7674 BSDX_(__NR_setcontext, sys_setcontext), // 422
7675 BSDXY(__NR_swapcontext, sys_swapcontext), // 423
7677 #if (FREEBSD_VERS >= FREEBSD_13_1)
7678 BSDX_(__NR_freebsd13_swapoff, sys_freebsd13_swapoff), // 424
7679 #else
7680 BSDX_(__NR_swapoff, sys_swapoff), // 424
7681 #endif
7682 BSDXY(__NR___acl_get_link, sys___acl_get_link), // 425
7683 BSDX_(__NR___acl_set_link, sys___acl_set_link), // 426
7684 BSDX_(__NR___acl_delete_link, sys___acl_delete_link), // 427
7686 BSDX_(__NR___acl_aclcheck_link, sys___acl_aclcheck_link), // 428
7687 BSDXY(__NR_sigwait, sys_sigwait), // 429
7688 BSDX_(__NR_thr_create, sys_thr_create), // 430
7689 BSDX_(__NR_thr_exit, sys_thr_exit), // 431
7691 BSDXY(__NR_thr_self, sys_thr_self), // 432
7692 BSDXY(__NR_thr_kill, sys_thr_kill), // 433
7693 #if (FREEBSD_VERS <= FREEBSD_10)
7694 BSDXY(__NR__umtx_lock, sys__umtx_lock), // 434
7695 BSDXY(__NR__umtx_unlock, sys__umtx_unlock), // 435
7696 #endif
7698 BSDX_(__NR_jail_attach, sys_jail_attach), // 436
7699 BSDXY(__NR_extattr_list_fd, sys_extattr_list_fd), // 437
7700 BSDXY(__NR_extattr_list_file, sys_extattr_list_file), // 438
7701 BSDXY(__NR_extattr_list_link, sys_extattr_list_link), // 439
7703 // obs kse_switchin 440
7704 // unimpl ksem_timedwait 441
7705 BSDX_(__NR_thr_suspend, sys_thr_suspend), // 442
7706 BSDX_(__NR_thr_wake, sys_thr_wake), // 443
7707 BSDX_(__NR_kldunloadf, sys_kldunloadf), // 444
7708 // unimpl audit 445
7709 // unimpl auditon 446
7710 // unimpl getauid 447
7712 // unimpl setauid 448
7713 // unimpl getaudit 449
7714 // unimpl setaudit 450
7715 // unimpl getaudit_addr 451
7716 // unimpl setaudit_addr 452
7717 // unimpl auditctl 453
7718 BSDXY(__NR__umtx_op, sys__umtx_op), // 454
7719 BSDX_(__NR_thr_new, sys_thr_new), // 455
7721 BSDX_(__NR_sigqueue, sys_sigqueue), // 456
7722 BSDXY(__NR_kmq_open, sys_kmq_open), // 457
7723 BSDX_(__NR_kmq_setattr, sys_kmq_setattr), // 458
7724 BSDXY(__NR_kmq_timedreceive, sys_kmq_timedreceive), // 459
7726 BSDX_(__NR_kmq_timedsend, sys_kmq_timedsend), // 460
7727 BSDX_(__NR_kmq_notify, sys_kmq_notify), // 461
7728 BSDX_(__NR_kmq_unlink, sys_kmq_unlink), // 462
7729 BSDX_(__NR_abort2, sys_abort2), // 463
7731 BSDX_(__NR_thr_set_name, sys_thr_set_name), // 464
7732 BSDX_(__NR_aio_fsync, sys_aio_fsync), // 465
7733 BSDXY(__NR_rtprio_thread, sys_rtprio_thread), // 466
7735 // unimpl sctp_peeloff 471
7736 BSDX_(__NR_sctp_generic_sendmsg, sys_sctp_generic_sendmsg), // 472
7737 // unimpl sctp_generic_sendmsg_iov 473
7738 BSDXY(__NR_sctp_generic_recvmsg, sys_sctp_generic_recvmsg), // 474
7739 BSDXY(__NR_pread, sys_pread), // 475
7741 BSDX_(__NR_pwrite, sys_pwrite), // 476
7742 BSDX_(__NR_mmap, sys_mmap), // 477
7743 BSDX_(__NR_lseek, sys_lseek), // 478
7744 BSDX_(__NR_truncate, sys_truncate), // 479
7745 BSDX_(__NR_ftruncate, sys_ftruncate), // 480
7746 BSDXY(__NR_thr_kill2, sys_thr_kill2), // 481
7747 BSDXY(__NR_shm_open, sys_shm_open), // 482
7748 BSDX_(__NR_shm_unlink, sys_shm_unlink), // 483
7750 BSDXY(__NR_cpuset, sys_cpuset), // 484
7751 BSDX_(__NR_cpuset_setid, sys_cpuset_setid), // 485
7752 BSDXY(__NR_cpuset_getid, sys_cpuset_getid), // 486
7754 BSDXY(__NR_cpuset_getaffinity, sys_cpuset_getaffinity), // 487
7755 BSDX_(__NR_cpuset_setaffinity, sys_cpuset_setaffinity), // 488
7756 BSDX_(__NR_faccessat, sys_faccessat), // 489
7757 BSDX_(__NR_fchmodat, sys_fchmodat), // 490
7758 BSDX_(__NR_fchownat, sys_fchownat), // 491
7760 BSDX_(__NR_fexecve, sys_fexecve), // 492
7761 #if (FREEBSD_VERS >= FREEBSD_12)
7762 BSDXY(__NR_freebsd11_fstatat, sys_freebsd11_fstatat), // 493
7763 #else
7764 BSDXY(__NR_fstatat, sys_fstatat), // 493
7765 #endif
7766 BSDX_(__NR_futimesat, sys_futimesat), // 494
7767 BSDX_(__NR_linkat, sys_linkat), // 495
7769 BSDX_(__NR_mkdirat, sys_mkdirat), // 496
7770 BSDX_(__NR_mkfifoat, sys_mkfifoat), // 497
7772 #if (FREEBSD_VERS >= FREEBSD_12)
7773 BSDX_(__NR_freebsd11_mknodat, sys_freebsd11_mknodat), // 498
7774 #else
7775 BSDX_(__NR_mknodat, sys_mknodat), // 498
7776 #endif
7778 BSDXY(__NR_openat, sys_openat), // 499
7780 BSDXY(__NR_readlinkat, sys_readlinkat), // 500
7781 BSDX_(__NR_renameat, sys_renameat), // 501
7782 BSDX_(__NR_symlinkat, sys_symlinkat), // 502
7783 BSDX_(__NR_unlinkat, sys_unlinkat), // 503
7785 BSDX_(__NR_posix_openpt, sys_posix_openpt), // 504
7786 // unimp gssd_syscall 505
7787 BSDX_(__NR_jail_get, sys_jail_get), // 506
7788 BSDX_(__NR_jail_set, sys_jail_set), // 507
7789 BSDX_(__NR_jail_remove, sys_jail_remove), // 508
7790 BSDXY(__NR_closefrom, sys_closefrom), // 509
7791 BSDXY(__NR___semctl, sys___semctl), // 510
7792 BSDXY(__NR_msgctl, sys_msgctl), // 511
7793 BSDXY(__NR_shmctl, sys_shmctl), // 512
7794 BSDX_(__NR_lpathconf, sys_lpathconf), // 513
7795 /* 514 is obsolete cap_new */
7796 BSDXY(__NR___cap_rights_get, sys_cap_rights_get), // 515
7797 BSDX_(__NR_cap_enter, sys_cap_enter), // 516
7798 BSDXY(__NR_cap_getmode, sys_cap_getmode), // 517
7799 BSDXY(__NR_pdfork, sys_pdfork), // 518
7800 BSDX_(__NR_pdkill, sys_pdkill), // 519
7801 BSDXY(__NR_pdgetpid, sys_pdgetpid), // 520
7802 BSDXY(__NR_pselect, sys_pselect), // 522
7803 BSDXY(__NR_getloginclass, sys_getloginclass), // 523
7804 BSDX_(__NR_setloginclass, sys_setloginclass), // 524
7805 BSDXY(__NR_rctl_get_racct, sys_rctl_get_racct), // 525
7806 BSDXY(__NR_rctl_get_rules, sys_rctl_get_rules), // 526
7807 BSDXY(__NR_rctl_get_limits, sys_rctl_get_limits), // 527
7808 BSDXY(__NR_rctl_add_rule, sys_rctl_add_rule), // 528
7809 BSDXY(__NR_rctl_remove_rule, sys_rctl_remove_rule), // 529
7810 BSDX_(__NR_posix_fallocate, sys_posix_fallocate), // 530
7811 BSDX_(__NR_posix_fadvise, sys_posix_fadvise), // 531
7812 BSDXY(__NR_wait6, sys_wait6), // 532
7813 BSDX_(__NR_cap_rights_limit, sys_cap_rights_limit), // 533
7814 BSDX_(__NR_cap_ioctls_limit, sys_cap_ioctls_limit), // 534
7815 BSDXY(__NR_cap_ioctls_get, sys_cap_ioctls_get), // 535
7816 BSDX_(__NR_cap_fcntls_limit, sys_cap_fcntls_limit), // 536
7817 BSDXY(__NR_cap_fcntls_get, sys_cap_fcntls_get), // 537
7818 BSDX_(__NR_bindat, sys_bindat), // 538
7819 BSDX_(__NR_connectat, sys_connectat), // 539
7820 BSDX_(__NR_chflagsat, sys_chflagsat), // 540
7821 BSDXY(__NR_accept4, sys_accept4), // 541
7822 BSDXY(__NR_pipe2, sys_pipe2), // 542
7823 BSDX_(__NR_aio_mlock, sys_aio_mlock), // 543
7824 BSDXY(__NR_procctl, sys_procctl), // 544
7826 // 544 is the highest syscall on FreeBSD 9
7828 #if (FREEBSD_VERS >= FREEBSD_10)
7830 BSDXY(__NR_ppoll, sys_ppoll), // 545
7831 BSDX_(__NR_futimens, sys_futimens), // 546
7832 BSDX_(__NR_utimensat, sys_utimensat), // 547
7834 #endif // FREEBSD_VERS >= FREEBSD_10
7836 #if (FREEBSD_VERS >= FREEBSD_11)
7838 /* 548 is obsolete numa_getaffinity */
7839 /* 549 is obsolete numa_setaffinity */
7840 BSDX_(__NR_fdatasync, sys_fdatasync), // 550
7842 #endif // FREEBSD_VERS >= FREEBSD_11
7844 #if (FREEBSD_VERS >= FREEBSD_12)
7845 BSDXY(__NR_fstat, sys_fstat), // 551
7846 BSDXY(__NR_fstatat, sys_fstatat), // 552
7847 BSDXY(__NR_fhstat, sys_fhstat), // 553
7848 BSDXY(__NR_getdirentries, sys_getdirentries), // 554
7849 BSDXY(__NR_statfs, sys_statfs), // 555
7850 BSDXY(__NR_fstatfs, sys_fstatfs), // 556
7851 BSDXY(__NR_getfsstat, sys_getfsstat), // 557
7852 BSDXY(__NR_fhstatfs, sys_fhstatfs), // 558
7853 BSDX_(__NR_mknodat, sys_mknodat), // 559
7854 BSDXY(__NR_kevent, sys_kevent), // 560
7855 BSDXY(__NR_cpuset_getdomain, sys_cpuset_getdomain), // 561
7856 BSDX_(__NR_cpuset_setdomain, sys_cpuset_setdomain), // 562
7857 BSDXY(__NR_getrandom, sys_getrandom), // 563
7858 BSDXY(__NR_getfhat, sys_getfhat), // 564
7859 BSDX_(__NR_fhlink, sys_fhlink), // 565
7860 BSDX_(__NR_fhlinkat, sys_fhlinkat), // 566
7861 BSDXY(__NR_fhreadlink, sys_fhreadlink), // 567
7862 #endif // FREEBSD_VERS >= FREEBSD_12
7864 #if (FREEBSD_VERS >= FREEBSD_12_2)
7865 BSDX_(__NR_funlinkat, sys_funlinkat), // 568
7866 BSDX_(__NR_copy_file_range, sys_copy_file_range), // 569
7867 BSDXY(__NR___sysctlbyname, sys___sysctlbyname), // 570
7869 #if (FREEBSD_VERS >= FREEBSD_13_0)
7870 BSDXY(__NR_shm_open2, sys_shm_open2), // 571
7871 // unimpl __NR_shm_rename 572
7872 BSDX_(__NR_sigfastblock, sys_sigfastblock), // 573
7873 BSDXY( __NR___realpathat, sys___realpathat), // 574
7874 #endif
7875 BSDXY(__NR_close_range, sys_close_range), // 575
7876 #endif
7878 #if (FREEBSD_VERS >= FREEBSD_13_0)
7879 // unimpl __NR_rpctls_syscall 576
7880 BSDX_(__NR___specialfd, sys___specialfd), // 577
7881 BSDX_(__NR_aio_writev, sys_aio_writev), // 578
7882 BSDXY(__NR_aio_readv, sys_aio_readv), // 579
7883 #endif
7885 #if (FREEBSD_VERS >= FREEBSD_13_1)
7887 #if (FREEBSD_VERS >= FREEBSD_14)
7888 BSDXY(__NR_fspacectl, sys_fspacectl), // 580
7889 #endif
7890 // unimpl __NR_sched_getcpu 581
7891 BSDX_(__NR_swapoff, sys_swapoff), // 582
7892 #endif
7894 #if (FREEBSD_VERS >= FREEBSD_15) || (FREEBSD_VERS >= FREEBSD_13_3)
7895 BSDXY(__NR_kqueuex, sys_kqueuex), // 583
7896 BSDX_(__NR_membarrier, sys_membarrier), // 584
7897 #endif
7898 #if (FREEBSD_VERS >= FREEBSD_15)
7899 BSDXY(__NR_timerfd_create, sys_timerfd_create), // 585
7900 BSDXY(__NR_timerfd_settime, sys_timerfd_settime), // 586
7901 BSDXY(__NR_timerfd_gettime, sys_timerfd_gettime), // 587
7902 BSDX_(__NR_kcmp, sys_kcmp), // 588
7903 #endif
7906 BSDX_(__NR_fake_sigreturn, sys_fake_sigreturn), // 1000, fake sigreturn
7910 const SyscallTableEntry* ML_(get_freebsd_syscall_entry) ( UInt sysno )
7912 const UInt syscall_table_size
7913 = sizeof(ML_(syscall_table)) / sizeof(ML_(syscall_table)[0]);
7915 /* Is it in the contiguous initial section of the table? */
7916 if (sysno < syscall_table_size) {
7917 const SyscallTableEntry* sys = &ML_(syscall_table)[sysno];
7918 if (sys->before == NULL) {
7919 return NULL; /* no entry */
7921 return sys;
7924 /* Can't find a wrapper */
7925 return NULL;
7928 /*--------------------------------------------------------------------*/
7929 /*--- end ---*/
7930 /*--------------------------------------------------------------------*/
7932 #endif // defined(VGO_freebsd)