1ea0fabbcSTim J. Robbins /*- 2c49761ddSPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3c49761ddSPedro F. Giffuni * 4ea0fabbcSTim J. Robbins * Copyright (c) 2004 Tim J. Robbins 5ea0fabbcSTim J. Robbins * Copyright (c) 2001 Doug Rabson 69a14aa01SUlrich Spörlein * Copyright (c) 1994-1996 Søren Schmidt 7ea0fabbcSTim J. Robbins * All rights reserved. 8ea0fabbcSTim J. Robbins * 9ea0fabbcSTim J. Robbins * Redistribution and use in source and binary forms, with or without 10ea0fabbcSTim J. Robbins * modification, are permitted provided that the following conditions 11ea0fabbcSTim J. Robbins * are met: 12ea0fabbcSTim J. Robbins * 1. Redistributions of source code must retain the above copyright 13ea0fabbcSTim J. Robbins * notice, this list of conditions and the following disclaimer 14ea0fabbcSTim J. Robbins * in this position and unchanged. 15ea0fabbcSTim J. Robbins * 2. Redistributions in binary form must reproduce the above copyright 16ea0fabbcSTim J. Robbins * notice, this list of conditions and the following disclaimer in the 17ea0fabbcSTim J. Robbins * documentation and/or other materials provided with the distribution. 18ea0fabbcSTim J. Robbins * 3. The name of the author may not be used to endorse or promote products 19ea0fabbcSTim J. Robbins * derived from this software without specific prior written permission 20ea0fabbcSTim J. Robbins * 21ea0fabbcSTim J. Robbins * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22ea0fabbcSTim J. Robbins * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23ea0fabbcSTim J. Robbins * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24ea0fabbcSTim J. Robbins * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25ea0fabbcSTim J. Robbins * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26ea0fabbcSTim J. Robbins * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27ea0fabbcSTim J. Robbins * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28ea0fabbcSTim J. Robbins * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29ea0fabbcSTim J. Robbins * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30ea0fabbcSTim J. Robbins * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31ea0fabbcSTim J. Robbins * 32ea0fabbcSTim J. Robbins * $FreeBSD$ 33ea0fabbcSTim J. Robbins */ 34ea0fabbcSTim J. Robbins 35a4e3bad7SJung-uk Kim #ifndef _AMD64_LINUX_H_ 36a4e3bad7SJung-uk Kim #define _AMD64_LINUX_H_ 37ea0fabbcSTim J. Robbins 38562894f0SBrooks Davis #include <sys/abi_compat.h> 39562894f0SBrooks Davis 404ab7403bSDmitry Chagin #include <compat/linux/linux.h> 41ea0fabbcSTim J. Robbins #include <amd64/linux32/linux32_syscall.h> 42ea0fabbcSTim J. Robbins 43931e2a1aSEd Maste #define LINUX_LEGACY_SYSCALLS 44931e2a1aSEd Maste 4519e252baSAlexander Leidinger #define LINUX_DTRACE linuxulator32 46ea0fabbcSTim J. Robbins 478f1e49a6SDmitry Chagin #define LINUX32_MAXUSER ((1ul << 32) - PAGE_SIZE) 488f1e49a6SDmitry Chagin #define LINUX32_SHAREDPAGE (LINUX32_MAXUSER - PAGE_SIZE) 498f1e49a6SDmitry Chagin #define LINUX32_USRSTACK LINUX32_SHAREDPAGE 508f1e49a6SDmitry Chagin 51ea0fabbcSTim J. Robbins /* XXX 16 = sizeof(linux32_ps_strings) */ 52ea0fabbcSTim J. Robbins #define LINUX32_PS_STRINGS (LINUX32_USRSTACK - 16) 53ea0fabbcSTim J. Robbins #define LINUX32_MAXDSIZ (512 * 1024 * 1024) /* 512MB */ 54ea0fabbcSTim J. Robbins #define LINUX32_MAXSSIZ (64 * 1024 * 1024) /* 64MB */ 55ea0fabbcSTim J. Robbins #define LINUX32_MAXVMEM 0 /* Unlimited */ 56ea0fabbcSTim J. Robbins 57ea0fabbcSTim J. Robbins /* 58ea0fabbcSTim J. Robbins * Provide a separate set of types for the Linux types. 59ea0fabbcSTim J. Robbins */ 60ea0fabbcSTim J. Robbins typedef int l_int; 61ea0fabbcSTim J. Robbins typedef int32_t l_long; 62ea0fabbcSTim J. Robbins typedef int64_t l_longlong; 63ea0fabbcSTim J. Robbins typedef short l_short; 64ea0fabbcSTim J. Robbins typedef unsigned int l_uint; 65ea0fabbcSTim J. Robbins typedef uint32_t l_ulong; 66ea0fabbcSTim J. Robbins typedef uint64_t l_ulonglong; 67ea0fabbcSTim J. Robbins typedef unsigned short l_ushort; 68ea0fabbcSTim J. Robbins 69ea0fabbcSTim J. Robbins typedef l_ulong l_uintptr_t; 70ea0fabbcSTim J. Robbins typedef l_long l_clock_t; 71ea0fabbcSTim J. Robbins typedef l_int l_daddr_t; 72ea0fabbcSTim J. Robbins typedef l_ushort l_dev_t; 73ea0fabbcSTim J. Robbins typedef l_uint l_gid_t; 74ea0fabbcSTim J. Robbins typedef l_ushort l_gid16_t; 75ea0fabbcSTim J. Robbins typedef l_ulong l_ino_t; 76ea0fabbcSTim J. Robbins typedef l_int l_key_t; 77ea0fabbcSTim J. Robbins typedef l_longlong l_loff_t; 78ea0fabbcSTim J. Robbins typedef l_ushort l_mode_t; 790af71035SDoug Ambrisko typedef l_long l_off_t; 80ea0fabbcSTim J. Robbins typedef l_int l_pid_t; 81ea0fabbcSTim J. Robbins typedef l_uint l_size_t; 82ea0fabbcSTim J. Robbins typedef l_long l_suseconds_t; 83ea0fabbcSTim J. Robbins typedef l_long l_time_t; 84ea0fabbcSTim J. Robbins typedef l_uint l_uid_t; 85ea0fabbcSTim J. Robbins typedef l_ushort l_uid16_t; 86aa8b2011SKonstantin Belousov typedef l_int l_timer_t; 87aa8b2011SKonstantin Belousov typedef l_int l_mqd_t; 883e89b641SDmitry Chagin typedef l_ulong l_fd_mask; 89ea0fabbcSTim J. Robbins 90ea0fabbcSTim J. Robbins typedef struct { 91ea0fabbcSTim J. Robbins l_int val[2]; 92ea0fabbcSTim J. Robbins } __packed l_fsid_t; 93ea0fabbcSTim J. Robbins 94ea0fabbcSTim J. Robbins typedef struct { 95ea0fabbcSTim J. Robbins l_time_t tv_sec; 96ea0fabbcSTim J. Robbins l_suseconds_t tv_usec; 9703cc95d2SDmitry Chagin } l_timeval; 98ea0fabbcSTim J. Robbins 99ea0fabbcSTim J. Robbins #define l_fd_set fd_set 100ea0fabbcSTim J. Robbins 101ea0fabbcSTim J. Robbins /* 102ea0fabbcSTim J. Robbins * Miscellaneous 103ea0fabbcSTim J. Robbins */ 104ca6e1fa3SEdward Tomasz Napierala #define LINUX_AT_COUNT 21 /* Count of used aux entry types. 1054d7c2e8aSDmitry Chagin * Keep this synchronized with 106dc858467SEd Maste * linux_fixup_elf() code. 1074d7c2e8aSDmitry Chagin */ 108ea0fabbcSTim J. Robbins struct l___sysctl_args 109ea0fabbcSTim J. Robbins { 110ea0fabbcSTim J. Robbins l_uintptr_t name; 111ea0fabbcSTim J. Robbins l_int nlen; 112ea0fabbcSTim J. Robbins l_uintptr_t oldval; 113ea0fabbcSTim J. Robbins l_uintptr_t oldlenp; 114ea0fabbcSTim J. Robbins l_uintptr_t newval; 115ea0fabbcSTim J. Robbins l_size_t newlen; 116ea0fabbcSTim J. Robbins l_ulong __spare[4]; 117ea0fabbcSTim J. Robbins } __packed; 118ea0fabbcSTim J. Robbins 119ea0fabbcSTim J. Robbins /* Resource limits */ 120ea0fabbcSTim J. Robbins #define LINUX_RLIMIT_CPU 0 121ea0fabbcSTim J. Robbins #define LINUX_RLIMIT_FSIZE 1 122ea0fabbcSTim J. Robbins #define LINUX_RLIMIT_DATA 2 123ea0fabbcSTim J. Robbins #define LINUX_RLIMIT_STACK 3 124ea0fabbcSTim J. Robbins #define LINUX_RLIMIT_CORE 4 125ea0fabbcSTim J. Robbins #define LINUX_RLIMIT_RSS 5 126ea0fabbcSTim J. Robbins #define LINUX_RLIMIT_NPROC 6 127ea0fabbcSTim J. Robbins #define LINUX_RLIMIT_NOFILE 7 128ea0fabbcSTim J. Robbins #define LINUX_RLIMIT_MEMLOCK 8 129a4e3bad7SJung-uk Kim #define LINUX_RLIMIT_AS 9 /* Address space limit */ 130ea0fabbcSTim J. Robbins 131ea0fabbcSTim J. Robbins #define LINUX_RLIM_NLIMITS 10 132ea0fabbcSTim J. Robbins 133ea0fabbcSTim J. Robbins struct l_rlimit { 134ea0fabbcSTim J. Robbins l_ulong rlim_cur; 135ea0fabbcSTim J. Robbins l_ulong rlim_max; 136ea0fabbcSTim J. Robbins } __packed; 137ea0fabbcSTim J. Robbins 138ea0fabbcSTim J. Robbins struct l_rusage { 139ea0fabbcSTim J. Robbins l_timeval ru_utime; 140ea0fabbcSTim J. Robbins l_timeval ru_stime; 141ea0fabbcSTim J. Robbins l_long ru_maxrss; 142ea0fabbcSTim J. Robbins l_long ru_ixrss; 143ea0fabbcSTim J. Robbins l_long ru_idrss; 144ea0fabbcSTim J. Robbins l_long ru_isrss; 145ea0fabbcSTim J. Robbins l_long ru_minflt; 146ea0fabbcSTim J. Robbins l_long ru_majflt; 147ea0fabbcSTim J. Robbins l_long ru_nswap; 148ea0fabbcSTim J. Robbins l_long ru_inblock; 149ea0fabbcSTim J. Robbins l_long ru_oublock; 150ea0fabbcSTim J. Robbins l_long ru_msgsnd; 151ea0fabbcSTim J. Robbins l_long ru_msgrcv; 152ea0fabbcSTim J. Robbins l_long ru_nsignals; 153ea0fabbcSTim J. Robbins l_long ru_nvcsw; 154ea0fabbcSTim J. Robbins l_long ru_nivcsw; 155ea0fabbcSTim J. Robbins } __packed; 156ea0fabbcSTim J. Robbins 15710931a46SJung-uk Kim struct l_mmap_argv { 15810931a46SJung-uk Kim l_uintptr_t addr; 15910931a46SJung-uk Kim l_size_t len; 16010931a46SJung-uk Kim l_int prot; 16110931a46SJung-uk Kim l_int flags; 16210931a46SJung-uk Kim l_int fd; 1630af71035SDoug Ambrisko l_ulong pgoff; 1640af71035SDoug Ambrisko }; 16510931a46SJung-uk Kim 166ea0fabbcSTim J. Robbins /* 167ea0fabbcSTim J. Robbins * stat family of syscalls 168ea0fabbcSTim J. Robbins */ 169ea0fabbcSTim J. Robbins struct l_timespec { 17077424f41SJung-uk Kim l_time_t tv_sec; 17177424f41SJung-uk Kim l_long tv_nsec; 172ea0fabbcSTim J. Robbins } __packed; 173ea0fabbcSTim J. Robbins 174ea0fabbcSTim J. Robbins struct l_newstat { 175ea0fabbcSTim J. Robbins l_ushort st_dev; 176ea0fabbcSTim J. Robbins l_ushort __pad1; 177ea0fabbcSTim J. Robbins l_ulong st_ino; 178ea0fabbcSTim J. Robbins l_ushort st_mode; 179ea0fabbcSTim J. Robbins l_ushort st_nlink; 180ea0fabbcSTim J. Robbins l_ushort st_uid; 181ea0fabbcSTim J. Robbins l_ushort st_gid; 182ea0fabbcSTim J. Robbins l_ushort st_rdev; 183ea0fabbcSTim J. Robbins l_ushort __pad2; 184ea0fabbcSTim J. Robbins l_ulong st_size; 185ea0fabbcSTim J. Robbins l_ulong st_blksize; 186ea0fabbcSTim J. Robbins l_ulong st_blocks; 187510ea843SEd Schouten struct l_timespec st_atim; 188510ea843SEd Schouten struct l_timespec st_mtim; 189510ea843SEd Schouten struct l_timespec st_ctim; 190ea0fabbcSTim J. Robbins l_ulong __unused4; 191ea0fabbcSTim J. Robbins l_ulong __unused5; 192ea0fabbcSTim J. Robbins } __packed; 193ea0fabbcSTim J. Robbins 1941f7642e0SAlexander Leidinger struct l_stat { 1951f7642e0SAlexander Leidinger l_ushort st_dev; 1961f7642e0SAlexander Leidinger l_ulong st_ino; 1971f7642e0SAlexander Leidinger l_ushort st_mode; 1981f7642e0SAlexander Leidinger l_ushort st_nlink; 1991f7642e0SAlexander Leidinger l_ushort st_uid; 2001f7642e0SAlexander Leidinger l_ushort st_gid; 2011f7642e0SAlexander Leidinger l_ushort st_rdev; 2021f7642e0SAlexander Leidinger l_long st_size; 203510ea843SEd Schouten struct l_timespec st_atim; 204510ea843SEd Schouten struct l_timespec st_mtim; 205510ea843SEd Schouten struct l_timespec st_ctim; 2061f7642e0SAlexander Leidinger l_long st_blksize; 2071f7642e0SAlexander Leidinger l_long st_blocks; 2081f7642e0SAlexander Leidinger l_ulong st_flags; 2091f7642e0SAlexander Leidinger l_ulong st_gen; 2101f7642e0SAlexander Leidinger }; 2111f7642e0SAlexander Leidinger 212ea0fabbcSTim J. Robbins struct l_stat64 { 213ea0fabbcSTim J. Robbins l_ushort st_dev; 214ea0fabbcSTim J. Robbins u_char __pad0[10]; 215ea0fabbcSTim J. Robbins l_ulong __st_ino; 216ea0fabbcSTim J. Robbins l_uint st_mode; 217ea0fabbcSTim J. Robbins l_uint st_nlink; 218ea0fabbcSTim J. Robbins l_ulong st_uid; 219ea0fabbcSTim J. Robbins l_ulong st_gid; 220ea0fabbcSTim J. Robbins l_ushort st_rdev; 221ea0fabbcSTim J. Robbins u_char __pad3[10]; 222ea0fabbcSTim J. Robbins l_longlong st_size; 223ea0fabbcSTim J. Robbins l_ulong st_blksize; 224ea0fabbcSTim J. Robbins l_ulong st_blocks; 225ea0fabbcSTim J. Robbins l_ulong __pad4; 226510ea843SEd Schouten struct l_timespec st_atim; 227510ea843SEd Schouten struct l_timespec st_mtim; 228510ea843SEd Schouten struct l_timespec st_ctim; 229ea0fabbcSTim J. Robbins l_ulonglong st_ino; 230ea0fabbcSTim J. Robbins } __packed; 231ea0fabbcSTim J. Robbins 2323ab85269SDavid Malone struct l_statfs64 { 2333ab85269SDavid Malone l_int f_type; 2343ab85269SDavid Malone l_int f_bsize; 2353ab85269SDavid Malone uint64_t f_blocks; 2363ab85269SDavid Malone uint64_t f_bfree; 2373ab85269SDavid Malone uint64_t f_bavail; 2383ab85269SDavid Malone uint64_t f_files; 2393ab85269SDavid Malone uint64_t f_ffree; 2403ab85269SDavid Malone l_fsid_t f_fsid; 2413ab85269SDavid Malone l_int f_namelen; 242e801ac78SEdward Tomasz Napierala l_int f_frsize; 243e801ac78SEdward Tomasz Napierala l_int f_flags; 244e801ac78SEdward Tomasz Napierala l_int f_spare[4]; 2453ab85269SDavid Malone } __packed; 2463ab85269SDavid Malone 247ea0fabbcSTim J. Robbins /* sigaction flags */ 248ea0fabbcSTim J. Robbins #define LINUX_SA_NOCLDSTOP 0x00000001 249ea0fabbcSTim J. Robbins #define LINUX_SA_NOCLDWAIT 0x00000002 250ea0fabbcSTim J. Robbins #define LINUX_SA_SIGINFO 0x00000004 251ea0fabbcSTim J. Robbins #define LINUX_SA_RESTORER 0x04000000 252ea0fabbcSTim J. Robbins #define LINUX_SA_ONSTACK 0x08000000 253ea0fabbcSTim J. Robbins #define LINUX_SA_RESTART 0x10000000 254ea0fabbcSTim J. Robbins #define LINUX_SA_INTERRUPT 0x20000000 255ea0fabbcSTim J. Robbins #define LINUX_SA_NOMASK 0x40000000 256ea0fabbcSTim J. Robbins #define LINUX_SA_ONESHOT 0x80000000 257ea0fabbcSTim J. Robbins 258ea0fabbcSTim J. Robbins /* sigprocmask actions */ 259ea0fabbcSTim J. Robbins #define LINUX_SIG_BLOCK 0 260ea0fabbcSTim J. Robbins #define LINUX_SIG_UNBLOCK 1 261ea0fabbcSTim J. Robbins #define LINUX_SIG_SETMASK 2 262ea0fabbcSTim J. Robbins 263ea0fabbcSTim J. Robbins /* sigaltstack */ 264ea0fabbcSTim J. Robbins #define LINUX_MINSIGSTKSZ 2048 265ea0fabbcSTim J. Robbins 266ea0fabbcSTim J. Robbins typedef l_uintptr_t l_handler_t; 267ea0fabbcSTim J. Robbins typedef l_ulong l_osigset_t; 268ea0fabbcSTim J. Robbins 269ea0fabbcSTim J. Robbins typedef struct { 270ea0fabbcSTim J. Robbins l_handler_t lsa_handler; 271ea0fabbcSTim J. Robbins l_osigset_t lsa_mask; 272ea0fabbcSTim J. Robbins l_ulong lsa_flags; 273ea0fabbcSTim J. Robbins l_uintptr_t lsa_restorer; 274ea0fabbcSTim J. Robbins } __packed l_osigaction_t; 275ea0fabbcSTim J. Robbins 276ea0fabbcSTim J. Robbins typedef struct { 277ea0fabbcSTim J. Robbins l_handler_t lsa_handler; 278ea0fabbcSTim J. Robbins l_ulong lsa_flags; 279ea0fabbcSTim J. Robbins l_uintptr_t lsa_restorer; 280ea0fabbcSTim J. Robbins l_sigset_t lsa_mask; 281ea0fabbcSTim J. Robbins } __packed l_sigaction_t; 282ea0fabbcSTim J. Robbins 283ea0fabbcSTim J. Robbins typedef struct { 284ea0fabbcSTim J. Robbins l_uintptr_t ss_sp; 285ea0fabbcSTim J. Robbins l_int ss_flags; 286ea0fabbcSTim J. Robbins l_size_t ss_size; 287ea0fabbcSTim J. Robbins } __packed l_stack_t; 288ea0fabbcSTim J. Robbins 289ea0fabbcSTim J. Robbins /* The Linux sigcontext, pretty much a standard 386 trapframe. */ 290ea0fabbcSTim J. Robbins struct l_sigcontext { 29177185f47SKonstantin Belousov l_uint sc_gs; 29277185f47SKonstantin Belousov l_uint sc_fs; 29377185f47SKonstantin Belousov l_uint sc_es; 29477185f47SKonstantin Belousov l_uint sc_ds; 29577185f47SKonstantin Belousov l_uint sc_edi; 29677185f47SKonstantin Belousov l_uint sc_esi; 29777185f47SKonstantin Belousov l_uint sc_ebp; 29877185f47SKonstantin Belousov l_uint sc_esp; 29977185f47SKonstantin Belousov l_uint sc_ebx; 30077185f47SKonstantin Belousov l_uint sc_edx; 30177185f47SKonstantin Belousov l_uint sc_ecx; 30277185f47SKonstantin Belousov l_uint sc_eax; 30377185f47SKonstantin Belousov l_uint sc_trapno; 30477185f47SKonstantin Belousov l_uint sc_err; 30577185f47SKonstantin Belousov l_uint sc_eip; 30677185f47SKonstantin Belousov l_uint sc_cs; 30777185f47SKonstantin Belousov l_uint sc_eflags; 30877185f47SKonstantin Belousov l_uint sc_esp_at_signal; 30977185f47SKonstantin Belousov l_uint sc_ss; 31077185f47SKonstantin Belousov l_uint sc_387; 31177185f47SKonstantin Belousov l_uint sc_mask; 31277185f47SKonstantin Belousov l_uint sc_cr2; 313ea0fabbcSTim J. Robbins } __packed; 314ea0fabbcSTim J. Robbins 315ea0fabbcSTim J. Robbins struct l_ucontext { 316ea0fabbcSTim J. Robbins l_ulong uc_flags; 317ea0fabbcSTim J. Robbins l_uintptr_t uc_link; 318ea0fabbcSTim J. Robbins l_stack_t uc_stack; 319ea0fabbcSTim J. Robbins struct l_sigcontext uc_mcontext; 320ea0fabbcSTim J. Robbins l_sigset_t uc_sigmask; 321ea0fabbcSTim J. Robbins } __packed; 322ea0fabbcSTim J. Robbins 323ea0fabbcSTim J. Robbins #define LINUX_SI_MAX_SIZE 128 324ea0fabbcSTim J. Robbins #define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE/sizeof(l_int)) - 3) 325ea0fabbcSTim J. Robbins 326aa8b2011SKonstantin Belousov typedef union l_sigval { 3276ddd7e6aSJohn Baldwin l_int sival_int; 3286ddd7e6aSJohn Baldwin l_uintptr_t sival_ptr; 329aa8b2011SKonstantin Belousov } l_sigval_t; 3306ddd7e6aSJohn Baldwin 331ea0fabbcSTim J. Robbins typedef struct l_siginfo { 332ea0fabbcSTim J. Robbins l_int lsi_signo; 333ea0fabbcSTim J. Robbins l_int lsi_errno; 334ea0fabbcSTim J. Robbins l_int lsi_code; 335ea0fabbcSTim J. Robbins union { 336ea0fabbcSTim J. Robbins l_int _pad[LINUX_SI_PAD_SIZE]; 337ea0fabbcSTim J. Robbins 338ea0fabbcSTim J. Robbins struct { 339ea0fabbcSTim J. Robbins l_pid_t _pid; 340aa8b2011SKonstantin Belousov l_uid_t _uid; 341ea0fabbcSTim J. Robbins } __packed _kill; 342ea0fabbcSTim J. Robbins 343ea0fabbcSTim J. Robbins struct { 344aa8b2011SKonstantin Belousov l_timer_t _tid; 345aa8b2011SKonstantin Belousov l_int _overrun; 346aa8b2011SKonstantin Belousov char _pad[sizeof(l_uid_t) - sizeof(l_int)]; 347aa8b2011SKonstantin Belousov l_sigval_t _sigval; 348aa8b2011SKonstantin Belousov l_int _sys_private; 349ea0fabbcSTim J. Robbins } __packed _timer; 350ea0fabbcSTim J. Robbins 351ea0fabbcSTim J. Robbins struct { 352ea0fabbcSTim J. Robbins l_pid_t _pid; /* sender's pid */ 353aa8b2011SKonstantin Belousov l_uid_t _uid; /* sender's uid */ 354aa8b2011SKonstantin Belousov l_sigval_t _sigval; 355ea0fabbcSTim J. Robbins } __packed _rt; 356ea0fabbcSTim J. Robbins 357ea0fabbcSTim J. Robbins struct { 358ea0fabbcSTim J. Robbins l_pid_t _pid; /* which child */ 359aa8b2011SKonstantin Belousov l_uid_t _uid; /* sender's uid */ 360ea0fabbcSTim J. Robbins l_int _status; /* exit code */ 361ea0fabbcSTim J. Robbins l_clock_t _utime; 362ea0fabbcSTim J. Robbins l_clock_t _stime; 363ea0fabbcSTim J. Robbins } __packed _sigchld; 364ea0fabbcSTim J. Robbins 365ea0fabbcSTim J. Robbins struct { 366a4e3bad7SJung-uk Kim l_uintptr_t _addr; /* Faulting insn/memory ref. */ 367ea0fabbcSTim J. Robbins } __packed _sigfault; 368ea0fabbcSTim J. Robbins 369ea0fabbcSTim J. Robbins struct { 370aa8b2011SKonstantin Belousov l_long _band; /* POLL_IN,POLL_OUT,POLL_MSG */ 371ea0fabbcSTim J. Robbins l_int _fd; 372ea0fabbcSTim J. Robbins } __packed _sigpoll; 373ea0fabbcSTim J. Robbins } _sifields; 374ea0fabbcSTim J. Robbins } __packed l_siginfo_t; 375ea0fabbcSTim J. Robbins 376ea0fabbcSTim J. Robbins #define lsi_pid _sifields._kill._pid 377ea0fabbcSTim J. Robbins #define lsi_uid _sifields._kill._uid 378aa8b2011SKonstantin Belousov #define lsi_tid _sifields._timer._tid 379aa8b2011SKonstantin Belousov #define lsi_overrun _sifields._timer._overrun 380aa8b2011SKonstantin Belousov #define lsi_sys_private _sifields._timer._sys_private 381ea0fabbcSTim J. Robbins #define lsi_status _sifields._sigchld._status 382ea0fabbcSTim J. Robbins #define lsi_utime _sifields._sigchld._utime 383ea0fabbcSTim J. Robbins #define lsi_stime _sifields._sigchld._stime 384ea0fabbcSTim J. Robbins #define lsi_value _sifields._rt._sigval 385ea0fabbcSTim J. Robbins #define lsi_int _sifields._rt._sigval.sival_int 386ea0fabbcSTim J. Robbins #define lsi_ptr _sifields._rt._sigval.sival_ptr 387ea0fabbcSTim J. Robbins #define lsi_addr _sifields._sigfault._addr 388ea0fabbcSTim J. Robbins #define lsi_band _sifields._sigpoll._band 389ea0fabbcSTim J. Robbins #define lsi_fd _sifields._sigpoll._fd 390ea0fabbcSTim J. Robbins 391ea0fabbcSTim J. Robbins struct l_fpreg { 392ea0fabbcSTim J. Robbins u_int16_t significand[4]; 393ea0fabbcSTim J. Robbins u_int16_t exponent; 394ea0fabbcSTim J. Robbins } __packed; 395ea0fabbcSTim J. Robbins 396ea0fabbcSTim J. Robbins struct l_fpxreg { 397ea0fabbcSTim J. Robbins u_int16_t significand[4]; 398ea0fabbcSTim J. Robbins u_int16_t exponent; 399ea0fabbcSTim J. Robbins u_int16_t padding[3]; 400ea0fabbcSTim J. Robbins } __packed; 401ea0fabbcSTim J. Robbins 402ea0fabbcSTim J. Robbins struct l_xmmreg { 403ea0fabbcSTim J. Robbins u_int32_t element[4]; 404ea0fabbcSTim J. Robbins } __packed; 405ea0fabbcSTim J. Robbins 406ea0fabbcSTim J. Robbins struct l_fpstate { 407ea0fabbcSTim J. Robbins /* Regular FPU environment */ 408ea0fabbcSTim J. Robbins u_int32_t cw; 409ea0fabbcSTim J. Robbins u_int32_t sw; 410ea0fabbcSTim J. Robbins u_int32_t tag; 411ea0fabbcSTim J. Robbins u_int32_t ipoff; 412ea0fabbcSTim J. Robbins u_int32_t cssel; 413ea0fabbcSTim J. Robbins u_int32_t dataoff; 414ea0fabbcSTim J. Robbins u_int32_t datasel; 415ea0fabbcSTim J. Robbins struct l_fpreg _st[8]; 416ea0fabbcSTim J. Robbins u_int16_t status; 417ea0fabbcSTim J. Robbins u_int16_t magic; /* 0xffff = regular FPU data */ 418ea0fabbcSTim J. Robbins 419ea0fabbcSTim J. Robbins /* FXSR FPU environment */ 420a4e3bad7SJung-uk Kim u_int32_t _fxsr_env[6]; /* env is ignored. */ 421ea0fabbcSTim J. Robbins u_int32_t mxcsr; 422ea0fabbcSTim J. Robbins u_int32_t reserved; 423a4e3bad7SJung-uk Kim struct l_fpxreg _fxsr_st[8]; /* reg data is ignored. */ 424ea0fabbcSTim J. Robbins struct l_xmmreg _xmm[8]; 425ea0fabbcSTim J. Robbins u_int32_t padding[56]; 426ea0fabbcSTim J. Robbins } __packed; 427ea0fabbcSTim J. Robbins 428ea0fabbcSTim J. Robbins /* 429ea0fabbcSTim J. Robbins * We make the stack look like Linux expects it when calling a signal 430ea0fabbcSTim J. Robbins * handler, but use the BSD way of calling the handler and sigreturn(). 431ea0fabbcSTim J. Robbins * This means that we need to pass the pointer to the handler too. 432ea0fabbcSTim J. Robbins * It is appended to the frame to not interfere with the rest of it. 433ea0fabbcSTim J. Robbins */ 434ea0fabbcSTim J. Robbins struct l_sigframe { 435ea0fabbcSTim J. Robbins l_int sf_sig; 436ea0fabbcSTim J. Robbins struct l_sigcontext sf_sc; 437ea0fabbcSTim J. Robbins struct l_fpstate sf_fpstate; 4384ab7403bSDmitry Chagin l_uint sf_extramask[1]; 439ea0fabbcSTim J. Robbins l_handler_t sf_handler; 440ea0fabbcSTim J. Robbins } __packed; 441ea0fabbcSTim J. Robbins 442ea0fabbcSTim J. Robbins struct l_rt_sigframe { 443ea0fabbcSTim J. Robbins l_int sf_sig; 444ea0fabbcSTim J. Robbins l_uintptr_t sf_siginfo; 445ea0fabbcSTim J. Robbins l_uintptr_t sf_ucontext; 446ea0fabbcSTim J. Robbins l_siginfo_t sf_si; 447ea0fabbcSTim J. Robbins struct l_ucontext sf_sc; 448ea0fabbcSTim J. Robbins l_handler_t sf_handler; 449ea0fabbcSTim J. Robbins } __packed; 450ea0fabbcSTim J. Robbins 451ea0fabbcSTim J. Robbins /* 4524d0f380dSDmitry Chagin * arch specific open/fcntl flags 453ea0fabbcSTim J. Robbins */ 454ea0fabbcSTim J. Robbins #define LINUX_F_GETLK64 12 455ea0fabbcSTim J. Robbins #define LINUX_F_SETLK64 13 456ea0fabbcSTim J. Robbins #define LINUX_F_SETLKW64 14 457ea0fabbcSTim J. Robbins 458ea0fabbcSTim J. Robbins union l_semun { 459ea0fabbcSTim J. Robbins l_int val; 460ea0fabbcSTim J. Robbins l_uintptr_t buf; 461ea0fabbcSTim J. Robbins l_uintptr_t array; 462ea0fabbcSTim J. Robbins l_uintptr_t __buf; 463ea0fabbcSTim J. Robbins l_uintptr_t __pad; 464ea0fabbcSTim J. Robbins } __packed; 465ea0fabbcSTim J. Robbins 466ea0fabbcSTim J. Robbins struct l_ifmap { 467ea0fabbcSTim J. Robbins l_ulong mem_start; 468ea0fabbcSTim J. Robbins l_ulong mem_end; 469ea0fabbcSTim J. Robbins l_ushort base_addr; 470ea0fabbcSTim J. Robbins u_char irq; 471ea0fabbcSTim J. Robbins u_char dma; 472ea0fabbcSTim J. Robbins u_char port; 473ea0fabbcSTim J. Robbins } __packed; 474ea0fabbcSTim J. Robbins 475ea0fabbcSTim J. Robbins struct l_ifreq { 476ea0fabbcSTim J. Robbins union { 477ea0fabbcSTim J. Robbins char ifrn_name[LINUX_IFNAMSIZ]; 478ea0fabbcSTim J. Robbins } ifr_ifrn; 479ea0fabbcSTim J. Robbins 480ea0fabbcSTim J. Robbins union { 481ea0fabbcSTim J. Robbins struct l_sockaddr ifru_addr; 482ea0fabbcSTim J. Robbins struct l_sockaddr ifru_dstaddr; 483ea0fabbcSTim J. Robbins struct l_sockaddr ifru_broadaddr; 484ea0fabbcSTim J. Robbins struct l_sockaddr ifru_netmask; 485ea0fabbcSTim J. Robbins struct l_sockaddr ifru_hwaddr; 486ea0fabbcSTim J. Robbins l_short ifru_flags[1]; 4877ece126eSTai-hwa Liang l_int ifru_ivalue; 488ea0fabbcSTim J. Robbins l_int ifru_mtu; 489ea0fabbcSTim J. Robbins struct l_ifmap ifru_map; 490ea0fabbcSTim J. Robbins char ifru_slave[LINUX_IFNAMSIZ]; 491ea0fabbcSTim J. Robbins l_uintptr_t ifru_data; 492ea0fabbcSTim J. Robbins } ifr_ifru; 493ea0fabbcSTim J. Robbins } __packed; 494ea0fabbcSTim J. Robbins 495a4e3bad7SJung-uk Kim #define ifr_name ifr_ifrn.ifrn_name /* Interface name */ 496ea0fabbcSTim J. Robbins #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ 4977ece126eSTai-hwa Liang #define ifr_ifindex ifr_ifru.ifru_ivalue /* Interface index */ 498ea0fabbcSTim J. Robbins 499ea0fabbcSTim J. Robbins struct l_ifconf { 500ea0fabbcSTim J. Robbins int ifc_len; 501ea0fabbcSTim J. Robbins union { 502ea0fabbcSTim J. Robbins l_uintptr_t ifcu_buf; 503ea0fabbcSTim J. Robbins l_uintptr_t ifcu_req; 504ea0fabbcSTim J. Robbins } ifc_ifcu; 505ea0fabbcSTim J. Robbins } __packed; 506ea0fabbcSTim J. Robbins 507ea0fabbcSTim J. Robbins #define ifc_buf ifc_ifcu.ifcu_buf 508ea0fabbcSTim J. Robbins #define ifc_req ifc_ifcu.ifcu_req 509ea0fabbcSTim J. Robbins 510ea0fabbcSTim J. Robbins /* 511ea0fabbcSTim J. Robbins * poll() 512ea0fabbcSTim J. Robbins */ 513ea0fabbcSTim J. Robbins #define LINUX_POLLIN 0x0001 514ea0fabbcSTim J. Robbins #define LINUX_POLLPRI 0x0002 515ea0fabbcSTim J. Robbins #define LINUX_POLLOUT 0x0004 516ea0fabbcSTim J. Robbins #define LINUX_POLLERR 0x0008 517ea0fabbcSTim J. Robbins #define LINUX_POLLHUP 0x0010 518ea0fabbcSTim J. Robbins #define LINUX_POLLNVAL 0x0020 519ea0fabbcSTim J. Robbins #define LINUX_POLLRDNORM 0x0040 520ea0fabbcSTim J. Robbins #define LINUX_POLLRDBAND 0x0080 521ea0fabbcSTim J. Robbins #define LINUX_POLLWRNORM 0x0100 522ea0fabbcSTim J. Robbins #define LINUX_POLLWRBAND 0x0200 523ea0fabbcSTim J. Robbins #define LINUX_POLLMSG 0x0400 524ea0fabbcSTim J. Robbins 525ea0fabbcSTim J. Robbins struct l_pollfd { 526ea0fabbcSTim J. Robbins l_int fd; 527ea0fabbcSTim J. Robbins l_short events; 528ea0fabbcSTim J. Robbins l_short revents; 529ea0fabbcSTim J. Robbins } __packed; 530ea0fabbcSTim J. Robbins 5319b44bfc5SAlexander Leidinger struct l_user_desc { 5329b44bfc5SAlexander Leidinger l_uint entry_number; 5339b44bfc5SAlexander Leidinger l_uint base_addr; 5349b44bfc5SAlexander Leidinger l_uint limit; 5359b44bfc5SAlexander Leidinger l_uint seg_32bit:1; 5369b44bfc5SAlexander Leidinger l_uint contents:2; 5379b44bfc5SAlexander Leidinger l_uint read_exec_only:1; 5389b44bfc5SAlexander Leidinger l_uint limit_in_pages:1; 5399b44bfc5SAlexander Leidinger l_uint seg_not_present:1; 5409b44bfc5SAlexander Leidinger l_uint useable:1; 5419b44bfc5SAlexander Leidinger }; 5429b44bfc5SAlexander Leidinger 5439b44bfc5SAlexander Leidinger #define LINUX_LOWERWORD 0x0000ffff 5449b44bfc5SAlexander Leidinger 5450eef2f8aSAlexander Leidinger /* 546a4e3bad7SJung-uk Kim * Macros which does the same thing as those in Linux include/asm-um/ldt-i386.h. 547a4e3bad7SJung-uk Kim * These convert Linux user space descriptor to machine one. 5489b44bfc5SAlexander Leidinger */ 549a4e3bad7SJung-uk Kim #define LINUX_LDT_entry_a(info) \ 550a4e3bad7SJung-uk Kim ((((info)->base_addr & LINUX_LOWERWORD) << 16) | \ 551a4e3bad7SJung-uk Kim ((info)->limit & LINUX_LOWERWORD)) 5529b44bfc5SAlexander Leidinger 553a4e3bad7SJung-uk Kim #define LINUX_ENTRY_B_READ_EXEC_ONLY 9 554a4e3bad7SJung-uk Kim #define LINUX_ENTRY_B_CONTENTS 10 555a4e3bad7SJung-uk Kim #define LINUX_ENTRY_B_SEG_NOT_PRESENT 15 556a4e3bad7SJung-uk Kim #define LINUX_ENTRY_B_BASE_ADDR 16 557a4e3bad7SJung-uk Kim #define LINUX_ENTRY_B_USEABLE 20 558a4e3bad7SJung-uk Kim #define LINUX_ENTRY_B_SEG32BIT 22 559a4e3bad7SJung-uk Kim #define LINUX_ENTRY_B_LIMIT 23 5609b44bfc5SAlexander Leidinger 561a4e3bad7SJung-uk Kim #define LINUX_LDT_entry_b(info) \ 5629b44bfc5SAlexander Leidinger (((info)->base_addr & 0xff000000) | \ 5639b44bfc5SAlexander Leidinger ((info)->limit & 0xf0000) | \ 564a4e3bad7SJung-uk Kim ((info)->contents << LINUX_ENTRY_B_CONTENTS) | \ 565a4e3bad7SJung-uk Kim (((info)->seg_not_present == 0) << LINUX_ENTRY_B_SEG_NOT_PRESENT) | \ 566a4e3bad7SJung-uk Kim (((info)->base_addr & 0x00ff0000) >> LINUX_ENTRY_B_BASE_ADDR) | \ 567a4e3bad7SJung-uk Kim (((info)->read_exec_only == 0) << LINUX_ENTRY_B_READ_EXEC_ONLY) | \ 568a4e3bad7SJung-uk Kim ((info)->seg_32bit << LINUX_ENTRY_B_SEG32BIT) | \ 569a4e3bad7SJung-uk Kim ((info)->useable << LINUX_ENTRY_B_USEABLE) | \ 570a4e3bad7SJung-uk Kim ((info)->limit_in_pages << LINUX_ENTRY_B_LIMIT) | 0x7000) 5719b44bfc5SAlexander Leidinger 572a4e3bad7SJung-uk Kim #define LINUX_LDT_empty(info) \ 573a4e3bad7SJung-uk Kim ((info)->base_addr == 0 && \ 5749b44bfc5SAlexander Leidinger (info)->limit == 0 && \ 5759b44bfc5SAlexander Leidinger (info)->contents == 0 && \ 5769b44bfc5SAlexander Leidinger (info)->seg_not_present == 1 && \ 5779b44bfc5SAlexander Leidinger (info)->read_exec_only == 1 && \ 5789b44bfc5SAlexander Leidinger (info)->seg_32bit == 0 && \ 5799b44bfc5SAlexander Leidinger (info)->limit_in_pages == 0 && \ 5809b44bfc5SAlexander Leidinger (info)->useable == 0) 5819b44bfc5SAlexander Leidinger 582a4e3bad7SJung-uk Kim /* 583a4e3bad7SJung-uk Kim * Macros for converting segments. 584a4e3bad7SJung-uk Kim * They do the same as those in arch/i386/kernel/process.c in Linux. 585a4e3bad7SJung-uk Kim */ 586a4e3bad7SJung-uk Kim #define LINUX_GET_BASE(desc) \ 587a4e3bad7SJung-uk Kim ((((desc)->a >> 16) & LINUX_LOWERWORD) | \ 5889b44bfc5SAlexander Leidinger (((desc)->b << 16) & 0x00ff0000) | \ 5899b44bfc5SAlexander Leidinger ((desc)->b & 0xff000000)) 5909b44bfc5SAlexander Leidinger 591a4e3bad7SJung-uk Kim #define LINUX_GET_LIMIT(desc) \ 592a4e3bad7SJung-uk Kim (((desc)->a & LINUX_LOWERWORD) | \ 5939b44bfc5SAlexander Leidinger ((desc)->b & 0xf0000)) 5949b44bfc5SAlexander Leidinger 595a4e3bad7SJung-uk Kim #define LINUX_GET_32BIT(desc) \ 596a4e3bad7SJung-uk Kim (((desc)->b >> LINUX_ENTRY_B_SEG32BIT) & 1) 597a4e3bad7SJung-uk Kim #define LINUX_GET_CONTENTS(desc) \ 598a4e3bad7SJung-uk Kim (((desc)->b >> LINUX_ENTRY_B_CONTENTS) & 3) 599a4e3bad7SJung-uk Kim #define LINUX_GET_WRITABLE(desc) \ 600a4e3bad7SJung-uk Kim (((desc)->b >> LINUX_ENTRY_B_READ_EXEC_ONLY) & 1) 601a4e3bad7SJung-uk Kim #define LINUX_GET_LIMIT_PAGES(desc) \ 602a4e3bad7SJung-uk Kim (((desc)->b >> LINUX_ENTRY_B_LIMIT) & 1) 603a4e3bad7SJung-uk Kim #define LINUX_GET_PRESENT(desc) \ 604a4e3bad7SJung-uk Kim (((desc)->b >> LINUX_ENTRY_B_SEG_NOT_PRESENT) & 1) 605a4e3bad7SJung-uk Kim #define LINUX_GET_USEABLE(desc) \ 606a4e3bad7SJung-uk Kim (((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1) 6079b44bfc5SAlexander Leidinger 60841f53a36SKonstantin Belousov struct iovec; 609bd911530SMahdi Mokhtari struct uio; 61041f53a36SKonstantin Belousov 61141f53a36SKonstantin Belousov struct l_iovec32 { 61241f53a36SKonstantin Belousov uint32_t iov_base; 61341f53a36SKonstantin Belousov l_size_t iov_len; 61441f53a36SKonstantin Belousov }; 61541f53a36SKonstantin Belousov 61641f53a36SKonstantin Belousov int linux32_copyiniov(struct l_iovec32 *iovp32, l_ulong iovcnt, 61741f53a36SKonstantin Belousov struct iovec **iovp, int error); 618bd911530SMahdi Mokhtari int linux32_copyinuio(struct l_iovec32 *iovp, l_ulong iovcnt, 619bd911530SMahdi Mokhtari struct uio **uiop); 620001398c4SDmitry Chagin int linux_copyout_rusage(struct rusage *ru, void *uaddr); 62141f53a36SKonstantin Belousov 622175c6c31SKonstantin Belousov /* robust futexes */ 623175c6c31SKonstantin Belousov struct linux_robust_list { 624175c6c31SKonstantin Belousov l_uintptr_t next; 625175c6c31SKonstantin Belousov }; 626175c6c31SKonstantin Belousov 627175c6c31SKonstantin Belousov struct linux_robust_list_head { 628175c6c31SKonstantin Belousov struct linux_robust_list list; 62962162dfcSKonstantin Belousov l_long futex_offset; 630175c6c31SKonstantin Belousov l_uintptr_t pending_list; 631175c6c31SKonstantin Belousov }; 632175c6c31SKonstantin Belousov 633*95c19e1dSEdward Tomasz Napierala /* This corresponds to 'struct user_regs_struct32' in Linux. */ 634*95c19e1dSEdward Tomasz Napierala struct linux_pt_regset32 { 635*95c19e1dSEdward Tomasz Napierala l_uint ebx; 636*95c19e1dSEdward Tomasz Napierala l_uint ecx; 637*95c19e1dSEdward Tomasz Napierala l_uint edx; 638*95c19e1dSEdward Tomasz Napierala l_uint esi; 639*95c19e1dSEdward Tomasz Napierala l_uint edi; 640*95c19e1dSEdward Tomasz Napierala l_uint ebp; 641*95c19e1dSEdward Tomasz Napierala l_uint eax; 642*95c19e1dSEdward Tomasz Napierala l_uint ds; 643*95c19e1dSEdward Tomasz Napierala l_uint es; 644*95c19e1dSEdward Tomasz Napierala l_uint fs; 645*95c19e1dSEdward Tomasz Napierala l_uint gs; 646*95c19e1dSEdward Tomasz Napierala l_uint orig_eax; 647*95c19e1dSEdward Tomasz Napierala l_uint eip; 648*95c19e1dSEdward Tomasz Napierala l_uint cs; 649*95c19e1dSEdward Tomasz Napierala l_uint eflags; 650*95c19e1dSEdward Tomasz Napierala l_uint esp; 651*95c19e1dSEdward Tomasz Napierala l_uint ss; 652*95c19e1dSEdward Tomasz Napierala }; 653*95c19e1dSEdward Tomasz Napierala 654*95c19e1dSEdward Tomasz Napierala struct reg32; 655*95c19e1dSEdward Tomasz Napierala 656*95c19e1dSEdward Tomasz Napierala void bsd_to_linux_regset32(struct reg32 *b_reg, 657*95c19e1dSEdward Tomasz Napierala struct linux_pt_regset32 *l_regset); 658*95c19e1dSEdward Tomasz Napierala 659a4e3bad7SJung-uk Kim #endif /* !_AMD64_LINUX_H_ */ 660