2 /*--------------------------------------------------------------------*/
3 /*--- Linux-specific syscalls stuff. priv_syswrap-linux.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2000-2017 Nicholas Nethercote
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 The GNU General Public License is contained in the file COPYING.
31 #ifndef __PRIV_SYSWRAP_LINUX_H
32 #define __PRIV_SYSWRAP_LINUX_H
34 #include "pub_core_basics.h" // ThreadId
35 #include "priv_types_n_macros.h" // DECL_TEMPLATE
37 // Clone-related functions
38 extern Word
ML_(start_thread_NORETURN
) ( void* arg
);
39 extern Addr
ML_(allocstack
) ( ThreadId tid
);
40 extern void ML_(call_on_new_stack_0_1
) ( Addr stack
, Addr retaddr
,
41 void (*f
)(Word
), Word arg1
);
43 // Linux-specific (but non-arch-specific) syscalls
45 DECL_TEMPLATE(linux
, sys_clone
)
46 DECL_TEMPLATE(linux
, sys_mount
);
47 DECL_TEMPLATE(linux
, sys_oldumount
);
48 DECL_TEMPLATE(linux
, sys_umount
);
49 DECL_TEMPLATE(linux
, sys_perf_event_open
);
50 DECL_TEMPLATE(linux
, sys_preadv
);
51 DECL_TEMPLATE(linux
, sys_pwritev
);
52 DECL_TEMPLATE(linux
, sys_sendmmsg
);
53 DECL_TEMPLATE(linux
, sys_recvmmsg
);
54 DECL_TEMPLATE(linux
, sys_dup3
);
55 DECL_TEMPLATE(linux
, sys_getcpu
);
56 DECL_TEMPLATE(linux
, sys_splice
);
57 DECL_TEMPLATE(linux
, sys_tee
);
58 DECL_TEMPLATE(linux
, sys_vmsplice
);
59 DECL_TEMPLATE(linux
, sys_readahead
);
60 DECL_TEMPLATE(linux
, sys_move_pages
);
62 // clone is similar enough between linux variants to have a generic
63 // version, but which will call an extern defined in syswrap-<platform>-linux.c
64 DECL_TEMPLATE(linux
, sys_clone
);
66 // POSIX, but various sub-cases differ between Linux and Darwin.
67 DECL_TEMPLATE(linux
, sys_fcntl
);
68 DECL_TEMPLATE(linux
, sys_fcntl64
);
69 DECL_TEMPLATE(linux
, sys_ioctl
);
71 DECL_TEMPLATE(linux
, sys_setfsuid16
);
72 DECL_TEMPLATE(linux
, sys_setfsuid
);
73 DECL_TEMPLATE(linux
, sys_setfsgid16
);
74 DECL_TEMPLATE(linux
, sys_setfsgid
);
75 DECL_TEMPLATE(linux
, sys_setresuid16
); // man page says "non-standard";
76 DECL_TEMPLATE(linux
, sys_setresuid
); // man page says "non-standard"
77 DECL_TEMPLATE(linux
, sys_getresuid16
);
78 DECL_TEMPLATE(linux
, sys_getresuid
);
79 DECL_TEMPLATE(linux
, sys_setresgid16
); // man page says "non-standard"
80 DECL_TEMPLATE(linux
, sys_setresgid
); // man page says "non-standard"
81 DECL_TEMPLATE(linux
, sys_getresgid16
);
82 DECL_TEMPLATE(linux
, sys_getresgid
);
84 DECL_TEMPLATE(linux
, sys_exit_group
);
85 DECL_TEMPLATE(linux
, sys_llseek
);
86 DECL_TEMPLATE(linux
, sys_adjtimex
);
87 DECL_TEMPLATE(linux
, sys_ioperm
);
88 DECL_TEMPLATE(linux
, sys_syslog
);
89 DECL_TEMPLATE(linux
, sys_vhangup
);
90 DECL_TEMPLATE(linux
, sys_sysinfo
);
91 DECL_TEMPLATE(linux
, sys_personality
);
92 DECL_TEMPLATE(linux
, sys_pivot_root
);
93 DECL_TEMPLATE(linux
, sys_sysctl
);
94 DECL_TEMPLATE(linux
, sys_prctl
);
95 DECL_TEMPLATE(linux
, sys_sendfile
);
96 DECL_TEMPLATE(linux
, sys_sendfile64
);
97 DECL_TEMPLATE(linux
, sys_futex
);
98 DECL_TEMPLATE(linux
, sys_set_robust_list
);
99 DECL_TEMPLATE(linux
, sys_get_robust_list
);
100 DECL_TEMPLATE(linux
, sys_pselect6
);
101 DECL_TEMPLATE(linux
, sys_ppoll
);
103 DECL_TEMPLATE(linux
, sys_epoll_create
);
104 DECL_TEMPLATE(linux
, sys_epoll_create1
);
105 DECL_TEMPLATE(linux
, sys_epoll_ctl
);
106 DECL_TEMPLATE(linux
, sys_epoll_wait
);
107 DECL_TEMPLATE(linux
, sys_epoll_pwait
);
108 DECL_TEMPLATE(linux
, sys_eventfd
);
109 DECL_TEMPLATE(linux
, sys_eventfd2
);
111 DECL_TEMPLATE(linux
, sys_fallocate
);
113 DECL_TEMPLATE(linux
, sys_prlimit64
);
115 DECL_TEMPLATE(linux
, sys_gettid
);
116 DECL_TEMPLATE(linux
, sys_set_tid_address
);
117 DECL_TEMPLATE(linux
, sys_tkill
);
118 DECL_TEMPLATE(linux
, sys_tgkill
);
120 DECL_TEMPLATE(linux
, sys_fadvise64
);
121 DECL_TEMPLATE(linux
, sys_fadvise64_64
);
123 DECL_TEMPLATE(linux
, sys_io_setup
);
124 DECL_TEMPLATE(linux
, sys_io_destroy
);
125 DECL_TEMPLATE(linux
, sys_io_getevents
);
126 DECL_TEMPLATE(linux
, sys_io_submit
);
127 DECL_TEMPLATE(linux
, sys_io_cancel
);
129 DECL_TEMPLATE(linux
, sys_ioprio_set
);
130 DECL_TEMPLATE(linux
, sys_ioprio_get
);
132 DECL_TEMPLATE(linux
, sys_mbind
);
133 DECL_TEMPLATE(linux
, sys_set_mempolicy
);
134 DECL_TEMPLATE(linux
, sys_get_mempolicy
);
136 DECL_TEMPLATE(linux
, sys_inotify_init
);
137 DECL_TEMPLATE(linux
, sys_inotify_init1
);
138 DECL_TEMPLATE(linux
, sys_inotify_add_watch
);
139 DECL_TEMPLATE(linux
, sys_inotify_rm_watch
);
141 DECL_TEMPLATE(linux
, sys_mq_open
);
142 DECL_TEMPLATE(linux
, sys_mq_unlink
);
143 DECL_TEMPLATE(linux
, sys_mq_timedsend
);
144 DECL_TEMPLATE(linux
, sys_mq_timedreceive
);
145 DECL_TEMPLATE(linux
, sys_mq_notify
);
146 DECL_TEMPLATE(linux
, sys_mq_getsetattr
);
148 DECL_TEMPLATE(linux
, sys_clock_settime
);
149 DECL_TEMPLATE(linux
, sys_clock_gettime
);
150 DECL_TEMPLATE(linux
, sys_clock_getres
);
151 DECL_TEMPLATE(linux
, sys_clock_nanosleep
);
152 DECL_TEMPLATE(linux
, sys_clock_adjtime
);
154 DECL_TEMPLATE(linux
, sys_timer_create
); // Linux: varies across archs?
155 DECL_TEMPLATE(linux
, sys_timer_settime
);
156 DECL_TEMPLATE(linux
, sys_timer_gettime
);
157 DECL_TEMPLATE(linux
, sys_timer_getoverrun
);
158 DECL_TEMPLATE(linux
, sys_timer_delete
);
159 DECL_TEMPLATE(linux
, sys_timerfd_create
);
160 DECL_TEMPLATE(linux
, sys_timerfd_gettime
);
161 DECL_TEMPLATE(linux
, sys_timerfd_settime
);
163 DECL_TEMPLATE(linux
, sys_signalfd
);
164 DECL_TEMPLATE(linux
, sys_signalfd4
);
166 DECL_TEMPLATE(linux
, sys_capget
);
167 DECL_TEMPLATE(linux
, sys_capset
);
169 DECL_TEMPLATE(linux
, sys_openat
);
170 DECL_TEMPLATE(linux
, sys_mkdirat
);
171 DECL_TEMPLATE(linux
, sys_mknodat
);
172 DECL_TEMPLATE(linux
, sys_fchownat
);
173 DECL_TEMPLATE(linux
, sys_futimesat
);
174 DECL_TEMPLATE(linux
, sys_newfstatat
);
175 DECL_TEMPLATE(linux
, sys_unlinkat
);
176 DECL_TEMPLATE(linux
, sys_renameat
);
177 DECL_TEMPLATE(linux
, sys_renameat2
);
178 DECL_TEMPLATE(linux
, sys_linkat
);
179 DECL_TEMPLATE(linux
, sys_symlinkat
);
180 DECL_TEMPLATE(linux
, sys_readlinkat
);
181 DECL_TEMPLATE(linux
, sys_fchmodat
);
182 DECL_TEMPLATE(linux
, sys_faccessat
);
183 DECL_TEMPLATE(linux
, sys_utimensat
);
184 DECL_TEMPLATE(linux
, sys_name_to_handle_at
);
185 DECL_TEMPLATE(linux
, sys_open_by_handle_at
);
187 DECL_TEMPLATE(linux
, sys_add_key
);
188 DECL_TEMPLATE(linux
, sys_request_key
);
189 DECL_TEMPLATE(linux
, sys_keyctl
);
191 // These ones have 32-bit generic equivalents, but the 16-bit versions (they
192 // use 16-bit gid_t and uid_t types) seem to be Linux-specific.
193 DECL_TEMPLATE(linux
, sys_getuid16
);
194 DECL_TEMPLATE(linux
, sys_setuid16
);
195 DECL_TEMPLATE(linux
, sys_getgid16
);
196 DECL_TEMPLATE(linux
, sys_setgid16
);
197 DECL_TEMPLATE(linux
, sys_geteuid16
);
198 DECL_TEMPLATE(linux
, sys_getegid16
);
199 DECL_TEMPLATE(linux
, sys_setreuid16
);
200 DECL_TEMPLATE(linux
, sys_setregid16
);
201 DECL_TEMPLATE(linux
, sys_getgroups16
);
202 DECL_TEMPLATE(linux
, sys_setgroups16
);
204 // Again, these 16-bit versions are Linux-specific, the 32-bit versions are
206 DECL_TEMPLATE(linux
, sys_chown16
);
207 DECL_TEMPLATE(linux
, sys_fchown16
);
208 //DECL_TEMPLATE(linux, sys_lchown16); // not yet encountered
210 // Are these POSIX? In Darwin they have an extra parameter 'position',
212 DECL_TEMPLATE(linux
, sys_setxattr
);
213 DECL_TEMPLATE(linux
, sys_lsetxattr
);
214 DECL_TEMPLATE(linux
, sys_fsetxattr
);
215 DECL_TEMPLATE(linux
, sys_getxattr
);
216 DECL_TEMPLATE(linux
, sys_lgetxattr
);
217 DECL_TEMPLATE(linux
, sys_fgetxattr
);
218 DECL_TEMPLATE(linux
, sys_listxattr
);
219 DECL_TEMPLATE(linux
, sys_llistxattr
);
220 DECL_TEMPLATE(linux
, sys_flistxattr
);
221 DECL_TEMPLATE(linux
, sys_removexattr
);
222 DECL_TEMPLATE(linux
, sys_lremovexattr
);
223 DECL_TEMPLATE(linux
, sys_fremovexattr
);
225 // These are Posix, but not necessarily syscalls. Darwin only supports
226 // sched_get_priority_{min,max} and sched_yield, but as libc functions, not
228 DECL_TEMPLATE(linux
, sys_sched_setparam
);
229 DECL_TEMPLATE(linux
, sys_sched_getparam
);
230 DECL_TEMPLATE(linux
, sys_sched_setscheduler
);
231 DECL_TEMPLATE(linux
, sys_sched_getscheduler
);
232 DECL_TEMPLATE(linux
, sys_sched_yield
);
233 DECL_TEMPLATE(linux
, sys_sched_get_priority_max
);
234 DECL_TEMPLATE(linux
, sys_sched_get_priority_min
);
235 DECL_TEMPLATE(linux
, sys_sched_rr_get_interval
);
236 DECL_TEMPLATE(linux
, sys_sched_setaffinity
);
237 DECL_TEMPLATE(linux
, sys_sched_getaffinity
);
239 DECL_TEMPLATE(linux
, sys_unshare
);
241 // These ones have different parameters and/or return values on Darwin.
242 // Also, some archs on Linux do not match the generic wrapper for sys_pipe.
243 DECL_TEMPLATE(linux
, sys_munlockall
);
244 DECL_TEMPLATE(linux
, sys_pipe
);
245 DECL_TEMPLATE(linux
, sys_pipe2
);
246 DECL_TEMPLATE(linux
, sys_quotactl
);
247 DECL_TEMPLATE(linux
, sys_waitid
);
249 // Posix, but in Darwin utime is a libc function that calls syscall utimes.
250 DECL_TEMPLATE(linux
, sys_utime
);
252 // On Darwin, off_t is 64-bits even on 32-bit platforms.
253 DECL_TEMPLATE(linux
, sys_lseek
);
255 // Darwin (and probably other OSes) don't have the old_sigset_t type.
256 DECL_TEMPLATE(linux
, sys_sigpending
);
257 DECL_TEMPLATE(linux
, sys_sigprocmask
);
258 DECL_TEMPLATE(linux
, sys_sigaction
);
260 // I think these are Linux-specific?
261 DECL_TEMPLATE(linux
, sys_rt_sigaction
);
262 DECL_TEMPLATE(linux
, sys_rt_sigprocmask
);
263 DECL_TEMPLATE(linux
, sys_rt_sigpending
);
264 DECL_TEMPLATE(linux
, sys_rt_sigtimedwait
);
265 DECL_TEMPLATE(linux
, sys_rt_sigqueueinfo
);
266 DECL_TEMPLATE(linux
, sys_rt_tgsigqueueinfo
);
267 DECL_TEMPLATE(linux
, sys_rt_sigsuspend
);
270 DECL_TEMPLATE(linux
, sys_sync_file_range
);
271 DECL_TEMPLATE(linux
, sys_sync_file_range2
);
272 DECL_TEMPLATE(linux
, sys_stime
); /* maybe generic? I'm not sure */
274 // Linux specific (kernel modules)
275 DECL_TEMPLATE(linux
, sys_init_module
);
276 DECL_TEMPLATE(linux
, sys_finit_module
);
277 DECL_TEMPLATE(linux
, sys_delete_module
);
279 // Linux-specific (oprofile-related)
280 DECL_TEMPLATE(linux
, sys_lookup_dcookie
); // (*/32/64) L
282 // Linux-specific (new in Linux 3.2)
283 DECL_TEMPLATE(linux
, sys_process_vm_readv
);
284 DECL_TEMPLATE(linux
, sys_process_vm_writev
);
286 // Linux-specific (new in Linux 2.6.36)
287 DECL_TEMPLATE(linux
, sys_fanotify_init
);
288 DECL_TEMPLATE(linux
, sys_fanotify_mark
);
290 // Linux-specific (new in Linux 3.17)
291 DECL_TEMPLATE(linux
, sys_getrandom
);
292 DECL_TEMPLATE(linux
, sys_memfd_create
);
294 DECL_TEMPLATE(linux
, sys_syncfs
);
296 /* ---------------------------------------------------------------------
297 Wrappers for sockets and ipc-ery. These are split into standalone
298 procedures because x86-linux hides them inside multiplexors
299 (sys_socketcall and sys_ipc).
300 ------------------------------------------------------------------ */
306 extern void ML_(linux_PRE_sys_msgsnd
) ( TId
, UW
, UW
, UW
, UW
);
307 extern void ML_(linux_PRE_sys_msgrcv
) ( TId
, UW
, UW
, UW
, UW
, UW
);
308 extern void ML_(linux_POST_sys_msgrcv
) ( TId
, UW
, UW
, UW
, UW
, UW
, UW
);
309 extern void ML_(linux_PRE_sys_msgctl
) ( TId
, UW
, UW
, UW
);
310 extern void ML_(linux_POST_sys_msgctl
) ( TId
, UW
, UW
, UW
, UW
);
311 extern void ML_(linux_PRE_sys_getsockopt
) ( TId
, UW
, UW
, UW
, UW
, UW
);
312 extern void ML_(linux_POST_sys_getsockopt
) ( TId
, SR
, UW
, UW
, UW
, UW
, UW
);
313 extern void ML_(linux_PRE_sys_setsockopt
) ( TId
, UW
, UW
, UW
, UW
, UW
);
314 extern void ML_(linux_PRE_sys_recvmmsg
) ( TId
, UW
, UW
, UW
, UW
, UW
);
315 extern void ML_(linux_POST_sys_recvmmsg
) ( TId
, UW
, UW
, UW
, UW
, UW
, UW
);
316 extern void ML_(linux_PRE_sys_sendmmsg
) ( TId
, UW
, UW
, UW
, UW
);
317 extern void ML_(linux_POST_sys_sendmmsg
) ( TId
, UW
, UW
, UW
, UW
, UW
);
319 // Linux-specific (but non-arch-specific) ptrace wrapper helpers
320 extern void ML_(linux_PRE_getregset
) ( ThreadId
, long, long );
321 extern void ML_(linux_PRE_setregset
) ( ThreadId
, long, long );
322 extern void ML_(linux_POST_traceme
) ( ThreadId
);
323 extern void ML_(linux_POST_getregset
)( ThreadId
, long, long );
329 /* sys_ipc and sys_socketcall are multiplexors which implements several syscalls.
330 Used e.g. by x86, ppc32, ppc64, ... */
331 DECL_TEMPLATE(linux
, sys_ipc
);
332 DECL_TEMPLATE(linux
, sys_socketcall
);
334 /* Depending on the platform, the below are implemented as
335 direct syscalls or via the above sys_socketcall multiplexor. */
337 /* Direct ipc related syscalls. */
339 DECL_TEMPLATE(linux
, sys_semget
);
340 DECL_TEMPLATE(linux
, sys_semop
);
341 DECL_TEMPLATE(linux
, sys_semctl
);
342 DECL_TEMPLATE(linux
, sys_semtimedop
);
344 DECL_TEMPLATE(linux
, sys_shmat
);
345 DECL_TEMPLATE(linux
, sys_shmget
);
346 DECL_TEMPLATE(linux
, sys_shmdt
);
347 DECL_TEMPLATE(linux
, sys_shmctl
);
349 DECL_TEMPLATE(linux
, sys_msgget
);
350 DECL_TEMPLATE(linux
, sys_msgrcv
);
351 DECL_TEMPLATE(linux
, sys_msgsnd
);
352 DECL_TEMPLATE(linux
, sys_msgctl
);
354 /* Direct socket related syscalls. */
355 DECL_TEMPLATE(linux
, sys_socket
);
356 DECL_TEMPLATE(linux
, sys_setsockopt
);
357 DECL_TEMPLATE(linux
, sys_getsockopt
);
358 DECL_TEMPLATE(linux
, sys_connect
);
359 DECL_TEMPLATE(linux
, sys_accept
);
360 DECL_TEMPLATE(linux
, sys_accept4
);
361 DECL_TEMPLATE(linux
, sys_send
);
362 DECL_TEMPLATE(linux
, sys_sendto
);
363 DECL_TEMPLATE(linux
, sys_recv
);
364 DECL_TEMPLATE(linux
, sys_recvfrom
);
365 DECL_TEMPLATE(linux
, sys_sendmsg
);
366 DECL_TEMPLATE(linux
, sys_recvmsg
);
367 DECL_TEMPLATE(linux
, sys_shutdown
);
368 DECL_TEMPLATE(linux
, sys_bind
);
369 DECL_TEMPLATE(linux
, sys_listen
);
370 DECL_TEMPLATE(linux
, sys_getsockname
);
371 DECL_TEMPLATE(linux
, sys_getpeername
);
372 DECL_TEMPLATE(linux
, sys_socketpair
);
373 DECL_TEMPLATE(linux
, sys_kcmp
);
375 // Some arch specific functions called from syswrap-linux.c
376 extern Int
do_syscall_clone_x86_linux ( Word (*fn
)(void *),
383 extern SysRes
ML_(x86_sys_set_thread_area
) ( ThreadId tid
,
384 vki_modify_ldt_t
* info
);
385 extern void ML_(x86_setup_LDT_GDT
) ( /*OUT*/ ThreadArchState
*child
,
386 /*IN*/ ThreadArchState
*parent
);
388 extern Long
do_syscall_clone_amd64_linux ( Word (*fn
)(void *),
395 extern ULong
do_syscall_clone_ppc32_linux ( Word (*fn
)(void *),
402 extern ULong
do_syscall_clone_ppc64_linux ( Word (*fn
)(void *),
409 extern ULong
do_syscall_clone_s390x_linux ( void *stack
,
416 extern Long
do_syscall_clone_arm64_linux ( Word (*fn
)(void *),
423 extern ULong
do_syscall_clone_arm_linux ( Word (*fn
)(void *),
430 extern ULong
do_syscall_clone_mips64_linux ( Word (*fn
) (void *), /* a0 - 4 */
431 void* stack
, /* a1 - 5 */
432 Int flags
, /* a2 - 6 */
433 void* arg
, /* a3 - 7 */
434 Int
* parent_tid
, /* a4 - 8 */
435 void* tls_ptr
, /* a5 - 9 */
436 Int
* child_tid
); /* a6 - 10 */
437 extern UInt
do_syscall_clone_mips_linux ( Word (*fn
) (void *), //a0 0 32
438 void* stack
, //a1 4 36
440 void* arg
, //a3 12 44
441 Int
* child_tid
, //stack 16 48
442 Int
* parent_tid
, //stack 20 52
443 void* tls_ptr
); //stack 24 56
444 #endif // __PRIV_SYSWRAP_LINUX_H
446 /*--------------------------------------------------------------------*/
448 /*--------------------------------------------------------------------*/