Commit 102cb61e40

Marc Tiehuis <marctiehuis@gmail.com>
2018-07-09 10:54:36
Get freebsd std compiling again
1 parent 264dd2e
std/os/freebsd.zig
@@ -1,11 +1,11 @@
+const c = @import("../c/index.zig");
 const assert = @import("../debug.zig").assert;
 const builtin = @import("builtin");
 const arch = switch (builtin.arch) {
-    builtin.Arch.x86_64 => @import("freebsd_x86_64.zig"),
-    builtin.Arch.i386 => @import("freebsd_i386.zig"),
+    builtin.Arch.x86_64 => @import("x86_64.zig"),
     else => @compileError("unsupported arch"),
 };
-pub use @import("freebsd_errno.zig");
+pub use @import("errno.zig");
 
 pub const PATH_MAX = 1024;
 
@@ -13,85 +13,86 @@ 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 MAP_FAILED     = @maxValue(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_GUARD      = 0x00002000;
-pub const MAP_EXCL       = 0x00004000;
-pub const MAP_NOCORE     = 0x00020000;
+pub const PROT_NONE = 0;
+pub const PROT_READ = 1;
+pub const PROT_WRITE = 2;
+pub const PROT_EXEC = 4;
+
+pub const MAP_FAILED = @maxValue(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 MAP_32BIT = 0x00080000;
 
-pub const WNOHANG    = 1;
-pub const WUNTRACED  = 2;
-pub const WSTOPPED   = WUNTRACED;
+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 WNOWAIT = 8;
+pub const WEXITED = 16;
+pub const WTRAPPED = 32;
 
-pub const SA_ONSTACK   = 0x0001;
-pub const SA_RESTART   = 0x0002;
+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_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 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;
+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;
 
 pub const O_RDONLY = 0o0;
 pub const O_WRONLY = 0o1;
-pub const O_RDWR   = 0o2;
+pub const O_RDWR = 0o2;
 pub const O_ACCMODE = 0o3;
 
 pub const O_CREAT = arch.O_CREAT;
@@ -119,7 +120,7 @@ pub const SEEK_SET = 0;
 pub const SEEK_CUR = 1;
 pub const SEEK_END = 2;
 
-pub const SIG_BLOCK   = 1;
+pub const SIG_BLOCK = 1;
 pub const SIG_UNBLOCK = 2;
 pub const SIG_SETMASK = 3;
 
@@ -272,7 +273,6 @@ 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;
@@ -329,15 +329,30 @@ pub const TIOCGPKT = 0x80045438;
 pub const TIOCGPTLCK = 0x80045439;
 pub const TIOCGEXCL = 0x80045440;
 
-fn unsigned(s: i32) -> u32 { @bitCast(u32, s) }
-fn signed(s: u32) -> i32 { @bitCast(i32, s) }
-pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) }
-pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) }
-pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) }
-pub fn WIFEXITED(s: i32) -> bool { WTERMSIG(s) == 0 }
-pub fn WIFSTOPPED(s: i32) -> bool { (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00 }
-pub fn WIFSIGNALED(s: i32) -> bool { (unsigned(s)&0xffff)-%1 < 0xff }
-
+fn unsigned(s: i32) u32 {
+    return @bitCast(u32, s);
+}
+fn signed(s: u32) i32 {
+    return @bitCast(i32, s);
+}
+pub fn WEXITSTATUS(s: i32) i32 {
+    return signed((unsigned(s) & 0xff00) >> 8);
+}
+pub fn WTERMSIG(s: i32) i32 {
+    return signed(unsigned(s) & 0x7f);
+}
+pub fn WSTOPSIG(s: i32) i32 {
+    return WEXITSTATUS(s);
+}
+pub fn WIFEXITED(s: i32) bool {
+    return WTERMSIG(s) == 0;
+}
+pub fn WIFSTOPPED(s: i32) bool {
+    return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
+}
+pub fn WIFSIGNALED(s: i32) bool {
+    return (unsigned(s) & 0xffff) -% 1 < 0xff;
+}
 
 pub const winsize = extern struct {
     ws_row: u16,
@@ -347,182 +362,160 @@ pub const winsize = extern struct {
 };
 
 /// Get the errno from a syscall return value, or 0 for no error.
-pub fn getErrno(r: usize) -> usize {
+pub fn getErrno(r: usize) usize {
     const signed_r = @bitCast(isize, r);
-    if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
+    return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
 }
 
-pub fn dup2(old: i32, new: i32) -> usize {
-    arch.syscall2(arch.SYS_dup2, usize(old), usize(new))
+pub fn dup2(old: i32, new: i32) usize {
+    return arch.syscall2(arch.SYS_dup2, usize(old), usize(new));
 }
 
-pub fn chdir(path: &const u8) -> usize {
-    arch.syscall1(arch.SYS_chdir, @ptrToInt(path))
+pub fn chdir(path: [*]const u8) usize {
+    return arch.syscall1(arch.SYS_chdir, @ptrToInt(path));
 }
 
-pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize {
-    arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp))
+pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
+    return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
 }
 
-pub fn fork() -> usize {
-    arch.syscall0(arch.SYS_fork)
+pub fn fork() usize {
+    return arch.syscall0(arch.SYS_fork);
 }
 
-pub fn getcwd(buf: &u8, size: usize) -> usize {
-    arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size)
+pub fn getcwd(buf: [*]u8, size: usize) usize {
+    return arch.syscall2(arch.SYS___getcwd, @ptrToInt(buf), size);
 }
 
-pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize {
-    arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count)
+pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
+    return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count);
 }
 
-pub fn isatty(fd: i32) -> bool {
+pub fn isatty(fd: i32) bool {
     var wsz: winsize = undefined;
-    return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
+    return arch.syscall3(arch.SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
 }
 
-pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize {
-    arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len)
+pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
+    return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
 }
 
-pub fn mkdir(path: &const u8, mode: u32) -> usize {
-    arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode)
+pub fn mkdir(path: [*]const u8, mode: u32) usize {
+    return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode);
 }
 
-pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize)
-    -> usize
-{
-    arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
-        @bitCast(usize, offset))
+pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {
+    return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset));
 }
 
