xref: /openbmc/qemu/bsd-user/syscall_defs.h (revision 61a8f110)
1 /*
2  *  System call related declarations
3  *
4  *  Copyright (c) 2013-15 Stacey D. Son (sson at FreeBSD)
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 
20 #ifndef SYSCALL_DEFS_H
21 #define SYSCALL_DEFS_H
22 
23 #include <sys/syscall.h>
24 #include <sys/resource.h>
25 
26 #include "errno_defs.h"
27 
28 #include "freebsd/syscall_nr.h"
29 #include "netbsd/syscall_nr.h"
30 #include "openbsd/syscall_nr.h"
31 
32 /*
33  * machine/_types.h
34  * or x86/_types.h
35  */
36 
37 /*
38  * time_t seems to be very inconsistly defined for the different *BSD's...
39  *
40  * FreeBSD uses a 64bits time_t except on i386
41  * so we have to add a special case here.
42  *
43  * On NetBSD time_t is always defined as an int64_t.  On OpenBSD time_t
44  * is always defined as an int.
45  *
46  */
47 #if (!defined(TARGET_I386))
48 typedef int64_t target_time_t;
49 #else
50 typedef int32_t target_time_t;
51 #endif
52 
53 struct target_iovec {
54     abi_long iov_base;   /* Starting address */
55     abi_long iov_len;   /* Number of bytes */
56 };
57 
58 /*
59  * sys/ipc.h
60  */
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 */
69 };
70 
71 #define TARGET_IPC_RMID 0   /* remove identifier */
72 #define TARGET_IPC_SET  1   /* set options */
73 #define TARGET_IPC_STAT 2   /* get options */
74 
75 /*
76  *  sys/mman.h
77  */
78 #define TARGET_FREEBSD_MAP_RESERVED0080 0x0080  /* previously misimplemented */
79                                                 /* MAP_INHERIT */
80 #define TARGET_FREEBSD_MAP_RESERVED0100 0x0100  /* previously unimplemented */
81                                                 /* MAP_NOEXTEND */
82 #define TARGET_FREEBSD_MAP_STACK        0x0400  /* region grows down, like a */
83                                                 /* stack */
84 #define TARGET_FREEBSD_MAP_NOSYNC       0x0800  /* page to but do not sync */
85                                                 /* underlying file */
86 
87 #define TARGET_FREEBSD_MAP_FLAGMASK     0x1ff7
88 
89 #define TARGET_NETBSD_MAP_INHERIT       0x0080  /* region is retained after */
90                                                 /* exec */
91 #define TARGET_NETBSD_MAP_TRYFIXED      0x0400  /* attempt hint address, even */
92                                                 /* within break */
93 #define TARGET_NETBSD_MAP_WIRED         0x0800  /* mlock() mapping when it is */
94                                                 /* established */
95 
96 #define TARGET_NETBSD_MAP_STACK         0x2000  /* allocated from memory, */
97                                                 /* swap space (stack) */
98 
99 #define TARGET_NETBSD_MAP_FLAGMASK      0x3ff7
100 
101 #define TARGET_OPENBSD_MAP_INHERIT      0x0080  /* region is retained after */
102                                                 /* exec */
103 #define TARGET_OPENBSD_MAP_NOEXTEND     0x0100  /* for MAP_FILE, don't change */
104                                                 /* file size */
105 #define TARGET_OPENBSD_MAP_TRYFIXED     0x0400  /* attempt hint address, */
106                                                 /* even within heap */
107 
108 #define TARGET_OPENBSD_MAP_FLAGMASK     0x17f7
109 
110 /* XXX */
111 #define TARGET_BSD_MAP_FLAGMASK         0x3ff7
112 
113 /*
114  * sys/time.h
115  * sys/timex.h
116  */
117 
118 typedef abi_long target_freebsd_suseconds_t;
119 
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
125     abi_long _pad;
126 #endif
127 };
128 
129 #define TARGET_CPUCLOCK_WHICH_PID   0
130 #define TARGET_CPUCLOCK_WHICH_TID   1
131 
132 /* sys/umtx.h */
133 struct target_freebsd__umtx_time {
134     struct target_freebsd_timespec  _timeout;
135     uint32_t    _flags;
136     uint32_t    _clockid;
137 };
138 
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
143     abi_long _pad;
144 #endif
145 };
146 
147 /*
148  *  sys/resource.h
149  */
150 #define TARGET_RLIM_INFINITY    RLIM_INFINITY
151 
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
165 
166 struct target_rlimit {
167     uint64_t rlim_cur;
168     uint64_t rlim_max;
169 };
170 
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 */
188 };
189 
190 struct target_freebsd__wrusage {
191     struct target_freebsd_rusage wru_self;
192     struct target_freebsd_rusage wru_children;
193 };
194 
195 /*
196  * sys/stat.h
197  */
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 */
214     int32_t    st_lspare;
215     struct target_freebsd_timespec st_birthtim; /* time of file creation */
216     /*
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
222      * CHAR_BIT is 8...
223      */
224     unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
225     unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
226 } __packed;
227 
228 #if defined(__i386__)
229 #define TARGET_HAS_STAT_TIME_T_EXT       1
230 #endif
231 
232 struct target_stat {
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 */
237     int16_t   st_padding0;
238     uint32_t  st_uid;               /* user ID of the file's owner */
239     uint32_t  st_gid;               /* group ID of the file's group */
240     int32_t   st_padding1;
241     uint64_t  st_rdev;              /* device type */
242 #ifdef TARGET_HAS_STAT_TIME_T_EXT
243     int32_t   st_atim_ext;
244 #endif
245     struct  target_freebsd_timespec st_atim; /* time of last access */
246 #ifdef TARGET_HAS_STAT_TIME_T_EXT
247     int32_t   st_mtim_ext;
248 #endif
249     struct  target_freebsd_timespec st_mtim; /* time of last data modification */
250 #ifdef TARGET_HAS_STAT_TIME_T_EXT
251     int32_t st_ctim_ext;
252 #endif
253     struct  target_freebsd_timespec st_ctim;/* time of last file status change */
254 #ifdef TARGET_HAS_STAT_TIME_T_EXT
255     int32_t st_btim_ext;
256 #endif
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];
264 };
265 
266 
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 */
285     /*
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
291      * CHAR_BIT is 8...
292      */
293     unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
294     unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
295 } __packed;
296 
297 /*
298  * sys/mount.h
299  */
300 
301 /* filesystem id type */
302 typedef struct target_freebsd_fsid { int32_t val[2]; } target_freebsd_fsid_t;
303 
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*/
328 };
329 
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 */
353 };
354 
355 /* File identifier. These are unique per filesystem on a single machine. */
356 #define TARGET_MAXFIDSZ     16
357 
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) */
362 };
363 
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 */
368 };
369 typedef struct target_freebsd_fhandle target_freebsd_fhandle_t;
370 
371 /*
372  * sys/fcntl.h
373  */
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
396 
397 struct target_freebsd_flock {
398     int64_t l_start;
399     int64_t l_len;
400     int32_t l_pid;
401     int16_t l_type;
402     int16_t l_whence;
403     int32_t l_sysid;
404 } QEMU_PACKED;
405 
406 /* sys/unistd.h */
407 /* user: vfork(2) semantics, clear signals */
408 #define TARGET_RFSPAWN (1U << 31)
409 
410 /*
411  * from sys/procctl.h
412  */
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
419 
420 struct target_procctl_reaper_status {
421     uint32_t rs_flags;
422     uint32_t rs_children;
423     uint32_t rs_descendants;
424     uint32_t rs_reaper;
425     uint32_t rs_pid;
426     uint32_t rs_pad0[15];
427 };
428 
429 struct target_procctl_reaper_pidinfo {
430     uint32_t pi_pid;
431     uint32_t pi_subtree;
432     uint32_t pi_flags;
433     uint32_t pi_pad0[15];
434 };
435 
436 struct target_procctl_reaper_pids {
437     uint32_t rp_count;
438     uint32_t rp_pad0[15];
439     abi_ulong rp_pids;
440 };
441 
442 struct target_procctl_reaper_kill {
443     int32_t  rk_sig;
444     uint32_t rk_flags;
445     uint32_t rk_subtree;
446     uint32_t rk_killed;
447     uint32_t rk_fpid;
448     uint32_t rk_pad0[15];
449 };
450 
451 
452 #define safe_syscall0(type, name) \
453 type safe_##name(void) \
454 { \
455     return safe_syscall(SYS_##name); \
456 }
457 
458 #define safe_syscall1(type, name, type1, arg1) \
459 type safe_##name(type1 arg1) \
460 { \
461     return safe_syscall(SYS_##name, arg1); \
462 }
463 
464 #define safe_syscall2(type, name, type1, arg1, type2, arg2) \
465 type safe_##name(type1 arg1, type2 arg2) \
466 { \
467     return safe_syscall(SYS_##name, arg1, arg2); \
468 }
469 
470 #define safe_syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
471 type safe_##name(type1 arg1, type2 arg2, type3 arg3) \
472 { \
473     return safe_syscall(SYS_##name, arg1, arg2, arg3); \
474 }
475 
476 #define safe_syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
477     type4, arg4) \
478 type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
479 { \
480     return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4); \
481 }
482 
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, \
486     type5 arg5) \
487 { \
488     return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5); \
489 }
490 
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) \
495 { \
496     return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
497 }
498 
499 #define safe_fcntl(...) safe_syscall(SYS_fcntl, __VA_ARGS__)
500 
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)
506 
507 #endif /* SYSCALL_DEFS_H */
508