1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 1994-1996 Søren Schmidt 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * $FreeBSD$ 28 */ 29 30 #ifndef _I386_LINUX_H_ 31 #define _I386_LINUX_H_ 32 33 #include <sys/abi_compat.h> 34 35 #include <compat/linux/linux.h> 36 #include <i386/linux/linux_syscall.h> 37 38 #define LINUX_LEGACY_SYSCALLS 39 40 #define LINUX_DTRACE linuxulator 41 42 /* 43 * Provide a separate set of types for the Linux types. 44 */ 45 typedef int l_int; 46 typedef int32_t l_long; 47 typedef int64_t l_longlong; 48 typedef short l_short; 49 typedef unsigned int l_uint; 50 typedef uint32_t l_ulong; 51 typedef uint64_t l_ulonglong; 52 typedef unsigned short l_ushort; 53 54 typedef char *l_caddr_t; 55 typedef l_ulong l_uintptr_t; 56 typedef l_long l_clock_t; 57 typedef l_int l_daddr_t; 58 typedef l_ushort l_dev_t; 59 typedef l_uint l_gid_t; 60 typedef l_ushort l_gid16_t; 61 typedef l_ulong l_ino_t; 62 typedef l_int l_key_t; 63 typedef l_longlong l_loff_t; 64 typedef l_ushort l_mode_t; 65 typedef l_long l_off_t; 66 typedef l_int l_pid_t; 67 typedef l_uint l_size_t; 68 typedef l_long l_suseconds_t; 69 typedef l_long l_time_t; 70 typedef l_longlong l_time64_t; 71 typedef l_uint l_uid_t; 72 typedef l_ushort l_uid16_t; 73 typedef l_int l_timer_t; 74 typedef l_int l_mqd_t; 75 typedef l_ulong l_fd_mask; 76 77 typedef struct { 78 l_int val[2]; 79 } l_fsid_t; 80 81 typedef struct { 82 l_time_t tv_sec; 83 l_suseconds_t tv_usec; 84 } l_timeval; 85 86 #define l_fd_set fd_set 87 88 /* 89 * Miscellaneous 90 */ 91 #define LINUX_AT_COUNT 20 /* Count of used aux entry types. 92 * Keep this synchronized with 93 * linux_fixup_elf() code. 94 */ 95 struct l___sysctl_args 96 { 97 l_int *name; 98 l_int nlen; 99 void *oldval; 100 l_size_t *oldlenp; 101 void *newval; 102 l_size_t newlen; 103 l_ulong __spare[4]; 104 }; 105 106 /* Resource limits */ 107 #define LINUX_RLIMIT_CPU 0 108 #define LINUX_RLIMIT_FSIZE 1 109 #define LINUX_RLIMIT_DATA 2 110 #define LINUX_RLIMIT_STACK 3 111 #define LINUX_RLIMIT_CORE 4 112 #define LINUX_RLIMIT_RSS 5 113 #define LINUX_RLIMIT_NPROC 6 114 #define LINUX_RLIMIT_NOFILE 7 115 #define LINUX_RLIMIT_MEMLOCK 8 116 #define LINUX_RLIMIT_AS 9 /* Address space limit */ 117 118 #define LINUX_RLIM_NLIMITS 10 119 120 struct l_rlimit { 121 l_ulong rlim_cur; 122 l_ulong rlim_max; 123 }; 124 125 struct l_mmap_argv { 126 l_uintptr_t addr; 127 l_size_t len; 128 l_int prot; 129 l_int flags; 130 l_int fd; 131 l_off_t pgoff; 132 }; 133 134 /* 135 * stat family of syscalls 136 */ 137 struct l_timespec { 138 l_time_t tv_sec; 139 l_long tv_nsec; 140 }; 141 142 /* __kernel_timespec */ 143 struct l_timespec64 { 144 l_time64_t tv_sec; 145 l_longlong tv_nsec; 146 }; 147 148 struct l_newstat { 149 l_ushort st_dev; 150 l_ushort __pad1; 151 l_ulong st_ino; 152 l_ushort st_mode; 153 l_ushort st_nlink; 154 l_ushort st_uid; 155 l_ushort st_gid; 156 l_ushort st_rdev; 157 l_ushort __pad2; 158 l_ulong st_size; 159 l_ulong st_blksize; 160 l_ulong st_blocks; 161 struct l_timespec st_atim; 162 struct l_timespec st_mtim; 163 struct l_timespec st_ctim; 164 l_ulong __unused4; 165 l_ulong __unused5; 166 }; 167 168 struct l_stat { 169 l_ushort st_dev; 170 l_ulong st_ino; 171 l_ushort st_mode; 172 l_ushort st_nlink; 173 l_ushort st_uid; 174 l_ushort st_gid; 175 l_ushort st_rdev; 176 l_long st_size; 177 struct l_timespec st_atim; 178 struct l_timespec st_mtim; 179 struct l_timespec st_ctim; 180 l_long st_blksize; 181 l_long st_blocks; 182 l_ulong st_flags; 183 l_ulong st_gen; 184 }; 185 186 struct l_stat64 { 187 l_ushort st_dev; 188 u_char __pad0[10]; 189 l_ulong __st_ino; 190 l_uint st_mode; 191 l_uint st_nlink; 192 l_ulong st_uid; 193 l_ulong st_gid; 194 l_ushort st_rdev; 195 u_char __pad3[10]; 196 l_longlong st_size; 197 l_ulong st_blksize; 198 l_ulong st_blocks; 199 l_ulong __pad4; 200 struct l_timespec st_atim; 201 struct l_timespec st_mtim; 202 struct l_timespec st_ctim; 203 l_ulonglong st_ino; 204 }; 205 206 struct l_statfs64 { 207 l_int f_type; 208 l_int f_bsize; 209 uint64_t f_blocks; 210 uint64_t f_bfree; 211 uint64_t f_bavail; 212 uint64_t f_files; 213 uint64_t f_ffree; 214 l_fsid_t f_fsid; 215 l_int f_namelen; 216 l_int f_frsize; 217 l_int f_flags; 218 l_int f_spare[4]; 219 }; 220 221 #define LINUX_NSIG_WORDS 2 222 223 /* sigaction flags */ 224 #define LINUX_SA_NOCLDSTOP 0x00000001 225 #define LINUX_SA_NOCLDWAIT 0x00000002 226 #define LINUX_SA_SIGINFO 0x00000004 227 #define LINUX_SA_RESTORER 0x04000000 228 #define LINUX_SA_ONSTACK 0x08000000 229 #define LINUX_SA_RESTART 0x10000000 230 #define LINUX_SA_INTERRUPT 0x20000000 231 #define LINUX_SA_NOMASK 0x40000000 232 #define LINUX_SA_ONESHOT 0x80000000 233 234 /* sigprocmask actions */ 235 #define LINUX_SIG_BLOCK 0 236 #define LINUX_SIG_UNBLOCK 1 237 #define LINUX_SIG_SETMASK 2 238 239 /* sigaltstack */ 240 #define LINUX_MINSIGSTKSZ 2048 241 242 typedef void (*l_handler_t)(l_int); 243 typedef l_ulong l_osigset_t; 244 245 typedef struct { 246 l_handler_t lsa_handler; 247 l_osigset_t lsa_mask; 248 l_ulong lsa_flags; 249 void (*lsa_restorer)(void); 250 } l_osigaction_t; 251 252 typedef struct { 253 l_handler_t lsa_handler; 254 l_ulong lsa_flags; 255 void (*lsa_restorer)(void); 256 l_sigset_t lsa_mask; 257 } l_sigaction_t; 258 259 typedef struct { 260 l_uintptr_t ss_sp; 261 l_int ss_flags; 262 l_size_t ss_size; 263 } l_stack_t; 264 265 /* The Linux sigcontext, pretty much a standard 386 trapframe. */ 266 struct l_sigcontext { 267 l_int sc_gs; 268 l_int sc_fs; 269 l_int sc_es; 270 l_int sc_ds; 271 l_int sc_edi; 272 l_int sc_esi; 273 l_int sc_ebp; 274 l_int sc_esp; 275 l_int sc_ebx; 276 l_int sc_edx; 277 l_int sc_ecx; 278 l_int sc_eax; 279 l_int sc_trapno; 280 l_int sc_err; 281 l_int sc_eip; 282 l_int sc_cs; 283 l_int sc_eflags; 284 l_int sc_esp_at_signal; 285 l_int sc_ss; 286 l_int sc_387; 287 l_int sc_mask; 288 l_int sc_cr2; 289 }; 290 291 struct l_ucontext { 292 l_ulong uc_flags; 293 void *uc_link; 294 l_stack_t uc_stack; 295 struct l_sigcontext uc_mcontext; 296 l_sigset_t uc_sigmask; 297 }; 298 299 #define LINUX_SI_MAX_SIZE 128 300 #define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE/sizeof(l_int)) - 3) 301 302 typedef union l_sigval { 303 l_int sival_int; 304 l_uintptr_t sival_ptr; 305 } l_sigval_t; 306 307 typedef struct l_siginfo { 308 l_int lsi_signo; 309 l_int lsi_errno; 310 l_int lsi_code; 311 union { 312 l_int _pad[LINUX_SI_PAD_SIZE]; 313 314 struct { 315 l_pid_t _pid; 316 l_uid_t _uid; 317 } _kill; 318 319 struct { 320 l_timer_t _tid; 321 l_int _overrun; 322 char _pad[sizeof(l_uid_t) - sizeof(l_int)]; 323 l_sigval_t _sigval; 324 l_int _sys_private; 325 } _timer; 326 327 struct { 328 l_pid_t _pid; /* sender's pid */ 329 l_uid_t _uid; /* sender's uid */ 330 l_sigval_t _sigval; 331 } _rt; 332 333 struct { 334 l_pid_t _pid; /* which child */ 335 l_uid_t _uid; /* sender's uid */ 336 l_int _status; /* exit code */ 337 l_clock_t _utime; 338 l_clock_t _stime; 339 } _sigchld; 340 341 struct { 342 l_uintptr_t _addr; /* Faulting insn/memory ref. */ 343 } _sigfault; 344 345 struct { 346 l_long _band; /* POLL_IN,POLL_OUT,POLL_MSG */ 347 l_int _fd; 348 } _sigpoll; 349 } _sifields; 350 } l_siginfo_t; 351 352 #define lsi_pid _sifields._kill._pid 353 #define lsi_uid _sifields._kill._uid 354 #define lsi_tid _sifields._timer._tid 355 #define lsi_overrun _sifields._timer._overrun 356 #define lsi_sys_private _sifields._timer._sys_private 357 #define lsi_status _sifields._sigchld._status 358 #define lsi_utime _sifields._sigchld._utime 359 #define lsi_stime _sifields._sigchld._stime 360 #define lsi_value _sifields._rt._sigval 361 #define lsi_int _sifields._rt._sigval.sival_int 362 #define lsi_ptr _sifields._rt._sigval.sival_ptr 363 #define lsi_addr _sifields._sigfault._addr 364 #define lsi_band _sifields._sigpoll._band 365 #define lsi_fd _sifields._sigpoll._fd 366 367 struct l_fpreg { 368 u_int16_t significand[4]; 369 u_int16_t exponent; 370 }; 371 372 struct l_fpxreg { 373 u_int16_t significand[4]; 374 u_int16_t exponent; 375 u_int16_t padding[3]; 376 }; 377 378 struct l_xmmreg { 379 u_int32_t element[4]; 380 }; 381 382 struct l_fpstate { 383 /* Regular FPU environment */ 384 u_int32_t cw; 385 u_int32_t sw; 386 u_int32_t tag; 387 u_int32_t ipoff; 388 u_int32_t cssel; 389 u_int32_t dataoff; 390 u_int32_t datasel; 391 struct l_fpreg _st[8]; 392 u_int16_t status; 393 u_int16_t magic; /* 0xffff = regular FPU data */ 394 395 /* FXSR FPU environment */ 396 u_int32_t _fxsr_env[6]; /* env is ignored. */ 397 u_int32_t mxcsr; 398 u_int32_t reserved; 399 struct l_fpxreg _fxsr_st[8]; /* reg data is ignored. */ 400 struct l_xmmreg _xmm[8]; 401 u_int32_t padding[56]; 402 }; 403 404 /* 405 * We make the stack look like Linux expects it when calling a signal 406 * handler, but use the BSD way of calling the handler and sigreturn(). 407 * This means that we need to pass the pointer to the handler too. 408 * It is appended to the frame to not interfere with the rest of it. 409 */ 410 struct l_sigframe { 411 l_int sf_sig; 412 struct l_sigcontext sf_sc; 413 struct l_fpstate sf_fpstate; 414 l_uint sf_extramask[LINUX_NSIG_WORDS-1]; 415 l_handler_t sf_handler; 416 }; 417 418 struct l_rt_sigframe { 419 l_int sf_sig; 420 l_siginfo_t *sf_siginfo; 421 struct l_ucontext *sf_ucontext; 422 l_siginfo_t sf_si; 423 struct l_ucontext sf_sc; 424 l_handler_t sf_handler; 425 }; 426 427 extern struct sysentvec linux_sysvec; 428 429 /* 430 * arch specific open/fcntl flags 431 */ 432 #define LINUX_F_GETLK64 12 433 #define LINUX_F_SETLK64 13 434 #define LINUX_F_SETLKW64 14 435 436 union l_semun { 437 l_int val; 438 l_uintptr_t buf; 439 l_ushort *array; 440 l_uintptr_t __buf; 441 l_uintptr_t __pad; 442 }; 443 444 struct l_ifmap { 445 l_ulong mem_start; 446 l_ulong mem_end; 447 l_ushort base_addr; 448 u_char irq; 449 u_char dma; 450 u_char port; 451 }; 452 453 struct l_ifreq { 454 union { 455 char ifrn_name[LINUX_IFNAMSIZ]; 456 } ifr_ifrn; 457 458 union { 459 struct l_sockaddr ifru_addr; 460 struct l_sockaddr ifru_dstaddr; 461 struct l_sockaddr ifru_broadaddr; 462 struct l_sockaddr ifru_netmask; 463 struct l_sockaddr ifru_hwaddr; 464 l_short ifru_flags[1]; 465 l_int ifru_ivalue; 466 l_int ifru_mtu; 467 struct l_ifmap ifru_map; 468 char ifru_slave[LINUX_IFNAMSIZ]; 469 l_caddr_t ifru_data; 470 } ifr_ifru; 471 }; 472 473 #define ifr_name ifr_ifrn.ifrn_name /* Interface name */ 474 #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ 475 #define ifr_ifindex ifr_ifru.ifru_ivalue /* Interface index */ 476 477 struct l_user_desc { 478 l_uint entry_number; 479 l_uint base_addr; 480 l_uint limit; 481 l_uint seg_32bit:1; 482 l_uint contents:2; 483 l_uint read_exec_only:1; 484 l_uint limit_in_pages:1; 485 l_uint seg_not_present:1; 486 l_uint useable:1; 487 }; 488 489 struct l_desc_struct { 490 unsigned long a, b; 491 }; 492 493 #define LINUX_LOWERWORD 0x0000ffff 494 495 /* 496 * Macros which does the same thing as those in Linux include/asm-um/ldt-i386.h. 497 * These convert Linux user space descriptor to machine one. 498 */ 499 #define LINUX_LDT_entry_a(info) \ 500 ((((info)->base_addr & LINUX_LOWERWORD) << 16) | \ 501 ((info)->limit & LINUX_LOWERWORD)) 502 503 #define LINUX_ENTRY_B_READ_EXEC_ONLY 9 504 #define LINUX_ENTRY_B_CONTENTS 10 505 #define LINUX_ENTRY_B_SEG_NOT_PRESENT 15 506 #define LINUX_ENTRY_B_BASE_ADDR 16 507 #define LINUX_ENTRY_B_USEABLE 20 508 #define LINUX_ENTRY_B_SEG32BIT 22 509 #define LINUX_ENTRY_B_LIMIT 23 510 511 #define LINUX_LDT_entry_b(info) \ 512 (((info)->base_addr & 0xff000000) | \ 513 ((info)->limit & 0xf0000) | \ 514 ((info)->contents << LINUX_ENTRY_B_CONTENTS) | \ 515 (((info)->seg_not_present == 0) << LINUX_ENTRY_B_SEG_NOT_PRESENT) | \ 516 (((info)->base_addr & 0x00ff0000) >> LINUX_ENTRY_B_BASE_ADDR) | \ 517 (((info)->read_exec_only == 0) << LINUX_ENTRY_B_READ_EXEC_ONLY) | \ 518 ((info)->seg_32bit << LINUX_ENTRY_B_SEG32BIT) | \ 519 ((info)->useable << LINUX_ENTRY_B_USEABLE) | \ 520 ((info)->limit_in_pages << LINUX_ENTRY_B_LIMIT) | 0x7000) 521 522 #define LINUX_LDT_empty(info) \ 523 ((info)->base_addr == 0 && \ 524 (info)->limit == 0 && \ 525 (info)->contents == 0 && \ 526 (info)->seg_not_present == 1 && \ 527 (info)->read_exec_only == 1 && \ 528 (info)->seg_32bit == 0 && \ 529 (info)->limit_in_pages == 0 && \ 530 (info)->useable == 0) 531 532 /* 533 * Macros for converting segments. 534 * They do the same as those in arch/i386/kernel/process.c in Linux. 535 */ 536 #define LINUX_GET_BASE(desc) \ 537 ((((desc)->a >> 16) & LINUX_LOWERWORD) | \ 538 (((desc)->b << 16) & 0x00ff0000) | \ 539 ((desc)->b & 0xff000000)) 540 541 #define LINUX_GET_LIMIT(desc) \ 542 (((desc)->a & LINUX_LOWERWORD) | \ 543 ((desc)->b & 0xf0000)) 544 545 #define LINUX_GET_32BIT(desc) \ 546 (((desc)->b >> LINUX_ENTRY_B_SEG32BIT) & 1) 547 #define LINUX_GET_CONTENTS(desc) \ 548 (((desc)->b >> LINUX_ENTRY_B_CONTENTS) & 3) 549 #define LINUX_GET_WRITABLE(desc) \ 550 (((desc)->b >> LINUX_ENTRY_B_READ_EXEC_ONLY) & 1) 551 #define LINUX_GET_LIMIT_PAGES(desc) \ 552 (((desc)->b >> LINUX_ENTRY_B_LIMIT) & 1) 553 #define LINUX_GET_PRESENT(desc) \ 554 (((desc)->b >> LINUX_ENTRY_B_SEG_NOT_PRESENT) & 1) 555 #define LINUX_GET_USEABLE(desc) \ 556 (((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1) 557 558 #define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r)) 559 560 /* robust futexes */ 561 struct linux_robust_list { 562 struct linux_robust_list *next; 563 }; 564 565 struct linux_robust_list_head { 566 struct linux_robust_list list; 567 l_long futex_offset; 568 struct linux_robust_list *pending_list; 569 }; 570 571 #endif /* !_I386_LINUX_H_ */ 572