-pub fn munmap(address: &u8, length: usize) -> usize {
-    arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length)
+pub fn munmap(address: usize, length: usize) usize {
+    return arch.syscall2(arch.SYS_munmap, address, length);
 }
 
-pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
-    arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count)
+pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
+    return arch.syscall3(arch.SYS_read, @intCast(usize, fd), @ptrToInt(buf), count);
 }
 
-pub fn rmdir(path: &const u8) -> usize {
-    arch.syscall1(arch.SYS_rmdir, @ptrToInt(path))
+pub fn rmdir(path: [*]const u8) usize {
+    return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path));
 }
 
-pub fn symlink(existing: &const u8, new: &const u8) -> usize {
-    arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new))
+pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
+    return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
 }
 
-pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize {
-    arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset)
+pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
+    return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
 }
 
-pub fn pipe(fd: &[2]i32) -> usize {
-    pipe2(fd, 0)
+pub fn pipe(fd: *[2]i32) usize {
+    return pipe2(fd, 0);
 }
 
-pub fn pipe2(fd: &[2]i32, flags: usize) -> usize {
-    arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags)
+pub fn pipe2(fd: *[2]i32, flags: usize) usize {
+    return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags);
 }
 
-pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
-    arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count)
+pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
+    return arch.syscall3(arch.SYS_write, @intCast(usize, fd), @ptrToInt(buf), count);
 }
 
-pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize {
-    arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset)
+pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
+    return arch.syscall4(arch.SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset);
 }
 
-pub fn rename(old: &const u8, new: &const u8) -> usize {
-    arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new))
+pub fn rename(old: [*]const u8, new: [*]const u8) usize {
+    return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new));
 }
 
