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 struct target_ipc_perm
{
62 uint32_t cuid
; /* creator user id */
63 uint32_t cgid
; /* creator group id */
64 uint32_t uid
; /* user id */
65 uint32_t gid
; /* group id */
66 uint16_t mode
; /* r/w permission */
67 uint16_t seq
; /* sequence # */
68 abi_long key
; /* user specified msg/sem/shm key */
71 #define TARGET_IPC_RMID 0 /* remove identifier */
72 #define TARGET_IPC_SET 1 /* set options */
73 #define TARGET_IPC_STAT 2 /* get options */
78 struct target_shmid_ds
{
79 struct target_ipc_perm shm_perm
; /* peration permission structure */
80 abi_ulong shm_segsz
; /* size of segment in bytes */
81 int32_t shm_lpid
; /* process ID of last shared memory op */
82 int32_t shm_cpid
; /* process ID of creator */
83 int32_t shm_nattch
; /* number of current attaches */
84 target_time_t shm_atime
; /* time of last shmat() */
85 target_time_t shm_dtime
; /* time of last shmdt() */
86 target_time_t shm_ctime
; /* time of last change by shmctl() */
89 #define N_BSD_SHM_REGIONS 32
90 struct bsd_shm_regions
{
98 #define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented */
100 #define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented */
102 #define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like a */
104 #define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync */
105 /* underlying file */
107 #define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7
109 #define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained after */
111 #define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, even */
113 #define TARGET_NETBSD_MAP_WIRED 0x0800 /* mlock() mapping when it is */
116 #define TARGET_NETBSD_MAP_STACK 0x2000 /* allocated from memory, */
117 /* swap space (stack) */
119 #define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7
121 #define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained after */
123 #define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change */
125 #define TARGET_OPENBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, */
126 /* even within heap */
128 #define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7
131 #define TARGET_BSD_MAP_FLAGMASK 0x3ff7
138 typedef abi_long target_freebsd_suseconds_t
;
140 /* compare to sys/timespec.h */
141 struct target_freebsd_timespec
{
142 target_time_t tv_sec
; /* seconds */
143 abi_long tv_nsec
; /* and nanoseconds */
144 #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
149 #define TARGET_CPUCLOCK_WHICH_PID 0
150 #define TARGET_CPUCLOCK_WHICH_TID 1
153 struct target_freebsd__umtx_time
{
154 struct target_freebsd_timespec _timeout
;
159 struct target_freebsd_timeval
{
160 target_time_t tv_sec
; /* seconds */
161 target_freebsd_suseconds_t tv_usec
;/* and microseconds */
162 #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
170 #define TARGET_RLIM_INFINITY RLIM_INFINITY
172 #define TARGET_RLIMIT_CPU 0
173 #define TARGET_RLIMIT_FSIZE 1
174 #define TARGET_RLIMIT_DATA 2
175 #define TARGET_RLIMIT_STACK 3
176 #define TARGET_RLIMIT_CORE 4
177 #define TARGET_RLIMIT_RSS 5
178 #define TARGET_RLIMIT_MEMLOCK 6
179 #define TARGET_RLIMIT_NPROC 7
180 #define TARGET_RLIMIT_NOFILE 8
181 #define TARGET_RLIMIT_SBSIZE 9
182 #define TARGET_RLIMIT_AS 10
183 #define TARGET_RLIMIT_NPTS 11
184 #define TARGET_RLIMIT_SWAP 12
186 struct target_rlimit
{
191 struct target_freebsd_rusage
{
192 struct target_freebsd_timeval ru_utime
; /* user time used */
193 struct target_freebsd_timeval ru_stime
; /* system time used */
194 abi_long ru_maxrss
; /* maximum resident set size */
195 abi_long ru_ixrss
; /* integral shared memory size */
196 abi_long ru_idrss
; /* integral unshared data size */
197 abi_long ru_isrss
; /* integral unshared stack size */
198 abi_long ru_minflt
; /* page reclaims */
199 abi_long ru_majflt
; /* page faults */
200 abi_long ru_nswap
; /* swaps */
201 abi_long ru_inblock
; /* block input operations */
202 abi_long ru_oublock
; /* block output operations */
203 abi_long ru_msgsnd
; /* messages sent */
204 abi_long ru_msgrcv
; /* messages received */
205 abi_long ru_nsignals
; /* signals received */
206 abi_long ru_nvcsw
; /* voluntary context switches */
207 abi_long ru_nivcsw
; /* involuntary context switches */
210 struct target_freebsd__wrusage
{
211 struct target_freebsd_rusage wru_self
;
212 struct target_freebsd_rusage wru_children
;
218 struct target_freebsd11_stat
{
219 uint32_t st_dev
; /* inode's device */
220 uint32_t st_ino
; /* inode's number */
221 int16_t st_mode
; /* inode protection mode */
222 int16_t st_nlink
; /* number of hard links */
223 uint32_t st_uid
; /* user ID of the file's owner */
224 uint32_t st_gid
; /* group ID of the file's group */
225 uint32_t st_rdev
; /* device type */
226 struct target_freebsd_timespec st_atim
; /* time last accessed */
227 struct target_freebsd_timespec st_mtim
; /* time last data modification */
228 struct target_freebsd_timespec st_ctim
; /* time last file status change */
229 int64_t st_size
; /* file size, in bytes */
230 int64_t st_blocks
; /* blocks allocated for file */
231 uint32_t st_blksize
; /* optimal blocksize for I/O */
232 uint32_t st_flags
; /* user defined flags for file */
233 uint32_t st_gen
; /* file generation number */
235 struct target_freebsd_timespec st_birthtim
; /* time of file creation */
237 * Explicitly pad st_birthtim to 16 bytes so that the size of
238 * struct stat is backwards compatible. We use bitfields instead
239 * of an array of chars so that this doesn't require a C99 compiler
240 * to compile if the size of the padding is 0. We use 2 bitfields
241 * to cover up to 64 bits on 32-bit machines. We assume that
244 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec
));
245 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec
));
248 #if defined(__i386__)
249 #define TARGET_HAS_STAT_TIME_T_EXT 1
253 uint64_t st_dev
; /* inode's device */
254 uint64_t st_ino
; /* inode's number */
255 uint64_t st_nlink
; /* number of hard links */
256 int16_t st_mode
; /* inode protection mode */
258 uint32_t st_uid
; /* user ID of the file's owner */
259 uint32_t st_gid
; /* group ID of the file's group */
261 uint64_t st_rdev
; /* device type */
262 #ifdef TARGET_HAS_STAT_TIME_T_EXT
265 struct target_freebsd_timespec st_atim
; /* time of last access */
266 #ifdef TARGET_HAS_STAT_TIME_T_EXT
269 struct target_freebsd_timespec st_mtim
; /* time of last data modification */
270 #ifdef TARGET_HAS_STAT_TIME_T_EXT
273 struct target_freebsd_timespec st_ctim
;/* time of last file status change */
274 #ifdef TARGET_HAS_STAT_TIME_T_EXT
277 struct target_freebsd_timespec st_birthtim
; /* time of file creation */
278 int64_t st_size
; /* file size, in bytes */
279 int64_t st_blocks
; /* blocks allocated for file */
280 uint32_t st_blksize
; /* optimal blocksize for I/O */
281 uint32_t st_flags
; /* user defined flags for file */
282 uint64_t st_gen
; /* file generation number */
283 uint64_t st_spare
[10];
287 /* struct nstat is the same as stat above but without the st_lspare field */
288 struct target_freebsd11_nstat
{
289 uint32_t st_dev
; /* inode's device */
290 uint32_t st_ino
; /* inode's number */
291 int16_t st_mode
; /* inode protection mode */
292 int16_t st_nlink
; /* number of hard links */
293 uint32_t st_uid
; /* user ID of the file's owner */
294 uint32_t st_gid
; /* group ID of the file's group */
295 uint32_t st_rdev
; /* device type */
296 struct target_freebsd_timespec st_atim
; /* time last accessed */
297 struct target_freebsd_timespec st_mtim
; /* time last data modification */
298 struct target_freebsd_timespec st_ctim
; /* time last file status change */
299 int64_t st_size
; /* file size, in bytes */
300 int64_t st_blocks
; /* blocks allocated for file */
301 uint32_t st_blksize
; /* optimal blocksize for I/O */
302 uint32_t st_flags
; /* user defined flags for file */
303 uint32_t st_gen
; /* file generation number */
304 struct target_freebsd_timespec st_birthtim
; /* time of file creation */
306 * Explicitly pad st_birthtim to 16 bytes so that the size of
307 * struct stat is backwards compatible. We use bitfields instead
308 * of an array of chars so that this doesn't require a C99 compiler
309 * to compile if the size of the padding is 0. We use 2 bitfields
310 * to cover up to 64 bits on 32-bit machines. We assume that
313 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec
));
314 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec
));
321 /* filesystem id type */
322 typedef struct target_freebsd_fsid
{ int32_t val
[2]; } target_freebsd_fsid_t
;
324 /* filesystem statistics */
325 struct target_freebsd11_statfs
{
326 uint32_t f_version
; /* structure version number */
327 uint32_t f_type
; /* type of filesystem */
328 uint64_t f_flags
; /* copy of mount exported flags */
329 uint64_t f_bsize
; /* filesystem fragment size */
330 uint64_t f_iosize
; /* optimal transfer block size */
331 uint64_t f_blocks
; /* total data blocks in filesystem */
332 uint64_t f_bfree
; /* free blocks in filesystem */
333 int64_t f_bavail
; /* free blocks avail to non-superuser */
334 uint64_t f_files
; /* total file nodes in filesystem */
335 int64_t f_ffree
; /* free nodes avail to non-superuser */
336 uint64_t f_syncwrites
; /* count of sync writes since mount */
337 uint64_t f_asyncwrites
; /* count of async writes since mount */
338 uint64_t f_syncreads
; /* count of sync reads since mount */
339 uint64_t f_asyncreads
; /* count of async reads since mount */
340 uint64_t f_spare
[10]; /* unused spare */
341 uint32_t f_namemax
; /* maximum filename length */
342 uint32_t f_owner
; /* user that mounted the filesystem */
343 target_freebsd_fsid_t f_fsid
; /* filesystem id */
344 char f_charspare
[80]; /* spare string space */
345 char f_fstypename
[16]; /* filesys type name */
346 char f_mntfromname
[88]; /* mount filesystem */
347 char f_mntonname
[88]; /* dir on which mounted*/
350 struct target_statfs
{
351 uint32_t f_version
; /* structure version number */
352 uint32_t f_type
; /* type of filesystem */
353 uint64_t f_flags
; /* copy of mount exported flags */
354 uint64_t f_bsize
; /* filesystem fragment size */
355 uint64_t f_iosize
; /* optimal transfer block size */
356 uint64_t f_blocks
; /* total data blocks in filesystem */
357 uint64_t f_bfree
; /* free blocks in filesystem */
358 int64_t f_bavail
; /* free blocks avail to non-superuser */
359 uint64_t f_files
; /* total file nodes in filesystem */
360 int64_t f_ffree
; /* free nodes avail to non-superuser */
361 uint64_t f_syncwrites
; /* count of sync writes since mount */
362 uint64_t f_asyncwrites
; /* count of async writes since mount */
363 uint64_t f_syncreads
; /* count of sync reads since mount */
364 uint64_t f_asyncreads
; /* count of async reads since mount */
365 uint64_t f_spare
[10]; /* unused spare */
366 uint32_t f_namemax
; /* maximum filename length */
367 uint32_t f_owner
; /* user that mounted the filesystem */
368 target_freebsd_fsid_t f_fsid
; /* filesystem id */
369 char f_charspare
[80]; /* spare string space */
370 char f_fstypename
[16]; /* filesystem type name */
371 char f_mntfromname
[1024]; /* mounted filesystem */
372 char f_mntonname
[1024]; /* directory on which mounted */
375 /* File identifier. These are unique per filesystem on a single machine. */
376 #define TARGET_MAXFIDSZ 16
378 struct target_freebsd_fid
{
379 uint16_t fid_len
; /* len of data in bytes */
380 uint16_t fid_data0
; /* force longword align */
381 char fid_data
[TARGET_MAXFIDSZ
]; /* data (variable len) */
384 /* Generic file handle */
385 struct target_freebsd_fhandle
{
386 target_freebsd_fsid_t fh_fsid
; /* Filesystem id of mount point */
387 struct target_freebsd_fid fh_fid
; /* Filesys specific id */
389 typedef struct target_freebsd_fhandle target_freebsd_fhandle_t
;
394 #define TARGET_F_DUPFD 0
395 #define TARGET_F_GETFD 1
396 #define TARGET_F_SETFD 2
397 #define TARGET_F_GETFL 3
398 #define TARGET_F_SETFL 4
399 #define TARGET_F_GETOWN 5
400 #define TARGET_F_SETOWN 6
401 #define TARGET_F_OGETLK 7
402 #define TARGET_F_OSETLK 8
403 #define TARGET_F_OSETLKW 9
404 #define TARGET_F_DUP2FD 10
405 #define TARGET_F_GETLK 11
406 #define TARGET_F_SETLK 12
407 #define TARGET_F_SETLKW 13
408 #define TARGET_F_SETLK_REMOTE 14
409 #define TARGET_F_READAHEAD 15
410 #define TARGET_F_RDAHEAD 16
411 #define TARGET_F_DUPFD_CLOEXEC 17
412 #define TARGET_F_DUP2FD_CLOEXEC 18
413 /* FreeBSD-specific */
414 #define TARGET_F_ADD_SEALS 19
415 #define TARGET_F_GET_SEALS 20
417 struct target_freebsd_flock
{
427 /* user: vfork(2) semantics, clear signals */
428 #define TARGET_RFSPAWN (1U << 31)
433 #define TARGET_PROC_SPROTECT 1
434 #define TARGET_PROC_REAP_ACQUIRE 2
435 #define TARGET_PROC_REAP_RELEASE 3
436 #define TARGET_PROC_REAP_STATUS 4
437 #define TARGET_PROC_REAP_GETPIDS 5
438 #define TARGET_PROC_REAP_KILL 6
440 struct target_procctl_reaper_status
{
442 uint32_t rs_children
;
443 uint32_t rs_descendants
;
446 uint32_t rs_pad0
[15];
449 struct target_procctl_reaper_pidinfo
{
453 uint32_t pi_pad0
[15];
456 struct target_procctl_reaper_pids
{
458 uint32_t rp_pad0
[15];
462 struct target_procctl_reaper_kill
{
468 uint32_t rk_pad0
[15];
472 #define safe_syscall0(type, name) \
473 type safe_##name(void) \
475 return safe_syscall(SYS_##name); \
478 #define safe_syscall1(type, name, type1, arg1) \
479 type safe_##name(type1 arg1) \
481 return safe_syscall(SYS_##name, arg1); \
484 #define safe_syscall2(type, name, type1, arg1, type2, arg2) \
485 type safe_##name(type1 arg1, type2 arg2) \
487 return safe_syscall(SYS_##name, arg1, arg2); \
490 #define safe_syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
491 type safe_##name(type1 arg1, type2 arg2, type3 arg3) \
493 return safe_syscall(SYS_##name, arg1, arg2, arg3); \
496 #define safe_syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
498 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
500 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4); \
503 #define safe_syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
504 type4, arg4, type5, arg5) \
505 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
508 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5); \
511 #define safe_syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
512 type4, arg4, type5, arg5, type6, arg6) \
513 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
514 type5 arg5, type6 arg6) \
516 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
519 #define safe_fcntl(...) safe_syscall(SYS_fcntl, __VA_ARGS__)
521 /* So far all target and host bitmasks are the same */
522 #undef target_to_host_bitmask
523 #define target_to_host_bitmask(x, tbl) (x)
524 #undef host_to_target_bitmask
525 #define host_to_target_bitmask(x, tbl) (x)
527 #endif /* SYSCALL_DEFS_H */