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