-pub fn open(path: &const u8, flags: u32, perm: usize) -> usize {
-    arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm)
+pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
+    return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm);
 }
 
-pub fn create(path: &const u8, perm: usize) -> usize {
-    arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm)
+pub fn create(path: [*]const u8, perm: usize) usize {
+    return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm);
 }
 
-pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize {
-    arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode)
+pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {
+    return arch.syscall4(arch.SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode);
 }
 
-pub fn close(fd: i32) -> usize {
-    arch.syscall1(arch.SYS_close, usize(fd))
+pub fn close(fd: i32) usize {
+    return arch.syscall1(arch.SYS_close, @intCast(usize, fd));
 }
 
-pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize {
-    arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos)
+pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {
+    return arch.syscall3(arch.SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos);
 }
 
-pub fn exit(status: i32) -> noreturn {
+pub fn exit(status: i32) noreturn {
     _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));
-    unreachable
+    unreachable;
 }
 
-pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
-    arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags))
+pub fn getrandom(buf: &u8, count: usize, flags: u32) usize {
+    return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, @bitCast(usize, flags));
 }
 
-pub fn kill(pid: i32, sig: i32) -> usize {
-    arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig))
+pub fn kill(pid: i32, sig: i32) usize {
+    return arch.syscall2(arch.SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig));
 }
 
-pub fn unlink(path: &const u8) -> usize {
-    arch.syscall1(arch.SYS_unlink, @ptrToInt(path))
+pub fn unlink(path: [*]const u8) usize {
+    return arch.syscall1(arch.SYS_unlink, @ptrToInt(path));
 }
 
-pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize {
-    arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0)
+pub fn waitpid(pid: i32, status: *i32, options: i32) usize {
+    return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
 }
 
-pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {
-    arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem))
+pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
+    return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
 }
 
