zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

blob e0fc5561 (41114B) - Raw


      1 const builtin = @import("builtin");
      2 const std = @import("../../std.zig");
      3 const maxInt = std.math.maxInt;
      4 usingnamespace @import("../bits.zig");
      5 
      6 pub usingnamespace switch (builtin.arch) {
      7     .mips, .mipsel => @import("linux/errno-mips.zig"),
      8     else => @import("linux/errno-generic.zig"),
      9 };
     10 
     11 pub usingnamespace switch (builtin.arch) {
     12     .i386 => @import("linux/i386.zig"),
     13     .x86_64 => @import("linux/x86_64.zig"),
     14     .aarch64 => @import("linux/arm64.zig"),
     15     .arm => @import("linux/arm-eabi.zig"),
     16     .riscv64 => @import("linux/riscv64.zig"),
     17     .mipsel => @import("linux/mipsel.zig"),
     18     else => struct {},
     19 };
     20 
     21 const is_mips = builtin.arch.isMIPS();
     22 
     23 pub const pid_t = i32;
     24 pub const fd_t = i32;
     25 pub const uid_t = i32;
     26 pub const gid_t = u32;
     27 pub const clock_t = isize;
     28 
     29 pub const NAME_MAX = 255;
     30 pub const PATH_MAX = 4096;
     31 pub const IOV_MAX = 1024;
     32 
     33 pub const STDIN_FILENO = 0;
     34 pub const STDOUT_FILENO = 1;
     35 pub const STDERR_FILENO = 2;
     36 
     37 /// Special value used to indicate openat should use the current working directory
     38 pub const AT_FDCWD = -100;
     39 
     40 /// Do not follow symbolic links
     41 pub const AT_SYMLINK_NOFOLLOW = 0x100;
     42 
     43 /// Remove directory instead of unlinking file
     44 pub const AT_REMOVEDIR = 0x200;
     45 
     46 /// Follow symbolic links.
     47 pub const AT_SYMLINK_FOLLOW = 0x400;
     48 
     49 /// Suppress terminal automount traversal
     50 pub const AT_NO_AUTOMOUNT = 0x800;
     51 
     52 /// Allow empty relative pathname
     53 pub const AT_EMPTY_PATH = 0x1000;
     54 
     55 /// Type of synchronisation required from statx()
     56 pub const AT_STATX_SYNC_TYPE = 0x6000;
     57 
     58 /// - Do whatever stat() does
     59 pub const AT_STATX_SYNC_AS_STAT = 0x0000;
     60 
     61 /// - Force the attributes to be sync'd with the server
     62 pub const AT_STATX_FORCE_SYNC = 0x2000;
     63 
     64 /// - Don't sync attributes with the server
     65 pub const AT_STATX_DONT_SYNC = 0x4000;
     66 
     67 /// Apply to the entire subtree
     68 pub const AT_RECURSIVE = 0x8000;
     69 
     70 pub const FUTEX_WAIT = 0;
     71 pub const FUTEX_WAKE = 1;
     72 pub const FUTEX_FD = 2;
     73 pub const FUTEX_REQUEUE = 3;
     74 pub const FUTEX_CMP_REQUEUE = 4;
     75 pub const FUTEX_WAKE_OP = 5;
     76 pub const FUTEX_LOCK_PI = 6;
     77 pub const FUTEX_UNLOCK_PI = 7;
     78 pub const FUTEX_TRYLOCK_PI = 8;
     79 pub const FUTEX_WAIT_BITSET = 9;
     80 
     81 pub const FUTEX_PRIVATE_FLAG = 128;
     82 
     83 pub const FUTEX_CLOCK_REALTIME = 256;
     84 
     85 pub const PROT_NONE = 0;
     86 pub const PROT_READ = 1;
     87 pub const PROT_WRITE = 2;
     88 pub const PROT_EXEC = 4;
     89 pub const PROT_GROWSDOWN = 0x01000000;
     90 pub const PROT_GROWSUP = 0x02000000;
     91 
     92 /// Share changes
     93 pub const MAP_SHARED = 0x01;
     94 
     95 /// Changes are private
     96 pub const MAP_PRIVATE = 0x02;
     97 
     98 /// share + validate extension flags
     99 pub const MAP_SHARED_VALIDATE = 0x03;
    100 
    101 /// Mask for type of mapping
    102 pub const MAP_TYPE = 0x0f;
    103 
    104 /// Interpret addr exactly
    105 pub const MAP_FIXED = 0x10;
    106 
    107 /// don't use a file
    108 pub const MAP_ANONYMOUS = if (is_mips) 0x800 else 0x20;
    109 
    110 // MAP_ 0x0100 - 0x4000 flags are per architecture
    111 
    112 /// populate (prefault) pagetables
    113 pub const MAP_POPULATE = if (is_mips) 0x10000 else 0x8000;
    114 
    115 /// do not block on IO
    116 pub const MAP_NONBLOCK = if (is_mips) 0x20000 else 0x10000;
    117 
    118 /// give out an address that is best suited for process/thread stacks
    119 pub const MAP_STACK = if (is_mips) 0x40000 else 0x20000;
    120 
    121 /// create a huge page mapping
    122 pub const MAP_HUGETLB = if (is_mips) 0x80000 else 0x40000;
    123 
    124 /// perform synchronous page faults for the mapping
    125 pub const MAP_SYNC = 0x80000;
    126 
    127 /// MAP_FIXED which doesn't unmap underlying mapping
    128 pub const MAP_FIXED_NOREPLACE = 0x100000;
    129 
    130 /// For anonymous mmap, memory could be uninitialized
    131 pub const MAP_UNINITIALIZED = 0x4000000;
    132 
    133 pub const F_OK = 0;
    134 pub const X_OK = 1;
    135 pub const W_OK = 2;
    136 pub const R_OK = 4;
    137 
    138 pub const WNOHANG = 1;
    139 pub const WUNTRACED = 2;
    140 pub const WSTOPPED = 2;
    141 pub const WEXITED = 4;
    142 pub const WCONTINUED = 8;
    143 pub const WNOWAIT = 0x1000000;
    144 
    145 pub usingnamespace if (is_mips)
    146     struct {
    147         pub const SA_NOCLDSTOP = 1;
    148         pub const SA_NOCLDWAIT = 0x10000;
    149         pub const SA_SIGINFO = 8;
    150 
    151         pub const SIG_BLOCK = 1;
    152         pub const SIG_UNBLOCK = 2;
    153         pub const SIG_SETMASK = 3;
    154     }
    155 else
    156     struct {
    157         pub const SA_NOCLDSTOP = 1;
    158         pub const SA_NOCLDWAIT = 2;
    159         pub const SA_SIGINFO = 4;
    160 
    161         pub const SIG_BLOCK = 0;
    162         pub const SIG_UNBLOCK = 1;
    163         pub const SIG_SETMASK = 2;
    164     };
    165 
    166 pub const SA_ONSTACK = 0x08000000;
    167 pub const SA_RESTART = 0x10000000;
    168 pub const SA_NODEFER = 0x40000000;
    169 pub const SA_RESETHAND = 0x80000000;
    170 pub const SA_RESTORER = 0x04000000;
    171 
    172 pub const SIGHUP = 1;
    173 pub const SIGINT = 2;
    174 pub const SIGQUIT = 3;
    175 pub const SIGILL = 4;
    176 pub const SIGTRAP = 5;
    177 pub const SIGABRT = 6;
    178 pub const SIGIOT = SIGABRT;
    179 pub const SIGBUS = 7;
    180 pub const SIGFPE = 8;
    181 pub const SIGKILL = 9;
    182 pub const SIGUSR1 = 10;
    183 pub const SIGSEGV = 11;
    184 pub const SIGUSR2 = 12;
    185 pub const SIGPIPE = 13;
    186 pub const SIGALRM = 14;
    187 pub const SIGTERM = 15;
    188 pub const SIGSTKFLT = 16;
    189 pub const SIGCHLD = 17;
    190 pub const SIGCONT = 18;
    191 pub const SIGSTOP = 19;
    192 pub const SIGTSTP = 20;
    193 pub const SIGTTIN = 21;
    194 pub const SIGTTOU = 22;
    195 pub const SIGURG = 23;
    196 pub const SIGXCPU = 24;
    197 pub const SIGXFSZ = 25;
    198 pub const SIGVTALRM = 26;
    199 pub const SIGPROF = 27;
    200 pub const SIGWINCH = 28;
    201 pub const SIGIO = 29;
    202 pub const SIGPOLL = 29;
    203 pub const SIGPWR = 30;
    204 pub const SIGSYS = 31;
    205 pub const SIGUNUSED = SIGSYS;
    206 
    207 pub const O_RDONLY = 0o0;
    208 pub const O_WRONLY = 0o1;
    209 pub const O_RDWR = 0o2;
    210 
    211 pub const kernel_rwf = u32;
    212 
    213 /// high priority request, poll if possible
    214 pub const RWF_HIPRI = kernel_rwf(0x00000001);
    215 
    216 /// per-IO O_DSYNC
    217 pub const RWF_DSYNC = kernel_rwf(0x00000002);
    218 
    219 /// per-IO O_SYNC
    220 pub const RWF_SYNC = kernel_rwf(0x00000004);
    221 
    222 /// per-IO, return -EAGAIN if operation would block
    223 pub const RWF_NOWAIT = kernel_rwf(0x00000008);
    224 
    225 /// per-IO O_APPEND
    226 pub const RWF_APPEND = kernel_rwf(0x00000010);
    227 
    228 pub const SEEK_SET = 0;
    229 pub const SEEK_CUR = 1;
    230 pub const SEEK_END = 2;
    231 
    232 pub const SHUT_RD = 0;
    233 pub const SHUT_WR = 1;
    234 pub const SHUT_RDWR = 2;
    235 
    236 pub const SOCK_STREAM = if (is_mips) 2 else 1;
    237 pub const SOCK_DGRAM = if (is_mips) 1 else 2;
    238 pub const SOCK_RAW = 3;
    239 pub const SOCK_RDM = 4;
    240 pub const SOCK_SEQPACKET = 5;
    241 pub const SOCK_DCCP = 6;
    242 pub const SOCK_PACKET = 10;
    243 pub const SOCK_CLOEXEC = 0o2000000;
    244 pub const SOCK_NONBLOCK = if (is_mips) 0o200 else 0o4000;
    245 
    246 pub const PF_UNSPEC = 0;
    247 pub const PF_LOCAL = 1;
    248 pub const PF_UNIX = PF_LOCAL;
    249 pub const PF_FILE = PF_LOCAL;
    250 pub const PF_INET = 2;
    251 pub const PF_AX25 = 3;
    252 pub const PF_IPX = 4;
    253 pub const PF_APPLETALK = 5;
    254 pub const PF_NETROM = 6;
    255 pub const PF_BRIDGE = 7;
    256 pub const PF_ATMPVC = 8;
    257 pub const PF_X25 = 9;
    258 pub const PF_INET6 = 10;
    259 pub const PF_ROSE = 11;
    260 pub const PF_DECnet = 12;
    261 pub const PF_NETBEUI = 13;
    262 pub const PF_SECURITY = 14;
    263 pub const PF_KEY = 15;
    264 pub const PF_NETLINK = 16;
    265 pub const PF_ROUTE = PF_NETLINK;
    266 pub const PF_PACKET = 17;
    267 pub const PF_ASH = 18;
    268 pub const PF_ECONET = 19;
    269 pub const PF_ATMSVC = 20;
    270 pub const PF_RDS = 21;
    271 pub const PF_SNA = 22;
    272 pub const PF_IRDA = 23;
    273 pub const PF_PPPOX = 24;
    274 pub const PF_WANPIPE = 25;
    275 pub const PF_LLC = 26;
    276 pub const PF_IB = 27;
    277 pub const PF_MPLS = 28;
    278 pub const PF_CAN = 29;
    279 pub const PF_TIPC = 30;
    280 pub const PF_BLUETOOTH = 31;
    281 pub const PF_IUCV = 32;
    282 pub const PF_RXRPC = 33;
    283 pub const PF_ISDN = 34;
    284 pub const PF_PHONET = 35;
    285 pub const PF_IEEE802154 = 36;
    286 pub const PF_CAIF = 37;
    287 pub const PF_ALG = 38;
    288 pub const PF_NFC = 39;
    289 pub const PF_VSOCK = 40;
    290 pub const PF_KCM = 41;
    291 pub const PF_QIPCRTR = 42;
    292 pub const PF_SMC = 43;
    293 pub const PF_MAX = 44;
    294 
    295 pub const AF_UNSPEC = PF_UNSPEC;
    296 pub const AF_LOCAL = PF_LOCAL;
    297 pub const AF_UNIX = AF_LOCAL;
    298 pub const AF_FILE = AF_LOCAL;
    299 pub const AF_INET = PF_INET;
    300 pub const AF_AX25 = PF_AX25;
    301 pub const AF_IPX = PF_IPX;
    302 pub const AF_APPLETALK = PF_APPLETALK;
    303 pub const AF_NETROM = PF_NETROM;
    304 pub const AF_BRIDGE = PF_BRIDGE;
    305 pub const AF_ATMPVC = PF_ATMPVC;
    306 pub const AF_X25 = PF_X25;
    307 pub const AF_INET6 = PF_INET6;
    308 pub const AF_ROSE = PF_ROSE;
    309 pub const AF_DECnet = PF_DECnet;
    310 pub const AF_NETBEUI = PF_NETBEUI;
    311 pub const AF_SECURITY = PF_SECURITY;
    312 pub const AF_KEY = PF_KEY;
    313 pub const AF_NETLINK = PF_NETLINK;
    314 pub const AF_ROUTE = PF_ROUTE;
    315 pub const AF_PACKET = PF_PACKET;
    316 pub const AF_ASH = PF_ASH;
    317 pub const AF_ECONET = PF_ECONET;
    318 pub const AF_ATMSVC = PF_ATMSVC;
    319 pub const AF_RDS = PF_RDS;
    320 pub const AF_SNA = PF_SNA;
    321 pub const AF_IRDA = PF_IRDA;
    322 pub const AF_PPPOX = PF_PPPOX;
    323 pub const AF_WANPIPE = PF_WANPIPE;
    324 pub const AF_LLC = PF_LLC;
    325 pub const AF_IB = PF_IB;
    326 pub const AF_MPLS = PF_MPLS;
    327 pub const AF_CAN = PF_CAN;
    328 pub const AF_TIPC = PF_TIPC;
    329 pub const AF_BLUETOOTH = PF_BLUETOOTH;
    330 pub const AF_IUCV = PF_IUCV;
    331 pub const AF_RXRPC = PF_RXRPC;
    332 pub const AF_ISDN = PF_ISDN;
    333 pub const AF_PHONET = PF_PHONET;
    334 pub const AF_IEEE802154 = PF_IEEE802154;
    335 pub const AF_CAIF = PF_CAIF;
    336 pub const AF_ALG = PF_ALG;
    337 pub const AF_NFC = PF_NFC;
    338 pub const AF_VSOCK = PF_VSOCK;
    339 pub const AF_KCM = PF_KCM;
    340 pub const AF_QIPCRTR = PF_QIPCRTR;
    341 pub const AF_SMC = PF_SMC;
    342 pub const AF_MAX = PF_MAX;
    343 
    344 pub usingnamespace if (!is_mips)
    345     struct {
    346         pub const SO_DEBUG = 1;
    347         pub const SO_REUSEADDR = 2;
    348         pub const SO_TYPE = 3;
    349         pub const SO_ERROR = 4;
    350         pub const SO_DONTROUTE = 5;
    351         pub const SO_BROADCAST = 6;
    352         pub const SO_SNDBUF = 7;
    353         pub const SO_RCVBUF = 8;
    354         pub const SO_KEEPALIVE = 9;
    355         pub const SO_OOBINLINE = 10;
    356         pub const SO_NO_CHECK = 11;
    357         pub const SO_PRIORITY = 12;
    358         pub const SO_LINGER = 13;
    359         pub const SO_BSDCOMPAT = 14;
    360         pub const SO_REUSEPORT = 15;
    361         pub const SO_PASSCRED = 16;
    362         pub const SO_PEERCRED = 17;
    363         pub const SO_RCVLOWAT = 18;
    364         pub const SO_SNDLOWAT = 19;
    365         pub const SO_RCVTIMEO = 20;
    366         pub const SO_SNDTIMEO = 21;
    367         pub const SO_ACCEPTCONN = 30;
    368         pub const SO_PEERSEC = 31;
    369         pub const SO_SNDBUFFORCE = 32;
    370         pub const SO_RCVBUFFORCE = 33;
    371         pub const SO_PROTOCOL = 38;
    372         pub const SO_DOMAIN = 39;
    373     }
    374 else
    375     struct {};
    376 
    377 pub const SO_SECURITY_AUTHENTICATION = 22;
    378 pub const SO_SECURITY_ENCRYPTION_TRANSPORT = 23;
    379 pub const SO_SECURITY_ENCRYPTION_NETWORK = 24;
    380 
    381 pub const SO_BINDTODEVICE = 25;
    382 
    383 pub const SO_ATTACH_FILTER = 26;
    384 pub const SO_DETACH_FILTER = 27;
    385 pub const SO_GET_FILTER = SO_ATTACH_FILTER;
    386 
    387 pub const SO_PEERNAME = 28;
    388 pub const SO_TIMESTAMP_OLD = 29;
    389 pub const SO_PASSSEC = 34;
    390 pub const SO_TIMESTAMPNS_OLD = 35;
    391 pub const SO_MARK = 36;
    392 pub const SO_TIMESTAMPING_OLD = 37;
    393 
    394 pub const SO_RXQ_OVFL = 40;
    395 pub const SO_WIFI_STATUS = 41;
    396 pub const SCM_WIFI_STATUS = SO_WIFI_STATUS;
    397 pub const SO_PEEK_OFF = 42;
    398 pub const SO_NOFCS = 43;
    399 pub const SO_LOCK_FILTER = 44;
    400 pub const SO_SELECT_ERR_QUEUE = 45;
    401 pub const SO_BUSY_POLL = 46;
    402 pub const SO_MAX_PACING_RATE = 47;
    403 pub const SO_BPF_EXTENSIONS = 48;
    404 pub const SO_INCOMING_CPU = 49;
    405 pub const SO_ATTACH_BPF = 50;
    406 pub const SO_DETACH_BPF = SO_DETACH_FILTER;
    407 pub const SO_ATTACH_REUSEPORT_CBPF = 51;
    408 pub const SO_ATTACH_REUSEPORT_EBPF = 52;
    409 pub const SO_CNX_ADVICE = 53;
    410 pub const SCM_TIMESTAMPING_OPT_STATS = 54;
    411 pub const SO_MEMINFO = 55;
    412 pub const SO_INCOMING_NAPI_ID = 56;
    413 pub const SO_COOKIE = 57;
    414 pub const SCM_TIMESTAMPING_PKTINFO = 58;
    415 pub const SO_PEERGROUPS = 59;
    416 pub const SO_ZEROCOPY = 60;
    417 pub const SO_TXTIME = 61;
    418 pub const SCM_TXTIME = SO_TXTIME;
    419 pub const SO_BINDTOIFINDEX = 62;
    420 pub const SO_TIMESTAMP_NEW = 63;
    421 pub const SO_TIMESTAMPNS_NEW = 64;
    422 pub const SO_TIMESTAMPING_NEW = 65;
    423 pub const SO_RCVTIMEO_NEW = 66;
    424 pub const SO_SNDTIMEO_NEW = 67;
    425 pub const SO_DETACH_REUSEPORT_BPF = 68;
    426 
    427 pub const SOL_SOCKET = if (is_mips) 65535 else 1;
    428 
    429 pub const SOL_IP = 0;
    430 pub const SOL_IPV6 = 41;
    431 pub const SOL_ICMPV6 = 58;
    432 
    433 pub const SOL_RAW = 255;
    434 pub const SOL_DECNET = 261;
    435 pub const SOL_X25 = 262;
    436 pub const SOL_PACKET = 263;
    437 pub const SOL_ATM = 264;
    438 pub const SOL_AAL = 265;
    439 pub const SOL_IRDA = 266;
    440 pub const SOL_NETBEUI = 267;
    441 pub const SOL_LLC = 268;
    442 pub const SOL_DCCP = 269;
    443 pub const SOL_NETLINK = 270;
    444 pub const SOL_TIPC = 271;
    445 pub const SOL_RXRPC = 272;
    446 pub const SOL_PPPOL2TP = 273;
    447 pub const SOL_BLUETOOTH = 274;
    448 pub const SOL_PNPIPE = 275;
    449 pub const SOL_RDS = 276;
    450 pub const SOL_IUCV = 277;
    451 pub const SOL_CAIF = 278;
    452 pub const SOL_ALG = 279;
    453 pub const SOL_NFC = 280;
    454 pub const SOL_KCM = 281;
    455 pub const SOL_TLS = 282;
    456 
    457 pub const SOMAXCONN = 128;
    458 
    459 pub const MSG_OOB = 0x0001;
    460 pub const MSG_PEEK = 0x0002;
    461 pub const MSG_DONTROUTE = 0x0004;
    462 pub const MSG_CTRUNC = 0x0008;
    463 pub const MSG_PROXY = 0x0010;
    464 pub const MSG_TRUNC = 0x0020;
    465 pub const MSG_DONTWAIT = 0x0040;
    466 pub const MSG_EOR = 0x0080;
    467 pub const MSG_WAITALL = 0x0100;
    468 pub const MSG_FIN = 0x0200;
    469 pub const MSG_SYN = 0x0400;
    470 pub const MSG_CONFIRM = 0x0800;
    471 pub const MSG_RST = 0x1000;
    472 pub const MSG_ERRQUEUE = 0x2000;
    473 pub const MSG_NOSIGNAL = 0x4000;
    474 pub const MSG_MORE = 0x8000;
    475 pub const MSG_WAITFORONE = 0x10000;
    476 pub const MSG_BATCH = 0x40000;
    477 pub const MSG_ZEROCOPY = 0x4000000;
    478 pub const MSG_FASTOPEN = 0x20000000;
    479 pub const MSG_CMSG_CLOEXEC = 0x40000000;
    480 
    481 pub const DT_UNKNOWN = 0;
    482 pub const DT_FIFO = 1;
    483 pub const DT_CHR = 2;
    484 pub const DT_DIR = 4;
    485 pub const DT_BLK = 6;
    486 pub const DT_REG = 8;
    487 pub const DT_LNK = 10;
    488 pub const DT_SOCK = 12;
    489 pub const DT_WHT = 14;
    490 
    491 pub const TCGETS = if (is_mips) 0x540D else 0x5401;
    492 pub const TCSETS = 0x5402;
    493 pub const TCSETSW = 0x5403;
    494 pub const TCSETSF = 0x5404;
    495 pub const TCGETA = 0x5405;
    496 pub const TCSETA = 0x5406;
    497 pub const TCSETAW = 0x5407;
    498 pub const TCSETAF = 0x5408;
    499 pub const TCSBRK = 0x5409;
    500 pub const TCXONC = 0x540A;
    501 pub const TCFLSH = 0x540B;
    502 pub const TIOCEXCL = 0x540C;
    503 pub const TIOCNXCL = 0x540D;
    504 pub const TIOCSCTTY = 0x540E;
    505 pub const TIOCGPGRP = 0x540F;
    506 pub const TIOCSPGRP = 0x5410;
    507 pub const TIOCOUTQ = if (is_mips) 0x7472 else 0x5411;
    508 pub const TIOCSTI = 0x5412;
    509 pub const TIOCGWINSZ = if (is_mips) 0x40087468 else 0x5413;
    510 pub const TIOCSWINSZ = if (is_mips) 0x80087467 else 0x5414;
    511 pub const TIOCMGET = 0x5415;
    512 pub const TIOCMBIS = 0x5416;
    513 pub const TIOCMBIC = 0x5417;
    514 pub const TIOCMSET = 0x5418;
    515 pub const TIOCGSOFTCAR = 0x5419;
    516 pub const TIOCSSOFTCAR = 0x541A;
    517 pub const FIONREAD = if (is_mips) 0x467F else 0x541B;
    518 pub const TIOCINQ = FIONREAD;
    519 pub const TIOCLINUX = 0x541C;
    520 pub const TIOCCONS = 0x541D;
    521 pub const TIOCGSERIAL = 0x541E;
    522 pub const TIOCSSERIAL = 0x541F;
    523 pub const TIOCPKT = 0x5420;
    524 pub const FIONBIO = 0x5421;
    525 pub const TIOCNOTTY = 0x5422;
    526 pub const TIOCSETD = 0x5423;
    527 pub const TIOCGETD = 0x5424;
    528 pub const TCSBRKP = 0x5425;
    529 pub const TIOCSBRK = 0x5427;
    530 pub const TIOCCBRK = 0x5428;
    531 pub const TIOCGSID = 0x5429;
    532 pub const TIOCGRS485 = 0x542E;
    533 pub const TIOCSRS485 = 0x542F;
    534 pub const TIOCGPTN = 0x80045430;
    535 pub const TIOCSPTLCK = 0x40045431;
    536 pub const TIOCGDEV = 0x80045432;
    537 pub const TCGETX = 0x5432;
    538 pub const TCSETX = 0x5433;
    539 pub const TCSETXF = 0x5434;
    540 pub const TCSETXW = 0x5435;
    541 pub const TIOCSIG = 0x40045436;
    542 pub const TIOCVHANGUP = 0x5437;
    543 pub const TIOCGPKT = 0x80045438;
    544 pub const TIOCGPTLCK = 0x80045439;
    545 pub const TIOCGEXCL = 0x80045440;
    546 
    547 pub const EPOLL_CLOEXEC = O_CLOEXEC;
    548 
    549 pub const EPOLL_CTL_ADD = 1;
    550 pub const EPOLL_CTL_DEL = 2;
    551 pub const EPOLL_CTL_MOD = 3;
    552 
    553 pub const EPOLLIN = 0x001;
    554 pub const EPOLLPRI = 0x002;
    555 pub const EPOLLOUT = 0x004;
    556 pub const EPOLLRDNORM = 0x040;
    557 pub const EPOLLRDBAND = 0x080;
    558 pub const EPOLLWRNORM = if (is_mips) 0x004 else 0x100;
    559 pub const EPOLLWRBAND = if (is_mips) 0x100 else 0x200;
    560 pub const EPOLLMSG = 0x400;
    561 pub const EPOLLERR = 0x008;
    562 pub const EPOLLHUP = 0x010;
    563 pub const EPOLLRDHUP = 0x2000;
    564 pub const EPOLLEXCLUSIVE = (@as(u32, 1) << 28);
    565 pub const EPOLLWAKEUP = (@as(u32, 1) << 29);
    566 pub const EPOLLONESHOT = (@as(u32, 1) << 30);
    567 pub const EPOLLET = (@as(u32, 1) << 31);
    568 
    569 pub const CLOCK_REALTIME = 0;
    570 pub const CLOCK_MONOTONIC = 1;
    571 pub const CLOCK_PROCESS_CPUTIME_ID = 2;
    572 pub const CLOCK_THREAD_CPUTIME_ID = 3;
    573 pub const CLOCK_MONOTONIC_RAW = 4;
    574 pub const CLOCK_REALTIME_COARSE = 5;
    575 pub const CLOCK_MONOTONIC_COARSE = 6;
    576 pub const CLOCK_BOOTTIME = 7;
    577 pub const CLOCK_REALTIME_ALARM = 8;
    578 pub const CLOCK_BOOTTIME_ALARM = 9;
    579 pub const CLOCK_SGI_CYCLE = 10;
    580 pub const CLOCK_TAI = 11;
    581 
    582 pub const CSIGNAL = 0x000000ff;
    583 pub const CLONE_VM = 0x00000100;
    584 pub const CLONE_FS = 0x00000200;
    585 pub const CLONE_FILES = 0x00000400;
    586 pub const CLONE_SIGHAND = 0x00000800;
    587 pub const CLONE_PTRACE = 0x00002000;
    588 pub const CLONE_VFORK = 0x00004000;
    589 pub const CLONE_PARENT = 0x00008000;
    590 pub const CLONE_THREAD = 0x00010000;
    591 pub const CLONE_NEWNS = 0x00020000;
    592 pub const CLONE_SYSVSEM = 0x00040000;
    593 pub const CLONE_SETTLS = 0x00080000;
    594 pub const CLONE_PARENT_SETTID = 0x00100000;
    595 pub const CLONE_CHILD_CLEARTID = 0x00200000;
    596 pub const CLONE_DETACHED = 0x00400000;
    597 pub const CLONE_UNTRACED = 0x00800000;
    598 pub const CLONE_CHILD_SETTID = 0x01000000;
    599 pub const CLONE_NEWCGROUP = 0x02000000;
    600 pub const CLONE_NEWUTS = 0x04000000;
    601 pub const CLONE_NEWIPC = 0x08000000;
    602 pub const CLONE_NEWUSER = 0x10000000;
    603 pub const CLONE_NEWPID = 0x20000000;
    604 pub const CLONE_NEWNET = 0x40000000;
    605 pub const CLONE_IO = 0x80000000;
    606 
    607 // Flags for the clone3() syscall.
    608 
    609 /// Clear any signal handler and reset to SIG_DFL.
    610 pub const CLONE_CLEAR_SIGHAND = 0x100000000;
    611 
    612 pub const EFD_SEMAPHORE = 1;
    613 pub const EFD_CLOEXEC = O_CLOEXEC;
    614 pub const EFD_NONBLOCK = O_NONBLOCK;
    615 
    616 pub const MS_RDONLY = 1;
    617 pub const MS_NOSUID = 2;
    618 pub const MS_NODEV = 4;
    619 pub const MS_NOEXEC = 8;
    620 pub const MS_SYNCHRONOUS = 16;
    621 pub const MS_REMOUNT = 32;
    622 pub const MS_MANDLOCK = 64;
    623 pub const MS_DIRSYNC = 128;
    624 pub const MS_NOATIME = 1024;
    625 pub const MS_NODIRATIME = 2048;
    626 pub const MS_BIND = 4096;
    627 pub const MS_MOVE = 8192;
    628 pub const MS_REC = 16384;
    629 pub const MS_SILENT = 32768;
    630 pub const MS_POSIXACL = (1 << 16);
    631 pub const MS_UNBINDABLE = (1 << 17);
    632 pub const MS_PRIVATE = (1 << 18);
    633 pub const MS_SLAVE = (1 << 19);
    634 pub const MS_SHARED = (1 << 20);
    635 pub const MS_RELATIME = (1 << 21);
    636 pub const MS_KERNMOUNT = (1 << 22);
    637 pub const MS_I_VERSION = (1 << 23);
    638 pub const MS_STRICTATIME = (1 << 24);
    639 pub const MS_LAZYTIME = (1 << 25);
    640 pub const MS_NOREMOTELOCK = (1 << 27);
    641 pub const MS_NOSEC = (1 << 28);
    642 pub const MS_BORN = (1 << 29);
    643 pub const MS_ACTIVE = (1 << 30);
    644 pub const MS_NOUSER = (1 << 31);
    645 
    646 pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME);
    647 
    648 pub const MS_MGC_VAL = 0xc0ed0000;
    649 pub const MS_MGC_MSK = 0xffff0000;
    650 
    651 pub const MNT_FORCE = 1;
    652 pub const MNT_DETACH = 2;
    653 pub const MNT_EXPIRE = 4;
    654 pub const UMOUNT_NOFOLLOW = 8;
    655 
    656 pub const IN_CLOEXEC = O_CLOEXEC;
    657 pub const IN_NONBLOCK = O_NONBLOCK;
    658 
    659 pub const IN_ACCESS = 0x00000001;
    660 pub const IN_MODIFY = 0x00000002;
    661 pub const IN_ATTRIB = 0x00000004;
    662 pub const IN_CLOSE_WRITE = 0x00000008;
    663 pub const IN_CLOSE_NOWRITE = 0x00000010;
    664 pub const IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE;
    665 pub const IN_OPEN = 0x00000020;
    666 pub const IN_MOVED_FROM = 0x00000040;
    667 pub const IN_MOVED_TO = 0x00000080;
    668 pub const IN_MOVE = IN_MOVED_FROM | IN_MOVED_TO;
    669 pub const IN_CREATE = 0x00000100;
    670 pub const IN_DELETE = 0x00000200;
    671 pub const IN_DELETE_SELF = 0x00000400;
    672 pub const IN_MOVE_SELF = 0x00000800;
    673 pub const IN_ALL_EVENTS = 0x00000fff;
    674 
    675 pub const IN_UNMOUNT = 0x00002000;
    676 pub const IN_Q_OVERFLOW = 0x00004000;
    677 pub const IN_IGNORED = 0x00008000;
    678 
    679 pub const IN_ONLYDIR = 0x01000000;
    680 pub const IN_DONT_FOLLOW = 0x02000000;
    681 pub const IN_EXCL_UNLINK = 0x04000000;
    682 pub const IN_MASK_ADD = 0x20000000;
    683 
    684 pub const IN_ISDIR = 0x40000000;
    685 pub const IN_ONESHOT = 0x80000000;
    686 
    687 pub const S_IFMT = 0o170000;
    688 
    689 pub const S_IFDIR = 0o040000;
    690 pub const S_IFCHR = 0o020000;
    691 pub const S_IFBLK = 0o060000;
    692 pub const S_IFREG = 0o100000;
    693 pub const S_IFIFO = 0o010000;
    694 pub const S_IFLNK = 0o120000;
    695 pub const S_IFSOCK = 0o140000;
    696 
    697 pub const S_ISUID = 0o4000;
    698 pub const S_ISGID = 0o2000;
    699 pub const S_ISVTX = 0o1000;
    700 pub const S_IRUSR = 0o400;
    701 pub const S_IWUSR = 0o200;
    702 pub const S_IXUSR = 0o100;
    703 pub const S_IRWXU = 0o700;
    704 pub const S_IRGRP = 0o040;
    705 pub const S_IWGRP = 0o020;
    706 pub const S_IXGRP = 0o010;
    707 pub const S_IRWXG = 0o070;
    708 pub const S_IROTH = 0o004;
    709 pub const S_IWOTH = 0o002;
    710 pub const S_IXOTH = 0o001;
    711 pub const S_IRWXO = 0o007;
    712 
    713 pub fn S_ISREG(m: u32) bool {
    714     return m & S_IFMT == S_IFREG;
    715 }
    716 
    717 pub fn S_ISDIR(m: u32) bool {
    718     return m & S_IFMT == S_IFDIR;
    719 }
    720 
    721 pub fn S_ISCHR(m: u32) bool {
    722     return m & S_IFMT == S_IFCHR;
    723 }
    724 
    725 pub fn S_ISBLK(m: u32) bool {
    726     return m & S_IFMT == S_IFBLK;
    727 }
    728 
    729 pub fn S_ISFIFO(m: u32) bool {
    730     return m & S_IFMT == S_IFIFO;
    731 }
    732 
    733 pub fn S_ISLNK(m: u32) bool {
    734     return m & S_IFMT == S_IFLNK;
    735 }
    736 
    737 pub fn S_ISSOCK(m: u32) bool {
    738     return m & S_IFMT == S_IFSOCK;
    739 }
    740 
    741 pub const TFD_NONBLOCK = O_NONBLOCK;
    742 pub const TFD_CLOEXEC = O_CLOEXEC;
    743 
    744 pub const TFD_TIMER_ABSTIME = 1;
    745 pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
    746 
    747 pub fn WEXITSTATUS(s: u32) u32 {
    748     return (s & 0xff00) >> 8;
    749 }
    750 pub fn WTERMSIG(s: u32) u32 {
    751     return s & 0x7f;
    752 }
    753 pub fn WSTOPSIG(s: u32) u32 {
    754     return WEXITSTATUS(s);
    755 }
    756 pub fn WIFEXITED(s: u32) bool {
    757     return WTERMSIG(s) == 0;
    758 }
    759 pub fn WIFSTOPPED(s: u32) bool {
    760     return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
    761 }
    762 pub fn WIFSIGNALED(s: u32) bool {
    763     return (s & 0xffff) -% 1 < 0xff;
    764 }
    765 
    766 pub const winsize = extern struct {
    767     ws_row: u16,
    768     ws_col: u16,
    769     ws_xpixel: u16,
    770     ws_ypixel: u16,
    771 };
    772 
    773 /// NSIG is the total number of signals defined.
    774 /// As signal numbers are sequential, NSIG is one greater than the largest defined signal number.
    775 pub const NSIG = if (is_mips) 128 else 65;
    776 
    777 pub const sigset_t = [1024 / 32]u32;
    778 
    779 pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len;
    780 pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;
    781 
    782 pub const k_sigaction = if (is_mips)
    783     extern struct {
    784         flags: usize,
    785         sigaction: ?extern fn (i32, *siginfo_t, *c_void) void,
    786         mask: [4]u32,
    787         restorer: extern fn () void,
    788     }
    789 else
    790     extern struct {
    791         sigaction: ?extern fn (i32, *siginfo_t, *c_void) void,
    792         flags: usize,
    793         restorer: extern fn () void,
    794         mask: [2]u32,
    795     };
    796 
    797 /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
    798 pub const Sigaction = extern struct {
    799     sigaction: ?extern fn (i32, *siginfo_t, *c_void) void,
    800     mask: sigset_t,
    801     flags: u32,
    802     restorer: ?extern fn () void = null,
    803 };
    804 
    805 pub const SIG_ERR = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, maxInt(usize));
    806 pub const SIG_DFL = @intToPtr(?extern fn (i32, *siginfo_t, *c_void) void, 0);
    807 pub const SIG_IGN = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, 1);
    808 pub const empty_sigset = [_]u32{0} ** sigset_t.len;
    809 
    810 pub const in_port_t = u16;
    811 pub const sa_family_t = u16;
    812 pub const socklen_t = u32;
    813 
    814 pub const sockaddr = extern struct {
    815     family: sa_family_t,
    816     data: [14]u8,
    817 };
    818 
    819 /// IPv4 socket address
    820 pub const sockaddr_in = extern struct {
    821     family: sa_family_t = AF_INET,
    822     port: in_port_t,
    823     addr: u32,
    824     zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
    825 };
    826 
    827 /// IPv6 socket address
    828 pub const sockaddr_in6 = extern struct {
    829     family: sa_family_t = AF_INET6,
    830     port: in_port_t,
    831     flowinfo: u32,
    832     addr: [16]u8,
    833     scope_id: u32,
    834 };
    835 
    836 /// UNIX domain socket address
    837 pub const sockaddr_un = extern struct {
    838     family: sa_family_t = AF_UNIX,
    839     path: [108]u8,
    840 };
    841 
    842 pub const mmsghdr = extern struct {
    843     msg_hdr: msghdr,
    844     msg_len: u32,
    845 };
    846 
    847 pub const mmsghdr_const = extern struct {
    848     msg_hdr: msghdr_const,
    849     msg_len: u32,
    850 };
    851 
    852 pub const epoll_data = extern union {
    853     ptr: usize,
    854     fd: i32,
    855     @"u32": u32,
    856     @"u64": u64,
    857 };
    858 
    859 // On x86_64 the structure is packed so that it matches the definition of its
    860 // 32bit counterpart
    861 pub const epoll_event = switch (builtin.arch) {
    862     .x86_64 => packed struct {
    863         events: u32,
    864         data: epoll_data,
    865     },
    866     else => extern struct {
    867         events: u32,
    868         data: epoll_data,
    869     },
    870 };
    871 
    872 pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
    873 pub const _LINUX_CAPABILITY_U32S_1 = 1;
    874 
    875 pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026;
    876 pub const _LINUX_CAPABILITY_U32S_2 = 2;
    877 
    878 pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522;
    879 pub const _LINUX_CAPABILITY_U32S_3 = 2;
    880 
    881 pub const VFS_CAP_REVISION_MASK = 0xFF000000;
    882 pub const VFS_CAP_REVISION_SHIFT = 24;
    883 pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
    884 pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001;
    885 
    886 pub const VFS_CAP_REVISION_1 = 0x01000000;
    887 pub const VFS_CAP_U32_1 = 1;
    888 pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1);
    889 
    890 pub const VFS_CAP_REVISION_2 = 0x02000000;
    891 pub const VFS_CAP_U32_2 = 2;
    892 pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2);
    893 
    894 pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
    895 pub const VFS_CAP_U32 = VFS_CAP_U32_2;
    896 pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
    897 
    898 pub const vfs_cap_data = extern struct {
    899     //all of these are mandated as little endian
    900     //when on disk.
    901     const Data = struct {
    902         permitted: u32,
    903         inheritable: u32,
    904     };
    905 
    906     magic_etc: u32,
    907     data: [VFS_CAP_U32]Data,
    908 };
    909 
    910 pub const CAP_CHOWN = 0;
    911 pub const CAP_DAC_OVERRIDE = 1;
    912 pub const CAP_DAC_READ_SEARCH = 2;
    913 pub const CAP_FOWNER = 3;
    914 pub const CAP_FSETID = 4;
    915 pub const CAP_KILL = 5;
    916 pub const CAP_SETGID = 6;
    917 pub const CAP_SETUID = 7;
    918 pub const CAP_SETPCAP = 8;
    919 pub const CAP_LINUX_IMMUTABLE = 9;
    920 pub const CAP_NET_BIND_SERVICE = 10;
    921 pub const CAP_NET_BROADCAST = 11;
    922 pub const CAP_NET_ADMIN = 12;
    923 pub const CAP_NET_RAW = 13;
    924 pub const CAP_IPC_LOCK = 14;
    925 pub const CAP_IPC_OWNER = 15;
    926 pub const CAP_SYS_MODULE = 16;
    927 pub const CAP_SYS_RAWIO = 17;
    928 pub const CAP_SYS_CHROOT = 18;
    929 pub const CAP_SYS_PTRACE = 19;
    930 pub const CAP_SYS_PACCT = 20;
    931 pub const CAP_SYS_ADMIN = 21;
    932 pub const CAP_SYS_BOOT = 22;
    933 pub const CAP_SYS_NICE = 23;
    934 pub const CAP_SYS_RESOURCE = 24;
    935 pub const CAP_SYS_TIME = 25;
    936 pub const CAP_SYS_TTY_CONFIG = 26;
    937 pub const CAP_MKNOD = 27;
    938 pub const CAP_LEASE = 28;
    939 pub const CAP_AUDIT_WRITE = 29;
    940 pub const CAP_AUDIT_CONTROL = 30;
    941 pub const CAP_SETFCAP = 31;
    942 pub const CAP_MAC_OVERRIDE = 32;
    943 pub const CAP_MAC_ADMIN = 33;
    944 pub const CAP_SYSLOG = 34;
    945 pub const CAP_WAKE_ALARM = 35;
    946 pub const CAP_BLOCK_SUSPEND = 36;
    947 pub const CAP_AUDIT_READ = 37;
    948 pub const CAP_LAST_CAP = CAP_AUDIT_READ;
    949 
    950 pub fn cap_valid(u8: x) bool {
    951     return x >= 0 and x <= CAP_LAST_CAP;
    952 }
    953 
    954 pub fn CAP_TO_MASK(cap: u8) u32 {
    955     return @as(u32, 1) << @intCast(u5, cap & 31);
    956 }
    957 
    958 pub fn CAP_TO_INDEX(cap: u8) u8 {
    959     return cap >> 5;
    960 }
    961 
    962 pub const cap_t = extern struct {
    963     hdrp: *cap_user_header_t,
    964     datap: *cap_user_data_t,
    965 };
    966 
    967 pub const cap_user_header_t = extern struct {
    968     version: u32,
    969     pid: usize,
    970 };
    971 
    972 pub const cap_user_data_t = extern struct {
    973     effective: u32,
    974     permitted: u32,
    975     inheritable: u32,
    976 };
    977 
    978 pub const inotify_event = extern struct {
    979     wd: i32,
    980     mask: u32,
    981     cookie: u32,
    982     len: u32,
    983     //name: [?]u8,
    984 };
    985 
    986 pub const dirent64 = extern struct {
    987     d_ino: u64,
    988     d_off: u64,
    989     d_reclen: u16,
    990     d_type: u8,
    991     d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/173
    992 
    993     pub fn reclen(self: dirent64) u16 {
    994         return self.d_reclen;
    995     }
    996 };
    997 
    998 pub const dl_phdr_info = extern struct {
    999     dlpi_addr: usize,
   1000     dlpi_name: ?[*:0]const u8,
   1001     dlpi_phdr: [*]std.elf.Phdr,
   1002     dlpi_phnum: u16,
   1003 };
   1004 
   1005 pub const CPU_SETSIZE = 128;
   1006 pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
   1007 pub const cpu_count_t = @IntType(false, std.math.log2(CPU_SETSIZE * 8));
   1008 
   1009 pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
   1010     var sum: cpu_count_t = 0;
   1011     for (set) |x| {
   1012         sum += @popCount(usize, x);
   1013     }
   1014     return sum;
   1015 }
   1016 
   1017 // TODO port these over
   1018 //#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set)
   1019 //#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set)
   1020 //#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set)
   1021 //#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2)
   1022 //#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2)
   1023 //#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2)
   1024 //#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set)
   1025 //#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)
   1026 //#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2)
   1027 
   1028 pub const MINSIGSTKSZ = switch (builtin.arch) {
   1029     .i386, .x86_64, .arm, .mipsel => 2048,
   1030     .aarch64 => 5120,
   1031     else => @compileError("MINSIGSTKSZ not defined for this architecture"),
   1032 };
   1033 pub const SIGSTKSZ = switch (builtin.arch) {
   1034     .i386, .x86_64, .arm, .mipsel => 8192,
   1035     .aarch64 => 16384,
   1036     else => @compileError("SIGSTKSZ not defined for this architecture"),
   1037 };
   1038 
   1039 pub const SS_ONSTACK = 1;
   1040 pub const SS_DISABLE = 2;
   1041 pub const SS_AUTODISARM = 1 << 31;
   1042 
   1043 pub const stack_t = extern struct {
   1044     ss_sp: [*]u8,
   1045     ss_flags: i32,
   1046     ss_size: isize,
   1047 };
   1048 
   1049 pub const sigval = extern union {
   1050     int: i32,
   1051     ptr: *c_void,
   1052 };
   1053 
   1054 const siginfo_fields_union = extern union {
   1055     pad: [128 - 2 * @sizeOf(c_int) - @sizeOf(c_long)]u8,
   1056     common: extern struct {
   1057         first: extern union {
   1058             piduid: extern struct {
   1059                 pid: pid_t,
   1060                 uid: uid_t,
   1061             },
   1062             timer: extern struct {
   1063                 timerid: i32,
   1064                 overrun: i32,
   1065             },
   1066         },
   1067         second: extern union {
   1068             value: sigval,
   1069             sigchld: extern struct {
   1070                 status: i32,
   1071                 utime: clock_t,
   1072                 stime: clock_t,
   1073             },
   1074         },
   1075     },
   1076     sigfault: extern struct {
   1077         addr: *c_void,
   1078         addr_lsb: i16,
   1079         first: extern union {
   1080             addr_bnd: extern struct {
   1081                 lower: *c_void,
   1082                 upper: *c_void,
   1083             },
   1084             pkey: u32,
   1085         },
   1086     },
   1087     sigpoll: extern struct {
   1088         band: isize,
   1089         fd: i32,
   1090     },
   1091     sigsys: extern struct {
   1092         call_addr: *c_void,
   1093         syscall: i32,
   1094         arch: u32,
   1095     },
   1096 };
   1097 
   1098 pub const siginfo_t = if (is_mips)
   1099     extern struct {
   1100         signo: i32,
   1101         code: i32,
   1102         errno: i32,
   1103         fields: siginfo_fields_union,
   1104     }
   1105 else
   1106     extern struct {
   1107         signo: i32,
   1108         errno: i32,
   1109         code: i32,
   1110         fields: siginfo_fields_union,
   1111     };
   1112 
   1113 pub const io_uring_params = extern struct {
   1114     sq_entries: u32,
   1115     cq_entries: u32,
   1116     flags: u32,
   1117     sq_thread_cpu: u32,
   1118     sq_thread_idle: u32,
   1119     features: u32,
   1120     resv: [4]u32,
   1121     sq_off: io_sqring_offsets,
   1122     cq_off: io_cqring_offsets,
   1123 };
   1124 
   1125 // io_uring_params.features flags
   1126 
   1127 pub const IORING_FEAT_SINGLE_MMAP = 1 << 0;
   1128 pub const IORING_FEAT_NODROP = 1 << 1;
   1129 pub const IORING_FEAT_SUBMIT_STABLE = 1 << 2;
   1130 
   1131 // io_uring_params.flags
   1132 
   1133 /// io_context is polled
   1134 pub const IORING_SETUP_IOPOLL = 1 << 0;
   1135 
   1136 /// SQ poll thread
   1137 pub const IORING_SETUP_SQPOLL = 1 << 1;
   1138 
   1139 /// sq_thread_cpu is valid
   1140 pub const IORING_SETUP_SQ_AFF = 1 << 2;
   1141 
   1142 /// app defines CQ size
   1143 pub const IORING_SETUP_CQSIZE = 1 << 3;
   1144 
   1145 pub const io_sqring_offsets = extern struct {
   1146     /// offset of ring head
   1147     head: u32,
   1148 
   1149     /// offset of ring tail
   1150     tail: u32,
   1151 
   1152     /// ring mask value
   1153     ring_mask: u32,
   1154 
   1155     /// entries in ring
   1156     ring_entries: u32,
   1157 
   1158     /// ring flags
   1159     flags: u32,
   1160 
   1161     /// number of sqes not submitted
   1162     dropped: u32,
   1163 
   1164     /// sqe index array
   1165     array: u32,
   1166 
   1167     resv1: u32,
   1168     resv2: u64,
   1169 };
   1170 
   1171 // io_sqring_offsets.flags
   1172 
   1173 /// needs io_uring_enter wakeup
   1174 pub const IORING_SQ_NEED_WAKEUP = 1 << 0;
   1175 
   1176 pub const io_cqring_offsets = extern struct {
   1177     head: u32,
   1178     tail: u32,
   1179     ring_mask: u32,
   1180     ring_entries: u32,
   1181     overflow: u32,
   1182     cqes: u32,
   1183     resv: [2]u64,
   1184 };
   1185 
   1186 pub const io_uring_sqe = extern struct {
   1187     opcode: u8,
   1188     flags: u8,
   1189     ioprio: u16,
   1190     fd: i32,
   1191     pub const union1 = extern union {
   1192         off: u64,
   1193         addr2: u64,
   1194     };
   1195     union1: union1,
   1196     addr: u64,
   1197     len: u32,
   1198     pub const union2 = extern union {
   1199         rw_flags: kernel_rwf,
   1200         fsync_flags: u32,
   1201         poll_events: u16,
   1202         sync_range_flags: u32,
   1203         msg_flags: u32,
   1204         timeout_flags: u32,
   1205         accept_flags: u32,
   1206         cancel_flags: u32,
   1207     };
   1208     union2: union2,
   1209     user_data: u64,
   1210     pub const union3 = extern union {
   1211         buf_index: u16,
   1212         __pad2: [3]u64,
   1213     };
   1214     union3: union3,
   1215 };
   1216 
   1217 // io_uring_sqe.flags
   1218 
   1219 /// use fixed fileset
   1220 pub const IOSQE_FIXED_FILE = 1 << 0;
   1221 
   1222 /// issue after inflight IO
   1223 pub const IOSQE_IO_DRAIN = 1 << 1;
   1224 
   1225 /// links next sqe
   1226 pub const IOSQE_IO_LINK = 1 << 2;
   1227 
   1228 /// like LINK, but stronger
   1229 pub const IOSQE_IO_HARDLINK = 1 << 3;
   1230 
   1231 pub const IORING_OP = extern enum {
   1232     NOP,
   1233     READV,
   1234     WRITEV,
   1235     FSYNC,
   1236     READ_FIXED,
   1237     WRITE_FIXED,
   1238     POLL_ADD,
   1239     POLL_REMOVE,
   1240     SYNC_FILE_RANGE,
   1241     SENDMSG,
   1242     RECVMSG,
   1243     TIMEOUT,
   1244     TIMEOUT_REMOVE,
   1245     ACCEPT,
   1246     ASYNC_CANCEL,
   1247     LINK_TIMEOUT,
   1248     CONNECT,
   1249 
   1250     _,
   1251 };
   1252 
   1253 // io_uring_sqe.fsync_flags
   1254 pub const IORING_FSYNC_DATASYNC = 1 << 0;
   1255 
   1256 // io_uring_sqe.timeout_flags
   1257 pub const IORING_TIMEOUT_ABS = 1 << 0;
   1258 
   1259 // IO completion data structure (Completion Queue Entry)
   1260 pub const io_uring_cqe = extern struct {
   1261     /// io_uring_sqe.data submission passed back
   1262     user_data: u64,
   1263 
   1264     /// result code for this event
   1265     res: i32,
   1266     flags: u32,
   1267 };
   1268 
   1269 pub const IORING_OFF_SQ_RING = 0;
   1270 pub const IORING_OFF_CQ_RING = 0x8000000;
   1271 pub const IORING_OFF_SQES = 0x10000000;
   1272 
   1273 // io_uring_enter flags
   1274 pub const IORING_ENTER_GETEVENTS = 1 << 0;
   1275 pub const IORING_ENTER_SQ_WAKEUP = 1 << 1;
   1276 
   1277 // io_uring_register opcodes and arguments
   1278 pub const IORING_REGISTER_BUFFERS = 0;
   1279 pub const IORING_UNREGISTER_BUFFERS = 1;
   1280 pub const IORING_REGISTER_FILES = 2;
   1281 pub const IORING_UNREGISTER_FILES = 3;
   1282 pub const IORING_REGISTER_EVENTFD = 4;
   1283 pub const IORING_UNREGISTER_EVENTFD = 5;
   1284 pub const IORING_REGISTER_FILES_UPDATE = 6;
   1285 
   1286 pub const io_uring_files_update = struct {
   1287     offset: u32,
   1288     resv: u32,
   1289     fds: u64,
   1290 };
   1291 
   1292 pub const utsname = extern struct {
   1293     sysname: [65]u8,
   1294     nodename: [65]u8,
   1295     release: [65]u8,
   1296     version: [65]u8,
   1297     machine: [65]u8,
   1298     domainname: [65]u8,
   1299 };
   1300 pub const HOST_NAME_MAX = 64;
   1301 
   1302 pub const STATX_TYPE = 0x0001;
   1303 pub const STATX_MODE = 0x0002;
   1304 pub const STATX_NLINK = 0x0004;
   1305 pub const STATX_UID = 0x0008;
   1306 pub const STATX_GID = 0x0010;
   1307 pub const STATX_ATIME = 0x0020;
   1308 pub const STATX_MTIME = 0x0040;
   1309 pub const STATX_CTIME = 0x0080;
   1310 pub const STATX_INO = 0x0100;
   1311 pub const STATX_SIZE = 0x0200;
   1312 pub const STATX_BLOCKS = 0x0400;
   1313 pub const STATX_BASIC_STATS = 0x07ff;
   1314 
   1315 pub const STATX_BTIME = 0x0800;
   1316 
   1317 pub const STATX_ATTR_COMPRESSED = 0x0004;
   1318 pub const STATX_ATTR_IMMUTABLE = 0x0010;
   1319 pub const STATX_ATTR_APPEND = 0x0020;
   1320 pub const STATX_ATTR_NODUMP = 0x0040;
   1321 pub const STATX_ATTR_ENCRYPTED = 0x0800;
   1322 pub const STATX_ATTR_AUTOMOUNT = 0x1000;
   1323 
   1324 pub const statx_timestamp = extern struct {
   1325     tv_sec: i64,
   1326     tv_nsec: u32,
   1327     __pad1: u32,
   1328 };
   1329 
   1330 /// Renamed to `Statx` to not conflict with the `statx` function.
   1331 pub const Statx = extern struct {
   1332     /// Mask of bits indicating filled fields
   1333     mask: u32,
   1334 
   1335     /// Block size for filesystem I/O
   1336     blksize: u32,
   1337 
   1338     /// Extra file attribute indicators
   1339     attributes: u64,
   1340 
   1341     /// Number of hard links
   1342     nlink: u32,
   1343 
   1344     /// User ID of owner
   1345     uid: u32,
   1346 
   1347     /// Group ID of owner
   1348     gid: u32,
   1349 
   1350     /// File type and mode
   1351     mode: u16,
   1352     __pad1: u16,
   1353 
   1354     /// Inode number
   1355     ino: u64,
   1356 
   1357     /// Total size in bytes
   1358     size: u64,
   1359 
   1360     /// Number of 512B blocks allocated
   1361     blocks: u64,
   1362 
   1363     /// Mask to show what's supported in `attributes`.
   1364     attributes_mask: u64,
   1365 
   1366     /// Last access file timestamp
   1367     atime: statx_timestamp,
   1368 
   1369     /// Creation file timestamp
   1370     btime: statx_timestamp,
   1371 
   1372     /// Last status change file timestamp
   1373     ctime: statx_timestamp,
   1374 
   1375     /// Last modification file timestamp
   1376     mtime: statx_timestamp,
   1377 
   1378     /// Major ID, if this file represents a device.
   1379     rdev_major: u32,
   1380 
   1381     /// Minor ID, if this file represents a device.
   1382     rdev_minor: u32,
   1383 
   1384     /// Major ID of the device containing the filesystem where this file resides.
   1385     dev_major: u32,
   1386 
   1387     /// Minor ID of the device containing the filesystem where this file resides.
   1388     dev_minor: u32,
   1389 
   1390     __pad2: [14]u64,
   1391 };
   1392 
   1393 pub const addrinfo = extern struct {
   1394     flags: i32,
   1395     family: i32,
   1396     socktype: i32,
   1397     protocol: i32,
   1398     addrlen: socklen_t,
   1399     addr: ?*sockaddr,
   1400     canonname: ?[*:0]u8,
   1401     next: ?*addrinfo,
   1402 };
   1403 
   1404 pub const IPPORT_RESERVED = 1024;
   1405 
   1406 pub const IPPROTO_IP = 0;
   1407 pub const IPPROTO_HOPOPTS = 0;
   1408 pub const IPPROTO_ICMP = 1;
   1409 pub const IPPROTO_IGMP = 2;
   1410 pub const IPPROTO_IPIP = 4;
   1411 pub const IPPROTO_TCP = 6;
   1412 pub const IPPROTO_EGP = 8;
   1413 pub const IPPROTO_PUP = 12;
   1414 pub const IPPROTO_UDP = 17;
   1415 pub const IPPROTO_IDP = 22;
   1416 pub const IPPROTO_TP = 29;
   1417 pub const IPPROTO_DCCP = 33;
   1418 pub const IPPROTO_IPV6 = 41;
   1419 pub const IPPROTO_ROUTING = 43;
   1420 pub const IPPROTO_FRAGMENT = 44;
   1421 pub const IPPROTO_RSVP = 46;
   1422 pub const IPPROTO_GRE = 47;
   1423 pub const IPPROTO_ESP = 50;
   1424 pub const IPPROTO_AH = 51;
   1425 pub const IPPROTO_ICMPV6 = 58;
   1426 pub const IPPROTO_NONE = 59;
   1427 pub const IPPROTO_DSTOPTS = 60;
   1428 pub const IPPROTO_MTP = 92;
   1429 pub const IPPROTO_BEETPH = 94;
   1430 pub const IPPROTO_ENCAP = 98;
   1431 pub const IPPROTO_PIM = 103;
   1432 pub const IPPROTO_COMP = 108;
   1433 pub const IPPROTO_SCTP = 132;
   1434 pub const IPPROTO_MH = 135;
   1435 pub const IPPROTO_UDPLITE = 136;
   1436 pub const IPPROTO_MPLS = 137;
   1437 pub const IPPROTO_RAW = 255;
   1438 pub const IPPROTO_MAX = 256;
   1439 
   1440 pub const RR_A = 1;
   1441 pub const RR_CNAME = 5;
   1442 pub const RR_AAAA = 28;
   1443 
   1444 pub const nfds_t = usize;
   1445 pub const pollfd = extern struct {
   1446     fd: fd_t,
   1447     events: i16,
   1448     revents: i16,
   1449 };
   1450 
   1451 pub const POLLIN = 0x001;
   1452 pub const POLLPRI = 0x002;
   1453 pub const POLLOUT = 0x004;
   1454 pub const POLLERR = 0x008;
   1455 pub const POLLHUP = 0x010;
   1456 pub const POLLNVAL = 0x020;
   1457 pub const POLLRDNORM = 0x040;
   1458 pub const POLLRDBAND = 0x080;
   1459 
   1460 pub const MFD_CLOEXEC = 0x0001;
   1461 pub const MFD_ALLOW_SEALING = 0x0002;
   1462 pub const MFD_HUGETLB = 0x0004;
   1463 pub const MFD_ALL_FLAGS = MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_HUGETLB;
   1464 
   1465 pub const HUGETLB_FLAG_ENCODE_SHIFT = 26;
   1466 pub const HUGETLB_FLAG_ENCODE_MASK = 0x3f;
   1467 pub const HUGETLB_FLAG_ENCODE_64KB = 16 << HUGETLB_FLAG_ENCODE_SHIFT;
   1468 pub const HUGETLB_FLAG_ENCODE_512KB = 19 << HUGETLB_FLAG_ENCODE_SHIFT;
   1469 pub const HUGETLB_FLAG_ENCODE_1MB = 20 << HUGETLB_FLAG_ENCODE_SHIFT;
   1470 pub const HUGETLB_FLAG_ENCODE_2MB = 21 << HUGETLB_FLAG_ENCODE_SHIFT;
   1471 pub const HUGETLB_FLAG_ENCODE_8MB = 23 << HUGETLB_FLAG_ENCODE_SHIFT;
   1472 pub const HUGETLB_FLAG_ENCODE_16MB = 24 << HUGETLB_FLAG_ENCODE_SHIFT;
   1473 pub const HUGETLB_FLAG_ENCODE_32MB = 25 << HUGETLB_FLAG_ENCODE_SHIFT;
   1474 pub const HUGETLB_FLAG_ENCODE_256MB = 28 << HUGETLB_FLAG_ENCODE_SHIFT;
   1475 pub const HUGETLB_FLAG_ENCODE_512MB = 29 << HUGETLB_FLAG_ENCODE_SHIFT;
   1476 pub const HUGETLB_FLAG_ENCODE_1GB = 30 << HUGETLB_FLAG_ENCODE_SHIFT;
   1477 pub const HUGETLB_FLAG_ENCODE_2GB = 31 << HUGETLB_FLAG_ENCODE_SHIFT;
   1478 pub const HUGETLB_FLAG_ENCODE_16GB = 34 << HUGETLB_FLAG_ENCODE_SHIFT;
   1479 
   1480 pub const MFD_HUGE_SHIFT = HUGETLB_FLAG_ENCODE_SHIFT;
   1481 pub const MFD_HUGE_MASK = HUGETLB_FLAG_ENCODE_MASK;
   1482 pub const MFD_HUGE_64KB = HUGETLB_FLAG_ENCODE_64KB;
   1483 pub const MFD_HUGE_512KB = HUGETLB_FLAG_ENCODE_512KB;
   1484 pub const MFD_HUGE_1MB = HUGETLB_FLAG_ENCODE_1MB;
   1485 pub const MFD_HUGE_2MB = HUGETLB_FLAG_ENCODE_2MB;
   1486 pub const MFD_HUGE_8MB = HUGETLB_FLAG_ENCODE_8MB;
   1487 pub const MFD_HUGE_16MB = HUGETLB_FLAG_ENCODE_16MB;
   1488 pub const MFD_HUGE_32MB = HUGETLB_FLAG_ENCODE_32MB;
   1489 pub const MFD_HUGE_256MB = HUGETLB_FLAG_ENCODE_256MB;
   1490 pub const MFD_HUGE_512MB = HUGETLB_FLAG_ENCODE_512MB;
   1491 pub const MFD_HUGE_1GB = HUGETLB_FLAG_ENCODE_1GB;
   1492 pub const MFD_HUGE_2GB = HUGETLB_FLAG_ENCODE_2GB;
   1493 pub const MFD_HUGE_16GB = HUGETLB_FLAG_ENCODE_16GB;
   1494 
   1495 pub const RUSAGE_SELF = 0;
   1496 pub const RUSAGE_CHILDREN = -1;
   1497 pub const RUSAGE_THREAD = 1;
   1498 
   1499 pub const rusage = extern struct {
   1500     utime: timeval,
   1501     stime: timeval,
   1502     maxrss: isize,
   1503     ix_rss: isize,
   1504     idrss: isize,
   1505     isrss: isize,
   1506     minflt: isize,
   1507     majflt: isize,
   1508     nswap: isize,
   1509     inblock: isize,
   1510     oublock: isize,
   1511     msgsnd: isize,
   1512     msgrcv: isize,
   1513     nsignals: isize,
   1514     nvcsw: isize,
   1515     nivcsw: isize,
   1516     __reserved: [16]isize = [1]isize{0} ** 16,
   1517 };
   1518 
   1519 pub const cc_t = u8;
   1520 pub const speed_t = u32;
   1521 pub const tcflag_t = u32;
   1522 
   1523 pub const NCCS = 32;
   1524 
   1525 pub const IGNBRK = 1;
   1526 pub const BRKINT = 2;
   1527 pub const IGNPAR = 4;
   1528 pub const PARMRK = 8;
   1529 pub const INPCK = 16;
   1530 pub const ISTRIP = 32;
   1531 pub const INLCR = 64;
   1532 pub const IGNCR = 128;
   1533 pub const ICRNL = 256;
   1534 pub const IUCLC = 512;
   1535 pub const IXON = 1024;
   1536 pub const IXANY = 2048;
   1537 pub const IXOFF = 4096;
   1538 pub const IMAXBEL = 8192;
   1539 pub const IUTF8 = 16384;
   1540 
   1541 pub const OPOST = 1;
   1542 pub const OLCUC = 2;
   1543 pub const ONLCR = 4;
   1544 pub const OCRNL = 8;
   1545 pub const ONOCR = 16;
   1546 pub const ONLRET = 32;
   1547 pub const OFILL = 64;
   1548 pub const OFDEL = 128;
   1549 pub const VTDLY = 16384;
   1550 pub const VT0 = 0;
   1551 pub const VT1 = 16384;
   1552 
   1553 pub const CSIZE = 48;
   1554 pub const CS5 = 0;
   1555 pub const CS6 = 16;
   1556 pub const CS7 = 32;
   1557 pub const CS8 = 48;
   1558 pub const CSTOPB = 64;
   1559 pub const CREAD = 128;
   1560 pub const PARENB = 256;
   1561 pub const PARODD = 512;
   1562 pub const HUPCL = 1024;
   1563 pub const CLOCAL = 2048;
   1564 
   1565 pub const ISIG = 1;
   1566 pub const ICANON = 2;
   1567 pub const ECHO = 8;
   1568 pub const ECHOE = 16;
   1569 pub const ECHOK = 32;
   1570 pub const ECHONL = 64;
   1571 pub const NOFLSH = 128;
   1572 pub const TOSTOP = 256;
   1573 pub const IEXTEN = 32768;
   1574 
   1575 pub const TCSA = extern enum(usize) {
   1576     NOW,
   1577     DRAIN,
   1578     FLUSH,
   1579     _,
   1580 };
   1581 
   1582 pub const termios = extern struct {
   1583     iflag: tcflag_t,
   1584     oflag: tcflag_t,
   1585     cflag: tcflag_t,
   1586     lflag: tcflag_t,
   1587     line: cc_t,
   1588     cc: [NCCS]cc_t,
   1589     ispeed: speed_t,
   1590     ospeed: speed_t,
   1591 };