aboutsummaryrefslogtreecommitdiff
path: root/std/os
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-03-26 06:39:28 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-03-26 06:39:28 -0400
commit5bc9feb5cb98fc13db62d01b2b9fec15677310a7 (patch)
tree12972dfc1f9b964bb74428ec0d6766e77b9b0be7 /std/os
parent7ce753a16b0c16b4c6494467f42f2d5fe9a235e6 (diff)
downloadzig-5bc9feb5cb98fc13db62d01b2b9fec15677310a7.tar.gz
zig-5bc9feb5cb98fc13db62d01b2b9fec15677310a7.zip
organize std and make import relative to current file
closes #216
Diffstat (limited to 'std/os')
-rw-r--r--std/os/darwin.zig118
-rw-r--r--std/os/darwin_x86_64.zig87
-rw-r--r--std/os/errno.zig146
-rw-r--r--std/os/index.zig78
-rw-r--r--std/os/linux.zig492
-rw-r--r--std/os/linux_i386.zig497
-rw-r--r--std/os/linux_x86_64.zig480
-rw-r--r--std/os/windows.zig17
8 files changed, 1915 insertions, 0 deletions
diff --git a/std/os/darwin.zig b/std/os/darwin.zig
new file mode 100644
index 0000000000..647fee40e2
--- /dev/null
+++ b/std/os/darwin.zig
@@ -0,0 +1,118 @@
+
+const arch = switch (@compileVar("arch")) {
+ Arch.x86_64 => @import("darwin_x86_64.zig"),
+ else => @compileError("unsupported arch"),
+};
+
+const errno = @import("errno.zig");
+
+pub const O_LARGEFILE = 0x0000;
+pub const O_RDONLY = 0x0000;
+
+pub const SEEK_SET = 0x0;
+pub const SEEK_CUR = 0x1;
+pub const SEEK_END = 0x2;
+
+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 fn exit(status: usize) -> noreturn {
+ _ = arch.syscall1(arch.SYS_exit, status);
+ unreachable
+}
+
+/// Get the errno from a syscall return value, or 0 for no error.
+pub fn getErrno(r: usize) -> usize {
+ const signed_r = *(&isize)(&r);
+ if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
+}
+
+pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
+ arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count)
+}
+
+pub fn close(fd: i32) -> usize {
+ arch.syscall1(arch.SYS_close, usize(fd))
+}
+
+pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {
+ arch.syscall3(arch.SYS_open, usize(path), flags, perm)
+}
+
+pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {
+ const buf = @alloca(u8, path.len + 1);
+ @memcpy(&buf[0], &path[0], path.len);
+ buf[path.len] = 0;
+ return open_c(buf.ptr, flags, perm);
+}
+
+pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
+ arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count)
+}
+
+pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
+ arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
+}
+
+pub const stat = arch.stat;
+pub const timespec = arch.timespec;
+
+pub fn fstat(fd: i32, stat_buf: &stat) -> usize {
+ arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf))
+}
+
+error Unexpected;
+
+pub fn getrandom(buf: &u8, count: usize) -> usize {
+ const rr = open_c(c"/dev/urandom", O_LARGEFILE | O_RDONLY, 0);
+
+ if(getErrno(rr) > 0) return rr;
+
+ var fd: i32 = i32(rr);
+ const readRes = read(fd, buf, count);
+ readRes
+}
+
+pub fn raise(sig: i32) -> i32 {
+ // TODO investigate whether we need to block signals before calling kill
+ // like we do in the linux version of raise
+
+ //var set: sigset_t = undefined;
+ //blockAppSignals(&set);
+ const pid = i32(arch.syscall0(arch.SYS_getpid));
+ const ret = i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig)));
+ //restoreSignals(&set);
+ return ret;
+}
diff --git a/std/os/darwin_x86_64.zig b/std/os/darwin_x86_64.zig
new file mode 100644
index 0000000000..ea6cc5a37a
--- /dev/null
+++ b/std/os/darwin_x86_64.zig
@@ -0,0 +1,87 @@
+
+pub const SYSCALL_CLASS_SHIFT = 24;
+pub const SYSCALL_CLASS_MASK = 0xFF << SYSCALL_CLASS_SHIFT;
+// pub const SYSCALL_NUMBER_MASK = ~SYSCALL_CLASS_MASK; // ~ modifier not supported yet
+
+pub const SYSCALL_CLASS_NONE = 0; // Invalid
+pub const SYSCALL_CLASS_MACH = 1; // Mach
+pub const SYSCALL_CLASS_UNIX = 2; // Unix/BSD
+pub const SYSCALL_CLASS_MDEP = 3; // Machine-dependent
+pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics
+
+// TODO: use the above constants to create the below values
+
+pub const SYS_exit = 0x2000001;
+pub const SYS_read = 0x2000003;
+pub const SYS_write = 0x2000004;
+pub const SYS_open = 0x2000005;
+pub const SYS_close = 0x2000006;
+pub const SYS_kill = 0x2000025;
+pub const SYS_getpid = 0x2000030;
+pub const SYS_fstat = 0x20000BD;
+pub const SYS_lseek = 0x20000C7;
+
+pub inline fn syscall0(number: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number)
+ : "rcx", "r11")
+}
+
+pub inline fn syscall1(number: usize, arg1: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1)
+ : "rcx", "r11")
+}
+
+pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1),
+ [arg2] "{rsi}" (arg2)
+ : "rcx", "r11")
+}
+
+pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1),
+ [arg2] "{rsi}" (arg2),
+ [arg3] "{rdx}" (arg3)
+ : "rcx", "r11")
+}
+
+
+
+
+pub const stat = extern struct {
+ dev: u32,
+ mode: u16,
+ nlink: u16,
+ ino: u64,
+ uid: u32,
+ gid: u32,
+ rdev: u64,
+
+ atim: timespec,
+ mtim: timespec,
+ ctim: timespec,
+
+ size: u64,
+ blocks: u64,
+ blksize: u32,
+ flags: u32,
+ gen: u32,
+ lspare: i32,
+ qspare: [2]u64,
+
+};
+
+pub const timespec = extern struct {
+ tv_sec: isize,
+ tv_nsec: isize,
+};
diff --git a/std/os/errno.zig b/std/os/errno.zig
new file mode 100644
index 0000000000..6f50b50225
--- /dev/null
+++ b/std/os/errno.zig
@@ -0,0 +1,146 @@
+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; // I/O error
+pub const ENXIO = 6; // No such device or address
+pub const E2BIG = 7; // Arg list too long
+pub const ENOEXEC = 8; // Exec format error
+pub const EBADF = 9; // Bad file number
+pub const ECHILD = 10; // No child processes
+pub const EAGAIN = 11; // Try again
+pub const ENOMEM = 12; // Out of 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 or resource busy
+pub const EEXIST = 17; // File exists
+pub const EXDEV = 18; // Cross-device link
+pub const ENODEV = 19; // No such 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; // File table overflow
+pub const EMFILE = 24; // Too many open files
+pub const ENOTTY = 25; // Not a typewriter
+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
+pub const EDOM = 33; // Math argument out of domain of func
+pub const ERANGE = 34; // Math result not representable
+pub const EDEADLK = 35; // Resource deadlock would occur
+pub const ENAMETOOLONG = 36; // File name too long
+pub const ENOLCK = 37; // No record locks available
+pub const ENOSYS = 38; // Function not implemented
+pub const ENOTEMPTY = 39; // Directory not empty
+pub const ELOOP = 40; // Too many symbolic links encountered
+pub const EWOULDBLOCK = EAGAIN; // Operation would block
+pub const ENOMSG = 42; // No message of desired type
+pub const EIDRM = 43; // Identifier removed
+pub const ECHRNG = 44; // Channel number out of range
+pub const EL2NSYNC = 45; // Level 2 not synchronized
+pub const EL3HLT = 46; // Level 3 halted
+pub const EL3RST = 47; // Level 3 reset
+pub const ELNRNG = 48; // Link number out of range
+pub const EUNATCH = 49; // Protocol driver not attached
+pub const ENOCSI = 50; // No CSI structure available
+pub const EL2HLT = 51; // Level 2 halted
+pub const EBADE = 52; // Invalid exchange
+pub const EBADR = 53; // Invalid request descriptor
+pub const EXFULL = 54; // Exchange full
+pub const ENOANO = 55; // No anode
+pub const EBADRQC = 56; // Invalid request code
+pub const EBADSLT = 57; // Invalid slot
+
+pub const EBFONT = 59; // Bad font file format
+pub const ENOSTR = 60; // Device not a stream
+pub const ENODATA = 61; // No data available
+pub const ETIME = 62; // Timer expired
+pub const ENOSR = 63; // Out of streams resources
+pub const ENONET = 64; // Machine is not on the network
+pub const ENOPKG = 65; // Package not installed
+pub const EREMOTE = 66; // Object is remote
+pub const ENOLINK = 67; // Link has been severed
+pub const EADV = 68; // Advertise error
+pub const ESRMNT = 69; // Srmount error
+pub const ECOMM = 70; // Communication error on send
+pub const EPROTO = 71; // Protocol error
+pub const EMULTIHOP = 72; // Multihop attempted
+pub const EDOTDOT = 73; // RFS specific error
+pub const EBADMSG = 74; // Not a data message
+pub const EOVERFLOW = 75; // Value too large for defined data type
+pub const ENOTUNIQ = 76; // Name not unique on network
+pub const EBADFD = 77; // File descriptor in bad state
+pub const EREMCHG = 78; // Remote address changed
+pub const ELIBACC = 79; // Can not access a needed shared library
+pub const ELIBBAD = 80; // Accessing a corrupted shared library
+pub const ELIBSCN = 81; // .lib section in a.out corrupted
+pub const ELIBMAX = 82; // Attempting to link in too many shared libraries
+pub const ELIBEXEC = 83; // Cannot exec a shared library directly
+pub const EILSEQ = 84; // Illegal byte sequence
+pub const ERESTART = 85; // Interrupted system call should be restarted
+pub const ESTRPIPE = 86; // Streams pipe error
+pub const EUSERS = 87; // Too many users
+pub const ENOTSOCK = 88; // Socket operation on non-socket
+pub const EDESTADDRREQ = 89; // Destination address required
+pub const EMSGSIZE = 90; // Message too long
+pub const EPROTOTYPE = 91; // Protocol wrong type for socket
+pub const ENOPROTOOPT = 92; // Protocol not available
+pub const EPROTONOSUPPORT = 93; // Protocol not supported
+pub const ESOCKTNOSUPPORT = 94; // Socket type not supported
+pub const EOPNOTSUPP = 95; // Operation not supported on transport endpoint
+pub const EPFNOSUPPORT = 96; // Protocol family not supported
+pub const EAFNOSUPPORT = 97; // Address family not supported by protocol
+pub const EADDRINUSE = 98; // Address already in use
+pub const EADDRNOTAVAIL = 99; // Cannot assign requested address
+pub const ENETDOWN = 100; // Network is down
+pub const ENETUNREACH = 101; // Network is unreachable
+pub const ENETRESET = 102; // Network dropped connection because of reset
+pub const ECONNABORTED = 103; // Software caused connection abort
+pub const ECONNRESET = 104; // Connection reset by peer
+pub const ENOBUFS = 105; // No buffer space available
+pub const EISCONN = 106; // Transport endpoint is already connected
+pub const ENOTCONN = 107; // Transport endpoint is not connected
+pub const ESHUTDOWN = 108; // Cannot send after transport endpoint shutdown
+pub const ETOOMANYREFS = 109; // Too many references: cannot splice
+pub const ETIMEDOUT = 110; // Connection timed out
+pub const ECONNREFUSED = 111; // Connection refused
+pub const EHOSTDOWN = 112; // Host is down
+pub const EHOSTUNREACH = 113; // No route to host
+pub const EALREADY = 114; // Operation already in progress
+pub const EINPROGRESS = 115; // Operation now in progress
+pub const ESTALE = 116; // Stale NFS file handle
+pub const EUCLEAN = 117; // Structure needs cleaning
+pub const ENOTNAM = 118; // Not a XENIX named type file
+pub const ENAVAIL = 119; // No XENIX semaphores available
+pub const EISNAM = 120; // Is a named type file
+pub const EREMOTEIO = 121; // Remote I/O error
+pub const EDQUOT = 122; // Quota exceeded
+
+pub const ENOMEDIUM = 123; // No medium found
+pub const EMEDIUMTYPE = 124; // Wrong medium type
+
+// nameserver query return codes
+pub const ENSROK = 0; // DNS server returned answer with no data
+pub const ENSRNODATA = 160; // DNS server returned answer with no data
+pub const ENSRFORMERR = 161; // DNS server claims query was misformatted
+pub const ENSRSERVFAIL = 162; // DNS server returned general failure
+pub const ENSRNOTFOUND = 163; // Domain name not found
+pub const ENSRNOTIMP = 164; // DNS server does not implement requested operation
+pub const ENSRREFUSED = 165; // DNS server refused query
+pub const ENSRBADQUERY = 166; // Misformatted DNS query
+pub const ENSRBADNAME = 167; // Misformatted domain name
+pub const ENSRBADFAMILY = 168; // Unsupported address family
+pub const ENSRBADRESP = 169; // Misformatted DNS reply
+pub const ENSRCONNREFUSED = 170; // Could not contact DNS servers
+pub const ENSRTIMEOUT = 171; // Timeout while contacting DNS servers
+pub const ENSROF = 172; // End of file
+pub const ENSRFILE = 173; // Error reading file
+pub const ENSRNOMEM = 174; // Out of memory
+pub const ENSRDESTRUCTION = 175; // Application terminated lookup
+pub const ENSRQUERYDOMAINTOOLONG = 176; // Domain name is too long
+pub const ENSRCNAMELOOP = 177; // Domain name is too long
diff --git a/std/os/index.zig b/std/os/index.zig
new file mode 100644
index 0000000000..63e74924fa
--- /dev/null
+++ b/std/os/index.zig
@@ -0,0 +1,78 @@
+pub const windows = @import("windows.zig");
+pub const darwin = @import("darwin.zig");
+pub const linux = @import("linux.zig");
+pub const posix = switch(@compileVar("os")) {
+ Os.linux => linux,
+ Os.darwin, Os.macosx, Os.ios => darwin,
+ Os.windows => windows,
+ else => @compileError("Unsupported OS"),
+};
+
+const errno = @import("errno.zig");
+const linking_libc = @import("../target.zig").linking_libc;
+const c = @import("../c/index.zig");
+
+error Unexpected;
+
+/// Fills `buf` with random bytes. If linking against libc, this calls the
+/// appropriate OS-specific library call. Otherwise it uses the zig standard
+/// library implementation.
+pub fn getRandomBytes(buf: []u8) -> %void {
+ while (true) {
+ const err = switch (@compileVar("os")) {
+ Os.linux => {
+ if (linking_libc) {
+ if (c.getrandom(buf.ptr, buf.len, 0) == -1) *c._errno() else 0
+ } else {
+ posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0))
+ }
+ },
+ Os.darwin, Os.macosx, Os.ios => {
+ if (linking_libc) {
+ if (posix.getrandom(buf.ptr, buf.len) == -1) *c._errno() else 0
+ } else {
+ posix.getErrno(posix.getrandom(buf.ptr, buf.len))
+ }
+ },
+ Os.windows => {
+ var hCryptProv: windows.HCRYPTPROV = undefined;
+ if (!windows.CryptAcquireContext(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) {
+ return error.Unexpected;
+ }
+ defer _ = windows.CryptReleaseContext(hCryptProv, 0);
+
+ if (!windows.CryptGenRandom(hCryptProv, windows.DWORD(buf.len), buf.ptr)) {
+ return error.Unexpected;
+ }
+ return;
+ },
+ else => @compileError("Unsupported OS"),
+ };
+ if (err > 0) {
+ return switch (err) {
+ errno.EINVAL => unreachable,
+ errno.EFAULT => unreachable,
+ errno.EINTR => continue,
+ else => error.Unexpected,
+ }
+ }
+ return;
+ }
+}
+
+/// Raises a signal in the current kernel thread, ending its execution.
+/// If linking against libc, this calls the abort() libc function. Otherwise
+/// it uses the zig standard library implementation.
+pub coldcc fn abort() -> noreturn {
+ if (linking_libc) {
+ c.abort();
+ }
+ switch (@compileVar("os")) {
+ Os.linux => {
+ _ = posix.raise(posix.SIGABRT);
+ _ = posix.raise(posix.SIGKILL);
+ while (true) {}
+ },
+ else => @compileError("Unsupported OS"),
+ }
+}
diff --git a/std/os/linux.zig b/std/os/linux.zig
new file mode 100644
index 0000000000..be86136dee
--- /dev/null
+++ b/std/os/linux.zig
@@ -0,0 +1,492 @@
+const arch = switch (@compileVar("arch")) {
+ Arch.x86_64 => @import("linux_x86_64.zig"),
+ Arch.i386 => @import("linux_i386.zig"),
+ else => @compileError("unsupported arch"),
+};
+const errno = @import("errno.zig");
+
+pub const MMAP_PROT_NONE = 0;
+pub const MMAP_PROT_READ = 1;
+pub const MMAP_PROT_WRITE = 2;
+pub const MMAP_PROT_EXEC = 4;
+
+pub const MMAP_MAP_FILE = 0;
+pub const MMAP_MAP_SHARED = 1;
+pub const MMAP_MAP_PRIVATE = 2;
+pub const MMAP_MAP_FIXED = 16;
+pub const MMAP_MAP_ANON = 32;
+
+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 O_CREAT = arch.O_CREAT;
+pub const O_EXCL = arch.O_EXCL;
+pub const O_NOCTTY = arch.O_NOCTTY;
+pub const O_TRUNC = arch.O_TRUNC;
+pub const O_APPEND = arch.O_APPEND;
+pub const O_NONBLOCK = arch.O_NONBLOCK;
+pub const O_DSYNC = arch.O_DSYNC;
+pub const O_SYNC = arch.O_SYNC;
+pub const O_RSYNC = arch.O_RSYNC;
+pub const O_DIRECTORY = arch.O_DIRECTORY;
+pub const O_NOFOLLOW = arch.O_NOFOLLOW;
+pub const O_CLOEXEC = arch.O_CLOEXEC;
+
+pub const O_ASYNC = arch.O_ASYNC;
+pub const O_DIRECT = arch.O_DIRECT;
+pub const O_LARGEFILE = arch.O_LARGEFILE;
+pub const O_NOATIME = arch.O_NOATIME;
+pub const O_PATH = arch.O_PATH;
+pub const O_TMPFILE = arch.O_TMPFILE;
+pub const O_NDELAY = arch.O_NDELAY;
+
+pub const SEEK_SET = 0;
+pub const SEEK_CUR = 1;
+pub const SEEK_END = 2;
+
+const SIG_BLOCK = 0;
+const SIG_UNBLOCK = 1;
+const SIG_SETMASK = 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 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;
+
+/// Get the errno from a syscall return value, or 0 for no error.
+pub fn getErrno(r: usize) -> usize {
+ const signed_r = *(&isize)(&r);
+ if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
+}
+
+pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: usize)
+ -> usize
+{
+ arch.syscall6(arch.SYS_mmap, usize(address), length, prot, flags, usize(fd), offset)
+}
+
+pub fn munmap(address: &u8, length: usize) -> usize {
+ arch.syscall2(arch.SYS_munmap, usize(address), length)
+}
+
+pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
+ arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count)
+}
+
+pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize {
+ arch.syscall4(arch.SYS_pread, usize(fd), usize(buf), count, offset)
+}
+
+pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
+ arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count)
+}
+
+pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize {
+ arch.syscall4(arch.SYS_pwrite, usize(fd), usize(buf), count, offset)
+}
+
+pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {
+ arch.syscall3(arch.SYS_open, usize(path), flags, perm)
+}
+
+pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {
+ const buf = @alloca(u8, path.len + 1);
+ @memcpy(&buf[0], &path[0], path.len);
+ buf[path.len] = 0;
+ return open_c(buf.ptr, flags, perm);
+}
+
+pub fn create_c(path: &const u8, perm: usize) -> usize {
+ arch.syscall2(arch.SYS_creat, usize(path), perm)
+}
+
+pub fn create(path: []const u8, perm: usize) -> usize {
+ const buf = @alloca(u8, path.len + 1);
+ @memcpy(&buf[0], &path[0], path.len);
+ buf[path.len] = 0;
+ return create_c(buf.ptr, perm);
+}
+
+pub fn openat_c(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize {
+ arch.syscall4(arch.SYS_openat, usize(dirfd), usize(path), flags, mode)
+}
+
+pub fn openat(dirfd: i32, path: []const u8, flags: usize, mode: usize) -> usize {
+ const buf = @alloca(u8, path.len + 1);
+ @memcpy(&buf[0], &path[0], path.len);
+ buf[path.len] = 0;
+ return openat_c(dirfd, buf.ptr, flags, mode);
+}
+
+pub fn close(fd: i32) -> usize {
+ arch.syscall1(arch.SYS_close, usize(fd))
+}
+
+pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
+ arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
+}
+
+pub fn exit(status: i32) -> noreturn {
+ _ = arch.syscall1(arch.SYS_exit, usize(status));
+ unreachable
+}
+
+pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
+ arch.syscall3(arch.SYS_getrandom, usize(buf), count, usize(flags))
+}
+
+pub fn kill(pid: i32, sig: i32) -> i32 {
+ i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig)))
+}
+
+const NSIG = 65;
+const sigset_t = [128]u8;
+const all_mask = []u8 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, };
+const app_mask = []u8 { 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, };
+
+pub fn raise(sig: i32) -> i32 {
+ var set: sigset_t = undefined;
+ blockAppSignals(&set);
+ const tid = i32(arch.syscall0(arch.SYS_gettid));
+ const ret = i32(arch.syscall2(arch.SYS_tkill, usize(tid), usize(sig)));
+ restoreSignals(&set);
+ return ret;
+}
+
+fn blockAllSignals(set: &sigset_t) {
+ _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&all_mask), usize(set), NSIG/8);
+}
+
+fn blockAppSignals(set: &sigset_t) {
+ _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&app_mask), usize(set), NSIG/8);
+}
+
+fn restoreSignals(set: &sigset_t) {
+ _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, usize(set), 0, NSIG/8);
+}
+
+
+pub const sa_family_t = u16;
+pub const socklen_t = u32;
+pub const in_addr = u32;
+pub const in6_addr = [16]u8;
+
+pub const sockaddr = extern struct {
+ family: sa_family_t,
+ port: u16,
+ data: [12]u8,
+};
+
+pub const sockaddr_in = extern struct {
+ family: sa_family_t,
+ port: u16,
+ addr: in_addr,
+ zero: [8]u8,
+};
+
+pub const sockaddr_in6 = extern struct {
+ family: sa_family_t,
+ port: u16,
+ flowinfo: u32,
+ addr: in6_addr,
+ scope_id: u32,
+};
+
+pub const iovec = extern struct {
+ iov_base: &u8,
+ iov_len: usize,
+};
+
+//
+//const IF_NAMESIZE = 16;
+//
+//export struct ifreq {
+// ifrn_name: [IF_NAMESIZE]u8,
+// union {
+// ifru_addr: sockaddr,
+// ifru_dstaddr: sockaddr,
+// ifru_broadaddr: sockaddr,
+// ifru_netmask: sockaddr,
+// ifru_hwaddr: sockaddr,
+// ifru_flags: i16,
+// ifru_ivalue: i32,
+// ifru_mtu: i32,
+// ifru_map: ifmap,
+// ifru_slave: [IF_NAMESIZE]u8,
+// ifru_newname: [IF_NAMESIZE]u8,
+// ifru_data: &u8,
+// } ifr_ifru;
+//}
+//
+
+pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
+ arch.syscall3(arch.SYS_getsockname, usize(fd), usize(addr), usize(len))
+}
+
+pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
+ arch.syscall3(arch.SYS_getpeername, usize(fd), usize(addr), usize(len))
+}
+
+pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize {
+ arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol))
+}
+
+pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize {
+ arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen))
+}
+
+pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize {
+ arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen))
+}
+
+pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize {
+ arch.syscall3(arch.SYS_sendmsg, usize(fd), usize(msg), flags)
+}
+
+pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
+ arch.syscall3(arch.SYS_connect, usize(fd), usize(addr), usize(len))
+}
+
+pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize {
+ arch.syscall3(arch.SYS_recvmsg, usize(fd), usize(msg), flags)
+}
+
+pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
+ noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize
+{
+ arch.syscall6(arch.SYS_recvfrom, usize(fd), usize(buf), len, flags, usize(addr), usize(alen))
+}
+
+pub fn shutdown(fd: i32, how: i32) -> usize {
+ arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how))
+}
+
+pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
+ arch.syscall3(arch.SYS_bind, usize(fd), usize(addr), usize(len))
+}
+
+pub fn listen(fd: i32, backlog: i32) -> usize {
+ arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog))
+}
+
+pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize {
+ arch.syscall6(arch.SYS_sendto, usize(fd), usize(buf), len, flags, usize(addr), usize(alen))
+}
+
+pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize {
+ arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), usize(&fd[0]))
+}
+
+pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
+ accept4(fd, addr, len, 0)
+}
+
+pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize {
+ arch.syscall4(arch.SYS_accept4, usize(fd), usize(addr), usize(len), flags)
+}
+
+// error NameTooLong;
+// error SystemResources;
+// error Io;
+//
+// pub fn if_nametoindex(name: []u8) -> %u32 {
+// var ifr: ifreq = undefined;
+//
+// if (name.len >= ifr.ifr_name.len) {
+// return error.NameTooLong;
+// }
+//
+// const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
+// const socket_err = getErrno(socket_ret);
+// if (socket_err > 0) {
+// return error.SystemResources;
+// }
+// const socket_fd = i32(socket_ret);
+// @memcpy(&ifr.ifr_name[0], &name[0], name.len);
+// ifr.ifr_name[name.len] = 0;
+// const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr);
+// close(socket_fd);
+// const ioctl_err = getErrno(ioctl_ret);
+// if (ioctl_err > 0) {
+// return error.Io;
+// }
+// return ifr.ifr_ifindex;
+// }
+
+pub const stat = arch.stat;
+pub const timespec = arch.timespec;
+
+pub fn fstat(fd: i32, stat_buf: &stat) -> usize {
+ arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf))
+}
diff --git a/std/os/linux_i386.zig b/std/os/linux_i386.zig
new file mode 100644
index 0000000000..218043307e
--- /dev/null
+++ b/std/os/linux_i386.zig
@@ -0,0 +1,497 @@
+const linux = @import("linux.zig");
+const socklen_t = linux.socklen_t;
+const iovec = linux.iovec;
+
+pub const SYS_restart_syscall = 0;
+pub const SYS_exit = 1;
+pub const SYS_fork = 2;
+pub const SYS_read = 3;
+pub const SYS_write = 4;
+pub const SYS_open = 5;
+pub const SYS_close = 6;
+pub const SYS_waitpid = 7;
+pub const SYS_creat = 8;
+pub const SYS_link = 9;
+pub const SYS_unlink = 10;
+pub const SYS_execve = 11;
+pub const SYS_chdir = 12;
+pub const SYS_time = 13;
+pub const SYS_mknod = 14;
+pub const SYS_chmod = 15;
+pub const SYS_lchown = 16;
+pub const SYS_break = 17;
+pub const SYS_oldstat = 18;
+pub const SYS_lseek = 19;
+pub const SYS_getpid = 20;
+pub const SYS_mount = 21;
+pub const SYS_umount = 22;
+pub const SYS_setuid = 23;
+pub const SYS_getuid = 24;
+pub const SYS_stime = 25;
+pub const SYS_ptrace = 26;
+pub const SYS_alarm = 27;
+pub const SYS_oldfstat = 28;
+pub const SYS_pause = 29;
+pub const SYS_utime = 30;
+pub const SYS_stty = 31;
+pub const SYS_gtty = 32;
+pub const SYS_access = 33;
+pub const SYS_nice = 34;
+pub const SYS_ftime = 35;
+pub const SYS_sync = 36;
+pub const SYS_kill = 37;
+pub const SYS_rename = 38;
+pub const SYS_mkdir = 39;
+pub const SYS_rmdir = 40;
+pub const SYS_dup = 41;
+pub const SYS_pipe = 42;
+pub const SYS_times = 43;
+pub const SYS_prof = 44;
+pub const SYS_brk = 45;
+pub const SYS_setgid = 46;
+pub const SYS_getgid = 47;
+pub const SYS_signal = 48;
+pub const SYS_geteuid = 49;
+pub const SYS_getegid = 50;
+pub const SYS_acct = 51;
+pub const SYS_umount2 = 52;
+pub const SYS_lock = 53;
+pub const SYS_ioctl = 54;
+pub const SYS_fcntl = 55;
+pub const SYS_mpx = 56;
+pub const SYS_setpgid = 57;
+pub const SYS_ulimit = 58;
+pub const SYS_oldolduname = 59;
+pub const SYS_umask = 60;
+pub const SYS_chroot = 61;
+pub const SYS_ustat = 62;
+pub const SYS_dup2 = 63;
+pub const SYS_getppid = 64;
+pub const SYS_getpgrp = 65;
+pub const SYS_setsid = 66;
+pub const SYS_sigaction = 67;
+pub const SYS_sgetmask = 68;
+pub const SYS_ssetmask = 69;
+pub const SYS_setreuid = 70;
+pub const SYS_setregid = 71;
+pub const SYS_sigsuspend = 72;
+pub const SYS_sigpending = 73;
+pub const SYS_sethostname = 74;
+pub const SYS_setrlimit = 75;
+pub const SYS_getrlimit = 76;
+pub const SYS_getrusage = 77;
+pub const SYS_gettimeofday = 78;
+pub const SYS_settimeofday = 79;
+pub const SYS_getgroups = 80;
+pub const SYS_setgroups = 81;
+pub const SYS_select = 82;
+pub const SYS_symlink = 83;
+pub const SYS_oldlstat = 84;
+pub const SYS_readlink = 85;
+pub const SYS_uselib = 86;
+pub const SYS_swapon = 87;
+pub const SYS_reboot = 88;
+pub const SYS_readdir = 89;
+pub const SYS_mmap = 90;
+pub const SYS_munmap = 91;
+pub const SYS_truncate = 92;
+pub const SYS_ftruncate = 93;
+pub const SYS_fchmod = 94;
+pub const SYS_fchown = 95;
+pub const SYS_getpriority = 96;
+pub const SYS_setpriority = 97;
+pub const SYS_profil = 98;
+pub const SYS_statfs = 99;
+pub const SYS_fstatfs = 100;
+pub const SYS_ioperm = 101;
+pub const SYS_socketcall = 102;
+pub const SYS_syslog = 103;
+pub const SYS_setitimer = 104;
+pub const SYS_getitimer = 105;
+pub const SYS_stat = 106;
+pub const SYS_lstat = 107;
+pub const SYS_fstat = 108;
+pub const SYS_olduname = 109;
+pub const SYS_iopl = 110;
+pub const SYS_vhangup = 111;
+pub const SYS_idle = 112;
+pub const SYS_vm86old = 113;
+pub const SYS_wait4 = 114;
+pub const SYS_swapoff = 115;
+pub const SYS_sysinfo = 116;
+pub const SYS_ipc = 117;
+pub const SYS_fsync = 118;
+pub const SYS_sigreturn = 119;
+pub const SYS_clone = 120;
+pub const SYS_setdomainname = 121;
+pub const SYS_uname = 122;
+pub const SYS_modify_ldt = 123;
+pub const SYS_adjtimex = 124;
+pub const SYS_mprotect = 125;
+pub const SYS_sigprocmask = 126;
+pub const SYS_create_module = 127;
+pub const SYS_init_module = 128;
+pub const SYS_delete_module = 129;
+pub const SYS_get_kernel_syms = 130;
+pub const SYS_quotactl = 131;
+pub const SYS_getpgid = 132;
+pub const SYS_fchdir = 133;
+pub const SYS_bdflush = 134;
+pub const SYS_sysfs = 135;
+pub const SYS_personality = 136;
+pub const SYS_afs_syscall = 137;
+pub const SYS_setfsuid = 138;
+pub const SYS_setfsgid = 139;
+pub const SYS__llseek = 140;
+pub const SYS_getdents = 141;
+pub const SYS__newselect = 142;
+pub const SYS_flock = 143;
+pub const SYS_msync = 144;
+pub const SYS_readv = 145;
+pub const SYS_writev = 146;
+pub const SYS_getsid = 147;
+pub const SYS_fdatasync = 148;
+pub const SYS__sysctl = 149;
+pub const SYS_mlock = 150;
+pub const SYS_munlock = 151;
+pub const SYS_mlockall = 152;
+pub const SYS_munlockall = 153;
+pub const SYS_sched_setparam = 154;
+pub const SYS_sched_getparam = 155;
+pub const SYS_sched_setscheduler = 156;
+pub const SYS_sched_getscheduler = 157;
+pub const SYS_sched_yield = 158;
+pub const SYS_sched_get_priority_max = 159;
+pub const SYS_sched_get_priority_min = 160;
+pub const SYS_sched_rr_get_interval = 161;
+pub const SYS_nanosleep = 162;
+pub const SYS_mremap = 163;
+pub const SYS_setresuid = 164;
+pub const SYS_getresuid = 165;
+pub const SYS_vm86 = 166;
+pub const SYS_query_module = 167;
+pub const SYS_poll = 168;
+pub const SYS_nfsservctl = 169;
+pub const SYS_setresgid = 170;
+pub const SYS_getresgid = 171;
+pub const SYS_prctl = 172;
+pub const SYS_rt_sigreturn = 173;
+pub const SYS_rt_sigaction = 174;
+pub const SYS_rt_sigprocmask = 175;
+pub const SYS_rt_sigpending = 176;
+pub const SYS_rt_sigtimedwait = 177;
+pub const SYS_rt_sigqueueinfo = 178;
+pub const SYS_rt_sigsuspend = 179;
+pub const SYS_pread64 = 180;
+pub const SYS_pwrite64 = 181;
+pub const SYS_chown = 182;
+pub const SYS_getcwd = 183;
+pub const SYS_capget = 184;
+pub const SYS_capset = 185;
+pub const SYS_sigaltstack = 186;
+pub const SYS_sendfile = 187;
+pub const SYS_getpmsg = 188;
+pub const SYS_putpmsg = 189;
+pub const SYS_vfork = 190;
+pub const SYS_ugetrlimit = 191;
+pub const SYS_mmap2 = 192;
+pub const SYS_truncate64 = 193;
+pub const SYS_ftruncate64 = 194;
+pub const SYS_stat64 = 195;
+pub const SYS_lstat64 = 196;
+pub const SYS_fstat64 = 197;
+pub const SYS_lchown32 = 198;
+pub const SYS_getuid32 = 199;
+pub const SYS_getgid32 = 200;
+pub const SYS_geteuid32 = 201;
+pub const SYS_getegid32 = 202;
+pub const SYS_setreuid32 = 203;
+pub const SYS_setregid32 = 204;
+pub const SYS_getgroups32 = 205;
+pub const SYS_setgroups32 = 206;
+pub const SYS_fchown32 = 207;
+pub const SYS_setresuid32 = 208;
+pub const SYS_getresuid32 = 209;
+pub const SYS_setresgid32 = 210;
+pub const SYS_getresgid32 = 211;
+pub const SYS_chown32 = 212;
+pub const SYS_setuid32 = 213;
+pub const SYS_setgid32 = 214;
+pub const SYS_setfsuid32 = 215;
+pub const SYS_setfsgid32 = 216;
+pub const SYS_pivot_root = 217;
+pub const SYS_mincore = 218;
+pub const SYS_madvise = 219;
+pub const SYS_madvise1 = 219;
+pub const SYS_getdents64 = 220;
+pub const SYS_fcntl64 = 221;
+pub const SYS_gettid = 224;
+pub const SYS_readahead = 225;
+pub const SYS_setxattr = 226;
+pub const SYS_lsetxattr = 227;
+pub const SYS_fsetxattr = 228;
+pub const SYS_getxattr = 229;
+pub const SYS_lgetxattr = 230;
+pub const SYS_fgetxattr = 231;
+pub const SYS_listxattr = 232;
+pub const SYS_llistxattr = 233;
+pub const SYS_flistxattr = 234;
+pub const SYS_removexattr = 235;
+pub const SYS_lremovexattr = 236;
+pub const SYS_fremovexattr = 237;
+pub const SYS_tkill = 238;
+pub const SYS_sendfile64 = 239;
+pub const SYS_futex = 240;
+pub const SYS_sched_setaffinity = 241;
+pub const SYS_sched_getaffinity = 242;
+pub const SYS_set_thread_area = 243;
+pub const SYS_get_thread_area = 244;
+pub const SYS_io_setup = 245;
+pub const SYS_io_destroy = 246;
+pub const SYS_io_getevents = 247;
+pub const SYS_io_submit = 248;
+pub const SYS_io_cancel = 249;
+pub const SYS_fadvise64 = 250;
+pub const SYS_exit_group = 252;
+pub const SYS_lookup_dcookie = 253;
+pub const SYS_epoll_create = 254;
+pub const SYS_epoll_ctl = 255;
+pub const SYS_epoll_wait = 256;
+pub const SYS_remap_file_pages = 257;
+pub const SYS_set_tid_address = 258;
+pub const SYS_timer_create = 259;
+pub const SYS_timer_settime = SYS_timer_create+1;
+pub const SYS_timer_gettime = SYS_timer_create+2;
+pub const SYS_timer_getoverrun = SYS_timer_create+3;
+pub const SYS_timer_delete = SYS_timer_create+4;
+pub const SYS_clock_settime = SYS_timer_create+5;
+pub const SYS_clock_gettime = SYS_timer_create+6;
+pub const SYS_clock_getres = SYS_timer_create+7;
+pub const SYS_clock_nanosleep = SYS_timer_create+8;
+pub const SYS_statfs64 = 268;
+pub const SYS_fstatfs64 = 269;
+pub const SYS_tgkill = 270;
+pub const SYS_utimes = 271;
+pub const SYS_fadvise64_64 = 272;
+pub const SYS_vserver = 273;
+pub const SYS_mbind = 274;
+pub const SYS_get_mempolicy = 275;
+pub const SYS_set_mempolicy = 276;
+pub const SYS_mq_open = 277;
+pub const SYS_mq_unlink = SYS_mq_open+1;
+pub const SYS_mq_timedsend = SYS_mq_open+2;
+pub const SYS_mq_timedreceive = SYS_mq_open+3;
+pub const SYS_mq_notify = SYS_mq_open+4;
+pub const SYS_mq_getsetattr = SYS_mq_open+5;
+pub const SYS_kexec_load = 283;
+pub const SYS_waitid = 284;
+pub const SYS_add_key = 286;
+pub const SYS_request_key = 287;
+pub const SYS_keyctl = 288;
+pub const SYS_ioprio_set = 289;
+pub const SYS_ioprio_get = 290;
+pub const SYS_inotify_init = 291;
+pub const SYS_inotify_add_watch = 292;
+pub const SYS_inotify_rm_watch = 293;
+pub const SYS_migrate_pages = 294;
+pub const SYS_openat = 295;
+pub const SYS_mkdirat = 296;
+pub const SYS_mknodat = 297;
+pub const SYS_fchownat = 298;
+pub const SYS_futimesat = 299;
+pub const SYS_fstatat64 = 300;
+pub const SYS_unlinkat = 301;
+pub const SYS_renameat = 302;
+pub const SYS_linkat = 303;
+pub const SYS_symlinkat = 304;
+pub const SYS_readlinkat = 305;
+pub const SYS_fchmodat = 306;
+pub const SYS_faccessat = 307;
+pub const SYS_pselect6 = 308;
+pub const SYS_ppoll = 309;
+pub const SYS_unshare = 310;
+pub const SYS_set_robust_list = 311;
+pub const SYS_get_robust_list = 312;
+pub const SYS_splice = 313;
+pub const SYS_sync_file_range = 314;
+pub const SYS_tee = 315;
+pub const SYS_vmsplice = 316;
+pub const SYS_move_pages = 317;
+pub const SYS_getcpu = 318;
+pub const SYS_epoll_pwait = 319;
+pub const SYS_utimensat = 320;
+pub const SYS_signalfd = 321;
+pub const SYS_timerfd_create = 322;
+pub const SYS_eventfd = 323;
+pub const SYS_fallocate = 324;
+pub const SYS_timerfd_settime = 325;
+pub const SYS_timerfd_gettime = 326;
+pub const SYS_signalfd4 = 327;
+pub const SYS_eventfd2 = 328;
+pub const SYS_epoll_create1 = 329;
+pub const SYS_dup3 = 330;
+pub const SYS_pipe2 = 331;
+pub const SYS_inotify_init1 = 332;
+pub const SYS_preadv = 333;
+pub const SYS_pwritev = 334;
+pub const SYS_rt_tgsigqueueinfo = 335;
+pub const SYS_perf_event_open = 336;
+pub const SYS_recvmmsg = 337;
+pub const SYS_fanotify_init = 338;
+pub const SYS_fanotify_mark = 339;
+pub const SYS_prlimit64 = 340;
+pub const SYS_name_to_handle_at = 341;
+pub const SYS_open_by_handle_at = 342;
+pub const SYS_clock_adjtime = 343;
+pub const SYS_syncfs = 344;
+pub const SYS_sendmmsg = 345;
+pub const SYS_setns = 346;
+pub const SYS_process_vm_readv = 347;
+pub const SYS_process_vm_writev = 348;
+pub const SYS_kcmp = 349;
+pub const SYS_finit_module = 350;
+pub const SYS_sched_setattr = 351;
+pub const SYS_sched_getattr = 352;
+pub const SYS_renameat2 = 353;
+pub const SYS_seccomp = 354;
+pub const SYS_getrandom = 355;
+pub const SYS_memfd_create = 356;
+pub const SYS_bpf = 357;
+pub const SYS_execveat = 358;
+pub const SYS_socket = 359;
+pub const SYS_socketpair = 360;
+pub const SYS_bind = 361;
+pub const SYS_connect = 362;
+pub const SYS_listen = 363;
+pub const SYS_accept4 = 364;
+pub const SYS_getsockopt = 365;
+pub const SYS_setsockopt = 366;
+pub const SYS_getsockname = 367;
+pub const SYS_getpeername = 368;
+pub const SYS_sendto = 369;
+pub const SYS_sendmsg = 370;
+pub const SYS_recvfrom = 371;
+pub const SYS_recvmsg = 372;
+pub const SYS_shutdown = 373;
+pub const SYS_userfaultfd = 374;
+pub const SYS_membarrier = 375;
+pub const SYS_mlock2 = 376;
+
+
+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 = 0o100000;
+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 = 12;
+pub const F_SETLK = 13;
+pub const F_SETLKW = 14;
+
+pub const F_SETOWN_EX = 15;
+pub const F_GETOWN_EX = 16;
+
+pub const F_GETOWNER_UIDS = 17;
+
+pub inline fn syscall0(number: usize) -> usize {
+ asm volatile ("int 80h"
+ : [ret] "={eax}" (-> usize)
+ : [number] "{eax}" (number))
+}
+
+pub inline fn syscall1(number: usize, arg1: usize) -> usize {
+ asm volatile ("int 80h"
+ : [ret] "={eax}" (-> usize)
+ : [number] "{eax}" (number),
+ [arg1] "{ebx}" (arg1))
+}
+
+pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
+ asm volatile ("int 80h"
+ : [ret] "={eax}" (-> usize)
+ : [number] "{eax}" (number),
+ [arg1] "{ebx}" (arg1),
+ [arg2] "{ecx}" (arg2))
+}
+
+pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
+ asm volatile ("int 80h"
+ : [ret] "={eax}" (-> usize)
+ : [number] "{eax}" (number),
+ [arg1] "{ebx}" (arg1),
+ [arg2] "{ecx}" (arg2),
+ [arg3] "{edx}" (arg3))
+}
+
+pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
+ asm volatile ("int 80h"
+ : [ret] "={eax}" (-> usize)
+ : [number] "{eax}" (number),
+ [arg1] "{ebx}" (arg1),
+ [arg2] "{ecx}" (arg2),
+ [arg3] "{edx}" (arg3),
+ [arg4] "{esi}" (arg4))
+}
+
+pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
+ arg4: usize, arg5: usize) -> usize
+{
+ asm volatile ("int 80h"
+ : [ret] "={eax}" (-> usize)
+ : [number] "{eax}" (number),
+ [arg1] "{ebx}" (arg1),
+ [arg2] "{ecx}" (arg2),
+ [arg3] "{edx}" (arg3),
+ [arg4] "{esi}" (arg4),
+ [arg5] "{edi}" (arg5))
+}
+
+pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
+ arg4: usize, arg5: usize, arg6: usize) -> usize
+{
+ asm volatile ("int 80h"
+ : [ret] "={eax}" (-> usize)
+ : [number] "{eax}" (number),
+ [arg1] "{ebx}" (arg1),
+ [arg2] "{ecx}" (arg2),
+ [arg3] "{edx}" (arg3),
+ [arg4] "{esi}" (arg4),
+ [arg5] "{edi}" (arg5),
+ [arg6] "{ebp}" (arg6))
+}
+
+export struct msghdr {
+ msg_name: &u8,
+ msg_namelen: socklen_t,
+ msg_iov: &iovec,
+ msg_iovlen: i32,
+ msg_control: &u8,
+ msg_controllen: socklen_t,
+ msg_flags: i32,
+}
diff --git a/std/os/linux_x86_64.zig b/std/os/linux_x86_64.zig
new file mode 100644
index 0000000000..0f8f163ce2
--- /dev/null
+++ b/std/os/linux_x86_64.zig
@@ -0,0 +1,480 @@
+const linux = @import("linux.zig");
+const socklen_t = linux.socklen_t;
+const iovec = linux.iovec;
+
+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_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 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 inline fn syscall0(number: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number)
+ : "rcx", "r11")
+}
+
+pub inline fn syscall1(number: usize, arg1: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1)
+ : "rcx", "r11")
+}
+
+pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1),
+ [arg2] "{rsi}" (arg2)
+ : "rcx", "r11")
+}
+
+pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1),
+ [arg2] "{rsi}" (arg2),
+ [arg3] "{rdx}" (arg3)
+ : "rcx", "r11")
+}
+
+pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1),
+ [arg2] "{rsi}" (arg2),
+ [arg3] "{rdx}" (arg3),
+ [arg4] "{r10}" (arg4)
+ : "rcx", "r11")
+}
+
+pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1),
+ [arg2] "{rsi}" (arg2),
+ [arg3] "{rdx}" (arg3),
+ [arg4] "{r10}" (arg4),
+ [arg5] "{r8}" (arg5)
+ : "rcx", "r11")
+}
+
+pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
+ arg5: usize, arg6: usize) -> usize
+{
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1),
+ [arg2] "{rsi}" (arg2),
+ [arg3] "{rdx}" (arg3),
+ [arg4] "{r10}" (arg4),
+ [arg5] "{r8}" (arg5),
+ [arg6] "{r9}" (arg6)
+ : "rcx", "r11")
+}
+
+pub const msghdr = extern struct {
+ msg_name: &u8,
+ msg_namelen: socklen_t,
+ msg_iov: &iovec,
+ msg_iovlen: i32,
+ __pad1: i32,
+ msg_control: &u8,
+ msg_controllen: socklen_t,
+ __pad2: socklen_t,
+ msg_flags: i32,
+};
+
+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,
+};
diff --git a/std/os/windows.zig b/std/os/windows.zig
new file mode 100644
index 0000000000..f713f61abe
--- /dev/null
+++ b/std/os/windows.zig
@@ -0,0 +1,17 @@
+pub extern fn CryptAcquireContext(phProv: &HCRYPTPROV, pszContainer: LPCTSTR,
+ pszProvider: LPCTSTR, dwProvType: DWORD, dwFlags: DWORD) -> bool;
+
+pub extern fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool;
+
+pub extern fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool;
+
+pub const PROV_RSA_FULL = 1;
+
+
+pub const BYTE = u8;
+pub const DWORD = u32;
+// TODO something about unicode WCHAR vs char
+pub const TCHAR = u8;
+pub const LPCTSTR = ?&const TCHAR;
+pub const ULONG_PTR = usize;
+pub const HCRYPTPROV = ULONG_PTR;