1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 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 */ 28 29 #ifndef _I386_LINUX_H_ 30 #define _I386_LINUX_H_ 31 32 #include <sys/abi_compat.h> 33 34 #include <compat/linux/linux.h> 35 #include <i386/linux/linux_syscall.h> 36 37 #define LINUX_LEGACY_SYSCALLS 38 39 #define LINUX_DTRACE linuxulator 40 41 #define LINUX_ARCHWANT_MMAP2PGOFF 1 42 43 /* 44 * Provide a separate set of types for the Linux types. 45 */ 46 typedef int l_int; 47 typedef int32_t l_long; 48 typedef int64_t l_longlong; 49 typedef short l_short; 50 typedef unsigned int l_uint; 51 typedef uint32_t l_ulong; 52 typedef uint64_t l_ulonglong; 53 typedef unsigned short l_ushort; 54 55 typedef char *l_caddr_t; 56 typedef l_ulong l_uintptr_t; 57 typedef l_long l_clock_t; 58 typedef l_int l_daddr_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 typedef struct { 89 l_time64_t tv_sec; 90 l_time64_t tv_usec; 91 } l_sock_timeval; 92 93 #define l_fd_set fd_set 94 95 /* 96 * Miscellaneous 97 */ 98 #define LINUX_AT_COUNT 22 /* Count of used aux entry types. 99 * Keep this synchronized with 100 * linux_copyout_auxargs() code. 101 */ 102 struct l___sysctl_args 103 { 104 l_int *name; 105 l_int nlen; 106 void *oldval; 107 l_size_t *oldlenp; 108 void *newval; 109 l_size_t newlen; 110 l_ulong __spare[4]; 111 }; 112 113 /* Resource limits */ 114 #define LINUX_RLIMIT_CPU 0 115 #define LINUX_RLIMIT_FSIZE 1 116 #define LINUX_RLIMIT_DATA 2 117 #define LINUX_RLIMIT_STACK 3 118 #define LINUX_RLIMIT_CORE 4 119 #define LINUX_RLIMIT_RSS 5 120 #define LINUX_RLIMIT_NPROC 6 121 #define LINUX_RLIMIT_NOFILE 7 122 #define LINUX_RLIMIT_MEMLOCK 8 123 #define LINUX_RLIMIT_AS 9 /* Address space limit */ 124 125 #define LINUX_RLIM_NLIMITS 10 126 127 struct l_rlimit { 128 l_ulong rlim_cur; 129 l_ulong rlim_max; 130 }; 131 132 struct l_mmap_argv { 133 l_uintptr_t addr; 134 l_size_t len; 135 l_int prot; 136 l_int flags; 137 l_int fd; 138 l_off_t pgoff; 139 }; 140 141 /* 142 * stat family of syscalls 143 */ 144 struct l_timespec { 145 l_time_t tv_sec; 146 l_long tv_nsec; 147 }; 148 149 /* __kernel_timespec */ 150 struct l_timespec64 { 151 l_time64_t tv_sec; 152 l_longlong tv_nsec; 153 }; 154 155 struct l_newstat { 156 l_ulong st_dev; 157 l_ulong st_ino; 158 l_ushort st_mode; 159 l_ushort st_nlink; 160 l_ushort st_uid; 161 l_ushort st_gid; 162 l_ulong st_rdev; 163 l_ulong st_size; 164 l_ulong st_blksize; 165 l_ulong st_blocks; 166 struct l_timespec st_atim; 167 struct l_timespec st_mtim; 168 struct l_timespec st_ctim; 169 l_ulong __unused4; 170 l_ulong __unused5; 171 }; 172 173 /* __old_kernel_stat now */ 174 struct l_old_stat { 175 l_ushort st_dev; 176 l_ulong st_ino; 177 l_ushort st_mode; 178 l_ushort st_nlink; 179 l_ushort st_uid; 180 l_ushort st_gid; 181 l_ushort st_rdev; 182 l_long st_size; 183 struct l_timespec st_atim; 184 struct l_timespec st_mtim; 185 struct l_timespec st_ctim; 186 l_long st_blksize; 187 l_long st_blocks; 188 l_ulong st_flags; 189 l_ulong st_gen; 190 }; 191 192 struct l_stat64 { 193 l_ulonglong st_dev; 194 u_char __pad0[4]; 195 l_ulong __st_ino; 196 l_uint st_mode; 197 l_uint st_nlink; 198 l_ulong st_uid; 199 l_ulong st_gid; 200 l_ulonglong st_rdev; 201 u_char __pad3[4]; 202 l_longlong st_size; 203 l_ulong st_blksize; 204 l_ulonglong st_blocks; 205 struct l_timespec st_atim; 206 struct l_timespec st_mtim; 207 struct l_timespec st_ctim; 208 l_ulonglong st_ino; 209 }; 210 211 struct l_statfs64 { 212 l_int f_type; 213 l_int f_bsize; 214 uint64_t f_blocks; 215 uint64_t f_bfree; 216 uint64_t f_bavail; 217 uint64_t f_files; 218 uint64_t f_ffree; 219 l_fsid_t f_fsid; 220 l_int f_namelen; 221 l_int f_frsize; 222 l_int f_flags; 223 l_int f_spare[4]; 224 }; 225 226 /* sigaction flags */ 227 #define LINUX_SA_NOCLDSTOP 0x00000001 228 #define LINUX_SA_NOCLDWAIT 0x00000002 229 #define LINUX_SA_SIGINFO 0x00000004 230 #define LINUX_SA_RESTORER 0x04000000 231 #define LINUX_SA_ONSTACK 0x08000000 232 #define LINUX_SA_RESTART 0x10000000 233 #define LINUX_SA_INTERRUPT 0x20000000 234 #define LINUX_SA_NOMASK 0x40000000 235 #define LINUX_SA_ONESHOT 0x80000000 236 237 /* sigaltstack */ 238 #define LINUX_MINSIGSTKSZ 2048 239 240 typedef void (*l_handler_t)(l_int); 241 typedef l_ulong l_osigset_t; 242 243 typedef struct { 244 l_handler_t lsa_handler; 245 l_osigset_t lsa_mask; 246 l_ulong lsa_flags; 247 void (*lsa_restorer)(void); 248 } l_osigaction_t; 249 250 typedef struct { 251 l_handler_t lsa_handler; 252 l_ulong lsa_flags; 253 void (*lsa_restorer)(void); 254 l_sigset_t lsa_mask; 255 } l_sigaction_t; 256 257 typedef struct { 258 l_uintptr_t ss_sp; 259 l_int ss_flags; 260 l_size_t ss_size; 261 } l_stack_t; 262 263 extern struct sysentvec linux_sysvec; 264 265 /* 266 * arch specific open/fcntl flags 267 */ 268 #define LINUX_F_GETLK64 12 269 #define LINUX_F_SETLK64 13 270 #define LINUX_F_SETLKW64 14 271 272 union l_semun { 273 l_int val; 274 l_uintptr_t buf; 275 l_ushort *array; 276 l_uintptr_t __buf; 277 l_uintptr_t __pad; 278 }; 279 280 struct l_user_desc { 281 l_uint entry_number; 282 l_uint base_addr; 283 l_uint limit; 284 l_uint seg_32bit:1; 285 l_uint contents:2; 286 l_uint read_exec_only:1; 287 l_uint limit_in_pages:1; 288 l_uint seg_not_present:1; 289 l_uint useable:1; 290 }; 291 292 struct l_desc_struct { 293 unsigned long a, b; 294 }; 295 296 #define LINUX_LOWERWORD 0x0000ffff 297 298 /* 299 * Macros which does the same thing as those in Linux include/asm-um/ldt-i386.h. 300 * These convert Linux user space descriptor to machine one. 301 */ 302 #define LINUX_LDT_entry_a(info) \ 303 ((((info)->base_addr & LINUX_LOWERWORD) << 16) | \ 304 ((info)->limit & LINUX_LOWERWORD)) 305 306 #define LINUX_ENTRY_B_READ_EXEC_ONLY 9 307 #define LINUX_ENTRY_B_CONTENTS 10 308 #define LINUX_ENTRY_B_SEG_NOT_PRESENT 15 309 #define LINUX_ENTRY_B_BASE_ADDR 16 310 #define LINUX_ENTRY_B_USEABLE 20 311 #define LINUX_ENTRY_B_SEG32BIT 22 312 #define LINUX_ENTRY_B_LIMIT 23 313 314 #define LINUX_LDT_entry_b(info) \ 315 (((info)->base_addr & 0xff000000) | \ 316 ((info)->limit & 0xf0000) | \ 317 ((info)->contents << LINUX_ENTRY_B_CONTENTS) | \ 318 (((info)->seg_not_present == 0) << LINUX_ENTRY_B_SEG_NOT_PRESENT) | \ 319 (((info)->base_addr & 0x00ff0000) >> LINUX_ENTRY_B_BASE_ADDR) | \ 320 (((info)->read_exec_only == 0) << LINUX_ENTRY_B_READ_EXEC_ONLY) | \ 321 ((info)->seg_32bit << LINUX_ENTRY_B_SEG32BIT) | \ 322 ((info)->useable << LINUX_ENTRY_B_USEABLE) | \ 323 ((info)->limit_in_pages << LINUX_ENTRY_B_LIMIT) | 0x7000) 324 325 #define LINUX_LDT_empty(info) \ 326 ((info)->base_addr == 0 && \ 327 (info)->limit == 0 && \ 328 (info)->contents == 0 && \ 329 (info)->seg_not_present == 1 && \ 330 (info)->read_exec_only == 1 && \ 331 (info)->seg_32bit == 0 && \ 332 (info)->limit_in_pages == 0 && \ 333 (info)->useable == 0) 334 335 /* 336 * Macros for converting segments. 337 * They do the same as those in arch/i386/kernel/process.c in Linux. 338 */ 339 #define LINUX_GET_BASE(desc) \ 340 ((((desc)->a >> 16) & LINUX_LOWERWORD) | \ 341 (((desc)->b << 16) & 0x00ff0000) | \ 342 ((desc)->b & 0xff000000)) 343 344 #define LINUX_GET_LIMIT(desc) \ 345 (((desc)->a & LINUX_LOWERWORD) | \ 346 ((desc)->b & 0xf0000)) 347 348 #define LINUX_GET_32BIT(desc) \ 349 (((desc)->b >> LINUX_ENTRY_B_SEG32BIT) & 1) 350 #define LINUX_GET_CONTENTS(desc) \ 351 (((desc)->b >> LINUX_ENTRY_B_CONTENTS) & 3) 352 #define LINUX_GET_WRITABLE(desc) \ 353 (((desc)->b >> LINUX_ENTRY_B_READ_EXEC_ONLY) & 1) 354 #define LINUX_GET_LIMIT_PAGES(desc) \ 355 (((desc)->b >> LINUX_ENTRY_B_LIMIT) & 1) 356 #define LINUX_GET_PRESENT(desc) \ 357 (((desc)->b >> LINUX_ENTRY_B_SEG_NOT_PRESENT) & 1) 358 #define LINUX_GET_USEABLE(desc) \ 359 (((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1) 360 361 #define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r)) 362 363 /* This corresponds to 'struct user_regs_struct' in Linux. */ 364 struct linux_pt_regset { 365 l_uint ebx; 366 l_uint ecx; 367 l_uint edx; 368 l_uint esi; 369 l_uint edi; 370 l_uint ebp; 371 l_uint eax; 372 l_uint ds; 373 l_uint es; 374 l_uint fs; 375 l_uint gs; 376 l_uint orig_eax; 377 l_uint eip; 378 l_uint cs; 379 l_uint eflags; 380 l_uint esp; 381 l_uint ss; 382 }; 383 384 #ifdef _KERNEL 385 struct reg; 386 387 void bsd_to_linux_regset(const struct reg *b_reg, 388 struct linux_pt_regset *l_regset); 389 #endif /* _KERNEL */ 390 391 #endif /* !_I386_LINUX_H_ */ 392