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