authorgravatar for maya@NetBSD.orgMaya Rashish <maya@NetBSD.org> 2019-02-16 12:29:12+02:00
committergravatar for maya@NetBSD.orgMaya Rashish <maya@NetBSD.org> 2019-02-17 09:17:34+02:00
logbc10382ec1b87da16943907ba2d0fbd267af07f0
tree1bc117549f49266c2d1244d0f1cc7220e201b86b
parentba56f365c813440b79c1710c6a8b0fd591883e13

Add NetBSD support

Mostly picking the same paths as FreeBSD. We need a little special handling for crt files, as netbsd uses its own (and not GCC's) for those, with slightly different names.

23 files changed, 1101 insertions(+), 67 deletions(-)

CMakeLists.txt+3
...@@ -447,6 +447,7 @@ set(ZIG_STD_FILES...@@ -447,6 +447,7 @@ set(ZIG_STD_FILES
447 "c/freebsd.zig"447 "c/freebsd.zig"
448 "c/index.zig"448 "c/index.zig"
449 "c/linux.zig"449 "c/linux.zig"
450 "c/netbsd.zig"
450 "c/windows.zig"451 "c/windows.zig"
451 "coff.zig"452 "coff.zig"
452 "crypto/blake2.zig"453 "crypto/blake2.zig"
...@@ -587,6 +588,8 @@ set(ZIG_STD_FILES...@@ -587,6 +588,8 @@ set(ZIG_STD_FILES
587 "os/linux/index.zig"588 "os/linux/index.zig"
588 "os/linux/vdso.zig"589 "os/linux/vdso.zig"
589 "os/linux/x86_64.zig"590 "os/linux/x86_64.zig"
591 "os/netbsd/errno.zig"
592 "os/netbsd/index.zig"
590 "os/path.zig"593 "os/path.zig"
591 "os/time.zig"594 "os/time.zig"
592 "os/uefi.zig"595 "os/uefi.zig"
cmake/Findllvm.cmake-1
...@@ -50,7 +50,6 @@ NEED_TARGET("AMDGPU")...@@ -50,7 +50,6 @@ NEED_TARGET("AMDGPU")
50NEED_TARGET("ARM")50NEED_TARGET("ARM")
51NEED_TARGET("BPF")51NEED_TARGET("BPF")
52NEED_TARGET("Hexagon")52NEED_TARGET("Hexagon")
53NEED_TARGET("Lanai")
54NEED_TARGET("Mips")53NEED_TARGET("Mips")
55NEED_TARGET("MSP430")54NEED_TARGET("MSP430")
56NEED_TARGET("NVPTX")55NEED_TARGET("NVPTX")
src-self-hosted/libc_installation.zig+1-1
...@@ -172,7 +172,7 @@ pub const LibCInstallation = struct {...@@ -172,7 +172,7 @@ pub const LibCInstallation = struct {
172 try group.call(findNativeStaticLibDir, self, loop);172 try group.call(findNativeStaticLibDir, self, loop);
173 try group.call(findNativeDynamicLinker, self, loop);173 try group.call(findNativeDynamicLinker, self, loop);
174 },174 },
175 builtin.Os.macosx, builtin.Os.freebsd => {175 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
176 self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include");176 self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include");
177 },177 },
178 else => @compileError("unimplemented: find libc for this OS"),178 else => @compileError("unimplemented: find libc for this OS"),
src/analyze.cpp+7-4
...@@ -4732,7 +4732,8 @@ void find_libc_include_path(CodeGen *g) {...@@ -4732,7 +4732,8 @@ void find_libc_include_path(CodeGen *g) {
4732 }4732 }
4733 } else if (g->zig_target.os == OsLinux ||4733 } else if (g->zig_target.os == OsLinux ||
4734 g->zig_target.os == OsMacOSX ||4734 g->zig_target.os == OsMacOSX ||
4735 g->zig_target.os == OsFreeBSD)4735 g->zig_target.os == OsFreeBSD ||
4736 g->zig_target.os == OsNetBSD)
4736 {4737 {
4737 g->libc_include_dir = get_posix_libc_include_path();4738 g->libc_include_dir = get_posix_libc_include_path();
4738 } else {4739 } else {
...@@ -4781,7 +4782,7 @@ void find_libc_lib_path(CodeGen *g) {...@@ -4781,7 +4782,7 @@ void find_libc_lib_path(CodeGen *g) {
47814782
4782 } else if (g->zig_target.os == OsLinux) {4783 } else if (g->zig_target.os == OsLinux) {
4783 g->libc_lib_dir = get_linux_libc_lib_path("crt1.o");4784 g->libc_lib_dir = get_linux_libc_lib_path("crt1.o");
4784 } else if (g->zig_target.os == OsFreeBSD) {4785 } else if ((g->zig_target.os == OsFreeBSD) || (g->zig_target.os == OsNetBSD)) {
4785 g->libc_lib_dir = buf_create_from_str("/usr/lib");4786 g->libc_lib_dir = buf_create_from_str("/usr/lib");
4786 } else {4787 } else {
4787 zig_panic("Unable to determine libc lib path.");4788 zig_panic("Unable to determine libc lib path.");
...@@ -4795,7 +4796,7 @@ void find_libc_lib_path(CodeGen *g) {...@@ -4795,7 +4796,7 @@ void find_libc_lib_path(CodeGen *g) {
4795 return;4796 return;
4796 } else if (g->zig_target.os == OsLinux) {4797 } else if (g->zig_target.os == OsLinux) {
4797 g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o");4798 g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o");
4798 } else if (g->zig_target.os == OsFreeBSD) {4799 } else if ((g->zig_target.os == OsFreeBSD) || (g->zig_target.os == OsNetBSD)) {
4799 g->libc_static_lib_dir = buf_create_from_str("/usr/lib");4800 g->libc_static_lib_dir = buf_create_from_str("/usr/lib");
4800 } else {4801 } else {
4801 zig_panic("Unable to determine libc static lib path.");4802 zig_panic("Unable to determine libc static lib path.");
...@@ -6710,7 +6711,9 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) {...@@ -6710,7 +6711,9 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) {
6710 if (is_libc && g->libc_link_lib != nullptr)6711 if (is_libc && g->libc_link_lib != nullptr)
6711 return g->libc_link_lib;6712 return g->libc_link_lib;
67126713
6713 if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && g->zig_target.os != OsIOS && g->zig_target.os != OsFreeBSD) {6714 if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX &&
6715 g->zig_target.os != OsIOS && g->zig_target.os != OsFreeBSD &&
6716 g->zig_target.os != OsNetBSD) {
6714 fprintf(stderr, "TODO linking against libc is currently incompatible with `--cache on`.\n"6717 fprintf(stderr, "TODO linking against libc is currently incompatible with `--cache on`.\n"
6715 "Zig is not yet capable of determining whether the libc installation has changed on subsequent builds.\n");6718 "Zig is not yet capable of determining whether the libc installation has changed on subsequent builds.\n");
6716 exit(1);6719 exit(1);
src/codegen.cpp+2-1
...@@ -184,7 +184,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out...@@ -184,7 +184,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
184 // On Darwin/MacOS/iOS, we always link libSystem which contains libc.184 // On Darwin/MacOS/iOS, we always link libSystem which contains libc.
185 if (g->zig_target.os == OsMacOSX ||185 if (g->zig_target.os == OsMacOSX ||
186 g->zig_target.os == OsIOS ||186 g->zig_target.os == OsIOS ||
187 g->zig_target.os == OsFreeBSD)187 g->zig_target.os == OsFreeBSD ||
188 g->zig_target.os == OsNetBSD)
188 {189 {
189 g->libc_link_lib = create_link_lib(buf_create_from_str("c"));190 g->libc_link_lib = create_link_lib(buf_create_from_str("c"));
190 g->link_libs_list.append(g->libc_link_lib);191 g->link_libs_list.append(g->libc_link_lib);
src/link.cpp+8-2
...@@ -198,6 +198,9 @@ static Buf *get_dynamic_linker_path(CodeGen *g) {...@@ -198,6 +198,9 @@ static Buf *get_dynamic_linker_path(CodeGen *g) {
198 if (g->zig_target.os == OsFreeBSD) {198 if (g->zig_target.os == OsFreeBSD) {
199 return buf_create_from_str("/libexec/ld-elf.so.1");199 return buf_create_from_str("/libexec/ld-elf.so.1");
200 }200 }
201 if (g->zig_target.os == OsNetBSD) {
202 return buf_create_from_str("/libexec/ld.elf_so");
203 }
201 if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) {204 if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) {
202 static const char *ld_names[] = {205 static const char *ld_names[] = {
203 "ld-linux-x86-64.so.2",206 "ld-linux-x86-64.so.2",
...@@ -263,10 +266,13 @@ static void construct_linker_job_elf(LinkJob *lj) {...@@ -263,10 +266,13 @@ static void construct_linker_job_elf(LinkJob *lj) {
263 if (lj->link_in_crt) {266 if (lj->link_in_crt) {
264 const char *crt1o;267 const char *crt1o;
265 const char *crtbegino;268 const char *crtbegino;
266 if (g->is_static) {269 if (g->zig_target.os == OsNetBSD) {
270 crt1o = "crt0.o";
271 crtbegino = "crtbegin.o";
272 } else if (g->is_static) {
267 crt1o = "crt1.o";273 crt1o = "crt1.o";
268 crtbegino = "crtbeginT.o";274 crtbegino = "crtbeginT.o";
269 } else {275 } else {
270 crt1o = "Scrt1.o";276 crt1o = "Scrt1.o";
271 crtbegino = "crtbegin.o";277 crtbegino = "crtbegin.o";
272 }278 }
src/os.cpp+14-5
...@@ -50,11 +50,11 @@ typedef SSIZE_T ssize_t;...@@ -50,11 +50,11 @@ typedef SSIZE_T ssize_t;
5050
51#endif51#endif
5252
53#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)53#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
54#include <link.h>54#include <link.h>
55#endif55#endif
5656
57#if defined(ZIG_OS_FREEBSD)57#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
58#include <sys/sysctl.h>58#include <sys/sysctl.h>
59#endif59#endif
6060
...@@ -78,7 +78,7 @@ static clock_serv_t cclock;...@@ -78,7 +78,7 @@ static clock_serv_t cclock;
78#if defined(__APPLE__) && !defined(environ)78#if defined(__APPLE__) && !defined(environ)
79#include <crt_externs.h>79#include <crt_externs.h>
80#define environ (*_NSGetEnviron())80#define environ (*_NSGetEnviron())
81#elif defined(ZIG_OS_FREEBSD)81#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
82extern char **environ;82extern char **environ;
83#endif83#endif
8484
...@@ -1458,6 +1458,15 @@ Error os_self_exe_path(Buf *out_path) {...@@ -1458,6 +1458,15 @@ Error os_self_exe_path(Buf *out_path) {
1458 }1458 }
1459 buf_resize(out_path, cb - 1);1459 buf_resize(out_path, cb - 1);
1460 return ErrorNone;1460 return ErrorNone;
1461#elif defined(ZIG_OS_NETBSD)
1462 buf_resize(out_path, PATH_MAX);
1463 int mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME };
1464 size_t cb = PATH_MAX;
1465 if (sysctl(mib, 4, buf_ptr(out_path), &cb, nullptr, 0) != 0) {
1466 return ErrorUnexpected;
1467 }
1468 buf_resize(out_path, cb - 1);
1469 return ErrorNone;
1461#endif1470#endif
1462 return ErrorFileNotFound;1471 return ErrorFileNotFound;
1463}1472}
...@@ -1776,7 +1785,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {...@@ -1776,7 +1785,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {
1776}1785}
17771786
17781787
1779#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)1788#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
1780static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) {1789static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) {
1781 ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data);1790 ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data);
1782 if (info->dlpi_name[0] == '/') {1791 if (info->dlpi_name[0] == '/') {
...@@ -1787,7 +1796,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size,...@@ -1787,7 +1796,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size,
1787#endif1796#endif
17881797
1789Error os_self_exe_shared_libs(ZigList<Buf *> &paths) {1798Error os_self_exe_shared_libs(ZigList<Buf *> &paths) {
1790#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)1799#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
1791 paths.resize(0);1800 paths.resize(0);
1792 dl_iterate_phdr(self_exe_shared_libs_callback, &paths);1801 dl_iterate_phdr(self_exe_shared_libs_callback, &paths);
1793 return ErrorNone;1802 return ErrorNone;
src/os.hpp+2
...@@ -25,6 +25,8 @@...@@ -25,6 +25,8 @@
25#define ZIG_OS_LINUX25#define ZIG_OS_LINUX
26#elif defined(__FreeBSD__)26#elif defined(__FreeBSD__)
27#define ZIG_OS_FREEBSD27#define ZIG_OS_FREEBSD
28#elif defined(__NetBSD__)
29#define ZIG_OS_NETBSD
28#else30#else
29#define ZIG_OS_UNKNOWN31#define ZIG_OS_UNKNOWN
30#endif32#endif
src/target.cpp+1-1
...@@ -743,6 +743,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -743,6 +743,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
743 case OsMacOSX:743 case OsMacOSX:
744 case OsZen:744 case OsZen:
745 case OsFreeBSD:745 case OsFreeBSD:
746 case OsNetBSD:
746 case OsOpenBSD:747 case OsOpenBSD:
747 switch (id) {748 switch (id) {
748 case CIntTypeShort:749 case CIntTypeShort:
...@@ -783,7 +784,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -783,7 +784,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
783 case OsIOS:784 case OsIOS:
784 case OsKFreeBSD:785 case OsKFreeBSD:
785 case OsLv2:786 case OsLv2:
786 case OsNetBSD:
787 case OsSolaris:787 case OsSolaris:
788 case OsHaiku:788 case OsHaiku:
789 case OsMinix:789 case OsMinix:
std/c/index.zig+1
...@@ -6,6 +6,7 @@ pub use switch (builtin.os) {...@@ -6,6 +6,7 @@ pub use switch (builtin.os) {
6 Os.windows => @import("windows.zig"),6 Os.windows => @import("windows.zig"),
7 Os.macosx, Os.ios => @import("darwin.zig"),7 Os.macosx, Os.ios => @import("darwin.zig"),
8 Os.freebsd => @import("freebsd.zig"),8 Os.freebsd => @import("freebsd.zig"),
9 Os.netbsd => @import("netbsd.zig"),
9 else => empty_import,10 else => empty_import,
10};11};
11const empty_import = @import("../empty.zig");12const empty_import = @import("../empty.zig");
std/c/netbsd.zig created+116
...@@ -0,0 +1,116 @@
1extern "c" fn __errno() *c_int;
2pub const _errno = __errno;
3
4pub extern "c" fn kqueue() c_int;
5pub extern "c" fn kevent(
6 kq: c_int,
7 changelist: [*]const Kevent,
8 nchanges: c_int,
9 eventlist: [*]Kevent,
10 nevents: c_int,
11 timeout: ?*const timespec,
12) c_int;
13pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
14pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
15pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
16pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;
17pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
18pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int;
19pub extern "c" fn preadv(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
20pub extern "c" fn pwritev(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
21pub extern "c" fn openat(fd: c_int, path: ?[*]const u8, flags: c_int) c_int;
22pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
23pub extern "c" fn setuid(uid: c_uint) c_int;
24pub extern "c" fn kill(pid: c_int, sig: c_int) c_int;
25pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
26pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
27
28/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
29pub const Kevent = extern struct {
30 ident: usize,
31 filter: i32,
32 flags: u32,
33 fflags: u32,
34 data: i64,
35 udata: usize,
36};
37
38pub const pthread_attr_t = extern struct {
39 pta_magic: u32,
40 pta_flags: c_int,
41 pta_private: *c_void,
42};
43
44pub const msghdr = extern struct {
45 msg_name: *u8,
46 msg_namelen: socklen_t,
47 msg_iov: *iovec,
48 msg_iovlen: i32,
49 __pad1: i32,
50 msg_control: *u8,
51 msg_controllen: socklen_t,
52 __pad2: socklen_t,
53 msg_flags: i32,
54};
55
56pub const Stat = extern struct {
57 dev: u64,
58 mode: u32,
59 ino: u64,
60 nlink: usize,
61
62 uid: u32,
63 gid: u32,
64 rdev: u64,
65
66 atim: timespec,
67 mtim: timespec,
68 ctim: timespec,
69 birthtim: timespec,
70
71 size: i64,
72 blocks: i64,
73 blksize: isize,
74 flags: u32,
75 gen: u32,
76 __spare: [2]u32,
77};
78
79pub const timespec = extern struct {
80 tv_sec: i64,
81 tv_nsec: isize,
82};
83
84pub const dirent = extern struct {
85 d_fileno: u64,
86 d_reclen: u16,
87 d_namlen: u16,
88 d_type: u8,
89 d_off: i64,
90 d_name: [512]u8,
91};
92
93pub const in_port_t = u16;
94pub const sa_family_t = u8;
95
96pub const sockaddr = extern union {
97 in: sockaddr_in,
98 in6: sockaddr_in6,
99};
100
101pub const sockaddr_in = extern struct {
102 len: u8,
103 family: sa_family_t,
104 port: in_port_t,
105 addr: u32,
106 zero: [8]u8,
107};
108
109pub const sockaddr_in6 = extern struct {
110 len: u8,
111 family: sa_family_t,
112 port: in_port_t,
113 flowinfo: u32,
114 addr: [16]u8,
115 scope_id: u32,
116};
std/debug/index.zig+3-3
...@@ -240,7 +240,7 @@ pub fn writeCurrentStackTraceWindows(...@@ -240,7 +240,7 @@ pub fn writeCurrentStackTraceWindows(
240pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {240pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
241 switch (builtin.os) {241 switch (builtin.os) {
242 builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color),242 builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color),
243 builtin.Os.linux, builtin.Os.freebsd => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color),243 builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color),
244 builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color),244 builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color),
245 else => return error.UnsupportedOperatingSystem,245 else => return error.UnsupportedOperatingSystem,
246 }246 }
...@@ -717,7 +717,7 @@ pub const OpenSelfDebugInfoError = error{...@@ -717,7 +717,7 @@ pub const OpenSelfDebugInfoError = error{
717717
718pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {718pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
719 switch (builtin.os) {719 switch (builtin.os) {
720 builtin.Os.linux, builtin.Os.freebsd => return openSelfDebugInfoLinux(allocator),720 builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => return openSelfDebugInfoLinux(allocator),
721 builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator),721 builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator),
722 builtin.Os.windows => return openSelfDebugInfoWindows(allocator),722 builtin.Os.windows => return openSelfDebugInfoWindows(allocator),
723 else => return error.UnsupportedOperatingSystem,723 else => return error.UnsupportedOperatingSystem,
...@@ -1141,7 +1141,7 @@ pub const DebugInfo = switch (builtin.os) {...@@ -1141,7 +1141,7 @@ pub const DebugInfo = switch (builtin.os) {
1141 sect_contribs: []pdb.SectionContribEntry,1141 sect_contribs: []pdb.SectionContribEntry,
1142 modules: []Module,1142 modules: []Module,
1143 },1143 },
1144 builtin.Os.linux, builtin.Os.freebsd => DwarfInfo,1144 builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => DwarfInfo,
1145 else => @compileError("Unsupported OS"),1145 else => @compileError("Unsupported OS"),
1146};1146};
11471147
std/event/fs.zig+23-8
...@@ -85,6 +85,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o...@@ -85,6 +85,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o
85 builtin.Os.macosx,85 builtin.Os.macosx,
86 builtin.Os.linux,86 builtin.Os.linux,
87 builtin.Os.freebsd,87 builtin.Os.freebsd,
88 builtin.Os.netbsd,
88 => {89 => {
89 const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len);90 const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len);
90 defer loop.allocator.free(iovecs);91 defer loop.allocator.free(iovecs);
...@@ -222,6 +223,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset:...@@ -222,6 +223,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset:
222 builtin.Os.macosx,223 builtin.Os.macosx,
223 builtin.Os.linux,224 builtin.Os.linux,
224 builtin.Os.freebsd,225 builtin.Os.freebsd,
226 builtin.Os.netbsd,
225 => {227 => {
226 const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len);228 const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len);
227 defer loop.allocator.free(iovecs);229 defer loop.allocator.free(iovecs);
...@@ -402,7 +404,11 @@ pub async fn openPosix(...@@ -402,7 +404,11 @@ pub async fn openPosix(
402404
403pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle {405pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle {
404 switch (builtin.os) {406 switch (builtin.os) {
405 builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => {407 builtin.Os.macosx,
408 builtin.Os.linux,
409 builtin.Os.freebsd,
410 builtin.Os.netbsd
411 => {
406 const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC;412 const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC;
407 return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);413 return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);
408 },414 },
...@@ -431,6 +437,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os...@@ -431,6 +437,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os
431 builtin.Os.macosx,437 builtin.Os.macosx,
432 builtin.Os.linux,438 builtin.Os.linux,
433 builtin.Os.freebsd,439 builtin.Os.freebsd,
440 builtin.Os.netbsd,
434 => {441 => {
435 const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC;442 const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC;
436 return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);443 return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);
...@@ -453,7 +460,7 @@ pub async fn openReadWrite(...@@ -453,7 +460,7 @@ pub async fn openReadWrite(
453 mode: os.File.Mode,460 mode: os.File.Mode,
454) os.File.OpenError!os.FileHandle {461) os.File.OpenError!os.FileHandle {
455 switch (builtin.os) {462 switch (builtin.os) {
456 builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => {463 builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => {
457 const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC;464 const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC;
458 return await (async openPosix(loop, path, flags, mode) catch unreachable);465 return await (async openPosix(loop, path, flags, mode) catch unreachable);
459 },466 },
...@@ -481,7 +488,7 @@ pub const CloseOperation = struct {...@@ -481,7 +488,7 @@ pub const CloseOperation = struct {
481 os_data: OsData,488 os_data: OsData,
482489
483 const OsData = switch (builtin.os) {490 const OsData = switch (builtin.os) {
484 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => OsDataPosix,491 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => OsDataPosix,
485492
486 builtin.Os.windows => struct {493 builtin.Os.windows => struct {
487 handle: ?os.FileHandle,494 handle: ?os.FileHandle,
...@@ -500,7 +507,7 @@ pub const CloseOperation = struct {...@@ -500,7 +507,7 @@ pub const CloseOperation = struct {
500 self.* = CloseOperation{507 self.* = CloseOperation{
501 .loop = loop,508 .loop = loop,
502 .os_data = switch (builtin.os) {509 .os_data = switch (builtin.os) {
503 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => initOsDataPosix(self),510 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => initOsDataPosix(self),
504 builtin.Os.windows => OsData{ .handle = null },511 builtin.Os.windows => OsData{ .handle = null },
505 else => @compileError("Unsupported OS"),512 else => @compileError("Unsupported OS"),
506 },513 },
...@@ -530,6 +537,7 @@ pub const CloseOperation = struct {...@@ -530,6 +537,7 @@ pub const CloseOperation = struct {
530 builtin.Os.linux,537 builtin.Os.linux,
531 builtin.Os.macosx,538 builtin.Os.macosx,
532 builtin.Os.freebsd,539 builtin.Os.freebsd,
540 builtin.Os.netbsd,
533 => {541 => {
534 if (self.os_data.have_fd) {542 if (self.os_data.have_fd) {
535 self.loop.posixFsRequest(&self.os_data.close_req_node);543 self.loop.posixFsRequest(&self.os_data.close_req_node);
...@@ -552,6 +560,7 @@ pub const CloseOperation = struct {...@@ -552,6 +560,7 @@ pub const CloseOperation = struct {
552 builtin.Os.linux,560 builtin.Os.linux,
553 builtin.Os.macosx,561 builtin.Os.macosx,
554 builtin.Os.freebsd,562 builtin.Os.freebsd,
563 builtin.Os.netbsd,
555 => {564 => {
556 self.os_data.close_req_node.data.msg.Close.fd = handle;565 self.os_data.close_req_node.data.msg.Close.fd = handle;
557 self.os_data.have_fd = true;566 self.os_data.have_fd = true;
...@@ -569,6 +578,7 @@ pub const CloseOperation = struct {...@@ -569,6 +578,7 @@ pub const CloseOperation = struct {
569 builtin.Os.linux,578 builtin.Os.linux,
570 builtin.Os.macosx,579 builtin.Os.macosx,
571 builtin.Os.freebsd,580 builtin.Os.freebsd,
581 builtin.Os.netbsd,
572 => {582 => {
573 self.os_data.have_fd = false;583 self.os_data.have_fd = false;
574 },584 },
...@@ -584,6 +594,7 @@ pub const CloseOperation = struct {...@@ -584,6 +594,7 @@ pub const CloseOperation = struct {
584 builtin.Os.linux,594 builtin.Os.linux,
585 builtin.Os.macosx,595 builtin.Os.macosx,
586 builtin.Os.freebsd,596 builtin.Os.freebsd,
597 builtin.Os.netbsd,
587 => {598 => {
588 assert(self.os_data.have_fd);599 assert(self.os_data.have_fd);
589 return self.os_data.close_req_node.data.msg.Close.fd;600 return self.os_data.close_req_node.data.msg.Close.fd;
...@@ -608,6 +619,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8,...@@ -608,6 +619,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8,
608 builtin.Os.linux,619 builtin.Os.linux,
609 builtin.Os.macosx,620 builtin.Os.macosx,
610 builtin.Os.freebsd,621 builtin.Os.freebsd,
622 builtin.Os.netbsd,
611 => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable),623 => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable),
612 builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable),624 builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable),
613 else => @compileError("Unsupported OS"),625 else => @compileError("Unsupported OS"),
...@@ -713,7 +725,7 @@ pub fn Watch(comptime V: type) type {...@@ -713,7 +725,7 @@ pub fn Watch(comptime V: type) type {
713 os_data: OsData,725 os_data: OsData,
714726
715 const OsData = switch (builtin.os) {727 const OsData = switch (builtin.os) {
716 builtin.Os.macosx, builtin.Os.freebsd => struct {728 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => struct {
717 file_table: FileTable,729 file_table: FileTable,
718 table_lock: event.Lock,730 table_lock: event.Lock,
719731
...@@ -802,7 +814,7 @@ pub fn Watch(comptime V: type) type {...@@ -802,7 +814,7 @@ pub fn Watch(comptime V: type) type {
802 return self;814 return self;
803 },815 },
804816
805 builtin.Os.macosx, builtin.Os.freebsd => {817 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
806 const self = try loop.allocator.create(Self);818 const self = try loop.allocator.create(Self);
807 errdefer loop.allocator.destroy(self);819 errdefer loop.allocator.destroy(self);
808820
...@@ -822,7 +834,7 @@ pub fn Watch(comptime V: type) type {...@@ -822,7 +834,7 @@ pub fn Watch(comptime V: type) type {
822 /// All addFile calls and removeFile calls must have completed.834 /// All addFile calls and removeFile calls must have completed.
823 pub fn destroy(self: *Self) void {835 pub fn destroy(self: *Self) void {
824 switch (builtin.os) {836 switch (builtin.os) {
825 builtin.Os.macosx, builtin.Os.freebsd => {837 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
826 // TODO we need to cancel the coroutines before destroying the lock838 // TODO we need to cancel the coroutines before destroying the lock
827 self.os_data.table_lock.deinit();839 self.os_data.table_lock.deinit();
828 var it = self.os_data.file_table.iterator();840 var it = self.os_data.file_table.iterator();
...@@ -864,7 +876,10 @@ pub fn Watch(comptime V: type) type {...@@ -864,7 +876,10 @@ pub fn Watch(comptime V: type) type {
864876
865 pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V {877 pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V {
866 switch (builtin.os) {878 switch (builtin.os) {
867 builtin.Os.macosx, builtin.Os.freebsd => return await (async addFileKEvent(self, file_path, value) catch unreachable),879 builtin.Os.macosx,
880 builtin.Os.freebsd,
881 builtin.Os.netbsd
882 => return await (async addFileKEvent(self, file_path, value) catch unreachable),
868 builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable),883 builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable),
869 builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable),884 builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable),
870 else => @compileError("Unsupported OS"),885 else => @compileError("Unsupported OS"),
std/event/loop.zig+11-10
...@@ -50,7 +50,7 @@ pub const Loop = struct {...@@ -50,7 +50,7 @@ pub const Loop = struct {
50 };50 };
5151
52 pub const EventFd = switch (builtin.os) {52 pub const EventFd = switch (builtin.os) {
53 builtin.Os.macosx, builtin.Os.freebsd => KEventFd,53 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => KEventFd,
54 builtin.Os.linux => struct {54 builtin.Os.linux => struct {
55 base: ResumeNode,55 base: ResumeNode,
56 epoll_op: u32,56 epoll_op: u32,
...@@ -69,7 +69,7 @@ pub const Loop = struct {...@@ -69,7 +69,7 @@ pub const Loop = struct {
69 };69 };
7070
71 pub const Basic = switch (builtin.os) {71 pub const Basic = switch (builtin.os) {
72 builtin.Os.macosx, builtin.Os.freebsd => KEventBasic,72 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => KEventBasic,
73 builtin.Os.linux => struct {73 builtin.Os.linux => struct {
74 base: ResumeNode,74 base: ResumeNode,
75 },75 },
...@@ -221,7 +221,7 @@ pub const Loop = struct {...@@ -221,7 +221,7 @@ pub const Loop = struct {
221 self.extra_threads[extra_thread_index] = try os.spawnThread(self, workerRun);221 self.extra_threads[extra_thread_index] = try os.spawnThread(self, workerRun);
222 }222 }
223 },223 },
224 builtin.Os.macosx, builtin.Os.freebsd => {224 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
225 self.os_data.kqfd = try os.bsdKQueue();225 self.os_data.kqfd = try os.bsdKQueue();
226 errdefer os.close(self.os_data.kqfd);226 errdefer os.close(self.os_data.kqfd);
227227
...@@ -386,7 +386,7 @@ pub const Loop = struct {...@@ -386,7 +386,7 @@ pub const Loop = struct {
386 os.close(self.os_data.epollfd);386 os.close(self.os_data.epollfd);
387 self.allocator.free(self.eventfd_resume_nodes);387 self.allocator.free(self.eventfd_resume_nodes);
388 },388 },
389 builtin.Os.macosx, builtin.Os.freebsd => {389 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
390 os.close(self.os_data.kqfd);390 os.close(self.os_data.kqfd);
391 os.close(self.os_data.fs_kqfd);391 os.close(self.os_data.fs_kqfd);
392 },392 },
...@@ -501,7 +501,7 @@ pub const Loop = struct {...@@ -501,7 +501,7 @@ pub const Loop = struct {
501 const eventfd_node = &resume_stack_node.data;501 const eventfd_node = &resume_stack_node.data;
502 eventfd_node.base.handle = next_tick_node.data;502 eventfd_node.base.handle = next_tick_node.data;
503 switch (builtin.os) {503 switch (builtin.os) {
504 builtin.Os.macosx, builtin.Os.freebsd => {504 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
505 const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent);505 const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent);
506 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];506 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
507 _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {507 _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {
...@@ -564,6 +564,7 @@ pub const Loop = struct {...@@ -564,6 +564,7 @@ pub const Loop = struct {
564 builtin.Os.linux,564 builtin.Os.linux,
565 builtin.Os.macosx,565 builtin.Os.macosx,
566 builtin.Os.freebsd,566 builtin.Os.freebsd,
567 builtin.Os.netbsd,
567 => self.os_data.fs_thread.wait(),568 => self.os_data.fs_thread.wait(),
568 else => {},569 else => {},
569 }570 }
...@@ -628,7 +629,7 @@ pub const Loop = struct {...@@ -628,7 +629,7 @@ pub const Loop = struct {
628 os.posixWrite(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;629 os.posixWrite(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
629 return;630 return;
630 },631 },
631 builtin.Os.macosx, builtin.Os.freebsd => {632 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
632 self.posixFsRequest(&self.os_data.fs_end_request);633 self.posixFsRequest(&self.os_data.fs_end_request);
633 const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent);634 const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent);
634 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];635 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
...@@ -686,7 +687,7 @@ pub const Loop = struct {...@@ -686,7 +687,7 @@ pub const Loop = struct {
686 }687 }
687 }688 }
688 },689 },
689 builtin.Os.macosx, builtin.Os.freebsd => {690 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
690 var eventlist: [1]posix.Kevent = undefined;691 var eventlist: [1]posix.Kevent = undefined;
691 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];692 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
692 const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;693 const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
...@@ -749,7 +750,7 @@ pub const Loop = struct {...@@ -749,7 +750,7 @@ pub const Loop = struct {
749 self.beginOneEvent(); // finished in posixFsRun after processing the msg750 self.beginOneEvent(); // finished in posixFsRun after processing the msg
750 self.os_data.fs_queue.put(request_node);751 self.os_data.fs_queue.put(request_node);
751 switch (builtin.os) {752 switch (builtin.os) {
752 builtin.Os.macosx, builtin.Os.freebsd => {753 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
753 const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake);754 const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake);
754 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];755 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
755 _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;756 _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
...@@ -819,7 +820,7 @@ pub const Loop = struct {...@@ -819,7 +820,7 @@ pub const Loop = struct {
819 else => unreachable,820 else => unreachable,
820 }821 }
821 },822 },
822 builtin.Os.macosx, builtin.Os.freebsd => {823 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
823 const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait);824 const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait);
824 var out_kevs: [1]posix.Kevent = undefined;825 var out_kevs: [1]posix.Kevent = undefined;
825 _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;826 _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;
...@@ -831,7 +832,7 @@ pub const Loop = struct {...@@ -831,7 +832,7 @@ pub const Loop = struct {
831832
832 const OsData = switch (builtin.os) {833 const OsData = switch (builtin.os) {
833 builtin.Os.linux => LinuxOsData,834 builtin.Os.linux => LinuxOsData,
834 builtin.Os.macosx, builtin.Os.freebsd => KEventData,835 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => KEventData,
835 builtin.Os.windows => struct {836 builtin.Os.windows => struct {
836 io_port: windows.HANDLE,837 io_port: windows.HANDLE,
837 extra_thread_count: usize,838 extra_thread_count: usize,
std/heap.zig+3-3
...@@ -71,7 +71,7 @@ pub const DirectAllocator = struct {...@@ -71,7 +71,7 @@ pub const DirectAllocator = struct {
71 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);71 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
7272
73 switch (builtin.os) {73 switch (builtin.os) {
74 Os.linux, Os.macosx, Os.ios, Os.freebsd => {74 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
75 const p = os.posix;75 const p = os.posix;
76 const alloc_size = if (alignment <= os.page_size) n else n + alignment;76 const alloc_size = if (alignment <= os.page_size) n else n + alignment;
77 const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);77 const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);
...@@ -120,7 +120,7 @@ pub const DirectAllocator = struct {...@@ -120,7 +120,7 @@ pub const DirectAllocator = struct {
120 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);120 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
121121
122 switch (builtin.os) {122 switch (builtin.os) {
123 Os.linux, Os.macosx, Os.ios, Os.freebsd => {123 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
124 if (new_size <= old_mem.len) {124 if (new_size <= old_mem.len) {
125 const base_addr = @ptrToInt(old_mem.ptr);125 const base_addr = @ptrToInt(old_mem.ptr);
126 const old_addr_end = base_addr + old_mem.len;126 const old_addr_end = base_addr + old_mem.len;
...@@ -164,7 +164,7 @@ pub const DirectAllocator = struct {...@@ -164,7 +164,7 @@ pub const DirectAllocator = struct {
164 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);164 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
165165
166 switch (builtin.os) {166 switch (builtin.os) {
167 Os.linux, Os.macosx, Os.ios, Os.freebsd => {167 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
168 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);168 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
169 },169 },
170 Os.windows => {170 Os.windows => {
std/os/file.zig+3-3
...@@ -237,7 +237,7 @@ pub const File = struct {...@@ -237,7 +237,7 @@ pub const File = struct {
237237
238 pub fn seekForward(self: File, amount: isize) SeekError!void {238 pub fn seekForward(self: File, amount: isize) SeekError!void {
239 switch (builtin.os) {239 switch (builtin.os) {
240 Os.linux, Os.macosx, Os.ios, Os.freebsd => {240 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
241 const result = posix.lseek(self.handle, amount, posix.SEEK_CUR);241 const result = posix.lseek(self.handle, amount, posix.SEEK_CUR);
242 const err = posix.getErrno(result);242 const err = posix.getErrno(result);
243 if (err > 0) {243 if (err > 0) {
...@@ -268,7 +268,7 @@ pub const File = struct {...@@ -268,7 +268,7 @@ pub const File = struct {
268268
269 pub fn seekTo(self: File, pos: usize) SeekError!void {269 pub fn seekTo(self: File, pos: usize) SeekError!void {
270 switch (builtin.os) {270 switch (builtin.os) {
271 Os.linux, Os.macosx, Os.ios, Os.freebsd => {271 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
272 const ipos = try math.cast(isize, pos);272 const ipos = try math.cast(isize, pos);
273 const result = posix.lseek(self.handle, ipos, posix.SEEK_SET);273 const result = posix.lseek(self.handle, ipos, posix.SEEK_SET);
274 const err = posix.getErrno(result);274 const err = posix.getErrno(result);
...@@ -309,7 +309,7 @@ pub const File = struct {...@@ -309,7 +309,7 @@ pub const File = struct {
309309
310 pub fn getPos(self: File) GetSeekPosError!usize {310 pub fn getPos(self: File) GetSeekPosError!usize {
311 switch (builtin.os) {311 switch (builtin.os) {
312 Os.linux, Os.macosx, Os.ios, Os.freebsd => {312 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
313 const result = posix.lseek(self.handle, 0, posix.SEEK_CUR);313 const result = posix.lseek(self.handle, 0, posix.SEEK_CUR);
314 const err = posix.getErrno(result);314 const err = posix.getErrno(result);
315 if (err > 0) {315 if (err > 0) {
std/os/get_app_data_dir.zig+1-1
...@@ -43,7 +43,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD...@@ -43,7 +43,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
43 };43 };
44 return os.path.join(allocator, [][]const u8{ home_dir, "Library", "Application Support", appname });44 return os.path.join(allocator, [][]const u8{ home_dir, "Library", "Application Support", appname });
45 },45 },
46 builtin.Os.linux, builtin.Os.freebsd => {46 builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => {
47 const home_dir = os.getEnvPosix("HOME") orelse {47 const home_dir = os.getEnvPosix("HOME") orelse {
48 // TODO look in /etc/passwd48 // TODO look in /etc/passwd
49 return error.AppDataDirUnavailable;49 return error.AppDataDirUnavailable;
std/os/get_user_id.zig+1-1
...@@ -11,7 +11,7 @@ pub const UserInfo = struct {...@@ -11,7 +11,7 @@ pub const UserInfo = struct {
11/// POSIX function which gets a uid from username.11/// POSIX function which gets a uid from username.
12pub fn getUserInfo(name: []const u8) !UserInfo {12pub fn getUserInfo(name: []const u8) !UserInfo {
13 return switch (builtin.os) {13 return switch (builtin.os) {
14 Os.linux, Os.macosx, Os.ios, Os.freebsd => posixGetUserInfo(name),14 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => posixGetUserInfo(name),
15 else => @compileError("Unsupported OS"),15 else => @compileError("Unsupported OS"),
16 };16 };
17}17}
std/os/index.zig+32-16
...@@ -3,7 +3,7 @@ const builtin = @import("builtin");...@@ -3,7 +3,7 @@ const builtin = @import("builtin");
3const Os = builtin.Os;3const Os = builtin.Os;
4const is_windows = builtin.os == Os.windows;4const is_windows = builtin.os == Os.windows;
5const is_posix = switch (builtin.os) {5const is_posix = switch (builtin.os) {
6 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => true,6 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => true,
7 else => false,7 else => false,
8};8};
9const os = @This();9const os = @This();
...@@ -30,6 +30,7 @@ pub const windows = @import("windows/index.zig");...@@ -30,6 +30,7 @@ pub const windows = @import("windows/index.zig");
30pub const darwin = @import("darwin.zig");30pub const darwin = @import("darwin.zig");
31pub const linux = @import("linux/index.zig");31pub const linux = @import("linux/index.zig");
32pub const freebsd = @import("freebsd/index.zig");32pub const freebsd = @import("freebsd/index.zig");
33pub const netbsd = @import("netbsd/index.zig");
33pub const zen = @import("zen.zig");34pub const zen = @import("zen.zig");
34pub const uefi = @import("uefi.zig");35pub const uefi = @import("uefi.zig");
3536
...@@ -37,6 +38,7 @@ pub const posix = switch (builtin.os) {...@@ -37,6 +38,7 @@ pub const posix = switch (builtin.os) {
37 Os.linux => linux,38 Os.linux => linux,
38 Os.macosx, Os.ios => darwin,39 Os.macosx, Os.ios => darwin,
39 Os.freebsd => freebsd,40 Os.freebsd => freebsd,
41 Os.netbsd => netbsd,
40 Os.zen => zen,42 Os.zen => zen,
41 else => @compileError("Unsupported OS"),43 else => @compileError("Unsupported OS"),
42};44};
...@@ -50,7 +52,7 @@ pub const time = @import("time.zig");...@@ -50,7 +52,7 @@ pub const time = @import("time.zig");
5052
51pub const page_size = 4 * 1024;53pub const page_size = 4 * 1024;
52pub const MAX_PATH_BYTES = switch (builtin.os) {54pub const MAX_PATH_BYTES = switch (builtin.os) {
53 Os.linux, Os.macosx, Os.ios, Os.freebsd => posix.PATH_MAX,55 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => posix.PATH_MAX,
54 // Each UTF-16LE character may be expanded to 3 UTF-8 bytes.56 // Each UTF-16LE character may be expanded to 3 UTF-8 bytes.
55 // If it would require 4 UTF-8 bytes, then there would be a surrogate57 // If it would require 4 UTF-8 bytes, then there would be a surrogate
56 // pair in the UTF-16LE, and we (over)account 3 bytes for it that way.58 // pair in the UTF-16LE, and we (over)account 3 bytes for it that way.
...@@ -125,7 +127,7 @@ pub fn getRandomBytes(buf: []u8) !void {...@@ -125,7 +127,7 @@ pub fn getRandomBytes(buf: []u8) !void {
125 else => return unexpectedErrorPosix(errno),127 else => return unexpectedErrorPosix(errno),
126 }128 }
127 },129 },
128 Os.macosx, Os.ios, Os.freebsd => return getRandomBytesDevURandom(buf),130 Os.macosx, Os.ios, Os.freebsd, Os.netbsd => return getRandomBytesDevURandom(buf),
129 Os.windows => {131 Os.windows => {
130 // Call RtlGenRandom() instead of CryptGetRandom() on Windows132 // Call RtlGenRandom() instead of CryptGetRandom() on Windows
131 // https://github.com/rust-lang-nursery/rand/issues/111133 // https://github.com/rust-lang-nursery/rand/issues/111
...@@ -185,7 +187,7 @@ pub fn abort() noreturn {...@@ -185,7 +187,7 @@ pub fn abort() noreturn {
185 c.abort();187 c.abort();
186 }188 }
187 switch (builtin.os) {189 switch (builtin.os) {
188 Os.linux, Os.macosx, Os.ios, Os.freebsd => {190 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
189 _ = posix.raise(posix.SIGABRT);191 _ = posix.raise(posix.SIGABRT);
190 _ = posix.raise(posix.SIGKILL);192 _ = posix.raise(posix.SIGKILL);
191 while (true) {}193 while (true) {}
...@@ -211,7 +213,7 @@ pub fn exit(status: u8) noreturn {...@@ -211,7 +213,7 @@ pub fn exit(status: u8) noreturn {
211 c.exit(status);213 c.exit(status);
212 }214 }
213 switch (builtin.os) {215 switch (builtin.os) {
214 Os.linux, Os.macosx, Os.ios, Os.freebsd => {216 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
215 posix.exit(status);217 posix.exit(status);
216 },218 },
217 Os.windows => {219 Os.windows => {
...@@ -327,7 +329,7 @@ pub fn posix_preadv(fd: i32, iov: [*]const posix.iovec, count: usize, offset: u6...@@ -327,7 +329,7 @@ pub fn posix_preadv(fd: i32, iov: [*]const posix.iovec, count: usize, offset: u6
327 }329 }
328 }330 }
329 },331 },
330 builtin.Os.linux, builtin.Os.freebsd => while (true) {332 builtin.Os.linux, builtin.Os.freebsd, Os.netbsd => while (true) {
331 const rc = posix.preadv(fd, iov, count, offset);333 const rc = posix.preadv(fd, iov, count, offset);
332 const err = posix.getErrno(rc);334 const err = posix.getErrno(rc);
333 switch (err) {335 switch (err) {
...@@ -434,7 +436,7 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off...@@ -434,7 +436,7 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off
434 }436 }
435 }437 }
436 },438 },
437 builtin.Os.linux, builtin.Os.freebsd => while (true) {439 builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => while (true) {
438 const rc = posix.pwritev(fd, iov, count, offset);440 const rc = posix.pwritev(fd, iov, count, offset);
439 const err = posix.getErrno(rc);441 const err = posix.getErrno(rc);
440 switch (err) {442 switch (err) {
...@@ -699,7 +701,7 @@ pub fn getBaseAddress() usize {...@@ -699,7 +701,7 @@ pub fn getBaseAddress() usize {
699 const phdr = linuxGetAuxVal(std.elf.AT_PHDR);701 const phdr = linuxGetAuxVal(std.elf.AT_PHDR);
700 return phdr - @sizeOf(std.elf.Ehdr);702 return phdr - @sizeOf(std.elf.Ehdr);
701 },703 },
702 builtin.Os.macosx, builtin.Os.freebsd => return @ptrToInt(&std.c._mh_execute_header),704 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => return @ptrToInt(&std.c._mh_execute_header),
703 builtin.Os.windows => return @ptrToInt(windows.GetModuleHandleW(null)),705 builtin.Os.windows => return @ptrToInt(windows.GetModuleHandleW(null)),
704 else => @compileError("Unsupported OS"),706 else => @compileError("Unsupported OS"),
705 }707 }
...@@ -1339,7 +1341,7 @@ pub fn deleteDirC(dir_path: [*]const u8) DeleteDirError!void {...@@ -1339,7 +1341,7 @@ pub fn deleteDirC(dir_path: [*]const u8) DeleteDirError!void {
1339 const dir_path_w = try windows_util.cStrToPrefixedFileW(dir_path);1341 const dir_path_w = try windows_util.cStrToPrefixedFileW(dir_path);
1340 return deleteDirW(&dir_path_w);1342 return deleteDirW(&dir_path_w);
1341 },1343 },
1342 Os.linux, Os.macosx, Os.ios, Os.freebsd => {1344 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
1343 const err = posix.getErrno(posix.rmdir(dir_path));1345 const err = posix.getErrno(posix.rmdir(dir_path));
1344 switch (err) {1346 switch (err) {
1345 0 => return,1347 0 => return,
...@@ -1382,7 +1384,7 @@ pub fn deleteDir(dir_path: []const u8) DeleteDirError!void {...@@ -1382,7 +1384,7 @@ pub fn deleteDir(dir_path: []const u8) DeleteDirError!void {
1382 const dir_path_w = try windows_util.sliceToPrefixedFileW(dir_path);1384 const dir_path_w = try windows_util.sliceToPrefixedFileW(dir_path);
1383 return deleteDirW(&dir_path_w);1385 return deleteDirW(&dir_path_w);
1384 },1386 },
1385 Os.linux, Os.macosx, Os.ios, Os.freebsd => {1387 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
1386 const dir_path_c = try toPosixPath(dir_path);1388 const dir_path_c = try toPosixPath(dir_path);
1387 return deleteDirC(&dir_path_c);1389 return deleteDirC(&dir_path_c);
1388 },1390 },
...@@ -1501,7 +1503,7 @@ pub const Dir = struct {...@@ -1501,7 +1503,7 @@ pub const Dir = struct {
1501 allocator: *Allocator,1503 allocator: *Allocator,
15021504
1503 pub const Handle = switch (builtin.os) {1505 pub const Handle = switch (builtin.os) {
1504 Os.macosx, Os.ios, Os.freebsd => struct {1506 Os.macosx, Os.ios, Os.freebsd, Os.netbsd => struct {
1505 fd: i32,1507 fd: i32,
1506 seek: i64,1508 seek: i64,
1507 buf: []u8,1509 buf: []u8,
...@@ -1578,7 +1580,7 @@ pub const Dir = struct {...@@ -1578,7 +1580,7 @@ pub const Dir = struct {
1578 .name_data = undefined,1580 .name_data = undefined,
1579 };1581 };
1580 },1582 },
1581 Os.macosx, Os.ios, Os.freebsd => Handle{1583 Os.macosx, Os.ios, Os.freebsd, Os.netbsd => Handle{
1582 .fd = try posixOpen(1584 .fd = try posixOpen(
1583 dir_path,1585 dir_path,
1584 posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC,1586 posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC,
...@@ -1609,7 +1611,7 @@ pub const Dir = struct {...@@ -1609,7 +1611,7 @@ pub const Dir = struct {
1609 Os.windows => {1611 Os.windows => {
1610 _ = windows.FindClose(self.handle.handle);1612 _ = windows.FindClose(self.handle.handle);
1611 },1613 },
1612 Os.macosx, Os.ios, Os.linux, Os.freebsd => {1614 Os.macosx, Os.ios, Os.linux, Os.freebsd, Os.netbsd => {
1613 self.allocator.free(self.handle.buf);1615 self.allocator.free(self.handle.buf);
1614 os.close(self.handle.fd);1616 os.close(self.handle.fd);
1615 },1617 },
...@@ -1625,6 +1627,7 @@ pub const Dir = struct {...@@ -1625,6 +1627,7 @@ pub const Dir = struct {
1625 Os.macosx, Os.ios => return self.nextDarwin(),1627 Os.macosx, Os.ios => return self.nextDarwin(),
1626 Os.windows => return self.nextWindows(),1628 Os.windows => return self.nextWindows(),
1627 Os.freebsd => return self.nextFreebsd(),1629 Os.freebsd => return self.nextFreebsd(),
1630 Os.netbsd => return self.nextFreebsd(),
1628 else => @compileError("unimplemented"),1631 else => @compileError("unimplemented"),
1629 }1632 }
1630 }1633 }
...@@ -2256,7 +2259,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) UnexpectedError {...@@ -2256,7 +2259,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) UnexpectedError {
2256pub fn openSelfExe() !os.File {2259pub fn openSelfExe() !os.File {
2257 switch (builtin.os) {2260 switch (builtin.os) {
2258 Os.linux => return os.File.openReadC(c"/proc/self/exe"),2261 Os.linux => return os.File.openReadC(c"/proc/self/exe"),
2259 Os.macosx, Os.ios, Os.freebsd => {2262 Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
2260 var buf: [MAX_PATH_BYTES]u8 = undefined;2263 var buf: [MAX_PATH_BYTES]u8 = undefined;
2261 const self_exe_path = try selfExePath(&buf);2264 const self_exe_path = try selfExePath(&buf);
2262 buf[self_exe_path.len] = 0;2265 buf[self_exe_path.len] = 0;
...@@ -2317,6 +2320,19 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 {...@@ -2317,6 +2320,19 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
2317 else => unexpectedErrorPosix(err),2320 else => unexpectedErrorPosix(err),
2318 };2321 };
2319 },2322 },
2323 Os.netbsd => {
2324 var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC_ARGS, -1, posix.KERN_PROC_PATHNAME };
2325 var out_len: usize = out_buffer.len;
2326 const err = posix.getErrno(posix.sysctl(&mib, 4, out_buffer, &out_len, null, 0));
2327
2328 if (err == 0) return mem.toSlice(u8, out_buffer);
2329
2330 return switch (err) {
2331 posix.EFAULT => error.BadAdress,
2332 posix.EPERM => error.PermissionDenied,
2333 else => unexpectedErrorPosix(err),
2334 };
2335 },
2320 Os.windows => {2336 Os.windows => {
2321 var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined;2337 var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined;
2322 const utf16le_slice = try selfExePathW(&utf16le_buf);2338 const utf16le_slice = try selfExePathW(&utf16le_buf);
...@@ -2355,7 +2371,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) ![]const u8 {...@@ -2355,7 +2371,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) ![]const u8 {
2355 // will not return null.2371 // will not return null.
2356 return path.dirname(full_exe_path).?;2372 return path.dirname(full_exe_path).?;
2357 },2373 },
2358 Os.windows, Os.macosx, Os.ios, Os.freebsd => {2374 Os.windows, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
2359 const self_exe_path = try selfExePath(out_buffer);2375 const self_exe_path = try selfExePath(out_buffer);
2360 // Assume that the OS APIs return absolute paths, and therefore dirname2376 // Assume that the OS APIs return absolute paths, and therefore dirname
2361 // will not return null.2377 // will not return null.
...@@ -3227,7 +3243,7 @@ pub const CpuCountError = error{...@@ -3227,7 +3243,7 @@ pub const CpuCountError = error{
32273243
3228pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize {3244pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize {
3229 switch (builtin.os) {3245 switch (builtin.os) {
3230 builtin.Os.macosx, builtin.Os.freebsd => {3246 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
3231 var count: c_int = undefined;3247 var count: c_int = undefined;
3232 var count_len: usize = @sizeOf(c_int);3248 var count_len: usize = @sizeOf(c_int);
3233 const rc = posix.sysctlbyname(switch (builtin.os) {3249 const rc = posix.sysctlbyname(switch (builtin.os) {
std/os/netbsd/errno.zig created+134
...@@ -0,0 +1,134 @@
1pub const EPERM = 1; // Operation not permitted
2pub const ENOENT = 2; // No such file or directory
3pub const ESRCH = 3; // No such process
4pub const EINTR = 4; // Interrupted system call
5pub const EIO = 5; // Input/output error
6pub const ENXIO = 6; // Device not configured
7pub const E2BIG = 7; // Argument list too long
8pub const ENOEXEC = 8; // Exec format error
9pub const EBADF = 9; // Bad file descriptor
10pub const ECHILD = 10; // No child processes
11pub const EDEADLK = 11; // Resource deadlock avoided
12// 11 was EAGAIN
13pub const ENOMEM = 12; // Cannot allocate memory
14pub const EACCES = 13; // Permission denied
15pub const EFAULT = 14; // Bad address
16pub const ENOTBLK = 15; // Block device required
17pub const EBUSY = 16; // Device busy
18pub const EEXIST = 17; // File exists
19pub const EXDEV = 18; // Cross-device link
20pub const ENODEV = 19; // Operation not supported by device
21pub const ENOTDIR = 20; // Not a directory
22pub const EISDIR = 21; // Is a directory
23pub const EINVAL = 22; // Invalid argument
24pub const ENFILE = 23; // Too many open files in system
25pub const EMFILE = 24; // Too many open files
26pub const ENOTTY = 25; // Inappropriate ioctl for device
27pub const ETXTBSY = 26; // Text file busy
28pub const EFBIG = 27; // File too large
29pub const ENOSPC = 28; // No space left on device
30pub const ESPIPE = 29; // Illegal seek
31pub const EROFS = 30; // Read-only file system
32pub const EMLINK = 31; // Too many links
33pub const EPIPE = 32; // Broken pipe
34
35// math software
36pub const EDOM = 33; // Numerical argument out of domain
37pub const ERANGE = 34; // Result too large or too small
38
39// non-blocking and interrupt i/o
40pub const EAGAIN = 35; // Resource temporarily unavailable
41pub const EWOULDBLOCK = EAGAIN; // Operation would block
42pub const EINPROGRESS = 36; // Operation now in progress
43pub const EALREADY = 37; // Operation already in progress
44
45// ipc/network software -- argument errors
46pub const ENOTSOCK = 38; // Socket operation on non-socket
47pub const EDESTADDRREQ = 39; // Destination address required
48pub const EMSGSIZE = 40; // Message too long
49pub const EPROTOTYPE = 41; // Protocol wrong type for socket
50pub const ENOPROTOOPT = 42; // Protocol option not available
51pub const EPROTONOSUPPORT = 43; // Protocol not supported
52pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
53pub const EOPNOTSUPP = 45; // Operation not supported
54pub const EPFNOSUPPORT = 46; // Protocol family not supported
55pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
56pub const EADDRINUSE = 48; // Address already in use
57pub const EADDRNOTAVAIL = 49; // Can't assign requested address
58
59// ipc/network software -- operational errors
60pub const ENETDOWN = 50; // Network is down
61pub const ENETUNREACH = 51; // Network is unreachable
62pub const ENETRESET = 52; // Network dropped connection on reset
63pub const ECONNABORTED = 53; // Software caused connection abort
64pub const ECONNRESET = 54; // Connection reset by peer
65pub const ENOBUFS = 55; // No buffer space available
66pub const EISCONN = 56; // Socket is already connected
67pub const ENOTCONN = 57; // Socket is not connected
68pub const ESHUTDOWN = 58; // Can't send after socket shutdown
69pub const ETOOMANYREFS = 59; // Too many references: can't splice
70pub const ETIMEDOUT = 60; // Operation timed out
71pub const ECONNREFUSED = 61; // Connection refused
72
73pub const ELOOP = 62; // Too many levels of symbolic links
74pub const ENAMETOOLONG = 63; // File name too long
75
76// should be rearranged
77pub const EHOSTDOWN = 64; // Host is down
78pub const EHOSTUNREACH = 65; // No route to host
79pub const ENOTEMPTY = 66; // Directory not empty
80
81// quotas & mush
82pub const EPROCLIM = 67; // Too many processes
83pub const EUSERS = 68; // Too many users
84pub const EDQUOT = 69; // Disc quota exceeded
85
86// Network File System
87pub const ESTALE = 70; // Stale NFS file handle
88pub const EREMOTE = 71; // Too many levels of remote in path
89pub const EBADRPC = 72; // RPC struct is bad
90pub const ERPCMISMATCH = 73; // RPC version wrong
91pub const EPROGUNAVAIL = 74; // RPC prog. not avail
92pub const EPROGMISMATCH = 75; // Program version wrong
93pub const EPROCUNAVAIL = 76; // Bad procedure for program
94
95pub const ENOLCK = 77; // No locks available
96pub const ENOSYS = 78; // Function not implemented
97
98pub const EFTYPE = 79; // Inappropriate file type or format
99pub const EAUTH = 80; // Authentication error
100pub const ENEEDAUTH = 81; // Need authenticator
101
102// SystemV IPC
103pub const EIDRM = 82; // Identifier removed
104pub const ENOMSG = 83; // No message of desired type
105pub const EOVERFLOW = 84; // Value too large to be stored in data type
106
107// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
108pub const EILSEQ = 85; // Illegal byte sequence
109
110// From IEEE Std 1003.1-2001
111// Base, Realtime, Threads or Thread Priority Scheduling option errors
112pub const ENOTSUP = 86; // Not supported
113
114// Realtime option errors
115pub const ECANCELED = 87; // Operation canceled
116
117// Realtime, XSI STREAMS option errors
118pub const EBADMSG = 88; // Bad or Corrupt message
119
120// XSI STREAMS option errors
121pub const ENODATA = 89; // No message available
122pub const ENOSR = 90; // No STREAM resources
123pub const ENOSTR = 91; // Not a STREAM
124pub const ETIME = 92; // STREAM ioctl timeout
125
126// File system extended attribute errors
127pub const ENOATTR = 93; // Attribute not found
128
129// Realtime, XSI STREAMS option errors
130pub const EMULTIHOP = 94; // Multihop attempted
131pub const ENOLINK = 95; // Link has been severed
132pub const EPROTO = 96; // Protocol error
133
134pub const ELAST = 96; // Must equal largest errno
std/os/netbsd/index.zig created+728
...@@ -0,0 +1,728 @@
1const builtin = @import("builtin");
2
3pub use @import("errno.zig");
4
5const std = @import("../../index.zig");
6const c = std.c;
7
8const assert = std.debug.assert;
9const maxInt = std.math.maxInt;
10pub const Kevent = c.Kevent;
11
12pub const CTL_KERN = 1;
13pub const CTL_DEBUG = 5;
14
15pub const KERN_PROC_ARGS = 48; // struct: process argv/env
16pub const KERN_PROC_PATHNAME = 5; // path to executable
17
18pub const PATH_MAX = 1024;
19
20pub const STDIN_FILENO = 0;
21pub const STDOUT_FILENO = 1;
22pub const STDERR_FILENO = 2;
23
24pub const PROT_NONE = 0;
25pub const PROT_READ = 1;
26pub const PROT_WRITE = 2;
27pub const PROT_EXEC = 4;
28
29pub const CLOCK_REALTIME = 0;
30pub const CLOCK_VIRTUAL = 1;
31pub const CLOCK_PROF = 2;
32pub const CLOCK_MONOTONIC = 3;
33pub const CLOCK_THREAD_CPUTIME_ID = 0x20000000;
34pub const CLOCK_PROCESS_CPUTIME_ID = 0x40000000;
35
36pub const MAP_FAILED = maxInt(usize);
37pub const MAP_SHARED = 0x0001;
38pub const MAP_PRIVATE = 0x0002;
39pub const MAP_REMAPDUP = 0x0004;
40pub const MAP_FIXED = 0x0010;
41pub const MAP_RENAME = 0x0020;
42pub const MAP_NORESERVE = 0x0040;
43pub const MAP_INHERIT = 0x0080;
44pub const MAP_HASSEMAPHORE = 0x0200;
45pub const MAP_TRYFIXED = 0x0400;
46pub const MAP_WIRED = 0x0800;
47
48pub const MAP_FILE = 0x0000;
49pub const MAP_NOSYNC = 0x0800;
50pub const MAP_ANON = 0x1000;
51pub const MAP_ANONYMOUS = MAP_ANON;
52pub const MAP_STACK = 0x2000;
53
54pub const WNOHANG = 0x00000001;
55pub const WUNTRACED = 0x00000002;
56pub const WSTOPPED = WUNTRACED;
57pub const WCONTINUED = 0x00000010;
58pub const WNOWAIT = 0x00010000;
59pub const WEXITED = 0x00000020;
60pub const WTRAPPED = 0x00000040;
61
62pub const SA_ONSTACK = 0x0001;
63pub const SA_RESTART = 0x0002;
64pub const SA_RESETHAND = 0x0004;
65pub const SA_NOCLDSTOP = 0x0008;
66pub const SA_NODEFER = 0x0010;
67pub const SA_NOCLDWAIT = 0x0020;
68pub const SA_SIGINFO = 0x0040;
69
70pub const SIGHUP = 1;
71pub const SIGINT = 2;
72pub const SIGQUIT = 3;
73pub const SIGILL = 4;
74pub const SIGTRAP = 5;
75pub const SIGABRT = 6;
76pub const SIGIOT = SIGABRT;
77pub const SIGEMT = 7;
78pub const SIGFPE = 8;
79pub const SIGKILL = 9;
80pub const SIGBUS = 10;
81pub const SIGSEGV = 11;
82pub const SIGSYS = 12;
83pub const SIGPIPE = 13;
84pub const SIGALRM = 14;
85pub const SIGTERM = 15;
86pub const SIGURG = 16;
87pub const SIGSTOP = 17;
88pub const SIGTSTP = 18;
89pub const SIGCONT = 19;
90pub const SIGCHLD = 20;
91pub const SIGTTIN = 21;
92pub const SIGTTOU = 22;
93pub const SIGIO = 23;
94pub const SIGXCPU = 24;
95pub const SIGXFSZ = 25;
96pub const SIGVTALRM = 26;
97pub const SIGPROF = 27;
98pub const SIGWINCH = 28;
99pub const SIGINFO = 29;
100pub const SIGUSR1 = 30;
101pub const SIGUSR2 = 31;
102pub const SIGPWR = 32;
103
104pub const SIGRTMIN = 33;
105pub const SIGRTMAX = 63;
106
107// access function
108pub const F_OK = 0; // test for existence of file
109pub const X_OK = 1; // test for execute or search permission
110pub const W_OK = 2; // test for write permission
111pub const R_OK = 4; // test for read permission
112
113
114pub const O_RDONLY = 0x0000;
115pub const O_WRONLY = 0x0001;
116pub const O_RDWR = 0x0002;
117pub const O_ACCMODE = 0x0003;
118
119pub const O_CREAT = 0x0200;
120pub const O_EXCL = 0x0800;
121pub const O_NOCTTY = 0x8000;
122pub const O_TRUNC = 0x0400;
123pub const O_APPEND = 0x0008;
124pub const O_NONBLOCK = 0x0004;
125pub const O_DSYNC = 0x00010000;
126pub const O_SYNC = 0x0080;
127pub const O_RSYNC = 0x00020000;
128pub const O_DIRECTORY = 0x00080000;
129pub const O_NOFOLLOW = 0x00000100;
130pub const O_CLOEXEC = 0x00400000;
131
132pub const O_ASYNC = 0x0040;
133pub const O_DIRECT = 0x00080000;
134pub const O_LARGEFILE = 0;
135pub const O_NOATIME = 0;
136pub const O_PATH = 0;
137pub const O_TMPFILE = 0;
138pub const O_NDELAY = O_NONBLOCK;
139
140pub const F_DUPFD = 0;
141pub const F_GETFD = 1;
142pub const F_SETFD = 2;
143pub const F_GETFL = 3;
144pub const F_SETFL = 4;
145
146pub const F_GETOWN = 5;
147pub const F_SETOWN = 6;
148
149pub const F_GETLK = 7;
150pub const F_SETLK = 8;
151pub const F_SETLKW = 9;
152
153pub const SEEK_SET = 0;
154pub const SEEK_CUR = 1;
155pub const SEEK_END = 2;
156
157pub const SIG_BLOCK = 1;
158pub const SIG_UNBLOCK = 2;
159pub const SIG_SETMASK = 3;
160
161pub const SOCK_STREAM = 1;
162pub const SOCK_DGRAM = 2;
163pub const SOCK_RAW = 3;
164pub const SOCK_RDM = 4;
165pub const SOCK_SEQPACKET = 5;
166
167pub const SOCK_CLOEXEC = 0x10000000;
168pub const SOCK_NONBLOCK = 0x20000000;
169
170pub const PROTO_ip = 0;
171pub const PROTO_icmp = 1;
172pub const PROTO_igmp = 2;
173pub const PROTO_ggp = 3;
174pub const PROTO_ipencap = 4;
175pub const PROTO_tcp = 6;
176pub const PROTO_egp = 8;
177pub const PROTO_pup = 12;
178pub const PROTO_udp = 17;
179pub const PROTO_xns_idp = 22;
180pub const PROTO_iso_tp4 = 29;
181pub const PROTO_ipv6 = 41;
182pub const PROTO_ipv6_route = 43;
183pub const PROTO_ipv6_frag = 44;
184pub const PROTO_rsvp = 46;
185pub const PROTO_gre = 47;
186pub const PROTO_esp = 50;
187pub const PROTO_ah = 51;
188pub const PROTO_ipv6_icmp = 58;
189pub const PROTO_ipv6_nonxt = 59;
190pub const PROTO_ipv6_opts = 60;
191pub const PROTO_encap = 98;
192pub const PROTO_pim = 103;
193pub const PROTO_raw = 255;
194
195pub const PF_UNSPEC = 0;
196pub const PF_LOCAL = 1;
197pub const PF_UNIX = PF_LOCAL;
198pub const PF_FILE = PF_LOCAL;
199pub const PF_INET = 2;
200pub const PF_APPLETALK = 16;
201pub const PF_INET6 = 24;
202pub const PF_DECnet = 12;
203pub const PF_KEY = 29;
204pub const PF_ROUTE = 34;
205pub const PF_SNA = 11;
206pub const PF_MPLS = 33;
207pub const PF_CAN = 35;
208pub const PF_BLUETOOTH = 31;
209pub const PF_ISDN = 26;
210pub const PF_MAX = 37;
211
212pub const AF_UNSPEC = PF_UNSPEC;
213pub const AF_LOCAL = PF_LOCAL;
214pub const AF_UNIX = AF_LOCAL;
215pub const AF_FILE = AF_LOCAL;
216pub const AF_INET = PF_INET;
217pub const AF_APPLETALK = PF_APPLETALK;
218pub const AF_INET6 = PF_INET6;
219pub const AF_KEY = PF_KEY;
220pub const AF_ROUTE = PF_ROUTE;
221pub const AF_SNA = PF_SNA;
222pub const AF_MPLS = PF_MPLS;
223pub const AF_CAN = PF_CAN;
224pub const AF_BLUETOOTH = PF_BLUETOOTH;
225pub const AF_ISDN = PF_ISDN;
226pub const AF_MAX = PF_MAX;
227
228pub const DT_UNKNOWN = 0;
229pub const DT_FIFO = 1;
230pub const DT_CHR = 2;
231pub const DT_DIR = 4;
232pub const DT_BLK = 6;
233pub const DT_REG = 8;
234pub const DT_LNK = 10;
235pub const DT_SOCK = 12;
236pub const DT_WHT = 14;
237
238/// add event to kq (implies enable)
239pub const EV_ADD = 0x0001;
240
241/// delete event from kq
242pub const EV_DELETE = 0x0002;
243
244/// enable event
245pub const EV_ENABLE = 0x0004;
246
247/// disable event (not reported)
248pub const EV_DISABLE = 0x0008;
249
250/// only report one occurrence
251pub const EV_ONESHOT = 0x0010;
252
253/// clear event state after reporting
254pub const EV_CLEAR = 0x0020;
255
256/// force immediate event output
257/// ... with or without EV_ERROR
258/// ... use KEVENT_FLAG_ERROR_EVENTS
259/// on syscalls supporting flags
260pub const EV_RECEIPT = 0x0040;
261
262/// disable event after reporting
263pub const EV_DISPATCH = 0x0080;
264
265pub const EVFILT_READ = 0;
266pub const EVFILT_WRITE = 1;
267
268/// attached to aio requests
269pub const EVFILT_AIO = 2;
270
271/// attached to vnodes
272pub const EVFILT_VNODE = 3;
273
274/// attached to struct proc
275pub const EVFILT_PROC = 4;
276
277/// attached to struct proc
278pub const EVFILT_SIGNAL = 5;
279
280/// timers
281pub const EVFILT_TIMER = 6;
282
283/// Filesystem events
284pub const EVFILT_FS = 7;
285
286/// XXX no EVFILT_USER, but what is it
287pub const EVFILT_USER = 0;
288
289/// On input, NOTE_TRIGGER causes the event to be triggered for output.
290pub const NOTE_TRIGGER = 0x08000000;
291
292/// low water mark
293pub const NOTE_LOWAT = 0x00000001;
294
295/// vnode was removed
296pub const NOTE_DELETE = 0x00000001;
297
298/// data contents changed
299pub const NOTE_WRITE = 0x00000002;
300
301/// size increased
302pub const NOTE_EXTEND = 0x00000004;
303
304/// attributes changed
305pub const NOTE_ATTRIB = 0x00000008;
306
307/// link count changed
308pub const NOTE_LINK = 0x00000010;
309
310/// vnode was renamed
311pub const NOTE_RENAME = 0x00000020;
312
313/// vnode access was revoked
314pub const NOTE_REVOKE = 0x00000040;
315
316/// process exited
317pub const NOTE_EXIT = 0x80000000;
318
319/// process forked
320pub const NOTE_FORK = 0x40000000;
321
322/// process exec'd
323pub const NOTE_EXEC = 0x20000000;
324
325/// mask for signal & exit status
326pub const NOTE_PDATAMASK = 0x000fffff;
327pub const NOTE_PCTRLMASK = 0xf0000000;
328
329pub const TIOCCBRK = 0x2000747a;
330pub const TIOCCDTR = 0x20007478;
331pub const TIOCCONS = 0x80047462;
332pub const TIOCDCDTIMESTAMP = 0x40107458;
333pub const TIOCDRAIN = 0x2000745e;
334pub const TIOCEXCL = 0x2000740d;
335pub const TIOCEXT = 0x80047460;
336pub const TIOCFLAG_CDTRCTS = 0x10;
337pub const TIOCFLAG_CLOCAL = 0x2;
338pub const TIOCFLAG_CRTSCTS = 0x4;
339pub const TIOCFLAG_MDMBUF = 0x8;
340pub const TIOCFLAG_SOFTCAR = 0x1;
341pub const TIOCFLUSH = 0x80047410;
342pub const TIOCGETA = 0x402c7413;
343pub const TIOCGETD = 0x4004741a;
344pub const TIOCGFLAGS = 0x4004745d;
345pub const TIOCGLINED = 0x40207442;
346pub const TIOCGPGRP = 0x40047477;
347pub const TIOCGQSIZE = 0x40047481;
348pub const TIOCGRANTPT = 0x20007447;
349pub const TIOCGSID = 0x40047463;
350pub const TIOCGSIZE = 0x40087468;
351pub const TIOCGWINSZ = 0x40087468;
352pub const TIOCMBIC = 0x8004746b;
353pub const TIOCMBIS = 0x8004746c;
354pub const TIOCMGET = 0x4004746a;
355pub const TIOCMSET = 0x8004746d;
356pub const TIOCM_CAR = 0x40;
357pub const TIOCM_CD = 0x40;
358pub const TIOCM_CTS = 0x20;
359pub const TIOCM_DSR = 0x100;
360pub const TIOCM_DTR = 0x2;
361pub const TIOCM_LE = 0x1;
362pub const TIOCM_RI = 0x80;
363pub const TIOCM_RNG = 0x80;
364pub const TIOCM_RTS = 0x4;
365pub const TIOCM_SR = 0x10;
366pub const TIOCM_ST = 0x8;
367pub const TIOCNOTTY = 0x20007471;
368pub const TIOCNXCL = 0x2000740e;
369pub const TIOCOUTQ = 0x40047473;
370pub const TIOCPKT = 0x80047470;
371pub const TIOCPKT_DATA = 0x0;
372pub const TIOCPKT_DOSTOP = 0x20;
373pub const TIOCPKT_FLUSHREAD = 0x1;
374pub const TIOCPKT_FLUSHWRITE = 0x2;
375pub const TIOCPKT_IOCTL = 0x40;
376pub const TIOCPKT_NOSTOP = 0x10;
377pub const TIOCPKT_START = 0x8;
378pub const TIOCPKT_STOP = 0x4;
379pub const TIOCPTMGET = 0x40287446;
380pub const TIOCPTSNAME = 0x40287448;
381pub const TIOCRCVFRAME = 0x80087445;
382pub const TIOCREMOTE = 0x80047469;
383pub const TIOCSBRK = 0x2000747b;
384pub const TIOCSCTTY = 0x20007461;
385pub const TIOCSDTR = 0x20007479;
386pub const TIOCSETA = 0x802c7414;
387pub const TIOCSETAF = 0x802c7416;
388pub const TIOCSETAW = 0x802c7415;
389pub const TIOCSETD = 0x8004741b;
390pub const TIOCSFLAGS = 0x8004745c;
391pub const TIOCSIG = 0x2000745f;
392pub const TIOCSLINED = 0x80207443;
393pub const TIOCSPGRP = 0x80047476;
394pub const TIOCSQSIZE = 0x80047480;
395pub const TIOCSSIZE = 0x80087467;
396pub const TIOCSTART = 0x2000746e;
397pub const TIOCSTAT = 0x80047465;
398pub const TIOCSTI = 0x80017472;
399pub const TIOCSTOP = 0x2000746f;
400pub const TIOCSWINSZ = 0x80087467;
401pub const TIOCUCNTL = 0x80047466;
402pub const TIOCXMTFRAME = 0x80087444;
403
404pub const sockaddr = c.sockaddr;
405pub const sockaddr_in = c.sockaddr_in;
406pub const sockaddr_in6 = c.sockaddr_in6;
407
408fn unsigned(s: i32) u32 {
409 return @bitCast(u32, s);
410}
411fn signed(s: u32) i32 {
412 return @bitCast(i32, s);
413}
414pub fn WEXITSTATUS(s: i32) i32 {
415 return signed((unsigned(s) >> 8) & 0xff);
416}
417pub fn WTERMSIG(s: i32) i32 {
418 return signed(unsigned(s) & 0x7f);
419}
420pub fn WSTOPSIG(s: i32) i32 {
421 return WEXITSTATUS(s);
422}
423pub fn WIFEXITED(s: i32) bool {
424 return WTERMSIG(s) == 0;
425}
426
427pub fn WIFCONTINUED(s: i32) bool {
428 return ((s & 0x7f) == 0xffff);
429}
430
431pub fn WIFSTOPPED(s: i32) bool {
432 return ((s & 0x7f != 0x7f) and !WIFCONTINUED(s));
433}
434
435pub fn WIFSIGNALED(s: i32) bool {
436 return !WIFSTOPPED(s) and !WIFCONTINUED(s) and !WIFEXITED(s);
437}
438
439pub const winsize = extern struct {
440 ws_row: u16,
441 ws_col: u16,
442 ws_xpixel: u16,
443 ws_ypixel: u16,
444};
445
446/// Get the errno from a syscall return value, or 0 for no error.
447pub fn getErrno(r: usize) usize {
448 const signed_r = @bitCast(isize, r);
449 return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
450}
451
452pub fn dup2(old: i32, new: i32) usize {
453 return errnoWrap(c.dup2(old, new));
454}
455
456pub fn chdir(path: [*]const u8) usize {
457 return errnoWrap(c.chdir(path));
458}
459
460pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
461 return errnoWrap(c.execve(path, argv, envp));
462}
463
464pub fn fork() usize {
465 return errnoWrap(c.fork());
466}
467
468pub fn access(path: [*]const u8, mode: u32) usize {
469 return errnoWrap(c.access(path, mode));
470}
471
472pub fn getcwd(buf: [*]u8, size: usize) usize {
473 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
474}
475
476pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
477 return errnoWrap(@bitCast(isize, c.getdents(fd, drip, count)));
478}
479
480pub fn getdirentries(fd: i32, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize {
481 return errnoWrap(@bitCast(isize, c.getdirentries(fd, buf_ptr, buf_len, basep)));
482}
483
484pub fn realpath(noalias filename: [*]const u8, noalias resolved_name: [*]u8) usize {
485 return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
486}
487
488pub fn isatty(fd: i32) bool {
489 return c.isatty(fd) != 0;
490}
491
492pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
493 return errnoWrap(c.readlink(path, buf_ptr, buf_len));
494}
495
496pub fn mkdir(path: [*]const u8, mode: u32) usize {
497 return errnoWrap(c.mkdir(path, mode));
498}
499
500pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
501 const ptr_result = c.mmap(
502 @ptrCast(?*c_void, address),
503 length,
504 @bitCast(c_int, @intCast(c_uint, prot)),
505 @bitCast(c_int, c_uint(flags)),
506 fd,
507 offset,
508 );
509 const isize_result = @bitCast(isize, @ptrToInt(ptr_result));
510 return errnoWrap(isize_result);
511}
512
513pub fn munmap(address: usize, length: usize) usize {
514 return errnoWrap(c.munmap(@intToPtr(*c_void, address), length));
515}
516
517pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize {
518 return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte));
519}
520
521pub fn rmdir(path: [*]const u8) usize {
522 return errnoWrap(c.rmdir(path));
523}
524
525pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
526 return errnoWrap(c.symlink(existing, new));
527}
528
529pub fn pread(fd: i32, buf: [*]u8, nbyte: usize, offset: u64) usize {
530 return errnoWrap(c.pread(fd, @ptrCast(*c_void, buf), nbyte, offset));
531}
532
533pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize {
534 return errnoWrap(c.preadv(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset));
535}
536
537pub fn pipe(fd: *[2]i32) usize {
538 return pipe2(fd, 0);
539}
540
541pub fn pipe2(fd: *[2]i32, flags: u32) usize {
542 comptime assert(i32.bit_count == c_int.bit_count);
543 return errnoWrap(c.pipe2(@ptrCast(*[2]c_int, fd), flags));
544}
545
546pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize {
547 return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte));
548}
549
550pub fn pwrite(fd: i32, buf: [*]const u8, nbyte: usize, offset: u64) usize {
551 return errnoWrap(c.pwrite(fd, @ptrCast(*const c_void, buf), nbyte, offset));
552}
553
554pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize {
555 return errnoWrap(c.pwritev(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset));
556}
557
558pub fn rename(old: [*]const u8, new: [*]const u8) usize {
559 return errnoWrap(c.rename(old, new));
560}
561
562pub fn open(path: [*]const u8, flags: u32, mode: usize) usize {
563 return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
564}
565
566pub fn create(path: [*]const u8, perm: usize) usize {
567 return arch.syscall2(SYS_creat, @ptrToInt(path), perm);
568}
569
570pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {
571 return errnoWrap(c.openat(@bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode));
572}
573
574pub fn close(fd: i32) usize {
575 return errnoWrap(c.close(fd));
576}
577
578pub fn lseek(fd: i32, offset: isize, whence: c_int) usize {
579 return errnoWrap(c.lseek(fd, offset, whence));
580}
581
582pub fn exit(code: i32) noreturn {
583 c.exit(code);
584}
585
586pub fn kill(pid: i32, sig: i32) usize {
587 return errnoWrap(c.kill(pid, sig));
588}
589
590pub fn unlink(path: [*]const u8) usize {
591 return errnoWrap(c.unlink(path));
592}
593
594pub fn waitpid(pid: i32, status: *i32, options: u32) usize {
595 comptime assert(i32.bit_count == c_int.bit_count);
596 return errnoWrap(c.waitpid(pid, @ptrCast(*c_int, status), @bitCast(c_int, options)));
597}
598
599pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
600 return errnoWrap(c.nanosleep(req, rem));
601}
602
603pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
604 return errnoWrap(c.clock_gettime(clk_id, tp));
605}
606
607pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
608 return errnoWrap(c.clock_getres(clk_id, tp));
609}
610
611pub fn setuid(uid: u32) usize {
612 return errnoWrap(c.setuid(uid));
613}
614
615pub fn setgid(gid: u32) usize {
616 return errnoWrap(c.setgid(gid));
617}
618
619pub fn setreuid(ruid: u32, euid: u32) usize {
620 return errnoWrap(c.setreuid(ruid, euid));
621}
622
623pub fn setregid(rgid: u32, egid: u32) usize {
624 return errnoWrap(c.setregid(rgid, egid));
625}
626
627const NSIG = 32;
628
629pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
630pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
631pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
632
633/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
634pub const Sigaction = extern struct {
635 /// signal handler
636 __sigaction_u: extern union {
637 __sa_handler: extern fn (i32) void,
638 __sa_sigaction: extern fn (i32, *__siginfo, usize) void,
639 },
640
641 /// see signal options
642 sa_flags: u32,
643
644 /// signal mask to apply
645 sa_mask: sigset_t,
646};
647
648pub const _SIG_WORDS = 4;
649pub const _SIG_MAXSIG = 128;
650
651pub inline fn _SIG_IDX(sig: usize) usize {
652 return sig - 1;
653}
654pub inline fn _SIG_WORD(sig: usize) usize {
655 return_SIG_IDX(sig) >> 5;
656}
657pub inline fn _SIG_BIT(sig: usize) usize {
658 return 1 << (_SIG_IDX(sig) & 31);
659}
660pub inline fn _SIG_VALID(sig: usize) usize {
661 return sig <= _SIG_MAXSIG and sig > 0;
662}
663
664pub const sigset_t = extern struct {
665 __bits: [_SIG_WORDS]u32,
666};
667
668pub fn raise(sig: i32) usize {
669 return errnoWrap(c.raise(sig));
670}
671
672pub const Stat = c.Stat;
673pub const dirent = c.dirent;
674pub const timespec = c.timespec;
675
676pub fn fstat(fd: i32, buf: *c.Stat) usize {
677 return errnoWrap(c.fstat(fd, buf));
678}
679pub const iovec = extern struct {
680 iov_base: [*]u8,
681 iov_len: usize,
682};
683
684pub const iovec_const = extern struct {
685 iov_base: [*]const u8,
686 iov_len: usize,
687};
688
689// TODO avoid libc dependency
690pub fn kqueue() usize {
691 return errnoWrap(c.kqueue());
692}
693
694// TODO avoid libc dependency
695pub fn kevent(kq: i32, changelist: []const Kevent, eventlist: []Kevent, timeout: ?*const timespec) usize {
696 return errnoWrap(c.kevent(
697 kq,
698 changelist.ptr,
699 @intCast(c_int, changelist.len),
700 eventlist.ptr,
701 @intCast(c_int, eventlist.len),
702 timeout,
703 ));
704}
705
706// TODO avoid libc dependency
707pub fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize {
708 return errnoWrap(c.sysctl(name, namelen, oldp, oldlenp, newp, newlen));
709}
710
711// TODO avoid libc dependency
712pub fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize {
713 return errnoWrap(c.sysctlbyname(name, oldp, oldlenp, newp, newlen));
714}
715
716// TODO avoid libc dependency
717pub fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) usize {
718 return errnoWrap(c.sysctlnametomib(name, wibp, sizep));
719}
720
721// TODO avoid libc dependency
722
723/// Takes the return value from a syscall and formats it back in the way
724/// that the kernel represents it to libc. Errno was a mistake, let's make
725/// it go away forever.
726fn errnoWrap(value: isize) usize {
727 return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value);
728}
std/os/path.zig+2-2
...@@ -1226,7 +1226,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro...@@ -1226,7 +1226,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro
1226 const pathname_w = try windows_util.cStrToPrefixedFileW(pathname);1226 const pathname_w = try windows_util.cStrToPrefixedFileW(pathname);
1227 return realW(out_buffer, pathname_w);1227 return realW(out_buffer, pathname_w);
1228 },1228 },
1229 Os.freebsd, Os.macosx, Os.ios => {1229 Os.freebsd, Os.netbsd, Os.macosx, Os.ios => {
1230 // TODO instead of calling the libc function here, port the implementation to Zig1230 // TODO instead of calling the libc function here, port the implementation to Zig
1231 const err = posix.getErrno(posix.realpath(pathname, out_buffer));1231 const err = posix.getErrno(posix.realpath(pathname, out_buffer));
1232 switch (err) {1232 switch (err) {
...@@ -1267,7 +1267,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError!...@@ -1267,7 +1267,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError!
1267 const pathname_w = try windows_util.sliceToPrefixedFileW(pathname);1267 const pathname_w = try windows_util.sliceToPrefixedFileW(pathname);
1268 return realW(out_buffer, &pathname_w);1268 return realW(out_buffer, &pathname_w);
1269 },1269 },
1270 Os.macosx, Os.ios, Os.linux, Os.freebsd => {1270 Os.macosx, Os.ios, Os.linux, Os.freebsd, Os.netbsd => {
1271 const pathname_c = try os.toPosixPath(pathname);1271 const pathname_c = try os.toPosixPath(pathname);
1272 return realC(out_buffer, &pathname_c);1272 return realC(out_buffer, &pathname_c);
1273 },1273 },
std/os/time.zig+5-5
...@@ -14,7 +14,7 @@ pub const epoch = @import("epoch.zig");...@@ -14,7 +14,7 @@ pub const epoch = @import("epoch.zig");
14/// Sleep for the specified duration14/// Sleep for the specified duration
15pub fn sleep(nanoseconds: u64) void {15pub fn sleep(nanoseconds: u64) void {
16 switch (builtin.os) {16 switch (builtin.os) {
17 Os.linux, Os.macosx, Os.ios, Os.freebsd => {17 Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
18 const s = nanoseconds / ns_per_s;18 const s = nanoseconds / ns_per_s;
19 const ns = nanoseconds % ns_per_s;19 const ns = nanoseconds % ns_per_s;
20 posixSleep(@intCast(u63, s), @intCast(u63, ns));20 posixSleep(@intCast(u63, s), @intCast(u63, ns));
...@@ -62,7 +62,7 @@ pub fn timestamp() u64 {...@@ -62,7 +62,7 @@ pub fn timestamp() u64 {
62/// Get the posix timestamp, UTC, in milliseconds62/// Get the posix timestamp, UTC, in milliseconds
63pub const milliTimestamp = switch (builtin.os) {63pub const milliTimestamp = switch (builtin.os) {
64 Os.windows => milliTimestampWindows,64 Os.windows => milliTimestampWindows,
65 Os.linux, Os.freebsd => milliTimestampPosix,65 Os.linux, Os.freebsd, Os.netbsd => milliTimestampPosix,
66 Os.macosx, Os.ios => milliTimestampDarwin,66 Os.macosx, Os.ios => milliTimestampDarwin,
67 else => @compileError("Unsupported OS"),67 else => @compileError("Unsupported OS"),
68};68};
...@@ -178,7 +178,7 @@ pub const Timer = struct {...@@ -178,7 +178,7 @@ pub const Timer = struct {
178 debug.assert(err != windows.FALSE);178 debug.assert(err != windows.FALSE);
179 self.start_time = @intCast(u64, start_time);179 self.start_time = @intCast(u64, start_time);
180 },180 },
181 Os.linux, Os.freebsd => {181 Os.linux, Os.freebsd, Os.netbsd => {
182 //On Linux, seccomp can do arbitrary things to our ability to call182 //On Linux, seccomp can do arbitrary things to our ability to call
183 // syscalls, including return any errno value it wants and183 // syscalls, including return any errno value it wants and
184 // inconsistently throwing errors. Since we can't account for184 // inconsistently throwing errors. Since we can't account for
...@@ -214,7 +214,7 @@ pub const Timer = struct {...@@ -214,7 +214,7 @@ pub const Timer = struct {
214 var clock = clockNative() - self.start_time;214 var clock = clockNative() - self.start_time;
215 return switch (builtin.os) {215 return switch (builtin.os) {
216 Os.windows => @divFloor(clock * ns_per_s, self.frequency),216 Os.windows => @divFloor(clock * ns_per_s, self.frequency),
217 Os.linux, Os.freebsd => clock,217 Os.linux, Os.freebsd, Os.netbsd => clock,
218 Os.macosx, Os.ios => @divFloor(clock * self.frequency.numer, self.frequency.denom),218 Os.macosx, Os.ios => @divFloor(clock * self.frequency.numer, self.frequency.denom),
219 else => @compileError("Unsupported OS"),219 else => @compileError("Unsupported OS"),
220 };220 };
...@@ -235,7 +235,7 @@ pub const Timer = struct {...@@ -235,7 +235,7 @@ pub const Timer = struct {
235235
236 const clockNative = switch (builtin.os) {236 const clockNative = switch (builtin.os) {
237 Os.windows => clockWindows,237 Os.windows => clockWindows,
238 Os.linux, Os.freebsd => clockLinux,238 Os.linux, Os.freebsd, Os.netbsd => clockLinux,
239 Os.macosx, Os.ios => clockDarwin,239 Os.macosx, Os.ios => clockDarwin,
240 else => @compileError("Unsupported OS"),240 else => @compileError("Unsupported OS"),
241 };241 };