1 2/*--------------------------------------------------------------------*/ 3/*--- Private syscalls header. priv_syswrap-generic.h ---*/ 4/*--------------------------------------------------------------------*/ 5 6/* 7 This file is part of Valgrind, a dynamic binary instrumentation 8 framework. 9 10 Copyright (C) 2000-2012 Julian Seward 11 jseward@acm.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_GENERIC_H 32#define __PRIV_SYSWRAP_GENERIC_H 33 34/* requires #include "priv_types_n_macros.h" */ 35 36 37// Return true if address range entirely contained within client 38// address space. 39extern 40Bool ML_(valid_client_addr)(Addr start, SizeT size, ThreadId tid, 41 const Char *syscallname); 42 43/* Handy small function to help stop wrappers from segfaulting when 44 presented with bogus client addresses. Is not used for generating 45 user-visible errors. */ 46extern Bool ML_(safe_to_deref) ( void* start, SizeT size ); 47 48// Returns True if the signal is OK for the client to use. 49extern Bool ML_(client_signal_OK)(Int sigNo); 50 51// Return true if we're allowed to use or create this fd. 52extern 53Bool ML_(fd_allowed)(Int fd, const Char *syscallname, ThreadId tid, Bool isNewFD); 54 55extern void ML_(record_fd_open_named) (ThreadId tid, Int fd); 56extern void ML_(record_fd_open_nameless) (ThreadId tid, Int fd); 57extern void ML_(record_fd_open_with_given_name)(ThreadId tid, Int fd, 58 char *pathname); 59 60// Used when killing threads -- we must not kill a thread if it's the thread 61// that would do Valgrind's final cleanup and output. 62extern 63Bool ML_(do_sigkill)(Int pid, Int tgid); 64 65/* When a client mmap or munmap has been successfully done, both the core 66 and the tool need to be notified of the new mapping. Hence this fn. */ 67extern void 68ML_(notify_core_and_tool_of_mmap) ( Addr a, SizeT len, UInt prot, 69 UInt mm_flags, Int fd, Off64T offset ); 70extern void 71ML_(notify_core_and_tool_of_munmap) ( Addr a, SizeT len ); 72extern void 73ML_(notify_core_and_tool_of_mprotect) ( Addr a, SizeT len, Int prot ); 74 75extern void 76ML_(buf_and_len_pre_check) ( ThreadId tid, Addr buf_p, Addr buflen_p, 77 Char* buf_s, Char* buflen_s ); 78extern void 79ML_(buf_and_len_post_check) ( ThreadId tid, SysRes res, 80 Addr buf_p, Addr buflen_p, Char* s ); 81 82/* PRE and POST for unknown ioctls based on ioctl request encoding */ 83extern 84void ML_(PRE_unknown_ioctl)(ThreadId tid, UWord request, UWord arg); 85extern 86void ML_(POST_unknown_ioctl)(ThreadId tid, UInt res, UWord request, UWord arg); 87 88 89DECL_TEMPLATE(generic, sys_ni_syscall); // * P -- unimplemented 90DECL_TEMPLATE(generic, sys_exit); 91DECL_TEMPLATE(generic, sys_fork); 92DECL_TEMPLATE(generic, sys_read); 93DECL_TEMPLATE(generic, sys_write); 94DECL_TEMPLATE(generic, sys_open); 95DECL_TEMPLATE(generic, sys_close); 96DECL_TEMPLATE(generic, sys_waitpid); 97DECL_TEMPLATE(generic, sys_creat); 98DECL_TEMPLATE(generic, sys_link); 99DECL_TEMPLATE(generic, sys_unlink); 100DECL_TEMPLATE(generic, sys_execve); // (*??) P 101DECL_TEMPLATE(generic, sys_chdir); 102DECL_TEMPLATE(generic, sys_time); 103DECL_TEMPLATE(generic, sys_mknod); 104DECL_TEMPLATE(generic, sys_chmod); 105DECL_TEMPLATE(generic, sys_getpid); 106DECL_TEMPLATE(generic, sys_alarm); 107DECL_TEMPLATE(generic, sys_pause); 108DECL_TEMPLATE(generic, sys_access); 109DECL_TEMPLATE(generic, sys_kill); 110DECL_TEMPLATE(generic, sys_rename); 111DECL_TEMPLATE(generic, sys_mkdir); 112DECL_TEMPLATE(generic, sys_rmdir); 113DECL_TEMPLATE(generic, sys_dup); 114DECL_TEMPLATE(generic, sys_times); 115DECL_TEMPLATE(generic, sys_setpgid); 116DECL_TEMPLATE(generic, sys_umask); 117DECL_TEMPLATE(generic, sys_dup2); 118DECL_TEMPLATE(generic, sys_getppid); 119DECL_TEMPLATE(generic, sys_getpgrp); 120DECL_TEMPLATE(generic, sys_setsid); 121DECL_TEMPLATE(generic, sys_munmap); 122DECL_TEMPLATE(generic, sys_truncate); 123DECL_TEMPLATE(generic, sys_ftruncate); 124DECL_TEMPLATE(generic, sys_fchmod); 125DECL_TEMPLATE(generic, sys_msync); 126DECL_TEMPLATE(generic, sys_readv); 127DECL_TEMPLATE(generic, sys_writev); 128DECL_TEMPLATE(generic, sys_getsid); 129DECL_TEMPLATE(generic, sys_fdatasync); 130DECL_TEMPLATE(generic, sys_mlock); 131DECL_TEMPLATE(generic, sys_munlock); 132DECL_TEMPLATE(generic, sys_mlockall); 133DECL_TEMPLATE(generic, sys_nanosleep); 134DECL_TEMPLATE(generic, sys_mremap); // POSIX, but Linux arg order may be odd 135DECL_TEMPLATE(generic, sys_getuid); 136DECL_TEMPLATE(generic, sys_getgid); 137DECL_TEMPLATE(generic, sys_geteuid); 138DECL_TEMPLATE(generic, sys_getegid); 139DECL_TEMPLATE(generic, sys_getpgid); 140DECL_TEMPLATE(generic, sys_fsync); 141DECL_TEMPLATE(generic, sys_wait4); 142DECL_TEMPLATE(generic, sys_mprotect); 143DECL_TEMPLATE(generic, sys_getcwd); 144DECL_TEMPLATE(generic, sys_symlink); 145DECL_TEMPLATE(generic, sys_getgroups); 146DECL_TEMPLATE(generic, sys_setgroups); // SVr4, SVID, X/OPEN, 4.3BSD 147DECL_TEMPLATE(generic, sys_chown); 148DECL_TEMPLATE(generic, sys_setuid); 149DECL_TEMPLATE(generic, sys_gettimeofday); 150DECL_TEMPLATE(generic, sys_madvise); 151 152// These ones aren't POSIX, but are in some standard and look reasonably 153// generic, and are the same for all architectures under Linux. 154DECL_TEMPLATE(generic, sys_nice); // SVr4, SVID EXT, AT&T, X/OPEN, BSD 4.3 155DECL_TEMPLATE(generic, sys_sync); // SVr4, SVID, X/OPEN, BSD 4.3 156DECL_TEMPLATE(generic, sys_brk); // 4.3BSD 157DECL_TEMPLATE(generic, sys_acct); // SVR4, non-POSIX 158DECL_TEMPLATE(generic, sys_chroot); // SVr4, SVID, 4.4BSD, X/OPEN 159DECL_TEMPLATE(generic, sys_readlink); // X/OPEN, 4.4BSD 160DECL_TEMPLATE(generic, sys_fchdir); // SVr4, SVID, POSIX, X/OPEN, 4.4BSD 161DECL_TEMPLATE(generic, sys_getdents); // SVr4,SVID 162DECL_TEMPLATE(generic, sys_select); // 4.4BSD 163DECL_TEMPLATE(generic, sys_flock); // 4.4BSD 164DECL_TEMPLATE(generic, sys_poll); // XPG4-UNIX 165DECL_TEMPLATE(generic, sys_getrusage); // SVr4, 4.3BSD 166DECL_TEMPLATE(generic, sys_stime); // SVr4, SVID, X/OPEN 167DECL_TEMPLATE(generic, sys_settimeofday); // SVr4, 4.3BSD (non-POSIX) 168DECL_TEMPLATE(generic, sys_getpriority); // SVr4, 4.4BSD 169DECL_TEMPLATE(generic, sys_setpriority); // SVr4, 4.4BSD 170DECL_TEMPLATE(generic, sys_setitimer); // SVr4, 4.4BSD 171DECL_TEMPLATE(generic, sys_getitimer); // SVr4, 4.4BSD 172DECL_TEMPLATE(generic, sys_setreuid); // 4.3BSD 173DECL_TEMPLATE(generic, sys_setregid); // 4.3BSD 174DECL_TEMPLATE(generic, sys_fchown); // SVr4,4.3BSD 175DECL_TEMPLATE(generic, sys_setgid); // SVr4,SVID 176DECL_TEMPLATE(generic, sys_utimes); // 4.3BSD 177 178// May not be generic for every architecture under Linux. 179DECL_TEMPLATE(generic, sys_sigaction); // (x86) P 180 181// Funny names, not sure... 182DECL_TEMPLATE(generic, sys_newstat); // * P 183DECL_TEMPLATE(generic, sys_newlstat); // * 184DECL_TEMPLATE(generic, sys_newfstat); // * P (SVr4,BSD4.3) 185 186// For the remainder, not really sure yet 187DECL_TEMPLATE(generic, sys_ptrace); // (x86?) (almost-P) 188DECL_TEMPLATE(generic, sys_setrlimit); // SVr4, 4.3BSD 189DECL_TEMPLATE(generic, sys_old_getrlimit); // SVr4, 4.3BSD L? 190DECL_TEMPLATE(generic, sys_statfs); // * L? 191DECL_TEMPLATE(generic, sys_fstatfs); // * L? 192DECL_TEMPLATE(generic, sys_iopl); // (x86/amd64) L 193DECL_TEMPLATE(generic, sys_ipc); // (x86) L 194DECL_TEMPLATE(generic, sys_newuname); // * P 195DECL_TEMPLATE(generic, sys_pread64); // * (Unix98?) 196DECL_TEMPLATE(generic, sys_pwrite64); // * (Unix98?) 197DECL_TEMPLATE(generic, sys_sigaltstack); // (x86) (XPG4-UNIX) 198DECL_TEMPLATE(generic, sys_getpmsg); // (?) (?) 199DECL_TEMPLATE(generic, sys_putpmsg); // (?) (?) 200DECL_TEMPLATE(generic, sys_getrlimit); // * (?) 201DECL_TEMPLATE(generic, sys_truncate64); // %% (P?) 202DECL_TEMPLATE(generic, sys_ftruncate64); // %% (P?) 203DECL_TEMPLATE(generic, sys_lchown); // * (L?) 204DECL_TEMPLATE(generic, sys_mincore); // * L? 205DECL_TEMPLATE(generic, sys_getdents64); // * (SVr4,SVID?) 206DECL_TEMPLATE(generic, sys_statfs64); // * (?) 207DECL_TEMPLATE(generic, sys_fstatfs64); // * (?) 208 209 210/* --------------------------------------------------------------------- 211 Wrappers for sockets and ipc-ery. These are split into standalone 212 procedures because x86-linux hides them inside multiplexors 213 (sys_socketcall and sys_ipc). 214 ------------------------------------------------------------------ */ 215 216#define TId ThreadId 217#define UW UWord 218#define SR SysRes 219 220extern void ML_(generic_PRE_sys_socketpair) ( TId, UW, UW, UW, UW ); 221extern SysRes ML_(generic_POST_sys_socketpair) ( TId, SR, UW, UW, UW, UW ); 222extern SysRes ML_(generic_POST_sys_socket) ( TId, SR ); 223extern void ML_(generic_PRE_sys_bind) ( TId, UW, UW, UW ); 224extern void ML_(generic_PRE_sys_accept) ( TId, UW, UW, UW ); 225extern SysRes ML_(generic_POST_sys_accept) ( TId, SR, UW, UW, UW ); 226extern void ML_(generic_PRE_sys_sendto) ( TId, UW, UW, UW, UW, UW, UW ); 227extern void ML_(generic_PRE_sys_send) ( TId, UW, UW, UW ); 228extern void ML_(generic_PRE_sys_recvfrom) ( TId, UW, UW, UW, UW, UW, UW ); 229extern void ML_(generic_POST_sys_recvfrom) ( TId, SR, UW, UW, UW, UW, UW, UW ); 230extern void ML_(generic_PRE_sys_recv) ( TId, UW, UW, UW ); 231extern void ML_(generic_POST_sys_recv) ( TId, UW, UW, UW, UW ); 232extern void ML_(generic_PRE_sys_connect) ( TId, UW, UW, UW ); 233extern void ML_(generic_PRE_sys_setsockopt) ( TId, UW, UW, UW, UW, UW ); 234extern void ML_(generic_PRE_sys_getsockname) ( TId, UW, UW, UW ); 235extern void ML_(generic_POST_sys_getsockname) ( TId, SR, UW, UW, UW ); 236extern void ML_(generic_PRE_sys_getpeername) ( TId, UW, UW, UW ); 237extern void ML_(generic_POST_sys_getpeername) ( TId, SR, UW, UW, UW ); 238extern void ML_(generic_PRE_sys_sendmsg) ( TId, Char *, struct vki_msghdr * ); 239extern void ML_(generic_PRE_sys_recvmsg) ( TId, Char *, struct vki_msghdr * ); 240extern void ML_(generic_POST_sys_recvmsg) ( TId, Char *, struct vki_msghdr *, UInt ); 241 242extern void ML_(generic_PRE_sys_semop) ( TId, UW, UW, UW ); 243extern void ML_(generic_PRE_sys_semtimedop) ( TId, UW, UW, UW, UW ); 244extern void ML_(generic_PRE_sys_semctl) ( TId, UW, UW, UW, UW ); 245extern void ML_(generic_POST_sys_semctl) ( TId, UW, UW, UW, UW, UW ); 246extern UWord ML_(generic_PRE_sys_shmat) ( TId, UW, UW, UW ); 247extern void ML_(generic_POST_sys_shmat) ( TId, UW, UW, UW, UW ); 248extern Bool ML_(generic_PRE_sys_shmdt) ( TId, UW ); 249extern void ML_(generic_POST_sys_shmdt) ( TId, UW, UW ); 250extern void ML_(generic_PRE_sys_shmctl) ( TId, UW, UW, UW ); 251extern void ML_(generic_POST_sys_shmctl) ( TId, UW, UW, UW, UW ); 252 253extern SysRes ML_(generic_PRE_sys_mmap) ( TId, UW, UW, UW, UW, UW, Off64T ); 254 255#define PRE_timeval_READ(zzname, zzarg) \ 256 do { \ 257 struct vki_timeval *zztv = (struct vki_timeval *)(zzarg); \ 258 PRE_FIELD_READ(zzname, zztv->tv_sec); \ 259 PRE_FIELD_READ(zzname, zztv->tv_usec); \ 260 } while (0) 261#define PRE_timeval_WRITE(zzname, zzarg) \ 262 do { \ 263 struct vki_timeval *zztv = (struct vki_timeval *)(zzarg); \ 264 PRE_FIELD_WRITE(zzname, zztv->tv_sec); \ 265 PRE_FIELD_WRITE(zzname, zztv->tv_usec); \ 266 } while (0) 267#define POST_timeval_WRITE(zzarg) \ 268 do { \ 269 struct vki_timeval *zztv = (struct vki_timeval *)(zzarg); \ 270 POST_FIELD_WRITE(zztv->tv_sec); \ 271 POST_FIELD_WRITE(zztv->tv_usec); \ 272 } while (0) 273 274 275#undef TId 276#undef UW 277#undef SR 278 279 280///////////////////////////////////////////////////////////////// 281 282 283#endif // __PRIV_SYSWRAP_GENERIC_H 284 285/*--------------------------------------------------------------------*/ 286/*--- end ---*/ 287/*--------------------------------------------------------------------*/ 288