2
0

syscall_defs.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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. #ifndef SYSCALL_DEFS_H
  20. #define SYSCALL_DEFS_H
  21. #include <sys/syscall.h>
  22. #include <sys/resource.h>
  23. #include "errno_defs.h"
  24. #include "freebsd/syscall_nr.h"
  25. #include "netbsd/syscall_nr.h"
  26. #include "openbsd/syscall_nr.h"
  27. /*
  28. * machine/_types.h
  29. * or x86/_types.h
  30. */
  31. /*
  32. * time_t seems to be very inconsistly defined for the different *BSD's...
  33. *
  34. * FreeBSD uses a 64bits time_t except on i386
  35. * so we have to add a special case here.
  36. *
  37. * On NetBSD time_t is always defined as an int64_t. On OpenBSD time_t
  38. * is always defined as an int.
  39. *
  40. */
  41. #if (!defined(TARGET_I386))
  42. typedef int64_t target_time_t;
  43. #else
  44. typedef int32_t target_time_t;
  45. #endif
  46. struct target_iovec {
  47. abi_long iov_base; /* Starting address */
  48. abi_long iov_len; /* Number of bytes */
  49. };
  50. /*
  51. * sys/ipc.h
  52. */
  53. struct target_ipc_perm {
  54. uint32_t cuid; /* creator user id */
  55. uint32_t cgid; /* creator group id */
  56. uint32_t uid; /* user id */
  57. uint32_t gid; /* group id */
  58. uint16_t mode; /* r/w permission */
  59. uint16_t seq; /* sequence # */
  60. abi_long key; /* user specified msg/sem/shm key */
  61. };
  62. #define TARGET_IPC_RMID 0 /* remove identifier */
  63. #define TARGET_IPC_SET 1 /* set options */
  64. #define TARGET_IPC_STAT 2 /* get options */
  65. /*
  66. * sys/shm.h
  67. */
  68. struct target_shmid_ds {
  69. struct target_ipc_perm shm_perm; /* peration permission structure */
  70. abi_ulong shm_segsz; /* size of segment in bytes */
  71. int32_t shm_lpid; /* process ID of last shared memory op */
  72. int32_t shm_cpid; /* process ID of creator */
  73. int32_t shm_nattch; /* number of current attaches */
  74. target_time_t shm_atime; /* time of last shmat() */
  75. target_time_t shm_dtime; /* time of last shmdt() */
  76. target_time_t shm_ctime; /* time of last change by shmctl() */
  77. };
  78. #define N_BSD_SHM_REGIONS 32
  79. struct bsd_shm_regions {
  80. abi_long start;
  81. abi_long size;
  82. };
  83. /*
  84. * sys/mman.h
  85. */
  86. #define TARGET_MADV_DONTNEED 4 /* dont need these pages */
  87. #define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented */
  88. /* MAP_INHERIT */
  89. #define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented */
  90. /* MAP_NOEXTEND */
  91. #define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like a */
  92. /* stack */
  93. #define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync */
  94. /* underlying file */
  95. #define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7
  96. #define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained after */
  97. /* exec */
  98. #define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, even */
  99. /* within break */
  100. #define TARGET_NETBSD_MAP_WIRED 0x0800 /* mlock() mapping when it is */
  101. /* established */
  102. #define TARGET_NETBSD_MAP_STACK 0x2000 /* allocated from memory, */
  103. /* swap space (stack) */
  104. #define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7
  105. #define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained after */
  106. /* exec */
  107. #define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change */
  108. /* file size */
  109. #define TARGET_OPENBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, */
  110. /* even within heap */
  111. #define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7
  112. /* XXX */
  113. #define TARGET_BSD_MAP_FLAGMASK 0x3ff7
  114. /*
  115. * sys/time.h
  116. * sys/timex.h
  117. */
  118. typedef abi_long target_freebsd_suseconds_t;
  119. /* compare to sys/timespec.h */
  120. struct target_freebsd_timespec {
  121. target_time_t tv_sec; /* seconds */
  122. abi_long tv_nsec; /* and nanoseconds */
  123. #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
  124. abi_long _pad;
  125. #endif
  126. };
  127. #define TARGET_CPUCLOCK_WHICH_PID 0
  128. #define TARGET_CPUCLOCK_WHICH_TID 1
  129. /* sys/umtx.h */
  130. struct target_freebsd__umtx_time {
  131. struct target_freebsd_timespec _timeout;
  132. uint32_t _flags;
  133. uint32_t _clockid;
  134. };
  135. struct target_freebsd_timeval {
  136. target_time_t tv_sec; /* seconds */
  137. target_freebsd_suseconds_t tv_usec;/* and microseconds */
  138. #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
  139. abi_long _pad;
  140. #endif
  141. };
  142. /*
  143. * sys/resource.h
  144. */
  145. #define TARGET_RLIM_INFINITY RLIM_INFINITY
  146. #define TARGET_RLIMIT_CPU 0
  147. #define TARGET_RLIMIT_FSIZE 1
  148. #define TARGET_RLIMIT_DATA 2
  149. #define TARGET_RLIMIT_STACK 3
  150. #define TARGET_RLIMIT_CORE 4
  151. #define TARGET_RLIMIT_RSS 5
  152. #define TARGET_RLIMIT_MEMLOCK 6
  153. #define TARGET_RLIMIT_NPROC 7
  154. #define TARGET_RLIMIT_NOFILE 8
  155. #define TARGET_RLIMIT_SBSIZE 9
  156. #define TARGET_RLIMIT_AS 10
  157. #define TARGET_RLIMIT_NPTS 11
  158. #define TARGET_RLIMIT_SWAP 12
  159. struct target_rlimit {
  160. uint64_t rlim_cur;
  161. uint64_t rlim_max;
  162. };
  163. struct target_freebsd_rusage {
  164. struct target_freebsd_timeval ru_utime; /* user time used */
  165. struct target_freebsd_timeval ru_stime; /* system time used */
  166. abi_long ru_maxrss; /* maximum resident set size */
  167. abi_long ru_ixrss; /* integral shared memory size */
  168. abi_long ru_idrss; /* integral unshared data size */
  169. abi_long ru_isrss; /* integral unshared stack size */
  170. abi_long ru_minflt; /* page reclaims */
  171. abi_long ru_majflt; /* page faults */
  172. abi_long ru_nswap; /* swaps */
  173. abi_long ru_inblock; /* block input operations */
  174. abi_long ru_oublock; /* block output operations */
  175. abi_long ru_msgsnd; /* messages sent */
  176. abi_long ru_msgrcv; /* messages received */
  177. abi_long ru_nsignals; /* signals received */
  178. abi_long ru_nvcsw; /* voluntary context switches */
  179. abi_long ru_nivcsw; /* involuntary context switches */
  180. };
  181. struct target_freebsd__wrusage {
  182. struct target_freebsd_rusage wru_self;
  183. struct target_freebsd_rusage wru_children;
  184. };
  185. /*
  186. * sys/stat.h
  187. */
  188. struct target_freebsd11_stat {
  189. uint32_t st_dev; /* inode's device */
  190. uint32_t st_ino; /* inode's number */
  191. int16_t st_mode; /* inode protection mode */
  192. int16_t st_nlink; /* number of hard links */
  193. uint32_t st_uid; /* user ID of the file's owner */
  194. uint32_t st_gid; /* group ID of the file's group */
  195. uint32_t st_rdev; /* device type */
  196. struct target_freebsd_timespec st_atim; /* time last accessed */
  197. struct target_freebsd_timespec st_mtim; /* time last data modification */
  198. struct target_freebsd_timespec st_ctim; /* time last file status change */
  199. int64_t st_size; /* file size, in bytes */
  200. int64_t st_blocks; /* blocks allocated for file */
  201. uint32_t st_blksize; /* optimal blocksize for I/O */
  202. uint32_t st_flags; /* user defined flags for file */
  203. uint32_t st_gen; /* file generation number */
  204. int32_t st_lspare;
  205. struct target_freebsd_timespec st_birthtim; /* time of file creation */
  206. /*
  207. * Explicitly pad st_birthtim to 16 bytes so that the size of
  208. * struct stat is backwards compatible. We use bitfields instead
  209. * of an array of chars so that this doesn't require a C99 compiler
  210. * to compile if the size of the padding is 0. We use 2 bitfields
  211. * to cover up to 64 bits on 32-bit machines. We assume that
  212. * CHAR_BIT is 8...
  213. */
  214. unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
  215. unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
  216. } __packed;
  217. #if defined(__i386__)
  218. #define TARGET_HAS_STAT_TIME_T_EXT 1
  219. #endif
  220. struct target_stat {
  221. uint64_t st_dev; /* inode's device */
  222. uint64_t st_ino; /* inode's number */
  223. uint64_t st_nlink; /* number of hard links */
  224. int16_t st_mode; /* inode protection mode */
  225. int16_t st_padding0;
  226. uint32_t st_uid; /* user ID of the file's owner */
  227. uint32_t st_gid; /* group ID of the file's group */
  228. int32_t st_padding1;
  229. uint64_t st_rdev; /* device type */
  230. #ifdef TARGET_HAS_STAT_TIME_T_EXT
  231. int32_t st_atim_ext;
  232. #endif
  233. struct target_freebsd_timespec st_atim; /* time of last access */
  234. #ifdef TARGET_HAS_STAT_TIME_T_EXT
  235. int32_t st_mtim_ext;
  236. #endif
  237. struct target_freebsd_timespec st_mtim; /* time of last data modification */
  238. #ifdef TARGET_HAS_STAT_TIME_T_EXT
  239. int32_t st_ctim_ext;
  240. #endif
  241. struct target_freebsd_timespec st_ctim;/* time of last file status change */
  242. #ifdef TARGET_HAS_STAT_TIME_T_EXT
  243. int32_t st_btim_ext;
  244. #endif
  245. struct target_freebsd_timespec st_birthtim; /* time of file creation */
  246. int64_t st_size; /* file size, in bytes */
  247. int64_t st_blocks; /* blocks allocated for file */
  248. uint32_t st_blksize; /* optimal blocksize for I/O */
  249. uint32_t st_flags; /* user defined flags for file */
  250. uint64_t st_gen; /* file generation number */
  251. uint64_t st_spare[10];
  252. };
  253. /* struct nstat is the same as stat above but without the st_lspare field */
  254. struct target_freebsd11_nstat {
  255. uint32_t st_dev; /* inode's device */
  256. uint32_t st_ino; /* inode's number */
  257. int16_t st_mode; /* inode protection mode */
  258. int16_t st_nlink; /* number of hard links */
  259. uint32_t st_uid; /* user ID of the file's owner */
  260. uint32_t st_gid; /* group ID of the file's group */
  261. uint32_t st_rdev; /* device type */
  262. struct target_freebsd_timespec st_atim; /* time last accessed */
  263. struct target_freebsd_timespec st_mtim; /* time last data modification */
  264. struct target_freebsd_timespec st_ctim; /* time last file status change */
  265. int64_t st_size; /* file size, in bytes */
  266. int64_t st_blocks; /* blocks allocated for file */
  267. uint32_t st_blksize; /* optimal blocksize for I/O */
  268. uint32_t st_flags; /* user defined flags for file */
  269. uint32_t st_gen; /* file generation number */
  270. struct target_freebsd_timespec st_birthtim; /* time of file creation */
  271. /*
  272. * Explicitly pad st_birthtim to 16 bytes so that the size of
  273. * struct stat is backwards compatible. We use bitfields instead
  274. * of an array of chars so that this doesn't require a C99 compiler
  275. * to compile if the size of the padding is 0. We use 2 bitfields
  276. * to cover up to 64 bits on 32-bit machines. We assume that
  277. * CHAR_BIT is 8...
  278. */
  279. unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
  280. unsigned int:(8 / 2) * (16 - (int)sizeof(struct target_freebsd_timespec));
  281. } __packed;
  282. /*
  283. * sys/mount.h
  284. */
  285. /* filesystem id type */
  286. typedef struct target_freebsd_fsid { int32_t val[2]; } target_freebsd_fsid_t;
  287. /* filesystem statistics */
  288. struct target_freebsd11_statfs {
  289. uint32_t f_version; /* structure version number */
  290. uint32_t f_type; /* type of filesystem */
  291. uint64_t f_flags; /* copy of mount exported flags */
  292. uint64_t f_bsize; /* filesystem fragment size */
  293. uint64_t f_iosize; /* optimal transfer block size */
  294. uint64_t f_blocks; /* total data blocks in filesystem */
  295. uint64_t f_bfree; /* free blocks in filesystem */
  296. int64_t f_bavail; /* free blocks avail to non-superuser */
  297. uint64_t f_files; /* total file nodes in filesystem */
  298. int64_t f_ffree; /* free nodes avail to non-superuser */
  299. uint64_t f_syncwrites; /* count of sync writes since mount */
  300. uint64_t f_asyncwrites; /* count of async writes since mount */
  301. uint64_t f_syncreads; /* count of sync reads since mount */
  302. uint64_t f_asyncreads; /* count of async reads since mount */
  303. uint64_t f_spare[10]; /* unused spare */
  304. uint32_t f_namemax; /* maximum filename length */
  305. uint32_t f_owner; /* user that mounted the filesystem */
  306. target_freebsd_fsid_t f_fsid; /* filesystem id */
  307. char f_charspare[80]; /* spare string space */
  308. char f_fstypename[16]; /* filesys type name */
  309. char f_mntfromname[88]; /* mount filesystem */
  310. char f_mntonname[88]; /* dir on which mounted*/
  311. };
  312. struct target_statfs {
  313. uint32_t f_version; /* structure version number */
  314. uint32_t f_type; /* type of filesystem */
  315. uint64_t f_flags; /* copy of mount exported flags */
  316. uint64_t f_bsize; /* filesystem fragment size */
  317. uint64_t f_iosize; /* optimal transfer block size */
  318. uint64_t f_blocks; /* total data blocks in filesystem */
  319. uint64_t f_bfree; /* free blocks in filesystem */
  320. int64_t f_bavail; /* free blocks avail to non-superuser */
  321. uint64_t f_files; /* total file nodes in filesystem */
  322. int64_t f_ffree; /* free nodes avail to non-superuser */
  323. uint64_t f_syncwrites; /* count of sync writes since mount */
  324. uint64_t f_asyncwrites; /* count of async writes since mount */
  325. uint64_t f_syncreads; /* count of sync reads since mount */
  326. uint64_t f_asyncreads; /* count of async reads since mount */
  327. uint64_t f_spare[10]; /* unused spare */
  328. uint32_t f_namemax; /* maximum filename length */
  329. uint32_t f_owner; /* user that mounted the filesystem */
  330. target_freebsd_fsid_t f_fsid; /* filesystem id */
  331. char f_charspare[80]; /* spare string space */
  332. char f_fstypename[16]; /* filesystem type name */
  333. char f_mntfromname[1024]; /* mounted filesystem */
  334. char f_mntonname[1024]; /* directory on which mounted */
  335. };
  336. /* File identifier. These are unique per filesystem on a single machine. */
  337. #define TARGET_MAXFIDSZ 16
  338. struct target_freebsd_fid {
  339. uint16_t fid_len; /* len of data in bytes */
  340. uint16_t fid_data0; /* force longword align */
  341. char fid_data[TARGET_MAXFIDSZ]; /* data (variable len) */
  342. };
  343. /* Generic file handle */
  344. struct target_freebsd_fhandle {
  345. target_freebsd_fsid_t fh_fsid; /* Filesystem id of mount point */
  346. struct target_freebsd_fid fh_fid; /* Filesys specific id */
  347. };
  348. typedef struct target_freebsd_fhandle target_freebsd_fhandle_t;
  349. /*
  350. * sys/fcntl.h
  351. */
  352. #define TARGET_F_DUPFD 0
  353. #define TARGET_F_GETFD 1
  354. #define TARGET_F_SETFD 2
  355. #define TARGET_F_GETFL 3
  356. #define TARGET_F_SETFL 4
  357. #define TARGET_F_GETOWN 5
  358. #define TARGET_F_SETOWN 6
  359. #define TARGET_F_OGETLK 7
  360. #define TARGET_F_OSETLK 8
  361. #define TARGET_F_OSETLKW 9
  362. #define TARGET_F_DUP2FD 10
  363. #define TARGET_F_GETLK 11
  364. #define TARGET_F_SETLK 12
  365. #define TARGET_F_SETLKW 13
  366. #define TARGET_F_SETLK_REMOTE 14
  367. #define TARGET_F_READAHEAD 15
  368. #define TARGET_F_RDAHEAD 16
  369. #define TARGET_F_DUPFD_CLOEXEC 17
  370. #define TARGET_F_DUP2FD_CLOEXEC 18
  371. /* FreeBSD-specific */
  372. #define TARGET_F_ADD_SEALS 19
  373. #define TARGET_F_GET_SEALS 20
  374. struct target_freebsd_flock {
  375. int64_t l_start;
  376. int64_t l_len;
  377. int32_t l_pid;
  378. int16_t l_type;
  379. int16_t l_whence;
  380. int32_t l_sysid;
  381. } QEMU_PACKED;
  382. /* sys/unistd.h */
  383. /* user: vfork(2) semantics, clear signals */
  384. #define TARGET_RFSPAWN (1U << 31)
  385. /*
  386. * from sys/procctl.h
  387. */
  388. #define TARGET_PROC_SPROTECT 1
  389. #define TARGET_PROC_REAP_ACQUIRE 2
  390. #define TARGET_PROC_REAP_RELEASE 3
  391. #define TARGET_PROC_REAP_STATUS 4
  392. #define TARGET_PROC_REAP_GETPIDS 5
  393. #define TARGET_PROC_REAP_KILL 6
  394. struct target_procctl_reaper_status {
  395. uint32_t rs_flags;
  396. uint32_t rs_children;
  397. uint32_t rs_descendants;
  398. uint32_t rs_reaper;
  399. uint32_t rs_pid;
  400. uint32_t rs_pad0[15];
  401. };
  402. struct target_procctl_reaper_pidinfo {
  403. uint32_t pi_pid;
  404. uint32_t pi_subtree;
  405. uint32_t pi_flags;
  406. uint32_t pi_pad0[15];
  407. };
  408. struct target_procctl_reaper_pids {
  409. uint32_t rp_count;
  410. uint32_t rp_pad0[15];
  411. abi_ulong rp_pids;
  412. };
  413. struct target_procctl_reaper_kill {
  414. int32_t rk_sig;
  415. uint32_t rk_flags;
  416. uint32_t rk_subtree;
  417. uint32_t rk_killed;
  418. uint32_t rk_fpid;
  419. uint32_t rk_pad0[15];
  420. };
  421. #define safe_syscall0(type, name) \
  422. type safe_##name(void) \
  423. { \
  424. return safe_syscall(SYS_##name); \
  425. }
  426. #define safe_syscall1(type, name, type1, arg1) \
  427. type safe_##name(type1 arg1) \
  428. { \
  429. return safe_syscall(SYS_##name, arg1); \
  430. }
  431. #define safe_syscall2(type, name, type1, arg1, type2, arg2) \
  432. type safe_##name(type1 arg1, type2 arg2) \
  433. { \
  434. return safe_syscall(SYS_##name, arg1, arg2); \
  435. }
  436. #define safe_syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
  437. type safe_##name(type1 arg1, type2 arg2, type3 arg3) \
  438. { \
  439. return safe_syscall(SYS_##name, arg1, arg2, arg3); \
  440. }
  441. #define safe_syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
  442. type4, arg4) \
  443. type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  444. { \
  445. return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4); \
  446. }
  447. #define safe_syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
  448. type4, arg4, type5, arg5) \
  449. type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  450. type5 arg5) \
  451. { \
  452. return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5); \
  453. }
  454. #define safe_syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
  455. type4, arg4, type5, arg5, type6, arg6) \
  456. type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  457. type5 arg5, type6 arg6) \
  458. { \
  459. return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
  460. }
  461. #define safe_fcntl(...) safe_syscall(SYS_fcntl, __VA_ARGS__)
  462. /* So far all target and host bitmasks are the same */
  463. #undef target_to_host_bitmask
  464. #define target_to_host_bitmask(x, tbl) (x)
  465. #undef host_to_target_bitmask
  466. #define host_to_target_bitmask(x, tbl) (x)
  467. #endif /* SYSCALL_DEFS_H */