authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-11-19 17:24:41-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-11-19 17:24:41-05:00
log9493738e5448ca166344a2d57abc44b29bb00081
tree9721b3e694e45f17ba21c0884759fba31fe0e1de
parent703c6684d103f14193411b589eaa0e0b1e1189f0
parentf3bc1c38bfb35cd588048f248c69100eaf709a4f
signature Commit is signed but in an unrecognized format.

Merge branch 'freebsd-up' of https://github.com/myfreeweb/zig into freebsd2


30 files changed, 1757 insertions(+), 67 deletions(-)

CMakeLists.txt+5
...@@ -444,6 +444,7 @@ set(ZIG_STD_FILES...@@ -444,6 +444,7 @@ set(ZIG_STD_FILES
444 "buffer.zig"444 "buffer.zig"
445 "build.zig"445 "build.zig"
446 "c/darwin.zig"446 "c/darwin.zig"
447 "c/freebsd.zig"
447 "c/index.zig"448 "c/index.zig"
448 "c/linux.zig"449 "c/linux.zig"
449 "c/windows.zig"450 "c/windows.zig"
...@@ -582,6 +583,10 @@ set(ZIG_STD_FILES...@@ -582,6 +583,10 @@ set(ZIG_STD_FILES
582 "os/linux/vdso.zig"583 "os/linux/vdso.zig"
583 "os/linux/x86_64.zig"584 "os/linux/x86_64.zig"
584 "os/linux/arm64.zig"585 "os/linux/arm64.zig"
586 "os/freebsd/errno.zig"
587 "os/freebsd/index.zig"
588 "os/freebsd/syscall.zig"
589 "os/freebsd/x86_64.zig"
585 "os/path.zig"590 "os/path.zig"
586 "os/time.zig"591 "os/time.zig"
587 "os/windows/advapi32.zig"592 "os/windows/advapi32.zig"
build.zig+1-1
...@@ -297,7 +297,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {...@@ -297,7 +297,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
297 );297 );
298298
299 exe.linkSystemLibrary("pthread");299 exe.linkSystemLibrary("pthread");
300 } else if (exe.target.isDarwin()) {300 } else if (exe.target.isDarwin() or exe.target.isFreeBSD()) {
301 if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "")) {301 if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "")) {
302 // Compiler is GCC.302 // Compiler is GCC.
303 try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null);303 try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null);
cmake/Findclang.cmake+2
...@@ -30,6 +30,7 @@ else()...@@ -30,6 +30,7 @@ else()
30 /usr/lib/llvm/7/include30 /usr/lib/llvm/7/include
31 /usr/lib/llvm-7/include31 /usr/lib/llvm-7/include
32 /usr/lib/llvm-7.0/include32 /usr/lib/llvm-7.0/include
33 /usr/local/llvm70/include
33 /mingw64/include)34 /mingw64/include)
3435
35 macro(FIND_AND_ADD_CLANG_LIB _libname_)36 macro(FIND_AND_ADD_CLANG_LIB _libname_)
...@@ -40,6 +41,7 @@ else()...@@ -40,6 +41,7 @@ else()
40 /usr/lib/llvm/7/lib41 /usr/lib/llvm/7/lib
41 /usr/lib/llvm-7/lib42 /usr/lib/llvm-7/lib
42 /usr/lib/llvm-7.0/lib43 /usr/lib/llvm-7.0/lib
44 /usr/local/llvm70/lib
43 /mingw64/lib45 /mingw64/lib
44 /c/msys64/mingw64/lib46 /c/msys64/mingw64/lib
45 c:\\msys64\\mingw64\\lib)47 c:\\msys64\\mingw64\\lib)
cmake/Findlld.cmake+6-1
...@@ -9,9 +9,13 @@...@@ -9,9 +9,13 @@
9find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h9find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
10 PATHS10 PATHS
11 /usr/lib/llvm-6.0/include11 /usr/lib/llvm-6.0/include
12 /usr/local/llvm60/include
12 /mingw64/include)13 /mingw64/include)
1314
14find_library(LLD_LIBRARY NAMES lld-6.0 lld PATHS /usr/lib/llvm-6.0/lib)15find_library(LLD_LIBRARY NAMES lld-6.0 lld60 lld
16 PATHS
17 /usr/lib/llvm-6.0/lib
18 /usr/local/llvm70/lib)
15if(EXISTS ${LLD_LIBRARY})19if(EXISTS ${LLD_LIBRARY})
16 set(LLD_LIBRARIES ${LLD_LIBRARY})20 set(LLD_LIBRARIES ${LLD_LIBRARY})
17else()21else()
...@@ -20,6 +24,7 @@ else()...@@ -20,6 +24,7 @@ else()
20 find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_}24 find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_}
21 PATHS25 PATHS
22 /usr/lib/llvm-6.0/lib26 /usr/lib/llvm-6.0/lib
27 /usr/local/llvm70/lib
23 /mingw64/lib28 /mingw64/lib
24 /c/msys64/mingw64/lib29 /c/msys64/mingw64/lib
25 c:/msys64/mingw64/lib)30 c:/msys64/mingw64/lib)
cmake/Findllvm.cmake+1-1
...@@ -8,7 +8,7 @@...@@ -8,7 +8,7 @@
8# LLVM_LIBDIRS8# LLVM_LIBDIRS
99
10find_program(LLVM_CONFIG_EXE10find_program(LLVM_CONFIG_EXE
11 NAMES llvm-config-7 llvm-config-7.0 llvm-config11 NAMES llvm-config-7 llvm-config-7.0 llvm-config70 llvm-config
12 PATHS12 PATHS
13 "/mingw64/bin"13 "/mingw64/bin"
14 "/c/msys64/mingw64/bin"14 "/c/msys64/mingw64/bin"
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 => {175 builtin.Os.macosx, builtin.Os.freebsd => {
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-self-hosted/target.zig+8-1
...@@ -299,6 +299,13 @@ pub const Target = union(enum) {...@@ -299,6 +299,13 @@ pub const Target = union(enum) {
299 pub fn getDynamicLinkerPath(self: Target) ?[]const u8 {299 pub fn getDynamicLinkerPath(self: Target) ?[]const u8 {
300 const env = self.getEnviron();300 const env = self.getEnviron();
301 const arch = self.getArch();301 const arch = self.getArch();
302 const os = self.getOs();
303 switch (os) {
304 builtin.Os.freebsd => {
305 return "/libexec/ld-elf.so.1";
306 },
307 else => {},
308 }
302 switch (env) {309 switch (env) {
303 builtin.Environ.android => {310 builtin.Environ.android => {
304 if (self.is64bit()) {311 if (self.is64bit()) {
...@@ -493,6 +500,7 @@ pub const Target = union(enum) {...@@ -493,6 +500,7 @@ pub const Target = union(enum) {
493500
494 builtin.Os.linux,501 builtin.Os.linux,
495 builtin.Os.macosx,502 builtin.Os.macosx,
503 builtin.Os.freebsd,
496 builtin.Os.openbsd,504 builtin.Os.openbsd,
497 builtin.Os.zen,505 builtin.Os.zen,
498 => switch (id) {506 => switch (id) {
...@@ -527,7 +535,6 @@ pub const Target = union(enum) {...@@ -527,7 +535,6 @@ pub const Target = union(enum) {
527 builtin.Os.ananas,535 builtin.Os.ananas,
528 builtin.Os.cloudabi,536 builtin.Os.cloudabi,
529 builtin.Os.dragonfly,537 builtin.Os.dragonfly,
530 builtin.Os.freebsd,
531 builtin.Os.fuchsia,538 builtin.Os.fuchsia,
532 builtin.Os.ios,539 builtin.Os.ios,
533 builtin.Os.kfreebsd,540 builtin.Os.kfreebsd,
src/analyze.cpp+8-1
...@@ -4579,7 +4579,10 @@ void find_libc_include_path(CodeGen *g) {...@@ -4579,7 +4579,10 @@ void find_libc_include_path(CodeGen *g) {
4579 fprintf(stderr, "Unable to determine libc include path. --libc-include-dir");4579 fprintf(stderr, "Unable to determine libc include path. --libc-include-dir");
4580 exit(1);4580 exit(1);
4581 }4581 }
4582 } else if (g->zig_target.os == OsLinux || g->zig_target.os == OsMacOSX) {4582 } else if (g->zig_target.os == OsLinux ||
4583 g->zig_target.os == OsMacOSX ||
4584 g->zig_target.os == OsFreeBSD)
4585 {
4583 g->libc_include_dir = get_posix_libc_include_path();4586 g->libc_include_dir = get_posix_libc_include_path();
4584 } else {4587 } else {
4585 fprintf(stderr, "Unable to determine libc include path.\n"4588 fprintf(stderr, "Unable to determine libc include path.\n"
...@@ -4627,6 +4630,8 @@ void find_libc_lib_path(CodeGen *g) {...@@ -4627,6 +4630,8 @@ void find_libc_lib_path(CodeGen *g) {
46274630
4628 } else if (g->zig_target.os == OsLinux) {4631 } else if (g->zig_target.os == OsLinux) {
4629 g->libc_lib_dir = get_linux_libc_lib_path("crt1.o");4632 g->libc_lib_dir = get_linux_libc_lib_path("crt1.o");
4633 } else if (g->zig_target.os == OsFreeBSD) {
4634 g->libc_lib_dir = buf_create_from_str("/usr/lib");
4630 } else {4635 } else {
4631 zig_panic("Unable to determine libc lib path.");4636 zig_panic("Unable to determine libc lib path.");
4632 }4637 }
...@@ -4639,6 +4644,8 @@ void find_libc_lib_path(CodeGen *g) {...@@ -4639,6 +4644,8 @@ void find_libc_lib_path(CodeGen *g) {
4639 return;4644 return;
4640 } else if (g->zig_target.os == OsLinux) {4645 } else if (g->zig_target.os == OsLinux) {
4641 g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o");4646 g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o");
4647 } else if (g->zig_target.os == OsFreeBSD) {
4648 g->libc_static_lib_dir = buf_create_from_str("/usr/lib");
4642 } else {4649 } else {
4643 zig_panic("Unable to determine libc static lib path.");4650 zig_panic("Unable to determine libc static lib path.");
4644 }4651 }
src/link.cpp+7
...@@ -150,6 +150,10 @@ static const char *getLDMOption(const ZigTarget *t) {...@@ -150,6 +150,10 @@ static const char *getLDMOption(const ZigTarget *t) {
150 if (t->env_type == ZigLLVM_GNUX32) {150 if (t->env_type == ZigLLVM_GNUX32) {
151 return "elf32_x86_64";151 return "elf32_x86_64";
152 }152 }
153 // Any target elf will use the freebsd osabi if suffixed with "_fbsd".
154 if (t->os == OsFreeBSD) {
155 return "elf_x86_64_fbsd";
156 }
153 return "elf_x86_64";157 return "elf_x86_64";
154 default:158 default:
155 zig_unreachable();159 zig_unreachable();
...@@ -191,6 +195,9 @@ static Buf *try_dynamic_linker_path(const char *ld_name) {...@@ -191,6 +195,9 @@ static Buf *try_dynamic_linker_path(const char *ld_name) {
191}195}
192196
193static Buf *get_dynamic_linker_path(CodeGen *g) {197static Buf *get_dynamic_linker_path(CodeGen *g) {
198 if (g->zig_target.os == OsFreeBSD) {
199 return buf_create_from_str("/libexec/ld-elf.so.1");
200 }
194 if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) {201 if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) {
195 static const char *ld_names[] = {202 static const char *ld_names[] = {
196 "ld-linux-x86-64.so.2",203 "ld-linux-x86-64.so.2",
src/os.cpp+20-6
...@@ -50,10 +50,13 @@ typedef SSIZE_T ssize_t;...@@ -50,10 +50,13 @@ typedef SSIZE_T ssize_t;
5050
51#endif51#endif
5252
53#if defined(ZIG_OS_LINUX)53#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)
54#include <link.h>54#include <link.h>
55#endif55#endif
5656
57#if defined(ZIG_OS_FREEBSD)
58#include <sys/sysctl.h>
59#endif
5760
58#if defined(__MACH__)61#if defined(__MACH__)
59#include <mach/clock.h>62#include <mach/clock.h>
...@@ -75,7 +78,9 @@ static clock_serv_t cclock;...@@ -75,7 +78,9 @@ static clock_serv_t cclock;
75#if defined(__APPLE__) && !defined(environ)78#if defined(__APPLE__) && !defined(environ)
76#include <crt_externs.h>79#include <crt_externs.h>
77#define environ (*_NSGetEnviron())80#define environ (*_NSGetEnviron())
78#endif 81#elif defined(ZIG_OS_FREEBSD)
82extern char **environ;
83#endif
7984
80#if defined(ZIG_OS_POSIX)85#if defined(ZIG_OS_POSIX)
81static void populate_termination(Termination *term, int status) {86static void populate_termination(Termination *term, int status) {
...@@ -1438,6 +1443,15 @@ Error os_self_exe_path(Buf *out_path) {...@@ -1438,6 +1443,15 @@ Error os_self_exe_path(Buf *out_path) {
1438 }1443 }
1439 buf_resize(out_path, amt);1444 buf_resize(out_path, amt);
1440 return ErrorNone;1445 return ErrorNone;
1446#elif defined(ZIG_OS_FREEBSD)
1447 buf_resize(out_path, PATH_MAX);
1448 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
1449 size_t cb = PATH_MAX;
1450 if (sysctl(mib, 4, buf_ptr(out_path), &cb, nullptr, 0) != 0) {
1451 return ErrorUnexpected;
1452 }
1453 buf_resize(out_path, cb);
1454 return ErrorNone;
1441#endif1455#endif
1442 return ErrorFileNotFound;1456 return ErrorFileNotFound;
1443}1457}
...@@ -1743,7 +1757,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {...@@ -1743,7 +1757,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {
1743 buf_resize(out_path, 0);1757 buf_resize(out_path, 0);
1744 buf_appendf(out_path, "%s/Library/Application Support/%s", home_dir, appname);1758 buf_appendf(out_path, "%s/Library/Application Support/%s", home_dir, appname);
1745 return ErrorNone;1759 return ErrorNone;
1746#elif defined(ZIG_OS_LINUX)1760#elif defined(ZIG_OS_POSIX)
1747 const char *home_dir = getenv("HOME");1761 const char *home_dir = getenv("HOME");
1748 if (home_dir == nullptr) {1762 if (home_dir == nullptr) {
1749 // TODO use /etc/passwd1763 // TODO use /etc/passwd
...@@ -1756,7 +1770,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {...@@ -1756,7 +1770,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {
1756}1770}
17571771
17581772
1759#if defined(ZIG_OS_LINUX)1773#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)
1760static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) {1774static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) {
1761 ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data);1775 ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data);
1762 if (info->dlpi_name[0] == '/') {1776 if (info->dlpi_name[0] == '/') {
...@@ -1767,7 +1781,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size,...@@ -1767,7 +1781,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size,
1767#endif1781#endif
17681782
1769Error os_self_exe_shared_libs(ZigList<Buf *> &paths) {1783Error os_self_exe_shared_libs(ZigList<Buf *> &paths) {
1770#if defined(ZIG_OS_LINUX)1784#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)
1771 paths.resize(0);1785 paths.resize(0);
1772 dl_iterate_phdr(self_exe_shared_libs_callback, &paths);1786 dl_iterate_phdr(self_exe_shared_libs_callback, &paths);
1773 return ErrorNone;1787 return ErrorNone;
...@@ -1936,7 +1950,7 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) {...@@ -1936,7 +1950,7 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) {
1936 mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime;1950 mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime;
1937 mtime->nsec = 0;1951 mtime->nsec = 0;
1938 return ErrorNone;1952 return ErrorNone;
1939#elif defined(ZIG_OS_LINUX)1953#elif defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD)
1940 struct stat statbuf;1954 struct stat statbuf;
1941 if (fstat(file, &statbuf) == -1)1955 if (fstat(file, &statbuf) == -1)
1942 return ErrorFileSystem;1956 return ErrorFileSystem;
src/os.hpp+2
...@@ -23,6 +23,8 @@...@@ -23,6 +23,8 @@
23#define ZIG_OS_WINDOWS23#define ZIG_OS_WINDOWS
24#elif defined(__linux__)24#elif defined(__linux__)
25#define ZIG_OS_LINUX25#define ZIG_OS_LINUX
26#elif defined(__FreeBSD__)
27#define ZIG_OS_FREEBSD
26#else28#else
27#define ZIG_OS_UNKNOWN29#define ZIG_OS_UNKNOWN
28#endif30#endif
src/target.cpp+1-1
...@@ -738,6 +738,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -738,6 +738,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
738 case OsLinux:738 case OsLinux:
739 case OsMacOSX:739 case OsMacOSX:
740 case OsZen:740 case OsZen:
741 case OsFreeBSD:
741 case OsOpenBSD:742 case OsOpenBSD:
742 switch (id) {743 switch (id) {
743 case CIntTypeShort:744 case CIntTypeShort:
...@@ -774,7 +775,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -774,7 +775,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
774 case OsAnanas:775 case OsAnanas:
775 case OsCloudABI:776 case OsCloudABI:
776 case OsDragonFly:777 case OsDragonFly:
777 case OsFreeBSD:
778 case OsIOS:778 case OsIOS:
779 case OsKFreeBSD:779 case OsKFreeBSD:
780 case OsLv2:780 case OsLv2:
src/util.cpp+1-1
...@@ -47,7 +47,7 @@ bool ptr_eq(const void *a, const void *b) {...@@ -47,7 +47,7 @@ bool ptr_eq(const void *a, const void *b) {
47// Ported from std/mem.zig.47// Ported from std/mem.zig.
48bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte) {48bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte) {
49 for (size_t i = 0; i < self->split_bytes.len; i += 1) {49 for (size_t i = 0; i < self->split_bytes.len; i += 1) {
50 if (byte == self->split_bytes.ptr[i]) {50 if (byte == self->split_bytes.ptr[i] || byte == 0) {
51 return true;51 return true;
52 }52 }
53 }53 }
std/build.zig+7
...@@ -795,6 +795,13 @@ pub const Target = union(enum) {...@@ -795,6 +795,13 @@ pub const Target = union(enum) {
795 };795 };
796 }796 }
797797
798 pub fn isFreeBSD(self: *const Target) bool {
799 return switch (self.getOs()) {
800 builtin.Os.freebsd => true,
801 else => false,
802 };
803 }
804
798 pub fn wantSharedLibSymLinks(self: *const Target) bool {805 pub fn wantSharedLibSymLinks(self: *const Target) bool {
799 return !self.isWindows();806 return !self.isWindows();
800 }807 }
std/c/freebsd.zig created+36
...@@ -0,0 +1,36 @@
1
2const timespec = @import("../os/freebsd/index.zig").timespec;
3
4extern "c" fn __error() *c_int;
5pub const _errno = __error;
6
7pub extern "c" fn kqueue() c_int;
8pub extern "c" fn kevent(
9 kq: c_int,
10 changelist: [*]const Kevent,
11 nchanges: c_int,
12 eventlist: [*]Kevent,
13 nevents: c_int,
14 timeout: ?*const timespec,
15) c_int;
16pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
17pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
18pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
19
20/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
21pub const Kevent = extern struct.{
22 ident: usize,
23 filter: i16,
24 flags: u16,
25 fflags: u32,
26 data: i64,
27 udata: usize,
28 // TODO ext
29};
30
31
32pub const pthread_attr_t = extern struct.{
33 __size: [56]u8,
34 __align: c_long,
35};
36
std/c/index.zig+1
...@@ -5,6 +5,7 @@ pub use switch (builtin.os) {...@@ -5,6 +5,7 @@ pub use switch (builtin.os) {
5 Os.linux => @import("linux.zig"),5 Os.linux => @import("linux.zig"),
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 else => empty_import,9 else => empty_import,
9};10};
10const empty_import = @import("../empty.zig");11const empty_import = @import("../empty.zig");
std/debug/index.zig+2
...@@ -1101,6 +1101,8 @@ pub const DebugInfo = switch (builtin.os) {...@@ -1101,6 +1101,8 @@ pub const DebugInfo = switch (builtin.os) {
1101 self.elf.close();1101 self.elf.close();
1102 }1102 }
1103 },1103 },
1104 builtin.Os.freebsd => struct.{
1105 },
1104 else => @compileError("Unsupported OS"),1106 else => @compileError("Unsupported OS"),
1105};1107};
11061108
std/event/fs.zig+21-10
...@@ -83,6 +83,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o...@@ -83,6 +83,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o
83 switch (builtin.os) {83 switch (builtin.os) {
84 builtin.Os.macosx,84 builtin.Os.macosx,
85 builtin.Os.linux,85 builtin.Os.linux,
86 builtin.Os.freebsd,
86 => {87 => {
87 const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len);88 const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len);
88 defer loop.allocator.free(iovecs);89 defer loop.allocator.free(iovecs);
...@@ -219,6 +220,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset:...@@ -219,6 +220,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset:
219 switch (builtin.os) {220 switch (builtin.os) {
220 builtin.Os.macosx,221 builtin.Os.macosx,
221 builtin.Os.linux,222 builtin.Os.linux,
223 builtin.Os.freebsd,
222 => {224 => {
223 const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len);225 const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len);
224 defer loop.allocator.free(iovecs);226 defer loop.allocator.free(iovecs);
...@@ -399,7 +401,7 @@ pub async fn openPosix(...@@ -399,7 +401,7 @@ pub async fn openPosix(
399401
400pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle {402pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle {
401 switch (builtin.os) {403 switch (builtin.os) {
402 builtin.Os.macosx, builtin.Os.linux => {404 builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => {
403 const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC;405 const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC;
404 return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);406 return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);
405 },407 },
...@@ -427,6 +429,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os...@@ -427,6 +429,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os
427 switch (builtin.os) {429 switch (builtin.os) {
428 builtin.Os.macosx,430 builtin.Os.macosx,
429 builtin.Os.linux,431 builtin.Os.linux,
432 builtin.Os.freebsd,
430 => {433 => {
431 const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC;434 const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC;
432 return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);435 return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);
...@@ -449,7 +452,7 @@ pub async fn openReadWrite(...@@ -449,7 +452,7 @@ pub async fn openReadWrite(
449 mode: os.File.Mode,452 mode: os.File.Mode,
450) os.File.OpenError!os.FileHandle {453) os.File.OpenError!os.FileHandle {
451 switch (builtin.os) {454 switch (builtin.os) {
452 builtin.Os.macosx, builtin.Os.linux => {455 builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => {
453 const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC;456 const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC;
454 return await (async openPosix(loop, path, flags, mode) catch unreachable);457 return await (async openPosix(loop, path, flags, mode) catch unreachable);
455 },458 },
...@@ -477,7 +480,7 @@ pub const CloseOperation = struct {...@@ -477,7 +480,7 @@ pub const CloseOperation = struct {
477 os_data: OsData,480 os_data: OsData,
478481
479 const OsData = switch (builtin.os) {482 const OsData = switch (builtin.os) {
480 builtin.Os.linux, builtin.Os.macosx => OsDataPosix,483 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => OsDataPosix,
481484
482 builtin.Os.windows => struct {485 builtin.Os.windows => struct {
483 handle: ?os.FileHandle,486 handle: ?os.FileHandle,
...@@ -496,7 +499,7 @@ pub const CloseOperation = struct {...@@ -496,7 +499,7 @@ pub const CloseOperation = struct {
496 self.* = CloseOperation{499 self.* = CloseOperation{
497 .loop = loop,500 .loop = loop,
498 .os_data = switch (builtin.os) {501 .os_data = switch (builtin.os) {
499 builtin.Os.linux, builtin.Os.macosx => initOsDataPosix(self),502 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => initOsDataPosix(self),
500 builtin.Os.windows => OsData{ .handle = null },503 builtin.Os.windows => OsData{ .handle = null },
501 else => @compileError("Unsupported OS"),504 else => @compileError("Unsupported OS"),
502 },505 },
...@@ -525,6 +528,7 @@ pub const CloseOperation = struct {...@@ -525,6 +528,7 @@ pub const CloseOperation = struct {
525 switch (builtin.os) {528 switch (builtin.os) {
526 builtin.Os.linux,529 builtin.Os.linux,
527 builtin.Os.macosx,530 builtin.Os.macosx,
531 builtin.Os.freebsd,
528 => {532 => {
529 if (self.os_data.have_fd) {533 if (self.os_data.have_fd) {
530 self.loop.posixFsRequest(&self.os_data.close_req_node);534 self.loop.posixFsRequest(&self.os_data.close_req_node);
...@@ -546,6 +550,7 @@ pub const CloseOperation = struct {...@@ -546,6 +550,7 @@ pub const CloseOperation = struct {
546 switch (builtin.os) {550 switch (builtin.os) {
547 builtin.Os.linux,551 builtin.Os.linux,
548 builtin.Os.macosx,552 builtin.Os.macosx,
553 builtin.Os.freebsd,
549 => {554 => {
550 self.os_data.close_req_node.data.msg.Close.fd = handle;555 self.os_data.close_req_node.data.msg.Close.fd = handle;
551 self.os_data.have_fd = true;556 self.os_data.have_fd = true;
...@@ -562,6 +567,7 @@ pub const CloseOperation = struct {...@@ -562,6 +567,7 @@ pub const CloseOperation = struct {
562 switch (builtin.os) {567 switch (builtin.os) {
563 builtin.Os.linux,568 builtin.Os.linux,
564 builtin.Os.macosx,569 builtin.Os.macosx,
570 builtin.Os.freebsd,
565 => {571 => {
566 self.os_data.have_fd = false;572 self.os_data.have_fd = false;
567 },573 },
...@@ -576,6 +582,7 @@ pub const CloseOperation = struct {...@@ -576,6 +582,7 @@ pub const CloseOperation = struct {
576 switch (builtin.os) {582 switch (builtin.os) {
577 builtin.Os.linux,583 builtin.Os.linux,
578 builtin.Os.macosx,584 builtin.Os.macosx,
585 builtin.Os.freebsd,
579 => {586 => {
580 assert(self.os_data.have_fd);587 assert(self.os_data.have_fd);
581 return self.os_data.close_req_node.data.msg.Close.fd;588 return self.os_data.close_req_node.data.msg.Close.fd;
...@@ -599,6 +606,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8,...@@ -599,6 +606,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8,
599 switch (builtin.os) {606 switch (builtin.os) {
600 builtin.Os.linux,607 builtin.Os.linux,
601 builtin.Os.macosx,608 builtin.Os.macosx,
609 builtin.Os.freebsd,
602 => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable),610 => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable),
603 builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable),611 builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable),
604 else => @compileError("Unsupported OS"),612 else => @compileError("Unsupported OS"),
...@@ -704,7 +712,7 @@ pub fn Watch(comptime V: type) type {...@@ -704,7 +712,7 @@ pub fn Watch(comptime V: type) type {
704 os_data: OsData,712 os_data: OsData,
705713
706 const OsData = switch (builtin.os) {714 const OsData = switch (builtin.os) {
707 builtin.Os.macosx => struct {715 builtin.Os.macosx, builtin.Os.freebsd => struct {
708 file_table: FileTable,716 file_table: FileTable,
709 table_lock: event.Lock,717 table_lock: event.Lock,
710718
...@@ -793,7 +801,7 @@ pub fn Watch(comptime V: type) type {...@@ -793,7 +801,7 @@ pub fn Watch(comptime V: type) type {
793 return self;801 return self;
794 },802 },
795803
796 builtin.Os.macosx => {804 builtin.Os.macosx, builtin.Os.freebsd => {
797 const self = try loop.allocator.createOne(Self);805 const self = try loop.allocator.createOne(Self);
798 errdefer loop.allocator.destroy(self);806 errdefer loop.allocator.destroy(self);
799807
...@@ -813,7 +821,7 @@ pub fn Watch(comptime V: type) type {...@@ -813,7 +821,7 @@ pub fn Watch(comptime V: type) type {
813 /// All addFile calls and removeFile calls must have completed.821 /// All addFile calls and removeFile calls must have completed.
814 pub fn destroy(self: *Self) void {822 pub fn destroy(self: *Self) void {
815 switch (builtin.os) {823 switch (builtin.os) {
816 builtin.Os.macosx => {824 builtin.Os.macosx, builtin.Os.freebsd => {
817 // TODO we need to cancel the coroutines before destroying the lock825 // TODO we need to cancel the coroutines before destroying the lock
818 self.os_data.table_lock.deinit();826 self.os_data.table_lock.deinit();
819 var it = self.os_data.file_table.iterator();827 var it = self.os_data.file_table.iterator();
...@@ -855,14 +863,14 @@ pub fn Watch(comptime V: type) type {...@@ -855,14 +863,14 @@ pub fn Watch(comptime V: type) type {
855863
856 pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V {864 pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V {
857 switch (builtin.os) {865 switch (builtin.os) {
858 builtin.Os.macosx => return await (async addFileMacosx(self, file_path, value) catch unreachable),866 builtin.Os.macosx, builtin.Os.freebsd => return await (async addFileKEvent(self, file_path, value) catch unreachable),
859 builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable),867 builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable),
860 builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable),868 builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable),
861 else => @compileError("Unsupported OS"),869 else => @compileError("Unsupported OS"),
862 }870 }
863 }871 }
864872
865 async fn addFileMacosx(self: *Self, file_path: []const u8, value: V) !?V {873 async fn addFileKEvent(self: *Self, file_path: []const u8, value: V) !?V {
866 const resolved_path = try os.path.resolve(self.channel.loop.allocator, file_path);874 const resolved_path = try os.path.resolve(self.channel.loop.allocator, file_path);
867 var resolved_path_consumed = false;875 var resolved_path_consumed = false;
868 defer if (!resolved_path_consumed) self.channel.loop.allocator.free(resolved_path);876 defer if (!resolved_path_consumed) self.channel.loop.allocator.free(resolved_path);
...@@ -871,7 +879,10 @@ pub fn Watch(comptime V: type) type {...@@ -871,7 +879,10 @@ pub fn Watch(comptime V: type) type {
871 var close_op_consumed = false;879 var close_op_consumed = false;
872 defer if (!close_op_consumed) close_op.finish();880 defer if (!close_op_consumed) close_op.finish();
873881
874 const flags = posix.O_SYMLINK | posix.O_EVTONLY;882 const flags = switch (builtin.os) {
883 builtin.Os.macosx => posix.O_SYMLINK | posix.O_EVTONLY,
884 else => 0,
885 };
875 const mode = 0;886 const mode = 0;
876 const fd = try await (async openPosix(self.channel.loop, resolved_path, flags, mode) catch unreachable);887 const fd = try await (async openPosix(self.channel.loop, resolved_path, flags, mode) catch unreachable);
877 close_op.setHandle(fd);888 close_op.setHandle(fd);
std/event/loop.zig+14-13
...@@ -49,7 +49,7 @@ pub const Loop = struct {...@@ -49,7 +49,7 @@ pub const Loop = struct {
49 };49 };
5050
51 pub const EventFd = switch (builtin.os) {51 pub const EventFd = switch (builtin.os) {
52 builtin.Os.macosx => MacOsEventFd,52 builtin.Os.macosx, builtin.Os.freebsd => KEventFd,
53 builtin.Os.linux => struct {53 builtin.Os.linux => struct {
54 base: ResumeNode,54 base: ResumeNode,
55 epoll_op: u32,55 epoll_op: u32,
...@@ -62,13 +62,13 @@ pub const Loop = struct {...@@ -62,13 +62,13 @@ pub const Loop = struct {
62 else => @compileError("unsupported OS"),62 else => @compileError("unsupported OS"),
63 };63 };
6464
65 const MacOsEventFd = struct {65 const KEventFd = struct {
66 base: ResumeNode,66 base: ResumeNode,
67 kevent: posix.Kevent,67 kevent: posix.Kevent,
68 };68 };
6969
70 pub const Basic = switch (builtin.os) {70 pub const Basic = switch (builtin.os) {
71 builtin.Os.macosx => MacOsBasic,71 builtin.Os.macosx, builtin.Os.freebsd => KEventBasic,
72 builtin.Os.linux => struct {72 builtin.Os.linux => struct {
73 base: ResumeNode,73 base: ResumeNode,
74 },74 },
...@@ -78,7 +78,7 @@ pub const Loop = struct {...@@ -78,7 +78,7 @@ pub const Loop = struct {
78 else => @compileError("unsupported OS"),78 else => @compileError("unsupported OS"),
79 };79 };
8080
81 const MacOsBasic = struct {81 const KEventBasic = struct {
82 base: ResumeNode,82 base: ResumeNode,
83 kev: posix.Kevent,83 kev: posix.Kevent,
84 };84 };
...@@ -214,7 +214,7 @@ pub const Loop = struct {...@@ -214,7 +214,7 @@ pub const Loop = struct {
214 self.extra_threads[extra_thread_index] = try os.spawnThread(self, workerRun);214 self.extra_threads[extra_thread_index] = try os.spawnThread(self, workerRun);
215 }215 }
216 },216 },
217 builtin.Os.macosx => {217 builtin.Os.macosx, builtin.Os.freebsd => {
218 self.os_data.kqfd = try os.bsdKQueue();218 self.os_data.kqfd = try os.bsdKQueue();
219 errdefer os.close(self.os_data.kqfd);219 errdefer os.close(self.os_data.kqfd);
220220
...@@ -369,7 +369,7 @@ pub const Loop = struct {...@@ -369,7 +369,7 @@ pub const Loop = struct {
369 os.close(self.os_data.epollfd);369 os.close(self.os_data.epollfd);
370 self.allocator.free(self.eventfd_resume_nodes);370 self.allocator.free(self.eventfd_resume_nodes);
371 },371 },
372 builtin.Os.macosx => {372 builtin.Os.macosx, builtin.Os.freebsd => {
373 os.close(self.os_data.kqfd);373 os.close(self.os_data.kqfd);
374 os.close(self.os_data.fs_kqfd);374 os.close(self.os_data.fs_kqfd);
375 },375 },
...@@ -484,7 +484,7 @@ pub const Loop = struct {...@@ -484,7 +484,7 @@ pub const Loop = struct {
484 const eventfd_node = &resume_stack_node.data;484 const eventfd_node = &resume_stack_node.data;
485 eventfd_node.base.handle = next_tick_node.data;485 eventfd_node.base.handle = next_tick_node.data;
486 switch (builtin.os) {486 switch (builtin.os) {
487 builtin.Os.macosx => {487 builtin.Os.macosx, builtin.Os.freebsd => {
488 const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent);488 const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent);
489 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];489 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
490 _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {490 _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {
...@@ -546,6 +546,7 @@ pub const Loop = struct {...@@ -546,6 +546,7 @@ pub const Loop = struct {
546 switch (builtin.os) {546 switch (builtin.os) {
547 builtin.Os.linux,547 builtin.Os.linux,
548 builtin.Os.macosx,548 builtin.Os.macosx,
549 builtin.Os.freebsd,
549 => self.os_data.fs_thread.wait(),550 => self.os_data.fs_thread.wait(),
550 else => {},551 else => {},
551 }552 }
...@@ -610,7 +611,7 @@ pub const Loop = struct {...@@ -610,7 +611,7 @@ pub const Loop = struct {
610 os.posixWrite(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;611 os.posixWrite(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
611 return;612 return;
612 },613 },
613 builtin.Os.macosx => {614 builtin.Os.macosx, builtin.Os.freebsd => {
614 self.posixFsRequest(&self.os_data.fs_end_request);615 self.posixFsRequest(&self.os_data.fs_end_request);
615 const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent);616 const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent);
616 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];617 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
...@@ -668,7 +669,7 @@ pub const Loop = struct {...@@ -668,7 +669,7 @@ pub const Loop = struct {
668 }669 }
669 }670 }
670 },671 },
671 builtin.Os.macosx => {672 builtin.Os.macosx, builtin.Os.freebsd => {
672 var eventlist: [1]posix.Kevent = undefined;673 var eventlist: [1]posix.Kevent = undefined;
673 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];674 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
674 const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;675 const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
...@@ -731,7 +732,7 @@ pub const Loop = struct {...@@ -731,7 +732,7 @@ pub const Loop = struct {
731 self.beginOneEvent(); // finished in posixFsRun after processing the msg732 self.beginOneEvent(); // finished in posixFsRun after processing the msg
732 self.os_data.fs_queue.put(request_node);733 self.os_data.fs_queue.put(request_node);
733 switch (builtin.os) {734 switch (builtin.os) {
734 builtin.Os.macosx => {735 builtin.Os.macosx, builtin.Os.freebsd => {
735 const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake);736 const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake);
736 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];737 const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
737 _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;738 _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
...@@ -801,7 +802,7 @@ pub const Loop = struct {...@@ -801,7 +802,7 @@ pub const Loop = struct {
801 else => unreachable,802 else => unreachable,
802 }803 }
803 },804 },
804 builtin.Os.macosx => {805 builtin.Os.macosx, builtin.Os.freebsd => {
805 const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait);806 const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait);
806 var out_kevs: [1]posix.Kevent = undefined;807 var out_kevs: [1]posix.Kevent = undefined;
807 _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;808 _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;
...@@ -813,7 +814,7 @@ pub const Loop = struct {...@@ -813,7 +814,7 @@ pub const Loop = struct {
813814
814 const OsData = switch (builtin.os) {815 const OsData = switch (builtin.os) {
815 builtin.Os.linux => LinuxOsData,816 builtin.Os.linux => LinuxOsData,
816 builtin.Os.macosx => MacOsData,817 builtin.Os.macosx, builtin.Os.freebsd => KEventData,
817 builtin.Os.windows => struct {818 builtin.Os.windows => struct {
818 io_port: windows.HANDLE,819 io_port: windows.HANDLE,
819 extra_thread_count: usize,820 extra_thread_count: usize,
...@@ -821,7 +822,7 @@ pub const Loop = struct {...@@ -821,7 +822,7 @@ pub const Loop = struct {
821 else => struct {},822 else => struct {},
822 };823 };
823824
824 const MacOsData = struct {825 const KEventData = struct {
825 kqfd: i32,826 kqfd: i32,
826 final_kevent: posix.Kevent,827 final_kevent: posix.Kevent,
827 fs_kevent_wake: posix.Kevent,828 fs_kevent_wake: posix.Kevent,
std/heap.zig+3-3
...@@ -70,7 +70,7 @@ pub const DirectAllocator = struct {...@@ -70,7 +70,7 @@ pub const DirectAllocator = struct {
70 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);70 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
7171
72 switch (builtin.os) {72 switch (builtin.os) {
73 Os.linux, Os.macosx, Os.ios => {73 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
74 const p = os.posix;74 const p = os.posix;
75 const alloc_size = if (alignment <= os.page_size) n else n + alignment;75 const alloc_size = if (alignment <= os.page_size) n else n + alignment;
76 const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);76 const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);
...@@ -121,7 +121,7 @@ pub const DirectAllocator = struct {...@@ -121,7 +121,7 @@ pub const DirectAllocator = struct {
121 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);121 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
122122
123 switch (builtin.os) {123 switch (builtin.os) {
124 Os.linux, Os.macosx, Os.ios => {124 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
125 if (new_size <= old_mem.len) {125 if (new_size <= old_mem.len) {
126 const base_addr = @ptrToInt(old_mem.ptr);126 const base_addr = @ptrToInt(old_mem.ptr);
127 const old_addr_end = base_addr + old_mem.len;127 const old_addr_end = base_addr + old_mem.len;
...@@ -166,7 +166,7 @@ pub const DirectAllocator = struct {...@@ -166,7 +166,7 @@ pub const DirectAllocator = struct {
166 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);166 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
167167
168 switch (builtin.os) {168 switch (builtin.os) {
169 Os.linux, Os.macosx, Os.ios => {169 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
170 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);170 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
171 },171 },
172 Os.windows => {172 Os.windows => {
std/os/file.zig+3-3
...@@ -230,7 +230,7 @@ pub const File = struct {...@@ -230,7 +230,7 @@ pub const File = struct {
230230
231 pub fn seekForward(self: File, amount: isize) !void {231 pub fn seekForward(self: File, amount: isize) !void {
232 switch (builtin.os) {232 switch (builtin.os) {
233 Os.linux, Os.macosx, Os.ios => {233 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
234 const result = posix.lseek(self.handle, amount, posix.SEEK_CUR);234 const result = posix.lseek(self.handle, amount, posix.SEEK_CUR);
235 const err = posix.getErrno(result);235 const err = posix.getErrno(result);
236 if (err > 0) {236 if (err > 0) {
...@@ -261,7 +261,7 @@ pub const File = struct {...@@ -261,7 +261,7 @@ pub const File = struct {
261261
262 pub fn seekTo(self: File, pos: usize) !void {262 pub fn seekTo(self: File, pos: usize) !void {
263 switch (builtin.os) {263 switch (builtin.os) {
264 Os.linux, Os.macosx, Os.ios => {264 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
265 const ipos = try math.cast(isize, pos);265 const ipos = try math.cast(isize, pos);
266 const result = posix.lseek(self.handle, ipos, posix.SEEK_SET);266 const result = posix.lseek(self.handle, ipos, posix.SEEK_SET);
267 const err = posix.getErrno(result);267 const err = posix.getErrno(result);
...@@ -295,7 +295,7 @@ pub const File = struct {...@@ -295,7 +295,7 @@ pub const File = struct {
295295
296 pub fn getPos(self: File) !usize {296 pub fn getPos(self: File) !usize {
297 switch (builtin.os) {297 switch (builtin.os) {
298 Os.linux, Os.macosx, Os.ios => {298 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
299 const result = posix.lseek(self.handle, 0, posix.SEEK_CUR);299 const result = posix.lseek(self.handle, 0, posix.SEEK_CUR);
300 const err = posix.getErrno(result);300 const err = posix.getErrno(result);
301 if (err > 0) {301 if (err > 0) {
std/os/freebsd/errno.zig created+121
...@@ -0,0 +1,121 @@
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 filesystem
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
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 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 ENOTSUP = EOPNOTSUPP; // Operation not supported
55pub const EPFNOSUPPORT = 46; // Protocol family not supported
56pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
57pub const EADDRINUSE = 48; // Address already in use
58pub const EADDRNOTAVAIL = 49; // Can't assign requested address
59
60// ipc/network software -- operational errors
61pub const ENETDOWN = 50; // Network is down
62pub const ENETUNREACH = 51; // Network is unreachable
63pub const ENETRESET = 52; // Network dropped connection on reset
64pub const ECONNABORTED = 53; // Software caused connection abort
65pub const ECONNRESET = 54; // Connection reset by peer
66pub const ENOBUFS = 55; // No buffer space available
67pub const EISCONN = 56; // Socket is already connected
68pub const ENOTCONN = 57; // Socket is not connected
69pub const ESHUTDOWN = 58; // Can't send after socket shutdown
70pub const ETOOMANYREFS = 59; // Too many references: can't splice
71pub const ETIMEDOUT = 60; // Operation timed out
72pub const ECONNREFUSED = 61; // Connection refused
73
74pub const ELOOP = 62; // Too many levels of symbolic links
75pub const ENAMETOOLONG = 63; // File name too long
76
77// should be rearranged
78pub const EHOSTDOWN = 64; // Host is down
79pub const EHOSTUNREACH = 65; // No route to host
80pub const ENOTEMPTY = 66; // Directory not empty
81
82// quotas & mush
83pub const EPROCLIM = 67; // Too many processes
84pub const EUSERS = 68; // Too many users
85pub const EDQUOT = 69; // Disc quota exceeded
86
87// Network File System
88pub const ESTALE = 70; // Stale NFS file handle
89pub const EREMOTE = 71; // Too many levels of remote in path
90pub const EBADRPC = 72; // RPC struct is bad
91pub const ERPCMISMATCH = 73; // RPC version wrong
92pub const EPROGUNAVAIL = 74; // RPC prog. not avail
93pub const EPROGMISMATCH = 75; // Program version wrong
94pub const EPROCUNAVAIL = 76; // Bad procedure for program
95
96pub const ENOLCK = 77; // No locks available
97pub const ENOSYS = 78; // Function not implemented
98
99pub const EFTYPE = 79; // Inappropriate file type or format
100pub const EAUTH = 80; // Authentication error
101pub const ENEEDAUTH = 81; // Need authenticator
102pub const EIDRM = 82; // Identifier removed
103pub const ENOMSG = 83; // No message of desired type
104pub const EOVERFLOW = 84; // Value too large to be stored in data type
105pub const ECANCELED = 85; // Operation canceled
106pub const EILSEQ = 86; // Illegal byte sequence
107pub const ENOATTR = 87; // Attribute not found
108
109pub const EDOOFUS = 88; // Programming error
110
111pub const EBADMSG = 89; // Bad message
112pub const EMULTIHOP = 90; // Multihop attempted
113pub const ENOLINK = 91; // Link has been severed
114pub const EPROTO = 92; // Protocol error
115
116pub const ENOTCAPABLE = 93; // Capabilities insufficient
117pub const ECAPMODE = 94; // Not permitted in capability mode
118pub const ENOTRECOVERABLE = 95; // State not recoverable
119pub const EOWNERDEAD = 96; // Previous owner died
120
121pub const ELAST = 96; // Must be equal largest errno
std/os/freebsd/index.zig created+802
...@@ -0,0 +1,802 @@
1const assert = @import("../debug.zig").assert;
2const builtin = @import("builtin");
3const arch = switch (builtin.arch) {
4 builtin.Arch.x86_64 => @import("x86_64.zig"),
5 else => @compileError("unsupported arch"),
6};
7pub use @import("syscall.zig");
8pub use @import("errno.zig");
9
10const std = @import("../../index.zig");
11const c = std.c;
12pub const Kevent = c.Kevent;
13
14pub const PATH_MAX = 1024;
15
16pub const STDIN_FILENO = 0;
17pub const STDOUT_FILENO = 1;
18pub const STDERR_FILENO = 2;
19
20pub const PROT_NONE = 0;
21pub const PROT_READ = 1;
22pub const PROT_WRITE = 2;
23pub const PROT_EXEC = 4;
24
25pub const MAP_FAILED = @maxValue(usize);
26pub const MAP_SHARED = 0x0001;
27pub const MAP_PRIVATE = 0x0002;
28pub const MAP_FIXED = 0x0010;
29pub const MAP_STACK = 0x0400;
30pub const MAP_NOSYNC = 0x0800;
31pub const MAP_ANON = 0x1000;
32pub const MAP_ANONYMOUS = MAP_ANON;
33pub const MAP_FILE = 0;
34pub const MAP_NORESERVE = 0;
35
36pub const MAP_GUARD = 0x00002000;
37pub const MAP_EXCL = 0x00004000;
38pub const MAP_NOCORE = 0x00020000;
39pub const MAP_PREFAULT_READ = 0x00040000;
40pub const MAP_32BIT = 0x00080000;
41
42pub const WNOHANG = 1;
43pub const WUNTRACED = 2;
44pub const WSTOPPED = WUNTRACED;
45pub const WCONTINUED = 4;
46pub const WNOWAIT = 8;
47pub const WEXITED = 16;
48pub const WTRAPPED = 32;
49
50pub const SA_ONSTACK = 0x0001;
51pub const SA_RESTART = 0x0002;
52pub const SA_RESETHAND = 0x0004;
53pub const SA_NOCLDSTOP = 0x0008;
54pub const SA_NODEFER = 0x0010;
55pub const SA_NOCLDWAIT = 0x0020;
56pub const SA_SIGINFO = 0x0040;
57
58pub const SIGHUP = 1;
59pub const SIGINT = 2;
60pub const SIGQUIT = 3;
61pub const SIGILL = 4;
62pub const SIGTRAP = 5;
63pub const SIGABRT = 6;
64pub const SIGIOT = SIGABRT;
65pub const SIGEMT = 7;
66pub const SIGFPE = 8;
67pub const SIGKILL = 9;
68pub const SIGBUS = 10;
69pub const SIGSEGV = 11;
70pub const SIGSYS = 12;
71pub const SIGPIPE = 13;
72pub const SIGALRM = 14;
73pub const SIGTERM = 15;
74pub const SIGURG = 16;
75pub const SIGSTOP = 17;
76pub const SIGTSTP = 18;
77pub const SIGCONT = 19;
78pub const SIGCHLD = 20;
79pub const SIGTTIN = 21;
80pub const SIGTTOU = 22;
81pub const SIGIO = 23;
82pub const SIGXCPU = 24;
83pub const SIGXFSZ = 25;
84pub const SIGVTALRM = 26;
85pub const SIGPROF = 27;
86pub const SIGWINCH = 28;
87pub const SIGINFO = 29;
88pub const SIGUSR1 = 30;
89pub const SIGUSR2 = 31;
90pub const SIGTHR = 32;
91pub const SIGLWP = SIGTHR;
92pub const SIGLIBRT = 33;
93
94pub const SIGRTMIN = 65;
95pub const SIGRTMAX = 126;
96
97pub const O_RDONLY = 0o0;
98pub const O_WRONLY = 0o1;
99pub const O_RDWR = 0o2;
100pub const O_ACCMODE = 0o3;
101
102pub const O_CREAT = 0o100;
103pub const O_EXCL = 0o200;
104pub const O_NOCTTY = 0o400;
105pub const O_TRUNC = 0o1000;
106pub const O_APPEND = 0o2000;
107pub const O_NONBLOCK = 0o4000;
108pub const O_DSYNC = 0o10000;
109pub const O_SYNC = 0o4010000;
110pub const O_RSYNC = 0o4010000;
111pub const O_DIRECTORY = 0o200000;
112pub const O_NOFOLLOW = 0o400000;
113pub const O_CLOEXEC = 0o2000000;
114
115pub const O_ASYNC = 0o20000;
116pub const O_DIRECT = 0o40000;
117pub const O_LARGEFILE = 0;
118pub const O_NOATIME = 0o1000000;
119pub const O_PATH = 0o10000000;
120pub const O_TMPFILE = 0o20200000;
121pub const O_NDELAY = O_NONBLOCK;
122
123pub const F_DUPFD = 0;
124pub const F_GETFD = 1;
125pub const F_SETFD = 2;
126pub const F_GETFL = 3;
127pub const F_SETFL = 4;
128
129pub const F_SETOWN = 8;
130pub const F_GETOWN = 9;
131pub const F_SETSIG = 10;
132pub const F_GETSIG = 11;
133
134pub const F_GETLK = 5;
135pub const F_SETLK = 6;
136pub const F_SETLKW = 7;
137
138pub const F_SETOWN_EX = 15;
139pub const F_GETOWN_EX = 16;
140
141pub const F_GETOWNER_UIDS = 17;
142
143pub const SEEK_SET = 0;
144pub const SEEK_CUR = 1;
145pub const SEEK_END = 2;
146
147pub const SIG_BLOCK = 1;
148pub const SIG_UNBLOCK = 2;
149pub const SIG_SETMASK = 3;
150
151pub const SOCK_STREAM = 1;
152pub const SOCK_DGRAM = 2;
153pub const SOCK_RAW = 3;
154pub const SOCK_RDM = 4;
155pub const SOCK_SEQPACKET = 5;
156
157pub const SOCK_CLOEXEC = 0x10000000;
158pub const SOCK_NONBLOCK = 0x20000000;
159
160// TODO: From here
161pub const PROTO_ip = 0o000;
162pub const PROTO_icmp = 0o001;
163pub const PROTO_igmp = 0o002;
164pub const PROTO_ggp = 0o003;
165pub const PROTO_ipencap = 0o004;
166pub const PROTO_st = 0o005;
167pub const PROTO_tcp = 0o006;
168pub const PROTO_egp = 0o010;
169pub const PROTO_pup = 0o014;
170pub const PROTO_udp = 0o021;
171pub const PROTO_hmp = 0o024;
172pub const PROTO_xns_idp = 0o026;
173pub const PROTO_rdp = 0o033;
174pub const PROTO_iso_tp4 = 0o035;
175pub const PROTO_xtp = 0o044;
176pub const PROTO_ddp = 0o045;
177pub const PROTO_idpr_cmtp = 0o046;
178pub const PROTO_ipv6 = 0o051;
179pub const PROTO_ipv6_route = 0o053;
180pub const PROTO_ipv6_frag = 0o054;
181pub const PROTO_idrp = 0o055;
182pub const PROTO_rsvp = 0o056;
183pub const PROTO_gre = 0o057;
184pub const PROTO_esp = 0o062;
185pub const PROTO_ah = 0o063;
186pub const PROTO_skip = 0o071;
187pub const PROTO_ipv6_icmp = 0o072;
188pub const PROTO_ipv6_nonxt = 0o073;
189pub const PROTO_ipv6_opts = 0o074;
190pub const PROTO_rspf = 0o111;
191pub const PROTO_vmtp = 0o121;
192pub const PROTO_ospf = 0o131;
193pub const PROTO_ipip = 0o136;
194pub const PROTO_encap = 0o142;
195pub const PROTO_pim = 0o147;
196pub const PROTO_raw = 0o377;
197
198pub const PF_UNSPEC = 0;
199pub const PF_LOCAL = 1;
200pub const PF_UNIX = PF_LOCAL;
201pub const PF_FILE = PF_LOCAL;
202pub const PF_INET = 2;
203pub const PF_AX25 = 3;
204pub const PF_IPX = 4;
205pub const PF_APPLETALK = 5;
206pub const PF_NETROM = 6;
207pub const PF_BRIDGE = 7;
208pub const PF_ATMPVC = 8;
209pub const PF_X25 = 9;
210pub const PF_INET6 = 10;
211pub const PF_ROSE = 11;
212pub const PF_DECnet = 12;
213pub const PF_NETBEUI = 13;
214pub const PF_SECURITY = 14;
215pub const PF_KEY = 15;
216pub const PF_NETLINK = 16;
217pub const PF_ROUTE = PF_NETLINK;
218pub const PF_PACKET = 17;
219pub const PF_ASH = 18;
220pub const PF_ECONET = 19;
221pub const PF_ATMSVC = 20;
222pub const PF_RDS = 21;
223pub const PF_SNA = 22;
224pub const PF_IRDA = 23;
225pub const PF_PPPOX = 24;
226pub const PF_WANPIPE = 25;
227pub const PF_LLC = 26;
228pub const PF_IB = 27;
229pub const PF_MPLS = 28;
230pub const PF_CAN = 29;
231pub const PF_TIPC = 30;
232pub const PF_BLUETOOTH = 31;
233pub const PF_IUCV = 32;
234pub const PF_RXRPC = 33;
235pub const PF_ISDN = 34;
236pub const PF_PHONET = 35;
237pub const PF_IEEE802154 = 36;
238pub const PF_CAIF = 37;
239pub const PF_ALG = 38;
240pub const PF_NFC = 39;
241pub const PF_VSOCK = 40;
242pub const PF_MAX = 41;
243
244pub const AF_UNSPEC = PF_UNSPEC;
245pub const AF_LOCAL = PF_LOCAL;
246pub const AF_UNIX = AF_LOCAL;
247pub const AF_FILE = AF_LOCAL;
248pub const AF_INET = PF_INET;
249pub const AF_AX25 = PF_AX25;
250pub const AF_IPX = PF_IPX;
251pub const AF_APPLETALK = PF_APPLETALK;
252pub const AF_NETROM = PF_NETROM;
253pub const AF_BRIDGE = PF_BRIDGE;
254pub const AF_ATMPVC = PF_ATMPVC;
255pub const AF_X25 = PF_X25;
256pub const AF_INET6 = PF_INET6;
257pub const AF_ROSE = PF_ROSE;
258pub const AF_DECnet = PF_DECnet;
259pub const AF_NETBEUI = PF_NETBEUI;
260pub const AF_SECURITY = PF_SECURITY;
261pub const AF_KEY = PF_KEY;
262pub const AF_NETLINK = PF_NETLINK;
263pub const AF_ROUTE = PF_ROUTE;
264pub const AF_PACKET = PF_PACKET;
265pub const AF_ASH = PF_ASH;
266pub const AF_ECONET = PF_ECONET;
267pub const AF_ATMSVC = PF_ATMSVC;
268pub const AF_RDS = PF_RDS;
269pub const AF_SNA = PF_SNA;
270pub const AF_IRDA = PF_IRDA;
271pub const AF_PPPOX = PF_PPPOX;
272pub const AF_WANPIPE = PF_WANPIPE;
273pub const AF_LLC = PF_LLC;
274pub const AF_IB = PF_IB;
275pub const AF_MPLS = PF_MPLS;
276pub const AF_CAN = PF_CAN;
277pub const AF_TIPC = PF_TIPC;
278pub const AF_BLUETOOTH = PF_BLUETOOTH;
279pub const AF_IUCV = PF_IUCV;
280pub const AF_RXRPC = PF_RXRPC;
281pub const AF_ISDN = PF_ISDN;
282pub const AF_PHONET = PF_PHONET;
283pub const AF_IEEE802154 = PF_IEEE802154;
284pub const AF_CAIF = PF_CAIF;
285pub const AF_ALG = PF_ALG;
286pub const AF_NFC = PF_NFC;
287pub const AF_VSOCK = PF_VSOCK;
288pub const AF_MAX = PF_MAX;
289
290pub const DT_UNKNOWN = 0;
291pub const DT_FIFO = 1;
292pub const DT_CHR = 2;
293pub const DT_DIR = 4;
294pub const DT_BLK = 6;
295pub const DT_REG = 8;
296pub const DT_LNK = 10;
297pub const DT_SOCK = 12;
298pub const DT_WHT = 14;
299
300/// add event to kq (implies enable)
301pub const EV_ADD = 0x0001;
302
303/// delete event from kq
304pub const EV_DELETE = 0x0002;
305
306/// enable event
307pub const EV_ENABLE = 0x0004;
308
309/// disable event (not reported)
310pub const EV_DISABLE = 0x0008;
311
312/// only report one occurrence
313pub const EV_ONESHOT = 0x0010;
314
315/// clear event state after reporting
316pub const EV_CLEAR = 0x0020;
317
318/// force immediate event output
319/// ... with or without EV_ERROR
320/// ... use KEVENT_FLAG_ERROR_EVENTS
321/// on syscalls supporting flags
322pub const EV_RECEIPT = 0x0040;
323
324/// disable event after reporting
325pub const EV_DISPATCH = 0x0080;
326
327pub const EVFILT_READ = -1;
328pub const EVFILT_WRITE = -2;
329
330/// attached to aio requests
331pub const EVFILT_AIO = -3;
332
333/// attached to vnodes
334pub const EVFILT_VNODE = -4;
335
336/// attached to struct proc
337pub const EVFILT_PROC = -5;
338
339/// attached to struct proc
340pub const EVFILT_SIGNAL = -6;
341
342/// timers
343pub const EVFILT_TIMER = -7;
344
345/// Process descriptors
346pub const EVFILT_PROCDESC = -8;
347
348/// Filesystem events
349pub const EVFILT_FS = -9;
350
351pub const EVFILT_LIO = -10;
352
353/// User events
354pub const EVFILT_USER = -11;
355
356/// Sendfile events
357pub const EVFILT_SENDFILE = -12;
358
359pub const EVFILT_EMPTY = -13;
360
361/// On input, NOTE_TRIGGER causes the event to be triggered for output.
362pub const NOTE_TRIGGER = 0x01000000;
363
364/// ignore input fflags
365pub const NOTE_FFNOP = 0x00000000;
366
367/// and fflags
368pub const NOTE_FFAND = 0x40000000;
369
370/// or fflags
371pub const NOTE_FFOR = 0x80000000;
372
373/// copy fflags
374pub const NOTE_FFCOPY = 0xc0000000;
375
376/// mask for operations
377pub const NOTE_FFCTRLMASK = 0xc0000000;
378pub const NOTE_FFLAGSMASK = 0x00ffffff;
379
380
381/// low water mark
382pub const NOTE_LOWAT = 0x00000001;
383
384/// behave like poll()
385pub const NOTE_FILE_POLL = 0x00000002;
386
387/// vnode was removed
388pub const NOTE_DELETE = 0x00000001;
389
390/// data contents changed
391pub const NOTE_WRITE = 0x00000002;
392
393/// size increased
394pub const NOTE_EXTEND = 0x00000004;
395
396/// attributes changed
397pub const NOTE_ATTRIB = 0x00000008;
398
399/// link count changed
400pub const NOTE_LINK = 0x00000010;
401
402/// vnode was renamed
403pub const NOTE_RENAME = 0x00000020;
404
405/// vnode access was revoked
406pub const NOTE_REVOKE = 0x00000040;
407
408/// vnode was opened
409pub const NOTE_OPEN = 0x00000080;
410
411/// file closed, fd did not allow write
412pub const NOTE_CLOSE = 0x00000100;
413
414/// file closed, fd did allow write
415pub const NOTE_CLOSE_WRITE = 0x00000200;
416
417/// file was read
418pub const NOTE_READ = 0x00000400;
419
420/// process exited
421pub const NOTE_EXIT = 0x80000000;
422
423/// process forked
424pub const NOTE_FORK = 0x40000000;
425
426/// process exec'd
427pub const NOTE_EXEC = 0x20000000;
428
429/// mask for signal & exit status
430pub const NOTE_PDATAMASK = 0x000fffff;
431pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
432
433/// data is seconds
434pub const NOTE_SECONDS = 0x00000001;
435
436/// data is milliseconds
437pub const NOTE_MSECONDS = 0x00000002;
438
439/// data is microseconds
440pub const NOTE_USECONDS = 0x00000004;
441
442/// data is nanoseconds
443pub const NOTE_NSECONDS = 0x00000008;
444
445/// timeout is absolute
446pub const NOTE_ABSTIME = 0x00000010;
447
448
449
450pub const TCGETS = 0x5401;
451pub const TCSETS = 0x5402;
452pub const TCSETSW = 0x5403;
453pub const TCSETSF = 0x5404;
454pub const TCGETA = 0x5405;
455pub const TCSETA = 0x5406;
456pub const TCSETAW = 0x5407;
457pub const TCSETAF = 0x5408;
458pub const TCSBRK = 0x5409;
459pub const TCXONC = 0x540A;
460pub const TCFLSH = 0x540B;
461pub const TIOCEXCL = 0x540C;
462pub const TIOCNXCL = 0x540D;
463pub const TIOCSCTTY = 0x540E;
464pub const TIOCGPGRP = 0x540F;
465pub const TIOCSPGRP = 0x5410;
466pub const TIOCOUTQ = 0x5411;
467pub const TIOCSTI = 0x5412;
468pub const TIOCGWINSZ = 0x5413;
469pub const TIOCSWINSZ = 0x5414;
470pub const TIOCMGET = 0x5415;
471pub const TIOCMBIS = 0x5416;
472pub const TIOCMBIC = 0x5417;
473pub const TIOCMSET = 0x5418;
474pub const TIOCGSOFTCAR = 0x5419;
475pub const TIOCSSOFTCAR = 0x541A;
476pub const FIONREAD = 0x541B;
477pub const TIOCINQ = FIONREAD;
478pub const TIOCLINUX = 0x541C;
479pub const TIOCCONS = 0x541D;
480pub const TIOCGSERIAL = 0x541E;
481pub const TIOCSSERIAL = 0x541F;
482pub const TIOCPKT = 0x5420;
483pub const FIONBIO = 0x5421;
484pub const TIOCNOTTY = 0x5422;
485pub const TIOCSETD = 0x5423;
486pub const TIOCGETD = 0x5424;
487pub const TCSBRKP = 0x5425;
488pub const TIOCSBRK = 0x5427;
489pub const TIOCCBRK = 0x5428;
490pub const TIOCGSID = 0x5429;
491pub const TIOCGRS485 = 0x542E;
492pub const TIOCSRS485 = 0x542F;
493pub const TIOCGPTN = 0x80045430;
494pub const TIOCSPTLCK = 0x40045431;
495pub const TIOCGDEV = 0x80045432;
496pub const TCGETX = 0x5432;
497pub const TCSETX = 0x5433;
498pub const TCSETXF = 0x5434;
499pub const TCSETXW = 0x5435;
500pub const TIOCSIG = 0x40045436;
501pub const TIOCVHANGUP = 0x5437;
502pub const TIOCGPKT = 0x80045438;
503pub const TIOCGPTLCK = 0x80045439;
504pub const TIOCGEXCL = 0x80045440;
505
506fn unsigned(s: i32) u32 {
507 return @bitCast(u32, s);
508}
509fn signed(s: u32) i32 {
510 return @bitCast(i32, s);
511}
512pub fn WEXITSTATUS(s: i32) i32 {
513 return signed((unsigned(s) & 0xff00) >> 8);
514}
515pub fn WTERMSIG(s: i32) i32 {
516 return signed(unsigned(s) & 0x7f);
517}
518pub fn WSTOPSIG(s: i32) i32 {
519 return WEXITSTATUS(s);
520}
521pub fn WIFEXITED(s: i32) bool {
522 return WTERMSIG(s) == 0;
523}
524pub fn WIFSTOPPED(s: i32) bool {
525 return @intCast(u16, (((unsigned(s) & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
526}
527pub fn WIFSIGNALED(s: i32) bool {
528 return (unsigned(s) & 0xffff) -% 1 < 0xff;
529}
530
531pub const winsize = extern struct.{
532 ws_row: u16,
533 ws_col: u16,
534 ws_xpixel: u16,
535 ws_ypixel: u16,
536};
537
538/// Get the errno from a syscall return value, or 0 for no error.
539pub fn getErrno(r: usize) usize {
540 const signed_r = @bitCast(isize, r);
541 return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
542}
543
544pub fn dup2(old: i32, new: i32) usize {
545 return arch.syscall2(SYS_dup2, @intCast(usize, old), @intCast(usize, new));
546}
547
548pub fn chdir(path: [*]const u8) usize {
549 return arch.syscall1(SYS_chdir, @ptrToInt(path));
550}
551
552pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
553 return arch.syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
554}
555
556pub fn fork() usize {
557 return arch.syscall0(SYS_fork);
558}
559
560pub fn getcwd(buf: [*]u8, size: usize) usize {
561 return arch.syscall2(SYS___getcwd, @ptrToInt(buf), size);
562}
563
564pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
565 return arch.syscall3(SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count);
566}
567
568pub fn isatty(fd: i32) bool {
569 var wsz: winsize = undefined;
570 return arch.syscall3(SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
571}
572
573pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
574 return arch.syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
575}
576
577pub fn mkdir(path: [*]const u8, mode: u32) usize {
578 return arch.syscall2(SYS_mkdir, @ptrToInt(path), mode);
579}
580
581pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {
582 return arch.syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset));
583}
584
585pub fn munmap(address: usize, length: usize) usize {
586 return arch.syscall2(SYS_munmap, address, length);
587}
588
589pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
590 return arch.syscall3(SYS_read, @intCast(usize, fd), @ptrToInt(buf), count);
591}
592
593pub fn rmdir(path: [*]const u8) usize {
594 return arch.syscall1(SYS_rmdir, @ptrToInt(path));
595}
596
597pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
598 return arch.syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
599}
600
601pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
602 return arch.syscall4(SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset);
603}
604
605pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize {
606 return arch.syscall4(SYS_preadv, @intCast(usize, fd), @ptrToInt(iov), count, offset);
607}
608
609pub fn pipe(fd: *[2]i32) usize {
610 return pipe2(fd, 0);
611}
612
613pub fn pipe2(fd: *[2]i32, flags: usize) usize {
614 return arch.syscall2(SYS_pipe2, @ptrToInt(fd), flags);
615}
616
617pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
618 return arch.syscall3(SYS_write, @intCast(usize, fd), @ptrToInt(buf), count);
619}
620
621pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
622 return arch.syscall4(SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset);
623}
624
625pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize {
626 return arch.syscall4(SYS_pwritev, @intCast(usize, fd), @ptrToInt(iov), count, offset);
627}
628
629pub fn rename(old: [*]const u8, new: [*]const u8) usize {
630 return arch.syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
631}
632
633pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
634 return arch.syscall3(SYS_open, @ptrToInt(path), flags, perm);
635}
636
637pub fn create(path: [*]const u8, perm: usize) usize {
638 return arch.syscall2(SYS_creat, @ptrToInt(path), perm);
639}
640
641pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {
642 return arch.syscall4(SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode);
643}
644
645pub fn close(fd: i32) usize {
646 return arch.syscall1(SYS_close, @intCast(usize, fd));
647}
648
649pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {
650 return arch.syscall3(SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos);
651}
652
653pub fn exit(status: i32) noreturn {
654 _ = arch.syscall1(SYS_exit, @bitCast(usize, isize(status)));
655 unreachable;
656}
657
658pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
659 return arch.syscall3(SYS_getrandom, @ptrToInt(buf), count, @intCast(usize, flags));
660}
661
662pub fn kill(pid: i32, sig: i32) usize {
663 return arch.syscall2(SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig));
664}
665
666pub fn unlink(path: [*]const u8) usize {
667 return arch.syscall1(SYS_unlink, @ptrToInt(path));
668}
669
670pub fn waitpid(pid: i32, status: *i32, options: i32) usize {
671 return arch.syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
672}
673
674pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
675 return arch.syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
676}
677
678pub fn setuid(uid: u32) usize {
679 return arch.syscall1(SYS_setuid, uid);
680}
681
682pub fn setgid(gid: u32) usize {
683 return arch.syscall1(SYS_setgid, gid);
684}
685
686pub fn setreuid(ruid: u32, euid: u32) usize {
687 return arch.syscall2(SYS_setreuid, ruid, euid);
688}
689
690pub fn setregid(rgid: u32, egid: u32) usize {
691 return arch.syscall2(SYS_setregid, rgid, egid);
692}
693
694pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize {
695 // TODO: Implement
696 return 0;
697}
698
699pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
700 // TODO: Implement
701 return 0;
702}
703
704const NSIG = 65;
705const sigset_t = [128 / @sizeOf(usize)]usize;
706const all_mask = []usize.{@maxValue(usize)};
707const app_mask = []usize.{0xfffffffc7fffffff};
708
709/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
710pub const Sigaction = struct.{
711 // TODO: Adjust to use freebsd struct layout
712 handler: extern fn (i32) void,
713 mask: sigset_t,
714 flags: u32,
715};
716
717pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize));
718pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
719pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
720pub const empty_sigset = []usize.{0} ** sigset_t.len;
721
722pub fn raise(sig: i32) usize {
723 // TODO implement, see linux equivalent for what we want to try and do
724 return 0;
725}
726
727fn blockAllSignals(set: *sigset_t) void {
728 // TODO implement
729}
730
731fn blockAppSignals(set: *sigset_t) void {
732 // TODO implement
733}
734
735fn restoreSignals(set: *sigset_t) void {
736 // TODO implement
737}
738
739pub fn sigaddset(set: *sigset_t, sig: u6) void {
740 const s = sig - 1;
741 (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
742}
743
744pub fn sigismember(set: *const sigset_t, sig: u6) bool {
745 const s = sig - 1;
746 return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
747}
748
749pub const Stat = arch.Stat;
750pub const timespec = arch.timespec;
751
752pub fn fstat(fd: i32, stat_buf: *Stat) usize {
753 return arch.syscall2(SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf));
754}
755
756pub const iovec = extern struct.{
757 iov_base: [*]u8,
758 iov_len: usize,
759};
760
761pub const iovec_const = extern struct.{
762 iov_base: [*]const u8,
763 iov_len: usize,
764};
765
766pub fn kqueue() usize {
767 return errnoWrap(c.kqueue());
768}
769
770pub fn kevent(kq: i32, changelist: []const Kevent, eventlist: []Kevent, timeout: ?*const timespec) usize {
771 return errnoWrap(c.kevent(
772 kq,
773 changelist.ptr,
774 @intCast(c_int, changelist.len),
775 eventlist.ptr,
776 @intCast(c_int, eventlist.len),
777 timeout,
778 ));
779}
780
781pub fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize {
782 return errnoWrap(c.sysctl(name, namelen, oldp, oldlenp, newp, newlen));
783}
784
785pub fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize {
786 return errnoWrap(c.sysctlbyname(name, oldp, oldlenp, newp, newlen));
787}
788
789pub fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) usize {
790 return errnoWrap(c.sysctlnametomib(name, wibp, sizep));
791}
792
793
794
795/// Takes the return value from a syscall and formats it back in the way
796/// that the kernel represents it to libc. Errno was a mistake, let's make
797/// it go away forever.
798fn errnoWrap(value: isize) usize {
799 return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value);
800}
801
802
std/os/freebsd/syscall.zig created+493
...@@ -0,0 +1,493 @@
1pub const SYS_syscall = 0;
2pub const SYS_exit = 1;
3pub const SYS_fork = 2;
4pub const SYS_read = 3;
5pub const SYS_write = 4;
6pub const SYS_open = 5;
7pub const SYS_close = 6;
8pub const SYS_wait4 = 7;
9// 8 is old creat
10pub const SYS_link = 9;
11pub const SYS_unlink = 10;
12// 11 is obsolete execv
13pub const SYS_chdir = 12;
14pub const SYS_fchdir = 13;
15pub const SYS_freebsd11_mknod = 14;
16pub const SYS_chmod = 15;
17pub const SYS_chown = 16;
18pub const SYS_break = 17;
19// 18 is freebsd4 getfsstat
20// 19 is old lseek
21pub const SYS_getpid = 20;
22pub const SYS_mount = 21;
23pub const SYS_unmount = 22;
24pub const SYS_setuid = 23;
25pub const SYS_getuid = 24;
26pub const SYS_geteuid = 25;
27pub const SYS_ptrace = 26;
28pub const SYS_recvmsg = 27;
29pub const SYS_sendmsg = 28;
30pub const SYS_recvfrom = 29;
31pub const SYS_accept = 30;
32pub const SYS_getpeername = 31;
33pub const SYS_getsockname = 32;
34pub const SYS_access = 33;
35pub const SYS_chflags = 34;
36pub const SYS_fchflags = 35;
37pub const SYS_sync = 36;
38pub const SYS_kill = 37;
39// 38 is old stat
40pub const SYS_getppid = 39;
41// 40 is old lstat
42pub const SYS_dup = 41;
43pub const SYS_freebsd10_pipe = 42;
44pub const SYS_getegid = 43;
45pub const SYS_profil = 44;
46pub const SYS_ktrace = 45;
47// 46 is old sigaction
48pub const SYS_getgid = 47;
49// 48 is old sigprocmask
50pub const SYS_getlogin = 49;
51pub const SYS_setlogin = 50;
52pub const SYS_acct = 51;
53// 52 is old sigpending
54pub const SYS_sigaltstack = 53;
55pub const SYS_ioctl = 54;
56pub const SYS_reboot = 55;
57pub const SYS_revoke = 56;
58pub const SYS_symlink = 57;
59pub const SYS_readlink = 58;
60pub const SYS_execve = 59;
61pub const SYS_umask = 60;
62pub const SYS_chroot = 61;
63// 62 is old fstat
64// 63 is old getkerninfo
65// 64 is old getpagesize
66pub const SYS_msync = 65;
67pub const SYS_vfork = 66;
68// 67 is obsolete vread
69// 68 is obsolete vwrite
70// 69 is obsolete sbrk (still present on some platforms)
71pub const SYS_sstk = 70;
72// 71 is old mmap
73pub const SYS_vadvise = 72;
74pub const SYS_munmap = 73;
75pub const SYS_mprotect = 74;
76pub const SYS_madvise = 75;
77// 76 is obsolete vhangup
78// 77 is obsolete vlimit
79pub const SYS_mincore = 78;
80pub const SYS_getgroups = 79;
81pub const SYS_setgroups = 80;
82pub const SYS_getpgrp = 81;
83pub const SYS_setpgid = 82;
84pub const SYS_setitimer = 83;
85// 84 is old wait
86pub const SYS_swapon = 85;
87pub const SYS_getitimer = 86;
88// 87 is old gethostname
89// 88 is old sethostname
90pub const SYS_getdtablesize = 89;
91pub const SYS_dup2 = 90;
92pub const SYS_fcntl = 92;
93pub const SYS_select = 93;
94pub const SYS_fsync = 95;
95pub const SYS_setpriority = 96;
96pub const SYS_socket = 97;
97pub const SYS_connect = 98;
98// 99 is old accept
99pub const SYS_getpriority = 100;
100// 101 is old send
101// 102 is old recv
102// 103 is old sigreturn
103pub const SYS_bind = 104;
104pub const SYS_setsockopt = 105;
105pub const SYS_listen = 106;
106// 107 is obsolete vtimes
107// 108 is old sigvec
108// 109 is old sigblock
109// 110 is old sigsetmask
110// 111 is old sigsuspend
111// 112 is old sigstack
112// 113 is old recvmsg
113// 114 is old sendmsg
114// 115 is obsolete vtrace
115pub const SYS_gettimeofday = 116;
116pub const SYS_getrusage = 117;
117pub const SYS_getsockopt = 118;
118pub const SYS_readv = 120;
119pub const SYS_writev = 121;
120pub const SYS_settimeofday = 122;
121pub const SYS_fchown = 123;
122pub const SYS_fchmod = 124;
123// 125 is old recvfrom
124pub const SYS_setreuid = 126;
125pub const SYS_setregid = 127;
126pub const SYS_rename = 128;
127// 129 is old truncate
128// 130 is old ftruncate
129pub const SYS_flock = 131;
130pub const SYS_mkfifo = 132;
131pub const SYS_sendto = 133;
132pub const SYS_shutdown = 134;
133pub const SYS_socketpair = 135;
134pub const SYS_mkdir = 136;
135pub const SYS_rmdir = 137;
136pub const SYS_utimes = 138;
137// 139 is obsolete 4.2 sigreturn
138pub const SYS_adjtime = 140;
139// 141 is old getpeername
140// 142 is old gethostid
141// 143 is old sethostid
142// 144 is old getrlimit
143// 145 is old setrlimit
144// 146 is old killpg
145pub const SYS_setsid = 147;
146pub const SYS_quotactl = 148;
147// 149 is old quota
148// 150 is old getsockname
149pub const SYS_nlm_syscall = 154;
150pub const SYS_nfssvc = 155;
151// 156 is old getdirentries
152// 157 is freebsd4 statfs
153// 158 is freebsd4 fstatfs
154pub const SYS_lgetfh = 160;
155pub const SYS_getfh = 161;
156// 162 is freebsd4 getdomainname
157// 163 is freebsd4 setdomainname
158// 164 is freebsd4 uname
159pub const SYS_sysarch = 165;
160pub const SYS_rtprio = 166;
161pub const SYS_semsys = 169;
162pub const SYS_msgsys = 170;
163pub const SYS_shmsys = 171;
164// 173 is freebsd6 pread
165// 174 is freebsd6 pwrite
166pub const SYS_setfib = 175;
167pub const SYS_ntp_adjtime = 176;
168pub const SYS_setgid = 181;
169pub const SYS_setegid = 182;
170pub const SYS_seteuid = 183;
171// 184 is obsolete lfs_bmapv
172// 185 is obsolete lfs_markv
173// 186 is obsolete lfs_segclean
174// 187 is obsolete lfs_segwait
175pub const SYS_freebsd11_stat = 188;
176pub const SYS_freebsd11_fstat = 189;
177pub const SYS_freebsd11_lstat = 190;
178pub const SYS_pathconf = 191;
179pub const SYS_fpathconf = 192;
180pub const SYS_getrlimit = 194;
181pub const SYS_setrlimit = 195;
182pub const SYS_freebsd11_getdirentries = 196;
183// 197 is freebsd6 mmap
184pub const SYS___syscall = 198;
185// 199 is freebsd6 lseek
186// 200 is freebsd6 truncate
187// 201 is freebsd6 ftruncate
188pub const SYS___sysctl = 202;
189pub const SYS_mlock = 203;
190pub const SYS_munlock = 204;
191pub const SYS_undelete = 205;
192pub const SYS_futimes = 206;
193pub const SYS_getpgid = 207;
194pub const SYS_poll = 209;
195pub const SYS_freebsd7___semctl = 220;
196pub const SYS_semget = 221;
197pub const SYS_semop = 222;
198pub const SYS_freebsd7_msgctl = 224;
199pub const SYS_msgget = 225;
200pub const SYS_msgsnd = 226;
201pub const SYS_msgrcv = 227;
202pub const SYS_shmat = 228;
203pub const SYS_freebsd7_shmctl = 229;
204pub const SYS_shmdt = 230;
205pub const SYS_shmget = 231;
206pub const SYS_clock_gettime = 232;
207pub const SYS_clock_settime = 233;
208pub const SYS_clock_getres = 234;
209pub const SYS_ktimer_create = 235;
210pub const SYS_ktimer_delete = 236;
211pub const SYS_ktimer_settime = 237;
212pub const SYS_ktimer_gettime = 238;
213pub const SYS_ktimer_getoverrun = 239;
214pub const SYS_nanosleep = 240;
215pub const SYS_ffclock_getcounter = 241;
216pub const SYS_ffclock_setestimate = 242;
217pub const SYS_ffclock_getestimate = 243;
218pub const SYS_clock_nanosleep = 244;
219pub const SYS_clock_getcpuclockid2 = 247;
220pub const SYS_ntp_gettime = 248;
221pub const SYS_minherit = 250;
222pub const SYS_rfork = 251;
223// 252 is obsolete openbsd_poll
224pub const SYS_issetugid = 253;
225pub const SYS_lchown = 254;
226pub const SYS_aio_read = 255;
227pub const SYS_aio_write = 256;
228pub const SYS_lio_listio = 257;
229pub const SYS_freebsd11_getdents = 272;
230pub const SYS_lchmod = 274;
231// 275 is obsolete netbsd_lchown
232pub const SYS_lutimes = 276;
233// 277 is obsolete netbsd_msync
234pub const SYS_freebsd11_nstat = 278;
235pub const SYS_freebsd11_nfstat = 279;
236pub const SYS_freebsd11_nlstat = 280;
237pub const SYS_preadv = 289;
238pub const SYS_pwritev = 290;
239// 297 is freebsd4 fhstatfs
240pub const SYS_fhopen = 298;
241pub const SYS_freebsd11_fhstat = 299;
242pub const SYS_modnext = 300;
243pub const SYS_modstat = 301;
244pub const SYS_modfnext = 302;
245pub const SYS_modfind = 303;
246pub const SYS_kldload = 304;
247pub const SYS_kldunload = 305;
248pub const SYS_kldfind = 306;
249pub const SYS_kldnext = 307;
250pub const SYS_kldstat = 308;
251pub const SYS_kldfirstmod = 309;
252pub const SYS_getsid = 310;
253pub const SYS_setresuid = 311;
254pub const SYS_setresgid = 312;
255// 313 is obsolete signanosleep
256pub const SYS_aio_return = 314;
257pub const SYS_aio_suspend = 315;
258pub const SYS_aio_cancel = 316;
259pub const SYS_aio_error = 317;
260// 318 is freebsd6 aio_read
261// 319 is freebsd6 aio_write
262// 320 is freebsd6 lio_listio
263pub const SYS_yield = 321;
264// 322 is obsolete thr_sleep
265// 323 is obsolete thr_wakeup
266pub const SYS_mlockall = 324;
267pub const SYS_munlockall = 325;
268pub const SYS___getcwd = 326;
269pub const SYS_sched_setparam = 327;
270pub const SYS_sched_getparam = 328;
271pub const SYS_sched_setscheduler = 329;
272pub const SYS_sched_getscheduler = 330;
273pub const SYS_sched_yield = 331;
274pub const SYS_sched_get_priority_max = 332;
275pub const SYS_sched_get_priority_min = 333;
276pub const SYS_sched_rr_get_interval = 334;
277pub const SYS_utrace = 335;
278// 336 is freebsd4 sendfile
279pub const SYS_kldsym = 337;
280pub const SYS_jail = 338;
281pub const SYS_nnpfs_syscall = 339;
282pub const SYS_sigprocmask = 340;
283pub const SYS_sigsuspend = 341;
284// 342 is freebsd4 sigaction
285pub const SYS_sigpending = 343;
286// 344 is freebsd4 sigreturn
287pub const SYS_sigtimedwait = 345;
288pub const SYS_sigwaitinfo = 346;
289pub const SYS___acl_get_file = 347;
290pub const SYS___acl_set_file = 348;
291pub const SYS___acl_get_fd = 349;
292pub const SYS___acl_set_fd = 350;
293pub const SYS___acl_delete_file = 351;
294pub const SYS___acl_delete_fd = 352;
295pub const SYS___acl_aclcheck_file = 353;
296pub const SYS___acl_aclcheck_fd = 354;
297pub const SYS_extattrctl = 355;
298pub const SYS_extattr_set_file = 356;
299pub const SYS_extattr_get_file = 357;
300pub const SYS_extattr_delete_file = 358;
301pub const SYS_aio_waitcomplete = 359;
302pub const SYS_getresuid = 360;
303pub const SYS_getresgid = 361;
304pub const SYS_kqueue = 362;
305pub const SYS_freebsd11_kevent = 363;
306// 364 is obsolete __cap_get_proc
307// 365 is obsolete __cap_set_proc
308// 366 is obsolete __cap_get_fd
309// 367 is obsolete __cap_get_file
310// 368 is obsolete __cap_set_fd
311// 369 is obsolete __cap_set_file
312pub const SYS_extattr_set_fd = 371;
313pub const SYS_extattr_get_fd = 372;
314pub const SYS_extattr_delete_fd = 373;
315pub const SYS___setugid = 374;
316pub const SYS_eaccess = 376;
317pub const SYS_afs3_syscall = 377;
318pub const SYS_nmount = 378;
319// 379 is obsolete kse_exit
320// 380 is obsolete kse_wakeup
321// 381 is obsolete kse_create
322// 382 is obsolete kse_thr_interrupt
323// 383 is obsolete kse_release
324pub const SYS___mac_get_proc = 384;
325pub const SYS___mac_set_proc = 385;
326pub const SYS___mac_get_fd = 386;
327pub const SYS___mac_get_file = 387;
328pub const SYS___mac_set_fd = 388;
329pub const SYS___mac_set_file = 389;
330pub const SYS_kenv = 390;
331pub const SYS_lchflags = 391;
332pub const SYS_uuidgen = 392;
333pub const SYS_sendfile = 393;
334pub const SYS_mac_syscall = 394;
335pub const SYS_freebsd11_getfsstat = 395;
336pub const SYS_freebsd11_statfs = 396;
337pub const SYS_freebsd11_fstatfs = 397;
338pub const SYS_freebsd11_fhstatfs = 398;
339pub const SYS_ksem_close = 400;
340pub const SYS_ksem_post = 401;
341pub const SYS_ksem_wait = 402;
342pub const SYS_ksem_trywait = 403;
343pub const SYS_ksem_init = 404;
344pub const SYS_ksem_open = 405;
345pub const SYS_ksem_unlink = 406;
346pub const SYS_ksem_getvalue = 407;
347pub const SYS_ksem_destroy = 408;
348pub const SYS___mac_get_pid = 409;
349pub const SYS___mac_get_link = 410;
350pub const SYS___mac_set_link = 411;
351pub const SYS_extattr_set_link = 412;
352pub const SYS_extattr_get_link = 413;
353pub const SYS_extattr_delete_link = 414;
354pub const SYS___mac_execve = 415;
355pub const SYS_sigaction = 416;
356pub const SYS_sigreturn = 417;
357pub const SYS_getcontext = 421;
358pub const SYS_setcontext = 422;
359pub const SYS_swapcontext = 423;
360pub const SYS_swapoff = 424;
361pub const SYS___acl_get_link = 425;
362pub const SYS___acl_set_link = 426;
363pub const SYS___acl_delete_link = 427;
364pub const SYS___acl_aclcheck_link = 428;
365pub const SYS_sigwait = 429;
366pub const SYS_thr_create = 430;
367pub const SYS_thr_exit = 431;
368pub const SYS_thr_self = 432;
369pub const SYS_thr_kill = 433;
370pub const SYS_jail_attach = 436;
371pub const SYS_extattr_list_fd = 437;
372pub const SYS_extattr_list_file = 438;
373pub const SYS_extattr_list_link = 439;
374// 440 is obsolete kse_switchin
375pub const SYS_ksem_timedwait = 441;
376pub const SYS_thr_suspend = 442;
377pub const SYS_thr_wake = 443;
378pub const SYS_kldunloadf = 444;
379pub const SYS_audit = 445;
380pub const SYS_auditon = 446;
381pub const SYS_getauid = 447;
382pub const SYS_setauid = 448;
383pub const SYS_getaudit = 449;
384pub const SYS_setaudit = 450;
385pub const SYS_getaudit_addr = 451;
386pub const SYS_setaudit_addr = 452;
387pub const SYS_auditctl = 453;
388pub const SYS__umtx_op = 454;
389pub const SYS_thr_new = 455;
390pub const SYS_sigqueue = 456;
391pub const SYS_kmq_open = 457;
392pub const SYS_kmq_setattr = 458;
393pub const SYS_kmq_timedreceive = 459;
394pub const SYS_kmq_timedsend = 460;
395pub const SYS_kmq_notify = 461;
396pub const SYS_kmq_unlink = 462;
397pub const SYS_abort2 = 463;
398pub const SYS_thr_set_name = 464;
399pub const SYS_aio_fsync = 465;
400pub const SYS_rtprio_thread = 466;
401pub const SYS_sctp_peeloff = 471;
402pub const SYS_sctp_generic_sendmsg = 472;
403pub const SYS_sctp_generic_sendmsg_iov = 473;
404pub const SYS_sctp_generic_recvmsg = 474;
405pub const SYS_pread = 475;
406pub const SYS_pwrite = 476;
407pub const SYS_mmap = 477;
408pub const SYS_lseek = 478;
409pub const SYS_truncate = 479;
410pub const SYS_ftruncate = 480;
411pub const SYS_thr_kill2 = 481;
412pub const SYS_shm_open = 482;
413pub const SYS_shm_unlink = 483;
414pub const SYS_cpuset = 484;
415pub const SYS_cpuset_setid = 485;
416pub const SYS_cpuset_getid = 486;
417pub const SYS_cpuset_getaffinity = 487;
418pub const SYS_cpuset_setaffinity = 488;
419pub const SYS_faccessat = 489;
420pub const SYS_fchmodat = 490;
421pub const SYS_fchownat = 491;
422pub const SYS_fexecve = 492;
423pub const SYS_freebsd11_fstatat = 493;
424pub const SYS_futimesat = 494;
425pub const SYS_linkat = 495;
426pub const SYS_mkdirat = 496;
427pub const SYS_mkfifoat = 497;
428pub const SYS_freebsd11_mknodat = 498;
429pub const SYS_openat = 499;
430pub const SYS_readlinkat = 500;
431pub const SYS_renameat = 501;
432pub const SYS_symlinkat = 502;
433pub const SYS_unlinkat = 503;
434pub const SYS_posix_openpt = 504;
435pub const SYS_gssd_syscall = 505;
436pub const SYS_jail_get = 506;
437pub const SYS_jail_set = 507;
438pub const SYS_jail_remove = 508;
439pub const SYS_closefrom = 509;
440pub const SYS___semctl = 510;
441pub const SYS_msgctl = 511;
442pub const SYS_shmctl = 512;
443pub const SYS_lpathconf = 513;
444// 514 is obsolete cap_new
445pub const SYS___cap_rights_get = 515;
446pub const SYS_cap_enter = 516;
447pub const SYS_cap_getmode = 517;
448pub const SYS_pdfork = 518;
449pub const SYS_pdkill = 519;
450pub const SYS_pdgetpid = 520;
451pub const SYS_pselect = 522;
452pub const SYS_getloginclass = 523;
453pub const SYS_setloginclass = 524;
454pub const SYS_rctl_get_racct = 525;
455pub const SYS_rctl_get_rules = 526;
456pub const SYS_rctl_get_limits = 527;
457pub const SYS_rctl_add_rule = 528;
458pub const SYS_rctl_remove_rule = 529;
459pub const SYS_posix_fallocate = 530;
460pub const SYS_posix_fadvise = 531;
461pub const SYS_wait6 = 532;
462pub const SYS_cap_rights_limit = 533;
463pub const SYS_cap_ioctls_limit = 534;
464pub const SYS_cap_ioctls_get = 535;
465pub const SYS_cap_fcntls_limit = 536;
466pub const SYS_cap_fcntls_get = 537;
467pub const SYS_bindat = 538;
468pub const SYS_connectat = 539;
469pub const SYS_chflagsat = 540;
470pub const SYS_accept4 = 541;
471pub const SYS_pipe2 = 542;
472pub const SYS_aio_mlock = 543;
473pub const SYS_procctl = 544;
474pub const SYS_ppoll = 545;
475pub const SYS_futimens = 546;
476pub const SYS_utimensat = 547;
477// 548 is obsolete numa_getaffinity
478// 549 is obsolete numa_setaffinity
479pub const SYS_fdatasync = 550;
480pub const SYS_fstat = 551;
481pub const SYS_fstatat = 552;
482pub const SYS_fhstat = 553;
483pub const SYS_getdirentries = 554;
484pub const SYS_statfs = 555;
485pub const SYS_fstatfs = 556;
486pub const SYS_getfsstat = 557;
487pub const SYS_fhstatfs = 558;
488pub const SYS_mknodat = 559;
489pub const SYS_kevent = 560;
490pub const SYS_cpuset_getdomain = 561;
491pub const SYS_cpuset_setdomain = 562;
492pub const SYS_getrandom = 563;
493pub const SYS_MAXSYSCALL = 564;
std/os/freebsd/x86_64.zig created+136
...@@ -0,0 +1,136 @@
1const freebsd = @import("index.zig");
2const socklen_t = freebsd.socklen_t;
3const iovec = freebsd.iovec;
4
5pub const SYS_sbrk = 69;
6
7pub fn syscall0(number: usize) usize {
8 return asm volatile ("syscall"
9 : [ret] "={rax}" (-> usize)
10 : [number] "{rax}" (number)
11 : "rcx", "r11"
12 );
13}
14
15pub fn syscall1(number: usize, arg1: usize) usize {
16 return asm volatile ("syscall"
17 : [ret] "={rax}" (-> usize)
18 : [number] "{rax}" (number),
19 [arg1] "{rdi}" (arg1)
20 : "rcx", "r11"
21 );
22}
23
24pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
25 return asm volatile ("syscall"
26 : [ret] "={rax}" (-> usize)
27 : [number] "{rax}" (number),
28 [arg1] "{rdi}" (arg1),
29 [arg2] "{rsi}" (arg2)
30 : "rcx", "r11"
31 );
32}
33
34pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
35 return asm volatile ("syscall"
36 : [ret] "={rax}" (-> usize)
37 : [number] "{rax}" (number),
38 [arg1] "{rdi}" (arg1),
39 [arg2] "{rsi}" (arg2),
40 [arg3] "{rdx}" (arg3)
41 : "rcx", "r11"
42 );
43}
44
45pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
46 return asm volatile ("syscall"
47 : [ret] "={rax}" (-> usize)
48 : [number] "{rax}" (number),
49 [arg1] "{rdi}" (arg1),
50 [arg2] "{rsi}" (arg2),
51 [arg3] "{rdx}" (arg3),
52 [arg4] "{r10}" (arg4)
53 : "rcx", "r11"
54 );
55}
56
57pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
58 return asm volatile ("syscall"
59 : [ret] "={rax}" (-> usize)
60 : [number] "{rax}" (number),
61 [arg1] "{rdi}" (arg1),
62 [arg2] "{rsi}" (arg2),
63 [arg3] "{rdx}" (arg3),
64 [arg4] "{r10}" (arg4),
65 [arg5] "{r8}" (arg5)
66 : "rcx", "r11"
67 );
68}
69
70pub fn syscall6(
71 number: usize,
72 arg1: usize,
73 arg2: usize,
74 arg3: usize,
75 arg4: usize,
76 arg5: usize,
77 arg6: usize,
78) usize {
79 return asm volatile ("syscall"
80 : [ret] "={rax}" (-> usize)
81 : [number] "{rax}" (number),
82 [arg1] "{rdi}" (arg1),
83 [arg2] "{rsi}" (arg2),
84 [arg3] "{rdx}" (arg3),
85 [arg4] "{r10}" (arg4),
86 [arg5] "{r8}" (arg5),
87 [arg6] "{r9}" (arg6)
88 : "rcx", "r11"
89 );
90}
91
92pub nakedcc fn restore_rt() void {
93 asm volatile ("syscall"
94 :
95 : [number] "{rax}" (usize(SYS_rt_sigreturn))
96 : "rcx", "r11"
97 );
98}
99
100pub const msghdr = extern struct.{
101 msg_name: &u8,
102 msg_namelen: socklen_t,
103 msg_iov: &iovec,
104 msg_iovlen: i32,
105 __pad1: i32,
106 msg_control: &u8,
107 msg_controllen: socklen_t,
108 __pad2: socklen_t,
109 msg_flags: i32,
110};
111
112/// Renamed to Stat to not conflict with the stat function.
113pub const Stat = extern struct.{
114 dev: u64,
115 ino: u64,
116 nlink: usize,
117
118 mode: u32,
119 uid: u32,
120 gid: u32,
121 __pad0: u32,
122 rdev: u64,
123 size: i64,
124 blksize: isize,
125 blocks: i64,
126
127 atim: timespec,
128 mtim: timespec,
129 ctim: timespec,
130 __unused: [3]isize,
131};
132
133pub const timespec = extern struct.{
134 tv_sec: isize,
135 tv_nsec: isize,
136};
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, home_dir, "Library", "Application Support", appname);44 return os.path.join(allocator, home_dir, "Library", "Application Support", appname);
45 },45 },
46 builtin.Os.linux => {46 builtin.Os.linux, builtin.Os.freebsd => {
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 => posixGetUserInfo(name),14 Os.linux, Os.macosx, Os.ios, Os.freebsd => posixGetUserInfo(name),
15 else => @compileError("Unsupported OS"),15 else => @compileError("Unsupported OS"),
16 };16 };
17}17}
std/os/index.zig+29-17
...@@ -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 => true,6 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => true,
7 else => false,7 else => false,
8};8};
9const os = @This();9const os = @This();
...@@ -24,10 +24,12 @@ test "std.os" {...@@ -24,10 +24,12 @@ test "std.os" {
24pub const windows = @import("windows/index.zig");24pub const windows = @import("windows/index.zig");
25pub const darwin = @import("darwin.zig");25pub const darwin = @import("darwin.zig");
26pub const linux = @import("linux/index.zig");26pub const linux = @import("linux/index.zig");
27pub const freebsd = @import("freebsd/index.zig");
27pub const zen = @import("zen.zig");28pub const zen = @import("zen.zig");
28pub const posix = switch (builtin.os) {29pub const posix = switch (builtin.os) {
29 Os.linux => linux,30 Os.linux => linux,
30 Os.macosx, Os.ios => darwin,31 Os.macosx, Os.ios => darwin,
32 Os.freebsd => freebsd,
31 Os.zen => zen,33 Os.zen => zen,
32 else => @compileError("Unsupported OS"),34 else => @compileError("Unsupported OS"),
33};35};
...@@ -40,7 +42,7 @@ pub const time = @import("time.zig");...@@ -40,7 +42,7 @@ pub const time = @import("time.zig");
4042
41pub const page_size = 4 * 1024;43pub const page_size = 4 * 1024;
42pub const MAX_PATH_BYTES = switch (builtin.os) {44pub const MAX_PATH_BYTES = switch (builtin.os) {
43 Os.linux, Os.macosx, Os.ios => posix.PATH_MAX,45 Os.linux, Os.macosx, Os.ios, Os.freebsd => posix.PATH_MAX,
44 // Each UTF-16LE character may be expanded to 3 UTF-8 bytes.46 // Each UTF-16LE character may be expanded to 3 UTF-8 bytes.
45 // If it would require 4 UTF-8 bytes, then there would be a surrogate47 // If it would require 4 UTF-8 bytes, then there would be a surrogate
46 // pair in the UTF-16LE, and we (over)account 3 bytes for it that way.48 // pair in the UTF-16LE, and we (over)account 3 bytes for it that way.
...@@ -101,7 +103,7 @@ const math = std.math;...@@ -101,7 +103,7 @@ const math = std.math;
101/// library implementation.103/// library implementation.
102pub fn getRandomBytes(buf: []u8) !void {104pub fn getRandomBytes(buf: []u8) !void {
103 switch (builtin.os) {105 switch (builtin.os) {
104 Os.linux => while (true) {106 Os.linux, Os.freebsd => while (true) {
105 // TODO check libc version and potentially call c.getrandom.107 // TODO check libc version and potentially call c.getrandom.
106 // See #397108 // See #397
107 const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));109 const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));
...@@ -174,7 +176,7 @@ pub fn abort() noreturn {...@@ -174,7 +176,7 @@ pub fn abort() noreturn {
174 c.abort();176 c.abort();
175 }177 }
176 switch (builtin.os) {178 switch (builtin.os) {
177 Os.linux, Os.macosx, Os.ios => {179 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
178 _ = posix.raise(posix.SIGABRT);180 _ = posix.raise(posix.SIGABRT);
179 _ = posix.raise(posix.SIGKILL);181 _ = posix.raise(posix.SIGKILL);
180 while (true) {}182 while (true) {}
...@@ -196,7 +198,7 @@ pub fn exit(status: u8) noreturn {...@@ -196,7 +198,7 @@ pub fn exit(status: u8) noreturn {
196 c.exit(status);198 c.exit(status);
197 }199 }
198 switch (builtin.os) {200 switch (builtin.os) {
199 Os.linux, Os.macosx, Os.ios => {201 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
200 posix.exit(status);202 posix.exit(status);
201 },203 },
202 Os.windows => {204 Os.windows => {
...@@ -419,7 +421,7 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off...@@ -419,7 +421,7 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off
419 }421 }
420 }422 }
421 },423 },
422 builtin.Os.linux => while (true) {424 builtin.Os.linux, builtin.Os.freebsd => while (true) {
423 const rc = posix.pwritev(fd, iov, count, offset);425 const rc = posix.pwritev(fd, iov, count, offset);
424 const err = posix.getErrno(rc);426 const err = posix.getErrno(rc);
425 switch (err) {427 switch (err) {
...@@ -687,7 +689,7 @@ pub fn getBaseAddress() usize {...@@ -687,7 +689,7 @@ pub fn getBaseAddress() usize {
687 };689 };
688 return phdr - @sizeOf(ElfHeader);690 return phdr - @sizeOf(ElfHeader);
689 },691 },
690 builtin.Os.macosx => return @ptrToInt(&std.c._mh_execute_header),692 builtin.Os.macosx, builtin.Os.freebsd => return @ptrToInt(&std.c._mh_execute_header),
691 builtin.Os.windows => return @ptrToInt(windows.GetModuleHandleW(null)),693 builtin.Os.windows => return @ptrToInt(windows.GetModuleHandleW(null)),
692 else => @compileError("Unsupported OS"),694 else => @compileError("Unsupported OS"),
693 }695 }
...@@ -1305,7 +1307,7 @@ pub fn deleteDirC(dir_path: [*]const u8) DeleteDirError!void {...@@ -1305,7 +1307,7 @@ pub fn deleteDirC(dir_path: [*]const u8) DeleteDirError!void {
1305 const dir_path_w = try windows_util.cStrToPrefixedFileW(dir_path);1307 const dir_path_w = try windows_util.cStrToPrefixedFileW(dir_path);
1306 return deleteDirW(&dir_path_w);1308 return deleteDirW(&dir_path_w);
1307 },1309 },
1308 Os.linux, Os.macosx, Os.ios => {1310 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
1309 const err = posix.getErrno(posix.rmdir(dir_path));1311 const err = posix.getErrno(posix.rmdir(dir_path));
1310 switch (err) {1312 switch (err) {
1311 0 => return,1313 0 => return,
...@@ -1348,7 +1350,7 @@ pub fn deleteDir(dir_path: []const u8) DeleteDirError!void {...@@ -1348,7 +1350,7 @@ pub fn deleteDir(dir_path: []const u8) DeleteDirError!void {
1348 const dir_path_w = try windows_util.sliceToPrefixedFileW(dir_path);1350 const dir_path_w = try windows_util.sliceToPrefixedFileW(dir_path);
1349 return deleteDirW(&dir_path_w);1351 return deleteDirW(&dir_path_w);
1350 },1352 },
1351 Os.linux, Os.macosx, Os.ios => {1353 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
1352 const dir_path_c = try toPosixPath(dir_path);1354 const dir_path_c = try toPosixPath(dir_path);
1353 return deleteDirC(&dir_path_c);1355 return deleteDirC(&dir_path_c);
1354 },1356 },
...@@ -1465,7 +1467,7 @@ pub const Dir = struct {...@@ -1465,7 +1467,7 @@ pub const Dir = struct {
1465 allocator: *Allocator,1467 allocator: *Allocator,
14661468
1467 pub const Handle = switch (builtin.os) {1469 pub const Handle = switch (builtin.os) {
1468 Os.macosx, Os.ios => struct {1470 Os.macosx, Os.ios, Os.freebsd => struct {
1469 fd: i32,1471 fd: i32,
1470 seek: i64,1472 seek: i64,
1471 buf: []u8,1473 buf: []u8,
...@@ -1541,7 +1543,7 @@ pub const Dir = struct {...@@ -1541,7 +1543,7 @@ pub const Dir = struct {
1541 .name_data = undefined,1543 .name_data = undefined,
1542 };1544 };
1543 },1545 },
1544 Os.macosx, Os.ios => Handle{1546 Os.macosx, Os.ios, Os.freebsd => Handle{
1545 .fd = try posixOpen(1547 .fd = try posixOpen(
1546 dir_path,1548 dir_path,
1547 posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC,1549 posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC,
...@@ -1572,7 +1574,7 @@ pub const Dir = struct {...@@ -1572,7 +1574,7 @@ pub const Dir = struct {
1572 Os.windows => {1574 Os.windows => {
1573 _ = windows.FindClose(self.handle.handle);1575 _ = windows.FindClose(self.handle.handle);
1574 },1576 },
1575 Os.macosx, Os.ios, Os.linux => {1577 Os.macosx, Os.ios, Os.linux, Os.freebsd => {
1576 self.allocator.free(self.handle.buf);1578 self.allocator.free(self.handle.buf);
1577 os.close(self.handle.fd);1579 os.close(self.handle.fd);
1578 },1580 },
...@@ -1587,6 +1589,7 @@ pub const Dir = struct {...@@ -1587,6 +1589,7 @@ pub const Dir = struct {
1587 Os.linux => return self.nextLinux(),1589 Os.linux => return self.nextLinux(),
1588 Os.macosx, Os.ios => return self.nextDarwin(),1590 Os.macosx, Os.ios => return self.nextDarwin(),
1589 Os.windows => return self.nextWindows(),1591 Os.windows => return self.nextWindows(),
1592 Os.freebsd => return self.nextFreebsd(),
1590 else => @compileError("unimplemented"),1593 else => @compileError("unimplemented"),
1591 }1594 }
1592 }1595 }
...@@ -1726,6 +1729,11 @@ pub const Dir = struct {...@@ -1726,6 +1729,11 @@ pub const Dir = struct {
1726 };1729 };
1727 }1730 }
1728 }1731 }
1732
1733 fn nextFreebsd(self: *Dir) !?Entry {
1734 self.handle.buf = try self.allocator.alloc(u8, page_size);
1735 return null; // TODO
1736 }
1729};1737};
17301738
1731pub fn changeCurDir(allocator: *Allocator, dir_path: []const u8) !void {1739pub fn changeCurDir(allocator: *Allocator, dir_path: []const u8) !void {
...@@ -2164,7 +2172,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) UnexpectedError {...@@ -2164,7 +2172,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) UnexpectedError {
2164pub fn openSelfExe() !os.File {2172pub fn openSelfExe() !os.File {
2165 switch (builtin.os) {2173 switch (builtin.os) {
2166 Os.linux => return os.File.openReadC(c"/proc/self/exe"),2174 Os.linux => return os.File.openReadC(c"/proc/self/exe"),
2167 Os.macosx, Os.ios => {2175 Os.macosx, Os.ios, Os.freebsd => {
2168 var buf: [MAX_PATH_BYTES]u8 = undefined;2176 var buf: [MAX_PATH_BYTES]u8 = undefined;
2169 const self_exe_path = try selfExePath(&buf);2177 const self_exe_path = try selfExePath(&buf);
2170 buf[self_exe_path.len] = 0;2178 buf[self_exe_path.len] = 0;
...@@ -2181,7 +2189,7 @@ pub fn openSelfExe() !os.File {...@@ -2181,7 +2189,7 @@ pub fn openSelfExe() !os.File {
21812189
2182test "openSelfExe" {2190test "openSelfExe" {
2183 switch (builtin.os) {2191 switch (builtin.os) {
2184 Os.linux, Os.macosx, Os.ios, Os.windows => (try openSelfExe()).close(),2192 Os.linux, Os.macosx, Os.ios, Os.windows, Os.freebsd => (try openSelfExe()).close(),
2185 else => return error.SkipZigTest, // Unsupported OS.2193 else => return error.SkipZigTest, // Unsupported OS.
2186 }2194 }
2187}2195}
...@@ -2212,6 +2220,7 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 {...@@ -2212,6 +2220,7 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 {
2212pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 {2220pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
2213 switch (builtin.os) {2221 switch (builtin.os) {
2214 Os.linux => return readLink(out_buffer, "/proc/self/exe"),2222 Os.linux => return readLink(out_buffer, "/proc/self/exe"),
2223 Os.freebsd => return readLink(out_buffer, "/proc/curproc/file"),
2215 Os.windows => {2224 Os.windows => {
2216 var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined;2225 var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined;
2217 const utf16le_slice = try selfExePathW(&utf16le_buf);2226 const utf16le_slice = try selfExePathW(&utf16le_buf);
...@@ -2250,7 +2259,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) ![]const u8 {...@@ -2250,7 +2259,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) ![]const u8 {
2250 // will not return null.2259 // will not return null.
2251 return path.dirname(full_exe_path).?;2260 return path.dirname(full_exe_path).?;
2252 },2261 },
2253 Os.windows, Os.macosx, Os.ios => {2262 Os.windows, Os.macosx, Os.ios, Os.freebsd => {
2254 const self_exe_path = try selfExePath(out_buffer);2263 const self_exe_path = try selfExePath(out_buffer);
2255 // Assume that the OS APIs return absolute paths, and therefore dirname2264 // Assume that the OS APIs return absolute paths, and therefore dirname
2256 // will not return null.2265 // will not return null.
...@@ -3095,10 +3104,13 @@ pub const CpuCountError = error{...@@ -3095,10 +3104,13 @@ pub const CpuCountError = error{
30953104
3096pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize {3105pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize {
3097 switch (builtin.os) {3106 switch (builtin.os) {
3098 builtin.Os.macosx => {3107 builtin.Os.macosx, builtin.Os.freebsd => {
3099 var count: c_int = undefined;3108 var count: c_int = undefined;
3100 var count_len: usize = @sizeOf(c_int);3109 var count_len: usize = @sizeOf(c_int);
3101 const rc = posix.sysctlbyname(c"hw.logicalcpu", @ptrCast(*c_void, &count), &count_len, null, 0);3110 const rc = posix.sysctlbyname(switch (builtin.os) {
3111 builtin.Os.macosx => c"hw.logicalcpu",
3112 else => c"hw.ncpu",
3113 }, @ptrCast(*c_void, &count), &count_len, null, 0);
3102 const err = posix.getErrno(rc);3114 const err = posix.getErrno(rc);
3103 switch (err) {3115 switch (err) {
3104 0 => return @intCast(usize, count),3116 0 => return @intCast(usize, count),
std/os/path.zig+10-1
...@@ -1188,6 +1188,15 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro...@@ -1188,6 +1188,15 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro
11881188
1189 return os.readLinkC(out_buffer, proc_path.ptr);1189 return os.readLinkC(out_buffer, proc_path.ptr);
1190 },1190 },
1191 Os.freebsd => { // XXX requires fdescfs
1192 const fd = try os.posixOpenC(pathname, posix.O_PATH | posix.O_NONBLOCK | posix.O_CLOEXEC, 0);
1193 defer os.close(fd);
1194
1195 var buf: ["/dev/fd/-2147483648".len]u8 = undefined;
1196 const proc_path = fmt.bufPrint(buf[0..], "/dev/fd/{}\x00", fd) catch unreachable;
1197
1198 return os.readLinkC(out_buffer, proc_path.ptr);
1199 },
1191 else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)),1200 else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)),
1192 }1201 }
1193}1202}
...@@ -1202,7 +1211,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError!...@@ -1202,7 +1211,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError!
1202 const pathname_w = try windows_util.sliceToPrefixedFileW(pathname);1211 const pathname_w = try windows_util.sliceToPrefixedFileW(pathname);
1203 return realW(out_buffer, &pathname_w);1212 return realW(out_buffer, &pathname_w);
1204 },1213 },
1205 Os.macosx, Os.ios, Os.linux => {1214 Os.macosx, Os.ios, Os.linux, Os.freebsd => {
1206 const pathname_c = try os.toPosixPath(pathname);1215 const pathname_c = try os.toPosixPath(pathname);
1207 return realC(out_buffer, &pathname_c);1216 return realC(out_buffer, &pathname_c);
1208 },1217 },
std/special/bootstrap.zig+14-4
...@@ -20,10 +20,17 @@ comptime {...@@ -20,10 +20,17 @@ comptime {
2020
21nakedcc fn _start() noreturn {21nakedcc fn _start() noreturn {
22 switch (builtin.arch) {22 switch (builtin.arch) {
23 builtin.Arch.x86_64 => {23 builtin.Arch.x86_64 => switch (builtin.os) {
24 argc_ptr = asm ("lea (%%rsp), %[argc]"24 builtin.Os.freebsd => {
25 : [argc] "=r" (-> [*]usize)25 argc_ptr = asm ("lea (%%rdi), %[argc]"
26 );26 : [argc] "=r" (-> [*]usize)
27 );
28 },
29 else => {
30 argc_ptr = asm ("lea (%%rsp), %[argc]"
31 : [argc] "=r" (-> [*]usize)
32 );
33 },
27 },34 },
28 builtin.Arch.i386 => {35 builtin.Arch.i386 => {
29 argc_ptr = asm ("lea (%%esp), %[argc]"36 argc_ptr = asm ("lea (%%esp), %[argc]"
...@@ -50,6 +57,9 @@ extern fn WinMainCRTStartup() noreturn {...@@ -50,6 +57,9 @@ extern fn WinMainCRTStartup() noreturn {
5057
51// TODO https://github.com/ziglang/zig/issues/26558// TODO https://github.com/ziglang/zig/issues/265
52fn posixCallMainAndExit() noreturn {59fn posixCallMainAndExit() noreturn {
60 if (builtin.os == builtin.Os.freebsd) {
61 @setAlignStack(16);
62 }
53 const argc = argc_ptr[0];63 const argc = argc_ptr[0];
54 const argv = @ptrCast([*][*]u8, argc_ptr + 1);64 const argv = @ptrCast([*][*]u8, argc_ptr + 1);
5565