UnixTypes.h 12 KB

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