aboutsummaryrefslogtreecommitdiff
path: root/std/os/bits
diff options
context:
space:
mode:
authorhryx <codroid@gmail.com>2019-05-27 17:24:21 -0700
committerhryx <codroid@gmail.com>2019-05-27 17:24:21 -0700
commite1f3eec9cc05535b3f3b81f2fb7cd65dd4d1e841 (patch)
tree5f408ed68a686491eaf759f9cbba02beac829b38 /std/os/bits
parent2aa1c5da5dded6b1b346c3a1b57443f2c459ebe9 (diff)
parent3fccc0747903f0726d6cc8ee73832cb62f1304bb (diff)
downloadzig-e1f3eec9cc05535b3f3b81f2fb7cd65dd4d1e841.tar.gz
zig-e1f3eec9cc05535b3f3b81f2fb7cd65dd4d1e841.zip
Merge branch 'master' into translate-c-userland
Diffstat (limited to 'std/os/bits')
-rw-r--r--std/os/bits/darwin.zig1080
-rw-r--r--std/os/bits/freebsd.zig837
-rw-r--r--std/os/bits/linux.zig931
-rw-r--r--std/os/bits/linux/arm64.zig405
-rw-r--r--std/os/bits/linux/errno.zig428
-rw-r--r--std/os/bits/linux/x86_64.zig470
-rw-r--r--std/os/bits/netbsd.zig725
-rw-r--r--std/os/bits/wasi.zig307
-rw-r--r--std/os/bits/windows.zig167
9 files changed, 5350 insertions, 0 deletions
diff --git a/std/os/bits/darwin.zig b/std/os/bits/darwin.zig
new file mode 100644
index 0000000000..a685735da0
--- /dev/null
+++ b/std/os/bits/darwin.zig
@@ -0,0 +1,1080 @@
+const std = @import("../../std.zig");
+const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
+
+pub const fd_t = c_int;
+pub const pid_t = c_int;
+
+pub const in_port_t = u16;
+pub const sa_family_t = u8;
+pub const socklen_t = u32;
+pub const sockaddr = extern union {
+ in: sockaddr_in,
+ in6: sockaddr_in6,
+};
+pub const sockaddr_in = extern struct {
+ len: u8,
+ family: sa_family_t,
+ port: in_port_t,
+ addr: u32,
+ zero: [8]u8,
+};
+pub const sockaddr_in6 = extern struct {
+ len: u8,
+ family: sa_family_t,
+ port: in_port_t,
+ flowinfo: u32,
+ addr: [16]u8,
+ scope_id: u32,
+};
+
+pub const timeval = extern struct {
+ tv_sec: c_long,
+ tv_usec: i32,
+};
+
+pub const timezone = extern struct {
+ tz_minuteswest: i32,
+ tz_dsttime: i32,
+};
+
+pub const mach_timebase_info_data = extern struct {
+ numer: u32,
+ denom: u32,
+};
+
+/// Renamed to Stat to not conflict with the stat function.
+pub const Stat = extern struct {
+ dev: i32,
+ mode: u16,
+ nlink: u16,
+ ino: u64,
+ uid: u32,
+ gid: u32,
+ rdev: i32,
+ atime: usize,
+ atimensec: usize,
+ mtime: usize,
+ mtimensec: usize,
+ ctime: usize,
+ ctimensec: usize,
+ birthtime: usize,
+ birthtimensec: usize,
+ size: i64,
+ blocks: i64,
+ blksize: i32,
+ flags: u32,
+ gen: u32,
+ lspare: i32,
+ qspare: [2]i64,
+};
+
+pub const timespec = extern struct {
+ tv_sec: isize,
+ tv_nsec: isize,
+};
+
+pub const sigset_t = u32;
+pub const empty_sigset = sigset_t(0);
+
+/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
+pub const Sigaction = extern struct {
+ handler: extern fn (c_int) void,
+ sa_mask: sigset_t,
+ sa_flags: c_int,
+};
+
+pub const dirent = extern struct {
+ d_ino: usize,
+ d_seekoff: usize,
+ d_reclen: u16,
+ d_namlen: u16,
+ d_type: u8,
+ d_name: u8, // field address is address of first byte of name
+};
+
+pub const pthread_attr_t = extern struct {
+ __sig: c_long,
+ __opaque: [56]u8,
+};
+
+/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
+pub const Kevent = extern struct {
+ ident: usize,
+ filter: i16,
+ flags: u16,
+ fflags: u32,
+ data: isize,
+ udata: usize,
+};
+
+// sys/types.h on macos uses #pragma pack(4) so these checks are
+// to make sure the struct is laid out the same. These values were
+// produced from C code using the offsetof macro.
+comptime {
+ assert(@byteOffsetOf(Kevent, "ident") == 0);
+ assert(@byteOffsetOf(Kevent, "filter") == 8);
+ assert(@byteOffsetOf(Kevent, "flags") == 10);
+ assert(@byteOffsetOf(Kevent, "fflags") == 12);
+ assert(@byteOffsetOf(Kevent, "data") == 16);
+ assert(@byteOffsetOf(Kevent, "udata") == 24);
+}
+
+pub const kevent64_s = extern struct {
+ ident: u64,
+ filter: i16,
+ flags: u16,
+ fflags: u32,
+ data: i64,
+ udata: u64,
+ ext: [2]u64,
+};
+
+// sys/types.h on macos uses #pragma pack() so these checks are
+// to make sure the struct is laid out the same. These values were
+// produced from C code using the offsetof macro.
+comptime {
+ assert(@byteOffsetOf(kevent64_s, "ident") == 0);
+ assert(@byteOffsetOf(kevent64_s, "filter") == 8);
+ assert(@byteOffsetOf(kevent64_s, "flags") == 10);
+ assert(@byteOffsetOf(kevent64_s, "fflags") == 12);
+ assert(@byteOffsetOf(kevent64_s, "data") == 16);
+ assert(@byteOffsetOf(kevent64_s, "udata") == 24);
+ assert(@byteOffsetOf(kevent64_s, "ext") == 32);
+}
+
+pub const mach_port_t = c_uint;
+pub const clock_serv_t = mach_port_t;
+pub const clock_res_t = c_int;
+pub const mach_port_name_t = natural_t;
+pub const natural_t = c_uint;
+pub const mach_timespec_t = extern struct {
+ tv_sec: c_uint,
+ tv_nsec: clock_res_t,
+};
+pub const kern_return_t = c_int;
+pub const host_t = mach_port_t;
+pub const CALENDAR_CLOCK = 1;
+
+pub const PATH_MAX = 1024;
+
+pub const STDIN_FILENO = 0;
+pub const STDOUT_FILENO = 1;
+pub const STDERR_FILENO = 2;
+
+/// [MC2] no permissions
+pub const PROT_NONE = 0x00;
+
+/// [MC2] pages can be read
+pub const PROT_READ = 0x01;
+
+/// [MC2] pages can be written
+pub const PROT_WRITE = 0x02;
+
+/// [MC2] pages can be executed
+pub const PROT_EXEC = 0x04;
+
+/// allocated from memory, swap space
+pub const MAP_ANONYMOUS = 0x1000;
+
+/// map from file (default)
+pub const MAP_FILE = 0x0000;
+
+/// interpret addr exactly
+pub const MAP_FIXED = 0x0010;
+
+/// region may contain semaphores
+pub const MAP_HASSEMAPHORE = 0x0200;
+
+/// changes are private
+pub const MAP_PRIVATE = 0x0002;
+
+/// share changes
+pub const MAP_SHARED = 0x0001;
+
+/// don't cache pages for this mapping
+pub const MAP_NOCACHE = 0x0400;
+
+/// don't reserve needed swap area
+pub const MAP_NORESERVE = 0x0040;
+pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
+
+/// [XSI] no hang in wait/no child to reap
+pub const WNOHANG = 0x00000001;
+
+/// [XSI] notify on stop, untraced child
+pub const WUNTRACED = 0x00000002;
+
+/// take signal on signal stack
+pub const SA_ONSTACK = 0x0001;
+
+/// restart system on signal return
+pub const SA_RESTART = 0x0002;
+
+/// reset to SIG_DFL when taking signal
+pub const SA_RESETHAND = 0x0004;
+
+/// do not generate SIGCHLD on child stop
+pub const SA_NOCLDSTOP = 0x0008;
+
+/// don't mask the signal we're delivering
+pub const SA_NODEFER = 0x0010;
+
+/// don't keep zombies around
+pub const SA_NOCLDWAIT = 0x0020;
+
+/// signal handler with SA_SIGINFO args
+pub const SA_SIGINFO = 0x0040;
+
+/// do not bounce off kernel's sigtramp
+pub const SA_USERTRAMP = 0x0100;
+
+/// signal handler with SA_SIGINFO args with 64bit regs information
+pub const SA_64REGSET = 0x0200;
+
+pub const O_LARGEFILE = 0x0000;
+pub const O_PATH = 0x0000;
+
+pub const F_OK = 0;
+pub const X_OK = 1;
+pub const W_OK = 2;
+pub const R_OK = 4;
+
+/// open for reading only
+pub const O_RDONLY = 0x0000;
+
+/// open for writing only
+pub const O_WRONLY = 0x0001;
+
+/// open for reading and writing
+pub const O_RDWR = 0x0002;
+
+/// do not block on open or for data to become available
+pub const O_NONBLOCK = 0x0004;
+
+/// append on each write
+pub const O_APPEND = 0x0008;
+
+/// create file if it does not exist
+pub const O_CREAT = 0x0200;
+
+/// truncate size to 0
+pub const O_TRUNC = 0x0400;
+
+/// error if O_CREAT and the file exists
+pub const O_EXCL = 0x0800;
+
+/// atomically obtain a shared lock
+pub const O_SHLOCK = 0x0010;
+
+/// atomically obtain an exclusive lock
+pub const O_EXLOCK = 0x0020;
+
+/// do not follow symlinks
+pub const O_NOFOLLOW = 0x0100;
+
+/// allow open of symlinks
+pub const O_SYMLINK = 0x200000;
+
+/// descriptor requested for event notifications only
+pub const O_EVTONLY = 0x8000;
+
+/// mark as close-on-exec
+pub const O_CLOEXEC = 0x1000000;
+
+pub const O_ACCMODE = 3;
+pub const O_ALERT = 536870912;
+pub const O_ASYNC = 64;
+pub const O_DIRECTORY = 1048576;
+pub const O_DP_GETRAWENCRYPTED = 1;
+pub const O_DP_GETRAWUNENCRYPTED = 2;
+pub const O_DSYNC = 4194304;
+pub const O_FSYNC = O_SYNC;
+pub const O_NOCTTY = 131072;
+pub const O_POPUP = 2147483648;
+pub const O_SYNC = 128;
+
+pub const SEEK_SET = 0x0;
+pub const SEEK_CUR = 0x1;
+pub const SEEK_END = 0x2;
+
+pub const DT_UNKNOWN = 0;
+pub const DT_FIFO = 1;
+pub const DT_CHR = 2;
+pub const DT_DIR = 4;
+pub const DT_BLK = 6;
+pub const DT_REG = 8;
+pub const DT_LNK = 10;
+pub const DT_SOCK = 12;
+pub const DT_WHT = 14;
+
+/// block specified signal set
+pub const SIG_BLOCK = 1;
+
+/// unblock specified signal set
+pub const SIG_UNBLOCK = 2;
+
+/// set specified signal set
+pub const SIG_SETMASK = 3;
+
+/// hangup
+pub const SIGHUP = 1;
+
+/// interrupt
+pub const SIGINT = 2;
+
+/// quit
+pub const SIGQUIT = 3;
+
+/// illegal instruction (not reset when caught)
+pub const SIGILL = 4;
+
+/// trace trap (not reset when caught)
+pub const SIGTRAP = 5;
+
+/// abort()
+pub const SIGABRT = 6;
+
+/// pollable event ([XSR] generated, not supported)
+pub const SIGPOLL = 7;
+
+/// compatibility
+pub const SIGIOT = SIGABRT;
+
+/// EMT instruction
+pub const SIGEMT = 7;
+
+/// floating point exception
+pub const SIGFPE = 8;
+
+/// kill (cannot be caught or ignored)
+pub const SIGKILL = 9;
+
+/// bus error
+pub const SIGBUS = 10;
+
+/// segmentation violation
+pub const SIGSEGV = 11;
+
+/// bad argument to system call
+pub const SIGSYS = 12;
+
+/// write on a pipe with no one to read it
+pub const SIGPIPE = 13;
+
+/// alarm clock
+pub const SIGALRM = 14;
+
+/// software termination signal from kill
+pub const SIGTERM = 15;
+
+/// urgent condition on IO channel
+pub const SIGURG = 16;
+
+/// sendable stop signal not from tty
+pub const SIGSTOP = 17;
+
+/// stop signal from tty
+pub const SIGTSTP = 18;
+
+/// continue a stopped process
+pub const SIGCONT = 19;
+
+/// to parent on child stop or exit
+pub const SIGCHLD = 20;
+
+/// to readers pgrp upon background tty read
+pub const SIGTTIN = 21;
+
+/// like TTIN for output if (tp->t_local&LTOSTOP)
+pub const SIGTTOU = 22;
+
+/// input/output possible signal
+pub const SIGIO = 23;
+
+/// exceeded CPU time limit
+pub const SIGXCPU = 24;
+
+/// exceeded file size limit
+pub const SIGXFSZ = 25;
+
+/// virtual time alarm
+pub const SIGVTALRM = 26;
+
+/// profiling time alarm
+pub const SIGPROF = 27;
+
+/// window size changes
+pub const SIGWINCH = 28;
+
+/// information request
+pub const SIGINFO = 29;
+
+/// user defined signal 1
+pub const SIGUSR1 = 30;
+
+/// user defined signal 2
+pub const SIGUSR2 = 31;
+
+/// no flag value
+pub const KEVENT_FLAG_NONE = 0x000;
+
+/// immediate timeout
+pub const KEVENT_FLAG_IMMEDIATE = 0x001;
+
+/// output events only include change
+pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
+
+/// add event to kq (implies enable)
+pub const EV_ADD = 0x0001;
+
+/// delete event from kq
+pub const EV_DELETE = 0x0002;
+
+/// enable event
+pub const EV_ENABLE = 0x0004;
+
+/// disable event (not reported)
+pub const EV_DISABLE = 0x0008;
+
+/// only report one occurrence
+pub const EV_ONESHOT = 0x0010;
+
+/// clear event state after reporting
+pub const EV_CLEAR = 0x0020;
+
+/// force immediate event output
+/// ... with or without EV_ERROR
+/// ... use KEVENT_FLAG_ERROR_EVENTS
+/// on syscalls supporting flags
+pub const EV_RECEIPT = 0x0040;
+
+/// disable event after reporting
+pub const EV_DISPATCH = 0x0080;
+
+/// unique kevent per udata value
+pub const EV_UDATA_SPECIFIC = 0x0100;
+
+/// ... in combination with EV_DELETE
+/// will defer delete until udata-specific
+/// event enabled. EINPROGRESS will be
+/// returned to indicate the deferral
+pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC;
+
+/// report that source has vanished
+/// ... only valid with EV_DISPATCH2
+pub const EV_VANISHED = 0x0200;
+
+/// reserved by system
+pub const EV_SYSFLAGS = 0xF000;
+
+/// filter-specific flag
+pub const EV_FLAG0 = 0x1000;
+
+/// filter-specific flag
+pub const EV_FLAG1 = 0x2000;
+
+/// EOF detected
+pub const EV_EOF = 0x8000;
+
+/// error, data contains errno
+pub const EV_ERROR = 0x4000;
+
+pub const EV_POLL = EV_FLAG0;
+pub const EV_OOBAND = EV_FLAG1;
+
+pub const EVFILT_READ = -1;
+pub const EVFILT_WRITE = -2;
+
+/// attached to aio requests
+pub const EVFILT_AIO = -3;
+
+/// attached to vnodes
+pub const EVFILT_VNODE = -4;
+
+/// attached to struct proc
+pub const EVFILT_PROC = -5;
+
+/// attached to struct proc
+pub const EVFILT_SIGNAL = -6;
+
+/// timers
+pub const EVFILT_TIMER = -7;
+
+/// Mach portsets
+pub const EVFILT_MACHPORT = -8;
+
+/// Filesystem events
+pub const EVFILT_FS = -9;
+
+/// User events
+pub const EVFILT_USER = -10;
+
+/// Virtual memory events
+pub const EVFILT_VM = -12;
+
+/// Exception events
+pub const EVFILT_EXCEPT = -15;
+
+pub const EVFILT_SYSCOUNT = 17;
+
+/// On input, NOTE_TRIGGER causes the event to be triggered for output.
+pub const NOTE_TRIGGER = 0x01000000;
+
+/// ignore input fflags
+pub const NOTE_FFNOP = 0x00000000;
+
+/// and fflags
+pub const NOTE_FFAND = 0x40000000;
+
+/// or fflags
+pub const NOTE_FFOR = 0x80000000;
+
+/// copy fflags
+pub const NOTE_FFCOPY = 0xc0000000;
+
+/// mask for operations
+pub const NOTE_FFCTRLMASK = 0xc0000000;
+pub const NOTE_FFLAGSMASK = 0x00ffffff;
+
+/// low water mark
+pub const NOTE_LOWAT = 0x00000001;
+
+/// OOB data
+pub const NOTE_OOB = 0x00000002;
+
+/// vnode was removed
+pub const NOTE_DELETE = 0x00000001;
+
+/// data contents changed
+pub const NOTE_WRITE = 0x00000002;
+
+/// size increased
+pub const NOTE_EXTEND = 0x00000004;
+
+/// attributes changed
+pub const NOTE_ATTRIB = 0x00000008;
+
+/// link count changed
+pub const NOTE_LINK = 0x00000010;
+
+/// vnode was renamed
+pub const NOTE_RENAME = 0x00000020;
+
+/// vnode access was revoked
+pub const NOTE_REVOKE = 0x00000040;
+
+/// No specific vnode event: to test for EVFILT_READ activation
+pub const NOTE_NONE = 0x00000080;
+
+/// vnode was unlocked by flock(2)
+pub const NOTE_FUNLOCK = 0x00000100;
+
+/// process exited
+pub const NOTE_EXIT = 0x80000000;
+
+/// process forked
+pub const NOTE_FORK = 0x40000000;
+
+/// process exec'd
+pub const NOTE_EXEC = 0x20000000;
+
+/// shared with EVFILT_SIGNAL
+pub const NOTE_SIGNAL = 0x08000000;
+
+/// exit status to be returned, valid for child process only
+pub const NOTE_EXITSTATUS = 0x04000000;
+
+/// provide details on reasons for exit
+pub const NOTE_EXIT_DETAIL = 0x02000000;
+
+/// mask for signal & exit status
+pub const NOTE_PDATAMASK = 0x000fffff;
+pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
+
+pub const NOTE_EXIT_DETAIL_MASK = 0x00070000;
+pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000;
+pub const NOTE_EXIT_MEMORY = 0x00020000;
+pub const NOTE_EXIT_CSERROR = 0x00040000;
+
+/// will react on memory pressure
+pub const NOTE_VM_PRESSURE = 0x80000000;
+
+/// will quit on memory pressure, possibly after cleaning up dirty state
+pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000;
+
+/// will quit immediately on memory pressure
+pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
+
+/// there was an error
+pub const NOTE_VM_ERROR = 0x10000000;
+
+/// data is seconds
+pub const NOTE_SECONDS = 0x00000001;
+
+/// data is microseconds
+pub const NOTE_USECONDS = 0x00000002;
+
+/// data is nanoseconds
+pub const NOTE_NSECONDS = 0x00000004;
+
+/// absolute timeout
+pub const NOTE_ABSOLUTE = 0x00000008;
+
+/// ext[1] holds leeway for power aware timers
+pub const NOTE_LEEWAY = 0x00000010;
+
+/// system does minimal timer coalescing
+pub const NOTE_CRITICAL = 0x00000020;
+
+/// system does maximum timer coalescing
+pub const NOTE_BACKGROUND = 0x00000040;
+pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
+
+/// data is mach absolute time units
+pub const NOTE_MACHTIME = 0x00000100;
+
+pub const AF_UNSPEC = 0;
+pub const AF_LOCAL = 1;
+pub const AF_UNIX = AF_LOCAL;
+pub const AF_INET = 2;
+pub const AF_SYS_CONTROL = 2;
+pub const AF_IMPLINK = 3;
+pub const AF_PUP = 4;
+pub const AF_CHAOS = 5;
+pub const AF_NS = 6;
+pub const AF_ISO = 7;
+pub const AF_OSI = AF_ISO;
+pub const AF_ECMA = 8;
+pub const AF_DATAKIT = 9;
+pub const AF_CCITT = 10;
+pub const AF_SNA = 11;
+pub const AF_DECnet = 12;
+pub const AF_DLI = 13;
+pub const AF_LAT = 14;
+pub const AF_HYLINK = 15;
+pub const AF_APPLETALK = 16;
+pub const AF_ROUTE = 17;
+pub const AF_LINK = 18;
+pub const AF_XTP = 19;
+pub const AF_COIP = 20;
+pub const AF_CNT = 21;
+pub const AF_RTIP = 22;
+pub const AF_IPX = 23;
+pub const AF_SIP = 24;
+pub const AF_PIP = 25;
+pub const AF_ISDN = 28;
+pub const AF_E164 = AF_ISDN;
+pub const AF_KEY = 29;
+pub const AF_INET6 = 30;
+pub const AF_NATM = 31;
+pub const AF_SYSTEM = 32;
+pub const AF_NETBIOS = 33;
+pub const AF_PPP = 34;
+pub const AF_MAX = 40;
+
+pub const PF_UNSPEC = AF_UNSPEC;
+pub const PF_LOCAL = AF_LOCAL;
+pub const PF_UNIX = PF_LOCAL;
+pub const PF_INET = AF_INET;
+pub const PF_IMPLINK = AF_IMPLINK;
+pub const PF_PUP = AF_PUP;
+pub const PF_CHAOS = AF_CHAOS;
+pub const PF_NS = AF_NS;
+pub const PF_ISO = AF_ISO;
+pub const PF_OSI = AF_ISO;
+pub const PF_ECMA = AF_ECMA;
+pub const PF_DATAKIT = AF_DATAKIT;
+pub const PF_CCITT = AF_CCITT;
+pub const PF_SNA = AF_SNA;
+pub const PF_DECnet = AF_DECnet;
+pub const PF_DLI = AF_DLI;
+pub const PF_LAT = AF_LAT;
+pub const PF_HYLINK = AF_HYLINK;
+pub const PF_APPLETALK = AF_APPLETALK;
+pub const PF_ROUTE = AF_ROUTE;
+pub const PF_LINK = AF_LINK;
+pub const PF_XTP = AF_XTP;
+pub const PF_COIP = AF_COIP;
+pub const PF_CNT = AF_CNT;
+pub const PF_SIP = AF_SIP;
+pub const PF_IPX = AF_IPX;
+pub const PF_RTIP = AF_RTIP;
+pub const PF_PIP = AF_PIP;
+pub const PF_ISDN = AF_ISDN;
+pub const PF_KEY = AF_KEY;
+pub const PF_INET6 = AF_INET6;
+pub const PF_NATM = AF_NATM;
+pub const PF_SYSTEM = AF_SYSTEM;
+pub const PF_NETBIOS = AF_NETBIOS;
+pub const PF_PPP = AF_PPP;
+pub const PF_MAX = AF_MAX;
+
+pub const SYSPROTO_EVENT = 1;
+pub const SYSPROTO_CONTROL = 2;
+
+pub const SOCK_STREAM = 1;
+pub const SOCK_DGRAM = 2;
+pub const SOCK_RAW = 3;
+pub const SOCK_RDM = 4;
+pub const SOCK_SEQPACKET = 5;
+pub const SOCK_MAXADDRLEN = 255;
+
+pub const IPPROTO_ICMP = 1;
+pub const IPPROTO_ICMPV6 = 58;
+pub const IPPROTO_TCP = 6;
+pub const IPPROTO_UDP = 17;
+pub const IPPROTO_IP = 0;
+pub const IPPROTO_IPV6 = 41;
+
+fn wstatus(x: u32) u32 {
+ return x & 0o177;
+}
+const wstopped = 0o177;
+pub fn WEXITSTATUS(x: u32) u32 {
+ return x >> 8;
+}
+pub fn WTERMSIG(x: u32) u32 {
+ return wstatus(x);
+}
+pub fn WSTOPSIG(x: u32) u32 {
+ return x >> 8;
+}
+pub fn WIFEXITED(x: u32) bool {
+ return wstatus(x) == 0;
+}
+pub fn WIFSTOPPED(x: u32) bool {
+ return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13;
+}
+pub fn WIFSIGNALED(x: u32) bool {
+ return wstatus(x) != wstopped and wstatus(x) != 0;
+}
+
+/// Operation not permitted
+pub const EPERM = 1;
+
+/// No such file or directory
+pub const ENOENT = 2;
+
+/// No such process
+pub const ESRCH = 3;
+
+/// Interrupted system call
+pub const EINTR = 4;
+
+/// Input/output error
+pub const EIO = 5;
+
+/// Device not configured
+pub const ENXIO = 6;
+
+/// Argument list too long
+pub const E2BIG = 7;
+
+/// Exec format error
+pub const ENOEXEC = 8;
+
+/// Bad file descriptor
+pub const EBADF = 9;
+
+/// No child processes
+pub const ECHILD = 10;
+
+/// Resource deadlock avoided
+pub const EDEADLK = 11;
+
+/// Cannot allocate memory
+pub const ENOMEM = 12;
+
+/// Permission denied
+pub const EACCES = 13;
+
+/// Bad address
+pub const EFAULT = 14;
+
+/// Block device required
+pub const ENOTBLK = 15;
+
+/// Device / Resource busy
+pub const EBUSY = 16;
+
+/// File exists
+pub const EEXIST = 17;
+
+/// Cross-device link
+pub const EXDEV = 18;
+
+/// Operation not supported by device
+pub const ENODEV = 19;
+
+/// Not a directory
+pub const ENOTDIR = 20;
+
+/// Is a directory
+pub const EISDIR = 21;
+
+/// Invalid argument
+pub const EINVAL = 22;
+
+/// Too many open files in system
+pub const ENFILE = 23;
+
+/// Too many open files
+pub const EMFILE = 24;
+
+/// Inappropriate ioctl for device
+pub const ENOTTY = 25;
+
+/// Text file busy
+pub const ETXTBSY = 26;
+
+/// File too large
+pub const EFBIG = 27;
+
+/// No space left on device
+pub const ENOSPC = 28;
+
+/// Illegal seek
+pub const ESPIPE = 29;
+
+/// Read-only file system
+pub const EROFS = 30;
+
+/// Too many links
+pub const EMLINK = 31;
+/// Broken pipe
+
+// math software
+pub const EPIPE = 32;
+
+/// Numerical argument out of domain
+pub const EDOM = 33;
+/// Result too large
+
+// non-blocking and interrupt i/o
+pub const ERANGE = 34;
+
+/// Resource temporarily unavailable
+pub const EAGAIN = 35;
+
+/// Operation would block
+pub const EWOULDBLOCK = EAGAIN;
+
+/// Operation now in progress
+pub const EINPROGRESS = 36;
+/// Operation already in progress
+
+// ipc/network software -- argument errors
+pub const EALREADY = 37;
+
+/// Socket operation on non-socket
+pub const ENOTSOCK = 38;
+
+/// Destination address required
+pub const EDESTADDRREQ = 39;
+
+/// Message too long
+pub const EMSGSIZE = 40;
+
+/// Protocol wrong type for socket
+pub const EPROTOTYPE = 41;
+
+/// Protocol not available
+pub const ENOPROTOOPT = 42;
+
+/// Protocol not supported
+pub const EPROTONOSUPPORT = 43;
+
+/// Socket type not supported
+pub const ESOCKTNOSUPPORT = 44;
+
+/// Operation not supported
+pub const ENOTSUP = 45;
+
+/// Protocol family not supported
+pub const EPFNOSUPPORT = 46;
+
+/// Address family not supported by protocol family
+pub const EAFNOSUPPORT = 47;
+
+/// Address already in use
+pub const EADDRINUSE = 48;
+/// Can't assign requested address
+
+// ipc/network software -- operational errors
+pub const EADDRNOTAVAIL = 49;
+
+/// Network is down
+pub const ENETDOWN = 50;
+
+/// Network is unreachable
+pub const ENETUNREACH = 51;
+
+/// Network dropped connection on reset
+pub const ENETRESET = 52;
+
+/// Software caused connection abort
+pub const ECONNABORTED = 53;
+
+/// Connection reset by peer
+pub const ECONNRESET = 54;
+
+/// No buffer space available
+pub const ENOBUFS = 55;
+
+/// Socket is already connected
+pub const EISCONN = 56;
+
+/// Socket is not connected
+pub const ENOTCONN = 57;
+
+/// Can't send after socket shutdown
+pub const ESHUTDOWN = 58;
+
+/// Too many references: can't splice
+pub const ETOOMANYREFS = 59;
+
+/// Operation timed out
+pub const ETIMEDOUT = 60;
+
+/// Connection refused
+pub const ECONNREFUSED = 61;
+
+/// Too many levels of symbolic links
+pub const ELOOP = 62;
+
+/// File name too long
+pub const ENAMETOOLONG = 63;
+
+/// Host is down
+pub const EHOSTDOWN = 64;
+
+/// No route to host
+pub const EHOSTUNREACH = 65;
+/// Directory not empty
+
+// quotas & mush
+pub const ENOTEMPTY = 66;
+
+/// Too many processes
+pub const EPROCLIM = 67;
+
+/// Too many users
+pub const EUSERS = 68;
+/// Disc quota exceeded
+
+// Network File System
+pub const EDQUOT = 69;
+
+/// Stale NFS file handle
+pub const ESTALE = 70;
+
+/// Too many levels of remote in path
+pub const EREMOTE = 71;
+
+/// RPC struct is bad
+pub const EBADRPC = 72;
+
+/// RPC version wrong
+pub const ERPCMISMATCH = 73;
+
+/// RPC prog. not avail
+pub const EPROGUNAVAIL = 74;
+
+/// Program version wrong
+pub const EPROGMISMATCH = 75;
+
+/// Bad procedure for program
+pub const EPROCUNAVAIL = 76;
+
+/// No locks available
+pub const ENOLCK = 77;
+
+/// Function not implemented
+pub const ENOSYS = 78;
+
+/// Inappropriate file type or format
+pub const EFTYPE = 79;
+
+/// Authentication error
+pub const EAUTH = 80;
+/// Need authenticator
+
+// Intelligent device errors
+pub const ENEEDAUTH = 81;
+
+/// Device power is off
+pub const EPWROFF = 82;
+
+/// Device error, e.g. paper out
+pub const EDEVERR = 83;
+/// Value too large to be stored in data type
+
+// Program loading errors
+pub const EOVERFLOW = 84;
+
+/// Bad executable
+pub const EBADEXEC = 85;
+
+/// Bad CPU type in executable
+pub const EBADARCH = 86;
+
+/// Shared library version mismatch
+pub const ESHLIBVERS = 87;
+
+/// Malformed Macho file
+pub const EBADMACHO = 88;
+
+/// Operation canceled
+pub const ECANCELED = 89;
+
+/// Identifier removed
+pub const EIDRM = 90;
+
+/// No message of desired type
+pub const ENOMSG = 91;
+
+/// Illegal byte sequence
+pub const EILSEQ = 92;
+
+/// Attribute not found
+pub const ENOATTR = 93;
+
+/// Bad message
+pub const EBADMSG = 94;
+
+/// Reserved
+pub const EMULTIHOP = 95;
+
+/// No message available on STREAM
+pub const ENODATA = 96;
+
+/// Reserved
+pub const ENOLINK = 97;
+
+/// No STREAM resources
+pub const ENOSR = 98;
+
+/// Not a STREAM
+pub const ENOSTR = 99;
+
+/// Protocol error
+pub const EPROTO = 100;
+
+/// STREAM ioctl timeout
+pub const ETIME = 101;
+
+/// No such policy registered
+pub const ENOPOLICY = 103;
+
+/// State not recoverable
+pub const ENOTRECOVERABLE = 104;
+
+/// Previous owner died
+pub const EOWNERDEAD = 105;
+
+/// Interface output queue is full
+pub const EQFULL = 106;
+
+/// Must be equal largest errno
+pub const ELAST = 106;
diff --git a/std/os/bits/freebsd.zig b/std/os/bits/freebsd.zig
new file mode 100644
index 0000000000..1925b75f3f
--- /dev/null
+++ b/std/os/bits/freebsd.zig
@@ -0,0 +1,837 @@
+const std = @import("../../std.zig");
+const maxInt = std.math.maxInt;
+
+pub const fd_t = c_int;
+pub const pid_t = c_int;
+
+/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
+pub const Kevent = extern struct {
+ ident: usize,
+ filter: i16,
+ flags: u16,
+ fflags: u32,
+ data: i64,
+ udata: usize,
+ // TODO ext
+};
+
+pub const pthread_attr_t = extern struct {
+ __size: [56]u8,
+ __align: c_long,
+};
+
+pub const msghdr = extern struct {
+ /// optional address
+ msg_name: ?*sockaddr,
+
+ /// size of address
+ msg_namelen: socklen_t,
+
+ /// scatter/gather array
+ msg_iov: [*]iovec,
+
+ /// # elements in msg_iov
+ msg_iovlen: i32,
+
+ /// ancillary data
+ msg_control: ?*c_void,
+
+ /// ancillary data buffer len
+ msg_controllen: socklen_t,
+
+ /// flags on received message
+ msg_flags: i32,
+};
+
+pub const msghdr_const = extern struct {
+ /// optional address
+ msg_name: ?*const sockaddr,
+
+ /// size of address
+ msg_namelen: socklen_t,
+
+ /// scatter/gather array
+ msg_iov: [*]iovec_const,
+
+ /// # elements in msg_iov
+ msg_iovlen: i32,
+
+ /// ancillary data
+ msg_control: ?*c_void,
+
+ /// ancillary data buffer len
+ msg_controllen: socklen_t,
+
+ /// flags on received message
+ msg_flags: i32,
+};
+
+pub const Stat = extern struct {
+ dev: u64,
+ ino: u64,
+ nlink: usize,
+
+ mode: u16,
+ __pad0: u16,
+ uid: u32,
+ gid: u32,
+ __pad1: u32,
+ rdev: u64,
+
+ atim: timespec,
+ mtim: timespec,
+ ctim: timespec,
+ birthtim: timespec,
+
+ size: i64,
+ blocks: i64,
+ blksize: isize,
+ flags: u32,
+ gen: u64,
+ __spare: [10]u64,
+};
+
+pub const timespec = extern struct {
+ tv_sec: isize,
+ tv_nsec: isize,
+};
+
+pub const dirent = extern struct {
+ d_fileno: usize,
+ d_off: i64,
+ d_reclen: u16,
+ d_type: u8,
+ d_pad0: u8,
+ d_namlen: u16,
+ d_pad1: u16,
+ d_name: [256]u8,
+};
+
+pub const in_port_t = u16;
+pub const sa_family_t = u16;
+
+pub const sockaddr = extern union {
+ in: sockaddr_in,
+ in6: sockaddr_in6,
+};
+
+pub const sockaddr_in = extern struct {
+ len: u8,
+ family: sa_family_t,
+ port: in_port_t,
+ addr: [16]u8,
+ zero: [8]u8,
+};
+
+pub const sockaddr_in6 = extern struct {
+ len: u8,
+ family: sa_family_t,
+ port: in_port_t,
+ flowinfo: u32,
+ addr: [16]u8,
+ scope_id: u32,
+};
+
+pub const CTL_KERN = 1;
+pub const CTL_DEBUG = 5;
+
+pub const KERN_PROC = 14; // struct: process entries
+pub const KERN_PROC_PATHNAME = 12; // path to executable
+
+pub const PATH_MAX = 1024;
+
+pub const STDIN_FILENO = 0;
+pub const STDOUT_FILENO = 1;
+pub const STDERR_FILENO = 2;
+
+pub const PROT_NONE = 0;
+pub const PROT_READ = 1;
+pub const PROT_WRITE = 2;
+pub const PROT_EXEC = 4;
+
+pub const CLOCK_REALTIME = 0;
+pub const CLOCK_VIRTUAL = 1;
+pub const CLOCK_PROF = 2;
+pub const CLOCK_MONOTONIC = 4;
+pub const CLOCK_UPTIME = 5;
+pub const CLOCK_UPTIME_PRECISE = 7;
+pub const CLOCK_UPTIME_FAST = 8;
+pub const CLOCK_REALTIME_PRECISE = 9;
+pub const CLOCK_REALTIME_FAST = 10;
+pub const CLOCK_MONOTONIC_PRECISE = 11;
+pub const CLOCK_MONOTONIC_FAST = 12;
+pub const CLOCK_SECOND = 13;
+pub const CLOCK_THREAD_CPUTIME_ID = 14;
+pub const CLOCK_PROCESS_CPUTIME_ID = 15;
+
+pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
+pub const MAP_SHARED = 0x0001;
+pub const MAP_PRIVATE = 0x0002;
+pub const MAP_FIXED = 0x0010;
+pub const MAP_STACK = 0x0400;
+pub const MAP_NOSYNC = 0x0800;
+pub const MAP_ANON = 0x1000;
+pub const MAP_ANONYMOUS = MAP_ANON;
+pub const MAP_FILE = 0;
+pub const MAP_NORESERVE = 0;
+
+pub const MAP_GUARD = 0x00002000;
+pub const MAP_EXCL = 0x00004000;
+pub const MAP_NOCORE = 0x00020000;
+pub const MAP_PREFAULT_READ = 0x00040000;
+pub const MAP_32BIT = 0x00080000;
+
+pub const WNOHANG = 1;
+pub const WUNTRACED = 2;
+pub const WSTOPPED = WUNTRACED;
+pub const WCONTINUED = 4;
+pub const WNOWAIT = 8;
+pub const WEXITED = 16;
+pub const WTRAPPED = 32;
+
+pub const SA_ONSTACK = 0x0001;
+pub const SA_RESTART = 0x0002;
+pub const SA_RESETHAND = 0x0004;
+pub const SA_NOCLDSTOP = 0x0008;
+pub const SA_NODEFER = 0x0010;
+pub const SA_NOCLDWAIT = 0x0020;
+pub const SA_SIGINFO = 0x0040;
+
+pub const SIGHUP = 1;
+pub const SIGINT = 2;
+pub const SIGQUIT = 3;
+pub const SIGILL = 4;
+pub const SIGTRAP = 5;
+pub const SIGABRT = 6;
+pub const SIGIOT = SIGABRT;
+pub const SIGEMT = 7;
+pub const SIGFPE = 8;
+pub const SIGKILL = 9;
+pub const SIGBUS = 10;
+pub const SIGSEGV = 11;
+pub const SIGSYS = 12;
+pub const SIGPIPE = 13;
+pub const SIGALRM = 14;
+pub const SIGTERM = 15;
+pub const SIGURG = 16;
+pub const SIGSTOP = 17;
+pub const SIGTSTP = 18;
+pub const SIGCONT = 19;
+pub const SIGCHLD = 20;
+pub const SIGTTIN = 21;
+pub const SIGTTOU = 22;
+pub const SIGIO = 23;
+pub const SIGXCPU = 24;
+pub const SIGXFSZ = 25;
+pub const SIGVTALRM = 26;
+pub const SIGPROF = 27;
+pub const SIGWINCH = 28;
+pub const SIGINFO = 29;
+pub const SIGUSR1 = 30;
+pub const SIGUSR2 = 31;
+pub const SIGTHR = 32;
+pub const SIGLWP = SIGTHR;
+pub const SIGLIBRT = 33;
+
+pub const SIGRTMIN = 65;
+pub const SIGRTMAX = 126;
+
+// access function
+pub const F_OK = 0; // test for existence of file
+pub const X_OK = 1; // test for execute or search permission
+pub const W_OK = 2; // test for write permission
+pub const R_OK = 4; // test for read permission
+
+pub const O_RDONLY = 0x0000;
+pub const O_WRONLY = 0x0001;
+pub const O_RDWR = 0x0002;
+pub const O_ACCMODE = 0x0003;
+
+pub const O_CREAT = 0x0200;
+pub const O_EXCL = 0x0800;
+pub const O_NOCTTY = 0x8000;
+pub const O_TRUNC = 0x0400;
+pub const O_APPEND = 0x0008;
+pub const O_NONBLOCK = 0x0004;
+pub const O_DSYNC = 0o10000;
+pub const O_SYNC = 0x0080;
+pub const O_RSYNC = 0o4010000;
+pub const O_DIRECTORY = 0o200000;
+pub const O_NOFOLLOW = 0x0100;
+pub const O_CLOEXEC = 0x00100000;
+
+pub const O_ASYNC = 0x0040;
+pub const O_DIRECT = 0x00010000;
+pub const O_LARGEFILE = 0;
+pub const O_NOATIME = 0o1000000;
+pub const O_PATH = 0o10000000;
+pub const O_TMPFILE = 0o20200000;
+pub const O_NDELAY = O_NONBLOCK;
+
+pub const F_DUPFD = 0;
+pub const F_GETFD = 1;
+pub const F_SETFD = 2;
+pub const F_GETFL = 3;
+pub const F_SETFL = 4;
+
+pub const F_SETOWN = 8;
+pub const F_GETOWN = 9;
+pub const F_SETSIG = 10;
+pub const F_GETSIG = 11;
+
+pub const F_GETLK = 5;
+pub const F_SETLK = 6;
+pub const F_SETLKW = 7;
+
+pub const F_SETOWN_EX = 15;
+pub const F_GETOWN_EX = 16;
+
+pub const F_GETOWNER_UIDS = 17;
+
+pub const SEEK_SET = 0;
+pub const SEEK_CUR = 1;
+pub const SEEK_END = 2;
+
+pub const SIG_BLOCK = 1;
+pub const SIG_UNBLOCK = 2;
+pub const SIG_SETMASK = 3;
+
+pub const SOCK_STREAM = 1;
+pub const SOCK_DGRAM = 2;
+pub const SOCK_RAW = 3;
+pub const SOCK_RDM = 4;
+pub const SOCK_SEQPACKET = 5;
+
+pub const SOCK_CLOEXEC = 0x10000000;
+pub const SOCK_NONBLOCK = 0x20000000;
+
+pub const PROTO_ip = 0o000;
+pub const PROTO_icmp = 0o001;
+pub const PROTO_igmp = 0o002;
+pub const PROTO_ggp = 0o003;
+pub const PROTO_ipencap = 0o004;
+pub const PROTO_st = 0o005;
+pub const PROTO_tcp = 0o006;
+pub const PROTO_egp = 0o010;
+pub const PROTO_pup = 0o014;
+pub const PROTO_udp = 0o021;
+pub const PROTO_hmp = 0o024;
+pub const PROTO_xns_idp = 0o026;
+pub const PROTO_rdp = 0o033;
+pub const PROTO_iso_tp4 = 0o035;
+pub const PROTO_xtp = 0o044;
+pub const PROTO_ddp = 0o045;
+pub const PROTO_idpr_cmtp = 0o046;
+pub const PROTO_ipv6 = 0o051;
+pub const PROTO_ipv6_route = 0o053;
+pub const PROTO_ipv6_frag = 0o054;
+pub const PROTO_idrp = 0o055;
+pub const PROTO_rsvp = 0o056;
+pub const PROTO_gre = 0o057;
+pub const PROTO_esp = 0o062;
+pub const PROTO_ah = 0o063;
+pub const PROTO_skip = 0o071;
+pub const PROTO_ipv6_icmp = 0o072;
+pub const PROTO_ipv6_nonxt = 0o073;
+pub const PROTO_ipv6_opts = 0o074;
+pub const PROTO_rspf = 0o111;
+pub const PROTO_vmtp = 0o121;
+pub const PROTO_ospf = 0o131;
+pub const PROTO_ipip = 0o136;
+pub const PROTO_encap = 0o142;
+pub const PROTO_pim = 0o147;
+pub const PROTO_raw = 0o377;
+
+pub const PF_UNSPEC = 0;
+pub const PF_LOCAL = 1;
+pub const PF_UNIX = PF_LOCAL;
+pub const PF_FILE = PF_LOCAL;
+pub const PF_INET = 2;
+pub const PF_AX25 = 3;
+pub const PF_IPX = 4;
+pub const PF_APPLETALK = 5;
+pub const PF_NETROM = 6;
+pub const PF_BRIDGE = 7;
+pub const PF_ATMPVC = 8;
+pub const PF_X25 = 9;
+pub const PF_INET6 = 10;
+pub const PF_ROSE = 11;
+pub const PF_DECnet = 12;
+pub const PF_NETBEUI = 13;
+pub const PF_SECURITY = 14;
+pub const PF_KEY = 15;
+pub const PF_NETLINK = 16;
+pub const PF_ROUTE = PF_NETLINK;
+pub const PF_PACKET = 17;
+pub const PF_ASH = 18;
+pub const PF_ECONET = 19;
+pub const PF_ATMSVC = 20;
+pub const PF_RDS = 21;
+pub const PF_SNA = 22;
+pub const PF_IRDA = 23;
+pub const PF_PPPOX = 24;
+pub const PF_WANPIPE = 25;
+pub const PF_LLC = 26;
+pub const PF_IB = 27;
+pub const PF_MPLS = 28;
+pub const PF_CAN = 29;
+pub const PF_TIPC = 30;
+pub const PF_BLUETOOTH = 31;
+pub const PF_IUCV = 32;
+pub const PF_RXRPC = 33;
+pub const PF_ISDN = 34;
+pub const PF_PHONET = 35;
+pub const PF_IEEE802154 = 36;
+pub const PF_CAIF = 37;
+pub const PF_ALG = 38;
+pub const PF_NFC = 39;
+pub const PF_VSOCK = 40;
+pub const PF_MAX = 41;
+
+pub const AF_UNSPEC = PF_UNSPEC;
+pub const AF_LOCAL = PF_LOCAL;
+pub const AF_UNIX = AF_LOCAL;
+pub const AF_FILE = AF_LOCAL;
+pub const AF_INET = PF_INET;
+pub const AF_AX25 = PF_AX25;
+pub const AF_IPX = PF_IPX;
+pub const AF_APPLETALK = PF_APPLETALK;
+pub const AF_NETROM = PF_NETROM;
+pub const AF_BRIDGE = PF_BRIDGE;
+pub const AF_ATMPVC = PF_ATMPVC;
+pub const AF_X25 = PF_X25;
+pub const AF_INET6 = PF_INET6;
+pub const AF_ROSE = PF_ROSE;
+pub const AF_DECnet = PF_DECnet;
+pub const AF_NETBEUI = PF_NETBEUI;
+pub const AF_SECURITY = PF_SECURITY;
+pub const AF_KEY = PF_KEY;
+pub const AF_NETLINK = PF_NETLINK;
+pub const AF_ROUTE = PF_ROUTE;
+pub const AF_PACKET = PF_PACKET;
+pub const AF_ASH = PF_ASH;
+pub const AF_ECONET = PF_ECONET;
+pub const AF_ATMSVC = PF_ATMSVC;
+pub const AF_RDS = PF_RDS;
+pub const AF_SNA = PF_SNA;
+pub const AF_IRDA = PF_IRDA;
+pub const AF_PPPOX = PF_PPPOX;
+pub const AF_WANPIPE = PF_WANPIPE;
+pub const AF_LLC = PF_LLC;
+pub const AF_IB = PF_IB;
+pub const AF_MPLS = PF_MPLS;
+pub const AF_CAN = PF_CAN;
+pub const AF_TIPC = PF_TIPC;
+pub const AF_BLUETOOTH = PF_BLUETOOTH;
+pub const AF_IUCV = PF_IUCV;
+pub const AF_RXRPC = PF_RXRPC;
+pub const AF_ISDN = PF_ISDN;
+pub const AF_PHONET = PF_PHONET;
+pub const AF_IEEE802154 = PF_IEEE802154;
+pub const AF_CAIF = PF_CAIF;
+pub const AF_ALG = PF_ALG;
+pub const AF_NFC = PF_NFC;
+pub const AF_VSOCK = PF_VSOCK;
+pub const AF_MAX = PF_MAX;
+
+pub const DT_UNKNOWN = 0;
+pub const DT_FIFO = 1;
+pub const DT_CHR = 2;
+pub const DT_DIR = 4;
+pub const DT_BLK = 6;
+pub const DT_REG = 8;
+pub const DT_LNK = 10;
+pub const DT_SOCK = 12;
+pub const DT_WHT = 14;
+
+/// add event to kq (implies enable)
+pub const EV_ADD = 0x0001;
+
+/// delete event from kq
+pub const EV_DELETE = 0x0002;
+
+/// enable event
+pub const EV_ENABLE = 0x0004;
+
+/// disable event (not reported)
+pub const EV_DISABLE = 0x0008;
+
+/// only report one occurrence
+pub const EV_ONESHOT = 0x0010;
+
+/// clear event state after reporting
+pub const EV_CLEAR = 0x0020;
+
+/// force immediate event output
+/// ... with or without EV_ERROR
+/// ... use KEVENT_FLAG_ERROR_EVENTS
+/// on syscalls supporting flags
+pub const EV_RECEIPT = 0x0040;
+
+/// disable event after reporting
+pub const EV_DISPATCH = 0x0080;
+
+pub const EVFILT_READ = -1;
+pub const EVFILT_WRITE = -2;
+
+/// attached to aio requests
+pub const EVFILT_AIO = -3;
+
+/// attached to vnodes
+pub const EVFILT_VNODE = -4;
+
+/// attached to struct proc
+pub const EVFILT_PROC = -5;
+
+/// attached to struct proc
+pub const EVFILT_SIGNAL = -6;
+
+/// timers
+pub const EVFILT_TIMER = -7;
+
+/// Process descriptors
+pub const EVFILT_PROCDESC = -8;
+
+/// Filesystem events
+pub const EVFILT_FS = -9;
+
+pub const EVFILT_LIO = -10;
+
+/// User events
+pub const EVFILT_USER = -11;
+
+/// Sendfile events
+pub const EVFILT_SENDFILE = -12;
+
+pub const EVFILT_EMPTY = -13;
+
+/// On input, NOTE_TRIGGER causes the event to be triggered for output.
+pub const NOTE_TRIGGER = 0x01000000;
+
+/// ignore input fflags
+pub const NOTE_FFNOP = 0x00000000;
+
+/// and fflags
+pub const NOTE_FFAND = 0x40000000;
+
+/// or fflags
+pub const NOTE_FFOR = 0x80000000;
+
+/// copy fflags
+pub const NOTE_FFCOPY = 0xc0000000;
+
+/// mask for operations
+pub const NOTE_FFCTRLMASK = 0xc0000000;
+pub const NOTE_FFLAGSMASK = 0x00ffffff;
+
+/// low water mark
+pub const NOTE_LOWAT = 0x00000001;
+
+/// behave like poll()
+pub const NOTE_FILE_POLL = 0x00000002;
+
+/// vnode was removed
+pub const NOTE_DELETE = 0x00000001;
+
+/// data contents changed
+pub const NOTE_WRITE = 0x00000002;
+
+/// size increased
+pub const NOTE_EXTEND = 0x00000004;
+
+/// attributes changed
+pub const NOTE_ATTRIB = 0x00000008;
+
+/// link count changed
+pub const NOTE_LINK = 0x00000010;
+
+/// vnode was renamed
+pub const NOTE_RENAME = 0x00000020;
+
+/// vnode access was revoked
+pub const NOTE_REVOKE = 0x00000040;
+
+/// vnode was opened
+pub const NOTE_OPEN = 0x00000080;
+
+/// file closed, fd did not allow write
+pub const NOTE_CLOSE = 0x00000100;
+
+/// file closed, fd did allow write
+pub const NOTE_CLOSE_WRITE = 0x00000200;
+
+/// file was read
+pub const NOTE_READ = 0x00000400;
+
+/// process exited
+pub const NOTE_EXIT = 0x80000000;
+
+/// process forked
+pub const NOTE_FORK = 0x40000000;
+
+/// process exec'd
+pub const NOTE_EXEC = 0x20000000;
+
+/// mask for signal & exit status
+pub const NOTE_PDATAMASK = 0x000fffff;
+pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
+
+/// data is seconds
+pub const NOTE_SECONDS = 0x00000001;
+
+/// data is milliseconds
+pub const NOTE_MSECONDS = 0x00000002;
+
+/// data is microseconds
+pub const NOTE_USECONDS = 0x00000004;
+
+/// data is nanoseconds
+pub const NOTE_NSECONDS = 0x00000008;
+
+/// timeout is absolute
+pub const NOTE_ABSTIME = 0x00000010;
+
+pub const TCGETS = 0x5401;
+pub const TCSETS = 0x5402;
+pub const TCSETSW = 0x5403;
+pub const TCSETSF = 0x5404;
+pub const TCGETA = 0x5405;
+pub const TCSETA = 0x5406;
+pub const TCSETAW = 0x5407;
+pub const TCSETAF = 0x5408;
+pub const TCSBRK = 0x5409;
+pub const TCXONC = 0x540A;
+pub const TCFLSH = 0x540B;
+pub const TIOCEXCL = 0x540C;
+pub const TIOCNXCL = 0x540D;
+pub const TIOCSCTTY = 0x540E;
+pub const TIOCGPGRP = 0x540F;
+pub const TIOCSPGRP = 0x5410;
+pub const TIOCOUTQ = 0x5411;
+pub const TIOCSTI = 0x5412;
+pub const TIOCGWINSZ = 0x5413;
+pub const TIOCSWINSZ = 0x5414;
+pub const TIOCMGET = 0x5415;
+pub const TIOCMBIS = 0x5416;
+pub const TIOCMBIC = 0x5417;
+pub const TIOCMSET = 0x5418;
+pub const TIOCGSOFTCAR = 0x5419;
+pub const TIOCSSOFTCAR = 0x541A;
+pub const FIONREAD = 0x541B;
+pub const TIOCINQ = FIONREAD;
+pub const TIOCLINUX = 0x541C;
+pub const TIOCCONS = 0x541D;
+pub const TIOCGSERIAL = 0x541E;
+pub const TIOCSSERIAL = 0x541F;
+pub const TIOCPKT = 0x5420;
+pub const FIONBIO = 0x5421;
+pub const TIOCNOTTY = 0x5422;
+pub const TIOCSETD = 0x5423;
+pub const TIOCGETD = 0x5424;
+pub const TCSBRKP = 0x5425;
+pub const TIOCSBRK = 0x5427;
+pub const TIOCCBRK = 0x5428;
+pub const TIOCGSID = 0x5429;
+pub const TIOCGRS485 = 0x542E;
+pub const TIOCSRS485 = 0x542F;
+pub const TIOCGPTN = 0x80045430;
+pub const TIOCSPTLCK = 0x40045431;
+pub const TIOCGDEV = 0x80045432;
+pub const TCGETX = 0x5432;
+pub const TCSETX = 0x5433;
+pub const TCSETXF = 0x5434;
+pub const TCSETXW = 0x5435;
+pub const TIOCSIG = 0x40045436;
+pub const TIOCVHANGUP = 0x5437;
+pub const TIOCGPKT = 0x80045438;
+pub const TIOCGPTLCK = 0x80045439;
+pub const TIOCGEXCL = 0x80045440;
+
+pub fn WEXITSTATUS(s: u32) u32 {
+ return (s & 0xff00) >> 8;
+}
+pub fn WTERMSIG(s: u32) u32 {
+ return s & 0x7f;
+}
+pub fn WSTOPSIG(s: u32) u32 {
+ return WEXITSTATUS(s);
+}
+pub fn WIFEXITED(s: u32) bool {
+ return WTERMSIG(s) == 0;
+}
+pub fn WIFSTOPPED(s: u32) bool {
+ return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
+}
+pub fn WIFSIGNALED(s: u32) bool {
+ return (s & 0xffff) -% 1 < 0xff;
+}
+
+pub const winsize = extern struct {
+ ws_row: u16,
+ ws_col: u16,
+ ws_xpixel: u16,
+ ws_ypixel: u16,
+};
+
+const NSIG = 32;
+
+pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
+pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
+pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
+
+/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
+pub const Sigaction = extern struct {
+ /// signal handler
+ __sigaction_u: extern union {
+ __sa_handler: extern fn (i32) void,
+ __sa_sigaction: extern fn (i32, *__siginfo, usize) void,
+ },
+
+ /// see signal options
+ sa_flags: u32,
+
+ /// signal mask to apply
+ sa_mask: sigset_t,
+};
+
+pub const _SIG_WORDS = 4;
+pub const _SIG_MAXSIG = 128;
+
+pub inline fn _SIG_IDX(sig: usize) usize {
+ return sig - 1;
+}
+pub inline fn _SIG_WORD(sig: usize) usize {
+ return_SIG_IDX(sig) >> 5;
+}
+pub inline fn _SIG_BIT(sig: usize) usize {
+ return 1 << (_SIG_IDX(sig) & 31);
+}
+pub inline fn _SIG_VALID(sig: usize) usize {
+ return sig <= _SIG_MAXSIG and sig > 0;
+}
+
+pub const sigset_t = extern struct {
+ __bits: [_SIG_WORDS]u32,
+};
+
+pub const EPERM = 1; // Operation not permitted
+pub const ENOENT = 2; // No such file or directory
+pub const ESRCH = 3; // No such process
+pub const EINTR = 4; // Interrupted system call
+pub const EIO = 5; // Input/output error
+pub const ENXIO = 6; // Device not configured
+pub const E2BIG = 7; // Argument list too long
+pub const ENOEXEC = 8; // Exec format error
+pub const EBADF = 9; // Bad file descriptor
+pub const ECHILD = 10; // No child processes
+pub const EDEADLK = 11; // Resource deadlock avoided
+// 11 was EAGAIN
+pub const ENOMEM = 12; // Cannot allocate memory
+pub const EACCES = 13; // Permission denied
+pub const EFAULT = 14; // Bad address
+pub const ENOTBLK = 15; // Block device required
+pub const EBUSY = 16; // Device busy
+pub const EEXIST = 17; // File exists
+pub const EXDEV = 18; // Cross-device link
+pub const ENODEV = 19; // Operation not supported by device
+pub const ENOTDIR = 20; // Not a directory
+pub const EISDIR = 21; // Is a directory
+pub const EINVAL = 22; // Invalid argument
+pub const ENFILE = 23; // Too many open files in system
+pub const EMFILE = 24; // Too many open files
+pub const ENOTTY = 25; // Inappropriate ioctl for device
+pub const ETXTBSY = 26; // Text file busy
+pub const EFBIG = 27; // File too large
+pub const ENOSPC = 28; // No space left on device
+pub const ESPIPE = 29; // Illegal seek
+pub const EROFS = 30; // Read-only filesystem
+pub const EMLINK = 31; // Too many links
+pub const EPIPE = 32; // Broken pipe
+
+// math software
+pub const EDOM = 33; // Numerical argument out of domain
+pub const ERANGE = 34; // Result too large
+
+// non-blocking and interrupt i/o
+pub const EAGAIN = 35; // Resource temporarily unavailable
+pub const EWOULDBLOCK = EAGAIN; // Operation would block
+pub const EINPROGRESS = 36; // Operation now in progress
+pub const EALREADY = 37; // Operation already in progress
+
+// ipc/network software -- argument errors
+pub const ENOTSOCK = 38; // Socket operation on non-socket
+pub const EDESTADDRREQ = 39; // Destination address required
+pub const EMSGSIZE = 40; // Message too long
+pub const EPROTOTYPE = 41; // Protocol wrong type for socket
+pub const ENOPROTOOPT = 42; // Protocol not available
+pub const EPROTONOSUPPORT = 43; // Protocol not supported
+pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
+pub const EOPNOTSUPP = 45; // Operation not supported
+pub const ENOTSUP = EOPNOTSUPP; // Operation not supported
+pub const EPFNOSUPPORT = 46; // Protocol family not supported
+pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
+pub const EADDRINUSE = 48; // Address already in use
+pub const EADDRNOTAVAIL = 49; // Can't assign requested address
+
+// ipc/network software -- operational errors
+pub const ENETDOWN = 50; // Network is down
+pub const ENETUNREACH = 51; // Network is unreachable
+pub const ENETRESET = 52; // Network dropped connection on reset
+pub const ECONNABORTED = 53; // Software caused connection abort
+pub const ECONNRESET = 54; // Connection reset by peer
+pub const ENOBUFS = 55; // No buffer space available
+pub const EISCONN = 56; // Socket is already connected
+pub const ENOTCONN = 57; // Socket is not connected
+pub const ESHUTDOWN = 58; // Can't send after socket shutdown
+pub const ETOOMANYREFS = 59; // Too many references: can't splice
+pub const ETIMEDOUT = 60; // Operation timed out
+pub const ECONNREFUSED = 61; // Connection refused
+
+pub const ELOOP = 62; // Too many levels of symbolic links
+pub const ENAMETOOLONG = 63; // File name too long
+
+// should be rearranged
+pub const EHOSTDOWN = 64; // Host is down
+pub const EHOSTUNREACH = 65; // No route to host
+pub const ENOTEMPTY = 66; // Directory not empty
+
+// quotas & mush
+pub const EPROCLIM = 67; // Too many processes
+pub const EUSERS = 68; // Too many users
+pub const EDQUOT = 69; // Disc quota exceeded
+
+// Network File System
+pub const ESTALE = 70; // Stale NFS file handle
+pub const EREMOTE = 71; // Too many levels of remote in path
+pub const EBADRPC = 72; // RPC struct is bad
+pub const ERPCMISMATCH = 73; // RPC version wrong
+pub const EPROGUNAVAIL = 74; // RPC prog. not avail
+pub const EPROGMISMATCH = 75; // Program version wrong
+pub const EPROCUNAVAIL = 76; // Bad procedure for program
+
+pub const ENOLCK = 77; // No locks available
+pub const ENOSYS = 78; // Function not implemented
+
+pub const EFTYPE = 79; // Inappropriate file type or format
+pub const EAUTH = 80; // Authentication error
+pub const ENEEDAUTH = 81; // Need authenticator
+pub const EIDRM = 82; // Identifier removed
+pub const ENOMSG = 83; // No message of desired type
+pub const EOVERFLOW = 84; // Value too large to be stored in data type
+pub const ECANCELED = 85; // Operation canceled
+pub const EILSEQ = 86; // Illegal byte sequence
+pub const ENOATTR = 87; // Attribute not found
+
+pub const EDOOFUS = 88; // Programming error
+
+pub const EBADMSG = 89; // Bad message
+pub const EMULTIHOP = 90; // Multihop attempted
+pub const ENOLINK = 91; // Link has been severed
+pub const EPROTO = 92; // Protocol error
+
+pub const ENOTCAPABLE = 93; // Capabilities insufficient
+pub const ECAPMODE = 94; // Not permitted in capability mode
+pub const ENOTRECOVERABLE = 95; // State not recoverable
+pub const EOWNERDEAD = 96; // Previous owner died
+
+pub const ELAST = 96; // Must be equal largest errno
diff --git a/std/os/bits/linux.zig b/std/os/bits/linux.zig
new file mode 100644
index 0000000000..6532e72362
--- /dev/null
+++ b/std/os/bits/linux.zig
@@ -0,0 +1,931 @@
+const builtin = @import("builtin");
+const std = @import("../../std.zig");
+const maxInt = std.math.maxInt;
+use @import("../bits.zig");
+
+pub use @import("linux/errno.zig");
+pub use switch (builtin.arch) {
+ .x86_64 => @import("linux/x86_64.zig"),
+ .aarch64 => @import("linux/arm64.zig"),
+ else => struct {},
+};
+
+pub const pid_t = i32;
+pub const fd_t = i32;
+
+pub const PATH_MAX = 4096;
+pub const IOV_MAX = 1024;
+
+pub const STDIN_FILENO = 0;
+pub const STDOUT_FILENO = 1;
+pub const STDERR_FILENO = 2;
+
+pub const FUTEX_WAIT = 0;
+pub const FUTEX_WAKE = 1;
+pub const FUTEX_FD = 2;
+pub const FUTEX_REQUEUE = 3;
+pub const FUTEX_CMP_REQUEUE = 4;
+pub const FUTEX_WAKE_OP = 5;
+pub const FUTEX_LOCK_PI = 6;
+pub const FUTEX_UNLOCK_PI = 7;
+pub const FUTEX_TRYLOCK_PI = 8;
+pub const FUTEX_WAIT_BITSET = 9;
+
+pub const FUTEX_PRIVATE_FLAG = 128;
+
+pub const FUTEX_CLOCK_REALTIME = 256;
+
+pub const PROT_NONE = 0;
+pub const PROT_READ = 1;
+pub const PROT_WRITE = 2;
+pub const PROT_EXEC = 4;
+pub const PROT_GROWSDOWN = 0x01000000;
+pub const PROT_GROWSUP = 0x02000000;
+
+pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
+pub const MAP_SHARED = 0x01;
+pub const MAP_PRIVATE = 0x02;
+pub const MAP_TYPE = 0x0f;
+pub const MAP_FIXED = 0x10;
+pub const MAP_ANONYMOUS = 0x20;
+pub const MAP_NORESERVE = 0x4000;
+pub const MAP_GROWSDOWN = 0x0100;
+pub const MAP_DENYWRITE = 0x0800;
+pub const MAP_EXECUTABLE = 0x1000;
+pub const MAP_LOCKED = 0x2000;
+pub const MAP_POPULATE = 0x8000;
+pub const MAP_NONBLOCK = 0x10000;
+pub const MAP_STACK = 0x20000;
+pub const MAP_HUGETLB = 0x40000;
+pub const MAP_FILE = 0;
+
+pub const F_OK = 0;
+pub const X_OK = 1;
+pub const W_OK = 2;
+pub const R_OK = 4;
+
+pub const WNOHANG = 1;
+pub const WUNTRACED = 2;
+pub const WSTOPPED = 2;
+pub const WEXITED = 4;
+pub const WCONTINUED = 8;
+pub const WNOWAIT = 0x1000000;
+
+pub const SA_NOCLDSTOP = 1;
+pub const SA_NOCLDWAIT = 2;
+pub const SA_SIGINFO = 4;
+pub const SA_ONSTACK = 0x08000000;
+pub const SA_RESTART = 0x10000000;
+pub const SA_NODEFER = 0x40000000;
+pub const SA_RESETHAND = 0x80000000;
+pub const SA_RESTORER = 0x04000000;
+
+pub const SIGHUP = 1;
+pub const SIGINT = 2;
+pub const SIGQUIT = 3;
+pub const SIGILL = 4;
+pub const SIGTRAP = 5;
+pub const SIGABRT = 6;
+pub const SIGIOT = SIGABRT;
+pub const SIGBUS = 7;
+pub const SIGFPE = 8;
+pub const SIGKILL = 9;
+pub const SIGUSR1 = 10;
+pub const SIGSEGV = 11;
+pub const SIGUSR2 = 12;
+pub const SIGPIPE = 13;
+pub const SIGALRM = 14;
+pub const SIGTERM = 15;
+pub const SIGSTKFLT = 16;
+pub const SIGCHLD = 17;
+pub const SIGCONT = 18;
+pub const SIGSTOP = 19;
+pub const SIGTSTP = 20;
+pub const SIGTTIN = 21;
+pub const SIGTTOU = 22;
+pub const SIGURG = 23;
+pub const SIGXCPU = 24;
+pub const SIGXFSZ = 25;
+pub const SIGVTALRM = 26;
+pub const SIGPROF = 27;
+pub const SIGWINCH = 28;
+pub const SIGIO = 29;
+pub const SIGPOLL = 29;
+pub const SIGPWR = 30;
+pub const SIGSYS = 31;
+pub const SIGUNUSED = SIGSYS;
+
+pub const O_RDONLY = 0o0;
+pub const O_WRONLY = 0o1;
+pub const O_RDWR = 0o2;
+
+pub const SEEK_SET = 0;
+pub const SEEK_CUR = 1;
+pub const SEEK_END = 2;
+
+pub const SIG_BLOCK = 0;
+pub const SIG_UNBLOCK = 1;
+pub const SIG_SETMASK = 2;
+
+pub const PROTO_ip = 0o000;
+pub const PROTO_icmp = 0o001;
+pub const PROTO_igmp = 0o002;
+pub const PROTO_ggp = 0o003;
+pub const PROTO_ipencap = 0o004;
+pub const PROTO_st = 0o005;
+pub const PROTO_tcp = 0o006;
+pub const PROTO_egp = 0o010;
+pub const PROTO_pup = 0o014;
+pub const PROTO_udp = 0o021;
+pub const PROTO_hmp = 0o024;
+pub const PROTO_xns_idp = 0o026;
+pub const PROTO_rdp = 0o033;
+pub const PROTO_iso_tp4 = 0o035;
+pub const PROTO_xtp = 0o044;
+pub const PROTO_ddp = 0o045;
+pub const PROTO_idpr_cmtp = 0o046;
+pub const PROTO_ipv6 = 0o051;
+pub const PROTO_ipv6_route = 0o053;
+pub const PROTO_ipv6_frag = 0o054;
+pub const PROTO_idrp = 0o055;
+pub const PROTO_rsvp = 0o056;
+pub const PROTO_gre = 0o057;
+pub const PROTO_esp = 0o062;
+pub const PROTO_ah = 0o063;
+pub const PROTO_skip = 0o071;
+pub const PROTO_ipv6_icmp = 0o072;
+pub const PROTO_ipv6_nonxt = 0o073;
+pub const PROTO_ipv6_opts = 0o074;
+pub const PROTO_rspf = 0o111;
+pub const PROTO_vmtp = 0o121;
+pub const PROTO_ospf = 0o131;
+pub const PROTO_ipip = 0o136;
+pub const PROTO_encap = 0o142;
+pub const PROTO_pim = 0o147;
+pub const PROTO_raw = 0o377;
+
+pub const SHUT_RD = 0;
+pub const SHUT_WR = 1;
+pub const SHUT_RDWR = 2;
+
+pub const SOCK_STREAM = 1;
+pub const SOCK_DGRAM = 2;
+pub const SOCK_RAW = 3;
+pub const SOCK_RDM = 4;
+pub const SOCK_SEQPACKET = 5;
+pub const SOCK_DCCP = 6;
+pub const SOCK_PACKET = 10;
+pub const SOCK_CLOEXEC = 0o2000000;
+pub const SOCK_NONBLOCK = 0o4000;
+
+pub const PF_UNSPEC = 0;
+pub const PF_LOCAL = 1;
+pub const PF_UNIX = PF_LOCAL;
+pub const PF_FILE = PF_LOCAL;
+pub const PF_INET = 2;
+pub const PF_AX25 = 3;
+pub const PF_IPX = 4;
+pub const PF_APPLETALK = 5;
+pub const PF_NETROM = 6;
+pub const PF_BRIDGE = 7;
+pub const PF_ATMPVC = 8;
+pub const PF_X25 = 9;
+pub const PF_INET6 = 10;
+pub const PF_ROSE = 11;
+pub const PF_DECnet = 12;
+pub const PF_NETBEUI = 13;
+pub const PF_SECURITY = 14;
+pub const PF_KEY = 15;
+pub const PF_NETLINK = 16;
+pub const PF_ROUTE = PF_NETLINK;
+pub const PF_PACKET = 17;
+pub const PF_ASH = 18;
+pub const PF_ECONET = 19;
+pub const PF_ATMSVC = 20;
+pub const PF_RDS = 21;
+pub const PF_SNA = 22;
+pub const PF_IRDA = 23;
+pub const PF_PPPOX = 24;
+pub const PF_WANPIPE = 25;
+pub const PF_LLC = 26;
+pub const PF_IB = 27;
+pub const PF_MPLS = 28;
+pub const PF_CAN = 29;
+pub const PF_TIPC = 30;
+pub const PF_BLUETOOTH = 31;
+pub const PF_IUCV = 32;
+pub const PF_RXRPC = 33;
+pub const PF_ISDN = 34;
+pub const PF_PHONET = 35;
+pub const PF_IEEE802154 = 36;
+pub const PF_CAIF = 37;
+pub const PF_ALG = 38;
+pub const PF_NFC = 39;
+pub const PF_VSOCK = 40;
+pub const PF_KCM = 41;
+pub const PF_QIPCRTR = 42;
+pub const PF_SMC = 43;
+pub const PF_MAX = 44;
+
+pub const AF_UNSPEC = PF_UNSPEC;
+pub const AF_LOCAL = PF_LOCAL;
+pub const AF_UNIX = AF_LOCAL;
+pub const AF_FILE = AF_LOCAL;
+pub const AF_INET = PF_INET;
+pub const AF_AX25 = PF_AX25;
+pub const AF_IPX = PF_IPX;
+pub const AF_APPLETALK = PF_APPLETALK;
+pub const AF_NETROM = PF_NETROM;
+pub const AF_BRIDGE = PF_BRIDGE;
+pub const AF_ATMPVC = PF_ATMPVC;
+pub const AF_X25 = PF_X25;
+pub const AF_INET6 = PF_INET6;
+pub const AF_ROSE = PF_ROSE;
+pub const AF_DECnet = PF_DECnet;
+pub const AF_NETBEUI = PF_NETBEUI;
+pub const AF_SECURITY = PF_SECURITY;
+pub const AF_KEY = PF_KEY;
+pub const AF_NETLINK = PF_NETLINK;
+pub const AF_ROUTE = PF_ROUTE;
+pub const AF_PACKET = PF_PACKET;
+pub const AF_ASH = PF_ASH;
+pub const AF_ECONET = PF_ECONET;
+pub const AF_ATMSVC = PF_ATMSVC;
+pub const AF_RDS = PF_RDS;
+pub const AF_SNA = PF_SNA;
+pub const AF_IRDA = PF_IRDA;
+pub const AF_PPPOX = PF_PPPOX;
+pub const AF_WANPIPE = PF_WANPIPE;
+pub const AF_LLC = PF_LLC;
+pub const AF_IB = PF_IB;
+pub const AF_MPLS = PF_MPLS;
+pub const AF_CAN = PF_CAN;
+pub const AF_TIPC = PF_TIPC;
+pub const AF_BLUETOOTH = PF_BLUETOOTH;
+pub const AF_IUCV = PF_IUCV;
+pub const AF_RXRPC = PF_RXRPC;
+pub const AF_ISDN = PF_ISDN;
+pub const AF_PHONET = PF_PHONET;
+pub const AF_IEEE802154 = PF_IEEE802154;
+pub const AF_CAIF = PF_CAIF;
+pub const AF_ALG = PF_ALG;
+pub const AF_NFC = PF_NFC;
+pub const AF_VSOCK = PF_VSOCK;
+pub const AF_KCM = PF_KCM;
+pub const AF_QIPCRTR = PF_QIPCRTR;
+pub const AF_SMC = PF_SMC;
+pub const AF_MAX = PF_MAX;
+
+pub const SO_DEBUG = 1;
+pub const SO_REUSEADDR = 2;
+pub const SO_TYPE = 3;
+pub const SO_ERROR = 4;
+pub const SO_DONTROUTE = 5;
+pub const SO_BROADCAST = 6;
+pub const SO_SNDBUF = 7;
+pub const SO_RCVBUF = 8;
+pub const SO_KEEPALIVE = 9;
+pub const SO_OOBINLINE = 10;
+pub const SO_NO_CHECK = 11;
+pub const SO_PRIORITY = 12;
+pub const SO_LINGER = 13;
+pub const SO_BSDCOMPAT = 14;
+pub const SO_REUSEPORT = 15;
+pub const SO_PASSCRED = 16;
+pub const SO_PEERCRED = 17;
+pub const SO_RCVLOWAT = 18;
+pub const SO_SNDLOWAT = 19;
+pub const SO_RCVTIMEO = 20;
+pub const SO_SNDTIMEO = 21;
+pub const SO_ACCEPTCONN = 30;
+pub const SO_SNDBUFFORCE = 32;
+pub const SO_RCVBUFFORCE = 33;
+pub const SO_PROTOCOL = 38;
+pub const SO_DOMAIN = 39;
+
+pub const SO_SECURITY_AUTHENTICATION = 22;
+pub const SO_SECURITY_ENCRYPTION_TRANSPORT = 23;
+pub const SO_SECURITY_ENCRYPTION_NETWORK = 24;
+
+pub const SO_BINDTODEVICE = 25;
+
+pub const SO_ATTACH_FILTER = 26;
+pub const SO_DETACH_FILTER = 27;
+pub const SO_GET_FILTER = SO_ATTACH_FILTER;
+
+pub const SO_PEERNAME = 28;
+pub const SO_TIMESTAMP = 29;
+pub const SCM_TIMESTAMP = SO_TIMESTAMP;
+
+pub const SO_PEERSEC = 31;
+pub const SO_PASSSEC = 34;
+pub const SO_TIMESTAMPNS = 35;
+pub const SCM_TIMESTAMPNS = SO_TIMESTAMPNS;
+pub const SO_MARK = 36;
+pub const SO_TIMESTAMPING = 37;
+pub const SCM_TIMESTAMPING = SO_TIMESTAMPING;
+pub const SO_RXQ_OVFL = 40;
+pub const SO_WIFI_STATUS = 41;
+pub const SCM_WIFI_STATUS = SO_WIFI_STATUS;
+pub const SO_PEEK_OFF = 42;
+pub const SO_NOFCS = 43;
+pub const SO_LOCK_FILTER = 44;
+pub const SO_SELECT_ERR_QUEUE = 45;
+pub const SO_BUSY_POLL = 46;
+pub const SO_MAX_PACING_RATE = 47;
+pub const SO_BPF_EXTENSIONS = 48;
+pub const SO_INCOMING_CPU = 49;
+pub const SO_ATTACH_BPF = 50;
+pub const SO_DETACH_BPF = SO_DETACH_FILTER;
+pub const SO_ATTACH_REUSEPORT_CBPF = 51;
+pub const SO_ATTACH_REUSEPORT_EBPF = 52;
+pub const SO_CNX_ADVICE = 53;
+pub const SCM_TIMESTAMPING_OPT_STATS = 54;
+pub const SO_MEMINFO = 55;
+pub const SO_INCOMING_NAPI_ID = 56;
+pub const SO_COOKIE = 57;
+pub const SCM_TIMESTAMPING_PKTINFO = 58;
+pub const SO_PEERGROUPS = 59;
+pub const SO_ZEROCOPY = 60;
+
+pub const SOL_SOCKET = 1;
+
+pub const SOL_IP = 0;
+pub const SOL_IPV6 = 41;
+pub const SOL_ICMPV6 = 58;
+
+pub const SOL_RAW = 255;
+pub const SOL_DECNET = 261;
+pub const SOL_X25 = 262;
+pub const SOL_PACKET = 263;
+pub const SOL_ATM = 264;
+pub const SOL_AAL = 265;
+pub const SOL_IRDA = 266;
+pub const SOL_NETBEUI = 267;
+pub const SOL_LLC = 268;
+pub const SOL_DCCP = 269;
+pub const SOL_NETLINK = 270;
+pub const SOL_TIPC = 271;
+pub const SOL_RXRPC = 272;
+pub const SOL_PPPOL2TP = 273;
+pub const SOL_BLUETOOTH = 274;
+pub const SOL_PNPIPE = 275;
+pub const SOL_RDS = 276;
+pub const SOL_IUCV = 277;
+pub const SOL_CAIF = 278;
+pub const SOL_ALG = 279;
+pub const SOL_NFC = 280;
+pub const SOL_KCM = 281;
+pub const SOL_TLS = 282;
+
+pub const SOMAXCONN = 128;
+
+pub const MSG_OOB = 0x0001;
+pub const MSG_PEEK = 0x0002;
+pub const MSG_DONTROUTE = 0x0004;
+pub const MSG_CTRUNC = 0x0008;
+pub const MSG_PROXY = 0x0010;
+pub const MSG_TRUNC = 0x0020;
+pub const MSG_DONTWAIT = 0x0040;
+pub const MSG_EOR = 0x0080;
+pub const MSG_WAITALL = 0x0100;
+pub const MSG_FIN = 0x0200;
+pub const MSG_SYN = 0x0400;
+pub const MSG_CONFIRM = 0x0800;
+pub const MSG_RST = 0x1000;
+pub const MSG_ERRQUEUE = 0x2000;
+pub const MSG_NOSIGNAL = 0x4000;
+pub const MSG_MORE = 0x8000;
+pub const MSG_WAITFORONE = 0x10000;
+pub const MSG_BATCH = 0x40000;
+pub const MSG_ZEROCOPY = 0x4000000;
+pub const MSG_FASTOPEN = 0x20000000;
+pub const MSG_CMSG_CLOEXEC = 0x40000000;
+
+pub const DT_UNKNOWN = 0;
+pub const DT_FIFO = 1;
+pub const DT_CHR = 2;
+pub const DT_DIR = 4;
+pub const DT_BLK = 6;
+pub const DT_REG = 8;
+pub const DT_LNK = 10;
+pub const DT_SOCK = 12;
+pub const DT_WHT = 14;
+
+pub const TCGETS = 0x5401;
+pub const TCSETS = 0x5402;
+pub const TCSETSW = 0x5403;
+pub const TCSETSF = 0x5404;
+pub const TCGETA = 0x5405;
+pub const TCSETA = 0x5406;
+pub const TCSETAW = 0x5407;
+pub const TCSETAF = 0x5408;
+pub const TCSBRK = 0x5409;
+pub const TCXONC = 0x540A;
+pub const TCFLSH = 0x540B;
+pub const TIOCEXCL = 0x540C;
+pub const TIOCNXCL = 0x540D;
+pub const TIOCSCTTY = 0x540E;
+pub const TIOCGPGRP = 0x540F;
+pub const TIOCSPGRP = 0x5410;
+pub const TIOCOUTQ = 0x5411;
+pub const TIOCSTI = 0x5412;
+pub const TIOCGWINSZ = 0x5413;
+pub const TIOCSWINSZ = 0x5414;
+pub const TIOCMGET = 0x5415;
+pub const TIOCMBIS = 0x5416;
+pub const TIOCMBIC = 0x5417;
+pub const TIOCMSET = 0x5418;
+pub const TIOCGSOFTCAR = 0x5419;
+pub const TIOCSSOFTCAR = 0x541A;
+pub const FIONREAD = 0x541B;
+pub const TIOCINQ = FIONREAD;
+pub const TIOCLINUX = 0x541C;
+pub const TIOCCONS = 0x541D;
+pub const TIOCGSERIAL = 0x541E;
+pub const TIOCSSERIAL = 0x541F;
+pub const TIOCPKT = 0x5420;
+pub const FIONBIO = 0x5421;
+pub const TIOCNOTTY = 0x5422;
+pub const TIOCSETD = 0x5423;
+pub const TIOCGETD = 0x5424;
+pub const TCSBRKP = 0x5425;
+pub const TIOCSBRK = 0x5427;
+pub const TIOCCBRK = 0x5428;
+pub const TIOCGSID = 0x5429;
+pub const TIOCGRS485 = 0x542E;
+pub const TIOCSRS485 = 0x542F;
+pub const TIOCGPTN = 0x80045430;
+pub const TIOCSPTLCK = 0x40045431;
+pub const TIOCGDEV = 0x80045432;
+pub const TCGETX = 0x5432;
+pub const TCSETX = 0x5433;
+pub const TCSETXF = 0x5434;
+pub const TCSETXW = 0x5435;
+pub const TIOCSIG = 0x40045436;
+pub const TIOCVHANGUP = 0x5437;
+pub const TIOCGPKT = 0x80045438;
+pub const TIOCGPTLCK = 0x80045439;
+pub const TIOCGEXCL = 0x80045440;
+
+pub const EPOLL_CLOEXEC = O_CLOEXEC;
+
+pub const EPOLL_CTL_ADD = 1;
+pub const EPOLL_CTL_DEL = 2;
+pub const EPOLL_CTL_MOD = 3;
+
+pub const EPOLLIN = 0x001;
+pub const EPOLLPRI = 0x002;
+pub const EPOLLOUT = 0x004;
+pub const EPOLLRDNORM = 0x040;
+pub const EPOLLRDBAND = 0x080;
+pub const EPOLLWRNORM = 0x100;
+pub const EPOLLWRBAND = 0x200;
+pub const EPOLLMSG = 0x400;
+pub const EPOLLERR = 0x008;
+pub const EPOLLHUP = 0x010;
+pub const EPOLLRDHUP = 0x2000;
+pub const EPOLLEXCLUSIVE = (u32(1) << 28);
+pub const EPOLLWAKEUP = (u32(1) << 29);
+pub const EPOLLONESHOT = (u32(1) << 30);
+pub const EPOLLET = (u32(1) << 31);
+
+pub const CLOCK_REALTIME = 0;
+pub const CLOCK_MONOTONIC = 1;
+pub const CLOCK_PROCESS_CPUTIME_ID = 2;
+pub const CLOCK_THREAD_CPUTIME_ID = 3;
+pub const CLOCK_MONOTONIC_RAW = 4;
+pub const CLOCK_REALTIME_COARSE = 5;
+pub const CLOCK_MONOTONIC_COARSE = 6;
+pub const CLOCK_BOOTTIME = 7;
+pub const CLOCK_REALTIME_ALARM = 8;
+pub const CLOCK_BOOTTIME_ALARM = 9;
+pub const CLOCK_SGI_CYCLE = 10;
+pub const CLOCK_TAI = 11;
+
+pub const CSIGNAL = 0x000000ff;
+pub const CLONE_VM = 0x00000100;
+pub const CLONE_FS = 0x00000200;
+pub const CLONE_FILES = 0x00000400;
+pub const CLONE_SIGHAND = 0x00000800;
+pub const CLONE_PTRACE = 0x00002000;
+pub const CLONE_VFORK = 0x00004000;
+pub const CLONE_PARENT = 0x00008000;
+pub const CLONE_THREAD = 0x00010000;
+pub const CLONE_NEWNS = 0x00020000;
+pub const CLONE_SYSVSEM = 0x00040000;
+pub const CLONE_SETTLS = 0x00080000;
+pub const CLONE_PARENT_SETTID = 0x00100000;
+pub const CLONE_CHILD_CLEARTID = 0x00200000;
+pub const CLONE_DETACHED = 0x00400000;
+pub const CLONE_UNTRACED = 0x00800000;
+pub const CLONE_CHILD_SETTID = 0x01000000;
+pub const CLONE_NEWCGROUP = 0x02000000;
+pub const CLONE_NEWUTS = 0x04000000;
+pub const CLONE_NEWIPC = 0x08000000;
+pub const CLONE_NEWUSER = 0x10000000;
+pub const CLONE_NEWPID = 0x20000000;
+pub const CLONE_NEWNET = 0x40000000;
+pub const CLONE_IO = 0x80000000;
+
+pub const EFD_SEMAPHORE = 1;
+pub const EFD_CLOEXEC = O_CLOEXEC;
+pub const EFD_NONBLOCK = O_NONBLOCK;
+
+pub const MS_RDONLY = 1;
+pub const MS_NOSUID = 2;
+pub const MS_NODEV = 4;
+pub const MS_NOEXEC = 8;
+pub const MS_SYNCHRONOUS = 16;
+pub const MS_REMOUNT = 32;
+pub const MS_MANDLOCK = 64;
+pub const MS_DIRSYNC = 128;
+pub const MS_NOATIME = 1024;
+pub const MS_NODIRATIME = 2048;
+pub const MS_BIND = 4096;
+pub const MS_MOVE = 8192;
+pub const MS_REC = 16384;
+pub const MS_SILENT = 32768;
+pub const MS_POSIXACL = (1 << 16);
+pub const MS_UNBINDABLE = (1 << 17);
+pub const MS_PRIVATE = (1 << 18);
+pub const MS_SLAVE = (1 << 19);
+pub const MS_SHARED = (1 << 20);
+pub const MS_RELATIME = (1 << 21);
+pub const MS_KERNMOUNT = (1 << 22);
+pub const MS_I_VERSION = (1 << 23);
+pub const MS_STRICTATIME = (1 << 24);
+pub const MS_LAZYTIME = (1 << 25);
+pub const MS_NOREMOTELOCK = (1 << 27);
+pub const MS_NOSEC = (1 << 28);
+pub const MS_BORN = (1 << 29);
+pub const MS_ACTIVE = (1 << 30);
+pub const MS_NOUSER = (1 << 31);
+
+pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME);
+
+pub const MS_MGC_VAL = 0xc0ed0000;
+pub const MS_MGC_MSK = 0xffff0000;
+
+pub const MNT_FORCE = 1;
+pub const MNT_DETACH = 2;
+pub const MNT_EXPIRE = 4;
+pub const UMOUNT_NOFOLLOW = 8;
+
+pub const IN_CLOEXEC = O_CLOEXEC;
+pub const IN_NONBLOCK = O_NONBLOCK;
+
+pub const IN_ACCESS = 0x00000001;
+pub const IN_MODIFY = 0x00000002;
+pub const IN_ATTRIB = 0x00000004;
+pub const IN_CLOSE_WRITE = 0x00000008;
+pub const IN_CLOSE_NOWRITE = 0x00000010;
+pub const IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE;
+pub const IN_OPEN = 0x00000020;
+pub const IN_MOVED_FROM = 0x00000040;
+pub const IN_MOVED_TO = 0x00000080;
+pub const IN_MOVE = IN_MOVED_FROM | IN_MOVED_TO;
+pub const IN_CREATE = 0x00000100;
+pub const IN_DELETE = 0x00000200;
+pub const IN_DELETE_SELF = 0x00000400;
+pub const IN_MOVE_SELF = 0x00000800;
+pub const IN_ALL_EVENTS = 0x00000fff;
+
+pub const IN_UNMOUNT = 0x00002000;
+pub const IN_Q_OVERFLOW = 0x00004000;
+pub const IN_IGNORED = 0x00008000;
+
+pub const IN_ONLYDIR = 0x01000000;
+pub const IN_DONT_FOLLOW = 0x02000000;
+pub const IN_EXCL_UNLINK = 0x04000000;
+pub const IN_MASK_ADD = 0x20000000;
+
+pub const IN_ISDIR = 0x40000000;
+pub const IN_ONESHOT = 0x80000000;
+
+pub const S_IFMT = 0o170000;
+
+pub const S_IFDIR = 0o040000;
+pub const S_IFCHR = 0o020000;
+pub const S_IFBLK = 0o060000;
+pub const S_IFREG = 0o100000;
+pub const S_IFIFO = 0o010000;
+pub const S_IFLNK = 0o120000;
+pub const S_IFSOCK = 0o140000;
+
+pub const S_ISUID = 0o4000;
+pub const S_ISGID = 0o2000;
+pub const S_ISVTX = 0o1000;
+pub const S_IRUSR = 0o400;
+pub const S_IWUSR = 0o200;
+pub const S_IXUSR = 0o100;
+pub const S_IRWXU = 0o700;
+pub const S_IRGRP = 0o040;
+pub const S_IWGRP = 0o020;
+pub const S_IXGRP = 0o010;
+pub const S_IRWXG = 0o070;
+pub const S_IROTH = 0o004;
+pub const S_IWOTH = 0o002;
+pub const S_IXOTH = 0o001;
+pub const S_IRWXO = 0o007;
+
+pub fn S_ISREG(m: u32) bool {
+ return m & S_IFMT == S_IFREG;
+}
+
+pub fn S_ISDIR(m: u32) bool {
+ return m & S_IFMT == S_IFDIR;
+}
+
+pub fn S_ISCHR(m: u32) bool {
+ return m & S_IFMT == S_IFCHR;
+}
+
+pub fn S_ISBLK(m: u32) bool {
+ return m & S_IFMT == S_IFBLK;
+}
+
+pub fn S_ISFIFO(m: u32) bool {
+ return m & S_IFMT == S_IFIFO;
+}
+
+pub fn S_ISLNK(m: u32) bool {
+ return m & S_IFMT == S_IFLNK;
+}
+
+pub fn S_ISSOCK(m: u32) bool {
+ return m & S_IFMT == S_IFSOCK;
+}
+
+pub const TFD_NONBLOCK = O_NONBLOCK;
+pub const TFD_CLOEXEC = O_CLOEXEC;
+
+pub const TFD_TIMER_ABSTIME = 1;
+pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
+
+pub fn WEXITSTATUS(s: u32) u32 {
+ return (s & 0xff00) >> 8;
+}
+pub fn WTERMSIG(s: u32) u32 {
+ return s & 0x7f;
+}
+pub fn WSTOPSIG(s: u32) u32 {
+ return WEXITSTATUS(s);
+}
+pub fn WIFEXITED(s: u32) bool {
+ return WTERMSIG(s) == 0;
+}
+pub fn WIFSTOPPED(s: u32) bool {
+ return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
+}
+pub fn WIFSIGNALED(s: u32) bool {
+ return (s & 0xffff) -% 1 < 0xff;
+}
+
+pub const winsize = extern struct {
+ ws_row: u16,
+ ws_col: u16,
+ ws_xpixel: u16,
+ ws_ypixel: u16,
+};
+
+pub const NSIG = 65;
+pub const sigset_t = [128 / @sizeOf(usize)]usize;
+pub const all_mask = []u32{ 0xffffffff, 0xffffffff };
+pub const app_mask = []u32{ 0xfffffffc, 0x7fffffff };
+
+pub const k_sigaction = extern struct {
+ handler: extern fn (i32) void,
+ flags: usize,
+ restorer: extern fn () void,
+ mask: [2]u32,
+};
+
+/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
+pub const Sigaction = struct {
+ handler: extern fn (i32) void,
+ mask: sigset_t,
+ flags: u32,
+};
+
+pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
+pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
+pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
+pub const empty_sigset = []usize{0} ** sigset_t.len;
+
+pub const in_port_t = u16;
+pub const sa_family_t = u16;
+pub const socklen_t = u32;
+
+/// This intentionally only has ip4 and ip6
+pub const sockaddr = extern union {
+ in: sockaddr_in,
+ in6: sockaddr_in6,
+};
+
+pub const sockaddr_in = extern struct {
+ family: sa_family_t,
+ port: in_port_t,
+ addr: u32,
+ zero: [8]u8,
+};
+
+pub const sockaddr_in6 = extern struct {
+ family: sa_family_t,
+ port: in_port_t,
+ flowinfo: u32,
+ addr: [16]u8,
+ scope_id: u32,
+};
+
+pub const sockaddr_un = extern struct {
+ family: sa_family_t,
+ path: [108]u8,
+};
+
+pub const mmsghdr = extern struct {
+ msg_hdr: msghdr,
+ msg_len: u32,
+};
+
+pub const mmsghdr_const = extern struct {
+ msg_hdr: msghdr_const,
+ msg_len: u32,
+};
+
+pub const epoll_data = extern union {
+ ptr: usize,
+ fd: i32,
+ @"u32": u32,
+ @"u64": u64,
+};
+
+// On x86_64 the structure is packed so that it matches the definition of its
+// 32bit counterpart
+pub const epoll_event = if (builtin.arch != .x86_64)
+ extern struct {
+ events: u32,
+ data: epoll_data,
+ }
+else
+ packed struct {
+ events: u32,
+ data: epoll_data,
+ };
+
+pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
+pub const _LINUX_CAPABILITY_U32S_1 = 1;
+
+pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026;
+pub const _LINUX_CAPABILITY_U32S_2 = 2;
+
+pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522;
+pub const _LINUX_CAPABILITY_U32S_3 = 2;
+
+pub const VFS_CAP_REVISION_MASK = 0xFF000000;
+pub const VFS_CAP_REVISION_SHIFT = 24;
+pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
+pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001;
+
+pub const VFS_CAP_REVISION_1 = 0x01000000;
+pub const VFS_CAP_U32_1 = 1;
+pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1);
+
+pub const VFS_CAP_REVISION_2 = 0x02000000;
+pub const VFS_CAP_U32_2 = 2;
+pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2);
+
+pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
+pub const VFS_CAP_U32 = VFS_CAP_U32_2;
+pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
+
+pub const vfs_cap_data = extern struct {
+ //all of these are mandated as little endian
+ //when on disk.
+ const Data = struct {
+ permitted: u32,
+ inheritable: u32,
+ };
+
+ magic_etc: u32,
+ data: [VFS_CAP_U32]Data,
+};
+
+pub const CAP_CHOWN = 0;
+pub const CAP_DAC_OVERRIDE = 1;
+pub const CAP_DAC_READ_SEARCH = 2;
+pub const CAP_FOWNER = 3;
+pub const CAP_FSETID = 4;
+pub const CAP_KILL = 5;
+pub const CAP_SETGID = 6;
+pub const CAP_SETUID = 7;
+pub const CAP_SETPCAP = 8;
+pub const CAP_LINUX_IMMUTABLE = 9;
+pub const CAP_NET_BIND_SERVICE = 10;
+pub const CAP_NET_BROADCAST = 11;
+pub const CAP_NET_ADMIN = 12;
+pub const CAP_NET_RAW = 13;
+pub const CAP_IPC_LOCK = 14;
+pub const CAP_IPC_OWNER = 15;
+pub const CAP_SYS_MODULE = 16;
+pub const CAP_SYS_RAWIO = 17;
+pub const CAP_SYS_CHROOT = 18;
+pub const CAP_SYS_PTRACE = 19;
+pub const CAP_SYS_PACCT = 20;
+pub const CAP_SYS_ADMIN = 21;
+pub const CAP_SYS_BOOT = 22;
+pub const CAP_SYS_NICE = 23;
+pub const CAP_SYS_RESOURCE = 24;
+pub const CAP_SYS_TIME = 25;
+pub const CAP_SYS_TTY_CONFIG = 26;
+pub const CAP_MKNOD = 27;
+pub const CAP_LEASE = 28;
+pub const CAP_AUDIT_WRITE = 29;
+pub const CAP_AUDIT_CONTROL = 30;
+pub const CAP_SETFCAP = 31;
+pub const CAP_MAC_OVERRIDE = 32;
+pub const CAP_MAC_ADMIN = 33;
+pub const CAP_SYSLOG = 34;
+pub const CAP_WAKE_ALARM = 35;
+pub const CAP_BLOCK_SUSPEND = 36;
+pub const CAP_AUDIT_READ = 37;
+pub const CAP_LAST_CAP = CAP_AUDIT_READ;
+
+pub fn cap_valid(u8: x) bool {
+ return x >= 0 and x <= CAP_LAST_CAP;
+}
+
+pub fn CAP_TO_MASK(cap: u8) u32 {
+ return u32(1) << u5(cap & 31);
+}
+
+pub fn CAP_TO_INDEX(cap: u8) u8 {
+ return cap >> 5;
+}
+
+pub const cap_t = extern struct {
+ hdrp: *cap_user_header_t,
+ datap: *cap_user_data_t,
+};
+
+pub const cap_user_header_t = extern struct {
+ version: u32,
+ pid: usize,
+};
+
+pub const cap_user_data_t = extern struct {
+ effective: u32,
+ permitted: u32,
+ inheritable: u32,
+};
+
+pub const inotify_event = extern struct {
+ wd: i32,
+ mask: u32,
+ cookie: u32,
+ len: u32,
+ //name: [?]u8,
+};
+
+pub const dirent64 = extern struct {
+ d_ino: u64,
+ d_off: u64,
+ d_reclen: u16,
+ d_type: u8,
+ d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/173
+};
+
+pub const dl_phdr_info = extern struct {
+ dlpi_addr: usize,
+ dlpi_name: ?[*]const u8,
+ dlpi_phdr: [*]std.elf.Phdr,
+ dlpi_phnum: u16,
+};
+
+pub const pthread_attr_t = extern struct {
+ __size: [56]u8,
+ __align: c_long,
+};
+
+pub const CPU_SETSIZE = 128;
+pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
+pub const cpu_count_t = @IntType(false, std.math.log2(CPU_SETSIZE * 8));
+
+pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
+ var sum: cpu_count_t = 0;
+ for (set) |x| {
+ sum += @popCount(usize, x);
+ }
+ return sum;
+}
+
+// TODO port these over
+//#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set)
+//#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set)
+//#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set)
+//#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2)
+//#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2)
+//#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2)
+//#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set)
+//#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)
+//#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2)
diff --git a/std/os/bits/linux/arm64.zig b/std/os/bits/linux/arm64.zig
new file mode 100644
index 0000000000..8966df30d2
--- /dev/null
+++ b/std/os/bits/linux/arm64.zig
@@ -0,0 +1,405 @@
+// arm64-specific declarations that are intended to be imported into the POSIX namespace.
+// This does include Linux-only APIs.
+
+const std = @import("../../std.zig");
+const linux = std.os.linux;
+const socklen_t = linux.socklen_t;
+const iovec = linux.iovec;
+const iovec_const = linux.iovec_const;
+
+pub const SYS_io_setup = 0;
+pub const SYS_io_destroy = 1;
+pub const SYS_io_submit = 2;
+pub const SYS_io_cancel = 3;
+pub const SYS_io_getevents = 4;
+pub const SYS_setxattr = 5;
+pub const SYS_lsetxattr = 6;
+pub const SYS_fsetxattr = 7;
+pub const SYS_getxattr = 8;
+pub const SYS_lgetxattr = 9;
+pub const SYS_fgetxattr = 10;
+pub const SYS_listxattr = 11;
+pub const SYS_llistxattr = 12;
+pub const SYS_flistxattr = 13;
+pub const SYS_removexattr = 14;
+pub const SYS_lremovexattr = 15;
+pub const SYS_fremovexattr = 16;
+pub const SYS_getcwd = 17;
+pub const SYS_lookup_dcookie = 18;
+pub const SYS_eventfd2 = 19;
+pub const SYS_epoll_create1 = 20;
+pub const SYS_epoll_ctl = 21;
+pub const SYS_epoll_pwait = 22;
+pub const SYS_dup = 23;
+pub const SYS_dup3 = 24;
+pub const SYS_fcntl = 25;
+pub const SYS_inotify_init1 = 26;
+pub const SYS_inotify_add_watch = 27;
+pub const SYS_inotify_rm_watch = 28;
+pub const SYS_ioctl = 29;
+pub const SYS_ioprio_set = 30;
+pub const SYS_ioprio_get = 31;
+pub const SYS_flock = 32;
+pub const SYS_mknodat = 33;
+pub const SYS_mkdirat = 34;
+pub const SYS_unlinkat = 35;
+pub const SYS_symlinkat = 36;
+pub const SYS_linkat = 37;
+pub const SYS_renameat = 38;
+pub const SYS_umount2 = 39;
+pub const SYS_mount = 40;
+pub const SYS_pivot_root = 41;
+pub const SYS_nfsservctl = 42;
+pub const SYS_statfs = 43;
+pub const SYS_fstatfs = 44;
+pub const SYS_truncate = 45;
+pub const SYS_ftruncate = 46;
+pub const SYS_fallocate = 47;
+pub const SYS_faccessat = 48;
+pub const SYS_chdir = 49;
+pub const SYS_fchdir = 50;
+pub const SYS_chroot = 51;
+pub const SYS_fchmod = 52;
+pub const SYS_fchmodat = 53;
+pub const SYS_fchownat = 54;
+pub const SYS_fchown = 55;
+pub const SYS_openat = 56;
+pub const SYS_close = 57;
+pub const SYS_vhangup = 58;
+pub const SYS_pipe2 = 59;
+pub const SYS_quotactl = 60;
+pub const SYS_getdents64 = 61;
+pub const SYS_lseek = 62;
+pub const SYS_read = 63;
+pub const SYS_write = 64;
+pub const SYS_readv = 65;
+pub const SYS_writev = 66;
+pub const SYS_pread64 = 67;
+pub const SYS_pwrite64 = 68;
+pub const SYS_preadv = 69;
+pub const SYS_pwritev = 70;
+pub const SYS_pselect6 = 72;
+pub const SYS_ppoll = 73;
+pub const SYS_signalfd4 = 74;
+pub const SYS_vmsplice = 75;
+pub const SYS_splice = 76;
+pub const SYS_tee = 77;
+pub const SYS_readlinkat = 78;
+pub const SYS_fstatat = 79;
+pub const SYS_fstat = 80;
+pub const SYS_sync = 81;
+pub const SYS_fsync = 82;
+pub const SYS_fdatasync = 83;
+pub const SYS_sync_file_range2 = 84;
+pub const SYS_sync_file_range = 84;
+pub const SYS_timerfd_create = 85;
+pub const SYS_timerfd_settime = 86;
+pub const SYS_timerfd_gettime = 87;
+pub const SYS_utimensat = 88;
+pub const SYS_acct = 89;
+pub const SYS_capget = 90;
+pub const SYS_capset = 91;
+pub const SYS_personality = 92;
+pub const SYS_exit = 93;
+pub const SYS_exit_group = 94;
+pub const SYS_waitid = 95;
+pub const SYS_set_tid_address = 96;
+pub const SYS_unshare = 97;
+pub const SYS_futex = 98;
+pub const SYS_set_robust_list = 99;
+pub const SYS_get_robust_list = 100;
+pub const SYS_nanosleep = 101;
+pub const SYS_getitimer = 102;
+pub const SYS_setitimer = 103;
+pub const SYS_kexec_load = 104;
+pub const SYS_init_module = 105;
+pub const SYS_delete_module = 106;
+pub const SYS_timer_create = 107;
+pub const SYS_timer_gettime = 108;
+pub const SYS_timer_getoverrun = 109;
+pub const SYS_timer_settime = 110;
+pub const SYS_timer_delete = 111;
+pub const SYS_clock_settime = 112;
+pub const SYS_clock_gettime = 113;
+pub const SYS_clock_getres = 114;
+pub const SYS_clock_nanosleep = 115;
+pub const SYS_syslog = 116;
+pub const SYS_ptrace = 117;
+pub const SYS_sched_setparam = 118;
+pub const SYS_sched_setscheduler = 119;
+pub const SYS_sched_getscheduler = 120;
+pub const SYS_sched_getparam = 121;
+pub const SYS_sched_setaffinity = 122;
+pub const SYS_sched_getaffinity = 123;
+pub const SYS_sched_yield = 124;
+pub const SYS_sched_get_priority_max = 125;
+pub const SYS_sched_get_priority_min = 126;
+pub const SYS_sched_rr_get_interval = 127;
+pub const SYS_restart_syscall = 128;
+pub const SYS_kill = 129;
+pub const SYS_tkill = 130;
+pub const SYS_tgkill = 131;
+pub const SYS_sigaltstack = 132;
+pub const SYS_rt_sigsuspend = 133;
+pub const SYS_rt_sigaction = 134;
+pub const SYS_rt_sigprocmask = 135;
+pub const SYS_rt_sigpending = 136;
+pub const SYS_rt_sigtimedwait = 137;
+pub const SYS_rt_sigqueueinfo = 138;
+pub const SYS_rt_sigreturn = 139;
+pub const SYS_setpriority = 140;
+pub const SYS_getpriority = 141;
+pub const SYS_reboot = 142;
+pub const SYS_setregid = 143;
+pub const SYS_setgid = 144;
+pub const SYS_setreuid = 145;
+pub const SYS_setuid = 146;
+pub const SYS_setresuid = 147;
+pub const SYS_getresuid = 148;
+pub const SYS_setresgid = 149;
+pub const SYS_getresgid = 150;
+pub const SYS_setfsuid = 151;
+pub const SYS_setfsgid = 152;
+pub const SYS_times = 153;
+pub const SYS_setpgid = 154;
+pub const SYS_getpgid = 155;
+pub const SYS_getsid = 156;
+pub const SYS_setsid = 157;
+pub const SYS_getgroups = 158;
+pub const SYS_setgroups = 159;
+pub const SYS_uname = 160;
+pub const SYS_sethostname = 161;
+pub const SYS_setdomainname = 162;
+pub const SYS_getrlimit = 163;
+pub const SYS_setrlimit = 164;
+pub const SYS_getrusage = 165;
+pub const SYS_umask = 166;
+pub const SYS_prctl = 167;
+pub const SYS_getcpu = 168;
+pub const SYS_gettimeofday = 169;
+pub const SYS_settimeofday = 170;
+pub const SYS_adjtimex = 171;
+pub const SYS_getpid = 172;
+pub const SYS_getppid = 173;
+pub const SYS_getuid = 174;
+pub const SYS_geteuid = 175;
+pub const SYS_getgid = 176;
+pub const SYS_getegid = 177;
+pub const SYS_gettid = 178;
+pub const SYS_sysinfo = 179;
+pub const SYS_mq_open = 180;
+pub const SYS_mq_unlink = 181;
+pub const SYS_mq_timedsend = 182;
+pub const SYS_mq_timedreceive = 183;
+pub const SYS_mq_notify = 184;
+pub const SYS_mq_getsetattr = 185;
+pub const SYS_msgget = 186;
+pub const SYS_msgctl = 187;
+pub const SYS_msgrcv = 188;
+pub const SYS_msgsnd = 189;
+pub const SYS_semget = 190;
+pub const SYS_semctl = 191;
+pub const SYS_semtimedop = 192;
+pub const SYS_semop = 193;
+pub const SYS_shmget = 194;
+pub const SYS_shmctl = 195;
+pub const SYS_shmat = 196;
+pub const SYS_shmdt = 197;
+pub const SYS_socket = 198;
+pub const SYS_socketpair = 199;
+pub const SYS_bind = 200;
+pub const SYS_listen = 201;
+pub const SYS_accept = 202;
+pub const SYS_connect = 203;
+pub const SYS_getsockname = 204;
+pub const SYS_getpeername = 205;
+pub const SYS_sendto = 206;
+pub const SYS_recvfrom = 207;
+pub const SYS_setsockopt = 208;
+pub const SYS_getsockopt = 209;
+pub const SYS_shutdown = 210;
+pub const SYS_sendmsg = 211;
+pub const SYS_recvmsg = 212;
+pub const SYS_readahead = 213;
+pub const SYS_brk = 214;
+pub const SYS_munmap = 215;
+pub const SYS_mremap = 216;
+pub const SYS_add_key = 217;
+pub const SYS_request_key = 218;
+pub const SYS_keyctl = 219;
+pub const SYS_clone = 220;
+pub const SYS_execve = 221;
+pub const SYS_mmap = 222;
+pub const SYS_fadvise64 = 223;
+pub const SYS_swapon = 224;
+pub const SYS_swapoff = 225;
+pub const SYS_mprotect = 226;
+pub const SYS_msync = 227;
+pub const SYS_mlock = 228;
+pub const SYS_munlock = 229;
+pub const SYS_mlockall = 230;
+pub const SYS_munlockall = 231;
+pub const SYS_mincore = 232;
+pub const SYS_madvise = 233;
+pub const SYS_remap_file_pages = 234;
+pub const SYS_mbind = 235;
+pub const SYS_get_mempolicy = 236;
+pub const SYS_set_mempolicy = 237;
+pub const SYS_migrate_pages = 238;
+pub const SYS_move_pages = 239;
+pub const SYS_rt_tgsigqueueinfo = 240;
+pub const SYS_perf_event_open = 241;
+pub const SYS_accept4 = 242;
+pub const SYS_recvmmsg = 243;
+pub const SYS_arch_specific_syscall = 244;
+pub const SYS_wait4 = 260;
+pub const SYS_prlimit64 = 261;
+pub const SYS_fanotify_init = 262;
+pub const SYS_fanotify_mark = 263;
+pub const SYS_clock_adjtime = 266;
+pub const SYS_syncfs = 267;
+pub const SYS_setns = 268;
+pub const SYS_sendmmsg = 269;
+pub const SYS_process_vm_readv = 270;
+pub const SYS_process_vm_writev = 271;
+pub const SYS_kcmp = 272;
+pub const SYS_finit_module = 273;
+pub const SYS_sched_setattr = 274;
+pub const SYS_sched_getattr = 275;
+pub const SYS_renameat2 = 276;
+pub const SYS_seccomp = 277;
+pub const SYS_getrandom = 278;
+pub const SYS_memfd_create = 279;
+pub const SYS_bpf = 280;
+pub const SYS_execveat = 281;
+pub const SYS_userfaultfd = 282;
+pub const SYS_membarrier = 283;
+pub const SYS_mlock2 = 284;
+pub const SYS_copy_file_range = 285;
+pub const SYS_preadv2 = 286;
+pub const SYS_pwritev2 = 287;
+pub const SYS_pkey_mprotect = 288;
+pub const SYS_pkey_alloc = 289;
+pub const SYS_pkey_free = 290;
+pub const SYS_statx = 291;
+pub const SYS_io_pgetevents = 292;
+pub const SYS_rseq = 293;
+pub const SYS_kexec_file_load = 294;
+pub const SYS_pidfd_send_signal = 424;
+pub const SYS_io_uring_setup = 425;
+pub const SYS_io_uring_enter = 426;
+pub const SYS_io_uring_register = 427;
+
+pub const O_CREAT = 0o100;
+pub const O_EXCL = 0o200;
+pub const O_NOCTTY = 0o400;
+pub const O_TRUNC = 0o1000;
+pub const O_APPEND = 0o2000;
+pub const O_NONBLOCK = 0o4000;
+pub const O_DSYNC = 0o10000;
+pub const O_SYNC = 0o4010000;
+pub const O_RSYNC = 0o4010000;
+pub const O_DIRECTORY = 0o200000;
+pub const O_NOFOLLOW = 0o400000;
+pub const O_CLOEXEC = 0o2000000;
+
+pub const O_ASYNC = 0o20000;
+pub const O_DIRECT = 0o40000;
+pub const O_LARGEFILE = 0;
+pub const O_NOATIME = 0o1000000;
+pub const O_PATH = 0o10000000;
+pub const O_TMPFILE = 0o20200000;
+pub const O_NDELAY = O_NONBLOCK;
+
+pub const F_DUPFD = 0;
+pub const F_GETFD = 1;
+pub const F_SETFD = 2;
+pub const F_GETFL = 3;
+pub const F_SETFL = 4;
+
+pub const F_SETOWN = 8;
+pub const F_GETOWN = 9;
+pub const F_SETSIG = 10;
+pub const F_GETSIG = 11;
+
+pub const F_GETLK = 5;
+pub const F_SETLK = 6;
+pub const F_SETLKW = 7;
+
+pub const F_SETOWN_EX = 15;
+pub const F_GETOWN_EX = 16;
+
+pub const F_GETOWNER_UIDS = 17;
+
+pub const AT_FDCWD = -100;
+pub const AT_SYMLINK_NOFOLLOW = 0x100;
+pub const AT_REMOVEDIR = 0x200;
+pub const AT_SYMLINK_FOLLOW = 0x400;
+pub const AT_NO_AUTOMOUNT = 0x800;
+pub const AT_EMPTY_PATH = 0x1000;
+
+pub const VDSO_USEFUL = true;
+pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
+pub const VDSO_CGT_VER = "LINUX_2.6.39";
+
+pub const msghdr = extern struct {
+ msg_name: ?*sockaddr,
+ msg_namelen: socklen_t,
+ msg_iov: [*]iovec,
+ msg_iovlen: i32,
+ __pad1: i32,
+ msg_control: ?*c_void,
+ msg_controllen: socklen_t,
+ __pad2: socklen_t,
+ msg_flags: i32,
+};
+
+pub const msghdr_const = extern struct {
+ msg_name: ?*const sockaddr,
+ msg_namelen: socklen_t,
+ msg_iov: [*]iovec_const,
+ msg_iovlen: i32,
+ __pad1: i32,
+ msg_control: ?*c_void,
+ msg_controllen: socklen_t,
+ __pad2: socklen_t,
+ msg_flags: i32,
+};
+
+/// Renamed to Stat to not conflict with the stat function.
+pub const Stat = extern struct {
+ dev: u64,
+ ino: u64,
+ nlink: usize,
+
+ mode: u32,
+ uid: u32,
+ gid: u32,
+ __pad0: u32,
+ rdev: u64,
+ size: i64,
+ blksize: isize,
+ blocks: i64,
+
+ atim: timespec,
+ mtim: timespec,
+ ctim: timespec,
+ __unused: [3]isize,
+};
+
+pub const timespec = extern struct {
+ tv_sec: isize,
+ tv_nsec: isize,
+};
+
+pub const timeval = extern struct {
+ tv_sec: isize,
+ tv_usec: isize,
+};
+
+pub const timezone = extern struct {
+ tz_minuteswest: i32,
+ tz_dsttime: i32,
+};
+
+pub const Elf_Symndx = u32;
diff --git a/std/os/bits/linux/errno.zig b/std/os/bits/linux/errno.zig
new file mode 100644
index 0000000000..741f76fdee
--- /dev/null
+++ b/std/os/bits/linux/errno.zig
@@ -0,0 +1,428 @@
+/// Operation not permitted
+pub const EPERM = 1;
+
+/// No such file or directory
+pub const ENOENT = 2;
+
+/// No such process
+pub const ESRCH = 3;
+
+/// Interrupted system call
+pub const EINTR = 4;
+
+/// I/O error
+pub const EIO = 5;
+
+/// No such device or address
+pub const ENXIO = 6;
+
+/// Arg list too long
+pub const E2BIG = 7;
+
+/// Exec format error
+pub const ENOEXEC = 8;
+
+/// Bad file number
+pub const EBADF = 9;
+
+/// No child processes
+pub const ECHILD = 10;
+
+/// Try again
+pub const EAGAIN = 11;
+
+/// Out of memory
+pub const ENOMEM = 12;
+
+/// Permission denied
+pub const EACCES = 13;
+
+/// Bad address
+pub const EFAULT = 14;
+
+/// Block device required
+pub const ENOTBLK = 15;
+
+/// Device or resource busy
+pub const EBUSY = 16;
+
+/// File exists
+pub const EEXIST = 17;
+
+/// Cross-device link
+pub const EXDEV = 18;
+
+/// No such device
+pub const ENODEV = 19;
+
+/// Not a directory
+pub const ENOTDIR = 20;
+
+/// Is a directory
+pub const EISDIR = 21;
+
+/// Invalid argument
+pub const EINVAL = 22;
+
+/// File table overflow
+pub const ENFILE = 23;
+
+/// Too many open files
+pub const EMFILE = 24;
+
+/// Not a typewriter
+pub const ENOTTY = 25;
+
+/// Text file busy
+pub const ETXTBSY = 26;
+
+/// File too large
+pub const EFBIG = 27;
+
+/// No space left on device
+pub const ENOSPC = 28;
+
+/// Illegal seek
+pub const ESPIPE = 29;
+
+/// Read-only file system
+pub const EROFS = 30;
+
+/// Too many links
+pub const EMLINK = 31;
+
+/// Broken pipe
+pub const EPIPE = 32;
+
+/// Math argument out of domain of func
+pub const EDOM = 33;
+
+/// Math result not representable
+pub const ERANGE = 34;
+
+/// Resource deadlock would occur
+pub const EDEADLK = 35;
+
+/// File name too long
+pub const ENAMETOOLONG = 36;
+
+/// No record locks available
+pub const ENOLCK = 37;
+
+/// Function not implemented
+pub const ENOSYS = 38;
+
+/// Directory not empty
+pub const ENOTEMPTY = 39;
+
+/// Too many symbolic links encountered
+pub const ELOOP = 40;
+
+/// Operation would block
+pub const EWOULDBLOCK = EAGAIN;
+
+/// No message of desired type
+pub const ENOMSG = 42;
+
+/// Identifier removed
+pub const EIDRM = 43;
+
+/// Channel number out of range
+pub const ECHRNG = 44;
+
+/// Level 2 not synchronized
+pub const EL2NSYNC = 45;
+
+/// Level 3 halted
+pub const EL3HLT = 46;
+
+/// Level 3 reset
+pub const EL3RST = 47;
+
+/// Link number out of range
+pub const ELNRNG = 48;
+
+/// Protocol driver not attached
+pub const EUNATCH = 49;
+
+/// No CSI structure available
+pub const ENOCSI = 50;
+
+/// Level 2 halted
+pub const EL2HLT = 51;
+
+/// Invalid exchange
+pub const EBADE = 52;
+
+/// Invalid request descriptor
+pub const EBADR = 53;
+
+/// Exchange full
+pub const EXFULL = 54;
+
+/// No anode
+pub const ENOANO = 55;
+
+/// Invalid request code
+pub const EBADRQC = 56;
+
+/// Invalid slot
+pub const EBADSLT = 57;
+
+/// Bad font file format
+pub const EBFONT = 59;
+
+/// Device not a stream
+pub const ENOSTR = 60;
+
+/// No data available
+pub const ENODATA = 61;
+
+/// Timer expired
+pub const ETIME = 62;
+
+/// Out of streams resources
+pub const ENOSR = 63;
+
+/// Machine is not on the network
+pub const ENONET = 64;
+
+/// Package not installed
+pub const ENOPKG = 65;
+
+/// Object is remote
+pub const EREMOTE = 66;
+
+/// Link has been severed
+pub const ENOLINK = 67;
+
+/// Advertise error
+pub const EADV = 68;
+
+/// Srmount error
+pub const ESRMNT = 69;
+
+/// Communication error on send
+pub const ECOMM = 70;
+
+/// Protocol error
+pub const EPROTO = 71;
+
+/// Multihop attempted
+pub const EMULTIHOP = 72;
+
+/// RFS specific error
+pub const EDOTDOT = 73;
+
+/// Not a data message
+pub const EBADMSG = 74;
+
+/// Value too large for defined data type
+pub const EOVERFLOW = 75;
+
+/// Name not unique on network
+pub const ENOTUNIQ = 76;
+
+/// File descriptor in bad state
+pub const EBADFD = 77;
+
+/// Remote address changed
+pub const EREMCHG = 78;
+
+/// Can not access a needed shared library
+pub const ELIBACC = 79;
+
+/// Accessing a corrupted shared library
+pub const ELIBBAD = 80;
+
+/// .lib section in a.out corrupted
+pub const ELIBSCN = 81;
+
+/// Attempting to link in too many shared libraries
+pub const ELIBMAX = 82;
+
+/// Cannot exec a shared library directly
+pub const ELIBEXEC = 83;
+
+/// Illegal byte sequence
+pub const EILSEQ = 84;
+
+/// Interrupted system call should be restarted
+pub const ERESTART = 85;
+
+/// Streams pipe error
+pub const ESTRPIPE = 86;
+
+/// Too many users
+pub const EUSERS = 87;
+
+/// Socket operation on non-socket
+pub const ENOTSOCK = 88;
+
+/// Destination address required
+pub const EDESTADDRREQ = 89;
+
+/// Message too long
+pub const EMSGSIZE = 90;
+
+/// Protocol wrong type for socket
+pub const EPROTOTYPE = 91;
+
+/// Protocol not available
+pub const ENOPROTOOPT = 92;
+
+/// Protocol not supported
+pub const EPROTONOSUPPORT = 93;
+
+/// Socket type not supported
+pub const ESOCKTNOSUPPORT = 94;
+
+/// Operation not supported on transport endpoint
+pub const EOPNOTSUPP = 95;
+pub const ENOTSUP = EOPNOTSUPP;
+
+/// Protocol family not supported
+pub const EPFNOSUPPORT = 96;
+
+/// Address family not supported by protocol
+pub const EAFNOSUPPORT = 97;
+
+/// Address already in use
+pub const EADDRINUSE = 98;
+
+/// Cannot assign requested address
+pub const EADDRNOTAVAIL = 99;
+
+/// Network is down
+pub const ENETDOWN = 100;
+
+/// Network is unreachable
+pub const ENETUNREACH = 101;
+
+/// Network dropped connection because of reset
+pub const ENETRESET = 102;
+
+/// Software caused connection abort
+pub const ECONNABORTED = 103;
+
+/// Connection reset by peer
+pub const ECONNRESET = 104;
+
+/// No buffer space available
+pub const ENOBUFS = 105;
+
+/// Transport endpoint is already connected
+pub const EISCONN = 106;
+
+/// Transport endpoint is not connected
+pub const ENOTCONN = 107;
+
+/// Cannot send after transport endpoint shutdown
+pub const ESHUTDOWN = 108;
+
+/// Too many references: cannot splice
+pub const ETOOMANYREFS = 109;
+
+/// Connection timed out
+pub const ETIMEDOUT = 110;
+
+/// Connection refused
+pub const ECONNREFUSED = 111;
+
+/// Host is down
+pub const EHOSTDOWN = 112;
+
+/// No route to host
+pub const EHOSTUNREACH = 113;
+
+/// Operation already in progress
+pub const EALREADY = 114;
+
+/// Operation now in progress
+pub const EINPROGRESS = 115;
+
+/// Stale NFS file handle
+pub const ESTALE = 116;
+
+/// Structure needs cleaning
+pub const EUCLEAN = 117;
+
+/// Not a XENIX named type file
+pub const ENOTNAM = 118;
+
+/// No XENIX semaphores available
+pub const ENAVAIL = 119;
+
+/// Is a named type file
+pub const EISNAM = 120;
+
+/// Remote I/O error
+pub const EREMOTEIO = 121;
+
+/// Quota exceeded
+pub const EDQUOT = 122;
+
+/// No medium found
+pub const ENOMEDIUM = 123;
+
+/// Wrong medium type
+pub const EMEDIUMTYPE = 124;
+
+// nameserver query return codes
+
+/// DNS server returned answer with no data
+pub const ENSROK = 0;
+
+/// DNS server returned answer with no data
+pub const ENSRNODATA = 160;
+
+/// DNS server claims query was misformatted
+pub const ENSRFORMERR = 161;
+
+/// DNS server returned general failure
+pub const ENSRSERVFAIL = 162;
+
+/// Domain name not found
+pub const ENSRNOTFOUND = 163;
+
+/// DNS server does not implement requested operation
+pub const ENSRNOTIMP = 164;
+
+/// DNS server refused query
+pub const ENSRREFUSED = 165;
+
+/// Misformatted DNS query
+pub const ENSRBADQUERY = 166;
+
+/// Misformatted domain name
+pub const ENSRBADNAME = 167;
+
+/// Unsupported address family
+pub const ENSRBADFAMILY = 168;
+
+/// Misformatted DNS reply
+pub const ENSRBADRESP = 169;
+
+/// Could not contact DNS servers
+pub const ENSRCONNREFUSED = 170;
+
+/// Timeout while contacting DNS servers
+pub const ENSRTIMEOUT = 171;
+
+/// End of file
+pub const ENSROF = 172;
+
+/// Error reading file
+pub const ENSRFILE = 173;
+
+/// Out of memory
+pub const ENSRNOMEM = 174;
+
+/// Application terminated lookup
+pub const ENSRDESTRUCTION = 175;
+
+/// Domain name is too long
+pub const ENSRQUERYDOMAINTOOLONG = 176;
+
+/// Domain name is too long
+pub const ENSRCNAMELOOP = 177;
diff --git a/std/os/bits/linux/x86_64.zig b/std/os/bits/linux/x86_64.zig
new file mode 100644
index 0000000000..12ac6b8d7a
--- /dev/null
+++ b/std/os/bits/linux/x86_64.zig
@@ -0,0 +1,470 @@
+// x86-64-specific declarations that are intended to be imported into the POSIX namespace.
+const std = @import("../../../std.zig");
+
+const linux = std.os.linux;
+const sockaddr = linux.sockaddr;
+const socklen_t = linux.socklen_t;
+const iovec = linux.iovec;
+const iovec_const = linux.iovec_const;
+
+pub const SYS_read = 0;
+pub const SYS_write = 1;
+pub const SYS_open = 2;
+pub const SYS_close = 3;
+pub const SYS_stat = 4;
+pub const SYS_fstat = 5;
+pub const SYS_lstat = 6;
+pub const SYS_poll = 7;
+pub const SYS_lseek = 8;
+pub const SYS_mmap = 9;
+pub const SYS_mprotect = 10;
+pub const SYS_munmap = 11;
+pub const SYS_brk = 12;
+pub const SYS_rt_sigaction = 13;
+pub const SYS_rt_sigprocmask = 14;
+pub const SYS_rt_sigreturn = 15;
+pub const SYS_ioctl = 16;
+pub const SYS_pread = 17;
+pub const SYS_pwrite = 18;
+pub const SYS_readv = 19;
+pub const SYS_writev = 20;
+pub const SYS_access = 21;
+pub const SYS_pipe = 22;
+pub const SYS_select = 23;
+pub const SYS_sched_yield = 24;
+pub const SYS_mremap = 25;
+pub const SYS_msync = 26;
+pub const SYS_mincore = 27;
+pub const SYS_madvise = 28;
+pub const SYS_shmget = 29;
+pub const SYS_shmat = 30;
+pub const SYS_shmctl = 31;
+pub const SYS_dup = 32;
+pub const SYS_dup2 = 33;
+pub const SYS_pause = 34;
+pub const SYS_nanosleep = 35;
+pub const SYS_getitimer = 36;
+pub const SYS_alarm = 37;
+pub const SYS_setitimer = 38;
+pub const SYS_getpid = 39;
+pub const SYS_sendfile = 40;
+pub const SYS_socket = 41;
+pub const SYS_connect = 42;
+pub const SYS_accept = 43;
+pub const SYS_sendto = 44;
+pub const SYS_recvfrom = 45;
+pub const SYS_sendmsg = 46;
+pub const SYS_recvmsg = 47;
+pub const SYS_shutdown = 48;
+pub const SYS_bind = 49;
+pub const SYS_listen = 50;
+pub const SYS_getsockname = 51;
+pub const SYS_getpeername = 52;
+pub const SYS_socketpair = 53;
+pub const SYS_setsockopt = 54;
+pub const SYS_getsockopt = 55;
+pub const SYS_clone = 56;
+pub const SYS_fork = 57;
+pub const SYS_vfork = 58;
+pub const SYS_execve = 59;
+pub const SYS_exit = 60;
+pub const SYS_wait4 = 61;
+pub const SYS_kill = 62;
+pub const SYS_uname = 63;
+pub const SYS_semget = 64;
+pub const SYS_semop = 65;
+pub const SYS_semctl = 66;
+pub const SYS_shmdt = 67;
+pub const SYS_msgget = 68;
+pub const SYS_msgsnd = 69;
+pub const SYS_msgrcv = 70;
+pub const SYS_msgctl = 71;
+pub const SYS_fcntl = 72;
+pub const SYS_flock = 73;
+pub const SYS_fsync = 74;
+pub const SYS_fdatasync = 75;
+pub const SYS_truncate = 76;
+pub const SYS_ftruncate = 77;
+pub const SYS_getdents = 78;
+pub const SYS_getcwd = 79;
+pub const SYS_chdir = 80;
+pub const SYS_fchdir = 81;
+pub const SYS_rename = 82;
+pub const SYS_mkdir = 83;
+pub const SYS_rmdir = 84;
+pub const SYS_creat = 85;
+pub const SYS_link = 86;
+pub const SYS_unlink = 87;
+pub const SYS_symlink = 88;
+pub const SYS_readlink = 89;
+pub const SYS_chmod = 90;
+pub const SYS_fchmod = 91;
+pub const SYS_chown = 92;
+pub const SYS_fchown = 93;
+pub const SYS_lchown = 94;
+pub const SYS_umask = 95;
+pub const SYS_gettimeofday = 96;
+pub const SYS_getrlimit = 97;
+pub const SYS_getrusage = 98;
+pub const SYS_sysinfo = 99;
+pub const SYS_times = 100;
+pub const SYS_ptrace = 101;
+pub const SYS_getuid = 102;
+pub const SYS_syslog = 103;
+pub const SYS_getgid = 104;
+pub const SYS_setuid = 105;
+pub const SYS_setgid = 106;
+pub const SYS_geteuid = 107;
+pub const SYS_getegid = 108;
+pub const SYS_setpgid = 109;
+pub const SYS_getppid = 110;
+pub const SYS_getpgrp = 111;
+pub const SYS_setsid = 112;
+pub const SYS_setreuid = 113;
+pub const SYS_setregid = 114;
+pub const SYS_getgroups = 115;
+pub const SYS_setgroups = 116;
+pub const SYS_setresuid = 117;
+pub const SYS_getresuid = 118;
+pub const SYS_setresgid = 119;
+pub const SYS_getresgid = 120;
+pub const SYS_getpgid = 121;
+pub const SYS_setfsuid = 122;
+pub const SYS_setfsgid = 123;
+pub const SYS_getsid = 124;
+pub const SYS_capget = 125;
+pub const SYS_capset = 126;
+pub const SYS_rt_sigpending = 127;
+pub const SYS_rt_sigtimedwait = 128;
+pub const SYS_rt_sigqueueinfo = 129;
+pub const SYS_rt_sigsuspend = 130;
+pub const SYS_sigaltstack = 131;
+pub const SYS_utime = 132;
+pub const SYS_mknod = 133;
+pub const SYS_uselib = 134;
+pub const SYS_personality = 135;
+pub const SYS_ustat = 136;
+pub const SYS_statfs = 137;
+pub const SYS_fstatfs = 138;
+pub const SYS_sysfs = 139;
+pub const SYS_getpriority = 140;
+pub const SYS_setpriority = 141;
+pub const SYS_sched_setparam = 142;
+pub const SYS_sched_getparam = 143;
+pub const SYS_sched_setscheduler = 144;
+pub const SYS_sched_getscheduler = 145;
+pub const SYS_sched_get_priority_max = 146;
+pub const SYS_sched_get_priority_min = 147;
+pub const SYS_sched_rr_get_interval = 148;
+pub const SYS_mlock = 149;
+pub const SYS_munlock = 150;
+pub const SYS_mlockall = 151;
+pub const SYS_munlockall = 152;
+pub const SYS_vhangup = 153;
+pub const SYS_modify_ldt = 154;
+pub const SYS_pivot_root = 155;
+pub const SYS__sysctl = 156;
+pub const SYS_prctl = 157;
+pub const SYS_arch_prctl = 158;
+pub const SYS_adjtimex = 159;
+pub const SYS_setrlimit = 160;
+pub const SYS_chroot = 161;
+pub const SYS_sync = 162;
+pub const SYS_acct = 163;
+pub const SYS_settimeofday = 164;
+pub const SYS_mount = 165;
+pub const SYS_umount2 = 166;
+pub const SYS_swapon = 167;
+pub const SYS_swapoff = 168;
+pub const SYS_reboot = 169;
+pub const SYS_sethostname = 170;
+pub const SYS_setdomainname = 171;
+pub const SYS_iopl = 172;
+pub const SYS_ioperm = 173;
+pub const SYS_create_module = 174;
+pub const SYS_init_module = 175;
+pub const SYS_delete_module = 176;
+pub const SYS_get_kernel_syms = 177;
+pub const SYS_query_module = 178;
+pub const SYS_quotactl = 179;
+pub const SYS_nfsservctl = 180;
+pub const SYS_getpmsg = 181;
+pub const SYS_putpmsg = 182;
+pub const SYS_afs_syscall = 183;
+pub const SYS_tuxcall = 184;
+pub const SYS_security = 185;
+pub const SYS_gettid = 186;
+pub const SYS_readahead = 187;
+pub const SYS_setxattr = 188;
+pub const SYS_lsetxattr = 189;
+pub const SYS_fsetxattr = 190;
+pub const SYS_getxattr = 191;
+pub const SYS_lgetxattr = 192;
+pub const SYS_fgetxattr = 193;
+pub const SYS_listxattr = 194;
+pub const SYS_llistxattr = 195;
+pub const SYS_flistxattr = 196;
+pub const SYS_removexattr = 197;
+pub const SYS_lremovexattr = 198;
+pub const SYS_fremovexattr = 199;
+pub const SYS_tkill = 200;
+pub const SYS_time = 201;
+pub const SYS_futex = 202;
+pub const SYS_sched_setaffinity = 203;
+pub const SYS_sched_getaffinity = 204;
+pub const SYS_set_thread_area = 205;
+pub const SYS_io_setup = 206;
+pub const SYS_io_destroy = 207;
+pub const SYS_io_getevents = 208;
+pub const SYS_io_submit = 209;
+pub const SYS_io_cancel = 210;
+pub const SYS_get_thread_area = 211;
+pub const SYS_lookup_dcookie = 212;
+pub const SYS_epoll_create = 213;
+pub const SYS_epoll_ctl_old = 214;
+pub const SYS_epoll_wait_old = 215;
+pub const SYS_remap_file_pages = 216;
+pub const SYS_getdents64 = 217;
+pub const SYS_set_tid_address = 218;
+pub const SYS_restart_syscall = 219;
+pub const SYS_semtimedop = 220;
+pub const SYS_fadvise64 = 221;
+pub const SYS_timer_create = 222;
+pub const SYS_timer_settime = 223;
+pub const SYS_timer_gettime = 224;
+pub const SYS_timer_getoverrun = 225;
+pub const SYS_timer_delete = 226;
+pub const SYS_clock_settime = 227;
+pub const SYS_clock_gettime = 228;
+pub const SYS_clock_getres = 229;
+pub const SYS_clock_nanosleep = 230;
+pub const SYS_exit_group = 231;
+pub const SYS_epoll_wait = 232;
+pub const SYS_epoll_ctl = 233;
+pub const SYS_tgkill = 234;
+pub const SYS_utimes = 235;
+pub const SYS_vserver = 236;
+pub const SYS_mbind = 237;
+pub const SYS_set_mempolicy = 238;
+pub const SYS_get_mempolicy = 239;
+pub const SYS_mq_open = 240;
+pub const SYS_mq_unlink = 241;
+pub const SYS_mq_timedsend = 242;
+pub const SYS_mq_timedreceive = 243;
+pub const SYS_mq_notify = 244;
+pub const SYS_mq_getsetattr = 245;
+pub const SYS_kexec_load = 246;
+pub const SYS_waitid = 247;
+pub const SYS_add_key = 248;
+pub const SYS_request_key = 249;
+pub const SYS_keyctl = 250;
+pub const SYS_ioprio_set = 251;
+pub const SYS_ioprio_get = 252;
+pub const SYS_inotify_init = 253;
+pub const SYS_inotify_add_watch = 254;
+pub const SYS_inotify_rm_watch = 255;
+pub const SYS_migrate_pages = 256;
+pub const SYS_openat = 257;
+pub const SYS_mkdirat = 258;
+pub const SYS_mknodat = 259;
+pub const SYS_fchownat = 260;
+pub const SYS_futimesat = 261;
+pub const SYS_newfstatat = 262;
+pub const SYS_fstatat = 262;
+pub const SYS_unlinkat = 263;
+pub const SYS_renameat = 264;
+pub const SYS_linkat = 265;
+pub const SYS_symlinkat = 266;
+pub const SYS_readlinkat = 267;
+pub const SYS_fchmodat = 268;
+pub const SYS_faccessat = 269;
+pub const SYS_pselect6 = 270;
+pub const SYS_ppoll = 271;
+pub const SYS_unshare = 272;
+pub const SYS_set_robust_list = 273;
+pub const SYS_get_robust_list = 274;
+pub const SYS_splice = 275;
+pub const SYS_tee = 276;
+pub const SYS_sync_file_range = 277;
+pub const SYS_vmsplice = 278;
+pub const SYS_move_pages = 279;
+pub const SYS_utimensat = 280;
+pub const SYS_epoll_pwait = 281;
+pub const SYS_signalfd = 282;
+pub const SYS_timerfd_create = 283;
+pub const SYS_eventfd = 284;
+pub const SYS_fallocate = 285;
+pub const SYS_timerfd_settime = 286;
+pub const SYS_timerfd_gettime = 287;
+pub const SYS_accept4 = 288;
+pub const SYS_signalfd4 = 289;
+pub const SYS_eventfd2 = 290;
+pub const SYS_epoll_create1 = 291;
+pub const SYS_dup3 = 292;
+pub const SYS_pipe2 = 293;
+pub const SYS_inotify_init1 = 294;
+pub const SYS_preadv = 295;
+pub const SYS_pwritev = 296;
+pub const SYS_rt_tgsigqueueinfo = 297;
+pub const SYS_perf_event_open = 298;
+pub const SYS_recvmmsg = 299;
+pub const SYS_fanotify_init = 300;
+pub const SYS_fanotify_mark = 301;
+pub const SYS_prlimit64 = 302;
+pub const SYS_name_to_handle_at = 303;
+pub const SYS_open_by_handle_at = 304;
+pub const SYS_clock_adjtime = 305;
+pub const SYS_syncfs = 306;
+pub const SYS_sendmmsg = 307;
+pub const SYS_setns = 308;
+pub const SYS_getcpu = 309;
+pub const SYS_process_vm_readv = 310;
+pub const SYS_process_vm_writev = 311;
+pub const SYS_kcmp = 312;
+pub const SYS_finit_module = 313;
+pub const SYS_sched_setattr = 314;
+pub const SYS_sched_getattr = 315;
+pub const SYS_renameat2 = 316;
+pub const SYS_seccomp = 317;
+pub const SYS_getrandom = 318;
+pub const SYS_memfd_create = 319;
+pub const SYS_kexec_file_load = 320;
+pub const SYS_bpf = 321;
+pub const SYS_execveat = 322;
+pub const SYS_userfaultfd = 323;
+pub const SYS_membarrier = 324;
+pub const SYS_mlock2 = 325;
+pub const SYS_copy_file_range = 326;
+pub const SYS_preadv2 = 327;
+pub const SYS_pwritev2 = 328;
+pub const SYS_pkey_mprotect = 329;
+pub const SYS_pkey_alloc = 330;
+pub const SYS_pkey_free = 331;
+pub const SYS_statx = 332;
+pub const SYS_io_pgetevents = 333;
+pub const SYS_rseq = 334;
+pub const SYS_pidfd_send_signal = 424;
+pub const SYS_io_uring_setup = 425;
+pub const SYS_io_uring_enter = 426;
+pub const SYS_io_uring_register = 427;
+
+pub const O_CREAT = 0o100;
+pub const O_EXCL = 0o200;
+pub const O_NOCTTY = 0o400;
+pub const O_TRUNC = 0o1000;
+pub const O_APPEND = 0o2000;
+pub const O_NONBLOCK = 0o4000;
+pub const O_DSYNC = 0o10000;
+pub const O_SYNC = 0o4010000;
+pub const O_RSYNC = 0o4010000;
+pub const O_DIRECTORY = 0o200000;
+pub const O_NOFOLLOW = 0o400000;
+pub const O_CLOEXEC = 0o2000000;
+
+pub const O_ASYNC = 0o20000;
+pub const O_DIRECT = 0o40000;
+pub const O_LARGEFILE = 0;
+pub const O_NOATIME = 0o1000000;
+pub const O_PATH = 0o10000000;
+pub const O_TMPFILE = 0o20200000;
+pub const O_NDELAY = O_NONBLOCK;
+
+pub const F_DUPFD = 0;
+pub const F_GETFD = 1;
+pub const F_SETFD = 2;
+pub const F_GETFL = 3;
+pub const F_SETFL = 4;
+
+pub const F_SETOWN = 8;
+pub const F_GETOWN = 9;
+pub const F_SETSIG = 10;
+pub const F_GETSIG = 11;
+
+pub const F_GETLK = 5;
+pub const F_SETLK = 6;
+pub const F_SETLKW = 7;
+
+pub const F_SETOWN_EX = 15;
+pub const F_GETOWN_EX = 16;
+
+pub const F_GETOWNER_UIDS = 17;
+
+pub const AT_FDCWD = -100;
+pub const AT_SYMLINK_NOFOLLOW = 0x100;
+pub const AT_REMOVEDIR = 0x200;
+pub const AT_SYMLINK_FOLLOW = 0x400;
+pub const AT_NO_AUTOMOUNT = 0x800;
+pub const AT_EMPTY_PATH = 0x1000;
+
+pub const VDSO_USEFUL = true;
+pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
+pub const VDSO_CGT_VER = "LINUX_2.6";
+pub const VDSO_GETCPU_SYM = "__vdso_getcpu";
+pub const VDSO_GETCPU_VER = "LINUX_2.6";
+
+pub const ARCH_SET_GS = 0x1001;
+pub const ARCH_SET_FS = 0x1002;
+pub const ARCH_GET_FS = 0x1003;
+pub const ARCH_GET_GS = 0x1004;
+
+pub const msghdr = extern struct {
+ msg_name: ?*sockaddr,
+ msg_namelen: socklen_t,
+ msg_iov: [*]iovec,
+ msg_iovlen: i32,
+ __pad1: i32,
+ msg_control: ?*c_void,
+ msg_controllen: socklen_t,
+ __pad2: socklen_t,
+ msg_flags: i32,
+};
+
+pub const msghdr_const = extern struct {
+ msg_name: ?*const sockaddr,
+ msg_namelen: socklen_t,
+ msg_iov: [*]iovec_const,
+ msg_iovlen: i32,
+ __pad1: i32,
+ msg_control: ?*c_void,
+ msg_controllen: socklen_t,
+ __pad2: socklen_t,
+ msg_flags: i32,
+};
+
+/// Renamed to Stat to not conflict with the stat function.
+pub const Stat = extern struct {
+ dev: u64,
+ ino: u64,
+ nlink: usize,
+
+ mode: u32,
+ uid: u32,
+ gid: u32,
+ __pad0: u32,
+ rdev: u64,
+ size: i64,
+ blksize: isize,
+ blocks: i64,
+
+ atim: timespec,
+ mtim: timespec,
+ ctim: timespec,
+ __unused: [3]isize,
+};
+
+pub const timespec = extern struct {
+ tv_sec: isize,
+ tv_nsec: isize,
+};
+
+pub const timeval = extern struct {
+ tv_sec: isize,
+ tv_usec: isize,
+};
+
+pub const timezone = extern struct {
+ tz_minuteswest: i32,
+ tz_dsttime: i32,
+};
+
+pub const Elf_Symndx = u32;
diff --git a/std/os/bits/netbsd.zig b/std/os/bits/netbsd.zig
new file mode 100644
index 0000000000..fc4c2904e0
--- /dev/null
+++ b/std/os/bits/netbsd.zig
@@ -0,0 +1,725 @@
+const std = @import("../../std.zig");
+const maxInt = std.math.maxInt;
+
+pub const fd_t = c_int;
+pub const pid_t = c_int;
+
+/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
+pub const Kevent = extern struct {
+ ident: usize,
+ filter: i32,
+ flags: u32,
+ fflags: u32,
+ data: i64,
+ udata: usize,
+};
+
+pub const pthread_attr_t = extern struct {
+ pta_magic: u32,
+ pta_flags: c_int,
+ pta_private: *c_void,
+};
+
+pub const msghdr = extern struct {
+ /// optional address
+ msg_name: ?*sockaddr,
+
+ /// size of address
+ msg_namelen: socklen_t,
+
+ /// scatter/gather array
+ msg_iov: [*]iovec,
+
+ /// # elements in msg_iov
+ msg_iovlen: i32,
+
+ /// ancillary data
+ msg_control: ?*c_void,
+
+ /// ancillary data buffer len
+ msg_controllen: socklen_t,
+
+ /// flags on received message
+ msg_flags: i32,
+};
+
+pub const msghdr_const = extern struct {
+ /// optional address
+ msg_name: ?*const sockaddr,
+
+ /// size of address
+ msg_namelen: socklen_t,
+
+ /// scatter/gather array
+ msg_iov: [*]iovec_const,
+
+ /// # elements in msg_iov
+ msg_iovlen: i32,
+
+ /// ancillary data
+ msg_control: ?*c_void,
+
+ /// ancillary data buffer len
+ msg_controllen: socklen_t,
+
+ /// flags on received message
+ msg_flags: i32,
+};
+
+pub const Stat = extern struct {
+ dev: u64,
+ mode: u32,
+ ino: u64,
+ nlink: usize,
+
+ uid: u32,
+ gid: u32,
+ rdev: u64,
+
+ atim: timespec,
+ mtim: timespec,
+ ctim: timespec,
+ birthtim: timespec,
+
+ size: i64,
+ blocks: i64,
+ blksize: isize,
+ flags: u32,
+ gen: u32,
+ __spare: [2]u32,
+};
+
+pub const timespec = extern struct {
+ tv_sec: i64,
+ tv_nsec: isize,
+};
+
+pub const dirent = extern struct {
+ d_fileno: u64,
+ d_reclen: u16,
+ d_namlen: u16,
+ d_type: u8,
+ d_off: i64,
+ d_name: [512]u8,
+};
+
+pub const in_port_t = u16;
+pub const sa_family_t = u8;
+
+pub const sockaddr = extern union {
+ in: sockaddr_in,
+ in6: sockaddr_in6,
+};
+
+pub const sockaddr_in = extern struct {
+ len: u8,
+ family: sa_family_t,
+ port: in_port_t,
+ addr: u32,
+ zero: [8]u8,
+};
+
+pub const sockaddr_in6 = extern struct {
+ len: u8,
+ family: sa_family_t,
+ port: in_port_t,
+ flowinfo: u32,
+ addr: [16]u8,
+ scope_id: u32,
+};
+
+pub const CTL_KERN = 1;
+pub const CTL_DEBUG = 5;
+
+pub const KERN_PROC_ARGS = 48; // struct: process argv/env
+pub const KERN_PROC_PATHNAME = 5; // path to executable
+
+pub const PATH_MAX = 1024;
+
+pub const STDIN_FILENO = 0;
+pub const STDOUT_FILENO = 1;
+pub const STDERR_FILENO = 2;
+
+pub const PROT_NONE = 0;
+pub const PROT_READ = 1;
+pub const PROT_WRITE = 2;
+pub const PROT_EXEC = 4;
+
+pub const CLOCK_REALTIME = 0;
+pub const CLOCK_VIRTUAL = 1;
+pub const CLOCK_PROF = 2;
+pub const CLOCK_MONOTONIC = 3;
+pub const CLOCK_THREAD_CPUTIME_ID = 0x20000000;
+pub const CLOCK_PROCESS_CPUTIME_ID = 0x40000000;
+
+pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
+pub const MAP_SHARED = 0x0001;
+pub const MAP_PRIVATE = 0x0002;
+pub const MAP_REMAPDUP = 0x0004;
+pub const MAP_FIXED = 0x0010;
+pub const MAP_RENAME = 0x0020;
+pub const MAP_NORESERVE = 0x0040;
+pub const MAP_INHERIT = 0x0080;
+pub const MAP_HASSEMAPHORE = 0x0200;
+pub const MAP_TRYFIXED = 0x0400;
+pub const MAP_WIRED = 0x0800;
+
+pub const MAP_FILE = 0x0000;
+pub const MAP_NOSYNC = 0x0800;
+pub const MAP_ANON = 0x1000;
+pub const MAP_ANONYMOUS = MAP_ANON;
+pub const MAP_STACK = 0x2000;
+
+pub const WNOHANG = 0x00000001;
+pub const WUNTRACED = 0x00000002;
+pub const WSTOPPED = WUNTRACED;
+pub const WCONTINUED = 0x00000010;
+pub const WNOWAIT = 0x00010000;
+pub const WEXITED = 0x00000020;
+pub const WTRAPPED = 0x00000040;
+
+pub const SA_ONSTACK = 0x0001;
+pub const SA_RESTART = 0x0002;
+pub const SA_RESETHAND = 0x0004;
+pub const SA_NOCLDSTOP = 0x0008;
+pub const SA_NODEFER = 0x0010;
+pub const SA_NOCLDWAIT = 0x0020;
+pub const SA_SIGINFO = 0x0040;
+
+pub const SIGHUP = 1;
+pub const SIGINT = 2;
+pub const SIGQUIT = 3;
+pub const SIGILL = 4;
+pub const SIGTRAP = 5;
+pub const SIGABRT = 6;
+pub const SIGIOT = SIGABRT;
+pub const SIGEMT = 7;
+pub const SIGFPE = 8;
+pub const SIGKILL = 9;
+pub const SIGBUS = 10;
+pub const SIGSEGV = 11;
+pub const SIGSYS = 12;
+pub const SIGPIPE = 13;
+pub const SIGALRM = 14;
+pub const SIGTERM = 15;
+pub const SIGURG = 16;
+pub const SIGSTOP = 17;
+pub const SIGTSTP = 18;
+pub const SIGCONT = 19;
+pub const SIGCHLD = 20;
+pub const SIGTTIN = 21;
+pub const SIGTTOU = 22;
+pub const SIGIO = 23;
+pub const SIGXCPU = 24;
+pub const SIGXFSZ = 25;
+pub const SIGVTALRM = 26;
+pub const SIGPROF = 27;
+pub const SIGWINCH = 28;
+pub const SIGINFO = 29;
+pub const SIGUSR1 = 30;
+pub const SIGUSR2 = 31;
+pub const SIGPWR = 32;
+
+pub const SIGRTMIN = 33;
+pub const SIGRTMAX = 63;
+
+// access function
+pub const F_OK = 0; // test for existence of file
+pub const X_OK = 1; // test for execute or search permission
+pub const W_OK = 2; // test for write permission
+pub const R_OK = 4; // test for read permission
+
+pub const O_RDONLY = 0x0000;
+pub const O_WRONLY = 0x0001;
+pub const O_RDWR = 0x0002;
+pub const O_ACCMODE = 0x0003;
+
+pub const O_CREAT = 0x0200;
+pub const O_EXCL = 0x0800;
+pub const O_NOCTTY = 0x8000;
+pub const O_TRUNC = 0x0400;
+pub const O_APPEND = 0x0008;
+pub const O_NONBLOCK = 0x0004;
+pub const O_DSYNC = 0x00010000;
+pub const O_SYNC = 0x0080;
+pub const O_RSYNC = 0x00020000;
+pub const O_DIRECTORY = 0x00080000;
+pub const O_NOFOLLOW = 0x00000100;
+pub const O_CLOEXEC = 0x00400000;
+
+pub const O_ASYNC = 0x0040;
+pub const O_DIRECT = 0x00080000;
+pub const O_LARGEFILE = 0;
+pub const O_NOATIME = 0;
+pub const O_PATH = 0;
+pub const O_TMPFILE = 0;
+pub const O_NDELAY = O_NONBLOCK;
+
+pub const F_DUPFD = 0;
+pub const F_GETFD = 1;
+pub const F_SETFD = 2;
+pub const F_GETFL = 3;
+pub const F_SETFL = 4;
+
+pub const F_GETOWN = 5;
+pub const F_SETOWN = 6;
+
+pub const F_GETLK = 7;
+pub const F_SETLK = 8;
+pub const F_SETLKW = 9;
+
+pub const SEEK_SET = 0;
+pub const SEEK_CUR = 1;
+pub const SEEK_END = 2;
+
+pub const SIG_BLOCK = 1;
+pub const SIG_UNBLOCK = 2;
+pub const SIG_SETMASK = 3;
+
+pub const SOCK_STREAM = 1;
+pub const SOCK_DGRAM = 2;
+pub const SOCK_RAW = 3;
+pub const SOCK_RDM = 4;
+pub const SOCK_SEQPACKET = 5;
+
+pub const SOCK_CLOEXEC = 0x10000000;
+pub const SOCK_NONBLOCK = 0x20000000;
+
+pub const PROTO_ip = 0;
+pub const PROTO_icmp = 1;
+pub const PROTO_igmp = 2;
+pub const PROTO_ggp = 3;
+pub const PROTO_ipencap = 4;
+pub const PROTO_tcp = 6;
+pub const PROTO_egp = 8;
+pub const PROTO_pup = 12;
+pub const PROTO_udp = 17;
+pub const PROTO_xns_idp = 22;
+pub const PROTO_iso_tp4 = 29;
+pub const PROTO_ipv6 = 41;
+pub const PROTO_ipv6_route = 43;
+pub const PROTO_ipv6_frag = 44;
+pub const PROTO_rsvp = 46;
+pub const PROTO_gre = 47;
+pub const PROTO_esp = 50;
+pub const PROTO_ah = 51;
+pub const PROTO_ipv6_icmp = 58;
+pub const PROTO_ipv6_nonxt = 59;
+pub const PROTO_ipv6_opts = 60;
+pub const PROTO_encap = 98;
+pub const PROTO_pim = 103;
+pub const PROTO_raw = 255;
+
+pub const PF_UNSPEC = 0;
+pub const PF_LOCAL = 1;
+pub const PF_UNIX = PF_LOCAL;
+pub const PF_FILE = PF_LOCAL;
+pub const PF_INET = 2;
+pub const PF_APPLETALK = 16;
+pub const PF_INET6 = 24;
+pub const PF_DECnet = 12;
+pub const PF_KEY = 29;
+pub const PF_ROUTE = 34;
+pub const PF_SNA = 11;
+pub const PF_MPLS = 33;
+pub const PF_CAN = 35;
+pub const PF_BLUETOOTH = 31;
+pub const PF_ISDN = 26;
+pub const PF_MAX = 37;
+
+pub const AF_UNSPEC = PF_UNSPEC;
+pub const AF_LOCAL = PF_LOCAL;
+pub const AF_UNIX = AF_LOCAL;
+pub const AF_FILE = AF_LOCAL;
+pub const AF_INET = PF_INET;
+pub const AF_APPLETALK = PF_APPLETALK;
+pub const AF_INET6 = PF_INET6;
+pub const AF_KEY = PF_KEY;
+pub const AF_ROUTE = PF_ROUTE;
+pub const AF_SNA = PF_SNA;
+pub const AF_MPLS = PF_MPLS;
+pub const AF_CAN = PF_CAN;
+pub const AF_BLUETOOTH = PF_BLUETOOTH;
+pub const AF_ISDN = PF_ISDN;
+pub const AF_MAX = PF_MAX;
+
+pub const DT_UNKNOWN = 0;
+pub const DT_FIFO = 1;
+pub const DT_CHR = 2;
+pub const DT_DIR = 4;
+pub const DT_BLK = 6;
+pub const DT_REG = 8;
+pub const DT_LNK = 10;
+pub const DT_SOCK = 12;
+pub const DT_WHT = 14;
+
+/// add event to kq (implies enable)
+pub const EV_ADD = 0x0001;
+
+/// delete event from kq
+pub const EV_DELETE = 0x0002;
+
+/// enable event
+pub const EV_ENABLE = 0x0004;
+
+/// disable event (not reported)
+pub const EV_DISABLE = 0x0008;
+
+/// only report one occurrence
+pub const EV_ONESHOT = 0x0010;
+
+/// clear event state after reporting
+pub const EV_CLEAR = 0x0020;
+
+/// force immediate event output
+/// ... with or without EV_ERROR
+/// ... use KEVENT_FLAG_ERROR_EVENTS
+/// on syscalls supporting flags
+pub const EV_RECEIPT = 0x0040;
+
+/// disable event after reporting
+pub const EV_DISPATCH = 0x0080;
+
+pub const EVFILT_READ = 0;
+pub const EVFILT_WRITE = 1;
+
+/// attached to aio requests
+pub const EVFILT_AIO = 2;
+
+/// attached to vnodes
+pub const EVFILT_VNODE = 3;
+
+/// attached to struct proc
+pub const EVFILT_PROC = 4;
+
+/// attached to struct proc
+pub const EVFILT_SIGNAL = 5;
+
+/// timers
+pub const EVFILT_TIMER = 6;
+
+/// Filesystem events
+pub const EVFILT_FS = 7;
+
+/// On input, NOTE_TRIGGER causes the event to be triggered for output.
+pub const NOTE_TRIGGER = 0x08000000;
+
+/// low water mark
+pub const NOTE_LOWAT = 0x00000001;
+
+/// vnode was removed
+pub const NOTE_DELETE = 0x00000001;
+
+/// data contents changed
+pub const NOTE_WRITE = 0x00000002;
+
+/// size increased
+pub const NOTE_EXTEND = 0x00000004;
+
+/// attributes changed
+pub const NOTE_ATTRIB = 0x00000008;
+
+/// link count changed
+pub const NOTE_LINK = 0x00000010;
+
+/// vnode was renamed
+pub const NOTE_RENAME = 0x00000020;
+
+/// vnode access was revoked
+pub const NOTE_REVOKE = 0x00000040;
+
+/// process exited
+pub const NOTE_EXIT = 0x80000000;
+
+/// process forked
+pub const NOTE_FORK = 0x40000000;
+
+/// process exec'd
+pub const NOTE_EXEC = 0x20000000;
+
+/// mask for signal & exit status
+pub const NOTE_PDATAMASK = 0x000fffff;
+pub const NOTE_PCTRLMASK = 0xf0000000;
+
+pub const TIOCCBRK = 0x2000747a;
+pub const TIOCCDTR = 0x20007478;
+pub const TIOCCONS = 0x80047462;
+pub const TIOCDCDTIMESTAMP = 0x40107458;
+pub const TIOCDRAIN = 0x2000745e;
+pub const TIOCEXCL = 0x2000740d;
+pub const TIOCEXT = 0x80047460;
+pub const TIOCFLAG_CDTRCTS = 0x10;
+pub const TIOCFLAG_CLOCAL = 0x2;
+pub const TIOCFLAG_CRTSCTS = 0x4;
+pub const TIOCFLAG_MDMBUF = 0x8;
+pub const TIOCFLAG_SOFTCAR = 0x1;
+pub const TIOCFLUSH = 0x80047410;
+pub const TIOCGETA = 0x402c7413;
+pub const TIOCGETD = 0x4004741a;
+pub const TIOCGFLAGS = 0x4004745d;
+pub const TIOCGLINED = 0x40207442;
+pub const TIOCGPGRP = 0x40047477;
+pub const TIOCGQSIZE = 0x40047481;
+pub const TIOCGRANTPT = 0x20007447;
+pub const TIOCGSID = 0x40047463;
+pub const TIOCGSIZE = 0x40087468;
+pub const TIOCGWINSZ = 0x40087468;
+pub const TIOCMBIC = 0x8004746b;
+pub const TIOCMBIS = 0x8004746c;
+pub const TIOCMGET = 0x4004746a;
+pub const TIOCMSET = 0x8004746d;
+pub const TIOCM_CAR = 0x40;
+pub const TIOCM_CD = 0x40;
+pub const TIOCM_CTS = 0x20;
+pub const TIOCM_DSR = 0x100;
+pub const TIOCM_DTR = 0x2;
+pub const TIOCM_LE = 0x1;
+pub const TIOCM_RI = 0x80;
+pub const TIOCM_RNG = 0x80;
+pub const TIOCM_RTS = 0x4;
+pub const TIOCM_SR = 0x10;
+pub const TIOCM_ST = 0x8;
+pub const TIOCNOTTY = 0x20007471;
+pub const TIOCNXCL = 0x2000740e;
+pub const TIOCOUTQ = 0x40047473;
+pub const TIOCPKT = 0x80047470;
+pub const TIOCPKT_DATA = 0x0;
+pub const TIOCPKT_DOSTOP = 0x20;
+pub const TIOCPKT_FLUSHREAD = 0x1;
+pub const TIOCPKT_FLUSHWRITE = 0x2;
+pub const TIOCPKT_IOCTL = 0x40;
+pub const TIOCPKT_NOSTOP = 0x10;
+pub const TIOCPKT_START = 0x8;
+pub const TIOCPKT_STOP = 0x4;
+pub const TIOCPTMGET = 0x40287446;
+pub const TIOCPTSNAME = 0x40287448;
+pub const TIOCRCVFRAME = 0x80087445;
+pub const TIOCREMOTE = 0x80047469;
+pub const TIOCSBRK = 0x2000747b;
+pub const TIOCSCTTY = 0x20007461;
+pub const TIOCSDTR = 0x20007479;
+pub const TIOCSETA = 0x802c7414;
+pub const TIOCSETAF = 0x802c7416;
+pub const TIOCSETAW = 0x802c7415;
+pub const TIOCSETD = 0x8004741b;
+pub const TIOCSFLAGS = 0x8004745c;
+pub const TIOCSIG = 0x2000745f;
+pub const TIOCSLINED = 0x80207443;
+pub const TIOCSPGRP = 0x80047476;
+pub const TIOCSQSIZE = 0x80047480;
+pub const TIOCSSIZE = 0x80087467;
+pub const TIOCSTART = 0x2000746e;
+pub const TIOCSTAT = 0x80047465;
+pub const TIOCSTI = 0x80017472;
+pub const TIOCSTOP = 0x2000746f;
+pub const TIOCSWINSZ = 0x80087467;
+pub const TIOCUCNTL = 0x80047466;
+pub const TIOCXMTFRAME = 0x80087444;
+
+pub fn WEXITSTATUS(s: u32) u32 {
+ return (s >> 8) & 0xff;
+}
+pub fn WTERMSIG(s: u32) u32 {
+ return s & 0x7f;
+}
+pub fn WSTOPSIG(s: u32) u32 {
+ return WEXITSTATUS(s);
+}
+pub fn WIFEXITED(s: u32) bool {
+ return WTERMSIG(s) == 0;
+}
+
+pub fn WIFCONTINUED(s: u32) bool {
+ return ((s & 0x7f) == 0xffff);
+}
+
+pub fn WIFSTOPPED(s: u32) bool {
+ return ((s & 0x7f != 0x7f) and !WIFCONTINUED(s));
+}
+
+pub fn WIFSIGNALED(s: u32) bool {
+ return !WIFSTOPPED(s) and !WIFCONTINUED(s) and !WIFEXITED(s);
+}
+
+pub const winsize = extern struct {
+ ws_row: u16,
+ ws_col: u16,
+ ws_xpixel: u16,
+ ws_ypixel: u16,
+};
+
+const NSIG = 32;
+
+pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
+pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
+pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
+
+/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
+pub const Sigaction = extern struct {
+ /// signal handler
+ __sigaction_u: extern union {
+ __sa_handler: extern fn (i32) void,
+ __sa_sigaction: extern fn (i32, *__siginfo, usize) void,
+ },
+
+ /// see signal options
+ sa_flags: u32,
+
+ /// signal mask to apply
+ sa_mask: sigset_t,
+};
+
+pub const _SIG_WORDS = 4;
+pub const _SIG_MAXSIG = 128;
+
+pub inline fn _SIG_IDX(sig: usize) usize {
+ return sig - 1;
+}
+pub inline fn _SIG_WORD(sig: usize) usize {
+ return_SIG_IDX(sig) >> 5;
+}
+pub inline fn _SIG_BIT(sig: usize) usize {
+ return 1 << (_SIG_IDX(sig) & 31);
+}
+pub inline fn _SIG_VALID(sig: usize) usize {
+ return sig <= _SIG_MAXSIG and sig > 0;
+}
+
+pub const sigset_t = extern struct {
+ __bits: [_SIG_WORDS]u32,
+};
+
+pub const EPERM = 1; // Operation not permitted
+pub const ENOENT = 2; // No such file or directory
+pub const ESRCH = 3; // No such process
+pub const EINTR = 4; // Interrupted system call
+pub const EIO = 5; // Input/output error
+pub const ENXIO = 6; // Device not configured
+pub const E2BIG = 7; // Argument list too long
+pub const ENOEXEC = 8; // Exec format error
+pub const EBADF = 9; // Bad file descriptor
+pub const ECHILD = 10; // No child processes
+pub const EDEADLK = 11; // Resource deadlock avoided
+// 11 was EAGAIN
+pub const ENOMEM = 12; // Cannot allocate memory
+pub const EACCES = 13; // Permission denied
+pub const EFAULT = 14; // Bad address
+pub const ENOTBLK = 15; // Block device required
+pub const EBUSY = 16; // Device busy
+pub const EEXIST = 17; // File exists
+pub const EXDEV = 18; // Cross-device link
+pub const ENODEV = 19; // Operation not supported by device
+pub const ENOTDIR = 20; // Not a directory
+pub const EISDIR = 21; // Is a directory
+pub const EINVAL = 22; // Invalid argument
+pub const ENFILE = 23; // Too many open files in system
+pub const EMFILE = 24; // Too many open files
+pub const ENOTTY = 25; // Inappropriate ioctl for device
+pub const ETXTBSY = 26; // Text file busy
+pub const EFBIG = 27; // File too large
+pub const ENOSPC = 28; // No space left on device
+pub const ESPIPE = 29; // Illegal seek
+pub const EROFS = 30; // Read-only file system
+pub const EMLINK = 31; // Too many links
+pub const EPIPE = 32; // Broken pipe
+
+// math software
+pub const EDOM = 33; // Numerical argument out of domain
+pub const ERANGE = 34; // Result too large or too small
+
+// non-blocking and interrupt i/o
+pub const EAGAIN = 35; // Resource temporarily unavailable
+pub const EWOULDBLOCK = EAGAIN; // Operation would block
+pub const EINPROGRESS = 36; // Operation now in progress
+pub const EALREADY = 37; // Operation already in progress
+
+// ipc/network software -- argument errors
+pub const ENOTSOCK = 38; // Socket operation on non-socket
+pub const EDESTADDRREQ = 39; // Destination address required
+pub const EMSGSIZE = 40; // Message too long
+pub const EPROTOTYPE = 41; // Protocol wrong type for socket
+pub const ENOPROTOOPT = 42; // Protocol option not available
+pub const EPROTONOSUPPORT = 43; // Protocol not supported
+pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
+pub const EOPNOTSUPP = 45; // Operation not supported
+pub const EPFNOSUPPORT = 46; // Protocol family not supported
+pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
+pub const EADDRINUSE = 48; // Address already in use
+pub const EADDRNOTAVAIL = 49; // Can't assign requested address
+
+// ipc/network software -- operational errors
+pub const ENETDOWN = 50; // Network is down
+pub const ENETUNREACH = 51; // Network is unreachable
+pub const ENETRESET = 52; // Network dropped connection on reset
+pub const ECONNABORTED = 53; // Software caused connection abort
+pub const ECONNRESET = 54; // Connection reset by peer
+pub const ENOBUFS = 55; // No buffer space available
+pub const EISCONN = 56; // Socket is already connected
+pub const ENOTCONN = 57; // Socket is not connected
+pub const ESHUTDOWN = 58; // Can't send after socket shutdown
+pub const ETOOMANYREFS = 59; // Too many references: can't splice
+pub const ETIMEDOUT = 60; // Operation timed out
+pub const ECONNREFUSED = 61; // Connection refused
+
+pub const ELOOP = 62; // Too many levels of symbolic links
+pub const ENAMETOOLONG = 63; // File name too long
+
+// should be rearranged
+pub const EHOSTDOWN = 64; // Host is down
+pub const EHOSTUNREACH = 65; // No route to host
+pub const ENOTEMPTY = 66; // Directory not empty
+
+// quotas & mush
+pub const EPROCLIM = 67; // Too many processes
+pub const EUSERS = 68; // Too many users
+pub const EDQUOT = 69; // Disc quota exceeded
+
+// Network File System
+pub const ESTALE = 70; // Stale NFS file handle
+pub const EREMOTE = 71; // Too many levels of remote in path
+pub const EBADRPC = 72; // RPC struct is bad
+pub const ERPCMISMATCH = 73; // RPC version wrong
+pub const EPROGUNAVAIL = 74; // RPC prog. not avail
+pub const EPROGMISMATCH = 75; // Program version wrong
+pub const EPROCUNAVAIL = 76; // Bad procedure for program
+
+pub const ENOLCK = 77; // No locks available
+pub const ENOSYS = 78; // Function not implemented
+
+pub const EFTYPE = 79; // Inappropriate file type or format
+pub const EAUTH = 80; // Authentication error
+pub const ENEEDAUTH = 81; // Need authenticator
+
+// SystemV IPC
+pub const EIDRM = 82; // Identifier removed
+pub const ENOMSG = 83; // No message of desired type
+pub const EOVERFLOW = 84; // Value too large to be stored in data type
+
+// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
+pub const EILSEQ = 85; // Illegal byte sequence
+
+// From IEEE Std 1003.1-2001
+// Base, Realtime, Threads or Thread Priority Scheduling option errors
+pub const ENOTSUP = 86; // Not supported
+
+// Realtime option errors
+pub const ECANCELED = 87; // Operation canceled
+
+// Realtime, XSI STREAMS option errors
+pub const EBADMSG = 88; // Bad or Corrupt message
+
+// XSI STREAMS option errors
+pub const ENODATA = 89; // No message available
+pub const ENOSR = 90; // No STREAM resources
+pub const ENOSTR = 91; // Not a STREAM
+pub const ETIME = 92; // STREAM ioctl timeout
+
+// File system extended attribute errors
+pub const ENOATTR = 93; // Attribute not found
+
+// Realtime, XSI STREAMS option errors
+pub const EMULTIHOP = 94; // Multihop attempted
+pub const ENOLINK = 95; // Link has been severed
+pub const EPROTO = 96; // Protocol error
+
+pub const ELAST = 96; // Must equal largest errno
diff --git a/std/os/bits/wasi.zig b/std/os/bits/wasi.zig
new file mode 100644
index 0000000000..93d2a82fde
--- /dev/null
+++ b/std/os/bits/wasi.zig
@@ -0,0 +1,307 @@
+pub const STDIN_FILENO = 0;
+pub const STDOUT_FILENO = 1;
+pub const STDERR_FILENO = 2;
+
+pub const advice_t = u8;
+pub const ADVICE_NORMAL: advice_t = 0;
+pub const ADVICE_SEQUENTIAL: advice_t = 1;
+pub const ADVICE_RANDOM: advice_t = 2;
+pub const ADVICE_WILLNEED: advice_t = 3;
+pub const ADVICE_DONTNEED: advice_t = 4;
+pub const ADVICE_NOREUSE: advice_t = 5;
+
+pub const clockid_t = u32;
+pub const CLOCK_REALTIME: clockid_t = 0;
+pub const CLOCK_MONOTONIC: clockid_t = 1;
+pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;
+pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;
+
+pub const device_t = u64;
+
+pub const dircookie_t = u64;
+pub const DIRCOOKIE_START: dircookie_t = 0;
+
+pub const dirent_t = extern struct {
+ d_next: dircookie_t,
+ d_ino: inode_t,
+ d_namlen: u32,
+ d_type: filetype_t,
+};
+
+pub const errno_t = u16;
+pub const ESUCCESS: errno_t = 0;
+pub const E2BIG: errno_t = 1;
+pub const EACCES: errno_t = 2;
+pub const EADDRINUSE: errno_t = 3;
+pub const EADDRNOTAVAIL: errno_t = 4;
+pub const EAFNOSUPPORT: errno_t = 5;
+pub const EAGAIN: errno_t = 6;
+pub const EALREADY: errno_t = 7;
+pub const EBADF: errno_t = 8;
+pub const EBADMSG: errno_t = 9;
+pub const EBUSY: errno_t = 10;
+pub const ECANCELED: errno_t = 11;
+pub const ECHILD: errno_t = 12;
+pub const ECONNABORTED: errno_t = 13;
+pub const ECONNREFUSED: errno_t = 14;
+pub const ECONNRESET: errno_t = 15;
+pub const EDEADLK: errno_t = 16;
+pub const EDESTADDRREQ: errno_t = 17;
+pub const EDOM: errno_t = 18;
+pub const EDQUOT: errno_t = 19;
+pub const EEXIST: errno_t = 20;
+pub const EFAULT: errno_t = 21;
+pub const EFBIG: errno_t = 22;
+pub const EHOSTUNREACH: errno_t = 23;
+pub const EIDRM: errno_t = 24;
+pub const EILSEQ: errno_t = 25;
+pub const EINPROGRESS: errno_t = 26;
+pub const EINTR: errno_t = 27;
+pub const EINVAL: errno_t = 28;
+pub const EIO: errno_t = 29;
+pub const EISCONN: errno_t = 30;
+pub const EISDIR: errno_t = 31;
+pub const ELOOP: errno_t = 32;
+pub const EMFILE: errno_t = 33;
+pub const EMLINK: errno_t = 34;
+pub const EMSGSIZE: errno_t = 35;
+pub const EMULTIHOP: errno_t = 36;
+pub const ENAMETOOLONG: errno_t = 37;
+pub const ENETDOWN: errno_t = 38;
+pub const ENETRESET: errno_t = 39;
+pub const ENETUNREACH: errno_t = 40;
+pub const ENFILE: errno_t = 41;
+pub const ENOBUFS: errno_t = 42;
+pub const ENODEV: errno_t = 43;
+pub const ENOENT: errno_t = 44;
+pub const ENOEXEC: errno_t = 45;
+pub const ENOLCK: errno_t = 46;
+pub const ENOLINK: errno_t = 47;
+pub const ENOMEM: errno_t = 48;
+pub const ENOMSG: errno_t = 49;
+pub const ENOPROTOOPT: errno_t = 50;
+pub const ENOSPC: errno_t = 51;
+pub const ENOSYS: errno_t = 52;
+pub const ENOTCONN: errno_t = 53;
+pub const ENOTDIR: errno_t = 54;
+pub const ENOTEMPTY: errno_t = 55;
+pub const ENOTRECOVERABLE: errno_t = 56;
+pub const ENOTSOCK: errno_t = 57;
+pub const ENOTSUP: errno_t = 58;
+pub const ENOTTY: errno_t = 59;
+pub const ENXIO: errno_t = 60;
+pub const EOVERFLOW: errno_t = 61;
+pub const EOWNERDEAD: errno_t = 62;
+pub const EPERM: errno_t = 63;
+pub const EPIPE: errno_t = 64;
+pub const EPROTO: errno_t = 65;
+pub const EPROTONOSUPPORT: errno_t = 66;
+pub const EPROTOTYPE: errno_t = 67;
+pub const ERANGE: errno_t = 68;
+pub const EROFS: errno_t = 69;
+pub const ESPIPE: errno_t = 70;
+pub const ESRCH: errno_t = 71;
+pub const ESTALE: errno_t = 72;
+pub const ETIMEDOUT: errno_t = 73;
+pub const ETXTBSY: errno_t = 74;
+pub const EXDEV: errno_t = 75;
+pub const ENOTCAPABLE: errno_t = 76;
+
+pub const event_t = extern struct {
+ userdata: userdata_t,
+ @"error": errno_t,
+ @"type": eventtype_t,
+ u: extern union {
+ fd_readwrite: extern struct {
+ nbytes: filesize_t,
+ flags: eventrwflags_t,
+ },
+ },
+};
+
+pub const eventrwflags_t = u16;
+pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;
+
+pub const eventtype_t = u8;
+pub const EVENTTYPE_CLOCK: eventtype_t = 0;
+pub const EVENTTYPE_FD_READ: eventtype_t = 1;
+pub const EVENTTYPE_FD_WRITE: eventtype_t = 2;
+
+pub const exitcode_t = u32;
+
+pub const fd_t = u32;
+
+pub const fdflags_t = u16;
+pub const FDFLAG_APPEND: fdflags_t = 0x0001;
+pub const FDFLAG_DSYNC: fdflags_t = 0x0002;
+pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
+pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
+pub const FDFLAG_SYNC: fdflags_t = 0x0010;
+
+const fdstat_t = extern struct {
+ fs_filetype: filetype_t,
+ fs_flags: fdflags_t,
+ fs_rights_base: rights_t,
+ fs_rights_inheriting: rights_t,
+};
+
+pub const filedelta_t = i64;
+
+pub const filesize_t = u64;
+
+pub const filestat_t = extern struct {
+ st_dev: device_t,
+ st_ino: inode_t,
+ st_filetype: filetype_t,
+ st_nlink: linkcount_t,
+ st_size: filesize_t,
+ st_atim: timestamp_t,
+ st_mtim: timestamp_t,
+ st_ctim: timestamp_t,
+};
+
+pub const filetype_t = u8;
+pub const FILETYPE_UNKNOWN: filetype_t = 0;
+pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1;
+pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2;
+pub const FILETYPE_DIRECTORY: filetype_t = 3;
+pub const FILETYPE_REGULAR_FILE: filetype_t = 4;
+pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5;
+pub const FILETYPE_SOCKET_STREAM: filetype_t = 6;
+pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7;
+
+pub const fstflags_t = u16;
+pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001;
+pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002;
+pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004;
+pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
+
+pub const inode_t = u64;
+
+pub const linkcount_t = u32;
+
+pub const lookupflags_t = u32;
+pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001;
+
+pub const oflags_t = u16;
+pub const O_CREAT: oflags_t = 0x0001;
+pub const O_DIRECTORY: oflags_t = 0x0002;
+pub const O_EXCL: oflags_t = 0x0004;
+pub const O_TRUNC: oflags_t = 0x0008;
+
+pub const preopentype_t = u8;
+pub const PREOPENTYPE_DIR: preopentype_t = 0;
+
+pub const prestat_t = extern struct {
+ pr_type: preopentype_t,
+ u: extern union {
+ dir: extern struct {
+ pr_name_len: usize,
+ },
+ },
+};
+
+pub const riflags_t = u16;
+pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
+pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
+
+pub const rights_t = u64;
+pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
+pub const RIGHT_FD_READ: rights_t = 0x0000000000000002;
+pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004;
+pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008;
+pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010;
+pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020;
+pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040;
+pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080;
+pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100;
+pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200;
+pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400;
+pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800;
+pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000;
+pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000;
+pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000;
+pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000;
+pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000;
+pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000;
+pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000;
+pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000;
+pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000;
+pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000;
+pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000;
+pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000;
+pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000;
+pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000;
+pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000;
+pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000;
+pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000;
+
+pub const roflags_t = u16;
+pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
+
+pub const sdflags_t = u8;
+pub const SHUT_RD: sdflags_t = 0x01;
+pub const SHUT_WR: sdflags_t = 0x02;
+
+pub const siflags_t = u16;
+
+pub const signal_t = u8;
+pub const SIGHUP: signal_t = 1;
+pub const SIGINT: signal_t = 2;
+pub const SIGQUIT: signal_t = 3;
+pub const SIGILL: signal_t = 4;
+pub const SIGTRAP: signal_t = 5;
+pub const SIGABRT: signal_t = 6;
+pub const SIGBUS: signal_t = 7;
+pub const SIGFPE: signal_t = 8;
+pub const SIGKILL: signal_t = 9;
+pub const SIGUSR1: signal_t = 10;
+pub const SIGSEGV: signal_t = 11;
+pub const SIGUSR2: signal_t = 12;
+pub const SIGPIPE: signal_t = 13;
+pub const SIGALRM: signal_t = 14;
+pub const SIGTERM: signal_t = 15;
+pub const SIGCHLD: signal_t = 16;
+pub const SIGCONT: signal_t = 17;
+pub const SIGSTOP: signal_t = 18;
+pub const SIGTSTP: signal_t = 19;
+pub const SIGTTIN: signal_t = 20;
+pub const SIGTTOU: signal_t = 21;
+pub const SIGURG: signal_t = 22;
+pub const SIGXCPU: signal_t = 23;
+pub const SIGXFSZ: signal_t = 24;
+pub const SIGVTALRM: signal_t = 25;
+pub const SIGPROF: signal_t = 26;
+pub const SIGWINCH: signal_t = 27;
+pub const SIGPOLL: signal_t = 28;
+pub const SIGPWR: signal_t = 29;
+pub const SIGSYS: signal_t = 30;
+
+pub const subclockflags_t = u16;
+pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;
+
+pub const subscription_t = extern struct {
+ userdata: userdata_t,
+ @"type": eventtype_t,
+ u: extern union {
+ clock: extern struct {
+ identifier: userdata_t,
+ clock_id: clockid_t,
+ timeout: timestamp_t,
+ precision: timestamp_t,
+ flags: subclockflags_t,
+ },
+ fd_readwrite: extern struct {
+ fd: fd_t,
+ },
+ },
+};
+
+pub const timestamp_t = u64;
+
+pub const userdata_t = u64;
+
+pub const whence_t = u8;
+pub const WHENCE_CUR: whence_t = 0;
+pub const WHENCE_END: whence_t = 1;
+pub const WHENCE_SET: whence_t = 2;
diff --git a/std/os/bits/windows.zig b/std/os/bits/windows.zig
new file mode 100644
index 0000000000..a242113ba0
--- /dev/null
+++ b/std/os/bits/windows.zig
@@ -0,0 +1,167 @@
+// The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
+
+use @import("../windows/bits.zig");
+
+pub const fd_t = HANDLE;
+pub const pid_t = HANDLE;
+
+pub const PATH_MAX = 260;
+
+pub const time_t = c_longlong;
+
+pub const timespec = extern struct {
+ tv_sec: time_t,
+ tv_nsec: c_long,
+};
+
+pub const sig_atomic_t = c_int;
+
+/// maximum signal number + 1
+pub const NSIG = 23;
+
+// Signal types
+
+/// interrupt
+pub const SIGINT = 2;
+
+/// illegal instruction - invalid function image
+pub const SIGILL = 4;
+
+/// floating point exception
+pub const SIGFPE = 8;
+
+/// segment violation
+pub const SIGSEGV = 11;
+
+/// Software termination signal from kill
+pub const SIGTERM = 15;
+
+/// Ctrl-Break sequence
+pub const SIGBREAK = 21;
+
+/// abnormal termination triggered by abort call
+pub const SIGABRT = 22;
+
+/// SIGABRT compatible with other platforms, same as SIGABRT
+pub const SIGABRT_COMPAT = 6;
+
+// Signal action codes
+
+/// default signal action
+pub const SIG_DFL = 0;
+
+/// ignore signal
+pub const SIG_IGN = 1;
+
+/// return current value
+pub const SIG_GET = 2;
+
+/// signal gets error
+pub const SIG_SGE = 3;
+
+/// acknowledge
+pub const SIG_ACK = 4;
+
+/// Signal error value (returned by signal call on error)
+pub const SIG_ERR = -1;
+
+pub const SEEK_SET = 0;
+pub const SEEK_CUR = 1;
+pub const SEEK_END = 2;
+
+pub const EPERM = 1;
+pub const ENOENT = 2;
+pub const ESRCH = 3;
+pub const EINTR = 4;
+pub const EIO = 5;
+pub const ENXIO = 6;
+pub const E2BIG = 7;
+pub const ENOEXEC = 8;
+pub const EBADF = 9;
+pub const ECHILD = 10;
+pub const EAGAIN = 11;
+pub const ENOMEM = 12;
+pub const EACCES = 13;
+pub const EFAULT = 14;
+pub const EBUSY = 16;
+pub const EEXIST = 17;
+pub const EXDEV = 18;
+pub const ENODEV = 19;
+pub const ENOTDIR = 20;
+pub const EISDIR = 21;
+pub const ENFILE = 23;
+pub const EMFILE = 24;
+pub const ENOTTY = 25;
+pub const EFBIG = 27;
+pub const ENOSPC = 28;
+pub const ESPIPE = 29;
+pub const EROFS = 30;
+pub const EMLINK = 31;
+pub const EPIPE = 32;
+pub const EDOM = 33;
+pub const EDEADLK = 36;
+pub const ENAMETOOLONG = 38;
+pub const ENOLCK = 39;
+pub const ENOSYS = 40;
+pub const ENOTEMPTY = 41;
+
+pub const EINVAL = 22;
+pub const ERANGE = 34;
+pub const EILSEQ = 42;
+pub const STRUNCATE = 80;
+
+// Support EDEADLOCK for compatibility with older Microsoft C versions
+pub const EDEADLOCK = EDEADLK;
+
+// POSIX Supplement
+pub const EADDRINUSE = 100;
+pub const EADDRNOTAVAIL = 101;
+pub const EAFNOSUPPORT = 102;
+pub const EALREADY = 103;
+pub const EBADMSG = 104;
+pub const ECANCELED = 105;
+pub const ECONNABORTED = 106;
+pub const ECONNREFUSED = 107;
+pub const ECONNRESET = 108;
+pub const EDESTADDRREQ = 109;
+pub const EHOSTUNREACH = 110;
+pub const EIDRM = 111;
+pub const EINPROGRESS = 112;
+pub const EISCONN = 113;
+pub const ELOOP = 114;
+pub const EMSGSIZE = 115;
+pub const ENETDOWN = 116;
+pub const ENETRESET = 117;
+pub const ENETUNREACH = 118;
+pub const ENOBUFS = 119;
+pub const ENODATA = 120;
+pub const ENOLINK = 121;
+pub const ENOMSG = 122;
+pub const ENOPROTOOPT = 123;
+pub const ENOSR = 124;
+pub const ENOSTR = 125;
+pub const ENOTCONN = 126;
+pub const ENOTRECOVERABLE = 127;
+pub const ENOTSOCK = 128;
+pub const ENOTSUP = 129;
+pub const EOPNOTSUPP = 130;
+pub const EOTHER = 131;
+pub const EOVERFLOW = 132;
+pub const EOWNERDEAD = 133;
+pub const EPROTO = 134;
+pub const EPROTONOSUPPORT = 135;
+pub const EPROTOTYPE = 136;
+pub const ETIME = 137;
+pub const ETIMEDOUT = 138;
+pub const ETXTBSY = 139;
+pub const EWOULDBLOCK = 140;
+pub const EDQUOT = 10069;
+
+pub const F_OK = 0;
+
+// These are workarounds for "use of undeclared identifier" compile errors
+// TODO make the compiler even more lazy. don't emit "use of undeclared identifier" errors
+// for if branches that aren't taken.
+pub const SIGKILL = @compileError("Windows libc does not have this");
+
+