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 1 167 #define LINUX_SS_DISABLE 2 168 169 170 int linux_to_bsd_sigaltstack(int lsa); 171 int bsd_to_linux_sigaltstack(int bsa); 172 173 174 typedef void (*linux_handler_t)(int); 175 typedef u_long linux_osigset_t; 176 177 typedef struct { 178 u_int __bits[LINUX_NSIG_WORDS]; 179 } linux_sigset_t; 180 181 typedef struct { 182 linux_handler_t lsa_handler; 183 linux_osigset_t lsa_mask; 184 u_long lsa_flags; 185 void (*lsa_restorer)(void); 186 } linux_osigaction_t; 187 188 typedef struct { 189 linux_handler_t lsa_handler; 190 u_long lsa_flags; 191 void (*lsa_restorer)(void); 192 linux_sigset_t lsa_mask; 193 } linux_sigaction_t; 194 195 typedef struct { 196 void *ss_sp; 197 int ss_flags; 198 linux_size_t ss_size; 199 } linux_stack_t; 200 201 /* The Linux sigcontext, pretty much a standard 386 trapframe. */ 202 struct linux_sigcontext { 203 int sc_gs; 204 int sc_fs; 205 int sc_es; 206 int sc_ds; 207 int sc_edi; 208 int sc_esi; 209 int sc_ebp; 210 int sc_esp; 211 int sc_ebx; 212 int sc_edx; 213 int sc_ecx; 214 int sc_eax; 215 int sc_trapno; 216 int sc_err; 217 int sc_eip; 218 int sc_cs; 219 int sc_eflags; 220 int sc_esp_at_signal; 221 int sc_ss; 222 int sc_387; 223 int sc_mask; 224 int sc_cr2; 225 }; 226 227 struct linux_ucontext { 228 unsigned long uc_flags; 229 void *uc_link; 230 linux_stack_t uc_stack; 231 struct linux_sigcontext uc_mcontext; 232 linux_sigset_t uc_sigmask; 233 }; 234 235 236 #define LINUX_SI_MAX_SIZE 128 237 #define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE/sizeof(int)) - 3) 238 239 typedef struct siginfo { 240 int lsi_signo; 241 int lsi_errno; 242 int lsi_code; 243 244 union { 245 int _pad[LINUX_SI_PAD_SIZE]; 246 struct { 247 linux_pid_t _pid; 248 linux_uid_t _uid; 249 } _kill; 250 251 struct { 252 unsigned int _timer1; 253 unsigned int _timer2; 254 } _timer; 255 256 struct { 257 linux_pid_t _pid; /* sender's pid */ 258 linux_uid_t _uid; /* sender's uid */ 259 union sigval _sigval; 260 } _rt; 261 262 struct { 263 linux_pid_t _pid; /* which child */ 264 linux_uid_t _uid; /* sender's uid */ 265 int _status; /* exit code */ 266 linux_clock_t _utime; 267 linux_clock_t _stime; 268 } _sigchld; 269 270 struct { 271 void *_addr; /* faulting insn/memory ref. */ 272 } _sigfault; 273 274 struct { 275 int _band; /* POLL_IN, POLL_OUT, POLL_MSG */ 276 int _fd; 277 } _sigpoll; 278 } _sifields; 279 } linux_siginfo_t; 280 281 #define lsi_pid _sifields._kill._pid 282 #define lsi_uid _sifields._kill._uid 283 #define lsi_status _sifields._sigchld._status 284 #define lsi_utime _sifields._sigchld._utime 285 #define lsi_stime _sifields._sigchld._stime 286 #define lsi_value _sifields._rt._sigval 287 #define lsi_int _sifields._rt._sigval.sival_int 288 #define lsi_ptr _sifields._rt._sigval.sival_ptr 289 #define lsi_addr _sifields._sigfault._addr 290 #define lsi_band _sifields._sigpoll._band 291 #define lsi_fd _sifields._sigpoll._fd 292 293 struct linux_fpreg { 294 u_int16_t significand[4]; 295 u_int16_t exponent; 296 }; 297 298 struct linux_fpxreg { 299 u_int16_t significand[4]; 300 u_int16_t exponent; 301 u_int16_t padding[3]; 302 }; 303 304 struct linux_xmmreg { 305 u_int32_t element[4]; 306 }; 307 308 struct linux_fpstate { 309 /* Regular FPU environment */ 310 u_int32_t cw; 311 u_int32_t sw; 312 u_int32_t tag; 313 u_int32_t ipoff; 314 u_int32_t cssel; 315 u_int32_t dataoff; 316 u_int32_t datasel; 317 struct linux_fpreg _st[8]; 318 u_int16_t status; 319 u_int16_t magic; /* 0xffff = regular FPU data */ 320 321 /* FXSR FPU environment */ 322 u_int32_t _fxsr_env[6]; /* env is ignored */ 323 u_int32_t mxcsr; 324 u_int32_t reserved; 325 struct linux_fpxreg _fxsr_st[8]; /* reg data is ignored */ 326 struct linux_xmmreg _xmm[8]; 327 u_int32_t padding[56]; 328 }; 329 330 /* 331 * We make the stack look like Linux expects it when calling a signal 332 * handler, but use the BSD way of calling the handler and sigreturn(). 333 * This means that we need to pass the pointer to the handler too. 334 * It is appended to the frame to not interfere with the rest of it. 335 */ 336 struct linux_sigframe { 337 int sf_sig; 338 struct linux_sigcontext sf_sc; 339 struct linux_fpstate sf_fpstate; 340 u_int sf_extramask[LINUX_NSIG_WORDS-1]; 341 linux_handler_t sf_handler; 342 }; 343 344 struct linux_rt_sigframe { 345 int sf_sig; 346 linux_siginfo_t *sf_siginfo; 347 struct linux_ucontext *sf_ucontext; 348 linux_siginfo_t sf_si; 349 struct linux_ucontext sf_sc; 350 linux_handler_t sf_handler; 351 }; 352 353 extern int bsd_to_linux_signal[]; 354 extern int linux_to_bsd_signal[]; 355 extern struct sysentvec linux_sysvec; 356 extern struct sysentvec elf_linux_sysvec; 357 358 /* 359 * Pluggable ioctl handlers 360 */ 361 struct linker_set; 362 struct linux_ioctl_args; 363 struct proc; 364 365 typedef int linux_ioctl_function_t(struct proc *, struct linux_ioctl_args *); 366 367 struct linux_ioctl_handler { 368 linux_ioctl_function_t *func; 369 int low, high; 370 }; 371 372 int linux_ioctl_register_handler(struct linux_ioctl_handler *h); 373 int linux_ioctl_register_handlers(struct linker_set *s); 374 int linux_ioctl_unregister_handler(struct linux_ioctl_handler *h); 375 int linux_ioctl_unregister_handlers(struct linker_set *s); 376 377 /* 378 * open/fcntl flags 379 */ 380 #define LINUX_O_RDONLY 00 381 #define LINUX_O_WRONLY 01 382 #define LINUX_O_RDWR 02 383 #define LINUX_O_CREAT 0100 384 #define LINUX_O_EXCL 0200 385 #define LINUX_O_NOCTTY 0400 386 #define LINUX_O_TRUNC 01000 387 #define LINUX_O_APPEND 02000 388 #define LINUX_O_NONBLOCK 04000 389 #define LINUX_O_NDELAY LINUX_O_NONBLOCK 390 #define LINUX_O_SYNC 010000 391 #define LINUX_FASYNC 020000 392 393 #define LINUX_F_DUPFD 0 394 #define LINUX_F_GETFD 1 395 #define LINUX_F_SETFD 2 396 #define LINUX_F_GETFL 3 397 #define LINUX_F_SETFL 4 398 #define LINUX_F_GETLK 5 399 #define LINUX_F_SETLK 6 400 #define LINUX_F_SETLKW 7 401 #define LINUX_F_SETOWN 8 402 #define LINUX_F_GETOWN 9 403 404 #define LINUX_F_RDLCK 0 405 #define LINUX_F_WRLCK 1 406 #define LINUX_F_UNLCK 2 407 408 /* 409 * SystemV IPC defines 410 */ 411 #define LINUX_SEMOP 1 412 #define LINUX_SEMGET 2 413 #define LINUX_SEMCTL 3 414 #define LINUX_MSGSND 11 415 #define LINUX_MSGRCV 12 416 #define LINUX_MSGGET 13 417 #define LINUX_MSGCTL 14 418 #define LINUX_SHMAT 21 419 #define LINUX_SHMDT 22 420 #define LINUX_SHMGET 23 421 #define LINUX_SHMCTL 24 422 423 #define LINUX_IPC_RMID 0 424 #define LINUX_IPC_SET 1 425 #define LINUX_IPC_STAT 2 426 #define LINUX_IPC_INFO 3 427 428 #define LINUX_SHM_LOCK 11 429 #define LINUX_SHM_UNLOCK 12 430 #define LINUX_SHM_STAT 13 431 #define LINUX_SHM_INFO 14 432 433 #define LINUX_SHM_RDONLY 0x1000 434 #define LINUX_SHM_RND 0x2000 435 #define LINUX_SHM_REMAP 0x4000 436 437 /* semctl commands */ 438 #define LINUX_GETPID 11 439 #define LINUX_GETVAL 12 440 #define LINUX_GETALL 13 441 #define LINUX_GETNCNT 14 442 #define LINUX_GETZCNT 15 443 #define LINUX_SETVAL 16 444 #define LINUX_SETALL 17 445 446 /* 447 * Socket defines 448 */ 449 #define LINUX_SOCKET 1 450 #define LINUX_BIND 2 451 #define LINUX_CONNECT 3 452 #define LINUX_LISTEN 4 453 #define LINUX_ACCEPT 5 454 #define LINUX_GETSOCKNAME 6 455 #define LINUX_GETPEERNAME 7 456 #define LINUX_SOCKETPAIR 8 457 #define LINUX_SEND 9 458 #define LINUX_RECV 10 459 #define LINUX_SENDTO 11 460 #define LINUX_RECVFROM 12 461 #define LINUX_SHUTDOWN 13 462 #define LINUX_SETSOCKOPT 14 463 #define LINUX_GETSOCKOPT 15 464 #define LINUX_SENDMSG 16 465 #define LINUX_RECVMSG 17 466 467 #define LINUX_AF_UNSPEC 0 468 #define LINUX_AF_UNIX 1 469 #define LINUX_AF_INET 2 470 #define LINUX_AF_AX25 3 471 #define LINUX_AF_IPX 4 472 #define LINUX_AF_APPLETALK 5 473 474 #define LINUX_SOL_SOCKET 1 475 #define LINUX_SOL_IP 0 476 #define LINUX_SOL_IPX 256 477 #define LINUX_SOL_AX25 257 478 #define LINUX_SOL_TCP 6 479 #define LINUX_SOL_UDP 17 480 481 #define LINUX_SO_DEBUG 1 482 #define LINUX_SO_REUSEADDR 2 483 #define LINUX_SO_TYPE 3 484 #define LINUX_SO_ERROR 4 485 #define LINUX_SO_DONTROUTE 5 486 #define LINUX_SO_BROADCAST 6 487 #define LINUX_SO_SNDBUF 7 488 #define LINUX_SO_RCVBUF 8 489 #define LINUX_SO_KEEPALIVE 9 490 #define LINUX_SO_OOBINLINE 10 491 #define LINUX_SO_NO_CHECK 11 492 #define LINUX_SO_PRIORITY 12 493 #define LINUX_SO_LINGER 13 494 495 #define LINUX_IP_TOS 1 496 #define LINUX_IP_TTL 2 497 #define LINUX_IP_HDRINCL 3 498 #define LINUX_IP_OPTIONS 4 499 500 #define LINUX_IP_MULTICAST_IF 32 501 #define LINUX_IP_MULTICAST_TTL 33 502 #define LINUX_IP_MULTICAST_LOOP 34 503 #define LINUX_IP_ADD_MEMBERSHIP 35 504 #define LINUX_IP_DROP_MEMBERSHIP 36 505 506 struct linux_sockaddr { 507 u_short sa_family; 508 char sa_data[14]; 509 }; 510 511 struct linux_ifmap { 512 u_long mem_start; 513 u_long mem_end; 514 u_short base_addr; 515 u_char irq; 516 u_char dma; 517 u_char port; 518 }; 519 520 #define LINUX_IFHWADDRLEN 6 521 #define LINUX_IFNAMSIZ 16 522 523 struct linux_ifreq { 524 union { 525 char ifrn_name[LINUX_IFNAMSIZ]; 526 } ifr_ifrn; 527 528 union { 529 struct linux_sockaddr ifru_addr; 530 struct linux_sockaddr ifru_dstaddr; 531 struct linux_sockaddr ifru_broadaddr; 532 struct linux_sockaddr ifru_netmask; 533 struct linux_sockaddr ifru_hwaddr; 534 short ifru_flags; 535 int ifru_metric; 536 int ifru_mtu; 537 struct linux_ifmap ifru_map; 538 char ifru_slave[LINUX_IFNAMSIZ]; /* Just fits the size */ 539 linux_caddr_t ifru_data; 540 } ifr_ifru; 541 }; 542 543 #define ifr_name ifr_ifrn.ifrn_name /* interface name */ 544 #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ 545 546 #endif /* !_I386_LINUX_LINUX_H_ */ 547