authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-12-29 12:49:23-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-12-29 12:49:23-05:00
logd8b6fa9134e247658bb98155ba2e4243cd335b1b
tree55887d1fb589b00a6ec4ed9d51bc38b9821f4699
parentc464ecf3bf6d764ad06a20f10efc386e26fb7fa2
parent2e08bd6be4a3b472fcaa69f0cb7683b269cdacdd
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #1859 from mgxm/fbsd2

Progress towards tier 1 support for FreeBSD x86_64

14 files changed, 274 insertions(+), 757 deletions(-)

.builds/freebsd.yml+23-2
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1arch: x86_641image: freebsd/latest
2image: freebsd
3packages:2packages:
4 - cmake3 - cmake
5 - ninja4 - ninja
...@@ -14,6 +13,28 @@ tasks:...@@ -14,6 +13,28 @@ tasks:
14 - test: |13 - test: |
15 cd zig/build14 cd zig/build
16 bin/zig test ../test/behavior.zig15 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 tests38 # TODO enable all tests
18 #bin/zig build --build-file ../build.zig test39 #bin/zig build --build-file ../build.zig test
19 # TODO integrate with the download page updater and make a40 # 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++.a294 \\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 );
298297
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;
63766376
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
178178
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 @@
1const timespec = @import("../os/freebsd/index.zig").timespec;
2
3extern "c" fn __error() *c_int;1extern "c" fn __error() *c_int;
4pub const _errno = __error;2pub const _errno = __error;
53
...@@ -15,6 +13,15 @@ pub extern "c" fn kevent(...@@ -15,6 +13,15 @@ pub extern "c" fn kevent(
15pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;13pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
16pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;14pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
17pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;15pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
16pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;
17pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
18pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int;
19pub extern "c" fn preadv(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
20pub extern "c" fn pwritev(fd: c_int, iov: *const c_void, iovcnt: c_int, offset: usize) isize;
21pub extern "c" fn openat(fd: c_int, path: ?[*]const u8, flags: c_int) c_int;
22pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
23pub extern "c" fn setuid(uid: c_uint) c_int;
24pub extern "c" fn kill(pid: c_int, sig: c_int) c_int;
1825
19/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.26/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
20pub const Kevent = extern struct {27pub 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
42pub 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
54pub 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
79pub const timespec = extern struct {
80 tv_sec: isize,
81 tv_nsec: isize,
82};
83
84pub 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(
264pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {264pub 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{
717717
718pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {718pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
719 switch (builtin.os) {719 switch (builtin.os) {
720 builtin.Os.linux => 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};
11481147
std/os/freebsd/index.zig+105-87
...@@ -1,17 +1,20 @@...@@ -1,17 +1,20 @@
1const assert = @import("../debug.zig").assert;
2const builtin = @import("builtin");1const builtin = @import("builtin");
3const arch = switch (builtin.arch) {2
4 builtin.Arch.x86_64 => @import("x86_64.zig"),
5 else => @compileError("unsupported arch"),
6};
7pub use @import("syscall.zig");
8pub use @import("errno.zig");3pub use @import("errno.zig");
94
10const std = @import("../../index.zig");5const std = @import("../../index.zig");
11const c = std.c;6const c = std.c;
7
8const assert = std.debug.assert;
12const maxInt = std.math.maxInt;9const maxInt = std.math.maxInt;
13pub const Kevent = c.Kevent;10pub const Kevent = c.Kevent;
1411
12pub const CTL_KERN = 1;
13pub const CTL_DEBUG = 5;
14
15pub const KERN_PROC = 14; // struct: process entries
16pub const KERN_PROC_PATHNAME = 12; // path to executable
17
15pub const PATH_MAX = 1024;18pub const PATH_MAX = 1024;
1619
17pub const STDIN_FILENO = 0;20pub const STDIN_FILENO = 0;
...@@ -95,26 +98,33 @@ pub const SIGLIBRT = 33;...@@ -95,26 +98,33 @@ pub const SIGLIBRT = 33;
95pub const SIGRTMIN = 65;98pub const SIGRTMIN = 65;
96pub const SIGRTMAX = 126;99pub const SIGRTMAX = 126;
97100
98pub const O_RDONLY = 0o0;101// access function
99pub const O_WRONLY = 0o1;102pub const F_OK = 0; // test for existence of file
100pub const O_RDWR = 0o2;103pub const X_OK = 1; // test for execute or search permission
101pub const O_ACCMODE = 0o3;104pub const W_OK = 2; // test for write permission
102105pub const R_OK = 4; // test for read permission
103pub const O_CREAT = 0o100;106
104pub const O_EXCL = 0o200;107
105pub const O_NOCTTY = 0o400;108pub const O_RDONLY = 0x0000;
106pub const O_TRUNC = 0o1000;109pub const O_WRONLY = 0x0001;
107pub const O_APPEND = 0o2000;110pub const O_RDWR = 0x0002;
108pub const O_NONBLOCK = 0o4000;111pub const O_ACCMODE = 0x0003;
112
113pub const O_CREAT = 0x0200;
114pub const O_EXCL = 0x0800;
115pub const O_NOCTTY = 0x8000;
116pub const O_TRUNC = 0x0400;
117pub const O_APPEND = 0x0008;
118pub const O_NONBLOCK = 0x0004;
109pub const O_DSYNC = 0o10000;119pub const O_DSYNC = 0o10000;
110pub const O_SYNC = 0o4010000;120pub const O_SYNC = 0x0080;
111pub const O_RSYNC = 0o4010000;121pub const O_RSYNC = 0o4010000;
112pub const O_DIRECTORY = 0o200000;122pub const O_DIRECTORY = 0o200000;
113pub const O_NOFOLLOW = 0o400000;123pub const O_NOFOLLOW = 0x0100;
114pub const O_CLOEXEC = 0o2000000;124pub const O_CLOEXEC = 0x00100000;
115125
116pub const O_ASYNC = 0o20000;126pub const O_ASYNC = 0x0040;
117pub const O_DIRECT = 0o40000;127pub const O_DIRECT = 0x00010000;
118pub const O_LARGEFILE = 0;128pub const O_LARGEFILE = 0;
119pub const O_NOATIME = 0o1000000;129pub const O_NOATIME = 0o1000000;
120pub const O_PATH = 0o10000000;130pub 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}
540550
541pub fn dup2(old: i32, new: i32) usize {551pub 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}
544554
545pub fn chdir(path: [*]const u8) usize {555pub fn chdir(path: [*]const u8) usize {
546 return arch.syscall1(SYS_chdir, @ptrToInt(path));556 return errnoWrap(c.chdir(path));
547}557}
548558
549pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {559pub 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}
552562
553pub fn fork() usize {563pub fn fork() usize {
554 return arch.syscall0(SYS_fork);564 return errnoWrap(c.fork());
565}
566
567pub fn access(path: [*]const u8, mode: u32) usize {
568 return errnoWrap(c.access(path, mode));
555}569}
556570
557pub fn getcwd(buf: [*]u8, size: usize) usize {571pub 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}
560574
561pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {575pub 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
579pub 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
583pub 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}
564586
565pub fn isatty(fd: i32) bool {587pub 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}
569590
570pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {591pub 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}
573594
574pub fn mkdir(path: [*]const u8, mode: u32) usize {595pub 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}
577598
578pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {599pub 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}
581611
582pub fn munmap(address: usize, length: usize) usize {612pub 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}
585615
586pub fn read(fd: i32, buf: [*]u8, count: usize) usize {616pub 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}
589619
590pub fn rmdir(path: [*]const u8) usize {620pub fn rmdir(path: [*]const u8) usize {
591 return arch.syscall1(SYS_rmdir, @ptrToInt(path));621 return errnoWrap(c.rmdir(path));
592}622}
593623
594pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {624pub 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}
597627
598pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {628pub 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}
601631
602pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize {632pub 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}
605635
606pub fn pipe(fd: *[2]i32) usize {636pub fn pipe(fd: *[2]i32) usize {
607 return pipe2(fd, 0);637 return pipe2(fd, 0);
608}638}
609639
610pub fn pipe2(fd: *[2]i32, flags: usize) usize {640pub 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}
613644
614pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {645pub 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}
617648
618pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {649pub 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}
621652
622pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize {653pub 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}
625656
626pub fn rename(old: [*]const u8, new: [*]const u8) usize {657pub 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}
629660
630pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {661pub 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}
633664
634pub fn create(path: [*]const u8, perm: usize) usize {665pub 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}
637668
638pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {669pub 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}
641672
642pub fn close(fd: i32) usize {673pub fn close(fd: i32) usize {
643 return arch.syscall1(SYS_close, @bitCast(usize, isize(fd)));674 return errnoWrap(c.close(fd));
644}
645
646pub 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}
649676
650pub fn exit(status: i32) noreturn {677pub 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}
654680
655pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {681pub fn exit(code: i32) noreturn {
656 return arch.syscall3(SYS_getrandom, @ptrToInt(buf), count, usize(flags));682 c.exit(code);
657}683}
658684
659pub fn kill(pid: i32, sig: i32) usize {685pub 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}
662688
663pub fn unlink(path: [*]const u8) usize {689pub fn unlink(path: [*]const u8) usize {
664 return arch.syscall1(SYS_unlink, @ptrToInt(path));690 return errnoWrap(c.unlink(path));
665}691}
666692
667pub fn waitpid(pid: i32, status: *i32, options: i32) usize {693pub 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}
670697
671pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {698pub 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}
674701
675pub fn setuid(uid: u32) usize {702pub fn setuid(uid: u32) usize {
676 return arch.syscall1(SYS_setuid, uid);703 return errnoWrap(c.setuid(uid));
677}704}
678705
679pub fn setgid(gid: u32) usize {706pub fn setgid(gid: u32) usize {
680 return arch.syscall1(SYS_setgid, gid);707 return errnoWrap(c.setgid(gid));
681}708}
682709
683pub fn setreuid(ruid: u32, euid: u32) usize {710pub fn setreuid(ruid: u32, euid: u32) usize {
684 return arch.syscall2(SYS_setreuid, ruid, euid);711 return errnoWrap(c.setreuid(ruid, euid));
685}712}
686713
687pub fn setregid(rgid: u32, egid: u32) usize {714pub fn setregid(rgid: u32, egid: u32) usize {
688 return arch.syscall2(SYS_setregid, rgid, egid);715 return errnoWrap(c.setregid(rgid, egid));
689}716}
690717
691const NSIG = 32;718const NSIG = 32;
...@@ -730,25 +757,16 @@ pub const sigset_t = extern struct {...@@ -730,25 +757,16 @@ pub const sigset_t = extern struct {
730};757};
731758
732pub fn raise(sig: i32) usize {759pub fn raise(sig: i32) usize {
733 // TODO have a chat with the freebsd folks and make sure there's no bug in760 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}
744762
745pub const Stat = arch.Stat;763pub const Stat = c.Stat;
746pub const timespec = arch.timespec;764pub const dirent = c.dirent;
765pub const timespec = c.timespec;
747766
748pub fn fstat(fd: i32, stat_buf: *Stat) usize {767pub 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
752pub const iovec = extern struct {770pub 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 @@
1pub const SYS_syscall = 0;
2pub const SYS_exit = 1;
3pub const SYS_fork = 2;
4pub const SYS_read = 3;
5pub const SYS_write = 4;
6pub const SYS_open = 5;
7pub const SYS_close = 6;
8pub const SYS_wait4 = 7;
9// 8 is old creat
10pub const SYS_link = 9;
11pub const SYS_unlink = 10;
12// 11 is obsolete execv
13pub const SYS_chdir = 12;
14pub const SYS_fchdir = 13;
15pub const SYS_freebsd11_mknod = 14;
16pub const SYS_chmod = 15;
17pub const SYS_chown = 16;
18pub const SYS_break = 17;
19// 18 is freebsd4 getfsstat
20// 19 is old lseek
21pub const SYS_getpid = 20;
22pub const SYS_mount = 21;
23pub const SYS_unmount = 22;
24pub const SYS_setuid = 23;
25pub const SYS_getuid = 24;
26pub const SYS_geteuid = 25;
27pub const SYS_ptrace = 26;
28pub const SYS_recvmsg = 27;
29pub const SYS_sendmsg = 28;
30pub const SYS_recvfrom = 29;
31pub const SYS_accept = 30;
32pub const SYS_getpeername = 31;
33pub const SYS_getsockname = 32;
34pub const SYS_access = 33;
35pub const SYS_chflags = 34;
36pub const SYS_fchflags = 35;
37pub const SYS_sync = 36;
38pub const SYS_kill = 37;
39// 38 is old stat
40pub const SYS_getppid = 39;
41// 40 is old lstat
42pub const SYS_dup = 41;
43pub const SYS_freebsd10_pipe = 42;
44pub const SYS_getegid = 43;
45pub const SYS_profil = 44;
46pub const SYS_ktrace = 45;
47// 46 is old sigaction
48pub const SYS_getgid = 47;
49// 48 is old sigprocmask
50pub const SYS_getlogin = 49;
51pub const SYS_setlogin = 50;
52pub const SYS_acct = 51;
53// 52 is old sigpending
54pub const SYS_sigaltstack = 53;
55pub const SYS_ioctl = 54;
56pub const SYS_reboot = 55;
57pub const SYS_revoke = 56;
58pub const SYS_symlink = 57;
59pub const SYS_readlink = 58;
60pub const SYS_execve = 59;
61pub const SYS_umask = 60;
62pub const SYS_chroot = 61;
63// 62 is old fstat
64// 63 is old getkerninfo
65// 64 is old getpagesize
66pub const SYS_msync = 65;
67pub const SYS_vfork = 66;
68// 67 is obsolete vread
69// 68 is obsolete vwrite
70// 69 is obsolete sbrk (still present on some platforms)
71pub const SYS_sstk = 70;
72// 71 is old mmap
73pub const SYS_vadvise = 72;
74pub const SYS_munmap = 73;
75pub const SYS_mprotect = 74;
76pub const SYS_madvise = 75;
77// 76 is obsolete vhangup
78// 77 is obsolete vlimit
79pub const SYS_mincore = 78;
80pub const SYS_getgroups = 79;
81pub const SYS_setgroups = 80;
82pub const SYS_getpgrp = 81;
83pub const SYS_setpgid = 82;
84pub const SYS_setitimer = 83;
85// 84 is old wait
86pub const SYS_swapon = 85;
87pub const SYS_getitimer = 86;
88// 87 is old gethostname
89// 88 is old sethostname
90pub const SYS_getdtablesize = 89;
91pub const SYS_dup2 = 90;
92pub const SYS_fcntl = 92;
93pub const SYS_select = 93;
94pub const SYS_fsync = 95;
95pub const SYS_setpriority = 96;
96pub const SYS_socket = 97;
97pub const SYS_connect = 98;
98// 99 is old accept
99pub const SYS_getpriority = 100;
100// 101 is old send
101// 102 is old recv
102// 103 is old sigreturn
103pub const SYS_bind = 104;
104pub const SYS_setsockopt = 105;
105pub const SYS_listen = 106;
106// 107 is obsolete vtimes
107// 108 is old sigvec
108// 109 is old sigblock
109// 110 is old sigsetmask
110// 111 is old sigsuspend
111// 112 is old sigstack
112// 113 is old recvmsg
113// 114 is old sendmsg
114// 115 is obsolete vtrace
115pub const SYS_gettimeofday = 116;
116pub const SYS_getrusage = 117;
117pub const SYS_getsockopt = 118;
118pub const SYS_readv = 120;
119pub const SYS_writev = 121;
120pub const SYS_settimeofday = 122;
121pub const SYS_fchown = 123;
122pub const SYS_fchmod = 124;
123// 125 is old recvfrom
124pub const SYS_setreuid = 126;
125pub const SYS_setregid = 127;
126pub const SYS_rename = 128;
127// 129 is old truncate
128// 130 is old ftruncate
129pub const SYS_flock = 131;
130pub const SYS_mkfifo = 132;
131pub const SYS_sendto = 133;
132pub const SYS_shutdown = 134;
133pub const SYS_socketpair = 135;
134pub const SYS_mkdir = 136;
135pub const SYS_rmdir = 137;
136pub const SYS_utimes = 138;
137// 139 is obsolete 4.2 sigreturn
138pub const SYS_adjtime = 140;
139// 141 is old getpeername
140// 142 is old gethostid
141// 143 is old sethostid
142// 144 is old getrlimit
143// 145 is old setrlimit
144// 146 is old killpg
145pub const SYS_setsid = 147;
146pub const SYS_quotactl = 148;
147// 149 is old quota
148// 150 is old getsockname
149pub const SYS_nlm_syscall = 154;
150pub const SYS_nfssvc = 155;
151// 156 is old getdirentries
152// 157 is freebsd4 statfs
153// 158 is freebsd4 fstatfs
154pub const SYS_lgetfh = 160;
155pub const SYS_getfh = 161;
156// 162 is freebsd4 getdomainname
157// 163 is freebsd4 setdomainname
158// 164 is freebsd4 uname
159pub const SYS_sysarch = 165;
160pub const SYS_rtprio = 166;
161pub const SYS_semsys = 169;
162pub const SYS_msgsys = 170;
163pub const SYS_shmsys = 171;
164// 173 is freebsd6 pread
165// 174 is freebsd6 pwrite
166pub const SYS_setfib = 175;
167pub const SYS_ntp_adjtime = 176;
168pub const SYS_setgid = 181;
169pub const SYS_setegid = 182;
170pub const SYS_seteuid = 183;
171// 184 is obsolete lfs_bmapv
172// 185 is obsolete lfs_markv
173// 186 is obsolete lfs_segclean
174// 187 is obsolete lfs_segwait
175pub const SYS_freebsd11_stat = 188;
176pub const SYS_freebsd11_fstat = 189;
177pub const SYS_freebsd11_lstat = 190;
178pub const SYS_pathconf = 191;
179pub const SYS_fpathconf = 192;
180pub const SYS_getrlimit = 194;
181pub const SYS_setrlimit = 195;
182pub const SYS_freebsd11_getdirentries = 196;
183// 197 is freebsd6 mmap
184pub const SYS___syscall = 198;
185// 199 is freebsd6 lseek
186// 200 is freebsd6 truncate
187// 201 is freebsd6 ftruncate
188pub const SYS___sysctl = 202;
189pub const SYS_mlock = 203;
190pub const SYS_munlock = 204;
191pub const SYS_undelete = 205;
192pub const SYS_futimes = 206;
193pub const SYS_getpgid = 207;
194pub const SYS_poll = 209;
195pub const SYS_freebsd7___semctl = 220;
196pub const SYS_semget = 221;
197pub const SYS_semop = 222;
198pub const SYS_freebsd7_msgctl = 224;
199pub const SYS_msgget = 225;
200pub const SYS_msgsnd = 226;
201pub const SYS_msgrcv = 227;
202pub const SYS_shmat = 228;
203pub const SYS_freebsd7_shmctl = 229;
204pub const SYS_shmdt = 230;
205pub const SYS_shmget = 231;
206pub const SYS_clock_gettime = 232;
207pub const SYS_clock_settime = 233;
208pub const SYS_clock_getres = 234;
209pub const SYS_ktimer_create = 235;
210pub const SYS_ktimer_delete = 236;
211pub const SYS_ktimer_settime = 237;
212pub const SYS_ktimer_gettime = 238;
213pub const SYS_ktimer_getoverrun = 239;
214pub const SYS_nanosleep = 240;
215pub const SYS_ffclock_getcounter = 241;
216pub const SYS_ffclock_setestimate = 242;
217pub const SYS_ffclock_getestimate = 243;
218pub const SYS_clock_nanosleep = 244;
219pub const SYS_clock_getcpuclockid2 = 247;
220pub const SYS_ntp_gettime = 248;
221pub const SYS_minherit = 250;
222pub const SYS_rfork = 251;
223// 252 is obsolete openbsd_poll
224pub const SYS_issetugid = 253;
225pub const SYS_lchown = 254;
226pub const SYS_aio_read = 255;
227pub const SYS_aio_write = 256;
228pub const SYS_lio_listio = 257;
229pub const SYS_freebsd11_getdents = 272;
230pub const SYS_lchmod = 274;
231// 275 is obsolete netbsd_lchown
232pub const SYS_lutimes = 276;
233// 277 is obsolete netbsd_msync
234pub const SYS_freebsd11_nstat = 278;
235pub const SYS_freebsd11_nfstat = 279;
236pub const SYS_freebsd11_nlstat = 280;
237pub const SYS_preadv = 289;
238pub const SYS_pwritev = 290;
239// 297 is freebsd4 fhstatfs
240pub const SYS_fhopen = 298;
241pub const SYS_freebsd11_fhstat = 299;
242pub const SYS_modnext = 300;
243pub const SYS_modstat = 301;
244pub const SYS_modfnext = 302;
245pub const SYS_modfind = 303;
246pub const SYS_kldload = 304;
247pub const SYS_kldunload = 305;
248pub const SYS_kldfind = 306;
249pub const SYS_kldnext = 307;
250pub const SYS_kldstat = 308;
251pub const SYS_kldfirstmod = 309;
252pub const SYS_getsid = 310;
253pub const SYS_setresuid = 311;
254pub const SYS_setresgid = 312;
255// 313 is obsolete signanosleep
256pub const SYS_aio_return = 314;
257pub const SYS_aio_suspend = 315;
258pub const SYS_aio_cancel = 316;
259pub const SYS_aio_error = 317;
260// 318 is freebsd6 aio_read
261// 319 is freebsd6 aio_write
262// 320 is freebsd6 lio_listio
263pub const SYS_yield = 321;
264// 322 is obsolete thr_sleep
265// 323 is obsolete thr_wakeup
266pub const SYS_mlockall = 324;
267pub const SYS_munlockall = 325;
268pub const SYS___getcwd = 326;
269pub const SYS_sched_setparam = 327;
270pub const SYS_sched_getparam = 328;
271pub const SYS_sched_setscheduler = 329;
272pub const SYS_sched_getscheduler = 330;
273pub const SYS_sched_yield = 331;
274pub const SYS_sched_get_priority_max = 332;
275pub const SYS_sched_get_priority_min = 333;
276pub const SYS_sched_rr_get_interval = 334;
277pub const SYS_utrace = 335;
278// 336 is freebsd4 sendfile
279pub const SYS_kldsym = 337;
280pub const SYS_jail = 338;
281pub const SYS_nnpfs_syscall = 339;
282pub const SYS_sigprocmask = 340;
283pub const SYS_sigsuspend = 341;
284// 342 is freebsd4 sigaction
285pub const SYS_sigpending = 343;
286// 344 is freebsd4 sigreturn
287pub const SYS_sigtimedwait = 345;
288pub const SYS_sigwaitinfo = 346;
289pub const SYS___acl_get_file = 347;
290pub const SYS___acl_set_file = 348;
291pub const SYS___acl_get_fd = 349;
292pub const SYS___acl_set_fd = 350;
293pub const SYS___acl_delete_file = 351;
294pub const SYS___acl_delete_fd = 352;
295pub const SYS___acl_aclcheck_file = 353;
296pub const SYS___acl_aclcheck_fd = 354;
297pub const SYS_extattrctl = 355;
298pub const SYS_extattr_set_file = 356;
299pub const SYS_extattr_get_file = 357;
300pub const SYS_extattr_delete_file = 358;
301pub const SYS_aio_waitcomplete = 359;
302pub const SYS_getresuid = 360;
303pub const SYS_getresgid = 361;
304pub const SYS_kqueue = 362;
305pub const SYS_freebsd11_kevent = 363;
306// 364 is obsolete __cap_get_proc
307// 365 is obsolete __cap_set_proc
308// 366 is obsolete __cap_get_fd
309// 367 is obsolete __cap_get_file
310// 368 is obsolete __cap_set_fd
311// 369 is obsolete __cap_set_file
312pub const SYS_extattr_set_fd = 371;
313pub const SYS_extattr_get_fd = 372;
314pub const SYS_extattr_delete_fd = 373;
315pub const SYS___setugid = 374;
316pub const SYS_eaccess = 376;
317pub const SYS_afs3_syscall = 377;
318pub const SYS_nmount = 378;
319// 379 is obsolete kse_exit
320// 380 is obsolete kse_wakeup
321// 381 is obsolete kse_create
322// 382 is obsolete kse_thr_interrupt
323// 383 is obsolete kse_release
324pub const SYS___mac_get_proc = 384;
325pub const SYS___mac_set_proc = 385;
326pub const SYS___mac_get_fd = 386;
327pub const SYS___mac_get_file = 387;
328pub const SYS___mac_set_fd = 388;
329pub const SYS___mac_set_file = 389;
330pub const SYS_kenv = 390;
331pub const SYS_lchflags = 391;
332pub const SYS_uuidgen = 392;
333pub const SYS_sendfile = 393;
334pub const SYS_mac_syscall = 394;
335pub const SYS_freebsd11_getfsstat = 395;
336pub const SYS_freebsd11_statfs = 396;
337pub const SYS_freebsd11_fstatfs = 397;
338pub const SYS_freebsd11_fhstatfs = 398;
339pub const SYS_ksem_close = 400;
340pub const SYS_ksem_post = 401;
341pub const SYS_ksem_wait = 402;
342pub const SYS_ksem_trywait = 403;
343pub const SYS_ksem_init = 404;
344pub const SYS_ksem_open = 405;
345pub const SYS_ksem_unlink = 406;
346pub const SYS_ksem_getvalue = 407;
347pub const SYS_ksem_destroy = 408;
348pub const SYS___mac_get_pid = 409;
349pub const SYS___mac_get_link = 410;
350pub const SYS___mac_set_link = 411;
351pub const SYS_extattr_set_link = 412;
352pub const SYS_extattr_get_link = 413;
353pub const SYS_extattr_delete_link = 414;
354pub const SYS___mac_execve = 415;
355pub const SYS_sigaction = 416;
356pub const SYS_sigreturn = 417;
357pub const SYS_getcontext = 421;
358pub const SYS_setcontext = 422;
359pub const SYS_swapcontext = 423;
360pub const SYS_swapoff = 424;
361pub const SYS___acl_get_link = 425;
362pub const SYS___acl_set_link = 426;
363pub const SYS___acl_delete_link = 427;
364pub const SYS___acl_aclcheck_link = 428;
365pub const SYS_sigwait = 429;
366pub const SYS_thr_create = 430;
367pub const SYS_thr_exit = 431;
368pub const SYS_thr_self = 432;
369pub const SYS_thr_kill = 433;
370pub const SYS_jail_attach = 436;
371pub const SYS_extattr_list_fd = 437;
372pub const SYS_extattr_list_file = 438;
373pub const SYS_extattr_list_link = 439;
374// 440 is obsolete kse_switchin
375pub const SYS_ksem_timedwait = 441;
376pub const SYS_thr_suspend = 442;
377pub const SYS_thr_wake = 443;
378pub const SYS_kldunloadf = 444;
379pub const SYS_audit = 445;
380pub const SYS_auditon = 446;
381pub const SYS_getauid = 447;
382pub const SYS_setauid = 448;
383pub const SYS_getaudit = 449;
384pub const SYS_setaudit = 450;
385pub const SYS_getaudit_addr = 451;
386pub const SYS_setaudit_addr = 452;
387pub const SYS_auditctl = 453;
388pub const SYS__umtx_op = 454;
389pub const SYS_thr_new = 455;
390pub const SYS_sigqueue = 456;
391pub const SYS_kmq_open = 457;
392pub const SYS_kmq_setattr = 458;
393pub const SYS_kmq_timedreceive = 459;
394pub const SYS_kmq_timedsend = 460;
395pub const SYS_kmq_notify = 461;
396pub const SYS_kmq_unlink = 462;
397pub const SYS_abort2 = 463;
398pub const SYS_thr_set_name = 464;
399pub const SYS_aio_fsync = 465;
400pub const SYS_rtprio_thread = 466;
401pub const SYS_sctp_peeloff = 471;
402pub const SYS_sctp_generic_sendmsg = 472;
403pub const SYS_sctp_generic_sendmsg_iov = 473;
404pub const SYS_sctp_generic_recvmsg = 474;
405pub const SYS_pread = 475;
406pub const SYS_pwrite = 476;
407pub const SYS_mmap = 477;
408pub const SYS_lseek = 478;
409pub const SYS_truncate = 479;
410pub const SYS_ftruncate = 480;
411pub const SYS_thr_kill2 = 481;
412pub const SYS_shm_open = 482;
413pub const SYS_shm_unlink = 483;
414pub const SYS_cpuset = 484;
415pub const SYS_cpuset_setid = 485;
416pub const SYS_cpuset_getid = 486;
417pub const SYS_cpuset_getaffinity = 487;
418pub const SYS_cpuset_setaffinity = 488;
419pub const SYS_faccessat = 489;
420pub const SYS_fchmodat = 490;
421pub const SYS_fchownat = 491;
422pub const SYS_fexecve = 492;
423pub const SYS_freebsd11_fstatat = 493;
424pub const SYS_futimesat = 494;
425pub const SYS_linkat = 495;
426pub const SYS_mkdirat = 496;
427pub const SYS_mkfifoat = 497;
428pub const SYS_freebsd11_mknodat = 498;
429pub const SYS_openat = 499;
430pub const SYS_readlinkat = 500;
431pub const SYS_renameat = 501;
432pub const SYS_symlinkat = 502;
433pub const SYS_unlinkat = 503;
434pub const SYS_posix_openpt = 504;
435pub const SYS_gssd_syscall = 505;
436pub const SYS_jail_get = 506;
437pub const SYS_jail_set = 507;
438pub const SYS_jail_remove = 508;
439pub const SYS_closefrom = 509;
440pub const SYS___semctl = 510;
441pub const SYS_msgctl = 511;
442pub const SYS_shmctl = 512;
443pub const SYS_lpathconf = 513;
444// 514 is obsolete cap_new
445pub const SYS___cap_rights_get = 515;
446pub const SYS_cap_enter = 516;
447pub const SYS_cap_getmode = 517;
448pub const SYS_pdfork = 518;
449pub const SYS_pdkill = 519;
450pub const SYS_pdgetpid = 520;
451pub const SYS_pselect = 522;
452pub const SYS_getloginclass = 523;
453pub const SYS_setloginclass = 524;
454pub const SYS_rctl_get_racct = 525;
455pub const SYS_rctl_get_rules = 526;
456pub const SYS_rctl_get_limits = 527;
457pub const SYS_rctl_add_rule = 528;
458pub const SYS_rctl_remove_rule = 529;
459pub const SYS_posix_fallocate = 530;
460pub const SYS_posix_fadvise = 531;
461pub const SYS_wait6 = 532;
462pub const SYS_cap_rights_limit = 533;
463pub const SYS_cap_ioctls_limit = 534;
464pub const SYS_cap_ioctls_get = 535;
465pub const SYS_cap_fcntls_limit = 536;
466pub const SYS_cap_fcntls_get = 537;
467pub const SYS_bindat = 538;
468pub const SYS_connectat = 539;
469pub const SYS_chflagsat = 540;
470pub const SYS_accept4 = 541;
471pub const SYS_pipe2 = 542;
472pub const SYS_aio_mlock = 543;
473pub const SYS_procctl = 544;
474pub const SYS_ppoll = 545;
475pub const SYS_futimens = 546;
476pub const SYS_utimensat = 547;
477// 548 is obsolete numa_getaffinity
478// 549 is obsolete numa_setaffinity
479pub const SYS_fdatasync = 550;
480pub const SYS_fstat = 551;
481pub const SYS_fstatat = 552;
482pub const SYS_fhstat = 553;
483pub const SYS_getdirentries = 554;
484pub const SYS_statfs = 555;
485pub const SYS_fstatfs = 556;
486pub const SYS_getfsstat = 557;
487pub const SYS_fhstatfs = 558;
488pub const SYS_mknodat = 559;
489pub const SYS_kevent = 560;
490pub const SYS_cpuset_getdomain = 561;
491pub const SYS_cpuset_setdomain = 562;
492pub const SYS_getrandom = 563;
493pub const SYS_MAXSYSCALL = 564;
std/os/freebsd/x86_64.zig deleted-136
...@@ -1,136 +0,0 @@
1const freebsd = @import("index.zig");
2const socklen_t = freebsd.socklen_t;
3const iovec = freebsd.iovec;
4
5pub const SYS_sbrk = 69;
6
7pub fn syscall0(number: usize) usize {
8 return asm volatile ("syscall"
9 : [ret] "={rax}" (-> usize)
10 : [number] "{rax}" (number)
11 : "rcx", "r11"
12 );
13}
14
15pub fn syscall1(number: usize, arg1: usize) usize {
16 return asm volatile ("syscall"
17 : [ret] "={rax}" (-> usize)
18 : [number] "{rax}" (number),
19 [arg1] "{rdi}" (arg1)
20 : "rcx", "r11"
21 );
22}
23
24pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
25 return asm volatile ("syscall"
26 : [ret] "={rax}" (-> usize)
27 : [number] "{rax}" (number),
28 [arg1] "{rdi}" (arg1),
29 [arg2] "{rsi}" (arg2)
30 : "rcx", "r11"
31 );
32}
33
34pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
35 return asm volatile ("syscall"
36 : [ret] "={rax}" (-> usize)
37 : [number] "{rax}" (number),
38 [arg1] "{rdi}" (arg1),
39 [arg2] "{rsi}" (arg2),
40 [arg3] "{rdx}" (arg3)
41 : "rcx", "r11"
42 );
43}
44
45pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
46 return asm volatile ("syscall"
47 : [ret] "={rax}" (-> usize)
48 : [number] "{rax}" (number),
49 [arg1] "{rdi}" (arg1),
50 [arg2] "{rsi}" (arg2),
51 [arg3] "{rdx}" (arg3),
52 [arg4] "{r10}" (arg4)
53 : "rcx", "r11"
54 );
55}
56
57pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
58 return asm volatile ("syscall"
59 : [ret] "={rax}" (-> usize)
60 : [number] "{rax}" (number),
61 [arg1] "{rdi}" (arg1),
62 [arg2] "{rsi}" (arg2),
63 [arg3] "{rdx}" (arg3),
64 [arg4] "{r10}" (arg4),
65 [arg5] "{r8}" (arg5)
66 : "rcx", "r11"
67 );
68}
69
70pub fn syscall6(
71 number: usize,
72 arg1: usize,
73 arg2: usize,
74 arg3: usize,
75 arg4: usize,
76 arg5: usize,
77 arg6: usize,
78) usize {
79 return asm volatile ("syscall"
80 : [ret] "={rax}" (-> usize)
81 : [number] "{rax}" (number),
82 [arg1] "{rdi}" (arg1),
83 [arg2] "{rsi}" (arg2),
84 [arg3] "{rdx}" (arg3),
85 [arg4] "{r10}" (arg4),
86 [arg5] "{r8}" (arg5),
87 [arg6] "{r9}" (arg6)
88 : "rcx", "r11"
89 );
90}
91
92pub nakedcc fn restore_rt() void {
93 asm volatile ("syscall"
94 :
95 : [number] "{rax}" (usize(SYS_rt_sigreturn))
96 : "rcx", "r11"
97 );
98}
99
100pub const msghdr = extern struct {
101 msg_name: *u8,
102 msg_namelen: socklen_t,
103 msg_iov: *iovec,
104 msg_iovlen: i32,
105 __pad1: i32,
106 msg_control: *u8,
107 msg_controllen: socklen_t,
108 __pad2: socklen_t,
109 msg_flags: i32,
110};
111
112/// Renamed to Stat to not conflict with the stat function.
113pub const Stat = extern struct {
114 dev: u64,
115 ino: u64,
116 nlink: usize,
117
118 mode: u32,
119 uid: u32,
120 gid: u32,
121 __pad0: u32,
122 rdev: u64,
123 size: i64,
124 blksize: isize,
125 blocks: i64,
126
127 atim: timespec,
128 mtim: timespec,
129 ctim: timespec,
130 __unused: [3]isize,
131};
132
133pub const timespec = extern struct {
134 tv_sec: isize,
135 tv_nsec: isize,
136};
std/os/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.
108pub fn getRandomBytes(buf: []u8) !void {108pub 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 #397112 // 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 Windows125 // Call RtlGenRandom() instead of CryptGetRandom() on Windows
126 // https://github.com/rust-lang-nursery/rand/issues/111126 // 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 }
17671767
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};
17731822
...@@ -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 {
2255pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 {2304pub 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 Zig1166 // 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
11891189
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 duration13/// Sleep for the specified duration
14pub fn sleep(nanoseconds: u64) void {14pub 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 {
2020
21nakedcc fn _start() noreturn {21nakedcc 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]"