Home | History | Annotate | Download | only in m_syswrap
      1 
      2 /*--------------------------------------------------------------------*/
      3 /*--- Platform-specific syscalls stuff.      syswrap-s390x-linux.c ---*/
      4 /*--------------------------------------------------------------------*/
      5 
      6 /*
      7    This file is part of Valgrind, a dynamic binary instrumentation
      8    framework.
      9 
     10    Copyright IBM Corp. 2010-2011
     11 
     12    This program is free software; you can redistribute it and/or
     13    modify it under the terms of the GNU General Public License as
     14    published by the Free Software Foundation; either version 2 of the
     15    License, or (at your option) any later version.
     16 
     17    This program is distributed in the hope that it will be useful, but
     18    WITHOUT ANY WARRANTY; without even the implied warranty of
     19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     20    General Public License for more details.
     21 
     22    You should have received a copy of the GNU General Public License
     23    along with this program; if not, write to the Free Software
     24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
     25    02111-1307, USA.
     26 
     27    The GNU General Public License is contained in the file COPYING.
     28 */
     29 
     30 /* Contributed by Christian Borntraeger */
     31 
     32 #if defined(VGP_s390x_linux)
     33 
     34 #include "pub_core_basics.h"
     35 #include "pub_core_vki.h"
     36 #include "pub_core_vkiscnums.h"
     37 #include "pub_core_libcsetjmp.h"    // to keep _threadstate.h happy
     38 #include "pub_core_threadstate.h"
     39 #include "pub_core_aspacemgr.h"
     40 #include "pub_core_debuglog.h"
     41 #include "pub_core_libcbase.h"
     42 #include "pub_core_libcassert.h"
     43 #include "pub_core_libcprint.h"
     44 #include "pub_core_libcproc.h"
     45 #include "pub_core_libcsignal.h"
     46 #include "pub_core_mallocfree.h"
     47 #include "pub_core_options.h"
     48 #include "pub_core_scheduler.h"
     49 #include "pub_core_sigframe.h"      // For VG_(sigframe_destroy)()
     50 #include "pub_core_signals.h"
     51 #include "pub_core_syscall.h"
     52 #include "pub_core_syswrap.h"
     53 #include "pub_core_tooliface.h"
     54 #include "pub_core_stacks.h"        // VG_(register_stack)
     55 
     56 #include "priv_types_n_macros.h"
     57 #include "priv_syswrap-generic.h"    /* for decls of generic wrappers */
     58 #include "priv_syswrap-linux.h"      /* for decls of linux-ish wrappers */
     59 #include "priv_syswrap-linux-variants.h" /* decls of linux variant wrappers */
     60 #include "priv_syswrap-main.h"
     61 
     62 
     63 /* ---------------------------------------------------------------------
     64    clone() handling
     65    ------------------------------------------------------------------ */
     66 
     67 /* Call f(arg1), but first switch stacks, using 'stack' as the new
     68    stack, and use 'retaddr' as f's return-to address.  Also, clear all
     69    the integer registers before entering f.
     70    Thought: Why are we clearing the GPRs ? The callee pointed to by f
     71    is a regular C function which will play by the ABI rules. So there is
     72    no need to zero out the GPRs. If we assumed that f accesses registers at
     73    will, then it would make sense to create a defined register state.
     74    But then, why only for the GPRs and not the FPRs ? */
     75 __attribute__((noreturn))
     76 void ML_(call_on_new_stack_0_1) ( Addr stack,
     77                                   Addr retaddr,
     78                                   void (*f)(Word),
     79                                   Word arg1 );
     80 /* Upon entering this function we have the following setup:
     81      r2 = stack
     82      r3 = retaddr
     83      r4 = f_desc
     84      r5 = arg1
     85 */
     86 asm(
     87     ".text\n"
     88     ".align 4\n"
     89     ".globl vgModuleLocal_call_on_new_stack_0_1\n"
     90     ".type vgModuleLocal_call_on_new_stack_0_1, @function\n"
     91     "vgModuleLocal_call_on_new_stack_0_1:\n"
     92     "   lgr %r15,%r2\n"     // stack to r15
     93     "   lgr %r14,%r3\n"     // retaddr to r14
     94     "   lgr %r2,%r5\n"      // arg1 to r2
     95     // zero all gprs to get a defined state
     96     "   lghi  %r0,0\n"
     97     "   lghi  %r1,0\n"
     98     // r2 holds the argument for the callee
     99     "   lghi  %r3,0\n"
    100     // r4 holds the callee address
    101     "   lghi  %r5,0\n"
    102     "   lghi  %r6,0\n"
    103     "   lghi  %r7,0\n"
    104     "   lghi  %r8,0\n"
    105     "   lghi  %r9,0\n"
    106     "   lghi  %r10,0\n"
    107     "   lghi  %r11,0\n"
    108     "   lghi  %r12,0\n"
    109     "   lghi  %r13,0\n"
    110     // r14 holds the return address for the callee
    111     // r15 is the stack pointer
    112     "   br  %r4\n"          // jump to f
    113     ".previous\n"
    114     );
    115 
    116 /*
    117         Perform a clone system call.  clone is strange because it has
    118         fork()-like return-twice semantics, so it needs special
    119         handling here.
    120 
    121         Upon entry, we have:
    122             void*  child_stack   in r2
    123             long   flags         in r3
    124             int*   parent_tid    in r4
    125             int*   child_tid     in r5
    126             int*   child_tid     in r6
    127             Word   (*fn)(void *) 160(r15)
    128             void   *arg          168(r15)
    129 
    130         System call requires:
    131             void*  child_stack  in r2  (sc arg1)
    132             long   flags        in r3  (sc arg2)
    133             int*   parent_tid   in r4  (sc arg3)
    134             int*   child_tid    in r5  (sc arg4)
    135             void*  tlsaddr      in r6  (sc arg5)
    136 
    137         Returns a ULong encoded as: top half is %cr following syscall,
    138         low half is syscall return value (r3).
    139  */
    140 #define __NR_CLONE        VG_STRINGIFY(__NR_clone)
    141 #define __NR_EXIT         VG_STRINGIFY(__NR_exit)
    142 
    143 extern
    144 ULong do_syscall_clone_s390x_linux ( void  *stack,
    145                                      ULong flags,
    146                                      Int   *child_tid,
    147                                      Int   *parent_tid,
    148                                      Addr  tlsaddr,
    149                                      Word (*fn)(void *),
    150                                      void  *arg);
    151 asm(
    152    "   .text\n"
    153    "   .align  4\n"
    154    "do_syscall_clone_s390x_linux:\n"
    155    "   lg    %r1, 160(%r15)\n"   // save fn from parent stack into r1
    156    "   lg    %r0, 168(%r15)\n"   // save arg from parent stack into r0
    157    "   aghi  %r2, -160\n"        // create stack frame for child
    158    // all syscall parameters are already in place (r2-r6)
    159    "   svc " __NR_CLONE"\n"        // clone()
    160    "   ltgr  %r2,%r2\n"           // child if retval == 0
    161    "   jne   1f\n"
    162 
    163    // CHILD - call thread function
    164    "   lgr   %r2, %r0\n"            // get arg from r0
    165    "   basr  %r14,%r1\n"            // call fn
    166 
    167    // exit. The result is already in r2
    168    "   svc " __NR_EXIT"\n"
    169 
    170    // Exit returned?!
    171    "   j +2\n"
    172 
    173    "1:\n"  // PARENT or ERROR
    174    "   br %r14\n"
    175    ".previous\n"
    176 );
    177 
    178 #undef __NR_CLONE
    179 #undef __NR_EXIT
    180 
    181 void VG_(cleanup_thread) ( ThreadArchState* arch )
    182 {
    183   /* only used on x86 for descriptor tables */
    184 }
    185 
    186 static void setup_child ( /*OUT*/ ThreadArchState *child,
    187                    /*IN*/  ThreadArchState *parent )
    188 {
    189    /* We inherit our parent's guest state. */
    190    child->vex = parent->vex;
    191    child->vex_shadow1 = parent->vex_shadow1;
    192    child->vex_shadow2 = parent->vex_shadow2;
    193 }
    194 
    195 
    196 /*
    197    When a client clones, we need to keep track of the new thread.  This means:
    198    1. allocate a ThreadId+ThreadState+stack for the the thread
    199 
    200    2. initialize the thread's new VCPU state
    201 
    202    3. create the thread using the same args as the client requested,
    203    but using the scheduler entrypoint for IP, and a separate stack
    204    for SP.
    205  */
    206 static SysRes do_clone ( ThreadId ptid,
    207                          Addr sp, ULong flags,
    208                          Int *parent_tidptr,
    209                          Int *child_tidptr,
    210                          Addr tlsaddr)
    211 {
    212    static const Bool debug = False;
    213 
    214    ThreadId     ctid = VG_(alloc_ThreadState)();
    215    ThreadState* ptst = VG_(get_ThreadState)(ptid);
    216    ThreadState* ctst = VG_(get_ThreadState)(ctid);
    217    UWord*       stack;
    218    NSegment const* seg;
    219    SysRes       res;
    220    ULong        r2;
    221    vki_sigset_t blockall, savedmask;
    222 
    223    VG_(sigfillset)(&blockall);
    224 
    225    vg_assert(VG_(is_running_thread)(ptid));
    226    vg_assert(VG_(is_valid_tid)(ctid));
    227 
    228    stack = (UWord*)ML_(allocstack)(ctid);
    229    if (stack == NULL) {
    230       res = VG_(mk_SysRes_Error)( VKI_ENOMEM );
    231       goto out;
    232    }
    233 
    234    /* Copy register state
    235 
    236       Both parent and child return to the same place, and the code
    237       following the clone syscall works out which is which, so we
    238       don't need to worry about it.
    239 
    240       The parent gets the child's new tid returned from clone, but the
    241       child gets 0.
    242 
    243       If the clone call specifies a NULL sp for the new thread, then
    244       it actually gets a copy of the parent's sp.
    245    */
    246    setup_child( &ctst->arch, &ptst->arch );
    247 
    248    /* Make sys_clone appear to have returned Success(0) in the
    249       child. */
    250    ctst->arch.vex.guest_r2 = 0;
    251 
    252    if (sp != 0)
    253       ctst->arch.vex.guest_r15 = sp;
    254 
    255    ctst->os_state.parent = ptid;
    256 
    257    /* inherit signal mask */
    258    ctst->sig_mask = ptst->sig_mask;
    259    ctst->tmp_sig_mask = ptst->sig_mask;
    260 
    261    /* have the parents thread group */
    262    ctst->os_state.threadgroup = ptst->os_state.threadgroup;
    263 
    264    /* We don't really know where the client stack is, because its
    265       allocated by the client.  The best we can do is look at the
    266       memory mappings and try to derive some useful information.  We
    267       assume that esp starts near its highest possible value, and can
    268       only go down to the start of the mmaped segment. */
    269    seg = VG_(am_find_nsegment)((Addr)sp);
    270    if (seg && seg->kind != SkResvn) {
    271       ctst->client_stack_highest_word = (Addr)VG_PGROUNDUP(sp);
    272       ctst->client_stack_szB = ctst->client_stack_highest_word - seg->start;
    273 
    274       VG_(register_stack)(seg->start, ctst->client_stack_highest_word);
    275 
    276       if (debug)
    277 	 VG_(printf)("tid %d: guessed client stack range %#lx-%#lx\n",
    278 		     ctid, seg->start, VG_PGROUNDUP(sp));
    279    } else {
    280       VG_(message)(Vg_UserMsg,
    281                    "!? New thread %d starts with SP(%#lx) unmapped\n",
    282 		   ctid, sp);
    283       ctst->client_stack_szB  = 0;
    284    }
    285 
    286    /* Assume the clone will succeed, and tell any tool that wants to
    287       know that this thread has come into existence.  If the clone
    288       fails, we'll send out a ll_exit notification for it at the out:
    289       label below, to clean up. */
    290    VG_TRACK ( pre_thread_ll_create, ptid, ctid );
    291 
    292    if (flags & VKI_CLONE_SETTLS) {
    293       if (debug)
    294 	 VG_(printf)("clone child has SETTLS: tls at %#lx\n", tlsaddr);
    295       ctst->arch.vex.guest_a0 = (UInt) (tlsaddr >> 32);
    296       ctst->arch.vex.guest_a1 = (UInt) tlsaddr;
    297    }
    298    flags &= ~VKI_CLONE_SETTLS;
    299 
    300    /* start the thread with everything blocked */
    301    VG_(sigprocmask)(VKI_SIG_SETMASK, &blockall, &savedmask);
    302 
    303    /* Create the new thread */
    304    r2 = do_syscall_clone_s390x_linux(
    305             stack, flags, child_tidptr, parent_tidptr, tlsaddr,
    306             ML_(start_thread_NORETURN), &VG_(threads)[ctid]);
    307 
    308    res = VG_(mk_SysRes_s390x_linux)( r2 );
    309 
    310    VG_(sigprocmask)(VKI_SIG_SETMASK, &savedmask, NULL);
    311 
    312   out:
    313    if (sr_isError(res)) {
    314       /* clone failed */
    315       ctst->status = VgTs_Empty;
    316       /* oops.  Better tell the tool the thread exited in a hurry :-) */
    317       VG_TRACK( pre_thread_ll_exit, ctid );
    318    }
    319 
    320    return res;
    321 
    322 }
    323 
    324 
    325 
    326 /* ---------------------------------------------------------------------
    327    PRE/POST wrappers for s390x/Linux-specific syscalls
    328    ------------------------------------------------------------------ */
    329 
    330 #define PRE(name)       DEFN_PRE_TEMPLATE(s390x_linux, name)
    331 #define POST(name)      DEFN_POST_TEMPLATE(s390x_linux, name)
    332 
    333 /* Add prototypes for the wrappers declared here, so that gcc doesn't
    334    harass us for not having prototypes.  Really this is a kludge --
    335    the right thing to do is to make these wrappers 'static' since they
    336    aren't visible outside this file, but that requires even more macro
    337    magic. */
    338 
    339 DECL_TEMPLATE(s390x_linux, sys_ptrace);
    340 DECL_TEMPLATE(s390x_linux, sys_socketcall);
    341 DECL_TEMPLATE(s390x_linux, sys_mmap);
    342 DECL_TEMPLATE(s390x_linux, sys_ipc);
    343 DECL_TEMPLATE(s390x_linux, sys_clone);
    344 DECL_TEMPLATE(s390x_linux, sys_sigreturn);
    345 DECL_TEMPLATE(s390x_linux, sys_rt_sigreturn);
    346 DECL_TEMPLATE(s390x_linux, sys_fadvise64);
    347 
    348 // PEEK TEXT,DATA and USER are common to all architectures
    349 // PEEKUSR_AREA and POKEUSR_AREA are special, having a memory area
    350 // containing the real addr, data, and len field pointed to by ARG3
    351 // instead of ARG4
    352 PRE(sys_ptrace)
    353 {
    354    PRINT("sys_ptrace ( %ld, %ld, %#lx, %#lx )", ARG1,ARG2,ARG3,ARG4);
    355    PRE_REG_READ4(int, "ptrace",
    356                  long, request, long, pid, long, addr, long, data);
    357    switch (ARG1) {
    358    case VKI_PTRACE_PEEKTEXT:
    359    case VKI_PTRACE_PEEKDATA:
    360    case VKI_PTRACE_PEEKUSR:
    361       PRE_MEM_WRITE( "ptrace(peek)", ARG4,
    362 		     sizeof (long));
    363       break;
    364    case VKI_PTRACE_GETEVENTMSG:
    365       PRE_MEM_WRITE( "ptrace(geteventmsg)", ARG4, sizeof(unsigned long));
    366       break;
    367    case VKI_PTRACE_GETSIGINFO:
    368       PRE_MEM_WRITE( "ptrace(getsiginfo)", ARG4, sizeof(vki_siginfo_t));
    369       break;
    370    case VKI_PTRACE_SETSIGINFO:
    371       PRE_MEM_READ( "ptrace(setsiginfo)", ARG4, sizeof(vki_siginfo_t));
    372       break;
    373    case VKI_PTRACE_PEEKUSR_AREA:
    374       {
    375          vki_ptrace_area *pa;
    376 
    377          /* Reads a part of the user area into memory at pa->process_addr */
    378 	 pa = (vki_ptrace_area *) ARG3;
    379          PRE_MEM_READ("ptrace(peekusrarea ptrace_area->len)",
    380                       (unsigned long) &pa->vki_len, sizeof(pa->vki_len));
    381          PRE_MEM_READ("ptrace(peekusrarea ptrace_area->kernel_addr)",
    382                       (unsigned long) &pa->vki_kernel_addr, sizeof(pa->vki_kernel_addr));
    383          PRE_MEM_READ("ptrace(peekusrarea ptrace_area->process_addr)",
    384                       (unsigned long) &pa->vki_process_addr, sizeof(pa->vki_process_addr));
    385          PRE_MEM_WRITE("ptrace(peekusrarea *(ptrace_area->process_addr))",
    386                        pa->vki_process_addr, pa->vki_len);
    387          break;
    388       }
    389    case VKI_PTRACE_POKEUSR_AREA:
    390       {
    391          vki_ptrace_area *pa;
    392 
    393          /* Updates a part of the user area from memory at pa->process_addr */
    394 	 pa = (vki_ptrace_area *) ARG3;
    395          PRE_MEM_READ("ptrace(pokeusrarea ptrace_area->len)",
    396                       (unsigned long) &pa->vki_len, sizeof(pa->vki_len));
    397          PRE_MEM_READ("ptrace(pokeusrarea ptrace_area->kernel_addr)",
    398                       (unsigned long) &pa->vki_kernel_addr,
    399                       sizeof(pa->vki_kernel_addr));
    400          PRE_MEM_READ("ptrace(pokeusrarea ptrace_area->process_addr)",
    401                       (unsigned long) &pa->vki_process_addr,
    402                       sizeof(pa->vki_process_addr));
    403          PRE_MEM_READ("ptrace(pokeusrarea *(ptrace_area->process_addr))",
    404                        pa->vki_process_addr, pa->vki_len);
    405          break;
    406       }
    407    default:
    408       break;
    409    }
    410 }
    411 
    412 POST(sys_ptrace)
    413 {
    414    switch (ARG1) {
    415    case VKI_PTRACE_PEEKTEXT:
    416    case VKI_PTRACE_PEEKDATA:
    417    case VKI_PTRACE_PEEKUSR:
    418       POST_MEM_WRITE( ARG4, sizeof (long));
    419       break;
    420    case VKI_PTRACE_GETEVENTMSG:
    421       POST_MEM_WRITE( ARG4, sizeof(unsigned long));
    422       break;
    423    case VKI_PTRACE_GETSIGINFO:
    424       /* XXX: This is a simplification. Different parts of the
    425        * siginfo_t are valid depending on the type of signal.
    426        */
    427       POST_MEM_WRITE( ARG4, sizeof(vki_siginfo_t));
    428       break;
    429    case VKI_PTRACE_PEEKUSR_AREA:
    430       {
    431          vki_ptrace_area *pa;
    432 
    433 	 pa = (vki_ptrace_area *) ARG3;
    434          POST_MEM_WRITE(pa->vki_process_addr, pa->vki_len);
    435       }
    436    default:
    437       break;
    438    }
    439 }
    440 
    441 
    442 PRE(sys_socketcall)
    443 {
    444 #  define ARG2_0  (((UWord*)ARG2)[0])
    445 #  define ARG2_1  (((UWord*)ARG2)[1])
    446 #  define ARG2_2  (((UWord*)ARG2)[2])
    447 #  define ARG2_3  (((UWord*)ARG2)[3])
    448 #  define ARG2_4  (((UWord*)ARG2)[4])
    449 #  define ARG2_5  (((UWord*)ARG2)[5])
    450 
    451    *flags |= SfMayBlock;
    452    PRINT("sys_socketcall ( %ld, %#lx )",ARG1,ARG2);
    453    PRE_REG_READ2(long, "socketcall", int, call, unsigned long *, args);
    454 
    455    switch (ARG1 /* request */) {
    456 
    457    case VKI_SYS_SOCKETPAIR:
    458      /* int socketpair(int d, int type, int protocol, int sv[2]); */
    459       PRE_MEM_READ( "socketcall.socketpair(args)", ARG2, 4*sizeof(Addr) );
    460       if (!ML_(valid_client_addr)(ARG2, 4*sizeof(Addr), tid, NULL)) {
    461          SET_STATUS_Failure( VKI_EFAULT );
    462          break;
    463       }
    464       ML_(generic_PRE_sys_socketpair)( tid, ARG2_0, ARG2_1, ARG2_2, ARG2_3 );
    465       break;
    466 
    467    case VKI_SYS_SOCKET:
    468      /* int socket(int domain, int type, int protocol); */
    469       PRE_MEM_READ( "socketcall.socket(args)", ARG2, 3*sizeof(Addr) );
    470       if (!ML_(valid_client_addr)(ARG2, 3*sizeof(Addr), tid, NULL)) {
    471          SET_STATUS_Failure( VKI_EFAULT );
    472          break;
    473       }
    474       break;
    475 
    476    case VKI_SYS_BIND:
    477      /* int bind(int sockfd, struct sockaddr *my_addr,
    478 	int addrlen); */
    479       PRE_MEM_READ( "socketcall.bind(args)", ARG2, 3*sizeof(Addr) );
    480       if (!ML_(valid_client_addr)(ARG2, 3*sizeof(Addr), tid, NULL)) {
    481          SET_STATUS_Failure( VKI_EFAULT );
    482          break;
    483       }
    484       ML_(generic_PRE_sys_bind)( tid, ARG2_0, ARG2_1, ARG2_2 );
    485       break;
    486 
    487    case VKI_SYS_LISTEN:
    488      /* int listen(int s, int backlog); */
    489       PRE_MEM_READ( "socketcall.listen(args)", ARG2, 2*sizeof(Addr) );
    490       if (!ML_(valid_client_addr)(ARG2, 2*sizeof(Addr), tid, NULL)) {
    491          SET_STATUS_Failure( VKI_EFAULT );
    492          break;
    493       }
    494       break;
    495 
    496    case VKI_SYS_ACCEPT: {
    497      /* int accept(int s, struct sockaddr *addr, int *addrlen); */
    498       PRE_MEM_READ( "socketcall.accept(args)", ARG2, 3*sizeof(Addr) );
    499       if (!ML_(valid_client_addr)(ARG2, 3*sizeof(Addr), tid, NULL)) {
    500          SET_STATUS_Failure( VKI_EFAULT );
    501          break;
    502       }
    503       ML_(generic_PRE_sys_accept)( tid, ARG2_0, ARG2_1, ARG2_2 );
    504       break;
    505    }
    506 
    507    case VKI_SYS_SENDTO:
    508      /* int sendto(int s, const void *msg, int len,
    509                     unsigned int flags,
    510                     const struct sockaddr *to, int tolen); */
    511      PRE_MEM_READ( "socketcall.sendto(args)", ARG2, 6*sizeof(Addr) );
    512      if (!ML_(valid_client_addr)(ARG2, 6*sizeof(Addr), tid, NULL)) {
    513          SET_STATUS_Failure( VKI_EFAULT );
    514          break;
    515      }
    516      ML_(generic_PRE_sys_sendto)( tid, ARG2_0, ARG2_1, ARG2_2,
    517 				  ARG2_3, ARG2_4, ARG2_5 );
    518      break;
    519 
    520    case VKI_SYS_SEND:
    521      /* int send(int s, const void *msg, size_t len, int flags); */
    522      PRE_MEM_READ( "socketcall.send(args)", ARG2, 4*sizeof(Addr) );
    523      if (!ML_(valid_client_addr)(ARG2, 4*sizeof(Addr), tid, NULL)) {
    524          SET_STATUS_Failure( VKI_EFAULT );
    525          break;
    526      }
    527      ML_(generic_PRE_sys_send)( tid, ARG2_0, ARG2_1, ARG2_2 );
    528      break;
    529 
    530    case VKI_SYS_RECVFROM:
    531      /* int recvfrom(int s, void *buf, int len, unsigned int flags,
    532 	struct sockaddr *from, int *fromlen); */
    533      PRE_MEM_READ( "socketcall.recvfrom(args)", ARG2, 6*sizeof(Addr) );
    534      if (!ML_(valid_client_addr)(ARG2, 6*sizeof(Addr), tid, NULL)) {
    535          SET_STATUS_Failure( VKI_EFAULT );
    536          break;
    537      }
    538      ML_(generic_PRE_sys_recvfrom)( tid, ARG2_0, ARG2_1, ARG2_2,
    539 				    ARG2_3, ARG2_4, ARG2_5 );
    540      break;
    541 
    542    case VKI_SYS_RECV:
    543      /* int recv(int s, void *buf, int len, unsigned int flags); */
    544      /* man 2 recv says:
    545          The  recv call is normally used only on a connected socket
    546          (see connect(2)) and is identical to recvfrom with a  NULL
    547          from parameter.
    548      */
    549      PRE_MEM_READ( "socketcall.recv(args)", ARG2, 4*sizeof(Addr) );
    550      if (!ML_(valid_client_addr)(ARG2, 4*sizeof(Addr), tid, NULL)) {
    551          SET_STATUS_Failure( VKI_EFAULT );
    552          break;
    553      }
    554      ML_(generic_PRE_sys_recv)( tid, ARG2_0, ARG2_1, ARG2_2 );
    555      break;
    556 
    557    case VKI_SYS_CONNECT:
    558      /* int connect(int sockfd,
    559 	struct sockaddr *serv_addr, int addrlen ); */
    560      PRE_MEM_READ( "socketcall.connect(args)", ARG2, 3*sizeof(Addr) );
    561      if (!ML_(valid_client_addr)(ARG2, 3*sizeof(Addr), tid, NULL)) {
    562          SET_STATUS_Failure( VKI_EFAULT );
    563          break;
    564      }
    565      ML_(generic_PRE_sys_connect)( tid, ARG2_0, ARG2_1, ARG2_2 );
    566      break;
    567 
    568    case VKI_SYS_SETSOCKOPT:
    569      /* int setsockopt(int s, int level, int optname,
    570 	const void *optval, int optlen); */
    571      PRE_MEM_READ( "socketcall.setsockopt(args)", ARG2, 5*sizeof(Addr) );
    572      if (!ML_(valid_client_addr)(ARG2, 5*sizeof(Addr), tid, NULL)) {
    573          SET_STATUS_Failure( VKI_EFAULT );
    574          break;
    575      }
    576      ML_(generic_PRE_sys_setsockopt)( tid, ARG2_0, ARG2_1, ARG2_2,
    577 				      ARG2_3, ARG2_4 );
    578      break;
    579 
    580    case VKI_SYS_GETSOCKOPT:
    581      /* int getsockopt(int s, int level, int optname,
    582 	void *optval, socklen_t *optlen); */
    583      PRE_MEM_READ( "socketcall.getsockopt(args)", ARG2, 5*sizeof(Addr) );
    584      if (!ML_(valid_client_addr)(ARG2, 5*sizeof(Addr), tid, NULL)) {
    585          SET_STATUS_Failure( VKI_EFAULT );
    586          break;
    587      }
    588      ML_(linux_PRE_sys_getsockopt)( tid, ARG2_0, ARG2_1, ARG2_2,
    589 				      ARG2_3, ARG2_4 );
    590      break;
    591 
    592    case VKI_SYS_GETSOCKNAME:
    593      /* int getsockname(int s, struct sockaddr* name, int* namelen) */
    594      PRE_MEM_READ( "socketcall.getsockname(args)", ARG2, 3*sizeof(Addr) );
    595      if (!ML_(valid_client_addr)(ARG2, 3*sizeof(Addr), tid, NULL)) {
    596          SET_STATUS_Failure( VKI_EFAULT );
    597          break;
    598      }
    599      ML_(generic_PRE_sys_getsockname)( tid, ARG2_0, ARG2_1, ARG2_2 );
    600      break;
    601 
    602    case VKI_SYS_GETPEERNAME:
    603      /* int getpeername(int s, struct sockaddr* name, int* namelen) */
    604      PRE_MEM_READ( "socketcall.getpeername(args)", ARG2, 3*sizeof(Addr) );
    605      if (!ML_(valid_client_addr)(ARG2, 3*sizeof(Addr), tid, NULL)) {
    606          SET_STATUS_Failure( VKI_EFAULT );
    607          break;
    608      }
    609      ML_(generic_PRE_sys_getpeername)( tid, ARG2_0, ARG2_1, ARG2_2 );
    610      break;
    611 
    612    case VKI_SYS_SHUTDOWN:
    613      /* int shutdown(int s, int how); */
    614      PRE_MEM_READ( "socketcall.shutdown(args)", ARG2, 2*sizeof(Addr) );
    615      if (!ML_(valid_client_addr)(ARG2, 2*sizeof(Addr), tid, NULL)) {
    616          SET_STATUS_Failure( VKI_EFAULT );
    617          break;
    618      }
    619      break;
    620 
    621    case VKI_SYS_SENDMSG: {
    622      /* int sendmsg(int s, const struct msghdr *msg, int flags); */
    623      PRE_MEM_READ( "socketcall.sendmsg(args)", ARG2, 3*sizeof(Addr) );
    624      if (!ML_(valid_client_addr)(ARG2, 3*sizeof(Addr), tid, NULL)) {
    625          SET_STATUS_Failure( VKI_EFAULT );
    626          break;
    627      }
    628      ML_(generic_PRE_sys_sendmsg)( tid, ARG2_0, ARG2_1 );
    629      break;
    630    }
    631 
    632    case VKI_SYS_RECVMSG: {
    633      /* int recvmsg(int s, struct msghdr *msg, int flags); */
    634      PRE_MEM_READ("socketcall.recvmsg(args)", ARG2, 3*sizeof(Addr) );
    635      if (!ML_(valid_client_addr)(ARG2, 3*sizeof(Addr), tid, NULL)) {
    636          SET_STATUS_Failure( VKI_EFAULT );
    637          break;
    638      }
    639      ML_(generic_PRE_sys_recvmsg)( tid, ARG2_0, ARG2_1 );
    640      break;
    641    }
    642 
    643    default:
    644      VG_(message)(Vg_DebugMsg,"Warning: unhandled socketcall 0x%lx\n",ARG1);
    645      SET_STATUS_Failure( VKI_EINVAL );
    646      break;
    647    }
    648 #  undef ARG2_0
    649 #  undef ARG2_1
    650 #  undef ARG2_2
    651 #  undef ARG2_3
    652 #  undef ARG2_4
    653 #  undef ARG2_5
    654 }
    655 
    656 POST(sys_socketcall)
    657 {
    658 #  define ARG2_0  (((UWord*)ARG2)[0])
    659 #  define ARG2_1  (((UWord*)ARG2)[1])
    660 #  define ARG2_2  (((UWord*)ARG2)[2])
    661 #  define ARG2_3  (((UWord*)ARG2)[3])
    662 #  define ARG2_4  (((UWord*)ARG2)[4])
    663 #  define ARG2_5  (((UWord*)ARG2)[5])
    664 
    665   SysRes r;
    666   vg_assert(SUCCESS);
    667   switch (ARG1 /* request */) {
    668 
    669   case VKI_SYS_SOCKETPAIR:
    670     r = ML_(generic_POST_sys_socketpair)(
    671 					 tid, VG_(mk_SysRes_Success)(RES),
    672 					 ARG2_0, ARG2_1, ARG2_2, ARG2_3
    673 					 );
    674     SET_STATUS_from_SysRes(r);
    675     break;
    676 
    677   case VKI_SYS_SOCKET:
    678     r = ML_(generic_POST_sys_socket)( tid, VG_(mk_SysRes_Success)(RES) );
    679     SET_STATUS_from_SysRes(r);
    680     break;
    681 
    682   case VKI_SYS_BIND:
    683     /* int bind(int sockfd, struct sockaddr *my_addr,
    684        int addrlen); */
    685     break;
    686 
    687   case VKI_SYS_LISTEN:
    688     /* int listen(int s, int backlog); */
    689     break;
    690 
    691   case VKI_SYS_ACCEPT:
    692     /* int accept(int s, struct sockaddr *addr, int *addrlen); */
    693     r = ML_(generic_POST_sys_accept)( tid, VG_(mk_SysRes_Success)(RES),
    694 				      ARG2_0, ARG2_1, ARG2_2 );
    695     SET_STATUS_from_SysRes(r);
    696     break;
    697 
    698   case VKI_SYS_SENDTO:
    699     break;
    700 
    701   case VKI_SYS_SEND:
    702     break;
    703 
    704   case VKI_SYS_RECVFROM:
    705     ML_(generic_POST_sys_recvfrom)( tid, VG_(mk_SysRes_Success)(RES),
    706 				    ARG2_0, ARG2_1, ARG2_2,
    707 				    ARG2_3, ARG2_4, ARG2_5 );
    708     break;
    709 
    710   case VKI_SYS_RECV:
    711     ML_(generic_POST_sys_recv)( tid, RES, ARG2_0, ARG2_1, ARG2_2 );
    712     break;
    713 
    714   case VKI_SYS_CONNECT:
    715     break;
    716 
    717   case VKI_SYS_SETSOCKOPT:
    718     break;
    719 
    720   case VKI_SYS_GETSOCKOPT:
    721     ML_(linux_POST_sys_getsockopt)( tid, VG_(mk_SysRes_Success)(RES),
    722 				      ARG2_0, ARG2_1,
    723 				      ARG2_2, ARG2_3, ARG2_4 );
    724     break;
    725 
    726   case VKI_SYS_GETSOCKNAME:
    727     ML_(generic_POST_sys_getsockname)( tid, VG_(mk_SysRes_Success)(RES),
    728 				       ARG2_0, ARG2_1, ARG2_2 );
    729     break;
    730 
    731   case VKI_SYS_GETPEERNAME:
    732     ML_(generic_POST_sys_getpeername)( tid, VG_(mk_SysRes_Success)(RES),
    733 				       ARG2_0, ARG2_1, ARG2_2 );
    734     break;
    735 
    736   case VKI_SYS_SHUTDOWN:
    737     break;
    738 
    739   case VKI_SYS_SENDMSG:
    740     break;
    741 
    742   case VKI_SYS_RECVMSG:
    743     ML_(generic_POST_sys_recvmsg)( tid, ARG2_0, ARG2_1 );
    744     break;
    745 
    746   default:
    747     VG_(message)(Vg_DebugMsg,"FATAL: unhandled socketcall 0x%lx\n",ARG1);
    748     VG_(core_panic)("... bye!\n");
    749     break; /*NOTREACHED*/
    750   }
    751 #  undef ARG2_0
    752 #  undef ARG2_1
    753 #  undef ARG2_2
    754 #  undef ARG2_3
    755 #  undef ARG2_4
    756 #  undef ARG2_5
    757 }
    758 
    759 PRE(sys_mmap)
    760 {
    761    UWord a0, a1, a2, a3, a4, a5;
    762    SysRes r;
    763 
    764    UWord* args = (UWord*)ARG1;
    765    PRE_REG_READ1(long, "sys_mmap", struct mmap_arg_struct *, args);
    766    PRE_MEM_READ( "sys_mmap(args)", (Addr) args, 6*sizeof(UWord) );
    767 
    768    a0 = args[0];
    769    a1 = args[1];
    770    a2 = args[2];
    771    a3 = args[3];
    772    a4 = args[4];
    773    a5 = args[5];
    774 
    775    PRINT("sys_mmap ( %#lx, %llu, %ld, %ld, %ld, %ld )",
    776          a0, (ULong)a1, a2, a3, a4, a5 );
    777 
    778    r = ML_(generic_PRE_sys_mmap)( tid, a0, a1, a2, a3, a4, (Off64T)a5 );
    779    SET_STATUS_from_SysRes(r);
    780 }
    781 
    782 static Addr deref_Addr ( ThreadId tid, Addr a, Char* s )
    783 {
    784    Addr* a_p = (Addr*)a;
    785    PRE_MEM_READ( s, (Addr)a_p, sizeof(Addr) );
    786    return *a_p;
    787 }
    788 
    789 PRE(sys_ipc)
    790 {
    791   PRINT("sys_ipc ( %ld, %ld, %ld, %ld, %#lx, %ld )",
    792         ARG1,ARG2,ARG3,ARG4,ARG5,ARG6);
    793   // XXX: this is simplistic -- some args are not used in all circumstances.
    794   PRE_REG_READ6(int, "ipc",
    795 		vki_uint, call, int, first, int, second, int, third,
    796 		void *, ptr, long, fifth)
    797 
    798     switch (ARG1 /* call */) {
    799     case VKI_SEMOP:
    800       ML_(generic_PRE_sys_semop)( tid, ARG2, ARG5, ARG3 );
    801       *flags |= SfMayBlock;
    802       break;
    803     case VKI_SEMGET:
    804       break;
    805     case VKI_SEMCTL:
    806       {
    807 	UWord arg = deref_Addr( tid, ARG5, "semctl(arg)" );
    808 	ML_(generic_PRE_sys_semctl)( tid, ARG2, ARG3, ARG4, arg );
    809 	break;
    810       }
    811     case VKI_SEMTIMEDOP:
    812       ML_(generic_PRE_sys_semtimedop)( tid, ARG2, ARG5, ARG3, ARG6 );
    813       *flags |= SfMayBlock;
    814       break;
    815     case VKI_MSGSND:
    816       ML_(linux_PRE_sys_msgsnd)( tid, ARG2, ARG5, ARG3, ARG4 );
    817       if ((ARG4 & VKI_IPC_NOWAIT) == 0)
    818 	*flags |= SfMayBlock;
    819       break;
    820     case VKI_MSGRCV:
    821       {
    822 	Addr msgp;
    823 	Word msgtyp;
    824 
    825 	msgp = deref_Addr( tid,
    826 			   (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgp),
    827 			   "msgrcv(msgp)" );
    828 	msgtyp = deref_Addr( tid,
    829 			     (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgtyp),
    830 			     "msgrcv(msgp)" );
    831 
    832 	ML_(linux_PRE_sys_msgrcv)( tid, ARG2, msgp, ARG3, msgtyp, ARG4 );
    833 
    834 	if ((ARG4 & VKI_IPC_NOWAIT) == 0)
    835 	  *flags |= SfMayBlock;
    836 	break;
    837       }
    838     case VKI_MSGGET:
    839       break;
    840     case VKI_MSGCTL:
    841       ML_(linux_PRE_sys_msgctl)( tid, ARG2, ARG3, ARG5 );
    842       break;
    843     case VKI_SHMAT:
    844       {
    845 	UWord w;
    846 	PRE_MEM_WRITE( "shmat(raddr)", ARG4, sizeof(Addr) );
    847 	w = ML_(generic_PRE_sys_shmat)( tid, ARG2, ARG5, ARG3 );
    848 	if (w == 0)
    849 	  SET_STATUS_Failure( VKI_EINVAL );
    850 	else
    851 	  ARG5 = w;
    852 	break;
    853       }
    854     case VKI_SHMDT:
    855       if (!ML_(generic_PRE_sys_shmdt)(tid, ARG5))
    856 	SET_STATUS_Failure( VKI_EINVAL );
    857       break;
    858     case VKI_SHMGET:
    859       break;
    860     case VKI_SHMCTL: /* IPCOP_shmctl */
    861       ML_(generic_PRE_sys_shmctl)( tid, ARG2, ARG3, ARG5 );
    862       break;
    863     default:
    864       VG_(message)(Vg_DebugMsg, "FATAL: unhandled syscall(ipc) %ld", ARG1 );
    865       VG_(core_panic)("... bye!\n");
    866       break; /*NOTREACHED*/
    867     }
    868 }
    869 
    870 POST(sys_ipc)
    871 {
    872   vg_assert(SUCCESS);
    873   switch (ARG1 /* call */) {
    874   case VKI_SEMOP:
    875   case VKI_SEMGET:
    876     break;
    877   case VKI_SEMCTL:
    878     {
    879       UWord arg = deref_Addr( tid, ARG5, "semctl(arg)" );
    880       ML_(generic_PRE_sys_semctl)( tid, ARG2, ARG3, ARG4, arg );
    881       break;
    882     }
    883   case VKI_SEMTIMEDOP:
    884   case VKI_MSGSND:
    885     break;
    886   case VKI_MSGRCV:
    887     {
    888       Addr msgp;
    889       Word msgtyp;
    890 
    891       msgp = deref_Addr( tid,
    892                          (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgp),
    893                          "msgrcv(msgp)" );
    894       msgtyp = deref_Addr( tid,
    895                            (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgtyp),
    896                            "msgrcv(msgp)" );
    897 
    898       ML_(linux_POST_sys_msgrcv)( tid, RES, ARG2, msgp, ARG3, msgtyp, ARG4 );
    899       break;
    900     }
    901   case VKI_MSGGET:
    902     break;
    903   case VKI_MSGCTL:
    904     ML_(linux_POST_sys_msgctl)( tid, RES, ARG2, ARG3, ARG5 );
    905     break;
    906   case VKI_SHMAT:
    907     {
    908       Addr addr;
    909 
    910       /* force readability. before the syscall it is
    911        * indeed uninitialized, as can be seen in
    912        * glibc/sysdeps/unix/sysv/linux/shmat.c */
    913       POST_MEM_WRITE( ARG4, sizeof( Addr ) );
    914 
    915       addr = deref_Addr ( tid, ARG4, "shmat(addr)" );
    916       ML_(generic_POST_sys_shmat)( tid, addr, ARG2, ARG5, ARG3 );
    917       break;
    918     }
    919   case VKI_SHMDT:
    920     ML_(generic_POST_sys_shmdt)( tid, RES, ARG5 );
    921     break;
    922   case VKI_SHMGET:
    923     break;
    924   case VKI_SHMCTL:
    925     ML_(generic_POST_sys_shmctl)( tid, RES, ARG2, ARG3, ARG5 );
    926     break;
    927   default:
    928     VG_(message)(Vg_DebugMsg,
    929 		 "FATAL: unhandled syscall(ipc) %ld",
    930 		 ARG1 );
    931     VG_(core_panic)("... bye!\n");
    932     break; /*NOTREACHED*/
    933   }
    934 }
    935 
    936 PRE(sys_clone)
    937 {
    938    UInt cloneflags;
    939 
    940    PRINT("sys_clone ( %lx, %#lx, %#lx, %#lx, %#lx )",ARG1,ARG2,ARG3,ARG4, ARG5);
    941    PRE_REG_READ2(int, "clone",
    942                  void *,        child_stack,
    943                  unsigned long, flags);
    944 
    945    if (ARG2 & VKI_CLONE_PARENT_SETTID) {
    946       if (VG_(tdict).track_pre_reg_read)
    947          PRA3("clone(parent_tidptr)", int *, parent_tidptr);
    948       PRE_MEM_WRITE("clone(parent_tidptr)", ARG3, sizeof(Int));
    949       if (!VG_(am_is_valid_for_client)(ARG3, sizeof(Int),
    950                                              VKI_PROT_WRITE)) {
    951          SET_STATUS_Failure( VKI_EFAULT );
    952          return;
    953       }
    954    }
    955    if (ARG2 & (VKI_CLONE_CHILD_SETTID | VKI_CLONE_CHILD_CLEARTID)) {
    956       if (VG_(tdict).track_pre_reg_read)
    957          PRA4("clone(child_tidptr)", int *, child_tidptr);
    958       PRE_MEM_WRITE("clone(child_tidptr)", ARG4, sizeof(Int));
    959       if (!VG_(am_is_valid_for_client)(ARG4, sizeof(Int),
    960                                              VKI_PROT_WRITE)) {
    961          SET_STATUS_Failure( VKI_EFAULT );
    962          return;
    963       }
    964    }
    965 
    966    cloneflags = ARG2;
    967 
    968    if (!ML_(client_signal_OK)(ARG2 & VKI_CSIGNAL)) {
    969       SET_STATUS_Failure( VKI_EINVAL );
    970       return;
    971    }
    972 
    973    /* Only look at the flags we really care about */
    974    switch (cloneflags & (VKI_CLONE_VM | VKI_CLONE_FS
    975                          | VKI_CLONE_FILES | VKI_CLONE_VFORK)) {
    976    case VKI_CLONE_VM | VKI_CLONE_FS | VKI_CLONE_FILES:
    977       /* thread creation */
    978       SET_STATUS_from_SysRes(
    979          do_clone(tid,
    980                   (Addr)ARG1,   /* child SP */
    981                   ARG2,         /* flags */
    982                   (Int *)ARG3,  /* parent_tidptr */
    983                   (Int *)ARG4, /* child_tidptr */
    984                   (Addr)ARG5)); /*  tlsaddr */
    985       break;
    986 
    987    case VKI_CLONE_VFORK | VKI_CLONE_VM: /* vfork */
    988       /* FALLTHROUGH - assume vfork == fork */
    989       cloneflags &= ~(VKI_CLONE_VFORK | VKI_CLONE_VM);
    990 
    991    case 0: /* plain fork */
    992       SET_STATUS_from_SysRes(
    993          ML_(do_fork_clone)(tid,
    994                        cloneflags,      /* flags */
    995                        (Int *)ARG3,     /* parent_tidptr */
    996                        (Int *)ARG4));   /* child_tidptr */
    997       break;
    998 
    999    default:
   1000       /* should we just ENOSYS? */
   1001       VG_(message)(Vg_UserMsg, "Unsupported clone() flags: 0x%lx", ARG2);
   1002       VG_(message)(Vg_UserMsg, "");
   1003       VG_(message)(Vg_UserMsg, "The only supported clone() uses are:");
   1004       VG_(message)(Vg_UserMsg, " - via a threads library (NPTL)");
   1005       VG_(message)(Vg_UserMsg, " - via the implementation of fork or vfork");
   1006       VG_(unimplemented)
   1007          ("Valgrind does not support general clone().");
   1008    }
   1009 
   1010    if (SUCCESS) {
   1011       if (ARG2 & VKI_CLONE_PARENT_SETTID)
   1012          POST_MEM_WRITE(ARG3, sizeof(Int));
   1013       if (ARG2 & (VKI_CLONE_CHILD_SETTID | VKI_CLONE_CHILD_CLEARTID))
   1014          POST_MEM_WRITE(ARG4, sizeof(Int));
   1015 
   1016       /* Thread creation was successful; let the child have the chance
   1017          to run */
   1018       *flags |= SfYieldAfter;
   1019    }
   1020 }
   1021 
   1022 PRE(sys_sigreturn)
   1023 {
   1024    ThreadState* tst;
   1025    PRINT("sys_sigreturn ( )");
   1026 
   1027    vg_assert(VG_(is_valid_tid)(tid));
   1028    vg_assert(tid >= 1 && tid < VG_N_THREADS);
   1029    vg_assert(VG_(is_running_thread)(tid));
   1030 
   1031    tst = VG_(get_ThreadState)(tid);
   1032 
   1033    /* This is only so that the IA is (might be) useful to report if
   1034       something goes wrong in the sigreturn */
   1035    ML_(fixup_guest_state_to_restart_syscall)(&tst->arch);
   1036 
   1037    /* Restore register state from frame and remove it */
   1038    VG_(sigframe_destroy)(tid, False);
   1039 
   1040    /* Tell the driver not to update the guest state with the "result",
   1041       and set a bogus result to keep it happy. */
   1042    *flags |= SfNoWriteResult;
   1043    SET_STATUS_Success(0);
   1044 
   1045    /* Check to see if any signals arose as a result of this. */
   1046    *flags |= SfPollAfter;
   1047 }
   1048 
   1049 
   1050 PRE(sys_rt_sigreturn)
   1051 {
   1052    /* See comments on PRE(sys_rt_sigreturn) in syswrap-amd64-linux.c for
   1053       an explanation of what follows. */
   1054 
   1055    ThreadState* tst;
   1056    PRINT("sys_rt_sigreturn ( )");
   1057 
   1058    vg_assert(VG_(is_valid_tid)(tid));
   1059    vg_assert(tid >= 1 && tid < VG_N_THREADS);
   1060    vg_assert(VG_(is_running_thread)(tid));
   1061 
   1062    tst = VG_(get_ThreadState)(tid);
   1063 
   1064    /* This is only so that the IA is (might be) useful to report if
   1065       something goes wrong in the sigreturn */
   1066    ML_(fixup_guest_state_to_restart_syscall)(&tst->arch);
   1067 
   1068    /* Restore register state from frame and remove it */
   1069    VG_(sigframe_destroy)(tid, True);
   1070 
   1071    /* Tell the driver not to update the guest state with the "result",
   1072       and set a bogus result to keep it happy. */
   1073    *flags |= SfNoWriteResult;
   1074    SET_STATUS_Success(0);
   1075 
   1076    /* Check to see if any signals arose as a result of this. */
   1077    *flags |= SfPollAfter;
   1078 }
   1079 
   1080 /* we cant use the LINX_ version for 64 bit */
   1081 PRE(sys_fadvise64)
   1082 {
   1083    PRINT("sys_fadvise64 ( %ld, %ld, %ld, %ld )", ARG1,ARG2,ARG3,ARG4);
   1084    PRE_REG_READ4(long, "fadvise64",
   1085                  int, fd, vki_loff_t, offset, vki_loff_t, len, int, advice);
   1086 }
   1087 
   1088 #undef PRE
   1089 #undef POST
   1090 
   1091 /* ---------------------------------------------------------------------
   1092    The s390x/Linux syscall table
   1093    ------------------------------------------------------------------ */
   1094 
   1095 /* Add an s390x-linux specific wrapper to a syscall table. */
   1096 #define PLAX_(sysno, name)    WRAPPER_ENTRY_X_(s390x_linux, sysno, name)
   1097 #define PLAXY(sysno, name)    WRAPPER_ENTRY_XY(s390x_linux, sysno, name)
   1098 
   1099 // This table maps from __NR_xxx syscall numbers from
   1100 // linux/arch/s390/kernel/syscalls.S to the appropriate PRE/POST sys_foo()
   1101 // wrappers on s390x. There are several unused numbers, which are only
   1102 // defined on s390 (31bit mode) but no longer available on s390x (64 bit).
   1103 // For those syscalls not handled by Valgrind, the annotation indicate its
   1104 // arch/OS combination, eg. */* (generic), */Linux (Linux only), ?/?
   1105 // (unknown).
   1106 
   1107 static SyscallTableEntry syscall_table[] = {
   1108    GENX_(0, sys_ni_syscall), /* unimplemented (by the kernel) */      // 0
   1109    GENX_(__NR_exit,  sys_exit),                                       // 1
   1110    GENX_(__NR_fork,  sys_fork),                                       // 2
   1111    GENXY(__NR_read,  sys_read),                                       // 3
   1112    GENX_(__NR_write,  sys_write),                                     // 4
   1113 
   1114    GENXY(__NR_open,  sys_open),                                       // 5
   1115    GENXY(__NR_close,  sys_close),                                     // 6
   1116 // ?????(__NR_restart_syscall, ),                                     // 7
   1117    GENXY(__NR_creat,  sys_creat),                                     // 8
   1118    GENX_(__NR_link,  sys_link),                                       // 9
   1119 
   1120    GENX_(__NR_unlink,  sys_unlink),                                   // 10
   1121    GENX_(__NR_execve,  sys_execve),                                   // 11
   1122    GENX_(__NR_chdir,  sys_chdir),                                     // 12
   1123    GENX_(13, sys_ni_syscall), /* unimplemented (by the kernel) */     // 13
   1124    GENX_(__NR_mknod,  sys_mknod),                                     // 14
   1125 
   1126    GENX_(__NR_chmod,  sys_chmod),                                     // 15
   1127    GENX_(16, sys_ni_syscall), /* unimplemented (by the kernel) */     // 16
   1128    GENX_(17, sys_ni_syscall), /* unimplemented (by the kernel) */     // 17
   1129    GENX_(18, sys_ni_syscall), /* unimplemented (by the kernel) */     // 18
   1130    LINX_(__NR_lseek,  sys_lseek),                                     // 19
   1131 
   1132    GENX_(__NR_getpid,  sys_getpid),                                   // 20
   1133    LINX_(__NR_mount,  sys_mount),                                     // 21
   1134    LINX_(__NR_umount, sys_oldumount),                                 // 22
   1135    GENX_(23, sys_ni_syscall), /* unimplemented (by the kernel) */     // 23
   1136    GENX_(24, sys_ni_syscall), /* unimplemented (by the kernel) */     // 24
   1137 
   1138    GENX_(25, sys_ni_syscall), /* unimplemented (by the kernel) */     // 25
   1139    PLAXY(__NR_ptrace, sys_ptrace),                                    // 26
   1140    GENX_(__NR_alarm,  sys_alarm),                                     // 27
   1141    GENX_(28, sys_ni_syscall), /* unimplemented (by the kernel) */     // 28
   1142    GENX_(__NR_pause,  sys_pause),                                     // 29
   1143 
   1144    LINX_(__NR_utime,  sys_utime),                                     // 30
   1145    GENX_(31, sys_ni_syscall), /* unimplemented (by the kernel) */     // 31
   1146    GENX_(32, sys_ni_syscall), /* unimplemented (by the kernel) */     // 32
   1147    GENX_(__NR_access,  sys_access),                                   // 33
   1148    GENX_(__NR_nice, sys_nice),                                        // 34
   1149 
   1150    GENX_(35, sys_ni_syscall), /* unimplemented (by the kernel) */     // 35
   1151    GENX_(__NR_sync, sys_sync),                                        // 36
   1152    GENX_(__NR_kill,  sys_kill),                                       // 37
   1153    GENX_(__NR_rename,  sys_rename),                                   // 38
   1154    GENX_(__NR_mkdir,  sys_mkdir),                                     // 39
   1155 
   1156    GENX_(__NR_rmdir, sys_rmdir),                                      // 40
   1157    GENXY(__NR_dup,  sys_dup),                                         // 41
   1158    LINXY(__NR_pipe,  sys_pipe),                                       // 42
   1159    GENXY(__NR_times,  sys_times),                                     // 43
   1160    GENX_(44, sys_ni_syscall), /* unimplemented (by the kernel) */     // 44
   1161 
   1162    GENX_(__NR_brk,  sys_brk),                                         // 45
   1163    GENX_(46, sys_ni_syscall), /* unimplemented (by the kernel) */     // 46
   1164    GENX_(47, sys_ni_syscall), /* unimplemented (by the kernel) */     // 47
   1165 // ?????(__NR_signal, ),                                              // 48
   1166    GENX_(49, sys_ni_syscall), /* unimplemented (by the kernel) */     // 49
   1167 
   1168    GENX_(50, sys_ni_syscall), /* unimplemented (by the kernel) */     // 50
   1169    GENX_(__NR_acct, sys_acct),                                        // 51
   1170    LINX_(__NR_umount2, sys_umount),                                   // 52
   1171    GENX_(53, sys_ni_syscall), /* unimplemented (by the kernel) */     // 53
   1172    LINXY(__NR_ioctl,  sys_ioctl),                                     // 54
   1173 
   1174    LINXY(__NR_fcntl,  sys_fcntl),                                     // 55
   1175    GENX_(56, sys_ni_syscall), /* unimplemented (by the kernel) */     // 56
   1176    GENX_(__NR_setpgid,  sys_setpgid),                                 // 57
   1177    GENX_(58, sys_ni_syscall), /* unimplemented (by the kernel) */     // 58
   1178    GENX_(59, sys_ni_syscall), /* unimplemented (by the kernel) */     // 59
   1179 
   1180    GENX_(__NR_umask,  sys_umask),                                     // 60
   1181    GENX_(__NR_chroot,  sys_chroot),                                   // 61
   1182 // ?????(__NR_ustat, sys_ustat), /* deprecated in favor of statfs */  // 62
   1183    GENXY(__NR_dup2,  sys_dup2),                                       // 63
   1184    GENX_(__NR_getppid,  sys_getppid),                                 // 64
   1185 
   1186    GENX_(__NR_getpgrp,  sys_getpgrp),                                 // 65
   1187    GENX_(__NR_setsid,  sys_setsid),                                   // 66
   1188 // ?????(__NR_sigaction, ),   /* userspace uses rt_sigaction */       // 67
   1189    GENX_(68, sys_ni_syscall), /* unimplemented (by the kernel) */     // 68
   1190    GENX_(69, sys_ni_syscall), /* unimplemented (by the kernel) */     // 69
   1191 
   1192    GENX_(70, sys_ni_syscall), /* unimplemented (by the kernel) */     // 70
   1193    GENX_(71, sys_ni_syscall), /* unimplemented (by the kernel) */     // 71
   1194 // ?????(__NR_sigsuspend, ),                                          // 72
   1195 // ?????(__NR_sigpending, ),                                          // 73
   1196 // ?????(__NR_sethostname, ),                                         // 74
   1197 
   1198    GENX_(__NR_setrlimit,  sys_setrlimit),                             // 75
   1199    GENXY(76,  sys_getrlimit), /* see also 191 */                      // 76
   1200    GENXY(__NR_getrusage,  sys_getrusage),                             // 77
   1201    GENXY(__NR_gettimeofday,  sys_gettimeofday),                       // 78
   1202    GENX_(__NR_settimeofday, sys_settimeofday),                        // 79
   1203 
   1204    GENX_(80, sys_ni_syscall), /* unimplemented (by the kernel) */     // 80
   1205    GENX_(81, sys_ni_syscall), /* unimplemented (by the kernel) */     // 81
   1206    GENX_(82, sys_ni_syscall), /* unimplemented (by the kernel) */     // 82
   1207    GENX_(__NR_symlink,  sys_symlink),                                 // 83
   1208    GENX_(84, sys_ni_syscall), /* unimplemented (by the kernel) */     // 84
   1209 
   1210    GENX_(__NR_readlink,  sys_readlink),                               // 85
   1211 // ?????(__NR_uselib, ),                                              // 86
   1212 // ?????(__NR_swapon, ),                                              // 87
   1213 // ?????(__NR_reboot, ),                                              // 88
   1214    GENX_(89, sys_ni_syscall), /* unimplemented (by the kernel) */     // 89
   1215 
   1216    PLAX_(__NR_mmap, sys_mmap ),                                       // 90
   1217    GENXY(__NR_munmap,  sys_munmap),                                   // 91
   1218    GENX_(__NR_truncate,  sys_truncate),                               // 92
   1219    GENX_(__NR_ftruncate,  sys_ftruncate),                             // 93
   1220    GENX_(__NR_fchmod,  sys_fchmod),                                   // 94
   1221 
   1222    GENX_(95, sys_ni_syscall), /* unimplemented (by the kernel) */     // 95
   1223    GENX_(__NR_getpriority, sys_getpriority),                          // 96
   1224    GENX_(__NR_setpriority, sys_setpriority),                          // 97
   1225    GENX_(98, sys_ni_syscall), /* unimplemented (by the kernel) */     // 98
   1226    GENXY(__NR_statfs,  sys_statfs),                                   // 99
   1227 
   1228    GENXY(__NR_fstatfs,  sys_fstatfs),                                 // 100
   1229    GENX_(101, sys_ni_syscall), /* unimplemented (by the kernel) */    // 101
   1230    PLAXY(__NR_socketcall, sys_socketcall),                            // 102
   1231    LINXY(__NR_syslog,  sys_syslog),                                   // 103
   1232    GENXY(__NR_setitimer,  sys_setitimer),                             // 104
   1233 
   1234    GENXY(__NR_getitimer,  sys_getitimer),                             // 105
   1235    GENXY(__NR_stat, sys_newstat),                                     // 106
   1236    GENXY(__NR_lstat, sys_newlstat),                                   // 107
   1237    GENXY(__NR_fstat, sys_newfstat),                                   // 108
   1238    GENX_(109, sys_ni_syscall), /* unimplemented (by the kernel) */    // 109
   1239 
   1240    LINXY(__NR_lookup_dcookie, sys_lookup_dcookie),                    // 110
   1241    LINX_(__NR_vhangup, sys_vhangup),                                  // 111
   1242    GENX_(112, sys_ni_syscall), /* unimplemented (by the kernel) */    // 112
   1243    GENX_(113, sys_ni_syscall), /* unimplemented (by the kernel) */    // 113
   1244    GENXY(__NR_wait4,  sys_wait4),                                     // 114
   1245 
   1246 // ?????(__NR_swapoff, ),                                             // 115
   1247    LINXY(__NR_sysinfo,  sys_sysinfo),                                 // 116
   1248    PLAXY(__NR_ipc, sys_ipc),                                          // 117
   1249    GENX_(__NR_fsync,  sys_fsync),                                     // 118
   1250    PLAX_(__NR_sigreturn, sys_sigreturn),                              // 119
   1251 
   1252    PLAX_(__NR_clone,  sys_clone),                                     // 120
   1253 // ?????(__NR_setdomainname, ),                                       // 121
   1254    GENXY(__NR_uname, sys_newuname),                                   // 122
   1255    GENX_(123, sys_ni_syscall), /* unimplemented (by the kernel) */    // 123
   1256 // ?????(__NR_adjtimex, ),                                            // 124
   1257 
   1258    GENXY(__NR_mprotect,  sys_mprotect),                               // 125
   1259 // LINXY(__NR_sigprocmask, sys_sigprocmask),                          // 126
   1260    GENX_(127, sys_ni_syscall), /* unimplemented (by the kernel) */    // 127
   1261    LINX_(__NR_init_module,  sys_init_module),                         // 128
   1262    LINX_(__NR_delete_module,  sys_delete_module),                     // 129
   1263 
   1264    GENX_(130, sys_ni_syscall), /* unimplemented (by the kernel) */    // 130
   1265    LINX_(__NR_quotactl, sys_quotactl),                                // 131
   1266    GENX_(__NR_getpgid,  sys_getpgid),                                 // 132
   1267    GENX_(__NR_fchdir,  sys_fchdir),                                   // 133
   1268 // ?????(__NR_bdflush, ),                                             // 134
   1269 
   1270 // ?????(__NR_sysfs, ),                                               // 135
   1271    LINX_(__NR_personality, sys_personality),                          // 136
   1272    GENX_(137, sys_ni_syscall), /* unimplemented (by the kernel) */    // 137
   1273    GENX_(138, sys_ni_syscall), /* unimplemented (by the kernel) */    // 138
   1274    GENX_(139, sys_ni_syscall), /* unimplemented (by the kernel) */    // 139
   1275 
   1276 // LINXY(__NR__llseek, sys_llseek), /* 64 bit --> lseek */            // 140
   1277    GENXY(__NR_getdents,  sys_getdents),                               // 141
   1278    GENX_(__NR_select, sys_select),                                    // 142
   1279    GENX_(__NR_flock,  sys_flock),                                     // 143
   1280    GENX_(__NR_msync,  sys_msync),                                     // 144
   1281 
   1282    GENXY(__NR_readv,  sys_readv),                                     // 145
   1283    GENX_(__NR_writev,  sys_writev),                                   // 146
   1284    GENX_(__NR_getsid, sys_getsid),                                    // 147
   1285    GENX_(__NR_fdatasync,  sys_fdatasync),                             // 148
   1286    LINXY(__NR__sysctl, sys_sysctl),                                   // 149
   1287 
   1288    GENX_(__NR_mlock,  sys_mlock),                                     // 150
   1289    GENX_(__NR_munlock,  sys_munlock),                                 // 151
   1290    GENX_(__NR_mlockall,  sys_mlockall),                               // 152
   1291    LINX_(__NR_munlockall,  sys_munlockall),                           // 153
   1292    LINXY(__NR_sched_setparam,  sys_sched_setparam),                   // 154
   1293 
   1294    LINXY(__NR_sched_getparam,  sys_sched_getparam),                   // 155
   1295    LINX_(__NR_sched_setscheduler,  sys_sched_setscheduler),           // 156
   1296    LINX_(__NR_sched_getscheduler,  sys_sched_getscheduler),           // 157
   1297    LINX_(__NR_sched_yield,  sys_sched_yield),                         // 158
   1298    LINX_(__NR_sched_get_priority_max,  sys_sched_get_priority_max),   // 159
   1299 
   1300    LINX_(__NR_sched_get_priority_min,  sys_sched_get_priority_min),   // 160
   1301 // ?????(__NR_sched_rr_get_interval, ),                               // 161
   1302    GENXY(__NR_nanosleep,  sys_nanosleep),                             // 162
   1303    GENX_(__NR_mremap,  sys_mremap),                                   // 163
   1304    GENX_(164, sys_ni_syscall), /* unimplemented (by the kernel) */    // 164
   1305 
   1306    GENX_(165, sys_ni_syscall), /* unimplemented (by the kernel) */    // 165
   1307    GENX_(166, sys_ni_syscall), /* unimplemented (by the kernel) */    // 166
   1308    GENX_(167, sys_ni_syscall), /* unimplemented (by the kernel) */    // 167
   1309    GENXY(__NR_poll,  sys_poll),                                       // 168
   1310 // ?????(__NR_nfsservctl, ),                                          // 169
   1311 
   1312    GENX_(170, sys_ni_syscall), /* unimplemented (by the kernel) */    // 170
   1313    GENX_(171, sys_ni_syscall), /* unimplemented (by the kernel) */    // 171
   1314    LINXY(__NR_prctl, sys_prctl),                                      // 172
   1315    PLAX_(__NR_rt_sigreturn,  sys_rt_sigreturn),                       // 173
   1316    LINXY(__NR_rt_sigaction,  sys_rt_sigaction),                       // 174
   1317 
   1318    LINXY(__NR_rt_sigprocmask,  sys_rt_sigprocmask),                   // 175
   1319    LINXY(__NR_rt_sigpending, sys_rt_sigpending),                      // 176
   1320    LINXY(__NR_rt_sigtimedwait,  sys_rt_sigtimedwait),                 // 177
   1321    LINXY(__NR_rt_sigqueueinfo, sys_rt_sigqueueinfo),                  // 178
   1322    LINX_(__NR_rt_sigsuspend, sys_rt_sigsuspend),                      // 179
   1323 
   1324    GENXY(__NR_pread64,  sys_pread64),                                 // 180
   1325    GENX_(__NR_pwrite64, sys_pwrite64),                                // 181
   1326    GENX_(182, sys_ni_syscall), /* unimplemented (by the kernel) */    // 182
   1327    GENXY(__NR_getcwd,  sys_getcwd),                                   // 183
   1328    LINXY(__NR_capget,  sys_capget),                                   // 184
   1329 
   1330    LINX_(__NR_capset,  sys_capset),                                   // 185
   1331    GENXY(__NR_sigaltstack,  sys_sigaltstack),                         // 186
   1332    LINXY(__NR_sendfile, sys_sendfile),                                // 187
   1333    GENX_(188, sys_ni_syscall), /* unimplemented (by the kernel) */    // 188
   1334    GENX_(189, sys_ni_syscall), /* unimplemented (by the kernel) */    // 189
   1335 
   1336    GENX_(__NR_vfork,  sys_fork),                                      // 190
   1337    GENXY(__NR_getrlimit,  sys_getrlimit),                             // 191
   1338    GENX_(192, sys_ni_syscall), /* not exported on 64bit*/             // 192
   1339    GENX_(193, sys_ni_syscall), /* unimplemented (by the kernel) */    // 193
   1340    GENX_(194, sys_ni_syscall), /* unimplemented (by the kernel) */    // 194
   1341 
   1342    GENX_(195, sys_ni_syscall), /* unimplemented (by the kernel) */    // 195
   1343    GENX_(196, sys_ni_syscall), /* unimplemented (by the kernel) */    // 196
   1344    GENX_(197, sys_ni_syscall), /* unimplemented (by the kernel) */    // 197
   1345    GENX_(__NR_lchown, sys_lchown),                                    // 198
   1346    GENX_(__NR_getuid, sys_getuid),                                    // 199
   1347 
   1348    GENX_(__NR_getgid, sys_getgid),                                    // 200
   1349    GENX_(__NR_geteuid, sys_geteuid),                                  // 201
   1350    GENX_(__NR_getegid, sys_getegid),                                  // 202
   1351    GENX_(__NR_setreuid, sys_setreuid),                                // 203
   1352    GENX_(__NR_setregid, sys_setregid),                                // 204
   1353 
   1354    GENXY(__NR_getgroups, sys_getgroups),                              // 205
   1355    GENX_(__NR_setgroups, sys_setgroups),                              // 206
   1356    GENX_(__NR_fchown, sys_fchown),                                    // 207
   1357    LINX_(__NR_setresuid, sys_setresuid),                              // 208
   1358    LINXY(__NR_getresuid, sys_getresuid),                              // 209
   1359 
   1360    LINX_(__NR_setresgid, sys_setresgid),                              // 210
   1361    LINXY(__NR_getresgid, sys_getresgid),                              // 211
   1362    GENX_(__NR_chown, sys_chown),                                      // 212
   1363    GENX_(__NR_setuid, sys_setuid),                                    // 213
   1364    GENX_(__NR_setgid, sys_setgid),                                    // 214
   1365 
   1366    LINX_(__NR_setfsuid, sys_setfsuid),                                // 215
   1367    LINX_(__NR_setfsgid, sys_setfsgid),                                // 216
   1368 // ?????(__NR_pivot_root, ),
   1369    GENXY(__NR_mincore, sys_mincore),                                  // 218
   1370    GENX_(__NR_madvise,  sys_madvise),                                 // 219
   1371 
   1372    GENXY(__NR_getdents64,  sys_getdents64),                           // 220
   1373    GENX_(221, sys_ni_syscall), /* unimplemented (by the kernel) */    // 221
   1374    LINX_(__NR_readahead, sys_readahead),                              // 222
   1375    GENX_(223, sys_ni_syscall), /* unimplemented (by the kernel) */    // 223
   1376    LINX_(__NR_setxattr, sys_setxattr),                                // 224
   1377 
   1378    LINX_(__NR_lsetxattr, sys_lsetxattr),                              // 225
   1379    LINX_(__NR_fsetxattr, sys_fsetxattr),                              // 226
   1380    LINXY(__NR_getxattr,  sys_getxattr),                               // 227
   1381    LINXY(__NR_lgetxattr,  sys_lgetxattr),                             // 228
   1382    LINXY(__NR_fgetxattr,  sys_fgetxattr),                             // 229
   1383 
   1384    LINXY(__NR_listxattr,  sys_listxattr),                             // 230
   1385    LINXY(__NR_llistxattr,  sys_llistxattr),                           // 231
   1386    LINXY(__NR_flistxattr,  sys_flistxattr),                           // 232
   1387    LINX_(__NR_removexattr,  sys_removexattr),                         // 233
   1388    LINX_(__NR_lremovexattr,  sys_lremovexattr),                       // 234
   1389 
   1390    LINX_(__NR_fremovexattr,  sys_fremovexattr),                       // 235
   1391    LINX_(__NR_gettid,  sys_gettid),                                   // 236
   1392    LINXY(__NR_tkill, sys_tkill),                                      // 237
   1393    LINXY(__NR_futex,  sys_futex),                                     // 238
   1394    LINX_(__NR_sched_setaffinity,  sys_sched_setaffinity),             // 239
   1395 
   1396    LINXY(__NR_sched_getaffinity,  sys_sched_getaffinity),             // 240
   1397    LINXY(__NR_tgkill, sys_tgkill),                                    // 241
   1398    GENX_(242, sys_ni_syscall), /* unimplemented (by the kernel) */    // 242
   1399    LINXY(__NR_io_setup, sys_io_setup),                                // 243
   1400    LINX_(__NR_io_destroy,  sys_io_destroy),                           // 244
   1401 
   1402    LINXY(__NR_io_getevents,  sys_io_getevents),                       // 245
   1403    LINX_(__NR_io_submit,  sys_io_submit),                             // 246
   1404    LINXY(__NR_io_cancel,  sys_io_cancel),                             // 247
   1405    LINX_(__NR_exit_group,  sys_exit_group),                           // 248
   1406    LINXY(__NR_epoll_create,  sys_epoll_create),                       // 249
   1407 
   1408    LINX_(__NR_epoll_ctl,  sys_epoll_ctl),                             // 250
   1409    LINXY(__NR_epoll_wait,  sys_epoll_wait),                           // 251
   1410    LINX_(__NR_set_tid_address,  sys_set_tid_address),                 // 252
   1411    PLAX_(__NR_fadvise64, sys_fadvise64),                              // 253
   1412    LINXY(__NR_timer_create,  sys_timer_create),                       // 254
   1413 
   1414    LINXY(__NR_timer_settime,  sys_timer_settime),                     // 255
   1415    LINXY(__NR_timer_gettime,  sys_timer_gettime),                     // 256
   1416    LINX_(__NR_timer_getoverrun,  sys_timer_getoverrun),               // 257
   1417    LINX_(__NR_timer_delete,  sys_timer_delete),                       // 258
   1418    LINX_(__NR_clock_settime,  sys_clock_settime),                     // 259
   1419 
   1420    LINXY(__NR_clock_gettime,  sys_clock_gettime),                     // 260
   1421    LINXY(__NR_clock_getres,  sys_clock_getres),                       // 261
   1422    LINXY(__NR_clock_nanosleep,  sys_clock_nanosleep),                 // 262
   1423    GENX_(263, sys_ni_syscall), /* unimplemented (by the kernel) */    // 263
   1424    GENX_(264, sys_ni_syscall), /* unimplemented (by the kernel) */    // 264
   1425 
   1426    GENXY(__NR_statfs64, sys_statfs64),                                // 265
   1427    GENXY(__NR_fstatfs64, sys_fstatfs64),                              // 266
   1428 // ?????(__NR_remap_file_pages, ),
   1429    GENX_(268, sys_ni_syscall), /* unimplemented (by the kernel) */    // 268
   1430    GENX_(269, sys_ni_syscall), /* unimplemented (by the kernel) */    // 269
   1431 
   1432    GENX_(270, sys_ni_syscall), /* unimplemented (by the kernel) */    // 270
   1433    LINXY(__NR_mq_open,  sys_mq_open),                                 // 271
   1434    LINX_(__NR_mq_unlink,  sys_mq_unlink),                             // 272
   1435    LINX_(__NR_mq_timedsend,  sys_mq_timedsend),                       // 273
   1436    LINXY(__NR_mq_timedreceive, sys_mq_timedreceive),                  // 274
   1437 
   1438    LINX_(__NR_mq_notify,  sys_mq_notify),                             // 275
   1439    LINXY(__NR_mq_getsetattr,  sys_mq_getsetattr),                     // 276
   1440 // ?????(__NR_kexec_load, ),
   1441    LINX_(__NR_add_key,  sys_add_key),                                 // 278
   1442    LINX_(__NR_request_key,  sys_request_key),                         // 279
   1443 
   1444    LINXY(__NR_keyctl,  sys_keyctl),                                   // 280
   1445    LINXY(__NR_waitid, sys_waitid),                                    // 281
   1446    LINX_(__NR_ioprio_set,  sys_ioprio_set),                           // 282
   1447    LINX_(__NR_ioprio_get,  sys_ioprio_get),                           // 283
   1448    LINX_(__NR_inotify_init,  sys_inotify_init),                       // 284
   1449 
   1450    LINX_(__NR_inotify_add_watch,  sys_inotify_add_watch),             // 285
   1451    LINX_(__NR_inotify_rm_watch,  sys_inotify_rm_watch),               // 286
   1452    GENX_(287, sys_ni_syscall), /* unimplemented (by the kernel) */    // 287
   1453    LINXY(__NR_openat,  sys_openat),                                   // 288
   1454    LINX_(__NR_mkdirat,  sys_mkdirat),                                 // 289
   1455 
   1456    LINX_(__NR_mknodat,  sys_mknodat),                                 // 290
   1457    LINX_(__NR_fchownat,  sys_fchownat),                               // 291
   1458    LINX_(__NR_futimesat,  sys_futimesat),                             // 292
   1459    LINXY(__NR_newfstatat, sys_newfstatat),                            // 293
   1460    LINX_(__NR_unlinkat,  sys_unlinkat),                               // 294
   1461 
   1462    LINX_(__NR_renameat,  sys_renameat),                               // 295
   1463    LINX_(__NR_linkat,  sys_linkat),                                   // 296
   1464    LINX_(__NR_symlinkat,  sys_symlinkat),                             // 297
   1465    LINX_(__NR_readlinkat,  sys_readlinkat),                           // 298
   1466    LINX_(__NR_fchmodat,  sys_fchmodat),                               // 299
   1467 
   1468    LINX_(__NR_faccessat,  sys_faccessat),                             // 300
   1469    LINX_(__NR_pselect6, sys_pselect6),                                // 301
   1470    LINXY(__NR_ppoll, sys_ppoll),                                      // 302
   1471 // ?????(__NR_unshare, ),
   1472    LINX_(__NR_set_robust_list,  sys_set_robust_list),                 // 304
   1473 
   1474    LINXY(__NR_get_robust_list,  sys_get_robust_list),                 // 305
   1475 // ?????(__NR_splice, ),
   1476    LINX_(__NR_sync_file_range, sys_sync_file_range),                  // 307
   1477 // ?????(__NR_tee, ),
   1478 // ?????(__NR_vmsplice, ),
   1479 
   1480    GENX_(310, sys_ni_syscall), /* unimplemented (by the kernel) */    // 310
   1481 // ?????(__NR_getcpu, ),
   1482    LINXY(__NR_epoll_pwait,  sys_epoll_pwait),                         // 312
   1483    GENX_(__NR_utimes, sys_utimes),                                    // 313
   1484    LINX_(__NR_fallocate, sys_fallocate),                              // 314
   1485 
   1486    LINX_(__NR_utimensat,  sys_utimensat),                             // 315
   1487    LINXY(__NR_signalfd,  sys_signalfd),                               // 316
   1488    GENX_(317, sys_ni_syscall), /* unimplemented (by the kernel) */    // 317
   1489    LINX_(__NR_eventfd,  sys_eventfd),                                 // 318
   1490    LINXY(__NR_timerfd_create,  sys_timerfd_create),                   // 319
   1491 
   1492    LINXY(__NR_timerfd_settime,  sys_timerfd_settime),                 // 320
   1493    LINXY(__NR_timerfd_gettime,  sys_timerfd_gettime),                 // 321
   1494    LINXY(__NR_signalfd4,  sys_signalfd4),                             // 322
   1495    LINX_(__NR_eventfd2,  sys_eventfd2),                               // 323
   1496    LINXY(__NR_inotify_init1,  sys_inotify_init1),                     // 324
   1497 
   1498    LINXY(__NR_pipe2,  sys_pipe2),                                     // 325
   1499    // (__NR_dup3,  ),
   1500    LINXY(__NR_epoll_create1,  sys_epoll_create1),                     // 327
   1501    LINXY(__NR_preadv, sys_preadv),                                    // 328
   1502    LINX_(__NR_pwritev, sys_pwritev),                                  // 329
   1503 
   1504 // ?????(__NR_rt_tgsigqueueinfo, ),
   1505    LINXY(__NR_perf_event_open, sys_perf_event_open),                  // 331
   1506 };
   1507 
   1508 SyscallTableEntry* ML_(get_linux_syscall_entry) ( UInt sysno )
   1509 {
   1510    const UInt syscall_table_size
   1511       = sizeof(syscall_table) / sizeof(syscall_table[0]);
   1512 
   1513    /* Is it in the contiguous initial section of the table? */
   1514    if (sysno < syscall_table_size) {
   1515       SyscallTableEntry* sys = &syscall_table[sysno];
   1516       if (sys->before == NULL)
   1517          return NULL; /* no entry */
   1518       else
   1519          return sys;
   1520    }
   1521 
   1522    /* Can't find a wrapper */
   1523    return NULL;
   1524 }
   1525 
   1526 #endif
   1527 
   1528 /*--------------------------------------------------------------------*/
   1529 /*--- end                                                          ---*/
   1530 /*--------------------------------------------------------------------*/
   1531