shim_types.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #ifndef _SHIM_TYPES_H_
  4. #define _SHIM_TYPES_H_
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #define __KERNEL__
  9. #include <linux/types.h>
  10. #include <linux/utsname.h>
  11. #include <linux/times.h>
  12. #include <linux/shm.h>
  13. #include <linux/msg.h>
  14. #include <linux/sem.h>
  15. #include <linux/kernel.h>
  16. #include <linux/utime.h>
  17. #include <linux/futex.h>
  18. #include <linux/aio_abi.h>
  19. #include <linux/perf_event.h>
  20. #include <linux/timex.h>
  21. #include <asm/posix_types.h>
  22. #include <asm/statfs.h>
  23. #include <asm/stat.h>
  24. #include <asm/ldt.h>
  25. #include <asm/signal.h>
  26. #include <asm/siginfo.h>
  27. #include <asm/poll.h>
  28. typedef unsigned int __u32;
  29. typedef unsigned long int nfds_t;
  30. typedef unsigned long int nlink_t;
  31. typedef __kernel_caddr_t caddr_t;
  32. typedef __kernel_mode_t mode_t;
  33. typedef __kernel_loff_t loff_t;
  34. typedef __kernel_time_t time_t;
  35. typedef __kernel_old_dev_t dev_t;
  36. typedef __kernel_ino_t ino_t;
  37. typedef __kernel_clockid_t clockid_t;
  38. typedef __kernel_key_t key_t;
  39. typedef __kernel_timer_t timer_t;
  40. typedef __kernel_fd_set fd_set;
  41. /* linux/time.h */
  42. struct __kernel_timespec {
  43. __kernel_time_t tv_sec; /* seconds */
  44. long tv_nsec; /* nanoseconds */
  45. };
  46. struct __kernel_timeval {
  47. __kernel_time_t tv_sec; /* seconds */
  48. __kernel_suseconds_t tv_usec; /* microsecond */
  49. };
  50. struct __kernel_itimerspec {
  51. struct __kernel_timespec it_interval; /* timer period */
  52. struct __kernel_timespec it_value; /* timer expiration */
  53. };
  54. struct __kernel_itimerval {
  55. struct __kernel_timeval it_interval; /* time interval */
  56. struct __kernel_timeval it_value; /* current value */
  57. };
  58. struct __kernel_timezone {
  59. int tz_minuteswest; /* minutes west of Greenwich */
  60. int tz_dsttime; /* type of dst correction */
  61. };
  62. /* linux/time.h
  63. * syscall interface - used (mainly by NTP daemon)
  64. * to discipline kernel clock oscillator
  65. */
  66. struct __kernel_timex {
  67. unsigned int modes; /* mode selector */
  68. long offset; /* time offset (usec) */
  69. long freq; /* frequency offset (scaled ppm) */
  70. long maxerror; /* maximum error (usec) */
  71. long esterror; /* estimated error (usec) */
  72. int status; /* clock command/status */
  73. long constant; /* pll time constant */
  74. long precision; /* clock precision (usec) (read only) */
  75. long tolerance; /* clock frequency tolerance (ppm)
  76. * (read only) */
  77. struct __kernel_timeval time; /* (read only) */
  78. long tick; /* (modified) usecs between clock ticks */
  79. long ppsfreq; /* pps frequency (scaled ppm) (ro) */
  80. long jitter; /* pps jitter (us) (ro) */
  81. int shift; /* interval duration (s) (shift) (ro) */
  82. long stabil; /* pps stability (scaled ppm) (ro) */
  83. long jitcnt; /* jitter limit exceeded (ro) */
  84. long calcnt; /* calibration intervals (ro) */
  85. long errcnt; /* calibration errors (ro) */
  86. long stbcnt; /* stability limit exceeded (ro) */
  87. int tai; /* TAI offset (ro) */
  88. int :32; int :32; int :32; int :32;
  89. int :32; int :32; int :32; int :32;
  90. int :32; int :32; int :32;
  91. };
  92. /* /arch/x86/include/asm/posix_types_64.h */
  93. typedef unsigned int __kernel_uid_t;
  94. typedef __kernel_uid_t __kernel_uid32_t;
  95. /* quota.h */
  96. typedef __kernel_uid32_t qid_t; /* Type in which we store ids in memory */
  97. /* capability.h */
  98. typedef struct __user_cap_header_struct {
  99. __u32 version;
  100. int pid;
  101. } *cap_user_header_t;
  102. typedef struct __user_cap_data_struct {
  103. __u32 effective;
  104. __u32 permitted;
  105. __u32 inheritable;
  106. } *cap_user_data_t;
  107. /* defined in function in sysdeps/unix/sysv/linux/sysctl.c */
  108. struct __kernel_sysctl_args {
  109. int *name; /* integer vector describing variable */
  110. int nlen; /* length of this vector */
  111. void *oldval; /* 0 or address where to store old value */
  112. size_t *oldlenp; /* available room for old value,
  113. overwritten by actual size of old value */
  114. void *newval; /* 0 or address of new value */
  115. size_t newlen; /* size of new value */
  116. };
  117. struct __kernel_sched_param {
  118. int __sched_priority;
  119. };
  120. struct __kernel_sigaction {
  121. __sighandler_t k_sa_handler;
  122. unsigned long sa_flags;
  123. void (*sa_restorer) (void);
  124. sigset_t sa_mask;
  125. };
  126. /* linux/aio_abi.h (for io_setup which has no glibc wrapper) */
  127. typedef unsigned long aio_context_t;
  128. /* asm/signal.h */
  129. #define NUM_SIGS 64
  130. #define NUM_KNOWN_SIGS 32
  131. typedef struct {
  132. unsigned long __val[NUM_SIGS / (8 * sizeof(unsigned long))];
  133. } __sigset_t;
  134. /* linux/rlimit.h */
  135. struct __kernel_rusage {
  136. struct __kernel_timeval ru_utime; /* user time used */
  137. struct __kernel_timeval ru_stime; /* system time used */
  138. long ru_maxrss; /* maximum resident set size */
  139. long ru_ixrss; /* integral shared memory size */
  140. long ru_idrss; /* integral unshared data size */
  141. long ru_isrss; /* integral unshared stack size */
  142. long ru_minflt; /* page reclaims */
  143. long ru_majflt; /* page faults */
  144. long ru_nswap; /* swaps */
  145. long ru_inblock; /* block input operations */
  146. long ru_oublock; /* block output operations */
  147. long ru_msgsnd; /* messages sent */
  148. long ru_msgrcv; /* messages received */
  149. long ru_nsignals; /* signals received */
  150. long ru_nvcsw; /* voluntary context switches */
  151. long ru_nivcsw; /* involuntary " */
  152. };
  153. struct __kernel_rlimit {
  154. unsigned long rlim_cur, rlim_max;
  155. };
  156. struct __kernel_rlimit64 {
  157. uint64_t rlim_cur, rlim_max;
  158. };
  159. /* linux/eventpoll.h
  160. * On x86-64 make the 64bit structure have the same alignment as the
  161. * 32bit structure. This makes 32bit emulation easier.
  162. *
  163. * UML/x86_64 needs the same packing as x86_64
  164. */
  165. struct __kernel_epoll_event {
  166. __u32 events;
  167. __u64 data;
  168. }
  169. #ifdef __x86_64__
  170. __attribute__((packed));
  171. #else
  172. ;
  173. #endif
  174. /* sys/ucontext.h */
  175. /* Type for general register. */
  176. typedef long int greg_t;
  177. /* Number of general registers. */
  178. #define NGREG 23
  179. /* Container for all general registers. */
  180. typedef greg_t gregset_t[NGREG];
  181. /* Number of each register in the `gregset_t' array. */
  182. enum
  183. {
  184. REG_R8 = 0,
  185. # define REG_R8 REG_R8
  186. REG_R9,
  187. # define REG_R9 REG_R9
  188. REG_R10,
  189. # define REG_R10 REG_R10
  190. REG_R11,
  191. # define REG_R11 REG_R11
  192. REG_R12,
  193. # define REG_R12 REG_R12
  194. REG_R13,
  195. # define REG_R13 REG_R13
  196. REG_R14,
  197. # define REG_R14 REG_R14
  198. REG_R15,
  199. # define REG_R15 REG_R15
  200. REG_RDI,
  201. # define REG_RDI REG_RDI
  202. REG_RSI,
  203. # define REG_RSI REG_RSI
  204. REG_RBP,
  205. # define REG_RBP REG_RBP
  206. REG_RBX,
  207. # define REG_RBX REG_RBX
  208. REG_RDX,
  209. # define REG_RDX REG_RDX
  210. REG_RAX,
  211. # define REG_RAX REG_RAX
  212. REG_RCX,
  213. # define REG_RCX REG_RCX
  214. REG_RSP,
  215. # define REG_RSP REG_RSP
  216. REG_RIP,
  217. # define REG_RIP REG_RIP
  218. REG_EFL,
  219. # define REG_EFL REG_EFL
  220. REG_CSGSFS, /* Actually short cs, gs, fs, __pad0. */
  221. # define REG_CSGSFS REG_CSGSFS
  222. REG_ERR,
  223. # define REG_ERR REG_ERR
  224. REG_TRAPNO,
  225. # define REG_TRAPNO REG_TRAPNO
  226. REG_OLDMASK,
  227. # define REG_OLDMASK REG_OLDMASK
  228. REG_CR2
  229. # define REG_CR2 REG_CR2
  230. };
  231. struct _libc_fpxreg {
  232. unsigned short int significand[4];
  233. unsigned short int exponent;
  234. unsigned short int padding[3];
  235. };
  236. struct _libc_xmmreg {
  237. __uint32_t element[4];
  238. };
  239. struct _libc_fpstate {
  240. /* 64-bit FXSAVE format. */
  241. __uint16_t cwd;
  242. __uint16_t swd;
  243. __uint16_t ftw;
  244. __uint16_t fop;
  245. __uint64_t rip;
  246. __uint64_t rdp;
  247. __uint32_t mxcsr;
  248. __uint32_t mxcr_mask;
  249. struct _libc_fpxreg st[8];
  250. struct _libc_xmmreg _xmm[16];
  251. __uint32_t padding[24];
  252. };
  253. /* Structure to describe FPU registers. */
  254. typedef struct _libc_fpstate *fpregset_t;
  255. /* Context to describe whole processor state. */
  256. typedef struct {
  257. gregset_t gregs;
  258. /* Note that fpregs is a pointer. */
  259. fpregset_t fpregs;
  260. unsigned long __reserved1 [8];
  261. } mcontext_t;
  262. /* Userlevel context. */
  263. typedef struct ucontext {
  264. unsigned long int uc_flags;
  265. struct ucontext *uc_link;
  266. stack_t uc_stack;
  267. mcontext_t uc_mcontext;
  268. __sigset_t uc_sigmask;
  269. struct _libc_fpstate __fpregs_mem;
  270. } ucontext_t;
  271. /* bits/ustat.h */
  272. struct __kernel_ustat
  273. {
  274. __daddr_t f_tfree; /* Number of free blocks. */
  275. __ino_t f_tinode; /* Number of free inodes. */
  276. char f_fname[6];
  277. char f_fpack[6];
  278. };
  279. /* bits/socket.h */
  280. struct msghdr {
  281. void *msg_name; /* Address to send to/receive from. */
  282. socklen_t msg_namelen; /* Length of address data. */
  283. struct iovec *msg_iov; /* Vector of data to send/receive into. */
  284. size_t msg_iovlen; /* Number of elements in the vector. */
  285. void *msg_control; /* Ancillary data (eg BSD filedesc passing). */
  286. size_t msg_controllen; /* Ancillary data buffer length.
  287. !! The type should be socklen_t but the
  288. definition of the kernel is incompatible
  289. with this. */
  290. int msg_flags; /* Flags on received message. */
  291. };
  292. /* For `recvmmsg'. */
  293. struct mmsghdr {
  294. struct msghdr msg_hdr; /* Actual message header. */
  295. unsigned int msg_len; /* Number of received bytes for the entry. */
  296. };
  297. /* POSIX.1g specifies this type name for the `sa_family' member. */
  298. typedef unsigned short int sa_family_t;
  299. /* This macro is used to declare the initial common members
  300. of the data types used for socket addresses, `struct sockaddr',
  301. `struct sockaddr_in', `struct sockaddr_un', etc. */
  302. #define __SOCKADDR_COMMON(sa_prefix) \
  303. sa_family_t sa_prefix##family
  304. /* Structure describing a generic socket address. */
  305. struct sockaddr {
  306. __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
  307. char sa_data[14]; /* Address data. */
  308. };
  309. /* linux/mqueue.h */
  310. struct __kernel_mq_attr {
  311. long mq_flags; /* message queue flags */
  312. long mq_maxmsg; /* maximum number of messages */
  313. long mq_msgsize; /* maximum message size */
  314. long mq_curmsgs; /* number of messages currently queued */
  315. long __reserved[4]; /* ignored for input, zeroed for output */
  316. };
  317. /* bits/uio.h */
  318. /* Structure for scatter/gather I/O. */
  319. struct iovec {
  320. void * iov_base; /* Pointer to data. */
  321. size_t iov_len; /* Length of data. */
  322. };
  323. /* bits/sched.h */
  324. /* Type for array elements in 'cpu_set_t'. */
  325. typedef unsigned long int __kernel_cpu_mask;
  326. /* Size definition for CPU sets. */
  327. # define __CPU_SETSIZE 1024
  328. # define __NCPUBITS (8 * sizeof (__kernel_cpu_mask))
  329. /* Data structure to describe CPU mask. */
  330. typedef struct {
  331. __kernel_cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
  332. } __kernel_cpu_set_t;
  333. struct getcpu_cache {
  334. unsigned long blob[128 / sizeof(long)];
  335. };
  336. # undef __CPU_SETSIZE
  337. # undef __NCPUBITS
  338. #define LINUX_DT_UNKNOWN 0
  339. #define LINUX_DT_FIFO 1
  340. #define LINUX_DT_CHR 2
  341. #define LINUX_DT_DIR 4
  342. #define LINUX_DT_BLK 6
  343. #define LINUX_DT_REG 8
  344. #define LINUX_DT_LNK 10
  345. #define LINUX_DT_SOCK 12
  346. #define LINUX_DT_WHT 14
  347. struct linux_dirent64 {
  348. uint64_t d_ino; /* Inode number */
  349. uint64_t d_off; /* Offset to next linux_dirent */
  350. unsigned short int d_reclen; /* Length of this linux_dirent */
  351. unsigned char d_type;
  352. char d_name[]; /* File name (null-terminated) */
  353. };
  354. struct linux_dirent {
  355. unsigned long d_ino; /* Inode number */
  356. unsigned long d_off; /* Offset to next linux_dirent */
  357. unsigned short int d_reclen; /* Length of this linux_dirent */
  358. char d_name[]; /* File name (null-terminated) */
  359. };
  360. struct linux_dirent_tail {
  361. char pad;
  362. unsigned char d_type;
  363. };
  364. struct linux_file_handle {
  365. unsigned int handle_bytes;
  366. int handle_type;
  367. unsigned char f_handle[0];
  368. };
  369. struct __kernel_addrinfo
  370. {
  371. int ai_flags; /* Input flags. */
  372. int ai_family; /* Protocol family for socket. */
  373. int ai_socktype; /* Socket type. */
  374. int ai_protocol; /* Protocol for socket. */
  375. socklen_t ai_addrlen; /* Length of socket address. */
  376. struct sockaddr *ai_addr; /* Socket address for socket. */
  377. char *ai_canonname; /* Canonical name for service location. */
  378. struct addrinfo *ai_next; /* Pointer to next in list. */
  379. };
  380. #include "elf.h"
  381. #ifdef __x86_64__
  382. typedef Elf64_auxv_t elf_auxv_t;
  383. #else
  384. typedef Elf64_auxv_t elf_auxv_t;
  385. #endif
  386. /* typedef for shim internal types */
  387. typedef unsigned int IDTYPE;
  388. typedef uint16_t FDTYPE;
  389. typedef unsigned long LEASETYPE;
  390. typedef unsigned long HASHTYPE;
  391. typedef struct atomic_int REFTYPE;
  392. #include <pal.h>
  393. typedef struct shim_lock {
  394. PAL_HANDLE lock;
  395. IDTYPE owner;
  396. } LOCKTYPE;
  397. typedef struct shim_aevent {
  398. PAL_HANDLE event;
  399. } AEVENTTYPE;
  400. #define STR_SIZE 256
  401. struct shim_str {
  402. char str[STR_SIZE];
  403. };
  404. #define QSTR_SIZE 32
  405. /* Use qstr for names. This has fixed size string + string object
  406. * if len > SHIM_QSTR_SIZE then use overflow string */
  407. struct shim_qstr {
  408. HASHTYPE hash;
  409. size_t len;
  410. char name[QSTR_SIZE];
  411. struct shim_str * oflow;
  412. };
  413. #endif /* _SHIM_TYPES_H_ */