-pub fn setuid(uid: u32) -> usize {
-    arch.syscall1(arch.SYS_setuid, uid)
+pub fn setuid(uid: u32) usize {
+    return arch.syscall1(arch.SYS_setuid, uid);
 }
 
-pub fn setgid(gid: u32) -> usize {
-    arch.syscall1(arch.SYS_setgid, gid)
+pub fn setgid(gid: u32) usize {
+    return arch.syscall1(arch.SYS_setgid, gid);
 }
 
-pub fn setreuid(ruid: u32, euid: u32) -> usize {
-    arch.syscall2(arch.SYS_setreuid, ruid, euid)
+pub fn setreuid(ruid: u32, euid: u32) usize {
+    return arch.syscall2(arch.SYS_setreuid, ruid, euid);
 }
 
-pub fn setregid(rgid: u32, egid: u32) -> usize {
-    arch.syscall2(arch.SYS_setregid, rgid, egid)
+pub fn setregid(rgid: u32, egid: u32) usize {
+    return arch.syscall2(arch.SYS_setregid, rgid, egid);
 }
 
-pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {
-    arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8)
+pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize {
+    // TODO: Implement
+    return 0;
 }
 
-pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {
-    assert(sig >= 1);
-    assert(sig != SIGKILL);
-    assert(sig != SIGSTOP);
-    var ksa = k_sigaction {
-        .handler = act.handler,
-        .flags = act.flags | SA_RESTORER,
-        .mask = undefined,
-        .restorer = @ptrCast(extern fn(), arch.restore_rt),
-    };
-    var ksa_old: k_sigaction = undefined;
-    @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
-    const result = arch.syscall4(arch.SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask)));
-    const err = getErrno(result);
-    if (err != 0) {
-        return result;
-    }
-    if (oact) |old| {
-        old.handler = ksa_old.handler;
-        old.flags = @truncate(u32, ksa_old.flags);
-        @memcpy(@ptrCast(&u8, &old.mask), @ptrCast(&const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask)));
-    }
+pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
+    // TODO: Implement
     return 0;
 }
 
@@ -531,203 +524,49 @@ const sigset_t = [128 / @sizeOf(usize)]usize;
 const all_mask = []usize{@maxValue(usize)};
 const app_mask = []usize{0xfffffffc7fffffff};
 
-const k_sigaction = extern struct {
-    handler: extern fn(i32),
-    flags: usize,
-    restorer: extern fn(),
-    mask: [2]u32,
-};
-
 /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
 pub const Sigaction = struct {
-    handler: extern fn(i32),
+    // TODO: Adjust to use freebsd struct layout
+    handler: extern fn (i32) void,
     mask: sigset_t,
     flags: u32,
 };
 
-pub const SIG_ERR = @intToPtr(extern fn(i32), @maxValue(usize));
-pub const SIG_DFL = @intToPtr(extern fn(i32), 0);
-pub const SIG_IGN = @intToPtr(extern fn(i32), 1);
+pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(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 fn raise(sig: i32) -> usize {
+pub fn raise(sig: i32) usize {
     // TODO implement, see linux equivalent for what we want to try and do
     return 0;
 }
 
-fn blockAllSignals(set: &sigset_t) {
+fn blockAllSignals(set: *sigset_t) void {
     // TODO implement
 }
 
-fn blockAppSignals(set: &sigset_t) {
+fn blockAppSignals(set: *sigset_t) void {
     // TODO implement
 }
 
-fn restoreSignals(set: &sigset_t) {
+fn restoreSignals(set: *sigset_t) void {
     // TODO implement
 }
 
-pub fn sigaddset(set: &sigset_t, sig: u6) {
+pub fn sigaddset(set: *sigset_t, sig: u6) void {
     const s = sig - 1;
     (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
 }
 
-pub fn sigismember(set: &const sigset_t, sig: u6) -> bool {
+pub fn sigismember(set: *const sigset_t, sig: u6) bool {
     const s = sig - 1;
     return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
 }
 
-
-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), @ptrToInt(addr), @ptrToInt(len))
-}
-
-pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
-    arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(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), @ptrToInt(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), @ptrToInt(optval), @ptrToInt(optlen))
-}
-
-pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize {
-    arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags)
-}
-
-pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
-    arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len))
-}
-
-pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize {
-    arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(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), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(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), @ptrToInt(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), @ptrToInt(buf), len, flags, @ptrToInt(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), @ptrToInt(&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), @ptrToInt(addr), @ptrToInt(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), @ptrToInt(stat_buf))
+pub fn fstat(fd: i32, stat_buf: *Stat) usize {
+    return arch.syscall2(arch.SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf));
 }
std/os/freebsd_errno.zig
@@ -1,121 +1,121 @@
-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
+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
+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
+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
+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 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
+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
+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
+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 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 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 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 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 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 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
+pub const ELAST = 96; // Must be equal largest errno
std/os/freebsd_x86_64.zig
@@ -1,4 +1,4 @@
-const freebsd = @import("freebsd.zig");
+const freebsd = @import("index.zig");
 const socklen_t = freebsd.socklen_t;
 const iovec = freebsd.iovec;
 
@@ -477,26 +477,26 @@ pub const SYS_mknodat = 559;
 pub const SYS_kevent = 560;
 pub const SYS_MAXSYSCALL = 561;
 
-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_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_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_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 O_NDELAY = O_NONBLOCK;
 
 pub const F_DUPFD = 0;
 pub const F_GETFD = 1;
@@ -518,86 +518,99 @@ pub const F_GETOWN_EX = 16;
 
 pub const F_GETOWNER_UIDS = 17;
 
