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