UnixTypes.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/DistinctNumeric.h>
  8. #include <AK/Types.h>
  9. #include <Kernel/API/POSIX/fcntl.h>
  10. #include <Kernel/API/POSIX/futex.h>
  11. #include <Kernel/API/POSIX/netinet/in.h>
  12. #include <Kernel/API/POSIX/signal.h>
  13. #include <Kernel/API/POSIX/sys/mman.h>
  14. #include <Kernel/API/POSIX/sys/socket.h>
  15. #include <Kernel/API/POSIX/sys/stat.h>
  16. #include <Kernel/API/POSIX/sys/un.h>
  17. #include <Kernel/API/POSIX/termios.h>
  18. #include <Kernel/API/POSIX/time.h>
  19. // Kernel internal options.
  20. #define O_NOFOLLOW_NOERROR (1 << 29)
  21. #define O_UNLINK_INTERNAL (1 << 30)
  22. #define MS_NODEV (1 << 0)
  23. #define MS_NOEXEC (1 << 1)
  24. #define MS_NOSUID (1 << 2)
  25. #define MS_BIND (1 << 3)
  26. #define MS_RDONLY (1 << 4)
  27. #define MS_REMOUNT (1 << 5)
  28. enum {
  29. _SC_MONOTONIC_CLOCK,
  30. _SC_NPROCESSORS_CONF,
  31. _SC_NPROCESSORS_ONLN,
  32. _SC_OPEN_MAX,
  33. _SC_TTY_NAME_MAX,
  34. _SC_PAGESIZE,
  35. _SC_GETPW_R_SIZE_MAX,
  36. _SC_CLK_TCK,
  37. };
  38. enum {
  39. PERF_EVENT_SAMPLE = 1,
  40. PERF_EVENT_MALLOC = 2,
  41. PERF_EVENT_FREE = 4,
  42. PERF_EVENT_MMAP = 8,
  43. PERF_EVENT_MUNMAP = 16,
  44. PERF_EVENT_PROCESS_CREATE = 32,
  45. PERF_EVENT_PROCESS_EXEC = 64,
  46. PERF_EVENT_PROCESS_EXIT = 128,
  47. PERF_EVENT_THREAD_CREATE = 256,
  48. PERF_EVENT_THREAD_EXIT = 512,
  49. PERF_EVENT_CONTEXT_SWITCH = 1024,
  50. PERF_EVENT_KMALLOC = 2048,
  51. PERF_EVENT_KFREE = 4096,
  52. PERF_EVENT_PAGE_FAULT = 8192,
  53. PERF_EVENT_SYSCALL = 16384,
  54. PERF_EVENT_SIGNPOST = 32768,
  55. };
  56. #define WNOHANG 1
  57. #define WUNTRACED 2
  58. #define WSTOPPED WUNTRACED
  59. #define WEXITED 4
  60. #define WCONTINUED 8
  61. #define WNOWAIT 0x1000000
  62. #define R_OK 4
  63. #define W_OK 2
  64. #define X_OK 1
  65. #define F_OK 0
  66. #define SEEK_SET 0
  67. #define SEEK_CUR 1
  68. #define SEEK_END 2
  69. #define MADV_SET_VOLATILE 0x100
  70. #define MADV_SET_NONVOLATILE 0x200
  71. #define F_DUPFD 0
  72. #define F_GETFD 1
  73. #define F_SETFD 2
  74. #define F_GETFL 3
  75. #define F_SETFL 4
  76. #define F_ISTTY 5
  77. #define F_GETLK 6
  78. #define F_SETLK 7
  79. #define F_SETLKW 8
  80. #define FD_CLOEXEC 1
  81. // Avoid interference with AK/Types.h and LibC/sys/types.h by defining *separate* names:
  82. TYPEDEF_DISTINCT_ORDERED_ID(pid_t, ProcessID);
  83. TYPEDEF_DISTINCT_ORDERED_ID(pid_t, ThreadID);
  84. TYPEDEF_DISTINCT_ORDERED_ID(pid_t, SessionID);
  85. TYPEDEF_DISTINCT_ORDERED_ID(pid_t, ProcessGroupID);
  86. struct tms {
  87. clock_t tms_utime;
  88. clock_t tms_stime;
  89. clock_t tms_cutime;
  90. clock_t tms_cstime;
  91. };
  92. typedef i64 off_t;
  93. typedef i64 time_t;
  94. typedef u32 blksize_t;
  95. typedef u32 blkcnt_t;
  96. #define POLLIN (1u << 0)
  97. #define POLLPRI (1u << 1)
  98. #define POLLOUT (1u << 2)
  99. #define POLLERR (1u << 3)
  100. #define POLLHUP (1u << 4)
  101. #define POLLNVAL (1u << 5)
  102. #define POLLRDHUP (1u << 13)
  103. struct pollfd {
  104. int fd;
  105. short events;
  106. short revents;
  107. };
  108. typedef u32 __u32;
  109. typedef u16 __u16;
  110. typedef u8 __u8;
  111. typedef int __s32;
  112. typedef short __s16;
  113. typedef u32 useconds_t;
  114. typedef i32 suseconds_t;
  115. struct timeval {
  116. time_t tv_sec;
  117. suseconds_t tv_usec;
  118. };
  119. typedef enum {
  120. P_ALL = 1,
  121. P_PID,
  122. P_PGID
  123. } idtype_t;
  124. #define UTSNAME_ENTRY_LEN 65
  125. struct utsname {
  126. char sysname[UTSNAME_ENTRY_LEN];
  127. char nodename[UTSNAME_ENTRY_LEN];
  128. char release[UTSNAME_ENTRY_LEN];
  129. char version[UTSNAME_ENTRY_LEN];
  130. char machine[UTSNAME_ENTRY_LEN];
  131. };
  132. struct iovec {
  133. void* iov_base;
  134. size_t iov_len;
  135. };
  136. struct sched_param {
  137. int sched_priority;
  138. };
  139. struct ifreq {
  140. #define IFNAMSIZ 16
  141. char ifr_name[IFNAMSIZ];
  142. union {
  143. struct sockaddr ifru_addr;
  144. struct sockaddr ifru_dstaddr;
  145. struct sockaddr ifru_broadaddr;
  146. struct sockaddr ifru_netmask;
  147. struct sockaddr ifru_hwaddr;
  148. short ifru_flags;
  149. int ifru_metric;
  150. int64_t ifru_vnetid;
  151. uint64_t ifru_media;
  152. void* ifru_data;
  153. unsigned int ifru_index;
  154. } ifr_ifru;
  155. #define ifr_addr ifr_ifru.ifru_addr // address
  156. #define ifr_dstaddr ifr_ifru.ifru_dstaddr // other end of p-to-p link
  157. #define ifr_broadaddr ifr_ifru.ifru_broadaddr // broadcast address
  158. #define ifr_netmask ifr_ifru.ifru_netmask // network mask
  159. #define ifr_flags ifr_ifru.ifru_flags // flags
  160. #define ifr_metric ifr_ifru.ifru_metric // metric
  161. #define ifr_mtu ifr_ifru.ifru_metric // mtu (overload)
  162. #define ifr_hardmtu ifr_ifru.ifru_metric // hardmtu (overload)
  163. #define ifr_media ifr_ifru.ifru_media // media options
  164. #define ifr_rdomainid ifr_ifru.ifru_metric // VRF instance (overload)
  165. #define ifr_vnetid ifr_ifru.ifru_vnetid // Virtual Net Id
  166. #define ifr_ttl ifr_ifru.ifru_metric // tunnel TTL (overload)
  167. #define ifr_data ifr_ifru.ifru_data // for use by interface
  168. #define ifr_index ifr_ifru.ifru_index // interface index
  169. #define ifr_llprio ifr_ifru.ifru_metric // link layer priority
  170. #define ifr_hwaddr ifr_ifru.ifru_hwaddr // MAC address
  171. };
  172. struct rtentry {
  173. struct sockaddr rt_gateway; /* the gateway address */
  174. struct sockaddr rt_genmask; /* the target network mask */
  175. unsigned short int rt_flags;
  176. char* rt_dev;
  177. /* FIXME: complete the struct */
  178. };
  179. #define RTF_UP 0x1 /* do not delete the route */
  180. #define RTF_GATEWAY 0x2 /* the route is a gateway and not an end host */
  181. #define AT_FDCWD -100
  182. #define AT_SYMLINK_NOFOLLOW 0x100
  183. struct arpreq {
  184. struct sockaddr arp_pa; /* protocol address */
  185. struct sockaddr arp_ha; /* hardware address */
  186. struct sockaddr arp_netmask; /* netmask of protocol address */
  187. int arp_flags; /* flags */
  188. char arp_dev[16];
  189. };
  190. #define PURGE_ALL_VOLATILE 0x1
  191. #define PURGE_ALL_CLEAN_INODE 0x2
  192. #define PT_TRACE_ME 1
  193. #define PT_ATTACH 2
  194. #define PT_CONTINUE 3
  195. #define PT_SYSCALL 4
  196. #define PT_GETREGS 5
  197. #define PT_DETACH 6
  198. #define PT_PEEK 7
  199. #define PT_POKE 8
  200. #define PT_SETREGS 9
  201. #define PT_POKEDEBUG 10
  202. #define PT_PEEKDEBUG 11
  203. // Used in struct dirent
  204. enum {
  205. DT_UNKNOWN = 0,
  206. #define DT_UNKNOWN DT_UNKNOWN
  207. DT_FIFO = 1,
  208. #define DT_FIFO DT_FIFO
  209. DT_CHR = 2,
  210. #define DT_CHR DT_CHR
  211. DT_DIR = 4,
  212. #define DT_DIR DT_DIR
  213. DT_BLK = 6,
  214. #define DT_BLK DT_BLK
  215. DT_REG = 8,
  216. #define DT_REG DT_REG
  217. DT_LNK = 10,
  218. #define DT_LNK DT_LNK
  219. DT_SOCK = 12,
  220. #define DT_SOCK DT_SOCK
  221. DT_WHT = 14
  222. #define DT_WHT DT_WHT
  223. };
  224. typedef uint64_t fsblkcnt_t;
  225. typedef uint64_t fsfilcnt_t;
  226. #define ST_RDONLY 0x1
  227. #define ST_NOSUID 0x2
  228. struct statvfs {
  229. unsigned long f_bsize;
  230. unsigned long f_frsize;
  231. fsblkcnt_t f_blocks;
  232. fsblkcnt_t f_bfree;
  233. fsblkcnt_t f_bavail;
  234. fsfilcnt_t f_files;
  235. fsfilcnt_t f_ffree;
  236. fsfilcnt_t f_favail;
  237. unsigned long f_fsid;
  238. unsigned long f_flag;
  239. unsigned long f_namemax;
  240. };