linux.h revision 293541
1/*- 2 * Copyright (c) 2013 Dmitry Chagin 3 * Copyright (c) 1994-1996 S��ren Schmidt 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer 11 * in this position and unchanged. 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 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * $FreeBSD: stable/10/sys/amd64/linux/linux.h 293541 2016-01-09 16:31:10Z dchagin $ 30 */ 31 32#ifndef _AMD64_LINUX_H_ 33#define _AMD64_LINUX_H_ 34 35#include <amd64/linux/linux_syscall.h> 36 37/* 38 * debugging support 39 */ 40extern u_char linux_debug_map[]; 41#define ldebug(name) isclr(linux_debug_map, LINUX_SYS_linux_ ## name) 42#define ARGS(nm, fmt) "linux(%ld/%ld): "#nm"("fmt")\n", \ 43 (long)td->td_proc->p_pid, (long)td->td_tid 44#define LMSG(fmt) "linux(%ld/%ld): "fmt"\n", \ 45 (long)td->td_proc->p_pid, (long)td->td_tid 46#define LINUX_DTRACE linuxulator 47 48#define PTRIN(v) (void *)(v) 49#define PTROUT(v) (uintptr_t)(v) 50 51#define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0) 52#define CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0) 53#define PTRIN_CP(src,dst,fld) \ 54 do { (dst).fld = PTRIN((src).fld); } while (0) 55 56/* 57 * Provide a separate set of types for the Linux types. 58 */ 59typedef int32_t l_int; 60typedef int64_t l_long; 61typedef int16_t l_short; 62typedef uint32_t l_uint; 63typedef uint64_t l_ulong; 64typedef uint16_t l_ushort; 65 66typedef l_ulong l_uintptr_t; 67typedef l_long l_clock_t; 68typedef l_int l_daddr_t; 69typedef l_ulong l_dev_t; 70typedef l_uint l_gid_t; 71typedef l_uint l_uid_t; 72typedef l_ulong l_ino_t; 73typedef l_int l_key_t; 74typedef l_long l_loff_t; 75typedef l_uint l_mode_t; 76typedef l_long l_off_t; 77typedef l_int l_pid_t; 78typedef l_ulong l_size_t; 79typedef l_long l_ssize_t; 80typedef l_long l_suseconds_t; 81typedef l_long l_time_t; 82typedef l_int l_timer_t; 83typedef l_int l_mqd_t; 84typedef l_size_t l_socklen_t; 85 86typedef struct { 87 l_int val[2]; 88} l_fsid_t; 89 90typedef struct { 91 l_time_t tv_sec; 92 l_suseconds_t tv_usec; 93} l_timeval; 94 95#define l_fd_set fd_set 96 97/* 98 * Miscellaneous 99 */ 100#define LINUX_NAME_MAX 255 101#define LINUX_CTL_MAXNAME 10 102 103#define LINUX_AT_COUNT 19 /* Count of used aux entry types. */ 104 105struct l___sysctl_args 106{ 107 l_uintptr_t name; 108 l_int nlen; 109 l_uintptr_t oldval; 110 l_uintptr_t oldlenp; 111 l_uintptr_t newval; 112 l_size_t newlen; 113 l_ulong __spare[4]; 114}; 115 116/* Scheduling policies */ 117#define LINUX_SCHED_OTHER 0 118#define LINUX_SCHED_FIFO 1 119#define LINUX_SCHED_RR 2 120 121/* Resource limits */ 122#define LINUX_RLIMIT_CPU 0 123#define LINUX_RLIMIT_FSIZE 1 124#define LINUX_RLIMIT_DATA 2 125#define LINUX_RLIMIT_STACK 3 126#define LINUX_RLIMIT_CORE 4 127#define LINUX_RLIMIT_RSS 5 128#define LINUX_RLIMIT_NPROC 6 129#define LINUX_RLIMIT_NOFILE 7 130#define LINUX_RLIMIT_MEMLOCK 8 131#define LINUX_RLIMIT_AS 9 /* Address space limit */ 132 133#define LINUX_RLIM_NLIMITS 10 134 135struct l_rlimit { 136 l_ulong rlim_cur; 137 l_ulong rlim_max; 138}; 139 140/* mmap options */ 141#define LINUX_MAP_SHARED 0x0001 142#define LINUX_MAP_PRIVATE 0x0002 143#define LINUX_MAP_FIXED 0x0010 144#define LINUX_MAP_ANON 0x0020 145#define LINUX_MAP_GROWSDOWN 0x0100 146 147/* 148 * stat family of syscalls 149 */ 150struct l_timespec { 151 l_time_t tv_sec; 152 l_long tv_nsec; 153}; 154 155struct l_newstat { 156 l_dev_t st_dev; 157 l_ino_t st_ino; 158 l_ulong st_nlink; 159 l_uint st_mode; 160 l_uid_t st_uid; 161 l_gid_t st_gid; 162 l_uint __st_pad1; 163 l_dev_t st_rdev; 164 l_off_t st_size; 165 l_long st_blksize; 166 l_long st_blocks; 167 struct l_timespec st_atim; 168 struct l_timespec st_mtim; 169 struct l_timespec st_ctim; 170 l_long __unused1; 171 l_long __unused2; 172 l_long __unused3; 173}; 174 175/* 176 * Signalling 177 */ 178#define LINUX_SIGHUP 1 179#define LINUX_SIGINT 2 180#define LINUX_SIGQUIT 3 181#define LINUX_SIGILL 4 182#define LINUX_SIGTRAP 5 183#define LINUX_SIGABRT 6 184#define LINUX_SIGIOT LINUX_SIGABRT 185#define LINUX_SIGBUS 7 186#define LINUX_SIGFPE 8 187#define LINUX_SIGKILL 9 188#define LINUX_SIGUSR1 10 189#define LINUX_SIGSEGV 11 190#define LINUX_SIGUSR2 12 191#define LINUX_SIGPIPE 13 192#define LINUX_SIGALRM 14 193#define LINUX_SIGTERM 15 194#define LINUX_SIGSTKFLT 16 195#define LINUX_SIGCHLD 17 196#define LINUX_SIGCONT 18 197#define LINUX_SIGSTOP 19 198#define LINUX_SIGTSTP 20 199#define LINUX_SIGTTIN 21 200#define LINUX_SIGTTOU 22 201#define LINUX_SIGURG 23 202#define LINUX_SIGXCPU 24 203#define LINUX_SIGXFSZ 25 204#define LINUX_SIGVTALRM 26 205#define LINUX_SIGPROF 27 206#define LINUX_SIGWINCH 28 207#define LINUX_SIGIO 29 208#define LINUX_SIGPOLL LINUX_SIGIO 209#define LINUX_SIGPWR 30 210#define LINUX_SIGSYS 31 211#define LINUX_SIGRTMIN 32 212 213#define LINUX_SIGTBLSZ 31 214#define LINUX_NSIG 64 215#define LINUX_NBPW 64 216#define LINUX_NSIG_WORDS (LINUX_NSIG / LINUX_NBPW) 217 218/* sigaction flags */ 219#define LINUX_SA_NOCLDSTOP 0x00000001 220#define LINUX_SA_NOCLDWAIT 0x00000002 221#define LINUX_SA_SIGINFO 0x00000004 222#define LINUX_SA_RESTORER 0x04000000 223#define LINUX_SA_ONSTACK 0x08000000 224#define LINUX_SA_RESTART 0x10000000 225#define LINUX_SA_INTERRUPT 0x20000000 226#define LINUX_SA_NOMASK 0x40000000 227#define LINUX_SA_ONESHOT 0x80000000 228 229/* sigprocmask actions */ 230#define LINUX_SIG_BLOCK 0 231#define LINUX_SIG_UNBLOCK 1 232#define LINUX_SIG_SETMASK 2 233 234/* primitives to manipulate sigset_t */ 235 236#define LINUX_SIGEMPTYSET(set) \ 237 do { \ 238 (set).__bits[0] = 0; \ 239 } while(0) 240 241#define LINUX_SIGISMEMBER(set, sig) \ 242 (1UL & ((set).__bits[0] >> _SIG_IDX(sig))) 243 244#define LINUX_SIGADDSET(set, sig) \ 245 (set).__bits[0] |= 1UL << _SIG_IDX(sig) 246 247/* sigaltstack */ 248#define LINUX_MINSIGSTKSZ 2048 249#define LINUX_SS_ONSTACK 1 250#define LINUX_SS_DISABLE 2 251 252int linux_to_bsd_sigaltstack(int lsa); 253int bsd_to_linux_sigaltstack(int bsa); 254 255typedef void (*l_handler_t)(l_int); 256 257typedef struct { 258 l_ulong __bits[LINUX_NSIG_WORDS]; 259} l_sigset_t; 260 261typedef struct { 262 l_handler_t lsa_handler; 263 l_ulong lsa_flags; 264 l_uintptr_t lsa_restorer; 265 l_sigset_t lsa_mask; 266} l_sigaction_t; 267 268typedef struct { 269 l_uintptr_t ss_sp; 270 l_int ss_flags; 271 l_size_t ss_size; 272} l_stack_t; 273 274struct l_fpstate { 275 u_int16_t cwd; 276 u_int16_t swd; 277 u_int16_t twd; 278 u_int16_t fop; 279 u_int64_t rip; 280 u_int64_t rdp; 281 u_int32_t mxcsr; 282 u_int32_t mxcsr_mask; 283 u_int32_t st_space[32]; 284 u_int32_t xmm_space[64]; 285 u_int32_t reserved2[24]; 286}; 287 288struct l_sigcontext { 289 l_ulong sc_r8; 290 l_ulong sc_r9; 291 l_ulong sc_r10; 292 l_ulong sc_r11; 293 l_ulong sc_r12; 294 l_ulong sc_r13; 295 l_ulong sc_r14; 296 l_ulong sc_r15; 297 l_ulong sc_rdi; 298 l_ulong sc_rsi; 299 l_ulong sc_rbp; 300 l_ulong sc_rbx; 301 l_ulong sc_rdx; 302 l_ulong sc_rax; 303 l_ulong sc_rcx; 304 l_ulong sc_rsp; 305 l_ulong sc_rip; 306 l_ulong sc_rflags; 307 l_ushort sc_cs; 308 l_ushort sc_gs; 309 l_ushort sc_fs; 310 l_ushort sc___pad0; 311 l_ulong sc_err; 312 l_ulong sc_trapno; 313 l_sigset_t sc_mask; 314 l_ulong sc_cr2; 315 struct l_fpstate *sc_fpstate; 316 l_ulong sc_reserved1[8]; 317}; 318 319struct l_ucontext { 320 l_ulong uc_flags; 321 l_uintptr_t uc_link; 322 l_stack_t uc_stack; 323 struct l_sigcontext uc_mcontext; 324 l_sigset_t uc_sigmask; 325}; 326 327#define LINUX_SI_PREAMBLE_SIZE (4 * sizeof(int)) 328#define LINUX_SI_MAX_SIZE 128 329#define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE - \ 330 LINUX_SI_PREAMBLE_SIZE) / sizeof(l_int)) 331typedef union l_sigval { 332 l_int sival_int; 333 l_uintptr_t sival_ptr; 334} l_sigval_t; 335 336typedef struct l_siginfo { 337 l_int lsi_signo; 338 l_int lsi_errno; 339 l_int lsi_code; 340 union { 341 l_int _pad[LINUX_SI_PAD_SIZE]; 342 343 struct { 344 l_pid_t _pid; 345 l_uid_t _uid; 346 } _kill; 347 348 struct { 349 l_timer_t _tid; 350 l_int _overrun; 351 char _pad[sizeof(l_uid_t) - sizeof(int)]; 352 union l_sigval _sigval; 353 l_uint _sys_private; 354 } _timer; 355 356 struct { 357 l_pid_t _pid; /* sender's pid */ 358 l_uid_t _uid; /* sender's uid */ 359 union l_sigval _sigval; 360 } _rt; 361 362 struct { 363 l_pid_t _pid; /* which child */ 364 l_uid_t _uid; /* sender's uid */ 365 l_int _status; /* exit code */ 366 l_clock_t _utime; 367 l_clock_t _stime; 368 } _sigchld; 369 370 struct { 371 l_uintptr_t _addr; /* Faulting insn/memory ref. */ 372 } _sigfault; 373 374 struct { 375 l_long _band; /* POLL_IN,POLL_OUT,POLL_MSG */ 376 l_int _fd; 377 } _sigpoll; 378 } _sifields; 379} l_siginfo_t; 380 381#define lsi_pid _sifields._kill._pid 382#define lsi_uid _sifields._kill._uid 383#define lsi_tid _sifields._timer._tid 384#define lsi_overrun _sifields._timer._overrun 385#define lsi_sys_private _sifields._timer._sys_private 386#define lsi_status _sifields._sigchld._status 387#define lsi_utime _sifields._sigchld._utime 388#define lsi_stime _sifields._sigchld._stime 389#define lsi_value _sifields._rt._sigval 390#define lsi_int _sifields._rt._sigval.sival_int 391#define lsi_ptr _sifields._rt._sigval.sival_ptr 392#define lsi_addr _sifields._sigfault._addr 393#define lsi_band _sifields._sigpoll._band 394#define lsi_fd _sifields._sigpoll._fd 395 396/* 397 * We make the stack look like Linux expects it when calling a signal 398 * handler, but use the BSD way of calling the handler and sigreturn(). 399 * This means that we need to pass the pointer to the handler too. 400 * It is appended to the frame to not interfere with the rest of it. 401 */ 402 403struct l_rt_sigframe { 404 struct l_ucontext sf_sc; 405 struct l_siginfo sf_si; 406 l_handler_t sf_handler; 407}; 408 409/* 410 * mount flags 411 */ 412#define LINUX_MS_RDONLY 0x0001 413#define LINUX_MS_NOSUID 0x0002 414#define LINUX_MS_NODEV 0x0004 415#define LINUX_MS_NOEXEC 0x0008 416#define LINUX_MS_REMOUNT 0x0020 417 418/* 419 * SystemV IPC defines 420 */ 421#define LINUX_IPC_RMID 0 422#define LINUX_IPC_SET 1 423#define LINUX_IPC_STAT 2 424#define LINUX_IPC_INFO 3 425 426#define LINUX_SHM_LOCK 11 427#define LINUX_SHM_UNLOCK 12 428#define LINUX_SHM_STAT 13 429#define LINUX_SHM_INFO 14 430 431#define LINUX_SHM_RDONLY 0x1000 432#define LINUX_SHM_RND 0x2000 433#define LINUX_SHM_REMAP 0x4000 434 435/* semctl commands */ 436#define LINUX_GETPID 11 437#define LINUX_GETVAL 12 438#define LINUX_GETALL 13 439#define LINUX_GETNCNT 14 440#define LINUX_GETZCNT 15 441#define LINUX_SETVAL 16 442#define LINUX_SETALL 17 443#define LINUX_SEM_STAT 18 444#define LINUX_SEM_INFO 19 445 446union l_semun { 447 l_int val; 448 l_uintptr_t buf; 449 l_uintptr_t array; 450 l_uintptr_t __buf; 451 l_uintptr_t __pad; 452}; 453 454struct l_ipc_perm { 455 l_key_t key; 456 l_uid_t uid; 457 l_gid_t gid; 458 l_uid_t cuid; 459 l_gid_t cgid; 460 l_ushort mode; 461 l_ushort seq; 462}; 463 464/* 465 * Socket defines 466 */ 467 468#define LINUX_SOL_SOCKET 1 469#define LINUX_SOL_IP 0 470#define LINUX_SOL_IPX 256 471#define LINUX_SOL_AX25 257 472#define LINUX_SOL_TCP 6 473#define LINUX_SOL_UDP 17 474 475#define LINUX_SO_DEBUG 1 476#define LINUX_SO_REUSEADDR 2 477#define LINUX_SO_TYPE 3 478#define LINUX_SO_ERROR 4 479#define LINUX_SO_DONTROUTE 5 480#define LINUX_SO_BROADCAST 6 481#define LINUX_SO_SNDBUF 7 482#define LINUX_SO_RCVBUF 8 483#define LINUX_SO_KEEPALIVE 9 484#define LINUX_SO_OOBINLINE 10 485#define LINUX_SO_NO_CHECK 11 486#define LINUX_SO_PRIORITY 12 487#define LINUX_SO_LINGER 13 488#define LINUX_SO_PASSCRED 16 489#define LINUX_SO_PEERCRED 17 490#define LINUX_SO_RCVLOWAT 18 491#define LINUX_SO_SNDLOWAT 19 492#define LINUX_SO_RCVTIMEO 20 493#define LINUX_SO_SNDTIMEO 21 494#define LINUX_SO_TIMESTAMP 29 495#define LINUX_SO_ACCEPTCONN 30 496 497#define LINUX_IP_TOS 1 498#define LINUX_IP_TTL 2 499#define LINUX_IP_HDRINCL 3 500#define LINUX_IP_OPTIONS 4 501 502#define LINUX_IP_MULTICAST_IF 32 503#define LINUX_IP_MULTICAST_TTL 33 504#define LINUX_IP_MULTICAST_LOOP 34 505#define LINUX_IP_ADD_MEMBERSHIP 35 506#define LINUX_IP_DROP_MEMBERSHIP 36 507 508struct l_sockaddr { 509 l_ushort sa_family; 510 char sa_data[14]; 511}; 512 513struct l_msghdr { 514 l_uintptr_t msg_name; 515 l_int msg_namelen; 516 l_uintptr_t msg_iov; 517 l_size_t msg_iovlen; 518 l_uintptr_t msg_control; 519 l_size_t msg_controllen; 520 l_uint msg_flags; 521}; 522 523struct l_cmsghdr { 524 l_size_t cmsg_len; 525 l_int cmsg_level; 526 l_int cmsg_type; 527}; 528 529struct l_ifmap { 530 l_ulong mem_start; 531 l_ulong mem_end; 532 l_ushort base_addr; 533 u_char irq; 534 u_char dma; 535 u_char port; 536} __packed; 537 538#define LINUX_IFHWADDRLEN 6 539#define LINUX_IFNAMSIZ 16 540 541struct l_ifreq { 542 union { 543 char ifrn_name[LINUX_IFNAMSIZ]; 544 } ifr_ifrn; 545 546 union { 547 struct l_sockaddr ifru_addr; 548 struct l_sockaddr ifru_dstaddr; 549 struct l_sockaddr ifru_broadaddr; 550 struct l_sockaddr ifru_netmask; 551 struct l_sockaddr ifru_hwaddr; 552 l_short ifru_flags[1]; 553 l_int ifru_metric; 554 l_int ifru_mtu; 555 struct l_ifmap ifru_map; 556 char ifru_slave[LINUX_IFNAMSIZ]; 557 l_uintptr_t ifru_data; 558 } ifr_ifru; 559} __packed; 560 561#define ifr_name ifr_ifrn.ifrn_name /* Interface name */ 562#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ 563 564struct l_ifconf { 565 int ifc_len; 566 union { 567 l_uintptr_t ifcu_buf; 568 l_uintptr_t ifcu_req; 569 } ifc_ifcu; 570}; 571 572#define ifc_buf ifc_ifcu.ifcu_buf 573#define ifc_req ifc_ifcu.ifcu_req 574 575/* 576 * poll() 577 */ 578#define LINUX_POLLIN 0x0001 579#define LINUX_POLLPRI 0x0002 580#define LINUX_POLLOUT 0x0004 581#define LINUX_POLLERR 0x0008 582#define LINUX_POLLHUP 0x0010 583#define LINUX_POLLNVAL 0x0020 584#define LINUX_POLLRDNORM 0x0040 585#define LINUX_POLLRDBAND 0x0080 586#define LINUX_POLLWRNORM 0x0100 587#define LINUX_POLLWRBAND 0x0200 588#define LINUX_POLLMSG 0x0400 589 590struct l_pollfd { 591 l_int fd; 592 l_short events; 593 l_short revents; 594}; 595 596 597#define LINUX_CLONE_VM 0x00000100 598#define LINUX_CLONE_FS 0x00000200 599#define LINUX_CLONE_FILES 0x00000400 600#define LINUX_CLONE_SIGHAND 0x00000800 601#define LINUX_CLONE_PID 0x00001000 /* No longer exist in Linux */ 602#define LINUX_CLONE_VFORK 0x00004000 603#define LINUX_CLONE_PARENT 0x00008000 604#define LINUX_CLONE_THREAD 0x00010000 605#define LINUX_CLONE_SETTLS 0x00080000 606#define LINUX_CLONE_PARENT_SETTID 0x00100000 607#define LINUX_CLONE_CHILD_CLEARTID 0x00200000 608#define LINUX_CLONE_CHILD_SETTID 0x01000000 609 610#define LINUX_ARCH_SET_GS 0x1001 611#define LINUX_ARCH_SET_FS 0x1002 612#define LINUX_ARCH_GET_GS 0x1003 613#define LINUX_ARCH_GET_FS 0x1004 614 615#define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r)) 616 617/* robust futexes */ 618struct linux_robust_list { 619 l_uintptr_t next; 620}; 621 622struct linux_robust_list_head { 623 struct linux_robust_list list; 624 l_long futex_offset; 625 l_uintptr_t pending_list; 626}; 627 628#endif /* !_AMD64_LINUX_H_ */ 629