target/i386: validate VEX.W for AVX instructions
[qemu/ar7.git] / bsd-user / syscall_defs.h
blob52f84d5dd1732eee8e323cf9fe8620e6d311cb4a
1 /*
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"
33 * machine/_types.h
34 * or x86/_types.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;
49 #else
50 typedef int32_t target_time_t;
51 #endif
53 struct target_iovec {
54 abi_long iov_base; /* Starting address */
55 abi_long iov_len; /* Number of bytes */
59 * sys/ipc.h
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 */
76 * sys/shm.h
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 {
91 abi_long start;
92 abi_long size;
96 * sys/mman.h
98 #define TARGET_MADV_DONTNEED 4 /* dont need these pages */
100 #define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented */
101 /* MAP_INHERIT */
102 #define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented */
103 /* MAP_NOEXTEND */
104 #define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like a */
105 /* stack */
106 #define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync */
107 /* underlying file */
109 #define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7
111 #define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained after */
112 /* exec */
113 #define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, even */
114 /* within break */
115 #define TARGET_NETBSD_MAP_WIRED 0x0800 /* mlock() mapping when it is */
116 /* established */
118 #define TARGET_NETBSD_MAP_STACK 0x2000 /* allocated from memory, */
119 /* swap space (stack) */
121 #define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7
123 #define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained after */
124 /* exec */
125 #define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change */
126 /* file size */
127 #define TARGET_OPENBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, */
128 /* even within heap */
130 #define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7
132 /* XXX */
133 #define TARGET_BSD_MAP_FLAGMASK 0x3ff7
136 * sys/time.h
137 * sys/timex.h
140 typedef abi_long target_freebsd_suseconds_t;
142 /* compare to sys/timespec.h */
143 struct target_freebsd_timespec {
144 target_time_t tv_sec; /* seconds */
145 abi_long tv_nsec; /* and nanoseconds */
146 #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
147 abi_long _pad;
148 #endif
151 #define TARGET_CPUCLOCK_WHICH_PID 0
152 #define TARGET_CPUCLOCK_WHICH_TID 1
154 /* sys/umtx.h */
155 struct target_freebsd__umtx_time {
156 struct target_freebsd_timespec _timeout;
157 uint32_t _flags;
158 uint32_t _clockid;
161 struct target_freebsd_timeval {
162 target_time_t tv_sec; /* seconds */
163 target_freebsd_suseconds_t tv_usec;/* and microseconds */
164 #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
165 abi_long _pad;
166 #endif
170 * sys/resource.h
172 #define TARGET_RLIM_INFINITY RLIM_INFINITY
174 #define TARGET_RLIMIT_CPU 0
175 #define TARGET_RLIMIT_FSIZE 1
176 #define TARGET_RLIMIT_DATA 2
177 #define TARGET_RLIMIT_STACK 3
178 #define TARGET_RLIMIT_CORE 4
179 #define TARGET_RLIMIT_RSS 5
180 #define TARGET_RLIMIT_MEMLOCK 6
181 #define TARGET_RLIMIT_NPROC 7
182 #define TARGET_RLIMIT_NOFILE 8
183 #define TARGET_RLIMIT_SBSIZE 9
184 #define TARGET_RLIMIT_AS 10
185 #define TARGET_RLIMIT_NPTS 11
186 #define TARGET_RLIMIT_SWAP 12
188 struct target_rlimit {
189 uint64_t rlim_cur;
190 uint64_t rlim_max;
193 struct target_freebsd_rusage {
194 struct target_freebsd_timeval ru_utime; /* user time used */
195 struct target_freebsd_timeval ru_stime; /* system time used */
196 abi_long ru_maxrss; /* maximum resident set size */
197 abi_long ru_ixrss; /* integral shared memory size */
198 abi_long ru_idrss; /* integral unshared data size */
199 abi_long ru_isrss; /* integral unshared stack size */
200 abi_long ru_minflt; /* page reclaims */
201 abi_long ru_majflt; /* page faults */
202 abi_long ru_nswap; /* swaps */
203 abi_long ru_inblock; /* block input operations */
204 abi_long ru_oublock; /* block output operations */
205 abi_long ru_msgsnd; /* messages sent */
206 abi_long ru_msgrcv; /* messages received */
207 abi_long ru_nsignals; /* signals received */
208 abi_long ru_nvcsw; /* voluntary context switches */
209 abi_long ru_nivcsw; /* involuntary context switches */
212 struct target_freebsd__wrusage {
213 struct target_freebsd_rusage wru_self;
214 struct target_freebsd_rusage wru_children;
218 * sys/stat.h
220 struct target_freebsd11_stat {
221 uint32_t st_dev; /* inode's device */
222 uint32_t st_ino; /* inode's number */
223 int16_t st_mode; /* inode protection mode */
224 int16_t st_nlink; /* number of hard links */
225 uint32_t st_uid; /* user ID of the file's owner */
226 uint32_t st_gid; /* group ID of the file's group */
227 uint32_t st_rdev; /* device type */
228 struct target_freebsd_timespec st_atim; /* time last accessed */
229 struct target_freebsd_timespec st_mtim; /* time last data modification */
230 struct target_freebsd_timespec st_ctim; /* time last file status change */
231 int64_t st_size; /* file size, in bytes */
232 int64_t st_blocks; /* blocks allocated for file */
233 uint32_t st_blksize; /* optimal blocksize for I/O */
234 uint32_t st_flags; /* user defined flags for file */
235 uint32_t st_gen; /* file generation number */
236 int32_t st_lspare;
237 struct target_freebsd_timespec st_birthtim; /* time of file creation */
239 * Explicitly pad st_birthtim to 16 bytes so that the size of
240 * struct stat is backwards compatible. We use bitfields instead
241 * of an array of chars so that this doesn't require a C99 compiler
242 * to compile if the size of the padding is 0. We use 2 bitfields
243 * to cover up to 64 bits on 32-bit machines. We assume that
244 * CHAR_BIT is 8...
246 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
247 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
248 } __packed;
250 #if defined(__i386__)
251 #define TARGET_HAS_STAT_TIME_T_EXT 1
252 #endif
254 struct target_stat {
255 uint64_t st_dev; /* inode's device */
256 uint64_t st_ino; /* inode's number */
257 uint64_t st_nlink; /* number of hard links */
258 int16_t st_mode; /* inode protection mode */
259 int16_t st_padding0;
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 int32_t st_padding1;
263 uint64_t st_rdev; /* device type */
264 #ifdef TARGET_HAS_STAT_TIME_T_EXT
265 int32_t st_atim_ext;
266 #endif
267 struct target_freebsd_timespec st_atim; /* time of last access */
268 #ifdef TARGET_HAS_STAT_TIME_T_EXT
269 int32_t st_mtim_ext;
270 #endif
271 struct target_freebsd_timespec st_mtim; /* time of last data modification */
272 #ifdef TARGET_HAS_STAT_TIME_T_EXT
273 int32_t st_ctim_ext;
274 #endif
275 struct target_freebsd_timespec st_ctim;/* time of last file status change */
276 #ifdef TARGET_HAS_STAT_TIME_T_EXT
277 int32_t st_btim_ext;
278 #endif
279 struct target_freebsd_timespec st_birthtim; /* time of file creation */
280 int64_t st_size; /* file size, in bytes */
281 int64_t st_blocks; /* blocks allocated for file */
282 uint32_t st_blksize; /* optimal blocksize for I/O */
283 uint32_t st_flags; /* user defined flags for file */
284 uint64_t st_gen; /* file generation number */
285 uint64_t st_spare[10];
289 /* struct nstat is the same as stat above but without the st_lspare field */
290 struct target_freebsd11_nstat {
291 uint32_t st_dev; /* inode's device */
292 uint32_t st_ino; /* inode's number */
293 int16_t st_mode; /* inode protection mode */
294 int16_t st_nlink; /* number of hard links */
295 uint32_t st_uid; /* user ID of the file's owner */
296 uint32_t st_gid; /* group ID of the file's group */
297 uint32_t st_rdev; /* device type */
298 struct target_freebsd_timespec st_atim; /* time last accessed */
299 struct target_freebsd_timespec st_mtim; /* time last data modification */
300 struct target_freebsd_timespec st_ctim; /* time last file status change */
301 int64_t st_size; /* file size, in bytes */
302 int64_t st_blocks; /* blocks allocated for file */
303 uint32_t st_blksize; /* optimal blocksize for I/O */
304 uint32_t st_flags; /* user defined flags for file */
305 uint32_t st_gen; /* file generation number */
306 struct target_freebsd_timespec st_birthtim; /* time of file creation */
308 * Explicitly pad st_birthtim to 16 bytes so that the size of
309 * struct stat is backwards compatible. We use bitfields instead
310 * of an array of chars so that this doesn't require a C99 compiler
311 * to compile if the size of the padding is 0. We use 2 bitfields
312 * to cover up to 64 bits on 32-bit machines. We assume that
313 * CHAR_BIT is 8...
315 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
316 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
317 } __packed;
320 * sys/mount.h
323 /* filesystem id type */
324 typedef struct target_freebsd_fsid { int32_t val[2]; } target_freebsd_fsid_t;
326 /* filesystem statistics */
327 struct target_freebsd11_statfs {
328 uint32_t f_version; /* structure version number */
329 uint32_t f_type; /* type of filesystem */
330 uint64_t f_flags; /* copy of mount exported flags */
331 uint64_t f_bsize; /* filesystem fragment size */
332 uint64_t f_iosize; /* optimal transfer block size */
333 uint64_t f_blocks; /* total data blocks in filesystem */
334 uint64_t f_bfree; /* free blocks in filesystem */
335 int64_t f_bavail; /* free blocks avail to non-superuser */
336 uint64_t f_files; /* total file nodes in filesystem */
337 int64_t f_ffree; /* free nodes avail to non-superuser */
338 uint64_t f_syncwrites; /* count of sync writes since mount */
339 uint64_t f_asyncwrites; /* count of async writes since mount */
340 uint64_t f_syncreads; /* count of sync reads since mount */
341 uint64_t f_asyncreads; /* count of async reads since mount */
342 uint64_t f_spare[10]; /* unused spare */
343 uint32_t f_namemax; /* maximum filename length */
344 uint32_t f_owner; /* user that mounted the filesystem */
345 target_freebsd_fsid_t f_fsid; /* filesystem id */
346 char f_charspare[80]; /* spare string space */
347 char f_fstypename[16]; /* filesys type name */
348 char f_mntfromname[88]; /* mount filesystem */
349 char f_mntonname[88]; /* dir on which mounted*/
352 struct target_statfs {
353 uint32_t f_version; /* structure version number */
354 uint32_t f_type; /* type of filesystem */
355 uint64_t f_flags; /* copy of mount exported flags */
356 uint64_t f_bsize; /* filesystem fragment size */
357 uint64_t f_iosize; /* optimal transfer block size */
358 uint64_t f_blocks; /* total data blocks in filesystem */
359 uint64_t f_bfree; /* free blocks in filesystem */
360 int64_t f_bavail; /* free blocks avail to non-superuser */
361 uint64_t f_files; /* total file nodes in filesystem */
362 int64_t f_ffree; /* free nodes avail to non-superuser */
363 uint64_t f_syncwrites; /* count of sync writes since mount */
364 uint64_t f_asyncwrites; /* count of async writes since mount */
365 uint64_t f_syncreads; /* count of sync reads since mount */
366 uint64_t f_asyncreads; /* count of async reads since mount */
367 uint64_t f_spare[10]; /* unused spare */
368 uint32_t f_namemax; /* maximum filename length */
369 uint32_t f_owner; /* user that mounted the filesystem */
370 target_freebsd_fsid_t f_fsid; /* filesystem id */
371 char f_charspare[80]; /* spare string space */
372 char f_fstypename[16]; /* filesystem type name */
373 char f_mntfromname[1024]; /* mounted filesystem */
374 char f_mntonname[1024]; /* directory on which mounted */
377 /* File identifier. These are unique per filesystem on a single machine. */
378 #define TARGET_MAXFIDSZ 16
380 struct target_freebsd_fid {
381 uint16_t fid_len; /* len of data in bytes */
382 uint16_t fid_data0; /* force longword align */
383 char fid_data[TARGET_MAXFIDSZ]; /* data (variable len) */
386 /* Generic file handle */
387 struct target_freebsd_fhandle {
388 target_freebsd_fsid_t fh_fsid; /* Filesystem id of mount point */
389 struct target_freebsd_fid fh_fid; /* Filesys specific id */
391 typedef struct target_freebsd_fhandle target_freebsd_fhandle_t;
394 * sys/fcntl.h
396 #define TARGET_F_DUPFD 0
397 #define TARGET_F_GETFD 1
398 #define TARGET_F_SETFD 2
399 #define TARGET_F_GETFL 3
400 #define TARGET_F_SETFL 4
401 #define TARGET_F_GETOWN 5
402 #define TARGET_F_SETOWN 6
403 #define TARGET_F_OGETLK 7
404 #define TARGET_F_OSETLK 8
405 #define TARGET_F_OSETLKW 9
406 #define TARGET_F_DUP2FD 10
407 #define TARGET_F_GETLK 11
408 #define TARGET_F_SETLK 12
409 #define TARGET_F_SETLKW 13
410 #define TARGET_F_SETLK_REMOTE 14
411 #define TARGET_F_READAHEAD 15
412 #define TARGET_F_RDAHEAD 16
413 #define TARGET_F_DUPFD_CLOEXEC 17
414 #define TARGET_F_DUP2FD_CLOEXEC 18
415 /* FreeBSD-specific */
416 #define TARGET_F_ADD_SEALS 19
417 #define TARGET_F_GET_SEALS 20
419 struct target_freebsd_flock {
420 int64_t l_start;
421 int64_t l_len;
422 int32_t l_pid;
423 int16_t l_type;
424 int16_t l_whence;
425 int32_t l_sysid;
426 } QEMU_PACKED;
428 /* sys/unistd.h */
429 /* user: vfork(2) semantics, clear signals */
430 #define TARGET_RFSPAWN (1U << 31)
433 * from sys/procctl.h
435 #define TARGET_PROC_SPROTECT 1
436 #define TARGET_PROC_REAP_ACQUIRE 2
437 #define TARGET_PROC_REAP_RELEASE 3
438 #define TARGET_PROC_REAP_STATUS 4
439 #define TARGET_PROC_REAP_GETPIDS 5
440 #define TARGET_PROC_REAP_KILL 6
442 struct target_procctl_reaper_status {
443 uint32_t rs_flags;
444 uint32_t rs_children;
445 uint32_t rs_descendants;
446 uint32_t rs_reaper;
447 uint32_t rs_pid;
448 uint32_t rs_pad0[15];
451 struct target_procctl_reaper_pidinfo {
452 uint32_t pi_pid;
453 uint32_t pi_subtree;
454 uint32_t pi_flags;
455 uint32_t pi_pad0[15];
458 struct target_procctl_reaper_pids {
459 uint32_t rp_count;
460 uint32_t rp_pad0[15];
461 abi_ulong rp_pids;
464 struct target_procctl_reaper_kill {
465 int32_t rk_sig;
466 uint32_t rk_flags;
467 uint32_t rk_subtree;
468 uint32_t rk_killed;
469 uint32_t rk_fpid;
470 uint32_t rk_pad0[15];
474 #define safe_syscall0(type, name) \
475 type safe_##name(void) \
477 return safe_syscall(SYS_##name); \
480 #define safe_syscall1(type, name, type1, arg1) \
481 type safe_##name(type1 arg1) \
483 return safe_syscall(SYS_##name, arg1); \
486 #define safe_syscall2(type, name, type1, arg1, type2, arg2) \
487 type safe_##name(type1 arg1, type2 arg2) \
489 return safe_syscall(SYS_##name, arg1, arg2); \
492 #define safe_syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
493 type safe_##name(type1 arg1, type2 arg2, type3 arg3) \
495 return safe_syscall(SYS_##name, arg1, arg2, arg3); \
498 #define safe_syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
499 type4, arg4) \
500 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
502 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4); \
505 #define safe_syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
506 type4, arg4, type5, arg5) \
507 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
508 type5 arg5) \
510 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5); \
513 #define safe_syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
514 type4, arg4, type5, arg5, type6, arg6) \
515 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
516 type5 arg5, type6 arg6) \
518 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
521 #define safe_fcntl(...) safe_syscall(SYS_fcntl, __VA_ARGS__)
523 /* So far all target and host bitmasks are the same */
524 #undef target_to_host_bitmask
525 #define target_to_host_bitmask(x, tbl) (x)
526 #undef host_to_target_bitmask
527 #define host_to_target_bitmask(x, tbl) (x)
529 #endif /* SYSCALL_DEFS_H */