drd/drd_pthread_intercepts: Add a workaround for what is probably a compiler bug
[valgrind.git] / coregrind / m_syswrap / syswrap-amd64-linux.c
blob9b8068d0ffc8c3826589726eccfe7e63752e0c5e
2 /*--------------------------------------------------------------------*/
3 /*--- Platform-specific syscalls stuff. syswrap-amd64-linux.c ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2000-2017 Nicholas Nethercote
11 njn@valgrind.org
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #if defined(VGP_amd64_linux)
31 #include "pub_core_basics.h"
32 #include "pub_core_vki.h"
33 #include "pub_core_vkiscnums.h"
34 #include "pub_core_threadstate.h"
35 #include "pub_core_aspacemgr.h"
36 #include "pub_core_debuglog.h"
37 #include "pub_core_options.h"
38 #include "pub_core_libcbase.h"
39 #include "pub_core_libcassert.h"
40 #include "pub_core_libcprint.h"
41 #include "pub_core_libcproc.h"
42 #include "pub_core_libcsignal.h"
43 #include "pub_core_scheduler.h"
44 #include "pub_core_sigframe.h"
45 #include "pub_core_signals.h"
46 #include "pub_core_syscall.h"
47 #include "pub_core_syswrap.h"
48 #include "pub_core_tooliface.h"
50 #include "priv_types_n_macros.h"
51 #include "priv_syswrap-generic.h" /* for decls of generic wrappers */
52 #include "priv_syswrap-linux.h" /* for decls of linux-ish wrappers */
53 #include "priv_syswrap-linux-variants.h" /* decls of linux variant wrappers */
54 #include "priv_syswrap-main.h"
57 /* ---------------------------------------------------------------------
58 clone() handling
59 ------------------------------------------------------------------ */
61 /* Call f(arg1), but first switch stacks, using 'stack' as the new
62 stack, and use 'retaddr' as f's return-to address. Also, clear all
63 the integer registers before entering f. */
64 __attribute__((noreturn))
65 void ML_(call_on_new_stack_0_1) ( Addr stack,
66 Addr retaddr,
67 void (*f)(Word),
68 Word arg1 );
69 // %rdi == stack
70 // %rsi == retaddr
71 // %rdx == f
72 // %rcx == arg1
73 asm(
74 ".text\n"
75 ".globl vgModuleLocal_call_on_new_stack_0_1\n"
76 "vgModuleLocal_call_on_new_stack_0_1:\n"
77 " movq %rdi, %rsp\n" // set stack
78 " pushq %rsi\n" // retaddr to stack
79 " pushq %rdx\n" // f to stack
80 " pushq %rcx\n" // arg1 to stack
81 " movq $0, %rax\n" // zero all GP regs
82 " movq $0, %rbx\n"
83 " movq $0, %rcx\n"
84 " movq $0, %rdx\n"
85 " movq $0, %rsi\n"
86 " movq $0, %rdi\n"
87 " movq $0, %rbp\n"
88 " movq $0, %r8\n"
89 " movq $0, %r9\n"
90 " movq $0, %r10\n"
91 " movq $0, %r11\n"
92 " movq $0, %r12\n"
93 " movq $0, %r13\n"
94 " movq $0, %r14\n"
95 " movq $0, %r15\n"
96 " popq %rdi\n" // arg1 to correct arg reg
97 " ret\n" // jump to f
98 " ud2\n" // should never get here
99 ".previous\n"
103 Perform a clone system call. clone is strange because it has
104 fork()-like return-twice semantics, so it needs special
105 handling here.
107 Upon entry, we have:
109 int (*fn)(void*) in %rdi
110 void* child_stack in %rsi
111 int flags in %rdx
112 void* arg in %rcx
113 pid_t* child_tid in %r8
114 pid_t* parent_tid in %r9
115 void* tls_ptr at 8(%rsp)
117 System call requires:
119 int $__NR_clone in %rax
120 int flags in %rdi
121 void* child_stack in %rsi
122 pid_t* parent_tid in %rdx
123 pid_t* child_tid in %r10
124 void* tls_ptr in %r8
126 Returns a Long encoded in the linux-amd64 way, not a SysRes.
128 #define __NR_CLONE VG_STRINGIFY(__NR_clone)
129 #define __NR_EXIT VG_STRINGIFY(__NR_exit)
131 // See priv_syswrap-linux.h for arg profile.
132 asm(
133 ".text\n"
134 ".globl do_syscall_clone_amd64_linux\n"
135 "do_syscall_clone_amd64_linux:\n"
136 // set up child stack, temporarily preserving fn and arg
137 " subq $16, %rsi\n" // make space on stack
138 " movq %rcx, 8(%rsi)\n" // save arg
139 " movq %rdi, 0(%rsi)\n" // save fn
141 // setup syscall
142 " movq $"__NR_CLONE", %rax\n" // syscall number
143 " movq %rdx, %rdi\n" // syscall arg1: flags
144 // %rsi already setup // syscall arg2: child_stack
145 " movq %r9, %rdx\n" // syscall arg3: parent_tid
146 " movq %r8, %r10\n" // syscall arg4: child_tid
147 " movq 8(%rsp), %r8\n" // syscall arg5: tls_ptr
149 " syscall\n" // clone()
151 " testq %rax, %rax\n" // child if retval == 0
152 " jnz 1f\n"
154 // CHILD - call thread function
155 " pop %rax\n" // pop fn
156 " pop %rdi\n" // pop fn arg1: arg
157 " call *%rax\n" // call fn
159 // exit with result
160 " movq %rax, %rdi\n" // arg1: return value from fn
161 " movq $"__NR_EXIT", %rax\n"
163 " syscall\n"
165 // Exit returned?!
166 " ud2\n"
168 "1:\n" // PARENT or ERROR
169 " ret\n"
170 ".previous\n"
173 #undef __NR_CLONE
174 #undef __NR_EXIT
177 /* ---------------------------------------------------------------------
178 More thread stuff
179 ------------------------------------------------------------------ */
181 void VG_(cleanup_thread) ( ThreadArchState *arch )
185 /* ---------------------------------------------------------------------
186 PRE/POST wrappers for AMD64/Linux-specific syscalls
187 ------------------------------------------------------------------ */
189 #define PRE(name) DEFN_PRE_TEMPLATE(amd64_linux, name)
190 #define POST(name) DEFN_POST_TEMPLATE(amd64_linux, name)
192 /* Add prototypes for the wrappers declared here, so that gcc doesn't
193 harass us for not having prototypes. Really this is a kludge --
194 the right thing to do is to make these wrappers 'static' since they
195 aren't visible outside this file, but that requires even more macro
196 magic. */
197 DECL_TEMPLATE(amd64_linux, sys_rt_sigreturn);
198 DECL_TEMPLATE(amd64_linux, sys_arch_prctl);
199 DECL_TEMPLATE(amd64_linux, sys_ptrace);
200 DECL_TEMPLATE(amd64_linux, sys_fadvise64);
201 DECL_TEMPLATE(amd64_linux, sys_mmap);
202 DECL_TEMPLATE(amd64_linux, sys_syscall184);
205 PRE(sys_rt_sigreturn)
207 /* This isn't really a syscall at all - it's a misuse of the
208 syscall mechanism by m_sigframe. VG_(sigframe_create) sets the
209 return address of the signal frames it creates to be a short
210 piece of code which does this "syscall". The only purpose of
211 the syscall is to call VG_(sigframe_destroy), which restores the
212 thread's registers from the frame and then removes it.
213 Consequently we must ask the syswrap driver logic not to write
214 back the syscall "result" as that would overwrite the
215 just-restored register state. */
217 ThreadState* tst;
218 PRINT("sys_rt_sigreturn ( )");
220 vg_assert(VG_(is_valid_tid)(tid));
221 vg_assert(tid >= 1 && tid < VG_N_THREADS);
222 vg_assert(VG_(is_running_thread)(tid));
224 /* Adjust RSP to point to start of frame; skip back up over handler
225 ret addr */
226 tst = VG_(get_ThreadState)(tid);
227 tst->arch.vex.guest_RSP -= sizeof(Addr);
229 /* This is only so that the RIP is (might be) useful to report if
230 something goes wrong in the sigreturn. JRS 20070318: no idea
231 what this is for */
232 ML_(fixup_guest_state_to_restart_syscall)(&tst->arch);
234 /* Restore register state from frame and remove it, as
235 described above */
236 VG_(sigframe_destroy)(tid, True);
238 /* Tell the driver not to update the guest state with the "result",
239 and set a bogus result to keep it happy. */
240 *flags |= SfNoWriteResult;
241 SET_STATUS_Success(0);
243 /* Check to see if any signals arose as a result of this. */
244 *flags |= SfPollAfter;
247 PRE(sys_arch_prctl)
249 ThreadState* tst;
250 Bool known_option = True;
251 PRINT( "arch_prctl ( %ld, %lx )", SARG1, ARG2 );
253 vg_assert(VG_(is_valid_tid)(tid));
254 vg_assert(tid >= 1 && tid < VG_N_THREADS);
255 vg_assert(VG_(is_running_thread)(tid));
257 // Nb: can't use "ARG2".."ARG5" here because that's our own macro...
258 PRE_REG_READ2(long, "arch_prctl",
259 int, option, unsigned long, arg2);
260 // XXX: totally wrong... we need to look at the 'option' arg, and do
261 // PRE_MEM_READs/PRE_MEM_WRITEs as necessary...
263 /* "do" the syscall ourselves; the kernel never sees it */
264 if (ARG1 == VKI_ARCH_SET_FS) {
265 tst = VG_(get_ThreadState)(tid);
266 tst->arch.vex.guest_FS_CONST = ARG2;
268 else if (ARG1 == VKI_ARCH_GET_FS) {
269 PRE_MEM_WRITE("arch_prctl(addr)", ARG2, sizeof(unsigned long));
270 tst = VG_(get_ThreadState)(tid);
271 *(unsigned long *)ARG2 = tst->arch.vex.guest_FS_CONST;
272 POST_MEM_WRITE(ARG2, sizeof(unsigned long));
274 else if (ARG1 == VKI_ARCH_SET_GS) {
275 tst = VG_(get_ThreadState)(tid);
276 tst->arch.vex.guest_GS_CONST = ARG2;
278 else if (ARG1 == VKI_ARCH_GET_GS) {
279 PRE_MEM_WRITE("arch_prctl(addr)", ARG2, sizeof(unsigned long));
280 tst = VG_(get_ThreadState)(tid);
281 *(unsigned long *)ARG2 = tst->arch.vex.guest_GS_CONST;
282 POST_MEM_WRITE(ARG2, sizeof(unsigned long));
284 else {
285 known_option = False;
288 /* Note; the Status writeback to guest state that happens after
289 this wrapper returns does not change guest_FS_CONST or guest_GS_CONST;
290 hence that direct assignment to the guest state is safe here. */
291 if (known_option)
292 SET_STATUS_Success( 0 );
293 else
294 SET_STATUS_Failure( VKI_EINVAL );
297 // Parts of this are amd64-specific, but the *PEEK* cases are generic.
299 // ARG3 is only used for pointers into the traced process's address
300 // space and for offsets into the traced process's struct
301 // user_regs_struct. It is never a pointer into this process's memory
302 // space, and we should therefore not check anything it points to.
303 PRE(sys_ptrace)
305 PRINT("sys_ptrace ( %ld, %ld, %#lx, %#lx )", SARG1, SARG2, ARG3, ARG4);
306 PRE_REG_READ4(int, "ptrace",
307 long, request, long, pid, long, addr, long, data);
308 switch (ARG1) {
309 case VKI_PTRACE_PEEKTEXT:
310 case VKI_PTRACE_PEEKDATA:
311 case VKI_PTRACE_PEEKUSR:
312 PRE_MEM_WRITE( "ptrace(peek)", ARG4,
313 sizeof (long));
314 break;
315 case VKI_PTRACE_GETREGS:
316 PRE_MEM_WRITE( "ptrace(getregs)", ARG4,
317 sizeof (struct vki_user_regs_struct));
318 break;
319 case VKI_PTRACE_GETFPREGS:
320 PRE_MEM_WRITE( "ptrace(getfpregs)", ARG4,
321 sizeof (struct vki_user_i387_struct));
322 break;
323 case VKI_PTRACE_GET_THREAD_AREA:
324 PRE_MEM_WRITE( "ptrace(get_thread_area)", ARG4,
325 sizeof(struct vki_user_desc) );
326 break;
327 case VKI_PTRACE_SETREGS:
328 PRE_MEM_READ( "ptrace(setregs)", ARG4,
329 sizeof (struct vki_user_regs_struct));
330 break;
331 case VKI_PTRACE_SETFPREGS:
332 PRE_MEM_READ( "ptrace(setfpregs)", ARG4,
333 sizeof (struct vki_user_i387_struct));
334 break;
335 case VKI_PTRACE_SET_THREAD_AREA:
336 PRE_MEM_READ( "ptrace(set_thread_area)", ARG4,
337 sizeof(struct vki_user_desc) );
338 break;
339 case VKI_PTRACE_GETEVENTMSG:
340 PRE_MEM_WRITE( "ptrace(geteventmsg)", ARG4, sizeof(unsigned long));
341 break;
342 case VKI_PTRACE_GETSIGINFO:
343 PRE_MEM_WRITE( "ptrace(getsiginfo)", ARG4, sizeof(vki_siginfo_t));
344 break;
345 case VKI_PTRACE_SETSIGINFO:
346 PRE_MEM_READ( "ptrace(setsiginfo)", ARG4, sizeof(vki_siginfo_t));
347 break;
348 case VKI_PTRACE_GETREGSET:
349 ML_(linux_PRE_getregset)(tid, ARG3, ARG4);
350 break;
351 case VKI_PTRACE_SETREGSET:
352 ML_(linux_PRE_setregset)(tid, ARG3, ARG4);
353 break;
354 default:
355 break;
359 POST(sys_ptrace)
361 switch (ARG1) {
362 case VKI_PTRACE_TRACEME:
363 ML_(linux_POST_traceme)(tid);
364 break;
365 case VKI_PTRACE_PEEKTEXT:
366 case VKI_PTRACE_PEEKDATA:
367 case VKI_PTRACE_PEEKUSR:
368 POST_MEM_WRITE( ARG4, sizeof (long));
369 break;
370 case VKI_PTRACE_GETREGS:
371 POST_MEM_WRITE( ARG4, sizeof (struct vki_user_regs_struct));
372 break;
373 case VKI_PTRACE_GETFPREGS:
374 POST_MEM_WRITE( ARG4, sizeof (struct vki_user_i387_struct));
375 break;
376 case VKI_PTRACE_GET_THREAD_AREA:
377 POST_MEM_WRITE( ARG4, sizeof(struct vki_user_desc) );
378 break;
379 case VKI_PTRACE_GETEVENTMSG:
380 POST_MEM_WRITE( ARG4, sizeof(unsigned long));
381 break;
382 case VKI_PTRACE_GETSIGINFO:
383 /* XXX: This is a simplification. Different parts of the
384 * siginfo_t are valid depending on the type of signal.
386 POST_MEM_WRITE( ARG4, sizeof(vki_siginfo_t));
387 break;
388 case VKI_PTRACE_GETREGSET:
389 ML_(linux_POST_getregset)(tid, ARG3, ARG4);
390 break;
391 default:
392 break;
396 PRE(sys_fadvise64)
398 PRINT("sys_fadvise64 ( %ld, %ld, %lu, %ld )", SARG1, SARG2, ARG3, SARG4);
399 PRE_REG_READ4(long, "fadvise64",
400 int, fd, vki_loff_t, offset, vki_size_t, len, int, advice);
403 PRE(sys_mmap)
405 SysRes r;
407 PRINT("sys_mmap ( %#lx, %lu, %ld, %ld, %ld, %ld )",
408 ARG1, ARG2, SARG3, SARG4, SARG5, SARG6 );
409 PRE_REG_READ6(long, "mmap",
410 unsigned long, start, unsigned long, length,
411 int, prot, int, flags, int, fd, vki_off_t, offset);
413 r = ML_(generic_PRE_sys_mmap)( tid, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6 );
414 SET_STATUS_from_SysRes(r);
418 /* ---------------------------------------------------------------
419 PRE/POST wrappers for AMD64/Linux-variant specific syscalls
420 ------------------------------------------------------------ */
422 PRE(sys_syscall184)
424 Int err;
426 /* 184 is used by sys_bproc. If we're not on a declared bproc
427 variant, fail in the usual way, since it is otherwise unused. */
429 if (!KernelVariantiS(KernelVariant_bproc, VG_(clo_kernel_variant))) {
430 PRINT("non-existent syscall! (syscall 184)");
431 PRE_REG_READ0(long, "ni_syscall(184)");
432 SET_STATUS_Failure( VKI_ENOSYS );
433 return;
436 err = ML_(linux_variant_PRE_sys_bproc)( ARG1, ARG2, ARG3,
437 ARG4, ARG5, ARG6 );
438 if (err) {
439 SET_STATUS_Failure( err );
440 return;
442 /* Let it go through. */
443 *flags |= SfMayBlock; /* who knows? play safe. */
446 POST(sys_syscall184)
448 ML_(linux_variant_POST_sys_bproc)( ARG1, ARG2, ARG3,
449 ARG4, ARG5, ARG6 );
452 #undef PRE
453 #undef POST
456 /* ---------------------------------------------------------------------
457 The AMD64/Linux syscall table
458 ------------------------------------------------------------------ */
460 /* Add an amd64-linux specific wrapper to a syscall table. */
461 #define PLAX_(const, name) WRAPPER_ENTRY_X_(amd64_linux, const, name)
462 #define PLAXY(const, name) WRAPPER_ENTRY_XY(amd64_linux, const, name)
464 // This table maps from __NR_xxx syscall numbers (from
465 // linux/include/asm-x86_64/unistd.h) to the appropriate PRE/POST sys_foo()
466 // wrappers on AMD64 (as per sys_call_table in
467 // linux/arch/x86_64/kernel/entry.S).
469 // When implementing these wrappers, you need to work out if the wrapper is
470 // generic, Linux-only (but arch-independent), or AMD64/Linux only.
472 static SyscallTableEntry syscall_table[] = {
473 GENXY(__NR_read, sys_read), // 0
474 GENX_(__NR_write, sys_write), // 1
475 GENXY(__NR_open, sys_open), // 2
476 GENXY(__NR_close, sys_close), // 3
477 GENXY(__NR_stat, sys_newstat), // 4
479 GENXY(__NR_fstat, sys_newfstat), // 5
480 GENXY(__NR_lstat, sys_newlstat), // 6
481 GENXY(__NR_poll, sys_poll), // 7
482 LINX_(__NR_lseek, sys_lseek), // 8
483 PLAX_(__NR_mmap, sys_mmap), // 9
485 GENXY(__NR_mprotect, sys_mprotect), // 10
486 GENXY(__NR_munmap, sys_munmap), // 11
487 GENX_(__NR_brk, sys_brk), // 12
488 LINXY(__NR_rt_sigaction, sys_rt_sigaction), // 13
489 LINXY(__NR_rt_sigprocmask, sys_rt_sigprocmask), // 14
491 PLAX_(__NR_rt_sigreturn, sys_rt_sigreturn), // 15
492 LINXY(__NR_ioctl, sys_ioctl), // 16
493 GENXY(__NR_pread64, sys_pread64), // 17
494 GENX_(__NR_pwrite64, sys_pwrite64), // 18
495 GENXY(__NR_readv, sys_readv), // 19
497 GENX_(__NR_writev, sys_writev), // 20
498 GENX_(__NR_access, sys_access), // 21
499 LINXY(__NR_pipe, sys_pipe), // 22
500 GENX_(__NR_select, sys_select), // 23
501 LINX_(__NR_sched_yield, sys_sched_yield), // 24
503 GENX_(__NR_mremap, sys_mremap), // 25
504 GENX_(__NR_msync, sys_msync), // 26
505 GENXY(__NR_mincore, sys_mincore), // 27
506 GENX_(__NR_madvise, sys_madvise), // 28
507 LINX_(__NR_shmget, sys_shmget), // 29
509 LINXY(__NR_shmat, sys_shmat), // 30
510 LINXY(__NR_shmctl, sys_shmctl), // 31
511 GENXY(__NR_dup, sys_dup), // 32
512 GENXY(__NR_dup2, sys_dup2), // 33
513 GENX_(__NR_pause, sys_pause), // 34
515 GENXY(__NR_nanosleep, sys_nanosleep), // 35
516 GENXY(__NR_getitimer, sys_getitimer), // 36
517 GENX_(__NR_alarm, sys_alarm), // 37
518 GENXY(__NR_setitimer, sys_setitimer), // 38
519 GENX_(__NR_getpid, sys_getpid), // 39
521 LINXY(__NR_sendfile, sys_sendfile), // 40
522 LINXY(__NR_socket, sys_socket), // 41
523 LINX_(__NR_connect, sys_connect), // 42
524 LINXY(__NR_accept, sys_accept), // 43
525 LINX_(__NR_sendto, sys_sendto), // 44
527 LINXY(__NR_recvfrom, sys_recvfrom), // 45
528 LINX_(__NR_sendmsg, sys_sendmsg), // 46
529 LINXY(__NR_recvmsg, sys_recvmsg), // 47
530 LINX_(__NR_shutdown, sys_shutdown), // 48
531 LINX_(__NR_bind, sys_bind), // 49
533 LINX_(__NR_listen, sys_listen), // 50
534 LINXY(__NR_getsockname, sys_getsockname), // 51
535 LINXY(__NR_getpeername, sys_getpeername), // 52
536 LINXY(__NR_socketpair, sys_socketpair), // 53
537 LINX_(__NR_setsockopt, sys_setsockopt), // 54
539 LINXY(__NR_getsockopt, sys_getsockopt), // 55
540 LINX_(__NR_clone, sys_clone), // 56
541 GENX_(__NR_fork, sys_fork), // 57
542 GENX_(__NR_vfork, sys_fork), // 58 treat as fork
543 GENX_(__NR_execve, sys_execve), // 59
545 GENX_(__NR_exit, sys_exit), // 60
546 GENXY(__NR_wait4, sys_wait4), // 61
547 GENX_(__NR_kill, sys_kill), // 62
548 GENXY(__NR_uname, sys_newuname), // 63
549 LINX_(__NR_semget, sys_semget), // 64
551 LINX_(__NR_semop, sys_semop), // 65
552 LINXY(__NR_semctl, sys_semctl), // 66
553 LINXY(__NR_shmdt, sys_shmdt), // 67
554 LINX_(__NR_msgget, sys_msgget), // 68
555 LINX_(__NR_msgsnd, sys_msgsnd), // 69
557 LINXY(__NR_msgrcv, sys_msgrcv), // 70
558 LINXY(__NR_msgctl, sys_msgctl), // 71
559 LINXY(__NR_fcntl, sys_fcntl), // 72
560 GENX_(__NR_flock, sys_flock), // 73
561 GENX_(__NR_fsync, sys_fsync), // 74
563 GENX_(__NR_fdatasync, sys_fdatasync), // 75
564 GENX_(__NR_truncate, sys_truncate), // 76
565 GENX_(__NR_ftruncate, sys_ftruncate), // 77
566 GENXY(__NR_getdents, sys_getdents), // 78
567 GENXY(__NR_getcwd, sys_getcwd), // 79
569 GENX_(__NR_chdir, sys_chdir), // 80
570 GENX_(__NR_fchdir, sys_fchdir), // 81
571 GENX_(__NR_rename, sys_rename), // 82
572 GENX_(__NR_mkdir, sys_mkdir), // 83
573 GENX_(__NR_rmdir, sys_rmdir), // 84
575 GENXY(__NR_creat, sys_creat), // 85
576 GENX_(__NR_link, sys_link), // 86
577 GENX_(__NR_unlink, sys_unlink), // 87
578 GENX_(__NR_symlink, sys_symlink), // 88
579 GENX_(__NR_readlink, sys_readlink), // 89
581 GENX_(__NR_chmod, sys_chmod), // 90
582 GENX_(__NR_fchmod, sys_fchmod), // 91
583 GENX_(__NR_chown, sys_chown), // 92
584 GENX_(__NR_fchown, sys_fchown), // 93
585 GENX_(__NR_lchown, sys_lchown), // 94
587 GENX_(__NR_umask, sys_umask), // 95
588 GENXY(__NR_gettimeofday, sys_gettimeofday), // 96
589 GENXY(__NR_getrlimit, sys_getrlimit), // 97
590 GENXY(__NR_getrusage, sys_getrusage), // 98
591 LINXY(__NR_sysinfo, sys_sysinfo), // 99
593 GENXY(__NR_times, sys_times), // 100
594 PLAXY(__NR_ptrace, sys_ptrace), // 101
595 GENX_(__NR_getuid, sys_getuid), // 102
596 LINXY(__NR_syslog, sys_syslog), // 103
597 GENX_(__NR_getgid, sys_getgid), // 104
599 GENX_(__NR_setuid, sys_setuid), // 105
600 GENX_(__NR_setgid, sys_setgid), // 106
601 GENX_(__NR_geteuid, sys_geteuid), // 107
602 GENX_(__NR_getegid, sys_getegid), // 108
603 GENX_(__NR_setpgid, sys_setpgid), // 109
605 GENX_(__NR_getppid, sys_getppid), // 110
606 GENX_(__NR_getpgrp, sys_getpgrp), // 111
607 GENX_(__NR_setsid, sys_setsid), // 112
608 GENX_(__NR_setreuid, sys_setreuid), // 113
609 GENX_(__NR_setregid, sys_setregid), // 114
611 GENXY(__NR_getgroups, sys_getgroups), // 115
612 GENX_(__NR_setgroups, sys_setgroups), // 116
613 LINX_(__NR_setresuid, sys_setresuid), // 117
614 LINXY(__NR_getresuid, sys_getresuid), // 118
615 LINX_(__NR_setresgid, sys_setresgid), // 119
617 LINXY(__NR_getresgid, sys_getresgid), // 120
618 GENX_(__NR_getpgid, sys_getpgid), // 121
619 LINX_(__NR_setfsuid, sys_setfsuid), // 122
620 LINX_(__NR_setfsgid, sys_setfsgid), // 123
621 GENX_(__NR_getsid, sys_getsid), // 124
623 LINXY(__NR_capget, sys_capget), // 125
624 LINX_(__NR_capset, sys_capset), // 126
625 LINXY(__NR_rt_sigpending, sys_rt_sigpending), // 127
626 LINXY(__NR_rt_sigtimedwait, sys_rt_sigtimedwait),// 128
627 LINXY(__NR_rt_sigqueueinfo, sys_rt_sigqueueinfo),// 129
629 LINX_(__NR_rt_sigsuspend, sys_rt_sigsuspend), // 130
630 GENXY(__NR_sigaltstack, sys_sigaltstack), // 131
631 LINX_(__NR_utime, sys_utime), // 132
632 GENX_(__NR_mknod, sys_mknod), // 133
633 // (__NR_uselib, sys_uselib), // 134
635 LINX_(__NR_personality, sys_personality), // 135
636 // (__NR_ustat, sys_ustat), // 136
637 GENXY(__NR_statfs, sys_statfs), // 137
638 GENXY(__NR_fstatfs, sys_fstatfs), // 138
639 // (__NR_sysfs, sys_sysfs), // 139
641 GENX_(__NR_getpriority, sys_getpriority), // 140
642 GENX_(__NR_setpriority, sys_setpriority), // 141
643 LINXY(__NR_sched_setparam, sys_sched_setparam), // 142
644 LINXY(__NR_sched_getparam, sys_sched_getparam), // 143
645 LINX_(__NR_sched_setscheduler, sys_sched_setscheduler), // 144
647 LINX_(__NR_sched_getscheduler, sys_sched_getscheduler), // 145
648 LINX_(__NR_sched_get_priority_max, sys_sched_get_priority_max), // 146
649 LINX_(__NR_sched_get_priority_min, sys_sched_get_priority_min), // 147
650 LINXY(__NR_sched_rr_get_interval, sys_sched_rr_get_interval), // 148
651 GENX_(__NR_mlock, sys_mlock), // 149
653 GENX_(__NR_munlock, sys_munlock), // 150
654 GENX_(__NR_mlockall, sys_mlockall), // 151
655 LINX_(__NR_munlockall, sys_munlockall), // 152
656 LINX_(__NR_vhangup, sys_vhangup), // 153
657 // (__NR_modify_ldt, sys_modify_ldt), // 154
659 LINX_(__NR_pivot_root, sys_pivot_root), // 155
660 LINXY(__NR__sysctl, sys_sysctl), // 156
661 LINXY(__NR_prctl, sys_prctl), // 157
662 PLAX_(__NR_arch_prctl, sys_arch_prctl), // 158
663 LINXY(__NR_adjtimex, sys_adjtimex), // 159
665 GENX_(__NR_setrlimit, sys_setrlimit), // 160
666 GENX_(__NR_chroot, sys_chroot), // 161
667 GENX_(__NR_sync, sys_sync), // 162
668 // (__NR_acct, sys_acct), // 163
669 GENX_(__NR_settimeofday, sys_settimeofday), // 164
671 LINX_(__NR_mount, sys_mount), // 165
672 LINX_(__NR_umount2, sys_umount), // 166
673 // (__NR_swapon, sys_swapon), // 167
674 // (__NR_swapoff, sys_swapoff), // 168
675 // (__NR_reboot, sys_reboot), // 169
677 GENX_(__NR_sethostname, sys_sethostname), // 170
678 // (__NR_setdomainname, sys_setdomainname), // 171
679 GENX_(__NR_iopl, sys_iopl), // 172
680 LINX_(__NR_ioperm, sys_ioperm), // 173
681 GENX_(__NR_create_module, sys_ni_syscall), // 174
683 LINX_(__NR_init_module, sys_init_module), // 175
684 LINX_(__NR_delete_module, sys_delete_module), // 176
685 // (__NR_get_kernel_syms, sys_ni_syscall), // 177
686 // (__NR_query_module, sys_ni_syscall), // 178
687 LINX_(__NR_quotactl, sys_quotactl), // 179
689 // (__NR_nfsservctl, sys_nfsservctl), // 180
690 // (__NR_getpmsg, sys_ni_syscall), // 181
691 // (__NR_putpmsg, sys_ni_syscall), // 182
692 // (__NR_afs_syscall, sys_ni_syscall), // 183
693 PLAXY(184, sys_syscall184), // 184 // sys_bproc?
695 // (__NR_security, sys_ni_syscall), // 185
696 LINX_(__NR_gettid, sys_gettid), // 186
697 LINX_(__NR_readahead, sys_readahead), // 187
698 LINX_(__NR_setxattr, sys_setxattr), // 188
699 LINX_(__NR_lsetxattr, sys_lsetxattr), // 189
701 LINX_(__NR_fsetxattr, sys_fsetxattr), // 190
702 LINXY(__NR_getxattr, sys_getxattr), // 191
703 LINXY(__NR_lgetxattr, sys_lgetxattr), // 192
704 LINXY(__NR_fgetxattr, sys_fgetxattr), // 193
705 LINXY(__NR_listxattr, sys_listxattr), // 194
707 LINXY(__NR_llistxattr, sys_llistxattr), // 195
708 LINXY(__NR_flistxattr, sys_flistxattr), // 196
709 LINX_(__NR_removexattr, sys_removexattr), // 197
710 LINX_(__NR_lremovexattr, sys_lremovexattr), // 198
711 LINX_(__NR_fremovexattr, sys_fremovexattr), // 199
713 LINXY(__NR_tkill, sys_tkill), // 200
714 GENXY(__NR_time, sys_time), /*was sys_time64*/ // 201
715 LINXY(__NR_futex, sys_futex), // 202
716 LINX_(__NR_sched_setaffinity, sys_sched_setaffinity), // 203
717 LINXY(__NR_sched_getaffinity, sys_sched_getaffinity), // 204
719 // (__NR_set_thread_area, sys_ni_syscall), // 205
720 LINXY(__NR_io_setup, sys_io_setup), // 206
721 LINX_(__NR_io_destroy, sys_io_destroy), // 207
722 LINXY(__NR_io_getevents, sys_io_getevents), // 208
723 LINX_(__NR_io_submit, sys_io_submit), // 209
725 LINXY(__NR_io_cancel, sys_io_cancel), // 210
726 // (__NR_get_thread_area, sys_ni_syscall), // 211
727 LINXY(__NR_lookup_dcookie, sys_lookup_dcookie), // 212
728 LINXY(__NR_epoll_create, sys_epoll_create), // 213
729 // (__NR_epoll_ctl_old, sys_ni_syscall), // 214
731 // (__NR_epoll_wait_old, sys_ni_syscall), // 215
732 // (__NR_remap_file_pages, sys_remap_file_pages)// 216
733 GENXY(__NR_getdents64, sys_getdents64), // 217
734 LINX_(__NR_set_tid_address, sys_set_tid_address),// 218
735 // (__NR_restart_syscall, sys_restart_syscall),// 219
737 LINX_(__NR_semtimedop, sys_semtimedop), // 220
738 PLAX_(__NR_fadvise64, sys_fadvise64), // 221
739 LINXY(__NR_timer_create, sys_timer_create), // 222
740 LINXY(__NR_timer_settime, sys_timer_settime), // 223
741 LINXY(__NR_timer_gettime, sys_timer_gettime), // 224
743 LINX_(__NR_timer_getoverrun, sys_timer_getoverrun), // 225
744 LINX_(__NR_timer_delete, sys_timer_delete), // 226
745 LINX_(__NR_clock_settime, sys_clock_settime), // 227
746 LINXY(__NR_clock_gettime, sys_clock_gettime), // 228
747 LINXY(__NR_clock_getres, sys_clock_getres), // 229
749 LINXY(__NR_clock_nanosleep, sys_clock_nanosleep),// 230
750 LINX_(__NR_exit_group, sys_exit_group), // 231
751 LINXY(__NR_epoll_wait, sys_epoll_wait), // 232
752 LINX_(__NR_epoll_ctl, sys_epoll_ctl), // 233
753 LINXY(__NR_tgkill, sys_tgkill), // 234
755 GENX_(__NR_utimes, sys_utimes), // 235
756 // (__NR_vserver, sys_ni_syscall), // 236
757 LINX_(__NR_mbind, sys_mbind), // 237
758 LINX_(__NR_set_mempolicy, sys_set_mempolicy), // 238
759 LINXY(__NR_get_mempolicy, sys_get_mempolicy), // 239
761 LINXY(__NR_mq_open, sys_mq_open), // 240
762 LINX_(__NR_mq_unlink, sys_mq_unlink), // 241
763 LINX_(__NR_mq_timedsend, sys_mq_timedsend), // 242
764 LINXY(__NR_mq_timedreceive, sys_mq_timedreceive),// 243
765 LINX_(__NR_mq_notify, sys_mq_notify), // 244
767 LINXY(__NR_mq_getsetattr, sys_mq_getsetattr), // 245
768 // (__NR_kexec_load, sys_ni_syscall), // 246
769 LINXY(__NR_waitid, sys_waitid), // 247
770 LINX_(__NR_add_key, sys_add_key), // 248
771 LINX_(__NR_request_key, sys_request_key), // 249
773 LINXY(__NR_keyctl, sys_keyctl), // 250
774 LINX_(__NR_ioprio_set, sys_ioprio_set), // 251
775 LINX_(__NR_ioprio_get, sys_ioprio_get), // 252
776 LINX_(__NR_inotify_init, sys_inotify_init), // 253
777 LINX_(__NR_inotify_add_watch, sys_inotify_add_watch), // 254
779 LINX_(__NR_inotify_rm_watch, sys_inotify_rm_watch), // 255
780 // LINX_(__NR_migrate_pages, sys_migrate_pages), // 256
781 LINXY(__NR_openat, sys_openat), // 257
782 LINX_(__NR_mkdirat, sys_mkdirat), // 258
783 LINX_(__NR_mknodat, sys_mknodat), // 259
785 LINX_(__NR_fchownat, sys_fchownat), // 260
786 LINX_(__NR_futimesat, sys_futimesat), // 261
787 LINXY(__NR_newfstatat, sys_newfstatat), // 262
788 LINX_(__NR_unlinkat, sys_unlinkat), // 263
789 LINX_(__NR_renameat, sys_renameat), // 264
791 LINX_(__NR_linkat, sys_linkat), // 265
792 LINX_(__NR_symlinkat, sys_symlinkat), // 266
793 LINX_(__NR_readlinkat, sys_readlinkat), // 267
794 LINX_(__NR_fchmodat, sys_fchmodat), // 268
795 LINX_(__NR_faccessat, sys_faccessat), // 269
797 LINXY(__NR_pselect6, sys_pselect6), // 270
798 LINXY(__NR_ppoll, sys_ppoll), // 271
799 LINX_(__NR_unshare, sys_unshare), // 272
800 LINX_(__NR_set_robust_list, sys_set_robust_list), // 273
801 LINXY(__NR_get_robust_list, sys_get_robust_list), // 274
803 LINX_(__NR_splice, sys_splice), // 275
804 LINX_(__NR_tee, sys_tee), // 276
805 LINX_(__NR_sync_file_range, sys_sync_file_range), // 277
806 LINXY(__NR_vmsplice, sys_vmsplice), // 278
807 LINXY(__NR_move_pages, sys_move_pages), // 279
809 LINX_(__NR_utimensat, sys_utimensat), // 280
810 LINXY(__NR_epoll_pwait, sys_epoll_pwait), // 281
811 LINXY(__NR_signalfd, sys_signalfd), // 282
812 LINXY(__NR_timerfd_create, sys_timerfd_create), // 283
813 LINXY(__NR_eventfd, sys_eventfd), // 284
815 LINX_(__NR_fallocate, sys_fallocate), // 285
816 LINXY(__NR_timerfd_settime, sys_timerfd_settime), // 286
817 LINXY(__NR_timerfd_gettime, sys_timerfd_gettime), // 287
818 LINXY(__NR_accept4, sys_accept4), // 288
819 LINXY(__NR_signalfd4, sys_signalfd4), // 289
821 LINXY(__NR_eventfd2, sys_eventfd2), // 290
822 LINXY(__NR_epoll_create1, sys_epoll_create1), // 291
823 LINXY(__NR_dup3, sys_dup3), // 292
824 LINXY(__NR_pipe2, sys_pipe2), // 293
825 LINXY(__NR_inotify_init1, sys_inotify_init1), // 294
827 LINXY(__NR_preadv, sys_preadv), // 295
828 LINX_(__NR_pwritev, sys_pwritev), // 296
829 LINXY(__NR_rt_tgsigqueueinfo, sys_rt_tgsigqueueinfo),// 297
830 LINXY(__NR_perf_event_open, sys_perf_event_open), // 298
831 LINXY(__NR_recvmmsg, sys_recvmmsg), // 299
833 LINXY(__NR_fanotify_init, sys_fanotify_init), // 300
834 LINX_(__NR_fanotify_mark, sys_fanotify_mark), // 301
835 LINXY(__NR_prlimit64, sys_prlimit64), // 302
836 LINXY(__NR_name_to_handle_at, sys_name_to_handle_at),// 303
837 LINXY(__NR_open_by_handle_at, sys_open_by_handle_at),// 304
839 LINXY(__NR_clock_adjtime, sys_clock_adjtime), // 305
840 LINX_(__NR_syncfs, sys_syncfs), // 306
841 LINXY(__NR_sendmmsg, sys_sendmmsg), // 307
842 // LINX_(__NR_setns, sys_ni_syscall), // 308
843 LINXY(__NR_getcpu, sys_getcpu), // 309
845 LINXY(__NR_process_vm_readv, sys_process_vm_readv), // 310
846 LINX_(__NR_process_vm_writev, sys_process_vm_writev),// 311
847 LINX_(__NR_kcmp, sys_kcmp), // 312
848 LINX_(__NR_finit_module, sys_finit_module), // 313
849 // LIN__(__NR_sched_setattr, sys_ni_syscall), // 314
851 // LIN__(__NR_sched_getattr, sys_ni_syscall), // 315
852 LINX_(__NR_renameat2, sys_renameat2), // 316
853 // LIN__(__NR_seccomp, sys_ni_syscall), // 317
854 LINXY(__NR_getrandom, sys_getrandom), // 318
855 LINXY(__NR_memfd_create, sys_memfd_create), // 319
857 // LIN__(__NR_kexec_file_load, sys_ni_syscall), // 320
858 LINXY(__NR_bpf, sys_bpf), // 321
860 LINXY(__NR_preadv2, sys_preadv2), // 327
861 LINX_(__NR_pwritev2, sys_pwritev2), // 328
863 LINXY(__NR_statx, sys_statx), // 332
865 LINX_(__NR_membarrier, sys_membarrier), // 324
867 LINX_(__NR_copy_file_range, sys_copy_file_range), // 326
869 LINXY(__NR_pkey_mprotect, sys_pkey_mprotect), // 329
870 LINX_(__NR_pkey_alloc, sys_pkey_alloc), // 330
871 LINX_(__NR_pkey_free, sys_pkey_free), // 331
873 LINXY(__NR_io_uring_setup, sys_io_uring_setup), // 425
874 LINXY(__NR_io_uring_enter, sys_io_uring_enter), // 426
875 LINXY(__NR_io_uring_register, sys_io_uring_register), // 427
878 SyscallTableEntry* ML_(get_linux_syscall_entry) ( UInt sysno )
880 const UInt syscall_table_size
881 = sizeof(syscall_table) / sizeof(syscall_table[0]);
883 /* Is it in the contiguous initial section of the table? */
884 if (sysno < syscall_table_size) {
885 SyscallTableEntry* sys = &syscall_table[sysno];
886 if (sys->before == NULL)
887 return NULL; /* no entry */
888 else
889 return sys;
892 /* Can't find a wrapper */
893 return NULL;
896 #endif // defined(VGP_amd64_linux)
898 /*--------------------------------------------------------------------*/
899 /*--- end ---*/
900 /*--------------------------------------------------------------------*/