FreeBSD: add file descriptor tracking for _umtx_op
[valgrind.git] / coregrind / m_syswrap / priv_syswrap-generic.h
blobec174a152007c0e066a9898e8338f8a2c9583fe1
2 /*--------------------------------------------------------------------*/
3 /*--- Private syscalls header. priv_syswrap-generic.h ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2000-2017 Julian Seward
11 jseward@acm.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 #ifndef __PRIV_SYSWRAP_GENERIC_H
30 #define __PRIV_SYSWRAP_GENERIC_H
32 #include "pub_core_basics.h" // ThreadId
33 #include "pub_core_vki.h" // vki_msghdr
34 #include "priv_types_n_macros.h" // DECL_TEMPLATE
37 /* Guess the client stack from the segment in which sp is mapped.
38 Register the guessed stack using VG_(register_stack).
39 Setup tst client_stack_highest_byte and client_stack_szB.
40 If sp is not in a mapped segment, does nothing. */
41 extern void ML_(guess_and_register_stack) (Addr sp, ThreadState* tst);
43 // Return true if address range entirely contained within client
44 // address space.
45 extern
46 Bool ML_(valid_client_addr)(Addr start, SizeT size, ThreadId tid,
47 const HChar *syscallname);
49 /* Handy small function to help stop wrappers from segfaulting when
50 presented with bogus client addresses. Is not used for generating
51 user-visible errors. */
52 extern Bool ML_(safe_to_deref) ( const void *start, SizeT size );
54 // Returns True if the signal is OK for the client to use.
55 extern Bool ML_(client_signal_OK)(Int sigNo);
57 // Return true if we're allowed to use or create this fd.
58 extern
59 Bool ML_(fd_allowed)(Int fd, const HChar *syscallname, ThreadId tid,
60 Bool isNewFD);
62 extern void ML_(record_fd_close) (ThreadId tid, Int fd);
63 extern void ML_(record_fd_close_range) (ThreadId tid, Int fd);
64 extern void ML_(record_fd_open_named) (ThreadId tid, Int fd);
65 extern void ML_(record_fd_open_nameless) (ThreadId tid, Int fd);
66 extern void ML_(record_fd_open_with_given_name)(ThreadId tid, Int fd,
67 const HChar *pathname);
69 // Return true if a given file descriptor is already recorded.
70 extern Bool ML_(fd_recorded)(Int fd);
71 // Returns a pathname representing a recorded fd.
72 // Returned string must not be modified nor free'd.
73 extern const HChar *ML_(find_fd_recorded_by_fd)(Int fd);
75 // Used when killing threads -- we must not kill a thread if it's the thread
76 // that would do Valgrind's final cleanup and output.
77 extern
78 Bool ML_(do_sigkill)(Int pid, Int tgid);
80 /* When a client mmap or munmap has been successfully done, both the core
81 and the tool need to be notified of the new mapping. Hence this fn. */
82 extern void
83 ML_(notify_core_and_tool_of_mmap) ( Addr a, SizeT len, UInt prot,
84 UInt mm_flags, Int fd, Off64T offset );
85 extern void
86 ML_(notify_core_and_tool_of_munmap) ( Addr a, SizeT len );
87 extern void
88 ML_(notify_core_and_tool_of_mprotect) ( Addr a, SizeT len, Int prot );
90 extern void
91 ML_(pre_mem_read_sockaddr) ( ThreadId tid, const HChar *description,
92 struct vki_sockaddr *sa, UInt salen );
93 extern void
94 ML_(buf_and_len_pre_check) ( ThreadId tid, Addr buf_p, Addr buflen_p,
95 const HChar* buf_s, const HChar* buflen_s );
96 extern void
97 ML_(buf_and_len_post_check) ( ThreadId tid, SysRes res,
98 Addr buf_p, Addr buflen_p, const HChar* s );
100 /* PRE and POST for unknown ioctls based on ioctl request encoding */
101 extern
102 void ML_(PRE_unknown_ioctl)(ThreadId tid, UWord request, UWord arg);
103 extern
104 void ML_(POST_unknown_ioctl)(ThreadId tid, UInt res, UWord request, UWord arg);
106 extern
107 void ML_(pre_argv_envp)(Addr a, ThreadId tid, const HChar *s1, const HChar *s2);
109 extern Bool
110 ML_(handle_auxv_open)(SyscallStatus *status, const HChar *filename,
111 int flags);
113 extern Bool
114 ML_(handle_self_exe_open)(SyscallStatus *status, const HChar *filename,
115 int flags);
117 /* Helper function for generic mprotect and linux pkey_mprotect. */
118 extern void handle_sys_mprotect (ThreadId tid, SyscallStatus *status,
119 Addr *addr, SizeT *len, Int *prot);
120 /* Helper functions for preadv/preadv2. */
121 extern
122 void handle_pre_sys_preadv(ThreadId tid, SyscallStatus* status,
123 Int fd, Addr vector, Int count,
124 const char *str);
125 extern
126 void handle_post_sys_preadv(ThreadId tid, SyscallStatus* status, Addr vector, Int count);
128 /* Helper function for pwritev/pwritev2. */
129 extern
130 void handle_sys_pwritev(ThreadId tid, SyscallStatus* status,
131 Int fd, Addr vector, Int count,
132 const char *str);
134 typedef enum {
135 EXECVE,
136 EXECVEAT,
137 FEXECVE
138 } ExecveType;
140 extern
141 void handle_pre_sys_execve(ThreadId tid, SyscallStatus *status, Addr pathname,
142 Addr arg_2, Addr arg_3, ExecveType execveType,
143 Bool check_pathptr);
145 DECL_TEMPLATE(generic, sys_ni_syscall); // * P -- unimplemented
146 DECL_TEMPLATE(generic, sys_exit);
147 DECL_TEMPLATE(generic, sys_fork);
148 DECL_TEMPLATE(generic, sys_read);
149 DECL_TEMPLATE(generic, sys_write);
150 DECL_TEMPLATE(generic, sys_open);
151 DECL_TEMPLATE(generic, sys_close);
152 DECL_TEMPLATE(generic, sys_waitpid);
153 DECL_TEMPLATE(generic, sys_creat);
154 DECL_TEMPLATE(generic, sys_link);
155 DECL_TEMPLATE(generic, sys_unlink);
156 DECL_TEMPLATE(generic, sys_execve); // (*??) P
157 DECL_TEMPLATE(generic, sys_chdir);
158 DECL_TEMPLATE(generic, sys_time);
159 DECL_TEMPLATE(generic, sys_mknod);
160 DECL_TEMPLATE(generic, sys_chmod);
161 DECL_TEMPLATE(generic, sys_getpid);
162 DECL_TEMPLATE(generic, sys_alarm);
163 DECL_TEMPLATE(generic, sys_pause);
164 DECL_TEMPLATE(generic, sys_access);
165 DECL_TEMPLATE(generic, sys_kill);
166 DECL_TEMPLATE(generic, sys_rename);
167 DECL_TEMPLATE(generic, sys_mkdir);
168 DECL_TEMPLATE(generic, sys_rmdir);
169 DECL_TEMPLATE(generic, sys_dup);
170 DECL_TEMPLATE(generic, sys_times);
171 DECL_TEMPLATE(generic, sys_setpgid);
172 DECL_TEMPLATE(generic, sys_umask);
173 DECL_TEMPLATE(generic, sys_dup2);
174 DECL_TEMPLATE(generic, sys_getppid);
175 DECL_TEMPLATE(generic, sys_getpgrp);
176 DECL_TEMPLATE(generic, sys_setsid);
177 DECL_TEMPLATE(generic, sys_munmap);
178 DECL_TEMPLATE(generic, sys_truncate);
179 DECL_TEMPLATE(generic, sys_ftruncate);
180 DECL_TEMPLATE(generic, sys_fchmod);
181 DECL_TEMPLATE(generic, sys_msync);
182 DECL_TEMPLATE(generic, sys_readv);
183 DECL_TEMPLATE(generic, sys_writev);
184 DECL_TEMPLATE(generic, sys_getsid);
185 DECL_TEMPLATE(generic, sys_fdatasync);
186 DECL_TEMPLATE(generic, sys_mlock);
187 DECL_TEMPLATE(generic, sys_munlock);
188 DECL_TEMPLATE(generic, sys_mlockall);
189 DECL_TEMPLATE(generic, sys_nanosleep);
190 DECL_TEMPLATE(generic, sys_mremap); // POSIX, but Linux arg order may be odd
191 DECL_TEMPLATE(generic, sys_getuid);
192 DECL_TEMPLATE(generic, sys_getgid);
193 DECL_TEMPLATE(generic, sys_geteuid);
194 DECL_TEMPLATE(generic, sys_getegid);
195 DECL_TEMPLATE(generic, sys_getpgid);
196 DECL_TEMPLATE(generic, sys_fsync);
197 DECL_TEMPLATE(generic, sys_wait4);
198 DECL_TEMPLATE(generic, sys_mprotect);
199 DECL_TEMPLATE(generic, sys_getcwd);
200 DECL_TEMPLATE(generic, sys_symlink);
201 DECL_TEMPLATE(generic, sys_getgroups);
202 DECL_TEMPLATE(generic, sys_setgroups); // SVr4, SVID, X/OPEN, 4.3BSD
203 DECL_TEMPLATE(generic, sys_chown);
204 DECL_TEMPLATE(generic, sys_setuid);
205 DECL_TEMPLATE(generic, sys_gettimeofday);
206 DECL_TEMPLATE(generic, sys_madvise);
207 DECL_TEMPLATE(generic, sys_sethostname);
209 // These ones aren't POSIX, but are in some standard and look reasonably
210 // generic, and are the same for all architectures under Linux.
211 DECL_TEMPLATE(generic, sys_nice); // SVr4, SVID EXT, AT&T, X/OPEN, BSD 4.3
212 DECL_TEMPLATE(generic, sys_sync); // SVr4, SVID, X/OPEN, BSD 4.3
213 DECL_TEMPLATE(generic, sys_brk); // 4.3BSD
214 DECL_TEMPLATE(generic, sys_acct); // SVR4, non-POSIX
215 DECL_TEMPLATE(generic, sys_chroot); // SVr4, SVID, 4.4BSD, X/OPEN
216 DECL_TEMPLATE(generic, sys_readlink); // X/OPEN, 4.4BSD
217 DECL_TEMPLATE(generic, sys_fchdir); // SVr4, SVID, POSIX, X/OPEN, 4.4BSD
218 DECL_TEMPLATE(generic, sys_getdents); // SVr4,SVID
219 DECL_TEMPLATE(generic, sys_select); // 4.4BSD
220 DECL_TEMPLATE(generic, sys_flock); // 4.4BSD
221 DECL_TEMPLATE(generic, sys_poll); // XPG4-UNIX
222 DECL_TEMPLATE(generic, sys_getrusage); // SVr4, 4.3BSD
223 DECL_TEMPLATE(generic, sys_stime); // SVr4, SVID, X/OPEN
224 DECL_TEMPLATE(generic, sys_settimeofday); // SVr4, 4.3BSD (non-POSIX)
225 DECL_TEMPLATE(generic, sys_getpriority); // SVr4, 4.4BSD
226 DECL_TEMPLATE(generic, sys_setpriority); // SVr4, 4.4BSD
227 DECL_TEMPLATE(generic, sys_setitimer); // SVr4, 4.4BSD
228 DECL_TEMPLATE(generic, sys_getitimer); // SVr4, 4.4BSD
229 DECL_TEMPLATE(generic, sys_setreuid); // 4.3BSD
230 DECL_TEMPLATE(generic, sys_setregid); // 4.3BSD
231 DECL_TEMPLATE(generic, sys_fchown); // SVr4,4.3BSD
232 DECL_TEMPLATE(generic, sys_setgid); // SVr4,SVID
233 DECL_TEMPLATE(generic, sys_utimes); // 4.3BSD
235 // May not be generic for every architecture under Linux.
236 DECL_TEMPLATE(generic, sys_sigaction); // (x86) P
238 // Funny names, not sure...
239 DECL_TEMPLATE(generic, sys_newstat); // * P
240 DECL_TEMPLATE(generic, sys_newlstat); // *
241 DECL_TEMPLATE(generic, sys_newfstat); // * P (SVr4,BSD4.3)
243 // For the remainder, not really sure yet
244 DECL_TEMPLATE(generic, sys_ptrace); // (x86?) (almost-P)
245 DECL_TEMPLATE(generic, sys_setrlimit); // SVr4, 4.3BSD
246 DECL_TEMPLATE(generic, sys_old_getrlimit); // SVr4, 4.3BSD L?
247 DECL_TEMPLATE(generic, sys_statfs); // * L?
248 DECL_TEMPLATE(generic, sys_fstatfs); // * L?
249 DECL_TEMPLATE(generic, sys_iopl); // (x86/amd64) L
250 DECL_TEMPLATE(generic, sys_newuname); // * P
251 DECL_TEMPLATE(generic, sys_pread64); // * (Unix98?)
252 DECL_TEMPLATE(generic, sys_pwrite64); // * (Unix98?)
253 DECL_TEMPLATE(generic, sys_sigaltstack); // (x86) (XPG4-UNIX)
254 DECL_TEMPLATE(generic, sys_getpmsg); // (?) (?)
255 DECL_TEMPLATE(generic, sys_putpmsg); // (?) (?)
256 DECL_TEMPLATE(generic, sys_getrlimit); // * (?)
257 DECL_TEMPLATE(generic, sys_truncate64); // %% (P?)
258 DECL_TEMPLATE(generic, sys_ftruncate64); // %% (P?)
259 DECL_TEMPLATE(generic, sys_lchown); // * (L?)
260 DECL_TEMPLATE(generic, sys_mincore); // * L?
261 DECL_TEMPLATE(generic, sys_getdents64); // * (SVr4,SVID?)
262 DECL_TEMPLATE(generic, sys_statfs64); // * (?)
263 DECL_TEMPLATE(generic, sys_fstatfs64); // * (?)
264 DECL_TEMPLATE(generic, sys_mlock2); // * L
267 /* ---------------------------------------------------------------------
268 Wrappers for sockets and ipc-ery. These are split into standalone
269 procedures because some platforms hides them inside multiplexors
270 (sys_socketcall and sys_ipc).
271 ------------------------------------------------------------------ */
273 #define TId ThreadId
274 #define UW UWord
275 #define SR SysRes
277 extern void ML_(generic_PRE_sys_socketpair) ( TId, UW, UW, UW, UW );
278 extern SysRes ML_(generic_POST_sys_socketpair) ( TId, SR, UW, UW, UW, UW );
279 extern SysRes ML_(generic_POST_sys_socket) ( TId, SR );
280 extern void ML_(generic_PRE_sys_bind) ( TId, UW, UW, UW );
281 extern void ML_(generic_PRE_sys_accept) ( TId, UW, UW, UW );
282 extern SysRes ML_(generic_POST_sys_accept) ( TId, SR, UW, UW, UW );
283 extern void ML_(generic_PRE_sys_sendto) ( TId, UW, UW, UW, UW, UW, UW );
284 extern void ML_(generic_PRE_sys_send) ( TId, UW, UW, UW );
285 extern void ML_(generic_PRE_sys_recvfrom) ( TId, UW, UW, UW, UW, UW, UW );
286 extern void ML_(generic_POST_sys_recvfrom) ( TId, SR, UW, UW, UW, UW, UW, UW );
287 extern void ML_(generic_PRE_sys_recv) ( TId, UW, UW, UW );
288 extern void ML_(generic_POST_sys_recv) ( TId, UW, UW, UW, UW );
289 extern void ML_(generic_PRE_sys_connect) ( TId, UW, UW, UW );
290 extern void ML_(generic_PRE_sys_setsockopt) ( TId, UW, UW, UW, UW, UW );
291 extern void ML_(generic_PRE_sys_getsockname) ( TId, UW, UW, UW );
292 extern void ML_(generic_POST_sys_getsockname) ( TId, SR, UW, UW, UW );
293 extern void ML_(generic_PRE_sys_getpeername) ( TId, UW, UW, UW );
294 extern void ML_(generic_POST_sys_getpeername) ( TId, SR, UW, UW, UW );
295 extern void ML_(generic_PRE_sys_sendmsg) ( TId, const HChar *,
296 struct vki_msghdr * );
297 extern void ML_(generic_PRE_sys_recvmsg) ( TId, const HChar *,
298 struct vki_msghdr * );
299 extern void ML_(generic_POST_sys_recvmsg) ( TId, const HChar *,
300 struct vki_msghdr *, UInt );
302 extern void ML_(generic_PRE_sys_semop) ( TId, UW, UW, UW );
303 extern void ML_(generic_PRE_sys_semtimedop) ( TId, UW, UW, UW, UW );
304 extern void ML_(generic_PRE_sys_semctl) ( TId, UW, UW, UW, UW );
305 extern void ML_(generic_POST_sys_semctl) ( TId, UW, UW, UW, UW, UW );
306 extern UWord ML_(generic_PRE_sys_shmat) ( TId, UW, UW, UW );
307 extern void ML_(generic_POST_sys_shmat) ( TId, UW, UW, UW, UW );
308 extern Bool ML_(generic_PRE_sys_shmdt) ( TId, UW );
309 extern void ML_(generic_POST_sys_shmdt) ( TId, UW, UW );
310 extern void ML_(generic_PRE_sys_shmctl) ( TId, UW, UW, UW );
311 extern void ML_(generic_POST_sys_shmctl) ( TId, UW, UW, UW, UW );
313 extern SysRes ML_(generic_PRE_sys_mmap) ( TId, UW, UW, UW, UW, UW, Off64T );
315 #define PRE_timeval_READ(zzname, zzarg) \
316 do { \
317 struct vki_timeval *zztv = (struct vki_timeval *)(zzarg); \
318 PRE_FIELD_READ(zzname, zztv->tv_sec); \
319 PRE_FIELD_READ(zzname, zztv->tv_usec); \
320 } while (0)
321 #define PRE_timeval_WRITE(zzname, zzarg) \
322 do { \
323 struct vki_timeval *zztv = (struct vki_timeval *)(zzarg); \
324 PRE_FIELD_WRITE(zzname, zztv->tv_sec); \
325 PRE_FIELD_WRITE(zzname, zztv->tv_usec); \
326 } while (0)
327 #define POST_timeval_WRITE(zzarg) \
328 do { \
329 struct vki_timeval *zztv = (struct vki_timeval *)(zzarg); \
330 POST_FIELD_WRITE(zztv->tv_sec); \
331 POST_FIELD_WRITE(zztv->tv_usec); \
332 } while (0)
335 #undef TId
336 #undef UW
337 #undef SR
340 /////////////////////////////////////////////////////////////////
343 #endif // __PRIV_SYSWRAP_GENERIC_H
345 /*--------------------------------------------------------------------*/
346 /*--- end ---*/
347 /*--------------------------------------------------------------------*/