2 * System call related declarations
4 * Copyright (c) 2013-15 Stacey D. Son (sson at FreeBSD)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef SYSCALL_DEFS_H
21 #define SYSCALL_DEFS_H
23 #include <sys/syscall.h>
24 #include <sys/resource.h>
26 #include "errno_defs.h"
28 #include "freebsd/syscall_nr.h"
29 #include "netbsd/syscall_nr.h"
30 #include "openbsd/syscall_nr.h"
38 * time_t seems to be very inconsistly defined for the different *BSD's...
40 * FreeBSD uses a 64bits time_t except on i386
41 * so we have to add a special case here.
43 * On NetBSD time_t is always defined as an int64_t. On OpenBSD time_t
44 * is always defined as an int.
47 #if (!defined(TARGET_I386))
48 typedef int64_t target_time_t;
50 typedef int32_t target_time_t;
54 abi_long iov_base; /* Starting address */
55 abi_long iov_len; /* Number of bytes */
61 #define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented */
63 #define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented */
65 #define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like a */
67 #define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync */
70 #define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7
72 #define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained after */
74 #define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, even */
76 #define TARGET_NETBSD_MAP_WIRED 0x0800 /* mlock() mapping when it is */
79 #define TARGET_NETBSD_MAP_STACK 0x2000 /* allocated from memory, */
80 /* swap space (stack) */
82 #define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7
84 #define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained after */
86 #define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change */
88 #define TARGET_OPENBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, */
89 /* even within heap */
91 #define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7
94 #define TARGET_BSD_MAP_FLAGMASK 0x3ff7
101 typedef abi_long target_freebsd_suseconds_t;
103 /* compare to sys/timespec.h */
104 struct target_freebsd_timespec {
105 target_time_t tv_sec; /* seconds */
106 abi_long tv_nsec; /* and nanoseconds */
107 #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
112 #define TARGET_CPUCLOCK_WHICH_PID 0
113 #define TARGET_CPUCLOCK_WHICH_TID 1
116 struct target_freebsd__umtx_time {
117 struct target_freebsd_timespec _timeout;
122 struct target_freebsd_timeval {
123 target_time_t tv_sec; /* seconds */
124 target_freebsd_suseconds_t tv_usec;/* and microseconds */
125 #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
133 #if defined(__FreeBSD__)
134 #define TARGET_RLIM_INFINITY RLIM_INFINITY
136 #define TARGET_RLIM_INFINITY ((abi_ulong)-1)
139 #define TARGET_RLIMIT_CPU 0
140 #define TARGET_RLIMIT_FSIZE 1
141 #define TARGET_RLIMIT_DATA 2
142 #define TARGET_RLIMIT_STACK 3
143 #define TARGET_RLIMIT_CORE 4
144 #define TARGET_RLIMIT_RSS 5
145 #define TARGET_RLIMIT_MEMLOCK 6
146 #define TARGET_RLIMIT_NPROC 7
147 #define TARGET_RLIMIT_NOFILE 8
148 #define TARGET_RLIMIT_SBSIZE 9
149 #define TARGET_RLIMIT_AS 10
150 #define TARGET_RLIMIT_NPTS 11
151 #define TARGET_RLIMIT_SWAP 12
153 struct target_rlimit {
158 struct target_freebsd_rusage {
159 struct target_freebsd_timeval ru_utime; /* user time used */
160 struct target_freebsd_timeval ru_stime; /* system time used */
161 abi_long ru_maxrss; /* maximum resident set size */
162 abi_long ru_ixrss; /* integral shared memory size */
163 abi_long ru_idrss; /* integral unshared data size */
164 abi_long ru_isrss; /* integral unshared stack size */
165 abi_long ru_minflt; /* page reclaims */
166 abi_long ru_majflt; /* page faults */
167 abi_long ru_nswap; /* swaps */
168 abi_long ru_inblock; /* block input operations */
169 abi_long ru_oublock; /* block output operations */
170 abi_long ru_msgsnd; /* messages sent */
171 abi_long ru_msgrcv; /* messages received */
172 abi_long ru_nsignals; /* signals received */
173 abi_long ru_nvcsw; /* voluntary context switches */
174 abi_long ru_nivcsw; /* involuntary context switches */
177 struct target_freebsd__wrusage {
178 struct target_freebsd_rusage wru_self;
179 struct target_freebsd_rusage wru_children;
185 struct target_freebsd11_stat {
186 uint32_t st_dev; /* inode's device */
187 uint32_t st_ino; /* inode's number */
188 int16_t st_mode; /* inode protection mode */
189 int16_t st_nlink; /* number of hard links */
190 uint32_t st_uid; /* user ID of the file's owner */
191 uint32_t st_gid; /* group ID of the file's group */
192 uint32_t st_rdev; /* device type */
193 struct target_freebsd_timespec st_atim; /* time last accessed */
194 struct target_freebsd_timespec st_mtim; /* time last data modification */
195 struct target_freebsd_timespec st_ctim; /* time last file status change */
196 int64_t st_size; /* file size, in bytes */
197 int64_t st_blocks; /* blocks allocated for file */
198 uint32_t st_blksize; /* optimal blocksize for I/O */
199 uint32_t st_flags; /* user defined flags for file */
200 uint32_t st_gen; /* file generation number */
202 struct target_freebsd_timespec st_birthtim; /* time of file creation */
204 * Explicitly pad st_birthtim to 16 bytes so that the size of
205 * struct stat is backwards compatible. We use bitfields instead
206 * of an array of chars so that this doesn't require a C99 compiler
207 * to compile if the size of the padding is 0. We use 2 bitfields
208 * to cover up to 64 bits on 32-bit machines. We assume that
211 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
212 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
215 #if defined(__i386__)
216 #define TARGET_HAS_STAT_TIME_T_EXT 1
220 uint64_t st_dev; /* inode's device */
221 uint64_t st_ino; /* inode's number */
222 uint64_t st_nlink; /* number of hard links */
223 int16_t st_mode; /* inode protection mode */
225 uint32_t st_uid; /* user ID of the file's owner */
226 uint32_t st_gid; /* group ID of the file's group */
228 uint64_t st_rdev; /* device type */
229 #ifdef TARGET_HAS_STAT_TIME_T_EXT
232 struct target_freebsd_timespec st_atim; /* time of last access */
233 #ifdef TARGET_HAS_STAT_TIME_T_EXT
236 struct target_freebsd_timespec st_mtim; /* time of last data modification */
237 #ifdef TARGET_HAS_STAT_TIME_T_EXT
240 struct target_freebsd_timespec st_ctim;/* time of last file status change */
241 #ifdef TARGET_HAS_STAT_TIME_T_EXT
244 struct target_freebsd_timespec st_birthtim; /* time of file creation */
245 int64_t st_size; /* file size, in bytes */
246 int64_t st_blocks; /* blocks allocated for file */
247 uint32_t st_blksize; /* optimal blocksize for I/O */
248 uint32_t st_flags; /* user defined flags for file */
249 uint64_t st_gen; /* file generation number */
250 uint64_t st_spare[10];
254 /* struct nstat is the same as stat above but without the st_lspare field */
255 struct target_freebsd11_nstat {
256 uint32_t st_dev; /* inode's device */
257 uint32_t st_ino; /* inode's number */
258 int16_t st_mode; /* inode protection mode */
259 int16_t st_nlink; /* number of hard links */
260 uint32_t st_uid; /* user ID of the file's owner */
261 uint32_t st_gid; /* group ID of the file's group */
262 uint32_t st_rdev; /* device type */
263 struct target_freebsd_timespec st_atim; /* time last accessed */
264 struct target_freebsd_timespec st_mtim; /* time last data modification */
265 struct target_freebsd_timespec st_ctim; /* time last file status change */
266 int64_t st_size; /* file size, in bytes */
267 int64_t st_blocks; /* blocks allocated for file */
268 uint32_t st_blksize; /* optimal blocksize for I/O */
269 uint32_t st_flags; /* user defined flags for file */
270 uint32_t st_gen; /* file generation number */
271 struct target_freebsd_timespec st_birthtim; /* time of file creation */
273 * Explicitly pad st_birthtim to 16 bytes so that the size of
274 * struct stat is backwards compatible. We use bitfields instead
275 * of an array of chars so that this doesn't require a C99 compiler
276 * to compile if the size of the padding is 0. We use 2 bitfields
277 * to cover up to 64 bits on 32-bit machines. We assume that
280 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
281 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
288 /* filesystem id type */
289 typedef struct target_freebsd_fsid { int32_t val[2]; } target_freebsd_fsid_t;
291 /* filesystem statistics */
292 struct target_freebsd11_statfs {
293 uint32_t f_version; /* structure version number */
294 uint32_t f_type; /* type of filesystem */
295 uint64_t f_flags; /* copy of mount exported flags */
296 uint64_t f_bsize; /* filesystem fragment size */
297 uint64_t f_iosize; /* optimal transfer block size */
298 uint64_t f_blocks; /* total data blocks in filesystem */
299 uint64_t f_bfree; /* free blocks in filesystem */
300 int64_t f_bavail; /* free blocks avail to non-superuser */
301 uint64_t f_files; /* total file nodes in filesystem */
302 int64_t f_ffree; /* free nodes avail to non-superuser */
303 uint64_t f_syncwrites; /* count of sync writes since mount */
304 uint64_t f_asyncwrites; /* count of async writes since mount */
305 uint64_t f_syncreads; /* count of sync reads since mount */
306 uint64_t f_asyncreads; /* count of async reads since mount */
307 uint64_t f_spare[10]; /* unused spare */
308 uint32_t f_namemax; /* maximum filename length */
309 uint32_t f_owner; /* user that mounted the filesystem */
310 target_freebsd_fsid_t f_fsid; /* filesystem id */
311 char f_charspare[80]; /* spare string space */
312 char f_fstypename[16]; /* filesys type name */
313 char f_mntfromname[88]; /* mount filesystem */
314 char f_mntonname[88]; /* dir on which mounted*/
317 struct target_statfs {
318 uint32_t f_version; /* structure version number */
319 uint32_t f_type; /* type of filesystem */
320 uint64_t f_flags; /* copy of mount exported flags */
321 uint64_t f_bsize; /* filesystem fragment size */
322 uint64_t f_iosize; /* optimal transfer block size */
323 uint64_t f_blocks; /* total data blocks in filesystem */
324 uint64_t f_bfree; /* free blocks in filesystem */
325 int64_t f_bavail; /* free blocks avail to non-superuser */
326 uint64_t f_files; /* total file nodes in filesystem */
327 int64_t f_ffree; /* free nodes avail to non-superuser */
328 uint64_t f_syncwrites; /* count of sync writes since mount */
329 uint64_t f_asyncwrites; /* count of async writes since mount */
330 uint64_t f_syncreads; /* count of sync reads since mount */
331 uint64_t f_asyncreads; /* count of async reads since mount */
332 uint64_t f_spare[10]; /* unused spare */
333 uint32_t f_namemax; /* maximum filename length */
334 uint32_t f_owner; /* user that mounted the filesystem */
335 target_freebsd_fsid_t f_fsid; /* filesystem id */
336 char f_charspare[80]; /* spare string space */
337 char f_fstypename[16]; /* filesystem type name */
338 char f_mntfromname[1024]; /* mounted filesystem */
339 char f_mntonname[1024]; /* directory on which mounted */
342 /* File identifier. These are unique per filesystem on a single machine. */
343 #define TARGET_MAXFIDSZ 16
345 struct target_freebsd_fid {
346 uint16_t fid_len; /* len of data in bytes */
347 uint16_t fid_data0; /* force longword align */
348 char fid_data[TARGET_MAXFIDSZ]; /* data (variable len) */
351 /* Generic file handle */
352 struct target_freebsd_fhandle {
353 target_freebsd_fsid_t fh_fsid; /* Filesystem id of mount point */
354 struct target_freebsd_fid fh_fid; /* Filesys specific id */
356 typedef struct target_freebsd_fhandle target_freebsd_fhandle_t;
361 #define TARGET_F_DUPFD 0
362 #define TARGET_F_GETFD 1
363 #define TARGET_F_SETFD 2
364 #define TARGET_F_GETFL 3
365 #define TARGET_F_SETFL 4
366 #define TARGET_F_GETOWN 5
367 #define TARGET_F_SETOWN 6
368 #define TARGET_F_OGETLK 7
369 #define TARGET_F_OSETLK 8
370 #define TARGET_F_OSETLKW 9
371 #define TARGET_F_DUP2FD 10
372 #define TARGET_F_GETLK 11
373 #define TARGET_F_SETLK 12
374 #define TARGET_F_SETLKW 13
375 #define TARGET_F_SETLK_REMOTE 14
376 #define TARGET_F_READAHEAD 15
377 #define TARGET_F_RDAHEAD 16
378 #define TARGET_F_DUPFD_CLOEXEC 17
379 #define TARGET_F_DUP2FD_CLOEXEC 18
380 /* FreeBSD-specific */
381 #define TARGET_F_ADD_SEALS 19
382 #define TARGET_F_GET_SEALS 20
384 struct target_freebsd_flock {
393 #define safe_syscall0(type, name) \
394 type safe_##name(void) \
396 return safe_syscall(SYS_##name); \
399 #define safe_syscall1(type, name, type1, arg1) \
400 type safe_##name(type1 arg1) \
402 return safe_syscall(SYS_##name, arg1); \
405 #define safe_syscall2(type, name, type1, arg1, type2, arg2) \
406 type safe_##name(type1 arg1, type2 arg2) \
408 return safe_syscall(SYS_##name, arg1, arg2); \
411 #define safe_syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
412 type safe_##name(type1 arg1, type2 arg2, type3 arg3) \
414 return safe_syscall(SYS_##name, arg1, arg2, arg3); \
417 #define safe_syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
419 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
421 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4); \
424 #define safe_syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
425 type4, arg4, type5, arg5) \
426 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
429 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5); \
432 #define safe_syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
433 type4, arg4, type5, arg5, type6, arg6) \
434 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
435 type5 arg5, type6 arg6) \
437 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
440 #define safe_fcntl(...) safe_syscall(SYS_fcntl, __VA_ARGS__)
442 /* So far all target and host bitmasks are the same */
443 #undef target_to_host_bitmask
444 #define target_to_host_bitmask(x, tbl) (x)
445 #undef host_to_target_bitmask
446 #define host_to_target_bitmask(x, tbl) (x)
448 #endif /* SYSCALL_DEFS_H */