-pub fn syscall0(number: usize) -> usize {
-    asm volatile ("syscall"
+pub fn syscall0(number: usize) usize {
+    return asm volatile ("syscall"
         : [ret] "={rax}" (-> usize)
         : [number] "{rax}" (number)
-        : "rcx", "r11")
+        : "rcx", "r11"
+    );
 }
 
-pub fn syscall1(number: usize, arg1: usize) -> usize {
-    asm volatile ("syscall"
+pub fn syscall1(number: usize, arg1: usize) usize {
+    return asm volatile ("syscall"
         : [ret] "={rax}" (-> usize)
         : [number] "{rax}" (number),
-            [arg1] "{rdi}" (arg1)
-        : "rcx", "r11")
+          [arg1] "{rdi}" (arg1)
+        : "rcx", "r11"
+    );
 }
 
-pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
-    asm volatile ("syscall"
+pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
+    return asm volatile ("syscall"
         : [ret] "={rax}" (-> usize)
         : [number] "{rax}" (number),
-            [arg1] "{rdi}" (arg1),
-            [arg2] "{rsi}" (arg2)
-        : "rcx", "r11")
+          [arg1] "{rdi}" (arg1),
+          [arg2] "{rsi}" (arg2)
+        : "rcx", "r11"
+    );
 }
 
-pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
-    asm volatile ("syscall"
+pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
+    return asm volatile ("syscall"
         : [ret] "={rax}" (-> usize)
         : [number] "{rax}" (number),
-            [arg1] "{rdi}" (arg1),
-            [arg2] "{rsi}" (arg2),
-            [arg3] "{rdx}" (arg3)
-        : "rcx", "r11")
+          [arg1] "{rdi}" (arg1),
+          [arg2] "{rsi}" (arg2),
+          [arg3] "{rdx}" (arg3)
+        : "rcx", "r11"
+    );
 }
 
-pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
-    asm volatile ("syscall"
+pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
+    return asm volatile ("syscall"
         : [ret] "={rax}" (-> usize)
         : [number] "{rax}" (number),
-            [arg1] "{rdi}" (arg1),
-            [arg2] "{rsi}" (arg2),
-            [arg3] "{rdx}" (arg3),
-            [arg4] "{r10}" (arg4)
-        : "rcx", "r11")
+          [arg1] "{rdi}" (arg1),
+          [arg2] "{rsi}" (arg2),
+          [arg3] "{rdx}" (arg3),
+          [arg4] "{r10}" (arg4)
+        : "rcx", "r11"
+    );
 }
 
-pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
-    asm volatile ("syscall"
+pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
+    return 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")
+          [arg1] "{rdi}" (arg1),
+          [arg2] "{rsi}" (arg2),
+          [arg3] "{rdx}" (arg3),
+          [arg4] "{r10}" (arg4),
+          [arg5] "{r8}" (arg5)
+        : "rcx", "r11"
+    );
 }
 
-pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
-    arg5: usize, arg6: usize) -> usize
-{
-    asm volatile ("syscall"
+pub fn syscall6(
+    number: usize,
+    arg1: usize,
+    arg2: usize,
+    arg3: usize,
+    arg4: usize,
+    arg5: usize,
+    arg6: usize,
+) usize {
+    return 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")
+          [arg1] "{rdi}" (arg1),
+          [arg2] "{rsi}" (arg2),
+          [arg3] "{rdx}" (arg3),
+          [arg4] "{r10}" (arg4),
+          [arg5] "{r8}" (arg5),
+          [arg6] "{r9}" (arg6)
+        : "rcx", "r11"
+    );
 }
 
-pub nakedcc fn restore_rt() {
+pub nakedcc fn restore_rt() void {
     asm volatile ("syscall"
         :
         : [number] "{rax}" (usize(SYS_rt_sigreturn))
-        : "rcx", "r11")
+        : "rcx", "r11"
+    );
 }
 
-
 pub const msghdr = extern struct {
     msg_name: &u8,
     msg_namelen: socklen_t,
std/os/index.zig
@@ -24,7 +24,7 @@ test "std.os" {
 pub const windows = @import("windows/index.zig");
 pub const darwin = @import("darwin.zig");
 pub const linux = @import("linux/index.zig");
-pub const freebsd = @import("freebsd.zig");
+pub const freebsd = @import("freebsd/index.zig");
 pub const zen = @import("zen.zig");
 pub const posix = switch (builtin.os) {
     Os.linux => linux,