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-2017
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_threadstate.h"
38 #include "pub_core_aspacemgr.h"
39 #include "pub_core_debuglog.h"
40 #include "pub_core_libcbase.h"
41 #include "pub_core_libcassert.h"
42 #include "pub_core_libcprint.h"
43 #include "pub_core_libcproc.h"
44 #include "pub_core_libcsignal.h"
45 #include "pub_core_mallocfree.h"
46 #include "pub_core_options.h"
47 #include "pub_core_scheduler.h"
48 #include "pub_core_sigframe.h"      // For VG_(sigframe_destroy)()
49 #include "pub_core_signals.h"
50 #include "pub_core_syscall.h"
51 #include "pub_core_syswrap.h"
52 #include "pub_core_tooliface.h"
53 
54 #include "priv_types_n_macros.h"
55 #include "priv_syswrap-generic.h"    /* for decls of generic wrappers */
56 #include "priv_syswrap-linux.h"      /* for decls of linux-ish wrappers */
57 #include "priv_syswrap-linux-variants.h" /* decls of linux variant wrappers */
58 #include "priv_syswrap-main.h"
59 
60 
61 /* ---------------------------------------------------------------------
62    clone() handling
63    ------------------------------------------------------------------ */
64 
65 /* Call f(arg1), but first switch stacks, using 'stack' as the new
66    stack, and use 'retaddr' as f's return-to address.  Also, clear all
67    the integer registers before entering f.
68    Thought: Why are we clearing the GPRs ? The callee pointed to by f
69    is a regular C function which will play by the ABI rules. So there is
70    no need to zero out the GPRs. If we assumed that f accesses registers at
71    will, then it would make sense to create a defined register state.
72    But then, why only for the GPRs and not the FPRs ? */
73 __attribute__((noreturn))
74 void ML_(call_on_new_stack_0_1) ( Addr stack,
75                                   Addr retaddr,
76                                   void (*f)(Word),
77                                   Word arg1 );
78 /* Upon entering this function we have the following setup:
79      r2 = stack
80      r3 = retaddr
81      r4 = f_desc
82      r5 = arg1
83 */
84 asm(
85     ".text\n"
86     ".align 4\n"
87     ".globl vgModuleLocal_call_on_new_stack_0_1\n"
88     ".type vgModuleLocal_call_on_new_stack_0_1, @function\n"
89     "vgModuleLocal_call_on_new_stack_0_1:\n"
90     "   lgr %r15,%r2\n"     // stack to r15
91     "   lgr %r14,%r3\n"     // retaddr to r14
92     "   lgr %r2,%r5\n"      // arg1 to r2
93     // zero all gprs to get a defined state
94     "   lghi  %r0,0\n"
95     "   lghi  %r1,0\n"
96     // r2 holds the argument for the callee
97     "   lghi  %r3,0\n"
98     // r4 holds the callee address
99     "   lghi  %r5,0\n"
100     "   lghi  %r6,0\n"
101     "   lghi  %r7,0\n"
102     "   lghi  %r8,0\n"
103     "   lghi  %r9,0\n"
104     "   lghi  %r10,0\n"
105     "   lghi  %r11,0\n"
106     "   lghi  %r12,0\n"
107     "   lghi  %r13,0\n"
108     // r14 holds the return address for the callee
109     // r15 is the stack pointer
110     "   br  %r4\n"          // jump to f
111     ".previous\n"
112     );
113 
114 /*
115         Perform a clone system call.  clone is strange because it has
116         fork()-like return-twice semantics, so it needs special
117         handling here.
118 
119         Upon entry, we have:
120             void*  child_stack   in r2
121             long   flags         in r3
122             int*   parent_tid    in r4
123             int*   child_tid     in r5
124             int*   tls address   in r6
125             Word   (*fn)(void *) 160(r15)
126             void   *arg          168(r15)
127 
128         System call requires:
129             void*  child_stack  in r2  (sc arg1)
130             long   flags        in r3  (sc arg2)
131             int*   parent_tid   in r4  (sc arg3)
132             int*   child_tid    in r5  (sc arg4)
133             void*  tlsaddr      in r6  (sc arg5)
134 
135         Returns a ULong encoded as: top half is %cr following syscall,
136         low half is syscall return value (r3).
137  */
138 #define __NR_CLONE        VG_STRINGIFY(__NR_clone)
139 #define __NR_EXIT         VG_STRINGIFY(__NR_exit)
140 
141 // See priv_syswrap-linux.h for arg profile.
142 asm(
143    "   .text\n"
144    "   .align  4\n"
145    ".globl do_syscall_clone_s390x_linux\n"
146    "do_syscall_clone_s390x_linux:\n"
147    "   lg    %r1, 160(%r15)\n"   // save fn from parent stack into r1
148    "   lg    %r0, 168(%r15)\n"   // save arg from parent stack into r0
149    "   aghi  %r2, -160\n"        // create stack frame for child
150    // all syscall parameters are already in place (r2-r6)
151    "   svc " __NR_CLONE"\n"        // clone()
152    "   ltgr  %r2,%r2\n"           // child if retval == 0
153    "   jne   1f\n"
154 
155    // CHILD - call thread function
156    "   lgr   %r2, %r0\n"            // get arg from r0
157    "   basr  %r14,%r1\n"            // call fn
158 
159    // exit. The result is already in r2
160    "   svc " __NR_EXIT"\n"
161 
162    // Exit returned?!
163    "   j +2\n"
164 
165    "1:\n"  // PARENT or ERROR
166    "   br %r14\n"
167    ".previous\n"
168 );
169 
170 #undef __NR_CLONE
171 #undef __NR_EXIT
172 
VG_(cleanup_thread)173 void VG_(cleanup_thread) ( ThreadArchState* arch )
174 {
175   /* only used on x86 for descriptor tables */
176 }
177 
178 /* ---------------------------------------------------------------------
179    PRE/POST wrappers for s390x/Linux-specific syscalls
180    ------------------------------------------------------------------ */
181 
182 #define PRE(name)       DEFN_PRE_TEMPLATE(s390x_linux, name)
183 #define POST(name)      DEFN_POST_TEMPLATE(s390x_linux, name)
184 
185 /* Add prototypes for the wrappers declared here, so that gcc doesn't
186    harass us for not having prototypes.  Really this is a kludge --
187    the right thing to do is to make these wrappers 'static' since they
188    aren't visible outside this file, but that requires even more macro
189    magic. */
190 
191 DECL_TEMPLATE(s390x_linux, sys_ptrace);
192 DECL_TEMPLATE(s390x_linux, sys_mmap);
193 DECL_TEMPLATE(s390x_linux, sys_sigreturn);
194 DECL_TEMPLATE(s390x_linux, sys_rt_sigreturn);
195 DECL_TEMPLATE(s390x_linux, sys_fadvise64);
196 
197 /* PEEK TEXT,DATA and USER are common to all architectures.
198    PEEKUSR_AREA and POKEUSR_AREA are special, having a memory area
199    containing the real addr, data, and len field pointed to by ARG3
200    instead of ARG4.
201    GETREGSET and SETREGSET use a struct iovec (pointed to by ARG4) for
202    the address and size of the user buffer. */
203 
PRE(sys_ptrace)204 PRE(sys_ptrace)
205 {
206    PRINT("sys_ptrace ( %ld, %ld, %#lx, %#lx )", SARG1, SARG2, ARG3, ARG4);
207    PRE_REG_READ4(int, "ptrace",
208                  long, request, long, pid, unsigned long, addr,
209                  unsigned long, data);
210    switch (ARG1) {
211    case VKI_PTRACE_PEEKTEXT:
212    case VKI_PTRACE_PEEKDATA:
213    case VKI_PTRACE_PEEKUSR:
214       PRE_MEM_WRITE( "ptrace(peek)", ARG4,
215 		     sizeof (long));
216       break;
217    case VKI_PTRACE_GETEVENTMSG:
218       PRE_MEM_WRITE( "ptrace(geteventmsg)", ARG4, sizeof(unsigned long));
219       break;
220    case VKI_PTRACE_GETSIGINFO:
221       PRE_MEM_WRITE( "ptrace(getsiginfo)", ARG4, sizeof(vki_siginfo_t));
222       break;
223    case VKI_PTRACE_SETSIGINFO:
224       PRE_MEM_READ( "ptrace(setsiginfo)", ARG4, sizeof(vki_siginfo_t));
225       break;
226    case VKI_PTRACE_PEEKUSR_AREA:
227       {
228          vki_ptrace_area *pa;
229 
230          /* Reads a part of the user area into memory at pa->process_addr */
231 	 pa = (vki_ptrace_area *) ARG3;
232          PRE_MEM_READ("ptrace(peekusrarea ptrace_area->len)",
233                       (unsigned long) &pa->vki_len, sizeof(pa->vki_len));
234          PRE_MEM_READ("ptrace(peekusrarea ptrace_area->kernel_addr)",
235                       (unsigned long) &pa->vki_kernel_addr, sizeof(pa->vki_kernel_addr));
236          PRE_MEM_READ("ptrace(peekusrarea ptrace_area->process_addr)",
237                       (unsigned long) &pa->vki_process_addr, sizeof(pa->vki_process_addr));
238          PRE_MEM_WRITE("ptrace(peekusrarea *(ptrace_area->process_addr))",
239                        pa->vki_process_addr, pa->vki_len);
240          break;
241       }
242    case VKI_PTRACE_POKEUSR_AREA:
243       {
244          vki_ptrace_area *pa;
245 
246          /* Updates a part of the user area from memory at pa->process_addr */
247 	 pa = (vki_ptrace_area *) ARG3;
248          PRE_MEM_READ("ptrace(pokeusrarea ptrace_area->len)",
249                       (unsigned long) &pa->vki_len, sizeof(pa->vki_len));
250          PRE_MEM_READ("ptrace(pokeusrarea ptrace_area->kernel_addr)",
251                       (unsigned long) &pa->vki_kernel_addr,
252                       sizeof(pa->vki_kernel_addr));
253          PRE_MEM_READ("ptrace(pokeusrarea ptrace_area->process_addr)",
254                       (unsigned long) &pa->vki_process_addr,
255                       sizeof(pa->vki_process_addr));
256          PRE_MEM_READ("ptrace(pokeusrarea *(ptrace_area->process_addr))",
257                        pa->vki_process_addr, pa->vki_len);
258          break;
259       }
260    case VKI_PTRACE_GETREGSET:
261       ML_(linux_PRE_getregset)(tid, ARG3, ARG4);
262       break;
263    case VKI_PTRACE_SETREGSET:
264       ML_(linux_PRE_setregset)(tid, ARG3, ARG4);
265       break;
266    default:
267       break;
268    }
269 }
270 
POST(sys_ptrace)271 POST(sys_ptrace)
272 {
273    switch (ARG1) {
274    case VKI_PTRACE_TRACEME:
275       ML_(linux_POST_traceme)(tid);
276       break;
277    case VKI_PTRACE_PEEKTEXT:
278    case VKI_PTRACE_PEEKDATA:
279    case VKI_PTRACE_PEEKUSR:
280       POST_MEM_WRITE( ARG4, sizeof (long));
281       break;
282    case VKI_PTRACE_GETEVENTMSG:
283       POST_MEM_WRITE( ARG4, sizeof(unsigned long));
284       break;
285    case VKI_PTRACE_GETSIGINFO:
286       /* XXX: This is a simplification. Different parts of the
287        * siginfo_t are valid depending on the type of signal.
288        */
289       POST_MEM_WRITE( ARG4, sizeof(vki_siginfo_t));
290       break;
291    case VKI_PTRACE_PEEKUSR_AREA:
292       {
293          vki_ptrace_area *pa;
294 
295 	 pa = (vki_ptrace_area *) ARG3;
296          POST_MEM_WRITE(pa->vki_process_addr, pa->vki_len);
297 	 break;
298       }
299    case VKI_PTRACE_GETREGSET:
300       ML_(linux_POST_getregset)(tid, ARG3, ARG4);
301       break;
302    default:
303       break;
304    }
305 }
306 
PRE(sys_mmap)307 PRE(sys_mmap)
308 {
309    UWord a0, a1, a2, a3, a4, a5;
310    SysRes r;
311 
312    UWord* args = (UWord*)ARG1;
313    PRE_REG_READ1(long, "sys_mmap", struct mmap_arg_struct *, args);
314    PRE_MEM_READ( "sys_mmap(args)", (Addr) args, 6*sizeof(UWord) );
315 
316    a0 = args[0];
317    a1 = args[1];
318    a2 = args[2];
319    a3 = args[3];
320    a4 = args[4];
321    a5 = args[5];
322 
323    PRINT("sys_mmap ( %#lx, %lu, %ld, %ld, %ld, %ld )",
324          a0, a1, (Word)a2, (Word)a3, (Word)a4, (Word)a5 );
325 
326    r = ML_(generic_PRE_sys_mmap)( tid, a0, a1, a2, a3, a4, (Off64T)a5 );
327    SET_STATUS_from_SysRes(r);
328 }
329 
PRE(sys_sigreturn)330 PRE(sys_sigreturn)
331 {
332    ThreadState* tst;
333    PRINT("sys_sigreturn ( )");
334 
335    vg_assert(VG_(is_valid_tid)(tid));
336    vg_assert(tid >= 1 && tid < VG_N_THREADS);
337    vg_assert(VG_(is_running_thread)(tid));
338 
339    tst = VG_(get_ThreadState)(tid);
340 
341    /* This is only so that the IA is (might be) useful to report if
342       something goes wrong in the sigreturn */
343    ML_(fixup_guest_state_to_restart_syscall)(&tst->arch);
344 
345    /* Restore register state from frame and remove it */
346    VG_(sigframe_destroy)(tid, False);
347 
348    /* Tell the driver not to update the guest state with the "result",
349       and set a bogus result to keep it happy. */
350    *flags |= SfNoWriteResult;
351    SET_STATUS_Success(0);
352 
353    /* Check to see if any signals arose as a result of this. */
354    *flags |= SfPollAfter;
355 }
356 
357 
PRE(sys_rt_sigreturn)358 PRE(sys_rt_sigreturn)
359 {
360    /* See comments on PRE(sys_rt_sigreturn) in syswrap-amd64-linux.c for
361       an explanation of what follows. */
362 
363    ThreadState* tst;
364    PRINT("sys_rt_sigreturn ( )");
365 
366    vg_assert(VG_(is_valid_tid)(tid));
367    vg_assert(tid >= 1 && tid < VG_N_THREADS);
368    vg_assert(VG_(is_running_thread)(tid));
369 
370    tst = VG_(get_ThreadState)(tid);
371 
372    /* This is only so that the IA is (might be) useful to report if
373       something goes wrong in the sigreturn */
374    ML_(fixup_guest_state_to_restart_syscall)(&tst->arch);
375 
376    /* Restore register state from frame and remove it */
377    VG_(sigframe_destroy)(tid, True);
378 
379    /* Tell the driver not to update the guest state with the "result",
380       and set a bogus result to keep it happy. */
381    *flags |= SfNoWriteResult;
382    SET_STATUS_Success(0);
383 
384    /* Check to see if any signals arose as a result of this. */
385    *flags |= SfPollAfter;
386 }
387 
388 /* we cant use the LINX_ version for 64 bit */
PRE(sys_fadvise64)389 PRE(sys_fadvise64)
390 {
391    PRINT("sys_fadvise64 ( %ld, %ld, %ld, %ld )", SARG1, SARG2, SARG3, SARG4);
392    PRE_REG_READ4(long, "fadvise64",
393                  int, fd, vki_loff_t, offset, vki_loff_t, len, int, advice);
394 }
395 
396 #undef PRE
397 #undef POST
398 
399 /* ---------------------------------------------------------------------
400    The s390x/Linux syscall table
401    ------------------------------------------------------------------ */
402 
403 /* Add an s390x-linux specific wrapper to a syscall table. */
404 #define PLAX_(sysno, name)    WRAPPER_ENTRY_X_(s390x_linux, sysno, name)
405 #define PLAXY(sysno, name)    WRAPPER_ENTRY_XY(s390x_linux, sysno, name)
406 
407 // This table maps from __NR_xxx syscall numbers from
408 // linux/arch/s390/kernel/syscalls.S to the appropriate PRE/POST sys_foo()
409 // wrappers on s390x. There are several unused numbers, which are only
410 // defined on s390 (31bit mode) but no longer available on s390x (64 bit).
411 // For those syscalls not handled by Valgrind, the annotation indicate its
412 // arch/OS combination, eg. */* (generic), */Linux (Linux only), ?/?
413 // (unknown).
414 
415 static SyscallTableEntry syscall_table[] = {
416    GENX_(0, sys_ni_syscall), /* unimplemented (by the kernel) */      // 0
417    GENX_(__NR_exit,  sys_exit),                                       // 1
418    GENX_(__NR_fork,  sys_fork),                                       // 2
419    GENXY(__NR_read,  sys_read),                                       // 3
420    GENX_(__NR_write,  sys_write),                                     // 4
421 
422    GENXY(__NR_open,  sys_open),                                       // 5
423    GENXY(__NR_close,  sys_close),                                     // 6
424 // ?????(__NR_restart_syscall, ),                                     // 7
425    GENXY(__NR_creat,  sys_creat),                                     // 8
426    GENX_(__NR_link,  sys_link),                                       // 9
427 
428    GENX_(__NR_unlink,  sys_unlink),                                   // 10
429    GENX_(__NR_execve,  sys_execve),                                   // 11
430    GENX_(__NR_chdir,  sys_chdir),                                     // 12
431    GENX_(13, sys_ni_syscall), /* unimplemented (by the kernel) */     // 13
432    GENX_(__NR_mknod,  sys_mknod),                                     // 14
433 
434    GENX_(__NR_chmod,  sys_chmod),                                     // 15
435    GENX_(16, sys_ni_syscall), /* unimplemented (by the kernel) */     // 16
436    GENX_(17, sys_ni_syscall), /* unimplemented (by the kernel) */     // 17
437    GENX_(18, sys_ni_syscall), /* unimplemented (by the kernel) */     // 18
438    LINX_(__NR_lseek,  sys_lseek),                                     // 19
439 
440    GENX_(__NR_getpid,  sys_getpid),                                   // 20
441    LINX_(__NR_mount,  sys_mount),                                     // 21
442    LINX_(__NR_umount, sys_oldumount),                                 // 22
443    GENX_(23, sys_ni_syscall), /* unimplemented (by the kernel) */     // 23
444    GENX_(24, sys_ni_syscall), /* unimplemented (by the kernel) */     // 24
445 
446    GENX_(25, sys_ni_syscall), /* unimplemented (by the kernel) */     // 25
447    PLAXY(__NR_ptrace, sys_ptrace),                                    // 26
448    GENX_(__NR_alarm,  sys_alarm),                                     // 27
449    GENX_(28, sys_ni_syscall), /* unimplemented (by the kernel) */     // 28
450    GENX_(__NR_pause,  sys_pause),                                     // 29
451 
452    LINX_(__NR_utime,  sys_utime),                                     // 30
453    GENX_(31, sys_ni_syscall), /* unimplemented (by the kernel) */     // 31
454    GENX_(32, sys_ni_syscall), /* unimplemented (by the kernel) */     // 32
455    GENX_(__NR_access,  sys_access),                                   // 33
456    GENX_(__NR_nice, sys_nice),                                        // 34
457 
458    GENX_(35, sys_ni_syscall), /* unimplemented (by the kernel) */     // 35
459    GENX_(__NR_sync, sys_sync),                                        // 36
460    GENX_(__NR_kill,  sys_kill),                                       // 37
461    GENX_(__NR_rename,  sys_rename),                                   // 38
462    GENX_(__NR_mkdir,  sys_mkdir),                                     // 39
463 
464    GENX_(__NR_rmdir, sys_rmdir),                                      // 40
465    GENXY(__NR_dup,  sys_dup),                                         // 41
466    LINXY(__NR_pipe,  sys_pipe),                                       // 42
467    GENXY(__NR_times,  sys_times),                                     // 43
468    GENX_(44, sys_ni_syscall), /* unimplemented (by the kernel) */     // 44
469 
470    GENX_(__NR_brk,  sys_brk),                                         // 45
471    GENX_(46, sys_ni_syscall), /* unimplemented (by the kernel) */     // 46
472    GENX_(47, sys_ni_syscall), /* unimplemented (by the kernel) */     // 47
473 // ?????(__NR_signal, ),                                              // 48
474    GENX_(49, sys_ni_syscall), /* unimplemented (by the kernel) */     // 49
475 
476    GENX_(50, sys_ni_syscall), /* unimplemented (by the kernel) */     // 50
477    GENX_(__NR_acct, sys_acct),                                        // 51
478    LINX_(__NR_umount2, sys_umount),                                   // 52
479    GENX_(53, sys_ni_syscall), /* unimplemented (by the kernel) */     // 53
480    LINXY(__NR_ioctl,  sys_ioctl),                                     // 54
481 
482    LINXY(__NR_fcntl,  sys_fcntl),                                     // 55
483    GENX_(56, sys_ni_syscall), /* unimplemented (by the kernel) */     // 56
484    GENX_(__NR_setpgid,  sys_setpgid),                                 // 57
485    GENX_(58, sys_ni_syscall), /* unimplemented (by the kernel) */     // 58
486    GENX_(59, sys_ni_syscall), /* unimplemented (by the kernel) */     // 59
487 
488    GENX_(__NR_umask,  sys_umask),                                     // 60
489    GENX_(__NR_chroot,  sys_chroot),                                   // 61
490 // ?????(__NR_ustat, sys_ustat), /* deprecated in favor of statfs */  // 62
491    GENXY(__NR_dup2,  sys_dup2),                                       // 63
492    GENX_(__NR_getppid,  sys_getppid),                                 // 64
493 
494    GENX_(__NR_getpgrp,  sys_getpgrp),                                 // 65
495    GENX_(__NR_setsid,  sys_setsid),                                   // 66
496 // ?????(__NR_sigaction, ),   /* userspace uses rt_sigaction */       // 67
497    GENX_(68, sys_ni_syscall), /* unimplemented (by the kernel) */     // 68
498    GENX_(69, sys_ni_syscall), /* unimplemented (by the kernel) */     // 69
499 
500    GENX_(70, sys_ni_syscall), /* unimplemented (by the kernel) */     // 70
501    GENX_(71, sys_ni_syscall), /* unimplemented (by the kernel) */     // 71
502 // ?????(__NR_sigsuspend, ),                                          // 72
503 // ?????(__NR_sigpending, ),                                          // 73
504 // ?????(__NR_sethostname, ),                                         // 74
505 
506    GENX_(__NR_setrlimit,  sys_setrlimit),                             // 75
507    GENXY(76,  sys_getrlimit), /* see also 191 */                      // 76
508    GENXY(__NR_getrusage,  sys_getrusage),                             // 77
509    GENXY(__NR_gettimeofday,  sys_gettimeofday),                       // 78
510    GENX_(__NR_settimeofday, sys_settimeofday),                        // 79
511 
512    GENX_(80, sys_ni_syscall), /* unimplemented (by the kernel) */     // 80
513    GENX_(81, sys_ni_syscall), /* unimplemented (by the kernel) */     // 81
514    GENX_(82, sys_ni_syscall), /* unimplemented (by the kernel) */     // 82
515    GENX_(__NR_symlink,  sys_symlink),                                 // 83
516    GENX_(84, sys_ni_syscall), /* unimplemented (by the kernel) */     // 84
517 
518    GENX_(__NR_readlink,  sys_readlink),                               // 85
519 // ?????(__NR_uselib, ),                                              // 86
520 // ?????(__NR_swapon, ),                                              // 87
521 // ?????(__NR_reboot, ),                                              // 88
522    GENX_(89, sys_ni_syscall), /* unimplemented (by the kernel) */     // 89
523 
524    PLAX_(__NR_mmap, sys_mmap ),                                       // 90
525    GENXY(__NR_munmap,  sys_munmap),                                   // 91
526    GENX_(__NR_truncate,  sys_truncate),                               // 92
527    GENX_(__NR_ftruncate,  sys_ftruncate),                             // 93
528    GENX_(__NR_fchmod,  sys_fchmod),                                   // 94
529 
530    GENX_(95, sys_ni_syscall), /* unimplemented (by the kernel) */     // 95
531    GENX_(__NR_getpriority, sys_getpriority),                          // 96
532    GENX_(__NR_setpriority, sys_setpriority),                          // 97
533    GENX_(98, sys_ni_syscall), /* unimplemented (by the kernel) */     // 98
534    GENXY(__NR_statfs,  sys_statfs),                                   // 99
535 
536    GENXY(__NR_fstatfs,  sys_fstatfs),                                 // 100
537    GENX_(101, sys_ni_syscall), /* unimplemented (by the kernel) */    // 101
538    LINXY(__NR_socketcall, sys_socketcall),                            // 102
539    LINXY(__NR_syslog,  sys_syslog),                                   // 103
540    GENXY(__NR_setitimer,  sys_setitimer),                             // 104
541 
542    GENXY(__NR_getitimer,  sys_getitimer),                             // 105
543    GENXY(__NR_stat, sys_newstat),                                     // 106
544    GENXY(__NR_lstat, sys_newlstat),                                   // 107
545    GENXY(__NR_fstat, sys_newfstat),                                   // 108
546    GENX_(109, sys_ni_syscall), /* unimplemented (by the kernel) */    // 109
547 
548    LINXY(__NR_lookup_dcookie, sys_lookup_dcookie),                    // 110
549    LINX_(__NR_vhangup, sys_vhangup),                                  // 111
550    GENX_(112, sys_ni_syscall), /* unimplemented (by the kernel) */    // 112
551    GENX_(113, sys_ni_syscall), /* unimplemented (by the kernel) */    // 113
552    GENXY(__NR_wait4,  sys_wait4),                                     // 114
553 
554 // ?????(__NR_swapoff, ),                                             // 115
555    LINXY(__NR_sysinfo,  sys_sysinfo),                                 // 116
556    LINXY(__NR_ipc, sys_ipc),                                          // 117
557    GENX_(__NR_fsync,  sys_fsync),                                     // 118
558    PLAX_(__NR_sigreturn, sys_sigreturn),                              // 119
559 
560    LINX_(__NR_clone,  sys_clone),                                     // 120
561 // ?????(__NR_setdomainname, ),                                       // 121
562    GENXY(__NR_uname, sys_newuname),                                   // 122
563    GENX_(123, sys_ni_syscall), /* unimplemented (by the kernel) */    // 123
564 // ?????(__NR_adjtimex, ),                                            // 124
565 
566    GENXY(__NR_mprotect,  sys_mprotect),                               // 125
567 // LINXY(__NR_sigprocmask, sys_sigprocmask),                          // 126
568    GENX_(127, sys_ni_syscall), /* unimplemented (by the kernel) */    // 127
569    LINX_(__NR_init_module,  sys_init_module),                         // 128
570    LINX_(__NR_delete_module,  sys_delete_module),                     // 129
571 
572    GENX_(130, sys_ni_syscall), /* unimplemented (by the kernel) */    // 130
573    LINX_(__NR_quotactl, sys_quotactl),                                // 131
574    GENX_(__NR_getpgid,  sys_getpgid),                                 // 132
575    GENX_(__NR_fchdir,  sys_fchdir),                                   // 133
576 // ?????(__NR_bdflush, ),                                             // 134
577 
578 // ?????(__NR_sysfs, ),                                               // 135
579    LINX_(__NR_personality, sys_personality),                          // 136
580    GENX_(137, sys_ni_syscall), /* unimplemented (by the kernel) */    // 137
581    GENX_(138, sys_ni_syscall), /* unimplemented (by the kernel) */    // 138
582    GENX_(139, sys_ni_syscall), /* unimplemented (by the kernel) */    // 139
583 
584 // LINXY(__NR__llseek, sys_llseek), /* 64 bit --> lseek */            // 140
585    GENXY(__NR_getdents,  sys_getdents),                               // 141
586    GENX_(__NR_select, sys_select),                                    // 142
587    GENX_(__NR_flock,  sys_flock),                                     // 143
588    GENX_(__NR_msync,  sys_msync),                                     // 144
589 
590    GENXY(__NR_readv,  sys_readv),                                     // 145
591    GENX_(__NR_writev,  sys_writev),                                   // 146
592    GENX_(__NR_getsid, sys_getsid),                                    // 147
593    GENX_(__NR_fdatasync,  sys_fdatasync),                             // 148
594    LINXY(__NR__sysctl, sys_sysctl),                                   // 149
595 
596    GENX_(__NR_mlock,  sys_mlock),                                     // 150
597    GENX_(__NR_munlock,  sys_munlock),                                 // 151
598    GENX_(__NR_mlockall,  sys_mlockall),                               // 152
599    LINX_(__NR_munlockall,  sys_munlockall),                           // 153
600    LINXY(__NR_sched_setparam,  sys_sched_setparam),                   // 154
601 
602    LINXY(__NR_sched_getparam,  sys_sched_getparam),                   // 155
603    LINX_(__NR_sched_setscheduler,  sys_sched_setscheduler),           // 156
604    LINX_(__NR_sched_getscheduler,  sys_sched_getscheduler),           // 157
605    LINX_(__NR_sched_yield,  sys_sched_yield),                         // 158
606    LINX_(__NR_sched_get_priority_max,  sys_sched_get_priority_max),   // 159
607 
608    LINX_(__NR_sched_get_priority_min,  sys_sched_get_priority_min),   // 160
609    LINXY(__NR_sched_rr_get_interval, sys_sched_rr_get_interval),      // 162
610    GENXY(__NR_nanosleep,  sys_nanosleep),                             // 162
611    GENX_(__NR_mremap,  sys_mremap),                                   // 163
612    GENX_(164, sys_ni_syscall), /* unimplemented (by the kernel) */    // 164
613 
614    GENX_(165, sys_ni_syscall), /* unimplemented (by the kernel) */    // 165
615    GENX_(166, sys_ni_syscall), /* unimplemented (by the kernel) */    // 166
616    GENX_(167, sys_ni_syscall), /* unimplemented (by the kernel) */    // 167
617    GENXY(__NR_poll,  sys_poll),                                       // 168
618 // ?????(__NR_nfsservctl, ),                                          // 169
619 
620    GENX_(170, sys_ni_syscall), /* unimplemented (by the kernel) */    // 170
621    GENX_(171, sys_ni_syscall), /* unimplemented (by the kernel) */    // 171
622    LINXY(__NR_prctl, sys_prctl),                                      // 172
623    PLAX_(__NR_rt_sigreturn,  sys_rt_sigreturn),                       // 173
624    LINXY(__NR_rt_sigaction,  sys_rt_sigaction),                       // 174
625 
626    LINXY(__NR_rt_sigprocmask,  sys_rt_sigprocmask),                   // 175
627    LINXY(__NR_rt_sigpending, sys_rt_sigpending),                      // 176
628    LINXY(__NR_rt_sigtimedwait,  sys_rt_sigtimedwait),                 // 177
629    LINXY(__NR_rt_sigqueueinfo, sys_rt_sigqueueinfo),                  // 178
630    LINX_(__NR_rt_sigsuspend, sys_rt_sigsuspend),                      // 179
631 
632    GENXY(__NR_pread64,  sys_pread64),                                 // 180
633    GENX_(__NR_pwrite64, sys_pwrite64),                                // 181
634    GENX_(182, sys_ni_syscall), /* unimplemented (by the kernel) */    // 182
635    GENXY(__NR_getcwd,  sys_getcwd),                                   // 183
636    LINXY(__NR_capget,  sys_capget),                                   // 184
637 
638    LINX_(__NR_capset,  sys_capset),                                   // 185
639    GENXY(__NR_sigaltstack,  sys_sigaltstack),                         // 186
640    LINXY(__NR_sendfile, sys_sendfile),                                // 187
641    GENX_(188, sys_ni_syscall), /* unimplemented (by the kernel) */    // 188
642    GENX_(189, sys_ni_syscall), /* unimplemented (by the kernel) */    // 189
643 
644    GENX_(__NR_vfork,  sys_fork),                                      // 190
645    GENXY(__NR_getrlimit,  sys_getrlimit),                             // 191
646    GENX_(192, sys_ni_syscall), /* not exported on 64bit*/             // 192
647    GENX_(193, sys_ni_syscall), /* unimplemented (by the kernel) */    // 193
648    GENX_(194, sys_ni_syscall), /* unimplemented (by the kernel) */    // 194
649 
650    GENX_(195, sys_ni_syscall), /* unimplemented (by the kernel) */    // 195
651    GENX_(196, sys_ni_syscall), /* unimplemented (by the kernel) */    // 196
652    GENX_(197, sys_ni_syscall), /* unimplemented (by the kernel) */    // 197
653    GENX_(__NR_lchown, sys_lchown),                                    // 198
654    GENX_(__NR_getuid, sys_getuid),                                    // 199
655 
656    GENX_(__NR_getgid, sys_getgid),                                    // 200
657    GENX_(__NR_geteuid, sys_geteuid),                                  // 201
658    GENX_(__NR_getegid, sys_getegid),                                  // 202
659    GENX_(__NR_setreuid, sys_setreuid),                                // 203
660    GENX_(__NR_setregid, sys_setregid),                                // 204
661 
662    GENXY(__NR_getgroups, sys_getgroups),                              // 205
663    GENX_(__NR_setgroups, sys_setgroups),                              // 206
664    GENX_(__NR_fchown, sys_fchown),                                    // 207
665    LINX_(__NR_setresuid, sys_setresuid),                              // 208
666    LINXY(__NR_getresuid, sys_getresuid),                              // 209
667 
668    LINX_(__NR_setresgid, sys_setresgid),                              // 210
669    LINXY(__NR_getresgid, sys_getresgid),                              // 211
670    GENX_(__NR_chown, sys_chown),                                      // 212
671    GENX_(__NR_setuid, sys_setuid),                                    // 213
672    GENX_(__NR_setgid, sys_setgid),                                    // 214
673 
674    LINX_(__NR_setfsuid, sys_setfsuid),                                // 215
675    LINX_(__NR_setfsgid, sys_setfsgid),                                // 216
676    LINX_(__NR_pivot_root, sys_pivot_root),                            // 217
677    GENXY(__NR_mincore, sys_mincore),                                  // 218
678    GENX_(__NR_madvise,  sys_madvise),                                 // 219
679 
680    GENXY(__NR_getdents64,  sys_getdents64),                           // 220
681    GENX_(221, sys_ni_syscall), /* unimplemented (by the kernel) */    // 221
682    LINX_(__NR_readahead, sys_readahead),                              // 222
683    GENX_(223, sys_ni_syscall), /* unimplemented (by the kernel) */    // 223
684    LINX_(__NR_setxattr, sys_setxattr),                                // 224
685 
686    LINX_(__NR_lsetxattr, sys_lsetxattr),                              // 225
687    LINX_(__NR_fsetxattr, sys_fsetxattr),                              // 226
688    LINXY(__NR_getxattr,  sys_getxattr),                               // 227
689    LINXY(__NR_lgetxattr,  sys_lgetxattr),                             // 228
690    LINXY(__NR_fgetxattr,  sys_fgetxattr),                             // 229
691 
692    LINXY(__NR_listxattr,  sys_listxattr),                             // 230
693    LINXY(__NR_llistxattr,  sys_llistxattr),                           // 231
694    LINXY(__NR_flistxattr,  sys_flistxattr),                           // 232
695    LINX_(__NR_removexattr,  sys_removexattr),                         // 233
696    LINX_(__NR_lremovexattr,  sys_lremovexattr),                       // 234
697 
698    LINX_(__NR_fremovexattr,  sys_fremovexattr),                       // 235
699    LINX_(__NR_gettid,  sys_gettid),                                   // 236
700    LINXY(__NR_tkill, sys_tkill),                                      // 237
701    LINXY(__NR_futex,  sys_futex),                                     // 238
702    LINX_(__NR_sched_setaffinity,  sys_sched_setaffinity),             // 239
703 
704    LINXY(__NR_sched_getaffinity,  sys_sched_getaffinity),             // 240
705    LINXY(__NR_tgkill, sys_tgkill),                                    // 241
706    GENX_(242, sys_ni_syscall), /* unimplemented (by the kernel) */    // 242
707    LINXY(__NR_io_setup, sys_io_setup),                                // 243
708    LINX_(__NR_io_destroy,  sys_io_destroy),                           // 244
709 
710    LINXY(__NR_io_getevents,  sys_io_getevents),                       // 245
711    LINX_(__NR_io_submit,  sys_io_submit),                             // 246
712    LINXY(__NR_io_cancel,  sys_io_cancel),                             // 247
713    LINX_(__NR_exit_group,  sys_exit_group),                           // 248
714    LINXY(__NR_epoll_create,  sys_epoll_create),                       // 249
715 
716    LINX_(__NR_epoll_ctl,  sys_epoll_ctl),                             // 250
717    LINXY(__NR_epoll_wait,  sys_epoll_wait),                           // 251
718    LINX_(__NR_set_tid_address,  sys_set_tid_address),                 // 252
719    PLAX_(__NR_fadvise64, sys_fadvise64),                              // 253
720    LINXY(__NR_timer_create,  sys_timer_create),                       // 254
721 
722    LINXY(__NR_timer_settime,  sys_timer_settime),                     // 255
723    LINXY(__NR_timer_gettime,  sys_timer_gettime),                     // 256
724    LINX_(__NR_timer_getoverrun,  sys_timer_getoverrun),               // 257
725    LINX_(__NR_timer_delete,  sys_timer_delete),                       // 258
726    LINX_(__NR_clock_settime,  sys_clock_settime),                     // 259
727 
728    LINXY(__NR_clock_gettime,  sys_clock_gettime),                     // 260
729    LINXY(__NR_clock_getres,  sys_clock_getres),                       // 261
730    LINXY(__NR_clock_nanosleep,  sys_clock_nanosleep),                 // 262
731    GENX_(263, sys_ni_syscall), /* unimplemented (by the kernel) */    // 263
732    GENX_(264, sys_ni_syscall), /* unimplemented (by the kernel) */    // 264
733 
734    GENXY(__NR_statfs64, sys_statfs64),                                // 265
735    GENXY(__NR_fstatfs64, sys_fstatfs64),                              // 266
736 // ?????(__NR_remap_file_pages, ),
737    GENX_(268, sys_ni_syscall), /* unimplemented (by the kernel) */    // 268
738    GENX_(269, sys_ni_syscall), /* unimplemented (by the kernel) */    // 269
739 
740    GENX_(270, sys_ni_syscall), /* unimplemented (by the kernel) */    // 270
741    LINXY(__NR_mq_open,  sys_mq_open),                                 // 271
742    LINX_(__NR_mq_unlink,  sys_mq_unlink),                             // 272
743    LINX_(__NR_mq_timedsend,  sys_mq_timedsend),                       // 273
744    LINXY(__NR_mq_timedreceive, sys_mq_timedreceive),                  // 274
745 
746    LINX_(__NR_mq_notify,  sys_mq_notify),                             // 275
747    LINXY(__NR_mq_getsetattr,  sys_mq_getsetattr),                     // 276
748 // ?????(__NR_kexec_load, ),
749    LINX_(__NR_add_key,  sys_add_key),                                 // 278
750    LINX_(__NR_request_key,  sys_request_key),                         // 279
751 
752    LINXY(__NR_keyctl,  sys_keyctl),                                   // 280
753    LINXY(__NR_waitid, sys_waitid),                                    // 281
754    LINX_(__NR_ioprio_set,  sys_ioprio_set),                           // 282
755    LINX_(__NR_ioprio_get,  sys_ioprio_get),                           // 283
756    LINX_(__NR_inotify_init,  sys_inotify_init),                       // 284
757 
758    LINX_(__NR_inotify_add_watch,  sys_inotify_add_watch),             // 285
759    LINX_(__NR_inotify_rm_watch,  sys_inotify_rm_watch),               // 286
760    GENX_(287, sys_ni_syscall), /* unimplemented (by the kernel) */    // 287
761    LINXY(__NR_openat,  sys_openat),                                   // 288
762    LINX_(__NR_mkdirat,  sys_mkdirat),                                 // 289
763 
764    LINX_(__NR_mknodat,  sys_mknodat),                                 // 290
765    LINX_(__NR_fchownat,  sys_fchownat),                               // 291
766    LINX_(__NR_futimesat,  sys_futimesat),                             // 292
767    LINXY(__NR_newfstatat, sys_newfstatat),                            // 293
768    LINX_(__NR_unlinkat,  sys_unlinkat),                               // 294
769 
770    LINX_(__NR_renameat,  sys_renameat),                               // 295
771    LINX_(__NR_linkat,  sys_linkat),                                   // 296
772    LINX_(__NR_symlinkat,  sys_symlinkat),                             // 297
773    LINX_(__NR_readlinkat,  sys_readlinkat),                           // 298
774    LINX_(__NR_fchmodat,  sys_fchmodat),                               // 299
775 
776    LINX_(__NR_faccessat,  sys_faccessat),                             // 300
777    LINXY(__NR_pselect6, sys_pselect6),                                // 301
778    LINXY(__NR_ppoll, sys_ppoll),                                      // 302
779    LINX_(__NR_unshare, sys_unshare),                                  // 303
780    LINX_(__NR_set_robust_list,  sys_set_robust_list),                 // 304
781 
782    LINXY(__NR_get_robust_list,  sys_get_robust_list),                 // 305
783    LINX_(__NR_splice, sys_splice),                                    // 306
784    LINX_(__NR_sync_file_range, sys_sync_file_range),                  // 307
785    LINX_(__NR_tee, sys_tee),                                          // 308
786    LINXY(__NR_vmsplice, sys_vmsplice),                                // 309
787 
788    GENX_(310, sys_ni_syscall), /* unimplemented (by the kernel) */    // 310
789    LINXY(__NR_getcpu, sys_getcpu),                                    // 311
790    LINXY(__NR_epoll_pwait,  sys_epoll_pwait),                         // 312
791    GENX_(__NR_utimes, sys_utimes),                                    // 313
792    LINX_(__NR_fallocate, sys_fallocate),                              // 314
793 
794    LINX_(__NR_utimensat,  sys_utimensat),                             // 315
795    LINXY(__NR_signalfd,  sys_signalfd),                               // 316
796    GENX_(317, sys_ni_syscall), /* unimplemented (by the kernel) */    // 317
797    LINXY(__NR_eventfd,  sys_eventfd),                                 // 318
798    LINXY(__NR_timerfd_create,  sys_timerfd_create),                   // 319
799 
800    LINXY(__NR_timerfd_settime,  sys_timerfd_settime),                 // 320
801    LINXY(__NR_timerfd_gettime,  sys_timerfd_gettime),                 // 321
802    LINXY(__NR_signalfd4,  sys_signalfd4),                             // 322
803    LINXY(__NR_eventfd2,  sys_eventfd2),                               // 323
804    LINXY(__NR_inotify_init1,  sys_inotify_init1),                     // 324
805 
806    LINXY(__NR_pipe2,  sys_pipe2),                                     // 325
807    LINXY(__NR_dup3,  sys_dup3),                                       // 326
808    LINXY(__NR_epoll_create1,  sys_epoll_create1),                     // 327
809    LINXY(__NR_preadv, sys_preadv),                                    // 328
810    LINX_(__NR_pwritev, sys_pwritev),                                  // 329
811 
812    LINXY(__NR_rt_tgsigqueueinfo, sys_rt_tgsigqueueinfo),              // 330
813    LINXY(__NR_perf_event_open, sys_perf_event_open),                  // 331
814    LINXY(__NR_fanotify_init, sys_fanotify_init),                      // 332
815    LINX_(__NR_fanotify_mark, sys_fanotify_mark),                      // 333
816    LINXY(__NR_prlimit64, sys_prlimit64),                              // 334
817 
818    LINXY(__NR_name_to_handle_at, sys_name_to_handle_at),              // 335
819    LINXY(__NR_open_by_handle_at, sys_open_by_handle_at),              // 336
820    LINXY(__NR_clock_adjtime, sys_clock_adjtime),                      // 337
821    LINX_(__NR_syncfs, sys_syncfs),                                    // 338
822 // ?????(__NR_setns, ),                                               // 339
823 
824    LINXY(__NR_process_vm_readv, sys_process_vm_readv),                // 340
825    LINX_(__NR_process_vm_writev, sys_process_vm_writev),              // 341
826 // ?????(__NR_s390_runtime_instr, ),                                  // 342
827    LINX_(__NR_kcmp, sys_kcmp),                                        // 343
828 // ?????(__NR_finit_module, ),                                        // 344
829 
830 // ?????(__NR_sched_setattr, ),                                       // 345
831 // ?????(__NR_sched_getattr, ),                                       // 346
832    LINX_(__NR_renameat2, sys_renameat2),                              // 347
833 // ?????(__NR_seccomp, ),                                             // 348
834    LINXY(__NR_getrandom, sys_getrandom),                              // 349
835 
836    LINXY(__NR_memfd_create, sys_memfd_create),                        // 350
837 
838    LINX_(__NR_membarrier, sys_membarrier),                            // 356
839    LINXY(__NR_recvmmsg, sys_recvmmsg),                                // 357
840    LINXY(__NR_sendmmsg, sys_sendmmsg),                                // 358
841    LINXY(__NR_socket, sys_socket),                                    // 359
842    LINXY(__NR_socketpair, sys_socketpair),                            // 360
843    LINX_(__NR_bind, sys_bind),                                        // 361
844    LINX_(__NR_connect, sys_connect),                                  // 362
845    LINX_(__NR_listen, sys_listen),                                    // 363
846    LINXY(__NR_accept4, sys_accept4),                                  // 364
847    LINXY(__NR_getsockopt, sys_getsockopt),                            // 365
848    LINX_(__NR_setsockopt, sys_setsockopt),                            // 366
849    LINXY(__NR_getsockname, sys_getsockname),                          // 367
850    LINXY(__NR_getpeername, sys_getpeername),                          // 368
851    LINX_(__NR_sendto, sys_sendto),                                    // 369
852    LINX_(__NR_sendmsg, sys_sendmsg),                                  // 270
853    LINXY(__NR_recvfrom, sys_recvfrom),                                // 371
854    LINXY(__NR_recvmsg, sys_recvmsg),                                  // 372
855    LINX_(__NR_shutdown, sys_shutdown),                                // 373
856 
857    LINXY(__NR_statx, sys_statx),                                      // 379
858 };
859 
ML_(get_linux_syscall_entry)860 SyscallTableEntry* ML_(get_linux_syscall_entry) ( UInt sysno )
861 {
862    const UInt syscall_table_size
863       = sizeof(syscall_table) / sizeof(syscall_table[0]);
864 
865    /* Is it in the contiguous initial section of the table? */
866    if (sysno < syscall_table_size) {
867       SyscallTableEntry* sys = &syscall_table[sysno];
868       if (sys->before == NULL)
869          return NULL; /* no entry */
870       else
871          return sys;
872    }
873 
874    /* Can't find a wrapper */
875    return NULL;
876 }
877 
878 #endif
879 
880 /*--------------------------------------------------------------------*/
881 /*--- end                                                          ---*/
882 /*--------------------------------------------------------------------*/
883