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 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
75 VG_(debugLog
)(1, "syswrap-linux",
76 "thread_wrapper(tid=%u): entry\n",
79 vg_assert(tst
->status
== VgTs_Init
);
81 /* make sure we get the CPU lock before doing anything significant */
82 VG_(acquire_BigLock
)(tid
, "thread_wrapper(starting new thread)");
85 VG_(printf
)("thread tid %u started: stack = %p\n",
88 /* Make sure error reporting is enabled in the new thread. */
89 tst
->err_disablement_level
= 0;
91 VG_TRACK(pre_thread_first_insn
, tid
);
93 tst
->os_state
.lwpid
= VG_(gettid
)();
94 /* Set the threadgroup for real. This overwrites the provisional value set
95 in do_clone(). See comments in do_clone for background, also #226116. */
96 tst
->os_state
.threadgroup
= VG_(getpid
)();
98 /* Thread created with all signals blocked; scheduler will set the
101 ret
= VG_(scheduler
)(tid
);
103 vg_assert(VG_(is_exiting
)(tid
));
105 vg_assert(tst
->status
== VgTs_Runnable
);
106 vg_assert(VG_(is_running_thread
)(tid
));
108 VG_(debugLog
)(1, "syswrap-linux",
109 "thread_wrapper(tid=%u): exit, schedreturncode %s\n",
110 tid
, VG_(name_of_VgSchedReturnCode
)(ret
));
112 /* Return to caller, still holding the lock. */
117 /* ---------------------------------------------------------------------
119 ------------------------------------------------------------------ */
121 /* Run a thread all the way to the end, then do appropriate exit actions
122 (this is the last-one-out-turn-off-the-lights bit). */
123 static void run_a_thread_NORETURN ( Word tidW
)
125 ThreadId tid
= (ThreadId
)tidW
;
126 VgSchedReturnCode src
;
129 #ifdef ENABLE_INNER_CLIENT_REQUEST
130 Int registered_vgstack_id
;
133 VG_(debugLog
)(1, "syswrap-linux",
134 "run_a_thread_NORETURN(tid=%u): pre-thread_wrapper\n",
137 tst
= VG_(get_ThreadState
)(tid
);
140 /* An thread has two stacks:
141 * the simulated stack (used by the synthetic cpu. Guest process
142 is using this stack).
143 * the valgrind stack (used by the real cpu. Valgrind code is running
145 When Valgrind runs as an inner, it must signals that its (real) stack
146 is the stack to use by the outer to e.g. do stacktraces.
149 (registered_vgstack_id
150 = VALGRIND_STACK_REGISTER (tst
->os_state
.valgrind_stack_base
,
151 tst
->os_state
.valgrind_stack_init_SP
));
153 /* Run the thread all the way through. */
154 src
= thread_wrapper(tid
);
156 VG_(debugLog
)(1, "syswrap-linux",
157 "run_a_thread_NORETURN(tid=%u): post-thread_wrapper\n",
160 c
= VG_(count_living_threads
)();
161 vg_assert(c
>= 1); /* stay sane */
163 /* Deregister thread's stack. */
164 if (tst
->os_state
.stk_id
!= NULL_STK_ID
)
165 VG_(deregister_stack
)(tst
->os_state
.stk_id
);
167 // Tell the tool this thread is exiting
168 VG_TRACK( pre_thread_ll_exit
, tid
);
170 /* If the thread is exiting with errors disabled, complain loudly;
171 doing so is bad (does the user know this has happened?) Also,
172 in all cases, be paranoid and clear the flag anyway so that the
173 thread slot is safe in this respect if later reallocated. This
174 should be unnecessary since the flag should be cleared when the
175 slot is reallocated, in thread_wrapper(). */
176 if (tst
->err_disablement_level
> 0) {
178 "WARNING: exiting thread has error reporting disabled.\n"
179 "WARNING: possibly as a result of some mistake in the use\n"
180 "WARNING: of the VALGRIND_DISABLE_ERROR_REPORTING macros.\n"
184 "run_a_thread_NORETURN(tid=%u): "
185 "WARNING: exiting thread has err_disablement_level = %u\n",
186 tid
, tst
->err_disablement_level
189 tst
->err_disablement_level
= 0;
193 VG_(debugLog
)(1, "syswrap-linux",
194 "run_a_thread_NORETURN(tid=%u): "
195 "last one standing\n",
198 /* We are the last one standing. Keep hold of the lock and
199 carry on to show final tool results, then exit the entire system.
200 Use the continuation pointer set at startup in m_main. */
201 ( * VG_(address_of_m_main_shutdown_actions_NORETURN
) ) (tid
, src
);
204 VG_(debugLog
)(1, "syswrap-linux",
205 "run_a_thread_NORETURN(tid=%u): "
206 "not last one standing\n",
209 /* OK, thread is dead, but others still exist. Just exit. */
211 /* This releases the run lock */
212 VG_(exit_thread
)(tid
);
213 vg_assert(tst
->status
== VgTs_Zombie
);
214 vg_assert(sizeof(tst
->status
) == 4);
215 vg_assert(sizeof(tst
->os_state
.exitcode
) == sizeof(Word
));
217 INNER_REQUEST (VALGRIND_STACK_DEREGISTER (registered_vgstack_id
));
219 /* We have to use this sequence to terminate the thread to
220 prevent a subtle race. If VG_(exit_thread)() had left the
221 ThreadState as Empty, then it could have been reallocated,
222 reusing the stack while we're doing these last cleanups.
223 Instead, VG_(exit_thread) leaves it as Zombie to prevent
224 reallocation. We need to make sure we don't touch the stack
225 between marking it Empty and exiting. Hence the
227 #if defined(VGP_x86_linux)
230 "movl %1, %0\n" /* set tst->status = VgTs_Empty */
231 "movl %2, %%eax\n" /* set %eax = __NR_exit */
232 "movl %3, %%ebx\n" /* set %ebx = tst->os_state.exitcode */
233 "int $0x80\n" /* exit(tst->os_state.exitcode) */
236 : "n" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
239 #elif defined(VGP_amd64_linux)
241 "movl %1, %0\n" /* set tst->status = VgTs_Empty */
242 "movq %2, %%rax\n" /* set %rax = __NR_exit */
243 "movq %3, %%rdi\n" /* set %rdi = tst->os_state.exitcode */
244 "syscall\n" /* exit(tst->os_state.exitcode) */
246 : "n" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
249 #elif defined(VGP_ppc32_linux) || defined(VGP_ppc64be_linux) \
250 || defined(VGP_ppc64le_linux)
251 { UInt vgts_empty
= (UInt
)VgTs_Empty
;
253 "stw %1,%0\n\t" /* set tst->status = VgTs_Empty */
254 "li 0,%2\n\t" /* set r0 = __NR_exit */
255 "lwz 3,%3\n\t" /* set r3 = tst->os_state.exitcode */
256 "sc\n\t" /* exit(tst->os_state.exitcode) */
258 : "r" (vgts_empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
262 #elif defined(VGP_arm_linux)
264 "str %1, %0\n" /* set tst->status = VgTs_Empty */
265 "mov r7, %2\n" /* set %r7 = __NR_exit */
266 "ldr r0, %3\n" /* set %r0 = tst->os_state.exitcode */
267 "svc 0x00000000\n" /* exit(tst->os_state.exitcode) */
269 : "r" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
272 #elif defined(VGP_arm64_linux)
274 "str %w1, %0\n" /* set tst->status = VgTs_Empty (32-bit store) */
275 "mov x8, %2\n" /* set %x8 = __NR_exit */
276 "ldr x0, %3\n" /* set %x0 = tst->os_state.exitcode */
277 "svc 0x00000000\n" /* exit(tst->os_state.exitcode) */
279 : "r" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
282 #elif defined(VGP_s390x_linux)
284 "st %1, %0\n" /* set tst->status = VgTs_Empty */
285 "lg 2, %3\n" /* set r2 = tst->os_state.exitcode */
286 "svc %2\n" /* exit(tst->os_state.exitcode) */
288 : "d" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
291 #elif defined(VGP_mips32_linux) || defined(VGP_mips64_linux)
293 "sw %1, %0\n\t" /* set tst->status = VgTs_Empty */
294 "li $2, %2\n\t" /* set v0 = __NR_exit */
295 "lw $4, %3\n\t" /* set a0 = tst->os_state.exitcode */
296 "syscall\n\t" /* exit(tst->os_state.exitcode) */
299 : "r" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
300 : "cc", "memory" , "v0", "a0"
302 #elif defined(VGP_nanomips_linux)
304 "sw %1, %0 \n\t" /* set tst->status = VgTs_Empty */
305 "li $t4, %2 \n\t" /* set t4 = __NR_exit */
306 "lw $a0, %3 \n\t" /* set a0 = tst->os_state.exitcode */
307 "syscall[32] \n\t" /* exit(tst->os_state.exitcode) */
309 : "r" (VgTs_Empty
), "n" (__NR_exit
), "m" (tst
->os_state
.exitcode
)
310 : "memory" , "$t4", "$a0"
313 # error Unknown platform
316 VG_(core_panic
)("Thread exit failed?\n");
323 Word
ML_(start_thread_NORETURN
) ( void* arg
)
325 ThreadState
* tst
= (ThreadState
*)arg
;
326 ThreadId tid
= tst
->tid
;
328 run_a_thread_NORETURN ( (Word
)tid
);
333 /* Allocate a stack for this thread, if it doesn't already have one.
334 They're allocated lazily, and never freed. Returns the initial stack
335 pointer value to use, or 0 if allocation failed. */
336 Addr
ML_(allocstack
)(ThreadId tid
)
338 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
342 /* Either the stack_base and stack_init_SP are both zero (in which
343 case a stack hasn't been allocated) or they are both non-zero,
344 in which case it has. */
346 if (tst
->os_state
.valgrind_stack_base
== 0)
347 vg_assert(tst
->os_state
.valgrind_stack_init_SP
== 0);
349 if (tst
->os_state
.valgrind_stack_base
!= 0)
350 vg_assert(tst
->os_state
.valgrind_stack_init_SP
!= 0);
352 /* If no stack is present, allocate one. */
354 if (tst
->os_state
.valgrind_stack_base
== 0) {
355 stack
= VG_(am_alloc_VgStack
)( &initial_SP
);
357 tst
->os_state
.valgrind_stack_base
= (Addr
)stack
;
358 tst
->os_state
.valgrind_stack_init_SP
= initial_SP
;
363 VG_(printf
)( "stack for tid %u at %p; init_SP=%p\n",
365 (void*)tst
->os_state
.valgrind_stack_base
,
366 (void*)tst
->os_state
.valgrind_stack_init_SP
);
368 return tst
->os_state
.valgrind_stack_init_SP
;
371 /* Allocate a stack for the main thread, and run it all the way to the
372 end. Although we already have a working VgStack
373 (VG_(interim_stack)) it's better to allocate a new one, so that
374 overflow detection works uniformly for all threads.
376 void VG_(main_thread_wrapper_NORETURN
)(ThreadId tid
)
379 VG_(debugLog
)(1, "syswrap-linux",
380 "entering VG_(main_thread_wrapper_NORETURN)\n");
382 sp
= ML_(allocstack
)(tid
);
383 #if defined(ENABLE_INNER_CLIENT_REQUEST)
385 // we must register the main thread stack before the call
386 // to ML_(call_on_new_stack_0_1), otherwise the outer valgrind
387 // reports 'write error' on the non registered stack.
388 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
391 VALGRIND_STACK_REGISTER (tst
->os_state
.valgrind_stack_base
,
392 tst
->os_state
.valgrind_stack_init_SP
));
396 #if defined(VGP_ppc32_linux)
397 /* make a stack frame */
401 #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
402 /* make a stack frame */
406 #elif defined(VGP_s390x_linux)
407 /* make a stack frame */
413 /* If we can't even allocate the first thread's stack, we're hosed.
415 vg_assert2(sp
!= 0, "Cannot allocate main thread's stack.");
417 /* shouldn't be any other threads around yet */
418 vg_assert( VG_(count_living_threads
)() == 1 );
420 ML_(call_on_new_stack_0_1
)(
421 (Addr
)sp
, /* stack */
422 0, /* bogus return address */
423 run_a_thread_NORETURN
, /* fn to call */
424 (Word
)tid
/* arg to give it */
431 /* Clone a new thread. Note that in the clone syscalls, we hard-code
432 tlsaddr argument as NULL : the guest TLS is emulated via guest
433 registers, and Valgrind itself has no thread local storage. */
434 static SysRes
clone_new_thread ( Word (*fn
)(void *),
442 /* Note that in all the below, we make sys_clone appear to have returned
443 Success(0) in the child, by assigning the relevant child guest
444 register(s) just before the clone syscall. */
445 #if defined(VGP_x86_linux)
447 ctst
->arch
.vex
.guest_EAX
= 0;
448 eax
= do_syscall_clone_x86_linux
449 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
450 child_tidptr
, parent_tidptr
, NULL
);
451 res
= VG_(mk_SysRes_x86_linux
)( eax
);
452 #elif defined(VGP_amd64_linux)
454 ctst
->arch
.vex
.guest_RAX
= 0;
455 rax
= do_syscall_clone_amd64_linux
456 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
457 child_tidptr
, parent_tidptr
, NULL
);
458 res
= VG_(mk_SysRes_amd64_linux
)( rax
);
459 #elif defined(VGP_ppc32_linux)
461 UInt old_cr
= LibVEX_GuestPPC32_get_CR( &ctst
->arch
.vex
);
463 ctst
->arch
.vex
.guest_GPR3
= 0;
465 LibVEX_GuestPPC32_put_CR( old_cr
& ~(1<<28), &ctst
->arch
.vex
);
466 word64
= do_syscall_clone_ppc32_linux
467 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
468 child_tidptr
, parent_tidptr
, NULL
);
469 /* High half word64 is syscall return value. Low half is
470 the entire CR, from which we need to extract CR0.SO. */
471 /* VG_(printf)("word64 = 0x%llx\n", word64); */
472 res
= VG_(mk_SysRes_ppc32_linux
)(/*val*/(UInt
)(word64
>> 32),
473 /*errflag*/ (((UInt
)word64
) >> 28) & 1);
474 #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
476 UInt old_cr
= LibVEX_GuestPPC64_get_CR( &ctst
->arch
.vex
);
478 ctst
->arch
.vex
.guest_GPR3
= 0;
480 LibVEX_GuestPPC64_put_CR( old_cr
& ~(1<<28), &ctst
->arch
.vex
);
481 word64
= do_syscall_clone_ppc64_linux
482 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
483 child_tidptr
, parent_tidptr
, NULL
);
484 /* Low half word64 is syscall return value. Hi half is
485 the entire CR, from which we need to extract CR0.SO. */
486 /* VG_(printf)("word64 = 0x%llx\n", word64); */
487 res
= VG_(mk_SysRes_ppc64_linux
)
488 (/*val*/(UInt
)(word64
& 0xFFFFFFFFULL
),
489 /*errflag*/ (UInt
)((word64
>> (32+28)) & 1));
490 #elif defined(VGP_s390x_linux)
492 ctst
->arch
.vex
.guest_r2
= 0;
493 r2
= do_syscall_clone_s390x_linux
494 (stack
, flags
, parent_tidptr
, child_tidptr
, NULL
,
495 ML_(start_thread_NORETURN
), ctst
);
496 res
= VG_(mk_SysRes_s390x_linux
)( r2
);
497 #elif defined(VGP_arm64_linux)
499 ctst
->arch
.vex
.guest_X0
= 0;
500 x0
= do_syscall_clone_arm64_linux
501 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
502 child_tidptr
, parent_tidptr
, NULL
);
503 res
= VG_(mk_SysRes_arm64_linux
)( x0
);
504 #elif defined(VGP_arm_linux)
506 ctst
->arch
.vex
.guest_R0
= 0;
507 r0
= do_syscall_clone_arm_linux
508 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
509 child_tidptr
, parent_tidptr
, NULL
);
510 res
= VG_(mk_SysRes_arm_linux
)( r0
);
511 #elif defined(VGP_mips64_linux)
513 ctst
->arch
.vex
.guest_r2
= 0;
514 ctst
->arch
.vex
.guest_r7
= 0;
515 ret
= do_syscall_clone_mips64_linux
516 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
517 parent_tidptr
, NULL
, child_tidptr
);
518 res
= VG_(mk_SysRes_mips64_linux
)( /* val */ ret
, 0, /* errflag */ 0);
519 #elif defined(VGP_mips32_linux)
521 ctst
->arch
.vex
.guest_r2
= 0;
522 ctst
->arch
.vex
.guest_r7
= 0;
523 ret
= do_syscall_clone_mips_linux
524 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
525 child_tidptr
, parent_tidptr
, NULL
);
526 /* High half word64 is syscall return value. Low half is
527 the entire CR, from which we need to extract CR0.SO. */
528 res
= VG_ (mk_SysRes_mips32_linux
) (/*val */ ret
, 0, /*errflag */ 0);
529 #elif defined(VGP_nanomips_linux)
531 ctst
->arch
.vex
.guest_r4
= 0;
532 ret
= do_syscall_clone_nanomips_linux
533 (ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
534 child_tidptr
, parent_tidptr
, NULL
);
535 res
= VG_ (mk_SysRes_nanomips_linux
) (ret
);
537 # error Unknown platform
542 static void setup_child ( /*OUT*/ ThreadArchState
*child
,
543 /*IN*/ ThreadArchState
*parent
)
545 /* We inherit our parent's guest state. */
546 child
->vex
= parent
->vex
;
547 child
->vex_shadow1
= parent
->vex_shadow1
;
548 child
->vex_shadow2
= parent
->vex_shadow2
;
550 #if defined(VGP_x86_linux)
551 extern void ML_(x86_setup_LDT_GDT
) ( /*OUT*/ ThreadArchState
*child
,
552 /*IN*/ ThreadArchState
*parent
);
553 ML_(x86_setup_LDT_GDT
)(child
, parent
);
557 static SysRes
setup_child_tls (ThreadId ctid
, Addr tlsaddr
)
559 static const Bool debug
= False
;
560 ThreadState
* ctst
= VG_(get_ThreadState
)(ctid
);
561 // res is succesful by default, overriden if a real syscall is needed/done.
562 SysRes res
= VG_(mk_SysRes_Success
)(0);
565 VG_(printf
)("clone child has SETTLS: tls at %#lx\n", tlsaddr
);
567 #if defined(VGP_x86_linux)
568 vki_modify_ldt_t
* tlsinfo
= (vki_modify_ldt_t
*)tlsaddr
;
570 VG_(printf
)("clone child has SETTLS: tls info at %p: idx=%u "
571 "base=%#lx limit=%x; esp=%#x fs=%x gs=%x\n",
572 tlsinfo
, tlsinfo
->entry_number
,
573 tlsinfo
->base_addr
, tlsinfo
->limit
,
574 ctst
->arch
.vex
.guest_ESP
,
575 ctst
->arch
.vex
.guest_FS
, ctst
->arch
.vex
.guest_GS
);
576 res
= ML_(x86_sys_set_thread_area
)(ctid
, tlsinfo
);
577 #elif defined(VGP_amd64_linux)
578 ctst
->arch
.vex
.guest_FS_CONST
= tlsaddr
;
579 #elif defined(VGP_ppc32_linux)
580 ctst
->arch
.vex
.guest_GPR2
= tlsaddr
;
581 #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
582 ctst
->arch
.vex
.guest_GPR13
= tlsaddr
;
583 #elif defined(VGP_s390x_linux)
584 ctst
->arch
.vex
.guest_a0
= (UInt
) (tlsaddr
>> 32);
585 ctst
->arch
.vex
.guest_a1
= (UInt
) tlsaddr
;
586 #elif defined(VGP_arm64_linux)
587 /* Just assign the tls pointer in the guest TPIDR_EL0. */
588 ctst
->arch
.vex
.guest_TPIDR_EL0
= tlsaddr
;
589 #elif defined(VGP_arm_linux)
590 /* Just assign the tls pointer in the guest TPIDRURO. */
591 ctst
->arch
.vex
.guest_TPIDRURO
= tlsaddr
;
592 #elif defined(VGP_mips64_linux)
593 ctst
->arch
.vex
.guest_ULR
= tlsaddr
;
594 ctst
->arch
.vex
.guest_r27
= tlsaddr
;
595 #elif defined(VGP_mips32_linux) || defined(VGP_nanomips_linux)
596 ctst
->arch
.vex
.guest_ULR
= tlsaddr
;
597 ctst
->arch
.vex
.guest_r27
= tlsaddr
;
599 # error Unknown platform
605 When a client clones, we need to keep track of the new thread. This means:
606 1. allocate a ThreadId+ThreadState+stack for the thread
608 2. initialize the thread's new VCPU state
610 3. create the thread using the same args as the client requested,
611 but using the scheduler entrypoint for EIP, and a separate stack
614 static SysRes
do_clone ( ThreadId ptid
,
615 UWord flags
, Addr sp
,
620 ThreadId ctid
= VG_(alloc_ThreadState
)();
621 ThreadState
* ptst
= VG_(get_ThreadState
)(ptid
);
622 ThreadState
* ctst
= VG_(get_ThreadState
)(ctid
);
625 vki_sigset_t blockall
, savedmask
;
627 VG_(sigfillset
)(&blockall
);
629 vg_assert(VG_(is_running_thread
)(ptid
));
630 vg_assert(VG_(is_valid_tid
)(ctid
));
632 stack
= (UWord
*)ML_(allocstack
)(ctid
);
634 res
= VG_(mk_SysRes_Error
)( VKI_ENOMEM
);
638 /* Copy register state
640 Both parent and child return to the same place, and the code
641 following the clone syscall works out which is which, so we
642 don't need to worry about it.
644 The parent gets the child's new tid returned from clone, but the
647 If the clone call specifies a NULL sp for the new thread, then
648 it actually gets a copy of the parent's sp.
650 setup_child( &ctst
->arch
, &ptst
->arch
);
653 VG_(set_SP
)(ctid
, sp
);
655 ctst
->os_state
.parent
= ptid
;
657 /* inherit signal mask */
658 ctst
->sig_mask
= ptst
->sig_mask
;
659 ctst
->tmp_sig_mask
= ptst
->sig_mask
;
661 /* Start the child with its threadgroup being the same as the
662 parent's. This is so that any exit_group calls that happen
663 after the child is created but before it sets its
664 os_state.threadgroup field for real (in thread_wrapper in
665 syswrap-linux.c), really kill the new thread. a.k.a this avoids
666 a race condition in which the thread is unkillable (via
667 exit_group) because its threadgroup is not set. The race window
668 is probably only a few hundred or a few thousand cycles long.
670 ctst
->os_state
.threadgroup
= ptst
->os_state
.threadgroup
;
672 ML_(guess_and_register_stack
) (sp
, ctst
);
674 /* Assume the clone will succeed, and tell any tool that wants to
675 know that this thread has come into existence. We cannot defer
676 it beyond this point because setup_tls, just below,
677 causes checks to assert by making references to the new ThreadId
678 if we don't state the new thread exists prior to that point.
679 If the clone fails, we'll send out a ll_exit notification for it
680 at the out: label below, to clean up. */
681 vg_assert(VG_(owns_BigLock_LL
)(ptid
));
682 VG_TRACK ( pre_thread_ll_create
, ptid
, ctid
);
684 if (flags
& VKI_CLONE_SETTLS
) {
685 res
= setup_child_tls(ctid
, tlsaddr
);
689 flags
&= ~VKI_CLONE_SETTLS
;
691 /* start the thread with everything blocked */
692 VG_(sigprocmask
)(VKI_SIG_SETMASK
, &blockall
, &savedmask
);
694 /* Create the new thread */
695 res
= clone_new_thread ( ML_(start_thread_NORETURN
), stack
, flags
, ctst
,
696 child_tidptr
, parent_tidptr
);
698 VG_(sigprocmask
)(VKI_SIG_SETMASK
, &savedmask
, NULL
);
701 if (sr_isError(res
)) {
703 VG_(cleanup_thread
)(&ctst
->arch
);
704 ctst
->status
= VgTs_Empty
;
705 /* oops. Better tell the tool the thread exited in a hurry :-) */
706 VG_TRACK( pre_thread_ll_exit
, ctid
);
712 /* Do a clone which is really a fork().
713 ML_(do_fork_clone) uses the clone syscall to fork a child process.
714 Note that this should not be called for a thread creation.
715 Also, some flags combinations are not supported, and such combinations
716 are handled either by masking the non supported flags or by asserting.
718 The CLONE_VFORK flag is accepted, as this just tells that the parent is
719 suspended till the child exits or calls execve. We better keep this flag,
720 just in case the guests parent/client code depends on this synchronisation.
722 We cannot keep the flag CLONE_VM, as Valgrind will do whatever host
723 instructions in the child process, that will mess up the parent host
724 memory. So, we hope for the best and assumes that the guest application does
725 not (really) depends on sharing the memory between parent and child in the
726 interval between clone and exits/execve.
728 If child_sp != 0, the child (guest) sp will be set to child_sp just after the
729 clone syscall, before child guest instructions are executed. */
730 static SysRes
ML_(do_fork_clone
) ( ThreadId tid
, UInt flags
,
731 Int
* parent_tidptr
, Int
* child_tidptr
,
734 vki_sigset_t fork_saved_mask
;
738 if (flags
& (VKI_CLONE_SETTLS
| VKI_CLONE_FS
| VKI_CLONE_VM
740 return VG_(mk_SysRes_Error
)( VKI_EINVAL
);
742 /* Block all signals during fork, so that we can fix things up in
743 the child without being interrupted. */
744 VG_(sigfillset
)(&mask
);
745 VG_(sigprocmask
)(VKI_SIG_SETMASK
, &mask
, &fork_saved_mask
);
747 VG_(do_atfork_pre
)(tid
);
749 /* Since this is the fork() form of clone, we don't need all that
751 #if defined(VGP_x86_linux) \
752 || defined(VGP_ppc32_linux) \
753 || defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux) \
754 || defined(VGP_arm_linux) || defined(VGP_mips32_linux) \
755 || defined(VGP_mips64_linux) || defined(VGP_arm64_linux) \
756 || defined(VGP_nanomips_linux)
757 res
= VG_(do_syscall5
)( __NR_clone
, flags
,
758 (UWord
)NULL
, (UWord
)parent_tidptr
,
759 (UWord
)NULL
, (UWord
)child_tidptr
);
760 #elif defined(VGP_amd64_linux)
761 /* note that the last two arguments are the opposite way round to x86 and
762 ppc32 as the amd64 kernel expects the arguments in a different order */
763 res
= VG_(do_syscall5
)( __NR_clone
, flags
,
764 (UWord
)NULL
, (UWord
)parent_tidptr
,
765 (UWord
)child_tidptr
, (UWord
)NULL
);
766 #elif defined(VGP_s390x_linux)
767 /* Note that s390 has the stack first and then the flags */
768 res
= VG_(do_syscall4
)( __NR_clone
, (UWord
) NULL
, flags
,
769 (UWord
)parent_tidptr
, (UWord
)child_tidptr
);
771 # error Unknown platform
774 if (!sr_isError(res
) && sr_Res(res
) == 0) {
777 VG_(set_SP
)(tid
, child_sp
);
778 VG_(do_atfork_child
)(tid
);
780 /* restore signal mask */
781 VG_(sigprocmask
)(VKI_SIG_SETMASK
, &fork_saved_mask
, NULL
);
784 if (!sr_isError(res
) && sr_Res(res
) > 0) {
786 VG_(do_atfork_parent
)(tid
);
788 if (VG_(clo_trace_syscalls
))
789 VG_(printf
)(" clone(fork): process %d created child %" FMT_REGWORD
"u\n",
790 VG_(getpid
)(), (RegWord
)sr_Res(res
));
792 /* restore signal mask */
793 VG_(sigprocmask
)(VKI_SIG_SETMASK
, &fork_saved_mask
, NULL
);
799 /* ---------------------------------------------------------------------
800 PRE/POST wrappers for arch-generic, Linux-specific syscalls
801 ------------------------------------------------------------------ */
803 // Nb: See the comment above the generic PRE/POST wrappers in
804 // m_syswrap/syswrap-generic.c for notes about how they work.
806 #define PRE(name) DEFN_PRE_TEMPLATE(linux, name)
807 #define POST(name) DEFN_POST_TEMPLATE(linux, name)
814 PRINT("sys_clone ( %" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
815 "x, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
,
818 // Order of arguments differs between platforms.
819 #if defined(VGP_x86_linux) \
820 || defined(VGP_ppc32_linux) \
821 || defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux) \
822 || defined(VGP_arm_linux) || defined(VGP_mips32_linux) \
823 || defined(VGP_mips64_linux) || defined(VGP_arm64_linux) \
824 || defined(VGP_nanomips_linux)
825 #define ARG_CHILD_TIDPTR ARG5
826 #define PRA_CHILD_TIDPTR PRA5
829 #elif defined(VGP_amd64_linux) || defined(VGP_s390x_linux)
830 #define ARG_CHILD_TIDPTR ARG4
831 #define PRA_CHILD_TIDPTR PRA4
835 # error Unknown platform
837 // And s390x is even more special, and inverts flags and child stack args
838 #if defined(VGP_s390x_linux)
839 #define ARG_FLAGS ARG2
840 #define PRA_FLAGS PRA2
841 #define ARG_CHILD_STACK ARG1
842 #define PRA_CHILD_STACK PRA1
844 #define ARG_FLAGS ARG1
845 #define PRA_FLAGS PRA1
846 #define ARG_CHILD_STACK ARG2
847 #define PRA_CHILD_STACK PRA2
850 if (VG_(tdict
).track_pre_reg_read
) {
851 PRA_FLAGS("clone", unsigned long, flags
);
852 PRA_CHILD_STACK("clone", void *, child_stack
);
855 if (ARG_FLAGS
& VKI_CLONE_PARENT_SETTID
) {
856 if (VG_(tdict
).track_pre_reg_read
) {
857 PRA3("clone", int *, parent_tidptr
);
859 PRE_MEM_WRITE("clone(parent_tidptr)", ARG3
, sizeof(Int
));
860 if (!VG_(am_is_valid_for_client
)(ARG3
, sizeof(Int
),
865 if (ARG_FLAGS
& VKI_CLONE_SETTLS
) {
866 if (VG_(tdict
).track_pre_reg_read
) {
867 PRA_TLS("clone", vki_modify_ldt_t
*, tlsinfo
);
869 /* Not very clear what is vki_modify_ldt_t: for many platforms, it is a
870 dummy type (that we define as a char). We only dereference/check the
871 ARG_TLS pointer if the type looks like a real type, i.e. sizeof > 1. */
872 if (sizeof(vki_modify_ldt_t
) > 1) {
873 PRE_MEM_READ("clone(tlsinfo)", ARG_TLS
, sizeof(vki_modify_ldt_t
));
874 if (!VG_(am_is_valid_for_client
)(ARG_TLS
, sizeof(vki_modify_ldt_t
),
880 if (ARG_FLAGS
& (VKI_CLONE_CHILD_SETTID
| VKI_CLONE_CHILD_CLEARTID
)) {
881 if (VG_(tdict
).track_pre_reg_read
) {
882 PRA_CHILD_TIDPTR("clone", int *, child_tidptr
);
884 PRE_MEM_WRITE("clone(child_tidptr)", ARG_CHILD_TIDPTR
, sizeof(Int
));
885 if (!VG_(am_is_valid_for_client
)(ARG_CHILD_TIDPTR
, sizeof(Int
),
892 SET_STATUS_Failure( VKI_EFAULT
);
896 cloneflags
= ARG_FLAGS
;
898 if (!ML_(client_signal_OK
)(ARG_FLAGS
& VKI_CSIGNAL
)) {
899 SET_STATUS_Failure( VKI_EINVAL
);
903 /* Only look at the flags we really care about */
904 switch (cloneflags
& (VKI_CLONE_VM
| VKI_CLONE_FS
905 | VKI_CLONE_FILES
| VKI_CLONE_VFORK
)) {
906 case VKI_CLONE_VM
| VKI_CLONE_FS
| VKI_CLONE_FILES
:
907 /* thread creation */
908 SET_STATUS_from_SysRes(
910 ARG_FLAGS
, /* flags */
911 (Addr
)ARG_CHILD_STACK
, /* child ESP */
912 (Int
*)(Addr
)ARG3
, /* parent_tidptr */
913 (Int
*)(Addr
)ARG_CHILD_TIDPTR
, /* child_tidptr */
914 (Addr
)ARG_TLS
)); /* set_tls */
917 case VKI_CLONE_VFORK
| VKI_CLONE_VM
: /* vfork */
918 cloneflags
&= ~VKI_CLONE_VM
;
919 // FALLTHROUGH - assume vfork (somewhat) == fork, see ML_(do_fork_clone).
921 case 0: /* plain fork */
922 SET_STATUS_from_SysRes(
923 ML_(do_fork_clone
)(tid
,
924 cloneflags
, /* flags */
925 (Int
*)(Addr
)ARG3
, /* parent_tidptr */
926 (Int
*)(Addr
)ARG_CHILD_TIDPTR
, /* child_tidptr */
927 (Addr
)ARG_CHILD_STACK
));
931 /* should we just ENOSYS? */
932 VG_(message
)(Vg_UserMsg
, "Unsupported clone() flags: 0x%" FMT_REGWORD
934 VG_(message
)(Vg_UserMsg
, "\n");
935 VG_(message
)(Vg_UserMsg
, "The only supported clone() uses are:\n");
936 VG_(message
)(Vg_UserMsg
, " - via a threads library (LinuxThreads or NPTL)\n");
937 VG_(message
)(Vg_UserMsg
, " - via the implementation of fork or vfork\n");
939 ("Valgrind does not support general clone().");
943 if (ARG_FLAGS
& VKI_CLONE_PARENT_SETTID
)
944 POST_MEM_WRITE(ARG3
, sizeof(Int
));
945 if (ARG_FLAGS
& (VKI_CLONE_CHILD_SETTID
| VKI_CLONE_CHILD_CLEARTID
))
946 POST_MEM_WRITE(ARG_CHILD_TIDPTR
, sizeof(Int
));
948 /* Thread creation was successful; let the child have the chance
950 *flags
|= SfYieldAfter
;
953 #undef ARG_CHILD_TIDPTR
954 #undef PRA_CHILD_TIDPTR
959 #undef ARG_CHILD_STACK
960 #undef PRA_CHILD_STACK
963 /* ---------------------------------------------------------------------
965 ------------------------------------------------------------------ */
969 // Nb: depending on 'flags', the 'type' and 'data' args may be ignored.
970 // We are conservative and check everything, except the memory pointed to
972 *flags
|= SfMayBlock
;
973 PRINT("sys_mount( %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x(%s), %#"
974 FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
975 ARG1
, (HChar
*)(Addr
)ARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
,
976 (HChar
*)(Addr
)ARG3
, ARG4
, ARG5
);
977 PRE_REG_READ5(long, "mount",
978 char *, source
, char *, target
, char *, type
,
979 unsigned long, flags
, void *, data
);
981 PRE_MEM_RASCIIZ( "mount(source)", ARG1
);
982 PRE_MEM_RASCIIZ( "mount(target)", ARG2
);
983 PRE_MEM_RASCIIZ( "mount(type)", ARG3
);
988 PRINT("sys_oldumount( %#" FMT_REGWORD
"x )", ARG1
);
989 PRE_REG_READ1(long, "umount", char *, path
);
990 PRE_MEM_RASCIIZ( "umount(path)", ARG1
);
995 PRINT("sys_umount( %#" FMT_REGWORD
"x, %ld )", ARG1
, SARG2
);
996 PRE_REG_READ2(long, "umount2", char *, path
, int, flags
);
997 PRE_MEM_RASCIIZ( "umount2(path)", ARG1
);
1000 /* Not actually wrapped by GLibc but does things with the system
1001 * mounts so it is put here.
1005 PRINT("sys_pivot_root ( %s %s )", (HChar
*)(Addr
)ARG1
, (HChar
*)(Addr
)ARG2
);
1006 PRE_REG_READ2(int, "pivot_root", char *, new_root
, char *, old_root
);
1007 PRE_MEM_RASCIIZ( "pivot_root(new_root)", ARG1
);
1008 PRE_MEM_RASCIIZ( "pivot_root(old_root)", ARG2
);
1012 /* ---------------------------------------------------------------------
1013 16- and 32-bit uid/gid wrappers
1014 ------------------------------------------------------------------ */
1018 PRINT("sys_setfsuid16 ( %" FMT_REGWORD
"u )", ARG1
);
1019 PRE_REG_READ1(long, "setfsuid16", vki_old_uid_t
, uid
);
1024 PRINT("sys_setfsuid ( %" FMT_REGWORD
"u )", ARG1
);
1025 PRE_REG_READ1(long, "setfsuid", vki_uid_t
, uid
);
1030 PRINT("sys_setfsgid16 ( %" FMT_REGWORD
"u )", ARG1
);
1031 PRE_REG_READ1(long, "setfsgid16", vki_old_gid_t
, gid
);
1036 PRINT("sys_setfsgid ( %" FMT_REGWORD
"u )", ARG1
);
1037 PRE_REG_READ1(long, "setfsgid", vki_gid_t
, gid
);
1040 PRE(sys_setresuid16
)
1042 PRINT("sys_setresuid16 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
1043 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
1044 PRE_REG_READ3(long, "setresuid16",
1045 vki_old_uid_t
, ruid
, vki_old_uid_t
, euid
, vki_old_uid_t
, suid
);
1050 PRINT("sys_setresuid ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
1051 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
1052 PRE_REG_READ3(long, "setresuid",
1053 vki_uid_t
, ruid
, vki_uid_t
, euid
, vki_uid_t
, suid
);
1056 PRE(sys_getresuid16
)
1058 PRINT("sys_getresuid16 ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1059 FMT_REGWORD
"x )", ARG1
,ARG2
,ARG3
);
1060 PRE_REG_READ3(long, "getresuid16",
1061 vki_old_uid_t
*, ruid
, vki_old_uid_t
*, euid
,
1062 vki_old_uid_t
*, suid
);
1063 PRE_MEM_WRITE( "getresuid16(ruid)", ARG1
, sizeof(vki_old_uid_t
) );
1064 PRE_MEM_WRITE( "getresuid16(euid)", ARG2
, sizeof(vki_old_uid_t
) );
1065 PRE_MEM_WRITE( "getresuid16(suid)", ARG3
, sizeof(vki_old_uid_t
) );
1067 POST(sys_getresuid16
)
1071 POST_MEM_WRITE( ARG1
, sizeof(vki_old_uid_t
) );
1072 POST_MEM_WRITE( ARG2
, sizeof(vki_old_uid_t
) );
1073 POST_MEM_WRITE( ARG3
, sizeof(vki_old_uid_t
) );
1079 PRINT("sys_getresuid ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1080 FMT_REGWORD
"x )", ARG1
,ARG2
,ARG3
);
1081 PRE_REG_READ3(long, "getresuid",
1082 vki_uid_t
*, ruid
, vki_uid_t
*, euid
, vki_uid_t
*, suid
);
1083 PRE_MEM_WRITE( "getresuid(ruid)", ARG1
, sizeof(vki_uid_t
) );
1084 PRE_MEM_WRITE( "getresuid(euid)", ARG2
, sizeof(vki_uid_t
) );
1085 PRE_MEM_WRITE( "getresuid(suid)", ARG3
, sizeof(vki_uid_t
) );
1091 POST_MEM_WRITE( ARG1
, sizeof(vki_uid_t
) );
1092 POST_MEM_WRITE( ARG2
, sizeof(vki_uid_t
) );
1093 POST_MEM_WRITE( ARG3
, sizeof(vki_uid_t
) );
1097 PRE(sys_setresgid16
)
1099 PRINT("sys_setresgid16 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
1100 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
1101 PRE_REG_READ3(long, "setresgid16",
1102 vki_old_gid_t
, rgid
,
1103 vki_old_gid_t
, egid
, vki_old_gid_t
, sgid
);
1108 PRINT("sys_setresgid ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
1109 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
1110 PRE_REG_READ3(long, "setresgid",
1111 vki_gid_t
, rgid
, vki_gid_t
, egid
, vki_gid_t
, sgid
);
1114 PRE(sys_getresgid16
)
1116 PRINT("sys_getresgid16 ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1117 FMT_REGWORD
"x )", ARG1
,ARG2
,ARG3
);
1118 PRE_REG_READ3(long, "getresgid16",
1119 vki_old_gid_t
*, rgid
, vki_old_gid_t
*, egid
,
1120 vki_old_gid_t
*, sgid
);
1121 PRE_MEM_WRITE( "getresgid16(rgid)", ARG1
, sizeof(vki_old_gid_t
) );
1122 PRE_MEM_WRITE( "getresgid16(egid)", ARG2
, sizeof(vki_old_gid_t
) );
1123 PRE_MEM_WRITE( "getresgid16(sgid)", ARG3
, sizeof(vki_old_gid_t
) );
1125 POST(sys_getresgid16
)
1129 POST_MEM_WRITE( ARG1
, sizeof(vki_old_gid_t
) );
1130 POST_MEM_WRITE( ARG2
, sizeof(vki_old_gid_t
) );
1131 POST_MEM_WRITE( ARG3
, sizeof(vki_old_gid_t
) );
1137 PRINT("sys_getresgid ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1138 FMT_REGWORD
"x )", ARG1
,ARG2
,ARG3
);
1139 PRE_REG_READ3(long, "getresgid",
1140 vki_gid_t
*, rgid
, vki_gid_t
*, egid
, vki_gid_t
*, sgid
);
1141 PRE_MEM_WRITE( "getresgid(rgid)", ARG1
, sizeof(vki_gid_t
) );
1142 PRE_MEM_WRITE( "getresgid(egid)", ARG2
, sizeof(vki_gid_t
) );
1143 PRE_MEM_WRITE( "getresgid(sgid)", ARG3
, sizeof(vki_gid_t
) );
1149 POST_MEM_WRITE( ARG1
, sizeof(vki_gid_t
) );
1150 POST_MEM_WRITE( ARG2
, sizeof(vki_gid_t
) );
1151 POST_MEM_WRITE( ARG3
, sizeof(vki_gid_t
) );
1155 /* ---------------------------------------------------------------------
1156 miscellaneous wrappers
1157 ------------------------------------------------------------------ */
1164 PRINT("exit_group( %ld )", SARG1
);
1165 PRE_REG_READ1(void, "exit_group", int, status
);
1167 tst
= VG_(get_ThreadState
)(tid
);
1168 /* A little complex; find all the threads with the same threadgroup
1169 as this one (including this one), and mark them to exit */
1170 /* It is unclear how one can get a threadgroup in this process which
1171 is not the threadgroup of the calling thread:
1172 The assignments to threadgroups are:
1173 = 0; /// scheduler.c os_state_clear
1174 = getpid(); /// scheduler.c in child after fork
1175 = getpid(); /// this file, in thread_wrapper
1176 = ptst->os_state.threadgroup; /// syswrap-*-linux.c,
1177 copying the thread group of the thread doing clone
1178 So, the only case where the threadgroup might be different to the getpid
1179 value is in the child, just after fork. But then the fork syscall is
1180 still going on, the forked thread has had no chance yet to make this
1182 for (t
= 1; t
< VG_N_THREADS
; t
++) {
1183 if ( /* not alive */
1184 VG_(threads
)[t
].status
== VgTs_Empty
1187 VG_(threads
)[t
].os_state
.threadgroup
!= tst
->os_state
.threadgroup
1190 /* Assign the exit code, VG_(nuke_all_threads_except) will assign
1192 VG_(threads
)[t
].os_state
.exitcode
= ARG1
;
1195 /* Indicate in all other threads that the process is exiting.
1196 Then wait using VG_(reap_threads) for these threads to disappear.
1198 Can this give a deadlock if another thread is calling exit in parallel
1199 and would then wait for this thread to disappear ?
1201 Other threads are either blocked in a syscall or have yielded the CPU.
1203 A thread that has yielded the CPU is trying to get the big lock in
1204 VG_(scheduler). This thread will get the CPU thanks to the call
1205 to VG_(reap_threads). The scheduler will then check for signals,
1206 kill the process if this is a fatal signal, and otherwise prepare
1207 the thread for handling this signal. After this preparation, if
1208 the thread status is VG_(is_exiting), the scheduler exits the thread.
1209 So, a thread that has yielded the CPU does not have a chance to
1210 call exit => no deadlock for this thread.
1212 VG_(nuke_all_threads_except) will send the VG_SIGVGKILL signal
1213 to all threads blocked in a syscall.
1214 The syscall will be interrupted, and the control will go to the
1215 scheduler. The scheduler will then return, as the thread is in
1218 VG_(nuke_all_threads_except
)( tid
, VgSrc_ExitProcess
);
1219 VG_(reap_threads
)(tid
);
1220 VG_(threads
)[tid
].exitreason
= VgSrc_ExitThread
;
1221 /* we do assign VgSrc_ExitThread and not VgSrc_ExitProcess, as this thread
1222 is the thread calling exit_group and so its registers must be considered
1223 as not reachable. See pub_tool_machine.h VG_(apply_to_GP_regs). */
1225 /* We have to claim the syscall already succeeded. */
1226 SET_STATUS_Success(0);
1231 PRINT("sys_llseek ( %" FMT_REGWORD
"u, 0x%" FMT_REGWORD
"x, 0x%"
1232 FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
1233 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
);
1234 PRE_REG_READ5(long, "llseek",
1235 unsigned int, fd
, unsigned long, offset_high
,
1236 unsigned long, offset_low
, vki_loff_t
*, result
,
1237 unsigned int, whence
);
1238 if (!ML_(fd_allowed
)(ARG1
, "llseek", tid
, False
))
1239 SET_STATUS_Failure( VKI_EBADF
);
1241 PRE_MEM_WRITE( "llseek(result)", ARG4
, sizeof(vki_loff_t
));
1247 POST_MEM_WRITE( ARG4
, sizeof(vki_loff_t
) );
1252 struct vki_timex
*tx
= (struct vki_timex
*)(Addr
)ARG1
;
1253 PRINT("sys_adjtimex ( %#" FMT_REGWORD
"x )", ARG1
);
1254 PRE_REG_READ1(long, "adjtimex", struct timex
*, buf
);
1256 if (ML_(safe_to_deref
) (tx
, sizeof(struct vki_timex
))) {
1257 PRE_MEM_READ( "adjtimex(timex->modes)", ARG1
, sizeof(tx
->modes
));
1259 #define ADJX(bits,field) \
1260 if (tx->modes & (bits)) \
1261 PRE_MEM_READ( "adjtimex(timex->"#field")", \
1262 (Addr)&tx->field, sizeof(tx->field))
1264 if (tx
->modes
& VKI_ADJ_ADJTIME
) {
1265 if (!(tx
->modes
& VKI_ADJ_OFFSET_READONLY
))
1266 PRE_MEM_READ( "adjtimex(timex->offset)", (Addr
)&tx
->offset
, sizeof(tx
->offset
));
1268 ADJX(VKI_ADJ_OFFSET
, offset
);
1269 ADJX(VKI_ADJ_FREQUENCY
, freq
);
1270 ADJX(VKI_ADJ_MAXERROR
, maxerror
);
1271 ADJX(VKI_ADJ_ESTERROR
, esterror
);
1272 ADJX(VKI_ADJ_STATUS
, status
);
1273 ADJX(VKI_ADJ_TIMECONST
|VKI_ADJ_TAI
, constant
);
1274 ADJX(VKI_ADJ_TICK
, tick
);
1279 PRE_MEM_WRITE( "adjtimex(timex)", ARG1
, sizeof(struct vki_timex
));
1284 POST_MEM_WRITE( ARG1
, sizeof(struct vki_timex
) );
1287 PRE(sys_clock_adjtime
)
1289 struct vki_timex
*tx
= (struct vki_timex
*)(Addr
)ARG2
;
1290 PRINT("sys_clock_adjtime ( %ld, %#" FMT_REGWORD
"x )", SARG1
,ARG2
);
1291 PRE_REG_READ2(long, "clock_adjtime", vki_clockid_t
, id
, struct timex
*, buf
);
1292 PRE_MEM_READ( "clock_adjtime(timex->modes)", ARG2
, sizeof(tx
->modes
));
1294 if (ML_(safe_to_deref
) (tx
, sizeof(struct vki_timex
))) {
1295 PRE_MEM_READ( "clock_adjtime(timex->modes)", ARG2
, sizeof(tx
->modes
));
1297 #define ADJX(bits,field) \
1298 if (tx->modes & (bits)) \
1299 PRE_MEM_READ( "clock_adjtime(timex->"#field")", \
1300 (Addr)&tx->field, sizeof(tx->field))
1302 if (tx
->modes
& VKI_ADJ_ADJTIME
) {
1303 if (!(tx
->modes
& VKI_ADJ_OFFSET_READONLY
))
1304 PRE_MEM_READ( "clock_adjtime(timex->offset)", (Addr
)&tx
->offset
, sizeof(tx
->offset
));
1306 ADJX(VKI_ADJ_OFFSET
, offset
);
1307 ADJX(VKI_ADJ_FREQUENCY
, freq
);
1308 ADJX(VKI_ADJ_MAXERROR
, maxerror
);
1309 ADJX(VKI_ADJ_ESTERROR
, esterror
);
1310 ADJX(VKI_ADJ_STATUS
, status
);
1311 ADJX(VKI_ADJ_TIMECONST
|VKI_ADJ_TAI
, constant
);
1312 ADJX(VKI_ADJ_TICK
, tick
);
1317 PRE_MEM_WRITE( "adjtimex(timex)", ARG2
, sizeof(struct vki_timex
));
1320 POST(sys_clock_adjtime
)
1322 POST_MEM_WRITE( ARG2
, sizeof(struct vki_timex
) );
1327 PRINT("sys_ioperm ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %ld )",
1328 ARG1
, ARG2
, SARG3
);
1329 PRE_REG_READ3(long, "ioperm",
1330 unsigned long, from
, unsigned long, num
, int, turn_on
);
1335 *flags
|= SfMayBlock
;
1336 PRINT("sys_syslog (%ld, %#" FMT_REGWORD
"x, %ld)", SARG1
, ARG2
, SARG3
);
1337 PRE_REG_READ3(long, "syslog", int, type
, char *, bufp
, int, len
);
1339 // The kernel uses magic numbers here, rather than named constants,
1340 // therefore so do we.
1341 case 2: case 3: case 4:
1342 PRE_MEM_WRITE( "syslog(bufp)", ARG2
, ARG3
);
1351 case 2: case 3: case 4:
1352 POST_MEM_WRITE( ARG2
, ARG3
);
1361 PRINT("sys_vhangup ( )");
1362 PRE_REG_READ0(long, "vhangup");
1367 PRINT("sys_sysinfo ( %#" FMT_REGWORD
"x )",ARG1
);
1368 PRE_REG_READ1(long, "sysinfo", struct sysinfo
*, info
);
1369 PRE_MEM_WRITE( "sysinfo(info)", ARG1
, sizeof(struct vki_sysinfo
) );
1373 POST_MEM_WRITE( ARG1
, sizeof(struct vki_sysinfo
) );
1376 PRE(sys_personality
)
1378 PRINT("sys_personality ( %llu )", (ULong
)ARG1
);
1379 PRE_REG_READ1(long, "personality", vki_u_long
, persona
);
1384 struct __vki_sysctl_args
*args
;
1385 PRINT("sys_sysctl ( %#" FMT_REGWORD
"x )", ARG1
);
1386 args
= (struct __vki_sysctl_args
*)(Addr
)ARG1
;
1387 PRE_REG_READ1(long, "sysctl", struct __sysctl_args
*, args
);
1388 PRE_MEM_WRITE( "sysctl(args)", ARG1
, sizeof(struct __vki_sysctl_args
) );
1389 if (!VG_(am_is_valid_for_client
)(ARG1
, sizeof(struct __vki_sysctl_args
),
1391 SET_STATUS_Failure( VKI_EFAULT
);
1395 PRE_MEM_READ("sysctl(name)", (Addr
)args
->name
, args
->nlen
* sizeof(*args
->name
));
1396 if (args
->newval
!= NULL
)
1397 PRE_MEM_READ("sysctl(newval)", (Addr
)args
->newval
, args
->newlen
);
1398 if (args
->oldlenp
!= NULL
) {
1399 PRE_MEM_READ("sysctl(oldlenp)", (Addr
)args
->oldlenp
, sizeof(*args
->oldlenp
));
1400 PRE_MEM_WRITE("sysctl(oldval)", (Addr
)args
->oldval
, *args
->oldlenp
);
1405 struct __vki_sysctl_args
*args
;
1406 args
= (struct __vki_sysctl_args
*)(Addr
)ARG1
;
1407 if (args
->oldlenp
!= NULL
) {
1408 POST_MEM_WRITE((Addr
)args
->oldlenp
, sizeof(*args
->oldlenp
));
1409 POST_MEM_WRITE((Addr
)args
->oldval
, 1 + *args
->oldlenp
);
1413 static void pre_asciiz_str(ThreadId tid
, Addr str
, SizeT maxlen
,
1414 const char *attr_name
)
1416 const HChar
*step_str
= (const HChar
*)str
;
1421 * The name can be up to maxlen bytes long, including the terminating null
1422 * byte. So do not check more than maxlen bytes.
1424 if (ML_(safe_to_deref
)((const HChar
*)str
, maxlen
)) {
1425 len
= VG_(strnlen
)((const HChar
*)str
, maxlen
);
1427 PRE_MEM_RASCIIZ(attr_name
, str
);
1429 PRE_MEM_READ(attr_name
, str
, maxlen
);
1432 * Do it the slow way, one byte at a time, while checking for terminating
1435 for (i
= 0; i
< maxlen
; i
++) {
1436 PRE_MEM_READ(attr_name
, (Addr
)&step_str
[i
], 1);
1437 if (!ML_(safe_to_deref
)(&step_str
[i
], 1) || step_str
[i
] == '\0')
1445 *flags
|= SfMayBlock
;
1446 PRINT( "sys_prctl ( %ld, %ld, %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
, SARG4
, SARG5
);
1448 case VKI_PR_SET_PDEATHSIG
:
1449 PRE_REG_READ2(int, "prctl", int, option
, int, signal
);
1451 case VKI_PR_GET_PDEATHSIG
:
1452 PRE_REG_READ2(int, "prctl", int, option
, int *, signal
);
1453 PRE_MEM_WRITE("prctl(get-death-signal)", ARG2
, sizeof(Int
));
1455 case VKI_PR_GET_DUMPABLE
:
1456 PRE_REG_READ1(int, "prctl", int, option
);
1458 case VKI_PR_SET_DUMPABLE
:
1459 PRE_REG_READ2(int, "prctl", int, option
, int, dump
);
1461 case VKI_PR_GET_UNALIGN
:
1462 PRE_REG_READ2(int, "prctl", int, option
, int *, value
);
1463 PRE_MEM_WRITE("prctl(get-unalign)", ARG2
, sizeof(Int
));
1465 case VKI_PR_SET_UNALIGN
:
1466 PRE_REG_READ2(int, "prctl", int, option
, int, value
);
1468 case VKI_PR_GET_KEEPCAPS
:
1469 PRE_REG_READ1(int, "prctl", int, option
);
1471 case VKI_PR_SET_KEEPCAPS
:
1472 PRE_REG_READ2(int, "prctl", int, option
, int, keepcaps
);
1474 case VKI_PR_GET_FPEMU
:
1475 PRE_REG_READ2(int, "prctl", int, option
, int *, value
);
1476 PRE_MEM_WRITE("prctl(get-fpemu)", ARG2
, sizeof(Int
));
1478 case VKI_PR_SET_FPEMU
:
1479 PRE_REG_READ2(int, "prctl", int, option
, int, value
);
1481 case VKI_PR_GET_FPEXC
:
1482 PRE_REG_READ2(int, "prctl", int, option
, int *, value
);
1483 PRE_MEM_WRITE("prctl(get-fpexc)", ARG2
, sizeof(Int
));
1485 case VKI_PR_SET_FPEXC
:
1486 PRE_REG_READ2(int, "prctl", int, option
, int, value
);
1488 case VKI_PR_GET_TIMING
:
1489 PRE_REG_READ1(int, "prctl", int, option
);
1491 case VKI_PR_SET_TIMING
:
1492 PRE_REG_READ2(int, "prctl", int, option
, int, timing
);
1494 case VKI_PR_SET_NAME
:
1495 PRE_REG_READ2(int, "prctl", int, option
, char *, name
);
1496 pre_asciiz_str(tid
, ARG2
, VKI_TASK_COMM_LEN
, "prctl(set-name)");
1498 case VKI_PR_GET_NAME
:
1499 PRE_REG_READ2(int, "prctl", int, option
, char *, name
);
1500 PRE_MEM_WRITE("prctl(get-name)", ARG2
, VKI_TASK_COMM_LEN
);
1502 case VKI_PR_GET_ENDIAN
:
1503 PRE_REG_READ2(int, "prctl", int, option
, int *, value
);
1504 PRE_MEM_WRITE("prctl(get-endian)", ARG2
, sizeof(Int
));
1506 case VKI_PR_SET_ENDIAN
:
1507 PRE_REG_READ2(int, "prctl", int, option
, int, value
);
1509 case VKI_PR_SET_PTRACER
:
1510 PRE_REG_READ2(int, "prctl", int, option
, int, ptracer_process_ID
);
1512 case VKI_PR_SET_SECCOMP
:
1513 /* This is a bit feeble in that it uses |option| before checking
1514 it, but at least both sides of the conditional check it. */
1515 if (ARG2
== VKI_SECCOMP_MODE_FILTER
) {
1516 PRE_REG_READ3(int, "prctl", int, option
, int, mode
, char*, filter
);
1518 /* Should check that ARG3 points at a valid struct sock_fprog.
1519 Sounds complex; hence be lame. */
1520 PRE_MEM_READ( "prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, filter)",
1524 PRE_REG_READ2(int, "prctl", int, option
, int, mode
);
1528 PRE_REG_READ5(long, "prctl",
1529 int, option
, unsigned long, arg2
, unsigned long, arg3
,
1530 unsigned long, arg4
, unsigned long, arg5
);
1537 case VKI_PR_GET_PDEATHSIG
:
1538 POST_MEM_WRITE(ARG2
, sizeof(Int
));
1540 case VKI_PR_GET_UNALIGN
:
1541 POST_MEM_WRITE(ARG2
, sizeof(Int
));
1543 case VKI_PR_GET_FPEMU
:
1544 POST_MEM_WRITE(ARG2
, sizeof(Int
));
1546 case VKI_PR_GET_FPEXC
:
1547 POST_MEM_WRITE(ARG2
, sizeof(Int
));
1549 case VKI_PR_GET_NAME
:
1550 POST_MEM_WRITE(ARG2
, VKI_TASK_COMM_LEN
);
1552 case VKI_PR_GET_ENDIAN
:
1553 POST_MEM_WRITE(ARG2
, sizeof(Int
));
1555 case VKI_PR_SET_NAME
:
1557 const HChar
* new_name
= (const HChar
*) (Addr
)ARG2
;
1558 if (new_name
) { // Paranoia
1559 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
1560 SizeT new_len
= VG_(strnlen
)(new_name
, VKI_TASK_COMM_LEN
);
1562 /* Don't bother reusing the memory. This is a rare event. */
1564 VG_(realloc
)("syswrap.prctl", tst
->thread_name
, new_len
+ 1);
1565 VG_(strlcpy
)(tst
->thread_name
, new_name
, new_len
+ 1);
1574 *flags
|= SfMayBlock
;
1575 PRINT("sys_sendfile ( %ld, %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
1576 SARG1
, SARG2
, ARG3
, ARG4
);
1577 PRE_REG_READ4(ssize_t
, "sendfile",
1578 int, out_fd
, int, in_fd
, vki_off_t
*, offset
,
1581 PRE_MEM_WRITE( "sendfile(offset)", ARG3
, sizeof(vki_off_t
) );
1586 POST_MEM_WRITE( ARG3
, sizeof( vki_off_t
) );
1592 *flags
|= SfMayBlock
;
1593 PRINT("sendfile64 ( %ld, %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
1594 SARG1
, SARG2
, ARG3
, ARG4
);
1595 PRE_REG_READ4(ssize_t
, "sendfile64",
1596 int, out_fd
, int, in_fd
, vki_loff_t
*, offset
,
1599 PRE_MEM_WRITE( "sendfile64(offset)", ARG3
, sizeof(vki_loff_t
) );
1601 POST(sys_sendfile64
)
1604 POST_MEM_WRITE( ARG3
, sizeof(vki_loff_t
) );
1611 arg param used by ops
1613 ARG1 - u32 *futex all
1615 ARG3 - int val WAIT,WAKE,FD,REQUEUE,CMP_REQUEUE
1616 ARG4 - struct timespec *utime WAIT:time* REQUEUE,CMP_REQUEUE:val2
1617 ARG5 - u32 *uaddr2 REQUEUE,CMP_REQUEUE
1618 ARG6 - int val3 CMP_REQUEUE
1620 PRINT("sys_futex ( %#" FMT_REGWORD
"x, %ld, %ld, %#" FMT_REGWORD
1621 "x, %#" FMT_REGWORD
"x )", ARG1
, SARG2
, SARG3
, ARG4
, ARG5
);
1622 switch(ARG2
& ~(VKI_FUTEX_PRIVATE_FLAG
|VKI_FUTEX_CLOCK_REALTIME
)) {
1623 case VKI_FUTEX_CMP_REQUEUE
:
1624 case VKI_FUTEX_WAKE_OP
:
1625 case VKI_FUTEX_CMP_REQUEUE_PI
:
1626 PRE_REG_READ6(long, "futex",
1627 vki_u32
*, futex
, int, op
, int, val
,
1628 struct timespec
*, utime
, vki_u32
*, uaddr2
, int, val3
);
1630 case VKI_FUTEX_REQUEUE
:
1631 case VKI_FUTEX_WAIT_REQUEUE_PI
:
1632 PRE_REG_READ5(long, "futex",
1633 vki_u32
*, futex
, int, op
, int, val
,
1634 struct timespec
*, utime
, vki_u32
*, uaddr2
);
1636 case VKI_FUTEX_WAIT_BITSET
:
1637 /* Check that the address at least begins in client-accessible area. */
1638 if (!VG_(am_is_valid_for_client
)( ARG1
, 1, VKI_PROT_READ
)) {
1639 SET_STATUS_Failure( VKI_EFAULT
);
1642 if (*(vki_u32
*)(Addr
)ARG1
!= ARG3
) {
1643 PRE_REG_READ4(long, "futex",
1644 vki_u32
*, futex
, int, op
, int, val
,
1645 struct timespec
*, utime
);
1647 /* Note argument 5 is unused, but argument 6 is used.
1648 So we cannot just PRE_REG_READ6. Read argument 6 separately. */
1649 PRE_REG_READ4(long, "futex",
1650 vki_u32
*, futex
, int, op
, int, val
,
1651 struct timespec
*, utime
);
1652 if (VG_(tdict
).track_pre_reg_read
)
1653 PRA6("futex",int,val3
);
1656 case VKI_FUTEX_WAKE_BITSET
:
1657 PRE_REG_READ3(long, "futex",
1658 vki_u32
*, futex
, int, op
, int, val
);
1659 if (VG_(tdict
).track_pre_reg_read
) {
1660 PRA6("futex", int, val3
);
1663 case VKI_FUTEX_WAIT
:
1664 case VKI_FUTEX_LOCK_PI
:
1665 PRE_REG_READ4(long, "futex",
1666 vki_u32
*, futex
, int, op
, int, val
,
1667 struct timespec
*, utime
);
1669 case VKI_FUTEX_WAKE
:
1671 PRE_REG_READ3(long, "futex",
1672 vki_u32
*, futex
, int, op
, int, val
);
1674 case VKI_FUTEX_TRYLOCK_PI
:
1675 case VKI_FUTEX_UNLOCK_PI
:
1677 PRE_REG_READ2(long, "futex", vki_u32
*, futex
, int, op
);
1681 *flags
|= SfMayBlock
;
1683 switch(ARG2
& ~(VKI_FUTEX_PRIVATE_FLAG
|VKI_FUTEX_CLOCK_REALTIME
)) {
1684 case VKI_FUTEX_WAIT
:
1685 case VKI_FUTEX_LOCK_PI
:
1686 case VKI_FUTEX_WAIT_BITSET
:
1687 case VKI_FUTEX_WAIT_REQUEUE_PI
:
1688 PRE_MEM_READ( "futex(futex)", ARG1
, sizeof(Int
) );
1690 PRE_MEM_READ( "futex(timeout)", ARG4
, sizeof(struct vki_timespec
) );
1693 case VKI_FUTEX_REQUEUE
:
1694 case VKI_FUTEX_CMP_REQUEUE
:
1695 case VKI_FUTEX_CMP_REQUEUE_PI
:
1696 case VKI_FUTEX_WAKE_OP
:
1697 PRE_MEM_READ( "futex(futex)", ARG1
, sizeof(Int
) );
1698 PRE_MEM_READ( "futex(futex2)", ARG5
, sizeof(Int
) );
1702 case VKI_FUTEX_TRYLOCK_PI
:
1703 case VKI_FUTEX_UNLOCK_PI
:
1704 case VKI_FUTEX_WAKE
:
1705 case VKI_FUTEX_WAKE_BITSET
:
1706 PRE_MEM_READ( "futex(futex)", ARG1
, sizeof(Int
) );
1710 SET_STATUS_Failure( VKI_ENOSYS
); // some futex function we don't understand
1717 POST_MEM_WRITE( ARG1
, sizeof(int) );
1718 if (ARG2
== VKI_FUTEX_FD
) {
1719 if (!ML_(fd_allowed
)(RES
, "futex", tid
, True
)) {
1721 SET_STATUS_Failure( VKI_EMFILE
);
1723 if (VG_(clo_track_fds
))
1724 ML_(record_fd_open_nameless
)(tid
, RES
);
1729 PRE(sys_set_robust_list
)
1731 PRINT("sys_set_robust_list ( %#" FMT_REGWORD
"x, %"
1732 FMT_REGWORD
"u )", ARG1
, ARG2
);
1733 PRE_REG_READ2(long, "set_robust_list",
1734 struct vki_robust_list_head
*, head
, vki_size_t
, len
);
1736 /* Just check the robust_list_head structure is readable - don't
1737 try and chase the list as the kernel will only read it when
1738 the thread exits so the current contents is irrelevant. */
1740 PRE_MEM_READ("set_robust_list(head)", ARG1
, ARG2
);
1743 PRE(sys_get_robust_list
)
1745 PRINT("sys_get_robust_list ( %ld, %#" FMT_REGWORD
"x, %#"
1746 FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
);
1747 PRE_REG_READ3(long, "get_robust_list",
1749 struct vki_robust_list_head
**, head_ptr
,
1750 vki_size_t
*, len_ptr
);
1751 PRE_MEM_WRITE("get_robust_list(head_ptr)",
1752 ARG2
, sizeof(struct vki_robust_list_head
*));
1753 PRE_MEM_WRITE("get_robust_list(len_ptr)",
1754 ARG3
, sizeof(struct vki_size_t
*));
1756 POST(sys_get_robust_list
)
1758 POST_MEM_WRITE(ARG2
, sizeof(struct vki_robust_list_head
*));
1759 POST_MEM_WRITE(ARG3
, sizeof(struct vki_size_t
*));
1762 struct pselect_sized_sigset
{
1763 const vki_sigset_t
*ss
;
1766 struct pselect_adjusted_sigset
{
1767 struct pselect_sized_sigset ss
; /* The actual syscall arg */
1768 vki_sigset_t adjusted_ss
;
1773 *flags
|= SfMayBlock
| SfPostOnFail
;
1774 PRINT("sys_pselect6 ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
1775 FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
1776 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
1777 PRE_REG_READ6(long, "pselect6",
1778 int, n
, vki_fd_set
*, readfds
, vki_fd_set
*, writefds
,
1779 vki_fd_set
*, exceptfds
, struct vki_timeval
*, timeout
,
1781 // XXX: this possibly understates how much memory is read.
1783 PRE_MEM_READ( "pselect6(readfds)",
1784 ARG2
, ARG1
/8 /* __FD_SETSIZE/8 */ );
1786 PRE_MEM_READ( "pselect6(writefds)",
1787 ARG3
, ARG1
/8 /* __FD_SETSIZE/8 */ );
1789 PRE_MEM_READ( "pselect6(exceptfds)",
1790 ARG4
, ARG1
/8 /* __FD_SETSIZE/8 */ );
1792 PRE_MEM_READ( "pselect6(timeout)", ARG5
, sizeof(struct vki_timeval
) );
1794 const struct pselect_sized_sigset
*pss
=
1795 (struct pselect_sized_sigset
*)(Addr
)ARG6
;
1796 PRE_MEM_READ( "pselect6(sig)", ARG6
, sizeof(*pss
) );
1797 if (!ML_(safe_to_deref
)(pss
, sizeof(*pss
))) {
1798 ARG6
= 1; /* Something recognisable to POST() hook. */
1800 struct pselect_adjusted_sigset
*pas
;
1801 pas
= VG_(malloc
)("syswrap.pselect6.1", sizeof(*pas
));
1803 pas
->ss
.ss
= (void *)1;
1804 pas
->ss
.ss_len
= pss
->ss_len
;
1805 if (pss
->ss_len
== sizeof(*pss
->ss
)) {
1806 if (pss
->ss
== NULL
) {
1809 PRE_MEM_READ("pselect6(sig->ss)", (Addr
)pss
->ss
, pss
->ss_len
);
1810 if (ML_(safe_to_deref
)(pss
->ss
, sizeof(*pss
->ss
))) {
1811 pas
->adjusted_ss
= *pss
->ss
;
1812 pas
->ss
.ss
= &pas
->adjusted_ss
;
1813 VG_(sanitize_client_sigmask
)(&pas
->adjusted_ss
);
1822 if (ARG6
!= 0 && ARG6
!= 1) {
1823 VG_(free
)((struct pselect_adjusted_sigset
*)(Addr
)ARG6
);
1830 struct vki_pollfd
* ufds
= (struct vki_pollfd
*)(Addr
)ARG1
;
1831 *flags
|= SfMayBlock
| SfPostOnFail
;
1832 PRINT("sys_ppoll ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#" FMT_REGWORD
1833 "x, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )\n",
1834 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
);
1835 PRE_REG_READ5(long, "ppoll",
1836 struct vki_pollfd
*, ufds
, unsigned int, nfds
,
1837 struct vki_timespec
*, tsp
, vki_sigset_t
*, sigmask
,
1838 vki_size_t
, sigsetsize
);
1840 for (i
= 0; i
< ARG2
; i
++) {
1841 PRE_MEM_READ( "ppoll(ufds.fd)",
1842 (Addr
)(&ufds
[i
].fd
), sizeof(ufds
[i
].fd
) );
1843 PRE_MEM_READ( "ppoll(ufds.events)",
1844 (Addr
)(&ufds
[i
].events
), sizeof(ufds
[i
].events
) );
1845 PRE_MEM_WRITE( "ppoll(ufds.revents)",
1846 (Addr
)(&ufds
[i
].revents
), sizeof(ufds
[i
].revents
) );
1850 PRE_MEM_READ( "ppoll(tsp)", ARG3
, sizeof(struct vki_timespec
) );
1851 if (ARG4
!= 0 && sizeof(vki_sigset_t
) == ARG5
) {
1852 const vki_sigset_t
*guest_sigmask
= (vki_sigset_t
*)(Addr
)ARG4
;
1853 PRE_MEM_READ( "ppoll(sigmask)", ARG4
, ARG5
);
1854 if (!ML_(safe_to_deref
)(guest_sigmask
, sizeof(*guest_sigmask
))) {
1855 ARG4
= 1; /* Something recognisable to POST() hook. */
1857 vki_sigset_t
*vg_sigmask
=
1858 VG_(malloc
)("syswrap.ppoll.1", sizeof(*vg_sigmask
));
1859 ARG4
= (Addr
)vg_sigmask
;
1860 *vg_sigmask
= *guest_sigmask
;
1861 VG_(sanitize_client_sigmask
)(vg_sigmask
);
1868 vg_assert(SUCCESS
|| FAILURE
);
1869 if (SUCCESS
&& (RES
>= 0)) {
1871 struct vki_pollfd
* ufds
= (struct vki_pollfd
*)(Addr
)ARG1
;
1872 for (i
= 0; i
< ARG2
; i
++)
1873 POST_MEM_WRITE( (Addr
)(&ufds
[i
].revents
), sizeof(ufds
[i
].revents
) );
1875 if (ARG4
!= 0 && ARG5
== sizeof(vki_sigset_t
) && ARG4
!= 1) {
1876 VG_(free
)((vki_sigset_t
*) (Addr
)ARG4
);
1881 /* ---------------------------------------------------------------------
1883 ------------------------------------------------------------------ */
1885 PRE(sys_epoll_create
)
1887 PRINT("sys_epoll_create ( %ld )", SARG1
);
1888 PRE_REG_READ1(long, "epoll_create", int, size
);
1890 POST(sys_epoll_create
)
1893 if (!ML_(fd_allowed
)(RES
, "epoll_create", tid
, True
)) {
1895 SET_STATUS_Failure( VKI_EMFILE
);
1897 if (VG_(clo_track_fds
))
1898 ML_(record_fd_open_nameless
) (tid
, RES
);
1902 PRE(sys_epoll_create1
)
1904 PRINT("sys_epoll_create1 ( %ld )", SARG1
);
1905 PRE_REG_READ1(long, "epoll_create1", int, flags
);
1907 POST(sys_epoll_create1
)
1910 if (!ML_(fd_allowed
)(RES
, "epoll_create1", tid
, True
)) {
1912 SET_STATUS_Failure( VKI_EMFILE
);
1914 if (VG_(clo_track_fds
))
1915 ML_(record_fd_open_nameless
) (tid
, RES
);
1921 static const HChar
* epoll_ctl_s
[3] = {
1926 PRINT("sys_epoll_ctl ( %ld, %s, %ld, %#" FMT_REGWORD
"x )",
1927 SARG1
, ( ARG2
<3 ? epoll_ctl_s
[ARG2
] : "?" ), SARG3
, ARG4
);
1928 PRE_REG_READ4(long, "epoll_ctl",
1929 int, epfd
, int, op
, int, fd
, struct vki_epoll_event
*, event
);
1930 if (ARG2
!= VKI_EPOLL_CTL_DEL
)
1931 PRE_MEM_READ( "epoll_ctl(event)", ARG4
, sizeof(struct vki_epoll_event
) );
1936 *flags
|= SfMayBlock
;
1937 PRINT("sys_epoll_wait ( %ld, %#" FMT_REGWORD
"x, %ld, %ld )",
1938 SARG1
, ARG2
, SARG3
, SARG4
);
1939 PRE_REG_READ4(long, "epoll_wait",
1940 int, epfd
, struct vki_epoll_event
*, events
,
1941 int, maxevents
, int, timeout
);
1942 PRE_MEM_WRITE( "epoll_wait(events)", ARG2
, sizeof(struct vki_epoll_event
)*ARG3
);
1944 POST(sys_epoll_wait
)
1948 POST_MEM_WRITE( ARG2
, sizeof(struct vki_epoll_event
)*RES
) ;
1951 PRE(sys_epoll_pwait
)
1953 *flags
|= SfMayBlock
;
1954 PRINT("sys_epoll_pwait ( %ld, %#" FMT_REGWORD
"x, %ld, %ld, %#"
1955 FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
1956 SARG1
, ARG2
, SARG3
, SARG4
, ARG5
, ARG6
);
1957 PRE_REG_READ6(long, "epoll_pwait",
1958 int, epfd
, struct vki_epoll_event
*, events
,
1959 int, maxevents
, int, timeout
, vki_sigset_t
*, sigmask
,
1960 vki_size_t
, sigsetsize
);
1961 PRE_MEM_WRITE( "epoll_pwait(events)", ARG2
, sizeof(struct vki_epoll_event
)*ARG3
);
1963 PRE_MEM_READ( "epoll_pwait(sigmask)", ARG5
, sizeof(vki_sigset_t
) );
1965 POST(sys_epoll_pwait
)
1969 POST_MEM_WRITE( ARG2
, sizeof(struct vki_epoll_event
)*RES
) ;
1974 PRINT("sys_eventfd ( %" FMT_REGWORD
"u )", ARG1
);
1975 PRE_REG_READ1(long, "sys_eventfd", unsigned int, count
);
1979 if (!ML_(fd_allowed
)(RES
, "eventfd", tid
, True
)) {
1981 SET_STATUS_Failure( VKI_EMFILE
);
1983 if (VG_(clo_track_fds
))
1984 ML_(record_fd_open_nameless
) (tid
, RES
);
1990 PRINT("sys_eventfd2 ( %" FMT_REGWORD
"u, %ld )", ARG1
, SARG2
);
1991 PRE_REG_READ2(long, "sys_eventfd2", unsigned int, count
, int, flags
);
1995 if (!ML_(fd_allowed
)(RES
, "eventfd2", tid
, True
)) {
1997 SET_STATUS_Failure( VKI_EMFILE
);
1999 if (VG_(clo_track_fds
))
2000 ML_(record_fd_open_nameless
) (tid
, RES
);
2006 *flags
|= SfMayBlock
;
2007 #if VG_WORDSIZE == 4
2008 PRINT("sys_fallocate ( %ld, %ld, %lld, %lld )",
2009 SARG1
, SARG2
, (Long
)MERGE64(ARG3
,ARG4
), (Long
)MERGE64(ARG5
,ARG6
));
2010 PRE_REG_READ6(long, "fallocate",
2012 unsigned, MERGE64_FIRST(offset
), unsigned, MERGE64_SECOND(offset
),
2013 unsigned, MERGE64_FIRST(len
), unsigned, MERGE64_SECOND(len
));
2014 #elif VG_WORDSIZE == 8
2015 PRINT("sys_fallocate ( %ld, %ld, %ld, %ld )",
2016 SARG1
, SARG2
, SARG3
, SARG4
);
2017 PRE_REG_READ4(long, "fallocate",
2018 int, fd
, int, mode
, vki_loff_t
, offset
, vki_loff_t
, len
);
2020 # error Unexpected word size
2022 if (!ML_(fd_allowed
)(ARG1
, "fallocate", tid
, False
))
2023 SET_STATUS_Failure( VKI_EBADF
);
2028 PRINT("sys_prlimit64 ( %ld, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %#"
2029 FMT_REGWORD
"x )", SARG1
,ARG2
,ARG3
,ARG4
);
2030 PRE_REG_READ4(long, "prlimit64",
2031 vki_pid_t
, pid
, unsigned int, resource
,
2032 const struct rlimit64
*, new_rlim
,
2033 struct rlimit64
*, old_rlim
);
2035 PRE_MEM_READ( "rlimit64(new_rlim)", ARG3
, sizeof(struct vki_rlimit64
) );
2037 PRE_MEM_WRITE( "rlimit64(old_rlim)", ARG4
, sizeof(struct vki_rlimit64
) );
2040 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
2041 > ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
) {
2042 SET_STATUS_Failure( VKI_EINVAL
);
2044 else if (ARG1
== 0 || ARG1
== VG_(getpid
)()) {
2046 case VKI_RLIMIT_NOFILE
:
2047 SET_STATUS_Success( 0 );
2049 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_cur
= VG_(fd_soft_limit
);
2050 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_max
= VG_(fd_hard_limit
);
2053 if (((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
2054 > VG_(fd_hard_limit
) ||
2055 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
2056 != VG_(fd_hard_limit
)) {
2057 SET_STATUS_Failure( VKI_EPERM
);
2060 VG_(fd_soft_limit
) =
2061 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
;
2066 case VKI_RLIMIT_DATA
:
2067 SET_STATUS_Success( 0 );
2069 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_cur
=
2070 VG_(client_rlimit_data
).rlim_cur
;
2071 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_max
=
2072 VG_(client_rlimit_data
).rlim_max
;
2075 if (((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
2076 > VG_(client_rlimit_data
).rlim_max
||
2077 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
2078 > VG_(client_rlimit_data
).rlim_max
) {
2079 SET_STATUS_Failure( VKI_EPERM
);
2082 VG_(client_rlimit_data
).rlim_cur
=
2083 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
;
2084 VG_(client_rlimit_data
).rlim_max
=
2085 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
;
2090 case VKI_RLIMIT_STACK
:
2091 SET_STATUS_Success( 0 );
2093 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_cur
=
2094 VG_(client_rlimit_stack
).rlim_cur
;
2095 ((struct vki_rlimit64
*)(Addr
)ARG4
)->rlim_max
=
2096 VG_(client_rlimit_stack
).rlim_max
;
2099 if (((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
2100 > VG_(client_rlimit_stack
).rlim_max
||
2101 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
2102 > VG_(client_rlimit_stack
).rlim_max
) {
2103 SET_STATUS_Failure( VKI_EPERM
);
2106 VG_(threads
)[tid
].client_stack_szB
=
2107 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
;
2108 VG_(client_rlimit_stack
).rlim_cur
=
2109 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_cur
;
2110 VG_(client_rlimit_stack
).rlim_max
=
2111 ((struct vki_rlimit64
*)(Addr
)ARG3
)->rlim_max
;
2122 POST_MEM_WRITE( ARG4
, sizeof(struct vki_rlimit64
) );
2125 /* ---------------------------------------------------------------------
2126 tid-related wrappers
2127 ------------------------------------------------------------------ */
2131 PRINT("sys_gettid ()");
2132 PRE_REG_READ0(long, "gettid");
2135 PRE(sys_set_tid_address
)
2137 PRINT("sys_set_tid_address ( %#" FMT_REGWORD
"x )", ARG1
);
2138 PRE_REG_READ1(long, "set_tid_address", int *, tidptr
);
2143 PRINT("sys_tkill ( %ld, %ld )", SARG1
, SARG2
);
2144 PRE_REG_READ2(long, "tkill", int, tid
, int, sig
);
2145 if (!ML_(client_signal_OK
)(ARG2
)) {
2146 SET_STATUS_Failure( VKI_EINVAL
);
2150 /* Check to see if this kill gave us a pending signal */
2151 *flags
|= SfPollAfter
;
2153 if (VG_(clo_trace_signals
))
2154 VG_(message
)(Vg_DebugMsg
, "tkill: sending signal %ld to pid %ld\n",
2157 /* If we're sending SIGKILL, check to see if the target is one of
2158 our threads and handle it specially. */
2159 if (ARG2
== VKI_SIGKILL
&& ML_(do_sigkill
)(ARG1
, -1)) {
2160 SET_STATUS_Success(0);
2164 /* Ask to handle this syscall via the slow route, since that's the
2165 only one that sets tst->status to VgTs_WaitSys. If the result
2166 of doing the syscall is an immediate run of
2167 async_signalhandler() in m_signals, then we need the thread to
2168 be properly tidied away. I have the impression the previous
2169 version of this wrapper worked on x86/amd64 only because the
2170 kernel did not immediately deliver the async signal to this
2171 thread (on ppc it did, which broke the assertion re tst->status
2172 at the top of async_signalhandler()). */
2173 *flags
|= SfMayBlock
;
2177 if (VG_(clo_trace_signals
))
2178 VG_(message
)(Vg_DebugMsg
, "tkill: sent signal %ld to pid %ld\n",
2184 PRINT("sys_tgkill ( %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
);
2185 PRE_REG_READ3(long, "tgkill", int, tgid
, int, tid
, int, sig
);
2186 if (!ML_(client_signal_OK
)(ARG3
)) {
2187 SET_STATUS_Failure( VKI_EINVAL
);
2191 /* Check to see if this kill gave us a pending signal */
2192 *flags
|= SfPollAfter
;
2194 if (VG_(clo_trace_signals
))
2195 VG_(message
)(Vg_DebugMsg
,
2196 "tgkill: sending signal %ld to pid %ld/%ld\n",
2197 SARG3
, SARG1
, SARG2
);
2199 /* If we're sending SIGKILL, check to see if the target is one of
2200 our threads and handle it specially. */
2201 if (ARG3
== VKI_SIGKILL
&& ML_(do_sigkill
)(ARG2
, ARG1
)) {
2202 SET_STATUS_Success(0);
2206 /* Ask to handle this syscall via the slow route, since that's the
2207 only one that sets tst->status to VgTs_WaitSys. If the result
2208 of doing the syscall is an immediate run of
2209 async_signalhandler() in m_signals, then we need the thread to
2210 be properly tidied away. I have the impression the previous
2211 version of this wrapper worked on x86/amd64 only because the
2212 kernel did not immediately deliver the async signal to this
2213 thread (on ppc it did, which broke the assertion re tst->status
2214 at the top of async_signalhandler()). */
2215 *flags
|= SfMayBlock
;
2219 if (VG_(clo_trace_signals
))
2220 VG_(message
)(Vg_DebugMsg
,
2221 "tgkill: sent signal %ld to pid %ld/%ld\n",
2222 SARG3
, SARG1
, SARG2
);
2225 /* ---------------------------------------------------------------------
2227 ------------------------------------------------------------------ */
2231 PRINT("sys_fadvise64 ( %ld, %llu, %" FMT_REGWORD
"u, %ld )",
2232 SARG1
, MERGE64(ARG2
,ARG3
), ARG4
, SARG5
);
2233 PRE_REG_READ5(long, "fadvise64",
2234 int, fd
, vki_u32
, MERGE64_FIRST(offset
), vki_u32
, MERGE64_SECOND(offset
),
2235 vki_size_t
, len
, int, advice
);
2238 PRE(sys_fadvise64_64
)
2240 PRINT("sys_fadvise64_64 ( %ld, %llu, %llu, %ld )",
2241 SARG1
, MERGE64(ARG2
,ARG3
), MERGE64(ARG4
,ARG5
), SARG6
);
2242 PRE_REG_READ6(long, "fadvise64_64",
2243 int, fd
, vki_u32
, MERGE64_FIRST(offset
), vki_u32
, MERGE64_SECOND(offset
),
2244 vki_u32
, MERGE64_FIRST(len
), vki_u32
, MERGE64_SECOND(len
), int, advice
);
2247 /* ---------------------------------------------------------------------
2249 ------------------------------------------------------------------ */
2251 // Nb: this wrapper has to pad/unpad memory around the syscall itself,
2252 // and this allows us to control exactly the code that gets run while
2253 // the padding is in place.
2257 PRINT("sys_io_setup ( %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )", ARG1
,ARG2
);
2258 PRE_REG_READ2(long, "io_setup",
2259 unsigned, nr_events
, vki_aio_context_t
*, ctxp
);
2260 PRE_MEM_WRITE( "io_setup(ctxp)", ARG2
, sizeof(vki_aio_context_t
) );
2266 struct vki_aio_ring
*r
;
2268 size
= VG_PGROUNDUP(sizeof(struct vki_aio_ring
) +
2269 ARG1
*sizeof(struct vki_io_event
));
2270 r
= *(struct vki_aio_ring
**)(Addr
)ARG2
;
2271 vg_assert(ML_(valid_client_addr
)((Addr
)r
, size
, tid
, "io_setup"));
2273 ML_(notify_core_and_tool_of_mmap
)( (Addr
)r
, size
,
2274 VKI_PROT_READ
| VKI_PROT_WRITE
,
2275 VKI_MAP_ANONYMOUS
, -1, 0 );
2277 POST_MEM_WRITE( ARG2
, sizeof(vki_aio_context_t
) );
2280 // Nb: This wrapper is "Special" because we need 'size' to do the unmap
2281 // after the syscall. We must get 'size' from the aio_ring structure,
2282 // before the syscall, while the aio_ring structure still exists. (And we
2283 // know that we must look at the aio_ring structure because Tom inspected the
2284 // kernel and glibc sources to see what they do, yuk.)
2286 // XXX This segment can be implicitly unmapped when aio
2287 // file-descriptors are closed...
2292 PRINT("sys_io_destroy ( %llu )", (ULong
)ARG1
);
2293 PRE_REG_READ1(long, "io_destroy", vki_aio_context_t
, ctx
);
2295 // If we are going to seg fault (due to a bogus ARG1) do it as late as
2297 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG1
, sizeof(struct vki_aio_ring
))) {
2298 struct vki_aio_ring
*r
= (struct vki_aio_ring
*)(Addr
)ARG1
;
2299 size
= VG_PGROUNDUP(sizeof(struct vki_aio_ring
) +
2300 r
->nr
*sizeof(struct vki_io_event
));
2303 SET_STATUS_from_SysRes( VG_(do_syscall1
)(SYSNO
, ARG1
) );
2305 if (SUCCESS
&& RES
== 0) {
2306 Bool d
= VG_(am_notify_munmap
)( ARG1
, size
);
2307 VG_TRACK( die_mem_munmap
, ARG1
, size
);
2309 VG_(discard_translations
)( (Addr
)ARG1
, (ULong
)size
,
2310 "PRE(sys_io_destroy)" );
2314 PRE(sys_io_getevents
)
2316 *flags
|= SfMayBlock
;
2317 PRINT("sys_io_getevents ( %llu, %lld, %lld, %#" FMT_REGWORD
"x, %#"
2319 (ULong
)ARG1
,(Long
)ARG2
,(Long
)ARG3
,ARG4
,ARG5
);
2320 PRE_REG_READ5(long, "io_getevents",
2321 vki_aio_context_t
, ctx_id
, long, min_nr
, long, nr
,
2322 struct io_event
*, events
,
2323 struct timespec
*, timeout
);
2325 PRE_MEM_WRITE( "io_getevents(events)",
2326 ARG4
, sizeof(struct vki_io_event
)*ARG3
);
2328 PRE_MEM_READ( "io_getevents(timeout)",
2329 ARG5
, sizeof(struct vki_timespec
));
2331 POST(sys_io_getevents
)
2336 POST_MEM_WRITE( ARG4
, sizeof(struct vki_io_event
)*RES
);
2337 for (i
= 0; i
< RES
; i
++) {
2338 const struct vki_io_event
*vev
=
2339 ((struct vki_io_event
*)(Addr
)ARG4
) + i
;
2340 const struct vki_iocb
*cb
= (struct vki_iocb
*)(Addr
)vev
->obj
;
2342 switch (cb
->aio_lio_opcode
) {
2343 case VKI_IOCB_CMD_PREAD
:
2344 if (vev
->result
> 0)
2345 POST_MEM_WRITE( cb
->aio_buf
, vev
->result
);
2348 case VKI_IOCB_CMD_PWRITE
:
2351 case VKI_IOCB_CMD_FSYNC
:
2354 case VKI_IOCB_CMD_FDSYNC
:
2357 case VKI_IOCB_CMD_PREADV
:
2358 if (vev
->result
> 0) {
2359 struct vki_iovec
* vec
= (struct vki_iovec
*)(Addr
)cb
->aio_buf
;
2360 Int remains
= vev
->result
;
2363 for (j
= 0; j
< cb
->aio_nbytes
; j
++) {
2364 Int nReadThisBuf
= vec
[j
].iov_len
;
2365 if (nReadThisBuf
> remains
) nReadThisBuf
= remains
;
2366 POST_MEM_WRITE( (Addr
)vec
[j
].iov_base
, nReadThisBuf
);
2367 remains
-= nReadThisBuf
;
2368 if (remains
< 0) VG_(core_panic
)("io_getevents(PREADV): remains < 0");
2373 case VKI_IOCB_CMD_PWRITEV
:
2377 VG_(message
)(Vg_DebugMsg
,
2378 "Warning: unhandled io_getevents opcode: %u\n",
2379 cb
->aio_lio_opcode
);
2390 PRINT("sys_io_submit ( %" FMT_REGWORD
"u, %ld, %#" FMT_REGWORD
"x )",
2392 PRE_REG_READ3(long, "io_submit",
2393 vki_aio_context_t
, ctx_id
, long, nr
,
2394 struct iocb
**, iocbpp
);
2395 PRE_MEM_READ( "io_submit(iocbpp)", ARG3
, ARG2
*sizeof(struct vki_iocb
*) );
2397 for (i
= 0; i
< ARG2
; i
++) {
2398 struct vki_iocb
*cb
= ((struct vki_iocb
**)(Addr
)ARG3
)[i
];
2399 struct vki_iovec
*iov
;
2401 PRE_MEM_READ( "io_submit(iocb)", (Addr
)cb
, sizeof(struct vki_iocb
) );
2402 switch (cb
->aio_lio_opcode
) {
2403 case VKI_IOCB_CMD_PREAD
:
2404 PRE_MEM_WRITE( "io_submit(PREAD)", cb
->aio_buf
, cb
->aio_nbytes
);
2407 case VKI_IOCB_CMD_PWRITE
:
2408 PRE_MEM_READ( "io_submit(PWRITE)", cb
->aio_buf
, cb
->aio_nbytes
);
2411 case VKI_IOCB_CMD_FSYNC
:
2414 case VKI_IOCB_CMD_FDSYNC
:
2417 case VKI_IOCB_CMD_PREADV
:
2418 iov
= (struct vki_iovec
*)(Addr
)cb
->aio_buf
;
2419 PRE_MEM_READ( "io_submit(PREADV)", cb
->aio_buf
, cb
->aio_nbytes
* sizeof(struct vki_iovec
) );
2420 for (j
= 0; j
< cb
->aio_nbytes
; j
++)
2421 PRE_MEM_WRITE( "io_submit(PREADV(iov[i]))", (Addr
)iov
[j
].iov_base
, iov
[j
].iov_len
);
2424 case VKI_IOCB_CMD_PWRITEV
:
2425 iov
= (struct vki_iovec
*)(Addr
)cb
->aio_buf
;
2426 PRE_MEM_READ( "io_submit(PWRITEV)", cb
->aio_buf
, cb
->aio_nbytes
* sizeof(struct vki_iovec
) );
2427 for (j
= 0; j
< cb
->aio_nbytes
; j
++)
2428 PRE_MEM_READ( "io_submit(PWRITEV(iov[i]))", (Addr
)iov
[j
].iov_base
, iov
[j
].iov_len
);
2432 VG_(message
)(Vg_DebugMsg
,"Warning: unhandled io_submit opcode: %u\n",
2433 cb
->aio_lio_opcode
);
2442 PRINT("sys_io_cancel ( %llu, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
2443 (ULong
)ARG1
, ARG2
, ARG3
);
2444 PRE_REG_READ3(long, "io_cancel",
2445 vki_aio_context_t
, ctx_id
, struct iocb
*, iocb
,
2446 struct io_event
*, result
);
2447 PRE_MEM_READ( "io_cancel(iocb)", ARG2
, sizeof(struct vki_iocb
) );
2448 PRE_MEM_WRITE( "io_cancel(result)", ARG3
, sizeof(struct vki_io_event
) );
2452 POST_MEM_WRITE( ARG3
, sizeof(struct vki_io_event
) );
2455 /* ---------------------------------------------------------------------
2456 *_mempolicy wrappers
2457 ------------------------------------------------------------------ */
2461 PRINT("sys_mbind ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %" FMT_REGWORD
2462 "u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )",
2463 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
2464 PRE_REG_READ6(long, "mbind",
2465 unsigned long, start
, unsigned long, len
,
2466 unsigned long, policy
, unsigned long *, nodemask
,
2467 unsigned long, maxnode
, unsigned, flags
);
2469 PRE_MEM_READ( "mbind(nodemask)", ARG4
,
2470 VG_ROUNDUP( ARG5
-1, sizeof(UWord
) * 8 ) / 8 );
2473 PRE(sys_set_mempolicy
)
2475 PRINT("sys_set_mempolicy ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
2477 PRE_REG_READ3(long, "set_mempolicy",
2478 int, policy
, unsigned long *, nodemask
,
2479 unsigned long, maxnode
);
2480 PRE_MEM_READ( "set_mempolicy(nodemask)", ARG2
,
2481 VG_ROUNDUP( ARG3
-1, sizeof(UWord
) * 8 ) / 8 );
2484 PRE(sys_get_mempolicy
)
2486 PRINT("sys_get_mempolicy ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %"
2487 FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"x )",
2488 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
);
2489 PRE_REG_READ5(long, "get_mempolicy",
2490 int *, policy
, unsigned long *, nodemask
,
2491 unsigned long, maxnode
, unsigned long, addr
,
2492 unsigned long, flags
);
2494 PRE_MEM_WRITE( "get_mempolicy(policy)", ARG1
, sizeof(Int
) );
2496 PRE_MEM_WRITE( "get_mempolicy(nodemask)", ARG2
,
2497 VG_ROUNDUP( ARG3
-1, sizeof(UWord
) * 8 ) / 8 );
2499 POST(sys_get_mempolicy
)
2502 POST_MEM_WRITE( ARG1
, sizeof(Int
) );
2504 POST_MEM_WRITE( ARG2
, VG_ROUNDUP( ARG3
-1, sizeof(UWord
) * 8 ) / 8 );
2507 /* ---------------------------------------------------------------------
2509 ------------------------------------------------------------------ */
2511 PRE(sys_fanotify_init
)
2513 PRINT("sys_fanotify_init ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )",
2515 PRE_REG_READ2(long, "fanotify_init",
2516 unsigned int, flags
, unsigned int, event_f_flags
);
2519 POST(sys_fanotify_init
)
2522 if (!ML_(fd_allowed
)(RES
, "fanotify_init", tid
, True
)) {
2524 SET_STATUS_Failure( VKI_EMFILE
);
2526 if (VG_(clo_track_fds
))
2527 ML_(record_fd_open_nameless
) (tid
, RES
);
2531 PRE(sys_fanotify_mark
)
2533 #if VG_WORDSIZE == 4
2534 PRINT( "sys_fanotify_mark ( %ld, %" FMT_REGWORD
"u, %llu, %ld, %#"
2535 FMT_REGWORD
"x(%s))", SARG1
, ARG2
, MERGE64(ARG3
,ARG4
), SARG5
, ARG6
,
2536 (HChar
*)(Addr
)ARG6
);
2537 PRE_REG_READ6(long, "sys_fanotify_mark",
2538 int, fanotify_fd
, unsigned int, flags
,
2539 __vki_u32
, mask0
, __vki_u32
, mask1
,
2540 int, dfd
, const char *, pathname
);
2542 PRE_MEM_RASCIIZ( "fanotify_mark(path)", ARG6
);
2543 #elif VG_WORDSIZE == 8
2544 PRINT( "sys_fanotify_mark ( %ld, %lu, %lu, %ld, %#lx(%s))",
2545 SARG1
, ARG2
, ARG3
, SARG4
, ARG5
, (HChar
*)(Addr
)ARG5
);
2546 PRE_REG_READ5(long, "sys_fanotify_mark",
2547 int, fanotify_fd
, unsigned int, flags
,
2549 int, dfd
, const char *, pathname
);
2551 PRE_MEM_RASCIIZ( "fanotify_mark(path)", ARG5
);
2553 # error Unexpected word size
2557 /* ---------------------------------------------------------------------
2559 ------------------------------------------------------------------ */
2561 PRE(sys_inotify_init
)
2563 PRINT("sys_inotify_init ( )");
2564 PRE_REG_READ0(long, "inotify_init");
2566 POST(sys_inotify_init
)
2569 if (!ML_(fd_allowed
)(RES
, "inotify_init", tid
, True
)) {
2571 SET_STATUS_Failure( VKI_EMFILE
);
2573 if (VG_(clo_track_fds
))
2574 ML_(record_fd_open_nameless
) (tid
, RES
);
2578 PRE(sys_inotify_init1
)
2580 PRINT("sys_inotify_init ( %ld )", SARG1
);
2581 PRE_REG_READ1(long, "inotify_init", int, flag
);
2584 POST(sys_inotify_init1
)
2587 if (!ML_(fd_allowed
)(RES
, "inotify_init", tid
, True
)) {
2589 SET_STATUS_Failure( VKI_EMFILE
);
2591 if (VG_(clo_track_fds
))
2592 ML_(record_fd_open_nameless
) (tid
, RES
);
2596 PRE(sys_inotify_add_watch
)
2598 PRINT( "sys_inotify_add_watch ( %ld, %#" FMT_REGWORD
"x, %"
2599 FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
);
2600 PRE_REG_READ3(long, "inotify_add_watch", int, fd
, char *, path
, int, mask
);
2601 PRE_MEM_RASCIIZ( "inotify_add_watch(path)", ARG2
);
2604 PRE(sys_inotify_rm_watch
)
2606 PRINT( "sys_inotify_rm_watch ( %ld, %" FMT_REGWORD
"x )", SARG1
, ARG2
);
2607 PRE_REG_READ2(long, "inotify_rm_watch", int, fd
, int, wd
);
2610 /* ---------------------------------------------------------------------
2612 ------------------------------------------------------------------ */
2616 PRINT("sys_mq_open( %#" FMT_REGWORD
"x(%s), %ld, %" FMT_REGWORD
"u, %#"
2617 FMT_REGWORD
"x )", ARG1
, (HChar
*)(Addr
)ARG1
, SARG2
, ARG3
, ARG4
);
2618 PRE_REG_READ4(long, "mq_open",
2619 const char *, name
, int, oflag
, vki_mode_t
, mode
,
2620 struct mq_attr
*, attr
);
2621 PRE_MEM_RASCIIZ( "mq_open(name)", ARG1
);
2622 if ((ARG2
& VKI_O_CREAT
) != 0 && ARG4
!= 0) {
2623 const struct vki_mq_attr
*attr
= (struct vki_mq_attr
*)(Addr
)ARG4
;
2624 PRE_MEM_READ( "mq_open(attr->mq_maxmsg)",
2625 (Addr
)&attr
->mq_maxmsg
, sizeof(attr
->mq_maxmsg
) );
2626 PRE_MEM_READ( "mq_open(attr->mq_msgsize)",
2627 (Addr
)&attr
->mq_msgsize
, sizeof(attr
->mq_msgsize
) );
2633 if (!ML_(fd_allowed
)(RES
, "mq_open", tid
, True
)) {
2635 SET_STATUS_Failure( VKI_EMFILE
);
2637 if (VG_(clo_track_fds
))
2638 ML_(record_fd_open_with_given_name
)(tid
, RES
, (HChar
*)(Addr
)ARG1
);
2644 PRINT("sys_mq_unlink ( %#" FMT_REGWORD
"x(%s) )", ARG1
,(char*)(Addr
)ARG1
);
2645 PRE_REG_READ1(long, "mq_unlink", const char *, name
);
2646 PRE_MEM_RASCIIZ( "mq_unlink(name)", ARG1
);
2649 PRE(sys_mq_timedsend
)
2651 *flags
|= SfMayBlock
;
2652 PRINT("sys_mq_timedsend ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
2653 FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
2654 SARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
2655 PRE_REG_READ5(long, "mq_timedsend",
2656 vki_mqd_t
, mqdes
, const char *, msg_ptr
, vki_size_t
, msg_len
,
2657 unsigned int, msg_prio
, const struct timespec
*, abs_timeout
);
2658 if (!ML_(fd_allowed
)(ARG1
, "mq_timedsend", tid
, False
)) {
2659 SET_STATUS_Failure( VKI_EBADF
);
2661 PRE_MEM_READ( "mq_timedsend(msg_ptr)", ARG2
, ARG3
);
2663 PRE_MEM_READ( "mq_timedsend(abs_timeout)", ARG5
,
2664 sizeof(struct vki_timespec
) );
2668 PRE(sys_mq_timedreceive
)
2670 *flags
|= SfMayBlock
;
2671 PRINT("sys_mq_timedreceive( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#"
2672 FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
2673 SARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
2674 PRE_REG_READ5(ssize_t
, "mq_timedreceive",
2675 vki_mqd_t
, mqdes
, char *, msg_ptr
, vki_size_t
, msg_len
,
2676 unsigned int *, msg_prio
,
2677 const struct timespec
*, abs_timeout
);
2678 if (!ML_(fd_allowed
)(ARG1
, "mq_timedreceive", tid
, False
)) {
2679 SET_STATUS_Failure( VKI_EBADF
);
2681 PRE_MEM_WRITE( "mq_timedreceive(msg_ptr)", ARG2
, ARG3
);
2683 PRE_MEM_WRITE( "mq_timedreceive(msg_prio)",
2684 ARG4
, sizeof(unsigned int) );
2686 PRE_MEM_READ( "mq_timedreceive(abs_timeout)",
2687 ARG5
, sizeof(struct vki_timespec
) );
2690 POST(sys_mq_timedreceive
)
2692 POST_MEM_WRITE( ARG2
, RES
);
2694 POST_MEM_WRITE( ARG4
, sizeof(unsigned int) );
2699 PRINT("sys_mq_notify( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
2700 PRE_REG_READ2(long, "mq_notify",
2701 vki_mqd_t
, mqdes
, const struct sigevent
*, notification
);
2702 if (!ML_(fd_allowed
)(ARG1
, "mq_notify", tid
, False
))
2703 SET_STATUS_Failure( VKI_EBADF
);
2705 PRE_MEM_READ( "mq_notify(notification)",
2706 ARG2
, sizeof(struct vki_sigevent
) );
2709 PRE(sys_mq_getsetattr
)
2711 PRINT("sys_mq_getsetattr( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
2712 SARG1
, ARG2
, ARG3
);
2713 PRE_REG_READ3(long, "mq_getsetattr",
2714 vki_mqd_t
, mqdes
, const struct mq_attr
*, mqstat
,
2715 struct mq_attr
*, omqstat
);
2716 if (!ML_(fd_allowed
)(ARG1
, "mq_getsetattr", tid
, False
)) {
2717 SET_STATUS_Failure( VKI_EBADF
);
2720 const struct vki_mq_attr
*attr
= (struct vki_mq_attr
*)(Addr
)ARG2
;
2721 PRE_MEM_READ( "mq_getsetattr(mqstat->mq_flags)",
2722 (Addr
)&attr
->mq_flags
, sizeof(attr
->mq_flags
) );
2725 PRE_MEM_WRITE( "mq_getsetattr(omqstat)", ARG3
,
2726 sizeof(struct vki_mq_attr
) );
2729 POST(sys_mq_getsetattr
)
2732 POST_MEM_WRITE( ARG3
, sizeof(struct vki_mq_attr
) );
2735 /* ---------------------------------------------------------------------
2737 ------------------------------------------------------------------ */
2739 PRE(sys_clock_settime
)
2741 PRINT("sys_clock_settime( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
2742 PRE_REG_READ2(long, "clock_settime",
2743 vki_clockid_t
, clk_id
, const struct timespec
*, tp
);
2744 PRE_MEM_READ( "clock_settime(tp)", ARG2
, sizeof(struct vki_timespec
) );
2747 PRE(sys_clock_gettime
)
2749 PRINT("sys_clock_gettime( %ld, %#" FMT_REGWORD
"x )" , SARG1
, ARG2
);
2750 PRE_REG_READ2(long, "clock_gettime",
2751 vki_clockid_t
, clk_id
, struct timespec
*, tp
);
2752 PRE_MEM_WRITE( "clock_gettime(tp)", ARG2
, sizeof(struct vki_timespec
) );
2754 POST(sys_clock_gettime
)
2756 POST_MEM_WRITE( ARG2
, sizeof(struct vki_timespec
) );
2759 PRE(sys_clock_getres
)
2761 PRINT("sys_clock_getres( %ld, %#" FMT_REGWORD
"x )" , SARG1
, ARG2
);
2762 // Nb: we can't use "RES" as the param name because that's a macro
2764 PRE_REG_READ2(long, "clock_getres",
2765 vki_clockid_t
, clk_id
, struct timespec
*, res
);
2767 PRE_MEM_WRITE( "clock_getres(res)", ARG2
, sizeof(struct vki_timespec
) );
2769 POST(sys_clock_getres
)
2772 POST_MEM_WRITE( ARG2
, sizeof(struct vki_timespec
) );
2775 PRE(sys_clock_nanosleep
)
2777 *flags
|= SfMayBlock
|SfPostOnFail
;
2778 PRINT("sys_clock_nanosleep( %ld, %ld, %#" FMT_REGWORD
"x, %#"
2780 SARG1
, SARG2
, ARG3
, ARG4
);
2781 PRE_REG_READ4(int32_t, "clock_nanosleep",
2782 vki_clockid_t
, clkid
, int, flags
,
2783 const struct timespec
*, rqtp
, struct timespec
*, rmtp
);
2784 PRE_MEM_READ( "clock_nanosleep(rqtp)", ARG3
, sizeof(struct vki_timespec
) );
2786 PRE_MEM_WRITE( "clock_nanosleep(rmtp)", ARG4
, sizeof(struct vki_timespec
) );
2788 POST(sys_clock_nanosleep
)
2790 if (ARG4
!= 0 && FAILURE
&& ERR
== VKI_EINTR
)
2791 POST_MEM_WRITE( ARG4
, sizeof(struct vki_timespec
) );
2794 /* ---------------------------------------------------------------------
2796 ------------------------------------------------------------------ */
2798 PRE(sys_timer_create
)
2800 PRINT("sys_timer_create( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
2802 PRE_REG_READ3(long, "timer_create",
2803 vki_clockid_t
, clockid
, struct sigevent
*, evp
,
2804 vki_timer_t
*, timerid
);
2806 struct vki_sigevent
*evp
= (struct vki_sigevent
*) (Addr
)ARG2
;
2807 PRE_MEM_READ( "timer_create(evp.sigev_value)", (Addr
)&evp
->sigev_value
,
2808 sizeof(vki_sigval_t
) );
2809 PRE_MEM_READ( "timer_create(evp.sigev_signo)", (Addr
)&evp
->sigev_signo
,
2811 PRE_MEM_READ( "timer_create(evp.sigev_notify)", (Addr
)&evp
->sigev_notify
,
2813 if (ML_(safe_to_deref
)(&evp
->sigev_notify
, sizeof(int))
2814 && (evp
->sigev_notify
& VKI_SIGEV_THREAD_ID
) != 0)
2815 PRE_MEM_READ( "timer_create(evp.sigev_notify_thread_id)",
2816 (Addr
)&evp
->vki_sigev_notify_thread_id
, sizeof(int) );
2818 PRE_MEM_WRITE( "timer_create(timerid)", ARG3
, sizeof(vki_timer_t
) );
2820 POST(sys_timer_create
)
2822 POST_MEM_WRITE( ARG3
, sizeof(vki_timer_t
) );
2825 PRE(sys_timer_settime
)
2827 PRINT("sys_timer_settime( %ld, %ld, %#" FMT_REGWORD
"x, %#"
2828 FMT_REGWORD
"x )", SARG1
,SARG2
,ARG3
,ARG4
);
2829 PRE_REG_READ4(long, "timer_settime",
2830 vki_timer_t
, timerid
, int, flags
,
2831 const struct itimerspec
*, value
,
2832 struct itimerspec
*, ovalue
);
2833 PRE_MEM_READ( "timer_settime(value)", ARG3
,
2834 sizeof(struct vki_itimerspec
) );
2836 PRE_MEM_WRITE( "timer_settime(ovalue)", ARG4
,
2837 sizeof(struct vki_itimerspec
) );
2839 POST(sys_timer_settime
)
2842 POST_MEM_WRITE( ARG4
, sizeof(struct vki_itimerspec
) );
2845 PRE(sys_timer_gettime
)
2847 PRINT("sys_timer_gettime( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
2848 PRE_REG_READ2(long, "timer_gettime",
2849 vki_timer_t
, timerid
, struct itimerspec
*, value
);
2850 PRE_MEM_WRITE( "timer_gettime(value)", ARG2
,
2851 sizeof(struct vki_itimerspec
));
2853 POST(sys_timer_gettime
)
2855 POST_MEM_WRITE( ARG2
, sizeof(struct vki_itimerspec
) );
2858 PRE(sys_timer_getoverrun
)
2860 PRINT("sys_timer_getoverrun( %#" FMT_REGWORD
"x )", ARG1
);
2861 PRE_REG_READ1(long, "timer_getoverrun", vki_timer_t
, timerid
);
2864 PRE(sys_timer_delete
)
2866 PRINT("sys_timer_delete( %#" FMT_REGWORD
"x )", ARG1
);
2867 PRE_REG_READ1(long, "timer_delete", vki_timer_t
, timerid
);
2870 /* ---------------------------------------------------------------------
2872 See also http://lwn.net/Articles/260172/ for an overview.
2873 See also /usr/src/linux/fs/timerfd.c for the implementation.
2874 ------------------------------------------------------------------ */
2876 /* Returns True if running on 2.6.22, else False (or False if
2877 cannot be determined). */
2878 static Bool
linux_kernel_2_6_22(void)
2880 static Int result
= -1;
2882 HChar release
[64]; // large enough
2886 res
= VG_(open
)("/proc/sys/kernel/osrelease", 0, 0);
2887 if (sr_isError(res
))
2890 read
= VG_(read
)(fd
, release
, sizeof(release
) - 1);
2895 //VG_(printf)("kernel release = %s\n", release);
2896 result
= VG_(strncmp
)(release
, "2.6.22", 6) == 0
2897 && ! VG_(isdigit
)(release
[6]);
2899 vg_assert(result
== 0 || result
== 1);
2903 PRE(sys_timerfd_create
)
2905 if (linux_kernel_2_6_22()) {
2906 /* 2.6.22 kernel: timerfd system call. */
2907 PRINT("sys_timerfd ( %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
, ARG3
);
2908 PRE_REG_READ3(long, "sys_timerfd",
2909 int, fd
, int, clockid
, const struct itimerspec
*, tmr
);
2910 PRE_MEM_READ("timerfd(tmr)", ARG3
,
2911 sizeof(struct vki_itimerspec
) );
2912 if ((Word
)ARG1
!= -1L && !ML_(fd_allowed
)(ARG1
, "timerfd", tid
, False
))
2913 SET_STATUS_Failure( VKI_EBADF
);
2915 /* 2.6.24 and later kernels: timerfd_create system call. */
2916 PRINT("sys_timerfd_create (%ld, %ld )", SARG1
, SARG2
);
2917 PRE_REG_READ2(long, "timerfd_create", int, clockid
, int, flags
);
2920 POST(sys_timerfd_create
)
2922 if (linux_kernel_2_6_22())
2924 /* 2.6.22 kernel: timerfd system call. */
2925 if (!ML_(fd_allowed
)(RES
, "timerfd", tid
, True
)) {
2927 SET_STATUS_Failure( VKI_EMFILE
);
2929 if (VG_(clo_track_fds
))
2930 ML_(record_fd_open_nameless
) (tid
, RES
);
2935 /* 2.6.24 and later kernels: timerfd_create system call. */
2936 if (!ML_(fd_allowed
)(RES
, "timerfd_create", tid
, True
)) {
2938 SET_STATUS_Failure( VKI_EMFILE
);
2940 if (VG_(clo_track_fds
))
2941 ML_(record_fd_open_nameless
) (tid
, RES
);
2946 PRE(sys_timerfd_gettime
)
2948 PRINT("sys_timerfd_gettime ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
2949 PRE_REG_READ2(long, "timerfd_gettime",
2951 struct vki_itimerspec
*, otmr
);
2952 if (!ML_(fd_allowed
)(ARG1
, "timerfd_gettime", tid
, False
))
2953 SET_STATUS_Failure(VKI_EBADF
);
2955 PRE_MEM_WRITE("timerfd_gettime(result)",
2956 ARG2
, sizeof(struct vki_itimerspec
));
2958 POST(sys_timerfd_gettime
)
2961 POST_MEM_WRITE(ARG2
, sizeof(struct vki_itimerspec
));
2964 PRE(sys_timerfd_settime
)
2966 PRINT("sys_timerfd_settime ( %ld, %ld, %#" FMT_REGWORD
"x, %#"
2967 FMT_REGWORD
"x )", SARG1
, SARG2
, ARG3
, ARG4
);
2968 PRE_REG_READ4(long, "timerfd_settime",
2971 const struct vki_itimerspec
*, utmr
,
2972 struct vki_itimerspec
*, otmr
);
2973 if (!ML_(fd_allowed
)(ARG1
, "timerfd_settime", tid
, False
))
2974 SET_STATUS_Failure(VKI_EBADF
);
2977 PRE_MEM_READ("timerfd_settime(result)",
2978 ARG3
, sizeof(struct vki_itimerspec
));
2981 PRE_MEM_WRITE("timerfd_settime(result)",
2982 ARG4
, sizeof(struct vki_itimerspec
));
2986 POST(sys_timerfd_settime
)
2988 if (RES
== 0 && ARG4
!= 0)
2989 POST_MEM_WRITE(ARG4
, sizeof(struct vki_itimerspec
));
2992 /* ---------------------------------------------------------------------
2993 capabilities wrappers
2994 ------------------------------------------------------------------ */
2998 PRINT("sys_capget ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )", ARG1
, ARG2
);
2999 PRE_REG_READ2(long, "capget",
3000 vki_cap_user_header_t
, header
, vki_cap_user_data_t
, data
);
3001 PRE_MEM_READ( "capget(header)", ARG1
,
3002 sizeof(struct __vki_user_cap_header_struct
) );
3003 if (ARG2
!= (Addr
)NULL
)
3004 PRE_MEM_WRITE( "capget(data)", ARG2
,
3005 sizeof(struct __vki_user_cap_data_struct
) );
3009 if (ARG2
!= (Addr
)NULL
)
3010 POST_MEM_WRITE( ARG2
, sizeof(struct __vki_user_cap_data_struct
) );
3015 PRINT("sys_capset ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )", ARG1
, ARG2
);
3016 PRE_REG_READ2(long, "capset",
3017 vki_cap_user_header_t
, header
,
3018 const vki_cap_user_data_t
, data
);
3019 PRE_MEM_READ( "capset(header)",
3020 ARG1
, sizeof(struct __vki_user_cap_header_struct
) );
3021 PRE_MEM_READ( "capset(data)",
3022 ARG2
, sizeof(struct __vki_user_cap_data_struct
) );
3025 /* ---------------------------------------------------------------------
3026 16-bit uid/gid/groups wrappers
3027 ------------------------------------------------------------------ */
3031 PRINT("sys_getuid16 ( )");
3032 PRE_REG_READ0(long, "getuid16");
3037 PRINT("sys_setuid16 ( %" FMT_REGWORD
"u )", ARG1
);
3038 PRE_REG_READ1(long, "setuid16", vki_old_uid_t
, uid
);
3043 PRINT("sys_getgid16 ( )");
3044 PRE_REG_READ0(long, "getgid16");
3049 PRINT("sys_setgid16 ( %" FMT_REGWORD
"u )", ARG1
);
3050 PRE_REG_READ1(long, "setgid16", vki_old_gid_t
, gid
);
3055 PRINT("sys_geteuid16 ( )");
3056 PRE_REG_READ0(long, "geteuid16");
3061 PRINT("sys_getegid16 ( )");
3062 PRE_REG_READ0(long, "getegid16");
3067 PRINT("setreuid16 ( 0x%" FMT_REGWORD
"x, 0x%" FMT_REGWORD
"x )", ARG1
, ARG2
);
3068 PRE_REG_READ2(long, "setreuid16", vki_old_uid_t
, ruid
, vki_old_uid_t
, euid
);
3073 PRINT("sys_setregid16 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )", ARG1
, ARG2
);
3074 PRE_REG_READ2(long, "setregid16", vki_old_gid_t
, rgid
, vki_old_gid_t
, egid
);
3077 PRE(sys_getgroups16
)
3079 PRINT("sys_getgroups16 ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3080 PRE_REG_READ2(long, "getgroups16", int, size
, vki_old_gid_t
*, list
);
3082 PRE_MEM_WRITE( "getgroups16(list)", ARG2
, ARG1
* sizeof(vki_old_gid_t
) );
3084 POST(sys_getgroups16
)
3087 if (ARG1
> 0 && RES
> 0)
3088 POST_MEM_WRITE( ARG2
, RES
* sizeof(vki_old_gid_t
) );
3091 PRE(sys_setgroups16
)
3093 PRINT("sys_setgroups16 ( %llu, %#" FMT_REGWORD
"x )", (ULong
)ARG1
, ARG2
);
3094 PRE_REG_READ2(long, "setgroups16", int, size
, vki_old_gid_t
*, list
);
3096 PRE_MEM_READ( "setgroups16(list)", ARG2
, ARG1
* sizeof(vki_old_gid_t
) );
3099 /* ---------------------------------------------------------------------
3101 ------------------------------------------------------------------ */
3105 PRINT("sys_chown16 ( %#" FMT_REGWORD
"x, 0x%" FMT_REGWORD
"x, 0x%"
3106 FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
3107 PRE_REG_READ3(long, "chown16",
3109 vki_old_uid_t
, owner
, vki_old_gid_t
, group
);
3110 PRE_MEM_RASCIIZ( "chown16(path)", ARG1
);
3115 PRINT("sys_fchown16 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
3116 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
3117 PRE_REG_READ3(long, "fchown16",
3118 unsigned int, fd
, vki_old_uid_t
, owner
, vki_old_gid_t
, group
);
3121 /* ---------------------------------------------------------------------
3123 ------------------------------------------------------------------ */
3127 *flags
|= SfMayBlock
;
3128 PRINT("sys_setxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
3129 FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld )", ARG1
, ARG2
, ARG3
,
3131 PRE_REG_READ5(long, "setxattr",
3132 char *, path
, char *, name
,
3133 void *, value
, vki_size_t
, size
, int, flags
);
3134 PRE_MEM_RASCIIZ( "setxattr(path)", ARG1
);
3135 PRE_MEM_RASCIIZ( "setxattr(name)", ARG2
);
3136 PRE_MEM_READ( "setxattr(value)", ARG3
, ARG4
);
3141 *flags
|= SfMayBlock
;
3142 PRINT("sys_lsetxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
3143 FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld )",
3144 ARG1
, ARG2
, ARG3
, ARG4
, SARG5
);
3145 PRE_REG_READ5(long, "lsetxattr",
3146 char *, path
, char *, name
,
3147 void *, value
, vki_size_t
, size
, int, flags
);
3148 PRE_MEM_RASCIIZ( "lsetxattr(path)", ARG1
);
3149 PRE_MEM_RASCIIZ( "lsetxattr(name)", ARG2
);
3150 PRE_MEM_READ( "lsetxattr(value)", ARG3
, ARG4
);
3155 *flags
|= SfMayBlock
;
3156 PRINT("sys_fsetxattr ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %"
3157 FMT_REGWORD
"u, %ld )",
3158 SARG1
, ARG2
, ARG3
, ARG4
, SARG5
);
3159 PRE_REG_READ5(long, "fsetxattr",
3160 int, fd
, char *, name
, void *, value
,
3161 vki_size_t
, size
, int, flags
);
3162 PRE_MEM_RASCIIZ( "fsetxattr(name)", ARG2
);
3163 PRE_MEM_READ( "fsetxattr(value)", ARG3
, ARG4
);
3168 *flags
|= SfMayBlock
;
3169 PRINT("sys_getxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
3170 FMT_REGWORD
"x, %llu )", ARG1
, ARG2
, ARG3
, (ULong
)ARG4
);
3171 PRE_REG_READ4(ssize_t
, "getxattr",
3172 char *, path
, char *, name
, void *, value
, vki_size_t
, size
);
3173 PRE_MEM_RASCIIZ( "getxattr(path)", ARG1
);
3174 PRE_MEM_RASCIIZ( "getxattr(name)", ARG2
);
3175 PRE_MEM_WRITE( "getxattr(value)", ARG3
, ARG4
);
3180 if (RES
> 0 && ARG3
!= (Addr
)NULL
) {
3181 POST_MEM_WRITE( ARG3
, RES
);
3187 *flags
|= SfMayBlock
;
3188 PRINT("sys_lgetxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
3189 FMT_REGWORD
"x, %llu )", ARG1
, ARG2
, ARG3
, (ULong
)ARG4
);
3190 PRE_REG_READ4(ssize_t
, "lgetxattr",
3191 char *, path
, char *, name
, void *, value
, vki_size_t
, size
);
3192 PRE_MEM_RASCIIZ( "lgetxattr(path)", ARG1
);
3193 PRE_MEM_RASCIIZ( "lgetxattr(name)", ARG2
);
3194 PRE_MEM_WRITE( "lgetxattr(value)", ARG3
, ARG4
);
3199 if (RES
> 0 && ARG3
!= (Addr
)NULL
) {
3200 POST_MEM_WRITE( ARG3
, RES
);
3206 *flags
|= SfMayBlock
;
3207 PRINT("sys_fgetxattr ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %"
3208 FMT_REGWORD
"u )", SARG1
, ARG2
, ARG3
, ARG4
);
3209 PRE_REG_READ4(ssize_t
, "fgetxattr",
3210 int, fd
, char *, name
, void *, value
, vki_size_t
, size
);
3211 PRE_MEM_RASCIIZ( "fgetxattr(name)", ARG2
);
3212 PRE_MEM_WRITE( "fgetxattr(value)", ARG3
, ARG4
);
3216 if (RES
> 0 && ARG3
!= (Addr
)NULL
)
3217 POST_MEM_WRITE( ARG3
, RES
);
3222 *flags
|= SfMayBlock
;
3223 PRINT("sys_listxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %llu )",
3224 ARG1
, ARG2
, (ULong
)ARG3
);
3225 PRE_REG_READ3(ssize_t
, "listxattr",
3226 char *, path
, char *, list
, vki_size_t
, size
);
3227 PRE_MEM_RASCIIZ( "listxattr(path)", ARG1
);
3228 PRE_MEM_WRITE( "listxattr(list)", ARG2
, ARG3
);
3232 if (RES
> 0 && ARG2
!= (Addr
)NULL
)
3233 POST_MEM_WRITE( ARG2
, RES
);
3238 *flags
|= SfMayBlock
;
3239 PRINT("sys_llistxattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %llu )",
3240 ARG1
, ARG2
, (ULong
)ARG3
);
3241 PRE_REG_READ3(ssize_t
, "llistxattr",
3242 char *, path
, char *, list
, vki_size_t
, size
);
3243 PRE_MEM_RASCIIZ( "llistxattr(path)", ARG1
);
3244 PRE_MEM_WRITE( "llistxattr(list)", ARG2
, ARG3
);
3246 POST(sys_llistxattr
)
3248 if (RES
> 0 && ARG2
!= (Addr
)NULL
)
3249 POST_MEM_WRITE( ARG2
, RES
);
3254 *flags
|= SfMayBlock
;
3255 PRINT("sys_flistxattr ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
3257 PRE_REG_READ3(ssize_t
, "flistxattr",
3258 int, fd
, char *, list
, vki_size_t
, size
);
3259 PRE_MEM_WRITE( "flistxattr(list)", ARG2
, ARG3
);
3261 POST(sys_flistxattr
)
3263 if (RES
> 0 && ARG2
!= (Addr
)NULL
)
3264 POST_MEM_WRITE( ARG2
, RES
);
3267 PRE(sys_removexattr
)
3269 *flags
|= SfMayBlock
;
3270 PRINT("sys_removexattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
3272 PRE_REG_READ2(long, "removexattr", char *, path
, char *, name
);
3273 PRE_MEM_RASCIIZ( "removexattr(path)", ARG1
);
3274 PRE_MEM_RASCIIZ( "removexattr(name)", ARG2
);
3277 PRE(sys_lremovexattr
)
3279 *flags
|= SfMayBlock
;
3280 PRINT("sys_lremovexattr ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
3282 PRE_REG_READ2(long, "lremovexattr", char *, path
, char *, name
);
3283 PRE_MEM_RASCIIZ( "lremovexattr(path)", ARG1
);
3284 PRE_MEM_RASCIIZ( "lremovexattr(name)", ARG2
);
3287 PRE(sys_fremovexattr
)
3289 *flags
|= SfMayBlock
;
3290 PRINT("sys_fremovexattr ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3291 PRE_REG_READ2(long, "fremovexattr", int, fd
, char *, name
);
3292 PRE_MEM_RASCIIZ( "fremovexattr(name)", ARG2
);
3295 /* ---------------------------------------------------------------------
3297 ------------------------------------------------------------------ */
3299 PRE(sys_sched_setparam
)
3301 PRINT("sched_setparam ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3302 PRE_REG_READ2(long, "sched_setparam",
3303 vki_pid_t
, pid
, struct sched_param
*, p
);
3304 PRE_MEM_READ( "sched_setparam(p)", ARG2
, sizeof(struct vki_sched_param
) );
3306 POST(sys_sched_setparam
)
3308 POST_MEM_WRITE( ARG2
, sizeof(struct vki_sched_param
) );
3311 PRE(sys_sched_getparam
)
3313 PRINT("sched_getparam ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3314 PRE_REG_READ2(long, "sched_getparam",
3315 vki_pid_t
, pid
, struct sched_param
*, p
);
3316 PRE_MEM_WRITE( "sched_getparam(p)", ARG2
, sizeof(struct vki_sched_param
) );
3318 POST(sys_sched_getparam
)
3320 POST_MEM_WRITE( ARG2
, sizeof(struct vki_sched_param
) );
3323 PRE(sys_sched_getscheduler
)
3325 PRINT("sys_sched_getscheduler ( %ld )", SARG1
);
3326 PRE_REG_READ1(long, "sched_getscheduler", vki_pid_t
, pid
);
3329 PRE(sys_sched_setscheduler
)
3331 PRINT("sys_sched_setscheduler ( %ld, %ld, %#" FMT_REGWORD
"x )",
3332 SARG1
, SARG2
, ARG3
);
3333 PRE_REG_READ3(long, "sched_setscheduler",
3334 vki_pid_t
, pid
, int, policy
, struct sched_param
*, p
);
3336 PRE_MEM_READ( "sched_setscheduler(p)",
3337 ARG3
, sizeof(struct vki_sched_param
));
3340 PRE(sys_sched_yield
)
3342 *flags
|= SfMayBlock
;
3343 PRINT("sched_yield()");
3344 PRE_REG_READ0(long, "sys_sched_yield");
3347 PRE(sys_sched_get_priority_max
)
3349 PRINT("sched_get_priority_max ( %ld )", SARG1
);
3350 PRE_REG_READ1(long, "sched_get_priority_max", int, policy
);
3353 PRE(sys_sched_get_priority_min
)
3355 PRINT("sched_get_priority_min ( %ld )", SARG1
);
3356 PRE_REG_READ1(long, "sched_get_priority_min", int, policy
);
3359 PRE(sys_sched_rr_get_interval
)
3361 PRINT("sys_sched_rr_get_interval ( %ld, %#" FMT_REGWORD
"x )", SARG1
, ARG2
);
3362 PRE_REG_READ2(int, "sched_rr_get_interval",
3364 struct vki_timespec
*, tp
);
3365 PRE_MEM_WRITE("sched_rr_get_interval(timespec)",
3366 ARG2
, sizeof(struct vki_timespec
));
3369 POST(sys_sched_rr_get_interval
)
3371 POST_MEM_WRITE(ARG2
, sizeof(struct vki_timespec
));
3374 PRE(sys_sched_setaffinity
)
3376 PRINT("sched_setaffinity ( %ld, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
3378 PRE_REG_READ3(long, "sched_setaffinity",
3379 vki_pid_t
, pid
, unsigned int, len
, unsigned long *, mask
);
3380 PRE_MEM_READ( "sched_setaffinity(mask)", ARG3
, ARG2
);
3383 PRE(sys_sched_getaffinity
)
3385 PRINT("sched_getaffinity ( %ld, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
3387 PRE_REG_READ3(long, "sched_getaffinity",
3388 vki_pid_t
, pid
, unsigned int, len
, unsigned long *, mask
);
3389 PRE_MEM_WRITE( "sched_getaffinity(mask)", ARG3
, ARG2
);
3391 POST(sys_sched_getaffinity
)
3393 POST_MEM_WRITE(ARG3
, ARG2
);
3398 PRINT("sys_unshare ( %#" FMT_REGWORD
"x )", ARG1
);
3399 PRE_REG_READ1(int, "unshare", unsigned long, flags
);
3402 /* ---------------------------------------------------------------------
3403 miscellaneous wrappers
3404 ------------------------------------------------------------------ */
3408 *flags
|= SfMayBlock
;
3409 PRINT("sys_munlockall ( )");
3410 PRE_REG_READ0(long, "munlockall");
3413 // This has different signatures for different platforms.
3415 // x86: int sys_pipe(unsigned long __user *fildes);
3416 // AMD64: long sys_pipe(int *fildes);
3417 // ppc32: int sys_pipe(int __user *fildes);
3418 // ppc64: int sys_pipe(int __user *fildes);
3420 // The type of the argument is most important, and it is an array of 32 bit
3421 // values in all cases. (The return type differs across platforms, but it
3422 // is not used.) So we use 'int' as its type. This fixed bug #113230 which
3423 // was caused by using an array of 'unsigned long's, which didn't work on
3427 PRINT("sys_pipe ( %#" FMT_REGWORD
"x )", ARG1
);
3428 PRE_REG_READ1(int, "pipe", int *, filedes
);
3429 PRE_MEM_WRITE( "pipe(filedes)", ARG1
, 2*sizeof(int) );
3433 Int
*p
= (Int
*)(Addr
)ARG1
;
3434 if (!ML_(fd_allowed
)(p
[0], "pipe", tid
, True
) ||
3435 !ML_(fd_allowed
)(p
[1], "pipe", tid
, True
)) {
3438 SET_STATUS_Failure( VKI_EMFILE
);
3440 POST_MEM_WRITE( ARG1
, 2*sizeof(int) );
3441 if (VG_(clo_track_fds
)) {
3442 ML_(record_fd_open_nameless
)(tid
, p
[0]);
3443 ML_(record_fd_open_nameless
)(tid
, p
[1]);
3448 /* pipe2 (a kernel 2.6.twentysomething invention) is like pipe, except
3449 there's a second arg containing flags to be applied to the new file
3450 descriptors. It hardly seems worth the effort to factor out the
3451 duplicated code, hence: */
3454 PRINT("sys_pipe2 ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )", ARG1
, ARG2
);
3455 PRE_REG_READ2(int, "pipe", int *, filedes
, long, flags
);
3456 PRE_MEM_WRITE( "pipe2(filedes)", ARG1
, 2*sizeof(int) );
3460 Int
*p
= (Int
*)(Addr
)ARG1
;
3461 if (!ML_(fd_allowed
)(p
[0], "pipe2", tid
, True
) ||
3462 !ML_(fd_allowed
)(p
[1], "pipe2", tid
, True
)) {
3465 SET_STATUS_Failure( VKI_EMFILE
);
3467 POST_MEM_WRITE( ARG1
, 2*sizeof(int) );
3468 if (VG_(clo_track_fds
)) {
3469 ML_(record_fd_open_nameless
)(tid
, p
[0]);
3470 ML_(record_fd_open_nameless
)(tid
, p
[1]);
3477 PRINT("sys_dup3 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %#"
3478 FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
3479 PRE_REG_READ3(long, "dup3", unsigned int, oldfd
, unsigned int, newfd
, int, flags
);
3480 if (!ML_(fd_allowed
)(ARG2
, "dup3", tid
, True
))
3481 SET_STATUS_Failure( VKI_EBADF
);
3487 if (VG_(clo_track_fds
))
3488 ML_(record_fd_open_named
)(tid
, RES
);
3493 PRINT("sys_quotactl (0x%" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, 0x%"
3494 FMT_REGWORD
"x, 0x%" FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
, ARG4
);
3495 PRE_REG_READ4(long, "quotactl",
3496 unsigned int, cmd
, const char *, special
, vki_qid_t
, id
,
3498 PRE_MEM_RASCIIZ( "quotactl(special)", ARG2
);
3503 *flags
|= SfMayBlock
;
3504 PRINT("sys_waitid( %ld, %ld, %#" FMT_REGWORD
"x, %ld, %#" FMT_REGWORD
"x )",
3505 SARG1
, SARG2
, ARG3
, SARG4
, ARG5
);
3506 PRE_REG_READ5(int32_t, "sys_waitid",
3507 int, which
, vki_pid_t
, pid
, struct vki_siginfo
*, infop
,
3508 int, options
, struct vki_rusage
*, ru
);
3509 PRE_MEM_WRITE( "waitid(infop)", ARG3
, sizeof(struct vki_siginfo
) );
3511 PRE_MEM_WRITE( "waitid(ru)", ARG5
, sizeof(struct vki_rusage
) );
3515 POST_MEM_WRITE( ARG3
, sizeof(struct vki_siginfo
) );
3517 POST_MEM_WRITE( ARG5
, sizeof(struct vki_rusage
) );
3520 PRE(sys_sync_file_range
)
3522 *flags
|= SfMayBlock
;
3523 #if VG_WORDSIZE == 4
3524 PRINT("sys_sync_file_range ( %ld, %lld, %lld, %#" FMT_REGWORD
"x )",
3525 SARG1
, (Long
)MERGE64(ARG2
,ARG3
), (Long
)MERGE64(ARG4
,ARG5
),ARG6
);
3526 PRE_REG_READ6(long, "sync_file_range",
3528 unsigned, MERGE64_FIRST(offset
), unsigned, MERGE64_SECOND(offset
),
3529 unsigned, MERGE64_FIRST(nbytes
), unsigned, MERGE64_SECOND(nbytes
),
3530 unsigned int, flags
);
3531 #elif VG_WORDSIZE == 8
3532 PRINT("sys_sync_file_range ( %ld, %ld, %ld, %#lx )",
3533 SARG1
, SARG2
, SARG3
, ARG4
);
3534 PRE_REG_READ4(long, "sync_file_range",
3535 int, fd
, vki_loff_t
, offset
, vki_loff_t
, nbytes
,
3536 unsigned int, flags
);
3538 # error Unexpected word size
3540 if (!ML_(fd_allowed
)(ARG1
, "sync_file_range", tid
, False
))
3541 SET_STATUS_Failure( VKI_EBADF
);
3544 PRE(sys_sync_file_range2
)
3546 *flags
|= SfMayBlock
;
3547 #if VG_WORDSIZE == 4
3548 PRINT("sys_sync_file_range2 ( %ld, %" FMT_REGWORD
"u, %lld, %lld )",
3549 SARG1
, ARG2
, (Long
)MERGE64(ARG3
,ARG4
), (Long
)MERGE64(ARG5
,ARG6
));
3550 PRE_REG_READ6(long, "sync_file_range2",
3551 int, fd
, unsigned int, flags
,
3552 unsigned, MERGE64_FIRST(offset
), unsigned, MERGE64_SECOND(offset
),
3553 unsigned, MERGE64_FIRST(nbytes
), unsigned, MERGE64_SECOND(nbytes
));
3554 #elif VG_WORDSIZE == 8
3555 PRINT("sys_sync_file_range2 ( %ld, %lu, %ld, %ld )",
3556 SARG1
, ARG2
, SARG3
, SARG4
);
3557 PRE_REG_READ4(long, "sync_file_range2",
3558 int, fd
, unsigned int, flags
,
3559 vki_loff_t
, offset
, vki_loff_t
, nbytes
);
3561 # error Unexpected word size
3563 if (!ML_(fd_allowed
)(ARG1
, "sync_file_range2", tid
, False
))
3564 SET_STATUS_Failure( VKI_EBADF
);
3569 PRINT("sys_stime ( %#" FMT_REGWORD
"x )", ARG1
);
3570 PRE_REG_READ1(int, "stime", vki_time_t
*, t
);
3571 PRE_MEM_READ( "stime(t)", ARG1
, sizeof(vki_time_t
) );
3574 PRE(sys_perf_event_open
)
3576 struct vki_perf_event_attr
*attr
;
3577 PRINT("sys_perf_event_open ( %#" FMT_REGWORD
"x, %ld, %ld, %ld, %#"
3578 FMT_REGWORD
"x )", ARG1
, SARG2
, SARG3
, SARG4
, ARG5
);
3579 PRE_REG_READ5(long, "perf_event_open",
3580 struct vki_perf_event_attr
*, attr
,
3581 vki_pid_t
, pid
, int, cpu
, int, group_fd
,
3582 unsigned long, flags
);
3583 attr
= (struct vki_perf_event_attr
*)(Addr
)ARG1
;
3584 PRE_MEM_READ( "perf_event_open(attr->size)",
3585 (Addr
)&attr
->size
, sizeof(attr
->size
) );
3586 PRE_MEM_READ( "perf_event_open(attr)",
3587 (Addr
)attr
, attr
->size
);
3590 POST(sys_perf_event_open
)
3593 if (!ML_(fd_allowed
)(RES
, "perf_event_open", tid
, True
)) {
3595 SET_STATUS_Failure( VKI_EMFILE
);
3597 if (VG_(clo_track_fds
))
3598 ML_(record_fd_open_nameless
)(tid
, RES
);
3604 PRINT("sys_getcpu ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
3605 FMT_REGWORD
"x )" , ARG1
, ARG2
, ARG3
);
3606 PRE_REG_READ3(int, "getcpu",
3607 unsigned *, cpu
, unsigned *, node
, struct vki_getcpu_cache
*, tcache
);
3609 PRE_MEM_WRITE( "getcpu(cpu)", ARG1
, sizeof(unsigned) );
3611 PRE_MEM_WRITE( "getcpu(node)", ARG2
, sizeof(unsigned) );
3613 PRE_MEM_WRITE( "getcpu(tcache)", ARG3
, sizeof(struct vki_getcpu_cache
) );
3619 POST_MEM_WRITE( ARG1
, sizeof(unsigned) );
3621 POST_MEM_WRITE( ARG2
, sizeof(unsigned) );
3623 POST_MEM_WRITE( ARG3
, sizeof(struct vki_getcpu_cache
) );
3628 PRINT("sys_move_pages ( %ld, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %#"
3629 FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
3630 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
3631 PRE_REG_READ6(int, "move_pages",
3632 vki_pid_t
, pid
, unsigned long, nr_pages
, const void **, pages
,
3633 const int *, nodes
, int *, status
, int, flags
);
3634 PRE_MEM_READ("move_pages(pages)", ARG3
, ARG2
* sizeof(void *));
3636 PRE_MEM_READ("move_pages(nodes)", ARG4
, ARG2
* sizeof(int));
3637 PRE_MEM_WRITE("move_pages(status)", ARG5
, ARG2
* sizeof(int));
3640 POST(sys_move_pages
)
3642 POST_MEM_WRITE(ARG5
, ARG2
* sizeof(int));
3647 PRINT("sys_getrandom ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
3648 FMT_REGWORD
"u )" , ARG1
, ARG2
, ARG3
);
3649 PRE_REG_READ3(int, "getrandom",
3650 char *, buf
, vki_size_t
, count
, unsigned int, flags
);
3651 PRE_MEM_WRITE( "getrandom(cpu)", ARG1
, ARG2
);
3656 POST_MEM_WRITE( ARG1
, ARG2
);
3659 PRE(sys_memfd_create
)
3661 PRINT("sys_memfd_create ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )" ,
3663 PRE_REG_READ2(int, "memfd_create",
3664 char *, uname
, unsigned int, flags
);
3665 PRE_MEM_RASCIIZ( "memfd_create(uname)", ARG1
);
3668 POST(sys_memfd_create
)
3671 if (!ML_(fd_allowed
)(RES
, "memfd_create", tid
, True
)) {
3673 SET_STATUS_Failure( VKI_EMFILE
);
3675 if (VG_(clo_track_fds
))
3676 ML_(record_fd_open_nameless
)(tid
, RES
);
3682 PRINT("sys_membarrier ( %#" FMT_REGWORD
"x )", ARG1
);
3683 PRE_REG_READ1(int, "membarrier", int, flags
);
3688 *flags
|= SfMayBlock
;
3689 PRINT("sys_syncfs ( %" FMT_REGWORD
"u )", ARG1
);
3690 PRE_REG_READ1(long, "syncfs", unsigned int, fd
);
3695 FUSE_COMPATIBLE_MAY_BLOCK();
3696 PRINT("sys_statx ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %ld, %#" FMT_REGWORD
"x )",
3697 (Word
)ARG1
,ARG2
,(char*)(Addr
)ARG2
,(Word
)ARG3
,(Word
)ARG4
,ARG5
);
3698 PRE_REG_READ5(long, "statx",
3699 int, dirfd
, char *, filename
, int, flags
,
3700 unsigned int, mask
, struct statx
*, buf
);
3701 // Work around Rust's dubious use of statx, as described here:
3702 // https://github.com/rust-lang/rust/blob/
3703 // ccd238309f9dce92a05a23c2959e2819668c69a4/
3704 // src/libstd/sys/unix/fs.rs#L128-L142
3705 // in which it passes NULL for both filename and buf, and then looks at the
3706 // return value, so as to determine whether or not this syscall is supported.
3707 Bool both_filename_and_buf_are_null
= ARG2
== 0 && ARG5
== 0;
3708 if (!both_filename_and_buf_are_null
) {
3709 PRE_MEM_RASCIIZ( "statx(filename)", ARG2
);
3710 PRE_MEM_WRITE( "statx(buf)", ARG5
, sizeof(struct vki_statx
) );
3715 POST_MEM_WRITE( ARG5
, sizeof(struct vki_statx
) );
3718 /* ---------------------------------------------------------------------
3720 ------------------------------------------------------------------ */
3724 *flags
|= SfMayBlock
;
3725 PRINT("sys_utime ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )", ARG1
,ARG2
);
3726 PRE_REG_READ2(long, "utime", char *, filename
, struct utimbuf
*, buf
);
3727 PRE_MEM_RASCIIZ( "utime(filename)", ARG1
);
3729 PRE_MEM_READ( "utime(buf)", ARG2
, sizeof(struct vki_utimbuf
) );
3732 /* ---------------------------------------------------------------------
3734 ------------------------------------------------------------------ */
3738 PRINT("sys_lseek ( %" FMT_REGWORD
"u, %ld, %" FMT_REGWORD
"u )",
3740 PRE_REG_READ3(vki_off_t
, "lseek",
3741 unsigned int, fd
, vki_off_t
, offset
, unsigned int, whence
);
3744 /* ---------------------------------------------------------------------
3746 ------------------------------------------------------------------ */
3750 *flags
|= SfMayBlock
;
3751 #if VG_WORDSIZE == 4
3752 PRINT("sys_readahead ( %ld, %lld, %" FMT_REGWORD
"u )",
3753 SARG1
, (Long
)MERGE64(ARG2
,ARG3
), ARG4
);
3754 PRE_REG_READ4(vki_off_t
, "readahead",
3755 int, fd
, unsigned, MERGE64_FIRST(offset
),
3756 unsigned, MERGE64_SECOND(offset
), vki_size_t
, count
);
3757 #elif VG_WORDSIZE == 8
3758 PRINT("sys_readahead ( %ld, %ld, %lu )", SARG1
, SARG2
, ARG3
);
3759 PRE_REG_READ3(vki_off_t
, "readahead",
3760 int, fd
, vki_loff_t
, offset
, vki_size_t
, count
);
3762 # error Unexpected word size
3764 if (!ML_(fd_allowed
)(ARG1
, "readahead", tid
, False
))
3765 SET_STATUS_Failure( VKI_EBADF
);
3768 /* ---------------------------------------------------------------------
3770 ------------------------------------------------------------------ */
3774 PRINT( "sys_sigpending ( %#" FMT_REGWORD
"x )", ARG1
);
3775 PRE_REG_READ1(long, "sigpending", vki_old_sigset_t
*, set
);
3776 PRE_MEM_WRITE( "sigpending(set)", ARG1
, sizeof(vki_old_sigset_t
));
3778 POST(sys_sigpending
)
3780 POST_MEM_WRITE( ARG1
, sizeof(vki_old_sigset_t
) ) ;
3783 // This syscall is not used on amd64/Linux -- it only provides
3784 // sys_rt_sigprocmask, which uses sigset_t rather than old_sigset_t.
3785 // This wrapper is only suitable for 32-bit architectures.
3786 // (XXX: so how is it that PRE(sys_sigpending) above doesn't need
3787 // conditional compilation like this?)
3788 #if defined(VGP_x86_linux) || defined(VGP_ppc32_linux) \
3789 || defined(VGP_arm_linux) || defined(VGP_mips32_linux) \
3790 || defined(VGP_nanomips_linux)
3791 PRE(sys_sigprocmask
)
3793 vki_old_sigset_t
* set
;
3794 vki_old_sigset_t
* oldset
;
3795 vki_sigset_t bigger_set
;
3796 vki_sigset_t bigger_oldset
;
3798 PRINT("sys_sigprocmask ( %ld, %#lx, %#lx )", SARG1
, ARG2
, ARG3
);
3799 PRE_REG_READ3(long, "sigprocmask",
3800 int, how
, vki_old_sigset_t
*, set
, vki_old_sigset_t
*, oldset
);
3802 PRE_MEM_READ( "sigprocmask(set)", ARG2
, sizeof(vki_old_sigset_t
));
3804 PRE_MEM_WRITE( "sigprocmask(oldset)", ARG3
, sizeof(vki_old_sigset_t
));
3806 // Nb: We must convert the smaller vki_old_sigset_t params into bigger
3807 // vki_sigset_t params.
3808 set
= (vki_old_sigset_t
*)(Addr
)ARG2
;
3809 oldset
= (vki_old_sigset_t
*)(Addr
)ARG3
;
3811 VG_(memset
)(&bigger_set
, 0, sizeof(vki_sigset_t
));
3812 VG_(memset
)(&bigger_oldset
, 0, sizeof(vki_sigset_t
));
3814 bigger_set
.sig
[0] = *(vki_old_sigset_t
*)set
;
3816 SET_STATUS_from_SysRes(
3817 VG_(do_sys_sigprocmask
) ( tid
, ARG1
/*how*/,
3818 set
? &bigger_set
: NULL
,
3819 oldset
? &bigger_oldset
: NULL
)
3823 *oldset
= bigger_oldset
.sig
[0];
3826 *flags
|= SfPollAfter
;
3828 POST(sys_sigprocmask
)
3831 if (RES
== 0 && ARG3
!= 0)
3832 POST_MEM_WRITE( ARG3
, sizeof(vki_old_sigset_t
));
3835 /* Convert from non-RT to RT sigset_t's */
3837 void convert_sigset_to_rt(const vki_old_sigset_t
*oldset
, vki_sigset_t
*set
)
3839 VG_(sigemptyset
)(set
);
3840 set
->sig
[0] = *oldset
;
3844 vki_sigaction_toK_t
new, *newp
;
3845 vki_sigaction_fromK_t old
, *oldp
;
3847 PRINT("sys_sigaction ( %ld, %#lx, %#lx )", SARG1
, ARG2
, ARG3
);
3848 PRE_REG_READ3(int, "sigaction",
3849 int, signum
, const struct old_sigaction
*, act
,
3850 struct old_sigaction
*, oldact
);
3855 struct vki_old_sigaction
*sa
= (struct vki_old_sigaction
*)(Addr
)ARG2
;
3856 PRE_MEM_READ( "sigaction(act->sa_handler)", (Addr
)&sa
->ksa_handler
, sizeof(sa
->ksa_handler
));
3857 PRE_MEM_READ( "sigaction(act->sa_mask)", (Addr
)&sa
->sa_mask
, sizeof(sa
->sa_mask
));
3858 PRE_MEM_READ( "sigaction(act->sa_flags)", (Addr
)&sa
->sa_flags
, sizeof(sa
->sa_flags
));
3859 if (ML_(safe_to_deref
)(sa
,sizeof(struct vki_old_sigaction
))
3860 && (sa
->sa_flags
& VKI_SA_RESTORER
))
3861 PRE_MEM_READ( "sigaction(act->sa_restorer)", (Addr
)&sa
->sa_restorer
, sizeof(sa
->sa_restorer
));
3865 PRE_MEM_WRITE( "sigaction(oldact)", ARG3
, sizeof(struct vki_old_sigaction
));
3869 /* If the new or old sigaction is not NULL, but the structs
3870 aren't accessible then sigaction returns EFAULT and we cannot
3871 use either struct for our own bookkeeping. Just fail early. */
3873 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG2
,
3874 sizeof(struct vki_old_sigaction
))) {
3875 VG_(umsg
)("Warning: bad act handler address %p in sigaction()\n",
3876 (void *)(Addr
)ARG2
);
3877 SET_STATUS_Failure ( VKI_EFAULT
);
3878 } else if ((ARG3
!= 0
3879 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG3
,
3880 sizeof(struct vki_old_sigaction
)))) {
3881 VG_(umsg
)("Warning: bad oldact handler address %p in sigaction()\n",
3882 (void *)(Addr
)ARG3
);
3883 SET_STATUS_Failure ( VKI_EFAULT
);
3886 struct vki_old_sigaction
*oldnew
=
3887 (struct vki_old_sigaction
*)(Addr
)ARG2
;
3889 new.ksa_handler
= oldnew
->ksa_handler
;
3890 new.sa_flags
= oldnew
->sa_flags
;
3891 new.sa_restorer
= oldnew
->sa_restorer
;
3892 convert_sigset_to_rt(&oldnew
->sa_mask
, &new.sa_mask
);
3896 SET_STATUS_from_SysRes( VG_(do_sys_sigaction
)(ARG1
, newp
, oldp
) );
3898 if (ARG3
!= 0 && SUCCESS
&& RES
== 0) {
3899 struct vki_old_sigaction
*oldold
=
3900 (struct vki_old_sigaction
*)(Addr
)ARG3
;
3902 oldold
->ksa_handler
= oldp
->ksa_handler
;
3903 oldold
->sa_flags
= oldp
->sa_flags
;
3904 oldold
->sa_restorer
= oldp
->sa_restorer
;
3905 oldold
->sa_mask
= oldp
->sa_mask
.sig
[0];
3912 if (RES
== 0 && ARG3
!= 0)
3913 POST_MEM_WRITE( ARG3
, sizeof(struct vki_old_sigaction
));
3919 PRINT("sys_signalfd ( %d, %#" FMT_REGWORD
"x, %llu )", (Int
)ARG1
, ARG2
,
3921 PRE_REG_READ3(long, "sys_signalfd",
3922 int, fd
, vki_sigset_t
*, sigmask
, vki_size_t
, sigsetsize
);
3923 PRE_MEM_READ( "signalfd(sigmask)", ARG2
, sizeof(vki_sigset_t
) );
3924 if ((int)ARG1
!= -1 && !ML_(fd_allowed
)(ARG1
, "signalfd", tid
, False
))
3925 SET_STATUS_Failure( VKI_EBADF
);
3929 if (!ML_(fd_allowed
)(RES
, "signalfd", tid
, True
)) {
3931 SET_STATUS_Failure( VKI_EMFILE
);
3933 if (VG_(clo_track_fds
))
3934 ML_(record_fd_open_nameless
) (tid
, RES
);
3940 PRINT("sys_signalfd4 ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld )",
3941 SARG1
, ARG2
, ARG3
, SARG4
);
3942 PRE_REG_READ4(long, "sys_signalfd4",
3943 int, fd
, vki_sigset_t
*, sigmask
, vki_size_t
, sigsetsize
, int, flags
);
3944 PRE_MEM_READ( "signalfd(sigmask)", ARG2
, sizeof(vki_sigset_t
) );
3945 if ((int)ARG1
!= -1 && !ML_(fd_allowed
)(ARG1
, "signalfd", tid
, False
))
3946 SET_STATUS_Failure( VKI_EBADF
);
3950 if (!ML_(fd_allowed
)(RES
, "signalfd4", tid
, True
)) {
3952 SET_STATUS_Failure( VKI_EMFILE
);
3954 if (VG_(clo_track_fds
))
3955 ML_(record_fd_open_nameless
) (tid
, RES
);
3960 /* ---------------------------------------------------------------------
3962 ------------------------------------------------------------------ */
3964 PRE(sys_rt_sigaction
)
3966 PRINT("sys_rt_sigaction ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %"
3967 FMT_REGWORD
"u )", SARG1
, ARG2
, ARG3
, ARG4
);
3968 PRE_REG_READ4(long, "rt_sigaction",
3969 int, signum
, const struct sigaction
*, act
,
3970 struct sigaction
*, oldact
, vki_size_t
, sigsetsize
);
3973 vki_sigaction_toK_t
*sa
= (vki_sigaction_toK_t
*)(Addr
)ARG2
;
3974 PRE_MEM_READ( "rt_sigaction(act->sa_handler)", (Addr
)&sa
->ksa_handler
, sizeof(sa
->ksa_handler
));
3975 PRE_MEM_READ( "rt_sigaction(act->sa_mask)", (Addr
)&sa
->sa_mask
, sizeof(sa
->sa_mask
));
3976 PRE_MEM_READ( "rt_sigaction(act->sa_flags)", (Addr
)&sa
->sa_flags
, sizeof(sa
->sa_flags
));
3977 if (ML_(safe_to_deref
)(sa
,sizeof(vki_sigaction_toK_t
))
3978 && (sa
->sa_flags
& VKI_SA_RESTORER
))
3979 PRE_MEM_READ( "rt_sigaction(act->sa_restorer)", (Addr
)&sa
->sa_restorer
, sizeof(sa
->sa_restorer
));
3982 PRE_MEM_WRITE( "rt_sigaction(oldact)", ARG3
, sizeof(vki_sigaction_fromK_t
));
3984 /* If the new or old sigaction is not NULL, but the structs
3985 aren't accessible then sigaction returns EFAULT and we cannot
3986 use either struct for our own bookkeeping. Just fail early. */
3988 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG2
,
3989 sizeof(vki_sigaction_toK_t
))) {
3990 VG_(umsg
)("Warning: bad act handler address %p in rt_sigaction()\n",
3991 (void *)(Addr
)ARG2
);
3992 SET_STATUS_Failure ( VKI_EFAULT
);
3993 } else if ((ARG3
!= 0
3994 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG3
,
3995 sizeof(vki_sigaction_fromK_t
)))) {
3996 VG_(umsg
)("Warning: bad oldact handler address %p in rt_sigaction()\n",
3997 (void *)(Addr
)ARG3
);
3998 SET_STATUS_Failure ( VKI_EFAULT
);
4001 // XXX: doesn't seem right to be calling do_sys_sigaction for
4002 // sys_rt_sigaction... perhaps this function should be renamed
4003 // VG_(do_sys_rt_sigaction)() --njn
4005 SET_STATUS_from_SysRes(
4006 VG_(do_sys_sigaction
)(ARG1
, (const vki_sigaction_toK_t
*)(Addr
)ARG2
,
4007 (vki_sigaction_fromK_t
*)(Addr
)ARG3
)
4011 POST(sys_rt_sigaction
)
4014 if (RES
== 0 && ARG3
!= 0)
4015 POST_MEM_WRITE( ARG3
, sizeof(vki_sigaction_fromK_t
));
4018 PRE(sys_rt_sigprocmask
)
4020 PRINT("sys_rt_sigprocmask ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %"
4021 FMT_REGWORD
"u )", SARG1
, ARG2
, ARG3
, ARG4
);
4022 PRE_REG_READ4(long, "rt_sigprocmask",
4023 int, how
, vki_sigset_t
*, set
, vki_sigset_t
*, oldset
,
4024 vki_size_t
, sigsetsize
);
4026 PRE_MEM_READ( "rt_sigprocmask(set)", ARG2
, sizeof(vki_sigset_t
));
4028 PRE_MEM_WRITE( "rt_sigprocmask(oldset)", ARG3
, sizeof(vki_sigset_t
));
4030 // Like the kernel, we fail if the sigsetsize is not exactly what we expect.
4031 // Since we want to use the set and oldset for bookkeeping we also want
4032 // to make sure they are addressable otherwise, like the kernel, we EFAULT.
4033 if (sizeof(vki_sigset_t
) != ARG4
)
4034 SET_STATUS_Failure( VKI_EINVAL
);
4036 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG2
, sizeof(vki_sigset_t
))) {
4037 VG_(dmsg
)("Warning: Bad set handler address %p in sigprocmask\n",
4038 (void *)(Addr
)ARG2
);
4039 SET_STATUS_Failure ( VKI_EFAULT
);
4042 && ! ML_(safe_to_deref
)((void *)(Addr
)ARG3
, sizeof(vki_sigset_t
))) {
4043 VG_(dmsg
)("Warning: Bad oldset address %p in sigprocmask\n",
4044 (void *)(Addr
)ARG3
);
4045 SET_STATUS_Failure ( VKI_EFAULT
);
4049 SET_STATUS_from_SysRes(
4050 VG_(do_sys_sigprocmask
) ( tid
, ARG1
/*how*/,
4051 (vki_sigset_t
*) (Addr
)ARG2
,
4052 (vki_sigset_t
*) (Addr
)ARG3
)
4057 *flags
|= SfPollAfter
;
4059 POST(sys_rt_sigprocmask
)
4062 if (RES
== 0 && ARG3
!= 0)
4063 POST_MEM_WRITE( ARG3
, sizeof(vki_sigset_t
));
4066 PRE(sys_rt_sigpending
)
4068 PRINT( "sys_rt_sigpending ( %#" FMT_REGWORD
"x )", ARG1
);
4069 PRE_REG_READ2(long, "rt_sigpending",
4070 vki_sigset_t
*, set
, vki_size_t
, sigsetsize
);
4071 PRE_MEM_WRITE( "rt_sigpending(set)", ARG1
, sizeof(vki_sigset_t
));
4073 POST(sys_rt_sigpending
)
4075 POST_MEM_WRITE( ARG1
, sizeof(vki_sigset_t
) ) ;
4078 PRE(sys_rt_sigtimedwait
)
4080 *flags
|= SfMayBlock
;
4081 PRINT("sys_rt_sigtimedwait ( %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %#"
4082 FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
4083 ARG1
, ARG2
, ARG3
, ARG4
);
4084 PRE_REG_READ4(long, "rt_sigtimedwait",
4085 const vki_sigset_t
*, set
, vki_siginfo_t
*, info
,
4086 const struct timespec
*, timeout
, vki_size_t
, sigsetsize
);
4088 PRE_MEM_READ( "rt_sigtimedwait(set)", ARG1
, sizeof(vki_sigset_t
));
4090 PRE_MEM_WRITE( "rt_sigtimedwait(info)", ARG2
, sizeof(vki_siginfo_t
) );
4092 PRE_MEM_READ( "rt_sigtimedwait(timeout)",
4093 ARG3
, sizeof(struct vki_timespec
) );
4095 POST(sys_rt_sigtimedwait
)
4098 POST_MEM_WRITE( ARG2
, sizeof(vki_siginfo_t
) );
4101 PRE(sys_rt_sigqueueinfo
)
4103 PRINT("sys_rt_sigqueueinfo(%ld, %ld, %#" FMT_REGWORD
"x)",
4104 SARG1
, SARG2
, ARG3
);
4105 PRE_REG_READ3(long, "rt_sigqueueinfo",
4106 int, pid
, int, sig
, vki_siginfo_t
*, uinfo
);
4108 PRE_MEM_READ( "rt_sigqueueinfo(uinfo)", ARG3
, VKI_SI_MAX_SIZE
);
4110 POST(sys_rt_sigqueueinfo
)
4112 if (!ML_(client_signal_OK
)(ARG2
))
4113 SET_STATUS_Failure( VKI_EINVAL
);
4116 PRE(sys_rt_tgsigqueueinfo
)
4118 PRINT("sys_rt_tgsigqueueinfo(%ld, %ld, %ld, %#" FMT_REGWORD
"x)",
4119 SARG1
, SARG2
, SARG3
, ARG4
);
4120 PRE_REG_READ4(long, "rt_tgsigqueueinfo",
4121 int, tgid
, int, pid
, int, sig
, vki_siginfo_t
*, uinfo
);
4123 PRE_MEM_READ( "rt_tgsigqueueinfo(uinfo)", ARG4
, VKI_SI_MAX_SIZE
);
4126 POST(sys_rt_tgsigqueueinfo
)
4128 if (!ML_(client_signal_OK
)(ARG3
))
4129 SET_STATUS_Failure( VKI_EINVAL
);
4132 // XXX: x86-specific? The kernel prototypes for the different archs are
4133 // hard to decipher.
4134 PRE(sys_rt_sigsuspend
)
4136 /* The C library interface to sigsuspend just takes a pointer to
4137 a signal mask but this system call has two arguments - a pointer
4138 to the mask and the number of bytes used by it. The kernel insists
4139 on the size being equal to sizeof(sigset_t) however and will just
4140 return EINVAL if it isn't.
4142 *flags
|= SfMayBlock
;
4143 PRINT("sys_rt_sigsuspend ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
4145 PRE_REG_READ2(int, "rt_sigsuspend", vki_sigset_t
*, mask
, vki_size_t
, size
)
4146 if (ARG1
!= (Addr
)NULL
) {
4147 PRE_MEM_READ( "rt_sigsuspend(mask)", ARG1
, sizeof(vki_sigset_t
) );
4148 if (ML_(safe_to_deref
)((vki_sigset_t
*) (Addr
)ARG1
, sizeof(vki_sigset_t
))) {
4149 VG_(sigdelset
)((vki_sigset_t
*) (Addr
)ARG1
, VG_SIGVGKILL
);
4150 /* We cannot mask VG_SIGVGKILL, as otherwise this thread would not
4151 be killable by VG_(nuke_all_threads_except).
4152 We thus silently ignore the user request to mask this signal.
4153 Note that this is similar to what is done for e.g.
4154 sigprocmask (see m_signals.c calculate_SKSS_from_SCSS). */
4156 SET_STATUS_Failure(VKI_EFAULT
);
4161 /* ---------------------------------------------------------------------
4162 linux msg* wrapper helpers
4163 ------------------------------------------------------------------ */
4166 ML_(linux_PRE_sys_msgsnd
) ( ThreadId tid
,
4167 UWord arg0
, UWord arg1
, UWord arg2
, UWord arg3
)
4169 /* int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg); */
4170 struct vki_msgbuf
*msgp
= (struct vki_msgbuf
*)arg1
;
4171 PRE_MEM_READ( "msgsnd(msgp->mtype)", (Addr
)&msgp
->mtype
, sizeof(msgp
->mtype
) );
4172 PRE_MEM_READ( "msgsnd(msgp->mtext)", (Addr
)&msgp
->mtext
, arg2
);
4176 ML_(linux_PRE_sys_msgrcv
) ( ThreadId tid
,
4177 UWord arg0
, UWord arg1
, UWord arg2
,
4178 UWord arg3
, UWord arg4
)
4180 /* ssize_t msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz,
4181 long msgtyp, int msgflg); */
4182 struct vki_msgbuf
*msgp
= (struct vki_msgbuf
*)arg1
;
4183 PRE_MEM_WRITE( "msgrcv(msgp->mtype)", (Addr
)&msgp
->mtype
, sizeof(msgp
->mtype
) );
4184 PRE_MEM_WRITE( "msgrcv(msgp->mtext)", (Addr
)&msgp
->mtext
, arg2
);
4187 ML_(linux_POST_sys_msgrcv
) ( ThreadId tid
,
4189 UWord arg0
, UWord arg1
, UWord arg2
,
4190 UWord arg3
, UWord arg4
)
4192 struct vki_msgbuf
*msgp
= (struct vki_msgbuf
*)arg1
;
4193 POST_MEM_WRITE( (Addr
)&msgp
->mtype
, sizeof(msgp
->mtype
) );
4194 POST_MEM_WRITE( (Addr
)&msgp
->mtext
, res
);
4198 ML_(linux_PRE_sys_msgctl
) ( ThreadId tid
,
4199 UWord arg0
, UWord arg1
, UWord arg2
)
4201 /* int msgctl(int msqid, int cmd, struct msqid_ds *buf); */
4202 switch (arg1
/* cmd */) {
4205 case VKI_IPC_INFO
|VKI_IPC_64
:
4206 case VKI_MSG_INFO
|VKI_IPC_64
:
4207 PRE_MEM_WRITE( "msgctl(IPC_INFO, buf)",
4208 arg2
, sizeof(struct vki_msginfo
) );
4212 PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)",
4213 arg2
, sizeof(struct vki_msqid_ds
) );
4215 case VKI_IPC_STAT
|VKI_IPC_64
:
4216 case VKI_MSG_STAT
|VKI_IPC_64
:
4217 PRE_MEM_WRITE( "msgctl(IPC_STAT, arg.buf)",
4218 arg2
, sizeof(struct vki_msqid64_ds
) );
4221 PRE_MEM_READ( "msgctl(IPC_SET, arg.buf)",
4222 arg2
, sizeof(struct vki_msqid_ds
) );
4224 case VKI_IPC_SET
|VKI_IPC_64
:
4225 PRE_MEM_READ( "msgctl(IPC_SET, arg.buf)",
4226 arg2
, sizeof(struct vki_msqid64_ds
) );
4231 ML_(linux_POST_sys_msgctl
) ( ThreadId tid
,
4233 UWord arg0
, UWord arg1
, UWord arg2
)
4235 switch (arg1
/* cmd */) {
4238 case VKI_IPC_INFO
|VKI_IPC_64
:
4239 case VKI_MSG_INFO
|VKI_IPC_64
:
4240 POST_MEM_WRITE( arg2
, sizeof(struct vki_msginfo
) );
4244 POST_MEM_WRITE( arg2
, sizeof(struct vki_msqid_ds
) );
4246 case VKI_IPC_STAT
|VKI_IPC_64
:
4247 case VKI_MSG_STAT
|VKI_IPC_64
:
4248 POST_MEM_WRITE( arg2
, sizeof(struct vki_msqid64_ds
) );
4253 /* ---------------------------------------------------------------------
4254 Generic handler for sys_ipc
4255 Depending on the platform, some syscalls (e.g. semctl, semop, ...)
4256 are either direct system calls, or are all implemented via sys_ipc.
4257 ------------------------------------------------------------------ */
4259 static Addr
deref_Addr ( ThreadId tid
, Addr a
, const HChar
* s
)
4261 Addr
* a_p
= (Addr
*)a
;
4262 PRE_MEM_READ( s
, (Addr
)a_p
, sizeof(Addr
) );
4266 static Bool
semctl_cmd_has_4args (UWord cmd
)
4268 switch (cmd
& ~VKI_IPC_64
)
4285 PRINT("sys_ipc ( %lu, %ld, %ld, %ld, %#lx, %ld )",
4286 ARG1
, SARG2
, SARG3
, SARG4
, ARG5
, SARG6
);
4288 switch (ARG1
/* call */) {
4290 PRE_REG_READ5(int, "ipc",
4291 vki_uint
, call
, int, first
, int, second
, int, third
,
4293 ML_(generic_PRE_sys_semop
)( tid
, ARG2
, ARG5
, ARG3
);
4294 *flags
|= SfMayBlock
;
4297 PRE_REG_READ4(int, "ipc",
4298 vki_uint
, call
, int, first
, int, second
, int, third
);
4302 PRE_REG_READ5(int, "ipc",
4303 vki_uint
, call
, int, first
, int, second
, int, third
,
4306 if (semctl_cmd_has_4args(ARG4
))
4307 arg
= deref_Addr( tid
, ARG5
, "semctl(arg)" );
4310 ML_(generic_PRE_sys_semctl
)( tid
, ARG2
, ARG3
, ARG4
, arg
);
4313 case VKI_SEMTIMEDOP
:
4314 PRE_REG_READ6(int, "ipc",
4315 vki_uint
, call
, int, first
, int, second
, int, third
,
4316 void *, ptr
, long, fifth
);
4317 ML_(generic_PRE_sys_semtimedop
)( tid
, ARG2
, ARG5
, ARG3
, ARG6
);
4318 *flags
|= SfMayBlock
;
4321 PRE_REG_READ5(int, "ipc",
4322 vki_uint
, call
, int, first
, int, second
, int, third
,
4324 ML_(linux_PRE_sys_msgsnd
)( tid
, ARG2
, ARG5
, ARG3
, ARG4
);
4325 if ((ARG4
& VKI_IPC_NOWAIT
) == 0)
4326 *flags
|= SfMayBlock
;
4330 PRE_REG_READ5(int, "ipc",
4331 vki_uint
, call
, int, first
, int, second
, int, third
,
4336 msgp
= deref_Addr( tid
, (Addr
) (&((struct vki_ipc_kludge
*)(Addr
)ARG5
)->msgp
),
4338 msgtyp
= deref_Addr( tid
,
4339 (Addr
) (&((struct vki_ipc_kludge
*)(Addr
)ARG5
)->msgtyp
),
4342 ML_(linux_PRE_sys_msgrcv
)( tid
, ARG2
, msgp
, ARG3
, msgtyp
, ARG4
);
4344 if ((ARG4
& VKI_IPC_NOWAIT
) == 0)
4345 *flags
|= SfMayBlock
;
4349 PRE_REG_READ3(int, "ipc", vki_uint
, call
, int, first
, int, second
);
4352 PRE_REG_READ5(int, "ipc",
4353 vki_uint
, call
, int, first
, int, second
, int, third
,
4355 ML_(linux_PRE_sys_msgctl
)( tid
, ARG2
, ARG3
, ARG5
);
4359 PRE_REG_READ5(int, "ipc",
4360 vki_uint
, call
, int, first
, int, second
, int, third
,
4363 PRE_MEM_WRITE( "shmat(raddr)", ARG4
, sizeof(Addr
) );
4364 w
= ML_(generic_PRE_sys_shmat
)( tid
, ARG2
, ARG5
, ARG3
);
4366 SET_STATUS_Failure( VKI_EINVAL
);
4372 PRE_REG_READ5(int, "ipc",
4373 vki_uint
, call
, int, first
, int, second
, int, third
,
4375 if (!ML_(generic_PRE_sys_shmdt
)(tid
, ARG5
))
4376 SET_STATUS_Failure( VKI_EINVAL
);
4379 PRE_REG_READ4(int, "ipc",
4380 vki_uint
, call
, int, first
, int, second
, int, third
);
4381 if (ARG4
& VKI_SHM_HUGETLB
) {
4382 static Bool warning_given
= False
;
4383 ARG4
&= ~VKI_SHM_HUGETLB
;
4384 if (!warning_given
) {
4385 warning_given
= True
;
4387 "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n");
4391 case VKI_SHMCTL
: /* IPCOP_shmctl */
4392 PRE_REG_READ5(int, "ipc",
4393 vki_uint
, call
, int, first
, int, second
, int, third
,
4395 ML_(generic_PRE_sys_shmctl
)( tid
, ARG2
, ARG3
, ARG5
);
4398 VG_(message
)(Vg_DebugMsg
, "FATAL: unhandled syscall(ipc) %lu\n", ARG1
);
4399 VG_(core_panic
)("... bye!\n");
4400 break; /*NOTREACHED*/
4407 switch (ARG1
/* call */) {
4414 if (semctl_cmd_has_4args(ARG4
))
4415 arg
= deref_Addr( tid
, ARG5
, "semctl(arg)" );
4418 ML_(generic_POST_sys_semctl
)( tid
, RES
, ARG2
, ARG3
, ARG4
, arg
);
4421 case VKI_SEMTIMEDOP
:
4429 msgp
= deref_Addr( tid
,
4430 (Addr
) (&((struct vki_ipc_kludge
*)(Addr
)ARG5
)->msgp
),
4432 msgtyp
= deref_Addr( tid
,
4433 (Addr
) (&((struct vki_ipc_kludge
*)(Addr
)ARG5
)->msgtyp
),
4436 ML_(linux_POST_sys_msgrcv
)( tid
, RES
, ARG2
, msgp
, ARG3
, msgtyp
, ARG4
);
4442 ML_(linux_POST_sys_msgctl
)( tid
, RES
, ARG2
, ARG3
, ARG5
);
4448 /* force readability. before the syscall it is
4449 * indeed uninitialized, as can be seen in
4450 * glibc/sysdeps/unix/sysv/linux/shmat.c */
4451 POST_MEM_WRITE( ARG4
, sizeof( Addr
) );
4453 addr
= deref_Addr ( tid
, ARG4
, "shmat(addr)" );
4454 ML_(generic_POST_sys_shmat
)( tid
, addr
, ARG2
, ARG5
, ARG3
);
4458 ML_(generic_POST_sys_shmdt
)( tid
, RES
, ARG5
);
4463 ML_(generic_POST_sys_shmctl
)( tid
, RES
, ARG2
, ARG3
, ARG5
);
4466 VG_(message
)(Vg_DebugMsg
,
4467 "FATAL: unhandled syscall(ipc) %lu\n",
4469 VG_(core_panic
)("... bye!\n");
4470 break; /*NOTREACHED*/
4477 PRINT("sys_semget ( %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
);
4478 PRE_REG_READ3(long, "semget", vki_key_t
, key
, int, nsems
, int, semflg
);
4483 *flags
|= SfMayBlock
;
4484 PRINT("sys_semop ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
4486 PRE_REG_READ3(long, "semop",
4487 int, semid
, struct sembuf
*, sops
, unsigned, nsoops
);
4488 ML_(generic_PRE_sys_semop
)(tid
, ARG1
,ARG2
,ARG3
);
4493 switch (ARG3
& ~VKI_IPC_64
) {
4496 PRINT("sys_semctl ( %ld, %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
,
4498 PRE_REG_READ4(long, "semctl",
4499 int, semid
, int, semnum
, int, cmd
, struct seminfo
*, arg
);
4504 PRINT("sys_semctl ( %ld, %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
,
4506 PRE_REG_READ4(long, "semctl",
4507 int, semid
, int, semnum
, int, cmd
, struct semid_ds
*, arg
);
4511 PRINT("sys_semctl ( %ld, %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
,
4513 PRE_REG_READ4(long, "semctl",
4514 int, semid
, int, semnum
, int, cmd
, unsigned short *, arg
);
4517 PRINT("sys_semctl ( %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
);
4518 PRE_REG_READ3(long, "semctl",
4519 int, semid
, int, semnum
, int, cmd
);
4522 #ifdef VGP_amd64_linux
4523 ML_(generic_PRE_sys_semctl
)(tid
, ARG1
,ARG2
,ARG3
|VKI_IPC_64
,ARG4
);
4525 ML_(generic_PRE_sys_semctl
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
);
4531 #ifdef VGP_amd64_linux
4532 ML_(generic_POST_sys_semctl
)(tid
, RES
,ARG1
,ARG2
,ARG3
|VKI_IPC_64
,ARG4
);
4534 ML_(generic_POST_sys_semctl
)(tid
, RES
,ARG1
,ARG2
,ARG3
,ARG4
);
4540 *flags
|= SfMayBlock
;
4541 PRINT("sys_semtimedop ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#"
4542 FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
, ARG4
);
4543 PRE_REG_READ4(long, "semtimedop",
4544 int, semid
, struct sembuf
*, sops
, unsigned, nsoops
,
4545 struct timespec
*, timeout
);
4546 ML_(generic_PRE_sys_semtimedop
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
);
4551 PRINT("sys_msgget ( %ld, %ld )", SARG1
, SARG2
);
4552 PRE_REG_READ2(long, "msgget", vki_key_t
, key
, int, msgflg
);
4557 PRINT("sys_msgsnd ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld )",
4558 SARG1
, ARG2
, ARG3
, SARG4
);
4559 PRE_REG_READ4(long, "msgsnd",
4560 int, msqid
, struct msgbuf
*, msgp
, vki_size_t
, msgsz
, int, msgflg
);
4561 ML_(linux_PRE_sys_msgsnd
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
);
4562 if ((ARG4
& VKI_IPC_NOWAIT
) == 0)
4563 *flags
|= SfMayBlock
;
4568 PRINT("sys_msgrcv ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld, %ld )",
4569 SARG1
, ARG2
, ARG3
, SARG4
, SARG5
);
4570 PRE_REG_READ5(long, "msgrcv",
4571 int, msqid
, struct msgbuf
*, msgp
, vki_size_t
, msgsz
,
4572 long, msgytp
, int, msgflg
);
4573 ML_(linux_PRE_sys_msgrcv
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
4574 if ((ARG5
& VKI_IPC_NOWAIT
) == 0)
4575 *flags
|= SfMayBlock
;
4579 ML_(linux_POST_sys_msgrcv
)(tid
, RES
,ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
4584 PRINT("sys_msgctl ( %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
, ARG3
);
4585 PRE_REG_READ3(long, "msgctl",
4586 int, msqid
, int, cmd
, struct msqid_ds
*, buf
);
4587 ML_(linux_PRE_sys_msgctl
)(tid
, ARG1
,ARG2
,ARG3
);
4592 ML_(linux_POST_sys_msgctl
)(tid
, RES
,ARG1
,ARG2
,ARG3
);
4597 PRINT("sys_shmget ( %ld, %" FMT_REGWORD
"u, %ld )", SARG1
, ARG2
, SARG3
);
4598 PRE_REG_READ3(long, "shmget", vki_key_t
, key
, vki_size_t
, size
, int, shmflg
);
4599 if (ARG3
& VKI_SHM_HUGETLB
) {
4600 static Bool warning_given
= False
;
4601 ARG3
&= ~VKI_SHM_HUGETLB
;
4602 if (!warning_given
) {
4603 warning_given
= True
;
4605 "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n");
4613 PRINT("sys_shmat ( %ld, %#" FMT_REGWORD
"x, %ld )", SARG1
, ARG2
, SARG3
);
4614 PRE_REG_READ3(long, "shmat",
4615 int, shmid
, const void *, shmaddr
, int, shmflg
);
4616 #if defined(VGP_arm_linux)
4617 /* Round the attach address down to an VKI_SHMLBA boundary if the
4618 client requested rounding. See #222545. This is necessary only
4619 on arm-linux because VKI_SHMLBA is 4 * VKI_PAGE size; on all
4620 other linux targets it is the same as the page size. */
4621 if (ARG3
& VKI_SHM_RND
)
4622 ARG2
= VG_ROUNDDN(ARG2
, VKI_SHMLBA
);
4624 arg2tmp
= ML_(generic_PRE_sys_shmat
)(tid
, ARG1
,ARG2
,ARG3
);
4626 SET_STATUS_Failure( VKI_EINVAL
);
4628 ARG2
= arg2tmp
; // used in POST
4633 ML_(generic_POST_sys_shmat
)(tid
, RES
,ARG1
,ARG2
,ARG3
);
4638 PRINT("sys_shmdt ( %#" FMT_REGWORD
"x )",ARG1
);
4639 PRE_REG_READ1(long, "shmdt", const void *, shmaddr
);
4640 if (!ML_(generic_PRE_sys_shmdt
)(tid
, ARG1
))
4641 SET_STATUS_Failure( VKI_EINVAL
);
4646 ML_(generic_POST_sys_shmdt
)(tid
, RES
,ARG1
);
4651 PRINT("sys_shmctl ( %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
, ARG3
);
4652 PRE_REG_READ3(long, "shmctl",
4653 int, shmid
, int, cmd
, struct shmid_ds
*, buf
);
4654 #ifdef VGP_amd64_linux
4655 ML_(generic_PRE_sys_shmctl
)(tid
, ARG1
,ARG2
|VKI_IPC_64
,ARG3
);
4657 ML_(generic_PRE_sys_shmctl
)(tid
, ARG1
,ARG2
,ARG3
);
4663 #ifdef VGP_amd64_linux
4664 ML_(generic_POST_sys_shmctl
)(tid
, RES
,ARG1
,ARG2
|VKI_IPC_64
,ARG3
);
4666 ML_(generic_POST_sys_shmctl
)(tid
, RES
,ARG1
,ARG2
,ARG3
);
4671 /* ---------------------------------------------------------------------
4672 Generic handler for sys_socketcall
4673 Depending on the platform, some socket related syscalls (e.g. socketpair,
4675 are either direct system calls, or are all implemented via sys_socketcall.
4676 ------------------------------------------------------------------ */
4677 #ifdef __NR_socketcall
4680 # define ARG2_0 (((UWord*)(Addr)ARG2)[0])
4681 # define ARG2_1 (((UWord*)(Addr)ARG2)[1])
4682 # define ARG2_2 (((UWord*)(Addr)ARG2)[2])
4683 # define ARG2_3 (((UWord*)(Addr)ARG2)[3])
4684 # define ARG2_4 (((UWord*)(Addr)ARG2)[4])
4685 # define ARG2_5 (((UWord*)(Addr)ARG2)[5])
4687 // call PRE_MEM_READ and check for EFAULT result.
4688 #define PRE_MEM_READ_ef(msg, arg, size) \
4690 PRE_MEM_READ( msg, arg, size); \
4691 if (!ML_(valid_client_addr)(arg, size, tid, NULL)) { \
4692 SET_STATUS_Failure( VKI_EFAULT ); \
4697 *flags
|= SfMayBlock
;
4698 PRINT("sys_socketcall ( %ld, %#lx )", SARG1
, ARG2
);
4699 PRE_REG_READ2(long, "socketcall", int, call
, unsigned long *, args
);
4701 switch (ARG1
/* request */) {
4703 case VKI_SYS_SOCKETPAIR
:
4704 /* int socketpair(int d, int type, int protocol, int sv[2]); */
4705 PRE_MEM_READ_ef( "socketcall.socketpair(args)", ARG2
, 4*sizeof(Addr
) );
4706 ML_(generic_PRE_sys_socketpair
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
);
4709 case VKI_SYS_SOCKET
:
4710 /* int socket(int domain, int type, int protocol); */
4711 PRE_MEM_READ_ef( "socketcall.socket(args)", ARG2
, 3*sizeof(Addr
) );
4715 /* int bind(int sockfd, struct sockaddr *my_addr,
4717 PRE_MEM_READ_ef( "socketcall.bind(args)", ARG2
, 3*sizeof(Addr
) );
4718 ML_(generic_PRE_sys_bind
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
4721 case VKI_SYS_LISTEN
:
4722 /* int listen(int s, int backlog); */
4723 PRE_MEM_READ_ef( "socketcall.listen(args)", ARG2
, 2*sizeof(Addr
) );
4726 case VKI_SYS_ACCEPT
:
4727 /* int accept(int s, struct sockaddr *addr, int *addrlen); */
4728 PRE_MEM_READ_ef( "socketcall.accept(args)", ARG2
, 3*sizeof(Addr
) );
4729 ML_(generic_PRE_sys_accept
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
4732 case VKI_SYS_ACCEPT4
:
4733 /* int accept4(int s, struct sockaddr *addr, int *addrlen, int flags); */
4734 PRE_MEM_READ_ef( "socketcall.accept4(args)", ARG2
, 4*sizeof(Addr
) );
4735 ML_(generic_PRE_sys_accept
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
4738 case VKI_SYS_SENDTO
:
4739 /* int sendto(int s, const void *msg, int len,
4741 const struct sockaddr *to, int tolen); */
4742 PRE_MEM_READ_ef( "socketcall.sendto(args)", ARG2
, 6*sizeof(Addr
) );
4743 ML_(generic_PRE_sys_sendto
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
,
4744 ARG2_3
, ARG2_4
, ARG2_5
);
4748 /* int send(int s, const void *msg, size_t len, int flags); */
4749 PRE_MEM_READ_ef( "socketcall.send(args)", ARG2
, 4*sizeof(Addr
) );
4750 ML_(generic_PRE_sys_send
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
4753 case VKI_SYS_RECVFROM
:
4754 /* int recvfrom(int s, void *buf, int len, unsigned int flags,
4755 struct sockaddr *from, int *fromlen); */
4756 PRE_MEM_READ_ef( "socketcall.recvfrom(args)", ARG2
, 6*sizeof(Addr
) );
4757 ML_(generic_PRE_sys_recvfrom
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
,
4758 ARG2_3
, ARG2_4
, ARG2_5
);
4762 /* int recv(int s, void *buf, int len, unsigned int flags); */
4764 The recv call is normally used only on a connected socket
4765 (see connect(2)) and is identical to recvfrom with a NULL
4768 PRE_MEM_READ_ef( "socketcall.recv(args)", ARG2
, 4*sizeof(Addr
) );
4769 ML_(generic_PRE_sys_recv
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
4772 case VKI_SYS_CONNECT
:
4773 /* int connect(int sockfd,
4774 struct sockaddr *serv_addr, int addrlen ); */
4775 PRE_MEM_READ_ef( "socketcall.connect(args)", ARG2
, 3*sizeof(Addr
) );
4776 ML_(generic_PRE_sys_connect
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
4779 case VKI_SYS_SETSOCKOPT
:
4780 /* int setsockopt(int s, int level, int optname,
4781 const void *optval, int optlen); */
4782 PRE_MEM_READ_ef( "socketcall.setsockopt(args)", ARG2
, 5*sizeof(Addr
) );
4783 ML_(linux_PRE_sys_setsockopt
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
,
4787 case VKI_SYS_GETSOCKOPT
:
4788 /* int getsockopt(int s, int level, int optname,
4789 void *optval, socklen_t *optlen); */
4790 PRE_MEM_READ_ef( "socketcall.getsockopt(args)", ARG2
, 5*sizeof(Addr
) );
4791 ML_(linux_PRE_sys_getsockopt
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
,
4795 case VKI_SYS_GETSOCKNAME
:
4796 /* int getsockname(int s, struct sockaddr* name, int* namelen) */
4797 PRE_MEM_READ_ef( "socketcall.getsockname(args)", ARG2
, 3*sizeof(Addr
) );
4798 ML_(generic_PRE_sys_getsockname
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
4801 case VKI_SYS_GETPEERNAME
:
4802 /* int getpeername(int s, struct sockaddr* name, int* namelen) */
4803 PRE_MEM_READ_ef( "socketcall.getpeername(args)", ARG2
, 3*sizeof(Addr
) );
4804 ML_(generic_PRE_sys_getpeername
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
);
4807 case VKI_SYS_SHUTDOWN
:
4808 /* int shutdown(int s, int how); */
4809 PRE_MEM_READ_ef( "socketcall.shutdown(args)", ARG2
, 2*sizeof(Addr
) );
4812 case VKI_SYS_SENDMSG
:
4813 /* int sendmsg(int s, const struct msghdr *msg, int flags); */
4814 PRE_MEM_READ_ef( "socketcall.sendmsg(args)", ARG2
, 3*sizeof(Addr
) );
4815 ML_(generic_PRE_sys_sendmsg
)( tid
, "msg",
4816 (struct vki_msghdr
*)(Addr
)ARG2_1
);
4819 case VKI_SYS_RECVMSG
:
4820 /* int recvmsg(int s, struct msghdr *msg, int flags); */
4821 PRE_MEM_READ_ef("socketcall.recvmsg(args)", ARG2
, 3*sizeof(Addr
) );
4822 ML_(generic_PRE_sys_recvmsg
)( tid
, "msg",
4823 (struct vki_msghdr
*)(Addr
)ARG2_1
);
4826 case VKI_SYS_RECVMMSG
:
4827 /* int recvmmsg(int s, struct mmsghdr *mmsg, int vlen, int flags,
4828 struct timespec *timeout); */
4829 PRE_MEM_READ_ef("socketcall.recvmmsg(args)", ARG2
, 5*sizeof(Addr
) );
4830 ML_(linux_PRE_sys_recvmmsg
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
,
4834 case VKI_SYS_SENDMMSG
:
4835 /* int sendmmsg(int s, struct mmsghdr *mmsg, int vlen, int flags); */
4836 PRE_MEM_READ_ef("socketcall.sendmmsg(args)", ARG2
, 4*sizeof(Addr
) );
4837 ML_(linux_PRE_sys_sendmmsg
)( tid
, ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
);
4841 VG_(message
)(Vg_DebugMsg
,"Warning: unhandled socketcall 0x%lx\n",ARG1
);
4842 SET_STATUS_Failure( VKI_EINVAL
);
4853 POST(sys_socketcall
)
4855 # define ARG2_0 (((UWord*)(Addr)ARG2)[0])
4856 # define ARG2_1 (((UWord*)(Addr)ARG2)[1])
4857 # define ARG2_2 (((UWord*)(Addr)ARG2)[2])
4858 # define ARG2_3 (((UWord*)(Addr)ARG2)[3])
4859 # define ARG2_4 (((UWord*)(Addr)ARG2)[4])
4860 # define ARG2_5 (((UWord*)(Addr)ARG2)[5])
4864 switch (ARG1
/* request */) {
4866 case VKI_SYS_SOCKETPAIR
:
4867 r
= ML_(generic_POST_sys_socketpair
)(
4868 tid
, VG_(mk_SysRes_Success
)(RES
),
4869 ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
4871 SET_STATUS_from_SysRes(r
);
4874 case VKI_SYS_SOCKET
:
4875 r
= ML_(generic_POST_sys_socket
)( tid
, VG_(mk_SysRes_Success
)(RES
) );
4876 SET_STATUS_from_SysRes(r
);
4880 /* int bind(int sockfd, struct sockaddr *my_addr,
4884 case VKI_SYS_LISTEN
:
4885 /* int listen(int s, int backlog); */
4888 case VKI_SYS_ACCEPT
:
4889 case VKI_SYS_ACCEPT4
:
4890 /* int accept(int s, struct sockaddr *addr, int *addrlen); */
4891 /* int accept4(int s, struct sockaddr *addr, int *addrlen, int flags); */
4892 r
= ML_(generic_POST_sys_accept
)( tid
, VG_(mk_SysRes_Success
)(RES
),
4893 ARG2_0
, ARG2_1
, ARG2_2
);
4894 SET_STATUS_from_SysRes(r
);
4897 case VKI_SYS_SENDTO
:
4903 case VKI_SYS_RECVFROM
:
4904 ML_(generic_POST_sys_recvfrom
)( tid
, VG_(mk_SysRes_Success
)(RES
),
4905 ARG2_0
, ARG2_1
, ARG2_2
,
4906 ARG2_3
, ARG2_4
, ARG2_5
);
4910 ML_(generic_POST_sys_recv
)( tid
, RES
, ARG2_0
, ARG2_1
, ARG2_2
);
4913 case VKI_SYS_CONNECT
:
4916 case VKI_SYS_SETSOCKOPT
:
4919 case VKI_SYS_GETSOCKOPT
:
4920 ML_(linux_POST_sys_getsockopt
)( tid
, VG_(mk_SysRes_Success
)(RES
),
4922 ARG2_2
, ARG2_3
, ARG2_4
);
4925 case VKI_SYS_GETSOCKNAME
:
4926 ML_(generic_POST_sys_getsockname
)( tid
, VG_(mk_SysRes_Success
)(RES
),
4927 ARG2_0
, ARG2_1
, ARG2_2
);
4930 case VKI_SYS_GETPEERNAME
:
4931 ML_(generic_POST_sys_getpeername
)( tid
, VG_(mk_SysRes_Success
)(RES
),
4932 ARG2_0
, ARG2_1
, ARG2_2
);
4935 case VKI_SYS_SHUTDOWN
:
4938 case VKI_SYS_SENDMSG
:
4941 case VKI_SYS_RECVMSG
:
4942 ML_(generic_POST_sys_recvmsg
)( tid
, "msg",
4943 (struct vki_msghdr
*)(Addr
)ARG2_1
, RES
);
4946 case VKI_SYS_RECVMMSG
:
4947 ML_(linux_POST_sys_recvmmsg
)( tid
, RES
,
4948 ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
, ARG2_4
);
4951 case VKI_SYS_SENDMMSG
:
4952 ML_(linux_POST_sys_sendmmsg
)( tid
, RES
, ARG2_0
, ARG2_1
, ARG2_2
, ARG2_3
);
4956 VG_(message
)(Vg_DebugMsg
,"FATAL: unhandled socketcall 0x%lx\n",ARG1
);
4957 VG_(core_panic
)("... bye!\n");
4958 break; /*NOTREACHED*/
4971 PRINT("sys_socket ( %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
);
4972 PRE_REG_READ3(long, "socket", int, domain
, int, type
, int, protocol
);
4978 r
= ML_(generic_POST_sys_socket
)(tid
, VG_(mk_SysRes_Success
)(RES
));
4979 SET_STATUS_from_SysRes(r
);
4984 PRINT("sys_setsockopt ( %ld, %ld, %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
4985 "u )", SARG1
, SARG2
, SARG3
, ARG4
, ARG5
);
4986 PRE_REG_READ5(long, "setsockopt",
4987 int, s
, int, level
, int, optname
,
4988 const void *, optval
, unsigned, optlen
); // socklen_t
4989 ML_(linux_PRE_sys_setsockopt
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
4994 PRINT("sys_getsockopt ( %ld, %ld, %ld, %#" FMT_REGWORD
"x, %ld )",
4995 SARG1
, SARG2
, SARG3
, ARG4
, SARG5
);
4996 PRE_REG_READ5(long, "getsockopt",
4997 int, s
, int, level
, int, optname
,
4998 void *, optval
, int, *optlen
);
4999 ML_(linux_PRE_sys_getsockopt
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
5001 POST(sys_getsockopt
)
5004 ML_(linux_POST_sys_getsockopt
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5005 ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
5010 *flags
|= SfMayBlock
;
5011 PRINT("sys_connect ( %ld, %#" FMT_REGWORD
"x, %ld )", SARG1
, ARG2
, SARG3
);
5012 PRE_REG_READ3(long, "connect",
5013 int, sockfd
, struct sockaddr
*, serv_addr
, int, addrlen
);
5014 ML_(generic_PRE_sys_connect
)(tid
, ARG1
,ARG2
,ARG3
);
5019 *flags
|= SfMayBlock
;
5020 PRINT("sys_accept ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
5022 PRE_REG_READ3(long, "accept",
5023 int, s
, struct sockaddr
*, addr
, int *, addrlen
);
5024 ML_(generic_PRE_sys_accept
)(tid
, ARG1
,ARG2
,ARG3
);
5030 r
= ML_(generic_POST_sys_accept
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5032 SET_STATUS_from_SysRes(r
);
5037 *flags
|= SfMayBlock
;
5038 PRINT("sys_accept4 ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %ld )",
5039 SARG1
, ARG2
, ARG3
, SARG4
);
5040 PRE_REG_READ4(long, "accept4",
5041 int, s
, struct sockaddr
*, addr
, int *, addrlen
, int, flags
);
5042 ML_(generic_PRE_sys_accept
)(tid
, ARG1
,ARG2
,ARG3
);
5048 r
= ML_(generic_POST_sys_accept
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5050 SET_STATUS_from_SysRes(r
);
5055 *flags
|= SfMayBlock
;
5056 PRINT("sys_send ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#"
5057 FMT_REGWORD
"x )", SARG1
, ARG2
, ARG3
, ARG4
);
5058 PRE_REG_READ4(long, "send",
5059 int, s
, const void *, msg
, vki_size_t
, len
,
5062 ML_(generic_PRE_sys_send
)( tid
, ARG1
, ARG2
, ARG3
);
5067 *flags
|= SfMayBlock
;
5068 PRINT("sys_sendto ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
5069 FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %ld )",
5070 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, SARG6
);
5071 PRE_REG_READ6(long, "sendto",
5072 int, s
, const void *, msg
, vki_size_t
, len
,
5073 unsigned int, flags
,
5074 const struct sockaddr
*, to
, int, tolen
);
5075 ML_(generic_PRE_sys_sendto
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
,ARG6
);
5080 *flags
|= SfMayBlock
;
5081 PRINT ("sys_recv ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
5082 FMT_REGWORD
"u )", SARG1
, ARG2
, ARG3
, ARG4
);
5083 PRE_REG_READ4 (long, "recv", int, s
, void *, buf
, vki_size_t
, len
,
5084 unsigned int, flags
);
5085 ML_ (generic_PRE_sys_recv
) (tid
, ARG1
, ARG2
, ARG3
);
5090 ML_ (generic_POST_sys_recv
) (tid
, RES
, ARG1
, ARG2
, ARG3
);
5095 *flags
|= SfMayBlock
;
5096 PRINT("sys_recvfrom ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
5097 FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
5098 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
5099 PRE_REG_READ6(long, "recvfrom",
5100 int, s
, void *, buf
, vki_size_t
, len
, unsigned int, flags
,
5101 struct sockaddr
*, from
, int *, fromlen
);
5102 ML_(generic_PRE_sys_recvfrom
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
,ARG6
);
5107 ML_(generic_POST_sys_recvfrom
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5108 ARG1
,ARG2
,ARG3
,ARG4
,ARG5
,ARG6
);
5113 *flags
|= SfMayBlock
;
5114 PRINT("sys_sendmsg ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
5116 PRE_REG_READ3(long, "sendmsg",
5117 int, s
, const struct msghdr
*, msg
, unsigned int, flags
);
5118 ML_(generic_PRE_sys_sendmsg
)(tid
, "msg", (struct vki_msghdr
*)(Addr
)ARG2
);
5123 *flags
|= SfMayBlock
;
5124 PRINT("sys_recvmsg ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
5126 PRE_REG_READ3(long, "recvmsg", int, s
, struct msghdr
*, msg
,
5127 unsigned int, flags
);
5128 ML_(generic_PRE_sys_recvmsg
)(tid
, "msg", (struct vki_msghdr
*)(Addr
)ARG2
);
5132 ML_(generic_POST_sys_recvmsg
)(tid
, "msg", (struct vki_msghdr
*)(Addr
)ARG2
,
5138 *flags
|= SfMayBlock
;
5139 PRINT("sys_shutdown ( %ld, %ld )", SARG1
, SARG2
);
5140 PRE_REG_READ2(int, "shutdown", int, s
, int, how
);
5145 PRINT("sys_bind ( %ld, %#" FMT_REGWORD
"x, %ld )", SARG1
, ARG2
, SARG3
);
5146 PRE_REG_READ3(long, "bind",
5147 int, sockfd
, struct sockaddr
*, my_addr
, int, addrlen
);
5148 ML_(generic_PRE_sys_bind
)(tid
, ARG1
,ARG2
,ARG3
);
5153 PRINT("sys_listen ( %ld, %ld )", SARG1
, SARG2
);
5154 PRE_REG_READ2(long, "listen", int, s
, int, backlog
);
5157 PRE(sys_getsockname
)
5159 PRINT("sys_getsockname ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
5161 PRE_REG_READ3(long, "getsockname",
5162 int, s
, struct sockaddr
*, name
, int *, namelen
);
5163 ML_(generic_PRE_sys_getsockname
)(tid
, ARG1
,ARG2
,ARG3
);
5165 POST(sys_getsockname
)
5168 ML_(generic_POST_sys_getsockname
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5172 PRE(sys_getpeername
)
5174 PRINT("sys_getpeername ( %ld, %#" FMT_REGWORD
"x, %#" FMT_REGWORD
"x )",
5176 PRE_REG_READ3(long, "getpeername",
5177 int, s
, struct sockaddr
*, name
, int *, namelen
);
5178 ML_(generic_PRE_sys_getpeername
)(tid
, ARG1
,ARG2
,ARG3
);
5180 POST(sys_getpeername
)
5183 ML_(generic_POST_sys_getpeername
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5189 PRINT("sys_socketpair ( %ld, %ld, %ld, %#" FMT_REGWORD
"x )", SARG1
, SARG2
,
5191 PRE_REG_READ4(long, "socketpair",
5192 int, d
, int, type
, int, protocol
, int*, sv
);
5193 ML_(generic_PRE_sys_socketpair
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
);
5195 POST(sys_socketpair
)
5198 ML_(generic_POST_sys_socketpair
)(tid
, VG_(mk_SysRes_Success
)(RES
),
5199 ARG1
,ARG2
,ARG3
,ARG4
);
5203 /* ---------------------------------------------------------------------
5205 ------------------------------------------------------------------ */
5209 HChar name
[30]; // large enough
5212 if (ARG3
& VKI_O_CREAT
) {
5214 PRINT("sys_openat ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %ld )",
5215 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
, SARG4
);
5216 PRE_REG_READ4(long, "openat",
5217 int, dfd
, const char *, filename
, int, flags
, int, mode
);
5220 PRINT("sys_openat ( %ld, %#" FMT_REGWORD
"x(%s), %ld )",
5221 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
);
5222 PRE_REG_READ3(long, "openat",
5223 int, dfd
, const char *, filename
, int, flags
);
5226 PRE_MEM_RASCIIZ( "openat(filename)", ARG2
);
5228 /* For absolute filenames, dfd is ignored. If dfd is AT_FDCWD,
5229 filename is relative to cwd. When comparing dfd against AT_FDCWD,
5230 be sure only to compare the bottom 32 bits. */
5231 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG2
, 1 )
5232 && *(Char
*)(Addr
)ARG2
!= '/'
5233 && ((Int
)ARG1
) != ((Int
)VKI_AT_FDCWD
)
5234 && !ML_(fd_allowed
)(ARG1
, "openat", tid
, False
))
5235 SET_STATUS_Failure( VKI_EBADF
);
5237 /* Handle the case where the open is of /proc/self/cmdline or
5238 /proc/<pid>/cmdline, and just give it a copy of the fd for the
5239 fake file we cooked up at startup (in m_main). Also, seek the
5240 cloned fd back to the start. */
5242 VG_(sprintf
)(name
, "/proc/%d/cmdline", VG_(getpid
)());
5243 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG2
, 1 )
5244 && (VG_(strcmp
)((HChar
*)(Addr
)ARG2
, name
) == 0
5245 || VG_(strcmp
)((HChar
*)(Addr
)ARG2
, "/proc/self/cmdline") == 0)) {
5246 sres
= VG_(dup
)( VG_(cl_cmdline_fd
) );
5247 SET_STATUS_from_SysRes( sres
);
5248 if (!sr_isError(sres
)) {
5249 OffT off
= VG_(lseek
)( sr_Res(sres
), 0, VKI_SEEK_SET
);
5251 SET_STATUS_Failure( VKI_EMFILE
);
5256 /* Do the same for /proc/self/auxv or /proc/<pid>/auxv case. */
5258 VG_(sprintf
)(name
, "/proc/%d/auxv", VG_(getpid
)());
5259 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG2
, 1 )
5260 && (VG_(strcmp
)((HChar
*)(Addr
)ARG2
, name
) == 0
5261 || VG_(strcmp
)((HChar
*)(Addr
)ARG2
, "/proc/self/auxv") == 0)) {
5262 sres
= VG_(dup
)( VG_(cl_auxv_fd
) );
5263 SET_STATUS_from_SysRes( sres
);
5264 if (!sr_isError(sres
)) {
5265 OffT off
= VG_(lseek
)( sr_Res(sres
), 0, VKI_SEEK_SET
);
5267 SET_STATUS_Failure( VKI_EMFILE
);
5272 /* Otherwise handle normally */
5273 *flags
|= SfMayBlock
;
5279 if (!ML_(fd_allowed
)(RES
, "openat", tid
, True
)) {
5281 SET_STATUS_Failure( VKI_EMFILE
);
5283 if (VG_(clo_track_fds
))
5284 ML_(record_fd_open_with_given_name
)(tid
, RES
, (HChar
*)(Addr
)ARG2
);
5290 *flags
|= SfMayBlock
;
5291 PRINT("sys_mkdirat ( %ld, %#" FMT_REGWORD
"x(%s), %ld )",
5292 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
);
5293 PRE_REG_READ3(long, "mkdirat",
5294 int, dfd
, const char *, pathname
, int, mode
);
5295 PRE_MEM_RASCIIZ( "mkdirat(pathname)", ARG2
);
5300 PRINT("sys_mknodat ( %ld, %#" FMT_REGWORD
"x(%s), 0x%" FMT_REGWORD
"x, 0x%"
5301 FMT_REGWORD
"x )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
);
5302 PRE_REG_READ4(long, "mknodat",
5303 int, dfd
, const char *, pathname
, int, mode
, unsigned, dev
);
5304 PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2
);
5309 PRINT("sys_fchownat ( %ld, %#" FMT_REGWORD
"x(%s), 0x%" FMT_REGWORD
"x, 0x%"
5310 FMT_REGWORD
"x )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
);
5311 PRE_REG_READ4(long, "fchownat",
5312 int, dfd
, const char *, path
,
5313 vki_uid_t
, owner
, vki_gid_t
, group
);
5314 PRE_MEM_RASCIIZ( "fchownat(path)", ARG2
);
5319 PRINT("sys_futimesat ( %ld, %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x )",
5320 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
);
5321 PRE_REG_READ3(long, "futimesat",
5322 int, dfd
, char *, filename
, struct timeval
*, tvp
);
5324 PRE_MEM_RASCIIZ( "futimesat(filename)", ARG2
);
5326 PRE_MEM_READ( "futimesat(tvp)", ARG3
, 2 * sizeof(struct vki_timeval
) );
5331 PRINT("sys_utimensat ( %ld, %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x, 0x%"
5332 FMT_REGWORD
"x )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
);
5333 PRE_REG_READ4(long, "utimensat",
5334 int, dfd
, char *, filename
, struct timespec
*, utimes
, int, flags
);
5336 PRE_MEM_RASCIIZ( "utimensat(filename)", ARG2
);
5338 /* If timespec.tv_nsec has the special value UTIME_NOW or UTIME_OMIT
5339 then the tv_sec field is ignored. */
5340 struct vki_timespec
*times
= (struct vki_timespec
*)(Addr
)ARG3
;
5341 PRE_MEM_READ( "utimensat(times[0].tv_nsec)",
5342 (Addr
)×
[0].tv_nsec
, sizeof(times
[0].tv_nsec
));
5343 PRE_MEM_READ( "utimensat(times[1].tv_nsec)",
5344 (Addr
)×
[1].tv_nsec
, sizeof(times
[1].tv_nsec
));
5345 if (ML_(safe_to_deref
)(times
, 2 * sizeof(struct vki_timespec
))) {
5346 if (times
[0].tv_nsec
!= VKI_UTIME_NOW
5347 && times
[0].tv_nsec
!= VKI_UTIME_OMIT
)
5348 PRE_MEM_READ( "utimensat(times[0].tv_sec)",
5349 (Addr
)×
[0].tv_sec
, sizeof(times
[0].tv_sec
));
5350 if (times
[1].tv_nsec
!= VKI_UTIME_NOW
5351 && times
[1].tv_nsec
!= VKI_UTIME_OMIT
)
5352 PRE_MEM_READ( "utimensat(times[1].tv_sec)",
5353 (Addr
)×
[1].tv_sec
, sizeof(times
[1].tv_sec
));
5358 #if !defined(VGP_nanomips_linux)
5361 FUSE_COMPATIBLE_MAY_BLOCK();
5362 PRINT("sys_newfstatat ( %ld, %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x )",
5363 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
);
5364 PRE_REG_READ3(long, "fstatat",
5365 int, dfd
, char *, file_name
, struct stat
*, buf
);
5366 PRE_MEM_RASCIIZ( "fstatat(file_name)", ARG2
);
5367 PRE_MEM_WRITE( "fstatat(buf)", ARG3
, sizeof(struct vki_stat
) );
5370 POST(sys_newfstatat
)
5372 POST_MEM_WRITE( ARG3
, sizeof(struct vki_stat
) );
5378 *flags
|= SfMayBlock
;
5379 PRINT("sys_unlinkat ( %ld, %#" FMT_REGWORD
"x(%s) )", SARG1
, ARG2
,
5380 (HChar
*)(Addr
)ARG2
);
5381 PRE_REG_READ2(long, "unlinkat", int, dfd
, const char *, pathname
);
5382 PRE_MEM_RASCIIZ( "unlinkat(pathname)", ARG2
);
5387 PRINT("sys_renameat ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %#"
5388 FMT_REGWORD
"x(%s) )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
,
5389 ARG4
, (HChar
*)(Addr
)ARG4
);
5390 PRE_REG_READ4(long, "renameat",
5391 int, olddfd
, const char *, oldpath
,
5392 int, newdfd
, const char *, newpath
);
5393 PRE_MEM_RASCIIZ( "renameat(oldpath)", ARG2
);
5394 PRE_MEM_RASCIIZ( "renameat(newpath)", ARG4
);
5399 PRINT("sys_renameat2 ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %#" FMT_REGWORD
5400 "x(%s), %" FMT_REGWORD
"u )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
,
5401 ARG4
, (HChar
*)(Addr
)ARG4
, ARG5
);
5402 PRE_REG_READ5(long, "renameat2",
5403 int, olddfd
, const char *, oldpath
,
5404 int, newdfd
, const char *, newpath
,
5405 unsigned int, flags
);
5406 PRE_MEM_RASCIIZ( "renameat2(oldpath)", ARG2
);
5407 PRE_MEM_RASCIIZ( "renameat2(newpath)", ARG4
);
5412 *flags
|= SfMayBlock
;
5413 PRINT("sys_linkat ( %ld, %#" FMT_REGWORD
"x(%s), %ld, %#" FMT_REGWORD
5414 "x(%s), %ld )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
, ARG4
,
5415 (HChar
*)(Addr
)ARG4
, SARG5
);
5416 PRE_REG_READ5(long, "linkat",
5417 int, olddfd
, const char *, oldpath
,
5418 int, newdfd
, const char *, newpath
,
5420 PRE_MEM_RASCIIZ( "linkat(oldpath)", ARG2
);
5421 PRE_MEM_RASCIIZ( "linkat(newpath)", ARG4
);
5426 *flags
|= SfMayBlock
;
5427 PRINT("sys_symlinkat ( %#" FMT_REGWORD
"x(%s), %ld, %#" FMT_REGWORD
5428 "x(%s) )", ARG1
, (HChar
*)(Addr
)ARG1
, SARG2
, ARG3
, (HChar
*)(Addr
)ARG3
);
5429 PRE_REG_READ3(long, "symlinkat",
5430 const char *, oldpath
, int, newdfd
, const char *, newpath
);
5431 PRE_MEM_RASCIIZ( "symlinkat(oldpath)", ARG1
);
5432 PRE_MEM_RASCIIZ( "symlinkat(newpath)", ARG3
);
5437 HChar name
[30]; // large enough
5440 PRINT("sys_readlinkat ( %ld, %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x, %"
5441 FMT_REGWORD
"u )", SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
);
5442 PRE_REG_READ4(long, "readlinkat",
5443 int, dfd
, const char *, path
, char *, buf
, vki_size_t
, bufsiz
);
5444 PRE_MEM_RASCIIZ( "readlinkat(path)", ARG2
);
5445 PRE_MEM_WRITE( "readlinkat(buf)", ARG3
,ARG4
);
5448 * Handle the case where readlinkat is looking at /proc/self/exe or
5451 VG_(sprintf
)(name
, "/proc/%d/exe", VG_(getpid
)());
5452 if (ML_(safe_to_deref
)((void*)(Addr
)ARG2
, 1)
5453 && (VG_(strcmp
)((HChar
*)(Addr
)ARG2
, name
) == 0
5454 || VG_(strcmp
)((HChar
*)(Addr
)ARG2
, "/proc/self/exe") == 0)) {
5455 VG_(sprintf
)(name
, "/proc/self/fd/%d", VG_(cl_exec_fd
));
5456 SET_STATUS_from_SysRes( VG_(do_syscall4
)(saved
, ARG1
, (UWord
)name
,
5460 SET_STATUS_from_SysRes( VG_(do_syscall4
)(saved
, ARG1
, ARG2
, ARG3
, ARG4
));
5463 if (SUCCESS
&& RES
> 0)
5464 POST_MEM_WRITE( ARG3
, RES
);
5469 PRINT("sys_fchmodat ( %ld, %#" FMT_REGWORD
"x(%s), %" FMT_REGWORD
"u )",
5470 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
);
5471 PRE_REG_READ3(long, "fchmodat",
5472 int, dfd
, const char *, path
, vki_mode_t
, mode
);
5473 PRE_MEM_RASCIIZ( "fchmodat(path)", ARG2
);
5478 PRINT("sys_faccessat ( %ld, %#" FMT_REGWORD
"x(%s), %ld )",
5479 SARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, SARG3
);
5480 PRE_REG_READ3(long, "faccessat",
5481 int, dfd
, const char *, pathname
, int, mode
);
5482 PRE_MEM_RASCIIZ( "faccessat(pathname)", ARG2
);
5485 PRE(sys_name_to_handle_at
)
5487 PRINT("sys_name_to_handle_at ( %ld, %#" FMT_REGWORD
"x(%s), %#"
5488 FMT_REGWORD
"x, %#" FMT_REGWORD
"x, %ld )", SARG1
, ARG2
,
5489 (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
, SARG5
);
5490 PRE_REG_READ5(int, "name_to_handle_at",
5491 int, dfd
, const char *, name
,
5492 struct vki_file_handle
*, handle
,
5493 int *, mnt_id
, int, flag
);
5494 PRE_MEM_RASCIIZ( "name_to_handle_at(name)", ARG2
);
5495 if (ML_(safe_to_deref
)( (void*)(Addr
)ARG3
, sizeof(struct vki_file_handle
))) {
5496 struct vki_file_handle
*fh
= (struct vki_file_handle
*)(Addr
)ARG3
;
5497 PRE_MEM_READ( "name_to_handle_at(handle)", (Addr
)&fh
->handle_bytes
, sizeof(fh
->handle_bytes
) );
5498 PRE_MEM_WRITE( "name_to_handle_at(handle)", (Addr
)fh
, sizeof(struct vki_file_handle
) + fh
->handle_bytes
);
5500 PRE_MEM_WRITE( "name_to_handle_at(mnt_id)", ARG4
, sizeof(int) );
5503 POST(sys_name_to_handle_at
)
5505 struct vki_file_handle
*fh
= (struct vki_file_handle
*)(Addr
)ARG3
;
5506 POST_MEM_WRITE( ARG3
, sizeof(struct vki_file_handle
) + fh
->handle_bytes
);
5507 POST_MEM_WRITE( ARG4
, sizeof(int) );
5510 PRE(sys_open_by_handle_at
)
5512 *flags
|= SfMayBlock
;
5513 PRINT("sys_open_by_handle_at ( %ld, %#" FMT_REGWORD
"x, %ld )", SARG1
,
5515 PRE_REG_READ3(int, "open_by_handle_at",
5517 struct vki_file_handle
*, handle
,
5519 PRE_MEM_READ( "open_by_handle_at(handle)", ARG2
,
5520 sizeof(struct vki_file_handle
) +
5521 ((struct vki_file_handle
*)(Addr
)ARG2
)->handle_bytes
);
5524 POST(sys_open_by_handle_at
)
5527 if (!ML_(fd_allowed
)(RES
, "open_by_handle_at", tid
, True
)) {
5529 SET_STATUS_Failure( VKI_EMFILE
);
5531 if (VG_(clo_track_fds
))
5532 ML_(record_fd_open_with_given_name
)(tid
, RES
, (HChar
*)(Addr
)ARG2
);
5536 /* ---------------------------------------------------------------------
5537 p{read,write}v wrappers
5538 ------------------------------------------------------------------ */
5539 /* This handles the common part of the PRE macro for preadv and preadv2. */
5540 void handle_pre_sys_preadv(ThreadId tid
, SyscallStatus
* status
,
5541 Int fd
, Addr vector
, Int count
, const char *str
)
5543 struct vki_iovec
* vec
;
5545 /* safe size for the "preadv/preadv2(vector[i])" string */
5548 if (!ML_(fd_allowed
)(fd
, str
, tid
, False
)) {
5549 SET_STATUS_Failure( VKI_EBADF
);
5550 } else if (count
> 0) {
5551 VG_(strcpy
) (tmp
, str
);
5552 VG_(strcat
) (tmp
, "(vector)");
5553 PRE_MEM_READ( tmp
, vector
, count
* sizeof(struct vki_iovec
) );
5555 if (ML_(safe_to_deref
) ((void *)(Addr
)vector
,
5556 count
* sizeof(struct vki_iovec
))) {
5557 vec
= (struct vki_iovec
*)(Addr
)vector
;
5558 for (i
= 0; i
< count
; i
++) {
5559 VG_(snprintf
) (tmp
, 30, "%s(vector[%d])", str
, i
);
5560 PRE_MEM_WRITE( tmp
, (Addr
)vec
[i
].iov_base
, vec
[i
].iov_len
);
5566 /* This handles the common part of the POST macro for preadv and preadv2. */
5567 void handle_post_sys_preadv(ThreadId tid
, SyscallStatus
* status
, Addr vector
, Int count
)
5572 struct vki_iovec
* vec
= (struct vki_iovec
*)(Addr
)vector
;
5575 /* RES holds the number of bytes read. */
5576 for (i
= 0; i
< count
; i
++) {
5577 Int nReadThisBuf
= vec
[i
].iov_len
;
5578 if (nReadThisBuf
> remains
) nReadThisBuf
= remains
;
5579 POST_MEM_WRITE( (Addr
)vec
[i
].iov_base
, nReadThisBuf
);
5580 remains
-= nReadThisBuf
;
5581 if (remains
< 0) VG_(core_panic
)("preadv: remains < 0");
5588 *flags
|= SfMayBlock
;
5589 const char *str
= "preadv";
5590 #if VG_WORDSIZE == 4
5591 /* Note that the offset argument here is in lo+hi order on both
5592 big and little endian platforms... */
5593 PRINT("sys_preadv ( %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
5595 ARG1
, ARG2
, ARG3
, (Long
)LOHI64(ARG4
,ARG5
));
5596 PRE_REG_READ5(ssize_t
, "preadv",
5597 unsigned long, fd
, const struct iovec
*, vector
,
5598 unsigned long, count
, vki_u32
, offset_low
,
5599 vki_u32
, offset_high
);
5600 #elif VG_WORDSIZE == 8
5601 PRINT("sys_preadv ( %lu, %#lx, %lu, %ld )", ARG1
, ARG2
, ARG3
, SARG4
);
5602 PRE_REG_READ4(ssize_t
, "preadv",
5603 unsigned long, fd
, const struct iovec
*, vector
,
5604 unsigned long, count
, Word
, offset
);
5606 # error Unexpected word size
5612 handle_pre_sys_preadv(tid
, status
, fd
, vector
, count
, str
);
5621 handle_post_sys_preadv(tid
, status
, vector
, count
);
5626 *flags
|= SfMayBlock
;
5627 const char *str
= "preadv2";
5628 #if VG_WORDSIZE == 4
5629 /* Note that the offset argument here is in lo+hi order on both
5630 big and little endian platforms... */
5631 PRINT("sys_preadv2 ( %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
5632 "u, %lld, %" FMT_REGWORD
"u )",
5633 ARG1
, ARG2
, ARG3
, (Long
)LOHI64(ARG4
,ARG5
), ARG6
);
5634 PRE_REG_READ6(ssize_t
, "preadv2",
5635 unsigned long, fd
, const struct iovec
*, vector
,
5636 unsigned long, count
, vki_u32
, offset_low
,
5637 vki_u32
, offset_high
, unsigned long, flags
);
5638 #elif VG_WORDSIZE == 8
5639 PRINT("sys_preadv2 ( %lu, %#lx, %lu, %ld, %lu )", ARG1
, ARG2
, ARG3
, SARG4
, ARG5
);
5640 PRE_REG_READ5(ssize_t
, "preadv2",
5641 unsigned long, fd
, const struct iovec
*, vector
,
5642 unsigned long, count
, Word
, offset
, unsigned long, flags
);
5644 # error Unexpected word size
5650 handle_pre_sys_preadv(tid
, status
, fd
, vector
, count
, str
);
5658 handle_post_sys_preadv(tid
, status
, vector
, count
);
5661 /* This handles the common part of the PRE macro for pwritev and pwritev2. */
5662 void handle_sys_pwritev(ThreadId tid
, SyscallStatus
* status
,
5663 Int fd
, Addr vector
, Int count
, const char *str
)
5666 struct vki_iovec
* vec
;
5667 /* safe size for the "preadv/preadv2(vector[i])" string */
5670 if (!ML_(fd_allowed
)(fd
, str
, tid
, False
)) {
5671 SET_STATUS_Failure( VKI_EBADF
);
5672 } else if (count
> 0) {
5673 VG_(strcpy
) (tmp
, str
);
5674 VG_(strcat
) (tmp
, "(vector)");
5675 PRE_MEM_READ( tmp
, vector
, count
* sizeof(struct vki_iovec
) );
5676 if (ML_(safe_to_deref
) ((void *)(Addr
)vector
,
5677 count
* sizeof(struct vki_iovec
))) {
5678 vec
= (struct vki_iovec
*)(Addr
)vector
;
5679 for (i
= 0; i
< count
; i
++) {
5680 VG_(snprintf
) (tmp
, 30, "%s(vector[%d])", str
, i
);
5681 PRE_MEM_READ( tmp
, (Addr
)vec
[i
].iov_base
, vec
[i
].iov_len
);
5689 *flags
|= SfMayBlock
;
5690 const char *str
= "pwritev";
5691 #if VG_WORDSIZE == 4
5692 /* Note that the offset argument here is in lo+hi order on both
5693 big and little endian platforms... */
5694 PRINT("sys_pwritev ( %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
5695 "u, %lld )", ARG1
, ARG2
, ARG3
, (Long
)LOHI64(ARG4
,ARG5
));
5696 PRE_REG_READ5(ssize_t
, "pwritev",
5697 unsigned long, fd
, const struct iovec
*, vector
,
5698 unsigned long, count
, vki_u32
, offset_low
,
5699 vki_u32
, offset_high
);
5700 #elif VG_WORDSIZE == 8
5701 PRINT("sys_pwritev ( %lu, %#lx, %lu, %ld )", ARG1
, ARG2
, ARG3
, SARG4
);
5702 PRE_REG_READ4(ssize_t
, "pwritev",
5703 unsigned long, fd
, const struct iovec
*, vector
,
5704 unsigned long, count
, Word
, offset
);
5706 # error Unexpected word size
5712 handle_sys_pwritev(tid
, status
, fd
, vector
, count
, str
);
5717 *flags
|= SfMayBlock
;
5718 const char *str
= "pwritev2";
5719 #if VG_WORDSIZE == 4
5720 /* Note that the offset argument here is in lo+hi order on both
5721 big and little endian platforms... */
5722 PRINT("sys_pwritev2 ( %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
5723 "u, %lld, %" FMT_REGWORD
"u )",
5724 ARG1
, ARG2
, ARG3
, (Long
)LOHI64(ARG4
,ARG5
), ARG6
);
5725 PRE_REG_READ6(ssize_t
, "pwritev2",
5726 unsigned long, fd
, const struct iovec
*, vector
,
5727 unsigned long, count
, vki_u32
, offset_low
,
5728 vki_u32
, offset_high
, unsigned long, flags
);
5729 #elif VG_WORDSIZE == 8
5730 /* Note offset_high isn't actually used? */
5731 PRE_REG_READ6(ssize_t
, "pwritev2",
5732 unsigned long, fd
, const struct iovec
*, vector
,
5733 unsigned long, count
, Word
, offset
,
5734 Word
, offset_high
, unsigned long, flags
);
5736 # error Unexpected word size
5742 handle_sys_pwritev(tid
, status
, fd
, vector
, count
, str
);
5745 /* ---------------------------------------------------------------------
5746 process_vm_{read,write}v wrappers
5747 ------------------------------------------------------------------ */
5749 PRE(sys_process_vm_readv
)
5751 PRINT("sys_process_vm_readv ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
5752 "u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )",
5753 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
5754 PRE_REG_READ6(ssize_t
, "process_vm_readv",
5756 const struct iovec
*, lvec
,
5757 unsigned long, liovcnt
,
5758 const struct iovec
*, rvec
,
5759 unsigned long, riovcnt
,
5760 unsigned long, flags
);
5761 PRE_MEM_READ( "process_vm_readv(lvec)",
5762 ARG2
, ARG3
* sizeof(struct vki_iovec
) );
5763 PRE_MEM_READ( "process_vm_readv(rvec)",
5764 ARG4
, ARG5
* sizeof(struct vki_iovec
) );
5766 && ML_(safe_to_deref
) ((void *)(Addr
)ARG2
,
5767 sizeof(struct vki_iovec
) * ARG3
)) {
5768 const struct vki_iovec
*vec
= (const struct vki_iovec
*)(Addr
)ARG2
;
5770 for (i
= 0; i
< ARG3
; i
++)
5771 PRE_MEM_WRITE( "process_vm_readv(lvec[...])",
5772 (Addr
)vec
[i
].iov_base
, vec
[i
].iov_len
);
5776 POST(sys_process_vm_readv
)
5778 const struct vki_iovec
*vec
= (const struct vki_iovec
*)(Addr
)ARG2
;
5781 for (i
= 0; i
< ARG3
; i
++) {
5782 UInt nReadThisBuf
= vec
[i
].iov_len
<= remains
?
5783 vec
[i
].iov_len
: remains
;
5784 POST_MEM_WRITE( (Addr
)vec
[i
].iov_base
, nReadThisBuf
);
5785 remains
-= nReadThisBuf
;
5789 PRE(sys_process_vm_writev
)
5791 PRINT("sys_process_vm_writev ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
5792 "u, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )",
5793 SARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
5794 PRE_REG_READ6(ssize_t
, "process_vm_writev",
5796 const struct iovec
*, lvec
,
5797 unsigned long, liovcnt
,
5798 const struct iovec
*, rvec
,
5799 unsigned long, riovcnt
,
5800 unsigned long, flags
);
5801 PRE_MEM_READ( "process_vm_writev(lvec)",
5802 ARG2
, ARG3
* sizeof(struct vki_iovec
) );
5803 PRE_MEM_READ( "process_vm_writev(rvec)",
5804 ARG4
, ARG5
* sizeof(struct vki_iovec
) );
5806 && ML_(safe_to_deref
) ((void *)(Addr
)ARG2
,
5807 sizeof(struct vki_iovec
) * ARG3
)) {
5808 const struct vki_iovec
*vec
= (const struct vki_iovec
*)(Addr
)ARG2
;
5810 for (i
= 0; i
< ARG3
; i
++)
5811 PRE_MEM_READ( "process_vm_writev(lvec[...])",
5812 (Addr
)vec
[i
].iov_base
, vec
[i
].iov_len
);
5816 /* ---------------------------------------------------------------------
5817 {send,recv}mmsg wrappers
5818 ------------------------------------------------------------------ */
5822 *flags
|= SfMayBlock
;
5823 PRINT("sys_sendmmsg ( %ld, %#" FMT_REGWORD
"x, %ld, %ld )", SARG1
, ARG2
,
5825 PRE_REG_READ4(long, "sendmmsg",
5826 int, s
, const struct mmsghdr
*, mmsg
, int, vlen
, int, flags
);
5827 ML_(linux_PRE_sys_sendmmsg
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
);
5832 ML_(linux_POST_sys_sendmmsg
) (tid
, RES
, ARG1
,ARG2
,ARG3
,ARG4
);
5837 *flags
|= SfMayBlock
;
5838 PRINT("sys_recvmmsg ( %ld, %#" FMT_REGWORD
"x, %ld, %ld, %#"
5840 SARG1
, ARG2
, SARG3
, SARG4
, ARG5
);
5841 PRE_REG_READ5(long, "recvmmsg",
5842 int, s
, struct mmsghdr
*, mmsg
, int, vlen
,
5843 int, flags
, struct timespec
*, timeout
);
5844 ML_(linux_PRE_sys_recvmmsg
)(tid
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
5849 ML_(linux_POST_sys_recvmmsg
) (tid
, RES
, ARG1
,ARG2
,ARG3
,ARG4
,ARG5
);
5852 /* ---------------------------------------------------------------------
5853 key retention service wrappers
5854 ------------------------------------------------------------------ */
5856 PRE(sys_request_key
)
5858 PRINT("sys_request_key ( %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x(%s), %#"
5859 FMT_REGWORD
"x(%s), %ld )", ARG1
, (HChar
*)(Addr
)ARG1
, ARG2
,
5860 (HChar
*)(Addr
)ARG2
, ARG3
, (HChar
*)(Addr
)ARG3
, SARG4
);
5861 PRE_REG_READ4(long, "request_key",
5862 const char *, type
, const char *, description
,
5863 const char *, callout_info
, vki_key_serial_t
, keyring
);
5864 PRE_MEM_RASCIIZ( "request_key(type)", ARG1
);
5865 PRE_MEM_RASCIIZ( "request_key(description)", ARG2
);
5866 if (ARG3
!= (UWord
)NULL
)
5867 PRE_MEM_RASCIIZ( "request_key(callout_info)", ARG3
);
5872 PRINT("sys_add_key ( %#" FMT_REGWORD
"x(%s), %#" FMT_REGWORD
"x(%s), %#"
5873 FMT_REGWORD
"x, %" FMT_REGWORD
"u, %ld )", ARG1
, (HChar
*)(Addr
)ARG1
,
5874 ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
, ARG4
, SARG5
);
5875 PRE_REG_READ5(long, "add_key",
5876 const char *, type
, const char *, description
,
5877 const void *, payload
, vki_size_t
, plen
,
5878 vki_key_serial_t
, keyring
);
5879 PRE_MEM_RASCIIZ( "add_key(type)", ARG1
);
5880 PRE_MEM_RASCIIZ( "add_key(description)", ARG2
);
5881 if (ARG3
!= (UWord
)NULL
)
5882 PRE_MEM_READ( "request_key(payload)", ARG3
, ARG4
);
5887 switch (ARG1
/* option */) {
5888 case VKI_KEYCTL_GET_KEYRING_ID
:
5889 PRINT("sys_keyctl ( KEYCTL_GET_KEYRING_ID, %ld, %ld )", SARG2
, SARG3
);
5890 PRE_REG_READ3(long, "keyctl(KEYCTL_GET_KEYRING_ID)",
5891 int, option
, vki_key_serial_t
, id
, int, create
);
5893 case VKI_KEYCTL_JOIN_SESSION_KEYRING
:
5894 PRINT("sys_keyctl ( KEYCTL_JOIN_SESSION_KEYRING, %#" FMT_REGWORD
5895 "x(%s) )", ARG2
,(char*)(Addr
)ARG2
);
5896 PRE_REG_READ2(long, "keyctl(KEYCTL_JOIN_SESSION_KEYRING)",
5897 int, option
, const char *, name
);
5898 if (ARG2
!= (UWord
)NULL
)
5899 PRE_MEM_RASCIIZ("keyctl(KEYCTL_JOIN_SESSION_KEYRING, name)", ARG2
);
5901 case VKI_KEYCTL_UPDATE
:
5902 PRINT("sys_keyctl ( KEYCTL_UPDATE, %ld, %#" FMT_REGWORD
"x, %"
5903 FMT_REGWORD
"u )", SARG2
, ARG3
, ARG4
);
5904 PRE_REG_READ4(long, "keyctl(KEYCTL_UPDATE)",
5905 int, option
, vki_key_serial_t
, key
,
5906 const void *, payload
, vki_size_t
, plen
);
5907 if (ARG3
!= (UWord
)NULL
)
5908 PRE_MEM_READ("keyctl(KEYCTL_UPDATE, payload)", ARG3
, ARG4
);
5910 case VKI_KEYCTL_REVOKE
:
5911 PRINT("sys_keyctl ( KEYCTL_REVOKE, %ld )", SARG2
);
5912 PRE_REG_READ2(long, "keyctl(KEYCTL_REVOKE)",
5913 int, option
, vki_key_serial_t
, id
);
5915 case VKI_KEYCTL_CHOWN
:
5916 PRINT("sys_keyctl ( KEYCTL_CHOWN, %ld, %" FMT_REGWORD
"u, %"
5917 FMT_REGWORD
"u )", SARG2
, ARG3
, ARG4
);
5918 PRE_REG_READ4(long, "keyctl(KEYCTL_CHOWN)",
5919 int, option
, vki_key_serial_t
, id
,
5920 vki_uid_t
, uid
, vki_gid_t
, gid
);
5922 case VKI_KEYCTL_SETPERM
:
5923 PRINT("sys_keyctl ( KEYCTL_SETPERM, %ld, %" FMT_REGWORD
"u )",
5925 PRE_REG_READ3(long, "keyctl(KEYCTL_SETPERM)",
5926 int, option
, vki_key_serial_t
, id
, vki_key_perm_t
, perm
);
5928 case VKI_KEYCTL_DESCRIBE
:
5929 PRINT("sys_keyctl ( KEYCTL_DESCRIBE, %ld, %#" FMT_REGWORD
"x, %"
5930 FMT_REGWORD
"u )", SARG2
, ARG3
, ARG4
);
5931 PRE_REG_READ4(long, "keyctl(KEYCTL_DESCRIBE)",
5932 int, option
, vki_key_serial_t
, id
,
5933 char *, buffer
, vki_size_t
, buflen
);
5934 if (ARG3
!= (UWord
)NULL
)
5935 PRE_MEM_WRITE("keyctl(KEYCTL_DESCRIBE, buffer)", ARG3
, ARG4
);
5937 case VKI_KEYCTL_CLEAR
:
5938 PRINT("sys_keyctl ( KEYCTL_CLEAR, %ld )", SARG2
);
5939 PRE_REG_READ2(long, "keyctl(KEYCTL_CLEAR)",
5940 int, option
, vki_key_serial_t
, keyring
);
5942 case VKI_KEYCTL_LINK
:
5943 PRINT("sys_keyctl ( KEYCTL_LINK, %ld, %ld )", SARG2
, SARG3
);
5944 PRE_REG_READ3(long, "keyctl(KEYCTL_LINK)", int, option
,
5945 vki_key_serial_t
, keyring
, vki_key_serial_t
, key
);
5947 case VKI_KEYCTL_UNLINK
:
5948 PRINT("sys_keyctl ( KEYCTL_UNLINK, %ld, %ld )", SARG2
, SARG3
);
5949 PRE_REG_READ3(long, "keyctl(KEYCTL_UNLINK)", int, option
,
5950 vki_key_serial_t
, keyring
, vki_key_serial_t
, key
);
5952 case VKI_KEYCTL_SEARCH
:
5953 PRINT("sys_keyctl ( KEYCTL_SEARCH, %ld, %#" FMT_REGWORD
"x(%s), %#"
5954 FMT_REGWORD
"x(%s), %ld )", SARG2
, ARG3
, (HChar
*)(Addr
)ARG3
,
5955 ARG4
, (HChar
*)(Addr
)ARG4
, SARG5
);
5956 PRE_REG_READ5(long, "keyctl(KEYCTL_SEARCH)",
5957 int, option
, vki_key_serial_t
, keyring
,
5958 const char *, type
, const char *, description
,
5959 vki_key_serial_t
, destring
);
5960 PRE_MEM_RASCIIZ("sys_keyctl(KEYCTL_SEARCH, type)", ARG3
);
5961 PRE_MEM_RASCIIZ("sys_keyctl(KEYCTL_SEARCH, description)", ARG4
);
5963 case VKI_KEYCTL_READ
:
5964 PRINT("sys_keyctl ( KEYCTL_READ, %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
5965 "u )", SARG2
, ARG3
, ARG4
);
5966 PRE_REG_READ4(long, "keyctl(KEYCTL_READ)",
5967 int, option
, vki_key_serial_t
, keyring
,
5968 char *, buffer
, vki_size_t
, buflen
);
5969 if (ARG3
!= (UWord
)NULL
)
5970 PRE_MEM_WRITE("keyctl(KEYCTL_READ, buffer)", ARG3
, ARG4
);
5972 case VKI_KEYCTL_INSTANTIATE
:
5973 PRINT("sys_keyctl ( KEYCTL_INSTANTIATE, %ld, %#" FMT_REGWORD
"x, %"
5974 FMT_REGWORD
"u, %ld )", SARG2
, ARG3
, ARG4
, SARG5
);
5975 PRE_REG_READ5(long, "keyctl(KEYCTL_INSTANTIATE)",
5976 int, option
, vki_key_serial_t
, key
,
5977 char *, payload
, vki_size_t
, plen
,
5978 vki_key_serial_t
, keyring
);
5979 if (ARG3
!= (UWord
)NULL
)
5980 PRE_MEM_READ("keyctl(KEYCTL_INSTANTIATE, payload)", ARG3
, ARG4
);
5982 case VKI_KEYCTL_NEGATE
:
5983 PRINT("sys_keyctl ( KEYCTL_NEGATE, %ld, %" FMT_REGWORD
"u, %ld )",
5984 SARG2
, ARG3
, SARG4
);
5985 PRE_REG_READ4(long, "keyctl(KEYCTL_NEGATE)",
5986 int, option
, vki_key_serial_t
, key
,
5987 unsigned, timeout
, vki_key_serial_t
, keyring
);
5989 case VKI_KEYCTL_SET_REQKEY_KEYRING
:
5990 PRINT("sys_keyctl ( KEYCTL_SET_REQKEY_KEYRING, %ld )", SARG2
);
5991 PRE_REG_READ2(long, "keyctl(KEYCTL_SET_REQKEY_KEYRING)",
5992 int, option
, int, reqkey_defl
);
5994 case VKI_KEYCTL_SET_TIMEOUT
:
5995 PRINT("sys_keyctl ( KEYCTL_SET_TIMEOUT, %ld, %" FMT_REGWORD
"u )",
5997 PRE_REG_READ3(long, "keyctl(KEYCTL_SET_TIMEOUT)",
5998 int, option
, vki_key_serial_t
, key
, unsigned, timeout
);
6000 case VKI_KEYCTL_ASSUME_AUTHORITY
:
6001 PRINT("sys_keyctl ( KEYCTL_ASSUME_AUTHORITY, %ld )", SARG2
);
6002 PRE_REG_READ2(long, "keyctl(KEYCTL_ASSUME_AUTHORITY)",
6003 int, option
, vki_key_serial_t
, key
);
6006 PRINT("sys_keyctl ( %ld ) ", SARG1
);
6007 PRE_REG_READ1(long, "keyctl", int, option
);
6015 switch (ARG1
/* option */) {
6016 case VKI_KEYCTL_DESCRIBE
:
6017 case VKI_KEYCTL_READ
:
6019 POST_MEM_WRITE(ARG3
, ARG4
);
6021 POST_MEM_WRITE(ARG3
, RES
);
6028 /* ---------------------------------------------------------------------
6030 ------------------------------------------------------------------ */
6034 PRINT("sys_ioprio_set ( %ld, %ld, %ld )", SARG1
, SARG2
, SARG3
);
6035 PRE_REG_READ3(int, "ioprio_set", int, which
, int, who
, int, ioprio
);
6040 PRINT("sys_ioprio_get ( %ld, %ld )", SARG1
, SARG2
);
6041 PRE_REG_READ2(int, "ioprio_get", int, which
, int, who
);
6044 /* ---------------------------------------------------------------------
6046 ------------------------------------------------------------------ */
6048 PRE(sys_init_module
)
6050 *flags
|= SfMayBlock
;
6051 PRINT("sys_init_module ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#"
6052 FMT_REGWORD
"x(\"%s\") )", ARG1
, ARG2
, ARG3
, (HChar
*)(Addr
)ARG3
);
6053 PRE_REG_READ3(long, "init_module",
6054 void *, umod
, unsigned long, len
, const char *, uargs
);
6055 PRE_MEM_READ( "init_module(umod)", ARG1
, ARG2
);
6056 PRE_MEM_RASCIIZ( "init_module(uargs)", ARG3
);
6059 PRE(sys_finit_module
)
6061 *flags
|= SfMayBlock
;
6063 PRINT("sys_finit_module ( %" FMT_REGWORD
"x, %#" FMT_REGWORD
"x(\"%s\"), %"
6064 FMT_REGWORD
"x )", ARG1
, ARG2
, (HChar
*)(Addr
)ARG2
, ARG3
);
6065 PRE_REG_READ3(long, "finit_module",
6066 int, fd
, const char *, params
, int, flags
);
6067 PRE_MEM_RASCIIZ("finit_module(params)", ARG2
);
6070 PRE(sys_delete_module
)
6072 *flags
|= SfMayBlock
;
6073 PRINT("sys_delete_module ( %#" FMT_REGWORD
"x(\"%s\"), 0x%" FMT_REGWORD
6074 "x )", ARG1
, (HChar
*)(Addr
)ARG1
, ARG2
);
6075 PRE_REG_READ2(long, "delete_module",
6076 const char *, name_user
, unsigned int, flags
);
6077 PRE_MEM_RASCIIZ("delete_module(name_user)", ARG1
);
6080 /* ---------------------------------------------------------------------
6082 ------------------------------------------------------------------ */
6086 *flags
|= SfMayBlock
;
6087 PRINT("sys_splice ( %ld, %#" FMT_REGWORD
"x, %ld, %#"
6088 FMT_REGWORD
"x, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
6089 SARG1
, ARG2
, SARG3
, ARG4
, ARG5
, ARG6
);
6090 PRE_REG_READ6(vki_ssize_t
, "splice",
6091 int, fd_in
, vki_loff_t
*, off_in
,
6092 int, fd_out
, vki_loff_t
*, off_out
,
6093 vki_size_t
, len
, unsigned int, flags
);
6094 if (!ML_(fd_allowed
)(ARG1
, "splice(fd_in)", tid
, False
) ||
6095 !ML_(fd_allowed
)(ARG3
, "splice(fd_out)", tid
, False
)) {
6096 SET_STATUS_Failure( VKI_EBADF
);
6099 PRE_MEM_READ( "splice(off_in)", ARG2
, sizeof(vki_loff_t
));
6101 PRE_MEM_READ( "splice(off_out)", ARG4
, sizeof(vki_loff_t
));
6107 *flags
|= SfMayBlock
;
6108 PRINT("sys_tree ( %ld, %ld, %" FMT_REGWORD
"u, %#" FMT_REGWORD
"x )",
6109 SARG1
, SARG2
, ARG3
, ARG4
);
6110 PRE_REG_READ4(vki_ssize_t
, "tee",
6111 int, fd_in
, int, fd_out
,
6112 vki_size_t
, len
, unsigned int, flags
);
6113 if (!ML_(fd_allowed
)(ARG1
, "tee(fd_in)", tid
, False
) ||
6114 !ML_(fd_allowed
)(ARG2
, "tee(fd_out)", tid
, False
)) {
6115 SET_STATUS_Failure( VKI_EBADF
);
6122 *flags
|= SfMayBlock
;
6123 PRINT("sys_vmsplice ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
6124 FMT_REGWORD
"u )", SARG1
, ARG2
, ARG3
, ARG4
);
6125 PRE_REG_READ4(vki_ssize_t
, "splice",
6126 int, fd
, struct vki_iovec
*, iov
,
6127 unsigned long, nr_segs
, unsigned int, flags
);
6128 if (!ML_(fd_allowed
)(ARG1
, "vmsplice(fd)", tid
, False
)) {
6129 SET_STATUS_Failure( VKI_EBADF
);
6130 } else if ((fdfl
= VG_(fcntl
)(ARG1
, VKI_F_GETFL
, 0)) < 0) {
6131 SET_STATUS_Failure( VKI_EBADF
);
6133 const struct vki_iovec
*iov
;
6134 PRE_MEM_READ( "vmsplice(iov)", ARG2
, sizeof(struct vki_iovec
) * ARG3
);
6135 for (iov
= (struct vki_iovec
*)(Addr
)ARG2
;
6136 iov
< (struct vki_iovec
*)(Addr
)ARG2
+ ARG3
; iov
++)
6138 if (ML_(safe_to_deref
) (iov
, sizeof(struct vki_iovec
))) {
6139 if ((fdfl
& VKI_O_ACCMODE
) == VKI_O_RDONLY
)
6140 PRE_MEM_WRITE( "vmsplice(iov[...])",
6141 (Addr
)iov
->iov_base
, iov
->iov_len
);
6143 PRE_MEM_READ( "vmsplice(iov[...])",
6144 (Addr
)iov
->iov_base
, iov
->iov_len
);
6154 Int fdfl
= VG_(fcntl
)(ARG1
, VKI_F_GETFL
, 0);
6155 vg_assert(fdfl
>= 0);
6156 if ((fdfl
& VKI_O_ACCMODE
) == VKI_O_RDONLY
)
6158 const struct vki_iovec
*iov
;
6159 for (iov
= (struct vki_iovec
*)(Addr
)ARG2
;
6160 iov
< (struct vki_iovec
*)(Addr
)ARG2
+ ARG3
; iov
++)
6162 POST_MEM_WRITE( (Addr
)iov
->iov_base
, iov
->iov_len
);
6168 /* ---------------------------------------------------------------------
6169 oprofile-related wrappers
6170 ------------------------------------------------------------------ */
6172 #if defined(VGP_x86_linux)
6173 PRE(sys_lookup_dcookie
)
6175 PRINT("sys_lookup_dcookie (0x%llx, %#lx, %lu)",
6176 MERGE64(ARG1
,ARG2
), ARG3
, ARG4
);
6177 PRE_REG_READ4(long, "lookup_dcookie",
6178 vki_u32
, MERGE64_FIRST(cookie
), vki_u32
, MERGE64_SECOND(cookie
),
6179 char *, buf
, vki_size_t
, len
);
6180 PRE_MEM_WRITE( "lookup_dcookie(buf)", ARG3
, ARG4
);
6182 POST(sys_lookup_dcookie
)
6185 if (ARG3
!= (Addr
)NULL
)
6186 POST_MEM_WRITE( ARG3
, RES
);
6190 #if defined(VGP_amd64_linux) || defined(VGP_s390x_linux) \
6191 || defined(VGP_arm64_linux) || defined(VGP_nanomips_linux)
6192 PRE(sys_lookup_dcookie
)
6194 *flags
|= SfMayBlock
;
6195 PRINT("sys_lookup_dcookie ( %lu, %#lx, %lu )", ARG1
, ARG2
, ARG3
);
6196 PRE_REG_READ3(int, "lookup_dcookie",
6197 unsigned long long, cookie
, char *, buf
, vki_size_t
, len
);
6199 PRE_MEM_WRITE( "sys_lookup_dcookie(buf)", ARG2
, ARG3
);
6202 POST(sys_lookup_dcookie
)
6205 if (ARG2
!= (Addr
)NULL
)
6206 POST_MEM_WRITE( ARG2
, RES
);
6210 /* ---------------------------------------------------------------------
6212 ------------------------------------------------------------------ */
6217 // These ones ignore ARG3.
6222 case VKI_F_GETLEASE
:
6223 case VKI_F_GETPIPE_SZ
:
6224 PRINT("sys_fcntl ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )", ARG1
, ARG2
);
6225 PRE_REG_READ2(long, "fcntl", unsigned int, fd
, unsigned int, cmd
);
6228 // These ones use ARG3 as "arg".
6230 case VKI_F_DUPFD_CLOEXEC
:
6233 case VKI_F_SETLEASE
:
6237 case VKI_F_SETPIPE_SZ
:
6238 PRINT("sys_fcntl[ARG3=='arg'] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6239 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6240 PRE_REG_READ3(long, "fcntl",
6241 unsigned int, fd
, unsigned int, cmd
, unsigned long, arg
);
6244 // These ones use ARG3 as "lock".
6248 case VKI_F_OFD_GETLK
:
6249 case VKI_F_OFD_SETLK
:
6250 case VKI_F_OFD_SETLKW
:
6251 PRINT("sys_fcntl[ARG3=='lock'] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6252 "u, %#" FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
6253 PRE_REG_READ3(long, "fcntl",
6254 unsigned int, fd
, unsigned int, cmd
,
6255 struct vki_flock
*, lock
);
6257 struct vki_flock
*lock
= (struct vki_flock
*) (Addr
)ARG3
;
6258 PRE_FIELD_READ("fcntl(lock->l_type)", lock
->l_type
);
6259 PRE_FIELD_READ("fcntl(lock->l_whence)", lock
->l_whence
);
6260 PRE_FIELD_READ("fcntl(lock->l_start)", lock
->l_start
);
6261 PRE_FIELD_READ("fcntl(lock->l_len)", lock
->l_len
);
6262 if (ARG2
== VKI_F_GETLK
|| ARG2
== VKI_F_OFD_GETLK
) {
6263 PRE_FIELD_WRITE("fcntl(lock->l_pid)", lock
->l_pid
);
6268 # if defined(VGP_x86_linux) || defined(VGP_mips64_linux)
6271 case VKI_F_SETLKW64
:
6272 PRINT("sys_fcntl[ARG3=='lock'] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6273 "u, %#" FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
6274 PRE_REG_READ3(long, "fcntl",
6275 unsigned int, fd
, unsigned int, cmd
,
6276 struct flock64
*, lock
);
6278 struct vki_flock64
*lock
= (struct vki_flock64
*) (Addr
)ARG3
;
6279 PRE_FIELD_READ("fcntl(lock->l_type)", lock
->l_type
);
6280 PRE_FIELD_READ("fcntl(lock->l_whence)", lock
->l_whence
);
6281 PRE_FIELD_READ("fcntl(lock->l_start)", lock
->l_start
);
6282 PRE_FIELD_READ("fcntl(lock->l_len)", lock
->l_len
);
6283 if (ARG2
== VKI_F_GETLK64
) {
6284 PRE_FIELD_WRITE("fcntl(lock->l_pid)", lock
->l_pid
);
6290 case VKI_F_SETOWN_EX
:
6291 PRINT("sys_fcntl[F_SETOWN_EX] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6292 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6293 PRE_REG_READ3(long, "fcntl",
6294 unsigned int, fd
, unsigned int, cmd
,
6295 struct vki_f_owner_ex
*, arg
);
6296 PRE_MEM_READ("fcntl(F_SETOWN_EX)", ARG3
, sizeof(struct vki_f_owner_ex
));
6299 case VKI_F_GETOWN_EX
:
6300 PRINT("sys_fcntl[F_GETOWN_EX] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6301 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6302 PRE_REG_READ3(long, "fcntl",
6303 unsigned int, fd
, unsigned int, cmd
,
6304 struct vki_f_owner_ex
*, arg
);
6305 PRE_MEM_WRITE("fcntl(F_GETOWN_EX)", ARG3
, sizeof(struct vki_f_owner_ex
));
6309 PRINT("sys_fcntl[UNKNOWN] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u, %"
6310 FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6311 VG_(umsg
)("Warning: unimplemented fcntl command: %" FMT_REGWORD
"u\n",
6313 SET_STATUS_Failure( VKI_EINVAL
);
6317 # if defined(VGP_x86_linux)
6318 if (ARG2
== VKI_F_SETLKW
|| ARG2
== VKI_F_SETLKW64
)
6320 if (ARG2
== VKI_F_SETLKW
)
6322 *flags
|= SfMayBlock
;
6328 if (ARG2
== VKI_F_DUPFD
) {
6329 if (!ML_(fd_allowed
)(RES
, "fcntl(DUPFD)", tid
, True
)) {
6331 SET_STATUS_Failure( VKI_EMFILE
);
6333 if (VG_(clo_track_fds
))
6334 ML_(record_fd_open_named
)(tid
, RES
);
6337 else if (ARG2
== VKI_F_DUPFD_CLOEXEC
) {
6338 if (!ML_(fd_allowed
)(RES
, "fcntl(DUPFD_CLOEXEC)", tid
, True
)) {
6340 SET_STATUS_Failure( VKI_EMFILE
);
6342 if (VG_(clo_track_fds
))
6343 ML_(record_fd_open_named
)(tid
, RES
);
6345 } else if (ARG2
== VKI_F_GETOWN_EX
) {
6346 POST_MEM_WRITE(ARG3
, sizeof(struct vki_f_owner_ex
));
6347 } else if (ARG2
== VKI_F_GETLK
|| ARG2
== VKI_F_OFD_GETLK
) {
6348 struct vki_flock
*lock
= (struct vki_flock
*) (Addr
)ARG3
;
6349 POST_FIELD_WRITE(lock
->l_pid
);
6350 # if defined(VGP_x86_linux) || defined(VGP_mips64_linux)
6351 } else if (ARG2
== VKI_F_GETLK64
) {
6352 struct vki_flock64
*lock
= (struct vki_flock64
*) (Addr
)ARG3
;
6353 PRE_FIELD_WRITE("fcntl(lock->l_pid)", lock
->l_pid
);
6358 // XXX: wrapper only suitable for 32-bit systems
6362 // These ones ignore ARG3.
6369 case VKI_F_GETLEASE
:
6370 PRINT("sys_fcntl64 ( %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )", ARG1
, ARG2
);
6371 PRE_REG_READ2(long, "fcntl64", unsigned int, fd
, unsigned int, cmd
);
6374 // These ones use ARG3 as "arg".
6376 case VKI_F_DUPFD_CLOEXEC
:
6379 case VKI_F_SETLEASE
:
6381 PRINT("sys_fcntl64[ARG3=='arg'] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6382 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6383 PRE_REG_READ3(long, "fcntl64",
6384 unsigned int, fd
, unsigned int, cmd
, unsigned long, arg
);
6387 // These ones use ARG3 as "lock".
6391 # if defined(VGP_x86_linux)
6394 case VKI_F_SETLKW64
:
6396 case VKI_F_OFD_GETLK
:
6397 case VKI_F_OFD_SETLK
:
6398 case VKI_F_OFD_SETLKW
:
6399 PRINT("sys_fcntl64[ARG3=='lock'] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6400 "u, %#" FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
6401 PRE_REG_READ3(long, "fcntl64",
6402 unsigned int, fd
, unsigned int, cmd
,
6403 struct flock64
*, lock
);
6406 case VKI_F_SETOWN_EX
:
6407 PRINT("sys_fcntl[F_SETOWN_EX] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6408 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6409 PRE_REG_READ3(long, "fcntl",
6410 unsigned int, fd
, unsigned int, cmd
,
6411 struct vki_f_owner_ex
*, arg
);
6412 PRE_MEM_READ("fcntl(F_SETOWN_EX)", ARG3
, sizeof(struct vki_f_owner_ex
));
6415 case VKI_F_GETOWN_EX
:
6416 PRINT("sys_fcntl[F_GETOWN_EX] ( %" FMT_REGWORD
"u, %" FMT_REGWORD
6417 "u, %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
);
6418 PRE_REG_READ3(long, "fcntl",
6419 unsigned int, fd
, unsigned int, cmd
,
6420 struct vki_f_owner_ex
*, arg
);
6421 PRE_MEM_WRITE("fcntl(F_GETOWN_EX)", ARG3
, sizeof(struct vki_f_owner_ex
));
6425 # if defined(VGP_x86_linux)
6426 if (ARG2
== VKI_F_SETLKW
|| ARG2
== VKI_F_SETLKW64
)
6428 if (ARG2
== VKI_F_SETLKW
)
6430 *flags
|= SfMayBlock
;
6436 if (ARG2
== VKI_F_DUPFD
) {
6437 if (!ML_(fd_allowed
)(RES
, "fcntl64(DUPFD)", tid
, True
)) {
6439 SET_STATUS_Failure( VKI_EMFILE
);
6441 if (VG_(clo_track_fds
))
6442 ML_(record_fd_open_named
)(tid
, RES
);
6445 else if (ARG2
== VKI_F_DUPFD_CLOEXEC
) {
6446 if (!ML_(fd_allowed
)(RES
, "fcntl64(DUPFD_CLOEXEC)", tid
, True
)) {
6448 SET_STATUS_Failure( VKI_EMFILE
);
6450 if (VG_(clo_track_fds
))
6451 ML_(record_fd_open_named
)(tid
, RES
);
6453 } else if (ARG2
== VKI_F_GETOWN_EX
) {
6454 POST_MEM_WRITE(ARG3
, sizeof(struct vki_f_owner_ex
));
6458 /* ---------------------------------------------------------------------
6460 ------------------------------------------------------------------ */
6462 struct vg_drm_version_info
{
6463 struct vki_drm_version data
;
6464 struct vki_drm_version
*orig
; // Original ARG3 pointer value at syscall entry.
6469 *flags
|= SfMayBlock
;
6473 // We first handle the ones that don't use ARG3 (even as a
6474 // scalar/non-pointer argument).
6475 switch (ARG2
/* request */) {
6477 /* asm-generic/ioctls.h */
6482 /* linux perf_event ioctls */
6483 case VKI_PERF_EVENT_IOC_ENABLE
:
6484 case VKI_PERF_EVENT_IOC_DISABLE
:
6486 /* linux/soundcard interface (ALSA) */
6487 case VKI_SNDRV_PCM_IOCTL_HW_FREE
:
6488 case VKI_SNDRV_PCM_IOCTL_HWSYNC
:
6489 case VKI_SNDRV_PCM_IOCTL_PREPARE
:
6490 case VKI_SNDRV_PCM_IOCTL_RESET
:
6491 case VKI_SNDRV_PCM_IOCTL_START
:
6492 case VKI_SNDRV_PCM_IOCTL_DROP
:
6493 case VKI_SNDRV_PCM_IOCTL_DRAIN
:
6494 case VKI_SNDRV_PCM_IOCTL_RESUME
:
6495 case VKI_SNDRV_PCM_IOCTL_XRUN
:
6496 case VKI_SNDRV_PCM_IOCTL_UNLINK
:
6497 case VKI_SNDRV_TIMER_IOCTL_START
:
6498 case VKI_SNDRV_TIMER_IOCTL_STOP
:
6499 case VKI_SNDRV_TIMER_IOCTL_CONTINUE
:
6500 case VKI_SNDRV_TIMER_IOCTL_PAUSE
:
6502 /* SCSI no operand */
6503 case VKI_SCSI_IOCTL_DOORLOCK
:
6504 case VKI_SCSI_IOCTL_DOORUNLOCK
:
6507 case VKI_CDROM_DISC_STATUS
:
6511 case VKI_DVD_READ_STRUCT
:
6513 /* KVM ioctls that don't check for a numeric value as parameter */
6514 case VKI_KVM_S390_ENABLE_SIE
:
6515 case VKI_KVM_CREATE_IRQCHIP
:
6516 case VKI_KVM_S390_INITIAL_RESET
:
6517 case VKI_KVM_KVMCLOCK_CTRL
:
6519 /* vhost without parameter */
6520 case VKI_VHOST_SET_OWNER
:
6521 case VKI_VHOST_RESET_OWNER
:
6523 /* User input device creation */
6524 case VKI_UI_DEV_CREATE
:
6525 case VKI_UI_DEV_DESTROY
:
6528 case VKI_IB_USER_MAD_ENABLE_PKEY
:
6531 case VKI_LL_IOC_GROUP_LOCK
:
6532 case VKI_LL_IOC_GROUP_UNLOCK
:
6535 case VKI_V4L2_LOG_STATUS
:
6538 case VKI_DRM_IOCTL_I915_GEM_THROTTLE
:
6542 PRINT("sys_ioctl ( %" FMT_REGWORD
"u, 0x%" FMT_REGWORD
"x )", ARG1
, ARG2
);
6543 PRE_REG_READ2(long, "ioctl",
6544 unsigned int, fd
, unsigned int, request
);
6548 PRINT("sys_ioctl ( %" FMT_REGWORD
"u, 0x%" FMT_REGWORD
"x, 0x%"
6549 FMT_REGWORD
"x )", ARG1
, ARG2
, ARG3
);
6550 PRE_REG_READ3(long, "ioctl",
6551 unsigned int, fd
, unsigned int, request
, unsigned long, arg
);
6555 // We now handle those that do look at ARG3 (and unknown ones fall into
6556 // this category). Nb: some of these may well belong in the
6557 // doesn't-use-ARG3 switch above.
6558 switch (ARG2
/* request */) {
6560 case VKI_ION_IOC_ALLOC
: {
6561 struct vki_ion_allocation_data
* data
6562 = (struct vki_ion_allocation_data
*)(Addr
)ARG3
;
6563 PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).len", data
->len
);
6564 PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).align", data
->align
);
6565 PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).heap_id_mask", data
->heap_id_mask
);
6566 PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).flags", data
->flags
);
6567 PRE_FIELD_WRITE("ioctl(ION_IOC_ALLOC).handle", data
->handle
);
6570 case VKI_ION_IOC_MAP
: {
6571 struct vki_ion_fd_data
* data
= (struct vki_ion_fd_data
*)(Addr
)ARG3
;
6572 PRE_FIELD_READ ("ioctl(ION_IOC_MAP).handle", data
->handle
);
6573 PRE_FIELD_WRITE("ioctl(ION_IOC_MAP).fd", data
->fd
);
6576 case VKI_ION_IOC_IMPORT
: {
6577 struct vki_ion_fd_data
* data
= (struct vki_ion_fd_data
*)(Addr
)ARG3
;
6578 PRE_FIELD_READ ("ioctl(ION_IOC_IMPORT).fd", data
->fd
);
6579 PRE_FIELD_WRITE("ioctl(ION_IOC_IMPORT).handle", data
->handle
);
6583 case VKI_SYNC_IOC_MERGE
: {
6584 struct vki_sync_merge_data
* data
=
6585 (struct vki_sync_merge_data
*)(Addr
)ARG3
;
6586 PRE_FIELD_READ ("ioctl(SYNC_IOC_MERGE).fd2", data
->fd2
);
6587 PRE_MEM_RASCIIZ("ioctl(SYNC_IOC_MERGE).name", (Addr
)(&data
->name
[0]));
6588 PRE_FIELD_WRITE("ioctl(SYNC_IOC_MERGE).fence", data
->fence
);
6595 PRE_MEM_READ( "ioctl(TCSET{S,SW,SF})", ARG3
, sizeof(struct vki_termios
) );
6598 PRE_MEM_WRITE( "ioctl(TCGETS)", ARG3
, sizeof(struct vki_termios
) );
6603 PRE_MEM_READ( "ioctl(TCSET{A,AW,AF})", ARG3
, sizeof(struct vki_termio
) );
6606 PRE_MEM_WRITE( "ioctl(TCGETA)", ARG3
, sizeof(struct vki_termio
) );
6613 /* These just take an int by value */
6615 case VKI_TIOCGWINSZ
:
6616 PRE_MEM_WRITE( "ioctl(TIOCGWINSZ)", ARG3
, sizeof(struct vki_winsize
) );
6618 case VKI_TIOCSWINSZ
:
6619 PRE_MEM_READ( "ioctl(TIOCSWINSZ)", ARG3
, sizeof(struct vki_winsize
) );
6622 PRE_MEM_READ( "ioctl(TIOCMBIS)", ARG3
, sizeof(unsigned int) );
6625 PRE_MEM_READ( "ioctl(TIOCMBIC)", ARG3
, sizeof(unsigned int) );
6628 PRE_MEM_READ( "ioctl(TIOCMSET)", ARG3
, sizeof(unsigned int) );
6631 PRE_MEM_WRITE( "ioctl(TIOCMGET)", ARG3
, sizeof(unsigned int) );
6634 PRE_MEM_READ( "ioctl(TIOCLINUX)", ARG3
, sizeof(char *) );
6635 if (*(char *)(Addr
)ARG3
== 11) {
6636 PRE_MEM_READ( "ioctl(TIOCLINUX, 11)", ARG3
, 2 * sizeof(char *) );
6640 /* Get process group ID for foreground processing group. */
6641 PRE_MEM_WRITE( "ioctl(TIOCGPGRP)", ARG3
, sizeof(vki_pid_t
) );
6644 /* Set a process group ID? */
6645 PRE_MEM_WRITE( "ioctl(TIOCGPGRP)", ARG3
, sizeof(vki_pid_t
) );
6647 case VKI_TIOCGPTN
: /* Get Pty Number (of pty-mux device) */
6648 PRE_MEM_WRITE( "ioctl(TIOCGPTN)", ARG3
, sizeof(int) );
6651 /* Just takes an int value. */
6653 case VKI_TIOCSPTLCK
: /* Lock/unlock Pty */
6654 PRE_MEM_READ( "ioctl(TIOCSPTLCK)", ARG3
, sizeof(int) );
6657 PRE_MEM_READ( "ioctl(FIONBIO)", ARG3
, sizeof(int) );
6660 PRE_MEM_READ( "ioctl(FIOASYNC)", ARG3
, sizeof(int) );
6662 case VKI_FIONREAD
: /* identical to SIOCINQ */
6663 PRE_MEM_WRITE( "ioctl(FIONREAD)", ARG3
, sizeof(int) );
6666 PRE_MEM_WRITE( "ioctl(FIOQSIZE)", ARG3
, sizeof(vki_loff_t
) );
6669 case VKI_TIOCSERGETLSR
:
6670 PRE_MEM_WRITE( "ioctl(TIOCSERGETLSR)", ARG3
, sizeof(int) );
6672 case VKI_TIOCGICOUNT
:
6673 PRE_MEM_WRITE( "ioctl(TIOCGICOUNT)", ARG3
,
6674 sizeof(struct vki_serial_icounter_struct
) );
6677 case VKI_SG_SET_COMMAND_Q
:
6678 PRE_MEM_READ( "ioctl(SG_SET_COMMAND_Q)", ARG3
, sizeof(int) );
6681 PRE_MEM_READ( "ioctl(SG_IO)", ARG3
, sizeof(vki_sg_io_hdr_t
) );
6683 vki_sg_io_hdr_t
*sgio
= (vki_sg_io_hdr_t
*)(Addr
)ARG3
;
6684 PRE_MEM_READ( "ioctl(SG_IO)", (Addr
)sgio
->cmdp
, sgio
->cmd_len
);
6685 if ( sgio
->dxfer_direction
== VKI_SG_DXFER_TO_DEV
||
6686 sgio
->dxfer_direction
== VKI_SG_DXFER_TO_FROM_DEV
) {
6687 PRE_MEM_READ( "ioctl(SG_IO)", (Addr
)sgio
->dxferp
, sgio
->dxfer_len
);
6691 case VKI_SG_GET_SCSI_ID
:
6692 PRE_MEM_WRITE( "ioctl(SG_GET_SCSI_ID)", ARG3
, sizeof(vki_sg_scsi_id_t
) );
6694 case VKI_SG_SET_RESERVED_SIZE
:
6695 PRE_MEM_READ( "ioctl(SG_SET_RESERVED_SIZE)", ARG3
, sizeof(int) );
6697 case VKI_SG_SET_TIMEOUT
:
6698 PRE_MEM_READ( "ioctl(SG_SET_TIMEOUT)", ARG3
, sizeof(int) );
6700 case VKI_SG_GET_RESERVED_SIZE
:
6701 PRE_MEM_WRITE( "ioctl(SG_GET_RESERVED_SIZE)", ARG3
, sizeof(int) );
6703 case VKI_SG_GET_TIMEOUT
:
6705 case VKI_SG_GET_VERSION_NUM
:
6706 PRE_MEM_WRITE( "ioctl(SG_GET_VERSION_NUM)", ARG3
, sizeof(int) );
6708 case VKI_SG_EMULATED_HOST
: /* 0x2203 */
6709 PRE_MEM_WRITE( "ioctl(SG_EMULATED_HOST)", ARG3
, sizeof(int) );
6711 case VKI_SG_GET_SG_TABLESIZE
: /* 0x227f */
6712 PRE_MEM_WRITE( "ioctl(SG_GET_SG_TABLESIZE)", ARG3
, sizeof(int) );
6715 case VKI_IIOCGETCPS
:
6716 PRE_MEM_WRITE( "ioctl(IIOCGETCPS)", ARG3
,
6717 VKI_ISDN_MAX_CHANNELS
* 2 * sizeof(unsigned long) );
6719 case VKI_IIOCNETGPN
:
6720 PRE_MEM_READ( "ioctl(IIOCNETGPN)",
6721 (Addr
)&((vki_isdn_net_ioctl_phone
*)(Addr
)ARG3
)->name
,
6722 sizeof(((vki_isdn_net_ioctl_phone
*)(Addr
)ARG3
)->name
) );
6723 PRE_MEM_WRITE( "ioctl(IIOCNETGPN)", ARG3
,
6724 sizeof(vki_isdn_net_ioctl_phone
) );
6727 /* These all use struct ifreq AFAIK */
6728 case VKI_SIOCGIFINDEX
: /* get iface index */
6729 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFINDEX)",
6730 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6731 PRE_MEM_WRITE( "ioctl(SIOCGIFINDEX)", ARG3
, sizeof(struct vki_ifreq
));
6733 case VKI_SIOCGIFFLAGS
: /* get flags */
6734 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFFLAGS)",
6735 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6736 PRE_MEM_WRITE( "ioctl(SIOCGIFFLAGS)", ARG3
, sizeof(struct vki_ifreq
));
6738 case VKI_SIOCGIFHWADDR
: /* Get hardware address */
6739 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFHWADDR)",
6740 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6741 PRE_MEM_WRITE( "ioctl(SIOCGIFHWADDR)", ARG3
, sizeof(struct vki_ifreq
));
6743 case VKI_SIOCGIFMTU
: /* get MTU size */
6744 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMTU)",
6745 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6746 PRE_MEM_WRITE( "ioctl(SIOCGIFMTU)", ARG3
, sizeof(struct vki_ifreq
));
6748 case VKI_SIOCGIFADDR
: /* get PA address */
6749 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFADDR)",
6750 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6751 PRE_MEM_WRITE( "ioctl(SIOCGIFADDR)", ARG3
, sizeof(struct vki_ifreq
));
6753 case VKI_SIOCGIFNETMASK
: /* get network PA mask */
6754 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFNETMASK)",
6755 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6756 PRE_MEM_WRITE( "ioctl(SIOCGIFNETMASK)", ARG3
, sizeof(struct vki_ifreq
));
6758 case VKI_SIOCGIFMETRIC
: /* get metric */
6759 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMETRIC)",
6760 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6761 PRE_MEM_WRITE( "ioctl(SIOCGIFMETRIC)", ARG3
, sizeof(struct vki_ifreq
));
6763 case VKI_SIOCGIFMAP
: /* Get device parameters */
6764 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMAP)",
6765 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6766 PRE_MEM_WRITE( "ioctl(SIOCGIFMAP)", ARG3
, sizeof(struct vki_ifreq
));
6768 case VKI_SIOCGIFTXQLEN
: /* Get the tx queue length */
6769 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFTXQLEN)",
6770 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6771 PRE_MEM_WRITE( "ioctl(SIOCGIFTXQLEN)", ARG3
, sizeof(struct vki_ifreq
));
6773 case VKI_SIOCGIFDSTADDR
: /* get remote PA address */
6774 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFDSTADDR)",
6775 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6776 PRE_MEM_WRITE( "ioctl(SIOCGIFDSTADDR)", ARG3
, sizeof(struct vki_ifreq
));
6778 case VKI_SIOCGIFBRDADDR
: /* get broadcast PA address */
6779 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFBRDADDR)",
6780 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6781 PRE_MEM_WRITE( "ioctl(SIOCGIFBRDADDR)", ARG3
, sizeof(struct vki_ifreq
));
6783 case VKI_SIOCGIFNAME
: /* get iface name */
6784 PRE_MEM_READ( "ioctl(SIOCGIFNAME)",
6785 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_ifindex
,
6786 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_ifindex
));
6787 PRE_MEM_WRITE( "ioctl(SIOCGIFNAME)", ARG3
, sizeof(struct vki_ifreq
));
6790 case VKI_SIOCETHTOOL
: { /* ethtool(8) interface */
6791 struct vki_ifreq
*ir
= (struct vki_ifreq
*)(Addr
)ARG3
;
6792 // The kernel will have to look at ifr_data to determine which operation
6794 PRE_MEM_READ( "ioctl(SIOCETHTOOL,ir->ifr_data)",
6795 (Addr
)ir
->vki_ifr_data
, sizeof(vki_u32
) );
6797 PRINT("SIOCETHTOOL( 0x%x )", *(vki_u32
*)ir
->vki_ifr_data
);
6799 // Is this correct? Is ifr_name *always* looked at?
6800 PRE_MEM_RASCIIZ( "ioctl(SIOCETHTOOL,ir->ifr_name)",
6801 (Addr
)ir
->vki_ifr_name
);
6803 // At least for ETHTOOL_GSET, it is apparently incorrect to insist that
6804 // the whole structure is defined. So in this case, just check it's
6806 switch ( *(vki_u32
*)ir
->vki_ifr_data
) {
6807 case VKI_ETHTOOL_GSET
:
6808 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,ir)",
6809 (Addr
)ir
, sizeof(struct vki_ifreq
) );
6812 PRE_MEM_READ( "ioctl(SIOCETHTOOL,ir)",
6813 (Addr
)ir
, sizeof(struct vki_ifreq
) );
6817 // Now perform the relevant pre-action for the operation.
6818 switch ( *(vki_u32
*)ir
->vki_ifr_data
) {
6819 case VKI_ETHTOOL_GSET
:
6820 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GSET)",
6821 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_cmd
) );
6823 case VKI_ETHTOOL_SSET
:
6824 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SSET)",
6825 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_cmd
) );
6827 case VKI_ETHTOOL_GDRVINFO
:
6828 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GDRVINFO)",
6829 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_drvinfo
) );
6831 case VKI_ETHTOOL_GREGS
:
6832 PRE_MEM_READ( "ioctl(SIOCETHTOOL,GREGS)",
6833 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_regs
) );
6834 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GREGS)",
6835 (Addr
)((struct vki_ethtool_regs
*)ir
->vki_ifr_data
)->data
,
6836 ((struct vki_ethtool_regs
*)ir
->vki_ifr_data
)->len
);
6838 case VKI_ETHTOOL_GWOL
:
6839 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GWOL)",
6840 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_wolinfo
) );
6842 case VKI_ETHTOOL_SWOL
:
6843 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SWOL)",
6844 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_wolinfo
) );
6846 case VKI_ETHTOOL_GMSGLVL
:
6847 case VKI_ETHTOOL_GLINK
:
6848 case VKI_ETHTOOL_GRXCSUM
:
6849 case VKI_ETHTOOL_GSG
:
6850 case VKI_ETHTOOL_GTSO
:
6851 case VKI_ETHTOOL_GUFO
:
6852 case VKI_ETHTOOL_GGSO
:
6853 case VKI_ETHTOOL_GFLAGS
:
6854 case VKI_ETHTOOL_GGRO
:
6855 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,Gvalue)",
6856 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_value
) );
6858 case VKI_ETHTOOL_SMSGLVL
:
6859 case VKI_ETHTOOL_SRXCSUM
:
6860 case VKI_ETHTOOL_SSG
:
6861 case VKI_ETHTOOL_STSO
:
6862 case VKI_ETHTOOL_SUFO
:
6863 case VKI_ETHTOOL_SGSO
:
6864 case VKI_ETHTOOL_SFLAGS
:
6865 case VKI_ETHTOOL_SGRO
:
6866 PRE_MEM_READ( "ioctl(SIOCETHTOOL,Svalue)",
6867 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_value
) );
6869 case VKI_ETHTOOL_NWAY_RST
:
6871 case VKI_ETHTOOL_GRINGPARAM
:
6872 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GRINGPARAM)",
6873 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_ringparam
) );
6875 case VKI_ETHTOOL_SRINGPARAM
:
6876 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SRINGPARAM)",
6877 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_ringparam
) );
6879 case VKI_ETHTOOL_TEST
:
6880 PRE_MEM_READ( "ioctl(SIOCETHTOOL,TEST)",
6881 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_test
) );
6882 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,TEST)",
6883 (Addr
)((struct vki_ethtool_test
*)ir
->vki_ifr_data
)->data
,
6884 ((struct vki_ethtool_test
*)ir
->vki_ifr_data
)->len
* sizeof(__vki_u64
) );
6886 case VKI_ETHTOOL_PHYS_ID
:
6888 case VKI_ETHTOOL_GPERMADDR
:
6889 PRE_MEM_READ( "ioctl(SIOCETHTOOL,GPERMADDR)",
6890 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_perm_addr
) );
6891 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GPERMADDR)",
6892 (Addr
)((struct vki_ethtool_perm_addr
*)ir
->vki_ifr_data
)->data
,
6893 ((struct vki_ethtool_perm_addr
*)ir
->vki_ifr_data
)->size
);
6895 case VKI_ETHTOOL_RESET
:
6897 case VKI_ETHTOOL_GSSET_INFO
:
6898 PRE_MEM_READ( "ioctl(SIOCETHTOOL,GSSET_INFO)",
6899 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_sset_info
) );
6900 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GSSET_INFO)",
6901 (Addr
)((struct vki_ethtool_sset_info
*)ir
->vki_ifr_data
)->data
,
6902 __builtin_popcountll(((struct vki_ethtool_sset_info
*)ir
->vki_ifr_data
)->sset_mask
) * sizeof(__vki_u32
) );
6904 case VKI_ETHTOOL_GFEATURES
:
6905 PRE_MEM_READ( "ioctl(SIOCETHTOOL,GFEATURES)",
6906 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_gfeatures
) );
6907 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GFEATURES)",
6908 (Addr
)((struct vki_ethtool_gfeatures
*)ir
->vki_ifr_data
)->features
,
6909 ((struct vki_ethtool_gfeatures
*)ir
->vki_ifr_data
)->size
* sizeof(struct vki_ethtool_get_features_block
) );
6911 case VKI_ETHTOOL_SFEATURES
:
6912 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SFEATURES)",
6913 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_sfeatures
) );
6914 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SFEATURES)",
6915 (Addr
)((struct vki_ethtool_sfeatures
*)ir
->vki_ifr_data
)->features
,
6916 ((struct vki_ethtool_sfeatures
*)ir
->vki_ifr_data
)->size
* sizeof(struct vki_ethtool_set_features_block
) );
6918 case VKI_ETHTOOL_GCHANNELS
:
6919 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GCHANNELS)",
6920 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_channels
) );
6922 case VKI_ETHTOOL_SCHANNELS
:
6923 PRE_MEM_READ( "ioctl(SIOCETHTOOL,SCHANNELS)",
6924 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_channels
) );
6926 case VKI_ETHTOOL_GET_TS_INFO
:
6927 PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GET_TS_INFO)",
6928 (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_ts_info
) );
6932 } /* case VKI_SIOCETHTOOL */
6934 case VKI_SIOCGMIIPHY
: /* get hardware entry */
6935 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIPHY)",
6936 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6937 PRE_MEM_WRITE( "ioctl(SIOCGIFMIIPHY)", ARG3
, sizeof(struct vki_ifreq
));
6939 case VKI_SIOCGMIIREG
: /* get hardware entry registers */
6940 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIREG)",
6941 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6942 PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)",
6943 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
,
6944 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
));
6945 PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)",
6946 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->reg_num
,
6947 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->reg_num
));
6948 PRE_MEM_WRITE( "ioctl(SIOCGIFMIIREG)", ARG3
,
6949 sizeof(struct vki_ifreq
));
6951 case VKI_SIOCGIFCONF
: /* get iface list */
6953 PRE_MEM_WRITE( "ioctl(SIOCGIFCONF)", ARG3, sizeof(struct ifconf));
6954 KERNEL_DO_SYSCALL(tid,RES);
6955 if (!VG_(is_kerror)(RES) && RES == 0)
6956 POST_MEM_WRITE(ARG3, sizeof(struct ifconf));
6958 PRE_MEM_READ( "ioctl(SIOCGIFCONF)",
6959 (Addr
)&((struct vki_ifconf
*)(Addr
)ARG3
)->ifc_len
,
6960 sizeof(((struct vki_ifconf
*)(Addr
)ARG3
)->ifc_len
));
6961 PRE_MEM_READ( "ioctl(SIOCGIFCONF)",
6962 (Addr
)&((struct vki_ifconf
*)(Addr
)ARG3
)->vki_ifc_buf
,
6963 sizeof(((struct vki_ifconf
*)(Addr
)ARG3
)->vki_ifc_buf
));
6965 // TODO len must be readable and writable
6966 // buf pointer only needs to be readable
6967 struct vki_ifconf
*ifc
= (struct vki_ifconf
*) (Addr
)ARG3
;
6968 PRE_MEM_WRITE( "ioctl(SIOCGIFCONF).ifc_buf",
6969 (Addr
)(ifc
->vki_ifc_buf
), ifc
->ifc_len
);
6972 case VKI_SIOCGSTAMP
:
6973 PRE_MEM_WRITE( "ioctl(SIOCGSTAMP)", ARG3
, sizeof(struct vki_timeval
));
6975 case VKI_SIOCGSTAMPNS
:
6976 PRE_MEM_WRITE( "ioctl(SIOCGSTAMPNS)", ARG3
, sizeof(struct vki_timespec
));
6978 /* SIOCOUTQ is an ioctl that, when called on a socket, returns
6979 the number of bytes currently in that socket's send buffer.
6980 It writes this value as an int to the memory location
6981 indicated by the third argument of ioctl(2). */
6983 PRE_MEM_WRITE( "ioctl(SIOCOUTQ)", ARG3
, sizeof(int));
6985 case VKI_SIOCGRARP
: /* get RARP table entry */
6986 case VKI_SIOCGARP
: /* get ARP table entry */
6987 PRE_MEM_WRITE( "ioctl(SIOCGARP)", ARG3
, sizeof(struct vki_arpreq
));
6990 case VKI_SIOCSIFFLAGS
: /* set flags */
6991 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFFLAGS)",
6992 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
6993 PRE_MEM_READ( "ioctl(SIOCSIFFLAGS)",
6994 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
,
6995 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
) );
6997 case VKI_SIOCSIFMAP
: /* Set device parameters */
6998 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMAP)",
6999 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7000 PRE_MEM_READ( "ioctl(SIOCSIFMAP)",
7001 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_map
,
7002 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_map
) );
7004 case VKI_SIOCSHWTSTAMP
: /* Set hardware time stamping */
7005 PRE_MEM_RASCIIZ( "ioctl(SIOCSHWTSTAMP)",
7006 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7007 PRE_MEM_READ( "ioctl(SIOCSHWTSTAMP)",
7008 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
,
7009 sizeof(struct vki_hwtstamp_config
) );
7011 case VKI_SIOCSIFTXQLEN
: /* Set the tx queue length */
7012 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFTXQLEN)",
7013 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7014 PRE_MEM_READ( "ioctl(SIOCSIFTXQLEN)",
7015 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_qlen
,
7016 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_qlen
) );
7018 case VKI_SIOCSIFADDR
: /* set PA address */
7019 case VKI_SIOCSIFDSTADDR
: /* set remote PA address */
7020 case VKI_SIOCSIFBRDADDR
: /* set broadcast PA address */
7021 case VKI_SIOCSIFNETMASK
: /* set network PA mask */
7022 PRE_MEM_RASCIIZ( "ioctl(SIOCSIF*ADDR)",
7023 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7024 PRE_MEM_READ( "ioctl(SIOCSIF*ADDR)",
7025 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_addr
,
7026 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_addr
) );
7028 case VKI_SIOCSIFMETRIC
: /* set metric */
7029 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMETRIC)",
7030 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7031 PRE_MEM_READ( "ioctl(SIOCSIFMETRIC)",
7032 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_metric
,
7033 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_metric
) );
7035 case VKI_SIOCSIFMTU
: /* set MTU size */
7036 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMTU)",
7037 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7038 PRE_MEM_READ( "ioctl(SIOCSIFMTU)",
7039 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_mtu
,
7040 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_mtu
) );
7042 case VKI_SIOCSIFHWADDR
: /* set hardware address */
7043 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFHWADDR)",
7044 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7045 PRE_MEM_READ( "ioctl(SIOCSIFHWADDR)",
7046 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_hwaddr
,
7047 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_hwaddr
) );
7049 case VKI_SIOCSMIIREG
: /* set hardware entry registers */
7050 PRE_MEM_RASCIIZ( "ioctl(SIOCSMIIREG)",
7051 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7052 PRE_MEM_READ( "ioctl(SIOCSMIIREG)",
7053 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
,
7054 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
));
7055 PRE_MEM_READ( "ioctl(SIOCSMIIREG)",
7056 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->reg_num
,
7057 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->reg_num
));
7058 PRE_MEM_READ( "ioctl(SIOCSMIIREG)",
7059 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->val_in
,
7060 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->val_in
));
7062 /* Routing table calls. */
7063 case VKI_SIOCADDRT
: /* add routing table entry */
7064 case VKI_SIOCDELRT
: /* delete routing table entry */
7065 PRE_MEM_READ( "ioctl(SIOCADDRT/DELRT)", ARG3
,
7066 sizeof(struct vki_rtentry
));
7069 /* tun/tap related ioctls */
7070 case VKI_TUNSETNOCSUM
:
7071 case VKI_TUNSETDEBUG
:
7074 PRE_MEM_RASCIIZ( "ioctl(TUNSETIFF)",
7075 (Addr
)((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
);
7076 PRE_MEM_READ( "ioctl(TUNSETIFF)",
7077 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
,
7078 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
) );
7079 PRE_MEM_WRITE( "ioctl(TUNSETIFF)", ARG3
, sizeof(struct vki_ifreq
) );
7081 case VKI_TUNSETPERSIST
:
7082 case VKI_TUNSETOWNER
:
7083 case VKI_TUNSETLINK
:
7084 case VKI_TUNSETGROUP
:
7086 case VKI_TUNGETFEATURES
:
7087 PRE_MEM_WRITE( "ioctl(TUNGETFEATURES)", ARG3
, sizeof(unsigned int) );
7089 case VKI_TUNSETOFFLOAD
:
7092 PRE_MEM_WRITE( "ioctl(TUNGETIFF)", ARG3
, sizeof(struct vki_ifreq
) );
7094 case VKI_TUNGETSNDBUF
:
7095 PRE_MEM_WRITE( "ioctl(TUNGETSNDBUF)", ARG3
, sizeof(int) );
7097 case VKI_TUNSETSNDBUF
:
7098 PRE_MEM_READ( "ioctl(TUNSETSNDBUF)", ARG3
, sizeof(int) );
7100 case VKI_TUNGETVNETHDRSZ
:
7101 PRE_MEM_WRITE( "ioctl(TUNGETVNETHDRSZ)", ARG3
, sizeof(int) );
7103 case VKI_TUNSETVNETHDRSZ
:
7104 PRE_MEM_READ( "ioctl(TUNSETVNETHDRSZ)", ARG3
, sizeof(int) );
7106 case VKI_TUNSETQUEUE
:
7107 PRE_MEM_READ( "ioctl(TUNSETQUEUE)",
7108 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
,
7109 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
) );
7111 case VKI_TUNSETIFINDEX
:
7112 PRE_MEM_READ( "ioctl(TUNSETIFINDEX)", ARG3
, sizeof(unsigned int));
7115 /* RARP cache control calls. */
7116 case VKI_SIOCDRARP
: /* delete RARP table entry */
7117 case VKI_SIOCSRARP
: /* set RARP table entry */
7118 /* ARP cache control calls. */
7119 case VKI_SIOCSARP
: /* set ARP table entry */
7120 case VKI_SIOCDARP
: /* delete ARP table entry */
7121 PRE_MEM_READ( "ioctl(SIOCSIFFLAGS)", ARG3
, sizeof(struct vki_ifreq
));
7125 PRE_MEM_WRITE( "ioctl(SIOCGPGRP)", ARG3
, sizeof(int) );
7128 PRE_MEM_READ( "ioctl(SIOCSPGRP)", ARG3
, sizeof(int) );
7129 //tst->sys_flags &= ~SfMayBlock;
7132 case VKI_SIOCATMARK
:
7133 PRE_MEM_READ( "ioctl(SIOCATMARK)", ARG3
, sizeof(int) );
7136 /* linux/soundcard interface (OSS) */
7137 case VKI_SNDCTL_SEQ_GETOUTCOUNT
:
7138 case VKI_SNDCTL_SEQ_GETINCOUNT
:
7139 case VKI_SNDCTL_SEQ_PERCMODE
:
7140 case VKI_SNDCTL_SEQ_TESTMIDI
:
7141 case VKI_SNDCTL_SEQ_RESETSAMPLES
:
7142 case VKI_SNDCTL_SEQ_NRSYNTHS
:
7143 case VKI_SNDCTL_SEQ_NRMIDIS
:
7144 case VKI_SNDCTL_SEQ_GETTIME
:
7145 case VKI_SNDCTL_DSP_GETBLKSIZE
:
7146 case VKI_SNDCTL_DSP_GETFMTS
:
7147 case VKI_SNDCTL_DSP_GETTRIGGER
:
7148 case VKI_SNDCTL_DSP_GETODELAY
:
7149 case VKI_SNDCTL_DSP_GETSPDIF
:
7150 case VKI_SNDCTL_DSP_GETCAPS
:
7151 case VKI_SOUND_PCM_READ_RATE
:
7152 case VKI_SOUND_PCM_READ_CHANNELS
:
7153 case VKI_SOUND_PCM_READ_BITS
:
7154 case VKI_SOUND_PCM_READ_FILTER
:
7155 PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOR, int))",
7158 case VKI_SNDCTL_SEQ_CTRLRATE
:
7159 case VKI_SNDCTL_DSP_SPEED
:
7160 case VKI_SNDCTL_DSP_STEREO
:
7161 case VKI_SNDCTL_DSP_CHANNELS
:
7162 case VKI_SOUND_PCM_WRITE_FILTER
:
7163 case VKI_SNDCTL_DSP_SUBDIVIDE
:
7164 case VKI_SNDCTL_DSP_SETFRAGMENT
:
7165 case VKI_SNDCTL_DSP_SETFMT
:
7166 case VKI_SNDCTL_DSP_GETCHANNELMASK
:
7167 case VKI_SNDCTL_DSP_BIND_CHANNEL
:
7168 case VKI_SNDCTL_TMR_TIMEBASE
:
7169 case VKI_SNDCTL_TMR_TEMPO
:
7170 case VKI_SNDCTL_TMR_SOURCE
:
7171 case VKI_SNDCTL_MIDI_PRETIME
:
7172 case VKI_SNDCTL_MIDI_MPUMODE
:
7173 PRE_MEM_READ( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOWR, int))",
7175 PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOWR, int))",
7178 case VKI_SNDCTL_DSP_GETOSPACE
:
7179 case VKI_SNDCTL_DSP_GETISPACE
:
7180 PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOR, audio_buf_info))",
7181 ARG3
, sizeof(vki_audio_buf_info
));
7183 case VKI_SNDCTL_DSP_NONBLOCK
:
7185 case VKI_SNDCTL_DSP_SETTRIGGER
:
7186 PRE_MEM_READ( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOW, int))",
7190 case VKI_SNDCTL_DSP_POST
:
7191 case VKI_SNDCTL_DSP_RESET
:
7192 case VKI_SNDCTL_DSP_SYNC
:
7193 case VKI_SNDCTL_DSP_SETSYNCRO
:
7194 case VKI_SNDCTL_DSP_SETDUPLEX
:
7197 /* linux/soundcard interface (ALSA) */
7198 case VKI_SNDRV_PCM_IOCTL_PAUSE
:
7199 case VKI_SNDRV_PCM_IOCTL_LINK
:
7200 /* these just take an int by value */
7202 case VKI_SNDRV_CTL_IOCTL_PVERSION
:
7203 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_PVERSION)", (Addr
)ARG3
, sizeof(int) );
7205 case VKI_SNDRV_CTL_IOCTL_CARD_INFO
:
7206 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_CARD_INFO)", (Addr
)ARG3
, sizeof(struct vki_snd_ctl_card_info
) );
7208 case VKI_SNDRV_CTL_IOCTL_ELEM_LIST
: {
7209 struct vki_snd_ctl_elem_list
*data
=
7210 (struct vki_snd_ctl_elem_list
*)(Addr
)ARG3
;
7211 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)&data
->offset
, sizeof(data
->offset
) );
7212 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)&data
->space
, sizeof(data
->space
) );
7213 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)&data
->used
, sizeof(data
->used
) );
7214 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)&data
->count
, sizeof(data
->count
) );
7215 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)&data
->pids
, sizeof(data
->pids
) );
7217 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr
)data
->pids
, sizeof(struct vki_snd_ctl_elem_id
) * data
->space
);
7221 case VKI_SNDRV_CTL_IOCTL_TLV_READ
: {
7222 struct vki_snd_ctl_tlv
*data
= (struct vki_snd_ctl_tlv
*)(Addr
)ARG3
;
7223 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_READ)", (Addr
)&data
->numid
, sizeof(data
->numid
) );
7224 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_READ)", (Addr
)&data
->length
, sizeof(data
->length
) );
7225 PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_TLV_READ)", (Addr
)data
->tlv
, data
->length
);
7228 case VKI_SNDRV_CTL_IOCTL_TLV_WRITE
:
7229 case VKI_SNDRV_CTL_IOCTL_TLV_COMMAND
: {
7230 struct vki_snd_ctl_tlv
*data
= (struct vki_snd_ctl_tlv
*)(Addr
)ARG3
;
7231 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_WRITE)", (Addr
)&data
->numid
, sizeof(data
->numid
) );
7232 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_WRITE)", (Addr
)&data
->length
, sizeof(data
->length
) );
7233 PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_WRITE)", (Addr
)data
->tlv
, data
->length
);
7237 /* Real Time Clock (/dev/rtc) ioctls */
7238 case VKI_RTC_UIE_ON
:
7239 case VKI_RTC_UIE_OFF
:
7240 case VKI_RTC_AIE_ON
:
7241 case VKI_RTC_AIE_OFF
:
7242 case VKI_RTC_PIE_ON
:
7243 case VKI_RTC_PIE_OFF
:
7244 case VKI_RTC_IRQP_SET
:
7246 case VKI_RTC_RD_TIME
:
7247 case VKI_RTC_ALM_READ
:
7248 PRE_MEM_WRITE( "ioctl(RTC_RD_TIME/ALM_READ)",
7249 ARG3
, sizeof(struct vki_rtc_time
));
7251 case VKI_RTC_ALM_SET
:
7252 PRE_MEM_READ( "ioctl(RTC_ALM_SET)", ARG3
, sizeof(struct vki_rtc_time
));
7254 case VKI_RTC_IRQP_READ
:
7255 PRE_MEM_WRITE( "ioctl(RTC_IRQP_READ)", ARG3
, sizeof(unsigned long));
7260 PRE_MEM_READ( "ioctl(BLKROSET)", ARG3
, sizeof(int));
7263 PRE_MEM_WRITE( "ioctl(BLKROGET)", ARG3
, sizeof(int));
7265 case VKI_BLKGETSIZE
:
7266 PRE_MEM_WRITE( "ioctl(BLKGETSIZE)", ARG3
, sizeof(unsigned long));
7273 PRE_MEM_WRITE( "ioctl(BLKRAGET)", ARG3
, sizeof(long));
7278 PRE_MEM_WRITE( "ioctl(BLKFRAGET)", ARG3
, sizeof(long));
7280 case VKI_BLKSECTGET
:
7281 PRE_MEM_WRITE( "ioctl(BLKSECTGET)", ARG3
, sizeof(unsigned short));
7284 PRE_MEM_WRITE( "ioctl(BLKSSZGET)", ARG3
, sizeof(int));
7287 PRE_MEM_WRITE( "ioctl(BLKBSZGET)", ARG3
, sizeof(int));
7290 PRE_MEM_READ( "ioctl(BLKBSZSET)", ARG3
, sizeof(int));
7292 case VKI_BLKGETSIZE64
:
7293 PRE_MEM_WRITE( "ioctl(BLKGETSIZE64)", ARG3
, sizeof(unsigned long long));
7295 case VKI_BLKPBSZGET
:
7296 PRE_MEM_WRITE( "ioctl(BLKPBSZGET)", ARG3
, sizeof(int));
7299 PRE_MEM_WRITE( "ioctl(BLKIOMIN)", ARG3
, sizeof(vki_uint
));
7302 PRE_MEM_WRITE( "ioctl(BLKIOOPT)", ARG3
, sizeof(vki_uint
));
7304 case VKI_BLKALIGNOFF
:
7305 PRE_MEM_WRITE( "ioctl(BLKALIGNOFF)", ARG3
, sizeof(int));
7307 case VKI_BLKDISCARDZEROES
:
7308 PRE_MEM_WRITE( "ioctl(BLKDISCARDZEROES)", ARG3
, sizeof(vki_uint
));
7310 case VKI_BLKREPORTZONE
:
7311 PRE_MEM_READ("ioctl(BLKREPORTZONE)", ARG3
,
7312 sizeof(struct vki_blk_zone_report
));
7314 case VKI_BLKRESETZONE
:
7315 PRE_MEM_READ("ioctl(BLKRESETZONE)", ARG3
,
7316 sizeof(struct vki_blk_zone_range
));
7320 case VKI_HDIO_GETGEO
: /* 0x0301 */
7321 PRE_MEM_WRITE( "ioctl(HDIO_GETGEO)", ARG3
, sizeof(struct vki_hd_geometry
));
7323 case VKI_HDIO_GET_DMA
: /* 0x030b */
7324 PRE_MEM_WRITE( "ioctl(HDIO_GET_DMA)", ARG3
, sizeof(long));
7326 case VKI_HDIO_GET_IDENTITY
: /* 0x030d */
7327 PRE_MEM_WRITE( "ioctl(HDIO_GET_IDENTITY)", ARG3
,
7328 VKI_SIZEOF_STRUCT_HD_DRIVEID
);
7332 case VKI_SCSI_IOCTL_GET_IDLUN
: /* 0x5382 */
7333 PRE_MEM_WRITE( "ioctl(SCSI_IOCTL_GET_IDLUN)", ARG3
, sizeof(struct vki_scsi_idlun
));
7335 case VKI_SCSI_IOCTL_GET_BUS_NUMBER
: /* 0x5386 */
7336 PRE_MEM_WRITE( "ioctl(SCSI_IOCTL_GET_BUS_NUMBER)", ARG3
, sizeof(int));
7339 /* CD ROM stuff (??) */
7340 case VKI_CDROM_GET_MCN
:
7341 PRE_MEM_READ( "ioctl(CDROM_GET_MCN)", ARG3
,
7342 sizeof(struct vki_cdrom_mcn
) );
7344 case VKI_CDROM_SEND_PACKET
:
7345 PRE_MEM_READ( "ioctl(CDROM_SEND_PACKET)", ARG3
,
7346 sizeof(struct vki_cdrom_generic_command
));
7348 case VKI_CDROMSUBCHNL
:
7349 PRE_MEM_READ( "ioctl(CDROMSUBCHNL (cdsc_format, char))",
7350 (Addr
) &(((struct vki_cdrom_subchnl
*) (Addr
)ARG3
)->cdsc_format
),
7351 sizeof(((struct vki_cdrom_subchnl
*) (Addr
)ARG3
)->cdsc_format
));
7352 PRE_MEM_WRITE( "ioctl(CDROMSUBCHNL)", ARG3
,
7353 sizeof(struct vki_cdrom_subchnl
));
7355 case VKI_CDROMREADMODE1
: /*0x530d*/
7356 PRE_MEM_READ("ioctl(CDROMREADMODE1)", ARG3
, VKI_CD_FRAMESIZE_RAW1
);
7357 PRE_MEM_WRITE("ioctl(CDROMREADMODE1)", ARG3
, VKI_CD_FRAMESIZE_RAW1
);
7359 case VKI_CDROMREADMODE2
: /*0x530c*/
7360 PRE_MEM_READ("ioctl(CDROMREADMODE2)", ARG3
, VKI_CD_FRAMESIZE_RAW0
);
7361 PRE_MEM_WRITE("ioctl(CDROMREADMODE2)", ARG3
, VKI_CD_FRAMESIZE_RAW0
);
7363 case VKI_CDROMREADTOCHDR
:
7364 PRE_MEM_WRITE( "ioctl(CDROMREADTOCHDR)", ARG3
,
7365 sizeof(struct vki_cdrom_tochdr
));
7367 case VKI_CDROMREADTOCENTRY
:
7368 PRE_MEM_READ( "ioctl(CDROMREADTOCENTRY (cdte_format, char))",
7369 (Addr
) &(((struct vki_cdrom_tocentry
*) (Addr
)ARG3
)->cdte_format
),
7370 sizeof(((struct vki_cdrom_tocentry
*) (Addr
)ARG3
)->cdte_format
));
7371 PRE_MEM_READ( "ioctl(CDROMREADTOCENTRY (cdte_track, char))",
7372 (Addr
) &(((struct vki_cdrom_tocentry
*) (Addr
)ARG3
)->cdte_track
),
7373 sizeof(((struct vki_cdrom_tocentry
*) (Addr
)ARG3
)->cdte_track
));
7374 PRE_MEM_WRITE( "ioctl(CDROMREADTOCENTRY)", ARG3
,
7375 sizeof(struct vki_cdrom_tocentry
));
7377 case VKI_CDROMMULTISESSION
: /* 0x5310 */
7378 PRE_MEM_WRITE( "ioctl(CDROMMULTISESSION)", ARG3
,
7379 sizeof(struct vki_cdrom_multisession
));
7381 case VKI_CDROMVOLREAD
: /* 0x5313 */
7382 PRE_MEM_WRITE( "ioctl(CDROMVOLREAD)", ARG3
,
7383 sizeof(struct vki_cdrom_volctrl
));
7385 case VKI_CDROMREADRAW
: /* 0x5314 */
7386 PRE_MEM_READ( "ioctl(CDROMREADRAW)", ARG3
, sizeof(struct vki_cdrom_msf
));
7387 PRE_MEM_WRITE( "ioctl(CDROMREADRAW)", ARG3
, VKI_CD_FRAMESIZE_RAW
);
7389 case VKI_CDROMREADAUDIO
: /* 0x530e */
7390 PRE_MEM_READ( "ioctl(CDROMREADAUDIO)", ARG3
,
7391 sizeof (struct vki_cdrom_read_audio
));
7393 /* ToDo: don't do any of the following if the structure is invalid */
7394 struct vki_cdrom_read_audio
*cra
=
7395 (struct vki_cdrom_read_audio
*) (Addr
)ARG3
;
7396 PRE_MEM_WRITE( "ioctl(CDROMREADAUDIO).buf",
7397 (Addr
)(cra
->buf
), cra
->nframes
* VKI_CD_FRAMESIZE_RAW
);
7400 case VKI_CDROMPLAYMSF
:
7401 PRE_MEM_READ( "ioctl(CDROMPLAYMSF)", ARG3
, sizeof(struct vki_cdrom_msf
));
7403 /* The following two are probably bogus (should check args
7404 for readability). JRS 20021117 */
7405 case VKI_CDROM_DRIVE_STATUS
: /* 0x5326 */
7406 case VKI_CDROM_CLEAR_OPTIONS
: /* 0x5321 */
7408 case VKI_CDROM_GET_CAPABILITY
: /* 0x5331 */
7412 PRE_MEM_WRITE( "ioctl(FIGETBSZ)", ARG3
, sizeof(unsigned long));
7415 PRE_MEM_READ( "ioctl(FIBMAP)", ARG3
, sizeof(int));
7418 case VKI_FBIOGET_VSCREENINFO
: /* 0x4600 */
7419 PRE_MEM_WRITE( "ioctl(FBIOGET_VSCREENINFO)", ARG3
,
7420 sizeof(struct vki_fb_var_screeninfo
));
7422 case VKI_FBIOPUT_VSCREENINFO
:
7423 PRE_MEM_READ( "ioctl(FBIOPUT_VSCREENINFO)", ARG3
,
7424 sizeof(struct vki_fb_var_screeninfo
));
7426 case VKI_FBIOGET_FSCREENINFO
: /* 0x4602 */
7427 PRE_MEM_WRITE( "ioctl(FBIOGET_FSCREENINFO)", ARG3
,
7428 sizeof(struct vki_fb_fix_screeninfo
));
7430 case VKI_FBIOPAN_DISPLAY
:
7431 PRE_MEM_READ( "ioctl(FBIOPAN_DISPLAY)", ARG3
,
7432 sizeof(struct vki_fb_var_screeninfo
));
7441 PRE_MEM_READ( "ioctl(PPSETMODE)", ARG3
, sizeof(int) );
7444 PRE_MEM_WRITE( "ioctl(PPGETMODE)", ARG3
, sizeof(int) );
7446 case VKI_PPSETPHASE
:
7447 PRE_MEM_READ( "ioctl(PPSETPHASE)", ARG3
, sizeof(int) );
7449 case VKI_PPGETPHASE
:
7450 PRE_MEM_WRITE( "ioctl(PPGETPHASE)", ARG3
, sizeof(int) );
7452 case VKI_PPGETMODES
:
7453 PRE_MEM_WRITE( "ioctl(PPGETMODES)", ARG3
, sizeof(unsigned int) );
7455 case VKI_PPSETFLAGS
:
7456 PRE_MEM_READ( "ioctl(PPSETFLAGS)", ARG3
, sizeof(int) );
7458 case VKI_PPGETFLAGS
:
7459 PRE_MEM_WRITE( "ioctl(PPGETFLAGS)", ARG3
, sizeof(int) );
7462 PRE_MEM_WRITE( "ioctl(PPRSTATUS)", ARG3
, sizeof(unsigned char) );
7465 PRE_MEM_WRITE( "ioctl(PPRDATA)", ARG3
, sizeof(unsigned char) );
7467 case VKI_PPRCONTROL
:
7468 PRE_MEM_WRITE( "ioctl(PPRCONTROL)", ARG3
, sizeof(unsigned char) );
7471 PRE_MEM_READ( "ioctl(PPWDATA)", ARG3
, sizeof(unsigned char) );
7473 case VKI_PPWCONTROL
:
7474 PRE_MEM_READ( "ioctl(PPWCONTROL)", ARG3
, sizeof(unsigned char) );
7476 case VKI_PPFCONTROL
:
7477 PRE_MEM_READ( "ioctl(PPFCONTROL)", ARG3
, 2 * sizeof(unsigned char) );
7480 PRE_MEM_READ( "ioctl(PPDATADIR)", ARG3
, sizeof(int) );
7483 PRE_MEM_READ( "ioctl(PPNEGOT)", ARG3
, sizeof(int) );
7485 case VKI_PPWCTLONIRQ
:
7486 PRE_MEM_READ( "ioctl(PPWCTLONIRQ)",ARG3
, sizeof(unsigned char) );
7489 PRE_MEM_WRITE( "ioctl(PPCLRIRQ)", ARG3
, sizeof(int) );
7492 PRE_MEM_READ( "ioctl(PPSETTIME)", ARG3
, sizeof(struct vki_timeval
) );
7495 PRE_MEM_WRITE( "ioctl(PPGETTIME)", ARG3
, sizeof(struct vki_timeval
) );
7499 PRE_MEM_WRITE( "ioctl(GIO_FONT)", ARG3
, 32 * 256 );
7502 PRE_MEM_READ( "ioctl(PIO_FONT)", ARG3
, 32 * 256 );
7506 PRE_MEM_READ( "ioctl(GIO_FONTX)", ARG3
, sizeof(struct vki_consolefontdesc
) );
7508 /* ToDo: don't do any of the following if the structure is invalid */
7509 struct vki_consolefontdesc
*cfd
=
7510 (struct vki_consolefontdesc
*)(Addr
)ARG3
;
7511 PRE_MEM_WRITE( "ioctl(GIO_FONTX).chardata", (Addr
)cfd
->chardata
,
7512 32 * cfd
->charcount
);
7516 PRE_MEM_READ( "ioctl(PIO_FONTX)", ARG3
, sizeof(struct vki_consolefontdesc
) );
7518 /* ToDo: don't do any of the following if the structure is invalid */
7519 struct vki_consolefontdesc
*cfd
=
7520 (struct vki_consolefontdesc
*)(Addr
)ARG3
;
7521 PRE_MEM_READ( "ioctl(PIO_FONTX).chardata", (Addr
)cfd
->chardata
,
7522 32 * cfd
->charcount
);
7526 case VKI_PIO_FONTRESET
:
7530 PRE_MEM_WRITE( "ioctl(GIO_CMAP)", ARG3
, 16 * 3 );
7533 PRE_MEM_READ( "ioctl(PIO_CMAP)", ARG3
, 16 * 3 );
7541 PRE_MEM_WRITE( "ioctl(KDGETLED)", ARG3
, sizeof(char) );
7547 PRE_MEM_WRITE( "ioctl(KDGKBTYPE)", ARG3
, sizeof(char) );
7559 PRE_MEM_WRITE( "ioctl(KDGETMODE)", ARG3
, sizeof(int) );
7563 case VKI_KDUNMAPDISP
:
7566 case VKI_GIO_SCRNMAP
:
7567 PRE_MEM_WRITE( "ioctl(GIO_SCRNMAP)", ARG3
, VKI_E_TABSZ
);
7569 case VKI_PIO_SCRNMAP
:
7570 PRE_MEM_READ( "ioctl(PIO_SCRNMAP)", ARG3
, VKI_E_TABSZ
);
7572 case VKI_GIO_UNISCRNMAP
:
7573 PRE_MEM_WRITE( "ioctl(GIO_UNISCRNMAP)", ARG3
,
7574 VKI_E_TABSZ
* sizeof(unsigned short) );
7576 case VKI_PIO_UNISCRNMAP
:
7577 PRE_MEM_READ( "ioctl(PIO_UNISCRNMAP)", ARG3
,
7578 VKI_E_TABSZ
* sizeof(unsigned short) );
7581 case VKI_GIO_UNIMAP
:
7583 struct vki_unimapdesc
*desc
= (struct vki_unimapdesc
*) (Addr
)ARG3
;
7584 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr
)&desc
->entry_ct
,
7585 sizeof(unsigned short));
7586 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr
)&desc
->entries
,
7587 sizeof(struct vki_unipair
*));
7588 PRE_MEM_WRITE( "ioctl(GIO_UNIMAP).entries", (Addr
)desc
->entries
,
7589 desc
->entry_ct
* sizeof(struct vki_unipair
));
7592 case VKI_PIO_UNIMAP
:
7594 struct vki_unimapdesc
*desc
= (struct vki_unimapdesc
*) (Addr
)ARG3
;
7595 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr
)&desc
->entry_ct
,
7596 sizeof(unsigned short) );
7597 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr
)&desc
->entries
,
7598 sizeof(struct vki_unipair
*) );
7599 PRE_MEM_READ( "ioctl(PIO_UNIMAP).entries", (Addr
)desc
->entries
,
7600 desc
->entry_ct
* sizeof(struct vki_unipair
) );
7603 case VKI_PIO_UNIMAPCLR
:
7604 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", ARG3
, sizeof(struct vki_unimapinit
));
7608 PRE_MEM_WRITE( "ioctl(KDGKBMODE)", ARG3
, sizeof(int) );
7614 PRE_MEM_WRITE( "ioctl(KDGKBMETA)", ARG3
, sizeof(int) );
7620 PRE_MEM_WRITE( "ioctl(KDGKBLED)", ARG3
, sizeof(char) );
7626 PRE_MEM_READ( "ioctl(KDGKBENT).kb_table",
7627 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_table
,
7628 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_table
) );
7629 PRE_MEM_READ( "ioctl(KDGKBENT).kb_index",
7630 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_index
,
7631 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_index
) );
7632 PRE_MEM_WRITE( "ioctl(KDGKBENT).kb_value",
7633 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
,
7634 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
) );
7637 PRE_MEM_READ( "ioctl(KDSKBENT).kb_table",
7638 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_table
,
7639 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_table
) );
7640 PRE_MEM_READ( "ioctl(KDSKBENT).kb_index",
7641 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_index
,
7642 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_index
) );
7643 PRE_MEM_READ( "ioctl(KDSKBENT).kb_value",
7644 (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
,
7645 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
) );
7649 PRE_MEM_READ( "ioctl(KDGKBSENT).kb_func",
7650 (Addr
)&((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_func
,
7651 sizeof(((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_func
) );
7652 PRE_MEM_WRITE( "ioctl(KDGKSENT).kb_string",
7653 (Addr
)((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_string
,
7654 sizeof(((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_string
) );
7657 PRE_MEM_READ( "ioctl(KDSKBSENT).kb_func",
7658 (Addr
)&((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_func
,
7659 sizeof(((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_func
) );
7660 PRE_MEM_RASCIIZ( "ioctl(KDSKBSENT).kb_string",
7661 (Addr
)((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_string
);
7664 case VKI_KDGKBDIACR
:
7665 PRE_MEM_WRITE( "ioctl(KDGKBDIACR)", ARG3
, sizeof(struct vki_kbdiacrs
) );
7667 case VKI_KDSKBDIACR
:
7668 PRE_MEM_READ( "ioctl(KDSKBDIACR)", ARG3
, sizeof(struct vki_kbdiacrs
) );
7671 case VKI_KDGETKEYCODE
:
7672 PRE_MEM_READ( "ioctl(KDGETKEYCODE).scancode",
7673 (Addr
)&((struct vki_kbkeycode
*)(Addr
)ARG3
)->scancode
,
7674 sizeof(((struct vki_kbkeycode
*)(Addr
)ARG3
)->scancode
) );
7675 PRE_MEM_WRITE( "ioctl(KDGETKEYCODE).keycode",
7676 (Addr
)((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
,
7677 sizeof(((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
) );
7679 case VKI_KDSETKEYCODE
:
7680 PRE_MEM_READ( "ioctl(KDSETKEYCODE).scancode",
7681 (Addr
)&((struct vki_kbkeycode
*)(Addr
)ARG3
)->scancode
,
7682 sizeof(((struct vki_kbkeycode
*)(Addr
)ARG3
)->scancode
) );
7683 PRE_MEM_READ( "ioctl(KDSETKEYCODE).keycode",
7684 (Addr
)((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
,
7685 sizeof(((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
) );
7688 case VKI_KDSIGACCEPT
:
7692 PRE_MEM_READ( "ioctl(KBKBDREP)", ARG3
, sizeof(struct vki_kbd_repeat
) );
7697 struct vki_console_font_op
*op
=
7698 (struct vki_console_font_op
*) (Addr
)ARG3
;
7699 PRE_MEM_READ( "ioctl(KDFONTOP)", (Addr
)op
,
7700 sizeof(struct vki_console_font_op
) );
7702 case VKI_KD_FONT_OP_SET
:
7703 PRE_MEM_READ( "ioctl(KDFONTOP,KD_FONT_OP_SET).data",
7705 (op
->width
+ 7) / 8 * 32 * op
->charcount
);
7707 case VKI_KD_FONT_OP_GET
:
7709 PRE_MEM_WRITE( "ioctl(KDFONTOP,KD_FONT_OP_GET).data",
7711 (op
->width
+ 7) / 8 * 32 * op
->charcount
);
7713 case VKI_KD_FONT_OP_SET_DEFAULT
:
7715 PRE_MEM_RASCIIZ( "ioctl(KDFONTOP,KD_FONT_OP_SET_DEFAULT).data",
7718 case VKI_KD_FONT_OP_COPY
:
7724 case VKI_VT_OPENQRY
:
7725 PRE_MEM_WRITE( "ioctl(VT_OPENQRY)", ARG3
, sizeof(int) );
7727 case VKI_VT_GETMODE
:
7728 PRE_MEM_WRITE( "ioctl(VT_GETMODE)", ARG3
, sizeof(struct vki_vt_mode
) );
7730 case VKI_VT_SETMODE
:
7731 PRE_MEM_READ( "ioctl(VT_SETMODE)", ARG3
, sizeof(struct vki_vt_mode
) );
7733 case VKI_VT_GETSTATE
:
7734 PRE_MEM_WRITE( "ioctl(VT_GETSTATE).v_active",
7735 (Addr
) &(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_active
),
7736 sizeof(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_active
));
7737 PRE_MEM_WRITE( "ioctl(VT_GETSTATE).v_state",
7738 (Addr
) &(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_state
),
7739 sizeof(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_state
));
7741 case VKI_VT_RELDISP
:
7742 case VKI_VT_ACTIVATE
:
7743 case VKI_VT_WAITACTIVE
:
7744 case VKI_VT_DISALLOCATE
:
7747 PRE_MEM_READ( "ioctl(VT_RESIZE)", ARG3
, sizeof(struct vki_vt_sizes
) );
7749 case VKI_VT_RESIZEX
:
7750 PRE_MEM_READ( "ioctl(VT_RESIZEX)", ARG3
, sizeof(struct vki_vt_consize
) );
7752 case VKI_VT_LOCKSWITCH
:
7753 case VKI_VT_UNLOCKSWITCH
:
7756 case VKI_USBDEVFS_CONTROL
:
7758 struct vki_usbdevfs_ctrltransfer
*vkuc
=
7759 (struct vki_usbdevfs_ctrltransfer
*)(Addr
)ARG3
;
7760 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).bRequestType", (Addr
)&vkuc
->bRequestType
, sizeof(vkuc
->bRequestType
));
7761 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).bRequest", (Addr
)&vkuc
->bRequest
, sizeof(vkuc
->bRequest
));
7762 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wValue", (Addr
)&vkuc
->wValue
, sizeof(vkuc
->wValue
));
7763 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wIndex", (Addr
)&vkuc
->wIndex
, sizeof(vkuc
->wIndex
));
7764 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wLength", (Addr
)&vkuc
->wLength
, sizeof(vkuc
->wLength
));
7765 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).timeout", (Addr
)&vkuc
->timeout
, sizeof(vkuc
->timeout
));
7766 if (vkuc
->bRequestType
& 0x80)
7767 PRE_MEM_WRITE( "ioctl(USBDEVFS_CONTROL).data", (Addr
)vkuc
->data
, vkuc
->wLength
);
7769 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).data", (Addr
)vkuc
->data
, vkuc
->wLength
);
7772 case VKI_USBDEVFS_BULK
:
7774 struct vki_usbdevfs_bulktransfer
*vkub
=
7775 (struct vki_usbdevfs_bulktransfer
*)(Addr
)ARG3
;
7776 PRE_MEM_READ( "ioctl(USBDEVFS_BULK)", ARG3
, sizeof(struct vki_usbdevfs_bulktransfer
));
7777 if (vkub
->ep
& 0x80)
7778 PRE_MEM_WRITE( "ioctl(USBDEVFS_BULK).data", (Addr
)vkub
->data
, vkub
->len
);
7780 PRE_MEM_READ( "ioctl(USBDEVFS_BULK).data", (Addr
)vkub
->data
, vkub
->len
);
7783 case VKI_USBDEVFS_GETDRIVER
:
7785 struct vki_usbdevfs_getdriver
*vkugd
=
7786 (struct vki_usbdevfs_getdriver
*) (Addr
)ARG3
;
7787 PRE_MEM_WRITE( "ioctl(USBDEVFS_GETDRIVER)", (Addr
)&vkugd
->driver
, sizeof(vkugd
->driver
));
7790 case VKI_USBDEVFS_SUBMITURB
:
7792 struct vki_usbdevfs_urb
*vkuu
= (struct vki_usbdevfs_urb
*)(Addr
)ARG3
;
7794 /* Not the whole struct needs to be initialized */
7795 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).endpoint", (Addr
)&vkuu
->endpoint
, sizeof(vkuu
->endpoint
));
7796 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).type", (Addr
)&vkuu
->type
, sizeof(vkuu
->type
));
7797 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).flags", (Addr
)&vkuu
->flags
, sizeof(vkuu
->flags
));
7798 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr
)&vkuu
->buffer
, sizeof(vkuu
->buffer
));
7799 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).signr", (Addr
)&vkuu
->signr
, sizeof(vkuu
->signr
));
7800 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).status", (Addr
)&vkuu
->status
, sizeof(vkuu
->status
));
7801 if (vkuu
->type
== VKI_USBDEVFS_URB_TYPE_CONTROL
) {
7802 struct vki_usbdevfs_setuppacket
*vkusp
= (struct vki_usbdevfs_setuppacket
*)vkuu
->buffer
;
7803 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr
)&vkuu
->buffer_length
, sizeof(vkuu
->buffer_length
));
7804 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer.setup_packet", (Addr
)vkusp
, sizeof(*vkusp
));
7805 if (vkusp
->bRequestType
& 0x80)
7806 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer.data", (Addr
)(vkusp
+1), vkuu
->buffer_length
- sizeof(*vkusp
));
7808 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer.data", (Addr
)(vkusp
+1), vkuu
->buffer_length
- sizeof(*vkusp
));
7809 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).actual_length", (Addr
)&vkuu
->actual_length
, sizeof(vkuu
->actual_length
));
7810 } else if (vkuu
->type
== VKI_USBDEVFS_URB_TYPE_ISO
) {
7811 int total_length
= 0;
7813 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).number_of_packets", (Addr
)&vkuu
->number_of_packets
, sizeof(vkuu
->number_of_packets
));
7814 for(i
=0; i
<vkuu
->number_of_packets
; i
++) {
7815 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].length", (Addr
)&vkuu
->iso_frame_desc
[i
].length
, sizeof(vkuu
->iso_frame_desc
[i
].length
));
7816 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
));
7817 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].status", (Addr
)&vkuu
->iso_frame_desc
[i
].status
, sizeof(vkuu
->iso_frame_desc
[i
].status
));
7818 total_length
+= vkuu
->iso_frame_desc
[i
].length
;
7820 if (vkuu
->endpoint
& 0x80)
7821 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr
)vkuu
->buffer
, total_length
);
7823 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr
)vkuu
->buffer
, total_length
);
7824 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).error_count", (Addr
)&vkuu
->error_count
, sizeof(vkuu
->error_count
));
7826 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr
)&vkuu
->buffer_length
, sizeof(vkuu
->buffer_length
));
7827 if (vkuu
->endpoint
& 0x80)
7828 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr
)vkuu
->buffer
, vkuu
->buffer_length
);
7830 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr
)vkuu
->buffer
, vkuu
->buffer_length
);
7831 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).actual_length", (Addr
)&vkuu
->actual_length
, sizeof(vkuu
->actual_length
));
7835 case VKI_USBDEVFS_DISCARDURB
:
7837 case VKI_USBDEVFS_REAPURB
:
7839 PRE_MEM_WRITE( "ioctl(USBDEVFS_REAPURB)", ARG3
, sizeof(struct vki_usbdevfs_urb
**));
7842 case VKI_USBDEVFS_REAPURBNDELAY
:
7844 PRE_MEM_WRITE( "ioctl(USBDEVFS_REAPURBNDELAY)", ARG3
, sizeof(struct vki_usbdevfs_urb
**));
7847 case VKI_USBDEVFS_CONNECTINFO
:
7848 PRE_MEM_WRITE( "ioctl(USBDEVFS_CONNECTINFO)", ARG3
, sizeof(struct vki_usbdevfs_connectinfo
));
7850 case VKI_USBDEVFS_IOCTL
:
7852 struct vki_usbdevfs_ioctl
*vkui
=
7853 (struct vki_usbdevfs_ioctl
*)(Addr
)ARG3
;
7855 PRE_MEM_READ("ioctl(USBDEVFS_IOCTL)", (Addr
)vkui
, sizeof(struct vki_usbdevfs_ioctl
));
7856 dir2
= _VKI_IOC_DIR(vkui
->ioctl_code
);
7857 size2
= _VKI_IOC_SIZE(vkui
->ioctl_code
);
7859 if (dir2
& _VKI_IOC_WRITE
)
7860 PRE_MEM_READ("ioctl(USBDEVFS_IOCTL).dataWrite", (Addr
)vkui
->data
, size2
);
7861 else if (dir2
& _VKI_IOC_READ
)
7862 PRE_MEM_WRITE("ioctl(USBDEVFS_IOCTL).dataRead", (Addr
)vkui
->data
, size2
);
7866 case VKI_USBDEVFS_RESET
:
7869 /* I2C (/dev/i2c-*) ioctls */
7871 case VKI_I2C_SLAVE_FORCE
:
7872 case VKI_I2C_TENBIT
:
7876 PRE_MEM_WRITE( "ioctl(I2C_FUNCS)", ARG3
, sizeof(unsigned long) );
7880 struct vki_i2c_rdwr_ioctl_data
*vkui
=
7881 (struct vki_i2c_rdwr_ioctl_data
*)(Addr
)ARG3
;
7883 PRE_MEM_READ("ioctl(I2C_RDWR)", (Addr
)vkui
, sizeof(struct vki_i2c_rdwr_ioctl_data
));
7884 for (i
=0; i
< vkui
->nmsgs
; i
++) {
7885 struct vki_i2c_msg
*msg
= vkui
->msgs
+ i
;
7886 PRE_MEM_READ("ioctl(I2C_RDWR).msgs", (Addr
)msg
, sizeof(struct vki_i2c_msg
));
7887 if (msg
->flags
& VKI_I2C_M_RD
)
7888 PRE_MEM_WRITE("ioctl(I2C_RDWR).msgs.buf", (Addr
)msg
->buf
, msg
->len
);
7890 PRE_MEM_READ("ioctl(I2C_RDWR).msgs.buf", (Addr
)msg
->buf
, msg
->len
);
7896 struct vki_i2c_smbus_ioctl_data
*vkis
7897 = (struct vki_i2c_smbus_ioctl_data
*) (Addr
)ARG3
;
7898 PRE_MEM_READ("ioctl(VKI_I2C_SMBUS).i2c_smbus_ioctl_data.read_write",
7899 (Addr
)&vkis
->read_write
, sizeof(vkis
->read_write
));
7900 PRE_MEM_READ("ioctl(VKI_I2C_SMBUS).i2c_smbus_ioctl_data.size",
7901 (Addr
)&vkis
->size
, sizeof(vkis
->size
));
7902 PRE_MEM_READ("ioctl(VKI_I2C_SMBUS).i2c_smbus_ioctl_data.command",
7903 (Addr
)&vkis
->command
, sizeof(vkis
->command
));
7904 /* i2c_smbus_write_quick hides its value in read_write, so
7905 this variable can have a different meaning */
7906 /* to make matters worse i2c_smbus_write_byte stores its
7908 if ( ! ((vkis
->size
== VKI_I2C_SMBUS_QUICK
) ||
7909 ((vkis
->size
== VKI_I2C_SMBUS_BYTE
)
7910 && (vkis
->read_write
== VKI_I2C_SMBUS_WRITE
)))) {
7911 /* the rest uses the byte array to store the data,
7912 some the first byte for size */
7914 switch(vkis
->size
) {
7915 case VKI_I2C_SMBUS_BYTE_DATA
:
7918 case VKI_I2C_SMBUS_WORD_DATA
:
7919 case VKI_I2C_SMBUS_PROC_CALL
:
7922 case VKI_I2C_SMBUS_BLOCK_DATA
:
7923 case VKI_I2C_SMBUS_I2C_BLOCK_BROKEN
:
7924 case VKI_I2C_SMBUS_BLOCK_PROC_CALL
:
7925 case VKI_I2C_SMBUS_I2C_BLOCK_DATA
:
7926 size
= 1 + vkis
->data
->block
[0];
7932 if ((vkis
->read_write
== VKI_I2C_SMBUS_READ
)
7933 || (vkis
->size
== VKI_I2C_SMBUS_PROC_CALL
)
7934 || (vkis
->size
== VKI_I2C_SMBUS_BLOCK_PROC_CALL
))
7935 PRE_MEM_WRITE("ioctl(VKI_I2C_SMBUS)"
7936 ".i2c_smbus_ioctl_data.data",
7937 (Addr
)&vkis
->data
->block
[0], size
);
7939 PRE_MEM_READ("ioctl(VKI_I2C_SMBUS)."
7940 "i2c_smbus_ioctl_data.data",
7941 (Addr
)&vkis
->data
->block
[0], size
);
7946 /* Wireless extensions ioctls */
7947 case VKI_SIOCSIWCOMMIT
:
7948 case VKI_SIOCSIWNWID
:
7949 case VKI_SIOCSIWFREQ
:
7950 case VKI_SIOCSIWMODE
:
7951 case VKI_SIOCSIWSENS
:
7952 case VKI_SIOCSIWRANGE
:
7953 case VKI_SIOCSIWPRIV
:
7954 case VKI_SIOCSIWSTATS
:
7955 case VKI_SIOCSIWSPY
:
7956 case VKI_SIOCSIWTHRSPY
:
7958 case VKI_SIOCSIWSCAN
:
7959 case VKI_SIOCSIWESSID
:
7960 case VKI_SIOCSIWRATE
:
7961 case VKI_SIOCSIWNICKN
:
7962 case VKI_SIOCSIWRTS
:
7963 case VKI_SIOCSIWFRAG
:
7964 case VKI_SIOCSIWTXPOW
:
7965 case VKI_SIOCSIWRETRY
:
7966 case VKI_SIOCSIWENCODE
:
7967 case VKI_SIOCSIWPOWER
:
7968 case VKI_SIOCSIWGENIE
:
7969 case VKI_SIOCSIWMLME
:
7970 case VKI_SIOCSIWAUTH
:
7971 case VKI_SIOCSIWENCODEEXT
:
7972 case VKI_SIOCSIWPMKSA
:
7974 case VKI_SIOCGIWNAME
:
7976 PRE_MEM_WRITE("ioctl(SIOCGIWNAME)",
7977 (Addr
)((struct vki_iwreq
*)(Addr
)ARG3
)->u
.name
,
7978 sizeof(((struct vki_iwreq
*)(Addr
)ARG3
)->u
.name
));
7981 case VKI_SIOCGIWNWID
:
7982 case VKI_SIOCGIWSENS
:
7983 case VKI_SIOCGIWRATE
:
7984 case VKI_SIOCGIWRTS
:
7985 case VKI_SIOCGIWFRAG
:
7986 case VKI_SIOCGIWTXPOW
:
7987 case VKI_SIOCGIWRETRY
:
7988 case VKI_SIOCGIWPOWER
:
7989 case VKI_SIOCGIWAUTH
:
7991 PRE_MEM_WRITE("ioctl(SIOCGIW[NWID|SENS|RATE|RTS|FRAG|TXPOW|"
7992 "RETRY|PARAM|AUTH])",
7993 (Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.nwid
,
7994 sizeof(struct vki_iw_param
));
7997 case VKI_SIOCGIWFREQ
:
7999 PRE_MEM_WRITE("ioctl(SIOCGIWFREQ",
8000 (Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.freq
,
8001 sizeof(struct vki_iw_freq
));
8004 case VKI_SIOCGIWMODE
:
8006 PRE_MEM_WRITE("ioctl(SIOCGIWMODE",
8007 (Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.mode
,
8011 case VKI_SIOCGIWRANGE
:
8012 case VKI_SIOCGIWPRIV
:
8013 case VKI_SIOCGIWSTATS
:
8014 case VKI_SIOCGIWSPY
:
8015 case VKI_SIOCGIWTHRSPY
:
8016 case VKI_SIOCGIWAPLIST
:
8017 case VKI_SIOCGIWSCAN
:
8018 case VKI_SIOCGIWESSID
:
8019 case VKI_SIOCGIWNICKN
:
8020 case VKI_SIOCGIWENCODE
:
8021 case VKI_SIOCGIWGENIE
:
8022 case VKI_SIOCGIWENCODEEXT
:
8024 struct vki_iw_point
* point
;
8025 point
= &((struct vki_iwreq
*)(Addr
)ARG3
)->u
.data
;
8026 PRE_MEM_WRITE("ioctl(SIOCGIW[RANGE|PRIV|STATS|SPY|THRSPY|"
8027 "APLIST|SCAN|ESSID|NICKN|ENCODE|GENIE|ENCODEEXT])",
8028 (Addr
)point
->pointer
, point
->length
);
8033 PRE_MEM_WRITE("ioctl(SIOCGIWAP)",
8034 (Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.ap_addr
,
8035 sizeof(struct vki_sockaddr
));
8039 /* User input device creation */
8040 case VKI_UI_SET_EVBIT
:
8041 case VKI_UI_SET_KEYBIT
:
8042 case VKI_UI_SET_RELBIT
:
8043 case VKI_UI_SET_ABSBIT
:
8044 case VKI_UI_SET_MSCBIT
:
8045 case VKI_UI_SET_LEDBIT
:
8046 case VKI_UI_SET_SNDBIT
:
8047 case VKI_UI_SET_FFBIT
:
8048 case VKI_UI_SET_SWBIT
:
8049 case VKI_UI_SET_PROPBIT
:
8050 /* These just take an int by value */
8053 # if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
8054 || defined(VGPV_mips32_linux_android) \
8055 || defined(VGPV_arm64_linux_android)
8057 case VKI_ASHMEM_GET_SIZE
:
8058 case VKI_ASHMEM_SET_SIZE
:
8059 case VKI_ASHMEM_GET_PROT_MASK
:
8060 case VKI_ASHMEM_SET_PROT_MASK
:
8061 case VKI_ASHMEM_GET_PIN_STATUS
:
8062 case VKI_ASHMEM_PURGE_ALL_CACHES
:
8064 case VKI_ASHMEM_GET_NAME
:
8065 PRE_MEM_WRITE( "ioctl(ASHMEM_SET_NAME)", ARG3
, VKI_ASHMEM_NAME_LEN
);
8067 case VKI_ASHMEM_SET_NAME
:
8068 PRE_MEM_RASCIIZ( "ioctl(ASHMEM_SET_NAME)", ARG3
);
8070 case VKI_ASHMEM_PIN
:
8071 case VKI_ASHMEM_UNPIN
:
8072 PRE_MEM_READ( "ioctl(ASHMEM_PIN|ASHMEM_UNPIN)",
8073 ARG3
, sizeof(struct vki_ashmem_pin
) );
8077 case VKI_BINDER_WRITE_READ
:
8079 struct vki_binder_write_read
* bwr
8080 = (struct vki_binder_write_read
*)(Addr
)ARG3
;
8082 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_buffer",
8084 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_size",
8086 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_consumed",
8087 bwr
->write_consumed
);
8088 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_buffer",
8090 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_size",
8092 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_consumed",
8093 bwr
->read_consumed
);
8095 PRE_FIELD_WRITE("ioctl(BINDER_WRITE_READ).write_consumed",
8096 bwr
->write_consumed
);
8097 PRE_FIELD_WRITE("ioctl(BINDER_WRITE_READ).read_consumed",
8098 bwr
->read_consumed
);
8101 PRE_MEM_WRITE("ioctl(BINDER_WRITE_READ).read_buffer[]",
8102 (Addr
)bwr
->read_buffer
, bwr
->read_size
);
8103 if (bwr
->write_size
)
8104 PRE_MEM_READ("ioctl(BINDER_WRITE_READ).write_buffer[]",
8105 (Addr
)bwr
->write_buffer
, bwr
->write_size
);
8109 case VKI_BINDER_SET_IDLE_TIMEOUT
:
8110 case VKI_BINDER_SET_MAX_THREADS
:
8111 case VKI_BINDER_SET_IDLE_PRIORITY
:
8112 case VKI_BINDER_SET_CONTEXT_MGR
:
8113 case VKI_BINDER_THREAD_EXIT
:
8115 case VKI_BINDER_VERSION
:
8117 struct vki_binder_version
* bv
=
8118 (struct vki_binder_version
*)(Addr
)ARG3
;
8119 PRE_FIELD_WRITE("ioctl(BINDER_VERSION)", bv
->protocol_version
);
8122 # endif /* defined(VGPV_*_linux_android) */
8124 case VKI_HCIGETDEVLIST
:
8126 struct vki_hci_dev_list_req
* dlr
=
8127 (struct vki_hci_dev_list_req
*)(Addr
)ARG3
;
8128 PRE_MEM_READ("ioctl(HCIGETDEVLIST)",
8129 (Addr
)ARG3
, sizeof(struct vki_hci_dev_list_req
));
8130 PRE_MEM_WRITE("ioctl(HCIGETDEVLIST)",
8131 (Addr
)ARG3
+ sizeof(struct vki_hci_dev_list_req
),
8132 dlr
->dev_num
* sizeof(struct vki_hci_dev_req
));
8136 case VKI_HCIINQUIRY
:
8138 struct vki_hci_inquiry_req
* ir
=
8139 (struct vki_hci_inquiry_req
*)(Addr
)ARG3
;
8140 PRE_MEM_READ("ioctl(HCIINQUIRY)",
8141 (Addr
)ARG3
, sizeof(struct vki_hci_inquiry_req
));
8142 PRE_MEM_WRITE("ioctl(HCIINQUIRY)",
8143 (Addr
)ARG3
+ sizeof(struct vki_hci_inquiry_req
),
8144 ir
->num_rsp
* sizeof(struct vki_inquiry_info
));
8148 case VKI_DRM_IOCTL_VERSION
:
8150 struct vki_drm_version
* data
= (struct vki_drm_version
*)(Addr
)ARG3
;
8151 struct vg_drm_version_info
* info
;
8152 PRE_MEM_WRITE("ioctl(DRM_VERSION).version_major", (Addr
)&data
->version_major
, sizeof(data
->version_major
));
8153 PRE_MEM_WRITE("ioctl(DRM_VERSION).version_minor", (Addr
)&data
->version_minor
, sizeof(data
->version_minor
));
8154 PRE_MEM_WRITE("ioctl(DRM_VERSION).version_patchlevel", (Addr
)&data
->version_patchlevel
, sizeof(data
->version_patchlevel
));
8155 PRE_MEM_READ("ioctl(DRM_VERSION).name_len", (Addr
)&data
->name_len
, sizeof(data
->name_len
));
8156 PRE_MEM_READ("ioctl(DRM_VERSION).name", (Addr
)&data
->name
, sizeof(data
->name
));
8157 PRE_MEM_WRITE("ioctl(DRM_VERSION).name", (Addr
)data
->name
, data
->name_len
);
8158 PRE_MEM_READ("ioctl(DRM_VERSION).date_len", (Addr
)&data
->date_len
, sizeof(data
->date_len
));
8159 PRE_MEM_READ("ioctl(DRM_VERSION).date", (Addr
)&data
->date
, sizeof(data
->date
));
8160 PRE_MEM_WRITE("ioctl(DRM_VERSION).date", (Addr
)data
->date
, data
->date_len
);
8161 PRE_MEM_READ("ioctl(DRM_VERSION).desc_len", (Addr
)&data
->desc_len
, sizeof(data
->desc_len
));
8162 PRE_MEM_READ("ioctl(DRM_VERSION).desc", (Addr
)&data
->desc
, sizeof(data
->desc
));
8163 PRE_MEM_WRITE("ioctl(DRM_VERSION).desc", (Addr
)data
->desc
, data
->desc_len
);
8164 info
= VG_(malloc
)("syswrap.ioctl.1", sizeof(*info
));
8165 // To ensure we VG_(free) info even when syscall fails:
8166 *flags
|= SfPostOnFail
;
8169 ARG3
= (Addr
)&info
->data
;
8172 case VKI_DRM_IOCTL_GET_UNIQUE
:
8174 struct vki_drm_unique
*data
= (struct vki_drm_unique
*)(Addr
)ARG3
;
8175 PRE_MEM_READ("ioctl(DRM_GET_UNIQUE).unique_len", (Addr
)&data
->unique_len
, sizeof(data
->unique_len
));
8176 PRE_MEM_READ("ioctl(DRM_GET_UNIQUE).unique", (Addr
)&data
->unique
, sizeof(data
->unique
));
8177 PRE_MEM_WRITE("ioctl(DRM_GET_UNIQUE).unique", (Addr
)data
->unique
, data
->unique_len
);
8180 case VKI_DRM_IOCTL_GET_MAGIC
:
8182 struct vki_drm_auth
*data
= (struct vki_drm_auth
*)(Addr
)ARG3
;
8183 PRE_MEM_WRITE("ioctl(DRM_GET_MAGIC).magic", (Addr
)&data
->magic
, sizeof(data
->magic
));
8186 case VKI_DRM_IOCTL_WAIT_VBLANK
:
8188 union vki_drm_wait_vblank
*data
=
8189 (union vki_drm_wait_vblank
*)(Addr
)ARG3
;
8190 PRE_MEM_READ("ioctl(DRM_WAIT_VBLANK).request.type", (Addr
)&data
->request
.type
, sizeof(data
->request
.type
));
8191 PRE_MEM_READ("ioctl(DRM_WAIT_VBLANK).request.sequence", (Addr
)&data
->request
.sequence
, sizeof(data
->request
.sequence
));
8192 /* XXX: It seems request.signal isn't used */
8193 PRE_MEM_WRITE("ioctl(DRM_WAIT_VBLANK).reply", (Addr
)&data
->reply
, sizeof(data
->reply
));
8196 case VKI_DRM_IOCTL_GEM_CLOSE
:
8198 struct vki_drm_gem_close
*data
=
8199 (struct vki_drm_gem_close
*)(Addr
)ARG3
;
8200 PRE_MEM_READ("ioctl(DRM_GEM_CLOSE).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8203 case VKI_DRM_IOCTL_GEM_FLINK
:
8205 struct vki_drm_gem_flink
*data
=
8206 (struct vki_drm_gem_flink
*)(Addr
)ARG3
;
8207 PRE_MEM_READ("ioctl(DRM_GEM_FLINK).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8208 PRE_MEM_WRITE("ioctl(DRM_GEM_FLINK).name", (Addr
)&data
->name
, sizeof(data
->name
));
8211 case VKI_DRM_IOCTL_GEM_OPEN
:
8213 struct vki_drm_gem_open
*data
= (struct vki_drm_gem_open
*)(Addr
)ARG3
;
8214 PRE_MEM_READ("ioctl(DRM_GEM_OPEN).name", (Addr
)&data
->name
, sizeof(data
->name
));
8215 PRE_MEM_WRITE("ioctl(DRM_GEM_OPEN).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8216 PRE_MEM_WRITE("ioctl(DRM_GEM_OPEN).size", (Addr
)&data
->size
, sizeof(data
->size
));
8219 case VKI_DRM_IOCTL_I915_GETPARAM
:
8221 vki_drm_i915_getparam_t
*data
= (vki_drm_i915_getparam_t
*)(Addr
)ARG3
;
8222 PRE_MEM_READ("ioctl(DRM_I915_GETPARAM).param", (Addr
)&data
->param
, sizeof(data
->param
));
8223 PRE_MEM_WRITE("ioctl(DRM_I915_GETPARAM).value", (Addr
)data
->value
, sizeof(int));
8226 case VKI_DRM_IOCTL_I915_GEM_BUSY
:
8228 struct vki_drm_i915_gem_busy
*data
=
8229 (struct vki_drm_i915_gem_busy
*)(Addr
)ARG3
;
8230 PRE_MEM_READ("ioctl(DRM_I915_GEM_BUSY).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8231 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_BUSY).busy", (Addr
)&data
->busy
, sizeof(data
->busy
));
8234 case VKI_DRM_IOCTL_I915_GEM_CREATE
:
8236 struct vki_drm_i915_gem_create
*data
=
8237 (struct vki_drm_i915_gem_create
*)(Addr
)ARG3
;
8238 PRE_MEM_READ("ioctl(DRM_I915_GEM_CREATE).size", (Addr
)&data
->size
, sizeof(data
->size
));
8239 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_CREATE).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8242 case VKI_DRM_IOCTL_I915_GEM_PREAD
:
8244 struct vki_drm_i915_gem_pread
*data
=
8245 (struct vki_drm_i915_gem_pread
*)(Addr
)ARG3
;
8246 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8247 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).offset", (Addr
)&data
->offset
, sizeof(data
->offset
));
8248 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).size", (Addr
)&data
->size
, sizeof(data
->size
));
8249 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).data_ptr", (Addr
)&data
->data_ptr
, sizeof(data
->data_ptr
));
8250 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_PREAD).data_ptr", (Addr
)data
->data_ptr
, data
->size
);
8253 case VKI_DRM_IOCTL_I915_GEM_PWRITE
:
8255 struct vki_drm_i915_gem_pwrite
*data
=
8256 (struct vki_drm_i915_gem_pwrite
*)(Addr
)ARG3
;
8257 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8258 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).offset", (Addr
)&data
->offset
, sizeof(data
->offset
));
8259 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).size", (Addr
)&data
->size
, sizeof(data
->size
));
8260 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).data_ptr", (Addr
)&data
->data_ptr
, sizeof(data
->data_ptr
));
8261 /* PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).data_ptr", (Addr)data->data_ptr, data->size);
8262 * NB: the buffer is allowed to contain any amount of uninitialized data (e.g.
8263 * interleaved vertex attributes may have a wide stride with uninitialized data between
8264 * consecutive vertices) */
8267 case VKI_DRM_IOCTL_I915_GEM_MMAPv1
:
8269 struct vki_drm_i915_gem_mmap_v1
*data
=
8270 (struct vki_drm_i915_gem_mmap_v1
*)(Addr
)ARG3
;
8271 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAPv1).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8272 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAPv1).offset", (Addr
)&data
->offset
, sizeof(data
->offset
));
8273 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAPv1).size", (Addr
)&data
->size
, sizeof(data
->size
));
8274 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_MMAPv1).addr_ptr", (Addr
)&data
->addr_ptr
, sizeof(data
->addr_ptr
));
8277 case VKI_DRM_IOCTL_I915_GEM_MMAP
:
8279 struct vki_drm_i915_gem_mmap
*data
=
8280 (struct vki_drm_i915_gem_mmap
*)(Addr
)ARG3
;
8281 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8282 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP).offset", (Addr
)&data
->offset
, sizeof(data
->offset
));
8283 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP).size", (Addr
)&data
->size
, sizeof(data
->size
));
8284 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP).flags", (Addr
)&data
->size
, sizeof(data
->flags
));
8285 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_MMAP).addr_ptr", (Addr
)&data
->addr_ptr
, sizeof(data
->addr_ptr
));
8288 case VKI_DRM_IOCTL_I915_GEM_MMAP_GTT
:
8290 struct vki_drm_i915_gem_mmap_gtt
*data
=
8291 (struct vki_drm_i915_gem_mmap_gtt
*)(Addr
)ARG3
;
8292 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP_GTT).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8293 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_MMAP_GTT).offset", (Addr
)&data
->offset
, sizeof(data
->offset
));
8296 case VKI_DRM_IOCTL_I915_GEM_SET_DOMAIN
:
8298 struct vki_drm_i915_gem_set_domain
*data
=
8299 (struct vki_drm_i915_gem_set_domain
*)(Addr
)ARG3
;
8300 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8301 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).read_domains", (Addr
)&data
->read_domains
, sizeof(data
->read_domains
));
8302 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).write_domain", (Addr
)&data
->write_domain
, sizeof(data
->write_domain
));
8305 case VKI_DRM_IOCTL_I915_GEM_SET_TILING
:
8307 struct vki_drm_i915_gem_set_tiling
*data
=
8308 (struct vki_drm_i915_gem_set_tiling
*)(Addr
)ARG3
;
8309 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8310 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).tiling_mode", (Addr
)&data
->tiling_mode
, sizeof(data
->tiling_mode
));
8311 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).stride", (Addr
)&data
->stride
, sizeof(data
->stride
));
8312 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_SET_TILING).swizzle_mode", (Addr
)&data
->swizzle_mode
, sizeof(data
->swizzle_mode
));
8315 case VKI_DRM_IOCTL_I915_GEM_GET_TILING
:
8317 struct vki_drm_i915_gem_get_tiling
*data
=
8318 (struct vki_drm_i915_gem_get_tiling
*)(Addr
)ARG3
;
8319 PRE_MEM_READ("ioctl(DRM_I915_GEM_GET_TILING).handle", (Addr
)&data
->handle
, sizeof(data
->handle
));
8320 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_TILING).tiling_mode", (Addr
)&data
->tiling_mode
, sizeof(data
->tiling_mode
));
8321 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_TILING).swizzle_mode", (Addr
)&data
->swizzle_mode
, sizeof(data
->swizzle_mode
));
8324 case VKI_DRM_IOCTL_I915_GEM_GET_APERTURE
:
8326 struct vki_drm_i915_gem_get_aperture
*data
=
8327 (struct vki_drm_i915_gem_get_aperture
*)(Addr
)ARG3
;
8328 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_APERTURE).aper_size", (Addr
)&data
->aper_size
, sizeof(data
->aper_size
));
8329 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_APERTURE).aper_available_size", (Addr
)&data
->aper_available_size
, sizeof(data
->aper_available_size
));
8333 /* KVM ioctls that check for a numeric value as parameter */
8334 case VKI_KVM_GET_API_VERSION
:
8335 case VKI_KVM_CREATE_VM
:
8336 case VKI_KVM_GET_VCPU_MMAP_SIZE
:
8337 case VKI_KVM_CHECK_EXTENSION
:
8338 case VKI_KVM_SET_TSS_ADDR
:
8339 case VKI_KVM_CREATE_VCPU
:
8343 case VKI_KVM_S390_MEM_OP
: {
8344 struct vki_kvm_s390_mem_op
*args
=
8345 (struct vki_kvm_s390_mem_op
*)(Addr
)(ARG3
);
8346 PRE_MEM_READ("ioctl(KVM_S390_MEM_OP)", ARG3
,
8347 sizeof(struct vki_kvm_s390_mem_op
));
8348 if (args
->flags
& VKI_KVM_S390_MEMOP_F_CHECK_ONLY
)
8350 if (args
->op
== VKI_KVM_S390_MEMOP_LOGICAL_READ
)
8351 PRE_MEM_WRITE("ioctl(KVM_S390_MEM_OP).buf", (Addr
)args
->buf
, args
->size
);
8352 if (args
->op
== VKI_KVM_S390_MEMOP_LOGICAL_WRITE
)
8353 PRE_MEM_READ("ioctl(KVM_S390_MEM_OP).buf", (Addr
)args
->buf
, args
->size
);
8359 case VKI_XEN_IOCTL_PRIVCMD_HYPERCALL
: {
8360 SyscallArgs harrghs
;
8361 struct vki_xen_privcmd_hypercall
*args
=
8362 (struct vki_xen_privcmd_hypercall
*)(Addr
)(ARG3
);
8367 VG_(memset
)(&harrghs
, 0, sizeof(harrghs
));
8368 harrghs
.sysno
= args
->op
;
8369 harrghs
.arg1
= args
->arg
[0];
8370 harrghs
.arg2
= args
->arg
[1];
8371 harrghs
.arg3
= args
->arg
[2];
8372 harrghs
.arg4
= args
->arg
[3];
8373 harrghs
.arg5
= args
->arg
[4];
8374 harrghs
.arg6
= harrghs
.arg7
= harrghs
.arg8
= 0;
8376 WRAPPER_PRE_NAME(xen
, hypercall
) (tid
, layout
, &harrghs
, status
, flags
);
8378 /* HACK. arg8 is used to return the number of hypercall
8379 * arguments actually consumed! */
8380 PRE_MEM_READ("hypercall", ARG3
, sizeof(args
->op
) +
8381 ( sizeof(args
->arg
[0]) * harrghs
.arg8
) );
8386 case VKI_XEN_IOCTL_PRIVCMD_MMAP
: {
8387 struct vki_xen_privcmd_mmap
*args
=
8388 (struct vki_xen_privcmd_mmap
*)(Addr
)(ARG3
);
8389 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(num)",
8390 (Addr
)&args
->num
, sizeof(args
->num
));
8391 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(dom)",
8392 (Addr
)&args
->dom
, sizeof(args
->dom
));
8393 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(entry)",
8394 (Addr
)args
->entry
, sizeof(*(args
->entry
)) * args
->num
);
8397 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH
: {
8398 struct vki_xen_privcmd_mmapbatch
*args
=
8399 (struct vki_xen_privcmd_mmapbatch
*)(Addr
)(ARG3
);
8400 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(num)",
8401 (Addr
)&args
->num
, sizeof(args
->num
));
8402 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(dom)",
8403 (Addr
)&args
->dom
, sizeof(args
->dom
));
8404 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(addr)",
8405 (Addr
)&args
->addr
, sizeof(args
->addr
));
8406 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(arr)",
8407 (Addr
)args
->arr
, sizeof(*(args
->arr
)) * args
->num
);
8410 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2
: {
8411 struct vki_xen_privcmd_mmapbatch_v2
*args
=
8412 (struct vki_xen_privcmd_mmapbatch_v2
*)(Addr
)(ARG3
);
8413 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(num)",
8414 (Addr
)&args
->num
, sizeof(args
->num
));
8415 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(dom)",
8416 (Addr
)&args
->dom
, sizeof(args
->dom
));
8417 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(addr)",
8418 (Addr
)&args
->addr
, sizeof(args
->addr
));
8419 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(arr)",
8420 (Addr
)args
->arr
, sizeof(*(args
->arr
)) * args
->num
);
8424 case VKI_XEN_IOCTL_EVTCHN_BIND_VIRQ
: {
8425 struct vki_xen_ioctl_evtchn_bind_virq
*args
=
8426 (struct vki_xen_ioctl_evtchn_bind_virq
*)(Addr
)(ARG3
);
8427 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_VIRQ(virq)",
8428 (Addr
)&args
->virq
, sizeof(args
->virq
));
8431 case VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN
: {
8432 struct vki_xen_ioctl_evtchn_bind_interdomain
*args
=
8433 (struct vki_xen_ioctl_evtchn_bind_interdomain
*)(Addr
)(ARG3
);
8434 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN(remote_domain)",
8435 (Addr
)&args
->remote_domain
, sizeof(args
->remote_domain
));
8436 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN(remote_port)",
8437 (Addr
)&args
->remote_port
, sizeof(args
->remote_port
));
8440 case VKI_XEN_IOCTL_EVTCHN_BIND_UNBOUND_PORT
: {
8441 struct vki_xen_ioctl_evtchn_bind_unbound_port
*args
=
8442 (struct vki_xen_ioctl_evtchn_bind_unbound_port
*)(Addr
)(ARG3
);
8443 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_UNBOUND_PORT(remote_domain)",
8444 (Addr
)&args
->remote_domain
, sizeof(args
->remote_domain
));
8447 case VKI_XEN_IOCTL_EVTCHN_UNBIND
: {
8448 struct vki_xen_ioctl_evtchn_unbind
*args
=
8449 (struct vki_xen_ioctl_evtchn_unbind
*)(Addr
)(ARG3
);
8450 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_UNBIND(port)",
8451 (Addr
)&args
->port
, sizeof(args
->port
));
8454 case VKI_XEN_IOCTL_EVTCHN_NOTIFY
: {
8455 struct vki_xen_ioctl_evtchn_notify
*args
=
8456 (struct vki_xen_ioctl_evtchn_notify
*)(Addr
)(ARG3
);
8457 PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_notify(port)",
8458 (Addr
)&args
->port
, sizeof(args
->port
));
8461 case VKI_XEN_IOCTL_EVTCHN_RESET
:
8467 case VKI_OBD_IOC_FID2PATH
: {
8468 struct vki_getinfo_fid2path
*gf
=
8469 (struct vki_getinfo_fid2path
*)(Addr
)ARG3
;
8470 PRE_MEM_READ("VKI_OBD_IOC_FID2PATH(args)", ARG3
, sizeof(struct vki_getinfo_fid2path
));
8471 PRE_FIELD_WRITE("VKI_OBD_IOC_FID2PATH(args).gf_recno", gf
->gf_recno
);
8472 PRE_FIELD_WRITE("VKI_OBD_IOC_FID2PATH(args).gf_linkno", gf
->gf_linkno
);
8473 PRE_MEM_WRITE("VKI_OBD_IOC_FID2PATH(args)", (Addr
)gf
->gf_path
, gf
->gf_pathlen
);
8477 case VKI_LL_IOC_PATH2FID
:
8478 PRE_MEM_WRITE("ioctl(VKI_LL_IOC_PATH2FID)", ARG3
, sizeof(struct vki_lu_fid
));
8481 case VKI_LL_IOC_GETPARENT
: {
8482 struct vki_getparent
*gp
= (struct vki_getparent
*)(Addr
)ARG3
;
8483 PRE_FIELD_READ("ioctl(VKI_LL_IOC_GETPARENT).gp_linkno", gp
->gp_linkno
);
8484 PRE_FIELD_READ("ioctl(VKI_LL_IOC_GETPARENT).gp_name_size", gp
->gp_name_size
);
8485 PRE_FIELD_WRITE("ioctl(VKI_LL_IOC_GETPARENT).gp_fid", gp
->gp_fid
);
8486 PRE_MEM_WRITE("ioctl(VKI_LL_IOC_GETPARENT).gp_name", (Addr
)gp
->gp_name
, gp
->gp_name_size
);
8491 case VKI_V4L2_QUERYCAP
: {
8492 struct vki_v4l2_capability
*data
=
8493 (struct vki_v4l2_capability
*)(Addr
)ARG3
;
8494 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYCAP)", (Addr
)data
, sizeof(*data
));
8497 case VKI_V4L2_ENUM_FMT
: {
8498 struct vki_v4l2_fmtdesc
*data
= (struct vki_v4l2_fmtdesc
*)(Addr
)ARG3
;
8499 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FMT).index", data
->index
);
8500 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FMT).type", data
->type
);
8501 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).flags", data
->flags
);
8502 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).description", data
->description
);
8503 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).pixelformat", data
->pixelformat
);
8504 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).reserved", data
->reserved
);
8507 case VKI_V4L2_G_FMT
: {
8508 struct vki_v4l2_format
*data
= (struct vki_v4l2_format
*)(Addr
)ARG3
;
8509 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).type", data
->type
);
8510 switch (data
->type
) {
8511 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE
:
8512 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
:
8513 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.pix.priv", data
->fmt
.pix
.priv
);
8514 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.pix", data
->fmt
.pix
);
8515 PRE_MEM_READ("ioctl(VKI_V4L2_G_FMT)",
8516 (Addr
)&data
->type
+ sizeof(data
->type
) + sizeof(data
->fmt
.pix
),
8517 sizeof(*data
) - sizeof(data
->type
) - sizeof(data
->fmt
.pix
));
8519 case VKI_V4L2_BUF_TYPE_VBI_CAPTURE
:
8520 case VKI_V4L2_BUF_TYPE_VBI_OUTPUT
:
8521 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.vbi", data
->fmt
.vbi
);
8523 case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
8524 case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
8525 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.sliced", data
->fmt
.sliced
);
8527 case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY
:
8528 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
8529 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.win.clips", data
->fmt
.win
.clips
);
8530 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.win.bitmap", data
->fmt
.win
.bitmap
);
8531 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.win.clipcount", data
->fmt
.win
.clipcount
);
8532 if (data
->fmt
.win
.clipcount
&& data
->fmt
.win
.clips
)
8533 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.clips[]",
8534 (Addr
)data
->fmt
.win
.clips
,
8535 data
->fmt
.win
.clipcount
* sizeof(data
->fmt
.win
.clips
[0]));
8536 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.clipcount", data
->fmt
.win
.clipcount
);
8537 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.w", data
->fmt
.win
.w
);
8538 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.field", data
->fmt
.win
.field
);
8539 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.chromakey", data
->fmt
.win
.chromakey
);
8540 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.global_alpha", data
->fmt
.win
.global_alpha
);
8542 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
8543 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
8544 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.pix_mp", data
->fmt
.pix_mp
);
8546 case VKI_V4L2_BUF_TYPE_SDR_CAPTURE
:
8547 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.sdr", data
->fmt
.sdr
);
8552 case VKI_V4L2_S_FMT
: {
8553 struct vki_v4l2_format
*data
= (struct vki_v4l2_format
*)(Addr
)ARG3
;
8554 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).type", data
->type
);
8555 switch (data
->type
) {
8556 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE
:
8557 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
:
8558 PRE_MEM_READ("ioctl(VKI_V4L2_S_FMT)",
8559 (Addr
)&data
->type
+ sizeof(data
->type
),
8560 sizeof(*data
) - sizeof(data
->type
));
8562 case VKI_V4L2_BUF_TYPE_VBI_CAPTURE
:
8563 case VKI_V4L2_BUF_TYPE_VBI_OUTPUT
:
8564 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.vbi", data
->fmt
.vbi
);
8566 case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
8567 case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
8568 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.sliced", data
->fmt
.sliced
);
8570 case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY
:
8571 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
8572 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.win", data
->fmt
.win
);
8573 if (data
->fmt
.win
.clipcount
&& data
->fmt
.win
.clips
)
8574 PRE_MEM_READ("ioctl(VKI_V4L2_S_FMT).fmt.win.clips[]",
8575 (Addr
)data
->fmt
.win
.clips
,
8576 data
->fmt
.win
.clipcount
* sizeof(data
->fmt
.win
.clips
[0]));
8577 if (data
->fmt
.win
.bitmap
)
8578 PRE_MEM_READ("ioctl(VKI_V4L2_S_FMT).fmt.win.bitmap[]",
8579 (Addr
)data
->fmt
.win
.bitmap
,
8580 data
->fmt
.win
.w
.height
* ((data
->fmt
.win
.w
.width
+ 7) / 8));
8582 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
8583 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
8584 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.pix_mp", data
->fmt
.pix_mp
);
8586 case VKI_V4L2_BUF_TYPE_SDR_CAPTURE
:
8587 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.sdr", data
->fmt
.sdr
);
8592 case VKI_V4L2_TRY_FMT
: {
8593 struct vki_v4l2_format
*data
= (struct vki_v4l2_format
*)(Addr
)ARG3
;
8594 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).type", data
->type
);
8595 switch (data
->type
) {
8596 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE
:
8597 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
:
8598 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_FMT)",
8599 (Addr
)&data
->type
+ sizeof(data
->type
),
8600 sizeof(*data
) - sizeof(data
->type
));
8602 case VKI_V4L2_BUF_TYPE_VBI_CAPTURE
:
8603 case VKI_V4L2_BUF_TYPE_VBI_OUTPUT
:
8604 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.vbi", data
->fmt
.vbi
);
8606 case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
8607 case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
8608 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.sliced", data
->fmt
.sliced
);
8610 case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY
:
8611 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
8612 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.win", data
->fmt
.win
);
8613 if (data
->fmt
.win
.clipcount
&& data
->fmt
.win
.clips
)
8614 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.win.clips[]",
8615 (Addr
)data
->fmt
.win
.clips
,
8616 data
->fmt
.win
.clipcount
* sizeof(data
->fmt
.win
.clips
[0]));
8617 if (data
->fmt
.win
.bitmap
)
8618 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.win.bitmap[]",
8619 (Addr
)data
->fmt
.win
.bitmap
,
8620 data
->fmt
.win
.w
.height
* ((data
->fmt
.win
.w
.width
+ 7) / 8));
8622 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
8623 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
8624 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.pix_mp", data
->fmt
.pix_mp
);
8626 case VKI_V4L2_BUF_TYPE_SDR_CAPTURE
:
8627 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.sdr", data
->fmt
.sdr
);
8632 case VKI_V4L2_REQBUFS
: {
8633 struct vki_v4l2_requestbuffers
*data
=
8634 (struct vki_v4l2_requestbuffers
*)(Addr
)ARG3
;
8635 PRE_MEM_READ("ioctl(VKI_V4L2_REQBUFS)", (Addr
)data
, sizeof(*data
));
8638 case VKI_V4L2_QUERYBUF
: {
8639 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
8640 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).type", data
->type
);
8641 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).index", data
->index
);
8642 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).reserved", data
->reserved
);
8643 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).reserved2", data
->reserved2
);
8644 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
8645 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
8648 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).length", data
->length
);
8649 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).m.planes", data
->m
.planes
);
8650 for (i
= 0; i
< data
->length
; i
++) {
8651 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].bytesused", data
->m
.planes
[i
].bytesused
);
8652 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].length", data
->m
.planes
[i
].length
);
8653 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].m", data
->m
.planes
[i
].m
);
8654 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].data_offset", data
->m
.planes
[i
].data_offset
);
8655 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].reserved", data
->m
.planes
[i
].reserved
);
8658 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m", data
->m
);
8659 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).length", data
->length
);
8661 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).bytesused", data
->bytesused
);
8662 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).flags", data
->flags
);
8663 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).field", data
->field
);
8664 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).timestamp", data
->timestamp
);
8665 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).timecode", data
->timecode
);
8666 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).sequence", data
->sequence
);
8667 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).memory", data
->memory
);
8668 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).sequence", data
->sequence
);
8671 case VKI_V4L2_G_FBUF
: {
8672 struct vki_v4l2_framebuffer
*data
=
8673 (struct vki_v4l2_framebuffer
*)(Addr
)ARG3
;
8674 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_FBUF)", (Addr
)data
, sizeof(*data
));
8677 case VKI_V4L2_S_FBUF
: {
8678 struct vki_v4l2_framebuffer
*data
=
8679 (struct vki_v4l2_framebuffer
*)(Addr
)ARG3
;
8680 PRE_FIELD_WRITE("ioctl(VKI_V4L2_S_FBUF).capability", data
->capability
);
8681 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FBUF).flags", data
->flags
);
8682 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FBUF).base", data
->base
);
8683 PRE_FIELD_READ("ioctl(VKI_V4L2_S_FBUF).fmt", data
->fmt
);
8686 case VKI_V4L2_OVERLAY
: {
8687 int *data
= (int *)(Addr
)ARG3
;
8688 PRE_MEM_READ("ioctl(VKI_V4L2_OVERLAY)", (Addr
)data
, sizeof(*data
));
8691 case VKI_V4L2_QBUF
: {
8692 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
8693 int is_output
= data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
||
8694 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
||
8695 data
->type
== VKI_V4L2_BUF_TYPE_VBI_OUTPUT
||
8696 data
->type
== VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
;
8698 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).type", data
->type
);
8699 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).index", data
->index
);
8700 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).flags", data
->flags
);
8701 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).memory", data
->memory
);
8702 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).reserved", data
->reserved
);
8703 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).reserved2", data
->reserved2
);
8705 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).bytesused", data
->bytesused
);
8706 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).field", data
->field
);
8708 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
8709 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
8712 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).length", data
->length
);
8713 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes", data
->m
.planes
);
8714 for (i
= 0; i
< data
->length
; i
++) {
8716 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].bytesused", data
->m
.planes
[i
].bytesused
);
8717 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].data_offset", data
->m
.planes
[i
].data_offset
);
8719 if (data
->memory
== VKI_V4L2_MEMORY_MMAP
)
8720 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QBUF).m.planes[].m", data
->m
.planes
[i
].m
);
8721 else if (data
->memory
== VKI_V4L2_MEMORY_DMABUF
)
8722 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].m.fd", data
->m
.planes
[i
].m
.fd
);
8724 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].m", data
->m
.planes
[i
].m
);
8725 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].reserved", data
->m
.planes
[i
].reserved
);
8728 if (data
->memory
== VKI_V4L2_MEMORY_MMAP
)
8729 PRE_FIELD_WRITE("ioctl(VKI_V4L2_QBUF).m", data
->m
);
8730 else if (data
->memory
== VKI_V4L2_MEMORY_DMABUF
)
8731 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.fd", data
->m
.fd
);
8733 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m", data
->m
);
8735 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).bytesused", data
->bytesused
);
8736 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).field", data
->field
);
8739 if (is_output
&& (data
->flags
& VKI_V4L2_BUF_FLAG_TIMESTAMP_MASK
) == VKI_V4L2_BUF_FLAG_TIMESTAMP_COPY
) {
8740 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).timestamp", data
->timestamp
);
8741 PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).timecode", data
->timecode
);
8745 case VKI_V4L2_EXPBUF
: {
8746 struct vki_v4l2_exportbuffer
*data
=
8747 (struct vki_v4l2_exportbuffer
*)(Addr
)ARG3
;
8748 PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).type", data
->type
);
8749 PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).index", data
->index
);
8750 PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).plane", data
->plane
);
8751 PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).flags", data
->flags
);
8752 PRE_FIELD_WRITE("ioctl(VKI_V4L2_EXPBUF).fd", data
->fd
);
8753 PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).reserved", data
->reserved
);
8756 case VKI_V4L2_DQBUF
: {
8757 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
8758 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).type", data
->type
);
8759 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).index", data
->index
);
8760 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).memory", data
->memory
);
8761 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).reserved", data
->reserved
);
8762 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).reserved2", data
->reserved2
);
8763 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).bytesused", data
->bytesused
);
8764 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).field", data
->field
);
8765 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
8766 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
8769 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).length", data
->length
);
8770 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).m.planes", data
->m
.planes
);
8771 for (i
= 0; i
< data
->length
; i
++) {
8772 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].bytesused", data
->m
.planes
[i
].bytesused
);
8773 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].data_offset", data
->m
.planes
[i
].data_offset
);
8774 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].length", data
->m
.planes
[i
].length
);
8775 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].m", data
->m
.planes
[i
].m
);
8776 PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).m.planes[].reserved", data
->m
.planes
[i
].reserved
);
8779 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m", data
->m
);
8780 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).length", data
->length
);
8781 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).bytesused", data
->bytesused
);
8782 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).field", data
->field
);
8784 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).timestamp", data
->timestamp
);
8785 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).timecode", data
->timecode
);
8786 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).sequence", data
->sequence
);
8789 case VKI_V4L2_STREAMON
: {
8790 int *data
= (int *)(Addr
)ARG3
;
8791 PRE_MEM_READ("ioctl(VKI_V4L2_STREAMON)", (Addr
)data
, sizeof(*data
));
8794 case VKI_V4L2_STREAMOFF
: {
8795 int *data
= (int *)(Addr
)ARG3
;
8796 PRE_MEM_READ("ioctl(VKI_V4L2_STREAMOFF)", (Addr
)data
, sizeof(*data
));
8799 case VKI_V4L2_G_PARM
: {
8800 struct vki_v4l2_streamparm
*data
=
8801 (struct vki_v4l2_streamparm
*)(Addr
)ARG3
;
8802 int is_output
= data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
||
8803 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
||
8804 data
->type
== VKI_V4L2_BUF_TYPE_VBI_OUTPUT
||
8805 data
->type
== VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
;
8807 PRE_FIELD_READ("ioctl(VKI_V4L2_G_PARM).type", data
->type
);
8809 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_PARM)", (Addr
)&data
->parm
.output
,
8810 sizeof(data
->parm
.output
) - sizeof(data
->parm
.output
.reserved
));
8811 PRE_FIELD_READ("ioctl(VKI_V4L2_G_PARM).parm.output.reserved", data
->parm
.output
.reserved
);
8813 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_PARM)", (Addr
)&data
->parm
.capture
,
8814 sizeof(data
->parm
.capture
) - sizeof(data
->parm
.capture
.reserved
));
8815 PRE_FIELD_READ("ioctl(VKI_V4L2_G_PARM).parm.capture.reserved", data
->parm
.capture
.reserved
);
8819 case VKI_V4L2_S_PARM
: {
8820 struct vki_v4l2_streamparm
*data
=
8821 (struct vki_v4l2_streamparm
*)(Addr
)ARG3
;
8822 int is_output
= data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
||
8823 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
||
8824 data
->type
== VKI_V4L2_BUF_TYPE_VBI_OUTPUT
||
8825 data
->type
== VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
;
8827 PRE_FIELD_READ("ioctl(VKI_V4L2_S_PARM).type", data
->type
);
8829 PRE_FIELD_READ("ioctl(VKI_V4L2_S_PARM).parm.output", data
->parm
.output
);
8831 PRE_FIELD_READ("ioctl(VKI_V4L2_S_PARM).parm.capture", data
->parm
.capture
);
8834 case VKI_V4L2_G_STD
: {
8835 vki_v4l2_std_id
*data
= (vki_v4l2_std_id
*)(Addr
)ARG3
;
8836 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_STD)", (Addr
)data
, sizeof(*data
));
8839 case VKI_V4L2_S_STD
: {
8840 vki_v4l2_std_id
*data
= (vki_v4l2_std_id
*)(Addr
)ARG3
;
8841 PRE_MEM_READ("ioctl(VKI_V4L2_S_STD)", (Addr
)data
, sizeof(*data
));
8844 case VKI_V4L2_ENUMSTD
: {
8845 struct vki_v4l2_standard
*data
= (struct vki_v4l2_standard
*)(Addr
)ARG3
;
8846 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMSTD).index", data
->index
);
8847 PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMSTD)", (Addr
)&data
->id
, sizeof(*data
) - sizeof(data
->index
));
8850 case VKI_V4L2_ENUMINPUT
: {
8851 struct vki_v4l2_input
*data
= (struct vki_v4l2_input
*)(Addr
)ARG3
;
8852 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMINPUT).index", data
->index
);
8853 PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMINPUT)", (Addr
)data
->name
, sizeof(*data
) - sizeof(data
->index
));
8856 case VKI_V4L2_G_CTRL
: {
8857 struct vki_v4l2_control
*data
= (struct vki_v4l2_control
*)(Addr
)ARG3
;
8858 PRE_FIELD_READ("ioctl(VKI_V4L2_G_CTRL).id", data
->id
);
8859 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_CTRL).value", data
->value
);
8862 case VKI_V4L2_S_CTRL
: {
8863 struct vki_v4l2_control
*data
= (struct vki_v4l2_control
*)(Addr
)ARG3
;
8864 PRE_MEM_READ("ioctl(VKI_V4L2_S_CTRL)", (Addr
)data
, sizeof(*data
));
8867 case VKI_V4L2_G_TUNER
: {
8868 struct vki_v4l2_tuner
*data
= (struct vki_v4l2_tuner
*)(Addr
)ARG3
;
8869 PRE_FIELD_READ("ioctl(VKI_V4L2_G_TUNER).index", data
->index
);
8870 PRE_FIELD_READ("ioctl(VKI_V4L2_G_TUNER).reserved", data
->reserved
);
8871 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_TUNER)", (Addr
)data
->name
,
8872 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
8875 case VKI_V4L2_S_TUNER
: {
8876 struct vki_v4l2_tuner
*data
= (struct vki_v4l2_tuner
*)(Addr
)ARG3
;
8877 PRE_FIELD_READ("ioctl(VKI_V4L2_S_TUNER).index", data
->index
);
8878 PRE_FIELD_READ("ioctl(VKI_V4L2_S_TUNER).audmode", data
->audmode
);
8879 PRE_FIELD_READ("ioctl(VKI_V4L2_S_TUNER).reserved", data
->reserved
);
8882 case VKI_V4L2_G_AUDIO
: {
8883 struct vki_v4l2_audio
*data
= (struct vki_v4l2_audio
*)(Addr
)ARG3
;
8884 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_AUDIO)", (Addr
)data
,
8885 sizeof(*data
) - sizeof(data
->reserved
));
8886 PRE_FIELD_READ("ioctl(VKI_V4L2_G_AUDIO).reserved", data
->reserved
);
8889 case VKI_V4L2_S_AUDIO
: {
8890 struct vki_v4l2_audio
*data
= (struct vki_v4l2_audio
*)(Addr
)ARG3
;
8891 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDIO).index", data
->index
);
8892 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDIO).mode", data
->mode
);
8893 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDIO).reserved", data
->reserved
);
8896 case VKI_V4L2_QUERYCTRL
: {
8897 struct vki_v4l2_queryctrl
*data
= (struct vki_v4l2_queryctrl
*)(Addr
)ARG3
;
8898 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYCTRL).id", data
->id
);
8899 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYCTRL)", (Addr
)&data
->type
,
8900 sizeof(*data
) - sizeof(data
->id
));
8903 case VKI_V4L2_QUERYMENU
: {
8904 struct vki_v4l2_querymenu
*data
= (struct vki_v4l2_querymenu
*)(Addr
)ARG3
;
8905 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYMENU).id", data
->id
);
8906 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYMENU).index", data
->index
);
8907 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYMENU)", (Addr
)data
->name
,
8908 sizeof(*data
) - sizeof(data
->id
) - sizeof(data
->index
));
8911 case VKI_V4L2_G_INPUT
: {
8912 int *data
= (int *)(Addr
)ARG3
;
8913 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_INPUT)", (Addr
)data
, sizeof(*data
));
8916 case VKI_V4L2_S_INPUT
: {
8917 int *data
= (int *)(Addr
)ARG3
;
8918 PRE_MEM_READ("ioctl(VKI_V4L2_S_INPUT)", (Addr
)data
, sizeof(*data
));
8921 case VKI_V4L2_G_EDID
: {
8922 struct vki_v4l2_edid
*data
= (struct vki_v4l2_edid
*)(Addr
)ARG3
;
8923 PRE_MEM_READ("ioctl(VKI_V4L2_G_EDID)", (Addr
)data
, sizeof(*data
));
8924 if (data
->blocks
&& data
->edid
)
8925 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_EDID)", (Addr
)data
->edid
, data
->blocks
* 128);
8928 case VKI_V4L2_S_EDID
: {
8929 struct vki_v4l2_edid
*data
= (struct vki_v4l2_edid
*)(Addr
)ARG3
;
8930 PRE_MEM_READ("ioctl(VKI_V4L2_S_EDID)", (Addr
)data
, sizeof(*data
));
8931 if (data
->blocks
&& data
->edid
)
8932 PRE_MEM_READ("ioctl(VKI_V4L2_S_EDID)", (Addr
)data
->edid
, data
->blocks
* 128);
8935 case VKI_V4L2_G_OUTPUT
: {
8936 int *data
= (int *)(Addr
)ARG3
;
8937 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_OUTPUT)", (Addr
)data
, sizeof(*data
));
8940 case VKI_V4L2_S_OUTPUT
: {
8941 int *data
= (int *)(Addr
)ARG3
;
8942 PRE_MEM_READ("ioctl(VKI_V4L2_S_OUTPUT)", (Addr
)data
, sizeof(*data
));
8945 case VKI_V4L2_ENUMOUTPUT
: {
8946 struct vki_v4l2_output
*data
= (struct vki_v4l2_output
*)(Addr
)ARG3
;
8947 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMOUTPUT).index", data
->index
);
8948 PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMOUTPUT)", (Addr
)data
->name
, sizeof(*data
) - sizeof(data
->index
));
8951 case VKI_V4L2_G_AUDOUT
: {
8952 struct vki_v4l2_audioout
*data
= (struct vki_v4l2_audioout
*)(Addr
)ARG3
;
8953 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_AUDOUT)", (Addr
)data
,
8954 sizeof(*data
) - sizeof(data
->reserved
));
8955 PRE_FIELD_READ("ioctl(VKI_V4L2_G_AUDOUT).reserved", data
->reserved
);
8958 case VKI_V4L2_S_AUDOUT
: {
8959 struct vki_v4l2_audioout
*data
= (struct vki_v4l2_audioout
*)(Addr
)ARG3
;
8960 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDOUT).index", data
->index
);
8961 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDOUT).reserved", data
->reserved
);
8962 PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDOUT).mode", data
->mode
);
8965 case VKI_V4L2_G_MODULATOR
: {
8966 struct vki_v4l2_modulator
*data
= (struct vki_v4l2_modulator
*)(Addr
)ARG3
;
8967 PRE_FIELD_READ("ioctl(VKI_V4L2_G_MODULATOR).index", data
->index
);
8968 PRE_FIELD_READ("ioctl(VKI_V4L2_G_MODULATOR).reserved", data
->reserved
);
8969 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_MODULATOR)", (Addr
)data
->name
,
8970 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
8973 case VKI_V4L2_S_MODULATOR
: {
8974 struct vki_v4l2_modulator
*data
= (struct vki_v4l2_modulator
*)(Addr
)ARG3
;
8975 PRE_FIELD_READ("ioctl(VKI_V4L2_S_MODULATOR).index", data
->index
);
8976 PRE_FIELD_READ("ioctl(VKI_V4L2_S_MODULATOR).txsubchans", data
->txsubchans
);
8977 PRE_FIELD_READ("ioctl(VKI_V4L2_S_MODULATOR).reserved", data
->reserved
);
8980 case VKI_V4L2_G_FREQUENCY
: {
8981 struct vki_v4l2_frequency
*data
= (struct vki_v4l2_frequency
*)(Addr
)ARG3
;
8982 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FREQUENCY).tuner", data
->tuner
);
8983 PRE_FIELD_READ("ioctl(VKI_V4L2_G_FREQUENCY).reserved", data
->reserved
);
8984 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FREQUENCY).type", data
->type
);
8985 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FREQUENCY).frequency", data
->frequency
);
8988 case VKI_V4L2_S_FREQUENCY
: {
8989 struct vki_v4l2_frequency
*data
= (struct vki_v4l2_frequency
*)(Addr
)ARG3
;
8990 PRE_MEM_READ("ioctl(VKI_V4L2_S_FREQUENCY)", (Addr
)data
, sizeof(*data
));
8993 case VKI_V4L2_CROPCAP
: {
8994 struct vki_v4l2_cropcap
*data
= (struct vki_v4l2_cropcap
*)(Addr
)ARG3
;
8995 PRE_FIELD_READ("ioctl(VKI_V4L2_CROPCAP)", data
->type
);
8996 PRE_MEM_WRITE("ioctl(VKI_V4L2_CROPCAP)", (Addr
)&data
->bounds
, sizeof(*data
) - sizeof(data
->type
));
8999 case VKI_V4L2_G_CROP
: {
9000 struct vki_v4l2_crop
*data
= (struct vki_v4l2_crop
*)(Addr
)ARG3
;
9001 PRE_FIELD_READ("ioctl(VKI_V4L2_G_CROP).type", data
->type
);
9002 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_CROP).c", data
->c
);
9005 case VKI_V4L2_S_CROP
: {
9006 struct vki_v4l2_crop
*data
= (struct vki_v4l2_crop
*)(Addr
)ARG3
;
9007 PRE_MEM_READ("ioctl(VKI_V4L2_S_CROP)", (Addr
)data
, sizeof(*data
));
9010 case VKI_V4L2_G_JPEGCOMP
: {
9011 struct vki_v4l2_jpegcompression
*data
=
9012 (struct vki_v4l2_jpegcompression
*)(Addr
)ARG3
;
9013 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_JPEGCOMP)", (Addr
)data
, sizeof(*data
));
9016 case VKI_V4L2_S_JPEGCOMP
: {
9017 struct vki_v4l2_jpegcompression
*data
=
9018 (struct vki_v4l2_jpegcompression
*)(Addr
)ARG3
;
9019 PRE_MEM_READ("ioctl(VKI_V4L2_S_JPEGCOMP)", (Addr
)data
, sizeof(*data
));
9022 case VKI_V4L2_QUERYSTD
: {
9023 vki_v4l2_std_id
*data
= (vki_v4l2_std_id
*)(Addr
)ARG3
;
9024 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYSTD)", (Addr
)data
, sizeof(*data
));
9027 case VKI_V4L2_ENUMAUDIO
: {
9028 struct vki_v4l2_audio
*data
= (struct vki_v4l2_audio
*)(Addr
)ARG3
;
9029 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDIO).index", data
->index
);
9030 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDIO).reserved", data
->reserved
);
9031 PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMAUDIO)", (Addr
)data
->name
,
9032 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
9035 case VKI_V4L2_ENUMAUDOUT
: {
9036 struct vki_v4l2_audioout
*data
= (struct vki_v4l2_audioout
*)(Addr
)ARG3
;
9037 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDOUT).index", data
->index
);
9038 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDOUT).reserved", data
->reserved
);
9039 PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMAUDOUT)", (Addr
)data
->name
,
9040 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
9043 case VKI_V4L2_G_PRIORITY
: {
9044 __vki_u32
*data
= (__vki_u32
*)(Addr
)ARG3
;
9045 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_PRIORITY)", (Addr
)data
, sizeof(*data
));
9048 case VKI_V4L2_S_PRIORITY
: {
9049 __vki_u32
*data
= (__vki_u32
*)(Addr
)ARG3
;
9050 PRE_MEM_READ("ioctl(VKI_V4L2_S_PRIORITY)", (Addr
)data
, sizeof(*data
));
9053 case VKI_V4L2_G_SLICED_VBI_CAP
: {
9054 struct vki_v4l2_sliced_vbi_cap
*data
=
9055 (struct vki_v4l2_sliced_vbi_cap
*)(Addr
)ARG3
;
9056 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SLICED_VBI_CAP).type", data
->type
);
9057 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SLICED_VBI_CAP).reserved", data
->reserved
);
9058 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_SLICED_VBI_CAP)", (Addr
)data
,
9059 sizeof(*data
) - sizeof(data
->type
) - sizeof(data
->reserved
));
9062 case VKI_V4L2_G_EXT_CTRLS
: {
9063 struct vki_v4l2_ext_controls
*data
=
9064 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
9065 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).ctrl_class", data
->ctrl_class
);
9066 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).count", data
->count
);
9070 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls", data
->controls
);
9071 for (i
= 0; i
< data
->count
; i
++) {
9072 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].id", data
->controls
[i
].id
);
9073 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].size", data
->controls
[i
].size
);
9074 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].reserved2", data
->controls
[i
].reserved2
);
9075 if (data
->controls
[i
].size
) {
9076 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].ptr", data
->controls
[i
].ptr
);
9077 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].ptr[]",
9078 (Addr
)data
->controls
[i
].ptr
, data
->controls
[i
].size
);
9080 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].value64",
9081 data
->controls
[i
].value64
);
9085 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_EXT_CTRLS).error_idx", data
->error_idx
);
9086 PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).reserved", data
->reserved
);
9089 case VKI_V4L2_S_EXT_CTRLS
: {
9090 struct vki_v4l2_ext_controls
*data
=
9091 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
9092 PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).ctrl_class", data
->ctrl_class
);
9093 PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).count", data
->count
);
9097 PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).controls", data
->controls
);
9098 PRE_MEM_READ("ioctl(VKI_V4L2_S_EXT_CTRLS)", (Addr
)data
->controls
,
9099 data
->count
* sizeof(data
->controls
[0]));
9100 for (i
= 0; i
< data
->count
; i
++) {
9101 if (data
->controls
[i
].size
) {
9102 PRE_MEM_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).controls[].ptr[]",
9103 (Addr
)data
->controls
[i
].ptr
, data
->controls
[i
].size
);
9107 PRE_FIELD_WRITE("ioctl(VKI_V4L2_S_EXT_CTRLS).error_idx", data
->error_idx
);
9108 PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).reserved", data
->reserved
);
9111 case VKI_V4L2_TRY_EXT_CTRLS
: {
9112 struct vki_v4l2_ext_controls
*data
=
9113 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
9114 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).ctrl_class", data
->ctrl_class
);
9115 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).count", data
->count
);
9119 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).controls", data
->controls
);
9120 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS)", (Addr
)data
->controls
,
9121 data
->count
* sizeof(data
->controls
[0]));
9122 for (i
= 0; i
< data
->count
; i
++) {
9123 if (data
->controls
[i
].size
) {
9124 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).controls[].ptr[]",
9125 (Addr
)data
->controls
[i
].ptr
, data
->controls
[i
].size
);
9129 PRE_FIELD_WRITE("ioctl(VKI_V4L2_TRY_EXT_CTRLS).error_idx", data
->error_idx
);
9130 PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).reserved", data
->reserved
);
9133 case VKI_V4L2_ENUM_FRAMESIZES
: {
9134 struct vki_v4l2_frmsizeenum
*data
=
9135 (struct vki_v4l2_frmsizeenum
*)(Addr
)ARG3
;
9136 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMESIZES).index", data
->index
);
9137 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMESIZES).pixel_format", data
->pixel_format
);
9138 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMESIZES).reserved", data
->reserved
);
9139 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMESIZES).type", data
->type
);
9140 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMESIZES).stepwise", data
->stepwise
);
9143 case VKI_V4L2_ENUM_FRAMEINTERVALS
: {
9144 struct vki_v4l2_frmivalenum
*data
=
9145 (struct vki_v4l2_frmivalenum
*)(Addr
)ARG3
;
9146 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).index", data
->index
);
9147 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).pixel_format", data
->pixel_format
);
9148 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).width", data
->width
);
9149 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).height", data
->height
);
9150 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).reserved", data
->reserved
);
9151 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).type", data
->type
);
9152 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).stepwise", data
->stepwise
);
9155 case VKI_V4L2_G_ENC_INDEX
: {
9156 struct vki_v4l2_enc_idx
*data
= (struct vki_v4l2_enc_idx
*)(Addr
)ARG3
;
9157 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_ENC_INDEX)", (Addr
)data
, sizeof(*data
));
9160 case VKI_V4L2_ENCODER_CMD
: {
9161 struct vki_v4l2_encoder_cmd
*data
=
9162 (struct vki_v4l2_encoder_cmd
*)(Addr
)ARG3
;
9163 PRE_MEM_READ("ioctl(VKI_V4L2_ENCODER_CMD)", (Addr
)data
, sizeof(*data
));
9166 case VKI_V4L2_TRY_ENCODER_CMD
: {
9167 struct vki_v4l2_encoder_cmd
*data
=
9168 (struct vki_v4l2_encoder_cmd
*)(Addr
)ARG3
;
9169 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_ENCODER_CMD)", (Addr
)data
, sizeof(*data
));
9172 case VKI_V4L2_DBG_S_REGISTER
: {
9173 struct vki_v4l2_dbg_register
*data
=
9174 (struct vki_v4l2_dbg_register
*)(Addr
)ARG3
;
9175 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).match.type", data
->match
.type
);
9176 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).match.addr", data
->match
.addr
);
9177 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).reg", data
->reg
);
9178 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).val", data
->val
);
9179 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_S_REGISTER).size", data
->size
);
9182 case VKI_V4L2_DBG_G_REGISTER
: {
9183 struct vki_v4l2_dbg_register
*data
=
9184 (struct vki_v4l2_dbg_register
*)(Addr
)ARG3
;
9185 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_REGISTER).match.type", data
->match
.type
);
9186 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_REGISTER).match.addr", data
->match
.addr
);
9187 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_REGISTER).reg", data
->reg
);
9188 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_REGISTER).val", data
->val
);
9189 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_REGISTER).size", data
->size
);
9192 case VKI_V4L2_S_HW_FREQ_SEEK
: {
9193 struct vki_v4l2_hw_freq_seek
*data
=
9194 (struct vki_v4l2_hw_freq_seek
*)(Addr
)ARG3
;
9195 PRE_MEM_READ("ioctl(VKI_V4L2_S_HW_FREQ_SEEK)", (Addr
)data
, sizeof(*data
));
9198 case VKI_V4L2_S_DV_TIMINGS
: {
9199 struct vki_v4l2_dv_timings
*data
=
9200 (struct vki_v4l2_dv_timings
*)(Addr
)ARG3
;
9201 PRE_FIELD_READ("ioctl(VKI_V4L2_S_DV_TIMINGS).type", data
->type
);
9202 PRE_FIELD_READ("ioctl(VKI_V4L2_S_DV_TIMINGS).bt", data
->bt
);
9205 case VKI_V4L2_G_DV_TIMINGS
: {
9206 struct vki_v4l2_dv_timings
*data
=
9207 (struct vki_v4l2_dv_timings
*)(Addr
)ARG3
;
9208 PRE_MEM_WRITE("ioctl(VKI_V4L2_G_DV_TIMINGS)", (Addr
)data
, sizeof(*data
));
9211 case VKI_V4L2_DQEVENT
: {
9212 struct vki_v4l2_event
*data
= (struct vki_v4l2_event
*)(Addr
)ARG3
;
9213 PRE_MEM_WRITE("ioctl(VKI_V4L2_DQEVENT)", (Addr
)data
, sizeof(*data
));
9216 case VKI_V4L2_SUBSCRIBE_EVENT
: {
9217 struct vki_v4l2_event_subscription
*data
=
9218 (struct vki_v4l2_event_subscription
*)(Addr
)ARG3
;
9219 PRE_MEM_READ("ioctl(VKI_V4L2_SUBSCRIBE_EVENT)", (Addr
)data
, sizeof(*data
));
9222 case VKI_V4L2_UNSUBSCRIBE_EVENT
: {
9223 struct vki_v4l2_event_subscription
*data
=
9224 (struct vki_v4l2_event_subscription
*)(Addr
)ARG3
;
9225 PRE_MEM_READ("ioctl(VKI_V4L2_UNSUBSCRIBE_EVENT)", (Addr
)data
, sizeof(*data
));
9228 case VKI_V4L2_CREATE_BUFS
: {
9229 struct vki_v4l2_create_buffers
*data
=
9230 (struct vki_v4l2_create_buffers
*)(Addr
)ARG3
;
9231 struct vki_v4l2_format
*fmt
= &data
->format
;
9232 PRE_FIELD_WRITE("ioctl(VKI_V4L2_CREATE_BUFS).index", data
->index
);
9233 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).count", data
->count
);
9234 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).memory", data
->memory
);
9235 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).reserved", data
->reserved
);
9236 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.type", fmt
->type
);
9237 switch (fmt
->type
) {
9238 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE
:
9239 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
:
9240 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.pix", fmt
->fmt
.raw_data
);
9242 case VKI_V4L2_BUF_TYPE_VBI_CAPTURE
:
9243 case VKI_V4L2_BUF_TYPE_VBI_OUTPUT
:
9244 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.vbi", fmt
->fmt
.vbi
);
9246 case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
9247 case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
9248 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.sliced", fmt
->fmt
.sliced
);
9250 case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY
:
9251 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
9252 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.win", fmt
->fmt
.win
);
9254 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
9255 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
9256 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.pix_mp", fmt
->fmt
.pix_mp
);
9258 case VKI_V4L2_BUF_TYPE_SDR_CAPTURE
:
9259 PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.sdr", fmt
->fmt
.sdr
);
9264 case VKI_V4L2_PREPARE_BUF
: {
9265 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
9266 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).index", data
->index
);
9267 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).type", data
->type
);
9268 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).memory", data
->memory
);
9269 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).reserved", data
->reserved
);
9270 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).reserved2", data
->reserved2
);
9271 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
9272 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
9275 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).length", data
->length
);
9276 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).m.planes", data
->m
.planes
);
9277 for (i
= 0; i
< data
->length
; i
++) {
9278 PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).m.planes[].reserved", data
->m
.planes
[i
].reserved
);
9283 case VKI_V4L2_G_SELECTION
: {
9284 struct vki_v4l2_selection
*data
= (struct vki_v4l2_selection
*)(Addr
)ARG3
;
9285 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).type", data
->type
);
9286 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).target", data
->target
);
9287 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).flags", data
->flags
);
9288 PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).reserved", data
->reserved
);
9289 PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_SELECTION).r", data
->r
);
9292 case VKI_V4L2_S_SELECTION
: {
9293 struct vki_v4l2_selection
*data
= (struct vki_v4l2_selection
*)(Addr
)ARG3
;
9294 PRE_MEM_READ("ioctl(VKI_V4L2_S_SELECTION)", (Addr
)data
, sizeof(*data
));
9297 case VKI_V4L2_DECODER_CMD
: {
9298 struct vki_v4l2_decoder_cmd
*data
=
9299 (struct vki_v4l2_decoder_cmd
*)(Addr
)ARG3
;
9300 PRE_MEM_READ("ioctl(VKI_V4L2_DECODER_CMD)", (Addr
)data
, sizeof(*data
));
9303 case VKI_V4L2_TRY_DECODER_CMD
: {
9304 struct vki_v4l2_decoder_cmd
*data
=
9305 (struct vki_v4l2_decoder_cmd
*)(Addr
)ARG3
;
9306 PRE_MEM_READ("ioctl(VKI_V4L2_TRY_DECODER_CMD)", (Addr
)data
, sizeof(*data
));
9309 case VKI_V4L2_ENUM_DV_TIMINGS
: {
9310 struct vki_v4l2_enum_dv_timings
*data
=
9311 (struct vki_v4l2_enum_dv_timings
*)(Addr
)ARG3
;
9312 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).index", data
->index
);
9313 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).pad", data
->pad
);
9314 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).reserved", data
->reserved
);
9315 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).timings", data
->timings
);
9318 case VKI_V4L2_QUERY_DV_TIMINGS
: {
9319 struct vki_v4l2_dv_timings
*data
=
9320 (struct vki_v4l2_dv_timings
*)(Addr
)ARG3
;
9321 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERY_DV_TIMINGS)", (Addr
)data
, sizeof(*data
));
9324 case VKI_V4L2_DV_TIMINGS_CAP
: {
9325 struct vki_v4l2_dv_timings_cap
*data
=
9326 (struct vki_v4l2_dv_timings_cap
*)(Addr
)ARG3
;
9327 PRE_MEM_WRITE("ioctl(VKI_V4L2_DV_TIMINGS_CAP)", (Addr
)data
, sizeof(*data
));
9330 case VKI_V4L2_ENUM_FREQ_BANDS
: {
9331 struct vki_v4l2_frequency_band
*data
=
9332 (struct vki_v4l2_frequency_band
*)(Addr
)ARG3
;
9333 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).tuner", data
->tuner
);
9334 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).type", data
->type
);
9335 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).index", data
->index
);
9336 PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).reserved", data
->reserved
);
9337 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).capability", data
->capability
);
9338 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).rangelow", data
->rangelow
);
9339 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).rangehigh", data
->rangehigh
);
9340 PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).modulation", data
->modulation
);
9343 case VKI_V4L2_DBG_G_CHIP_INFO
: {
9344 struct vki_v4l2_dbg_chip_info
*data
=
9345 (struct vki_v4l2_dbg_chip_info
*)(Addr
)ARG3
;
9346 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).match.type", data
->match
.type
);
9347 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).match.addr", data
->match
.addr
);
9348 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).name", data
->name
);
9349 PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).flags", data
->flags
);
9350 PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).reserved", data
->reserved
);
9353 case VKI_V4L2_QUERY_EXT_CTRL
: {
9354 struct vki_v4l2_query_ext_ctrl
*data
=
9355 (struct vki_v4l2_query_ext_ctrl
*)(Addr
)ARG3
;
9356 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERY_EXT_CTRL).id", data
->id
);
9357 PRE_FIELD_READ("ioctl(VKI_V4L2_QUERY_EXT_CTRL).reserved", data
->reserved
);
9358 PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERY_EXT_CTRL)", (Addr
)&data
->type
,
9359 sizeof(*data
) - sizeof(data
->id
) - sizeof(data
->reserved
));
9362 case VKI_V4L2_SUBDEV_G_FMT
: {
9363 struct vki_v4l2_subdev_format
*data
=
9364 (struct vki_v4l2_subdev_format
*)(Addr
)ARG3
;
9365 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FMT).pad", data
->pad
);
9366 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FMT).which", data
->which
);
9367 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FMT).reserved", data
->reserved
);
9368 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_FMT).format", data
->format
);
9371 case VKI_V4L2_SUBDEV_S_FMT
: {
9372 struct vki_v4l2_subdev_format
*data
=
9373 (struct vki_v4l2_subdev_format
*)(Addr
)ARG3
;
9374 PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_FMT)", (Addr
)data
, sizeof(*data
));
9377 case VKI_V4L2_SUBDEV_G_FRAME_INTERVAL
: {
9378 struct vki_v4l2_subdev_frame_interval
*data
=
9379 (struct vki_v4l2_subdev_frame_interval
*)(Addr
)ARG3
;
9380 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FRAME_SIZE).pad", data
->pad
);
9381 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FRAME_SIZE).reserved", data
->reserved
);
9382 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_FRAME_SIZE).interval", data
->interval
);
9385 case VKI_V4L2_SUBDEV_S_FRAME_INTERVAL
: {
9386 struct vki_v4l2_subdev_frame_interval
*data
=
9387 (struct vki_v4l2_subdev_frame_interval
*)(Addr
)ARG3
;
9388 PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_FRAME_INTERVAL)", (Addr
)data
, sizeof(*data
));
9391 case VKI_V4L2_SUBDEV_ENUM_MBUS_CODE
: {
9392 struct vki_v4l2_subdev_mbus_code_enum
*data
=
9393 (struct vki_v4l2_subdev_mbus_code_enum
*)(Addr
)ARG3
;
9394 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).index", data
->index
);
9395 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).pad", data
->pad
);
9396 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).code", data
->code
);
9397 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).which", data
->which
);
9398 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).reserved", data
->reserved
);
9401 case VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE
: {
9402 struct vki_v4l2_subdev_frame_size_enum
*data
=
9403 (struct vki_v4l2_subdev_frame_size_enum
*)(Addr
)ARG3
;
9404 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).index", data
->index
);
9405 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).pad", data
->pad
);
9406 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).code", data
->code
);
9407 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).which", data
->which
);
9408 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).reserved", data
->reserved
);
9409 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).min_width", data
->min_width
);
9410 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).min_height", data
->min_height
);
9411 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).max_width", data
->max_width
);
9412 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).max_height", data
->max_height
);
9415 case VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL
: {
9416 struct vki_v4l2_subdev_frame_interval_enum
*data
=
9417 (struct vki_v4l2_subdev_frame_interval_enum
*)(Addr
)ARG3
;
9418 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).index", data
->index
);
9419 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).pad", data
->pad
);
9420 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).code", data
->code
);
9421 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).width", data
->width
);
9422 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).height", data
->height
);
9423 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).which", data
->which
);
9424 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).reserved", data
->reserved
);
9425 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).interval", data
->interval
);
9428 case VKI_V4L2_SUBDEV_G_CROP
: {
9429 struct vki_v4l2_subdev_crop
*data
=
9430 (struct vki_v4l2_subdev_crop
*)(Addr
)ARG3
;
9431 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_CROP).pad", data
->pad
);
9432 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_CROP).which", data
->which
);
9433 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_CROP).reserved", data
->reserved
);
9434 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_CROP).rect", data
->rect
);
9437 case VKI_V4L2_SUBDEV_S_CROP
: {
9438 struct vki_v4l2_subdev_crop
*data
=
9439 (struct vki_v4l2_subdev_crop
*)(Addr
)ARG3
;
9440 PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_CROP)", (Addr
)data
, sizeof(*data
));
9443 case VKI_V4L2_SUBDEV_G_SELECTION
: {
9444 struct vki_v4l2_subdev_selection
*data
=
9445 (struct vki_v4l2_subdev_selection
*)(Addr
)ARG3
;
9446 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).pad", data
->pad
);
9447 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).which", data
->which
);
9448 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).target", data
->target
);
9449 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).flags", data
->flags
);
9450 PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).reserved", data
->reserved
);
9451 PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).r", data
->r
);
9454 case VKI_V4L2_SUBDEV_S_SELECTION
: {
9455 struct vki_v4l2_subdev_selection
*data
=
9456 (struct vki_v4l2_subdev_selection
*)(Addr
)ARG3
;
9457 PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_SELECTION)", (Addr
)data
, sizeof(*data
));
9460 case VKI_MEDIA_IOC_DEVICE_INFO
: {
9461 struct vki_media_device_info
*data
=
9462 (struct vki_media_device_info
*)(Addr
)ARG3
;
9463 PRE_FIELD_READ("ioctl(VKI_MEDIA_IOC_DEVICE_INFO).reserved", data
->reserved
);
9464 PRE_MEM_WRITE("ioctl(VKI_MEDIA_IOC_DEVICE_INFO)",
9465 (Addr
)data
, sizeof(*data
) - sizeof(data
->reserved
));
9468 case VKI_MEDIA_IOC_ENUM_ENTITIES
: {
9469 struct vki_media_entity_desc
*data
=
9470 (struct vki_media_entity_desc
*)(Addr
)ARG3
;
9471 PRE_FIELD_READ("ioctl(VKI_MEDIA_IOC_ENUM_ENTITIES).id", data
->id
);
9472 PRE_MEM_WRITE("ioctl(VKI_MEDIA_IOC_ENUM_ENTITIES)",
9473 (Addr
)data
->name
, sizeof(*data
) - sizeof(data
->id
));
9476 case VKI_MEDIA_IOC_ENUM_LINKS
: {
9477 struct vki_media_links_enum
*data
=
9478 (struct vki_media_links_enum
*)(Addr
)ARG3
;
9479 PRE_MEM_READ("ioctl(VKI_MEDIA_IOC_ENUM_LINKS)", (Addr
)data
, sizeof(*data
));
9482 case VKI_MEDIA_IOC_SETUP_LINK
: {
9483 struct vki_media_link_desc
*data
=
9484 (struct vki_media_link_desc
*)(Addr
)ARG3
;
9485 PRE_MEM_READ("ioctl(VKI_MEDIA_IOC_SETUP_LINK)", (Addr
)data
, sizeof(*data
));
9490 case VKI_TIOCGSERIAL
: {
9491 struct vki_serial_struct
*data
= (struct vki_serial_struct
*)(Addr
)ARG3
;
9492 PRE_MEM_WRITE("ioctl(VKI_TIOCGSERIAL)", (Addr
)data
, sizeof(*data
));
9495 case VKI_TIOCSSERIAL
: {
9496 struct vki_serial_struct
*data
= (struct vki_serial_struct
*)(Addr
)ARG3
;
9497 PRE_MEM_READ("ioctl(VKI_TIOCSSERIAL)", (Addr
)data
, sizeof(*data
));
9501 case VKI_PERF_EVENT_IOC_RESET
:
9502 case VKI_PERF_EVENT_IOC_REFRESH
:
9503 case VKI_PERF_EVENT_IOC_SET_OUTPUT
:
9504 case VKI_PERF_EVENT_IOC_SET_BPF
:
9505 /* These take scalar arguments, so already handled above */
9508 case VKI_PERF_EVENT_IOC_PERIOD
:
9509 PRE_MEM_READ("ioctl(VKI_PERF_EVENT_IOC_PERIOD)", (Addr
)ARG3
, sizeof(__vki_u64
));
9512 case VKI_PERF_EVENT_IOC_SET_FILTER
:
9513 PRE_MEM_RASCIIZ("ioctl(VKI_PERF_EVENT_IOC_SET_FILTER).filter", ARG3
);
9516 case VKI_PERF_EVENT_IOC_ID
:
9517 PRE_MEM_WRITE("ioctl(VKI_PERF_EVENT_IOC_ID)", (Addr
)ARG3
, sizeof(__vki_u64
));
9520 /* Pulse Per Second (PPS) */
9521 case VKI_PPS_GETPARAMS
: {
9522 struct vki_pps_kparams
*data
= (struct vki_pps_kparams
*)(Addr
)ARG3
;
9523 PRE_MEM_WRITE("ioctl(PPS_GETPARAMS)", (Addr
)data
, sizeof(*data
));
9526 case VKI_PPS_SETPARAMS
: {
9527 struct vki_pps_kparams
*data
= (struct vki_pps_kparams
*)(Addr
)ARG3
;
9528 PRE_FIELD_READ("ioctl(PPS_SETPARAMS).mode", data
->mode
);
9529 PRE_FIELD_READ("ioctl(PPS_SETPARAMS).assert_off_tu.sec",
9530 data
->assert_off_tu
.sec
);
9531 PRE_FIELD_READ("ioctl(PPS_SETPARAMS).assert_off_tu.nsec",
9532 data
->assert_off_tu
.nsec
);
9533 PRE_FIELD_READ("ioctl(PPS_SETPARAMS).clear_off_tu.sec",
9534 data
->clear_off_tu
.sec
);
9535 PRE_FIELD_READ("ioctl(PPS_SETPARAMS).clear_off_tu.nsec",
9536 data
->clear_off_tu
.nsec
);
9539 case VKI_PPS_GETCAP
:
9540 PRE_MEM_WRITE("ioctl(PPS_GETCAP)", (Addr
)ARG3
, sizeof(int));
9542 case VKI_PPS_FETCH
: {
9543 struct vki_pps_fdata
*data
= (struct vki_pps_fdata
*)(Addr
)ARG3
;
9544 PRE_FIELD_READ("ioctl(PPS_FETCH).timeout", data
->timeout
);
9545 PRE_FIELD_WRITE("ioctl(PPS_FETCH).info", data
->info
);
9548 case VKI_PPS_KC_BIND
: {
9549 struct vki_pps_bind_args
*data
= (struct vki_pps_bind_args
*)(Addr
)ARG3
;
9550 PRE_MEM_READ("ioctl(PPS_KC_BIND)", (Addr
)data
, sizeof(*data
));
9554 /* PTP Hardware Clock */
9555 case VKI_PTP_CLOCK_GETCAPS
: {
9556 struct vki_ptp_clock_caps
*data
=
9557 (struct vki_ptp_clock_caps
*)(Addr
)ARG3
;
9558 PRE_MEM_WRITE("ioctl(PTP_CLOCK_GETCAPS)", (Addr
)data
, sizeof(*data
));
9561 case VKI_PTP_EXTTS_REQUEST
: {
9562 struct vki_ptp_extts_request
*data
=
9563 (struct vki_ptp_extts_request
*)(Addr
)ARG3
;
9564 PRE_MEM_READ("ioctl(PTP_EXTTS_REQUEST)", (Addr
)data
, sizeof(*data
));
9567 case VKI_PTP_PEROUT_REQUEST
: {
9568 struct vki_ptp_perout_request
*data
=
9569 (struct vki_ptp_perout_request
*)(Addr
)ARG3
;
9570 PRE_MEM_READ("ioctl(PTP_PEROUT_REQUEST)", (Addr
)data
, sizeof(*data
));
9573 case VKI_PTP_ENABLE_PPS
:
9575 case VKI_PTP_SYS_OFFSET
: {
9576 struct vki_ptp_sys_offset
*data
=
9577 (struct vki_ptp_sys_offset
*)(Addr
)ARG3
;
9578 PRE_FIELD_READ("ioctl(PTP_SYS_OFFSET).n_samples", data
->n_samples
);
9579 if (data
->n_samples
<= VKI_PTP_MAX_SAMPLES
)
9580 PRE_MEM_WRITE("ioctl(PTP_SYS_OFFSET).ts", (Addr
)data
->ts
,
9581 (2 * data
->n_samples
+ 1) * sizeof(data
->ts
[0]));
9584 case VKI_PTP_PIN_GETFUNC
: {
9585 struct vki_ptp_pin_desc
*data
= (struct vki_ptp_pin_desc
*)(Addr
)ARG3
;
9586 PRE_FIELD_READ("ioctl(PTP_PIN_GETFUNC).index", data
->index
);
9587 PRE_MEM_WRITE("ioctl(PTP_PIN_GETFUNC)", (Addr
)data
, sizeof(*data
));
9590 case VKI_PTP_PIN_SETFUNC
: {
9591 struct vki_ptp_pin_desc
*data
= (struct vki_ptp_pin_desc
*)(Addr
)ARG3
;
9592 PRE_FIELD_READ("ioctl(PTP_PIN_SETFUNC).index", data
->index
);
9593 PRE_FIELD_READ("ioctl(PTP_PIN_SETFUNC).func", data
->func
);
9594 PRE_FIELD_READ("ioctl(PTP_PIN_SETFUNC).chan", data
->chan
);
9597 case VKI_PTP_SYS_OFFSET_PRECISE
: {
9598 struct vki_ptp_sys_offset_precise
*data
=
9599 (struct vki_ptp_sys_offset_precise
*)(Addr
)ARG3
;
9600 PRE_MEM_WRITE("ioctl(PTP_SYS_OFFSET_PRECISE)", (Addr
)data
, sizeof(*data
));
9603 case VKI_PTP_SYS_OFFSET_EXTENDED
: {
9604 struct vki_ptp_sys_offset_extended
*data
=
9605 (struct vki_ptp_sys_offset_extended
*)(Addr
)ARG3
;
9606 PRE_FIELD_READ("ioctl(PTP_SYS_OFFSET_EXTENDED).n_samples", data
->n_samples
);
9607 PRE_FIELD_READ("ioctl(PTP_SYS_OFFSET_EXTENDED).rsv", data
->rsv
);
9608 if (data
->n_samples
<= VKI_PTP_MAX_SAMPLES
)
9609 PRE_MEM_WRITE("ioctl(PTP_SYS_OFFSET_EXTENDED).ts", (Addr
)data
->ts
,
9610 3 * data
->n_samples
* sizeof(data
->ts
[0][0]));
9615 /* EVIOC* are variable length and return size written on success */
9616 switch (ARG2
& ~(_VKI_IOC_SIZEMASK
<< _VKI_IOC_SIZESHIFT
)) {
9617 case VKI_EVIOCGNAME(0):
9618 case VKI_EVIOCGPHYS(0):
9619 case VKI_EVIOCGUNIQ(0):
9620 case VKI_EVIOCGKEY(0):
9621 case VKI_EVIOCGLED(0):
9622 case VKI_EVIOCGSND(0):
9623 case VKI_EVIOCGSW(0):
9624 case VKI_EVIOCGBIT(VKI_EV_SYN
,0):
9625 case VKI_EVIOCGBIT(VKI_EV_KEY
,0):
9626 case VKI_EVIOCGBIT(VKI_EV_REL
,0):
9627 case VKI_EVIOCGBIT(VKI_EV_ABS
,0):
9628 case VKI_EVIOCGBIT(VKI_EV_MSC
,0):
9629 case VKI_EVIOCGBIT(VKI_EV_SW
,0):
9630 case VKI_EVIOCGBIT(VKI_EV_LED
,0):
9631 case VKI_EVIOCGBIT(VKI_EV_SND
,0):
9632 case VKI_EVIOCGBIT(VKI_EV_REP
,0):
9633 case VKI_EVIOCGBIT(VKI_EV_FF
,0):
9634 case VKI_EVIOCGBIT(VKI_EV_PWR
,0):
9635 case VKI_EVIOCGBIT(VKI_EV_FF_STATUS
,0):
9636 PRE_MEM_WRITE("ioctl(EVIO*)", ARG3
, _VKI_IOC_SIZE(ARG2
));
9639 ML_(PRE_unknown_ioctl
)(tid
, ARG2
, ARG3
);
9650 vg_assert(SUCCESS
|| (FAILURE
&& VKI_DRM_IOCTL_VERSION
== ARG2
));
9652 /* --- BEGIN special IOCTL handlers for specific Android hardware --- */
9654 /* BEGIN undocumented ioctls for PowerVR SGX 540 (the GPU on Nexus S) */
9655 if (KernelVariantiS(KernelVariant_android_gpu_sgx5xx
,
9656 VG_(clo_kernel_variant
))) {
9658 if (ARG2
>= 0xC01C6700 && ARG2
<= 0xC01C67FF && ARG3
>= 0x1000) {
9659 /* What's going on here: there appear to be a bunch of ioctls
9660 of the form 0xC01C67xx which are undocumented, and if
9661 unhandled give rise to a vast number of false positives in
9664 The "normal" interpretation of an ioctl of this form would
9665 be that the 3rd arg is a pointer to an area of size 0x1C
9666 (28 bytes) which is filled in by the kernel. Hence you
9667 might think that "POST_MEM_WRITE(ARG3, 28)" would fix it.
9670 It requires POST_MEM_WRITE(ARG3, 256) to silence them.
9671 One interpretation of this is that ARG3 really does point
9672 to a 28 byte struct, but inside that are pointers to other
9673 areas also filled in by the kernel. If these happen to be
9674 allocated just back up the stack then the 256 byte paint
9675 might cover them too, somewhat indiscriminately.
9677 By printing out ARG3 and also the 28 bytes that it points
9678 at, it's possible to guess that the 7 word structure has
9682 ioctl-number 0x1C ptr1 ptr1size ptr2 ptr2size aBitMask
9684 Unfortunately that doesn't seem to work for some reason,
9685 so stay with the blunt-instrument approach for the time
9689 /* blunt-instrument approach */
9690 POST_MEM_WRITE(ARG3
, 256);
9692 /* be a bit more sophisticated */
9693 POST_MEM_WRITE(ARG3
, 28);
9694 UInt
* word
= (UInt
*)(Addr
)ARG3
;
9695 if (word
&& word
[2] && word
[3] < 0x200/*stay sane*/)
9696 POST_MEM_WRITE(word
[2], word
[3]); // "ptr1"
9697 if (word
&& word
[4] && word
[5] < 0x200/*stay sane*/)
9698 POST_MEM_WRITE(word
[4], word
[5]); // "ptr2"
9700 goto post_sys_ioctl__out
;
9703 /* END undocumented ioctls for PowerVR SGX 540 (the GPU on Nexus S) */
9705 /* BEGIN undocumented ioctls for Qualcomm Adreno 3xx */
9706 if (KernelVariantiS(KernelVariant_android_gpu_adreno3xx
,
9707 VG_(clo_kernel_variant
))) {
9708 if (ARG2
== 0xC00C0902) {
9709 POST_MEM_WRITE(ARG3
, 24); // 16 is not enough
9710 goto post_sys_ioctl__out
;
9713 /* END undocumented ioctls for Qualcomm Adreno 3xx */
9715 /* --- END special IOCTL handlers for specific Android hardware --- */
9717 /* --- normal handling --- */
9718 switch (ARG2
/* request */) {
9720 /* The Linux kernel "ion" memory allocator, used on Android. Note:
9721 this is pretty poor given that there's no pre-handling to check
9722 that writable areas are addressable. */
9723 case VKI_ION_IOC_ALLOC
: {
9724 struct vki_ion_allocation_data
* data
9725 = (struct vki_ion_allocation_data
*)(Addr
)ARG3
;
9726 POST_FIELD_WRITE(data
->handle
);
9729 case VKI_ION_IOC_MAP
: {
9730 struct vki_ion_fd_data
* data
= (struct vki_ion_fd_data
*)(Addr
)ARG3
;
9731 POST_FIELD_WRITE(data
->fd
);
9734 case VKI_ION_IOC_FREE
: // is this necessary?
9735 POST_MEM_WRITE(ARG3
, sizeof(struct vki_ion_handle_data
));
9737 case VKI_ION_IOC_SHARE
:
9739 case VKI_ION_IOC_IMPORT
: {
9740 struct vki_ion_fd_data
* data
= (struct vki_ion_fd_data
*)(Addr
)ARG3
;
9741 POST_FIELD_WRITE(data
->handle
);
9744 case VKI_ION_IOC_SYNC
:
9746 case VKI_ION_IOC_CUSTOM
: // is this necessary?
9747 POST_MEM_WRITE(ARG3
, sizeof(struct vki_ion_custom_data
));
9750 case VKI_SYNC_IOC_MERGE
: {
9751 struct vki_sync_merge_data
* data
=
9752 (struct vki_sync_merge_data
*)(Addr
)ARG3
;
9753 POST_FIELD_WRITE(data
->fence
);
9760 case VKI_IB_USER_MAD_ENABLE_PKEY
:
9763 POST_MEM_WRITE( ARG3
, sizeof(struct vki_termios
) );
9770 POST_MEM_WRITE( ARG3
, sizeof(struct vki_termio
) );
9778 case VKI_TIOCGWINSZ
:
9779 POST_MEM_WRITE( ARG3
, sizeof(struct vki_winsize
) );
9781 case VKI_TIOCSWINSZ
:
9787 POST_MEM_WRITE( ARG3
, sizeof(unsigned int) );
9790 POST_MEM_WRITE( ARG3
, sizeof(char *) );
9793 /* Get process group ID for foreground processing group. */
9794 POST_MEM_WRITE( ARG3
, sizeof(vki_pid_t
) );
9797 /* Set a process group ID? */
9798 POST_MEM_WRITE( ARG3
, sizeof(vki_pid_t
) );
9800 case VKI_TIOCGPTN
: /* Get Pty Number (of pty-mux device) */
9801 POST_MEM_WRITE( ARG3
, sizeof(int));
9805 case VKI_TIOCSPTLCK
: /* Lock/unlock Pty */
9817 case VKI_FIONREAD
: /* identical to SIOCINQ */
9818 POST_MEM_WRITE( ARG3
, sizeof(int) );
9821 POST_MEM_WRITE( ARG3
, sizeof(vki_loff_t
) );
9824 case VKI_TIOCSERGETLSR
:
9825 POST_MEM_WRITE( ARG3
, sizeof(int) );
9827 case VKI_TIOCGICOUNT
:
9828 POST_MEM_WRITE( ARG3
, sizeof(struct vki_serial_icounter_struct
) );
9831 case VKI_SG_SET_COMMAND_Q
:
9835 vki_sg_io_hdr_t
*sgio
= (vki_sg_io_hdr_t
*)(Addr
)ARG3
;
9837 POST_MEM_WRITE( (Addr
)sgio
->sbp
, sgio
->sb_len_wr
);
9839 if ( sgio
->dxfer_direction
== VKI_SG_DXFER_FROM_DEV
||
9840 sgio
->dxfer_direction
== VKI_SG_DXFER_TO_FROM_DEV
) {
9841 int transferred
= sgio
->dxfer_len
- sgio
->resid
;
9842 POST_MEM_WRITE( (Addr
)sgio
->dxferp
, transferred
);
9846 case VKI_SG_GET_SCSI_ID
:
9847 POST_MEM_WRITE(ARG3
, sizeof(vki_sg_scsi_id_t
));
9849 case VKI_SG_SET_RESERVED_SIZE
:
9851 case VKI_SG_SET_TIMEOUT
:
9853 case VKI_SG_GET_RESERVED_SIZE
:
9854 POST_MEM_WRITE(ARG3
, sizeof(int));
9856 case VKI_SG_GET_TIMEOUT
:
9858 case VKI_SG_GET_VERSION_NUM
:
9859 POST_MEM_WRITE(ARG3
, sizeof(int));
9861 case VKI_SG_EMULATED_HOST
:
9862 POST_MEM_WRITE(ARG3
, sizeof(int));
9864 case VKI_SG_GET_SG_TABLESIZE
:
9865 POST_MEM_WRITE(ARG3
, sizeof(int));
9868 case VKI_IIOCGETCPS
:
9869 POST_MEM_WRITE( ARG3
, VKI_ISDN_MAX_CHANNELS
* 2 * sizeof(unsigned long) );
9871 case VKI_IIOCNETGPN
:
9872 POST_MEM_WRITE( ARG3
, sizeof(vki_isdn_net_ioctl_phone
) );
9875 /* These all use struct ifreq AFAIK */
9876 case VKI_SIOCGIFINDEX
: /* get iface index */
9877 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_ifindex
,
9878 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_ifindex
));
9880 case VKI_SIOCGIFFLAGS
: /* get flags */
9881 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
,
9882 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
));
9884 case VKI_SIOCGIFHWADDR
: /* Get hardware address */
9885 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_hwaddr
,
9886 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_hwaddr
));
9888 case VKI_SIOCGIFMTU
: /* get MTU size */
9889 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_mtu
,
9890 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_mtu
) );
9892 case VKI_SIOCGIFADDR
: /* get PA address */
9893 case VKI_SIOCGIFDSTADDR
: /* get remote PA address */
9894 case VKI_SIOCGIFBRDADDR
: /* get broadcast PA address */
9895 case VKI_SIOCGIFNETMASK
: /* get network PA mask */
9897 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_addr
,
9898 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_addr
) );
9900 case VKI_SIOCGIFMETRIC
: /* get metric */
9902 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_metric
,
9903 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_metric
) );
9905 case VKI_SIOCGIFMAP
: /* Get device parameters */
9907 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_map
,
9908 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_map
) );
9911 case VKI_SIOCGIFTXQLEN
: /* Get the tx queue length */
9913 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_qlen
,
9914 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_qlen
) );
9916 case VKI_SIOCGIFNAME
: /* get iface name */
9918 (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
,
9919 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
) );
9921 case VKI_SIOCETHTOOL
: { /* ethtool(8) interface */
9922 struct vki_ifreq
*ir
= (struct vki_ifreq
*)(Addr
)ARG3
;
9923 switch ( *(vki_u32
*)ir
->vki_ifr_data
) {
9924 case VKI_ETHTOOL_GSET
:
9925 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_cmd
));
9927 case VKI_ETHTOOL_SSET
:
9929 case VKI_ETHTOOL_GDRVINFO
:
9930 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_drvinfo
) );
9932 case VKI_ETHTOOL_GREGS
:
9933 POST_MEM_WRITE( (Addr
)((struct vki_ethtool_regs
*)ir
->vki_ifr_data
)->data
,
9934 ((struct vki_ethtool_regs
*)ir
->vki_ifr_data
)->len
);
9936 case VKI_ETHTOOL_GWOL
:
9937 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_wolinfo
) );
9939 case VKI_ETHTOOL_SWOL
:
9941 case VKI_ETHTOOL_GMSGLVL
:
9942 case VKI_ETHTOOL_GLINK
:
9943 case VKI_ETHTOOL_GRXCSUM
:
9944 case VKI_ETHTOOL_GSG
:
9945 case VKI_ETHTOOL_GTSO
:
9946 case VKI_ETHTOOL_GUFO
:
9947 case VKI_ETHTOOL_GGSO
:
9948 case VKI_ETHTOOL_GFLAGS
:
9949 case VKI_ETHTOOL_GGRO
:
9950 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_value
));
9952 case VKI_ETHTOOL_SMSGLVL
:
9953 case VKI_ETHTOOL_SRXCSUM
:
9954 case VKI_ETHTOOL_SSG
:
9955 case VKI_ETHTOOL_STSO
:
9956 case VKI_ETHTOOL_SUFO
:
9957 case VKI_ETHTOOL_SGSO
:
9958 case VKI_ETHTOOL_SFLAGS
:
9959 case VKI_ETHTOOL_SGRO
:
9961 case VKI_ETHTOOL_NWAY_RST
:
9963 case VKI_ETHTOOL_GRINGPARAM
:
9964 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_ringparam
));
9966 case VKI_ETHTOOL_SRINGPARAM
:
9968 case VKI_ETHTOOL_TEST
:
9969 POST_MEM_WRITE( (Addr
)((struct vki_ethtool_test
*)ir
->vki_ifr_data
)->data
,
9970 ((struct vki_ethtool_test
*)ir
->vki_ifr_data
)->len
* sizeof(__vki_u64
) );
9972 case VKI_ETHTOOL_PHYS_ID
:
9974 case VKI_ETHTOOL_GPERMADDR
:
9975 POST_MEM_WRITE( (Addr
)((struct vki_ethtool_perm_addr
*)ir
->vki_ifr_data
)->data
,
9976 ((struct vki_ethtool_perm_addr
*)ir
->vki_ifr_data
)->size
);
9978 case VKI_ETHTOOL_RESET
:
9980 case VKI_ETHTOOL_GSSET_INFO
:
9981 POST_MEM_WRITE( (Addr
)((struct vki_ethtool_sset_info
*)ir
->vki_ifr_data
)->data
,
9982 __builtin_popcountll(((struct vki_ethtool_sset_info
*)ir
->vki_ifr_data
)->sset_mask
) * sizeof(__vki_u32
) );
9984 case VKI_ETHTOOL_GFEATURES
:
9985 POST_MEM_WRITE( (Addr
)((struct vki_ethtool_gfeatures
*)ir
->vki_ifr_data
)->features
,
9986 ((struct vki_ethtool_gfeatures
*)ir
->vki_ifr_data
)->size
* sizeof(struct vki_ethtool_get_features_block
) );
9988 case VKI_ETHTOOL_SFEATURES
:
9990 case VKI_ETHTOOL_GCHANNELS
:
9991 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_channels
) );
9993 case VKI_ETHTOOL_SCHANNELS
:
9995 case VKI_ETHTOOL_GET_TS_INFO
:
9996 POST_MEM_WRITE( (Addr
)ir
->vki_ifr_data
, sizeof(struct vki_ethtool_ts_info
) );
10001 case VKI_SIOCGMIIPHY
: /* get hardware entry */
10003 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
,
10004 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->phy_id
));
10006 case VKI_SIOCGMIIREG
: /* get hardware entry registers */
10008 (Addr
)&((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->val_out
,
10009 sizeof(((struct vki_mii_ioctl_data
*)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_data
)->val_out
));
10012 /* tun/tap related ioctls */
10013 case VKI_TUNSETIFF
:
10014 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
,
10015 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
) );
10017 case VKI_TUNGETFEATURES
:
10018 POST_MEM_WRITE( ARG3
, sizeof(unsigned int) );
10020 case VKI_TUNGETIFF
:
10021 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
,
10022 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_name
) );
10023 POST_MEM_WRITE( (Addr
)&((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
,
10024 sizeof(((struct vki_ifreq
*)(Addr
)ARG3
)->vki_ifr_flags
) );
10026 case VKI_TUNGETSNDBUF
:
10027 POST_MEM_WRITE( ARG3
, sizeof(int) );
10029 case VKI_TUNGETVNETHDRSZ
:
10030 POST_MEM_WRITE( ARG3
, sizeof(int) );
10033 case VKI_SIOCGIFCONF
: /* get iface list */
10035 PRE_MEM_WRITE("ioctl(SIOCGIFCONF)", ARG3, sizeof(struct ifconf));
10036 KERNEL_DO_SYSCALL(tid,RES);
10037 if (!VG_(is_kerror)(RES) && RES == 0)
10038 POST_MEM_WRITE(ARG3, sizeof(struct ifconf));
10040 if (RES
== 0 && ARG3
) {
10041 struct vki_ifconf
*ifc
= (struct vki_ifconf
*) (Addr
)ARG3
;
10042 if (ifc
->vki_ifc_buf
!= NULL
)
10043 POST_MEM_WRITE( (Addr
)(ifc
->vki_ifc_buf
), ifc
->ifc_len
);
10046 case VKI_SIOCGSTAMP
:
10047 POST_MEM_WRITE( ARG3
, sizeof(struct vki_timeval
) );
10049 case VKI_SIOCGSTAMPNS
:
10050 POST_MEM_WRITE( ARG3
, sizeof(struct vki_timespec
) );
10052 /* SIOCOUTQ is an ioctl that, when called on a socket, returns
10053 the number of bytes currently in that socket's send buffer.
10054 It writes this value as an int to the memory location
10055 indicated by the third argument of ioctl(2). */
10057 POST_MEM_WRITE(ARG3
, sizeof(int));
10059 case VKI_SIOCGRARP
: /* get RARP table entry */
10060 case VKI_SIOCGARP
: /* get ARP table entry */
10061 POST_MEM_WRITE(ARG3
, sizeof(struct vki_arpreq
));
10064 case VKI_SIOCSIFFLAGS
: /* set flags */
10065 case VKI_SIOCSIFMAP
: /* Set device parameters */
10066 case VKI_SIOCSHWTSTAMP
: /* Set hardware time stamping */
10067 case VKI_SIOCSIFTXQLEN
: /* Set the tx queue length */
10068 case VKI_SIOCSIFDSTADDR
: /* set remote PA address */
10069 case VKI_SIOCSIFBRDADDR
: /* set broadcast PA address */
10070 case VKI_SIOCSIFNETMASK
: /* set network PA mask */
10071 case VKI_SIOCSIFMETRIC
: /* set metric */
10072 case VKI_SIOCSIFADDR
: /* set PA address */
10073 case VKI_SIOCSIFMTU
: /* set MTU size */
10074 case VKI_SIOCSIFHWADDR
: /* set hardware address */
10075 case VKI_SIOCSMIIREG
: /* set hardware entry registers */
10077 /* Routing table calls. */
10078 case VKI_SIOCADDRT
: /* add routing table entry */
10079 case VKI_SIOCDELRT
: /* delete routing table entry */
10082 /* RARP cache control calls. */
10083 case VKI_SIOCDRARP
: /* delete RARP table entry */
10084 case VKI_SIOCSRARP
: /* set RARP table entry */
10085 /* ARP cache control calls. */
10086 case VKI_SIOCSARP
: /* set ARP table entry */
10087 case VKI_SIOCDARP
: /* delete ARP table entry */
10090 case VKI_SIOCGPGRP
:
10091 POST_MEM_WRITE(ARG3
, sizeof(int));
10093 case VKI_SIOCSPGRP
:
10096 case VKI_SIOCATMARK
:
10097 POST_MEM_WRITE(ARG3
, sizeof(int));
10100 /* linux/soundcard interface (OSS) */
10101 case VKI_SNDCTL_SEQ_GETOUTCOUNT
:
10102 case VKI_SNDCTL_SEQ_GETINCOUNT
:
10103 case VKI_SNDCTL_SEQ_PERCMODE
:
10104 case VKI_SNDCTL_SEQ_TESTMIDI
:
10105 case VKI_SNDCTL_SEQ_RESETSAMPLES
:
10106 case VKI_SNDCTL_SEQ_NRSYNTHS
:
10107 case VKI_SNDCTL_SEQ_NRMIDIS
:
10108 case VKI_SNDCTL_SEQ_GETTIME
:
10109 case VKI_SNDCTL_DSP_GETBLKSIZE
:
10110 case VKI_SNDCTL_DSP_GETFMTS
:
10111 case VKI_SNDCTL_DSP_SETFMT
:
10112 case VKI_SNDCTL_DSP_GETTRIGGER
:
10113 case VKI_SNDCTL_DSP_GETODELAY
:
10114 case VKI_SNDCTL_DSP_GETSPDIF
:
10115 case VKI_SNDCTL_DSP_GETCAPS
:
10116 case VKI_SOUND_PCM_READ_RATE
:
10117 case VKI_SOUND_PCM_READ_CHANNELS
:
10118 case VKI_SOUND_PCM_READ_BITS
:
10119 case VKI_SOUND_PCM_READ_FILTER
:
10120 POST_MEM_WRITE(ARG3
, sizeof(int));
10122 case VKI_SNDCTL_SEQ_CTRLRATE
:
10123 case VKI_SNDCTL_DSP_SPEED
:
10124 case VKI_SNDCTL_DSP_STEREO
:
10125 case VKI_SNDCTL_DSP_CHANNELS
:
10126 case VKI_SOUND_PCM_WRITE_FILTER
:
10127 case VKI_SNDCTL_DSP_SUBDIVIDE
:
10128 case VKI_SNDCTL_DSP_SETFRAGMENT
:
10129 case VKI_SNDCTL_DSP_GETCHANNELMASK
:
10130 case VKI_SNDCTL_DSP_BIND_CHANNEL
:
10131 case VKI_SNDCTL_TMR_TIMEBASE
:
10132 case VKI_SNDCTL_TMR_TEMPO
:
10133 case VKI_SNDCTL_TMR_SOURCE
:
10134 case VKI_SNDCTL_MIDI_PRETIME
:
10135 case VKI_SNDCTL_MIDI_MPUMODE
:
10137 case VKI_SNDCTL_DSP_GETOSPACE
:
10138 case VKI_SNDCTL_DSP_GETISPACE
:
10139 POST_MEM_WRITE(ARG3
, sizeof(vki_audio_buf_info
));
10141 case VKI_SNDCTL_DSP_NONBLOCK
:
10143 case VKI_SNDCTL_DSP_SETTRIGGER
:
10146 case VKI_SNDCTL_DSP_POST
:
10147 case VKI_SNDCTL_DSP_RESET
:
10148 case VKI_SNDCTL_DSP_SYNC
:
10149 case VKI_SNDCTL_DSP_SETSYNCRO
:
10150 case VKI_SNDCTL_DSP_SETDUPLEX
:
10153 /* linux/soundcard interface (ALSA) */
10154 case VKI_SNDRV_PCM_IOCTL_HW_FREE
:
10155 case VKI_SNDRV_PCM_IOCTL_HWSYNC
:
10156 case VKI_SNDRV_PCM_IOCTL_PREPARE
:
10157 case VKI_SNDRV_PCM_IOCTL_RESET
:
10158 case VKI_SNDRV_PCM_IOCTL_START
:
10159 case VKI_SNDRV_PCM_IOCTL_DROP
:
10160 case VKI_SNDRV_PCM_IOCTL_DRAIN
:
10161 case VKI_SNDRV_PCM_IOCTL_RESUME
:
10162 case VKI_SNDRV_PCM_IOCTL_XRUN
:
10163 case VKI_SNDRV_PCM_IOCTL_UNLINK
:
10164 case VKI_SNDRV_TIMER_IOCTL_START
:
10165 case VKI_SNDRV_TIMER_IOCTL_STOP
:
10166 case VKI_SNDRV_TIMER_IOCTL_CONTINUE
:
10167 case VKI_SNDRV_TIMER_IOCTL_PAUSE
:
10170 case VKI_SNDRV_CTL_IOCTL_PVERSION
: {
10171 POST_MEM_WRITE( (Addr
)ARG3
, sizeof(int) );
10174 case VKI_SNDRV_CTL_IOCTL_CARD_INFO
:
10175 POST_MEM_WRITE( (Addr
)ARG3
, sizeof(struct vki_snd_ctl_card_info
) );
10177 case VKI_SNDRV_CTL_IOCTL_ELEM_LIST
: {
10178 struct vki_snd_ctl_elem_list
*data
=
10179 (struct vki_snd_ctl_elem_list
*)(Addr
)ARG3
;
10180 POST_MEM_WRITE( (Addr
)&data
->used
, sizeof(data
->used
) );
10181 POST_MEM_WRITE( (Addr
)&data
->count
, sizeof(data
->count
) );
10183 POST_MEM_WRITE( (Addr
)data
->pids
, sizeof(struct vki_snd_ctl_elem_id
) * data
->used
);
10187 case VKI_SNDRV_CTL_IOCTL_TLV_READ
: {
10188 struct vki_snd_ctl_tlv
*data
= (struct vki_snd_ctl_tlv
*)(Addr
)ARG3
;
10189 POST_MEM_WRITE( (Addr
)data
->tlv
, data
->length
);
10192 case VKI_SNDRV_CTL_IOCTL_TLV_WRITE
:
10193 case VKI_SNDRV_CTL_IOCTL_TLV_COMMAND
:
10196 /* SCSI no operand */
10197 case VKI_SCSI_IOCTL_DOORLOCK
:
10198 case VKI_SCSI_IOCTL_DOORUNLOCK
:
10201 /* Real Time Clock (/dev/rtc) ioctls */
10202 case VKI_RTC_UIE_ON
:
10203 case VKI_RTC_UIE_OFF
:
10204 case VKI_RTC_AIE_ON
:
10205 case VKI_RTC_AIE_OFF
:
10206 case VKI_RTC_PIE_ON
:
10207 case VKI_RTC_PIE_OFF
:
10208 case VKI_RTC_IRQP_SET
:
10210 case VKI_RTC_RD_TIME
:
10211 case VKI_RTC_ALM_READ
:
10212 POST_MEM_WRITE(ARG3
, sizeof(struct vki_rtc_time
));
10214 case VKI_RTC_ALM_SET
:
10216 case VKI_RTC_IRQP_READ
:
10217 POST_MEM_WRITE(ARG3
, sizeof(unsigned long));
10220 /* Block devices */
10224 POST_MEM_WRITE(ARG3
, sizeof(int));
10226 case VKI_BLKGETSIZE
:
10227 POST_MEM_WRITE(ARG3
, sizeof(unsigned long));
10229 case VKI_BLKFLSBUF
:
10234 POST_MEM_WRITE(ARG3
, sizeof(long));
10236 case VKI_BLKFRASET
:
10238 case VKI_BLKFRAGET
:
10239 POST_MEM_WRITE(ARG3
, sizeof(long));
10241 case VKI_BLKSECTGET
:
10242 POST_MEM_WRITE(ARG3
, sizeof(unsigned short));
10244 case VKI_BLKSSZGET
:
10245 POST_MEM_WRITE(ARG3
, sizeof(int));
10247 case VKI_BLKBSZGET
:
10248 POST_MEM_WRITE(ARG3
, sizeof(int));
10250 case VKI_BLKBSZSET
:
10252 case VKI_BLKGETSIZE64
:
10253 POST_MEM_WRITE(ARG3
, sizeof(unsigned long long));
10255 case VKI_BLKPBSZGET
:
10256 POST_MEM_WRITE(ARG3
, sizeof(int));
10259 POST_MEM_WRITE(ARG3
, sizeof(vki_uint
));
10262 POST_MEM_WRITE(ARG3
, sizeof(vki_uint
));
10264 case VKI_BLKALIGNOFF
:
10265 POST_MEM_WRITE(ARG3
, sizeof(int));
10267 case VKI_BLKDISCARDZEROES
:
10268 POST_MEM_WRITE(ARG3
, sizeof(vki_uint
));
10270 case VKI_BLKREPORTZONE
: {
10271 const struct vki_blk_zone_report
*zr
= (void *)(Addr
)ARG3
;
10273 POST_MEM_WRITE(ARG3
, sizeof(*zr
) + zr
->nr_zones
* sizeof(zr
->zones
[0]));
10276 case VKI_BLKRESETZONE
:
10280 case VKI_HDIO_GETGEO
: /* 0x0301 */
10281 POST_MEM_WRITE(ARG3
, sizeof(struct vki_hd_geometry
));
10283 case VKI_HDIO_GET_DMA
: /* 0x030b */
10284 POST_MEM_WRITE(ARG3
, sizeof(long));
10286 case VKI_HDIO_GET_IDENTITY
: /* 0x030d */
10287 POST_MEM_WRITE(ARG3
, VKI_SIZEOF_STRUCT_HD_DRIVEID
);
10291 case VKI_SCSI_IOCTL_GET_IDLUN
: /* 0x5382 */
10292 POST_MEM_WRITE(ARG3
, sizeof(struct vki_scsi_idlun
));
10294 case VKI_SCSI_IOCTL_GET_BUS_NUMBER
: /* 0x5386 */
10295 POST_MEM_WRITE(ARG3
, sizeof(int));
10298 /* CD ROM stuff (??) */
10299 case VKI_CDROM_DISC_STATUS
:
10300 case VKI_CDROMSTOP
:
10302 case VKI_CDROMSUBCHNL
:
10303 POST_MEM_WRITE(ARG3
, sizeof(struct vki_cdrom_subchnl
));
10305 case VKI_CDROMREADTOCHDR
:
10306 POST_MEM_WRITE(ARG3
, sizeof(struct vki_cdrom_tochdr
));
10308 case VKI_CDROMREADTOCENTRY
:
10309 POST_MEM_WRITE(ARG3
, sizeof(struct vki_cdrom_tocentry
));
10311 case VKI_CDROMMULTISESSION
:
10312 POST_MEM_WRITE(ARG3
, sizeof(struct vki_cdrom_multisession
));
10314 case VKI_CDROMVOLREAD
:
10315 POST_MEM_WRITE(ARG3
, sizeof(struct vki_cdrom_volctrl
));
10317 case VKI_CDROMREADMODE1
:
10318 POST_MEM_WRITE(ARG3
, VKI_CD_FRAMESIZE_RAW1
);
10320 case VKI_CDROMREADMODE2
:
10321 POST_MEM_WRITE(ARG3
, VKI_CD_FRAMESIZE_RAW0
);
10323 case VKI_CDROMREADRAW
:
10324 POST_MEM_WRITE(ARG3
, VKI_CD_FRAMESIZE_RAW
);
10326 case VKI_CDROMREADAUDIO
:
10328 struct vki_cdrom_read_audio
*cra
=
10329 (struct vki_cdrom_read_audio
*) (Addr
)ARG3
;
10330 POST_MEM_WRITE( (Addr
)(cra
->buf
), cra
->nframes
* VKI_CD_FRAMESIZE_RAW
);
10334 case VKI_CDROMPLAYMSF
:
10336 /* The following two are probably bogus (should check args
10337 for readability). JRS 20021117 */
10338 case VKI_CDROM_DRIVE_STATUS
: /* 0x5326 */
10339 case VKI_CDROM_CLEAR_OPTIONS
: /* 0x5321 */
10341 case VKI_CDROM_GET_CAPABILITY
: /* 0x5331 */
10345 case VKI_DVD_READ_STRUCT
:
10349 POST_MEM_WRITE(ARG3
, sizeof(unsigned long));
10352 POST_MEM_WRITE(ARG3
, sizeof(int));
10355 case VKI_FBIOGET_VSCREENINFO
: //0x4600
10356 POST_MEM_WRITE(ARG3
, sizeof(struct vki_fb_var_screeninfo
));
10358 case VKI_FBIOGET_FSCREENINFO
: //0x4602
10359 POST_MEM_WRITE(ARG3
, sizeof(struct vki_fb_fix_screeninfo
));
10365 case VKI_PPRELEASE
:
10366 case VKI_PPSETMODE
:
10367 case VKI_PPSETPHASE
:
10368 case VKI_PPSETFLAGS
:
10370 case VKI_PPWCONTROL
:
10371 case VKI_PPFCONTROL
:
10372 case VKI_PPDATADIR
:
10374 case VKI_PPWCTLONIRQ
:
10375 case VKI_PPSETTIME
:
10377 case VKI_PPGETMODE
:
10378 POST_MEM_WRITE( ARG3
, sizeof(int) );
10380 case VKI_PPGETPHASE
:
10381 POST_MEM_WRITE( ARG3
, sizeof(int) );
10383 case VKI_PPGETMODES
:
10384 POST_MEM_WRITE( ARG3
, sizeof(unsigned int) );
10386 case VKI_PPGETFLAGS
:
10387 POST_MEM_WRITE( ARG3
, sizeof(int) );
10389 case VKI_PPRSTATUS
:
10390 POST_MEM_WRITE( ARG3
, sizeof(unsigned char) );
10393 POST_MEM_WRITE( ARG3
, sizeof(unsigned char) );
10395 case VKI_PPRCONTROL
:
10396 POST_MEM_WRITE( ARG3
, sizeof(unsigned char) );
10399 POST_MEM_WRITE( ARG3
, sizeof(int) );
10401 case VKI_PPGETTIME
:
10402 POST_MEM_WRITE( ARG3
, sizeof(struct vki_timeval
) );
10406 POST_MEM_WRITE( ARG3
, 32 * 256 );
10411 case VKI_GIO_FONTX
:
10412 POST_MEM_WRITE((Addr
)((struct vki_consolefontdesc
*)(Addr
)ARG3
)->chardata
,
10413 32 * ((struct vki_consolefontdesc
*)(Addr
)ARG3
)->charcount
);
10415 case VKI_PIO_FONTX
:
10418 case VKI_PIO_FONTRESET
:
10422 POST_MEM_WRITE( ARG3
, 16 * 3 );
10427 case VKI_KIOCSOUND
:
10432 POST_MEM_WRITE( ARG3
, sizeof(char) );
10437 case VKI_KDGKBTYPE
:
10438 POST_MEM_WRITE( ARG3
, sizeof(char) );
10444 case VKI_KDDISABIO
:
10447 case VKI_KDSETMODE
:
10449 case VKI_KDGETMODE
:
10450 POST_MEM_WRITE( ARG3
, sizeof(int) );
10453 case VKI_KDMAPDISP
:
10454 case VKI_KDUNMAPDISP
:
10457 case VKI_GIO_SCRNMAP
:
10458 POST_MEM_WRITE( ARG3
, VKI_E_TABSZ
);
10460 case VKI_PIO_SCRNMAP
:
10462 case VKI_GIO_UNISCRNMAP
:
10463 POST_MEM_WRITE( ARG3
, VKI_E_TABSZ
* sizeof(unsigned short) );
10465 case VKI_PIO_UNISCRNMAP
:
10468 case VKI_GIO_UNIMAP
:
10470 struct vki_unimapdesc
*desc
= (struct vki_unimapdesc
*) (Addr
)ARG3
;
10471 POST_MEM_WRITE( (Addr
)&desc
->entry_ct
, sizeof(desc
->entry_ct
));
10472 POST_MEM_WRITE( (Addr
)desc
->entries
,
10473 desc
->entry_ct
* sizeof(struct vki_unipair
) );
10476 case VKI_PIO_UNIMAP
:
10478 case VKI_PIO_UNIMAPCLR
:
10481 case VKI_KDGKBMODE
:
10482 POST_MEM_WRITE( ARG3
, sizeof(int) );
10484 case VKI_KDSKBMODE
:
10487 case VKI_KDGKBMETA
:
10488 POST_MEM_WRITE( ARG3
, sizeof(int) );
10490 case VKI_KDSKBMETA
:
10494 POST_MEM_WRITE( ARG3
, sizeof(char) );
10500 POST_MEM_WRITE( (Addr
)&((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
,
10501 sizeof(((struct vki_kbentry
*)(Addr
)ARG3
)->kb_value
) );
10506 case VKI_KDGKBSENT
:
10507 POST_MEM_WRITE( (Addr
)((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_string
,
10508 sizeof(((struct vki_kbsentry
*)(Addr
)ARG3
)->kb_string
) );
10510 case VKI_KDSKBSENT
:
10513 case VKI_KDGKBDIACR
:
10514 POST_MEM_WRITE( ARG3
, sizeof(struct vki_kbdiacrs
) );
10516 case VKI_KDSKBDIACR
:
10519 case VKI_KDGETKEYCODE
:
10520 POST_MEM_WRITE( (Addr
)((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
,
10521 sizeof(((struct vki_kbkeycode
*)(Addr
)ARG3
)->keycode
) );
10523 case VKI_KDSETKEYCODE
:
10526 case VKI_KDSIGACCEPT
:
10534 struct vki_console_font_op
*op
=
10535 (struct vki_console_font_op
*) (Addr
)ARG3
;
10536 switch ( op
->op
) {
10537 case VKI_KD_FONT_OP_SET
:
10539 case VKI_KD_FONT_OP_GET
:
10541 POST_MEM_WRITE( (Addr
) op
->data
,
10542 (op
->width
+ 7) / 8 * 32 * op
->charcount
);
10544 case VKI_KD_FONT_OP_SET_DEFAULT
:
10546 case VKI_KD_FONT_OP_COPY
:
10549 POST_MEM_WRITE( (Addr
) op
, sizeof(*op
));
10553 case VKI_VT_OPENQRY
:
10554 POST_MEM_WRITE( ARG3
, sizeof(int) );
10556 case VKI_VT_GETMODE
:
10557 POST_MEM_WRITE( ARG3
, sizeof(struct vki_vt_mode
) );
10559 case VKI_VT_SETMODE
:
10561 case VKI_VT_GETSTATE
:
10562 POST_MEM_WRITE( (Addr
) &(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_active
),
10563 sizeof(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_active
) );
10564 POST_MEM_WRITE( (Addr
) &(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_state
),
10565 sizeof(((struct vki_vt_stat
*) (Addr
)ARG3
)->v_state
) );
10567 case VKI_VT_RELDISP
:
10568 case VKI_VT_ACTIVATE
:
10569 case VKI_VT_WAITACTIVE
:
10570 case VKI_VT_DISALLOCATE
:
10572 case VKI_VT_RESIZE
:
10574 case VKI_VT_RESIZEX
:
10576 case VKI_VT_LOCKSWITCH
:
10577 case VKI_VT_UNLOCKSWITCH
:
10580 case VKI_USBDEVFS_CONTROL
:
10582 struct vki_usbdevfs_ctrltransfer
*vkuc
=
10583 (struct vki_usbdevfs_ctrltransfer
*)(Addr
)ARG3
;
10584 if (vkuc
->bRequestType
& 0x80)
10585 POST_MEM_WRITE((Addr
)vkuc
->data
, RES
);
10588 case VKI_USBDEVFS_BULK
:
10590 struct vki_usbdevfs_bulktransfer
*vkub
=
10591 (struct vki_usbdevfs_bulktransfer
*)(Addr
)ARG3
;
10592 if (vkub
->ep
& 0x80)
10593 POST_MEM_WRITE((Addr
)vkub
->data
, RES
);
10596 case VKI_USBDEVFS_GETDRIVER
:
10598 struct vki_usbdevfs_getdriver
*vkugd
=
10599 (struct vki_usbdevfs_getdriver
*)(Addr
)ARG3
;
10600 POST_MEM_WRITE((Addr
)&vkugd
->driver
, sizeof(vkugd
->driver
));
10603 case VKI_USBDEVFS_REAPURB
:
10604 case VKI_USBDEVFS_REAPURBNDELAY
:
10606 struct vki_usbdevfs_urb
**vkuu
= (struct vki_usbdevfs_urb
**)(Addr
)ARG3
;
10607 POST_MEM_WRITE((Addr
)vkuu
, sizeof(*vkuu
));
10610 POST_MEM_WRITE((Addr
) &((*vkuu
)->status
),sizeof((*vkuu
)->status
));
10611 if ((*vkuu
)->type
== VKI_USBDEVFS_URB_TYPE_CONTROL
) {
10612 struct vki_usbdevfs_setuppacket
*vkusp
= (struct vki_usbdevfs_setuppacket
*)(*vkuu
)->buffer
;
10613 if (vkusp
->bRequestType
& 0x80)
10614 POST_MEM_WRITE((Addr
)(vkusp
+1), (*vkuu
)->buffer_length
- sizeof(*vkusp
));
10615 POST_MEM_WRITE((Addr
)&(*vkuu
)->actual_length
, sizeof((*vkuu
)->actual_length
));
10616 } else if ((*vkuu
)->type
== VKI_USBDEVFS_URB_TYPE_ISO
) {
10617 char *bp
= (*vkuu
)->buffer
;
10619 for(i
=0; i
<(*vkuu
)->number_of_packets
; i
++) {
10620 POST_MEM_WRITE((Addr
)&(*vkuu
)->iso_frame_desc
[i
].actual_length
, sizeof((*vkuu
)->iso_frame_desc
[i
].actual_length
));
10621 POST_MEM_WRITE((Addr
)&(*vkuu
)->iso_frame_desc
[i
].status
, sizeof((*vkuu
)->iso_frame_desc
[i
].status
));
10622 if ((*vkuu
)->endpoint
& 0x80)
10623 POST_MEM_WRITE((Addr
)bp
, (*vkuu
)->iso_frame_desc
[i
].actual_length
);
10624 bp
+= (*vkuu
)->iso_frame_desc
[i
].length
; // FIXME: or actual_length??
10626 POST_MEM_WRITE((Addr
)&(*vkuu
)->error_count
, sizeof((*vkuu
)->error_count
));
10628 if ((*vkuu
)->endpoint
& 0x80)
10629 POST_MEM_WRITE((Addr
)(*vkuu
)->buffer
, (*vkuu
)->actual_length
);
10630 POST_MEM_WRITE((Addr
)&(*vkuu
)->actual_length
, sizeof((*vkuu
)->actual_length
));
10634 case VKI_USBDEVFS_CONNECTINFO
:
10635 POST_MEM_WRITE(ARG3
, sizeof(struct vki_usbdevfs_connectinfo
));
10637 case VKI_USBDEVFS_IOCTL
:
10639 struct vki_usbdevfs_ioctl
*vkui
=
10640 (struct vki_usbdevfs_ioctl
*)(Addr
)ARG3
;
10642 dir2
= _VKI_IOC_DIR(vkui
->ioctl_code
);
10643 size2
= _VKI_IOC_SIZE(vkui
->ioctl_code
);
10645 if (dir2
& _VKI_IOC_READ
)
10646 POST_MEM_WRITE((Addr
)vkui
->data
, size2
);
10651 /* I2C (/dev/i2c-*) ioctls */
10652 case VKI_I2C_SLAVE
:
10653 case VKI_I2C_SLAVE_FORCE
:
10654 case VKI_I2C_TENBIT
:
10657 case VKI_I2C_FUNCS
:
10658 POST_MEM_WRITE( ARG3
, sizeof(unsigned long) );
10662 struct vki_i2c_rdwr_ioctl_data
*vkui
=
10663 (struct vki_i2c_rdwr_ioctl_data
*)(Addr
)ARG3
;
10665 for (i
=0; i
< vkui
->nmsgs
; i
++) {
10666 struct vki_i2c_msg
*msg
= vkui
->msgs
+ i
;
10667 if (msg
->flags
& VKI_I2C_M_RD
)
10668 POST_MEM_WRITE((Addr
)msg
->buf
, msg
->len
);
10672 case VKI_I2C_SMBUS
:
10674 struct vki_i2c_smbus_ioctl_data
*vkis
10675 = (struct vki_i2c_smbus_ioctl_data
*) (Addr
)ARG3
;
10676 /* i2c_smbus_write_quick hides its value in read_write, so
10677 this variable can have a different meaning */
10678 if ((vkis
->read_write
== VKI_I2C_SMBUS_READ
)
10679 || (vkis
->size
== VKI_I2C_SMBUS_PROC_CALL
)
10680 || (vkis
->size
== VKI_I2C_SMBUS_BLOCK_PROC_CALL
)) {
10681 if ( ! (vkis
->size
== VKI_I2C_SMBUS_QUICK
)) {
10683 switch(vkis
->size
) {
10684 case VKI_I2C_SMBUS_BYTE
:
10685 case VKI_I2C_SMBUS_BYTE_DATA
:
10688 case VKI_I2C_SMBUS_WORD_DATA
:
10689 case VKI_I2C_SMBUS_PROC_CALL
:
10692 case VKI_I2C_SMBUS_BLOCK_DATA
:
10693 case VKI_I2C_SMBUS_I2C_BLOCK_BROKEN
:
10694 case VKI_I2C_SMBUS_BLOCK_PROC_CALL
:
10695 case VKI_I2C_SMBUS_I2C_BLOCK_DATA
:
10696 size
= 1 + vkis
->data
->block
[0];
10701 POST_MEM_WRITE((Addr
)&vkis
->data
->block
[0], size
);
10707 /* Wireless extensions ioctls */
10708 case VKI_SIOCSIWCOMMIT
:
10709 case VKI_SIOCSIWNWID
:
10710 case VKI_SIOCSIWFREQ
:
10711 case VKI_SIOCSIWMODE
:
10712 case VKI_SIOCSIWSENS
:
10713 case VKI_SIOCSIWRANGE
:
10714 case VKI_SIOCSIWPRIV
:
10715 case VKI_SIOCSIWSTATS
:
10716 case VKI_SIOCSIWSPY
:
10717 case VKI_SIOCSIWTHRSPY
:
10718 case VKI_SIOCSIWAP
:
10719 case VKI_SIOCSIWSCAN
:
10720 case VKI_SIOCSIWESSID
:
10721 case VKI_SIOCSIWRATE
:
10722 case VKI_SIOCSIWNICKN
:
10723 case VKI_SIOCSIWRTS
:
10724 case VKI_SIOCSIWFRAG
:
10725 case VKI_SIOCSIWTXPOW
:
10726 case VKI_SIOCSIWRETRY
:
10727 case VKI_SIOCSIWENCODE
:
10728 case VKI_SIOCSIWPOWER
:
10729 case VKI_SIOCSIWGENIE
:
10730 case VKI_SIOCSIWMLME
:
10731 case VKI_SIOCSIWAUTH
:
10732 case VKI_SIOCSIWENCODEEXT
:
10733 case VKI_SIOCSIWPMKSA
:
10735 case VKI_SIOCGIWNAME
:
10737 POST_MEM_WRITE((Addr
)((struct vki_iwreq
*)(Addr
)ARG3
)->u
.name
,
10738 sizeof(((struct vki_iwreq
*)(Addr
)ARG3
)->u
.name
));
10741 case VKI_SIOCGIWNWID
:
10742 case VKI_SIOCGIWSENS
:
10743 case VKI_SIOCGIWRATE
:
10744 case VKI_SIOCGIWRTS
:
10745 case VKI_SIOCGIWFRAG
:
10746 case VKI_SIOCGIWTXPOW
:
10747 case VKI_SIOCGIWRETRY
:
10748 case VKI_SIOCGIWPOWER
:
10749 case VKI_SIOCGIWAUTH
:
10751 POST_MEM_WRITE((Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.param
,
10752 sizeof(struct vki_iw_param
));
10755 case VKI_SIOCGIWFREQ
:
10757 POST_MEM_WRITE((Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.freq
,
10758 sizeof(struct vki_iw_freq
));
10761 case VKI_SIOCGIWMODE
:
10763 POST_MEM_WRITE((Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.mode
,
10764 sizeof(__vki_u32
));
10767 case VKI_SIOCGIWRANGE
:
10768 case VKI_SIOCGIWPRIV
:
10769 case VKI_SIOCGIWSTATS
:
10770 case VKI_SIOCGIWSPY
:
10771 case VKI_SIOCGIWTHRSPY
:
10772 case VKI_SIOCGIWAPLIST
:
10773 case VKI_SIOCGIWSCAN
:
10774 case VKI_SIOCGIWESSID
:
10775 case VKI_SIOCGIWNICKN
:
10776 case VKI_SIOCGIWENCODE
:
10777 case VKI_SIOCGIWGENIE
:
10778 case VKI_SIOCGIWENCODEEXT
:
10780 struct vki_iw_point
* point
;
10781 point
= &((struct vki_iwreq
*)(Addr
)ARG3
)->u
.data
;
10782 POST_MEM_WRITE((Addr
)point
->pointer
, point
->length
);
10785 case VKI_SIOCGIWAP
:
10787 POST_MEM_WRITE((Addr
)&((struct vki_iwreq
*)(Addr
)ARG3
)->u
.ap_addr
,
10788 sizeof(struct vki_sockaddr
));
10792 # if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
10793 || defined(VGPV_mips32_linux_android) \
10794 || defined(VGPV_arm64_linux_android)
10796 case VKI_ASHMEM_GET_SIZE
:
10797 case VKI_ASHMEM_SET_SIZE
:
10798 case VKI_ASHMEM_GET_PROT_MASK
:
10799 case VKI_ASHMEM_SET_PROT_MASK
:
10800 case VKI_ASHMEM_GET_PIN_STATUS
:
10801 case VKI_ASHMEM_PURGE_ALL_CACHES
:
10802 case VKI_ASHMEM_SET_NAME
:
10803 case VKI_ASHMEM_PIN
:
10804 case VKI_ASHMEM_UNPIN
:
10806 case VKI_ASHMEM_GET_NAME
:
10807 POST_MEM_WRITE( ARG3
, VKI_ASHMEM_NAME_LEN
);
10811 case VKI_BINDER_WRITE_READ
:
10813 struct vki_binder_write_read
* bwr
10814 = (struct vki_binder_write_read
*)(Addr
)ARG3
;
10815 POST_FIELD_WRITE(bwr
->write_consumed
);
10816 POST_FIELD_WRITE(bwr
->read_consumed
);
10818 if (bwr
->read_size
)
10819 POST_MEM_WRITE((Addr
)bwr
->read_buffer
, bwr
->read_consumed
);
10823 case VKI_BINDER_SET_IDLE_TIMEOUT
:
10824 case VKI_BINDER_SET_MAX_THREADS
:
10825 case VKI_BINDER_SET_IDLE_PRIORITY
:
10826 case VKI_BINDER_SET_CONTEXT_MGR
:
10827 case VKI_BINDER_THREAD_EXIT
:
10829 case VKI_BINDER_VERSION
:
10831 struct vki_binder_version
* bv
=
10832 (struct vki_binder_version
*)(Addr
)ARG3
;
10833 POST_FIELD_WRITE(bv
->protocol_version
);
10836 # endif /* defined(VGPV_*_linux_android) */
10838 case VKI_HCIGETDEVLIST
:
10840 struct vki_hci_dev_list_req
* dlr
=
10841 (struct vki_hci_dev_list_req
*)(Addr
)ARG3
;
10842 POST_MEM_WRITE((Addr
)ARG3
+ sizeof(struct vki_hci_dev_list_req
),
10843 dlr
->dev_num
* sizeof(struct vki_hci_dev_req
));
10847 case VKI_HCIINQUIRY
:
10849 struct vki_hci_inquiry_req
* ir
=
10850 (struct vki_hci_inquiry_req
*)(Addr
)ARG3
;
10851 POST_MEM_WRITE((Addr
)ARG3
+ sizeof(struct vki_hci_inquiry_req
),
10852 ir
->num_rsp
* sizeof(struct vki_inquiry_info
));
10856 case VKI_DRM_IOCTL_VERSION
:
10858 struct vki_drm_version
* data
= (struct vki_drm_version
*)(Addr
)ARG3
;
10859 struct vg_drm_version_info
* info
= container_of(data
, struct vg_drm_version_info
, data
);
10860 const vki_size_t orig_name_len
= info
->orig
->name_len
;
10861 const vki_size_t orig_date_len
= info
->orig
->date_len
;
10862 const vki_size_t orig_desc_len
= info
->orig
->desc_len
;
10863 *info
->orig
= info
->data
;
10864 ARG3
= (Addr
)info
->orig
;
10868 POST_MEM_WRITE((Addr
)&data
->version_major
, sizeof(data
->version_major
));
10869 POST_MEM_WRITE((Addr
)&data
->version_minor
, sizeof(data
->version_minor
));
10870 POST_MEM_WRITE((Addr
)&data
->version_patchlevel
, sizeof(data
->version_patchlevel
));
10871 POST_MEM_WRITE((Addr
)&data
->name_len
, sizeof(data
->name_len
));
10872 POST_MEM_WRITE((Addr
)data
->name
, VG_MIN(data
->name_len
, orig_name_len
));
10873 POST_MEM_WRITE((Addr
)&data
->date_len
, sizeof(data
->date_len
));
10874 POST_MEM_WRITE((Addr
)data
->date
, VG_MIN(data
->date_len
, orig_date_len
));
10875 POST_MEM_WRITE((Addr
)&data
->desc_len
, sizeof(data
->desc_len
));
10876 POST_MEM_WRITE((Addr
)data
->desc
, VG_MIN(data
->desc_len
, orig_desc_len
));
10880 case VKI_DRM_IOCTL_GET_UNIQUE
:
10882 struct vki_drm_unique
*data
= (struct vki_drm_unique
*)(Addr
)ARG3
;
10883 POST_MEM_WRITE((Addr
)data
->unique
, sizeof(data
->unique_len
));
10886 case VKI_DRM_IOCTL_GET_MAGIC
:
10888 struct vki_drm_auth
*data
= (struct vki_drm_auth
*)(Addr
)ARG3
;
10889 POST_MEM_WRITE((Addr
)&data
->magic
, sizeof(data
->magic
));
10892 case VKI_DRM_IOCTL_WAIT_VBLANK
:
10894 union vki_drm_wait_vblank
*data
=
10895 (union vki_drm_wait_vblank
*)(Addr
)ARG3
;
10896 POST_MEM_WRITE((Addr
)&data
->reply
, sizeof(data
->reply
));
10899 case VKI_DRM_IOCTL_GEM_FLINK
:
10901 struct vki_drm_gem_flink
*data
=
10902 (struct vki_drm_gem_flink
*)(Addr
)ARG3
;
10903 POST_MEM_WRITE((Addr
)&data
->name
, sizeof(data
->name
));
10906 case VKI_DRM_IOCTL_GEM_OPEN
:
10908 struct vki_drm_gem_open
*data
= (struct vki_drm_gem_open
*)(Addr
)ARG3
;
10909 POST_MEM_WRITE((Addr
)&data
->handle
, sizeof(data
->handle
));
10910 POST_MEM_WRITE((Addr
)&data
->size
, sizeof(data
->size
));
10913 case VKI_DRM_IOCTL_I915_GETPARAM
:
10915 vki_drm_i915_getparam_t
*data
= (vki_drm_i915_getparam_t
*)(Addr
)ARG3
;
10916 POST_MEM_WRITE((Addr
)data
->value
, sizeof(int));
10919 case VKI_DRM_IOCTL_I915_GEM_BUSY
:
10921 struct vki_drm_i915_gem_busy
*data
=
10922 (struct vki_drm_i915_gem_busy
*)(Addr
)ARG3
;
10923 POST_MEM_WRITE((Addr
)&data
->busy
, sizeof(data
->busy
));
10926 case VKI_DRM_IOCTL_I915_GEM_CREATE
:
10928 struct vki_drm_i915_gem_create
*data
=
10929 (struct vki_drm_i915_gem_create
*)(Addr
)ARG3
;
10930 POST_MEM_WRITE((Addr
)&data
->handle
, sizeof(data
->handle
));
10933 case VKI_DRM_IOCTL_I915_GEM_PREAD
:
10935 struct vki_drm_i915_gem_pread
*data
=
10936 (struct vki_drm_i915_gem_pread
*)(Addr
)ARG3
;
10937 POST_MEM_WRITE((Addr
)data
->data_ptr
, data
->size
);
10940 case VKI_DRM_IOCTL_I915_GEM_MMAPv1
:
10942 struct vki_drm_i915_gem_mmap_v1
*data
=
10943 (struct vki_drm_i915_gem_mmap_v1
*)(Addr
)ARG3
;
10944 Addr addr
= data
->addr_ptr
;
10945 SizeT size
= data
->size
;
10946 vg_assert(ML_(valid_client_addr
)(addr
, size
, tid
,
10947 "ioctl(DRM_IOCTL_I915_GEM_MMAPv1)"));
10948 ML_(notify_core_and_tool_of_mmap
)(addr
, size
,
10949 VKI_PROT_READ
| VKI_PROT_WRITE
,
10950 VKI_MAP_ANONYMOUS
, -1, 0 );
10951 POST_MEM_WRITE((Addr
)&data
->addr_ptr
, sizeof(data
->addr_ptr
));
10954 case VKI_DRM_IOCTL_I915_GEM_MMAP
:
10956 struct vki_drm_i915_gem_mmap
*data
=
10957 (struct vki_drm_i915_gem_mmap
*)(Addr
)ARG3
;
10958 Addr addr
= data
->addr_ptr
;
10959 SizeT size
= data
->size
;
10960 vg_assert(ML_(valid_client_addr
)(addr
, size
, tid
,
10961 "ioctl(DRM_IOCTL_I915_GEM_MMAP)"));
10962 ML_(notify_core_and_tool_of_mmap
)(addr
, size
,
10963 VKI_PROT_READ
| VKI_PROT_WRITE
,
10964 VKI_MAP_ANONYMOUS
, -1, 0 );
10965 POST_MEM_WRITE((Addr
)&data
->addr_ptr
, sizeof(data
->addr_ptr
));
10968 case VKI_DRM_IOCTL_I915_GEM_MMAP_GTT
:
10970 struct vki_drm_i915_gem_mmap_gtt
*data
=
10971 (struct vki_drm_i915_gem_mmap_gtt
*)(Addr
)ARG3
;
10972 POST_MEM_WRITE((Addr
)&data
->offset
, sizeof(data
->offset
));
10975 case VKI_DRM_IOCTL_I915_GEM_SET_TILING
:
10977 struct vki_drm_i915_gem_set_tiling
*data
=
10978 (struct vki_drm_i915_gem_set_tiling
*)(Addr
)ARG3
;
10979 POST_MEM_WRITE((Addr
)&data
->tiling_mode
, sizeof(data
->tiling_mode
));
10980 POST_MEM_WRITE((Addr
)&data
->stride
, sizeof(data
->stride
));
10981 POST_MEM_WRITE((Addr
)&data
->swizzle_mode
, sizeof(data
->swizzle_mode
));
10984 case VKI_DRM_IOCTL_I915_GEM_GET_TILING
:
10986 struct vki_drm_i915_gem_get_tiling
*data
=
10987 (struct vki_drm_i915_gem_get_tiling
*)(Addr
)ARG3
;
10988 POST_MEM_WRITE((Addr
)&data
->tiling_mode
, sizeof(data
->tiling_mode
));
10989 POST_MEM_WRITE((Addr
)&data
->swizzle_mode
, sizeof(data
->swizzle_mode
));
10992 case VKI_DRM_IOCTL_I915_GEM_GET_APERTURE
:
10994 struct vki_drm_i915_gem_get_aperture
*data
=
10995 (struct vki_drm_i915_gem_get_aperture
*)(Addr
)ARG3
;
10996 POST_MEM_WRITE((Addr
)&data
->aper_size
, sizeof(data
->aper_size
));
10997 POST_MEM_WRITE((Addr
)&data
->aper_available_size
, sizeof(data
->aper_available_size
));
11001 /* KVM ioctls that only write the system call return value */
11002 case VKI_KVM_GET_API_VERSION
:
11003 case VKI_KVM_CREATE_VM
:
11004 case VKI_KVM_CHECK_EXTENSION
:
11005 case VKI_KVM_GET_VCPU_MMAP_SIZE
:
11006 case VKI_KVM_S390_ENABLE_SIE
:
11007 case VKI_KVM_CREATE_VCPU
:
11008 case VKI_KVM_SET_TSS_ADDR
:
11009 case VKI_KVM_CREATE_IRQCHIP
:
11011 case VKI_KVM_S390_INITIAL_RESET
:
11012 case VKI_KVM_KVMCLOCK_CTRL
:
11015 case VKI_KVM_S390_MEM_OP
: {
11016 struct vki_kvm_s390_mem_op
*args
=
11017 (struct vki_kvm_s390_mem_op
*)(Addr
)(ARG3
);
11018 if (args
->flags
& VKI_KVM_S390_MEMOP_F_CHECK_ONLY
)
11020 if (args
->op
== VKI_KVM_S390_MEMOP_LOGICAL_READ
)
11021 POST_MEM_WRITE((Addr
)args
->buf
, args
->size
);
11026 case VKI_XEN_IOCTL_PRIVCMD_HYPERCALL
: {
11027 SyscallArgs harrghs
;
11028 struct vki_xen_privcmd_hypercall
*args
=
11029 (struct vki_xen_privcmd_hypercall
*)(Addr
)(ARG3
);
11034 VG_(memset
)(&harrghs
, 0, sizeof(harrghs
));
11035 harrghs
.sysno
= args
->op
;
11036 harrghs
.arg1
= args
->arg
[0];
11037 harrghs
.arg2
= args
->arg
[1];
11038 harrghs
.arg3
= args
->arg
[2];
11039 harrghs
.arg4
= args
->arg
[3];
11040 harrghs
.arg5
= args
->arg
[4];
11041 harrghs
.arg6
= harrghs
.arg7
= harrghs
.arg8
= 0;
11043 WRAPPER_POST_NAME(xen
, hypercall
) (tid
, &harrghs
, status
);
11047 case VKI_XEN_IOCTL_PRIVCMD_MMAP
:
11049 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH
: {
11050 struct vki_xen_privcmd_mmapbatch
*args
=
11051 (struct vki_xen_privcmd_mmapbatch
*)(Addr
)(ARG3
);
11052 POST_MEM_WRITE((Addr
)args
->arr
, sizeof(*(args
->arr
)) * args
->num
);
11055 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2
: {
11056 struct vki_xen_privcmd_mmapbatch_v2
*args
=
11057 (struct vki_xen_privcmd_mmapbatch_v2
*)(Addr
)(ARG3
);
11058 POST_MEM_WRITE((Addr
)args
->err
, sizeof(*(args
->err
)) * args
->num
);
11062 case VKI_XEN_IOCTL_EVTCHN_BIND_VIRQ
:
11063 case VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN
:
11064 case VKI_XEN_IOCTL_EVTCHN_BIND_UNBOUND_PORT
:
11065 case VKI_XEN_IOCTL_EVTCHN_UNBIND
:
11066 case VKI_XEN_IOCTL_EVTCHN_NOTIFY
:
11067 case VKI_XEN_IOCTL_EVTCHN_RESET
:
11073 case VKI_OBD_IOC_FID2PATH
: {
11074 struct vki_getinfo_fid2path
*args
= (void *)(Addr
)(ARG3
);
11075 POST_FIELD_WRITE(args
->gf_recno
);
11076 POST_FIELD_WRITE(args
->gf_linkno
);
11077 POST_MEM_WRITE((Addr
)args
->gf_path
, VG_(strlen
)(args
->gf_path
)+1);
11081 case VKI_LL_IOC_PATH2FID
:
11082 POST_MEM_WRITE(ARG3
, sizeof(struct vki_lu_fid
));
11085 case VKI_LL_IOC_GETPARENT
: {
11086 struct vki_getparent
*gp
= (struct vki_getparent
*)(Addr
)ARG3
;
11087 POST_FIELD_WRITE(gp
->gp_fid
);
11088 POST_MEM_WRITE((Addr
)gp
->gp_name
, VG_(strlen
)(gp
->gp_name
)+1);
11093 case VKI_V4L2_S_FMT
:
11094 case VKI_V4L2_TRY_FMT
:
11095 case VKI_V4L2_REQBUFS
:
11096 case VKI_V4L2_OVERLAY
:
11097 case VKI_V4L2_STREAMON
:
11098 case VKI_V4L2_STREAMOFF
:
11099 case VKI_V4L2_S_PARM
:
11100 case VKI_V4L2_S_STD
:
11101 case VKI_V4L2_S_FREQUENCY
:
11102 case VKI_V4L2_S_CTRL
:
11103 case VKI_V4L2_S_TUNER
:
11104 case VKI_V4L2_S_AUDIO
:
11105 case VKI_V4L2_S_INPUT
:
11106 case VKI_V4L2_S_EDID
:
11107 case VKI_V4L2_S_OUTPUT
:
11108 case VKI_V4L2_S_AUDOUT
:
11109 case VKI_V4L2_S_MODULATOR
:
11110 case VKI_V4L2_S_JPEGCOMP
:
11111 case VKI_V4L2_S_CROP
:
11112 case VKI_V4L2_S_PRIORITY
:
11113 case VKI_V4L2_S_HW_FREQ_SEEK
:
11114 case VKI_V4L2_S_DV_TIMINGS
:
11115 case VKI_V4L2_SUBSCRIBE_EVENT
:
11116 case VKI_V4L2_UNSUBSCRIBE_EVENT
:
11117 case VKI_V4L2_PREPARE_BUF
:
11119 case VKI_V4L2_QUERYCAP
: {
11120 struct vki_v4l2_capability
*data
=
11121 (struct vki_v4l2_capability
*)(Addr
)ARG3
;
11122 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11125 case VKI_V4L2_ENUM_FMT
: {
11126 struct vki_v4l2_fmtdesc
*data
= (struct vki_v4l2_fmtdesc
*)(Addr
)ARG3
;
11127 POST_FIELD_WRITE(data
->flags
);
11128 POST_FIELD_WRITE(data
->description
);
11129 POST_FIELD_WRITE(data
->pixelformat
);
11130 POST_FIELD_WRITE(data
->reserved
);
11133 case VKI_V4L2_G_FMT
: {
11134 struct vki_v4l2_format
*data
= (struct vki_v4l2_format
*)(Addr
)ARG3
;
11135 switch (data
->type
) {
11136 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE
:
11137 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
:
11138 POST_FIELD_WRITE(data
->fmt
.pix
);
11140 case VKI_V4L2_BUF_TYPE_VBI_CAPTURE
:
11141 case VKI_V4L2_BUF_TYPE_VBI_OUTPUT
:
11142 POST_FIELD_WRITE(data
->fmt
.vbi
);
11144 case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
11145 case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
11146 POST_FIELD_WRITE(data
->fmt
.sliced
);
11148 case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY
:
11149 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
11150 POST_FIELD_WRITE(data
->fmt
.win
);
11152 case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
11153 case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
11154 POST_FIELD_WRITE(data
->fmt
.pix_mp
);
11156 case VKI_V4L2_BUF_TYPE_SDR_CAPTURE
:
11157 POST_FIELD_WRITE(data
->fmt
.sdr
);
11162 case VKI_V4L2_QUERYBUF
: {
11163 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
11164 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
11165 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
11168 for (i
= 0; i
< data
->length
; i
++) {
11169 POST_FIELD_WRITE(data
->m
.planes
[i
].bytesused
);
11170 POST_FIELD_WRITE(data
->m
.planes
[i
].length
);
11171 POST_FIELD_WRITE(data
->m
.planes
[i
].m
);
11172 POST_FIELD_WRITE(data
->m
.planes
[i
].data_offset
);
11173 POST_FIELD_WRITE(data
->m
.planes
[i
].reserved
);
11176 POST_FIELD_WRITE(data
->m
);
11177 POST_FIELD_WRITE(data
->length
);
11179 POST_FIELD_WRITE(data
->bytesused
);
11180 POST_FIELD_WRITE(data
->flags
);
11181 POST_FIELD_WRITE(data
->field
);
11182 POST_FIELD_WRITE(data
->timestamp
);
11183 POST_FIELD_WRITE(data
->timecode
);
11184 POST_FIELD_WRITE(data
->sequence
);
11185 POST_FIELD_WRITE(data
->memory
);
11186 POST_FIELD_WRITE(data
->sequence
);
11189 case VKI_V4L2_G_FBUF
: {
11190 struct vki_v4l2_framebuffer
*data
=
11191 (struct vki_v4l2_framebuffer
*)(Addr
)ARG3
;
11192 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11195 case VKI_V4L2_S_FBUF
: {
11196 struct vki_v4l2_framebuffer
*data
=
11197 (struct vki_v4l2_framebuffer
*)(Addr
)ARG3
;
11198 POST_FIELD_WRITE(data
->capability
);
11199 POST_FIELD_WRITE(data
->flags
);
11200 POST_FIELD_WRITE(data
->fmt
);
11203 case VKI_V4L2_QBUF
: {
11204 struct vki_v4l2_buffer
*data
= (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
11206 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
11207 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
11210 for (i
= 0; i
< data
->length
; i
++) {
11211 POST_FIELD_WRITE(data
->m
.planes
[i
].length
);
11212 if (data
->memory
== VKI_V4L2_MEMORY_MMAP
)
11213 POST_FIELD_WRITE(data
->m
.planes
[i
].m
);
11216 if (data
->memory
== VKI_V4L2_MEMORY_MMAP
)
11217 POST_FIELD_WRITE(data
->m
);
11218 POST_FIELD_WRITE(data
->length
);
11222 case VKI_V4L2_EXPBUF
: {
11223 struct vki_v4l2_exportbuffer
*data
=
11224 (struct vki_v4l2_exportbuffer
*)(Addr
)ARG3
;
11225 POST_FIELD_WRITE(data
->fd
);
11228 case VKI_V4L2_DQBUF
: {
11229 struct vki_v4l2_buffer
*data
=
11230 (struct vki_v4l2_buffer
*)(Addr
)ARG3
;
11231 POST_FIELD_WRITE(data
->index
);
11232 POST_FIELD_WRITE(data
->bytesused
);
11233 POST_FIELD_WRITE(data
->field
);
11234 if (data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
||
11235 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
) {
11238 for (i
= 0; i
< data
->length
; i
++) {
11239 POST_FIELD_WRITE(data
->m
.planes
[i
].bytesused
);
11240 POST_FIELD_WRITE(data
->m
.planes
[i
].data_offset
);
11241 POST_FIELD_WRITE(data
->m
.planes
[i
].length
);
11242 POST_FIELD_WRITE(data
->m
.planes
[i
].m
);
11245 POST_FIELD_WRITE(data
->m
);
11246 POST_FIELD_WRITE(data
->length
);
11247 POST_FIELD_WRITE(data
->bytesused
);
11248 POST_FIELD_WRITE(data
->field
);
11250 POST_FIELD_WRITE(data
->timestamp
);
11251 POST_FIELD_WRITE(data
->timecode
);
11252 POST_FIELD_WRITE(data
->sequence
);
11255 case VKI_V4L2_G_PARM
: {
11256 struct vki_v4l2_streamparm
*data
=
11257 (struct vki_v4l2_streamparm
*)(Addr
)ARG3
;
11258 int is_output
= data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT
||
11259 data
->type
== VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
||
11260 data
->type
== VKI_V4L2_BUF_TYPE_VBI_OUTPUT
||
11261 data
->type
== VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
;
11264 POST_MEM_WRITE((Addr
)&data
->parm
.output
,
11265 sizeof(data
->parm
.output
) - sizeof(data
->parm
.output
.reserved
));
11267 POST_MEM_WRITE((Addr
)&data
->parm
.capture
,
11268 sizeof(data
->parm
.capture
) - sizeof(data
->parm
.capture
.reserved
));
11271 case VKI_V4L2_G_STD
: {
11272 vki_v4l2_std_id
*data
= (vki_v4l2_std_id
*)(Addr
)ARG3
;
11273 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11276 case VKI_V4L2_ENUMSTD
: {
11277 struct vki_v4l2_standard
*data
= (struct vki_v4l2_standard
*)(Addr
)ARG3
;
11278 POST_MEM_WRITE((Addr
)&data
->id
, sizeof(*data
) - sizeof(data
->index
));
11281 case VKI_V4L2_ENUMINPUT
: {
11282 struct vki_v4l2_input
*data
= (struct vki_v4l2_input
*)(Addr
)ARG3
;
11283 POST_MEM_WRITE((Addr
)data
->name
, sizeof(*data
) - sizeof(data
->index
));
11286 case VKI_V4L2_G_CTRL
: {
11287 struct vki_v4l2_control
*data
= (struct vki_v4l2_control
*)(Addr
)ARG3
;
11288 POST_FIELD_WRITE(data
->value
);
11291 case VKI_V4L2_G_TUNER
: {
11292 struct vki_v4l2_tuner
*data
= (struct vki_v4l2_tuner
*)(Addr
)ARG3
;
11293 POST_MEM_WRITE((Addr
)data
->name
,
11294 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
11297 case VKI_V4L2_G_AUDIO
: {
11298 struct vki_v4l2_audio
*data
= (struct vki_v4l2_audio
*)(Addr
)ARG3
;
11299 POST_MEM_WRITE((Addr
)data
,
11300 sizeof(*data
) - sizeof(data
->reserved
));
11303 case VKI_V4L2_QUERYCTRL
: {
11304 struct vki_v4l2_queryctrl
*data
= (struct vki_v4l2_queryctrl
*)(Addr
)ARG3
;
11305 POST_MEM_WRITE((Addr
)&data
->type
,
11306 sizeof(*data
) - sizeof(data
->id
));
11309 case VKI_V4L2_QUERYMENU
: {
11310 struct vki_v4l2_querymenu
*data
= (struct vki_v4l2_querymenu
*)(Addr
)ARG3
;
11311 POST_MEM_WRITE((Addr
)data
->name
,
11312 sizeof(*data
) - sizeof(data
->id
) - sizeof(data
->index
));
11315 case VKI_V4L2_G_INPUT
: {
11316 int *data
= (int *)(Addr
)ARG3
;
11317 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11320 case VKI_V4L2_G_EDID
: {
11321 struct vki_v4l2_edid
*data
= (struct vki_v4l2_edid
*)(Addr
)ARG3
;
11322 if (data
->blocks
&& data
->edid
)
11323 POST_MEM_WRITE((Addr
)data
->edid
, data
->blocks
* 128);
11326 case VKI_V4L2_G_OUTPUT
: {
11327 int *data
= (int *)(Addr
)ARG3
;
11328 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11331 case VKI_V4L2_ENUMOUTPUT
: {
11332 struct vki_v4l2_output
*data
= (struct vki_v4l2_output
*)(Addr
)ARG3
;
11333 POST_MEM_WRITE((Addr
)data
->name
, sizeof(*data
) - sizeof(data
->index
));
11336 case VKI_V4L2_G_AUDOUT
: {
11337 struct vki_v4l2_audioout
*data
= (struct vki_v4l2_audioout
*)(Addr
)ARG3
;
11338 POST_MEM_WRITE((Addr
)data
,
11339 sizeof(*data
) - sizeof(data
->reserved
));
11342 case VKI_V4L2_G_MODULATOR
: {
11343 struct vki_v4l2_modulator
*data
= (struct vki_v4l2_modulator
*)(Addr
)ARG3
;
11344 POST_MEM_WRITE((Addr
)data
->name
,
11345 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
11348 case VKI_V4L2_G_FREQUENCY
: {
11349 struct vki_v4l2_frequency
*data
= (struct vki_v4l2_frequency
*)(Addr
)ARG3
;
11350 POST_FIELD_WRITE(data
->type
);
11351 POST_FIELD_WRITE(data
->frequency
);
11354 case VKI_V4L2_CROPCAP
: {
11355 struct vki_v4l2_cropcap
*data
= (struct vki_v4l2_cropcap
*)(Addr
)ARG3
;
11356 POST_MEM_WRITE((Addr
)&data
->bounds
, sizeof(*data
) - sizeof(data
->type
));
11359 case VKI_V4L2_G_CROP
: {
11360 struct vki_v4l2_crop
*data
= (struct vki_v4l2_crop
*)(Addr
)ARG3
;
11361 POST_FIELD_WRITE(data
->c
);
11364 case VKI_V4L2_G_JPEGCOMP
: {
11365 struct vki_v4l2_jpegcompression
*data
=
11366 (struct vki_v4l2_jpegcompression
*)(Addr
)ARG3
;
11367 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11370 case VKI_V4L2_QUERYSTD
: {
11371 vki_v4l2_std_id
*data
= (vki_v4l2_std_id
*)(Addr
)ARG3
;
11372 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11375 case VKI_V4L2_ENUMAUDIO
: {
11376 struct vki_v4l2_audio
*data
= (struct vki_v4l2_audio
*)(Addr
)ARG3
;
11377 POST_MEM_WRITE((Addr
)data
->name
,
11378 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
11381 case VKI_V4L2_ENUMAUDOUT
: {
11382 struct vki_v4l2_audioout
*data
= (struct vki_v4l2_audioout
*)(Addr
)ARG3
;
11383 POST_MEM_WRITE((Addr
)data
->name
,
11384 sizeof(*data
) - sizeof(data
->index
) - sizeof(data
->reserved
));
11387 case VKI_V4L2_G_PRIORITY
: {
11388 __vki_u32
*data
= (__vki_u32
*)(Addr
)ARG3
;
11389 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11392 case VKI_V4L2_G_SLICED_VBI_CAP
: {
11393 struct vki_v4l2_sliced_vbi_cap
*data
=
11394 (struct vki_v4l2_sliced_vbi_cap
*)(Addr
)ARG3
;
11395 POST_MEM_WRITE((Addr
)data
,
11396 sizeof(*data
) - sizeof(data
->type
) - sizeof(data
->reserved
));
11399 case VKI_V4L2_G_EXT_CTRLS
: {
11400 struct vki_v4l2_ext_controls
*data
=
11401 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
11405 for (i
= 0; i
< data
->count
; i
++) {
11406 if (data
->controls
[i
].size
)
11407 POST_MEM_WRITE((Addr
)data
->controls
[i
].ptr
, data
->controls
[i
].size
);
11409 POST_FIELD_WRITE(data
->controls
[i
].value64
);
11412 POST_FIELD_WRITE(data
->error_idx
);
11415 case VKI_V4L2_S_EXT_CTRLS
: {
11416 struct vki_v4l2_ext_controls
*data
=
11417 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
11418 POST_FIELD_WRITE(data
->error_idx
);
11421 case VKI_V4L2_TRY_EXT_CTRLS
: {
11422 struct vki_v4l2_ext_controls
*data
=
11423 (struct vki_v4l2_ext_controls
*)(Addr
)ARG3
;
11424 POST_FIELD_WRITE(data
->error_idx
);
11427 case VKI_V4L2_ENUM_FRAMESIZES
: {
11428 struct vki_v4l2_frmsizeenum
*data
=
11429 (struct vki_v4l2_frmsizeenum
*)(Addr
)ARG3
;
11430 POST_FIELD_WRITE(data
->type
);
11431 POST_FIELD_WRITE(data
->stepwise
);
11434 case VKI_V4L2_ENUM_FRAMEINTERVALS
: {
11435 struct vki_v4l2_frmivalenum
*data
=
11436 (struct vki_v4l2_frmivalenum
*)(Addr
)ARG3
;
11437 POST_FIELD_WRITE(data
->type
);
11438 POST_FIELD_WRITE(data
->stepwise
);
11441 case VKI_V4L2_G_ENC_INDEX
: {
11442 struct vki_v4l2_enc_idx
*data
= (struct vki_v4l2_enc_idx
*)(Addr
)ARG3
;
11443 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11446 case VKI_V4L2_ENCODER_CMD
: {
11447 struct vki_v4l2_encoder_cmd
*data
=
11448 (struct vki_v4l2_encoder_cmd
*)(Addr
)ARG3
;
11449 POST_FIELD_WRITE(data
->flags
);
11452 case VKI_V4L2_TRY_ENCODER_CMD
: {
11453 struct vki_v4l2_encoder_cmd
*data
=
11454 (struct vki_v4l2_encoder_cmd
*)(Addr
)ARG3
;
11455 POST_FIELD_WRITE(data
->flags
);
11458 case VKI_V4L2_DBG_S_REGISTER
: {
11459 struct vki_v4l2_dbg_register
*data
=
11460 (struct vki_v4l2_dbg_register
*)(Addr
)ARG3
;
11461 POST_FIELD_WRITE(data
->size
);
11464 case VKI_V4L2_DBG_G_REGISTER
: {
11465 struct vki_v4l2_dbg_register
*data
=
11466 (struct vki_v4l2_dbg_register
*)(Addr
)ARG3
;
11467 POST_FIELD_WRITE(data
->val
);
11468 POST_FIELD_WRITE(data
->size
);
11471 case VKI_V4L2_G_DV_TIMINGS
: {
11472 struct vki_v4l2_dv_timings
*data
=
11473 (struct vki_v4l2_dv_timings
*)(Addr
)ARG3
;
11474 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11477 case VKI_V4L2_DQEVENT
: {
11478 struct vki_v4l2_event
*data
= (struct vki_v4l2_event
*)(Addr
)ARG3
;
11479 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11482 case VKI_V4L2_CREATE_BUFS
: {
11483 struct vki_v4l2_create_buffers
*data
=
11484 (struct vki_v4l2_create_buffers
*)(Addr
)ARG3
;
11485 POST_FIELD_WRITE(data
->index
);
11488 case VKI_V4L2_G_SELECTION
: {
11489 struct vki_v4l2_selection
*data
=
11490 (struct vki_v4l2_selection
*)(Addr
)ARG3
;
11491 POST_FIELD_WRITE(data
->r
);
11494 case VKI_V4L2_S_SELECTION
: {
11495 struct vki_v4l2_selection
*data
= (struct vki_v4l2_selection
*)(Addr
)ARG3
;
11496 POST_FIELD_WRITE(data
->r
);
11499 case VKI_V4L2_DECODER_CMD
: {
11500 struct vki_v4l2_decoder_cmd
*data
=
11501 (struct vki_v4l2_decoder_cmd
*)(Addr
)ARG3
;
11502 POST_FIELD_WRITE(data
->flags
);
11505 case VKI_V4L2_TRY_DECODER_CMD
: {
11506 struct vki_v4l2_decoder_cmd
*data
=
11507 (struct vki_v4l2_decoder_cmd
*)(Addr
)ARG3
;
11508 POST_FIELD_WRITE(data
->flags
);
11511 case VKI_V4L2_ENUM_DV_TIMINGS
: {
11512 struct vki_v4l2_enum_dv_timings
*data
=
11513 (struct vki_v4l2_enum_dv_timings
*)(Addr
)ARG3
;
11514 POST_FIELD_WRITE(data
->timings
);
11517 case VKI_V4L2_QUERY_DV_TIMINGS
: {
11518 struct vki_v4l2_dv_timings
*data
=
11519 (struct vki_v4l2_dv_timings
*)(Addr
)ARG3
;
11520 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11523 case VKI_V4L2_DV_TIMINGS_CAP
: {
11524 struct vki_v4l2_dv_timings_cap
*data
=
11525 (struct vki_v4l2_dv_timings_cap
*)(Addr
)ARG3
;
11526 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11529 case VKI_V4L2_ENUM_FREQ_BANDS
: {
11530 struct vki_v4l2_frequency_band
*data
=
11531 (struct vki_v4l2_frequency_band
*)(Addr
)ARG3
;
11532 POST_FIELD_WRITE(data
->capability
);
11533 POST_FIELD_WRITE(data
->rangelow
);
11534 POST_FIELD_WRITE(data
->rangehigh
);
11535 POST_FIELD_WRITE(data
->modulation
);
11538 case VKI_V4L2_DBG_G_CHIP_INFO
: {
11539 struct vki_v4l2_dbg_chip_info
*data
=
11540 (struct vki_v4l2_dbg_chip_info
*)(Addr
)ARG3
;
11541 POST_FIELD_WRITE(data
->name
);
11542 POST_FIELD_WRITE(data
->flags
);
11545 case VKI_V4L2_QUERY_EXT_CTRL
: {
11546 struct vki_v4l2_query_ext_ctrl
*data
=
11547 (struct vki_v4l2_query_ext_ctrl
*)(Addr
)ARG3
;
11548 POST_MEM_WRITE((Addr
)&data
->type
,
11549 sizeof(*data
) - sizeof(data
->id
) - sizeof(data
->reserved
));
11553 case VKI_V4L2_SUBDEV_S_FMT
:
11554 case VKI_V4L2_SUBDEV_S_FRAME_INTERVAL
:
11555 case VKI_V4L2_SUBDEV_S_CROP
:
11556 case VKI_V4L2_SUBDEV_S_SELECTION
:
11559 case VKI_V4L2_SUBDEV_G_FMT
: {
11560 struct vki_v4l2_subdev_format
*data
=
11561 (struct vki_v4l2_subdev_format
*)(Addr
)ARG3
;
11562 POST_FIELD_WRITE(data
->format
);
11565 case VKI_V4L2_SUBDEV_G_FRAME_INTERVAL
: {
11566 struct vki_v4l2_subdev_frame_interval
*data
=
11567 (struct vki_v4l2_subdev_frame_interval
*)(Addr
)ARG3
;
11568 POST_FIELD_WRITE(data
->interval
);
11571 case VKI_V4L2_SUBDEV_ENUM_MBUS_CODE
: {
11572 struct vki_v4l2_subdev_mbus_code_enum
*data
=
11573 (struct vki_v4l2_subdev_mbus_code_enum
*)(Addr
)ARG3
;
11574 POST_FIELD_WRITE(data
->code
);
11577 case VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE
: {
11578 struct vki_v4l2_subdev_frame_size_enum
*data
=
11579 (struct vki_v4l2_subdev_frame_size_enum
*)(Addr
)ARG3
;
11580 POST_FIELD_WRITE(data
->min_width
);
11581 POST_FIELD_WRITE(data
->min_height
);
11582 POST_FIELD_WRITE(data
->max_width
);
11583 POST_FIELD_WRITE(data
->max_height
);
11586 case VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL
: {
11587 struct vki_v4l2_subdev_frame_interval_enum
*data
=
11588 (struct vki_v4l2_subdev_frame_interval_enum
*)(Addr
)ARG3
;
11589 POST_FIELD_WRITE(data
->interval
);
11592 case VKI_V4L2_SUBDEV_G_CROP
: {
11593 struct vki_v4l2_subdev_crop
*data
=
11594 (struct vki_v4l2_subdev_crop
*)(Addr
)ARG3
;
11595 POST_FIELD_WRITE(data
->rect
);
11598 case VKI_V4L2_SUBDEV_G_SELECTION
: {
11599 struct vki_v4l2_subdev_selection
*data
=
11600 (struct vki_v4l2_subdev_selection
*)(Addr
)ARG3
;
11601 POST_FIELD_WRITE(data
->r
);
11604 case VKI_MEDIA_IOC_DEVICE_INFO
: {
11605 struct vki_media_device_info
*data
=
11606 (struct vki_media_device_info
*)(Addr
)ARG3
;
11607 POST_MEM_WRITE((Addr
)data
, sizeof(*data
) - sizeof(data
->reserved
));
11610 case VKI_MEDIA_IOC_ENUM_ENTITIES
: {
11611 struct vki_media_entity_desc
*data
=
11612 (struct vki_media_entity_desc
*)(Addr
)ARG3
;
11613 POST_MEM_WRITE((Addr
)data
->name
, sizeof(*data
) - sizeof(data
->id
));
11616 case VKI_MEDIA_IOC_ENUM_LINKS
:
11618 * This ioctl does write to the provided pointers, but it's not
11619 * possible to deduce the size of the array those pointers point to.
11622 case VKI_MEDIA_IOC_SETUP_LINK
:
11626 case VKI_TIOCGSERIAL
: {
11627 struct vki_serial_struct
*data
= (struct vki_serial_struct
*)(Addr
)ARG3
;
11628 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11631 case VKI_TIOCSSERIAL
:
11634 case VKI_PERF_EVENT_IOC_ENABLE
:
11635 case VKI_PERF_EVENT_IOC_DISABLE
:
11636 case VKI_PERF_EVENT_IOC_REFRESH
:
11637 case VKI_PERF_EVENT_IOC_RESET
:
11638 case VKI_PERF_EVENT_IOC_PERIOD
:
11639 case VKI_PERF_EVENT_IOC_SET_OUTPUT
:
11640 case VKI_PERF_EVENT_IOC_SET_FILTER
:
11641 case VKI_PERF_EVENT_IOC_SET_BPF
:
11644 case VKI_PERF_EVENT_IOC_ID
:
11645 POST_MEM_WRITE((Addr
)ARG3
, sizeof(__vki_u64
));
11648 /* Pulse Per Second (PPS) */
11649 case VKI_PPS_GETPARAMS
: {
11650 struct vki_pps_kparams
*data
= (struct vki_pps_kparams
*)(Addr
)ARG3
;
11651 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11654 case VKI_PPS_GETCAP
:
11655 POST_MEM_WRITE((Addr
)ARG3
, sizeof(int));
11657 case VKI_PPS_FETCH
: {
11658 struct vki_pps_fdata
*data
= (struct vki_pps_fdata
*)(Addr
)ARG3
;
11659 POST_FIELD_WRITE(data
->info
);
11662 case VKI_PPS_SETPARAMS
:
11663 case VKI_PPS_KC_BIND
:
11666 /* PTP Hardware Clock */
11667 case VKI_PTP_CLOCK_GETCAPS
: {
11668 struct vki_ptp_clock_caps
*data
=
11669 (struct vki_ptp_clock_caps
*)(Addr
)ARG3
;
11670 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11673 case VKI_PTP_SYS_OFFSET
: {
11674 struct vki_ptp_sys_offset
*data
=
11675 (struct vki_ptp_sys_offset
*)(Addr
)ARG3
;
11676 POST_MEM_WRITE((Addr
)data
->ts
,
11677 (2 * data
->n_samples
+ 1) * sizeof(data
->ts
[0]));
11680 case VKI_PTP_PIN_GETFUNC
: {
11681 struct vki_ptp_pin_desc
*data
= (struct vki_ptp_pin_desc
*)(Addr
)ARG3
;
11682 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11685 case VKI_PTP_SYS_OFFSET_PRECISE
: {
11686 struct vki_ptp_sys_offset_precise
*data
=
11687 (struct vki_ptp_sys_offset_precise
*)(Addr
)ARG3
;
11688 POST_MEM_WRITE((Addr
)data
, sizeof(*data
));
11691 case VKI_PTP_SYS_OFFSET_EXTENDED
: {
11692 struct vki_ptp_sys_offset_extended
*data
=
11693 (struct vki_ptp_sys_offset_extended
*)(Addr
)ARG3
;
11694 POST_MEM_WRITE((Addr
)data
->ts
,
11695 3 * data
->n_samples
* sizeof(data
->ts
[0][0]));
11698 case VKI_PTP_EXTTS_REQUEST
:
11699 case VKI_PTP_PEROUT_REQUEST
:
11700 case VKI_PTP_ENABLE_PPS
:
11701 case VKI_PTP_PIN_SETFUNC
:
11705 /* EVIOC* are variable length and return size written on success */
11706 switch (ARG2
& ~(_VKI_IOC_SIZEMASK
<< _VKI_IOC_SIZESHIFT
)) {
11707 case VKI_EVIOCGNAME(0):
11708 case VKI_EVIOCGPHYS(0):
11709 case VKI_EVIOCGUNIQ(0):
11710 case VKI_EVIOCGKEY(0):
11711 case VKI_EVIOCGLED(0):
11712 case VKI_EVIOCGSND(0):
11713 case VKI_EVIOCGSW(0):
11714 case VKI_EVIOCGBIT(VKI_EV_SYN
,0):
11715 case VKI_EVIOCGBIT(VKI_EV_KEY
,0):
11716 case VKI_EVIOCGBIT(VKI_EV_REL
,0):
11717 case VKI_EVIOCGBIT(VKI_EV_ABS
,0):
11718 case VKI_EVIOCGBIT(VKI_EV_MSC
,0):
11719 case VKI_EVIOCGBIT(VKI_EV_SW
,0):
11720 case VKI_EVIOCGBIT(VKI_EV_LED
,0):
11721 case VKI_EVIOCGBIT(VKI_EV_SND
,0):
11722 case VKI_EVIOCGBIT(VKI_EV_REP
,0):
11723 case VKI_EVIOCGBIT(VKI_EV_FF
,0):
11724 case VKI_EVIOCGBIT(VKI_EV_PWR
,0):
11725 case VKI_EVIOCGBIT(VKI_EV_FF_STATUS
,0):
11727 POST_MEM_WRITE(ARG3
, RES
);
11730 ML_(POST_unknown_ioctl
)(tid
, RES
, ARG2
, ARG3
);
11736 post_sys_ioctl__out
:
11737 {} /* keep C compilers happy */
11740 /* ---------------------------------------------------------------------
11741 socketcall wrapper helpers
11742 ------------------------------------------------------------------ */
11745 ML_(linux_PRE_sys_getsockopt
) ( ThreadId tid
,
11746 UWord arg0
, UWord arg1
, UWord arg2
,
11747 UWord arg3
, UWord arg4
)
11749 /* int getsockopt(int s, int level, int optname,
11750 void *optval, socklen_t *optlen); */
11751 Addr optval_p
= arg3
;
11752 Addr optlen_p
= arg4
;
11753 /* vg_assert(sizeof(socklen_t) == sizeof(UInt)); */
11754 if (optval_p
!= (Addr
)NULL
) {
11755 ML_(buf_and_len_pre_check
) ( tid
, optval_p
, optlen_p
,
11756 "socketcall.getsockopt(optval)",
11757 "socketcall.getsockopt(optlen)" );
11758 if (arg1
== VKI_SOL_SCTP
&&
11759 (arg2
== VKI_SCTP_GET_PEER_ADDRS
||
11760 arg2
== VKI_SCTP_GET_LOCAL_ADDRS
))
11762 struct vki_sctp_getaddrs
*ga
= (struct vki_sctp_getaddrs
*)arg3
;
11763 int address_bytes
= sizeof(struct vki_sockaddr_in6
) * ga
->addr_num
;
11764 PRE_MEM_WRITE( "socketcall.getsockopt(optval.addrs)",
11765 (Addr
)ga
->addrs
, address_bytes
);
11771 ML_(linux_POST_sys_getsockopt
) ( ThreadId tid
,
11773 UWord arg0
, UWord arg1
, UWord arg2
,
11774 UWord arg3
, UWord arg4
)
11776 Addr optval_p
= arg3
;
11777 Addr optlen_p
= arg4
;
11778 vg_assert(!sr_isError(res
)); /* guaranteed by caller */
11779 if (optval_p
!= (Addr
)NULL
) {
11780 ML_(buf_and_len_post_check
) ( tid
, res
, optval_p
, optlen_p
,
11781 "socketcall.getsockopt(optlen_out)" );
11782 if (arg1
== VKI_SOL_SCTP
&&
11783 (arg2
== VKI_SCTP_GET_PEER_ADDRS
||
11784 arg2
== VKI_SCTP_GET_LOCAL_ADDRS
))
11786 struct vki_sctp_getaddrs
*ga
= (struct vki_sctp_getaddrs
*)arg3
;
11787 struct vki_sockaddr
*a
= ga
->addrs
;
11789 for (i
= 0; i
< ga
->addr_num
; i
++) {
11791 if (a
->sa_family
== VKI_AF_INET
)
11792 sl
= sizeof(struct vki_sockaddr_in
);
11793 else if (a
->sa_family
== VKI_AF_INET6
)
11794 sl
= sizeof(struct vki_sockaddr_in6
);
11796 VG_(message
)(Vg_UserMsg
, "Warning: getsockopt: unhandled "
11797 "address type %d\n", a
->sa_family
);
11799 a
= (struct vki_sockaddr
*)((char*)a
+ sl
);
11801 POST_MEM_WRITE( (Addr
)ga
->addrs
, (char*)a
- (char*)ga
->addrs
);
11807 ML_(linux_PRE_sys_setsockopt
) ( ThreadId tid
,
11808 UWord arg0
, UWord arg1
, UWord arg2
,
11809 UWord arg3
, UWord arg4
)
11811 /* int setsockopt(int s, int level, int optname,
11812 const void *optval, socklen_t optlen); */
11813 Addr optval_p
= arg3
;
11814 if (optval_p
!= (Addr
)NULL
) {
11816 * OK, let's handle at least some setsockopt levels and options
11817 * ourselves, so we don't get false claims of references to
11818 * uninitialized memory (such as padding in structures) and *do*
11819 * check what pointers in the argument point to.
11821 if (arg1
== VKI_SOL_SOCKET
&& arg2
== VKI_SO_ATTACH_FILTER
)
11823 struct vki_sock_fprog
*fp
= (struct vki_sock_fprog
*)optval_p
;
11826 * struct sock_fprog has a 16-bit count of instructions,
11827 * followed by a pointer to an array of those instructions.
11828 * There's padding between those two elements.
11830 * So that we don't bogusly complain about the padding bytes,
11831 * we just report that we read len and and filter.
11833 * We then make sure that what filter points to is valid.
11835 PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, &optval.len)",
11836 (Addr
)&fp
->len
, sizeof(fp
->len
) );
11837 PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, &optval.filter)",
11838 (Addr
)&fp
->filter
, sizeof(fp
->filter
) );
11840 /* len * sizeof (*filter) */
11841 if (fp
->filter
!= NULL
)
11843 PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, optval.filter)",
11844 (Addr
)(fp
->filter
),
11845 fp
->len
* sizeof(*fp
->filter
) );
11850 PRE_MEM_READ( "socketcall.setsockopt(optval)",
11852 arg4
/* optlen */ );
11858 ML_(linux_PRE_sys_recvmmsg
) ( ThreadId tid
,
11859 UWord arg1
, UWord arg2
, UWord arg3
,
11860 UWord arg4
, UWord arg5
)
11862 struct vki_mmsghdr
*mmsg
= (struct vki_mmsghdr
*)arg2
;
11863 HChar name
[40]; // large enough
11865 for (i
= 0; i
< arg3
; i
++) {
11866 VG_(sprintf
)(name
, "mmsg[%u].msg_hdr", i
);
11867 ML_(generic_PRE_sys_recvmsg
)(tid
, name
, &mmsg
[i
].msg_hdr
);
11868 VG_(sprintf
)(name
, "recvmmsg(mmsg[%u].msg_len)", i
);
11869 PRE_MEM_WRITE( name
, (Addr
)&mmsg
[i
].msg_len
, sizeof(mmsg
[i
].msg_len
) );
11872 PRE_MEM_READ( "recvmmsg(timeout)", arg5
, sizeof(struct vki_timespec
) );
11876 ML_(linux_POST_sys_recvmmsg
) (ThreadId tid
, UWord res
,
11877 UWord arg1
, UWord arg2
, UWord arg3
,
11878 UWord arg4
, UWord arg5
)
11881 struct vki_mmsghdr
*mmsg
= (struct vki_mmsghdr
*)arg2
;
11882 HChar name
[32]; // large enough
11884 for (i
= 0; i
< res
; i
++) {
11885 VG_(sprintf
)(name
, "mmsg[%u].msg_hdr", i
);
11886 ML_(generic_POST_sys_recvmsg
)(tid
, name
, &mmsg
[i
].msg_hdr
, mmsg
[i
].msg_len
);
11887 POST_MEM_WRITE( (Addr
)&mmsg
[i
].msg_len
, sizeof(mmsg
[i
].msg_len
) );
11893 ML_(linux_PRE_sys_sendmmsg
) ( ThreadId tid
,
11894 UWord arg1
, UWord arg2
, UWord arg3
, UWord arg4
)
11896 struct vki_mmsghdr
*mmsg
= (struct vki_mmsghdr
*)arg2
;
11897 HChar name
[40]; // large enough
11899 for (i
= 0; i
< arg3
; i
++) {
11900 VG_(sprintf
)(name
, "mmsg[%u].msg_hdr", i
);
11901 ML_(generic_PRE_sys_sendmsg
)(tid
, name
, &mmsg
[i
].msg_hdr
);
11902 VG_(sprintf
)(name
, "sendmmsg(mmsg[%u].msg_len)", i
);
11903 PRE_MEM_WRITE( name
, (Addr
)&mmsg
[i
].msg_len
, sizeof(mmsg
[i
].msg_len
) );
11908 ML_(linux_POST_sys_sendmmsg
) (ThreadId tid
, UWord res
,
11909 UWord arg1
, UWord arg2
, UWord arg3
, UWord arg4
)
11912 struct vki_mmsghdr
*mmsg
= (struct vki_mmsghdr
*)arg2
;
11914 for (i
= 0; i
< res
; i
++) {
11915 POST_MEM_WRITE( (Addr
)&mmsg
[i
].msg_len
, sizeof(mmsg
[i
].msg_len
) );
11920 /* ---------------------------------------------------------------------
11921 ptrace wrapper helpers
11922 ------------------------------------------------------------------ */
11925 ML_(linux_POST_traceme
) ( ThreadId tid
)
11927 ThreadState
*tst
= VG_(get_ThreadState
)(tid
);
11928 tst
->ptrace
= VKI_PT_PTRACED
;
11932 ML_(linux_PRE_getregset
) ( ThreadId tid
, long arg3
, long arg4
)
11934 struct vki_iovec
*iov
= (struct vki_iovec
*) arg4
;
11936 PRE_FIELD_READ("ptrace(getregset iovec->iov_base)", iov
->iov_base
);
11937 PRE_FIELD_READ("ptrace(getregset iovec->iov_len)", iov
->iov_len
);
11938 if (ML_(safe_to_deref
)(iov
, sizeof(struct vki_iovec
))) {
11939 PRE_MEM_WRITE("ptrace(getregset *(iovec->iov_base))",
11940 (Addr
) iov
->iov_base
, iov
->iov_len
);
11945 ML_(linux_PRE_setregset
) ( ThreadId tid
, long arg3
, long arg4
)
11947 struct vki_iovec
*iov
= (struct vki_iovec
*) arg4
;
11949 PRE_FIELD_READ("ptrace(setregset iovec->iov_base)", iov
->iov_base
);
11950 PRE_FIELD_READ("ptrace(setregset iovec->iov_len)", iov
->iov_len
);
11951 if (ML_(safe_to_deref
)(iov
, sizeof(struct vki_iovec
))) {
11952 PRE_MEM_READ("ptrace(setregset *(iovec->iov_base))",
11953 (Addr
) iov
->iov_base
, iov
->iov_len
);
11958 ML_(linux_POST_getregset
) ( ThreadId tid
, long arg3
, long arg4
)
11960 struct vki_iovec
*iov
= (struct vki_iovec
*) arg4
;
11962 /* XXX: The actual amount of data written by the kernel might be
11963 less than iov_len, depending on the regset (arg3). */
11964 POST_MEM_WRITE((unsigned long) iov
->iov_base
, iov
->iov_len
);
11969 PRINT("kcmp ( %ld, %ld, %ld, %" FMT_REGWORD
"u, %" FMT_REGWORD
"u )",
11970 SARG1
, SARG2
, SARG3
, ARG4
, ARG5
);
11972 case VKI_KCMP_VM
: case VKI_KCMP_FILES
: case VKI_KCMP_FS
:
11973 case VKI_KCMP_SIGHAND
: case VKI_KCMP_IO
: case VKI_KCMP_SYSVSEM
:
11974 /* Most of the comparison types don't look at |idx1| or
11976 PRE_REG_READ3(long, "kcmp",
11977 vki_pid_t
, pid1
, vki_pid_t
, pid2
, int, type
);
11979 case VKI_KCMP_FILE
:
11981 PRE_REG_READ5(long, "kcmp",
11982 vki_pid_t
, pid1
, vki_pid_t
, pid2
, int, type
,
11983 unsigned long, idx1
, unsigned long, idx2
);
11988 /* ---------------------------------------------------------------------
11990 ------------------------------------------------------------------ */
11992 static Bool
bpf_map_get_sizes(Int fd
, UInt
*key_size
, UInt
*value_size
)
11994 HChar path
[32], buf
[1024]; /* large enough */
12002 VG_(sprintf
)(path
, "/proc/%d/fdinfo/%d", VG_(getpid
)(), fd
);
12003 sres
= VG_(open
)(path
, VKI_O_RDONLY
, 0);
12004 if (sr_isError(sres
))
12006 proc_fd
= sr_Res(sres
);
12008 if (VG_(read
)(proc_fd
, buf
, sizeof(buf
)) <= 0)
12010 VG_(close
)(proc_fd
);
12012 comp
= VG_(strstr
)(buf
, "key_size:");
12014 *key_size
= VG_(strtoull10
)(comp
+ sizeof("key_size:"), NULL
);
12016 comp
= VG_(strstr
)(buf
, "value_size:");
12018 *value_size
= VG_(strtoull10
)(comp
+ sizeof("value_size:"), NULL
);
12020 return (*key_size
&& *value_size
);
12024 * From a file descriptor for an eBPF object, try to determine the size of the
12025 * struct that will be written, i.e. determine if object is a map or a program.
12026 * There is no direct way to do this, so parse /proc/<pid>/fdinfo/<fd> and
12027 * search for strings "prog_type" or "map_type".
12029 static UInt
bpf_obj_get_info_size(Int fd
)
12031 HChar path
[32], buf
[1024]; /* large enough */
12035 VG_(sprintf
)(path
, "/proc/%d/fdinfo/%d", VG_(getpid
)(), fd
);
12036 sres
= VG_(open
)(path
, VKI_O_RDONLY
, 0);
12037 if (sr_isError(sres
))
12039 proc_fd
= sr_Res(sres
);
12041 if (VG_(read
)(proc_fd
, buf
, sizeof(buf
)) <= 0)
12043 VG_(close
)(proc_fd
);
12045 if (VG_(strstr
)(buf
, "prog_type:"))
12046 return sizeof(struct vki_bpf_prog_info
);
12048 if (VG_(strstr
)(buf
, "map_type:"))
12049 return sizeof(struct vki_bpf_map_info
);
12056 union vki_bpf_attr
*attr
= (union vki_bpf_attr
*)(Addr
)ARG2
;
12057 UInt res
, key_size
, value_size
;
12059 PRINT("sys_bpf ( %ld, %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
12060 (Word
)ARG1
, ARG2
, ARG3
);
12061 PRE_REG_READ3(long, "bpf",
12062 int, cmd
, union vki_bpf_attr
*, attr
, unsigned int, size
);
12064 case VKI_BPF_PROG_GET_NEXT_ID
:
12065 case VKI_BPF_MAP_GET_NEXT_ID
:
12066 PRE_MEM_WRITE("bpf(attr->next_id", (Addr
)&attr
->next_id
, sizeof(attr
->next_id
));
12068 case VKI_BPF_PROG_GET_FD_BY_ID
:
12069 PRE_MEM_READ("bpf(attr->prog_id", (Addr
)&attr
->prog_id
, sizeof(attr
->prog_id
));
12071 case VKI_BPF_MAP_GET_FD_BY_ID
:
12072 PRE_MEM_READ("bpf(attr->map_id", (Addr
)&attr
->map_id
, sizeof(attr
->map_id
));
12074 case VKI_BPF_BTF_GET_FD_BY_ID
:
12075 PRE_MEM_READ("bpf(attr->btf_id", (Addr
)&attr
->btf_id
, sizeof(attr
->btf_id
));
12077 case VKI_BPF_MAP_CREATE
:
12078 PRE_MEM_READ("bpf(attr->map_flags", (Addr
)&attr
->map_flags
, sizeof(attr
->map_flags
));
12079 if (attr
->map_flags
& VKI_BPF_F_NUMA_NODE
)
12080 PRE_MEM_READ("bpf(attr->numa_node", (Addr
)&attr
->numa_node
, sizeof(attr
->numa_node
));
12081 PRE_MEM_READ("bpf(attr->map_type", (Addr
)&attr
->map_type
, sizeof(attr
->map_type
));
12082 PRE_MEM_READ("bpf(attr->map_ifindex", (Addr
)&attr
->map_ifindex
, sizeof(attr
->map_ifindex
));
12083 PRE_MEM_READ("bpf(attr->max_entries", (Addr
)&attr
->max_entries
, sizeof(attr
->max_entries
));
12084 PRE_MEM_READ("bpf(attr->key_size", (Addr
)&attr
->key_size
, sizeof(attr
->key_size
));
12085 PRE_MEM_READ("bpf(attr->value_size", (Addr
)&attr
->value_size
, sizeof(attr
->value_size
));
12086 pre_asciiz_str(tid
, (unsigned long int)attr
->map_name
,
12087 VKI_BPF_OBJ_NAME_LEN
, "bpf(attr->map_name)");
12088 switch (attr
->map_type
) {
12089 case VKI_BPF_MAP_TYPE_ARRAY_OF_MAPS
:
12090 case VKI_BPF_MAP_TYPE_HASH_OF_MAPS
:
12091 PRE_MEM_READ("bpf(attr->inner_map_fd", (Addr
)&attr
->inner_map_fd
, sizeof(attr
->inner_map_fd
));
12092 if (!ML_(fd_allowed
)(attr
->inner_map_fd
, "bpf", tid
, False
))
12093 SET_STATUS_Failure(VKI_EBADF
);
12095 case VKI_BPF_MAP_TYPE_ARRAY
:
12096 if (ARG3
>= offsetof(union vki_bpf_attr
, btf_value_type_id
) + sizeof(__vki_u32
)) {
12097 PRE_MEM_READ("bpf(attr->btf_key_type_id", (Addr
)&attr
->btf_key_type_id
, sizeof(attr
->btf_key_type_id
));
12098 PRE_MEM_READ("bpf(attr->btf_value_type_id", (Addr
)&attr
->btf_value_type_id
, sizeof(attr
->btf_value_type_id
));
12099 if (attr
->btf_key_type_id
&& attr
->btf_value_type_id
) {
12100 PRE_MEM_READ("bpf(attr->btf_id", (Addr
)&attr
->btf_id
, sizeof(attr
->btf_id
));
12101 if (!ML_(fd_allowed
)(attr
->btf_fd
, "bpf", tid
, False
)) {
12102 SET_STATUS_Failure(VKI_EBADF
);
12108 case VKI_BPF_MAP_TYPE_UNSPEC
:
12109 case VKI_BPF_MAP_TYPE_HASH
:
12110 case VKI_BPF_MAP_TYPE_PROG_ARRAY
:
12111 case VKI_BPF_MAP_TYPE_PERF_EVENT_ARRAY
:
12112 case VKI_BPF_MAP_TYPE_PERCPU_HASH
:
12113 case VKI_BPF_MAP_TYPE_PERCPU_ARRAY
:
12114 case VKI_BPF_MAP_TYPE_STACK_TRACE
:
12115 case VKI_BPF_MAP_TYPE_CGROUP_ARRAY
:
12116 case VKI_BPF_MAP_TYPE_LRU_HASH
:
12117 case VKI_BPF_MAP_TYPE_LRU_PERCPU_HASH
:
12118 case VKI_BPF_MAP_TYPE_LPM_TRIE
:
12119 case VKI_BPF_MAP_TYPE_DEVMAP
:
12120 case VKI_BPF_MAP_TYPE_SOCKMAP
:
12121 case VKI_BPF_MAP_TYPE_CPUMAP
:
12122 case VKI_BPF_MAP_TYPE_XSKMAP
:
12123 case VKI_BPF_MAP_TYPE_SOCKHASH
:
12128 case VKI_BPF_MAP_LOOKUP_ELEM
:
12129 /* Perform a lookup on an eBPF map. Read key, write value. */
12130 PRE_MEM_READ("bpf(attr->key)", (Addr
)&attr
->key
, sizeof(attr
->key
));
12131 PRE_MEM_READ("bpf(attr->value)", (Addr
)&attr
->value
, sizeof(attr
->value
));
12132 PRE_MEM_READ("bpf(attr->map_fd)", (Addr
)&attr
->map_fd
, sizeof(attr
->map_fd
));
12133 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12134 if (!ML_(fd_allowed
)(attr
->map_fd
, "bpf", tid
, False
)) {
12135 SET_STATUS_Failure(VKI_EBADF
);
12138 /* Get size of key and value for this map. */
12139 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
)) {
12140 PRE_MEM_READ("bpf(attr->key)", attr
->key
, key_size
);
12141 PRE_MEM_WRITE("bpf(attr->value)", attr
->value
, value_size
);
12145 case VKI_BPF_MAP_UPDATE_ELEM
:
12146 /* Add or update a map element in kernel. Read key, read value. */
12147 PRE_MEM_READ("bpf(attr->key)", (Addr
)&attr
->key
, sizeof(attr
->key
));
12148 PRE_MEM_READ("bpf(attr->value)", (Addr
)&attr
->value
, sizeof(attr
->value
));
12149 PRE_MEM_READ("bpf(attr->map_fd)", (Addr
)&attr
->map_fd
, sizeof(attr
->map_fd
));
12150 PRE_MEM_READ("bpf(attr->flags)", (Addr
)&attr
->flags
, sizeof(attr
->flags
));
12151 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12152 if (!ML_(fd_allowed
)(attr
->map_fd
, "bpf", tid
, False
)) {
12153 SET_STATUS_Failure(VKI_EBADF
);
12156 /* Get size of key and value for this map. */
12157 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
)) {
12158 PRE_MEM_READ("bpf(attr->key)", attr
->key
, key_size
);
12159 PRE_MEM_READ("bpf(attr->value)", attr
->value
, value_size
);
12163 case VKI_BPF_MAP_DELETE_ELEM
:
12164 /* Delete a map element in kernel. Read key from user space. */
12165 PRE_MEM_READ("bpf(attr->key)", (Addr
)&attr
->key
, sizeof(attr
->key
));
12166 PRE_MEM_READ("bpf(attr->map_fd)", (Addr
)&attr
->map_fd
, sizeof(attr
->map_fd
));
12167 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12168 if (!ML_(fd_allowed
)(attr
->map_fd
, "bpf", tid
, False
)) {
12169 SET_STATUS_Failure(VKI_EBADF
);
12172 /* Get size of key for this map. */
12173 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
))
12174 PRE_MEM_READ("bpf(attr->key)", attr
->key
, key_size
);
12177 case VKI_BPF_MAP_GET_NEXT_KEY
:
12178 /* From a key, get next key for the map. Read key, write next key. */
12179 PRE_MEM_READ("bpf(attr->key)", (Addr
)&attr
->key
, sizeof(attr
->key
));
12180 PRE_MEM_READ("bpf(attr->next_key)", (Addr
)&attr
->next_key
, sizeof(attr
->next_key
));
12181 PRE_MEM_READ("bpf(attr->map_fd)", (Addr
)&attr
->map_fd
, sizeof(attr
->map_fd
));
12182 PRE_MEM_READ("bpf(attr->flags)", (Addr
)&attr
->flags
, sizeof(attr
->flags
));
12183 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12184 if (!ML_(fd_allowed
)(attr
->map_fd
, "bpf", tid
, False
)) {
12185 SET_STATUS_Failure(VKI_EBADF
);
12188 /* Get size of key for this map. */
12189 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
)) {
12190 PRE_MEM_READ("bpf(attr->key)", attr
->key
, key_size
);
12191 PRE_MEM_WRITE("bpf(attr->next_key)", attr
->next_key
, key_size
);
12195 case VKI_BPF_PROG_LOAD
:
12196 /* Load a program into the kernel from an array of instructions. */
12197 PRE_MEM_READ("bpf(attr->prog_type)", (Addr
)&attr
->prog_type
, sizeof(attr
->prog_type
));
12198 PRE_MEM_READ("bpf(attr->prog_flags)", (Addr
)&attr
->prog_flags
, sizeof(attr
->prog_flags
));
12199 PRE_MEM_READ("bpf(attr->license)", (Addr
)&attr
->license
, sizeof(attr
->license
));
12200 PRE_MEM_READ("bpf(attr->insn_cnt)", (Addr
)&attr
->insn_cnt
, sizeof(attr
->insn_cnt
));
12201 PRE_MEM_READ("bpf(attr->expected_attach_type)", (Addr
)&attr
->expected_attach_type
, sizeof(attr
->expected_attach_type
));
12202 PRE_MEM_READ("bpf(attr->prog_ifindex)", (Addr
)&attr
->prog_ifindex
, sizeof(attr
->prog_ifindex
));
12203 PRE_MEM_READ("bpf(attr->log_level)", (Addr
)&attr
->log_level
, sizeof(attr
->log_level
));
12204 PRE_MEM_READ("bpf(attr->log_buf)", (Addr
)&attr
->log_buf
, sizeof(attr
->log_buf
));
12205 PRE_MEM_READ("bpf(attr->log_size)", (Addr
)&attr
->log_size
, sizeof(attr
->log_size
));
12206 pre_asciiz_str(tid
, (Addr
)attr
->prog_name
, VKI_BPF_OBJ_NAME_LEN
, "bpf(attr->prog_name)");
12207 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12208 if (attr
->prog_type
== VKI_BPF_PROG_TYPE_KPROBE
)
12209 PRE_MEM_READ("bpf(attr->kern_version)", (Addr
)&attr
->kern_version
, sizeof(attr
->kern_version
));
12210 /* Read instructions, license, program name. */
12211 PRE_MEM_READ("bpf(attr->insns)", attr
->insns
,
12212 attr
->insn_cnt
* sizeof(struct vki_bpf_insn
));
12213 /* License is limited to 128 characters in kernel/bpf/syscall.c. */
12214 pre_asciiz_str(tid
, attr
->license
, 128, "bpf(attr->license)");
12215 /* Possibly write up to log_len into user space log buffer. */
12216 if (attr
->log_level
|| attr
->log_size
|| attr
->log_buf
)
12217 PRE_MEM_WRITE("bpf(attr->log_buf)", attr
->log_buf
, attr
->log_size
);
12220 case VKI_BPF_OBJ_PIN
:
12221 /* Pin eBPF program or map to given location under /sys/fs/bpf/. */
12223 case VKI_BPF_OBJ_GET
:
12224 /* Get pinned eBPF program or map. Read path name. */
12225 PRE_MEM_READ("bpf(attr->file_flags)", (Addr
)&attr
->file_flags
, sizeof(attr
->file_flags
));
12226 PRE_MEM_READ("bpf(attr->pathname)", (Addr
)&attr
->pathname
, sizeof(attr
->pathname
));
12227 PRE_MEM_READ("bpf(attr->bpf_fd)", (Addr
)&attr
->bpf_fd
, sizeof(attr
->bpf_fd
));
12228 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12229 if (!ML_(fd_allowed
)(attr
->bpf_fd
, "bpf", tid
, False
)) {
12230 SET_STATUS_Failure(VKI_EBADF
);
12233 pre_asciiz_str(tid
, attr
->pathname
, VKI_BPF_OBJ_NAME_LEN
, "bpf(attr->pathname)");
12236 case VKI_BPF_PROG_ATTACH
:
12237 case VKI_BPF_PROG_DETACH
:
12238 /* Detach eBPF program from kernel attach point. */
12239 PRE_MEM_READ("bpf(attr->attach_type)", (Addr
)&attr
->attach_type
, sizeof(attr
->attach_type
));
12240 PRE_MEM_READ("bpf(attr->target_fd)", (Addr
)&attr
->target_fd
, sizeof(attr
->target_fd
));
12241 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12242 if (!ML_(fd_allowed
)(attr
->target_fd
, "bpf", tid
, False
))
12243 SET_STATUS_Failure(VKI_EBADF
);
12244 if (ARG1
== VKI_BPF_PROG_ATTACH
||
12245 (attr
->attach_type
!= VKI_BPF_SK_SKB_STREAM_PARSER
&&
12246 attr
->attach_type
!= VKI_BPF_SK_SKB_STREAM_VERDICT
&&
12247 attr
->attach_type
!= VKI_BPF_SK_MSG_VERDICT
)) {
12248 PRE_MEM_READ("bpf(attr->attach_bpf_fd)", (Addr
)&attr
->attach_bpf_fd
, sizeof(attr
->attach_bpf_fd
));
12249 if (!ML_(fd_allowed
)(attr
->attach_bpf_fd
, "bpf", tid
, False
))
12250 SET_STATUS_Failure(VKI_EBADF
);
12254 case VKI_BPF_PROG_TEST_RUN
:
12255 /* Test prog. Read data_in, write up to data_size_out to data_out. */
12256 PRE_MEM_READ("bpf(attr->test.prog_fd)", (Addr
)&attr
->test
.prog_fd
, sizeof(attr
->test
.prog_fd
));
12257 PRE_MEM_READ("bpf(attr->test.repeat)", (Addr
)&attr
->test
.repeat
, sizeof(attr
->test
.repeat
));
12258 PRE_MEM_READ("bpf(attr->test.data_size_in)", (Addr
)&attr
->test
.data_size_in
, sizeof(attr
->test
.data_size_in
));
12259 PRE_MEM_READ("bpf(attr->test.data_in)", (Addr
)&attr
->test
.data_in
, sizeof(attr
->test
.data_in
));
12260 PRE_MEM_READ("bpf(attr->test.data_out)", (Addr
)&attr
->test
.data_out
, sizeof(attr
->test
.data_out
));
12261 PRE_MEM_WRITE("bpf(attr->test.retval)", (Addr
)&attr
->test
.retval
, sizeof(attr
->test
.retval
));
12262 PRE_MEM_WRITE("bpf(attr->test.data_size_out)", (Addr
)&attr
->test
.data_size_out
, sizeof(attr
->test
.data_size_out
));
12263 PRE_MEM_WRITE("bpf(attr->test.duration)", (Addr
)&attr
->test
.duration
, sizeof(attr
->test
.duration
));
12264 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12265 if (!ML_(fd_allowed
)(attr
->test
.prog_fd
, "bpf", tid
, False
)) {
12266 SET_STATUS_Failure(VKI_EBADF
);
12269 PRE_MEM_READ("bpf(attr->test.data_in)", attr
->test
.data_in
, attr
->test
.data_size_in
);
12270 /* should be data_size_in + VKI_XDP_PACKET_HEADROOM for VKI_BPF_PROG_TYPE_XDP */
12271 PRE_MEM_WRITE("bpf(attr->test.data_out)", attr
->test
.data_out
, attr
->test
.data_size_in
);
12274 case VKI_BPF_OBJ_GET_INFO_BY_FD
:
12275 /* Get info for eBPF map or program. Write info. */
12276 PRE_MEM_READ("bpf(attr->info.bpf_fd)", (Addr
)&attr
->info
.bpf_fd
, sizeof(attr
->info
.bpf_fd
));
12277 PRE_MEM_READ("bpf(attr->info.info)", (Addr
)&attr
->info
.info
, sizeof(attr
->info
.info
));
12278 PRE_MEM_READ("bpf(attr->info.info_len)", (Addr
)&attr
->info
.info_len
, sizeof(attr
->info
.info_len
));
12279 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12280 if (!ML_(fd_allowed
)(attr
->info
.bpf_fd
, "bpf", tid
, False
)) {
12281 SET_STATUS_Failure(VKI_EBADF
);
12284 /* Get size of struct to write: is object a program or a map? */
12285 res
= bpf_obj_get_info_size(attr
->info
.bpf_fd
);
12287 PRE_MEM_WRITE("bpf(attr->info.info)", attr
->info
.info
,
12288 VG_MIN(attr
->info
.info_len
, res
));
12290 PRE_MEM_WRITE("bpf(attr->info.info)", attr
->info
.info
,
12291 VG_MIN(attr
->info
.info_len
,
12292 VG_MAX(VG_MAX(sizeof(struct vki_bpf_prog_info
),
12293 sizeof(struct vki_bpf_map_info
)),
12294 sizeof(struct vki_bpf_btf_info
))));
12297 case VKI_BPF_PROG_QUERY
:
12299 * Query list of eBPF program attached to cgroup.
12300 * Write array of ids (up to attr->query.prog_cnt u32-long ids).
12302 PRE_MEM_READ("bpf(attr->query.query_flags)", (Addr
)&attr
->query
.query_flags
, sizeof(attr
->query
.query_flags
));
12303 PRE_MEM_READ("bpf(attr->query.attach_type)", (Addr
)&attr
->query
.attach_type
, sizeof(attr
->query
.attach_type
));
12304 PRE_MEM_READ("bpf(attr->query.target_fd)", (Addr
)&attr
->query
.target_fd
, sizeof(attr
->query
.target_fd
));
12305 PRE_MEM_READ("bpf(attr->query.prog_cnt)", (Addr
)&attr
->query
.prog_cnt
, sizeof(attr
->query
.prog_cnt
));
12306 PRE_MEM_WRITE("bpf(attr->query.attach_flags)", (Addr
)&attr
->query
.attach_flags
, sizeof(attr
->query
.attach_flags
));
12307 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12308 if (!ML_(fd_allowed
)(attr
->query
.target_fd
, "bpf", tid
, False
)) {
12309 SET_STATUS_Failure(VKI_EBADF
);
12312 if (attr
->query
.prog_cnt
> 0) {
12313 PRE_MEM_READ("bpf(attr->query.prog_ids)", (Addr
)&attr
->query
.prog_ids
, sizeof(attr
->query
.prog_ids
));
12314 if (attr
->query
.prog_ids
) {
12315 PRE_MEM_WRITE("bpf(attr->query.prog_ids)", attr
->query
.prog_ids
,
12316 attr
->query
.prog_cnt
* sizeof(__vki_u32
));
12321 case VKI_BPF_RAW_TRACEPOINT_OPEN
:
12322 /* Open raw tracepoint. Read tracepoint name. */
12323 PRE_MEM_READ("bpf(attr->raw_tracepoint.name)", (Addr
)&attr
->raw_tracepoint
.name
, sizeof(attr
->raw_tracepoint
.name
));
12324 PRE_MEM_READ("bpf(attr->raw_tracepoint.prog_fd)", (Addr
)&attr
->raw_tracepoint
.prog_fd
, sizeof(attr
->raw_tracepoint
.prog_fd
));
12325 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12326 if (!ML_(fd_allowed
)(attr
->raw_tracepoint
.prog_fd
,
12327 "bpf", tid
, False
)) {
12328 SET_STATUS_Failure(VKI_EBADF
);
12331 /* Name is limited to 128 characters in kernel/bpf/syscall.c. */
12332 pre_asciiz_str(tid
, attr
->raw_tracepoint
.name
, 128,
12333 "bpf(attr->raw_tracepoint.name)");
12336 case VKI_BPF_BTF_LOAD
:
12337 /* Load BTF information about a program into the kernel. */
12338 PRE_MEM_READ("bpf(attr->btf)", (Addr
)&attr
->btf
, sizeof(attr
->btf
));
12339 PRE_MEM_READ("bpf(attr->btf_size)", (Addr
)&attr
->btf_size
, sizeof(attr
->btf_size
));
12340 PRE_MEM_READ("bpf(attr->btf_log_buf)", (Addr
)&attr
->btf_log_buf
, sizeof(attr
->btf_log_buf
));
12341 PRE_MEM_READ("bpf(attr->btf_log_size)", (Addr
)&attr
->btf_log_size
, sizeof(attr
->btf_log_size
));
12342 PRE_MEM_READ("bpf(attr->btf_log_level)", (Addr
)&attr
->btf_log_level
, sizeof(attr
->btf_log_level
));
12343 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12344 /* Read BTF data. */
12345 PRE_MEM_READ("bpf(attr->btf)", attr
->btf
, attr
->btf_size
);
12346 /* Possibly write up to btf_log_len into user space log buffer. */
12347 if (attr
->btf_log_level
|| attr
->btf_log_size
|| attr
->btf_log_buf
)
12348 PRE_MEM_WRITE("bpf(attr->btf_log_buf)",
12349 attr
->btf_log_buf
, attr
->btf_log_size
);
12352 case VKI_BPF_TASK_FD_QUERY
:
12353 /* Get info about the task. Write collected info. */
12354 PRE_MEM_READ("bpf(attr->task_fd_query.pid)", (Addr
)&attr
->task_fd_query
.pid
, sizeof(attr
->task_fd_query
.pid
));
12355 PRE_MEM_READ("bpf(attr->task_fd_query.fd)", (Addr
)&attr
->task_fd_query
.fd
, sizeof(attr
->task_fd_query
.fd
));
12356 PRE_MEM_READ("bpf(attr->task_fd_query.flags)", (Addr
)&attr
->task_fd_query
.flags
, sizeof(attr
->task_fd_query
.flags
));
12357 PRE_MEM_READ("bpf(attr->task_fd_query.buf_len)", (Addr
)&attr
->task_fd_query
.buf_len
, sizeof(attr
->task_fd_query
.buf_len
));
12358 PRE_MEM_READ("bpf(attr->task_fd_query.buf)", (Addr
)&attr
->task_fd_query
.buf
, sizeof(attr
->task_fd_query
.buf
));
12359 PRE_MEM_WRITE("bpf(attr->task_fd_query.prog_id)", (Addr
)&attr
->task_fd_query
.prog_id
, sizeof(attr
->task_fd_query
.prog_id
));
12360 PRE_MEM_WRITE("bpf(attr->task_fd_query.fd_type)", (Addr
)&attr
->task_fd_query
.fd_type
, sizeof(attr
->task_fd_query
.fd_type
));
12361 PRE_MEM_WRITE("bpf(attr->task_fd_query.probe_offset)", (Addr
)&attr
->task_fd_query
.probe_offset
, sizeof(attr
->task_fd_query
.probe_offset
));
12362 PRE_MEM_WRITE("bpf(attr->task_fd_query.probe_addr)", (Addr
)&attr
->task_fd_query
.probe_addr
, sizeof(attr
->task_fd_query
.probe_addr
));
12363 if (ML_(safe_to_deref
)(attr
, ARG3
)) {
12364 if (!ML_(fd_allowed
)(attr
->task_fd_query
.fd
, "bpf", tid
, False
)) {
12365 SET_STATUS_Failure(VKI_EBADF
);
12368 if (attr
->task_fd_query
.buf_len
> 0) {
12369 /* Write task or perf event name. */
12370 PRE_MEM_WRITE("bpf(attr->task_fd_query.buf)",
12371 attr
->task_fd_query
.buf
,
12372 attr
->task_fd_query
.buf_len
);
12377 VG_(message
)(Vg_DebugMsg
,
12378 "FATAL: unhandled eBPF command %lu\n", ARG1
);
12379 VG_(core_panic
)("... bye!\n");
12386 union vki_bpf_attr
*attr
= (union vki_bpf_attr
*)(Addr
)ARG2
;
12387 UInt key_size
, value_size
;
12389 vg_assert(SUCCESS
);
12392 case VKI_BPF_PROG_GET_NEXT_ID
:
12393 case VKI_BPF_MAP_GET_NEXT_ID
:
12394 POST_MEM_WRITE(attr
->next_id
, sizeof(attr
->next_id
));
12396 case VKI_BPF_MAP_UPDATE_ELEM
:
12397 case VKI_BPF_MAP_DELETE_ELEM
:
12398 case VKI_BPF_OBJ_PIN
:
12399 case VKI_BPF_PROG_ATTACH
:
12400 case VKI_BPF_PROG_DETACH
:
12402 /* Following commands have bpf() return a file descriptor. */
12403 case VKI_BPF_MAP_CREATE
:
12404 case VKI_BPF_OBJ_GET
:
12405 case VKI_BPF_PROG_GET_FD_BY_ID
:
12406 case VKI_BPF_MAP_GET_FD_BY_ID
:
12407 case VKI_BPF_BTF_GET_FD_BY_ID
:
12408 case VKI_BPF_RAW_TRACEPOINT_OPEN
:
12409 if (!ML_(fd_allowed
)(RES
, "bpf", tid
, True
)) {
12411 SET_STATUS_Failure(VKI_EMFILE
);
12413 if (VG_(clo_track_fds
))
12414 ML_(record_fd_open_nameless
)(tid
, RES
);
12418 * TODO: Is there a way to pass information between PRE and POST hooks?
12419 * To avoid querying again for the size of keys and values.
12421 case VKI_BPF_MAP_LOOKUP_ELEM
:
12422 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
))
12423 POST_MEM_WRITE(attr
->value
, value_size
);
12425 case VKI_BPF_MAP_GET_NEXT_KEY
:
12426 if (bpf_map_get_sizes(attr
->map_fd
, &key_size
, &value_size
))
12427 POST_MEM_WRITE(attr
->next_key
, key_size
);
12429 case VKI_BPF_PROG_LOAD
:
12430 /* Return a file descriptor for loaded program, write into log_buf. */
12431 if (!ML_(fd_allowed
)(RES
, "bpf", tid
, True
)) {
12433 SET_STATUS_Failure(VKI_EMFILE
);
12435 if (VG_(clo_track_fds
))
12436 ML_(record_fd_open_nameless
)(tid
, RES
);
12438 if (attr
->log_level
|| attr
->log_size
|| attr
->log_buf
)
12439 POST_MEM_WRITE(attr
->log_buf
, attr
->log_size
);
12441 case VKI_BPF_PROG_TEST_RUN
:
12442 POST_MEM_WRITE((Addr
)&attr
->test
.retval
, sizeof(attr
->test
.retval
));
12443 POST_MEM_WRITE((Addr
)&attr
->test
.data_size_out
, sizeof(attr
->test
.data_size_out
));
12444 POST_MEM_WRITE((Addr
)&attr
->test
.duration
, sizeof(attr
->test
.duration
));
12445 POST_MEM_WRITE(attr
->test
.data_out
, attr
->test
.data_size_out
);
12447 case VKI_BPF_OBJ_GET_INFO_BY_FD
:
12448 POST_MEM_WRITE(attr
->info
.info
, attr
->info
.info_len
);
12450 case VKI_BPF_PROG_QUERY
:
12451 POST_MEM_WRITE((Addr
)&attr
->query
.attach_flags
, sizeof(attr
->query
.attach_flags
));
12452 POST_MEM_WRITE((Addr
)&attr
->query
.prog_cnt
, sizeof(attr
->query
.prog_cnt
));
12453 if (attr
->query
.prog_ids
)
12454 POST_MEM_WRITE(attr
->query
.prog_ids
,
12455 attr
->query
.prog_cnt
* sizeof(__vki_u32
));
12457 case VKI_BPF_BTF_LOAD
:
12458 /* Return a file descriptor for BTF data, write into btf_log_buf. */
12459 if (!ML_(fd_allowed
)(RES
, "bpf", tid
, True
)) {
12461 SET_STATUS_Failure(VKI_EMFILE
);
12463 if (VG_(clo_track_fds
))
12464 ML_(record_fd_open_nameless
)(tid
, RES
);
12466 if (attr
->btf_log_level
)
12467 POST_MEM_WRITE(attr
->btf_log_buf
, attr
->btf_log_size
);
12469 case VKI_BPF_TASK_FD_QUERY
:
12470 POST_MEM_WRITE(attr
->task_fd_query
.buf
, attr
->task_fd_query
.buf_len
);
12471 POST_MEM_WRITE((Addr
)&attr
->task_fd_query
.prog_id
, sizeof(attr
->task_fd_query
.prog_id
));
12472 POST_MEM_WRITE((Addr
)&attr
->task_fd_query
.fd_type
, sizeof(attr
->task_fd_query
.fd_type
));
12473 POST_MEM_WRITE((Addr
)&attr
->task_fd_query
.probe_offset
, sizeof(attr
->task_fd_query
.probe_offset
));
12474 POST_MEM_WRITE((Addr
)&attr
->task_fd_query
.probe_addr
, sizeof(attr
->task_fd_query
.probe_addr
));
12477 VG_(message
)(Vg_DebugMsg
,
12478 "FATAL: unhandled eBPF command %lu\n", ARG1
);
12479 VG_(core_panic
)("... bye!\n");
12484 PRE(sys_copy_file_range
)
12486 PRINT("sys_copy_file_range (%lu, %lu, %lu, %lu, %lu, %lu)", ARG1
, ARG2
, ARG3
,
12489 PRE_REG_READ6(vki_size_t
, "copy_file_range",
12491 vki_loff_t
*, "off_in",
12493 vki_loff_t
*, "off_out",
12495 unsigned int, "flags");
12497 /* File descriptors are "specially" tracked by valgrind.
12498 valgrind itself uses some, so make sure someone didn't
12499 put in one of our own... */
12500 if (!ML_(fd_allowed
)(ARG1
, "copy_file_range(fd_in)", tid
, False
) ||
12501 !ML_(fd_allowed
)(ARG3
, "copy_file_range(fd_in)", tid
, False
)) {
12502 SET_STATUS_Failure( VKI_EBADF
);
12504 /* Now see if the offsets are defined. PRE_MEM_READ will
12505 double check it can dereference them. */
12507 PRE_MEM_READ( "copy_file_range(off_in)", ARG2
, sizeof(vki_loff_t
));
12509 PRE_MEM_READ( "copy_file_range(off_out)", ARG4
, sizeof(vki_loff_t
));
12513 PRE(sys_pkey_alloc
)
12515 PRINT("pkey_alloc (%lu, %lu)", ARG1
, ARG2
);
12517 PRE_REG_READ2(long, "pkey_alloc",
12518 unsigned long, "flags",
12519 unsigned long, "access_rights");
12521 /* The kernel says: pkey_alloc() is always safe to call regardless of
12522 whether or not the operating system supports protection keys. It can be
12523 used in lieu of any other mechanism for detecting pkey support and will
12524 simply fail with the error ENOSPC if the operating system has no pkey
12527 So we simply always return ENOSPC to signal memory protection keys are
12528 not supported under valgrind, unless there are unknown flags, then we
12530 unsigned long pkey_flags
= ARG1
;
12531 if (pkey_flags
!= 0)
12532 SET_STATUS_Failure( VKI_EINVAL
);
12534 SET_STATUS_Failure( VKI_ENOSPC
);
12539 PRINT("pkey_free (%" FMT_REGWORD
"u )", ARG1
);
12541 PRE_REG_READ1(long, "pkey_free",
12542 unsigned long, "pkey");
12544 /* Since pkey_alloc () can never succeed, see above, freeing any pkey is
12545 always an error. */
12546 SET_STATUS_Failure( VKI_EINVAL
);
12549 PRE(sys_pkey_mprotect
)
12551 PRINT("sys_pkey_mprotect ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
12552 FMT_REGWORD
"u %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
, ARG4
);
12553 PRE_REG_READ4(long, "pkey_mprotect",
12554 unsigned long, addr
, vki_size_t
, len
, unsigned long, prot
,
12555 unsigned long, pkey
);
12562 /* Since pkey_alloc () can never succeed, see above, any pkey is
12563 invalid. Except for -1, then pkey_mprotect acts just like mprotect. */
12565 SET_STATUS_Failure( VKI_EINVAL
);
12567 handle_sys_mprotect (tid
, status
, &addr
, &len
, &prot
);
12574 POST(sys_pkey_mprotect
)
12580 ML_(notify_core_and_tool_of_mprotect
)(addr
, len
, prot
);
12583 PRE(sys_io_uring_setup
)
12585 PRINT("sys_io_uring_setup ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u )",
12587 PRE_REG_READ2(long, "io_uring_setup", unsigned int, entries
,
12588 struct vki_io_uring_params
*, p
);
12590 PRE_MEM_READ("io_uring_setup(p)", ARG2
,
12591 offsetof(struct vki_io_uring_params
, sq_off
));
12594 POST(sys_io_uring_setup
)
12596 vg_assert(SUCCESS
);
12597 if (!ML_(fd_allowed
)(RES
, "io_uring_setup", tid
, True
)) {
12599 SET_STATUS_Failure( VKI_EMFILE
);
12601 if (VG_(clo_track_fds
))
12602 ML_(record_fd_open_with_given_name
)(tid
, RES
, (HChar
*)(Addr
)ARG1
);
12603 POST_MEM_WRITE(ARG2
+ offsetof(struct vki_io_uring_params
, sq_off
),
12604 sizeof(struct vki_io_sqring_offsets
) +
12605 sizeof(struct vki_io_cqring_offsets
));
12609 PRE(sys_io_uring_enter
)
12611 PRINT("sys_io_uring_enter ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
12612 FMT_REGWORD
"u %" FMT_REGWORD
"u, %" FMT_REGWORD
"u %"
12614 ARG1
, ARG2
, ARG3
, ARG4
, ARG5
, ARG6
);
12615 PRE_REG_READ6(long, "io_uring_enter",
12616 unsigned int, fd
, unsigned int, to_submit
,
12617 unsigned int, min_complete
, unsigned int, flags
,
12618 const void *, sig
, unsigned long, sigsz
);
12620 PRE_MEM_READ("io_uring_enter(sig)", ARG5
, ARG6
);
12623 POST(sys_io_uring_enter
)
12627 PRE(sys_io_uring_register
)
12629 PRINT("sys_io_uring_register ( %#" FMT_REGWORD
"x, %" FMT_REGWORD
"u, %"
12630 FMT_REGWORD
"u %" FMT_REGWORD
"u )", ARG1
, ARG2
, ARG3
, ARG4
);
12631 PRE_REG_READ4(long, "io_uring_register",
12632 unsigned int, fd
, unsigned int, opcode
,
12633 void *, arg
, unsigned int, nr_args
);
12635 case VKI_IORING_REGISTER_BUFFERS
:
12636 PRE_MEM_READ("", ARG3
, ARG4
* sizeof(struct vki_iovec
));
12638 case VKI_IORING_UNREGISTER_BUFFERS
:
12640 case VKI_IORING_REGISTER_FILES
:
12641 PRE_MEM_READ("", ARG3
, ARG4
* sizeof(__vki_s32
));
12643 case VKI_IORING_UNREGISTER_FILES
:
12645 case VKI_IORING_REGISTER_EVENTFD
:
12646 PRE_MEM_READ("", ARG3
, sizeof(__vki_s32
));
12648 case VKI_IORING_UNREGISTER_EVENTFD
:
12653 POST(sys_io_uring_register
)
12660 #endif // defined(VGO_linux)
12662 /*--------------------------------------------------------------------*/
12664 /*--------------------------------------------------------------------*/