| author | |
| committer | |
| log | d8b6fa9134e247658bb98155ba2e4243cd335b1b |
| tree | 55887d1fb589b00a6ec4ed9d51bc38b9821f4699 |
| parent | c464ecf3bf6d764ad06a20f10efc386e26fb7fa2 |
| parent | 2e08bd6be4a3b472fcaa69f0cb7683b269cdacdd |
| signature | Signed by PGP key 4AEE18F83AFDEB23 |
Progress towards tier 1 support for FreeBSD x86_6414 files changed, 274 insertions(+), 757 deletions(-)
.builds/freebsd.yml+23-2| ... | @@ -1,5 +1,4 @@ | ... | @@ -1,5 +1,4 @@ |
| 1 | arch: x86_64 | 1 | image: freebsd/latest |
| 2 | image: freebsd | ||
| 3 | packages: | 2 | packages: |
| 4 | - cmake | 3 | - cmake |
| 5 | - ninja | 4 | - ninja |
| ... | @@ -14,6 +13,28 @@ tasks: | ... | @@ -14,6 +13,28 @@ tasks: |
| 14 | - test: | | 13 | - test: | |
| 15 | cd zig/build | 14 | cd zig/build |
| 16 | bin/zig test ../test/behavior.zig | 15 | bin/zig test ../test/behavior.zig |
| 16 | bin/zig test ../std/special/compiler_rt/index.zig | ||
| 17 | |||
| 18 | bin/zig test ../test/behavior.zig --library c | ||
| 19 | bin/zig test ../std/special/compiler_rt/index.zig --library c | ||
| 20 | |||
| 21 | bin/zig test ../test/behavior.zig --release-fast | ||
| 22 | bin/zig test ../std/special/compiler_rt/index.zig --release-fast | ||
| 23 | |||
| 24 | bin/zig test ../test/behavior.zig --release-fast --library c | ||
| 25 | bin/zig test ../std/special/compiler_rt/index.zig --release-fast --library c | ||
| 26 | |||
| 27 | bin/zig test ../test/behavior.zig --release-small --library c | ||
| 28 | bin/zig test ../std/special/compiler_rt/index.zig --release-small --library c | ||
| 29 | |||
| 30 | bin/zig test ../test/behavior.zig --release-small | ||
| 31 | bin/zig test ../std/special/compiler_rt/index.zig --release-small | ||
| 32 | |||
| 33 | bin/zig test ../test/behavior.zig --release-safe | ||
| 34 | bin/zig test ../std/special/compiler_rt/index.zig --release-safe | ||
| 35 | |||
| 36 | bin/zig test ../test/behavior.zig --release-safe --library c | ||
| 37 | bin/zig test ../std/special/compiler_rt/index.zig --release-safe --library c | ||
| 17 | # TODO enable all tests | 38 | # TODO enable all tests |
| 18 | #bin/zig build --build-file ../build.zig test | 39 | #bin/zig build --build-file ../build.zig test |
| 19 | # TODO integrate with the download page updater and make a | 40 | # TODO integrate with the download page updater and make a |
CMakeLists.txt-2| ... | @@ -586,8 +586,6 @@ set(ZIG_STD_FILES | ... | @@ -586,8 +586,6 @@ set(ZIG_STD_FILES |
| 586 | "os/linux/arm64.zig" | 586 | "os/linux/arm64.zig" |
| 587 | "os/freebsd/errno.zig" | 587 | "os/freebsd/errno.zig" |
| 588 | "os/freebsd/index.zig" | 588 | "os/freebsd/index.zig" |
| 589 | "os/freebsd/syscall.zig" | ||
| 590 | "os/freebsd/x86_64.zig" | ||
| 591 | "os/path.zig" | 589 | "os/path.zig" |
| 592 | "os/time.zig" | 590 | "os/time.zig" |
| 593 | "os/uefi.zig" | 591 | "os/uefi.zig" |
build.zig+5-2| ... | @@ -293,11 +293,14 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void { | ... | @@ -293,11 +293,14 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void { |
| 293 | try addCxxKnownPath(b, ctx, exe, "libstdc++.a", | 293 | try addCxxKnownPath(b, ctx, exe, "libstdc++.a", |
| 294 | \\Unable to determine path to libstdc++.a | 294 | \\Unable to determine path to libstdc++.a |
| 295 | \\On Fedora, install libstdc++-static and try again. | 295 | \\On Fedora, install libstdc++-static and try again. |
| 296 | \\ | ||
| 297 | ); | 296 | ); |
| 298 | 297 | ||
| 299 | exe.linkSystemLibrary("pthread"); | 298 | exe.linkSystemLibrary("pthread"); |
| 300 | } else if (exe.target.isDarwin() or exe.target.isFreeBSD()) { | 299 | } else if (exe.target.isFreeBSD()) { |
| 300 | try addCxxKnownPath(b, ctx, exe, "libc++.a", null); | ||
| 301 | exe.linkSystemLibrary("pthread"); | ||
| 302 | } | ||
| 303 | else if (exe.target.isDarwin()) { | ||
| 301 | if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "")) { | 304 | if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "")) { |
| 302 | // Compiler is GCC. | 305 | // Compiler is GCC. |
| 303 | try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null); | 306 | try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null); |
src/analyze.cpp+1-1| ... | @@ -6374,7 +6374,7 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) { | ... | @@ -6374,7 +6374,7 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) { |
| 6374 | if (is_libc && g->libc_link_lib != nullptr) | 6374 | if (is_libc && g->libc_link_lib != nullptr) |
| 6375 | return g->libc_link_lib; | 6375 | return g->libc_link_lib; |
| 6376 | 6376 | ||
| 6377 | if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && g->zig_target.os != OsIOS) { | 6377 | if (g->enable_cache && is_libc && g->zig_target.os != OsMacOSX && g->zig_target.os != OsIOS && g->zig_target.os != OsFreeBSD) { |
| 6378 | fprintf(stderr, "TODO linking against libc is currently incompatible with `--cache on`.\n" | 6378 | fprintf(stderr, "TODO linking against libc is currently incompatible with `--cache on`.\n" |
| 6379 | "Zig is not yet capable of determining whether the libc installation has changed on subsequent builds.\n"); | 6379 | "Zig is not yet capable of determining whether the libc installation has changed on subsequent builds.\n"); |
| 6380 | exit(1); | 6380 | exit(1); |
src/codegen.cpp+2-1| ... | @@ -178,7 +178,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out | ... | @@ -178,7 +178,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out |
| 178 | 178 | ||
| 179 | // On Darwin/MacOS/iOS, we always link libSystem which contains libc. | 179 | // On Darwin/MacOS/iOS, we always link libSystem which contains libc. |
| 180 | if (g->zig_target.os == OsMacOSX || | 180 | if (g->zig_target.os == OsMacOSX || |
| 181 | g->zig_target.os == OsIOS) | 181 | g->zig_target.os == OsIOS || |
| 182 | 	g->zig_target.os == OsFreeBSD) | ||
| 182 | { | 183 | { |
| 183 | g->libc_link_lib = create_link_lib(buf_create_from_str("c")); | 184 | g->libc_link_lib = create_link_lib(buf_create_from_str("c")); |
| 184 | g->link_libs_list.append(g->libc_link_lib); | 185 | g->link_libs_list.append(g->libc_link_lib); |
std/c/freebsd.zig+62-2| ... | @@ -1,5 +1,3 @@ | ... | @@ -1,5 +1,3 @@ |
| 1 | const timespec = @import("../os/freebsd/index.zig").timespec; | ||
| 2 | |||
| 3 | extern "c" fn __error() *c_int; | 1 | extern "c" fn __error() *c_int; |
| 4 | pub const _errno = __error; | 2 | pub const _errno = __error; |
| 5 | 3 | ||
| ... | @@ -15,6 +13,15 @@ pub extern "c" fn kevent( | ... | @@ -15,6 +13,15 @@ pub extern "c" fn kevent( |
| 15 | pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | 13 | pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; |
| 16 | pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | 14 | pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; |
| 17 | pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; | 15 | pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; |
| 16 | pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize; | ||
| 17 | pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize; | ||
| 18 | pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int; | ||
| 19 | pub extern "c" fn preadv(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize; | ||
| 20 | pub extern "c" fn pwritev(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize; | ||
| 21 | pub extern "c" fn openat(fd: c_int, path: ?[*]const u8, flags: c_int) c_int; | ||
| 22 | pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int; | ||
| 23 | pub extern "c" fn setuid(uid: c_uint) c_int; | ||
| 24 | pub extern "c" fn kill(pid: c_int, sig: c_int) c_int; | ||
| 18 | 25 | ||
| 19 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. | 26 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. |
| 20 | pub const Kevent = extern struct { | 27 | pub const Kevent = extern struct { |
| ... | @@ -31,3 +38,56 @@ pub const pthread_attr_t = extern struct { | ... | @@ -31,3 +38,56 @@ pub const pthread_attr_t = extern struct { |
| 31 | __size: [56]u8, | 38 | __size: [56]u8, |
| 32 | __align: c_long, | 39 | __align: c_long, |
| 33 | }; | 40 | }; |
| 41 | |||
| 42 | pub const msghdr = extern struct { | ||
| 43 | msg_name: *u8, | ||
| 44 | msg_namelen: socklen_t, | ||
| 45 | msg_iov: *iovec, | ||
| 46 | msg_iovlen: i32, | ||
| 47 | __pad1: i32, | ||
| 48 | msg_control: *u8, | ||
| 49 | msg_controllen: socklen_t, | ||
| 50 | __pad2: socklen_t, | ||
| 51 | msg_flags: i32, | ||
| 52 | }; | ||
| 53 | |||
| 54 | pub const Stat = extern struct { | ||
| 55 | dev: u64, | ||
| 56 | ino: u64, | ||
| 57 | nlink: usize, | ||
| 58 | |||
| 59 | mode: u16, | ||
| 60 | __pad0: u16, | ||
| 61 | uid: u32, | ||
| 62 | gid: u32, | ||
| 63 | __pad1: u32, | ||
| 64 | rdev: u64, | ||
| 65 | |||
| 66 | atim: timespec, | ||
| 67 | mtim: timespec, | ||
| 68 | ctim: timespec, | ||
| 69 | birthtim: timespec, | ||
| 70 | |||
| 71 | size: i64, | ||
| 72 | blocks: i64, | ||
| 73 | blksize: isize, | ||
| 74 | flags: u32, | ||
| 75 | gen: u64, | ||
| 76 | __spare: [10]u64, | ||
| 77 | }; | ||
| 78 | |||
| 79 | pub const timespec = extern struct { | ||
| 80 | tv_sec: isize, | ||
| 81 | tv_nsec: isize, | ||
| 82 | }; | ||
| 83 | |||
| 84 | pub const dirent = extern struct { | ||
| 85 | d_fileno: usize, | ||
| 86 | d_off: i64, | ||
| 87 | d_reclen: u16, | ||
| 88 | d_type: u8, | ||
| 89 | d_pad0: u8, | ||
| 90 | d_namlen: u16, | ||
| 91 | d_pad1: u16, | ||
| 92 | d_name: [256]u8, | ||
| 93 | }; |
std/debug/index.zig+3-4| ... | @@ -264,7 +264,7 @@ pub fn writeCurrentStackTraceWindows( | ... | @@ -264,7 +264,7 @@ pub fn writeCurrentStackTraceWindows( |
| 264 | pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void { | 264 | pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void { |
| 265 | switch (builtin.os) { | 265 | switch (builtin.os) { |
| 266 | builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color), | 266 | builtin.Os.macosx => return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color), |
| 267 | builtin.Os.linux => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color), | 267 | builtin.Os.linux, builtin.Os.freebsd => return printSourceAtAddressLinux(debug_info, out_stream, address, tty_color), |
| 268 | builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color), | 268 | builtin.Os.windows => return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color), |
| 269 | else => return error.UnsupportedOperatingSystem, | 269 | else => return error.UnsupportedOperatingSystem, |
| 270 | } | 270 | } |
| ... | @@ -717,7 +717,7 @@ pub const OpenSelfDebugInfoError = error{ | ... | @@ -717,7 +717,7 @@ pub const OpenSelfDebugInfoError = error{ |
| 717 | 717 | ||
| 718 | pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo { | 718 | pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo { |
| 719 | switch (builtin.os) { | 719 | switch (builtin.os) { |
| 720 | builtin.Os.linux => return openSelfDebugInfoLinux(allocator), | 720 | builtin.Os.linux, builtin.Os.freebsd => return openSelfDebugInfoLinux(allocator), |
| 721 | builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator), | 721 | builtin.Os.macosx, builtin.Os.ios => return openSelfDebugInfoMacOs(allocator), |
| 722 | builtin.Os.windows => return openSelfDebugInfoWindows(allocator), | 722 | builtin.Os.windows => return openSelfDebugInfoWindows(allocator), |
| 723 | else => return error.UnsupportedOperatingSystem, | 723 | else => return error.UnsupportedOperatingSystem, |
| ... | @@ -1141,8 +1141,7 @@ pub const DebugInfo = switch (builtin.os) { | ... | @@ -1141,8 +1141,7 @@ pub const DebugInfo = switch (builtin.os) { |
| 1141 | sect_contribs: []pdb.SectionContribEntry, | 1141 | sect_contribs: []pdb.SectionContribEntry, |
| 1142 | modules: []Module, | 1142 | modules: []Module, |
| 1143 | }, | 1143 | }, |
| 1144 | builtin.Os.linux => DwarfInfo, | 1144 | builtin.Os.linux, builtin.Os.freebsd => DwarfInfo, |
| 1145 | builtin.Os.freebsd => struct {}, | ||
| 1146 | else => @compileError("Unsupported OS"), | 1145 | else => @compileError("Unsupported OS"), |
| 1147 | }; | 1146 | }; |
| 1148 | 1147 |
std/os/freebsd/index.zig+105-87| ... | @@ -1,17 +1,20 @@ | ... | @@ -1,17 +1,20 @@ |
| 1 | const assert = @import("../debug.zig").assert; | ||
| 2 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 3 | const arch = switch (builtin.arch) { | 2 | |
| 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"); | 3 | pub use @import("errno.zig"); |
| 9 | 4 | ||
| 10 | const std = @import("../../index.zig"); | 5 | const std = @import("../../index.zig"); |
| 11 | const c = std.c; | 6 | const c = std.c; |
| 7 | |||
| 8 | const assert = std.debug.assert; | ||
| 12 | const maxInt = std.math.maxInt; | 9 | const maxInt = std.math.maxInt; |
| 13 | pub const Kevent = c.Kevent; | 10 | pub const Kevent = c.Kevent; |
| 14 | 11 | ||
| 12 | pub const CTL_KERN = 1; | ||
| 13 | pub const CTL_DEBUG = 5; | ||
| 14 | |||
| 15 | pub const KERN_PROC = 14; // struct: process entries | ||
| 16 | pub const KERN_PROC_PATHNAME = 12; // path to executable | ||
| 17 | |||
| 15 | pub const PATH_MAX = 1024; | 18 | pub const PATH_MAX = 1024; |
| 16 | 19 | ||
| 17 | pub const STDIN_FILENO = 0; | 20 | pub const STDIN_FILENO = 0; |
| ... | @@ -95,26 +98,33 @@ pub const SIGLIBRT = 33; | ... | @@ -95,26 +98,33 @@ pub const SIGLIBRT = 33; |
| 95 | pub const SIGRTMIN = 65; | 98 | pub const SIGRTMIN = 65; |
| 96 | pub const SIGRTMAX = 126; | 99 | pub const SIGRTMAX = 126; |
| 97 | 100 | ||
| 98 | pub const O_RDONLY = 0o0; | 101 | // access function |
| 99 | pub const O_WRONLY = 0o1; | 102 | pub const F_OK = 0; // test for existence of file |
| 100 | pub const O_RDWR = 0o2; | 103 | pub const X_OK = 1; // test for execute or search permission |
| 101 | pub const O_ACCMODE = 0o3; | 104 | pub const W_OK = 2; // test for write permission |
| 102 | 105 | pub const R_OK = 4; // test for read permission | |
| 103 | pub const O_CREAT = 0o100; | 106 | |
| 104 | pub const O_EXCL = 0o200; | 107 | |
| 105 | pub const O_NOCTTY = 0o400; | 108 | pub const O_RDONLY = 0x0000; |
| 106 | pub const O_TRUNC = 0o1000; | 109 | pub const O_WRONLY = 0x0001; |
| 107 | pub const O_APPEND = 0o2000; | 110 | pub const O_RDWR = 0x0002; |
| 108 | pub const O_NONBLOCK = 0o4000; | 111 | pub const O_ACCMODE = 0x0003; |
| 112 | |||
| 113 | pub const O_CREAT = 0x0200; | ||
| 114 | pub const O_EXCL = 0x0800; | ||
| 115 | pub const O_NOCTTY = 0x8000; | ||
| 116 | pub const O_TRUNC = 0x0400; | ||
| 117 | pub const O_APPEND = 0x0008; | ||
| 118 | pub const O_NONBLOCK = 0x0004; | ||
| 109 | pub const O_DSYNC = 0o10000; | 119 | pub const O_DSYNC = 0o10000; |
| 110 | pub const O_SYNC = 0o4010000; | 120 | pub const O_SYNC = 0x0080; |
| 111 | pub const O_RSYNC = 0o4010000; | 121 | pub const O_RSYNC = 0o4010000; |
| 112 | pub const O_DIRECTORY = 0o200000; | 122 | pub const O_DIRECTORY = 0o200000; |
| 113 | pub const O_NOFOLLOW = 0o400000; | 123 | pub const O_NOFOLLOW = 0x0100; |
| 114 | pub const O_CLOEXEC = 0o2000000; | 124 | pub const O_CLOEXEC = 0x00100000; |
| 115 | 125 | ||
| 116 | pub const O_ASYNC = 0o20000; | 126 | pub const O_ASYNC = 0x0040; |
| 117 | pub const O_DIRECT = 0o40000; | 127 | pub const O_DIRECT = 0x00010000; |
| 118 | pub const O_LARGEFILE = 0; | 128 | pub const O_LARGEFILE = 0; |
| 119 | pub const O_NOATIME = 0o1000000; | 129 | pub const O_NOATIME = 0o1000000; |
| 120 | pub const O_PATH = 0o10000000; | 130 | pub const O_PATH = 0o10000000; |
| ... | @@ -539,96 +549,117 @@ pub fn getErrno(r: usize) usize { | ... | @@ -539,96 +549,117 @@ pub fn getErrno(r: usize) usize { |
| 539 | } | 549 | } |
| 540 | 550 | ||
| 541 | pub fn dup2(old: i32, new: i32) usize { | 551 | pub fn dup2(old: i32, new: i32) usize { |
| 542 | return arch.syscall2(SYS_dup2, @bitCast(usize, isize(old)), @bitCast(usize, isize(new))); | 552 | return errnoWrap(c.dup2(old, new)); |
| 543 | } | 553 | } |
| 544 | 554 | ||
| 545 | pub fn chdir(path: [*]const u8) usize { | 555 | pub fn chdir(path: [*]const u8) usize { |
| 546 | return arch.syscall1(SYS_chdir, @ptrToInt(path)); | 556 | return errnoWrap(c.chdir(path)); |
| 547 | } | 557 | } |
| 548 | 558 | ||
| 549 | pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { | 559 | pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { |
| 550 | return arch.syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); | 560 | return errnoWrap(c.execve(path, argv, envp)); |
| 551 | } | 561 | } |
| 552 | 562 | ||
| 553 | pub fn fork() usize { | 563 | pub fn fork() usize { |
| 554 | return arch.syscall0(SYS_fork); | 564 | return errnoWrap(c.fork()); |
| 565 | } | ||
| 566 | |||
| 567 | pub fn access(path: [*]const u8, mode: u32) usize { | ||
| 568 | return errnoWrap(c.access(path, mode)); | ||
| 555 | } | 569 | } |
| 556 | 570 | ||
| 557 | pub fn getcwd(buf: [*]u8, size: usize) usize { | 571 | pub fn getcwd(buf: [*]u8, size: usize) usize { |
| 558 | return arch.syscall2(SYS___getcwd, @ptrToInt(buf), size); | 572 | return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0; |
| 559 | } | 573 | } |
| 560 | 574 | ||
| 561 | pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { | 575 | pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { |
| 562 | return arch.syscall3(SYS_getdents, @bitCast(usize, isize(fd)), @ptrToInt(dirp), count); | 576 | return errnoWrap(@bitCast(isize, c.getdents(fd, drip, count))); |
| 577 | } | ||
| 578 | |||
| 579 | pub fn getdirentries(fd: i32, buf_ptr: [*]u8, buf_len: usize, basep: *i64) usize { | ||
| 580 | return errnoWrap(@bitCast(isize, c.getdirentries(fd, buf_ptr, buf_len, basep))); | ||
| 581 | } | ||
| 582 | |||
| 583 | pub fn realpath(noalias filename: [*]const u8, noalias resolved_name: [*]u8) usize { | ||
| 584 | return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0; | ||
| 563 | } | 585 | } |
| 564 | 586 | ||
| 565 | pub fn isatty(fd: i32) bool { | 587 | pub fn isatty(fd: i32) bool { |
| 566 | var wsz: winsize = undefined; | 588 | return c.isatty(fd) != 0; |
| 567 | return arch.syscall3(SYS_ioctl, @bitCast(usize, isize(fd)), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | ||
| 568 | } | 589 | } |
| 569 | 590 | ||
| 570 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { | 591 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { |
| 571 | return arch.syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | 592 | return errnoWrap(c.readlink(path, buf_ptr, buf_len)); |
| 572 | } | 593 | } |
| 573 | 594 | ||
| 574 | pub fn mkdir(path: [*]const u8, mode: u32) usize { | 595 | pub fn mkdir(path: [*]const u8, mode: u32) usize { |
| 575 | return arch.syscall2(SYS_mkdir, @ptrToInt(path), mode); | 596 | return errnoWrap(c.mkdir(path, mode)); |
| 576 | } | 597 | } |
| 577 | 598 | ||
| 578 | pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { | 599 | pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize { |
| 579 | return arch.syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset)); | 600 | const ptr_result = c.mmap( |
| 601 | @ptrCast(*c_void, address), | ||
| 602 | length, | ||
| 603 | @bitCast(c_int, @intCast(c_uint, prot)), | ||
| 604 | @bitCast(c_int, c_uint(flags)), | ||
| 605 | fd, | ||
| 606 | offset, | ||
| 607 | ); | ||
| 608 | const isize_result = @bitCast(isize, @ptrToInt(ptr_result)); | ||
| 609 | return errnoWrap(isize_result); | ||
| 580 | } | 610 | } |
| 581 | 611 | ||
| 582 | pub fn munmap(address: usize, length: usize) usize { | 612 | pub fn munmap(address: usize, length: usize) usize { |
| 583 | return arch.syscall2(SYS_munmap, address, length); | 613 | return errnoWrap(c.munmap(@intToPtr(*c_void, address), length)); |
| 584 | } | 614 | } |
| 585 | 615 | ||
| 586 | pub fn read(fd: i32, buf: [*]u8, count: usize) usize { | 616 | pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize { |
| 587 | return arch.syscall3(SYS_read, @bitCast(usize, isize(fd)), @ptrToInt(buf), count); | 617 | return errnoWrap(c.read(fd, @ptrCast(*c_void, buf), nbyte)); |
| 588 | } | 618 | } |
| 589 | 619 | ||
| 590 | pub fn rmdir(path: [*]const u8) usize { | 620 | pub fn rmdir(path: [*]const u8) usize { |
| 591 | return arch.syscall1(SYS_rmdir, @ptrToInt(path)); | 621 | return errnoWrap(c.rmdir(path)); |
| 592 | } | 622 | } |
| 593 | 623 | ||
| 594 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { | 624 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { |
| 595 | return arch.syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); | 625 | return errnoWrap(c.symlink(existing, new)); |
| 596 | } | 626 | } |
| 597 | 627 | ||
| 598 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { | 628 | pub fn pread(fd: i32, buf: [*]u8, nbyte: usize, offset: u64) usize { |
| 599 | return arch.syscall4(SYS_pread, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset); | 629 | return errnoWrap(c.pread(fd, @ptrCast(*c_void, buf), nbyte, offset)); |
| 600 | } | 630 | } |
| 601 | 631 | ||
| 602 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize { | 632 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize { |
| 603 | return arch.syscall4(SYS_preadv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset); | 633 | return errnoWrap(c.preadv(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset)); |
| 604 | } | 634 | } |
| 605 | 635 | ||
| 606 | pub fn pipe(fd: *[2]i32) usize { | 636 | pub fn pipe(fd: *[2]i32) usize { |
| 607 | return pipe2(fd, 0); | 637 | return pipe2(fd, 0); |
| 608 | } | 638 | } |
| 609 | 639 | ||
| 610 | pub fn pipe2(fd: *[2]i32, flags: usize) usize { | 640 | pub fn pipe2(fd: *[2]i32, flags: u32) usize { |
| 611 | return arch.syscall2(SYS_pipe2, @ptrToInt(fd), flags); | 641 | comptime assert(i32.bit_count == c_int.bit_count); |
| 642 | return errnoWrap(c.pipe2(@ptrCast(*[2]c_int, fd), flags)); | ||
| 612 | } | 643 | } |
| 613 | 644 | ||
| 614 | pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { | 645 | pub fn write(fd: i32, buf: [*]const u8, nbyte: usize) usize { |
| 615 | return arch.syscall3(SYS_write, @bitCast(usize, isize(fd)), @ptrToInt(buf), count); | 646 | return errnoWrap(c.write(fd, @ptrCast(*const c_void, buf), nbyte)); |
| 616 | } | 647 | } |
| 617 | 648 | ||
| 618 | pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { | 649 | pub fn pwrite(fd: i32, buf: [*]const u8, nbyte: usize, offset: u64) usize { |
| 619 | return arch.syscall4(SYS_pwrite, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset); | 650 | return errnoWrap(c.pwrite(fd, @ptrCast(*const c_void, buf), nbyte, offset)); |
| 620 | } | 651 | } |
| 621 | 652 | ||
| 622 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize { | 653 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize { |
| 623 | return arch.syscall4(SYS_pwritev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset); | 654 | return errnoWrap(c.pwritev(fd, @ptrCast(*const c_void, iov), @intCast(c_int, count), offset)); |
| 624 | } | 655 | } |
| 625 | 656 | ||
| 626 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { | 657 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { |
| 627 | return arch.syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); | 658 | return errnoWrap(c.rename(old, new)); |
| 628 | } | 659 | } |
| 629 | 660 | ||
| 630 | pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { | 661 | pub fn open(path: [*]const u8, flags: u32, mode: usize) usize { |
| 631 | return arch.syscall3(SYS_open, @ptrToInt(path), flags, perm); | 662 | return errnoWrap(c.open(path, @bitCast(c_int, flags), mode)); |
| 632 | } | 663 | } |
| 633 | 664 | ||
| 634 | pub fn create(path: [*]const u8, perm: usize) usize { | 665 | pub fn create(path: [*]const u8, perm: usize) usize { |
| ... | @@ -636,56 +667,52 @@ pub fn create(path: [*]const u8, perm: usize) usize { | ... | @@ -636,56 +667,52 @@ pub fn create(path: [*]const u8, perm: usize) usize { |
| 636 | } | 667 | } |
| 637 | 668 | ||
| 638 | pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { | 669 | pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { |
| 639 | return arch.syscall4(SYS_openat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode); | 670 | return errnoWrap(c.openat(@bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode)); |
| 640 | } | 671 | } |
| 641 | 672 | ||
| 642 | pub fn close(fd: i32) usize { | 673 | pub fn close(fd: i32) usize { |
| 643 | return arch.syscall1(SYS_close, @bitCast(usize, isize(fd))); | 674 | return errnoWrap(c.close(fd)); |
| 644 | } | ||
| 645 | |||
| 646 | pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { | ||
| 647 | return arch.syscall3(SYS_lseek, @bitCast(usize, isize(fd)), @bitCast(usize, offset), ref_pos); | ||
| 648 | } | 675 | } |
| 649 | 676 | ||
| 650 | pub fn exit(status: i32) noreturn { | 677 | pub fn lseek(fd: i32, offset: isize, whence: c_int) usize { |
| 651 | _ = arch.syscall1(SYS_exit, @bitCast(usize, isize(status))); | 678 | return errnoWrap(c.lseek(fd, offset, whence)); |
| 652 | unreachable; | ||
| 653 | } | 679 | } |
| 654 | 680 | ||
| 655 | pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { | 681 | pub fn exit(code: i32) noreturn { |
| 656 | return arch.syscall3(SYS_getrandom, @ptrToInt(buf), count, usize(flags)); | 682 | c.exit(code); |
| 657 | } | 683 | } |
| 658 | 684 | ||
| 659 | pub fn kill(pid: i32, sig: i32) usize { | 685 | pub fn kill(pid: i32, sig: i32) usize { |
| 660 | return arch.syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig))); | 686 | return errnoWrap(c.kill(pid, sig)); |
| 661 | } | 687 | } |
| 662 | 688 | ||
| 663 | pub fn unlink(path: [*]const u8) usize { | 689 | pub fn unlink(path: [*]const u8) usize { |
| 664 | return arch.syscall1(SYS_unlink, @ptrToInt(path)); | 690 | return errnoWrap(c.unlink(path)); |
| 665 | } | 691 | } |
| 666 | 692 | ||
| 667 | pub fn waitpid(pid: i32, status: *i32, options: i32) usize { | 693 | pub fn waitpid(pid: i32, status: *i32, options: u32) usize { |
| 668 | return arch.syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); | 694 | comptime assert(i32.bit_count == c_int.bit_count); |
| 695 | return errnoWrap(c.waitpid(pid, @ptrCast(*c_int, status), @bitCast(c_int, options))); | ||
| 669 | } | 696 | } |
| 670 | 697 | ||
| 671 | pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { | 698 | pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { |
| 672 | return arch.syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); | 699 | return errnoWrap(c.nanosleep(req, rem)); |
| 673 | } | 700 | } |
| 674 | 701 | ||
| 675 | pub fn setuid(uid: u32) usize { | 702 | pub fn setuid(uid: u32) usize { |
| 676 | return arch.syscall1(SYS_setuid, uid); | 703 | return errnoWrap(c.setuid(uid)); |
| 677 | } | 704 | } |
| 678 | 705 | ||
| 679 | pub fn setgid(gid: u32) usize { | 706 | pub fn setgid(gid: u32) usize { |
| 680 | return arch.syscall1(SYS_setgid, gid); | 707 | return errnoWrap(c.setgid(gid)); |
| 681 | } | 708 | } |
| 682 | 709 | ||
| 683 | pub fn setreuid(ruid: u32, euid: u32) usize { | 710 | pub fn setreuid(ruid: u32, euid: u32) usize { |
| 684 | return arch.syscall2(SYS_setreuid, ruid, euid); | 711 | return errnoWrap(c.setreuid(ruid, euid)); |
| 685 | } | 712 | } |
| 686 | 713 | ||
| 687 | pub fn setregid(rgid: u32, egid: u32) usize { | 714 | pub fn setregid(rgid: u32, egid: u32) usize { |
| 688 | return arch.syscall2(SYS_setregid, rgid, egid); | 715 | return errnoWrap(c.setregid(rgid, egid)); |
| 689 | } | 716 | } |
| 690 | 717 | ||
| 691 | const NSIG = 32; | 718 | const NSIG = 32; |
| ... | @@ -730,25 +757,16 @@ pub const sigset_t = extern struct { | ... | @@ -730,25 +757,16 @@ pub const sigset_t = extern struct { |
| 730 | }; | 757 | }; |
| 731 | 758 | ||
| 732 | pub fn raise(sig: i32) usize { | 759 | pub fn raise(sig: i32) usize { |
| 733 | // TODO have a chat with the freebsd folks and make sure there's no bug in | 760 | return errnoWrap(c.raise(sig)); |
| 734 | // their libc. musl-libc blocks signals in between these calls because | ||
| 735 | // if a signal handler runs and forks between the gettid and sending the | ||
| 736 | // signal, the parent will get 2 signals, one from itself and one from the child | ||
| 737 | // if the protection does not belong here, then it belongs in abort(), | ||
| 738 | // like it does in freebsd's libc. | ||
| 739 | var id: usize = undefined; | ||
| 740 | const rc = arch.syscall1(SYS_thr_self, @ptrToInt(&id)); | ||
| 741 | if (getErrno(rc) != 0) return rc; | ||
| 742 | return arch.syscall2(SYS_thr_kill, id, @bitCast(usize, isize(sig))); | ||
| 743 | } | 761 | } |
| 744 | 762 | ||
| 745 | pub const Stat = arch.Stat; | 763 | pub const Stat = c.Stat; |
| 746 | pub const timespec = arch.timespec; | 764 | pub const dirent = c.dirent; |
| 765 | pub const timespec = c.timespec; | ||
| 747 | 766 | ||
| 748 | pub fn fstat(fd: i32, stat_buf: *Stat) usize { | 767 | pub fn fstat(fd: i32, buf: *c.Stat) usize { |
| 749 | return arch.syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); | 768 | return errnoWrap(c.fstat(fd, buf)); |
| 750 | } | 769 | } |
| 751 | |||
| 752 | pub const iovec = extern struct { | 770 | pub const iovec = extern struct { |
| 753 | iov_base: [*]u8, | 771 | iov_base: [*]u8, |
| 754 | iov_len: usize, | 772 | iov_len: usize, |
std/os/freebsd/syscall.zig deleted-493| ... | @@ -1,493 +0,0 @@ | ||
| 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 deleted-136| ... | @@ -1,136 +0,0 @@ | ||
| 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/index.zig+67-5| ... | @@ -107,7 +107,7 @@ const math = std.math; | ... | @@ -107,7 +107,7 @@ const math = std.math; |
| 107 | /// library implementation. | 107 | /// library implementation. |
| 108 | pub fn getRandomBytes(buf: []u8) !void { | 108 | pub fn getRandomBytes(buf: []u8) !void { |
| 109 | switch (builtin.os) { | 109 | switch (builtin.os) { |
| 110 | Os.linux, Os.freebsd => while (true) { | 110 | Os.linux => while (true) { |
| 111 | // TODO check libc version and potentially call c.getrandom. | 111 | // TODO check libc version and potentially call c.getrandom. |
| 112 | // See #397 | 112 | // See #397 |
| 113 | const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0)); | 113 | const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0)); |
| ... | @@ -120,7 +120,7 @@ pub fn getRandomBytes(buf: []u8) !void { | ... | @@ -120,7 +120,7 @@ pub fn getRandomBytes(buf: []u8) !void { |
| 120 | else => return unexpectedErrorPosix(errno), | 120 | else => return unexpectedErrorPosix(errno), |
| 121 | } | 121 | } |
| 122 | }, | 122 | }, |
| 123 | Os.macosx, Os.ios => return getRandomBytesDevURandom(buf), | 123 | Os.macosx, Os.ios, Os.freebsd => return getRandomBytesDevURandom(buf), |
| 124 | Os.windows => { | 124 | Os.windows => { |
| 125 | // Call RtlGenRandom() instead of CryptGetRandom() on Windows | 125 | // Call RtlGenRandom() instead of CryptGetRandom() on Windows |
| 126 | // https://github.com/rust-lang-nursery/rand/issues/111 | 126 | // https://github.com/rust-lang-nursery/rand/issues/111 |
| ... | @@ -1766,8 +1766,57 @@ pub const Dir = struct { | ... | @@ -1766,8 +1766,57 @@ pub const Dir = struct { |
| 1766 | } | 1766 | } |
| 1767 | 1767 | ||
| 1768 | fn nextFreebsd(self: *Dir) !?Entry { | 1768 | fn nextFreebsd(self: *Dir) !?Entry { |
| 1769 | //self.handle.buf = try self.allocator.alloc(u8, page_size); | 1769 | start_over: while (true) { |
| 1770 | @compileError("TODO implement dirs for FreeBSD"); | 1770 | if (self.handle.index >= self.handle.end_index) { |
| 1771 | if (self.handle.buf.len == 0) { | ||
| 1772 | self.handle.buf = try self.allocator.alloc(u8, page_size); | ||
| 1773 | } | ||
| 1774 | |||
| 1775 | while (true) { | ||
| 1776 | const result = posix.getdirentries(self.handle.fd, self.handle.buf.ptr, self.handle.buf.len, &self.handle.seek); | ||
| 1777 | const err = posix.getErrno(result); | ||
| 1778 | if (err > 0) { | ||
| 1779 | switch (err) { | ||
| 1780 | posix.EBADF, posix.EFAULT, posix.ENOTDIR => unreachable, | ||
| 1781 | posix.EINVAL => { | ||
| 1782 | self.handle.buf = try self.allocator.realloc(u8, self.handle.buf, self.handle.buf.len * 2); | ||
| 1783 | continue; | ||
| 1784 | }, | ||
| 1785 | else => return unexpectedErrorPosix(err), | ||
| 1786 | } | ||
| 1787 | } | ||
| 1788 | if (result == 0) return null; | ||
| 1789 | self.handle.index = 0; | ||
| 1790 | self.handle.end_index = result; | ||
| 1791 | break; | ||
| 1792 | } | ||
| 1793 | } | ||
| 1794 | const freebsd_entry = @ptrCast(*align(1) posix.dirent, &self.handle.buf[self.handle.index]); | ||
| 1795 | const next_index = self.handle.index + freebsd_entry.d_reclen; | ||
| 1796 | self.handle.index = next_index; | ||
| 1797 | |||
| 1798 | const name = @ptrCast([*]u8, &freebsd_entry.d_name)[0..freebsd_entry.d_namlen]; | ||
| 1799 | |||
| 1800 | if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) { | ||
| 1801 | continue :start_over; | ||
| 1802 | } | ||
| 1803 | |||
| 1804 | const entry_kind = switch (freebsd_entry.d_type) { | ||
| 1805 | posix.DT_BLK => Entry.Kind.BlockDevice, | ||
| 1806 | posix.DT_CHR => Entry.Kind.CharacterDevice, | ||
| 1807 | posix.DT_DIR => Entry.Kind.Directory, | ||
| 1808 | posix.DT_FIFO => Entry.Kind.NamedPipe, | ||
| 1809 | posix.DT_LNK => Entry.Kind.SymLink, | ||
| 1810 | posix.DT_REG => Entry.Kind.File, | ||
| 1811 | posix.DT_SOCK => Entry.Kind.UnixDomainSocket, | ||
| 1812 | posix.DT_WHT => Entry.Kind.Whiteout, | ||
| 1813 | else => Entry.Kind.Unknown, | ||
| 1814 | }; | ||
| 1815 | return Entry{ | ||
| 1816 | .name = name, | ||
| 1817 | .kind = entry_kind, | ||
| 1818 | }; | ||
| 1819 | } | ||
| 1771 | } | 1820 | } |
| 1772 | }; | 1821 | }; |
| 1773 | 1822 | ||
| ... | @@ -2255,7 +2304,20 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 { | ... | @@ -2255,7 +2304,20 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 { |
| 2255 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | 2304 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 2256 | switch (builtin.os) { | 2305 | switch (builtin.os) { |
| 2257 | Os.linux => return readLink(out_buffer, "/proc/self/exe"), | 2306 | Os.linux => return readLink(out_buffer, "/proc/self/exe"), |
| 2258 | Os.freebsd => return readLink(out_buffer, "/proc/curproc/file"), | 2307 | Os.freebsd => { |
| 2308 | var mib = [4]c_int{ posix.CTL_KERN, posix.KERN_PROC, posix.KERN_PROC_PATHNAME, -1}; | ||
| 2309 | var out_len: usize = out_buffer.len; | ||
| 2310 | const err = posix.getErrno(posix.sysctl(&mib, 4, out_buffer, &out_len, null, 0)); | ||
| 2311 | |||
| 2312 | if (err == 0 ) return mem.toSlice(u8, out_buffer); | ||
| 2313 | |||
| 2314 | return switch (err) { | ||
| 2315 | posix.EFAULT => error.BadAdress, | ||
| 2316 | posix.EPERM => error.PermissionDenied, | ||
| 2317 | else => unexpectedErrorPosix(err), | ||
| 2318 | }; | ||
| 2319 | |||
| 2320 | }, | ||
| 2259 | Os.windows => { | 2321 | Os.windows => { |
| 2260 | var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined; | 2322 | var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined; |
| 2261 | const utf16le_slice = try selfExePathW(&utf16le_buf); | 2323 | const utf16le_slice = try selfExePathW(&utf16le_buf); |
std/os/path.zig+1-10| ... | @@ -1162,7 +1162,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro | ... | @@ -1162,7 +1162,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro |
| 1162 | const pathname_w = try windows_util.cStrToPrefixedFileW(pathname); | 1162 | const pathname_w = try windows_util.cStrToPrefixedFileW(pathname); |
| 1163 | return realW(out_buffer, pathname_w); | 1163 | return realW(out_buffer, pathname_w); |
| 1164 | }, | 1164 | }, |
| 1165 | Os.macosx, Os.ios => { | 1165 | Os.freebsd, Os.macosx, Os.ios => { |
| 1166 | // TODO instead of calling the libc function here, port the implementation to Zig | 1166 | // TODO instead of calling the libc function here, port the implementation to Zig |
| 1167 | const err = posix.getErrno(posix.realpath(pathname, out_buffer)); | 1167 | const err = posix.getErrno(posix.realpath(pathname, out_buffer)); |
| 1168 | switch (err) { | 1168 | switch (err) { |
| ... | @@ -1189,15 +1189,6 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro | ... | @@ -1189,15 +1189,6 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro |
| 1189 | 1189 | ||
| 1190 | return os.readLinkC(out_buffer, proc_path.ptr); | 1190 | return os.readLinkC(out_buffer, proc_path.ptr); |
| 1191 | }, | 1191 | }, |
| 1192 | Os.freebsd => { // XXX requires fdescfs | ||
| 1193 | const fd = try os.posixOpenC(pathname, posix.O_PATH | posix.O_NONBLOCK | posix.O_CLOEXEC, 0); | ||
| 1194 | defer os.close(fd); | ||
| 1195 | |||
| 1196 | var buf: ["/dev/fd/-2147483648\x00".len]u8 = undefined; | ||
| 1197 | const proc_path = fmt.bufPrint(buf[0..], "/dev/fd/{}\x00", fd) catch unreachable; | ||
| 1198 | |||
| 1199 | return os.readLinkC(out_buffer, proc_path.ptr); | ||
| 1200 | }, | ||
| 1201 | else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)), | 1192 | else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)), |
| 1202 | } | 1193 | } |
| 1203 | } | 1194 | } |
std/os/time.zig+1-1| ... | @@ -13,7 +13,7 @@ pub const epoch = @import("epoch.zig"); | ... | @@ -13,7 +13,7 @@ pub const epoch = @import("epoch.zig"); |
| 13 | /// Sleep for the specified duration | 13 | /// Sleep for the specified duration |
| 14 | pub fn sleep(nanoseconds: u64) void { | 14 | pub fn sleep(nanoseconds: u64) void { |
| 15 | switch (builtin.os) { | 15 | switch (builtin.os) { |
| 16 | Os.linux, Os.macosx, Os.ios => { | 16 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 17 | const s = nanoseconds / ns_per_s; | 17 | const s = nanoseconds / ns_per_s; |
| 18 | const ns = nanoseconds % ns_per_s; | 18 | const ns = nanoseconds % ns_per_s; |
| 19 | posixSleep(@intCast(u63, s), @intCast(u63, ns)); | 19 | posixSleep(@intCast(u63, s), @intCast(u63, ns)); |
std/special/bootstrap.zig+4-11| ... | @@ -20,17 +20,10 @@ comptime { | ... | @@ -20,17 +20,10 @@ comptime { |
| 20 | 20 | ||
| 21 | nakedcc fn _start() noreturn { | 21 | nakedcc fn _start() noreturn { |
| 22 | switch (builtin.arch) { | 22 | switch (builtin.arch) { |
| 23 | builtin.Arch.x86_64 => switch (builtin.os) { | 23 | builtin.Arch.x86_64 => { |
| 24 | builtin.Os.freebsd => { | 24 | argc_ptr = asm ("lea (%%rsp), %[argc]" |
| 25 | argc_ptr = asm ("lea (%%rdi), %[argc]" | 25 | : [argc] "=r" (-> [*]usize) |
| 26 | : [argc] "=r" (-> [*]usize) | 26 | ); |
| 27 | ); | ||
| 28 | }, | ||
| 29 | else => { | ||
| 30 | argc_ptr = asm ("lea (%%rsp), %[argc]" | ||
| 31 | : [argc] "=r" (-> [*]usize) | ||
| 32 | ); | ||
| 33 | }, | ||
| 34 | }, | 27 | }, |
| 35 | builtin.Arch.i386 => { | 28 | builtin.Arch.i386 => { |
| 36 | argc_ptr = asm ("lea (%%esp), %[argc]" | 29 | argc_ptr = asm ("lea (%%esp), %[argc]" |