authorgravatar for 1@tse.gratisTse <1@tse.gratis> 2019-10-23 01:06:35+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-30 21:21:58-04:00
log33cc2044811e41a74e3112fc0abcc5dc6fd34836
tree380b8a0e296e32fae4415035338ec268c1a1beaf
parent7c7350345147c61e3e0873c3c4f233e351a3910a

DragonFlyBSD support


30 files changed, 807 insertions(+), 57 deletions(-)

lib/std/atomic/queue.zig+1
...@@ -152,6 +152,7 @@ const puts_per_thread = 500;...@@ -152,6 +152,7 @@ const puts_per_thread = 500;
152const put_thread_count = 3;152const put_thread_count = 3;
153153
154test "std.atomic.Queue" {154test "std.atomic.Queue" {
155 if (builtin.os == .dragonfly) return error.SkipZigTest;
155 var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024);156 var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024);
156 defer std.heap.direct_allocator.free(plenty_of_memory);157 defer std.heap.direct_allocator.free(plenty_of_memory);
157158
lib/std/atomic/stack.zig+1
...@@ -86,6 +86,7 @@ const puts_per_thread = 500;...@@ -86,6 +86,7 @@ const puts_per_thread = 500;
86const put_thread_count = 3;86const put_thread_count = 3;
8787
88test "std.atomic.stack" {88test "std.atomic.stack" {
89 if (builtin.os == .dragonfly) return error.SkipZigTest;
89 var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024);90 var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024);
90 defer std.heap.direct_allocator.free(plenty_of_memory);91 defer std.heap.direct_allocator.free(plenty_of_memory);
9192
lib/std/c.zig+1
...@@ -10,6 +10,7 @@ pub usingnamespace switch (builtin.os) {...@@ -10,6 +10,7 @@ pub usingnamespace switch (builtin.os) {
10 .macosx, .ios, .tvos, .watchos => @import("c/darwin.zig"),10 .macosx, .ios, .tvos, .watchos => @import("c/darwin.zig"),
11 .freebsd => @import("c/freebsd.zig"),11 .freebsd => @import("c/freebsd.zig"),
12 .netbsd => @import("c/netbsd.zig"),12 .netbsd => @import("c/netbsd.zig"),
13 .dragonfly => @import("c/dragonfly.zig"),
13 else => struct {},14 else => struct {},
14};15};
1516
lib/std/c/dragonfly.zig created+14
...@@ -0,0 +1,14 @@
1const std = @import("../std.zig");
2usingnamespace std.c;
3
4extern "c" threadlocal var errno: c_int;
5pub fn _errno() *c_int {
6 return &errno;
7}
8
9pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
10pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
11pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
12
13pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
14pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
lib/std/debug.zig+1-1
...@@ -1272,7 +1272,7 @@ pub const DebugInfo = switch (builtin.os) {...@@ -1272,7 +1272,7 @@ pub const DebugInfo = switch (builtin.os) {
1272 sect_contribs: []pdb.SectionContribEntry,1272 sect_contribs: []pdb.SectionContribEntry,
1273 modules: []Module,1273 modules: []Module,
1274 },1274 },
1275 .linux, .freebsd, .netbsd => DwarfInfo,1275 .linux, .freebsd, .netbsd, .dragonfly => DwarfInfo,
1276 else => @compileError("Unsupported OS"),1276 else => @compileError("Unsupported OS"),
1277};1277};
12781278
lib/std/event/channel.zig+1
...@@ -304,6 +304,7 @@ pub fn Channel(comptime T: type) type {...@@ -304,6 +304,7 @@ pub fn Channel(comptime T: type) type {
304}304}
305305
306test "std.event.Channel" {306test "std.event.Channel" {
307 if (builtin.os == .dragonfly) return error.SkipZigTest;
307 // https://github.com/ziglang/zig/issues/1908308 // https://github.com/ziglang/zig/issues/1908
308 if (builtin.single_threaded) return error.SkipZigTest;309 if (builtin.single_threaded) return error.SkipZigTest;
309 // https://github.com/ziglang/zig/issues/3251310 // https://github.com/ziglang/zig/issues/3251
lib/std/event/fs.zig+16-8
...@@ -92,6 +92,7 @@ pub fn pwritev(loop: *Loop, fd: fd_t, data: []const []const u8, offset: usize) P...@@ -92,6 +92,7 @@ pub fn pwritev(loop: *Loop, fd: fd_t, data: []const []const u8, offset: usize) P
92 .linux,92 .linux,
93 .freebsd,93 .freebsd,
94 .netbsd,94 .netbsd,
95 .dragonfly,
95 => {96 => {
96 const iovecs = try loop.allocator.alloc(os.iovec_const, data.len);97 const iovecs = try loop.allocator.alloc(os.iovec_const, data.len);
97 defer loop.allocator.free(iovecs);98 defer loop.allocator.free(iovecs);
...@@ -248,6 +249,7 @@ pub fn preadv(loop: *Loop, fd: fd_t, data: []const []u8, offset: usize) PReadVEr...@@ -248,6 +249,7 @@ pub fn preadv(loop: *Loop, fd: fd_t, data: []const []u8, offset: usize) PReadVEr
248 .linux,249 .linux,
249 .freebsd,250 .freebsd,
250 .netbsd,251 .netbsd,
252 .dragonfly,
251 => {253 => {
252 const iovecs = try loop.allocator.alloc(os.iovec, data.len);254 const iovecs = try loop.allocator.alloc(os.iovec, data.len);
253 defer loop.allocator.free(iovecs);255 defer loop.allocator.free(iovecs);
...@@ -412,7 +414,7 @@ pub fn openPosix(...@@ -412,7 +414,7 @@ pub fn openPosix(
412414
413pub fn openRead(loop: *Loop, path: []const u8) File.OpenError!fd_t {415pub fn openRead(loop: *Loop, path: []const u8) File.OpenError!fd_t {
414 switch (builtin.os) {416 switch (builtin.os) {
415 .macosx, .linux, .freebsd, .netbsd => {417 .macosx, .linux, .freebsd, .netbsd, .dragonfly => {
416 const flags = os.O_LARGEFILE | os.O_RDONLY | os.O_CLOEXEC;418 const flags = os.O_LARGEFILE | os.O_RDONLY | os.O_CLOEXEC;
417 return openPosix(loop, path, flags, File.default_mode);419 return openPosix(loop, path, flags, File.default_mode);
418 },420 },
...@@ -444,6 +446,7 @@ pub fn openWriteMode(loop: *Loop, path: []const u8, mode: File.Mode) File.OpenEr...@@ -444,6 +446,7 @@ pub fn openWriteMode(loop: *Loop, path: []const u8, mode: File.Mode) File.OpenEr
444 .linux,446 .linux,
445 .freebsd,447 .freebsd,
446 .netbsd,448 .netbsd,
449 .dragonfly,
447 => {450 => {
448 const flags = os.O_LARGEFILE | os.O_WRONLY | os.O_CREAT | os.O_CLOEXEC | os.O_TRUNC;451 const flags = os.O_LARGEFILE | os.O_WRONLY | os.O_CREAT | os.O_CLOEXEC | os.O_TRUNC;
449 return openPosix(loop, path, flags, File.default_mode);452 return openPosix(loop, path, flags, File.default_mode);
...@@ -468,7 +471,7 @@ pub fn openReadWrite(...@@ -468,7 +471,7 @@ pub fn openReadWrite(
468 mode: File.Mode,471 mode: File.Mode,
469) File.OpenError!fd_t {472) File.OpenError!fd_t {
470 switch (builtin.os) {473 switch (builtin.os) {
471 .macosx, .linux, .freebsd, .netbsd => {474 .macosx, .linux, .freebsd, .netbsd, .dragonfly => {
472 const flags = os.O_LARGEFILE | os.O_RDWR | os.O_CREAT | os.O_CLOEXEC;475 const flags = os.O_LARGEFILE | os.O_RDWR | os.O_CREAT | os.O_CLOEXEC;
473 return openPosix(loop, path, flags, mode);476 return openPosix(loop, path, flags, mode);
474 },477 },
...@@ -498,7 +501,7 @@ pub const CloseOperation = struct {...@@ -498,7 +501,7 @@ pub const CloseOperation = struct {
498 os_data: OsData,501 os_data: OsData,
499502
500 const OsData = switch (builtin.os) {503 const OsData = switch (builtin.os) {
501 .linux, .macosx, .freebsd, .netbsd => OsDataPosix,504 .linux, .macosx, .freebsd, .netbsd, .dragonfly => OsDataPosix,
502505
503 .windows => struct {506 .windows => struct {
504 handle: ?fd_t,507 handle: ?fd_t,
...@@ -517,7 +520,7 @@ pub const CloseOperation = struct {...@@ -517,7 +520,7 @@ pub const CloseOperation = struct {
517 self.* = CloseOperation{520 self.* = CloseOperation{
518 .loop = loop,521 .loop = loop,
519 .os_data = switch (builtin.os) {522 .os_data = switch (builtin.os) {
520 .linux, .macosx, .freebsd, .netbsd => initOsDataPosix(self),523 .linux, .macosx, .freebsd, .netbsd, .dragonfly => initOsDataPosix(self),
521 .windows => OsData{ .handle = null },524 .windows => OsData{ .handle = null },
522 else => @compileError("Unsupported OS"),525 else => @compileError("Unsupported OS"),
523 },526 },
...@@ -548,6 +551,7 @@ pub const CloseOperation = struct {...@@ -548,6 +551,7 @@ pub const CloseOperation = struct {
548 .macosx,551 .macosx,
549 .freebsd,552 .freebsd,
550 .netbsd,553 .netbsd,
554 .dragonfly,
551 => {555 => {
552 if (self.os_data.have_fd) {556 if (self.os_data.have_fd) {
553 self.loop.posixFsRequest(&self.os_data.close_req_node);557 self.loop.posixFsRequest(&self.os_data.close_req_node);
...@@ -571,6 +575,7 @@ pub const CloseOperation = struct {...@@ -571,6 +575,7 @@ pub const CloseOperation = struct {
571 .macosx,575 .macosx,
572 .freebsd,576 .freebsd,
573 .netbsd,577 .netbsd,
578 .dragonfly,
574 => {579 => {
575 self.os_data.close_req_node.data.msg.Close.fd = handle;580 self.os_data.close_req_node.data.msg.Close.fd = handle;
576 self.os_data.have_fd = true;581 self.os_data.have_fd = true;
...@@ -589,6 +594,7 @@ pub const CloseOperation = struct {...@@ -589,6 +594,7 @@ pub const CloseOperation = struct {
589 .macosx,594 .macosx,
590 .freebsd,595 .freebsd,
591 .netbsd,596 .netbsd,
597 .dragonfly,
592 => {598 => {
593 self.os_data.have_fd = false;599 self.os_data.have_fd = false;
594 },600 },
...@@ -605,6 +611,7 @@ pub const CloseOperation = struct {...@@ -605,6 +611,7 @@ pub const CloseOperation = struct {
605 .macosx,611 .macosx,
606 .freebsd,612 .freebsd,
607 .netbsd,613 .netbsd,
614 .dragonfly,
608 => {615 => {
609 assert(self.os_data.have_fd);616 assert(self.os_data.have_fd);
610 return self.os_data.close_req_node.data.msg.Close.fd;617 return self.os_data.close_req_node.data.msg.Close.fd;
...@@ -630,6 +637,7 @@ pub fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8, mode:...@@ -630,6 +637,7 @@ pub fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8, mode:
630 .macosx,637 .macosx,
631 .freebsd,638 .freebsd,
632 .netbsd,639 .netbsd,
640 .dragonfly,
633 => return writeFileModeThread(loop, path, contents, mode),641 => return writeFileModeThread(loop, path, contents, mode),
634 .windows => return writeFileWindows(loop, path, contents),642 .windows => return writeFileWindows(loop, path, contents),
635 else => @compileError("Unsupported OS"),643 else => @compileError("Unsupported OS"),
...@@ -742,7 +750,7 @@ fn hashString(s: []const u16) u32 {...@@ -742,7 +750,7 @@ fn hashString(s: []const u16) u32 {
742// os_data: OsData,750// os_data: OsData,
743//751//
744// const OsData = switch (builtin.os) {752// const OsData = switch (builtin.os) {
745// .macosx, .freebsd, .netbsd => struct {753// .macosx, .freebsd, .netbsd, .dragonfly => struct {
746// file_table: FileTable,754// file_table: FileTable,
747// table_lock: event.Lock,755// table_lock: event.Lock,
748//756//
...@@ -831,7 +839,7 @@ fn hashString(s: []const u16) u32 {...@@ -831,7 +839,7 @@ fn hashString(s: []const u16) u32 {
831// return self;839// return self;
832// },840// },
833//841//
834// .macosx, .freebsd, .netbsd => {842// .macosx, .freebsd, .netbsd, .dragonfly => {
835// const self = try loop.allocator.create(Self);843// const self = try loop.allocator.create(Self);
836// errdefer loop.allocator.destroy(self);844// errdefer loop.allocator.destroy(self);
837//845//
...@@ -851,7 +859,7 @@ fn hashString(s: []const u16) u32 {...@@ -851,7 +859,7 @@ fn hashString(s: []const u16) u32 {
851// /// All addFile calls and removeFile calls must have completed.859// /// All addFile calls and removeFile calls must have completed.
852// pub fn destroy(self: *Self) void {860// pub fn destroy(self: *Self) void {
853// switch (builtin.os) {861// switch (builtin.os) {
854// .macosx, .freebsd, .netbsd => {862// .macosx, .freebsd, .netbsd, .dragonfly => {
855// // TODO we need to cancel the frames before destroying the lock863// // TODO we need to cancel the frames before destroying the lock
856// self.os_data.table_lock.deinit();864// self.os_data.table_lock.deinit();
857// var it = self.os_data.file_table.iterator();865// var it = self.os_data.file_table.iterator();
...@@ -893,7 +901,7 @@ fn hashString(s: []const u16) u32 {...@@ -893,7 +901,7 @@ fn hashString(s: []const u16) u32 {
893//901//
894// pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V {902// pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V {
895// switch (builtin.os) {903// switch (builtin.os) {
896// .macosx, .freebsd, .netbsd => return await (async addFileKEvent(self, file_path, value) catch unreachable),904// .macosx, .freebsd, .netbsd, .dragonfly => return await (async addFileKEvent(self, file_path, value) catch unreachable),
897// .linux => return await (async addFileLinux(self, file_path, value) catch unreachable),905// .linux => return await (async addFileLinux(self, file_path, value) catch unreachable),
898// .windows => return await (async addFileWindows(self, file_path, value) catch unreachable),906// .windows => return await (async addFileWindows(self, file_path, value) catch unreachable),
899// else => @compileError("Unsupported OS"),907// else => @compileError("Unsupported OS"),
lib/std/event/group.zig+1
...@@ -81,6 +81,7 @@ pub fn Group(comptime ReturnType: type) type {...@@ -81,6 +81,7 @@ pub fn Group(comptime ReturnType: type) type {
81}81}
8282
83test "std.event.Group" {83test "std.event.Group" {
84 if (builtin.os == .dragonfly) return error.SkipZigTest;
84 // https://github.com/ziglang/zig/issues/190885 // https://github.com/ziglang/zig/issues/1908
85 if (builtin.single_threaded) return error.SkipZigTest;86 if (builtin.single_threaded) return error.SkipZigTest;
8687
lib/std/event/lock.zig+1
...@@ -116,6 +116,7 @@ pub const Lock = struct {...@@ -116,6 +116,7 @@ pub const Lock = struct {
116};116};
117117
118test "std.event.Lock" {118test "std.event.Lock" {
119 if (builtin.os == .dragonfly) return error.SkipZigTest;
119 // TODO https://github.com/ziglang/zig/issues/1908120 // TODO https://github.com/ziglang/zig/issues/1908
120 if (builtin.single_threaded) return error.SkipZigTest;121 if (builtin.single_threaded) return error.SkipZigTest;
121 // TODO https://github.com/ziglang/zig/issues/3251122 // TODO https://github.com/ziglang/zig/issues/3251
lib/std/event/loop.zig+11-10
...@@ -51,7 +51,7 @@ pub const Loop = struct {...@@ -51,7 +51,7 @@ pub const Loop = struct {
51 };51 };
5252
53 pub const EventFd = switch (builtin.os) {53 pub const EventFd = switch (builtin.os) {
54 .macosx, .freebsd, .netbsd => KEventFd,54 .macosx, .freebsd, .netbsd, .dragonfly => KEventFd,
55 .linux => struct {55 .linux => struct {
56 base: ResumeNode,56 base: ResumeNode,
57 epoll_op: u32,57 epoll_op: u32,
...@@ -70,7 +70,7 @@ pub const Loop = struct {...@@ -70,7 +70,7 @@ pub const Loop = struct {
70 };70 };
7171
72 pub const Basic = switch (builtin.os) {72 pub const Basic = switch (builtin.os) {
73 .macosx, .freebsd, .netbsd => KEventBasic,73 .macosx, .freebsd, .netbsd, .dragonfly => KEventBasic,
74 .linux => struct {74 .linux => struct {
75 base: ResumeNode,75 base: ResumeNode,
76 },76 },
...@@ -244,7 +244,7 @@ pub const Loop = struct {...@@ -244,7 +244,7 @@ pub const Loop = struct {
244 self.extra_threads[extra_thread_index] = try Thread.spawn(self, workerRun);244 self.extra_threads[extra_thread_index] = try Thread.spawn(self, workerRun);
245 }245 }
246 },246 },
247 .macosx, .freebsd, .netbsd => {247 .macosx, .freebsd, .netbsd, .dragonfly => {
248 self.os_data.kqfd = try os.kqueue();248 self.os_data.kqfd = try os.kqueue();
249 errdefer os.close(self.os_data.kqfd);249 errdefer os.close(self.os_data.kqfd);
250250
...@@ -409,7 +409,7 @@ pub const Loop = struct {...@@ -409,7 +409,7 @@ pub const Loop = struct {
409 os.close(self.os_data.epollfd);409 os.close(self.os_data.epollfd);
410 self.allocator.free(self.eventfd_resume_nodes);410 self.allocator.free(self.eventfd_resume_nodes);
411 },411 },
412 .macosx, .freebsd, .netbsd => {412 .macosx, .freebsd, .netbsd, .dragonfly => {
413 os.close(self.os_data.kqfd);413 os.close(self.os_data.kqfd);
414 os.close(self.os_data.fs_kqfd);414 os.close(self.os_data.fs_kqfd);
415 },415 },
...@@ -523,7 +523,7 @@ pub const Loop = struct {...@@ -523,7 +523,7 @@ pub const Loop = struct {
523 const eventfd_node = &resume_stack_node.data;523 const eventfd_node = &resume_stack_node.data;
524 eventfd_node.base.handle = next_tick_node.data;524 eventfd_node.base.handle = next_tick_node.data;
525 switch (builtin.os) {525 switch (builtin.os) {
526 .macosx, .freebsd, .netbsd => {526 .macosx, .freebsd, .netbsd, .dragonfly => {
527 const kevent_array = (*const [1]os.Kevent)(&eventfd_node.kevent);527 const kevent_array = (*const [1]os.Kevent)(&eventfd_node.kevent);
528 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];528 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
529 _ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {529 _ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {
...@@ -587,6 +587,7 @@ pub const Loop = struct {...@@ -587,6 +587,7 @@ pub const Loop = struct {
587 .macosx,587 .macosx,
588 .freebsd,588 .freebsd,
589 .netbsd,589 .netbsd,
590 .dragonfly,
590 => self.os_data.fs_thread.wait(),591 => self.os_data.fs_thread.wait(),
591 else => {},592 else => {},
592 }593 }
...@@ -644,7 +645,7 @@ pub const Loop = struct {...@@ -644,7 +645,7 @@ pub const Loop = struct {
644 os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;645 os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
645 return;646 return;
646 },647 },
647 .macosx, .freebsd, .netbsd => {648 .macosx, .freebsd, .netbsd, .dragonfly => {
648 self.posixFsRequest(&self.os_data.fs_end_request);649 self.posixFsRequest(&self.os_data.fs_end_request);
649 const final_kevent = (*const [1]os.Kevent)(&self.os_data.final_kevent);650 const final_kevent = (*const [1]os.Kevent)(&self.os_data.final_kevent);
650 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];651 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
...@@ -702,7 +703,7 @@ pub const Loop = struct {...@@ -702,7 +703,7 @@ pub const Loop = struct {
702 }703 }
703 }704 }
704 },705 },
705 .macosx, .freebsd, .netbsd => {706 .macosx, .freebsd, .netbsd, .dragonfly => {
706 var eventlist: [1]os.Kevent = undefined;707 var eventlist: [1]os.Kevent = undefined;
707 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];708 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
708 const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;709 const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
...@@ -765,7 +766,7 @@ pub const Loop = struct {...@@ -765,7 +766,7 @@ pub const Loop = struct {
765 self.beginOneEvent(); // finished in posixFsRun after processing the msg766 self.beginOneEvent(); // finished in posixFsRun after processing the msg
766 self.os_data.fs_queue.put(request_node);767 self.os_data.fs_queue.put(request_node);
767 switch (builtin.os) {768 switch (builtin.os) {
768 .macosx, .freebsd, .netbsd => {769 .macosx, .freebsd, .netbsd, .dragonfly => {
769 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wake);770 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wake);
770 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];771 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
771 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;772 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
...@@ -838,7 +839,7 @@ pub const Loop = struct {...@@ -838,7 +839,7 @@ pub const Loop = struct {
838 else => unreachable,839 else => unreachable,
839 }840 }
840 },841 },
841 .macosx, .freebsd, .netbsd => {842 .macosx, .freebsd, .netbsd, .dragonfly => {
842 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wait);843 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wait);
843 var out_kevs: [1]os.Kevent = undefined;844 var out_kevs: [1]os.Kevent = undefined;
844 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;845 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;
...@@ -850,7 +851,7 @@ pub const Loop = struct {...@@ -850,7 +851,7 @@ pub const Loop = struct {
850851
851 const OsData = switch (builtin.os) {852 const OsData = switch (builtin.os) {
852 .linux => LinuxOsData,853 .linux => LinuxOsData,
853 .macosx, .freebsd, .netbsd => KEventData,854 .macosx, .freebsd, .netbsd, .dragonfly => KEventData,
854 .windows => struct {855 .windows => struct {
855 io_port: windows.HANDLE,856 io_port: windows.HANDLE,
856 extra_thread_count: usize,857 extra_thread_count: usize,
lib/std/fs.zig+6-6
...@@ -28,7 +28,7 @@ pub const GetAppDataDirError = @import("fs/get_app_data_dir.zig").GetAppDataDirE...@@ -28,7 +28,7 @@ pub const GetAppDataDirError = @import("fs/get_app_data_dir.zig").GetAppDataDirE
28/// All file system operations which return a path are guaranteed to28/// All file system operations which return a path are guaranteed to
29/// fit into a UTF-8 encoded array of this length.29/// fit into a UTF-8 encoded array of this length.
30pub const MAX_PATH_BYTES = switch (builtin.os) {30pub const MAX_PATH_BYTES = switch (builtin.os) {
31 .linux, .macosx, .ios, .freebsd, .netbsd => os.PATH_MAX,31 .linux, .macosx, .ios, .freebsd, .netbsd, .dragonfly => os.PATH_MAX,
32 // Each UTF-16LE character may be expanded to 3 UTF-8 bytes.32 // Each UTF-16LE character may be expanded to 3 UTF-8 bytes.
33 // If it would require 4 UTF-8 bytes, then there would be a surrogate33 // If it would require 4 UTF-8 bytes, then there would be a surrogate
34 // pair in the UTF-16LE, and we (over)account 3 bytes for it that way.34 // pair in the UTF-16LE, and we (over)account 3 bytes for it that way.
...@@ -380,7 +380,7 @@ pub const Dir = struct {...@@ -380,7 +380,7 @@ pub const Dir = struct {
380 const IteratorError = error{AccessDenied} || os.UnexpectedError;380 const IteratorError = error{AccessDenied} || os.UnexpectedError;
381381
382 pub const Iterator = switch (builtin.os) {382 pub const Iterator = switch (builtin.os) {
383 .macosx, .ios, .freebsd, .netbsd => struct {383 .macosx, .ios, .freebsd, .netbsd, .dragonfly => struct {
384 dir: Dir,384 dir: Dir,
385 seek: i64,385 seek: i64,
386 buf: [8192]u8, // TODO align(@alignOf(os.dirent)),386 buf: [8192]u8, // TODO align(@alignOf(os.dirent)),
...@@ -396,7 +396,7 @@ pub const Dir = struct {...@@ -396,7 +396,7 @@ pub const Dir = struct {
396 pub fn next(self: *Self) Error!?Entry {396 pub fn next(self: *Self) Error!?Entry {
397 switch (builtin.os) {397 switch (builtin.os) {
398 .macosx, .ios => return self.nextDarwin(),398 .macosx, .ios => return self.nextDarwin(),
399 .freebsd, .netbsd => return self.nextBsd(),399 .freebsd, .netbsd, .dragonfly => return self.nextBsd(),
400 else => @compileError("unimplemented"),400 else => @compileError("unimplemented"),
401 }401 }
402 }402 }
...@@ -630,7 +630,7 @@ pub const Dir = struct {...@@ -630,7 +630,7 @@ pub const Dir = struct {
630630
631 pub fn iterate(self: Dir) Iterator {631 pub fn iterate(self: Dir) Iterator {
632 switch (builtin.os) {632 switch (builtin.os) {
633 .macosx, .ios, .freebsd, .netbsd => return Iterator{633 .macosx, .ios, .freebsd, .netbsd, .dragonfly => return Iterator{
634 .dir = self,634 .dir = self,
635 .seek = 0,635 .seek = 0,
636 .index = 0,636 .index = 0,
...@@ -1162,7 +1162,7 @@ pub fn openSelfExe() OpenSelfExeError!File {...@@ -1162,7 +1162,7 @@ pub fn openSelfExe() OpenSelfExeError!File {
11621162
1163test "openSelfExe" {1163test "openSelfExe" {
1164 switch (builtin.os) {1164 switch (builtin.os) {
1165 .linux, .macosx, .ios, .windows, .freebsd => (try openSelfExe()).close(),1165 .linux, .macosx, .ios, .windows, .freebsd, .dragonfly => (try openSelfExe()).close(),
1166 else => return error.SkipZigTest, // Unsupported OS.1166 else => return error.SkipZigTest, // Unsupported OS.
1167 }1167 }
1168}1168}
...@@ -1188,7 +1188,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {...@@ -1188,7 +1188,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
1188 }1188 }
1189 switch (builtin.os) {1189 switch (builtin.os) {
1190 .linux => return os.readlinkC(c"/proc/self/exe", out_buffer),1190 .linux => return os.readlinkC(c"/proc/self/exe", out_buffer),
1191 .freebsd => {1191 .freebsd, .dragonfly => {
1192 var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC, os.KERN_PROC_PATHNAME, -1 };1192 var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC, os.KERN_PROC_PATHNAME, -1 };
1193 var out_len: usize = out_buffer.len;1193 var out_len: usize = out_buffer.len;
1194 try os.sysctl(&mib, out_buffer, &out_len, null, 0);1194 try os.sysctl(&mib, out_buffer, &out_len, null, 0);
lib/std/fs/get_app_data_dir.zig+1-1
...@@ -44,7 +44,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD...@@ -44,7 +44,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
44 };44 };
45 return fs.path.join(allocator, [_][]const u8{ home_dir, "Library", "Application Support", appname });45 return fs.path.join(allocator, [_][]const u8{ home_dir, "Library", "Application Support", appname });
46 },46 },
47 .linux, .freebsd, .netbsd => {47 .linux, .freebsd, .netbsd, .dragonfly => {
48 const home_dir = os.getenv("HOME") orelse {48 const home_dir = os.getenv("HOME") orelse {
49 // TODO look in /etc/passwd49 // TODO look in /etc/passwd
50 return error.AppDataDirUnavailable;50 return error.AppDataDirUnavailable;
lib/std/mutex.zig+1
...@@ -130,6 +130,7 @@ const TestContext = struct {...@@ -130,6 +130,7 @@ const TestContext = struct {
130};130};
131131
132test "std.Mutex" {132test "std.Mutex" {
133 if (builtin.os == .dragonfly) return error.SkipZigTest;
133 var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024);134 var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024);
134 defer std.heap.direct_allocator.free(plenty_of_memory);135 defer std.heap.direct_allocator.free(plenty_of_memory);
135136
lib/std/os.zig+3-1
...@@ -24,9 +24,10 @@ const dl = @import("dynamic_library.zig");...@@ -24,9 +24,10 @@ const dl = @import("dynamic_library.zig");
24const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;24const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
2525
26pub const darwin = @import("os/darwin.zig");26pub const darwin = @import("os/darwin.zig");
27pub const dragonfly = @import("os/dragonfly.zig");
27pub const freebsd = @import("os/freebsd.zig");28pub const freebsd = @import("os/freebsd.zig");
28pub const linux = @import("os/linux.zig");
29pub const netbsd = @import("os/netbsd.zig");29pub const netbsd = @import("os/netbsd.zig");
30pub const linux = @import("os/linux.zig");
30pub const uefi = @import("os/uefi.zig");31pub const uefi = @import("os/uefi.zig");
31pub const wasi = @import("os/wasi.zig");32pub const wasi = @import("os/wasi.zig");
32pub const windows = @import("os/windows.zig");33pub const windows = @import("os/windows.zig");
...@@ -55,6 +56,7 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) {...@@ -55,6 +56,7 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) {
55 .freebsd => freebsd,56 .freebsd => freebsd,
56 .linux => linux,57 .linux => linux,
57 .netbsd => netbsd,58 .netbsd => netbsd,
59 .dragonfly => dragonfly,
58 .wasi => wasi,60 .wasi => wasi,
59 .windows => windows,61 .windows => windows,
60 .zen => zen,62 .zen => zen,
lib/std/os/bits.zig+1
...@@ -5,6 +5,7 @@ const builtin = @import("builtin");...@@ -5,6 +5,7 @@ const builtin = @import("builtin");
55
6pub usingnamespace switch (builtin.os) {6pub usingnamespace switch (builtin.os) {
7 .macosx, .ios, .tvos, .watchos => @import("bits/darwin.zig"),7 .macosx, .ios, .tvos, .watchos => @import("bits/darwin.zig"),
8 .dragonfly => @import("bits/dragonfly.zig"),
8 .freebsd => @import("bits/freebsd.zig"),9 .freebsd => @import("bits/freebsd.zig"),
9 .linux => @import("bits/linux.zig"),10 .linux => @import("bits/linux.zig"),
10 .netbsd => @import("bits/netbsd.zig"),11 .netbsd => @import("bits/netbsd.zig"),
lib/std/os/bits/darwin.zig+4
...@@ -119,6 +119,10 @@ pub const dirent = extern struct {...@@ -119,6 +119,10 @@ pub const dirent = extern struct {
119 d_namlen: u16,119 d_namlen: u16,
120 d_type: u8,120 d_type: u8,
121 d_name: u8, // field address is address of first byte of name121 d_name: u8, // field address is address of first byte of name
122
123 pub fn reclen(self: dirent) usize {
124 return self.d_reclen;
125 }
122};126};
123127
124pub const pthread_attr_t = extern struct {128pub const pthread_attr_t = extern struct {
lib/std/os/bits/dragonfly.zig created+702
...@@ -0,0 +1,702 @@
1const std = @import("../../std.zig");
2const maxInt = std.math.maxInt;
3
4pub fn S_ISCHR(m: u32) bool {
5 return m & S_IFMT == S_IFCHR;
6}
7pub const fd_t = c_int;
8pub const pid_t = c_int;
9pub const off_t = c_long;
10
11pub const ENOTSUP = EOPNOTSUPP;
12pub const EWOULDBLOCK = EAGAIN;
13pub const EPERM = 1;
14pub const ENOENT = 2;
15pub const ESRCH = 3;
16pub const EINTR = 4;
17pub const EIO = 5;
18pub const ENXIO = 6;
19pub const E2BIG = 7;
20pub const ENOEXEC = 8;
21pub const EBADF = 9;
22pub const ECHILD = 10;
23pub const EDEADLK = 11;
24pub const ENOMEM = 12;
25pub const EACCES = 13;
26pub const EFAULT = 14;
27pub const ENOTBLK = 15;
28pub const EBUSY = 16;
29pub const EEXIST = 17;
30pub const EXDEV = 18;
31pub const ENODEV = 19;
32pub const ENOTDIR = 20;
33pub const EISDIR = 21;
34pub const EINVAL = 22;
35pub const ENFILE = 23;
36pub const EMFILE = 24;
37pub const ENOTTY = 25;
38pub const ETXTBSY = 26;
39pub const EFBIG = 27;
40pub const ENOSPC = 28;
41pub const ESPIPE = 29;
42pub const EROFS = 30;
43pub const EMLINK = 31;
44pub const EPIPE = 32;
45pub const EDOM = 33;
46pub const ERANGE = 34;
47pub const EAGAIN = 35;
48pub const EINPROGRESS = 36;
49pub const EALREADY = 37;
50pub const ENOTSOCK = 38;
51pub const EDESTADDRREQ = 39;
52pub const EMSGSIZE = 40;
53pub const EPROTOTYPE = 41;
54pub const ENOPROTOOPT = 42;
55pub const EPROTONOSUPPORT = 43;
56pub const ESOCKTNOSUPPORT = 44;
57pub const EOPNOTSUPP = 45;
58pub const EPFNOSUPPORT = 46;
59pub const EAFNOSUPPORT = 47;
60pub const EADDRINUSE = 48;
61pub const EADDRNOTAVAIL = 49;
62pub const ENETDOWN = 50;
63pub const ENETUNREACH = 51;
64pub const ENETRESET = 52;
65pub const ECONNABORTED = 53;
66pub const ECONNRESET = 54;
67pub const ENOBUFS = 55;
68pub const EISCONN = 56;
69pub const ENOTCONN = 57;
70pub const ESHUTDOWN = 58;
71pub const ETOOMANYREFS = 59;
72pub const ETIMEDOUT = 60;
73pub const ECONNREFUSED = 61;
74pub const ELOOP = 62;
75pub const ENAMETOOLONG = 63;
76pub const EHOSTDOWN = 64;
77pub const EHOSTUNREACH = 65;
78pub const ENOTEMPTY = 66;
79pub const EPROCLIM = 67;
80pub const EUSERS = 68;
81pub const EDQUOT = 69;
82pub const ESTALE = 70;
83pub const EREMOTE = 71;
84pub const EBADRPC = 72;
85pub const ERPCMISMATCH = 73;
86pub const EPROGUNAVAIL = 74;
87pub const EPROGMISMATCH = 75;
88pub const EPROCUNAVAIL = 76;
89pub const ENOLCK = 77;
90pub const ENOSYS = 78;
91pub const EFTYPE = 79;
92pub const EAUTH = 80;
93pub const ENEEDAUTH = 81;
94pub const EIDRM = 82;
95pub const ENOMSG = 83;
96pub const EOVERFLOW = 84;
97pub const ECANCELED = 85;
98pub const EILSEQ = 86;
99pub const ENOATTR = 87;
100pub const EDOOFUS = 88;
101pub const EBADMSG = 89;
102pub const EMULTIHOP = 90;
103pub const ENOLINK = 91;
104pub const EPROTO = 92;
105pub const ENOMEDIUM = 93;
106pub const ELAST = 99;
107pub const EASYNC = 99;
108
109pub const STDIN_FILENO = 0;
110pub const STDOUT_FILENO = 1;
111pub const STDERR_FILENO = 2;
112
113pub const PROT_NONE = 0;
114pub const PROT_READ = 1;
115pub const PROT_WRITE = 2;
116pub const PROT_EXEC = 4;
117
118pub const MAP_FILE = 0;
119pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
120pub const MAP_ANONYMOUS = MAP_ANON;
121pub const MAP_COPY = MAP_PRIVATE;
122pub const MAP_SHARED = 1;
123pub const MAP_PRIVATE = 2;
124pub const MAP_FIXED = 16;
125pub const MAP_RENAME = 32;
126pub const MAP_NORESERVE = 64;
127pub const MAP_INHERIT = 128;
128pub const MAP_NOEXTEND = 256;
129pub const MAP_HASSEMAPHORE = 512;
130pub const MAP_STACK = 1024;
131pub const MAP_NOSYNC = 2048;
132pub const MAP_ANON = 4096;
133pub const MAP_VPAGETABLE = 8192;
134pub const MAP_TRYFIXED = 65536;
135pub const MAP_NOCORE = 131072;
136pub const MAP_SIZEALIGN = 262144;
137
138pub const PATH_MAX = 1024;
139
140pub const Stat = extern struct {
141 ino: c_ulong,
142 nlink: c_uint,
143 dev: c_uint,
144 mode: c_ushort,
145 padding1: u16,
146 uid: c_uint,
147 gid: c_uint,
148 rdev: c_uint,
149 atim: timespec,
150 mtim: timespec,
151 ctim: timespec,
152 size: c_ulong,
153 blocks: i64,
154 blksize: u32,
155 flags: u32,
156 gen: u32,
157 lspare: i32,
158 qspare1: i64,
159 qspare2: i64,
160 pub fn atime(self: Stat) timespec {
161 return self.atim;
162 }
163
164 pub fn mtime(self: Stat) timespec {
165 return self.mtim;
166 }
167
168 pub fn ctime(self: Stat) timespec {
169 return self.ctim;
170 }
171};
172
173pub const timespec = extern struct {
174 tv_sec: c_long,
175 tv_nsec: c_long,
176};
177
178pub const CTL_UNSPEC = 0;
179pub const CTL_KERN = 1;
180pub const CTL_VM = 2;
181pub const CTL_VFS = 3;
182pub const CTL_NET = 4;
183pub const CTL_DEBUG = 5;
184pub const CTL_HW = 6;
185pub const CTL_MACHDEP = 7;
186pub const CTL_USER = 8;
187pub const CTL_LWKT = 10;
188pub const CTL_MAXID = 11;
189pub const CTL_MAXNAME = 12;
190
191pub const KERN_PROC_ALL = 0;
192pub const KERN_OSTYPE = 1;
193pub const KERN_PROC_PID = 1;
194pub const KERN_OSRELEASE = 2;
195pub const KERN_PROC_PGRP = 2;
196pub const KERN_OSREV = 3;
197pub const KERN_PROC_SESSION = 3;
198pub const KERN_VERSION = 4;
199pub const KERN_PROC_TTY = 4;
200pub const KERN_MAXVNODES = 5;
201pub const KERN_PROC_UID = 5;
202pub const KERN_MAXPROC = 6;
203pub const KERN_PROC_RUID = 6;
204pub const KERN_MAXFILES = 7;
205pub const KERN_PROC_ARGS = 7;
206pub const KERN_ARGMAX = 8;
207pub const KERN_PROC_CWD = 8;
208pub const KERN_PROC_PATHNAME = 9;
209pub const KERN_SECURELVL = 9;
210pub const KERN_PROC_SIGTRAMP = 10;
211pub const KERN_HOSTNAME = 10;
212pub const KERN_HOSTID = 11;
213pub const KERN_CLOCKRATE = 12;
214pub const KERN_VNODE = 13;
215pub const KERN_PROC = 14;
216pub const KERN_FILE = 15;
217pub const KERN_PROC_FLAGMASK = 16;
218pub const KERN_PROF = 16;
219pub const KERN_PROC_FLAG_LWP = 16;
220pub const KERN_POSIX1 = 17;
221pub const KERN_NGROUPS = 18;
222pub const KERN_JOB_CONTROL = 19;
223pub const KERN_SAVED_IDS = 20;
224pub const KERN_BOOTTIME = 21;
225pub const KERN_NISDOMAINNAME = 22;
226pub const KERN_UPDATEINTERVAL = 23;
227pub const KERN_OSRELDATE = 24;
228pub const KERN_NTP_PLL = 25;
229pub const KERN_BOOTFILE = 26;
230pub const KERN_MAXFILESPERPROC = 27;
231pub const KERN_MAXPROCPERUID = 28;
232pub const KERN_DUMPDEV = 29;
233pub const KERN_IPC = 30;
234pub const KERN_DUMMY = 31;
235pub const KERN_PS_STRINGS = 32;
236pub const KERN_USRSTACK = 33;
237pub const KERN_LOGSIGEXIT = 34;
238pub const KERN_IOV_MAX = 35;
239pub const KERN_MAXPOSIXLOCKSPERUID = 36;
240pub const KERN_MAXID = 37;
241
242pub const HOST_NAME_MAX = 255;
243
244pub const O_LARGEFILE = 0; // faked support
245pub const O_RDONLY = 0;
246pub const O_NDELAY = O_NONBLOCK;
247pub const O_WRONLY = 1;
248pub const O_RDWR = 2;
249pub const O_ACCMODE = 3;
250pub const O_NONBLOCK = 4;
251pub const O_APPEND = 8;
252pub const O_SHLOCK = 16;
253pub const O_EXLOCK = 32;
254pub const O_ASYNC = 64;
255pub const O_FSYNC = 128;
256pub const O_SYNC = 128;
257pub const O_NOFOLLOW = 256;
258pub const O_CREAT = 512;
259pub const O_TRUNC = 1024;
260pub const O_EXCL = 2048;
261pub const O_NOCTTY = 32768;
262pub const O_DIRECT = 65536;
263pub const O_CLOEXEC = 131072;
264pub const O_FBLOCKING = 262144;
265pub const O_FNONBLOCKING = 524288;
266pub const O_FAPPEND = 1048576;
267pub const O_FOFFSET = 2097152;
268pub const O_FSYNCWRITE = 4194304;
269pub const O_FASYNCWRITE = 8388608;
270pub const O_DIRECTORY = 134217728;
271
272pub const SEEK_SET = 0;
273pub const SEEK_CUR = 1;
274pub const SEEK_END = 2;
275pub const SEEK_DATA = 3;
276pub const SEEK_HOLE = 4;
277
278pub const F_OK = 0;
279pub const F_ULOCK = 0;
280pub const F_LOCK = 1;
281pub const F_TLOCK = 2;
282pub const F_TEST = 3;
283
284pub const AT_FDCWD = -328243;
285pub const AT_SYMLINK_NOFOLLOW = 1;
286pub const AT_REMOVEDIR = 2;
287pub const AT_EACCESS = 4;
288pub const AT_SYMLINK_FOLLOW = 8;
289
290pub fn WEXITSTATUS(s: u32) u32 {
291 return (s & 0xff00) >> 8;
292}
293pub fn WTERMSIG(s: u32) u32 {
294 return s & 0x7f;
295}
296pub fn WSTOPSIG(s: u32) u32 {
297 return WEXITSTATUS(s);
298}
299pub fn WIFEXITED(s: u32) bool {
300 return WTERMSIG(s) == 0;
301}
302pub fn WIFSTOPPED(s: u32) bool {
303 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
304}
305pub fn WIFSIGNALED(s: u32) bool {
306 return (s & 0xffff) -% 1 < 0xff;
307}
308
309pub const dirent = extern struct {
310 d_fileno: c_ulong,
311 d_namlen: u16,
312 d_type: u8,
313 d_unused1: u8,
314 d_unused2: u32,
315 d_name: [256]u8,
316
317 pub fn reclen(self: dirent) usize {
318 return (@byteOffsetOf(dirent, "d_name") + self.d_namlen + 1 + 7) & ~usize(7);
319 }
320};
321
322pub const DT_UNKNOWN = 0;
323pub const DT_FIFO = 1;
324pub const DT_CHR = 2;
325pub const DT_DIR = 4;
326pub const DT_BLK = 6;
327pub const DT_REG = 8;
328pub const DT_LNK = 10;
329pub const DT_SOCK = 12;
330pub const DT_WHT = 14;
331pub const DT_DBF = 15;
332
333pub const CLOCK_REALTIME = 0;
334pub const CLOCK_VIRTUAL = 1;
335pub const CLOCK_PROF = 2;
336pub const CLOCK_MONOTONIC = 4;
337pub const CLOCK_UPTIME = 5;
338pub const CLOCK_UPTIME_PRECISE = 7;
339pub const CLOCK_UPTIME_FAST = 8;
340pub const CLOCK_REALTIME_PRECISE = 9;
341pub const CLOCK_REALTIME_FAST = 10;
342pub const CLOCK_MONOTONIC_PRECISE = 11;
343pub const CLOCK_MONOTONIC_FAST = 12;
344pub const CLOCK_SECOND = 13;
345pub const CLOCK_THREAD_CPUTIME_ID = 14;
346pub const CLOCK_PROCESS_CPUTIME_ID = 15;
347
348pub const sockaddr = extern struct {
349 sa_len: u8,
350 sa_family: u8,
351 sa_data: [14]u8,
352};
353
354pub const Kevent = extern struct {
355 ident: usize,
356 filter: c_short,
357 flags: c_ushort,
358 fflags: c_uint,
359 data: isize,
360 udata: usize,
361};
362
363pub const pthread_attr_t = extern struct { // copied from freebsd
364 __size: [56]u8,
365 __align: c_long,
366};
367
368pub const EVFILT_FS = -10;
369pub const EVFILT_USER = -9;
370pub const EVFILT_EXCEPT = -8;
371pub const EVFILT_TIMER = -7;
372pub const EVFILT_SIGNAL = -6;
373pub const EVFILT_PROC = -5;
374pub const EVFILT_VNODE = -4;
375pub const EVFILT_AIO = -3;
376pub const EVFILT_WRITE = -2;
377pub const EVFILT_READ = -1;
378pub const EVFILT_SYSCOUNT = 10;
379pub const EVFILT_MARKER = 15;
380
381pub const EV_ADD = 1;
382pub const EV_DELETE = 2;
383pub const EV_ENABLE = 4;
384pub const EV_DISABLE = 8;
385pub const EV_ONESHOT = 16;
386pub const EV_CLEAR = 32;
387pub const EV_RECEIPT = 64;
388pub const EV_DISPATCH = 128;
389pub const EV_NODATA = 4096;
390pub const EV_FLAG1 = 8192;
391pub const EV_ERROR = 16384;
392pub const EV_EOF = 32768;
393pub const EV_SYSFLAGS = 61440;
394
395pub const NOTE_FFNOP = 0;
396pub const NOTE_TRACK = 1;
397pub const NOTE_DELETE = 1;
398pub const NOTE_LOWAT = 1;
399pub const NOTE_TRACKERR = 2;
400pub const NOTE_OOB = 2;
401pub const NOTE_WRITE = 2;
402pub const NOTE_EXTEND = 4;
403pub const NOTE_CHILD = 4;
404pub const NOTE_ATTRIB = 8;
405pub const NOTE_LINK = 16;
406pub const NOTE_RENAME = 32;
407pub const NOTE_REVOKE = 64;
408pub const NOTE_PDATAMASK = 1048575;
409pub const NOTE_FFLAGSMASK = 16777215;
410pub const NOTE_TRIGGER = 16777216;
411pub const NOTE_EXEC = 536870912;
412pub const NOTE_FFAND = 1073741824;
413pub const NOTE_FORK = 1073741824;
414pub const NOTE_EXIT = 2147483648;
415pub const NOTE_FFOR = 2147483648;
416pub const NOTE_FFCTRLMASK = 3221225472;
417pub const NOTE_FFCOPY = 3221225472;
418pub const NOTE_PCTRLMASK = 4026531840;
419
420pub const stack_t = extern struct {
421 ss_sp: [*]u8,
422 ss_size: isize,
423 ss_flags: i32,
424};
425
426pub const S_IREAD = S_IRUSR;
427pub const S_IEXEC = S_IXUSR;
428pub const S_IWRITE = S_IWUSR;
429pub const S_IXOTH = 1;
430pub const S_IWOTH = 2;
431pub const S_IROTH = 4;
432pub const S_IRWXO = 7;
433pub const S_IXGRP = 8;
434pub const S_IWGRP = 16;
435pub const S_IRGRP = 32;
436pub const S_IRWXG = 56;
437pub const S_IXUSR = 64;
438pub const S_IWUSR = 128;
439pub const S_IRUSR = 256;
440pub const S_IRWXU = 448;
441pub const S_ISTXT = 512;
442pub const S_BLKSIZE = 512;
443pub const S_ISVTX = 512;
444pub const S_ISGID = 1024;
445pub const S_ISUID = 2048;
446pub const S_IFIFO = 4096;
447pub const S_IFCHR = 8192;
448pub const S_IFDIR = 16384;
449pub const S_IFBLK = 24576;
450pub const S_IFREG = 32768;
451pub const S_IFDB = 36864;
452pub const S_IFLNK = 40960;
453pub const S_IFSOCK = 49152;
454pub const S_IFWHT = 57344;
455pub const S_IFMT = 61440;
456
457pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
458pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
459pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
460pub const BADSIG = SIG_ERR;
461pub const SIG_BLOCK = 1;
462pub const SIG_UNBLOCK = 2;
463pub const SIG_SETMASK = 3;
464
465pub const SIGIOT = SIGABRT;
466pub const SIGHUP = 1;
467pub const SIGINT = 2;
468pub const SIGQUIT = 3;
469pub const SIGILL = 4;
470pub const SIGTRAP = 5;
471pub const SIGABRT = 6;
472pub const SIGEMT = 7;
473pub const SIGFPE = 8;
474pub const SIGKILL = 9;
475pub const SIGBUS = 10;
476pub const SIGSEGV = 11;
477pub const SIGSYS = 12;
478pub const SIGPIPE = 13;
479pub const SIGALRM = 14;
480pub const SIGTERM = 15;
481pub const SIGURG = 16;
482pub const SIGSTOP = 17;
483pub const SIGTSTP = 18;
484pub const SIGCONT = 19;
485pub const SIGCHLD = 20;
486pub const SIGTTIN = 21;
487pub const SIGTTOU = 22;
488pub const SIGIO = 23;
489pub const SIGXCPU = 24;
490pub const SIGXFSZ = 25;
491pub const SIGVTALRM = 26;
492pub const SIGPROF = 27;
493pub const SIGWINCH = 28;
494pub const SIGINFO = 29;
495pub const SIGUSR1 = 30;
496pub const SIGUSR2 = 31;
497pub const SIGTHR = 32;
498pub const SIGCKPT = 33;
499pub const SIGCKPTEXIT = 34;
500pub const siginfo_t = extern struct {
501 si_signo: c_int,
502 si_errno: c_int,
503 si_code: c_int,
504 si_pid: c_int,
505 si_uid: c_uint,
506 si_status: c_int,
507 si_addr: ?*c_void,
508 si_value: union_sigval,
509 si_band: c_long,
510 __spare__: [7]c_int,
511};
512pub const sigset_t = extern struct {
513 __bits: [4]c_uint,
514};
515pub const sig_atomic_t = c_int;
516pub const Sigaction = extern struct {
517 __sigaction_u: extern union {
518 __sa_handler: ?extern fn(c_int) void,
519 __sa_sigaction: ?extern fn(c_int, [*c]siginfo_t, ?*c_void) void,
520 },
521 sa_flags: c_int,
522 sa_mask: sigset_t,
523};
524pub const sig_t = [*c]extern fn(c_int) void;
525
526pub const sigvec = extern struct {
527 sv_handler: [*c]__sighandler_t,
528 sv_mask: c_int,
529 sv_flags: c_int,
530};
531
532pub const SOCK_STREAM = 1;
533pub const SOCK_DGRAM = 2;
534pub const SOCK_RAW = 3;
535pub const SOCK_RDM = 4;
536pub const SOCK_SEQPACKET = 5;
537pub const SOCK_MAXADDRLEN = 255;
538pub const SOCK_CLOEXEC = 268435456;
539pub const SOCK_NONBLOCK = 536870912;
540
541pub const PF_INET6 = AF_INET6;
542pub const PF_IMPLINK = AF_IMPLINK;
543pub const PF_ROUTE = AF_ROUTE;
544pub const PF_ISO = AF_ISO;
545pub const PF_PIP = pseudo_AF_PIP;
546pub const PF_CHAOS = AF_CHAOS;
547pub const PF_DATAKIT = AF_DATAKIT;
548pub const PF_INET = AF_INET;
549pub const PF_APPLETALK = AF_APPLETALK;
550pub const PF_SIP = AF_SIP;
551pub const PF_OSI = AF_ISO;
552pub const PF_CNT = AF_CNT;
553pub const PF_LINK = AF_LINK;
554pub const PF_HYLINK = AF_HYLINK;
555pub const PF_MAX = AF_MAX;
556pub const PF_KEY = pseudo_AF_KEY;
557pub const PF_PUP = AF_PUP;
558pub const PF_COIP = AF_COIP;
559pub const PF_SNA = AF_SNA;
560pub const PF_LOCAL = AF_LOCAL;
561pub const PF_NETBIOS = AF_NETBIOS;
562pub const PF_NATM = AF_NATM;
563pub const PF_BLUETOOTH = AF_BLUETOOTH;
564pub const PF_UNSPEC = AF_UNSPEC;
565pub const PF_NETGRAPH = AF_NETGRAPH;
566pub const PF_ECMA = AF_ECMA;
567pub const PF_IPX = AF_IPX;
568pub const PF_DLI = AF_DLI;
569pub const PF_ATM = AF_ATM;
570pub const PF_CCITT = AF_CCITT;
571pub const PF_ISDN = AF_ISDN;
572pub const PF_RTIP = pseudo_AF_RTIP;
573pub const PF_LAT = AF_LAT;
574pub const PF_UNIX = PF_LOCAL;
575pub const PF_XTP = pseudo_AF_XTP;
576pub const PF_DECnet = AF_DECnet;
577
578pub const AF_UNSPEC = 0;
579pub const AF_OSI = AF_ISO;
580pub const AF_UNIX = AF_LOCAL;
581pub const AF_LOCAL = 1;
582pub const AF_INET = 2;
583pub const AF_IMPLINK = 3;
584pub const AF_PUP = 4;
585pub const AF_CHAOS = 5;
586pub const AF_NETBIOS = 6;
587pub const AF_ISO = 7;
588pub const AF_ECMA = 8;
589pub const AF_DATAKIT = 9;
590pub const AF_CCITT = 10;
591pub const AF_SNA = 11;
592pub const AF_DLI = 13;
593pub const AF_LAT = 14;
594pub const AF_HYLINK = 15;
595pub const AF_APPLETALK = 16;
596pub const AF_ROUTE = 17;
597pub const AF_LINK = 18;
598pub const AF_COIP = 20;
599pub const AF_CNT = 21;
600pub const AF_IPX = 23;
601pub const AF_SIP = 24;
602pub const AF_ISDN = 26;
603pub const AF_NATM = 29;
604pub const AF_ATM = 30;
605pub const AF_NETGRAPH = 32;
606pub const AF_BLUETOOTH = 33;
607pub const AF_MPLS = 34;
608pub const AF_MAX = 36;
609
610pub const sa_family_t = u8;
611pub const socklen_t = c_uint;
612pub const sockaddr_storage = extern struct {
613 ss_len: u8,
614 ss_family: sa_family_t,
615 __ss_pad1: [6]u8,
616 __ss_align: i64,
617 __ss_pad2: [112]u8,
618};
619pub const dl_phdr_info = extern struct {
620 dlpi_addr: usize,
621 dlpi_name: ?[*]const u8,
622 dlpi_phdr: [*]std.elf.Phdr,
623 dlpi_phnum: u16,
624};
625pub const msghdr = extern struct {
626 msg_name: ?*c_void,
627 msg_namelen: socklen_t,
628 msg_iov: [*c]iovec,
629 msg_iovlen: c_int,
630 msg_control: ?*c_void,
631 msg_controllen: socklen_t,
632 msg_flags: c_int,
633};
634pub const cmsghdr = extern struct {
635 cmsg_len: socklen_t,
636 cmsg_level: c_int,
637 cmsg_type: c_int,
638};
639pub const cmsgcred = extern struct {
640 cmcred_pid: pid_t,
641 cmcred_uid: uid_t,
642 cmcred_euid: uid_t,
643 cmcred_gid: gid_t,
644 cmcred_ngroups: c_short,
645 cmcred_groups: [16]gid_t,
646};
647pub const sf_hdtr = extern struct {
648 headers: [*c]iovec,
649 hdr_cnt: c_int,
650 trailers: [*c]iovec,
651 trl_cnt: c_int,
652};
653
654pub const MS_SYNC = 0;
655pub const MS_ASYNC = 1;
656pub const MS_INVALIDATE = 2;
657
658pub const POSIX_MADV_SEQUENTIAL = 2;
659pub const POSIX_MADV_RANDOM = 1;
660pub const POSIX_MADV_DONTNEED = 4;
661pub const POSIX_MADV_NORMAL = 0;
662pub const POSIX_MADV_WILLNEED = 3;
663
664pub const MADV_SEQUENTIAL = 2;
665pub const MADV_CONTROL_END = MADV_SETMAP;
666pub const MADV_DONTNEED = 4;
667pub const MADV_RANDOM = 1;
668pub const MADV_WILLNEED = 3;
669pub const MADV_NORMAL = 0;
670pub const MADV_CONTROL_START = MADV_INVAL;
671pub const MADV_FREE = 5;
672pub const MADV_NOSYNC = 6;
673pub const MADV_AUTOSYNC = 7;
674pub const MADV_NOCORE = 8;
675pub const MADV_CORE = 9;
676pub const MADV_INVAL = 10;
677pub const MADV_SETMAP = 11;
678
679pub const F_DUPFD = 0;
680pub const F_GETFD = 1;
681pub const F_RDLCK = 1;
682pub const F_SETFD = 2;
683pub const F_UNLCK = 2;
684pub const F_WRLCK = 3;
685pub const F_GETFL = 3;
686pub const F_SETFL = 4;
687pub const F_GETOWN = 5;
688pub const F_SETOWN = 6;
689pub const F_GETLK = 7;
690pub const F_SETLK = 8;
691pub const F_SETLKW = 9;
692pub const F_DUP2FD = 10;
693pub const F_DUPFD_CLOEXEC = 17;
694pub const F_DUP2FD_CLOEXEC = 18;
695
696pub const Flock = extern struct {
697 l_start: off_t,
698 l_len: off_t,
699 l_pid: pid_t,
700 l_type: c_short,
701 l_whence: c_short,
702};
lib/std/os/bits/freebsd.zig+4
...@@ -132,6 +132,10 @@ pub const dirent = extern struct {...@@ -132,6 +132,10 @@ pub const dirent = extern struct {
132 d_namlen: u16,132 d_namlen: u16,
133 d_pad1: u16,133 d_pad1: u16,
134 d_name: [256]u8,134 d_name: [256]u8,
135
136 pub fn reclen(self: dirent) usize {
137 return self.d_reclen;
138 }
135};139};
136140
137pub const in_port_t = u16;141pub const in_port_t = u16;
lib/std/os/bits/linux.zig+4
...@@ -1023,6 +1023,10 @@ pub const dirent64 = extern struct {...@@ -1023,6 +1023,10 @@ pub const dirent64 = extern struct {
1023 d_reclen: u16,1023 d_reclen: u16,
1024 d_type: u8,1024 d_type: u8,
1025 d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/1731025 d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/173
1026
1027 pub fn reclen(self: dirent) usize {
1028 return self.d_reclen;
1029 }
1026};1030};
10271031
1028pub const dl_phdr_info = extern struct {1032pub const dl_phdr_info = extern struct {
lib/std/os/bits/netbsd.zig+4
...@@ -128,6 +128,10 @@ pub const dirent = extern struct {...@@ -128,6 +128,10 @@ pub const dirent = extern struct {
128 d_type: u8,128 d_type: u8,
129 d_off: i64,129 d_off: i64,
130 d_name: [512]u8,130 d_name: [512]u8,
131
132 pub fn reclen(self: dirent) usize {
133 return self.d_reclen;
134 }
131};135};
132136
133pub const in_port_t = u16;137pub const in_port_t = u16;
lib/std/os/dragonfly.zig created+3
...@@ -0,0 +1,3 @@
1const std = @import("../std.zig");
2pub usingnamespace std.c;
3pub usingnamespace @import("bits.zig");
lib/std/os/test.zig+4
...@@ -16,6 +16,7 @@ const AtomicRmwOp = builtin.AtomicRmwOp;...@@ -16,6 +16,7 @@ const AtomicRmwOp = builtin.AtomicRmwOp;
16const AtomicOrder = builtin.AtomicOrder;16const AtomicOrder = builtin.AtomicOrder;
1717
18test "makePath, put some files in it, deleteTree" {18test "makePath, put some files in it, deleteTree" {
19 if (builtin.os == .dragonfly) return error.SkipZigTest;
19 try fs.makePath(a, "os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c");20 try fs.makePath(a, "os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c");
20 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");21 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");
21 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");22 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
...@@ -28,6 +29,7 @@ test "makePath, put some files in it, deleteTree" {...@@ -28,6 +29,7 @@ test "makePath, put some files in it, deleteTree" {
28}29}
2930
30test "access file" {31test "access file" {
32 if (builtin.os == .dragonfly) return error.SkipZigTest;
31 try fs.makePath(a, "os_test_tmp");33 try fs.makePath(a, "os_test_tmp");
32 if (File.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt")) |ok| {34 if (File.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt")) |ok| {
33 @panic("expected error");35 @panic("expected error");
...@@ -95,6 +97,7 @@ test "cpu count" {...@@ -95,6 +97,7 @@ test "cpu count" {
95}97}
9698
97test "AtomicFile" {99test "AtomicFile" {
100 if (builtin.os == .dragonfly) return error.SkipZigTest;
98 var buffer: [1024]u8 = undefined;101 var buffer: [1024]u8 = undefined;
99 const allocator = &std.heap.FixedBufferAllocator.init(buffer[0..]).allocator;102 const allocator = &std.heap.FixedBufferAllocator.init(buffer[0..]).allocator;
100 const test_out_file = "tmp_atomic_file_test_dest.txt";103 const test_out_file = "tmp_atomic_file_test_dest.txt";
...@@ -115,6 +118,7 @@ test "AtomicFile" {...@@ -115,6 +118,7 @@ test "AtomicFile" {
115}118}
116119
117test "thread local storage" {120test "thread local storage" {
121 if (builtin.os == .dragonfly) return error.SkipZigTest;
118 if (builtin.single_threaded) return error.SkipZigTest;122 if (builtin.single_threaded) return error.SkipZigTest;
119 const thread1 = try Thread.spawn({}, testTls);123 const thread1 = try Thread.spawn({}, testTls);
120 const thread2 = try Thread.spawn({}, testTls);124 const thread2 = try Thread.spawn({}, testTls);
lib/std/statically_initialized_mutex.zig+1
...@@ -61,6 +61,7 @@ pub const StaticallyInitializedMutex = switch (builtin.os) {...@@ -61,6 +61,7 @@ pub const StaticallyInitializedMutex = switch (builtin.os) {
61};61};
6262
63test "std.StaticallyInitializedMutex" {63test "std.StaticallyInitializedMutex" {
64 if (builtin.os == .dragonfly) return error.SkipZigTest;
64 const TestContext = struct {65 const TestContext = struct {
65 data: i128,66 data: i128,
6667
src/libc_installation.cpp+4-4
...@@ -320,7 +320,7 @@ Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirnam...@@ -320,7 +320,7 @@ Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirnam
320320
321#undef CC_EXE321#undef CC_EXE
322322
323#if defined(ZIG_OS_WINDOWS) || defined(ZIG_OS_LINUX)323#if defined(ZIG_OS_WINDOWS) || defined(ZIG_OS_LINUX) || defined(ZIG_OS_DRAGONFLY)
324static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool verbose) {324static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool verbose) {
325 return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose);325 return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose);
326}326}
...@@ -413,6 +413,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {...@@ -413,6 +413,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
413 "# The directory that contains `stdlib.h`.\n"413 "# The directory that contains `stdlib.h`.\n"
414 "# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`\n"414 "# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`\n"
415 "include_dir=%s\n"415 "include_dir=%s\n"
416 "\n"
416 "# The system-specific include directory. May be the same as `include_dir`.\n"417 "# The system-specific include directory. May be the same as `include_dir`.\n"
417 "# On Windows it's the directory that includes `vcruntime.h`.\n"418 "# On Windows it's the directory that includes `vcruntime.h`.\n"
418 "# On POSIX it's the directory that includes `sys/errno.h`.\n"419 "# On POSIX it's the directory that includes `sys/errno.h`.\n"
...@@ -435,8 +436,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {...@@ -435,8 +436,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) {
435 "# The directory that contains `kernel32.lib`.\n"436 "# The directory that contains `kernel32.lib`.\n"
436 "# Only needed when targeting MSVC on Windows.\n"437 "# Only needed when targeting MSVC on Windows.\n"
437 "kernel32_lib_dir=%s\n"438 "kernel32_lib_dir=%s\n"
438 "\n"439 "\n",
439 ,
440 buf_ptr(&self->include_dir),440 buf_ptr(&self->include_dir),
441 buf_ptr(&self->sys_include_dir),441 buf_ptr(&self->sys_include_dir),
442 buf_ptr(&self->crt_dir),442 buf_ptr(&self->crt_dir),
...@@ -489,7 +489,7 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {...@@ -489,7 +489,7 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) {
489 return err;489 return err;
490#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)490#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)
491 buf_init_from_str(&self->crt_dir, "/usr/lib");491 buf_init_from_str(&self->crt_dir, "/usr/lib");
492#elif defined(ZIG_OS_LINUX)492#elif defined(ZIG_OS_LINUX) || defined(ZIG_OS_DRAGONFLY)
493 if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))493 if ((err = zig_libc_find_native_crt_dir_posix(self, verbose)))
494 return err;494 return err;
495#endif495#endif
src/link.cpp-16
...@@ -1792,28 +1792,12 @@ static void construct_linker_job_elf(LinkJob *lj) {...@@ -1792,28 +1792,12 @@ static void construct_linker_job_elf(LinkJob *lj) {
1792 if (g->libc != nullptr) {1792 if (g->libc != nullptr) {
1793 if (!g->have_dynamic_link) {1793 if (!g->have_dynamic_link) {
1794 lj->args.append("--start-group");1794 lj->args.append("--start-group");
1795 if (!target_is_android(g->zig_target)) {
1796 lj->args.append("-lgcc");
1797 lj->args.append("-lgcc_eh");
1798 }
1799 lj->args.append("-lc");1795 lj->args.append("-lc");
1800 lj->args.append("-lm");1796 lj->args.append("-lm");
1801 lj->args.append("--end-group");1797 lj->args.append("--end-group");
1802 } else {1798 } else {
1803 if (!target_is_android(g->zig_target)) {
1804 lj->args.append("-lgcc");
1805 lj->args.append("--as-needed");
1806 lj->args.append("-lgcc_s");
1807 lj->args.append("--no-as-needed");
1808 }
1809 lj->args.append("-lc");1799 lj->args.append("-lc");
1810 lj->args.append("-lm");1800 lj->args.append("-lm");
1811 if (!target_is_android(g->zig_target)) {
1812 lj->args.append("-lgcc");
1813 lj->args.append("--as-needed");
1814 lj->args.append("-lgcc_s");
1815 lj->args.append("--no-as-needed");
1816 }
1817 }1801 }
18181802
1819 if (g->zig_target->os == OsFreeBSD) {1803 if (g->zig_target->os == OsFreeBSD) {
src/os.cpp+6-6
...@@ -52,7 +52,7 @@ typedef SSIZE_T ssize_t;...@@ -52,7 +52,7 @@ typedef SSIZE_T ssize_t;
5252
53#endif53#endif
5454
55#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)55#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
56#include <link.h>56#include <link.h>
57#endif57#endif
5858
...@@ -60,7 +60,7 @@ typedef SSIZE_T ssize_t;...@@ -60,7 +60,7 @@ typedef SSIZE_T ssize_t;
60#include <sys/auxv.h>60#include <sys/auxv.h>
61#endif61#endif
6262
63#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)63#if defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
64#include <sys/sysctl.h>64#include <sys/sysctl.h>
65#endif65#endif
6666
...@@ -85,7 +85,7 @@ static clock_serv_t macos_monotonic_clock;...@@ -85,7 +85,7 @@ static clock_serv_t macos_monotonic_clock;
85#if defined(__APPLE__) && !defined(environ)85#if defined(__APPLE__) && !defined(environ)
86#include <crt_externs.h>86#include <crt_externs.h>
87#define environ (*_NSGetEnviron())87#define environ (*_NSGetEnviron())
88#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)88#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
89extern char **environ;89extern char **environ;
90#endif90#endif
9191
...@@ -1450,7 +1450,7 @@ Error os_self_exe_path(Buf *out_path) {...@@ -1450,7 +1450,7 @@ Error os_self_exe_path(Buf *out_path) {
1450 }1450 }
1451 buf_resize(out_path, amt);1451 buf_resize(out_path, amt);
1452 return ErrorNone;1452 return ErrorNone;
1453#elif defined(ZIG_OS_FREEBSD)1453#elif defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_DRAGONFLY)
1454 buf_resize(out_path, PATH_MAX);1454 buf_resize(out_path, PATH_MAX);
1455 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };1455 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
1456 size_t cb = PATH_MAX;1456 size_t cb = PATH_MAX;
...@@ -1792,7 +1792,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {...@@ -1792,7 +1792,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {
1792}1792}
17931793
17941794
1795#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)1795#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
1796static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) {1796static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) {
1797 ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data);1797 ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data);
1798 if (info->dlpi_name[0] == '/') {1798 if (info->dlpi_name[0] == '/') {
...@@ -1803,7 +1803,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size,...@@ -1803,7 +1803,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size,
1803#endif1803#endif
18041804
1805Error os_self_exe_shared_libs(ZigList<Buf *> &paths) {1805Error os_self_exe_shared_libs(ZigList<Buf *> &paths) {
1806#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD)1806#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
1807 paths.resize(0);1807 paths.resize(0);
1808 dl_iterate_phdr(self_exe_shared_libs_callback, &paths);1808 dl_iterate_phdr(self_exe_shared_libs_callback, &paths);
1809 return ErrorNone;1809 return ErrorNone;
src/os.hpp+2
...@@ -27,6 +27,8 @@...@@ -27,6 +27,8 @@
27#define ZIG_OS_FREEBSD27#define ZIG_OS_FREEBSD
28#elif defined(__NetBSD__)28#elif defined(__NetBSD__)
29#define ZIG_OS_NETBSD29#define ZIG_OS_NETBSD
30#elif defined(__DragonFly__)
31#define ZIG_OS_DRAGONFLY
30#else32#else
31#define ZIG_OS_UNKNOWN33#define ZIG_OS_UNKNOWN
32#endif34#endif
src/target.cpp+5-4
...@@ -1050,6 +1050,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -1050,6 +1050,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
1050 case OsZen:1050 case OsZen:
1051 case OsFreeBSD:1051 case OsFreeBSD:
1052 case OsNetBSD:1052 case OsNetBSD:
1053 case OsDragonFly:
1053 case OsOpenBSD:1054 case OsOpenBSD:
1054 case OsWASI:1055 case OsWASI:
1055 case OsEmscripten:1056 case OsEmscripten:
...@@ -1104,7 +1105,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -1104,7 +1105,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
1104 }1105 }
1105 case OsAnanas:1106 case OsAnanas:
1106 case OsCloudABI:1107 case OsCloudABI:
1107 case OsDragonFly:
1108 case OsKFreeBSD:1108 case OsKFreeBSD:
1109 case OsLv2:1109 case OsLv2:
1110 case OsSolaris:1110 case OsSolaris:
...@@ -1267,6 +1267,8 @@ const char *target_dynamic_linker(const ZigTarget *target) {...@@ -1267,6 +1267,8 @@ const char *target_dynamic_linker(const ZigTarget *target) {
1267 return "/libexec/ld-elf.so.1";1267 return "/libexec/ld-elf.so.1";
1268 case OsNetBSD:1268 case OsNetBSD:
1269 return "/libexec/ld.elf_so";1269 return "/libexec/ld.elf_so";
1270 case OsDragonFly:
1271 return "/libexec/ld-elf.so.2";
1270 case OsLinux: {1272 case OsLinux: {
1271 const ZigLLVM_EnvironmentType abi = target->abi;1273 const ZigLLVM_EnvironmentType abi = target->abi;
1272 switch (target->arch) {1274 switch (target->arch) {
...@@ -1383,7 +1385,6 @@ const char *target_dynamic_linker(const ZigTarget *target) {...@@ -1383,7 +1385,6 @@ const char *target_dynamic_linker(const ZigTarget *target) {
13831385
1384 case OsAnanas:1386 case OsAnanas:
1385 case OsCloudABI:1387 case OsCloudABI:
1386 case OsDragonFly:
1387 case OsFuchsia:1388 case OsFuchsia:
1388 case OsKFreeBSD:1389 case OsKFreeBSD:
1389 case OsLv2:1390 case OsLv2:
...@@ -1579,7 +1580,7 @@ bool target_os_requires_libc(Os os) {...@@ -1579,7 +1580,7 @@ bool target_os_requires_libc(Os os) {
1579 // On Darwin, we always link libSystem which contains libc.1580 // On Darwin, we always link libSystem which contains libc.
1580 // Similarly on FreeBSD and NetBSD we always link system libc1581 // Similarly on FreeBSD and NetBSD we always link system libc
1581 // since this is the stable syscall interface.1582 // since this is the stable syscall interface.
1582 return (target_os_is_darwin(os) || os == OsFreeBSD || os == OsNetBSD);1583 return (target_os_is_darwin(os) || os == OsFreeBSD || os == OsNetBSD || os == OsDragonFly);
1583}1584}
15841585
1585bool target_supports_fpic(const ZigTarget *target) {1586bool target_supports_fpic(const ZigTarget *target) {
...@@ -1636,7 +1637,6 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {...@@ -1636,7 +1637,6 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
1636 case OsFreestanding:1637 case OsFreestanding:
1637 case OsAnanas:1638 case OsAnanas:
1638 case OsCloudABI:1639 case OsCloudABI:
1639 case OsDragonFly:
1640 case OsLv2:1640 case OsLv2:
1641 case OsSolaris:1641 case OsSolaris:
1642 case OsHaiku:1642 case OsHaiku:
...@@ -1665,6 +1665,7 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {...@@ -1665,6 +1665,7 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
1665 case OsFuchsia:1665 case OsFuchsia:
1666 case OsKFreeBSD:1666 case OsKFreeBSD:
1667 case OsNetBSD:1667 case OsNetBSD:
1668 case OsDragonFly:
1668 case OsHurd:1669 case OsHurd:
1669 return ZigLLVM_GNU;1670 return ZigLLVM_GNU;
1670 case OsUefi:1671 case OsUefi:
test/stage1/behavior/byteswap.zig+2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
3const builtin = @import("builtin");
34
4test "@byteSwap integers" {5test "@byteSwap integers" {
5 const ByteSwapIntTest = struct {6 const ByteSwapIntTest = struct {
...@@ -40,6 +41,7 @@ test "@byteSwap integers" {...@@ -40,6 +41,7 @@ test "@byteSwap integers" {
4041
41test "@byteSwap vectors" {42test "@byteSwap vectors" {
42 // Disabled because of #331743 // Disabled because of #3317
44 if (builtin.os == .dragonfly) return error.SkipZigTest;
43 if (@import("builtin").arch == .mipsel) return error.SkipZigTest;45 if (@import("builtin").arch == .mipsel) return error.SkipZigTest;
4446
45 const ByteSwapVectorTest = struct {47 const ByteSwapVectorTest = struct {
test/stage1/behavior/vector.zig+2
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const mem = std.mem;2const mem = std.mem;
3const expect = std.testing.expect;3const expect = std.testing.expect;
4const builtin = @import("builtin");
45
5test "implicit cast vector to array - bool" {6test "implicit cast vector to array - bool" {
6 const S = struct {7 const S = struct {
...@@ -111,6 +112,7 @@ test "array to vector" {...@@ -111,6 +112,7 @@ test "array to vector" {
111}112}
112113
113test "vector casts of sizes not divisable by 8" {114test "vector casts of sizes not divisable by 8" {
115 if (builtin.os == .dragonfly) return error.SkipZigTest;
114 const S = struct {116 const S = struct {
115 fn doTheTest() void {117 fn doTheTest() void {
116 {118 {