linux.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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. #ifndef _I386_LINUX_H_
  30. #define _I386_LINUX_H_
  31. #include <sys/abi_compat.h>
  32. #include <sys/signal.h> /* for sigval union */
  33. #include <compat/linux/linux.h>
  34. #include <i386/linux/linux_syscall.h>
  35. #define LINUX_LEGACY_SYSCALLS
  36. #define LINUX_DTRACE linuxulator
  37. #define LINUX_SHAREDPAGE (VM_MAXUSER_ADDRESS - PAGE_SIZE)
  38. #define LINUX_USRSTACK LINUX_SHAREDPAGE
  39. /*
  40. * Provide a separate set of types for the Linux types.
  41. */
  42. typedef int l_int;
  43. typedef int32_t l_long;
  44. typedef int64_t l_longlong;
  45. typedef short l_short;
  46. typedef unsigned int l_uint;
  47. typedef uint32_t l_ulong;
  48. typedef uint64_t l_ulonglong;
  49. typedef unsigned short l_ushort;
  50. typedef char *l_caddr_t;
  51. typedef l_ulong l_uintptr_t;
  52. typedef l_long l_clock_t;
  53. typedef l_int l_daddr_t;
  54. typedef l_ushort l_dev_t;
  55. typedef l_uint l_gid_t;
  56. typedef l_ushort l_gid16_t;
  57. typedef l_ulong l_ino_t;
  58. typedef l_int l_key_t;
  59. typedef l_longlong l_loff_t;
  60. typedef l_ushort l_mode_t;
  61. typedef l_long l_off_t;
  62. typedef l_int l_pid_t;
  63. typedef l_uint l_size_t;
  64. typedef l_long l_suseconds_t;
  65. typedef l_long l_time_t;
  66. typedef l_uint l_uid_t;
  67. typedef l_ushort l_uid16_t;
  68. typedef l_int l_timer_t;
  69. typedef l_int l_mqd_t;
  70. typedef l_ulong l_fd_mask;
  71. typedef struct {
  72. l_int val[2];
  73. } l_fsid_t;
  74. typedef struct {
  75. l_time_t tv_sec;
  76. l_suseconds_t tv_usec;
  77. } l_timeval;
  78. #define l_fd_set fd_set
  79. /*
  80. * Miscellaneous
  81. */
  82. #define LINUX_AT_COUNT 20 /* Count of used aux entry types.
  83. * Keep this synchronized with
  84. * linux_fixup_elf() code.
  85. */
  86. struct l___sysctl_args
  87. {
  88. l_int *name;
  89. l_int nlen;
  90. void *oldval;
  91. l_size_t *oldlenp;
  92. void *newval;
  93. l_size_t newlen;
  94. l_ulong __spare[4];
  95. };
  96. /* Resource limits */
  97. #define LINUX_RLIMIT_CPU 0
  98. #define LINUX_RLIMIT_FSIZE 1
  99. #define LINUX_RLIMIT_DATA 2
  100. #define LINUX_RLIMIT_STACK 3
  101. #define LINUX_RLIMIT_CORE 4
  102. #define LINUX_RLIMIT_RSS 5
  103. #define LINUX_RLIMIT_NPROC 6
  104. #define LINUX_RLIMIT_NOFILE 7
  105. #define LINUX_RLIMIT_MEMLOCK 8
  106. #define LINUX_RLIMIT_AS 9 /* Address space limit */
  107. #define LINUX_RLIM_NLIMITS 10
  108. struct l_rlimit {
  109. l_ulong rlim_cur;
  110. l_ulong rlim_max;
  111. };
  112. struct l_mmap_argv {
  113. l_uintptr_t addr;
  114. l_size_t len;
  115. l_int prot;
  116. l_int flags;
  117. l_int fd;
  118. l_off_t pgoff;
  119. } __packed;
  120. /*
  121. * stat family of syscalls
  122. */
  123. struct l_timespec {
  124. l_time_t tv_sec;
  125. l_long tv_nsec;
  126. };
  127. struct l_newstat {
  128. l_ushort st_dev;
  129. l_ushort __pad1;
  130. l_ulong st_ino;
  131. l_ushort st_mode;
  132. l_ushort st_nlink;
  133. l_ushort st_uid;
  134. l_ushort st_gid;
  135. l_ushort st_rdev;
  136. l_ushort __pad2;
  137. l_ulong st_size;
  138. l_ulong st_blksize;
  139. l_ulong st_blocks;
  140. struct l_timespec st_atim;
  141. struct l_timespec st_mtim;
  142. struct l_timespec st_ctim;
  143. l_ulong __unused4;
  144. l_ulong __unused5;
  145. };
  146. struct l_stat {
  147. l_ushort st_dev;
  148. l_ulong st_ino;
  149. l_ushort st_mode;
  150. l_ushort st_nlink;
  151. l_ushort st_uid;
  152. l_ushort st_gid;
  153. l_ushort st_rdev;
  154. l_long st_size;
  155. struct l_timespec st_atim;
  156. struct l_timespec st_mtim;
  157. struct l_timespec st_ctim;
  158. l_long st_blksize;
  159. l_long st_blocks;
  160. l_ulong st_flags;
  161. l_ulong st_gen;
  162. };
  163. struct l_stat64 {
  164. l_ushort st_dev;
  165. u_char __pad0[10];
  166. l_ulong __st_ino;
  167. l_uint st_mode;
  168. l_uint st_nlink;
  169. l_ulong st_uid;
  170. l_ulong st_gid;
  171. l_ushort st_rdev;
  172. u_char __pad3[10];
  173. l_longlong st_size;
  174. l_ulong st_blksize;
  175. l_ulong st_blocks;
  176. l_ulong __pad4;
  177. struct l_timespec st_atim;
  178. struct l_timespec st_mtim;
  179. struct l_timespec st_ctim;
  180. l_ulonglong st_ino;
  181. };
  182. struct l_statfs64 {
  183. l_int f_type;
  184. l_int f_bsize;
  185. uint64_t f_blocks;
  186. uint64_t f_bfree;
  187. uint64_t f_bavail;
  188. uint64_t f_files;
  189. uint64_t f_ffree;
  190. l_fsid_t f_fsid;
  191. l_int f_namelen;
  192. l_int f_frsize;
  193. l_int f_flags;
  194. l_int f_spare[4];
  195. };
  196. #define LINUX_NSIG_WORDS 2
  197. /* sigaction flags */
  198. #define LINUX_SA_NOCLDSTOP 0x00000001
  199. #define LINUX_SA_NOCLDWAIT 0x00000002
  200. #define LINUX_SA_SIGINFO 0x00000004
  201. #define LINUX_SA_RESTORER 0x04000000
  202. #define LINUX_SA_ONSTACK 0x08000000
  203. #define LINUX_SA_RESTART 0x10000000
  204. #define LINUX_SA_INTERRUPT 0x20000000
  205. #define LINUX_SA_NOMASK 0x40000000
  206. #define LINUX_SA_ONESHOT 0x80000000
  207. /* sigprocmask actions */
  208. #define LINUX_SIG_BLOCK 0
  209. #define LINUX_SIG_UNBLOCK 1
  210. #define LINUX_SIG_SETMASK 2
  211. /* sigaltstack */
  212. #define LINUX_MINSIGSTKSZ 2048
  213. typedef void (*l_handler_t)(l_int);
  214. typedef l_ulong l_osigset_t;
  215. typedef struct {
  216. l_handler_t lsa_handler;
  217. l_osigset_t lsa_mask;
  218. l_ulong lsa_flags;
  219. void (*lsa_restorer)(void);
  220. } l_osigaction_t;
  221. typedef struct {
  222. l_handler_t lsa_handler;
  223. l_ulong lsa_flags;
  224. void (*lsa_restorer)(void);
  225. l_sigset_t lsa_mask;
  226. } l_sigaction_t;
  227. typedef struct {
  228. void *ss_sp;
  229. l_int ss_flags;
  230. l_size_t ss_size;
  231. } l_stack_t;
  232. /* The Linux sigcontext, pretty much a standard 386 trapframe. */
  233. struct l_sigcontext {
  234. l_int sc_gs;
  235. l_int sc_fs;
  236. l_int sc_es;
  237. l_int sc_ds;
  238. l_int sc_edi;
  239. l_int sc_esi;
  240. l_int sc_ebp;
  241. l_int sc_esp;
  242. l_int sc_ebx;
  243. l_int sc_edx;
  244. l_int sc_ecx;
  245. l_int sc_eax;
  246. l_int sc_trapno;
  247. l_int sc_err;
  248. l_int sc_eip;
  249. l_int sc_cs;
  250. l_int sc_eflags;
  251. l_int sc_esp_at_signal;
  252. l_int sc_ss;
  253. l_int sc_387;
  254. l_int sc_mask;
  255. l_int sc_cr2;
  256. };
  257. struct l_ucontext {
  258. l_ulong uc_flags;
  259. void *uc_link;
  260. l_stack_t uc_stack;
  261. struct l_sigcontext uc_mcontext;
  262. l_sigset_t uc_sigmask;
  263. };
  264. #define LINUX_SI_MAX_SIZE 128
  265. #define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE/sizeof(l_int)) - 3)
  266. typedef union l_sigval {
  267. l_int sival_int;
  268. l_uintptr_t sival_ptr;
  269. } l_sigval_t;
  270. typedef struct l_siginfo {
  271. l_int lsi_signo;
  272. l_int lsi_errno;
  273. l_int lsi_code;
  274. union {
  275. l_int _pad[LINUX_SI_PAD_SIZE];
  276. struct {
  277. l_pid_t _pid;
  278. l_uid_t _uid;
  279. } _kill;
  280. struct {
  281. l_timer_t _tid;
  282. l_int _overrun;
  283. char _pad[sizeof(l_uid_t) - sizeof(l_int)];
  284. l_sigval_t _sigval;
  285. l_int _sys_private;
  286. } _timer;
  287. struct {
  288. l_pid_t _pid; /* sender's pid */
  289. l_uid_t _uid; /* sender's uid */
  290. l_sigval_t _sigval;
  291. } _rt;
  292. struct {
  293. l_pid_t _pid; /* which child */
  294. l_uid_t _uid; /* sender's uid */
  295. l_int _status; /* exit code */
  296. l_clock_t _utime;
  297. l_clock_t _stime;
  298. } _sigchld;
  299. struct {
  300. l_uintptr_t _addr; /* Faulting insn/memory ref. */
  301. } _sigfault;
  302. struct {
  303. l_long _band; /* POLL_IN,POLL_OUT,POLL_MSG */
  304. l_int _fd;
  305. } _sigpoll;
  306. } _sifields;
  307. } l_siginfo_t;
  308. #define lsi_pid _sifields._kill._pid
  309. #define lsi_uid _sifields._kill._uid
  310. #define lsi_tid _sifields._timer._tid
  311. #define lsi_overrun _sifields._timer._overrun
  312. #define lsi_sys_private _sifields._timer._sys_private
  313. #define lsi_status _sifields._sigchld._status
  314. #define lsi_utime _sifields._sigchld._utime
  315. #define lsi_stime _sifields._sigchld._stime
  316. #define lsi_value _sifields._rt._sigval
  317. #define lsi_int _sifields._rt._sigval.sival_int
  318. #define lsi_ptr _sifields._rt._sigval.sival_ptr
  319. #define lsi_addr _sifields._sigfault._addr
  320. #define lsi_band _sifields._sigpoll._band
  321. #define lsi_fd _sifields._sigpoll._fd
  322. struct l_fpreg {
  323. u_int16_t significand[4];
  324. u_int16_t exponent;
  325. };
  326. struct l_fpxreg {
  327. u_int16_t significand[4];
  328. u_int16_t exponent;
  329. u_int16_t padding[3];
  330. };
  331. struct l_xmmreg {
  332. u_int32_t element[4];
  333. };
  334. struct l_fpstate {
  335. /* Regular FPU environment */
  336. u_int32_t cw;
  337. u_int32_t sw;
  338. u_int32_t tag;
  339. u_int32_t ipoff;
  340. u_int32_t cssel;
  341. u_int32_t dataoff;
  342. u_int32_t datasel;
  343. struct l_fpreg _st[8];
  344. u_int16_t status;
  345. u_int16_t magic; /* 0xffff = regular FPU data */
  346. /* FXSR FPU environment */
  347. u_int32_t _fxsr_env[6]; /* env is ignored. */
  348. u_int32_t mxcsr;
  349. u_int32_t reserved;
  350. struct l_fpxreg _fxsr_st[8]; /* reg data is ignored. */
  351. struct l_xmmreg _xmm[8];
  352. u_int32_t padding[56];
  353. };
  354. /*
  355. * We make the stack look like Linux expects it when calling a signal
  356. * handler, but use the BSD way of calling the handler and sigreturn().
  357. * This means that we need to pass the pointer to the handler too.
  358. * It is appended to the frame to not interfere with the rest of it.
  359. */
  360. struct l_sigframe {
  361. l_int sf_sig;
  362. struct l_sigcontext sf_sc;
  363. struct l_fpstate sf_fpstate;
  364. l_uint sf_extramask[LINUX_NSIG_WORDS-1];
  365. l_handler_t sf_handler;
  366. };
  367. struct l_rt_sigframe {
  368. l_int sf_sig;
  369. l_siginfo_t *sf_siginfo;
  370. struct l_ucontext *sf_ucontext;
  371. l_siginfo_t sf_si;
  372. struct l_ucontext sf_sc;
  373. l_handler_t sf_handler;
  374. };
  375. extern struct sysentvec linux_sysvec;
  376. /*
  377. * arch specific open/fcntl flags
  378. */
  379. #define LINUX_F_GETLK64 12
  380. #define LINUX_F_SETLK64 13
  381. #define LINUX_F_SETLKW64 14
  382. union l_semun {
  383. l_int val;
  384. l_uintptr_t buf;
  385. l_ushort *array;
  386. l_uintptr_t __buf;
  387. l_uintptr_t __pad;
  388. };
  389. struct l_ifmap {
  390. l_ulong mem_start;
  391. l_ulong mem_end;
  392. l_ushort base_addr;
  393. u_char irq;
  394. u_char dma;
  395. u_char port;
  396. };
  397. struct l_ifreq {
  398. union {
  399. char ifrn_name[LINUX_IFNAMSIZ];
  400. } ifr_ifrn;
  401. union {
  402. struct l_sockaddr ifru_addr;
  403. struct l_sockaddr ifru_dstaddr;
  404. struct l_sockaddr ifru_broadaddr;
  405. struct l_sockaddr ifru_netmask;
  406. struct l_sockaddr ifru_hwaddr;
  407. l_short ifru_flags[1];
  408. l_int ifru_ivalue;
  409. l_int ifru_mtu;
  410. struct l_ifmap ifru_map;
  411. char ifru_slave[LINUX_IFNAMSIZ];
  412. l_caddr_t ifru_data;
  413. } ifr_ifru;
  414. };
  415. #define ifr_name ifr_ifrn.ifrn_name /* Interface name */
  416. #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
  417. #define ifr_ifindex ifr_ifru.ifru_ivalue /* Interface index */
  418. /*
  419. * poll()
  420. */
  421. #define LINUX_POLLIN 0x0001
  422. #define LINUX_POLLPRI 0x0002
  423. #define LINUX_POLLOUT 0x0004
  424. #define LINUX_POLLERR 0x0008
  425. #define LINUX_POLLHUP 0x0010
  426. #define LINUX_POLLNVAL 0x0020
  427. #define LINUX_POLLRDNORM 0x0040
  428. #define LINUX_POLLRDBAND 0x0080
  429. #define LINUX_POLLWRNORM 0x0100
  430. #define LINUX_POLLWRBAND 0x0200
  431. #define LINUX_POLLMSG 0x0400
  432. struct l_pollfd {
  433. l_int fd;
  434. l_short events;
  435. l_short revents;
  436. };
  437. struct l_user_desc {
  438. l_uint entry_number;
  439. l_uint base_addr;
  440. l_uint limit;
  441. l_uint seg_32bit:1;
  442. l_uint contents:2;
  443. l_uint read_exec_only:1;
  444. l_uint limit_in_pages:1;
  445. l_uint seg_not_present:1;
  446. l_uint useable:1;
  447. };
  448. struct l_desc_struct {
  449. unsigned long a, b;
  450. };
  451. #define LINUX_LOWERWORD 0x0000ffff
  452. /*
  453. * Macros which does the same thing as those in Linux include/asm-um/ldt-i386.h.
  454. * These convert Linux user space descriptor to machine one.
  455. */
  456. #define LINUX_LDT_entry_a(info) \
  457. ((((info)->base_addr & LINUX_LOWERWORD) << 16) | \
  458. ((info)->limit & LINUX_LOWERWORD))
  459. #define LINUX_ENTRY_B_READ_EXEC_ONLY 9
  460. #define LINUX_ENTRY_B_CONTENTS 10
  461. #define LINUX_ENTRY_B_SEG_NOT_PRESENT 15
  462. #define LINUX_ENTRY_B_BASE_ADDR 16
  463. #define LINUX_ENTRY_B_USEABLE 20
  464. #define LINUX_ENTRY_B_SEG32BIT 22
  465. #define LINUX_ENTRY_B_LIMIT 23
  466. #define LINUX_LDT_entry_b(info) \
  467. (((info)->base_addr & 0xff000000) | \
  468. ((info)->limit & 0xf0000) | \
  469. ((info)->contents << LINUX_ENTRY_B_CONTENTS) | \
  470. (((info)->seg_not_present == 0) << LINUX_ENTRY_B_SEG_NOT_PRESENT) | \
  471. (((info)->base_addr & 0x00ff0000) >> LINUX_ENTRY_B_BASE_ADDR) | \
  472. (((info)->read_exec_only == 0) << LINUX_ENTRY_B_READ_EXEC_ONLY) | \
  473. ((info)->seg_32bit << LINUX_ENTRY_B_SEG32BIT) | \
  474. ((info)->useable << LINUX_ENTRY_B_USEABLE) | \
  475. ((info)->limit_in_pages << LINUX_ENTRY_B_LIMIT) | 0x7000)
  476. #define LINUX_LDT_empty(info) \
  477. ((info)->base_addr == 0 && \
  478. (info)->limit == 0 && \
  479. (info)->contents == 0 && \
  480. (info)->seg_not_present == 1 && \
  481. (info)->read_exec_only == 1 && \
  482. (info)->seg_32bit == 0 && \
  483. (info)->limit_in_pages == 0 && \
  484. (info)->useable == 0)
  485. /*
  486. * Macros for converting segments.
  487. * They do the same as those in arch/i386/kernel/process.c in Linux.
  488. */
  489. #define LINUX_GET_BASE(desc) \
  490. ((((desc)->a >> 16) & LINUX_LOWERWORD) | \
  491. (((desc)->b << 16) & 0x00ff0000) | \
  492. ((desc)->b & 0xff000000))
  493. #define LINUX_GET_LIMIT(desc) \
  494. (((desc)->a & LINUX_LOWERWORD) | \
  495. ((desc)->b & 0xf0000))
  496. #define LINUX_GET_32BIT(desc) \
  497. (((desc)->b >> LINUX_ENTRY_B_SEG32BIT) & 1)
  498. #define LINUX_GET_CONTENTS(desc) \
  499. (((desc)->b >> LINUX_ENTRY_B_CONTENTS) & 3)
  500. #define LINUX_GET_WRITABLE(desc) \
  501. (((desc)->b >> LINUX_ENTRY_B_READ_EXEC_ONLY) & 1)
  502. #define LINUX_GET_LIMIT_PAGES(desc) \
  503. (((desc)->b >> LINUX_ENTRY_B_LIMIT) & 1)
  504. #define LINUX_GET_PRESENT(desc) \
  505. (((desc)->b >> LINUX_ENTRY_B_SEG_NOT_PRESENT) & 1)
  506. #define LINUX_GET_USEABLE(desc) \
  507. (((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1)
  508. #define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r))
  509. /* robust futexes */
  510. struct linux_robust_list {
  511. struct linux_robust_list *next;
  512. };
  513. struct linux_robust_list_head {
  514. struct linux_robust_list list;
  515. l_long futex_offset;
  516. struct linux_robust_list *pending_list;
  517. };
  518. #endif /* !_I386_LINUX_H_ */