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 #define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented */
80 #define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented */
82 #define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like a */
84 #define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync */
87 #define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7
89 #define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained after */
91 #define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, even */
93 #define TARGET_NETBSD_MAP_WIRED 0x0800 /* mlock() mapping when it is */
96 #define TARGET_NETBSD_MAP_STACK 0x2000 /* allocated from memory, */
97 /* swap space (stack) */
99 #define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7
101 #define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained after */
103 #define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change */
105 #define TARGET_OPENBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, */
106 /* even within heap */
108 #define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7
111 #define TARGET_BSD_MAP_FLAGMASK 0x3ff7
118 typedef abi_long target_freebsd_suseconds_t
;
120 /* compare to sys/timespec.h */
121 struct target_freebsd_timespec
{
122 target_time_t tv_sec
; /* seconds */
123 abi_long tv_nsec
; /* and nanoseconds */
124 #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
129 #define TARGET_CPUCLOCK_WHICH_PID 0
130 #define TARGET_CPUCLOCK_WHICH_TID 1
133 struct target_freebsd__umtx_time
{
134 struct target_freebsd_timespec _timeout
;
139 struct target_freebsd_timeval
{
140 target_time_t tv_sec
; /* seconds */
141 target_freebsd_suseconds_t tv_usec
;/* and microseconds */
142 #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
150 #define TARGET_RLIM_INFINITY RLIM_INFINITY
152 #define TARGET_RLIMIT_CPU 0
153 #define TARGET_RLIMIT_FSIZE 1
154 #define TARGET_RLIMIT_DATA 2
155 #define TARGET_RLIMIT_STACK 3
156 #define TARGET_RLIMIT_CORE 4
157 #define TARGET_RLIMIT_RSS 5
158 #define TARGET_RLIMIT_MEMLOCK 6
159 #define TARGET_RLIMIT_NPROC 7
160 #define TARGET_RLIMIT_NOFILE 8
161 #define TARGET_RLIMIT_SBSIZE 9
162 #define TARGET_RLIMIT_AS 10
163 #define TARGET_RLIMIT_NPTS 11
164 #define TARGET_RLIMIT_SWAP 12
166 struct target_rlimit
{
171 struct target_freebsd_rusage
{
172 struct target_freebsd_timeval ru_utime
; /* user time used */
173 struct target_freebsd_timeval ru_stime
; /* system time used */
174 abi_long ru_maxrss
; /* maximum resident set size */
175 abi_long ru_ixrss
; /* integral shared memory size */
176 abi_long ru_idrss
; /* integral unshared data size */
177 abi_long ru_isrss
; /* integral unshared stack size */
178 abi_long ru_minflt
; /* page reclaims */
179 abi_long ru_majflt
; /* page faults */
180 abi_long ru_nswap
; /* swaps */
181 abi_long ru_inblock
; /* block input operations */
182 abi_long ru_oublock
; /* block output operations */
183 abi_long ru_msgsnd
; /* messages sent */
184 abi_long ru_msgrcv
; /* messages received */
185 abi_long ru_nsignals
; /* signals received */
186 abi_long ru_nvcsw
; /* voluntary context switches */
187 abi_long ru_nivcsw
; /* involuntary context switches */
190 struct target_freebsd__wrusage
{
191 struct target_freebsd_rusage wru_self
;
192 struct target_freebsd_rusage wru_children
;
198 struct target_freebsd11_stat
{
199 uint32_t st_dev
; /* inode's device */
200 uint32_t st_ino
; /* inode's number */
201 int16_t st_mode
; /* inode protection mode */
202 int16_t st_nlink
; /* number of hard links */
203 uint32_t st_uid
; /* user ID of the file's owner */
204 uint32_t st_gid
; /* group ID of the file's group */
205 uint32_t st_rdev
; /* device type */
206 struct target_freebsd_timespec st_atim
; /* time last accessed */
207 struct target_freebsd_timespec st_mtim
; /* time last data modification */
208 struct target_freebsd_timespec st_ctim
; /* time last file status change */
209 int64_t st_size
; /* file size, in bytes */
210 int64_t st_blocks
; /* blocks allocated for file */
211 uint32_t st_blksize
; /* optimal blocksize for I/O */
212 uint32_t st_flags
; /* user defined flags for file */
213 uint32_t st_gen
; /* file generation number */
215 struct target_freebsd_timespec st_birthtim
; /* time of file creation */
217 * Explicitly pad st_birthtim to 16 bytes so that the size of
218 * struct stat is backwards compatible. We use bitfields instead
219 * of an array of chars so that this doesn't require a C99 compiler
220 * to compile if the size of the padding is 0. We use 2 bitfields
221 * to cover up to 64 bits on 32-bit machines. We assume that
224 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec
));
225 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec
));
228 #if defined(__i386__)
229 #define TARGET_HAS_STAT_TIME_T_EXT 1
233 uint64_t st_dev
; /* inode's device */
234 uint64_t st_ino
; /* inode's number */
235 uint64_t st_nlink
; /* number of hard links */
236 int16_t st_mode
; /* inode protection mode */
238 uint32_t st_uid
; /* user ID of the file's owner */
239 uint32_t st_gid
; /* group ID of the file's group */
241 uint64_t st_rdev
; /* device type */
242 #ifdef TARGET_HAS_STAT_TIME_T_EXT
245 struct target_freebsd_timespec st_atim
; /* time of last access */
246 #ifdef TARGET_HAS_STAT_TIME_T_EXT
249 struct target_freebsd_timespec st_mtim
; /* time of last data modification */
250 #ifdef TARGET_HAS_STAT_TIME_T_EXT
253 struct target_freebsd_timespec st_ctim
;/* time of last file status change */
254 #ifdef TARGET_HAS_STAT_TIME_T_EXT
257 struct target_freebsd_timespec st_birthtim
; /* time of file creation */
258 int64_t st_size
; /* file size, in bytes */
259 int64_t st_blocks
; /* blocks allocated for file */
260 uint32_t st_blksize
; /* optimal blocksize for I/O */
261 uint32_t st_flags
; /* user defined flags for file */
262 uint64_t st_gen
; /* file generation number */
263 uint64_t st_spare
[10];
267 /* struct nstat is the same as stat above but without the st_lspare field */
268 struct target_freebsd11_nstat
{
269 uint32_t st_dev
; /* inode's device */
270 uint32_t st_ino
; /* inode's number */
271 int16_t st_mode
; /* inode protection mode */
272 int16_t st_nlink
; /* number of hard links */
273 uint32_t st_uid
; /* user ID of the file's owner */
274 uint32_t st_gid
; /* group ID of the file's group */
275 uint32_t st_rdev
; /* device type */
276 struct target_freebsd_timespec st_atim
; /* time last accessed */
277 struct target_freebsd_timespec st_mtim
; /* time last data modification */
278 struct target_freebsd_timespec st_ctim
; /* time last file status change */
279 int64_t st_size
; /* file size, in bytes */
280 int64_t st_blocks
; /* blocks allocated for file */
281 uint32_t st_blksize
; /* optimal blocksize for I/O */
282 uint32_t st_flags
; /* user defined flags for file */
283 uint32_t st_gen
; /* file generation number */
284 struct target_freebsd_timespec st_birthtim
; /* time of file creation */
286 * Explicitly pad st_birthtim to 16 bytes so that the size of
287 * struct stat is backwards compatible. We use bitfields instead
288 * of an array of chars so that this doesn't require a C99 compiler
289 * to compile if the size of the padding is 0. We use 2 bitfields
290 * to cover up to 64 bits on 32-bit machines. We assume that
293 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec
));
294 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec
));
301 /* filesystem id type */
302 typedef struct target_freebsd_fsid
{ int32_t val
[2]; } target_freebsd_fsid_t
;
304 /* filesystem statistics */
305 struct target_freebsd11_statfs
{
306 uint32_t f_version
; /* structure version number */
307 uint32_t f_type
; /* type of filesystem */
308 uint64_t f_flags
; /* copy of mount exported flags */
309 uint64_t f_bsize
; /* filesystem fragment size */
310 uint64_t f_iosize
; /* optimal transfer block size */
311 uint64_t f_blocks
; /* total data blocks in filesystem */
312 uint64_t f_bfree
; /* free blocks in filesystem */
313 int64_t f_bavail
; /* free blocks avail to non-superuser */
314 uint64_t f_files
; /* total file nodes in filesystem */
315 int64_t f_ffree
; /* free nodes avail to non-superuser */
316 uint64_t f_syncwrites
; /* count of sync writes since mount */
317 uint64_t f_asyncwrites
; /* count of async writes since mount */
318 uint64_t f_syncreads
; /* count of sync reads since mount */
319 uint64_t f_asyncreads
; /* count of async reads since mount */
320 uint64_t f_spare
[10]; /* unused spare */
321 uint32_t f_namemax
; /* maximum filename length */
322 uint32_t f_owner
; /* user that mounted the filesystem */
323 target_freebsd_fsid_t f_fsid
; /* filesystem id */
324 char f_charspare
[80]; /* spare string space */
325 char f_fstypename
[16]; /* filesys type name */
326 char f_mntfromname
[88]; /* mount filesystem */
327 char f_mntonname
[88]; /* dir on which mounted*/
330 struct target_statfs
{
331 uint32_t f_version
; /* structure version number */
332 uint32_t f_type
; /* type of filesystem */
333 uint64_t f_flags
; /* copy of mount exported flags */
334 uint64_t f_bsize
; /* filesystem fragment size */
335 uint64_t f_iosize
; /* optimal transfer block size */
336 uint64_t f_blocks
; /* total data blocks in filesystem */
337 uint64_t f_bfree
; /* free blocks in filesystem */
338 int64_t f_bavail
; /* free blocks avail to non-superuser */
339 uint64_t f_files
; /* total file nodes in filesystem */
340 int64_t f_ffree
; /* free nodes avail to non-superuser */
341 uint64_t f_syncwrites
; /* count of sync writes since mount */
342 uint64_t f_asyncwrites
; /* count of async writes since mount */
343 uint64_t f_syncreads
; /* count of sync reads since mount */
344 uint64_t f_asyncreads
; /* count of async reads since mount */
345 uint64_t f_spare
[10]; /* unused spare */
346 uint32_t f_namemax
; /* maximum filename length */
347 uint32_t f_owner
; /* user that mounted the filesystem */
348 target_freebsd_fsid_t f_fsid
; /* filesystem id */
349 char f_charspare
[80]; /* spare string space */
350 char f_fstypename
[16]; /* filesystem type name */
351 char f_mntfromname
[1024]; /* mounted filesystem */
352 char f_mntonname
[1024]; /* directory on which mounted */
355 /* File identifier. These are unique per filesystem on a single machine. */
356 #define TARGET_MAXFIDSZ 16
358 struct target_freebsd_fid
{
359 uint16_t fid_len
; /* len of data in bytes */
360 uint16_t fid_data0
; /* force longword align */
361 char fid_data
[TARGET_MAXFIDSZ
]; /* data (variable len) */
364 /* Generic file handle */
365 struct target_freebsd_fhandle
{
366 target_freebsd_fsid_t fh_fsid
; /* Filesystem id of mount point */
367 struct target_freebsd_fid fh_fid
; /* Filesys specific id */
369 typedef struct target_freebsd_fhandle target_freebsd_fhandle_t
;
374 #define TARGET_F_DUPFD 0
375 #define TARGET_F_GETFD 1
376 #define TARGET_F_SETFD 2
377 #define TARGET_F_GETFL 3
378 #define TARGET_F_SETFL 4
379 #define TARGET_F_GETOWN 5
380 #define TARGET_F_SETOWN 6
381 #define TARGET_F_OGETLK 7
382 #define TARGET_F_OSETLK 8
383 #define TARGET_F_OSETLKW 9
384 #define TARGET_F_DUP2FD 10
385 #define TARGET_F_GETLK 11
386 #define TARGET_F_SETLK 12
387 #define TARGET_F_SETLKW 13
388 #define TARGET_F_SETLK_REMOTE 14
389 #define TARGET_F_READAHEAD 15
390 #define TARGET_F_RDAHEAD 16
391 #define TARGET_F_DUPFD_CLOEXEC 17
392 #define TARGET_F_DUP2FD_CLOEXEC 18
393 /* FreeBSD-specific */
394 #define TARGET_F_ADD_SEALS 19
395 #define TARGET_F_GET_SEALS 20
397 struct target_freebsd_flock
{
407 /* user: vfork(2) semantics, clear signals */
408 #define TARGET_RFSPAWN (1U << 31)
413 #define TARGET_PROC_SPROTECT 1
414 #define TARGET_PROC_REAP_ACQUIRE 2
415 #define TARGET_PROC_REAP_RELEASE 3
416 #define TARGET_PROC_REAP_STATUS 4
417 #define TARGET_PROC_REAP_GETPIDS 5
418 #define TARGET_PROC_REAP_KILL 6
420 struct target_procctl_reaper_status
{
422 uint32_t rs_children
;
423 uint32_t rs_descendants
;
426 uint32_t rs_pad0
[15];
429 struct target_procctl_reaper_pidinfo
{
433 uint32_t pi_pad0
[15];
436 struct target_procctl_reaper_pids
{
438 uint32_t rp_pad0
[15];
442 struct target_procctl_reaper_kill
{
448 uint32_t rk_pad0
[15];
452 #define safe_syscall0(type, name) \
453 type safe_##name(void) \
455 return safe_syscall(SYS_##name); \
458 #define safe_syscall1(type, name, type1, arg1) \
459 type safe_##name(type1 arg1) \
461 return safe_syscall(SYS_##name, arg1); \
464 #define safe_syscall2(type, name, type1, arg1, type2, arg2) \
465 type safe_##name(type1 arg1, type2 arg2) \
467 return safe_syscall(SYS_##name, arg1, arg2); \
470 #define safe_syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
471 type safe_##name(type1 arg1, type2 arg2, type3 arg3) \
473 return safe_syscall(SYS_##name, arg1, arg2, arg3); \
476 #define safe_syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
478 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
480 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4); \
483 #define safe_syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
484 type4, arg4, type5, arg5) \
485 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
488 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5); \
491 #define safe_syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
492 type4, arg4, type5, arg5, type6, arg6) \
493 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
494 type5 arg5, type6 arg6) \
496 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
499 #define safe_fcntl(...) safe_syscall(SYS_fcntl, __VA_ARGS__)
501 /* So far all target and host bitmasks are the same */
502 #undef target_to_host_bitmask
503 #define target_to_host_bitmask(x, tbl) (x)
504 #undef host_to_target_bitmask
505 #define host_to_target_bitmask(x, tbl) (x)
507 #endif /* SYSCALL_DEFS_H */