2 /*--------------------------------------------------------------------*/
3 /*--- Linux-specific syscalls, etc. syswrap-linux.c ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2000-2017 Nicholas Nethercote
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #if defined(VGO_linux)
31 #include "pub_core_basics.h"
32 #include "pub_core_vki.h"
33 #include "pub_core_vkiscnums.h"
34 #include "pub_core_threadstate.h"
35 #include "pub_core_aspacemgr.h"
36 #include "pub_core_debuginfo.h" // VG_(di_notify_*)
37 #include "pub_core_transtab.h" // VG_(discard_translations)
38 #include "pub_core_xarray.h"
39 #include "pub_core_clientstate.h"
40 #include "pub_core_debuglog.h"
41 #include "pub_core_libcbase.h"
42 #include "pub_core_libcassert.h"
43 #include "pub_core_libcfile.h"
44 #include "pub_core_libcprint.h"
45 #include "pub_core_libcproc.h"
46 #include "pub_core_libcsignal.h"
47 #include "pub_core_machine.h" // VG_(get_SP)
48 #include "pub_core_mallocfree.h"
49 #include "pub_core_tooliface.h"
50 #include "pub_core_options.h"
51 #include "pub_core_scheduler.h"
52 #include "pub_core_signals.h"
53 #include "pub_core_stacks.h"
54 #include "pub_core_syscall.h"
55 #include "pub_core_syswrap.h"
56 #include "pub_core_inner.h"
57 #if defined(ENABLE_INNER_CLIENT_REQUEST)
58 #include "pub_core_clreq.h"
61 #include "priv_types_n_macros.h"
62 #include "priv_syswrap-generic.h"
63 #include "priv_syswrap-linux.h"
64 #include "priv_syswrap-main.h"
65 #include "priv_syswrap-xen.h"
67 // Run a thread from beginning to end and return the thread's
68 // scheduler-return-code.
69 static VgSchedReturnCode
thread_wrapper(Word
/*ThreadId*/ tidW
)
71 VgSchedReturnCode ret
;
72 ThreadId tid
= (ThreadId
)tidW
;
73 Int lwpid
= VG_(gettid
)();
74 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
76 VG_(debugLog
)(1, "syswrap-linux",
77 "thread_wrapper(tid=%u,lwpid=%d): entry\n",
80 vg_assert(tst
->status
== VgTs_Init
);
82 /* make sure we get the CPU lock before doing anything significant */
83 VG_(acquire_BigLock
)(tid
, "thread_wrapper(starting new thread)");
86 VG_(printf
)("thread tid %u started: stack = %p\n",
89 /* Make sure error reporting is enabled in the new thread. */
90 tst
->err_disablement_level
= 0;
92 VG_TRACK(pre_thread_first_insn
, tid
);
94 tst
->os_state
.lwpid
= lwpid
;
95 /* Set the threadgroup for real. This overwrites the provisional value set
96 in do_clone(). See comments in do_clone for background, also #226116. */
97 tst
->os_state
.threadgroup
= VG_(getpid
)();
99 /* Thread created with all signals blocked; scheduler will set the
102 ret
= VG_(scheduler
)(tid
);
104 vg_assert(VG_(is_exiting
)(tid
));
106 vg_assert(tst
->status
== VgTs_Runnable
);
107 vg_assert(VG_(is_running_thread
)(tid
));
109 VG_(debugLog
)(1, "syswrap-linux",
110 "thread_wrapper(tid=%u,lwpid=%d): exit, schedreturncode %s\n",
111 tid
, lwpid
, VG_(name_of_VgSchedReturnCode
)(ret
));
113 /* Return to caller, still holding the lock. */
118 /* ---------------------------------------------------------------------
120 ------------------------------------------------------------------ */
122 /* Run a thread all the way to the end, then do appropriate exit actions
123 (this is the last-one-out-turn-off-the-lights bit). */
124 static void run_a_thread_NORETURN ( Word tidW
)
126 ThreadId tid
= (ThreadId
)tidW
;
127 VgSchedReturnCode src
;
130 #ifdef ENABLE_INNER_CLIENT_REQUEST
131 Int registered_vgstack_id
;
134 VG_(debugLog
)(1, "syswrap-linux",
135 "run_a_thread_NORETURN(tid=%u): pre-thread_wrapper\n",
138 tst
= VG_(get_ThreadState
)(tid
);
141 /* An thread has two stacks:
142 * the simulated stack (used by the synthetic cpu. Guest process
143 is using this stack).
144 * the valgrind stack (used by the real cpu. Valgrind code is running
146 When Valgrind runs as an inner, it must signals that its (real) stack
147 is the stack to use by the outer to e.g. do stacktraces.
150 (registered_vgstack_id
151 = VALGRIND_STACK_REGISTER (tst
->os_state
.valgrind_stack_base
,
152 tst
->os_state
.valgrind_stack_init_SP
));
154 /* Run the thread all the way through. */
155 src
= thread_wrapper(tid
);
157 VG_(debugLog
)(1, "syswrap-linux",
158 "run_a_thread_NORETURN(tid=%u): post-thread_wrapper\n",
161 c
= VG_(count_living_threads
)();
162 vg_assert(c
>= 1); /* stay sane */
164 /* Deregister thread's stack. */
165 if (tst
->os_state
.stk_id
!= NULL_STK_ID
)
166 VG_(deregister_stack
)(tst
->os_state
.stk_id
);
168 // Tell the tool this thread is exiting
169 VG_TRACK( pre_thread_ll_exit
, tid
);
171 /* If the thread is exiting with errors disabled, complain loudly;
172 doing so is bad (does the user know this has happened?) Also,
173 in all cases, be paranoid and clear the flag anyway so that the
174 thread slot is safe in this respect if later reallocated. This
175 should be unnecessary since the flag should be cleared when the
176 slot is reallocated, in thread_wrapper(). */
177 if (tst
->err_disablement_level
> 0) {
179 "WARNING: exiting thread has error reporting disabled.\n"
180 "WARNING: possibly as a result of some mistake in the use\n"
181 "WARNING: of the VALGRIND_DISABLE_ERROR_REPORTING macros.\n"
185 "run_a_thread_NORETURN(tid=%u): "
186 "WARNING: exiting thread has err_disablement_level = %u\n",
187 tid
, tst
->err_disablement_level
190 tst
->err_disablement_level
= 0;
194 VG_(debugLog
)(1, "syswrap-linux",
195 "run_a_thread_NORETURN(tid=%u): "
196 "last one standing\n",
199 /* We are the last one standing. Keep hold of the lock and
200 carry on to show final tool results, then exit the entire system.
201 Use the continuation pointer set at startup in m_main. */
202 ( * VG_(address_of_m_main_shutdown_actions_NORETURN
) ) (tid
, src
);
205 VG_(debugLog
)(1, "syswrap-linux",
206 "run_a_thread_NORETURN(tid=%u): "
207 "not last one standing\n",
210 /* OK, thread is dead, but others still exist. Just exit. */
212 /* This releases the run lock */
213 VG_(exit_thread
)(tid
);
214 vg_assert(tst
->status
== VgTs_Zombie
);
215 vg_assert(sizeof(tst
->status
) == 4);
216 vg_assert(sizeof(tst
->os_state
.exitcode
) == sizeof(Word
));
218 INNER_REQUEST (VALGRIND_STACK_DEREGISTER (registered_vgstack_id
));
220 /* We have to use this sequence to terminate the thread to
221 prevent a subtle race. If VG_(exit_thread)() had left the
222 ThreadState as Empty, then it could have been reallocated,
223 reusing the stack while we're doing these last cleanups.
224 Instead, VG_(exit_thread) leaves it as Zombie to prevent
225 reallocation. We need to make sure we don't touch the stack
226 between marking it Empty and exiting. Hence the
228 #if defined(VGP_x86_linux)
231 "movl %1, %0\n" /* set tst->status = VgTs_Empty */
232 "movl %2, %%eax\n" /* set %eax = __NR_exit */
233 "movl %3, %%ebx\n" /* set %ebx = tst->os_state.exitcode */
234 "int $0x80\n" /* exit(tst->os_state.exitcode) */
237 : "n" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
240 #elif defined(VGP_amd64_linux)
242 "movl %1, %0\n" /* set tst->status = VgTs_Empty */
243 "movq %2, %%rax\n" /* set %rax = __NR_exit */
244 "movq %3, %%rdi\n" /* set %rdi = tst->os_state.exitcode */
245 "syscall\n" /* exit(tst->os_state.exitcode) */
247 : "n" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
250 #elif defined(VGP_ppc32_linux) || defined(VGP_ppc64be_linux) \
251 || defined(VGP_ppc64le_linux)
252 { UInt vgts_empty
= (UInt
)VgTs_Empty
;
254 "stw %1,%0\n\t" /* set tst->status = VgTs_Empty */
255 "li 0,%2\n\t" /* set r0 = __NR_exit */
256 "lwz 3,%3\n\t" /* set r3 = tst->os_state.exitcode */
257 "sc\n\t" /* exit(tst->os_state.exitcode) */
259 : "r" (vgts_empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
263 #elif defined(VGP_arm_linux)
265 "str %1, %0\n" /* set tst->status = VgTs_Empty */
266 "mov r7, %2\n" /* set %r7 = __NR_exit */
267 "ldr r0, %3\n" /* set %r0 = tst->os_state.exitcode */
268 "svc 0x00000000\n" /* exit(tst->os_state.exitcode) */
270 : "r" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
273 #elif defined(VGP_arm64_linux)
275 "str %w1, %0\n" /* set tst->status = VgTs_Empty (32-bit store) */
276 "mov x8, %2\n" /* set %x8 = __NR_exit */
277 "ldr x0, %3\n" /* set %x0 = tst->os_state.exitcode */
278 "svc 0x00000000\n" /* exit(tst->os_state.exitcode) */
280 : "r" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
283 #elif defined(VGP_s390x_linux)
285 "st %1, %0\n" /* set tst->status = VgTs_Empty */
286 "lg 2, %3\n" /* set r2 = tst->os_state.exitcode */
287 "svc %2\n" /* exit(tst->os_state.exitcode) */
289 : "d" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
292 #elif defined(VGP_mips32_linux) || defined(VGP_mips64_linux)
294 "sw %1, %0\n\t" /* set tst->status = VgTs_Empty */
295 "li $2, %2\n\t" /* set v0 = __NR_exit */
296 "lw $4, %3\n\t" /* set a0 = tst->os_state.exitcode */
297 "syscall\n\t" /* exit(tst->os_state.exitcode) */
300 : "r" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
301 : "cc", "memory" , "v0", "a0"
303 #elif defined(VGP_nanomips_linux)
305 "sw %1, %0 \n\t" /* set tst->status = VgTs_Empty */
306 "li $t4, %2 \n\t" /* set t4 = __NR_exit */
307 "lw $a0, %3 \n\t" /* set a0 = tst->os_state.exitcode */
308 "syscall[32] \n\t" /* exit(tst->os_state.exitcode) */
310 : "r" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
311 : "memory" , "$t4", "$a0"
314 # error Unknown platform
317 VG_(core_panic
)("Thread exit failed?\n");
324 Word
ML_(start_thread_NORETURN
) ( void* arg
)
326 ThreadState
* tst
= (ThreadState
*)arg
;
327 ThreadId tid
= tst
->tid
;
329 run_a_thread_NORETURN ( (Word
)tid
);
334 /* Allocate a stack for this thread, if it doesn't already have one.
335 They're allocated lazily, and never freed. Returns the initial stack
336 pointer value to use, or 0 if allocation failed. */
337 Addr
ML_(allocstack
)(ThreadId tid
)
339 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
343 /* Either the stack_base and stack_init_SP are both zero (in which
344 case a stack hasn't been allocated) or they are both non-zero,
345 in which case it has. */
347 if (tst
->os_state
.valgrind_stack_base
== 0)
348 vg_assert(tst
->os_state
.valgrind_stack_init_SP
== 0);
350 if (tst
->os_state
.valgrind_stack_base
!= 0)
351 vg_assert(tst
->os_state
.valgrind_stack_init_SP
!= 0);
353 /* If no stack is present, allocate one. */
355 if (tst
->os_state
.valgrind_stack_base
== 0) {
356 stack
= VG_(am_alloc_VgStack
)( &initial_SP
);
358 tst
->os_state
.valgrind_stack_base
= (Addr
)stack
;
359 tst
->os_state
.valgrind_stack_init_SP
= initial_SP
;
364 VG_(printf
)( "stack for tid %u at %p; init_SP=%p\n",
366 (void*)tst
->os_state
.valgrind_stack_base
,
367 (void*)tst
->os_state
.valgrind_stack_init_SP
);
369 return tst
->os_state
.valgrind_stack_init_SP
;
372 /* Allocate a stack for the main thread, and run it all the way to the
373 end. Although we already have a working VgStack
374 (VG_(interim_stack)) it's better to allocate a new one, so that
375 overflow detection works uniformly for all threads.
377 void VG_(main_thread_wrapper_NORETURN
)(ThreadId tid
)
380 VG_(debugLog
)(1, "syswrap-linux",
381 "entering VG_(main_thread_wrapper_NORETURN)\n");
383 sp
= ML_(allocstack
)(tid
);
384 #if defined(ENABLE_INNER_CLIENT_REQUEST)
386 // we must register the main thread stack before the call
387 // to ML_(call_on_new_stack_0_1), otherwise the outer valgrind
388 // reports 'write error' on the non registered stack.
389 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
392 VALGRIND_STACK_REGISTER (tst
->os_state
.valgrind_stack_base
,
393 tst
->os_state
.valgrind_stack_init_SP
));
397 #if defined(VGP_ppc32_linux)
398 /* make a stack frame */
402 #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
403 /* make a stack frame */
407 #elif defined(VGP_s390x_linux)
408 /* make a stack frame */
414 /* If we can't even allocate the first thread's stack, we're hosed.
416 vg_assert2(sp
!= 0, "Cannot allocate main thread's stack.");
418 /* shouldn't be any other threads around yet */
419 vg_assert( VG_(count_living_threads
)() == 1 );
421 ML_(call_on_new_stack_0_1
)(
422 (Addr
)sp
, /* stack */
423 0, /* bogus return address */
424 run_a_thread_NORETURN
, /* fn to call */
425 (Word
)tid
/* arg to give it */
432 /* Clone a new thread. Note that in the clone syscalls, we hard-code
433 tlsaddr argument as NULL : the guest TLS is emulated via guest
434 registers, and Valgrind itself has no thread local storage. */
435 static SysRes
clone_new_thread ( Word (*fn
)(void *),
443 /* Note that in all the below, we make sys_clone appear to have returned
444 Success(0) in the child, by assigning the relevant child guest
445 register(s) just before the clone syscall. */
446 #if defined(VGP_x86_linux)
448 ctst
->arch
.vex
.guest_EAX
= 0;
449 eax
= do_syscall_clone_x86_linux
450 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
451 child_tidptr
, parent_tidptr
, NULL
);
452 res
= VG_(mk_SysRes_x86_linux
)( eax
);
453 #elif defined(VGP_amd64_linux)
455 ctst
->arch
.vex
.guest_RAX
= 0;
456 rax
= do_syscall_clone_amd64_linux
457 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
458 child_tidptr
, parent_tidptr
, NULL
);
459 res
= VG_(mk_SysRes_amd64_linux
)( rax
);
460 #elif defined(VGP_ppc32_linux)
462 UInt old_cr
= LibVEX_GuestPPC32_get_CR( &ctst
->arch
.vex
);
464 ctst
->arch
.vex
.guest_GPR3
= 0;
466 LibVEX_GuestPPC32_put_CR( old_cr
& ~(1<<28), &ctst
->arch
.vex
);
467 word64
= do_syscall_clone_ppc32_linux
468 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
469 child_tidptr
, parent_tidptr
, NULL
);
470 /* High half word64 is syscall return value. Low half is
471 the entire CR, from which we need to extract CR0.SO. */
472 /* VG_(printf)("word64 = 0x%llx\n", word64); */
473 res
= VG_(mk_SysRes_ppc32_linux
)(/*val*/(UInt
)(word64
>> 32),
474 /*errflag*/ (((UInt
)word64
) >> 28) & 1);
475 #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
477 UInt old_cr
= LibVEX_GuestPPC64_get_CR( &ctst
->arch
.vex
);
478 UInt flag
= ctst
->arch
.vex
.guest_syscall_flag
;
480 ctst
->arch
.vex
.guest_GPR3
= 0;
482 LibVEX_GuestPPC64_put_CR( old_cr
& ~(1<<28), &ctst
->arch
.vex
);
483 word64
= do_syscall_clone_ppc64_linux
484 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
485 child_tidptr
, parent_tidptr
, NULL
);
486 /* Low half word64 is syscall return value. Hi half is
487 the entire CR, from which we need to extract CR0.SO. */
488 /* VG_(printf)("word64 = 0x%llx\n", word64); */
489 res
= VG_(mk_SysRes_ppc64_linux
)
490 (/*val*/(UInt
)(word64
& 0xFFFFFFFFULL
),
491 /*errflag*/ (UInt
)((word64
>> (32+28)) & 1), flag
);
492 #elif defined(VGP_s390x_linux)
494 ctst
->arch
.vex
.guest_r2
= 0;
495 r2
= do_syscall_clone_s390x_linux
496 (stack
, flags
, parent_tidptr
, child_tidptr
, NULL
,
497 ML_(start_thread_NORETURN
), ctst
);
498 res
= VG_(mk_SysRes_s390x_linux
)( r2
);
499 #elif defined(VGP_arm64_linux)
501 ctst
->arch
.vex
.guest_X0
= 0;
502 x0
= do_syscall_clone_arm64_linux
503 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
504 child_tidptr
, parent_tidptr
, NULL
);
505 res
= VG_(mk_SysRes_arm64_linux
)( x0
);
506 #elif defined(VGP_arm_linux)
508 ctst
->arch
.vex
.guest_R0
= 0;
509 r0
= do_syscall_clone_arm_linux
510 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
511 child_tidptr
, parent_tidptr
, NULL
);
512 res
= VG_(mk_SysRes_arm_linux
)( r0
);
513 #elif defined(VGP_mips64_linux)
515 ctst
->arch
.vex
.guest_r2
= 0;
516 ctst
->arch
.vex
.guest_r7
= 0;
517 ret
= do_syscall_clone_mips64_linux
518 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
519 parent_tidptr
, NULL
, child_tidptr
);
520 res
= VG_(mk_SysRes_mips64_linux
)( /* val */ ret
, 0, /* errflag */ 0);
521 #elif defined(VGP_mips32_linux)
523 ctst
->arch
.vex
.guest_r2
= 0;
524 ctst
->arch
.vex
.guest_r7
= 0;
525 ret
= do_syscall_clone_mips_linux
526 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
527 child_tidptr
, parent_tidptr
, NULL
);
528 /* High half word64 is syscall return value. Low half is
529 the entire CR, from which we need to extract CR0.SO. */
530 res
= VG_ (mk_SysRes_mips32_linux
) (/*val */ ret
, 0, /*errflag */ 0);
531 #elif defined(VGP_nanomips_linux)
533 ctst
->arch
.vex
.guest_r4
= 0;
534 ret
= do_syscall_clone_nanomips_linux
535 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
536 child_tidptr
, parent_tidptr
, NULL
);
537 res
= VG_ (mk_SysRes_nanomips_linux
) (ret
);
539 # error Unknown platform
544 static void setup_child ( /*OUT*/ ThreadArchState
*child
,
545 /*IN*/ ThreadArchState
*parent
)
547 /* We inherit our parent's guest state. */
548 child
->vex
= parent
->vex
;
549 child
->vex_shadow1
= parent
->vex_shadow1
;
550 child
->vex_shadow2
= parent
->vex_shadow2
;
552 #if defined(VGP_x86_linux)
553 extern void ML_(x86_setup_LDT_GDT
) ( /*OUT*/ ThreadArchState
*child
,
554 /*IN*/ ThreadArchState
*parent
);
555 ML_(x86_setup_LDT_GDT
)(child
, parent
);
559 static SysRes
setup_child_tls (ThreadId ctid
, Addr tlsaddr
)
561 static const Bool debug
= False
;
562 ThreadState
* ctst
= VG_(get_ThreadState
)(ctid
);
563 // res is succesful by default, overriden if a real syscall is needed/done.
564 SysRes res
= VG_(mk_SysRes_Success
)(0);
567 VG_(printf
)("clone child has SETTLS: tls at %#lx\n", tlsaddr
);
569 #if defined(VGP_x86_linux)
570 vki_modify_ldt_t
* tlsinfo
= (vki_modify_ldt_t
*)tlsaddr
;
572 VG_(printf
)("clone child has SETTLS: tls info at %p: idx=%u "
573 "base=%#lx limit=%x; esp=%#x fs=%x gs=%x\n",
574 tlsinfo
, tlsinfo
->entry_number
,
575 tlsinfo
->base_addr
, tlsinfo
->limit
,
576 ctst
->arch
.vex
.guest_ESP
,
577 ctst
->arch
.vex
.guest_FS
, ctst
->arch
.vex
.guest_GS
);
578 res
= ML_(x86_sys_set_thread_area
)(ctid
, tlsinfo
);
579 #elif defined(VGP_amd64_linux)
580 ctst
->arch
.vex
.guest_FS_CONST
= tlsaddr
;
581 #elif defined(VGP_ppc32_linux)
582 ctst
->arch
.vex
.guest_GPR2
= tlsaddr
;
583 #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
584 ctst
->arch
.vex
.guest_GPR13
= tlsaddr
;
585 #elif defined(VGP_s390x_linux)
586 ctst
->arch
.vex
.guest_a0
= (UInt
) (tlsaddr
>> 32);
587 ctst
->arch
.vex
.guest_a1
= (UInt
) tlsaddr
;
588 #elif defined(VGP_arm64_linux)
589 /* Just assign the tls pointer in the guest TPIDR_EL0. */
590 ctst
->arch
.vex
.guest_TPIDR_EL0
= tlsaddr
;
591 #elif defined(VGP_arm_linux)
592 /* Just assign the tls pointer in the guest TPIDRURO. */
593 ctst
->arch
.vex
.guest_TPIDRURO
= tlsaddr
;
594 #elif defined(VGP_mips64_linux)
595 ctst
->arch
.vex
.guest_ULR
= tlsaddr
;
596 ctst
->arch
.vex
.guest_r27
= tlsaddr
;
597 #elif defined(VGP_mips32_linux) || defined(VGP_nanomips_linux)
598 ctst
->arch
.vex
.guest_ULR
= tlsaddr
;
599 ctst
->arch
.vex
.guest_r27
= tlsaddr
;
601 # error Unknown platform
607 When a client clones, we need to keep track of the new thread. This means:
608 1. allocate a ThreadId+ThreadState+stack for the thread
610 2. initialize the thread's new VCPU state
612 3. create the thread using the same args as the client requested,
613 but using the scheduler entrypoint for EIP, and a separate stack
616 static SysRes
do_clone ( ThreadId ptid
,
617 UWord flags
, Addr sp
,
622 ThreadId ctid
= VG_(alloc_ThreadState
)();
623 ThreadState
* ptst
= VG_(get_ThreadState
)(ptid
);
624 ThreadState
* ctst
= VG_(get_ThreadState
)(ctid
);
627 vki_sigset_t blockall
, savedmask
;
629 VG_(sigfillset
)(&blockall
);
631 vg_assert(VG_(is_running_thread
)(ptid
));
632 vg_assert(VG_(is_valid_tid
)(ctid
));
634 stack
= (UWord
*)ML_(allocstack
)(ctid
);
636 res
= VG_(mk_SysRes_Error
)( VKI_ENOMEM
);
640 /* Copy register state
642 Both parent and child return to the same place, and the code
643 following the clone syscall works out which is which, so we
644 don't need to worry about it.
646 The parent gets the child's new tid returned from clone, but the
649 If the clone call specifies a NULL sp for the new thread, then
650 it actually gets a copy of the parent's sp.
652 setup_child( &ctst
->arch
, &ptst
->arch
);
655 VG_(set_SP
)(ctid
, sp
);
657 ctst
->os_state
.parent
= ptid
;
659 /* inherit signal mask */
660 ctst
->sig_mask
= ptst
->sig_mask
;
661 ctst
->tmp_sig_mask
= ptst
->sig_mask
;
663 /* Start the child with its threadgroup being the same as the
664 parent's. This is so that any exit_group calls that happen
665 after the child is created but before it sets its
666 os_state.threadgroup field for real (in thread_wrapper in
667 syswrap-linux.c), really kill the new thread. a.k.a this avoids
668 a race condition in which the thread is unkillable (via
669 exit_group) because its threadgroup is not set. The race window
670 is probably only a few hundred or a few thousand cycles long.
672 ctst
->os_state
.threadgroup
= ptst
->os_state
.threadgroup
;
674 ML_(guess_and_register_stack
) (sp
, ctst
);
676 /* Assume the clone will succeed, and tell any tool that wants to
677 know that this thread has come into existence. We cannot defer
678 it beyond this point because setup_tls, just below,
679 causes checks to assert by making references to the new ThreadId
680 if we don't state the new thread exists prior to that point.
681 If the clone fails, we'll send out a ll_exit notification for it
682 at the out: label below, to clean up. */
683 vg_assert(VG_(owns_BigLock_LL
)(ptid
));
684 VG_TRACK ( pre_thread_ll_create
, ptid
, ctid
);
686 if (flags
& VKI_CLONE_SETTLS
) {
687 res
= setup_child_tls(ctid
, tlsaddr
);
691 flags
&= ~VKI_CLONE_SETTLS
;
693 /* start the thread with everything blocked */
694 VG_(sigprocmask
)(VKI_SIG_SETMASK
, &blockall
, &savedmask
);
696 /* Create the new thread */
697 res
= clone_new_thread ( ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
698 child_tidptr
, parent_tidptr
);
700 VG_(sigprocmask
)(VKI_SIG_SETMASK
, &savedmask
, NULL
);
703 if (sr_isError(res
)) {
705 VG_(cleanup_thread
)(&ctst
->arch
);
706 ctst
->status
= VgTs_Empty
;
707 /* oops. Better tell the tool the thread exited in a hurry :-) */
708 VG_TRACK( pre_thread_ll_exit
, ctid
);
714 /* Do a clone which is really a fork().
715 ML_(do_fork_clone) uses the clone syscall to fork a child process.
716 Note that this should not be called for a thread creation.
717 Also, some flags combinations are not supported, and such combinations
718 are handled either by masking the non supported flags or by asserting.
720 The CLONE_VFORK flag is accepted, as this just tells that the parent is
721 suspended till the child exits or calls execve. We better keep this flag,
722 just in case the guests parent/client code depends on this synchronisation.
724 We cannot keep the flag CLONE_VM, as Valgrind will do whatever host
725 instructions in the child process, that will mess up the parent host
726 memory. So, we hope for the best and assumes that the guest application does
727 not (really) depends on sharing the memory between parent and child in the
728 interval between clone and exits/execve.
730 If child_sp != 0, the child (guest) sp will be set to child_sp just after the
731 clone syscall, before child guest instructions are executed. */
732 static SysRes
ML_(do_fork_clone
) ( ThreadId tid
, UInt flags
,
733 Int
* parent_tidptr
, Int
* child_tidptr
,
736 vki_sigset_t fork_saved_mask
;
740 if (flags
& (VKI_CLONE_SETTLS
| VKI_CLONE_FS
| VKI_CLONE_VM
742 return VG_(mk_SysRes_Error
)( VKI_EINVAL
);
744 /* Block all signals during fork, so that we can fix things up in
745 the child without being interrupted. */
746 VG_(sigfillset
)(&mask
);
747 VG_(sigprocmask
)(VKI_SIG_SETMASK
, &mask
, &fork_saved_mask
);
749 VG_(do_atfork_pre
)(tid
);
751 /* Since this is the fork() form of clone, we don't need all that
753 #if defined(VGP_x86_linux) \
754 || defined(VGP_ppc32_linux) \
755 || defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux) \
756 || defined(VGP_arm_linux) || defined(VGP_mips32_linux) \
757 || defined(VGP_mips64_linux) || defined(VGP_arm64_linux) \
758 || defined(VGP_nanomips_linux)
759 res
= VG_(do_syscall5
)( __NR_clone
, flags
,
760 (UWord
)NULL
, (UWord
)parent_tidptr
,
761 (UWord
)NULL
, (UWord
)child_tidptr
);
762 #elif defined(VGP_amd64_linux)
763 /* note that the last two arguments are the opposite way round to x86 and
764 ppc32 as the amd64 kernel expects the arguments in a different order */
765 res
= VG_(do_syscall5
)( __NR_clone
, flags
,
766 (UWord
)NULL
, (UWord
)parent_tidptr
,
767 (UWord
)child_tidptr
, (UWord
)NULL
);
768 #elif defined(VGP_s390x_linux)
769 /* Note that s390 has the stack first and then the flags */
770 res
= VG_(do_syscall4
)( __NR_clone
, (UWord
) NULL
, flags
,
771 (UWord
)parent_tidptr
, (UWord
)child_tidptr
);
773 # error Unknown platform
776 if (!sr_isError(res
) && sr_Res(res
) == 0) {
779 VG_(set_SP
)(tid
, child_sp
);
780 VG_(do_atfork_child
)(tid
);
782 /* restore signal mask */
783 VG_(sigprocmask
)(VKI_SIG_SETMASK
, &fork_saved_mask
, NULL
);
786 if (!sr_isError(res
) && sr_Res(res
) > 0) {
788 VG_(do_atfork_parent
)(tid
);
790 if (VG_(clo_trace_syscalls
))
791 VG_(printf
)(" clone(fork): process %d created child %" FMT_REGWORD
"u\n",
792 VG_(getpid
)(), (RegWord
)sr_Res(res
));
794 /* restore signal mask */
795 VG_(sigprocmask
)(VKI_SIG_SETMASK
, &fork_saved_mask
, NULL
);
801 /* ---------------------------------------------------------------------
802 PRE/POST wrappers for arch-generic, Linux-specific syscalls
803 ------------------------------------------------------------------ */
805 // Nb: See the comment above the generic PRE/POST wrappers in
806 // m_syswrap/syswrap-generic.c for notes about how they work.
808 #define PRE(name) DEFN_PRE_TEMPLATE(linux, name)
809 #define POST(name) DEFN_POST_TEMPLATE(linux, name)
816 PRINT("sys_clone ( %" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
817 "x, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
,
820 // Order of arguments differs between platforms.
821 #if defined(VGP_x86_linux) \
822 || defined(VGP_ppc32_linux) \
823 || defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux) \
824 || defined(VGP_arm_linux) || defined(VGP_mips32_linux) \
825 || defined(VGP_mips64_linux) || defined(VGP_arm64_linux) \
826 || defined(VGP_nanomips_linux)
827 #define ARG_CHILD_TIDPTR ARG5
828 #define PRA_CHILD_TIDPTR PRA5
831 #elif defined(VGP_amd64_linux) || defined(VGP_s390x_linux)
832 #define ARG_CHILD_TIDPTR ARG4
833 #define PRA_CHILD_TIDPTR PRA4
837 # error Unknown platform
839 // And s390x is even more special, and inverts flags and child stack args
840 #if defined(VGP_s390x_linux)
841 #define ARG_FLAGS ARG2
842 #define PRA_FLAGS PRA2
843 #define ARG_CHILD_STACK ARG1
844 #define PRA_CHILD_STACK PRA1
846 #define ARG_FLAGS ARG1
847 #define PRA_FLAGS PRA1
848 #define ARG_CHILD_STACK ARG2
849 #define PRA_CHILD_STACK PRA2
852 if (VG_(tdict
).track_pre_reg_read
) {
853 PRA_FLAGS("clone", unsigned long, flags
);
854 PRA_CHILD_STACK("clone", void *, child_stack
);
857 if (ARG_FLAGS
& (VKI_CLONE_PARENT_SETTID
| VKI_CLONE_PIDFD
)) {
858 if (VG_(tdict
).track_pre_reg_read
) {
859 PRA3("clone", int *, parent_tidptr
);
861 PRE_MEM_WRITE("clone(parent_tidptr)", ARG3
, sizeof(Int
));
862 if (!VG_(am_is_valid_for_client
)(ARG3
, sizeof(Int
),
867 if (ARG_FLAGS
& VKI_CLONE_SETTLS
) {
868 if (VG_(tdict
).track_pre_reg_read
) {
869 PRA_TLS("clone", vki_modify_ldt_t
*, tlsinfo
);
871 /* Not very clear what is vki_modify_ldt_t: for many platforms, it is a
872 dummy type (that we define as a char). We only dereference/check the
873 ARG_TLS pointer if the type looks like a real type, i.e. sizeof > 1. */
874 if (sizeof(vki_modify_ldt_t
) > 1) {
875 PRE_MEM_READ("clone(tlsinfo)", ARG_TLS
, sizeof(vki_modify_ldt_t
));
876 if (!VG_(am_is_valid_for_client
)(ARG_TLS
, sizeof(vki_modify_ldt_t
),
882 if (ARG_FLAGS
& (VKI_CLONE_CHILD_SETTID
| VKI_CLONE_CHILD_CLEARTID
)) {
883 if (VG_(tdict
).track_pre_reg_read
) {
884 PRA_CHILD_TIDPTR("clone", int *, child_tidptr
);
886 PRE_MEM_WRITE("clone(child_tidptr)", ARG_CHILD_TIDPTR
, sizeof(Int
));
887 if (!VG_(am_is_valid_for_client
)(ARG_CHILD_TIDPTR
, sizeof(Int
),
894 SET_STATUS_Failure( VKI_EFAULT
);
898 cloneflags
= ARG_FLAGS
;
900 if (!ML_(client_signal_OK
)(ARG_FLAGS
& VKI_CSIGNAL
)) {
901 SET_STATUS_Failure( VKI_EINVAL
);
905 /* Only look at the flags we really care about */
906 switch (cloneflags
& (VKI_CLONE_VM
| VKI_CLONE_FS
907 | VKI_CLONE_FILES
| VKI_CLONE_VFORK
)) {
908 case VKI_CLONE_VM
| VKI_CLONE_FS
| VKI_CLONE_FILES
:
909 /* thread creation */
910 SET_STATUS_from_SysRes(
912 ARG_FLAGS
, /* flags */
913 (Addr
)ARG_CHILD_STACK
, /* child ESP */
914 (Int
*)(Addr
)ARG3
, /* parent_tidptr */
915 (Int
*)(Addr
)ARG_CHILD_TIDPTR
, /* child_tidptr */
916 (Addr
)ARG_TLS
)); /* set_tls */
919 case VKI_CLONE_VFORK
| VKI_CLONE_VM
: /* vfork */
920 case VKI_CLONE_VFORK
: /* vfork without memory sharing */
921 cloneflags
&= ~VKI_CLONE_VM
;
922 // FALLTHROUGH - assume vfork (somewhat) == fork, see ML_(do_fork_clone).
924 case 0: /* plain fork */
925 SET_STATUS_from_SysRes(
926 ML_(do_fork_clone
)(tid
,
927 cloneflags
, /* flags */
928 (Int
*)(Addr
)ARG3
, /* parent_tidptr */
929 (Int
*)(Addr
)ARG_CHILD_TIDPTR
, /* child_tidptr */
930 (Addr
)ARG_CHILD_STACK
));
934 /* should we just ENOSYS? */
935 VG_(message
)(Vg_UserMsg
, "Unsupported clone() flags: 0x%" FMT_REGWORD
937 VG_(message
)(Vg_UserMsg
, "\n");
938 VG_(message
)(Vg_UserMsg
, "The only supported clone() uses are:\n");
939 VG_(message
)(Vg_UserMsg
, " - via a threads library (LinuxThreads or NPTL)\n");
940 VG_(message
)(Vg_UserMsg
, " - via the implementation of fork or vfork\n");
942 ("Valgrind does not support general clone().");
945 if (SUCCESS
&& RES
!= 0) {
946 if (ARG_FLAGS
& (VKI_CLONE_PARENT_SETTID
| VKI_CLONE_PIDFD
))
947 POST_MEM_WRITE(ARG3
, sizeof(Int
));
948 if (ARG_FLAGS
& (VKI_CLONE_CHILD_SETTID
| VKI_CLONE_CHILD_CLEARTID
))
949 POST_MEM_WRITE(ARG_CHILD_TIDPTR
, sizeof(Int
));
950 if (ARG_FLAGS
& VKI_CLONE_PIDFD
) {
951 Int fd
= *(Int
*)(Addr
)ARG3
;
952 if (!ML_(fd_allowed
)(fd
, "clone", tid
, True
)) {
954 SET_STATUS_Failure( VKI_EMFILE
);
956 if (VG_(clo_track_fds
))
957 ML_(record_fd_open_nameless
) (tid
, fd
);
961 /* Thread creation was successful; let the child have the chance
963 *flags
|= SfYieldAfter
;
966 #undef ARG_CHILD_TIDPTR
967 #undef PRA_CHILD_TIDPTR
972 #undef ARG_CHILD_STACK
973 #undef PRA_CHILD_STACK
976 /* ---------------------------------------------------------------------
978 ------------------------------------------------------------------ */
982 // Nb: depending on 'flags', the 'type' and 'data' args may be ignored.
983 // We are conservative and check everything, except the memory pointed to
985 *flags
|= SfMayBlock
;
986 PRINT("sys_mount( %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x(%s), %#"
987 FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
988 ARG1
, (HChar
*)(Addr
)ARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
,
989 (HChar
*)(Addr
)ARG3
, ARG4
, ARG5
);
990 PRE_REG_READ5(long, "mount",
991 char *, source
, char *, target
, char *, type
,
992 unsigned long, flags
, void *, data
);
994 PRE_MEM_RASCIIZ( "mount(source)", ARG1
);
995 PRE_MEM_RASCIIZ( "mount(target)", ARG2
);
996 PRE_MEM_RASCIIZ( "mount(type)", ARG3
);
1001 PRINT("sys_oldumount( %#" FMT_REGWORD
"x )", ARG1
);
1002 PRE_REG_READ1(long, "umount", char *, path
);
1003 PRE_MEM_RASCIIZ( "umount(path)", ARG1
);
1008 PRINT("sys_umount( %#" FMT_REGWORD
"x, %ld )", ARG1
, SARG2
);
1009 PRE_REG_READ2(long, "umount2", char *, path
, int, flags
);
1010 PRE_MEM_RASCIIZ( "umount2(path)", ARG1
);
1013 /* Not actually wrapped by GLibc but does things with the system
1014 * mounts so it is put here.
1018 PRINT("sys_pivot_root ( %s %s )", (HChar
*)(Addr
)ARG1
, (HChar
*)(Addr
)ARG2
);
1019 PRE_REG_READ2(int, "pivot_root", char *, new_root
, char *, old_root
);
1020 PRE_MEM_RASCIIZ( "pivot_root(new_root)", ARG1
);
1021 PRE_MEM_RASCIIZ( "pivot_root(old_root)", ARG2
);
1025 /* ---------------------------------------------------------------------
1026 16- and 32-bit uid/gid wrappers
1027 ------------------------------------------------------------------ */
1031 PRINT("sys_setfsuid16 ( %" FMT_REGWORD
"u )", ARG1
);
1032 PRE_REG_READ1(long, "setfsuid16", vki_old_uid_t
, uid
);
1037 PRINT("sys_setfsuid ( %" FMT_REGWORD
"u )", ARG1
);
1038 PRE_REG_READ1(long, "setfsuid", vki_uid_t
, uid
);
1043 PRINT("sys_setfsgid16 ( %" FMT_REGWORD
"u )", ARG1
);
1044 PRE_REG_READ1(long, "setfsgid16", vki_old_gid_t
, gid
);
1049 PRINT("sys_setfsgid ( %" FMT_REGWORD
"u )", ARG1
);
1050 PRE_REG_READ1(long, "setfsgid", vki_gid_t
, gid
);
1053 PRE(sys_setresuid16
)
1055 PRINT("sys_setresuid16 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
1056 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
1057 PRE_REG_READ3(long, "setresuid16",
1058 vki_old_uid_t
, ruid
, vki_old_uid_t
, euid
, vki_old_uid_t
, suid
);
1063 PRINT("sys_setresuid ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
1064 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
1065 PRE_REG_READ3(long, "setresuid",
1066 vki_uid_t
, ruid
, vki_uid_t
, euid
, vki_uid_t
, suid
);
1069 PRE(sys_getresuid16
)
1071 PRINT("sys_getresuid16 ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1072 FMT_REGWORD
"x )", ARG1
,ARG2
,ARG3
);
1073 PRE_REG_READ3(long, "getresuid16",
1074 vki_old_uid_t
*, ruid
, vki_old_uid_t
*, euid
,
1075 vki_old_uid_t
*, suid
);
1076 PRE_MEM_WRITE( "getresuid16(ruid)", ARG1
, sizeof(vki_old_uid_t
) );
1077 PRE_MEM_WRITE( "getresuid16(euid)", ARG2
, sizeof(vki_old_uid_t
) );
1078 PRE_MEM_WRITE( "getresuid16(suid)", ARG3
, sizeof(vki_old_uid_t
) );
1080 POST(sys_getresuid16
)
1084 POST_MEM_WRITE( ARG1
, sizeof(vki_old_uid_t
) );
1085 POST_MEM_WRITE( ARG2
, sizeof(vki_old_uid_t
) );
1086 POST_MEM_WRITE( ARG3
, sizeof(vki_old_uid_t
) );
1092 PRINT("sys_getresuid ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1093 FMT_REGWORD
"x )", ARG1
,ARG2
,ARG3
);
1094 PRE_REG_READ3(long, "getresuid",
1095 vki_uid_t
*, ruid
, vki_uid_t
*, euid
, vki_uid_t
*, suid
);
1096 PRE_MEM_WRITE( "getresuid(ruid)", ARG1
, sizeof(vki_uid_t
) );
1097 PRE_MEM_WRITE( "getresuid(euid)", ARG2
, sizeof(vki_uid_t
) );
1098 PRE_MEM_WRITE( "getresuid(suid)", ARG3
, sizeof(vki_uid_t
) );
1104 POST_MEM_WRITE( ARG1
, sizeof(vki_uid_t
) );
1105 POST_MEM_WRITE( ARG2
, sizeof(vki_uid_t
) );
1106 POST_MEM_WRITE( ARG3
, sizeof(vki_uid_t
) );
1110 PRE(sys_setresgid16
)
1112 PRINT("sys_setresgid16 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
1113 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
1114 PRE_REG_READ3(long, "setresgid16",
1115 vki_old_gid_t
, rgid
,
1116 vki_old_gid_t
, egid
, vki_old_gid_t
, sgid
);
1121 PRINT("sys_setresgid ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
1122 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
1123 PRE_REG_READ3(long, "setresgid",
1124 vki_gid_t
, rgid
, vki_gid_t
, egid
, vki_gid_t
, sgid
);
1127 PRE(sys_getresgid16
)
1129 PRINT("sys_getresgid16 ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1130 FMT_REGWORD
"x )", ARG1
,ARG2
,ARG3
);
1131 PRE_REG_READ3(long, "getresgid16",
1132 vki_old_gid_t
*, rgid
, vki_old_gid_t
*, egid
,
1133 vki_old_gid_t
*, sgid
);
1134 PRE_MEM_WRITE( "getresgid16(rgid)", ARG1
, sizeof(vki_old_gid_t
) );
1135 PRE_MEM_WRITE( "getresgid16(egid)", ARG2
, sizeof(vki_old_gid_t
) );
1136 PRE_MEM_WRITE( "getresgid16(sgid)", ARG3
, sizeof(vki_old_gid_t
) );
1138 POST(sys_getresgid16
)
1142 POST_MEM_WRITE( ARG1
, sizeof(vki_old_gid_t
) );
1143 POST_MEM_WRITE( ARG2
, sizeof(vki_old_gid_t
) );
1144 POST_MEM_WRITE( ARG3
, sizeof(vki_old_gid_t
) );
1150 PRINT("sys_getresgid ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1151 FMT_REGWORD
"x )", ARG1
,ARG2
,ARG3
);
1152 PRE_REG_READ3(long, "getresgid",
1153 vki_gid_t
*, rgid
, vki_gid_t
*, egid
, vki_gid_t
*, sgid
);
1154 PRE_MEM_WRITE( "getresgid(rgid)", ARG1
, sizeof(vki_gid_t
) );
1155 PRE_MEM_WRITE( "getresgid(egid)", ARG2
, sizeof(vki_gid_t
) );
1156 PRE_MEM_WRITE( "getresgid(sgid)", ARG3
, sizeof(vki_gid_t
) );
1162 POST_MEM_WRITE( ARG1
, sizeof(vki_gid_t
) );
1163 POST_MEM_WRITE( ARG2
, sizeof(vki_gid_t
) );
1164 POST_MEM_WRITE( ARG3
, sizeof(vki_gid_t
) );
1168 /* ---------------------------------------------------------------------
1169 miscellaneous wrappers
1170 ------------------------------------------------------------------ */
1177 PRINT("exit_group( %ld )", SARG1
);
1178 PRE_REG_READ1(void, "exit_group", int, status
);
1180 tst
= VG_(get_ThreadState
)(tid
);
1181 /* A little complex; find all the threads with the same threadgroup
1182 as this one (including this one), and mark them to exit */
1183 /* It is unclear how one can get a threadgroup in this process which
1184 is not the threadgroup of the calling thread:
1185 The assignments to threadgroups are:
1186 = 0; /// scheduler.c os_state_clear
1187 = getpid(); /// scheduler.c in child after fork
1188 = getpid(); /// this file, in thread_wrapper
1189 = ptst->os_state.threadgroup; /// syswrap-*-linux.c,
1190 copying the thread group of the thread doing clone
1191 So, the only case where the threadgroup might be different to the getpid
1192 value is in the child, just after fork. But then the fork syscall is
1193 still going on, the forked thread has had no chance yet to make this
1195 for (t
= 1; t
< VG_N_THREADS
; t
++) {
1196 if ( /* not alive */
1197 VG_(threads
)[t
].status
== VgTs_Empty
1200 VG_(threads
)[t
].os_state
.threadgroup
!= tst
->os_state
.threadgroup
1203 /* Assign the exit code, VG_(nuke_all_threads_except) will assign
1205 VG_(threads
)[t
].os_state
.exitcode
= ARG1
;
1208 /* Indicate in all other threads that the process is exiting.
1209 Then wait using VG_(reap_threads) for these threads to disappear.
1211 Can this give a deadlock if another thread is calling exit in parallel
1212 and would then wait for this thread to disappear ?
1214 Other threads are either blocked in a syscall or have yielded the CPU.
1216 A thread that has yielded the CPU is trying to get the big lock in
1217 VG_(scheduler). This thread will get the CPU thanks to the call
1218 to VG_(reap_threads). The scheduler will then check for signals,
1219 kill the process if this is a fatal signal, and otherwise prepare
1220 the thread for handling this signal. After this preparation, if
1221 the thread status is VG_(is_exiting), the scheduler exits the thread.
1222 So, a thread that has yielded the CPU does not have a chance to
1223 call exit => no deadlock for this thread.
1225 VG_(nuke_all_threads_except) will send the VG_SIGVGKILL signal
1226 to all threads blocked in a syscall.
1227 The syscall will be interrupted, and the control will go to the
1228 scheduler. The scheduler will then return, as the thread is in
1231 VG_(nuke_all_threads_except
)( tid
, VgSrc_ExitProcess
);
1232 VG_(reap_threads
)(tid
);
1233 VG_(threads
)[tid
].exitreason
= VgSrc_ExitThread
;
1234 /* we do assign VgSrc_ExitThread and not VgSrc_ExitProcess, as this thread
1235 is the thread calling exit_group and so its registers must be considered
1236 as not reachable. See pub_tool_machine.h VG_(apply_to_GP_regs). */
1238 /* We have to claim the syscall already succeeded. */
1239 SET_STATUS_Success(0);
1244 PRINT("sys_llseek ( %" FMT_REGWORD
"u, 0x%" FMT_REGWORD
"x, 0x%"
1245 FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
1246 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
);
1247 PRE_REG_READ5(long, "llseek",
1248 unsigned int, fd
, unsigned long, offset_high
,
1249 unsigned long, offset_low
, vki_loff_t
*, result
,
1250 unsigned int, whence
);
1251 if (!ML_(fd_allowed
)(ARG1
, "llseek", tid
, False
))
1252 SET_STATUS_Failure( VKI_EBADF
);
1254 PRE_MEM_WRITE( "llseek(result)", ARG4
, sizeof(vki_loff_t
));
1260 POST_MEM_WRITE( ARG4
, sizeof(vki_loff_t
) );
1265 struct vki_timex
*tx
= (struct vki_timex
*)(Addr
)ARG1
;
1266 PRINT("sys_adjtimex ( %#" FMT_REGWORD
"x )", ARG1
);
1267 PRE_REG_READ1(long, "adjtimex", struct timex
*, buf
);
1269 if (ML_(safe_to_deref
) (tx
, sizeof(struct vki_timex
))) {
1270 PRE_MEM_READ( "adjtimex(timex->modes)", ARG1
, sizeof(tx
->modes
));
1272 #define ADJX(bits,field) \
1273 if (tx->modes & (bits)) \
1274 PRE_MEM_READ( "adjtimex(timex->"#field")", \
1275 (Addr)&tx->field, sizeof(tx->field))
1277 if (tx
->modes
& VKI_ADJ_ADJTIME
) {
1278 if (!(tx
->modes
& VKI_ADJ_OFFSET_READONLY
))
1279 PRE_MEM_READ( "adjtimex(timex->offset)", (Addr
)&tx
->offset
, sizeof(tx
->offset
));
1281 ADJX(VKI_ADJ_OFFSET
, offset
);
1282 ADJX(VKI_ADJ_FREQUENCY
, freq
);
1283 ADJX(VKI_ADJ_MAXERROR
, maxerror
);
1284 ADJX(VKI_ADJ_ESTERROR
, esterror
);
1285 ADJX(VKI_ADJ_STATUS
, status
);
1286 ADJX(VKI_ADJ_TIMECONST
|VKI_ADJ_TAI
, constant
);
1287 ADJX(VKI_ADJ_TICK
, tick
);
1292 PRE_MEM_WRITE( "adjtimex(timex)", ARG1
, sizeof(struct vki_timex
));
1297 POST_MEM_WRITE( ARG1
, sizeof(struct vki_timex
) );
1300 PRE(sys_clock_adjtime
)
1302 struct vki_timex
*tx
= (struct vki_timex
*)(Addr
)ARG2
;
1303 PRINT("sys_clock_adjtime ( %ld, %#" FMT_REGWORD
"x )", SARG1
,ARG2
);
1304 PRE_REG_READ2(long, "clock_adjtime", vki_clockid_t
, id
, struct timex
*, buf
);
1305 PRE_MEM_READ( "clock_adjtime(timex->modes)", ARG2
, sizeof(tx
->modes
));
1307 if (ML_(safe_to_deref
) (tx
, sizeof(struct vki_timex
))) {
1308 PRE_MEM_READ( "clock_adjtime(timex->modes)", ARG2
, sizeof(tx
->modes
));
1310 #define ADJX(bits,field) \
1311 if (tx->modes & (bits)) \
1312 PRE_MEM_READ( "clock_adjtime(timex->"#field")", \
1313 (Addr)&tx->field, sizeof(tx->field))
1315 if (tx
->modes
& VKI_ADJ_ADJTIME
) {
1316 if (!(tx
->modes
& VKI_ADJ_OFFSET_READONLY
))
1317 PRE_MEM_READ( "clock_adjtime(timex->offset)", (Addr
)&tx
->offset
, sizeof(tx
->offset
));
1319 ADJX(VKI_ADJ_OFFSET
, offset
);
1320 ADJX(VKI_ADJ_FREQUENCY
, freq
);
1321 ADJX(VKI_ADJ_MAXERROR
, maxerror
);
1322 ADJX(VKI_ADJ_ESTERROR
, esterror
);
1323 ADJX(VKI_ADJ_STATUS
, status
);
1324 ADJX(VKI_ADJ_TIMECONST
|VKI_ADJ_TAI
, constant
);
1325 ADJX(VKI_ADJ_TICK
, tick
);
1330 PRE_MEM_WRITE( "adjtimex(timex)", ARG2
, sizeof(struct vki_timex
));
1333 POST(sys_clock_adjtime
)
1335 POST_MEM_WRITE( ARG2
, sizeof(struct vki_timex
) );
1340 PRINT("sys_ioperm ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %ld )",
1341 ARG1
, ARG2
, SARG3
);
1342 PRE_REG_READ3(long, "ioperm",
1343 unsigned long, from
, unsigned long, num
, int, turn_on
);
1348 *flags
|= SfMayBlock
;
1349 PRINT("sys_syslog (%ld, %#" FMT_REGWORD
"x, %ld)", SARG1
, ARG2
, SARG3
);
1350 PRE_REG_READ3(long, "syslog", int, type
, char *, bufp
, int, len
);
1352 // The kernel uses magic numbers here, rather than named constants,
1353 // therefore so do we.
1354 case 2: case 3: case 4:
1355 PRE_MEM_WRITE( "syslog(bufp)", ARG2
, ARG3
);
1364 case 2: case 3: case 4:
1365 POST_MEM_WRITE( ARG2
, ARG3
);
1374 PRINT("sys_vhangup ( )");
1375 PRE_REG_READ0(long, "vhangup");
1380 PRINT("sys_sysinfo ( %#" FMT_REGWORD
"x )",ARG1
);
1381 PRE_REG_READ1(long, "sysinfo", struct sysinfo
*, info
);
1382 PRE_MEM_WRITE( "sysinfo(info)", ARG1
, sizeof(struct vki_sysinfo
) );
1386 POST_MEM_WRITE( ARG1
, sizeof(struct vki_sysinfo
) );
1389 PRE(sys_personality
)
1391 PRINT("sys_personality ( %llu )", (ULong
)ARG1
);
1392 PRE_REG_READ1(long, "personality", vki_u_long
, persona
);
1397 struct __vki_sysctl_args
*args
;
1398 PRINT("sys_sysctl ( %#" FMT_REGWORD
"x )", ARG1
);
1399 args
= (struct __vki_sysctl_args
*)(Addr
)ARG1
;
1400 PRE_REG_READ1(long, "sysctl", struct __sysctl_args
*, args
);
1401 PRE_MEM_WRITE( "sysctl(args)", ARG1
, sizeof(struct __vki_sysctl_args
) );
1402 if (!VG_(am_is_valid_for_client
)(ARG1
, sizeof(struct __vki_sysctl_args
),
1404 SET_STATUS_Failure( VKI_EFAULT
);
1408 PRE_MEM_READ("sysctl(name)", (Addr
)args
->name
, args
->nlen
* sizeof(*args
->name
));
1409 if (args
->newval
!= NULL
)
1410 PRE_MEM_READ("sysctl(newval)", (Addr
)args
->newval
, args
->newlen
);
1411 if (args
->oldlenp
!= NULL
) {
1412 PRE_MEM_READ("sysctl(oldlenp)", (Addr
)args
->oldlenp
, sizeof(*args
->oldlenp
));
1413 PRE_MEM_WRITE("sysctl(oldval)", (Addr
)args
->oldval
, *args
->oldlenp
);
1418 struct __vki_sysctl_args
*args
;
1419 args
= (struct __vki_sysctl_args
*)(Addr
)ARG1
;
1420 if (args
->oldlenp
!= NULL
) {
1421 POST_MEM_WRITE((Addr
)args
->oldlenp
, sizeof(*args
->oldlenp
));
1422 POST_MEM_WRITE((Addr
)args
->oldval
, 1 + *args
->oldlenp
);
1426 static void pre_asciiz_str(ThreadId tid
, Addr str
, SizeT maxlen
,
1427 const char *attr_name
)
1429 const HChar
*step_str
= (const HChar
*)str
;
1434 * The name can be up to maxlen bytes long, including the terminating null
1435 * byte. So do not check more than maxlen bytes.
1437 if (ML_(safe_to_deref
)((const HChar
*)str
, maxlen
)) {
1438 len
= VG_(strnlen
)((const HChar
*)str
, maxlen
);
1440 PRE_MEM_RASCIIZ(attr_name
, str
);
1442 PRE_MEM_READ(attr_name
, str
, maxlen
);
1445 * Do it the slow way, one byte at a time, while checking for terminating
1448 for (i
= 0; i
< maxlen
; i
++) {
1449 PRE_MEM_READ(attr_name
, (Addr
)&step_str
[i
], 1);
1450 if (!ML_(safe_to_deref
)(&step_str
[i
], 1) || step_str
[i
] == '\0')
1458 *flags
|= SfMayBlock
;
1459 PRINT( "sys_prctl ( %ld, %ld, %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
, SARG4
, SARG5
);
1461 case VKI_PR_SET_PDEATHSIG
:
1462 PRE_REG_READ2(int, "prctl", int, option
, int, signal
);
1464 case VKI_PR_GET_PDEATHSIG
:
1465 PRE_REG_READ2(int, "prctl", int, option
, int *, signal
);
1466 PRE_MEM_WRITE("prctl(get-death-signal)", ARG2
, sizeof(Int
));
1468 case VKI_PR_GET_DUMPABLE
:
1469 PRE_REG_READ1(int, "prctl", int, option
);
1471 case VKI_PR_SET_DUMPABLE
:
1472 PRE_REG_READ2(int, "prctl", int, option
, int, dump
);
1474 case VKI_PR_GET_UNALIGN
:
1475 PRE_REG_READ2(int, "prctl", int, option
, int *, value
);
1476 PRE_MEM_WRITE("prctl(get-unalign)", ARG2
, sizeof(Int
));
1478 case VKI_PR_SET_UNALIGN
:
1479 PRE_REG_READ2(int, "prctl", int, option
, int, value
);
1481 case VKI_PR_GET_KEEPCAPS
:
1482 PRE_REG_READ1(int, "prctl", int, option
);
1484 case VKI_PR_SET_KEEPCAPS
:
1485 PRE_REG_READ2(int, "prctl", int, option
, int, keepcaps
);
1487 case VKI_PR_GET_FPEMU
:
1488 PRE_REG_READ2(int, "prctl", int, option
, int *, value
);
1489 PRE_MEM_WRITE("prctl(get-fpemu)", ARG2
, sizeof(Int
));
1491 case VKI_PR_SET_FPEMU
:
1492 PRE_REG_READ2(int, "prctl", int, option
, int, value
);
1494 case VKI_PR_GET_FPEXC
:
1495 PRE_REG_READ2(int, "prctl", int, option
, int *, value
);
1496 PRE_MEM_WRITE("prctl(get-fpexc)", ARG2
, sizeof(Int
));
1498 case VKI_PR_SET_FPEXC
:
1499 PRE_REG_READ2(int, "prctl", int, option
, int, value
);
1501 case VKI_PR_GET_TIMING
:
1502 PRE_REG_READ1(int, "prctl", int, option
);
1504 case VKI_PR_SET_TIMING
:
1505 PRE_REG_READ2(int, "prctl", int, option
, int, timing
);
1507 case VKI_PR_SET_NAME
:
1508 PRE_REG_READ2(int, "prctl", int, option
, char *, name
);
1509 pre_asciiz_str(tid
, ARG2
, VKI_TASK_COMM_LEN
, "prctl(set-name)");
1511 case VKI_PR_GET_NAME
:
1512 PRE_REG_READ2(int, "prctl", int, option
, char *, name
);
1513 PRE_MEM_WRITE("prctl(get-name)", ARG2
, VKI_TASK_COMM_LEN
);
1515 case VKI_PR_GET_ENDIAN
:
1516 PRE_REG_READ2(int, "prctl", int, option
, int *, value
);
1517 PRE_MEM_WRITE("prctl(get-endian)", ARG2
, sizeof(Int
));
1519 case VKI_PR_SET_ENDIAN
:
1520 PRE_REG_READ2(int, "prctl", int, option
, int, value
);
1522 case VKI_PR_SET_PTRACER
:
1523 PRE_REG_READ2(int, "prctl", int, option
, int, ptracer_process_ID
);
1525 case VKI_PR_SET_SECCOMP
:
1526 /* This is a bit feeble in that it uses |option| before checking
1527 it, but at least both sides of the conditional check it. */
1528 if (ARG2
== VKI_SECCOMP_MODE_FILTER
) {
1529 PRE_REG_READ3(int, "prctl", int, option
, int, mode
, char*, filter
);
1531 /* Should check that ARG3 points at a valid struct sock_fprog.
1532 Sounds complex; hence be lame. */
1533 PRE_MEM_READ( "prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, filter)",
1537 PRE_REG_READ2(int, "prctl", int, option
, int, mode
);
1540 case VKI_PR_CAPBSET_READ
:
1541 PRE_REG_READ2(int, "prctl", int, option
, int, capability
);
1543 case VKI_PR_CAPBSET_DROP
:
1544 PRE_REG_READ2(int, "prctl", int, option
, int, capability
);
1547 PRE_REG_READ5(long, "prctl",
1548 int, option
, unsigned long, arg2
, unsigned long, arg3
,
1549 unsigned long, arg4
, unsigned long, arg5
);
1556 case VKI_PR_GET_PDEATHSIG
:
1557 POST_MEM_WRITE(ARG2
, sizeof(Int
));
1559 case VKI_PR_GET_UNALIGN
:
1560 POST_MEM_WRITE(ARG2
, sizeof(Int
));
1562 case VKI_PR_GET_FPEMU
:
1563 POST_MEM_WRITE(ARG2
, sizeof(Int
));
1565 case VKI_PR_GET_FPEXC
:
1566 POST_MEM_WRITE(ARG2
, sizeof(Int
));
1568 case VKI_PR_GET_NAME
:
1569 POST_MEM_WRITE(ARG2
, VKI_TASK_COMM_LEN
);
1571 case VKI_PR_GET_ENDIAN
:
1572 POST_MEM_WRITE(ARG2
, sizeof(Int
));
1574 case VKI_PR_SET_NAME
:
1576 const HChar
* new_name
= (const HChar
*) (Addr
)ARG2
;
1577 if (new_name
) { // Paranoia
1578 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
1579 SizeT new_len
= VG_(strnlen
)(new_name
, VKI_TASK_COMM_LEN
);
1581 /* Don't bother reusing the memory. This is a rare event. */
1583 VG_(realloc
)("syswrap.prctl", tst
->thread_name
, new_len
+ 1);
1584 VG_(strlcpy
)(tst
->thread_name
, new_name
, new_len
+ 1);
1593 *flags
|= SfMayBlock
;
1594 PRINT("sys_sendfile ( %ld, %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
1595 SARG1
, SARG2
, ARG3
, ARG4
);
1596 PRE_REG_READ4(ssize_t
, "sendfile",
1597 int, out_fd
, int, in_fd
, vki_off_t
*, offset
,
1600 PRE_MEM_WRITE( "sendfile(offset)", ARG3
, sizeof(vki_off_t
) );
1605 POST_MEM_WRITE( ARG3
, sizeof( vki_off_t
) );
1611 *flags
|= SfMayBlock
;
1612 PRINT("sendfile64 ( %ld, %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
1613 SARG1
, SARG2
, ARG3
, ARG4
);
1614 PRE_REG_READ4(ssize_t
, "sendfile64",
1615 int, out_fd
, int, in_fd
, vki_loff_t
*, offset
,
1618 PRE_MEM_WRITE( "sendfile64(offset)", ARG3
, sizeof(vki_loff_t
) );
1620 POST(sys_sendfile64
)
1623 POST_MEM_WRITE( ARG3
, sizeof(vki_loff_t
) );
1627 static void pre_read_timespec64 (ThreadId tid
, const char *msg
, UWord arg
)
1629 struct vki_timespec64
*ts64
= (void *)(Addr
)arg
;
1630 PRE_MEM_READ (msg
, (Addr
) &ts64
->tv_sec
, sizeof(vki_time64_t
));
1631 PRE_MEM_READ (msg
, (Addr
) &ts64
->tv_nsec
, sizeof(vki_int32_t
));
1634 static void pre_read_itimerspec64 (ThreadId tid
, const char *msg
, UWord arg
)
1636 struct vki_itimerspec64
*its64
= (void *)(Addr
)arg
;
1637 pre_read_timespec64 (tid
, msg
, (UWord
) &its64
->it_interval
);
1638 pre_read_timespec64 (tid
, msg
, (UWord
) &its64
->it_value
);
1641 static void futex_pre_helper ( ThreadId tid
, SyscallArgLayout
* layout
,
1642 SyscallArgs
* arrghs
, SyscallStatus
* status
,
1643 UWord
* flags
, Bool is_time64
)
1646 arg param used by ops
1648 ARG1 - u32 *futex all
1650 ARG3 - int val WAIT,WAKE,FD,REQUEUE,CMP_REQUEUE
1651 ARG4 - struct timespec *utime WAIT:time* REQUEUE,CMP_REQUEUE:val2
1652 ARG5 - u32 *uaddr2 REQUEUE,CMP_REQUEUE
1653 ARG6 - int val3 CMP_REQUEUE
1656 switch(ARG2
& ~(VKI_FUTEX_PRIVATE_FLAG
|VKI_FUTEX_CLOCK_REALTIME
)) {
1657 case VKI_FUTEX_CMP_REQUEUE
:
1658 case VKI_FUTEX_WAKE_OP
:
1659 case VKI_FUTEX_CMP_REQUEUE_PI
:
1661 PRE_REG_READ6(long, "futex_time64",
1662 vki_u32
*, futex
, int, op
, int, val
,
1663 struct timespec64
*, utime
, vki_u32
*, uaddr2
, int, val3
);
1665 PRE_REG_READ6(long, "futex",
1666 vki_u32
*, futex
, int, op
, int, val
,
1667 struct timespec
*, utime
, vki_u32
*, uaddr2
, int, val3
);
1670 case VKI_FUTEX_REQUEUE
:
1671 case VKI_FUTEX_WAIT_REQUEUE_PI
:
1673 PRE_REG_READ5(long, "futex_time64",
1674 vki_u32
*, futex
, int, op
, int, val
,
1675 struct timespec64
*, utime
, vki_u32
*, uaddr2
);
1677 PRE_REG_READ5(long, "futex",
1678 vki_u32
*, futex
, int, op
, int, val
,
1679 struct timespec
*, utime
, vki_u32
*, uaddr2
);
1682 case VKI_FUTEX_WAIT_BITSET
:
1683 /* Check that the address at least begins in client-accessible area. */
1684 if (!VG_(am_is_valid_for_client
)( ARG1
, 1, VKI_PROT_READ
)) {
1685 SET_STATUS_Failure( VKI_EFAULT
);
1688 if (*(vki_u32
*)(Addr
)ARG1
!= ARG3
) {
1690 PRE_REG_READ4(long, "futex_time64",
1691 vki_u32
*, futex
, int, op
, int, val
,
1692 struct timespec64
*, utime
);
1694 PRE_REG_READ4(long, "futex",
1695 vki_u32
*, futex
, int, op
, int, val
,
1696 struct timespec64
*, utime
);
1699 /* Note argument 5 is unused, but argument 6 is used.
1700 So we cannot just PRE_REG_READ6. Read argument 6 separately. */
1702 PRE_REG_READ4(long, "futex_time64",
1703 vki_u32
*, futex
, int, op
, int, val
,
1704 struct timespec64
*, utime
);
1706 PRE_REG_READ4(long, "futex",
1707 vki_u32
*, futex
, int, op
, int, val
,
1708 struct timespec
*, utime
);
1710 if (VG_(tdict
).track_pre_reg_read
)
1711 PRA6("futex",int,val3
);
1714 case VKI_FUTEX_WAKE_BITSET
:
1715 PRE_REG_READ3(long, "futex",
1716 vki_u32
*, futex
, int, op
, int, val
);
1717 if (VG_(tdict
).track_pre_reg_read
) {
1718 PRA6("futex", int, val3
);
1721 case VKI_FUTEX_WAIT
:
1722 case VKI_FUTEX_LOCK_PI
:
1724 PRE_REG_READ4(long, "futex_time64",
1725 vki_u32
*, futex
, int, op
, int, val
,
1726 struct timespec64
*, utime
);
1728 PRE_REG_READ4(long, "futex",
1729 vki_u32
*, futex
, int, op
, int, val
,
1730 struct timespec
*, utime
);
1733 case VKI_FUTEX_WAKE
:
1735 PRE_REG_READ3(long, "futex",
1736 vki_u32
*, futex
, int, op
, int, val
);
1738 case VKI_FUTEX_TRYLOCK_PI
:
1739 case VKI_FUTEX_UNLOCK_PI
:
1741 PRE_REG_READ2(long, "futex", vki_u32
*, futex
, int, op
);
1745 *flags
|= SfMayBlock
;
1747 switch(ARG2
& ~(VKI_FUTEX_PRIVATE_FLAG
|VKI_FUTEX_CLOCK_REALTIME
)) {
1748 case VKI_FUTEX_WAIT
:
1749 case VKI_FUTEX_LOCK_PI
:
1750 case VKI_FUTEX_WAIT_BITSET
:
1751 case VKI_FUTEX_WAIT_REQUEUE_PI
:
1752 PRE_MEM_READ( "futex(futex)", ARG1
, sizeof(Int
) );
1755 pre_read_timespec64 (tid
, "futex_time64(timeout)", ARG4
);
1757 PRE_MEM_READ( "futex(timeout)", ARG4
,
1758 sizeof(struct vki_timespec
) );
1763 case VKI_FUTEX_REQUEUE
:
1764 case VKI_FUTEX_CMP_REQUEUE
:
1765 case VKI_FUTEX_CMP_REQUEUE_PI
:
1766 case VKI_FUTEX_WAKE_OP
:
1767 PRE_MEM_READ( "futex(futex)", ARG1
, sizeof(Int
) );
1768 PRE_MEM_READ( "futex(futex2)", ARG5
, sizeof(Int
) );
1772 case VKI_FUTEX_TRYLOCK_PI
:
1773 case VKI_FUTEX_UNLOCK_PI
:
1774 case VKI_FUTEX_WAKE
:
1775 case VKI_FUTEX_WAKE_BITSET
:
1776 PRE_MEM_READ( "futex(futex)", ARG1
, sizeof(Int
) );
1780 SET_STATUS_Failure( VKI_ENOSYS
); // some futex function we don't understand
1785 static void futex_post_helper ( ThreadId tid
, SyscallArgs
* arrghs
,
1786 SyscallStatus
* status
)
1789 POST_MEM_WRITE( ARG1
, sizeof(int) );
1790 if (ARG2
== VKI_FUTEX_FD
) {
1791 if (!ML_(fd_allowed
)(RES
, "futex", tid
, True
)) {
1793 SET_STATUS_Failure( VKI_EMFILE
);
1795 if (VG_(clo_track_fds
))
1796 ML_(record_fd_open_nameless
)(tid
, RES
);
1803 PRINT("sys_futex ( %#" FMT_REGWORD
"x, %ld, %ld, %#" FMT_REGWORD
1804 "x, %#" FMT_REGWORD
"x )", ARG1
, SARG2
, SARG3
, ARG4
, ARG5
);
1805 futex_pre_helper (tid
, layout
, arrghs
, status
, flags
, False
);
1810 futex_post_helper (tid
, arrghs
, status
);
1813 PRE(sys_futex_time64
)
1815 PRINT("sys_futex_time64 ( %#" FMT_REGWORD
"x, %ld, %ld, %#" FMT_REGWORD
1816 "x, %#" FMT_REGWORD
"x )", ARG1
, SARG2
, SARG3
, ARG4
, ARG5
);
1817 futex_pre_helper (tid
, layout
, arrghs
, status
, flags
, True
);
1820 POST(sys_futex_time64
)
1822 futex_post_helper (tid
, arrghs
, status
);
1825 PRE(sys_set_robust_list
)
1827 PRINT("sys_set_robust_list ( %#" FMT_REGWORD
"x, %"
1828 FMT_REGWORD
"u )", ARG1
, ARG2
);
1829 PRE_REG_READ2(long, "set_robust_list",
1830 struct vki_robust_list_head
*, head
, vki_size_t
, len
);
1832 /* Just check the robust_list_head structure is readable - don't
1833 try and chase the list as the kernel will only read it when
1834 the thread exits so the current contents is irrelevant. */
1836 PRE_MEM_READ("set_robust_list(head)", ARG1
, ARG2
);
1839 PRE(sys_get_robust_list
)
1841 PRINT("sys_get_robust_list ( %ld, %#" FMT_REGWORD
"x, %#"
1842 FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
);
1843 PRE_REG_READ3(long, "get_robust_list",
1845 struct vki_robust_list_head
**, head_ptr
,
1846 vki_size_t
*, len_ptr
);
1847 PRE_MEM_WRITE("get_robust_list(head_ptr)",
1848 ARG2
, sizeof(struct vki_robust_list_head
*));
1849 PRE_MEM_WRITE("get_robust_list(len_ptr)",
1850 ARG3
, sizeof(struct vki_size_t
*));
1852 POST(sys_get_robust_list
)
1854 POST_MEM_WRITE(ARG2
, sizeof(struct vki_robust_list_head
*));
1855 POST_MEM_WRITE(ARG3
, sizeof(struct vki_size_t
*));
1858 struct pselect_sized_sigset
{
1859 const vki_sigset_t
*ss
;
1862 struct pselect_adjusted_sigset
{
1863 struct pselect_sized_sigset ss
; /* The actual syscall arg */
1864 vki_sigset_t adjusted_ss
;
1867 static void pselect6_pre_helper ( ThreadId tid
, SyscallArgLayout
* layout
,
1868 SyscallArgs
* arrghs
, SyscallStatus
* status
,
1869 UWord
* flags
, Bool is_time64
)
1871 *flags
|= SfMayBlock
| SfPostOnFail
;
1873 PRE_REG_READ6(long, "pselect6_time64",
1874 int, n
, vki_fd_set
*, readfds
, vki_fd_set
*, writefds
,
1875 vki_fd_set
*, exceptfds
, struct vki_timespec64
*, timeout
,
1878 PRE_REG_READ6(long, "pselect6",
1879 int, n
, vki_fd_set
*, readfds
, vki_fd_set
*, writefds
,
1880 vki_fd_set
*, exceptfds
, struct vki_timespec
*, timeout
,
1883 // XXX: this possibly understates how much memory is read.
1885 PRE_MEM_READ( "pselect6(readfds)",
1886 ARG2
, ARG1
/8 /* __FD_SETSIZE/8 */ );
1888 PRE_MEM_READ( "pselect6(writefds)",
1889 ARG3
, ARG1
/8 /* __FD_SETSIZE/8 */ );
1891 PRE_MEM_READ( "pselect6(exceptfds)",
1892 ARG4
, ARG1
/8 /* __FD_SETSIZE/8 */ );
1895 pre_read_timespec64(tid
, "pselect6_time64(timeout)", ARG5
);
1897 PRE_MEM_READ( "pselect6(timeout)", ARG5
,
1898 sizeof(struct vki_timespec
) );
1902 const struct pselect_sized_sigset
*pss
=
1903 (struct pselect_sized_sigset
*)(Addr
)ARG6
;
1904 PRE_MEM_READ( "pselect6(sig)", ARG6
, sizeof(*pss
) );
1905 if (!ML_(safe_to_deref
)(pss
, sizeof(*pss
))) {
1906 ARG6
= 1; /* Something recognisable to POST() hook. */
1908 struct pselect_adjusted_sigset
*pas
;
1909 pas
= VG_(malloc
)("syswrap.pselect6.1", sizeof(*pas
));
1911 pas
->ss
.ss
= (void *)1;
1912 pas
->ss
.ss_len
= pss
->ss_len
;
1913 if (pss
->ss_len
== sizeof(*pss
->ss
)) {
1914 if (pss
->ss
== NULL
) {
1917 PRE_MEM_READ("pselect6(sig->ss)", (Addr
)pss
->ss
, pss
->ss_len
);
1918 if (ML_(safe_to_deref
)(pss
->ss
, sizeof(*pss
->ss
))) {
1919 pas
->adjusted_ss
= *pss
->ss
;
1920 pas
->ss
.ss
= &pas
->adjusted_ss
;
1921 VG_(sanitize_client_sigmask
)(&pas
->adjusted_ss
);
1931 PRINT("sys_pselect6 ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1932 FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
1933 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
1934 pselect6_pre_helper (tid
, layout
, arrghs
, status
, flags
, False
);
1939 if (ARG6
!= 0 && ARG6
!= 1) {
1940 VG_(free
)((struct pselect_adjusted_sigset
*)(Addr
)ARG6
);
1944 PRE(sys_pselect6_time64
)
1946 PRINT("sys_pselect6_time64 ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1947 FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
1948 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
1949 pselect6_pre_helper (tid
, layout
, arrghs
, status
, flags
, True
);
1952 POST(sys_pselect6_time64
)
1954 if (ARG6
!= 0 && ARG6
!= 1) {
1955 VG_(free
)((struct pselect_adjusted_sigset
*)(Addr
)ARG6
);
1959 static void ppoll_pre_helper ( ThreadId tid
, SyscallArgLayout
* layout
,
1960 SyscallArgs
* arrghs
, SyscallStatus
* status
,
1961 UWord
* flags
, Bool is_time64
)
1964 struct vki_pollfd
* ufds
= (struct vki_pollfd
*)(Addr
)ARG1
;
1965 *flags
|= SfMayBlock
| SfPostOnFail
;
1966 PRINT("sys_ppoll ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#" FMT_REGWORD
1967 "x, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )\n",
1968 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
);
1970 PRE_REG_READ5(long, "ppoll_time64",
1971 struct vki_pollfd
*, ufds
, unsigned int, nfds
,
1972 struct vki_timespec64
*, tsp
, vki_sigset_t
*, sigmask
,
1973 vki_size_t
, sigsetsize
);
1975 PRE_REG_READ5(long, "ppoll",
1976 struct vki_pollfd
*, ufds
, unsigned int, nfds
,
1977 struct vki_timespec
*, tsp
, vki_sigset_t
*, sigmask
,
1978 vki_size_t
, sigsetsize
);
1981 for (i
= 0; i
< ARG2
; i
++) {
1982 PRE_MEM_READ( "ppoll(ufds.fd)",
1983 (Addr
)(&ufds
[i
].fd
), sizeof(ufds
[i
].fd
) );
1984 PRE_MEM_READ( "ppoll(ufds.events)",
1985 (Addr
)(&ufds
[i
].events
), sizeof(ufds
[i
].events
) );
1986 PRE_MEM_WRITE( "ppoll(ufds.revents)",
1987 (Addr
)(&ufds
[i
].revents
), sizeof(ufds
[i
].revents
) );
1992 pre_read_timespec64(tid
, "ppoll_time64(tsp)", ARG3
);
1994 PRE_MEM_READ( "ppoll(tsp)", ARG3
,
1995 sizeof(struct vki_timespec
) );
1998 if (ARG4
!= 0 && sizeof(vki_sigset_t
) == ARG5
) {
1999 const vki_sigset_t
*guest_sigmask
= (vki_sigset_t
*)(Addr
)ARG4
;
2000 PRE_MEM_READ( "ppoll(sigmask)", ARG4
, ARG5
);
2001 if (!ML_(safe_to_deref
)(guest_sigmask
, sizeof(*guest_sigmask
))) {
2002 ARG4
= 1; /* Something recognisable to POST() hook. */
2004 vki_sigset_t
*vg_sigmask
=
2005 VG_(malloc
)("syswrap.ppoll.1", sizeof(*vg_sigmask
));
2006 ARG4
= (Addr
)vg_sigmask
;
2007 *vg_sigmask
= *guest_sigmask
;
2008 VG_(sanitize_client_sigmask
)(vg_sigmask
);
2013 static void ppoll_post_helper ( ThreadId tid
, SyscallArgs
* arrghs
,
2014 SyscallStatus
* status
)
2016 vg_assert(SUCCESS
|| FAILURE
);
2017 if (SUCCESS
&& (RES
>= 0)) {
2019 struct vki_pollfd
* ufds
= (struct vki_pollfd
*)(Addr
)ARG1
;
2020 for (i
= 0; i
< ARG2
; i
++)
2021 POST_MEM_WRITE( (Addr
)(&ufds
[i
].revents
), sizeof(ufds
[i
].revents
) );
2023 if (ARG4
!= 0 && ARG5
== sizeof(vki_sigset_t
) && ARG4
!= 1) {
2024 VG_(free
)((vki_sigset_t
*) (Addr
)ARG4
);
2030 PRINT("sys_ppoll ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#" FMT_REGWORD
2031 "x, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )\n",
2032 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
);
2033 ppoll_pre_helper (tid
, layout
, arrghs
, status
, flags
, False
);
2038 ppoll_post_helper (tid
, arrghs
, status
);
2041 PRE(sys_ppoll_time64
)
2043 PRINT("sys_ppoll_time64 ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
2044 "u, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )\n",
2045 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
);
2046 ppoll_pre_helper (tid
, layout
, arrghs
, status
, flags
, False
);
2049 POST(sys_ppoll_time64
)
2051 ppoll_post_helper (tid
, arrghs
, status
);
2055 /* ---------------------------------------------------------------------
2057 ------------------------------------------------------------------ */
2059 PRE(sys_epoll_create
)
2061 PRINT("sys_epoll_create ( %ld )", SARG1
);
2062 PRE_REG_READ1(long, "epoll_create", int, size
);
2064 POST(sys_epoll_create
)
2067 if (!ML_(fd_allowed
)(RES
, "epoll_create", tid
, True
)) {
2069 SET_STATUS_Failure( VKI_EMFILE
);
2071 if (VG_(clo_track_fds
))
2072 ML_(record_fd_open_nameless
) (tid
, RES
);
2076 PRE(sys_epoll_create1
)
2078 PRINT("sys_epoll_create1 ( %ld )", SARG1
);
2079 PRE_REG_READ1(long, "epoll_create1", int, flags
);
2081 POST(sys_epoll_create1
)
2084 if (!ML_(fd_allowed
)(RES
, "epoll_create1", tid
, True
)) {
2086 SET_STATUS_Failure( VKI_EMFILE
);
2088 if (VG_(clo_track_fds
))
2089 ML_(record_fd_open_nameless
) (tid
, RES
);
2095 static const HChar
* epoll_ctl_s
[3] = {
2100 PRINT("sys_epoll_ctl ( %ld, %s, %ld, %#" FMT_REGWORD
"x )",
2101 SARG1
, ( ARG2
<3 ? epoll_ctl_s
[ARG2
] : "?" ), SARG3
, ARG4
);
2102 PRE_REG_READ4(long, "epoll_ctl",
2103 int, epfd
, int, op
, int, fd
, struct vki_epoll_event
*, event
);
2104 if (ARG2
!= VKI_EPOLL_CTL_DEL
) {
2105 /* Just check the events field, the data field is for user space and
2106 unused by the kernel. */
2107 struct vki_epoll_event
*event
= (struct vki_epoll_event
*) ARG4
;
2108 PRE_MEM_READ( "epoll_ctl(event)", (Addr
) &event
->events
,
2109 sizeof(__vki_u32
) );
2113 /* RES event records have been written (exclude padding). */
2114 static void epoll_post_helper ( ThreadId tid
, SyscallArgs
* arrghs
,
2115 SyscallStatus
* status
)
2120 struct vki_epoll_event
*events
= (struct vki_epoll_event
*)(Addr
)ARG2
;
2121 for (i
= 0; i
< RES
; i
++) {
2122 /* Assume both events and data are set (data is user space only). */
2123 POST_FIELD_WRITE(events
[i
].events
);
2124 POST_FIELD_WRITE(events
[i
].data
);
2131 *flags
|= SfMayBlock
;
2132 PRINT("sys_epoll_wait ( %ld, %#" FMT_REGWORD
"x, %ld, %ld )",
2133 SARG1
, ARG2
, SARG3
, SARG4
);
2134 PRE_REG_READ4(long, "epoll_wait",
2135 int, epfd
, struct vki_epoll_event
*, events
,
2136 int, maxevents
, int, timeout
);
2137 /* Assume all (maxevents) events records should be (fully) writable. */
2138 PRE_MEM_WRITE( "epoll_wait(events)", ARG2
, sizeof(struct vki_epoll_event
)*ARG3
);
2140 POST(sys_epoll_wait
)
2142 epoll_post_helper (tid
, arrghs
, status
);
2145 PRE(sys_epoll_pwait
)
2147 *flags
|= SfMayBlock
;
2148 PRINT("sys_epoll_pwait ( %ld, %#" FMT_REGWORD
"x, %ld, %ld, %#"
2149 FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
2150 SARG1
, ARG2
, SARG3
, SARG4
, ARG5
, ARG6
);
2151 PRE_REG_READ6(long, "epoll_pwait",
2152 int, epfd
, struct vki_epoll_event
*, events
,
2153 int, maxevents
, int, timeout
, vki_sigset_t
*, sigmask
,
2154 vki_size_t
, sigsetsize
);
2155 /* Assume all (maxevents) events records should be (fully) writable. */
2156 PRE_MEM_WRITE( "epoll_pwait(events)", ARG2
, sizeof(struct vki_epoll_event
)*ARG3
);
2158 PRE_MEM_READ( "epoll_pwait(sigmask)", ARG5
, sizeof(vki_sigset_t
) );
2160 POST(sys_epoll_pwait
)
2162 epoll_post_helper (tid
, arrghs
, status
);
2167 PRINT("sys_eventfd ( %" FMT_REGWORD
"u )", ARG1
);
2168 PRE_REG_READ1(long, "sys_eventfd", unsigned int, count
);
2172 if (!ML_(fd_allowed
)(RES
, "eventfd", tid
, True
)) {
2174 SET_STATUS_Failure( VKI_EMFILE
);
2176 if (VG_(clo_track_fds
))
2177 ML_(record_fd_open_nameless
) (tid
, RES
);
2183 PRINT("sys_eventfd2 ( %" FMT_REGWORD
"u, %ld )", ARG1
, SARG2
);
2184 PRE_REG_READ2(long, "sys_eventfd2", unsigned int, count
, int, flags
);
2188 if (!ML_(fd_allowed
)(RES
, "eventfd2", tid
, True
)) {
2190 SET_STATUS_Failure( VKI_EMFILE
);
2192 if (VG_(clo_track_fds
))
2193 ML_(record_fd_open_nameless
) (tid
, RES
);
2199 *flags
|= SfMayBlock
;
2200 #if VG_WORDSIZE == 4
2201 PRINT("sys_fallocate ( %ld, %ld, %lld, %lld )",
2202 SARG1
, SARG2
, (Long
)MERGE64(ARG3
,ARG4
), (Long
)MERGE64(ARG5
,ARG6
));
2203 PRE_REG_READ6(long, "fallocate",
2205 unsigned, MERGE64_FIRST(offset
), unsigned, MERGE64_SECOND(offset
),
2206 unsigned, MERGE64_FIRST(len
), unsigned, MERGE64_SECOND(len
));
2207 #elif VG_WORDSIZE == 8
2208 PRINT("sys_fallocate ( %ld, %ld, %ld, %ld )",
2209 SARG1
, SARG2
, SARG3
, SARG4
);
2210 PRE_REG_READ4(long, "fallocate",
2211 int, fd
, int, mode
, vki_loff_t
, offset
, vki_loff_t
, len
);
2213 # error Unexpected word size
2215 if (!ML_(fd_allowed
)(ARG1
, "fallocate", tid
, False
))
2216 SET_STATUS_Failure( VKI_EBADF
);
2221 PRINT("sys_prlimit64 ( %ld, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %#"
2222 FMT_REGWORD
"x )", SARG1
,ARG2
,ARG3
,ARG4
);
2223 PRE_REG_READ4(long, "prlimit64",
2224 vki_pid_t
, pid
, unsigned int, resource
,
2225 const struct rlimit64
*, new_rlim
,
2226 struct rlimit64
*, old_rlim
);
2228 PRE_MEM_READ( "rlimit64(new_rlim)", ARG3
, sizeof(struct vki_rlimit64
) );
2230 PRE_MEM_WRITE( "rlimit64(old_rlim)", ARG4
, sizeof(struct vki_rlimit64
) );
2233 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
2234 > ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
) {
2235 SET_STATUS_Failure( VKI_EINVAL
);
2237 else if (ARG1
== 0 || ARG1
== VG_(getpid
)()) {
2239 case VKI_RLIMIT_NOFILE
:
2240 SET_STATUS_Success( 0 );
2242 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_cur
= VG_(fd_soft_limit
);
2243 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_max
= VG_(fd_hard_limit
);
2246 if (((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
2247 > VG_(fd_hard_limit
) ||
2248 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
2249 != VG_(fd_hard_limit
)) {
2250 SET_STATUS_Failure( VKI_EPERM
);
2253 VG_(fd_soft_limit
) =
2254 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
;
2259 case VKI_RLIMIT_DATA
:
2260 SET_STATUS_Success( 0 );
2262 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_cur
=
2263 VG_(client_rlimit_data
).rlim_cur
;
2264 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_max
=
2265 VG_(client_rlimit_data
).rlim_max
;
2268 if (((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
2269 > VG_(client_rlimit_data
).rlim_max
||
2270 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
2271 > VG_(client_rlimit_data
).rlim_max
) {
2272 SET_STATUS_Failure( VKI_EPERM
);
2275 VG_(client_rlimit_data
).rlim_cur
=
2276 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
;
2277 VG_(client_rlimit_data
).rlim_max
=
2278 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
;
2283 case VKI_RLIMIT_STACK
:
2284 SET_STATUS_Success( 0 );
2286 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_cur
=
2287 VG_(client_rlimit_stack
).rlim_cur
;
2288 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_max
=
2289 VG_(client_rlimit_stack
).rlim_max
;
2292 if (((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
2293 > VG_(client_rlimit_stack
).rlim_max
||
2294 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
2295 > VG_(client_rlimit_stack
).rlim_max
) {
2296 SET_STATUS_Failure( VKI_EPERM
);
2299 VG_(threads
)[tid
].client_stack_szB
=
2300 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
;
2301 VG_(client_rlimit_stack
).rlim_cur
=
2302 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
;
2303 VG_(client_rlimit_stack
).rlim_max
=
2304 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
;
2315 POST_MEM_WRITE( ARG4
, sizeof(struct vki_rlimit64
) );
2318 /* ---------------------------------------------------------------------
2319 tid-related wrappers
2320 ------------------------------------------------------------------ */
2324 PRINT("sys_gettid ()");
2325 PRE_REG_READ0(long, "gettid");
2328 PRE(sys_set_tid_address
)
2330 PRINT("sys_set_tid_address ( %#" FMT_REGWORD
"x )", ARG1
);
2331 PRE_REG_READ1(long, "set_tid_address", int *, tidptr
);
2336 PRINT("sys_tkill ( %ld, %ld )", SARG1
, SARG2
);
2337 PRE_REG_READ2(long, "tkill", int, tid
, int, sig
);
2338 if (!ML_(client_signal_OK
)(ARG2
)) {
2339 SET_STATUS_Failure( VKI_EINVAL
);
2343 /* Check to see if this kill gave us a pending signal */
2344 *flags
|= SfPollAfter
;
2346 if (VG_(clo_trace_signals
))
2347 VG_(message
)(Vg_DebugMsg
, "tkill: sending signal %ld to pid %ld\n",
2350 /* If we're sending SIGKILL, check to see if the target is one of
2351 our threads and handle it specially. */
2352 if (ARG2
== VKI_SIGKILL
&& ML_(do_sigkill
)(ARG1
, -1)) {
2353 SET_STATUS_Success(0);
2357 /* Ask to handle this syscall via the slow route, since that's the
2358 only one that sets tst->status to VgTs_WaitSys. If the result
2359 of doing the syscall is an immediate run of
2360 async_signalhandler() in m_signals, then we need the thread to
2361 be properly tidied away. I have the impression the previous
2362 version of this wrapper worked on x86/amd64 only because the
2363 kernel did not immediately deliver the async signal to this
2364 thread (on ppc it did, which broke the assertion re tst->status
2365 at the top of async_signalhandler()). */
2366 *flags
|= SfMayBlock
;
2370 if (VG_(clo_trace_signals
))
2371 VG_(message
)(Vg_DebugMsg
, "tkill: sent signal %ld to pid %ld\n",
2377 PRINT("sys_tgkill ( %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
);
2378 PRE_REG_READ3(long, "tgkill", int, tgid
, int, tid
, int, sig
);
2379 if (!ML_(client_signal_OK
)(ARG3
)) {
2380 SET_STATUS_Failure( VKI_EINVAL
);
2384 /* Check to see if this kill gave us a pending signal */
2385 *flags
|= SfPollAfter
;
2387 if (VG_(clo_trace_signals
))
2388 VG_(message
)(Vg_DebugMsg
,
2389 "tgkill: sending signal %ld to pid %ld/%ld\n",
2390 SARG3
, SARG1
, SARG2
);
2392 /* If we're sending SIGKILL, check to see if the target is one of
2393 our threads and handle it specially. */
2394 if (ARG3
== VKI_SIGKILL
&& ML_(do_sigkill
)(ARG2
, ARG1
)) {
2395 SET_STATUS_Success(0);
2399 /* Ask to handle this syscall via the slow route, since that's the
2400 only one that sets tst->status to VgTs_WaitSys. If the result
2401 of doing the syscall is an immediate run of
2402 async_signalhandler() in m_signals, then we need the thread to
2403 be properly tidied away. I have the impression the previous
2404 version of this wrapper worked on x86/amd64 only because the
2405 kernel did not immediately deliver the async signal to this
2406 thread (on ppc it did, which broke the assertion re tst->status
2407 at the top of async_signalhandler()). */
2408 *flags
|= SfMayBlock
;
2412 if (VG_(clo_trace_signals
))
2413 VG_(message
)(Vg_DebugMsg
,
2414 "tgkill: sent signal %ld to pid %ld/%ld\n",
2415 SARG3
, SARG1
, SARG2
);
2418 /* ---------------------------------------------------------------------
2420 ------------------------------------------------------------------ */
2424 PRINT("sys_fadvise64 ( %ld, %llu, %" FMT_REGWORD
"u, %ld )",
2425 SARG1
, MERGE64(ARG2
,ARG3
), ARG4
, SARG5
);
2426 PRE_REG_READ5(long, "fadvise64",
2427 int, fd
, vki_u32
, MERGE64_FIRST(offset
), vki_u32
, MERGE64_SECOND(offset
),
2428 vki_size_t
, len
, int, advice
);
2431 PRE(sys_fadvise64_64
)
2433 PRINT("sys_fadvise64_64 ( %ld, %llu, %llu, %ld )",
2434 SARG1
, MERGE64(ARG2
,ARG3
), MERGE64(ARG4
,ARG5
), SARG6
);
2435 PRE_REG_READ6(long, "fadvise64_64",
2436 int, fd
, vki_u32
, MERGE64_FIRST(offset
), vki_u32
, MERGE64_SECOND(offset
),
2437 vki_u32
, MERGE64_FIRST(len
), vki_u32
, MERGE64_SECOND(len
), int, advice
);
2440 /* ---------------------------------------------------------------------
2442 ------------------------------------------------------------------ */
2444 // Nb: this wrapper has to pad/unpad memory around the syscall itself,
2445 // and this allows us to control exactly the code that gets run while
2446 // the padding is in place.
2450 PRINT("sys_io_setup ( %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )", ARG1
,ARG2
);
2451 PRE_REG_READ2(long, "io_setup",
2452 unsigned, nr_events
, vki_aio_context_t
*, ctxp
);
2453 PRE_MEM_WRITE( "io_setup(ctxp)", ARG2
, sizeof(vki_aio_context_t
) );
2459 struct vki_aio_ring
*r
;
2461 size
= VG_PGROUNDUP(sizeof(struct vki_aio_ring
) +
2462 ARG1
*sizeof(struct vki_io_event
));
2463 r
= *(struct vki_aio_ring
**)(Addr
)ARG2
;
2464 vg_assert(ML_(valid_client_addr
)((Addr
)r
, size
, tid
, "io_setup"));
2466 ML_(notify_core_and_tool_of_mmap
)( (Addr
)r
, size
,
2467 VKI_PROT_READ
| VKI_PROT_WRITE
,
2468 VKI_MAP_ANONYMOUS
, -1, 0 );
2470 POST_MEM_WRITE( ARG2
, sizeof(vki_aio_context_t
) );
2473 // Nb: This wrapper is "Special" because we need 'size' to do the unmap
2474 // after the syscall. We must get 'size' from the aio_ring structure,
2475 // before the syscall, while the aio_ring structure still exists. (And we
2476 // know that we must look at the aio_ring structure because Tom inspected the
2477 // kernel and glibc sources to see what they do, yuk.)
2479 // XXX This segment can be implicitly unmapped when aio
2480 // file-descriptors are closed...
2485 PRINT("sys_io_destroy ( %llu )", (ULong
)ARG1
);
2486 PRE_REG_READ1(long, "io_destroy", vki_aio_context_t
, ctx
);
2488 // If we are going to seg fault (due to a bogus ARG1) do it as late as
2490 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG1
, sizeof(struct vki_aio_ring
))) {
2491 struct vki_aio_ring
*r
= (struct vki_aio_ring
*)(Addr
)ARG1
;
2492 size
= VG_PGROUNDUP(sizeof(struct vki_aio_ring
) +
2493 r
->nr
*sizeof(struct vki_io_event
));
2496 SET_STATUS_from_SysRes( VG_(do_syscall1
)(SYSNO
, ARG1
) );
2498 if (SUCCESS
&& RES
== 0) {
2499 Bool d
= VG_(am_notify_munmap
)( ARG1
, size
);
2500 VG_TRACK( die_mem_munmap
, ARG1
, size
);
2502 VG_(discard_translations
)( (Addr
)ARG1
, (ULong
)size
,
2503 "PRE(sys_io_destroy)" );
2507 PRE(sys_io_getevents
)
2509 *flags
|= SfMayBlock
;
2510 PRINT("sys_io_getevents ( %llu, %lld, %lld, %#" FMT_REGWORD
"x, %#"
2512 (ULong
)ARG1
,(Long
)ARG2
,(Long
)ARG3
,ARG4
,ARG5
);
2513 PRE_REG_READ5(long, "io_getevents",
2514 vki_aio_context_t
, ctx_id
, long, min_nr
, long, nr
,
2515 struct io_event
*, events
,
2516 struct timespec
*, timeout
);
2518 PRE_MEM_WRITE( "io_getevents(events)",
2519 ARG4
, sizeof(struct vki_io_event
)*ARG3
);
2521 PRE_MEM_READ( "io_getevents(timeout)",
2522 ARG5
, sizeof(struct vki_timespec
));
2524 POST(sys_io_getevents
)
2529 POST_MEM_WRITE( ARG4
, sizeof(struct vki_io_event
)*RES
);
2530 for (i
= 0; i
< RES
; i
++) {
2531 const struct vki_io_event
*vev
=
2532 ((struct vki_io_event
*)(Addr
)ARG4
) + i
;
2533 const struct vki_iocb
*cb
= (struct vki_iocb
*)(Addr
)vev
->obj
;
2535 switch (cb
->aio_lio_opcode
) {
2536 case VKI_IOCB_CMD_PREAD
:
2537 if (vev
->result
> 0)
2538 POST_MEM_WRITE( cb
->aio_buf
, vev
->result
);
2541 case VKI_IOCB_CMD_PWRITE
:
2544 case VKI_IOCB_CMD_FSYNC
:
2547 case VKI_IOCB_CMD_FDSYNC
:
2550 case VKI_IOCB_CMD_PREADV
:
2551 if (vev
->result
> 0) {
2552 struct vki_iovec
* vec
= (struct vki_iovec
*)(Addr
)cb
->aio_buf
;
2553 Int remains
= vev
->result
;
2556 for (j
= 0; j
< cb
->aio_nbytes
; j
++) {
2557 Int nReadThisBuf
= vec
[j
].iov_len
;
2558 if (nReadThisBuf
> remains
) nReadThisBuf
= remains
;
2559 POST_MEM_WRITE( (Addr
)vec
[j
].iov_base
, nReadThisBuf
);
2560 remains
-= nReadThisBuf
;
2561 if (remains
< 0) VG_(core_panic
)("io_getevents(PREADV): remains < 0");
2566 case VKI_IOCB_CMD_PWRITEV
:
2570 VG_(message
)(Vg_DebugMsg
,
2571 "Warning: unhandled io_getevents opcode: %u\n",
2572 cb
->aio_lio_opcode
);
2583 PRINT("sys_io_submit ( %" FMT_REGWORD
"u, %ld, %#" FMT_REGWORD
"x )",
2585 PRE_REG_READ3(long, "io_submit",
2586 vki_aio_context_t
, ctx_id
, long, nr
,
2587 struct iocb
**, iocbpp
);
2588 PRE_MEM_READ( "io_submit(iocbpp)", ARG3
, ARG2
*sizeof(struct vki_iocb
*) );
2590 for (i
= 0; i
< ARG2
; i
++) {
2591 struct vki_iocb
*cb
= ((struct vki_iocb
**)(Addr
)ARG3
)[i
];
2592 struct vki_iovec
*iov
;
2594 PRE_MEM_READ( "io_submit(iocb)", (Addr
)cb
, sizeof(struct vki_iocb
) );
2595 switch (cb
->aio_lio_opcode
) {
2596 case VKI_IOCB_CMD_PREAD
:
2597 PRE_MEM_WRITE( "io_submit(PREAD)", cb
->aio_buf
, cb
->aio_nbytes
);
2600 case VKI_IOCB_CMD_PWRITE
:
2601 PRE_MEM_READ( "io_submit(PWRITE)", cb
->aio_buf
, cb
->aio_nbytes
);
2604 case VKI_IOCB_CMD_FSYNC
:
2607 case VKI_IOCB_CMD_FDSYNC
:
2610 case VKI_IOCB_CMD_PREADV
:
2611 iov
= (struct vki_iovec
*)(Addr
)cb
->aio_buf
;
2612 PRE_MEM_READ( "io_submit(PREADV)", cb
->aio_buf
, cb
->aio_nbytes
* sizeof(struct vki_iovec
) );
2613 for (j
= 0; j
< cb
->aio_nbytes
; j
++)
2614 PRE_MEM_WRITE( "io_submit(PREADV(iov[i]))", (Addr
)iov
[j
].iov_base
, iov
[j
].iov_len
);
2617 case VKI_IOCB_CMD_PWRITEV
:
2618 iov
= (struct vki_iovec
*)(Addr
)cb
->aio_buf
;
2619 PRE_MEM_READ( "io_submit(PWRITEV)", cb
->aio_buf
, cb
->aio_nbytes
* sizeof(struct vki_iovec
) );
2620 for (j
= 0; j
< cb
->aio_nbytes
; j
++)
2621 PRE_MEM_READ( "io_submit(PWRITEV(iov[i]))", (Addr
)iov
[j
].iov_base
, iov
[j
].iov_len
);
2625 VG_(message
)(Vg_DebugMsg
,"Warning: unhandled io_submit opcode: %u\n",
2626 cb
->aio_lio_opcode
);
2635 PRINT("sys_io_cancel ( %llu, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
2636 (ULong
)ARG1
, ARG2
, ARG3
);
2637 PRE_REG_READ3(long, "io_cancel",
2638 vki_aio_context_t
, ctx_id
, struct iocb
*, iocb
,
2639 struct io_event
*, result
);
2640 PRE_MEM_READ( "io_cancel(iocb)", ARG2
, sizeof(struct vki_iocb
) );
2641 PRE_MEM_WRITE( "io_cancel(result)", ARG3
, sizeof(struct vki_io_event
) );
2645 POST_MEM_WRITE( ARG3
, sizeof(struct vki_io_event
) );
2648 /* ---------------------------------------------------------------------
2649 *_mempolicy wrappers
2650 ------------------------------------------------------------------ */
2654 PRINT("sys_mbind ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %" FMT_REGWORD
2655 "u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )",
2656 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
2657 PRE_REG_READ6(long, "mbind",
2658 unsigned long, start
, unsigned long, len
,
2659 unsigned long, policy
, unsigned long *, nodemask
,
2660 unsigned long, maxnode
, unsigned, flags
);
2662 PRE_MEM_READ( "mbind(nodemask)", ARG4
,
2663 VG_ROUNDUP( ARG5
-1, sizeof(UWord
) * 8 ) / 8 );
2666 PRE(sys_set_mempolicy
)
2668 PRINT("sys_set_mempolicy ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
2670 PRE_REG_READ3(long, "set_mempolicy",
2671 int, policy
, unsigned long *, nodemask
,
2672 unsigned long, maxnode
);
2673 PRE_MEM_READ( "set_mempolicy(nodemask)", ARG2
,
2674 VG_ROUNDUP( ARG3
-1, sizeof(UWord
) * 8 ) / 8 );
2677 PRE(sys_get_mempolicy
)
2679 PRINT("sys_get_mempolicy ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %"
2680 FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"x )",
2681 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
);
2682 PRE_REG_READ5(long, "get_mempolicy",
2683 int *, policy
, unsigned long *, nodemask
,
2684 unsigned long, maxnode
, unsigned long, addr
,
2685 unsigned long, flags
);
2687 PRE_MEM_WRITE( "get_mempolicy(policy)", ARG1
, sizeof(Int
) );
2689 PRE_MEM_WRITE( "get_mempolicy(nodemask)", ARG2
,
2690 VG_ROUNDUP( ARG3
-1, sizeof(UWord
) * 8 ) / 8 );
2692 POST(sys_get_mempolicy
)
2695 POST_MEM_WRITE( ARG1
, sizeof(Int
) );
2697 POST_MEM_WRITE( ARG2
, VG_ROUNDUP( ARG3
-1, sizeof(UWord
) * 8 ) / 8 );
2700 /* ---------------------------------------------------------------------
2702 ------------------------------------------------------------------ */
2704 PRE(sys_fanotify_init
)
2706 PRINT("sys_fanotify_init ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )",
2708 PRE_REG_READ2(long, "fanotify_init",
2709 unsigned int, flags
, unsigned int, event_f_flags
);
2712 POST(sys_fanotify_init
)
2715 if (!ML_(fd_allowed
)(RES
, "fanotify_init", tid
, True
)) {
2717 SET_STATUS_Failure( VKI_EMFILE
);
2719 if (VG_(clo_track_fds
))
2720 ML_(record_fd_open_nameless
) (tid
, RES
);
2724 PRE(sys_fanotify_mark
)
2726 #if VG_WORDSIZE == 4
2727 PRINT( "sys_fanotify_mark ( %ld, %" FMT_REGWORD
"u, %llu, %ld, %#"
2728 FMT_REGWORD
"x(%s))", SARG1
, ARG2
, MERGE64(ARG3
,ARG4
), SARG5
, ARG6
,
2729 (HChar
*)(Addr
)ARG6
);
2730 PRE_REG_READ6(long, "sys_fanotify_mark",
2731 int, fanotify_fd
, unsigned int, flags
,
2732 __vki_u32
, mask0
, __vki_u32
, mask1
,
2733 int, dfd
, const char *, pathname
);
2735 PRE_MEM_RASCIIZ( "fanotify_mark(path)", ARG6
);
2736 #elif VG_WORDSIZE == 8
2737 PRINT( "sys_fanotify_mark ( %ld, %lu, %lu, %ld, %#lx(%s))",
2738 SARG1
, ARG2
, ARG3
, SARG4
, ARG5
, (HChar
*)(Addr
)ARG5
);
2739 PRE_REG_READ5(long, "sys_fanotify_mark",
2740 int, fanotify_fd
, unsigned int, flags
,
2742 int, dfd
, const char *, pathname
);
2744 PRE_MEM_RASCIIZ( "fanotify_mark(path)", ARG5
);
2746 # error Unexpected word size
2750 /* ---------------------------------------------------------------------
2752 ------------------------------------------------------------------ */
2754 PRE(sys_inotify_init
)
2756 PRINT("sys_inotify_init ( )");
2757 PRE_REG_READ0(long, "inotify_init");
2759 POST(sys_inotify_init
)
2762 if (!ML_(fd_allowed
)(RES
, "inotify_init", tid
, True
)) {
2764 SET_STATUS_Failure( VKI_EMFILE
);
2766 if (VG_(clo_track_fds
))
2767 ML_(record_fd_open_nameless
) (tid
, RES
);
2771 PRE(sys_inotify_init1
)
2773 PRINT("sys_inotify_init ( %ld )", SARG1
);
2774 PRE_REG_READ1(long, "inotify_init", int, flag
);
2777 POST(sys_inotify_init1
)
2780 if (!ML_(fd_allowed
)(RES
, "inotify_init", tid
, True
)) {
2782 SET_STATUS_Failure( VKI_EMFILE
);
2784 if (VG_(clo_track_fds
))
2785 ML_(record_fd_open_nameless
) (tid
, RES
);
2789 PRE(sys_inotify_add_watch
)
2791 PRINT( "sys_inotify_add_watch ( %ld, %#" FMT_REGWORD
"x, %"
2792 FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
);
2793 PRE_REG_READ3(long, "inotify_add_watch", int, fd
, char *, path
, int, mask
);
2794 PRE_MEM_RASCIIZ( "inotify_add_watch(path)", ARG2
);
2797 PRE(sys_inotify_rm_watch
)
2799 PRINT( "sys_inotify_rm_watch ( %ld, %" FMT_REGWORD
"x )", SARG1
, ARG2
);
2800 PRE_REG_READ2(long, "inotify_rm_watch", int, fd
, int, wd
);
2803 /* ---------------------------------------------------------------------
2805 ------------------------------------------------------------------ */
2809 PRINT("sys_mq_open( %#" FMT_REGWORD
"x(%s), %ld, %" FMT_REGWORD
"u, %#"
2810 FMT_REGWORD
"x )", ARG1
, (HChar
*)(Addr
)ARG1
, SARG2
, ARG3
, ARG4
);
2811 PRE_REG_READ4(long, "mq_open",
2812 const char *, name
, int, oflag
, vki_mode_t
, mode
,
2813 struct mq_attr
*, attr
);
2814 PRE_MEM_RASCIIZ( "mq_open(name)", ARG1
);
2815 if ((ARG2
& VKI_O_CREAT
) != 0 && ARG4
!= 0) {
2816 const struct vki_mq_attr
*attr
= (struct vki_mq_attr
*)(Addr
)ARG4
;
2817 PRE_MEM_READ( "mq_open(attr->mq_maxmsg)",
2818 (Addr
)&attr
->mq_maxmsg
, sizeof(attr
->mq_maxmsg
) );
2819 PRE_MEM_READ( "mq_open(attr->mq_msgsize)",
2820 (Addr
)&attr
->mq_msgsize
, sizeof(attr
->mq_msgsize
) );
2826 if (!ML_(fd_allowed
)(RES
, "mq_open", tid
, True
)) {
2828 SET_STATUS_Failure( VKI_EMFILE
);
2830 if (VG_(clo_track_fds
))
2831 ML_(record_fd_open_with_given_name
)(tid
, RES
, (HChar
*)(Addr
)ARG1
);
2837 PRINT("sys_mq_unlink ( %#" FMT_REGWORD
"x(%s) )", ARG1
,(char*)(Addr
)ARG1
);
2838 PRE_REG_READ1(long, "mq_unlink", const char *, name
);
2839 PRE_MEM_RASCIIZ( "mq_unlink(name)", ARG1
);
2842 PRE(sys_mq_timedsend
)
2844 *flags
|= SfMayBlock
;
2845 PRINT("sys_mq_timedsend ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
2846 FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
2847 SARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
2848 PRE_REG_READ5(long, "mq_timedsend",
2849 vki_mqd_t
, mqdes
, const char *, msg_ptr
, vki_size_t
, msg_len
,
2850 unsigned int, msg_prio
, const struct timespec
*, abs_timeout
);
2851 if (!ML_(fd_allowed
)(ARG1
, "mq_timedsend", tid
, False
)) {
2852 SET_STATUS_Failure( VKI_EBADF
);
2854 PRE_MEM_READ( "mq_timedsend(msg_ptr)", ARG2
, ARG3
);
2856 PRE_MEM_READ( "mq_timedsend(abs_timeout)", ARG5
,
2857 sizeof(struct vki_timespec
) );
2861 PRE(sys_mq_timedsend_time64
)
2863 *flags
|= SfMayBlock
;
2864 PRINT("sys_mq_timedsend_time64 ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
2865 "u, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
2866 SARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
2867 PRE_REG_READ5(long, "mq_timedsend_time64",
2868 vki_mqd_t
, mqdes
, const char *, msg_ptr
, vki_size_t
, msg_len
,
2869 unsigned int, msg_prio
,
2870 const struct vki_timespec64
*, abs_timeout
);
2871 if (!ML_(fd_allowed
)(ARG1
, "mq_timedsend_time64", tid
, False
)) {
2872 SET_STATUS_Failure( VKI_EBADF
);
2874 PRE_MEM_READ( "mq_timedsend_time64(msg_ptr)", ARG2
, ARG3
);
2876 pre_read_timespec64(tid
, "mq_timedsend_time64(abs_timeout)", ARG5
);
2880 PRE(sys_mq_timedreceive
)
2882 *flags
|= SfMayBlock
;
2883 PRINT("sys_mq_timedreceive( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#"
2884 FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
2885 SARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
2886 PRE_REG_READ5(ssize_t
, "mq_timedreceive",
2887 vki_mqd_t
, mqdes
, char *, msg_ptr
, vki_size_t
, msg_len
,
2888 unsigned int *, msg_prio
,
2889 const struct timespec
*, abs_timeout
);
2890 if (!ML_(fd_allowed
)(ARG1
, "mq_timedreceive", tid
, False
)) {
2891 SET_STATUS_Failure( VKI_EBADF
);
2893 PRE_MEM_WRITE( "mq_timedreceive(msg_ptr)", ARG2
, ARG3
);
2895 PRE_MEM_WRITE( "mq_timedreceive(msg_prio)",
2896 ARG4
, sizeof(unsigned int) );
2898 PRE_MEM_READ( "mq_timedreceive(abs_timeout)",
2899 ARG5
, sizeof(struct vki_timespec
) );
2902 POST(sys_mq_timedreceive
)
2904 POST_MEM_WRITE( ARG2
, RES
);
2906 POST_MEM_WRITE( ARG4
, sizeof(unsigned int) );
2909 PRE(sys_mq_timedreceive_time64
)
2911 *flags
|= SfMayBlock
;
2912 PRINT("sys_mq_timedreceive_time64( %ld, %#" FMT_REGWORD
"x, %"
2913 FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
2914 SARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
2915 PRE_REG_READ5(ssize_t
, "mq_timedreceive_time64",
2916 vki_mqd_t
, mqdes
, char *, msg_ptr
, vki_size_t
, msg_len
,
2917 unsigned int *, msg_prio
,
2918 const struct vki_timespec64
*, abs_timeout
);
2919 if (!ML_(fd_allowed
)(ARG1
, "mq_timedreceive_time64", tid
, False
)) {
2920 SET_STATUS_Failure( VKI_EBADF
);
2922 PRE_MEM_WRITE( "mq_timedreceive_time64(msg_ptr)", ARG2
, ARG3
);
2924 PRE_MEM_WRITE( "mq_timedreceive_time64(msg_prio)",
2925 ARG4
, sizeof(unsigned int) );
2927 pre_read_timespec64(tid
, "mq_timedreceive_time64(abs_timeout)", ARG5
);
2931 POST(sys_mq_timedreceive_time64
)
2933 POST_MEM_WRITE( ARG2
, RES
);
2935 POST_MEM_WRITE( ARG4
, sizeof(unsigned int) );
2940 PRINT("sys_mq_notify( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
2941 PRE_REG_READ2(long, "mq_notify",
2942 vki_mqd_t
, mqdes
, const struct sigevent
*, notification
);
2943 if (!ML_(fd_allowed
)(ARG1
, "mq_notify", tid
, False
))
2944 SET_STATUS_Failure( VKI_EBADF
);
2946 PRE_MEM_READ( "mq_notify(notification)",
2947 ARG2
, sizeof(struct vki_sigevent
) );
2950 PRE(sys_mq_getsetattr
)
2952 PRINT("sys_mq_getsetattr( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
2953 SARG1
, ARG2
, ARG3
);
2954 PRE_REG_READ3(long, "mq_getsetattr",
2955 vki_mqd_t
, mqdes
, const struct mq_attr
*, mqstat
,
2956 struct mq_attr
*, omqstat
);
2957 if (!ML_(fd_allowed
)(ARG1
, "mq_getsetattr", tid
, False
)) {
2958 SET_STATUS_Failure( VKI_EBADF
);
2961 const struct vki_mq_attr
*attr
= (struct vki_mq_attr
*)(Addr
)ARG2
;
2962 PRE_MEM_READ( "mq_getsetattr(mqstat->mq_flags)",
2963 (Addr
)&attr
->mq_flags
, sizeof(attr
->mq_flags
) );
2966 PRE_MEM_WRITE( "mq_getsetattr(omqstat)", ARG3
,
2967 sizeof(struct vki_mq_attr
) );
2970 POST(sys_mq_getsetattr
)
2973 POST_MEM_WRITE( ARG3
, sizeof(struct vki_mq_attr
) );
2976 /* ---------------------------------------------------------------------
2978 ------------------------------------------------------------------ */
2980 PRE(sys_clock_settime
)
2982 PRINT("sys_clock_settime( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
2983 PRE_REG_READ2(long, "clock_settime",
2984 vki_clockid_t
, clk_id
, const struct timespec
*, tp
);
2985 PRE_MEM_READ( "clock_settime(tp)", ARG2
, sizeof(struct vki_timespec
) );
2988 PRE(sys_clock_settime64
)
2990 PRINT("sys_clock_settime64( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
2991 PRE_REG_READ2(long, "clock_settime64",
2992 vki_clockid_t
, clk_id
, const struct timespec64
*, tp
);
2993 pre_read_timespec64(tid
, "clock_settime64(tp)", ARG2
);
2996 PRE(sys_clock_gettime
)
2998 PRINT("sys_clock_gettime( %ld, %#" FMT_REGWORD
"x )" , SARG1
, ARG2
);
2999 PRE_REG_READ2(long, "clock_gettime",
3000 vki_clockid_t
, clk_id
, struct timespec
*, tp
);
3001 PRE_MEM_WRITE( "clock_gettime(tp)", ARG2
, sizeof(struct vki_timespec
) );
3003 POST(sys_clock_gettime
)
3005 POST_MEM_WRITE( ARG2
, sizeof(struct vki_timespec
) );
3008 PRE(sys_clock_gettime64
)
3010 PRINT("sys_clock_gettime64( %ld, %#" FMT_REGWORD
"x )" , SARG1
, ARG2
);
3011 PRE_REG_READ2(long, "clock_gettime64",
3012 vki_clockid_t
, clk_id
, struct vki_timespec64
*, tp
);
3013 PRE_MEM_WRITE ( "clock_gettime64(tp)", ARG2
,
3014 sizeof(struct vki_timespec64
) );
3016 POST(sys_clock_gettime64
)
3018 POST_MEM_WRITE( ARG2
, sizeof(struct vki_timespec64
) );
3021 PRE(sys_clock_getres
)
3023 PRINT("sys_clock_getres( %ld, %#" FMT_REGWORD
"x )" , SARG1
, ARG2
);
3024 // Nb: we can't use "RES" as the param name because that's a macro
3026 PRE_REG_READ2(long, "clock_getres",
3027 vki_clockid_t
, clk_id
, struct timespec
*, res
);
3029 PRE_MEM_WRITE( "clock_getres(res)", ARG2
, sizeof(struct vki_timespec
) );
3031 POST(sys_clock_getres
)
3034 POST_MEM_WRITE( ARG2
, sizeof(struct vki_timespec
) );
3037 PRE(sys_clock_getres_time64
)
3039 PRINT("sys_clock_getres_time64( %ld, %#" FMT_REGWORD
"x )" , SARG1
, ARG2
);
3040 // Nb: we can't use "RES" as the param name because that's a macro
3042 PRE_REG_READ2(long, "clock_getres_time64",
3043 vki_clockid_t
, clk_id
, struct vki_timespec64
*, res
);
3045 PRE_MEM_WRITE( "clock_getres_time64(res)", ARG2
,
3046 sizeof(struct vki_timespec64
) );
3048 POST(sys_clock_getres_time64
)
3051 POST_MEM_WRITE( ARG2
, sizeof(struct vki_timespec64
) );
3054 PRE(sys_clock_nanosleep
)
3056 *flags
|= SfMayBlock
|SfPostOnFail
;
3057 PRINT("sys_clock_nanosleep( %ld, %ld, %#" FMT_REGWORD
"x, %#"
3059 SARG1
, SARG2
, ARG3
, ARG4
);
3060 PRE_REG_READ4(int32_t, "clock_nanosleep",
3061 vki_clockid_t
, clkid
, int, flags
,
3062 const struct timespec
*, rqtp
, struct timespec
*, rmtp
);
3063 PRE_MEM_READ( "clock_nanosleep(rqtp)", ARG3
, sizeof(struct vki_timespec
) );
3065 PRE_MEM_WRITE( "clock_nanosleep(rmtp)", ARG4
, sizeof(struct vki_timespec
) );
3067 POST(sys_clock_nanosleep
)
3069 if (ARG4
!= 0 && FAILURE
&& ERR
== VKI_EINTR
)
3070 POST_MEM_WRITE( ARG4
, sizeof(struct vki_timespec
) );
3073 PRE(sys_clock_nanosleep_time64
)
3075 *flags
|= SfMayBlock
|SfPostOnFail
;
3076 PRINT("sys_clock_nanosleep_time64( %ld, %ld, %#" FMT_REGWORD
"x, %#"
3078 SARG1
, SARG2
, ARG3
, ARG4
);
3079 PRE_REG_READ4(int32_t, "clock_nanosleep_time64",
3080 vki_clockid_t
, clkid
, int, flags
,
3081 const struct vki_timespec64
*, rqtp
,
3082 struct vki_timespec64
*, rmtp
);
3083 pre_read_timespec64(tid
, "clock_nanosleep_time64(rqtp)", ARG3
);
3085 PRE_MEM_WRITE( "clock_nanosleep_time64(rmtp)", ARG4
,
3086 sizeof(struct vki_timespec64
) );
3088 POST(sys_clock_nanosleep_time64
)
3090 if (ARG4
!= 0 && FAILURE
&& ERR
== VKI_EINTR
)
3091 POST_MEM_WRITE( ARG4
, sizeof(struct vki_timespec64
) );
3094 /* ---------------------------------------------------------------------
3096 ------------------------------------------------------------------ */
3098 PRE(sys_timer_create
)
3100 PRINT("sys_timer_create( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
3102 PRE_REG_READ3(long, "timer_create",
3103 vki_clockid_t
, clockid
, struct sigevent
*, evp
,
3104 vki_timer_t
*, timerid
);
3106 struct vki_sigevent
*evp
= (struct vki_sigevent
*) (Addr
)ARG2
;
3107 PRE_MEM_READ( "timer_create(evp.sigev_value)", (Addr
)&evp
->sigev_value
,
3108 sizeof(vki_sigval_t
) );
3109 PRE_MEM_READ( "timer_create(evp.sigev_signo)", (Addr
)&evp
->sigev_signo
,
3111 PRE_MEM_READ( "timer_create(evp.sigev_notify)", (Addr
)&evp
->sigev_notify
,
3113 if (ML_(safe_to_deref
)(&evp
->sigev_notify
, sizeof(int))
3114 && (evp
->sigev_notify
& VKI_SIGEV_THREAD_ID
) != 0)
3115 PRE_MEM_READ( "timer_create(evp.sigev_notify_thread_id)",
3116 (Addr
)&evp
->vki_sigev_notify_thread_id
, sizeof(int) );
3118 PRE_MEM_WRITE( "timer_create(timerid)", ARG3
, sizeof(vki_timer_t
) );
3120 POST(sys_timer_create
)
3122 POST_MEM_WRITE( ARG3
, sizeof(vki_timer_t
) );
3125 PRE(sys_timer_settime
)
3127 PRINT("sys_timer_settime( %ld, %ld, %#" FMT_REGWORD
"x, %#"
3128 FMT_REGWORD
"x )", SARG1
,SARG2
,ARG3
,ARG4
);
3129 PRE_REG_READ4(long, "timer_settime",
3130 vki_timer_t
, timerid
, int, flags
,
3131 const struct itimerspec
*, value
,
3132 struct itimerspec
*, ovalue
);
3133 PRE_MEM_READ( "timer_settime(value)", ARG3
,
3134 sizeof(struct vki_itimerspec
) );
3136 PRE_MEM_WRITE( "timer_settime(ovalue)", ARG4
,
3137 sizeof(struct vki_itimerspec
) );
3139 POST(sys_timer_settime
)
3142 POST_MEM_WRITE( ARG4
, sizeof(struct vki_itimerspec
) );
3145 PRE(sys_timer_settime64
)
3147 PRINT("sys_timer_settime64( %ld, %ld, %#" FMT_REGWORD
"x, %#"
3148 FMT_REGWORD
"x )", SARG1
,SARG2
,ARG3
,ARG4
);
3149 PRE_REG_READ4(long, "timer_settime64",
3150 vki_timer_t
, timerid
, int, flags
,
3151 const struct vki_itimerspec64
*, value
,
3152 struct vki_itimerspec64
*, ovalue
);
3153 PRE_MEM_READ( "timer_settime64(value)", ARG3
,
3154 sizeof(struct vki_itimerspec64
) );
3156 PRE_MEM_WRITE( "timer_settime64(ovalue)", ARG4
,
3157 sizeof(struct vki_itimerspec64
) );
3159 POST(sys_timer_settime64
)
3162 POST_MEM_WRITE( ARG4
, sizeof(struct vki_itimerspec64
) );
3165 PRE(sys_timer_gettime
)
3167 PRINT("sys_timer_gettime( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3168 PRE_REG_READ2(long, "timer_gettime",
3169 vki_timer_t
, timerid
, struct itimerspec
*, value
);
3170 PRE_MEM_WRITE( "timer_gettime(value)", ARG2
,
3171 sizeof(struct vki_itimerspec
));
3173 POST(sys_timer_gettime
)
3175 POST_MEM_WRITE( ARG2
, sizeof(struct vki_itimerspec
) );
3178 PRE(sys_timer_gettime64
)
3180 PRINT("sys_timer_gettime64( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3181 PRE_REG_READ2(long, "timer_gettime64",
3182 vki_timer_t
, timerid
, struct vki_itimerspec64
*, value
);
3183 PRE_MEM_WRITE( "timer_gettime64(value)", ARG2
,
3184 sizeof(struct vki_itimerspec64
));
3186 POST(sys_timer_gettime64
)
3188 POST_MEM_WRITE( ARG2
, sizeof(struct vki_itimerspec64
) );
3191 PRE(sys_timer_getoverrun
)
3193 PRINT("sys_timer_getoverrun( %#" FMT_REGWORD
"x )", ARG1
);
3194 PRE_REG_READ1(long, "timer_getoverrun", vki_timer_t
, timerid
);
3197 PRE(sys_timer_delete
)
3199 PRINT("sys_timer_delete( %#" FMT_REGWORD
"x )", ARG1
);
3200 PRE_REG_READ1(long, "timer_delete", vki_timer_t
, timerid
);
3203 /* ---------------------------------------------------------------------
3205 See also http://lwn.net/Articles/260172/ for an overview.
3206 See also /usr/src/linux/fs/timerfd.c for the implementation.
3207 ------------------------------------------------------------------ */
3209 /* Returns True if running on 2.6.22, else False (or False if
3210 cannot be determined). */
3211 static Bool
linux_kernel_2_6_22(void)
3213 static Int result
= -1;
3215 HChar release
[64]; // large enough
3219 res
= VG_(open
)("/proc/sys/kernel/osrelease", 0, 0);
3220 if (sr_isError(res
))
3223 read
= VG_(read
)(fd
, release
, sizeof(release
) - 1);
3228 //VG_(printf)("kernel release = %s\n", release);
3229 result
= VG_(strncmp
)(release
, "2.6.22", 6) == 0
3230 && ! VG_(isdigit
)(release
[6]);
3232 vg_assert(result
== 0 || result
== 1);
3236 PRE(sys_timerfd_create
)
3238 if (linux_kernel_2_6_22()) {
3239 /* 2.6.22 kernel: timerfd system call. */
3240 PRINT("sys_timerfd ( %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
, ARG3
);
3241 PRE_REG_READ3(long, "sys_timerfd",
3242 int, fd
, int, clockid
, const struct itimerspec
*, tmr
);
3243 PRE_MEM_READ("timerfd(tmr)", ARG3
,
3244 sizeof(struct vki_itimerspec
) );
3245 if ((Word
)ARG1
!= -1L && !ML_(fd_allowed
)(ARG1
, "timerfd", tid
, False
))
3246 SET_STATUS_Failure( VKI_EBADF
);
3248 /* 2.6.24 and later kernels: timerfd_create system call. */
3249 PRINT("sys_timerfd_create (%ld, %ld )", SARG1
, SARG2
);
3250 PRE_REG_READ2(long, "timerfd_create", int, clockid
, int, flags
);
3253 POST(sys_timerfd_create
)
3255 if (linux_kernel_2_6_22())
3257 /* 2.6.22 kernel: timerfd system call. */
3258 if (!ML_(fd_allowed
)(RES
, "timerfd", tid
, True
)) {
3260 SET_STATUS_Failure( VKI_EMFILE
);
3262 if (VG_(clo_track_fds
))
3263 ML_(record_fd_open_nameless
) (tid
, RES
);
3268 /* 2.6.24 and later kernels: timerfd_create system call. */
3269 if (!ML_(fd_allowed
)(RES
, "timerfd_create", tid
, True
)) {
3271 SET_STATUS_Failure( VKI_EMFILE
);
3273 if (VG_(clo_track_fds
))
3274 ML_(record_fd_open_nameless
) (tid
, RES
);
3279 PRE(sys_timerfd_gettime
)
3281 PRINT("sys_timerfd_gettime ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3282 PRE_REG_READ2(long, "timerfd_gettime",
3284 struct vki_itimerspec
*, otmr
);
3285 if (!ML_(fd_allowed
)(ARG1
, "timerfd_gettime", tid
, False
))
3286 SET_STATUS_Failure(VKI_EBADF
);
3288 PRE_MEM_WRITE("timerfd_gettime(result)",
3289 ARG2
, sizeof(struct vki_itimerspec
));
3291 POST(sys_timerfd_gettime
)
3294 POST_MEM_WRITE(ARG2
, sizeof(struct vki_itimerspec
));
3297 PRE(sys_timerfd_gettime64
)
3299 PRINT("sys_timerfd_gettime64 ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3300 PRE_REG_READ2(long, "timerfd_gettime64",
3302 struct vki_itimerspec64
*, otmr
);
3303 if (!ML_(fd_allowed
)(ARG1
, "timerfd_gettime64", tid
, False
))
3304 SET_STATUS_Failure(VKI_EBADF
);
3306 PRE_MEM_WRITE("timerfd_gettime64(result)",
3307 ARG2
, sizeof(struct vki_itimerspec64
));
3309 POST(sys_timerfd_gettime64
)
3312 POST_MEM_WRITE(ARG2
, sizeof(struct vki_itimerspec64
));
3315 PRE(sys_timerfd_settime
)
3317 PRINT("sys_timerfd_settime ( %ld, %ld, %#" FMT_REGWORD
"x, %#"
3318 FMT_REGWORD
"x )", SARG1
, SARG2
, ARG3
, ARG4
);
3319 PRE_REG_READ4(long, "timerfd_settime",
3322 const struct vki_itimerspec
*, utmr
,
3323 struct vki_itimerspec
*, otmr
);
3324 if (!ML_(fd_allowed
)(ARG1
, "timerfd_settime", tid
, False
))
3325 SET_STATUS_Failure(VKI_EBADF
);
3328 PRE_MEM_READ("timerfd_settime(result)",
3329 ARG3
, sizeof(struct vki_itimerspec
));
3332 PRE_MEM_WRITE("timerfd_settime(result)",
3333 ARG4
, sizeof(struct vki_itimerspec
));
3337 POST(sys_timerfd_settime
)
3339 if (RES
== 0 && ARG4
!= 0)
3340 POST_MEM_WRITE(ARG4
, sizeof(struct vki_itimerspec
));
3343 PRE(sys_timerfd_settime64
)
3345 PRINT("sys_timerfd_settime64 ( %ld, %ld, %#" FMT_REGWORD
"x, %#"
3346 FMT_REGWORD
"x )", SARG1
, SARG2
, ARG3
, ARG4
);
3347 PRE_REG_READ4(long, "timerfd_settime64",
3350 const struct vki_itimerspec64
*, utmr
,
3351 struct vki_itimerspec64
*, otmr
);
3352 if (!ML_(fd_allowed
)(ARG1
, "timerfd_settime64", tid
, False
))
3353 SET_STATUS_Failure(VKI_EBADF
);
3356 pre_read_itimerspec64 (tid
, "timerfd_settime64(result)", ARG3
);
3359 PRE_MEM_WRITE("timerfd_settime64(result)",
3360 ARG4
, sizeof(struct vki_itimerspec64
));
3364 POST(sys_timerfd_settime64
)
3366 if (RES
== 0 && ARG4
!= 0)
3367 POST_MEM_WRITE(ARG4
, sizeof(struct vki_itimerspec64
));
3370 /* ---------------------------------------------------------------------
3371 capabilities wrappers
3372 ------------------------------------------------------------------ */
3376 PRINT("sys_capget ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )", ARG1
, ARG2
);
3377 PRE_REG_READ2(long, "capget",
3378 vki_cap_user_header_t
, header
, vki_cap_user_data_t
, data
);
3379 PRE_MEM_READ( "capget(header)", ARG1
,
3380 sizeof(struct __vki_user_cap_header_struct
) );
3381 if (ARG2
!= (Addr
)NULL
)
3382 PRE_MEM_WRITE( "capget(data)", ARG2
,
3383 sizeof(struct __vki_user_cap_data_struct
) );
3387 if (ARG2
!= (Addr
)NULL
)
3388 POST_MEM_WRITE( ARG2
, sizeof(struct __vki_user_cap_data_struct
) );
3393 PRINT("sys_capset ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )", ARG1
, ARG2
);
3394 PRE_REG_READ2(long, "capset",
3395 vki_cap_user_header_t
, header
,
3396 const vki_cap_user_data_t
, data
);
3397 PRE_MEM_READ( "capset(header)",
3398 ARG1
, sizeof(struct __vki_user_cap_header_struct
) );
3399 PRE_MEM_READ( "capset(data)",
3400 ARG2
, sizeof(struct __vki_user_cap_data_struct
) );
3403 /* ---------------------------------------------------------------------
3404 16-bit uid/gid/groups wrappers
3405 ------------------------------------------------------------------ */
3409 PRINT("sys_getuid16 ( )");
3410 PRE_REG_READ0(long, "getuid16");
3415 PRINT("sys_setuid16 ( %" FMT_REGWORD
"u )", ARG1
);
3416 PRE_REG_READ1(long, "setuid16", vki_old_uid_t
, uid
);
3421 PRINT("sys_getgid16 ( )");
3422 PRE_REG_READ0(long, "getgid16");
3427 PRINT("sys_setgid16 ( %" FMT_REGWORD
"u )", ARG1
);
3428 PRE_REG_READ1(long, "setgid16", vki_old_gid_t
, gid
);
3433 PRINT("sys_geteuid16 ( )");
3434 PRE_REG_READ0(long, "geteuid16");
3439 PRINT("sys_getegid16 ( )");
3440 PRE_REG_READ0(long, "getegid16");
3445 PRINT("setreuid16 ( 0x%" FMT_REGWORD
"x, 0x%" FMT_REGWORD
"x )", ARG1
, ARG2
);
3446 PRE_REG_READ2(long, "setreuid16", vki_old_uid_t
, ruid
, vki_old_uid_t
, euid
);
3451 PRINT("sys_setregid16 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )", ARG1
, ARG2
);
3452 PRE_REG_READ2(long, "setregid16", vki_old_gid_t
, rgid
, vki_old_gid_t
, egid
);
3455 PRE(sys_getgroups16
)
3457 PRINT("sys_getgroups16 ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3458 PRE_REG_READ2(long, "getgroups16", int, size
, vki_old_gid_t
*, list
);
3460 PRE_MEM_WRITE( "getgroups16(list)", ARG2
, ARG1
* sizeof(vki_old_gid_t
) );
3462 POST(sys_getgroups16
)
3465 if (ARG1
> 0 && RES
> 0)
3466 POST_MEM_WRITE( ARG2
, RES
* sizeof(vki_old_gid_t
) );
3469 PRE(sys_setgroups16
)
3471 PRINT("sys_setgroups16 ( %llu, %#" FMT_REGWORD
"x )", (ULong
)ARG1
, ARG2
);
3472 PRE_REG_READ2(long, "setgroups16", int, size
, vki_old_gid_t
*, list
);
3474 PRE_MEM_READ( "setgroups16(list)", ARG2
, ARG1
* sizeof(vki_old_gid_t
) );
3477 /* ---------------------------------------------------------------------
3479 ------------------------------------------------------------------ */
3483 PRINT("sys_chown16 ( %#" FMT_REGWORD
"x, 0x%" FMT_REGWORD
"x, 0x%"
3484 FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
3485 PRE_REG_READ3(long, "chown16",
3487 vki_old_uid_t
, owner
, vki_old_gid_t
, group
);
3488 PRE_MEM_RASCIIZ( "chown16(path)", ARG1
);
3493 PRINT("sys_fchown16 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
3494 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
3495 PRE_REG_READ3(long, "fchown16",
3496 unsigned int, fd
, vki_old_uid_t
, owner
, vki_old_gid_t
, group
);
3499 /* ---------------------------------------------------------------------
3501 ------------------------------------------------------------------ */
3505 *flags
|= SfMayBlock
;
3506 PRINT("sys_setxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
3507 FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld )", ARG1
, ARG2
, ARG3
,
3509 PRE_REG_READ5(long, "setxattr",
3510 char *, path
, char *, name
,
3511 void *, value
, vki_size_t
, size
, int, flags
);
3512 PRE_MEM_RASCIIZ( "setxattr(path)", ARG1
);
3513 PRE_MEM_RASCIIZ( "setxattr(name)", ARG2
);
3514 PRE_MEM_READ( "setxattr(value)", ARG3
, ARG4
);
3519 *flags
|= SfMayBlock
;
3520 PRINT("sys_lsetxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
3521 FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld )",
3522 ARG1
, ARG2
, ARG3
, ARG4
, SARG5
);
3523 PRE_REG_READ5(long, "lsetxattr",
3524 char *, path
, char *, name
,
3525 void *, value
, vki_size_t
, size
, int, flags
);
3526 PRE_MEM_RASCIIZ( "lsetxattr(path)", ARG1
);
3527 PRE_MEM_RASCIIZ( "lsetxattr(name)", ARG2
);
3528 PRE_MEM_READ( "lsetxattr(value)", ARG3
, ARG4
);
3533 *flags
|= SfMayBlock
;
3534 PRINT("sys_fsetxattr ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %"
3535 FMT_REGWORD
"u, %ld )",
3536 SARG1
, ARG2
, ARG3
, ARG4
, SARG5
);
3537 PRE_REG_READ5(long, "fsetxattr",
3538 int, fd
, char *, name
, void *, value
,
3539 vki_size_t
, size
, int, flags
);
3540 PRE_MEM_RASCIIZ( "fsetxattr(name)", ARG2
);
3541 PRE_MEM_READ( "fsetxattr(value)", ARG3
, ARG4
);
3546 *flags
|= SfMayBlock
;
3547 PRINT("sys_getxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
3548 FMT_REGWORD
"x, %llu )", ARG1
, ARG2
, ARG3
, (ULong
)ARG4
);
3549 PRE_REG_READ4(ssize_t
, "getxattr",
3550 char *, path
, char *, name
, void *, value
, vki_size_t
, size
);
3551 PRE_MEM_RASCIIZ( "getxattr(path)", ARG1
);
3552 PRE_MEM_RASCIIZ( "getxattr(name)", ARG2
);
3553 PRE_MEM_WRITE( "getxattr(value)", ARG3
, ARG4
);
3558 if (RES
> 0 && ARG3
!= (Addr
)NULL
) {
3559 POST_MEM_WRITE( ARG3
, RES
);
3565 *flags
|= SfMayBlock
;
3566 PRINT("sys_lgetxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
3567 FMT_REGWORD
"x, %llu )", ARG1
, ARG2
, ARG3
, (ULong
)ARG4
);
3568 PRE_REG_READ4(ssize_t
, "lgetxattr",
3569 char *, path
, char *, name
, void *, value
, vki_size_t
, size
);
3570 PRE_MEM_RASCIIZ( "lgetxattr(path)", ARG1
);
3571 PRE_MEM_RASCIIZ( "lgetxattr(name)", ARG2
);
3572 PRE_MEM_WRITE( "lgetxattr(value)", ARG3
, ARG4
);
3577 if (RES
> 0 && ARG3
!= (Addr
)NULL
) {
3578 POST_MEM_WRITE( ARG3
, RES
);
3584 *flags
|= SfMayBlock
;
3585 PRINT("sys_fgetxattr ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %"
3586 FMT_REGWORD
"u )", SARG1
, ARG2
, ARG3
, ARG4
);
3587 PRE_REG_READ4(ssize_t
, "fgetxattr",
3588 int, fd
, char *, name
, void *, value
, vki_size_t
, size
);
3589 PRE_MEM_RASCIIZ( "fgetxattr(name)", ARG2
);
3590 PRE_MEM_WRITE( "fgetxattr(value)", ARG3
, ARG4
);
3594 if (RES
> 0 && ARG3
!= (Addr
)NULL
)
3595 POST_MEM_WRITE( ARG3
, RES
);
3600 *flags
|= SfMayBlock
;
3601 PRINT("sys_listxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %llu )",
3602 ARG1
, ARG2
, (ULong
)ARG3
);
3603 PRE_REG_READ3(ssize_t
, "listxattr",
3604 char *, path
, char *, list
, vki_size_t
, size
);
3605 PRE_MEM_RASCIIZ( "listxattr(path)", ARG1
);
3606 PRE_MEM_WRITE( "listxattr(list)", ARG2
, ARG3
);
3610 if (RES
> 0 && ARG2
!= (Addr
)NULL
)
3611 POST_MEM_WRITE( ARG2
, RES
);
3616 *flags
|= SfMayBlock
;
3617 PRINT("sys_llistxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %llu )",
3618 ARG1
, ARG2
, (ULong
)ARG3
);
3619 PRE_REG_READ3(ssize_t
, "llistxattr",
3620 char *, path
, char *, list
, vki_size_t
, size
);
3621 PRE_MEM_RASCIIZ( "llistxattr(path)", ARG1
);
3622 PRE_MEM_WRITE( "llistxattr(list)", ARG2
, ARG3
);
3624 POST(sys_llistxattr
)
3626 if (RES
> 0 && ARG2
!= (Addr
)NULL
)
3627 POST_MEM_WRITE( ARG2
, RES
);
3632 *flags
|= SfMayBlock
;
3633 PRINT("sys_flistxattr ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
3635 PRE_REG_READ3(ssize_t
, "flistxattr",
3636 int, fd
, char *, list
, vki_size_t
, size
);
3637 PRE_MEM_WRITE( "flistxattr(list)", ARG2
, ARG3
);
3639 POST(sys_flistxattr
)
3641 if (RES
> 0 && ARG2
!= (Addr
)NULL
)
3642 POST_MEM_WRITE( ARG2
, RES
);
3645 PRE(sys_removexattr
)
3647 *flags
|= SfMayBlock
;
3648 PRINT("sys_removexattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
3650 PRE_REG_READ2(long, "removexattr", char *, path
, char *, name
);
3651 PRE_MEM_RASCIIZ( "removexattr(path)", ARG1
);
3652 PRE_MEM_RASCIIZ( "removexattr(name)", ARG2
);
3655 PRE(sys_lremovexattr
)
3657 *flags
|= SfMayBlock
;
3658 PRINT("sys_lremovexattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
3660 PRE_REG_READ2(long, "lremovexattr", char *, path
, char *, name
);
3661 PRE_MEM_RASCIIZ( "lremovexattr(path)", ARG1
);
3662 PRE_MEM_RASCIIZ( "lremovexattr(name)", ARG2
);
3665 PRE(sys_fremovexattr
)
3667 *flags
|= SfMayBlock
;
3668 PRINT("sys_fremovexattr ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3669 PRE_REG_READ2(long, "fremovexattr", int, fd
, char *, name
);
3670 PRE_MEM_RASCIIZ( "fremovexattr(name)", ARG2
);
3673 /* ---------------------------------------------------------------------
3675 ------------------------------------------------------------------ */
3677 PRE(sys_sched_setparam
)
3679 PRINT("sched_setparam ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3680 PRE_REG_READ2(long, "sched_setparam",
3681 vki_pid_t
, pid
, struct sched_param
*, p
);
3682 PRE_MEM_READ( "sched_setparam(p)", ARG2
, sizeof(struct vki_sched_param
) );
3684 POST(sys_sched_setparam
)
3686 POST_MEM_WRITE( ARG2
, sizeof(struct vki_sched_param
) );
3689 PRE(sys_sched_getparam
)
3691 PRINT("sched_getparam ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3692 PRE_REG_READ2(long, "sched_getparam",
3693 vki_pid_t
, pid
, struct sched_param
*, p
);
3694 PRE_MEM_WRITE( "sched_getparam(p)", ARG2
, sizeof(struct vki_sched_param
) );
3696 POST(sys_sched_getparam
)
3698 POST_MEM_WRITE( ARG2
, sizeof(struct vki_sched_param
) );
3701 PRE(sys_sched_setattr
)
3703 struct vki_sched_attr
*attr
;
3704 PRINT("sched_setattr ( %ld, %#" FMT_REGWORD
"x, %#"
3705 FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
);
3706 PRE_REG_READ3(long, "sched_setattr",
3707 vki_pid_t
, pid
, struct sched_attr
*, p
, unsigned int, flags
);
3708 /* We need to be able to read at least the size field. */
3709 PRE_MEM_READ( "sched_setattr(attr->size)", ARG2
, sizeof(vki_uint32_t
) );
3710 attr
= (struct vki_sched_attr
*)(Addr
)ARG2
;
3711 if (ML_(safe_to_deref
)(attr
,sizeof(vki_uint32_t
)))
3712 PRE_MEM_READ( "sched_setattr(attr)", (Addr
)attr
, attr
->size
);
3715 PRE(sys_sched_getattr
)
3717 struct vki_sched_attr
*attr
;
3718 PRINT("sched_getattr ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
3719 FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
, ARG4
);
3720 PRE_REG_READ4(long, "sched_getattr",
3721 vki_pid_t
, pid
, struct sched_attr
*, p
,
3722 unsigned int, size
, unsigned int, flags
);
3723 /* We need to be able to read at least the size field. */
3724 PRE_MEM_READ( "sched_setattr(attr->size)", ARG2
, sizeof(vki_uint32_t
) );
3725 /* And the kernel needs to be able to write to the whole struct size. */
3726 attr
= (struct vki_sched_attr
*)(Addr
)ARG2
;
3727 if (ML_(safe_to_deref
)(attr
,sizeof(vki_uint32_t
)))
3728 PRE_MEM_WRITE( "sched_setattr(attr)", (Addr
)attr
, attr
->size
);
3730 POST(sys_sched_getattr
)
3732 struct vki_sched_attr
*attr
= (struct vki_sched_attr
*)(Addr
)ARG2
;
3733 POST_MEM_WRITE( (Addr
)attr
, attr
->size
);
3736 PRE(sys_sched_getscheduler
)
3738 PRINT("sys_sched_getscheduler ( %ld )", SARG1
);
3739 PRE_REG_READ1(long, "sched_getscheduler", vki_pid_t
, pid
);
3742 PRE(sys_sched_setscheduler
)
3744 PRINT("sys_sched_setscheduler ( %ld, %ld, %#" FMT_REGWORD
"x )",
3745 SARG1
, SARG2
, ARG3
);
3746 PRE_REG_READ3(long, "sched_setscheduler",
3747 vki_pid_t
, pid
, int, policy
, struct sched_param
*, p
);
3749 PRE_MEM_READ( "sched_setscheduler(p)",
3750 ARG3
, sizeof(struct vki_sched_param
));
3753 PRE(sys_sched_yield
)
3755 *flags
|= SfMayBlock
;
3756 PRINT("sched_yield()");
3757 PRE_REG_READ0(long, "sys_sched_yield");
3760 PRE(sys_sched_get_priority_max
)
3762 PRINT("sched_get_priority_max ( %ld )", SARG1
);
3763 PRE_REG_READ1(long, "sched_get_priority_max", int, policy
);
3766 PRE(sys_sched_get_priority_min
)
3768 PRINT("sched_get_priority_min ( %ld )", SARG1
);
3769 PRE_REG_READ1(long, "sched_get_priority_min", int, policy
);
3772 PRE(sys_sched_rr_get_interval
)
3774 PRINT("sys_sched_rr_get_interval ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3775 PRE_REG_READ2(int, "sched_rr_get_interval",
3777 struct vki_timespec
*, tp
);
3778 PRE_MEM_WRITE("sched_rr_get_interval(timespec)",
3779 ARG2
, sizeof(struct vki_timespec
));
3782 POST(sys_sched_rr_get_interval
)
3784 POST_MEM_WRITE(ARG2
, sizeof(struct vki_timespec
));
3787 PRE(sys_sched_rr_get_interval_time64
)
3789 PRINT("sys_sched_rr_get_interval_time64 ( %ld, %#" FMT_REGWORD
"x )",
3791 PRE_REG_READ2(int, "sched_rr_get_interval_time64",
3793 struct vki_timespec
*, tp
);
3794 PRE_MEM_WRITE("sched_rr_get_interval_time64(timespec)",
3795 ARG2
, sizeof(struct vki_timespec64
));
3798 POST(sys_sched_rr_get_interval_time64
)
3800 POST_MEM_WRITE(ARG2
, sizeof(struct vki_timespec64
));
3803 PRE(sys_sched_setaffinity
)
3805 PRINT("sched_setaffinity ( %ld, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
3807 PRE_REG_READ3(long, "sched_setaffinity",
3808 vki_pid_t
, pid
, unsigned int, len
, unsigned long *, mask
);
3809 PRE_MEM_READ( "sched_setaffinity(mask)", ARG3
, ARG2
);
3812 PRE(sys_sched_getaffinity
)
3814 PRINT("sched_getaffinity ( %ld, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
3816 PRE_REG_READ3(long, "sched_getaffinity",
3817 vki_pid_t
, pid
, unsigned int, len
, unsigned long *, mask
);
3818 PRE_MEM_WRITE( "sched_getaffinity(mask)", ARG3
, ARG2
);
3820 POST(sys_sched_getaffinity
)
3822 POST_MEM_WRITE(ARG3
, ARG2
);
3827 PRINT("sys_unshare ( %#" FMT_REGWORD
"x )", ARG1
);
3828 PRE_REG_READ1(int, "unshare", unsigned long, flags
);
3833 PRINT("sys_setns ( %ld, %ld )", SARG1
, SARG2
);
3834 PRE_REG_READ2(int, "setns",
3837 if (!ML_(fd_allowed
)(ARG1
, "setns", tid
, False
))
3838 SET_STATUS_Failure( VKI_EBADF
);
3842 /* ---------------------------------------------------------------------
3843 miscellaneous wrappers
3844 ------------------------------------------------------------------ */
3848 *flags
|= SfMayBlock
;
3849 PRINT("sys_munlockall ( )");
3850 PRE_REG_READ0(long, "munlockall");
3853 // This has different signatures for different platforms.
3855 // x86: int sys_pipe(unsigned long __user *fildes);
3856 // AMD64: long sys_pipe(int *fildes);
3857 // ppc32: int sys_pipe(int __user *fildes);
3858 // ppc64: int sys_pipe(int __user *fildes);
3860 // The type of the argument is most important, and it is an array of 32 bit
3861 // values in all cases. (The return type differs across platforms, but it
3862 // is not used.) So we use 'int' as its type. This fixed bug #113230 which
3863 // was caused by using an array of 'unsigned long's, which didn't work on
3867 PRINT("sys_pipe ( %#" FMT_REGWORD
"x )", ARG1
);
3868 PRE_REG_READ1(int, "pipe", int *, filedes
);
3869 PRE_MEM_WRITE( "pipe(filedes)", ARG1
, 2*sizeof(int) );
3873 Int
*p
= (Int
*)(Addr
)ARG1
;
3874 if (!ML_(fd_allowed
)(p
[0], "pipe", tid
, True
) ||
3875 !ML_(fd_allowed
)(p
[1], "pipe", tid
, True
)) {
3878 SET_STATUS_Failure( VKI_EMFILE
);
3880 POST_MEM_WRITE( ARG1
, 2*sizeof(int) );
3881 if (VG_(clo_track_fds
)) {
3882 ML_(record_fd_open_nameless
)(tid
, p
[0]);
3883 ML_(record_fd_open_nameless
)(tid
, p
[1]);
3888 /* pipe2 (a kernel 2.6.twentysomething invention) is like pipe, except
3889 there's a second arg containing flags to be applied to the new file
3890 descriptors. It hardly seems worth the effort to factor out the
3891 duplicated code, hence: */
3894 PRINT("sys_pipe2 ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )", ARG1
, ARG2
);
3895 PRE_REG_READ2(int, "pipe", int *, filedes
, long, flags
);
3896 PRE_MEM_WRITE( "pipe2(filedes)", ARG1
, 2*sizeof(int) );
3900 Int
*p
= (Int
*)(Addr
)ARG1
;
3901 if (!ML_(fd_allowed
)(p
[0], "pipe2", tid
, True
) ||
3902 !ML_(fd_allowed
)(p
[1], "pipe2", tid
, True
)) {
3905 SET_STATUS_Failure( VKI_EMFILE
);
3907 POST_MEM_WRITE( ARG1
, 2*sizeof(int) );
3908 if (VG_(clo_track_fds
)) {
3909 ML_(record_fd_open_nameless
)(tid
, p
[0]);
3910 ML_(record_fd_open_nameless
)(tid
, p
[1]);
3917 PRINT("sys_dup3 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %#"
3918 FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
3919 PRE_REG_READ3(long, "dup3", unsigned int, oldfd
, unsigned int, newfd
, int, flags
);
3920 if (!ML_(fd_allowed
)(ARG2
, "dup3", tid
, True
))
3921 SET_STATUS_Failure( VKI_EBADF
);
3927 if (VG_(clo_track_fds
))
3928 ML_(record_fd_open_named
)(tid
, RES
);
3933 PRINT("sys_quotactl (0x%" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, 0x%"
3934 FMT_REGWORD
"x, 0x%" FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
, ARG4
);
3935 PRE_REG_READ4(long, "quotactl",
3936 unsigned int, cmd
, const char *, special
, vki_qid_t
, id
,
3938 PRE_MEM_RASCIIZ( "quotactl(special)", ARG2
);
3943 *flags
|= SfMayBlock
;
3944 PRINT("sys_waitid( %ld, %ld, %#" FMT_REGWORD
"x, %ld, %#" FMT_REGWORD
"x )",
3945 SARG1
, SARG2
, ARG3
, SARG4
, ARG5
);
3946 PRE_REG_READ5(int32_t, "sys_waitid",
3947 int, which
, vki_pid_t
, pid
, struct vki_siginfo
*, infop
,
3948 int, options
, struct vki_rusage
*, ru
);
3949 PRE_MEM_WRITE( "waitid(infop)", ARG3
, sizeof(struct vki_siginfo
) );
3951 PRE_MEM_WRITE( "waitid(ru)", ARG5
, sizeof(struct vki_rusage
) );
3955 POST_MEM_WRITE( ARG3
, sizeof(struct vki_siginfo
) );
3957 POST_MEM_WRITE( ARG5
, sizeof(struct vki_rusage
) );
3960 PRE(sys_sync_file_range
)
3962 *flags
|= SfMayBlock
;
3963 #if VG_WORDSIZE == 4
3964 PRINT("sys_sync_file_range ( %ld, %lld, %lld, %#" FMT_REGWORD
"x )",
3965 SARG1
, (Long
)MERGE64(ARG2
,ARG3
), (Long
)MERGE64(ARG4
,ARG5
),ARG6
);
3966 PRE_REG_READ6(long, "sync_file_range",
3968 unsigned, MERGE64_FIRST(offset
), unsigned, MERGE64_SECOND(offset
),
3969 unsigned, MERGE64_FIRST(nbytes
), unsigned, MERGE64_SECOND(nbytes
),
3970 unsigned int, flags
);
3971 #elif VG_WORDSIZE == 8
3972 PRINT("sys_sync_file_range ( %ld, %ld, %ld, %#lx )",
3973 SARG1
, SARG2
, SARG3
, ARG4
);
3974 PRE_REG_READ4(long, "sync_file_range",
3975 int, fd
, vki_loff_t
, offset
, vki_loff_t
, nbytes
,
3976 unsigned int, flags
);
3978 # error Unexpected word size
3980 if (!ML_(fd_allowed
)(ARG1
, "sync_file_range", tid
, False
))
3981 SET_STATUS_Failure( VKI_EBADF
);
3984 PRE(sys_sync_file_range2
)
3986 *flags
|= SfMayBlock
;
3987 #if VG_WORDSIZE == 4
3988 PRINT("sys_sync_file_range2 ( %ld, %" FMT_REGWORD
"u, %lld, %lld )",
3989 SARG1
, ARG2
, (Long
)MERGE64(ARG3
,ARG4
), (Long
)MERGE64(ARG5
,ARG6
));
3990 PRE_REG_READ6(long, "sync_file_range2",
3991 int, fd
, unsigned int, flags
,
3992 unsigned, MERGE64_FIRST(offset
), unsigned, MERGE64_SECOND(offset
),
3993 unsigned, MERGE64_FIRST(nbytes
), unsigned, MERGE64_SECOND(nbytes
));
3994 #elif VG_WORDSIZE == 8
3995 PRINT("sys_sync_file_range2 ( %ld, %lu, %ld, %ld )",
3996 SARG1
, ARG2
, SARG3
, SARG4
);
3997 PRE_REG_READ4(long, "sync_file_range2",
3998 int, fd
, unsigned int, flags
,
3999 vki_loff_t
, offset
, vki_loff_t
, nbytes
);
4001 # error Unexpected word size
4003 if (!ML_(fd_allowed
)(ARG1
, "sync_file_range2", tid
, False
))
4004 SET_STATUS_Failure( VKI_EBADF
);
4009 PRINT("sys_stime ( %#" FMT_REGWORD
"x )", ARG1
);
4010 PRE_REG_READ1(int, "stime", vki_time_t
*, t
);
4011 PRE_MEM_READ( "stime(t)", ARG1
, sizeof(vki_time_t
) );
4014 PRE(sys_perf_event_open
)
4016 struct vki_perf_event_attr
*attr
;
4017 PRINT("sys_perf_event_open ( %#" FMT_REGWORD
"x, %ld, %ld, %ld, %#"
4018 FMT_REGWORD
"x )", ARG1
, SARG2
, SARG3
, SARG4
, ARG5
);
4019 PRE_REG_READ5(long, "perf_event_open",
4020 struct vki_perf_event_attr
*, attr
,
4021 vki_pid_t
, pid
, int, cpu
, int, group_fd
,
4022 unsigned long, flags
);
4023 attr
= (struct vki_perf_event_attr
*)(Addr
)ARG1
;
4024 PRE_MEM_READ( "perf_event_open(attr->size)",
4025 (Addr
)&attr
->size
, sizeof(attr
->size
) );
4026 PRE_MEM_READ( "perf_event_open(attr)",
4027 (Addr
)attr
, attr
->size
);
4030 POST(sys_perf_event_open
)
4033 if (!ML_(fd_allowed
)(RES
, "perf_event_open", tid
, True
)) {
4035 SET_STATUS_Failure( VKI_EMFILE
);
4037 if (VG_(clo_track_fds
))
4038 ML_(record_fd_open_nameless
)(tid
, RES
);
4044 PRINT("sys_getcpu ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
4045 FMT_REGWORD
"x )" , ARG1
, ARG2
, ARG3
);
4046 PRE_REG_READ3(int, "getcpu",
4047 unsigned *, cpu
, unsigned *, node
, struct vki_getcpu_cache
*, tcache
);
4049 PRE_MEM_WRITE( "getcpu(cpu)", ARG1
, sizeof(unsigned) );
4051 PRE_MEM_WRITE( "getcpu(node)", ARG2
, sizeof(unsigned) );
4053 PRE_MEM_WRITE( "getcpu(tcache)", ARG3
, sizeof(struct vki_getcpu_cache
) );
4059 POST_MEM_WRITE( ARG1
, sizeof(unsigned) );
4061 POST_MEM_WRITE( ARG2
, sizeof(unsigned) );
4063 POST_MEM_WRITE( ARG3
, sizeof(struct vki_getcpu_cache
) );
4068 PRINT("sys_move_pages ( %ld, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %#"
4069 FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
4070 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
4071 PRE_REG_READ6(int, "move_pages",
4072 vki_pid_t
, pid
, unsigned long, nr_pages
, const void **, pages
,
4073 const int *, nodes
, int *, status
, int, flags
);
4074 PRE_MEM_READ("move_pages(pages)", ARG3
, ARG2
* sizeof(void *));
4076 PRE_MEM_READ("move_pages(nodes)", ARG4
, ARG2
* sizeof(int));
4077 PRE_MEM_WRITE("move_pages(status)", ARG5
, ARG2
* sizeof(int));
4080 POST(sys_move_pages
)
4082 POST_MEM_WRITE(ARG5
, ARG2
* sizeof(int));
4087 PRINT("sys_getrandom ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
4088 FMT_REGWORD
"u )" , ARG1
, ARG2
, ARG3
);
4089 PRE_REG_READ3(int, "getrandom",
4090 char *, buf
, vki_size_t
, count
, unsigned int, flags
);
4091 PRE_MEM_WRITE( "getrandom(cpu)", ARG1
, ARG2
);
4096 POST_MEM_WRITE( ARG1
, ARG2
);
4099 PRE(sys_memfd_create
)
4101 PRINT("sys_memfd_create ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )" ,
4103 PRE_REG_READ2(int, "memfd_create",
4104 char *, uname
, unsigned int, flags
);
4105 PRE_MEM_RASCIIZ( "memfd_create(uname)", ARG1
);
4108 POST(sys_memfd_create
)
4111 if (!ML_(fd_allowed
)(RES
, "memfd_create", tid
, True
)) {
4113 SET_STATUS_Failure( VKI_EMFILE
);
4115 if (VG_(clo_track_fds
))
4116 ML_(record_fd_open_nameless
)(tid
, RES
);
4120 PRE(sys_memfd_secret
)
4122 PRINT("sys_memfd_secret ( %#" FMT_REGWORD
"x )", ARG1
);
4123 PRE_REG_READ1(int, "memfd_secret", unsigned int, flags
);
4126 POST(sys_memfd_secret
)
4129 if (!ML_(fd_allowed
)(RES
, "memfd_secret", tid
, True
)) {
4131 SET_STATUS_Failure( VKI_EMFILE
);
4133 if (VG_(clo_track_fds
))
4134 ML_(record_fd_open_nameless
)(tid
, RES
);
4140 PRINT("sys_membarrier ( %#" FMT_REGWORD
"x )", ARG1
);
4141 PRE_REG_READ1(int, "membarrier", int, flags
);
4146 *flags
|= SfMayBlock
;
4147 PRINT("sys_syncfs ( %" FMT_REGWORD
"u )", ARG1
);
4148 PRE_REG_READ1(long, "syncfs", unsigned int, fd
);
4153 FUSE_COMPATIBLE_MAY_BLOCK();
4154 PRINT("sys_statx ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %ld, %#" FMT_REGWORD
"x )",
4155 (Word
)ARG1
,ARG2
,(char*)(Addr
)ARG2
,(Word
)ARG3
,(Word
)ARG4
,ARG5
);
4156 PRE_REG_READ5(long, "statx",
4157 int, dirfd
, char *, filename
, int, flags
,
4158 unsigned int, mask
, struct statx
*, buf
);
4159 // Work around Rust's dubious use of statx, as described here:
4160 // https://github.com/rust-lang/rust/blob/
4161 // ccd238309f9dce92a05a23c2959e2819668c69a4/
4162 // src/libstd/sys/unix/fs.rs#L128-L142
4163 // in which it passes NULL for both filename and buf, and then looks at the
4164 // return value, so as to determine whether or not this syscall is supported.
4165 Bool both_filename_and_buf_are_null
= ARG2
== 0 && ARG5
== 0;
4166 if (!both_filename_and_buf_are_null
) {
4167 PRE_MEM_RASCIIZ( "statx(filename)", ARG2
);
4168 PRE_MEM_WRITE( "statx(buf)", ARG5
, sizeof(struct vki_statx
) );
4173 POST_MEM_WRITE( ARG5
, sizeof(struct vki_statx
) );
4176 /* ---------------------------------------------------------------------
4178 ------------------------------------------------------------------ */
4182 *flags
|= SfMayBlock
;
4183 PRINT("sys_utime ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )", ARG1
,ARG2
);
4184 PRE_REG_READ2(long, "utime", char *, filename
, struct utimbuf
*, buf
);
4185 PRE_MEM_RASCIIZ( "utime(filename)", ARG1
);
4187 PRE_MEM_READ( "utime(buf)", ARG2
, sizeof(struct vki_utimbuf
) );
4190 /* ---------------------------------------------------------------------
4192 ------------------------------------------------------------------ */
4196 PRINT("sys_lseek ( %" FMT_REGWORD
"u, %ld, %" FMT_REGWORD
"u )",
4198 PRE_REG_READ3(vki_off_t
, "lseek",
4199 unsigned int, fd
, vki_off_t
, offset
, unsigned int, whence
);
4202 /* ---------------------------------------------------------------------
4204 ------------------------------------------------------------------ */
4208 *flags
|= SfMayBlock
;
4209 #if VG_WORDSIZE == 4
4210 PRINT("sys_readahead ( %ld, %lld, %" FMT_REGWORD
"u )",
4211 SARG1
, (Long
)MERGE64(ARG2
,ARG3
), ARG4
);
4212 PRE_REG_READ4(vki_off_t
, "readahead",
4213 int, fd
, unsigned, MERGE64_FIRST(offset
),
4214 unsigned, MERGE64_SECOND(offset
), vki_size_t
, count
);
4215 #elif VG_WORDSIZE == 8
4216 PRINT("sys_readahead ( %ld, %ld, %lu )", SARG1
, SARG2
, ARG3
);
4217 PRE_REG_READ3(vki_off_t
, "readahead",
4218 int, fd
, vki_loff_t
, offset
, vki_size_t
, count
);
4220 # error Unexpected word size
4222 if (!ML_(fd_allowed
)(ARG1
, "readahead", tid
, False
))
4223 SET_STATUS_Failure( VKI_EBADF
);
4226 /* ---------------------------------------------------------------------
4228 ------------------------------------------------------------------ */
4232 PRINT( "sys_sigpending ( %#" FMT_REGWORD
"x )", ARG1
);
4233 PRE_REG_READ1(long, "sigpending", vki_old_sigset_t
*, set
);
4234 PRE_MEM_WRITE( "sigpending(set)", ARG1
, sizeof(vki_old_sigset_t
));
4236 POST(sys_sigpending
)
4238 POST_MEM_WRITE( ARG1
, sizeof(vki_old_sigset_t
) ) ;
4241 // This syscall is not used on amd64/Linux -- it only provides
4242 // sys_rt_sigprocmask, which uses sigset_t rather than old_sigset_t.
4243 // This wrapper is only suitable for 32-bit architectures.
4244 // (XXX: so how is it that PRE(sys_sigpending) above doesn't need
4245 // conditional compilation like this?)
4246 #if defined(VGP_x86_linux) || defined(VGP_ppc32_linux) \
4247 || defined(VGP_arm_linux) || defined(VGP_mips32_linux) \
4248 || defined(VGP_nanomips_linux)
4249 PRE(sys_sigprocmask
)
4251 vki_old_sigset_t
* set
;
4252 vki_old_sigset_t
* oldset
;
4253 vki_sigset_t bigger_set
;
4254 vki_sigset_t bigger_oldset
;
4256 PRINT("sys_sigprocmask ( %ld, %#lx, %#lx )", SARG1
, ARG2
, ARG3
);
4257 PRE_REG_READ3(long, "sigprocmask",
4258 int, how
, vki_old_sigset_t
*, set
, vki_old_sigset_t
*, oldset
);
4260 PRE_MEM_READ( "sigprocmask(set)", ARG2
, sizeof(vki_old_sigset_t
));
4262 PRE_MEM_WRITE( "sigprocmask(oldset)", ARG3
, sizeof(vki_old_sigset_t
));
4264 // Nb: We must convert the smaller vki_old_sigset_t params into bigger
4265 // vki_sigset_t params.
4266 set
= (vki_old_sigset_t
*)(Addr
)ARG2
;
4267 oldset
= (vki_old_sigset_t
*)(Addr
)ARG3
;
4269 VG_(memset
)(&bigger_set
, 0, sizeof(vki_sigset_t
));
4270 VG_(memset
)(&bigger_oldset
, 0, sizeof(vki_sigset_t
));
4272 bigger_set
.sig
[0] = *(vki_old_sigset_t
*)set
;
4274 SET_STATUS_from_SysRes(
4275 VG_(do_sys_sigprocmask
) ( tid
, ARG1
/*how*/,
4276 set
? &bigger_set
: NULL
,
4277 oldset
? &bigger_oldset
: NULL
)
4281 *oldset
= bigger_oldset
.sig
[0];
4284 *flags
|= SfPollAfter
;
4286 POST(sys_sigprocmask
)
4289 if (RES
== 0 && ARG3
!= 0)
4290 POST_MEM_WRITE( ARG3
, sizeof(vki_old_sigset_t
));
4293 /* Convert from non-RT to RT sigset_t's */
4295 void convert_sigset_to_rt(const vki_old_sigset_t
*oldset
, vki_sigset_t
*set
)
4297 VG_(sigemptyset
)(set
);
4298 set
->sig
[0] = *oldset
;
4302 vki_sigaction_toK_t
new, *newp
;
4303 vki_sigaction_fromK_t old
, *oldp
;
4305 PRINT("sys_sigaction ( %ld, %#lx, %#lx )", SARG1
, ARG2
, ARG3
);
4306 PRE_REG_READ3(int, "sigaction",
4307 int, signum
, const struct old_sigaction
*, act
,
4308 struct old_sigaction
*, oldact
);
4313 struct vki_old_sigaction
*sa
= (struct vki_old_sigaction
*)(Addr
)ARG2
;
4314 PRE_MEM_READ( "sigaction(act->sa_handler)", (Addr
)&sa
->ksa_handler
, sizeof(sa
->ksa_handler
));
4315 PRE_MEM_READ( "sigaction(act->sa_mask)", (Addr
)&sa
->sa_mask
, sizeof(sa
->sa_mask
));
4316 PRE_MEM_READ( "sigaction(act->sa_flags)", (Addr
)&sa
->sa_flags
, sizeof(sa
->sa_flags
));
4317 if (ML_(safe_to_deref
)(sa
,sizeof(struct vki_old_sigaction
))
4318 && (sa
->sa_flags
& VKI_SA_RESTORER
))
4319 PRE_MEM_READ( "sigaction(act->sa_restorer)", (Addr
)&sa
->sa_restorer
, sizeof(sa
->sa_restorer
));
4323 PRE_MEM_WRITE( "sigaction(oldact)", ARG3
, sizeof(struct vki_old_sigaction
));
4327 /* If the new or old sigaction is not NULL, but the structs
4328 aren't accessible then sigaction returns EFAULT and we cannot
4329 use either struct for our own bookkeeping. Just fail early. */
4331 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG2
,
4332 sizeof(struct vki_old_sigaction
))) {
4333 VG_(umsg
)("Warning: bad act handler address %p in sigaction()\n",
4334 (void *)(Addr
)ARG2
);
4335 SET_STATUS_Failure ( VKI_EFAULT
);
4336 } else if ((ARG3
!= 0
4337 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG3
,
4338 sizeof(struct vki_old_sigaction
)))) {
4339 VG_(umsg
)("Warning: bad oldact handler address %p in sigaction()\n",
4340 (void *)(Addr
)ARG3
);
4341 SET_STATUS_Failure ( VKI_EFAULT
);
4344 struct vki_old_sigaction
*oldnew
=
4345 (struct vki_old_sigaction
*)(Addr
)ARG2
;
4347 new.ksa_handler
= oldnew
->ksa_handler
;
4348 new.sa_flags
= oldnew
->sa_flags
;
4349 new.sa_restorer
= oldnew
->sa_restorer
;
4350 convert_sigset_to_rt(&oldnew
->sa_mask
, &new.sa_mask
);
4354 SET_STATUS_from_SysRes( VG_(do_sys_sigaction
)(ARG1
, newp
, oldp
) );
4356 if (ARG3
!= 0 && SUCCESS
&& RES
== 0) {
4357 struct vki_old_sigaction
*oldold
=
4358 (struct vki_old_sigaction
*)(Addr
)ARG3
;
4360 oldold
->ksa_handler
= oldp
->ksa_handler
;
4361 oldold
->sa_flags
= oldp
->sa_flags
;
4362 oldold
->sa_restorer
= oldp
->sa_restorer
;
4363 oldold
->sa_mask
= oldp
->sa_mask
.sig
[0];
4370 if (RES
== 0 && ARG3
!= 0)
4371 POST_MEM_WRITE( ARG3
, sizeof(struct vki_old_sigaction
));
4377 PRINT("sys_signalfd ( %d, %#" FMT_REGWORD
"x, %llu )", (Int
)ARG1
, ARG2
,
4379 PRE_REG_READ3(long, "sys_signalfd",
4380 int, fd
, vki_sigset_t
*, sigmask
, vki_size_t
, sigsetsize
);
4381 PRE_MEM_READ( "signalfd(sigmask)", ARG2
, sizeof(vki_sigset_t
) );
4382 if ((int)ARG1
!= -1 && !ML_(fd_allowed
)(ARG1
, "signalfd", tid
, False
))
4383 SET_STATUS_Failure( VKI_EBADF
);
4387 if (!ML_(fd_allowed
)(RES
, "signalfd", tid
, True
)) {
4389 SET_STATUS_Failure( VKI_EMFILE
);
4391 if (VG_(clo_track_fds
))
4392 ML_(record_fd_open_nameless
) (tid
, RES
);
4398 PRINT("sys_signalfd4 ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld )",
4399 SARG1
, ARG2
, ARG3
, SARG4
);
4400 PRE_REG_READ4(long, "sys_signalfd4",
4401 int, fd
, vki_sigset_t
*, sigmask
, vki_size_t
, sigsetsize
, int, flags
);
4402 PRE_MEM_READ( "signalfd(sigmask)", ARG2
, sizeof(vki_sigset_t
) );
4403 if ((int)ARG1
!= -1 && !ML_(fd_allowed
)(ARG1
, "signalfd", tid
, False
))
4404 SET_STATUS_Failure( VKI_EBADF
);
4408 if (!ML_(fd_allowed
)(RES
, "signalfd4", tid
, True
)) {
4410 SET_STATUS_Failure( VKI_EMFILE
);
4412 if (VG_(clo_track_fds
))
4413 ML_(record_fd_open_nameless
) (tid
, RES
);
4418 /* ---------------------------------------------------------------------
4420 ------------------------------------------------------------------ */
4422 PRE(sys_rt_sigaction
)
4424 PRINT("sys_rt_sigaction ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %"
4425 FMT_REGWORD
"u )", SARG1
, ARG2
, ARG3
, ARG4
);
4426 PRE_REG_READ4(long, "rt_sigaction",
4427 int, signum
, const struct sigaction
*, act
,
4428 struct sigaction
*, oldact
, vki_size_t
, sigsetsize
);
4431 vki_sigaction_toK_t
*sa
= (vki_sigaction_toK_t
*)(Addr
)ARG2
;
4432 PRE_MEM_READ( "rt_sigaction(act->sa_handler)", (Addr
)&sa
->ksa_handler
, sizeof(sa
->ksa_handler
));
4433 PRE_MEM_READ( "rt_sigaction(act->sa_mask)", (Addr
)&sa
->sa_mask
, sizeof(sa
->sa_mask
));
4434 PRE_MEM_READ( "rt_sigaction(act->sa_flags)", (Addr
)&sa
->sa_flags
, sizeof(sa
->sa_flags
));
4435 if (ML_(safe_to_deref
)(sa
,sizeof(vki_sigaction_toK_t
))
4436 && (sa
->sa_flags
& VKI_SA_RESTORER
))
4437 PRE_MEM_READ( "rt_sigaction(act->sa_restorer)", (Addr
)&sa
->sa_restorer
, sizeof(sa
->sa_restorer
));
4440 PRE_MEM_WRITE( "rt_sigaction(oldact)", ARG3
, sizeof(vki_sigaction_fromK_t
));
4442 /* If the new or old sigaction is not NULL, but the structs
4443 aren't accessible then sigaction returns EFAULT and we cannot
4444 use either struct for our own bookkeeping. Just fail early. */
4446 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG2
,
4447 sizeof(vki_sigaction_toK_t
))) {
4448 VG_(umsg
)("Warning: bad act handler address %p in rt_sigaction()\n",
4449 (void *)(Addr
)ARG2
);
4450 SET_STATUS_Failure ( VKI_EFAULT
);
4451 } else if ((ARG3
!= 0
4452 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG3
,
4453 sizeof(vki_sigaction_fromK_t
)))) {
4454 VG_(umsg
)("Warning: bad oldact handler address %p in rt_sigaction()\n",
4455 (void *)(Addr
)ARG3
);
4456 SET_STATUS_Failure ( VKI_EFAULT
);
4459 // XXX: doesn't seem right to be calling do_sys_sigaction for
4460 // sys_rt_sigaction... perhaps this function should be renamed
4461 // VG_(do_sys_rt_sigaction)() --njn
4463 SET_STATUS_from_SysRes(
4464 VG_(do_sys_sigaction
)(ARG1
, (const vki_sigaction_toK_t
*)(Addr
)ARG2
,
4465 (vki_sigaction_fromK_t
*)(Addr
)ARG3
)
4469 POST(sys_rt_sigaction
)
4472 if (RES
== 0 && ARG3
!= 0)
4473 POST_MEM_WRITE( ARG3
, sizeof(vki_sigaction_fromK_t
));
4476 PRE(sys_rt_sigprocmask
)
4478 PRINT("sys_rt_sigprocmask ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %"
4479 FMT_REGWORD
"u )", SARG1
, ARG2
, ARG3
, ARG4
);
4480 PRE_REG_READ4(long, "rt_sigprocmask",
4481 int, how
, vki_sigset_t
*, set
, vki_sigset_t
*, oldset
,
4482 vki_size_t
, sigsetsize
);
4484 PRE_MEM_READ( "rt_sigprocmask(set)", ARG2
, sizeof(vki_sigset_t
));
4486 PRE_MEM_WRITE( "rt_sigprocmask(oldset)", ARG3
, sizeof(vki_sigset_t
));
4488 // Like the kernel, we fail if the sigsetsize is not exactly what we expect.
4489 // Since we want to use the set and oldset for bookkeeping we also want
4490 // to make sure they are addressable otherwise, like the kernel, we EFAULT.
4491 if (sizeof(vki_sigset_t
) != ARG4
)
4492 SET_STATUS_Failure( VKI_EINVAL
);
4494 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG2
, sizeof(vki_sigset_t
))) {
4495 VG_(dmsg
)("Warning: Bad set handler address %p in sigprocmask\n",
4496 (void *)(Addr
)ARG2
);
4497 SET_STATUS_Failure ( VKI_EFAULT
);
4500 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG3
, sizeof(vki_sigset_t
))) {
4501 VG_(dmsg
)("Warning: Bad oldset address %p in sigprocmask\n",
4502 (void *)(Addr
)ARG3
);
4503 SET_STATUS_Failure ( VKI_EFAULT
);
4507 SET_STATUS_from_SysRes(
4508 VG_(do_sys_sigprocmask
) ( tid
, ARG1
/*how*/,
4509 (vki_sigset_t
*) (Addr
)ARG2
,
4510 (vki_sigset_t
*) (Addr
)ARG3
)
4515 *flags
|= SfPollAfter
;
4517 POST(sys_rt_sigprocmask
)
4520 if (RES
== 0 && ARG3
!= 0)
4521 POST_MEM_WRITE( ARG3
, sizeof(vki_sigset_t
));
4524 PRE(sys_rt_sigpending
)
4526 PRINT( "sys_rt_sigpending ( %#" FMT_REGWORD
"x )", ARG1
);
4527 PRE_REG_READ2(long, "rt_sigpending",
4528 vki_sigset_t
*, set
, vki_size_t
, sigsetsize
);
4529 PRE_MEM_WRITE( "rt_sigpending(set)", ARG1
, sizeof(vki_sigset_t
));
4531 POST(sys_rt_sigpending
)
4533 POST_MEM_WRITE( ARG1
, sizeof(vki_sigset_t
) ) ;
4536 PRE(sys_rt_sigtimedwait
)
4538 *flags
|= SfMayBlock
;
4539 PRINT("sys_rt_sigtimedwait ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
4540 FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
4541 ARG1
, ARG2
, ARG3
, ARG4
);
4542 PRE_REG_READ4(long, "rt_sigtimedwait",
4543 const vki_sigset_t
*, set
, vki_siginfo_t
*, info
,
4544 const struct timespec
*, timeout
, vki_size_t
, sigsetsize
);
4546 PRE_MEM_READ( "rt_sigtimedwait(set)", ARG1
, sizeof(vki_sigset_t
));
4548 PRE_MEM_WRITE( "rt_sigtimedwait(info)", ARG2
, sizeof(vki_siginfo_t
) );
4550 PRE_MEM_READ( "rt_sigtimedwait(timeout)",
4551 ARG3
, sizeof(struct vki_timespec
) );
4553 POST(sys_rt_sigtimedwait
)
4556 POST_MEM_WRITE( ARG2
, sizeof(vki_siginfo_t
) );
4559 PRE(sys_rt_sigtimedwait_time64
)
4561 *flags
|= SfMayBlock
;
4562 PRINT("sys_rt_sigtimedwait_time64 ( %#" FMT_REGWORD
"x, %#"
4563 FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
4564 ARG1
, ARG2
, ARG3
, ARG4
);
4565 PRE_REG_READ4(long, "rt_sigtimedwait_time64",
4566 const vki_sigset_t
*, set
, vki_siginfo_t
*, info
,
4567 const struct vki_timespec64
*, timeout
,
4568 vki_size_t
, sigsetsize
);
4570 PRE_MEM_READ( "rt_sigtimedwait_time64(set)", ARG1
, sizeof(vki_sigset_t
) );
4572 PRE_MEM_WRITE( "rt_sigtimedwait_time64(info)", ARG2
,
4573 sizeof(vki_siginfo_t
) );
4575 pre_read_timespec64(tid
, "rt_sigtimedwait_time64(timeout)", ARG3
);
4577 POST(sys_rt_sigtimedwait_time64
)
4580 POST_MEM_WRITE( ARG2
, sizeof(vki_siginfo_t
) );
4583 PRE(sys_rt_sigqueueinfo
)
4585 PRINT("sys_rt_sigqueueinfo(%ld, %ld, %#" FMT_REGWORD
"x)",
4586 SARG1
, SARG2
, ARG3
);
4587 PRE_REG_READ3(long, "rt_sigqueueinfo",
4588 int, pid
, int, sig
, vki_siginfo_t
*, uinfo
);
4590 PRE_MEM_READ( "rt_sigqueueinfo(uinfo)", ARG3
, VKI_SI_MAX_SIZE
);
4592 POST(sys_rt_sigqueueinfo
)
4594 if (!ML_(client_signal_OK
)(ARG2
))
4595 SET_STATUS_Failure( VKI_EINVAL
);
4598 PRE(sys_rt_tgsigqueueinfo
)
4600 PRINT("sys_rt_tgsigqueueinfo(%ld, %ld, %ld, %#" FMT_REGWORD
"x)",
4601 SARG1
, SARG2
, SARG3
, ARG4
);
4602 PRE_REG_READ4(long, "rt_tgsigqueueinfo",
4603 int, tgid
, int, pid
, int, sig
, vki_siginfo_t
*, uinfo
);
4605 PRE_MEM_READ( "rt_tgsigqueueinfo(uinfo)", ARG4
, VKI_SI_MAX_SIZE
);
4608 POST(sys_rt_tgsigqueueinfo
)
4610 if (!ML_(client_signal_OK
)(ARG3
))
4611 SET_STATUS_Failure( VKI_EINVAL
);
4614 // XXX: x86-specific? The kernel prototypes for the different archs are
4615 // hard to decipher.
4616 PRE(sys_rt_sigsuspend
)
4618 /* The C library interface to sigsuspend just takes a pointer to
4619 a signal mask but this system call has two arguments - a pointer
4620 to the mask and the number of bytes used by it. The kernel insists
4621 on the size being equal to sizeof(sigset_t) however and will just
4622 return EINVAL if it isn't.
4624 *flags
|= SfMayBlock
;
4625 PRINT("sys_rt_sigsuspend ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
4627 PRE_REG_READ2(int, "rt_sigsuspend", vki_sigset_t
*, mask
, vki_size_t
, size
)
4628 if (ARG1
!= (Addr
)NULL
) {
4629 PRE_MEM_READ( "rt_sigsuspend(mask)", ARG1
, sizeof(vki_sigset_t
) );
4630 if (ML_(safe_to_deref
)((vki_sigset_t
*) (Addr
)ARG1
, sizeof(vki_sigset_t
))) {
4631 VG_(sigdelset
)((vki_sigset_t
*) (Addr
)ARG1
, VG_SIGVGKILL
);
4632 /* We cannot mask VG_SIGVGKILL, as otherwise this thread would not
4633 be killable by VG_(nuke_all_threads_except).
4634 We thus silently ignore the user request to mask this signal.
4635 Note that this is similar to what is done for e.g.
4636 sigprocmask (see m_signals.c calculate_SKSS_from_SCSS). */
4638 SET_STATUS_Failure(VKI_EFAULT
);
4643 /* ---------------------------------------------------------------------
4644 linux msg* wrapper helpers
4645 ------------------------------------------------------------------ */
4648 ML_(linux_PRE_sys_msgsnd
) ( ThreadId tid
,
4649 UWord arg0
, UWord arg1
, UWord arg2
, UWord arg3
)
4651 /* int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg); */
4652 struct vki_msgbuf
*msgp
= (struct vki_msgbuf
*)arg1
;
4653 PRE_MEM_READ( "msgsnd(msgp->mtype)", (Addr
)&msgp
->mtype
, sizeof(msgp
->mtype
) );
4654 PRE_MEM_READ( "msgsnd(msgp->mtext)", (Addr
)&msgp
->mtext
, arg2
);
4658 ML_(linux_PRE_sys_msgrcv
) ( ThreadId tid
,
4659 UWord arg0
, UWord arg1
, UWord arg2
,
4660 UWord arg3
, UWord arg4
)
4662 /* ssize_t msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz,
4663 long msgtyp, int msgflg); */
4664 struct vki_msgbuf
*msgp
= (struct vki_msgbuf
*)arg1
;
4665 PRE_MEM_WRITE( "msgrcv(msgp->mtype)", (Addr
)&msgp
->mtype
, sizeof(msgp
->mtype
) );
4666 PRE_MEM_WRITE( "msgrcv(msgp->mtext)", (Addr
)&msgp
->mtext
, arg2
);
4669 ML_(linux_POST_sys_msgrcv
) ( ThreadId tid
,
4671 UWord arg0
, UWord arg1
, UWord arg2
,
4672 UWord arg3
, UWord arg4
)
4674 struct vki_msgbuf
*msgp
= (struct vki_msgbuf
*)arg1
;
4675 POST_MEM_WRITE( (Addr
)&msgp
->mtype
, sizeof(msgp
->mtype
) );
4676 POST_MEM_WRITE( (Addr
)&msgp
->mtext
, res
);
4680 ML_(linux_PRE_sys_msgctl
) ( ThreadId tid
,
4681 UWord arg0
, UWord arg1
, UWord arg2
)
4683 /* int msgctl(int msqid, int cmd, struct msqid_ds *buf); */
4684 switch (arg1
/* cmd */) {
4687 case VKI_IPC_INFO
|VKI_IPC_64
:
4688 case VKI_MSG_INFO
|VKI_IPC_64
:
4689 PRE_MEM_WRITE( "msgctl(IPC_INFO, buf)",
4690 arg2
, sizeof(struct vki_msginfo
) );
4694 PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)",
4695 arg2
, sizeof(struct vki_msqid_ds
) );
4697 case VKI_IPC_STAT
|VKI_IPC_64
:
4698 case VKI_MSG_STAT
|VKI_IPC_64
:
4699 PRE_MEM_WRITE( "msgctl(IPC_STAT, arg.buf)",
4700 arg2
, sizeof(struct vki_msqid64_ds
) );
4703 PRE_MEM_READ( "msgctl(IPC_SET, arg.buf)",
4704 arg2
, sizeof(struct vki_msqid_ds
) );
4706 case VKI_IPC_SET
|VKI_IPC_64
:
4707 PRE_MEM_READ( "msgctl(IPC_SET, arg.buf)",
4708 arg2
, sizeof(struct vki_msqid64_ds
) );
4713 ML_(linux_POST_sys_msgctl
) ( ThreadId tid
,
4715 UWord arg0
, UWord arg1
, UWord arg2
)
4717 switch (arg1
/* cmd */) {
4720 case VKI_IPC_INFO
|VKI_IPC_64
:
4721 case VKI_MSG_INFO
|VKI_IPC_64
:
4722 POST_MEM_WRITE( arg2
, sizeof(struct vki_msginfo
) );
4726 POST_MEM_WRITE( arg2
, sizeof(struct vki_msqid_ds
) );
4728 case VKI_IPC_STAT
|VKI_IPC_64
:
4729 case VKI_MSG_STAT
|VKI_IPC_64
:
4730 POST_MEM_WRITE( arg2
, sizeof(struct vki_msqid64_ds
) );
4735 /* ---------------------------------------------------------------------
4736 Generic handler for sys_ipc
4737 Depending on the platform, some syscalls (e.g. semctl, semop, ...)
4738 are either direct system calls, or are all implemented via sys_ipc.
4739 ------------------------------------------------------------------ */
4741 static Addr
deref_Addr ( ThreadId tid
, Addr a
, const HChar
* s
)
4743 Addr
* a_p
= (Addr
*)a
;
4744 PRE_MEM_READ( s
, (Addr
)a_p
, sizeof(Addr
) );
4748 static Bool
semctl_cmd_has_4args (UWord cmd
)
4750 switch (cmd
& ~VKI_IPC_64
)
4767 PRINT("sys_ipc ( %lu, %ld, %ld, %ld, %#lx, %ld )",
4768 ARG1
, SARG2
, SARG3
, SARG4
, ARG5
, SARG6
);
4770 switch (ARG1
/* call */) {
4772 PRE_REG_READ5(int, "ipc",
4773 vki_uint
, call
, int, first
, int, second
, int, third
,
4775 ML_(generic_PRE_sys_semop
)( tid
, ARG2
, ARG5
, ARG3
);
4776 *flags
|= SfMayBlock
;
4779 PRE_REG_READ4(int, "ipc",
4780 vki_uint
, call
, int, first
, int, second
, int, third
);
4784 PRE_REG_READ5(int, "ipc",
4785 vki_uint
, call
, int, first
, int, second
, int, third
,
4788 if (semctl_cmd_has_4args(ARG4
))
4789 arg
= deref_Addr( tid
, ARG5
, "semctl(arg)" );
4792 ML_(generic_PRE_sys_semctl
)( tid
, ARG2
, ARG3
, ARG4
, arg
);
4795 case VKI_SEMTIMEDOP
:
4796 #ifdef VGP_s390x_linux
4797 /* On s390x Linux platforms the sys_ipc semtimedop call has four instead
4798 of five parameters, where the timeout is passed in the third instead of
4800 PRE_REG_READ5(int, "ipc",
4801 vki_uint
, call
, int, first
, int, second
, long, third
,
4803 ML_(generic_PRE_sys_semtimedop
)( tid
, ARG2
, ARG5
, ARG3
, ARG4
);
4805 PRE_REG_READ6(int, "ipc",
4806 vki_uint
, call
, int, first
, int, second
, int, third
,
4807 void *, ptr
, long, fifth
);
4808 ML_(generic_PRE_sys_semtimedop
)( tid
, ARG2
, ARG5
, ARG3
, ARG6
);
4810 *flags
|= SfMayBlock
;
4813 PRE_REG_READ5(int, "ipc",
4814 vki_uint
, call
, int, first
, int, second
, int, third
,
4816 ML_(linux_PRE_sys_msgsnd
)( tid
, ARG2
, ARG5
, ARG3
, ARG4
);
4817 if ((ARG4
& VKI_IPC_NOWAIT
) == 0)
4818 *flags
|= SfMayBlock
;
4822 PRE_REG_READ5(int, "ipc",
4823 vki_uint
, call
, int, first
, int, second
, int, third
,
4828 msgp
= deref_Addr( tid
, (Addr
) (&((struct vki_ipc_kludge
*)(Addr
)ARG5
)->msgp
),
4830 msgtyp
= deref_Addr( tid
,
4831 (Addr
) (&((struct vki_ipc_kludge
*)(Addr
)ARG5
)->msgtyp
),
4834 ML_(linux_PRE_sys_msgrcv
)( tid
, ARG2
, msgp
, ARG3
, msgtyp
, ARG4
);
4836 if ((ARG4
& VKI_IPC_NOWAIT
) == 0)
4837 *flags
|= SfMayBlock
;
4841 PRE_REG_READ3(int, "ipc", vki_uint
, call
, int, first
, int, second
);
4844 PRE_REG_READ5(int, "ipc",
4845 vki_uint
, call
, int, first
, int, second
, int, third
,
4847 ML_(linux_PRE_sys_msgctl
)( tid
, ARG2
, ARG3
, ARG5
);
4851 PRE_REG_READ5(int, "ipc",
4852 vki_uint
, call
, int, first
, int, second
, int, third
,
4855 PRE_MEM_WRITE( "shmat(raddr)", ARG4
, sizeof(Addr
) );
4856 w
= ML_(generic_PRE_sys_shmat
)( tid
, ARG2
, ARG5
, ARG3
);
4858 SET_STATUS_Failure( VKI_EINVAL
);
4864 PRE_REG_READ5(int, "ipc",
4865 vki_uint
, call
, int, first
, int, second
, int, third
,
4867 if (!ML_(generic_PRE_sys_shmdt
)(tid
, ARG5
))
4868 SET_STATUS_Failure( VKI_EINVAL
);
4871 PRE_REG_READ4(int, "ipc",
4872 vki_uint
, call
, int, first
, int, second
, int, third
);
4873 if (ARG4
& VKI_SHM_HUGETLB
) {
4874 static Bool warning_given
= False
;
4875 ARG4
&= ~VKI_SHM_HUGETLB
;
4876 if (!warning_given
) {
4877 warning_given
= True
;
4879 "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n");
4883 case VKI_SHMCTL
: /* IPCOP_shmctl */
4884 PRE_REG_READ5(int, "ipc",
4885 vki_uint
, call
, int, first
, int, second
, int, third
,
4887 ML_(generic_PRE_sys_shmctl
)( tid
, ARG2
, ARG3
, ARG5
);
4890 VG_(message
)(Vg_DebugMsg
, "FATAL: unhandled syscall(ipc) %lu\n", ARG1
);
4891 VG_(core_panic
)("... bye!\n");
4892 break; /*NOTREACHED*/
4899 switch (ARG1
/* call */) {
4906 if (semctl_cmd_has_4args(ARG4
))
4907 arg
= deref_Addr( tid
, ARG5
, "semctl(arg)" );
4910 ML_(generic_POST_sys_semctl
)( tid
, RES
, ARG2
, ARG3
, ARG4
, arg
);
4913 case VKI_SEMTIMEDOP
:
4921 msgp
= deref_Addr( tid
,
4922 (Addr
) (&((struct vki_ipc_kludge
*)(Addr
)ARG5
)->msgp
),
4924 msgtyp
= deref_Addr( tid
,
4925 (Addr
) (&((struct vki_ipc_kludge
*)(Addr
)ARG5
)->msgtyp
),
4928 ML_(linux_POST_sys_msgrcv
)( tid
, RES
, ARG2
, msgp
, ARG3
, msgtyp
, ARG4
);
4934 ML_(linux_POST_sys_msgctl
)( tid
, RES
, ARG2
, ARG3
, ARG5
);
4940 /* force readability. before the syscall it is
4941 * indeed uninitialized, as can be seen in
4942 * glibc/sysdeps/unix/sysv/linux/shmat.c */
4943 POST_MEM_WRITE( ARG4
, sizeof( Addr
) );
4945 addr
= deref_Addr ( tid
, ARG4
, "shmat(addr)" );
4946 ML_(generic_POST_sys_shmat
)( tid
, addr
, ARG2
, ARG5
, ARG3
);
4950 ML_(generic_POST_sys_shmdt
)( tid
, RES
, ARG5
);
4955 ML_(generic_POST_sys_shmctl
)( tid
, RES
, ARG2
, ARG3
, ARG5
);
4958 VG_(message
)(Vg_DebugMsg
,
4959 "FATAL: unhandled syscall(ipc) %lu\n",
4961 VG_(core_panic
)("... bye!\n");
4962 break; /*NOTREACHED*/
4969 PRINT("sys_semget ( %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
);
4970 PRE_REG_READ3(long, "semget", vki_key_t
, key
, int, nsems
, int, semflg
);
4975 *flags
|= SfMayBlock
;
4976 PRINT("sys_semop ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
4978 PRE_REG_READ3(long, "semop",
4979 int, semid
, struct sembuf
*, sops
, unsigned, nsoops
);
4980 ML_(generic_PRE_sys_semop
)(tid
, ARG1
,ARG2
,ARG3
);
4985 switch (ARG3
& ~VKI_IPC_64
) {
4988 PRINT("sys_semctl ( %ld, %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
,
4990 PRE_REG_READ4(long, "semctl",
4991 int, semid
, int, semnum
, int, cmd
, struct seminfo
*, arg
);
4996 PRINT("sys_semctl ( %ld, %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
,
4998 PRE_REG_READ4(long, "semctl",
4999 int, semid
, int, semnum
, int, cmd
, struct semid_ds
*, arg
);
5003 PRINT("sys_semctl ( %ld, %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
,
5005 PRE_REG_READ4(long, "semctl",
5006 int, semid
, int, semnum
, int, cmd
, unsigned short *, arg
);
5009 PRINT("sys_semctl ( %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
);
5010 PRE_REG_READ3(long, "semctl",
5011 int, semid
, int, semnum
, int, cmd
);
5014 #ifdef VGP_amd64_linux
5015 ML_(generic_PRE_sys_semctl
)(tid
, ARG1
,ARG2
,ARG3
|VKI_IPC_64
,ARG4
);
5017 ML_(generic_PRE_sys_semctl
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
);
5023 #ifdef VGP_amd64_linux
5024 ML_(generic_POST_sys_semctl
)(tid
, RES
,ARG1
,ARG2
,ARG3
|VKI_IPC_64
,ARG4
);
5026 ML_(generic_POST_sys_semctl
)(tid
, RES
,ARG1
,ARG2
,ARG3
,ARG4
);
5032 *flags
|= SfMayBlock
;
5033 PRINT("sys_semtimedop ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#"
5034 FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
, ARG4
);
5035 PRE_REG_READ4(long, "semtimedop",
5036 int, semid
, struct sembuf
*, sops
, unsigned, nsoops
,
5037 struct timespec
*, timeout
);
5038 ML_(generic_PRE_sys_semtimedop
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
);
5041 PRE(sys_semtimedop_time64
)
5043 *flags
|= SfMayBlock
;
5044 PRINT("sys_semtimedop_time64 ( %ld, %#" FMT_REGWORD
"x, %"
5045 FMT_REGWORD
"u, %#" FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
, ARG4
);
5046 PRE_REG_READ4(long, "semtimedop_time64",
5047 int, semid
, struct sembuf
*, sops
, unsigned, nsoops
,
5048 struct vki_timespec64
*, timeout
);
5049 PRE_MEM_READ( "semtimedop_time64(sops)", ARG1
,
5050 ARG2
* sizeof(struct vki_sembuf
) );
5052 pre_read_timespec64(tid
, "semtimedop_time64(timeout)", ARG3
);
5057 PRINT("sys_msgget ( %ld, %ld )", SARG1
, SARG2
);
5058 PRE_REG_READ2(long, "msgget", vki_key_t
, key
, int, msgflg
);
5063 PRINT("sys_msgsnd ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld )",
5064 SARG1
, ARG2
, ARG3
, SARG4
);
5065 PRE_REG_READ4(long, "msgsnd",
5066 int, msqid
, struct msgbuf
*, msgp
, vki_size_t
, msgsz
, int, msgflg
);
5067 ML_(linux_PRE_sys_msgsnd
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
);
5068 if ((ARG4
& VKI_IPC_NOWAIT
) == 0)
5069 *flags
|= SfMayBlock
;
5074 PRINT("sys_msgrcv ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld, %ld )",
5075 SARG1
, ARG2
, ARG3
, SARG4
, SARG5
);
5076 PRE_REG_READ5(long, "msgrcv",
5077 int, msqid
, struct msgbuf
*, msgp
, vki_size_t
, msgsz
,
5078 long, msgytp
, int, msgflg
);
5079 ML_(linux_PRE_sys_msgrcv
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
5080 if ((ARG5
& VKI_IPC_NOWAIT
) == 0)
5081 *flags
|= SfMayBlock
;
5085 ML_(linux_POST_sys_msgrcv
)(tid
, RES
,ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
5090 PRINT("sys_msgctl ( %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
, ARG3
);
5091 PRE_REG_READ3(long, "msgctl",
5092 int, msqid
, int, cmd
, struct msqid_ds
*, buf
);
5093 ML_(linux_PRE_sys_msgctl
)(tid
, ARG1
,ARG2
,ARG3
);
5098 ML_(linux_POST_sys_msgctl
)(tid
, RES
,ARG1
,ARG2
,ARG3
);
5103 PRINT("sys_shmget ( %ld, %" FMT_REGWORD
"u, %ld )", SARG1
, ARG2
, SARG3
);
5104 PRE_REG_READ3(long, "shmget", vki_key_t
, key
, vki_size_t
, size
, int, shmflg
);
5105 if (ARG3
& VKI_SHM_HUGETLB
) {
5106 static Bool warning_given
= False
;
5107 ARG3
&= ~VKI_SHM_HUGETLB
;
5108 if (!warning_given
) {
5109 warning_given
= True
;
5111 "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n");
5119 PRINT("sys_shmat ( %ld, %#" FMT_REGWORD
"x, %ld )", SARG1
, ARG2
, SARG3
);
5120 PRE_REG_READ3(long, "shmat",
5121 int, shmid
, const void *, shmaddr
, int, shmflg
);
5122 #if defined(VGP_arm_linux)
5123 /* Round the attach address down to an VKI_SHMLBA boundary if the
5124 client requested rounding. See #222545. This is necessary only
5125 on arm-linux because VKI_SHMLBA is 4 * VKI_PAGE size; on all
5126 other linux targets it is the same as the page size. */
5127 if (ARG3
& VKI_SHM_RND
)
5128 ARG2
= VG_ROUNDDN(ARG2
, VKI_SHMLBA
);
5130 arg2tmp
= ML_(generic_PRE_sys_shmat
)(tid
, ARG1
,ARG2
,ARG3
);
5132 SET_STATUS_Failure( VKI_EINVAL
);
5134 ARG2
= arg2tmp
; // used in POST
5139 ML_(generic_POST_sys_shmat
)(tid
, RES
,ARG1
,ARG2
,ARG3
);
5144 PRINT("sys_shmdt ( %#" FMT_REGWORD
"x )",ARG1
);
5145 PRE_REG_READ1(long, "shmdt", const void *, shmaddr
);
5146 if (!ML_(generic_PRE_sys_shmdt
)(tid
, ARG1
))
5147 SET_STATUS_Failure( VKI_EINVAL
);
5152 ML_(generic_POST_sys_shmdt
)(tid
, RES
,ARG1
);
5157 PRINT("sys_shmctl ( %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
, ARG3
);
5158 PRE_REG_READ3(long, "shmctl",
5159 int, shmid
, int, cmd
, struct shmid_ds
*, buf
);
5160 #if defined(VGP_amd64_linux) || defined(VGP_arm64_linux)
5161 ML_(generic_PRE_sys_shmctl
)(tid
, ARG1
,ARG2
|VKI_IPC_64
,ARG3
);
5163 ML_(generic_PRE_sys_shmctl
)(tid
, ARG1
,ARG2
,ARG3
);
5169 #if defined(VGP_amd64_linux) || defined(VGP_arm64_linux)
5170 ML_(generic_POST_sys_shmctl
)(tid
, RES
,ARG1
,ARG2
|VKI_IPC_64
,ARG3
);
5172 ML_(generic_POST_sys_shmctl
)(tid
, RES
,ARG1
,ARG2
,ARG3
);
5177 /* ---------------------------------------------------------------------
5178 Generic handler for sys_socketcall
5179 Depending on the platform, some socket related syscalls (e.g. socketpair,
5181 are either direct system calls, or are all implemented via sys_socketcall.
5182 ------------------------------------------------------------------ */
5183 #ifdef __NR_socketcall
5186 # define ARG2_0 (((UWord*)(Addr)ARG2)[0])
5187 # define ARG2_1 (((UWord*)(Addr)ARG2)[1])
5188 # define ARG2_2 (((UWord*)(Addr)ARG2)[2])
5189 # define ARG2_3 (((UWord*)(Addr)ARG2)[3])
5190 # define ARG2_4 (((UWord*)(Addr)ARG2)[4])
5191 # define ARG2_5 (((UWord*)(Addr)ARG2)[5])
5193 // call PRE_MEM_READ and check for EFAULT result.
5194 #define PRE_MEM_READ_ef(msg, arg, size) \
5196 PRE_MEM_READ( msg, arg, size); \
5197 if (!ML_(valid_client_addr)(arg, size, tid, NULL)) { \
5198 SET_STATUS_Failure( VKI_EFAULT ); \
5203 *flags
|= SfMayBlock
;
5204 PRINT("sys_socketcall ( %ld, %#lx )", SARG1
, ARG2
);
5205 PRE_REG_READ2(long, "socketcall", int, call
, unsigned long *, args
);
5207 switch (ARG1
/* request */) {
5209 case VKI_SYS_SOCKETPAIR
:
5210 /* int socketpair(int d, int type, int protocol, int sv[2]); */
5211 PRE_MEM_READ_ef( "socketcall.socketpair(args)", ARG2
, 4*sizeof(Addr
) );
5212 ML_(generic_PRE_sys_socketpair
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
);
5215 case VKI_SYS_SOCKET
:
5216 /* int socket(int domain, int type, int protocol); */
5217 PRE_MEM_READ_ef( "socketcall.socket(args)", ARG2
, 3*sizeof(Addr
) );
5221 /* int bind(int sockfd, struct sockaddr *my_addr,
5223 PRE_MEM_READ_ef( "socketcall.bind(args)", ARG2
, 3*sizeof(Addr
) );
5224 ML_(generic_PRE_sys_bind
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
5227 case VKI_SYS_LISTEN
:
5228 /* int listen(int s, int backlog); */
5229 PRE_MEM_READ_ef( "socketcall.listen(args)", ARG2
, 2*sizeof(Addr
) );
5232 case VKI_SYS_ACCEPT
:
5233 /* int accept(int s, struct sockaddr *addr, int *addrlen); */
5234 PRE_MEM_READ_ef( "socketcall.accept(args)", ARG2
, 3*sizeof(Addr
) );
5235 ML_(generic_PRE_sys_accept
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
5238 case VKI_SYS_ACCEPT4
:
5239 /* int accept4(int s, struct sockaddr *addr, int *addrlen, int flags); */
5240 PRE_MEM_READ_ef( "socketcall.accept4(args)", ARG2
, 4*sizeof(Addr
) );
5241 ML_(generic_PRE_sys_accept
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
5244 case VKI_SYS_SENDTO
:
5245 /* int sendto(int s, const void *msg, int len,
5247 const struct sockaddr *to, int tolen); */
5248 PRE_MEM_READ_ef( "socketcall.sendto(args)", ARG2
, 6*sizeof(Addr
) );
5249 ML_(generic_PRE_sys_sendto
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
,
5250 ARG2_3
, ARG2_4
, ARG2_5
);
5254 /* int send(int s, const void *msg, size_t len, int flags); */
5255 PRE_MEM_READ_ef( "socketcall.send(args)", ARG2
, 4*sizeof(Addr
) );
5256 ML_(generic_PRE_sys_send
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
5259 case VKI_SYS_RECVFROM
:
5260 /* int recvfrom(int s, void *buf, int len, unsigned int flags,
5261 struct sockaddr *from, int *fromlen); */
5262 PRE_MEM_READ_ef( "socketcall.recvfrom(args)", ARG2
, 6*sizeof(Addr
) );
5263 ML_(generic_PRE_sys_recvfrom
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
,
5264 ARG2_3
, ARG2_4
, ARG2_5
);
5268 /* int recv(int s, void *buf, int len, unsigned int flags); */
5270 The recv call is normally used only on a connected socket
5271 (see connect(2)) and is identical to recvfrom with a NULL
5274 PRE_MEM_READ_ef( "socketcall.recv(args)", ARG2
, 4*sizeof(Addr
) );
5275 ML_(generic_PRE_sys_recv
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
5278 case VKI_SYS_CONNECT
:
5279 /* int connect(int sockfd,
5280 struct sockaddr *serv_addr, int addrlen ); */
5281 PRE_MEM_READ_ef( "socketcall.connect(args)", ARG2
, 3*sizeof(Addr
) );
5282 ML_(generic_PRE_sys_connect
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
5285 case VKI_SYS_SETSOCKOPT
:
5286 /* int setsockopt(int s, int level, int optname,
5287 const void *optval, int optlen); */
5288 PRE_MEM_READ_ef( "socketcall.setsockopt(args)", ARG2
, 5*sizeof(Addr
) );
5289 ML_(linux_PRE_sys_setsockopt
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
,
5293 case VKI_SYS_GETSOCKOPT
:
5294 /* int getsockopt(int s, int level, int optname,
5295 void *optval, socklen_t *optlen); */
5296 PRE_MEM_READ_ef( "socketcall.getsockopt(args)", ARG2
, 5*sizeof(Addr
) );
5297 ML_(linux_PRE_sys_getsockopt
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
,
5301 case VKI_SYS_GETSOCKNAME
:
5302 /* int getsockname(int s, struct sockaddr* name, int* namelen) */
5303 PRE_MEM_READ_ef( "socketcall.getsockname(args)", ARG2
, 3*sizeof(Addr
) );
5304 ML_(generic_PRE_sys_getsockname
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
5307 case VKI_SYS_GETPEERNAME
:
5308 /* int getpeername(int s, struct sockaddr* name, int* namelen) */
5309 PRE_MEM_READ_ef( "socketcall.getpeername(args)", ARG2
, 3*sizeof(Addr
) );
5310 ML_(generic_PRE_sys_getpeername
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
5313 case VKI_SYS_SHUTDOWN
:
5314 /* int shutdown(int s, int how); */
5315 PRE_MEM_READ_ef( "socketcall.shutdown(args)", ARG2
, 2*sizeof(Addr
) );
5318 case VKI_SYS_SENDMSG
:
5319 /* int sendmsg(int s, const struct msghdr *msg, int flags); */
5320 PRE_MEM_READ_ef( "socketcall.sendmsg(args)", ARG2
, 3*sizeof(Addr
) );
5321 ML_(generic_PRE_sys_sendmsg
)( tid
, "msg",
5322 (struct vki_msghdr
*)(Addr
)ARG2_1
);
5325 case VKI_SYS_RECVMSG
:
5326 /* int recvmsg(int s, struct msghdr *msg, int flags); */
5327 PRE_MEM_READ_ef("socketcall.recvmsg(args)", ARG2
, 3*sizeof(Addr
) );
5328 ML_(generic_PRE_sys_recvmsg
)( tid
, "msg",
5329 (struct vki_msghdr
*)(Addr
)ARG2_1
);
5332 case VKI_SYS_RECVMMSG
:
5333 /* int recvmmsg(int s, struct mmsghdr *mmsg, int vlen, int flags,
5334 struct timespec *timeout); */
5335 PRE_MEM_READ_ef("socketcall.recvmmsg(args)", ARG2
, 5*sizeof(Addr
) );
5336 ML_(linux_PRE_sys_recvmmsg
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
,
5340 case VKI_SYS_SENDMMSG
:
5341 /* int sendmmsg(int s, struct mmsghdr *mmsg, int vlen, int flags); */
5342 PRE_MEM_READ_ef("socketcall.sendmmsg(args)", ARG2
, 4*sizeof(Addr
) );
5343 ML_(linux_PRE_sys_sendmmsg
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
);
5347 VG_(message
)(Vg_DebugMsg
,"Warning: unhandled socketcall 0x%lx\n",ARG1
);
5348 SET_STATUS_Failure( VKI_EINVAL
);
5359 POST(sys_socketcall
)
5361 # define ARG2_0 (((UWord*)(Addr)ARG2)[0])
5362 # define ARG2_1 (((UWord*)(Addr)ARG2)[1])
5363 # define ARG2_2 (((UWord*)(Addr)ARG2)[2])
5364 # define ARG2_3 (((UWord*)(Addr)ARG2)[3])
5365 # define ARG2_4 (((UWord*)(Addr)ARG2)[4])
5366 # define ARG2_5 (((UWord*)(Addr)ARG2)[5])
5370 switch (ARG1
/* request */) {
5372 case VKI_SYS_SOCKETPAIR
:
5373 r
= ML_(generic_POST_sys_socketpair
)(
5374 tid
, VG_(mk_SysRes_Success
)(RES
),
5375 ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
5377 SET_STATUS_from_SysRes(r
);
5380 case VKI_SYS_SOCKET
:
5381 r
= ML_(generic_POST_sys_socket
)( tid
, VG_(mk_SysRes_Success
)(RES
) );
5382 SET_STATUS_from_SysRes(r
);
5386 /* int bind(int sockfd, struct sockaddr *my_addr,
5390 case VKI_SYS_LISTEN
:
5391 /* int listen(int s, int backlog); */
5394 case VKI_SYS_ACCEPT
:
5395 case VKI_SYS_ACCEPT4
:
5396 /* int accept(int s, struct sockaddr *addr, int *addrlen); */
5397 /* int accept4(int s, struct sockaddr *addr, int *addrlen, int flags); */
5398 r
= ML_(generic_POST_sys_accept
)( tid
, VG_(mk_SysRes_Success
)(RES
),
5399 ARG2_0
, ARG2_1
, ARG2_2
);
5400 SET_STATUS_from_SysRes(r
);
5403 case VKI_SYS_SENDTO
:
5409 case VKI_SYS_RECVFROM
:
5410 ML_(generic_POST_sys_recvfrom
)( tid
, VG_(mk_SysRes_Success
)(RES
),
5411 ARG2_0
, ARG2_1
, ARG2_2
,
5412 ARG2_3
, ARG2_4
, ARG2_5
);
5416 ML_(generic_POST_sys_recv
)( tid
, RES
, ARG2_0
, ARG2_1
, ARG2_2
);
5419 case VKI_SYS_CONNECT
:
5422 case VKI_SYS_SETSOCKOPT
:
5425 case VKI_SYS_GETSOCKOPT
:
5426 ML_(linux_POST_sys_getsockopt
)( tid
, VG_(mk_SysRes_Success
)(RES
),
5428 ARG2_2
, ARG2_3
, ARG2_4
);
5431 case VKI_SYS_GETSOCKNAME
:
5432 ML_(generic_POST_sys_getsockname
)( tid
, VG_(mk_SysRes_Success
)(RES
),
5433 ARG2_0
, ARG2_1
, ARG2_2
);
5436 case VKI_SYS_GETPEERNAME
:
5437 ML_(generic_POST_sys_getpeername
)( tid
, VG_(mk_SysRes_Success
)(RES
),
5438 ARG2_0
, ARG2_1
, ARG2_2
);
5441 case VKI_SYS_SHUTDOWN
:
5444 case VKI_SYS_SENDMSG
:
5447 case VKI_SYS_RECVMSG
:
5448 ML_(generic_POST_sys_recvmsg
)( tid
, "msg",
5449 (struct vki_msghdr
*)(Addr
)ARG2_1
, RES
);
5452 case VKI_SYS_RECVMMSG
:
5453 ML_(linux_POST_sys_recvmmsg
)( tid
, RES
,
5454 ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
, ARG2_4
);
5457 case VKI_SYS_SENDMMSG
:
5458 ML_(linux_POST_sys_sendmmsg
)( tid
, RES
, ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
);
5462 VG_(message
)(Vg_DebugMsg
,"FATAL: unhandled socketcall 0x%lx\n",ARG1
);
5463 VG_(core_panic
)("... bye!\n");
5464 break; /*NOTREACHED*/
5477 PRINT("sys_socket ( %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
);
5478 PRE_REG_READ3(long, "socket", int, domain
, int, type
, int, protocol
);
5484 r
= ML_(generic_POST_sys_socket
)(tid
, VG_(mk_SysRes_Success
)(RES
));
5485 SET_STATUS_from_SysRes(r
);
5490 PRINT("sys_setsockopt ( %ld, %ld, %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
5491 "u )", SARG1
, SARG2
, SARG3
, ARG4
, ARG5
);
5492 PRE_REG_READ5(long, "setsockopt",
5493 int, s
, int, level
, int, optname
,
5494 const void *, optval
, unsigned, optlen
); // socklen_t
5495 ML_(linux_PRE_sys_setsockopt
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
5500 PRINT("sys_getsockopt ( %ld, %ld, %ld, %#" FMT_REGWORD
"x, %ld )",
5501 SARG1
, SARG2
, SARG3
, ARG4
, SARG5
);
5502 PRE_REG_READ5(long, "getsockopt",
5503 int, s
, int, level
, int, optname
,
5504 void *, optval
, int, *optlen
);
5505 ML_(linux_PRE_sys_getsockopt
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
5507 POST(sys_getsockopt
)
5510 ML_(linux_POST_sys_getsockopt
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5511 ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
5516 *flags
|= SfMayBlock
;
5517 PRINT("sys_connect ( %ld, %#" FMT_REGWORD
"x, %ld )", SARG1
, ARG2
, SARG3
);
5518 PRE_REG_READ3(long, "connect",
5519 int, sockfd
, struct sockaddr
*, serv_addr
, int, addrlen
);
5520 ML_(generic_PRE_sys_connect
)(tid
, ARG1
,ARG2
,ARG3
);
5525 *flags
|= SfMayBlock
;
5526 PRINT("sys_accept ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
5528 PRE_REG_READ3(long, "accept",
5529 int, s
, struct sockaddr
*, addr
, int *, addrlen
);
5530 ML_(generic_PRE_sys_accept
)(tid
, ARG1
,ARG2
,ARG3
);
5536 r
= ML_(generic_POST_sys_accept
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5538 SET_STATUS_from_SysRes(r
);
5543 *flags
|= SfMayBlock
;
5544 PRINT("sys_accept4 ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %ld )",
5545 SARG1
, ARG2
, ARG3
, SARG4
);
5546 PRE_REG_READ4(long, "accept4",
5547 int, s
, struct sockaddr
*, addr
, int *, addrlen
, int, flags
);
5548 ML_(generic_PRE_sys_accept
)(tid
, ARG1
,ARG2
,ARG3
);
5554 r
= ML_(generic_POST_sys_accept
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5556 SET_STATUS_from_SysRes(r
);
5561 *flags
|= SfMayBlock
;
5562 PRINT("sys_send ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#"
5563 FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
, ARG4
);
5564 PRE_REG_READ4(long, "send",
5565 int, s
, const void *, msg
, vki_size_t
, len
,
5568 ML_(generic_PRE_sys_send
)( tid
, ARG1
, ARG2
, ARG3
);
5573 *flags
|= SfMayBlock
;
5574 PRINT("sys_sendto ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
5575 FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %ld )",
5576 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, SARG6
);
5577 PRE_REG_READ6(long, "sendto",
5578 int, s
, const void *, msg
, vki_size_t
, len
,
5579 unsigned int, flags
,
5580 const struct sockaddr
*, to
, int, tolen
);
5581 ML_(generic_PRE_sys_sendto
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
,ARG6
);
5586 *flags
|= SfMayBlock
;
5587 PRINT ("sys_recv ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
5588 FMT_REGWORD
"u )", SARG1
, ARG2
, ARG3
, ARG4
);
5589 PRE_REG_READ4 (long, "recv", int, s
, void *, buf
, vki_size_t
, len
,
5590 unsigned int, flags
);
5591 ML_ (generic_PRE_sys_recv
) (tid
, ARG1
, ARG2
, ARG3
);
5596 ML_ (generic_POST_sys_recv
) (tid
, RES
, ARG1
, ARG2
, ARG3
);
5601 *flags
|= SfMayBlock
;
5602 PRINT("sys_recvfrom ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
5603 FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
5604 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
5605 PRE_REG_READ6(long, "recvfrom",
5606 int, s
, void *, buf
, vki_size_t
, len
, unsigned int, flags
,
5607 struct sockaddr
*, from
, int *, fromlen
);
5608 ML_(generic_PRE_sys_recvfrom
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
,ARG6
);
5613 ML_(generic_POST_sys_recvfrom
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5614 ARG1
,ARG2
,ARG3
,ARG4
,ARG5
,ARG6
);
5619 *flags
|= SfMayBlock
;
5620 PRINT("sys_sendmsg ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
5622 PRE_REG_READ3(long, "sendmsg",
5623 int, s
, const struct msghdr
*, msg
, unsigned int, flags
);
5624 ML_(generic_PRE_sys_sendmsg
)(tid
, "msg", (struct vki_msghdr
*)(Addr
)ARG2
);
5629 *flags
|= SfMayBlock
;
5630 PRINT("sys_recvmsg ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
5632 PRE_REG_READ3(long, "recvmsg", int, s
, struct msghdr
*, msg
,
5633 unsigned int, flags
);
5634 ML_(generic_PRE_sys_recvmsg
)(tid
, "msg", (struct vki_msghdr
*)(Addr
)ARG2
);
5638 ML_(generic_POST_sys_recvmsg
)(tid
, "msg", (struct vki_msghdr
*)(Addr
)ARG2
,
5644 *flags
|= SfMayBlock
;
5645 PRINT("sys_shutdown ( %ld, %ld )", SARG1
, SARG2
);
5646 PRE_REG_READ2(int, "shutdown", int, s
, int, how
);
5651 PRINT("sys_bind ( %ld, %#" FMT_REGWORD
"x, %ld )", SARG1
, ARG2
, SARG3
);
5652 PRE_REG_READ3(long, "bind",
5653 int, sockfd
, struct sockaddr
*, my_addr
, int, addrlen
);
5654 ML_(generic_PRE_sys_bind
)(tid
, ARG1
,ARG2
,ARG3
);
5659 PRINT("sys_listen ( %ld, %ld )", SARG1
, SARG2
);
5660 PRE_REG_READ2(long, "listen", int, s
, int, backlog
);
5663 PRE(sys_getsockname
)
5665 PRINT("sys_getsockname ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
5667 PRE_REG_READ3(long, "getsockname",
5668 int, s
, struct sockaddr
*, name
, int *, namelen
);
5669 ML_(generic_PRE_sys_getsockname
)(tid
, ARG1
,ARG2
,ARG3
);
5671 POST(sys_getsockname
)
5674 ML_(generic_POST_sys_getsockname
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5678 PRE(sys_getpeername
)
5680 PRINT("sys_getpeername ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
5682 PRE_REG_READ3(long, "getpeername",
5683 int, s
, struct sockaddr
*, name
, int *, namelen
);
5684 ML_(generic_PRE_sys_getpeername
)(tid
, ARG1
,ARG2
,ARG3
);
5686 POST(sys_getpeername
)
5689 ML_(generic_POST_sys_getpeername
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5695 PRINT("sys_socketpair ( %ld, %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
,
5697 PRE_REG_READ4(long, "socketpair",
5698 int, d
, int, type
, int, protocol
, int*, sv
);
5699 ML_(generic_PRE_sys_socketpair
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
);
5701 POST(sys_socketpair
)
5704 ML_(generic_POST_sys_socketpair
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5705 ARG1
,ARG2
,ARG3
,ARG4
);
5709 /* ---------------------------------------------------------------------
5711 ------------------------------------------------------------------ */
5715 HChar name
[30]; // large enough
5718 if (ARG3
& VKI_O_CREAT
) {
5720 PRINT("sys_openat ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %ld )",
5721 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
, SARG4
);
5722 PRE_REG_READ4(long, "openat",
5723 int, dfd
, const char *, filename
, int, flags
, int, mode
);
5726 PRINT("sys_openat ( %ld, %#" FMT_REGWORD
"x(%s), %ld )",
5727 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
);
5728 PRE_REG_READ3(long, "openat",
5729 int, dfd
, const char *, filename
, int, flags
);
5732 PRE_MEM_RASCIIZ( "openat(filename)", ARG2
);
5734 /* For absolute filenames, dfd is ignored. If dfd is AT_FDCWD,
5735 filename is relative to cwd. When comparing dfd against AT_FDCWD,
5736 be sure only to compare the bottom 32 bits. */
5737 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG2
, 1 )
5738 && *(Char
*)(Addr
)ARG2
!= '/'
5739 && ((Int
)ARG1
) != ((Int
)VKI_AT_FDCWD
)
5740 && !ML_(fd_allowed
)(ARG1
, "openat", tid
, False
))
5741 SET_STATUS_Failure( VKI_EBADF
);
5743 /* Handle the case where the open is of /proc/self/cmdline or
5744 /proc/<pid>/cmdline, and just give it a copy of the fd for the
5745 fake file we cooked up at startup (in m_main). Also, seek the
5746 cloned fd back to the start. */
5748 VG_(sprintf
)(name
, "/proc/%d/cmdline", VG_(getpid
)());
5749 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG2
, 1 )
5750 && (VG_(strcmp
)((HChar
*)(Addr
)ARG2
, name
) == 0
5751 || VG_(strcmp
)((HChar
*)(Addr
)ARG2
, "/proc/self/cmdline") == 0)) {
5752 sres
= VG_(dup
)( VG_(cl_cmdline_fd
) );
5753 SET_STATUS_from_SysRes( sres
);
5754 if (!sr_isError(sres
)) {
5755 OffT off
= VG_(lseek
)( sr_Res(sres
), 0, VKI_SEEK_SET
);
5757 SET_STATUS_Failure( VKI_EMFILE
);
5762 /* Do the same for /proc/self/auxv or /proc/<pid>/auxv case. */
5764 VG_(sprintf
)(name
, "/proc/%d/auxv", VG_(getpid
)());
5765 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG2
, 1 )
5766 && (VG_(strcmp
)((HChar
*)(Addr
)ARG2
, name
) == 0
5767 || VG_(strcmp
)((HChar
*)(Addr
)ARG2
, "/proc/self/auxv") == 0)) {
5768 sres
= VG_(dup
)( VG_(cl_auxv_fd
) );
5769 SET_STATUS_from_SysRes( sres
);
5770 if (!sr_isError(sres
)) {
5771 OffT off
= VG_(lseek
)( sr_Res(sres
), 0, VKI_SEEK_SET
);
5773 SET_STATUS_Failure( VKI_EMFILE
);
5778 /* And for /proc/self/exe or /proc/<pid>/exe case. */
5780 VG_(sprintf
)(name
, "/proc/%d/exe", VG_(getpid
)());
5781 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG2
, 1 )
5782 && (VG_(strcmp
)((HChar
*)(Addr
)ARG2
, name
) == 0
5783 || VG_(strcmp
)((HChar
*)(Addr
)ARG2
, "/proc/self/exe") == 0)) {
5784 sres
= VG_(dup
)( VG_(cl_exec_fd
) );
5785 SET_STATUS_from_SysRes( sres
);
5786 if (!sr_isError(sres
)) {
5787 OffT off
= VG_(lseek
)( sr_Res(sres
), 0, VKI_SEEK_SET
);
5789 SET_STATUS_Failure( VKI_EMFILE
);
5794 /* Otherwise handle normally */
5795 *flags
|= SfMayBlock
;
5801 if (!ML_(fd_allowed
)(RES
, "openat", tid
, True
)) {
5803 SET_STATUS_Failure( VKI_EMFILE
);
5805 if (VG_(clo_track_fds
))
5806 ML_(record_fd_open_with_given_name
)(tid
, RES
, (HChar
*)(Addr
)ARG2
);
5812 *flags
|= SfMayBlock
;
5813 PRINT("sys_mkdirat ( %ld, %#" FMT_REGWORD
"x(%s), %ld )",
5814 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
);
5815 PRE_REG_READ3(long, "mkdirat",
5816 int, dfd
, const char *, pathname
, int, mode
);
5817 PRE_MEM_RASCIIZ( "mkdirat(pathname)", ARG2
);
5822 PRINT("sys_mknodat ( %ld, %#" FMT_REGWORD
"x(%s), 0x%" FMT_REGWORD
"x, 0x%"
5823 FMT_REGWORD
"x )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
);
5824 PRE_REG_READ4(long, "mknodat",
5825 int, dfd
, const char *, pathname
, int, mode
, unsigned, dev
);
5826 PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2
);
5831 PRINT("sys_fchownat ( %ld, %#" FMT_REGWORD
"x(%s), 0x%" FMT_REGWORD
"x, 0x%"
5832 FMT_REGWORD
"x )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
);
5833 PRE_REG_READ4(long, "fchownat",
5834 int, dfd
, const char *, path
,
5835 vki_uid_t
, owner
, vki_gid_t
, group
);
5836 PRE_MEM_RASCIIZ( "fchownat(path)", ARG2
);
5841 PRINT("sys_futimesat ( %ld, %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x )",
5842 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
);
5843 PRE_REG_READ3(long, "futimesat",
5844 int, dfd
, char *, filename
, struct timeval
*, tvp
);
5846 PRE_MEM_RASCIIZ( "futimesat(filename)", ARG2
);
5848 PRE_MEM_READ( "futimesat(tvp)", ARG3
, 2 * sizeof(struct vki_timeval
) );
5853 PRINT("sys_utimensat ( %ld, %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x, 0x%"
5854 FMT_REGWORD
"x )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
);
5855 PRE_REG_READ4(long, "utimensat",
5856 int, dfd
, char *, filename
, struct timespec
*, utimes
, int, flags
);
5858 PRE_MEM_RASCIIZ( "utimensat(filename)", ARG2
);
5860 /* If timespec.tv_nsec has the special value UTIME_NOW or UTIME_OMIT
5861 then the tv_sec field is ignored. */
5862 struct vki_timespec
*times
= (struct vki_timespec
*)(Addr
)ARG3
;
5863 PRE_MEM_READ( "utimensat(times[0].tv_nsec)",
5864 (Addr
)×
[0].tv_nsec
, sizeof(times
[0].tv_nsec
));
5865 PRE_MEM_READ( "utimensat(times[1].tv_nsec)",
5866 (Addr
)×
[1].tv_nsec
, sizeof(times
[1].tv_nsec
));
5867 if (ML_(safe_to_deref
)(times
, 2 * sizeof(struct vki_timespec
))) {
5868 if (times
[0].tv_nsec
!= VKI_UTIME_NOW
5869 && times
[0].tv_nsec
!= VKI_UTIME_OMIT
)
5870 PRE_MEM_READ( "utimensat(times[0].tv_sec)",
5871 (Addr
)×
[0].tv_sec
, sizeof(times
[0].tv_sec
));
5872 if (times
[1].tv_nsec
!= VKI_UTIME_NOW
5873 && times
[1].tv_nsec
!= VKI_UTIME_OMIT
)
5874 PRE_MEM_READ( "utimensat(times[1].tv_sec)",
5875 (Addr
)×
[1].tv_sec
, sizeof(times
[1].tv_sec
));
5880 PRE(sys_utimensat_time64
)
5882 PRINT("sys_utimensat_time64 ( %ld, %#" FMT_REGWORD
"x(%s), %#"
5883 FMT_REGWORD
"x, 0x%" FMT_REGWORD
"x )",
5884 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
);
5885 PRE_REG_READ4(long, "utimensat_time64",
5886 int, dfd
, char *, filename
, struct timespec
*, utimes
, int, flags
);
5888 PRE_MEM_RASCIIZ( "utimensat_time64(filename)", ARG2
);
5890 /* If timespec.tv_nsec has the special value UTIME_NOW or UTIME_OMIT
5891 then the tv_sec field is ignored. */
5892 struct vki_timespec64
*times
= (struct vki_timespec64
*)(Addr
)ARG3
;
5893 PRE_MEM_READ( "utimensat_time64(times[0].tv_nsec)",
5894 (Addr
)×
[0].tv_nsec
, sizeof(times
[0].tv_nsec
));
5895 PRE_MEM_READ( "utimensat_time64(times[1].tv_nsec)",
5896 (Addr
)×
[1].tv_nsec
, sizeof(times
[1].tv_nsec
));
5897 if (ML_(safe_to_deref
)(times
, 2 * sizeof(struct vki_timespec64
))) {
5898 if (times
[0].tv_nsec
!= VKI_UTIME_NOW
5899 && times
[0].tv_nsec
!= VKI_UTIME_OMIT
)
5900 PRE_MEM_READ( "utimensat_time64(times[0].tv_sec)",
5901 (Addr
)×
[0].tv_sec
, sizeof(times
[0].tv_sec
));
5902 if (times
[1].tv_nsec
!= VKI_UTIME_NOW
5903 && times
[1].tv_nsec
!= VKI_UTIME_OMIT
)
5904 PRE_MEM_READ( "utimensat_time64(times[1].tv_sec)",
5905 (Addr
)×
[1].tv_sec
, sizeof(times
[1].tv_sec
));
5910 #if !defined(VGP_nanomips_linux)
5913 FUSE_COMPATIBLE_MAY_BLOCK();
5914 PRINT("sys_newfstatat ( %ld, %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x )",
5915 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
);
5916 PRE_REG_READ3(long, "fstatat",
5917 int, dfd
, char *, file_name
, struct stat
*, buf
);
5918 // See the comment about Rust in PRE(sys_statx). When glibc does support
5919 // statx rust uses that instead of the system call, but glibc's statx is
5920 // implemented in terms of fstatat, so the filename being NULL is
5921 // transferred here.
5923 PRE_MEM_RASCIIZ( "fstatat(file_name)", ARG2
);
5924 PRE_MEM_WRITE( "fstatat(buf)", ARG3
, sizeof(struct vki_stat
) );
5928 POST(sys_newfstatat
)
5930 POST_MEM_WRITE( ARG3
, sizeof(struct vki_stat
) );
5936 *flags
|= SfMayBlock
;
5937 PRINT("sys_unlinkat ( %ld, %#" FMT_REGWORD
"x(%s) )", SARG1
, ARG2
,
5938 (HChar
*)(Addr
)ARG2
);
5939 PRE_REG_READ2(long, "unlinkat", int, dfd
, const char *, pathname
);
5940 PRE_MEM_RASCIIZ( "unlinkat(pathname)", ARG2
);
5945 PRINT("sys_renameat ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %#"
5946 FMT_REGWORD
"x(%s) )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
,
5947 ARG4
, (HChar
*)(Addr
)ARG4
);
5948 PRE_REG_READ4(long, "renameat",
5949 int, olddfd
, const char *, oldpath
,
5950 int, newdfd
, const char *, newpath
);
5951 PRE_MEM_RASCIIZ( "renameat(oldpath)", ARG2
);
5952 PRE_MEM_RASCIIZ( "renameat(newpath)", ARG4
);
5957 PRINT("sys_renameat2 ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %#" FMT_REGWORD
5958 "x(%s), %" FMT_REGWORD
"u )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
,
5959 ARG4
, (HChar
*)(Addr
)ARG4
, ARG5
);
5960 PRE_REG_READ5(long, "renameat2",
5961 int, olddfd
, const char *, oldpath
,
5962 int, newdfd
, const char *, newpath
,
5963 unsigned int, flags
);
5964 PRE_MEM_RASCIIZ( "renameat2(oldpath)", ARG2
);
5965 PRE_MEM_RASCIIZ( "renameat2(newpath)", ARG4
);
5970 *flags
|= SfMayBlock
;
5971 PRINT("sys_linkat ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %#" FMT_REGWORD
5972 "x(%s), %ld )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
, ARG4
,
5973 (HChar
*)(Addr
)ARG4
, SARG5
);
5974 PRE_REG_READ5(long, "linkat",
5975 int, olddfd
, const char *, oldpath
,
5976 int, newdfd
, const char *, newpath
,
5978 PRE_MEM_RASCIIZ( "linkat(oldpath)", ARG2
);
5979 PRE_MEM_RASCIIZ( "linkat(newpath)", ARG4
);
5984 *flags
|= SfMayBlock
;
5985 PRINT("sys_symlinkat ( %#" FMT_REGWORD
"x(%s), %ld, %#" FMT_REGWORD
5986 "x(%s) )", ARG1
, (HChar
*)(Addr
)ARG1
, SARG2
, ARG3
, (HChar
*)(Addr
)ARG3
);
5987 PRE_REG_READ3(long, "symlinkat",
5988 const char *, oldpath
, int, newdfd
, const char *, newpath
);
5989 PRE_MEM_RASCIIZ( "symlinkat(oldpath)", ARG1
);
5990 PRE_MEM_RASCIIZ( "symlinkat(newpath)", ARG3
);
5995 HChar name
[30]; // large enough
5998 PRINT("sys_readlinkat ( %ld, %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x, %"
5999 FMT_REGWORD
"u )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
);
6000 PRE_REG_READ4(long, "readlinkat",
6001 int, dfd
, const char *, path
, char *, buf
, vki_size_t
, bufsiz
);
6002 PRE_MEM_RASCIIZ( "readlinkat(path)", ARG2
);
6003 PRE_MEM_WRITE( "readlinkat(buf)", ARG3
,ARG4
);
6006 * Handle the case where readlinkat is looking at /proc/self/exe or
6009 VG_(sprintf
)(name
, "/proc/%d/exe", VG_(getpid
)());
6010 if (ML_(safe_to_deref
)((void*)(Addr
)ARG2
, 1)
6011 && (VG_(strcmp
)((HChar
*)(Addr
)ARG2
, name
) == 0
6012 || VG_(strcmp
)((HChar
*)(Addr
)ARG2
, "/proc/self/exe") == 0)) {
6013 VG_(sprintf
)(name
, "/proc/self/fd/%d", VG_(cl_exec_fd
));
6014 SET_STATUS_from_SysRes( VG_(do_syscall4
)(saved
, ARG1
, (UWord
)name
,
6018 SET_STATUS_from_SysRes( VG_(do_syscall4
)(saved
, ARG1
, ARG2
, ARG3
, ARG4
));
6021 if (SUCCESS
&& RES
> 0)
6022 POST_MEM_WRITE( ARG3
, RES
);
6027 PRINT("sys_fchmodat ( %ld, %#" FMT_REGWORD
"x(%s), %" FMT_REGWORD
"u )",
6028 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
);
6029 PRE_REG_READ3(long, "fchmodat",
6030 int, dfd
, const char *, path
, vki_mode_t
, mode
);
6031 PRE_MEM_RASCIIZ( "fchmodat(path)", ARG2
);
6036 PRINT("sys_faccessat ( %ld, %#" FMT_REGWORD
"x(%s), %ld )",
6037 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
);
6038 PRE_REG_READ3(long, "faccessat",
6039 int, dfd
, const char *, pathname
, int, mode
);
6040 PRE_MEM_RASCIIZ( "faccessat(pathname)", ARG2
);
6045 PRINT("sys_faccessat2 ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %ld )",
6046 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
, SARG4
);
6047 PRE_REG_READ4(long, "faccessat2",
6048 int, dfd
, const char *, pathname
, int, mode
, int, flags
);
6049 PRE_MEM_RASCIIZ( "faccessat2(pathname)", ARG2
);
6052 PRE(sys_name_to_handle_at
)
6054 PRINT("sys_name_to_handle_at ( %ld, %#" FMT_REGWORD
"x(%s), %#"
6055 FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %ld )", SARG1
, ARG2
,
6056 (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
, SARG5
);
6057 PRE_REG_READ5(int, "name_to_handle_at",
6058 int, dfd
, const char *, name
,
6059 struct vki_file_handle
*, handle
,
6060 int *, mnt_id
, int, flag
);
6061 PRE_MEM_RASCIIZ( "name_to_handle_at(name)", ARG2
);
6062 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG3
, sizeof(struct vki_file_handle
))) {
6063 struct vki_file_handle
*fh
= (struct vki_file_handle
*)(Addr
)ARG3
;
6064 PRE_MEM_READ( "name_to_handle_at(handle)", (Addr
)&fh
->handle_bytes
, sizeof(fh
->handle_bytes
) );
6065 PRE_MEM_WRITE( "name_to_handle_at(handle)", (Addr
)fh
, sizeof(struct vki_file_handle
) + fh
->handle_bytes
);
6067 PRE_MEM_WRITE( "name_to_handle_at(mnt_id)", ARG4
, sizeof(int) );
6070 POST(sys_name_to_handle_at
)
6072 struct vki_file_handle
*fh
= (struct vki_file_handle
*)(Addr
)ARG3
;
6073 POST_MEM_WRITE( ARG3
, sizeof(struct vki_file_handle
) + fh
->handle_bytes
);
6074 POST_MEM_WRITE( ARG4
, sizeof(int) );
6077 PRE(sys_open_by_handle_at
)
6079 *flags
|= SfMayBlock
;
6080 PRINT("sys_open_by_handle_at ( %ld, %#" FMT_REGWORD
"x, %ld )", SARG1
,
6082 PRE_REG_READ3(int, "open_by_handle_at",
6084 struct vki_file_handle
*, handle
,
6086 PRE_MEM_READ( "open_by_handle_at(handle)", ARG2
,
6087 sizeof(struct vki_file_handle
) +
6088 ((struct vki_file_handle
*)(Addr
)ARG2
)->handle_bytes
);
6091 POST(sys_open_by_handle_at
)
6094 if (!ML_(fd_allowed
)(RES
, "open_by_handle_at", tid
, True
)) {
6096 SET_STATUS_Failure( VKI_EMFILE
);
6098 if (VG_(clo_track_fds
))
6099 ML_(record_fd_open_with_given_name
)(tid
, RES
, (HChar
*)(Addr
)ARG2
);
6103 /* ---------------------------------------------------------------------
6104 p{read,write}v wrappers
6105 ------------------------------------------------------------------ */
6106 /* This handles the common part of the PRE macro for preadv and preadv2. */
6107 void handle_pre_sys_preadv(ThreadId tid
, SyscallStatus
* status
,
6108 Int fd
, Addr vector
, Int count
, const char *str
)
6110 struct vki_iovec
* vec
;
6112 /* safe size for the "preadv/preadv2(vector[i])" string */
6115 if (!ML_(fd_allowed
)(fd
, str
, tid
, False
)) {
6116 SET_STATUS_Failure( VKI_EBADF
);
6117 } else if (count
> 0) {
6118 VG_(strcpy
) (tmp
, str
);
6119 VG_(strcat
) (tmp
, "(vector)");
6120 PRE_MEM_READ( tmp
, vector
, count
* sizeof(struct vki_iovec
) );
6122 if (ML_(safe_to_deref
) ((void *)(Addr
)vector
,
6123 count
* sizeof(struct vki_iovec
))) {
6124 vec
= (struct vki_iovec
*)(Addr
)vector
;
6125 for (i
= 0; i
< count
; i
++) {
6126 /* Note: building such a dynamic error string is *not*
6127 a pattern to follow. See bug 417075. */
6128 VG_(snprintf
) (tmp
, 30, "%s(vector[%d])", str
, i
);
6129 PRE_MEM_WRITE( tmp
, (Addr
)vec
[i
].iov_base
, vec
[i
].iov_len
);
6135 /* This handles the common part of the POST macro for preadv and preadv2. */
6136 void handle_post_sys_preadv(ThreadId tid
, SyscallStatus
* status
, Addr vector
, Int count
)
6141 struct vki_iovec
* vec
= (struct vki_iovec
*)(Addr
)vector
;
6144 /* RES holds the number of bytes read. */
6145 for (i
= 0; i
< count
; i
++) {
6146 Int nReadThisBuf
= vec
[i
].iov_len
;
6147 if (nReadThisBuf
> remains
) nReadThisBuf
= remains
;
6148 POST_MEM_WRITE( (Addr
)vec
[i
].iov_base
, nReadThisBuf
);
6149 remains
-= nReadThisBuf
;
6150 if (remains
< 0) VG_(core_panic
)("preadv: remains < 0");
6157 *flags
|= SfMayBlock
;
6158 const char *str
= "preadv";
6159 #if VG_WORDSIZE == 4
6160 /* Note that the offset argument here is in lo+hi order on both
6161 big and little endian platforms... */
6162 PRINT("sys_preadv ( %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
6164 ARG1
, ARG2
, ARG3
, (Long
)LOHI64(ARG4
,ARG5
));
6165 PRE_REG_READ5(ssize_t
, "preadv",
6166 unsigned long, fd
, const struct iovec
*, vector
,
6167 unsigned long, count
, vki_u32
, offset_low
,
6168 vki_u32
, offset_high
);
6169 #elif VG_WORDSIZE == 8
6170 PRINT("sys_preadv ( %lu, %#lx, %lu, %ld )", ARG1
, ARG2
, ARG3
, SARG4
);
6171 PRE_REG_READ4(ssize_t
, "preadv",
6172 unsigned long, fd
, const struct iovec
*, vector
,
6173 unsigned long, count
, Word
, offset
);
6175 # error Unexpected word size
6181 handle_pre_sys_preadv(tid
, status
, fd
, vector
, count
, str
);
6190 handle_post_sys_preadv(tid
, status
, vector
, count
);
6195 *flags
|= SfMayBlock
;
6196 const char *str
= "preadv2";
6197 #if VG_WORDSIZE == 4
6198 /* Note that the offset argument here is in lo+hi order on both
6199 big and little endian platforms... */
6200 PRINT("sys_preadv2 ( %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
6201 "u, %lld, %" FMT_REGWORD
"u )",
6202 ARG1
, ARG2
, ARG3
, (Long
)LOHI64(ARG4
,ARG5
), ARG6
);
6203 PRE_REG_READ6(ssize_t
, "preadv2",
6204 unsigned long, fd
, const struct iovec
*, vector
,
6205 unsigned long, count
, vki_u32
, offset_low
,
6206 vki_u32
, offset_high
, unsigned long, flags
);
6207 #elif VG_WORDSIZE == 8
6208 PRINT("sys_preadv2 ( %lu, %#lx, %lu, %ld, %lu )", ARG1
, ARG2
, ARG3
, SARG4
, ARG5
);
6209 PRE_REG_READ5(ssize_t
, "preadv2",
6210 unsigned long, fd
, const struct iovec
*, vector
,
6211 unsigned long, count
, Word
, offset
, unsigned long, flags
);
6213 # error Unexpected word size
6219 handle_pre_sys_preadv(tid
, status
, fd
, vector
, count
, str
);
6227 handle_post_sys_preadv(tid
, status
, vector
, count
);
6230 /* This handles the common part of the PRE macro for pwritev and pwritev2. */
6231 void handle_sys_pwritev(ThreadId tid
, SyscallStatus
* status
,
6232 Int fd
, Addr vector
, Int count
, const char *str
)
6235 struct vki_iovec
* vec
;
6236 /* safe size for the "preadv/preadv2(vector[i])" string */
6239 if (!ML_(fd_allowed
)(fd
, str
, tid
, False
)) {
6240 SET_STATUS_Failure( VKI_EBADF
);
6241 } else if (count
> 0) {
6242 VG_(strcpy
) (tmp
, str
);
6243 VG_(strcat
) (tmp
, "(vector)");
6244 PRE_MEM_READ( tmp
, vector
, count
* sizeof(struct vki_iovec
) );
6245 if (ML_(safe_to_deref
) ((void *)(Addr
)vector
,
6246 count
* sizeof(struct vki_iovec
))) {
6247 vec
= (struct vki_iovec
*)(Addr
)vector
;
6248 for (i
= 0; i
< count
; i
++) {
6249 /* Note: building such a dynamic error string is *not*
6250 a pattern to follow. See bug 417075. */
6251 VG_(snprintf
) (tmp
, 30, "%s(vector[%d])", str
, i
);
6252 PRE_MEM_READ( tmp
, (Addr
)vec
[i
].iov_base
, vec
[i
].iov_len
);
6260 *flags
|= SfMayBlock
;
6261 const char *str
= "pwritev";
6262 #if VG_WORDSIZE == 4
6263 /* Note that the offset argument here is in lo+hi order on both
6264 big and little endian platforms... */
6265 PRINT("sys_pwritev ( %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
6266 "u, %lld )", ARG1
, ARG2
, ARG3
, (Long
)LOHI64(ARG4
,ARG5
));
6267 PRE_REG_READ5(ssize_t
, "pwritev",
6268 unsigned long, fd
, const struct iovec
*, vector
,
6269 unsigned long, count
, vki_u32
, offset_low
,
6270 vki_u32
, offset_high
);
6271 #elif VG_WORDSIZE == 8
6272 PRINT("sys_pwritev ( %lu, %#lx, %lu, %ld )", ARG1
, ARG2
, ARG3
, SARG4
);
6273 PRE_REG_READ4(ssize_t
, "pwritev",
6274 unsigned long, fd
, const struct iovec
*, vector
,
6275 unsigned long, count
, Word
, offset
);
6277 # error Unexpected word size
6283 handle_sys_pwritev(tid
, status
, fd
, vector
, count
, str
);
6288 *flags
|= SfMayBlock
;
6289 const char *str
= "pwritev2";
6290 #if VG_WORDSIZE == 4
6291 /* Note that the offset argument here is in lo+hi order on both
6292 big and little endian platforms... */
6293 PRINT("sys_pwritev2 ( %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
6294 "u, %lld, %" FMT_REGWORD
"u )",
6295 ARG1
, ARG2
, ARG3
, (Long
)LOHI64(ARG4
,ARG5
), ARG6
);
6296 PRE_REG_READ6(ssize_t
, "pwritev2",
6297 unsigned long, fd
, const struct iovec
*, vector
,
6298 unsigned long, count
, vki_u32
, offset_low
,
6299 vki_u32
, offset_high
, unsigned long, flags
);
6300 #elif VG_WORDSIZE == 8
6301 /* Note offset_high isn't actually used? */
6302 PRE_REG_READ6(ssize_t
, "pwritev2",
6303 unsigned long, fd
, const struct iovec
*, vector
,
6304 unsigned long, count
, Word
, offset
,
6305 Word
, offset_high
, unsigned long, flags
);
6307 # error Unexpected word size
6313 handle_sys_pwritev(tid
, status
, fd
, vector
, count
, str
);
6316 /* ---------------------------------------------------------------------
6317 process_vm_{read,write}v wrappers
6318 ------------------------------------------------------------------ */
6320 PRE(sys_process_vm_readv
)
6322 PRINT("sys_process_vm_readv ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
6323 "u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )",
6324 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
6325 PRE_REG_READ6(ssize_t
, "process_vm_readv",
6327 const struct iovec
*, lvec
,
6328 unsigned long, liovcnt
,
6329 const struct iovec
*, rvec
,
6330 unsigned long, riovcnt
,
6331 unsigned long, flags
);
6332 PRE_MEM_READ( "process_vm_readv(lvec)",
6333 ARG2
, ARG3
* sizeof(struct vki_iovec
) );
6334 PRE_MEM_READ( "process_vm_readv(rvec)",
6335 ARG4
, ARG5
* sizeof(struct vki_iovec
) );
6337 && ML_(safe_to_deref
) ((void *)(Addr
)ARG2
,
6338 sizeof(struct vki_iovec
) * ARG3
)) {
6339 const struct vki_iovec
*vec
= (const struct vki_iovec
*)(Addr
)ARG2
;
6341 for (i
= 0; i
< ARG3
; i
++)
6342 PRE_MEM_WRITE( "process_vm_readv(lvec[...])",
6343 (Addr
)vec
[i
].iov_base
, vec
[i
].iov_len
);
6347 POST(sys_process_vm_readv
)
6349 const struct vki_iovec
*vec
= (const struct vki_iovec
*)(Addr
)ARG2
;
6352 for (i
= 0; i
< ARG3
; i
++) {
6353 UInt nReadThisBuf
= vec
[i
].iov_len
<= remains
?
6354 vec
[i
].iov_len
: remains
;
6355 POST_MEM_WRITE( (Addr
)vec
[i
].iov_base
, nReadThisBuf
);
6356 remains
-= nReadThisBuf
;
6360 PRE(sys_process_vm_writev
)
6362 PRINT("sys_process_vm_writev ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
6363 "u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )",
6364 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
6365 PRE_REG_READ6(ssize_t
, "process_vm_writev",
6367 const struct iovec
*, lvec
,
6368 unsigned long, liovcnt
,
6369 const struct iovec
*, rvec
,
6370 unsigned long, riovcnt
,
6371 unsigned long, flags
);
6372 PRE_MEM_READ( "process_vm_writev(lvec)",
6373 ARG2
, ARG3
* sizeof(struct vki_iovec
) );
6374 PRE_MEM_READ( "process_vm_writev(rvec)",
6375 ARG4
, ARG5
* sizeof(struct vki_iovec
) );
6377 && ML_(safe_to_deref
) ((void *)(Addr
)ARG2
,
6378 sizeof(struct vki_iovec
) * ARG3
)) {
6379 const struct vki_iovec
*vec
= (const struct vki_iovec
*)(Addr
)ARG2
;
6381 for (i
= 0; i
< ARG3
; i
++)
6382 PRE_MEM_READ( "process_vm_writev(lvec[...])",
6383 (Addr
)vec
[i
].iov_base
, vec
[i
].iov_len
);
6387 /* ---------------------------------------------------------------------
6388 {send,recv}mmsg wrappers
6389 ------------------------------------------------------------------ */
6393 *flags
|= SfMayBlock
;
6394 PRINT("sys_sendmmsg ( %ld, %#" FMT_REGWORD
"x, %ld, %ld )", SARG1
, ARG2
,
6396 PRE_REG_READ4(long, "sendmmsg",
6397 int, s
, const struct mmsghdr
*, mmsg
, int, vlen
, int, flags
);
6398 ML_(linux_PRE_sys_sendmmsg
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
);
6403 ML_(linux_POST_sys_sendmmsg
) (tid
, RES
, ARG1
,ARG2
,ARG3
,ARG4
);
6408 *flags
|= SfMayBlock
;
6409 PRINT("sys_recvmmsg ( %ld, %#" FMT_REGWORD
"x, %ld, %ld, %#"
6411 SARG1
, ARG2
, SARG3
, SARG4
, ARG5
);
6412 PRE_REG_READ5(long, "recvmmsg",
6413 int, s
, struct mmsghdr
*, mmsg
, int, vlen
,
6414 int, flags
, struct timespec
*, timeout
);
6415 ML_(linux_PRE_sys_recvmmsg
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
6420 ML_(linux_POST_sys_recvmmsg
) (tid
, RES
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
6423 PRE(sys_recvmmsg_time64
)
6425 *flags
|= SfMayBlock
;
6426 PRINT("sys_recvmmsg_time64 ( %ld, %#" FMT_REGWORD
"x, %ld, %ld, %#"
6428 SARG1
, ARG2
, SARG3
, SARG4
, ARG5
);
6429 PRE_REG_READ5(long, "recvmmsg_time64",
6430 int, s
, struct mmsghdr
*, mmsg
, int, vlen
,
6431 int, flags
, struct vki_timespec64
*, timeout
);
6432 struct vki_mmsghdr
*mmsg
= (struct vki_mmsghdr
*)ARG2
;
6433 HChar name
[40]; // large enough
6435 for (i
= 0; i
< ARG3
; i
++) {
6436 VG_(sprintf
)(name
, "mmsg[%u].msg_hdr", i
);
6437 ML_(generic_PRE_sys_recvmsg
)(tid
, name
, &mmsg
[i
].msg_hdr
);
6438 VG_(sprintf
)(name
, "recvmmsg(mmsg[%u].msg_len)", i
);
6439 PRE_MEM_WRITE( name
, (Addr
)&mmsg
[i
].msg_len
, sizeof(mmsg
[i
].msg_len
) );
6442 pre_read_timespec64(tid
, "recvmmsg(timeout)", ARG5
);
6445 POST(sys_recvmmsg_time64
)
6447 /* ARG5 isn't actually used, so just use the generic POST. */
6448 ML_(linux_POST_sys_recvmmsg
) (tid
, RES
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
6451 /* ---------------------------------------------------------------------
6452 key retention service wrappers
6453 ------------------------------------------------------------------ */
6455 PRE(sys_request_key
)
6457 PRINT("sys_request_key ( %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x(%s), %#"
6458 FMT_REGWORD
"x(%s), %ld )", ARG1
, (HChar
*)(Addr
)ARG1
, ARG2
,
6459 (HChar
*)(Addr
)ARG2
, ARG3
, (HChar
*)(Addr
)ARG3
, SARG4
);
6460 PRE_REG_READ4(long, "request_key",
6461 const char *, type
, const char *, description
,
6462 const char *, callout_info
, vki_key_serial_t
, keyring
);
6463 PRE_MEM_RASCIIZ( "request_key(type)", ARG1
);
6464 PRE_MEM_RASCIIZ( "request_key(description)", ARG2
);
6465 if (ARG3
!= (UWord
)NULL
)
6466 PRE_MEM_RASCIIZ( "request_key(callout_info)", ARG3
);
6471 PRINT("sys_add_key ( %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x(%s), %#"
6472 FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld )", ARG1
, (HChar
*)(Addr
)ARG1
,
6473 ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
, SARG5
);
6474 PRE_REG_READ5(long, "add_key",
6475 const char *, type
, const char *, description
,
6476 const void *, payload
, vki_size_t
, plen
,
6477 vki_key_serial_t
, keyring
);
6478 PRE_MEM_RASCIIZ( "add_key(type)", ARG1
);
6479 PRE_MEM_RASCIIZ( "add_key(description)", ARG2
);
6480 if (ARG3
!= (UWord
)NULL
)
6481 PRE_MEM_READ( "request_key(payload)", ARG3
, ARG4
);
6486 switch (ARG1
/* option */) {
6487 case VKI_KEYCTL_GET_KEYRING_ID
:
6488 PRINT("sys_keyctl ( KEYCTL_GET_KEYRING_ID, %ld, %ld )", SARG2
, SARG3
);
6489 PRE_REG_READ3(long, "keyctl(KEYCTL_GET_KEYRING_ID)",
6490 int, option
, vki_key_serial_t
, id
, int, create
);
6492 case VKI_KEYCTL_JOIN_SESSION_KEYRING
:
6493 PRINT("sys_keyctl ( KEYCTL_JOIN_SESSION_KEYRING, %#" FMT_REGWORD
6494 "x(%s) )", ARG2
,(char*)(Addr
)ARG2
);
6495 PRE_REG_READ2(long, "keyctl(KEYCTL_JOIN_SESSION_KEYRING)",
6496 int, option
, const char *, name
);
6497 if (ARG2
!= (UWord
)NULL
)
6498 PRE_MEM_RASCIIZ("keyctl(KEYCTL_JOIN_SESSION_KEYRING, name)", ARG2
);
6500 case VKI_KEYCTL_UPDATE
:
6501 PRINT("sys_keyctl ( KEYCTL_UPDATE, %ld, %#" FMT_REGWORD
"x, %"
6502 FMT_REGWORD
"u )", SARG2
, ARG3
, ARG4
);
6503 PRE_REG_READ4(long, "keyctl(KEYCTL_UPDATE)",
6504 int, option
, vki_key_serial_t
, key
,
6505 const void *, payload
, vki_size_t
, plen
);
6506 if (ARG3
!= (UWord
)NULL
)
6507 PRE_MEM_READ("keyctl(KEYCTL_UPDATE, payload)", ARG3
, ARG4
);
6509 case VKI_KEYCTL_REVOKE
:
6510 PRINT("sys_keyctl ( KEYCTL_REVOKE, %ld )", SARG2
);
6511 PRE_REG_READ2(long, "keyctl(KEYCTL_REVOKE)",
6512 int, option
, vki_key_serial_t
, id
);
6514 case VKI_KEYCTL_CHOWN
:
6515 PRINT("sys_keyctl ( KEYCTL_CHOWN, %ld, %" FMT_REGWORD
"u, %"
6516 FMT_REGWORD
"u )", SARG2
, ARG3
, ARG4
);
6517 PRE_REG_READ4(long, "keyctl(KEYCTL_CHOWN)",
6518 int, option
, vki_key_serial_t
, id
,
6519 vki_uid_t
, uid
, vki_gid_t
, gid
);
6521 case VKI_KEYCTL_SETPERM
:
6522 PRINT("sys_keyctl ( KEYCTL_SETPERM, %ld, %" FMT_REGWORD
"u )",
6524 PRE_REG_READ3(long, "keyctl(KEYCTL_SETPERM)",
6525 int, option
, vki_key_serial_t
, id
, vki_key_perm_t
, perm
);
6527 case VKI_KEYCTL_DESCRIBE
:
6528 PRINT("sys_keyctl ( KEYCTL_DESCRIBE, %ld, %#" FMT_REGWORD
"x, %"
6529 FMT_REGWORD
"u )", SARG2
, ARG3
, ARG4
);
6530 PRE_REG_READ4(long, "keyctl(KEYCTL_DESCRIBE)",
6531 int, option
, vki_key_serial_t
, id
,
6532 char *, buffer
, vki_size_t
, buflen
);
6533 if (ARG3
!= (UWord
)NULL
)
6534 PRE_MEM_WRITE("keyctl(KEYCTL_DESCRIBE, buffer)", ARG3
, ARG4
);
6536 case VKI_KEYCTL_CLEAR
:
6537 PRINT("sys_keyctl ( KEYCTL_CLEAR, %ld )", SARG2
);
6538 PRE_REG_READ2(long, "keyctl(KEYCTL_CLEAR)",
6539 int, option
, vki_key_serial_t
, keyring
);
6541 case VKI_KEYCTL_LINK
:
6542 PRINT("sys_keyctl ( KEYCTL_LINK, %ld, %ld )", SARG2
, SARG3
);
6543 PRE_REG_READ3(long, "keyctl(KEYCTL_LINK)", int, option
,
6544 vki_key_serial_t
, keyring
, vki_key_serial_t
, key
);
6546 case VKI_KEYCTL_UNLINK
:
6547 PRINT("sys_keyctl ( KEYCTL_UNLINK, %ld, %ld )", SARG2
, SARG3
);
6548 PRE_REG_READ3(long, "keyctl(KEYCTL_UNLINK)", int, option
,
6549 vki_key_serial_t
, keyring
, vki_key_serial_t
, key
);
6551 case VKI_KEYCTL_SEARCH
:
6552 PRINT("sys_keyctl ( KEYCTL_SEARCH, %ld, %#" FMT_REGWORD
"x(%s), %#"
6553 FMT_REGWORD
"x(%s), %ld )", SARG2
, ARG3
, (HChar
*)(Addr
)ARG3
,
6554 ARG4
, (HChar
*)(Addr
)ARG4
, SARG5
);
6555 PRE_REG_READ5(long, "keyctl(KEYCTL_SEARCH)",
6556 int, option
, vki_key_serial_t
, keyring
,
6557 const char *, type
, const char *, description
,
6558 vki_key_serial_t
, destring
);
6559 PRE_MEM_RASCIIZ("sys_keyctl(KEYCTL_SEARCH, type)", ARG3
);
6560 PRE_MEM_RASCIIZ("sys_keyctl(KEYCTL_SEARCH, description)", ARG4
);
6562 case VKI_KEYCTL_READ
:
6563 PRINT("sys_keyctl ( KEYCTL_READ, %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
6564 "u )", SARG2
, ARG3
, ARG4
);
6565 PRE_REG_READ4(long, "keyctl(KEYCTL_READ)",
6566 int, option
, vki_key_serial_t
, keyring
,
6567 char *, buffer
, vki_size_t
, buflen
);
6568 if (ARG3
!= (UWord
)NULL
)
6569 PRE_MEM_WRITE("keyctl(KEYCTL_READ, buffer)", ARG3
, ARG4
);
6571 case VKI_KEYCTL_INSTANTIATE
:
6572 PRINT("sys_keyctl ( KEYCTL_INSTANTIATE, %ld, %#" FMT_REGWORD
"x, %"
6573 FMT_REGWORD
"u, %ld )", SARG2
, ARG3
, ARG4
, SARG5
);
6574 PRE_REG_READ5(long, "keyctl(KEYCTL_INSTANTIATE)",
6575 int, option
, vki_key_serial_t
, key
,
6576 char *, payload
, vki_size_t
, plen
,
6577 vki_key_serial_t
, keyring
);
6578 if (ARG3
!= (UWord
)NULL
)
6579 PRE_MEM_READ("keyctl(KEYCTL_INSTANTIATE, payload)", ARG3
, ARG4
);
6581 case VKI_KEYCTL_NEGATE
:
6582 PRINT("sys_keyctl ( KEYCTL_NEGATE, %ld, %" FMT_REGWORD
"u, %ld )",
6583 SARG2
, ARG3
, SARG4
);
6584 PRE_REG_READ4(long, "keyctl(KEYCTL_NEGATE)",
6585 int, option
, vki_key_serial_t
, key
,
6586 unsigned, timeout
, vki_key_serial_t
, keyring
);
6588 case VKI_KEYCTL_SET_REQKEY_KEYRING
:
6589 PRINT("sys_keyctl ( KEYCTL_SET_REQKEY_KEYRING, %ld )", SARG2
);
6590 PRE_REG_READ2(long, "keyctl(KEYCTL_SET_REQKEY_KEYRING)",
6591 int, option
, int, reqkey_defl
);
6593 case VKI_KEYCTL_SET_TIMEOUT
:
6594 PRINT("sys_keyctl ( KEYCTL_SET_TIMEOUT, %ld, %" FMT_REGWORD
"u )",
6596 PRE_REG_READ3(long, "keyctl(KEYCTL_SET_TIMEOUT)",
6597 int, option
, vki_key_serial_t
, key
, unsigned, timeout
);
6599 case VKI_KEYCTL_ASSUME_AUTHORITY
:
6600 PRINT("sys_keyctl ( KEYCTL_ASSUME_AUTHORITY, %ld )", SARG2
);
6601 PRE_REG_READ2(long, "keyctl(KEYCTL_ASSUME_AUTHORITY)",
6602 int, option
, vki_key_serial_t
, key
);
6605 PRINT("sys_keyctl ( %ld ) ", SARG1
);
6606 PRE_REG_READ1(long, "keyctl", int, option
);
6614 switch (ARG1
/* option */) {
6615 case VKI_KEYCTL_DESCRIBE
:
6616 case VKI_KEYCTL_READ
:
6618 POST_MEM_WRITE(ARG3
, ARG4
);
6620 POST_MEM_WRITE(ARG3
, RES
);
6627 /* ---------------------------------------------------------------------
6629 ------------------------------------------------------------------ */
6633 PRINT("sys_ioprio_set ( %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
);
6634 PRE_REG_READ3(int, "ioprio_set", int, which
, int, who
, int, ioprio
);
6639 PRINT("sys_ioprio_get ( %ld, %ld )", SARG1
, SARG2
);
6640 PRE_REG_READ2(int, "ioprio_get", int, which
, int, who
);
6643 /* ---------------------------------------------------------------------
6645 ------------------------------------------------------------------ */
6647 PRE(sys_init_module
)
6649 *flags
|= SfMayBlock
;
6650 PRINT("sys_init_module ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#"
6651 FMT_REGWORD
"x(\"%s\") )", ARG1
, ARG2
, ARG3
, (HChar
*)(Addr
)ARG3
);
6652 PRE_REG_READ3(long, "init_module",
6653 void *, umod
, unsigned long, len
, const char *, uargs
);
6654 PRE_MEM_READ( "init_module(umod)", ARG1
, ARG2
);
6655 PRE_MEM_RASCIIZ( "init_module(uargs)", ARG3
);
6658 PRE(sys_finit_module
)
6660 *flags
|= SfMayBlock
;
6662 PRINT("sys_finit_module ( %" FMT_REGWORD
"x, %#" FMT_REGWORD
"x(\"%s\"), %"
6663 FMT_REGWORD
"x )", ARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
);
6664 PRE_REG_READ3(long, "finit_module",
6665 int, fd
, const char *, params
, int, flags
);
6666 PRE_MEM_RASCIIZ("finit_module(params)", ARG2
);
6669 PRE(sys_delete_module
)
6671 *flags
|= SfMayBlock
;
6672 PRINT("sys_delete_module ( %#" FMT_REGWORD
"x(\"%s\"), 0x%" FMT_REGWORD
6673 "x )", ARG1
, (HChar
*)(Addr
)ARG1
, ARG2
);
6674 PRE_REG_READ2(long, "delete_module",
6675 const char *, name_user
, unsigned int, flags
);
6676 PRE_MEM_RASCIIZ("delete_module(name_user)", ARG1
);
6679 /* ---------------------------------------------------------------------
6681 ------------------------------------------------------------------ */
6685 *flags
|= SfMayBlock
;
6686 PRINT("sys_splice ( %ld, %#" FMT_REGWORD
"x, %ld, %#"
6687 FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
6688 SARG1
, ARG2
, SARG3
, ARG4
, ARG5
, ARG6
);
6689 PRE_REG_READ6(vki_ssize_t
, "splice",
6690 int, fd_in
, vki_loff_t
*, off_in
,
6691 int, fd_out
, vki_loff_t
*, off_out
,
6692 vki_size_t
, len
, unsigned int, flags
);
6693 if (!ML_(fd_allowed
)(ARG1
, "splice(fd_in)", tid
, False
) ||
6694 !ML_(fd_allowed
)(ARG3
, "splice(fd_out)", tid
, False
)) {
6695 SET_STATUS_Failure( VKI_EBADF
);
6698 PRE_MEM_READ( "splice(off_in)", ARG2
, sizeof(vki_loff_t
));
6700 PRE_MEM_READ( "splice(off_out)", ARG4
, sizeof(vki_loff_t
));
6706 *flags
|= SfMayBlock
;
6707 PRINT("sys_tree ( %ld, %ld, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
6708 SARG1
, SARG2
, ARG3
, ARG4
);
6709 PRE_REG_READ4(vki_ssize_t
, "tee",
6710 int, fd_in
, int, fd_out
,
6711 vki_size_t
, len
, unsigned int, flags
);
6712 if (!ML_(fd_allowed
)(ARG1
, "tee(fd_in)", tid
, False
) ||
6713 !ML_(fd_allowed
)(ARG2
, "tee(fd_out)", tid
, False
)) {
6714 SET_STATUS_Failure( VKI_EBADF
);
6721 *flags
|= SfMayBlock
;
6722 PRINT("sys_vmsplice ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
6723 FMT_REGWORD
"u )", SARG1
, ARG2
, ARG3
, ARG4
);
6724 PRE_REG_READ4(vki_ssize_t
, "splice",
6725 int, fd
, struct vki_iovec
*, iov
,
6726 unsigned long, nr_segs
, unsigned int, flags
);
6727 if (!ML_(fd_allowed
)(ARG1
, "vmsplice(fd)", tid
, False
)) {
6728 SET_STATUS_Failure( VKI_EBADF
);
6729 } else if ((fdfl
= VG_(fcntl
)(ARG1
, VKI_F_GETFL
, 0)) < 0) {
6730 SET_STATUS_Failure( VKI_EBADF
);
6732 const struct vki_iovec
*iov
;
6733 PRE_MEM_READ( "vmsplice(iov)", ARG2
, sizeof(struct vki_iovec
) * ARG3
);
6734 for (iov
= (struct vki_iovec
*)(Addr
)ARG2
;
6735 iov
< (struct vki_iovec
*)(Addr
)ARG2
+ ARG3
; iov
++)
6737 if (ML_(safe_to_deref
) (iov
, sizeof(struct vki_iovec
))) {
6738 if ((fdfl
& VKI_O_ACCMODE
) == VKI_O_RDONLY
)
6739 PRE_MEM_WRITE( "vmsplice(iov[...])",
6740 (Addr
)iov
->iov_base
, iov
->iov_len
);
6742 PRE_MEM_READ( "vmsplice(iov[...])",
6743 (Addr
)iov
->iov_base
, iov
->iov_len
);
6753 Int fdfl
= VG_(fcntl
)(ARG1
, VKI_F_GETFL
, 0);
6754 vg_assert(fdfl
>= 0);
6755 if ((fdfl
& VKI_O_ACCMODE
) == VKI_O_RDONLY
)
6757 const struct vki_iovec
*iov
;
6758 for (iov
= (struct vki_iovec
*)(Addr
)ARG2
;
6759 iov
< (struct vki_iovec
*)(Addr
)ARG2
+ ARG3
; iov
++)
6761 POST_MEM_WRITE( (Addr
)iov
->iov_base
, iov
->iov_len
);
6767 /* ---------------------------------------------------------------------
6768 oprofile-related wrappers
6769 ------------------------------------------------------------------ */
6771 #if defined(VGP_x86_linux)
6772 PRE(sys_lookup_dcookie
)
6774 PRINT("sys_lookup_dcookie (0x%llx, %#lx, %lu)",
6775 MERGE64(ARG1
,ARG2
), ARG3
, ARG4
);
6776 PRE_REG_READ4(long, "lookup_dcookie",
6777 vki_u32
, MERGE64_FIRST(cookie
), vki_u32
, MERGE64_SECOND(cookie
),
6778 char *, buf
, vki_size_t
, len
);
6779 PRE_MEM_WRITE( "lookup_dcookie(buf)", ARG3
, ARG4
);
6781 POST(sys_lookup_dcookie
)
6784 if (ARG3
!= (Addr
)NULL
)
6785 POST_MEM_WRITE( ARG3
, RES
);
6789 #if defined(VGP_amd64_linux) || defined(VGP_s390x_linux) \
6790 || defined(VGP_arm64_linux) || defined(VGP_nanomips_linux)
6791 PRE(sys_lookup_dcookie
)
6793 *flags
|= SfMayBlock
;
6794 PRINT("sys_lookup_dcookie ( %lu, %#lx, %lu )", ARG1
, ARG2
, ARG3
);
6795 PRE_REG_READ3(int, "lookup_dcookie",
6796 unsigned long long, cookie
, char *, buf
, vki_size_t
, len
);
6798 PRE_MEM_WRITE( "sys_lookup_dcookie(buf)", ARG2
, ARG3
);
6801 POST(sys_lookup_dcookie
)
6804 if (ARG2
!= (Addr
)NULL
)
6805 POST_MEM_WRITE( ARG2
, RES
);
6809 /* ---------------------------------------------------------------------
6811 ------------------------------------------------------------------ */
6816 // These ones ignore ARG3.
6821 case VKI_F_GETLEASE
:
6822 case VKI_F_GETPIPE_SZ
:
6823 case VKI_F_GET_SEALS
:
6824 PRINT("sys_fcntl ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )", ARG1
, ARG2
);
6825 PRE_REG_READ2(long, "fcntl", unsigned int, fd
, unsigned int, cmd
);
6828 // These ones use ARG3 as "arg".
6830 case VKI_F_DUPFD_CLOEXEC
:
6833 case VKI_F_SETLEASE
:
6837 case VKI_F_SETPIPE_SZ
:
6838 case VKI_F_ADD_SEALS
:
6839 PRINT("sys_fcntl[ARG3=='arg'] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6840 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6841 PRE_REG_READ3(long, "fcntl",
6842 unsigned int, fd
, unsigned int, cmd
, unsigned long, arg
);
6845 // These ones use ARG3 as "lock".
6849 case VKI_F_OFD_GETLK
:
6850 case VKI_F_OFD_SETLK
:
6851 case VKI_F_OFD_SETLKW
:
6852 PRINT("sys_fcntl[ARG3=='lock'] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6853 "u, %#" FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
6854 PRE_REG_READ3(long, "fcntl",
6855 unsigned int, fd
, unsigned int, cmd
,
6856 struct vki_flock
*, lock
);
6858 struct vki_flock
*lock
= (struct vki_flock
*) (Addr
)ARG3
;
6859 PRE_FIELD_READ("fcntl(lock->l_type)", lock
->l_type
);
6860 PRE_FIELD_READ("fcntl(lock->l_whence)", lock
->l_whence
);
6861 PRE_FIELD_READ("fcntl(lock->l_start)", lock
->l_start
);
6862 PRE_FIELD_READ("fcntl(lock->l_len)", lock
->l_len
);
6863 if (ARG2
== VKI_F_GETLK
|| ARG2
== VKI_F_OFD_GETLK
) {
6864 PRE_FIELD_WRITE("fcntl(lock->l_pid)", lock
->l_pid
);
6869 # if defined(VGP_x86_linux) || defined(VGP_mips64_linux)
6872 case VKI_F_SETLKW64
:
6873 PRINT("sys_fcntl[ARG3=='lock'] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6874 "u, %#" FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
6875 PRE_REG_READ3(long, "fcntl",
6876 unsigned int, fd
, unsigned int, cmd
,
6877 struct flock64
*, lock
);
6879 struct vki_flock64
*lock
= (struct vki_flock64
*) (Addr
)ARG3
;
6880 PRE_FIELD_READ("fcntl(lock->l_type)", lock
->l_type
);
6881 PRE_FIELD_READ("fcntl(lock->l_whence)", lock
->l_whence
);
6882 PRE_FIELD_READ("fcntl(lock->l_start)", lock
->l_start
);
6883 PRE_FIELD_READ("fcntl(lock->l_len)", lock
->l_len
);
6884 if (ARG2
== VKI_F_GETLK64
) {
6885 PRE_FIELD_WRITE("fcntl(lock->l_pid)", lock
->l_pid
);
6891 case VKI_F_SETOWN_EX
:
6892 PRINT("sys_fcntl[F_SETOWN_EX] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6893 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6894 PRE_REG_READ3(long, "fcntl",
6895 unsigned int, fd
, unsigned int, cmd
,
6896 struct vki_f_owner_ex
*, arg
);
6897 PRE_MEM_READ("fcntl(F_SETOWN_EX)", ARG3
, sizeof(struct vki_f_owner_ex
));
6900 case VKI_F_GETOWN_EX
:
6901 PRINT("sys_fcntl[F_GETOWN_EX] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6902 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6903 PRE_REG_READ3(long, "fcntl",
6904 unsigned int, fd
, unsigned int, cmd
,
6905 struct vki_f_owner_ex
*, arg
);
6906 PRE_MEM_WRITE("fcntl(F_GETOWN_EX)", ARG3
, sizeof(struct vki_f_owner_ex
));
6910 PRINT("sys_fcntl[UNKNOWN] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
6911 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6912 VG_(umsg
)("Warning: unimplemented fcntl command: %" FMT_REGWORD
"u\n",
6914 SET_STATUS_Failure( VKI_EINVAL
);
6918 # if defined(VGP_x86_linux)
6919 if (ARG2
== VKI_F_SETLKW
|| ARG2
== VKI_F_SETLKW64
)
6921 if (ARG2
== VKI_F_SETLKW
)
6923 *flags
|= SfMayBlock
;
6929 if (ARG2
== VKI_F_DUPFD
) {
6930 if (!ML_(fd_allowed
)(RES
, "fcntl(DUPFD)", tid
, True
)) {
6932 SET_STATUS_Failure( VKI_EMFILE
);
6934 if (VG_(clo_track_fds
))
6935 ML_(record_fd_open_named
)(tid
, RES
);
6938 else if (ARG2
== VKI_F_DUPFD_CLOEXEC
) {
6939 if (!ML_(fd_allowed
)(RES
, "fcntl(DUPFD_CLOEXEC)", tid
, True
)) {
6941 SET_STATUS_Failure( VKI_EMFILE
);
6943 if (VG_(clo_track_fds
))
6944 ML_(record_fd_open_named
)(tid
, RES
);
6946 } else if (ARG2
== VKI_F_GETOWN_EX
) {
6947 POST_MEM_WRITE(ARG3
, sizeof(struct vki_f_owner_ex
));
6948 } else if (ARG2
== VKI_F_GETLK
|| ARG2
== VKI_F_OFD_GETLK
) {
6949 struct vki_flock
*lock
= (struct vki_flock
*) (Addr
)ARG3
;
6950 POST_FIELD_WRITE(lock
->l_pid
);
6951 # if defined(VGP_x86_linux) || defined(VGP_mips64_linux)
6952 } else if (ARG2
== VKI_F_GETLK64
) {
6953 struct vki_flock64
*lock
= (struct vki_flock64
*) (Addr
)ARG3
;
6954 PRE_FIELD_WRITE("fcntl(lock->l_pid)", lock
->l_pid
);
6959 // XXX: wrapper only suitable for 32-bit systems
6963 // These ones ignore ARG3.
6970 case VKI_F_GETLEASE
:
6971 case VKI_F_GET_SEALS
:
6972 PRINT("sys_fcntl64 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )", ARG1
, ARG2
);
6973 PRE_REG_READ2(long, "fcntl64", unsigned int, fd
, unsigned int, cmd
);
6976 // These ones use ARG3 as "arg".
6978 case VKI_F_DUPFD_CLOEXEC
:
6981 case VKI_F_SETLEASE
:
6983 case VKI_F_ADD_SEALS
:
6984 PRINT("sys_fcntl64[ARG3=='arg'] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6985 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6986 PRE_REG_READ3(long, "fcntl64",
6987 unsigned int, fd
, unsigned int, cmd
, unsigned long, arg
);
6990 // These ones use ARG3 as "lock".
6994 # if defined(VGP_x86_linux)
6997 case VKI_F_SETLKW64
:
6999 case VKI_F_OFD_GETLK
:
7000 case VKI_F_OFD_SETLK
:
7001 case VKI_F_OFD_SETLKW
:
7002 PRINT("sys_fcntl64[ARG3=='lock'] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
7003 "u, %#" FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
7004 PRE_REG_READ3(long, "fcntl64",
7005 unsigned int, fd
, unsigned int, cmd
,
7006 struct flock64
*, lock
);
7009 case VKI_F_SETOWN_EX
:
7010 PRINT("sys_fcntl[F_SETOWN_EX] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
7011 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
7012 PRE_REG_READ3(long, "fcntl",
7013 unsigned int, fd
, unsigned int, cmd
,
7014 struct vki_f_owner_ex
*, arg
);
7015 PRE_MEM_READ("fcntl(F_SETOWN_EX)", ARG3
, sizeof(struct vki_f_owner_ex
));
7018 case VKI_F_GETOWN_EX
:
7019 PRINT("sys_fcntl[F_GETOWN_EX] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
7020 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
7021 PRE_REG_READ3(long, "fcntl",
7022 unsigned int, fd
, unsigned int, cmd
,
7023 struct vki_f_owner_ex
*, arg
);
7024 PRE_MEM_WRITE("fcntl(F_GETOWN_EX)", ARG3
, sizeof(struct vki_f_owner_ex
));
7028 # if defined(VGP_x86_linux)
7029 if (ARG2
== VKI_F_SETLKW
|| ARG2
== VKI_F_SETLKW64
)
7031 if (ARG2
== VKI_F_SETLKW
)
7033 *flags
|= SfMayBlock
;
7039 if (ARG2
== VKI_F_DUPFD
) {
7040 if (!ML_(fd_allowed
)(RES
, "fcntl64(DUPFD)", tid
, True
)) {
7042 SET_STATUS_Failure( VKI_EMFILE
);
7044 if (VG_(clo_track_fds
))
7045 ML_(record_fd_open_named
)(tid
, RES
);
7048 else if (ARG2
== VKI_F_DUPFD_CLOEXEC
) {
7049 if (!ML_(fd_allowed
)(RES
, "fcntl64(DUPFD_CLOEXEC)", tid
, True
)) {
7051 SET_STATUS_Failure( VKI_EMFILE
);
7053 if (VG_(clo_track_fds
))
7054 ML_(record_fd_open_named
)(tid
, RES
);
7056 } else if (ARG2
== VKI_F_GETOWN_EX
) {
7057 POST_MEM_WRITE(ARG3
, sizeof(struct vki_f_owner_ex
));
7061 /* ---------------------------------------------------------------------
7063 ------------------------------------------------------------------ */
7065 struct vg_drm_version_info
{
7066 struct vki_drm_version data
;
7067 struct vki_drm_version
*orig
; // Original ARG3 pointer value at syscall entry.
7072 *flags
|= SfMayBlock
;
7076 // We first handle the ones that don't use ARG3 (even as a
7077 // scalar/non-pointer argument).
7078 switch (ARG2
/* request */) {
7080 /* asm-generic/ioctls.h */
7085 /* linux perf_event ioctls */
7086 case VKI_PERF_EVENT_IOC_ENABLE
:
7087 case VKI_PERF_EVENT_IOC_DISABLE
:
7089 /* linux/soundcard interface (ALSA) */
7090 case VKI_SNDRV_PCM_IOCTL_HW_FREE
:
7091 case VKI_SNDRV_PCM_IOCTL_HWSYNC
:
7092 case VKI_SNDRV_PCM_IOCTL_PREPARE
:
7093 case VKI_SNDRV_PCM_IOCTL_RESET
:
7094 case VKI_SNDRV_PCM_IOCTL_START
:
7095 case VKI_SNDRV_PCM_IOCTL_DROP
:
7096 case VKI_SNDRV_PCM_IOCTL_DRAIN
:
7097 case VKI_SNDRV_PCM_IOCTL_RESUME
:
7098 case VKI_SNDRV_PCM_IOCTL_XRUN
:
7099 case VKI_SNDRV_PCM_IOCTL_UNLINK
:
7100 case VKI_SNDRV_TIMER_IOCTL_START
:
7101 case VKI_SNDRV_TIMER_IOCTL_STOP
:
7102 case VKI_SNDRV_TIMER_IOCTL_CONTINUE
:
7103 case VKI_SNDRV_TIMER_IOCTL_PAUSE
:
7105 /* SCSI no operand */
7106 case VKI_SCSI_IOCTL_DOORLOCK
:
7107 case VKI_SCSI_IOCTL_DOORUNLOCK
:
7110 case VKI_CDROM_DISC_STATUS
:
7114 case VKI_DVD_READ_STRUCT
:
7116 /* KVM ioctls that don't check for a numeric value as parameter */
7117 case VKI_KVM_S390_ENABLE_SIE
:
7118 case VKI_KVM_CREATE_IRQCHIP
:
7119 case VKI_KVM_S390_INITIAL_RESET
:
7120 case VKI_KVM_KVMCLOCK_CTRL
:
7122 /* vhost without parameter */
7123 case VKI_VHOST_SET_OWNER
:
7124 case VKI_VHOST_RESET_OWNER
:
7126 /* User input device creation */
7127 case VKI_UI_DEV_CREATE
:
7128 case VKI_UI_DEV_DESTROY
:
7131 case VKI_IB_USER_MAD_ENABLE_PKEY
:
7134 case VKI_LL_IOC_GROUP_LOCK
:
7135 case VKI_LL_IOC_GROUP_UNLOCK
:
7138 case VKI_V4L2_LOG_STATUS
:
7141 case VKI_DRM_IOCTL_I915_GEM_THROTTLE
:
7145 PRINT("sys_ioctl ( %" FMT_REGWORD
"u, 0x%" FMT_REGWORD
"x )", ARG1
, ARG2
);
7146 PRE_REG_READ2(long, "ioctl",
7147 unsigned int, fd
, unsigned int, request
);
7151 PRINT("sys_ioctl ( %" FMT_REGWORD
"u, 0x%" FMT_REGWORD
"x, 0x%"
7152 FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
7153 PRE_REG_READ3(long, "ioctl",
7154 unsigned int, fd
, unsigned int, request
, unsigned long, arg
);
7158 // We now handle those that do look at ARG3 (and unknown ones fall into
7159 // this category). Nb: some of these may well belong in the
7160 // doesn't-use-ARG3 switch above.
7161 switch (ARG2
/* request */) {
7163 case VKI_ION_IOC_ALLOC
: {
7164 struct vki_ion_allocation_data
* data
7165 = (struct vki_ion_allocation_data
*)(Addr
)ARG3
;
7166 PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).len", data
->len
);
7167 PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).align", data
->align
);
7168 PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).heap_id_mask", data
->heap_id_mask
);
7169 PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).flags", data
->flags
);
7170 PRE_FIELD_WRITE("ioctl(ION_IOC_ALLOC).handle", data
->handle
);
7173 case VKI_ION_IOC_MAP
: {
7174 struct vki_ion_fd_data
* data
= (struct vki_ion_fd_data
*)(Addr
)ARG3
;
7175 PRE_FIELD_READ ("ioctl(ION_IOC_MAP).handle", data
->handle
);
7176 PRE_FIELD_WRITE("ioctl(ION_IOC_MAP).fd", data
->fd
);
7179 case VKI_ION_IOC_IMPORT
: {
7180 struct vki_ion_fd_data
* data
= (struct vki_ion_fd_data
*)(Addr
)ARG3
;
7181 PRE_FIELD_READ ("ioctl(ION_IOC_IMPORT).fd", data
->fd
);
7182 PRE_FIELD_WRITE("ioctl(ION_IOC_IMPORT).handle", data
->handle
);
7186 case VKI_SYNC_IOC_MERGE
: {
7187 struct vki_sync_merge_data
* data
=
7188 (struct vki_sync_merge_data
*)(Addr
)ARG3
;
7189 PRE_FIELD_READ ("ioctl(SYNC_IOC_MERGE).fd2", data
->fd2
);
7190 PRE_MEM_RASCIIZ("ioctl(SYNC_IOC_MERGE).name", (Addr
)(&data
->name
[0]));
7191 PRE_FIELD_WRITE("ioctl(SYNC_IOC_MERGE).fence", data
->fence
);
7198 PRE_MEM_READ( "ioctl(TCSET{S,SW,SF})", ARG3
, sizeof(struct vki_termios
) );
7201 PRE_MEM_WRITE( "ioctl(TCGETS)", ARG3
, sizeof(struct vki_termios
) );
7206 PRE_MEM_READ( "ioctl(TCSET{A,AW,AF})", ARG3
, sizeof(struct vki_termio
) );
7209 PRE_MEM_WRITE( "ioctl(TCGETA)", ARG3
, sizeof(struct vki_termio
) );
7216 /* These just take an int by value */
7218 case VKI_TIOCGWINSZ
:
7219 PRE_MEM_WRITE( "ioctl(TIOCGWINSZ)", ARG3
, sizeof(struct vki_winsize
) );
7221 case VKI_TIOCSWINSZ
:
7222 PRE_MEM_READ( "ioctl(TIOCSWINSZ)", ARG3
, sizeof(struct vki_winsize
) );
7225 PRE_MEM_READ( "ioctl(TIOCMBIS)", ARG3
, sizeof(unsigned int) );
7228 PRE_MEM_READ( "ioctl(TIOCMBIC)", ARG3
, sizeof(unsigned int) );
7231 PRE_MEM_READ( "ioctl(TIOCMSET)", ARG3
, sizeof(unsigned int) );
7234 PRE_MEM_WRITE( "ioctl(TIOCMGET)", ARG3
, sizeof(unsigned int) );
7237 PRE_MEM_READ( "ioctl(TIOCLINUX)", ARG3
, sizeof(char *) );
7238 if (*(char *)(Addr
)ARG3
== 11) {
7239 PRE_MEM_READ( "ioctl(TIOCLINUX, 11)", ARG3
, 2 * sizeof(char *) );
7243 /* Get process group ID for foreground processing group. */
7244 PRE_MEM_WRITE( "ioctl(TIOCGPGRP)", ARG3
, sizeof(vki_pid_t
) );
7247 /* Set a process group ID? */
7248 PRE_MEM_WRITE( "ioctl(TIOCGPGRP)", ARG3
, sizeof(vki_pid_t
) );
7250 case VKI_TIOCGPTN
: /* Get Pty Number (of pty-mux device) */
7251 PRE_MEM_WRITE( "ioctl(TIOCGPTN)", ARG3
, sizeof(int) );
7254 /* Just takes an int value. */
7256 case VKI_TIOCSPTLCK
: /* Lock/unlock Pty */
7257 PRE_MEM_READ( "ioctl(TIOCSPTLCK)", ARG3
, sizeof(int) );
7260 PRE_MEM_READ( "ioctl(FIONBIO)", ARG3
, sizeof(int) );
7263 PRE_MEM_READ( "ioctl(FIOASYNC)", ARG3
, sizeof(int) );
7265 case VKI_FIONREAD
: /* identical to SIOCINQ */
7266 PRE_MEM_WRITE( "ioctl(FIONREAD)", ARG3
, sizeof(int) );
7269 PRE_MEM_WRITE( "ioctl(FIOQSIZE)", ARG3
, sizeof(vki_loff_t
) );
7272 case VKI_TIOCSERGETLSR
:
7273 PRE_MEM_WRITE( "ioctl(TIOCSERGETLSR)", ARG3
, sizeof(int) );
7275 case VKI_TIOCGICOUNT
:
7276 PRE_MEM_WRITE( "ioctl(TIOCGICOUNT)", ARG3
,
7277 sizeof(struct vki_serial_icounter_struct
) );
7280 case VKI_SG_SET_COMMAND_Q
:
7281 PRE_MEM_READ( "ioctl(SG_SET_COMMAND_Q)", ARG3
, sizeof(int) );
7284 PRE_MEM_READ( "ioctl(SG_IO)", ARG3
, sizeof(vki_sg_io_hdr_t
) );
7286 vki_sg_io_hdr_t
*sgio
= (vki_sg_io_hdr_t
*)(Addr
)ARG3
;
7287 PRE_MEM_READ( "ioctl(SG_IO)", (Addr
)sgio
->cmdp
, sgio
->cmd_len
);
7288 if ( sgio
->dxfer_direction
== VKI_SG_DXFER_TO_DEV
||
7289 sgio
->dxfer_direction
== VKI_SG_DXFER_TO_FROM_DEV
) {
7290 PRE_MEM_READ( "ioctl(SG_IO)", (Addr
)sgio
->dxferp
, sgio
->dxfer_len
);
7294 case VKI_SG_GET_SCSI_ID
:
7295 PRE_MEM_WRITE( "ioctl(SG_GET_SCSI_ID)", ARG3
, sizeof(vki_sg_scsi_id_t
) );
7297 case VKI_SG_SET_RESERVED_SIZE
:
7298 PRE_MEM_READ( "ioctl(SG_SET_RESERVED_SIZE)", ARG3
, sizeof(int) );
7300 case VKI_SG_SET_TIMEOUT
:
7301 PRE_MEM_READ( "ioctl(SG_SET_TIMEOUT)", ARG3
, sizeof(int) );
7303 case VKI_SG_GET_RESERVED_SIZE
:
7304 PRE_MEM_WRITE( "ioctl(SG_GET_RESERVED_SIZE)", ARG3
, sizeof(int) );
7306 case VKI_SG_GET_TIMEOUT
:
7308 case VKI_SG_GET_VERSION_NUM
:
7309 PRE_MEM_WRITE( "ioctl(SG_GET_VERSION_NUM)", ARG3
, sizeof(int) );
7311 case VKI_SG_EMULATED_HOST
: /* 0x2203 */
7312 PRE_MEM_WRITE( "ioctl(SG_EMULATED_HOST)", ARG3
, sizeof(int) );
7314 case VKI_SG_GET_SG_TABLESIZE
: /* 0x227f */
7315 PRE_MEM_WRITE( "ioctl(SG_GET_SG_TABLESIZE)", ARG3
, sizeof(int) );
7318 case VKI_IIOCGETCPS
:
7319 PRE_MEM_WRITE( "ioctl(IIOCGETCPS)", ARG3
,
7320 VKI_ISDN_MAX_CHANNELS
* 2 * sizeof(unsigned long) );
7322 case VKI_IIOCNETGPN
:
7323 PRE_MEM_READ( "ioctl(IIOCNETGPN)",
7324 (Addr
)&((vki_isdn_net_ioctl_phone
*)(Addr
)ARG3
)->name
,
7325 sizeof(((vki_isdn_net_ioctl_phone
*)(Addr
)ARG3
)->name
) );
7326 PRE_MEM_WRITE( "ioctl(IIOCNETGPN)", ARG3
,
7327 sizeof(vki_isdn_net_ioctl_phone
) );
7330 /* These all use struct ifreq AFAIK */
7331 case VKI_SIOCGIFINDEX
: /* get iface index */
7332 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFINDEX)",
7333 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7334 PRE_MEM_WRITE( "ioctl(SIOCGIFINDEX)", ARG3
, sizeof(struct vki_ifreq
));
7336 case VKI_SIOCGIFFLAGS
: /* get flags */
7337 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFFLAGS)",
7338 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7339 PRE_MEM_WRITE( "ioctl(SIOCGIFFLAGS)", ARG3
, sizeof(struct vki_ifreq
));
7341 case VKI_SIOCGIFHWADDR
: /* Get hardware address */
7342 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFHWADDR)",
7343 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7344 PRE_MEM_WRITE( "ioctl(SIOCGIFHWADDR)", ARG3
, sizeof(struct vki_ifreq
));
7346 case VKI_SIOCGIFMTU
: /* get MTU size */
7347 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMTU)",
7348 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7349 PRE_MEM_WRITE( "ioctl(SIOCGIFMTU)", ARG3
, sizeof(struct vki_ifreq
));
7351 case VKI_SIOCGIFADDR
: /* get PA address */
7352 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFADDR)",
7353 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7354 PRE_MEM_WRITE( "ioctl(SIOCGIFADDR)", ARG3
, sizeof(struct vki_ifreq
));
7356 case VKI_SIOCGIFNETMASK
: /* get network PA mask */
7357 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFNETMASK)",
7358 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7359 PRE_MEM_WRITE( "ioctl(SIOCGIFNETMASK)", ARG3
, sizeof(struct vki_ifreq
));
7361 case VKI_SIOCGIFMETRIC
: /* get metric */
7362 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMETRIC)",
7363 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7364 PRE_MEM_WRITE( "ioctl(SIOCGIFMETRIC)", ARG3
, sizeof(struct vki_ifreq
));
7366 case VKI_SIOCGIFMAP
: /* Get device parameters */
7367 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMAP)",
7368 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7369 PRE_MEM_WRITE( "ioctl(SIOCGIFMAP)", ARG3
, sizeof(struct vki_ifreq
));
7371 case VKI_SIOCGIFTXQLEN
: /* Get the tx queue length */
7372 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFTXQLEN)",
7373 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7374 PRE_MEM_WRITE( "ioctl(SIOCGIFTXQLEN)", ARG3
, sizeof(struct vki_ifreq
));
7376 case VKI_SIOCGIFDSTADDR
: /* get remote PA address */
7377 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFDSTADDR)",
7378 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7379 PRE_MEM_WRITE( "ioctl(SIOCGIFDSTADDR)", ARG3
, sizeof(struct vki_ifreq
));
7381 case VKI_SIOCGIFBRDADDR
: /* get broadcast PA address */
7382 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFBRDADDR)",
7383 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7384 PRE_MEM_WRITE( "ioctl(SIOCGIFBRDADDR)", ARG3
, sizeof(struct vki_ifreq
));
7386 case VKI_SIOCGIFNAME
: /* get iface name */
7387 PRE_MEM_READ( "ioctl(SIOCGIFNAME)",
7388 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_ifindex
,
7389 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_ifindex
));
7390 PRE_MEM_WRITE( "ioctl(SIOCGIFNAME)", ARG3
, sizeof(struct vki_ifreq
));
7393 case VKI_SIOCETHTOOL
: { /* ethtool(8) interface */
7394 struct vki_ifreq
*ir
= (struct vki_ifreq
*)(Addr
)ARG3
;
7395 // The kernel will have to look at ifr_data to determine which operation
7397 PRE_MEM_READ( "ioctl(SIOCETHTOOL,ir->ifr_data)",
7398 (Addr
)ir
->vki_ifr_data
, sizeof(vki_u32
) );
7400 PRINT("SIOCETHTOOL( 0x%x )", *(vki_u32
*)ir
->vki_ifr_data
);
7402 // Is this correct? Is ifr_name *always* looked at?
7403 PRE_MEM_RASCIIZ( "ioctl(SIOCETHTOOL,ir->ifr_name)",
7404 (Addr
)ir
->vki_ifr_name
);
7406 // At least for ETHTOOL_GSET, it is apparently incorrect to insist that
7407 // the whole structure is defined. So in this case, just check it's
7409 switch ( *(vki_u32
*)ir
->vki_ifr_data
) {
7410 case VKI_ETHTOOL_GSET
:
7411 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,ir)",
7412 (Addr
)ir
, sizeof(struct vki_ifreq
) );
7415 PRE_MEM_READ( "ioctl(SIOCETHTOOL,ir)",
7416 (Addr
)ir
, sizeof(struct vki_ifreq
) );
7420 // Now perform the relevant pre-action for the operation.
7421 switch ( *(vki_u32
*)ir
->vki_ifr_data
) {
7422 case VKI_ETHTOOL_GSET
:
7423 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GSET)",
7424 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_cmd
) );
7426 case VKI_ETHTOOL_SSET
:
7427 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SSET)",
7428 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_cmd
) );
7430 case VKI_ETHTOOL_GDRVINFO
:
7431 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GDRVINFO)",
7432 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_drvinfo
) );
7434 case VKI_ETHTOOL_GREGS
:
7435 PRE_MEM_READ( "ioctl(SIOCETHTOOL,GREGS)",
7436 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_regs
) );
7437 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GREGS)",
7438 (Addr
)((struct vki_ethtool_regs
*)ir
->vki_ifr_data
)->data
,
7439 ((struct vki_ethtool_regs
*)ir
->vki_ifr_data
)->len
);
7441 case VKI_ETHTOOL_GWOL
:
7442 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GWOL)",
7443 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_wolinfo
) );
7445 case VKI_ETHTOOL_SWOL
:
7446 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SWOL)",
7447 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_wolinfo
) );
7449 case VKI_ETHTOOL_GMSGLVL
:
7450 case VKI_ETHTOOL_GLINK
:
7451 case VKI_ETHTOOL_GRXCSUM
:
7452 case VKI_ETHTOOL_GSG
:
7453 case VKI_ETHTOOL_GTSO
:
7454 case VKI_ETHTOOL_GUFO
:
7455 case VKI_ETHTOOL_GGSO
:
7456 case VKI_ETHTOOL_GFLAGS
:
7457 case VKI_ETHTOOL_GGRO
:
7458 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,Gvalue)",
7459 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_value
) );
7461 case VKI_ETHTOOL_SMSGLVL
:
7462 case VKI_ETHTOOL_SRXCSUM
:
7463 case VKI_ETHTOOL_SSG
:
7464 case VKI_ETHTOOL_STSO
:
7465 case VKI_ETHTOOL_SUFO
:
7466 case VKI_ETHTOOL_SGSO
:
7467 case VKI_ETHTOOL_SFLAGS
:
7468 case VKI_ETHTOOL_SGRO
:
7469 PRE_MEM_READ( "ioctl(SIOCETHTOOL,Svalue)",
7470 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_value
) );
7472 case VKI_ETHTOOL_NWAY_RST
:
7474 case VKI_ETHTOOL_GRINGPARAM
:
7475 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GRINGPARAM)",
7476 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_ringparam
) );
7478 case VKI_ETHTOOL_SRINGPARAM
:
7479 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SRINGPARAM)",
7480 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_ringparam
) );
7482 case VKI_ETHTOOL_TEST
:
7483 PRE_MEM_READ( "ioctl(SIOCETHTOOL,TEST)",
7484 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_test
) );
7485 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,TEST)",
7486 (Addr
)((struct vki_ethtool_test
*)ir
->vki_ifr_data
)->data
,
7487 ((struct vki_ethtool_test
*)ir
->vki_ifr_data
)->len
* sizeof(__vki_u64
) );
7489 case VKI_ETHTOOL_PHYS_ID
:
7491 case VKI_ETHTOOL_GPERMADDR
:
7492 PRE_MEM_READ( "ioctl(SIOCETHTOOL,GPERMADDR)",
7493 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_perm_addr
) );
7494 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GPERMADDR)",
7495 (Addr
)((struct vki_ethtool_perm_addr
*)ir
->vki_ifr_data
)->data
,
7496 ((struct vki_ethtool_perm_addr
*)ir
->vki_ifr_data
)->size
);
7498 case VKI_ETHTOOL_RESET
:
7500 case VKI_ETHTOOL_GSSET_INFO
:
7501 PRE_MEM_READ( "ioctl(SIOCETHTOOL,GSSET_INFO)",
7502 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_sset_info
) );
7503 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GSSET_INFO)",
7504 (Addr
)((struct vki_ethtool_sset_info
*)ir
->vki_ifr_data
)->data
,
7505 __builtin_popcountll(((struct vki_ethtool_sset_info
*)ir
->vki_ifr_data
)->sset_mask
) * sizeof(__vki_u32
) );
7507 case VKI_ETHTOOL_GFEATURES
:
7508 PRE_MEM_READ( "ioctl(SIOCETHTOOL,GFEATURES)",
7509 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_gfeatures
) );
7510 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GFEATURES)",
7511 (Addr
)((struct vki_ethtool_gfeatures
*)ir
->vki_ifr_data
)->features
,
7512 ((struct vki_ethtool_gfeatures
*)ir
->vki_ifr_data
)->size
* sizeof(struct vki_ethtool_get_features_block
) );
7514 case VKI_ETHTOOL_SFEATURES
:
7515 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SFEATURES)",
7516 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_sfeatures
) );
7517 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SFEATURES)",
7518 (Addr
)((struct vki_ethtool_sfeatures
*)ir
->vki_ifr_data
)->features
,
7519 ((struct vki_ethtool_sfeatures
*)ir
->vki_ifr_data
)->size
* sizeof(struct vki_ethtool_set_features_block
) );
7521 case VKI_ETHTOOL_GCHANNELS
:
7522 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GCHANNELS)",
7523 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_channels
) );
7525 case VKI_ETHTOOL_SCHANNELS
:
7526 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SCHANNELS)",
7527 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_channels
) );
7529 case VKI_ETHTOOL_GET_TS_INFO
:
7530 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GET_TS_INFO)",
7531 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_ts_info
) );
7535 } /* case VKI_SIOCETHTOOL */
7537 case VKI_SIOCGMIIPHY
: /* get hardware entry */
7538 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIPHY)",
7539 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7540 PRE_MEM_WRITE( "ioctl(SIOCGIFMIIPHY)", ARG3
, sizeof(struct vki_ifreq
));
7542 case VKI_SIOCGMIIREG
: /* get hardware entry registers */
7543 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIREG)",
7544 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7545 PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)",
7546 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
,
7547 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
));
7548 PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)",
7549 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->reg_num
,
7550 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->reg_num
));
7551 PRE_MEM_WRITE( "ioctl(SIOCGIFMIIREG)", ARG3
,
7552 sizeof(struct vki_ifreq
));
7554 case VKI_SIOCGIFCONF
: /* get iface list */
7556 PRE_MEM_WRITE( "ioctl(SIOCGIFCONF)", ARG3, sizeof(struct ifconf));
7557 KERNEL_DO_SYSCALL(tid,RES);
7558 if (!VG_(is_kerror)(RES) && RES == 0)
7559 POST_MEM_WRITE(ARG3, sizeof(struct ifconf));
7561 PRE_MEM_READ( "ioctl(SIOCGIFCONF)",
7562 (Addr
)&((struct vki_ifconf
*)(Addr
)ARG3
)->ifc_len
,
7563 sizeof(((struct vki_ifconf
*)(Addr
)ARG3
)->ifc_len
));
7564 PRE_MEM_READ( "ioctl(SIOCGIFCONF)",
7565 (Addr
)&((struct vki_ifconf
*)(Addr
)ARG3
)->vki_ifc_buf
,
7566 sizeof(((struct vki_ifconf
*)(Addr
)ARG3
)->vki_ifc_buf
));
7568 // TODO len must be readable and writable
7569 // buf pointer only needs to be readable
7570 struct vki_ifconf
*ifc
= (struct vki_ifconf
*) (Addr
)ARG3
;
7571 PRE_MEM_WRITE( "ioctl(SIOCGIFCONF).ifc_buf",
7572 (Addr
)(ifc
->vki_ifc_buf
), ifc
->ifc_len
);
7575 case VKI_SIOCGSTAMP
:
7576 PRE_MEM_WRITE( "ioctl(SIOCGSTAMP)", ARG3
, sizeof(struct vki_timeval
));
7578 case VKI_SIOCGSTAMPNS
:
7579 PRE_MEM_WRITE( "ioctl(SIOCGSTAMPNS)", ARG3
, sizeof(struct vki_timespec
));
7581 /* SIOCOUTQ is an ioctl that, when called on a socket, returns
7582 the number of bytes currently in that socket's send buffer.
7583 It writes this value as an int to the memory location
7584 indicated by the third argument of ioctl(2). */
7586 PRE_MEM_WRITE( "ioctl(SIOCOUTQ)", ARG3
, sizeof(int));
7588 case VKI_SIOCGRARP
: /* get RARP table entry */
7589 case VKI_SIOCGARP
: /* get ARP table entry */
7590 PRE_MEM_WRITE( "ioctl(SIOCGARP)", ARG3
, sizeof(struct vki_arpreq
));
7593 case VKI_SIOCSIFFLAGS
: /* set flags */
7594 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFFLAGS)",
7595 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7596 PRE_MEM_READ( "ioctl(SIOCSIFFLAGS)",
7597 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
,
7598 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
) );
7600 case VKI_SIOCSIFMAP
: /* Set device parameters */
7601 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMAP)",
7602 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7603 PRE_MEM_READ( "ioctl(SIOCSIFMAP)",
7604 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_map
,
7605 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_map
) );
7607 case VKI_SIOCSHWTSTAMP
: /* Set hardware time stamping */
7608 PRE_MEM_RASCIIZ( "ioctl(SIOCSHWTSTAMP)",
7609 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7610 PRE_MEM_READ( "ioctl(SIOCSHWTSTAMP)",
7611 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
,
7612 sizeof(struct vki_hwtstamp_config
) );
7614 case VKI_SIOCSIFTXQLEN
: /* Set the tx queue length */
7615 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFTXQLEN)",
7616 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7617 PRE_MEM_READ( "ioctl(SIOCSIFTXQLEN)",
7618 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_qlen
,
7619 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_qlen
) );
7621 case VKI_SIOCSIFADDR
: /* set PA address */
7622 case VKI_SIOCSIFDSTADDR
: /* set remote PA address */
7623 case VKI_SIOCSIFBRDADDR
: /* set broadcast PA address */
7624 case VKI_SIOCSIFNETMASK
: /* set network PA mask */
7625 PRE_MEM_RASCIIZ( "ioctl(SIOCSIF*ADDR)",
7626 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7627 PRE_MEM_READ( "ioctl(SIOCSIF*ADDR)",
7628 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_addr
,
7629 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_addr
) );
7631 case VKI_SIOCSIFMETRIC
: /* set metric */
7632 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMETRIC)",
7633 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7634 PRE_MEM_READ( "ioctl(SIOCSIFMETRIC)",
7635 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_metric
,
7636 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_metric
) );
7638 case VKI_SIOCSIFMTU
: /* set MTU size */
7639 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMTU)",
7640 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7641 PRE_MEM_READ( "ioctl(SIOCSIFMTU)",
7642 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_mtu
,
7643 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_mtu
) );
7645 case VKI_SIOCSIFHWADDR
: /* set hardware address */
7646 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFHWADDR)",
7647 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7648 PRE_MEM_READ( "ioctl(SIOCSIFHWADDR)",
7649 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_hwaddr
,
7650 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_hwaddr
) );
7652 case VKI_SIOCSMIIREG
: /* set hardware entry registers */
7653 PRE_MEM_RASCIIZ( "ioctl(SIOCSMIIREG)",
7654 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7655 PRE_MEM_READ( "ioctl(SIOCSMIIREG)",
7656 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
,
7657 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
));
7658 PRE_MEM_READ( "ioctl(SIOCSMIIREG)",
7659 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->reg_num
,
7660 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->reg_num
));
7661 PRE_MEM_READ( "ioctl(SIOCSMIIREG)",
7662 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->val_in
,
7663 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->val_in
));
7665 /* Routing table calls. */
7666 case VKI_SIOCADDRT
: /* add routing table entry */
7667 case VKI_SIOCDELRT
: /* delete routing table entry */
7668 PRE_MEM_READ( "ioctl(SIOCADDRT/DELRT)", ARG3
,
7669 sizeof(struct vki_rtentry
));
7672 /* tun/tap related ioctls */
7673 case VKI_TUNSETNOCSUM
:
7674 case VKI_TUNSETDEBUG
:
7677 PRE_MEM_RASCIIZ( "ioctl(TUNSETIFF)",
7678 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7679 PRE_MEM_READ( "ioctl(TUNSETIFF)",
7680 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
,
7681 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
) );
7682 PRE_MEM_WRITE( "ioctl(TUNSETIFF)", ARG3
, sizeof(struct vki_ifreq
) );
7684 case VKI_TUNSETPERSIST
:
7685 case VKI_TUNSETOWNER
:
7686 case VKI_TUNSETLINK
:
7687 case VKI_TUNSETGROUP
:
7689 case VKI_TUNGETFEATURES
:
7690 PRE_MEM_WRITE( "ioctl(TUNGETFEATURES)", ARG3
, sizeof(unsigned int) );
7692 case VKI_TUNSETOFFLOAD
:
7695 PRE_MEM_WRITE( "ioctl(TUNGETIFF)", ARG3
, sizeof(struct vki_ifreq
) );
7697 case VKI_TUNGETSNDBUF
:
7698 PRE_MEM_WRITE( "ioctl(TUNGETSNDBUF)", ARG3
, sizeof(int) );
7700 case VKI_TUNSETSNDBUF
:
7701 PRE_MEM_READ( "ioctl(TUNSETSNDBUF)", ARG3
, sizeof(int) );
7703 case VKI_TUNGETVNETHDRSZ
:
7704 PRE_MEM_WRITE( "ioctl(TUNGETVNETHDRSZ)", ARG3
, sizeof(int) );
7706 case VKI_TUNSETVNETHDRSZ
:
7707 PRE_MEM_READ( "ioctl(TUNSETVNETHDRSZ)", ARG3
, sizeof(int) );
7709 case VKI_TUNSETQUEUE
:
7710 PRE_MEM_READ( "ioctl(TUNSETQUEUE)",
7711 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
,
7712 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
) );
7714 case VKI_TUNSETIFINDEX
:
7715 PRE_MEM_READ( "ioctl(TUNSETIFINDEX)", ARG3
, sizeof(unsigned int));
7718 /* RARP cache control calls. */
7719 case VKI_SIOCDRARP
: /* delete RARP table entry */
7720 case VKI_SIOCSRARP
: /* set RARP table entry */
7721 /* ARP cache control calls. */
7722 case VKI_SIOCSARP
: /* set ARP table entry */
7723 case VKI_SIOCDARP
: /* delete ARP table entry */
7724 PRE_MEM_READ( "ioctl(SIOCSIFFLAGS)", ARG3
, sizeof(struct vki_ifreq
));
7728 PRE_MEM_WRITE( "ioctl(SIOCGPGRP)", ARG3
, sizeof(int) );
7731 PRE_MEM_READ( "ioctl(SIOCSPGRP)", ARG3
, sizeof(int) );
7732 //tst->sys_flags &= ~SfMayBlock;
7735 case VKI_SIOCATMARK
:
7736 PRE_MEM_READ( "ioctl(SIOCATMARK)", ARG3
, sizeof(int) );
7739 /* linux/soundcard interface (OSS) */
7740 case VKI_SNDCTL_SEQ_GETOUTCOUNT
:
7741 case VKI_SNDCTL_SEQ_GETINCOUNT
:
7742 case VKI_SNDCTL_SEQ_PERCMODE
:
7743 case VKI_SNDCTL_SEQ_TESTMIDI
:
7744 case VKI_SNDCTL_SEQ_RESETSAMPLES
:
7745 case VKI_SNDCTL_SEQ_NRSYNTHS
:
7746 case VKI_SNDCTL_SEQ_NRMIDIS
:
7747 case VKI_SNDCTL_SEQ_GETTIME
:
7748 case VKI_SNDCTL_DSP_GETBLKSIZE
:
7749 case VKI_SNDCTL_DSP_GETFMTS
:
7750 case VKI_SNDCTL_DSP_GETTRIGGER
:
7751 case VKI_SNDCTL_DSP_GETODELAY
:
7752 case VKI_SNDCTL_DSP_GETSPDIF
:
7753 case VKI_SNDCTL_DSP_GETCAPS
:
7754 case VKI_SOUND_PCM_READ_RATE
:
7755 case VKI_SOUND_PCM_READ_CHANNELS
:
7756 case VKI_SOUND_PCM_READ_BITS
:
7757 case VKI_SOUND_PCM_READ_FILTER
:
7758 PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOR, int))",
7761 case VKI_SNDCTL_SEQ_CTRLRATE
:
7762 case VKI_SNDCTL_DSP_SPEED
:
7763 case VKI_SNDCTL_DSP_STEREO
:
7764 case VKI_SNDCTL_DSP_CHANNELS
:
7765 case VKI_SOUND_PCM_WRITE_FILTER
:
7766 case VKI_SNDCTL_DSP_SUBDIVIDE
:
7767 case VKI_SNDCTL_DSP_SETFRAGMENT
:
7768 case VKI_SNDCTL_DSP_SETFMT
:
7769 case VKI_SNDCTL_DSP_GETCHANNELMASK
:
7770 case VKI_SNDCTL_DSP_BIND_CHANNEL
:
7771 case VKI_SNDCTL_TMR_TIMEBASE
:
7772 case VKI_SNDCTL_TMR_TEMPO
:
7773 case VKI_SNDCTL_TMR_SOURCE
:
7774 case VKI_SNDCTL_MIDI_PRETIME
:
7775 case VKI_SNDCTL_MIDI_MPUMODE
:
7776 PRE_MEM_READ( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOWR, int))",
7778 PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOWR, int))",
7781 case VKI_SNDCTL_DSP_GETOSPACE
:
7782 case VKI_SNDCTL_DSP_GETISPACE
:
7783 PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOR, audio_buf_info))",
7784 ARG3
, sizeof(vki_audio_buf_info
));
7786 case VKI_SNDCTL_DSP_NONBLOCK
:
7788 case VKI_SNDCTL_DSP_SETTRIGGER
:
7789 PRE_MEM_READ( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOW, int))",
7793 case VKI_SNDCTL_DSP_POST
:
7794 case VKI_SNDCTL_DSP_RESET
:
7795 case VKI_SNDCTL_DSP_SYNC
:
7796 case VKI_SNDCTL_DSP_SETSYNCRO
:
7797 case VKI_SNDCTL_DSP_SETDUPLEX
:
7800 /* linux/soundcard interface (ALSA) */
7801 case VKI_SNDRV_PCM_IOCTL_PAUSE
:
7802 case VKI_SNDRV_PCM_IOCTL_LINK
:
7803 /* these just take an int by value */
7805 case VKI_SNDRV_CTL_IOCTL_PVERSION
:
7806 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_PVERSION)", (Addr
)ARG3
, sizeof(int) );
7808 case VKI_SNDRV_CTL_IOCTL_CARD_INFO
:
7809 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_CARD_INFO)", (Addr
)ARG3
, sizeof(struct vki_snd_ctl_card_info
) );
7811 case VKI_SNDRV_CTL_IOCTL_ELEM_LIST
: {
7812 struct vki_snd_ctl_elem_list
*data
=
7813 (struct vki_snd_ctl_elem_list
*)(Addr
)ARG3
;
7814 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)&data
->offset
, sizeof(data
->offset
) );
7815 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)&data
->space
, sizeof(data
->space
) );
7816 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)&data
->used
, sizeof(data
->used
) );
7817 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)&data
->count
, sizeof(data
->count
) );
7818 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)&data
->pids
, sizeof(data
->pids
) );
7820 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)data
->pids
, sizeof(struct vki_snd_ctl_elem_id
) * data
->space
);
7824 case VKI_SNDRV_CTL_IOCTL_TLV_READ
: {
7825 struct vki_snd_ctl_tlv
*data
= (struct vki_snd_ctl_tlv
*)(Addr
)ARG3
;
7826 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_READ)", (Addr
)&data
->numid
, sizeof(data
->numid
) );
7827 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_READ)", (Addr
)&data
->length
, sizeof(data
->length
) );
7828 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_TLV_READ)", (Addr
)data
->tlv
, data
->length
);
7831 case VKI_SNDRV_CTL_IOCTL_TLV_WRITE
:
7832 case VKI_SNDRV_CTL_IOCTL_TLV_COMMAND
: {
7833 struct vki_snd_ctl_tlv
*data
= (struct vki_snd_ctl_tlv
*)(Addr
)ARG3
;
7834 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_WRITE)", (Addr
)&data
->numid
, sizeof(data
->numid
) );
7835 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_WRITE)", (Addr
)&data
->length
, sizeof(data
->length
) );
7836 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_WRITE)", (Addr
)data
->tlv
, data
->length
);
7840 /* Real Time Clock (/dev/rtc) ioctls */
7841 case VKI_RTC_UIE_ON
:
7842 case VKI_RTC_UIE_OFF
:
7843 case VKI_RTC_AIE_ON
:
7844 case VKI_RTC_AIE_OFF
:
7845 case VKI_RTC_PIE_ON
:
7846 case VKI_RTC_PIE_OFF
:
7847 case VKI_RTC_IRQP_SET
:
7849 case VKI_RTC_RD_TIME
:
7850 case VKI_RTC_ALM_READ
:
7851 PRE_MEM_WRITE( "ioctl(RTC_RD_TIME/ALM_READ)",
7852 ARG3
, sizeof(struct vki_rtc_time
));
7854 case VKI_RTC_ALM_SET
:
7855 PRE_MEM_READ( "ioctl(RTC_ALM_SET)", ARG3
, sizeof(struct vki_rtc_time
));
7857 case VKI_RTC_IRQP_READ
:
7858 PRE_MEM_WRITE( "ioctl(RTC_IRQP_READ)", ARG3
, sizeof(unsigned long));
7863 PRE_MEM_READ( "ioctl(BLKROSET)", ARG3
, sizeof(int));
7866 PRE_MEM_WRITE( "ioctl(BLKROGET)", ARG3
, sizeof(int));
7868 case VKI_BLKGETSIZE
:
7869 PRE_MEM_WRITE( "ioctl(BLKGETSIZE)", ARG3
, sizeof(unsigned long));
7876 PRE_MEM_WRITE( "ioctl(BLKRAGET)", ARG3
, sizeof(long));
7881 PRE_MEM_WRITE( "ioctl(BLKFRAGET)", ARG3
, sizeof(long));
7883 case VKI_BLKSECTGET
:
7884 PRE_MEM_WRITE( "ioctl(BLKSECTGET)", ARG3
, sizeof(unsigned short));
7887 PRE_MEM_WRITE( "ioctl(BLKSSZGET)", ARG3
, sizeof(int));
7890 PRE_MEM_WRITE( "ioctl(BLKBSZGET)", ARG3
, sizeof(int));
7893 PRE_MEM_READ( "ioctl(BLKBSZSET)", ARG3
, sizeof(int));
7895 case VKI_BLKGETSIZE64
:
7896 PRE_MEM_WRITE( "ioctl(BLKGETSIZE64)", ARG3
, sizeof(unsigned long long));
7898 case VKI_BLKPBSZGET
:
7899 PRE_MEM_WRITE( "ioctl(BLKPBSZGET)", ARG3
, sizeof(int));
7902 PRE_MEM_WRITE( "ioctl(BLKIOMIN)", ARG3
, sizeof(vki_uint
));
7905 PRE_MEM_WRITE( "ioctl(BLKIOOPT)", ARG3
, sizeof(vki_uint
));
7907 case VKI_BLKALIGNOFF
:
7908 PRE_MEM_WRITE( "ioctl(BLKALIGNOFF)", ARG3
, sizeof(int));
7910 case VKI_BLKDISCARDZEROES
:
7911 PRE_MEM_WRITE( "ioctl(BLKDISCARDZEROES)", ARG3
, sizeof(vki_uint
));
7913 case VKI_BLKREPORTZONE
:
7914 PRE_MEM_READ("ioctl(BLKREPORTZONE)", ARG3
,
7915 sizeof(struct vki_blk_zone_report
));
7917 case VKI_BLKRESETZONE
:
7918 PRE_MEM_READ("ioctl(BLKRESETZONE)", ARG3
,
7919 sizeof(struct vki_blk_zone_range
));
7923 case VKI_HDIO_GETGEO
: /* 0x0301 */
7924 PRE_MEM_WRITE( "ioctl(HDIO_GETGEO)", ARG3
, sizeof(struct vki_hd_geometry
));
7926 case VKI_HDIO_GET_DMA
: /* 0x030b */
7927 PRE_MEM_WRITE( "ioctl(HDIO_GET_DMA)", ARG3
, sizeof(long));
7929 case VKI_HDIO_GET_IDENTITY
: /* 0x030d */
7930 PRE_MEM_WRITE( "ioctl(HDIO_GET_IDENTITY)", ARG3
,
7931 VKI_SIZEOF_STRUCT_HD_DRIVEID
);
7935 case VKI_SCSI_IOCTL_GET_IDLUN
: /* 0x5382 */
7936 PRE_MEM_WRITE( "ioctl(SCSI_IOCTL_GET_IDLUN)", ARG3
, sizeof(struct vki_scsi_idlun
));
7938 case VKI_SCSI_IOCTL_GET_BUS_NUMBER
: /* 0x5386 */
7939 PRE_MEM_WRITE( "ioctl(SCSI_IOCTL_GET_BUS_NUMBER)", ARG3
, sizeof(int));
7942 /* CD ROM stuff (??) */
7943 case VKI_CDROM_GET_MCN
:
7944 PRE_MEM_READ( "ioctl(CDROM_GET_MCN)", ARG3
,
7945 sizeof(struct vki_cdrom_mcn
) );
7947 case VKI_CDROM_SEND_PACKET
:
7948 PRE_MEM_READ( "ioctl(CDROM_SEND_PACKET)", ARG3
,
7949 sizeof(struct vki_cdrom_generic_command
));
7951 case VKI_CDROMSUBCHNL
:
7952 PRE_MEM_READ( "ioctl(CDROMSUBCHNL (cdsc_format, char))",
7953 (Addr
) &(((struct vki_cdrom_subchnl
*) (Addr
)ARG3
)->cdsc_format
),
7954 sizeof(((struct vki_cdrom_subchnl
*) (Addr
)ARG3
)->cdsc_format
));
7955 PRE_MEM_WRITE( "ioctl(CDROMSUBCHNL)", ARG3
,
7956 sizeof(struct vki_cdrom_subchnl
));
7958 case VKI_CDROMREADMODE1
: /*0x530d*/
7959 PRE_MEM_READ("ioctl(CDROMREADMODE1)", ARG3
, VKI_CD_FRAMESIZE_RAW1
);
7960 PRE_MEM_WRITE("ioctl(CDROMREADMODE1)", ARG3
, VKI_CD_FRAMESIZE_RAW1
);
7962 case VKI_CDROMREADMODE2
: /*0x530c*/
7963 PRE_MEM_READ("ioctl(CDROMREADMODE2)", ARG3
, VKI_CD_FRAMESIZE_RAW0
);
7964 PRE_MEM_WRITE("ioctl(CDROMREADMODE2)", ARG3
, VKI_CD_FRAMESIZE_RAW0
);
7966 case VKI_CDROMREADTOCHDR
:
7967 PRE_MEM_WRITE( "ioctl(CDROMREADTOCHDR)", ARG3
,
7968 sizeof(struct vki_cdrom_tochdr
));
7970 case VKI_CDROMREADTOCENTRY
:
7971 PRE_MEM_READ( "ioctl(CDROMREADTOCENTRY (cdte_format, char))",
7972 (Addr
) &(((struct vki_cdrom_tocentry
*) (Addr
)ARG3
)->cdte_format
),
7973 sizeof(((struct vki_cdrom_tocentry
*) (Addr
)ARG3
)->cdte_format
));
7974 PRE_MEM_READ( "ioctl(CDROMREADTOCENTRY (cdte_track, char))",
7975 (Addr
) &(((struct vki_cdrom_tocentry
*) (Addr
)ARG3
)->cdte_track
),
7976 sizeof(((struct vki_cdrom_tocentry
*) (Addr
)ARG3
)->cdte_track
));
7977 PRE_MEM_WRITE( "ioctl(CDROMREADTOCENTRY)", ARG3
,
7978 sizeof(struct vki_cdrom_tocentry
));
7980 case VKI_CDROMMULTISESSION
: /* 0x5310 */
7981 PRE_MEM_WRITE( "ioctl(CDROMMULTISESSION)", ARG3
,
7982 sizeof(struct vki_cdrom_multisession
));
7984 case VKI_CDROMVOLREAD
: /* 0x5313 */
7985 PRE_MEM_WRITE( "ioctl(CDROMVOLREAD)", ARG3
,
7986 sizeof(struct vki_cdrom_volctrl
));
7988 case VKI_CDROMREADRAW
: /* 0x5314 */
7989 PRE_MEM_READ( "ioctl(CDROMREADRAW)", ARG3
, sizeof(struct vki_cdrom_msf
));
7990 PRE_MEM_WRITE( "ioctl(CDROMREADRAW)", ARG3
, VKI_CD_FRAMESIZE_RAW
);
7992 case VKI_CDROMREADAUDIO
: /* 0x530e */
7993 PRE_MEM_READ( "ioctl(CDROMREADAUDIO)", ARG3
,
7994 sizeof (struct vki_cdrom_read_audio
));
7996 /* ToDo: don't do any of the following if the structure is invalid */
7997 struct vki_cdrom_read_audio
*cra
=
7998 (struct vki_cdrom_read_audio
*) (Addr
)ARG3
;
7999 PRE_MEM_WRITE( "ioctl(CDROMREADAUDIO).buf",
8000 (Addr
)(cra
->buf
), cra
->nframes
* VKI_CD_FRAMESIZE_RAW
);
8003 case VKI_CDROMPLAYMSF
:
8004 PRE_MEM_READ( "ioctl(CDROMPLAYMSF)", ARG3
, sizeof(struct vki_cdrom_msf
));
8006 /* The following two are probably bogus (should check args
8007 for readability). JRS 20021117 */
8008 case VKI_CDROM_DRIVE_STATUS
: /* 0x5326 */
8009 case VKI_CDROM_CLEAR_OPTIONS
: /* 0x5321 */
8011 case VKI_CDROM_GET_CAPABILITY
: /* 0x5331 */
8015 PRE_MEM_WRITE( "ioctl(FIGETBSZ)", ARG3
, sizeof(unsigned long));
8018 PRE_MEM_READ( "ioctl(FIBMAP)", ARG3
, sizeof(int));
8021 /* The direction of FICLONE (W) is incorrectly specified
8022 * as it expects a file descriptor and not a pointer to
8026 case VKI_FBIOGET_VSCREENINFO
: /* 0x4600 */
8027 PRE_MEM_WRITE( "ioctl(FBIOGET_VSCREENINFO)", ARG3
,
8028 sizeof(struct vki_fb_var_screeninfo
));
8030 case VKI_FBIOPUT_VSCREENINFO
:
8031 PRE_MEM_READ( "ioctl(FBIOPUT_VSCREENINFO)", ARG3
,
8032 sizeof(struct vki_fb_var_screeninfo
));
8034 case VKI_FBIOGET_FSCREENINFO
: /* 0x4602 */
8035 PRE_MEM_WRITE( "ioctl(FBIOGET_FSCREENINFO)", ARG3
,
8036 sizeof(struct vki_fb_fix_screeninfo
));
8038 case VKI_FBIOPAN_DISPLAY
:
8039 PRE_MEM_READ( "ioctl(FBIOPAN_DISPLAY)", ARG3
,
8040 sizeof(struct vki_fb_var_screeninfo
));
8049 PRE_MEM_READ( "ioctl(PPSETMODE)", ARG3
, sizeof(int) );
8052 PRE_MEM_WRITE( "ioctl(PPGETMODE)", ARG3
, sizeof(int) );
8054 case VKI_PPSETPHASE
:
8055 PRE_MEM_READ( "ioctl(PPSETPHASE)", ARG3
, sizeof(int) );
8057 case VKI_PPGETPHASE
:
8058 PRE_MEM_WRITE( "ioctl(PPGETPHASE)", ARG3
, sizeof(int) );
8060 case VKI_PPGETMODES
:
8061 PRE_MEM_WRITE( "ioctl(PPGETMODES)", ARG3
, sizeof(unsigned int) );
8063 case VKI_PPSETFLAGS
:
8064 PRE_MEM_READ( "ioctl(PPSETFLAGS)", ARG3
, sizeof(int) );
8066 case VKI_PPGETFLAGS
:
8067 PRE_MEM_WRITE( "ioctl(PPGETFLAGS)", ARG3
, sizeof(int) );
8070 PRE_MEM_WRITE( "ioctl(PPRSTATUS)", ARG3
, sizeof(unsigned char) );
8073 PRE_MEM_WRITE( "ioctl(PPRDATA)", ARG3
, sizeof(unsigned char) );
8075 case VKI_PPRCONTROL
:
8076 PRE_MEM_WRITE( "ioctl(PPRCONTROL)", ARG3
, sizeof(unsigned char) );
8079 PRE_MEM_READ( "ioctl(PPWDATA)", ARG3
, sizeof(unsigned char) );
8081 case VKI_PPWCONTROL
:
8082 PRE_MEM_READ( "ioctl(PPWCONTROL)", ARG3
, sizeof(unsigned char) );
8084 case VKI_PPFCONTROL
:
8085 PRE_MEM_READ( "ioctl(PPFCONTROL)", ARG3
, 2 * sizeof(unsigned char) );
8088 PRE_MEM_READ( "ioctl(PPDATADIR)", ARG3
, sizeof(int) );
8091 PRE_MEM_READ( "ioctl(PPNEGOT)", ARG3
, sizeof(int) );
8093 case VKI_PPWCTLONIRQ
:
8094 PRE_MEM_READ( "ioctl(PPWCTLONIRQ)",ARG3
, sizeof(unsigned char) );
8097 PRE_MEM_WRITE( "ioctl(PPCLRIRQ)", ARG3
, sizeof(int) );
8100 PRE_MEM_READ( "ioctl(PPSETTIME)", ARG3
, sizeof(struct vki_timeval
) );
8103 PRE_MEM_WRITE( "ioctl(PPGETTIME)", ARG3
, sizeof(struct vki_timeval
) );
8107 PRE_MEM_WRITE( "ioctl(GIO_FONT)", ARG3
, 32 * 256 );
8110 PRE_MEM_READ( "ioctl(PIO_FONT)", ARG3
, 32 * 256 );
8114 PRE_MEM_READ( "ioctl(GIO_FONTX)", ARG3
, sizeof(struct vki_consolefontdesc
) );
8116 /* ToDo: don't do any of the following if the structure is invalid */
8117 struct vki_consolefontdesc
*cfd
=
8118 (struct vki_consolefontdesc
*)(Addr
)ARG3
;
8119 PRE_MEM_WRITE( "ioctl(GIO_FONTX).chardata", (Addr
)cfd
->chardata
,
8120 32 * cfd
->charcount
);
8124 PRE_MEM_READ( "ioctl(PIO_FONTX)", ARG3
, sizeof(struct vki_consolefontdesc
) );
8126 /* ToDo: don't do any of the following if the structure is invalid */
8127 struct vki_consolefontdesc
*cfd
=
8128 (struct vki_consolefontdesc
*)(Addr
)ARG3
;
8129 PRE_MEM_READ( "ioctl(PIO_FONTX).chardata", (Addr
)cfd
->chardata
,
8130 32 * cfd
->charcount
);
8134 case VKI_PIO_FONTRESET
:
8138 PRE_MEM_WRITE( "ioctl(GIO_CMAP)", ARG3
, 16 * 3 );
8141 PRE_MEM_READ( "ioctl(PIO_CMAP)", ARG3
, 16 * 3 );
8149 PRE_MEM_WRITE( "ioctl(KDGETLED)", ARG3
, sizeof(char) );
8155 PRE_MEM_WRITE( "ioctl(KDGKBTYPE)", ARG3
, sizeof(char) );
8167 PRE_MEM_WRITE( "ioctl(KDGETMODE)", ARG3
, sizeof(int) );
8171 case VKI_KDUNMAPDISP
:
8174 case VKI_GIO_SCRNMAP
:
8175 PRE_MEM_WRITE( "ioctl(GIO_SCRNMAP)", ARG3
, VKI_E_TABSZ
);
8177 case VKI_PIO_SCRNMAP
:
8178 PRE_MEM_READ( "ioctl(PIO_SCRNMAP)", ARG3
, VKI_E_TABSZ
);
8180 case VKI_GIO_UNISCRNMAP
:
8181 PRE_MEM_WRITE( "ioctl(GIO_UNISCRNMAP)", ARG3
,
8182 VKI_E_TABSZ
* sizeof(unsigned short) );
8184 case VKI_PIO_UNISCRNMAP
:
8185 PRE_MEM_READ( "ioctl(PIO_UNISCRNMAP)", ARG3
,
8186 VKI_E_TABSZ
* sizeof(unsigned short) );
8189 case VKI_GIO_UNIMAP
:
8191 struct vki_unimapdesc
*desc
= (struct vki_unimapdesc
*) (Addr
)ARG3
;
8192 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr
)&desc
->entry_ct
,
8193 sizeof(unsigned short));
8194 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr
)&desc
->entries
,
8195 sizeof(struct vki_unipair
*));
8196 PRE_MEM_WRITE( "ioctl(GIO_UNIMAP).entries", (Addr
)desc
->entries
,
8197 desc
->entry_ct
* sizeof(struct vki_unipair
));
8200 case VKI_PIO_UNIMAP
:
8202 struct vki_unimapdesc
*desc
= (struct vki_unimapdesc
*) (Addr
)ARG3
;
8203 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr
)&desc
->entry_ct
,
8204 sizeof(unsigned short) );
8205 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr
)&desc
->entries
,
8206 sizeof(struct vki_unipair
*) );
8207 PRE_MEM_READ( "ioctl(PIO_UNIMAP).entries", (Addr
)desc
->entries
,
8208 desc
->entry_ct
* sizeof(struct vki_unipair
) );
8211 case VKI_PIO_UNIMAPCLR
:
8212 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", ARG3
, sizeof(struct vki_unimapinit
));
8216 PRE_MEM_WRITE( "ioctl(KDGKBMODE)", ARG3
, sizeof(int) );
8222 PRE_MEM_WRITE( "ioctl(KDGKBMETA)", ARG3
, sizeof(int) );
8228 PRE_MEM_WRITE( "ioctl(KDGKBLED)", ARG3
, sizeof(char) );
8234 PRE_MEM_READ( "ioctl(KDGKBENT).kb_table",
8235 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_table
,
8236 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_table
) );
8237 PRE_MEM_READ( "ioctl(KDGKBENT).kb_index",
8238 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_index
,
8239 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_index
) );
8240 PRE_MEM_WRITE( "ioctl(KDGKBENT).kb_value",
8241 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
,
8242 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
) );
8245 PRE_MEM_READ( "ioctl(KDSKBENT).kb_table",
8246 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_table
,
8247 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_table
) );
8248 PRE_MEM_READ( "ioctl(KDSKBENT).kb_index",
8249 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_index
,
8250 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_index
) );
8251 PRE_MEM_READ( "ioctl(KDSKBENT).kb_value",
8252 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
,
8253 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
) );
8257 PRE_MEM_READ( "ioctl(KDGKBSENT).kb_func",
8258 (Addr
)&((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_func
,
8259 sizeof(((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_func
) );
8260 PRE_MEM_WRITE( "ioctl(KDGKSENT).kb_string",
8261 (Addr
)((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_string
,
8262 sizeof(((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_string
) );
8265 PRE_MEM_READ( "ioctl(KDSKBSENT).kb_func",
8266 (Addr
)&((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_func
,
8267 sizeof(((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_func
) );
8268 PRE_MEM_RASCIIZ( "ioctl(KDSKBSENT).kb_string",
8269 (Addr
)((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_string
);
8272 case VKI_KDGKBDIACR
:
8273 PRE_MEM_WRITE( "ioctl(KDGKBDIACR)", ARG3
, sizeof(struct vki_kbdiacrs
) );
8275 case VKI_KDSKBDIACR
:
8276 PRE_MEM_READ( "ioctl(KDSKBDIACR)", ARG3
, sizeof(struct vki_kbdiacrs
) );
8279 case VKI_KDGETKEYCODE
:
8280 PRE_MEM_READ( "ioctl(KDGETKEYCODE).scancode",
8281 (Addr
)&((struct vki_kbkeycode
*)(Addr
)ARG3
)->scancode
,
8282 sizeof(((struct vki_kbkeycode
*)(Addr
)ARG3
)->scancode
) );
8283 PRE_MEM_WRITE( "ioctl(KDGETKEYCODE).keycode",
8284 (Addr
)((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
,
8285 sizeof(((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
) );
8287 case VKI_KDSETKEYCODE
:
8288 PRE_MEM_READ( "ioctl(KDSETKEYCODE).scancode",
8289 (Addr
)&((struct vki_kbkeycode
*)(Addr
)ARG3
)->scancode
,
8290 sizeof(((struct vki_kbkeycode
*)(Addr
)ARG3
)->scancode
) );
8291 PRE_MEM_READ( "ioctl(KDSETKEYCODE).keycode",
8292 (Addr
)((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
,
8293 sizeof(((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
) );
8296 case VKI_KDSIGACCEPT
:
8300 PRE_MEM_READ( "ioctl(KBKBDREP)", ARG3
, sizeof(struct vki_kbd_repeat
) );
8305 struct vki_console_font_op
*op
=
8306 (struct vki_console_font_op
*) (Addr
)ARG3
;
8307 PRE_MEM_READ( "ioctl(KDFONTOP)", (Addr
)op
,
8308 sizeof(struct vki_console_font_op
) );
8310 case VKI_KD_FONT_OP_SET
:
8311 PRE_MEM_READ( "ioctl(KDFONTOP,KD_FONT_OP_SET).data",
8313 (op
->width
+ 7) / 8 * 32 * op
->charcount
);
8315 case VKI_KD_FONT_OP_GET
:
8317 PRE_MEM_WRITE( "ioctl(KDFONTOP,KD_FONT_OP_GET).data",
8319 (op
->width
+ 7) / 8 * 32 * op
->charcount
);
8321 case VKI_KD_FONT_OP_SET_DEFAULT
:
8323 PRE_MEM_RASCIIZ( "ioctl(KDFONTOP,KD_FONT_OP_SET_DEFAULT).data",
8326 case VKI_KD_FONT_OP_COPY
:
8332 case VKI_VT_OPENQRY
:
8333 PRE_MEM_WRITE( "ioctl(VT_OPENQRY)", ARG3
, sizeof(int) );
8335 case VKI_VT_GETMODE
:
8336 PRE_MEM_WRITE( "ioctl(VT_GETMODE)", ARG3
, sizeof(struct vki_vt_mode
) );
8338 case VKI_VT_SETMODE
:
8339 PRE_MEM_READ( "ioctl(VT_SETMODE)", ARG3
, sizeof(struct vki_vt_mode
) );
8341 case VKI_VT_GETSTATE
:
8342 PRE_MEM_WRITE( "ioctl(VT_GETSTATE).v_active",
8343 (Addr
) &(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_active
),
8344 sizeof(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_active
));
8345 PRE_MEM_WRITE( "ioctl(VT_GETSTATE).v_state",
8346 (Addr
) &(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_state
),
8347 sizeof(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_state
));
8349 case VKI_VT_RELDISP
:
8350 case VKI_VT_ACTIVATE
:
8351 case VKI_VT_WAITACTIVE
:
8352 case VKI_VT_DISALLOCATE
:
8355 PRE_MEM_READ( "ioctl(VT_RESIZE)", ARG3
, sizeof(struct vki_vt_sizes
) );
8357 case VKI_VT_RESIZEX
:
8358 PRE_MEM_READ( "ioctl(VT_RESIZEX)", ARG3
, sizeof(struct vki_vt_consize
) );
8360 case VKI_VT_LOCKSWITCH
:
8361 case VKI_VT_UNLOCKSWITCH
:
8364 case VKI_USBDEVFS_CONTROL
:
8366 struct vki_usbdevfs_ctrltransfer
*vkuc
=
8367 (struct vki_usbdevfs_ctrltransfer
*)(Addr
)ARG3
;
8368 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).bRequestType", (Addr
)&vkuc
->bRequestType
, sizeof(vkuc
->bRequestType
));
8369 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).bRequest", (Addr
)&vkuc
->bRequest
, sizeof(vkuc
->bRequest
));
8370 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wValue", (Addr
)&vkuc
->wValue
, sizeof(vkuc
->wValue
));
8371 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wIndex", (Addr
)&vkuc
->wIndex
, sizeof(vkuc
->wIndex
));
8372 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wLength", (Addr
)&vkuc
->wLength
, sizeof(vkuc
->wLength
));
8373 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).timeout", (Addr
)&vkuc
->timeout
, sizeof(vkuc
->timeout
));
8374 if (vkuc
->bRequestType
& 0x80)
8375 PRE_MEM_WRITE( "ioctl(USBDEVFS_CONTROL).data", (Addr
)vkuc
->data
, vkuc
->wLength
);
8377 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).data", (Addr
)vkuc
->data
, vkuc
->wLength
);
8380 case VKI_USBDEVFS_BULK
:
8382 struct vki_usbdevfs_bulktransfer
*vkub
=
8383 (struct vki_usbdevfs_bulktransfer
*)(Addr
)ARG3
;
8384 PRE_MEM_READ( "ioctl(USBDEVFS_BULK)", ARG3
, sizeof(struct vki_usbdevfs_bulktransfer
));
8385 if (vkub
->ep
& 0x80)
8386 PRE_MEM_WRITE( "ioctl(USBDEVFS_BULK).data", (Addr
)vkub
->data
, vkub
->len
);
8388 PRE_MEM_READ( "ioctl(USBDEVFS_BULK).data", (Addr
)vkub
->data
, vkub
->len
);
8391 case VKI_USBDEVFS_GETDRIVER
:
8393 struct vki_usbdevfs_getdriver
*vkugd
=
8394 (struct vki_usbdevfs_getdriver
*) (Addr
)ARG3
;
8395 PRE_MEM_WRITE( "ioctl(USBDEVFS_GETDRIVER)", (Addr
)&vkugd
->driver
, sizeof(vkugd
->driver
));
8398 case VKI_USBDEVFS_SUBMITURB
:
8400 struct vki_usbdevfs_urb
*vkuu
= (struct vki_usbdevfs_urb
*)(Addr
)ARG3
;
8402 /* Not the whole struct needs to be initialized */
8403 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).endpoint", (Addr
)&vkuu
->endpoint
, sizeof(vkuu
->endpoint
));
8404 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).type", (Addr
)&vkuu
->type
, sizeof(vkuu
->type
));
8405 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).flags", (Addr
)&vkuu
->flags
, sizeof(vkuu
->flags
));
8406 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr
)&vkuu
->buffer
, sizeof(vkuu
->buffer
));
8407 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).signr", (Addr
)&vkuu
->signr
, sizeof(vkuu
->signr
));
8408 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).status", (Addr
)&vkuu
->status
, sizeof(vkuu
->status
));
8409 if (vkuu
->type
== VKI_USBDEVFS_URB_TYPE_CONTROL
) {
8410 struct vki_usbdevfs_setuppacket
*vkusp
= (struct vki_usbdevfs_setuppacket
*)vkuu
->buffer
;
8411 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr
)&vkuu
->buffer_length
, sizeof(vkuu
->buffer_length
));
8412 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer.setup_packet", (Addr
)vkusp
, sizeof(*vkusp
));
8413 if (vkusp
->bRequestType
& 0x80)
8414 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer.data", (Addr
)(vkusp
+1), vkuu
->buffer_length
- sizeof(*vkusp
));
8416 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer.data", (Addr
)(vkusp
+1), vkuu
->buffer_length
- sizeof(*vkusp
));
8417 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).actual_length", (Addr
)&vkuu
->actual_length
, sizeof(vkuu
->actual_length
));
8418 } else if (vkuu
->type
== VKI_USBDEVFS_URB_TYPE_ISO
) {
8419 int total_length
= 0;
8421 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).number_of_packets", (Addr
)&vkuu
->number_of_packets
, sizeof(vkuu
->number_of_packets
));
8422 for(i
=0; i
<vkuu
->number_of_packets
; i
++) {
8423 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].length", (Addr
)&vkuu
->iso_frame_desc
[i
].length
, sizeof(vkuu
->iso_frame_desc
[i
].length
));
8424 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].actual_length", (Addr
)&vkuu
->iso_frame_desc
[i
].actual_length
, sizeof(vkuu
->iso_frame_desc
[i
].actual_length
));
8425 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].status", (Addr
)&vkuu
->iso_frame_desc
[i
].status
, sizeof(vkuu
->iso_frame_desc
[i
].status
));
8426 total_length
+= vkuu
->iso_frame_desc
[i
].length
;
8428 if (vkuu
->endpoint
& 0x80)
8429 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr
)vkuu
->buffer
, total_length
);
8431 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr
)vkuu
->buffer
, total_length
);
8432 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).error_count", (Addr
)&vkuu
->error_count
, sizeof(vkuu
->error_count
));
8434 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr
)&vkuu
->buffer_length
, sizeof(vkuu
->buffer_length
));
8435 if (vkuu
->endpoint
& 0x80)
8436 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr
)vkuu
->buffer
, vkuu
->buffer_length
);
8438 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr
)vkuu
->buffer
, vkuu
->buffer_length
);
8439 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).actual_length", (Addr
)&vkuu
->actual_length
, sizeof(vkuu
->actual_length
));
8443 case VKI_USBDEVFS_DISCARDURB
:
8445 case VKI_USBDEVFS_REAPURB
:
8447 PRE_MEM_WRITE( "ioctl(USBDEVFS_REAPURB)", ARG3
, sizeof(struct vki_usbdevfs_urb
**));
8450 case VKI_USBDEVFS_REAPURBNDELAY
:
8452 PRE_MEM_WRITE( "ioctl(USBDEVFS_REAPURBNDELAY)", ARG3
, sizeof(struct vki_usbdevfs_urb
**));
8455 case VKI_USBDEVFS_CONNECTINFO
:
8456 PRE_MEM_WRITE( "ioctl(USBDEVFS_CONNECTINFO)", ARG3
, sizeof(struct vki_usbdevfs_connectinfo
));
8458 case VKI_USBDEVFS_IOCTL
:
8460 struct vki_usbdevfs_ioctl
*vkui
=
8461 (struct vki_usbdevfs_ioctl
*)(Addr
)ARG3
;
8463 PRE_MEM_READ("ioctl(USBDEVFS_IOCTL)", (Addr
)vkui
, sizeof(struct vki_usbdevfs_ioctl
));
8464 dir2
= _VKI_IOC_DIR(vkui
->ioctl_code
);
8465 size2
= _VKI_IOC_SIZE(vkui
->ioctl_code
);
8467 if (dir2
& _VKI_IOC_WRITE
)
8468 PRE_MEM_READ("ioctl(USBDEVFS_IOCTL).dataWrite", (Addr
)vkui
->data
, size2
);
8469 else if (dir2
& _VKI_IOC_READ
)
8470 PRE_MEM_WRITE("ioctl(USBDEVFS_IOCTL).dataRead", (Addr
)vkui
->data
, size2
);
8474 case VKI_USBDEVFS_RESET
:
8477 /* I2C (/dev/i2c-*) ioctls */
8479 case VKI_I2C_SLAVE_FORCE
:
8480 case VKI_I2C_TENBIT
:
8484 PRE_MEM_WRITE( "ioctl(I2C_FUNCS)", ARG3
, sizeof(unsigned long) );
8488 struct vki_i2c_rdwr_ioctl_data
*vkui
=
8489 (struct vki_i2c_rdwr_ioctl_data
*)(Addr
)ARG3
;
8491 PRE_MEM_READ("ioctl(I2C_RDWR)", (Addr
)vkui
, sizeof(struct vki_i2c_rdwr_ioctl_data
));
8492 for (i
=0; i
< vkui
->nmsgs
; i
++) {
8493 struct vki_i2c_msg
*msg
= vkui
->msgs
+ i
;
8494 PRE_MEM_READ("ioctl(I2C_RDWR).msgs", (Addr
)msg
, sizeof(struct vki_i2c_msg
));
8495 if (msg
->flags
& VKI_I2C_M_RD
)
8496 PRE_MEM_WRITE("ioctl(I2C_RDWR).msgs.buf", (Addr
)msg
->buf
, msg
->len
);
8498 PRE_MEM_READ("ioctl(I2C_RDWR).msgs.buf", (Addr
)msg
->buf
, msg
->len
);
8504 struct vki_i2c_smbus_ioctl_data
*vkis
8505 = (struct vki_i2c_smbus_ioctl_data
*) (Addr
)ARG3
;
8506 PRE_MEM_READ("ioctl(VKI_I2C_SMBUS).i2c_smbus_ioctl_data.read_write",
8507 (Addr
)&vkis
->read_write
, sizeof(vkis
->read_write
));
8508 PRE_MEM_READ("ioctl(VKI_I2C_SMBUS).i2c_smbus_ioctl_data.size",
8509 (Addr
)&vkis
->size
, sizeof(vkis
->size
));
8510 PRE_MEM_READ("ioctl(VKI_I2C_SMBUS).i2c_smbus_ioctl_data.command",
8511 (Addr
)&vkis
->command
, sizeof(vkis
->command
));
8512 /* i2c_smbus_write_quick hides its value in read_write, so
8513 this variable can have a different meaning */
8514 /* to make matters worse i2c_smbus_write_byte stores its
8516 if ( ! ((vkis
->size
== VKI_I2C_SMBUS_QUICK
) ||
8517 ((vkis
->size
== VKI_I2C_SMBUS_BYTE
)
8518 && (vkis
->read_write
== VKI_I2C_SMBUS_WRITE
)))) {
8519 /* the rest uses the byte array to store the data,
8520 some the first byte for size */
8522 switch(vkis
->size
) {
8523 case VKI_I2C_SMBUS_BYTE_DATA
:
8526 case VKI_I2C_SMBUS_WORD_DATA
:
8527 case VKI_I2C_SMBUS_PROC_CALL
:
8530 case VKI_I2C_SMBUS_BLOCK_DATA
:
8531 case VKI_I2C_SMBUS_I2C_BLOCK_BROKEN
:
8532 case VKI_I2C_SMBUS_BLOCK_PROC_CALL
:
8533 case VKI_I2C_SMBUS_I2C_BLOCK_DATA
:
8534 size
= 1 + vkis
->data
->block
[0];
8540 if ((vkis
->read_write
== VKI_I2C_SMBUS_READ
)
8541 || (vkis
->size
== VKI_I2C_SMBUS_PROC_CALL
)
8542 || (vkis
->size
== VKI_I2C_SMBUS_BLOCK_PROC_CALL
))
8543 PRE_MEM_WRITE("ioctl(VKI_I2C_SMBUS)"
8544 ".i2c_smbus_ioctl_data.data",
8545 (Addr
)&vkis
->data
->block
[0], size
);
8547 PRE_MEM_READ("ioctl(VKI_I2C_SMBUS)."
8548 "i2c_smbus_ioctl_data.data",
8549 (Addr
)&vkis
->data
->block
[0], size
);
8554 /* Wireless extensions ioctls */
8555 case VKI_SIOCSIWCOMMIT
:
8556 case VKI_SIOCSIWNWID
:
8557 case VKI_SIOCSIWFREQ
:
8558 case VKI_SIOCSIWMODE
:
8559 case VKI_SIOCSIWSENS
:
8560 case VKI_SIOCSIWRANGE
:
8561 case VKI_SIOCSIWPRIV
:
8562 case VKI_SIOCSIWSTATS
:
8563 case VKI_SIOCSIWSPY
:
8564 case VKI_SIOCSIWTHRSPY
:
8566 case VKI_SIOCSIWSCAN
:
8567 case VKI_SIOCSIWESSID
:
8568 case VKI_SIOCSIWRATE
:
8569 case VKI_SIOCSIWNICKN
:
8570 case VKI_SIOCSIWRTS
:
8571 case VKI_SIOCSIWFRAG
:
8572 case VKI_SIOCSIWTXPOW
:
8573 case VKI_SIOCSIWRETRY
:
8574 case VKI_SIOCSIWENCODE
:
8575 case VKI_SIOCSIWPOWER
:
8576 case VKI_SIOCSIWGENIE
:
8577 case VKI_SIOCSIWMLME
:
8578 case VKI_SIOCSIWAUTH
:
8579 case VKI_SIOCSIWENCODEEXT
:
8580 case VKI_SIOCSIWPMKSA
:
8582 case VKI_SIOCGIWNAME
:
8584 PRE_MEM_WRITE("ioctl(SIOCGIWNAME)",
8585 (Addr
)((struct vki_iwreq
*)(Addr
)ARG3
)->u
.name
,
8586 sizeof(((struct vki_iwreq
*)(Addr
)ARG3
)->u
.name
));
8589 case VKI_SIOCGIWNWID
:
8590 case VKI_SIOCGIWSENS
:
8591 case VKI_SIOCGIWRATE
:
8592 case VKI_SIOCGIWRTS
:
8593 case VKI_SIOCGIWFRAG
:
8594 case VKI_SIOCGIWTXPOW
:
8595 case VKI_SIOCGIWRETRY
:
8596 case VKI_SIOCGIWPOWER
:
8597 case VKI_SIOCGIWAUTH
:
8599 PRE_MEM_WRITE("ioctl(SIOCGIW[NWID|SENS|RATE|RTS|FRAG|TXPOW|"
8600 "RETRY|PARAM|AUTH])",
8601 (Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.nwid
,
8602 sizeof(struct vki_iw_param
));
8605 case VKI_SIOCGIWFREQ
:
8607 PRE_MEM_WRITE("ioctl(SIOCGIWFREQ",
8608 (Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.freq
,
8609 sizeof(struct vki_iw_freq
));
8612 case VKI_SIOCGIWMODE
:
8614 PRE_MEM_WRITE("ioctl(SIOCGIWMODE",
8615 (Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.mode
,
8619 case VKI_SIOCGIWRANGE
:
8620 case VKI_SIOCGIWPRIV
:
8621 case VKI_SIOCGIWSTATS
:
8622 case VKI_SIOCGIWSPY
:
8623 case VKI_SIOCGIWTHRSPY
:
8624 case VKI_SIOCGIWAPLIST
:
8625 case VKI_SIOCGIWSCAN
:
8626 case VKI_SIOCGIWESSID
:
8627 case VKI_SIOCGIWNICKN
:
8628 case VKI_SIOCGIWENCODE
:
8629 case VKI_SIOCGIWGENIE
:
8630 case VKI_SIOCGIWENCODEEXT
:
8632 struct vki_iw_point
* point
;
8633 point
= &((struct vki_iwreq
*)(Addr
)ARG3
)->u
.data
;
8634 PRE_MEM_WRITE("ioctl(SIOCGIW[RANGE|PRIV|STATS|SPY|THRSPY|"
8635 "APLIST|SCAN|ESSID|NICKN|ENCODE|GENIE|ENCODEEXT])",
8636 (Addr
)point
->pointer
, point
->length
);
8641 PRE_MEM_WRITE("ioctl(SIOCGIWAP)",
8642 (Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.ap_addr
,
8643 sizeof(struct vki_sockaddr
));
8647 /* User input device creation */
8648 case VKI_UI_SET_EVBIT
:
8649 case VKI_UI_SET_KEYBIT
:
8650 case VKI_UI_SET_RELBIT
:
8651 case VKI_UI_SET_ABSBIT
:
8652 case VKI_UI_SET_MSCBIT
:
8653 case VKI_UI_SET_LEDBIT
:
8654 case VKI_UI_SET_SNDBIT
:
8655 case VKI_UI_SET_FFBIT
:
8656 case VKI_UI_SET_SWBIT
:
8657 case VKI_UI_SET_PROPBIT
:
8658 /* These just take an int by value */
8661 # if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
8662 || defined(VGPV_mips32_linux_android) \
8663 || defined(VGPV_arm64_linux_android)
8665 case VKI_ASHMEM_GET_SIZE
:
8666 case VKI_ASHMEM_SET_SIZE
:
8667 case VKI_ASHMEM_GET_PROT_MASK
:
8668 case VKI_ASHMEM_SET_PROT_MASK
:
8669 case VKI_ASHMEM_GET_PIN_STATUS
:
8670 case VKI_ASHMEM_PURGE_ALL_CACHES
:
8672 case VKI_ASHMEM_GET_NAME
:
8673 PRE_MEM_WRITE( "ioctl(ASHMEM_SET_NAME)", ARG3
, VKI_ASHMEM_NAME_LEN
);
8675 case VKI_ASHMEM_SET_NAME
:
8676 PRE_MEM_RASCIIZ( "ioctl(ASHMEM_SET_NAME)", ARG3
);
8678 case VKI_ASHMEM_PIN
:
8679 case VKI_ASHMEM_UNPIN
:
8680 PRE_MEM_READ( "ioctl(ASHMEM_PIN|ASHMEM_UNPIN)",
8681 ARG3
, sizeof(struct vki_ashmem_pin
) );
8685 case VKI_BINDER_WRITE_READ
:
8687 struct vki_binder_write_read
* bwr
8688 = (struct vki_binder_write_read
*)(Addr
)ARG3
;
8690 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_buffer",
8692 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_size",
8694 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_consumed",
8695 bwr
->write_consumed
);
8696 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_buffer",
8698 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_size",
8700 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_consumed",
8701 bwr
->read_consumed
);
8703 PRE_FIELD_WRITE("ioctl(BINDER_WRITE_READ).write_consumed",
8704 bwr
->write_consumed
);
8705 PRE_FIELD_WRITE("ioctl(BINDER_WRITE_READ).read_consumed",
8706 bwr
->read_consumed
);
8709 PRE_MEM_WRITE("ioctl(BINDER_WRITE_READ).read_buffer[]",
8710 (Addr
)bwr
->read_buffer
, bwr
->read_size
);
8711 if (bwr
->write_size
)
8712 PRE_MEM_READ("ioctl(BINDER_WRITE_READ).write_buffer[]",
8713 (Addr
)bwr
->write_buffer
, bwr
->write_size
);
8717 case VKI_BINDER_SET_IDLE_TIMEOUT
:
8718 case VKI_BINDER_SET_MAX_THREADS
:
8719 case VKI_BINDER_SET_IDLE_PRIORITY
:
8720 case VKI_BINDER_SET_CONTEXT_MGR
:
8721 case VKI_BINDER_THREAD_EXIT
:
8723 case VKI_BINDER_VERSION
:
8725 struct vki_binder_version
* bv
=
8726 (struct vki_binder_version
*)(Addr
)ARG3
;
8727 PRE_FIELD_WRITE("ioctl(BINDER_VERSION)", bv
->protocol_version
);
8730 # endif /* defined(VGPV_*_linux_android) */
8732 case VKI_HCIGETDEVLIST
:
8734 struct vki_hci_dev_list_req
* dlr
=
8735 (struct vki_hci_dev_list_req
*)(Addr
)ARG3
;
8736 PRE_MEM_READ("ioctl(HCIGETDEVLIST)",
8737 (Addr
)ARG3
, sizeof(struct vki_hci_dev_list_req
));
8738 PRE_MEM_WRITE("ioctl(HCIGETDEVLIST)",
8739 (Addr
)ARG3
+ sizeof(struct vki_hci_dev_list_req
),
8740 dlr
->dev_num
* sizeof(struct vki_hci_dev_req
));
8744 case VKI_HCIINQUIRY
:
8746 struct vki_hci_inquiry_req
* ir
=
8747 (struct vki_hci_inquiry_req
*)(Addr
)ARG3
;
8748 PRE_MEM_READ("ioctl(HCIINQUIRY)",
8749 (Addr
)ARG3
, sizeof(struct vki_hci_inquiry_req
));
8750 PRE_MEM_WRITE("ioctl(HCIINQUIRY)",
8751 (Addr
)ARG3
+ sizeof(struct vki_hci_inquiry_req
),
8752 ir
->num_rsp
* sizeof(struct vki_inquiry_info
));
8756 case VKI_DRM_IOCTL_VERSION
:
8758 struct vki_drm_version
* data
= (struct vki_drm_version
*)(Addr
)ARG3
;
8759 struct vg_drm_version_info
* info
;
8760 PRE_MEM_WRITE("ioctl(DRM_VERSION).version_major", (Addr
)&data
->version_major
, sizeof(data
->version_major
));
8761 PRE_MEM_WRITE("ioctl(DRM_VERSION).version_minor", (Addr
)&data
->version_minor
, sizeof(data
->version_minor
));
8762 PRE_MEM_WRITE("ioctl(DRM_VERSION).version_patchlevel", (Addr
)&data
->version_patchlevel
, sizeof(data
->version_patchlevel
));
8763 PRE_MEM_READ("ioctl(DRM_VERSION).name_len", (Addr
)&data
->name_len
, sizeof(data
->name_len
));
8764 PRE_MEM_READ("ioctl(DRM_VERSION).name", (Addr
)&data
->name
, sizeof(data
->name
));
8765 PRE_MEM_WRITE("ioctl(DRM_VERSION).name", (Addr
)data
->name
, data
->name_len
);
8766 PRE_MEM_READ("ioctl(DRM_VERSION).date_len", (Addr
)&data
->date_len
, sizeof(data
->date_len
));
8767 PRE_MEM_READ("ioctl(DRM_VERSION).date", (Addr
)&data
->date
, sizeof(data
->date
));
8768 PRE_MEM_WRITE("ioctl(DRM_VERSION).date", (Addr
)data
->date
, data
->date_len
);
8769 PRE_MEM_READ("ioctl(DRM_VERSION).desc_len", (Addr
)&data
->desc_len
, sizeof(data
->desc_len
));
8770 PRE_MEM_READ("ioctl(DRM_VERSION).desc", (Addr
)&data
->desc
, sizeof(data
->desc
));
8771 PRE_MEM_WRITE("ioctl(DRM_VERSION).desc", (Addr
)data
->desc
, data
->desc_len
);
8772 info
= VG_(malloc
)("syswrap.ioctl.1", sizeof(*info
));
8773 // To ensure we VG_(free) info even when syscall fails:
8774 *flags
|= SfPostOnFail
;
8777 ARG3
= (Addr
)&info
->data
;
8780 case VKI_DRM_IOCTL_GET_UNIQUE
:
8782 struct vki_drm_unique
*data
= (struct vki_drm_unique
*)(Addr
)ARG3
;
8783 PRE_MEM_READ("ioctl(DRM_GET_UNIQUE).unique_len", (Addr
)&data
->unique_len
, sizeof(data
->unique_len
));
8784 PRE_MEM_READ("ioctl(DRM_GET_UNIQUE).unique", (Addr
)&data
->unique
, sizeof(data
->unique
));
8785 PRE_MEM_WRITE("ioctl(DRM_GET_UNIQUE).unique", (Addr
)data
->unique
, data
->unique_len
);
8788 case VKI_DRM_IOCTL_GET_MAGIC
:
8790 struct vki_drm_auth
*data
= (struct vki_drm_auth
*)(Addr
)ARG3
;
8791 PRE_MEM_WRITE("ioctl(DRM_GET_MAGIC).magic", (Addr
)&data
->magic
, sizeof(data
->magic
));
8794 case VKI_DRM_IOCTL_WAIT_VBLANK
:
8796 union vki_drm_wait_vblank
*data
=
8797 (union vki_drm_wait_vblank
*)(Addr
)ARG3
;
8798 PRE_MEM_READ("ioctl(DRM_WAIT_VBLANK).request.type", (Addr
)&data
->request
.type
, sizeof(data
->request
.type
));
8799 PRE_MEM_READ("ioctl(DRM_WAIT_VBLANK).request.sequence", (Addr
)&data
->request
.sequence
, sizeof(data
->request
.sequence
));
8800 /* XXX: It seems request.signal isn't used */
8801 PRE_MEM_WRITE("ioctl(DRM_WAIT_VBLANK).reply", (Addr
)&data
->reply
, sizeof(data
->reply
));
8804 case VKI_DRM_IOCTL_GEM_CLOSE
:
8806 struct vki_drm_gem_close
*data
=
8807 (struct vki_drm_gem_close
*)(Addr
)ARG3
;
8808 PRE_MEM_READ("ioctl(DRM_GEM_CLOSE).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8811 case VKI_DRM_IOCTL_GEM_FLINK
:
8813 struct vki_drm_gem_flink
*data
=
8814 (struct vki_drm_gem_flink
*)(Addr
)ARG3
;
8815 PRE_MEM_READ("ioctl(DRM_GEM_FLINK).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8816 PRE_MEM_WRITE("ioctl(DRM_GEM_FLINK).name", (Addr
)&data
->name
, sizeof(data
->name
));
8819 case VKI_DRM_IOCTL_GEM_OPEN
:
8821 struct vki_drm_gem_open
*data
= (struct vki_drm_gem_open
*)(Addr
)ARG3
;
8822 PRE_MEM_READ("ioctl(DRM_GEM_OPEN).name", (Addr
)&data
->name
, sizeof(data
->name
));
8823 PRE_MEM_WRITE("ioctl(DRM_GEM_OPEN).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8824 PRE_MEM_WRITE("ioctl(DRM_GEM_OPEN).size", (Addr
)&data
->size
, sizeof(data
->size
));
8827 case VKI_DRM_IOCTL_I915_GETPARAM
:
8829 vki_drm_i915_getparam_t
*data
= (vki_drm_i915_getparam_t
*)(Addr
)ARG3
;
8830 PRE_MEM_READ("ioctl(DRM_I915_GETPARAM).param", (Addr
)&data
->param
, sizeof(data
->param
));
8831 PRE_MEM_WRITE("ioctl(DRM_I915_GETPARAM).value", (Addr
)data
->value
, sizeof(int));
8834 case VKI_DRM_IOCTL_I915_GEM_BUSY
:
8836 struct vki_drm_i915_gem_busy
*data
=
8837 (struct vki_drm_i915_gem_busy
*)(Addr
)ARG3
;
8838 PRE_MEM_READ("ioctl(DRM_I915_GEM_BUSY).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8839 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_BUSY).busy", (Addr
)&data
->busy
, sizeof(data
->busy
));
8842 case VKI_DRM_IOCTL_I915_GEM_CREATE
:
8844 struct vki_drm_i915_gem_create
*data
=
8845 (struct vki_drm_i915_gem_create
*)(Addr
)ARG3
;
8846 PRE_MEM_READ("ioctl(DRM_I915_GEM_CREATE).size", (Addr
)&data
->size
, sizeof(data
->size
));
8847 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_CREATE).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8850 case VKI_DRM_IOCTL_I915_GEM_PREAD
:
8852 struct vki_drm_i915_gem_pread
*data
=
8853 (struct vki_drm_i915_gem_pread
*)(Addr
)ARG3
;
8854 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8855 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).offset", (Addr
)&data
->offset
, sizeof(data
->offset
));
8856 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).size", (Addr
)&data
->size
, sizeof(data
->size
));
8857 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).data_ptr", (Addr
)&data
->data_ptr
, sizeof(data
->data_ptr
));
8858 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_PREAD).data_ptr", (Addr
)data
->data_ptr
, data
->size
);
8861 case VKI_DRM_IOCTL_I915_GEM_PWRITE
:
8863 struct vki_drm_i915_gem_pwrite
*data
=
8864 (struct vki_drm_i915_gem_pwrite
*)(Addr
)ARG3
;
8865 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8866 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).offset", (Addr
)&data
->offset
, sizeof(data
->offset
));
8867 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).size", (Addr
)&data
->size
, sizeof(data
->size
));
8868 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).data_ptr", (Addr
)&data
->data_ptr
, sizeof(data
->data_ptr
));
8869 /* PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).data_ptr", (Addr)data->data_ptr, data->size);
8870 * NB: the buffer is allowed to contain any amount of uninitialized data (e.g.
8871 * interleaved vertex attributes may have a wide stride with uninitialized data between
8872 * consecutive vertices) */
8875 case VKI_DRM_IOCTL_I915_GEM_MMAPv1
:
8877 struct vki_drm_i915_gem_mmap_v1
*data
=
8878 (struct vki_drm_i915_gem_mmap_v1
*)(Addr
)ARG3
;
8879 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAPv1).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8880 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAPv1).offset", (Addr
)&data
->offset
, sizeof(data
->offset
));
8881 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAPv1).size", (Addr
)&data
->size
, sizeof(data
->size
));
8882 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_MMAPv1).addr_ptr", (Addr
)&data
->addr_ptr
, sizeof(data
->addr_ptr
));
8885 case VKI_DRM_IOCTL_I915_GEM_MMAP
:
8887 struct vki_drm_i915_gem_mmap
*data
=
8888 (struct vki_drm_i915_gem_mmap
*)(Addr
)ARG3
;
8889 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8890 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP).offset", (Addr
)&data
->offset
, sizeof(data
->offset
));
8891 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP).size", (Addr
)&data
->size
, sizeof(data
->size
));
8892 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP).flags", (Addr
)&data
->size
, sizeof(data
->flags
));
8893 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_MMAP).addr_ptr", (Addr
)&data
->addr_ptr
, sizeof(data
->addr_ptr
));
8896 case VKI_DRM_IOCTL_I915_GEM_MMAP_GTT
:
8898 struct vki_drm_i915_gem_mmap_gtt
*data
=
8899 (struct vki_drm_i915_gem_mmap_gtt
*)(Addr
)ARG3
;
8900 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP_GTT).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8901 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_MMAP_GTT).offset", (Addr
)&data
->offset
, sizeof(data
->offset
));
8904 case VKI_DRM_IOCTL_I915_GEM_SET_DOMAIN
:
8906 struct vki_drm_i915_gem_set_domain
*data
=
8907 (struct vki_drm_i915_gem_set_domain
*)(Addr
)ARG3
;
8908 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8909 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).read_domains", (Addr
)&data
->read_domains
, sizeof(data
->read_domains
));
8910 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).write_domain", (Addr
)&data
->write_domain
, sizeof(data
->write_domain
));
8913 case VKI_DRM_IOCTL_I915_GEM_SET_TILING
:
8915 struct vki_drm_i915_gem_set_tiling
*data
=
8916 (struct vki_drm_i915_gem_set_tiling
*)(Addr
)ARG3
;
8917 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8918 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).tiling_mode", (Addr
)&data
->tiling_mode
, sizeof(data
->tiling_mode
));
8919 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).stride", (Addr
)&data
->stride
, sizeof(data
->stride
));
8920 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_SET_TILING).swizzle_mode", (Addr
)&data
->swizzle_mode
, sizeof(data
->swizzle_mode
));
8923 case VKI_DRM_IOCTL_I915_GEM_GET_TILING
:
8925 struct vki_drm_i915_gem_get_tiling
*data
=
8926 (struct vki_drm_i915_gem_get_tiling
*)(Addr
)ARG3
;
8927 PRE_MEM_READ("ioctl(DRM_I915_GEM_GET_TILING).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8928 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_TILING).tiling_mode", (Addr
)&data
->tiling_mode
, sizeof(data
->tiling_mode
));
8929 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_TILING).swizzle_mode", (Addr
)&data
->swizzle_mode
, sizeof(data
->swizzle_mode
));
8932 case VKI_DRM_IOCTL_I915_GEM_GET_APERTURE
:
8934 struct vki_drm_i915_gem_get_aperture
*data
=
8935 (struct vki_drm_i915_gem_get_aperture
*)(Addr
)ARG3
;
8936 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_APERTURE).aper_size", (Addr
)&data
->aper_size
, sizeof(data
->aper_size
));
8937 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_APERTURE).aper_available_size", (Addr
)&data
->aper_available_size
, sizeof(data
->aper_available_size
));
8941 /* KVM ioctls that check for a numeric value as parameter */
8942 case VKI_KVM_GET_API_VERSION
:
8943 case VKI_KVM_CREATE_VM
:
8944 case VKI_KVM_GET_VCPU_MMAP_SIZE
:
8945 case VKI_KVM_CHECK_EXTENSION
:
8946 case VKI_KVM_SET_TSS_ADDR
:
8947 case VKI_KVM_CREATE_VCPU
:
8951 case VKI_KVM_S390_MEM_OP
: {
8952 struct vki_kvm_s390_mem_op
*args
=
8953 (struct vki_kvm_s390_mem_op
*)(Addr
)(ARG3
);
8954 PRE_MEM_READ("ioctl(KVM_S390_MEM_OP)", ARG3
,
8955 sizeof(struct vki_kvm_s390_mem_op
));
8956 if (args
->flags
& VKI_KVM_S390_MEMOP_F_CHECK_ONLY
)
8958 if (args
->op
== VKI_KVM_S390_MEMOP_LOGICAL_READ
)
8959 PRE_MEM_WRITE("ioctl(KVM_S390_MEM_OP).buf", (Addr
)args
->buf
, args
->size
);
8960 if (args
->op
== VKI_KVM_S390_MEMOP_LOGICAL_WRITE
)
8961 PRE_MEM_READ("ioctl(KVM_S390_MEM_OP).buf", (Addr
)args
->buf
, args
->size
);
8967 case VKI_XEN_IOCTL_PRIVCMD_HYPERCALL
: {
8968 SyscallArgs harrghs
;
8969 struct vki_xen_privcmd_hypercall
*args
=
8970 (struct vki_xen_privcmd_hypercall
*)(Addr
)(ARG3
);
8975 VG_(memset
)(&harrghs
, 0, sizeof(harrghs
));
8976 harrghs
.sysno
= args
->op
;
8977 harrghs
.arg1
= args
->arg
[0];
8978 harrghs
.arg2
= args
->arg
[1];
8979 harrghs
.arg3
= args
->arg
[2];
8980 harrghs
.arg4
= args
->arg
[3];
8981 harrghs
.arg5
= args
->arg
[4];
8982 harrghs
.arg6
= harrghs
.arg7
= harrghs
.arg8
= 0;
8984 WRAPPER_PRE_NAME(xen
, hypercall
) (tid
, layout
, &harrghs
, status
, flags
);
8986 /* HACK. arg8 is used to return the number of hypercall
8987 * arguments actually consumed! */
8988 PRE_MEM_READ("hypercall", ARG3
, sizeof(args
->op
) +
8989 ( sizeof(args
->arg
[0]) * harrghs
.arg8
) );
8994 case VKI_XEN_IOCTL_PRIVCMD_MMAP
: {
8995 struct vki_xen_privcmd_mmap
*args
=
8996 (struct vki_xen_privcmd_mmap
*)(Addr
)(ARG3
);
8997 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(num)",
8998 (Addr
)&args
->num
, sizeof(args
->num
));
8999 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(dom)",
9000 (Addr
)&args
->dom
, sizeof(args
->dom
));
9001 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(entry)",
9002 (Addr
)args
->entry
, sizeof(*(args
->entry
)) * args
->num
);
9005 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH
: {
9006 struct vki_xen_privcmd_mmapbatch
*args
=
9007 (struct vki_xen_privcmd_mmapbatch
*)(Addr
)(ARG3
);
9008 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(num)",
9009 (Addr
)&args
->num
, sizeof(args
->num
));
9010 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(dom)",
9011 (Addr
)&args
->dom
, sizeof(args
->dom
));
9012 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(addr)",
9013 (Addr
)&args
->addr
, sizeof(args
->addr
));
9014 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(arr)",
9015 (Addr
)args
->arr
, sizeof(*(args
->arr
)) * args
->num
);
9018 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2
: {
9019 struct vki_xen_privcmd_mmapbatch_v2
*args
=
9020 (struct vki_xen_privcmd_mmapbatch_v2
*)(Addr
)(ARG3
);
9021 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(num)",
9022 (Addr
)&args
->num
, sizeof(args
->num
));
9023 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(dom)",
9024 (Addr
)&args
->dom
, sizeof(args
->dom
));
9025 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(addr)",
9026 (Addr
)&args
->addr
, sizeof(args
->addr
));
9027 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(arr)",
9028 (Addr
)args
->arr
, sizeof(*(args
->arr
)) * args
->num
);
9032 case VKI_XEN_IOCTL_EVTCHN_BIND_VIRQ
: {
9033 struct vki_xen_ioctl_evtchn_bind_virq
*args
=
9034 (struct vki_xen_ioctl_evtchn_bind_virq
*)(Addr
)(ARG3
);
9035 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_VIRQ(virq)",
9036 (Addr
)&args
->virq
, sizeof(args
->virq
));
9039 case VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN
: {
9040 struct vki_xen_ioctl_evtchn_bind_interdomain
*args
=
9041 (struct vki_xen_ioctl_evtchn_bind_interdomain
*)(Addr
)(ARG3
);
9042 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN(remote_domain)",
9043 (Addr
)&args
->remote_domain
, sizeof(args
->remote_domain
));
9044 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN(remote_port)",
9045 (Addr
)&args
->remote_port
, sizeof(args
->remote_port
));
9048 case VKI_XEN_IOCTL_EVTCHN_BIND_UNBOUND_PORT
: {
9049 struct vki_xen_ioctl_evtchn_bind_unbound_port
*args
=
9050 (struct vki_xen_ioctl_evtchn_bind_unbound_port
*)(Addr
)(ARG3
);
9051 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_UNBOUND_PORT(remote_domain)",
9052 (Addr
)&args
->remote_domain
, sizeof(args
->remote_domain
));
9055 case VKI_XEN_IOCTL_EVTCHN_UNBIND
: {
9056 struct vki_xen_ioctl_evtchn_unbind
*args
=
9057 (struct vki_xen_ioctl_evtchn_unbind
*)(Addr
)(ARG3
);
9058 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_UNBIND(port)",
9059 (Addr
)&args
->port
, sizeof(args
->port
));
9062 case VKI_XEN_IOCTL_EVTCHN_NOTIFY
: {
9063 struct vki_xen_ioctl_evtchn_notify
*args
=
9064 (struct vki_xen_ioctl_evtchn_notify
*)(Addr
)(ARG3
);
9065 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_notify(port)",
9066 (Addr
)&args
->port
, sizeof(args
->port
));
9069 case VKI_XEN_IOCTL_EVTCHN_RESET
:
9075 case VKI_OBD_IOC_FID2PATH
: {
9076 struct vki_getinfo_fid2path
*gf
=
9077 (struct vki_getinfo_fid2path
*)(Addr
)ARG3
;
9078 PRE_MEM_READ("VKI_OBD_IOC_FID2PATH(args)", ARG3
, sizeof(struct vki_getinfo_fid2path
));
9079 PRE_FIELD_WRITE("VKI_OBD_IOC_FID2PATH(args).gf_recno", gf
->gf_recno
);
9080 PRE_FIELD_WRITE("VKI_OBD_IOC_FID2PATH(args).gf_linkno", gf
->gf_linkno
);
9081 PRE_MEM_WRITE("VKI_OBD_IOC_FID2PATH(args)", (Addr
)gf
->gf_path
, gf
->gf_pathlen
);
9085 case VKI_LL_IOC_PATH2FID
:
9086 PRE_MEM_WRITE("ioctl(VKI_LL_IOC_PATH2FID)", ARG3
, sizeof(struct vki_lu_fid
));
9089 case VKI_LL_IOC_GETPARENT
: {
9090 struct vki_getparent
*gp
= (struct vki_getparent
*)(Addr
)ARG3
;
9091 PRE_FIELD_READ("ioctl(VKI_LL_IOC_GETPARENT).gp_linkno", gp
->gp_linkno
);
9092 PRE_FIELD_READ("ioctl(VKI_LL_IOC_GETPARENT).gp_name_size", gp
->gp_name_size
);
9093 PRE_FIELD_WRITE("ioctl(VKI_LL_IOC_GETPARENT).gp_fid", gp
->gp_fid
);
9094 PRE_MEM_WRITE("ioctl(VKI_LL_IOC_GETPARENT).gp_name", (Addr
)gp
->gp_name
, gp
->gp_name_size
);
9099 case VKI_V4L2_QUERYCAP
: {
9100 struct vki_v4l2_capability
*data
=
9101 (struct vki_v4l2_capability
*)(Addr
)ARG3
;
9102 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYCAP)", (Addr
)data
, sizeof(*data
));
9105 case VKI_V4L2_ENUM_FMT
: {
9106 struct vki_v4l2_fmtdesc
*data
= (struct vki_v4l2_fmtdesc
*)(Addr
)ARG3
;
9107 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FMT).index", data
->index
);
9108 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FMT).type", data
->type
);
9109 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).flags", data
->flags
);
9110 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).description", data
->description
);
9111 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).pixelformat", data
->pixelformat
);
9112 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).reserved", data
->reserved
);
9115 case VKI_V4L2_G_FMT
: {
9116 struct vki_v4l2_format
*data
= (struct vki_v4l2_format
*)(Addr
)ARG3
;
9117 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).type", data
->type
);
9118 switch (data
->type
) {
9119 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE
:
9120 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
:
9121 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.pix.priv", data
->fmt
.pix
.priv
);
9122 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.pix", data
->fmt
.pix
);
9123 PRE_MEM_READ("ioctl(VKI_V4L2_G_FMT)",
9124 (Addr
)&data
->type
+ sizeof(data
->type
) + sizeof(data
->fmt
.pix
),
9125 sizeof(*data
) - sizeof(data
->type
) - sizeof(data
->fmt
.pix
));
9127 case VKI_V4L2_BUF_TYPE_VBI_CAPTURE
:
9128 case VKI_V4L2_BUF_TYPE_VBI_OUTPUT
:
9129 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.vbi", data
->fmt
.vbi
);
9131 case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
9132 case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
9133 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.sliced", data
->fmt
.sliced
);
9135 case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY
:
9136 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
9137 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.win.clips", data
->fmt
.win
.clips
);
9138 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.win.bitmap", data
->fmt
.win
.bitmap
);
9139 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.win.clipcount", data
->fmt
.win
.clipcount
);
9140 if (data
->fmt
.win
.clipcount
&& data
->fmt
.win
.clips
)
9141 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.clips[]",
9142 (Addr
)data
->fmt
.win
.clips
,
9143 data
->fmt
.win
.clipcount
* sizeof(data
->fmt
.win
.clips
[0]));
9144 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.clipcount", data
->fmt
.win
.clipcount
);
9145 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.w", data
->fmt
.win
.w
);
9146 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.field", data
->fmt
.win
.field
);
9147 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.chromakey", data
->fmt
.win
.chromakey
);
9148 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.global_alpha", data
->fmt
.win
.global_alpha
);
9150 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
9151 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
9152 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.pix_mp", data
->fmt
.pix_mp
);
9154 case VKI_V4L2_BUF_TYPE_SDR_CAPTURE
:
9155 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.sdr", data
->fmt
.sdr
);
9160 case VKI_V4L2_S_FMT
: {
9161 struct vki_v4l2_format
*data
= (struct vki_v4l2_format
*)(Addr
)ARG3
;
9162 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).type", data
->type
);
9163 switch (data
->type
) {
9164 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE
:
9165 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
:
9166 PRE_MEM_READ("ioctl(VKI_V4L2_S_FMT)",
9167 (Addr
)&data
->type
+ sizeof(data
->type
),
9168 sizeof(*data
) - sizeof(data
->type
));
9170 case VKI_V4L2_BUF_TYPE_VBI_CAPTURE
:
9171 case VKI_V4L2_BUF_TYPE_VBI_OUTPUT
:
9172 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.vbi", data
->fmt
.vbi
);
9174 case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
9175 case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
9176 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.sliced", data
->fmt
.sliced
);
9178 case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY
:
9179 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
9180 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.win", data
->fmt
.win
);
9181 if (data
->fmt
.win
.clipcount
&& data
->fmt
.win
.clips
)
9182 PRE_MEM_READ("ioctl(VKI_V4L2_S_FMT).fmt.win.clips[]",
9183 (Addr
)data
->fmt
.win
.clips
,
9184 data
->fmt
.win
.clipcount
* sizeof(data
->fmt
.win
.clips
[0]));
9185 if (data
->fmt
.win
.bitmap
)
9186 PRE_MEM_READ("ioctl(VKI_V4L2_S_FMT).fmt.win.bitmap[]",
9187 (Addr
)data
->fmt
.win
.bitmap
,
9188 data
->fmt
.win
.w
.height
* ((data
->fmt
.win
.w
.width
+ 7) / 8));
9190 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
9191 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
9192 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.pix_mp", data
->fmt
.pix_mp
);
9194 case VKI_V4L2_BUF_TYPE_SDR_CAPTURE
:
9195 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.sdr", data
->fmt
.sdr
);
9200 case VKI_V4L2_TRY_FMT
: {
9201 struct vki_v4l2_format
*data
= (struct vki_v4l2_format
*)(Addr
)ARG3
;
9202 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).type", data
->type
);
9203 switch (data
->type
) {
9204 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE
:
9205 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
:
9206 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_FMT)",
9207 (Addr
)&data
->type
+ sizeof(data
->type
),
9208 sizeof(*data
) - sizeof(data
->type
));
9210 case VKI_V4L2_BUF_TYPE_VBI_CAPTURE
:
9211 case VKI_V4L2_BUF_TYPE_VBI_OUTPUT
:
9212 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.vbi", data
->fmt
.vbi
);
9214 case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
9215 case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
9216 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.sliced", data
->fmt
.sliced
);
9218 case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY
:
9219 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
9220 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.win", data
->fmt
.win
);
9221 if (data
->fmt
.win
.clipcount
&& data
->fmt
.win
.clips
)
9222 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.win.clips[]",
9223 (Addr
)data
->fmt
.win
.clips
,
9224 data
->fmt
.win
.clipcount
* sizeof(data
->fmt
.win
.clips
[0]));
9225 if (data
->fmt
.win
.bitmap
)
9226 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.win.bitmap[]",
9227 (Addr
)data
->fmt
.win
.bitmap
,
9228 data
->fmt
.win
.w
.height
* ((data
->fmt
.win
.w
.width
+ 7) / 8));
9230 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
9231 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
9232 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.pix_mp", data
->fmt
.pix_mp
);
9234 case VKI_V4L2_BUF_TYPE_SDR_CAPTURE
:
9235 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.sdr", data
->fmt
.sdr
);
9240 case VKI_V4L2_REQBUFS
: {
9241 struct vki_v4l2_requestbuffers
*data
=
9242 (struct vki_v4l2_requestbuffers
*)(Addr
)ARG3
;
9243 PRE_MEM_READ("ioctl(VKI_V4L2_REQBUFS)", (Addr
)data
, sizeof(*data
));
9246 case VKI_V4L2_QUERYBUF
: {
9247 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
9248 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).type", data
->type
);
9249 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).index", data
->index
);
9250 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).reserved", data
->reserved
);
9251 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).reserved2", data
->reserved2
);
9252 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
9253 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
9256 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).length", data
->length
);
9257 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).m.planes", data
->m
.planes
);
9258 for (i
= 0; i
< data
->length
; i
++) {
9259 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].bytesused", data
->m
.planes
[i
].bytesused
);
9260 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].length", data
->m
.planes
[i
].length
);
9261 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].m", data
->m
.planes
[i
].m
);
9262 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].data_offset", data
->m
.planes
[i
].data_offset
);
9263 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].reserved", data
->m
.planes
[i
].reserved
);
9266 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m", data
->m
);
9267 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).length", data
->length
);
9269 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).bytesused", data
->bytesused
);
9270 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).flags", data
->flags
);
9271 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).field", data
->field
);
9272 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).timestamp", data
->timestamp
);
9273 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).timecode", data
->timecode
);
9274 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).sequence", data
->sequence
);
9275 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).memory", data
->memory
);
9276 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).sequence", data
->sequence
);
9279 case VKI_V4L2_G_FBUF
: {
9280 struct vki_v4l2_framebuffer
*data
=
9281 (struct vki_v4l2_framebuffer
*)(Addr
)ARG3
;
9282 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_FBUF)", (Addr
)data
, sizeof(*data
));
9285 case VKI_V4L2_S_FBUF
: {
9286 struct vki_v4l2_framebuffer
*data
=
9287 (struct vki_v4l2_framebuffer
*)(Addr
)ARG3
;
9288 PRE_FIELD_WRITE("ioctl(VKI_V4L2_S_FBUF).capability", data
->capability
);
9289 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FBUF).flags", data
->flags
);
9290 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FBUF).base", data
->base
);
9291 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FBUF).fmt", data
->fmt
);
9294 case VKI_V4L2_OVERLAY
: {
9295 int *data
= (int *)(Addr
)ARG3
;
9296 PRE_MEM_READ("ioctl(VKI_V4L2_OVERLAY)", (Addr
)data
, sizeof(*data
));
9299 case VKI_V4L2_QBUF
: {
9300 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
9301 int is_output
= data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
||
9302 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
||
9303 data
->type
== VKI_V4L2_BUF_TYPE_VBI_OUTPUT
||
9304 data
->type
== VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
;
9306 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).type", data
->type
);
9307 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).index", data
->index
);
9308 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).flags", data
->flags
);
9309 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).memory", data
->memory
);
9310 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).reserved", data
->reserved
);
9311 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).reserved2", data
->reserved2
);
9313 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).bytesused", data
->bytesused
);
9314 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).field", data
->field
);
9316 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
9317 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
9320 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).length", data
->length
);
9321 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes", data
->m
.planes
);
9322 for (i
= 0; i
< data
->length
; i
++) {
9324 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].bytesused", data
->m
.planes
[i
].bytesused
);
9325 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].data_offset", data
->m
.planes
[i
].data_offset
);
9327 if (data
->memory
== VKI_V4L2_MEMORY_MMAP
)
9328 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QBUF).m.planes[].m", data
->m
.planes
[i
].m
);
9329 else if (data
->memory
== VKI_V4L2_MEMORY_DMABUF
)
9330 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].m.fd", data
->m
.planes
[i
].m
.fd
);
9332 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].m", data
->m
.planes
[i
].m
);
9333 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].reserved", data
->m
.planes
[i
].reserved
);
9336 if (data
->memory
== VKI_V4L2_MEMORY_MMAP
)
9337 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QBUF).m", data
->m
);
9338 else if (data
->memory
== VKI_V4L2_MEMORY_DMABUF
)
9339 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.fd", data
->m
.fd
);
9341 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m", data
->m
);
9343 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).bytesused", data
->bytesused
);
9344 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).field", data
->field
);
9347 if (is_output
&& (data
->flags
& VKI_V4L2_BUF_FLAG_TIMESTAMP_MASK
) == VKI_V4L2_BUF_FLAG_TIMESTAMP_COPY
) {
9348 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).timestamp", data
->timestamp
);
9349 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).timecode", data
->timecode
);
9353 case VKI_V4L2_EXPBUF
: {
9354 struct vki_v4l2_exportbuffer
*data
=
9355 (struct vki_v4l2_exportbuffer
*)(Addr
)ARG3
;
9356 PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).type", data
->type
);
9357 PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).index", data
->index
);
9358 PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).plane", data
->plane
);
9359 PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).flags", data
->flags
);
9360 PRE_FIELD_WRITE("ioctl(VKI_V4L2_EXPBUF).fd", data
->fd
);
9361 PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).reserved", data
->reserved
);
9364 case VKI_V4L2_DQBUF
: {
9365 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
9366 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).type", data
->type
);
9367 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).index", data
->index
);
9368 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).memory", data
->memory
);
9369 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).reserved", data
->reserved
);
9370 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).reserved2", data
->reserved2
);
9371 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).bytesused", data
->bytesused
);
9372 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).field", data
->field
);
9373 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
9374 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
9377 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).length", data
->length
);
9378 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).m.planes", data
->m
.planes
);
9379 for (i
= 0; i
< data
->length
; i
++) {
9380 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].bytesused", data
->m
.planes
[i
].bytesused
);
9381 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].data_offset", data
->m
.planes
[i
].data_offset
);
9382 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].length", data
->m
.planes
[i
].length
);
9383 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].m", data
->m
.planes
[i
].m
);
9384 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).m.planes[].reserved", data
->m
.planes
[i
].reserved
);
9387 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m", data
->m
);
9388 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).length", data
->length
);
9389 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).bytesused", data
->bytesused
);
9390 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).field", data
->field
);
9392 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).timestamp", data
->timestamp
);
9393 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).timecode", data
->timecode
);
9394 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).sequence", data
->sequence
);
9397 case VKI_V4L2_STREAMON
: {
9398 int *data
= (int *)(Addr
)ARG3
;
9399 PRE_MEM_READ("ioctl(VKI_V4L2_STREAMON)", (Addr
)data
, sizeof(*data
));
9402 case VKI_V4L2_STREAMOFF
: {
9403 int *data
= (int *)(Addr
)ARG3
;
9404 PRE_MEM_READ("ioctl(VKI_V4L2_STREAMOFF)", (Addr
)data
, sizeof(*data
));
9407 case VKI_V4L2_G_PARM
: {
9408 struct vki_v4l2_streamparm
*data
=
9409 (struct vki_v4l2_streamparm
*)(Addr
)ARG3
;
9410 int is_output
= data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
||
9411 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
||
9412 data
->type
== VKI_V4L2_BUF_TYPE_VBI_OUTPUT
||
9413 data
->type
== VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
;
9415 PRE_FIELD_READ("ioctl(VKI_V4L2_G_PARM).type", data
->type
);
9417 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_PARM)", (Addr
)&data
->parm
.output
,
9418 sizeof(data
->parm
.output
) - sizeof(data
->parm
.output
.reserved
));
9419 PRE_FIELD_READ("ioctl(VKI_V4L2_G_PARM).parm.output.reserved", data
->parm
.output
.reserved
);
9421 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_PARM)", (Addr
)&data
->parm
.capture
,
9422 sizeof(data
->parm
.capture
) - sizeof(data
->parm
.capture
.reserved
));
9423 PRE_FIELD_READ("ioctl(VKI_V4L2_G_PARM).parm.capture.reserved", data
->parm
.capture
.reserved
);
9427 case VKI_V4L2_S_PARM
: {
9428 struct vki_v4l2_streamparm
*data
=
9429 (struct vki_v4l2_streamparm
*)(Addr
)ARG3
;
9430 int is_output
= data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
||
9431 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
||
9432 data
->type
== VKI_V4L2_BUF_TYPE_VBI_OUTPUT
||
9433 data
->type
== VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
;
9435 PRE_FIELD_READ("ioctl(VKI_V4L2_S_PARM).type", data
->type
);
9437 PRE_FIELD_READ("ioctl(VKI_V4L2_S_PARM).parm.output", data
->parm
.output
);
9439 PRE_FIELD_READ("ioctl(VKI_V4L2_S_PARM).parm.capture", data
->parm
.capture
);
9442 case VKI_V4L2_G_STD
: {
9443 vki_v4l2_std_id
*data
= (vki_v4l2_std_id
*)(Addr
)ARG3
;
9444 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_STD)", (Addr
)data
, sizeof(*data
));
9447 case VKI_V4L2_S_STD
: {
9448 vki_v4l2_std_id
*data
= (vki_v4l2_std_id
*)(Addr
)ARG3
;
9449 PRE_MEM_READ("ioctl(VKI_V4L2_S_STD)", (Addr
)data
, sizeof(*data
));
9452 case VKI_V4L2_ENUMSTD
: {
9453 struct vki_v4l2_standard
*data
= (struct vki_v4l2_standard
*)(Addr
)ARG3
;
9454 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMSTD).index", data
->index
);
9455 PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMSTD)", (Addr
)&data
->id
, sizeof(*data
) - sizeof(data
->index
));
9458 case VKI_V4L2_ENUMINPUT
: {
9459 struct vki_v4l2_input
*data
= (struct vki_v4l2_input
*)(Addr
)ARG3
;
9460 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMINPUT).index", data
->index
);
9461 PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMINPUT)", (Addr
)data
->name
, sizeof(*data
) - sizeof(data
->index
));
9464 case VKI_V4L2_G_CTRL
: {
9465 struct vki_v4l2_control
*data
= (struct vki_v4l2_control
*)(Addr
)ARG3
;
9466 PRE_FIELD_READ("ioctl(VKI_V4L2_G_CTRL).id", data
->id
);
9467 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_CTRL).value", data
->value
);
9470 case VKI_V4L2_S_CTRL
: {
9471 struct vki_v4l2_control
*data
= (struct vki_v4l2_control
*)(Addr
)ARG3
;
9472 PRE_MEM_READ("ioctl(VKI_V4L2_S_CTRL)", (Addr
)data
, sizeof(*data
));
9475 case VKI_V4L2_G_TUNER
: {
9476 struct vki_v4l2_tuner
*data
= (struct vki_v4l2_tuner
*)(Addr
)ARG3
;
9477 PRE_FIELD_READ("ioctl(VKI_V4L2_G_TUNER).index", data
->index
);
9478 PRE_FIELD_READ("ioctl(VKI_V4L2_G_TUNER).reserved", data
->reserved
);
9479 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_TUNER)", (Addr
)data
->name
,
9480 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
9483 case VKI_V4L2_S_TUNER
: {
9484 struct vki_v4l2_tuner
*data
= (struct vki_v4l2_tuner
*)(Addr
)ARG3
;
9485 PRE_FIELD_READ("ioctl(VKI_V4L2_S_TUNER).index", data
->index
);
9486 PRE_FIELD_READ("ioctl(VKI_V4L2_S_TUNER).audmode", data
->audmode
);
9487 PRE_FIELD_READ("ioctl(VKI_V4L2_S_TUNER).reserved", data
->reserved
);
9490 case VKI_V4L2_G_AUDIO
: {
9491 struct vki_v4l2_audio
*data
= (struct vki_v4l2_audio
*)(Addr
)ARG3
;
9492 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_AUDIO)", (Addr
)data
,
9493 sizeof(*data
) - sizeof(data
->reserved
));
9494 PRE_FIELD_READ("ioctl(VKI_V4L2_G_AUDIO).reserved", data
->reserved
);
9497 case VKI_V4L2_S_AUDIO
: {
9498 struct vki_v4l2_audio
*data
= (struct vki_v4l2_audio
*)(Addr
)ARG3
;
9499 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDIO).index", data
->index
);
9500 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDIO).mode", data
->mode
);
9501 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDIO).reserved", data
->reserved
);
9504 case VKI_V4L2_QUERYCTRL
: {
9505 struct vki_v4l2_queryctrl
*data
= (struct vki_v4l2_queryctrl
*)(Addr
)ARG3
;
9506 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYCTRL).id", data
->id
);
9507 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYCTRL)", (Addr
)&data
->type
,
9508 sizeof(*data
) - sizeof(data
->id
));
9511 case VKI_V4L2_QUERYMENU
: {
9512 struct vki_v4l2_querymenu
*data
= (struct vki_v4l2_querymenu
*)(Addr
)ARG3
;
9513 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYMENU).id", data
->id
);
9514 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYMENU).index", data
->index
);
9515 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYMENU)", (Addr
)data
->name
,
9516 sizeof(*data
) - sizeof(data
->id
) - sizeof(data
->index
));
9519 case VKI_V4L2_G_INPUT
: {
9520 int *data
= (int *)(Addr
)ARG3
;
9521 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_INPUT)", (Addr
)data
, sizeof(*data
));
9524 case VKI_V4L2_S_INPUT
: {
9525 int *data
= (int *)(Addr
)ARG3
;
9526 PRE_MEM_READ("ioctl(VKI_V4L2_S_INPUT)", (Addr
)data
, sizeof(*data
));
9529 case VKI_V4L2_G_EDID
: {
9530 struct vki_v4l2_edid
*data
= (struct vki_v4l2_edid
*)(Addr
)ARG3
;
9531 PRE_MEM_READ("ioctl(VKI_V4L2_G_EDID)", (Addr
)data
, sizeof(*data
));
9532 if (data
->blocks
&& data
->edid
)
9533 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_EDID)", (Addr
)data
->edid
, data
->blocks
* 128);
9536 case VKI_V4L2_S_EDID
: {
9537 struct vki_v4l2_edid
*data
= (struct vki_v4l2_edid
*)(Addr
)ARG3
;
9538 PRE_MEM_READ("ioctl(VKI_V4L2_S_EDID)", (Addr
)data
, sizeof(*data
));
9539 if (data
->blocks
&& data
->edid
)
9540 PRE_MEM_READ("ioctl(VKI_V4L2_S_EDID)", (Addr
)data
->edid
, data
->blocks
* 128);
9543 case VKI_V4L2_G_OUTPUT
: {
9544 int *data
= (int *)(Addr
)ARG3
;
9545 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_OUTPUT)", (Addr
)data
, sizeof(*data
));
9548 case VKI_V4L2_S_OUTPUT
: {
9549 int *data
= (int *)(Addr
)ARG3
;
9550 PRE_MEM_READ("ioctl(VKI_V4L2_S_OUTPUT)", (Addr
)data
, sizeof(*data
));
9553 case VKI_V4L2_ENUMOUTPUT
: {
9554 struct vki_v4l2_output
*data
= (struct vki_v4l2_output
*)(Addr
)ARG3
;
9555 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMOUTPUT).index", data
->index
);
9556 PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMOUTPUT)", (Addr
)data
->name
, sizeof(*data
) - sizeof(data
->index
));
9559 case VKI_V4L2_G_AUDOUT
: {
9560 struct vki_v4l2_audioout
*data
= (struct vki_v4l2_audioout
*)(Addr
)ARG3
;
9561 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_AUDOUT)", (Addr
)data
,
9562 sizeof(*data
) - sizeof(data
->reserved
));
9563 PRE_FIELD_READ("ioctl(VKI_V4L2_G_AUDOUT).reserved", data
->reserved
);
9566 case VKI_V4L2_S_AUDOUT
: {
9567 struct vki_v4l2_audioout
*data
= (struct vki_v4l2_audioout
*)(Addr
)ARG3
;
9568 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDOUT).index", data
->index
);
9569 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDOUT).reserved", data
->reserved
);
9570 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDOUT).mode", data
->mode
);
9573 case VKI_V4L2_G_MODULATOR
: {
9574 struct vki_v4l2_modulator
*data
= (struct vki_v4l2_modulator
*)(Addr
)ARG3
;
9575 PRE_FIELD_READ("ioctl(VKI_V4L2_G_MODULATOR).index", data
->index
);
9576 PRE_FIELD_READ("ioctl(VKI_V4L2_G_MODULATOR).reserved", data
->reserved
);
9577 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_MODULATOR)", (Addr
)data
->name
,
9578 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
9581 case VKI_V4L2_S_MODULATOR
: {
9582 struct vki_v4l2_modulator
*data
= (struct vki_v4l2_modulator
*)(Addr
)ARG3
;
9583 PRE_FIELD_READ("ioctl(VKI_V4L2_S_MODULATOR).index", data
->index
);
9584 PRE_FIELD_READ("ioctl(VKI_V4L2_S_MODULATOR).txsubchans", data
->txsubchans
);
9585 PRE_FIELD_READ("ioctl(VKI_V4L2_S_MODULATOR).reserved", data
->reserved
);
9588 case VKI_V4L2_G_FREQUENCY
: {
9589 struct vki_v4l2_frequency
*data
= (struct vki_v4l2_frequency
*)(Addr
)ARG3
;
9590 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FREQUENCY).tuner", data
->tuner
);
9591 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FREQUENCY).reserved", data
->reserved
);
9592 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FREQUENCY).type", data
->type
);
9593 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FREQUENCY).frequency", data
->frequency
);
9596 case VKI_V4L2_S_FREQUENCY
: {
9597 struct vki_v4l2_frequency
*data
= (struct vki_v4l2_frequency
*)(Addr
)ARG3
;
9598 PRE_MEM_READ("ioctl(VKI_V4L2_S_FREQUENCY)", (Addr
)data
, sizeof(*data
));
9601 case VKI_V4L2_CROPCAP
: {
9602 struct vki_v4l2_cropcap
*data
= (struct vki_v4l2_cropcap
*)(Addr
)ARG3
;
9603 PRE_FIELD_READ("ioctl(VKI_V4L2_CROPCAP)", data
->type
);
9604 PRE_MEM_WRITE("ioctl(VKI_V4L2_CROPCAP)", (Addr
)&data
->bounds
, sizeof(*data
) - sizeof(data
->type
));
9607 case VKI_V4L2_G_CROP
: {
9608 struct vki_v4l2_crop
*data
= (struct vki_v4l2_crop
*)(Addr
)ARG3
;
9609 PRE_FIELD_READ("ioctl(VKI_V4L2_G_CROP).type", data
->type
);
9610 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_CROP).c", data
->c
);
9613 case VKI_V4L2_S_CROP
: {
9614 struct vki_v4l2_crop
*data
= (struct vki_v4l2_crop
*)(Addr
)ARG3
;
9615 PRE_MEM_READ("ioctl(VKI_V4L2_S_CROP)", (Addr
)data
, sizeof(*data
));
9618 case VKI_V4L2_G_JPEGCOMP
: {
9619 struct vki_v4l2_jpegcompression
*data
=
9620 (struct vki_v4l2_jpegcompression
*)(Addr
)ARG3
;
9621 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_JPEGCOMP)", (Addr
)data
, sizeof(*data
));
9624 case VKI_V4L2_S_JPEGCOMP
: {
9625 struct vki_v4l2_jpegcompression
*data
=
9626 (struct vki_v4l2_jpegcompression
*)(Addr
)ARG3
;
9627 PRE_MEM_READ("ioctl(VKI_V4L2_S_JPEGCOMP)", (Addr
)data
, sizeof(*data
));
9630 case VKI_V4L2_QUERYSTD
: {
9631 vki_v4l2_std_id
*data
= (vki_v4l2_std_id
*)(Addr
)ARG3
;
9632 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYSTD)", (Addr
)data
, sizeof(*data
));
9635 case VKI_V4L2_ENUMAUDIO
: {
9636 struct vki_v4l2_audio
*data
= (struct vki_v4l2_audio
*)(Addr
)ARG3
;
9637 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDIO).index", data
->index
);
9638 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDIO).reserved", data
->reserved
);
9639 PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMAUDIO)", (Addr
)data
->name
,
9640 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
9643 case VKI_V4L2_ENUMAUDOUT
: {
9644 struct vki_v4l2_audioout
*data
= (struct vki_v4l2_audioout
*)(Addr
)ARG3
;
9645 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDOUT).index", data
->index
);
9646 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDOUT).reserved", data
->reserved
);
9647 PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMAUDOUT)", (Addr
)data
->name
,
9648 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
9651 case VKI_V4L2_G_PRIORITY
: {
9652 __vki_u32
*data
= (__vki_u32
*)(Addr
)ARG3
;
9653 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_PRIORITY)", (Addr
)data
, sizeof(*data
));
9656 case VKI_V4L2_S_PRIORITY
: {
9657 __vki_u32
*data
= (__vki_u32
*)(Addr
)ARG3
;
9658 PRE_MEM_READ("ioctl(VKI_V4L2_S_PRIORITY)", (Addr
)data
, sizeof(*data
));
9661 case VKI_V4L2_G_SLICED_VBI_CAP
: {
9662 struct vki_v4l2_sliced_vbi_cap
*data
=
9663 (struct vki_v4l2_sliced_vbi_cap
*)(Addr
)ARG3
;
9664 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SLICED_VBI_CAP).type", data
->type
);
9665 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SLICED_VBI_CAP).reserved", data
->reserved
);
9666 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_SLICED_VBI_CAP)", (Addr
)data
,
9667 sizeof(*data
) - sizeof(data
->type
) - sizeof(data
->reserved
));
9670 case VKI_V4L2_G_EXT_CTRLS
: {
9671 struct vki_v4l2_ext_controls
*data
=
9672 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
9673 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).ctrl_class", data
->ctrl_class
);
9674 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).count", data
->count
);
9678 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls", data
->controls
);
9679 for (i
= 0; i
< data
->count
; i
++) {
9680 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].id", data
->controls
[i
].id
);
9681 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].size", data
->controls
[i
].size
);
9682 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].reserved2", data
->controls
[i
].reserved2
);
9683 if (data
->controls
[i
].size
) {
9684 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].ptr", data
->controls
[i
].ptr
);
9685 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].ptr[]",
9686 (Addr
)data
->controls
[i
].ptr
, data
->controls
[i
].size
);
9688 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].value64",
9689 data
->controls
[i
].value64
);
9693 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_EXT_CTRLS).error_idx", data
->error_idx
);
9694 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).reserved", data
->reserved
);
9697 case VKI_V4L2_S_EXT_CTRLS
: {
9698 struct vki_v4l2_ext_controls
*data
=
9699 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
9700 PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).ctrl_class", data
->ctrl_class
);
9701 PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).count", data
->count
);
9705 PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).controls", data
->controls
);
9706 PRE_MEM_READ("ioctl(VKI_V4L2_S_EXT_CTRLS)", (Addr
)data
->controls
,
9707 data
->count
* sizeof(data
->controls
[0]));
9708 for (i
= 0; i
< data
->count
; i
++) {
9709 if (data
->controls
[i
].size
) {
9710 PRE_MEM_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).controls[].ptr[]",
9711 (Addr
)data
->controls
[i
].ptr
, data
->controls
[i
].size
);
9715 PRE_FIELD_WRITE("ioctl(VKI_V4L2_S_EXT_CTRLS).error_idx", data
->error_idx
);
9716 PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).reserved", data
->reserved
);
9719 case VKI_V4L2_TRY_EXT_CTRLS
: {
9720 struct vki_v4l2_ext_controls
*data
=
9721 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
9722 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).ctrl_class", data
->ctrl_class
);
9723 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).count", data
->count
);
9727 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).controls", data
->controls
);
9728 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS)", (Addr
)data
->controls
,
9729 data
->count
* sizeof(data
->controls
[0]));
9730 for (i
= 0; i
< data
->count
; i
++) {
9731 if (data
->controls
[i
].size
) {
9732 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).controls[].ptr[]",
9733 (Addr
)data
->controls
[i
].ptr
, data
->controls
[i
].size
);
9737 PRE_FIELD_WRITE("ioctl(VKI_V4L2_TRY_EXT_CTRLS).error_idx", data
->error_idx
);
9738 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).reserved", data
->reserved
);
9741 case VKI_V4L2_ENUM_FRAMESIZES
: {
9742 struct vki_v4l2_frmsizeenum
*data
=
9743 (struct vki_v4l2_frmsizeenum
*)(Addr
)ARG3
;
9744 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMESIZES).index", data
->index
);
9745 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMESIZES).pixel_format", data
->pixel_format
);
9746 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMESIZES).reserved", data
->reserved
);
9747 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMESIZES).type", data
->type
);
9748 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMESIZES).stepwise", data
->stepwise
);
9751 case VKI_V4L2_ENUM_FRAMEINTERVALS
: {
9752 struct vki_v4l2_frmivalenum
*data
=
9753 (struct vki_v4l2_frmivalenum
*)(Addr
)ARG3
;
9754 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).index", data
->index
);
9755 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).pixel_format", data
->pixel_format
);
9756 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).width", data
->width
);
9757 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).height", data
->height
);
9758 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).reserved", data
->reserved
);
9759 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).type", data
->type
);
9760 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).stepwise", data
->stepwise
);
9763 case VKI_V4L2_G_ENC_INDEX
: {
9764 struct vki_v4l2_enc_idx
*data
= (struct vki_v4l2_enc_idx
*)(Addr
)ARG3
;
9765 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_ENC_INDEX)", (Addr
)data
, sizeof(*data
));
9768 case VKI_V4L2_ENCODER_CMD
: {
9769 struct vki_v4l2_encoder_cmd
*data
=
9770 (struct vki_v4l2_encoder_cmd
*)(Addr
)ARG3
;
9771 PRE_MEM_READ("ioctl(VKI_V4L2_ENCODER_CMD)", (Addr
)data
, sizeof(*data
));
9774 case VKI_V4L2_TRY_ENCODER_CMD
: {
9775 struct vki_v4l2_encoder_cmd
*data
=
9776 (struct vki_v4l2_encoder_cmd
*)(Addr
)ARG3
;
9777 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_ENCODER_CMD)", (Addr
)data
, sizeof(*data
));
9780 case VKI_V4L2_DBG_S_REGISTER
: {
9781 struct vki_v4l2_dbg_register
*data
=
9782 (struct vki_v4l2_dbg_register
*)(Addr
)ARG3
;
9783 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).match.type", data
->match
.type
);
9784 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).match.addr", data
->match
.addr
);
9785 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).reg", data
->reg
);
9786 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).val", data
->val
);
9787 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_S_REGISTER).size", data
->size
);
9790 case VKI_V4L2_DBG_G_REGISTER
: {
9791 struct vki_v4l2_dbg_register
*data
=
9792 (struct vki_v4l2_dbg_register
*)(Addr
)ARG3
;
9793 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_REGISTER).match.type", data
->match
.type
);
9794 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_REGISTER).match.addr", data
->match
.addr
);
9795 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_REGISTER).reg", data
->reg
);
9796 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_REGISTER).val", data
->val
);
9797 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_REGISTER).size", data
->size
);
9800 case VKI_V4L2_S_HW_FREQ_SEEK
: {
9801 struct vki_v4l2_hw_freq_seek
*data
=
9802 (struct vki_v4l2_hw_freq_seek
*)(Addr
)ARG3
;
9803 PRE_MEM_READ("ioctl(VKI_V4L2_S_HW_FREQ_SEEK)", (Addr
)data
, sizeof(*data
));
9806 case VKI_V4L2_S_DV_TIMINGS
: {
9807 struct vki_v4l2_dv_timings
*data
=
9808 (struct vki_v4l2_dv_timings
*)(Addr
)ARG3
;
9809 PRE_FIELD_READ("ioctl(VKI_V4L2_S_DV_TIMINGS).type", data
->type
);
9810 PRE_FIELD_READ("ioctl(VKI_V4L2_S_DV_TIMINGS).bt", data
->bt
);
9813 case VKI_V4L2_G_DV_TIMINGS
: {
9814 struct vki_v4l2_dv_timings
*data
=
9815 (struct vki_v4l2_dv_timings
*)(Addr
)ARG3
;
9816 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_DV_TIMINGS)", (Addr
)data
, sizeof(*data
));
9819 case VKI_V4L2_DQEVENT
: {
9820 struct vki_v4l2_event
*data
= (struct vki_v4l2_event
*)(Addr
)ARG3
;
9821 PRE_MEM_WRITE("ioctl(VKI_V4L2_DQEVENT)", (Addr
)data
, sizeof(*data
));
9824 case VKI_V4L2_SUBSCRIBE_EVENT
: {
9825 struct vki_v4l2_event_subscription
*data
=
9826 (struct vki_v4l2_event_subscription
*)(Addr
)ARG3
;
9827 PRE_MEM_READ("ioctl(VKI_V4L2_SUBSCRIBE_EVENT)", (Addr
)data
, sizeof(*data
));
9830 case VKI_V4L2_UNSUBSCRIBE_EVENT
: {
9831 struct vki_v4l2_event_subscription
*data
=
9832 (struct vki_v4l2_event_subscription
*)(Addr
)ARG3
;
9833 PRE_MEM_READ("ioctl(VKI_V4L2_UNSUBSCRIBE_EVENT)", (Addr
)data
, sizeof(*data
));
9836 case VKI_V4L2_CREATE_BUFS
: {
9837 struct vki_v4l2_create_buffers
*data
=
9838 (struct vki_v4l2_create_buffers
*)(Addr
)ARG3
;
9839 struct vki_v4l2_format
*fmt
= &data
->format
;
9840 PRE_FIELD_WRITE("ioctl(VKI_V4L2_CREATE_BUFS).index", data
->index
);
9841 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).count", data
->count
);
9842 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).memory", data
->memory
);
9843 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).reserved", data
->reserved
);
9844 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.type", fmt
->type
);
9845 switch (fmt
->type
) {
9846 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE
:
9847 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
:
9848 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.pix", fmt
->fmt
.raw_data
);
9850 case VKI_V4L2_BUF_TYPE_VBI_CAPTURE
:
9851 case VKI_V4L2_BUF_TYPE_VBI_OUTPUT
:
9852 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.vbi", fmt
->fmt
.vbi
);
9854 case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
9855 case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
9856 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.sliced", fmt
->fmt
.sliced
);
9858 case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY
:
9859 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
9860 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.win", fmt
->fmt
.win
);
9862 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
9863 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
9864 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.pix_mp", fmt
->fmt
.pix_mp
);
9866 case VKI_V4L2_BUF_TYPE_SDR_CAPTURE
:
9867 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.sdr", fmt
->fmt
.sdr
);
9872 case VKI_V4L2_PREPARE_BUF
: {
9873 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
9874 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).index", data
->index
);
9875 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).type", data
->type
);
9876 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).memory", data
->memory
);
9877 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).reserved", data
->reserved
);
9878 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).reserved2", data
->reserved2
);
9879 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
9880 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
9883 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).length", data
->length
);
9884 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).m.planes", data
->m
.planes
);
9885 for (i
= 0; i
< data
->length
; i
++) {
9886 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).m.planes[].reserved", data
->m
.planes
[i
].reserved
);
9891 case VKI_V4L2_G_SELECTION
: {
9892 struct vki_v4l2_selection
*data
= (struct vki_v4l2_selection
*)(Addr
)ARG3
;
9893 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).type", data
->type
);
9894 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).target", data
->target
);
9895 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).flags", data
->flags
);
9896 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).reserved", data
->reserved
);
9897 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_SELECTION).r", data
->r
);
9900 case VKI_V4L2_S_SELECTION
: {
9901 struct vki_v4l2_selection
*data
= (struct vki_v4l2_selection
*)(Addr
)ARG3
;
9902 PRE_MEM_READ("ioctl(VKI_V4L2_S_SELECTION)", (Addr
)data
, sizeof(*data
));
9905 case VKI_V4L2_DECODER_CMD
: {
9906 struct vki_v4l2_decoder_cmd
*data
=
9907 (struct vki_v4l2_decoder_cmd
*)(Addr
)ARG3
;
9908 PRE_MEM_READ("ioctl(VKI_V4L2_DECODER_CMD)", (Addr
)data
, sizeof(*data
));
9911 case VKI_V4L2_TRY_DECODER_CMD
: {
9912 struct vki_v4l2_decoder_cmd
*data
=
9913 (struct vki_v4l2_decoder_cmd
*)(Addr
)ARG3
;
9914 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_DECODER_CMD)", (Addr
)data
, sizeof(*data
));
9917 case VKI_V4L2_ENUM_DV_TIMINGS
: {
9918 struct vki_v4l2_enum_dv_timings
*data
=
9919 (struct vki_v4l2_enum_dv_timings
*)(Addr
)ARG3
;
9920 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).index", data
->index
);
9921 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).pad", data
->pad
);
9922 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).reserved", data
->reserved
);
9923 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).timings", data
->timings
);
9926 case VKI_V4L2_QUERY_DV_TIMINGS
: {
9927 struct vki_v4l2_dv_timings
*data
=
9928 (struct vki_v4l2_dv_timings
*)(Addr
)ARG3
;
9929 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERY_DV_TIMINGS)", (Addr
)data
, sizeof(*data
));
9932 case VKI_V4L2_DV_TIMINGS_CAP
: {
9933 struct vki_v4l2_dv_timings_cap
*data
=
9934 (struct vki_v4l2_dv_timings_cap
*)(Addr
)ARG3
;
9935 PRE_MEM_WRITE("ioctl(VKI_V4L2_DV_TIMINGS_CAP)", (Addr
)data
, sizeof(*data
));
9938 case VKI_V4L2_ENUM_FREQ_BANDS
: {
9939 struct vki_v4l2_frequency_band
*data
=
9940 (struct vki_v4l2_frequency_band
*)(Addr
)ARG3
;
9941 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).tuner", data
->tuner
);
9942 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).type", data
->type
);
9943 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).index", data
->index
);
9944 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).reserved", data
->reserved
);
9945 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).capability", data
->capability
);
9946 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).rangelow", data
->rangelow
);
9947 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).rangehigh", data
->rangehigh
);
9948 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).modulation", data
->modulation
);
9951 case VKI_V4L2_DBG_G_CHIP_INFO
: {
9952 struct vki_v4l2_dbg_chip_info
*data
=
9953 (struct vki_v4l2_dbg_chip_info
*)(Addr
)ARG3
;
9954 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).match.type", data
->match
.type
);
9955 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).match.addr", data
->match
.addr
);
9956 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).name", data
->name
);
9957 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).flags", data
->flags
);
9958 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).reserved", data
->reserved
);
9961 case VKI_V4L2_QUERY_EXT_CTRL
: {
9962 struct vki_v4l2_query_ext_ctrl
*data
=
9963 (struct vki_v4l2_query_ext_ctrl
*)(Addr
)ARG3
;
9964 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERY_EXT_CTRL).id", data
->id
);
9965 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERY_EXT_CTRL).reserved", data
->reserved
);
9966 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERY_EXT_CTRL)", (Addr
)&data
->type
,
9967 sizeof(*data
) - sizeof(data
->id
) - sizeof(data
->reserved
));
9970 case VKI_V4L2_SUBDEV_G_FMT
: {
9971 struct vki_v4l2_subdev_format
*data
=
9972 (struct vki_v4l2_subdev_format
*)(Addr
)ARG3
;
9973 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FMT).pad", data
->pad
);
9974 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FMT).which", data
->which
);
9975 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FMT).reserved", data
->reserved
);
9976 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_FMT).format", data
->format
);
9979 case VKI_V4L2_SUBDEV_S_FMT
: {
9980 struct vki_v4l2_subdev_format
*data
=
9981 (struct vki_v4l2_subdev_format
*)(Addr
)ARG3
;
9982 PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_FMT)", (Addr
)data
, sizeof(*data
));
9985 case VKI_V4L2_SUBDEV_G_FRAME_INTERVAL
: {
9986 struct vki_v4l2_subdev_frame_interval
*data
=
9987 (struct vki_v4l2_subdev_frame_interval
*)(Addr
)ARG3
;
9988 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FRAME_SIZE).pad", data
->pad
);
9989 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FRAME_SIZE).reserved", data
->reserved
);
9990 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_FRAME_SIZE).interval", data
->interval
);
9993 case VKI_V4L2_SUBDEV_S_FRAME_INTERVAL
: {
9994 struct vki_v4l2_subdev_frame_interval
*data
=
9995 (struct vki_v4l2_subdev_frame_interval
*)(Addr
)ARG3
;
9996 PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_FRAME_INTERVAL)", (Addr
)data
, sizeof(*data
));
9999 case VKI_V4L2_SUBDEV_ENUM_MBUS_CODE
: {
10000 struct vki_v4l2_subdev_mbus_code_enum
*data
=
10001 (struct vki_v4l2_subdev_mbus_code_enum
*)(Addr
)ARG3
;
10002 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).index", data
->index
);
10003 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).pad", data
->pad
);
10004 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).code", data
->code
);
10005 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).which", data
->which
);
10006 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).reserved", data
->reserved
);
10009 case VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE
: {
10010 struct vki_v4l2_subdev_frame_size_enum
*data
=
10011 (struct vki_v4l2_subdev_frame_size_enum
*)(Addr
)ARG3
;
10012 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).index", data
->index
);
10013 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).pad", data
->pad
);
10014 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).code", data
->code
);
10015 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).which", data
->which
);
10016 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).reserved", data
->reserved
);
10017 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).min_width", data
->min_width
);
10018 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).min_height", data
->min_height
);
10019 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).max_width", data
->max_width
);
10020 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).max_height", data
->max_height
);
10023 case VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL
: {
10024 struct vki_v4l2_subdev_frame_interval_enum
*data
=
10025 (struct vki_v4l2_subdev_frame_interval_enum
*)(Addr
)ARG3
;
10026 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).index", data
->index
);
10027 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).pad", data
->pad
);
10028 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).code", data
->code
);
10029 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).width", data
->width
);
10030 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).height", data
->height
);
10031 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).which", data
->which
);
10032 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).reserved", data
->reserved
);
10033 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).interval", data
->interval
);
10036 case VKI_V4L2_SUBDEV_G_CROP
: {
10037 struct vki_v4l2_subdev_crop
*data
=
10038 (struct vki_v4l2_subdev_crop
*)(Addr
)ARG3
;
10039 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_CROP).pad", data
->pad
);
10040 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_CROP).which", data
->which
);
10041 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_CROP).reserved", data
->reserved
);
10042 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_CROP).rect", data
->rect
);
10045 case VKI_V4L2_SUBDEV_S_CROP
: {
10046 struct vki_v4l2_subdev_crop
*data
=
10047 (struct vki_v4l2_subdev_crop
*)(Addr
)ARG3
;
10048 PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_CROP)", (Addr
)data
, sizeof(*data
));
10051 case VKI_V4L2_SUBDEV_G_SELECTION
: {
10052 struct vki_v4l2_subdev_selection
*data
=
10053 (struct vki_v4l2_subdev_selection
*)(Addr
)ARG3
;
10054 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).pad", data
->pad
);
10055 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).which", data
->which
);
10056 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).target", data
->target
);
10057 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).flags", data
->flags
);
10058 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).reserved", data
->reserved
);
10059 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).r", data
->r
);
10062 case VKI_V4L2_SUBDEV_S_SELECTION
: {
10063 struct vki_v4l2_subdev_selection
*data
=
10064 (struct vki_v4l2_subdev_selection
*)(Addr
)ARG3
;
10065 PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_SELECTION)", (Addr
)data
, sizeof(*data
));
10068 case VKI_MEDIA_IOC_DEVICE_INFO
: {
10069 struct vki_media_device_info
*data
=
10070 (struct vki_media_device_info
*)(Addr
)ARG3
;
10071 PRE_FIELD_READ("ioctl(VKI_MEDIA_IOC_DEVICE_INFO).reserved", data
->reserved
);
10072 PRE_MEM_WRITE("ioctl(VKI_MEDIA_IOC_DEVICE_INFO)",
10073 (Addr
)data
, sizeof(*data
) - sizeof(data
->reserved
));
10076 case VKI_MEDIA_IOC_ENUM_ENTITIES
: {
10077 struct vki_media_entity_desc
*data
=
10078 (struct vki_media_entity_desc
*)(Addr
)ARG3
;
10079 PRE_FIELD_READ("ioctl(VKI_MEDIA_IOC_ENUM_ENTITIES).id", data
->id
);
10080 PRE_MEM_WRITE("ioctl(VKI_MEDIA_IOC_ENUM_ENTITIES)",
10081 (Addr
)data
->name
, sizeof(*data
) - sizeof(data
->id
));
10084 case VKI_MEDIA_IOC_ENUM_LINKS
: {
10085 struct vki_media_links_enum
*data
=
10086 (struct vki_media_links_enum
*)(Addr
)ARG3
;
10087 PRE_MEM_READ("ioctl(VKI_MEDIA_IOC_ENUM_LINKS)", (Addr
)data
, sizeof(*data
));
10090 case VKI_MEDIA_IOC_SETUP_LINK
: {
10091 struct vki_media_link_desc
*data
=
10092 (struct vki_media_link_desc
*)(Addr
)ARG3
;
10093 PRE_MEM_READ("ioctl(VKI_MEDIA_IOC_SETUP_LINK)", (Addr
)data
, sizeof(*data
));
10098 case VKI_TIOCGSERIAL
: {
10099 struct vki_serial_struct
*data
= (struct vki_serial_struct
*)(Addr
)ARG3
;
10100 PRE_MEM_WRITE("ioctl(VKI_TIOCGSERIAL)", (Addr
)data
, sizeof(*data
));
10103 case VKI_TIOCSSERIAL
: {
10104 struct vki_serial_struct
*data
= (struct vki_serial_struct
*)(Addr
)ARG3
;
10105 PRE_MEM_READ("ioctl(VKI_TIOCSSERIAL)", (Addr
)data
, sizeof(*data
));
10109 case VKI_PERF_EVENT_IOC_RESET
:
10110 case VKI_PERF_EVENT_IOC_REFRESH
:
10111 case VKI_PERF_EVENT_IOC_SET_OUTPUT
:
10112 case VKI_PERF_EVENT_IOC_SET_BPF
:
10113 /* These take scalar arguments, so already handled above */
10116 case VKI_PERF_EVENT_IOC_PERIOD
:
10117 PRE_MEM_READ("ioctl(VKI_PERF_EVENT_IOC_PERIOD)", (Addr
)ARG3
, sizeof(__vki_u64
));
10120 case VKI_PERF_EVENT_IOC_SET_FILTER
:
10121 PRE_MEM_RASCIIZ("ioctl(VKI_PERF_EVENT_IOC_SET_FILTER).filter", ARG3
);
10124 case VKI_PERF_EVENT_IOC_ID
:
10125 PRE_MEM_WRITE("ioctl(VKI_PERF_EVENT_IOC_ID)", (Addr
)ARG3
, sizeof(__vki_u64
));
10128 /* Pulse Per Second (PPS) */
10129 case VKI_PPS_GETPARAMS
: {
10130 struct vki_pps_kparams
*data
= (struct vki_pps_kparams
*)(Addr
)ARG3
;
10131 PRE_MEM_WRITE("ioctl(PPS_GETPARAMS)", (Addr
)data
, sizeof(*data
));
10134 case VKI_PPS_SETPARAMS
: {
10135 struct vki_pps_kparams
*data
= (struct vki_pps_kparams
*)(Addr
)ARG3
;
10136 PRE_FIELD_READ("ioctl(PPS_SETPARAMS).mode", data
->mode
);
10137 PRE_FIELD_READ("ioctl(PPS_SETPARAMS).assert_off_tu.sec",
10138 data
->assert_off_tu
.sec
);
10139 PRE_FIELD_READ("ioctl(PPS_SETPARAMS).assert_off_tu.nsec",
10140 data
->assert_off_tu
.nsec
);
10141 PRE_FIELD_READ("ioctl(PPS_SETPARAMS).clear_off_tu.sec",
10142 data
->clear_off_tu
.sec
);
10143 PRE_FIELD_READ("ioctl(PPS_SETPARAMS).clear_off_tu.nsec",
10144 data
->clear_off_tu
.nsec
);
10147 case VKI_PPS_GETCAP
:
10148 PRE_MEM_WRITE("ioctl(PPS_GETCAP)", (Addr
)ARG3
, sizeof(int));
10150 case VKI_PPS_FETCH
: {
10151 struct vki_pps_fdata
*data
= (struct vki_pps_fdata
*)(Addr
)ARG3
;
10152 PRE_FIELD_READ("ioctl(PPS_FETCH).timeout", data
->timeout
);
10153 PRE_FIELD_WRITE("ioctl(PPS_FETCH).info", data
->info
);
10156 case VKI_PPS_KC_BIND
: {
10157 struct vki_pps_bind_args
*data
= (struct vki_pps_bind_args
*)(Addr
)ARG3
;
10158 PRE_MEM_READ("ioctl(PPS_KC_BIND)", (Addr
)data
, sizeof(*data
));
10162 /* PTP Hardware Clock */
10163 case VKI_PTP_CLOCK_GETCAPS
: {
10164 struct vki_ptp_clock_caps
*data
=
10165 (struct vki_ptp_clock_caps
*)(Addr
)ARG3
;
10166 PRE_MEM_WRITE("ioctl(PTP_CLOCK_GETCAPS)", (Addr
)data
, sizeof(*data
));
10169 case VKI_PTP_EXTTS_REQUEST
: {
10170 struct vki_ptp_extts_request
*data
=
10171 (struct vki_ptp_extts_request
*)(Addr
)ARG3
;
10172 PRE_MEM_READ("ioctl(PTP_EXTTS_REQUEST)", (Addr
)data
, sizeof(*data
));
10175 case VKI_PTP_PEROUT_REQUEST
: {
10176 struct vki_ptp_perout_request
*data
=
10177 (struct vki_ptp_perout_request
*)(Addr
)ARG3
;
10178 PRE_MEM_READ("ioctl(PTP_PEROUT_REQUEST)", (Addr
)data
, sizeof(*data
));
10181 case VKI_PTP_ENABLE_PPS
:
10183 case VKI_PTP_SYS_OFFSET
: {
10184 struct vki_ptp_sys_offset
*data
=
10185 (struct vki_ptp_sys_offset
*)(Addr
)ARG3
;
10186 PRE_FIELD_READ("ioctl(PTP_SYS_OFFSET).n_samples", data
->n_samples
);
10187 if (data
->n_samples
<= VKI_PTP_MAX_SAMPLES
)
10188 PRE_MEM_WRITE("ioctl(PTP_SYS_OFFSET).ts", (Addr
)data
->ts
,
10189 (2 * data
->n_samples
+ 1) * sizeof(data
->ts
[0]));
10192 case VKI_PTP_PIN_GETFUNC
: {
10193 struct vki_ptp_pin_desc
*data
= (struct vki_ptp_pin_desc
*)(Addr
)ARG3
;
10194 PRE_FIELD_READ("ioctl(PTP_PIN_GETFUNC).index", data
->index
);
10195 PRE_MEM_WRITE("ioctl(PTP_PIN_GETFUNC)", (Addr
)data
, sizeof(*data
));
10198 case VKI_PTP_PIN_SETFUNC
: {
10199 struct vki_ptp_pin_desc
*data
= (struct vki_ptp_pin_desc
*)(Addr
)ARG3
;
10200 PRE_FIELD_READ("ioctl(PTP_PIN_SETFUNC).index", data
->index
);
10201 PRE_FIELD_READ("ioctl(PTP_PIN_SETFUNC).func", data
->func
);
10202 PRE_FIELD_READ("ioctl(PTP_PIN_SETFUNC).chan", data
->chan
);
10205 case VKI_PTP_SYS_OFFSET_PRECISE
: {
10206 struct vki_ptp_sys_offset_precise
*data
=
10207 (struct vki_ptp_sys_offset_precise
*)(Addr
)ARG3
;
10208 PRE_MEM_WRITE("ioctl(PTP_SYS_OFFSET_PRECISE)", (Addr
)data
, sizeof(*data
));
10211 case VKI_PTP_SYS_OFFSET_EXTENDED
: {
10212 struct vki_ptp_sys_offset_extended
*data
=
10213 (struct vki_ptp_sys_offset_extended
*)(Addr
)ARG3
;
10214 PRE_FIELD_READ("ioctl(PTP_SYS_OFFSET_EXTENDED).n_samples", data
->n_samples
);
10215 PRE_FIELD_READ("ioctl(PTP_SYS_OFFSET_EXTENDED).rsv", data
->rsv
);
10216 if (data
->n_samples
<= VKI_PTP_MAX_SAMPLES
)
10217 PRE_MEM_WRITE("ioctl(PTP_SYS_OFFSET_EXTENDED).ts", (Addr
)data
->ts
,
10218 3 * data
->n_samples
* sizeof(data
->ts
[0][0]));
10223 /* EVIOC* are variable length and return size written on success */
10224 switch (ARG2
& ~(_VKI_IOC_SIZEMASK
<< _VKI_IOC_SIZESHIFT
)) {
10225 case VKI_EVIOCGNAME(0):
10226 case VKI_EVIOCGPHYS(0):
10227 case VKI_EVIOCGUNIQ(0):
10228 case VKI_EVIOCGKEY(0):
10229 case VKI_EVIOCGLED(0):
10230 case VKI_EVIOCGSND(0):
10231 case VKI_EVIOCGSW(0):
10232 case VKI_EVIOCGBIT(VKI_EV_SYN
,0):
10233 case VKI_EVIOCGBIT(VKI_EV_KEY
,0):
10234 case VKI_EVIOCGBIT(VKI_EV_REL
,0):
10235 case VKI_EVIOCGBIT(VKI_EV_ABS
,0):
10236 case VKI_EVIOCGBIT(VKI_EV_MSC
,0):
10237 case VKI_EVIOCGBIT(VKI_EV_SW
,0):
10238 case VKI_EVIOCGBIT(VKI_EV_LED
,0):
10239 case VKI_EVIOCGBIT(VKI_EV_SND
,0):
10240 case VKI_EVIOCGBIT(VKI_EV_REP
,0):
10241 case VKI_EVIOCGBIT(VKI_EV_FF
,0):
10242 case VKI_EVIOCGBIT(VKI_EV_PWR
,0):
10243 case VKI_EVIOCGBIT(VKI_EV_FF_STATUS
,0):
10244 PRE_MEM_WRITE("ioctl(EVIO*)", ARG3
, _VKI_IOC_SIZE(ARG2
));
10247 ML_(PRE_unknown_ioctl
)(tid
, ARG2
, ARG3
);
10258 vg_assert(SUCCESS
|| (FAILURE
&& VKI_DRM_IOCTL_VERSION
== ARG2
));
10260 /* --- BEGIN special IOCTL handlers for specific Android hardware --- */
10262 /* BEGIN undocumented ioctls for PowerVR SGX 540 (the GPU on Nexus S) */
10263 if (KernelVariantiS(KernelVariant_android_gpu_sgx5xx
,
10264 VG_(clo_kernel_variant
))) {
10266 if (ARG2
>= 0xC01C6700 && ARG2
<= 0xC01C67FF && ARG3
>= 0x1000) {
10267 /* What's going on here: there appear to be a bunch of ioctls
10268 of the form 0xC01C67xx which are undocumented, and if
10269 unhandled give rise to a vast number of false positives in
10272 The "normal" interpretation of an ioctl of this form would
10273 be that the 3rd arg is a pointer to an area of size 0x1C
10274 (28 bytes) which is filled in by the kernel. Hence you
10275 might think that "POST_MEM_WRITE(ARG3, 28)" would fix it.
10278 It requires POST_MEM_WRITE(ARG3, 256) to silence them.
10279 One interpretation of this is that ARG3 really does point
10280 to a 28 byte struct, but inside that are pointers to other
10281 areas also filled in by the kernel. If these happen to be
10282 allocated just back up the stack then the 256 byte paint
10283 might cover them too, somewhat indiscriminately.
10285 By printing out ARG3 and also the 28 bytes that it points
10286 at, it's possible to guess that the 7 word structure has
10290 ioctl-number 0x1C ptr1 ptr1size ptr2 ptr2size aBitMask
10292 Unfortunately that doesn't seem to work for some reason,
10293 so stay with the blunt-instrument approach for the time
10297 /* blunt-instrument approach */
10298 POST_MEM_WRITE(ARG3
, 256);
10300 /* be a bit more sophisticated */
10301 POST_MEM_WRITE(ARG3
, 28);
10302 UInt
* word
= (UInt
*)(Addr
)ARG3
;
10303 if (word
&& word
[2] && word
[3] < 0x200/*stay sane*/)
10304 POST_MEM_WRITE(word
[2], word
[3]); // "ptr1"
10305 if (word
&& word
[4] && word
[5] < 0x200/*stay sane*/)
10306 POST_MEM_WRITE(word
[4], word
[5]); // "ptr2"
10308 goto post_sys_ioctl__out
;
10311 /* END undocumented ioctls for PowerVR SGX 540 (the GPU on Nexus S) */
10313 /* BEGIN undocumented ioctls for Qualcomm Adreno 3xx */
10314 if (KernelVariantiS(KernelVariant_android_gpu_adreno3xx
,
10315 VG_(clo_kernel_variant
))) {
10316 if (ARG2
== 0xC00C0902) {
10317 POST_MEM_WRITE(ARG3
, 24); // 16 is not enough
10318 goto post_sys_ioctl__out
;
10321 /* END undocumented ioctls for Qualcomm Adreno 3xx */
10323 /* --- END special IOCTL handlers for specific Android hardware --- */
10325 /* --- normal handling --- */
10326 switch (ARG2
/* request */) {
10328 /* The Linux kernel "ion" memory allocator, used on Android. Note:
10329 this is pretty poor given that there's no pre-handling to check
10330 that writable areas are addressable. */
10331 case VKI_ION_IOC_ALLOC
: {
10332 struct vki_ion_allocation_data
* data
10333 = (struct vki_ion_allocation_data
*)(Addr
)ARG3
;
10334 POST_FIELD_WRITE(data
->handle
);
10337 case VKI_ION_IOC_MAP
: {
10338 struct vki_ion_fd_data
* data
= (struct vki_ion_fd_data
*)(Addr
)ARG3
;
10339 POST_FIELD_WRITE(data
->fd
);
10342 case VKI_ION_IOC_FREE
: // is this necessary?
10343 POST_MEM_WRITE(ARG3
, sizeof(struct vki_ion_handle_data
));
10345 case VKI_ION_IOC_SHARE
:
10347 case VKI_ION_IOC_IMPORT
: {
10348 struct vki_ion_fd_data
* data
= (struct vki_ion_fd_data
*)(Addr
)ARG3
;
10349 POST_FIELD_WRITE(data
->handle
);
10352 case VKI_ION_IOC_SYNC
:
10354 case VKI_ION_IOC_CUSTOM
: // is this necessary?
10355 POST_MEM_WRITE(ARG3
, sizeof(struct vki_ion_custom_data
));
10358 case VKI_SYNC_IOC_MERGE
: {
10359 struct vki_sync_merge_data
* data
=
10360 (struct vki_sync_merge_data
*)(Addr
)ARG3
;
10361 POST_FIELD_WRITE(data
->fence
);
10368 case VKI_IB_USER_MAD_ENABLE_PKEY
:
10371 POST_MEM_WRITE( ARG3
, sizeof(struct vki_termios
) );
10378 POST_MEM_WRITE( ARG3
, sizeof(struct vki_termio
) );
10386 case VKI_TIOCGWINSZ
:
10387 POST_MEM_WRITE( ARG3
, sizeof(struct vki_winsize
) );
10389 case VKI_TIOCSWINSZ
:
10395 POST_MEM_WRITE( ARG3
, sizeof(unsigned int) );
10397 case VKI_TIOCLINUX
:
10398 POST_MEM_WRITE( ARG3
, sizeof(char *) );
10400 case VKI_TIOCGPGRP
:
10401 /* Get process group ID for foreground processing group. */
10402 POST_MEM_WRITE( ARG3
, sizeof(vki_pid_t
) );
10404 case VKI_TIOCSPGRP
:
10405 /* Set a process group ID? */
10406 POST_MEM_WRITE( ARG3
, sizeof(vki_pid_t
) );
10408 case VKI_TIOCGPTN
: /* Get Pty Number (of pty-mux device) */
10409 POST_MEM_WRITE( ARG3
, sizeof(int));
10411 case VKI_TIOCSCTTY
:
10413 case VKI_TIOCSPTLCK
: /* Lock/unlock Pty */
10421 case VKI_TIOCNOTTY
:
10425 case VKI_FIONREAD
: /* identical to SIOCINQ */
10426 POST_MEM_WRITE( ARG3
, sizeof(int) );
10429 POST_MEM_WRITE( ARG3
, sizeof(vki_loff_t
) );
10432 case VKI_TIOCSERGETLSR
:
10433 POST_MEM_WRITE( ARG3
, sizeof(int) );
10435 case VKI_TIOCGICOUNT
:
10436 POST_MEM_WRITE( ARG3
, sizeof(struct vki_serial_icounter_struct
) );
10439 case VKI_SG_SET_COMMAND_Q
:
10443 vki_sg_io_hdr_t
*sgio
= (vki_sg_io_hdr_t
*)(Addr
)ARG3
;
10445 POST_MEM_WRITE( (Addr
)sgio
->sbp
, sgio
->sb_len_wr
);
10447 if ( sgio
->dxfer_direction
== VKI_SG_DXFER_FROM_DEV
||
10448 sgio
->dxfer_direction
== VKI_SG_DXFER_TO_FROM_DEV
) {
10449 int transferred
= sgio
->dxfer_len
- sgio
->resid
;
10450 POST_MEM_WRITE( (Addr
)sgio
->dxferp
, transferred
);
10454 case VKI_SG_GET_SCSI_ID
:
10455 POST_MEM_WRITE(ARG3
, sizeof(vki_sg_scsi_id_t
));
10457 case VKI_SG_SET_RESERVED_SIZE
:
10459 case VKI_SG_SET_TIMEOUT
:
10461 case VKI_SG_GET_RESERVED_SIZE
:
10462 POST_MEM_WRITE(ARG3
, sizeof(int));
10464 case VKI_SG_GET_TIMEOUT
:
10466 case VKI_SG_GET_VERSION_NUM
:
10467 POST_MEM_WRITE(ARG3
, sizeof(int));
10469 case VKI_SG_EMULATED_HOST
:
10470 POST_MEM_WRITE(ARG3
, sizeof(int));
10472 case VKI_SG_GET_SG_TABLESIZE
:
10473 POST_MEM_WRITE(ARG3
, sizeof(int));
10476 case VKI_IIOCGETCPS
:
10477 POST_MEM_WRITE( ARG3
, VKI_ISDN_MAX_CHANNELS
* 2 * sizeof(unsigned long) );
10479 case VKI_IIOCNETGPN
:
10480 POST_MEM_WRITE( ARG3
, sizeof(vki_isdn_net_ioctl_phone
) );
10483 /* These all use struct ifreq AFAIK */
10484 case VKI_SIOCGIFINDEX
: /* get iface index */
10485 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_ifindex
,
10486 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_ifindex
));
10488 case VKI_SIOCGIFFLAGS
: /* get flags */
10489 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
,
10490 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
));
10492 case VKI_SIOCGIFHWADDR
: /* Get hardware address */
10493 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_hwaddr
,
10494 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_hwaddr
));
10496 case VKI_SIOCGIFMTU
: /* get MTU size */
10497 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_mtu
,
10498 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_mtu
) );
10500 case VKI_SIOCGIFADDR
: /* get PA address */
10501 case VKI_SIOCGIFDSTADDR
: /* get remote PA address */
10502 case VKI_SIOCGIFBRDADDR
: /* get broadcast PA address */
10503 case VKI_SIOCGIFNETMASK
: /* get network PA mask */
10505 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_addr
,
10506 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_addr
) );
10508 case VKI_SIOCGIFMETRIC
: /* get metric */
10510 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_metric
,
10511 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_metric
) );
10513 case VKI_SIOCGIFMAP
: /* Get device parameters */
10515 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_map
,
10516 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_map
) );
10519 case VKI_SIOCGIFTXQLEN
: /* Get the tx queue length */
10521 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_qlen
,
10522 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_qlen
) );
10524 case VKI_SIOCGIFNAME
: /* get iface name */
10526 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
,
10527 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
) );
10529 case VKI_SIOCETHTOOL
: { /* ethtool(8) interface */
10530 struct vki_ifreq
*ir
= (struct vki_ifreq
*)(Addr
)ARG3
;
10531 switch ( *(vki_u32
*)ir
->vki_ifr_data
) {
10532 case VKI_ETHTOOL_GSET
:
10533 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_cmd
));
10535 case VKI_ETHTOOL_SSET
:
10537 case VKI_ETHTOOL_GDRVINFO
:
10538 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_drvinfo
) );
10540 case VKI_ETHTOOL_GREGS
:
10541 POST_MEM_WRITE( (Addr
)((struct vki_ethtool_regs
*)ir
->vki_ifr_data
)->data
,
10542 ((struct vki_ethtool_regs
*)ir
->vki_ifr_data
)->len
);
10544 case VKI_ETHTOOL_GWOL
:
10545 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_wolinfo
) );
10547 case VKI_ETHTOOL_SWOL
:
10549 case VKI_ETHTOOL_GMSGLVL
:
10550 case VKI_ETHTOOL_GLINK
:
10551 case VKI_ETHTOOL_GRXCSUM
:
10552 case VKI_ETHTOOL_GSG
:
10553 case VKI_ETHTOOL_GTSO
:
10554 case VKI_ETHTOOL_GUFO
:
10555 case VKI_ETHTOOL_GGSO
:
10556 case VKI_ETHTOOL_GFLAGS
:
10557 case VKI_ETHTOOL_GGRO
:
10558 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_value
));
10560 case VKI_ETHTOOL_SMSGLVL
:
10561 case VKI_ETHTOOL_SRXCSUM
:
10562 case VKI_ETHTOOL_SSG
:
10563 case VKI_ETHTOOL_STSO
:
10564 case VKI_ETHTOOL_SUFO
:
10565 case VKI_ETHTOOL_SGSO
:
10566 case VKI_ETHTOOL_SFLAGS
:
10567 case VKI_ETHTOOL_SGRO
:
10569 case VKI_ETHTOOL_NWAY_RST
:
10571 case VKI_ETHTOOL_GRINGPARAM
:
10572 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_ringparam
));
10574 case VKI_ETHTOOL_SRINGPARAM
:
10576 case VKI_ETHTOOL_TEST
:
10577 POST_MEM_WRITE( (Addr
)((struct vki_ethtool_test
*)ir
->vki_ifr_data
)->data
,
10578 ((struct vki_ethtool_test
*)ir
->vki_ifr_data
)->len
* sizeof(__vki_u64
) );
10580 case VKI_ETHTOOL_PHYS_ID
:
10582 case VKI_ETHTOOL_GPERMADDR
:
10583 POST_MEM_WRITE( (Addr
)((struct vki_ethtool_perm_addr
*)ir
->vki_ifr_data
)->data
,
10584 ((struct vki_ethtool_perm_addr
*)ir
->vki_ifr_data
)->size
);
10586 case VKI_ETHTOOL_RESET
:
10588 case VKI_ETHTOOL_GSSET_INFO
:
10589 POST_MEM_WRITE( (Addr
)((struct vki_ethtool_sset_info
*)ir
->vki_ifr_data
)->data
,
10590 __builtin_popcountll(((struct vki_ethtool_sset_info
*)ir
->vki_ifr_data
)->sset_mask
) * sizeof(__vki_u32
) );
10592 case VKI_ETHTOOL_GFEATURES
:
10593 POST_MEM_WRITE( (Addr
)((struct vki_ethtool_gfeatures
*)ir
->vki_ifr_data
)->features
,
10594 ((struct vki_ethtool_gfeatures
*)ir
->vki_ifr_data
)->size
* sizeof(struct vki_ethtool_get_features_block
) );
10596 case VKI_ETHTOOL_SFEATURES
:
10598 case VKI_ETHTOOL_GCHANNELS
:
10599 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_channels
) );
10601 case VKI_ETHTOOL_SCHANNELS
:
10603 case VKI_ETHTOOL_GET_TS_INFO
:
10604 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_ts_info
) );
10609 case VKI_SIOCGMIIPHY
: /* get hardware entry */
10611 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
,
10612 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
));
10614 case VKI_SIOCGMIIREG
: /* get hardware entry registers */
10616 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->val_out
,
10617 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->val_out
));
10620 /* tun/tap related ioctls */
10621 case VKI_TUNSETIFF
:
10622 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
,
10623 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
) );
10625 case VKI_TUNGETFEATURES
:
10626 POST_MEM_WRITE( ARG3
, sizeof(unsigned int) );
10628 case VKI_TUNGETIFF
:
10629 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
,
10630 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
) );
10631 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
,
10632 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
) );
10634 case VKI_TUNGETSNDBUF
:
10635 POST_MEM_WRITE( ARG3
, sizeof(int) );
10637 case VKI_TUNGETVNETHDRSZ
:
10638 POST_MEM_WRITE( ARG3
, sizeof(int) );
10641 case VKI_SIOCGIFCONF
: /* get iface list */
10643 PRE_MEM_WRITE("ioctl(SIOCGIFCONF)", ARG3, sizeof(struct ifconf));
10644 KERNEL_DO_SYSCALL(tid,RES);
10645 if (!VG_(is_kerror)(RES) && RES == 0)
10646 POST_MEM_WRITE(ARG3, sizeof(struct ifconf));
10648 if (RES
== 0 && ARG3
) {
10649 struct vki_ifconf
*ifc
= (struct vki_ifconf
*) (Addr
)ARG3
;
10650 if (ifc
->vki_ifc_buf
!= NULL
)
10651 POST_MEM_WRITE( (Addr
)(ifc
->vki_ifc_buf
), ifc
->ifc_len
);
10654 case VKI_SIOCGSTAMP
:
10655 POST_MEM_WRITE( ARG3
, sizeof(struct vki_timeval
) );
10657 case VKI_SIOCGSTAMPNS
:
10658 POST_MEM_WRITE( ARG3
, sizeof(struct vki_timespec
) );
10660 /* SIOCOUTQ is an ioctl that, when called on a socket, returns
10661 the number of bytes currently in that socket's send buffer.
10662 It writes this value as an int to the memory location
10663 indicated by the third argument of ioctl(2). */
10665 POST_MEM_WRITE(ARG3
, sizeof(int));
10667 case VKI_SIOCGRARP
: /* get RARP table entry */
10668 case VKI_SIOCGARP
: /* get ARP table entry */
10669 POST_MEM_WRITE(ARG3
, sizeof(struct vki_arpreq
));
10672 case VKI_SIOCSIFFLAGS
: /* set flags */
10673 case VKI_SIOCSIFMAP
: /* Set device parameters */
10674 case VKI_SIOCSHWTSTAMP
: /* Set hardware time stamping */
10675 case VKI_SIOCSIFTXQLEN
: /* Set the tx queue length */
10676 case VKI_SIOCSIFDSTADDR
: /* set remote PA address */
10677 case VKI_SIOCSIFBRDADDR
: /* set broadcast PA address */
10678 case VKI_SIOCSIFNETMASK
: /* set network PA mask */
10679 case VKI_SIOCSIFMETRIC
: /* set metric */
10680 case VKI_SIOCSIFADDR
: /* set PA address */
10681 case VKI_SIOCSIFMTU
: /* set MTU size */
10682 case VKI_SIOCSIFHWADDR
: /* set hardware address */
10683 case VKI_SIOCSMIIREG
: /* set hardware entry registers */
10685 /* Routing table calls. */
10686 case VKI_SIOCADDRT
: /* add routing table entry */
10687 case VKI_SIOCDELRT
: /* delete routing table entry */
10690 /* RARP cache control calls. */
10691 case VKI_SIOCDRARP
: /* delete RARP table entry */
10692 case VKI_SIOCSRARP
: /* set RARP table entry */
10693 /* ARP cache control calls. */
10694 case VKI_SIOCSARP
: /* set ARP table entry */
10695 case VKI_SIOCDARP
: /* delete ARP table entry */
10698 case VKI_SIOCGPGRP
:
10699 POST_MEM_WRITE(ARG3
, sizeof(int));
10701 case VKI_SIOCSPGRP
:
10704 case VKI_SIOCATMARK
:
10705 POST_MEM_WRITE(ARG3
, sizeof(int));
10708 /* linux/soundcard interface (OSS) */
10709 case VKI_SNDCTL_SEQ_GETOUTCOUNT
:
10710 case VKI_SNDCTL_SEQ_GETINCOUNT
:
10711 case VKI_SNDCTL_SEQ_PERCMODE
:
10712 case VKI_SNDCTL_SEQ_TESTMIDI
:
10713 case VKI_SNDCTL_SEQ_RESETSAMPLES
:
10714 case VKI_SNDCTL_SEQ_NRSYNTHS
:
10715 case VKI_SNDCTL_SEQ_NRMIDIS
:
10716 case VKI_SNDCTL_SEQ_GETTIME
:
10717 case VKI_SNDCTL_DSP_GETBLKSIZE
:
10718 case VKI_SNDCTL_DSP_GETFMTS
:
10719 case VKI_SNDCTL_DSP_SETFMT
:
10720 case VKI_SNDCTL_DSP_GETTRIGGER
:
10721 case VKI_SNDCTL_DSP_GETODELAY
:
10722 case VKI_SNDCTL_DSP_GETSPDIF
:
10723 case VKI_SNDCTL_DSP_GETCAPS
:
10724 case VKI_SOUND_PCM_READ_RATE
:
10725 case VKI_SOUND_PCM_READ_CHANNELS
:
10726 case VKI_SOUND_PCM_READ_BITS
:
10727 case VKI_SOUND_PCM_READ_FILTER
:
10728 POST_MEM_WRITE(ARG3
, sizeof(int));
10730 case VKI_SNDCTL_SEQ_CTRLRATE
:
10731 case VKI_SNDCTL_DSP_SPEED
:
10732 case VKI_SNDCTL_DSP_STEREO
:
10733 case VKI_SNDCTL_DSP_CHANNELS
:
10734 case VKI_SOUND_PCM_WRITE_FILTER
:
10735 case VKI_SNDCTL_DSP_SUBDIVIDE
:
10736 case VKI_SNDCTL_DSP_SETFRAGMENT
:
10737 case VKI_SNDCTL_DSP_GETCHANNELMASK
:
10738 case VKI_SNDCTL_DSP_BIND_CHANNEL
:
10739 case VKI_SNDCTL_TMR_TIMEBASE
:
10740 case VKI_SNDCTL_TMR_TEMPO
:
10741 case VKI_SNDCTL_TMR_SOURCE
:
10742 case VKI_SNDCTL_MIDI_PRETIME
:
10743 case VKI_SNDCTL_MIDI_MPUMODE
:
10745 case VKI_SNDCTL_DSP_GETOSPACE
:
10746 case VKI_SNDCTL_DSP_GETISPACE
:
10747 POST_MEM_WRITE(ARG3
, sizeof(vki_audio_buf_info
));
10749 case VKI_SNDCTL_DSP_NONBLOCK
:
10751 case VKI_SNDCTL_DSP_SETTRIGGER
:
10754 case VKI_SNDCTL_DSP_POST
:
10755 case VKI_SNDCTL_DSP_RESET
:
10756 case VKI_SNDCTL_DSP_SYNC
:
10757 case VKI_SNDCTL_DSP_SETSYNCRO
:
10758 case VKI_SNDCTL_DSP_SETDUPLEX
:
10761 /* linux/soundcard interface (ALSA) */
10762 case VKI_SNDRV_PCM_IOCTL_HW_FREE
:
10763 case VKI_SNDRV_PCM_IOCTL_HWSYNC
:
10764 case VKI_SNDRV_PCM_IOCTL_PREPARE
:
10765 case VKI_SNDRV_PCM_IOCTL_RESET
:
10766 case VKI_SNDRV_PCM_IOCTL_START
:
10767 case VKI_SNDRV_PCM_IOCTL_DROP
:
10768 case VKI_SNDRV_PCM_IOCTL_DRAIN
:
10769 case VKI_SNDRV_PCM_IOCTL_RESUME
:
10770 case VKI_SNDRV_PCM_IOCTL_XRUN
:
10771 case VKI_SNDRV_PCM_IOCTL_UNLINK
:
10772 case VKI_SNDRV_TIMER_IOCTL_START
:
10773 case VKI_SNDRV_TIMER_IOCTL_STOP
:
10774 case VKI_SNDRV_TIMER_IOCTL_CONTINUE
:
10775 case VKI_SNDRV_TIMER_IOCTL_PAUSE
:
10778 case VKI_SNDRV_CTL_IOCTL_PVERSION
: {
10779 POST_MEM_WRITE( (Addr
)ARG3
, sizeof(int) );
10782 case VKI_SNDRV_CTL_IOCTL_CARD_INFO
:
10783 POST_MEM_WRITE( (Addr
)ARG3
, sizeof(struct vki_snd_ctl_card_info
) );
10785 case VKI_SNDRV_CTL_IOCTL_ELEM_LIST
: {
10786 struct vki_snd_ctl_elem_list
*data
=
10787 (struct vki_snd_ctl_elem_list
*)(Addr
)ARG3
;
10788 POST_MEM_WRITE( (Addr
)&data
->used
, sizeof(data
->used
) );
10789 POST_MEM_WRITE( (Addr
)&data
->count
, sizeof(data
->count
) );
10791 POST_MEM_WRITE( (Addr
)data
->pids
, sizeof(struct vki_snd_ctl_elem_id
) * data
->used
);
10795 case VKI_SNDRV_CTL_IOCTL_TLV_READ
: {
10796 struct vki_snd_ctl_tlv
*data
= (struct vki_snd_ctl_tlv
*)(Addr
)ARG3
;
10797 POST_MEM_WRITE( (Addr
)data
->tlv
, data
->length
);
10800 case VKI_SNDRV_CTL_IOCTL_TLV_WRITE
:
10801 case VKI_SNDRV_CTL_IOCTL_TLV_COMMAND
:
10804 /* SCSI no operand */
10805 case VKI_SCSI_IOCTL_DOORLOCK
:
10806 case VKI_SCSI_IOCTL_DOORUNLOCK
:
10809 /* Real Time Clock (/dev/rtc) ioctls */
10810 case VKI_RTC_UIE_ON
:
10811 case VKI_RTC_UIE_OFF
:
10812 case VKI_RTC_AIE_ON
:
10813 case VKI_RTC_AIE_OFF
:
10814 case VKI_RTC_PIE_ON
:
10815 case VKI_RTC_PIE_OFF
:
10816 case VKI_RTC_IRQP_SET
:
10818 case VKI_RTC_RD_TIME
:
10819 case VKI_RTC_ALM_READ
:
10820 POST_MEM_WRITE(ARG3
, sizeof(struct vki_rtc_time
));
10822 case VKI_RTC_ALM_SET
:
10824 case VKI_RTC_IRQP_READ
:
10825 POST_MEM_WRITE(ARG3
, sizeof(unsigned long));
10828 /* Block devices */
10832 POST_MEM_WRITE(ARG3
, sizeof(int));
10834 case VKI_BLKGETSIZE
:
10835 POST_MEM_WRITE(ARG3
, sizeof(unsigned long));
10837 case VKI_BLKFLSBUF
:
10842 POST_MEM_WRITE(ARG3
, sizeof(long));
10844 case VKI_BLKFRASET
:
10846 case VKI_BLKFRAGET
:
10847 POST_MEM_WRITE(ARG3
, sizeof(long));
10849 case VKI_BLKSECTGET
:
10850 POST_MEM_WRITE(ARG3
, sizeof(unsigned short));
10852 case VKI_BLKSSZGET
:
10853 POST_MEM_WRITE(ARG3
, sizeof(int));
10855 case VKI_BLKBSZGET
:
10856 POST_MEM_WRITE(ARG3
, sizeof(int));
10858 case VKI_BLKBSZSET
:
10860 case VKI_BLKGETSIZE64
:
10861 POST_MEM_WRITE(ARG3
, sizeof(unsigned long long));
10863 case VKI_BLKPBSZGET
:
10864 POST_MEM_WRITE(ARG3
, sizeof(int));
10867 POST_MEM_WRITE(ARG3
, sizeof(vki_uint
));
10870 POST_MEM_WRITE(ARG3
, sizeof(vki_uint
));
10872 case VKI_BLKALIGNOFF
:
10873 POST_MEM_WRITE(ARG3
, sizeof(int));
10875 case VKI_BLKDISCARDZEROES
:
10876 POST_MEM_WRITE(ARG3
, sizeof(vki_uint
));
10878 case VKI_BLKREPORTZONE
: {
10879 const struct vki_blk_zone_report
*zr
= (void *)(Addr
)ARG3
;
10881 POST_MEM_WRITE(ARG3
, sizeof(*zr
) + zr
->nr_zones
* sizeof(zr
->zones
[0]));
10884 case VKI_BLKRESETZONE
:
10888 case VKI_HDIO_GETGEO
: /* 0x0301 */
10889 POST_MEM_WRITE(ARG3
, sizeof(struct vki_hd_geometry
));
10891 case VKI_HDIO_GET_DMA
: /* 0x030b */
10892 POST_MEM_WRITE(ARG3
, sizeof(long));
10894 case VKI_HDIO_GET_IDENTITY
: /* 0x030d */
10895 POST_MEM_WRITE(ARG3
, VKI_SIZEOF_STRUCT_HD_DRIVEID
);
10899 case VKI_SCSI_IOCTL_GET_IDLUN
: /* 0x5382 */
10900 POST_MEM_WRITE(ARG3
, sizeof(struct vki_scsi_idlun
));
10902 case VKI_SCSI_IOCTL_GET_BUS_NUMBER
: /* 0x5386 */
10903 POST_MEM_WRITE(ARG3
, sizeof(int));
10906 /* CD ROM stuff (??) */
10907 case VKI_CDROM_DISC_STATUS
:
10908 case VKI_CDROMSTOP
:
10910 case VKI_CDROMSUBCHNL
:
10911 POST_MEM_WRITE(ARG3
, sizeof(struct vki_cdrom_subchnl
));
10913 case VKI_CDROMREADTOCHDR
:
10914 POST_MEM_WRITE(ARG3
, sizeof(struct vki_cdrom_tochdr
));
10916 case VKI_CDROMREADTOCENTRY
:
10917 POST_MEM_WRITE(ARG3
, sizeof(struct vki_cdrom_tocentry
));
10919 case VKI_CDROMMULTISESSION
:
10920 POST_MEM_WRITE(ARG3
, sizeof(struct vki_cdrom_multisession
));
10922 case VKI_CDROMVOLREAD
:
10923 POST_MEM_WRITE(ARG3
, sizeof(struct vki_cdrom_volctrl
));
10925 case VKI_CDROMREADMODE1
:
10926 POST_MEM_WRITE(ARG3
, VKI_CD_FRAMESIZE_RAW1
);
10928 case VKI_CDROMREADMODE2
:
10929 POST_MEM_WRITE(ARG3
, VKI_CD_FRAMESIZE_RAW0
);
10931 case VKI_CDROMREADRAW
:
10932 POST_MEM_WRITE(ARG3
, VKI_CD_FRAMESIZE_RAW
);
10934 case VKI_CDROMREADAUDIO
:
10936 struct vki_cdrom_read_audio
*cra
=
10937 (struct vki_cdrom_read_audio
*) (Addr
)ARG3
;
10938 POST_MEM_WRITE( (Addr
)(cra
->buf
), cra
->nframes
* VKI_CD_FRAMESIZE_RAW
);
10942 case VKI_CDROMPLAYMSF
:
10944 /* The following two are probably bogus (should check args
10945 for readability). JRS 20021117 */
10946 case VKI_CDROM_DRIVE_STATUS
: /* 0x5326 */
10947 case VKI_CDROM_CLEAR_OPTIONS
: /* 0x5321 */
10949 case VKI_CDROM_GET_CAPABILITY
: /* 0x5331 */
10953 case VKI_DVD_READ_STRUCT
:
10957 POST_MEM_WRITE(ARG3
, sizeof(unsigned long));
10960 POST_MEM_WRITE(ARG3
, sizeof(int));
10965 case VKI_FBIOGET_VSCREENINFO
: //0x4600
10966 POST_MEM_WRITE(ARG3
, sizeof(struct vki_fb_var_screeninfo
));
10968 case VKI_FBIOGET_FSCREENINFO
: //0x4602
10969 POST_MEM_WRITE(ARG3
, sizeof(struct vki_fb_fix_screeninfo
));
10975 case VKI_PPRELEASE
:
10976 case VKI_PPSETMODE
:
10977 case VKI_PPSETPHASE
:
10978 case VKI_PPSETFLAGS
:
10980 case VKI_PPWCONTROL
:
10981 case VKI_PPFCONTROL
:
10982 case VKI_PPDATADIR
:
10984 case VKI_PPWCTLONIRQ
:
10985 case VKI_PPSETTIME
:
10987 case VKI_PPGETMODE
:
10988 POST_MEM_WRITE( ARG3
, sizeof(int) );
10990 case VKI_PPGETPHASE
:
10991 POST_MEM_WRITE( ARG3
, sizeof(int) );
10993 case VKI_PPGETMODES
:
10994 POST_MEM_WRITE( ARG3
, sizeof(unsigned int) );
10996 case VKI_PPGETFLAGS
:
10997 POST_MEM_WRITE( ARG3
, sizeof(int) );
10999 case VKI_PPRSTATUS
:
11000 POST_MEM_WRITE( ARG3
, sizeof(unsigned char) );
11003 POST_MEM_WRITE( ARG3
, sizeof(unsigned char) );
11005 case VKI_PPRCONTROL
:
11006 POST_MEM_WRITE( ARG3
, sizeof(unsigned char) );
11009 POST_MEM_WRITE( ARG3
, sizeof(int) );
11011 case VKI_PPGETTIME
:
11012 POST_MEM_WRITE( ARG3
, sizeof(struct vki_timeval
) );
11016 POST_MEM_WRITE( ARG3
, 32 * 256 );
11021 case VKI_GIO_FONTX
:
11022 POST_MEM_WRITE((Addr
)((struct vki_consolefontdesc
*)(Addr
)ARG3
)->chardata
,
11023 32 * ((struct vki_consolefontdesc
*)(Addr
)ARG3
)->charcount
);
11025 case VKI_PIO_FONTX
:
11028 case VKI_PIO_FONTRESET
:
11032 POST_MEM_WRITE( ARG3
, 16 * 3 );
11037 case VKI_KIOCSOUND
:
11042 POST_MEM_WRITE( ARG3
, sizeof(char) );
11047 case VKI_KDGKBTYPE
:
11048 POST_MEM_WRITE( ARG3
, sizeof(char) );
11054 case VKI_KDDISABIO
:
11057 case VKI_KDSETMODE
:
11059 case VKI_KDGETMODE
:
11060 POST_MEM_WRITE( ARG3
, sizeof(int) );
11063 case VKI_KDMAPDISP
:
11064 case VKI_KDUNMAPDISP
:
11067 case VKI_GIO_SCRNMAP
:
11068 POST_MEM_WRITE( ARG3
, VKI_E_TABSZ
);
11070 case VKI_PIO_SCRNMAP
:
11072 case VKI_GIO_UNISCRNMAP
:
11073 POST_MEM_WRITE( ARG3
, VKI_E_TABSZ
* sizeof(unsigned short) );
11075 case VKI_PIO_UNISCRNMAP
:
11078 case VKI_GIO_UNIMAP
:
11080 struct vki_unimapdesc
*desc
= (struct vki_unimapdesc
*) (Addr
)ARG3
;
11081 POST_MEM_WRITE( (Addr
)&desc
->entry_ct
, sizeof(desc
->entry_ct
));
11082 POST_MEM_WRITE( (Addr
)desc
->entries
,
11083 desc
->entry_ct
* sizeof(struct vki_unipair
) );
11086 case VKI_PIO_UNIMAP
:
11088 case VKI_PIO_UNIMAPCLR
:
11091 case VKI_KDGKBMODE
:
11092 POST_MEM_WRITE( ARG3
, sizeof(int) );
11094 case VKI_KDSKBMODE
:
11097 case VKI_KDGKBMETA
:
11098 POST_MEM_WRITE( ARG3
, sizeof(int) );
11100 case VKI_KDSKBMETA
:
11104 POST_MEM_WRITE( ARG3
, sizeof(char) );
11110 POST_MEM_WRITE( (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
,
11111 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
) );
11116 case VKI_KDGKBSENT
:
11117 POST_MEM_WRITE( (Addr
)((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_string
,
11118 sizeof(((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_string
) );
11120 case VKI_KDSKBSENT
:
11123 case VKI_KDGKBDIACR
:
11124 POST_MEM_WRITE( ARG3
, sizeof(struct vki_kbdiacrs
) );
11126 case VKI_KDSKBDIACR
:
11129 case VKI_KDGETKEYCODE
:
11130 POST_MEM_WRITE( (Addr
)((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
,
11131 sizeof(((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
) );
11133 case VKI_KDSETKEYCODE
:
11136 case VKI_KDSIGACCEPT
:
11144 struct vki_console_font_op
*op
=
11145 (struct vki_console_font_op
*) (Addr
)ARG3
;
11146 switch ( op
->op
) {
11147 case VKI_KD_FONT_OP_SET
:
11149 case VKI_KD_FONT_OP_GET
:
11151 POST_MEM_WRITE( (Addr
) op
->data
,
11152 (op
->width
+ 7) / 8 * 32 * op
->charcount
);
11154 case VKI_KD_FONT_OP_SET_DEFAULT
:
11156 case VKI_KD_FONT_OP_COPY
:
11159 POST_MEM_WRITE( (Addr
) op
, sizeof(*op
));
11163 case VKI_VT_OPENQRY
:
11164 POST_MEM_WRITE( ARG3
, sizeof(int) );
11166 case VKI_VT_GETMODE
:
11167 POST_MEM_WRITE( ARG3
, sizeof(struct vki_vt_mode
) );
11169 case VKI_VT_SETMODE
:
11171 case VKI_VT_GETSTATE
:
11172 POST_MEM_WRITE( (Addr
) &(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_active
),
11173 sizeof(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_active
) );
11174 POST_MEM_WRITE( (Addr
) &(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_state
),
11175 sizeof(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_state
) );
11177 case VKI_VT_RELDISP
:
11178 case VKI_VT_ACTIVATE
:
11179 case VKI_VT_WAITACTIVE
:
11180 case VKI_VT_DISALLOCATE
:
11182 case VKI_VT_RESIZE
:
11184 case VKI_VT_RESIZEX
:
11186 case VKI_VT_LOCKSWITCH
:
11187 case VKI_VT_UNLOCKSWITCH
:
11190 case VKI_USBDEVFS_CONTROL
:
11192 struct vki_usbdevfs_ctrltransfer
*vkuc
=
11193 (struct vki_usbdevfs_ctrltransfer
*)(Addr
)ARG3
;
11194 if (vkuc
->bRequestType
& 0x80)
11195 POST_MEM_WRITE((Addr
)vkuc
->data
, RES
);
11198 case VKI_USBDEVFS_BULK
:
11200 struct vki_usbdevfs_bulktransfer
*vkub
=
11201 (struct vki_usbdevfs_bulktransfer
*)(Addr
)ARG3
;
11202 if (vkub
->ep
& 0x80)
11203 POST_MEM_WRITE((Addr
)vkub
->data
, RES
);
11206 case VKI_USBDEVFS_GETDRIVER
:
11208 struct vki_usbdevfs_getdriver
*vkugd
=
11209 (struct vki_usbdevfs_getdriver
*)(Addr
)ARG3
;
11210 POST_MEM_WRITE((Addr
)&vkugd
->driver
, sizeof(vkugd
->driver
));
11213 case VKI_USBDEVFS_REAPURB
:
11214 case VKI_USBDEVFS_REAPURBNDELAY
:
11216 struct vki_usbdevfs_urb
**vkuu
= (struct vki_usbdevfs_urb
**)(Addr
)ARG3
;
11217 POST_MEM_WRITE((Addr
)vkuu
, sizeof(*vkuu
));
11220 POST_MEM_WRITE((Addr
) &((*vkuu
)->status
),sizeof((*vkuu
)->status
));
11221 if ((*vkuu
)->type
== VKI_USBDEVFS_URB_TYPE_CONTROL
) {
11222 struct vki_usbdevfs_setuppacket
*vkusp
= (struct vki_usbdevfs_setuppacket
*)(*vkuu
)->buffer
;
11223 if (vkusp
->bRequestType
& 0x80)
11224 POST_MEM_WRITE((Addr
)(vkusp
+1), (*vkuu
)->buffer_length
- sizeof(*vkusp
));
11225 POST_MEM_WRITE((Addr
)&(*vkuu
)->actual_length
, sizeof((*vkuu
)->actual_length
));
11226 } else if ((*vkuu
)->type
== VKI_USBDEVFS_URB_TYPE_ISO
) {
11227 char *bp
= (*vkuu
)->buffer
;
11229 for(i
=0; i
<(*vkuu
)->number_of_packets
; i
++) {
11230 POST_MEM_WRITE((Addr
)&(*vkuu
)->iso_frame_desc
[i
].actual_length
, sizeof((*vkuu
)->iso_frame_desc
[i
].actual_length
));
11231 POST_MEM_WRITE((Addr
)&(*vkuu
)->iso_frame_desc
[i
].status
, sizeof((*vkuu
)->iso_frame_desc
[i
].status
));
11232 if ((*vkuu
)->endpoint
& 0x80)
11233 POST_MEM_WRITE((Addr
)bp
, (*vkuu
)->iso_frame_desc
[i
].actual_length
);
11234 bp
+= (*vkuu
)->iso_frame_desc
[i
].length
; // FIXME: or actual_length??
11236 POST_MEM_WRITE((Addr
)&(*vkuu
)->error_count
, sizeof((*vkuu
)->error_count
));
11238 if ((*vkuu
)->endpoint
& 0x80)
11239 POST_MEM_WRITE((Addr
)(*vkuu
)->buffer
, (*vkuu
)->actual_length
);
11240 POST_MEM_WRITE((Addr
)&(*vkuu
)->actual_length
, sizeof((*vkuu
)->actual_length
));
11244 case VKI_USBDEVFS_CONNECTINFO
:
11245 POST_MEM_WRITE(ARG3
, sizeof(struct vki_usbdevfs_connectinfo
));
11247 case VKI_USBDEVFS_IOCTL
:
11249 struct vki_usbdevfs_ioctl
*vkui
=
11250 (struct vki_usbdevfs_ioctl
*)(Addr
)ARG3
;
11252 dir2
= _VKI_IOC_DIR(vkui
->ioctl_code
);
11253 size2
= _VKI_IOC_SIZE(vkui
->ioctl_code
);
11255 if (dir2
& _VKI_IOC_READ
)
11256 POST_MEM_WRITE((Addr
)vkui
->data
, size2
);
11261 /* I2C (/dev/i2c-*) ioctls */
11262 case VKI_I2C_SLAVE
:
11263 case VKI_I2C_SLAVE_FORCE
:
11264 case VKI_I2C_TENBIT
:
11267 case VKI_I2C_FUNCS
:
11268 POST_MEM_WRITE( ARG3
, sizeof(unsigned long) );
11272 struct vki_i2c_rdwr_ioctl_data
*vkui
=
11273 (struct vki_i2c_rdwr_ioctl_data
*)(Addr
)ARG3
;
11275 for (i
=0; i
< vkui
->nmsgs
; i
++) {
11276 struct vki_i2c_msg
*msg
= vkui
->msgs
+ i
;
11277 if (msg
->flags
& VKI_I2C_M_RD
)
11278 POST_MEM_WRITE((Addr
)msg
->buf
, msg
->len
);
11282 case VKI_I2C_SMBUS
:
11284 struct vki_i2c_smbus_ioctl_data
*vkis
11285 = (struct vki_i2c_smbus_ioctl_data
*) (Addr
)ARG3
;
11286 /* i2c_smbus_write_quick hides its value in read_write, so
11287 this variable can have a different meaning */
11288 if ((vkis
->read_write
== VKI_I2C_SMBUS_READ
)
11289 || (vkis
->size
== VKI_I2C_SMBUS_PROC_CALL
)
11290 || (vkis
->size
== VKI_I2C_SMBUS_BLOCK_PROC_CALL
)) {
11291 if ( ! (vkis
->size
== VKI_I2C_SMBUS_QUICK
)) {
11293 switch(vkis
->size
) {
11294 case VKI_I2C_SMBUS_BYTE
:
11295 case VKI_I2C_SMBUS_BYTE_DATA
:
11298 case VKI_I2C_SMBUS_WORD_DATA
:
11299 case VKI_I2C_SMBUS_PROC_CALL
:
11302 case VKI_I2C_SMBUS_BLOCK_DATA
:
11303 case VKI_I2C_SMBUS_I2C_BLOCK_BROKEN
:
11304 case VKI_I2C_SMBUS_BLOCK_PROC_CALL
:
11305 case VKI_I2C_SMBUS_I2C_BLOCK_DATA
:
11306 size
= 1 + vkis
->data
->block
[0];
11311 POST_MEM_WRITE((Addr
)&vkis
->data
->block
[0], size
);
11317 /* Wireless extensions ioctls */
11318 case VKI_SIOCSIWCOMMIT
:
11319 case VKI_SIOCSIWNWID
:
11320 case VKI_SIOCSIWFREQ
:
11321 case VKI_SIOCSIWMODE
:
11322 case VKI_SIOCSIWSENS
:
11323 case VKI_SIOCSIWRANGE
:
11324 case VKI_SIOCSIWPRIV
:
11325 case VKI_SIOCSIWSTATS
:
11326 case VKI_SIOCSIWSPY
:
11327 case VKI_SIOCSIWTHRSPY
:
11328 case VKI_SIOCSIWAP
:
11329 case VKI_SIOCSIWSCAN
:
11330 case VKI_SIOCSIWESSID
:
11331 case VKI_SIOCSIWRATE
:
11332 case VKI_SIOCSIWNICKN
:
11333 case VKI_SIOCSIWRTS
:
11334 case VKI_SIOCSIWFRAG
:
11335 case VKI_SIOCSIWTXPOW
:
11336 case VKI_SIOCSIWRETRY
:
11337 case VKI_SIOCSIWENCODE
:
11338 case VKI_SIOCSIWPOWER
:
11339 case VKI_SIOCSIWGENIE
:
11340 case VKI_SIOCSIWMLME
:
11341 case VKI_SIOCSIWAUTH
:
11342 case VKI_SIOCSIWENCODEEXT
:
11343 case VKI_SIOCSIWPMKSA
:
11345 case VKI_SIOCGIWNAME
:
11347 POST_MEM_WRITE((Addr
)((struct vki_iwreq
*)(Addr
)ARG3
)->u
.name
,
11348 sizeof(((struct vki_iwreq
*)(Addr
)ARG3
)->u
.name
));
11351 case VKI_SIOCGIWNWID
:
11352 case VKI_SIOCGIWSENS
:
11353 case VKI_SIOCGIWRATE
:
11354 case VKI_SIOCGIWRTS
:
11355 case VKI_SIOCGIWFRAG
:
11356 case VKI_SIOCGIWTXPOW
:
11357 case VKI_SIOCGIWRETRY
:
11358 case VKI_SIOCGIWPOWER
:
11359 case VKI_SIOCGIWAUTH
:
11361 POST_MEM_WRITE((Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.param
,
11362 sizeof(struct vki_iw_param
));
11365 case VKI_SIOCGIWFREQ
:
11367 POST_MEM_WRITE((Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.freq
,
11368 sizeof(struct vki_iw_freq
));
11371 case VKI_SIOCGIWMODE
:
11373 POST_MEM_WRITE((Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.mode
,
11374 sizeof(__vki_u32
));
11377 case VKI_SIOCGIWRANGE
:
11378 case VKI_SIOCGIWPRIV
:
11379 case VKI_SIOCGIWSTATS
:
11380 case VKI_SIOCGIWSPY
:
11381 case VKI_SIOCGIWTHRSPY
:
11382 case VKI_SIOCGIWAPLIST
:
11383 case VKI_SIOCGIWSCAN
:
11384 case VKI_SIOCGIWESSID
:
11385 case VKI_SIOCGIWNICKN
:
11386 case VKI_SIOCGIWENCODE
:
11387 case VKI_SIOCGIWGENIE
:
11388 case VKI_SIOCGIWENCODEEXT
:
11390 struct vki_iw_point
* point
;
11391 point
= &((struct vki_iwreq
*)(Addr
)ARG3
)->u
.data
;
11392 POST_MEM_WRITE((Addr
)point
->pointer
, point
->length
);
11395 case VKI_SIOCGIWAP
:
11397 POST_MEM_WRITE((Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.ap_addr
,
11398 sizeof(struct vki_sockaddr
));
11402 # if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
11403 || defined(VGPV_mips32_linux_android) \
11404 || defined(VGPV_arm64_linux_android)
11406 case VKI_ASHMEM_GET_SIZE
:
11407 case VKI_ASHMEM_SET_SIZE
:
11408 case VKI_ASHMEM_GET_PROT_MASK
:
11409 case VKI_ASHMEM_SET_PROT_MASK
:
11410 case VKI_ASHMEM_GET_PIN_STATUS
:
11411 case VKI_ASHMEM_PURGE_ALL_CACHES
:
11412 case VKI_ASHMEM_SET_NAME
:
11413 case VKI_ASHMEM_PIN
:
11414 case VKI_ASHMEM_UNPIN
:
11416 case VKI_ASHMEM_GET_NAME
:
11417 POST_MEM_WRITE( ARG3
, VKI_ASHMEM_NAME_LEN
);
11421 case VKI_BINDER_WRITE_READ
:
11423 struct vki_binder_write_read
* bwr
11424 = (struct vki_binder_write_read
*)(Addr
)ARG3
;
11425 POST_FIELD_WRITE(bwr
->write_consumed
);
11426 POST_FIELD_WRITE(bwr
->read_consumed
);
11428 if (bwr
->read_size
)
11429 POST_MEM_WRITE((Addr
)bwr
->read_buffer
, bwr
->read_consumed
);
11433 case VKI_BINDER_SET_IDLE_TIMEOUT
:
11434 case VKI_BINDER_SET_MAX_THREADS
:
11435 case VKI_BINDER_SET_IDLE_PRIORITY
:
11436 case VKI_BINDER_SET_CONTEXT_MGR
:
11437 case VKI_BINDER_THREAD_EXIT
:
11439 case VKI_BINDER_VERSION
:
11441 struct vki_binder_version
* bv
=
11442 (struct vki_binder_version
*)(Addr
)ARG3
;
11443 POST_FIELD_WRITE(bv
->protocol_version
);
11446 # endif /* defined(VGPV_*_linux_android) */
11448 case VKI_HCIGETDEVLIST
:
11450 struct vki_hci_dev_list_req
* dlr
=
11451 (struct vki_hci_dev_list_req
*)(Addr
)ARG3
;
11452 POST_MEM_WRITE((Addr
)ARG3
+ sizeof(struct vki_hci_dev_list_req
),
11453 dlr
->dev_num
* sizeof(struct vki_hci_dev_req
));
11457 case VKI_HCIINQUIRY
:
11459 struct vki_hci_inquiry_req
* ir
=
11460 (struct vki_hci_inquiry_req
*)(Addr
)ARG3
;
11461 POST_MEM_WRITE((Addr
)ARG3
+ sizeof(struct vki_hci_inquiry_req
),
11462 ir
->num_rsp
* sizeof(struct vki_inquiry_info
));
11466 case VKI_DRM_IOCTL_VERSION
:
11468 struct vki_drm_version
* data
= (struct vki_drm_version
*)(Addr
)ARG3
;
11469 struct vg_drm_version_info
* info
= container_of(data
, struct vg_drm_version_info
, data
);
11470 const vki_size_t orig_name_len
= info
->orig
->name_len
;
11471 const vki_size_t orig_date_len
= info
->orig
->date_len
;
11472 const vki_size_t orig_desc_len
= info
->orig
->desc_len
;
11473 *info
->orig
= info
->data
;
11474 ARG3
= (Addr
)info
->orig
;
11478 POST_MEM_WRITE((Addr
)&data
->version_major
, sizeof(data
->version_major
));
11479 POST_MEM_WRITE((Addr
)&data
->version_minor
, sizeof(data
->version_minor
));
11480 POST_MEM_WRITE((Addr
)&data
->version_patchlevel
, sizeof(data
->version_patchlevel
));
11481 POST_MEM_WRITE((Addr
)&data
->name_len
, sizeof(data
->name_len
));
11482 POST_MEM_WRITE((Addr
)data
->name
, VG_MIN(data
->name_len
, orig_name_len
));
11483 POST_MEM_WRITE((Addr
)&data
->date_len
, sizeof(data
->date_len
));
11484 POST_MEM_WRITE((Addr
)data
->date
, VG_MIN(data
->date_len
, orig_date_len
));
11485 POST_MEM_WRITE((Addr
)&data
->desc_len
, sizeof(data
->desc_len
));
11486 POST_MEM_WRITE((Addr
)data
->desc
, VG_MIN(data
->desc_len
, orig_desc_len
));
11490 case VKI_DRM_IOCTL_GET_UNIQUE
:
11492 struct vki_drm_unique
*data
= (struct vki_drm_unique
*)(Addr
)ARG3
;
11493 POST_MEM_WRITE((Addr
)data
->unique
, sizeof(data
->unique_len
));
11496 case VKI_DRM_IOCTL_GET_MAGIC
:
11498 struct vki_drm_auth
*data
= (struct vki_drm_auth
*)(Addr
)ARG3
;
11499 POST_MEM_WRITE((Addr
)&data
->magic
, sizeof(data
->magic
));
11502 case VKI_DRM_IOCTL_WAIT_VBLANK
:
11504 union vki_drm_wait_vblank
*data
=
11505 (union vki_drm_wait_vblank
*)(Addr
)ARG3
;
11506 POST_MEM_WRITE((Addr
)&data
->reply
, sizeof(data
->reply
));
11509 case VKI_DRM_IOCTL_GEM_FLINK
:
11511 struct vki_drm_gem_flink
*data
=
11512 (struct vki_drm_gem_flink
*)(Addr
)ARG3
;
11513 POST_MEM_WRITE((Addr
)&data
->name
, sizeof(data
->name
));
11516 case VKI_DRM_IOCTL_GEM_OPEN
:
11518 struct vki_drm_gem_open
*data
= (struct vki_drm_gem_open
*)(Addr
)ARG3
;
11519 POST_MEM_WRITE((Addr
)&data
->handle
, sizeof(data
->handle
));
11520 POST_MEM_WRITE((Addr
)&data
->size
, sizeof(data
->size
));
11523 case VKI_DRM_IOCTL_I915_GETPARAM
:
11525 vki_drm_i915_getparam_t
*data
= (vki_drm_i915_getparam_t
*)(Addr
)ARG3
;
11526 POST_MEM_WRITE((Addr
)data
->value
, sizeof(int));
11529 case VKI_DRM_IOCTL_I915_GEM_BUSY
:
11531 struct vki_drm_i915_gem_busy
*data
=
11532 (struct vki_drm_i915_gem_busy
*)(Addr
)ARG3
;
11533 POST_MEM_WRITE((Addr
)&data
->busy
, sizeof(data
->busy
));
11536 case VKI_DRM_IOCTL_I915_GEM_CREATE
:
11538 struct vki_drm_i915_gem_create
*data
=
11539 (struct vki_drm_i915_gem_create
*)(Addr
)ARG3
;
11540 POST_MEM_WRITE((Addr
)&data
->handle
, sizeof(data
->handle
));
11543 case VKI_DRM_IOCTL_I915_GEM_PREAD
:
11545 struct vki_drm_i915_gem_pread
*data
=
11546 (struct vki_drm_i915_gem_pread
*)(Addr
)ARG3
;
11547 POST_MEM_WRITE((Addr
)data
->data_ptr
, data
->size
);
11550 case VKI_DRM_IOCTL_I915_GEM_MMAPv1
:
11552 struct vki_drm_i915_gem_mmap_v1
*data
=
11553 (struct vki_drm_i915_gem_mmap_v1
*)(Addr
)ARG3
;
11554 Addr addr
= data
->addr_ptr
;
11555 SizeT size
= data
->size
;
11556 vg_assert(ML_(valid_client_addr
)(addr
, size
, tid
,
11557 "ioctl(DRM_IOCTL_I915_GEM_MMAPv1)"));
11558 ML_(notify_core_and_tool_of_mmap
)(addr
, size
,
11559 VKI_PROT_READ
| VKI_PROT_WRITE
,
11560 VKI_MAP_ANONYMOUS
, -1, 0 );
11561 POST_MEM_WRITE((Addr
)&data
->addr_ptr
, sizeof(data
->addr_ptr
));
11564 case VKI_DRM_IOCTL_I915_GEM_MMAP
:
11566 struct vki_drm_i915_gem_mmap
*data
=
11567 (struct vki_drm_i915_gem_mmap
*)(Addr
)ARG3
;
11568 Addr addr
= data
->addr_ptr
;
11569 SizeT size
= data
->size
;
11570 vg_assert(ML_(valid_client_addr
)(addr
, size
, tid
,
11571 "ioctl(DRM_IOCTL_I915_GEM_MMAP)"));
11572 ML_(notify_core_and_tool_of_mmap
)(addr
, size
,
11573 VKI_PROT_READ
| VKI_PROT_WRITE
,
11574 VKI_MAP_ANONYMOUS
, -1, 0 );
11575 POST_MEM_WRITE((Addr
)&data
->addr_ptr
, sizeof(data
->addr_ptr
));
11578 case VKI_DRM_IOCTL_I915_GEM_MMAP_GTT
:
11580 struct vki_drm_i915_gem_mmap_gtt
*data
=
11581 (struct vki_drm_i915_gem_mmap_gtt
*)(Addr
)ARG3
;
11582 POST_MEM_WRITE((Addr
)&data
->offset
, sizeof(data
->offset
));
11585 case VKI_DRM_IOCTL_I915_GEM_SET_TILING
:
11587 struct vki_drm_i915_gem_set_tiling
*data
=
11588 (struct vki_drm_i915_gem_set_tiling
*)(Addr
)ARG3
;
11589 POST_MEM_WRITE((Addr
)&data
->tiling_mode
, sizeof(data
->tiling_mode
));
11590 POST_MEM_WRITE((Addr
)&data
->stride
, sizeof(data
->stride
));
11591 POST_MEM_WRITE((Addr
)&data
->swizzle_mode
, sizeof(data
->swizzle_mode
));
11594 case VKI_DRM_IOCTL_I915_GEM_GET_TILING
:
11596 struct vki_drm_i915_gem_get_tiling
*data
=
11597 (struct vki_drm_i915_gem_get_tiling
*)(Addr
)ARG3
;
11598 POST_MEM_WRITE((Addr
)&data
->tiling_mode
, sizeof(data
->tiling_mode
));
11599 POST_MEM_WRITE((Addr
)&data
->swizzle_mode
, sizeof(data
->swizzle_mode
));
11602 case VKI_DRM_IOCTL_I915_GEM_GET_APERTURE
:
11604 struct vki_drm_i915_gem_get_aperture
*data
=
11605 (struct vki_drm_i915_gem_get_aperture
*)(Addr
)ARG3
;
11606 POST_MEM_WRITE((Addr
)&data
->aper_size
, sizeof(data
->aper_size
));
11607 POST_MEM_WRITE((Addr
)&data
->aper_available_size
, sizeof(data
->aper_available_size
));
11611 /* KVM ioctls that only write the system call return value */
11612 case VKI_KVM_GET_API_VERSION
:
11613 case VKI_KVM_CREATE_VM
:
11614 case VKI_KVM_CHECK_EXTENSION
:
11615 case VKI_KVM_GET_VCPU_MMAP_SIZE
:
11616 case VKI_KVM_S390_ENABLE_SIE
:
11617 case VKI_KVM_CREATE_VCPU
:
11618 case VKI_KVM_SET_TSS_ADDR
:
11619 case VKI_KVM_CREATE_IRQCHIP
:
11621 case VKI_KVM_S390_INITIAL_RESET
:
11622 case VKI_KVM_KVMCLOCK_CTRL
:
11625 case VKI_KVM_S390_MEM_OP
: {
11626 struct vki_kvm_s390_mem_op
*args
=
11627 (struct vki_kvm_s390_mem_op
*)(Addr
)(ARG3
);
11628 if (args
->flags
& VKI_KVM_S390_MEMOP_F_CHECK_ONLY
)
11630 if (args
->op
== VKI_KVM_S390_MEMOP_LOGICAL_READ
)
11631 POST_MEM_WRITE((Addr
)args
->buf
, args
->size
);
11636 case VKI_XEN_IOCTL_PRIVCMD_HYPERCALL
: {
11637 SyscallArgs harrghs
;
11638 struct vki_xen_privcmd_hypercall
*args
=
11639 (struct vki_xen_privcmd_hypercall
*)(Addr
)(ARG3
);
11644 VG_(memset
)(&harrghs
, 0, sizeof(harrghs
));
11645 harrghs
.sysno
= args
->op
;
11646 harrghs
.arg1
= args
->arg
[0];
11647 harrghs
.arg2
= args
->arg
[1];
11648 harrghs
.arg3
= args
->arg
[2];
11649 harrghs
.arg4
= args
->arg
[3];
11650 harrghs
.arg5
= args
->arg
[4];
11651 harrghs
.arg6
= harrghs
.arg7
= harrghs
.arg8
= 0;
11653 WRAPPER_POST_NAME(xen
, hypercall
) (tid
, &harrghs
, status
);
11657 case VKI_XEN_IOCTL_PRIVCMD_MMAP
:
11659 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH
: {
11660 struct vki_xen_privcmd_mmapbatch
*args
=
11661 (struct vki_xen_privcmd_mmapbatch
*)(Addr
)(ARG3
);
11662 POST_MEM_WRITE((Addr
)args
->arr
, sizeof(*(args
->arr
)) * args
->num
);
11665 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2
: {
11666 struct vki_xen_privcmd_mmapbatch_v2
*args
=
11667 (struct vki_xen_privcmd_mmapbatch_v2
*)(Addr
)(ARG3
);
11668 POST_MEM_WRITE((Addr
)args
->err
, sizeof(*(args
->err
)) * args
->num
);
11672 case VKI_XEN_IOCTL_EVTCHN_BIND_VIRQ
:
11673 case VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN
:
11674 case VKI_XEN_IOCTL_EVTCHN_BIND_UNBOUND_PORT
:
11675 case VKI_XEN_IOCTL_EVTCHN_UNBIND
:
11676 case VKI_XEN_IOCTL_EVTCHN_NOTIFY
:
11677 case VKI_XEN_IOCTL_EVTCHN_RESET
:
11683 case VKI_OBD_IOC_FID2PATH
: {
11684 struct vki_getinfo_fid2path
*args
= (void *)(Addr
)(ARG3
);
11685 POST_FIELD_WRITE(args
->gf_recno
);
11686 POST_FIELD_WRITE(args
->gf_linkno
);
11687 POST_MEM_WRITE((Addr
)args
->gf_path
, VG_(strlen
)(args
->gf_path
)+1);
11691 case VKI_LL_IOC_PATH2FID
:
11692 POST_MEM_WRITE(ARG3
, sizeof(struct vki_lu_fid
));
11695 case VKI_LL_IOC_GETPARENT
: {
11696 struct vki_getparent
*gp
= (struct vki_getparent
*)(Addr
)ARG3
;
11697 POST_FIELD_WRITE(gp
->gp_fid
);
11698 POST_MEM_WRITE((Addr
)gp
->gp_name
, VG_(strlen
)(gp
->gp_name
)+1);
11703 case VKI_V4L2_S_FMT
:
11704 case VKI_V4L2_TRY_FMT
:
11705 case VKI_V4L2_REQBUFS
:
11706 case VKI_V4L2_OVERLAY
:
11707 case VKI_V4L2_STREAMON
:
11708 case VKI_V4L2_STREAMOFF
:
11709 case VKI_V4L2_S_PARM
:
11710 case VKI_V4L2_S_STD
:
11711 case VKI_V4L2_S_FREQUENCY
:
11712 case VKI_V4L2_S_CTRL
:
11713 case VKI_V4L2_S_TUNER
:
11714 case VKI_V4L2_S_AUDIO
:
11715 case VKI_V4L2_S_INPUT
:
11716 case VKI_V4L2_S_EDID
:
11717 case VKI_V4L2_S_OUTPUT
:
11718 case VKI_V4L2_S_AUDOUT
:
11719 case VKI_V4L2_S_MODULATOR
:
11720 case VKI_V4L2_S_JPEGCOMP
:
11721 case VKI_V4L2_S_CROP
:
11722 case VKI_V4L2_S_PRIORITY
:
11723 case VKI_V4L2_S_HW_FREQ_SEEK
:
11724 case VKI_V4L2_S_DV_TIMINGS
:
11725 case VKI_V4L2_SUBSCRIBE_EVENT
:
11726 case VKI_V4L2_UNSUBSCRIBE_EVENT
:
11727 case VKI_V4L2_PREPARE_BUF
:
11729 case VKI_V4L2_QUERYCAP
: {
11730 struct vki_v4l2_capability
*data
=
11731 (struct vki_v4l2_capability
*)(Addr
)ARG3
;
11732 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11735 case VKI_V4L2_ENUM_FMT
: {
11736 struct vki_v4l2_fmtdesc
*data
= (struct vki_v4l2_fmtdesc
*)(Addr
)ARG3
;
11737 POST_FIELD_WRITE(data
->flags
);
11738 POST_FIELD_WRITE(data
->description
);
11739 POST_FIELD_WRITE(data
->pixelformat
);
11740 POST_FIELD_WRITE(data
->reserved
);
11743 case VKI_V4L2_G_FMT
: {
11744 struct vki_v4l2_format
*data
= (struct vki_v4l2_format
*)(Addr
)ARG3
;
11745 switch (data
->type
) {
11746 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE
:
11747 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
:
11748 POST_FIELD_WRITE(data
->fmt
.pix
);
11750 case VKI_V4L2_BUF_TYPE_VBI_CAPTURE
:
11751 case VKI_V4L2_BUF_TYPE_VBI_OUTPUT
:
11752 POST_FIELD_WRITE(data
->fmt
.vbi
);
11754 case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
11755 case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
11756 POST_FIELD_WRITE(data
->fmt
.sliced
);
11758 case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY
:
11759 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
11760 POST_FIELD_WRITE(data
->fmt
.win
);
11762 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
11763 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
11764 POST_FIELD_WRITE(data
->fmt
.pix_mp
);
11766 case VKI_V4L2_BUF_TYPE_SDR_CAPTURE
:
11767 POST_FIELD_WRITE(data
->fmt
.sdr
);
11772 case VKI_V4L2_QUERYBUF
: {
11773 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
11774 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
11775 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
11778 for (i
= 0; i
< data
->length
; i
++) {
11779 POST_FIELD_WRITE(data
->m
.planes
[i
].bytesused
);
11780 POST_FIELD_WRITE(data
->m
.planes
[i
].length
);
11781 POST_FIELD_WRITE(data
->m
.planes
[i
].m
);
11782 POST_FIELD_WRITE(data
->m
.planes
[i
].data_offset
);
11783 POST_FIELD_WRITE(data
->m
.planes
[i
].reserved
);
11786 POST_FIELD_WRITE(data
->m
);
11787 POST_FIELD_WRITE(data
->length
);
11789 POST_FIELD_WRITE(data
->bytesused
);
11790 POST_FIELD_WRITE(data
->flags
);
11791 POST_FIELD_WRITE(data
->field
);
11792 POST_FIELD_WRITE(data
->timestamp
);
11793 POST_FIELD_WRITE(data
->timecode
);
11794 POST_FIELD_WRITE(data
->sequence
);
11795 POST_FIELD_WRITE(data
->memory
);
11796 POST_FIELD_WRITE(data
->sequence
);
11799 case VKI_V4L2_G_FBUF
: {
11800 struct vki_v4l2_framebuffer
*data
=
11801 (struct vki_v4l2_framebuffer
*)(Addr
)ARG3
;
11802 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11805 case VKI_V4L2_S_FBUF
: {
11806 struct vki_v4l2_framebuffer
*data
=
11807 (struct vki_v4l2_framebuffer
*)(Addr
)ARG3
;
11808 POST_FIELD_WRITE(data
->capability
);
11809 POST_FIELD_WRITE(data
->flags
);
11810 POST_FIELD_WRITE(data
->fmt
);
11813 case VKI_V4L2_QBUF
: {
11814 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
11816 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
11817 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
11820 for (i
= 0; i
< data
->length
; i
++) {
11821 POST_FIELD_WRITE(data
->m
.planes
[i
].length
);
11822 if (data
->memory
== VKI_V4L2_MEMORY_MMAP
)
11823 POST_FIELD_WRITE(data
->m
.planes
[i
].m
);
11826 if (data
->memory
== VKI_V4L2_MEMORY_MMAP
)
11827 POST_FIELD_WRITE(data
->m
);
11828 POST_FIELD_WRITE(data
->length
);
11832 case VKI_V4L2_EXPBUF
: {
11833 struct vki_v4l2_exportbuffer
*data
=
11834 (struct vki_v4l2_exportbuffer
*)(Addr
)ARG3
;
11835 POST_FIELD_WRITE(data
->fd
);
11838 case VKI_V4L2_DQBUF
: {
11839 struct vki_v4l2_buffer
*data
=
11840 (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
11841 POST_FIELD_WRITE(data
->index
);
11842 POST_FIELD_WRITE(data
->bytesused
);
11843 POST_FIELD_WRITE(data
->field
);
11844 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
11845 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
11848 for (i
= 0; i
< data
->length
; i
++) {
11849 POST_FIELD_WRITE(data
->m
.planes
[i
].bytesused
);
11850 POST_FIELD_WRITE(data
->m
.planes
[i
].data_offset
);
11851 POST_FIELD_WRITE(data
->m
.planes
[i
].length
);
11852 POST_FIELD_WRITE(data
->m
.planes
[i
].m
);
11855 POST_FIELD_WRITE(data
->m
);
11856 POST_FIELD_WRITE(data
->length
);
11857 POST_FIELD_WRITE(data
->bytesused
);
11858 POST_FIELD_WRITE(data
->field
);
11860 POST_FIELD_WRITE(data
->timestamp
);
11861 POST_FIELD_WRITE(data
->timecode
);
11862 POST_FIELD_WRITE(data
->sequence
);
11865 case VKI_V4L2_G_PARM
: {
11866 struct vki_v4l2_streamparm
*data
=
11867 (struct vki_v4l2_streamparm
*)(Addr
)ARG3
;
11868 int is_output
= data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
||
11869 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
||
11870 data
->type
== VKI_V4L2_BUF_TYPE_VBI_OUTPUT
||
11871 data
->type
== VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
;
11874 POST_MEM_WRITE((Addr
)&data
->parm
.output
,
11875 sizeof(data
->parm
.output
) - sizeof(data
->parm
.output
.reserved
));
11877 POST_MEM_WRITE((Addr
)&data
->parm
.capture
,
11878 sizeof(data
->parm
.capture
) - sizeof(data
->parm
.capture
.reserved
));
11881 case VKI_V4L2_G_STD
: {
11882 vki_v4l2_std_id
*data
= (vki_v4l2_std_id
*)(Addr
)ARG3
;
11883 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11886 case VKI_V4L2_ENUMSTD
: {
11887 struct vki_v4l2_standard
*data
= (struct vki_v4l2_standard
*)(Addr
)ARG3
;
11888 POST_MEM_WRITE((Addr
)&data
->id
, sizeof(*data
) - sizeof(data
->index
));
11891 case VKI_V4L2_ENUMINPUT
: {
11892 struct vki_v4l2_input
*data
= (struct vki_v4l2_input
*)(Addr
)ARG3
;
11893 POST_MEM_WRITE((Addr
)data
->name
, sizeof(*data
) - sizeof(data
->index
));
11896 case VKI_V4L2_G_CTRL
: {
11897 struct vki_v4l2_control
*data
= (struct vki_v4l2_control
*)(Addr
)ARG3
;
11898 POST_FIELD_WRITE(data
->value
);
11901 case VKI_V4L2_G_TUNER
: {
11902 struct vki_v4l2_tuner
*data
= (struct vki_v4l2_tuner
*)(Addr
)ARG3
;
11903 POST_MEM_WRITE((Addr
)data
->name
,
11904 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
11907 case VKI_V4L2_G_AUDIO
: {
11908 struct vki_v4l2_audio
*data
= (struct vki_v4l2_audio
*)(Addr
)ARG3
;
11909 POST_MEM_WRITE((Addr
)data
,
11910 sizeof(*data
) - sizeof(data
->reserved
));
11913 case VKI_V4L2_QUERYCTRL
: {
11914 struct vki_v4l2_queryctrl
*data
= (struct vki_v4l2_queryctrl
*)(Addr
)ARG3
;
11915 POST_MEM_WRITE((Addr
)&data
->type
,
11916 sizeof(*data
) - sizeof(data
->id
));
11919 case VKI_V4L2_QUERYMENU
: {
11920 struct vki_v4l2_querymenu
*data
= (struct vki_v4l2_querymenu
*)(Addr
)ARG3
;
11921 POST_MEM_WRITE((Addr
)data
->name
,
11922 sizeof(*data
) - sizeof(data
->id
) - sizeof(data
->index
));
11925 case VKI_V4L2_G_INPUT
: {
11926 int *data
= (int *)(Addr
)ARG3
;
11927 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11930 case VKI_V4L2_G_EDID
: {
11931 struct vki_v4l2_edid
*data
= (struct vki_v4l2_edid
*)(Addr
)ARG3
;
11932 if (data
->blocks
&& data
->edid
)
11933 POST_MEM_WRITE((Addr
)data
->edid
, data
->blocks
* 128);
11936 case VKI_V4L2_G_OUTPUT
: {
11937 int *data
= (int *)(Addr
)ARG3
;
11938 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11941 case VKI_V4L2_ENUMOUTPUT
: {
11942 struct vki_v4l2_output
*data
= (struct vki_v4l2_output
*)(Addr
)ARG3
;
11943 POST_MEM_WRITE((Addr
)data
->name
, sizeof(*data
) - sizeof(data
->index
));
11946 case VKI_V4L2_G_AUDOUT
: {
11947 struct vki_v4l2_audioout
*data
= (struct vki_v4l2_audioout
*)(Addr
)ARG3
;
11948 POST_MEM_WRITE((Addr
)data
,
11949 sizeof(*data
) - sizeof(data
->reserved
));
11952 case VKI_V4L2_G_MODULATOR
: {
11953 struct vki_v4l2_modulator
*data
= (struct vki_v4l2_modulator
*)(Addr
)ARG3
;
11954 POST_MEM_WRITE((Addr
)data
->name
,
11955 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
11958 case VKI_V4L2_G_FREQUENCY
: {
11959 struct vki_v4l2_frequency
*data
= (struct vki_v4l2_frequency
*)(Addr
)ARG3
;
11960 POST_FIELD_WRITE(data
->type
);
11961 POST_FIELD_WRITE(data
->frequency
);
11964 case VKI_V4L2_CROPCAP
: {
11965 struct vki_v4l2_cropcap
*data
= (struct vki_v4l2_cropcap
*)(Addr
)ARG3
;
11966 POST_MEM_WRITE((Addr
)&data
->bounds
, sizeof(*data
) - sizeof(data
->type
));
11969 case VKI_V4L2_G_CROP
: {
11970 struct vki_v4l2_crop
*data
= (struct vki_v4l2_crop
*)(Addr
)ARG3
;
11971 POST_FIELD_WRITE(data
->c
);
11974 case VKI_V4L2_G_JPEGCOMP
: {
11975 struct vki_v4l2_jpegcompression
*data
=
11976 (struct vki_v4l2_jpegcompression
*)(Addr
)ARG3
;
11977 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11980 case VKI_V4L2_QUERYSTD
: {
11981 vki_v4l2_std_id
*data
= (vki_v4l2_std_id
*)(Addr
)ARG3
;
11982 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11985 case VKI_V4L2_ENUMAUDIO
: {
11986 struct vki_v4l2_audio
*data
= (struct vki_v4l2_audio
*)(Addr
)ARG3
;
11987 POST_MEM_WRITE((Addr
)data
->name
,
11988 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
11991 case VKI_V4L2_ENUMAUDOUT
: {
11992 struct vki_v4l2_audioout
*data
= (struct vki_v4l2_audioout
*)(Addr
)ARG3
;
11993 POST_MEM_WRITE((Addr
)data
->name
,
11994 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
11997 case VKI_V4L2_G_PRIORITY
: {
11998 __vki_u32
*data
= (__vki_u32
*)(Addr
)ARG3
;
11999 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12002 case VKI_V4L2_G_SLICED_VBI_CAP
: {
12003 struct vki_v4l2_sliced_vbi_cap
*data
=
12004 (struct vki_v4l2_sliced_vbi_cap
*)(Addr
)ARG3
;
12005 POST_MEM_WRITE((Addr
)data
,
12006 sizeof(*data
) - sizeof(data
->type
) - sizeof(data
->reserved
));
12009 case VKI_V4L2_G_EXT_CTRLS
: {
12010 struct vki_v4l2_ext_controls
*data
=
12011 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
12015 for (i
= 0; i
< data
->count
; i
++) {
12016 if (data
->controls
[i
].size
)
12017 POST_MEM_WRITE((Addr
)data
->controls
[i
].ptr
, data
->controls
[i
].size
);
12019 POST_FIELD_WRITE(data
->controls
[i
].value64
);
12022 POST_FIELD_WRITE(data
->error_idx
);
12025 case VKI_V4L2_S_EXT_CTRLS
: {
12026 struct vki_v4l2_ext_controls
*data
=
12027 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
12028 POST_FIELD_WRITE(data
->error_idx
);
12031 case VKI_V4L2_TRY_EXT_CTRLS
: {
12032 struct vki_v4l2_ext_controls
*data
=
12033 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
12034 POST_FIELD_WRITE(data
->error_idx
);
12037 case VKI_V4L2_ENUM_FRAMESIZES
: {
12038 struct vki_v4l2_frmsizeenum
*data
=
12039 (struct vki_v4l2_frmsizeenum
*)(Addr
)ARG3
;
12040 POST_FIELD_WRITE(data
->type
);
12041 POST_FIELD_WRITE(data
->stepwise
);
12044 case VKI_V4L2_ENUM_FRAMEINTERVALS
: {
12045 struct vki_v4l2_frmivalenum
*data
=
12046 (struct vki_v4l2_frmivalenum
*)(Addr
)ARG3
;
12047 POST_FIELD_WRITE(data
->type
);
12048 POST_FIELD_WRITE(data
->stepwise
);
12051 case VKI_V4L2_G_ENC_INDEX
: {
12052 struct vki_v4l2_enc_idx
*data
= (struct vki_v4l2_enc_idx
*)(Addr
)ARG3
;
12053 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12056 case VKI_V4L2_ENCODER_CMD
: {
12057 struct vki_v4l2_encoder_cmd
*data
=
12058 (struct vki_v4l2_encoder_cmd
*)(Addr
)ARG3
;
12059 POST_FIELD_WRITE(data
->flags
);
12062 case VKI_V4L2_TRY_ENCODER_CMD
: {
12063 struct vki_v4l2_encoder_cmd
*data
=
12064 (struct vki_v4l2_encoder_cmd
*)(Addr
)ARG3
;
12065 POST_FIELD_WRITE(data
->flags
);
12068 case VKI_V4L2_DBG_S_REGISTER
: {
12069 struct vki_v4l2_dbg_register
*data
=
12070 (struct vki_v4l2_dbg_register
*)(Addr
)ARG3
;
12071 POST_FIELD_WRITE(data
->size
);
12074 case VKI_V4L2_DBG_G_REGISTER
: {
12075 struct vki_v4l2_dbg_register
*data
=
12076 (struct vki_v4l2_dbg_register
*)(Addr
)ARG3
;
12077 POST_FIELD_WRITE(data
->val
);
12078 POST_FIELD_WRITE(data
->size
);
12081 case VKI_V4L2_G_DV_TIMINGS
: {
12082 struct vki_v4l2_dv_timings
*data
=
12083 (struct vki_v4l2_dv_timings
*)(Addr
)ARG3
;
12084 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12087 case VKI_V4L2_DQEVENT
: {
12088 struct vki_v4l2_event
*data
= (struct vki_v4l2_event
*)(Addr
)ARG3
;
12089 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12092 case VKI_V4L2_CREATE_BUFS
: {
12093 struct vki_v4l2_create_buffers
*data
=
12094 (struct vki_v4l2_create_buffers
*)(Addr
)ARG3
;
12095 POST_FIELD_WRITE(data
->index
);
12098 case VKI_V4L2_G_SELECTION
: {
12099 struct vki_v4l2_selection
*data
=
12100 (struct vki_v4l2_selection
*)(Addr
)ARG3
;
12101 POST_FIELD_WRITE(data
->r
);
12104 case VKI_V4L2_S_SELECTION
: {
12105 struct vki_v4l2_selection
*data
= (struct vki_v4l2_selection
*)(Addr
)ARG3
;
12106 POST_FIELD_WRITE(data
->r
);
12109 case VKI_V4L2_DECODER_CMD
: {
12110 struct vki_v4l2_decoder_cmd
*data
=
12111 (struct vki_v4l2_decoder_cmd
*)(Addr
)ARG3
;
12112 POST_FIELD_WRITE(data
->flags
);
12115 case VKI_V4L2_TRY_DECODER_CMD
: {
12116 struct vki_v4l2_decoder_cmd
*data
=
12117 (struct vki_v4l2_decoder_cmd
*)(Addr
)ARG3
;
12118 POST_FIELD_WRITE(data
->flags
);
12121 case VKI_V4L2_ENUM_DV_TIMINGS
: {
12122 struct vki_v4l2_enum_dv_timings
*data
=
12123 (struct vki_v4l2_enum_dv_timings
*)(Addr
)ARG3
;
12124 POST_FIELD_WRITE(data
->timings
);
12127 case VKI_V4L2_QUERY_DV_TIMINGS
: {
12128 struct vki_v4l2_dv_timings
*data
=
12129 (struct vki_v4l2_dv_timings
*)(Addr
)ARG3
;
12130 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12133 case VKI_V4L2_DV_TIMINGS_CAP
: {
12134 struct vki_v4l2_dv_timings_cap
*data
=
12135 (struct vki_v4l2_dv_timings_cap
*)(Addr
)ARG3
;
12136 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12139 case VKI_V4L2_ENUM_FREQ_BANDS
: {
12140 struct vki_v4l2_frequency_band
*data
=
12141 (struct vki_v4l2_frequency_band
*)(Addr
)ARG3
;
12142 POST_FIELD_WRITE(data
->capability
);
12143 POST_FIELD_WRITE(data
->rangelow
);
12144 POST_FIELD_WRITE(data
->rangehigh
);
12145 POST_FIELD_WRITE(data
->modulation
);
12148 case VKI_V4L2_DBG_G_CHIP_INFO
: {
12149 struct vki_v4l2_dbg_chip_info
*data
=
12150 (struct vki_v4l2_dbg_chip_info
*)(Addr
)ARG3
;
12151 POST_FIELD_WRITE(data
->name
);
12152 POST_FIELD_WRITE(data
->flags
);
12155 case VKI_V4L2_QUERY_EXT_CTRL
: {
12156 struct vki_v4l2_query_ext_ctrl
*data
=
12157 (struct vki_v4l2_query_ext_ctrl
*)(Addr
)ARG3
;
12158 POST_MEM_WRITE((Addr
)&data
->type
,
12159 sizeof(*data
) - sizeof(data
->id
) - sizeof(data
->reserved
));
12163 case VKI_V4L2_SUBDEV_S_FMT
:
12164 case VKI_V4L2_SUBDEV_S_FRAME_INTERVAL
:
12165 case VKI_V4L2_SUBDEV_S_CROP
:
12166 case VKI_V4L2_SUBDEV_S_SELECTION
:
12169 case VKI_V4L2_SUBDEV_G_FMT
: {
12170 struct vki_v4l2_subdev_format
*data
=
12171 (struct vki_v4l2_subdev_format
*)(Addr
)ARG3
;
12172 POST_FIELD_WRITE(data
->format
);
12175 case VKI_V4L2_SUBDEV_G_FRAME_INTERVAL
: {
12176 struct vki_v4l2_subdev_frame_interval
*data
=
12177 (struct vki_v4l2_subdev_frame_interval
*)(Addr
)ARG3
;
12178 POST_FIELD_WRITE(data
->interval
);
12181 case VKI_V4L2_SUBDEV_ENUM_MBUS_CODE
: {
12182 struct vki_v4l2_subdev_mbus_code_enum
*data
=
12183 (struct vki_v4l2_subdev_mbus_code_enum
*)(Addr
)ARG3
;
12184 POST_FIELD_WRITE(data
->code
);
12187 case VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE
: {
12188 struct vki_v4l2_subdev_frame_size_enum
*data
=
12189 (struct vki_v4l2_subdev_frame_size_enum
*)(Addr
)ARG3
;
12190 POST_FIELD_WRITE(data
->min_width
);
12191 POST_FIELD_WRITE(data
->min_height
);
12192 POST_FIELD_WRITE(data
->max_width
);
12193 POST_FIELD_WRITE(data
->max_height
);
12196 case VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL
: {
12197 struct vki_v4l2_subdev_frame_interval_enum
*data
=
12198 (struct vki_v4l2_subdev_frame_interval_enum
*)(Addr
)ARG3
;
12199 POST_FIELD_WRITE(data
->interval
);
12202 case VKI_V4L2_SUBDEV_G_CROP
: {
12203 struct vki_v4l2_subdev_crop
*data
=
12204 (struct vki_v4l2_subdev_crop
*)(Addr
)ARG3
;
12205 POST_FIELD_WRITE(data
->rect
);
12208 case VKI_V4L2_SUBDEV_G_SELECTION
: {
12209 struct vki_v4l2_subdev_selection
*data
=
12210 (struct vki_v4l2_subdev_selection
*)(Addr
)ARG3
;
12211 POST_FIELD_WRITE(data
->r
);
12214 case VKI_MEDIA_IOC_DEVICE_INFO
: {
12215 struct vki_media_device_info
*data
=
12216 (struct vki_media_device_info
*)(Addr
)ARG3
;
12217 POST_MEM_WRITE((Addr
)data
, sizeof(*data
) - sizeof(data
->reserved
));
12220 case VKI_MEDIA_IOC_ENUM_ENTITIES
: {
12221 struct vki_media_entity_desc
*data
=
12222 (struct vki_media_entity_desc
*)(Addr
)ARG3
;
12223 POST_MEM_WRITE((Addr
)data
->name
, sizeof(*data
) - sizeof(data
->id
));
12226 case VKI_MEDIA_IOC_ENUM_LINKS
:
12228 * This ioctl does write to the provided pointers, but it's not
12229 * possible to deduce the size of the array those pointers point to.
12232 case VKI_MEDIA_IOC_SETUP_LINK
:
12236 case VKI_TIOCGSERIAL
: {
12237 struct vki_serial_struct
*data
= (struct vki_serial_struct
*)(Addr
)ARG3
;
12238 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12241 case VKI_TIOCSSERIAL
:
12244 case VKI_PERF_EVENT_IOC_ENABLE
:
12245 case VKI_PERF_EVENT_IOC_DISABLE
:
12246 case VKI_PERF_EVENT_IOC_REFRESH
:
12247 case VKI_PERF_EVENT_IOC_RESET
:
12248 case VKI_PERF_EVENT_IOC_PERIOD
:
12249 case VKI_PERF_EVENT_IOC_SET_OUTPUT
:
12250 case VKI_PERF_EVENT_IOC_SET_FILTER
:
12251 case VKI_PERF_EVENT_IOC_SET_BPF
:
12254 case VKI_PERF_EVENT_IOC_ID
:
12255 POST_MEM_WRITE((Addr
)ARG3
, sizeof(__vki_u64
));
12258 /* Pulse Per Second (PPS) */
12259 case VKI_PPS_GETPARAMS
: {
12260 struct vki_pps_kparams
*data
= (struct vki_pps_kparams
*)(Addr
)ARG3
;
12261 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12264 case VKI_PPS_GETCAP
:
12265 POST_MEM_WRITE((Addr
)ARG3
, sizeof(int));
12267 case VKI_PPS_FETCH
: {
12268 struct vki_pps_fdata
*data
= (struct vki_pps_fdata
*)(Addr
)ARG3
;
12269 POST_FIELD_WRITE(data
->info
);
12272 case VKI_PPS_SETPARAMS
:
12273 case VKI_PPS_KC_BIND
:
12276 /* PTP Hardware Clock */
12277 case VKI_PTP_CLOCK_GETCAPS
: {
12278 struct vki_ptp_clock_caps
*data
=
12279 (struct vki_ptp_clock_caps
*)(Addr
)ARG3
;
12280 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12283 case VKI_PTP_SYS_OFFSET
: {
12284 struct vki_ptp_sys_offset
*data
=
12285 (struct vki_ptp_sys_offset
*)(Addr
)ARG3
;
12286 POST_MEM_WRITE((Addr
)data
->ts
,
12287 (2 * data
->n_samples
+ 1) * sizeof(data
->ts
[0]));
12290 case VKI_PTP_PIN_GETFUNC
: {
12291 struct vki_ptp_pin_desc
*data
= (struct vki_ptp_pin_desc
*)(Addr
)ARG3
;
12292 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12295 case VKI_PTP_SYS_OFFSET_PRECISE
: {
12296 struct vki_ptp_sys_offset_precise
*data
=
12297 (struct vki_ptp_sys_offset_precise
*)(Addr
)ARG3
;
12298 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
12301 case VKI_PTP_SYS_OFFSET_EXTENDED
: {
12302 struct vki_ptp_sys_offset_extended
*data
=
12303 (struct vki_ptp_sys_offset_extended
*)(Addr
)ARG3
;
12304 POST_MEM_WRITE((Addr
)data
->ts
,
12305 3 * data
->n_samples
* sizeof(data
->ts
[0][0]));
12308 case VKI_PTP_EXTTS_REQUEST
:
12309 case VKI_PTP_PEROUT_REQUEST
:
12310 case VKI_PTP_ENABLE_PPS
:
12311 case VKI_PTP_PIN_SETFUNC
:
12315 /* EVIOC* are variable length and return size written on success */
12316 switch (ARG2
& ~(_VKI_IOC_SIZEMASK
<< _VKI_IOC_SIZESHIFT
)) {
12317 case VKI_EVIOCGNAME(0):
12318 case VKI_EVIOCGPHYS(0):
12319 case VKI_EVIOCGUNIQ(0):
12320 case VKI_EVIOCGKEY(0):
12321 case VKI_EVIOCGLED(0):
12322 case VKI_EVIOCGSND(0):
12323 case VKI_EVIOCGSW(0):
12324 case VKI_EVIOCGBIT(VKI_EV_SYN
,0):
12325 case VKI_EVIOCGBIT(VKI_EV_KEY
,0):
12326 case VKI_EVIOCGBIT(VKI_EV_REL
,0):
12327 case VKI_EVIOCGBIT(VKI_EV_ABS
,0):
12328 case VKI_EVIOCGBIT(VKI_EV_MSC
,0):
12329 case VKI_EVIOCGBIT(VKI_EV_SW
,0):
12330 case VKI_EVIOCGBIT(VKI_EV_LED
,0):
12331 case VKI_EVIOCGBIT(VKI_EV_SND
,0):
12332 case VKI_EVIOCGBIT(VKI_EV_REP
,0):
12333 case VKI_EVIOCGBIT(VKI_EV_FF
,0):
12334 case VKI_EVIOCGBIT(VKI_EV_PWR
,0):
12335 case VKI_EVIOCGBIT(VKI_EV_FF_STATUS
,0):
12337 POST_MEM_WRITE(ARG3
, RES
);
12340 ML_(POST_unknown_ioctl
)(tid
, RES
, ARG2
, ARG3
);
12346 post_sys_ioctl__out
:
12347 {} /* keep C compilers happy */
12350 /* ---------------------------------------------------------------------
12351 socketcall wrapper helpers
12352 ------------------------------------------------------------------ */
12355 ML_(linux_PRE_sys_getsockopt
) ( ThreadId tid
,
12356 UWord arg0
, UWord arg1
, UWord arg2
,
12357 UWord arg3
, UWord arg4
)
12359 /* int getsockopt(int s, int level, int optname,
12360 void *optval, socklen_t *optlen); */
12361 Addr optval_p
= arg3
;
12362 Addr optlen_p
= arg4
;
12363 /* vg_assert(sizeof(socklen_t) == sizeof(UInt)); */
12364 if (optval_p
!= (Addr
)NULL
) {
12365 ML_(buf_and_len_pre_check
) ( tid
, optval_p
, optlen_p
,
12366 "socketcall.getsockopt(optval)",
12367 "socketcall.getsockopt(optlen)" );
12368 if (arg1
== VKI_SOL_SCTP
&&
12369 (arg2
== VKI_SCTP_GET_PEER_ADDRS
||
12370 arg2
== VKI_SCTP_GET_LOCAL_ADDRS
))
12372 struct vki_sctp_getaddrs
*ga
= (struct vki_sctp_getaddrs
*)arg3
;
12373 int address_bytes
= sizeof(struct vki_sockaddr_in6
) * ga
->addr_num
;
12374 PRE_MEM_WRITE( "socketcall.getsockopt(optval.addrs)",
12375 (Addr
)ga
->addrs
, address_bytes
);
12381 ML_(linux_POST_sys_getsockopt
) ( ThreadId tid
,
12383 UWord arg0
, UWord arg1
, UWord arg2
,
12384 UWord arg3
, UWord arg4
)
12386 Addr optval_p
= arg3
;
12387 Addr optlen_p
= arg4
;
12388 vg_assert(!sr_isError(res
)); /* guaranteed by caller */
12389 if (optval_p
!= (Addr
)NULL
) {
12390 ML_(buf_and_len_post_check
) ( tid
, res
, optval_p
, optlen_p
,
12391 "socketcall.getsockopt(optlen_out)" );
12392 if (arg1
== VKI_SOL_SCTP
&&
12393 (arg2
== VKI_SCTP_GET_PEER_ADDRS
||
12394 arg2
== VKI_SCTP_GET_LOCAL_ADDRS
))
12396 struct vki_sctp_getaddrs
*ga
= (struct vki_sctp_getaddrs
*)arg3
;
12397 struct vki_sockaddr
*a
= ga
->addrs
;
12399 for (i
= 0; i
< ga
->addr_num
; i
++) {
12401 if (a
->sa_family
== VKI_AF_INET
)
12402 sl
= sizeof(struct vki_sockaddr_in
);
12403 else if (a
->sa_family
== VKI_AF_INET6
)
12404 sl
= sizeof(struct vki_sockaddr_in6
);
12406 VG_(message
)(Vg_UserMsg
, "Warning: getsockopt: unhandled "
12407 "address type %d\n", a
->sa_family
);
12409 a
= (struct vki_sockaddr
*)((char*)a
+ sl
);
12411 POST_MEM_WRITE( (Addr
)ga
->addrs
, (char*)a
- (char*)ga
->addrs
);
12417 ML_(linux_PRE_sys_setsockopt
) ( ThreadId tid
,
12418 UWord arg0
, UWord arg1
, UWord arg2
,
12419 UWord arg3
, UWord arg4
)
12421 /* int setsockopt(int s, int level, int optname,
12422 const void *optval, socklen_t optlen); */
12423 Addr optval_p
= arg3
;
12424 if (optval_p
!= (Addr
)NULL
) {
12426 * OK, let's handle at least some setsockopt levels and options
12427 * ourselves, so we don't get false claims of references to
12428 * uninitialized memory (such as padding in structures) and *do*
12429 * check what pointers in the argument point to.
12431 if (arg1
== VKI_SOL_SOCKET
&& arg2
== VKI_SO_ATTACH_FILTER
)
12433 struct vki_sock_fprog
*fp
= (struct vki_sock_fprog
*)optval_p
;
12436 * struct sock_fprog has a 16-bit count of instructions,
12437 * followed by a pointer to an array of those instructions.
12438 * There's padding between those two elements.
12440 * So that we don't bogusly complain about the padding bytes,
12441 * we just report that we read len and and filter.
12443 * We then make sure that what filter points to is valid.
12445 PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, &optval.len)",
12446 (Addr
)&fp
->len
, sizeof(fp
->len
) );
12447 PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, &optval.filter)",
12448 (Addr
)&fp
->filter
, sizeof(fp
->filter
) );
12450 /* len * sizeof (*filter) */
12451 if (fp
->filter
!= NULL
)
12453 PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, optval.filter)",
12454 (Addr
)(fp
->filter
),
12455 fp
->len
* sizeof(*fp
->filter
) );
12460 PRE_MEM_READ( "socketcall.setsockopt(optval)",
12462 arg4
/* optlen */ );
12468 ML_(linux_PRE_sys_recvmmsg
) ( ThreadId tid
,
12469 UWord arg1
, UWord arg2
, UWord arg3
,
12470 UWord arg4
, UWord arg5
)
12472 struct vki_mmsghdr
*mmsg
= (struct vki_mmsghdr
*)arg2
;
12473 HChar name
[40]; // large enough
12475 for (i
= 0; i
< arg3
; i
++) {
12476 VG_(sprintf
)(name
, "mmsg[%u].msg_hdr", i
);
12477 ML_(generic_PRE_sys_recvmsg
)(tid
, name
, &mmsg
[i
].msg_hdr
);
12478 VG_(sprintf
)(name
, "recvmmsg(mmsg[%u].msg_len)", i
);
12479 PRE_MEM_WRITE( name
, (Addr
)&mmsg
[i
].msg_len
, sizeof(mmsg
[i
].msg_len
) );
12482 PRE_MEM_READ( "recvmmsg(timeout)", arg5
, sizeof(struct vki_timespec
) );
12486 ML_(linux_POST_sys_recvmmsg
) (ThreadId tid
, UWord res
,
12487 UWord arg1
, UWord arg2
, UWord arg3
,
12488 UWord arg4
, UWord arg5
)
12491 struct vki_mmsghdr
*mmsg
= (struct vki_mmsghdr
*)arg2
;
12492 HChar name
[32]; // large enough
12494 for (i
= 0; i
< res
; i
++) {
12495 VG_(sprintf
)(name
, "mmsg[%u].msg_hdr", i
);
12496 ML_(generic_POST_sys_recvmsg
)(tid
, name
, &mmsg
[i
].msg_hdr
, mmsg
[i
].msg_len
);
12497 POST_MEM_WRITE( (Addr
)&mmsg
[i
].msg_len
, sizeof(mmsg
[i
].msg_len
) );
12503 ML_(linux_PRE_sys_sendmmsg
) ( ThreadId tid
,
12504 UWord arg1
, UWord arg2
, UWord arg3
, UWord arg4
)
12506 struct vki_mmsghdr
*mmsg
= (struct vki_mmsghdr
*)arg2
;
12507 HChar name
[40]; // large enough
12509 for (i
= 0; i
< arg3
; i
++) {
12510 VG_(sprintf
)(name
, "mmsg[%u].msg_hdr", i
);
12511 ML_(generic_PRE_sys_sendmsg
)(tid
, name
, &mmsg
[i
].msg_hdr
);
12512 VG_(sprintf
)(name
, "sendmmsg(mmsg[%u].msg_len)", i
);
12513 PRE_MEM_WRITE( name
, (Addr
)&mmsg
[i
].msg_len
, sizeof(mmsg
[i
].msg_len
) );
12518 ML_(linux_POST_sys_sendmmsg
) (ThreadId tid
, UWord res
,
12519 UWord arg1
, UWord arg2
, UWord arg3
, UWord arg4
)
12522 struct vki_mmsghdr
*mmsg
= (struct vki_mmsghdr
*)arg2
;
12524 for (i
= 0; i
< res
; i
++) {
12525 POST_MEM_WRITE( (Addr
)&mmsg
[i
].msg_len
, sizeof(mmsg
[i
].msg_len
) );
12530 /* ---------------------------------------------------------------------
12531 ptrace wrapper helpers
12532 ------------------------------------------------------------------ */
12535 ML_(linux_POST_traceme
) ( ThreadId tid
)
12537 ThreadState
*tst
= VG_(get_ThreadState
)(tid
);
12538 tst
->ptrace
= VKI_PT_PTRACED
;
12542 ML_(linux_PRE_getregset
) ( ThreadId tid
, long arg3
, long arg4
)
12544 struct vki_iovec
*iov
= (struct vki_iovec
*) arg4
;
12546 PRE_FIELD_READ("ptrace(getregset iovec->iov_base)", iov
->iov_base
);
12547 PRE_FIELD_READ("ptrace(getregset iovec->iov_len)", iov
->iov_len
);
12548 if (ML_(safe_to_deref
)(iov
, sizeof(struct vki_iovec
))) {
12549 PRE_MEM_WRITE("ptrace(getregset *(iovec->iov_base))",
12550 (Addr
) iov
->iov_base
, iov
->iov_len
);
12555 ML_(linux_PRE_setregset
) ( ThreadId tid
, long arg3
, long arg4
)
12557 struct vki_iovec
*iov
= (struct vki_iovec
*) arg4
;
12559 PRE_FIELD_READ("ptrace(setregset iovec->iov_base)", iov
->iov_base
);
12560 PRE_FIELD_READ("ptrace(setregset iovec->iov_len)", iov
->iov_len
);
12561 if (ML_(safe_to_deref
)(iov
, sizeof(struct vki_iovec
))) {
12562 PRE_MEM_READ("ptrace(setregset *(iovec->iov_base))",
12563 (Addr
) iov
->iov_base
, iov
->iov_len
);
12568 ML_(linux_POST_getregset
) ( ThreadId tid
, long arg3
, long arg4
)
12570 struct vki_iovec
*iov
= (struct vki_iovec
*) arg4
;
12572 /* XXX: The actual amount of data written by the kernel might be
12573 less than iov_len, depending on the regset (arg3). */
12574 POST_MEM_WRITE((unsigned long) iov
->iov_base
, iov
->iov_len
);
12579 PRINT("kcmp ( %ld, %ld, %ld, %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )",
12580 SARG1
, SARG2
, SARG3
, ARG4
, ARG5
);
12582 case VKI_KCMP_VM
: case VKI_KCMP_FILES
: case VKI_KCMP_FS
:
12583 case VKI_KCMP_SIGHAND
: case VKI_KCMP_IO
: case VKI_KCMP_SYSVSEM
:
12584 /* Most of the comparison types don't look at |idx1| or
12586 PRE_REG_READ3(long, "kcmp",
12587 vki_pid_t
, pid1
, vki_pid_t
, pid2
, int, type
);
12589 case VKI_KCMP_FILE
:
12591 PRE_REG_READ5(long, "kcmp",
12592 vki_pid_t
, pid1
, vki_pid_t
, pid2
, int, type
,
12593 unsigned long, idx1
, unsigned long, idx2
);
12598 /* ---------------------------------------------------------------------
12600 ------------------------------------------------------------------ */
12602 static Bool
bpf_map_get_sizes(Int fd
, UInt
*key_size
, UInt
*value_size
)
12604 HChar path
[32], buf
[1024]; /* large enough */
12612 VG_(sprintf
)(path
, "/proc/%d/fdinfo/%d", VG_(getpid
)(), fd
);
12613 sres
= VG_(open
)(path
, VKI_O_RDONLY
, 0);
12614 if (sr_isError(sres
))
12616 proc_fd
= sr_Res(sres
);
12618 if (VG_(read
)(proc_fd
, buf
, sizeof(buf
)) <= 0)
12620 VG_(close
)(proc_fd
);
12622 comp
= VG_(strstr
)(buf
, "key_size:");
12624 *key_size
= VG_(strtoull10
)(comp
+ sizeof("key_size:"), NULL
);
12626 comp
= VG_(strstr
)(buf
, "value_size:");
12628 *value_size
= VG_(strtoull10
)(comp
+ sizeof("value_size:"), NULL
);
12630 return (*key_size
&& *value_size
);
12634 * From a file descriptor for an eBPF object, try to determine the size of the
12635 * struct that will be written, i.e. determine if object is a map or a program.
12636 * There is no direct way to do this, so parse /proc/<pid>/fdinfo/<fd> and
12637 * search for strings "prog_type" or "map_type".
12639 static UInt
bpf_obj_get_info_size(Int fd
)
12641 HChar path
[32], buf
[1024]; /* large enough */
12645 VG_(sprintf
)(path
, "/proc/%d/fdinfo/%d", VG_(getpid
)(), fd
);
12646 sres
= VG_(open
)(path
, VKI_O_RDONLY
, 0);
12647 if (sr_isError(sres
))
12649 proc_fd
= sr_Res(sres
);
12651 if (VG_(read
)(proc_fd
, buf
, sizeof(buf
)) <= 0)
12653 VG_(close
)(proc_fd
);
12655 if (VG_(strstr
)(buf
, "prog_type:"))
12656 return sizeof(struct vki_bpf_prog_info
);
12658 if (VG_(strstr
)(buf
, "map_type:"))
12659 return sizeof(struct vki_bpf_map_info
);
12666 union vki_bpf_attr
*attr
= (union vki_bpf_attr
*)(Addr
)ARG2
;
12667 UInt res
, key_size
, value_size
;
12669 PRINT("sys_bpf ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
12670 (Word
)ARG1
, ARG2
, ARG3
);
12671 PRE_REG_READ3(long, "bpf",
12672 int, cmd
, union vki_bpf_attr
*, attr
, unsigned int, size
);
12674 case VKI_BPF_PROG_GET_NEXT_ID
:
12675 case VKI_BPF_MAP_GET_NEXT_ID
:
12676 PRE_MEM_WRITE("bpf(attr->next_id", (Addr
)&attr
->next_id
, sizeof(attr
->next_id
));
12678 case VKI_BPF_PROG_GET_FD_BY_ID
:
12679 PRE_MEM_READ("bpf(attr->prog_id", (Addr
)&attr
->prog_id
, sizeof(attr
->prog_id
));
12681 case VKI_BPF_MAP_GET_FD_BY_ID
:
12682 PRE_MEM_READ("bpf(attr->map_id", (Addr
)&attr
->map_id
, sizeof(attr
->map_id
));
12684 case VKI_BPF_BTF_GET_FD_BY_ID
:
12685 PRE_MEM_READ("bpf(attr->btf_id", (Addr
)&attr
->btf_id
, sizeof(attr
->btf_id
));
12687 case VKI_BPF_MAP_CREATE
:
12688 PRE_MEM_READ("bpf(attr->map_flags", (Addr
)&attr
->map_flags
, sizeof(attr
->map_flags
));
12689 if (attr
->map_flags
& VKI_BPF_F_NUMA_NODE
)
12690 PRE_MEM_READ("bpf(attr->numa_node", (Addr
)&attr
->numa_node
, sizeof(attr
->numa_node
));
12691 PRE_MEM_READ("bpf(attr->map_type", (Addr
)&attr
->map_type
, sizeof(attr
->map_type
));
12692 PRE_MEM_READ("bpf(attr->map_ifindex", (Addr
)&attr
->map_ifindex
, sizeof(attr
->map_ifindex
));
12693 PRE_MEM_READ("bpf(attr->max_entries", (Addr
)&attr
->max_entries
, sizeof(attr
->max_entries
));
12694 PRE_MEM_READ("bpf(attr->key_size", (Addr
)&attr
->key_size
, sizeof(attr
->key_size
));
12695 PRE_MEM_READ("bpf(attr->value_size", (Addr
)&attr
->value_size
, sizeof(attr
->value_size
));
12696 pre_asciiz_str(tid
, (unsigned long int)attr
->map_name
,
12697 VKI_BPF_OBJ_NAME_LEN
, "bpf(attr->map_name)");
12698 switch (attr
->map_type
) {
12699 case VKI_BPF_MAP_TYPE_ARRAY_OF_MAPS
:
12700 case VKI_BPF_MAP_TYPE_HASH_OF_MAPS
:
12701 PRE_MEM_READ("bpf(attr->inner_map_fd", (Addr
)&attr
->inner_map_fd
, sizeof(attr
->inner_map_fd
));
12702 if (!ML_(fd_allowed
)(attr
->inner_map_fd
, "bpf", tid
, False
))
12703 SET_STATUS_Failure(VKI_EBADF
);
12705 case VKI_BPF_MAP_TYPE_ARRAY
:
12706 if (ARG3
>= offsetof(union vki_bpf_attr
, btf_value_type_id
) + sizeof(__vki_u32
)) {
12707 PRE_MEM_READ("bpf(attr->btf_key_type_id", (Addr
)&attr
->btf_key_type_id
, sizeof(attr
->btf_key_type_id
));
12708 PRE_MEM_READ("bpf(attr->btf_value_type_id", (Addr
)&attr
->btf_value_type_id
, sizeof(attr
->btf_value_type_id
));
12709 if (attr
->btf_key_type_id
&& attr
->btf_value_type_id
) {
12710 PRE_MEM_READ("bpf(attr->btf_id", (Addr
)&attr
->btf_id
, sizeof(attr
->btf_id
));
12711 if (!ML_(fd_allowed
)(attr
->btf_fd
, "bpf", tid
, False
)) {
12712 SET_STATUS_Failure(VKI_EBADF
);
12718 case VKI_BPF_MAP_TYPE_UNSPEC
:
12719 case VKI_BPF_MAP_TYPE_HASH
:
12720 case VKI_BPF_MAP_TYPE_PROG_ARRAY
:
12721 case VKI_BPF_MAP_TYPE_PERF_EVENT_ARRAY
:
12722 case VKI_BPF_MAP_TYPE_PERCPU_HASH
:
12723 case VKI_BPF_MAP_TYPE_PERCPU_ARRAY
:
12724 case VKI_BPF_MAP_TYPE_STACK_TRACE
:
12725 case VKI_BPF_MAP_TYPE_CGROUP_ARRAY
:
12726 case VKI_BPF_MAP_TYPE_LRU_HASH
:
12727 case VKI_BPF_MAP_TYPE_LRU_PERCPU_HASH
:
12728 case VKI_BPF_MAP_TYPE_LPM_TRIE
:
12729 case VKI_BPF_MAP_TYPE_DEVMAP
:
12730 case VKI_BPF_MAP_TYPE_SOCKMAP
:
12731 case VKI_BPF_MAP_TYPE_CPUMAP
:
12732 case VKI_BPF_MAP_TYPE_XSKMAP
:
12733 case VKI_BPF_MAP_TYPE_SOCKHASH
:
12738 case VKI_BPF_MAP_LOOKUP_ELEM
:
12739 /* Perform a lookup on an eBPF map. Read key, write value. */
12740 PRE_MEM_READ("bpf(attr->key)", (Addr
)&attr
->key
, sizeof(attr
->key
));
12741 PRE_MEM_READ("bpf(attr->value)", (Addr
)&attr
->value
, sizeof(attr
->value
));
12742 PRE_MEM_READ("bpf(attr->map_fd)", (Addr
)&attr
->map_fd
, sizeof(attr
->map_fd
));
12743 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12744 if (!ML_(fd_allowed
)(attr
->map_fd
, "bpf", tid
, False
)) {
12745 SET_STATUS_Failure(VKI_EBADF
);
12748 /* Get size of key and value for this map. */
12749 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
)) {
12750 PRE_MEM_READ("bpf(attr->key)", attr
->key
, key_size
);
12751 PRE_MEM_WRITE("bpf(attr->value)", attr
->value
, value_size
);
12755 case VKI_BPF_MAP_UPDATE_ELEM
:
12756 /* Add or update a map element in kernel. Read key, read value. */
12757 PRE_MEM_READ("bpf(attr->key)", (Addr
)&attr
->key
, sizeof(attr
->key
));
12758 PRE_MEM_READ("bpf(attr->value)", (Addr
)&attr
->value
, sizeof(attr
->value
));
12759 PRE_MEM_READ("bpf(attr->map_fd)", (Addr
)&attr
->map_fd
, sizeof(attr
->map_fd
));
12760 PRE_MEM_READ("bpf(attr->flags)", (Addr
)&attr
->flags
, sizeof(attr
->flags
));
12761 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12762 if (!ML_(fd_allowed
)(attr
->map_fd
, "bpf", tid
, False
)) {
12763 SET_STATUS_Failure(VKI_EBADF
);
12766 /* Get size of key and value for this map. */
12767 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
)) {
12768 PRE_MEM_READ("bpf(attr->key)", attr
->key
, key_size
);
12769 PRE_MEM_READ("bpf(attr->value)", attr
->value
, value_size
);
12773 case VKI_BPF_MAP_DELETE_ELEM
:
12774 /* Delete a map element in kernel. Read key from user space. */
12775 PRE_MEM_READ("bpf(attr->key)", (Addr
)&attr
->key
, sizeof(attr
->key
));
12776 PRE_MEM_READ("bpf(attr->map_fd)", (Addr
)&attr
->map_fd
, sizeof(attr
->map_fd
));
12777 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12778 if (!ML_(fd_allowed
)(attr
->map_fd
, "bpf", tid
, False
)) {
12779 SET_STATUS_Failure(VKI_EBADF
);
12782 /* Get size of key for this map. */
12783 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
))
12784 PRE_MEM_READ("bpf(attr->key)", attr
->key
, key_size
);
12787 case VKI_BPF_MAP_GET_NEXT_KEY
:
12788 /* From a key, get next key for the map. Read key, write next key. */
12789 PRE_MEM_READ("bpf(attr->key)", (Addr
)&attr
->key
, sizeof(attr
->key
));
12790 PRE_MEM_READ("bpf(attr->next_key)", (Addr
)&attr
->next_key
, sizeof(attr
->next_key
));
12791 PRE_MEM_READ("bpf(attr->map_fd)", (Addr
)&attr
->map_fd
, sizeof(attr
->map_fd
));
12792 PRE_MEM_READ("bpf(attr->flags)", (Addr
)&attr
->flags
, sizeof(attr
->flags
));
12793 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12794 if (!ML_(fd_allowed
)(attr
->map_fd
, "bpf", tid
, False
)) {
12795 SET_STATUS_Failure(VKI_EBADF
);
12798 /* Get size of key for this map. */
12799 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
)) {
12800 PRE_MEM_READ("bpf(attr->key)", attr
->key
, key_size
);
12801 PRE_MEM_WRITE("bpf(attr->next_key)", attr
->next_key
, key_size
);
12805 case VKI_BPF_PROG_LOAD
:
12806 /* Load a program into the kernel from an array of instructions. */
12807 PRE_MEM_READ("bpf(attr->prog_type)", (Addr
)&attr
->prog_type
, sizeof(attr
->prog_type
));
12808 PRE_MEM_READ("bpf(attr->prog_flags)", (Addr
)&attr
->prog_flags
, sizeof(attr
->prog_flags
));
12809 PRE_MEM_READ("bpf(attr->license)", (Addr
)&attr
->license
, sizeof(attr
->license
));
12810 PRE_MEM_READ("bpf(attr->insn_cnt)", (Addr
)&attr
->insn_cnt
, sizeof(attr
->insn_cnt
));
12811 PRE_MEM_READ("bpf(attr->expected_attach_type)", (Addr
)&attr
->expected_attach_type
, sizeof(attr
->expected_attach_type
));
12812 PRE_MEM_READ("bpf(attr->prog_ifindex)", (Addr
)&attr
->prog_ifindex
, sizeof(attr
->prog_ifindex
));
12813 PRE_MEM_READ("bpf(attr->log_level)", (Addr
)&attr
->log_level
, sizeof(attr
->log_level
));
12814 PRE_MEM_READ("bpf(attr->log_buf)", (Addr
)&attr
->log_buf
, sizeof(attr
->log_buf
));
12815 PRE_MEM_READ("bpf(attr->log_size)", (Addr
)&attr
->log_size
, sizeof(attr
->log_size
));
12816 pre_asciiz_str(tid
, (Addr
)attr
->prog_name
, VKI_BPF_OBJ_NAME_LEN
, "bpf(attr->prog_name)");
12817 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12818 if (attr
->prog_type
== VKI_BPF_PROG_TYPE_KPROBE
)
12819 PRE_MEM_READ("bpf(attr->kern_version)", (Addr
)&attr
->kern_version
, sizeof(attr
->kern_version
));
12820 /* Read instructions, license, program name. */
12821 PRE_MEM_READ("bpf(attr->insns)", attr
->insns
,
12822 attr
->insn_cnt
* sizeof(struct vki_bpf_insn
));
12823 /* License is limited to 128 characters in kernel/bpf/syscall.c. */
12824 pre_asciiz_str(tid
, attr
->license
, 128, "bpf(attr->license)");
12825 /* Possibly write up to log_len into user space log buffer. */
12826 if (attr
->log_level
|| attr
->log_size
|| attr
->log_buf
)
12827 PRE_MEM_WRITE("bpf(attr->log_buf)", attr
->log_buf
, attr
->log_size
);
12830 case VKI_BPF_OBJ_PIN
:
12831 /* Pin eBPF program or map to given location under /sys/fs/bpf/. */
12833 case VKI_BPF_OBJ_GET
:
12834 /* Get pinned eBPF program or map. Read path name. */
12835 PRE_MEM_READ("bpf(attr->file_flags)", (Addr
)&attr
->file_flags
, sizeof(attr
->file_flags
));
12836 PRE_MEM_READ("bpf(attr->pathname)", (Addr
)&attr
->pathname
, sizeof(attr
->pathname
));
12837 PRE_MEM_READ("bpf(attr->bpf_fd)", (Addr
)&attr
->bpf_fd
, sizeof(attr
->bpf_fd
));
12838 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12839 if (!ML_(fd_allowed
)(attr
->bpf_fd
, "bpf", tid
, False
)) {
12840 SET_STATUS_Failure(VKI_EBADF
);
12843 pre_asciiz_str(tid
, attr
->pathname
, VKI_BPF_OBJ_NAME_LEN
, "bpf(attr->pathname)");
12846 case VKI_BPF_PROG_ATTACH
:
12847 case VKI_BPF_PROG_DETACH
:
12848 /* Detach eBPF program from kernel attach point. */
12849 PRE_MEM_READ("bpf(attr->attach_type)", (Addr
)&attr
->attach_type
, sizeof(attr
->attach_type
));
12850 PRE_MEM_READ("bpf(attr->target_fd)", (Addr
)&attr
->target_fd
, sizeof(attr
->target_fd
));
12851 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12852 if (!ML_(fd_allowed
)(attr
->target_fd
, "bpf", tid
, False
))
12853 SET_STATUS_Failure(VKI_EBADF
);
12854 if (ARG1
== VKI_BPF_PROG_ATTACH
||
12855 (attr
->attach_type
!= VKI_BPF_SK_SKB_STREAM_PARSER
&&
12856 attr
->attach_type
!= VKI_BPF_SK_SKB_STREAM_VERDICT
&&
12857 attr
->attach_type
!= VKI_BPF_SK_MSG_VERDICT
)) {
12858 PRE_MEM_READ("bpf(attr->attach_bpf_fd)", (Addr
)&attr
->attach_bpf_fd
, sizeof(attr
->attach_bpf_fd
));
12859 if (!ML_(fd_allowed
)(attr
->attach_bpf_fd
, "bpf", tid
, False
))
12860 SET_STATUS_Failure(VKI_EBADF
);
12864 case VKI_BPF_PROG_TEST_RUN
:
12865 /* Test prog. Read data_in, write up to data_size_out to data_out. */
12866 PRE_MEM_READ("bpf(attr->test.prog_fd)", (Addr
)&attr
->test
.prog_fd
, sizeof(attr
->test
.prog_fd
));
12867 PRE_MEM_READ("bpf(attr->test.repeat)", (Addr
)&attr
->test
.repeat
, sizeof(attr
->test
.repeat
));
12868 PRE_MEM_READ("bpf(attr->test.data_size_in)", (Addr
)&attr
->test
.data_size_in
, sizeof(attr
->test
.data_size_in
));
12869 PRE_MEM_READ("bpf(attr->test.data_in)", (Addr
)&attr
->test
.data_in
, sizeof(attr
->test
.data_in
));
12870 PRE_MEM_READ("bpf(attr->test.data_out)", (Addr
)&attr
->test
.data_out
, sizeof(attr
->test
.data_out
));
12871 PRE_MEM_WRITE("bpf(attr->test.retval)", (Addr
)&attr
->test
.retval
, sizeof(attr
->test
.retval
));
12872 PRE_MEM_WRITE("bpf(attr->test.data_size_out)", (Addr
)&attr
->test
.data_size_out
, sizeof(attr
->test
.data_size_out
));
12873 PRE_MEM_WRITE("bpf(attr->test.duration)", (Addr
)&attr
->test
.duration
, sizeof(attr
->test
.duration
));
12874 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12875 if (!ML_(fd_allowed
)(attr
->test
.prog_fd
, "bpf", tid
, False
)) {
12876 SET_STATUS_Failure(VKI_EBADF
);
12879 PRE_MEM_READ("bpf(attr->test.data_in)", attr
->test
.data_in
, attr
->test
.data_size_in
);
12880 /* should be data_size_in + VKI_XDP_PACKET_HEADROOM for VKI_BPF_PROG_TYPE_XDP */
12881 PRE_MEM_WRITE("bpf(attr->test.data_out)", attr
->test
.data_out
, attr
->test
.data_size_in
);
12884 case VKI_BPF_OBJ_GET_INFO_BY_FD
:
12885 /* Get info for eBPF map or program. Write info. */
12886 PRE_MEM_READ("bpf(attr->info.bpf_fd)", (Addr
)&attr
->info
.bpf_fd
, sizeof(attr
->info
.bpf_fd
));
12887 PRE_MEM_READ("bpf(attr->info.info)", (Addr
)&attr
->info
.info
, sizeof(attr
->info
.info
));
12888 PRE_MEM_READ("bpf(attr->info.info_len)", (Addr
)&attr
->info
.info_len
, sizeof(attr
->info
.info_len
));
12889 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12890 if (!ML_(fd_allowed
)(attr
->info
.bpf_fd
, "bpf", tid
, False
)) {
12891 SET_STATUS_Failure(VKI_EBADF
);
12894 /* Get size of struct to write: is object a program or a map? */
12895 res
= bpf_obj_get_info_size(attr
->info
.bpf_fd
);
12897 PRE_MEM_WRITE("bpf(attr->info.info)", attr
->info
.info
,
12898 VG_MIN(attr
->info
.info_len
, res
));
12900 PRE_MEM_WRITE("bpf(attr->info.info)", attr
->info
.info
,
12901 VG_MIN(attr
->info
.info_len
,
12902 VG_MAX(VG_MAX(sizeof(struct vki_bpf_prog_info
),
12903 sizeof(struct vki_bpf_map_info
)),
12904 sizeof(struct vki_bpf_btf_info
))));
12907 case VKI_BPF_PROG_QUERY
:
12909 * Query list of eBPF program attached to cgroup.
12910 * Write array of ids (up to attr->query.prog_cnt u32-long ids).
12912 PRE_MEM_READ("bpf(attr->query.query_flags)", (Addr
)&attr
->query
.query_flags
, sizeof(attr
->query
.query_flags
));
12913 PRE_MEM_READ("bpf(attr->query.attach_type)", (Addr
)&attr
->query
.attach_type
, sizeof(attr
->query
.attach_type
));
12914 PRE_MEM_READ("bpf(attr->query.target_fd)", (Addr
)&attr
->query
.target_fd
, sizeof(attr
->query
.target_fd
));
12915 PRE_MEM_READ("bpf(attr->query.prog_cnt)", (Addr
)&attr
->query
.prog_cnt
, sizeof(attr
->query
.prog_cnt
));
12916 PRE_MEM_WRITE("bpf(attr->query.attach_flags)", (Addr
)&attr
->query
.attach_flags
, sizeof(attr
->query
.attach_flags
));
12917 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12918 if (!ML_(fd_allowed
)(attr
->query
.target_fd
, "bpf", tid
, False
)) {
12919 SET_STATUS_Failure(VKI_EBADF
);
12922 if (attr
->query
.prog_cnt
> 0) {
12923 PRE_MEM_READ("bpf(attr->query.prog_ids)", (Addr
)&attr
->query
.prog_ids
, sizeof(attr
->query
.prog_ids
));
12924 if (attr
->query
.prog_ids
) {
12925 PRE_MEM_WRITE("bpf(attr->query.prog_ids)", attr
->query
.prog_ids
,
12926 attr
->query
.prog_cnt
* sizeof(__vki_u32
));
12931 case VKI_BPF_RAW_TRACEPOINT_OPEN
:
12932 /* Open raw tracepoint. Read tracepoint name. */
12933 PRE_MEM_READ("bpf(attr->raw_tracepoint.name)", (Addr
)&attr
->raw_tracepoint
.name
, sizeof(attr
->raw_tracepoint
.name
));
12934 PRE_MEM_READ("bpf(attr->raw_tracepoint.prog_fd)", (Addr
)&attr
->raw_tracepoint
.prog_fd
, sizeof(attr
->raw_tracepoint
.prog_fd
));
12935 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12936 if (!ML_(fd_allowed
)(attr
->raw_tracepoint
.prog_fd
,
12937 "bpf", tid
, False
)) {
12938 SET_STATUS_Failure(VKI_EBADF
);
12941 /* Name is limited to 128 characters in kernel/bpf/syscall.c. */
12942 if (attr
->raw_tracepoint
.name
!= 0)
12943 pre_asciiz_str(tid
, attr
->raw_tracepoint
.name
, 128,
12944 "bpf(attr->raw_tracepoint.name)");
12947 case VKI_BPF_BTF_LOAD
:
12948 /* Load BTF information about a program into the kernel. */
12949 PRE_MEM_READ("bpf(attr->btf)", (Addr
)&attr
->btf
, sizeof(attr
->btf
));
12950 PRE_MEM_READ("bpf(attr->btf_size)", (Addr
)&attr
->btf_size
, sizeof(attr
->btf_size
));
12951 PRE_MEM_READ("bpf(attr->btf_log_buf)", (Addr
)&attr
->btf_log_buf
, sizeof(attr
->btf_log_buf
));
12952 PRE_MEM_READ("bpf(attr->btf_log_size)", (Addr
)&attr
->btf_log_size
, sizeof(attr
->btf_log_size
));
12953 PRE_MEM_READ("bpf(attr->btf_log_level)", (Addr
)&attr
->btf_log_level
, sizeof(attr
->btf_log_level
));
12954 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12955 /* Read BTF data. */
12956 PRE_MEM_READ("bpf(attr->btf)", attr
->btf
, attr
->btf_size
);
12957 /* Possibly write up to btf_log_len into user space log buffer. */
12958 if (attr
->btf_log_level
|| attr
->btf_log_size
|| attr
->btf_log_buf
)
12959 PRE_MEM_WRITE("bpf(attr->btf_log_buf)",
12960 attr
->btf_log_buf
, attr
->btf_log_size
);
12963 case VKI_BPF_TASK_FD_QUERY
:
12964 /* Get info about the task. Write collected info. */
12965 PRE_MEM_READ("bpf(attr->task_fd_query.pid)", (Addr
)&attr
->task_fd_query
.pid
, sizeof(attr
->task_fd_query
.pid
));
12966 PRE_MEM_READ("bpf(attr->task_fd_query.fd)", (Addr
)&attr
->task_fd_query
.fd
, sizeof(attr
->task_fd_query
.fd
));
12967 PRE_MEM_READ("bpf(attr->task_fd_query.flags)", (Addr
)&attr
->task_fd_query
.flags
, sizeof(attr
->task_fd_query
.flags
));
12968 PRE_MEM_READ("bpf(attr->task_fd_query.buf_len)", (Addr
)&attr
->task_fd_query
.buf_len
, sizeof(attr
->task_fd_query
.buf_len
));
12969 PRE_MEM_READ("bpf(attr->task_fd_query.buf)", (Addr
)&attr
->task_fd_query
.buf
, sizeof(attr
->task_fd_query
.buf
));
12970 PRE_MEM_WRITE("bpf(attr->task_fd_query.prog_id)", (Addr
)&attr
->task_fd_query
.prog_id
, sizeof(attr
->task_fd_query
.prog_id
));
12971 PRE_MEM_WRITE("bpf(attr->task_fd_query.fd_type)", (Addr
)&attr
->task_fd_query
.fd_type
, sizeof(attr
->task_fd_query
.fd_type
));
12972 PRE_MEM_WRITE("bpf(attr->task_fd_query.probe_offset)", (Addr
)&attr
->task_fd_query
.probe_offset
, sizeof(attr
->task_fd_query
.probe_offset
));
12973 PRE_MEM_WRITE("bpf(attr->task_fd_query.probe_addr)", (Addr
)&attr
->task_fd_query
.probe_addr
, sizeof(attr
->task_fd_query
.probe_addr
));
12974 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12975 if (!ML_(fd_allowed
)(attr
->task_fd_query
.fd
, "bpf", tid
, False
)) {
12976 SET_STATUS_Failure(VKI_EBADF
);
12979 if (attr
->task_fd_query
.buf_len
> 0) {
12980 /* Write task or perf event name. */
12981 PRE_MEM_WRITE("bpf(attr->task_fd_query.buf)",
12982 attr
->task_fd_query
.buf
,
12983 attr
->task_fd_query
.buf_len
);
12987 case VKI_BPF_MAP_LOOKUP_AND_DELETE_ELEM
:
12988 /* Perform a lookup on an eBPF map. Read key, write value (delete key) */
12989 PRE_MEM_READ("bpf(attr->key)", (Addr
)&attr
->key
, sizeof(attr
->key
));
12990 PRE_MEM_READ("bpf(attr->value)", (Addr
)&attr
->value
, sizeof(attr
->value
));
12991 PRE_MEM_READ("bpf(attr->map_fd)", (Addr
)&attr
->map_fd
, sizeof(attr
->map_fd
));
12992 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12993 if (!ML_(fd_allowed
)(attr
->map_fd
, "bpf", tid
, False
)) {
12994 SET_STATUS_Failure(VKI_EBADF
);
12997 /* Get size of key and value for this map. */
12998 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
)) {
12999 PRE_MEM_READ("bpf(attr->key)", attr
->key
, key_size
);
13000 PRE_MEM_WRITE("bpf(attr->value)", attr
->value
, value_size
);
13004 case VKI_BPF_MAP_FREEZE
:
13005 /* Freeze map, read map_fd (write frozen flag, not visible to user space). */
13006 PRE_MEM_READ("bpf(attr->map_fd)", (Addr
)&attr
->map_fd
, sizeof(attr
->map_fd
));
13009 VG_(message
)(Vg_DebugMsg
,
13010 "WARNING: unhandled eBPF command %lu\n", ARG1
);
13017 union vki_bpf_attr
*attr
= (union vki_bpf_attr
*)(Addr
)ARG2
;
13018 UInt key_size
, value_size
;
13020 vg_assert(SUCCESS
);
13023 case VKI_BPF_PROG_GET_NEXT_ID
:
13024 case VKI_BPF_MAP_GET_NEXT_ID
:
13025 POST_MEM_WRITE(attr
->next_id
, sizeof(attr
->next_id
));
13027 case VKI_BPF_MAP_UPDATE_ELEM
:
13028 case VKI_BPF_MAP_DELETE_ELEM
:
13029 case VKI_BPF_OBJ_PIN
:
13030 case VKI_BPF_PROG_ATTACH
:
13031 case VKI_BPF_PROG_DETACH
:
13033 /* Following commands have bpf() return a file descriptor. */
13034 case VKI_BPF_MAP_CREATE
:
13035 case VKI_BPF_OBJ_GET
:
13036 case VKI_BPF_PROG_GET_FD_BY_ID
:
13037 case VKI_BPF_MAP_GET_FD_BY_ID
:
13038 case VKI_BPF_BTF_GET_FD_BY_ID
:
13039 case VKI_BPF_RAW_TRACEPOINT_OPEN
:
13040 if (!ML_(fd_allowed
)(RES
, "bpf", tid
, True
)) {
13042 SET_STATUS_Failure(VKI_EMFILE
);
13044 if (VG_(clo_track_fds
))
13045 ML_(record_fd_open_nameless
)(tid
, RES
);
13049 * TODO: Is there a way to pass information between PRE and POST hooks?
13050 * To avoid querying again for the size of keys and values.
13052 case VKI_BPF_MAP_LOOKUP_ELEM
:
13053 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
))
13054 POST_MEM_WRITE(attr
->value
, value_size
);
13056 case VKI_BPF_MAP_GET_NEXT_KEY
:
13057 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
))
13058 POST_MEM_WRITE(attr
->next_key
, key_size
);
13060 case VKI_BPF_PROG_LOAD
:
13061 /* Return a file descriptor for loaded program, write into log_buf. */
13062 if (!ML_(fd_allowed
)(RES
, "bpf", tid
, True
)) {
13064 SET_STATUS_Failure(VKI_EMFILE
);
13066 if (VG_(clo_track_fds
))
13067 ML_(record_fd_open_nameless
)(tid
, RES
);
13069 if (attr
->log_level
|| attr
->log_size
|| attr
->log_buf
)
13070 POST_MEM_WRITE(attr
->log_buf
, attr
->log_size
);
13072 case VKI_BPF_PROG_TEST_RUN
:
13073 POST_MEM_WRITE((Addr
)&attr
->test
.retval
, sizeof(attr
->test
.retval
));
13074 POST_MEM_WRITE((Addr
)&attr
->test
.data_size_out
, sizeof(attr
->test
.data_size_out
));
13075 POST_MEM_WRITE((Addr
)&attr
->test
.duration
, sizeof(attr
->test
.duration
));
13076 POST_MEM_WRITE(attr
->test
.data_out
, attr
->test
.data_size_out
);
13078 case VKI_BPF_OBJ_GET_INFO_BY_FD
:
13079 POST_MEM_WRITE(attr
->info
.info
, attr
->info
.info_len
);
13081 case VKI_BPF_PROG_QUERY
:
13082 POST_MEM_WRITE((Addr
)&attr
->query
.attach_flags
, sizeof(attr
->query
.attach_flags
));
13083 POST_MEM_WRITE((Addr
)&attr
->query
.prog_cnt
, sizeof(attr
->query
.prog_cnt
));
13084 if (attr
->query
.prog_ids
)
13085 POST_MEM_WRITE(attr
->query
.prog_ids
,
13086 attr
->query
.prog_cnt
* sizeof(__vki_u32
));
13088 case VKI_BPF_BTF_LOAD
:
13089 /* Return a file descriptor for BTF data, write into btf_log_buf. */
13090 if (!ML_(fd_allowed
)(RES
, "bpf", tid
, True
)) {
13092 SET_STATUS_Failure(VKI_EMFILE
);
13094 if (VG_(clo_track_fds
))
13095 ML_(record_fd_open_nameless
)(tid
, RES
);
13097 if (attr
->btf_log_level
)
13098 POST_MEM_WRITE(attr
->btf_log_buf
, attr
->btf_log_size
);
13100 case VKI_BPF_TASK_FD_QUERY
:
13101 POST_MEM_WRITE(attr
->task_fd_query
.buf
, attr
->task_fd_query
.buf_len
);
13102 POST_MEM_WRITE((Addr
)&attr
->task_fd_query
.prog_id
, sizeof(attr
->task_fd_query
.prog_id
));
13103 POST_MEM_WRITE((Addr
)&attr
->task_fd_query
.fd_type
, sizeof(attr
->task_fd_query
.fd_type
));
13104 POST_MEM_WRITE((Addr
)&attr
->task_fd_query
.probe_offset
, sizeof(attr
->task_fd_query
.probe_offset
));
13105 POST_MEM_WRITE((Addr
)&attr
->task_fd_query
.probe_addr
, sizeof(attr
->task_fd_query
.probe_addr
));
13107 case VKI_BPF_MAP_LOOKUP_AND_DELETE_ELEM
:
13108 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
))
13109 POST_MEM_WRITE(attr
->value
, value_size
);
13111 case VKI_BPF_MAP_FREEZE
:
13112 /* Freeze map, read map_fd (write frozen flag, not visible to user space). */
13115 VG_(message
)(Vg_DebugMsg
,
13116 "WARNING: unhandled eBPF command %lu\n", ARG1
);
13121 PRE(sys_copy_file_range
)
13123 PRINT("sys_copy_file_range (%lu, %lu, %lu, %lu, %lu, %lu)", ARG1
, ARG2
, ARG3
,
13126 PRE_REG_READ6(vki_size_t
, "copy_file_range",
13128 vki_loff_t
*, "off_in",
13130 vki_loff_t
*, "off_out",
13132 unsigned int, "flags");
13134 /* File descriptors are "specially" tracked by valgrind.
13135 valgrind itself uses some, so make sure someone didn't
13136 put in one of our own... */
13137 if (!ML_(fd_allowed
)(ARG1
, "copy_file_range(fd_in)", tid
, False
) ||
13138 !ML_(fd_allowed
)(ARG3
, "copy_file_range(fd_in)", tid
, False
)) {
13139 SET_STATUS_Failure( VKI_EBADF
);
13141 /* Now see if the offsets are defined. PRE_MEM_READ will
13142 double check it can dereference them. */
13144 PRE_MEM_READ( "copy_file_range(off_in)", ARG2
, sizeof(vki_loff_t
));
13146 PRE_MEM_READ( "copy_file_range(off_out)", ARG4
, sizeof(vki_loff_t
));
13150 PRE(sys_pkey_alloc
)
13152 PRINT("pkey_alloc (%lu, %lu)", ARG1
, ARG2
);
13154 PRE_REG_READ2(long, "pkey_alloc",
13155 unsigned long, "flags",
13156 unsigned long, "access_rights");
13158 /* The kernel says: pkey_alloc() is always safe to call regardless of
13159 whether or not the operating system supports protection keys. It can be
13160 used in lieu of any other mechanism for detecting pkey support and will
13161 simply fail with the error ENOSPC if the operating system has no pkey
13164 So we simply always return ENOSPC to signal memory protection keys are
13165 not supported under valgrind, unless there are unknown flags, then we
13167 unsigned long pkey_flags
= ARG1
;
13168 if (pkey_flags
!= 0)
13169 SET_STATUS_Failure( VKI_EINVAL
);
13171 SET_STATUS_Failure( VKI_ENOSPC
);
13176 PRINT("pkey_free (%" FMT_REGWORD
"u )", ARG1
);
13178 PRE_REG_READ1(long, "pkey_free",
13179 unsigned long, "pkey");
13181 /* Since pkey_alloc () can never succeed, see above, freeing any pkey is
13182 always an error. */
13183 SET_STATUS_Failure( VKI_EINVAL
);
13186 PRE(sys_pkey_mprotect
)
13188 PRINT("sys_pkey_mprotect ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
13189 FMT_REGWORD
"u %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
, ARG4
);
13190 PRE_REG_READ4(long, "pkey_mprotect",
13191 unsigned long, addr
, vki_size_t
, len
, unsigned long, prot
,
13192 unsigned long, pkey
);
13199 /* Since pkey_alloc () can never succeed, see above, any pkey is
13200 invalid. Except for -1, then pkey_mprotect acts just like mprotect. */
13202 SET_STATUS_Failure( VKI_EINVAL
);
13204 handle_sys_mprotect (tid
, status
, &addr
, &len
, &prot
);
13211 POST(sys_pkey_mprotect
)
13217 ML_(notify_core_and_tool_of_mprotect
)(addr
, len
, prot
);
13220 PRE(sys_io_uring_setup
)
13222 PRINT("sys_io_uring_setup ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
13224 PRE_REG_READ2(long, "io_uring_setup", unsigned int, entries
,
13225 struct vki_io_uring_params
*, p
);
13227 PRE_MEM_READ("io_uring_setup(p)", ARG2
,
13228 offsetof(struct vki_io_uring_params
, sq_off
));
13231 POST(sys_io_uring_setup
)
13233 vg_assert(SUCCESS
);
13234 if (!ML_(fd_allowed
)(RES
, "io_uring_setup", tid
, True
)) {
13236 SET_STATUS_Failure( VKI_EMFILE
);
13238 if (VG_(clo_track_fds
))
13239 ML_(record_fd_open_nameless
)(tid
, RES
);
13240 POST_MEM_WRITE(ARG2
+ offsetof(struct vki_io_uring_params
, sq_off
),
13241 sizeof(struct vki_io_sqring_offsets
) +
13242 sizeof(struct vki_io_cqring_offsets
));
13246 PRE(sys_io_uring_enter
)
13248 PRINT("sys_io_uring_enter ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
13249 FMT_REGWORD
"u %" FMT_REGWORD
"u, %" FMT_REGWORD
"u %"
13251 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
13252 PRE_REG_READ6(long, "io_uring_enter",
13253 unsigned int, fd
, unsigned int, to_submit
,
13254 unsigned int, min_complete
, unsigned int, flags
,
13255 const void *, sig
, unsigned long, sigsz
);
13257 PRE_MEM_READ("io_uring_enter(sig)", ARG5
, ARG6
);
13260 POST(sys_io_uring_enter
)
13264 PRE(sys_io_uring_register
)
13266 PRINT("sys_io_uring_register ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
13267 FMT_REGWORD
"u %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
, ARG4
);
13268 PRE_REG_READ4(long, "io_uring_register",
13269 unsigned int, fd
, unsigned int, opcode
,
13270 void *, arg
, unsigned int, nr_args
);
13272 case VKI_IORING_REGISTER_BUFFERS
:
13273 PRE_MEM_READ("", ARG3
, ARG4
* sizeof(struct vki_iovec
));
13275 case VKI_IORING_UNREGISTER_BUFFERS
:
13277 case VKI_IORING_REGISTER_FILES
:
13278 PRE_MEM_READ("", ARG3
, ARG4
* sizeof(__vki_s32
));
13280 case VKI_IORING_UNREGISTER_FILES
:
13282 case VKI_IORING_REGISTER_EVENTFD
:
13283 PRE_MEM_READ("", ARG3
, sizeof(__vki_s32
));
13285 case VKI_IORING_UNREGISTER_EVENTFD
:
13290 POST(sys_io_uring_register
)
13296 PRINT("sys_execveat ( %lu, %#lx(%s), %#lx, %#lx, %lu", ARG1
, ARG2
, (char*)ARG2
, ARG3
, ARG4
, ARG5
);
13297 PRE_REG_READ5(vki_off_t
, "execveat",
13298 int, fd
, char *, filename
, char **, argv
, char **, envp
, int, flags
);
13299 PRE_MEM_RASCIIZ( "execveat(filename)", ARG2
);
13301 #if !defined(__NR_execveat)
13302 SET_STATUS_Failure(VKI_ENOSYS
);
13306 const HChar
*path
= (const HChar
*) ARG2
;
13310 HChar
*abs_path
= NULL
;
13311 Bool check_at_symlink
= False
;
13312 Bool check_pathptr
= True
;
13314 if (ML_(safe_to_deref
) (path
, 1)) {
13315 /* If pathname is absolute, we'll ignore dirfd
13316 * and just pass the pathname, try to determine
13317 * the absolute path otherwise. */
13318 if (path
[0] != '/') {
13319 /* Check dirfd is a valid fd. */
13320 if (!ML_(fd_allowed
)(ARG1
, "execveat", tid
, False
)) {
13321 SET_STATUS_Failure( VKI_EBADF
);
13324 /* If pathname is empty and AT_EMPTY_PATH is
13325 set then dirfd describes the whole path. */
13326 if (path
[0] == '\0') {
13327 if (ARG5
& VKI_AT_EMPTY_PATH
) {
13328 if (VG_(resolve_filename
)(ARG1
, &buf
)) {
13330 check_pathptr
= False
;
13334 else if (ARG1
== VKI_AT_FDCWD
) {
13335 check_at_symlink
= True
;
13337 if (ARG5
& VKI_AT_SYMLINK_NOFOLLOW
)
13338 check_at_symlink
= True
;
13339 else if (VG_(resolve_filename
)(ARG1
, &buf
)) {
13340 abs_path
= VG_(malloc
)("execveat",
13341 (VG_(strlen
)(buf
) + 1
13342 + VG_(strlen
)(path
) + 1));
13343 VG_(sprintf
)(abs_path
, "%s/%s", buf
, path
);
13345 check_pathptr
= False
;
13349 if (check_at_symlink
) {
13350 struct vg_stat statbuf
;
13353 statres
= VG_(stat
)(path
, &statbuf
);
13354 if (sr_isError(statres
) || VKI_S_ISLNK(statbuf
.mode
)) {
13355 SET_STATUS_Failure( VKI_ELOOP
);
13361 SET_STATUS_Failure(VKI_EFAULT
);
13365 handle_pre_sys_execve(tid
, status
, (Addr
) path
, arg_2
, arg_3
, EXECVEAT
,
13368 /* The exec failed, we keep running... cleanup. */
13369 VG_(free
)(abs_path
);
13374 PRE(sys_close_range
)
13376 SysRes res
= VG_(mk_SysRes_Success
)(0);
13377 unsigned int beg
, end
;
13378 unsigned int last
= ARG2
;
13380 FUSE_COMPATIBLE_MAY_BLOCK();
13381 PRINT("sys_close_range ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
13382 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
13383 PRE_REG_READ3(long, "close_range",
13384 unsigned int, first
, unsigned int, last
,
13385 unsigned int, flags
);
13388 SET_STATUS_Failure( VKI_EINVAL
);
13392 if (last
>= VG_(fd_hard_limit
))
13393 last
= VG_(fd_hard_limit
) - 1;
13396 SET_STATUS_Success ( 0 );
13403 || (end
== 2/*stderr*/ && VG_(debugLog_getLevel
)() > 0)
13404 || end
== VG_(log_output_sink
).fd
13405 || end
== VG_(xml_output_sink
).fd
) {
13406 /* Split the range if it contains a file descriptor we're not
13407 * supposed to close. */
13408 if (end
- 1 >= beg
)
13409 res
= VG_(do_syscall3
)(__NR_close_range
, (UWord
)beg
, (UWord
)end
- 1, ARG3
);
13412 } while (end
++ <= last
);
13414 /* If it failed along the way, it's presumably the flags being wrong. */
13415 SET_STATUS_from_SysRes (res
);
13418 POST(sys_close_range
)
13421 unsigned int last
= ARG2
;
13423 if (!VG_(clo_track_fds
)
13424 || (ARG3
& VKI_CLOSE_RANGE_CLOEXEC
) != 0)
13427 if (last
>= VG_(fd_hard_limit
))
13428 last
= VG_(fd_hard_limit
) - 1;
13430 for (fd
= ARG1
; fd
<= last
; fd
++)
13431 if ((fd
!= 2/*stderr*/ || VG_(debugLog_getLevel
)() == 0)
13432 && fd
!= VG_(log_output_sink
).fd
13433 && fd
!= VG_(xml_output_sink
).fd
)
13434 ML_(record_fd_close
)(fd
);
13440 #endif // defined(VGO_linux)
13442 /*--------------------------------------------------------------------*/
13444 /*--------------------------------------------------------------------*/