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