1 /*- 2 * Copyright (c) 1994-1996 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31 #ifndef _I386_LINUX_LINUX_H_ 32 #define _I386_LINUX_LINUX_H_ 33 34 #include <sys/signal.h> /* for sigval union */ 35 36 #include <i386/linux/linux_syscall.h> 37 38 #ifdef MALLOC_DECLARE 39 MALLOC_DECLARE(M_LINUX); 40 #endif 41 42 /* 43 * Miscellaneous 44 */ 45 #define LINUX_NAME_MAX 255 46 #define LINUX_MAX_UTSNAME 65 47 48 /* Scheduling policies */ 49 #define LINUX_SCHED_OTHER 0 50 #define LINUX_SCHED_FIFO 1 51 #define LINUX_SCHED_RR 2 52 53 /* Resource limits */ 54 #define LINUX_RLIMIT_CPU 0 55 #define LINUX_RLIMIT_FSIZE 1 56 #define LINUX_RLIMIT_DATA 2 57 #define LINUX_RLIMIT_STACK 3 58 #define LINUX_RLIMIT_CORE 4 59 #define LINUX_RLIMIT_RSS 5 60 #define LINUX_RLIMIT_NPROC 6 61 #define LINUX_RLIMIT_NOFILE 7 62 #define LINUX_RLIMIT_MEMLOCK 8 63 #define LINUX_RLIMIT_AS 9 /* address space limit */ 64 65 #define LINUX_RLIM_NLIMITS 10 66 67 /* mmap options */ 68 #define LINUX_MAP_SHARED 0x0001 69 #define LINUX_MAP_PRIVATE 0x0002 70 #define LINUX_MAP_FIXED 0x0010 71 #define LINUX_MAP_ANON 0x0020 72 #define LINUX_MAP_GROWSDOWN 0x0100 73 74 typedef char * linux_caddr_t; 75 typedef long linux_clock_t; 76 typedef u_short linux_dev_t; 77 typedef u_short linux_gid_t; 78 typedef u_long linux_ino_t; 79 typedef int linux_key_t; /* XXX */ 80 typedef u_short linux_mode_t; 81 typedef u_short linux_nlink_t; 82 typedef long linux_off_t; 83 typedef int linux_pid_t; 84 typedef u_int linux_size_t; 85 typedef long linux_time_t; 86 typedef u_short linux_uid_t; 87 88 typedef struct { 89 long val[2]; 90 } linux_fsid_t; 91 92 struct linux_new_utsname { 93 char sysname[LINUX_MAX_UTSNAME]; 94 char nodename[LINUX_MAX_UTSNAME]; 95 char release[LINUX_MAX_UTSNAME]; 96 char version[LINUX_MAX_UTSNAME]; 97 char machine[LINUX_MAX_UTSNAME]; 98 char domainname[LINUX_MAX_UTSNAME]; 99 }; 100 101 /* 102 * Signalling 103 */ 104 #define LINUX_SIGHUP 1 105 #define LINUX_SIGINT 2 106 #define LINUX_SIGQUIT 3 107 #define LINUX_SIGILL 4 108 #define LINUX_SIGTRAP 5 109 #define LINUX_SIGABRT 6 110 #define LINUX_SIGIOT LINUX_SIGABRT 111 #define LINUX_SIGBUS 7 112 #define LINUX_SIGFPE 8 113 #define LINUX_SIGKILL 9 114 #define LINUX_SIGUSR1 10 115 #define LINUX_SIGSEGV 11 116 #define LINUX_SIGUSR2 12 117 #define LINUX_SIGPIPE 13 118 #define LINUX_SIGALRM 14 119 #define LINUX_SIGTERM 15 120 #define LINUX_SIGSTKFLT 16 121 #define LINUX_SIGCHLD 17 122 #define LINUX_SIGCONT 18 123 #define LINUX_SIGSTOP 19 124 #define LINUX_SIGTSTP 20 125 #define LINUX_SIGTTIN 21 126 #define LINUX_SIGTTOU 22 127 #define LINUX_SIGURG 23 128 #define LINUX_SIGXCPU 24 129 #define LINUX_SIGXFSZ 25 130 #define LINUX_SIGVTALRM 26 131 #define LINUX_SIGPROF 27 132 #define LINUX_SIGWINCH 28 133 #define LINUX_SIGIO 29 134 #define LINUX_SIGPOLL LINUX_SIGIO 135 #define LINUX_SIGPWR 30 136 #define LINUX_SIGUNUSED 31 137 138 #define LINUX_SIGTBLSZ 31 139 #define LINUX_NSIG_WORDS 2 140 #define LINUX_NBPW 32 141 #define LINUX_NSIG (LINUX_NBPW * LINUX_NSIG_WORDS) 142 143 /* sigaction flags */ 144 #define LINUX_SA_NOCLDSTOP 0x00000001 145 #define LINUX_SA_NOCLDWAIT 0x00000002 146 #define LINUX_SA_SIGINFO 0x00000004 147 #define LINUX_SA_RESTORER 0x04000000 148 #define LINUX_SA_ONSTACK 0x08000000 149 #define LINUX_SA_RESTART 0x10000000 150 #define LINUX_SA_INTERRUPT 0x20000000 151 #define LINUX_SA_NOMASK 0x40000000 152 #define LINUX_SA_ONESHOT 0x80000000 153 154 /* sigprocmask actions */ 155 #define LINUX_SIG_BLOCK 0 156 #define LINUX_SIG_UNBLOCK 1 157 #define LINUX_SIG_SETMASK 2 158 159 /* sigset_t macros */ 160 #define LINUX_SIGEMPTYSET(set) (set).__bits[0] = (set).__bits[1] = 0 161 #define LINUX_SIGISMEMBER(set, sig) SIGISMEMBER(set, sig) 162 #define LINUX_SIGADDSET(set, sig) SIGADDSET(set, sig) 163 164 /* sigaltstack */ 165 #define LINUX_MINSIGSTKSZ 2048 166 #define LINUX_SS_ONSTACK_BC 0 /* backwards compat SS_ONSTACK */ 167 #define LINUX_SS_ONSTACK 1 168 #define LINUX_SS_DISABLE 2 169 170 171 int linux_to_bsd_sigaltstack(int lsa); 172 int bsd_to_linux_sigaltstack(int bsa); 173 174 175 typedef void (*linux_handler_t)(int); 176 typedef u_long linux_osigset_t; 177 178 typedef struct { 179 u_int __bits[LINUX_NSIG_WORDS]; 180 } linux_sigset_t; 181 182 typedef struct { 183 linux_handler_t lsa_handler; 184 linux_osigset_t lsa_mask; 185 u_long lsa_flags; 186 void (*lsa_restorer)(void); 187 } linux_osigaction_t; 188 189 typedef struct { 190 linux_handler_t lsa_handler; 191 u_long lsa_flags; 192 void (*lsa_restorer)(void); 193 linux_sigset_t lsa_mask; 194 } linux_sigaction_t; 195 196 typedef struct { 197 void *ss_sp; 198 int ss_flags; 199 linux_size_t ss_size; 200 } linux_stack_t; 201 202 /* The Linux sigcontext, pretty much a standard 386 trapframe. */ 203 struct linux_sigcontext { 204 int sc_gs; 205 int sc_fs; 206 int sc_es; 207 int sc_ds; 208 int sc_edi; 209 int sc_esi; 210 int sc_ebp; 211 int sc_esp; 212 int sc_ebx; 213 int sc_edx; 214 int sc_ecx; 215 int sc_eax; 216 int sc_trapno; 217 int sc_err; 218 int sc_eip; 219 int sc_cs; 220 int sc_eflags; 221 int sc_esp_at_signal; 222 int sc_ss; 223 int sc_387; 224 int sc_mask; 225 int sc_cr2; 226 }; 227 228 struct linux_ucontext { 229 unsigned long uc_flags; 230 void *uc_link; 231 linux_stack_t uc_stack; 232 struct linux_sigcontext uc_mcontext; 233 linux_sigset_t uc_sigmask; 234 }; 235 236 237 #define LINUX_SI_MAX_SIZE 128 238 #define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE/sizeof(int)) - 3) 239 240 typedef struct siginfo { 241 int lsi_signo; 242 int lsi_errno; 243 int lsi_code; 244 245 union { 246 int _pad[LINUX_SI_PAD_SIZE]; 247 struct { 248 linux_pid_t _pid; 249 linux_uid_t _uid; 250 } _kill; 251 252 struct { 253 unsigned int _timer1; 254 unsigned int _timer2; 255 } _timer; 256 257 struct { 258 linux_pid_t _pid; /* sender's pid */ 259 linux_uid_t _uid; /* sender's uid */ 260 union sigval _sigval; 261 } _rt; 262 263 struct { 264 linux_pid_t _pid; /* which child */ 265 linux_uid_t _uid; /* sender's uid */ 266 int _status; /* exit code */ 267 linux_clock_t _utime; 268 linux_clock_t _stime; 269 } _sigchld; 270 271 struct { 272 void *_addr; /* faulting insn/memory ref. */ 273 } _sigfault; 274 275 struct { 276 int _band; /* POLL_IN, POLL_OUT, POLL_MSG */ 277 int _fd; 278 } _sigpoll; 279 } _sifields; 280 } linux_siginfo_t; 281 282 #define lsi_pid _sifields._kill._pid 283 #define lsi_uid _sifields._kill._uid 284 #define lsi_status _sifields._sigchld._status 285 #define lsi_utime _sifields._sigchld._utime 286 #define lsi_stime _sifields._sigchld._stime 287 #define lsi_value _sifields._rt._sigval 288 #define lsi_int _sifields._rt._sigval.sival_int 289 #define lsi_ptr _sifields._rt._sigval.sival_ptr 290 #define lsi_addr _sifields._sigfault._addr 291 #define lsi_band _sifields._sigpoll._band 292 #define lsi_fd _sifields._sigpoll._fd 293 294 struct linux_fpreg { 295 u_int16_t significand[4]; 296 u_int16_t exponent; 297 }; 298 299 struct linux_fpxreg { 300 u_int16_t significand[4]; 301 u_int16_t exponent; 302 u_int16_t padding[3]; 303 }; 304 305 struct linux_xmmreg { 306 u_int32_t element[4]; 307 }; 308 309 struct linux_fpstate { 310 /* Regular FPU environment */ 311 u_int32_t cw; 312 u_int32_t sw; 313 u_int32_t tag; 314 u_int32_t ipoff; 315 u_int32_t cssel; 316 u_int32_t dataoff; 317 u_int32_t datasel; 318 struct linux_fpreg _st[8]; 319 u_int16_t status; 320 u_int16_t magic; /* 0xffff = regular FPU data */ 321 322 /* FXSR FPU environment */ 323 u_int32_t _fxsr_env[6]; /* env is ignored */ 324 u_int32_t mxcsr; 325 u_int32_t reserved; 326 struct linux_fpxreg _fxsr_st[8]; /* reg data is ignored */ 327 struct linux_xmmreg _xmm[8]; 328 u_int32_t padding[56]; 329 }; 330 331 /* 332 * We make the stack look like Linux expects it when calling a signal 333 * handler, but use the BSD way of calling the handler and sigreturn(). 334 * This means that we need to pass the pointer to the handler too. 335 * It is appended to the frame to not interfere with the rest of it. 336 */ 337 struct linux_sigframe { 338 int sf_sig; 339 struct linux_sigcontext sf_sc; 340 struct linux_fpstate sf_fpstate; 341 u_int sf_extramask[LINUX_NSIG_WORDS-1]; 342 linux_handler_t sf_handler; 343 }; 344 345 struct linux_rt_sigframe { 346 int sf_sig; 347 linux_siginfo_t *sf_siginfo; 348 struct linux_ucontext *sf_ucontext; 349 linux_siginfo_t sf_si; 350 struct linux_ucontext sf_sc; 351 linux_handler_t sf_handler; 352 }; 353 354 extern int bsd_to_linux_signal[]; 355 extern int linux_to_bsd_signal[]; 356 extern struct sysentvec linux_sysvec; 357 extern struct sysentvec elf_linux_sysvec; 358 359 /* 360 * Pluggable ioctl handlers 361 */ 362 struct linker_set; 363 struct linux_ioctl_args; 364 struct proc; 365 366 typedef int linux_ioctl_function_t(struct proc *, struct linux_ioctl_args *); 367 368 struct linux_ioctl_handler { 369 linux_ioctl_function_t *func; 370 int low, high; 371 }; 372 373 int linux_ioctl_register_handler(struct linux_ioctl_handler *h); 374 int linux_ioctl_register_handlers(struct linker_set *s); 375 int linux_ioctl_unregister_handler(struct linux_ioctl_handler *h); 376 int linux_ioctl_unregister_handlers(struct linker_set *s); 377 378 /* 379 * open/fcntl flags 380 */ 381 #define LINUX_O_RDONLY 00 382 #define LINUX_O_WRONLY 01 383 #define LINUX_O_RDWR 02 384 #define LINUX_O_CREAT 0100 385 #define LINUX_O_EXCL 0200 386 #define LINUX_O_NOCTTY 0400 387 #define LINUX_O_TRUNC 01000 388 #define LINUX_O_APPEND 02000 389 #define LINUX_O_NONBLOCK 04000 390 #define LINUX_O_NDELAY LINUX_O_NONBLOCK 391 #define LINUX_O_SYNC 010000 392 #define LINUX_FASYNC 020000 393 394 #define LINUX_F_DUPFD 0 395 #define LINUX_F_GETFD 1 396 #define LINUX_F_SETFD 2 397 #define LINUX_F_GETFL 3 398 #define LINUX_F_SETFL 4 399 #define LINUX_F_GETLK 5 400 #define LINUX_F_SETLK 6 401 #define LINUX_F_SETLKW 7 402 #define LINUX_F_SETOWN 8 403 #define LINUX_F_GETOWN 9 404 405 #define LINUX_F_RDLCK 0 406 #define LINUX_F_WRLCK 1 407 #define LINUX_F_UNLCK 2 408 409 /* 410 * SystemV IPC defines 411 */ 412 #define LINUX_SEMOP 1 413 #define LINUX_SEMGET 2 414 #define LINUX_SEMCTL 3 415 #define LINUX_MSGSND 11 416 #define LINUX_MSGRCV 12 417 #define LINUX_MSGGET 13 418 #define LINUX_MSGCTL 14 419 #define LINUX_SHMAT 21 420 #define LINUX_SHMDT 22 421 #define LINUX_SHMGET 23 422 #define LINUX_SHMCTL 24 423 424 #define LINUX_IPC_RMID 0 425 #define LINUX_IPC_SET 1 426 #define LINUX_IPC_STAT 2 427 #define LINUX_IPC_INFO 3 428 429 #define LINUX_SHM_LOCK 11 430 #define LINUX_SHM_UNLOCK 12 431 #define LINUX_SHM_STAT 13 432 #define LINUX_SHM_INFO 14 433 434 #define LINUX_SHM_RDONLY 0x1000 435 #define LINUX_SHM_RND 0x2000 436 #define LINUX_SHM_REMAP 0x4000 437 438 /* semctl commands */ 439 #define LINUX_GETPID 11 440 #define LINUX_GETVAL 12 441 #define LINUX_GETALL 13 442 #define LINUX_GETNCNT 14 443 #define LINUX_GETZCNT 15 444 #define LINUX_SETVAL 16 445 #define LINUX_SETALL 17 446 447 /* 448 * Socket defines 449 */ 450 #define LINUX_SOCKET 1 451 #define LINUX_BIND 2 452 #define LINUX_CONNECT 3 453 #define LINUX_LISTEN 4 454 #define LINUX_ACCEPT 5 455 #define LINUX_GETSOCKNAME 6 456 #define LINUX_GETPEERNAME 7 457 #define LINUX_SOCKETPAIR 8 458 #define LINUX_SEND 9 459 #define LINUX_RECV 10 460 #define LINUX_SENDTO 11 461 #define LINUX_RECVFROM 12 462 #define LINUX_SHUTDOWN 13 463 #define LINUX_SETSOCKOPT 14 464 #define LINUX_GETSOCKOPT 15 465 #define LINUX_SENDMSG 16 466 #define LINUX_RECVMSG 17 467 468 #define LINUX_AF_UNSPEC 0 469 #define LINUX_AF_UNIX 1 470 #define LINUX_AF_INET 2 471 #define LINUX_AF_AX25 3 472 #define LINUX_AF_IPX 4 473 #define LINUX_AF_APPLETALK 5 474 475 #define LINUX_SOL_SOCKET 1 476 #define LINUX_SOL_IP 0 477 #define LINUX_SOL_IPX 256 478 #define LINUX_SOL_AX25 257 479 #define LINUX_SOL_TCP 6 480 #define LINUX_SOL_UDP 17 481 482 #define LINUX_SO_DEBUG 1 483 #define LINUX_SO_REUSEADDR 2 484 #define LINUX_SO_TYPE 3 485 #define LINUX_SO_ERROR 4 486 #define LINUX_SO_DONTROUTE 5 487 #define LINUX_SO_BROADCAST 6 488 #define LINUX_SO_SNDBUF 7 489 #define LINUX_SO_RCVBUF 8 490 #define LINUX_SO_KEEPALIVE 9 491 #define LINUX_SO_OOBINLINE 10 492 #define LINUX_SO_NO_CHECK 11 493 #define LINUX_SO_PRIORITY 12 494 #define LINUX_SO_LINGER 13 495 496 #define LINUX_IP_TOS 1 497 #define LINUX_IP_TTL 2 498 #define LINUX_IP_HDRINCL 3 499 #define LINUX_IP_OPTIONS 4 500 501 #define LINUX_IP_MULTICAST_IF 32 502 #define LINUX_IP_MULTICAST_TTL 33 503 #define LINUX_IP_MULTICAST_LOOP 34 504 #define LINUX_IP_ADD_MEMBERSHIP 35 505 #define LINUX_IP_DROP_MEMBERSHIP 36 506 507 struct linux_sockaddr { 508 u_short sa_family; 509 char sa_data[14]; 510 }; 511 512 struct linux_ifmap { 513 u_long mem_start; 514 u_long mem_end; 515 u_short base_addr; 516 u_char irq; 517 u_char dma; 518 u_char port; 519 }; 520 521 #define LINUX_IFHWADDRLEN 6 522 #define LINUX_IFNAMSIZ 16 523 524 struct linux_ifreq { 525 union { 526 char ifrn_name[LINUX_IFNAMSIZ]; 527 } ifr_ifrn; 528 529 union { 530 struct linux_sockaddr ifru_addr; 531 struct linux_sockaddr ifru_dstaddr; 532 struct linux_sockaddr ifru_broadaddr; 533 struct linux_sockaddr ifru_netmask; 534 struct linux_sockaddr ifru_hwaddr; 535 short ifru_flags; 536 int ifru_metric; 537 int ifru_mtu; 538 struct linux_ifmap ifru_map; 539 char ifru_slave[LINUX_IFNAMSIZ]; /* Just fits the size */ 540 linux_caddr_t ifru_data; 541 } ifr_ifru; 542 }; 543 544 #define ifr_name ifr_ifrn.ifrn_name /* interface name */ 545 #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ 546 547 #endif /* !_I386_LINUX_LINUX_H_ */ 548