UnixTypes.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <AK/Types.h>
  28. #define PERF_EVENT_MALLOC 1
  29. #define PERF_EVENT_FREE 2
  30. #define WNOHANG 1
  31. #define WUNTRACED 2
  32. #define WSTOPPED WUNTRACED
  33. #define WEXITED 4
  34. #define WCONTINUED 8
  35. #define R_OK 4
  36. #define W_OK 2
  37. #define X_OK 1
  38. #define F_OK 0
  39. #define SIG_DFL ((void*)0)
  40. #define SIG_ERR ((void*)-1)
  41. #define SIG_IGN ((void*)1)
  42. #define SEEK_SET 0
  43. #define SEEK_CUR 1
  44. #define SEEK_END 2
  45. #define MAP_SHARED 0x01
  46. #define MAP_PRIVATE 0x02
  47. #define MAP_FIXED 0x10
  48. #define MAP_ANONYMOUS 0x20
  49. #define MAP_ANON MAP_ANONYMOUS
  50. #define MAP_STACK 0x40
  51. #define MAP_PURGEABLE 0x80
  52. #define PROT_READ 0x1
  53. #define PROT_WRITE 0x2
  54. #define PROT_EXEC 0x4
  55. #define PROT_NONE 0x0
  56. #define MADV_SET_VOLATILE 0x100
  57. #define MADV_SET_NONVOLATILE 0x200
  58. #define MADV_GET_VOLATILE 0x400
  59. #define F_DUPFD 0
  60. #define F_GETFD 1
  61. #define F_SETFD 2
  62. #define F_GETFL 3
  63. #define F_SETFL 4
  64. #define FD_CLOEXEC 1
  65. #define FUTEX_WAIT 1
  66. #define FUTEX_WAKE 2
  67. /* c_cc characters */
  68. #define VINTR 0
  69. #define VQUIT 1
  70. #define VERASE 2
  71. #define VKILL 3
  72. #define VEOF 4
  73. #define VTIME 5
  74. #define VMIN 6
  75. #define VSWTC 7
  76. #define VSTART 8
  77. #define VSTOP 9
  78. #define VSUSP 10
  79. #define VEOL 11
  80. #define VREPRINT 12
  81. #define VDISCARD 13
  82. #define VWERASE 14
  83. #define VLNEXT 15
  84. #define VEOL2 16
  85. /* c_iflag bits */
  86. #define IGNBRK 0000001
  87. #define BRKINT 0000002
  88. #define IGNPAR 0000004
  89. #define PARMRK 0000010
  90. #define INPCK 0000020
  91. #define ISTRIP 0000040
  92. #define INLCR 0000100
  93. #define IGNCR 0000200
  94. #define ICRNL 0000400
  95. #define IUCLC 0001000
  96. #define IXON 0002000
  97. #define IXANY 0004000
  98. #define IXOFF 0010000
  99. #define IMAXBEL 0020000
  100. #define IUTF8 0040000
  101. /* c_oflag bits */
  102. #define OPOST 0000001
  103. #define OLCUC 0000002
  104. #define ONLCR 0000004
  105. #define OCRNL 0000010
  106. #define ONOCR 0000020
  107. #define ONLRET 0000040
  108. #define OFILL 0000100
  109. #define OFDEL 0000200
  110. #if defined __USE_MISC || defined __USE_XOPEN
  111. # define NLDLY 0000400
  112. # define NL0 0000000
  113. # define NL1 0000400
  114. # define CRDLY 0003000
  115. # define CR0 0000000
  116. # define CR1 0001000
  117. # define CR2 0002000
  118. # define CR3 0003000
  119. # define TABDLY 0014000
  120. # define TAB0 0000000
  121. # define TAB1 0004000
  122. # define TAB2 0010000
  123. # define TAB3 0014000
  124. # define BSDLY 0020000
  125. # define BS0 0000000
  126. # define BS1 0020000
  127. # define FFDLY 0100000
  128. # define FF0 0000000
  129. # define FF1 0100000
  130. #endif
  131. #define VTDLY 0040000
  132. #define VT0 0000000
  133. #define VT1 0040000
  134. #ifdef __USE_MISC
  135. # define XTABS 0014000
  136. #endif
  137. /* c_cflag bit meaning */
  138. #ifdef __USE_MISC
  139. # define CBAUD 0010017
  140. #endif
  141. #define B0 0000000 /* hang up */
  142. #define B50 0000001
  143. #define B75 0000002
  144. #define B110 0000003
  145. #define B134 0000004
  146. #define B150 0000005
  147. #define B200 0000006
  148. #define B300 0000007
  149. #define B600 0000010
  150. #define B1200 0000011
  151. #define B1800 0000012
  152. #define B2400 0000013
  153. #define B4800 0000014
  154. #define B9600 0000015
  155. #define B19200 0000016
  156. #define B38400 0000017
  157. #ifdef __USE_MISC
  158. # define EXTA B19200
  159. # define EXTB B38400
  160. #endif
  161. #define CSIZE 0000060
  162. #define CS5 0000000
  163. #define CS6 0000020
  164. #define CS7 0000040
  165. #define CS8 0000060
  166. #define CSTOPB 0000100
  167. #define CREAD 0000200
  168. #define PARENB 0000400
  169. #define PARODD 0001000
  170. #define HUPCL 0002000
  171. #define CLOCAL 0004000
  172. #ifdef __USE_MISC
  173. # define CBAUDEX 0010000
  174. #endif
  175. #define B57600 0010001
  176. #define B115200 0010002
  177. #define B230400 0010003
  178. #define B460800 0010004
  179. #define B500000 0010005
  180. #define B576000 0010006
  181. #define B921600 0010007
  182. #define B1000000 0010010
  183. #define B1152000 0010011
  184. #define B1500000 0010012
  185. #define B2000000 0010013
  186. #define B2500000 0010014
  187. #define B3000000 0010015
  188. #define B3500000 0010016
  189. #define B4000000 0010017
  190. #define __MAX_BAUD B4000000
  191. #ifdef __USE_MISC
  192. # define CIBAUD 002003600000 /* input baud rate (not used) */
  193. # define CMSPAR 010000000000 /* mark or space (stick) parity */
  194. # define CRTSCTS 020000000000 /* flow control */
  195. #endif
  196. /* c_lflag bits */
  197. #define ISIG 0000001
  198. #define ICANON 0000002
  199. #if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
  200. # define XCASE 0000004
  201. #endif
  202. #define ECHO 0000010
  203. #define ECHOE 0000020
  204. #define ECHOK 0000040
  205. #define ECHONL 0000100
  206. #define NOFLSH 0000200
  207. #define TOSTOP 0000400
  208. #ifdef __USE_MISC
  209. # define ECHOCTL 0001000
  210. # define ECHOPRT 0002000
  211. # define ECHOKE 0004000
  212. # define FLUSHO 0010000
  213. # define PENDIN 0040000
  214. #endif
  215. #define IEXTEN 0100000
  216. #ifdef __USE_MISC
  217. # define EXTPROC 0200000
  218. #endif
  219. /* tcflow() and TCXONC use these */
  220. #define TCOOFF 0
  221. #define TCOON 1
  222. #define TCIOFF 2
  223. #define TCION 3
  224. /* tcflush() and TCFLSH use these */
  225. #define TCIFLUSH 0
  226. #define TCOFLUSH 1
  227. #define TCIOFLUSH 2
  228. /* tcsetattr uses these */
  229. #define TCSANOW 0
  230. #define TCSADRAIN 1
  231. #define TCSAFLUSH 2
  232. typedef u32 dev_t;
  233. typedef u32 ino_t;
  234. typedef u16 mode_t;
  235. typedef u32 nlink_t;
  236. typedef u32 uid_t;
  237. typedef u32 gid_t;
  238. typedef u32 clock_t;
  239. typedef u32 socklen_t;
  240. typedef int pid_t;
  241. struct tms {
  242. clock_t tms_utime;
  243. clock_t tms_stime;
  244. clock_t tms_cutime;
  245. clock_t tms_cstime;
  246. };
  247. typedef void (*__sighandler_t)(int);
  248. typedef __sighandler_t sighandler_t;
  249. typedef u32 sigset_t;
  250. union sigval {
  251. int sival_int;
  252. void* sival_ptr;
  253. };
  254. typedef struct siginfo {
  255. int si_signo;
  256. int si_code;
  257. pid_t si_pid;
  258. uid_t si_uid;
  259. void* si_addr;
  260. int si_status;
  261. union sigval si_value;
  262. } siginfo_t;
  263. struct sigaction {
  264. union {
  265. void (*sa_handler)(int);
  266. void (*sa_sigaction)(int, siginfo_t*, void*);
  267. };
  268. sigset_t sa_mask;
  269. int sa_flags;
  270. };
  271. #define SA_NOCLDSTOP 1
  272. #define SA_NOCLDWAIT 2
  273. #define SA_SIGINFO 4
  274. #define SA_NODEFER 0x40000000
  275. #define SIG_BLOCK 0
  276. #define SIG_UNBLOCK 1
  277. #define SIG_SETMASK 2
  278. #define CLD_EXITED 0
  279. #define CLD_KILLED 1
  280. #define CLD_DUMPED 2
  281. #define CLD_TRAPPED 3
  282. #define CLD_STOPPED 4
  283. #define CLD_CONTINUED 5
  284. #define OFF_T_MAX 2147483647
  285. typedef i32 off_t;
  286. typedef i64 time_t;
  287. struct utimbuf {
  288. time_t actime;
  289. time_t modtime;
  290. };
  291. typedef u32 blksize_t;
  292. typedef u32 blkcnt_t;
  293. #define NCCS 32
  294. typedef uint32_t tcflag_t;
  295. typedef uint8_t cc_t;
  296. typedef uint32_t speed_t;
  297. struct termios {
  298. tcflag_t c_iflag;
  299. tcflag_t c_oflag;
  300. tcflag_t c_cflag;
  301. tcflag_t c_lflag;
  302. cc_t c_cc[NCCS];
  303. speed_t c_ispeed;
  304. speed_t c_ospeed;
  305. };
  306. struct stat {
  307. dev_t st_dev; /* ID of device containing file */
  308. ino_t st_ino; /* inode number */
  309. mode_t st_mode; /* protection */
  310. nlink_t st_nlink; /* number of hard links */
  311. uid_t st_uid; /* user ID of owner */
  312. gid_t st_gid; /* group ID of owner */
  313. dev_t st_rdev; /* device ID (if special file) */
  314. off_t st_size; /* total size, in bytes */
  315. blksize_t st_blksize; /* blocksize for file system I/O */
  316. blkcnt_t st_blocks; /* number of 512B blocks allocated */
  317. time_t st_atime; /* time of last access */
  318. time_t st_mtime; /* time of last modification */
  319. time_t st_ctime; /* time of last status change */
  320. };
  321. #define POLLIN (1u << 0)
  322. #define POLLPRI (1u << 2)
  323. #define POLLOUT (1u << 3)
  324. #define POLLERR (1u << 4)
  325. #define POLLHUP (1u << 5)
  326. #define POLLNVAL (1u << 6)
  327. struct pollfd {
  328. int fd;
  329. short events;
  330. short revents;
  331. };
  332. #define AF_MASK 0xff
  333. #define AF_UNSPEC 0
  334. #define AF_LOCAL 1
  335. #define AF_INET 2
  336. #define PF_LOCAL AF_LOCAL
  337. #define PF_INET AF_INET
  338. #define SOCK_TYPE_MASK 0xff
  339. #define SOCK_STREAM 1
  340. #define SOCK_RAW 3
  341. #define SOCK_DGRAM 2
  342. #define SOCK_NONBLOCK 04000
  343. #define SOCK_CLOEXEC 02000000
  344. #define SHUT_RD 1
  345. #define SHUT_WR 2
  346. #define SHUT_RDWR 3
  347. #define MSG_DONTWAIT 0x40
  348. #define SOL_SOCKET 1
  349. #define SO_RCVTIMEO 1
  350. #define SO_SNDTIMEO 2
  351. #define SO_KEEPALIVE 3
  352. #define SO_ERROR 4
  353. #define SO_PEERCRED 5
  354. #define SO_REUSEADDR 6
  355. #define IPPROTO_IP 0
  356. #define IPPROTO_ICMP 1
  357. #define IPPROTO_TCP 6
  358. #define IPPROTO_UDP 17
  359. #define IP_TTL 2
  360. struct ucred {
  361. pid_t pid;
  362. uid_t uid;
  363. gid_t gid;
  364. };
  365. struct sockaddr {
  366. u16 sa_family;
  367. char sa_data[14];
  368. };
  369. #define S_IFSOCK 0140000
  370. #define UNIX_PATH_MAX 108
  371. struct sockaddr_un {
  372. u16 sun_family;
  373. char sun_path[UNIX_PATH_MAX];
  374. };
  375. struct in_addr {
  376. uint32_t s_addr;
  377. };
  378. struct sockaddr_in {
  379. int16_t sin_family;
  380. uint16_t sin_port;
  381. struct in_addr sin_addr;
  382. char sin_zero[8];
  383. };
  384. typedef u32 __u32;
  385. typedef u16 __u16;
  386. typedef u8 __u8;
  387. typedef int __s32;
  388. typedef short __s16;
  389. typedef u32 useconds_t;
  390. typedef i32 suseconds_t;
  391. struct timeval {
  392. time_t tv_sec;
  393. suseconds_t tv_usec;
  394. };
  395. struct timespec {
  396. time_t tv_sec;
  397. long tv_nsec;
  398. };
  399. typedef enum {
  400. P_ALL = 1,
  401. P_PID,
  402. P_PGID
  403. } idtype_t;
  404. typedef int clockid_t;
  405. #define CLOCK_REALTIME 0
  406. #define CLOCK_MONOTONIC 1
  407. #define TIMER_ABSTIME 99
  408. #define UTSNAME_ENTRY_LEN 65
  409. struct utsname {
  410. char sysname[UTSNAME_ENTRY_LEN];
  411. char nodename[UTSNAME_ENTRY_LEN];
  412. char release[UTSNAME_ENTRY_LEN];
  413. char version[UTSNAME_ENTRY_LEN];
  414. char machine[UTSNAME_ENTRY_LEN];
  415. };
  416. struct [[gnu::packed]] FarPtr
  417. {
  418. u32 offset { 0 };
  419. u16 selector { 0 };
  420. };
  421. struct iovec {
  422. void* iov_base;
  423. size_t iov_len;
  424. };
  425. struct sched_param {
  426. int sched_priority;
  427. };
  428. struct ifreq {
  429. #define IFNAMSIZ 16
  430. char ifr_name[IFNAMSIZ];
  431. union {
  432. struct sockaddr ifru_addr;
  433. struct sockaddr ifru_dstaddr;
  434. struct sockaddr ifru_broadaddr;
  435. struct sockaddr ifru_netmask;
  436. struct sockaddr ifru_hwaddr;
  437. short ifru_flags;
  438. int ifru_metric;
  439. int64_t ifru_vnetid;
  440. uint64_t ifru_media;
  441. void* ifru_data;
  442. unsigned int ifru_index;
  443. } ifr_ifru;
  444. #define ifr_addr ifr_ifru.ifru_addr // address
  445. #define ifr_dstaddr ifr_ifru.ifru_dstaddr // other end of p-to-p link
  446. #define ifr_broadaddr ifr_ifru.ifru_broadaddr // broadcast address
  447. #define ifr_netmask ifr_ifru.ifru_netmask // network mask
  448. #define ifr_flags ifr_ifru.ifru_flags // flags
  449. #define ifr_metric ifr_ifru.ifru_metric // metric
  450. #define ifr_mtu ifr_ifru.ifru_metric // mtu (overload)
  451. #define ifr_hardmtu ifr_ifru.ifru_metric // hardmtu (overload)
  452. #define ifr_media ifr_ifru.ifru_media // media options
  453. #define ifr_rdomainid ifr_ifru.ifru_metric // VRF instance (overload)
  454. #define ifr_vnetid ifr_ifru.ifru_vnetid // Virtual Net Id
  455. #define ifr_ttl ifr_ifru.ifru_metric // tunnel TTL (overload)
  456. #define ifr_data ifr_ifru.ifru_data // for use by interface
  457. #define ifr_index ifr_ifru.ifru_index // interface index
  458. #define ifr_llprio ifr_ifru.ifru_metric // link layer priority
  459. #define ifr_hwaddr ifr_ifru.ifru_hwaddr // MAC address
  460. };
  461. struct rtentry {
  462. struct sockaddr rt_gateway; /* the gateway address */
  463. struct sockaddr rt_genmask; /* the target network mask */
  464. unsigned short int rt_flags;
  465. char* rt_dev;
  466. /* FIXME: complete the struct */
  467. };
  468. #define RTF_UP 0x1 /* do not delete the route */
  469. #define RTF_GATEWAY 0x2 /* the route is a gateway and not an end host */
  470. #define AT_FDCWD -100
  471. #define PURGE_ALL_VOLATILE 0x1
  472. #define PURGE_ALL_CLEAN_INODE 0x2
  473. #define PT_TRACE_ME 1
  474. #define PT_ATTACH 2
  475. #define PT_CONTINUE 3
  476. #define PT_SYSCALL 4
  477. #define PT_GETREGS 5
  478. #define PT_DETACH 6