shim_types.h 14 KB

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