master
h 562 lines 19.3 KB
Raw
1 /*
2 * System call related declarations
3 *
4 * Copyright (c) 2013-2015 Stacey D. Son
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 #ifndef SYSCALL_DEFS_H
9 #define SYSCALL_DEFS_H
10
11 #include <sys/syscall.h>
12 #include <sys/resource.h>
13
14 #include "errno_defs.h"
15
16 #include "os-syscall.h"
17
18 /*
19 * machine/_types.h
20 * or x86/_types.h
21 */
22
23 struct target_iovec {
24 abi_long iov_base; /* Starting address */
25 abi_long iov_len; /* Number of bytes */
26 };
27
28 /*
29 * sys/ipc.h
30 */
31 struct target_ipc_perm {
32 uint32_t cuid; /* creator user id */
33 uint32_t cgid; /* creator group id */
34 uint32_t uid; /* user id */
35 uint32_t gid; /* group id */
36 uint16_t mode; /* r/w permission */
37 uint16_t seq; /* sequence # */
38 abi_long key; /* user specified msg/sem/shm key */
39 };
40
41 #define TARGET_IPC_RMID 0 /* remove identifier */
42 #define TARGET_IPC_SET 1 /* set options */
43 #define TARGET_IPC_STAT 2 /* get options */
44
45 /*
46 * sys/shm.h
47 */
48 struct target_shmid_ds {
49 struct target_ipc_perm shm_perm; /* peration permission structure */
50 abi_ulong shm_segsz; /* size of segment in bytes */
51 int32_t shm_lpid; /* process ID of last shared memory op */
52 int32_t shm_cpid; /* process ID of creator */
53 int32_t shm_nattch; /* number of current attaches */
54 target_time_t shm_atime; /* time of last shmat() */
55 target_time_t shm_dtime; /* time of last shmdt() */
56 target_time_t shm_ctime; /* time of last change by shmctl() */
57 };
58
59 #define N_BSD_SHM_REGIONS 32
60 struct bsd_shm_regions {
61 abi_long start;
62 abi_long size;
63 };
64
65 /*
66 * sys/sem.h
67 */
68 #define TARGET_GETNCNT 3 /* Return the value of semncnt {READ} */
69 #define TARGET_GETPID 4 /* Return the value of sempid {READ} */
70 #define TARGET_GETVAL 5 /* Return the value of semval {READ} */
71 #define TARGET_GETALL 6 /* Return semvals into arg.array {READ} */
72 #define TARGET_GETZCNT 7 /* Return the value of semzcnt {READ} */
73 #define TARGET_SETVAL 8 /* Set the value of semval to arg.val {ALTER} */
74 #define TARGET_SETALL 9 /* Set semvals from arg.array {ALTER} */
75
76 struct target_sembuf {
77 abi_ushort sem_num; /* semaphore # */
78 abi_short sem_op; /* semaphore operation */
79 abi_short sem_flg; /* operation flags */
80 };
81
82 union target_semun {
83 abi_int val; /* value for SETVAL */
84 abi_ulong buf; /* buffer for IPC_STAT & IPC_SET */
85 abi_ulong array; /* array for GETALL & SETALL */
86 };
87
88 struct target_semid_ds {
89 struct target_ipc_perm sem_perm; /* operation permission struct */
90 abi_ptr sem_base; /* pointer to first semaphore in set */
91 abi_ushort sem_nsems; /* number of sems in set */
92 target_time_t sem_otime; /* last operation time */
93 target_time_t sem_ctime; /* times measured in secs */
94 };
95
96 /*
97 * sys/msg.h
98 */
99 struct target_msqid_ds {
100 struct target_ipc_perm msg_perm; /* msg queue permission bits */
101 abi_ptr msg_first; /* first message in the queue */
102 abi_ptr msg_last; /* last message in the queue */
103 abi_ulong msg_cbytes; /* # of bytes in use on the queue */
104 abi_ulong msg_qnum; /* number of msgs in the queue */
105 abi_ulong msg_qbytes; /* max # of bytes on the queue */
106 int32_t msg_lspid; /* pid of last msgsnd() */
107 int32_t msg_lrpid; /* pid of last msgrcv() */
108 target_time_t msg_stime; /* time of last msgsnd() */
109 target_time_t msg_rtime; /* time of last msgrcv() */
110 target_time_t msg_ctime; /* time of last msgctl() */
111 };
112
113 /*
114 * sys/msgbuf.h
115 */
116 struct target_msgbuf {
117 abi_long mtype; /* message type */
118 char mtext[1]; /* body of message */
119 };
120
121 /*
122 * sys/mman.h
123 */
124 #define TARGET_MADV_DONTNEED 4 /* dont need these pages */
125
126 #define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented */
127 /* MAP_INHERIT */
128 #define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented */
129 /* MAP_NOEXTEND */
130 #define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like a */
131 /* stack */
132 #define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync */
133 /* underlying file */
134
135 #define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7
136
137 /* XXX */
138 #define TARGET_BSD_MAP_FLAGMASK 0x3ff7
139
140 /*
141 * sys/time.h
142 * sys/timex.h
143 */
144
145 typedef abi_long target_freebsd_suseconds_t;
146
147 /* compare to sys/timespec.h */
148 struct target_freebsd_timespec {
149 target_time_t tv_sec; /* seconds */
150 abi_long tv_nsec; /* and nanoseconds */
151 #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
152 abi_long _pad;
153 #endif
154 };
155
156 #define TARGET_CPUCLOCK_WHICH_PID 0
157 #define TARGET_CPUCLOCK_WHICH_TID 1
158
159 /* sys/umtx.h */
160 struct target_freebsd__umtx_time {
161 struct target_freebsd_timespec _timeout;
162 uint32_t _flags;
163 uint32_t _clockid;
164 };
165
166 struct target_freebsd_timeval {
167 target_time_t tv_sec; /* seconds */
168 target_freebsd_suseconds_t tv_usec;/* and microseconds */
169 #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
170 abi_long _pad;
171 #endif
172 };
173
174 /*
175 * sys/resource.h
176 */
177 #define TARGET_RLIM_INFINITY RLIM_INFINITY
178
179 #define TARGET_RLIMIT_CPU 0
180 #define TARGET_RLIMIT_FSIZE 1
181 #define TARGET_RLIMIT_DATA 2
182 #define TARGET_RLIMIT_STACK 3
183 #define TARGET_RLIMIT_CORE 4
184 #define TARGET_RLIMIT_RSS 5
185 #define TARGET_RLIMIT_MEMLOCK 6
186 #define TARGET_RLIMIT_NPROC 7
187 #define TARGET_RLIMIT_NOFILE 8
188 #define TARGET_RLIMIT_SBSIZE 9
189 #define TARGET_RLIMIT_AS 10
190 #define TARGET_RLIMIT_NPTS 11
191 #define TARGET_RLIMIT_SWAP 12
192
193 struct target_rlimit {
194 uint64_t rlim_cur;
195 uint64_t rlim_max;
196 };
197
198 struct target_freebsd_rusage {
199 struct target_freebsd_timeval ru_utime; /* user time used */
200 struct target_freebsd_timeval ru_stime; /* system time used */
201 abi_long ru_maxrss; /* maximum resident set size */
202 abi_long ru_ixrss; /* integral shared memory size */
203 abi_long ru_idrss; /* integral unshared data size */
204 abi_long ru_isrss; /* integral unshared stack size */
205 abi_long ru_minflt; /* page reclaims */
206 abi_long ru_majflt; /* page faults */
207 abi_long ru_nswap; /* swaps */
208 abi_long ru_inblock; /* block input operations */
209 abi_long ru_oublock; /* block output operations */
210 abi_long ru_msgsnd; /* messages sent */
211 abi_long ru_msgrcv; /* messages received */
212 abi_long ru_nsignals; /* signals received */
213 abi_long ru_nvcsw; /* voluntary context switches */
214 abi_long ru_nivcsw; /* involuntary context switches */
215 };
216
217 struct target_freebsd__wrusage {
218 struct target_freebsd_rusage wru_self;
219 struct target_freebsd_rusage wru_children;
220 };
221
222 /*
223 * sys/stat.h
224 */
225 struct target_freebsd11_stat {
226 uint32_t st_dev; /* inode's device */
227 uint32_t st_ino; /* inode's number */
228 int16_t st_mode; /* inode protection mode */
229 int16_t st_nlink; /* number of hard links */
230 uint32_t st_uid; /* user ID of the file's owner */
231 uint32_t st_gid; /* group ID of the file's group */
232 uint32_t st_rdev; /* device type */
233 struct target_freebsd_timespec st_atim; /* time last accessed */
234 struct target_freebsd_timespec st_mtim; /* time last data modification */
235 struct target_freebsd_timespec st_ctim; /* time last file status change */
236 int64_t st_size; /* file size, in bytes */
237 int64_t st_blocks; /* blocks allocated for file */
238 uint32_t st_blksize; /* optimal blocksize for I/O */
239 uint32_t st_flags; /* user defined flags for file */
240 uint32_t st_gen; /* file generation number */
241 int32_t st_lspare;
242 struct target_freebsd_timespec st_birthtim; /* time of file creation */
243 /*
244 * Explicitly pad st_birthtim to 16 bytes so that the size of
245 * struct stat is backwards compatible. We use bitfields instead
246 * of an array of chars so that this doesn't require a C99 compiler
247 * to compile if the size of the padding is 0. We use 2 bitfields
248 * to cover up to 64 bits on 32-bit machines. We assume that
249 * CHAR_BIT is 8...
250 */
251 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
252 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
253 } __packed;
254
255 #if defined(TARGET_I386) && !defined(TARGET_X86_64)
256 #define TARGET_HAS_STAT_TIME_T_EXT 1
257 #endif
258
259 struct target_stat {
260 uint64_t st_dev; /* inode's device */
261 uint64_t st_ino; /* inode's number */
262 uint64_t st_nlink; /* number of hard links */
263 int16_t st_mode; /* inode protection mode */
264 int16_t st_padding0;
265 uint32_t st_uid; /* user ID of the file's owner */
266 uint32_t st_gid; /* group ID of the file's group */
267 int32_t st_padding1;
268 uint64_t st_rdev; /* device type */
269 #ifdef TARGET_HAS_STAT_TIME_T_EXT
270 int32_t st_atim_ext;
271 #endif
272 struct target_freebsd_timespec st_atim; /* time of last access */
273 #ifdef TARGET_HAS_STAT_TIME_T_EXT
274 int32_t st_mtim_ext;
275 #endif
276 struct target_freebsd_timespec st_mtim; /* time of last data modification */
277 #ifdef TARGET_HAS_STAT_TIME_T_EXT
278 int32_t st_ctim_ext;
279 #endif
280 struct target_freebsd_timespec st_ctim;/* time of last file status change */
281 #ifdef TARGET_HAS_STAT_TIME_T_EXT
282 int32_t st_btim_ext;
283 #endif
284 struct target_freebsd_timespec st_birthtim; /* time of file creation */
285 int64_t st_size; /* file size, in bytes */
286 int64_t st_blocks; /* blocks allocated for file */
287 uint32_t st_blksize; /* optimal blocksize for I/O */
288 uint32_t st_flags; /* user defined flags for file */
289 uint64_t st_gen; /* file generation number */
290 uint64_t st_spare[10];
291 };
292
293
294 /* struct nstat is the same as stat above but without the st_lspare field */
295 struct target_freebsd11_nstat {
296 uint32_t st_dev; /* inode's device */
297 uint32_t st_ino; /* inode's number */
298 int16_t st_mode; /* inode protection mode */
299 int16_t st_nlink; /* number of hard links */
300 uint32_t st_uid; /* user ID of the file's owner */
301 uint32_t st_gid; /* group ID of the file's group */
302 uint32_t st_rdev; /* device type */
303 struct target_freebsd_timespec st_atim; /* time last accessed */
304 struct target_freebsd_timespec st_mtim; /* time last data modification */
305 struct target_freebsd_timespec st_ctim; /* time last file status change */
306 int64_t st_size; /* file size, in bytes */
307 int64_t st_blocks; /* blocks allocated for file */
308 uint32_t st_blksize; /* optimal blocksize for I/O */
309 uint32_t st_flags; /* user defined flags for file */
310 uint32_t st_gen; /* file generation number */
311 struct target_freebsd_timespec st_birthtim; /* time of file creation */
312 /*
313 * Explicitly pad st_birthtim to 16 bytes so that the size of
314 * struct stat is backwards compatible. We use bitfields instead
315 * of an array of chars so that this doesn't require a C99 compiler
316 * to compile if the size of the padding is 0. We use 2 bitfields
317 * to cover up to 64 bits on 32-bit machines. We assume that
318 * CHAR_BIT is 8...
319 */
320 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
321 unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
322 } __packed;
323
324 /*
325 * sys/mount.h
326 */
327
328 /* filesystem id type */
329 typedef struct target_freebsd_fsid { int32_t val[2]; } target_freebsd_fsid_t;
330
331 /* filesystem statistics */
332 struct target_freebsd11_statfs {
333 uint32_t f_version; /* structure version number */
334 uint32_t f_type; /* type of filesystem */
335 uint64_t f_flags; /* copy of mount exported flags */
336 uint64_t f_bsize; /* filesystem fragment size */
337 uint64_t f_iosize; /* optimal transfer block size */
338 uint64_t f_blocks; /* total data blocks in filesystem */
339 uint64_t f_bfree; /* free blocks in filesystem */
340 int64_t f_bavail; /* free blocks avail to non-superuser */
341 uint64_t f_files; /* total file nodes in filesystem */
342 int64_t f_ffree; /* free nodes avail to non-superuser */
343 uint64_t f_syncwrites; /* count of sync writes since mount */
344 uint64_t f_asyncwrites; /* count of async writes since mount */
345 uint64_t f_syncreads; /* count of sync reads since mount */
346 uint64_t f_asyncreads; /* count of async reads since mount */
347 uint64_t f_spare[10]; /* unused spare */
348 uint32_t f_namemax; /* maximum filename length */
349 uint32_t f_owner; /* user that mounted the filesystem */
350 target_freebsd_fsid_t f_fsid; /* filesystem id */
351 char f_charspare[80]; /* spare string space */
352 char f_fstypename[16]; /* filesys type name */
353 char f_mntfromname[88]; /* mount filesystem */
354 char f_mntonname[88]; /* dir on which mounted*/
355 };
356
357 struct target_statfs {
358 uint32_t f_version; /* structure version number */
359 uint32_t f_type; /* type of filesystem */
360 uint64_t f_flags; /* copy of mount exported flags */
361 uint64_t f_bsize; /* filesystem fragment size */
362 uint64_t f_iosize; /* optimal transfer block size */
363 uint64_t f_blocks; /* total data blocks in filesystem */
364 uint64_t f_bfree; /* free blocks in filesystem */
365 int64_t f_bavail; /* free blocks avail to non-superuser */
366 uint64_t f_files; /* total file nodes in filesystem */
367 int64_t f_ffree; /* free nodes avail to non-superuser */
368 uint64_t f_syncwrites; /* count of sync writes since mount */
369 uint64_t f_asyncwrites; /* count of async writes since mount */
370 uint64_t f_syncreads; /* count of sync reads since mount */
371 uint64_t f_asyncreads; /* count of async reads since mount */
372 uint64_t f_spare[10]; /* unused spare */
373 uint32_t f_namemax; /* maximum filename length */
374 uint32_t f_owner; /* user that mounted the filesystem */
375 target_freebsd_fsid_t f_fsid; /* filesystem id */
376 char f_charspare[80]; /* spare string space */
377 char f_fstypename[16]; /* filesystem type name */
378 char f_mntfromname[1024]; /* mounted filesystem */
379 char f_mntonname[1024]; /* directory on which mounted */
380 };
381
382 /* File identifier. These are unique per filesystem on a single machine. */
383 #define TARGET_MAXFIDSZ 16
384
385 struct target_freebsd_fid {
386 uint16_t fid_len; /* len of data in bytes */
387 uint16_t fid_data0; /* force longword align */
388 char fid_data[TARGET_MAXFIDSZ]; /* data (variable len) */
389 };
390
391 /* Generic file handle */
392 struct target_freebsd_fhandle {
393 target_freebsd_fsid_t fh_fsid; /* Filesystem id of mount point */
394 struct target_freebsd_fid fh_fid; /* Filesys specific id */
395 };
396 typedef struct target_freebsd_fhandle target_freebsd_fhandle_t;
397
398 /*
399 * sys/fcntl.h
400 */
401 #define TARGET_F_DUPFD 0
402 #define TARGET_F_GETFD 1
403 #define TARGET_F_SETFD 2
404 #define TARGET_F_GETFL 3
405 #define TARGET_F_SETFL 4
406 #define TARGET_F_GETOWN 5
407 #define TARGET_F_SETOWN 6
408 #define TARGET_F_OGETLK 7
409 #define TARGET_F_OSETLK 8
410 #define TARGET_F_OSETLKW 9
411 #define TARGET_F_DUP2FD 10
412 #define TARGET_F_GETLK 11
413 #define TARGET_F_SETLK 12
414 #define TARGET_F_SETLKW 13
415 #define TARGET_F_SETLK_REMOTE 14
416 #define TARGET_F_READAHEAD 15
417 #define TARGET_F_RDAHEAD 16
418 #define TARGET_F_DUPFD_CLOEXEC 17
419 #define TARGET_F_DUP2FD_CLOEXEC 18
420 /* FreeBSD-specific */
421 #define TARGET_F_ADD_SEALS 19
422 #define TARGET_F_GET_SEALS 20
423
424 struct target_freebsd_flock {
425 int64_t l_start;
426 int64_t l_len;
427 int32_t l_pid;
428 int16_t l_type;
429 int16_t l_whence;
430 int32_t l_sysid;
431 } QEMU_PACKED;
432
433 /* sys/unistd.h */
434 /* user: vfork(2) semantics, clear signals */
435 #define TARGET_RFSPAWN (1U << 31)
436
437 /*
438 * from sys/procctl.h
439 */
440 #define TARGET_PROC_SPROTECT 1
441 #define TARGET_PROC_REAP_ACQUIRE 2
442 #define TARGET_PROC_REAP_RELEASE 3
443 #define TARGET_PROC_REAP_STATUS 4
444 #define TARGET_PROC_REAP_GETPIDS 5
445 #define TARGET_PROC_REAP_KILL 6
446
447 struct target_procctl_reaper_status {
448 uint32_t rs_flags;
449 uint32_t rs_children;
450 uint32_t rs_descendants;
451 uint32_t rs_reaper;
452 uint32_t rs_pid;
453 uint32_t rs_pad0[15];
454 };
455
456 struct target_procctl_reaper_pidinfo {
457 uint32_t pi_pid;
458 uint32_t pi_subtree;
459 uint32_t pi_flags;
460 uint32_t pi_pad0[15];
461 };
462
463 struct target_procctl_reaper_pids {
464 uint32_t rp_count;
465 uint32_t rp_pad0[15];
466 abi_ulong rp_pids;
467 };
468
469 struct target_procctl_reaper_kill {
470 int32_t rk_sig;
471 uint32_t rk_flags;
472 uint32_t rk_subtree;
473 uint32_t rk_killed;
474 uint32_t rk_fpid;
475 uint32_t rk_pad0[15];
476 };
477
478 /*
479 * sys/uuid.h
480 */
481 #define TARGET_UUID_NODE_LEN 6
482
483 struct target_uuid {
484 uint32_t time_low;
485 uint16_t time_mid;
486 uint16_t time_hi_and_version;
487 uint8_t clock_seq_hi_and_reserved;
488 uint8_t clock_seq_low;
489 uint8_t node[TARGET_UUID_NODE_LEN];
490 };
491
492
493 #define safe_syscall0(type, name) \
494 type safe_##name(void) \
495 { \
496 return safe_syscall(SYS_##name); \
497 }
498
499 #define safe_syscall1(type, name, type1, arg1) \
500 type safe_##name(type1 arg1) \
501 { \
502 return safe_syscall(SYS_##name, arg1); \
503 }
504
505 #define safe_syscall2(type, name, type1, arg1, type2, arg2) \
506 type safe_##name(type1 arg1, type2 arg2) \
507 { \
508 return safe_syscall(SYS_##name, arg1, arg2); \
509 }
510
511 #define safe_syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
512 type safe_##name(type1 arg1, type2 arg2, type3 arg3) \
513 { \
514 return safe_syscall(SYS_##name, arg1, arg2, arg3); \
515 }
516
517 #define safe_syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
518 type4, arg4) \
519 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
520 { \
521 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4); \
522 }
523
524 #define safe_syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
525 type4, arg4, type5, arg5) \
526 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
527 type5 arg5) \
528 { \
529 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5); \
530 }
531
532 #define safe_syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
533 type4, arg4, type5, arg5, type6, arg6) \
534 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
535 type5 arg5, type6 arg6) \
536 { \
537 return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
538 }
539
540 /*
541 * sys/socket.h
542 */
543 struct target_sockaddr {
544 uint8_t sa_len;
545 uint8_t sa_family;
546 uint8_t sa_data[14];
547 } QEMU_PACKED;
548
549 struct target_in_addr {
550 uint32_t s_addr; /* big endian */
551 };
552
553 #define safe_ioctl(...) safe_syscall(SYS_ioctl, __VA_ARGS__)
554 #define safe_fcntl(...) safe_syscall(SYS_fcntl, __VA_ARGS__)
555
556 /* So far all target and host bitmasks are the same */
557 #undef target_to_host_bitmask
558 #define target_to_host_bitmask(x, tbl) (x)
559 #undef host_to_target_bitmask
560 #define host_to_target_bitmask(x, tbl) (x)
561
562 #endif /* SYSCALL_DEFS_H */