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