Home | History | Annotate | Download | only in m_syswrap
      1 
      2 /*--------------------------------------------------------------------*/
      3 /*--- Linux-specific syscalls, etc.                syswrap-linux.c ---*/
      4 /*--------------------------------------------------------------------*/
      5 
      6 /*
      7    This file is part of Valgrind, a dynamic binary instrumentation
      8    framework.
      9 
     10    Copyright (C) 2000-2015 Nicholas Nethercote
     11       njn (at) valgrind.org
     12 
     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.
     17 
     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.
     22 
     23    You should have received a copy of the GNU General Public License
     24    along with this program; if not, write to the Free Software
     25    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
     26    02111-1307, USA.
     27 
     28    The GNU General Public License is contained in the file COPYING.
     29 */
     30 
     31 #if defined(VGO_linux)
     32 
     33 #include "pub_core_basics.h"
     34 #include "pub_core_vki.h"
     35 #include "pub_core_vkiscnums.h"
     36 #include "pub_core_threadstate.h"
     37 #include "pub_core_aspacemgr.h"
     38 #include "pub_core_debuginfo.h"    // VG_(di_notify_*)
     39 #include "pub_core_transtab.h"     // VG_(discard_translations)
     40 #include "pub_core_xarray.h"
     41 #include "pub_core_clientstate.h"
     42 #include "pub_core_debuglog.h"
     43 #include "pub_core_libcbase.h"
     44 #include "pub_core_libcassert.h"
     45 #include "pub_core_libcfile.h"
     46 #include "pub_core_libcprint.h"
     47 #include "pub_core_libcproc.h"
     48 #include "pub_core_libcsignal.h"
     49 #include "pub_core_machine.h"      // VG_(get_SP)
     50 #include "pub_core_mallocfree.h"
     51 #include "pub_core_tooliface.h"
     52 #include "pub_core_options.h"
     53 #include "pub_core_scheduler.h"
     54 #include "pub_core_signals.h"
     55 #include "pub_core_syscall.h"
     56 #include "pub_core_syswrap.h"
     57 #include "pub_core_inner.h"
     58 #if defined(ENABLE_INNER_CLIENT_REQUEST)
     59 #include "pub_core_clreq.h"
     60 #endif
     61 
     62 #include "priv_types_n_macros.h"
     63 #include "priv_syswrap-generic.h"
     64 #include "priv_syswrap-linux.h"
     65 #include "priv_syswrap-xen.h"
     66 
     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)
     70 {
     71    VgSchedReturnCode ret;
     72    ThreadId     tid = (ThreadId)tidW;
     73    ThreadState* tst = VG_(get_ThreadState)(tid);
     74 
     75    VG_(debugLog)(1, "syswrap-linux",
     76                     "thread_wrapper(tid=%u): entry\n",
     77                     tid);
     78 
     79    vg_assert(tst->status == VgTs_Init);
     80 
     81    /* make sure we get the CPU lock before doing anything significant */
     82    VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)");
     83 
     84    if (0)
     85       VG_(printf)("thread tid %u started: stack = %p\n",
     86 		  tid, (void *)&tid);
     87 
     88    /* Make sure error reporting is enabled in the new thread. */
     89    tst->err_disablement_level = 0;
     90 
     91    VG_TRACK(pre_thread_first_insn, tid);
     92 
     93    tst->os_state.lwpid = VG_(gettid)();
     94    /* Set the threadgroup for real.  This overwrites the provisional
     95       value set in do_clone() syswrap-*-linux.c.  See comments in
     96       do_clone for background, also #226116. */
     97    tst->os_state.threadgroup = VG_(getpid)();
     98 
     99    /* Thread created with all signals blocked; scheduler will set the
    100       appropriate mask */
    101 
    102    ret = VG_(scheduler)(tid);
    103 
    104    vg_assert(VG_(is_exiting)(tid));
    105 
    106    vg_assert(tst->status == VgTs_Runnable);
    107    vg_assert(VG_(is_running_thread)(tid));
    108 
    109    VG_(debugLog)(1, "syswrap-linux",
    110                     "thread_wrapper(tid=%u): exit, schedreturncode %s\n",
    111                     tid, VG_(name_of_VgSchedReturnCode)(ret));
    112 
    113    /* Return to caller, still holding the lock. */
    114    return ret;
    115 }
    116 
    117 
    118 /* ---------------------------------------------------------------------
    119    clone-related stuff
    120    ------------------------------------------------------------------ */
    121 
    122 /* Run a thread all the way to the end, then do appropriate exit actions
    123    (this is the last-one-out-turn-off-the-lights bit).  */
    124 static void run_a_thread_NORETURN ( Word tidW )
    125 {
    126    ThreadId          tid = (ThreadId)tidW;
    127    VgSchedReturnCode src;
    128    Int               c;
    129    ThreadState*      tst;
    130 #ifdef ENABLE_INNER_CLIENT_REQUEST
    131    Int               registered_vgstack_id;
    132 #endif
    133 
    134    VG_(debugLog)(1, "syswrap-linux",
    135                     "run_a_thread_NORETURN(tid=%u): pre-thread_wrapper\n",
    136                     tid);
    137 
    138    tst = VG_(get_ThreadState)(tid);
    139    vg_assert(tst);
    140 
    141    /* An thread has two stacks:
    142       * the simulated stack (used by the synthetic cpu. Guest process
    143         is using this stack).
    144       * the valgrind stack (used by the real cpu. Valgrind code is running
    145         on this stack).
    146       When Valgrind runs as an inner, it must signals that its (real) stack
    147       is the stack to use by the outer to e.g. do stacktraces.
    148    */
    149    INNER_REQUEST
    150       (registered_vgstack_id
    151        = VALGRIND_STACK_REGISTER (tst->os_state.valgrind_stack_base,
    152                                   tst->os_state.valgrind_stack_init_SP));
    153 
    154    /* Run the thread all the way through. */
    155    src = thread_wrapper(tid);
    156 
    157    VG_(debugLog)(1, "syswrap-linux",
    158                     "run_a_thread_NORETURN(tid=%u): post-thread_wrapper\n",
    159                     tid);
    160 
    161    c = VG_(count_living_threads)();
    162    vg_assert(c >= 1); /* stay sane */
    163 
    164    // Tell the tool this thread is exiting
    165    VG_TRACK( pre_thread_ll_exit, tid );
    166 
    167    /* If the thread is exiting with errors disabled, complain loudly;
    168       doing so is bad (does the user know this has happened?)  Also,
    169       in all cases, be paranoid and clear the flag anyway so that the
    170       thread slot is safe in this respect if later reallocated.  This
    171       should be unnecessary since the flag should be cleared when the
    172       slot is reallocated, in thread_wrapper(). */
    173    if (tst->err_disablement_level > 0) {
    174       VG_(umsg)(
    175          "WARNING: exiting thread has error reporting disabled.\n"
    176          "WARNING: possibly as a result of some mistake in the use\n"
    177          "WARNING: of the VALGRIND_DISABLE_ERROR_REPORTING macros.\n"
    178       );
    179       VG_(debugLog)(
    180          1, "syswrap-linux",
    181             "run_a_thread_NORETURN(tid=%u): "
    182             "WARNING: exiting thread has err_disablement_level = %u\n",
    183             tid, tst->err_disablement_level
    184       );
    185    }
    186    tst->err_disablement_level = 0;
    187 
    188    if (c == 1) {
    189 
    190       VG_(debugLog)(1, "syswrap-linux",
    191                        "run_a_thread_NORETURN(tid=%u): "
    192                           "last one standing\n",
    193                           tid);
    194 
    195       /* We are the last one standing.  Keep hold of the lock and
    196          carry on to show final tool results, then exit the entire system.
    197          Use the continuation pointer set at startup in m_main. */
    198       ( * VG_(address_of_m_main_shutdown_actions_NORETURN) ) (tid, src);
    199    } else {
    200 
    201       VG_(debugLog)(1, "syswrap-linux",
    202                        "run_a_thread_NORETURN(tid=%u): "
    203                           "not last one standing\n",
    204                           tid);
    205 
    206       /* OK, thread is dead, but others still exist.  Just exit. */
    207 
    208       /* This releases the run lock */
    209       VG_(exit_thread)(tid);
    210       vg_assert(tst->status == VgTs_Zombie);
    211       vg_assert(sizeof(tst->status) == 4);
    212       vg_assert(sizeof(tst->os_state.exitcode) == sizeof(Word));
    213 
    214       INNER_REQUEST (VALGRIND_STACK_DEREGISTER (registered_vgstack_id));
    215 
    216       /* We have to use this sequence to terminate the thread to
    217          prevent a subtle race.  If VG_(exit_thread)() had left the
    218          ThreadState as Empty, then it could have been reallocated,
    219          reusing the stack while we're doing these last cleanups.
    220          Instead, VG_(exit_thread) leaves it as Zombie to prevent
    221          reallocation.  We need to make sure we don't touch the stack
    222          between marking it Empty and exiting.  Hence the
    223          assembler. */
    224 #if defined(VGP_x86_linux)
    225       asm volatile (
    226          "pushl %%ebx\n"
    227          "movl	%1, %0\n"	/* set tst->status = VgTs_Empty */
    228          "movl	%2, %%eax\n"    /* set %eax = __NR_exit */
    229          "movl	%3, %%ebx\n"    /* set %ebx = tst->os_state.exitcode */
    230          "int	$0x80\n"	/* exit(tst->os_state.exitcode) */
    231 	 "popl %%ebx\n"
    232          : "=m" (tst->status)
    233          : "n" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode)
    234          : "eax"
    235       );
    236 #elif defined(VGP_amd64_linux)
    237       asm volatile (
    238          "movl	%1, %0\n"	/* set tst->status = VgTs_Empty */
    239          "movq	%2, %%rax\n"    /* set %rax = __NR_exit */
    240          "movq	%3, %%rdi\n"    /* set %rdi = tst->os_state.exitcode */
    241          "syscall\n"		/* exit(tst->os_state.exitcode) */
    242          : "=m" (tst->status)
    243          : "n" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode)
    244          : "rax", "rdi"
    245       );
    246 #elif defined(VGP_ppc32_linux) || defined(VGP_ppc64be_linux) \
    247       || defined(VGP_ppc64le_linux)
    248       { UInt vgts_empty = (UInt)VgTs_Empty;
    249         asm volatile (
    250           "stw %1,%0\n\t"          /* set tst->status = VgTs_Empty */
    251           "li  0,%2\n\t"           /* set r0 = __NR_exit */
    252           "lwz 3,%3\n\t"           /* set r3 = tst->os_state.exitcode */
    253           "sc\n\t"                 /* exit(tst->os_state.exitcode) */
    254           : "=m" (tst->status)
    255           : "r" (vgts_empty), "n" (__NR_exit), "m" (tst->os_state.exitcode)
    256           : "r0", "r3"
    257         );
    258       }
    259 #elif defined(VGP_arm_linux)
    260       asm volatile (
    261          "str  %1, %0\n"      /* set tst->status = VgTs_Empty */
    262          "mov  r7, %2\n"      /* set %r7 = __NR_exit */
    263          "ldr  r0, %3\n"      /* set %r0 = tst->os_state.exitcode */
    264          "svc  0x00000000\n"  /* exit(tst->os_state.exitcode) */
    265          : "=m" (tst->status)
    266          : "r" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode)
    267          : "r0", "r7"
    268       );
    269 #elif defined(VGP_arm64_linux)
    270       asm volatile (
    271          "str  %w1, %0\n"     /* set tst->status = VgTs_Empty (32-bit store) */
    272          "mov  x8,  %2\n"     /* set %r7 = __NR_exit */
    273          "ldr  x0,  %3\n"     /* set %r0 = tst->os_state.exitcode */
    274          "svc  0x00000000\n"  /* exit(tst->os_state.exitcode) */
    275          : "=m" (tst->status)
    276          : "r" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode)
    277          : "r0", "r7"
    278       );
    279 #elif defined(VGP_s390x_linux)
    280       asm volatile (
    281          "st   %1, %0\n"        /* set tst->status = VgTs_Empty */
    282          "lg   2, %3\n"         /* set r2 = tst->os_state.exitcode */
    283          "svc %2\n"             /* exit(tst->os_state.exitcode) */
    284          : "=m" (tst->status)
    285          : "d" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode)
    286          : "2"
    287       );
    288 #elif defined(VGP_mips32_linux) || defined(VGP_mips64_linux)
    289       asm volatile (
    290          "sw   %1, %0\n\t"     /* set tst->status = VgTs_Empty */
    291          "li   $2, %2\n\t"     /* set v0 = __NR_exit */
    292          "lw   $4, %3\n\t"     /* set a0 = tst->os_state.exitcode */
    293          "syscall\n\t"         /* exit(tst->os_state.exitcode) */
    294          "nop"
    295          : "=m" (tst->status)
    296          : "r" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode)
    297          : "cc", "memory" , "v0", "a0"
    298       );
    299 #elif defined(VGP_tilegx_linux)
    300       asm volatile (
    301          "st4    %0,  %1\n"      /* set tst->status = VgTs_Empty */
    302          "moveli r10, %2\n"      /* set r10 = __NR_exit */
    303          "move   r0,  %3\n"      /* set  r0 = tst->os_state.exitcode */
    304          "swint1\n"              /* exit(tst->os_state.exitcode) */
    305          : "=m" (tst->status)
    306          : "r" (VgTs_Empty), "n" (__NR_exit), "r" (tst->os_state.exitcode)
    307          : "r0", "r1", "r2", "r3", "r4", "r5");
    308 #else
    309 # error Unknown platform
    310 #endif
    311 
    312       VG_(core_panic)("Thread exit failed?\n");
    313    }
    314 
    315    /*NOTREACHED*/
    316    vg_assert(0);
    317 }
    318 
    319 Word ML_(start_thread_NORETURN) ( void* arg )
    320 {
    321    ThreadState* tst = (ThreadState*)arg;
    322    ThreadId     tid = tst->tid;
    323 
    324    run_a_thread_NORETURN ( (Word)tid );
    325    /*NOTREACHED*/
    326    vg_assert(0);
    327 }
    328 
    329 /* Allocate a stack for this thread, if it doesn't already have one.
    330    They're allocated lazily, and never freed.  Returns the initial stack
    331    pointer value to use, or 0 if allocation failed. */
    332 Addr ML_(allocstack)(ThreadId tid)
    333 {
    334    ThreadState* tst = VG_(get_ThreadState)(tid);
    335    VgStack*     stack;
    336    Addr         initial_SP;
    337 
    338    /* Either the stack_base and stack_init_SP are both zero (in which
    339       case a stack hasn't been allocated) or they are both non-zero,
    340       in which case it has. */
    341 
    342    if (tst->os_state.valgrind_stack_base == 0)
    343       vg_assert(tst->os_state.valgrind_stack_init_SP == 0);
    344 
    345    if (tst->os_state.valgrind_stack_base != 0)
    346       vg_assert(tst->os_state.valgrind_stack_init_SP != 0);
    347 
    348    /* If no stack is present, allocate one. */
    349 
    350    if (tst->os_state.valgrind_stack_base == 0) {
    351       stack = VG_(am_alloc_VgStack)( &initial_SP );
    352       if (stack) {
    353          tst->os_state.valgrind_stack_base    = (Addr)stack;
    354          tst->os_state.valgrind_stack_init_SP = initial_SP;
    355       }
    356    }
    357 
    358    if (0)
    359       VG_(printf)( "stack for tid %u at %p; init_SP=%p\n",
    360                    tid,
    361                    (void*)tst->os_state.valgrind_stack_base,
    362                    (void*)tst->os_state.valgrind_stack_init_SP );
    363 
    364    return tst->os_state.valgrind_stack_init_SP;
    365 }
    366 
    367 /* Allocate a stack for the main thread, and run it all the way to the
    368    end.  Although we already have a working VgStack
    369    (VG_(interim_stack)) it's better to allocate a new one, so that
    370    overflow detection works uniformly for all threads.
    371 */
    372 void VG_(main_thread_wrapper_NORETURN)(ThreadId tid)
    373 {
    374    Addr sp;
    375    VG_(debugLog)(1, "syswrap-linux",
    376                     "entering VG_(main_thread_wrapper_NORETURN)\n");
    377 
    378    sp = ML_(allocstack)(tid);
    379 #if defined(ENABLE_INNER_CLIENT_REQUEST)
    380    {
    381       // we must register the main thread stack before the call
    382       // to ML_(call_on_new_stack_0_1), otherwise the outer valgrind
    383       // reports 'write error' on the non registered stack.
    384       ThreadState* tst = VG_(get_ThreadState)(tid);
    385       INNER_REQUEST
    386          ((void)
    387           VALGRIND_STACK_REGISTER (tst->os_state.valgrind_stack_base,
    388                                    tst->os_state.valgrind_stack_init_SP));
    389    }
    390 #endif
    391 
    392 #if defined(VGP_ppc32_linux)
    393    /* make a stack frame */
    394    sp -= 16;
    395    sp &= ~0xF;
    396    *(UWord *)sp = 0;
    397 #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
    398    /* make a stack frame */
    399    sp -= 112;
    400    sp &= ~((Addr)0xF);
    401    *(UWord *)sp = 0;
    402 #elif defined(VGP_s390x_linux)
    403    /* make a stack frame */
    404    sp -= 160;
    405    sp &= ~((Addr)0xF);
    406    *(UWord *)sp = 0;
    407 #endif
    408 
    409    /* If we can't even allocate the first thread's stack, we're hosed.
    410       Give up. */
    411    vg_assert2(sp != 0, "Cannot allocate main thread's stack.");
    412 
    413    /* shouldn't be any other threads around yet */
    414    vg_assert( VG_(count_living_threads)() == 1 );
    415 
    416    ML_(call_on_new_stack_0_1)(
    417       (Addr)sp,               /* stack */
    418       0,                      /* bogus return address */
    419       run_a_thread_NORETURN,  /* fn to call */
    420       (Word)tid               /* arg to give it */
    421    );
    422 
    423    /*NOTREACHED*/
    424    vg_assert(0);
    425 }
    426 
    427 
    428 /* Do a clone which is really a fork() */
    429 SysRes ML_(do_fork_clone) ( ThreadId tid, UInt flags,
    430                             Int* parent_tidptr, Int* child_tidptr )
    431 {
    432    vki_sigset_t fork_saved_mask;
    433    vki_sigset_t mask;
    434    SysRes       res;
    435 
    436    if (flags & (VKI_CLONE_SETTLS | VKI_CLONE_FS | VKI_CLONE_VM
    437                 | VKI_CLONE_FILES | VKI_CLONE_VFORK))
    438       return VG_(mk_SysRes_Error)( VKI_EINVAL );
    439 
    440    /* Block all signals during fork, so that we can fix things up in
    441       the child without being interrupted. */
    442    VG_(sigfillset)(&mask);
    443    VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &fork_saved_mask);
    444 
    445    VG_(do_atfork_pre)(tid);
    446 
    447    /* Since this is the fork() form of clone, we don't need all that
    448       VG_(clone) stuff */
    449 #if defined(VGP_x86_linux) \
    450     || defined(VGP_ppc32_linux) \
    451     || defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)	\
    452     || defined(VGP_arm_linux) || defined(VGP_mips32_linux) \
    453     || defined(VGP_mips64_linux) || defined(VGP_arm64_linux)
    454    res = VG_(do_syscall5)( __NR_clone, flags,
    455                            (UWord)NULL, (UWord)parent_tidptr,
    456                            (UWord)NULL, (UWord)child_tidptr );
    457 #elif defined(VGP_amd64_linux) || defined(VGP_tilegx_linux)
    458    /* note that the last two arguments are the opposite way round to x86 and
    459       ppc32 as the amd64 kernel expects the arguments in a different order */
    460    res = VG_(do_syscall5)( __NR_clone, flags,
    461                            (UWord)NULL, (UWord)parent_tidptr,
    462                            (UWord)child_tidptr, (UWord)NULL );
    463 #elif defined(VGP_s390x_linux)
    464    /* Note that s390 has the stack first and then the flags */
    465    res = VG_(do_syscall4)( __NR_clone, (UWord) NULL, flags,
    466                           (UWord)parent_tidptr, (UWord)child_tidptr);
    467 #else
    468 # error Unknown platform
    469 #endif
    470 
    471    if (!sr_isError(res) && sr_Res(res) == 0) {
    472       /* child */
    473       VG_(do_atfork_child)(tid);
    474 
    475       /* restore signal mask */
    476       VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
    477 
    478       /* If --child-silent-after-fork=yes was specified, set the
    479          output file descriptors to 'impossible' values.  This is
    480          noticed by send_bytes_to_logging_sink in m_libcprint.c, which
    481          duly stops writing any further output. */
    482       if (VG_(clo_child_silent_after_fork)) {
    483          if (!VG_(log_output_sink).is_socket)
    484             VG_(log_output_sink).fd = -1;
    485          if (!VG_(xml_output_sink).is_socket)
    486             VG_(xml_output_sink).fd = -1;
    487       }
    488    }
    489    else
    490    if (!sr_isError(res) && sr_Res(res) > 0) {
    491       /* parent */
    492       VG_(do_atfork_parent)(tid);
    493 
    494       if (VG_(clo_trace_syscalls))
    495 	  VG_(printf)("   clone(fork): process %d created child %lu\n",
    496                       VG_(getpid)(), sr_Res(res));
    497 
    498       /* restore signal mask */
    499       VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL);
    500    }
    501 
    502    return res;
    503 }
    504 
    505 
    506 /* ---------------------------------------------------------------------
    507    PRE/POST wrappers for arch-generic, Linux-specific syscalls
    508    ------------------------------------------------------------------ */
    509 
    510 // Nb: See the comment above the generic PRE/POST wrappers in
    511 // m_syswrap/syswrap-generic.c for notes about how they work.
    512 
    513 #define PRE(name)       DEFN_PRE_TEMPLATE(linux, name)
    514 #define POST(name)      DEFN_POST_TEMPLATE(linux, name)
    515 
    516 // Macros to support 64-bit syscall args split into two 32 bit values
    517 #define LOHI64(lo,hi)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
    518 #if defined(VG_LITTLEENDIAN)
    519 #define MERGE64(lo,hi)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
    520 #define MERGE64_FIRST(name) name##_low
    521 #define MERGE64_SECOND(name) name##_high
    522 #elif defined(VG_BIGENDIAN)
    523 #define MERGE64(hi,lo)   ( ((ULong)(lo)) | (((ULong)(hi)) << 32) )
    524 #define MERGE64_FIRST(name) name##_high
    525 #define MERGE64_SECOND(name) name##_low
    526 #else
    527 #error Unknown endianness
    528 #endif
    529 
    530 /* ---------------------------------------------------------------------
    531    *mount wrappers
    532    ------------------------------------------------------------------ */
    533 
    534 PRE(sys_mount)
    535 {
    536    // Nb: depending on 'flags', the 'type' and 'data' args may be ignored.
    537    // We are conservative and check everything, except the memory pointed to
    538    // by 'data'.
    539    *flags |= SfMayBlock;
    540    PRINT("sys_mount( %#lx(%s), %#lx(%s), %#lx(%s), %#lx, %#lx )",
    541          ARG1,(HChar*)ARG1, ARG2,(HChar*)ARG2, ARG3,(HChar*)ARG3, ARG4, ARG5);
    542    PRE_REG_READ5(long, "mount",
    543                  char *, source, char *, target, char *, type,
    544                  unsigned long, flags, void *, data);
    545    if (ARG1)
    546       PRE_MEM_RASCIIZ( "mount(source)", ARG1);
    547    PRE_MEM_RASCIIZ( "mount(target)", ARG2);
    548    PRE_MEM_RASCIIZ( "mount(type)", ARG3);
    549 }
    550 
    551 PRE(sys_oldumount)
    552 {
    553    PRINT("sys_oldumount( %#lx )", ARG1);
    554    PRE_REG_READ1(long, "umount", char *, path);
    555    PRE_MEM_RASCIIZ( "umount(path)", ARG1);
    556 }
    557 
    558 PRE(sys_umount)
    559 {
    560    PRINT("sys_umount( %#lx, %ld )", ARG1, SARG2);
    561    PRE_REG_READ2(long, "umount2", char *, path, int, flags);
    562    PRE_MEM_RASCIIZ( "umount2(path)", ARG1);
    563 }
    564 
    565 /* Not actually wrapped by GLibc but does things with the system
    566  * mounts so it is put here.
    567  */
    568 PRE(sys_pivot_root)
    569 {
    570    PRINT("sys_pivot_root ( %s %s )", (HChar*)ARG1, (HChar*)ARG2);
    571    PRE_REG_READ2(int, "pivot_root", char *, new_root, char *, old_root);
    572    PRE_MEM_RASCIIZ( "pivot_root(new_root)", ARG1);
    573    PRE_MEM_RASCIIZ( "pivot_root(old_root)", ARG2);
    574 }
    575 
    576 
    577 /* ---------------------------------------------------------------------
    578    16- and 32-bit uid/gid wrappers
    579    ------------------------------------------------------------------ */
    580 
    581 PRE(sys_setfsuid16)
    582 {
    583    PRINT("sys_setfsuid16 ( %lu )", ARG1);
    584    PRE_REG_READ1(long, "setfsuid16", vki_old_uid_t, uid);
    585 }
    586 
    587 PRE(sys_setfsuid)
    588 {
    589    PRINT("sys_setfsuid ( %lu )", ARG1);
    590    PRE_REG_READ1(long, "setfsuid", vki_uid_t, uid);
    591 }
    592 
    593 PRE(sys_setfsgid16)
    594 {
    595    PRINT("sys_setfsgid16 ( %lu )", ARG1);
    596    PRE_REG_READ1(long, "setfsgid16", vki_old_gid_t, gid);
    597 }
    598 
    599 PRE(sys_setfsgid)
    600 {
    601    PRINT("sys_setfsgid ( %lu )", ARG1);
    602    PRE_REG_READ1(long, "setfsgid", vki_gid_t, gid);
    603 }
    604 
    605 PRE(sys_setresuid16)
    606 {
    607    PRINT("sys_setresuid16 ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
    608    PRE_REG_READ3(long, "setresuid16",
    609                  vki_old_uid_t, ruid, vki_old_uid_t, euid, vki_old_uid_t, suid);
    610 }
    611 
    612 PRE(sys_setresuid)
    613 {
    614    PRINT("sys_setresuid ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
    615    PRE_REG_READ3(long, "setresuid",
    616                  vki_uid_t, ruid, vki_uid_t, euid, vki_uid_t, suid);
    617 }
    618 
    619 PRE(sys_getresuid16)
    620 {
    621    PRINT("sys_getresuid16 ( %#lx, %#lx, %#lx )", ARG1,ARG2,ARG3);
    622    PRE_REG_READ3(long, "getresuid16",
    623                  vki_old_uid_t *, ruid, vki_old_uid_t *, euid,
    624                  vki_old_uid_t *, suid);
    625    PRE_MEM_WRITE( "getresuid16(ruid)", ARG1, sizeof(vki_old_uid_t) );
    626    PRE_MEM_WRITE( "getresuid16(euid)", ARG2, sizeof(vki_old_uid_t) );
    627    PRE_MEM_WRITE( "getresuid16(suid)", ARG3, sizeof(vki_old_uid_t) );
    628 }
    629 POST(sys_getresuid16)
    630 {
    631    vg_assert(SUCCESS);
    632    if (RES == 0) {
    633       POST_MEM_WRITE( ARG1, sizeof(vki_old_uid_t) );
    634       POST_MEM_WRITE( ARG2, sizeof(vki_old_uid_t) );
    635       POST_MEM_WRITE( ARG3, sizeof(vki_old_uid_t) );
    636    }
    637 }
    638 
    639 PRE(sys_getresuid)
    640 {
    641    PRINT("sys_getresuid ( %#lx, %#lx, %#lx )", ARG1,ARG2,ARG3);
    642    PRE_REG_READ3(long, "getresuid",
    643                  vki_uid_t *, ruid, vki_uid_t *, euid, vki_uid_t *, suid);
    644    PRE_MEM_WRITE( "getresuid(ruid)", ARG1, sizeof(vki_uid_t) );
    645    PRE_MEM_WRITE( "getresuid(euid)", ARG2, sizeof(vki_uid_t) );
    646    PRE_MEM_WRITE( "getresuid(suid)", ARG3, sizeof(vki_uid_t) );
    647 }
    648 POST(sys_getresuid)
    649 {
    650    vg_assert(SUCCESS);
    651    if (RES == 0) {
    652       POST_MEM_WRITE( ARG1, sizeof(vki_uid_t) );
    653       POST_MEM_WRITE( ARG2, sizeof(vki_uid_t) );
    654       POST_MEM_WRITE( ARG3, sizeof(vki_uid_t) );
    655    }
    656 }
    657 
    658 PRE(sys_setresgid16)
    659 {
    660    PRINT("sys_setresgid16 ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
    661    PRE_REG_READ3(long, "setresgid16",
    662                  vki_old_gid_t, rgid,
    663                  vki_old_gid_t, egid, vki_old_gid_t, sgid);
    664 }
    665 
    666 PRE(sys_setresgid)
    667 {
    668    PRINT("sys_setresgid ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
    669    PRE_REG_READ3(long, "setresgid",
    670                  vki_gid_t, rgid, vki_gid_t, egid, vki_gid_t, sgid);
    671 }
    672 
    673 PRE(sys_getresgid16)
    674 {
    675    PRINT("sys_getresgid16 ( %#lx, %#lx, %#lx )", ARG1,ARG2,ARG3);
    676    PRE_REG_READ3(long, "getresgid16",
    677                  vki_old_gid_t *, rgid, vki_old_gid_t *, egid,
    678                  vki_old_gid_t *, sgid);
    679    PRE_MEM_WRITE( "getresgid16(rgid)", ARG1, sizeof(vki_old_gid_t) );
    680    PRE_MEM_WRITE( "getresgid16(egid)", ARG2, sizeof(vki_old_gid_t) );
    681    PRE_MEM_WRITE( "getresgid16(sgid)", ARG3, sizeof(vki_old_gid_t) );
    682 }
    683 POST(sys_getresgid16)
    684 {
    685    vg_assert(SUCCESS);
    686    if (RES == 0) {
    687       POST_MEM_WRITE( ARG1, sizeof(vki_old_gid_t) );
    688       POST_MEM_WRITE( ARG2, sizeof(vki_old_gid_t) );
    689       POST_MEM_WRITE( ARG3, sizeof(vki_old_gid_t) );
    690    }
    691 }
    692 
    693 PRE(sys_getresgid)
    694 {
    695    PRINT("sys_getresgid ( %#lx, %#lx, %#lx )", ARG1,ARG2,ARG3);
    696    PRE_REG_READ3(long, "getresgid",
    697                  vki_gid_t *, rgid, vki_gid_t *, egid, vki_gid_t *, sgid);
    698    PRE_MEM_WRITE( "getresgid(rgid)", ARG1, sizeof(vki_gid_t) );
    699    PRE_MEM_WRITE( "getresgid(egid)", ARG2, sizeof(vki_gid_t) );
    700    PRE_MEM_WRITE( "getresgid(sgid)", ARG3, sizeof(vki_gid_t) );
    701 }
    702 POST(sys_getresgid)
    703 {
    704    vg_assert(SUCCESS);
    705    if (RES == 0) {
    706       POST_MEM_WRITE( ARG1, sizeof(vki_gid_t) );
    707       POST_MEM_WRITE( ARG2, sizeof(vki_gid_t) );
    708       POST_MEM_WRITE( ARG3, sizeof(vki_gid_t) );
    709    }
    710 }
    711 
    712 /* ---------------------------------------------------------------------
    713    miscellaneous wrappers
    714    ------------------------------------------------------------------ */
    715 
    716 PRE(sys_exit_group)
    717 {
    718    ThreadId     t;
    719    ThreadState* tst;
    720 
    721    PRINT("exit_group( %ld )", SARG1);
    722    PRE_REG_READ1(void, "exit_group", int, status);
    723 
    724    tst = VG_(get_ThreadState)(tid);
    725    /* A little complex; find all the threads with the same threadgroup
    726       as this one (including this one), and mark them to exit */
    727    /* It is unclear how one can get a threadgroup in this process which
    728       is not the threadgroup of the calling thread:
    729       The assignments to threadgroups are:
    730         = 0; /// scheduler.c os_state_clear
    731         = getpid(); /// scheduler.c in child after fork
    732         = getpid(); /// this file, in thread_wrapper
    733         = ptst->os_state.threadgroup; /// syswrap-*-linux.c,
    734                            copying the thread group of the thread doing clone
    735       So, the only case where the threadgroup might be different to the getpid
    736       value is in the child, just after fork. But then the fork syscall is
    737       still going on, the forked thread has had no chance yet to make this
    738       syscall. */
    739    for (t = 1; t < VG_N_THREADS; t++) {
    740       if ( /* not alive */
    741            VG_(threads)[t].status == VgTs_Empty
    742            ||
    743 	   /* not our group */
    744            VG_(threads)[t].os_state.threadgroup != tst->os_state.threadgroup
    745          )
    746          continue;
    747       /* Assign the exit code, VG_(nuke_all_threads_except) will assign
    748          the exitreason. */
    749       VG_(threads)[t].os_state.exitcode = ARG1;
    750    }
    751 
    752    /* Indicate in all other threads that the process is exiting.
    753       Then wait using VG_(reap_threads) for these threads to disappear.
    754 
    755       Can this give a deadlock if another thread is calling exit in parallel
    756       and would then wait for this thread to disappear ?
    757       The answer is no:
    758       Other threads are either blocked in a syscall or have yielded the CPU.
    759 
    760       A thread that has yielded the CPU is trying to get the big lock in
    761       VG_(scheduler). This thread will get the CPU thanks to the call
    762       to VG_(reap_threads). The scheduler will then check for signals,
    763       kill the process if this is a fatal signal, and otherwise prepare
    764       the thread for handling this signal. After this preparation, if
    765       the thread status is VG_(is_exiting), the scheduler exits the thread.
    766       So, a thread that has yielded the CPU does not have a chance to
    767       call exit => no deadlock for this thread.
    768 
    769       VG_(nuke_all_threads_except) will send the VG_SIGVGKILL signal
    770       to all threads blocked in a syscall.
    771       The syscall will be interrupted, and the control will go to the
    772       scheduler. The scheduler will then return, as the thread is in
    773       exiting state. */
    774 
    775    VG_(nuke_all_threads_except)( tid, VgSrc_ExitProcess );
    776    VG_(reap_threads)(tid);
    777    VG_(threads)[tid].exitreason = VgSrc_ExitThread;
    778    /* we do assign VgSrc_ExitThread and not VgSrc_ExitProcess, as this thread
    779       is the thread calling exit_group and so its registers must be considered
    780       as not reachable. See pub_tool_machine.h VG_(apply_to_GP_regs). */
    781 
    782    /* We have to claim the syscall already succeeded. */
    783    SET_STATUS_Success(0);
    784 }
    785 
    786 PRE(sys_llseek)
    787 {
    788    PRINT("sys_llseek ( %lu, 0x%lx, 0x%lx, %#lx, %lu )", ARG1,ARG2,ARG3,ARG4,ARG5);
    789    PRE_REG_READ5(long, "llseek",
    790                  unsigned int, fd, unsigned long, offset_high,
    791                  unsigned long, offset_low, vki_loff_t *, result,
    792                  unsigned int, whence);
    793    if (!ML_(fd_allowed)(ARG1, "llseek", tid, False))
    794       SET_STATUS_Failure( VKI_EBADF );
    795    else
    796       PRE_MEM_WRITE( "llseek(result)", ARG4, sizeof(vki_loff_t));
    797 }
    798 POST(sys_llseek)
    799 {
    800    vg_assert(SUCCESS);
    801    if (RES == 0)
    802       POST_MEM_WRITE( ARG4, sizeof(vki_loff_t) );
    803 }
    804 
    805 PRE(sys_adjtimex)
    806 {
    807    struct vki_timex *tx = (struct vki_timex *)ARG1;
    808    PRINT("sys_adjtimex ( %#lx )", ARG1);
    809    PRE_REG_READ1(long, "adjtimex", struct timex *, buf);
    810    PRE_MEM_READ( "adjtimex(timex->modes)", ARG1, sizeof(tx->modes));
    811 
    812 #define ADJX(bits,field) 				\
    813    if (tx->modes & (bits))                              \
    814       PRE_MEM_READ( "adjtimex(timex->"#field")",	\
    815 		    (Addr)&tx->field, sizeof(tx->field))
    816 
    817    if (tx->modes & VKI_ADJ_ADJTIME) {
    818       if (!(tx->modes & VKI_ADJ_OFFSET_READONLY))
    819          PRE_MEM_READ( "adjtimex(timex->offset)", (Addr)&tx->offset, sizeof(tx->offset));
    820    } else {
    821       ADJX(VKI_ADJ_OFFSET, offset);
    822       ADJX(VKI_ADJ_FREQUENCY, freq);
    823       ADJX(VKI_ADJ_MAXERROR, maxerror);
    824       ADJX(VKI_ADJ_ESTERROR, esterror);
    825       ADJX(VKI_ADJ_STATUS, status);
    826       ADJX(VKI_ADJ_TIMECONST|VKI_ADJ_TAI, constant);
    827       ADJX(VKI_ADJ_TICK, tick);
    828    }
    829 #undef ADJX
    830 
    831    PRE_MEM_WRITE( "adjtimex(timex)", ARG1, sizeof(struct vki_timex));
    832 }
    833 
    834 POST(sys_adjtimex)
    835 {
    836    POST_MEM_WRITE( ARG1, sizeof(struct vki_timex) );
    837 }
    838 
    839 PRE(sys_clock_adjtime)
    840 {
    841    struct vki_timex *tx = (struct vki_timex *)ARG2;
    842    PRINT("sys_clock_adjtime ( %ld, %#lx )", SARG1,ARG2);
    843    PRE_REG_READ2(long, "clock_adjtime", vki_clockid_t, id, struct timex *, buf);
    844    PRE_MEM_READ( "clock_adjtime(timex->modes)", ARG2, sizeof(tx->modes));
    845 
    846 #define ADJX(bits,field)                                \
    847    if (tx->modes & (bits))                              \
    848       PRE_MEM_READ( "clock_adjtime(timex->"#field")",   \
    849                     (Addr)&tx->field, sizeof(tx->field))
    850 
    851    if (tx->modes & VKI_ADJ_ADJTIME) {
    852       if (!(tx->modes & VKI_ADJ_OFFSET_READONLY))
    853          PRE_MEM_READ( "clock_adjtime(timex->offset)", (Addr)&tx->offset, sizeof(tx->offset));
    854    } else {
    855       ADJX(VKI_ADJ_OFFSET, offset);
    856       ADJX(VKI_ADJ_FREQUENCY, freq);
    857       ADJX(VKI_ADJ_MAXERROR, maxerror);
    858       ADJX(VKI_ADJ_ESTERROR, esterror);
    859       ADJX(VKI_ADJ_STATUS, status);
    860       ADJX(VKI_ADJ_TIMECONST|VKI_ADJ_TAI, constant);
    861       ADJX(VKI_ADJ_TICK, tick);
    862    }
    863 #undef ADJX
    864 
    865    PRE_MEM_WRITE( "adjtimex(timex)", ARG2, sizeof(struct vki_timex));
    866 }
    867 
    868 POST(sys_clock_adjtime)
    869 {
    870    POST_MEM_WRITE( ARG2, sizeof(struct vki_timex) );
    871 }
    872 
    873 PRE(sys_ioperm)
    874 {
    875    PRINT("sys_ioperm ( %lu, %lu, %ld )", ARG1, ARG2, SARG3 );
    876    PRE_REG_READ3(long, "ioperm",
    877                  unsigned long, from, unsigned long, num, int, turn_on);
    878 }
    879 
    880 PRE(sys_syslog)
    881 {
    882    *flags |= SfMayBlock;
    883    PRINT("sys_syslog (%ld, %#lx, %ld)", SARG1, ARG2, SARG3);
    884    PRE_REG_READ3(long, "syslog", int, type, char *, bufp, int, len);
    885    switch (ARG1) {
    886    // The kernel uses magic numbers here, rather than named constants,
    887    // therefore so do we.
    888    case 2: case 3: case 4:
    889       PRE_MEM_WRITE( "syslog(bufp)", ARG2, ARG3);
    890       break;
    891    default:
    892       break;
    893    }
    894 }
    895 POST(sys_syslog)
    896 {
    897    switch (ARG1) {
    898    case 2: case 3: case 4:
    899       POST_MEM_WRITE( ARG2, ARG3 );
    900       break;
    901    default:
    902       break;
    903    }
    904 }
    905 
    906 PRE(sys_vhangup)
    907 {
    908    PRINT("sys_vhangup ( )");
    909    PRE_REG_READ0(long, "vhangup");
    910 }
    911 
    912 PRE(sys_sysinfo)
    913 {
    914    PRINT("sys_sysinfo ( %#lx )",ARG1);
    915    PRE_REG_READ1(long, "sysinfo", struct sysinfo *, info);
    916    PRE_MEM_WRITE( "sysinfo(info)", ARG1, sizeof(struct vki_sysinfo) );
    917 }
    918 POST(sys_sysinfo)
    919 {
    920    POST_MEM_WRITE( ARG1, sizeof(struct vki_sysinfo) );
    921 }
    922 
    923 PRE(sys_personality)
    924 {
    925    PRINT("sys_personality ( %llu )", (ULong)ARG1);
    926    PRE_REG_READ1(long, "personality", vki_u_long, persona);
    927 }
    928 
    929 PRE(sys_sysctl)
    930 {
    931    struct __vki_sysctl_args *args;
    932    PRINT("sys_sysctl ( %#lx )", ARG1 );
    933    args = (struct __vki_sysctl_args *)ARG1;
    934    PRE_REG_READ1(long, "sysctl", struct __sysctl_args *, args);
    935    PRE_MEM_WRITE( "sysctl(args)", ARG1, sizeof(struct __vki_sysctl_args) );
    936    if (!VG_(am_is_valid_for_client)(ARG1, sizeof(struct __vki_sysctl_args),
    937                                           VKI_PROT_READ)) {
    938       SET_STATUS_Failure( VKI_EFAULT );
    939       return;
    940    }
    941 
    942    PRE_MEM_READ("sysctl(name)", (Addr)args->name, args->nlen * sizeof(*args->name));
    943    if (args->newval != NULL)
    944       PRE_MEM_READ("sysctl(newval)", (Addr)args->newval, args->newlen);
    945    if (args->oldlenp != NULL) {
    946       PRE_MEM_READ("sysctl(oldlenp)", (Addr)args->oldlenp, sizeof(*args->oldlenp));
    947       PRE_MEM_WRITE("sysctl(oldval)", (Addr)args->oldval, *args->oldlenp);
    948    }
    949 }
    950 POST(sys_sysctl)
    951 {
    952    struct __vki_sysctl_args *args;
    953    args = (struct __vki_sysctl_args *)ARG1;
    954    if (args->oldlenp != NULL) {
    955       POST_MEM_WRITE((Addr)args->oldlenp, sizeof(*args->oldlenp));
    956       POST_MEM_WRITE((Addr)args->oldval, 1 + *args->oldlenp);
    957    }
    958 }
    959 
    960 PRE(sys_prctl)
    961 {
    962    *flags |= SfMayBlock;
    963    PRINT( "sys_prctl ( %ld, %ld, %ld, %ld, %ld )", SARG1, SARG2, SARG3, SARG4, SARG5 );
    964    switch (ARG1) {
    965    case VKI_PR_SET_PDEATHSIG:
    966       PRE_REG_READ2(int, "prctl", int, option, int, signal);
    967       break;
    968    case VKI_PR_GET_PDEATHSIG:
    969       PRE_REG_READ2(int, "prctl", int, option, int *, signal);
    970       PRE_MEM_WRITE("prctl(get-death-signal)", ARG2, sizeof(Int));
    971       break;
    972    case VKI_PR_GET_DUMPABLE:
    973       PRE_REG_READ1(int, "prctl", int, option);
    974       break;
    975    case VKI_PR_SET_DUMPABLE:
    976       PRE_REG_READ2(int, "prctl", int, option, int, dump);
    977       break;
    978    case VKI_PR_GET_UNALIGN:
    979       PRE_REG_READ2(int, "prctl", int, option, int *, value);
    980       PRE_MEM_WRITE("prctl(get-unalign)", ARG2, sizeof(Int));
    981       break;
    982    case VKI_PR_SET_UNALIGN:
    983       PRE_REG_READ2(int, "prctl", int, option, int, value);
    984       break;
    985    case VKI_PR_GET_KEEPCAPS:
    986       PRE_REG_READ1(int, "prctl", int, option);
    987       break;
    988    case VKI_PR_SET_KEEPCAPS:
    989       PRE_REG_READ2(int, "prctl", int, option, int, keepcaps);
    990       break;
    991    case VKI_PR_GET_FPEMU:
    992       PRE_REG_READ2(int, "prctl", int, option, int *, value);
    993       PRE_MEM_WRITE("prctl(get-fpemu)", ARG2, sizeof(Int));
    994       break;
    995    case VKI_PR_SET_FPEMU:
    996       PRE_REG_READ2(int, "prctl", int, option, int, value);
    997       break;
    998    case VKI_PR_GET_FPEXC:
    999       PRE_REG_READ2(int, "prctl", int, option, int *, value);
   1000       PRE_MEM_WRITE("prctl(get-fpexc)", ARG2, sizeof(Int));
   1001       break;
   1002    case VKI_PR_SET_FPEXC:
   1003       PRE_REG_READ2(int, "prctl", int, option, int, value);
   1004       break;
   1005    case VKI_PR_GET_TIMING:
   1006       PRE_REG_READ1(int, "prctl", int, option);
   1007       break;
   1008    case VKI_PR_SET_TIMING:
   1009       PRE_REG_READ2(int, "prctl", int, option, int, timing);
   1010       break;
   1011    case VKI_PR_SET_NAME:
   1012       PRE_REG_READ2(int, "prctl", int, option, char *, name);
   1013       PRE_MEM_RASCIIZ("prctl(set-name)", ARG2);
   1014       break;
   1015    case VKI_PR_GET_NAME:
   1016       PRE_REG_READ2(int, "prctl", int, option, char *, name);
   1017       PRE_MEM_WRITE("prctl(get-name)", ARG2, VKI_TASK_COMM_LEN);
   1018       break;
   1019    case VKI_PR_GET_ENDIAN:
   1020       PRE_REG_READ2(int, "prctl", int, option, int *, value);
   1021       PRE_MEM_WRITE("prctl(get-endian)", ARG2, sizeof(Int));
   1022       break;
   1023    case VKI_PR_SET_ENDIAN:
   1024       PRE_REG_READ2(int, "prctl", int, option, int, value);
   1025       break;
   1026    case VKI_PR_SET_PTRACER:
   1027       PRE_REG_READ2(int, "prctl", int, option, int, ptracer_process_ID);
   1028       break;
   1029    case VKI_PR_SET_SECCOMP:
   1030       /* This is a bit feeble in that it uses |option| before checking
   1031          it, but at least both sides of the conditional check it. */
   1032       if (ARG2 == VKI_SECCOMP_MODE_FILTER) {
   1033          PRE_REG_READ3(int, "prctl", int, option, int, mode, char*, filter);
   1034          if (ARG3) {
   1035             /* Should check that ARG3 points at a valid struct sock_fprog.
   1036                Sounds complex; hence be lame. */
   1037             PRE_MEM_READ( "prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, filter)",
   1038                           ARG3, 1 );
   1039          }
   1040       } else {
   1041          PRE_REG_READ2(int, "prctl", int, option, int, mode);
   1042       }
   1043       break;
   1044    default:
   1045       PRE_REG_READ5(long, "prctl",
   1046                     int, option, unsigned long, arg2, unsigned long, arg3,
   1047                     unsigned long, arg4, unsigned long, arg5);
   1048       break;
   1049    }
   1050 }
   1051 POST(sys_prctl)
   1052 {
   1053    switch (ARG1) {
   1054    case VKI_PR_GET_PDEATHSIG:
   1055       POST_MEM_WRITE(ARG2, sizeof(Int));
   1056       break;
   1057    case VKI_PR_GET_UNALIGN:
   1058       POST_MEM_WRITE(ARG2, sizeof(Int));
   1059       break;
   1060    case VKI_PR_GET_FPEMU:
   1061       POST_MEM_WRITE(ARG2, sizeof(Int));
   1062       break;
   1063    case VKI_PR_GET_FPEXC:
   1064       POST_MEM_WRITE(ARG2, sizeof(Int));
   1065       break;
   1066    case VKI_PR_GET_NAME:
   1067       POST_MEM_WRITE(ARG2, VKI_TASK_COMM_LEN);
   1068       break;
   1069    case VKI_PR_GET_ENDIAN:
   1070       POST_MEM_WRITE(ARG2, sizeof(Int));
   1071       break;
   1072    case VKI_PR_SET_NAME:
   1073       {
   1074          const HChar* new_name = (const HChar*) ARG2;
   1075          if (new_name) {    // Paranoia
   1076             ThreadState* tst = VG_(get_ThreadState)(tid);
   1077             SizeT new_len = VG_(strlen)(new_name);
   1078 
   1079             /* Don't bother reusing the memory. This is a rare event. */
   1080             tst->thread_name =
   1081               VG_(realloc)("syswrap.prctl", tst->thread_name, new_len + 1);
   1082             VG_(strcpy)(tst->thread_name, new_name);
   1083          }
   1084       }
   1085       break;
   1086    }
   1087 }
   1088 
   1089 PRE(sys_sendfile)
   1090 {
   1091    *flags |= SfMayBlock;
   1092    PRINT("sys_sendfile ( %ld, %ld, %#lx, %lu )", SARG1,SARG2,ARG3,ARG4);
   1093    PRE_REG_READ4(ssize_t, "sendfile",
   1094                  int, out_fd, int, in_fd, vki_off_t *, offset,
   1095                  vki_size_t, count);
   1096    if (ARG3 != 0)
   1097       PRE_MEM_WRITE( "sendfile(offset)", ARG3, sizeof(vki_off_t) );
   1098 }
   1099 POST(sys_sendfile)
   1100 {
   1101    if (ARG3 != 0 ) {
   1102       POST_MEM_WRITE( ARG3, sizeof( vki_off_t ) );
   1103    }
   1104 }
   1105 
   1106 PRE(sys_sendfile64)
   1107 {
   1108    *flags |= SfMayBlock;
   1109    PRINT("sendfile64 ( %ld, %ld, %#lx, %lu )",SARG1,SARG2,ARG3,ARG4);
   1110    PRE_REG_READ4(ssize_t, "sendfile64",
   1111                  int, out_fd, int, in_fd, vki_loff_t *, offset,
   1112                  vki_size_t, count);
   1113    if (ARG3 != 0)
   1114       PRE_MEM_WRITE( "sendfile64(offset)", ARG3, sizeof(vki_loff_t) );
   1115 }
   1116 POST(sys_sendfile64)
   1117 {
   1118    if (ARG3 != 0 ) {
   1119       POST_MEM_WRITE( ARG3, sizeof(vki_loff_t) );
   1120    }
   1121 }
   1122 
   1123 PRE(sys_futex)
   1124 {
   1125    /*
   1126       arg    param                              used by ops
   1127 
   1128       ARG1 - u32 *futex				all
   1129       ARG2 - int op
   1130       ARG3 - int val				WAIT,WAKE,FD,REQUEUE,CMP_REQUEUE
   1131       ARG4 - struct timespec *utime		WAIT:time*	REQUEUE,CMP_REQUEUE:val2
   1132       ARG5 - u32 *uaddr2			REQUEUE,CMP_REQUEUE
   1133       ARG6 - int val3				CMP_REQUEUE
   1134     */
   1135    PRINT("sys_futex ( %#lx, %ld, %ld, %#lx, %#lx )", ARG1,SARG2,SARG3,ARG4,ARG5);
   1136    switch(ARG2 & ~(VKI_FUTEX_PRIVATE_FLAG|VKI_FUTEX_CLOCK_REALTIME)) {
   1137    case VKI_FUTEX_CMP_REQUEUE:
   1138    case VKI_FUTEX_WAKE_OP:
   1139    case VKI_FUTEX_CMP_REQUEUE_PI:
   1140       PRE_REG_READ6(long, "futex",
   1141                     vki_u32 *, futex, int, op, int, val,
   1142                     struct timespec *, utime, vki_u32 *, uaddr2, int, val3);
   1143       break;
   1144    case VKI_FUTEX_REQUEUE:
   1145    case VKI_FUTEX_WAIT_REQUEUE_PI:
   1146       PRE_REG_READ5(long, "futex",
   1147                     vki_u32 *, futex, int, op, int, val,
   1148                     struct timespec *, utime, vki_u32 *, uaddr2);
   1149       break;
   1150    case VKI_FUTEX_WAIT_BITSET:
   1151       /* Check that the address at least begins in client-accessible area. */
   1152       if (!VG_(am_is_valid_for_client)( ARG1, 1, VKI_PROT_READ )) {
   1153             SET_STATUS_Failure( VKI_EFAULT );
   1154             return;
   1155       }
   1156       if (*(vki_u32 *)ARG1 != ARG3) {
   1157          PRE_REG_READ5(long, "futex",
   1158                        vki_u32 *, futex, int, op, int, val,
   1159                        struct timespec *, utime, int, dummy);
   1160       } else {
   1161          PRE_REG_READ6(long, "futex",
   1162                        vki_u32 *, futex, int, op, int, val,
   1163                        struct timespec *, utime, int, dummy, int, val3);
   1164       }
   1165       break;
   1166    case VKI_FUTEX_WAKE_BITSET:
   1167       PRE_REG_READ6(long, "futex",
   1168                     vki_u32 *, futex, int, op, int, val,
   1169                     int, dummy, int, dummy2, int, val3);
   1170       break;
   1171    case VKI_FUTEX_WAIT:
   1172    case VKI_FUTEX_LOCK_PI:
   1173       PRE_REG_READ4(long, "futex",
   1174                     vki_u32 *, futex, int, op, int, val,
   1175                     struct timespec *, utime);
   1176       break;
   1177    case VKI_FUTEX_WAKE:
   1178    case VKI_FUTEX_FD:
   1179    case VKI_FUTEX_TRYLOCK_PI:
   1180       PRE_REG_READ3(long, "futex",
   1181                     vki_u32 *, futex, int, op, int, val);
   1182       break;
   1183    case VKI_FUTEX_UNLOCK_PI:
   1184    default:
   1185       PRE_REG_READ2(long, "futex", vki_u32 *, futex, int, op);
   1186       break;
   1187    }
   1188 
   1189    *flags |= SfMayBlock;
   1190 
   1191    switch(ARG2 & ~(VKI_FUTEX_PRIVATE_FLAG|VKI_FUTEX_CLOCK_REALTIME)) {
   1192    case VKI_FUTEX_WAIT:
   1193    case VKI_FUTEX_LOCK_PI:
   1194    case VKI_FUTEX_WAIT_BITSET:
   1195    case VKI_FUTEX_WAIT_REQUEUE_PI:
   1196       PRE_MEM_READ( "futex(futex)", ARG1, sizeof(Int) );
   1197       if (ARG4 != 0)
   1198 	 PRE_MEM_READ( "futex(timeout)", ARG4, sizeof(struct vki_timespec) );
   1199       break;
   1200 
   1201    case VKI_FUTEX_REQUEUE:
   1202    case VKI_FUTEX_CMP_REQUEUE:
   1203    case VKI_FUTEX_CMP_REQUEUE_PI:
   1204    case VKI_FUTEX_WAKE_OP:
   1205       PRE_MEM_READ( "futex(futex)", ARG1, sizeof(Int) );
   1206       PRE_MEM_READ( "futex(futex2)", ARG5, sizeof(Int) );
   1207       break;
   1208 
   1209    case VKI_FUTEX_FD:
   1210    case VKI_FUTEX_TRYLOCK_PI:
   1211    case VKI_FUTEX_UNLOCK_PI:
   1212       PRE_MEM_READ( "futex(futex)", ARG1, sizeof(Int) );
   1213      break;
   1214 
   1215    case VKI_FUTEX_WAKE:
   1216    case VKI_FUTEX_WAKE_BITSET:
   1217       /* no additional pointers */
   1218       break;
   1219 
   1220    default:
   1221       SET_STATUS_Failure( VKI_ENOSYS );   // some futex function we don't understand
   1222       break;
   1223    }
   1224 }
   1225 POST(sys_futex)
   1226 {
   1227    vg_assert(SUCCESS);
   1228    POST_MEM_WRITE( ARG1, sizeof(int) );
   1229    if (ARG2 == VKI_FUTEX_FD) {
   1230       if (!ML_(fd_allowed)(RES, "futex", tid, True)) {
   1231          VG_(close)(RES);
   1232          SET_STATUS_Failure( VKI_EMFILE );
   1233       } else {
   1234          if (VG_(clo_track_fds))
   1235             ML_(record_fd_open_nameless)(tid, RES);
   1236       }
   1237    }
   1238 }
   1239 
   1240 PRE(sys_set_robust_list)
   1241 {
   1242    PRINT("sys_set_robust_list ( %#lx, %lu )", ARG1,ARG2);
   1243    PRE_REG_READ2(long, "set_robust_list",
   1244                  struct vki_robust_list_head *, head, vki_size_t, len);
   1245 
   1246    /* Just check the robust_list_head structure is readable - don't
   1247       try and chase the list as the kernel will only read it when
   1248       the thread exits so the current contents is irrelevant. */
   1249    if (ARG1 != 0)
   1250       PRE_MEM_READ("set_robust_list(head)", ARG1, ARG2);
   1251 }
   1252 
   1253 PRE(sys_get_robust_list)
   1254 {
   1255    PRINT("sys_get_robust_list ( %ld, %#lx, %#lx )", SARG1,ARG2,ARG3);
   1256    PRE_REG_READ3(long, "get_robust_list",
   1257                  int, pid,
   1258                  struct vki_robust_list_head **, head_ptr,
   1259                  vki_size_t *, len_ptr);
   1260    PRE_MEM_WRITE("get_robust_list(head_ptr)",
   1261                  ARG2, sizeof(struct vki_robust_list_head *));
   1262    PRE_MEM_WRITE("get_robust_list(len_ptr)",
   1263                  ARG3, sizeof(struct vki_size_t *));
   1264 }
   1265 POST(sys_get_robust_list)
   1266 {
   1267    POST_MEM_WRITE(ARG2, sizeof(struct vki_robust_list_head *));
   1268    POST_MEM_WRITE(ARG3, sizeof(struct vki_size_t *));
   1269 }
   1270 
   1271 PRE(sys_pselect6)
   1272 {
   1273    *flags |= SfMayBlock;
   1274    PRINT("sys_pselect6 ( %ld, %#lx, %#lx, %#lx, %#lx, %#lx )",
   1275          SARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
   1276    PRE_REG_READ6(long, "pselect6",
   1277                  int, n, vki_fd_set *, readfds, vki_fd_set *, writefds,
   1278                  vki_fd_set *, exceptfds, struct vki_timeval *, timeout,
   1279                  void *, sig);
   1280    // XXX: this possibly understates how much memory is read.
   1281    if (ARG2 != 0)
   1282       PRE_MEM_READ( "pselect6(readfds)",
   1283 		     ARG2, ARG1/8 /* __FD_SETSIZE/8 */ );
   1284    if (ARG3 != 0)
   1285       PRE_MEM_READ( "pselect6(writefds)",
   1286 		     ARG3, ARG1/8 /* __FD_SETSIZE/8 */ );
   1287    if (ARG4 != 0)
   1288       PRE_MEM_READ( "pselect6(exceptfds)",
   1289 		     ARG4, ARG1/8 /* __FD_SETSIZE/8 */ );
   1290    if (ARG5 != 0)
   1291       PRE_MEM_READ( "pselect6(timeout)", ARG5, sizeof(struct vki_timeval) );
   1292    if (ARG6 != 0)
   1293       PRE_MEM_READ( "pselect6(sig)", ARG6, sizeof(void *)+sizeof(vki_size_t) );
   1294 }
   1295 
   1296 PRE(sys_ppoll)
   1297 {
   1298    UInt i;
   1299    struct vki_pollfd* ufds = (struct vki_pollfd *)ARG1;
   1300    *flags |= SfMayBlock;
   1301    PRINT("sys_ppoll ( %#lx, %lu, %#lx, %#lx, %lu )\n", ARG1,ARG2,ARG3,ARG4,ARG5);
   1302    PRE_REG_READ5(long, "ppoll",
   1303                  struct vki_pollfd *, ufds, unsigned int, nfds,
   1304                  struct vki_timespec *, tsp, vki_sigset_t *, sigmask,
   1305                  vki_size_t, sigsetsize);
   1306 
   1307    for (i = 0; i < ARG2; i++) {
   1308       PRE_MEM_READ( "ppoll(ufds.fd)",
   1309                     (Addr)(&ufds[i].fd), sizeof(ufds[i].fd) );
   1310       PRE_MEM_READ( "ppoll(ufds.events)",
   1311                     (Addr)(&ufds[i].events), sizeof(ufds[i].events) );
   1312       PRE_MEM_WRITE( "ppoll(ufds.revents)",
   1313                      (Addr)(&ufds[i].revents), sizeof(ufds[i].revents) );
   1314    }
   1315 
   1316    if (ARG3)
   1317       PRE_MEM_READ( "ppoll(tsp)", ARG3, sizeof(struct vki_timespec) );
   1318    if (ARG4)
   1319       PRE_MEM_READ( "ppoll(sigmask)", ARG4, sizeof(vki_sigset_t) );
   1320 }
   1321 
   1322 POST(sys_ppoll)
   1323 {
   1324    if (RES > 0) {
   1325       UInt i;
   1326       struct vki_pollfd* ufds = (struct vki_pollfd *)ARG1;
   1327       for (i = 0; i < ARG2; i++)
   1328 	 POST_MEM_WRITE( (Addr)(&ufds[i].revents), sizeof(ufds[i].revents) );
   1329    }
   1330 }
   1331 
   1332 
   1333 /* ---------------------------------------------------------------------
   1334    epoll_* wrappers
   1335    ------------------------------------------------------------------ */
   1336 
   1337 PRE(sys_epoll_create)
   1338 {
   1339    PRINT("sys_epoll_create ( %ld )", SARG1);
   1340    PRE_REG_READ1(long, "epoll_create", int, size);
   1341 }
   1342 POST(sys_epoll_create)
   1343 {
   1344    vg_assert(SUCCESS);
   1345    if (!ML_(fd_allowed)(RES, "epoll_create", tid, True)) {
   1346       VG_(close)(RES);
   1347       SET_STATUS_Failure( VKI_EMFILE );
   1348    } else {
   1349       if (VG_(clo_track_fds))
   1350          ML_(record_fd_open_nameless) (tid, RES);
   1351    }
   1352 }
   1353 
   1354 PRE(sys_epoll_create1)
   1355 {
   1356    PRINT("sys_epoll_create1 ( %ld )", SARG1);
   1357    PRE_REG_READ1(long, "epoll_create1", int, flags);
   1358 }
   1359 POST(sys_epoll_create1)
   1360 {
   1361    vg_assert(SUCCESS);
   1362    if (!ML_(fd_allowed)(RES, "epoll_create1", tid, True)) {
   1363       VG_(close)(RES);
   1364       SET_STATUS_Failure( VKI_EMFILE );
   1365    } else {
   1366       if (VG_(clo_track_fds))
   1367          ML_(record_fd_open_nameless) (tid, RES);
   1368    }
   1369 }
   1370 
   1371 PRE(sys_epoll_ctl)
   1372 {
   1373    static const HChar* epoll_ctl_s[3] = {
   1374       "EPOLL_CTL_ADD",
   1375       "EPOLL_CTL_DEL",
   1376       "EPOLL_CTL_MOD"
   1377    };
   1378    PRINT("sys_epoll_ctl ( %ld, %s, %ld, %#lx )",
   1379          SARG1, ( ARG2<3 ? epoll_ctl_s[ARG2] : "?" ), SARG3, ARG4);
   1380    PRE_REG_READ4(long, "epoll_ctl",
   1381                  int, epfd, int, op, int, fd, struct vki_epoll_event *, event);
   1382    if (ARG2 != VKI_EPOLL_CTL_DEL)
   1383       PRE_MEM_READ( "epoll_ctl(event)", ARG4, sizeof(struct vki_epoll_event) );
   1384 }
   1385 
   1386 PRE(sys_epoll_wait)
   1387 {
   1388    *flags |= SfMayBlock;
   1389    PRINT("sys_epoll_wait ( %ld, %#lx, %ld, %ld )", SARG1, ARG2, SARG3, SARG4);
   1390    PRE_REG_READ4(long, "epoll_wait",
   1391                  int, epfd, struct vki_epoll_event *, events,
   1392                  int, maxevents, int, timeout);
   1393    PRE_MEM_WRITE( "epoll_wait(events)", ARG2, sizeof(struct vki_epoll_event)*ARG3);
   1394 }
   1395 POST(sys_epoll_wait)
   1396 {
   1397    vg_assert(SUCCESS);
   1398    if (RES > 0)
   1399       POST_MEM_WRITE( ARG2, sizeof(struct vki_epoll_event)*RES ) ;
   1400 }
   1401 
   1402 PRE(sys_epoll_pwait)
   1403 {
   1404    *flags |= SfMayBlock;
   1405    PRINT("sys_epoll_pwait ( %ld, %#lx, %ld, %ld, %#lx, %lu )",
   1406          SARG1, ARG2, SARG3, SARG4, ARG5, ARG6);
   1407    PRE_REG_READ6(long, "epoll_pwait",
   1408                  int, epfd, struct vki_epoll_event *, events,
   1409                  int, maxevents, int, timeout, vki_sigset_t *, sigmask,
   1410                  vki_size_t, sigsetsize);
   1411    PRE_MEM_WRITE( "epoll_pwait(events)", ARG2, sizeof(struct vki_epoll_event)*ARG3);
   1412    if (ARG4)
   1413       PRE_MEM_READ( "epoll_pwait(sigmask)", ARG5, sizeof(vki_sigset_t) );
   1414 }
   1415 POST(sys_epoll_pwait)
   1416 {
   1417    vg_assert(SUCCESS);
   1418    if (RES > 0)
   1419       POST_MEM_WRITE( ARG2, sizeof(struct vki_epoll_event)*RES ) ;
   1420 }
   1421 
   1422 PRE(sys_eventfd)
   1423 {
   1424    PRINT("sys_eventfd ( %lu )", ARG1);
   1425    PRE_REG_READ1(long, "sys_eventfd", unsigned int, count);
   1426 }
   1427 POST(sys_eventfd)
   1428 {
   1429    if (!ML_(fd_allowed)(RES, "eventfd", tid, True)) {
   1430       VG_(close)(RES);
   1431       SET_STATUS_Failure( VKI_EMFILE );
   1432    } else {
   1433       if (VG_(clo_track_fds))
   1434          ML_(record_fd_open_nameless) (tid, RES);
   1435    }
   1436 }
   1437 
   1438 PRE(sys_eventfd2)
   1439 {
   1440    PRINT("sys_eventfd2 ( %lu, %ld )", ARG1, SARG2);
   1441    PRE_REG_READ2(long, "sys_eventfd2", unsigned int, count, int, flags);
   1442 }
   1443 POST(sys_eventfd2)
   1444 {
   1445    if (!ML_(fd_allowed)(RES, "eventfd2", tid, True)) {
   1446       VG_(close)(RES);
   1447       SET_STATUS_Failure( VKI_EMFILE );
   1448    } else {
   1449       if (VG_(clo_track_fds))
   1450          ML_(record_fd_open_nameless) (tid, RES);
   1451    }
   1452 }
   1453 
   1454 PRE(sys_fallocate)
   1455 {
   1456    *flags |= SfMayBlock;
   1457 #if VG_WORDSIZE == 4
   1458    PRINT("sys_fallocate ( %ld, %ld, %lld, %lld )",
   1459          SARG1, SARG2, (Long)MERGE64(ARG3,ARG4), (Long)MERGE64(ARG5,ARG6));
   1460    PRE_REG_READ6(long, "fallocate",
   1461                  int, fd, int, mode,
   1462                  unsigned, MERGE64_FIRST(offset), unsigned, MERGE64_SECOND(offset),
   1463                  unsigned, MERGE64_FIRST(len), unsigned, MERGE64_SECOND(len));
   1464 #elif VG_WORDSIZE == 8
   1465    PRINT("sys_fallocate ( %ld, %ld, %ld, %ld )",
   1466          SARG1, SARG2, SARG3, SARG4);
   1467    PRE_REG_READ4(long, "fallocate",
   1468                  int, fd, int, mode, vki_loff_t, offset, vki_loff_t, len);
   1469 #else
   1470 #  error Unexpected word size
   1471 #endif
   1472    if (!ML_(fd_allowed)(ARG1, "fallocate", tid, False))
   1473       SET_STATUS_Failure( VKI_EBADF );
   1474 }
   1475 
   1476 PRE(sys_prlimit64)
   1477 {
   1478    PRINT("sys_prlimit64 ( %ld, %lu, %#lx, %#lx )", SARG1,ARG2,ARG3,ARG4);
   1479    PRE_REG_READ4(long, "prlimit64",
   1480                  vki_pid_t, pid, unsigned int, resource,
   1481                  const struct rlimit64 *, new_rlim,
   1482                  struct rlimit64 *, old_rlim);
   1483    if (ARG3)
   1484       PRE_MEM_READ( "rlimit64(new_rlim)", ARG3, sizeof(struct vki_rlimit64) );
   1485    if (ARG4)
   1486       PRE_MEM_WRITE( "rlimit64(old_rlim)", ARG4, sizeof(struct vki_rlimit64) );
   1487 
   1488    if (ARG3 &&
   1489        ((struct vki_rlimit64 *)ARG3)->rlim_cur > ((struct vki_rlimit64 *)ARG3)->rlim_max) {
   1490       SET_STATUS_Failure( VKI_EINVAL );
   1491    }
   1492    else if (ARG1 == 0 || ARG1 == VG_(getpid)()) {
   1493       switch (ARG2) {
   1494       case VKI_RLIMIT_NOFILE:
   1495          SET_STATUS_Success( 0 );
   1496          if (ARG4) {
   1497             ((struct vki_rlimit64 *)ARG4)->rlim_cur = VG_(fd_soft_limit);
   1498             ((struct vki_rlimit64 *)ARG4)->rlim_max = VG_(fd_hard_limit);
   1499          }
   1500          if (ARG3) {
   1501             if (((struct vki_rlimit64 *)ARG3)->rlim_cur > VG_(fd_hard_limit) ||
   1502                 ((struct vki_rlimit64 *)ARG3)->rlim_max != VG_(fd_hard_limit)) {
   1503                SET_STATUS_Failure( VKI_EPERM );
   1504             }
   1505             else {
   1506                VG_(fd_soft_limit) = ((struct vki_rlimit64 *)ARG3)->rlim_cur;
   1507             }
   1508          }
   1509          break;
   1510 
   1511       case VKI_RLIMIT_DATA:
   1512          SET_STATUS_Success( 0 );
   1513          if (ARG4) {
   1514             ((struct vki_rlimit64 *)ARG4)->rlim_cur = VG_(client_rlimit_data).rlim_cur;
   1515             ((struct vki_rlimit64 *)ARG4)->rlim_max = VG_(client_rlimit_data).rlim_max;
   1516          }
   1517          if (ARG3) {
   1518             if (((struct vki_rlimit64 *)ARG3)->rlim_cur > VG_(client_rlimit_data).rlim_max ||
   1519                 ((struct vki_rlimit64 *)ARG3)->rlim_max > VG_(client_rlimit_data).rlim_max) {
   1520                SET_STATUS_Failure( VKI_EPERM );
   1521             }
   1522             else {
   1523                VG_(client_rlimit_data).rlim_cur = ((struct vki_rlimit64 *)ARG3)->rlim_cur;
   1524                VG_(client_rlimit_data).rlim_max = ((struct vki_rlimit64 *)ARG3)->rlim_max;
   1525             }
   1526          }
   1527          break;
   1528 
   1529       case VKI_RLIMIT_STACK:
   1530          SET_STATUS_Success( 0 );
   1531          if (ARG4) {
   1532             ((struct vki_rlimit64 *)ARG4)->rlim_cur = VG_(client_rlimit_stack).rlim_cur;
   1533             ((struct vki_rlimit64 *)ARG4)->rlim_max = VG_(client_rlimit_stack).rlim_max;
   1534          }
   1535          if (ARG3) {
   1536             if (((struct vki_rlimit64 *)ARG3)->rlim_cur > VG_(client_rlimit_stack).rlim_max ||
   1537                 ((struct vki_rlimit64 *)ARG3)->rlim_max > VG_(client_rlimit_stack).rlim_max) {
   1538                SET_STATUS_Failure( VKI_EPERM );
   1539             }
   1540             else {
   1541                VG_(threads)[tid].client_stack_szB = ((struct vki_rlimit64 *)ARG3)->rlim_cur;
   1542                VG_(client_rlimit_stack).rlim_cur = ((struct vki_rlimit64 *)ARG3)->rlim_cur;
   1543                VG_(client_rlimit_stack).rlim_max = ((struct vki_rlimit64 *)ARG3)->rlim_max;
   1544            }
   1545          }
   1546          break;
   1547       }
   1548    }
   1549 }
   1550 
   1551 POST(sys_prlimit64)
   1552 {
   1553    if (ARG4)
   1554       POST_MEM_WRITE( ARG4, sizeof(struct vki_rlimit64) );
   1555 }
   1556 
   1557 /* ---------------------------------------------------------------------
   1558    tid-related wrappers
   1559    ------------------------------------------------------------------ */
   1560 
   1561 PRE(sys_gettid)
   1562 {
   1563    PRINT("sys_gettid ()");
   1564    PRE_REG_READ0(long, "gettid");
   1565 }
   1566 
   1567 PRE(sys_set_tid_address)
   1568 {
   1569    PRINT("sys_set_tid_address ( %#lx )", ARG1);
   1570    PRE_REG_READ1(long, "set_tid_address", int *, tidptr);
   1571 }
   1572 
   1573 PRE(sys_tkill)
   1574 {
   1575    PRINT("sys_tgkill ( %ld, %ld )", SARG1, SARG2);
   1576    PRE_REG_READ2(long, "tkill", int, tid, int, sig);
   1577    if (!ML_(client_signal_OK)(ARG2)) {
   1578       SET_STATUS_Failure( VKI_EINVAL );
   1579       return;
   1580    }
   1581 
   1582    /* Check to see if this kill gave us a pending signal */
   1583    *flags |= SfPollAfter;
   1584 
   1585    if (VG_(clo_trace_signals))
   1586       VG_(message)(Vg_DebugMsg, "tkill: sending signal %ld to pid %ld\n",
   1587 		   SARG2, SARG1);
   1588 
   1589    /* If we're sending SIGKILL, check to see if the target is one of
   1590       our threads and handle it specially. */
   1591    if (ARG2 == VKI_SIGKILL && ML_(do_sigkill)(ARG1, -1)) {
   1592       SET_STATUS_Success(0);
   1593       return;
   1594    }
   1595 
   1596    /* Ask to handle this syscall via the slow route, since that's the
   1597       only one that sets tst->status to VgTs_WaitSys.  If the result
   1598       of doing the syscall is an immediate run of
   1599       async_signalhandler() in m_signals, then we need the thread to
   1600       be properly tidied away.  I have the impression the previous
   1601       version of this wrapper worked on x86/amd64 only because the
   1602       kernel did not immediately deliver the async signal to this
   1603       thread (on ppc it did, which broke the assertion re tst->status
   1604       at the top of async_signalhandler()). */
   1605    *flags |= SfMayBlock;
   1606 }
   1607 POST(sys_tkill)
   1608 {
   1609    if (VG_(clo_trace_signals))
   1610       VG_(message)(Vg_DebugMsg, "tkill: sent signal %ld to pid %ld\n",
   1611                    SARG2, SARG1);
   1612 }
   1613 
   1614 PRE(sys_tgkill)
   1615 {
   1616    PRINT("sys_tgkill ( %ld, %ld, %ld )", SARG1, SARG2, SARG3);
   1617    PRE_REG_READ3(long, "tgkill", int, tgid, int, tid, int, sig);
   1618    if (!ML_(client_signal_OK)(ARG3)) {
   1619       SET_STATUS_Failure( VKI_EINVAL );
   1620       return;
   1621    }
   1622 
   1623    /* Check to see if this kill gave us a pending signal */
   1624    *flags |= SfPollAfter;
   1625 
   1626    if (VG_(clo_trace_signals))
   1627       VG_(message)(Vg_DebugMsg,
   1628                    "tgkill: sending signal %ld to pid %ld/%ld\n",
   1629 		   SARG3, SARG1, SARG2);
   1630 
   1631    /* If we're sending SIGKILL, check to see if the target is one of
   1632       our threads and handle it specially. */
   1633    if (ARG3 == VKI_SIGKILL && ML_(do_sigkill)(ARG2, ARG1)) {
   1634       SET_STATUS_Success(0);
   1635       return;
   1636    }
   1637 
   1638    /* Ask to handle this syscall via the slow route, since that's the
   1639       only one that sets tst->status to VgTs_WaitSys.  If the result
   1640       of doing the syscall is an immediate run of
   1641       async_signalhandler() in m_signals, then we need the thread to
   1642       be properly tidied away.  I have the impression the previous
   1643       version of this wrapper worked on x86/amd64 only because the
   1644       kernel did not immediately deliver the async signal to this
   1645       thread (on ppc it did, which broke the assertion re tst->status
   1646       at the top of async_signalhandler()). */
   1647    *flags |= SfMayBlock;
   1648 }
   1649 POST(sys_tgkill)
   1650 {
   1651    if (VG_(clo_trace_signals))
   1652       VG_(message)(Vg_DebugMsg,
   1653                    "tgkill: sent signal %ld to pid %ld/%ld\n",
   1654                    SARG3, SARG1, SARG2);
   1655 }
   1656 
   1657 /* ---------------------------------------------------------------------
   1658    fadvise64* wrappers
   1659    ------------------------------------------------------------------ */
   1660 
   1661 PRE(sys_fadvise64)
   1662 {
   1663    PRINT("sys_fadvise64 ( %ld, %llu, %lu, %ld )",
   1664          SARG1, MERGE64(ARG2,ARG3), ARG4, SARG5);
   1665    PRE_REG_READ5(long, "fadvise64",
   1666                  int, fd, vki_u32, MERGE64_FIRST(offset), vki_u32, MERGE64_SECOND(offset),
   1667                  vki_size_t, len, int, advice);
   1668 }
   1669 
   1670 PRE(sys_fadvise64_64)
   1671 {
   1672    PRINT("sys_fadvise64_64 ( %ld, %llu, %llu, %ld )",
   1673          SARG1, MERGE64(ARG2,ARG3), MERGE64(ARG4,ARG5), SARG6);
   1674    PRE_REG_READ6(long, "fadvise64_64",
   1675                  int, fd, vki_u32, MERGE64_FIRST(offset), vki_u32, MERGE64_SECOND(offset),
   1676                  vki_u32, MERGE64_FIRST(len), vki_u32, MERGE64_SECOND(len), int, advice);
   1677 }
   1678 
   1679 /* ---------------------------------------------------------------------
   1680    io_* wrappers
   1681    ------------------------------------------------------------------ */
   1682 
   1683 // Nb: this wrapper has to pad/unpad memory around the syscall itself,
   1684 // and this allows us to control exactly the code that gets run while
   1685 // the padding is in place.
   1686 
   1687 PRE(sys_io_setup)
   1688 {
   1689    PRINT("sys_io_setup ( %lu, %#lx )", ARG1,ARG2);
   1690    PRE_REG_READ2(long, "io_setup",
   1691                  unsigned, nr_events, vki_aio_context_t *, ctxp);
   1692    PRE_MEM_WRITE( "io_setup(ctxp)", ARG2, sizeof(vki_aio_context_t) );
   1693 }
   1694 
   1695 POST(sys_io_setup)
   1696 {
   1697    SizeT size;
   1698    struct vki_aio_ring *r;
   1699 
   1700    size = VG_PGROUNDUP(sizeof(struct vki_aio_ring) +
   1701                        ARG1*sizeof(struct vki_io_event));
   1702    r = *(struct vki_aio_ring **)ARG2;
   1703    vg_assert(ML_(valid_client_addr)((Addr)r, size, tid, "io_setup"));
   1704 
   1705    ML_(notify_core_and_tool_of_mmap)( (Addr)r, size,
   1706                                       VKI_PROT_READ | VKI_PROT_WRITE,
   1707                                       VKI_MAP_ANONYMOUS, -1, 0 );
   1708 
   1709    POST_MEM_WRITE( ARG2, sizeof(vki_aio_context_t) );
   1710 }
   1711 
   1712 // Nb: This wrapper is "Special" because we need 'size' to do the unmap
   1713 // after the syscall.  We must get 'size' from the aio_ring structure,
   1714 // before the syscall, while the aio_ring structure still exists.  (And we
   1715 // know that we must look at the aio_ring structure because Tom inspected the
   1716 // kernel and glibc sources to see what they do, yuk.)
   1717 //
   1718 // XXX This segment can be implicitly unmapped when aio
   1719 // file-descriptors are closed...
   1720 PRE(sys_io_destroy)
   1721 {
   1722    SizeT size = 0;
   1723 
   1724    PRINT("sys_io_destroy ( %llu )", (ULong)ARG1);
   1725    PRE_REG_READ1(long, "io_destroy", vki_aio_context_t, ctx);
   1726 
   1727    // If we are going to seg fault (due to a bogus ARG1) do it as late as
   1728    // possible...
   1729    if (ML_(safe_to_deref)( (void*)ARG1, sizeof(struct vki_aio_ring))) {
   1730       struct vki_aio_ring *r = (struct vki_aio_ring *)ARG1;
   1731       size = VG_PGROUNDUP(sizeof(struct vki_aio_ring) +
   1732                           r->nr*sizeof(struct vki_io_event));
   1733    }
   1734 
   1735    SET_STATUS_from_SysRes( VG_(do_syscall1)(SYSNO, ARG1) );
   1736 
   1737    if (SUCCESS && RES == 0) {
   1738       Bool d = VG_(am_notify_munmap)( ARG1, size );
   1739       VG_TRACK( die_mem_munmap, ARG1, size );
   1740       if (d)
   1741         VG_(discard_translations)( (Addr)ARG1, (ULong)size,
   1742                                     "PRE(sys_io_destroy)" );
   1743    }
   1744 }
   1745 
   1746 PRE(sys_io_getevents)
   1747 {
   1748    *flags |= SfMayBlock;
   1749    PRINT("sys_io_getevents ( %llu, %lld, %lld, %#lx, %#lx )",
   1750          (ULong)ARG1,(Long)ARG2,(Long)ARG3,ARG4,ARG5);
   1751    PRE_REG_READ5(long, "io_getevents",
   1752                  vki_aio_context_t, ctx_id, long, min_nr, long, nr,
   1753                  struct io_event *, events,
   1754                  struct timespec *, timeout);
   1755    if (ARG3 > 0)
   1756       PRE_MEM_WRITE( "io_getevents(events)",
   1757                      ARG4, sizeof(struct vki_io_event)*ARG3 );
   1758    if (ARG5 != 0)
   1759       PRE_MEM_READ( "io_getevents(timeout)",
   1760                     ARG5, sizeof(struct vki_timespec));
   1761 }
   1762 POST(sys_io_getevents)
   1763 {
   1764    Int i;
   1765    vg_assert(SUCCESS);
   1766    if (RES > 0) {
   1767       POST_MEM_WRITE( ARG4, sizeof(struct vki_io_event)*RES );
   1768       for (i = 0; i < RES; i++) {
   1769          const struct vki_io_event *vev = ((struct vki_io_event *)ARG4) + i;
   1770          const struct vki_iocb *cb = (struct vki_iocb *)(Addr)vev->obj;
   1771 
   1772          switch (cb->aio_lio_opcode) {
   1773          case VKI_IOCB_CMD_PREAD:
   1774             if (vev->result > 0)
   1775                POST_MEM_WRITE( cb->aio_buf, vev->result );
   1776             break;
   1777 
   1778          case VKI_IOCB_CMD_PWRITE:
   1779             break;
   1780 
   1781          case VKI_IOCB_CMD_FSYNC:
   1782             break;
   1783 
   1784          case VKI_IOCB_CMD_FDSYNC:
   1785             break;
   1786 
   1787          case VKI_IOCB_CMD_PREADV:
   1788 	     if (vev->result > 0) {
   1789                   struct vki_iovec * vec = (struct vki_iovec *)(Addr)cb->aio_buf;
   1790                   Int remains = vev->result;
   1791                   Int j;
   1792 
   1793                   for (j = 0; j < cb->aio_nbytes; j++) {
   1794                        Int nReadThisBuf = vec[j].iov_len;
   1795                        if (nReadThisBuf > remains) nReadThisBuf = remains;
   1796                        POST_MEM_WRITE( (Addr)vec[j].iov_base, nReadThisBuf );
   1797                        remains -= nReadThisBuf;
   1798                        if (remains < 0) VG_(core_panic)("io_getevents(PREADV): remains < 0");
   1799                   }
   1800 	     }
   1801              break;
   1802 
   1803          case VKI_IOCB_CMD_PWRITEV:
   1804              break;
   1805 
   1806          default:
   1807             VG_(message)(Vg_DebugMsg,
   1808                         "Warning: unhandled io_getevents opcode: %u\n",
   1809                         cb->aio_lio_opcode);
   1810             break;
   1811          }
   1812       }
   1813    }
   1814 }
   1815 
   1816 PRE(sys_io_submit)
   1817 {
   1818    Int i, j;
   1819 
   1820    PRINT("sys_io_submit ( %lu, %ld, %#lx )", ARG1, SARG2, ARG3);
   1821    PRE_REG_READ3(long, "io_submit",
   1822                  vki_aio_context_t, ctx_id, long, nr,
   1823                  struct iocb **, iocbpp);
   1824    PRE_MEM_READ( "io_submit(iocbpp)", ARG3, ARG2*sizeof(struct vki_iocb *) );
   1825    if (ARG3 != 0) {
   1826       for (i = 0; i < ARG2; i++) {
   1827          struct vki_iocb *cb = ((struct vki_iocb **)ARG3)[i];
   1828          struct vki_iovec *iov;
   1829 
   1830          PRE_MEM_READ( "io_submit(iocb)", (Addr)cb, sizeof(struct vki_iocb) );
   1831          switch (cb->aio_lio_opcode) {
   1832          case VKI_IOCB_CMD_PREAD:
   1833             PRE_MEM_WRITE( "io_submit(PREAD)", cb->aio_buf, cb->aio_nbytes );
   1834             break;
   1835 
   1836          case VKI_IOCB_CMD_PWRITE:
   1837             PRE_MEM_READ( "io_submit(PWRITE)", cb->aio_buf, cb->aio_nbytes );
   1838             break;
   1839 
   1840          case VKI_IOCB_CMD_FSYNC:
   1841             break;
   1842 
   1843          case VKI_IOCB_CMD_FDSYNC:
   1844             break;
   1845 
   1846          case VKI_IOCB_CMD_PREADV:
   1847             iov = (struct vki_iovec *)(Addr)cb->aio_buf;
   1848             PRE_MEM_READ( "io_submit(PREADV)", cb->aio_buf, cb->aio_nbytes * sizeof(struct vki_iovec) );
   1849             for (j = 0; j < cb->aio_nbytes; j++)
   1850                 PRE_MEM_WRITE( "io_submit(PREADV(iov[i]))", (Addr)iov[j].iov_base, iov[j].iov_len );
   1851             break;
   1852 
   1853          case VKI_IOCB_CMD_PWRITEV:
   1854             iov = (struct vki_iovec *)(Addr)cb->aio_buf;
   1855             PRE_MEM_READ( "io_submit(PWRITEV)", cb->aio_buf, cb->aio_nbytes * sizeof(struct vki_iovec) );
   1856             for (j = 0; j < cb->aio_nbytes; j++)
   1857                 PRE_MEM_READ( "io_submit(PWRITEV(iov[i]))", (Addr)iov[j].iov_base, iov[j].iov_len );
   1858             break;
   1859 
   1860          default:
   1861             VG_(message)(Vg_DebugMsg,"Warning: unhandled io_submit opcode: %u\n",
   1862                          cb->aio_lio_opcode);
   1863             break;
   1864          }
   1865       }
   1866    }
   1867 }
   1868 
   1869 PRE(sys_io_cancel)
   1870 {
   1871    PRINT("sys_io_cancel ( %llu, %#lx, %#lx )", (ULong)ARG1,ARG2,ARG3);
   1872    PRE_REG_READ3(long, "io_cancel",
   1873                  vki_aio_context_t, ctx_id, struct iocb *, iocb,
   1874                  struct io_event *, result);
   1875    PRE_MEM_READ( "io_cancel(iocb)", ARG2, sizeof(struct vki_iocb) );
   1876    PRE_MEM_WRITE( "io_cancel(result)", ARG3, sizeof(struct vki_io_event) );
   1877 }
   1878 POST(sys_io_cancel)
   1879 {
   1880    POST_MEM_WRITE( ARG3, sizeof(struct vki_io_event) );
   1881 }
   1882 
   1883 /* ---------------------------------------------------------------------
   1884    *_mempolicy wrappers
   1885    ------------------------------------------------------------------ */
   1886 
   1887 PRE(sys_mbind)
   1888 {
   1889    PRINT("sys_mbind ( %#lx, %lu, %lu, %#lx, %lu, %lu )", ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
   1890    PRE_REG_READ6(long, "mbind",
   1891                  unsigned long, start, unsigned long, len,
   1892                  unsigned long, policy, unsigned long *, nodemask,
   1893                  unsigned long, maxnode, unsigned, flags);
   1894    if (ARG1 != 0)
   1895       PRE_MEM_READ( "mbind(nodemask)", ARG4,
   1896                     VG_ROUNDUP( ARG5-1, sizeof(UWord) * 8 ) / 8 );
   1897 }
   1898 
   1899 PRE(sys_set_mempolicy)
   1900 {
   1901    PRINT("sys_set_mempolicy ( %ld, %#lx, %lu )", SARG1, ARG2, ARG3);
   1902    PRE_REG_READ3(long, "set_mempolicy",
   1903                  int, policy, unsigned long *, nodemask,
   1904                  unsigned long, maxnode);
   1905    PRE_MEM_READ( "set_mempolicy(nodemask)", ARG2,
   1906                  VG_ROUNDUP( ARG3-1, sizeof(UWord) * 8 ) / 8 );
   1907 }
   1908 
   1909 PRE(sys_get_mempolicy)
   1910 {
   1911    PRINT("sys_get_mempolicy ( %#lx, %#lx, %lu, %#lx, %lx )", ARG1,ARG2,ARG3,ARG4,ARG5);
   1912    PRE_REG_READ5(long, "get_mempolicy",
   1913                  int *, policy, unsigned long *, nodemask,
   1914                  unsigned long, maxnode, unsigned long, addr,
   1915                  unsigned long, flags);
   1916    if (ARG1 != 0)
   1917       PRE_MEM_WRITE( "get_mempolicy(policy)", ARG1, sizeof(Int) );
   1918    if (ARG2 != 0)
   1919       PRE_MEM_WRITE( "get_mempolicy(nodemask)", ARG2,
   1920                      VG_ROUNDUP( ARG3-1, sizeof(UWord) * 8 ) / 8 );
   1921 }
   1922 POST(sys_get_mempolicy)
   1923 {
   1924    if (ARG1 != 0)
   1925       POST_MEM_WRITE( ARG1, sizeof(Int) );
   1926    if (ARG2 != 0)
   1927       POST_MEM_WRITE( ARG2, VG_ROUNDUP( ARG3-1, sizeof(UWord) * 8 ) / 8 );
   1928 }
   1929 
   1930 /* ---------------------------------------------------------------------
   1931    fanotify_* wrappers
   1932    ------------------------------------------------------------------ */
   1933 
   1934 PRE(sys_fanotify_init)
   1935 {
   1936    PRINT("sys_fanotify_init ( %lu, %lu )", ARG1,ARG2);
   1937    PRE_REG_READ2(long, "fanotify_init",
   1938                  unsigned int, flags, unsigned int, event_f_flags);
   1939 }
   1940 
   1941 POST(sys_fanotify_init)
   1942 {
   1943    vg_assert(SUCCESS);
   1944    if (!ML_(fd_allowed)(RES, "fanotify_init", tid, True)) {
   1945       VG_(close)(RES);
   1946       SET_STATUS_Failure( VKI_EMFILE );
   1947    } else {
   1948       if (VG_(clo_track_fds))
   1949          ML_(record_fd_open_nameless) (tid, RES);
   1950    }
   1951 }
   1952 
   1953 PRE(sys_fanotify_mark)
   1954 {
   1955 #if VG_WORDSIZE == 4
   1956    PRINT( "sys_fanotify_mark ( %ld, %lu, %llu, %ld, %#lx(%s))",
   1957           SARG1, ARG2, MERGE64(ARG3,ARG4), SARG5, ARG6, (HChar *)ARG6);
   1958    PRE_REG_READ6(long, "sys_fanotify_mark",
   1959                  int, fanotify_fd, unsigned int, flags,
   1960                  __vki_u32, mask0, __vki_u32, mask1,
   1961                  int, dfd, const char *, pathname);
   1962    if (ARG6)
   1963       PRE_MEM_RASCIIZ( "fanotify_mark(path)", ARG6);
   1964 #elif VG_WORDSIZE == 8
   1965    PRINT( "sys_fanotify_mark ( %ld, %lu, %lu, %ld, %#lx(%s))",
   1966           SARG1, ARG2, ARG3, SARG4, ARG5, (HChar *)ARG5);
   1967    PRE_REG_READ5(long, "sys_fanotify_mark",
   1968                  int, fanotify_fd, unsigned int, flags,
   1969                  __vki_u64, mask,
   1970                  int, dfd, const char *, pathname);
   1971    if (ARG5)
   1972       PRE_MEM_RASCIIZ( "fanotify_mark(path)", ARG5);
   1973 #else
   1974 #  error Unexpected word size
   1975 #endif
   1976 }
   1977 
   1978 /* ---------------------------------------------------------------------
   1979    inotify_* wrappers
   1980    ------------------------------------------------------------------ */
   1981 
   1982 PRE(sys_inotify_init)
   1983 {
   1984    PRINT("sys_inotify_init ( )");
   1985    PRE_REG_READ0(long, "inotify_init");
   1986 }
   1987 POST(sys_inotify_init)
   1988 {
   1989    vg_assert(SUCCESS);
   1990    if (!ML_(fd_allowed)(RES, "inotify_init", tid, True)) {
   1991       VG_(close)(RES);
   1992       SET_STATUS_Failure( VKI_EMFILE );
   1993    } else {
   1994       if (VG_(clo_track_fds))
   1995          ML_(record_fd_open_nameless) (tid, RES);
   1996    }
   1997 }
   1998 
   1999 PRE(sys_inotify_init1)
   2000 {
   2001    PRINT("sys_inotify_init ( %ld )", SARG1);
   2002    PRE_REG_READ1(long, "inotify_init", int, flag);
   2003 }
   2004 
   2005 POST(sys_inotify_init1)
   2006 {
   2007    vg_assert(SUCCESS);
   2008    if (!ML_(fd_allowed)(RES, "inotify_init", tid, True)) {
   2009       VG_(close)(RES);
   2010       SET_STATUS_Failure( VKI_EMFILE );
   2011    } else {
   2012       if (VG_(clo_track_fds))
   2013          ML_(record_fd_open_nameless) (tid, RES);
   2014    }
   2015 }
   2016 
   2017 PRE(sys_inotify_add_watch)
   2018 {
   2019    PRINT( "sys_inotify_add_watch ( %ld, %#lx, %lx )", SARG1, ARG2, ARG3);
   2020    PRE_REG_READ3(long, "inotify_add_watch", int, fd, char *, path, int, mask);
   2021    PRE_MEM_RASCIIZ( "inotify_add_watch(path)", ARG2 );
   2022 }
   2023 
   2024 PRE(sys_inotify_rm_watch)
   2025 {
   2026    PRINT( "sys_inotify_rm_watch ( %ld, %lx )", SARG1, ARG2);
   2027    PRE_REG_READ2(long, "inotify_rm_watch", int, fd, int, wd);
   2028 }
   2029 
   2030 /* ---------------------------------------------------------------------
   2031    mq_* wrappers
   2032    ------------------------------------------------------------------ */
   2033 
   2034 PRE(sys_mq_open)
   2035 {
   2036    PRINT("sys_mq_open( %#lx(%s), %ld, %lu, %#lx )",
   2037          ARG1, (HChar*)ARG1, SARG2, ARG3, ARG4);
   2038    PRE_REG_READ4(long, "mq_open",
   2039                  const char *, name, int, oflag, vki_mode_t, mode,
   2040                  struct mq_attr *, attr);
   2041    PRE_MEM_RASCIIZ( "mq_open(name)", ARG1 );
   2042    if ((ARG2 & VKI_O_CREAT) != 0 && ARG4 != 0) {
   2043       const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG4;
   2044       PRE_MEM_READ( "mq_open(attr->mq_maxmsg)",
   2045                      (Addr)&attr->mq_maxmsg, sizeof(attr->mq_maxmsg) );
   2046       PRE_MEM_READ( "mq_open(attr->mq_msgsize)",
   2047                      (Addr)&attr->mq_msgsize, sizeof(attr->mq_msgsize) );
   2048    }
   2049 }
   2050 POST(sys_mq_open)
   2051 {
   2052    vg_assert(SUCCESS);
   2053    if (!ML_(fd_allowed)(RES, "mq_open", tid, True)) {
   2054       VG_(close)(RES);
   2055       SET_STATUS_Failure( VKI_EMFILE );
   2056    } else {
   2057       if (VG_(clo_track_fds))
   2058          ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1);
   2059    }
   2060 }
   2061 
   2062 PRE(sys_mq_unlink)
   2063 {
   2064    PRINT("sys_mq_unlink ( %#lx(%s) )", ARG1,(char*)ARG1);
   2065    PRE_REG_READ1(long, "mq_unlink", const char *, name);
   2066    PRE_MEM_RASCIIZ( "mq_unlink(name)", ARG1 );
   2067 }
   2068 
   2069 PRE(sys_mq_timedsend)
   2070 {
   2071    *flags |= SfMayBlock;
   2072    PRINT("sys_mq_timedsend ( %ld, %#lx, %lu, %lu, %#lx )",
   2073          SARG1,ARG2,ARG3,ARG4,ARG5);
   2074    PRE_REG_READ5(long, "mq_timedsend",
   2075                  vki_mqd_t, mqdes, const char *, msg_ptr, vki_size_t, msg_len,
   2076                  unsigned int, msg_prio, const struct timespec *, abs_timeout);
   2077    if (!ML_(fd_allowed)(ARG1, "mq_timedsend", tid, False)) {
   2078       SET_STATUS_Failure( VKI_EBADF );
   2079    } else {
   2080       PRE_MEM_READ( "mq_timedsend(msg_ptr)", ARG2, ARG3 );
   2081       if (ARG5 != 0)
   2082          PRE_MEM_READ( "mq_timedsend(abs_timeout)", ARG5,
   2083                         sizeof(struct vki_timespec) );
   2084    }
   2085 }
   2086 
   2087 PRE(sys_mq_timedreceive)
   2088 {
   2089    *flags |= SfMayBlock;
   2090    PRINT("sys_mq_timedreceive( %ld, %#lx, %lu, %#lx, %#lx )",
   2091          SARG1,ARG2,ARG3,ARG4,ARG5);
   2092    PRE_REG_READ5(ssize_t, "mq_timedreceive",
   2093                  vki_mqd_t, mqdes, char *, msg_ptr, vki_size_t, msg_len,
   2094                  unsigned int *, msg_prio,
   2095                  const struct timespec *, abs_timeout);
   2096    if (!ML_(fd_allowed)(ARG1, "mq_timedreceive", tid, False)) {
   2097       SET_STATUS_Failure( VKI_EBADF );
   2098    } else {
   2099       PRE_MEM_WRITE( "mq_timedreceive(msg_ptr)", ARG2, ARG3 );
   2100       if (ARG4 != 0)
   2101          PRE_MEM_WRITE( "mq_timedreceive(msg_prio)",
   2102                         ARG4, sizeof(unsigned int) );
   2103       if (ARG5 != 0)
   2104          PRE_MEM_READ( "mq_timedreceive(abs_timeout)",
   2105                         ARG5, sizeof(struct vki_timespec) );
   2106    }
   2107 }
   2108 POST(sys_mq_timedreceive)
   2109 {
   2110    POST_MEM_WRITE( ARG2, RES );
   2111    if (ARG4 != 0)
   2112       POST_MEM_WRITE( ARG4, sizeof(unsigned int) );
   2113 }
   2114 
   2115 PRE(sys_mq_notify)
   2116 {
   2117    PRINT("sys_mq_notify( %ld, %#lx )", SARG1, ARG2 );
   2118    PRE_REG_READ2(long, "mq_notify",
   2119                  vki_mqd_t, mqdes, const struct sigevent *, notification);
   2120    if (!ML_(fd_allowed)(ARG1, "mq_notify", tid, False))
   2121       SET_STATUS_Failure( VKI_EBADF );
   2122    else if (ARG2 != 0)
   2123       PRE_MEM_READ( "mq_notify(notification)",
   2124                     ARG2, sizeof(struct vki_sigevent) );
   2125 }
   2126 
   2127 PRE(sys_mq_getsetattr)
   2128 {
   2129    PRINT("sys_mq_getsetattr( %ld, %#lx, %#lx )", SARG1,ARG2,ARG3 );
   2130    PRE_REG_READ3(long, "mq_getsetattr",
   2131                  vki_mqd_t, mqdes, const struct mq_attr *, mqstat,
   2132                  struct mq_attr *, omqstat);
   2133    if (!ML_(fd_allowed)(ARG1, "mq_getsetattr", tid, False)) {
   2134       SET_STATUS_Failure( VKI_EBADF );
   2135    } else {
   2136       if (ARG2 != 0) {
   2137          const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG2;
   2138          PRE_MEM_READ( "mq_getsetattr(mqstat->mq_flags)",
   2139                         (Addr)&attr->mq_flags, sizeof(attr->mq_flags) );
   2140       }
   2141       if (ARG3 != 0)
   2142          PRE_MEM_WRITE( "mq_getsetattr(omqstat)", ARG3,
   2143                         sizeof(struct vki_mq_attr) );
   2144    }
   2145 }
   2146 POST(sys_mq_getsetattr)
   2147 {
   2148    if (ARG3 != 0)
   2149       POST_MEM_WRITE( ARG3, sizeof(struct vki_mq_attr) );
   2150 }
   2151 
   2152 /* ---------------------------------------------------------------------
   2153    clock_* wrappers
   2154    ------------------------------------------------------------------ */
   2155 
   2156 PRE(sys_clock_settime)
   2157 {
   2158    PRINT("sys_clock_settime( %ld, %#lx )", SARG1, ARG2);
   2159    PRE_REG_READ2(long, "clock_settime",
   2160                  vki_clockid_t, clk_id, const struct timespec *, tp);
   2161    PRE_MEM_READ( "clock_settime(tp)", ARG2, sizeof(struct vki_timespec) );
   2162 }
   2163 
   2164 PRE(sys_clock_gettime)
   2165 {
   2166    PRINT("sys_clock_gettime( %ld, %#lx )" , SARG1, ARG2);
   2167    PRE_REG_READ2(long, "clock_gettime",
   2168                  vki_clockid_t, clk_id, struct timespec *, tp);
   2169    PRE_MEM_WRITE( "clock_gettime(tp)", ARG2, sizeof(struct vki_timespec) );
   2170 }
   2171 POST(sys_clock_gettime)
   2172 {
   2173    POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) );
   2174 }
   2175 
   2176 PRE(sys_clock_getres)
   2177 {
   2178    PRINT("sys_clock_getres( %ld, %#lx )" , SARG1, ARG2);
   2179    // Nb: we can't use "RES" as the param name because that's a macro
   2180    // defined above!
   2181    PRE_REG_READ2(long, "clock_getres",
   2182                  vki_clockid_t, clk_id, struct timespec *, res);
   2183    if (ARG2 != 0)
   2184       PRE_MEM_WRITE( "clock_getres(res)", ARG2, sizeof(struct vki_timespec) );
   2185 }
   2186 POST(sys_clock_getres)
   2187 {
   2188    if (ARG2 != 0)
   2189       POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) );
   2190 }
   2191 
   2192 PRE(sys_clock_nanosleep)
   2193 {
   2194    *flags |= SfMayBlock|SfPostOnFail;
   2195    PRINT("sys_clock_nanosleep( %ld, %ld, %#lx, %#lx )",
   2196          SARG1, SARG2, ARG3, ARG4);
   2197    PRE_REG_READ4(int32_t, "clock_nanosleep",
   2198                  vki_clockid_t, clkid, int, flags,
   2199                  const struct timespec *, rqtp, struct timespec *, rmtp);
   2200    PRE_MEM_READ( "clock_nanosleep(rqtp)", ARG3, sizeof(struct vki_timespec) );
   2201    if (ARG4 != 0)
   2202       PRE_MEM_WRITE( "clock_nanosleep(rmtp)", ARG4, sizeof(struct vki_timespec) );
   2203 }
   2204 POST(sys_clock_nanosleep)
   2205 {
   2206    if (ARG4 != 0 && FAILURE && ERR == VKI_EINTR)
   2207       POST_MEM_WRITE( ARG4, sizeof(struct vki_timespec) );
   2208 }
   2209 
   2210 /* ---------------------------------------------------------------------
   2211    timer_* wrappers
   2212    ------------------------------------------------------------------ */
   2213 
   2214 PRE(sys_timer_create)
   2215 {
   2216    PRINT("sys_timer_create( %ld, %#lx, %#lx )", SARG1, ARG2, ARG3);
   2217    PRE_REG_READ3(long, "timer_create",
   2218                  vki_clockid_t, clockid, struct sigevent *, evp,
   2219                  vki_timer_t *, timerid);
   2220    if (ARG2 != 0) {
   2221       struct vki_sigevent *evp = (struct vki_sigevent *) ARG2;
   2222       PRE_MEM_READ( "timer_create(evp.sigev_value)", (Addr)&evp->sigev_value,
   2223                     sizeof(vki_sigval_t) );
   2224       PRE_MEM_READ( "timer_create(evp.sigev_signo)", (Addr)&evp->sigev_signo,
   2225                     sizeof(int) );
   2226       PRE_MEM_READ( "timer_create(evp.sigev_notify)", (Addr)&evp->sigev_notify,
   2227                     sizeof(int) );
   2228       if (ML_(safe_to_deref)(&evp->sigev_notify, sizeof(int))
   2229           && (evp->sigev_notify & VKI_SIGEV_THREAD_ID) != 0)
   2230          PRE_MEM_READ( "timer_create(evp.sigev_notify_thread_id)",
   2231                        (Addr)&evp->vki_sigev_notify_thread_id, sizeof(int) );
   2232    }
   2233    PRE_MEM_WRITE( "timer_create(timerid)", ARG3, sizeof(vki_timer_t) );
   2234 }
   2235 POST(sys_timer_create)
   2236 {
   2237    POST_MEM_WRITE( ARG3, sizeof(vki_timer_t) );
   2238 }
   2239 
   2240 PRE(sys_timer_settime)
   2241 {
   2242    PRINT("sys_timer_settime( %ld, %ld, %#lx, %#lx )", SARG1,SARG2,ARG3,ARG4);
   2243    PRE_REG_READ4(long, "timer_settime",
   2244                  vki_timer_t, timerid, int, flags,
   2245                  const struct itimerspec *, value,
   2246                  struct itimerspec *, ovalue);
   2247    PRE_MEM_READ( "timer_settime(value)", ARG3,
   2248                   sizeof(struct vki_itimerspec) );
   2249    if (ARG4 != 0)
   2250        PRE_MEM_WRITE( "timer_settime(ovalue)", ARG4,
   2251                       sizeof(struct vki_itimerspec) );
   2252 }
   2253 POST(sys_timer_settime)
   2254 {
   2255    if (ARG4 != 0)
   2256       POST_MEM_WRITE( ARG4, sizeof(struct vki_itimerspec) );
   2257 }
   2258 
   2259 PRE(sys_timer_gettime)
   2260 {
   2261    PRINT("sys_timer_gettime( %ld, %#lx )", SARG1, ARG2);
   2262    PRE_REG_READ2(long, "timer_gettime",
   2263                  vki_timer_t, timerid, struct itimerspec *, value);
   2264    PRE_MEM_WRITE( "timer_gettime(value)", ARG2,
   2265                   sizeof(struct vki_itimerspec));
   2266 }
   2267 POST(sys_timer_gettime)
   2268 {
   2269    POST_MEM_WRITE( ARG2, sizeof(struct vki_itimerspec) );
   2270 }
   2271 
   2272 PRE(sys_timer_getoverrun)
   2273 {
   2274    PRINT("sys_timer_getoverrun( %#lx )", ARG1);
   2275    PRE_REG_READ1(long, "timer_getoverrun", vki_timer_t, timerid);
   2276 }
   2277 
   2278 PRE(sys_timer_delete)
   2279 {
   2280    PRINT("sys_timer_delete( %#lx )", ARG1);
   2281    PRE_REG_READ1(long, "timer_delete", vki_timer_t, timerid);
   2282 }
   2283 
   2284 /* ---------------------------------------------------------------------
   2285    timerfd* wrappers
   2286    See also http://lwn.net/Articles/260172/ for an overview.
   2287    See also /usr/src/linux/fs/timerfd.c for the implementation.
   2288    ------------------------------------------------------------------ */
   2289 
   2290 /* Returns True if running on 2.6.22, else False (or False if
   2291    cannot be determined). */
   2292 static Bool linux_kernel_2_6_22(void)
   2293 {
   2294    static Int result = -1;
   2295    Int fd, read;
   2296    HChar release[64];   // large enough
   2297    SysRes res;
   2298 
   2299    if (result == -1) {
   2300       res = VG_(open)("/proc/sys/kernel/osrelease", 0, 0);
   2301       if (sr_isError(res))
   2302          return False;
   2303       fd = sr_Res(res);
   2304       read = VG_(read)(fd, release, sizeof(release) - 1);
   2305       if (read < 0)
   2306          return False;
   2307       release[read] = 0;
   2308       VG_(close)(fd);
   2309       //VG_(printf)("kernel release = %s\n", release);
   2310       result = VG_(strncmp)(release, "2.6.22", 6) == 0
   2311                && ! VG_(isdigit)(release[6]);
   2312    }
   2313    vg_assert(result == 0 || result == 1);
   2314    return result == 1;
   2315 }
   2316 
   2317 PRE(sys_timerfd_create)
   2318 {
   2319    if (linux_kernel_2_6_22()) {
   2320       /* 2.6.22 kernel: timerfd system call. */
   2321       PRINT("sys_timerfd ( %ld, %ld, %#lx )", SARG1, SARG2, ARG3);
   2322       PRE_REG_READ3(long, "sys_timerfd",
   2323                     int, fd, int, clockid, const struct itimerspec *, tmr);
   2324       PRE_MEM_READ("timerfd(tmr)", ARG3,
   2325                    sizeof(struct vki_itimerspec) );
   2326       if ((Word)ARG1 != -1L && !ML_(fd_allowed)(ARG1, "timerfd", tid, False))
   2327          SET_STATUS_Failure( VKI_EBADF );
   2328    } else {
   2329       /* 2.6.24 and later kernels: timerfd_create system call. */
   2330       PRINT("sys_timerfd_create (%ld, %ld )", SARG1, SARG2);
   2331       PRE_REG_READ2(long, "timerfd_create", int, clockid, int, flags);
   2332    }
   2333 }
   2334 POST(sys_timerfd_create)
   2335 {
   2336    if (linux_kernel_2_6_22())
   2337    {
   2338       /* 2.6.22 kernel: timerfd system call. */
   2339       if (!ML_(fd_allowed)(RES, "timerfd", tid, True)) {
   2340          VG_(close)(RES);
   2341          SET_STATUS_Failure( VKI_EMFILE );
   2342       } else {
   2343          if (VG_(clo_track_fds))
   2344             ML_(record_fd_open_nameless) (tid, RES);
   2345       }
   2346    }
   2347    else
   2348    {
   2349       /* 2.6.24 and later kernels: timerfd_create system call. */
   2350       if (!ML_(fd_allowed)(RES, "timerfd_create", tid, True)) {
   2351          VG_(close)(RES);
   2352          SET_STATUS_Failure( VKI_EMFILE );
   2353       } else {
   2354          if (VG_(clo_track_fds))
   2355             ML_(record_fd_open_nameless) (tid, RES);
   2356       }
   2357    }
   2358 }
   2359 
   2360 PRE(sys_timerfd_gettime)
   2361 {
   2362    PRINT("sys_timerfd_gettime ( %ld, %#lx )", SARG1, ARG2);
   2363    PRE_REG_READ2(long, "timerfd_gettime",
   2364                  int, ufd,
   2365                  struct vki_itimerspec*, otmr);
   2366    if (!ML_(fd_allowed)(ARG1, "timerfd_gettime", tid, False))
   2367       SET_STATUS_Failure(VKI_EBADF);
   2368    else
   2369       PRE_MEM_WRITE("timerfd_gettime(result)",
   2370                     ARG2, sizeof(struct vki_itimerspec));
   2371 }
   2372 POST(sys_timerfd_gettime)
   2373 {
   2374    if (RES == 0)
   2375       POST_MEM_WRITE(ARG2, sizeof(struct vki_itimerspec));
   2376 }
   2377 
   2378 PRE(sys_timerfd_settime)
   2379 {
   2380    PRINT("sys_timerfd_settime ( %ld, %ld, %#lx, %#lx )",
   2381          SARG1, SARG2, ARG3, ARG4);
   2382    PRE_REG_READ4(long, "timerfd_settime",
   2383                  int, ufd,
   2384                  int, flags,
   2385                  const struct vki_itimerspec*, utmr,
   2386                  struct vki_itimerspec*, otmr);
   2387    if (!ML_(fd_allowed)(ARG1, "timerfd_settime", tid, False))
   2388       SET_STATUS_Failure(VKI_EBADF);
   2389    else
   2390    {
   2391       PRE_MEM_READ("timerfd_settime(result)",
   2392                    ARG3, sizeof(struct vki_itimerspec));
   2393       if (ARG4)
   2394       {
   2395          PRE_MEM_WRITE("timerfd_settime(result)",
   2396                        ARG4, sizeof(struct vki_itimerspec));
   2397       }
   2398    }
   2399 }
   2400 POST(sys_timerfd_settime)
   2401 {
   2402    if (RES == 0 && ARG4 != 0)
   2403       POST_MEM_WRITE(ARG4, sizeof(struct vki_itimerspec));
   2404 }
   2405 
   2406 /* ---------------------------------------------------------------------
   2407    capabilities wrappers
   2408    ------------------------------------------------------------------ */
   2409 
   2410 PRE(sys_capget)
   2411 {
   2412    PRINT("sys_capget ( %#lx, %#lx )", ARG1, ARG2 );
   2413    PRE_REG_READ2(long, "capget",
   2414                  vki_cap_user_header_t, header, vki_cap_user_data_t, data);
   2415    PRE_MEM_READ( "capget(header)", ARG1,
   2416                   sizeof(struct __vki_user_cap_header_struct) );
   2417    if (ARG2 != (Addr)NULL)
   2418       PRE_MEM_WRITE( "capget(data)", ARG2,
   2419                      sizeof(struct __vki_user_cap_data_struct) );
   2420 }
   2421 POST(sys_capget)
   2422 {
   2423    if (ARG2 != (Addr)NULL)
   2424       POST_MEM_WRITE( ARG2, sizeof(struct __vki_user_cap_data_struct) );
   2425 }
   2426 
   2427 PRE(sys_capset)
   2428 {
   2429    PRINT("sys_capset ( %#lx, %#lx )", ARG1, ARG2 );
   2430    PRE_REG_READ2(long, "capset",
   2431                  vki_cap_user_header_t, header,
   2432                  const vki_cap_user_data_t, data);
   2433    PRE_MEM_READ( "capset(header)",
   2434                   ARG1, sizeof(struct __vki_user_cap_header_struct) );
   2435    PRE_MEM_READ( "capset(data)",
   2436                   ARG2, sizeof(struct __vki_user_cap_data_struct) );
   2437 }
   2438 
   2439 /* ---------------------------------------------------------------------
   2440    16-bit uid/gid/groups wrappers
   2441    ------------------------------------------------------------------ */
   2442 
   2443 PRE(sys_getuid16)
   2444 {
   2445    PRINT("sys_getuid16 ( )");
   2446    PRE_REG_READ0(long, "getuid16");
   2447 }
   2448 
   2449 PRE(sys_setuid16)
   2450 {
   2451    PRINT("sys_setuid16 ( %lu )", ARG1);
   2452    PRE_REG_READ1(long, "setuid16", vki_old_uid_t, uid);
   2453 }
   2454 
   2455 PRE(sys_getgid16)
   2456 {
   2457    PRINT("sys_getgid16 ( )");
   2458    PRE_REG_READ0(long, "getgid16");
   2459 }
   2460 
   2461 PRE(sys_setgid16)
   2462 {
   2463    PRINT("sys_setgid16 ( %lu )", ARG1);
   2464    PRE_REG_READ1(long, "setgid16", vki_old_gid_t, gid);
   2465 }
   2466 
   2467 PRE(sys_geteuid16)
   2468 {
   2469    PRINT("sys_geteuid16 ( )");
   2470    PRE_REG_READ0(long, "geteuid16");
   2471 }
   2472 
   2473 PRE(sys_getegid16)
   2474 {
   2475    PRINT("sys_getegid16 ( )");
   2476    PRE_REG_READ0(long, "getegid16");
   2477 }
   2478 
   2479 PRE(sys_setreuid16)
   2480 {
   2481    PRINT("setreuid16 ( 0x%lx, 0x%lx )", ARG1, ARG2);
   2482    PRE_REG_READ2(long, "setreuid16", vki_old_uid_t, ruid, vki_old_uid_t, euid);
   2483 }
   2484 
   2485 PRE(sys_setregid16)
   2486 {
   2487    PRINT("sys_setregid16 ( %lu, %lu )", ARG1, ARG2);
   2488    PRE_REG_READ2(long, "setregid16", vki_old_gid_t, rgid, vki_old_gid_t, egid);
   2489 }
   2490 
   2491 PRE(sys_getgroups16)
   2492 {
   2493    PRINT("sys_getgroups16 ( %ld, %#lx )", SARG1, ARG2);
   2494    PRE_REG_READ2(long, "getgroups16", int, size, vki_old_gid_t *, list);
   2495    if (ARG1 > 0)
   2496       PRE_MEM_WRITE( "getgroups16(list)", ARG2, ARG1 * sizeof(vki_old_gid_t) );
   2497 }
   2498 POST(sys_getgroups16)
   2499 {
   2500    vg_assert(SUCCESS);
   2501    if (ARG1 > 0 && RES > 0)
   2502       POST_MEM_WRITE( ARG2, RES * sizeof(vki_old_gid_t) );
   2503 }
   2504 
   2505 PRE(sys_setgroups16)
   2506 {
   2507    PRINT("sys_setgroups16 ( %llu, %#lx )", (ULong)ARG1, ARG2);
   2508    PRE_REG_READ2(long, "setgroups16", int, size, vki_old_gid_t *, list);
   2509    if (ARG1 > 0)
   2510       PRE_MEM_READ( "setgroups16(list)", ARG2, ARG1 * sizeof(vki_old_gid_t) );
   2511 }
   2512 
   2513 /* ---------------------------------------------------------------------
   2514    *chown16 wrappers
   2515    ------------------------------------------------------------------ */
   2516 
   2517 PRE(sys_chown16)
   2518 {
   2519    PRINT("sys_chown16 ( %#lx, 0x%lx, 0x%lx )", ARG1,ARG2,ARG3);
   2520    PRE_REG_READ3(long, "chown16",
   2521                  const char *, path,
   2522                  vki_old_uid_t, owner, vki_old_gid_t, group);
   2523    PRE_MEM_RASCIIZ( "chown16(path)", ARG1 );
   2524 }
   2525 
   2526 PRE(sys_fchown16)
   2527 {
   2528    PRINT("sys_fchown16 ( %lu, %lu, %lu )", ARG1,ARG2,ARG3);
   2529    PRE_REG_READ3(long, "fchown16",
   2530                  unsigned int, fd, vki_old_uid_t, owner, vki_old_gid_t, group);
   2531 }
   2532 
   2533 /* ---------------------------------------------------------------------
   2534    *xattr wrappers
   2535    ------------------------------------------------------------------ */
   2536 
   2537 PRE(sys_setxattr)
   2538 {
   2539    *flags |= SfMayBlock;
   2540    PRINT("sys_setxattr ( %#lx, %#lx, %#lx, %lu, %ld )",
   2541          ARG1, ARG2, ARG3, ARG4, SARG5);
   2542    PRE_REG_READ5(long, "setxattr",
   2543                  char *, path, char *, name,
   2544                  void *, value, vki_size_t, size, int, flags);
   2545    PRE_MEM_RASCIIZ( "setxattr(path)", ARG1 );
   2546    PRE_MEM_RASCIIZ( "setxattr(name)", ARG2 );
   2547    PRE_MEM_READ( "setxattr(value)", ARG3, ARG4 );
   2548 }
   2549 
   2550 PRE(sys_lsetxattr)
   2551 {
   2552    *flags |= SfMayBlock;
   2553    PRINT("sys_lsetxattr ( %#lx, %#lx, %#lx, %lu, %ld )",
   2554          ARG1, ARG2, ARG3, ARG4, SARG5);
   2555    PRE_REG_READ5(long, "lsetxattr",
   2556                  char *, path, char *, name,
   2557                  void *, value, vki_size_t, size, int, flags);
   2558    PRE_MEM_RASCIIZ( "lsetxattr(path)", ARG1 );
   2559    PRE_MEM_RASCIIZ( "lsetxattr(name)", ARG2 );
   2560    PRE_MEM_READ( "lsetxattr(value)", ARG3, ARG4 );
   2561 }
   2562 
   2563 PRE(sys_fsetxattr)
   2564 {
   2565    *flags |= SfMayBlock;
   2566    PRINT("sys_fsetxattr ( %ld, %#lx, %#lx, %lu, %ld )",
   2567          SARG1, ARG2, ARG3, ARG4, SARG5);
   2568    PRE_REG_READ5(long, "fsetxattr",
   2569                  int, fd, char *, name, void *, value,
   2570                  vki_size_t, size, int, flags);
   2571    PRE_MEM_RASCIIZ( "fsetxattr(name)", ARG2 );
   2572    PRE_MEM_READ( "fsetxattr(value)", ARG3, ARG4 );
   2573 }
   2574 
   2575 PRE(sys_getxattr)
   2576 {
   2577    *flags |= SfMayBlock;
   2578    PRINT("sys_getxattr ( %#lx, %#lx, %#lx, %llu )", ARG1,ARG2,ARG3, (ULong)ARG4);
   2579    PRE_REG_READ4(ssize_t, "getxattr",
   2580                  char *, path, char *, name, void *, value, vki_size_t, size);
   2581    PRE_MEM_RASCIIZ( "getxattr(path)", ARG1 );
   2582    PRE_MEM_RASCIIZ( "getxattr(name)", ARG2 );
   2583    PRE_MEM_WRITE( "getxattr(value)", ARG3, ARG4 );
   2584 }
   2585 POST(sys_getxattr)
   2586 {
   2587    vg_assert(SUCCESS);
   2588    if (RES > 0 && ARG3 != (Addr)NULL) {
   2589       POST_MEM_WRITE( ARG3, RES );
   2590    }
   2591 }
   2592 
   2593 PRE(sys_lgetxattr)
   2594 {
   2595    *flags |= SfMayBlock;
   2596    PRINT("sys_lgetxattr ( %#lx, %#lx, %#lx, %llu )", ARG1,ARG2,ARG3, (ULong)ARG4);
   2597    PRE_REG_READ4(ssize_t, "lgetxattr",
   2598                  char *, path, char *, name, void *, value, vki_size_t, size);
   2599    PRE_MEM_RASCIIZ( "lgetxattr(path)", ARG1 );
   2600    PRE_MEM_RASCIIZ( "lgetxattr(name)", ARG2 );
   2601    PRE_MEM_WRITE( "lgetxattr(value)", ARG3, ARG4 );
   2602 }
   2603 POST(sys_lgetxattr)
   2604 {
   2605    vg_assert(SUCCESS);
   2606    if (RES > 0 && ARG3 != (Addr)NULL) {
   2607       POST_MEM_WRITE( ARG3, RES );
   2608    }
   2609 }
   2610 
   2611 PRE(sys_fgetxattr)
   2612 {
   2613    *flags |= SfMayBlock;
   2614    PRINT("sys_fgetxattr ( %ld, %#lx, %#lx, %lu )", SARG1, ARG2, ARG3, ARG4);
   2615    PRE_REG_READ4(ssize_t, "fgetxattr",
   2616                  int, fd, char *, name, void *, value, vki_size_t, size);
   2617    PRE_MEM_RASCIIZ( "fgetxattr(name)", ARG2 );
   2618    PRE_MEM_WRITE( "fgetxattr(value)", ARG3, ARG4 );
   2619 }
   2620 POST(sys_fgetxattr)
   2621 {
   2622    if (RES > 0 && ARG3 != (Addr)NULL)
   2623       POST_MEM_WRITE( ARG3, RES );
   2624 }
   2625 
   2626 PRE(sys_listxattr)
   2627 {
   2628    *flags |= SfMayBlock;
   2629    PRINT("sys_listxattr ( %#lx, %#lx, %llu )", ARG1, ARG2, (ULong)ARG3);
   2630    PRE_REG_READ3(ssize_t, "listxattr",
   2631                  char *, path, char *, list, vki_size_t, size);
   2632    PRE_MEM_RASCIIZ( "listxattr(path)", ARG1 );
   2633    PRE_MEM_WRITE( "listxattr(list)", ARG2, ARG3 );
   2634 }
   2635 POST(sys_listxattr)
   2636 {
   2637    if (RES > 0 && ARG2 != (Addr)NULL)
   2638       POST_MEM_WRITE( ARG2, RES );
   2639 }
   2640 
   2641 PRE(sys_llistxattr)
   2642 {
   2643    *flags |= SfMayBlock;
   2644    PRINT("sys_llistxattr ( %#lx, %#lx, %llu )", ARG1, ARG2, (ULong)ARG3);
   2645    PRE_REG_READ3(ssize_t, "llistxattr",
   2646                  char *, path, char *, list, vki_size_t, size);
   2647    PRE_MEM_RASCIIZ( "llistxattr(path)", ARG1 );
   2648    PRE_MEM_WRITE( "llistxattr(list)", ARG2, ARG3 );
   2649 }
   2650 POST(sys_llistxattr)
   2651 {
   2652    if (RES > 0 && ARG2 != (Addr)NULL)
   2653       POST_MEM_WRITE( ARG2, RES );
   2654 }
   2655 
   2656 PRE(sys_flistxattr)
   2657 {
   2658    *flags |= SfMayBlock;
   2659    PRINT("sys_flistxattr ( %ld, %#lx, %lu )", SARG1, ARG2, ARG3);
   2660    PRE_REG_READ3(ssize_t, "flistxattr",
   2661                  int, fd, char *, list, vki_size_t, size);
   2662    PRE_MEM_WRITE( "flistxattr(list)", ARG2, ARG3 );
   2663 }
   2664 POST(sys_flistxattr)
   2665 {
   2666    if (RES > 0 && ARG2 != (Addr)NULL)
   2667       POST_MEM_WRITE( ARG2, RES );
   2668 }
   2669 
   2670 PRE(sys_removexattr)
   2671 {
   2672    *flags |= SfMayBlock;
   2673    PRINT("sys_removexattr ( %#lx, %#lx )", ARG1, ARG2);
   2674    PRE_REG_READ2(long, "removexattr", char *, path, char *, name);
   2675    PRE_MEM_RASCIIZ( "removexattr(path)", ARG1 );
   2676    PRE_MEM_RASCIIZ( "removexattr(name)", ARG2 );
   2677 }
   2678 
   2679 PRE(sys_lremovexattr)
   2680 {
   2681    *flags |= SfMayBlock;
   2682    PRINT("sys_lremovexattr ( %#lx, %#lx )", ARG1, ARG2);
   2683    PRE_REG_READ2(long, "lremovexattr", char *, path, char *, name);
   2684    PRE_MEM_RASCIIZ( "lremovexattr(path)", ARG1 );
   2685    PRE_MEM_RASCIIZ( "lremovexattr(name)", ARG2 );
   2686 }
   2687 
   2688 PRE(sys_fremovexattr)
   2689 {
   2690    *flags |= SfMayBlock;
   2691    PRINT("sys_fremovexattr ( %ld, %#lx )", SARG1, ARG2);
   2692    PRE_REG_READ2(long, "fremovexattr", int, fd, char *, name);
   2693    PRE_MEM_RASCIIZ( "fremovexattr(name)", ARG2 );
   2694 }
   2695 
   2696 /* ---------------------------------------------------------------------
   2697    sched_* wrappers
   2698    ------------------------------------------------------------------ */
   2699 
   2700 PRE(sys_sched_setparam)
   2701 {
   2702    PRINT("sched_setparam ( %ld, %#lx )", SARG1, ARG2 );
   2703    PRE_REG_READ2(long, "sched_setparam",
   2704                  vki_pid_t, pid, struct sched_param *, p);
   2705    PRE_MEM_READ( "sched_setparam(p)", ARG2, sizeof(struct vki_sched_param) );
   2706 }
   2707 POST(sys_sched_setparam)
   2708 {
   2709    POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) );
   2710 }
   2711 
   2712 PRE(sys_sched_getparam)
   2713 {
   2714    PRINT("sched_getparam ( %ld, %#lx )", SARG1, ARG2 );
   2715    PRE_REG_READ2(long, "sched_getparam",
   2716                  vki_pid_t, pid, struct sched_param *, p);
   2717    PRE_MEM_WRITE( "sched_getparam(p)", ARG2, sizeof(struct vki_sched_param) );
   2718 }
   2719 POST(sys_sched_getparam)
   2720 {
   2721    POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) );
   2722 }
   2723 
   2724 PRE(sys_sched_getscheduler)
   2725 {
   2726    PRINT("sys_sched_getscheduler ( %ld )", SARG1);
   2727    PRE_REG_READ1(long, "sched_getscheduler", vki_pid_t, pid);
   2728 }
   2729 
   2730 PRE(sys_sched_setscheduler)
   2731 {
   2732    PRINT("sys_sched_setscheduler ( %ld, %ld, %#lx )", SARG1, SARG2, ARG3);
   2733    PRE_REG_READ3(long, "sched_setscheduler",
   2734                  vki_pid_t, pid, int, policy, struct sched_param *, p);
   2735    if (ARG3 != 0)
   2736       PRE_MEM_READ( "sched_setscheduler(p)",
   2737 		    ARG3, sizeof(struct vki_sched_param));
   2738 }
   2739 
   2740 PRE(sys_sched_yield)
   2741 {
   2742    *flags |= SfMayBlock;
   2743    PRINT("sched_yield()");
   2744    PRE_REG_READ0(long, "sys_sched_yield");
   2745 }
   2746 
   2747 PRE(sys_sched_get_priority_max)
   2748 {
   2749    PRINT("sched_get_priority_max ( %ld )", SARG1);
   2750    PRE_REG_READ1(long, "sched_get_priority_max", int, policy);
   2751 }
   2752 
   2753 PRE(sys_sched_get_priority_min)
   2754 {
   2755    PRINT("sched_get_priority_min ( %ld )", SARG1);
   2756    PRE_REG_READ1(long, "sched_get_priority_min", int, policy);
   2757 }
   2758 
   2759 PRE(sys_sched_rr_get_interval)
   2760 {
   2761    PRINT("sys_sched_rr_get_interval ( %ld, %#lx )", SARG1, ARG2);
   2762    PRE_REG_READ2(int, "sched_rr_get_interval",
   2763                  vki_pid_t, pid,
   2764                  struct vki_timespec *, tp);
   2765    PRE_MEM_WRITE("sched_rr_get_interval(timespec)",
   2766                  ARG2, sizeof(struct vki_timespec));
   2767 }
   2768 
   2769 POST(sys_sched_rr_get_interval)
   2770 {
   2771    POST_MEM_WRITE(ARG2, sizeof(struct vki_timespec));
   2772 }
   2773 
   2774 PRE(sys_sched_setaffinity)
   2775 {
   2776    PRINT("sched_setaffinity ( %ld, %lu, %#lx )", SARG1, ARG2, ARG3);
   2777    PRE_REG_READ3(long, "sched_setaffinity",
   2778                  vki_pid_t, pid, unsigned int, len, unsigned long *, mask);
   2779    PRE_MEM_READ( "sched_setaffinity(mask)", ARG3, ARG2);
   2780 }
   2781 
   2782 PRE(sys_sched_getaffinity)
   2783 {
   2784    PRINT("sched_getaffinity ( %ld, %lu, %#lx )", SARG1, ARG2, ARG3);
   2785    PRE_REG_READ3(long, "sched_getaffinity",
   2786                  vki_pid_t, pid, unsigned int, len, unsigned long *, mask);
   2787    PRE_MEM_WRITE( "sched_getaffinity(mask)", ARG3, ARG2);
   2788 }
   2789 POST(sys_sched_getaffinity)
   2790 {
   2791    POST_MEM_WRITE(ARG3, ARG2);
   2792 }
   2793 
   2794 PRE(sys_unshare)
   2795 {
   2796    PRINT("sys_unshare ( %#lx )", ARG1);
   2797    PRE_REG_READ1(int, "unshare", unsigned long, flags);
   2798 }
   2799 
   2800 /* ---------------------------------------------------------------------
   2801    miscellaneous wrappers
   2802    ------------------------------------------------------------------ */
   2803 
   2804 PRE(sys_munlockall)
   2805 {
   2806    *flags |= SfMayBlock;
   2807    PRINT("sys_munlockall ( )");
   2808    PRE_REG_READ0(long, "munlockall");
   2809 }
   2810 
   2811 // This has different signatures for different platforms.
   2812 //
   2813 //  x86:   int  sys_pipe(unsigned long __user *fildes);
   2814 //  AMD64: long sys_pipe(int *fildes);
   2815 //  ppc32: int  sys_pipe(int __user *fildes);
   2816 //  ppc64: int  sys_pipe(int __user *fildes);
   2817 //
   2818 // The type of the argument is most important, and it is an array of 32 bit
   2819 // values in all cases.  (The return type differs across platforms, but it
   2820 // is not used.)  So we use 'int' as its type.  This fixed bug #113230 which
   2821 // was caused by using an array of 'unsigned long's, which didn't work on
   2822 // AMD64.
   2823 PRE(sys_pipe)
   2824 {
   2825    PRINT("sys_pipe ( %#lx )", ARG1);
   2826    PRE_REG_READ1(int, "pipe", int *, filedes);
   2827    PRE_MEM_WRITE( "pipe(filedes)", ARG1, 2*sizeof(int) );
   2828 }
   2829 POST(sys_pipe)
   2830 {
   2831    Int *p = (Int *)ARG1;
   2832    if (!ML_(fd_allowed)(p[0], "pipe", tid, True) ||
   2833        !ML_(fd_allowed)(p[1], "pipe", tid, True)) {
   2834       VG_(close)(p[0]);
   2835       VG_(close)(p[1]);
   2836       SET_STATUS_Failure( VKI_EMFILE );
   2837    } else {
   2838       POST_MEM_WRITE( ARG1, 2*sizeof(int) );
   2839       if (VG_(clo_track_fds)) {
   2840          ML_(record_fd_open_nameless)(tid, p[0]);
   2841          ML_(record_fd_open_nameless)(tid, p[1]);
   2842       }
   2843    }
   2844 }
   2845 
   2846 /* pipe2 (a kernel 2.6.twentysomething invention) is like pipe, except
   2847    there's a second arg containing flags to be applied to the new file
   2848    descriptors.  It hardly seems worth the effort to factor out the
   2849    duplicated code, hence: */
   2850 PRE(sys_pipe2)
   2851 {
   2852    PRINT("sys_pipe2 ( %#lx, %#lx )", ARG1, ARG2);
   2853    PRE_REG_READ2(int, "pipe", int *, filedes, long, flags);
   2854    PRE_MEM_WRITE( "pipe2(filedes)", ARG1, 2*sizeof(int) );
   2855 }
   2856 POST(sys_pipe2)
   2857 {
   2858    Int *p = (Int *)ARG1;
   2859    if (!ML_(fd_allowed)(p[0], "pipe2", tid, True) ||
   2860        !ML_(fd_allowed)(p[1], "pipe2", tid, True)) {
   2861       VG_(close)(p[0]);
   2862       VG_(close)(p[1]);
   2863       SET_STATUS_Failure( VKI_EMFILE );
   2864    } else {
   2865       POST_MEM_WRITE( ARG1, 2*sizeof(int) );
   2866       if (VG_(clo_track_fds)) {
   2867          ML_(record_fd_open_nameless)(tid, p[0]);
   2868          ML_(record_fd_open_nameless)(tid, p[1]);
   2869       }
   2870    }
   2871 }
   2872 
   2873 PRE(sys_dup3)
   2874 {
   2875    PRINT("sys_dup3 ( %lu, %lu, %#lx )", ARG1, ARG2, ARG3);
   2876    PRE_REG_READ3(long, "dup3", unsigned int, oldfd, unsigned int, newfd, int, flags);
   2877    if (!ML_(fd_allowed)(ARG2, "dup3", tid, True))
   2878       SET_STATUS_Failure( VKI_EBADF );
   2879 }
   2880 
   2881 POST(sys_dup3)
   2882 {
   2883    vg_assert(SUCCESS);
   2884    if (VG_(clo_track_fds))
   2885       ML_(record_fd_open_named)(tid, RES);
   2886 }
   2887 
   2888 PRE(sys_quotactl)
   2889 {
   2890    PRINT("sys_quotactl (0x%lx, %#lx, 0x%lx, 0x%lx )", ARG1,ARG2,ARG3, ARG4);
   2891    PRE_REG_READ4(long, "quotactl",
   2892                  unsigned int, cmd, const char *, special, vki_qid_t, id,
   2893                  void *, addr);
   2894    PRE_MEM_RASCIIZ( "quotactl(special)", ARG2 );
   2895 }
   2896 
   2897 PRE(sys_waitid)
   2898 {
   2899    *flags |= SfMayBlock;
   2900    PRINT("sys_waitid( %ld, %ld, %#lx, %ld, %#lx )",
   2901          SARG1, SARG2, ARG3, SARG4, ARG5);
   2902    PRE_REG_READ5(int32_t, "sys_waitid",
   2903                  int, which, vki_pid_t, pid, struct vki_siginfo *, infop,
   2904                  int, options, struct vki_rusage *, ru);
   2905    PRE_MEM_WRITE( "waitid(infop)", ARG3, sizeof(struct vki_siginfo) );
   2906    if (ARG5 != 0)
   2907       PRE_MEM_WRITE( "waitid(ru)", ARG5, sizeof(struct vki_rusage) );
   2908 }
   2909 POST(sys_waitid)
   2910 {
   2911    POST_MEM_WRITE( ARG3, sizeof(struct vki_siginfo) );
   2912    if (ARG5 != 0)
   2913       POST_MEM_WRITE( ARG5, sizeof(struct vki_rusage) );
   2914 }
   2915 
   2916 PRE(sys_sync_file_range)
   2917 {
   2918    *flags |= SfMayBlock;
   2919 #if VG_WORDSIZE == 4
   2920    PRINT("sys_sync_file_range ( %ld, %lld, %lld, %#lx )",
   2921          SARG1, (Long)MERGE64(ARG2,ARG3), (Long)MERGE64(ARG4,ARG5),ARG6);
   2922    PRE_REG_READ6(long, "sync_file_range",
   2923                  int, fd,
   2924                  unsigned, MERGE64_FIRST(offset), unsigned, MERGE64_SECOND(offset),
   2925                  unsigned, MERGE64_FIRST(nbytes), unsigned, MERGE64_SECOND(nbytes),
   2926                  unsigned int, flags);
   2927 #elif VG_WORDSIZE == 8
   2928    PRINT("sys_sync_file_range ( %ld, %ld, %ld, %#lx )",
   2929          SARG1, SARG2, SARG3, ARG4);
   2930    PRE_REG_READ4(long, "sync_file_range",
   2931                  int, fd, vki_loff_t, offset, vki_loff_t, nbytes,
   2932                  unsigned int, flags);
   2933 #else
   2934 #  error Unexpected word size
   2935 #endif
   2936    if (!ML_(fd_allowed)(ARG1, "sync_file_range", tid, False))
   2937       SET_STATUS_Failure( VKI_EBADF );
   2938 }
   2939 
   2940 PRE(sys_sync_file_range2)
   2941 {
   2942    *flags |= SfMayBlock;
   2943 #if VG_WORDSIZE == 4
   2944    PRINT("sys_sync_file_range2 ( %ld, %lu, %lld, %lld )",
   2945          SARG1, ARG2, (Long)MERGE64(ARG3,ARG4), (Long)MERGE64(ARG5,ARG6));
   2946    PRE_REG_READ6(long, "sync_file_range2",
   2947                  int, fd, unsigned int, flags,
   2948                  unsigned, MERGE64_FIRST(offset), unsigned, MERGE64_SECOND(offset),
   2949                  unsigned, MERGE64_FIRST(nbytes), unsigned, MERGE64_SECOND(nbytes));
   2950 #elif VG_WORDSIZE == 8
   2951    PRINT("sys_sync_file_range2 ( %ld, %lu, %ld, %ld )",
   2952          SARG1, ARG2, SARG3, SARG4);
   2953    PRE_REG_READ4(long, "sync_file_range2",
   2954                  int, fd, unsigned int, flags,
   2955                  vki_loff_t, offset, vki_loff_t, nbytes);
   2956 #else
   2957 #  error Unexpected word size
   2958 #endif
   2959    if (!ML_(fd_allowed)(ARG1, "sync_file_range2", tid, False))
   2960       SET_STATUS_Failure( VKI_EBADF );
   2961 }
   2962 
   2963 PRE(sys_stime)
   2964 {
   2965    PRINT("sys_stime ( %#lx )", ARG1);
   2966    PRE_REG_READ1(int, "stime", vki_time_t*, t);
   2967    PRE_MEM_READ( "stime(t)", ARG1, sizeof(vki_time_t) );
   2968 }
   2969 
   2970 PRE(sys_perf_event_open)
   2971 {
   2972    struct vki_perf_event_attr *attr;
   2973    PRINT("sys_perf_event_open ( %#lx, %ld, %ld, %ld, %#lx )",
   2974          ARG1, SARG2, SARG3, SARG4, ARG5);
   2975    PRE_REG_READ5(long, "perf_event_open",
   2976                  struct vki_perf_event_attr *, attr,
   2977                  vki_pid_t, pid, int, cpu, int, group_fd,
   2978                  unsigned long, flags);
   2979    attr = (struct vki_perf_event_attr *)ARG1;
   2980    PRE_MEM_READ( "perf_event_open(attr->size)",
   2981                  (Addr)&attr->size, sizeof(attr->size) );
   2982    PRE_MEM_READ( "perf_event_open(attr)",
   2983                  (Addr)attr, attr->size );
   2984 }
   2985 
   2986 POST(sys_perf_event_open)
   2987 {
   2988    vg_assert(SUCCESS);
   2989    if (!ML_(fd_allowed)(RES, "perf_event_open", tid, True)) {
   2990       VG_(close)(RES);
   2991       SET_STATUS_Failure( VKI_EMFILE );
   2992    } else {
   2993       if (VG_(clo_track_fds))
   2994          ML_(record_fd_open_nameless)(tid, RES);
   2995    }
   2996 }
   2997 
   2998 PRE(sys_getcpu)
   2999 {
   3000    PRINT("sys_getcpu ( %#lx, %#lx, %#lx )" , ARG1,ARG2,ARG3);
   3001    PRE_REG_READ3(int, "getcpu",
   3002                  unsigned *, cpu, unsigned *, node, struct vki_getcpu_cache *, tcache);
   3003    if (ARG1 != 0)
   3004       PRE_MEM_WRITE( "getcpu(cpu)", ARG1, sizeof(unsigned) );
   3005    if (ARG2 != 0)
   3006       PRE_MEM_WRITE( "getcpu(node)", ARG2, sizeof(unsigned) );
   3007    if (ARG3 != 0)
   3008       PRE_MEM_WRITE( "getcpu(tcache)", ARG3, sizeof(struct vki_getcpu_cache) );
   3009 }
   3010 
   3011 POST(sys_getcpu)
   3012 {
   3013    if (ARG1 != 0)
   3014       POST_MEM_WRITE( ARG1, sizeof(unsigned) );
   3015    if (ARG2 != 0)
   3016       POST_MEM_WRITE( ARG2, sizeof(unsigned) );
   3017    if (ARG3 != 0)
   3018       POST_MEM_WRITE( ARG3, sizeof(struct vki_getcpu_cache) );
   3019 }
   3020 
   3021 PRE(sys_move_pages)
   3022 {
   3023    PRINT("sys_move_pages ( %ld, %lu, %#lx, %#lx, %#lx, %#lx )",
   3024          SARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
   3025    PRE_REG_READ6(int, "move_pages",
   3026                  vki_pid_t, pid, unsigned long, nr_pages, const void **, pages,
   3027                  const int *, nodes, int *, status, int, flags);
   3028    PRE_MEM_READ("move_pages(pages)", ARG3, ARG2 * sizeof(void *));
   3029    if (ARG4)
   3030       PRE_MEM_READ("move_pages(nodes)", ARG4, ARG2 * sizeof(int));
   3031    PRE_MEM_WRITE("move_pages(status)", ARG5, ARG2 * sizeof(int));
   3032 }
   3033 
   3034 POST(sys_move_pages)
   3035 {
   3036    POST_MEM_WRITE(ARG5, ARG2 * sizeof(int));
   3037 }
   3038 
   3039 PRE(sys_getrandom)
   3040 {
   3041    PRINT("sys_getrandom ( %#lx, %lu, %lu )" , ARG1, ARG2, ARG3);
   3042    PRE_REG_READ3(int, "getrandom",
   3043                  char *, buf, vki_size_t, count, unsigned int, flags);
   3044    PRE_MEM_WRITE( "getrandom(cpu)", ARG1, ARG2 );
   3045 }
   3046 
   3047 POST(sys_getrandom)
   3048 {
   3049    POST_MEM_WRITE( ARG1, ARG2 );
   3050 }
   3051 
   3052 PRE(sys_memfd_create)
   3053 {
   3054    PRINT("sys_memfd_create ( %#lx, %lu )" , ARG1, ARG2);
   3055    PRE_REG_READ2(int, "memfd_create",
   3056                  char *, uname, unsigned int, flags);
   3057    PRE_MEM_RASCIIZ( "memfd_create(uname)", ARG1 );
   3058 }
   3059 
   3060 POST(sys_memfd_create)
   3061 {
   3062    vg_assert(SUCCESS);
   3063    if (!ML_(fd_allowed)(RES, "memfd_create", tid, True)) {
   3064       VG_(close)(RES);
   3065       SET_STATUS_Failure( VKI_EMFILE );
   3066    } else {
   3067       if (VG_(clo_track_fds))
   3068          ML_(record_fd_open_nameless)(tid, RES);
   3069    }
   3070 }
   3071 
   3072 PRE(sys_syncfs)
   3073 {
   3074    *flags |= SfMayBlock;
   3075    PRINT("sys_syncfs ( %lu )", ARG1);
   3076    PRE_REG_READ1(long, "syncfs", unsigned int, fd);
   3077 }
   3078 
   3079 /* ---------------------------------------------------------------------
   3080    utime wrapper
   3081    ------------------------------------------------------------------ */
   3082 
   3083 PRE(sys_utime)
   3084 {
   3085    *flags |= SfMayBlock;
   3086    PRINT("sys_utime ( %#lx, %#lx )", ARG1,ARG2);
   3087    PRE_REG_READ2(long, "utime", char *, filename, struct utimbuf *, buf);
   3088    PRE_MEM_RASCIIZ( "utime(filename)", ARG1 );
   3089    if (ARG2 != 0)
   3090       PRE_MEM_READ( "utime(buf)", ARG2, sizeof(struct vki_utimbuf) );
   3091 }
   3092 
   3093 /* ---------------------------------------------------------------------
   3094    lseek wrapper
   3095    ------------------------------------------------------------------ */
   3096 
   3097 PRE(sys_lseek)
   3098 {
   3099    PRINT("sys_lseek ( %lu, %ld, %lu )", ARG1, SARG2, ARG3);
   3100    PRE_REG_READ3(vki_off_t, "lseek",
   3101                  unsigned int, fd, vki_off_t, offset, unsigned int, whence);
   3102 }
   3103 
   3104 /* ---------------------------------------------------------------------
   3105    readahead wrapper
   3106    ------------------------------------------------------------------ */
   3107 
   3108 PRE(sys_readahead)
   3109 {
   3110    *flags |= SfMayBlock;
   3111 #if VG_WORDSIZE == 4
   3112    PRINT("sys_readahead ( %ld, %lld, %lu )",
   3113          SARG1, (Long)MERGE64(ARG2,ARG3), ARG4);
   3114    PRE_REG_READ4(vki_off_t, "readahead",
   3115                  int, fd, unsigned, MERGE64_FIRST(offset),
   3116                  unsigned, MERGE64_SECOND(offset), vki_size_t, count);
   3117 #elif VG_WORDSIZE == 8
   3118    PRINT("sys_readahead ( %ld, %ld, %lu )", SARG1, SARG2, ARG3);
   3119    PRE_REG_READ3(vki_off_t, "readahead",
   3120                  int, fd, vki_loff_t, offset, vki_size_t, count);
   3121 #else
   3122 #  error Unexpected word size
   3123 #endif
   3124    if (!ML_(fd_allowed)(ARG1, "readahead", tid, False))
   3125       SET_STATUS_Failure( VKI_EBADF );
   3126 }
   3127 
   3128 /* ---------------------------------------------------------------------
   3129    sig* wrappers
   3130    ------------------------------------------------------------------ */
   3131 
   3132 PRE(sys_sigpending)
   3133 {
   3134    PRINT( "sys_sigpending ( %#lx )", ARG1 );
   3135    PRE_REG_READ1(long, "sigpending", vki_old_sigset_t *, set);
   3136    PRE_MEM_WRITE( "sigpending(set)", ARG1, sizeof(vki_old_sigset_t));
   3137 }
   3138 POST(sys_sigpending)
   3139 {
   3140    POST_MEM_WRITE( ARG1, sizeof(vki_old_sigset_t) ) ;
   3141 }
   3142 
   3143 // This syscall is not used on amd64/Linux -- it only provides
   3144 // sys_rt_sigprocmask, which uses sigset_t rather than old_sigset_t.
   3145 // This wrapper is only suitable for 32-bit architectures.
   3146 // (XXX: so how is it that PRE(sys_sigpending) above doesn't need
   3147 // conditional compilation like this?)
   3148 #if defined(VGP_x86_linux) || defined(VGP_ppc32_linux) \
   3149     || defined(VGP_arm_linux) || defined(VGP_mips32_linux)
   3150 PRE(sys_sigprocmask)
   3151 {
   3152    vki_old_sigset_t* set;
   3153    vki_old_sigset_t* oldset;
   3154    vki_sigset_t bigger_set;
   3155    vki_sigset_t bigger_oldset;
   3156 
   3157    PRINT("sys_sigprocmask ( %ld, %#lx, %#lx )", SARG1, ARG2, ARG3);
   3158    PRE_REG_READ3(long, "sigprocmask",
   3159                  int, how, vki_old_sigset_t *, set, vki_old_sigset_t *, oldset);
   3160    if (ARG2 != 0)
   3161       PRE_MEM_READ( "sigprocmask(set)", ARG2, sizeof(vki_old_sigset_t));
   3162    if (ARG3 != 0)
   3163       PRE_MEM_WRITE( "sigprocmask(oldset)", ARG3, sizeof(vki_old_sigset_t));
   3164 
   3165    // Nb: We must convert the smaller vki_old_sigset_t params into bigger
   3166    // vki_sigset_t params.
   3167    set    = (vki_old_sigset_t*)ARG2;
   3168    oldset = (vki_old_sigset_t*)ARG3;
   3169 
   3170    VG_(memset)(&bigger_set,    0, sizeof(vki_sigset_t));
   3171    VG_(memset)(&bigger_oldset, 0, sizeof(vki_sigset_t));
   3172    if (set)
   3173       bigger_set.sig[0] = *(vki_old_sigset_t*)set;
   3174 
   3175    SET_STATUS_from_SysRes(
   3176       VG_(do_sys_sigprocmask) ( tid, ARG1 /*how*/,
   3177                                 set ? &bigger_set    : NULL,
   3178                              oldset ? &bigger_oldset : NULL)
   3179    );
   3180 
   3181    if (oldset)
   3182       *oldset = bigger_oldset.sig[0];
   3183 
   3184    if (SUCCESS)
   3185       *flags |= SfPollAfter;
   3186 }
   3187 POST(sys_sigprocmask)
   3188 {
   3189    vg_assert(SUCCESS);
   3190    if (RES == 0 && ARG3 != 0)
   3191       POST_MEM_WRITE( ARG3, sizeof(vki_old_sigset_t));
   3192 }
   3193 
   3194 /* Convert from non-RT to RT sigset_t's */
   3195 static
   3196 void convert_sigset_to_rt(const vki_old_sigset_t *oldset, vki_sigset_t *set)
   3197 {
   3198    VG_(sigemptyset)(set);
   3199    set->sig[0] = *oldset;
   3200 }
   3201 PRE(sys_sigaction)
   3202 {
   3203    vki_sigaction_toK_t   new, *newp;
   3204    vki_sigaction_fromK_t old, *oldp;
   3205 
   3206    PRINT("sys_sigaction ( %ld, %#lx, %#lx )",  SARG1, ARG2, ARG3);
   3207    PRE_REG_READ3(int, "sigaction",
   3208                  int, signum, const struct old_sigaction *, act,
   3209                  struct old_sigaction *, oldact);
   3210 
   3211    newp = oldp = NULL;
   3212 
   3213    if (ARG2 != 0) {
   3214       struct vki_old_sigaction *sa = (struct vki_old_sigaction *)ARG2;
   3215       PRE_MEM_READ( "sigaction(act->sa_handler)", (Addr)&sa->ksa_handler, sizeof(sa->ksa_handler));
   3216       PRE_MEM_READ( "sigaction(act->sa_mask)", (Addr)&sa->sa_mask, sizeof(sa->sa_mask));
   3217       PRE_MEM_READ( "sigaction(act->sa_flags)", (Addr)&sa->sa_flags, sizeof(sa->sa_flags));
   3218       if (ML_(safe_to_deref)(sa,sizeof(sa))
   3219           && (sa->sa_flags & VKI_SA_RESTORER))
   3220          PRE_MEM_READ( "sigaction(act->sa_restorer)", (Addr)&sa->sa_restorer, sizeof(sa->sa_restorer));
   3221    }
   3222 
   3223    if (ARG3 != 0) {
   3224       PRE_MEM_WRITE( "sigaction(oldact)", ARG3, sizeof(struct vki_old_sigaction));
   3225       oldp = &old;
   3226    }
   3227 
   3228    if (ARG2 != 0) {
   3229       struct vki_old_sigaction *oldnew = (struct vki_old_sigaction *)ARG2;
   3230 
   3231       new.ksa_handler = oldnew->ksa_handler;
   3232       new.sa_flags = oldnew->sa_flags;
   3233       new.sa_restorer = oldnew->sa_restorer;
   3234       convert_sigset_to_rt(&oldnew->sa_mask, &new.sa_mask);
   3235       newp = &new;
   3236    }
   3237 
   3238    SET_STATUS_from_SysRes( VG_(do_sys_sigaction)(ARG1, newp, oldp) );
   3239 
   3240    if (ARG3 != 0 && SUCCESS && RES == 0) {
   3241       struct vki_old_sigaction *oldold = (struct vki_old_sigaction *)ARG3;
   3242 
   3243       oldold->ksa_handler = oldp->ksa_handler;
   3244       oldold->sa_flags = oldp->sa_flags;
   3245       oldold->sa_restorer = oldp->sa_restorer;
   3246       oldold->sa_mask = oldp->sa_mask.sig[0];
   3247    }
   3248 }
   3249 POST(sys_sigaction)
   3250 {
   3251    vg_assert(SUCCESS);
   3252    if (RES == 0 && ARG3 != 0)
   3253       POST_MEM_WRITE( ARG3, sizeof(struct vki_old_sigaction));
   3254 }
   3255 #endif
   3256 
   3257 PRE(sys_signalfd)
   3258 {
   3259    PRINT("sys_signalfd ( %d, %#lx, %llu )", (Int)ARG1,ARG2,(ULong)ARG3);
   3260    PRE_REG_READ3(long, "sys_signalfd",
   3261                  int, fd, vki_sigset_t *, sigmask, vki_size_t, sigsetsize);
   3262    PRE_MEM_READ( "signalfd(sigmask)", ARG2, sizeof(vki_sigset_t) );
   3263    if ((int)ARG1 != -1 && !ML_(fd_allowed)(ARG1, "signalfd", tid, False))
   3264       SET_STATUS_Failure( VKI_EBADF );
   3265 }
   3266 POST(sys_signalfd)
   3267 {
   3268    if (!ML_(fd_allowed)(RES, "signalfd", tid, True)) {
   3269       VG_(close)(RES);
   3270       SET_STATUS_Failure( VKI_EMFILE );
   3271    } else {
   3272       if (VG_(clo_track_fds))
   3273          ML_(record_fd_open_nameless) (tid, RES);
   3274    }
   3275 }
   3276 
   3277 PRE(sys_signalfd4)
   3278 {
   3279    PRINT("sys_signalfd4 ( %ld, %#lx, %lu, %ld )", SARG1, ARG2, ARG3, SARG4);
   3280    PRE_REG_READ4(long, "sys_signalfd4",
   3281                  int, fd, vki_sigset_t *, sigmask, vki_size_t, sigsetsize, int, flags);
   3282    PRE_MEM_READ( "signalfd(sigmask)", ARG2, sizeof(vki_sigset_t) );
   3283    if ((int)ARG1 != -1 && !ML_(fd_allowed)(ARG1, "signalfd", tid, False))
   3284       SET_STATUS_Failure( VKI_EBADF );
   3285 }
   3286 POST(sys_signalfd4)
   3287 {
   3288    if (!ML_(fd_allowed)(RES, "signalfd4", tid, True)) {
   3289       VG_(close)(RES);
   3290       SET_STATUS_Failure( VKI_EMFILE );
   3291    } else {
   3292       if (VG_(clo_track_fds))
   3293          ML_(record_fd_open_nameless) (tid, RES);
   3294    }
   3295 }
   3296 
   3297 
   3298 /* ---------------------------------------------------------------------
   3299    rt_sig* wrappers
   3300    ------------------------------------------------------------------ */
   3301 
   3302 PRE(sys_rt_sigaction)
   3303 {
   3304    PRINT("sys_rt_sigaction ( %ld, %#lx, %#lx, %lu )", SARG1, ARG2, ARG3, ARG4);
   3305    PRE_REG_READ4(long, "rt_sigaction",
   3306                  int, signum, const struct sigaction *, act,
   3307                  struct sigaction *, oldact, vki_size_t, sigsetsize);
   3308 
   3309    if (ARG2 != 0) {
   3310       vki_sigaction_toK_t *sa = (vki_sigaction_toK_t *)ARG2;
   3311       PRE_MEM_READ( "rt_sigaction(act->sa_handler)", (Addr)&sa->ksa_handler, sizeof(sa->ksa_handler));
   3312       PRE_MEM_READ( "rt_sigaction(act->sa_mask)", (Addr)&sa->sa_mask, sizeof(sa->sa_mask));
   3313       PRE_MEM_READ( "rt_sigaction(act->sa_flags)", (Addr)&sa->sa_flags, sizeof(sa->sa_flags));
   3314       if (sa->sa_flags & VKI_SA_RESTORER)
   3315          PRE_MEM_READ( "rt_sigaction(act->sa_restorer)", (Addr)&sa->sa_restorer, sizeof(sa->sa_restorer));
   3316    }
   3317    if (ARG3 != 0)
   3318       PRE_MEM_WRITE( "rt_sigaction(oldact)", ARG3, sizeof(vki_sigaction_fromK_t));
   3319 
   3320    // XXX: doesn't seem right to be calling do_sys_sigaction for
   3321    // sys_rt_sigaction... perhaps this function should be renamed
   3322    // VG_(do_sys_rt_sigaction)()  --njn
   3323 
   3324    SET_STATUS_from_SysRes(
   3325       VG_(do_sys_sigaction)(ARG1, (const vki_sigaction_toK_t *)ARG2,
   3326                             (vki_sigaction_fromK_t *)ARG3)
   3327    );
   3328 }
   3329 POST(sys_rt_sigaction)
   3330 {
   3331    vg_assert(SUCCESS);
   3332    if (RES == 0 && ARG3 != 0)
   3333       POST_MEM_WRITE( ARG3, sizeof(vki_sigaction_fromK_t));
   3334 }
   3335 
   3336 PRE(sys_rt_sigprocmask)
   3337 {
   3338    PRINT("sys_rt_sigprocmask ( %ld, %#lx, %#lx, %lu )",
   3339          SARG1, ARG2, ARG3, ARG4);
   3340    PRE_REG_READ4(long, "rt_sigprocmask",
   3341                  int, how, vki_sigset_t *, set, vki_sigset_t *, oldset,
   3342                  vki_size_t, sigsetsize);
   3343    if (ARG2 != 0)
   3344       PRE_MEM_READ( "rt_sigprocmask(set)", ARG2, sizeof(vki_sigset_t));
   3345    if (ARG3 != 0)
   3346       PRE_MEM_WRITE( "rt_sigprocmask(oldset)", ARG3, sizeof(vki_sigset_t));
   3347 
   3348    // Like the kernel, we fail if the sigsetsize is not exactly what we expect.
   3349    if (sizeof(vki_sigset_t) != ARG4)
   3350       SET_STATUS_Failure( VKI_EMFILE );
   3351    else {
   3352       SET_STATUS_from_SysRes(
   3353                   VG_(do_sys_sigprocmask) ( tid, ARG1 /*how*/,
   3354                                             (vki_sigset_t*) ARG2,
   3355                                             (vki_sigset_t*) ARG3 )
   3356       );
   3357    }
   3358 
   3359    if (SUCCESS)
   3360       *flags |= SfPollAfter;
   3361 }
   3362 POST(sys_rt_sigprocmask)
   3363 {
   3364    vg_assert(SUCCESS);
   3365    if (RES == 0 && ARG3 != 0)
   3366       POST_MEM_WRITE( ARG3, sizeof(vki_sigset_t));
   3367 }
   3368 
   3369 PRE(sys_rt_sigpending)
   3370 {
   3371    PRINT( "sys_rt_sigpending ( %#lx )", ARG1 );
   3372    PRE_REG_READ2(long, "rt_sigpending",
   3373                  vki_sigset_t *, set, vki_size_t, sigsetsize);
   3374    PRE_MEM_WRITE( "rt_sigpending(set)", ARG1, sizeof(vki_sigset_t));
   3375 }
   3376 POST(sys_rt_sigpending)
   3377 {
   3378    POST_MEM_WRITE( ARG1, sizeof(vki_sigset_t) ) ;
   3379 }
   3380 
   3381 PRE(sys_rt_sigtimedwait)
   3382 {
   3383    *flags |= SfMayBlock;
   3384    PRINT("sys_rt_sigtimedwait ( %#lx, %#lx, %#lx, %lu )",
   3385          ARG1, ARG2, ARG3, ARG4);
   3386    PRE_REG_READ4(long, "rt_sigtimedwait",
   3387                  const vki_sigset_t *, set, vki_siginfo_t *, info,
   3388                  const struct timespec *, timeout, vki_size_t, sigsetsize);
   3389    if (ARG1 != 0)
   3390       PRE_MEM_READ(  "rt_sigtimedwait(set)",  ARG1, sizeof(vki_sigset_t));
   3391    if (ARG2 != 0)
   3392       PRE_MEM_WRITE( "rt_sigtimedwait(info)", ARG2, sizeof(vki_siginfo_t) );
   3393    if (ARG3 != 0)
   3394       PRE_MEM_READ( "rt_sigtimedwait(timeout)",
   3395                     ARG3, sizeof(struct vki_timespec) );
   3396 }
   3397 POST(sys_rt_sigtimedwait)
   3398 {
   3399    if (ARG2 != 0)
   3400       POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) );
   3401 }
   3402 
   3403 PRE(sys_rt_sigqueueinfo)
   3404 {
   3405    PRINT("sys_rt_sigqueueinfo(%ld, %ld, %#lx)", SARG1, SARG2, ARG3);
   3406    PRE_REG_READ3(long, "rt_sigqueueinfo",
   3407                  int, pid, int, sig, vki_siginfo_t *, uinfo);
   3408    if (ARG2 != 0)
   3409       PRE_MEM_READ( "rt_sigqueueinfo(uinfo)", ARG3, VKI_SI_MAX_SIZE );
   3410 }
   3411 POST(sys_rt_sigqueueinfo)
   3412 {
   3413    if (!ML_(client_signal_OK)(ARG2))
   3414       SET_STATUS_Failure( VKI_EINVAL );
   3415 }
   3416 
   3417 PRE(sys_rt_tgsigqueueinfo)
   3418 {
   3419    PRINT("sys_rt_tgsigqueueinfo(%ld, %ld, %ld, %#lx)",
   3420          SARG1, SARG2, SARG3, ARG4);
   3421    PRE_REG_READ4(long, "rt_tgsigqueueinfo",
   3422                  int, tgid, int, pid, int, sig, vki_siginfo_t *, uinfo);
   3423    if (ARG3 != 0)
   3424       PRE_MEM_READ( "rt_tgsigqueueinfo(uinfo)", ARG4, VKI_SI_MAX_SIZE );
   3425 }
   3426 
   3427 POST(sys_rt_tgsigqueueinfo)
   3428 {
   3429    if (!ML_(client_signal_OK)(ARG3))
   3430       SET_STATUS_Failure( VKI_EINVAL );
   3431 }
   3432 
   3433 // XXX: x86-specific?  The kernel prototypes for the different archs are
   3434 //      hard to decipher.
   3435 PRE(sys_rt_sigsuspend)
   3436 {
   3437    /* The C library interface to sigsuspend just takes a pointer to
   3438       a signal mask but this system call has two arguments - a pointer
   3439       to the mask and the number of bytes used by it. The kernel insists
   3440       on the size being equal to sizeof(sigset_t) however and will just
   3441       return EINVAL if it isn't.
   3442     */
   3443    *flags |= SfMayBlock;
   3444    PRINT("sys_rt_sigsuspend ( %#lx, %lu )", ARG1, ARG2 );
   3445    PRE_REG_READ2(int, "rt_sigsuspend", vki_sigset_t *, mask, vki_size_t, size)
   3446    if (ARG1 != (Addr)NULL) {
   3447       PRE_MEM_READ( "rt_sigsuspend(mask)", ARG1, sizeof(vki_sigset_t) );
   3448    }
   3449 }
   3450 
   3451 /* ---------------------------------------------------------------------
   3452    linux msg* wrapper helpers
   3453    ------------------------------------------------------------------ */
   3454 
   3455 void
   3456 ML_(linux_PRE_sys_msgsnd) ( ThreadId tid,
   3457                             UWord arg0, UWord arg1, UWord arg2, UWord arg3 )
   3458 {
   3459    /* int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg); */
   3460    struct vki_msgbuf *msgp = (struct vki_msgbuf *)arg1;
   3461    PRE_MEM_READ( "msgsnd(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) );
   3462    PRE_MEM_READ( "msgsnd(msgp->mtext)", (Addr)&msgp->mtext, arg2 );
   3463 }
   3464 
   3465 void
   3466 ML_(linux_PRE_sys_msgrcv) ( ThreadId tid,
   3467                             UWord arg0, UWord arg1, UWord arg2,
   3468                             UWord arg3, UWord arg4 )
   3469 {
   3470    /* ssize_t msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz,
   3471                      long msgtyp, int msgflg); */
   3472    struct vki_msgbuf *msgp = (struct vki_msgbuf *)arg1;
   3473    PRE_MEM_WRITE( "msgrcv(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) );
   3474    PRE_MEM_WRITE( "msgrcv(msgp->mtext)", (Addr)&msgp->mtext, arg2 );
   3475 }
   3476 void
   3477 ML_(linux_POST_sys_msgrcv) ( ThreadId tid,
   3478                              UWord res,
   3479                              UWord arg0, UWord arg1, UWord arg2,
   3480                              UWord arg3, UWord arg4 )
   3481 {
   3482    struct vki_msgbuf *msgp = (struct vki_msgbuf *)arg1;
   3483    POST_MEM_WRITE( (Addr)&msgp->mtype, sizeof(msgp->mtype) );
   3484    POST_MEM_WRITE( (Addr)&msgp->mtext, res );
   3485 }
   3486 
   3487 void
   3488 ML_(linux_PRE_sys_msgctl) ( ThreadId tid,
   3489                             UWord arg0, UWord arg1, UWord arg2 )
   3490 {
   3491    /* int msgctl(int msqid, int cmd, struct msqid_ds *buf); */
   3492    switch (arg1 /* cmd */) {
   3493    case VKI_IPC_INFO:
   3494    case VKI_MSG_INFO:
   3495    case VKI_IPC_INFO|VKI_IPC_64:
   3496    case VKI_MSG_INFO|VKI_IPC_64:
   3497       PRE_MEM_WRITE( "msgctl(IPC_INFO, buf)",
   3498                      arg2, sizeof(struct vki_msginfo) );
   3499       break;
   3500    case VKI_IPC_STAT:
   3501    case VKI_MSG_STAT:
   3502       PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)",
   3503                      arg2, sizeof(struct vki_msqid_ds) );
   3504       break;
   3505    case VKI_IPC_STAT|VKI_IPC_64:
   3506    case VKI_MSG_STAT|VKI_IPC_64:
   3507       PRE_MEM_WRITE( "msgctl(IPC_STAT, arg.buf)",
   3508                      arg2, sizeof(struct vki_msqid64_ds) );
   3509       break;
   3510    case VKI_IPC_SET:
   3511       PRE_MEM_READ( "msgctl(IPC_SET, arg.buf)",
   3512                     arg2, sizeof(struct vki_msqid_ds) );
   3513       break;
   3514    case VKI_IPC_SET|VKI_IPC_64:
   3515       PRE_MEM_READ( "msgctl(IPC_SET, arg.buf)",
   3516                     arg2, sizeof(struct vki_msqid64_ds) );
   3517       break;
   3518    }
   3519 }
   3520 void
   3521 ML_(linux_POST_sys_msgctl) ( ThreadId tid,
   3522                              UWord res,
   3523                              UWord arg0, UWord arg1, UWord arg2 )
   3524 {
   3525    switch (arg1 /* cmd */) {
   3526    case VKI_IPC_INFO:
   3527    case VKI_MSG_INFO:
   3528    case VKI_IPC_INFO|VKI_IPC_64:
   3529    case VKI_MSG_INFO|VKI_IPC_64:
   3530       POST_MEM_WRITE( arg2, sizeof(struct vki_msginfo) );
   3531       break;
   3532    case VKI_IPC_STAT:
   3533    case VKI_MSG_STAT:
   3534       POST_MEM_WRITE( arg2, sizeof(struct vki_msqid_ds) );
   3535       break;
   3536    case VKI_IPC_STAT|VKI_IPC_64:
   3537    case VKI_MSG_STAT|VKI_IPC_64:
   3538       POST_MEM_WRITE( arg2, sizeof(struct vki_msqid64_ds) );
   3539       break;
   3540    }
   3541 }
   3542 
   3543 /* ---------------------------------------------------------------------
   3544    Generic handler for sys_ipc
   3545    Depending on the platform, some syscalls (e.g. semctl, semop, ...)
   3546    are either direct system calls, or are all implemented via sys_ipc.
   3547    ------------------------------------------------------------------ */
   3548 #ifdef __NR_ipc
   3549 static Addr deref_Addr ( ThreadId tid, Addr a, const HChar* s )
   3550 {
   3551    Addr* a_p = (Addr*)a;
   3552    PRE_MEM_READ( s, (Addr)a_p, sizeof(Addr) );
   3553    return *a_p;
   3554 }
   3555 
   3556 static Bool semctl_cmd_has_4args (UWord cmd)
   3557 {
   3558    switch (cmd & ~VKI_IPC_64)
   3559    {
   3560    case VKI_IPC_INFO:
   3561    case VKI_SEM_INFO:
   3562    case VKI_IPC_STAT:
   3563    case VKI_SEM_STAT:
   3564    case VKI_IPC_SET:
   3565    case VKI_GETALL:
   3566    case VKI_SETALL:
   3567       return True;
   3568    default:
   3569       return False;
   3570    }
   3571 }
   3572 
   3573 PRE(sys_ipc)
   3574 {
   3575    PRINT("sys_ipc ( %lu, %ld, %ld, %ld, %#lx, %ld )",
   3576          ARG1, SARG2, SARG3, SARG4, ARG5, SARG6);
   3577 
   3578    switch (ARG1 /* call */) {
   3579    case VKI_SEMOP:
   3580       PRE_REG_READ5(int, "ipc",
   3581                     vki_uint, call, int, first, int, second, int, third,
   3582                     void *, ptr);
   3583       ML_(generic_PRE_sys_semop)( tid, ARG2, ARG5, ARG3 );
   3584       *flags |= SfMayBlock;
   3585       break;
   3586    case VKI_SEMGET:
   3587       PRE_REG_READ4(int, "ipc",
   3588                     vki_uint, call, int, first, int, second, int, third);
   3589       break;
   3590    case VKI_SEMCTL:
   3591    {
   3592       PRE_REG_READ5(int, "ipc",
   3593                     vki_uint, call, int, first, int, second, int, third,
   3594                     void *, ptr);
   3595       UWord arg;
   3596       if (semctl_cmd_has_4args(ARG4))
   3597          arg = deref_Addr( tid, ARG5, "semctl(arg)" );
   3598       else
   3599          arg = 0;
   3600       ML_(generic_PRE_sys_semctl)( tid, ARG2, ARG3, ARG4, arg );
   3601       break;
   3602    }
   3603    case VKI_SEMTIMEDOP:
   3604       PRE_REG_READ6(int, "ipc",
   3605                     vki_uint, call, int, first, int, second, int, third,
   3606                     void *, ptr, long, fifth);
   3607       ML_(generic_PRE_sys_semtimedop)( tid, ARG2, ARG5, ARG3, ARG6 );
   3608       *flags |= SfMayBlock;
   3609       break;
   3610    case VKI_MSGSND:
   3611       PRE_REG_READ5(int, "ipc",
   3612                     vki_uint, call, int, first, int, second, int, third,
   3613                     void *, ptr);
   3614       ML_(linux_PRE_sys_msgsnd)( tid, ARG2, ARG5, ARG3, ARG4 );
   3615       if ((ARG4 & VKI_IPC_NOWAIT) == 0)
   3616          *flags |= SfMayBlock;
   3617       break;
   3618    case VKI_MSGRCV:
   3619    {
   3620       PRE_REG_READ5(int, "ipc",
   3621                     vki_uint, call, int, first, int, second, int, third,
   3622                     void *, ptr);
   3623       Addr msgp;
   3624       Word msgtyp;
   3625 
   3626       msgp = deref_Addr( tid, (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgp),
   3627                          "msgrcv(msgp)" );
   3628       msgtyp = deref_Addr( tid,
   3629                            (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgtyp),
   3630                            "msgrcv(msgp)" );
   3631 
   3632       ML_(linux_PRE_sys_msgrcv)( tid, ARG2, msgp, ARG3, msgtyp, ARG4 );
   3633 
   3634       if ((ARG4 & VKI_IPC_NOWAIT) == 0)
   3635          *flags |= SfMayBlock;
   3636       break;
   3637    }
   3638    case VKI_MSGGET:
   3639       PRE_REG_READ3(int, "ipc", vki_uint, call, int, first, int, second);
   3640       break;
   3641    case VKI_MSGCTL:
   3642       PRE_REG_READ5(int, "ipc",
   3643                     vki_uint, call, int, first, int, second, int, third,
   3644                     void *, ptr);
   3645       ML_(linux_PRE_sys_msgctl)( tid, ARG2, ARG3, ARG5 );
   3646       break;
   3647    case VKI_SHMAT:
   3648    {
   3649       PRE_REG_READ5(int, "ipc",
   3650                     vki_uint, call, int, first, int, second, int, third,
   3651                     void *, ptr);
   3652       UWord w;
   3653       PRE_MEM_WRITE( "shmat(raddr)", ARG4, sizeof(Addr) );
   3654       w = ML_(generic_PRE_sys_shmat)( tid, ARG2, ARG5, ARG3 );
   3655       if (w == 0)
   3656          SET_STATUS_Failure( VKI_EINVAL );
   3657       else
   3658          ARG5 = w;
   3659       break;
   3660    }
   3661    case VKI_SHMDT:
   3662       PRE_REG_READ5(int, "ipc",
   3663                     vki_uint, call, int, first, int, second, int, third,
   3664                     void *, ptr);
   3665       if (!ML_(generic_PRE_sys_shmdt)(tid, ARG5))
   3666 	 SET_STATUS_Failure( VKI_EINVAL );
   3667       break;
   3668    case VKI_SHMGET:
   3669       PRE_REG_READ4(int, "ipc",
   3670                     vki_uint, call, int, first, int, second, int, third);
   3671       if (ARG4 & VKI_SHM_HUGETLB) {
   3672          static Bool warning_given = False;
   3673          ARG4 &= ~VKI_SHM_HUGETLB;
   3674          if (!warning_given) {
   3675             warning_given = True;
   3676             VG_(umsg)(
   3677                "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n");
   3678          }
   3679       }
   3680       break;
   3681    case VKI_SHMCTL: /* IPCOP_shmctl */
   3682       PRE_REG_READ5(int, "ipc",
   3683                     vki_uint, call, int, first, int, second, int, third,
   3684                     void *, ptr);
   3685       ML_(generic_PRE_sys_shmctl)( tid, ARG2, ARG3, ARG5 );
   3686       break;
   3687    default:
   3688       VG_(message)(Vg_DebugMsg, "FATAL: unhandled syscall(ipc) %lu\n", ARG1 );
   3689       VG_(core_panic)("... bye!\n");
   3690       break; /*NOTREACHED*/
   3691    }
   3692 }
   3693 
   3694 POST(sys_ipc)
   3695 {
   3696    vg_assert(SUCCESS);
   3697    switch (ARG1 /* call */) {
   3698    case VKI_SEMOP:
   3699    case VKI_SEMGET:
   3700       break;
   3701    case VKI_SEMCTL:
   3702    {
   3703       UWord arg;
   3704       if (semctl_cmd_has_4args(ARG4))
   3705          arg = deref_Addr( tid, ARG5, "semctl(arg)" );
   3706       else
   3707          arg = 0;
   3708       ML_(generic_POST_sys_semctl)( tid, RES, ARG2, ARG3, ARG4, arg );
   3709       break;
   3710    }
   3711    case VKI_SEMTIMEDOP:
   3712    case VKI_MSGSND:
   3713       break;
   3714    case VKI_MSGRCV:
   3715    {
   3716       Addr msgp;
   3717       Word msgtyp;
   3718 
   3719       msgp = deref_Addr( tid,
   3720 			 (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgp),
   3721 			 "msgrcv(msgp)" );
   3722       msgtyp = deref_Addr( tid,
   3723 			   (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgtyp),
   3724 			   "msgrcv(msgp)" );
   3725 
   3726       ML_(linux_POST_sys_msgrcv)( tid, RES, ARG2, msgp, ARG3, msgtyp, ARG4 );
   3727       break;
   3728    }
   3729    case VKI_MSGGET:
   3730       break;
   3731    case VKI_MSGCTL:
   3732       ML_(linux_POST_sys_msgctl)( tid, RES, ARG2, ARG3, ARG5 );
   3733       break;
   3734    case VKI_SHMAT:
   3735    {
   3736       Addr addr;
   3737 
   3738       /* force readability. before the syscall it is
   3739        * indeed uninitialized, as can be seen in
   3740        * glibc/sysdeps/unix/sysv/linux/shmat.c */
   3741       POST_MEM_WRITE( ARG4, sizeof( Addr ) );
   3742 
   3743       addr = deref_Addr ( tid, ARG4, "shmat(addr)" );
   3744       ML_(generic_POST_sys_shmat)( tid, addr, ARG2, ARG5, ARG3 );
   3745       break;
   3746    }
   3747    case VKI_SHMDT:
   3748       ML_(generic_POST_sys_shmdt)( tid, RES, ARG5 );
   3749       break;
   3750    case VKI_SHMGET:
   3751       break;
   3752    case VKI_SHMCTL:
   3753       ML_(generic_POST_sys_shmctl)( tid, RES, ARG2, ARG3, ARG5 );
   3754       break;
   3755    default:
   3756       VG_(message)(Vg_DebugMsg,
   3757 		   "FATAL: unhandled syscall(ipc) %lu\n",
   3758 		   ARG1 );
   3759       VG_(core_panic)("... bye!\n");
   3760       break; /*NOTREACHED*/
   3761    }
   3762 }
   3763 #endif
   3764 
   3765 PRE(sys_semget)
   3766 {
   3767    PRINT("sys_semget ( %ld, %ld, %ld )", SARG1, SARG2, SARG3);
   3768    PRE_REG_READ3(long, "semget", vki_key_t, key, int, nsems, int, semflg);
   3769 }
   3770 
   3771 PRE(sys_semop)
   3772 {
   3773    *flags |= SfMayBlock;
   3774    PRINT("sys_semop ( %ld, %#lx, %lu )", SARG1, ARG2, ARG3);
   3775    PRE_REG_READ3(long, "semop",
   3776                  int, semid, struct sembuf *, sops, unsigned, nsoops);
   3777    ML_(generic_PRE_sys_semop)(tid, ARG1,ARG2,ARG3);
   3778 }
   3779 
   3780 PRE(sys_semctl)
   3781 {
   3782    switch (ARG3 & ~VKI_IPC_64) {
   3783    case VKI_IPC_INFO:
   3784    case VKI_SEM_INFO:
   3785       PRINT("sys_semctl ( %ld, %ld, %ld, %#lx )", SARG1, SARG2, SARG3, ARG4);
   3786       PRE_REG_READ4(long, "semctl",
   3787                     int, semid, int, semnum, int, cmd, struct seminfo *, arg);
   3788       break;
   3789    case VKI_IPC_STAT:
   3790    case VKI_SEM_STAT:
   3791    case VKI_IPC_SET:
   3792       PRINT("sys_semctl ( %ld, %ld, %ld, %#lx )", SARG1, SARG2, SARG3, ARG4);
   3793       PRE_REG_READ4(long, "semctl",
   3794                     int, semid, int, semnum, int, cmd, struct semid_ds *, arg);
   3795       break;
   3796    case VKI_GETALL:
   3797    case VKI_SETALL:
   3798       PRINT("sys_semctl ( %ld, %ld, %ld, %#lx )", SARG1, SARG2, SARG3, ARG4);
   3799       PRE_REG_READ4(long, "semctl",
   3800                     int, semid, int, semnum, int, cmd, unsigned short *, arg);
   3801       break;
   3802    default:
   3803       PRINT("sys_semctl ( %ld, %ld, %ld )", SARG1, SARG2, SARG3);
   3804       PRE_REG_READ3(long, "semctl",
   3805                     int, semid, int, semnum, int, cmd);
   3806       break;
   3807    }
   3808 #ifdef VGP_amd64_linux
   3809    ML_(generic_PRE_sys_semctl)(tid, ARG1,ARG2,ARG3|VKI_IPC_64,ARG4);
   3810 #else
   3811    ML_(generic_PRE_sys_semctl)(tid, ARG1,ARG2,ARG3,ARG4);
   3812 #endif
   3813 }
   3814 
   3815 POST(sys_semctl)
   3816 {
   3817 #ifdef VGP_amd64_linux
   3818    ML_(generic_POST_sys_semctl)(tid, RES,ARG1,ARG2,ARG3|VKI_IPC_64,ARG4);
   3819 #else
   3820    ML_(generic_POST_sys_semctl)(tid, RES,ARG1,ARG2,ARG3,ARG4);
   3821 #endif
   3822 }
   3823 
   3824 PRE(sys_semtimedop)
   3825 {
   3826    *flags |= SfMayBlock;
   3827    PRINT("sys_semtimedop ( %ld, %#lx, %lu, %#lx )", SARG1, ARG2, ARG3, ARG4);
   3828    PRE_REG_READ4(long, "semtimedop",
   3829                  int, semid, struct sembuf *, sops, unsigned, nsoops,
   3830                  struct timespec *, timeout);
   3831    ML_(generic_PRE_sys_semtimedop)(tid, ARG1,ARG2,ARG3,ARG4);
   3832 }
   3833 
   3834 PRE(sys_msgget)
   3835 {
   3836    PRINT("sys_msgget ( %ld, %ld )", SARG1, SARG2);
   3837    PRE_REG_READ2(long, "msgget", vki_key_t, key, int, msgflg);
   3838 }
   3839 
   3840 PRE(sys_msgsnd)
   3841 {
   3842    PRINT("sys_msgsnd ( %ld, %#lx, %lu, %ld )", SARG1, ARG2, ARG3, SARG4);
   3843    PRE_REG_READ4(long, "msgsnd",
   3844                  int, msqid, struct msgbuf *, msgp, vki_size_t, msgsz, int, msgflg);
   3845    ML_(linux_PRE_sys_msgsnd)(tid, ARG1,ARG2,ARG3,ARG4);
   3846    if ((ARG4 & VKI_IPC_NOWAIT) == 0)
   3847       *flags |= SfMayBlock;
   3848 }
   3849 
   3850 PRE(sys_msgrcv)
   3851 {
   3852    PRINT("sys_msgrcv ( %ld, %#lx, %lu, %ld, %ld )",
   3853          SARG1, ARG2, ARG3, SARG4, SARG5);
   3854    PRE_REG_READ5(long, "msgrcv",
   3855                  int, msqid, struct msgbuf *, msgp, vki_size_t, msgsz,
   3856                  long, msgytp, int, msgflg);
   3857    ML_(linux_PRE_sys_msgrcv)(tid, ARG1,ARG2,ARG3,ARG4,ARG5);
   3858    if ((ARG5 & VKI_IPC_NOWAIT) == 0)
   3859       *flags |= SfMayBlock;
   3860 }
   3861 POST(sys_msgrcv)
   3862 {
   3863    ML_(linux_POST_sys_msgrcv)(tid, RES,ARG1,ARG2,ARG3,ARG4,ARG5);
   3864 }
   3865 
   3866 PRE(sys_msgctl)
   3867 {
   3868    PRINT("sys_msgctl ( %ld, %ld, %#lx )", SARG1, SARG2, ARG3);
   3869    PRE_REG_READ3(long, "msgctl",
   3870                  int, msqid, int, cmd, struct msqid_ds *, buf);
   3871    ML_(linux_PRE_sys_msgctl)(tid, ARG1,ARG2,ARG3);
   3872 }
   3873 
   3874 POST(sys_msgctl)
   3875 {
   3876    ML_(linux_POST_sys_msgctl)(tid, RES,ARG1,ARG2,ARG3);
   3877 }
   3878 
   3879 PRE(sys_shmget)
   3880 {
   3881    PRINT("sys_shmget ( %ld, %lu, %ld )", SARG1, ARG2, SARG3);
   3882    PRE_REG_READ3(long, "shmget", vki_key_t, key, vki_size_t, size, int, shmflg);
   3883    if (ARG3 & VKI_SHM_HUGETLB) {
   3884       static Bool warning_given = False;
   3885       ARG3 &= ~VKI_SHM_HUGETLB;
   3886       if (!warning_given) {
   3887          warning_given = True;
   3888          VG_(umsg)(
   3889             "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n");
   3890       }
   3891    }
   3892 }
   3893 
   3894 PRE(wrap_sys_shmat)
   3895 {
   3896    UWord arg2tmp;
   3897    PRINT("wrap_sys_shmat ( %ld, %#lx, %ld )", SARG1, ARG2, SARG3);
   3898    PRE_REG_READ3(long, "shmat",
   3899                  int, shmid, const void *, shmaddr, int, shmflg);
   3900 #if defined(VGP_arm_linux)
   3901    /* Round the attach address down to an VKI_SHMLBA boundary if the
   3902       client requested rounding.  See #222545.  This is necessary only
   3903       on arm-linux because VKI_SHMLBA is 4 * VKI_PAGE size; on all
   3904       other linux targets it is the same as the page size. */
   3905    if (ARG3 & VKI_SHM_RND)
   3906       ARG2 = VG_ROUNDDN(ARG2, VKI_SHMLBA);
   3907 #endif
   3908    arg2tmp = ML_(generic_PRE_sys_shmat)(tid, ARG1,ARG2,ARG3);
   3909    if (arg2tmp == 0)
   3910       SET_STATUS_Failure( VKI_EINVAL );
   3911    else
   3912       ARG2 = arg2tmp;  // used in POST
   3913 }
   3914 
   3915 POST(wrap_sys_shmat)
   3916 {
   3917    ML_(generic_POST_sys_shmat)(tid, RES,ARG1,ARG2,ARG3);
   3918 }
   3919 
   3920 PRE(sys_shmdt)
   3921 {
   3922    PRINT("sys_shmdt ( %#lx )",ARG1);
   3923    PRE_REG_READ1(long, "shmdt", const void *, shmaddr);
   3924    if (!ML_(generic_PRE_sys_shmdt)(tid, ARG1))
   3925       SET_STATUS_Failure( VKI_EINVAL );
   3926 }
   3927 
   3928 POST(sys_shmdt)
   3929 {
   3930    ML_(generic_POST_sys_shmdt)(tid, RES,ARG1);
   3931 }
   3932 
   3933 PRE(sys_shmctl)
   3934 {
   3935    PRINT("sys_shmctl ( %ld, %ld, %#lx )", SARG1, SARG2, ARG3);
   3936    PRE_REG_READ3(long, "shmctl",
   3937                  int, shmid, int, cmd, struct shmid_ds *, buf);
   3938 #ifdef VGP_amd64_linux
   3939    ML_(generic_PRE_sys_shmctl)(tid, ARG1,ARG2|VKI_IPC_64,ARG3);
   3940 #else
   3941    ML_(generic_PRE_sys_shmctl)(tid, ARG1,ARG2,ARG3);
   3942 #endif
   3943 }
   3944 
   3945 POST(sys_shmctl)
   3946 {
   3947 #ifdef VGP_amd64_linux
   3948    ML_(generic_POST_sys_shmctl)(tid, RES,ARG1,ARG2|VKI_IPC_64,ARG3);
   3949 #else
   3950    ML_(generic_POST_sys_shmctl)(tid, RES,ARG1,ARG2,ARG3);
   3951 #endif
   3952 }
   3953 
   3954 
   3955 /* ---------------------------------------------------------------------
   3956    Generic handler for sys_socketcall
   3957    Depending on the platform, some socket related syscalls (e.g. socketpair,
   3958    socket, bind, ...)
   3959    are either direct system calls, or are all implemented via sys_socketcall.
   3960    ------------------------------------------------------------------ */
   3961 #ifdef __NR_socketcall
   3962 PRE(sys_socketcall)
   3963 {
   3964 #  define ARG2_0  (((UWord*)ARG2)[0])
   3965 #  define ARG2_1  (((UWord*)ARG2)[1])
   3966 #  define ARG2_2  (((UWord*)ARG2)[2])
   3967 #  define ARG2_3  (((UWord*)ARG2)[3])
   3968 #  define ARG2_4  (((UWord*)ARG2)[4])
   3969 #  define ARG2_5  (((UWord*)ARG2)[5])
   3970 
   3971 // call PRE_MEM_READ and check for EFAULT result.
   3972 #define PRE_MEM_READ_ef(msg, arg, size)                         \
   3973    {                                                            \
   3974       PRE_MEM_READ( msg, arg, size);                            \
   3975       if (!ML_(valid_client_addr)(arg, size, tid, NULL)) {      \
   3976          SET_STATUS_Failure( VKI_EFAULT );                      \
   3977          break;                                                 \
   3978       }                                                         \
   3979    }
   3980 
   3981    *flags |= SfMayBlock;
   3982    PRINT("sys_socketcall ( %ld, %#lx )", SARG1, ARG2);
   3983    PRE_REG_READ2(long, "socketcall", int, call, unsigned long *, args);
   3984 
   3985    switch (ARG1 /* request */) {
   3986 
   3987    case VKI_SYS_SOCKETPAIR:
   3988       /* int socketpair(int d, int type, int protocol, int sv[2]); */
   3989       PRE_MEM_READ_ef( "socketcall.socketpair(args)", ARG2, 4*sizeof(Addr) );
   3990       ML_(generic_PRE_sys_socketpair)( tid, ARG2_0, ARG2_1, ARG2_2, ARG2_3 );
   3991       break;
   3992 
   3993    case VKI_SYS_SOCKET:
   3994       /* int socket(int domain, int type, int protocol); */
   3995       PRE_MEM_READ_ef( "socketcall.socket(args)", ARG2, 3*sizeof(Addr) );
   3996       break;
   3997 
   3998    case VKI_SYS_BIND:
   3999       /* int bind(int sockfd, struct sockaddr *my_addr,
   4000                   int addrlen); */
   4001       PRE_MEM_READ_ef( "socketcall.bind(args)", ARG2, 3*sizeof(Addr) );
   4002       ML_(generic_PRE_sys_bind)( tid, ARG2_0, ARG2_1, ARG2_2 );
   4003       break;
   4004 
   4005    case VKI_SYS_LISTEN:
   4006       /* int listen(int s, int backlog); */
   4007       PRE_MEM_READ_ef( "socketcall.listen(args)", ARG2, 2*sizeof(Addr) );
   4008       break;
   4009 
   4010    case VKI_SYS_ACCEPT:
   4011       /* int accept(int s, struct sockaddr *addr, int *addrlen); */
   4012       PRE_MEM_READ_ef( "socketcall.accept(args)", ARG2, 3*sizeof(Addr) );
   4013       ML_(generic_PRE_sys_accept)( tid, ARG2_0, ARG2_1, ARG2_2 );
   4014       break;
   4015 
   4016    case VKI_SYS_ACCEPT4:
   4017       /* int accept4(int s, struct sockaddr *addr, int *addrlen, int flags); */
   4018       PRE_MEM_READ_ef( "socketcall.accept4(args)", ARG2, 4*sizeof(Addr) );
   4019       ML_(generic_PRE_sys_accept)( tid, ARG2_0, ARG2_1, ARG2_2 );
   4020       break;
   4021 
   4022    case VKI_SYS_SENDTO:
   4023       /* int sendto(int s, const void *msg, int len,
   4024                     unsigned int flags,
   4025                     const struct sockaddr *to, int tolen); */
   4026       PRE_MEM_READ_ef( "socketcall.sendto(args)", ARG2, 6*sizeof(Addr) );
   4027       ML_(generic_PRE_sys_sendto)( tid, ARG2_0, ARG2_1, ARG2_2,
   4028                                    ARG2_3, ARG2_4, ARG2_5 );
   4029       break;
   4030 
   4031    case VKI_SYS_SEND:
   4032       /* int send(int s, const void *msg, size_t len, int flags); */
   4033       PRE_MEM_READ_ef( "socketcall.send(args)", ARG2, 4*sizeof(Addr) );
   4034       ML_(generic_PRE_sys_send)( tid, ARG2_0, ARG2_1, ARG2_2 );
   4035       break;
   4036 
   4037    case VKI_SYS_RECVFROM:
   4038       /* int recvfrom(int s, void *buf, int len, unsigned int flags,
   4039          struct sockaddr *from, int *fromlen); */
   4040       PRE_MEM_READ_ef( "socketcall.recvfrom(args)", ARG2, 6*sizeof(Addr) );
   4041       ML_(generic_PRE_sys_recvfrom)( tid, ARG2_0, ARG2_1, ARG2_2,
   4042                                      ARG2_3, ARG2_4, ARG2_5 );
   4043       break;
   4044 
   4045    case VKI_SYS_RECV:
   4046       /* int recv(int s, void *buf, int len, unsigned int flags); */
   4047       /* man 2 recv says:
   4048          The  recv call is normally used only on a connected socket
   4049          (see connect(2)) and is identical to recvfrom with a  NULL
   4050          from parameter.
   4051       */
   4052       PRE_MEM_READ_ef( "socketcall.recv(args)", ARG2, 4*sizeof(Addr) );
   4053       ML_(generic_PRE_sys_recv)( tid, ARG2_0, ARG2_1, ARG2_2 );
   4054       break;
   4055 
   4056    case VKI_SYS_CONNECT:
   4057       /* int connect(int sockfd,
   4058                      struct sockaddr *serv_addr, int addrlen ); */
   4059       PRE_MEM_READ_ef( "socketcall.connect(args)", ARG2, 3*sizeof(Addr) );
   4060       ML_(generic_PRE_sys_connect)( tid, ARG2_0, ARG2_1, ARG2_2 );
   4061       break;
   4062 
   4063    case VKI_SYS_SETSOCKOPT:
   4064       /* int setsockopt(int s, int level, int optname,
   4065                         const void *optval, int optlen); */
   4066       PRE_MEM_READ_ef( "socketcall.setsockopt(args)", ARG2, 5*sizeof(Addr) );
   4067       ML_(linux_PRE_sys_setsockopt)( tid, ARG2_0, ARG2_1, ARG2_2,
   4068                                      ARG2_3, ARG2_4 );
   4069       break;
   4070 
   4071    case VKI_SYS_GETSOCKOPT:
   4072       /* int getsockopt(int s, int level, int optname,
   4073                         void *optval, socklen_t *optlen); */
   4074       PRE_MEM_READ_ef( "socketcall.getsockopt(args)", ARG2, 5*sizeof(Addr) );
   4075       ML_(linux_PRE_sys_getsockopt)( tid, ARG2_0, ARG2_1, ARG2_2,
   4076                                      ARG2_3, ARG2_4 );
   4077       break;
   4078 
   4079    case VKI_SYS_GETSOCKNAME:
   4080       /* int getsockname(int s, struct sockaddr* name, int* namelen) */
   4081       PRE_MEM_READ_ef( "socketcall.getsockname(args)", ARG2, 3*sizeof(Addr) );
   4082       ML_(generic_PRE_sys_getsockname)( tid, ARG2_0, ARG2_1, ARG2_2 );
   4083       break;
   4084 
   4085    case VKI_SYS_GETPEERNAME:
   4086       /* int getpeername(int s, struct sockaddr* name, int* namelen) */
   4087       PRE_MEM_READ_ef( "socketcall.getpeername(args)", ARG2, 3*sizeof(Addr) );
   4088       ML_(generic_PRE_sys_getpeername)( tid, ARG2_0, ARG2_1, ARG2_2 );
   4089       break;
   4090 
   4091    case VKI_SYS_SHUTDOWN:
   4092       /* int shutdown(int s, int how); */
   4093       PRE_MEM_READ_ef( "socketcall.shutdown(args)", ARG2, 2*sizeof(Addr) );
   4094       break;
   4095 
   4096    case VKI_SYS_SENDMSG:
   4097       /* int sendmsg(int s, const struct msghdr *msg, int flags); */
   4098       PRE_MEM_READ_ef( "socketcall.sendmsg(args)", ARG2, 3*sizeof(Addr) );
   4099       ML_(generic_PRE_sys_sendmsg)( tid, "msg", (struct vki_msghdr *)ARG2_1 );
   4100       break;
   4101 
   4102    case VKI_SYS_RECVMSG:
   4103       /* int recvmsg(int s, struct msghdr *msg, int flags); */
   4104       PRE_MEM_READ_ef("socketcall.recvmsg(args)", ARG2, 3*sizeof(Addr) );
   4105       ML_(generic_PRE_sys_recvmsg)( tid, "msg", (struct vki_msghdr *)ARG2_1 );
   4106       break;
   4107 
   4108    case VKI_SYS_RECVMMSG:
   4109       /* int recvmmsg(int s, struct mmsghdr *mmsg, int vlen, int flags,
   4110                       struct timespec *timeout); */
   4111       PRE_MEM_READ_ef("socketcall.recvmmsg(args)", ARG2, 5*sizeof(Addr) );
   4112       ML_(linux_PRE_sys_recvmmsg)( tid, ARG2_0, ARG2_1, ARG2_2, ARG2_3,
   4113                                    ARG2_4 );
   4114       break;
   4115 
   4116    case VKI_SYS_SENDMMSG:
   4117       /* int sendmmsg(int s, struct mmsghdr *mmsg, int vlen, int flags); */
   4118       PRE_MEM_READ_ef("socketcall.sendmmsg(args)", ARG2, 4*sizeof(Addr) );
   4119       ML_(linux_PRE_sys_sendmmsg)( tid, ARG2_0, ARG2_1, ARG2_2, ARG2_3 );
   4120       break;
   4121 
   4122    default:
   4123       VG_(message)(Vg_DebugMsg,"Warning: unhandled socketcall 0x%lx\n",ARG1);
   4124       SET_STATUS_Failure( VKI_EINVAL );
   4125       break;
   4126    }
   4127 #  undef ARG2_0
   4128 #  undef ARG2_1
   4129 #  undef ARG2_2
   4130 #  undef ARG2_3
   4131 #  undef ARG2_4
   4132 #  undef ARG2_5
   4133 }
   4134 
   4135 POST(sys_socketcall)
   4136 {
   4137 #  define ARG2_0  (((UWord*)ARG2)[0])
   4138 #  define ARG2_1  (((UWord*)ARG2)[1])
   4139 #  define ARG2_2  (((UWord*)ARG2)[2])
   4140 #  define ARG2_3  (((UWord*)ARG2)[3])
   4141 #  define ARG2_4  (((UWord*)ARG2)[4])
   4142 #  define ARG2_5  (((UWord*)ARG2)[5])
   4143 
   4144    SysRes r;
   4145    vg_assert(SUCCESS);
   4146    switch (ARG1 /* request */) {
   4147 
   4148    case VKI_SYS_SOCKETPAIR:
   4149       r = ML_(generic_POST_sys_socketpair)(
   4150              tid, VG_(mk_SysRes_Success)(RES),
   4151              ARG2_0, ARG2_1, ARG2_2, ARG2_3
   4152           );
   4153       SET_STATUS_from_SysRes(r);
   4154       break;
   4155 
   4156    case VKI_SYS_SOCKET:
   4157       r = ML_(generic_POST_sys_socket)( tid, VG_(mk_SysRes_Success)(RES) );
   4158       SET_STATUS_from_SysRes(r);
   4159       break;
   4160 
   4161    case VKI_SYS_BIND:
   4162       /* int bind(int sockfd, struct sockaddr *my_addr,
   4163 			int addrlen); */
   4164       break;
   4165 
   4166    case VKI_SYS_LISTEN:
   4167       /* int listen(int s, int backlog); */
   4168       break;
   4169 
   4170    case VKI_SYS_ACCEPT:
   4171    case VKI_SYS_ACCEPT4:
   4172       /* int accept(int s, struct sockaddr *addr, int *addrlen); */
   4173       /* int accept4(int s, struct sockaddr *addr, int *addrlen, int flags); */
   4174      r = ML_(generic_POST_sys_accept)( tid, VG_(mk_SysRes_Success)(RES),
   4175                                             ARG2_0, ARG2_1, ARG2_2 );
   4176      SET_STATUS_from_SysRes(r);
   4177      break;
   4178 
   4179    case VKI_SYS_SENDTO:
   4180       break;
   4181 
   4182    case VKI_SYS_SEND:
   4183       break;
   4184 
   4185    case VKI_SYS_RECVFROM:
   4186       ML_(generic_POST_sys_recvfrom)( tid, VG_(mk_SysRes_Success)(RES),
   4187                                            ARG2_0, ARG2_1, ARG2_2,
   4188                                            ARG2_3, ARG2_4, ARG2_5 );
   4189       break;
   4190 
   4191    case VKI_SYS_RECV:
   4192       ML_(generic_POST_sys_recv)( tid, RES, ARG2_0, ARG2_1, ARG2_2 );
   4193       break;
   4194 
   4195    case VKI_SYS_CONNECT:
   4196       break;
   4197 
   4198    case VKI_SYS_SETSOCKOPT:
   4199       break;
   4200 
   4201    case VKI_SYS_GETSOCKOPT:
   4202       ML_(linux_POST_sys_getsockopt)( tid, VG_(mk_SysRes_Success)(RES),
   4203                                       ARG2_0, ARG2_1,
   4204                                       ARG2_2, ARG2_3, ARG2_4 );
   4205       break;
   4206 
   4207    case VKI_SYS_GETSOCKNAME:
   4208       ML_(generic_POST_sys_getsockname)( tid, VG_(mk_SysRes_Success)(RES),
   4209                                               ARG2_0, ARG2_1, ARG2_2 );
   4210       break;
   4211 
   4212    case VKI_SYS_GETPEERNAME:
   4213       ML_(generic_POST_sys_getpeername)( tid, VG_(mk_SysRes_Success)(RES),
   4214                                               ARG2_0, ARG2_1, ARG2_2 );
   4215       break;
   4216 
   4217    case VKI_SYS_SHUTDOWN:
   4218       break;
   4219 
   4220    case VKI_SYS_SENDMSG:
   4221       break;
   4222 
   4223    case VKI_SYS_RECVMSG:
   4224       ML_(generic_POST_sys_recvmsg)( tid, "msg", (struct vki_msghdr *)ARG2_1, RES );
   4225       break;
   4226 
   4227    case VKI_SYS_RECVMMSG:
   4228       ML_(linux_POST_sys_recvmmsg)( tid, RES,
   4229                                     ARG2_0, ARG2_1, ARG2_2, ARG2_3, ARG2_4 );
   4230       break;
   4231 
   4232    case VKI_SYS_SENDMMSG:
   4233       ML_(linux_POST_sys_sendmmsg)( tid, RES, ARG2_0, ARG2_1, ARG2_2, ARG2_3 );
   4234       break;
   4235 
   4236    default:
   4237       VG_(message)(Vg_DebugMsg,"FATAL: unhandled socketcall 0x%lx\n",ARG1);
   4238       VG_(core_panic)("... bye!\n");
   4239       break; /*NOTREACHED*/
   4240    }
   4241 #  undef ARG2_0
   4242 #  undef ARG2_1
   4243 #  undef ARG2_2
   4244 #  undef ARG2_3
   4245 #  undef ARG2_4
   4246 #  undef ARG2_5
   4247 }
   4248 #endif
   4249 
   4250 PRE(sys_socket)
   4251 {
   4252    PRINT("sys_socket ( %ld, %ld, %ld )", SARG1, SARG2, SARG3);
   4253    PRE_REG_READ3(long, "socket", int, domain, int, type, int, protocol);
   4254 }
   4255 POST(sys_socket)
   4256 {
   4257    SysRes r;
   4258    vg_assert(SUCCESS);
   4259    r = ML_(generic_POST_sys_socket)(tid, VG_(mk_SysRes_Success)(RES));
   4260    SET_STATUS_from_SysRes(r);
   4261 }
   4262 
   4263 PRE(sys_setsockopt)
   4264 {
   4265    PRINT("sys_setsockopt ( %ld, %ld, %ld, %#lx, %lu )",
   4266          SARG1, SARG2, SARG3, ARG4, ARG5);
   4267    PRE_REG_READ5(long, "setsockopt",
   4268                  int, s, int, level, int, optname,
   4269                  const void *, optval, unsigned, optlen); // socklen_t
   4270    ML_(linux_PRE_sys_setsockopt)(tid, ARG1,ARG2,ARG3,ARG4,ARG5);
   4271 }
   4272 
   4273 PRE(sys_getsockopt)
   4274 {
   4275    PRINT("sys_getsockopt ( %ld, %ld, %ld, %#lx, %ld )",
   4276          SARG1, SARG2, SARG3, ARG4, SARG5);
   4277    PRE_REG_READ5(long, "getsockopt",
   4278                  int, s, int, level, int, optname,
   4279                  void *, optval, int, *optlen);
   4280    ML_(linux_PRE_sys_getsockopt)(tid, ARG1,ARG2,ARG3,ARG4,ARG5);
   4281 }
   4282 POST(sys_getsockopt)
   4283 {
   4284    vg_assert(SUCCESS);
   4285    ML_(linux_POST_sys_getsockopt)(tid, VG_(mk_SysRes_Success)(RES),
   4286                                        ARG1,ARG2,ARG3,ARG4,ARG5);
   4287 }
   4288 
   4289 PRE(sys_connect)
   4290 {
   4291    *flags |= SfMayBlock;
   4292    PRINT("sys_connect ( %ld, %#lx, %ld )", SARG1, ARG2, SARG3);
   4293    PRE_REG_READ3(long, "connect",
   4294                  int, sockfd, struct sockaddr *, serv_addr, int, addrlen);
   4295    ML_(generic_PRE_sys_connect)(tid, ARG1,ARG2,ARG3);
   4296 }
   4297 
   4298 PRE(sys_accept)
   4299 {
   4300    *flags |= SfMayBlock;
   4301    PRINT("sys_accept ( %ld, %#lx, %#lx )", SARG1, ARG2, ARG3);
   4302    PRE_REG_READ3(long, "accept",
   4303                  int, s, struct sockaddr *, addr, int *, addrlen);
   4304    ML_(generic_PRE_sys_accept)(tid, ARG1,ARG2,ARG3);
   4305 }
   4306 POST(sys_accept)
   4307 {
   4308    SysRes r;
   4309    vg_assert(SUCCESS);
   4310    r = ML_(generic_POST_sys_accept)(tid, VG_(mk_SysRes_Success)(RES),
   4311                                          ARG1,ARG2,ARG3);
   4312    SET_STATUS_from_SysRes(r);
   4313 }
   4314 
   4315 PRE(sys_accept4)
   4316 {
   4317    *flags |= SfMayBlock;
   4318    PRINT("sys_accept4 ( %ld, %#lx, %#lx, %ld )", SARG1, ARG2, ARG3, SARG4);
   4319    PRE_REG_READ4(long, "accept4",
   4320                  int, s, struct sockaddr *, addr, int *, addrlen, int, flags);
   4321    ML_(generic_PRE_sys_accept)(tid, ARG1,ARG2,ARG3);
   4322 }
   4323 POST(sys_accept4)
   4324 {
   4325    SysRes r;
   4326    vg_assert(SUCCESS);
   4327    r = ML_(generic_POST_sys_accept)(tid, VG_(mk_SysRes_Success)(RES),
   4328                                          ARG1,ARG2,ARG3);
   4329    SET_STATUS_from_SysRes(r);
   4330 }
   4331 
   4332 PRE(sys_send)
   4333 {
   4334    *flags |= SfMayBlock;
   4335    PRINT("sys_send ( %ld, %#lx, %lu, %#lx )", SARG1, ARG2, ARG3, ARG4);
   4336    PRE_REG_READ4(long, "send",
   4337                  int, s, const void *, msg, vki_size_t, len,
   4338                  int, flags);
   4339 
   4340    ML_(generic_PRE_sys_send)( tid, ARG1, ARG2, ARG3 );
   4341 }
   4342 
   4343 PRE(sys_sendto)
   4344 {
   4345    *flags |= SfMayBlock;
   4346    PRINT("sys_sendto ( %ld, %#lx, %lu, %lu, %#lx, %ld )",
   4347          SARG1, ARG2, ARG3, ARG4, ARG5, SARG6);
   4348    PRE_REG_READ6(long, "sendto",
   4349                  int, s, const void *, msg, vki_size_t, len,
   4350                  unsigned int, flags,
   4351                  const struct sockaddr *, to, int, tolen);
   4352    ML_(generic_PRE_sys_sendto)(tid, ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
   4353 }
   4354 
   4355 PRE (sys_recv)
   4356 {
   4357   *flags |= SfMayBlock;
   4358   PRINT ("sys_recv ( %ld, %#lx, %lu, %lu )", SARG1, ARG2, ARG3, ARG4);
   4359   PRE_REG_READ4 (long, "recv", int, s, void *, buf, vki_size_t, len,
   4360                  unsigned int, flags);
   4361   ML_ (generic_PRE_sys_recv) (tid, ARG1, ARG2, ARG3);
   4362 }
   4363 
   4364 POST (sys_recv)
   4365 {
   4366   ML_ (generic_POST_sys_recv) (tid, RES, ARG1, ARG2, ARG3);
   4367 }
   4368 
   4369 PRE(sys_recvfrom)
   4370 {
   4371    *flags |= SfMayBlock;
   4372    PRINT("sys_recvfrom ( %ld, %#lx, %lu, %lu, %#lx, %#lx )",
   4373          SARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
   4374    PRE_REG_READ6(long, "recvfrom",
   4375                  int, s, void *, buf, vki_size_t, len, unsigned int, flags,
   4376                  struct sockaddr *, from, int *, fromlen);
   4377    ML_(generic_PRE_sys_recvfrom)(tid, ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
   4378 }
   4379 POST(sys_recvfrom)
   4380 {
   4381    vg_assert(SUCCESS);
   4382    ML_(generic_POST_sys_recvfrom)(tid, VG_(mk_SysRes_Success)(RES),
   4383                                        ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
   4384 }
   4385 
   4386 PRE(sys_sendmsg)
   4387 {
   4388    *flags |= SfMayBlock;
   4389    PRINT("sys_sendmsg ( %ld, %#lx, %lu )", SARG1, ARG2, ARG3);
   4390    PRE_REG_READ3(long, "sendmsg",
   4391                  int, s, const struct msghdr *, msg, unsigned int, flags);
   4392    ML_(generic_PRE_sys_sendmsg)(tid, "msg", (struct vki_msghdr *)ARG2);
   4393 }
   4394 
   4395 PRE(sys_recvmsg)
   4396 {
   4397    *flags |= SfMayBlock;
   4398    PRINT("sys_recvmsg ( %ld, %#lx, %lu )", SARG1, ARG2, ARG3);
   4399    PRE_REG_READ3(long, "recvmsg", int, s, struct msghdr *, msg,
   4400                  unsigned int, flags);
   4401    ML_(generic_PRE_sys_recvmsg)(tid, "msg", (struct vki_msghdr *)ARG2);
   4402 }
   4403 POST(sys_recvmsg)
   4404 {
   4405    ML_(generic_POST_sys_recvmsg)(tid, "msg", (struct vki_msghdr *)ARG2, RES);
   4406 }
   4407 
   4408 PRE(sys_shutdown)
   4409 {
   4410    *flags |= SfMayBlock;
   4411    PRINT("sys_shutdown ( %ld, %ld )", SARG1, SARG2);
   4412    PRE_REG_READ2(int, "shutdown", int, s, int, how);
   4413 }
   4414 
   4415 PRE(sys_bind)
   4416 {
   4417    PRINT("sys_bind ( %ld, %#lx, %ld )", SARG1, ARG2, SARG3);
   4418    PRE_REG_READ3(long, "bind",
   4419                  int, sockfd, struct sockaddr *, my_addr, int, addrlen);
   4420    ML_(generic_PRE_sys_bind)(tid, ARG1,ARG2,ARG3);
   4421 }
   4422 
   4423 PRE(sys_listen)
   4424 {
   4425    PRINT("sys_listen ( %ld, %ld )", SARG1, SARG2);
   4426    PRE_REG_READ2(long, "listen", int, s, int, backlog);
   4427 }
   4428 
   4429 PRE(sys_getsockname)
   4430 {
   4431    PRINT("sys_getsockname ( %ld, %#lx, %#lx )", SARG1, ARG2, ARG3);
   4432    PRE_REG_READ3(long, "getsockname",
   4433                  int, s, struct sockaddr *, name, int *, namelen);
   4434    ML_(generic_PRE_sys_getsockname)(tid, ARG1,ARG2,ARG3);
   4435 }
   4436 POST(sys_getsockname)
   4437 {
   4438    vg_assert(SUCCESS);
   4439    ML_(generic_POST_sys_getsockname)(tid, VG_(mk_SysRes_Success)(RES),
   4440                                           ARG1,ARG2,ARG3);
   4441 }
   4442 
   4443 PRE(sys_getpeername)
   4444 {
   4445    PRINT("sys_getpeername ( %ld, %#lx, %#lx )", SARG1, ARG2, ARG3);
   4446    PRE_REG_READ3(long, "getpeername",
   4447                  int, s, struct sockaddr *, name, int *, namelen);
   4448    ML_(generic_PRE_sys_getpeername)(tid, ARG1,ARG2,ARG3);
   4449 }
   4450 POST(sys_getpeername)
   4451 {
   4452    vg_assert(SUCCESS);
   4453    ML_(generic_POST_sys_getpeername)(tid, VG_(mk_SysRes_Success)(RES),
   4454                                           ARG1,ARG2,ARG3);
   4455 }
   4456 
   4457 PRE(sys_socketpair)
   4458 {
   4459    PRINT("sys_socketpair ( %ld, %ld, %ld, %#lx )", SARG1, SARG2, SARG3, ARG4);
   4460    PRE_REG_READ4(long, "socketpair",
   4461                  int, d, int, type, int, protocol, int*, sv);
   4462    ML_(generic_PRE_sys_socketpair)(tid, ARG1,ARG2,ARG3,ARG4);
   4463 }
   4464 POST(sys_socketpair)
   4465 {
   4466    vg_assert(SUCCESS);
   4467    ML_(generic_POST_sys_socketpair)(tid, VG_(mk_SysRes_Success)(RES),
   4468                                          ARG1,ARG2,ARG3,ARG4);
   4469 }
   4470 
   4471 
   4472 /* ---------------------------------------------------------------------
   4473    *at wrappers
   4474    ------------------------------------------------------------------ */
   4475 
   4476 PRE(sys_openat)
   4477 {
   4478    HChar  name[30];   // large enough
   4479    SysRes sres;
   4480 
   4481    if (ARG3 & VKI_O_CREAT) {
   4482       // 4-arg version
   4483       PRINT("sys_openat ( %ld, %#lx(%s), %ld, %ld )",
   4484             SARG1, ARG2, (HChar*)ARG2, SARG3, SARG4);
   4485       PRE_REG_READ4(long, "openat",
   4486                     int, dfd, const char *, filename, int, flags, int, mode);
   4487    } else {
   4488       // 3-arg version
   4489       PRINT("sys_openat ( %ld, %#lx(%s), %ld )",
   4490             SARG1, ARG2, (HChar*)ARG2, SARG3);
   4491       PRE_REG_READ3(long, "openat",
   4492                     int, dfd, const char *, filename, int, flags);
   4493    }
   4494 
   4495    PRE_MEM_RASCIIZ( "openat(filename)", ARG2 );
   4496 
   4497    /* For absolute filenames, dfd is ignored.  If dfd is AT_FDCWD,
   4498       filename is relative to cwd.  When comparing dfd against AT_FDCWD,
   4499       be sure only to compare the bottom 32 bits. */
   4500    if (ML_(safe_to_deref)( (void*)ARG2, 1 )
   4501        && *(Char *)ARG2 != '/'
   4502        && ((Int)ARG1) != ((Int)VKI_AT_FDCWD)
   4503        && !ML_(fd_allowed)(ARG1, "openat", tid, False))
   4504       SET_STATUS_Failure( VKI_EBADF );
   4505 
   4506    /* Handle the case where the open is of /proc/self/cmdline or
   4507       /proc/<pid>/cmdline, and just give it a copy of the fd for the
   4508       fake file we cooked up at startup (in m_main).  Also, seek the
   4509       cloned fd back to the start. */
   4510 
   4511    VG_(sprintf)(name, "/proc/%d/cmdline", VG_(getpid)());
   4512    if (ML_(safe_to_deref)( (void*)ARG2, 1 )
   4513        && (VG_(strcmp)((HChar *)ARG2, name) == 0
   4514            || VG_(strcmp)((HChar *)ARG2, "/proc/self/cmdline") == 0)) {
   4515       sres = VG_(dup)( VG_(cl_cmdline_fd) );
   4516       SET_STATUS_from_SysRes( sres );
   4517       if (!sr_isError(sres)) {
   4518          OffT off = VG_(lseek)( sr_Res(sres), 0, VKI_SEEK_SET );
   4519          if (off < 0)
   4520             SET_STATUS_Failure( VKI_EMFILE );
   4521       }
   4522       return;
   4523    }
   4524 
   4525    /* Do the same for /proc/self/auxv or /proc/<pid>/auxv case. */
   4526 
   4527    VG_(sprintf)(name, "/proc/%d/auxv", VG_(getpid)());
   4528    if (ML_(safe_to_deref)( (void*)ARG2, 1 )
   4529        && (VG_(strcmp)((HChar *)ARG2, name) == 0
   4530            || VG_(strcmp)((HChar *)ARG2, "/proc/self/auxv") == 0)) {
   4531       sres = VG_(dup)( VG_(cl_auxv_fd) );
   4532       SET_STATUS_from_SysRes( sres );
   4533       if (!sr_isError(sres)) {
   4534          OffT off = VG_(lseek)( sr_Res(sres), 0, VKI_SEEK_SET );
   4535          if (off < 0)
   4536             SET_STATUS_Failure( VKI_EMFILE );
   4537       }
   4538       return;
   4539    }
   4540 
   4541    /* Otherwise handle normally */
   4542    *flags |= SfMayBlock;
   4543 }
   4544 
   4545 POST(sys_openat)
   4546 {
   4547    vg_assert(SUCCESS);
   4548    if (!ML_(fd_allowed)(RES, "openat", tid, True)) {
   4549       VG_(close)(RES);
   4550       SET_STATUS_Failure( VKI_EMFILE );
   4551    } else {
   4552       if (VG_(clo_track_fds))
   4553          ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG2);
   4554    }
   4555 }
   4556 
   4557 PRE(sys_mkdirat)
   4558 {
   4559    *flags |= SfMayBlock;
   4560    PRINT("sys_mkdirat ( %ld, %#lx(%s), %ld )",
   4561          SARG1, ARG2, (HChar*)ARG2, SARG3);
   4562    PRE_REG_READ3(long, "mkdirat",
   4563                  int, dfd, const char *, pathname, int, mode);
   4564    PRE_MEM_RASCIIZ( "mkdirat(pathname)", ARG2 );
   4565 }
   4566 
   4567 PRE(sys_mknodat)
   4568 {
   4569    PRINT("sys_mknodat ( %ld, %#lx(%s), 0x%lx, 0x%lx )",
   4570          SARG1, ARG2, (HChar*)ARG2, ARG3, ARG4 );
   4571    PRE_REG_READ4(long, "mknodat",
   4572                  int, dfd, const char *, pathname, int, mode, unsigned, dev);
   4573    PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2 );
   4574 }
   4575 
   4576 PRE(sys_fchownat)
   4577 {
   4578    PRINT("sys_fchownat ( %ld, %#lx(%s), 0x%lx, 0x%lx )",
   4579          SARG1, ARG2, (HChar*)ARG2, ARG3, ARG4);
   4580    PRE_REG_READ4(long, "fchownat",
   4581                  int, dfd, const char *, path,
   4582                  vki_uid_t, owner, vki_gid_t, group);
   4583    PRE_MEM_RASCIIZ( "fchownat(path)", ARG2 );
   4584 }
   4585 
   4586 PRE(sys_futimesat)
   4587 {
   4588    PRINT("sys_futimesat ( %ld, %#lx(%s), %#lx )",
   4589          SARG1, ARG2, (HChar*)ARG2, ARG3);
   4590    PRE_REG_READ3(long, "futimesat",
   4591                  int, dfd, char *, filename, struct timeval *, tvp);
   4592    if (ARG2 != 0)
   4593       PRE_MEM_RASCIIZ( "futimesat(filename)", ARG2 );
   4594    if (ARG3 != 0)
   4595       PRE_MEM_READ( "futimesat(tvp)", ARG3, 2 * sizeof(struct vki_timeval) );
   4596 }
   4597 
   4598 PRE(sys_utimensat)
   4599 {
   4600    PRINT("sys_utimensat ( %ld, %#lx(%s), %#lx, 0x%lx )",
   4601          SARG1, ARG2, (HChar*)ARG2, ARG3, ARG4);
   4602    PRE_REG_READ4(long, "utimensat",
   4603                  int, dfd, char *, filename, struct timespec *, utimes, int, flags);
   4604    if (ARG2 != 0)
   4605       PRE_MEM_RASCIIZ( "utimensat(filename)", ARG2 );
   4606    if (ARG3 != 0)
   4607       PRE_MEM_READ( "utimensat(tvp)", ARG3, 2 * sizeof(struct vki_timespec) );
   4608 }
   4609 
   4610 PRE(sys_newfstatat)
   4611 {
   4612    FUSE_COMPATIBLE_MAY_BLOCK();
   4613    PRINT("sys_newfstatat ( %ld, %#lx(%s), %#lx )",
   4614          SARG1, ARG2, (HChar*)ARG2, ARG3);
   4615    PRE_REG_READ3(long, "fstatat",
   4616                  int, dfd, char *, file_name, struct stat *, buf);
   4617    PRE_MEM_RASCIIZ( "fstatat(file_name)", ARG2 );
   4618    PRE_MEM_WRITE( "fstatat(buf)", ARG3, sizeof(struct vki_stat) );
   4619 }
   4620 
   4621 POST(sys_newfstatat)
   4622 {
   4623    POST_MEM_WRITE( ARG3, sizeof(struct vki_stat) );
   4624 }
   4625 
   4626 PRE(sys_unlinkat)
   4627 {
   4628    *flags |= SfMayBlock;
   4629    PRINT("sys_unlinkat ( %ld, %#lx(%s) )", SARG1, ARG2, (HChar*)ARG2);
   4630    PRE_REG_READ2(long, "unlinkat", int, dfd, const char *, pathname);
   4631    PRE_MEM_RASCIIZ( "unlinkat(pathname)", ARG2 );
   4632 }
   4633 
   4634 PRE(sys_renameat)
   4635 {
   4636    PRINT("sys_renameat ( %ld, %#lx(%s), %ld, %#lx(%s) )",
   4637          SARG1, ARG2, (HChar*)ARG2, SARG3, ARG4, (HChar*)ARG4);
   4638    PRE_REG_READ4(long, "renameat",
   4639                  int, olddfd, const char *, oldpath,
   4640                  int, newdfd, const char *, newpath);
   4641    PRE_MEM_RASCIIZ( "renameat(oldpath)", ARG2 );
   4642    PRE_MEM_RASCIIZ( "renameat(newpath)", ARG4 );
   4643 }
   4644 
   4645 PRE(sys_linkat)
   4646 {
   4647    *flags |= SfMayBlock;
   4648    PRINT("sys_linkat ( %ld, %#lx(%s), %ld, %#lx(%s), %ld )",
   4649          SARG1, ARG2, (HChar*)ARG2, SARG3, ARG4, (HChar*)ARG4, SARG5);
   4650    PRE_REG_READ5(long, "linkat",
   4651                  int, olddfd, const char *, oldpath,
   4652                  int, newdfd, const char *, newpath,
   4653                  int, flags);
   4654    PRE_MEM_RASCIIZ( "linkat(oldpath)", ARG2);
   4655    PRE_MEM_RASCIIZ( "linkat(newpath)", ARG4);
   4656 }
   4657 
   4658 PRE(sys_symlinkat)
   4659 {
   4660    *flags |= SfMayBlock;
   4661    PRINT("sys_symlinkat ( %#lx(%s), %ld, %#lx(%s) )",
   4662          ARG1, (HChar*)ARG1, SARG2, ARG3, (HChar*)ARG3);
   4663    PRE_REG_READ3(long, "symlinkat",
   4664                  const char *, oldpath, int, newdfd, const char *, newpath);
   4665    PRE_MEM_RASCIIZ( "symlinkat(oldpath)", ARG1 );
   4666    PRE_MEM_RASCIIZ( "symlinkat(newpath)", ARG3 );
   4667 }
   4668 
   4669 PRE(sys_readlinkat)
   4670 {
   4671    HChar name[30];       // large enough
   4672    Word  saved = SYSNO;
   4673 
   4674    PRINT("sys_readlinkat ( %ld, %#lx(%s), %#lx, %lu )",
   4675          SARG1, ARG2, (HChar*)ARG2, ARG3, ARG4);
   4676    PRE_REG_READ4(long, "readlinkat",
   4677                  int, dfd, const char *, path, char *, buf, vki_size_t, bufsiz);
   4678    PRE_MEM_RASCIIZ( "readlinkat(path)", ARG2 );
   4679    PRE_MEM_WRITE( "readlinkat(buf)", ARG3,ARG4 );
   4680 
   4681    /*
   4682     * Handle the case where readlinkat is looking at /proc/self/exe or
   4683     * /proc/<pid>/exe.
   4684     */
   4685    VG_(sprintf)(name, "/proc/%d/exe", VG_(getpid)());
   4686    if (ML_(safe_to_deref)((void*)ARG2, 1)
   4687        && (VG_(strcmp)((HChar *)ARG2, name) == 0
   4688            || VG_(strcmp)((HChar *)ARG2, "/proc/self/exe") == 0)) {
   4689       VG_(sprintf)(name, "/proc/self/fd/%d", VG_(cl_exec_fd));
   4690       SET_STATUS_from_SysRes( VG_(do_syscall4)(saved, ARG1, (UWord)name,
   4691                                                       ARG3, ARG4));
   4692    } else {
   4693       /* Normal case */
   4694       SET_STATUS_from_SysRes( VG_(do_syscall4)(saved, ARG1, ARG2, ARG3, ARG4));
   4695    }
   4696 
   4697    if (SUCCESS && RES > 0)
   4698       POST_MEM_WRITE( ARG3, RES );
   4699 }
   4700 
   4701 PRE(sys_fchmodat)
   4702 {
   4703    PRINT("sys_fchmodat ( %ld, %#lx(%s), %lu )",
   4704          SARG1, ARG2, (HChar*)ARG2, ARG3);
   4705    PRE_REG_READ3(long, "fchmodat",
   4706                  int, dfd, const char *, path, vki_mode_t, mode);
   4707    PRE_MEM_RASCIIZ( "fchmodat(path)", ARG2 );
   4708 }
   4709 
   4710 PRE(sys_faccessat)
   4711 {
   4712    PRINT("sys_faccessat ( %ld, %#lx(%s), %ld )",
   4713          SARG1, ARG2, (HChar*)ARG2, SARG3);
   4714    PRE_REG_READ3(long, "faccessat",
   4715                  int, dfd, const char *, pathname, int, mode);
   4716    PRE_MEM_RASCIIZ( "faccessat(pathname)", ARG2 );
   4717 }
   4718 
   4719 PRE(sys_name_to_handle_at)
   4720 {
   4721    PRINT("sys_name_to_handle_at ( %ld, %#lx(%s), %#lx, %#lx, %ld )",
   4722          SARG1, ARG2, (HChar*)ARG2, ARG3, ARG4, SARG5);
   4723    PRE_REG_READ5(int, "name_to_handle_at",
   4724                  int, dfd, const char *, name,
   4725                  struct vki_file_handle *, handle,
   4726                  int *, mnt_id, int, flag);
   4727    PRE_MEM_RASCIIZ( "name_to_handle_at(name)", ARG2 );
   4728    if (ML_(safe_to_deref)( (void*)ARG3, sizeof(struct vki_file_handle))) {
   4729       struct vki_file_handle *fh = (struct vki_file_handle *)ARG3;
   4730       PRE_MEM_READ( "name_to_handle_at(handle)", (Addr)&fh->handle_bytes, sizeof(fh->handle_bytes) );
   4731       PRE_MEM_WRITE( "name_to_handle_at(handle)", (Addr)fh, sizeof(struct vki_file_handle) + fh->handle_bytes );
   4732    }
   4733    PRE_MEM_WRITE( "name_to_handle_at(mnt_id)", ARG4, sizeof(int) );
   4734 }
   4735 
   4736 POST(sys_name_to_handle_at)
   4737 {
   4738    struct vki_file_handle *fh = (struct vki_file_handle *)ARG3;
   4739    POST_MEM_WRITE( ARG3, sizeof(struct vki_file_handle) + fh->handle_bytes );
   4740    POST_MEM_WRITE( ARG4, sizeof(int) );
   4741 }
   4742 
   4743 PRE(sys_open_by_handle_at)
   4744 {
   4745    *flags |= SfMayBlock;
   4746    PRINT("sys_open_by_handle_at ( %ld, %#lx, %ld )", SARG1, ARG2, SARG3);
   4747    PRE_REG_READ3(int, "open_by_handle_at",
   4748                  int, mountdirfd,
   4749                  struct vki_file_handle *, handle,
   4750                  int, flags);
   4751    PRE_MEM_READ( "open_by_handle_at(handle)", ARG2, sizeof(struct vki_file_handle) + ((struct vki_file_handle*)ARG2)->handle_bytes );
   4752 }
   4753 
   4754 POST(sys_open_by_handle_at)
   4755 {
   4756    vg_assert(SUCCESS);
   4757    if (!ML_(fd_allowed)(RES, "open_by_handle_at", tid, True)) {
   4758       VG_(close)(RES);
   4759       SET_STATUS_Failure( VKI_EMFILE );
   4760    } else {
   4761       if (VG_(clo_track_fds))
   4762          ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG2);
   4763    }
   4764 }
   4765 
   4766 /* ---------------------------------------------------------------------
   4767    p{read,write}v wrappers
   4768    ------------------------------------------------------------------ */
   4769 
   4770 PRE(sys_preadv)
   4771 {
   4772    Int i;
   4773    struct vki_iovec * vec;
   4774    *flags |= SfMayBlock;
   4775 #if VG_WORDSIZE == 4
   4776    /* Note that the offset argument here is in lo+hi order on both
   4777       big and little endian platforms... */
   4778    PRINT("sys_preadv ( %lu, %#lx, %lu, %lld )",
   4779          ARG1, ARG2, ARG3, (Long)LOHI64(ARG4,ARG5));
   4780    PRE_REG_READ5(ssize_t, "preadv",
   4781                  unsigned long, fd, const struct iovec *, vector,
   4782                  unsigned long, count, vki_u32, offset_low,
   4783                  vki_u32, offset_high);
   4784 #elif VG_WORDSIZE == 8
   4785    PRINT("sys_preadv ( %lu, %#lx, %lu, %ld )", ARG1, ARG2, ARG3, SARG4);
   4786    PRE_REG_READ4(ssize_t, "preadv",
   4787                  unsigned long, fd, const struct iovec *, vector,
   4788                  unsigned long, count, Word, offset);
   4789 #else
   4790 #  error Unexpected word size
   4791 #endif
   4792    if (!ML_(fd_allowed)(ARG1, "preadv", tid, False)) {
   4793       SET_STATUS_Failure( VKI_EBADF );
   4794    } else {
   4795       PRE_MEM_READ( "preadv(vector)", ARG2, ARG3 * sizeof(struct vki_iovec) );
   4796 
   4797       if (ARG2 != 0) {
   4798          /* ToDo: don't do any of the following if the vector is invalid */
   4799          vec = (struct vki_iovec *)ARG2;
   4800          for (i = 0; i < (Int)ARG3; i++)
   4801             PRE_MEM_WRITE( "preadv(vector[...])",
   4802                            (Addr)vec[i].iov_base, vec[i].iov_len );
   4803       }
   4804    }
   4805 }
   4806 
   4807 POST(sys_preadv)
   4808 {
   4809    vg_assert(SUCCESS);
   4810    if (RES > 0) {
   4811       Int i;
   4812       struct vki_iovec * vec = (struct vki_iovec *)ARG2;
   4813       Int remains = RES;
   4814 
   4815       /* RES holds the number of bytes read. */
   4816       for (i = 0; i < (Int)ARG3; i++) {
   4817 	 Int nReadThisBuf = vec[i].iov_len;
   4818 	 if (nReadThisBuf > remains) nReadThisBuf = remains;
   4819 	 POST_MEM_WRITE( (Addr)vec[i].iov_base, nReadThisBuf );
   4820 	 remains -= nReadThisBuf;
   4821 	 if (remains < 0) VG_(core_panic)("preadv: remains < 0");
   4822       }
   4823    }
   4824 }
   4825 
   4826 PRE(sys_pwritev)
   4827 {
   4828    Int i;
   4829    struct vki_iovec * vec;
   4830    *flags |= SfMayBlock;
   4831 #if VG_WORDSIZE == 4
   4832    /* Note that the offset argument here is in lo+hi order on both
   4833       big and little endian platforms... */
   4834    PRINT("sys_pwritev ( %lu, %#lx, %lu, %lld )",
   4835          ARG1, ARG2, ARG3, (Long)LOHI64(ARG4,ARG5));
   4836    PRE_REG_READ5(ssize_t, "pwritev",
   4837                  unsigned long, fd, const struct iovec *, vector,
   4838                  unsigned long, count, vki_u32, offset_low,
   4839                  vki_u32, offset_high);
   4840 #elif VG_WORDSIZE == 8
   4841    PRINT("sys_pwritev ( %lu, %#lx, %lu, %ld )", ARG1, ARG2, ARG3, SARG4);
   4842    PRE_REG_READ4(ssize_t, "pwritev",
   4843                  unsigned long, fd, const struct iovec *, vector,
   4844                  unsigned long, count, Word, offset);
   4845 #else
   4846 #  error Unexpected word size
   4847 #endif
   4848    if (!ML_(fd_allowed)(ARG1, "pwritev", tid, False)) {
   4849       SET_STATUS_Failure( VKI_EBADF );
   4850    } else {
   4851       PRE_MEM_READ( "pwritev(vector)",
   4852 		     ARG2, ARG3 * sizeof(struct vki_iovec) );
   4853       if (ARG2 != 0) {
   4854          /* ToDo: don't do any of the following if the vector is invalid */
   4855          vec = (struct vki_iovec *)ARG2;
   4856          for (i = 0; i < (Int)ARG3; i++)
   4857             PRE_MEM_READ( "pwritev(vector[...])",
   4858                            (Addr)vec[i].iov_base, vec[i].iov_len );
   4859       }
   4860    }
   4861 }
   4862 
   4863 /* ---------------------------------------------------------------------
   4864    process_vm_{read,write}v wrappers
   4865    ------------------------------------------------------------------ */
   4866 
   4867 PRE(sys_process_vm_readv)
   4868 {
   4869    PRINT("sys_process_vm_readv ( %ld, %#lx, %lu, %#lx, %lu, %lu )",
   4870          SARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
   4871    PRE_REG_READ6(ssize_t, "process_vm_readv",
   4872                  vki_pid_t, pid,
   4873                  const struct iovec *, lvec,
   4874                  unsigned long, liovcnt,
   4875                  const struct iovec *, rvec,
   4876                  unsigned long, riovcnt,
   4877                  unsigned long, flags);
   4878    PRE_MEM_READ( "process_vm_readv(lvec)",
   4879                  ARG2, ARG3 * sizeof(struct vki_iovec) );
   4880    PRE_MEM_READ( "process_vm_readv(rvec)",
   4881                  ARG4, ARG5 * sizeof(struct vki_iovec) );
   4882    if (ARG2 != 0) {
   4883       /* TODO: Don't do any of the following if lvec is invalid */
   4884       const struct vki_iovec *vec = (const struct vki_iovec *)ARG2;
   4885       UInt i;
   4886       for (i = 0; i < ARG3; i++)
   4887          PRE_MEM_WRITE( "process_vm_readv(lvec[...])",
   4888                         (Addr)vec[i].iov_base, vec[i].iov_len );
   4889    }
   4890 }
   4891 
   4892 POST(sys_process_vm_readv)
   4893 {
   4894    const struct vki_iovec *vec = (const struct vki_iovec *)ARG2;
   4895    UInt remains = RES;
   4896    UInt i;
   4897    for (i = 0; i < ARG3; i++) {
   4898       UInt nReadThisBuf = vec[i].iov_len <= remains ?
   4899                           vec[i].iov_len : remains;
   4900       POST_MEM_WRITE( (Addr)vec[i].iov_base, nReadThisBuf );
   4901       remains -= nReadThisBuf;
   4902    }
   4903 }
   4904 
   4905 PRE(sys_process_vm_writev)
   4906 {
   4907    PRINT("sys_process_vm_writev ( %ld, %#lx, %lu, %#lx, %lu, %lu )",
   4908          SARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
   4909    PRE_REG_READ6(ssize_t, "process_vm_writev",
   4910                  vki_pid_t, pid,
   4911                  const struct iovec *, lvec,
   4912                  unsigned long, liovcnt,
   4913                  const struct iovec *, rvec,
   4914                  unsigned long, riovcnt,
   4915                  unsigned long, flags);
   4916    PRE_MEM_READ( "process_vm_writev(lvec)",
   4917                  ARG2, ARG3 * sizeof(struct vki_iovec) );
   4918    PRE_MEM_READ( "process_vm_writev(rvec)",
   4919                  ARG4, ARG5 * sizeof(struct vki_iovec) );
   4920    if (ARG2 != 0) {
   4921       /* TODO: Don't do any of the following if lvec is invalid */
   4922       const struct vki_iovec *vec = (const struct vki_iovec *)ARG2;
   4923       UInt i;
   4924       for (i = 0; i < ARG3; i++)
   4925          PRE_MEM_READ( "process_vm_writev(lvec[...])",
   4926                        (Addr)vec[i].iov_base, vec[i].iov_len );
   4927    }
   4928 }
   4929 
   4930 /* ---------------------------------------------------------------------
   4931    {send,recv}mmsg wrappers
   4932    ------------------------------------------------------------------ */
   4933 
   4934 PRE(sys_sendmmsg)
   4935 {
   4936    *flags |= SfMayBlock;
   4937    PRINT("sys_sendmmsg ( %ld, %#lx, %ld, %ld )", SARG1, ARG2, SARG3, SARG4);
   4938    PRE_REG_READ4(long, "sendmmsg",
   4939                  int, s, const struct mmsghdr *, mmsg, int, vlen, int, flags);
   4940    ML_(linux_PRE_sys_sendmmsg)(tid, ARG1,ARG2,ARG3,ARG4);
   4941 }
   4942 
   4943 POST(sys_sendmmsg)
   4944 {
   4945    ML_(linux_POST_sys_sendmmsg) (tid, RES, ARG1,ARG2,ARG3,ARG4);
   4946 }
   4947 
   4948 PRE(sys_recvmmsg)
   4949 {
   4950    *flags |= SfMayBlock;
   4951    PRINT("sys_recvmmsg ( %ld, %#lx, %ld, %ld, %#lx )",
   4952          SARG1, ARG2, SARG3, SARG4, ARG5);
   4953    PRE_REG_READ5(long, "recvmmsg",
   4954                  int, s, struct mmsghdr *, mmsg, int, vlen,
   4955                  int, flags, struct timespec *, timeout);
   4956    ML_(linux_PRE_sys_recvmmsg)(tid, ARG1,ARG2,ARG3,ARG4,ARG5);
   4957 }
   4958 
   4959 POST(sys_recvmmsg)
   4960 {
   4961    ML_(linux_POST_sys_recvmmsg) (tid, RES, ARG1,ARG2,ARG3,ARG4,ARG5);
   4962 }
   4963 
   4964 /* ---------------------------------------------------------------------
   4965    key retention service wrappers
   4966    ------------------------------------------------------------------ */
   4967 
   4968 PRE(sys_request_key)
   4969 {
   4970    PRINT("sys_request_key ( %#lx(%s), %#lx(%s), %#lx(%s), %ld )",
   4971          ARG1, (HChar*)ARG1, ARG2, (HChar*)ARG2, ARG3, (HChar*)ARG3, SARG4);
   4972    PRE_REG_READ4(long, "request_key",
   4973                  const char *, type, const char *, description,
   4974                  const char *, callout_info, vki_key_serial_t, keyring);
   4975    PRE_MEM_RASCIIZ( "request_key(type)", ARG1);
   4976    PRE_MEM_RASCIIZ( "request_key(description)", ARG2);
   4977    if (ARG3 != (UWord)NULL)
   4978       PRE_MEM_RASCIIZ( "request_key(callout_info)", ARG3);
   4979 }
   4980 
   4981 PRE(sys_add_key)
   4982 {
   4983    PRINT("sys_add_key ( %#lx(%s), %#lx(%s), %#lx, %lu, %ld )",
   4984          ARG1, (HChar*)ARG1, ARG2, (HChar*)ARG2, ARG3, ARG4, SARG5);
   4985    PRE_REG_READ5(long, "add_key",
   4986                  const char *, type, const char *, description,
   4987                  const void *, payload, vki_size_t, plen,
   4988                  vki_key_serial_t, keyring);
   4989    PRE_MEM_RASCIIZ( "add_key(type)", ARG1);
   4990    PRE_MEM_RASCIIZ( "add_key(description)", ARG2);
   4991    if (ARG3 != (UWord)NULL)
   4992       PRE_MEM_READ( "request_key(payload)", ARG3, ARG4);
   4993 }
   4994 
   4995 PRE(sys_keyctl)
   4996 {
   4997    switch (ARG1 /* option */) {
   4998    case VKI_KEYCTL_GET_KEYRING_ID:
   4999       PRINT("sys_keyctl ( KEYCTL_GET_KEYRING_ID, %ld, %ld )", SARG2, SARG3);
   5000       PRE_REG_READ3(long, "keyctl(KEYCTL_GET_KEYRING_ID)",
   5001                     int, option, vki_key_serial_t, id, int, create);
   5002       break;
   5003    case VKI_KEYCTL_JOIN_SESSION_KEYRING:
   5004       PRINT("sys_keyctl ( KEYCTL_JOIN_SESSION_KEYRING, %#lx(%s) )", ARG2,(char*)ARG2);
   5005       PRE_REG_READ2(long, "keyctl(KEYCTL_JOIN_SESSION_KEYRING)",
   5006                     int, option, const char *, name);
   5007       if (ARG2 != (UWord)NULL)
   5008          PRE_MEM_RASCIIZ("keyctl(KEYCTL_JOIN_SESSION_KEYRING, name)", ARG2);
   5009       break;
   5010    case VKI_KEYCTL_UPDATE:
   5011       PRINT("sys_keyctl ( KEYCTL_UPDATE, %ld, %#lx, %lu )", SARG2, ARG3, ARG4);
   5012       PRE_REG_READ4(long, "keyctl(KEYCTL_UPDATE)",
   5013                     int, option, vki_key_serial_t, key,
   5014                     const void *, payload, vki_size_t, plen);
   5015       if (ARG3 != (UWord)NULL)
   5016          PRE_MEM_READ("keyctl(KEYCTL_UPDATE, payload)", ARG3, ARG4);
   5017       break;
   5018    case VKI_KEYCTL_REVOKE:
   5019       PRINT("sys_keyctl ( KEYCTL_REVOKE, %ld )", SARG2);
   5020       PRE_REG_READ2(long, "keyctl(KEYCTL_REVOKE)",
   5021                     int, option, vki_key_serial_t, id);
   5022       break;
   5023    case VKI_KEYCTL_CHOWN:
   5024       PRINT("sys_keyctl ( KEYCTL_CHOWN, %ld, %lu, %lu )", SARG2, ARG3, ARG4);
   5025       PRE_REG_READ4(long, "keyctl(KEYCTL_CHOWN)",
   5026                     int, option, vki_key_serial_t, id,
   5027                     vki_uid_t, uid, vki_gid_t, gid);
   5028       break;
   5029    case VKI_KEYCTL_SETPERM:
   5030       PRINT("sys_keyctl ( KEYCTL_SETPERM, %ld, %lu )", SARG2, ARG3);
   5031       PRE_REG_READ3(long, "keyctl(KEYCTL_SETPERM)",
   5032                     int, option, vki_key_serial_t, id, vki_key_perm_t, perm);
   5033       break;
   5034    case VKI_KEYCTL_DESCRIBE:
   5035       PRINT("sys_keyctl ( KEYCTL_DESCRIBE, %ld, %#lx, %lu )", SARG2, ARG3, ARG4);
   5036       PRE_REG_READ4(long, "keyctl(KEYCTL_DESCRIBE)",
   5037                     int, option, vki_key_serial_t, id,
   5038                     char *, buffer, vki_size_t, buflen);
   5039       if (ARG3 != (UWord)NULL)
   5040          PRE_MEM_WRITE("keyctl(KEYCTL_DESCRIBE, buffer)", ARG3, ARG4);
   5041       break;
   5042    case VKI_KEYCTL_CLEAR:
   5043       PRINT("sys_keyctl ( KEYCTL_CLEAR, %ld )", SARG2);
   5044       PRE_REG_READ2(long, "keyctl(KEYCTL_CLEAR)",
   5045                     int, option, vki_key_serial_t, keyring);
   5046       break;
   5047    case VKI_KEYCTL_LINK:
   5048       PRINT("sys_keyctl ( KEYCTL_LINK, %ld, %ld )", SARG2, SARG3);
   5049       PRE_REG_READ3(long, "keyctl(KEYCTL_LINK)", int, option,
   5050                     vki_key_serial_t, keyring, vki_key_serial_t, key);
   5051       break;
   5052    case VKI_KEYCTL_UNLINK:
   5053       PRINT("sys_keyctl ( KEYCTL_UNLINK, %ld, %ld )", SARG2, SARG3);
   5054       PRE_REG_READ3(long, "keyctl(KEYCTL_UNLINK)", int, option,
   5055                     vki_key_serial_t, keyring, vki_key_serial_t, key);
   5056       break;
   5057    case VKI_KEYCTL_SEARCH:
   5058       PRINT("sys_keyctl ( KEYCTL_SEARCH, %ld, %#lx(%s), %#lx(%s), %ld )",
   5059             SARG2, ARG3, (HChar*)ARG3, ARG4, (HChar*)ARG4, SARG5);
   5060       PRE_REG_READ5(long, "keyctl(KEYCTL_SEARCH)",
   5061                     int, option, vki_key_serial_t, keyring,
   5062                     const char *, type, const char *, description,
   5063                     vki_key_serial_t, destring);
   5064       PRE_MEM_RASCIIZ("sys_keyctl(KEYCTL_SEARCH, type)", ARG3);
   5065       PRE_MEM_RASCIIZ("sys_keyctl(KEYCTL_SEARCH, description)", ARG4);
   5066       break;
   5067    case VKI_KEYCTL_READ:
   5068       PRINT("sys_keyctl ( KEYCTL_READ, %ld, %#lx, %lu )", SARG2, ARG3, ARG4);
   5069       PRE_REG_READ4(long, "keyctl(KEYCTL_READ)",
   5070                     int, option, vki_key_serial_t, keyring,
   5071                     char *, buffer, vki_size_t, buflen);
   5072       if (ARG3 != (UWord)NULL)
   5073          PRE_MEM_WRITE("keyctl(KEYCTL_READ, buffer)", ARG3, ARG4);
   5074       break;
   5075    case VKI_KEYCTL_INSTANTIATE:
   5076       PRINT("sys_keyctl ( KEYCTL_INSTANTIATE, %ld, %#lx, %lu, %ld )",
   5077             SARG2, ARG3, ARG4, SARG5);
   5078       PRE_REG_READ5(long, "keyctl(KEYCTL_INSTANTIATE)",
   5079                     int, option, vki_key_serial_t, key,
   5080                     char *, payload, vki_size_t, plen,
   5081                     vki_key_serial_t, keyring);
   5082       if (ARG3 != (UWord)NULL)
   5083          PRE_MEM_READ("keyctl(KEYCTL_INSTANTIATE, payload)", ARG3, ARG4);
   5084       break;
   5085    case VKI_KEYCTL_NEGATE:
   5086       PRINT("sys_keyctl ( KEYCTL_NEGATE, %ld, %lu, %ld )", SARG2, ARG3, SARG4);
   5087       PRE_REG_READ4(long, "keyctl(KEYCTL_NEGATE)",
   5088                     int, option, vki_key_serial_t, key,
   5089                     unsigned, timeout, vki_key_serial_t, keyring);
   5090       break;
   5091    case VKI_KEYCTL_SET_REQKEY_KEYRING:
   5092       PRINT("sys_keyctl ( KEYCTL_SET_REQKEY_KEYRING, %ld )", SARG2);
   5093       PRE_REG_READ2(long, "keyctl(KEYCTL_SET_REQKEY_KEYRING)",
   5094                     int, option, int, reqkey_defl);
   5095       break;
   5096    case VKI_KEYCTL_SET_TIMEOUT:
   5097       PRINT("sys_keyctl ( KEYCTL_SET_TIMEOUT, %ld, %lu )", SARG2, ARG3);
   5098       PRE_REG_READ3(long, "keyctl(KEYCTL_SET_TIMEOUT)",
   5099                     int, option, vki_key_serial_t, key, unsigned, timeout);
   5100       break;
   5101    case VKI_KEYCTL_ASSUME_AUTHORITY:
   5102       PRINT("sys_keyctl ( KEYCTL_ASSUME_AUTHORITY, %ld )", SARG2);
   5103       PRE_REG_READ2(long, "keyctl(KEYCTL_ASSUME_AUTHORITY)",
   5104                     int, option, vki_key_serial_t, key);
   5105       break;
   5106    default:
   5107       PRINT("sys_keyctl ( %ld ) ", SARG1);
   5108       PRE_REG_READ1(long, "keyctl", int, option);
   5109       break;
   5110    }
   5111 }
   5112 
   5113 POST(sys_keyctl)
   5114 {
   5115    vg_assert(SUCCESS);
   5116    switch (ARG1 /* option */) {
   5117    case VKI_KEYCTL_DESCRIBE:
   5118    case VKI_KEYCTL_READ:
   5119       if (RES > ARG4)
   5120          POST_MEM_WRITE(ARG3, ARG4);
   5121       else
   5122          POST_MEM_WRITE(ARG3, RES);
   5123       break;
   5124    default:
   5125       break;
   5126    }
   5127 }
   5128 
   5129 /* ---------------------------------------------------------------------
   5130    ioprio_ wrappers
   5131    ------------------------------------------------------------------ */
   5132 
   5133 PRE(sys_ioprio_set)
   5134 {
   5135    PRINT("sys_ioprio_set ( %ld, %ld, %ld )", SARG1, SARG2, SARG3);
   5136    PRE_REG_READ3(int, "ioprio_set", int, which, int, who, int, ioprio);
   5137 }
   5138 
   5139 PRE(sys_ioprio_get)
   5140 {
   5141    PRINT("sys_ioprio_get ( %ld, %ld )", SARG1, SARG2);
   5142    PRE_REG_READ2(int, "ioprio_get", int, which, int, who);
   5143 }
   5144 
   5145 /* ---------------------------------------------------------------------
   5146    _module wrappers
   5147    ------------------------------------------------------------------ */
   5148 
   5149 PRE(sys_init_module)
   5150 {
   5151    *flags |= SfMayBlock;
   5152    PRINT("sys_init_module ( %#lx, %lu, %#lx(\"%s\") )",
   5153          ARG1, ARG2, ARG3, (HChar*)ARG3);
   5154    PRE_REG_READ3(long, "init_module",
   5155                  void *, umod, unsigned long, len, const char *, uargs);
   5156    PRE_MEM_READ( "init_module(umod)", ARG1, ARG2 );
   5157    PRE_MEM_RASCIIZ( "init_module(uargs)", ARG3 );
   5158 }
   5159 
   5160 PRE(sys_delete_module)
   5161 {
   5162    *flags |= SfMayBlock;
   5163    PRINT("sys_delete_module ( %#lx(\"%s\"), 0x%lx )", ARG1, (HChar*)ARG1, ARG2);
   5164    PRE_REG_READ2(long, "delete_module",
   5165                  const char *, name_user, unsigned int, flags);
   5166    PRE_MEM_RASCIIZ("delete_module(name_user)", ARG1);
   5167 }
   5168 
   5169 /* ---------------------------------------------------------------------
   5170    splice wrappers
   5171    ------------------------------------------------------------------ */
   5172 
   5173 PRE(sys_splice)
   5174 {
   5175    *flags |= SfMayBlock;
   5176    PRINT("sys_splice ( %ld, %#lx, %ld, %#lx, %lu, %#lx )",
   5177          SARG1, ARG2, SARG3, ARG4, ARG5, ARG6);
   5178    PRE_REG_READ6(vki_ssize_t, "splice",
   5179                  int, fd_in, vki_loff_t *, off_in,
   5180                  int, fd_out, vki_loff_t *, off_out,
   5181                  vki_size_t, len, unsigned int, flags);
   5182    if (!ML_(fd_allowed)(ARG1, "splice(fd_in)", tid, False) ||
   5183        !ML_(fd_allowed)(ARG3, "splice(fd_out)", tid, False)) {
   5184       SET_STATUS_Failure( VKI_EBADF );
   5185    } else {
   5186       if (ARG2 != 0)
   5187          PRE_MEM_READ( "splice(off_in)", ARG2, sizeof(vki_loff_t));
   5188       if (ARG4 != 0)
   5189          PRE_MEM_READ( "splice(off_out)", ARG4, sizeof(vki_loff_t));
   5190    }
   5191 }
   5192 
   5193 PRE(sys_tee)
   5194 {
   5195    *flags |= SfMayBlock;
   5196    PRINT("sys_tree ( %ld, %ld, %lu, %#lx )", SARG1, SARG2, ARG3, ARG4);
   5197    PRE_REG_READ4(vki_ssize_t, "tee",
   5198                  int, fd_in, int, fd_out,
   5199                  vki_size_t, len, unsigned int, flags);
   5200    if (!ML_(fd_allowed)(ARG1, "tee(fd_in)", tid, False) ||
   5201        !ML_(fd_allowed)(ARG2, "tee(fd_out)", tid, False)) {
   5202       SET_STATUS_Failure( VKI_EBADF );
   5203    }
   5204 }
   5205 
   5206 PRE(sys_vmsplice)
   5207 {
   5208    Int fdfl;
   5209    *flags |= SfMayBlock;
   5210    PRINT("sys_vmsplice ( %ld, %#lx, %lu, %lu )", SARG1, ARG2, ARG3, ARG4);
   5211    PRE_REG_READ4(vki_ssize_t, "splice",
   5212                  int, fd, struct vki_iovec *, iov,
   5213                  unsigned long, nr_segs, unsigned int, flags);
   5214    if (!ML_(fd_allowed)(ARG1, "vmsplice(fd)", tid, False)) {
   5215       SET_STATUS_Failure( VKI_EBADF );
   5216    } else if ((fdfl = VG_(fcntl)(ARG1, VKI_F_GETFL, 0)) < 0) {
   5217       SET_STATUS_Failure( VKI_EBADF );
   5218    } else {
   5219       const struct vki_iovec *iov;
   5220       PRE_MEM_READ( "vmsplice(iov)", ARG2, sizeof(struct vki_iovec) * ARG3 );
   5221       for (iov = (struct vki_iovec *)ARG2;
   5222            iov < (struct vki_iovec *)ARG2 + ARG3; iov++)
   5223       {
   5224          if ((fdfl & VKI_O_ACCMODE) == VKI_O_RDONLY)
   5225             PRE_MEM_WRITE( "vmsplice(iov[...])", (Addr)iov->iov_base, iov->iov_len );
   5226          else
   5227             PRE_MEM_READ( "vmsplice(iov[...])", (Addr)iov->iov_base, iov->iov_len );
   5228       }
   5229    }
   5230 }
   5231 
   5232 POST(sys_vmsplice)
   5233 {
   5234    vg_assert(SUCCESS);
   5235    if (RES > 0) {
   5236       Int fdfl = VG_(fcntl)(ARG1, VKI_F_GETFL, 0);
   5237       vg_assert(fdfl >= 0);
   5238       if ((fdfl & VKI_O_ACCMODE) == VKI_O_RDONLY)
   5239       {
   5240          const struct vki_iovec *iov;
   5241          for (iov = (struct vki_iovec *)ARG2;
   5242               iov < (struct vki_iovec *)ARG2 + ARG3; iov++)
   5243          {
   5244             POST_MEM_WRITE( (Addr)iov->iov_base, iov->iov_len );
   5245          }
   5246       }
   5247    }
   5248 }
   5249 
   5250 /* ---------------------------------------------------------------------
   5251    oprofile-related wrappers
   5252    ------------------------------------------------------------------ */
   5253 
   5254 #if defined(VGP_x86_linux)
   5255 PRE(sys_lookup_dcookie)
   5256 {
   5257    PRINT("sys_lookup_dcookie (0x%llx, %#lx, %lu)",
   5258          MERGE64(ARG1,ARG2), ARG3, ARG4);
   5259    PRE_REG_READ4(long, "lookup_dcookie",
   5260                  vki_u32, MERGE64_FIRST(cookie), vki_u32, MERGE64_SECOND(cookie),
   5261                  char *, buf, vki_size_t, len);
   5262    PRE_MEM_WRITE( "lookup_dcookie(buf)", ARG3, ARG4);
   5263 }
   5264 POST(sys_lookup_dcookie)
   5265 {
   5266    vg_assert(SUCCESS);
   5267    if (ARG3 != (Addr)NULL)
   5268       POST_MEM_WRITE( ARG3, RES);
   5269 }
   5270 #endif
   5271 
   5272 #if defined(VGP_amd64_linux) || defined(VGP_s390x_linux)        \
   5273       || defined(VGP_tilegx_linux)
   5274 PRE(sys_lookup_dcookie)
   5275 {
   5276    *flags |= SfMayBlock;
   5277    PRINT("sys_lookup_dcookie ( %lu, %#lx, %lu )", ARG1, ARG2, ARG3);
   5278    PRE_REG_READ3(int, "lookup_dcookie",
   5279                  unsigned long long, cookie, char *, buf, vki_size_t, len);
   5280 
   5281    PRE_MEM_WRITE( "sys_lookup_dcookie(buf)", ARG2, ARG3 );
   5282 }
   5283 
   5284 POST(sys_lookup_dcookie)
   5285 {
   5286    vg_assert(SUCCESS);
   5287    if (ARG2 != (Addr)NULL)
   5288      POST_MEM_WRITE( ARG2, RES );
   5289 }
   5290 #endif
   5291 
   5292 /* ---------------------------------------------------------------------
   5293    fcntl wrappers
   5294    ------------------------------------------------------------------ */
   5295 
   5296 PRE(sys_fcntl)
   5297 {
   5298    switch (ARG2) {
   5299    // These ones ignore ARG3.
   5300    case VKI_F_GETFD:
   5301    case VKI_F_GETFL:
   5302    case VKI_F_GETOWN:
   5303    case VKI_F_GETSIG:
   5304    case VKI_F_GETLEASE:
   5305    case VKI_F_GETPIPE_SZ:
   5306       PRINT("sys_fcntl ( %lu, %lu )", ARG1, ARG2);
   5307       PRE_REG_READ2(long, "fcntl", unsigned int, fd, unsigned int, cmd);
   5308       break;
   5309 
   5310    // These ones use ARG3 as "arg".
   5311    case VKI_F_DUPFD:
   5312    case VKI_F_DUPFD_CLOEXEC:
   5313    case VKI_F_SETFD:
   5314    case VKI_F_SETFL:
   5315    case VKI_F_SETLEASE:
   5316    case VKI_F_NOTIFY:
   5317    case VKI_F_SETOWN:
   5318    case VKI_F_SETSIG:
   5319    case VKI_F_SETPIPE_SZ:
   5320       PRINT("sys_fcntl[ARG3=='arg'] ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
   5321       PRE_REG_READ3(long, "fcntl",
   5322                     unsigned int, fd, unsigned int, cmd, unsigned long, arg);
   5323       break;
   5324 
   5325    // These ones use ARG3 as "lock".
   5326    case VKI_F_GETLK:
   5327    case VKI_F_SETLK:
   5328    case VKI_F_SETLKW:
   5329 #  if defined(VGP_x86_linux) || defined(VGP_mips64_linux)
   5330    case VKI_F_GETLK64:
   5331    case VKI_F_SETLK64:
   5332    case VKI_F_SETLKW64:
   5333 #  endif
   5334    case VKI_F_OFD_GETLK:
   5335    case VKI_F_OFD_SETLK:
   5336    case VKI_F_OFD_SETLKW:
   5337       PRINT("sys_fcntl[ARG3=='lock'] ( %lu, %lu, %#lx )", ARG1, ARG2, ARG3);
   5338       PRE_REG_READ3(long, "fcntl",
   5339                     unsigned int, fd, unsigned int, cmd,
   5340                     struct flock64 *, lock);
   5341       break;
   5342 
   5343    case VKI_F_SETOWN_EX:
   5344       PRINT("sys_fcntl[F_SETOWN_EX] ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
   5345       PRE_REG_READ3(long, "fcntl",
   5346                     unsigned int, fd, unsigned int, cmd,
   5347                     struct vki_f_owner_ex *, arg);
   5348       PRE_MEM_READ("fcntl(F_SETOWN_EX)", ARG3, sizeof(struct vki_f_owner_ex));
   5349       break;
   5350 
   5351    case VKI_F_GETOWN_EX:
   5352       PRINT("sys_fcntl[F_GETOWN_EX] ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
   5353       PRE_REG_READ3(long, "fcntl",
   5354                     unsigned int, fd, unsigned int, cmd,
   5355                     struct vki_f_owner_ex *, arg);
   5356       PRE_MEM_WRITE("fcntl(F_GETOWN_EX)", ARG3, sizeof(struct vki_f_owner_ex));
   5357       break;
   5358 
   5359    default:
   5360       PRINT("sys_fcntl[UNKNOWN] ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
   5361       I_die_here;
   5362       break;
   5363    }
   5364 
   5365 #  if defined(VGP_x86_linux)
   5366    if (ARG2 == VKI_F_SETLKW || ARG2 == VKI_F_SETLKW64)
   5367 #  else
   5368    if (ARG2 == VKI_F_SETLKW)
   5369 #  endif
   5370       *flags |= SfMayBlock;
   5371 }
   5372 
   5373 POST(sys_fcntl)
   5374 {
   5375    vg_assert(SUCCESS);
   5376    if (ARG2 == VKI_F_DUPFD) {
   5377       if (!ML_(fd_allowed)(RES, "fcntl(DUPFD)", tid, True)) {
   5378          VG_(close)(RES);
   5379          SET_STATUS_Failure( VKI_EMFILE );
   5380       } else {
   5381          if (VG_(clo_track_fds))
   5382             ML_(record_fd_open_named)(tid, RES);
   5383       }
   5384    }
   5385    else if (ARG2 == VKI_F_DUPFD_CLOEXEC) {
   5386       if (!ML_(fd_allowed)(RES, "fcntl(DUPFD_CLOEXEC)", tid, True)) {
   5387          VG_(close)(RES);
   5388          SET_STATUS_Failure( VKI_EMFILE );
   5389       } else {
   5390          if (VG_(clo_track_fds))
   5391             ML_(record_fd_open_named)(tid, RES);
   5392       }
   5393    } else if (ARG2 == VKI_F_GETOWN_EX) {
   5394       POST_MEM_WRITE(ARG3, sizeof(struct vki_f_owner_ex));
   5395    }
   5396 }
   5397 
   5398 // XXX: wrapper only suitable for 32-bit systems
   5399 PRE(sys_fcntl64)
   5400 {
   5401    switch (ARG2) {
   5402    // These ones ignore ARG3.
   5403    case VKI_F_GETFD:
   5404    case VKI_F_GETFL:
   5405    case VKI_F_GETOWN:
   5406    case VKI_F_SETOWN:
   5407    case VKI_F_GETSIG:
   5408    case VKI_F_SETSIG:
   5409    case VKI_F_GETLEASE:
   5410       PRINT("sys_fcntl64 ( %lu, %lu )", ARG1, ARG2);
   5411       PRE_REG_READ2(long, "fcntl64", unsigned int, fd, unsigned int, cmd);
   5412       break;
   5413 
   5414    // These ones use ARG3 as "arg".
   5415    case VKI_F_DUPFD:
   5416    case VKI_F_DUPFD_CLOEXEC:
   5417    case VKI_F_SETFD:
   5418    case VKI_F_SETFL:
   5419    case VKI_F_SETLEASE:
   5420    case VKI_F_NOTIFY:
   5421       PRINT("sys_fcntl64[ARG3=='arg'] ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
   5422       PRE_REG_READ3(long, "fcntl64",
   5423                     unsigned int, fd, unsigned int, cmd, unsigned long, arg);
   5424       break;
   5425 
   5426    // These ones use ARG3 as "lock".
   5427    case VKI_F_GETLK:
   5428    case VKI_F_SETLK:
   5429    case VKI_F_SETLKW:
   5430 #  if defined(VGP_x86_linux)
   5431    case VKI_F_GETLK64:
   5432    case VKI_F_SETLK64:
   5433    case VKI_F_SETLKW64:
   5434 #  endif
   5435    case VKI_F_OFD_GETLK:
   5436    case VKI_F_OFD_SETLK:
   5437    case VKI_F_OFD_SETLKW:
   5438       PRINT("sys_fcntl64[ARG3=='lock'] ( %lu, %lu, %#lx )", ARG1, ARG2, ARG3);
   5439       PRE_REG_READ3(long, "fcntl64",
   5440                     unsigned int, fd, unsigned int, cmd,
   5441                     struct flock64 *, lock);
   5442       break;
   5443 
   5444    case VKI_F_SETOWN_EX:
   5445       PRINT("sys_fcntl[F_SETOWN_EX] ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
   5446       PRE_REG_READ3(long, "fcntl",
   5447                     unsigned int, fd, unsigned int, cmd,
   5448                     struct vki_f_owner_ex *, arg);
   5449       PRE_MEM_READ("fcntl(F_SETOWN_EX)", ARG3, sizeof(struct vki_f_owner_ex));
   5450       break;
   5451 
   5452    case VKI_F_GETOWN_EX:
   5453       PRINT("sys_fcntl[F_GETOWN_EX] ( %lu, %lu, %lu )", ARG1, ARG2, ARG3);
   5454       PRE_REG_READ3(long, "fcntl",
   5455                     unsigned int, fd, unsigned int, cmd,
   5456                     struct vki_f_owner_ex *, arg);
   5457       PRE_MEM_WRITE("fcntl(F_GETOWN_EX)", ARG3, sizeof(struct vki_f_owner_ex));
   5458       break;
   5459    }
   5460 
   5461 #  if defined(VGP_x86_linux)
   5462    if (ARG2 == VKI_F_SETLKW || ARG2 == VKI_F_SETLKW64)
   5463 #  else
   5464    if (ARG2 == VKI_F_SETLKW)
   5465 #  endif
   5466       *flags |= SfMayBlock;
   5467 }
   5468 
   5469 POST(sys_fcntl64)
   5470 {
   5471    vg_assert(SUCCESS);
   5472    if (ARG2 == VKI_F_DUPFD) {
   5473       if (!ML_(fd_allowed)(RES, "fcntl64(DUPFD)", tid, True)) {
   5474          VG_(close)(RES);
   5475          SET_STATUS_Failure( VKI_EMFILE );
   5476       } else {
   5477          if (VG_(clo_track_fds))
   5478             ML_(record_fd_open_named)(tid, RES);
   5479       }
   5480    }
   5481    else if (ARG2 == VKI_F_DUPFD_CLOEXEC) {
   5482       if (!ML_(fd_allowed)(RES, "fcntl64(DUPFD_CLOEXEC)", tid, True)) {
   5483          VG_(close)(RES);
   5484          SET_STATUS_Failure( VKI_EMFILE );
   5485       } else {
   5486          if (VG_(clo_track_fds))
   5487             ML_(record_fd_open_named)(tid, RES);
   5488       }
   5489    } else if (ARG2 == VKI_F_GETOWN_EX) {
   5490       POST_MEM_WRITE(ARG3, sizeof(struct vki_f_owner_ex));
   5491    }
   5492 }
   5493 
   5494 /* ---------------------------------------------------------------------
   5495    ioctl wrappers
   5496    ------------------------------------------------------------------ */
   5497 
   5498 PRE(sys_ioctl)
   5499 {
   5500    *flags |= SfMayBlock;
   5501 
   5502    ARG2 = (UInt)ARG2;
   5503 
   5504    // We first handle the ones that don't use ARG3 (even as a
   5505    // scalar/non-pointer argument).
   5506    switch (ARG2 /* request */) {
   5507 
   5508       /* asm-generic/ioctls.h */
   5509    case VKI_FIOCLEX:
   5510    case VKI_FIONCLEX:
   5511    case VKI_TIOCNOTTY:
   5512 
   5513       /* linux/soundcard interface (ALSA) */
   5514    case VKI_SNDRV_PCM_IOCTL_HW_FREE:
   5515    case VKI_SNDRV_PCM_IOCTL_HWSYNC:
   5516    case VKI_SNDRV_PCM_IOCTL_PREPARE:
   5517    case VKI_SNDRV_PCM_IOCTL_RESET:
   5518    case VKI_SNDRV_PCM_IOCTL_START:
   5519    case VKI_SNDRV_PCM_IOCTL_DROP:
   5520    case VKI_SNDRV_PCM_IOCTL_DRAIN:
   5521    case VKI_SNDRV_PCM_IOCTL_RESUME:
   5522    case VKI_SNDRV_PCM_IOCTL_XRUN:
   5523    case VKI_SNDRV_PCM_IOCTL_UNLINK:
   5524    case VKI_SNDRV_TIMER_IOCTL_START:
   5525    case VKI_SNDRV_TIMER_IOCTL_STOP:
   5526    case VKI_SNDRV_TIMER_IOCTL_CONTINUE:
   5527    case VKI_SNDRV_TIMER_IOCTL_PAUSE:
   5528 
   5529       /* SCSI no operand */
   5530    case VKI_SCSI_IOCTL_DOORLOCK:
   5531    case VKI_SCSI_IOCTL_DOORUNLOCK:
   5532 
   5533    /* CDROM stuff. */
   5534    case VKI_CDROM_DISC_STATUS:
   5535 
   5536    /* KVM ioctls that dont check for a numeric value as parameter */
   5537    case VKI_KVM_S390_ENABLE_SIE:
   5538    case VKI_KVM_CREATE_IRQCHIP:
   5539    case VKI_KVM_S390_INITIAL_RESET:
   5540    case VKI_KVM_KVMCLOCK_CTRL:
   5541 
   5542    /* vhost without parameter */
   5543    case VKI_VHOST_SET_OWNER:
   5544    case VKI_VHOST_RESET_OWNER:
   5545 
   5546    /* User input device creation */
   5547    case VKI_UI_DEV_CREATE:
   5548    case VKI_UI_DEV_DESTROY:
   5549 
   5550    /* InfiniBand */
   5551    case VKI_IB_USER_MAD_ENABLE_PKEY:
   5552 
   5553    /* Lustre */
   5554    case VKI_LL_IOC_GROUP_LOCK:
   5555    case VKI_LL_IOC_GROUP_UNLOCK:
   5556 
   5557    /* V4L2 */
   5558    case VKI_V4L2_LOG_STATUS:
   5559 
   5560    /* DVB */
   5561    case VKI_DMX_STOP:
   5562       PRINT("sys_ioctl ( %lu, 0x%lx )", ARG1, ARG2);
   5563       PRE_REG_READ2(long, "ioctl",
   5564                     unsigned int, fd, unsigned int, request);
   5565       return;
   5566 
   5567    default:
   5568       PRINT("sys_ioctl ( %lu, 0x%lx, 0x%lx )", ARG1, ARG2, ARG3);
   5569       PRE_REG_READ3(long, "ioctl",
   5570                     unsigned int, fd, unsigned int, request, unsigned long, arg);
   5571       break;
   5572    }
   5573 
   5574    // We now handle those that do look at ARG3 (and unknown ones fall into
   5575    // this category).  Nb: some of these may well belong in the
   5576    // doesn't-use-ARG3 switch above.
   5577    switch (ARG2 /* request */) {
   5578 
   5579    case VKI_ION_IOC_ALLOC: {
   5580       struct vki_ion_allocation_data* data
   5581          = (struct vki_ion_allocation_data*)ARG3;
   5582       PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).len",          data->len);
   5583       PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).align",        data->align);
   5584       PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).heap_id_mask", data->heap_id_mask);
   5585       PRE_FIELD_READ ("ioctl(ION_IOC_ALLOC).flags",        data->flags);
   5586       PRE_FIELD_WRITE("ioctl(ION_IOC_ALLOC).handle",       data->handle);
   5587       break;
   5588    }
   5589    case VKI_ION_IOC_MAP: {
   5590       struct vki_ion_fd_data* data = (struct vki_ion_fd_data*)ARG3;
   5591       PRE_FIELD_READ ("ioctl(ION_IOC_MAP).handle", data->handle);
   5592       PRE_FIELD_WRITE("ioctl(ION_IOC_MAP).fd",     data->fd);
   5593       break;
   5594    }
   5595    case VKI_ION_IOC_IMPORT: {
   5596       struct vki_ion_fd_data* data = (struct vki_ion_fd_data*)ARG3;
   5597       PRE_FIELD_READ ("ioctl(ION_IOC_IMPORT).fd",     data->fd);
   5598       PRE_FIELD_WRITE("ioctl(ION_IOC_IMPORT).handle", data->handle);
   5599       break;
   5600    }
   5601 
   5602    case VKI_SYNC_IOC_MERGE: {
   5603       struct vki_sync_merge_data* data = (struct vki_sync_merge_data*)ARG3;
   5604       PRE_FIELD_READ ("ioctl(SYNC_IOC_MERGE).fd2",   data->fd2);
   5605       PRE_MEM_RASCIIZ("ioctl(SYNC_IOC_MERGE).name",  (Addr)(&data->name[0]));
   5606       PRE_FIELD_WRITE("ioctl(SYNC_IOC_MERGE).fence", data->fence);
   5607       break;
   5608    }
   5609 
   5610    case VKI_TCSETS:
   5611    case VKI_TCSETSW:
   5612    case VKI_TCSETSF:
   5613       PRE_MEM_READ( "ioctl(TCSET{S,SW,SF})", ARG3, sizeof(struct vki_termios) );
   5614       break;
   5615    case VKI_TCGETS:
   5616       PRE_MEM_WRITE( "ioctl(TCGETS)", ARG3, sizeof(struct vki_termios) );
   5617       break;
   5618    case VKI_TCSETA:
   5619    case VKI_TCSETAW:
   5620    case VKI_TCSETAF:
   5621       PRE_MEM_READ( "ioctl(TCSET{A,AW,AF})", ARG3, sizeof(struct vki_termio) );
   5622       break;
   5623    case VKI_TCGETA:
   5624       PRE_MEM_WRITE( "ioctl(TCGETA)", ARG3, sizeof(struct vki_termio) );
   5625       break;
   5626    case VKI_TCSBRK:
   5627    case VKI_TCXONC:
   5628    case VKI_TCSBRKP:
   5629    case VKI_TCFLSH:
   5630    case VKI_TIOCSIG:
   5631       /* These just take an int by value */
   5632       break;
   5633    case VKI_TIOCGWINSZ:
   5634       PRE_MEM_WRITE( "ioctl(TIOCGWINSZ)", ARG3, sizeof(struct vki_winsize) );
   5635       break;
   5636    case VKI_TIOCSWINSZ:
   5637       PRE_MEM_READ( "ioctl(TIOCSWINSZ)",  ARG3, sizeof(struct vki_winsize) );
   5638       break;
   5639    case VKI_TIOCMBIS:
   5640       PRE_MEM_READ( "ioctl(TIOCMBIS)",    ARG3, sizeof(unsigned int) );
   5641       break;
   5642    case VKI_TIOCMBIC:
   5643       PRE_MEM_READ( "ioctl(TIOCMBIC)",    ARG3, sizeof(unsigned int) );
   5644       break;
   5645    case VKI_TIOCMSET:
   5646       PRE_MEM_READ( "ioctl(TIOCMSET)",    ARG3, sizeof(unsigned int) );
   5647       break;
   5648    case VKI_TIOCMGET:
   5649       PRE_MEM_WRITE( "ioctl(TIOCMGET)",   ARG3, sizeof(unsigned int) );
   5650       break;
   5651    case VKI_TIOCLINUX:
   5652       PRE_MEM_READ( "ioctl(TIOCLINUX)",   ARG3, sizeof(char *) );
   5653       if (*(char *)ARG3 == 11) {
   5654 	 PRE_MEM_READ( "ioctl(TIOCLINUX, 11)", ARG3, 2 * sizeof(char *) );
   5655       }
   5656       break;
   5657    case VKI_TIOCGPGRP:
   5658       /* Get process group ID for foreground processing group. */
   5659       PRE_MEM_WRITE( "ioctl(TIOCGPGRP)", ARG3, sizeof(vki_pid_t) );
   5660       break;
   5661    case VKI_TIOCSPGRP:
   5662       /* Set a process group ID? */
   5663       PRE_MEM_WRITE( "ioctl(TIOCGPGRP)", ARG3, sizeof(vki_pid_t) );
   5664       break;
   5665    case VKI_TIOCGPTN: /* Get Pty Number (of pty-mux device) */
   5666       PRE_MEM_WRITE( "ioctl(TIOCGPTN)", ARG3, sizeof(int) );
   5667       break;
   5668    case VKI_TIOCSCTTY:
   5669       /* Just takes an int value.  */
   5670       break;
   5671    case VKI_TIOCSPTLCK: /* Lock/unlock Pty */
   5672       PRE_MEM_READ( "ioctl(TIOCSPTLCK)", ARG3, sizeof(int) );
   5673       break;
   5674    case VKI_FIONBIO:
   5675       PRE_MEM_READ( "ioctl(FIONBIO)",    ARG3, sizeof(int) );
   5676       break;
   5677    case VKI_FIOASYNC:
   5678       PRE_MEM_READ( "ioctl(FIOASYNC)",   ARG3, sizeof(int) );
   5679       break;
   5680    case VKI_FIONREAD:                /* identical to SIOCINQ */
   5681       PRE_MEM_WRITE( "ioctl(FIONREAD)",  ARG3, sizeof(int) );
   5682       break;
   5683    case VKI_FIOQSIZE:
   5684       PRE_MEM_WRITE( "ioctl(FIOQSIZE)",  ARG3, sizeof(vki_loff_t) );
   5685       break;
   5686 
   5687    case VKI_TIOCSERGETLSR:
   5688       PRE_MEM_WRITE( "ioctl(TIOCSERGETLSR)", ARG3, sizeof(int) );
   5689       break;
   5690    case VKI_TIOCGICOUNT:
   5691       PRE_MEM_WRITE( "ioctl(TIOCGICOUNT)", ARG3,
   5692                      sizeof(struct vki_serial_icounter_struct) );
   5693       break;
   5694 
   5695    case VKI_SG_SET_COMMAND_Q:
   5696       PRE_MEM_READ( "ioctl(SG_SET_COMMAND_Q)", ARG3, sizeof(int) );
   5697       break;
   5698    case VKI_SG_IO:
   5699       PRE_MEM_READ( "ioctl(SG_IO)", ARG3, sizeof(vki_sg_io_hdr_t) );
   5700       {
   5701          vki_sg_io_hdr_t *sgio = (vki_sg_io_hdr_t*)ARG3;
   5702          PRE_MEM_READ( "ioctl(SG_IO)", (Addr)sgio->cmdp, sgio->cmd_len );
   5703          if ( sgio->dxfer_direction == VKI_SG_DXFER_TO_DEV ||
   5704               sgio->dxfer_direction == VKI_SG_DXFER_TO_FROM_DEV ) {
   5705             PRE_MEM_READ( "ioctl(SG_IO)", (Addr)sgio->dxferp, sgio->dxfer_len );
   5706          }
   5707       }
   5708       break;
   5709    case VKI_SG_GET_SCSI_ID:
   5710       PRE_MEM_WRITE( "ioctl(SG_GET_SCSI_ID)", ARG3, sizeof(vki_sg_scsi_id_t) );
   5711       break;
   5712    case VKI_SG_SET_RESERVED_SIZE:
   5713       PRE_MEM_READ( "ioctl(SG_SET_RESERVED_SIZE)", ARG3, sizeof(int) );
   5714       break;
   5715    case VKI_SG_SET_TIMEOUT:
   5716       PRE_MEM_READ( "ioctl(SG_SET_TIMEOUT)", ARG3, sizeof(int) );
   5717       break;
   5718    case VKI_SG_GET_RESERVED_SIZE:
   5719       PRE_MEM_WRITE( "ioctl(SG_GET_RESERVED_SIZE)", ARG3, sizeof(int) );
   5720       break;
   5721    case VKI_SG_GET_TIMEOUT:
   5722       break;
   5723    case VKI_SG_GET_VERSION_NUM:
   5724       PRE_MEM_WRITE(  "ioctl(SG_GET_VERSION_NUM)",  ARG3, sizeof(int) );
   5725       break;
   5726    case VKI_SG_EMULATED_HOST: /* 0x2203 */
   5727       PRE_MEM_WRITE( "ioctl(SG_EMULATED_HOST)",    ARG3, sizeof(int) );
   5728       break;
   5729    case VKI_SG_GET_SG_TABLESIZE: /* 0x227f */
   5730       PRE_MEM_WRITE( "ioctl(SG_GET_SG_TABLESIZE)", ARG3, sizeof(int) );
   5731       break;
   5732 
   5733    case VKI_IIOCGETCPS:
   5734       PRE_MEM_WRITE( "ioctl(IIOCGETCPS)", ARG3,
   5735 		     VKI_ISDN_MAX_CHANNELS * 2 * sizeof(unsigned long) );
   5736       break;
   5737    case VKI_IIOCNETGPN:
   5738       PRE_MEM_READ( "ioctl(IIOCNETGPN)",
   5739 		     (Addr)&((vki_isdn_net_ioctl_phone *)ARG3)->name,
   5740 		     sizeof(((vki_isdn_net_ioctl_phone *)ARG3)->name) );
   5741       PRE_MEM_WRITE( "ioctl(IIOCNETGPN)", ARG3,
   5742 		     sizeof(vki_isdn_net_ioctl_phone) );
   5743       break;
   5744 
   5745       /* These all use struct ifreq AFAIK */
   5746    case VKI_SIOCGIFINDEX:        /* get iface index              */
   5747       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFINDEX)",
   5748                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5749       PRE_MEM_WRITE( "ioctl(SIOCGIFINDEX)", ARG3, sizeof(struct vki_ifreq));
   5750       break;
   5751    case VKI_SIOCGIFFLAGS:        /* get flags                    */
   5752       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFFLAGS)",
   5753                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5754       PRE_MEM_WRITE( "ioctl(SIOCGIFFLAGS)", ARG3, sizeof(struct vki_ifreq));
   5755       break;
   5756    case VKI_SIOCGIFHWADDR:       /* Get hardware address         */
   5757       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFHWADDR)",
   5758                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5759       PRE_MEM_WRITE( "ioctl(SIOCGIFHWADDR)", ARG3, sizeof(struct vki_ifreq));
   5760       break;
   5761    case VKI_SIOCGIFMTU:          /* get MTU size                 */
   5762       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMTU)",
   5763                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5764       PRE_MEM_WRITE( "ioctl(SIOCGIFMTU)", ARG3, sizeof(struct vki_ifreq));
   5765       break;
   5766    case VKI_SIOCGIFADDR:         /* get PA address               */
   5767       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFADDR)",
   5768                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5769       PRE_MEM_WRITE( "ioctl(SIOCGIFADDR)", ARG3, sizeof(struct vki_ifreq));
   5770       break;
   5771    case VKI_SIOCGIFNETMASK:      /* get network PA mask          */
   5772       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFNETMASK)",
   5773                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5774       PRE_MEM_WRITE( "ioctl(SIOCGIFNETMASK)", ARG3, sizeof(struct vki_ifreq));
   5775       break;
   5776    case VKI_SIOCGIFMETRIC:       /* get metric                   */
   5777       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMETRIC)",
   5778                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5779       PRE_MEM_WRITE( "ioctl(SIOCGIFMETRIC)", ARG3, sizeof(struct vki_ifreq));
   5780       break;
   5781    case VKI_SIOCGIFMAP:          /* Get device parameters        */
   5782       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMAP)",
   5783                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5784       PRE_MEM_WRITE( "ioctl(SIOCGIFMAP)", ARG3, sizeof(struct vki_ifreq));
   5785       break;
   5786    case VKI_SIOCGIFTXQLEN:       /* Get the tx queue length      */
   5787       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFTXQLEN)",
   5788                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5789       PRE_MEM_WRITE( "ioctl(SIOCGIFTXQLEN)", ARG3, sizeof(struct vki_ifreq));
   5790       break;
   5791    case VKI_SIOCGIFDSTADDR:      /* get remote PA address        */
   5792       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFDSTADDR)",
   5793                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5794       PRE_MEM_WRITE( "ioctl(SIOCGIFDSTADDR)", ARG3, sizeof(struct vki_ifreq));
   5795       break;
   5796    case VKI_SIOCGIFBRDADDR:      /* get broadcast PA address     */
   5797       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFBRDADDR)",
   5798                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5799       PRE_MEM_WRITE( "ioctl(SIOCGIFBRDADDR)", ARG3, sizeof(struct vki_ifreq));
   5800       break;
   5801    case VKI_SIOCGIFNAME:         /* get iface name               */
   5802       PRE_MEM_READ( "ioctl(SIOCGIFNAME)",
   5803                      (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_ifindex,
   5804                      sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_ifindex) );
   5805       PRE_MEM_WRITE( "ioctl(SIOCGIFNAME)", ARG3, sizeof(struct vki_ifreq));
   5806       break;
   5807    case VKI_SIOCETHTOOL: {       /* ethtool(8) interface         */
   5808       struct vki_ifreq *ir = (struct vki_ifreq *)ARG3;
   5809       PRE_MEM_READ( "ioctl(SIOCETHTOOL)", (Addr)ir, sizeof(struct vki_ifreq) );
   5810       PRE_MEM_RASCIIZ( "ioctl(SIOCETHTOOL)", (Addr)ir->vki_ifr_name );
   5811       PRE_MEM_READ( "ioctl(SIOCETHTOOL)", (Addr)ir->vki_ifr_data, sizeof(vki_u32) );
   5812       PRINT("SIOCETHTOOL( 0x%x )", *(vki_u32 *)ir->vki_ifr_data );
   5813       switch ( *(vki_u32 *)ir->vki_ifr_data ) {
   5814       case VKI_ETHTOOL_GSET:
   5815          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GSET)",
   5816                         (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_cmd) );
   5817          break;
   5818       case VKI_ETHTOOL_SSET:
   5819          PRE_MEM_READ( "ioctl(SIOCETHTOOL,SSET)",
   5820                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_cmd) );
   5821          break;
   5822       case VKI_ETHTOOL_GDRVINFO:
   5823          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GDRVINFO)",
   5824                         (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_drvinfo) );
   5825          break;
   5826       case VKI_ETHTOOL_GREGS:
   5827          PRE_MEM_READ( "ioctl(SIOCETHTOOL,GREGS)",
   5828                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_regs) );
   5829          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GREGS)",
   5830                         (Addr)((struct vki_ethtool_regs *)ir->vki_ifr_data)->data,
   5831                         ((struct vki_ethtool_regs *)ir->vki_ifr_data)->len );
   5832          break;
   5833       case VKI_ETHTOOL_GWOL:
   5834          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GWOL)",
   5835                         (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_wolinfo) );
   5836          break;
   5837       case VKI_ETHTOOL_SWOL:
   5838          PRE_MEM_READ( "ioctl(SIOCETHTOOL,SWOL)",
   5839                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_wolinfo) );
   5840          break;
   5841       case VKI_ETHTOOL_GMSGLVL:
   5842       case VKI_ETHTOOL_GLINK:
   5843       case VKI_ETHTOOL_GRXCSUM:
   5844       case VKI_ETHTOOL_GSG:
   5845       case VKI_ETHTOOL_GTSO:
   5846       case VKI_ETHTOOL_GUFO:
   5847       case VKI_ETHTOOL_GGSO:
   5848       case VKI_ETHTOOL_GFLAGS:
   5849       case VKI_ETHTOOL_GGRO:
   5850          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,Gvalue)",
   5851                         (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_value) );
   5852          break;
   5853       case VKI_ETHTOOL_SMSGLVL:
   5854       case VKI_ETHTOOL_SRXCSUM:
   5855       case VKI_ETHTOOL_SSG:
   5856       case VKI_ETHTOOL_STSO:
   5857       case VKI_ETHTOOL_SUFO:
   5858       case VKI_ETHTOOL_SGSO:
   5859       case VKI_ETHTOOL_SFLAGS:
   5860       case VKI_ETHTOOL_SGRO:
   5861          PRE_MEM_READ( "ioctl(SIOCETHTOOL,Svalue)",
   5862                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_value) );
   5863          break;
   5864       case VKI_ETHTOOL_NWAY_RST:
   5865          break;
   5866       case VKI_ETHTOOL_GRINGPARAM:
   5867          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GRINGPARAM)",
   5868                         (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_ringparam) );
   5869          break;
   5870       case VKI_ETHTOOL_SRINGPARAM:
   5871          PRE_MEM_READ( "ioctl(SIOCETHTOOL,SRINGPARAM)",
   5872                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_ringparam) );
   5873          break;
   5874       case VKI_ETHTOOL_TEST:
   5875          PRE_MEM_READ( "ioctl(SIOCETHTOOL,TEST)",
   5876                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_test) );
   5877          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,TEST)",
   5878                         (Addr)((struct vki_ethtool_test *)ir->vki_ifr_data)->data,
   5879                         ((struct vki_ethtool_test *)ir->vki_ifr_data)->len * sizeof(__vki_u64) );
   5880          break;
   5881       case VKI_ETHTOOL_PHYS_ID:
   5882          break;
   5883       case VKI_ETHTOOL_GPERMADDR:
   5884          PRE_MEM_READ( "ioctl(SIOCETHTOOL,GPERMADDR)",
   5885                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_perm_addr) );
   5886          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GPERMADDR)",
   5887                         (Addr)((struct vki_ethtool_perm_addr *)ir->vki_ifr_data)->data,
   5888                         ((struct vki_ethtool_perm_addr *)ir->vki_ifr_data)->size );
   5889          break;
   5890       case VKI_ETHTOOL_RESET:
   5891          break;
   5892       case VKI_ETHTOOL_GSSET_INFO:
   5893          PRE_MEM_READ( "ioctl(SIOCETHTOOL,GSSET_INFO)",
   5894                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_sset_info) );
   5895          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GSSET_INFO)",
   5896                         (Addr)((struct vki_ethtool_sset_info *)ir->vki_ifr_data)->data,
   5897                         __builtin_popcountll(((struct vki_ethtool_sset_info *)ir->vki_ifr_data)->sset_mask) * sizeof(__vki_u32) );
   5898          break;
   5899       case VKI_ETHTOOL_GFEATURES:
   5900          PRE_MEM_READ( "ioctl(SIOCETHTOOL,GFEATURES)",
   5901                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_gfeatures) );
   5902          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GFEATURES)",
   5903                         (Addr)((struct vki_ethtool_gfeatures *)ir->vki_ifr_data)->features,
   5904                         ((struct vki_ethtool_gfeatures *)ir->vki_ifr_data)->size * sizeof(struct vki_ethtool_get_features_block) );
   5905          break;
   5906       case VKI_ETHTOOL_SFEATURES:
   5907          PRE_MEM_READ( "ioctl(SIOCETHTOOL,SFEATURES)",
   5908                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_sfeatures) );
   5909          PRE_MEM_READ( "ioctl(SIOCETHTOOL,SFEATURES)",
   5910                        (Addr)((struct vki_ethtool_sfeatures *)ir->vki_ifr_data)->features,
   5911                        ((struct vki_ethtool_sfeatures *)ir->vki_ifr_data)->size * sizeof(struct vki_ethtool_set_features_block) );
   5912          break;
   5913       case VKI_ETHTOOL_GCHANNELS:
   5914          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GCHANNELS)",
   5915                         (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_channels) );
   5916          break;
   5917       case VKI_ETHTOOL_SCHANNELS:
   5918          PRE_MEM_READ( "ioctl(SIOCETHTOOL,SCHANNELS)",
   5919                        (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_channels) );
   5920          break;
   5921       case VKI_ETHTOOL_GET_TS_INFO:
   5922          PRE_MEM_WRITE( "ioctl(SIOCETHTOOL,GET_TS_INFO)",
   5923                         (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_ts_info) );
   5924          break;
   5925       }
   5926       break;
   5927    }
   5928    case VKI_SIOCGMIIPHY:         /* get hardware entry           */
   5929       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIPHY)",
   5930                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5931       PRE_MEM_WRITE( "ioctl(SIOCGIFMIIPHY)", ARG3, sizeof(struct vki_ifreq));
   5932       break;
   5933    case VKI_SIOCGMIIREG:         /* get hardware entry registers */
   5934       PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIREG)",
   5935                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5936       PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)",
   5937                      (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id,
   5938                      sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) );
   5939       PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)",
   5940                      (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num,
   5941                      sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num) );
   5942       PRE_MEM_WRITE( "ioctl(SIOCGIFMIIREG)", ARG3,
   5943 		     sizeof(struct vki_ifreq));
   5944       break;
   5945    case VKI_SIOCGIFCONF:         /* get iface list               */
   5946       /* WAS:
   5947 	 PRE_MEM_WRITE( "ioctl(SIOCGIFCONF)", ARG3, sizeof(struct ifconf));
   5948 	 KERNEL_DO_SYSCALL(tid,RES);
   5949 	 if (!VG_(is_kerror)(RES) && RES == 0)
   5950 	 POST_MEM_WRITE(ARG3, sizeof(struct ifconf));
   5951       */
   5952       PRE_MEM_READ( "ioctl(SIOCGIFCONF)",
   5953                     (Addr)&((struct vki_ifconf *)ARG3)->ifc_len,
   5954                     sizeof(((struct vki_ifconf *)ARG3)->ifc_len));
   5955       PRE_MEM_READ( "ioctl(SIOCGIFCONF)",
   5956                     (Addr)&((struct vki_ifconf *)ARG3)->vki_ifc_buf,
   5957                     sizeof(((struct vki_ifconf *)ARG3)->vki_ifc_buf));
   5958       if ( ARG3 ) {
   5959 	 // TODO len must be readable and writable
   5960 	 // buf pointer only needs to be readable
   5961 	 struct vki_ifconf *ifc = (struct vki_ifconf *) ARG3;
   5962 	 PRE_MEM_WRITE( "ioctl(SIOCGIFCONF).ifc_buf",
   5963 			(Addr)(ifc->vki_ifc_buf), ifc->ifc_len );
   5964       }
   5965       break;
   5966    case VKI_SIOCGSTAMP:
   5967       PRE_MEM_WRITE( "ioctl(SIOCGSTAMP)", ARG3, sizeof(struct vki_timeval));
   5968       break;
   5969    case VKI_SIOCGSTAMPNS:
   5970       PRE_MEM_WRITE( "ioctl(SIOCGSTAMPNS)", ARG3, sizeof(struct vki_timespec));
   5971       break;
   5972       /* SIOCOUTQ is an ioctl that, when called on a socket, returns
   5973 	 the number of bytes currently in that socket's send buffer.
   5974 	 It writes this value as an int to the memory location
   5975 	 indicated by the third argument of ioctl(2). */
   5976    case VKI_SIOCOUTQ:
   5977       PRE_MEM_WRITE( "ioctl(SIOCOUTQ)", ARG3, sizeof(int));
   5978       break;
   5979    case VKI_SIOCGRARP:           /* get RARP table entry         */
   5980    case VKI_SIOCGARP:            /* get ARP table entry          */
   5981       PRE_MEM_WRITE( "ioctl(SIOCGARP)", ARG3, sizeof(struct vki_arpreq));
   5982       break;
   5983 
   5984    case VKI_SIOCSIFFLAGS:        /* set flags                    */
   5985       PRE_MEM_RASCIIZ( "ioctl(SIOCSIFFLAGS)",
   5986                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5987       PRE_MEM_READ( "ioctl(SIOCSIFFLAGS)",
   5988                      (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags,
   5989                      sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) );
   5990       break;
   5991    case VKI_SIOCSIFMAP:          /* Set device parameters        */
   5992       PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMAP)",
   5993                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   5994       PRE_MEM_READ( "ioctl(SIOCSIFMAP)",
   5995                      (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_map,
   5996                      sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_map) );
   5997       break;
   5998    case VKI_SIOCSHWTSTAMP:       /* Set hardware time stamping   */
   5999       PRE_MEM_RASCIIZ( "ioctl(SIOCSHWTSTAMP)",
   6000                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   6001       PRE_MEM_READ( "ioctl(SIOCSHWTSTAMP)",
   6002                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_data,
   6003                      sizeof(struct vki_hwtstamp_config) );
   6004       break;
   6005    case VKI_SIOCSIFTXQLEN:       /* Set the tx queue length      */
   6006       PRE_MEM_RASCIIZ( "ioctl(SIOCSIFTXQLEN)",
   6007                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   6008       PRE_MEM_READ( "ioctl(SIOCSIFTXQLEN)",
   6009                      (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_qlen,
   6010                      sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_qlen) );
   6011       break;
   6012    case VKI_SIOCSIFADDR:         /* set PA address               */
   6013    case VKI_SIOCSIFDSTADDR:      /* set remote PA address        */
   6014    case VKI_SIOCSIFBRDADDR:      /* set broadcast PA address     */
   6015    case VKI_SIOCSIFNETMASK:      /* set network PA mask          */
   6016       PRE_MEM_RASCIIZ( "ioctl(SIOCSIF*ADDR)",
   6017                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   6018       PRE_MEM_READ( "ioctl(SIOCSIF*ADDR)",
   6019                      (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_addr,
   6020                      sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_addr) );
   6021       break;
   6022    case VKI_SIOCSIFMETRIC:       /* set metric                   */
   6023       PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMETRIC)",
   6024                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   6025       PRE_MEM_READ( "ioctl(SIOCSIFMETRIC)",
   6026                      (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_metric,
   6027                      sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_metric) );
   6028       break;
   6029    case VKI_SIOCSIFMTU:          /* set MTU size                 */
   6030       PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMTU)",
   6031                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   6032       PRE_MEM_READ( "ioctl(SIOCSIFMTU)",
   6033                      (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_mtu,
   6034                      sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_mtu) );
   6035       break;
   6036    case VKI_SIOCSIFHWADDR:       /* set hardware address         */
   6037       PRE_MEM_RASCIIZ( "ioctl(SIOCSIFHWADDR)",
   6038                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   6039       PRE_MEM_READ( "ioctl(SIOCSIFHWADDR)",
   6040                      (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_hwaddr,
   6041                      sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_hwaddr) );
   6042       break;
   6043    case VKI_SIOCSMIIREG:         /* set hardware entry registers */
   6044       PRE_MEM_RASCIIZ( "ioctl(SIOCSMIIREG)",
   6045                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   6046       PRE_MEM_READ( "ioctl(SIOCSMIIREG)",
   6047                      (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id,
   6048                      sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) );
   6049       PRE_MEM_READ( "ioctl(SIOCSMIIREG)",
   6050                      (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num,
   6051                      sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num) );
   6052       PRE_MEM_READ( "ioctl(SIOCSMIIREG)",
   6053                      (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_in,
   6054                      sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_in) );
   6055       break;
   6056       /* Routing table calls.  */
   6057    case VKI_SIOCADDRT:           /* add routing table entry      */
   6058    case VKI_SIOCDELRT:           /* delete routing table entry   */
   6059       PRE_MEM_READ( "ioctl(SIOCADDRT/DELRT)", ARG3,
   6060 		    sizeof(struct vki_rtentry));
   6061       break;
   6062 
   6063       /* tun/tap related ioctls */
   6064    case VKI_TUNSETNOCSUM:
   6065    case VKI_TUNSETDEBUG:
   6066       break;
   6067    case VKI_TUNSETIFF:
   6068       PRE_MEM_RASCIIZ( "ioctl(TUNSETIFF)",
   6069                      (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name );
   6070       PRE_MEM_READ( "ioctl(TUNSETIFF)",
   6071                      (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags,
   6072                      sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) );
   6073       PRE_MEM_WRITE( "ioctl(TUNSETIFF)", ARG3, sizeof(struct vki_ifreq) );
   6074       break;
   6075    case VKI_TUNSETPERSIST:
   6076    case VKI_TUNSETOWNER:
   6077    case VKI_TUNSETLINK:
   6078    case VKI_TUNSETGROUP:
   6079       break;
   6080    case VKI_TUNGETFEATURES:
   6081       PRE_MEM_WRITE( "ioctl(TUNGETFEATURES)", ARG3, sizeof(unsigned int) );
   6082       break;
   6083    case VKI_TUNSETOFFLOAD:
   6084       break;
   6085    case VKI_TUNGETIFF:
   6086       PRE_MEM_WRITE( "ioctl(TUNGETIFF)", ARG3, sizeof(struct vki_ifreq) );
   6087       break;
   6088    case VKI_TUNGETSNDBUF:
   6089       PRE_MEM_WRITE( "ioctl(TUNGETSNDBUF)", ARG3, sizeof(int) );
   6090       break;
   6091    case VKI_TUNSETSNDBUF:
   6092       PRE_MEM_READ( "ioctl(TUNSETSNDBUF)", ARG3, sizeof(int) );
   6093       break;
   6094    case VKI_TUNGETVNETHDRSZ:
   6095       PRE_MEM_WRITE( "ioctl(TUNGETVNETHDRSZ)", ARG3, sizeof(int) );
   6096       break;
   6097    case VKI_TUNSETVNETHDRSZ:
   6098       PRE_MEM_READ( "ioctl(TUNSETVNETHDRSZ)", ARG3, sizeof(int) );
   6099       break;
   6100    case VKI_TUNSETQUEUE:
   6101       PRE_MEM_READ( "ioctl(TUNSETQUEUE)",
   6102                      (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags,
   6103                      sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) );
   6104       break;
   6105    case VKI_TUNSETIFINDEX:
   6106       PRE_MEM_READ( "ioctl(TUNSETIFINDEX)", ARG3, sizeof(unsigned int));
   6107       break;
   6108 
   6109       /* RARP cache control calls. */
   6110    case VKI_SIOCDRARP:           /* delete RARP table entry      */
   6111    case VKI_SIOCSRARP:           /* set RARP table entry         */
   6112       /* ARP cache control calls. */
   6113    case VKI_SIOCSARP:            /* set ARP table entry          */
   6114    case VKI_SIOCDARP:            /* delete ARP table entry       */
   6115       PRE_MEM_READ( "ioctl(SIOCSIFFLAGS)", ARG3, sizeof(struct vki_ifreq));
   6116       break;
   6117 
   6118    case VKI_SIOCGPGRP:
   6119       PRE_MEM_WRITE( "ioctl(SIOCGPGRP)", ARG3, sizeof(int) );
   6120       break;
   6121    case VKI_SIOCSPGRP:
   6122       PRE_MEM_READ( "ioctl(SIOCSPGRP)", ARG3, sizeof(int) );
   6123       //tst->sys_flags &= ~SfMayBlock;
   6124       break;
   6125 
   6126     case VKI_SIOCATMARK:
   6127       PRE_MEM_READ( "ioctl(SIOCATMARK)", ARG3, sizeof(int) );
   6128       break;
   6129 
   6130       /* linux/soundcard interface (OSS) */
   6131    case VKI_SNDCTL_SEQ_GETOUTCOUNT:
   6132    case VKI_SNDCTL_SEQ_GETINCOUNT:
   6133    case VKI_SNDCTL_SEQ_PERCMODE:
   6134    case VKI_SNDCTL_SEQ_TESTMIDI:
   6135    case VKI_SNDCTL_SEQ_RESETSAMPLES:
   6136    case VKI_SNDCTL_SEQ_NRSYNTHS:
   6137    case VKI_SNDCTL_SEQ_NRMIDIS:
   6138    case VKI_SNDCTL_SEQ_GETTIME:
   6139    case VKI_SNDCTL_DSP_GETBLKSIZE:
   6140    case VKI_SNDCTL_DSP_GETFMTS:
   6141    case VKI_SNDCTL_DSP_GETTRIGGER:
   6142    case VKI_SNDCTL_DSP_GETODELAY:
   6143    case VKI_SNDCTL_DSP_GETSPDIF:
   6144    case VKI_SNDCTL_DSP_GETCAPS:
   6145    case VKI_SOUND_PCM_READ_RATE:
   6146    case VKI_SOUND_PCM_READ_CHANNELS:
   6147    case VKI_SOUND_PCM_READ_BITS:
   6148    case VKI_SOUND_PCM_READ_FILTER:
   6149       PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOR, int))",
   6150 		     ARG3, sizeof(int));
   6151       break;
   6152    case VKI_SNDCTL_SEQ_CTRLRATE:
   6153    case VKI_SNDCTL_DSP_SPEED:
   6154    case VKI_SNDCTL_DSP_STEREO:
   6155    case VKI_SNDCTL_DSP_CHANNELS:
   6156    case VKI_SOUND_PCM_WRITE_FILTER:
   6157    case VKI_SNDCTL_DSP_SUBDIVIDE:
   6158    case VKI_SNDCTL_DSP_SETFRAGMENT:
   6159    case VKI_SNDCTL_DSP_SETFMT:
   6160    case VKI_SNDCTL_DSP_GETCHANNELMASK:
   6161    case VKI_SNDCTL_DSP_BIND_CHANNEL:
   6162    case VKI_SNDCTL_TMR_TIMEBASE:
   6163    case VKI_SNDCTL_TMR_TEMPO:
   6164    case VKI_SNDCTL_TMR_SOURCE:
   6165    case VKI_SNDCTL_MIDI_PRETIME:
   6166    case VKI_SNDCTL_MIDI_MPUMODE:
   6167       PRE_MEM_READ( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOWR, int))",
   6168 		     ARG3, sizeof(int));
   6169       PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOWR, int))",
   6170 		     ARG3, sizeof(int));
   6171       break;
   6172    case VKI_SNDCTL_DSP_GETOSPACE:
   6173    case VKI_SNDCTL_DSP_GETISPACE:
   6174       PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOR, audio_buf_info))",
   6175                      ARG3, sizeof(vki_audio_buf_info));
   6176       break;
   6177    case VKI_SNDCTL_DSP_NONBLOCK:
   6178       break;
   6179    case VKI_SNDCTL_DSP_SETTRIGGER:
   6180       PRE_MEM_READ( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOW, int))",
   6181 		     ARG3, sizeof(int));
   6182       break;
   6183 
   6184    case VKI_SNDCTL_DSP_POST:
   6185    case VKI_SNDCTL_DSP_RESET:
   6186    case VKI_SNDCTL_DSP_SYNC:
   6187    case VKI_SNDCTL_DSP_SETSYNCRO:
   6188    case VKI_SNDCTL_DSP_SETDUPLEX:
   6189       break;
   6190 
   6191       /* linux/soundcard interface (ALSA) */
   6192    case VKI_SNDRV_PCM_IOCTL_PAUSE:
   6193    case VKI_SNDRV_PCM_IOCTL_LINK:
   6194       /* these just take an int by value */
   6195       break;
   6196    case VKI_SNDRV_CTL_IOCTL_PVERSION:
   6197       PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_PVERSION)", (Addr)ARG3, sizeof(int) );
   6198       break;
   6199    case VKI_SNDRV_CTL_IOCTL_CARD_INFO:
   6200       PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_CARD_INFO)", (Addr)ARG3, sizeof(struct vki_snd_ctl_card_info) );
   6201       break;
   6202    case VKI_SNDRV_CTL_IOCTL_ELEM_LIST: {
   6203       struct vki_snd_ctl_elem_list *data = (struct vki_snd_ctl_elem_list *)ARG3;
   6204       PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr)&data->offset, sizeof(data->offset) );
   6205       PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr)&data->space, sizeof(data->space) );
   6206       PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr)&data->used, sizeof(data->used) );
   6207       PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr)&data->count, sizeof(data->count) );
   6208       PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr)&data->pids, sizeof(data->pids) );
   6209       if (data->pids) {
   6210          PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_ELEM_LIST)", (Addr)data->pids, sizeof(struct vki_snd_ctl_elem_id) * data->space );
   6211       }
   6212       break;
   6213    }
   6214    case VKI_SNDRV_CTL_IOCTL_TLV_READ: {
   6215       struct vki_snd_ctl_tlv *data = (struct vki_snd_ctl_tlv *)ARG3;
   6216       PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_READ)", (Addr)&data->numid, sizeof(data->numid) );
   6217       PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_READ)", (Addr)&data->length, sizeof(data->length) );
   6218       PRE_MEM_WRITE( "ioctl(SNDRV_CTL_IOCTL_TLV_READ)", (Addr)data->tlv, data->length );
   6219       break;
   6220    }
   6221    case VKI_SNDRV_CTL_IOCTL_TLV_WRITE:
   6222    case VKI_SNDRV_CTL_IOCTL_TLV_COMMAND: {
   6223       struct vki_snd_ctl_tlv *data = (struct vki_snd_ctl_tlv *)ARG3;
   6224       PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_WRITE)", (Addr)&data->numid, sizeof(data->numid) );
   6225       PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_WRITE)", (Addr)&data->length, sizeof(data->length) );
   6226       PRE_MEM_READ( "ioctl(SNDRV_CTL_IOCTL_TLV_WRITE)", (Addr)data->tlv, data->length );
   6227       break;
   6228    }
   6229 
   6230       /* Real Time Clock (/dev/rtc) ioctls */
   6231    case VKI_RTC_UIE_ON:
   6232    case VKI_RTC_UIE_OFF:
   6233    case VKI_RTC_AIE_ON:
   6234    case VKI_RTC_AIE_OFF:
   6235    case VKI_RTC_PIE_ON:
   6236    case VKI_RTC_PIE_OFF:
   6237    case VKI_RTC_IRQP_SET:
   6238       break;
   6239    case VKI_RTC_RD_TIME:
   6240    case VKI_RTC_ALM_READ:
   6241       PRE_MEM_WRITE( "ioctl(RTC_RD_TIME/ALM_READ)",
   6242 		     ARG3, sizeof(struct vki_rtc_time));
   6243       break;
   6244    case VKI_RTC_ALM_SET:
   6245       PRE_MEM_READ( "ioctl(RTC_ALM_SET)", ARG3, sizeof(struct vki_rtc_time));
   6246       break;
   6247    case VKI_RTC_IRQP_READ:
   6248       PRE_MEM_WRITE( "ioctl(RTC_IRQP_READ)", ARG3, sizeof(unsigned long));
   6249       break;
   6250 
   6251       /* Block devices */
   6252    case VKI_BLKROSET:
   6253       PRE_MEM_READ( "ioctl(BLKROSET)", ARG3, sizeof(int));
   6254       break;
   6255    case VKI_BLKROGET:
   6256       PRE_MEM_WRITE( "ioctl(BLKROGET)", ARG3, sizeof(int));
   6257       break;
   6258    case VKI_BLKGETSIZE:
   6259       PRE_MEM_WRITE( "ioctl(BLKGETSIZE)", ARG3, sizeof(unsigned long));
   6260       break;
   6261    case VKI_BLKRASET:
   6262       break;
   6263    case VKI_BLKRAGET:
   6264       PRE_MEM_WRITE( "ioctl(BLKRAGET)", ARG3, sizeof(long));
   6265       break;
   6266    case VKI_BLKFRASET:
   6267       break;
   6268    case VKI_BLKFRAGET:
   6269       PRE_MEM_WRITE( "ioctl(BLKFRAGET)", ARG3, sizeof(long));
   6270       break;
   6271    case VKI_BLKSECTGET:
   6272       PRE_MEM_WRITE( "ioctl(BLKSECTGET)", ARG3, sizeof(unsigned short));
   6273       break;
   6274    case VKI_BLKSSZGET:
   6275       PRE_MEM_WRITE( "ioctl(BLKSSZGET)", ARG3, sizeof(int));
   6276       break;
   6277    case VKI_BLKBSZGET:
   6278       PRE_MEM_WRITE( "ioctl(BLKBSZGET)", ARG3, sizeof(int));
   6279       break;
   6280    case VKI_BLKBSZSET:
   6281       PRE_MEM_READ( "ioctl(BLKBSZSET)", ARG3, sizeof(int));
   6282       break;
   6283    case VKI_BLKGETSIZE64:
   6284       PRE_MEM_WRITE( "ioctl(BLKGETSIZE64)", ARG3, sizeof(unsigned long long));
   6285       break;
   6286    case VKI_BLKPBSZGET:
   6287       PRE_MEM_WRITE( "ioctl(BLKPBSZGET)", ARG3, sizeof(int));
   6288       break;
   6289    case VKI_BLKDISCARDZEROES:
   6290       PRE_MEM_WRITE( "ioctl(BLKDISCARDZEROES)", ARG3, sizeof(vki_uint));
   6291       break;
   6292 
   6293       /* Hard disks */
   6294    case VKI_HDIO_GETGEO: /* 0x0301 */
   6295       PRE_MEM_WRITE( "ioctl(HDIO_GETGEO)", ARG3, sizeof(struct vki_hd_geometry));
   6296       break;
   6297    case VKI_HDIO_GET_DMA: /* 0x030b */
   6298       PRE_MEM_WRITE( "ioctl(HDIO_GET_DMA)", ARG3, sizeof(long));
   6299       break;
   6300    case VKI_HDIO_GET_IDENTITY: /* 0x030d */
   6301       PRE_MEM_WRITE( "ioctl(HDIO_GET_IDENTITY)", ARG3,
   6302                      VKI_SIZEOF_STRUCT_HD_DRIVEID );
   6303       break;
   6304 
   6305       /* SCSI */
   6306    case VKI_SCSI_IOCTL_GET_IDLUN: /* 0x5382 */
   6307       PRE_MEM_WRITE( "ioctl(SCSI_IOCTL_GET_IDLUN)", ARG3, sizeof(struct vki_scsi_idlun));
   6308       break;
   6309    case VKI_SCSI_IOCTL_GET_BUS_NUMBER: /* 0x5386 */
   6310       PRE_MEM_WRITE( "ioctl(SCSI_IOCTL_GET_BUS_NUMBER)", ARG3, sizeof(int));
   6311       break;
   6312 
   6313       /* CD ROM stuff (??)  */
   6314    case VKI_CDROM_GET_MCN:
   6315       PRE_MEM_READ( "ioctl(CDROM_GET_MCN)", ARG3,
   6316                     sizeof(struct vki_cdrom_mcn) );
   6317       break;
   6318    case VKI_CDROM_SEND_PACKET:
   6319       PRE_MEM_READ( "ioctl(CDROM_SEND_PACKET)", ARG3,
   6320                     sizeof(struct vki_cdrom_generic_command));
   6321       break;
   6322    case VKI_CDROMSUBCHNL:
   6323       PRE_MEM_READ( "ioctl(CDROMSUBCHNL (cdsc_format, char))",
   6324 		    (Addr) &(((struct vki_cdrom_subchnl*) ARG3)->cdsc_format),
   6325 		    sizeof(((struct vki_cdrom_subchnl*) ARG3)->cdsc_format));
   6326       PRE_MEM_WRITE( "ioctl(CDROMSUBCHNL)", ARG3,
   6327 		     sizeof(struct vki_cdrom_subchnl));
   6328       break;
   6329    case VKI_CDROMREADMODE2:
   6330       PRE_MEM_READ( "ioctl(CDROMREADMODE2)", ARG3, VKI_CD_FRAMESIZE_RAW0 );
   6331       break;
   6332    case VKI_CDROMREADTOCHDR:
   6333       PRE_MEM_WRITE( "ioctl(CDROMREADTOCHDR)", ARG3,
   6334 		     sizeof(struct vki_cdrom_tochdr));
   6335       break;
   6336    case VKI_CDROMREADTOCENTRY:
   6337       PRE_MEM_READ( "ioctl(CDROMREADTOCENTRY (cdte_format, char))",
   6338 		    (Addr) &(((struct vki_cdrom_tocentry*) ARG3)->cdte_format),
   6339 		    sizeof(((struct vki_cdrom_tocentry*) ARG3)->cdte_format));
   6340       PRE_MEM_READ( "ioctl(CDROMREADTOCENTRY (cdte_track, char))",
   6341 		    (Addr) &(((struct vki_cdrom_tocentry*) ARG3)->cdte_track),
   6342 		    sizeof(((struct vki_cdrom_tocentry*) ARG3)->cdte_track));
   6343       PRE_MEM_WRITE( "ioctl(CDROMREADTOCENTRY)", ARG3,
   6344 		     sizeof(struct vki_cdrom_tocentry));
   6345       break;
   6346    case VKI_CDROMMULTISESSION: /* 0x5310 */
   6347       PRE_MEM_WRITE( "ioctl(CDROMMULTISESSION)", ARG3,
   6348 		     sizeof(struct vki_cdrom_multisession));
   6349       break;
   6350    case VKI_CDROMVOLREAD: /* 0x5313 */
   6351       PRE_MEM_WRITE( "ioctl(CDROMVOLREAD)", ARG3,
   6352 		     sizeof(struct vki_cdrom_volctrl));
   6353       break;
   6354    case VKI_CDROMREADRAW: /* 0x5314 */
   6355       PRE_MEM_READ( "ioctl(CDROMREADRAW)", ARG3, sizeof(struct vki_cdrom_msf));
   6356       PRE_MEM_WRITE( "ioctl(CDROMREADRAW)", ARG3, VKI_CD_FRAMESIZE_RAW);
   6357       break;
   6358    case VKI_CDROMREADAUDIO: /* 0x530e */
   6359       PRE_MEM_READ( "ioctl(CDROMREADAUDIO)", ARG3,
   6360 		     sizeof (struct vki_cdrom_read_audio));
   6361       if ( ARG3 ) {
   6362          /* ToDo: don't do any of the following if the structure is invalid */
   6363          struct vki_cdrom_read_audio *cra = (struct vki_cdrom_read_audio *) ARG3;
   6364 	 PRE_MEM_WRITE( "ioctl(CDROMREADAUDIO).buf",
   6365 	                (Addr)(cra->buf), cra->nframes * VKI_CD_FRAMESIZE_RAW);
   6366       }
   6367       break;
   6368    case VKI_CDROMPLAYMSF:
   6369       PRE_MEM_READ( "ioctl(CDROMPLAYMSF)", ARG3, sizeof(struct vki_cdrom_msf));
   6370       break;
   6371       /* The following two are probably bogus (should check args
   6372 	 for readability).  JRS 20021117 */
   6373    case VKI_CDROM_DRIVE_STATUS: /* 0x5326 */
   6374    case VKI_CDROM_CLEAR_OPTIONS: /* 0x5321 */
   6375       break;
   6376    case VKI_CDROM_GET_CAPABILITY: /* 0x5331 */
   6377       break;
   6378 
   6379    case VKI_FIGETBSZ:
   6380       PRE_MEM_WRITE( "ioctl(FIGETBSZ)", ARG3, sizeof(unsigned long));
   6381       break;
   6382    case VKI_FIBMAP:
   6383       PRE_MEM_READ( "ioctl(FIBMAP)", ARG3, sizeof(int));
   6384       break;
   6385 
   6386    case VKI_FBIOGET_VSCREENINFO: /* 0x4600 */
   6387       PRE_MEM_WRITE( "ioctl(FBIOGET_VSCREENINFO)", ARG3,
   6388                      sizeof(struct vki_fb_var_screeninfo));
   6389       break;
   6390    case VKI_FBIOPUT_VSCREENINFO:
   6391       PRE_MEM_READ( "ioctl(FBIOPUT_VSCREENINFO)", ARG3,
   6392                     sizeof(struct vki_fb_var_screeninfo));
   6393       break;
   6394    case VKI_FBIOGET_FSCREENINFO: /* 0x4602 */
   6395       PRE_MEM_WRITE( "ioctl(FBIOGET_FSCREENINFO)", ARG3,
   6396                      sizeof(struct vki_fb_fix_screeninfo));
   6397       break;
   6398    case VKI_FBIOPAN_DISPLAY:
   6399       PRE_MEM_READ( "ioctl(FBIOPAN_DISPLAY)", ARG3,
   6400                     sizeof(struct vki_fb_var_screeninfo));
   6401 
   6402       break;
   6403    case VKI_PPCLAIM:
   6404    case VKI_PPEXCL:
   6405    case VKI_PPYIELD:
   6406    case VKI_PPRELEASE:
   6407       break;
   6408    case VKI_PPSETMODE:
   6409       PRE_MEM_READ( "ioctl(PPSETMODE)",   ARG3, sizeof(int) );
   6410       break;
   6411    case VKI_PPGETMODE:
   6412       PRE_MEM_WRITE( "ioctl(PPGETMODE)",  ARG3, sizeof(int) );
   6413       break;
   6414    case VKI_PPSETPHASE:
   6415       PRE_MEM_READ(  "ioctl(PPSETPHASE)", ARG3, sizeof(int) );
   6416       break;
   6417    case VKI_PPGETPHASE:
   6418       PRE_MEM_WRITE( "ioctl(PPGETPHASE)", ARG3, sizeof(int) );
   6419       break;
   6420    case VKI_PPGETMODES:
   6421       PRE_MEM_WRITE( "ioctl(PPGETMODES)", ARG3, sizeof(unsigned int) );
   6422       break;
   6423    case VKI_PPSETFLAGS:
   6424       PRE_MEM_READ(  "ioctl(PPSETFLAGS)", ARG3, sizeof(int) );
   6425       break;
   6426    case VKI_PPGETFLAGS:
   6427       PRE_MEM_WRITE( "ioctl(PPGETFLAGS)", ARG3, sizeof(int) );
   6428       break;
   6429    case VKI_PPRSTATUS:
   6430       PRE_MEM_WRITE( "ioctl(PPRSTATUS)",  ARG3, sizeof(unsigned char) );
   6431       break;
   6432    case VKI_PPRDATA:
   6433       PRE_MEM_WRITE( "ioctl(PPRDATA)",    ARG3, sizeof(unsigned char) );
   6434       break;
   6435    case VKI_PPRCONTROL:
   6436       PRE_MEM_WRITE( "ioctl(PPRCONTROL)", ARG3, sizeof(unsigned char) );
   6437       break;
   6438    case VKI_PPWDATA:
   6439       PRE_MEM_READ(  "ioctl(PPWDATA)",    ARG3, sizeof(unsigned char) );
   6440       break;
   6441    case VKI_PPWCONTROL:
   6442       PRE_MEM_READ(  "ioctl(PPWCONTROL)", ARG3, sizeof(unsigned char) );
   6443       break;
   6444    case VKI_PPFCONTROL:
   6445       PRE_MEM_READ(  "ioctl(PPFCONTROL)", ARG3, 2 * sizeof(unsigned char) );
   6446       break;
   6447    case VKI_PPDATADIR:
   6448       PRE_MEM_READ(  "ioctl(PPDATADIR)",  ARG3, sizeof(int) );
   6449       break;
   6450    case VKI_PPNEGOT:
   6451       PRE_MEM_READ(  "ioctl(PPNEGOT)",    ARG3, sizeof(int) );
   6452       break;
   6453    case VKI_PPWCTLONIRQ:
   6454       PRE_MEM_READ(  "ioctl(PPWCTLONIRQ)",ARG3, sizeof(unsigned char) );
   6455       break;
   6456    case VKI_PPCLRIRQ:
   6457       PRE_MEM_WRITE( "ioctl(PPCLRIRQ)",   ARG3, sizeof(int) );
   6458       break;
   6459    case VKI_PPSETTIME:
   6460       PRE_MEM_READ(  "ioctl(PPSETTIME)",  ARG3, sizeof(struct vki_timeval) );
   6461       break;
   6462    case VKI_PPGETTIME:
   6463       PRE_MEM_WRITE( "ioctl(PPGETTIME)",  ARG3, sizeof(struct vki_timeval) );
   6464       break;
   6465 
   6466    case VKI_GIO_FONT:
   6467       PRE_MEM_WRITE( "ioctl(GIO_FONT)", ARG3, 32 * 256 );
   6468       break;
   6469    case VKI_PIO_FONT:
   6470       PRE_MEM_READ( "ioctl(PIO_FONT)", ARG3, 32 * 256 );
   6471       break;
   6472 
   6473    case VKI_GIO_FONTX:
   6474       PRE_MEM_READ( "ioctl(GIO_FONTX)", ARG3, sizeof(struct vki_consolefontdesc) );
   6475       if ( ARG3 ) {
   6476          /* ToDo: don't do any of the following if the structure is invalid */
   6477          struct vki_consolefontdesc *cfd = (struct vki_consolefontdesc *)ARG3;
   6478          PRE_MEM_WRITE( "ioctl(GIO_FONTX).chardata", (Addr)cfd->chardata,
   6479                         32 * cfd->charcount );
   6480       }
   6481       break;
   6482    case VKI_PIO_FONTX:
   6483       PRE_MEM_READ( "ioctl(PIO_FONTX)", ARG3, sizeof(struct vki_consolefontdesc) );
   6484       if ( ARG3 ) {
   6485          /* ToDo: don't do any of the following if the structure is invalid */
   6486          struct vki_consolefontdesc *cfd = (struct vki_consolefontdesc *)ARG3;
   6487          PRE_MEM_READ( "ioctl(PIO_FONTX).chardata", (Addr)cfd->chardata,
   6488                        32 * cfd->charcount );
   6489       }
   6490       break;
   6491 
   6492    case VKI_PIO_FONTRESET:
   6493       break;
   6494 
   6495    case VKI_GIO_CMAP:
   6496       PRE_MEM_WRITE( "ioctl(GIO_CMAP)", ARG3, 16 * 3 );
   6497       break;
   6498    case VKI_PIO_CMAP:
   6499       PRE_MEM_READ( "ioctl(PIO_CMAP)", ARG3, 16 * 3 );
   6500       break;
   6501 
   6502    case VKI_KIOCSOUND:
   6503    case VKI_KDMKTONE:
   6504       break;
   6505 
   6506    case VKI_KDGETLED:
   6507       PRE_MEM_WRITE( "ioctl(KDGETLED)", ARG3, sizeof(char) );
   6508       break;
   6509    case VKI_KDSETLED:
   6510       break;
   6511 
   6512    case VKI_KDGKBTYPE:
   6513       PRE_MEM_WRITE( "ioctl(KDGKBTYPE)", ARG3, sizeof(char) );
   6514       break;
   6515 
   6516    case VKI_KDADDIO:
   6517    case VKI_KDDELIO:
   6518    case VKI_KDENABIO:
   6519    case VKI_KDDISABIO:
   6520       break;
   6521 
   6522    case VKI_KDSETMODE:
   6523       break;
   6524    case VKI_KDGETMODE:
   6525       PRE_MEM_WRITE( "ioctl(KDGETMODE)", ARG3, sizeof(int) );
   6526       break;
   6527 
   6528    case VKI_KDMAPDISP:
   6529    case VKI_KDUNMAPDISP:
   6530       break;
   6531 
   6532    case VKI_GIO_SCRNMAP:
   6533       PRE_MEM_WRITE( "ioctl(GIO_SCRNMAP)", ARG3, VKI_E_TABSZ );
   6534       break;
   6535    case VKI_PIO_SCRNMAP:
   6536       PRE_MEM_READ( "ioctl(PIO_SCRNMAP)", ARG3, VKI_E_TABSZ  );
   6537       break;
   6538    case VKI_GIO_UNISCRNMAP:
   6539       PRE_MEM_WRITE( "ioctl(GIO_UNISCRNMAP)", ARG3,
   6540                      VKI_E_TABSZ * sizeof(unsigned short) );
   6541       break;
   6542    case VKI_PIO_UNISCRNMAP:
   6543       PRE_MEM_READ( "ioctl(PIO_UNISCRNMAP)", ARG3,
   6544                     VKI_E_TABSZ * sizeof(unsigned short) );
   6545       break;
   6546 
   6547    case VKI_GIO_UNIMAP:
   6548       if ( ARG3 ) {
   6549          struct vki_unimapdesc *desc = (struct vki_unimapdesc *) ARG3;
   6550          PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr)&desc->entry_ct,
   6551                        sizeof(unsigned short));
   6552          PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr)&desc->entries,
   6553                        sizeof(struct vki_unipair *));
   6554          PRE_MEM_WRITE( "ioctl(GIO_UNIMAP).entries", (Addr)desc->entries,
   6555                         desc->entry_ct * sizeof(struct vki_unipair));
   6556       }
   6557       break;
   6558    case VKI_PIO_UNIMAP:
   6559       if ( ARG3 ) {
   6560          struct vki_unimapdesc *desc = (struct vki_unimapdesc *) ARG3;
   6561          PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr)&desc->entry_ct,
   6562                        sizeof(unsigned short) );
   6563          PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr)&desc->entries,
   6564                        sizeof(struct vki_unipair *) );
   6565          PRE_MEM_READ( "ioctl(PIO_UNIMAP).entries", (Addr)desc->entries,
   6566                        desc->entry_ct * sizeof(struct vki_unipair) );
   6567       }
   6568       break;
   6569    case VKI_PIO_UNIMAPCLR:
   6570       PRE_MEM_READ( "ioctl(GIO_UNIMAP)", ARG3, sizeof(struct vki_unimapinit));
   6571       break;
   6572 
   6573    case VKI_KDGKBMODE:
   6574       PRE_MEM_WRITE( "ioctl(KDGKBMODE)", ARG3, sizeof(int) );
   6575       break;
   6576    case VKI_KDSKBMODE:
   6577       break;
   6578 
   6579    case VKI_KDGKBMETA:
   6580       PRE_MEM_WRITE( "ioctl(KDGKBMETA)", ARG3, sizeof(int) );
   6581       break;
   6582    case VKI_KDSKBMETA:
   6583       break;
   6584 
   6585    case VKI_KDGKBLED:
   6586       PRE_MEM_WRITE( "ioctl(KDGKBLED)", ARG3, sizeof(char) );
   6587       break;
   6588    case VKI_KDSKBLED:
   6589       break;
   6590 
   6591    case VKI_KDGKBENT:
   6592       PRE_MEM_READ( "ioctl(KDGKBENT).kb_table",
   6593                     (Addr)&((struct vki_kbentry *)ARG3)->kb_table,
   6594                     sizeof(((struct vki_kbentry *)ARG3)->kb_table) );
   6595       PRE_MEM_READ( "ioctl(KDGKBENT).kb_index",
   6596                     (Addr)&((struct vki_kbentry *)ARG3)->kb_index,
   6597                     sizeof(((struct vki_kbentry *)ARG3)->kb_index) );
   6598       PRE_MEM_WRITE( "ioctl(KDGKBENT).kb_value",
   6599 		     (Addr)&((struct vki_kbentry *)ARG3)->kb_value,
   6600 		     sizeof(((struct vki_kbentry *)ARG3)->kb_value) );
   6601       break;
   6602    case VKI_KDSKBENT:
   6603       PRE_MEM_READ( "ioctl(KDSKBENT).kb_table",
   6604                     (Addr)&((struct vki_kbentry *)ARG3)->kb_table,
   6605                     sizeof(((struct vki_kbentry *)ARG3)->kb_table) );
   6606       PRE_MEM_READ( "ioctl(KDSKBENT).kb_index",
   6607                     (Addr)&((struct vki_kbentry *)ARG3)->kb_index,
   6608                     sizeof(((struct vki_kbentry *)ARG3)->kb_index) );
   6609       PRE_MEM_READ( "ioctl(KDSKBENT).kb_value",
   6610                     (Addr)&((struct vki_kbentry *)ARG3)->kb_value,
   6611                     sizeof(((struct vki_kbentry *)ARG3)->kb_value) );
   6612       break;
   6613 
   6614    case VKI_KDGKBSENT:
   6615       PRE_MEM_READ( "ioctl(KDGKBSENT).kb_func",
   6616                     (Addr)&((struct vki_kbsentry *)ARG3)->kb_func,
   6617                     sizeof(((struct vki_kbsentry *)ARG3)->kb_func) );
   6618       PRE_MEM_WRITE( "ioctl(KDGKSENT).kb_string",
   6619 		     (Addr)((struct vki_kbsentry *)ARG3)->kb_string,
   6620 		     sizeof(((struct vki_kbsentry *)ARG3)->kb_string) );
   6621       break;
   6622    case VKI_KDSKBSENT:
   6623       PRE_MEM_READ( "ioctl(KDSKBSENT).kb_func",
   6624                     (Addr)&((struct vki_kbsentry *)ARG3)->kb_func,
   6625                     sizeof(((struct vki_kbsentry *)ARG3)->kb_func) );
   6626       PRE_MEM_RASCIIZ( "ioctl(KDSKBSENT).kb_string",
   6627                        (Addr)((struct vki_kbsentry *)ARG3)->kb_string );
   6628       break;
   6629 
   6630    case VKI_KDGKBDIACR:
   6631       PRE_MEM_WRITE( "ioctl(KDGKBDIACR)", ARG3, sizeof(struct vki_kbdiacrs) );
   6632       break;
   6633    case VKI_KDSKBDIACR:
   6634       PRE_MEM_READ( "ioctl(KDSKBDIACR)", ARG3, sizeof(struct vki_kbdiacrs) );
   6635       break;
   6636 
   6637    case VKI_KDGETKEYCODE:
   6638       PRE_MEM_READ( "ioctl(KDGETKEYCODE).scancode",
   6639                     (Addr)&((struct vki_kbkeycode *)ARG3)->scancode,
   6640                     sizeof(((struct vki_kbkeycode *)ARG3)->scancode) );
   6641       PRE_MEM_WRITE( "ioctl(KDGETKEYCODE).keycode",
   6642 		     (Addr)((struct vki_kbkeycode *)ARG3)->keycode,
   6643 		     sizeof(((struct vki_kbkeycode *)ARG3)->keycode) );
   6644       break;
   6645    case VKI_KDSETKEYCODE:
   6646       PRE_MEM_READ( "ioctl(KDSETKEYCODE).scancode",
   6647                     (Addr)&((struct vki_kbkeycode *)ARG3)->scancode,
   6648                     sizeof(((struct vki_kbkeycode *)ARG3)->scancode) );
   6649       PRE_MEM_READ( "ioctl(KDSETKEYCODE).keycode",
   6650                     (Addr)((struct vki_kbkeycode *)ARG3)->keycode,
   6651                     sizeof(((struct vki_kbkeycode *)ARG3)->keycode) );
   6652       break;
   6653 
   6654    case VKI_KDSIGACCEPT:
   6655       break;
   6656 
   6657    case VKI_KDKBDREP:
   6658       PRE_MEM_READ( "ioctl(KBKBDREP)", ARG3, sizeof(struct vki_kbd_repeat) );
   6659       break;
   6660 
   6661    case VKI_KDFONTOP:
   6662       if ( ARG3 ) {
   6663          struct vki_console_font_op *op = (struct vki_console_font_op *) ARG3;
   6664          PRE_MEM_READ( "ioctl(KDFONTOP)", (Addr)op,
   6665                        sizeof(struct vki_console_font_op) );
   6666          switch ( op->op ) {
   6667             case VKI_KD_FONT_OP_SET:
   6668                PRE_MEM_READ( "ioctl(KDFONTOP,KD_FONT_OP_SET).data",
   6669                              (Addr)op->data,
   6670                              (op->width + 7) / 8 * 32 * op->charcount );
   6671                break;
   6672             case VKI_KD_FONT_OP_GET:
   6673                if ( op->data )
   6674                   PRE_MEM_WRITE( "ioctl(KDFONTOP,KD_FONT_OP_GET).data",
   6675                                  (Addr)op->data,
   6676                                  (op->width + 7) / 8 * 32 * op->charcount );
   6677                break;
   6678             case VKI_KD_FONT_OP_SET_DEFAULT:
   6679                if ( op->data )
   6680                   PRE_MEM_RASCIIZ( "ioctl(KDFONTOP,KD_FONT_OP_SET_DEFAULT).data",
   6681                                    (Addr)op->data );
   6682                break;
   6683             case VKI_KD_FONT_OP_COPY:
   6684                break;
   6685          }
   6686       }
   6687       break;
   6688 
   6689    case VKI_VT_OPENQRY:
   6690       PRE_MEM_WRITE( "ioctl(VT_OPENQRY)", ARG3, sizeof(int) );
   6691       break;
   6692    case VKI_VT_GETMODE:
   6693       PRE_MEM_WRITE( "ioctl(VT_GETMODE)", ARG3, sizeof(struct vki_vt_mode) );
   6694       break;
   6695    case VKI_VT_SETMODE:
   6696       PRE_MEM_READ( "ioctl(VT_SETMODE)", ARG3, sizeof(struct vki_vt_mode) );
   6697       break;
   6698    case VKI_VT_GETSTATE:
   6699       PRE_MEM_WRITE( "ioctl(VT_GETSTATE).v_active",
   6700                      (Addr) &(((struct vki_vt_stat*) ARG3)->v_active),
   6701                      sizeof(((struct vki_vt_stat*) ARG3)->v_active));
   6702       PRE_MEM_WRITE( "ioctl(VT_GETSTATE).v_state",
   6703                      (Addr) &(((struct vki_vt_stat*) ARG3)->v_state),
   6704                      sizeof(((struct vki_vt_stat*) ARG3)->v_state));
   6705       break;
   6706    case VKI_VT_RELDISP:
   6707    case VKI_VT_ACTIVATE:
   6708    case VKI_VT_WAITACTIVE:
   6709    case VKI_VT_DISALLOCATE:
   6710       break;
   6711    case VKI_VT_RESIZE:
   6712       PRE_MEM_READ( "ioctl(VT_RESIZE)", ARG3, sizeof(struct vki_vt_sizes) );
   6713       break;
   6714    case VKI_VT_RESIZEX:
   6715       PRE_MEM_READ( "ioctl(VT_RESIZEX)", ARG3, sizeof(struct vki_vt_consize) );
   6716       break;
   6717    case VKI_VT_LOCKSWITCH:
   6718    case VKI_VT_UNLOCKSWITCH:
   6719       break;
   6720 
   6721    case VKI_USBDEVFS_CONTROL:
   6722       if ( ARG3 ) {
   6723          struct vki_usbdevfs_ctrltransfer *vkuc = (struct vki_usbdevfs_ctrltransfer *)ARG3;
   6724          PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).bRequestType", (Addr)&vkuc->bRequestType, sizeof(vkuc->bRequestType));
   6725          PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).bRequest", (Addr)&vkuc->bRequest, sizeof(vkuc->bRequest));
   6726          PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wValue", (Addr)&vkuc->wValue, sizeof(vkuc->wValue));
   6727          PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wIndex", (Addr)&vkuc->wIndex, sizeof(vkuc->wIndex));
   6728          PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wLength", (Addr)&vkuc->wLength, sizeof(vkuc->wLength));
   6729          PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).timeout", (Addr)&vkuc->timeout, sizeof(vkuc->timeout));
   6730          if (vkuc->bRequestType & 0x80)
   6731             PRE_MEM_WRITE( "ioctl(USBDEVFS_CONTROL).data", (Addr)vkuc->data, vkuc->wLength);
   6732          else
   6733             PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).data", (Addr)vkuc->data, vkuc->wLength);
   6734       }
   6735       break;
   6736    case VKI_USBDEVFS_BULK:
   6737       if ( ARG3 ) {
   6738          struct vki_usbdevfs_bulktransfer *vkub = (struct vki_usbdevfs_bulktransfer *)ARG3;
   6739          PRE_MEM_READ( "ioctl(USBDEVFS_BULK)", ARG3, sizeof(struct vki_usbdevfs_bulktransfer));
   6740          if (vkub->ep & 0x80)
   6741             PRE_MEM_WRITE( "ioctl(USBDEVFS_BULK).data", (Addr)vkub->data, vkub->len);
   6742          else
   6743             PRE_MEM_READ( "ioctl(USBDEVFS_BULK).data", (Addr)vkub->data, vkub->len);
   6744       }
   6745       break;
   6746    case VKI_USBDEVFS_GETDRIVER:
   6747       if ( ARG3 ) {
   6748          struct vki_usbdevfs_getdriver *vkugd = (struct vki_usbdevfs_getdriver *) ARG3;
   6749          PRE_MEM_WRITE( "ioctl(USBDEVFS_GETDRIVER)", (Addr)&vkugd->driver, sizeof(vkugd->driver));
   6750       }
   6751       break;
   6752    case VKI_USBDEVFS_SUBMITURB:
   6753       if ( ARG3 ) {
   6754          struct vki_usbdevfs_urb *vkuu = (struct vki_usbdevfs_urb *)ARG3;
   6755 
   6756          /* Not the whole struct needs to be initialized */
   6757          PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).endpoint", (Addr)&vkuu->endpoint, sizeof(vkuu->endpoint));
   6758          PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).type", (Addr)&vkuu->type, sizeof(vkuu->type));
   6759          PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).flags", (Addr)&vkuu->flags, sizeof(vkuu->flags));
   6760          PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)&vkuu->buffer, sizeof(vkuu->buffer));
   6761          PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).signr", (Addr)&vkuu->signr, sizeof(vkuu->signr));
   6762          PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).status", (Addr)&vkuu->status, sizeof(vkuu->status));
   6763          if (vkuu->type == VKI_USBDEVFS_URB_TYPE_CONTROL) {
   6764             struct vki_usbdevfs_setuppacket *vkusp = (struct vki_usbdevfs_setuppacket *)vkuu->buffer;
   6765             PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr)&vkuu->buffer_length, sizeof(vkuu->buffer_length));
   6766             PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer.setup_packet", (Addr)vkusp, sizeof(*vkusp));
   6767             if (vkusp->bRequestType & 0x80)
   6768                PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer.data", (Addr)(vkusp+1), vkuu->buffer_length - sizeof(*vkusp));
   6769             else
   6770                PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer.data", (Addr)(vkusp+1), vkuu->buffer_length - sizeof(*vkusp));
   6771             PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).actual_length", (Addr)&vkuu->actual_length, sizeof(vkuu->actual_length));
   6772          } else if (vkuu->type == VKI_USBDEVFS_URB_TYPE_ISO) {
   6773             int total_length = 0;
   6774             int i;
   6775             PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).number_of_packets", (Addr)&vkuu->number_of_packets, sizeof(vkuu->number_of_packets));
   6776             for(i=0; i<vkuu->number_of_packets; i++) {
   6777                PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].length", (Addr)&vkuu->iso_frame_desc[i].length, sizeof(vkuu->iso_frame_desc[i].length));
   6778                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));
   6779                PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].status", (Addr)&vkuu->iso_frame_desc[i].status, sizeof(vkuu->iso_frame_desc[i].status));
   6780                total_length += vkuu->iso_frame_desc[i].length;
   6781             }
   6782             if (vkuu->endpoint & 0x80)
   6783                PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, total_length);
   6784             else
   6785                PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, total_length);
   6786             PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).error_count", (Addr)&vkuu->error_count, sizeof(vkuu->error_count));
   6787          } else {
   6788             PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr)&vkuu->buffer_length, sizeof(vkuu->buffer_length));
   6789             if (vkuu->endpoint & 0x80)
   6790                PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, vkuu->buffer_length);
   6791             else
   6792                PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, vkuu->buffer_length);
   6793             PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).actual_length", (Addr)&vkuu->actual_length, sizeof(vkuu->actual_length));
   6794          }
   6795       }
   6796       break;
   6797    case VKI_USBDEVFS_DISCARDURB:
   6798       break;
   6799    case VKI_USBDEVFS_REAPURB:
   6800       if ( ARG3 ) {
   6801          PRE_MEM_WRITE( "ioctl(USBDEVFS_REAPURB)", ARG3, sizeof(struct vki_usbdevfs_urb **));
   6802       }
   6803       break;
   6804    case VKI_USBDEVFS_REAPURBNDELAY:
   6805       if ( ARG3 ) {
   6806          PRE_MEM_WRITE( "ioctl(USBDEVFS_REAPURBNDELAY)", ARG3, sizeof(struct vki_usbdevfs_urb **));
   6807       }
   6808       break;
   6809    case VKI_USBDEVFS_CONNECTINFO:
   6810       PRE_MEM_WRITE( "ioctl(USBDEVFS_CONNECTINFO)", ARG3, sizeof(struct vki_usbdevfs_connectinfo));
   6811       break;
   6812    case VKI_USBDEVFS_IOCTL:
   6813       if ( ARG3 ) {
   6814          struct vki_usbdevfs_ioctl *vkui = (struct vki_usbdevfs_ioctl *)ARG3;
   6815          UInt dir2, size2;
   6816          PRE_MEM_READ("ioctl(USBDEVFS_IOCTL)", (Addr)vkui, sizeof(struct vki_usbdevfs_ioctl));
   6817          dir2  = _VKI_IOC_DIR(vkui->ioctl_code);
   6818          size2 = _VKI_IOC_SIZE(vkui->ioctl_code);
   6819          if (size2 > 0) {
   6820             if (dir2 & _VKI_IOC_WRITE)
   6821                PRE_MEM_READ("ioctl(USBDEVFS_IOCTL).dataWrite", (Addr)vkui->data, size2);
   6822             else if (dir2 & _VKI_IOC_READ)
   6823                PRE_MEM_WRITE("ioctl(USBDEVFS_IOCTL).dataRead", (Addr)vkui->data, size2);
   6824          }
   6825       }
   6826       break;
   6827    case VKI_USBDEVFS_RESET:
   6828       break;
   6829 
   6830       /* I2C (/dev/i2c-*) ioctls */
   6831    case VKI_I2C_SLAVE:
   6832    case VKI_I2C_SLAVE_FORCE:
   6833    case VKI_I2C_TENBIT:
   6834    case VKI_I2C_PEC:
   6835       break;
   6836    case VKI_I2C_FUNCS:
   6837       PRE_MEM_WRITE( "ioctl(I2C_FUNCS)", ARG3, sizeof(unsigned long) );
   6838       break;
   6839    case VKI_I2C_RDWR:
   6840       if ( ARG3 ) {
   6841           struct vki_i2c_rdwr_ioctl_data *vkui = (struct vki_i2c_rdwr_ioctl_data *)ARG3;
   6842           UInt i;
   6843           PRE_MEM_READ("ioctl(I2C_RDWR)", (Addr)vkui, sizeof(struct vki_i2c_rdwr_ioctl_data));
   6844           for (i=0; i < vkui->nmsgs; i++) {
   6845               struct vki_i2c_msg *msg = vkui->msgs + i;
   6846               PRE_MEM_READ("ioctl(I2C_RDWR).msgs", (Addr)msg, sizeof(struct vki_i2c_msg));
   6847               if (msg->flags & VKI_I2C_M_RD)
   6848                   PRE_MEM_WRITE("ioctl(I2C_RDWR).msgs.buf", (Addr)msg->buf, msg->len);
   6849               else
   6850                   PRE_MEM_READ("ioctl(I2C_RDWR).msgs.buf", (Addr)msg->buf, msg->len);
   6851           }
   6852       }
   6853       break;
   6854    case VKI_I2C_SMBUS:
   6855        if ( ARG3 ) {
   6856             struct vki_i2c_smbus_ioctl_data *vkis
   6857                = (struct vki_i2c_smbus_ioctl_data *) ARG3;
   6858             PRE_MEM_READ("ioctl(VKI_I2C_SMBUS).i2c_smbus_ioctl_data.read_write",
   6859                          (Addr)&vkis->read_write, sizeof(vkis->read_write));
   6860             PRE_MEM_READ("ioctl(VKI_I2C_SMBUS).i2c_smbus_ioctl_data.size",
   6861                          (Addr)&vkis->size, sizeof(vkis->size));
   6862             PRE_MEM_READ("ioctl(VKI_I2C_SMBUS).i2c_smbus_ioctl_data.command",
   6863                          (Addr)&vkis->command, sizeof(vkis->command));
   6864             /* i2c_smbus_write_quick hides its value in read_write, so
   6865                this variable can have a different meaning */
   6866             /* to make matters worse i2c_smbus_write_byte stores its
   6867                value in command */
   6868             if ( ! ((vkis->size == VKI_I2C_SMBUS_QUICK) ||
   6869                  ((vkis->size == VKI_I2C_SMBUS_BYTE)
   6870                   && (vkis->read_write == VKI_I2C_SMBUS_WRITE))))  {
   6871                     /* the rest uses the byte array to store the data,
   6872                        some the first byte for size */
   6873                     UInt size;
   6874                     switch(vkis->size) {
   6875                         case VKI_I2C_SMBUS_BYTE_DATA:
   6876                             size = 1;
   6877                             break;
   6878                         case VKI_I2C_SMBUS_WORD_DATA:
   6879                         case VKI_I2C_SMBUS_PROC_CALL:
   6880                             size = 2;
   6881                             break;
   6882                         case VKI_I2C_SMBUS_BLOCK_DATA:
   6883                         case VKI_I2C_SMBUS_I2C_BLOCK_BROKEN:
   6884                         case VKI_I2C_SMBUS_BLOCK_PROC_CALL:
   6885                         case VKI_I2C_SMBUS_I2C_BLOCK_DATA:
   6886                             size = 1 + vkis->data->block[0];
   6887                             break;
   6888                         default:
   6889                             size = 0;
   6890                     }
   6891 
   6892                     if ((vkis->read_write == VKI_I2C_SMBUS_READ)
   6893                         || (vkis->size == VKI_I2C_SMBUS_PROC_CALL)
   6894                         || (vkis->size == VKI_I2C_SMBUS_BLOCK_PROC_CALL))
   6895                         PRE_MEM_WRITE("ioctl(VKI_I2C_SMBUS)"
   6896                                       ".i2c_smbus_ioctl_data.data",
   6897                                       (Addr)&vkis->data->block[0], size);
   6898                     else
   6899                         PRE_MEM_READ("ioctl(VKI_I2C_SMBUS)."
   6900                                      "i2c_smbus_ioctl_data.data",
   6901                                      (Addr)&vkis->data->block[0], size);
   6902             }
   6903        }
   6904        break;
   6905 
   6906       /* Wireless extensions ioctls */
   6907    case VKI_SIOCSIWCOMMIT:
   6908    case VKI_SIOCSIWNWID:
   6909    case VKI_SIOCSIWFREQ:
   6910    case VKI_SIOCSIWMODE:
   6911    case VKI_SIOCSIWSENS:
   6912    case VKI_SIOCSIWRANGE:
   6913    case VKI_SIOCSIWPRIV:
   6914    case VKI_SIOCSIWSTATS:
   6915    case VKI_SIOCSIWSPY:
   6916    case VKI_SIOCSIWTHRSPY:
   6917    case VKI_SIOCSIWAP:
   6918    case VKI_SIOCSIWSCAN:
   6919    case VKI_SIOCSIWESSID:
   6920    case VKI_SIOCSIWRATE:
   6921    case VKI_SIOCSIWNICKN:
   6922    case VKI_SIOCSIWRTS:
   6923    case VKI_SIOCSIWFRAG:
   6924    case VKI_SIOCSIWTXPOW:
   6925    case VKI_SIOCSIWRETRY:
   6926    case VKI_SIOCSIWENCODE:
   6927    case VKI_SIOCSIWPOWER:
   6928    case VKI_SIOCSIWGENIE:
   6929    case VKI_SIOCSIWMLME:
   6930    case VKI_SIOCSIWAUTH:
   6931    case VKI_SIOCSIWENCODEEXT:
   6932    case VKI_SIOCSIWPMKSA:
   6933       break;
   6934    case VKI_SIOCGIWNAME:
   6935       if (ARG3) {
   6936          PRE_MEM_WRITE("ioctl(SIOCGIWNAME)",
   6937                        (Addr)((struct vki_iwreq *)ARG3)->u.name,
   6938                        sizeof(((struct vki_iwreq *)ARG3)->u.name));
   6939       }
   6940       break;
   6941    case VKI_SIOCGIWNWID:
   6942    case VKI_SIOCGIWSENS:
   6943    case VKI_SIOCGIWRATE:
   6944    case VKI_SIOCGIWRTS:
   6945    case VKI_SIOCGIWFRAG:
   6946    case VKI_SIOCGIWTXPOW:
   6947    case VKI_SIOCGIWRETRY:
   6948    case VKI_SIOCGIWPOWER:
   6949    case VKI_SIOCGIWAUTH:
   6950       if (ARG3) {
   6951          PRE_MEM_WRITE("ioctl(SIOCGIW[NWID|SENS|RATE|RTS|FRAG|TXPOW|"
   6952                        "RETRY|PARAM|AUTH])",
   6953                        (Addr)&((struct vki_iwreq *)ARG3)->u.nwid,
   6954                        sizeof(struct vki_iw_param));
   6955       }
   6956       break;
   6957    case VKI_SIOCGIWFREQ:
   6958       if (ARG3) {
   6959          PRE_MEM_WRITE("ioctl(SIOCGIWFREQ",
   6960                        (Addr)&((struct vki_iwreq *)ARG3)->u.freq,
   6961                        sizeof(struct vki_iw_freq));
   6962       }
   6963       break;
   6964    case VKI_SIOCGIWMODE:
   6965       if (ARG3) {
   6966          PRE_MEM_WRITE("ioctl(SIOCGIWMODE",
   6967                        (Addr)&((struct vki_iwreq *)ARG3)->u.mode,
   6968                        sizeof(__vki_u32));
   6969       }
   6970       break;
   6971    case VKI_SIOCGIWRANGE:
   6972    case VKI_SIOCGIWPRIV:
   6973    case VKI_SIOCGIWSTATS:
   6974    case VKI_SIOCGIWSPY:
   6975    case VKI_SIOCGIWTHRSPY:
   6976    case VKI_SIOCGIWAPLIST:
   6977    case VKI_SIOCGIWSCAN:
   6978    case VKI_SIOCGIWESSID:
   6979    case VKI_SIOCGIWNICKN:
   6980    case VKI_SIOCGIWENCODE:
   6981    case VKI_SIOCGIWGENIE:
   6982    case VKI_SIOCGIWENCODEEXT:
   6983       if (ARG3) {
   6984          struct vki_iw_point* point;
   6985          point = &((struct vki_iwreq *)ARG3)->u.data;
   6986          PRE_MEM_WRITE("ioctl(SIOCGIW[RANGE|PRIV|STATS|SPY|THRSPY|"
   6987                        "APLIST|SCAN|ESSID|NICKN|ENCODE|GENIE|ENCODEEXT])",
   6988                        (Addr)point->pointer, point->length);
   6989       }
   6990       break;
   6991    case VKI_SIOCGIWAP:
   6992       if (ARG3) {
   6993          PRE_MEM_WRITE("ioctl(SIOCGIWAP)",
   6994                        (Addr)&((struct vki_iwreq *)ARG3)->u.ap_addr,
   6995                        sizeof(struct vki_sockaddr));
   6996       }
   6997       break;
   6998 
   6999   /* User input device creation */
   7000   case VKI_UI_SET_EVBIT:
   7001   case VKI_UI_SET_KEYBIT:
   7002   case VKI_UI_SET_RELBIT:
   7003   case VKI_UI_SET_ABSBIT:
   7004   case VKI_UI_SET_MSCBIT:
   7005   case VKI_UI_SET_LEDBIT:
   7006   case VKI_UI_SET_SNDBIT:
   7007   case VKI_UI_SET_FFBIT:
   7008   case VKI_UI_SET_SWBIT:
   7009   case VKI_UI_SET_PROPBIT:
   7010       /* These just take an int by value */
   7011       break;
   7012 
   7013 #  if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
   7014       || defined(VGPV_mips32_linux_android)
   7015    /* ashmem */
   7016    case VKI_ASHMEM_GET_SIZE:
   7017    case VKI_ASHMEM_SET_SIZE:
   7018    case VKI_ASHMEM_GET_PROT_MASK:
   7019    case VKI_ASHMEM_SET_PROT_MASK:
   7020    case VKI_ASHMEM_GET_PIN_STATUS:
   7021    case VKI_ASHMEM_PURGE_ALL_CACHES:
   7022        break;
   7023    case VKI_ASHMEM_GET_NAME:
   7024        PRE_MEM_WRITE( "ioctl(ASHMEM_SET_NAME)", ARG3, VKI_ASHMEM_NAME_LEN );
   7025        break;
   7026    case VKI_ASHMEM_SET_NAME:
   7027        PRE_MEM_RASCIIZ( "ioctl(ASHMEM_SET_NAME)", ARG3);
   7028        break;
   7029    case VKI_ASHMEM_PIN:
   7030    case VKI_ASHMEM_UNPIN:
   7031        PRE_MEM_READ( "ioctl(ASHMEM_PIN|ASHMEM_UNPIN)",
   7032                      ARG3, sizeof(struct vki_ashmem_pin) );
   7033        break;
   7034 
   7035    /* binder */
   7036    case VKI_BINDER_WRITE_READ:
   7037        if (ARG3) {
   7038            struct vki_binder_write_read* bwr
   7039               = (struct vki_binder_write_read*)ARG3;
   7040 
   7041            PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_buffer",
   7042                           bwr->write_buffer);
   7043            PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_size",
   7044                           bwr->write_size);
   7045            PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_consumed",
   7046                           bwr->write_consumed);
   7047            PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_buffer",
   7048                           bwr->read_buffer);
   7049            PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_size",
   7050                           bwr->read_size);
   7051            PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_consumed",
   7052                           bwr->read_consumed);
   7053 
   7054            PRE_FIELD_WRITE("ioctl(BINDER_WRITE_READ).write_consumed",
   7055                            bwr->write_consumed);
   7056            PRE_FIELD_WRITE("ioctl(BINDER_WRITE_READ).read_consumed",
   7057                            bwr->read_consumed);
   7058 
   7059            if (bwr->read_size)
   7060                PRE_MEM_WRITE("ioctl(BINDER_WRITE_READ).read_buffer[]",
   7061                              (Addr)bwr->read_buffer, bwr->read_size);
   7062            if (bwr->write_size)
   7063                PRE_MEM_READ("ioctl(BINDER_WRITE_READ).write_buffer[]",
   7064                             (Addr)bwr->write_buffer, bwr->write_size);
   7065        }
   7066        break;
   7067 
   7068    case VKI_BINDER_SET_IDLE_TIMEOUT:
   7069    case VKI_BINDER_SET_MAX_THREADS:
   7070    case VKI_BINDER_SET_IDLE_PRIORITY:
   7071    case VKI_BINDER_SET_CONTEXT_MGR:
   7072    case VKI_BINDER_THREAD_EXIT:
   7073        break;
   7074    case VKI_BINDER_VERSION:
   7075        if (ARG3) {
   7076            struct vki_binder_version* bv = (struct vki_binder_version*)ARG3;
   7077            PRE_FIELD_WRITE("ioctl(BINDER_VERSION)", bv->protocol_version);
   7078        }
   7079        break;
   7080 #  endif /* defined(VGPV_*_linux_android) */
   7081 
   7082    case VKI_HCIGETDEVLIST:
   7083       if (ARG3) {
   7084          struct vki_hci_dev_list_req* dlr = (struct vki_hci_dev_list_req*)ARG3;
   7085          PRE_MEM_READ("ioctl(HCIGETDEVLIST)",
   7086                       (Addr)ARG3, sizeof(struct vki_hci_dev_list_req));
   7087          PRE_MEM_WRITE("ioctl(HCIGETDEVLIST)",
   7088                        (Addr)ARG3 + sizeof(struct vki_hci_dev_list_req),
   7089                        dlr->dev_num * sizeof(struct vki_hci_dev_req));
   7090       }
   7091       break;
   7092 
   7093    case VKI_HCIINQUIRY:
   7094       if (ARG3) {
   7095          struct vki_hci_inquiry_req* ir = (struct vki_hci_inquiry_req*)ARG3;
   7096          PRE_MEM_READ("ioctl(HCIINQUIRY)",
   7097                       (Addr)ARG3, sizeof(struct vki_hci_inquiry_req));
   7098          PRE_MEM_WRITE("ioctl(HCIINQUIRY)",
   7099                        (Addr)ARG3 + sizeof(struct vki_hci_inquiry_req),
   7100                        ir->num_rsp * sizeof(struct vki_inquiry_info));
   7101       }
   7102       break;
   7103 
   7104    case VKI_DRM_IOCTL_VERSION:
   7105       if (ARG3) {
   7106          struct vki_drm_version *data = (struct vki_drm_version *)ARG3;
   7107 	 PRE_MEM_WRITE("ioctl(DRM_VERSION).version_major", (Addr)&data->version_major, sizeof(data->version_major));
   7108          PRE_MEM_WRITE("ioctl(DRM_VERSION).version_minor", (Addr)&data->version_minor, sizeof(data->version_minor));
   7109          PRE_MEM_WRITE("ioctl(DRM_VERSION).version_patchlevel", (Addr)&data->version_patchlevel, sizeof(data->version_patchlevel));
   7110          PRE_MEM_READ("ioctl(DRM_VERSION).name_len", (Addr)&data->name_len, sizeof(data->name_len));
   7111          PRE_MEM_READ("ioctl(DRM_VERSION).name", (Addr)&data->name, sizeof(data->name));
   7112          PRE_MEM_WRITE("ioctl(DRM_VERSION).name", (Addr)data->name, data->name_len);
   7113          PRE_MEM_READ("ioctl(DRM_VERSION).date_len", (Addr)&data->date_len, sizeof(data->date_len));
   7114          PRE_MEM_READ("ioctl(DRM_VERSION).date", (Addr)&data->date, sizeof(data->date));
   7115          PRE_MEM_WRITE("ioctl(DRM_VERSION).date", (Addr)data->date, data->date_len);
   7116          PRE_MEM_READ("ioctl(DRM_VERSION).desc_len", (Addr)&data->desc_len, sizeof(data->desc_len));
   7117          PRE_MEM_READ("ioctl(DRM_VERSION).desc", (Addr)&data->desc, sizeof(data->desc));
   7118          PRE_MEM_WRITE("ioctl(DRM_VERSION).desc", (Addr)data->desc, data->desc_len);
   7119       }
   7120       break;
   7121    case VKI_DRM_IOCTL_GET_UNIQUE:
   7122       if (ARG3) {
   7123          struct vki_drm_unique *data = (struct vki_drm_unique *)ARG3;
   7124 	 PRE_MEM_READ("ioctl(DRM_GET_UNIQUE).unique_len", (Addr)&data->unique_len, sizeof(data->unique_len));
   7125 	 PRE_MEM_READ("ioctl(DRM_GET_UNIQUE).unique", (Addr)&data->unique, sizeof(data->unique));
   7126 	 PRE_MEM_WRITE("ioctl(DRM_GET_UNIQUE).unique", (Addr)data->unique, data->unique_len);
   7127       }
   7128       break;
   7129    case VKI_DRM_IOCTL_GET_MAGIC:
   7130       if (ARG3) {
   7131          struct vki_drm_auth *data = (struct vki_drm_auth *)ARG3;
   7132          PRE_MEM_WRITE("ioctl(DRM_GET_MAGIC).magic", (Addr)&data->magic, sizeof(data->magic));
   7133       }
   7134       break;
   7135    case VKI_DRM_IOCTL_WAIT_VBLANK:
   7136       if (ARG3) {
   7137          union vki_drm_wait_vblank *data = (union vki_drm_wait_vblank *)ARG3;
   7138 	 PRE_MEM_READ("ioctl(DRM_WAIT_VBLANK).request.type", (Addr)&data->request.type, sizeof(data->request.type));
   7139 	 PRE_MEM_READ("ioctl(DRM_WAIT_VBLANK).request.sequence", (Addr)&data->request.sequence, sizeof(data->request.sequence));
   7140 	 /* XXX: It seems request.signal isn't used */
   7141          PRE_MEM_WRITE("ioctl(DRM_WAIT_VBLANK).reply", (Addr)&data->reply, sizeof(data->reply));
   7142       }
   7143       break;
   7144    case VKI_DRM_IOCTL_GEM_CLOSE:
   7145       if (ARG3) {
   7146          struct vki_drm_gem_close *data = (struct vki_drm_gem_close *)ARG3;
   7147 	 PRE_MEM_READ("ioctl(DRM_GEM_CLOSE).handle", (Addr)&data->handle, sizeof(data->handle));
   7148       }
   7149       break;
   7150    case VKI_DRM_IOCTL_GEM_FLINK:
   7151       if (ARG3) {
   7152          struct vki_drm_gem_flink *data = (struct vki_drm_gem_flink *)ARG3;
   7153 	 PRE_MEM_READ("ioctl(DRM_GEM_FLINK).handle", (Addr)&data->handle, sizeof(data->handle));
   7154          PRE_MEM_WRITE("ioctl(DRM_GEM_FLINK).name", (Addr)&data->name, sizeof(data->name));
   7155       }
   7156       break;
   7157    case VKI_DRM_IOCTL_GEM_OPEN:
   7158       if (ARG3) {
   7159          struct vki_drm_gem_open *data = (struct vki_drm_gem_open *)ARG3;
   7160 	 PRE_MEM_READ("ioctl(DRM_GEM_OPEN).name", (Addr)&data->name, sizeof(data->name));
   7161 	 PRE_MEM_WRITE("ioctl(DRM_GEM_OPEN).handle", (Addr)&data->handle, sizeof(data->handle));
   7162 	 PRE_MEM_WRITE("ioctl(DRM_GEM_OPEN).size", (Addr)&data->size, sizeof(data->size));
   7163       }
   7164       break;
   7165    case VKI_DRM_IOCTL_I915_GETPARAM:
   7166       if (ARG3) {
   7167          vki_drm_i915_getparam_t *data = (vki_drm_i915_getparam_t *)ARG3;
   7168 	 PRE_MEM_READ("ioctl(DRM_I915_GETPARAM).param", (Addr)&data->param, sizeof(data->param));
   7169 	 PRE_MEM_WRITE("ioctl(DRM_I915_GETPARAM).value", (Addr)data->value, sizeof(int));
   7170       }
   7171       break;
   7172    case VKI_DRM_IOCTL_I915_GEM_BUSY:
   7173       if (ARG3) {
   7174          struct vki_drm_i915_gem_busy *data = (struct vki_drm_i915_gem_busy *)ARG3;
   7175 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_BUSY).handle", (Addr)&data->handle, sizeof(data->handle));
   7176          PRE_MEM_WRITE("ioctl(DRM_I915_GEM_BUSY).busy", (Addr)&data->busy, sizeof(data->busy));
   7177       }
   7178       break;
   7179    case VKI_DRM_IOCTL_I915_GEM_CREATE:
   7180       if (ARG3) {
   7181          struct vki_drm_i915_gem_create *data = (struct vki_drm_i915_gem_create *)ARG3;
   7182 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_CREATE).size", (Addr)&data->size, sizeof(data->size));
   7183 	 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_CREATE).handle", (Addr)&data->handle, sizeof(data->handle));
   7184       }
   7185       break;
   7186    case VKI_DRM_IOCTL_I915_GEM_PREAD:
   7187       if (ARG3) {
   7188          struct vki_drm_i915_gem_pread *data = (struct vki_drm_i915_gem_pread *)ARG3;
   7189 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).handle", (Addr)&data->handle, sizeof(data->handle));
   7190 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).offset", (Addr)&data->offset, sizeof(data->offset));
   7191 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).size", (Addr)&data->size, sizeof(data->size));
   7192 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).data_ptr", (Addr)&data->data_ptr, sizeof(data->data_ptr));
   7193 	 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_PREAD).data_ptr", (Addr)data->data_ptr, data->size);
   7194       }
   7195       break;
   7196    case VKI_DRM_IOCTL_I915_GEM_PWRITE:
   7197       if (ARG3) {
   7198          struct vki_drm_i915_gem_pwrite *data = (struct vki_drm_i915_gem_pwrite *)ARG3;
   7199 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).handle", (Addr)&data->handle, sizeof(data->handle));
   7200 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).offset", (Addr)&data->offset, sizeof(data->offset));
   7201 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).size", (Addr)&data->size, sizeof(data->size));
   7202 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).data_ptr", (Addr)&data->data_ptr, sizeof(data->data_ptr));
   7203 	 /* PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).data_ptr", (Addr)data->data_ptr, data->size);
   7204 	  * NB: the buffer is allowed to contain any amount of uninitialized data (e.g.
   7205 	  * interleaved vertex attributes may have a wide stride with uninitialized data between
   7206 	  * consecutive vertices) */
   7207       }
   7208       break;
   7209    case VKI_DRM_IOCTL_I915_GEM_MMAP_GTT:
   7210       if (ARG3) {
   7211          struct vki_drm_i915_gem_mmap_gtt *data = (struct vki_drm_i915_gem_mmap_gtt *)ARG3;
   7212 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP_GTT).handle", (Addr)&data->handle, sizeof(data->handle));
   7213          PRE_MEM_WRITE("ioctl(DRM_I915_GEM_MMAP_GTT).offset", (Addr)&data->offset, sizeof(data->offset));
   7214       }
   7215       break;
   7216    case VKI_DRM_IOCTL_I915_GEM_SET_DOMAIN:
   7217       if (ARG3) {
   7218          struct vki_drm_i915_gem_set_domain *data = (struct vki_drm_i915_gem_set_domain *)ARG3;
   7219 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).handle", (Addr)&data->handle, sizeof(data->handle));
   7220 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).read_domains", (Addr)&data->read_domains, sizeof(data->read_domains));
   7221 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).write_domain", (Addr)&data->write_domain, sizeof(data->write_domain));
   7222       }
   7223       break;
   7224    case VKI_DRM_IOCTL_I915_GEM_SET_TILING:
   7225       if (ARG3) {
   7226          struct vki_drm_i915_gem_set_tiling *data = (struct vki_drm_i915_gem_set_tiling *)ARG3;
   7227 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).handle", (Addr)&data->handle, sizeof(data->handle));
   7228          PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).tiling_mode", (Addr)&data->tiling_mode, sizeof(data->tiling_mode));
   7229          PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).stride", (Addr)&data->stride, sizeof(data->stride));
   7230          PRE_MEM_WRITE("ioctl(DRM_I915_GEM_SET_TILING).swizzle_mode", (Addr)&data->swizzle_mode, sizeof(data->swizzle_mode));
   7231       }
   7232       break;
   7233    case VKI_DRM_IOCTL_I915_GEM_GET_TILING:
   7234       if (ARG3) {
   7235          struct vki_drm_i915_gem_get_tiling *data = (struct vki_drm_i915_gem_get_tiling *)ARG3;
   7236 	 PRE_MEM_READ("ioctl(DRM_I915_GEM_GET_TILING).handle", (Addr)&data->handle, sizeof(data->handle));
   7237 	 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_TILING).tiling_mode", (Addr)&data->tiling_mode, sizeof(data->tiling_mode));
   7238          PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_TILING).swizzle_mode", (Addr)&data->swizzle_mode, sizeof(data->swizzle_mode));
   7239       }
   7240       break;
   7241    case VKI_DRM_IOCTL_I915_GEM_GET_APERTURE:
   7242       if (ARG3) {
   7243          struct vki_drm_i915_gem_get_aperture *data = (struct vki_drm_i915_gem_get_aperture *)ARG3;
   7244          PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_APERTURE).aper_size", (Addr)&data->aper_size, sizeof(data->aper_size));
   7245          PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_APERTURE).aper_available_size", (Addr)&data->aper_available_size, sizeof(data->aper_available_size));
   7246       }
   7247       break;
   7248 
   7249    /* KVM ioctls that check for a numeric value as parameter */
   7250    case VKI_KVM_GET_API_VERSION:
   7251    case VKI_KVM_CREATE_VM:
   7252    case VKI_KVM_GET_VCPU_MMAP_SIZE:
   7253    case VKI_KVM_CHECK_EXTENSION:
   7254    case VKI_KVM_SET_TSS_ADDR:
   7255    case VKI_KVM_CREATE_VCPU:
   7256    case VKI_KVM_RUN:
   7257       break;
   7258 
   7259    case VKI_KVM_S390_MEM_OP: {
   7260       struct vki_kvm_s390_mem_op *args =
   7261          (struct vki_kvm_s390_mem_op *)(ARG3);
   7262       PRE_MEM_READ("ioctl(KVM_S390_MEM_OP)", ARG3,
   7263                    sizeof(struct vki_kvm_s390_mem_op));
   7264       if (args->flags & VKI_KVM_S390_MEMOP_F_CHECK_ONLY)
   7265          break;
   7266       if (args->op == VKI_KVM_S390_MEMOP_LOGICAL_READ)
   7267          PRE_MEM_WRITE("ioctl(KVM_S390_MEM_OP).buf", (Addr)args->buf, args->size);
   7268       if (args->op == VKI_KVM_S390_MEMOP_LOGICAL_WRITE)
   7269          PRE_MEM_READ("ioctl(KVM_S390_MEM_OP).buf", (Addr)args->buf, args->size);
   7270       }
   7271       break;
   7272 
   7273 
   7274 #ifdef ENABLE_XEN
   7275    case VKI_XEN_IOCTL_PRIVCMD_HYPERCALL: {
   7276       SyscallArgs harrghs;
   7277       struct vki_xen_privcmd_hypercall *args =
   7278          (struct vki_xen_privcmd_hypercall *)(ARG3);
   7279 
   7280       if (!args)
   7281          break;
   7282 
   7283       VG_(memset)(&harrghs, 0, sizeof(harrghs));
   7284       harrghs.sysno = args->op;
   7285       harrghs.arg1 = args->arg[0];
   7286       harrghs.arg2 = args->arg[1];
   7287       harrghs.arg3 = args->arg[2];
   7288       harrghs.arg4 = args->arg[3];
   7289       harrghs.arg5 = args->arg[4];
   7290       harrghs.arg6 = harrghs.arg7 = harrghs.arg8 = 0;
   7291 
   7292       WRAPPER_PRE_NAME(xen, hypercall) (tid, layout, &harrghs, status, flags);
   7293 
   7294       /* HACK. arg8 is used to return the number of hypercall
   7295        * arguments actually consumed! */
   7296       PRE_MEM_READ("hypercall", ARG3, sizeof(args->op) +
   7297                    ( sizeof(args->arg[0]) * harrghs.arg8 ) );
   7298 
   7299       break;
   7300    }
   7301 
   7302    case VKI_XEN_IOCTL_PRIVCMD_MMAP: {
   7303        struct vki_xen_privcmd_mmap *args =
   7304            (struct vki_xen_privcmd_mmap *)(ARG3);
   7305        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(num)",
   7306                     (Addr)&args->num, sizeof(args->num));
   7307        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(dom)",
   7308                     (Addr)&args->dom, sizeof(args->dom));
   7309        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(entry)",
   7310                     (Addr)args->entry, sizeof(*(args->entry)) * args->num);
   7311       break;
   7312    }
   7313    case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH: {
   7314        struct vki_xen_privcmd_mmapbatch *args =
   7315            (struct vki_xen_privcmd_mmapbatch *)(ARG3);
   7316        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(num)",
   7317                     (Addr)&args->num, sizeof(args->num));
   7318        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(dom)",
   7319                     (Addr)&args->dom, sizeof(args->dom));
   7320        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(addr)",
   7321                     (Addr)&args->addr, sizeof(args->addr));
   7322        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(arr)",
   7323                     (Addr)args->arr, sizeof(*(args->arr)) * args->num);
   7324       break;
   7325    }
   7326    case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2: {
   7327        struct vki_xen_privcmd_mmapbatch_v2 *args =
   7328            (struct vki_xen_privcmd_mmapbatch_v2 *)(ARG3);
   7329        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(num)",
   7330                     (Addr)&args->num, sizeof(args->num));
   7331        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(dom)",
   7332                     (Addr)&args->dom, sizeof(args->dom));
   7333        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(addr)",
   7334                     (Addr)&args->addr, sizeof(args->addr));
   7335        PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(arr)",
   7336                     (Addr)args->arr, sizeof(*(args->arr)) * args->num);
   7337       break;
   7338    }
   7339 
   7340    case VKI_XEN_IOCTL_EVTCHN_BIND_VIRQ: {
   7341          struct vki_xen_ioctl_evtchn_bind_virq *args =
   7342             (struct vki_xen_ioctl_evtchn_bind_virq *)(ARG3);
   7343          PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_VIRQ(virq)",
   7344                  (Addr)&args->virq, sizeof(args->virq));
   7345       }
   7346       break;
   7347    case VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN: {
   7348          struct vki_xen_ioctl_evtchn_bind_interdomain *args =
   7349             (struct vki_xen_ioctl_evtchn_bind_interdomain *)(ARG3);
   7350          PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN(remote_domain)",
   7351                  (Addr)&args->remote_domain, sizeof(args->remote_domain));
   7352          PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN(remote_port)",
   7353                  (Addr)&args->remote_port, sizeof(args->remote_port));
   7354       }
   7355       break;
   7356    case VKI_XEN_IOCTL_EVTCHN_BIND_UNBOUND_PORT: {
   7357          struct vki_xen_ioctl_evtchn_bind_unbound_port *args =
   7358             (struct vki_xen_ioctl_evtchn_bind_unbound_port *)(ARG3);
   7359          PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_BIND_UNBOUND_PORT(remote_domain)",
   7360                  (Addr)&args->remote_domain, sizeof(args->remote_domain));
   7361       }
   7362       break;
   7363    case VKI_XEN_IOCTL_EVTCHN_UNBIND: {
   7364          struct vki_xen_ioctl_evtchn_unbind *args =
   7365             (struct vki_xen_ioctl_evtchn_unbind *)(ARG3);
   7366          PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_UNBIND(port)",
   7367                  (Addr)&args->port, sizeof(args->port));
   7368       }
   7369       break;
   7370    case VKI_XEN_IOCTL_EVTCHN_NOTIFY: {
   7371          struct vki_xen_ioctl_evtchn_notify *args =
   7372             (struct vki_xen_ioctl_evtchn_notify*)(ARG3);
   7373          PRE_MEM_READ("VKI_XEN_IOCTL_EVTCHN_notify(port)",
   7374                  (Addr)&args->port, sizeof(args->port));
   7375       }
   7376       break;
   7377    case VKI_XEN_IOCTL_EVTCHN_RESET:
   7378       /* No input*/
   7379       break;
   7380 #endif
   7381 
   7382    /* Lustre */
   7383    case VKI_OBD_IOC_FID2PATH: {
   7384       struct vki_getinfo_fid2path *gf = (struct vki_getinfo_fid2path *)ARG3;
   7385       PRE_MEM_READ("VKI_OBD_IOC_FID2PATH(args)", ARG3, sizeof(struct vki_getinfo_fid2path));
   7386       PRE_FIELD_WRITE("VKI_OBD_IOC_FID2PATH(args).gf_recno", gf->gf_recno);
   7387       PRE_FIELD_WRITE("VKI_OBD_IOC_FID2PATH(args).gf_linkno", gf->gf_linkno);
   7388       PRE_MEM_WRITE("VKI_OBD_IOC_FID2PATH(args)", (Addr)gf->gf_path, gf->gf_pathlen);
   7389       break;
   7390    }
   7391 
   7392    case VKI_LL_IOC_PATH2FID:
   7393       PRE_MEM_WRITE("ioctl(VKI_LL_IOC_PATH2FID)", ARG3, sizeof(struct vki_lu_fid));
   7394       break;
   7395 
   7396    case VKI_LL_IOC_GETPARENT: {
   7397       struct vki_getparent *gp = (struct vki_getparent *)ARG3;
   7398       PRE_FIELD_READ("ioctl(VKI_LL_IOC_GETPARENT).gp_linkno", gp->gp_linkno);
   7399       PRE_FIELD_READ("ioctl(VKI_LL_IOC_GETPARENT).gp_name_size", gp->gp_name_size);
   7400       PRE_FIELD_WRITE("ioctl(VKI_LL_IOC_GETPARENT).gp_fid", gp->gp_fid);
   7401       PRE_MEM_WRITE("ioctl(VKI_LL_IOC_GETPARENT).gp_name", (Addr)gp->gp_name, gp->gp_name_size);
   7402       break;
   7403    }
   7404 
   7405    /* V4L2 */
   7406    case VKI_V4L2_QUERYCAP: {
   7407       struct vki_v4l2_capability *data = (struct vki_v4l2_capability *)ARG3;
   7408       PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYCAP)", (Addr)data, sizeof(*data));
   7409       break;
   7410    }
   7411    case VKI_V4L2_ENUM_FMT: {
   7412       struct vki_v4l2_fmtdesc *data = (struct vki_v4l2_fmtdesc *)ARG3;
   7413       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FMT).index", data->index);
   7414       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FMT).type", data->type);
   7415       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).flags", data->flags);
   7416       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).description", data->description);
   7417       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).pixelformat", data->pixelformat);
   7418       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FMT).reserved", data->reserved);
   7419       break;
   7420    }
   7421    case VKI_V4L2_G_FMT: {
   7422       struct vki_v4l2_format *data = (struct vki_v4l2_format *)ARG3;
   7423       PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).type", data->type);
   7424       switch (data->type) {
   7425       case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE:
   7426       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT:
   7427          PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.pix.priv", data->fmt.pix.priv);
   7428          PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.pix", data->fmt.pix);
   7429          PRE_MEM_READ("ioctl(VKI_V4L2_G_FMT)",
   7430                (Addr)&data->type + sizeof(data->type) + sizeof(data->fmt.pix),
   7431                sizeof(*data) - sizeof(data->type) - sizeof(data->fmt.pix));
   7432          break;
   7433       case VKI_V4L2_BUF_TYPE_VBI_CAPTURE:
   7434       case VKI_V4L2_BUF_TYPE_VBI_OUTPUT:
   7435          PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.vbi", data->fmt.vbi);
   7436          break;
   7437       case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
   7438       case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
   7439          PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.sliced", data->fmt.sliced);
   7440          break;
   7441       case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY:
   7442       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
   7443          PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.win.clips", data->fmt.win.clips);
   7444          PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.win.bitmap", data->fmt.win.bitmap);
   7445          PRE_FIELD_READ("ioctl(VKI_V4L2_G_FMT).fmt.win.clipcount", data->fmt.win.clipcount);
   7446          if (data->fmt.win.clipcount && data->fmt.win.clips)
   7447             PRE_MEM_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.clips[]",
   7448                   (Addr)data->fmt.win.clips,
   7449                   data->fmt.win.clipcount * sizeof(data->fmt.win.clips[0]));
   7450          PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.clipcount", data->fmt.win.clipcount);
   7451          PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.w", data->fmt.win.w);
   7452          PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.field", data->fmt.win.field);
   7453          PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.chromakey", data->fmt.win.chromakey);
   7454          PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.win.global_alpha", data->fmt.win.global_alpha);
   7455          break;
   7456       case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
   7457       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
   7458          PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.pix_mp", data->fmt.pix_mp);
   7459          break;
   7460       case VKI_V4L2_BUF_TYPE_SDR_CAPTURE:
   7461          PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FMT).fmt.sdr", data->fmt.sdr);
   7462          break;
   7463       }
   7464       break;
   7465    }
   7466    case VKI_V4L2_S_FMT: {
   7467       struct vki_v4l2_format *data = (struct vki_v4l2_format *)ARG3;
   7468       PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).type", data->type);
   7469       switch (data->type) {
   7470       case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE:
   7471       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT:
   7472          PRE_MEM_READ("ioctl(VKI_V4L2_S_FMT)",
   7473                (Addr)&data->type + sizeof(data->type),
   7474                sizeof(*data) - sizeof(data->type));
   7475          break;
   7476       case VKI_V4L2_BUF_TYPE_VBI_CAPTURE:
   7477       case VKI_V4L2_BUF_TYPE_VBI_OUTPUT:
   7478          PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.vbi", data->fmt.vbi);
   7479          break;
   7480       case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
   7481       case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
   7482          PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.sliced", data->fmt.sliced);
   7483          break;
   7484       case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY:
   7485       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
   7486          PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.win", data->fmt.win);
   7487          if (data->fmt.win.clipcount && data->fmt.win.clips)
   7488             PRE_MEM_READ("ioctl(VKI_V4L2_S_FMT).fmt.win.clips[]",
   7489                   (Addr)data->fmt.win.clips,
   7490                   data->fmt.win.clipcount * sizeof(data->fmt.win.clips[0]));
   7491          if (data->fmt.win.bitmap)
   7492             PRE_MEM_READ("ioctl(VKI_V4L2_S_FMT).fmt.win.bitmap[]",
   7493                   (Addr)data->fmt.win.bitmap,
   7494                   data->fmt.win.w.height * ((data->fmt.win.w.width + 7) / 8));
   7495          break;
   7496       case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
   7497       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
   7498          PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.pix_mp", data->fmt.pix_mp);
   7499          break;
   7500       case VKI_V4L2_BUF_TYPE_SDR_CAPTURE:
   7501          PRE_FIELD_READ("ioctl(VKI_V4L2_S_FMT).fmt.sdr", data->fmt.sdr);
   7502          break;
   7503       }
   7504       break;
   7505    }
   7506    case VKI_V4L2_TRY_FMT: {
   7507       struct vki_v4l2_format *data = (struct vki_v4l2_format *)ARG3;
   7508       PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).type", data->type);
   7509       switch (data->type) {
   7510       case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE:
   7511       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT:
   7512          PRE_MEM_READ("ioctl(VKI_V4L2_TRY_FMT)",
   7513                (Addr)&data->type + sizeof(data->type),
   7514                sizeof(*data) - sizeof(data->type));
   7515          break;
   7516       case VKI_V4L2_BUF_TYPE_VBI_CAPTURE:
   7517       case VKI_V4L2_BUF_TYPE_VBI_OUTPUT:
   7518          PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.vbi", data->fmt.vbi);
   7519          break;
   7520       case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
   7521       case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
   7522          PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.sliced", data->fmt.sliced);
   7523          break;
   7524       case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY:
   7525       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
   7526          PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.win", data->fmt.win);
   7527          if (data->fmt.win.clipcount && data->fmt.win.clips)
   7528             PRE_MEM_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.win.clips[]",
   7529                   (Addr)data->fmt.win.clips,
   7530                   data->fmt.win.clipcount * sizeof(data->fmt.win.clips[0]));
   7531          if (data->fmt.win.bitmap)
   7532             PRE_MEM_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.win.bitmap[]",
   7533                   (Addr)data->fmt.win.bitmap,
   7534                   data->fmt.win.w.height * ((data->fmt.win.w.width + 7) / 8));
   7535          break;
   7536       case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
   7537       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
   7538          PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.pix_mp", data->fmt.pix_mp);
   7539          break;
   7540       case VKI_V4L2_BUF_TYPE_SDR_CAPTURE:
   7541          PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_FMT).fmt.sdr", data->fmt.sdr);
   7542          break;
   7543       }
   7544       break;
   7545    }
   7546    case VKI_V4L2_REQBUFS: {
   7547       struct vki_v4l2_requestbuffers *data = (struct vki_v4l2_requestbuffers *)ARG3;
   7548       PRE_MEM_READ("ioctl(VKI_V4L2_REQBUFS)", (Addr)data, sizeof(*data));
   7549       break;
   7550    }
   7551    case VKI_V4L2_QUERYBUF: {
   7552       struct vki_v4l2_buffer *data = (struct vki_v4l2_buffer *)ARG3;
   7553       PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).type", data->type);
   7554       PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).index", data->index);
   7555       PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).reserved", data->reserved);
   7556       PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).reserved2", data->reserved2);
   7557       if (data->type == VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
   7558             data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
   7559          unsigned i;
   7560 
   7561          PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).length", data->length);
   7562          PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYBUF).m.planes", data->m.planes);
   7563          for (i = 0; i < data->length; i++) {
   7564             PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].bytesused", data->m.planes[i].bytesused);
   7565             PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].length", data->m.planes[i].length);
   7566             PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].m", data->m.planes[i].m);
   7567             PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].data_offset", data->m.planes[i].data_offset);
   7568             PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m.planes[].reserved", data->m.planes[i].reserved);
   7569          }
   7570       } else {
   7571          PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).m", data->m);
   7572          PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).length", data->length);
   7573       }
   7574       PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).bytesused", data->bytesused);
   7575       PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).flags", data->flags);
   7576       PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).field", data->field);
   7577       PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).timestamp", data->timestamp);
   7578       PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).timecode", data->timecode);
   7579       PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).sequence", data->sequence);
   7580       PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).memory", data->memory);
   7581       PRE_FIELD_WRITE("ioctl(VKI_V4L2_QUERYBUF).sequence", data->sequence);
   7582       break;
   7583    }
   7584    case VKI_V4L2_G_FBUF: {
   7585       struct vki_v4l2_framebuffer *data = (struct vki_v4l2_framebuffer *)ARG3;
   7586       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_FBUF)", (Addr)data, sizeof(*data));
   7587       break;
   7588    }
   7589    case VKI_V4L2_S_FBUF: {
   7590       struct vki_v4l2_framebuffer *data = (struct vki_v4l2_framebuffer *)ARG3;
   7591       PRE_FIELD_WRITE("ioctl(VKI_V4L2_S_FBUF).capability", data->capability);
   7592       PRE_FIELD_READ("ioctl(VKI_V4L2_S_FBUF).flags", data->flags);
   7593       PRE_FIELD_READ("ioctl(VKI_V4L2_S_FBUF).base", data->base);
   7594       PRE_FIELD_READ("ioctl(VKI_V4L2_S_FBUF).fmt", data->fmt);
   7595       break;
   7596    }
   7597    case VKI_V4L2_OVERLAY: {
   7598       int *data = (int *)ARG3;
   7599       PRE_MEM_READ("ioctl(VKI_V4L2_OVERLAY)", (Addr)data, sizeof(*data));
   7600       break;
   7601    }
   7602    case VKI_V4L2_QBUF: {
   7603       struct vki_v4l2_buffer *data = (struct vki_v4l2_buffer *)ARG3;
   7604       int is_output = data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT ||
   7605          data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ||
   7606          data->type == VKI_V4L2_BUF_TYPE_VBI_OUTPUT ||
   7607          data->type == VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT;
   7608 
   7609       PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).type", data->type);
   7610       PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).index", data->index);
   7611       PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).flags", data->flags);
   7612       PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).memory", data->memory);
   7613       PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).reserved", data->reserved);
   7614       PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).reserved2", data->reserved2);
   7615       if (is_output) {
   7616          PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).bytesused", data->bytesused);
   7617          PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).field", data->field);
   7618       }
   7619       if (data->type == VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
   7620             data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
   7621          unsigned i;
   7622 
   7623          PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).length", data->length);
   7624          PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes", data->m.planes);
   7625          for (i = 0; i < data->length; i++) {
   7626             if (is_output) {
   7627                PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].bytesused", data->m.planes[i].bytesused);
   7628                PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].data_offset", data->m.planes[i].data_offset);
   7629             }
   7630             if (data->memory == VKI_V4L2_MEMORY_MMAP)
   7631                PRE_FIELD_WRITE("ioctl(VKI_V4L2_QBUF).m.planes[].m", data->m.planes[i].m);
   7632             else if (data->memory == VKI_V4L2_MEMORY_DMABUF)
   7633                PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].m.fd", data->m.planes[i].m.fd);
   7634             else
   7635                PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].m", data->m.planes[i].m);
   7636             PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.planes[].reserved", data->m.planes[i].reserved);
   7637          }
   7638       } else {
   7639          if (data->memory == VKI_V4L2_MEMORY_MMAP)
   7640             PRE_FIELD_WRITE("ioctl(VKI_V4L2_QBUF).m", data->m);
   7641          else if (data->memory == VKI_V4L2_MEMORY_DMABUF)
   7642             PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m.fd", data->m.fd);
   7643          else
   7644             PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).m", data->m);
   7645          if (is_output) {
   7646             PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).bytesused", data->bytesused);
   7647             PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).field", data->field);
   7648          }
   7649       }
   7650       if (is_output && (data->flags & VKI_V4L2_BUF_FLAG_TIMESTAMP_MASK) == VKI_V4L2_BUF_FLAG_TIMESTAMP_COPY) {
   7651          PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).timestamp", data->timestamp);
   7652          PRE_FIELD_READ("ioctl(VKI_V4L2_QBUF).timecode", data->timecode);
   7653       }
   7654       break;
   7655    }
   7656    case VKI_V4L2_EXPBUF: {
   7657       struct vki_v4l2_exportbuffer *data = (struct vki_v4l2_exportbuffer *)ARG3;
   7658       PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).type", data->type);
   7659       PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).index", data->index);
   7660       PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).plane", data->plane);
   7661       PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).flags", data->flags);
   7662       PRE_FIELD_WRITE("ioctl(VKI_V4L2_EXPBUF).fd", data->fd);
   7663       PRE_FIELD_READ("ioctl(VKI_V4L2_EXPBUF).reserved", data->reserved);
   7664       break;
   7665    }
   7666    case VKI_V4L2_DQBUF: {
   7667       struct vki_v4l2_buffer *data = (struct vki_v4l2_buffer *)ARG3;
   7668       PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).type", data->type);
   7669       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).index", data->index);
   7670       PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).memory", data->memory);
   7671       PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).reserved", data->reserved);
   7672       PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).reserved2", data->reserved2);
   7673       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).bytesused", data->bytesused);
   7674       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).field", data->field);
   7675       if (data->type == VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
   7676             data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
   7677          unsigned i;
   7678 
   7679          PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).length", data->length);
   7680          PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).m.planes", data->m.planes);
   7681          for (i = 0; i < data->length; i++) {
   7682             PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].bytesused", data->m.planes[i].bytesused);
   7683             PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].data_offset", data->m.planes[i].data_offset);
   7684             PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].length", data->m.planes[i].length);
   7685             PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m.planes[].m", data->m.planes[i].m);
   7686             PRE_FIELD_READ("ioctl(VKI_V4L2_DQBUF).m.planes[].reserved", data->m.planes[i].reserved);
   7687          }
   7688       } else {
   7689          PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).m", data->m);
   7690          PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).length", data->length);
   7691          PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).bytesused", data->bytesused);
   7692          PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).field", data->field);
   7693       }
   7694       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).timestamp", data->timestamp);
   7695       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).timecode", data->timecode);
   7696       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DQBUF).sequence", data->sequence);
   7697       break;
   7698    }
   7699    case VKI_V4L2_STREAMON: {
   7700       int *data = (int *)ARG3;
   7701       PRE_MEM_READ("ioctl(VKI_V4L2_STREAMON)", (Addr)data, sizeof(*data));
   7702       break;
   7703    }
   7704    case VKI_V4L2_STREAMOFF: {
   7705       int *data = (int *)ARG3;
   7706       PRE_MEM_READ("ioctl(VKI_V4L2_STREAMOFF)", (Addr)data, sizeof(*data));
   7707       break;
   7708    }
   7709    case VKI_V4L2_G_PARM: {
   7710       struct vki_v4l2_streamparm *data = (struct vki_v4l2_streamparm *)ARG3;
   7711       int is_output = data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT ||
   7712          data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ||
   7713          data->type == VKI_V4L2_BUF_TYPE_VBI_OUTPUT ||
   7714          data->type == VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT;
   7715 
   7716       PRE_FIELD_READ("ioctl(VKI_V4L2_G_PARM).type", data->type);
   7717       if (is_output) {
   7718          PRE_MEM_WRITE("ioctl(VKI_V4L2_G_PARM)", (Addr)&data->parm.output,
   7719             sizeof(data->parm.output) - sizeof(data->parm.output.reserved));
   7720          PRE_FIELD_READ("ioctl(VKI_V4L2_G_PARM).parm.output.reserved", data->parm.output.reserved);
   7721       } else {
   7722          PRE_MEM_WRITE("ioctl(VKI_V4L2_G_PARM)", (Addr)&data->parm.capture,
   7723             sizeof(data->parm.capture) - sizeof(data->parm.capture.reserved));
   7724          PRE_FIELD_READ("ioctl(VKI_V4L2_G_PARM).parm.capture.reserved", data->parm.capture.reserved);
   7725       }
   7726       break;
   7727    }
   7728    case VKI_V4L2_S_PARM: {
   7729       struct vki_v4l2_streamparm *data = (struct vki_v4l2_streamparm *)ARG3;
   7730       int is_output = data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT ||
   7731          data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ||
   7732          data->type == VKI_V4L2_BUF_TYPE_VBI_OUTPUT ||
   7733          data->type == VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT;
   7734 
   7735       PRE_FIELD_READ("ioctl(VKI_V4L2_S_PARM).type", data->type);
   7736       if (is_output)
   7737          PRE_FIELD_READ("ioctl(VKI_V4L2_S_PARM).parm.output", data->parm.output);
   7738       else
   7739          PRE_FIELD_READ("ioctl(VKI_V4L2_S_PARM).parm.capture", data->parm.capture);
   7740       break;
   7741    }
   7742    case VKI_V4L2_G_STD: {
   7743       vki_v4l2_std_id *data = (vki_v4l2_std_id *)ARG3;
   7744       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_STD)", (Addr)data, sizeof(*data));
   7745       break;
   7746    }
   7747    case VKI_V4L2_S_STD: {
   7748       vki_v4l2_std_id *data = (vki_v4l2_std_id *)ARG3;
   7749       PRE_MEM_READ("ioctl(VKI_V4L2_S_STD)", (Addr)data, sizeof(*data));
   7750       break;
   7751    }
   7752    case VKI_V4L2_ENUMSTD: {
   7753       struct vki_v4l2_standard *data = (struct vki_v4l2_standard *)ARG3;
   7754       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMSTD).index", data->index);
   7755       PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMSTD)", (Addr)&data->id, sizeof(*data) - sizeof(data->index));
   7756       break;
   7757    }
   7758    case VKI_V4L2_ENUMINPUT: {
   7759       struct vki_v4l2_input *data = (struct vki_v4l2_input *)ARG3;
   7760       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMINPUT).index", data->index);
   7761       PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMINPUT)", (Addr)data->name, sizeof(*data) - sizeof(data->index));
   7762       break;
   7763    }
   7764    case VKI_V4L2_G_CTRL: {
   7765       struct vki_v4l2_control *data = (struct vki_v4l2_control *)ARG3;
   7766       PRE_FIELD_READ("ioctl(VKI_V4L2_G_CTRL).id", data->id);
   7767       PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_CTRL).value", data->value);
   7768       break;
   7769    }
   7770    case VKI_V4L2_S_CTRL: {
   7771       struct vki_v4l2_control *data = (struct vki_v4l2_control *)ARG3;
   7772       PRE_MEM_READ("ioctl(VKI_V4L2_S_CTRL)", (Addr)data, sizeof(*data));
   7773       break;
   7774    }
   7775    case VKI_V4L2_G_TUNER: {
   7776       struct vki_v4l2_tuner *data = (struct vki_v4l2_tuner *)ARG3;
   7777       PRE_FIELD_READ("ioctl(VKI_V4L2_G_TUNER).index", data->index);
   7778       PRE_FIELD_READ("ioctl(VKI_V4L2_G_TUNER).reserved", data->reserved);
   7779       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_TUNER)", (Addr)data->name,
   7780             sizeof(*data) - sizeof(data->index) - sizeof(data->reserved));
   7781       break;
   7782    }
   7783    case VKI_V4L2_S_TUNER: {
   7784       struct vki_v4l2_tuner *data = (struct vki_v4l2_tuner *)ARG3;
   7785       PRE_FIELD_READ("ioctl(VKI_V4L2_S_TUNER).index", data->index);
   7786       PRE_FIELD_READ("ioctl(VKI_V4L2_S_TUNER).audmode", data->audmode);
   7787       PRE_FIELD_READ("ioctl(VKI_V4L2_S_TUNER).reserved", data->reserved);
   7788       break;
   7789    }
   7790    case VKI_V4L2_G_AUDIO: {
   7791       struct vki_v4l2_audio *data = (struct vki_v4l2_audio *)ARG3;
   7792       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_AUDIO)", (Addr)data,
   7793             sizeof(*data) - sizeof(data->reserved));
   7794       PRE_FIELD_READ("ioctl(VKI_V4L2_G_AUDIO).reserved", data->reserved);
   7795       break;
   7796    }
   7797    case VKI_V4L2_S_AUDIO: {
   7798       struct vki_v4l2_audio *data = (struct vki_v4l2_audio *)ARG3;
   7799       PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDIO).index", data->index);
   7800       PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDIO).mode", data->mode);
   7801       PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDIO).reserved", data->reserved);
   7802       break;
   7803    }
   7804    case VKI_V4L2_QUERYCTRL: {
   7805       struct vki_v4l2_queryctrl *data = (struct vki_v4l2_queryctrl *)ARG3;
   7806       PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYCTRL).id", data->id);
   7807       PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYCTRL)", (Addr)&data->type,
   7808             sizeof(*data) - sizeof(data->id));
   7809       break;
   7810    }
   7811    case VKI_V4L2_QUERYMENU: {
   7812       struct vki_v4l2_querymenu *data = (struct vki_v4l2_querymenu *)ARG3;
   7813       PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYMENU).id", data->id);
   7814       PRE_FIELD_READ("ioctl(VKI_V4L2_QUERYMENU).index", data->index);
   7815       PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYMENU)", (Addr)data->name,
   7816             sizeof(*data) - sizeof(data->id) - sizeof(data->index));
   7817       break;
   7818    }
   7819    case VKI_V4L2_G_INPUT: {
   7820       int *data = (int *)ARG3;
   7821       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_INPUT)", (Addr)data, sizeof(*data));
   7822       break;
   7823    }
   7824    case VKI_V4L2_S_INPUT: {
   7825       int *data = (int *)ARG3;
   7826       PRE_MEM_READ("ioctl(VKI_V4L2_S_INPUT)", (Addr)data, sizeof(*data));
   7827       break;
   7828    }
   7829    case VKI_V4L2_G_EDID: {
   7830       struct vki_v4l2_edid *data = (struct vki_v4l2_edid *)ARG3;
   7831       PRE_MEM_READ("ioctl(VKI_V4L2_G_EDID)", (Addr)data, sizeof(*data));
   7832       if (data->blocks && data->edid)
   7833          PRE_MEM_WRITE("ioctl(VKI_V4L2_G_EDID)", (Addr)data->edid, data->blocks * 128);
   7834       break;
   7835    }
   7836    case VKI_V4L2_S_EDID: {
   7837       struct vki_v4l2_edid *data = (struct vki_v4l2_edid *)ARG3;
   7838       PRE_MEM_READ("ioctl(VKI_V4L2_S_EDID)", (Addr)data, sizeof(*data));
   7839       if (data->blocks && data->edid)
   7840          PRE_MEM_READ("ioctl(VKI_V4L2_S_EDID)", (Addr)data->edid, data->blocks * 128);
   7841       break;
   7842    }
   7843    case VKI_V4L2_G_OUTPUT: {
   7844       int *data = (int *)ARG3;
   7845       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_OUTPUT)", (Addr)data, sizeof(*data));
   7846       break;
   7847    }
   7848    case VKI_V4L2_S_OUTPUT: {
   7849       int *data = (int *)ARG3;
   7850       PRE_MEM_READ("ioctl(VKI_V4L2_S_OUTPUT)", (Addr)data, sizeof(*data));
   7851       break;
   7852    }
   7853    case VKI_V4L2_ENUMOUTPUT: {
   7854       struct vki_v4l2_output *data = (struct vki_v4l2_output *)ARG3;
   7855       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMOUTPUT).index", data->index);
   7856       PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMOUTPUT)", (Addr)data->name, sizeof(*data) - sizeof(data->index));
   7857       break;
   7858    }
   7859    case VKI_V4L2_G_AUDOUT: {
   7860       struct vki_v4l2_audioout *data = (struct vki_v4l2_audioout *)ARG3;
   7861       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_AUDOUT)", (Addr)data,
   7862             sizeof(*data) - sizeof(data->reserved));
   7863       PRE_FIELD_READ("ioctl(VKI_V4L2_G_AUDOUT).reserved", data->reserved);
   7864       break;
   7865    }
   7866    case VKI_V4L2_S_AUDOUT: {
   7867       struct vki_v4l2_audioout *data = (struct vki_v4l2_audioout *)ARG3;
   7868       PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDOUT).index", data->index);
   7869       PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDOUT).reserved", data->reserved);
   7870       PRE_FIELD_READ("ioctl(VKI_V4L2_S_AUDOUT).mode", data->mode);
   7871       break;
   7872    }
   7873    case VKI_V4L2_G_MODULATOR: {
   7874       struct vki_v4l2_modulator *data = (struct vki_v4l2_modulator *)ARG3;
   7875       PRE_FIELD_READ("ioctl(VKI_V4L2_G_MODULATOR).index", data->index);
   7876       PRE_FIELD_READ("ioctl(VKI_V4L2_G_MODULATOR).reserved", data->reserved);
   7877       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_MODULATOR)", (Addr)data->name,
   7878             sizeof(*data) - sizeof(data->index) - sizeof(data->reserved));
   7879       break;
   7880    }
   7881    case VKI_V4L2_S_MODULATOR: {
   7882       struct vki_v4l2_modulator *data = (struct vki_v4l2_modulator *)ARG3;
   7883       PRE_FIELD_READ("ioctl(VKI_V4L2_S_MODULATOR).index", data->index);
   7884       PRE_FIELD_READ("ioctl(VKI_V4L2_S_MODULATOR).txsubchans", data->txsubchans);
   7885       PRE_FIELD_READ("ioctl(VKI_V4L2_S_MODULATOR).reserved", data->reserved);
   7886       break;
   7887    }
   7888    case VKI_V4L2_G_FREQUENCY: {
   7889       struct vki_v4l2_frequency *data = (struct vki_v4l2_frequency *)ARG3;
   7890       PRE_FIELD_READ("ioctl(VKI_V4L2_G_FREQUENCY).tuner", data->tuner);
   7891       PRE_FIELD_READ("ioctl(VKI_V4L2_G_FREQUENCY).reserved", data->reserved);
   7892       PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FREQUENCY).type", data->type);
   7893       PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_FREQUENCY).frequency", data->frequency);
   7894       break;
   7895    }
   7896    case VKI_V4L2_S_FREQUENCY: {
   7897       struct vki_v4l2_frequency *data = (struct vki_v4l2_frequency *)ARG3;
   7898       PRE_MEM_READ("ioctl(VKI_V4L2_S_FREQUENCY)", (Addr)data, sizeof(*data));
   7899       break;
   7900    }
   7901    case VKI_V4L2_CROPCAP: {
   7902       struct vki_v4l2_cropcap *data = (struct vki_v4l2_cropcap *)ARG3;
   7903       PRE_FIELD_READ("ioctl(VKI_V4L2_CROPCAP)", data->type);
   7904       PRE_MEM_WRITE("ioctl(VKI_V4L2_CROPCAP)", (Addr)&data->bounds, sizeof(*data) - sizeof(data->type));
   7905       break;
   7906    }
   7907    case VKI_V4L2_G_CROP: {
   7908       struct vki_v4l2_crop *data = (struct vki_v4l2_crop *)ARG3;
   7909       PRE_FIELD_READ("ioctl(VKI_V4L2_G_CROP).type", data->type);
   7910       PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_CROP).c", data->c);
   7911       break;
   7912    }
   7913    case VKI_V4L2_S_CROP: {
   7914       struct vki_v4l2_crop *data = (struct vki_v4l2_crop *)ARG3;
   7915       PRE_MEM_READ("ioctl(VKI_V4L2_S_CROP)", (Addr)data, sizeof(*data));
   7916       break;
   7917    }
   7918    case VKI_V4L2_G_JPEGCOMP: {
   7919       struct vki_v4l2_jpegcompression *data = (struct vki_v4l2_jpegcompression *)ARG3;
   7920       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_JPEGCOMP)", (Addr)data, sizeof(*data));
   7921       break;
   7922    }
   7923    case VKI_V4L2_S_JPEGCOMP: {
   7924       struct vki_v4l2_jpegcompression *data = (struct vki_v4l2_jpegcompression *)ARG3;
   7925       PRE_MEM_READ("ioctl(VKI_V4L2_S_JPEGCOMP)", (Addr)data, sizeof(*data));
   7926       break;
   7927    }
   7928    case VKI_V4L2_QUERYSTD: {
   7929       vki_v4l2_std_id *data = (vki_v4l2_std_id *)ARG3;
   7930       PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERYSTD)", (Addr)data, sizeof(*data));
   7931       break;
   7932    }
   7933    case VKI_V4L2_ENUMAUDIO: {
   7934       struct vki_v4l2_audio *data = (struct vki_v4l2_audio *)ARG3;
   7935       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDIO).index", data->index);
   7936       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDIO).reserved", data->reserved);
   7937       PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMAUDIO)", (Addr)data->name,
   7938             sizeof(*data) - sizeof(data->index) - sizeof(data->reserved));
   7939       break;
   7940    }
   7941    case VKI_V4L2_ENUMAUDOUT: {
   7942       struct vki_v4l2_audioout *data = (struct vki_v4l2_audioout *)ARG3;
   7943       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDOUT).index", data->index);
   7944       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUMAUDOUT).reserved", data->reserved);
   7945       PRE_MEM_WRITE("ioctl(VKI_V4L2_ENUMAUDOUT)", (Addr)data->name,
   7946             sizeof(*data) - sizeof(data->index) - sizeof(data->reserved));
   7947       break;
   7948    }
   7949    case VKI_V4L2_G_PRIORITY: {
   7950       __vki_u32 *data = (__vki_u32 *)ARG3;
   7951       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_PRIORITY)", (Addr)data, sizeof(*data));
   7952       break;
   7953    }
   7954    case VKI_V4L2_S_PRIORITY: {
   7955       __vki_u32 *data = (__vki_u32 *)ARG3;
   7956       PRE_MEM_READ("ioctl(VKI_V4L2_S_PRIORITY)", (Addr)data, sizeof(*data));
   7957       break;
   7958    }
   7959    case VKI_V4L2_G_SLICED_VBI_CAP: {
   7960       struct vki_v4l2_sliced_vbi_cap *data = (struct vki_v4l2_sliced_vbi_cap *)ARG3;
   7961       PRE_FIELD_READ("ioctl(VKI_V4L2_G_SLICED_VBI_CAP).type", data->type);
   7962       PRE_FIELD_READ("ioctl(VKI_V4L2_G_SLICED_VBI_CAP).reserved", data->reserved);
   7963       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_SLICED_VBI_CAP)", (Addr)data,
   7964             sizeof(*data) - sizeof(data->type) - sizeof(data->reserved));
   7965       break;
   7966    }
   7967    case VKI_V4L2_G_EXT_CTRLS: {
   7968       struct vki_v4l2_ext_controls *data = (struct vki_v4l2_ext_controls *)ARG3;
   7969       PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).ctrl_class", data->ctrl_class);
   7970       PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).count", data->count);
   7971       if (data->count) {
   7972          unsigned i;
   7973 
   7974          PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls", data->controls);
   7975          for (i = 0; i < data->count; i++) {
   7976             PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].id", data->controls[i].id);
   7977             PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].size", data->controls[i].size);
   7978             PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].reserved2", data->controls[i].reserved2);
   7979             if (data->controls[i].size) {
   7980                PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].ptr", data->controls[i].ptr);
   7981                PRE_MEM_WRITE("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].ptr[]",
   7982                      (Addr)data->controls[i].ptr, data->controls[i].size);
   7983             } else {
   7984                PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_EXT_CTRLS).controls[].value64",
   7985                      data->controls[i].value64);
   7986             }
   7987          }
   7988       }
   7989       PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_EXT_CTRLS).error_idx", data->error_idx);
   7990       PRE_FIELD_READ("ioctl(VKI_V4L2_G_EXT_CTRLS).reserved", data->reserved);
   7991       break;
   7992    }
   7993    case VKI_V4L2_S_EXT_CTRLS: {
   7994       struct vki_v4l2_ext_controls *data = (struct vki_v4l2_ext_controls *)ARG3;
   7995       PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).ctrl_class", data->ctrl_class);
   7996       PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).count", data->count);
   7997       if (data->count) {
   7998          unsigned i;
   7999 
   8000          PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).controls", data->controls);
   8001          PRE_MEM_READ("ioctl(VKI_V4L2_S_EXT_CTRLS)", (Addr)data->controls,
   8002                data->count * sizeof(data->controls[0]));
   8003          for (i = 0; i < data->count; i++) {
   8004             if (data->controls[i].size) {
   8005                PRE_MEM_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).controls[].ptr[]",
   8006                      (Addr)data->controls[i].ptr, data->controls[i].size);
   8007             }
   8008          }
   8009       }
   8010       PRE_FIELD_WRITE("ioctl(VKI_V4L2_S_EXT_CTRLS).error_idx", data->error_idx);
   8011       PRE_FIELD_READ("ioctl(VKI_V4L2_S_EXT_CTRLS).reserved", data->reserved);
   8012       break;
   8013    }
   8014    case VKI_V4L2_TRY_EXT_CTRLS: {
   8015       struct vki_v4l2_ext_controls *data = (struct vki_v4l2_ext_controls *)ARG3;
   8016       PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).ctrl_class", data->ctrl_class);
   8017       PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).count", data->count);
   8018       if (data->count) {
   8019          unsigned i;
   8020 
   8021          PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).controls", data->controls);
   8022          PRE_MEM_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS)", (Addr)data->controls,
   8023                data->count * sizeof(data->controls[0]));
   8024          for (i = 0; i < data->count; i++) {
   8025             if (data->controls[i].size) {
   8026                PRE_MEM_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).controls[].ptr[]",
   8027                      (Addr)data->controls[i].ptr, data->controls[i].size);
   8028             }
   8029          }
   8030       }
   8031       PRE_FIELD_WRITE("ioctl(VKI_V4L2_TRY_EXT_CTRLS).error_idx", data->error_idx);
   8032       PRE_FIELD_READ("ioctl(VKI_V4L2_TRY_EXT_CTRLS).reserved", data->reserved);
   8033       break;
   8034    }
   8035    case VKI_V4L2_ENUM_FRAMESIZES: {
   8036       struct vki_v4l2_frmsizeenum *data = (struct vki_v4l2_frmsizeenum *)ARG3;
   8037       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMESIZES).index", data->index);
   8038       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMESIZES).pixel_format", data->pixel_format);
   8039       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMESIZES).reserved", data->reserved);
   8040       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMESIZES).type", data->type);
   8041       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMESIZES).stepwise", data->stepwise);
   8042       break;
   8043    }
   8044    case VKI_V4L2_ENUM_FRAMEINTERVALS: {
   8045       struct vki_v4l2_frmivalenum *data = (struct vki_v4l2_frmivalenum *)ARG3;
   8046       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).index", data->index);
   8047       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).pixel_format", data->pixel_format);
   8048       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).width", data->width);
   8049       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).height", data->height);
   8050       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).reserved", data->reserved);
   8051       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).type", data->type);
   8052       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FRAMEINTERVALS).stepwise", data->stepwise);
   8053       break;
   8054    }
   8055    case VKI_V4L2_G_ENC_INDEX: {
   8056       struct vki_v4l2_enc_idx *data = (struct vki_v4l2_enc_idx *)ARG3;
   8057       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_ENC_INDEX)", (Addr)data, sizeof(*data));
   8058       break;
   8059    }
   8060    case VKI_V4L2_ENCODER_CMD: {
   8061       struct vki_v4l2_encoder_cmd *data = (struct vki_v4l2_encoder_cmd *)ARG3;
   8062       PRE_MEM_READ("ioctl(VKI_V4L2_ENCODER_CMD)", (Addr)data, sizeof(*data));
   8063       break;
   8064    }
   8065    case VKI_V4L2_TRY_ENCODER_CMD: {
   8066       struct vki_v4l2_encoder_cmd *data = (struct vki_v4l2_encoder_cmd *)ARG3;
   8067       PRE_MEM_READ("ioctl(VKI_V4L2_TRY_ENCODER_CMD)", (Addr)data, sizeof(*data));
   8068       break;
   8069    }
   8070    case VKI_V4L2_DBG_S_REGISTER: {
   8071       struct vki_v4l2_dbg_register *data = (struct vki_v4l2_dbg_register *)ARG3;
   8072       PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).match.type", data->match.type);
   8073       PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).match.addr", data->match.addr);
   8074       PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).reg", data->reg);
   8075       PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_S_REGISTER).val", data->val);
   8076       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_S_REGISTER).size", data->size);
   8077       break;
   8078    }
   8079    case VKI_V4L2_DBG_G_REGISTER: {
   8080       struct vki_v4l2_dbg_register *data = (struct vki_v4l2_dbg_register *)ARG3;
   8081       PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_REGISTER).match.type", data->match.type);
   8082       PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_REGISTER).match.addr", data->match.addr);
   8083       PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_REGISTER).reg", data->reg);
   8084       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_REGISTER).val", data->val);
   8085       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_REGISTER).size", data->size);
   8086       break;
   8087    }
   8088    case VKI_V4L2_S_HW_FREQ_SEEK: {
   8089       struct vki_v4l2_hw_freq_seek *data = (struct vki_v4l2_hw_freq_seek *)ARG3;
   8090       PRE_MEM_READ("ioctl(VKI_V4L2_S_HW_FREQ_SEEK)", (Addr)data, sizeof(*data));
   8091       break;
   8092    }
   8093    case VKI_V4L2_S_DV_TIMINGS: {
   8094       struct vki_v4l2_dv_timings *data = (struct vki_v4l2_dv_timings *)ARG3;
   8095       PRE_FIELD_READ("ioctl(VKI_V4L2_S_DV_TIMINGS).type", data->type);
   8096       PRE_FIELD_READ("ioctl(VKI_V4L2_S_DV_TIMINGS).bt", data->bt);
   8097       break;
   8098    }
   8099    case VKI_V4L2_G_DV_TIMINGS: {
   8100       struct vki_v4l2_dv_timings *data = (struct vki_v4l2_dv_timings *)ARG3;
   8101       PRE_MEM_WRITE("ioctl(VKI_V4L2_G_DV_TIMINGS)", (Addr)data, sizeof(*data));
   8102       break;
   8103    }
   8104    case VKI_V4L2_DQEVENT: {
   8105       struct vki_v4l2_event *data = (struct vki_v4l2_event *)ARG3;
   8106       PRE_MEM_WRITE("ioctl(VKI_V4L2_DQEVENT)", (Addr)data, sizeof(*data));
   8107       break;
   8108    }
   8109    case VKI_V4L2_SUBSCRIBE_EVENT: {
   8110       struct vki_v4l2_event_subscription *data = (struct vki_v4l2_event_subscription *)ARG3;
   8111       PRE_MEM_READ("ioctl(VKI_V4L2_SUBSCRIBE_EVENT)", (Addr)data, sizeof(*data));
   8112       break;
   8113    }
   8114    case VKI_V4L2_UNSUBSCRIBE_EVENT: {
   8115       struct vki_v4l2_event_subscription *data = (struct vki_v4l2_event_subscription *)ARG3;
   8116       PRE_MEM_READ("ioctl(VKI_V4L2_UNSUBSCRIBE_EVENT)", (Addr)data, sizeof(*data));
   8117       break;
   8118    }
   8119    case VKI_V4L2_CREATE_BUFS: {
   8120       struct vki_v4l2_create_buffers *data = (struct vki_v4l2_create_buffers *)ARG3;
   8121       struct vki_v4l2_format *fmt = &data->format;
   8122       PRE_FIELD_WRITE("ioctl(VKI_V4L2_CREATE_BUFS).index", data->index);
   8123       PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).count", data->count);
   8124       PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).memory", data->memory);
   8125       PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).reserved", data->reserved);
   8126       PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.type", fmt->type);
   8127       switch (fmt->type) {
   8128       case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE:
   8129       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT:
   8130          PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.pix", fmt->fmt.raw_data);
   8131          break;
   8132       case VKI_V4L2_BUF_TYPE_VBI_CAPTURE:
   8133       case VKI_V4L2_BUF_TYPE_VBI_OUTPUT:
   8134          PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.vbi", fmt->fmt.vbi);
   8135          break;
   8136       case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
   8137       case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
   8138          PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.sliced", fmt->fmt.sliced);
   8139          break;
   8140       case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY:
   8141       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
   8142          PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.win", fmt->fmt.win);
   8143          break;
   8144       case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
   8145       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
   8146          PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.pix_mp", fmt->fmt.pix_mp);
   8147          break;
   8148       case VKI_V4L2_BUF_TYPE_SDR_CAPTURE:
   8149          PRE_FIELD_READ("ioctl(VKI_V4L2_CREATE_BUFS).format.sdr", fmt->fmt.sdr);
   8150          break;
   8151       }
   8152       break;
   8153    }
   8154    case VKI_V4L2_PREPARE_BUF: {
   8155       struct vki_v4l2_buffer *data = (struct vki_v4l2_buffer *)ARG3;
   8156       PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).index", data->index);
   8157       PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).type", data->type);
   8158       PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).memory", data->memory);
   8159       PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).reserved", data->reserved);
   8160       PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).reserved2", data->reserved2);
   8161       if (data->type == VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
   8162             data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
   8163          unsigned i;
   8164 
   8165          PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).length", data->length);
   8166          PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).m.planes", data->m.planes);
   8167          for (i = 0; i < data->length; i++) {
   8168             PRE_FIELD_READ("ioctl(VKI_V4L2_PREPARE_BUF).m.planes[].reserved", data->m.planes[i].reserved);
   8169          }
   8170       }
   8171       break;
   8172    }
   8173    case VKI_V4L2_G_SELECTION: {
   8174       struct vki_v4l2_selection *data = (struct vki_v4l2_selection *)ARG3;
   8175       PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).type", data->type);
   8176       PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).target", data->target);
   8177       PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).flags", data->flags);
   8178       PRE_FIELD_READ("ioctl(VKI_V4L2_G_SELECTION).reserved", data->reserved);
   8179       PRE_FIELD_WRITE("ioctl(VKI_V4L2_G_SELECTION).r", data->r);
   8180       break;
   8181    }
   8182    case VKI_V4L2_S_SELECTION: {
   8183       struct vki_v4l2_selection *data = (struct vki_v4l2_selection *)ARG3;
   8184       PRE_MEM_READ("ioctl(VKI_V4L2_S_SELECTION)", (Addr)data, sizeof(*data));
   8185       break;
   8186    }
   8187    case VKI_V4L2_DECODER_CMD: {
   8188       struct vki_v4l2_decoder_cmd *data = (struct vki_v4l2_decoder_cmd *)ARG3;
   8189       PRE_MEM_READ("ioctl(VKI_V4L2_DECODER_CMD)", (Addr)data, sizeof(*data));
   8190       break;
   8191    }
   8192    case VKI_V4L2_TRY_DECODER_CMD: {
   8193       struct vki_v4l2_decoder_cmd *data = (struct vki_v4l2_decoder_cmd *)ARG3;
   8194       PRE_MEM_READ("ioctl(VKI_V4L2_TRY_DECODER_CMD)", (Addr)data, sizeof(*data));
   8195       break;
   8196    }
   8197    case VKI_V4L2_ENUM_DV_TIMINGS: {
   8198       struct vki_v4l2_enum_dv_timings *data = (struct vki_v4l2_enum_dv_timings *)ARG3;
   8199       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).index", data->index);
   8200       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).pad", data->pad);
   8201       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).reserved", data->reserved);
   8202       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_DV_TIMINGS).timings", data->timings);
   8203       break;
   8204    }
   8205    case VKI_V4L2_QUERY_DV_TIMINGS: {
   8206       struct vki_v4l2_dv_timings *data = (struct vki_v4l2_dv_timings *)ARG3;
   8207       PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERY_DV_TIMINGS)", (Addr)data, sizeof(*data));
   8208       break;
   8209    }
   8210    case VKI_V4L2_DV_TIMINGS_CAP: {
   8211       struct vki_v4l2_dv_timings_cap *data = (struct vki_v4l2_dv_timings_cap *)ARG3;
   8212       PRE_MEM_WRITE("ioctl(VKI_V4L2_DV_TIMINGS_CAP)", (Addr)data, sizeof(*data));
   8213       break;
   8214    }
   8215    case VKI_V4L2_ENUM_FREQ_BANDS: {
   8216       struct vki_v4l2_frequency_band *data = (struct vki_v4l2_frequency_band *)ARG3;
   8217       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).tuner", data->tuner);
   8218       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).type", data->type);
   8219       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).index", data->index);
   8220       PRE_FIELD_READ("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).reserved", data->reserved);
   8221       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).capability", data->capability);
   8222       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).rangelow", data->rangelow);
   8223       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).rangehigh", data->rangehigh);
   8224       PRE_FIELD_WRITE("ioctl(VKI_V4L2_ENUM_FREQ_BANDS).modulation", data->modulation);
   8225       break;
   8226    }
   8227    case VKI_V4L2_DBG_G_CHIP_INFO: {
   8228       struct vki_v4l2_dbg_chip_info *data = (struct vki_v4l2_dbg_chip_info *)ARG3;
   8229       PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).match.type", data->match.type);
   8230       PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).match.addr", data->match.addr);
   8231       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).name", data->name);
   8232       PRE_FIELD_WRITE("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).flags", data->flags);
   8233       PRE_FIELD_READ("ioctl(VKI_V4L2_DBG_G_CHIP_INFO).reserved", data->reserved);
   8234       break;
   8235    }
   8236    case VKI_V4L2_QUERY_EXT_CTRL: {
   8237       struct vki_v4l2_query_ext_ctrl *data = (struct vki_v4l2_query_ext_ctrl *)ARG3;
   8238       PRE_FIELD_READ("ioctl(VKI_V4L2_QUERY_EXT_CTRL).id", data->id);
   8239       PRE_FIELD_READ("ioctl(VKI_V4L2_QUERY_EXT_CTRL).reserved", data->reserved);
   8240       PRE_MEM_WRITE("ioctl(VKI_V4L2_QUERY_EXT_CTRL)", (Addr)&data->type,
   8241             sizeof(*data) - sizeof(data->id) - sizeof(data->reserved));
   8242       break;
   8243    }
   8244    case VKI_V4L2_SUBDEV_G_FMT: {
   8245       struct vki_v4l2_subdev_format *data = (struct vki_v4l2_subdev_format *)ARG3;
   8246       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FMT).pad", data->pad);
   8247       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FMT).which", data->which);
   8248       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FMT).reserved", data->reserved);
   8249       PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_FMT).format", data->format);
   8250       break;
   8251    }
   8252    case VKI_V4L2_SUBDEV_S_FMT: {
   8253       struct vki_v4l2_subdev_format *data = (struct vki_v4l2_subdev_format *)ARG3;
   8254       PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_FMT)", (Addr)data, sizeof(*data));
   8255       break;
   8256    }
   8257    case VKI_V4L2_SUBDEV_G_FRAME_INTERVAL: {
   8258       struct vki_v4l2_subdev_frame_interval *data = (struct vki_v4l2_subdev_frame_interval *)ARG3;
   8259       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FRAME_SIZE).pad", data->pad);
   8260       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_FRAME_SIZE).reserved", data->reserved);
   8261       PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_FRAME_SIZE).interval", data->interval);
   8262       break;
   8263    }
   8264    case VKI_V4L2_SUBDEV_S_FRAME_INTERVAL: {
   8265       struct vki_v4l2_subdev_frame_interval *data = (struct vki_v4l2_subdev_frame_interval *)ARG3;
   8266       PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_FRAME_INTERVAL)", (Addr)data, sizeof(*data));
   8267       break;
   8268    }
   8269    case VKI_V4L2_SUBDEV_ENUM_MBUS_CODE: {
   8270       struct vki_v4l2_subdev_mbus_code_enum *data = (struct vki_v4l2_subdev_mbus_code_enum *)ARG3;
   8271       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).index", data->index);
   8272       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).pad", data->pad);
   8273       PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).code", data->code);
   8274       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).which", data->which);
   8275       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_MBUS_CODE).reserved", data->reserved);
   8276       break;
   8277    }
   8278    case VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE: {
   8279       struct vki_v4l2_subdev_frame_size_enum *data = (struct vki_v4l2_subdev_frame_size_enum *)ARG3;
   8280       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).index", data->index);
   8281       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).pad", data->pad);
   8282       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).code", data->code);
   8283       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).which", data->which);
   8284       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).reserved", data->reserved);
   8285       PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).min_width", data->min_width);
   8286       PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).min_height", data->min_height);
   8287       PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).max_width", data->max_width);
   8288       PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE).max_height", data->max_height);
   8289       break;
   8290    }
   8291    case VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL: {
   8292       struct vki_v4l2_subdev_frame_interval_enum *data = (struct vki_v4l2_subdev_frame_interval_enum *)ARG3;
   8293       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).index", data->index);
   8294       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).pad", data->pad);
   8295       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).code", data->code);
   8296       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).width", data->width);
   8297       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).height", data->height);
   8298       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).which", data->which);
   8299       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).reserved", data->reserved);
   8300       PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL).interval", data->interval);
   8301       break;
   8302    }
   8303    case VKI_V4L2_SUBDEV_G_CROP: {
   8304       struct vki_v4l2_subdev_crop *data = (struct vki_v4l2_subdev_crop *)ARG3;
   8305       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_CROP).pad", data->pad);
   8306       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_CROP).which", data->which);
   8307       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_CROP).reserved", data->reserved);
   8308       PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_CROP).rect", data->rect);
   8309       break;
   8310    }
   8311    case VKI_V4L2_SUBDEV_S_CROP: {
   8312       struct vki_v4l2_subdev_crop *data = (struct vki_v4l2_subdev_crop *)ARG3;
   8313       PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_CROP)", (Addr)data, sizeof(*data));
   8314       break;
   8315    }
   8316    case VKI_V4L2_SUBDEV_G_SELECTION: {
   8317       struct vki_v4l2_subdev_selection *data = (struct vki_v4l2_subdev_selection *)ARG3;
   8318       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).pad", data->pad);
   8319       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).which", data->which);
   8320       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).target", data->target);
   8321       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).flags", data->flags);
   8322       PRE_FIELD_READ("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).reserved", data->reserved);
   8323       PRE_FIELD_WRITE("ioctl(VKI_V4L2_SUBDEV_G_SELECTION).r", data->r);
   8324       break;
   8325    }
   8326    case VKI_V4L2_SUBDEV_S_SELECTION: {
   8327       struct vki_v4l2_subdev_selection *data = (struct vki_v4l2_subdev_selection *)ARG3;
   8328       PRE_MEM_READ("ioctl(VKI_V4L2_SUBDEV_S_SELECTION)", (Addr)data, sizeof(*data));
   8329       break;
   8330    }
   8331    case VKI_MEDIA_IOC_DEVICE_INFO: {
   8332       struct vki_media_device_info *data = (struct vki_media_device_info *)ARG3;
   8333       PRE_FIELD_READ("ioctl(VKI_MEDIA_IOC_DEVICE_INFO).reserved", data->reserved);
   8334       PRE_MEM_WRITE("ioctl(VKI_MEDIA_IOC_DEVICE_INFO)",
   8335             (Addr)data, sizeof(*data) - sizeof(data->reserved));
   8336       break;
   8337    }
   8338    case VKI_MEDIA_IOC_ENUM_ENTITIES: {
   8339       struct vki_media_entity_desc *data = (struct vki_media_entity_desc *)ARG3;
   8340       PRE_FIELD_READ("ioctl(VKI_MEDIA_IOC_ENUM_ENTITIES).id", data->id);
   8341       PRE_MEM_WRITE("ioctl(VKI_MEDIA_IOC_ENUM_ENTITIES)",
   8342             (Addr)data->name, sizeof(*data) - sizeof(data->id));
   8343       break;
   8344    }
   8345    case VKI_MEDIA_IOC_ENUM_LINKS: {
   8346       struct vki_media_links_enum *data = (struct vki_media_links_enum *)ARG3;
   8347       PRE_MEM_READ("ioctl(VKI_MEDIA_IOC_ENUM_LINKS)", (Addr)data, sizeof(*data));
   8348       break;
   8349    }
   8350    case VKI_MEDIA_IOC_SETUP_LINK: {
   8351       struct vki_media_link_desc *data = (struct vki_media_link_desc *)ARG3;
   8352       PRE_MEM_READ("ioctl(VKI_MEDIA_IOC_SETUP_LINK)", (Addr)data, sizeof(*data));
   8353       break;
   8354    }
   8355 
   8356    /* Serial */
   8357    case VKI_TIOCGSERIAL: {
   8358       struct vki_serial_struct *data = (struct vki_serial_struct *)ARG3;
   8359       PRE_MEM_WRITE("ioctl(VKI_TIOCGSERIAL)", (Addr)data, sizeof(*data));
   8360       break;
   8361    }
   8362    case VKI_TIOCSSERIAL: {
   8363       struct vki_serial_struct *data = (struct vki_serial_struct *)ARG3;
   8364       PRE_MEM_READ("ioctl(VKI_TIOCSSERIAL)", (Addr)data, sizeof(*data));
   8365       break;
   8366    }
   8367 
   8368    default:
   8369       /* EVIOC* are variable length and return size written on success */
   8370       switch (ARG2 & ~(_VKI_IOC_SIZEMASK << _VKI_IOC_SIZESHIFT)) {
   8371       case VKI_EVIOCGNAME(0):
   8372       case VKI_EVIOCGPHYS(0):
   8373       case VKI_EVIOCGUNIQ(0):
   8374       case VKI_EVIOCGKEY(0):
   8375       case VKI_EVIOCGLED(0):
   8376       case VKI_EVIOCGSND(0):
   8377       case VKI_EVIOCGSW(0):
   8378       case VKI_EVIOCGBIT(VKI_EV_SYN,0):
   8379       case VKI_EVIOCGBIT(VKI_EV_KEY,0):
   8380       case VKI_EVIOCGBIT(VKI_EV_REL,0):
   8381       case VKI_EVIOCGBIT(VKI_EV_ABS,0):
   8382       case VKI_EVIOCGBIT(VKI_EV_MSC,0):
   8383       case VKI_EVIOCGBIT(VKI_EV_SW,0):
   8384       case VKI_EVIOCGBIT(VKI_EV_LED,0):
   8385       case VKI_EVIOCGBIT(VKI_EV_SND,0):
   8386       case VKI_EVIOCGBIT(VKI_EV_REP,0):
   8387       case VKI_EVIOCGBIT(VKI_EV_FF,0):
   8388       case VKI_EVIOCGBIT(VKI_EV_PWR,0):
   8389       case VKI_EVIOCGBIT(VKI_EV_FF_STATUS,0):
   8390          PRE_MEM_WRITE("ioctl(EVIO*)", ARG3, _VKI_IOC_SIZE(ARG2));
   8391          break;
   8392       default:
   8393          ML_(PRE_unknown_ioctl)(tid, ARG2, ARG3);
   8394          break;
   8395       }
   8396       break;
   8397    }
   8398 }
   8399 
   8400 POST(sys_ioctl)
   8401 {
   8402    vg_assert(SUCCESS);
   8403 
   8404    ARG2 = (UInt)ARG2;
   8405 
   8406    /* --- BEGIN special IOCTL handlers for specific Android hardware --- */
   8407 
   8408    /* BEGIN undocumented ioctls for PowerVR SGX 540 (the GPU on Nexus S) */
   8409    if (KernelVariantiS(KernelVariant_android_gpu_sgx5xx,
   8410                        VG_(clo_kernel_variant))) {
   8411 
   8412       if (ARG2 >= 0xC01C6700 && ARG2 <= 0xC01C67FF && ARG3 >= 0x1000) {
   8413          /* What's going on here: there appear to be a bunch of ioctls
   8414             of the form 0xC01C67xx which are undocumented, and if
   8415             unhandled give rise to a vast number of false positives in
   8416             Memcheck.
   8417 
   8418             The "normal" interpretation of an ioctl of this form would
   8419             be that the 3rd arg is a pointer to an area of size 0x1C
   8420             (28 bytes) which is filled in by the kernel.  Hence you
   8421             might think that "POST_MEM_WRITE(ARG3, 28)" would fix it.
   8422             But it doesn't.
   8423 
   8424             It requires POST_MEM_WRITE(ARG3, 256) to silence them.
   8425             One interpretation of this is that ARG3 really does point
   8426             to a 28 byte struct, but inside that are pointers to other
   8427             areas also filled in by the kernel.  If these happen to be
   8428             allocated just back up the stack then the 256 byte paint
   8429             might cover them too, somewhat indiscriminately.
   8430 
   8431             By printing out ARG3 and also the 28 bytes that it points
   8432             at, it's possible to guess that the 7 word structure has
   8433             this form
   8434 
   8435               0            1    2    3        4    5        6
   8436               ioctl-number 0x1C ptr1 ptr1size ptr2 ptr2size aBitMask
   8437 
   8438             Unfortunately that doesn't seem to work for some reason,
   8439             so stay with the blunt-instrument approach for the time
   8440             being.
   8441          */
   8442          if (1) {
   8443             /* blunt-instrument approach */
   8444             POST_MEM_WRITE(ARG3, 256);
   8445          } else {
   8446             /* be a bit more sophisticated */
   8447             POST_MEM_WRITE(ARG3, 28);
   8448             UInt* word = (UInt*)ARG3;
   8449             if (word && word[2] && word[3] < 0x200/*stay sane*/)
   8450                POST_MEM_WRITE(word[2], word[3]); // "ptr1"
   8451             if (word && word[4] && word[5] < 0x200/*stay sane*/)
   8452                POST_MEM_WRITE(word[4], word[5]); // "ptr2"
   8453          }
   8454          goto post_sys_ioctl__out;
   8455       }
   8456    }
   8457    /* END undocumented ioctls for PowerVR SGX 540 (the GPU on Nexus S) */
   8458 
   8459    /* BEGIN undocumented ioctls for Qualcomm Adreno 3xx */
   8460    if (KernelVariantiS(KernelVariant_android_gpu_adreno3xx,
   8461                        VG_(clo_kernel_variant))) {
   8462      if (ARG2 == 0xC00C0902) {
   8463          POST_MEM_WRITE(ARG3, 24); // 16 is not enough
   8464          goto post_sys_ioctl__out;
   8465      }
   8466    }
   8467    /* END undocumented ioctls for Qualcomm Adreno 3xx */
   8468 
   8469    /* --- END special IOCTL handlers for specific Android hardware --- */
   8470 
   8471    /* --- normal handling --- */
   8472    switch (ARG2 /* request */) {
   8473 
   8474    /* The Linux kernel "ion" memory allocator, used on Android.  Note:
   8475       this is pretty poor given that there's no pre-handling to check
   8476       that writable areas are addressable. */
   8477    case VKI_ION_IOC_ALLOC: {
   8478       struct vki_ion_allocation_data* data
   8479          = (struct vki_ion_allocation_data*)ARG3;
   8480       POST_FIELD_WRITE(data->handle);
   8481       break;
   8482    }
   8483    case VKI_ION_IOC_MAP: {
   8484       struct vki_ion_fd_data* data = (struct vki_ion_fd_data*)ARG3;
   8485       POST_FIELD_WRITE(data->fd);
   8486       break;
   8487    }
   8488    case VKI_ION_IOC_FREE: // is this necessary?
   8489       POST_MEM_WRITE(ARG3, sizeof(struct vki_ion_handle_data));
   8490       break;
   8491    case VKI_ION_IOC_SHARE:
   8492       break;
   8493    case VKI_ION_IOC_IMPORT: {
   8494       struct vki_ion_fd_data* data = (struct vki_ion_fd_data*)ARG3;
   8495       POST_FIELD_WRITE(data->handle);
   8496       break;
   8497    }
   8498    case VKI_ION_IOC_SYNC:
   8499       break;
   8500    case VKI_ION_IOC_CUSTOM: // is this necessary?
   8501       POST_MEM_WRITE(ARG3, sizeof(struct vki_ion_custom_data));
   8502       break;
   8503 
   8504    case VKI_SYNC_IOC_MERGE: {
   8505       struct vki_sync_merge_data* data = (struct vki_sync_merge_data*)ARG3;
   8506       POST_FIELD_WRITE(data->fence);
   8507       break;
   8508    }
   8509 
   8510    case VKI_TCSETS:
   8511    case VKI_TCSETSW:
   8512    case VKI_TCSETSF:
   8513    case VKI_IB_USER_MAD_ENABLE_PKEY:
   8514       break;
   8515    case VKI_TCGETS:
   8516       POST_MEM_WRITE( ARG3, sizeof(struct vki_termios) );
   8517       break;
   8518    case VKI_TCSETA:
   8519    case VKI_TCSETAW:
   8520    case VKI_TCSETAF:
   8521       break;
   8522    case VKI_TCGETA:
   8523       POST_MEM_WRITE( ARG3, sizeof(struct vki_termio) );
   8524       break;
   8525    case VKI_TCSBRK:
   8526    case VKI_TCXONC:
   8527    case VKI_TCSBRKP:
   8528    case VKI_TCFLSH:
   8529    case VKI_TIOCSIG:
   8530       break;
   8531    case VKI_TIOCGWINSZ:
   8532       POST_MEM_WRITE( ARG3, sizeof(struct vki_winsize) );
   8533       break;
   8534    case VKI_TIOCSWINSZ:
   8535    case VKI_TIOCMBIS:
   8536    case VKI_TIOCMBIC:
   8537    case VKI_TIOCMSET:
   8538       break;
   8539    case VKI_TIOCMGET:
   8540       POST_MEM_WRITE( ARG3, sizeof(unsigned int) );
   8541       break;
   8542    case VKI_TIOCLINUX:
   8543       POST_MEM_WRITE( ARG3, sizeof(char *) );
   8544       break;
   8545    case VKI_TIOCGPGRP:
   8546       /* Get process group ID for foreground processing group. */
   8547       POST_MEM_WRITE( ARG3, sizeof(vki_pid_t) );
   8548       break;
   8549    case VKI_TIOCSPGRP:
   8550       /* Set a process group ID? */
   8551       POST_MEM_WRITE( ARG3, sizeof(vki_pid_t) );
   8552       break;
   8553    case VKI_TIOCGPTN: /* Get Pty Number (of pty-mux device) */
   8554       POST_MEM_WRITE( ARG3, sizeof(int));
   8555       break;
   8556    case VKI_TIOCSCTTY:
   8557       break;
   8558    case VKI_TIOCSPTLCK: /* Lock/unlock Pty */
   8559       break;
   8560    case VKI_FIONBIO:
   8561       break;
   8562    case VKI_FIONCLEX:
   8563       break;
   8564    case VKI_FIOCLEX:
   8565       break;
   8566    case VKI_TIOCNOTTY:
   8567       break;
   8568    case VKI_FIOASYNC:
   8569       break;
   8570    case VKI_FIONREAD:                /* identical to SIOCINQ */
   8571       POST_MEM_WRITE( ARG3, sizeof(int) );
   8572       break;
   8573    case VKI_FIOQSIZE:
   8574       POST_MEM_WRITE( ARG3, sizeof(vki_loff_t) );
   8575       break;
   8576 
   8577    case VKI_TIOCSERGETLSR:
   8578       POST_MEM_WRITE( ARG3, sizeof(int) );
   8579       break;
   8580    case VKI_TIOCGICOUNT:
   8581       POST_MEM_WRITE( ARG3, sizeof(struct vki_serial_icounter_struct) );
   8582       break;
   8583 
   8584    case VKI_SG_SET_COMMAND_Q:
   8585       break;
   8586    case VKI_SG_IO:
   8587       {
   8588          vki_sg_io_hdr_t *sgio = (vki_sg_io_hdr_t*)ARG3;
   8589          if ( sgio->sbp ) {
   8590             POST_MEM_WRITE( (Addr)sgio->sbp, sgio->sb_len_wr );
   8591          }
   8592          if ( sgio->dxfer_direction == VKI_SG_DXFER_FROM_DEV ||
   8593               sgio->dxfer_direction == VKI_SG_DXFER_TO_FROM_DEV ) {
   8594             int transferred = sgio->dxfer_len - sgio->resid;
   8595             POST_MEM_WRITE( (Addr)sgio->dxferp, transferred );
   8596          }
   8597       }
   8598       break;
   8599    case VKI_SG_GET_SCSI_ID:
   8600       POST_MEM_WRITE(ARG3, sizeof(vki_sg_scsi_id_t));
   8601       break;
   8602    case VKI_SG_SET_RESERVED_SIZE:
   8603       break;
   8604    case VKI_SG_SET_TIMEOUT:
   8605       break;
   8606    case VKI_SG_GET_RESERVED_SIZE:
   8607       POST_MEM_WRITE(ARG3, sizeof(int));
   8608       break;
   8609    case VKI_SG_GET_TIMEOUT:
   8610       break;
   8611    case VKI_SG_GET_VERSION_NUM:
   8612       POST_MEM_WRITE(ARG3, sizeof(int));
   8613       break;
   8614    case VKI_SG_EMULATED_HOST:
   8615       POST_MEM_WRITE(ARG3, sizeof(int));
   8616       break;
   8617    case VKI_SG_GET_SG_TABLESIZE:
   8618       POST_MEM_WRITE(ARG3, sizeof(int));
   8619       break;
   8620 
   8621    case VKI_IIOCGETCPS:
   8622       POST_MEM_WRITE( ARG3, VKI_ISDN_MAX_CHANNELS * 2 * sizeof(unsigned long) );
   8623       break;
   8624    case VKI_IIOCNETGPN:
   8625       POST_MEM_WRITE( ARG3, sizeof(vki_isdn_net_ioctl_phone) );
   8626       break;
   8627 
   8628       /* These all use struct ifreq AFAIK */
   8629    case VKI_SIOCGIFINDEX:        /* get iface index              */
   8630       POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_ifindex,
   8631                       sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_ifindex) );
   8632       break;
   8633    case VKI_SIOCGIFFLAGS:        /* get flags                    */
   8634       POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags,
   8635                       sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) );
   8636       break;
   8637    case VKI_SIOCGIFHWADDR:       /* Get hardware address         */
   8638       POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_hwaddr,
   8639                       sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_hwaddr) );
   8640       break;
   8641    case VKI_SIOCGIFMTU:          /* get MTU size                 */
   8642       POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_mtu,
   8643                       sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_mtu) );
   8644       break;
   8645    case VKI_SIOCGIFADDR:         /* get PA address               */
   8646    case VKI_SIOCGIFDSTADDR:      /* get remote PA address        */
   8647    case VKI_SIOCGIFBRDADDR:      /* get broadcast PA address     */
   8648    case VKI_SIOCGIFNETMASK:      /* get network PA mask          */
   8649       POST_MEM_WRITE(
   8650                 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_addr,
   8651                 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_addr) );
   8652       break;
   8653    case VKI_SIOCGIFMETRIC:       /* get metric                   */
   8654       POST_MEM_WRITE(
   8655                 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_metric,
   8656                 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_metric) );
   8657       break;
   8658    case VKI_SIOCGIFMAP:          /* Get device parameters        */
   8659       POST_MEM_WRITE(
   8660                 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_map,
   8661                 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_map) );
   8662       break;
   8663      break;
   8664    case VKI_SIOCGIFTXQLEN:       /* Get the tx queue length      */
   8665       POST_MEM_WRITE(
   8666                 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_qlen,
   8667                 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_qlen) );
   8668       break;
   8669    case VKI_SIOCGIFNAME:         /* get iface name               */
   8670       POST_MEM_WRITE(
   8671                 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_name,
   8672                 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_name) );
   8673       break;
   8674    case VKI_SIOCETHTOOL: {       /* ethtool(8) interface         */
   8675       struct vki_ifreq *ir = (struct vki_ifreq *)ARG3;
   8676       switch ( *(vki_u32 *)ir->vki_ifr_data ) {
   8677       case VKI_ETHTOOL_GSET:
   8678          POST_MEM_WRITE( (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_cmd));
   8679          break;
   8680       case VKI_ETHTOOL_SSET:
   8681          break;
   8682       case VKI_ETHTOOL_GDRVINFO:
   8683          POST_MEM_WRITE( (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_drvinfo) );
   8684          break;
   8685       case VKI_ETHTOOL_GREGS:
   8686          POST_MEM_WRITE( (Addr)((struct vki_ethtool_regs *)ir->vki_ifr_data)->data,
   8687                          ((struct vki_ethtool_regs *)ir->vki_ifr_data)->len );
   8688          break;
   8689       case VKI_ETHTOOL_GWOL:
   8690          POST_MEM_WRITE( (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_wolinfo) );
   8691          break;
   8692       case VKI_ETHTOOL_SWOL:
   8693          break;
   8694       case VKI_ETHTOOL_GMSGLVL:
   8695       case VKI_ETHTOOL_GLINK:
   8696       case VKI_ETHTOOL_GRXCSUM:
   8697       case VKI_ETHTOOL_GSG:
   8698       case VKI_ETHTOOL_GTSO:
   8699       case VKI_ETHTOOL_GUFO:
   8700       case VKI_ETHTOOL_GGSO:
   8701       case VKI_ETHTOOL_GFLAGS:
   8702       case VKI_ETHTOOL_GGRO:
   8703          POST_MEM_WRITE( (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_value));
   8704          break;
   8705       case VKI_ETHTOOL_SMSGLVL:
   8706       case VKI_ETHTOOL_SRXCSUM:
   8707       case VKI_ETHTOOL_SSG:
   8708       case VKI_ETHTOOL_STSO:
   8709       case VKI_ETHTOOL_SUFO:
   8710       case VKI_ETHTOOL_SGSO:
   8711       case VKI_ETHTOOL_SFLAGS:
   8712       case VKI_ETHTOOL_SGRO:
   8713          break;
   8714       case VKI_ETHTOOL_NWAY_RST:
   8715          break;
   8716       case VKI_ETHTOOL_GRINGPARAM:
   8717          POST_MEM_WRITE( (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_ringparam));
   8718          break;
   8719       case VKI_ETHTOOL_SRINGPARAM:
   8720          break;
   8721       case VKI_ETHTOOL_TEST:
   8722          POST_MEM_WRITE( (Addr)((struct vki_ethtool_test *)ir->vki_ifr_data)->data,
   8723                          ((struct vki_ethtool_test *)ir->vki_ifr_data)->len * sizeof(__vki_u64) );
   8724          break;
   8725       case VKI_ETHTOOL_PHYS_ID:
   8726          break;
   8727       case VKI_ETHTOOL_GPERMADDR:
   8728          POST_MEM_WRITE( (Addr)((struct vki_ethtool_perm_addr *)ir->vki_ifr_data)->data,
   8729                          ((struct vki_ethtool_perm_addr *)ir->vki_ifr_data)->size );
   8730          break;
   8731       case VKI_ETHTOOL_RESET:
   8732          break;
   8733       case VKI_ETHTOOL_GSSET_INFO:
   8734          POST_MEM_WRITE( (Addr)((struct vki_ethtool_sset_info *)ir->vki_ifr_data)->data,
   8735                         __builtin_popcountll(((struct vki_ethtool_sset_info *)ir->vki_ifr_data)->sset_mask) * sizeof(__vki_u32) );
   8736          break;
   8737       case VKI_ETHTOOL_GFEATURES:
   8738          POST_MEM_WRITE( (Addr)((struct vki_ethtool_gfeatures *)ir->vki_ifr_data)->features,
   8739                          ((struct vki_ethtool_gfeatures *)ir->vki_ifr_data)->size * sizeof(struct vki_ethtool_get_features_block) );
   8740          break;
   8741       case VKI_ETHTOOL_SFEATURES:
   8742          break;
   8743       case VKI_ETHTOOL_GCHANNELS:
   8744          POST_MEM_WRITE( (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_channels) );
   8745          break;
   8746       case VKI_ETHTOOL_SCHANNELS:
   8747          break;
   8748       case VKI_ETHTOOL_GET_TS_INFO:
   8749          POST_MEM_WRITE( (Addr)ir->vki_ifr_data, sizeof(struct vki_ethtool_ts_info) );
   8750          break;
   8751       }
   8752       break;
   8753    }
   8754    case VKI_SIOCGMIIPHY:         /* get hardware entry           */
   8755       POST_MEM_WRITE(
   8756                 (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id,
   8757                 sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) );
   8758       break;
   8759    case VKI_SIOCGMIIREG:         /* get hardware entry registers */
   8760       POST_MEM_WRITE(
   8761                 (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_out,
   8762                 sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_out) );
   8763       break;
   8764 
   8765       /* tun/tap related ioctls */
   8766    case VKI_TUNSETIFF:
   8767       POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_name,
   8768                       sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_name) );
   8769       break;
   8770    case VKI_TUNGETFEATURES:
   8771       POST_MEM_WRITE( ARG3, sizeof(unsigned int) );
   8772       break;
   8773    case VKI_TUNGETIFF:
   8774       POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_name,
   8775                       sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_name) );
   8776       POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags,
   8777                       sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) );
   8778       break;
   8779    case VKI_TUNGETSNDBUF:
   8780       POST_MEM_WRITE( ARG3, sizeof(int) );
   8781       break;
   8782    case VKI_TUNGETVNETHDRSZ:
   8783       POST_MEM_WRITE( ARG3, sizeof(int) );
   8784       break;
   8785 
   8786    case VKI_SIOCGIFCONF:         /* get iface list               */
   8787       /* WAS:
   8788 	 PRE_MEM_WRITE("ioctl(SIOCGIFCONF)", ARG3, sizeof(struct ifconf));
   8789 	 KERNEL_DO_SYSCALL(tid,RES);
   8790 	 if (!VG_(is_kerror)(RES) && RES == 0)
   8791 	 POST_MEM_WRITE(ARG3, sizeof(struct ifconf));
   8792       */
   8793       if (RES == 0 && ARG3 ) {
   8794 	 struct vki_ifconf *ifc = (struct vki_ifconf *) ARG3;
   8795 	 if (ifc->vki_ifc_buf != NULL)
   8796 	    POST_MEM_WRITE( (Addr)(ifc->vki_ifc_buf), ifc->ifc_len );
   8797       }
   8798       break;
   8799    case VKI_SIOCGSTAMP:
   8800       POST_MEM_WRITE( ARG3, sizeof(struct vki_timeval) );
   8801       break;
   8802    case VKI_SIOCGSTAMPNS:
   8803       POST_MEM_WRITE( ARG3, sizeof(struct vki_timespec) );
   8804       break;
   8805       /* SIOCOUTQ is an ioctl that, when called on a socket, returns
   8806 	 the number of bytes currently in that socket's send buffer.
   8807 	 It writes this value as an int to the memory location
   8808 	 indicated by the third argument of ioctl(2). */
   8809    case VKI_SIOCOUTQ:
   8810       POST_MEM_WRITE(ARG3, sizeof(int));
   8811       break;
   8812    case VKI_SIOCGRARP:           /* get RARP table entry         */
   8813    case VKI_SIOCGARP:            /* get ARP table entry          */
   8814       POST_MEM_WRITE(ARG3, sizeof(struct vki_arpreq));
   8815       break;
   8816 
   8817    case VKI_SIOCSIFFLAGS:        /* set flags                    */
   8818    case VKI_SIOCSIFMAP:          /* Set device parameters        */
   8819    case VKI_SIOCSHWTSTAMP:       /* Set hardware time stamping   */
   8820    case VKI_SIOCSIFTXQLEN:       /* Set the tx queue length      */
   8821    case VKI_SIOCSIFDSTADDR:      /* set remote PA address        */
   8822    case VKI_SIOCSIFBRDADDR:      /* set broadcast PA address     */
   8823    case VKI_SIOCSIFNETMASK:      /* set network PA mask          */
   8824    case VKI_SIOCSIFMETRIC:       /* set metric                   */
   8825    case VKI_SIOCSIFADDR:         /* set PA address               */
   8826    case VKI_SIOCSIFMTU:          /* set MTU size                 */
   8827    case VKI_SIOCSIFHWADDR:       /* set hardware address         */
   8828    case VKI_SIOCSMIIREG:         /* set hardware entry registers */
   8829       break;
   8830       /* Routing table calls.  */
   8831    case VKI_SIOCADDRT:           /* add routing table entry      */
   8832    case VKI_SIOCDELRT:           /* delete routing table entry   */
   8833       break;
   8834 
   8835       /* RARP cache control calls. */
   8836    case VKI_SIOCDRARP:           /* delete RARP table entry      */
   8837    case VKI_SIOCSRARP:           /* set RARP table entry         */
   8838       /* ARP cache control calls. */
   8839    case VKI_SIOCSARP:            /* set ARP table entry          */
   8840    case VKI_SIOCDARP:            /* delete ARP table entry       */
   8841       break;
   8842 
   8843    case VKI_SIOCGPGRP:
   8844       POST_MEM_WRITE(ARG3, sizeof(int));
   8845       break;
   8846    case VKI_SIOCSPGRP:
   8847       break;
   8848 
   8849    case VKI_SIOCATMARK:
   8850       POST_MEM_WRITE(ARG3, sizeof(int));
   8851       break;
   8852 
   8853       /* linux/soundcard interface (OSS) */
   8854    case VKI_SNDCTL_SEQ_GETOUTCOUNT:
   8855    case VKI_SNDCTL_SEQ_GETINCOUNT:
   8856    case VKI_SNDCTL_SEQ_PERCMODE:
   8857    case VKI_SNDCTL_SEQ_TESTMIDI:
   8858    case VKI_SNDCTL_SEQ_RESETSAMPLES:
   8859    case VKI_SNDCTL_SEQ_NRSYNTHS:
   8860    case VKI_SNDCTL_SEQ_NRMIDIS:
   8861    case VKI_SNDCTL_SEQ_GETTIME:
   8862    case VKI_SNDCTL_DSP_GETBLKSIZE:
   8863    case VKI_SNDCTL_DSP_GETFMTS:
   8864    case VKI_SNDCTL_DSP_SETFMT:
   8865    case VKI_SNDCTL_DSP_GETTRIGGER:
   8866    case VKI_SNDCTL_DSP_GETODELAY:
   8867    case VKI_SNDCTL_DSP_GETSPDIF:
   8868    case VKI_SNDCTL_DSP_GETCAPS:
   8869    case VKI_SOUND_PCM_READ_RATE:
   8870    case VKI_SOUND_PCM_READ_CHANNELS:
   8871    case VKI_SOUND_PCM_READ_BITS:
   8872    case VKI_SOUND_PCM_READ_FILTER:
   8873       POST_MEM_WRITE(ARG3, sizeof(int));
   8874       break;
   8875    case VKI_SNDCTL_SEQ_CTRLRATE:
   8876    case VKI_SNDCTL_DSP_SPEED:
   8877    case VKI_SNDCTL_DSP_STEREO:
   8878    case VKI_SNDCTL_DSP_CHANNELS:
   8879    case VKI_SOUND_PCM_WRITE_FILTER:
   8880    case VKI_SNDCTL_DSP_SUBDIVIDE:
   8881    case VKI_SNDCTL_DSP_SETFRAGMENT:
   8882    case VKI_SNDCTL_DSP_GETCHANNELMASK:
   8883    case VKI_SNDCTL_DSP_BIND_CHANNEL:
   8884    case VKI_SNDCTL_TMR_TIMEBASE:
   8885    case VKI_SNDCTL_TMR_TEMPO:
   8886    case VKI_SNDCTL_TMR_SOURCE:
   8887    case VKI_SNDCTL_MIDI_PRETIME:
   8888    case VKI_SNDCTL_MIDI_MPUMODE:
   8889       break;
   8890    case VKI_SNDCTL_DSP_GETOSPACE:
   8891    case VKI_SNDCTL_DSP_GETISPACE:
   8892       POST_MEM_WRITE(ARG3, sizeof(vki_audio_buf_info));
   8893       break;
   8894    case VKI_SNDCTL_DSP_NONBLOCK:
   8895       break;
   8896    case VKI_SNDCTL_DSP_SETTRIGGER:
   8897       break;
   8898 
   8899    case VKI_SNDCTL_DSP_POST:
   8900    case VKI_SNDCTL_DSP_RESET:
   8901    case VKI_SNDCTL_DSP_SYNC:
   8902    case VKI_SNDCTL_DSP_SETSYNCRO:
   8903    case VKI_SNDCTL_DSP_SETDUPLEX:
   8904       break;
   8905 
   8906       /* linux/soundcard interface (ALSA) */
   8907    case VKI_SNDRV_PCM_IOCTL_HW_FREE:
   8908    case VKI_SNDRV_PCM_IOCTL_HWSYNC:
   8909    case VKI_SNDRV_PCM_IOCTL_PREPARE:
   8910    case VKI_SNDRV_PCM_IOCTL_RESET:
   8911    case VKI_SNDRV_PCM_IOCTL_START:
   8912    case VKI_SNDRV_PCM_IOCTL_DROP:
   8913    case VKI_SNDRV_PCM_IOCTL_DRAIN:
   8914    case VKI_SNDRV_PCM_IOCTL_RESUME:
   8915    case VKI_SNDRV_PCM_IOCTL_XRUN:
   8916    case VKI_SNDRV_PCM_IOCTL_UNLINK:
   8917    case VKI_SNDRV_TIMER_IOCTL_START:
   8918    case VKI_SNDRV_TIMER_IOCTL_STOP:
   8919    case VKI_SNDRV_TIMER_IOCTL_CONTINUE:
   8920    case VKI_SNDRV_TIMER_IOCTL_PAUSE:
   8921    case VKI_SNDRV_CTL_IOCTL_PVERSION: {
   8922       POST_MEM_WRITE( (Addr)ARG3, sizeof(int) );
   8923       break;
   8924    }
   8925    case VKI_SNDRV_CTL_IOCTL_CARD_INFO:
   8926       POST_MEM_WRITE( (Addr)ARG3, sizeof(struct vki_snd_ctl_card_info) );
   8927       break;
   8928    case VKI_SNDRV_CTL_IOCTL_ELEM_LIST: {
   8929       struct vki_snd_ctl_elem_list *data = (struct vki_snd_ctl_elem_list *)ARG3;
   8930       POST_MEM_WRITE( (Addr)&data->used, sizeof(data->used) );
   8931       POST_MEM_WRITE( (Addr)&data->count, sizeof(data->count) );
   8932       if (data->pids) {
   8933          POST_MEM_WRITE( (Addr)data->pids, sizeof(struct vki_snd_ctl_elem_id) * data->used );
   8934       }
   8935       break;
   8936    }
   8937    case VKI_SNDRV_CTL_IOCTL_TLV_READ: {
   8938       struct vki_snd_ctl_tlv *data = (struct vki_snd_ctl_tlv *)ARG3;
   8939       POST_MEM_WRITE( (Addr)data->tlv, data->length );
   8940       break;
   8941    }
   8942    case VKI_SNDRV_CTL_IOCTL_TLV_WRITE:
   8943    case VKI_SNDRV_CTL_IOCTL_TLV_COMMAND:
   8944       break;
   8945 
   8946       /* SCSI no operand */
   8947    case VKI_SCSI_IOCTL_DOORLOCK:
   8948    case VKI_SCSI_IOCTL_DOORUNLOCK:
   8949       break;
   8950 
   8951       /* Real Time Clock (/dev/rtc) ioctls */
   8952    case VKI_RTC_UIE_ON:
   8953    case VKI_RTC_UIE_OFF:
   8954    case VKI_RTC_AIE_ON:
   8955    case VKI_RTC_AIE_OFF:
   8956    case VKI_RTC_PIE_ON:
   8957    case VKI_RTC_PIE_OFF:
   8958    case VKI_RTC_IRQP_SET:
   8959       break;
   8960    case VKI_RTC_RD_TIME:
   8961    case VKI_RTC_ALM_READ:
   8962       POST_MEM_WRITE(ARG3, sizeof(struct vki_rtc_time));
   8963       break;
   8964    case VKI_RTC_ALM_SET:
   8965       break;
   8966    case VKI_RTC_IRQP_READ:
   8967       POST_MEM_WRITE(ARG3, sizeof(unsigned long));
   8968       break;
   8969 
   8970       /* Block devices */
   8971    case VKI_BLKROSET:
   8972       break;
   8973    case VKI_BLKROGET:
   8974       POST_MEM_WRITE(ARG3, sizeof(int));
   8975       break;
   8976    case VKI_BLKGETSIZE:
   8977       POST_MEM_WRITE(ARG3, sizeof(unsigned long));
   8978       break;
   8979    case VKI_BLKRASET:
   8980       break;
   8981    case VKI_BLKRAGET:
   8982       POST_MEM_WRITE(ARG3, sizeof(long));
   8983       break;
   8984    case VKI_BLKFRASET:
   8985       break;
   8986    case VKI_BLKFRAGET:
   8987       POST_MEM_WRITE(ARG3, sizeof(long));
   8988       break;
   8989    case VKI_BLKSECTGET:
   8990       POST_MEM_WRITE(ARG3, sizeof(unsigned short));
   8991       break;
   8992    case VKI_BLKSSZGET:
   8993       POST_MEM_WRITE(ARG3, sizeof(int));
   8994       break;
   8995    case VKI_BLKBSZGET:
   8996       POST_MEM_WRITE(ARG3, sizeof(int));
   8997       break;
   8998    case VKI_BLKBSZSET:
   8999       break;
   9000    case VKI_BLKGETSIZE64:
   9001       POST_MEM_WRITE(ARG3, sizeof(unsigned long long));
   9002       break;
   9003    case VKI_BLKPBSZGET:
   9004       POST_MEM_WRITE(ARG3, sizeof(int));
   9005       break;
   9006    case VKI_BLKDISCARDZEROES:
   9007       POST_MEM_WRITE(ARG3, sizeof(vki_uint));
   9008       break;
   9009 
   9010       /* Hard disks */
   9011    case VKI_HDIO_GETGEO: /* 0x0301 */
   9012       POST_MEM_WRITE(ARG3, sizeof(struct vki_hd_geometry));
   9013       break;
   9014    case VKI_HDIO_GET_DMA: /* 0x030b */
   9015       POST_MEM_WRITE(ARG3, sizeof(long));
   9016       break;
   9017    case VKI_HDIO_GET_IDENTITY: /* 0x030d */
   9018       POST_MEM_WRITE(ARG3, VKI_SIZEOF_STRUCT_HD_DRIVEID );
   9019       break;
   9020 
   9021       /* SCSI */
   9022    case VKI_SCSI_IOCTL_GET_IDLUN: /* 0x5382 */
   9023       POST_MEM_WRITE(ARG3, sizeof(struct vki_scsi_idlun));
   9024       break;
   9025    case VKI_SCSI_IOCTL_GET_BUS_NUMBER: /* 0x5386 */
   9026       POST_MEM_WRITE(ARG3, sizeof(int));
   9027       break;
   9028 
   9029       /* CD ROM stuff (??)  */
   9030    case VKI_CDROM_DISC_STATUS:
   9031       break;
   9032    case VKI_CDROMSUBCHNL:
   9033       POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_subchnl));
   9034       break;
   9035    case VKI_CDROMREADTOCHDR:
   9036       POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_tochdr));
   9037       break;
   9038    case VKI_CDROMREADTOCENTRY:
   9039       POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_tocentry));
   9040       break;
   9041    case VKI_CDROMMULTISESSION:
   9042       POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_multisession));
   9043       break;
   9044    case VKI_CDROMVOLREAD:
   9045       POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_volctrl));
   9046       break;
   9047    case VKI_CDROMREADRAW:
   9048       POST_MEM_WRITE(ARG3, VKI_CD_FRAMESIZE_RAW);
   9049       break;
   9050    case VKI_CDROMREADAUDIO:
   9051    {
   9052       struct vki_cdrom_read_audio *cra = (struct vki_cdrom_read_audio *) ARG3;
   9053       POST_MEM_WRITE( (Addr)(cra->buf), cra->nframes * VKI_CD_FRAMESIZE_RAW);
   9054       break;
   9055    }
   9056 
   9057    case VKI_CDROMPLAYMSF:
   9058       break;
   9059       /* The following two are probably bogus (should check args
   9060 	 for readability).  JRS 20021117 */
   9061    case VKI_CDROM_DRIVE_STATUS: /* 0x5326 */
   9062    case VKI_CDROM_CLEAR_OPTIONS: /* 0x5321 */
   9063       break;
   9064    case VKI_CDROM_GET_CAPABILITY: /* 0x5331 */
   9065       break;
   9066 
   9067    case VKI_FIGETBSZ:
   9068       POST_MEM_WRITE(ARG3, sizeof(unsigned long));
   9069       break;
   9070    case VKI_FIBMAP:
   9071       POST_MEM_WRITE(ARG3, sizeof(int));
   9072       break;
   9073 
   9074    case VKI_FBIOGET_VSCREENINFO: //0x4600
   9075       POST_MEM_WRITE(ARG3, sizeof(struct vki_fb_var_screeninfo));
   9076       break;
   9077    case VKI_FBIOGET_FSCREENINFO: //0x4602
   9078       POST_MEM_WRITE(ARG3, sizeof(struct vki_fb_fix_screeninfo));
   9079       break;
   9080 
   9081    case VKI_PPCLAIM:
   9082    case VKI_PPEXCL:
   9083    case VKI_PPYIELD:
   9084    case VKI_PPRELEASE:
   9085    case VKI_PPSETMODE:
   9086    case VKI_PPSETPHASE:
   9087    case VKI_PPSETFLAGS:
   9088    case VKI_PPWDATA:
   9089    case VKI_PPWCONTROL:
   9090    case VKI_PPFCONTROL:
   9091    case VKI_PPDATADIR:
   9092    case VKI_PPNEGOT:
   9093    case VKI_PPWCTLONIRQ:
   9094    case VKI_PPSETTIME:
   9095       break;
   9096    case VKI_PPGETMODE:
   9097       POST_MEM_WRITE( ARG3, sizeof(int) );
   9098       break;
   9099    case VKI_PPGETPHASE:
   9100       POST_MEM_WRITE( ARG3, sizeof(int) );
   9101       break;
   9102    case VKI_PPGETMODES:
   9103       POST_MEM_WRITE( ARG3, sizeof(unsigned int) );
   9104       break;
   9105    case VKI_PPGETFLAGS:
   9106       POST_MEM_WRITE( ARG3, sizeof(int) );
   9107       break;
   9108    case VKI_PPRSTATUS:
   9109       POST_MEM_WRITE( ARG3, sizeof(unsigned char) );
   9110       break;
   9111    case VKI_PPRDATA:
   9112       POST_MEM_WRITE( ARG3, sizeof(unsigned char) );
   9113       break;
   9114    case VKI_PPRCONTROL:
   9115       POST_MEM_WRITE( ARG3, sizeof(unsigned char) );
   9116       break;
   9117    case VKI_PPCLRIRQ:
   9118       POST_MEM_WRITE( ARG3, sizeof(int) );
   9119       break;
   9120    case VKI_PPGETTIME:
   9121       POST_MEM_WRITE( ARG3, sizeof(struct vki_timeval) );
   9122       break;
   9123 
   9124    case VKI_GIO_FONT:
   9125       POST_MEM_WRITE( ARG3, 32 * 256 );
   9126       break;
   9127    case VKI_PIO_FONT:
   9128       break;
   9129 
   9130    case VKI_GIO_FONTX:
   9131       POST_MEM_WRITE( (Addr)((struct vki_consolefontdesc *)ARG3)->chardata,
   9132                       32 * ((struct vki_consolefontdesc *)ARG3)->charcount );
   9133       break;
   9134    case VKI_PIO_FONTX:
   9135       break;
   9136 
   9137    case VKI_PIO_FONTRESET:
   9138       break;
   9139 
   9140    case VKI_GIO_CMAP:
   9141       POST_MEM_WRITE( ARG3, 16 * 3 );
   9142       break;
   9143    case VKI_PIO_CMAP:
   9144       break;
   9145 
   9146    case VKI_KIOCSOUND:
   9147    case VKI_KDMKTONE:
   9148       break;
   9149 
   9150    case VKI_KDGETLED:
   9151       POST_MEM_WRITE( ARG3, sizeof(char) );
   9152       break;
   9153    case VKI_KDSETLED:
   9154       break;
   9155 
   9156    case VKI_KDGKBTYPE:
   9157       POST_MEM_WRITE( ARG3, sizeof(char) );
   9158       break;
   9159 
   9160    case VKI_KDADDIO:
   9161    case VKI_KDDELIO:
   9162    case VKI_KDENABIO:
   9163    case VKI_KDDISABIO:
   9164       break;
   9165 
   9166    case VKI_KDSETMODE:
   9167       break;
   9168    case VKI_KDGETMODE:
   9169       POST_MEM_WRITE( ARG3, sizeof(int) );
   9170       break;
   9171 
   9172    case VKI_KDMAPDISP:
   9173    case VKI_KDUNMAPDISP:
   9174       break;
   9175 
   9176    case VKI_GIO_SCRNMAP:
   9177       POST_MEM_WRITE( ARG3, VKI_E_TABSZ );
   9178       break;
   9179    case VKI_PIO_SCRNMAP:
   9180       break;
   9181    case VKI_GIO_UNISCRNMAP:
   9182       POST_MEM_WRITE( ARG3, VKI_E_TABSZ * sizeof(unsigned short) );
   9183       break;
   9184    case VKI_PIO_UNISCRNMAP:
   9185       break;
   9186 
   9187    case VKI_GIO_UNIMAP:
   9188       if ( ARG3 ) {
   9189          struct vki_unimapdesc *desc = (struct vki_unimapdesc *) ARG3;
   9190          POST_MEM_WRITE( (Addr)&desc->entry_ct, sizeof(desc->entry_ct));
   9191          POST_MEM_WRITE( (Addr)desc->entries,
   9192       	                 desc->entry_ct * sizeof(struct vki_unipair) );
   9193       }
   9194       break;
   9195    case VKI_PIO_UNIMAP:
   9196       break;
   9197    case VKI_PIO_UNIMAPCLR:
   9198       break;
   9199 
   9200    case VKI_KDGKBMODE:
   9201       POST_MEM_WRITE( ARG3, sizeof(int) );
   9202       break;
   9203    case VKI_KDSKBMODE:
   9204       break;
   9205 
   9206    case VKI_KDGKBMETA:
   9207       POST_MEM_WRITE( ARG3, sizeof(int) );
   9208       break;
   9209    case VKI_KDSKBMETA:
   9210       break;
   9211 
   9212    case VKI_KDGKBLED:
   9213       POST_MEM_WRITE( ARG3, sizeof(char) );
   9214       break;
   9215    case VKI_KDSKBLED:
   9216       break;
   9217 
   9218    case VKI_KDGKBENT:
   9219       POST_MEM_WRITE( (Addr)&((struct vki_kbentry *)ARG3)->kb_value,
   9220                       sizeof(((struct vki_kbentry *)ARG3)->kb_value) );
   9221       break;
   9222    case VKI_KDSKBENT:
   9223       break;
   9224 
   9225    case VKI_KDGKBSENT:
   9226       POST_MEM_WRITE( (Addr)((struct vki_kbsentry *)ARG3)->kb_string,
   9227                       sizeof(((struct vki_kbsentry *)ARG3)->kb_string) );
   9228       break;
   9229    case VKI_KDSKBSENT:
   9230       break;
   9231 
   9232    case VKI_KDGKBDIACR:
   9233       POST_MEM_WRITE( ARG3, sizeof(struct vki_kbdiacrs) );
   9234       break;
   9235    case VKI_KDSKBDIACR:
   9236       break;
   9237 
   9238    case VKI_KDGETKEYCODE:
   9239       POST_MEM_WRITE( (Addr)((struct vki_kbkeycode *)ARG3)->keycode,
   9240                       sizeof(((struct vki_kbkeycode *)ARG3)->keycode) );
   9241       break;
   9242    case VKI_KDSETKEYCODE:
   9243       break;
   9244 
   9245    case VKI_KDSIGACCEPT:
   9246       break;
   9247 
   9248    case VKI_KDKBDREP:
   9249       break;
   9250 
   9251    case VKI_KDFONTOP:
   9252       if ( ARG3 ) {
   9253          struct vki_console_font_op *op = (struct vki_console_font_op *) ARG3;
   9254          switch ( op->op ) {
   9255             case VKI_KD_FONT_OP_SET:
   9256                break;
   9257             case VKI_KD_FONT_OP_GET:
   9258                if ( op->data )
   9259                   POST_MEM_WRITE( (Addr) op->data,
   9260                                   (op->width + 7) / 8 * 32 * op->charcount );
   9261                break;
   9262             case VKI_KD_FONT_OP_SET_DEFAULT:
   9263                break;
   9264             case VKI_KD_FONT_OP_COPY:
   9265                break;
   9266          }
   9267          POST_MEM_WRITE( (Addr) op, sizeof(*op));
   9268       }
   9269       break;
   9270 
   9271    case VKI_VT_OPENQRY:
   9272       POST_MEM_WRITE( ARG3, sizeof(int) );
   9273       break;
   9274    case VKI_VT_GETMODE:
   9275       POST_MEM_WRITE( ARG3, sizeof(struct vki_vt_mode) );
   9276       break;
   9277    case VKI_VT_SETMODE:
   9278       break;
   9279    case VKI_VT_GETSTATE:
   9280       POST_MEM_WRITE( (Addr) &(((struct vki_vt_stat*) ARG3)->v_active),
   9281                       sizeof(((struct vki_vt_stat*) ARG3)->v_active) );
   9282       POST_MEM_WRITE( (Addr) &(((struct vki_vt_stat*) ARG3)->v_state),
   9283                       sizeof(((struct vki_vt_stat*) ARG3)->v_state) );
   9284       break;
   9285    case VKI_VT_RELDISP:
   9286    case VKI_VT_ACTIVATE:
   9287    case VKI_VT_WAITACTIVE:
   9288    case VKI_VT_DISALLOCATE:
   9289       break;
   9290    case VKI_VT_RESIZE:
   9291       break;
   9292    case VKI_VT_RESIZEX:
   9293       break;
   9294    case VKI_VT_LOCKSWITCH:
   9295    case VKI_VT_UNLOCKSWITCH:
   9296       break;
   9297 
   9298    case VKI_USBDEVFS_CONTROL:
   9299       if ( ARG3 ) {
   9300          struct vki_usbdevfs_ctrltransfer *vkuc = (struct vki_usbdevfs_ctrltransfer *)ARG3;
   9301          if (vkuc->bRequestType & 0x80)
   9302             POST_MEM_WRITE((Addr)vkuc->data, RES);
   9303       }
   9304       break;
   9305    case VKI_USBDEVFS_BULK:
   9306       if ( ARG3 ) {
   9307          struct vki_usbdevfs_bulktransfer *vkub = (struct vki_usbdevfs_bulktransfer *)ARG3;
   9308          if (vkub->ep & 0x80)
   9309             POST_MEM_WRITE((Addr)vkub->data, RES);
   9310       }
   9311       break;
   9312    case VKI_USBDEVFS_GETDRIVER:
   9313       if ( ARG3 ) {
   9314          struct vki_usbdevfs_getdriver *vkugd = (struct vki_usbdevfs_getdriver *)ARG3;
   9315          POST_MEM_WRITE((Addr)&vkugd->driver, sizeof(vkugd->driver));
   9316       }
   9317       break;
   9318    case VKI_USBDEVFS_REAPURB:
   9319    case VKI_USBDEVFS_REAPURBNDELAY:
   9320       if ( ARG3 ) {
   9321          struct vki_usbdevfs_urb **vkuu = (struct vki_usbdevfs_urb**)ARG3;
   9322          POST_MEM_WRITE((Addr)vkuu, sizeof(*vkuu));
   9323          if (!*vkuu)
   9324             break;
   9325          POST_MEM_WRITE((Addr) &((*vkuu)->status),sizeof((*vkuu)->status));
   9326          if ((*vkuu)->type == VKI_USBDEVFS_URB_TYPE_CONTROL) {
   9327             struct vki_usbdevfs_setuppacket *vkusp = (struct vki_usbdevfs_setuppacket *)(*vkuu)->buffer;
   9328             if (vkusp->bRequestType & 0x80)
   9329                POST_MEM_WRITE((Addr)(vkusp+1), (*vkuu)->buffer_length - sizeof(*vkusp));
   9330             POST_MEM_WRITE((Addr)&(*vkuu)->actual_length, sizeof((*vkuu)->actual_length));
   9331          } else if ((*vkuu)->type == VKI_USBDEVFS_URB_TYPE_ISO) {
   9332             char *bp = (*vkuu)->buffer;
   9333             int i;
   9334             for(i=0; i<(*vkuu)->number_of_packets; i++) {
   9335                POST_MEM_WRITE((Addr)&(*vkuu)->iso_frame_desc[i].actual_length, sizeof((*vkuu)->iso_frame_desc[i].actual_length));
   9336                POST_MEM_WRITE((Addr)&(*vkuu)->iso_frame_desc[i].status, sizeof((*vkuu)->iso_frame_desc[i].status));
   9337                if ((*vkuu)->endpoint & 0x80)
   9338                   POST_MEM_WRITE((Addr)bp, (*vkuu)->iso_frame_desc[i].actual_length);
   9339                bp += (*vkuu)->iso_frame_desc[i].length; // FIXME: or actual_length??
   9340             }
   9341             POST_MEM_WRITE((Addr)&(*vkuu)->error_count, sizeof((*vkuu)->error_count));
   9342          } else {
   9343             if ((*vkuu)->endpoint & 0x80)
   9344                POST_MEM_WRITE((Addr)(*vkuu)->buffer, (*vkuu)->actual_length);
   9345             POST_MEM_WRITE((Addr)&(*vkuu)->actual_length, sizeof((*vkuu)->actual_length));
   9346          }
   9347       }
   9348       break;
   9349    case VKI_USBDEVFS_CONNECTINFO:
   9350       POST_MEM_WRITE(ARG3, sizeof(struct vki_usbdevfs_connectinfo));
   9351       break;
   9352    case VKI_USBDEVFS_IOCTL:
   9353       if ( ARG3 ) {
   9354          struct vki_usbdevfs_ioctl *vkui = (struct vki_usbdevfs_ioctl *)ARG3;
   9355          UInt dir2, size2;
   9356          dir2  = _VKI_IOC_DIR(vkui->ioctl_code);
   9357          size2 = _VKI_IOC_SIZE(vkui->ioctl_code);
   9358          if (size2 > 0) {
   9359             if (dir2 & _VKI_IOC_READ)
   9360                POST_MEM_WRITE((Addr)vkui->data, size2);
   9361          }
   9362       }
   9363       break;
   9364 
   9365       /* I2C (/dev/i2c-*) ioctls */
   9366    case VKI_I2C_SLAVE:
   9367    case VKI_I2C_SLAVE_FORCE:
   9368    case VKI_I2C_TENBIT:
   9369    case VKI_I2C_PEC:
   9370       break;
   9371    case VKI_I2C_FUNCS:
   9372       POST_MEM_WRITE( ARG3, sizeof(unsigned long) );
   9373       break;
   9374    case VKI_I2C_RDWR:
   9375       if ( ARG3 ) {
   9376           struct vki_i2c_rdwr_ioctl_data *vkui = (struct vki_i2c_rdwr_ioctl_data *)ARG3;
   9377           UInt i;
   9378           for (i=0; i < vkui->nmsgs; i++) {
   9379               struct vki_i2c_msg *msg = vkui->msgs + i;
   9380               if (msg->flags & VKI_I2C_M_RD)
   9381                   POST_MEM_WRITE((Addr)msg->buf, msg->len);
   9382           }
   9383       }
   9384       break;
   9385    case VKI_I2C_SMBUS:
   9386        if ( ARG3 ) {
   9387             struct vki_i2c_smbus_ioctl_data *vkis
   9388                = (struct vki_i2c_smbus_ioctl_data *) ARG3;
   9389             /* i2c_smbus_write_quick hides its value in read_write, so
   9390                this variable can have a different meaning */
   9391             if ((vkis->read_write == VKI_I2C_SMBUS_READ)
   9392                 || (vkis->size == VKI_I2C_SMBUS_PROC_CALL)
   9393                 || (vkis->size == VKI_I2C_SMBUS_BLOCK_PROC_CALL)) {
   9394                 if ( ! (vkis->size == VKI_I2C_SMBUS_QUICK)) {
   9395                     UInt size;
   9396                     switch(vkis->size) {
   9397                         case VKI_I2C_SMBUS_BYTE:
   9398                         case VKI_I2C_SMBUS_BYTE_DATA:
   9399                             size = 1;
   9400                             break;
   9401                         case VKI_I2C_SMBUS_WORD_DATA:
   9402                         case VKI_I2C_SMBUS_PROC_CALL:
   9403                             size = 2;
   9404                             break;
   9405                         case VKI_I2C_SMBUS_BLOCK_DATA:
   9406                         case VKI_I2C_SMBUS_I2C_BLOCK_BROKEN:
   9407                         case VKI_I2C_SMBUS_BLOCK_PROC_CALL:
   9408                         case VKI_I2C_SMBUS_I2C_BLOCK_DATA:
   9409                             size = 1 + vkis->data->block[0];
   9410                             break;
   9411                         default:
   9412                             size = 0;
   9413                     }
   9414                     POST_MEM_WRITE((Addr)&vkis->data->block[0], size);
   9415                 }
   9416             }
   9417        }
   9418        break;
   9419 
   9420       /* Wireless extensions ioctls */
   9421    case VKI_SIOCSIWCOMMIT:
   9422    case VKI_SIOCSIWNWID:
   9423    case VKI_SIOCSIWFREQ:
   9424    case VKI_SIOCSIWMODE:
   9425    case VKI_SIOCSIWSENS:
   9426    case VKI_SIOCSIWRANGE:
   9427    case VKI_SIOCSIWPRIV:
   9428    case VKI_SIOCSIWSTATS:
   9429    case VKI_SIOCSIWSPY:
   9430    case VKI_SIOCSIWTHRSPY:
   9431    case VKI_SIOCSIWAP:
   9432    case VKI_SIOCSIWSCAN:
   9433    case VKI_SIOCSIWESSID:
   9434    case VKI_SIOCSIWRATE:
   9435    case VKI_SIOCSIWNICKN:
   9436    case VKI_SIOCSIWRTS:
   9437    case VKI_SIOCSIWFRAG:
   9438    case VKI_SIOCSIWTXPOW:
   9439    case VKI_SIOCSIWRETRY:
   9440    case VKI_SIOCSIWENCODE:
   9441    case VKI_SIOCSIWPOWER:
   9442    case VKI_SIOCSIWGENIE:
   9443    case VKI_SIOCSIWMLME:
   9444    case VKI_SIOCSIWAUTH:
   9445    case VKI_SIOCSIWENCODEEXT:
   9446    case VKI_SIOCSIWPMKSA:
   9447       break;
   9448    case VKI_SIOCGIWNAME:
   9449       if (ARG3) {
   9450          POST_MEM_WRITE((Addr)((struct vki_iwreq *)ARG3)->u.name,
   9451                         sizeof(((struct vki_iwreq *)ARG3)->u.name));
   9452       }
   9453       break;
   9454    case VKI_SIOCGIWNWID:
   9455    case VKI_SIOCGIWSENS:
   9456    case VKI_SIOCGIWRATE:
   9457    case VKI_SIOCGIWRTS:
   9458    case VKI_SIOCGIWFRAG:
   9459    case VKI_SIOCGIWTXPOW:
   9460    case VKI_SIOCGIWRETRY:
   9461    case VKI_SIOCGIWPOWER:
   9462    case VKI_SIOCGIWAUTH:
   9463       if (ARG3) {
   9464          POST_MEM_WRITE((Addr)&((struct vki_iwreq *)ARG3)->u.param,
   9465                         sizeof(struct vki_iw_param));
   9466       }
   9467       break;
   9468    case VKI_SIOCGIWFREQ:
   9469       if (ARG3) {
   9470          POST_MEM_WRITE((Addr)&((struct vki_iwreq *)ARG3)->u.freq,
   9471                         sizeof(struct vki_iw_freq));
   9472       }
   9473       break;
   9474    case VKI_SIOCGIWMODE:
   9475       if (ARG3) {
   9476          POST_MEM_WRITE((Addr)&((struct vki_iwreq *)ARG3)->u.mode,
   9477                        sizeof(__vki_u32));
   9478       }
   9479       break;
   9480    case VKI_SIOCGIWRANGE:
   9481    case VKI_SIOCGIWPRIV:
   9482    case VKI_SIOCGIWSTATS:
   9483    case VKI_SIOCGIWSPY:
   9484    case VKI_SIOCGIWTHRSPY:
   9485    case VKI_SIOCGIWAPLIST:
   9486    case VKI_SIOCGIWSCAN:
   9487    case VKI_SIOCGIWESSID:
   9488    case VKI_SIOCGIWNICKN:
   9489    case VKI_SIOCGIWENCODE:
   9490    case VKI_SIOCGIWGENIE:
   9491    case VKI_SIOCGIWENCODEEXT:
   9492       if (ARG3) {
   9493          struct vki_iw_point* point;
   9494          point = &((struct vki_iwreq *)ARG3)->u.data;
   9495          POST_MEM_WRITE((Addr)point->pointer, point->length);
   9496       }
   9497       break;
   9498    case VKI_SIOCGIWAP:
   9499       if (ARG3) {
   9500          POST_MEM_WRITE((Addr)&((struct vki_iwreq *)ARG3)->u.ap_addr,
   9501                         sizeof(struct vki_sockaddr));
   9502       }
   9503       break;
   9504 
   9505 #  if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
   9506       || defined(VGPV_mips32_linux_android)
   9507    /* ashmem */
   9508    case VKI_ASHMEM_GET_SIZE:
   9509    case VKI_ASHMEM_SET_SIZE:
   9510    case VKI_ASHMEM_GET_PROT_MASK:
   9511    case VKI_ASHMEM_SET_PROT_MASK:
   9512    case VKI_ASHMEM_GET_PIN_STATUS:
   9513    case VKI_ASHMEM_PURGE_ALL_CACHES:
   9514    case VKI_ASHMEM_SET_NAME:
   9515    case VKI_ASHMEM_PIN:
   9516    case VKI_ASHMEM_UNPIN:
   9517        break;
   9518    case VKI_ASHMEM_GET_NAME:
   9519        POST_MEM_WRITE( ARG3, VKI_ASHMEM_NAME_LEN );
   9520        break;
   9521 
   9522    /* binder */
   9523    case VKI_BINDER_WRITE_READ:
   9524        if (ARG3) {
   9525            struct vki_binder_write_read* bwr
   9526               = (struct vki_binder_write_read*)ARG3;
   9527            POST_FIELD_WRITE(bwr->write_consumed);
   9528            POST_FIELD_WRITE(bwr->read_consumed);
   9529 
   9530            if (bwr->read_size)
   9531                POST_MEM_WRITE((Addr)bwr->read_buffer, bwr->read_consumed);
   9532        }
   9533        break;
   9534 
   9535    case VKI_BINDER_SET_IDLE_TIMEOUT:
   9536    case VKI_BINDER_SET_MAX_THREADS:
   9537    case VKI_BINDER_SET_IDLE_PRIORITY:
   9538    case VKI_BINDER_SET_CONTEXT_MGR:
   9539    case VKI_BINDER_THREAD_EXIT:
   9540        break;
   9541    case VKI_BINDER_VERSION:
   9542        if (ARG3) {
   9543            struct vki_binder_version* bv = (struct vki_binder_version*)ARG3;
   9544            POST_FIELD_WRITE(bv->protocol_version);
   9545        }
   9546        break;
   9547 #  endif /* defined(VGPV_*_linux_android) */
   9548 
   9549    case VKI_HCIGETDEVLIST:
   9550       if (ARG3) {
   9551         struct vki_hci_dev_list_req* dlr = (struct vki_hci_dev_list_req*)ARG3;
   9552         POST_MEM_WRITE((Addr)ARG3 + sizeof(struct vki_hci_dev_list_req),
   9553                        dlr->dev_num * sizeof(struct vki_hci_dev_req));
   9554       }
   9555       break;
   9556 
   9557    case VKI_HCIINQUIRY:
   9558       if (ARG3) {
   9559         struct vki_hci_inquiry_req* ir = (struct vki_hci_inquiry_req*)ARG3;
   9560         POST_MEM_WRITE((Addr)ARG3 + sizeof(struct vki_hci_inquiry_req),
   9561                        ir->num_rsp * sizeof(struct vki_inquiry_info));
   9562       }
   9563       break;
   9564 
   9565    case VKI_DRM_IOCTL_VERSION:
   9566       if (ARG3) {
   9567          struct vki_drm_version *data = (struct vki_drm_version *)ARG3;
   9568 	 POST_MEM_WRITE((Addr)&data->version_major, sizeof(data->version_major));
   9569          POST_MEM_WRITE((Addr)&data->version_minor, sizeof(data->version_minor));
   9570          POST_MEM_WRITE((Addr)&data->version_patchlevel, sizeof(data->version_patchlevel));
   9571          POST_MEM_WRITE((Addr)&data->name_len, sizeof(data->name_len));
   9572          POST_MEM_WRITE((Addr)data->name, data->name_len);
   9573          POST_MEM_WRITE((Addr)&data->date_len, sizeof(data->date_len));
   9574          POST_MEM_WRITE((Addr)data->date, data->date_len);
   9575          POST_MEM_WRITE((Addr)&data->desc_len, sizeof(data->desc_len));
   9576          POST_MEM_WRITE((Addr)data->desc, data->desc_len);
   9577       }
   9578       break;
   9579    case VKI_DRM_IOCTL_GET_UNIQUE:
   9580       if (ARG3) {
   9581          struct vki_drm_unique *data = (struct vki_drm_unique *)ARG3;
   9582 	 POST_MEM_WRITE((Addr)data->unique, sizeof(data->unique_len));
   9583       }
   9584       break;
   9585    case VKI_DRM_IOCTL_GET_MAGIC:
   9586       if (ARG3) {
   9587          struct vki_drm_auth *data = (struct vki_drm_auth *)ARG3;
   9588          POST_MEM_WRITE((Addr)&data->magic, sizeof(data->magic));
   9589       }
   9590       break;
   9591    case VKI_DRM_IOCTL_WAIT_VBLANK:
   9592       if (ARG3) {
   9593          union vki_drm_wait_vblank *data = (union vki_drm_wait_vblank *)ARG3;
   9594          POST_MEM_WRITE((Addr)&data->reply, sizeof(data->reply));
   9595       }
   9596       break;
   9597    case VKI_DRM_IOCTL_GEM_FLINK:
   9598       if (ARG3) {
   9599          struct vki_drm_gem_flink *data = (struct vki_drm_gem_flink *)ARG3;
   9600          POST_MEM_WRITE((Addr)&data->name, sizeof(data->name));
   9601       }
   9602       break;
   9603    case VKI_DRM_IOCTL_GEM_OPEN:
   9604       if (ARG3) {
   9605          struct vki_drm_gem_open *data = (struct vki_drm_gem_open *)ARG3;
   9606 	 POST_MEM_WRITE((Addr)&data->handle, sizeof(data->handle));
   9607 	 POST_MEM_WRITE((Addr)&data->size, sizeof(data->size));
   9608       }
   9609       break;
   9610    case VKI_DRM_IOCTL_I915_GETPARAM:
   9611       if (ARG3) {
   9612          vki_drm_i915_getparam_t *data = (vki_drm_i915_getparam_t *)ARG3;
   9613 	 POST_MEM_WRITE((Addr)data->value, sizeof(int));
   9614       }
   9615       break;
   9616    case VKI_DRM_IOCTL_I915_GEM_BUSY:
   9617       if (ARG3) {
   9618          struct vki_drm_i915_gem_busy *data = (struct vki_drm_i915_gem_busy *)ARG3;
   9619          POST_MEM_WRITE((Addr)&data->busy, sizeof(data->busy));
   9620       }
   9621       break;
   9622    case VKI_DRM_IOCTL_I915_GEM_CREATE:
   9623       if (ARG3) {
   9624          struct vki_drm_i915_gem_create *data = (struct vki_drm_i915_gem_create *)ARG3;
   9625 	 POST_MEM_WRITE((Addr)&data->handle, sizeof(data->handle));
   9626       }
   9627       break;
   9628    case VKI_DRM_IOCTL_I915_GEM_PREAD:
   9629       if (ARG3) {
   9630          struct vki_drm_i915_gem_pread *data = (struct vki_drm_i915_gem_pread *)ARG3;
   9631 	 POST_MEM_WRITE((Addr)data->data_ptr, data->size);
   9632       }
   9633       break;
   9634    case VKI_DRM_IOCTL_I915_GEM_MMAP_GTT:
   9635       if (ARG3) {
   9636          struct vki_drm_i915_gem_mmap_gtt *data = (struct vki_drm_i915_gem_mmap_gtt *)ARG3;
   9637          POST_MEM_WRITE((Addr)&data->offset, sizeof(data->offset));
   9638       }
   9639       break;
   9640    case VKI_DRM_IOCTL_I915_GEM_SET_TILING:
   9641       if (ARG3) {
   9642          struct vki_drm_i915_gem_set_tiling *data = (struct vki_drm_i915_gem_set_tiling *)ARG3;
   9643          POST_MEM_WRITE((Addr)&data->tiling_mode, sizeof(data->tiling_mode));
   9644          POST_MEM_WRITE((Addr)&data->stride, sizeof(data->stride));
   9645          POST_MEM_WRITE((Addr)&data->swizzle_mode, sizeof(data->swizzle_mode));
   9646       }
   9647       break;
   9648    case VKI_DRM_IOCTL_I915_GEM_GET_TILING:
   9649       if (ARG3) {
   9650          struct vki_drm_i915_gem_get_tiling *data = (struct vki_drm_i915_gem_get_tiling *)ARG3;
   9651 	 POST_MEM_WRITE((Addr)&data->tiling_mode, sizeof(data->tiling_mode));
   9652          POST_MEM_WRITE((Addr)&data->swizzle_mode, sizeof(data->swizzle_mode));
   9653       }
   9654       break;
   9655    case VKI_DRM_IOCTL_I915_GEM_GET_APERTURE:
   9656       if (ARG3) {
   9657          struct vki_drm_i915_gem_get_aperture *data = (struct vki_drm_i915_gem_get_aperture *)ARG3;
   9658          POST_MEM_WRITE((Addr)&data->aper_size, sizeof(data->aper_size));
   9659          POST_MEM_WRITE((Addr)&data->aper_available_size, sizeof(data->aper_available_size));
   9660       }
   9661       break;
   9662 
   9663    /* KVM ioctls that only write the system call return value */
   9664    case VKI_KVM_GET_API_VERSION:
   9665    case VKI_KVM_CREATE_VM:
   9666    case VKI_KVM_CHECK_EXTENSION:
   9667    case VKI_KVM_GET_VCPU_MMAP_SIZE:
   9668    case VKI_KVM_S390_ENABLE_SIE:
   9669    case VKI_KVM_CREATE_VCPU:
   9670    case VKI_KVM_SET_TSS_ADDR:
   9671    case VKI_KVM_CREATE_IRQCHIP:
   9672    case VKI_KVM_RUN:
   9673    case VKI_KVM_S390_INITIAL_RESET:
   9674    case VKI_KVM_KVMCLOCK_CTRL:
   9675       break;
   9676 
   9677    case VKI_KVM_S390_MEM_OP: {
   9678       struct vki_kvm_s390_mem_op *args =
   9679          (struct vki_kvm_s390_mem_op *)(ARG3);
   9680       if (args->flags & VKI_KVM_S390_MEMOP_F_CHECK_ONLY)
   9681          break;
   9682       if (args->op == VKI_KVM_S390_MEMOP_LOGICAL_READ)
   9683          POST_MEM_WRITE((Addr)args->buf, args->size);
   9684       }
   9685       break;
   9686 
   9687 #ifdef ENABLE_XEN
   9688    case VKI_XEN_IOCTL_PRIVCMD_HYPERCALL: {
   9689        SyscallArgs harrghs;
   9690        struct vki_xen_privcmd_hypercall *args =
   9691           (struct vki_xen_privcmd_hypercall *)(ARG3);
   9692 
   9693        if (!args)
   9694           break;
   9695 
   9696        VG_(memset)(&harrghs, 0, sizeof(harrghs));
   9697        harrghs.sysno = args->op;
   9698        harrghs.arg1 = args->arg[0];
   9699        harrghs.arg2 = args->arg[1];
   9700        harrghs.arg3 = args->arg[2];
   9701        harrghs.arg4 = args->arg[3];
   9702        harrghs.arg5 = args->arg[4];
   9703        harrghs.arg6 = harrghs.arg7 = harrghs.arg8 = 0;
   9704 
   9705        WRAPPER_POST_NAME(xen, hypercall) (tid, &harrghs, status);
   9706       }
   9707       break;
   9708 
   9709    case VKI_XEN_IOCTL_PRIVCMD_MMAP:
   9710       break;
   9711    case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH: {
   9712        struct vki_xen_privcmd_mmapbatch *args =
   9713            (struct vki_xen_privcmd_mmapbatch *)(ARG3);
   9714        POST_MEM_WRITE((Addr)args->arr, sizeof(*(args->arr)) * args->num);
   9715       }
   9716       break;
   9717    case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2: {
   9718        struct vki_xen_privcmd_mmapbatch_v2 *args =
   9719            (struct vki_xen_privcmd_mmapbatch_v2 *)(ARG3);
   9720        POST_MEM_WRITE((Addr)args->err, sizeof(*(args->err)) * args->num);
   9721       }
   9722       break;
   9723 
   9724    case VKI_XEN_IOCTL_EVTCHN_BIND_VIRQ:
   9725    case VKI_XEN_IOCTL_EVTCHN_BIND_INTERDOMAIN:
   9726    case VKI_XEN_IOCTL_EVTCHN_BIND_UNBOUND_PORT:
   9727    case VKI_XEN_IOCTL_EVTCHN_UNBIND:
   9728    case VKI_XEN_IOCTL_EVTCHN_NOTIFY:
   9729    case VKI_XEN_IOCTL_EVTCHN_RESET:
   9730       /* No output */
   9731       break;
   9732 #endif
   9733 
   9734    /* Lustre */
   9735    case VKI_OBD_IOC_FID2PATH: {
   9736        struct vki_getinfo_fid2path *args = (void *)(ARG3);
   9737        POST_FIELD_WRITE(args->gf_recno);
   9738        POST_FIELD_WRITE(args->gf_linkno);
   9739        POST_MEM_WRITE((Addr)args->gf_path, VG_(strlen)(args->gf_path)+1);
   9740        break;
   9741       }
   9742 
   9743    case VKI_LL_IOC_PATH2FID:
   9744        POST_MEM_WRITE(ARG3, sizeof(struct vki_lu_fid));
   9745       break;
   9746 
   9747    case VKI_LL_IOC_GETPARENT: {
   9748        struct vki_getparent *gp = (struct vki_getparent *)ARG3;
   9749        POST_FIELD_WRITE(gp->gp_fid);
   9750        POST_MEM_WRITE((Addr)gp->gp_name, VG_(strlen)(gp->gp_name)+1);
   9751        break;
   9752    }
   9753 
   9754    /* V4L2 */
   9755    case VKI_V4L2_S_FMT:
   9756    case VKI_V4L2_TRY_FMT:
   9757    case VKI_V4L2_REQBUFS:
   9758    case VKI_V4L2_OVERLAY:
   9759    case VKI_V4L2_STREAMON:
   9760    case VKI_V4L2_STREAMOFF:
   9761    case VKI_V4L2_S_PARM:
   9762    case VKI_V4L2_S_STD:
   9763    case VKI_V4L2_S_FREQUENCY:
   9764    case VKI_V4L2_S_CTRL:
   9765    case VKI_V4L2_S_TUNER:
   9766    case VKI_V4L2_S_AUDIO:
   9767    case VKI_V4L2_S_INPUT:
   9768    case VKI_V4L2_S_EDID:
   9769    case VKI_V4L2_S_OUTPUT:
   9770    case VKI_V4L2_S_AUDOUT:
   9771    case VKI_V4L2_S_MODULATOR:
   9772    case VKI_V4L2_S_JPEGCOMP:
   9773    case VKI_V4L2_S_CROP:
   9774    case VKI_V4L2_S_PRIORITY:
   9775    case VKI_V4L2_S_HW_FREQ_SEEK:
   9776    case VKI_V4L2_S_DV_TIMINGS:
   9777    case VKI_V4L2_SUBSCRIBE_EVENT:
   9778    case VKI_V4L2_UNSUBSCRIBE_EVENT:
   9779    case VKI_V4L2_PREPARE_BUF:
   9780       break;
   9781    case VKI_V4L2_QUERYCAP: {
   9782       struct vki_v4l2_capability *data = (struct vki_v4l2_capability *)ARG3;
   9783       POST_MEM_WRITE((Addr)data, sizeof(*data));
   9784       break;
   9785    }
   9786    case VKI_V4L2_ENUM_FMT: {
   9787       struct vki_v4l2_fmtdesc *data = (struct vki_v4l2_fmtdesc *)ARG3;
   9788       POST_FIELD_WRITE(data->flags);
   9789       POST_FIELD_WRITE(data->description);
   9790       POST_FIELD_WRITE(data->pixelformat);
   9791       POST_FIELD_WRITE(data->reserved);
   9792       break;
   9793    }
   9794    case VKI_V4L2_G_FMT: {
   9795       struct vki_v4l2_format *data = (struct vki_v4l2_format *)ARG3;
   9796       switch (data->type) {
   9797       case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE:
   9798       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT:
   9799          POST_FIELD_WRITE(data->fmt.pix);
   9800          break;
   9801       case VKI_V4L2_BUF_TYPE_VBI_CAPTURE:
   9802       case VKI_V4L2_BUF_TYPE_VBI_OUTPUT:
   9803          POST_FIELD_WRITE(data->fmt.vbi);
   9804          break;
   9805       case VKI_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
   9806       case VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
   9807          POST_FIELD_WRITE(data->fmt.sliced);
   9808          break;
   9809       case VKI_V4L2_BUF_TYPE_VIDEO_OVERLAY:
   9810       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
   9811          POST_FIELD_WRITE(data->fmt.win);
   9812          break;
   9813       case VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
   9814       case VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
   9815          POST_FIELD_WRITE(data->fmt.pix_mp);
   9816          break;
   9817       case VKI_V4L2_BUF_TYPE_SDR_CAPTURE:
   9818          POST_FIELD_WRITE(data->fmt.sdr);
   9819          break;
   9820       }
   9821       break;
   9822    }
   9823    case VKI_V4L2_QUERYBUF: {
   9824       struct vki_v4l2_buffer *data = (struct vki_v4l2_buffer *)ARG3;
   9825       if (data->type == VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
   9826             data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
   9827          unsigned i;
   9828 
   9829          for (i = 0; i < data->length; i++) {
   9830             POST_FIELD_WRITE(data->m.planes[i].bytesused);
   9831             POST_FIELD_WRITE(data->m.planes[i].length);
   9832             POST_FIELD_WRITE(data->m.planes[i].m);
   9833             POST_FIELD_WRITE(data->m.planes[i].data_offset);
   9834             POST_FIELD_WRITE(data->m.planes[i].reserved);
   9835          }
   9836       } else {
   9837          POST_FIELD_WRITE(data->m);
   9838          POST_FIELD_WRITE(data->length);
   9839       }
   9840       POST_FIELD_WRITE(data->bytesused);
   9841       POST_FIELD_WRITE(data->flags);
   9842       POST_FIELD_WRITE(data->field);
   9843       POST_FIELD_WRITE(data->timestamp);
   9844       POST_FIELD_WRITE(data->timecode);
   9845       POST_FIELD_WRITE(data->sequence);
   9846       POST_FIELD_WRITE(data->memory);
   9847       POST_FIELD_WRITE(data->sequence);
   9848       break;
   9849    }
   9850    case VKI_V4L2_G_FBUF: {
   9851       struct vki_v4l2_framebuffer *data = (struct vki_v4l2_framebuffer *)ARG3;
   9852       POST_MEM_WRITE((Addr)data, sizeof(*data));
   9853       break;
   9854    }
   9855    case VKI_V4L2_S_FBUF: {
   9856       struct vki_v4l2_framebuffer *data = (struct vki_v4l2_framebuffer *)ARG3;
   9857       POST_FIELD_WRITE(data->capability);
   9858       POST_FIELD_WRITE(data->flags);
   9859       POST_FIELD_WRITE(data->fmt);
   9860       break;
   9861    }
   9862    case VKI_V4L2_QBUF: {
   9863       struct vki_v4l2_buffer *data = (struct vki_v4l2_buffer *)ARG3;
   9864 
   9865       if (data->type == VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
   9866             data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
   9867          unsigned i;
   9868 
   9869          for (i = 0; i < data->length; i++) {
   9870             POST_FIELD_WRITE(data->m.planes[i].length);
   9871             if (data->memory == VKI_V4L2_MEMORY_MMAP)
   9872                POST_FIELD_WRITE(data->m.planes[i].m);
   9873          }
   9874       } else {
   9875          if (data->memory == VKI_V4L2_MEMORY_MMAP)
   9876             POST_FIELD_WRITE(data->m);
   9877          POST_FIELD_WRITE(data->length);
   9878       }
   9879       break;
   9880    }
   9881    case VKI_V4L2_EXPBUF: {
   9882       struct vki_v4l2_exportbuffer *data = (struct vki_v4l2_exportbuffer *)ARG3;
   9883       POST_FIELD_WRITE(data->fd);
   9884       break;
   9885    }
   9886    case VKI_V4L2_DQBUF: {
   9887       struct vki_v4l2_buffer *data = (struct vki_v4l2_buffer *)ARG3;
   9888       POST_FIELD_WRITE(data->index);
   9889       POST_FIELD_WRITE(data->bytesused);
   9890       POST_FIELD_WRITE(data->field);
   9891       if (data->type == VKI_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
   9892             data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
   9893          unsigned i;
   9894 
   9895          for (i = 0; i < data->length; i++) {
   9896             POST_FIELD_WRITE(data->m.planes[i].bytesused);
   9897             POST_FIELD_WRITE(data->m.planes[i].data_offset);
   9898             POST_FIELD_WRITE(data->m.planes[i].length);
   9899             POST_FIELD_WRITE(data->m.planes[i].m);
   9900          }
   9901       } else {
   9902          POST_FIELD_WRITE(data->m);
   9903          POST_FIELD_WRITE(data->length);
   9904          POST_FIELD_WRITE(data->bytesused);
   9905          POST_FIELD_WRITE(data->field);
   9906       }
   9907       POST_FIELD_WRITE(data->timestamp);
   9908       POST_FIELD_WRITE(data->timecode);
   9909       POST_FIELD_WRITE(data->sequence);
   9910       break;
   9911    }
   9912    case VKI_V4L2_G_PARM: {
   9913       struct vki_v4l2_streamparm *data = (struct vki_v4l2_streamparm *)ARG3;
   9914       int is_output = data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT ||
   9915          data->type == VKI_V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ||
   9916          data->type == VKI_V4L2_BUF_TYPE_VBI_OUTPUT ||
   9917          data->type == VKI_V4L2_BUF_TYPE_SLICED_VBI_OUTPUT;
   9918 
   9919       if (is_output)
   9920         POST_MEM_WRITE((Addr)&data->parm.output,
   9921             sizeof(data->parm.output) - sizeof(data->parm.output.reserved));
   9922       else
   9923         POST_MEM_WRITE((Addr)&data->parm.capture,
   9924             sizeof(data->parm.capture) - sizeof(data->parm.capture.reserved));
   9925       break;
   9926    }
   9927    case VKI_V4L2_G_STD: {
   9928       vki_v4l2_std_id *data = (vki_v4l2_std_id *)ARG3;
   9929       POST_MEM_WRITE((Addr)data, sizeof(*data));
   9930       break;
   9931    }
   9932    case VKI_V4L2_ENUMSTD: {
   9933       struct vki_v4l2_standard *data = (struct vki_v4l2_standard *)ARG3;
   9934       POST_MEM_WRITE((Addr)&data->id, sizeof(*data) - sizeof(data->index));
   9935       break;
   9936    }
   9937    case VKI_V4L2_ENUMINPUT: {
   9938       struct vki_v4l2_input *data = (struct vki_v4l2_input *)ARG3;
   9939       POST_MEM_WRITE((Addr)data->name, sizeof(*data) - sizeof(data->index));
   9940       break;
   9941    }
   9942    case VKI_V4L2_G_CTRL: {
   9943       struct vki_v4l2_control *data = (struct vki_v4l2_control *)ARG3;
   9944       POST_FIELD_WRITE(data->value);
   9945       break;
   9946    }
   9947    case VKI_V4L2_G_TUNER: {
   9948       struct vki_v4l2_tuner *data = (struct vki_v4l2_tuner *)ARG3;
   9949       POST_MEM_WRITE((Addr)data->name,
   9950             sizeof(*data) - sizeof(data->index) - sizeof(data->reserved));
   9951       break;
   9952    }
   9953    case VKI_V4L2_G_AUDIO: {
   9954       struct vki_v4l2_audio *data = (struct vki_v4l2_audio *)ARG3;
   9955       POST_MEM_WRITE((Addr)data,
   9956             sizeof(*data) - sizeof(data->reserved));
   9957       break;
   9958    }
   9959    case VKI_V4L2_QUERYCTRL: {
   9960       struct vki_v4l2_queryctrl *data = (struct vki_v4l2_queryctrl *)ARG3;
   9961       POST_MEM_WRITE((Addr)&data->type,
   9962             sizeof(*data) - sizeof(data->id));
   9963       break;
   9964    }
   9965    case VKI_V4L2_QUERYMENU: {
   9966       struct vki_v4l2_querymenu *data = (struct vki_v4l2_querymenu *)ARG3;
   9967       POST_MEM_WRITE((Addr)data->name,
   9968             sizeof(*data) - sizeof(data->id) - sizeof(data->index));
   9969       break;
   9970    }
   9971    case VKI_V4L2_G_INPUT: {
   9972       int *data = (int *)ARG3;
   9973       POST_MEM_WRITE((Addr)data, sizeof(*data));
   9974       break;
   9975    }
   9976    case VKI_V4L2_G_EDID: {
   9977       struct vki_v4l2_edid *data = (struct vki_v4l2_edid *)ARG3;
   9978       if (data->blocks && data->edid)
   9979          POST_MEM_WRITE((Addr)data->edid, data->blocks * 128);
   9980       break;
   9981    }
   9982    case VKI_V4L2_G_OUTPUT: {
   9983       int *data = (int *)ARG3;
   9984       POST_MEM_WRITE((Addr)data, sizeof(*data));
   9985       break;
   9986    }
   9987    case VKI_V4L2_ENUMOUTPUT: {
   9988       struct vki_v4l2_output *data = (struct vki_v4l2_output *)ARG3;
   9989       POST_MEM_WRITE((Addr)data->name, sizeof(*data) - sizeof(data->index));
   9990       break;
   9991    }
   9992    case VKI_V4L2_G_AUDOUT: {
   9993       struct vki_v4l2_audioout *data = (struct vki_v4l2_audioout *)ARG3;
   9994       POST_MEM_WRITE((Addr)data,
   9995             sizeof(*data) - sizeof(data->reserved));
   9996       break;
   9997    }
   9998    case VKI_V4L2_G_MODULATOR: {
   9999       struct vki_v4l2_modulator *data = (struct vki_v4l2_modulator *)ARG3;
   10000       POST_MEM_WRITE((Addr)data->name,
   10001             sizeof(*data) - sizeof(data->index) - sizeof(data->reserved));
   10002       break;
   10003    }
   10004    case VKI_V4L2_G_FREQUENCY: {
   10005       struct vki_v4l2_frequency *data = (struct vki_v4l2_frequency *)ARG3;
   10006       POST_FIELD_WRITE(data->type);
   10007       POST_FIELD_WRITE(data->frequency);
   10008       break;
   10009    }
   10010    case VKI_V4L2_CROPCAP: {
   10011       struct vki_v4l2_cropcap *data = (struct vki_v4l2_cropcap *)ARG3;
   10012       POST_MEM_WRITE((Addr)&data->bounds, sizeof(*data) - sizeof(data->type));
   10013       break;
   10014    }
   10015    case VKI_V4L2_G_CROP: {
   10016       struct vki_v4l2_crop *data = (struct vki_v4l2_crop *)ARG3;
   10017       POST_FIELD_WRITE(data->c);
   10018       break;
   10019    }
   10020    case VKI_V4L2_G_JPEGCOMP: {
   10021       struct vki_v4l2_jpegcompression *data = (struct vki_v4l2_jpegcompression *)ARG3;
   10022       POST_MEM_WRITE((Addr)data, sizeof(*data));
   10023       break;
   10024    }
   10025    case VKI_V4L2_QUERYSTD: {
   10026       vki_v4l2_std_id *data = (vki_v4l2_std_id *)ARG3;
   10027       POST_MEM_WRITE((Addr)data, sizeof(*data));
   10028       break;
   10029    }
   10030    case VKI_V4L2_ENUMAUDIO: {
   10031       struct vki_v4l2_audio *data = (struct vki_v4l2_audio *)ARG3;
   10032       POST_MEM_WRITE((Addr)data->name,
   10033             sizeof(*data) - sizeof(data->index) - sizeof(data->reserved));
   10034       break;
   10035    }
   10036    case VKI_V4L2_ENUMAUDOUT: {
   10037       struct vki_v4l2_audioout *data = (struct vki_v4l2_audioout *)ARG3;
   10038       POST_MEM_WRITE((Addr)data->name,
   10039             sizeof(*data) - sizeof(data->index) - sizeof(data->reserved));
   10040       break;
   10041    }
   10042    case VKI_V4L2_G_PRIORITY: {
   10043       __vki_u32 *data = (__vki_u32 *)ARG3;
   10044       POST_MEM_WRITE((Addr)data, sizeof(*data));
   10045       break;
   10046    }
   10047    case VKI_V4L2_G_SLICED_VBI_CAP: {
   10048       struct vki_v4l2_sliced_vbi_cap *data = (struct vki_v4l2_sliced_vbi_cap *)ARG3;
   10049       POST_MEM_WRITE((Addr)data,
   10050             sizeof(*data) - sizeof(data->type) - sizeof(data->reserved));
   10051       break;
   10052    }
   10053    case VKI_V4L2_G_EXT_CTRLS: {
   10054       struct vki_v4l2_ext_controls *data = (struct vki_v4l2_ext_controls *)ARG3;
   10055       if (data->count) {
   10056          unsigned i;
   10057 
   10058          for (i = 0; i < data->count; i++) {
   10059             if (data->controls[i].size)
   10060                POST_MEM_WRITE((Addr)data->controls[i].ptr, data->controls[i].size);
   10061             else
   10062                POST_FIELD_WRITE(data->controls[i].value64);
   10063          }
   10064       }
   10065       POST_FIELD_WRITE(data->error_idx);
   10066       break;
   10067    }
   10068    case VKI_V4L2_S_EXT_CTRLS: {
   10069       struct vki_v4l2_ext_controls *data = (struct vki_v4l2_ext_controls *)ARG3;
   10070       POST_FIELD_WRITE(data->error_idx);
   10071       break;
   10072    }
   10073    case VKI_V4L2_TRY_EXT_CTRLS: {
   10074       struct vki_v4l2_ext_controls *data = (struct vki_v4l2_ext_controls *)ARG3;
   10075       POST_FIELD_WRITE(data->error_idx);
   10076       break;
   10077    }
   10078    case VKI_V4L2_ENUM_FRAMESIZES: {
   10079       struct vki_v4l2_frmsizeenum *data = (struct vki_v4l2_frmsizeenum *)ARG3;
   10080       POST_FIELD_WRITE(data->type);
   10081       POST_FIELD_WRITE(data->stepwise);
   10082       break;
   10083    }
   10084    case VKI_V4L2_ENUM_FRAMEINTERVALS: {
   10085       struct vki_v4l2_frmivalenum *data = (struct vki_v4l2_frmivalenum *)ARG3;
   10086       POST_FIELD_WRITE(data->type);
   10087       POST_FIELD_WRITE(data->stepwise);
   10088       break;
   10089    }
   10090    case VKI_V4L2_G_ENC_INDEX: {
   10091       struct vki_v4l2_enc_idx *data = (struct vki_v4l2_enc_idx *)ARG3;
   10092       POST_MEM_WRITE((Addr)data, sizeof(*data));
   10093       break;
   10094    }
   10095    case VKI_V4L2_ENCODER_CMD: {
   10096       struct vki_v4l2_encoder_cmd *data = (struct vki_v4l2_encoder_cmd *)ARG3;
   10097       POST_FIELD_WRITE(data->flags);
   10098       break;
   10099    }
   10100    case VKI_V4L2_TRY_ENCODER_CMD: {
   10101       struct vki_v4l2_encoder_cmd *data = (struct vki_v4l2_encoder_cmd *)ARG3;
   10102       POST_FIELD_WRITE(data->flags);
   10103       break;
   10104    }
   10105    case VKI_V4L2_DBG_S_REGISTER: {
   10106       struct vki_v4l2_dbg_register *data = (struct vki_v4l2_dbg_register *)ARG3;
   10107       POST_FIELD_WRITE(data->size);
   10108       break;
   10109    }
   10110    case VKI_V4L2_DBG_G_REGISTER: {
   10111       struct vki_v4l2_dbg_register *data = (struct vki_v4l2_dbg_register *)ARG3;
   10112       POST_FIELD_WRITE(data->val);
   10113       POST_FIELD_WRITE(data->size);
   10114       break;
   10115    }
   10116    case VKI_V4L2_G_DV_TIMINGS: {
   10117       struct vki_v4l2_dv_timings *data = (struct vki_v4l2_dv_timings *)ARG3;
   10118       POST_MEM_WRITE((Addr)data, sizeof(*data));
   10119       break;
   10120    }
   10121    case VKI_V4L2_DQEVENT: {
   10122       struct vki_v4l2_event *data = (struct vki_v4l2_event *)ARG3;
   10123       POST_MEM_WRITE((Addr)data, sizeof(*data));
   10124       break;
   10125    }
   10126    case VKI_V4L2_CREATE_BUFS: {
   10127       struct vki_v4l2_create_buffers *data = (struct vki_v4l2_create_buffers *)ARG3;
   10128       POST_FIELD_WRITE(data->index);
   10129       break;
   10130    }
   10131    case VKI_V4L2_G_SELECTION: {
   10132       struct vki_v4l2_selection *data = (struct vki_v4l2_selection *)ARG3;
   10133       POST_FIELD_WRITE(data->r);
   10134       break;
   10135    }
   10136    case VKI_V4L2_S_SELECTION: {
   10137       struct vki_v4l2_selection *data = (struct vki_v4l2_selection *)ARG3;
   10138       POST_FIELD_WRITE(data->r);
   10139       break;
   10140    }
   10141    case VKI_V4L2_DECODER_CMD: {
   10142       struct vki_v4l2_decoder_cmd *data = (struct vki_v4l2_decoder_cmd *)ARG3;
   10143       POST_FIELD_WRITE(data->flags);
   10144       break;
   10145    }
   10146    case VKI_V4L2_TRY_DECODER_CMD: {
   10147       struct vki_v4l2_decoder_cmd *data = (struct vki_v4l2_decoder_cmd *)ARG3;
   10148       POST_FIELD_WRITE(data->flags);
   10149       break;
   10150    }
   10151    case VKI_V4L2_ENUM_DV_TIMINGS: {
   10152       struct vki_v4l2_enum_dv_timings *data = (struct vki_v4l2_enum_dv_timings *)ARG3;
   10153       POST_FIELD_WRITE(data->timings);
   10154       break;
   10155    }
   10156    case VKI_V4L2_QUERY_DV_TIMINGS: {
   10157       struct vki_v4l2_dv_timings *data = (struct vki_v4l2_dv_timings *)ARG3;
   10158       POST_MEM_WRITE((Addr)data, sizeof(*data));
   10159       break;
   10160    }
   10161    case VKI_V4L2_DV_TIMINGS_CAP: {
   10162       struct vki_v4l2_dv_timings_cap *data = (struct vki_v4l2_dv_timings_cap *)ARG3;
   10163       POST_MEM_WRITE((Addr)data, sizeof(*data));
   10164       break;
   10165    }
   10166    case VKI_V4L2_ENUM_FREQ_BANDS: {
   10167       struct vki_v4l2_frequency_band *data = (struct vki_v4l2_frequency_band *)ARG3;
   10168       POST_FIELD_WRITE(data->capability);
   10169       POST_FIELD_WRITE(data->rangelow);
   10170       POST_FIELD_WRITE(data->rangehigh);
   10171       POST_FIELD_WRITE(data->modulation);
   10172       break;
   10173    }
   10174    case VKI_V4L2_DBG_G_CHIP_INFO: {
   10175       struct vki_v4l2_dbg_chip_info *data = (struct vki_v4l2_dbg_chip_info *)ARG3;
   10176       POST_FIELD_WRITE(data->name);
   10177       POST_FIELD_WRITE(data->flags);
   10178       break;
   10179    }
   10180    case VKI_V4L2_QUERY_EXT_CTRL: {
   10181       struct vki_v4l2_query_ext_ctrl *data = (struct vki_v4l2_query_ext_ctrl *)ARG3;
   10182       POST_MEM_WRITE((Addr)&data->type,
   10183             sizeof(*data) - sizeof(data->id) - sizeof(data->reserved));
   10184       break;
   10185    }
   10186 
   10187    case VKI_V4L2_SUBDEV_S_FMT:
   10188    case VKI_V4L2_SUBDEV_S_FRAME_INTERVAL:
   10189    case VKI_V4L2_SUBDEV_S_CROP:
   10190    case VKI_V4L2_SUBDEV_S_SELECTION:
   10191       break;
   10192 
   10193    case VKI_V4L2_SUBDEV_G_FMT: {
   10194       struct vki_v4l2_subdev_format *data = (struct vki_v4l2_subdev_format *)ARG3;
   10195       POST_FIELD_WRITE(data->format);
   10196       break;
   10197    }
   10198    case VKI_V4L2_SUBDEV_G_FRAME_INTERVAL: {
   10199       struct vki_v4l2_subdev_frame_interval *data = (struct vki_v4l2_subdev_frame_interval *)ARG3;
   10200       POST_FIELD_WRITE(data->interval);
   10201       break;
   10202    }
   10203    case VKI_V4L2_SUBDEV_ENUM_MBUS_CODE: {
   10204       struct vki_v4l2_subdev_mbus_code_enum *data = (struct vki_v4l2_subdev_mbus_code_enum *)ARG3;
   10205       POST_FIELD_WRITE(data->code);
   10206       break;
   10207    }
   10208    case VKI_V4L2_SUBDEV_ENUM_FRAME_SIZE: {
   10209       struct vki_v4l2_subdev_frame_size_enum *data = (struct vki_v4l2_subdev_frame_size_enum *)ARG3;
   10210       POST_FIELD_WRITE(data->min_width);
   10211       POST_FIELD_WRITE(data->min_height);
   10212       POST_FIELD_WRITE(data->max_width);
   10213       POST_FIELD_WRITE(data->max_height);
   10214       break;
   10215    }
   10216    case VKI_V4L2_SUBDEV_ENUM_FRAME_INTERVAL: {
   10217       struct vki_v4l2_subdev_frame_interval_enum *data = (struct vki_v4l2_subdev_frame_interval_enum *)ARG3;
   10218       POST_FIELD_WRITE(data->interval);
   10219       break;
   10220    }
   10221    case VKI_V4L2_SUBDEV_G_CROP: {
   10222       struct vki_v4l2_subdev_crop *data = (struct vki_v4l2_subdev_crop *)ARG3;
   10223       POST_FIELD_WRITE(data->rect);
   10224       break;
   10225    }
   10226    case VKI_V4L2_SUBDEV_G_SELECTION: {
   10227       struct vki_v4l2_subdev_selection *data = (struct vki_v4l2_subdev_selection *)ARG3;
   10228       POST_FIELD_WRITE(data->r);
   10229       break;
   10230    }
   10231    case VKI_MEDIA_IOC_DEVICE_INFO: {
   10232       struct vki_media_device_info *data = (struct vki_media_device_info *)ARG3;
   10233       POST_MEM_WRITE((Addr)data, sizeof(*data) - sizeof(data->reserved));
   10234       break;
   10235    }
   10236    case VKI_MEDIA_IOC_ENUM_ENTITIES: {
   10237       struct vki_media_entity_desc *data = (struct vki_media_entity_desc *)ARG3;
   10238       POST_MEM_WRITE((Addr)data->name, sizeof(*data) - sizeof(data->id));
   10239       break;
   10240    }
   10241    case VKI_MEDIA_IOC_ENUM_LINKS:
   10242       /*
   10243        * This ioctl does write to the provided pointers, but it's not
   10244        * possible to deduce the size of the array those pointers point to.
   10245        */
   10246       break;
   10247    case VKI_MEDIA_IOC_SETUP_LINK:
   10248       break;
   10249 
   10250    /* Serial */
   10251    case VKI_TIOCGSERIAL: {
   10252       struct vki_serial_struct *data = (struct vki_serial_struct *)ARG3;
   10253       POST_MEM_WRITE((Addr)data, sizeof(*data));
   10254       break;
   10255    }
   10256    case VKI_TIOCSSERIAL:
   10257       break;
   10258 
   10259    default:
   10260       /* EVIOC* are variable length and return size written on success */
   10261       switch (ARG2 & ~(_VKI_IOC_SIZEMASK << _VKI_IOC_SIZESHIFT)) {
   10262       case VKI_EVIOCGNAME(0):
   10263       case VKI_EVIOCGPHYS(0):
   10264       case VKI_EVIOCGUNIQ(0):
   10265       case VKI_EVIOCGKEY(0):
   10266       case VKI_EVIOCGLED(0):
   10267       case VKI_EVIOCGSND(0):
   10268       case VKI_EVIOCGSW(0):
   10269       case VKI_EVIOCGBIT(VKI_EV_SYN,0):
   10270       case VKI_EVIOCGBIT(VKI_EV_KEY,0):
   10271       case VKI_EVIOCGBIT(VKI_EV_REL,0):
   10272       case VKI_EVIOCGBIT(VKI_EV_ABS,0):
   10273       case VKI_EVIOCGBIT(VKI_EV_MSC,0):
   10274       case VKI_EVIOCGBIT(VKI_EV_SW,0):
   10275       case VKI_EVIOCGBIT(VKI_EV_LED,0):
   10276       case VKI_EVIOCGBIT(VKI_EV_SND,0):
   10277       case VKI_EVIOCGBIT(VKI_EV_REP,0):
   10278       case VKI_EVIOCGBIT(VKI_EV_FF,0):
   10279       case VKI_EVIOCGBIT(VKI_EV_PWR,0):
   10280       case VKI_EVIOCGBIT(VKI_EV_FF_STATUS,0):
   10281          if (RES > 0)
   10282             POST_MEM_WRITE(ARG3, RES);
   10283          break;
   10284       default:
   10285          ML_(POST_unknown_ioctl)(tid, RES, ARG2, ARG3);
   10286          break;
   10287       }
   10288       break;
   10289    }
   10290 
   10291   post_sys_ioctl__out:
   10292    {} /* keep C compilers happy */
   10293 }
   10294 
   10295 /* ---------------------------------------------------------------------
   10296    socketcall wrapper helpers
   10297    ------------------------------------------------------------------ */
   10298 
   10299 void
   10300 ML_(linux_PRE_sys_getsockopt) ( ThreadId tid,
   10301                                 UWord arg0, UWord arg1, UWord arg2,
   10302                                 UWord arg3, UWord arg4 )
   10303 {
   10304    /* int getsockopt(int s, int level, int optname,
   10305                      void *optval, socklen_t *optlen); */
   10306    Addr optval_p = arg3;
   10307    Addr optlen_p = arg4;
   10308    /* vg_assert(sizeof(socklen_t) == sizeof(UInt)); */
   10309    if (optval_p != (Addr)NULL) {
   10310       ML_(buf_and_len_pre_check) ( tid, optval_p, optlen_p,
   10311                                    "socketcall.getsockopt(optval)",
   10312                                    "socketcall.getsockopt(optlen)" );
   10313       if (arg1 == VKI_SOL_SCTP &&
   10314           (arg2 == VKI_SCTP_GET_PEER_ADDRS ||
   10315            arg2 == VKI_SCTP_GET_LOCAL_ADDRS))
   10316       {
   10317          struct vki_sctp_getaddrs *ga = (struct vki_sctp_getaddrs*)arg3;
   10318          int address_bytes = sizeof(struct vki_sockaddr_in6) * ga->addr_num;
   10319          PRE_MEM_WRITE( "socketcall.getsockopt(optval.addrs)",
   10320                         (Addr)ga->addrs, address_bytes );
   10321       }
   10322    }
   10323 }
   10324 
   10325 void
   10326 ML_(linux_POST_sys_getsockopt) ( ThreadId tid,
   10327                                  SysRes res,
   10328                                  UWord arg0, UWord arg1, UWord arg2,
   10329                                  UWord arg3, UWord arg4 )
   10330 {
   10331    Addr optval_p = arg3;
   10332    Addr optlen_p = arg4;
   10333    vg_assert(!sr_isError(res)); /* guaranteed by caller */
   10334    if (optval_p != (Addr)NULL) {
   10335       ML_(buf_and_len_post_check) ( tid, res, optval_p, optlen_p,
   10336                                     "socketcall.getsockopt(optlen_out)" );
   10337       if (arg1 == VKI_SOL_SCTP &&
   10338           (arg2 == VKI_SCTP_GET_PEER_ADDRS ||
   10339            arg2 == VKI_SCTP_GET_LOCAL_ADDRS))
   10340       {
   10341          struct vki_sctp_getaddrs *ga = (struct vki_sctp_getaddrs*)arg3;
   10342          struct vki_sockaddr *a = ga->addrs;
   10343          int i;
   10344          for (i = 0; i < ga->addr_num; i++) {
   10345             int sl = 0;
   10346             if (a->sa_family == VKI_AF_INET)
   10347                sl = sizeof(struct vki_sockaddr_in);
   10348             else if (a->sa_family == VKI_AF_INET6)
   10349                sl = sizeof(struct vki_sockaddr_in6);
   10350             else {
   10351                VG_(message)(Vg_UserMsg, "Warning: getsockopt: unhandled "
   10352                                         "address type %d\n", a->sa_family);
   10353             }
   10354             a = (struct vki_sockaddr*)((char*)a + sl);
   10355          }
   10356          POST_MEM_WRITE( (Addr)ga->addrs, (char*)a - (char*)ga->addrs );
   10357       }
   10358    }
   10359 }
   10360 
   10361 void
   10362 ML_(linux_PRE_sys_setsockopt) ( ThreadId tid,
   10363                                 UWord arg0, UWord arg1, UWord arg2,
   10364                                 UWord arg3, UWord arg4 )
   10365 {
   10366    /* int setsockopt(int s, int level, int optname,
   10367                      const void *optval, socklen_t optlen); */
   10368    Addr optval_p = arg3;
   10369    if (optval_p != (Addr)NULL) {
   10370       /*
   10371        * OK, let's handle at least some setsockopt levels and options
   10372        * ourselves, so we don't get false claims of references to
   10373        * uninitialized memory (such as padding in structures) and *do*
   10374        * check what pointers in the argument point to.
   10375        */
   10376       if (arg1 == VKI_SOL_SOCKET && arg2 == VKI_SO_ATTACH_FILTER)
   10377       {
   10378          struct vki_sock_fprog *fp = (struct vki_sock_fprog *)optval_p;
   10379 
   10380          /*
   10381           * struct sock_fprog has a 16-bit count of instructions,
   10382           * followed by a pointer to an array of those instructions.
   10383           * There's padding between those two elements.
   10384           *
   10385           * So that we don't bogusly complain about the padding bytes,
   10386           * we just report that we read len and and filter.
   10387           *
   10388           * We then make sure that what filter points to is valid.
   10389           */
   10390          PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, &optval.len)",
   10391                        (Addr)&fp->len, sizeof(fp->len) );
   10392          PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, &optval.filter)",
   10393                        (Addr)&fp->filter, sizeof(fp->filter) );
   10394 
   10395          /* len * sizeof (*filter) */
   10396          if (fp->filter != NULL)
   10397          {
   10398             PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, optval.filter)",
   10399                           (Addr)(fp->filter),
   10400                           fp->len * sizeof(*fp->filter) );
   10401          }
   10402       }
   10403       else
   10404       {
   10405          PRE_MEM_READ( "socketcall.setsockopt(optval)",
   10406                        arg3, /* optval */
   10407                        arg4  /* optlen */ );
   10408       }
   10409    }
   10410 }
   10411 
   10412 void
   10413 ML_(linux_PRE_sys_recvmmsg) ( ThreadId tid,
   10414                               UWord arg1, UWord arg2, UWord arg3,
   10415                               UWord arg4, UWord arg5 )
   10416 {
   10417    struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)arg2;
   10418    HChar name[40];     // large enough
   10419    UInt i;
   10420    for (i = 0; i < arg3; i++) {
   10421       VG_(sprintf)(name, "mmsg[%u].msg_hdr", i);
   10422       ML_(generic_PRE_sys_recvmsg)(tid, name, &mmsg[i].msg_hdr);
   10423       VG_(sprintf)(name, "recvmmsg(mmsg[%u].msg_len)", i);
   10424       PRE_MEM_WRITE( name, (Addr)&mmsg[i].msg_len, sizeof(mmsg[i].msg_len) );
   10425    }
   10426    if (arg5)
   10427       PRE_MEM_READ( "recvmmsg(timeout)", arg5, sizeof(struct vki_timespec) );
   10428 }
   10429 
   10430 void
   10431 ML_(linux_POST_sys_recvmmsg) (ThreadId tid, UWord res,
   10432                               UWord arg1, UWord arg2, UWord arg3,
   10433                               UWord arg4, UWord arg5 )
   10434 {
   10435    if (res > 0) {
   10436       struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)arg2;
   10437       HChar name[32];    // large enough
   10438       UInt i;
   10439       for (i = 0; i < res; i++) {
   10440          VG_(sprintf)(name, "mmsg[%u].msg_hdr", i);
   10441          ML_(generic_POST_sys_recvmsg)(tid, name, &mmsg[i].msg_hdr, mmsg[i].msg_len);
   10442          POST_MEM_WRITE( (Addr)&mmsg[i].msg_len, sizeof(mmsg[i].msg_len) );
   10443       }
   10444    }
   10445 }
   10446 
   10447 void
   10448 ML_(linux_PRE_sys_sendmmsg) ( ThreadId tid,
   10449                               UWord arg1, UWord arg2, UWord arg3, UWord arg4 )
   10450 {
   10451    struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)arg2;
   10452    HChar name[40];     // large enough
   10453    UInt i;
   10454    for (i = 0; i < arg3; i++) {
   10455       VG_(sprintf)(name, "mmsg[%u].msg_hdr", i);
   10456       ML_(generic_PRE_sys_sendmsg)(tid, name, &mmsg[i].msg_hdr);
   10457       VG_(sprintf)(name, "sendmmsg(mmsg[%u].msg_len)", i);
   10458       PRE_MEM_WRITE( name, (Addr)&mmsg[i].msg_len, sizeof(mmsg[i].msg_len) );
   10459    }
   10460 }
   10461 
   10462 void
   10463 ML_(linux_POST_sys_sendmmsg) (ThreadId tid, UWord res,
   10464                               UWord arg1, UWord arg2, UWord arg3, UWord arg4 )
   10465 {
   10466    if (res > 0) {
   10467       struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)arg2;
   10468       UInt i;
   10469       for (i = 0; i < res; i++) {
   10470          POST_MEM_WRITE( (Addr)&mmsg[i].msg_len, sizeof(mmsg[i].msg_len) );
   10471       }
   10472    }
   10473 }
   10474 
   10475 /* ---------------------------------------------------------------------
   10476    ptrace wrapper helpers
   10477    ------------------------------------------------------------------ */
   10478 
   10479 void
   10480 ML_(linux_PRE_getregset) ( ThreadId tid, long arg3, long arg4 )
   10481 {
   10482    struct vki_iovec *iov = (struct vki_iovec *) arg4;
   10483 
   10484    PRE_MEM_READ("ptrace(getregset iovec->iov_base)",
   10485 		(unsigned long) &iov->iov_base, sizeof(iov->iov_base));
   10486    PRE_MEM_READ("ptrace(getregset iovec->iov_len)",
   10487 		(unsigned long) &iov->iov_len, sizeof(iov->iov_len));
   10488    PRE_MEM_WRITE("ptrace(getregset *(iovec->iov_base))",
   10489 		 (unsigned long) iov->iov_base, iov->iov_len);
   10490 }
   10491 
   10492 void
   10493 ML_(linux_PRE_setregset) ( ThreadId tid, long arg3, long arg4 )
   10494 {
   10495    struct vki_iovec *iov = (struct vki_iovec *) arg4;
   10496 
   10497    PRE_MEM_READ("ptrace(setregset iovec->iov_base)",
   10498 		(unsigned long) &iov->iov_base, sizeof(iov->iov_base));
   10499    PRE_MEM_READ("ptrace(setregset iovec->iov_len)",
   10500 		(unsigned long) &iov->iov_len, sizeof(iov->iov_len));
   10501    PRE_MEM_READ("ptrace(setregset *(iovec->iov_base))",
   10502 		(unsigned long) iov->iov_base, iov->iov_len);
   10503 }
   10504 
   10505 void
   10506 ML_(linux_POST_getregset) ( ThreadId tid, long arg3, long arg4 )
   10507 {
   10508    struct vki_iovec *iov = (struct vki_iovec *) arg4;
   10509 
   10510    /* XXX: The actual amount of data written by the kernel might be
   10511       less than iov_len, depending on the regset (arg3). */
   10512    POST_MEM_WRITE((unsigned long) iov->iov_base, iov->iov_len);
   10513 }
   10514 
   10515 PRE(sys_kcmp)
   10516 {
   10517    PRINT("kcmp ( %ld, %ld, %ld, %lu, %lu )", SARG1, SARG2, SARG3, ARG4, ARG5);
   10518    switch (ARG3) {
   10519       case VKI_KCMP_VM: case VKI_KCMP_FILES: case VKI_KCMP_FS:
   10520       case VKI_KCMP_SIGHAND: case VKI_KCMP_IO: case VKI_KCMP_SYSVSEM:
   10521          /* Most of the comparison types don't look at |idx1| or
   10522             |idx2|. */
   10523          PRE_REG_READ3(long, "kcmp",
   10524                        vki_pid_t, pid1, vki_pid_t, pid2, int, type);
   10525          break;
   10526       case VKI_KCMP_FILE:
   10527       default:
   10528          PRE_REG_READ5(long, "kcmp",
   10529                        vki_pid_t, pid1, vki_pid_t, pid2, int, type,
   10530                        unsigned long, idx1, unsigned long, idx2);
   10531          break;
   10532    }
   10533 }
   10534 
   10535 #undef PRE
   10536 #undef POST
   10537 
   10538 #endif // defined(VGO_linux)
   10539 
   10540 /*--------------------------------------------------------------------*/
   10541 /*--- end                                                          ---*/
   10542 /*--------------------------------------------------------------------*/
   10543