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