FreeBSD: complete loading debuginfo if entering capability mode
[valgrind.git] / coregrind / m_syswrap / syswrap-freebsd.c
bloba59872b3c942c8cc56f3e452e84d0cbe98e9343e
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 #if defined(ENABLE_INNER_CLIENT_REQUEST)
60 #include "pub_core_clreq.h"
61 #endif
63 #include "priv_types_n_macros.h"
64 #include "priv_syswrap-generic.h"
65 #include "priv_syswrap-main.h"
66 #include "priv_syswrap-freebsd.h"
68 static Bool capabiltyMode = False;
70 Bool VG_(get_capability_mode)(void)
72 return capabiltyMode;
76 // Run a thread from beginning to end and return the thread's
77 // scheduler-return-code.
78 static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW)
80 VgSchedReturnCode ret;
81 ThreadId tid = (ThreadId)tidW;
82 Int lwpid = VG_(gettid)();
83 ThreadState* tst = VG_(get_ThreadState)(tid);
85 VG_(debugLog)(1, "syswrap-freebsd",
86 "thread_wrapper(tid=%u,lwpid=%d): entry\n",
87 tid, lwpid);
89 vg_assert(tst->status == VgTs_Init);
91 /* make sure we get the CPU lock before doing anything significant */
92 VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)");
94 if (0) {
95 VG_(printf)("thread tid %u started: stack = %p\n",
96 tid, (void*)&tid);
99 /* Make sure error reporting is enabled in the new thread. */
100 tst->err_disablement_level = 0;
102 VG_TRACK(pre_thread_first_insn, tid);
104 tst->os_state.lwpid = lwpid;
105 /* Set the threadgroup for real. This overwrites the provisional value set
106 in do_clone(). See comments in do_clone for background, also #226116. */
107 tst->os_state.threadgroup = VG_(getpid)();
109 /* Thread created with all signals blocked; scheduler will set the
110 appropriate mask */
112 ret = VG_(scheduler)(tid);
114 vg_assert(VG_(is_exiting)(tid));
116 vg_assert(tst->status == VgTs_Runnable);
117 vg_assert(VG_(is_running_thread)(tid));
119 VG_(debugLog)(1, "syswrap-freebsd",
120 "thread_wrapper(tid=%u,lwpid=%d): exit, schedreturncode %s\n",
121 tid, lwpid, VG_(name_of_VgSchedReturnCode)(ret));
123 /* Return to caller, still holding the lock. */
124 return ret;
128 /* ---------------------------------------------------------------------
129 clone-related stuff
130 ------------------------------------------------------------------ */
132 /* Run a thread all the way to the end, then do appropriate exit actions
133 (this is the last-one-out-turn-off-the-lights bit). */
134 __attribute__((noreturn))
135 static void run_a_thread_NORETURN ( Word tidW )
137 ThreadId tid = (ThreadId)tidW;
138 VgSchedReturnCode src;
139 Int c;
140 ThreadState* tst;
141 #ifdef ENABLE_INNER_CLIENT_REQUEST
142 Int registered_vgstack_id;
143 #endif
145 VG_(debugLog)(1, "syswrap-freebsd",
146 "run_a_thread_NORETURN(tid=%u): pre-thread_wrapper\n",
147 tid);
149 tst = VG_(get_ThreadState)(tid);
150 vg_assert(tst);
152 /* An thread has two stacks:
153 * the simulated stack (used by the synthetic cpu. Guest process
154 is using this stack).
155 * the valgrind stack (used by the real cpu. Valgrind code is running
156 on this stack).
157 When Valgrind runs as an inner, it must signals that its (real) stack
158 is the stack to use by the outer to e.g. do stacktraces.
160 INNER_REQUEST
161 (registered_vgstack_id
162 = VALGRIND_STACK_REGISTER (tst->os_state.valgrind_stack_base,
163 tst->os_state.valgrind_stack_init_SP));
165 /* Run the thread all the way through. */
166 src = thread_wrapper(tid);
168 VG_(debugLog)(1, "syswrap-freebsd",
169 "run_a_thread_NORETURN(tid=%u): post-thread_wrapper\n",
170 tid);
172 c = VG_(count_living_threads)();
173 vg_assert(c >= 1); /* stay sane */
175 /* Deregister thread's stack. */
176 if (tst->os_state.stk_id != NULL_STK_ID) {
177 VG_(deregister_stack)(tst->os_state.stk_id);
180 // Tell the tool this thread is exiting
181 VG_TRACK( pre_thread_ll_exit, tid );
183 /* If the thread is exiting with errors disabled, complain loudly;
184 doing so is bad (does the user know this has happened?) Also,
185 in all cases, be paranoid and clear the flag anyway so that the
186 thread slot is safe in this respect if later reallocated. This
187 should be unnecessary since the flag should be cleared when the
188 slot is reallocated, in thread_wrapper(). */
189 if (tst->err_disablement_level > 0) {
190 VG_(umsg)(
191 "WARNING: exiting thread has error reporting disabled.\n"
192 "WARNING: possibly as a result of some mistake in the use\n"
193 "WARNING: of the VALGRIND_DISABLE_ERROR_REPORTING macros.\n"
195 VG_(debugLog)(
196 1, "syswrap-freebsd",
197 "run_a_thread_NORETURN(tid=%u): "
198 "WARNING: exiting thread has err_disablement_level = %u\n",
199 tid, tst->err_disablement_level
202 tst->err_disablement_level = 0;
204 if (c == 1) {
206 VG_(debugLog)(1, "syswrap-freebsd",
207 "run_a_thread_NORETURN(tid=%u): "
208 "last one standing\n",
209 tid);
211 /* We are the last one standing. Keep hold of the lock and
212 carry on to show final tool results, then exit the entire system.
213 Use the continuation pointer set at startup in m_main. */
214 ( * VG_(address_of_m_main_shutdown_actions_NORETURN) ) (tid, src);
215 } else {
217 VG_(debugLog)(1, "syswrap-freebsd",
218 "run_a_thread_NORETURN(tid=%u): "
219 "not last one standing\n",
220 tid);
222 /* OK, thread is dead, but others still exist. Just exit. */
224 /* This releases the run lock */
225 VG_(exit_thread)(tid);
226 vg_assert(tst->status == VgTs_Zombie);
227 vg_assert(sizeof(tst->status) == 4);
228 vg_assert(sizeof(tst->os_state.exitcode) == sizeof(Word));
230 INNER_REQUEST (VALGRIND_STACK_DEREGISTER (registered_vgstack_id));
232 /* We have to use this sequence to terminate the thread to
233 prevent a subtle race. If VG_(exit_thread)() had left the
234 ThreadState as Empty, then it could have been reallocated,
235 reusing the stack while we're doing these last cleanups.
236 Instead, VG_(exit_thread) leaves it as Zombie to prevent
237 reallocation. We need to make sure we don't touch the stack
238 between marking it Empty and exiting. Hence the
239 assembler. */
240 #if defined(VGP_x86_freebsd) /* FreeBSD has args on the stack */
241 __asm__ volatile (
242 "movl %1, %0\n" /* set tst->status = VgTs_Empty */
243 "movl %2, %%eax\n" /* set %eax = __NR_thr_exit */
244 "movl %3, %%ebx\n" /* set %ebx = tst->os_state.exitcode */
245 "pushl %%ebx\n" /* arg on stack */
246 "pushl %%ebx\n" /* fake return address */
247 "int $0x80\n" /* thr_exit(tst->os_state.exitcode) */
248 "popl %%ebx\n" /* fake return address */
249 "popl %%ebx\n" /* arg off stack */
250 : "=m" (tst->status)
251 : "n" (VgTs_Empty), "n" (__NR_thr_exit), "m" (tst->os_state.exitcode)
252 : "eax", "ebx"
254 #elif defined(VGP_amd64_freebsd)
255 __asm__ volatile (
256 "movl %1, %0\n" /* set tst->status = VgTs_Empty */
257 "movq %2, %%rax\n" /* set %rax = __NR_thr_exit */
258 "movq %3, %%rdi\n" /* set %rdi = tst->os_state.exitcode */
259 "pushq %%rdi\n" /* fake return address */
260 "syscall\n" /* thr_exit(tst->os_state.exitcode) */
261 "popq %%rdi\n" /* fake return address */
262 : "=m" (tst->status)
263 : "n" (VgTs_Empty), "n" (__NR_thr_exit), "m" (tst->os_state.exitcode)
264 : "rax", "rdi"
266 #else
267 # error Unknown platform
268 #endif
270 VG_(core_panic)("Thread exit failed?\n");
273 /*NOTREACHED*/
274 vg_assert(0);
277 Word ML_(start_thread_NORETURN) ( void* arg )
279 ThreadState* tst = (ThreadState*)arg;
280 ThreadId tid = tst->tid;
282 run_a_thread_NORETURN ( (Word)tid );
283 /*NOTREACHED*/
284 vg_assert(0);
287 /* Allocate a stack for this thread, if it doesn't already have one.
288 They're allocated lazily, and never freed. Returns the initial stack
289 pointer value to use, or 0 if allocation failed. */
290 Addr ML_(allocstack)(ThreadId tid)
292 ThreadState* tst = VG_(get_ThreadState)(tid);
293 VgStack* stack;
294 Addr initial_SP;
296 /* Either the stack_base and stack_init_SP are both zero (in which
297 case a stack hasn't been allocated) or they are both non-zero,
298 in which case it has. */
300 if (tst->os_state.valgrind_stack_base == 0) {
301 vg_assert(tst->os_state.valgrind_stack_init_SP == 0);
304 if (tst->os_state.valgrind_stack_base != 0) {
305 vg_assert(tst->os_state.valgrind_stack_init_SP != 0);
308 /* If no stack is present, allocate one. */
310 if (tst->os_state.valgrind_stack_base == 0) {
311 stack = VG_(am_alloc_VgStack)( &initial_SP );
312 if (stack) {
313 tst->os_state.valgrind_stack_base = (Addr)stack;
314 tst->os_state.valgrind_stack_init_SP = initial_SP;
318 if (0) {
319 VG_(printf)( "stack for tid %u at %p; init_SP=%p\n",
320 tid,
321 (void*)tst->os_state.valgrind_stack_base,
322 (void*)tst->os_state.valgrind_stack_init_SP );
325 return tst->os_state.valgrind_stack_init_SP;
328 /* Allocate a stack for the main thread, and run it all the way to the
329 end. Although we already have a working VgStack
330 (VG_(interim_stack)) it's better to allocate a new one, so that
331 overflow detection works uniformly for all threads.
333 __attribute__((noreturn))
334 void VG_(main_thread_wrapper_NORETURN)(ThreadId tid)
336 Addr sp;
337 VG_(debugLog)(1, "syswrap-freebsd",
338 "entering VG_(main_thread_wrapper_NORETURN)\n");
340 sp = ML_(allocstack)(tid);
341 #if defined(ENABLE_INNER_CLIENT_REQUEST)
343 // we must register the main thread stack before the call
344 // to ML_(call_on_new_stack_0_1), otherwise the outer valgrind
345 // reports 'write error' on the non registered stack.
346 ThreadState* tst = VG_(get_ThreadState)(tid);
347 INNER_REQUEST
348 ((void)
349 VALGRIND_STACK_REGISTER (tst->os_state.valgrind_stack_base,
350 tst->os_state.valgrind_stack_init_SP));
352 #endif
354 /* If we can't even allocate the first thread's stack, we're hosed.
355 Give up. */
356 vg_assert2(sp != 0, "%s", "Cannot allocate main thread's stack.");
358 /* shouldn't be any other threads around yet */
359 vg_assert( VG_(count_living_threads)() == 1 );
361 ML_(call_on_new_stack_0_1)(
362 (Addr)sp, /* stack */
363 0, /* bogus return address */
364 run_a_thread_NORETURN, /* fn to call */
365 (Word)tid /* arg to give it */
368 /*NOTREACHED*/
369 vg_assert(0);
373 /* Do a fork() */
374 SysRes ML_(do_fork) ( ThreadId tid )
376 vki_sigset_t fork_saved_mask;
377 vki_sigset_t mask;
378 SysRes res;
380 /* Block all signals during fork, so that we can fix things up in
381 the child without being interrupted. */
382 VG_(sigfillset)(&mask);
383 VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &fork_saved_mask);
385 VG_(do_atfork_pre)(tid);
387 res = VG_(do_syscall0)( __NR_fork );
389 if (!sr_isError(res)) {
390 if (sr_Res(res) == 0) {
391 /* child */
392 VG_(do_atfork_child)(tid);
394 /* restore signal mask */
395 VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
397 } else {
398 /* parent */
399 VG_(do_atfork_parent)(tid);
401 if (VG_(clo_trace_syscalls)) {
402 VG_(printf)(" clone(fork): process %d created child %lu\n",
403 VG_(getpid)(), sr_Res(res));
406 /* restore signal mask */
407 VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
411 return res;
414 static Addr ML_(make_safe_mask) ( const HChar* malloc_message, Addr mask_pointer )
416 vki_sigset_t* new_mask;
417 const vki_sigset_t* old_mask = (vki_sigset_t *)mask_pointer;
419 if (!ML_(safe_to_deref)(old_mask, sizeof(vki_sigset_t))) {
420 new_mask = (vki_sigset_t*)1; /* Something recognisable to POST() hook. */
421 } else {
422 new_mask = VG_(malloc)(malloc_message, sizeof(vki_sigset_t));
423 *new_mask = *old_mask;
424 VG_(sanitize_client_sigmask)(new_mask);
427 return (Addr)new_mask;
430 static void ML_(free_safe_mask) ( Addr mask_pointer )
432 if (mask_pointer != 0 && mask_pointer != 1) {
433 VG_(free)((vki_sigset_t *) mask_pointer);
438 /* ---------------------------------------------------------------------
439 PRE/POST wrappers for arch-generic, FreeBSD-specific syscalls
440 ------------------------------------------------------------------ */
442 // Nb: See the comment above the generic PRE/POST wrappers in
443 // m_syswrap/syswrap-generic.c for notes about how they work.
445 #define PRE(name) DEFN_PRE_TEMPLATE(freebsd, name)
446 #define POST(name) DEFN_POST_TEMPLATE(freebsd, name)
448 /* On FreeBSD, if any thread calls exit(2), then they are all shut down, pretty
449 * much like linux's exit_group().
451 // SYS_exit 1
452 // void exit(int status);
453 PRE(sys_exit)
455 ThreadId t;
457 PRINT("exit( %" FMT_REGWORD "u )", ARG1);
458 PRE_REG_READ1(void, "exit", int, status);
460 /* Mark all threads (including this one) to exit. */
461 for (t = 1; t < VG_N_THREADS; t++) {
462 if ( /* not alive */ VG_(threads)[t].status == VgTs_Empty ) {
463 continue;
466 //VG_(threads)[t].exitreason = VgSrc_ExitThread;
467 VG_(threads)[t].os_state.exitcode = ARG1;
469 // if (t != tid)
470 // VG_(get_thread_out_of_syscall)(t); /* unblock it, if blocked */
473 VG_(nuke_all_threads_except)( tid, VgSrc_ExitProcess );
474 VG_(reap_threads)(tid);
475 VG_(threads)[tid].exitreason = VgSrc_ExitThread;
477 /* We have to claim the syscall already succeeded. */
478 SET_STATUS_Success(0);
481 // SYS_fork 2
482 // pid_t fork(void);
483 PRE(sys_fork)
485 PRINT("%s", "sys_fork ()");
486 PRE_REG_READ0(pid_t, "fork");
488 SET_STATUS_from_SysRes( ML_(do_fork)(tid) );
489 if (SUCCESS) {
490 /* Thread creation was successful; let the child have the chance
491 to run */
492 *flags |= SfYieldAfter;
496 // SYS_read 3
497 // generic
499 // SYS_write 4
500 // generic
502 // SYS_open 5
503 // generic
505 // SYS_close 6
506 // generic
508 // SYS_wait4 7
509 // generic
511 // SYS_link 9
512 // generic
514 // SYS_unlink 10
515 // generic
517 // SYS_chdir 12
519 // SYS_fchdir 13
520 // generic
522 // SYS_freebsd11_mknod 14
523 // generic
525 // SYS_chmod 15
526 // generic
528 // SYS_chown 16
529 // generic
531 // SYS_break 17
532 // generic
534 // SYS_getpid 20
535 // generic
537 // SYS_mount 21
538 // int mount(const char *type, const char *dir, int flags, void *data);
539 PRE(sys_mount)
541 // Nb: depending on 'flags', the 'type' and 'data' args may be ignored.
542 // We are conservative and check everything, except the memory pointed to
543 // by 'data'.
544 *flags |= SfMayBlock;
545 PRINT( "sys_mount( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
546 PRE_REG_READ4(int, "mount",
547 const char *, type, char *, dir, int, flags,
548 void *, data);
549 PRE_MEM_RASCIIZ( "mount(type)", ARG1);
550 PRE_MEM_RASCIIZ( "mount(path)", ARG2);
553 // SYS_unmount 22
554 // int unmount(const char *dir, int flags);
555 PRE(sys_unmount)
557 PRINT("sys_umount( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
558 PRE_REG_READ2(int, "unmount", const char *, dir, int, flags);
559 PRE_MEM_RASCIIZ( "unmount(path)", ARG1);
562 // SYS_setuid 23
563 // generic
565 // SYS_getuid 24
566 // generic
568 // SYS_geteuid 25
569 // generic
571 // SYS_ptrace 26
572 // int ptrace(int request, pid_t pid, caddr_t addr, int data);
573 PRE(sys_ptrace)
575 struct vki_ptrace_io_desc *io_desc;
576 PRINT("sys_ptrace ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, 0x%" FMT_REGWORD "x, %" FMT_REGWORD "u)", ARG1, ARG2, ARG3, ARG4);
578 PRE_REG_READ4(int, "ptrace", int, request, pid_t, pid, caddr_t, addr, int, data);
580 switch (ARG1) {
581 case VKI_PTRACE_TRACEME:
582 case VKI_PTRACE_READ_I:
583 case VKI_PTRACE_READ_D:
584 case VKI_PTRACE_WRITE_I:
585 case VKI_PTRACE_WRITE_D:
586 break;
588 case VKI_PTRACE_IO:
589 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_ptrace_io_desc));
590 io_desc = (struct vki_ptrace_io_desc *)ARG3;
591 switch (io_desc->piod_op) {
592 case VKI_PIOD_READ_D:
593 case VKI_PIOD_READ_I:
594 PRE_MEM_WRITE( "ptrace", (UWord)io_desc->piod_addr, io_desc->piod_len);
595 break;
596 case VKI_PIOD_WRITE_D:
597 case VKI_PIOD_WRITE_I:
598 PRE_MEM_READ( "ptrace", (UWord)io_desc->piod_addr, io_desc->piod_len);
599 break;
601 break;
603 case VKI_PTRACE_CONTINUE:
604 case VKI_PTRACE_STEP:
605 case VKI_PTRACE_KILL:
606 case VKI_PTRACE_ATTACH:
607 case VKI_PTRACE_DETACH:
608 break;
610 case VKI_PTRACE_GETREGS:
611 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_user_regs_struct));
612 break;
614 case VKI_PTRACE_SETREGS:
615 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_user_regs_struct));
616 break;
618 case VKI_PTRACE_GETFPREGS:
619 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_fpreg));
620 break;
622 case VKI_PTRACE_SETFPREGS:
623 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_fpreg));
624 break;
626 case VKI_PTRACE_GETDBREGS:
627 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_dbreg));
628 break;
630 case VKI_PTRACE_SETDBREGS:
631 PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_dbreg));
632 break;
634 case VKI_PTRACE_LWPINFO:
635 PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_ptrace_lwpinfo));
636 break;
638 case VKI_PTRACE_GETNUMLWPS:
639 break;
641 case VKI_PTRACE_GETLWPLIST:
642 PRE_MEM_WRITE( "ptrace", ARG3, sizeof(vki_lwpid_t) * ARG4);
643 break;
645 case VKI_PTRACE_SETSTEP:
646 case VKI_PTRACE_CLEARSTEP:
647 case VKI_PTRACE_SUSPEND:
648 case VKI_PTRACE_RESUME:
649 case VKI_PTRACE_TO_SCE:
650 case VKI_PTRACE_TO_SCX:
651 case VKI_PTRACE_SYSCALL:
652 case VKI_PTRACE_VM_TIMESTAMP:
653 break;
654 case VKI_PTRACE_VM_ENTRY:
655 PRE_MEM_WRITE( "ptrace", ARG3, sizeof(struct vki_ptrace_vm_entry));
656 break;
660 POST(sys_ptrace)
662 struct vki_ptrace_io_desc *io_desc;
664 switch (ARG1) {
665 case VKI_PTRACE_TRACEME:
666 case VKI_PTRACE_READ_I:
667 case VKI_PTRACE_READ_D:
668 case VKI_PTRACE_WRITE_I:
669 case VKI_PTRACE_WRITE_D:
670 break;
672 case VKI_PTRACE_IO:
673 io_desc = (struct vki_ptrace_io_desc *)ARG3;
674 switch (io_desc->piod_op) {
675 case VKI_PIOD_READ_D:
676 case VKI_PIOD_READ_I:
677 if ((Word)RES != -1) {
678 POST_MEM_WRITE((UWord)io_desc->piod_addr, io_desc->piod_len);
680 break;
681 case VKI_PIOD_WRITE_D:
682 case VKI_PIOD_WRITE_I:
683 break;
685 break;
687 case VKI_PTRACE_CONTINUE:
688 case VKI_PTRACE_STEP:
689 case VKI_PTRACE_KILL:
690 case VKI_PTRACE_ATTACH:
691 case VKI_PTRACE_DETACH:
692 break;
694 case VKI_PTRACE_GETREGS:
695 if ((Word)RES != -1) {
696 POST_MEM_WRITE(ARG3, sizeof(struct vki_user_regs_struct));
698 break;
700 case VKI_PTRACE_SETREGS:
701 break;
703 case VKI_PTRACE_GETFPREGS:
704 if ((Word)RES != -1) {
705 POST_MEM_WRITE(ARG3, sizeof(struct vki_fpreg));
707 break;
709 case VKI_PTRACE_SETFPREGS:
710 break;
712 case VKI_PTRACE_GETDBREGS:
713 if ((Word)RES != -1) {
714 POST_MEM_WRITE(ARG3, sizeof(struct vki_dbreg));
716 break;
718 case VKI_PTRACE_SETDBREGS:
719 break;
721 case VKI_PTRACE_LWPINFO:
722 if ((Word)RES != -1) {
723 POST_MEM_WRITE(ARG3, sizeof(struct vki_ptrace_lwpinfo));
725 break;
727 case VKI_PTRACE_GETNUMLWPS:
728 break;
730 case VKI_PTRACE_GETLWPLIST:
731 if ((Word)RES != -1) {
732 POST_MEM_WRITE(ARG3, sizeof(vki_lwpid_t) * RES);
734 break;
736 case VKI_PTRACE_SETSTEP:
737 case VKI_PTRACE_CLEARSTEP:
738 case VKI_PTRACE_SUSPEND:
739 case VKI_PTRACE_RESUME:
740 case VKI_PTRACE_TO_SCE:
741 case VKI_PTRACE_TO_SCX:
742 case VKI_PTRACE_SYSCALL:
743 case VKI_PTRACE_VM_TIMESTAMP:
744 break;
746 case VKI_PTRACE_VM_ENTRY:
747 if ((Word)RES != -1) {
748 POST_MEM_WRITE(ARG3, sizeof(struct vki_ptrace_vm_entry));
750 break;
754 // SYS_recvmsg 27
755 // ssize_t recvmsg(int s, struct msghdr *msg, int flags);
756 PRE(sys_recvmsg)
758 *flags |= SfMayBlock;
759 PRINT("sys_recvmsg ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )",SARG1,ARG2,SARG3);
760 PRE_REG_READ3(vki_ssize_t, "recvmsg", int, s, struct msghdr *, msg, int, flags);
761 ML_(generic_PRE_sys_recvmsg)(tid, "recvmsg", (struct vki_msghdr *)ARG2);
764 POST(sys_recvmsg)
767 ML_(generic_POST_sys_recvmsg)(tid, "recvmsg", (struct vki_msghdr *)ARG2, RES);
770 // SYS_sendmsg 28
771 // ssize_t sendmsg(int s, const struct msghdr *msg, int flags);
772 PRE(sys_sendmsg)
774 *flags |= SfMayBlock;
775 PRINT("sys_sendmsg ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
776 PRE_REG_READ3(ssize_t, "sendmsg",
777 int, s, const struct msghdr *, msg, int, flags);
778 ML_(generic_PRE_sys_sendmsg)(tid, "sendmsg", (struct vki_msghdr *)ARG2);
781 // SYS_recvfrom 29
782 // ssize_t recvfrom(int s, void *buf, size_t len, int flags,
783 // struct sockaddr * restrict from, socklen_t * restrict fromlen);
784 PRE(sys_recvfrom)
786 *flags |= SfMayBlock;
787 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);
788 PRE_REG_READ6(ssize_t, "recvfrom",
789 int, s, void *, buf, size_t, len, int, flags,
790 struct sockaddr *, from, int *, fromlen);
791 ML_(generic_PRE_sys_recvfrom)(tid, ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
794 POST(sys_recvfrom)
796 vg_assert(SUCCESS);
797 ML_(generic_POST_sys_recvfrom)(tid, VG_(mk_SysRes_Success)(RES),
798 ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
801 // SYS_accept 30
802 // int accept(int s, struct sockaddr * restrict addr,
803 // socklen_t * restrict addrlen);
804 PRE(sys_accept)
806 *flags |= SfMayBlock;
807 PRINT("sys_accept ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
808 PRE_REG_READ3(int, "accept",
809 int, s, struct sockaddr *, addr, int, *addrlen);
810 ML_(generic_PRE_sys_accept)(tid, ARG1,ARG2,ARG3);
813 POST(sys_accept)
815 SysRes r;
816 vg_assert(SUCCESS);
817 r = ML_(generic_POST_sys_accept)(tid, VG_(mk_SysRes_Success)(RES),
818 ARG1,ARG2,ARG3);
819 SET_STATUS_from_SysRes(r);
822 // SYS_getpeername 31
823 // int getpeername(int s, struct sockaddr * restrict name,
824 // socklen_t * restrict namelen);
825 PRE(sys_getpeername)
827 PRINT("sys_getpeername ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3);
828 PRE_REG_READ3(int, "getpeername",
829 int, s, struct sockaddr *, name, socklen_t *, namelen);
830 ML_(generic_PRE_sys_getpeername)(tid, ARG1,ARG2,ARG3);
833 POST(sys_getpeername)
835 vg_assert(SUCCESS);
836 ML_(generic_POST_sys_getpeername)(tid, VG_(mk_SysRes_Success)(RES),
837 ARG1,ARG2,ARG3);
840 // SYS_getsockname 32
841 // int getsockname(int s, struct sockaddr * restrict name,
842 // socklen_t * restrict namelen);
843 PRE(sys_getsockname)
845 PRINT("sys_getsockname ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",SARG1,ARG2,ARG3);
846 PRE_REG_READ3(long, "getsockname",
847 int, s, struct sockaddr *, name, int *, namelen);
848 ML_(generic_PRE_sys_getsockname)(tid, ARG1,ARG2,ARG3);
851 POST(sys_getsockname)
853 vg_assert(SUCCESS);
854 ML_(generic_POST_sys_getsockname)(tid, VG_(mk_SysRes_Success)(RES),
855 ARG1,ARG2,ARG3);
858 // SYS_access 33
859 // generic
861 // SYS_chflags 34
862 // int chflags(const char *path, unsigned long flags)
863 PRE(sys_chflags)
865 PRINT("sys_chflags ( %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2);
866 PRE_REG_READ2(int, "chflags",
867 const char *, path, unsigned long, flags);
868 PRE_MEM_RASCIIZ( "chflags(path)", ARG1 );
871 // SYS_fchflags 35
872 // int fchflags(int fd, unsigned long flags);
873 PRE(sys_fchflags)
875 PRINT("sys_fchflags ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2);
876 PRE_REG_READ2(int, "fchflags", int, fd, unsigned long, flags);
879 // SYS_sync 36
880 // generic
882 // SYS_kill 37
883 // generic
885 // SYS_getppid 39
886 // generic
888 // SYS_dup 41
889 // generic
891 // Pipe on freebsd doesn't have args, and uses dual returns!
892 // SYS_freebsd10_pipe 42
893 // int pipe(void);
894 PRE(sys_pipe)
896 PRINT("%s", "sys_pipe ()");
899 POST(sys_pipe)
901 if (!ML_(fd_allowed)(RES, "pipe", tid, True) ||
902 !ML_(fd_allowed)(RESHI, "pipe", tid, True)) {
903 VG_(close)(RES);
904 VG_(close)(RESHI);
905 SET_STATUS_Failure( VKI_EMFILE );
906 } else {
907 if (VG_(clo_track_fds)) {
908 ML_(record_fd_open_nameless)(tid, RES);
909 ML_(record_fd_open_nameless)(tid, RESHI);
914 // SYS_getegid 43
915 // generic
917 // SYS_profil 44
918 // generic
920 // SYS_ktrace 45
921 // generic
923 // SYS_getgid 47
924 // generic
926 // SYS_getlogin 49
927 // syscall.master refers to namelen and namebuf for the argument names
928 // man getlogin has just getlogin(void) but also
929 // int getlogin_r(char *name, int len);
930 // so let's go with those names
931 PRE(sys_getlogin)
933 PRINT("sys_getlogin ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2);
934 PRE_REG_READ2(int, "getlogin", char *, buf, u_int, len);
935 PRE_MEM_WRITE( "getlogin(name)", ARG1, ARG2 );
938 POST(sys_getlogin)
940 POST_MEM_WRITE(ARG1, ARG2 );
943 // SYS_setlogin 50
944 // int setlogin(const char *name);
945 PRE(sys_setlogin)
947 PRINT("sys_setlogin ( %#" FMT_REGWORD "x )",ARG1);
948 PRE_REG_READ1(long, "setlogin", char *, buf);
949 PRE_MEM_RASCIIZ( "setlogin(buf)", ARG1 );
952 // SYS_acct 51
953 // generic
955 // SYS_sigaltstack 53
956 // generic
958 // SYS_ioctl 54
959 // int ioctl(int fd, unsigned long request, ...);
960 PRE(sys_ioctl)
962 UInt dir = _VKI_IOC_DIR(ARG2);
963 UInt size = _VKI_IOC_SIZE(ARG2);
964 *flags |= SfMayBlock;
965 // @todo PJF presumably the presence of ARG3 depends on ARG2
966 PRINT("sys_ioctl ( %" FMT_REGWORD "u, 0x%" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3);
967 PRE_REG_READ3(int, "ioctl",
968 int, fd, unsigned long, request, unsigned long, arg);
970 /* On FreeBSD, ALL ioctl's are IOR/IOW encoded. Just use the default decoder */
971 if (SimHintiS(SimHint_lax_ioctls, VG_(clo_sim_hints))) {
973 * Be very lax about ioctl handling; the only
974 * assumption is that the size is correct. Doesn't
975 * require the full buffer to be initialized when
976 * writing. Without this, using some device
977 * drivers with a large number of strange ioctl
978 * commands becomes very tiresome.
980 } else if (dir == _VKI_IOC_NONE && size > 0) {
981 static UWord unknown_ioctl[10];
982 static Int moans = sizeof(unknown_ioctl) / sizeof(unknown_ioctl[0]);
983 if (moans > 0 && !VG_(clo_xml)) {
984 /* Check if have not already moaned for this request. */
985 UInt i;
986 for (i = 0; i < sizeof(unknown_ioctl)/sizeof(unknown_ioctl[0]); i++) {
987 if (unknown_ioctl[i] == ARG2) {
988 break;
990 if (unknown_ioctl[i] == 0) {
991 unknown_ioctl[i] = ARG2;
992 moans--;
993 VG_(umsg)("Warning: noted but unhandled ioctl 0x%lx"
994 " with no direction hints.\n", ARG2);
995 VG_(umsg)(" This could cause spurious value errors to appear.\n");
996 VG_(umsg)(" See README_MISSING_SYSCALL_OR_IOCTL for "
997 "guidance on writing a proper wrapper.\n" );
998 return;
1002 } else {
1003 if ((dir & _VKI_IOC_WRITE) && size > 0) {
1004 PRE_MEM_READ( "ioctl(generic)", ARG3, size);
1006 if ((dir & _VKI_IOC_READ) && size > 0) {
1007 PRE_MEM_WRITE( "ioctl(generic)", ARG3, size);
1011 // The block below is from Ryan Stone
1012 // https://bitbucket.org/rysto32/valgrind-freebsd/commits/5323c22be9f6c71a00e842c3ddfa1fa8a7feb279
1013 // however it drags in hundreds of lines of headers into vki-freebsd.h.
1014 // How stable are these structures? -> maintainability is a concern
1015 // Also there are no testcases for this.
1016 // Hence #if 0
1017 #if 0
1018 /* Handle specific ioctls which pass structures which may have pointers to other
1019 buffers */
1020 switch (ARG2 /* request */) {
1021 case VKI_SIOCGIFMEDIA:
1022 if (ARG3) {
1023 struct vki_ifmediareq* imr = (struct vki_ifmediareq*)ARG3;
1024 if (imr->ifm_ulist) {
1025 PRE_MEM_WRITE("ioctl(SIOCGIFMEDIA).ifm_ulist",
1026 (Addr)(imr->ifm_ulist), imr->ifm_count * sizeof(int));
1029 break;
1031 case VKI_PCIOCGETCONF:
1032 if (ARG3) {
1033 struct vki_pci_conf_io* pci = (struct vki_pci_conf_io*)ARG3;
1034 PRE_MEM_READ("ioctl(PCIOCGETCONF).patterns",
1035 (Addr)(pci->patterns), pci->pat_buf_len);
1036 PRE_MEM_WRITE("ioctl(PCIOCGETCONF).matches",
1037 (Addr)(pci->matches), pci->match_buf_len);
1039 break;
1041 case VKI_CAMIOCOMMAND:
1042 if (ARG3) {
1043 union vki_ccb* ccb = (union vki_ccb*)ARG3;
1044 if (ccb->ccb_h.func_code == VKI_XPT_DEV_MATCH) {
1045 PRE_MEM_WRITE("ioctl(CAMIOCOMMAND:XPT_DEV_MATCH).matches",
1046 (Addr)(ccb->cdm.matches), ccb->cdm.match_buf_len);
1047 } else if (ccb->ccb_h.func_code == VKI_XPT_SCSI_IO) {
1048 struct vki_ccb_scsiio* scsiio = (struct vki_ccb_scsiio*)ccb;
1049 if (scsiio->dxfer_len) {
1050 if ((scsiio->ccb_h.flags & VKI_CAM_DIR_MASK) == VKI_CAM_DIR_IN) {
1051 PRE_MEM_WRITE("ioctl(CAMIOCOMMAND:XPT_SCSI_IO).data_ptr",
1052 (Addr)(scsiio->data_ptr), scsiio->dxfer_len);
1053 } else if ((scsiio->ccb_h.flags & VKI_CAM_DIR_MASK) == VKI_CAM_DIR_OUT) {
1054 PRE_MEM_READ("ioctl(CAMIOCOMMAND:XPT_SCSI_IO).data_ptr",
1055 (Addr)(scsiio->data_ptr), scsiio->dxfer_len);
1058 } else if (ccb->ccb_h.func_code == VKI_XPT_GDEV_TYPE ||
1059 ccb->ccb_h.func_code == VKI_XPT_PATH_INQ ||
1060 ccb->ccb_h.func_code == VKI_XPT_GET_TRAN_SETTINGS) {
1061 // do nothing
1062 } else {
1063 VG_(message)(Vg_UserMsg,
1064 "Warning: unhandled ioctl CAMIOCOMMAND function 0x%lx\n",
1065 ccb->ccb_h.func_code);
1068 break;
1070 #endif
1073 POST(sys_ioctl)
1075 UInt dir = _VKI_IOC_DIR(ARG2);
1076 UInt size = _VKI_IOC_SIZE(ARG2);
1077 vg_assert(SUCCESS);
1078 if (size > 0 && (dir & _VKI_IOC_READ)
1079 && RES == 0 && ARG3 != (Addr)NULL) {
1080 POST_MEM_WRITE(ARG3, size);
1083 #if 0
1084 /* Handle specific ioctls which pass structures which may have pointers to other
1085 buffers */
1086 switch (ARG2 /* request */) {
1087 case VKI_SIOCGIFMEDIA:
1088 if (ARG3) {
1089 struct vki_ifmediareq* imr = (struct vki_ifmediareq*)ARG3;
1090 if (imr->ifm_ulist) {
1091 POST_MEM_WRITE((Addr)(imr->ifm_ulist), imr->ifm_count * sizeof(int));
1094 break;
1096 case VKI_PCIOCGETCONF:
1097 if (ARG3) {
1098 struct vki_pci_conf_io* pci = (struct vki_pci_conf_io*)ARG3;
1099 POST_MEM_WRITE((Addr)(pci->matches), pci->num_matches * sizeof(struct vki_pci_conf));
1101 break;
1103 case VKI_CAMIOCOMMAND:
1104 if (ARG3) {
1105 union vki_ccb* ccb = (union vki_ccb*)ARG3;
1106 if (ccb->ccb_h.func_code == VKI_XPT_DEV_MATCH) {
1107 POST_MEM_WRITE((Addr)(ccb->cdm.matches), ccb->cdm.num_matches*sizeof(struct vki_dev_match_result));
1108 } else if (ccb->ccb_h.func_code == VKI_XPT_SCSI_IO) {
1109 struct vki_ccb_scsiio* scsiio = (struct vki_ccb_scsiio*)ccb;
1110 if (scsiio->dxfer_len) {
1111 if ((scsiio->ccb_h.flags & VKI_CAM_DIR_MASK) == VKI_CAM_DIR_IN) {
1112 POST_MEM_WRITE((Addr)(scsiio->data_ptr), scsiio->dxfer_len);
1117 break;
1119 #endif
1122 // SYS_reboot 55
1123 // int reboot(int howto);
1124 PRE(sys_reboot)
1126 PRINT("sys_reboot ( %" FMT_REGWORD "d )", SARG1);
1127 PRE_REG_READ1(int, "reboot", int, howto);
1130 // SYS_revoke 56
1131 // int revoke(const char *path);
1132 PRE(sys_revoke)
1134 PRINT("sys_revoke ( %#" FMT_REGWORD "x(%s) )", ARG1, (char*)ARG1);
1135 PRE_REG_READ1(long, "revoke", const char *, path);
1136 PRE_MEM_RASCIIZ( "revoke(path)", ARG1);
1139 // SYS_symlink 57
1140 // generic
1142 static void do_readlink(const HChar* path, HChar *buf, SizeT bufsize, SyscallStatus* status, Bool* curproc_file)
1144 HChar name[30];
1145 VG_(sprintf)(name, "/proc/%d/file", VG_(getpid)());
1146 if (ML_(safe_to_deref)(path, 1)
1147 && (VG_(strcmp)(path, name) == 0
1148 || VG_(strcmp)(path, "/proc/curproc/file") == 0)) {
1149 vg_assert(VG_(resolved_exename));
1150 Int len = VG_(snprintf)(buf, bufsize, "%s", VG_(resolved_exename));
1151 SET_STATUS_Success(len);
1152 *curproc_file = True;
1156 // SYS_readlink 58
1157 // ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsiz);
1158 PRE(sys_readlink)
1160 FUSE_COMPATIBLE_MAY_BLOCK();
1161 Word saved = SYSNO;
1162 Bool curproc_file = False;
1164 PRINT("sys_readlink ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %llu )",
1165 ARG1, (char*)(Addr)ARG1, ARG2, (ULong)ARG3);
1166 PRE_REG_READ3(long, "readlink",
1167 const char *, path, char *, buf, int, bufsiz);
1168 PRE_MEM_RASCIIZ( "readlink(path)", ARG1 );
1169 PRE_MEM_WRITE( "readlink(buf)", ARG2,ARG3 );
1171 if (VG_(have_slash_proc) == True)
1174 * Handle the case where readlink is looking at /proc/curproc/file or
1175 * /proc/<pid>/file
1177 do_readlink((const HChar *)ARG1, (HChar *)ARG2, (SizeT)ARG3, status, &curproc_file);
1180 if (!curproc_file) {
1181 /* Normal case */
1182 SET_STATUS_from_SysRes( VG_(do_syscall3)(saved, ARG1, ARG2, ARG3));
1184 if (SUCCESS && RES > 0) {
1185 POST_MEM_WRITE( ARG2, RES );
1189 // SYS_execve 59
1190 // generic
1192 // SYS_umask 60
1193 // generic
1195 // SYS_chroot 61
1196 // generic
1198 // SYS_msync 65
1199 // generic
1201 // SYS_vfork 66
1202 // pid_t vfork(void);
1203 PRE(sys_vfork)
1205 PRINT("%s", "sys_vfork ()");
1206 PRE_REG_READ0(pid_t, "vfork");
1208 /* Pretend vfork == fork. Not true, but will have to do. */
1209 SET_STATUS_from_SysRes( ML_(do_fork)(tid) );
1210 if (SUCCESS) {
1211 /* Thread creation was successful; let the child have the chance
1212 to run */
1213 *flags |= SfYieldAfter;
1217 // SYS_sbrk 69
1218 // void * sbrk(intptr_t incr);
1219 PRE(sys_sbrk)
1221 PRINT("sys_sbrk ( %#" FMT_REGWORD "x )",ARG1);
1222 PRE_REG_READ1(void*, "sbrk", vki_intptr_t, incr);
1225 // SYS_freebsd11_vadvise 72
1226 // @todo maybe
1228 // SYS_munmap 73
1229 // generic
1231 // SYS_mprotect 74
1232 // generic
1234 // SYS_madvise 75
1235 // generic
1237 // SYS_mincore 78
1238 // generic
1240 // SYS_getgroups 79
1241 // generic
1243 // SYS_setgroups 80
1244 // generic
1246 // SYS_getpgrp 81
1247 // generic
1249 // SYS_setpgid 82
1250 // generic
1252 // SYS_setitimer 83
1253 // generic
1255 // SYS_swapon 85
1256 // int swapon(const char *special);
1257 PRE(sys_swapon)
1259 PRINT("sys_swapon ( %#" FMT_REGWORD "x(%s) )", ARG1,(char*)ARG1);
1260 PRE_REG_READ1(int, "swapon", const char*, special );
1261 PRE_MEM_RASCIIZ( "swapon(special)", ARG1 );
1264 // SYS_getitimer 86
1265 // generic
1267 // SYS_getdtablesize 89
1268 // int getdtablesize(void);
1269 PRE(sys_getdtablesize)
1271 PRINT("%s", "sys_getdtablesize ( )");
1272 PRE_REG_READ0(long, "getdtablesize");
1275 // SYS_dup2 90
1276 // generic
1278 // SYS_fcntl 92
1279 // int fcntl(int fd, int cmd, ...);
1280 PRE(sys_fcntl)
1282 switch (ARG2) {
1283 // These ones ignore ARG3.
1284 case VKI_F_GETFD:
1285 case VKI_F_GETFL:
1286 case VKI_F_GETOWN:
1287 case VKI_F_GET_SEALS:
1288 case VKI_F_ISUNIONSTACK:
1289 PRINT("sys_fcntl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,SARG2);
1290 PRE_REG_READ2(int, "fcntl", int, fd, int, cmd);
1291 break;
1293 // These ones use ARG3 as "arg".
1294 case VKI_F_DUPFD:
1295 case VKI_F_DUPFD_CLOEXEC:
1296 case VKI_F_SETFD:
1297 case VKI_F_SETFL:
1298 case VKI_F_SETOWN:
1299 case VKI_F_READAHEAD:
1300 case VKI_F_RDAHEAD:
1301 case VKI_F_ADD_SEALS:
1302 PRINT("sys_fcntl[ARG3=='arg'] ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,SARG2,SARG3);
1303 PRE_REG_READ3(int, "fcntl",
1304 int, fd, int, cmd, int, arg);
1305 break;
1307 // These ones use ARG3 as "lock" - obsolete.
1308 case VKI_F_OSETLKW:
1309 *flags |= SfMayBlock;
1310 /* FALLTHROUGH */
1311 case VKI_F_OGETLK:
1312 case VKI_F_OSETLK:
1313 PRINT("sys_fcntl[ARG3=='lock'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
1314 PRE_REG_READ3(int, "fcntl",
1315 int, fd, int, cmd,
1316 struct oflock *, lock);
1317 break;
1319 // This one uses ARG3 as "oldd" and ARG4 as "newd".
1320 case VKI_F_DUP2FD:
1321 case VKI_F_DUP2FD_CLOEXEC:
1322 PRINT("sys_fcntl[ARG3=='oldd', ARG4=='newd'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",
1323 ARG1,ARG2,ARG3,ARG4);
1324 PRE_REG_READ4(int, "fcntl",
1325 int, fd, int, cmd,
1326 unsigned long, oldd, unsigned long, newd);
1327 break;
1329 // These ones use ARG3 as "lock".
1330 case VKI_F_SETLKW:
1331 *flags |= SfMayBlock;
1332 /* FALLTHROUGH */
1333 case VKI_F_GETLK:
1334 case VKI_F_SETLK:
1335 case VKI_F_SETLK_REMOTE:
1336 PRINT("sys_fcntl[ARG3=='lock'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
1337 PRE_REG_READ3(int, "fcntl",
1338 int, fd, int, cmd,
1339 struct flock *, lock);
1340 break;
1341 case VKI_F_KINFO:
1342 PRINT("sys_fcntl[ARG3=='kinfo_file'] ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
1343 PRE_REG_READ3(int, "fcntl",
1344 int, fd, int, cmd,
1345 struct vki_kinfo_file *, kinfo);
1346 if (ARG3) {
1347 struct vki_kinfo_file* p_kinfo_file = (struct vki_kinfo_file*)ARG3;
1348 PRE_MEM_WRITE("fcntl(ARG3=='kinfo_file)", ARG3, p_kinfo_file->vki_kf_structsize);
1350 break;
1352 default:
1353 PRINT("sys_fcntl[UNKNOWN] ( %lu, %lu, %lu )", ARG1,ARG2,ARG3);
1354 I_die_here;
1358 POST(sys_fcntl)
1360 vg_assert(SUCCESS);
1361 if (ARG2 == VKI_F_DUPFD) {
1362 if (!ML_(fd_allowed)(RES, "fcntl(DUPFD)", tid, True)) {
1363 VG_(close)(RES);
1364 SET_STATUS_Failure( VKI_EMFILE );
1365 } else {
1366 if (VG_(clo_track_fds)) {
1367 ML_(record_fd_open_named)(tid, RES);
1370 } else if (ARG2 == VKI_F_DUPFD_CLOEXEC) {
1371 if (!ML_(fd_allowed)(RES, "fcntl(DUPFD_CLOEXEC)", tid, True)) {
1372 VG_(close)(RES);
1373 SET_STATUS_Failure( VKI_EMFILE );
1374 } else {
1375 if (VG_(clo_track_fds)) {
1376 ML_(record_fd_open_named)(tid, RES);
1382 // SYS_select 93
1383 // generic
1385 // SYS_fsync 95
1386 // generic
1388 // SYS_setpriority 9
1389 // generic
1391 // SYS_socket 97
1392 // int socket(int domain, int type, int protocol);
1393 PRE(sys_socket)
1395 PRINT("sys_socket ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %" FMT_REGWORD "d )",SARG1,SARG2,SARG3);
1396 PRE_REG_READ3(int, "socket", int, domain, int, type, int, protocol);
1399 POST(sys_socket)
1401 SysRes r;
1402 vg_assert(SUCCESS);
1403 r = ML_(generic_POST_sys_socket)(tid, VG_(mk_SysRes_Success)(RES));
1404 SET_STATUS_from_SysRes(r);
1407 // SYS_connect 98
1408 // int connect(int s, const struct sockaddr *name, socklen_t namelen);
1409 PRE(sys_connect)
1411 *flags |= SfMayBlock;
1412 PRINT("sys_connect ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
1413 PRE_REG_READ3(int, "connect",
1414 int, s, const struct sockaddr *, name, int, namelen);
1415 ML_(generic_PRE_sys_connect)(tid, ARG1,ARG2,ARG3);
1418 // SYS_getpriority 100
1419 // generic
1421 // SYS_bind 104
1422 // int bind(int s, const struct sockaddr *addr, socklen_t addrlen);
1423 PRE(sys_bind)
1425 PRINT("sys_bind ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
1426 PRE_REG_READ3(int, "bind",
1427 int, s, struct sockaddr *, addr, int, addrlen);
1428 ML_(generic_PRE_sys_bind)(tid, ARG1,ARG2,ARG3);
1431 // SYS_setsockopt 105
1432 // int setsockopt(int s, int level, int optname, const void *optval,
1433 // socklen_t optlen);
1434 PRE(sys_setsockopt)
1436 PRINT("sys_setsockopt ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",SARG1,SARG2,SARG3,ARG4,ARG5);
1437 PRE_REG_READ5(int, "setsockopt",
1438 int, s, int, level, int, optname,
1439 const void *, optval, vki_socklen_t, optlen);
1440 ML_(generic_PRE_sys_setsockopt)(tid, ARG1,ARG2,ARG3,ARG4,ARG5);
1443 // SYS_listen 106
1444 // int listen(int s, int backlog);
1445 PRE(sys_listen)
1447 PRINT("sys_listen ( %" FMT_REGWORD "d, %" FMT_REGWORD "d )",SARG1,SARG2);
1448 PRE_REG_READ2(int, "listen", int, s, int, backlog);
1451 //SYS_gettimeofday 116
1452 // generic
1454 // SYS_getrusage 117
1455 // generic
1457 // SYS_getsockopt 118
1458 // int getsockopt(int s, int level, int optname, void * restrict optval,
1459 // socklen_t * restrict optlen);
1460 PRE(sys_getsockopt)
1462 Addr optval_p = ARG4;
1463 Addr optlen_p = ARG5;
1464 PRINT("sys_getsockopt ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4,ARG5);
1465 PRE_REG_READ5(int, "getsockopt",
1466 int, s, int, level, int, optname,
1467 void *, optval, int, *optlen);
1468 if (optval_p != (Addr)NULL) {
1469 ML_(buf_and_len_pre_check) ( tid, optval_p, optlen_p,
1470 "getsockopt(optval)",
1471 "getsockopt(optlen)" );
1475 POST(sys_getsockopt)
1477 Addr optval_p = ARG4;
1478 Addr optlen_p = ARG5;
1479 vg_assert(SUCCESS);
1480 if (optval_p != (Addr)NULL) {
1481 ML_(buf_and_len_post_check) ( tid, VG_(mk_SysRes_Success)(RES),
1482 optval_p, optlen_p,
1483 "getsockopt(optlen_out)" );
1487 // SYS_readv 120
1488 // generic
1490 // SYS_writev 121
1491 // generic
1493 // SYS_settimeofday 122
1494 // generic
1496 // SYS_fchown 123
1497 // generic
1499 // SYS_fchmod 124
1500 // generic
1502 // SYS_setreuid 126
1503 // generic
1505 // SYS_setregid 127
1506 // generic
1508 // SYS_rename 128
1509 // generic
1511 // SYS_flock 131
1512 // generic
1514 // SYS_mkfifo 132
1515 // int mkfifo(const char *path, mode_t mode);
1516 PRE(sys_mkfifo)
1518 PRINT("sys_mkfifo ( %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x, 0x%" FMT_REGWORD "x )", ARG1, (char *)ARG1, ARG2, ARG3 );
1519 PRE_REG_READ2(int, "mkfifo", const char *, path, int, mode);
1520 PRE_MEM_RASCIIZ( "mkfifo(path)", ARG1 );
1523 // SYS_sendto 133
1524 // ssize_t sendto(int s, const void *msg, size_t len, int flags,
1525 // const struct sockaddr *to, socklen_t tolen);
1526 PRE(sys_sendto)
1528 *flags |= SfMayBlock;
1529 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);
1530 PRE_REG_READ6(ssize_t, "sendto",
1531 int, s, const void *, msg, int, len,
1532 int, flags,
1533 const struct sockaddr *, to, socklen_t, tolen);
1534 ML_(generic_PRE_sys_sendto)(tid, ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
1537 // SYS_shutdown 134
1538 // int shutdown(int s, int how);
1539 PRE(sys_shutdown)
1541 *flags |= SfMayBlock;
1542 PRINT("sys_shutdown ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2);
1543 PRE_REG_READ2(int, "shutdown", int, s, int, how);
1546 // SYS_socketpair 135
1547 // int socketpair(int domain, int type, int protocol, int *sv);
1548 PRE(sys_socketpair)
1550 PRINT("sys_socketpair ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
1551 PRE_REG_READ4(int, "socketpair",
1552 int, domain, int, type, int, protocol, int *, sv);
1553 ML_(generic_PRE_sys_socketpair)(tid, ARG1,ARG2,ARG3,ARG4);
1556 POST(sys_socketpair)
1558 vg_assert(SUCCESS);
1559 ML_(generic_POST_sys_socketpair)(tid, VG_(mk_SysRes_Success)(RES),
1560 ARG1,ARG2,ARG3,ARG4);
1563 // SYS_mkdir 136
1564 // generic
1566 // SYS_rmdir 137
1567 // generic
1569 // SYS_utimes 138
1570 // generic
1572 // SYS_adjtime 140
1573 // int adjtime(const struct timeval *delta, struct timeval *olddelta);
1574 PRE(sys_adjtime)
1576 PRINT("sys_adjtime ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
1577 PRE_REG_READ2(int, "adjtime",
1578 const struct vki_timeval *, delta, struct vki_timeval *, olddelta);
1579 PRE_MEM_READ("adjtime(delta)", ARG1, sizeof(struct vki_timeval));
1580 if (ARG2) {
1581 PRE_MEM_WRITE("adjtime(olddelta)", ARG1, sizeof(struct vki_timeval));
1585 POST(sys_adjtime)
1587 if (ARG2) {
1588 POST_MEM_WRITE(ARG1, sizeof(struct vki_timeval));
1592 // SYS_setsid 147
1593 // generic
1595 // SYS_quotactl 148
1596 /* int quotactl(const char *path, int cmd, int id, void *addr); */
1597 PRE(sys_quotactl)
1599 PRINT("sys_quotactl ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3, ARG4);
1600 switch (ARG2) {
1601 case VKI_Q_QUOTAON:
1602 case VKI_Q_SETQUOTA:
1603 case VKI_Q_SETUSE:
1605 case VKI_Q_GETQUOTASIZE:
1606 PRE_REG_READ4(int, "quotactl",
1607 const char *, path, int, cmd, int, id,
1608 void *, addr);
1609 PRE_MEM_RASCIIZ( "quotactl(path)", ARG1 );
1610 break;
1611 case VKI_Q_GETQUOTA:
1612 if (VG_(tdict).track_pre_reg_read) {
1614 PRRSN;
1615 PRA1("quotactl",const char*,path);
1616 PRA2("quotactl",int,cmd);
1617 PRA4("quotactl",void*,addr);
1619 break;
1620 case VKI_Q_QUOTAOFF:
1621 case VKI_Q_SYNC:
1622 PRE_REG_READ2(int, "quotactl",
1623 const char *, path, int, cmd);
1624 break;
1625 default:
1626 break;
1630 // SYS_nlm_syscall 154
1631 // syscall.master says ; 154 is initialised by the NLM code, if present.
1632 // @todo
1634 // SYS_nfssvc 155
1635 // int nfssvc(int flags, void *argstructp);
1636 // lengthy manpage, at least 3 types of struct that argstructp can point to
1637 // @todo
1639 // SYS_lgetfh 160
1640 // int lgetfh(const char *path, fhandle_t *fhp);
1641 PRE(sys_lgetfh)
1643 PRINT("sys_lgetfh ( %#" FMT_REGWORD "x, %" FMT_REGWORD "x ", ARG1, ARG2);
1644 PRE_REG_READ2(int, "lgetfh", const char*, path, vki_fhandle_t*, fhp);
1645 PRE_MEM_RASCIIZ( "lgetfh(path)", ARG1 );
1646 PRE_MEM_WRITE("lgetfh(fhp)", ARG2, sizeof(vki_fhandle_t));
1649 POST(sys_lgetfh)
1651 POST_MEM_WRITE(ARG2, sizeof(vki_fhandle_t));
1654 // SYS_getfh 161
1655 // int getfh(const char *path, fhandle_t *fhp);
1656 PRE(sys_getfh)
1658 PRINT("sys_getfh ( %#" FMT_REGWORD "x, %" FMT_REGWORD "x ", ARG1, ARG2);
1659 PRE_REG_READ2(int, "getfh", const char*, path, vki_fhandle_t*, fhp);
1660 PRE_MEM_RASCIIZ( "getfh(path)", ARG1 );
1661 PRE_MEM_WRITE("getfh(fhp)", ARG2, sizeof(vki_fhandle_t));
1664 POST(sys_getfh)
1666 POST_MEM_WRITE(ARG2, sizeof(vki_fhandle_t));
1669 #if (FREEBSD_VERS <= FREEBSD_10)
1670 // 162
1671 // int getdomainname(char *domainname, int len);
1672 PRE(sys_freebsd4_getdomainname)
1674 PRINT("sys_freebsd4_getdomainname ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2);
1675 PRE_REG_READ2(int, "getdomainname",
1676 char *, domainname, int, len);
1677 PRE_MEM_WRITE( "getdomainname(domainname)", ARG1, ARG2 );
1680 POST(sys_freebsd4_getdomainname)
1682 if (ARG1 != 0) {
1683 POST_MEM_WRITE( ARG1, ARG2 );
1687 // 163
1688 // int setdomainname(char *domainname, int len);
1689 PRE(sys_freebsd4_setdomainname)
1691 PRINT("sys_freebsd4_setdomainname ( %#" FMT_REGWORD "x )",ARG1);
1692 PRE_REG_READ2(int, "setdomainname", char *, domainname, int, len);
1693 PRE_MEM_RASCIIZ( "setdomainname(domainname)", ARG1 );
1696 // 164
1697 // int uname(struct utsname *name);
1698 PRE(sys_freebsd4_uname)
1700 PRINT("sys_freebsd4_uname ( %#" FMT_REGWORD "x )", ARG1);
1701 PRE_REG_READ1(int, "uname", struct utsname *, name);
1702 PRE_MEM_WRITE( "uname(name)", ARG1, sizeof(struct vki_utsname) );
1705 POST(sys_freebsd4_uname)
1707 if (ARG1 != 0) {
1708 POST_MEM_WRITE( ARG1, sizeof(struct vki_utsname) );
1711 #endif
1713 // SYS_sysarch 165
1714 // x86/amd64
1716 // SYS_rtprio 166
1717 PRE(sys_rtprio)
1719 PRINT( "sys_rtprio ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1, ARG2, ARG3 );
1720 PRE_REG_READ3(int, "rtprio",
1721 int, function, pid_t, pid, struct rtprio *, rtp);
1722 if (ARG1 == VKI_RTP_SET) {
1723 PRE_MEM_READ( "rtprio(rtp#set)", ARG3, sizeof(struct vki_rtprio));
1724 } else if (ARG1 == VKI_RTP_LOOKUP) {
1725 PRE_MEM_WRITE( "rtprio(rtp#lookup)", ARG3, sizeof(struct vki_rtprio));
1726 } else {
1727 /* PHK ?? */
1731 POST(sys_rtprio)
1733 if (ARG1 == VKI_RTP_LOOKUP && RES == 0) {
1734 POST_MEM_WRITE( ARG3, sizeof(struct vki_rtprio));
1738 // freebsd6_pread 173 FREEBSD_VERS <= 10
1739 // x86/amd64
1741 // freebsd6_pwrite 174 FREEBSD_VERS <= 10
1742 // x86/amd64
1744 // SYS_setfib 175
1745 // int setfib(int fib);
1746 PRE(sys_setfib)
1748 PRINT("sys_setfib ( %" FMT_REGWORD "d )", SARG1);
1749 PRE_REG_READ1(int, "setfib", int, fib);
1752 // SYS_ntp_adjtime 176
1753 // int ntp_adjtime(struct timex *);
1754 // @todo
1756 // SYS_setgid 181
1757 // generic
1759 // SYS_setegid 182
1760 // int setegid(gid_t egid);
1761 PRE(sys_setegid)
1763 PRINT("sys_setegid ( %" FMT_REGWORD "u )", ARG1);
1764 PRE_REG_READ1(int, "setegid", vki_gid_t, gid);
1767 // SYS_seteuid 183
1768 // int seteuid(uid_t euid);
1769 PRE(sys_seteuid)
1771 PRINT("sys_seteuid ( %" FMT_REGWORD "u )", ARG1);
1772 PRE_REG_READ1(long, "seteuid", vki_uid_t, uid);
1776 #if (FREEBSD_VERS >= FREEBSD_12)
1778 // SYS_freebsd11_stat 188
1779 // int stat(char *path, struct freebsd11_stat *sb);
1780 PRE(sys_freebsd11_stat)
1782 PRINT("sys_freebsd11_stat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1783 PRE_REG_READ2(int, "stat", char *, path, struct freebsd11_stat *, sb);
1784 PRE_MEM_RASCIIZ( "stat(path)", ARG1 );
1785 PRE_MEM_WRITE( "stat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1788 POST(sys_freebsd11_stat)
1790 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1793 // SYS_freebsd11_fstat 189
1794 // int fstat(int fd, struct stat *sb);
1795 PRE(sys_freebsd11_fstat)
1797 PRINT("sys_freebsd11_fstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
1798 PRE_REG_READ2(int, "fstat", int, fd, struct stat *, sb);
1799 PRE_MEM_WRITE( "fstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1802 POST(sys_freebsd11_fstat)
1804 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1807 // SYS_freebsd11_lstat 190
1808 // int lstat(const char * restrict path, struct stat * restrict sb);
1809 PRE(sys_freebsd11_lstat)
1811 PRINT("sys_freebsd11_lstat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1812 PRE_REG_READ2(sb, "lstat", const char *, path, struct freebsd11_stat *, sb);
1813 PRE_MEM_RASCIIZ( "lstat(path)", ARG1 );
1814 PRE_MEM_WRITE( "lstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1817 POST(sys_freebsd11_lstat)
1819 vg_assert(SUCCESS);
1820 if (RES == 0) {
1821 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1825 #else
1827 PRE(sys_stat)
1829 PRINT("sys_stat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1830 PRE_REG_READ2(int, "stat", char *, path, struct stat *, sb);
1831 PRE_MEM_RASCIIZ( "stat(path)", ARG1 );
1832 PRE_MEM_WRITE( "stat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1835 POST(sys_stat)
1837 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1841 PRE(sys_fstat)
1843 PRINT("sys_fstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
1844 PRE_REG_READ2(int, "fstat", int, fd, struct stat *, sb);
1845 PRE_MEM_WRITE( "fstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1848 POST(sys_fstat)
1850 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1853 PRE(sys_lstat)
1855 PRINT("sys_lstat ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
1856 PRE_REG_READ2(int, "lstat", const char *, path, struct stat *, sb);
1857 PRE_MEM_RASCIIZ( "lstat(path)", ARG1 );
1858 PRE_MEM_WRITE( "lstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
1861 POST(sys_lstat)
1863 vg_assert(SUCCESS);
1864 if (RES == 0) {
1865 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
1869 #endif
1871 // SYS_pathconf 191
1872 // long pathconf(const char *path, int name);
1873 PRE(sys_pathconf)
1875 PRINT("sys_pathconf ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )",ARG1,(char *)ARG1,ARG2);
1876 PRE_REG_READ2(long, "pathconf", char *, path, int, name);
1877 PRE_MEM_RASCIIZ( "pathconf(path)", ARG1 );
1880 // SYS_fpathconf 192
1881 // long fpathconf(int fd, int name);
1882 PRE(sys_fpathconf)
1884 PRINT("sys_fpathconf ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2);
1885 PRE_REG_READ2(long, "fpathconf", int, fd, int, name);
1888 // SYS_getrlimit 194
1889 // generic
1891 // SYS_setrlimit 195
1892 // generic
1895 // SYS_freebsd11_getdirentries 196
1896 // int getdirentries(int fd, char *buf, int nbytes, long *basep);
1897 #if (FREEBSD_VERS >= FREEBSD_12)
1898 PRE(sys_freebsd11_getdirentries)
1900 *flags |= SfMayBlock;
1901 PRINT("sys_freebsd11_getdirentries ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
1902 PRE_REG_READ4(int, "getdirentries",
1903 int, fd, char *, buf,
1904 int, nbytes,
1905 long *, basep);
1906 PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 );
1907 if (ARG4) {
1908 PRE_MEM_WRITE( "getdirentries(basep)", ARG4, sizeof(long) );
1912 POST(sys_freebsd11_getdirentries)
1914 vg_assert(SUCCESS);
1915 if (RES > 0) {
1916 POST_MEM_WRITE( ARG2, RES );
1917 if ( ARG4 != 0 ) {
1918 POST_MEM_WRITE( ARG4, sizeof (long));
1922 #else
1923 PRE(sys_getdirentries)
1925 *flags |= SfMayBlock;
1926 PRINT("sys_getdirentries ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
1927 PRE_REG_READ4(int, "getdirentries",
1928 int, fd, char *, buf,
1929 int, nbytes,
1930 long *, basep);
1931 PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 );
1932 if (ARG4)
1933 PRE_MEM_WRITE( "getdirentries(basep)", ARG4, sizeof(long) );
1936 POST(sys_getdirentries)
1938 vg_assert(SUCCESS);
1939 if (RES > 0) {
1940 POST_MEM_WRITE( ARG2, RES );
1941 if ( ARG4 != 0 )
1942 POST_MEM_WRITE( ARG4, sizeof (long));
1945 #endif
1947 // SYS_freebsd6_mmap 197
1948 // amd64 / x86
1951 // SYS___syscall 198
1952 // special handling
1954 // freebsd6_lseek 199 FREEBSD_VERS <= 10
1955 // x86/amd64
1957 // freebsd6_truncate 200 FREEBSD_VERS <= 10
1958 // x86/amd64
1960 // freebsd6_ftruncate 201 FREEBSD_VERS <= 10
1961 // x86/amd64
1963 static Bool sysctl_kern_ps_strings(SizeT* out, SizeT* outlen)
1965 Word tmp = -1;
1966 const struct auxv *cauxv;
1968 for (cauxv = (struct auxv*)VG_(client_auxv); cauxv->a_type != VKI_AT_NULL; cauxv++) {
1969 if (cauxv->a_type == VKI_AT_PS_STRINGS) {
1970 tmp = (Word)cauxv->u.a_ptr;
1972 *out = tmp;
1973 *outlen = sizeof(size_t);
1974 return True;
1977 return False;
1980 static void sysctl_kern_usrstack(SizeT* out, SizeT* outlen)
1982 *out = VG_(get_usrstack)();
1983 *outlen = sizeof(ULong);
1986 static Bool sysctl_kern_proc_pathname(HChar *out, SizeT *len)
1988 const HChar *exe_name = VG_(resolved_exename);
1990 if (!len) {
1991 return False;
1994 if (!out) {
1995 HChar tmp[VKI_PATH_MAX];
1996 if (!VG_(realpath)(exe_name, tmp)) {
1997 return False;
1999 *len = VG_(strlen)(tmp)+1;
2000 return True;
2003 if (!VG_(realpath)(exe_name, out)) {
2004 return False;
2007 *len = VG_(strlen)(out)+1;
2008 return True;
2011 // SYS___sysctl 202
2012 /* int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen); */
2013 /* ARG1 ARG2 ARG3 ARG4 ARG5 ARG6 */
2014 PRE(sys___sysctl)
2016 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 );
2018 int* name = (int*)ARG1;
2019 if (ML_(safe_to_deref)(name, sizeof(int))) {
2020 PRINT("\nmib[0]: ");
2021 if (SARG2 >= 1) {
2022 switch (name[0]) {
2023 case 0: // CTL_UNSPEC
2024 PRINT("unspec");
2025 break;
2026 case 1: // CTL_KERN
2027 PRINT("kern");
2028 break;
2029 case 2: // CTL_VM
2030 PRINT("vm");
2031 break;
2032 case 3: // CTL_VFS
2033 PRINT("vfs");
2034 break;
2035 case 4: // CTL_NET
2036 PRINT("net");
2037 break;
2038 case 5: // CTL_DEBUG
2039 PRINT("debug");
2040 break;
2041 case 6: // CTL_HW
2042 PRINT("hw");
2043 break;
2044 case 7: // CTL_MACHDEP
2045 PRINT("machdep");
2046 break;
2047 case 8: // CTL _USER
2048 PRINT("user");
2049 break;
2050 case 9: //CTL_P1003_1B
2051 PRINT("p1003_b1b");
2052 break;
2053 default:
2054 PRINT("unrecognized (%d)", ((int*)ARG1)[0]);
2055 break;
2058 if (SARG2 >= 2 && ML_(safe_to_deref)(name, 2*sizeof(int))) {
2059 PRINT(" mib[1]: %d\n", name[1]);
2064 * Special handling cases
2066 * 1. kern.usrstack
2067 * This sysctl returns the address of the bottom of the user stack
2068 * (that is the highest user stack address, since the stack grows
2069 * downwards). Without any special handling this would return the
2070 * address of the host userstack. We have created a stack for the
2071 * guest (in aspacemgr) and that is the one that we want the guest
2072 * to see. Aspacemgr is setup in m_main.c with the adresses and sizes
2073 * saved to file static variables in that file, so we call
2074 * VG_(get_usrstack)() to retrieve them from there.
2076 if (SARG2 == 2 && ML_(safe_to_deref)(name, 2*sizeof(int))) {
2077 if (name[0] == 1 && name[1] == 33) {
2078 // kern.usrstack
2079 sysctl_kern_usrstack((SizeT*)ARG3, (SizeT*)ARG4);
2080 SET_STATUS_Success(0);
2085 * 2. kern.ps_strings
2087 if (SARG2 == 2 && ML_(safe_to_deref)(name, 2*sizeof(int))) {
2088 if (name[0] == 1 && name[1] == 32) {
2089 if (sysctl_kern_ps_strings((SizeT*)ARG3, (SizeT*)ARG4)) {
2090 SET_STATUS_Success(0);
2096 * 3. kern.proc.pathname
2098 if (SARG2 == 4 && ML_(safe_to_deref)(name, 4*sizeof(int))) {
2099 if (name[0] == 1 && name[1] == 14 && name[2] == 12) {
2100 vki_pid_t pid = (vki_pid_t)name[3];
2101 if (pid == -1 || pid == VG_(getpid)()) {
2102 sysctl_kern_proc_pathname((HChar *)ARG3, (SizeT *)ARG4);
2103 SET_STATUS_Success(0);
2108 PRE_REG_READ6(int, "__sysctl", int *, name, vki_u_int32_t, namelen, void *, oldp,
2109 vki_size_t *, oldlenp, void *, newp, vki_size_t, newlen);
2111 // read number of ints specified in ARG2 from mem pointed to by ARG1
2112 PRE_MEM_READ("sysctl(name)", (Addr)ARG1, ARG2 * sizeof(int));
2114 // if 'newp' is not NULL can read namelen bytes from that address
2115 if (ARG5 != (UWord)NULL) {
2116 PRE_MEM_READ("sysctl(newp)", (Addr)ARG5, ARG6);
2119 // there are two scenarios for oldlenp/oldp
2120 // 1. oldval is NULL and oldlenp is non-NULL
2121 // this is a query of oldlenp so oldlenp will be written
2122 // 2. Both are non-NULL
2123 // this is a query of oldp, oldlenp will be read and oldp will
2124 // be written
2126 // More thoughts on this
2127 // if say oldp is a string buffer
2128 // oldlenp will point to the length of the buffer
2130 // but on return does oldlenp also get updated?
2132 // is oldlenp is not NULL, can write
2133 if (ARG4 != (UWord)NULL) {
2134 if (ARG3 != (UWord)NULL) {
2135 // case 2 above
2136 PRE_MEM_READ("sysctl(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
2137 PRE_MEM_WRITE("sysctl(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
2138 if (ML_(safe_to_deref)((void*)(Addr)ARG4, sizeof(vki_size_t))) {
2139 PRE_MEM_WRITE("sysctl(oldp)", (Addr)ARG3, *(vki_size_t *)ARG4);
2140 } else {
2141 VG_(dmsg)("Warning: Bad oldlenp address %p in sysctl\n",
2142 (void *)(Addr)ARG4);
2143 SET_STATUS_Failure ( VKI_EFAULT );
2145 } else {
2146 // case 1 above
2147 PRE_MEM_WRITE("sysctl(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
2152 POST(sys___sysctl)
2154 if (ARG4 != (UWord)NULL) {
2155 if (ARG3 != (UWord)NULL) {
2156 POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
2157 POST_MEM_WRITE((Addr)ARG3, *(vki_size_t *)ARG4);
2158 } else {
2159 POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
2164 // SYS_mlock 203
2165 // generic
2167 // SYS_munlock 204
2168 // generic
2170 // SYS_undelete 205
2171 // int undelete(const char *path);
2172 PRE(sys_undelete)
2174 *flags |= SfMayBlock;
2175 PRINT("sys_undelete ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
2176 PRE_REG_READ1(int, "undelete", const char *, path);
2177 PRE_MEM_RASCIIZ( "undelete(path)", ARG1 );
2180 // SYS_futimes 206
2181 // int futimes(int fd, const struct timeval *times);
2182 PRE(sys_futimes)
2184 PRINT("sys_lutimes ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2185 PRE_REG_READ2(long, "futimes", int, fd, struct timeval *, times);
2186 if (ARG2 != 0) {
2187 PRE_MEM_READ( "futimes(times)", ARG2, sizeof(struct vki_timeval) );
2191 // SYS_getpgid 207
2192 // generic
2194 // SYS_poll 209
2195 // generic
2197 // SYS_freebsd7___semctl 220
2198 // int semctl(int semid, int semnum, int cmd, ...);
2199 PRE(sys_freebsd7___semctl)
2201 switch (ARG3) {
2202 case VKI_IPC_INFO:
2203 case VKI_SEM_INFO:
2204 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
2205 PRE_REG_READ4(int, "semctl",
2206 int, semid, int, semnum, int, cmd, struct seminfo *, arg);
2207 break;
2208 case VKI_IPC_STAT:
2209 case VKI_SEM_STAT:
2210 case VKI_IPC_SET:
2211 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
2212 PRE_REG_READ4(int, "semctl",
2213 int, semid, int, semnum, int, cmd, struct vki_semid_ds_old *, arg);
2214 break;
2215 case VKI_GETALL:
2216 case VKI_SETALL:
2217 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
2218 PRE_REG_READ4(int, "semctl",
2219 int, semid, int, semnum, int, cmd, unsigned short *, arg);
2220 break;
2221 default:
2222 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2223 PRE_REG_READ3(long, "semctl",
2224 int, semid, int, semnum, int, cmd);
2225 break;
2227 ML_(generic_PRE_sys_semctl)(tid, ARG1,ARG2,ARG3,ARG4);
2230 POST(sys_freebsd7___semctl)
2232 ML_(generic_POST_sys_semctl)(tid, RES,ARG1,ARG2,ARG3,ARG4);
2235 // SYS_semget 221
2236 // int semget(key_t key, int nsems, int flag);
2237 PRE(sys_semget)
2239 PRINT("sys_semget ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2240 PRE_REG_READ3(int, "semget", vki_key_t, key, int, nsems, int, flag);
2243 // SYS_semop 222
2244 // int semop(int semid, struct sembuf *array, size_t nops);
2245 PRE(sys_semop)
2247 *flags |= SfMayBlock;
2248 PRINT("sys_semop ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2249 PRE_REG_READ3(int, "semop",
2250 int, semid, struct sembuf *, array, unsigned, nops);
2251 ML_(generic_PRE_sys_semop)(tid, ARG1,ARG2,ARG3);
2254 // SYS_freebsd7_msgctl 224
2255 // int msgctl(int msqid, int cmd, struct msqid_ds_old *buf);
2256 PRE(sys_freebsd7_msgctl)
2258 PRINT("sys_freebsd7_msgctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3 );
2260 PRE_REG_READ3(int, "msgctl", int, msqid, int, cmd, struct msqid_ds_old *, buf);
2262 switch (ARG2 /* cmd */) {
2263 case VKI_IPC_STAT:
2264 PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)",
2265 ARG3, sizeof(struct vki_msqid_ds_old) );
2266 break;
2267 case VKI_IPC_SET:
2268 PRE_MEM_READ( "msgctl(IPC_SET, buf)",
2269 ARG3, sizeof(struct vki_msqid_ds_old) );
2270 break;
2274 POST(sys_freebsd7_msgctl)
2276 switch (ARG2 /* cmd */) {
2277 case VKI_IPC_STAT:
2278 POST_MEM_WRITE( ARG3, sizeof(struct vki_msqid_ds_old) );
2279 break;
2283 // SYS_msgget 225
2284 // int msgget(key_t key, int msgflg);
2285 PRE(sys_msgget)
2287 PRINT("sys_msgget ( %" FMT_REGWORD"d, %" FMT_REGWORD"d )",SARG1,SARG2);
2288 PRE_REG_READ2(int, "msgget", key_t, key, int, msgflg);
2291 // SYS_msgsnd 226
2292 // int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg);
2293 PRE(sys_msgsnd)
2295 PRINT("sys_msgsnd ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,ARG2,SARG3,SARG4 );
2296 PRE_REG_READ4(int, "msgsnd", int, msqid, struct msgbuf *, msgp, size_t, msgsz, int, msgflg);
2297 struct vki_msgbuf *msgp = (struct vki_msgbuf *)ARG2;
2298 PRE_MEM_READ( "msgsnd(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) );
2299 PRE_MEM_READ( "msgsnd(msgp->mtext)", (Addr)&msgp->mtext, ARG3 );
2301 // SYS_msgrcv 227
2302 // ssize_t msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int msgflg);
2303 PRE(sys_msgrcv)
2305 *flags |= SfMayBlock;
2307 PRINT("sys_msgrcv ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1,ARG2,ARG3,SARG4,SARG5 );
2308 PRE_REG_READ5(ssize_t, "msgrcv", int, msqid, struct msgbuf *, msgp, size_t, msgsz,
2309 long, msgtyp, int, msgflg);
2310 struct vki_msgbuf *msgp = (struct vki_msgbuf *)ARG2;
2311 PRE_MEM_WRITE( "msgrcv(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) );
2312 PRE_MEM_WRITE( "msgrcv(msgp->mtext)", (Addr)&msgp->mtext, ARG3 );
2315 POST(sys_msgrcv)
2317 struct vki_msgbuf *msgp = (struct vki_msgbuf *)ARG2;
2318 POST_MEM_WRITE( (Addr)&msgp->mtype, sizeof(msgp->mtype) );
2319 POST_MEM_WRITE( (Addr)&msgp->mtext, RES );
2322 // SYS_shmat 228
2323 // void * shmat(int shmid, const void *addr, int flag);
2324 PRE(sys_shmat)
2326 UWord arg2tmp;
2327 PRINT("sys_shmat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2328 PRE_REG_READ3(void *, "shmat",
2329 int, shmid, const void *, addr, int, flag);
2330 arg2tmp = ML_(generic_PRE_sys_shmat)(tid, ARG1,ARG2,ARG3);
2331 if (arg2tmp == 0) {
2332 SET_STATUS_Failure( VKI_EINVAL );
2333 } else {
2334 ARG2 = arg2tmp;
2338 POST(sys_shmat)
2340 ML_(generic_POST_sys_shmat)(tid, RES,ARG1,ARG2,ARG3);
2343 // SYS_freebsd7_shmctl 229
2344 // int shmctl(int shmid, int cmd, struct shmid_ds *buf);
2345 PRE(sys_freebsd7_shmctl)
2347 PRINT("sys_freebsd7_shmctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,SARG2,ARG3);
2348 PRE_REG_READ3(int, "shmctl",
2349 int, shmid, int, cmd, struct vki_shmid_ds_old *, buf);
2350 switch (ARG2 /* cmd */) {
2351 case VKI_IPC_STAT:
2352 PRE_MEM_WRITE( "shmctl7(IPC_STAT, buf)",
2353 ARG3, sizeof(struct vki_shmid_ds_old) );
2354 break;
2355 case VKI_IPC_SET:
2356 PRE_MEM_READ( "shmctl7(IPC_SET, buf)",
2357 ARG3, sizeof(struct vki_shmid_ds_old) );
2358 break;
2362 POST(sys_freebsd7_shmctl)
2364 if (ARG2 == VKI_IPC_STAT) {
2365 POST_MEM_WRITE( ARG3, sizeof(struct vki_shmid_ds_old) );
2369 // SYS_shmdt 230
2370 // int shmdt(const void *addr);
2371 PRE(sys_shmdt)
2373 PRINT("sys_shmdt ( %#" FMT_REGWORD "x )",ARG1);
2374 PRE_REG_READ1(int, "shmdt", const void *, addr);
2375 if (!ML_(generic_PRE_sys_shmdt)(tid, ARG1)) {
2376 SET_STATUS_Failure( VKI_EINVAL );
2380 POST(sys_shmdt)
2382 ML_(generic_POST_sys_shmdt)(tid, RES,ARG1);
2385 // SYS_shmget 231
2386 // int shmget(key_t key, size_t size, int flag);
2387 PRE(sys_shmget)
2389 PRINT("sys_shmget ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
2390 PRE_REG_READ3(int, "shmget", vki_key_t, key, vki_size_t, size, int, flag);
2394 // SYS_clock_gettime 232
2395 // int clock_gettime(clockid_t clock_id, struct timespec *tp);
2396 PRE(sys_clock_gettime)
2398 PRINT("sys_clock_gettime( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2399 PRE_REG_READ2(int, "clock_gettime",
2400 vki_clockid_t, clk_id, struct timespec *, tp);
2401 PRE_MEM_WRITE( "clock_gettime(tp)", ARG2, sizeof(struct vki_timespec) );
2404 POST(sys_clock_gettime)
2406 POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) );
2409 // SYS_clock_settime 233
2410 // int clock_settime(clockid_t clock_id, const struct timespec *tp);
2411 PRE(sys_clock_settime)
2413 PRINT("sys_clock_settime( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2414 PRE_REG_READ2(int, "clock_settime",
2415 vki_clockid_t, clk_id, const struct timespec *, tp);
2416 PRE_MEM_READ( "clock_settime(tp)", ARG2, sizeof(struct vki_timespec) );
2419 // SYS_clock_getres 234
2420 // int clock_getres(clockid_t clock_id, struct timespec *tp);
2421 PRE(sys_clock_getres)
2423 PRINT("sys_clock_getres( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2);
2424 // Nb: we can't use "RES" as the param name because that's a macro
2425 // defined above!
2426 PRE_REG_READ2(int, "clock_getres",
2427 vki_clockid_t, clock_id, struct timespec *, tp);
2428 if (ARG2 != 0) {
2429 PRE_MEM_WRITE( "clock_getres(tp)", ARG2, sizeof(struct vki_timespec) );
2433 POST(sys_clock_getres)
2435 if (ARG2 != 0) {
2436 POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) );
2440 // SYS_ktimer_create 235
2441 // int timer_create(clockid_t clockid, struct sigevent *restrict evp,
2442 // timer_t *restrict timerid);
2443 PRE(sys_timer_create)
2445 PRINT("sys_timer_create( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", SARG1,ARG2,ARG3);
2446 PRE_REG_READ3(int, "timer_create",
2447 vki_clockid_t, clockid, struct sigevent *, evp,
2448 vki_timer_t *, timerid);
2449 if (ARG2 != 0) {
2450 PRE_MEM_READ( "timer_create(evp)", ARG2, sizeof(struct vki_sigevent) );
2452 PRE_MEM_WRITE( "timer_create(timerid)", ARG3, sizeof(vki_timer_t) );
2455 POST(sys_timer_create)
2457 POST_MEM_WRITE( ARG3, sizeof(vki_timer_t) );
2460 // SYS_ktimer_delete 236
2461 // int timer_delete(timer_t timerid);
2462 PRE(sys_timer_delete)
2464 PRINT("sys_timer_delete( %#" FMT_REGWORD "x )", ARG1);
2465 PRE_REG_READ1(long, "timer_delete", vki_timer_t, timerid);
2468 // SYS_ktimer_settime 237
2469 // int timer_settime(timer_t timerid, int flags,
2470 // const struct itimerspec *restrict value,
2471 // struct itimerspec *restrict ovalue);
2472 PRE(sys_timer_settime)
2474 PRINT("sys_timer_settime( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3,ARG4);
2475 PRE_REG_READ4(int, "timer_settime",
2476 vki_timer_t, timerid, int, flags,
2477 const struct itimerspec *, value,
2478 struct itimerspec *, ovalue);
2479 PRE_MEM_READ( "timer_settime(value)", ARG3,
2480 sizeof(struct vki_itimerspec) );
2481 if (ARG4 != 0) {
2482 PRE_MEM_WRITE( "timer_settime(ovalue)", ARG4,
2483 sizeof(struct vki_itimerspec) );
2487 POST(sys_timer_settime)
2489 if (ARG4 != 0) {
2490 POST_MEM_WRITE( ARG4, sizeof(struct vki_itimerspec) );
2494 // SYS_ktimer_gettime 238
2495 // int timer_gettime(timer_t timerid, struct itimerspec *value);
2496 PRE(sys_timer_gettime)
2498 PRINT("sys_timer_gettime( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2);
2499 PRE_REG_READ2(long, "timer_gettime",
2500 vki_timer_t, timerid, struct itimerspec *, value);
2501 PRE_MEM_WRITE( "timer_gettime(value)", ARG2,
2502 sizeof(struct vki_itimerspec));
2505 POST(sys_timer_gettime)
2507 POST_MEM_WRITE( ARG2, sizeof(struct vki_itimerspec) );
2510 // SYS_ktimer_getoverrun 239
2511 // int timer_getoverrun(timer_t timerid);
2512 PRE(sys_timer_getoverrun)
2514 PRINT("sys_timer_getoverrun( %#" FMT_REGWORD "x )", ARG1);
2515 PRE_REG_READ1(int, "timer_getoverrun", vki_timer_t, timerid);
2518 // SYS_nanosleep 240
2519 // generic
2521 // SYS_ffclock_getcounter 241
2522 // int ffclock_getcounter(ffcounter *ffcount);
2523 // @todo
2525 // SYS_ffclock_setestimate 242
2526 // int ffclock_setestimate(struct ffclock_estimate *cest);
2527 // @todo
2529 // SYS_ffclock_getestimate 243
2530 // int ffclock_getestimate(struct ffclock_estimate *cest);
2531 // @todo
2533 // SYS_clock_nanosleep 244
2534 // int clock_nanosleep(clockid_t clock_id, int flags,
2535 // const struct timespec *rqtp, struct timespec *rmtp);
2536 PRE(sys_clock_nanosleep)
2538 *flags |= SfMayBlock|SfPostOnFail;
2539 PRINT("sys_clock_nanosleep ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
2540 SARG1, SARG2, ARG3, ARG4);
2541 PRE_REG_READ4(int, "clock_nanosleep", clockid_t, clock_id, int, flags,
2542 const struct timespec *, rqtp, struct timespec *, rmtp);
2543 PRE_MEM_READ("clock_nanosleep(rqtp)", ARG1, sizeof(struct vki_timespec));
2544 if (ARG2 != 0) {
2545 PRE_MEM_WRITE( "clock_nanosleep(rmtp)", ARG2, sizeof(struct vki_timespec) );
2549 POST(sys_clock_nanosleep)
2551 if (ARG2 != 0) {
2552 POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) );
2556 // SYS_clock_getcpuclockid2 247
2557 // x86/amd64
2559 POST(sys_clock_getcpuclockid2)
2561 POST_MEM_WRITE(ARG3, sizeof(vki_clockid_t));
2565 // SYS_ntp_gettime 248
2566 // int ntp_gettime(struct ntptimeval *);
2567 // @todo
2569 // SYS_minherit 250
2570 // int minherit(void *addr, size_t len, int inherit);
2571 PRE(sys_minherit)
2573 PRINT("sys_minherit( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
2574 PRE_REG_READ3(int, "minherit",
2575 void *, addr, vki_size_t, len, int, inherit);
2576 if (ARG2 != 0) {
2577 PRE_MEM_WRITE( "minherit(addr)", ARG1,ARG2 );
2581 POST(sys_minherit)
2583 if (ARG2 != 0) {
2584 POST_MEM_WRITE( ARG1, ARG2 );
2588 // SYS_rfork 251
2589 // x86/amd64 not functional
2591 // SYS_issetugid 253
2592 // int issetugid(void);
2593 PRE(sys_issetugid)
2595 PRINT("%s", "sys_issetugid ()");
2596 PRE_REG_READ0(long, "issetugid");
2599 // SYS_lchown 254
2600 // generic
2602 // SYS_aio_read 255
2603 // int aio_read(struct aiocb *iocb);
2604 PRE(sys_aio_read)
2606 PRINT("sys_aio_read ( %#" FMT_REGWORD "x )", ARG1);
2607 PRE_REG_READ1(int, "aio_read", struct vki_aiocb *, iocb);
2608 PRE_MEM_READ("aio_read(iocb)", ARG1, sizeof(struct vki_aiocb));
2609 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
2610 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
2611 PRE_MEM_WRITE( "aio_read(iocb->aio_offset)", (Addr)iocb, sizeof(struct vki_aiocb));
2615 POST(sys_aio_read)
2617 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
2618 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
2619 POST_MEM_WRITE((Addr)iocb, sizeof(struct vki_aiocb));
2623 // SYS_aio_write 256
2624 // int aio_write(struct aiocb *iocb);
2625 PRE(sys_aio_write)
2627 PRINT("sys_aio_write ( %#" FMT_REGWORD "x )", ARG1);
2628 PRE_REG_READ1(int, "aio_write", struct vki_aiocb *, iocb);
2629 PRE_MEM_READ("aio_read(iocb)", ARG1, sizeof(struct vki_aiocb));
2630 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
2631 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
2632 PRE_MEM_WRITE( "aio_write(iocb->aio_offset)", (Addr)iocb, sizeof(struct vki_aiocb));
2636 POST(sys_aio_write)
2638 if (ML_(safe_to_deref)((struct vki_aiocb *)ARG1, sizeof(struct vki_aiocb))) {
2639 struct vki_aiocb *iocb = (struct vki_aiocb *)ARG1;
2640 PRE_MEM_WRITE( "aio_write(iocb->aio_offset)", (Addr)iocb, sizeof(struct vki_aiocb));
2644 // SYS_lio_listio 257
2645 // int lio_listio(int mode, struct aiocb * const list[], int nent,
2646 // struct sigevent *sig);
2647 PRE(sys_lio_listio)
2649 PRINT("sys_lio_listio ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",
2650 SARG1, ARG2, SARG3, ARG4);
2651 PRE_REG_READ4(int, "lio_listio", int, mode, struct aiocb * const *, list, int, nent,
2652 struct sigevent *,sig);
2653 PRE_MEM_READ("lio_listio(list)", ARG2, ARG3*sizeof(struct vki_aiocb *));
2654 // loop check elements
2655 if (ML_(safe_to_deref)((struct vki_aiocb **)ARG2, ARG3*sizeof(struct vki_aiocb *))) {
2656 struct vki_aiocb** list = (struct vki_aiocb **)ARG2;
2657 for (int i = 0; i < (int)ARG3; ++i) {
2658 if (list[i]) {
2659 PRE_MEM_READ("lio_listio(list[?])", (Addr)list[i], ARG3*sizeof(struct vki_aiocb));
2661 // @todo
2662 // figure out what gets read/written
2663 // when list[i]->aio_lio_opcode == VKI_LIO_READ and
2664 // when list[i]->aio_lio_opcode == VKI_LIO_WRITE
2665 //if (ML_(safe_to_deref)(list[i], ARG3*sizeof(struct vki_aiocb))) {
2670 if (ARG1 & VKI_LIO_WAIT) {
2671 *flags |= SfMayBlock;
2674 if (ARG4 && (ARG1 == VKI_LIO_NOWAIT)) {
2675 PRE_MEM_READ("lio_listio(sig)", ARG4, sizeof(struct vki_sigevent));
2679 // SYS_freebsd11_getdents 272
2680 // generic
2682 // SYS_lchmod 274
2683 // int lchmod(const char *path, mode_t mode);
2684 PRE(sys_lchmod)
2686 PRINT("sys_lchmod ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char *)ARG1,ARG2);
2687 PRE_REG_READ2(int, "lchmod", const char *, path, vki_mode_t, mode);
2688 PRE_MEM_RASCIIZ( "lchmod(path)", ARG1 );
2691 // SYS_lutimes 276
2692 // int lutimes(const char *path, const struct timeval *times);
2693 PRE(sys_lutimes)
2695 PRINT("sys_lutimes ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2);
2696 PRE_REG_READ2(int, "lutimes", char *, path, struct timeval *, times);
2697 PRE_MEM_RASCIIZ( "lutimes(path)", ARG1 );
2698 if (ARG2 != 0) {
2699 PRE_MEM_READ( "lutimes(times)", ARG2, sizeof(struct vki_timeval) );
2703 // SYS_freebsd11_nstat 278
2704 // @todo, maybe
2706 // SYS_freebsd11_nfstat 279
2707 // @todo, maybe
2709 // SYS_freebsd11_nlstat 280
2710 // @todo, maybe
2712 // SYS_preadv 289
2713 // amd64 / x86
2715 // SYS_pwritev 290
2716 // amd64 / x86
2718 // SYS_fhopen 298
2719 // int fhopen(const fhandle_t *fhp, int flags);
2720 PRE(sys_fhopen)
2722 PRINT("sys_open ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",ARG1,ARG2);
2723 PRE_REG_READ2(int, "fhopen",
2724 struct fhandle_t *, fhp, int, flags);
2725 PRE_MEM_READ( "fhopen(fhp)", ARG1, sizeof(struct vki_fhandle) );
2727 /* Otherwise handle normally */
2728 *flags |= SfMayBlock;
2731 POST(sys_fhopen)
2733 vg_assert(SUCCESS);
2734 if (!ML_(fd_allowed)(RES, "fhopen", tid, True)) {
2735 VG_(close)(RES);
2736 SET_STATUS_Failure( VKI_EMFILE );
2737 } else {
2738 if (VG_(clo_track_fds)) {
2739 ML_(record_fd_open_nameless)(tid, RES);
2744 // SYS_freebsd11_fhstat 299
2745 // int fhstat(const fhandle_t *fhp, struct stat *sb);
2746 #if (FREEBSD_VERS >= FREEBSD_12)
2747 PRE(sys_freebsd11_fhstat)
2749 PRINT("sys_freebsd11_fhstat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
2750 PRE_REG_READ2(int, "fhstat", struct fhandle *, fhp, struct freebd11_stat *, sb);
2751 PRE_MEM_READ( "fhstat(fhp)", ARG1, sizeof(struct vki_fhandle) );
2752 PRE_MEM_WRITE( "fhstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
2755 POST(sys_freebsd11_fhstat)
2757 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
2759 #else
2760 PRE(sys_fhstat)
2762 PRINT("sys_fhstat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
2763 PRE_REG_READ2(int, "fhstat", struct fhandle *, fhp, struct stat *, sb);
2764 PRE_MEM_READ( "fhstat(fhp)", ARG1, sizeof(struct vki_fhandle) );
2765 PRE_MEM_WRITE( "fhstat(sb)", ARG2, sizeof(struct vki_freebsd11_stat) );
2768 POST(sys_fhstat)
2770 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_stat) );
2773 #endif
2775 // SYS_modnext 300
2776 // int modnext(int modid);
2777 PRE(sys_modnext)
2779 PRINT("sys_modnext ( %" FMT_REGWORD "d )",SARG1);
2780 PRE_REG_READ1(int, "modnext", int, modid);
2783 // SYS_modstat 301
2784 // int modstat(int modid, struct module_stat *stat);
2785 PRE(sys_modstat)
2787 PRINT("sys_modstat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2);
2788 PRE_REG_READ2(int, "modstat", int, modid, struct module_stat *, buf);
2789 PRE_MEM_WRITE( "modstat(stat)", ARG2, sizeof(struct vki_module_stat) );
2792 POST(sys_modstat)
2794 POST_MEM_WRITE( ARG2, sizeof(struct vki_module_stat) );
2797 // SYS_modfnext 302
2798 // int modfnext(int modid);
2799 PRE(sys_modfnext)
2801 PRINT("sys_modfnext ( %" FMT_REGWORD "d )",SARG1);
2802 PRE_REG_READ1(int, "modfnext", int, modid);
2805 // SYS_modfind 303
2806 // int modfind(const char *modname);
2807 PRE(sys_modfind)
2809 PRINT("sys_modfind ( %#" FMT_REGWORD "x )",ARG1);
2810 PRE_REG_READ1(long, "modfind", char *, modname);
2811 PRE_MEM_RASCIIZ( "modfind(modname)", ARG1 );
2814 // SYS_kldload 304
2815 // int kldload(const char *file);
2816 PRE(sys_kldload)
2818 PRINT("sys_kldload ( %#" FMT_REGWORD "x(%s) )", ARG1, (char *)ARG1);
2819 PRE_REG_READ1(int, "kldload", const char *, "file");
2820 PRE_MEM_RASCIIZ( "kldload(file)", ARG1 );
2823 // SYS_kldunload 305
2824 // int kldunload(int fileid);
2825 PRE(sys_kldunload)
2827 PRINT("sys_kldunload ( %" FMT_REGWORD "u )", ARG1);
2828 PRE_REG_READ1(int, "kldunload", int, "fileid");
2831 // SYS_kldfind 306
2832 // int kldfind(const char *file);
2833 PRE(sys_kldfind)
2835 PRINT("sys_kldfind ( %#" FMT_REGWORD "x(%s) )", ARG1, (char *)ARG1);
2836 PRE_REG_READ1(int, "kldfind", const char *, file);
2837 PRE_MEM_RASCIIZ( "kldfind(file)", ARG1 );
2840 // SYS_kldnext 307
2841 // int kldnext(int fileid);
2842 PRE(sys_kldnext)
2844 PRINT("sys_kldnext ( %" FMT_REGWORD "u )", ARG1);
2845 PRE_REG_READ1(int, "kldnext", int, fileid);
2848 // SYS_kldstat 308
2849 // int kldstat(int fileid, struct kld_file_stat *stat);
2850 PRE(sys_kldstat)
2852 PRINT("sys_kldstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
2853 PRE_REG_READ2(int, "kldstat", int, fileid, struct kld_file_stat*, stat);
2854 PRE_MEM_WRITE("kldstat(stat)", ARG2, sizeof(struct vki_kld_file_stat));
2857 POST(sys_kldstat)
2859 POST_MEM_WRITE(ARG2, sizeof(struct vki_kld_file_stat));
2862 // SYS_kldfirstmod 309
2863 // int kldfirstmod(int fileid);
2864 PRE(sys_kldfirstmod)
2866 PRINT("sys_kldfirstmod ( %" FMT_REGWORD "u )", ARG1);
2867 PRE_REG_READ1(int, "kldfirstmod", int, fileid);
2870 // SYS_setresuid 311
2871 // int setresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
2872 PRE(sys_setresuid)
2874 PRINT("sys_setresuid ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
2875 PRE_REG_READ3(int, "setresuid",
2876 vki_uid_t, ruid, vki_uid_t, euid, vki_uid_t, suid);
2879 // SYS_setresgid 312
2880 // int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
2881 PRE(sys_setresgid)
2883 PRINT("sys_setresgid ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
2884 PRE_REG_READ3(int, "setresgid",
2885 vki_gid_t, rgid, vki_gid_t, egid, vki_gid_t, sgid);
2888 // SYS_aio_return 314
2889 // ssize_t aio_return(struct aiocb *iocb);
2890 PRE(sys_aio_return)
2892 PRINT("sys_aio_return ( %#" FMT_REGWORD "x )", ARG1);
2893 PRE_REG_READ1(ssize_t, "aio_return", struct aiocb *, iocb);
2894 // not too clear if this is read-only, sounds like it from the man page
2895 // but it isn't const
2896 PRE_MEM_READ("aio_return(iocb)", ARG1, sizeof(struct vki_aiocb));
2899 // SYS_aio_suspend 315
2900 // int aio_suspend(const struct aiocb *const iocbs[], int niocb,
2901 // const struct timespec *timeout);
2902 PRE(sys_aio_suspend)
2904 PRINT("sys_aio_suspend ( %#" FMT_REGWORD "x )", ARG1);
2905 PRE_REG_READ3(int, "aio_suspend", struct aiocb **, iocbs, int, nbiocb, const struct timespec*, timeout);
2906 PRE_MEM_READ("aio_suspend(iocbs)", ARG1, ARG2*sizeof(struct vki_aiocb));
2907 PRE_MEM_READ("aio_suspend(timeout)", ARG3, sizeof(struct vki_timespec));
2910 // SYS_aio_cancel 316
2911 // int aio_cancel(int fildes, struct aiocb *iocb);
2912 PRE(sys_aio_cancel)
2914 PRINT("sys_aio_cancel ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
2915 PRE_REG_READ2(int, "aio_cancel", int, fildex, struct aiocb *, iocb);
2916 if (ARG2) {
2917 PRE_MEM_READ("aio_cancel(iocb)", ARG2, sizeof(struct vki_aiocb));
2921 // SYS_aio_error 317
2922 // int aio_error(const struct aiocb *iocb);
2923 PRE(sys_aio_error)
2925 PRINT("sys_aio_error ( %#" FMT_REGWORD "x )", ARG1);
2926 PRE_REG_READ1(ssize_t, "aio_error", struct aiocb *, iocb);
2927 PRE_MEM_READ("aio_error(iocb)", ARG1, sizeof(struct vki_aiocb));
2930 // SYS_yield 321
2931 int yield(void);
2932 PRE(sys_yield)
2934 *flags |= SfMayBlock;
2935 PRINT("%s", "yield()");
2936 PRE_REG_READ0(long, "yield");
2939 // SYS_mlockall 324
2940 // generic
2942 // SYS_munlockall 325
2943 // int munlockall(void);
2944 PRE(sys_munlockall)
2946 *flags |= SfMayBlock;
2947 PRINT("%s", "sys_munlockall ( )");
2948 PRE_REG_READ0(int, "munlockall");
2951 // SYS___getcwd 326
2952 // int __getcwd(char *buf, size_t buflen);
2953 PRE(sys___getcwd)
2955 PRINT("sys___getcwd ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2);
2956 PRE_REG_READ2(long, "__getcwd", char *, buf, unsigned int, buflen);
2957 PRE_MEM_WRITE( "__getcwd(buf)", ARG1, ARG2 );
2960 POST(sys___getcwd)
2962 vg_assert(SUCCESS);
2963 if (RES == 0) {
2964 // QQQ it is unclear if this is legal or not, but the
2965 // QQQ kernel just wrote it there...
2966 // QQQ Why oh why didn't phk return the length from __getcwd()?
2967 UInt len = VG_(strlen) ( (char *)ARG1 ) + 1;
2968 POST_MEM_WRITE( ARG1, len );
2972 //SYS_sched_setparam 327
2973 // int sched_setparam(pid_t pid, const struct sched_param *param);
2974 PRE(sys_sched_setparam)
2976 PRINT("sched_setparam ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2 );
2977 PRE_REG_READ2(int, "sched_setparam",
2978 vki_pid_t, pid, struct sched_param *, param);
2979 PRE_MEM_READ( "sched_setparam(param)", ARG2, sizeof(struct vki_sched_param) );
2982 POST(sys_sched_setparam)
2984 POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) );
2987 // SYS_sched_getparam 328
2988 // int sched_getparam(pid_t pid, struct sched_param *param);
2989 PRE(sys_sched_getparam)
2991 PRINT("sched_getparam ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2 );
2992 PRE_REG_READ2(int, "sched_getparam",
2993 vki_pid_t, pid, struct sched_param *, param);
2994 PRE_MEM_WRITE( "sched_getparam(param)", ARG2, sizeof(struct vki_sched_param) );
2997 POST(sys_sched_getparam)
2999 POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) );
3002 // SYS_sched_setscheduler 329
3003 // int sched_setscheduler(pid_t pid, int policy,
3004 // const struct sched_param *param);
3005 PRE(sys_sched_setscheduler)
3007 PRINT("sys_sched_setscheduler ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3);
3008 PRE_REG_READ3(int, "sched_setscheduler",
3009 vki_pid_t, pid, int, policy, struct sched_param *, param);
3010 if (ARG3 != 0) {
3011 PRE_MEM_READ("sched_setscheduler(param)",
3012 ARG3, sizeof(struct vki_sched_param));
3016 // SYS_sched_getscheduler 330
3017 // int sched_getscheduler(pid_t pid);
3018 PRE(sys_sched_getscheduler)
3020 PRINT("sys_sched_getscheduler ( %" FMT_REGWORD "d )", SARG1);
3021 PRE_REG_READ1(int, "sched_getscheduler", vki_pid_t, pid);
3024 // SYS_sched_yield 331
3025 // int sched_yield(void);
3026 PRE(sys_sched_yield)
3028 *flags |= SfMayBlock;
3029 PRINT("sched_yield()");
3030 PRE_REG_READ0(int, "sched_yield");
3033 // SYS_sched_get_priority_max 332
3034 // int sched_get_priority_max(int policy);
3035 PRE(sys_sched_get_priority_max)
3037 PRINT("sched_get_priority_max ( %" FMT_REGWORD "u )", ARG1);
3038 PRE_REG_READ1(long, "sched_get_priority_max", int, policy);
3041 // SYS_sched_get_priority_min 333
3042 // int sched_get_priority_min(int policy);
3043 PRE(sys_sched_get_priority_min)
3045 PRINT("sched_get_priority_min ( %" FMT_REGWORD "u )", ARG1);
3046 PRE_REG_READ1(long, "sched_get_priority_min", int, policy);
3049 // SYS_sched_rr_get_interval 334
3050 // int sched_rr_get_interval(pid_t pid, struct timespec *interval);
3051 PRE(sys_sched_rr_get_interval)
3053 PRINT("sys_sched_rr_get_interval ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
3054 PRE_REG_READ2(int, "sched_rr_get_interval", vki_pid_t, pid, struct vki_timespec *,interval);
3055 PRE_MEM_WRITE("sys_sched_rr_get_interval(interval)", ARG2, sizeof(struct vki_timespec));
3058 POST(sys_sched_rr_get_interval)
3060 POST_MEM_WRITE(ARG2, sizeof(struct vki_timespec));
3063 // SYS_utrace 335
3064 // int utrace(const void *addr, size_t len);
3065 PRE(sys_utrace)
3067 PRINT("sys_utrace ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
3068 PRE_REG_READ2(int, "utrace", const void *, addr, vki_size_t, len);
3069 PRE_MEM_READ( "utrace(addr)", ARG2, ARG3 );
3072 // SYS_kldsym 337
3073 // int kldsym(int fileid, int cmd, void *data);
3074 PRE(sys_kldsym)
3076 PRINT("sys_kldsym ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3 );
3077 PRE_REG_READ3(int, "kldsym", int, fileid, int, cmd, void*, data);
3078 PRE_MEM_READ( "kldsym(data)", ARG3, sizeof(struct vki_kld_sym_lookup) );
3079 struct vki_kld_sym_lookup *kslp = (struct vki_kld_sym_lookup *)ARG3;
3080 if (ML_(safe_to_deref)(kslp, sizeof(struct vki_kld_sym_lookup))) {
3081 PRE_MEM_RASCIIZ( "kldsym(data.symname)", (Addr)kslp->symname );
3085 POST(sys_kldsym)
3087 struct vki_kld_sym_lookup *kslp = (struct vki_kld_sym_lookup *)ARG3;
3088 POST_MEM_WRITE( (Addr)&kslp->symvalue, sizeof(kslp->symvalue) );
3089 POST_MEM_WRITE( (Addr)&kslp->symsize, sizeof(kslp->symsize) );
3092 // SYS_jail 338
3093 // int jail(struct jail *jail);
3094 PRE(sys_jail)
3096 PRINT("sys_jail ( %#" FMT_REGWORD "x )", ARG1);
3097 PRE_REG_READ1(int, "jail", struct jail *, jail);
3098 PRE_MEM_READ( "jail(jail)", ARG1, sizeof(struct vki_jail) );
3101 // SYS_nnpfs_syscall 338
3102 // @todo
3104 // SYS_sigprocmask 340
3105 // int sigprocmask(int how, const sigset_t * restrict set,
3106 // sigset_t * restrict oset);
3107 PRE(sys_sigprocmask)
3109 PRINT("sys_sigprocmask ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3);
3110 PRE_REG_READ3(int, "sigprocmask",
3111 int, how, vki_sigset_t *, set, vki_sigset_t *, oset);
3112 if (ARG2 != 0) {
3113 PRE_MEM_READ( "sigprocmask(set)", ARG2, sizeof(vki_sigset_t));
3115 if (ARG3 != 0) {
3116 PRE_MEM_WRITE( "sigprocmask(oset)", ARG3, sizeof(vki_sigset_t));
3119 if (ARG2 != 0 &&
3120 !ML_(safe_to_deref)((void *)(Addr)ARG2, sizeof(vki_sigset_t))) {
3121 VG_(dmsg)("Warning: Bad set handler address %p in sigprocmask\n",
3122 (void *)(Addr)ARG2);
3123 SET_STATUS_Failure ( VKI_EFAULT );
3124 } else if (ARG3 != 0 &&
3125 !ML_(safe_to_deref)((void *)(Addr)ARG3, sizeof(vki_sigset_t))) {
3126 VG_(dmsg)("Warning: Bad oldset address %p in sigprocmask\n",
3127 (void *)(Addr)ARG3);
3128 SET_STATUS_Failure ( VKI_EFAULT );
3129 } else {
3130 SET_STATUS_from_SysRes(VG_(do_sys_sigprocmask)(tid, ARG1 /*how*/,
3131 (vki_sigset_t*)(Addr)ARG2,
3132 (vki_sigset_t*)(Addr)ARG3));
3135 if (SUCCESS) {
3136 *flags |= SfPollAfter;
3140 POST(sys_sigprocmask)
3142 vg_assert(SUCCESS);
3143 if (RES == 0 && ARG3 != 0) {
3144 POST_MEM_WRITE( ARG3, sizeof(vki_sigset_t));
3148 // SYS_sigsuspend 341
3149 // int sigsuspend(const sigset_t *sigmask);
3150 PRE(sys_sigsuspend)
3152 *flags |= SfMayBlock;
3153 PRINT("sys_sigsuspend ( %#" FMT_REGWORD "x )", ARG1 );
3154 PRE_REG_READ1(int, "sigsuspend", const vki_sigset_t *, sigmask);
3155 PRE_MEM_READ( "sigsuspend(sigmask)", ARG1, sizeof(vki_sigset_t) );
3156 if (ARG1) {
3157 ARG1 = ML_(make_safe_mask)("syswrap.sigsuspend.1", (Addr)ARG1);
3161 POST(sys_sigsuspend)
3163 ML_(free_safe_mask) ( (Addr)ARG1 );
3166 // SYS_sigpending 343
3167 // int sigpending(sigset_t *set);
3168 PRE(sys_sigpending)
3170 PRINT( "sys_sigpending ( %#" FMT_REGWORD "x )", ARG1 );
3171 PRE_REG_READ1(int, "sigpending", vki_sigset_t *, set);
3172 PRE_MEM_WRITE( "sigpending(set)", ARG1, sizeof(vki_sigset_t));
3175 POST(sys_sigpending)
3177 POST_MEM_WRITE( ARG1, sizeof(vki_sigset_t) ) ;
3181 // SYS_sigtimedwait 345
3182 // int sigtimedwait(const sigset_t *restrict set, siginfo_t *restrict info,
3183 // const struct timespec *restrict timeout);
3184 PRE(sys_sigtimedwait)
3186 *flags |= SfMayBlock;
3187 PRINT("sys_sigtimedwait ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
3188 ARG1,ARG2,ARG3);
3189 PRE_REG_READ3(int, "sigtimedwait",
3190 const vki_sigset_t *, set, vki_siginfo_t *, info,
3191 const struct timespec *, timeout);
3192 if (ARG1 != 0) {
3193 PRE_MEM_READ( "sigtimedwait(set)", ARG1, sizeof(vki_sigset_t));
3195 if (ARG2 != 0) {
3196 PRE_MEM_WRITE( "sigtimedwait(info)", ARG2, sizeof(vki_siginfo_t) );
3198 if (ARG3 != 0) {
3199 PRE_MEM_READ( "sigtimedwait(timeout)",
3200 ARG3, sizeof(struct vki_timespec) );
3204 POST(sys_sigtimedwait)
3206 if (ARG2 != 0) {
3207 POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) );
3211 // SYS_sigwaitinfo 346
3212 // int sigwaitinfo(const sigset_t * restrict set, siginfo_t * restrict info);
3213 PRE(sys_sigwaitinfo)
3215 *flags |= SfMayBlock;
3216 PRINT("sys_sigwaitinfo ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
3217 ARG1,ARG2);
3218 PRE_REG_READ2(int, "sigwaitinfo",
3219 const vki_sigset_t *, set, vki_siginfo_t *, info);
3220 if (ARG1 != 0) {
3221 PRE_MEM_READ( "sigwaitinfo(set)", ARG1, sizeof(vki_sigset_t));
3223 if (ARG2 != 0) {
3224 PRE_MEM_WRITE( "sigwaitinfo(info)", ARG2, sizeof(vki_siginfo_t) );
3228 POST(sys_sigwaitinfo)
3230 if (ARG2 != 0) {
3231 POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) );
3235 // SYS___acl_get_file 347
3236 // int __acl_get_file(const char *path, acl_type_t type, struct acl *aclp);
3237 PRE(sys___acl_get_file)
3239 PRINT("sys___acl_get_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
3240 PRE_REG_READ3(int, "acl_get_file",
3241 const char *, path, int, type, struct vki_acl *, aclp);
3242 PRE_MEM_RASCIIZ("acl_get_file(path", ARG1);
3243 PRE_MEM_WRITE( "acl_get_file(aclp)", ARG3, sizeof(struct vki_acl) );
3246 POST(sys___acl_get_file)
3248 vg_assert(SUCCESS);
3249 if (RES == 0) {
3250 POST_MEM_WRITE( ARG3, sizeof(struct vki_acl) );
3254 // SYS___acl_set_file 348
3255 // int __acl_set_file(const char *path, acl_type_t type, struct acl *aclp);
3256 PRE(sys___acl_set_file)
3258 PRINT("sys___acl_set_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
3259 PRE_REG_READ3(int, "acl_set_file",
3260 const char *, path, int, type, struct vki_acl *, aclp);
3261 PRE_MEM_RASCIIZ("acl_set_file(path", ARG1);
3262 PRE_MEM_READ("acl_set_file(aclp)", ARG3, sizeof(struct vki_acl) );
3265 // SYS___acl_get_fd 349
3266 // int __acl_get_fd(int filedes, acl_type_t type, struct acl *aclp);
3267 PRE(sys___acl_get_fd)
3269 PRINT("sys___acl_get_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3270 PRE_REG_READ3(int, "acl_get_fd",
3271 int, fd, int, type, struct vki_acl *, aclp);
3272 PRE_MEM_WRITE( "acl_get_file(aclp)", ARG3, sizeof(struct vki_acl) );
3275 POST(sys___acl_get_fd)
3277 vg_assert(SUCCESS);
3278 if (RES == 0) {
3279 POST_MEM_WRITE( ARG3, sizeof(struct vki_acl) );
3283 // SYS___acl_set_fd 350
3284 // int __acl_set_fd(int filedes, acl_type_t type, struct acl *aclp);
3285 PRE(sys___acl_set_fd)
3287 PRINT("sys___acl_set_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3288 PRE_REG_READ3(int, "acl_set_fd",
3289 int, filedes, int, type, struct vki_acl *, aclp);
3290 PRE_MEM_READ( "acl_get_file(aclp)", ARG3, sizeof(struct vki_acl) );
3293 // SYS___acl_delete_file 351
3294 // int __acl_delete_file(const char *path, acl_type_t type);
3295 PRE(sys___acl_delete_file)
3297 PRINT("sys___acl_delete_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char *)ARG1,ARG2);
3298 PRE_MEM_RASCIIZ("acl_set_file(path", ARG1);
3299 PRE_REG_READ2(int, "acl_delete_file",
3300 const char *, path, int, type);
3302 // SYS___acl_delete_fd 352
3303 // int __acl_delete_fd(int filedes, acl_type_t type);
3304 PRE(sys___acl_delete_fd)
3306 PRINT("sys___acl_delete_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2);
3307 PRE_REG_READ2(int, "acl_delete_fd",
3308 int, filedes, int, acltype);
3311 // SYS___acl_aclcheck_file 353
3312 // int __acl_aclcheck_file(const char *path, acl_type_t type, struct acl *aclp);
3313 PRE(sys___acl_aclcheck_file)
3315 PRINT("sys___acl_aclcheck_file ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
3316 PRE_REG_READ3(int, "acl_aclcheck_file",
3317 const char *, path, int, type, struct vki_acl *, aclp);
3318 PRE_MEM_RASCIIZ("acl_set_file(path", ARG1);
3319 PRE_MEM_READ( "acl_aclcheck_file(aclp)", ARG3, sizeof(struct vki_acl) );
3322 // SYS___acl_aclcheck_fd 354
3323 // int __acl_aclcheck_fd(int filedes, acl_type_t type, struct acl *aclp);
3324 PRE(sys___acl_aclcheck_fd)
3326 PRINT("sys___acl_aclcheck_fd ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3327 PRE_REG_READ3(int, "acl_aclcheck_fd",
3328 int, fd, int, type, struct vki_acl *, aclp);
3329 PRE_MEM_READ( "acl_aclcheck_fd(aclp)", ARG3, sizeof(struct vki_acl) );
3332 // SYS_extattrctl 355
3333 // no manpage?
3334 // syscalls.master: int extattrctl(_In_z_ const char *path, int cmd, _In_z_opt_ const char *filename, int attrnamespace, _In_z_ const char *attrname);
3335 PRE(sys_extattrctl)
3337 PRINT("sys_extattrctl ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3,SARG4,ARG5);
3338 PRE_REG_READ5(ssize_t, "extattrctl",
3339 const char *, path, int, cmd, const char *, filename, int, attrnamespace, const char *, attrname);
3340 PRE_MEM_RASCIIZ("extattrctl(path)", ARG1);
3341 PRE_MEM_RASCIIZ("extattrctl(filename)", ARG3);
3342 PRE_MEM_RASCIIZ("extattrctl(attrname)", ARG5);
3345 // SYS_extattr_set_file 356
3346 // ssize_t extattr_set_file(const char *path, int attrnamespace,
3347 // const char *attrname, const void *data, size_t nbytes);
3348 PRE(sys_extattr_set_file)
3350 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);
3351 PRE_REG_READ5(ssize_t, "extattr_set_file",
3352 const char *, path, int, attrnamespace, const char *, attrname, const void *, data, size_t, nbytes);
3353 PRE_MEM_RASCIIZ("extattr_set_file(path)", ARG1);
3354 PRE_MEM_RASCIIZ("extattr_set_file(attrname)", ARG3);
3355 PRE_MEM_READ("extattr_set_file(data)", ARG4, ARG5);
3358 // SYS_extattr_get_file 357
3359 // ssize_t extattr_get_file(const char *path, int attrnamespace,
3360 // const char *attrname, void *data, size_t nbytes);
3361 PRE(sys_extattr_get_file)
3363 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);
3364 PRE_REG_READ5(ssize_t, "extattr_get_file",
3365 const char *, path, int, attrnamespace, const char *, attrname, void *, data, size_t, nbytes);
3366 PRE_MEM_RASCIIZ("extattr_get_file(path)", ARG1);
3367 PRE_MEM_RASCIIZ("extattr_get_file(attrname)", ARG3);
3368 if (ARG4) {
3369 PRE_MEM_WRITE("extattr_get_file(data)", ARG4, ARG5);
3373 POST(sys_extattr_get_file)
3375 if (ARG4) {
3376 POST_MEM_WRITE(ARG4, ARG5);
3380 // SYS_extattr_delete_file 358
3381 // int extattr_delete_file(const char *path, int attrnamespace,
3382 // const char *attrname);
3383 PRE(sys_extattr_delete_file)
3385 PRINT("sys_extattr_delete_file ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3);
3386 PRE_REG_READ3(ssize_t, "extattr_delete_file",
3387 const char *, path, int, attrnamespace, const char *, attrname);
3388 PRE_MEM_RASCIIZ("extattr_delete_file(path)", ARG1);
3389 PRE_MEM_RASCIIZ("extattr_delete_file(attrname)", ARG3);
3392 // SYS_aio_waitcomplete 359
3393 // ssize_t aio_waitcomplete(struct aiocb **iocbp, struct timespec *timeout);
3394 PRE(sys_aio_waitcomplete)
3396 *flags |= SfMayBlock;
3397 PRINT("sys_aio_waitcomplete ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2);
3398 PRE_REG_READ2(ssize_t, "aio_waitcomplete", struct aiocb **, iocbp, struct timespec *, timeout);
3399 if (ARG2) {
3400 PRE_MEM_READ("aio_waitcomplete(timeout", ARG2, sizeof(struct vki_timespec));
3402 PRE_MEM_WRITE( "aio_waitcomplete(iocbp)", ARG1, sizeof(struct aiocb *));
3405 POST(sys_aio_waitcomplete)
3407 POST_MEM_WRITE(ARG1, sizeof(struct aiocb *));
3410 // SYS_getresuid 360
3411 // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
3412 PRE(sys_getresuid)
3414 PRINT("sys_getresuid ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3415 PRE_REG_READ3(long, "getresuid",
3416 vki_uid_t *, ruid, vki_uid_t *, euid, vki_uid_t *, suid);
3417 PRE_MEM_WRITE( "getresuid(ruid)", ARG1, sizeof(vki_uid_t) );
3418 PRE_MEM_WRITE( "getresuid(euid)", ARG2, sizeof(vki_uid_t) );
3419 PRE_MEM_WRITE( "getresuid(suid)", ARG3, sizeof(vki_uid_t) );
3422 POST(sys_getresuid)
3424 vg_assert(SUCCESS);
3425 if (RES == 0) {
3426 POST_MEM_WRITE( ARG1, sizeof(vki_uid_t) );
3427 POST_MEM_WRITE( ARG2, sizeof(vki_uid_t) );
3428 POST_MEM_WRITE( ARG3, sizeof(vki_uid_t) );
3432 // SYS_getresgid 361
3433 // int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid);
3434 PRE(sys_getresgid)
3436 PRINT("sys_getresgid ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3);
3437 PRE_REG_READ3(long, "getresgid",
3438 vki_gid_t *, rgid, vki_gid_t *, egid, vki_gid_t *, sgid);
3439 PRE_MEM_WRITE( "getresgid(rgid)", ARG1, sizeof(vki_gid_t) );
3440 PRE_MEM_WRITE( "getresgid(egid)", ARG2, sizeof(vki_gid_t) );
3441 PRE_MEM_WRITE( "getresgid(sgid)", ARG3, sizeof(vki_gid_t) );
3444 POST(sys_getresgid)
3446 vg_assert(SUCCESS);
3447 if (RES == 0) {
3448 POST_MEM_WRITE( ARG1, sizeof(vki_gid_t) );
3449 POST_MEM_WRITE( ARG2, sizeof(vki_gid_t) );
3450 POST_MEM_WRITE( ARG3, sizeof(vki_gid_t) );
3454 // SYS_kqueue 362
3455 // int kqueue(void);
3456 PRE(sys_kqueue)
3458 PRINT("%s", "sys_kqueue ()");
3459 PRE_REG_READ0(omt, "kqueue");
3462 POST(sys_kqueue)
3464 if (!ML_(fd_allowed)(RES, "kqueue", tid, True)) {
3465 VG_(close)(RES);
3466 SET_STATUS_Failure( VKI_EMFILE );
3467 } else {
3468 if (VG_(clo_track_fds)) {
3469 ML_(record_fd_open_nameless)(tid, RES);
3474 // SYS_freebsd11_kevent 363
3475 // int kevent(int kq, const struct kevent *changelist, int nchanges,
3476 // struct kevent *eventlist, int nevents,
3477 // const struct timespec *timeout);
3478 #if (FREEBSD_VERS >= FREEBSD_12)
3479 PRE(sys_freebsd11_kevent)
3481 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);
3482 PRE_REG_READ6(int, "kevent",
3483 int, fd, const struct vki_kevent_freebsd11 *, changelist, int, nchanges,
3484 struct vki_kevent_freebsd11 *, eventlist, int, nevents,
3485 struct timespec *, timeout);
3486 if (ARG2 != 0 && ARG3 != 0) {
3487 PRE_MEM_READ( "kevent(changelist)", ARG2, sizeof(struct vki_kevent_freebsd11)*ARG3 );
3489 if (ARG4 != 0 && ARG5 != 0) {
3490 PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent_freebsd11)*ARG5);
3492 if (ARG5 != 0) {
3493 *flags |= SfMayBlock;
3495 if (ARG6 != 0) {
3496 PRE_MEM_READ( "kevent(timeout)",
3497 ARG6, sizeof(struct vki_timespec));
3501 POST(sys_freebsd11_kevent)
3503 vg_assert(SUCCESS);
3504 if ((Word)RES != -1) {
3505 if (ARG4 != 0) {
3506 POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent_freebsd11)*RES) ;
3510 #else
3511 PRE(sys_kevent)
3513 *flags |= SfMayBlock;
3514 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);
3515 PRE_REG_READ6(int, "kevent",
3516 int, fd, struct vki_kevent_freebsd11 *, changelist, int, nchanges,
3517 struct vki_kevent_freebsd11 *, eventlist, int, nevents,
3518 struct timespec *, timeout);
3519 if (ARG2 != 0 && ARG3 != 0)
3520 PRE_MEM_READ( "kevent(changelist)", ARG2, sizeof(struct vki_kevent_freebsd11)*ARG3 );
3521 if (ARG4 != 0 && ARG5 != 0)
3522 PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent_freebsd11)*ARG5);
3523 if (ARG6 != 0)
3524 PRE_MEM_READ( "kevent(timeout)",
3525 ARG6, sizeof(struct vki_timespec));
3528 POST(sys_kevent)
3530 vg_assert(SUCCESS);
3531 if ((Word)RES != -1) {
3532 if (ARG4 != 0)
3533 POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent_freebsd11)*RES) ;
3536 #endif
3538 // SYS_extattr_set_fd 371
3539 // ssize_t extattr_set_fd(int fd, int attrnamespace, const char *attrname,
3540 // const void *data, size_t nbytes);
3541 PRE(sys_extattr_set_fd)
3543 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);
3544 PRE_REG_READ5(int, "extattr_set_fd", int, fd, int, attrnamespace, const char *,attrname, const void *,data, size_t, nbytes);
3545 PRE_MEM_RASCIIZ( "extattr_set_fd(attrname)", ARG3 );
3546 PRE_MEM_READ("extattr_set_fd(data)", ARG4, ARG5);
3549 // SYS_extattr_get_fd 372
3550 // ssize_t extattr_get_fd(int fd, int attrnamespace, const char *attrname,
3551 // void *data, size_t nbytes);
3552 PRE(sys_extattr_get_fd)
3554 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);
3555 PRE_REG_READ5(int, "extattr_get_fd", int, fd, int, attrnamespace, const char *,attrname, const void *,data, size_t, nbytes);
3556 PRE_MEM_RASCIIZ( "extattr_get_fd(attrname)", ARG3 );
3557 PRE_MEM_WRITE("extattr_get_fd(data)", ARG4, ARG5);
3560 POST(sys_extattr_get_fd)
3562 POST_MEM_WRITE(ARG4, ARG5);
3565 // SYS_extattr_delete_fd 373
3566 // int extattr_delete_fd(int fd, int attrnamespace, const char *attrname);
3567 PRE(sys_extattr_delete_fd)
3569 PRINT("sys_extattr_delete_fd ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3);
3570 PRE_REG_READ3(int, "extattr_delete_fd", int, fd, int, attrnamespace, const char *,attrname);
3571 PRE_MEM_RASCIIZ( "extattr_delete_fd(attrname)", ARG3 );
3574 // SYS___setugid 374
3575 // no manpage?
3576 // syscalls.master: int __setugid(int flag);
3577 PRE(sys___setugid)
3579 PRINT("sys___setugid ( %" FMT_REGWORD "d )", SARG1);
3580 PRE_REG_READ1(int, "__setugid", int, flag);
3583 // SYS_eaccess 376
3584 // int eaccess(const char *path, int mode);
3585 PRE(sys_eaccess)
3587 PRINT("sys_eaccess ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char*)ARG1,ARG2);
3588 PRE_REG_READ2(int, "eaccess", const char *, path, int, mode);
3589 PRE_MEM_RASCIIZ( "eaccess(path)", ARG1 );
3592 // SYS_afs3_syscall 377
3593 // @todo
3595 // SYS_nmount 378
3596 // int nmount(struct iovec *iov, u_int niov, int flags);
3597 PRE(sys_nmount)
3599 PRINT("sys_nmount ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d )", ARG1, ARG2, SARG3);
3600 PRE_REG_READ3(int, "nmount", struct iovec *, iov, u_int, niov, int, flags);
3601 PRE_MEM_READ( "nmount(pathname)", ARG1, ARG2*sizeof(struct vki_iovec) );
3604 // SYS___mac_get_proc 384
3605 // @todo
3607 // SYS___mac_set_proc 385
3608 // @todo
3610 // SYS___mac_get_fd 386
3611 // @todo
3613 // SYS___mac_get_file 387
3614 // @todo
3616 // SYS___mac_set_fd 388
3617 // @todo
3619 // SYS___mac_set_file 389
3620 // @todo
3622 // SYS_kenv 390
3623 // int kenv(int action, const char *name, char *value, int len);
3624 PRE(sys_kenv)
3626 PRINT("sys_kenv ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3,ARG4);
3627 PRE_REG_READ4(int, "kenv",
3628 int, action, const char *, name, char *, value, int, len);
3629 switch (ARG1) {
3630 case VKI_KENV_GET:
3631 case VKI_KENV_SET:
3632 case VKI_KENV_UNSET:
3633 PRE_MEM_RASCIIZ("kenv(name)", ARG2);
3634 /* FALLTHROUGH */
3635 case VKI_KENV_DUMP:
3636 break;
3637 default:
3638 VG_(dmsg)("Warning: Bad action %" FMT_REGWORD "u in kenv\n", ARG1);
3642 POST(sys_kenv)
3644 if (SUCCESS) {
3645 switch (ARG1) {
3646 case VKI_KENV_GET:
3647 POST_MEM_WRITE(ARG3, ARG4);
3648 break;
3649 case VKI_KENV_DUMP:
3650 if (ARG3 != (Addr)NULL) {
3651 POST_MEM_WRITE(ARG3, ARG4);
3653 break;
3658 // SYS_lchflags 391
3659 // int lchflags(const char *path, unsigned long flags);
3660 PRE(sys_lchflags)
3662 PRINT("sys_lchflags ( %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2);
3663 PRE_REG_READ2(int, "lchflags",
3664 const char *, path, unsigned long, flags);
3665 PRE_MEM_RASCIIZ( "lchflags(path)", ARG1 );
3668 // SYS_uuidgen 392
3669 // int uuidgen(struct uuid *store, int count);
3670 PRE(sys_uuidgen)
3672 PRINT("sys_uuidgen ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1,ARG2);
3673 PRE_REG_READ2(int, "uuidgen",
3674 struct vki_uuid *, store, int, count);
3675 PRE_MEM_WRITE( "uuidgen(store)", ARG1, ARG2 * sizeof(struct vki_uuid));
3678 POST(sys_uuidgen)
3680 if (SUCCESS) {
3681 POST_MEM_WRITE( ARG1, ARG2 * sizeof(struct vki_uuid) );
3685 // SYS_sendfile 393
3686 // x86/amd64
3688 // SYS_mac_syscall 394
3689 // @todo
3691 #if (FREEBSD_VERS >= FREEBSD_12)
3693 // SYS_freebsd11_getfsstat 395
3694 // int getfsstat(struct freebsd11_statfs *buf, long bufsize, int mode);
3696 PRE(sys_freebsd11_getfsstat)
3698 PRINT("sys_freebsd11_getfsstat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
3699 PRE_REG_READ3(int, "getfsstat", struct vki_freebsd11_statfs *, buf, long, bufsize, int, mode);
3700 PRE_MEM_WRITE( "getfsstat(buf)", ARG1, ARG2 );
3703 POST(sys_freebsd11_getfsstat)
3705 vg_assert(SUCCESS);
3706 if ((Word)RES != -1) {
3707 POST_MEM_WRITE( ARG1, RES * sizeof(struct vki_freebsd11_statfs) );
3711 // SYS_freebsd11_statfs 396
3712 // int statfs(const char *path, struct statfs *buf);
3713 PRE(sys_freebsd11_statfs)
3715 PRINT("sys_statfs ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
3716 PRE_REG_READ2(int, "statfs", const char *, path, struct statfs *, buf);
3717 PRE_MEM_RASCIIZ( "statfs(path)", ARG1 );
3718 PRE_MEM_WRITE( "statfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3721 POST(sys_freebsd11_statfs)
3723 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3726 // SYS_freebsd11_fstatfs 397
3727 // int fstatfs(int fd, struct statfs *buf);
3728 PRE(sys_freebsd11_fstatfs)
3730 PRINT("sys_fstatfs ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2);
3731 PRE_REG_READ2(int, "fstatfs",
3732 unsigned int, fd, struct statfs *, buf);
3733 PRE_MEM_WRITE( "fstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3736 POST(sys_freebsd11_fstatfs)
3738 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3741 // SYS_freebsd11_fhstatfs 398
3742 // int fhstatfs(const fhandle_t *fhp, struct statfs *buf);
3743 PRE(sys_freebsd11_fhstatfs)
3745 PRINT("sys_fhstatfs ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
3746 PRE_REG_READ2(int, "fhstatfs",
3747 struct fhandle *, fhp, struct statfs *, buf);
3748 PRE_MEM_READ( "fhstatfs(fhp)", ARG1, sizeof(struct vki_fhandle) );
3749 PRE_MEM_WRITE( "fhstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3752 POST(sys_freebsd11_fhstatfs)
3754 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3758 #else
3760 PRE(sys_getfsstat)
3762 PRINT("sys_getfsstat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
3763 PRE_REG_READ3(int, "getfsstat", struct vki_freebsd11_statfs *, buf, long, bufsize, int, mode);
3764 PRE_MEM_WRITE( "getfsstat(buf)", ARG1, ARG2 );
3767 POST(sys_getfsstat)
3769 vg_assert(SUCCESS);
3770 if ((Word)RES != -1) {
3771 POST_MEM_WRITE( ARG1, RES * sizeof(struct vki_freebsd11_statfs) );
3775 PRE(sys_statfs)
3777 PRINT("sys_statfs ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
3778 PRE_REG_READ2(int, "statfs", const char *, path, struct statfs *, buf);
3779 PRE_MEM_RASCIIZ( "statfs(path)", ARG1 );
3780 PRE_MEM_WRITE( "statfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3783 POST(sys_statfs)
3785 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3788 PRE(sys_fstatfs)
3790 PRINT("sys_fstatfs ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2);
3791 PRE_REG_READ2(int, "fstatfs",
3792 unsigned int, fd, struct statfs *, buf);
3793 PRE_MEM_WRITE( "fstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3796 POST(sys_fstatfs)
3798 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3801 PRE(sys_fhstatfs)
3803 PRINT("sys_fhstatfs ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
3804 PRE_REG_READ2(int, "fhstatfs",
3805 struct fhandle *, fhp, struct statfs *, buf);
3806 PRE_MEM_READ( "fhstatfs(fhp)", ARG1, sizeof(struct vki_fhandle) );
3807 PRE_MEM_WRITE( "fhstatfs(buf)", ARG2, sizeof(struct vki_freebsd11_statfs) );
3810 POST(sys_fhstatfs)
3812 POST_MEM_WRITE( ARG2, sizeof(struct vki_freebsd11_statfs) );
3816 #endif
3818 // SYS_ksem_close 400
3819 // @todo
3821 // SYS_ksem_post 401
3822 // @todo
3824 // SYS_ksem_wait 402
3825 // @todo
3827 // SYS_ksem_trywait 403
3828 // @todo
3830 // SYS_ksem_init 404
3831 // @todo
3833 // SYS_ksem_open 405
3834 // @todo
3836 // SYS_ksem_unlink 406
3837 // @todo
3839 // SYS_ksem_getvalue 407
3840 // @todo
3842 // SYS_ksem_destroy 408
3843 // @todo
3845 // SYS___mac_get_pid 409
3846 // @todo
3848 // SYS___mac_get_link 410
3849 // @todo
3851 // SYS___mac_set_link 411
3852 // @todo
3854 // SYS_extattr_set_link 412
3855 // ssize_t extattr_set_link(const char *path, int attrnamespace,
3856 // const char *attrname, const void *data, size_t nbytes);
3857 PRE(sys_extattr_set_link)
3859 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);
3860 PRE_REG_READ5(ssize_t, "extattr_set_link",
3861 const char *, path, int, attrnamespace, const char *, attrname, const void *, data, size_t, nbytes);
3862 PRE_MEM_RASCIIZ("extattr_set_link(path)", ARG1);
3863 PRE_MEM_RASCIIZ("extattr_set_link(attrname)", ARG3);
3864 PRE_MEM_READ("extattr_set_link(data)", ARG4, ARG5);
3867 // SYS_extattr_get_link 413
3868 // ssize_t extattr_get_link(const char *path, int attrnamespace,
3869 // const char *attrname, void *data, size_t nbytes);
3870 PRE(sys_extattr_get_link)
3872 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);
3873 PRE_REG_READ5(ssize_t, "extattr_get_link",
3874 const char *, path, int, attrnamespace, const char *, attrname, void *, data, size_t, nbytes);
3875 PRE_MEM_RASCIIZ("extattr_get_link(path)", ARG1);
3876 PRE_MEM_RASCIIZ("extattr_get_link(attrname)", ARG3);
3877 if (ARG4) {
3878 PRE_MEM_WRITE("extattr_get_link(data)", ARG4, ARG5);
3882 POST(sys_extattr_get_link)
3884 if (ARG4) {
3885 POST_MEM_WRITE(ARG4, ARG5);
3889 // SYS_extattr_delete_link 414
3890 // int extattr_delete_link(const char *path, int attrnamespace,
3891 // const char *attrname);
3892 PRE(sys_extattr_delete_link)
3894 PRINT("sys_extattr_delete_link ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1,SARG2,ARG3);
3895 PRE_REG_READ3(ssize_t, "extattr_delete_link",
3896 const char *, path, int, attrnamespace, const char *, attrname);
3897 PRE_MEM_RASCIIZ("extattr_delete_link(path)", ARG1);
3898 PRE_MEM_RASCIIZ("extattr_delete_link(attrname)", ARG3);
3901 // SYS___mac_execve 415
3902 // @todo
3904 // SYS_sigaction 416
3905 //int sigaction(int sig, const struct sigaction * restrict act,
3906 // struct sigaction * restrict oact);
3907 PRE(sys_sigaction)
3909 vki_sigaction_toK_t new;
3910 vki_sigaction_toK_t *newp;
3911 vki_sigaction_fromK_t old;
3912 vki_sigaction_fromK_t *oldp;
3914 PRINT("sys_sigaction ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
3915 SARG1,ARG2,ARG3);
3916 PRE_REG_READ3(long, "sigaction",
3917 int, sign, const struct sigaction *, act,
3918 struct sigaction *, oact);
3920 newp = oldp = NULL;
3922 if (ARG2 != 0) {
3923 struct vki_sigaction *sa = (struct vki_sigaction *)ARG2;
3924 PRE_MEM_READ( "sigaction(act->sa_handler)", (Addr)&sa->ksa_handler, sizeof(sa->ksa_handler));
3925 PRE_MEM_READ( "sigaction(act->sa_mask)", (Addr)&sa->sa_mask, sizeof(sa->sa_mask));
3926 PRE_MEM_READ( "sigaction(act->sa_flags)", (Addr)&sa->sa_flags, sizeof(sa->sa_flags));
3929 if (ARG3 != 0) {
3930 PRE_MEM_WRITE( "sigaction(oact)", ARG3, sizeof(struct vki_sigaction));
3931 oldp = &old;
3934 if (ARG2 != 0
3935 && ! ML_(safe_to_deref)((void *)(Addr)ARG2,
3936 sizeof(struct vki_sigaction))) {
3937 VG_(umsg)("Warning: bad act handler address %p in sigaction()\n",
3938 (void *)(Addr)ARG2);
3939 SET_STATUS_Failure ( VKI_EFAULT );
3940 } else if ((ARG3 != 0
3941 && ! ML_(safe_to_deref)((void *)(Addr)ARG3,
3942 sizeof(struct vki_sigaction)))) {
3943 VG_(umsg)("Warning: bad oact handler address %p in sigaction()\n",
3944 (void *)(Addr)ARG3);
3945 SET_STATUS_Failure ( VKI_EFAULT );
3946 } else {
3947 if (ARG2 != 0) {
3948 struct vki_sigaction *oldnew =
3949 (struct vki_sigaction *)(Addr)ARG2;
3951 new.ksa_handler = oldnew->ksa_handler;
3952 new.sa_flags = oldnew->sa_flags;
3953 new.sa_mask = oldnew->sa_mask;
3954 newp = &new;
3957 SET_STATUS_from_SysRes( VG_(do_sys_sigaction)(ARG1, newp, oldp) );
3959 if (ARG3 != 0 && SUCCESS && RES == 0) {
3960 struct vki_sigaction *oldold =
3961 (struct vki_sigaction *)(Addr)ARG3;
3963 oldold->ksa_handler = oldp->ksa_handler;
3964 oldold->sa_flags = oldp->sa_flags;
3965 oldold->sa_mask = oldp->sa_mask;
3970 POST(sys_sigaction)
3972 vg_assert(SUCCESS);
3973 if (RES == 0 && ARG3 != 0) {
3974 POST_MEM_WRITE( ARG3, sizeof(struct vki_sigaction));
3978 // SYS_sigreturn 417
3979 // x86/amd64
3981 // SYS_getcontext 421
3982 // SYS_setcontext 422
3983 // SYS_swapcontext 423
3984 // PRE in x86/amd64
3986 POST(sys_getcontext)
3988 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucontext) );
3991 POST(sys_swapcontext)
3993 if (SUCCESS) {
3994 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucontext) );
3998 #if (FREEBSD_VERS >= FREEBSD_13_1)
3999 // SYS_freebsd13_swapoff 424
4000 // int swapoff(const char *special);
4001 PRE(sys_freebsd13_swapoff)
4003 PRINT("sys_freebsd13_swapoff ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
4004 PRE_REG_READ1(int, "swapoff", const char *, special);
4005 PRE_MEM_RASCIIZ( "swapoff(special)", ARG1 );
4007 #else
4008 // SYS_swapoff 424
4009 // int swapoff(const char *special);
4010 PRE(sys_swapoff)
4012 PRINT("sys_swapoff ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
4013 PRE_REG_READ1(int, "swapoff", const char *, special);
4014 PRE_MEM_RASCIIZ( "swapoff(special)", ARG1 );
4016 #endif
4018 // SYS___acl_get_link 425
4019 // int __acl_get_link(const char *path, acl_type_t type, struct acl *aclp);
4020 PRE(sys___acl_get_link)
4022 PRINT("sys___acl_get_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
4023 PRE_REG_READ3(int, "__acl_get_link",
4024 const char *, path, int, acltype, struct vki_acl *, aclp);
4025 PRE_MEM_RASCIIZ( "__acl_get_link(path)", ARG1 );
4026 PRE_MEM_WRITE( "__acl_get_link(aclp)", ARG3, sizeof(struct vki_acl) );
4029 POST(sys___acl_get_link)
4031 vg_assert(SUCCESS);
4032 if (RES == 0) {
4033 POST_MEM_WRITE( ARG3, sizeof(struct vki_acl) );
4037 // SYS___acl_set_link 426
4038 // int __acl_set_link(const char *path, acl_type_t type, struct acl *aclp);
4039 PRE(sys___acl_set_link)
4041 PRINT("sys___acl_set_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
4042 PRE_REG_READ3(int, "__acl_set_link",
4043 const char *, path, int, acltype, struct vki_acl *, aclp);
4044 PRE_MEM_RASCIIZ( "__acl_set_link(path)", ARG1 );
4045 PRE_MEM_READ( "__acl_set_link(aclp)", ARG3, sizeof(struct vki_acl) );
4047 // SYS___acl_delete_link 427
4048 // int __acl_delete_link(const char *path, acl_type_t type);
4049 PRE(sys___acl_delete_link)
4051 PRINT("sys___acl_delete_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char *)ARG1,ARG2);
4052 PRE_MEM_RASCIIZ( "__acl_delete_link(path)", ARG1 );
4053 PRE_REG_READ2(int, "__acl_delete_link",
4054 const char *, path, int, acltype);
4057 // SYS___acl_aclcheck_link 428
4058 // int __acl_aclcheck_link(const char *path, acl_type_t type, struct acl *aclp);
4059 PRE(sys___acl_aclcheck_link)
4061 PRINT("sys___acl_aclcheck_link ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2,ARG3);
4062 PRE_REG_READ3(long, "__acl_aclcheck_link",
4063 const char *, path, int, acltype, struct vki_acl *, aclp);
4064 PRE_MEM_RASCIIZ( "__acl_check_link(path)", ARG1 );
4065 PRE_MEM_READ( "__acl_aclcheck_link(aclp)", ARG3, sizeof(struct vki_acl) );
4068 // SYS_sigwait 429
4069 // int sigwait(const sigset_t * restrict set, int * restrict sig);
4070 PRE(sys_sigwait)
4072 *flags |= SfMayBlock;
4073 PRINT("sys_sigwait ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
4074 ARG1,ARG2);
4075 PRE_REG_READ2(int, "sigwait",
4076 const vki_sigset_t *, set, int *, sig);
4077 if (ARG1 != 0) {
4078 PRE_MEM_READ( "sigwait(set)", ARG1, sizeof(vki_sigset_t));
4080 if (ARG2 != 0) {
4081 PRE_MEM_WRITE( "sigwait(sig)", ARG2, sizeof(int));
4085 POST(sys_sigwait)
4087 if (ARG2 != 0) {
4088 POST_MEM_WRITE( ARG2, sizeof(int));
4092 // SYS_thr_create 430
4093 // no manpage?
4094 // syscalls.master: int thr_create(_In_ ucontext_t *ctx, _Out_ long *id, int flags );
4095 PRE(sys_thr_create)
4097 PRINT( "sys_thr_create ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )", ARG1, ARG2, SARG3 );
4098 PRE_REG_READ3(int, "thr_create", /*ucontext_t*/void *, ctx, long *, id, int, flags );
4100 VG_(message)(Vg_UserMsg, "thr_create() not implemented");
4101 VG_(unimplemented)("Valgrind does not support thr_create().");
4103 SET_STATUS_Failure(VKI_ENOSYS);
4106 // SYS_thr_exit 431
4107 // void thr_exit(long *state);
4108 PRE(sys_thr_exit)
4110 ThreadState *tst;
4112 PRINT( "sys_thr_exit ( %#" FMT_REGWORD "x )", ARG1 );
4113 PRE_REG_READ1(void, "thr_exit", long *, state);
4115 if (ARG1) {
4116 PRE_MEM_WRITE( "thr_exit(state)", ARG1, sizeof(long) );
4119 tst = VG_(get_ThreadState)(tid);
4120 tst->exitreason = VgSrc_ExitThread;
4121 tst->os_state.exitcode = ARG1;
4122 SET_STATUS_Success(0);
4125 // SYS_thr_self 432
4126 // int thr_self(long *id);
4127 PRE(sys_thr_self)
4129 PRINT( "sys_thr_self ( %#" FMT_REGWORD "x )", ARG1 );
4130 PRE_REG_READ1(int, "thr_self", long *, id);
4131 PRE_MEM_WRITE( "thr_self()", ARG1, sizeof(long));
4134 POST(sys_thr_self)
4136 POST_MEM_WRITE( ARG1, sizeof(long));
4139 // SYS_thr_kill 433
4140 // int thr_kill(long id, int sig);
4141 PRE(sys_thr_kill)
4143 PRINT("sys_thr_kill ( %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2);
4144 PRE_REG_READ2(long, "thr_kill", long, id, int, sig);
4145 if (!ML_(client_signal_OK)(ARG2)) {
4146 SET_STATUS_Failure( VKI_EINVAL );
4147 return;
4150 /* Check to see if this kill gave us a pending signal */
4151 *flags |= SfPollAfter;
4153 if (VG_(clo_trace_signals)) {
4154 VG_(message)(Vg_DebugMsg, "thr_kill: sending signal %lu to tid %lu\n",
4155 ARG2, ARG1);
4158 /* If we're sending SIGKILL, check to see if the target is one of
4159 our threads and handle it specially. */
4160 if (ARG2 == VKI_SIGKILL && ML_(do_sigkill)(ARG1, -1)) {
4161 SET_STATUS_Success(0);
4162 return;
4165 /* Ask to handle this syscall via the slow route, since that's the
4166 only one that sets tst->status to VgTs_WaitSys. If the result
4167 of doing the syscall is an immediate run of
4168 async_signalhandler() in m_signals, then we need the thread to
4169 be properly tidied away. I have the impression the previous
4170 version of this wrapper worked on x86/amd64 only because the
4171 kernel did not immediately deliver the async signal to this
4172 thread (on ppc it did, which broke the assertion re tst->status
4173 at the top of async_signalhandler()). */
4174 *flags |= SfMayBlock;
4177 POST(sys_thr_kill)
4179 if (VG_(clo_trace_signals)) {
4180 VG_(message)(Vg_DebugMsg, "thr_kill: sent signal %lu to tid %lu\n",
4181 ARG2, ARG1);
4185 #if (FREEBSD_VERS <= FREEBSD_10)
4186 // SYS__umtx_lock 434
4187 PRE(sys__umtx_lock)
4189 PRINT( "sys__umtx_lock ( %#" FMT_REGWORD "x )", ARG1);
4190 PRE_REG_READ1(long, "_umtx_lock", struct vki_umtx *, umtx);
4191 PRE_MEM_READ( "_umtx_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4192 PRE_MEM_WRITE( "_umtx_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4195 POST(sys__umtx_lock)
4197 if (SUCCESS) {
4198 POST_MEM_WRITE(ARG1, sizeof(struct vki_umtx));
4202 // SYS__umtx_unlock 434
4203 PRE(sys__umtx_unlock)
4205 PRINT( "sys__umtx_unlock ( %#" FMT_REGWORD "x )", ARG1);
4206 PRE_REG_READ1(long, "_umtx_unlock", struct vki_umtx *, umtx);
4207 PRE_MEM_READ( "_umtx_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4208 PRE_MEM_WRITE( "_umtx_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4211 POST(sys__umtx_unlock)
4213 if (SUCCESS) {
4214 POST_MEM_WRITE(ARG1, sizeof(struct vki_umtx));
4217 #endif
4219 // SYS_jail_attach 436
4220 // int jail_attach(int jid);
4221 PRE(sys_jail_attach)
4223 PRINT("sys_jail_attach ( %" FMT_REGWORD "d )", SARG1);
4224 PRE_REG_READ1(int, "jail_attach", int, jid);
4227 // SYS_extattr_list_fd 437
4228 // ssize_t extattr_list_fd(int fd, int attrnamespace, void *data, size_t nbytes);
4229 PRE(sys_extattr_list_fd)
4231 PRINT("extattr_list_fd ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", SARG1, SARG2, ARG3, ARG4);
4232 PRE_REG_READ4(ssize_t, "extattr_list_fd", int, id, int, attrnamespace, void *,data, size_t, nbytes);
4233 PRE_MEM_WRITE("extattr_list_fd(data)", ARG3, ARG4);
4236 POST(sys_extattr_list_fd)
4238 POST_MEM_WRITE(ARG3, ARG4);
4241 // SYS_extattr_list_file 438
4242 // ssize_t extattr_list_file(const char *path, int attrnamespace, void *data,
4243 // size_t nbytes);
4244 PRE(sys_extattr_list_file)
4246 PRINT("extattr_list_file ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, SARG2, ARG3, ARG4);
4247 PRE_REG_READ4(ssize_t, "extattr_list_file", const char *, path, int, attrnamespace, void *,data, size_t, nbytes);
4248 PRE_MEM_RASCIIZ("extattr_list_file(path)", ARG1);
4249 PRE_MEM_WRITE("extattr_list_file(data)", ARG3, ARG4);
4252 POST(sys_extattr_list_file)
4254 POST_MEM_WRITE(ARG3, ARG4);
4257 // SYS_extattr_list_link 439
4258 // ssize_t extattr_get_link(const char *path, int attrnamespace,
4259 // const char *attrname, void *data, size_t nbytes);
4260 PRE(sys_extattr_list_link)
4262 PRINT("extattr_list_link ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, SARG2, ARG3, ARG4);
4263 PRE_REG_READ4(ssize_t, "extattr_list_link", const char *, path, int, attrnamespace, void *,data, size_t, nbytes);
4264 PRE_MEM_RASCIIZ("extattr_list_link(path)", ARG1);
4265 PRE_MEM_WRITE("extattr_list_link(data)", ARG3, ARG4);
4268 POST(sys_extattr_list_link)
4270 POST_MEM_WRITE(ARG3, ARG4);
4273 // SYS_ksem_timedwait 441
4274 // @todo
4276 // SYS_thr_suspend 442
4277 // int thr_suspend(struct timespec *timeout);
4278 PRE(sys_thr_suspend)
4280 PRINT("sys_thr_suspend ( %#" FMT_REGWORD "x )", ARG1);
4281 PRE_REG_READ1(int, "thr_suspend", struct timespec *, timeout);
4282 PRE_MEM_READ("thr_suspend(timeout)", ARG1, sizeof(struct vki_timespec));
4284 VG_(message)(Vg_UserMsg, "thr_supend() not implemented");
4285 VG_(unimplemented)("Valgrind does not support thr_suspend().");
4287 SET_STATUS_Failure(VKI_ENOSYS);
4290 // SYS_thr_wake 443
4291 // int thr_wake(long id);
4292 PRE(sys_thr_wake)
4294 PRINT("sys_thr_wake ( %" FMT_REGWORD "d )", SARG1);
4295 PRE_REG_READ1(long, "thr_wake", long, id);
4297 if (VG_(is_valid_tid)(ARG1)) {
4298 VG_(threads)[ARG1].status = VgTs_Runnable;
4299 } else {
4300 SET_STATUS_Failure( VKI_ESRCH );
4305 // SYS_kldunloadf 444
4306 // int kldunloadf(int fileid, int flags);
4307 PRE(sys_kldunloadf)
4309 PRINT("sys_kldunloadf ( %" FMT_REGWORD "d, %" FMT_REGWORD "d )", SARG1, SARG2);
4310 PRE_REG_READ2(int, "kldunloadf", int, fileid, int, flags);
4313 // SYS_audit 445
4314 // int audit(const char *record, u_int length);
4315 // @todo
4317 // SYS_auditon 446
4318 // int auditon(int cmd, void *data, u_int length);
4319 // @todo
4321 // SYS_getauid 447
4322 // int getauid(au_id_t *auid);
4323 // @todo
4325 // SYS_setauid 448
4326 // int setauid(au_id_t *auid);
4327 // @todo
4329 // SYS_getaudit 449
4330 // int getaudit(auditinfo_t *auditinfo);
4331 // @todo
4333 // SYS_setaudit 450
4334 // int setaudit(auditinfo_t *auditinfo);
4335 // @todo
4337 // SYS_getaudit_addr 451
4338 // int getaudit_addr(auditinfo_addr_t *auditinfo_addr, u_int length);
4339 // @todo
4341 // SYS_setaudit_addr 452
4342 // int setaudit_addr(auditinfo_addr_t *auditinfo_addr, u_int length);
4343 // @todo
4345 // SYS_auditctl 453
4346 // @todo
4348 // SYS__umtx_op 454
4349 // int _umtx_op(void *obj, int op, u_long val, void *uaddr, void *uaddr2);
4350 PRE(sys__umtx_op)
4352 /* 5 args are always passed through. The last two can vary, but
4353 they're always pointers. They may not be used though. */
4354 switch(ARG2) {
4355 case VKI_UMTX_OP_LOCK:
4356 // marked as COMPAT10
4357 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, LOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4358 PRE_REG_READ5(long, "_umtx_op_lock",
4359 struct umtx *, obj, int, op, unsigned long, id,
4360 size_t, timeout_size, struct vki_timespec *, timeout);
4361 PRE_MEM_READ( "_umtx_op_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4362 if (ARG5) {
4363 PRE_MEM_READ( "_umtx_op_lock(timespec)", ARG5, ARG4 );
4365 PRE_MEM_WRITE( "_umtx_op_lock(mtx)", ARG1, sizeof(struct vki_umtx) );
4366 *flags |= SfMayBlock;
4367 break;
4368 case VKI_UMTX_OP_UNLOCK:
4369 // marked as COMPAT10
4370 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, UNLOCK, %" FMT_REGWORD "u)", ARG1, ARG3);
4371 PRE_REG_READ3(long, "_umtx_op_unlock",
4372 struct umtx *, obj, int, op, unsigned long, id);
4373 PRE_MEM_READ( "_umtx_op_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4374 PRE_MEM_WRITE( "_umtx_op_unlock(mtx)", ARG1, sizeof(struct vki_umtx) );
4375 break;
4376 case VKI_UMTX_OP_WAIT:
4377 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4378 PRE_REG_READ5(long, "_umtx_op_wait",
4379 long *, obj, int, op, unsigned long, val,
4380 size_t, timeout_size, struct vki_timespec *, timeout);
4381 if (ARG1) {
4382 PRE_MEM_READ( "_umtx_op_wait(val)", ARG1, sizeof(long) );
4383 if (*(long*)ARG1 == (long)ARG3) {
4384 *flags |= SfMayBlock;
4388 if (ARG5) {
4389 PRE_MEM_READ( "_umtx_op_wait(timeout)", ARG5, ARG4 );
4392 break;
4393 case VKI_UMTX_OP_WAKE:
4394 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, WAKE, %" FMT_REGWORD "u)", ARG1, ARG3);
4395 PRE_REG_READ3(long, "_umtx_op_wake",
4396 vki_uintptr_t *, obj, int, op, int, val);
4397 // PJF I don't think that the value of obj gets read, the address is being used as a key
4398 //PRE_MEM_READ("_umtx_op_wake(obj)", ARG1, sizeof(vki_uintptr_t));
4399 break;
4400 case VKI_UMTX_OP_MUTEX_TRYLOCK:
4401 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_TRYLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4402 PRE_REG_READ2(long, "_umtx_op_mutex_trylock", struct umutex *, obj, int, op);
4403 PRE_MEM_READ( "_umtx_op_mutex_trylock(mutex)", ARG1, sizeof(struct vki_umutex) );
4404 PRE_MEM_WRITE( "_umtx_op_mutex_trylock(mutex)", ARG1, sizeof(struct vki_umutex) );
4405 /* not too sure about the restart here
4406 * it's hard to test as if the mutex is locked this returns EBUSY
4407 * so there is only a small window where the syscall could be interrupted */
4408 *flags |= SfMayBlock | SfKernelRestart;
4409 break;
4410 case VKI_UMTX_OP_MUTEX_LOCK:
4411 // called by pthread_mutex_lock
4412 // when the atribute UMUTEX_PRIO_PROTECT or UMUTEX_PRIO_INHERIT is set
4413 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_LOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4414 PRE_REG_READ5(long, "_umtx_op_mutex_lock",
4415 struct umutex *, obj, int, op, unsigned long, noid,
4416 size_t, timeout_size, struct vki_timespec *, timeout);
4417 PRE_MEM_READ( "_umtx_op_mutex_lock(mutex)", ARG1, sizeof(struct vki_umutex) );
4418 if (ARG5) {
4419 PRE_MEM_READ( "_umtx_op_mutex_lock(timespec)", ARG5, ARG4 );
4420 } else {
4421 *flags |= SfKernelRestart;
4423 PRE_MEM_WRITE( "_umtx_op_mutex_lock(mutex)", ARG1, sizeof(struct vki_umutex) );
4424 *flags |= SfMayBlock;
4425 break;
4426 case VKI_UMTX_OP_MUTEX_UNLOCK:
4427 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_UNLOCK)", ARG1);
4428 PRE_REG_READ2(long, "_umtx_op_mutex_unlock",
4429 struct umutex *, obj, int, op);
4430 PRE_MEM_READ( "_umtx_op_mutex_unlock(mutex)", ARG1, sizeof(struct vki_umutex) );
4431 PRE_MEM_WRITE( "_umtx_op_mutex_unlock(mutex)", ARG1, sizeof(struct vki_umutex) );
4432 break;
4433 case VKI_UMTX_OP_SET_CEILING:
4434 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SET_CEILING, %" FMT_REGWORD "u, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4);
4435 PRE_REG_READ4(long, "_umtx_op_set_ceiling",
4436 struct umutex *, obj, int, op, unsigned int, ceiling,
4437 unsigned int *, old_ceiling);
4438 PRE_MEM_READ( "_umtx_op_set_ceiling(mutex)", ARG1, sizeof(struct vki_umutex) );
4439 PRE_MEM_WRITE( "_umtx_op_set_ceiling(mutex)", ARG1, sizeof(struct vki_umutex) );
4440 if (ARG4) {
4441 PRE_MEM_WRITE( "_umtx_op_set_ceiling(old_ceiling)", ARG4, sizeof(vki_uint32_t) );
4443 break;
4444 case VKI_UMTX_OP_CV_WAIT:
4445 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4446 PRE_REG_READ5(long, "_umtx_op_cv_wait",
4447 struct ucond *, obj, int, op, unsigned long, wflags,
4448 struct umutex *, umtx, struct vki_timespec *, timeout);
4449 PRE_MEM_READ( "_umtx_op_cv_wait(cond)", ARG1, sizeof(struct vki_ucond) );
4450 PRE_MEM_WRITE( "_umtx_op_cv_wait(cond)", ARG1, sizeof(struct vki_ucond) );
4451 PRE_MEM_READ( "_umtx_op_cv_wait(mutex)", ARG4, sizeof(struct vki_umutex) );
4452 PRE_MEM_WRITE( "_umtx_op_cv_wait(mutex)", ARG4, sizeof(struct vki_umutex) );
4453 if (ARG5) {
4454 PRE_MEM_READ( "_umtx_op_cv_wait(timespec)", ARG5, sizeof(struct vki_timespec) );
4456 *flags |= SfMayBlock;
4457 break;
4458 case VKI_UMTX_OP_CV_SIGNAL:
4459 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_SIGNAL)", ARG1);
4460 PRE_REG_READ2(long, "_umtx_op_cv_signal",
4461 struct ucond *, obj, int, op);
4462 PRE_MEM_READ( "_umtx_op_cv_signal(cond)", ARG1, sizeof(struct vki_ucond) );
4463 PRE_MEM_WRITE( "_umtx_op_cv_signal(cond)", ARG1, sizeof(struct vki_ucond) );
4464 break;
4465 case VKI_UMTX_OP_CV_BROADCAST:
4466 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_BROADCAST, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4467 PRE_REG_READ2(long, "_umtx_op_cv_broadcast",
4468 struct ucond *, obj, int, op);
4469 PRE_MEM_READ( "_umtx_op_cv_broadcast(cond)", ARG1, sizeof(struct vki_ucond) );
4470 PRE_MEM_WRITE( "_umtx_op_cv_broadcast(cond)", ARG1, sizeof(struct vki_ucond) );
4471 break;
4472 case VKI_UMTX_OP_WAIT_UINT:
4473 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAIT_UINT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4474 PRE_REG_READ5(long, "_umtx_op_wait_uint",
4475 int *, obj, int, op, unsigned long, id,
4476 size_t, timeout_wait, struct vki_timespec *, timeout);
4477 PRE_MEM_READ( "_umtx_op_wait(uint)", ARG1, sizeof(int) );
4478 if (ARG5) {
4479 PRE_MEM_READ( "_umtx_op_wait(timespec)", ARG5, ARG4 );
4481 *flags |= SfMayBlock;
4482 break;
4483 case VKI_UMTX_OP_RW_RDLOCK:
4484 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, RW_RDLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4485 PRE_REG_READ5(long, "_umtx_op_rw_rdlock",
4486 struct urwlock *, obj, int, op, unsigned long, noid,
4487 void *, zero, struct vki_timespec *, timeout);
4488 PRE_MEM_READ( "_umtx_op_rw_rdlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4489 PRE_MEM_WRITE( "_umtx_op_rw_rdlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4490 *flags |= SfMayBlock;
4491 break;
4492 case VKI_UMTX_OP_RW_WRLOCK:
4493 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, RW_WRLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4494 PRE_REG_READ5(long, "_umtx_op_rw_wrlock",
4495 struct urwlock *, obj, int, op, unsigned long, noid,
4496 void *, zero, struct vki_timespec *, timeout);
4497 PRE_MEM_READ( "_umtx_op_rw_wrlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4498 PRE_MEM_WRITE( "_umtx_op_rw_wrlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4499 *flags |= SfMayBlock;
4500 break;
4501 case VKI_UMTX_OP_RW_UNLOCK:
4502 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, RW_UNLOCK, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4503 PRE_REG_READ2(long, "_umtx_op_rw_unlock",
4504 struct urwlock *, obj, int, op);
4505 PRE_MEM_READ( "_umtx_op_rw_unlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4506 PRE_MEM_WRITE( "_umtx_op_rw_unlock(rw)", ARG1, sizeof(struct vki_urwlock) );
4507 break;
4508 case VKI_UMTX_OP_WAIT_UINT_PRIVATE:
4509 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAIT_UINT_PRIVATE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4510 PRE_REG_READ5(long, "_umtx_op_wait_uint_private",
4511 int *, obj, int, op, unsigned long, id,
4512 size_t, timeout_size, struct vki_timespec *, timeout);
4513 PRE_MEM_READ( "_umtx_op_wait_private(uint)", ARG1, sizeof(int) );
4514 if (ARG5) {
4515 PRE_MEM_READ( "_umtx_op_wait_private(umtx_time)", ARG5, ARG4 );
4517 *flags |= SfMayBlock;
4518 break;
4519 case VKI_UMTX_OP_WAKE_PRIVATE:
4520 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, CV_WAKE_PRIVATE, %" FMT_REGWORD "u)", ARG1, ARG3);
4521 PRE_REG_READ3(long, "_umtx_op_wake_private",
4522 vki_uintptr_t *, obj, int, op, int, val);
4523 // PJF like OP_WAKE contents of obj not read
4524 //PRE_MEM_READ("_umtx_op_wake_private(obj)", ARG1, sizeof(vki_uintptr_t));
4525 break;
4526 case VKI_UMTX_OP_MUTEX_WAIT:
4527 // pthread_mutex_lock without prio flags
4528 // does not need to be restarted
4529 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4530 PRE_REG_READ2(long, "_umtx_op_mutex_wait",
4531 struct umutex *, obj, int, op);
4532 PRE_MEM_READ( "_umtx_op_mutex_wait(mutex)", ARG1, sizeof(struct vki_umutex) );
4533 PRE_MEM_WRITE( "_umtx_op_mutex_wait(mutex)", ARG1, sizeof(struct vki_umutex) );
4534 *flags |= SfMayBlock;
4535 break;
4536 case VKI_UMTX_OP_MUTEX_WAKE:
4537 // marked as deprecated
4538 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_WAKE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4539 PRE_REG_READ2(long, "_umtx_op_mutex_wake",
4540 struct umutex *, obj, int, op);
4541 PRE_MEM_READ( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4542 PRE_MEM_WRITE( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4543 break;
4544 case VKI_UMTX_OP_SEM_WAIT:
4545 // marked as deprecated
4546 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4547 PRE_REG_READ5(long, "_umtx_op_sem_wait",
4548 struct usem *, obj, int, op, unsigned long, id,
4549 size_t, timeout_size, struct vki_timespec *, timeout);
4550 PRE_MEM_READ( "_umtx_op_sem_wait(usem)", ARG1, sizeof(struct vki_usem) );
4551 PRE_MEM_WRITE( "_umtx_op_sem_wait(usem)", ARG1, sizeof(struct vki_usem) );
4552 if (ARG5) {
4553 PRE_MEM_READ( "_umtx_op_sem_wait(umtx_time)", ARG5, ARG4 );
4555 *flags |= SfMayBlock;
4556 break;
4557 case VKI_UMTX_OP_SEM_WAKE:
4558 // marked as deprecated
4559 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM_WAKE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4560 PRE_REG_READ2(long, "_umtx_op_sem_wake",
4561 struct umutex *, obj, int, op);
4562 PRE_MEM_READ( "_umtx_op_sem_wake(mutex)", ARG1, sizeof(struct vki_usem) );
4563 PRE_MEM_WRITE( "_umtx_op_sem_wake(mutex)", ARG1, sizeof(struct vki_usem) );
4564 break;
4565 case VKI_UMTX_OP_NWAKE_PRIVATE:
4566 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, NWAKE_PRIVATE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4567 PRE_REG_READ3(long, "_umtx_op_nwake_private",
4568 struct umutex *, obj, int, op, int, count);
4569 PRE_MEM_READ( "_umtx_op_nwake_private(mtxs)", ARG1, ARG3 * sizeof(void *) );
4570 PRE_MEM_WRITE( "_umtx_op_mutex_wake(mtxs)", ARG1, sizeof(struct vki_umutex) );
4571 break;
4572 case VKI_UMTX_OP_MUTEX_WAKE2:
4573 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, MUTEX_WAKE2, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4574 PRE_REG_READ3(long, "_umtx_op_mutex_wake2",
4575 struct umutex *, obj, int, op, unsigned long, flags);
4576 PRE_MEM_READ( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4577 PRE_MEM_WRITE( "_umtx_op_mutex_wake(mutex)", ARG1, sizeof(struct vki_umutex) );
4578 break;
4579 case VKI_UMTX_OP_SEM2_WAIT:
4580 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM2_WAIT, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4581 PRE_REG_READ3(long, "_umtx_op_sem2_wake",
4582 struct _usem2 *, obj, int, op, unsigned long, flags);
4583 PRE_MEM_READ( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4584 PRE_MEM_WRITE( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4585 *flags |= SfMayBlock;
4586 break;
4587 case VKI_UMTX_OP_SEM2_WAKE:
4588 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SEM2_WAKE, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4589 PRE_REG_READ3(long, "_umtx_op_sem2_wake",
4590 struct _usem2 *, obj, int, op, unsigned long, flags);
4591 PRE_MEM_READ( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4592 PRE_MEM_WRITE( "_umtx_op_sem2_wait(mutex)", ARG1, sizeof(struct vki_usem2) );
4593 break;
4594 case VKI_UMTX_OP_SHM:
4595 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, SHM, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4596 PRE_REG_READ4(long, "_umtx_op_shm",
4597 void *, obj, int, op, unsigned long, val, void*, uaddr);
4598 break;
4599 case VKI_UMTX_OP_ROBUST_LISTS:
4600 // val (ARG2) ought to be the same as sizeof(struct vki_umtx_robust_lists_params)
4601 // then the structure contains a pointer to mutex structures
4602 if (ARG1 != sizeof(struct vki_umtx_robust_lists_params)) {
4603 SET_STATUS_Failure( VKI_ENOSYS );
4605 PRINT( "sys__umtx_op ( %#" FMT_REGWORD "x, ROBUST_LISTS, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x)", ARG1, ARG3, ARG4, ARG5);
4606 PRE_REG_READ3(long, "_umtx_op_robust_lists",
4607 struct umtx_robust_lists_params *, obj, int, op, unsigned long, flags);
4608 PRE_MEM_READ( "_umtx_op_robust_lists(mutex)", ARG3, sizeof(struct vki_umtx_robust_lists_params) );
4609 break;
4610 default:
4611 VG_(umsg)("WARNING: _umtx_op unsupported value.\n");
4612 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);
4613 break;
4617 POST(sys__umtx_op)
4619 switch(ARG2) {
4620 case VKI_UMTX_OP_LOCK:
4621 case VKI_UMTX_OP_UNLOCK:
4622 if (SUCCESS) {
4623 POST_MEM_WRITE( ARG1, sizeof(struct vki_umtx) );
4625 break;
4626 case VKI_UMTX_OP_WAIT:
4627 case VKI_UMTX_OP_WAKE:
4628 case VKI_UMTX_OP_WAIT_UINT:
4629 case VKI_UMTX_OP_WAIT_UINT_PRIVATE:
4630 case VKI_UMTX_OP_WAKE_PRIVATE:
4631 break;
4632 case VKI_UMTX_OP_MUTEX_TRYLOCK:
4633 case VKI_UMTX_OP_MUTEX_LOCK:
4634 case VKI_UMTX_OP_MUTEX_UNLOCK:
4635 case VKI_UMTX_OP_MUTEX_WAIT: /* Sets/clears contested bits */
4636 case VKI_UMTX_OP_MUTEX_WAKE: /* Sets/clears contested bits */
4637 if (SUCCESS) {
4638 POST_MEM_WRITE( ARG1, sizeof(vki_uintptr_t) );
4640 break;
4641 case VKI_UMTX_OP_SET_CEILING:
4642 if (SUCCESS) {
4643 POST_MEM_WRITE( ARG1, sizeof(struct vki_umutex) );
4644 if (ARG4) {
4645 POST_MEM_WRITE( ARG4, sizeof(vki_uint32_t) );
4648 break;
4649 case VKI_UMTX_OP_CV_WAIT:
4650 if (SUCCESS) {
4651 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucond) );
4652 POST_MEM_WRITE( ARG4, sizeof(struct vki_umutex) );
4654 break;
4655 case VKI_UMTX_OP_CV_SIGNAL:
4656 case VKI_UMTX_OP_CV_BROADCAST:
4657 if (SUCCESS) {
4658 POST_MEM_WRITE( ARG1, sizeof(struct vki_ucond) );
4660 break;
4661 case VKI_UMTX_OP_RW_RDLOCK:
4662 case VKI_UMTX_OP_RW_WRLOCK:
4663 case VKI_UMTX_OP_RW_UNLOCK:
4664 if (SUCCESS) {
4665 POST_MEM_WRITE( ARG1, sizeof(struct vki_urwlock) );
4667 break;
4668 case VKI_UMTX_OP_SEM2_WAIT:
4669 case VKI_UMTX_OP_SEM2_WAKE:
4670 if (SUCCESS) {
4671 POST_MEM_WRITE( ARG1, sizeof(struct vki_usem2) );
4673 break;
4674 case VKI_UMTX_OP_SHM:
4675 case VKI_UMTX_OP_ROBUST_LISTS:
4676 default:
4677 break;
4681 // SYS_thr_new 455
4682 // x86/amd64
4684 // SYS_sigqueue 456
4685 // int sigqueue(pid_t pid, int signo, const union sigval value);
4686 PRE(sys_sigqueue)
4688 PRINT("sys_sigqueue ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",
4689 SARG1,SARG2,ARG3);
4690 PRE_REG_READ3(int, "sigqueue", vki_pid_t, pid, int, signo, const union vki_sigval, value);
4693 // SYS_kmq_open 457
4694 // mqd_t mq_open(const char *name, int oflag, ...);
4695 // int kmq_open(_In_z_ const char *path, int flags, mode_t mode, _In_opt_ const struct mq_attr *attr);
4696 PRE(sys_kmq_open)
4698 if (ARG2 & VKI_O_CREAT) {
4699 PRINT("sys_kmq_open( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu, %#" FMT_REGWORD "x )",
4700 ARG1,(char *)ARG1,ARG2,(vki_mode_t)ARG3,ARG4);
4701 PRE_REG_READ4(long, "mq_open",
4702 const char *, name, int, oflag, vki_mode_t, mode,
4703 struct mq_attr *, attr);
4704 } else {
4705 PRINT("sys_kmq_open( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu)",
4706 ARG1,(char *)ARG1,ARG2,(vki_mode_t)ARG3);
4707 PRE_REG_READ3(long, "mq_open",
4708 const char *, name, int, oflag, vki_mode_t, mode);
4710 PRE_MEM_RASCIIZ( "mq_open(name)", ARG1 );
4711 if (ARG2 & VKI_O_CREAT) {
4712 PRE_MEM_READ("mq_open(attr)", ARG4, sizeof(struct vki_mq_attr));
4713 if (ML_(safe_to_deref)((struct vki_mq_attr *)ARG4, sizeof(struct vki_mq_attr))) {
4714 const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG4;
4715 PRE_MEM_READ("mq_open(attr->mq_maxmsg)",
4716 (Addr)&attr->mq_maxmsg, sizeof(attr->mq_maxmsg) );
4717 PRE_MEM_READ("mq_open(attr->mq_msgsize)",
4718 (Addr)&attr->mq_msgsize, sizeof(attr->mq_msgsize) );
4723 POST(sys_kmq_open)
4725 vg_assert(SUCCESS);
4726 if (!ML_(fd_allowed)(RES, "mq_open", tid, True)) {
4727 VG_(close)(RES);
4728 SET_STATUS_Failure( VKI_EMFILE );
4729 } else {
4730 if (VG_(clo_track_fds)) {
4731 ML_(record_fd_open_with_given_name)(tid, RES, (const HChar*)ARG1);
4736 // SYS_kmq_setattr 458
4737 // int mq_setattr(mqd_t mqdes, const struct mq_attr *restrict mqstat,
4738 // struct mq_attr *restrict omqstat);
4739 PRE(sys_kmq_setattr)
4741 PRINT("sys_kmq_getattr( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1,ARG2,ARG3 );
4742 PRE_REG_READ3(int, "mq_setattr",
4743 vki_mqd_t, mqdes, const struct mq_attr *, mqstat,
4744 struct mq_attr *, omqstat);
4745 if (!ML_(fd_allowed)(ARG1, "mq_getattr", tid, False)) {
4746 SET_STATUS_Failure( VKI_EBADF );
4747 } else {
4748 if (ML_(safe_to_deref)((struct vki_mq_attr *)ARG2, sizeof(struct vki_mq_attr))) {
4749 const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG2;
4750 PRE_MEM_READ( "mq_setattr(mqstat->mq_flags)",
4751 (Addr)&attr->mq_flags, sizeof(attr->mq_flags) );
4753 PRE_MEM_WRITE( "mq_setattr(omqstat)", ARG3,
4754 sizeof(struct vki_mq_attr) );
4758 // SYS_kmq_timedreceive 459
4759 // ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
4760 // unsigned *msg_prio, const struct timespec *abs_timeout);
4761 PRE(sys_kmq_timedreceive)
4763 *flags |= SfMayBlock;
4764 PRINT("sys_kmq_timedreceive( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %llu, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
4765 ARG1,ARG2,(ULong)ARG3,ARG4,ARG5);
4766 PRE_REG_READ5(ssize_t, "mq_timedreceive",
4767 vki_mqd_t, mqdes, char *, msg_ptr, vki_size_t, msg_len,
4768 unsigned int *, msg_prio,
4769 const struct timespec *, abs_timeout);
4770 if (!ML_(fd_allowed)(ARG1, "mq_timedreceive", tid, False)) {
4771 SET_STATUS_Failure( VKI_EBADF );
4772 } else {
4773 PRE_MEM_WRITE( "mq_timedreceive(msg_ptr)", ARG2, ARG3 );
4774 if (ARG4 != 0) {
4775 PRE_MEM_WRITE( "mq_timedreceive(msg_prio)",
4776 ARG4, sizeof(unsigned int) );
4778 if (ARG5 != 0) {
4779 PRE_MEM_READ( "mq_timedreceive(abs_timeout)",
4780 ARG5, sizeof(struct vki_timespec) );
4785 POST(sys_kmq_timedreceive)
4787 POST_MEM_WRITE( ARG2, ARG3 );
4788 if (ARG4 != 0) {
4789 POST_MEM_WRITE( ARG4, sizeof(unsigned int) );
4793 // SYS_kmq_timedsend 460
4794 // int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
4795 // unsigned msg_prio, const struct timespec *abs_timeout);
4796 PRE(sys_kmq_timedsend)
4798 *flags |= SfMayBlock;
4799 PRINT("sys_kmq_timedsend ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %llu, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",
4800 ARG1,ARG2,(ULong)ARG3,ARG4,ARG5);
4801 PRE_REG_READ5(int, "mq_timedsend",
4802 vki_mqd_t, mqdes, const char *, msg_ptr, vki_size_t, msg_len,
4803 unsigned int, msg_prio, const struct timespec *, abs_timeout);
4804 if (!ML_(fd_allowed)(ARG1, "mq_timedsend", tid, False)) {
4805 SET_STATUS_Failure( VKI_EBADF );
4806 } else {
4807 PRE_MEM_READ( "mq_timedsend(msg_ptr)", ARG2, ARG3 );
4808 if (ARG5 != 0) {
4809 PRE_MEM_READ( "mq_timedsend(abs_timeout)", ARG5,
4810 sizeof(struct vki_timespec) );
4815 // SYS_kmq_notify 461
4816 // int mq_notify(mqd_t mqdes, const struct sigevent *notification);
4817 PRE(sys_kmq_notify)
4819 PRINT("sys_kmq_notify( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2 );
4820 PRE_REG_READ2(int, "mq_notify",
4821 vki_mqd_t, mqdes, const struct sigevent *, notification);
4822 if (!ML_(fd_allowed)(ARG1, "mq_notify", tid, False)) {
4823 SET_STATUS_Failure( VKI_EBADF );
4825 else if (ARG2 != 0) {
4826 PRE_MEM_READ( "mq_notify(notification)",
4827 ARG2, sizeof(struct vki_sigevent) );
4831 // SYS_kmq_unlink 462
4832 // int kmq_unlink(const char *path);
4833 PRE(sys_kmq_unlink)
4835 PRINT("sys_kmq_unlink ( %#" FMT_REGWORD "x(%s) )", ARG1,(char *)ARG1);
4836 PRE_REG_READ1(int, "mq_unlink", const char *, name);
4837 PRE_MEM_RASCIIZ( "mq_unlink(name)", ARG1 );
4840 // SYS_abort2 463
4841 // void abort2(const char *why, int nargs, void **args);
4842 PRE(sys_abort2)
4844 PRINT( "sys_abort2 ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", ARG1, SARG2, ARG3 );
4845 PRE_REG_READ3(void, "abort2", const char *, why, int, nargs, void **, args);
4846 // max length of 'why' is 128
4847 PRE_MEM_RASCIIZ( "abort2(why)", ARG2);
4848 // max val for nargs is 16
4849 PRE_MEM_READ("abort2(args", ARG3, ARG2*sizeof(void*));
4852 // SYS_thr_set_name 464
4853 // int thr_set_name(long id, const char *name);
4854 PRE(sys_thr_set_name)
4856 PRINT( "sys_thr_set_name ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1, ARG2 );
4857 PRE_REG_READ2(int, "thr_set_name", long, id, const char *, name);
4858 PRE_MEM_RASCIIZ( "thr_set_name(name)", ARG2);
4860 if (ML_(safe_to_deref)((void*)ARG2, 1)) {
4861 const HChar* new_name = (const HChar*) (Addr)ARG2;
4862 ThreadState* tst = VG_(get_ThreadState)(tid);
4863 SizeT new_len = VG_(strnlen)(new_name, VKI_MAXCOMLEN+1);
4864 tst->thread_name = VG_(realloc)("syswrap.thr_set_name", tst->thread_name, new_len + 1);
4865 VG_(strlcpy)(tst->thread_name, new_name, new_len + 1);
4869 // SYS_aio_fsync 465
4870 // int aio_fsync(int op, struct aiocb *iocb);
4871 PRE(sys_aio_fsync)
4873 PRINT("aio_fsync ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,ARG2);
4874 PRE_REG_READ2(int, "aio_fsync", int, op, struct vki_aiocb *, iocb);
4875 PRE_MEM_READ( "aio_fsync(iocb)", ARG2, sizeof(struct vki_aiocb) );
4878 // SYS_rtprio_thread 466
4879 // int rtprio_thread(int function, lwpid_t lwpid, struct rtprio *rtp);
4880 PRE(sys_rtprio_thread)
4882 PRINT( "sys_rtprio_thread ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1, ARG2, ARG3 );
4883 PRE_REG_READ3(int, "rtprio_thread",
4884 int, function, __vki_lwpid_t, lwpid, struct vki_rtprio *, rtp);
4885 if (ARG1 == VKI_RTP_SET) {
4886 PRE_MEM_READ( "rtprio_thread(rtp#set)", ARG3, sizeof(struct vki_rtprio));
4887 } else if (ARG1 == VKI_RTP_LOOKUP) {
4888 PRE_MEM_WRITE( "rtprio_thread(rtp#lookup)", ARG3, sizeof(struct vki_rtprio));
4889 } else {
4890 /* PHK ?? */
4894 POST(sys_rtprio_thread)
4896 if (ARG1 == VKI_RTP_LOOKUP && RES == 0) {
4897 POST_MEM_WRITE( ARG3, sizeof(struct vki_rtprio));
4901 // SYS_sctp_peeloff 471
4902 // int sctp_peeloff(int s, sctp_assoc_t id);
4903 // @todo
4906 // SYS_sctp_generic_sendmsg 472
4907 // int sctp_generic_sendmsg(int s, void *msg, int msglen, struct sockaddr *to,
4908 // socklen_t len, struct sctp_sndrcvinfo *sinfo, int flags);
4910 // Not called directly from libc
4911 PRE(sys_sctp_generic_sendmsg)
4913 *flags |= SfMayBlock;
4914 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);
4915 PRE_REG_READ7(ssize_t, "sctp_generic_sendmsg",
4916 int, s, void *, msg, int, msglen,
4917 struct sockaddr *, to, socklen_t, len,
4918 struct sctp_sndrcvinfo *, sinfo, int, flags);
4920 PRE_MEM_READ( "sctp_generic_sendmsg(msg)", ARG2, ARG3);
4922 ML_(pre_mem_read_sockaddr) (tid, "sctp_generic_sendmsg(to)", (struct vki_sockaddr *)ARG4, ARG5);
4924 if (ARG6 != (Addr)NULL) {
4925 PRE_MEM_READ( "sctp_generic_sendmsg(sinfo)", ARG6, sizeof(struct vki_sctp_sndrcvinfo));
4929 // SYS_sctp_generic_sendmsg_iov 473
4930 // int sctp_generic_sendmsg_iov(int s, struct iovec *iov, int iovlen,
4931 // struct sockaddr *to, struct sctp_sndrcvinfo *sinfo, int flags);
4932 // @todo
4934 // SYS_sctp_generic_recvmsg 474
4935 // int sctp_generic_recvmsg(int s, struct iovec *iov, int iovlen,
4936 // struct sockaddr *from, socklen_t *fromlen,
4937 // struct sctp_sndrcvinfo *sinfo, int *msgflags);
4939 // Not called directly from libc
4940 PRE(sys_sctp_generic_recvmsg)
4942 *flags |= SfMayBlock;
4943 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);
4944 PRE_REG_READ7(ssize_t, "sctp_generic_recvmsg",
4945 int, s, struct iovec *, iov, int, iovlen,
4946 struct sockaddr *, from, socklen_t *, fromlen,
4947 struct sctp_sndrcvinfo *, sinfo, int *, msgflags);
4949 // in the sctp_recvmsg libc wrapper this is always 1
4950 if ((Int)ARG3 > 0) {
4951 PRE_MEM_READ( "sctp_generic_recvmsg(iov)", ARG2, ARG3 * sizeof(struct vki_iovec) );
4953 if (ML_(safe_to_deref)((const void*)ARG2, ARG3 * sizeof(struct vki_iovec))) {
4954 struct vki_iovec* iovec = (struct vki_iovec*)ARG2;
4955 PRE_MEM_WRITE("sctp_generic_recvmsg(iov.iov_base)", (Addr)iovec->iov_base, iovec->iov_len);
4958 if (ARG4 != (Addr)NULL) {
4959 ML_(buf_and_len_pre_check) (tid, ARG4, ARG5,
4960 "sctp_generic_recvmsg(from)",
4961 "sctp_generic_recvmsg(fromlen_in)");
4964 if (ARG6 != (Addr)NULL) {
4965 PRE_MEM_WRITE("sctp_generic_recvmsg(sinfo)", ARG6, sizeof(struct vki_sctp_sndrcvinfo));
4968 if (ARG7 != (Addr)NULL) {
4969 PRE_MEM_WRITE("sctp_generic_recvmsg(msgflags)", ARG7, sizeof(int));
4973 POST(sys_sctp_generic_recvmsg)
4975 vg_assert(SUCCESS);
4976 struct vki_iovec* iovec = (struct vki_iovec*)ARG2;
4977 POST_MEM_WRITE((Addr)iovec->iov_base, iovec->iov_len);
4979 POST_MEM_WRITE( ARG2, ARG3*sizeof(struct vki_iovec) );
4981 if (ARG4 != (Addr)NULL) {
4982 ML_(buf_and_len_post_check) (tid, VG_(mk_SysRes_Success)(RES), ARG4, ARG5,
4983 "sctp_generic_recvmsg(fromlen_out)");
4986 if (ARG6 != (Addr)NULL) {
4987 POST_MEM_WRITE(ARG6, sizeof(struct vki_sctp_sndrcvinfo));
4990 if (ARG7 != (Addr)NULL) {
4991 POST_MEM_WRITE(ARG7, sizeof(int));
4995 // SYS_pread 475
4996 // x86/amd64
4998 // SYS_pwrite 476
4999 // x86/amd64
5001 // SYS_mmap 477
5002 // x86/amd64
5004 // SYS_lseek 478
5005 // x86/amd64
5007 //SYS_truncate 479
5008 // x86/amd64
5010 // SYS_ftruncate 480
5011 // x86/amd64
5013 // SYS_thr_kill2 481
5014 // int thr_kill2(pid_t pid, long id, int sig);
5015 PRE(sys_thr_kill2)
5017 PRINT("sys_thr_kill2 ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3);
5018 PRE_REG_READ3(int, "thr_kill2", pid_t, pid, long, tid, int, sig);
5019 if (!ML_(client_signal_OK)(ARG3)) {
5020 SET_STATUS_Failure( VKI_EINVAL );
5021 return;
5024 /* Check to see if this kill gave us a pending signal */
5025 *flags |= SfPollAfter;
5027 if (VG_(clo_trace_signals)) {
5028 VG_(message)(Vg_DebugMsg, "thr_kill2: sending signal %lu to pid %lu/%lu\n",
5029 ARG3, ARG1, ARG2);
5032 /* If we're sending SIGKILL, check to see if the target is one of
5033 our threads and handle it specially. */
5034 if (ARG3 == VKI_SIGKILL && ML_(do_sigkill)(ARG2, ARG1)) {
5035 SET_STATUS_Success(0);
5036 return;
5039 /* Ask to handle this syscall via the slow route, since that's the
5040 only one that sets tst->status to VgTs_WaitSys. If the result
5041 of doing the syscall is an immediate run of
5042 async_signalhandler() in m_signals, then we need the thread to
5043 be properly tidied away. I have the impression the previous
5044 version of this wrapper worked on x86/amd64 only because the
5045 kernel did not immediately deliver the async signal to this
5046 thread (on ppc it did, which broke the assertion re tst->status
5047 at the top of async_signalhandler()). */
5048 *flags |= SfMayBlock;
5051 POST(sys_thr_kill2)
5053 if (VG_(clo_trace_signals)) {
5054 VG_(message)(Vg_DebugMsg, "thr_kill2: sent signal %lu to pid %lu/%lu\n",
5055 ARG3, ARG1, ARG2);
5059 // SYS_shm_open 482
5060 // int shm_open(const char *path, int flags, mode_t mode);
5061 PRE(sys_shm_open)
5063 PRE_REG_READ3(int, "shm_open",
5064 const char *, path, int, flags, vki_mode_t, mode);
5065 if (ARG1 == VKI_SHM_ANON) {
5066 PRINT("sys_shm_open(%#" FMT_REGWORD "x(SHM_ANON), %" FMT_REGWORD "u, %hu)", ARG1, ARG2, (vki_mode_t)ARG3);
5067 } else {
5068 PRINT("sys_shm_open(%#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu)", ARG1, (HChar *)ARG1, ARG2, (vki_mode_t)ARG3);
5069 PRE_MEM_RASCIIZ( "shm_open(path)", ARG1 );
5071 *flags |= SfMayBlock;
5074 POST(sys_shm_open)
5076 vg_assert(SUCCESS);
5077 if (!ML_(fd_allowed)(RES, "shm_open", tid, True)) {
5078 VG_(close)(RES);
5079 SET_STATUS_Failure( VKI_EMFILE );
5080 } else {
5081 if (VG_(clo_track_fds)) {
5082 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1);
5087 // SYS_shm_unlink 483
5088 // int shm_unlink(const char *path);
5089 PRE(sys_shm_unlink)
5091 PRINT("sys_shm_unlink(%#" FMT_REGWORD "x(%s))", ARG1, (char *)ARG1);
5092 PRE_REG_READ1(int, "shm_unlink",
5093 const char *, path);
5095 PRE_MEM_RASCIIZ( "shm_unlink(path)", ARG1 );
5097 *flags |= SfMayBlock;
5100 // SYS_cpuset 484
5101 // int cpuset(cpusetid_t *setid);
5102 PRE(sys_cpuset)
5104 PRINT("sys_cpuset ( %#" FMT_REGWORD "x )", ARG1);
5105 PRE_REG_READ1(int, "cpuset", vki_cpusetid_t *, setid);
5106 PRE_MEM_WRITE("cpuset(setid)", ARG1, sizeof(vki_cpusetid_t));
5109 POST(sys_cpuset)
5111 POST_MEM_WRITE(ARG1, sizeof(vki_cpusetid_t));
5114 // SYS_cpuset_setid 485
5115 // amd64 / x86
5117 // SYS_cpuset_getid 486
5118 // amd64 / x86
5120 // SYS_cpuset_getaffinity 487
5121 // amd64 / x86
5123 // SYS_cpuset_setaffinity 488
5124 // amd64 / x86
5126 // SYS_faccessat 489
5127 // int faccessat(int fd, const char *path, int mode, int flag);
5128 PRE(sys_faccessat)
5130 PRINT("sys_faccessat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,ARG2,(char*)ARG2,ARG3);
5131 PRE_REG_READ3(int, "faccessat",
5132 int, fd, const char *, path, int, flag);
5133 PRE_MEM_RASCIIZ( "faccessat(path)", ARG2 );
5136 // SYS_fchmodat 490
5137 // int fchmodat(int fd, const char *path, mode_t mode, int flag);
5138 PRE(sys_fchmodat)
5140 PRINT("sys_fchmodat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,ARG2,(char*)ARG2,ARG3);
5141 PRE_REG_READ4(int, "fchmodat",
5142 int, fd, const char *, path, vki_mode_t, mode, int, flag);
5143 PRE_MEM_RASCIIZ( "fchmodat(path)", ARG2 );
5146 // SYS_fchownat 491
5147 // int fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag);
5148 PRE(sys_fchownat)
5150 PRINT("sys_fchownat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x, 0x%" FMT_REGWORD "x, %" FMT_REGWORD "d )",
5151 ARG1,ARG2,(char*)ARG2,ARG3,ARG4, SARG5);
5152 PRE_REG_READ5(int, "fchownat",
5153 int, fd, const char *, path,
5154 vki_uid_t, owner, vki_gid_t, group, int, flag);
5155 PRE_MEM_RASCIIZ( "fchownat(path)", ARG2 );
5158 // SYS_fexecve 492
5159 // int fexecve(int fd, char *const argv[], char *const envp[]);
5160 PRE(sys_fexecve)
5162 PRINT("sys_fexecve ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
5163 SARG1,ARG2,ARG3);
5164 PRE_REG_READ3(int, "fexecve",
5165 int, fd, char * const *, argv,
5166 char * const *, envp);
5168 if (!ML_(fd_allowed)(ARG1, "fexecve", tid, False)) {
5169 SET_STATUS_Failure(VKI_EBADF);
5170 return;
5173 const HChar *fname;
5175 if (VG_(resolve_filename)(ARG1, &fname) == False) {
5176 SET_STATUS_Failure(VKI_ENOENT);
5177 return;
5180 struct vg_stat stats;
5181 if (VG_(fstat)(ARG1, &stats) != 0) {
5182 SET_STATUS_Failure(VKI_EACCES);
5183 return;
5186 Int openFlags;
5188 if (VG_(resolve_filemode)(ARG1, &openFlags) == False) {
5189 SET_STATUS_Failure(VKI_ENOENT);
5190 return;
5194 * openFlags is in kernel FFLAGS format
5195 * (see /usr/include/sys/fcntl.h)
5196 * which alllows us to tell if RDONLY is set
5200 Bool isScript = False;
5202 SysRes res;
5203 res = VG_(open)(fname, VKI_O_RDONLY,
5204 VKI_S_IRUSR|VKI_S_IRGRP|VKI_S_IROTH);
5205 if (sr_isError(res)) {
5206 SET_STATUS_Failure(VKI_ENOENT);
5207 return;
5210 char buf[2];
5211 VG_(read)((Int)sr_Res(res), buf, 2);
5212 VG_(close)((Int)sr_Res(res));
5213 if (buf[0] == '#' && buf[1] == '!') {
5214 isScript = True;
5217 if (isScript) {
5218 if (!(openFlags & VKI_FREAD)) {
5219 SET_STATUS_Failure(VKI_EACCES);
5220 return;
5222 } else {
5223 if (!((openFlags & VKI_O_EXEC) ||
5224 (stats.mode & (VKI_S_IXUSR|VKI_S_IXGRP|VKI_S_IXOTH)))) {
5225 SET_STATUS_Failure(VKI_EACCES);
5226 return;
5230 Addr arg_2 = (Addr)ARG2;
5231 Addr arg_3 = (Addr)ARG3;
5233 handle_pre_sys_execve(tid, status, (Addr)fname, arg_2, arg_3, FEXECVE, False);
5236 // SYS_freebsd11_fstatat 493
5237 // int fstatat(int fd, const char *path, struct stat *sb, int flag);
5238 #if (FREEBSD_VERS >= FREEBSD_12)
5239 PRE(sys_freebsd11_fstatat)
5241 PRINT("sys_freebsd11_fstatat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3);
5242 PRE_REG_READ4(int, "fstatat",
5243 int, fd, const char *, path, struct freebsd11_stat *, buf, int, flag);
5244 PRE_MEM_RASCIIZ( "fstatat(path)", ARG2 );
5245 PRE_MEM_WRITE( "fstatat(sb)", ARG3, sizeof(struct vki_freebsd11_stat) );
5248 POST(sys_freebsd11_fstatat)
5250 POST_MEM_WRITE( ARG3, sizeof(struct vki_freebsd11_stat) );
5252 #else
5253 PRE(sys_fstatat)
5255 PRINT("sys_fstatat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3);
5256 PRE_REG_READ4(int, "fstatat",
5257 int, fd, const char *, path, struct stat *, buf, int, flag);
5258 PRE_MEM_RASCIIZ( "fstatat(path)", ARG2 );
5259 PRE_MEM_WRITE( "fstatat(sb)", ARG3, sizeof(struct vki_freebsd11_stat) );
5262 POST(sys_fstatat)
5264 POST_MEM_WRITE( ARG3, sizeof(struct vki_freebsd11_stat) );
5266 #endif
5268 // SYS_futimesat 494
5269 // int futimesat(int fd, const char *path, const struct timeval times[2]);
5270 PRE(sys_futimesat)
5272 PRINT("sys_futimesat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3);
5273 PRE_REG_READ3(int, "futimesat",
5274 int, fd, const char *, path, struct timeval *, times);
5275 if (ARG2 != 0) {
5276 PRE_MEM_RASCIIZ( "futimesat(path)", ARG2 );
5278 if (ARG3 != 0) {
5279 PRE_MEM_READ( "futimesat(times)", ARG3, 2 * sizeof(struct vki_timeval) );
5283 // SYS_linkat 495
5284 // int linkat(int fd1, const char *name1, int fd2, const char *name2, int flag);
5285 PRE(sys_linkat)
5287 *flags |= SfMayBlock;
5288 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);
5289 PRE_REG_READ5(int, "linkat",
5290 int, fd1, const char *, name1,
5291 int, fd2, const char *, name2,
5292 int, flag);
5293 PRE_MEM_RASCIIZ( "linkat(name1)", ARG2);
5294 PRE_MEM_RASCIIZ( "linkat(name2)", ARG4);
5297 // SYS_mkdirat 496
5298 // int mkdirat(int fd, const char *path, mode_t mode);
5299 PRE(sys_mkdirat)
5301 *flags |= SfMayBlock;
5302 PRINT("sys_mkdirat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,ARG2,(char*)ARG2,ARG3);
5303 PRE_REG_READ3(int, "mkdirat",
5304 int, fd, const char *, path, int, mode);
5305 PRE_MEM_RASCIIZ( "mkdirat(path)", ARG2 );
5308 // SYS_mkfifoat 497
5309 // int mkfifoat(int fd, const char *path, mode_t mode);
5310 PRE(sys_mkfifoat)
5312 PRINT("sys_mkfifoat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x )",
5313 SARG1,ARG2,(HChar*)ARG2,ARG3 );
5314 PRE_REG_READ3(int, "mkfifoat",
5315 int, fd, const char *, path, vki_mode_t, mode);
5316 PRE_MEM_RASCIIZ( "mkfifoat(path)", ARG2 );
5319 // SYS_freebsd11_mknodat 498
5320 // int mknodat(int fd, const char *path, mode_t mode, dev_t dev);
5321 #if (FREEBSD_VERS >= FREEBSD_12)
5322 PRE(sys_freebsd11_mknodat)
5324 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 );
5325 PRE_REG_READ4(long, "mknodat",
5326 int, dfd, const char *, pathname, int, mode, unsigned, dev);
5327 PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2 );
5329 #else
5330 PRE(sys_mknodat)
5332 PRINT("sys_mknodat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x, 0x%" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4 );
5333 PRE_REG_READ4(long, "mknodat",
5334 int, dfd, const char *, pathname, int, mode, unsigned, dev);
5335 PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2 );
5337 #endif
5339 // SYS_openat 499
5340 // int openat(int fd, const char *path, int flags, ...);
5341 PRE(sys_openat)
5344 if (ARG3 & VKI_O_CREAT) {
5345 // 4-arg version
5346 PRINT("sys_openat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,(char*)ARG2,ARG3,ARG4);
5347 PRE_REG_READ4(int, "openat",
5348 int, fd, const char *, path, int, flags, vki_mode_t, mode);
5349 } else {
5350 // 3-arg version
5351 PRINT("sys_openat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )",ARG1,ARG2,(char*)ARG2,ARG3);
5352 PRE_REG_READ3(int, "openat",
5353 int, fd, const char *, path, int, flags);
5356 if (ARG1 != (unsigned)VKI_AT_FDCWD && !ML_(fd_allowed)(ARG1, "openat", tid, False)) {
5357 SET_STATUS_Failure( VKI_EBADF );
5358 } else {
5359 PRE_MEM_RASCIIZ( "openat(path)", ARG2 );
5362 /* Otherwise handle normally */
5363 *flags |= SfMayBlock;
5366 POST(sys_openat)
5368 vg_assert(SUCCESS);
5369 if (!ML_(fd_allowed)(RES, "openat", tid, True)) {
5370 VG_(close)(RES);
5371 SET_STATUS_Failure( VKI_EMFILE );
5372 } else {
5373 if (VG_(clo_track_fds)) {
5374 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG2);
5379 // SYS_readlinkat 500
5380 // ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf,
5381 // size_t bufsize);
5382 PRE(sys_readlinkat)
5384 Word saved = SYSNO;
5385 Bool curproc_file = False;
5387 PRINT("sys_readlinkat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %llu )", ARG1,ARG2,(char*)ARG2,ARG3,(ULong)ARG4);
5388 PRE_REG_READ4(ssize_t, "readlinkat",
5389 int, fd, const char *, path, char *, buf, int, bufsize);
5390 PRE_MEM_RASCIIZ( "readlinkat(path)", ARG2 );
5391 PRE_MEM_WRITE( "readlinkat(buf)", ARG3,ARG4 );
5393 if (VG_(have_slash_proc) == True && (Int)ARG1 == VKI_AT_FDCWD) {
5395 * Handle the case where readlinkat is looking at /proc/curproc/file or
5396 * /proc/<pid>/file.
5398 do_readlink((const HChar *)ARG2, (HChar *)ARG3, (SizeT)ARG4, status, &curproc_file);
5401 // @todo PJF there is still the case where fd refers to /proc or /proc/pid
5402 // or /proc/curproc and path is relative pid/file, curptoc/file or just file
5404 if (!curproc_file) {
5405 /* Normal case */
5406 SET_STATUS_from_SysRes( VG_(do_syscall4)(saved, ARG1, ARG2, ARG3, ARG4));
5408 if (SUCCESS && RES > 0) {
5409 POST_MEM_WRITE( ARG3, RES );
5413 POST(sys_readlinkat)
5415 POST_MEM_WRITE( ARG3, RES );
5418 // SYS_renameat 501
5419 // int renameat(int fromfd, const char *from, int tofd, const char *to);
5420 PRE(sys_renameat)
5422 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);
5423 PRE_REG_READ4(int, "renameat",
5424 int, fromfd, const char *, from,
5425 int, tofd, const char *, to);
5426 PRE_MEM_RASCIIZ( "renameat(oldpath)", ARG2 );
5427 PRE_MEM_RASCIIZ( "renameat(newpath)", ARG4 );
5430 // SYS_symlinkat 502
5431 // int symlinkat(const char *name1, int fd, const char *name2);
5432 PRE(sys_symlinkat)
5434 *flags |= SfMayBlock;
5435 PRINT("sys_symlinkat ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s) )",ARG1,(char*)ARG1,ARG2,ARG3,(char*)ARG3);
5436 PRE_REG_READ3(int, "symlinkat",
5437 const char *, name1, int, fd, const char *, name2);
5438 PRE_MEM_RASCIIZ( "symlinkat(name1)", ARG1 );
5439 PRE_MEM_RASCIIZ( "symlinkat(name2)", ARG3 );
5442 // SYS_unlinkat 503
5443 // int unlinkat(int fd, const char *path, int flag);
5444 PRE(sys_unlinkat)
5446 *flags |= SfMayBlock;
5447 PRINT("sys_unlinkat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u ",
5448 ARG1, ARG2, (char*)ARG2, ARG3);
5449 PRE_REG_READ3(int, "unlinkat", int, fd, const char *, path, int, flag);
5450 PRE_MEM_RASCIIZ( "unlinkat(path)", ARG2 );
5453 // SYS_posix_openpt 504
5454 // int posix_openpt(int oflag);
5455 PRE(sys_posix_openpt)
5457 PRINT("sys_posix_openpt ( %" FMT_REGWORD "d )", SARG1);
5458 PRE_REG_READ1(int, "posix_openpt", int, oflag);
5461 // SYS_gssd_syscall 505
5462 // @todo
5463 // see https://www.freebsd.org/cgi/man.cgi?format=html&query=gssapi(3)
5464 // syscalls.master says ; 505 is initialised by the kgssapi code, if present.
5466 // SYS_jail_get 506
5467 // int jail_get(struct iovec *iov, u_int niov, int flags);
5468 PRE(sys_jail_get)
5470 PRINT("sys_jail_get ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
5471 PRE_REG_READ3(int, "jail_get", struct vki_iovec *, iov, unsigned int,
5472 niov, int, flags);
5473 PRE_MEM_READ("jail_get(iov)", ARG1, ARG2 * sizeof(struct vki_iovec));
5476 // SYS_jail_set 507
5477 // int jail_set(struct iovec *iov, u_int niov, int flags);
5478 PRE(sys_jail_set)
5480 PRINT("sys_jail_set ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
5481 PRE_REG_READ3(int, "jail_set", struct vki_iovec *, iov, unsigned int,
5482 niov, int, flags);
5483 PRE_MEM_READ("jail_set(iovs)", ARG1, ARG2 * sizeof(struct vki_iovec));
5486 // SYS_jail_remove 508
5487 // int jail_remove(int jid);
5488 PRE(sys_jail_remove)
5490 PRINT("sys_jail_remove ( %" FMT_REGWORD "d )", SARG1);
5491 PRE_REG_READ1(int, "jail_remove", int, jid);
5494 // SYS_closefrom 509
5495 // void closefrom(int lowfd);
5496 PRE(sys_closefrom)
5498 PRINT("sys_closefrom ( %" FMT_REGWORD "dx )", SARG1);
5499 PRE_REG_READ1(int, "closefrom", int, lowfd);
5502 * Can't pass this on to the kernel otherwise it will close
5503 * all of the host files like the log
5506 for (int i = ARG1; i < VG_(fd_soft_limit); ++i) {
5507 VG_(close)(i);
5510 SET_STATUS_Success(0);
5513 // SYS___semctl 510
5514 // int semctl(int semid, int semnum, int cmd, ...);
5515 // int __semctl(int semid, int semnum, int cmd, _Inout_ union semun *arg);
5516 PRE(sys___semctl)
5518 switch (ARG3) {
5519 case VKI_IPC_INFO:
5520 case VKI_SEM_INFO:
5521 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
5522 PRE_REG_READ4(int, "semctl",
5523 int, semid, int, semnum, int, cmd, struct seminfo *, arg);
5524 break;
5525 case VKI_IPC_STAT:
5526 case VKI_SEM_STAT:
5527 case VKI_IPC_SET:
5528 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
5529 PRE_REG_READ4(long, "semctl",
5530 int, semid, int, semnum, int, cmd, struct semid_ds *, arg);
5531 break;
5532 case VKI_GETALL:
5533 case VKI_SETALL:
5534 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4);
5535 PRE_REG_READ4(long, "semctl",
5536 int, semid, int, semnum, int, cmd, unsigned short *, arg);
5537 break;
5538 default:
5539 PRINT("sys_semctl ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
5540 PRE_REG_READ3(long, "semctl",
5541 int, semid, int, semnum, int, cmd);
5542 break;
5544 ML_(generic_PRE_sys_semctl)(tid, ARG1,ARG2,ARG3,ARG4);
5547 POST(sys___semctl)
5549 ML_(generic_POST_sys_semctl)(tid, RES,ARG1,ARG2,ARG3,ARG4);
5552 // SYS_msgctl 511
5553 // int msgctl(int msqid, int cmd, struct msqid_ds *buf);
5554 PRE(sys_msgctl)
5556 PRINT("sys_msgctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3 );
5558 PRE_REG_READ3(int, "msgctl", int, msqid, int, cmd, struct msqid_ds *, buf);
5560 switch (ARG2 /* cmd */) {
5561 case VKI_IPC_STAT:
5562 PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)",
5563 ARG3, sizeof(struct vki_msqid_ds) );
5564 break;
5565 case VKI_IPC_SET:
5566 PRE_MEM_READ( "msgctl(IPC_SET, buf)",
5567 ARG3, sizeof(struct vki_msqid_ds) );
5568 break;
5572 POST(sys_msgctl)
5574 switch (ARG2 /* cmd */) {
5575 case VKI_IPC_STAT:
5576 POST_MEM_WRITE( ARG3, sizeof(struct vki_msqid_ds) );
5577 break;
5582 // SYS_shmctl 512
5583 // int shmctl(int shmid, int cmd, struct shmid_ds *buf);
5584 PRE(sys_shmctl)
5586 PRINT("sys_shmctl ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,SARG2,ARG3);
5587 PRE_REG_READ3(int, "shmctl",
5588 int, shmid, int, cmd, struct vki_shmid_ds *, buf);
5589 switch (ARG2 /* cmd */) {
5590 case VKI_IPC_STAT:
5591 PRE_MEM_WRITE( "shmctl(IPC_STAT, buf)",
5592 ARG3, sizeof(struct vki_shmid_ds) );
5593 break;
5594 case VKI_IPC_SET:
5595 PRE_MEM_READ( "shmctl(IPC_SET, buf)",
5596 ARG3, sizeof(struct vki_shmid_ds) );
5597 break;
5601 POST(sys_shmctl)
5603 if (ARG2 == VKI_IPC_STAT) {
5604 POST_MEM_WRITE( ARG3, sizeof(struct vki_shmid_ds) );
5608 // SYS_lpathconf 513
5609 // long lpathconf(const char *path, int name);
5610 PRE(sys_lpathconf)
5612 PRINT("sys_lpathconf ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d)", ARG1, SARG2);
5613 PRE_REG_READ2(long, "lpathconf", const char *, path, int, name);
5614 PRE_MEM_RASCIIZ("lpathconf(path)", ARG1);
5617 // SYS___cap_rights_get 515
5618 // note extra 1st argument for the internal function which is not present
5619 // in the public interface
5620 // int __cap_rights_get(int version, int fd, cap_rights_t *rights);
5621 PRE(sys_cap_rights_get)
5623 PRINT("sys_cap_rights_get ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, SARG2, ARG3);
5624 PRE_REG_READ3(long, "cap_rights_get", int, version, int, fd, vki_cap_rights_t*, rights);
5625 PRE_MEM_WRITE("cap_rights_get(rights)", ARG3, sizeof(vki_cap_rights_t));
5628 POST(sys_cap_rights_get)
5630 POST_MEM_WRITE(ARG2, sizeof(vki_cap_rights_t));
5633 // SYS_cap_enter 516
5634 // int cap_enter(void);
5635 PRE(sys_cap_enter)
5637 PRINT("%s", "sys_cap_enter ( )");
5638 PRE_REG_READ0(int, "cap_enter");
5639 static Bool warning_given = False;
5640 if (!warning_given) {
5641 warning_given = True;
5642 capabiltyMode = True;
5643 VG_(umsg)(
5644 "WARNING: Valgrind may not operate correctly in capability mode.\n"
5645 " Please consider disabling capability by using the RUNNING_ON_VALGRIND mechanism.\n"
5646 " See http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.clientreq\n");
5648 /* now complete loading debuginfo since it is not allowed after entering cap mode */
5649 VG_(load_all_debuginfo)();
5652 // SYS_cap_getmode 517
5653 // int cap_getmode(u_int *modep);
5654 PRE(sys_cap_getmode)
5656 PRINT("sys_cap_getmode ( %#" FMT_REGWORD "x )", ARG1);
5657 PRE_REG_READ1(int, "cap_getmode", u_int*, modep);
5658 PRE_MEM_WRITE("cap_getmode(modep)", ARG1, sizeof(u_int));
5661 POST(sys_cap_getmode)
5663 POST_MEM_WRITE(ARG1, sizeof(u_int));
5666 static vki_sigset_t pdfork_saved_mask;
5668 // SYS_pdfork 518
5669 // pid_t pdfork(int *fdp, int flags);
5670 PRE(sys_pdfork)
5672 Bool is_child;
5673 Int child_pid;
5674 vki_sigset_t mask;
5676 PRINT("sys_pdfork ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1, ARG2);
5677 PRE_REG_READ2(pid_t, "pdfork", int*, fdp, int, flags);
5679 /* Block all signals during fork, so that we can fix things up in
5680 the child without being interrupted. */
5681 VG_(sigfillset)(&mask);
5682 VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &pdfork_saved_mask);
5684 VG_(do_atfork_pre)(tid);
5686 SET_STATUS_from_SysRes( VG_(do_syscall2)(__NR_pdfork, ARG1, ARG2) );
5688 if (!SUCCESS) {
5689 return;
5692 // RES is 0 for child, non-0 (the child's PID) for parent.
5693 is_child = ( RES == 0 ? True : False );
5694 child_pid = ( is_child ? -1 : (Int)RES );
5696 if (is_child) {
5697 VG_(do_atfork_child)(tid);
5699 /* restore signal mask */
5700 VG_(sigprocmask)(VKI_SIG_SETMASK, &pdfork_saved_mask, NULL);
5701 } else {
5702 VG_(do_atfork_parent)(tid);
5704 PRINT(" fork: process %d created child %d\n", VG_(getpid)(), child_pid);
5706 /* restore signal mask */
5707 VG_(sigprocmask)(VKI_SIG_SETMASK, &pdfork_saved_mask, NULL);
5710 if (ARG1) {
5711 PRE_MEM_WRITE( "pdfork(fdp)", ARG1, sizeof(int) );
5715 POST(sys_pdfork)
5717 if (ARG1) {
5718 POST_MEM_WRITE( ARG1, sizeof(int) );
5722 // pdkill 519
5723 //int pdkill(int fd, int signum)
5724 PRE(sys_pdkill)
5726 PRINT("sys_pdkill ( %" FMT_REGWORD "u, %" FMT_REGWORD "d )", ARG1, SARG2);
5727 PRE_REG_READ2(int, "pdkill", int, fd, int, signum);
5729 if (!ML_(client_signal_OK)(ARG2)) {
5730 SET_STATUS_Failure( VKI_EINVAL );
5731 return;
5734 /* Ther was some code here to check if the kill is to this process
5736 * But it was totally wrong
5738 * It was calling ML_(do_sigkill)(Int pid, Int tgid)
5740 * With a file descriptor
5742 * Fortunately this will never match a real process otherwise
5743 * it might have accidentally killed us.
5745 * For a start we need the pid, obtained with pdgetpid
5746 * Next ML_(do_sigkill) doesn't map to FreeBSD. It takes a
5747 * pid (lwpid) and a tgid (threadgroup)
5749 * On FreeBSD lwpid is the tid and threadgroup is the pid
5750 * The kill functions operate on pids, not tids.
5752 * One last thing, I don't see how pdkill could do a self
5753 * kill 9. It neads an fd which implied pdfork whichimplies
5754 * that the fd/pid are for a child process
5757 SET_STATUS_from_SysRes(VG_(do_syscall2)(SYSNO, ARG1, ARG2));
5759 if (VG_(clo_trace_signals)) {
5760 VG_(message)(Vg_DebugMsg, "pdkill: sent signal %ld to fd %ld\n",
5761 SARG2, SARG1);
5764 /* This kill might have given us a pending signal. Ask for a check once
5765 the syscall is done. */
5766 *flags |= SfPollAfter;
5770 // SYS_pdgetpid 520
5771 // int pdgetpid(int fd, pid_t *pidp);
5772 PRE(sys_pdgetpid)
5774 PRINT("pdgetpid ( %" FMT_REGWORD "d, %#lx )", SARG1, ARG2);
5775 PRE_REG_READ2(int, "pdgetpid",
5776 int, fd, pid_t*, pidp);
5777 PRE_MEM_WRITE( "pdgetpid(pidp))", ARG2, sizeof(vki_pid_t) );
5780 POST(sys_pdgetpid)
5782 POST_MEM_WRITE( ARG2, sizeof(vki_pid_t) );
5785 // SYS_pselect 522
5787 // int pselect(int nfds, fd_set * restrict readfds, fd_set * restrict writefds,
5788 // fd_set * restrict exceptfds,
5789 // const struct timespec * restrict timeout,
5790 // const sigset_t * restrict newsigmask);
5791 PRE(sys_pselect)
5793 *flags |= SfMayBlock | SfPostOnFail;
5794 PRINT("sys_pselect ( %ld, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %#"
5795 FMT_REGWORD "x, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",
5796 SARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
5797 PRE_REG_READ6(int, "pselect",
5798 int, nfds, vki_fd_set *, readfds, vki_fd_set *, writefds,
5799 vki_fd_set *, exceptfds, struct vki_timespec *, timeout,
5800 const sigset_t *, newsigmask);
5801 // XXX: this possibly understates how much memory is read.
5802 if (ARG2 != 0) {
5803 PRE_MEM_READ( "pselect(readfds)",
5804 ARG2, ARG1/8 /* __FD_SETSIZE/8 */ );
5806 if (ARG3 != 0) {
5807 PRE_MEM_READ( "pselect(writefds)",
5808 ARG3, ARG1/8 /* __FD_SETSIZE/8 */ );
5810 if (ARG4 != 0) {
5811 PRE_MEM_READ( "pselect(exceptfds)",
5812 ARG4, ARG1/8 /* __FD_SETSIZE/8 */ );
5814 if (ARG5 != 0) {
5815 PRE_MEM_READ( "pselect(timeout)", ARG5, sizeof(struct vki_timeval) );
5818 if (ARG6 != 0) {
5819 PRE_MEM_READ( "pselect(sig)", ARG6, sizeof(vki_sigset_t) );
5820 ARG6 = ML_(make_safe_mask)("syswrap.pselect.1", (Addr)ARG6);
5824 POST(sys_pselect)
5826 ML_(free_safe_mask) ( (Addr)ARG6 );
5829 // SYS_getloginclass 523
5830 // int getloginclass(char *name, size_t len);
5831 PRE(sys_getloginclass)
5833 PRINT("sys_getloginclass ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
5834 PRE_REG_READ2(int, "getloginclass", char *, name, size_t, len);
5835 // The buffer should be at least MAXLOGNAME bytes in length.
5836 PRE_MEM_WRITE("getloginclass(name)", ARG1, ARG2);
5839 POST(sys_getloginclass)
5841 POST_MEM_WRITE(ARG1, ARG2);
5844 // SYS_setloginclass 524
5845 // int setloginclass(const char *name);
5846 PRE(sys_setloginclass)
5848 PRINT("sys_setloginclass ( %#" FMT_REGWORD "x(%s) )", ARG1, (HChar*)ARG1);
5849 PRE_REG_READ1(int, "setloginclass", const char *, name);
5850 PRE_MEM_RASCIIZ("rctl_setloginclass(name)", ARG1);
5853 // SYS_rctl_get_racct 525
5854 // int rctl_get_racct(const char *inbufp, size_t inbuflen, char *outbufp,
5855 // size_t outbuflen);
5856 PRE(sys_rctl_get_racct)
5858 PRINT("sys_rctl_get_racct ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
5859 PRE_REG_READ4(int, "rctl_get_racct", const char *, inbufp, size_t, inbuflen, char *, outbufp,
5860 size_t, outbuflen);
5861 PRE_MEM_READ("rctl_get_racct(inbufp)", ARG1, ARG2);
5862 PRE_MEM_WRITE("rctl_get_racct(outbufp)", ARG3, ARG4);
5865 POST(sys_rctl_get_racct)
5867 POST_MEM_WRITE(ARG3, ARG4);
5870 // SYS_rctl_get_rules 526
5871 // int rctl_get_rules(const char *inbufp, size_t inbuflen, char *outbufp,
5872 // size_t outbuflen);
5873 PRE(sys_rctl_get_rules)
5875 PRINT("sys_rctl_get_rules ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
5876 PRE_REG_READ4(int, "rctl_get_rules", const char *, inbufp, size_t, inbuflen, char *, outbufp,
5877 size_t, outbuflen);
5878 PRE_MEM_READ("rctl_get_rules(inbufp)", ARG1, ARG2);
5879 PRE_MEM_WRITE("rctl_get_rules(outbufp)", ARG3, ARG4);
5882 POST(sys_rctl_get_rules)
5884 POST_MEM_WRITE(ARG3, ARG4);
5887 // SYS_rctl_get_limits 527
5888 // int rctl_get_limits(const char *inbufp, size_t inbuflen, char *outbufp,
5889 // size_t outbuflen);
5890 PRE(sys_rctl_get_limits)
5892 PRINT("sys_rctl_get_limits ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
5893 PRE_REG_READ4(int, "rctl_get_limits", const char *, inbufp, size_t, inbuflen, char *, outbufp,
5894 size_t, outbuflen);
5895 PRE_MEM_READ("rctl_get_limits(inbufp)", ARG1, ARG2);
5896 PRE_MEM_WRITE("rctl_get_limits(outbufp)", ARG3, ARG4);
5899 POST(sys_rctl_get_limits)
5901 POST_MEM_WRITE(ARG3, ARG4);
5904 // SYS_rctl_add_rule 528
5905 // int rctl_add_rule(const char *inbufp, size_t inbuflen, char *outbufp,
5906 // size_t outbuflen);
5907 PRE(sys_rctl_add_rule)
5909 PRINT("sys_rctl_add_rule ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
5910 PRE_REG_READ2(int, "rctl_add_rule", const char *, inbufp, size_t, inbuflen);
5911 PRE_MEM_READ("rctl_add_rule(inbufp)", ARG1, ARG2);
5912 // man page says
5913 // The outbufp and outbuflen arguments are unused
5914 //PRE_MEM_WRITE("rctl_add_rule(outbufp)", ARG3, ARG4);
5917 POST(sys_rctl_add_rule)
5919 //POST_MEM_WRITE(ARG3, ARG4);
5922 // SYS_rctl_remove_rule 529
5923 // int rctl_remove_rule(const char *inbufp, size_t inbuflen, char *outbufp,
5924 // size_t outbuflen);
5925 PRE(sys_rctl_remove_rule)
5927 PRINT("sys_rctl_remove_rule ( %#" FMT_REGWORD "xd, %" FMT_REGWORD "u, %#" FMT_REGWORD "xd, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3, ARG4);
5928 PRE_REG_READ2(int, "rctl_remove_rule", const char *, inbufp, size_t, inbuflen);
5929 PRE_MEM_READ("rctl_remove_rule(inbufp)", ARG1, ARG2);
5930 // man page says
5931 // The outbufp and outbuflen arguments are unused
5932 //PRE_MEM_WRITE("rctl_remove_rule(outbufp)", ARG3, ARG4);
5935 POST(sys_rctl_remove_rule)
5937 //POST_MEM_WRITE(ARG3, ARG4);
5940 // SYS_posix_fallocate 530
5941 // x86/amd64
5943 // SYS_posix_fadvise 531
5944 // x86/amd64
5946 // SYS_wait6 532
5947 // amd64 / x86
5949 // SYS_cap_rights_limit 533
5950 //int cap_rights_limit(int fd, const cap_rights_t *rights);
5951 PRE(sys_cap_rights_limit)
5953 PRINT("sys_cap_rights_limit ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
5954 PRE_REG_READ2(int, "cap_rights_limit",
5955 int, fd, const cap_rights_t *, rights);
5956 PRE_MEM_READ( "cap_rights_limit(rights)", ARG2, sizeof(struct vki_cap_rights) );
5959 // SYS_cap_ioctls_limit 534
5960 // int cap_ioctls_limit(int fd, const unsigned long *cmds, size_t ncmds);
5961 PRE(sys_cap_ioctls_limit)
5963 PRINT("cap_ioctls_limit ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
5964 PRE_REG_READ3(int, "cap_ioctls_limit",
5965 int, fd, unsigned long*, rights, vki_size_t, ncmds);
5966 // "can be up to 256" taking that to not be inclusive
5967 if (ARG3 < 256 ) {
5968 PRE_MEM_READ( "cap_ioctls_limit(cmds))", ARG2, ARG3*sizeof(unsigned long) );
5970 // else fail?
5973 // SYS_cap_ioctls_get 535
5974 // int cap_ioctls_get(int fd, unsigned long *cmds, size_t maxcmds);
5975 PRE(sys_cap_ioctls_get)
5977 PRINT("sys_cap_ioctls_get ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", SARG1, ARG2, ARG3);
5978 PRE_REG_READ3(int, "cap_ioctls_get", int, fd, unsigned long *, cmds, size_t, maxcmds);
5979 if (ARG3 < 256) {
5980 PRE_MEM_WRITE("cap_ioctls_get(cmds)", ARG2, ARG3*sizeof(unsigned long));
5984 POST(sys_cap_ioctls_get)
5986 if (ARG3 < 256) {
5987 POST_MEM_WRITE(ARG2, ARG3*sizeof(unsigned long));
5992 // SYS_cap_fcntls_limit 536
5993 //int cap_fcntls_limit(int fd, uint32_t fcntlrights);
5994 PRE(sys_cap_fcntls_limit)
5996 PRINT("cap_fcntls_limit ( %" FMT_REGWORD "d, %" FMT_REGWORD "u )", SARG1, ARG2);
5997 PRE_REG_READ2(long, "cap_fcntls_limit",
5998 int, fd, vki_uint32_t, fcntlrights);
6001 // SYS_cap_fcntls_get 537
6002 // int cap_fcntls_get(int fd, uint32_t *fcntlrightsp);
6003 PRE(sys_cap_fcntls_get)
6005 PRINT("sys_cap_fcntls_get ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6006 PRE_REG_READ2(int, "cap_fcntls_get", int, fd, uint32_t *, fcntlrightsp);
6007 PRE_MEM_WRITE("cap_fcntls_get(fcntlrightsp)", ARG2, sizeof(uint32_t));
6010 POST(sys_cap_fcntls_get)
6012 POST_MEM_WRITE(ARG2, sizeof(uint32_t));
6015 // SYS_bindat 538
6016 // int bindat(int fd, int s, const struct sockaddr *addr, socklen_t addrlen);
6017 PRE(sys_bindat)
6019 PRINT("sys_bindat ( %" FMT_REGWORD "d, %" FMT_REGWORD "dx, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",
6020 SARG1, SARG2, ARG3, ARG4);
6021 PRE_REG_READ4(int, "bindat", int, fd, int, s, const struct vki_sockaddr *, name, vki_socklen_t, namelen);
6022 PRE_MEM_READ("bindat(name)", ARG3, ARG4);
6025 // SYS_connectat 539
6026 // int connectat(int fd, int s, const struct sockaddr *name, socklen_t namelen);
6027 PRE(sys_connectat)
6029 PRINT("sys_connectat ( %" FMT_REGWORD "d, %" FMT_REGWORD "dx, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )",
6030 SARG1, SARG2, ARG3, ARG4);
6031 PRE_REG_READ4(int, "connectat", int, fd, int, s, const struct vki_sockaddr *, name, vki_socklen_t, namelen);
6032 PRE_MEM_READ("connectat(name)", ARG3, ARG4);
6035 // SYS_chflagsat 540
6036 // int chflagsat(int fd, const char *path, unsigned long flags, int atflag);
6037 PRE(sys_chflagsat)
6039 PRINT("sys_chglagsat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d )",
6040 SARG1, ARG2, ARG3, SARG4);
6041 PRE_REG_READ4(int, "chflagsat", int, fd, const char *, path, unsigned long, flags, int, atflag);
6042 PRE_MEM_RASCIIZ("chflagsat(path)", ARG2);
6045 // SYS_accept4 541
6046 // int accept4(int s, struct sockaddr * restrict addr,
6047 // socklen_t * restrict addrlen, int flags);
6048 PRE(sys_accept4)
6050 *flags |= SfMayBlock;
6051 PRINT("sys_accept4 ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u)",ARG1,ARG2,ARG3,ARG4);
6052 PRE_REG_READ4(int, "accept4",
6053 int, s, struct sockaddr *, addr, int, *addrlen, int, flags);
6054 ML_(generic_PRE_sys_accept)(tid, ARG1,ARG2,ARG3);
6057 POST(sys_accept4)
6059 SysRes r;
6060 vg_assert(SUCCESS);
6061 r = ML_(generic_POST_sys_accept)(tid, VG_(mk_SysRes_Success)(RES),
6062 ARG1,ARG2,ARG3);
6063 SET_STATUS_from_SysRes(r);
6066 // SYS_pipe2 542
6067 // int pipe2(int fildes[2], int flags);
6068 PRE(sys_pipe2)
6070 PRINT("sys_pipe2 ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", ARG1, ARG2);
6071 PRE_REG_READ2(int, "pipe2",
6072 int *, fildes, int, flags);
6073 PRE_MEM_WRITE("pipe2(fildes)", ARG1, 2 * sizeof(int));
6077 POST(sys_pipe2)
6079 int *fildes;
6081 if (RES != 0) {
6082 return;
6085 POST_MEM_WRITE(ARG1, 2 * sizeof(int));
6086 fildes = (int *)ARG1;
6088 if (!ML_(fd_allowed)(fildes[0], "pipe2", tid, True) ||
6089 !ML_(fd_allowed)(fildes[1], "pipe2", tid, True)) {
6090 VG_(close)(fildes[0]);
6091 VG_(close)(fildes[1]);
6092 SET_STATUS_Failure( VKI_EMFILE );
6093 } else if (VG_(clo_track_fds)) {
6094 ML_(record_fd_open_nameless)(tid, fildes[0]);
6095 ML_(record_fd_open_nameless)(tid, fildes[1]);
6099 // SYS_aio_mlock 543
6100 // int aio_mlock(struct aiocb *iocb);
6101 PRE(sys_aio_mlock)
6103 PRINT("sys_aio_mlock ( %#" FMT_REGWORD "x )", ARG1);
6104 PRE_REG_READ1(int, "aio_mlock", struct vki_aiocb *, iocb);
6105 PRE_MEM_READ("aio_mlock(iocb", ARG1, sizeof(struct vki_aiocb));
6106 // this locks memory into RAM, don't think that we need to do
6107 // anything extra
6110 // SYS_procctl 544
6111 // amd64 / x86
6113 // SYS_ppoll 545
6114 // int ppoll(struct pollfd fds[], nfds_t nfds,
6115 // const struct timespec * restrict timeout,
6116 // const sigset_t * restrict newsigmask);
6117 PRE(sys_ppoll)
6119 PRINT("sys_ppoll ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD
6120 "x, %#" FMT_REGWORD "x )",
6121 ARG1, ARG2, ARG3, ARG4);
6122 UInt i;
6123 struct vki_pollfd* fds = (struct vki_pollfd *)(Addr)ARG1;
6124 *flags |= SfMayBlock | SfPostOnFail;
6125 PRE_REG_READ4(long, "ppoll",
6126 struct vki_pollfd *, fds, unsigned int, nfds,
6127 struct vki_timespec *, timeout, vki_sigset_t *, newsigmask);
6129 for (i = 0; i < ARG2; i++) {
6130 PRE_MEM_READ( "ppoll(fds.fd)",
6131 (Addr)(&fds[i].fd), sizeof(fds[i].fd) );
6132 if (ML_(safe_to_deref)(&fds[i].fd, sizeof(fds[i].fd)) && fds[i].fd >= 0) {
6133 PRE_MEM_READ( "ppoll(fds.events)",
6134 (Addr)(&fds[i].events), sizeof(fds[i].events) );
6136 PRE_MEM_WRITE( "ppoll(fds.revents)",
6137 (Addr)(&fds[i].revents), sizeof(fds[i].revents) );
6140 if (ARG3) {
6141 PRE_MEM_READ( "ppoll(timeout)", ARG3,
6142 sizeof(struct vki_timespec) );
6144 if (ARG4) {
6145 PRE_MEM_READ( "ppoll(newsigmask)", ARG4, sizeof(vki_sigset_t));
6146 ARG4 = ML_(make_safe_mask)("syswrap.ppoll.1", (Addr)ARG4);
6150 POST(sys_ppoll)
6152 if (SUCCESS && ((Word)RES != -1)) {
6153 UInt i;
6154 struct vki_pollfd* ufds = (struct vki_pollfd *)(Addr)ARG1;
6155 for (i = 0; i < ARG2; i++) {
6156 POST_MEM_WRITE( (Addr)(&ufds[i].revents), sizeof(ufds[i].revents) );
6159 ML_(free_safe_mask) ( (Addr)ARG4 );
6162 // SYS_futimens 546
6163 // int futimens(int fd, const struct timespec times[2]);
6164 PRE(sys_futimens)
6166 PRINT("sys_futimens ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6167 PRE_REG_READ2(int, "futimens", int, fd, const struct timespec *, times);
6168 PRE_MEM_READ("futimens(times)", ARG2, 2*sizeof(struct vki_timespec));
6171 // SYS_utimensat 547
6172 // int utimensat(int fd, const char *path, const struct timespec times[2],
6173 // int flag);
6174 PRE(sys_utimensat)
6176 PRINT("sys_utimensat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x, %" FMT_REGWORD "d )",
6177 SARG1, ARG2, ARG3, SARG4);
6178 PRE_REG_READ4(int, "utimensat", int, fd, const char *,path, const struct timespec *, times,
6179 int, flag);
6180 PRE_MEM_RASCIIZ("utimensat(path)", ARG2);
6181 PRE_MEM_READ("utimensat(times)", ARG3, 2*sizeof(struct vki_timespec));
6184 // SYS_fdatasync 550
6185 // int fdatasync(int fd);
6186 PRE(sys_fdatasync)
6188 PRINT("sys_fdatasync ( %" FMT_REGWORD "d )",SARG1);
6189 PRE_REG_READ1(int, "fdatasync", int, fd);
6192 #if (FREEBSD_VERS >= FREEBSD_12)
6193 // SYS_fstat 551
6194 // int fstat(int fd, struct stat *sb);
6195 PRE(sys_fstat)
6197 PRINT("sys_fstat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
6198 PRE_REG_READ2(int, "fstat", int, fd, struct stat *, sb);
6199 PRE_MEM_WRITE( "fstat(sb)", ARG2, sizeof(struct vki_stat) );
6202 POST(sys_fstat)
6204 POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) );
6207 // SYS_fstatat 552
6208 // int fstatat(int fd, const char *path, struct stat *sb, int flag);
6209 PRE(sys_fstatat)
6211 PRINT("sys_fstatat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %" FMT_REGWORD "d )", SARG1,ARG2,(char*)ARG2,ARG3,SARG4);
6212 PRE_REG_READ4(int, "fstatat",
6213 int, fd, const char *, path, struct stat *, sb, int, flag);
6214 PRE_MEM_RASCIIZ( "fstatat(path)", ARG2 );
6215 PRE_MEM_WRITE( "fstatat(sb)", ARG3, sizeof(struct vki_stat) );
6218 POST(sys_fstatat)
6220 POST_MEM_WRITE( ARG3, sizeof(struct vki_stat) );
6222 // SYS_fhstat 553
6223 // int fhstat(const fhandle_t *fhp, struct stat *sb);
6224 PRE(sys_fhstat)
6226 PRINT("sys_fhstat ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
6227 PRE_REG_READ2(long, "fhstat", const vki_fhandle_t *, fhp, struct stat *, sb);
6228 PRE_MEM_READ( "fhstat(fhp)", ARG1, sizeof(struct vki_fhandle) );
6229 PRE_MEM_WRITE( "fhstat(sb)", ARG2, sizeof(struct vki_stat) );
6232 POST(sys_fhstat)
6234 POST_MEM_WRITE( ARG2, sizeof(struct vki_stat) );
6237 // SYS_getdirentries 554
6238 // ssize_t getdirentries(int fd, char *buf, size_t nbytes, off_t *basep);
6239 PRE(sys_getdirentries)
6241 *flags |= SfMayBlock;
6242 PRINT("sys_getdirentries ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", SARG1,ARG2,ARG3,ARG4);
6243 PRE_REG_READ4(ssize_t, "getdirentries",
6244 int, fd, char *, buf,
6245 size_t, nbytes,
6246 off_t *, basep);
6247 PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 );
6248 if (ARG4) {
6249 PRE_MEM_WRITE("getdirentries(basep)", ARG4, sizeof (vki_off_t));
6253 POST(sys_getdirentries)
6255 vg_assert(SUCCESS);
6256 if (RES > 0) {
6257 POST_MEM_WRITE( ARG2, RES );
6258 if ( ARG4 != 0 ) {
6259 POST_MEM_WRITE( ARG4, sizeof (vki_off_t));
6264 // SYS_statfs 555
6265 // int statfs(const char *path, struct statfs *buf);
6266 PRE(sys_statfs)
6268 PRINT("sys_statfs ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",ARG1,(char *)ARG1,ARG2);
6269 PRE_REG_READ2(int, "statfs", const char *, path, struct statfs *, buf);
6270 PRE_MEM_RASCIIZ( "statfs(path)", ARG1 );
6271 PRE_MEM_WRITE( "statfs(buf)", ARG2, sizeof(struct vki_statfs) );
6274 POST(sys_statfs)
6276 POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) );
6279 // SYS_fstatfs 556
6280 // int fstatfs(int fd, struct statfs *buf);
6281 PRE(sys_fstatfs)
6283 PRINT("sys_fstatfs ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )",SARG1,ARG2);
6284 PRE_REG_READ2(int, "fstatfs",
6285 int, fd, struct vki_statfs *, buf);
6286 PRE_MEM_WRITE( "fstatfs(buf)", ARG2, sizeof(struct vki_statfs) );
6289 POST(sys_fstatfs)
6291 POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) );
6294 // SYS_getfsstat 557
6295 // int getfsstat(struct statfs *buf, long bufsize, int mode);
6296 PRE(sys_getfsstat)
6298 PRINT("sys_getfsstat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )",ARG1,ARG2,ARG3);
6299 PRE_REG_READ3(long, "getfsstat", struct vki_statfs *, buf, long, len, int, flags);
6300 PRE_MEM_WRITE( "getfsstat(buf)", ARG1, ARG2 );
6303 POST(sys_getfsstat)
6305 vg_assert(SUCCESS);
6306 if ((Word)RES != -1) {
6307 POST_MEM_WRITE( ARG1, RES * sizeof(struct vki_statfs) );
6311 // SYS_fhstatfs 558
6312 // int fhstatfs(const fhandle_t *fhp, struct statfs *buf);
6313 PRE(sys_fhstatfs)
6315 PRINT("sys_fhstatfs ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2);
6316 PRE_REG_READ2(long, "fhstatfs",
6317 struct fhandle *, fhp, struct statfs *, buf);
6318 PRE_MEM_READ( "fhstatfs(fhp)", ARG1, sizeof(struct vki_fhandle) );
6319 PRE_MEM_WRITE( "fhstatfs(buf)", ARG2, sizeof(struct vki_statfs) );
6322 POST(sys_fhstatfs)
6324 POST_MEM_WRITE( ARG2, sizeof(struct vki_statfs) );
6327 // SYS_mknodat 559
6328 // x86 / amd64
6330 // SYS_kevent 560
6331 // int kevent(int kq, const struct kevent *changelist, int nchanges,
6332 // struct kevent *eventlist, int nevents,
6333 // const struct timespec *timeout);
6334 PRE(sys_kevent)
6336 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);
6337 PRE_REG_READ6(int, "kevent",
6338 int, kq, struct vki_kevent *, changelist, int, nchanges,
6339 struct vki_kevent *, eventlist, int, nevents,
6340 struct timespec *, timeout);
6341 if (ARG2 != 0 && ARG3 != 0) {
6342 PRE_MEM_READ( "kevent(changelist)", ARG2, sizeof(struct vki_kevent)*ARG3 );
6344 if (ARG4 != 0 && ARG5 != 0) {
6345 PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent)*ARG5);
6347 if (ARG5 != 0) {
6348 *flags |= SfMayBlock;
6350 if (ARG6 != 0) {
6351 PRE_MEM_READ( "kevent(timeout)",
6352 ARG6, sizeof(struct vki_timespec));
6356 POST(sys_kevent)
6358 vg_assert(SUCCESS);
6359 if ((Word)RES != -1) {
6360 if (ARG4 != 0) {
6361 POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent)*RES) ;
6366 // SYS_cpuset_getdomain 561
6367 // x86 / amd64
6369 // SYS_cpuset_setdomain 562
6370 // x86 / amd64
6372 // SYS_getrandom 563
6373 // ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
6374 PRE(sys_getrandom)
6376 PRINT("sys_getrandom ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1, ARG2, ARG3);
6377 PRE_REG_READ3(ssize_t, "getrandom",
6378 void *, buf, vki_size_t, buflen, unsigned int, flags);
6379 PRE_MEM_WRITE( "getrandom(buf)", ARG1, ARG2 );
6380 if ((ARG3 & VKI_GRND_NONBLOCK) == 0) {
6381 *flags |= SfMayBlock;
6385 POST(sys_getrandom)
6387 POST_MEM_WRITE( ARG1, ARG2 );
6390 // SYS_getfhat 564
6391 // int getfhat(int fd, const char *path, fhandle_t *fhp, int flag);
6392 PRE(sys_getfhat)
6394 PRINT("sys_getfhat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "x, %" FMT_REGWORD "d ", SARG1, ARG2, ARG3, SARG4);
6395 PRE_REG_READ4(int, "getfhat", int, fd, const char*, path, vki_fhandle_t*, fhp, int, flag);
6396 PRE_MEM_RASCIIZ( "getfhat(path)", ARG2 );
6397 PRE_MEM_WRITE("getfhat(fhp)", ARG3, sizeof(vki_fhandle_t));
6400 POST(sys_getfhat)
6402 POST_MEM_WRITE(ARG3, sizeof(vki_fhandle_t));
6405 // SYS_fhlink 565
6406 // int fhlink(fhandle_t *fhp, const char *to);
6407 PRE(sys_fhlink)
6409 PRINT("sys_fhlink ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1, ARG2);
6410 PRE_REG_READ2(int, "fhlink", vki_fhandle_t *, fhp, const char *, to);
6411 PRE_MEM_READ( "fhlink(fhp)", ARG1, sizeof(vki_fhandle_t));
6412 PRE_MEM_RASCIIZ("fhlink(buf)", ARG2);
6415 // SYS_fhlinkat 566
6416 // int fhlinkat(fhandle_t *fhp, int tofd, const char *to);
6417 PRE(sys_fhlinkat)
6419 PRINT("sys_fhlinkat ( %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "xu ", ARG1, SARG2, ARG3);
6420 PRE_REG_READ3(int, "fhlinkat", vki_fhandle_t *, fhp, int, tofd, const char *, to);
6421 PRE_MEM_READ( "fhlinkat(fhp)", ARG1, sizeof(vki_fhandle_t));
6422 PRE_MEM_RASCIIZ("fhreadlink(to)", ARG3);
6425 // SYS_fhreadlink 567
6426 // int fhreadlink(fhandle_t *fhp, char *buf, size_t bufsize);
6427 PRE(sys_fhreadlink)
6429 PRINT("sys_fhreadlink ( %#" FMT_REGWORD "x, %" FMT_REGWORD "x, %" FMT_REGWORD "u ", ARG1, ARG2, ARG3);
6430 PRE_REG_READ3(int, "fhreadlink", vki_fhandle_t *, fhp, char *, buf, size_t, bufsize);
6431 PRE_MEM_READ( "fhreadlink(fhp)", ARG1, sizeof(vki_fhandle_t));
6432 PRE_MEM_WRITE("fhreadlink(buf)", ARG2, ARG3);
6435 POST(sys_fhreadlink)
6437 POST_MEM_WRITE(ARG2, ARG3);
6440 #endif
6442 #if (FREEBSD_VERS >= FREEBSD_12_2)
6444 // SYS_unlinkat 568
6445 // int funlinkat(int dfd, const char *path, int fd, int flag);
6446 PRE(sys_funlinkat)
6448 *flags |= SfMayBlock;
6449 PRINT("sys_funlinkat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %" FMT_REGWORD"u )",
6450 SARG1, ARG2, (char*)ARG2, ARG4, ARG5);
6451 PRE_REG_READ4(int, "funlinkat", int, dfd, const char *, path, int, fd, int, flag);
6452 PRE_MEM_RASCIIZ( "funlinkat(path)", ARG2 );
6455 // SYS_copy_file_range 569
6456 // ssize_t copy_file_range(int infd, off_t *inoffp, int outfd, off_t *outoffp,
6457 // size_t len, unsigned int flags);
6458 PRE(sys_copy_file_range)
6460 PRINT("sys_copy_file_range (%" FMT_REGWORD"d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "d, %" FMT_REGWORD "d)",
6461 SARG1, ARG2, SARG3, ARG4, (char*)ARG4, SARG5, SARG6);
6463 PRE_REG_READ6(vki_ssize_t, "copy_file_range",
6464 int, "infd",
6465 vki_off_t *, "inoffp",
6466 int, "outfd",
6467 vki_off_t *, "outoffp",
6468 vki_size_t, "len",
6469 unsigned int, "flags");
6471 /* File descriptors are "specially" tracked by valgrind.
6472 valgrind itself uses some, so make sure someone didn't
6473 put in one of our own... */
6474 if (!ML_(fd_allowed)(ARG1, "copy_file_range(infd)", tid, False) ||
6475 !ML_(fd_allowed)(ARG3, "copy_file_range(infd)", tid, False)) {
6476 SET_STATUS_Failure( VKI_EBADF );
6477 } else {
6478 /* Now see if the offsets are defined. PRE_MEM_READ will
6479 double check it can dereference them. */
6480 if (ARG2 != 0) {
6481 PRE_MEM_READ( "copy_file_range(inoffp)", ARG2, sizeof(vki_off_t));
6483 if (ARG4 != 0) {
6484 PRE_MEM_READ( "copy_file_range(outoffp)", ARG4, sizeof(vki_off_t));
6490 // SYS___sysctlbyname 570
6491 // int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
6492 // const void *newp, size_t newlen);
6493 // syscalls.master:
6494 // int __sysctlbyname(_In_reads_(namelen) const char *name, size_t namelen,
6495 // _Out_writes_bytes_opt_(*oldlenp) void *old,
6496 // _Inout_opt_ size_t *oldlenp, _In_reads_bytes_opt_(newlen) void *new,
6497 // size_t newlen );
6498 PRE(sys___sysctlbyname)
6500 // this is very much like SYS___sysctl, instead of having an OID with length
6501 // here threre is an ascii string with length
6502 // @todo PJF factor out the common functionality of the two
6503 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 );
6504 PRE_REG_READ6(int, "__sysctlbyname", const char *, name, vki_size_t, namelen,
6505 void *, oldp, vki_size_t *, oldlenp,
6506 void *, newp, vki_size_t, newlen);
6509 const char* name = (const char*)ARG1;
6510 if (ML_(safe_to_deref)(name, sizeof("kern.ps_strings")) &&
6511 VG_(strcmp)(name, "kern.ps_strings") == 0) {
6512 if (sysctl_kern_ps_strings((SizeT*)ARG3, (SizeT*)ARG4)) {
6513 SET_STATUS_Success(0);
6517 if (ML_(safe_to_deref)(name, sizeof("kern.usrstack")) &&
6518 VG_(strcmp)(name, "kern.usrstack") == 0) {
6519 sysctl_kern_usrstack((SizeT*)ARG3, (SizeT*)ARG4);
6520 SET_STATUS_Success(0);
6523 // kern.proc.pathname doesn't seem to be handled
6524 // makes sense as the pid is variable and using
6525 // a MIB is easier than generating a string
6527 // read number of ints specified in ARG2 from mem pointed to by ARG1
6528 PRE_MEM_READ("__sysctlbyname(name)", (Addr)ARG1, ARG2 * sizeof(int));
6530 // if 'newp' is not NULL can read namelen bytes from that addess
6531 if (ARG5 != (UWord)NULL) {
6532 PRE_MEM_READ("__sysctlbyname(newp)", (Addr)ARG5, ARG6);
6535 // there are two scenarios for oldlenp/oldp
6536 // 1. oldval is NULL and oldlenp is non-NULL
6537 // this is a query of oldlenp so oldlenp will be written
6538 // 2. Both are non-NULL
6539 // this is a query of oldp, oldlenp will be read and oldp will
6540 // be written
6542 // is oldlenp is not NULL, can write
6543 if (ARG4 != (UWord)NULL) {
6544 if (ARG3 != (UWord)NULL) {
6545 // case 2 above
6546 PRE_MEM_READ("__sysctlbyname(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
6547 if (ML_(safe_to_deref)((void*)(Addr)ARG4, sizeof(vki_size_t))) {
6548 PRE_MEM_WRITE("__sysctlbyname(oldp)", (Addr)ARG3, *(vki_size_t *)ARG4);
6549 } else {
6550 VG_(dmsg)("Warning: Bad oldlenp address %p in sysctlbyname\n",
6551 (void *)(Addr)ARG4);
6552 SET_STATUS_Failure ( VKI_EFAULT );
6554 } else {
6555 // case 1 above
6556 PRE_MEM_WRITE("__sysctlbyname(oldlenp)", (Addr)ARG4, sizeof(vki_size_t));
6561 POST(sys___sysctlbyname)
6563 if (ARG4 != (UWord)NULL) {
6564 if (ARG3 != (UWord)NULL) {
6565 //POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
6566 POST_MEM_WRITE((Addr)ARG3, *(vki_size_t *)ARG4);
6567 } else {
6568 POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t));
6573 #endif // (FREEBSD_VERS >= FREEBSD_12_2)
6575 #if (FREEBSD_VERS >= FREEBSD_13_0)
6577 // SYS_shm_open2 571
6578 // from syscalls.master
6579 // int shm_open2(_In_z_ const char *path,
6580 // int flags,
6581 // mode_t mode,
6582 // int shmflags,
6583 // _In_z_ const char *name);
6584 PRE(sys_shm_open2)
6586 PRE_REG_READ5(int, "shm_open2",
6587 const char *, path, int, flags, vki_mode_t, mode, int, shmflags, const char*, name);
6588 if (ARG1 == VKI_SHM_ANON) {
6589 PRINT("sys_shm_open2(%#" FMT_REGWORD "x(SHM_ANON), %" FMT_REGWORD "u, %hu, %d, %#" FMT_REGWORD "x(%s))",
6590 ARG1, ARG2, (vki_mode_t)ARG3, (Int)ARG4, ARG5, (HChar*)ARG5);
6591 } else {
6592 PRINT("sys_shm_open2(%#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u, %hu, %d, %#" FMT_REGWORD "x(%s))",
6593 ARG1, (HChar *)ARG1, ARG2, (vki_mode_t)ARG3, (Int)ARG4, ARG5, (HChar*)ARG5);
6594 PRE_MEM_RASCIIZ( "shm_open2(path)", ARG1 );
6597 if (ARG5) {
6598 PRE_MEM_RASCIIZ( "shm_open2(name)", ARG5 );
6600 *flags |= SfMayBlock;
6603 POST(sys_shm_open2)
6605 vg_assert(SUCCESS);
6606 if (!ML_(fd_allowed)(RES, "shm_open2", tid, True)) {
6607 VG_(close)(RES);
6608 SET_STATUS_Failure( VKI_EMFILE );
6609 } else {
6610 if (VG_(clo_track_fds)) {
6611 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1);
6616 // SYS_sigfastblock
6617 // int sigfastblock(int cmd, void *ptr);
6618 PRE(sys_sigfastblock)
6620 PRINT("sys_sigfastblock ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1, ARG2);
6621 PRE_REG_READ2(int, "sigfasblock", int, cmd, void*, ptr);
6624 // SYS___realpathat 574
6625 // from syscalls.master
6626 // int __realpathat(int fd,
6627 // _In_z_ const char *path,
6628 // _Out_writes_z_(size) char *buf,
6629 // size_t size,
6630 // int flags)
6631 PRE(sys___realpathat)
6633 PRINT("sys___realpathat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %" FMT_REGWORD "u %" FMT_REGWORD "d )",
6634 SARG1,ARG2,(const char*)ARG2,ARG3,ARG4,SARG5 );
6635 PRE_REG_READ5(int, "__realpathat", int, fd, const char *, path,
6636 char *, buf, vki_size_t, size, int, flags);
6637 PRE_MEM_RASCIIZ("__realpathat(path)", (Addr)ARG2);
6638 PRE_MEM_WRITE("__realpathat(buf)", (Addr)ARG3, ARG4);
6641 POST(sys___realpathat)
6643 POST_MEM_WRITE((Addr)ARG3, ARG4);
6646 // SYS___specialfd 577
6647 // syscalls.master
6648 // int __specialfd(int type,
6649 // _In_reads_bytes_(len) const void *req,
6650 // size_t len);
6651 PRE(sys___specialfd)
6653 PRINT("sys___specialfd ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )",
6654 SARG1,ARG2,(const char*)ARG2,ARG3 );
6655 PRE_REG_READ3(int, "__specialfd", int, type, const void *, req, vki_size_t, len);
6656 PRE_MEM_READ("__specialfd(req)", (Addr)ARG2, ARG3);
6659 #endif // (FREEBSD_VERS >= FREEBSD_13_0)
6661 #if (FREEBSD_VERS >= FREEBSD_13_1)
6663 // SYS_swapoff 582
6664 // int swapoff(const char *special, u_int flags);
6665 PRE(sys_swapoff)
6667 PRINT("sys_swapoff ( %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "u )", ARG1,(char *)ARG1, ARG2);
6668 PRE_REG_READ2(int, "swapoff", const char *, special, u_int, flags);
6669 PRE_MEM_RASCIIZ( "swapoff(special)", ARG1 );
6672 #endif
6674 #undef PRE
6675 #undef POST
6677 const SyscallTableEntry ML_(syscall_table)[] = {
6678 // syscall (handled specially) // 0
6679 BSDX_(__NR_exit, sys_exit), // 1
6680 BSDX_(__NR_fork, sys_fork), // 2
6681 GENXY(__NR_read, sys_read), // 3
6683 GENX_(__NR_write, sys_write), // 4
6684 GENXY(__NR_open, sys_open), // 5
6685 GENXY(__NR_close, sys_close), // 6
6686 GENXY(__NR_wait4, sys_wait4), // 7
6688 // 4.3 creat 8
6689 GENX_(__NR_link, sys_link), // 9
6690 GENX_(__NR_unlink, sys_unlink), // 10
6691 // obsol execv 11
6693 GENX_(__NR_chdir, sys_chdir), // 12
6694 GENX_(__NR_fchdir, sys_fchdir), // 13
6695 GENX_(__NR_freebsd11_mknod, sys_mknod), // 14
6696 GENX_(__NR_chmod, sys_chmod), // 15
6698 GENX_(__NR_chown, sys_chown), // 16
6699 GENX_(__NR_break, sys_brk), // 17
6700 // freebsd 4 getfsstat 18
6701 // 4.3 lseek 19
6703 GENX_(__NR_getpid, sys_getpid), // 20
6704 BSDX_(__NR_mount, sys_mount), // 21
6705 BSDX_(__NR_unmount, sys_unmount), // 22
6706 GENX_(__NR_setuid, sys_setuid), // 23
6708 GENX_(__NR_getuid, sys_getuid), // 24
6709 GENX_(__NR_geteuid, sys_geteuid), // 25
6710 BSDXY(__NR_ptrace, sys_ptrace), // 26
6711 BSDXY(__NR_recvmsg, sys_recvmsg), // 27
6713 BSDX_(__NR_sendmsg, sys_sendmsg), // 28
6714 BSDXY(__NR_recvfrom, sys_recvfrom), // 29
6715 BSDXY(__NR_accept, sys_accept), // 30
6716 BSDXY(__NR_getpeername, sys_getpeername), // 31
6718 BSDXY(__NR_getsockname, sys_getsockname), // 32
6719 GENX_(__NR_access, sys_access), // 33
6720 BSDX_(__NR_chflags, sys_chflags), // 34
6721 BSDX_(__NR_fchflags, sys_fchflags), // 35
6723 GENX_(__NR_sync, sys_sync), // 36
6724 GENX_(__NR_kill, sys_kill), // 37
6725 // 4.3 stat 38
6726 GENX_(__NR_getppid, sys_getppid), // 39
6728 // 4.3 lstat 40
6729 GENXY(__NR_dup, sys_dup), // 41
6731 BSDXY(__NR_freebsd10_pipe, sys_pipe), // 42
6732 GENX_(__NR_getegid, sys_getegid), // 43
6734 GENX_(__NR_profil, sys_ni_syscall), // 44
6735 GENX_(__NR_ktrace, sys_ni_syscall), // 45
6736 // 4.3 sigaction 46
6737 GENX_(__NR_getgid, sys_getgid), // 47
6739 // 4.3 sigaction (int sigset) 48
6740 BSDXY(__NR_getlogin, sys_getlogin), // 49
6741 BSDX_(__NR_setlogin, sys_setlogin), // 50
6742 GENX_(__NR_acct, sys_acct), // 51
6744 // 4.3 sigpending 52
6745 GENXY(__NR_sigaltstack, sys_sigaltstack), // 53
6746 BSDXY(__NR_ioctl, sys_ioctl), // 54
6747 BSDX_(__NR_reboot, sys_reboot), // 55
6749 BSDX_(__NR_revoke, sys_revoke), // 56
6750 GENX_(__NR_symlink, sys_symlink), // 57
6751 BSDX_(__NR_readlink, sys_readlink), // 58
6752 GENX_(__NR_execve, sys_execve), // 59
6754 GENX_(__NR_umask, sys_umask), // 60
6755 GENX_(__NR_chroot, sys_chroot), // 61
6756 // 4.3 fstat 62
6757 // 4.3 getgerninfo 63
6759 // 4.3 getpagesize 64
6760 GENX_(__NR_msync, sys_msync), // 65
6761 BSDX_(__NR_vfork, sys_vfork), // 66
6762 // obsol vread 67
6764 // obsol vwrite 68
6765 BSDX_(__NR_sbrk, sys_sbrk), // 69
6766 // not implemented in OS sstk 70
6767 // 4.3 mmap 71
6769 // freebsd11 vadvise 72
6770 GENXY(__NR_munmap, sys_munmap), // 73
6771 GENXY(__NR_mprotect, sys_mprotect), // 74
6772 GENX_(__NR_madvise, sys_madvise), // 75
6774 // obsol vhangup 76
6775 // obsol vlimit 77
6776 GENXY(__NR_mincore, sys_mincore), // 78
6777 GENXY(__NR_getgroups, sys_getgroups), // 79
6779 GENX_(__NR_setgroups, sys_setgroups), // 80
6780 GENX_(__NR_getpgrp, sys_getpgrp), // 81
6781 GENX_(__NR_setpgid, sys_setpgid), // 82
6782 GENXY(__NR_setitimer, sys_setitimer), // 83
6784 // 4.3 wait 84
6785 BSDX_(__NR_swapon, sys_swapon), // 85
6786 GENXY(__NR_getitimer, sys_getitimer), // 86
6787 // 4.3 gethostname 87
6789 // 4.3 sethostname 88
6790 BSDX_(__NR_getdtablesize, sys_getdtablesize), // 89
6791 GENXY(__NR_dup2, sys_dup2), // 90
6793 BSDXY(__NR_fcntl, sys_fcntl), // 92
6794 GENX_(__NR_select, sys_select), // 93
6795 GENX_(__NR_fsync, sys_fsync), // 95
6797 GENX_(__NR_setpriority, sys_setpriority), // 96
6798 BSDXY(__NR_socket, sys_socket), // 97
6799 BSDX_(__NR_connect, sys_connect), // 98
6800 // 4.3 accept 99
6802 GENX_(__NR_getpriority, sys_getpriority), // 100
6803 // 4.3 send 101
6804 // 4.3 recv 102
6805 // 4.3 sigreturn 103
6807 BSDX_(__NR_bind, sys_bind), // 104
6808 BSDX_(__NR_setsockopt, sys_setsockopt), // 105
6809 BSDX_(__NR_listen, sys_listen), // 106
6810 // obsol vtimes 107
6812 // 4.3 sigvec 108
6813 // 4.3 sigblock 109
6814 // 4.3 sigsetmask 110
6815 // 4.3 sigsuspend 111
6817 // 4.3 sigstack 112
6818 // 4.3 recvmsg 113
6819 // 4.3 sendmsg 114
6820 // 4.3 vtrace 115
6822 GENXY(__NR_gettimeofday, sys_gettimeofday), // 116
6823 GENXY(__NR_getrusage, sys_getrusage), // 117
6824 BSDXY(__NR_getsockopt, sys_getsockopt), // 118
6826 GENXY(__NR_readv, sys_readv), // 120
6827 GENX_(__NR_writev, sys_writev), // 121
6828 GENX_(__NR_settimeofday, sys_settimeofday), // 122
6829 GENX_(__NR_fchown, sys_fchown), // 123
6831 GENX_(__NR_fchmod, sys_fchmod), // 124
6832 // 4.3 recvfrom 125
6833 GENX_(__NR_setreuid, sys_setreuid), // 126
6834 GENX_(__NR_setregid, sys_setregid), // 127
6836 GENX_(__NR_rename, sys_rename), // 128
6837 // 4.3 truncate 129
6838 // 4.3 ftruncate 130
6839 GENX_(__NR_flock, sys_flock), // 131
6841 BSDX_(__NR_mkfifo, sys_mkfifo), // 132
6842 BSDX_(__NR_sendto, sys_sendto), // 133
6843 BSDX_(__NR_shutdown, sys_shutdown), // 134
6844 BSDXY(__NR_socketpair, sys_socketpair), // 135
6846 GENX_(__NR_mkdir, sys_mkdir), // 136
6847 GENX_(__NR_rmdir, sys_rmdir), // 137
6848 GENX_(__NR_utimes, sys_utimes), // 138
6849 // 4.2 sigreturn 139
6851 BSDXY(__NR_adjtime, sys_adjtime), // 140
6852 // 4.3 getpeername 141
6853 // 4.3 gethostid 142
6854 // 4.3 sethostid 143
6856 // 4.3 getrlimit` 144
6857 // 4.3 setrlimit 145
6858 // 4.3 killpg 146
6859 GENX_(__NR_setsid, sys_setsid), // 147
6861 BSDX_(__NR_quotactl, sys_quotactl), // 148
6862 // 4.3 quota 149
6863 // 4.3 getsockname 150
6864 // bsd/os sem_lock 151
6866 // bsd/os sem_wakeup 152
6867 // bsd/os asyncdaemon 153
6869 // no idea what the following syscall does
6870 // unimp SYS_nlm_syscall 154
6872 // a somewhat complicated NFS API
6873 // takes a flag and a void* that can point to one of
6874 // three different types of struct depending on the flag
6875 // unimp SYS_nfssvc 155
6877 // 4.3 getdirentries 156
6878 // freebsd 4 statfs 157
6879 // freebsd 4 fstatfs 158
6881 BSDXY(__NR_lgetfh, sys_lgetfh), // 160
6882 BSDXY(__NR_getfh, sys_getfh), // 161
6883 #if (FREEBSD_VERS <= FREEBSD_10)
6884 BSDXY(__NR_freebsd4_getdomainname, sys_freebsd4_getdomainname), // 162
6885 BSDX_(__NR_freebsd4_setdomainname, sys_freebsd4_setdomainname), // 163
6886 BSDXY(__NR_freebsd4_uname, sys_freebsd4_uname), // 164
6887 #endif
6888 BSDXY(__NR_sysarch, sys_sysarch), // 165
6889 BSDXY(__NR_rtprio, sys_rtprio), // 166
6891 // the following 3 seem only to be defines in a header
6892 // semsys 169
6893 // msgsys 170
6894 // shmsys 171
6896 #if (FREEBSD_VERS <= FREEBSD_10)
6897 BSDXY(__NR_freebsd6_pread, sys_freebsd6_pread), // 173
6898 BSDX_(__NR_freebsd6_pwrite, sys_freebsd6_pwrite), // 174
6899 #endif
6900 BSDX_(__NR_setfib, sys_setfib), // 175
6902 // @todo PJF this exists on Darwin and Solaris as well
6903 // and it isn't implememented on either
6904 // looking at the manpage there is a rather fearsome
6905 // timex struct with a mixture of ro and rw fields
6906 // BSDXY(__NR_ntp_adjtime, sys_ntp_adjtime), // 176
6908 // bsd/os sfork 177
6909 // bsd/os getdescriptor 178
6910 // bsd/os setdescriptor 179
6912 GENX_(__NR_setgid, sys_setgid), // 181
6913 BSDX_(__NR_setegid, sys_setegid), // 182
6914 BSDX_(__NR_seteuid, sys_seteuid), // 183
6916 // obs lfs_bmapv 184
6917 // obs lfs_markv 185
6918 // obs lfs_segclean 186
6919 // obs lfs_segwait 187
6921 #if (FREEBSD_VERS >= FREEBSD_12)
6922 BSDXY(__NR_freebsd11_stat, sys_freebsd11_stat), // 188
6923 BSDXY(__NR_freebsd11_fstat, sys_freebsd11_fstat), // 189
6924 BSDXY(__NR_freebsd11_lstat, sys_freebsd11_lstat), // 190
6925 #else
6926 BSDXY(__NR_stat, sys_stat), // 188
6927 BSDXY(__NR_fstat, sys_fstat), // 189
6928 BSDXY(__NR_lstat, sys_lstat), // 190
6929 #endif
6930 BSDX_(__NR_pathconf, sys_pathconf), // 191
6931 BSDX_(__NR_fpathconf, sys_fpathconf), // 192
6932 GENXY(__NR_getrlimit, sys_getrlimit), // 194
6933 GENX_(__NR_setrlimit, sys_setrlimit), // 195
6934 #if (FREEBSD_VERS >= FREEBSD_12)
6935 BSDXY(__NR_freebsd11_getdirentries, sys_freebsd11_getdirentries), // 196
6936 #else
6937 BSDXY(__NR_getdirentries, sys_getdirentries), // 196
6938 #endif
6939 #if (FREEBSD_VERS <= FREEBSD_10)
6940 BSDX_(__NR_freebsd6_mmap, sys_freebsd6_mmap), // 197
6941 #endif
6942 // __syscall (handled specially) // 198
6943 #if (FREEBSD_VERS <= FREEBSD_10)
6944 BSDX_(__NR_freebsd6_lseek, sys_freebsd6_lseek), // 199
6945 BSDX_(__NR_freebsd6_truncate, sys_freebsd6_truncate), // 200
6946 BSDX_(__NR_freebsd6_ftruncate, sys_freebsd6_ftruncate), // 201
6947 #endif
6948 BSDXY(__NR___sysctl, sys___sysctl), // 202
6949 GENX_(__NR_mlock, sys_mlock), // 203
6951 GENX_(__NR_munlock, sys_munlock), // 204
6952 BSDX_(__NR_undelete, sys_undelete), // 205
6953 BSDX_(__NR_futimes, sys_futimes), // 206
6954 GENX_(__NR_getpgid, sys_getpgid), // 207
6956 // netbsd newreboot 208
6957 GENXY(__NR_poll, sys_poll), // 209
6959 BSDXY(__NR_freebsd7___semctl, sys_freebsd7___semctl), // 220
6960 BSDX_(__NR_semget, sys_semget), // 221
6961 BSDX_(__NR_semop, sys_semop), // 222
6962 // obs semconfig 223
6964 BSDXY(__NR_freebsd7_msgctl, sys_freebsd7_msgctl), // 224
6965 BSDX_(__NR_msgget, sys_msgget), // 225
6966 BSDX_(__NR_msgsnd, sys_msgsnd), // 226
6967 BSDXY(__NR_msgrcv, sys_msgrcv), // 227
6969 BSDXY(__NR_shmat, sys_shmat), // 228
6970 BSDXY(__NR_freebsd7_shmctl, sys_freebsd7_shmctl), // 229
6971 BSDXY(__NR_shmdt, sys_shmdt), // 230
6972 BSDX_(__NR_shmget, sys_shmget), // 231
6974 BSDXY(__NR_clock_gettime, sys_clock_gettime), // 232
6975 BSDX_(__NR_clock_settime, sys_clock_settime), // 233
6976 BSDXY(__NR_clock_getres, sys_clock_getres), // 234
6977 BSDXY(__NR_ktimer_create, sys_timer_create), // 235
6978 BSDX_(__NR_ktimer_delete, sys_timer_delete), // 236
6979 BSDXY(__NR_ktimer_settime, sys_timer_settime), // 237
6980 BSDXY(__NR_ktimer_gettime, sys_timer_gettime), // 238
6981 BSDX_(__NR_ktimer_getoverrun, sys_timer_getoverrun), // 239
6983 GENXY(__NR_nanosleep, sys_nanosleep), // 240
6984 // unimpl SYS_ffclock_getcounter 241
6985 // unimpl SYS_ffclock_setestimate 242
6986 // unimpl SYS_ffclock_getestimate 243
6988 BSDXY(__NR_clock_nanosleep, sys_clock_nanosleep), // 244
6989 BSDXY(__NR_clock_getcpuclockid2, sys_clock_getcpuclockid2), // 247
6991 // unimpl SYS_ntp_gettime 248
6992 BSDXY(__NR_minherit, sys_minherit), // 250
6993 BSDX_(__NR_rfork, sys_rfork), // 251
6995 // openbsd_poll // 252
6996 BSDX_(__NR_issetugid, sys_issetugid), // 253
6997 GENX_(__NR_lchown, sys_lchown), // 254
6998 BSDXY(__NR_aio_read, sys_aio_read), // 255
6999 BSDXY(__NR_aio_write, sys_aio_write), // 256
7000 BSDX_(__NR_lio_listio, sys_lio_listio), // 257
7002 GENXY(__NR_freebsd11_getdents, sys_getdents), // 272
7003 BSDX_(__NR_lchmod, sys_lchmod), // 274
7004 // netbsd_lchown // 275
7006 BSDX_(__NR_lutimes, sys_lutimes), // 276
7007 // netbsd msync 277
7008 // unimpl SYS_freebsd11_nstat 278
7009 // unimpl SYS_freebsd11_nfstat 279
7011 // unimpl SYS_freebsd11_nlstat 280
7013 BSDXY(__NR_preadv, sys_preadv), // 289
7014 BSDX_(__NR_pwritev, sys_pwritev), // 290
7016 // freebsd 4 fhstatfs 297
7017 BSDXY(__NR_fhopen, sys_fhopen), // 298
7018 #if (FREEBSD_VERS >= FREEBSD_12)
7019 BSDXY(__NR_freebsd11_fhstat, sys_freebsd11_fhstat), // 299
7020 #else
7021 BSDXY(__NR_fhstat, sys_fhstat), // 299
7022 #endif
7024 BSDX_(__NR_modnext, sys_modnext), // 300
7025 BSDXY(__NR_modstat, sys_modstat), // 301
7026 BSDX_(__NR_modfnext, sys_modfnext), // 302
7027 BSDX_(__NR_modfind, sys_modfind), // 303
7029 BSDX_(__NR_kldload, sys_kldload), // 304
7030 BSDX_(__NR_kldunload, sys_kldunload), // 305
7031 BSDX_(__NR_kldfind, sys_kldfind), // 306
7032 BSDX_(__NR_kldnext, sys_kldnext), // 307
7034 BSDXY(__NR_kldstat, sys_kldstat), // 308
7035 BSDX_(__NR_kldfirstmod, sys_kldfirstmod), // 309
7036 GENX_(__NR_getsid, sys_getsid), // 310
7037 BSDX_(__NR_setresuid, sys_setresuid), // 311
7039 BSDX_(__NR_setresgid, sys_setresgid), // 312
7040 // obsol signanosleep 313
7041 BSDX_(__NR_aio_return, sys_aio_return), // 314
7042 BSDX_(__NR_aio_suspend, sys_aio_suspend), // 315
7044 BSDX_(__NR_aio_cancel, sys_aio_cancel), // 316
7045 BSDX_(__NR_aio_error, sys_aio_error), // 317
7046 // freebsd 6 aio_read 318
7047 // freebsd 6 aio_write 319
7048 // freebsd 6 lio_listio 320
7049 BSDX_(__NR_yield, sys_yield), // 321
7050 // obs thr_sleep 322
7051 // obs thr_wakeup 323
7053 GENX_(__NR_mlockall, sys_mlockall), // 324
7054 BSDX_(__NR_munlockall, sys_munlockall), // 325
7055 BSDXY(__NR___getcwd, sys___getcwd), // 326
7056 BSDX_(__NR_sched_setparam, sys_sched_setparam), // 327
7057 BSDXY(__NR_sched_getparam, sys_sched_getparam), // 328
7058 BSDX_(__NR_sched_setscheduler, sys_sched_setscheduler), // 329
7059 BSDX_(__NR_sched_getscheduler, sys_sched_getscheduler), // 330
7060 BSDX_(__NR_sched_yield, sys_sched_yield), // 331
7062 BSDX_(__NR_sched_get_priority_max, sys_sched_get_priority_max), // 332
7063 BSDX_(__NR_sched_get_priority_min, sys_sched_get_priority_min), // 333
7064 BSDXY(__NR_sched_rr_get_interval, sys_sched_rr_get_interval), // 334
7065 BSDX_(__NR_utrace, sys_utrace), // 335
7067 // freebsd 4 sendfile 336
7068 BSDXY(__NR_kldsym, sys_kldsym), // 337
7069 BSDX_(__NR_jail, sys_jail), // 338
7070 // unimpl SYS_nnpfs_syscall 339
7072 BSDXY(__NR_sigprocmask, sys_sigprocmask), // 340
7073 BSDXY(__NR_sigsuspend, sys_sigsuspend), // 341
7074 // freebsd 4 sigaction 342
7075 BSDXY(__NR_sigpending, sys_sigpending), // 343
7077 // freebsd 4 sigreturn 344
7078 BSDXY(__NR_sigtimedwait, sys_sigtimedwait), // 345
7079 BSDXY(__NR_sigwaitinfo, sys_sigwaitinfo), // 346
7080 BSDXY(__NR___acl_get_file, sys___acl_get_file), // 347
7082 BSDX_(__NR___acl_set_file, sys___acl_set_file), // 348
7083 BSDXY(__NR___acl_get_fd, sys___acl_get_fd), // 349
7084 BSDX_(__NR___acl_set_fd, sys___acl_set_fd), // 350
7085 BSDX_(__NR___acl_delete_file, sys___acl_delete_file), // 351
7087 BSDX_(__NR___acl_delete_fd, sys___acl_delete_fd), // 352
7088 BSDX_(__NR___acl_aclcheck_file, sys___acl_aclcheck_file), // 353
7089 BSDX_(__NR___acl_aclcheck_fd, sys___acl_aclcheck_fd), // 354
7090 BSDX_(__NR_extattrctl, sys_extattrctl), // 355
7091 BSDX_(__NR_extattr_set_file, sys_extattr_set_file), // 356
7092 BSDXY(__NR_extattr_get_file, sys_extattr_get_file), // 357
7093 BSDX_(__NR_extattr_delete_file, sys_extattr_delete_file), // 358
7094 BSDXY(__NR_aio_waitcomplete, sys_aio_waitcomplete), // 359
7096 BSDXY(__NR_getresuid, sys_getresuid), // 360
7097 BSDXY(__NR_getresgid, sys_getresgid), // 361
7098 BSDXY(__NR_kqueue, sys_kqueue), // 362
7099 #if (FREEBSD_VERS >= FREEBSD_12)
7100 BSDXY(__NR_freebsd11_kevent, sys_freebsd11_kevent), // 363
7101 #else
7102 BSDXY(__NR_kevent, sys_kevent), // 363
7103 #endif
7104 // obs __cap_get_proc 364
7105 // obs __cap_set_proc 365
7106 // obs __cap_get_fd 366
7107 // obs __cap_get_file 367
7108 // obs __cap_set_fd 368
7109 // obs __cap_set_file 369
7111 BSDX_(__NR_extattr_set_fd, sys_extattr_set_fd), // 371
7112 BSDXY(__NR_extattr_get_fd, sys_extattr_get_fd), // 372
7113 BSDX_(__NR_extattr_delete_fd, sys_extattr_delete_fd), // 373
7114 BSDX_(__NR___setugid, sys___setugid), // 374
7115 // obs nfsclnt 375
7117 BSDX_(__NR_eaccess, sys_eaccess), // 376
7118 // unimpl afs3_syscall 377
7119 BSDX_(__NR_nmount, sys_nmount), // 378
7120 // obs kse_exit 379
7121 // obs kse_wakeup 380
7122 // obs kse_create 381
7123 // obs kse_thr_interrupt 382
7124 // obs kse_release 383
7126 // unimpl __mac_get_proc 384
7127 // unimpl __mac_set_proc 385
7128 // unimpl __mac_get_fd 386
7129 // unimpl __mac_get_file 387
7130 // unimpl __mac_set_fd 388
7131 // unimpl __mac_set_file 389
7132 BSDXY(__NR_kenv, sys_kenv), // 390
7133 BSDX_(__NR_lchflags, sys_lchflags), // 391
7135 BSDXY(__NR_uuidgen, sys_uuidgen), // 392
7136 BSDXY(__NR_sendfile, sys_sendfile), // 393
7137 // unimpl mac_syscall 394
7139 #if (FREEBSD_VERS >= FREEBSD_12)
7140 BSDXY(__NR_freebsd11_getfsstat, sys_freebsd11_getfsstat), // 395
7141 BSDXY(__NR_freebsd11_statfs, sys_statfs), // 396
7142 BSDXY(__NR_freebsd11_fstatfs, sys_fstatfs), // 397
7143 BSDXY(__NR_freebsd11_fhstatfs, sys_fhstatfs), // 398
7144 #else
7145 BSDXY(__NR_getfsstat, sys_getfsstat), // 395
7146 BSDXY(__NR_statfs, sys_statfs), // 396
7147 BSDXY(__NR_fstatfs, sys_fstatfs), // 397
7148 BSDXY(__NR_fhstatfs, sys_fhstatfs), // 398
7149 #endif
7151 // unimpl ksem_close 400
7152 // unimpl ksem_post 401
7153 // unimpl ksem_wait 402
7154 // unimpl ksem_trywait 403
7156 // unimpl ksem_init 404
7157 // unimpl ksem_open 405
7158 // unimpl ksem_unlink 406
7159 // unimpl ksem_getvalue 407
7161 // unimpl ksem_destroy 408
7162 // unimpl __mac_get_pid 409
7163 // unimpl __mac_get_link 410
7164 // unimpl __mac_set_link 411
7166 BSDX_(__NR_extattr_set_link, sys_extattr_set_link), // 412
7167 BSDXY(__NR_extattr_get_link, sys_extattr_get_link), // 413
7168 BSDX_(__NR_extattr_delete_link, sys_extattr_delete_link), // 414
7169 // unimpl __mac_execve 415
7171 BSDXY(__NR_sigaction, sys_sigaction), // 416
7172 BSDX_(__NR_sigreturn, sys_sigreturn), // 417
7174 BSDXY(__NR_getcontext, sys_getcontext), // 421
7175 BSDX_(__NR_setcontext, sys_setcontext), // 422
7176 BSDXY(__NR_swapcontext, sys_swapcontext), // 423
7178 #if (FREEBSD_VERS >= FREEBSD_13_1)
7179 BSDX_(__NR_freebsd13_swapoff, sys_freebsd13_swapoff), // 424
7180 #else
7181 BSDX_(__NR_swapoff, sys_swapoff), // 424
7182 #endif
7183 BSDXY(__NR___acl_get_link, sys___acl_get_link), // 425
7184 BSDX_(__NR___acl_set_link, sys___acl_set_link), // 426
7185 BSDX_(__NR___acl_delete_link, sys___acl_delete_link), // 427
7187 BSDX_(__NR___acl_aclcheck_link, sys___acl_aclcheck_link), // 428
7188 BSDXY(__NR_sigwait, sys_sigwait), // 429
7189 BSDX_(__NR_thr_create, sys_thr_create), // 430
7190 BSDX_(__NR_thr_exit, sys_thr_exit), // 431
7192 BSDXY(__NR_thr_self, sys_thr_self), // 432
7193 BSDXY(__NR_thr_kill, sys_thr_kill), // 433
7194 #if (FREEBSD_VERS <= FREEBSD_10)
7195 BSDXY(__NR__umtx_lock, sys__umtx_lock), // 434
7196 BSDXY(__NR__umtx_unlock, sys__umtx_unlock), // 435
7197 #endif
7199 BSDX_(__NR_jail_attach, sys_jail_attach), // 436
7200 BSDXY(__NR_extattr_list_fd, sys_extattr_list_fd), // 437
7201 BSDXY(__NR_extattr_list_file, sys_extattr_list_file), // 438
7202 BSDXY(__NR_extattr_list_link, sys_extattr_list_link), // 439
7204 // obs kse_switchin 440
7205 // unimpl ksem_timedwait 441
7206 BSDX_(__NR_thr_suspend, sys_thr_suspend), // 442
7207 BSDX_(__NR_thr_wake, sys_thr_wake), // 443
7208 BSDX_(__NR_kldunloadf, sys_kldunloadf), // 444
7209 // unimpl audit 445
7210 // unimpl auditon 446
7211 // unimpl getauid 447
7213 // unimpl setauid 448
7214 // unimpl getaudit 449
7215 // unimpl setaudit 450
7216 // unimpl getaudit_addr 451
7217 // unimpl setaudit_addr 452
7218 // unimpl auditctl 453
7219 BSDXY(__NR__umtx_op, sys__umtx_op), // 454
7220 BSDX_(__NR_thr_new, sys_thr_new), // 455
7222 BSDX_(__NR_sigqueue, sys_sigqueue), // 456
7223 BSDXY(__NR_kmq_open, sys_kmq_open), // 457
7224 BSDX_(__NR_kmq_setattr, sys_kmq_setattr), // 458
7225 BSDXY(__NR_kmq_timedreceive, sys_kmq_timedreceive), // 459
7227 BSDX_(__NR_kmq_timedsend, sys_kmq_timedsend), // 460
7228 BSDX_(__NR_kmq_notify, sys_kmq_notify), // 461
7229 BSDX_(__NR_kmq_unlink, sys_kmq_unlink), // 462
7230 BSDX_(__NR_abort2, sys_abort2), // 463
7232 BSDX_(__NR_thr_set_name, sys_thr_set_name), // 464
7233 BSDX_(__NR_aio_fsync, sys_aio_fsync), // 465
7234 BSDXY(__NR_rtprio_thread, sys_rtprio_thread), // 466
7236 // unimpl sctp_peeloff 471
7237 BSDX_(__NR_sctp_generic_sendmsg, sys_sctp_generic_sendmsg), // 472
7238 // unimpl sctp_generic_sendmsg_iov 473
7239 BSDXY(__NR_sctp_generic_recvmsg, sys_sctp_generic_recvmsg), // 474
7240 BSDXY(__NR_pread, sys_pread), // 475
7242 BSDX_(__NR_pwrite, sys_pwrite), // 476
7243 BSDX_(__NR_mmap, sys_mmap), // 477
7244 BSDX_(__NR_lseek, sys_lseek), // 478
7245 BSDX_(__NR_truncate, sys_truncate), // 479
7246 BSDX_(__NR_ftruncate, sys_ftruncate), // 480
7247 BSDXY(__NR_thr_kill2, sys_thr_kill2), // 481
7248 BSDXY(__NR_shm_open, sys_shm_open), // 482
7249 BSDX_(__NR_shm_unlink, sys_shm_unlink), // 483
7251 BSDXY(__NR_cpuset, sys_cpuset), // 484
7252 BSDX_(__NR_cpuset_setid, sys_cpuset_setid), // 485
7253 BSDXY(__NR_cpuset_getid, sys_cpuset_getid), // 486
7255 BSDXY(__NR_cpuset_getaffinity, sys_cpuset_getaffinity), // 487
7256 BSDX_(__NR_cpuset_setaffinity, sys_cpuset_setaffinity), // 488
7257 BSDX_(__NR_faccessat, sys_faccessat), // 489
7258 BSDX_(__NR_fchmodat, sys_fchmodat), // 490
7259 BSDX_(__NR_fchownat, sys_fchownat), // 491
7261 BSDX_(__NR_fexecve, sys_fexecve), // 492
7262 #if (FREEBSD_VERS >= FREEBSD_12)
7263 BSDXY(__NR_freebsd11_fstatat, sys_freebsd11_fstatat), // 493
7264 #else
7265 BSDXY(__NR_fstatat, sys_fstatat), // 493
7266 #endif
7267 BSDX_(__NR_futimesat, sys_futimesat), // 494
7268 BSDX_(__NR_linkat, sys_linkat), // 495
7270 BSDX_(__NR_mkdirat, sys_mkdirat), // 496
7271 BSDX_(__NR_mkfifoat, sys_mkfifoat), // 497
7273 #if (FREEBSD_VERS >= FREEBSD_12)
7274 BSDX_(__NR_freebsd11_mknodat, sys_freebsd11_mknodat), // 498
7275 #else
7276 BSDX_(__NR_mknodat, sys_mknodat), // 498
7277 #endif
7279 BSDXY(__NR_openat, sys_openat), // 499
7281 BSDXY(__NR_readlinkat, sys_readlinkat), // 500
7282 BSDX_(__NR_renameat, sys_renameat), // 501
7283 BSDX_(__NR_symlinkat, sys_symlinkat), // 502
7284 BSDX_(__NR_unlinkat, sys_unlinkat), // 503
7286 BSDX_(__NR_posix_openpt, sys_posix_openpt), // 504
7287 // unimp gssd_syscall 505
7288 BSDX_(__NR_jail_get, sys_jail_get), // 506
7289 BSDX_(__NR_jail_set, sys_jail_set), // 507
7290 BSDX_(__NR_jail_remove, sys_jail_remove), // 508
7291 BSDX_(__NR_closefrom, sys_closefrom), // 509
7292 BSDXY(__NR___semctl, sys___semctl), // 510
7293 BSDXY(__NR_msgctl, sys_msgctl), // 511
7294 BSDXY(__NR_shmctl, sys_shmctl), // 512
7295 BSDX_(__NR_lpathconf, sys_lpathconf), // 513
7296 /* 514 is obsolete cap_new */
7297 BSDXY(__NR___cap_rights_get, sys_cap_rights_get), // 515
7298 BSDX_(__NR_cap_enter, sys_cap_enter), // 516
7299 BSDXY(__NR_cap_getmode, sys_cap_getmode), // 517
7300 BSDXY(__NR_pdfork, sys_pdfork), // 518
7301 BSDX_(__NR_pdkill, sys_pdkill), // 519
7302 BSDXY(__NR_pdgetpid, sys_pdgetpid), // 520
7303 BSDXY(__NR_pselect, sys_pselect), // 522
7304 BSDXY(__NR_getloginclass, sys_getloginclass), // 523
7305 BSDX_(__NR_setloginclass, sys_setloginclass), // 524
7306 BSDXY(__NR_rctl_get_racct, sys_rctl_get_racct), // 525
7307 BSDXY(__NR_rctl_get_rules, sys_rctl_get_rules), // 526
7308 BSDXY(__NR_rctl_get_limits, sys_rctl_get_limits), // 527
7309 BSDXY(__NR_rctl_add_rule, sys_rctl_add_rule), // 528
7310 BSDXY(__NR_rctl_remove_rule, sys_rctl_remove_rule), // 529
7311 BSDX_(__NR_posix_fallocate, sys_posix_fallocate), // 530
7312 BSDX_(__NR_posix_fadvise, sys_posix_fadvise), // 531
7313 BSDXY(__NR_wait6, sys_wait6), // 532
7314 BSDX_(__NR_cap_rights_limit, sys_cap_rights_limit), // 533
7315 BSDX_(__NR_cap_ioctls_limit, sys_cap_ioctls_limit), // 534
7316 BSDXY(__NR_cap_ioctls_get, sys_cap_ioctls_get), // 535
7317 BSDX_(__NR_cap_fcntls_limit, sys_cap_fcntls_limit), // 536
7318 BSDXY(__NR_cap_fcntls_get, sys_cap_fcntls_get), // 537
7319 BSDX_(__NR_bindat, sys_bindat), // 538
7320 BSDX_(__NR_connectat, sys_connectat), // 539
7321 BSDX_(__NR_chflagsat, sys_chflagsat), // 540
7322 BSDXY(__NR_accept4, sys_accept4), // 541
7323 BSDXY(__NR_pipe2, sys_pipe2), // 542
7324 BSDX_(__NR_aio_mlock, sys_aio_mlock), // 543
7325 BSDXY(__NR_procctl, sys_procctl), // 544
7327 // 544 is the highest syscall on FreeBSD 9
7329 #if (FREEBSD_VERS >= FREEBSD_10)
7331 BSDXY(__NR_ppoll, sys_ppoll), // 545
7332 BSDX_(__NR_futimens, sys_futimens), // 546
7333 BSDX_(__NR_utimensat, sys_utimensat), // 547
7335 #endif // FREEBSD_VERS >= FREEBSD_10
7337 #if (FREEBSD_VERS >= FREEBSD_11)
7339 /* 548 is obsolete numa_getaffinity */
7340 /* 549 is obsolete numa_setaffinity */
7341 BSDX_(__NR_fdatasync, sys_fdatasync), // 550
7343 #endif // FREEBSD_VERS >= FREEBSD_11
7345 #if (FREEBSD_VERS >= FREEBSD_12)
7346 BSDXY(__NR_fstat, sys_fstat), // 551
7347 BSDXY(__NR_fstatat, sys_fstatat), // 552
7348 BSDXY(__NR_fhstat, sys_fhstat), // 553
7349 BSDXY(__NR_getdirentries, sys_getdirentries), // 554
7350 BSDXY(__NR_statfs, sys_statfs), // 555
7351 BSDXY(__NR_fstatfs, sys_fstatfs), // 556
7352 BSDXY(__NR_getfsstat, sys_getfsstat), // 557
7353 BSDXY(__NR_fhstatfs, sys_fhstatfs), // 558
7354 BSDX_(__NR_mknodat, sys_mknodat), // 559
7355 BSDXY(__NR_kevent, sys_kevent), // 560
7356 BSDXY(__NR_cpuset_getdomain, sys_cpuset_getdomain), // 561
7357 BSDX_(__NR_cpuset_setdomain, sys_cpuset_setdomain), // 562
7358 BSDXY(__NR_getrandom, sys_getrandom), // 563
7359 BSDXY(__NR_getfhat, sys_getfhat), // 564
7360 BSDX_(__NR_fhlink, sys_fhlink), // 565
7361 BSDX_(__NR_fhlinkat, sys_fhlinkat), // 566
7362 BSDXY(__NR_fhreadlink, sys_fhreadlink), // 567
7363 #endif // FREEBSD_VERS >= FREEBSD_12
7365 #if (FREEBSD_VERS >= FREEBSD_12_2)
7366 BSDX_(__NR_funlinkat, sys_funlinkat), // 568
7367 BSDX_(__NR_copy_file_range, sys_copy_file_range), // 569
7368 BSDXY(__NR___sysctlbyname, sys___sysctlbyname), // 570
7370 #if (FREEBSD_VERS >= FREEBSD_13_0)
7371 BSDXY(__NR_shm_open2, sys_shm_open2), // 571
7372 // unimpl __NR_shm_rename 572
7373 BSDX_(__NR_sigfastblock, sys_sigfastblock), // 573
7374 BSDXY( __NR___realpathat, sys___realpathat), // 574
7375 #endif
7376 // unimpl __NR_close_range 575
7377 #endif
7379 #if (FREEBSD_VERS >= FREEBSD_13_0)
7380 // unimpl __NR_rpctls_syscall 576
7381 BSDX_(__NR___specialfd, sys___specialfd), // 577
7382 // unimpl __NR_aio_writev 578
7383 // unimpl __NR_aio_readv 579
7384 #endif
7386 #if (FREEBSD_VERS >= FREEBSD_13_1)
7387 // unimpl __NR_fspacectl 580
7388 // unimpl __NR_sched_getcpu 581
7389 BSDX_(__NR_swapoff, sys_swapoff), // 582
7390 #endif
7392 BSDX_(__NR_fake_sigreturn, sys_fake_sigreturn), // 1000, fake sigreturn
7396 const SyscallTableEntry* ML_(get_freebsd_syscall_entry) ( UInt sysno )
7398 const UInt syscall_table_size
7399 = sizeof(ML_(syscall_table)) / sizeof(ML_(syscall_table)[0]);
7401 /* Is it in the contiguous initial section of the table? */
7402 if (sysno < syscall_table_size) {
7403 const SyscallTableEntry* sys = &ML_(syscall_table)[sysno];
7404 if (sys->before == NULL) {
7405 return NULL; /* no entry */
7407 return sys;
7410 /* Can't find a wrapper */
7411 return NULL;
7414 /*--------------------------------------------------------------------*/
7415 /*--- end ---*/
7416 /*--------------------------------------------------------------------*/
7418 #endif // defined(VGO_freebsd)