1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 1994-1996 Søren Schmidt 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 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 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * $FreeBSD$ 28 */ 29 30 #ifndef _I386_LINUX_H_ 31 #define _I386_LINUX_H_ 32 33 #include <sys/abi_compat.h> 34 35 #include <compat/linux/linux.h> 36 #include <i386/linux/linux_syscall.h> 37 38 #define LINUX_LEGACY_SYSCALLS 39 40 #define LINUX_DTRACE linuxulator 41 42 /* 43 * Provide a separate set of types for the Linux types. 44 */ 45 typedef int l_int; 46 typedef int32_t l_long; 47 typedef int64_t l_longlong; 48 typedef short l_short; 49 typedef unsigned int l_uint; 50 typedef uint32_t l_ulong; 51 typedef uint64_t l_ulonglong; 52 typedef unsigned short l_ushort; 53 54 typedef char *l_caddr_t; 55 typedef l_ulong l_uintptr_t; 56 typedef l_long l_clock_t; 57 typedef l_int l_daddr_t; 58 typedef l_ushort l_dev_t; 59 typedef l_uint l_gid_t; 60 typedef l_ushort l_gid16_t; 61 typedef l_ulong l_ino_t; 62 typedef l_int l_key_t; 63 typedef l_longlong l_loff_t; 64 typedef l_ushort l_mode_t; 65 typedef l_long l_off_t; 66 typedef l_int l_pid_t; 67 typedef l_uint l_size_t; 68 typedef l_long l_suseconds_t; 69 typedef l_long l_time_t; 70 typedef l_longlong l_time64_t; 71 typedef l_uint l_uid_t; 72 typedef l_ushort l_uid16_t; 73 typedef l_int l_timer_t; 74 typedef l_int l_mqd_t; 75 typedef l_ulong l_fd_mask; 76 77 #include <compat/linux/linux_siginfo.h> 78 79 typedef struct { 80 l_int val[2]; 81 } l_fsid_t; 82 83 typedef struct { 84 l_time_t tv_sec; 85 l_suseconds_t tv_usec; 86 } l_timeval; 87 88 #define l_fd_set fd_set 89 90 /* 91 * Miscellaneous 92 */ 93 #define LINUX_AT_COUNT 20 /* Count of used aux entry types. 94 * Keep this synchronized with 95 * linux_fixup_elf() code. 96 */ 97 struct l___sysctl_args 98 { 99 l_int *name; 100 l_int nlen; 101 void *oldval; 102 l_size_t *oldlenp; 103 void *newval; 104 l_size_t newlen; 105 l_ulong __spare[4]; 106 }; 107 108 /* Resource limits */ 109 #define LINUX_RLIMIT_CPU 0 110 #define LINUX_RLIMIT_FSIZE 1 111 #define LINUX_RLIMIT_DATA 2 112 #define LINUX_RLIMIT_STACK 3 113 #define LINUX_RLIMIT_CORE 4 114 #define LINUX_RLIMIT_RSS 5 115 #define LINUX_RLIMIT_NPROC 6 116 #define LINUX_RLIMIT_NOFILE 7 117 #define LINUX_RLIMIT_MEMLOCK 8 118 #define LINUX_RLIMIT_AS 9 /* Address space limit */ 119 120 #define LINUX_RLIM_NLIMITS 10 121 122 struct l_rlimit { 123 l_ulong rlim_cur; 124 l_ulong rlim_max; 125 }; 126 127 struct l_mmap_argv { 128 l_uintptr_t addr; 129 l_size_t len; 130 l_int prot; 131 l_int flags; 132 l_int fd; 133 l_off_t pgoff; 134 }; 135 136 /* 137 * stat family of syscalls 138 */ 139 struct l_timespec { 140 l_time_t tv_sec; 141 l_long tv_nsec; 142 }; 143 144 /* __kernel_timespec */ 145 struct l_timespec64 { 146 l_time64_t tv_sec; 147 l_longlong tv_nsec; 148 }; 149 150 struct l_newstat { 151 l_ushort st_dev; 152 l_ushort __pad1; 153 l_ulong st_ino; 154 l_ushort st_mode; 155 l_ushort st_nlink; 156 l_ushort st_uid; 157 l_ushort st_gid; 158 l_ushort st_rdev; 159 l_ushort __pad2; 160 l_ulong st_size; 161 l_ulong st_blksize; 162 l_ulong st_blocks; 163 struct l_timespec st_atim; 164 struct l_timespec st_mtim; 165 struct l_timespec st_ctim; 166 l_ulong __unused4; 167 l_ulong __unused5; 168 }; 169 170 struct l_stat { 171 l_ushort st_dev; 172 l_ulong st_ino; 173 l_ushort st_mode; 174 l_ushort st_nlink; 175 l_ushort st_uid; 176 l_ushort st_gid; 177 l_ushort st_rdev; 178 l_long st_size; 179 struct l_timespec st_atim; 180 struct l_timespec st_mtim; 181 struct l_timespec st_ctim; 182 l_long st_blksize; 183 l_long st_blocks; 184 l_ulong st_flags; 185 l_ulong st_gen; 186 }; 187 188 struct l_stat64 { 189 l_ushort st_dev; 190 u_char __pad0[10]; 191 l_ulong __st_ino; 192 l_uint st_mode; 193 l_uint st_nlink; 194 l_ulong st_uid; 195 l_ulong st_gid; 196 l_ushort st_rdev; 197 u_char __pad3[10]; 198 l_longlong st_size; 199 l_ulong st_blksize; 200 l_ulong st_blocks; 201 l_ulong __pad4; 202 struct l_timespec st_atim; 203 struct l_timespec st_mtim; 204 struct l_timespec st_ctim; 205 l_ulonglong st_ino; 206 }; 207 208 struct l_statfs64 { 209 l_int f_type; 210 l_int f_bsize; 211 uint64_t f_blocks; 212 uint64_t f_bfree; 213 uint64_t f_bavail; 214 uint64_t f_files; 215 uint64_t f_ffree; 216 l_fsid_t f_fsid; 217 l_int f_namelen; 218 l_int f_frsize; 219 l_int f_flags; 220 l_int f_spare[4]; 221 }; 222 223 /* sigaction flags */ 224 #define LINUX_SA_NOCLDSTOP 0x00000001 225 #define LINUX_SA_NOCLDWAIT 0x00000002 226 #define LINUX_SA_SIGINFO 0x00000004 227 #define LINUX_SA_RESTORER 0x04000000 228 #define LINUX_SA_ONSTACK 0x08000000 229 #define LINUX_SA_RESTART 0x10000000 230 #define LINUX_SA_INTERRUPT 0x20000000 231 #define LINUX_SA_NOMASK 0x40000000 232 #define LINUX_SA_ONESHOT 0x80000000 233 234 /* sigprocmask actions */ 235 #define LINUX_SIG_BLOCK 0 236 #define LINUX_SIG_UNBLOCK 1 237 #define LINUX_SIG_SETMASK 2 238 239 /* sigaltstack */ 240 #define LINUX_MINSIGSTKSZ 2048 241 242 typedef void (*l_handler_t)(l_int); 243 typedef l_ulong l_osigset_t; 244 245 typedef struct { 246 l_handler_t lsa_handler; 247 l_osigset_t lsa_mask; 248 l_ulong lsa_flags; 249 void (*lsa_restorer)(void); 250 } l_osigaction_t; 251 252 typedef struct { 253 l_handler_t lsa_handler; 254 l_ulong lsa_flags; 255 void (*lsa_restorer)(void); 256 l_sigset_t lsa_mask; 257 } l_sigaction_t; 258 259 typedef struct { 260 l_uintptr_t ss_sp; 261 l_int ss_flags; 262 l_size_t ss_size; 263 } l_stack_t; 264 265 extern struct sysentvec linux_sysvec; 266 267 /* 268 * arch specific open/fcntl flags 269 */ 270 #define LINUX_F_GETLK64 12 271 #define LINUX_F_SETLK64 13 272 #define LINUX_F_SETLKW64 14 273 274 union l_semun { 275 l_int val; 276 l_uintptr_t buf; 277 l_ushort *array; 278 l_uintptr_t __buf; 279 l_uintptr_t __pad; 280 }; 281 282 struct l_ifmap { 283 l_ulong mem_start; 284 l_ulong mem_end; 285 l_ushort base_addr; 286 u_char irq; 287 u_char dma; 288 u_char port; 289 }; 290 291 struct l_ifreq { 292 union { 293 char ifrn_name[LINUX_IFNAMSIZ]; 294 } ifr_ifrn; 295 296 union { 297 struct l_sockaddr ifru_addr; 298 struct l_sockaddr ifru_dstaddr; 299 struct l_sockaddr ifru_broadaddr; 300 struct l_sockaddr ifru_netmask; 301 struct l_sockaddr ifru_hwaddr; 302 l_short ifru_flags[1]; 303 l_int ifru_ivalue; 304 l_int ifru_mtu; 305 struct l_ifmap ifru_map; 306 char ifru_slave[LINUX_IFNAMSIZ]; 307 l_caddr_t ifru_data; 308 } ifr_ifru; 309 }; 310 311 #define ifr_name ifr_ifrn.ifrn_name /* Interface name */ 312 #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ 313 #define ifr_ifindex ifr_ifru.ifru_ivalue /* Interface index */ 314 315 struct l_user_desc { 316 l_uint entry_number; 317 l_uint base_addr; 318 l_uint limit; 319 l_uint seg_32bit:1; 320 l_uint contents:2; 321 l_uint read_exec_only:1; 322 l_uint limit_in_pages:1; 323 l_uint seg_not_present:1; 324 l_uint useable:1; 325 }; 326 327 struct l_desc_struct { 328 unsigned long a, b; 329 }; 330 331 #define LINUX_LOWERWORD 0x0000ffff 332 333 /* 334 * Macros which does the same thing as those in Linux include/asm-um/ldt-i386.h. 335 * These convert Linux user space descriptor to machine one. 336 */ 337 #define LINUX_LDT_entry_a(info) \ 338 ((((info)->base_addr & LINUX_LOWERWORD) << 16) | \ 339 ((info)->limit & LINUX_LOWERWORD)) 340 341 #define LINUX_ENTRY_B_READ_EXEC_ONLY 9 342 #define LINUX_ENTRY_B_CONTENTS 10 343 #define LINUX_ENTRY_B_SEG_NOT_PRESENT 15 344 #define LINUX_ENTRY_B_BASE_ADDR 16 345 #define LINUX_ENTRY_B_USEABLE 20 346 #define LINUX_ENTRY_B_SEG32BIT 22 347 #define LINUX_ENTRY_B_LIMIT 23 348 349 #define LINUX_LDT_entry_b(info) \ 350 (((info)->base_addr & 0xff000000) | \ 351 ((info)->limit & 0xf0000) | \ 352 ((info)->contents << LINUX_ENTRY_B_CONTENTS) | \ 353 (((info)->seg_not_present == 0) << LINUX_ENTRY_B_SEG_NOT_PRESENT) | \ 354 (((info)->base_addr & 0x00ff0000) >> LINUX_ENTRY_B_BASE_ADDR) | \ 355 (((info)->read_exec_only == 0) << LINUX_ENTRY_B_READ_EXEC_ONLY) | \ 356 ((info)->seg_32bit << LINUX_ENTRY_B_SEG32BIT) | \ 357 ((info)->useable << LINUX_ENTRY_B_USEABLE) | \ 358 ((info)->limit_in_pages << LINUX_ENTRY_B_LIMIT) | 0x7000) 359 360 #define LINUX_LDT_empty(info) \ 361 ((info)->base_addr == 0 && \ 362 (info)->limit == 0 && \ 363 (info)->contents == 0 && \ 364 (info)->seg_not_present == 1 && \ 365 (info)->read_exec_only == 1 && \ 366 (info)->seg_32bit == 0 && \ 367 (info)->limit_in_pages == 0 && \ 368 (info)->useable == 0) 369 370 /* 371 * Macros for converting segments. 372 * They do the same as those in arch/i386/kernel/process.c in Linux. 373 */ 374 #define LINUX_GET_BASE(desc) \ 375 ((((desc)->a >> 16) & LINUX_LOWERWORD) | \ 376 (((desc)->b << 16) & 0x00ff0000) | \ 377 ((desc)->b & 0xff000000)) 378 379 #define LINUX_GET_LIMIT(desc) \ 380 (((desc)->a & LINUX_LOWERWORD) | \ 381 ((desc)->b & 0xf0000)) 382 383 #define LINUX_GET_32BIT(desc) \ 384 (((desc)->b >> LINUX_ENTRY_B_SEG32BIT) & 1) 385 #define LINUX_GET_CONTENTS(desc) \ 386 (((desc)->b >> LINUX_ENTRY_B_CONTENTS) & 3) 387 #define LINUX_GET_WRITABLE(desc) \ 388 (((desc)->b >> LINUX_ENTRY_B_READ_EXEC_ONLY) & 1) 389 #define LINUX_GET_LIMIT_PAGES(desc) \ 390 (((desc)->b >> LINUX_ENTRY_B_LIMIT) & 1) 391 #define LINUX_GET_PRESENT(desc) \ 392 (((desc)->b >> LINUX_ENTRY_B_SEG_NOT_PRESENT) & 1) 393 #define LINUX_GET_USEABLE(desc) \ 394 (((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1) 395 396 #define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r)) 397 398 /* robust futexes */ 399 struct linux_robust_list { 400 struct linux_robust_list *next; 401 }; 402 403 struct linux_robust_list_head { 404 struct linux_robust_list list; 405 l_long futex_offset; 406 struct linux_robust_list *pending_list; 407 }; 408 409 #endif /* !_I386_LINUX_H_ */ 410