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