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