| author | |
| committer | |
| log | 06435535d3e40e4676e98009fad136f98fffbf2e |
| tree | a72055c4cce2869fa81f12d621560d6bec436f62 |
| parent | f1610f6c1ddbb5c2b42d2ecac433b8eff11d5a3a |
| signature | Commit is signed but in an unrecognized format. |
7 files changed, 46 insertions(+), 55 deletions(-)
std/child_process.zig+2-2| ... | ... | @@ -47,7 +47,7 @@ pub const ChildProcess = struct { |
| 47 | 47 | /// Set to change the current working directory when spawning the child process. |
| 48 | 48 | pub cwd: ?[]const u8, |
| 49 | 49 | |
| 50 | err_pipe: if (os.windows.is_the_target) void else [2]i32, | |
| 50 | err_pipe: if (os.windows.is_the_target) void else [2]os.fd_t, | |
| 51 | 51 | llnode: if (os.windows.is_the_target) void else LinkedList(*ChildProcess).Node, |
| 52 | 52 | |
| 53 | 53 | pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError || |
| ... | ... | @@ -701,7 +701,7 @@ fn windowsMakePipeOut(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *const |
| 701 | 701 | wr.* = wr_h; |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | fn destroyPipe(pipe: [2]i32) void { | |
| 704 | fn destroyPipe(pipe: [2]os.fd_t) void { | |
| 705 | 705 | os.close(pipe[0]); |
| 706 | 706 | os.close(pipe[1]); |
| 707 | 707 | } |
std/event/loop.zig+12-12| ... | ... | @@ -222,10 +222,10 @@ pub const Loop = struct { |
| 222 | 222 | } |
| 223 | 223 | }, |
| 224 | 224 | .macosx, .freebsd, .netbsd => { |
| 225 | self.os_data.kqfd = try os.bsdKQueue(); | |
| 225 | self.os_data.kqfd = try os.kqueue(); | |
| 226 | 226 | errdefer os.close(self.os_data.kqfd); |
| 227 | 227 | |
| 228 | self.os_data.fs_kqfd = try os.bsdKQueue(); | |
| 228 | self.os_data.fs_kqfd = try os.kqueue(); | |
| 229 | 229 | errdefer os.close(self.os_data.fs_kqfd); |
| 230 | 230 | |
| 231 | 231 | self.os_data.fs_queue = std.atomic.Queue(fs.Request).init(); |
| ... | ... | @@ -264,7 +264,7 @@ pub const Loop = struct { |
| 264 | 264 | }; |
| 265 | 265 | self.available_eventfd_resume_nodes.push(eventfd_node); |
| 266 | 266 | const kevent_array = (*const [1]os.Kevent)(&eventfd_node.data.kevent); |
| 267 | _ = try os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null); | |
| 267 | _ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null); | |
| 268 | 268 | eventfd_node.data.kevent.flags = os.EV_CLEAR | os.EV_ENABLE; |
| 269 | 269 | eventfd_node.data.kevent.fflags = os.NOTE_TRIGGER; |
| 270 | 270 | } |
| ... | ... | @@ -280,7 +280,7 @@ pub const Loop = struct { |
| 280 | 280 | .udata = @ptrToInt(&self.final_resume_node), |
| 281 | 281 | }; |
| 282 | 282 | const final_kev_arr = (*const [1]os.Kevent)(&self.os_data.final_kevent); |
| 283 | _ = try os.bsdKEvent(self.os_data.kqfd, final_kev_arr, empty_kevs, null); | |
| 283 | _ = try os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null); | |
| 284 | 284 | self.os_data.final_kevent.flags = os.EV_ENABLE; |
| 285 | 285 | self.os_data.final_kevent.fflags = os.NOTE_TRIGGER; |
| 286 | 286 | |
| ... | ... | @@ -315,7 +315,7 @@ pub const Loop = struct { |
| 315 | 315 | |
| 316 | 316 | var extra_thread_index: usize = 0; |
| 317 | 317 | errdefer { |
| 318 | _ = os.bsdKEvent(self.os_data.kqfd, final_kev_arr, empty_kevs, null) catch unreachable; | |
| 318 | _ = os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null) catch unreachable; | |
| 319 | 319 | while (extra_thread_index != 0) { |
| 320 | 320 | extra_thread_index -= 1; |
| 321 | 321 | self.extra_threads[extra_thread_index].wait(); |
| ... | ... | @@ -474,7 +474,7 @@ pub const Loop = struct { |
| 474 | 474 | }; |
| 475 | 475 | const kevent_array = (*const [1]os.Kevent)(&kev); |
| 476 | 476 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; |
| 477 | _ = try os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null); | |
| 477 | _ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null); | |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | pub fn bsdRemoveKev(self: *Loop, ident: usize, filter: i16) void { |
| ... | ... | @@ -488,7 +488,7 @@ pub const Loop = struct { |
| 488 | 488 | }; |
| 489 | 489 | const kevent_array = (*const [1]os.Kevent)(&kev); |
| 490 | 490 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; |
| 491 | _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch undefined; | |
| 491 | _ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch undefined; | |
| 492 | 492 | self.finishOneEvent(); |
| 493 | 493 | } |
| 494 | 494 | |
| ... | ... | @@ -504,7 +504,7 @@ pub const Loop = struct { |
| 504 | 504 | .macosx, .freebsd, .netbsd => { |
| 505 | 505 | const kevent_array = (*const [1]os.Kevent)(&eventfd_node.kevent); |
| 506 | 506 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; |
| 507 | _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { | |
| 507 | _ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { | |
| 508 | 508 | self.next_tick_queue.unget(next_tick_node); |
| 509 | 509 | self.available_eventfd_resume_nodes.push(resume_stack_node); |
| 510 | 510 | return; |
| ... | ... | @@ -634,7 +634,7 @@ pub const Loop = struct { |
| 634 | 634 | const final_kevent = (*const [1]os.Kevent)(&self.os_data.final_kevent); |
| 635 | 635 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; |
| 636 | 636 | // cannot fail because we already added it and this just enables it |
| 637 | _ = os.bsdKEvent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable; | |
| 637 | _ = os.kevent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable; | |
| 638 | 638 | return; |
| 639 | 639 | }, |
| 640 | 640 | .windows => { |
| ... | ... | @@ -690,7 +690,7 @@ pub const Loop = struct { |
| 690 | 690 | .macosx, .freebsd, .netbsd => { |
| 691 | 691 | var eventlist: [1]os.Kevent = undefined; |
| 692 | 692 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; |
| 693 | const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; | |
| 693 | const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; | |
| 694 | 694 | for (eventlist[0..count]) |ev| { |
| 695 | 695 | const resume_node = @intToPtr(*ResumeNode, ev.udata); |
| 696 | 696 | const handle = resume_node.handle; |
| ... | ... | @@ -753,7 +753,7 @@ pub const Loop = struct { |
| 753 | 753 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 754 | 754 | const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wake); |
| 755 | 755 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; |
| 756 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable; | |
| 756 | _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable; | |
| 757 | 757 | }, |
| 758 | 758 | builtin.Os.linux => { |
| 759 | 759 | _ = @atomicRmw(i32, &self.os_data.fs_queue_item, AtomicRmwOp.Xchg, 1, AtomicOrder.SeqCst); |
| ... | ... | @@ -823,7 +823,7 @@ pub const Loop = struct { |
| 823 | 823 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 824 | 824 | const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wait); |
| 825 | 825 | var out_kevs: [1]os.Kevent = undefined; |
| 826 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable; | |
| 826 | _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable; | |
| 827 | 827 | }, |
| 828 | 828 | else => @compileError("Unsupported OS"), |
| 829 | 829 | } |
std/fs.zig+6-6| ... | ... | @@ -509,7 +509,7 @@ pub const Dir = struct { |
| 509 | 509 | } |
| 510 | 510 | } |
| 511 | 511 | self.handle.index = 0; |
| 512 | self.handle.end_index = @intCast(usize, result); | |
| 512 | self.handle.end_index = @intCast(usize, rc); | |
| 513 | 513 | break; |
| 514 | 514 | } |
| 515 | 515 | } |
| ... | ... | @@ -694,7 +694,7 @@ pub fn readLinkC(pathname: [*]const u8, buffer: *[os.PATH_MAX]u8) ![]u8 { |
| 694 | 694 | return os.readlinkC(pathname, buffer); |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError; | |
| 697 | pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfExePathError; | |
| 698 | 698 | |
| 699 | 699 | pub fn openSelfExe() OpenSelfExeError!File { |
| 700 | 700 | if (os.linux.is_the_target) { |
| ... | ... | @@ -730,10 +730,10 @@ pub const SelfExePathError = os.ReadLinkError || os.SysCtlError; |
| 730 | 730 | /// On Linux, depends on procfs being mounted. If the currently executing binary has |
| 731 | 731 | /// been deleted, the file path looks something like `/a/b/c/exe (deleted)`. |
| 732 | 732 | /// TODO make the return type of this a null terminated pointer |
| 733 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | |
| 733 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 { | |
| 734 | 734 | if (os.darwin.is_the_target) { |
| 735 | 735 | var u32_len: u32 = out_buffer.len; |
| 736 | const rc = c._NSGetExecutablePath(out_buffer, &u32_len); | |
| 736 | const rc = std.c._NSGetExecutablePath(out_buffer, &u32_len); | |
| 737 | 737 | if (rc != 0) return error.NameTooLong; |
| 738 | 738 | return mem.toSlice(u8, out_buffer); |
| 739 | 739 | } |
| ... | ... | @@ -765,13 +765,13 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /// Same as `selfExePath` except the result is UTF16LE-encoded. |
| 768 | pub fn selfExePathW(out_buffer: *[os.windows.PATH_MAX_WIDE]u16) ![]u16 { | |
| 768 | pub fn selfExePathW(out_buffer: *[os.windows.PATH_MAX_WIDE]u16) SelfExePathError![]u16 { | |
| 769 | 769 | return os.windows.GetModuleFileNameW(null, out_buffer, out_buffer.len); |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | /// `selfExeDirPath` except allocates the result on the heap. |
| 773 | 773 | /// Caller owns returned memory. |
| 774 | pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 { | |
| 774 | pub fn selfExeDirPathAlloc(allocator: *Allocator) SelfExePathError![]u8 { | |
| 775 | 775 | var buf: [MAX_PATH_BYTES]u8 = undefined; |
| 776 | 776 | return mem.dupe(allocator, u8, try selfExeDirPath(&buf)); |
| 777 | 777 | } |
std/os.zig+23-10| ... | ... | @@ -297,8 +297,9 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) ReadError!usize { |
| 297 | 297 | const err = darwin.getErrno(rc); |
| 298 | 298 | switch (err) { |
| 299 | 299 | 0 => { |
| 300 | off += rc; | |
| 301 | inner_off += rc; | |
| 300 | const amt_read = @bitCast(usize, rc); | |
| 301 | off += amt_read; | |
| 302 | inner_off += amt_read; | |
| 302 | 303 | if (inner_off == v.iov_len) { |
| 303 | 304 | iov_i += 1; |
| 304 | 305 | inner_off = 0; |
| ... | ... | @@ -421,8 +422,9 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) WriteError!void |
| 421 | 422 | const err = darwin.getErrno(rc); |
| 422 | 423 | switch (err) { |
| 423 | 424 | 0 => { |
| 424 | off += rc; | |
| 425 | inner_off += rc; | |
| 425 | const amt_written = @bitCast(usize, rc); | |
| 426 | off += amt_written; | |
| 427 | inner_off += amt_written; | |
| 426 | 428 | if (inner_off == v.iov_len) { |
| 427 | 429 | iov_i += 1; |
| 428 | 430 | inner_off = 0; |
| ... | ... | @@ -1205,8 +1207,8 @@ pub fn isatty(handle: fd_t) bool { |
| 1205 | 1207 | @compileError("TODO implement std.os.isatty for WASI"); |
| 1206 | 1208 | } |
| 1207 | 1209 | if (linux.is_the_target) { |
| 1208 | var wsz: system.winsize = undefined; | |
| 1209 | return system.syscall3(system.SYS_ioctl, @bitCast(usize, isize(handle)), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | |
| 1210 | var wsz: linux.winsize = undefined; | |
| 1211 | return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, isize(handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | |
| 1210 | 1212 | } |
| 1211 | 1213 | unreachable; |
| 1212 | 1214 | } |
| ... | ... | @@ -1778,6 +1780,10 @@ pub const KEventError = error{ |
| 1778 | 1780 | |
| 1779 | 1781 | /// The specified process to attach to does not exist. |
| 1780 | 1782 | ProcessNotFound, |
| 1783 | ||
| 1784 | /// changelist or eventlist had too many items on it. | |
| 1785 | /// TODO remove this possibility | |
| 1786 | Overflow, | |
| 1781 | 1787 | }; |
| 1782 | 1788 | |
| 1783 | 1789 | pub fn kevent( |
| ... | ... | @@ -1787,9 +1793,16 @@ pub fn kevent( |
| 1787 | 1793 | timeout: ?*const timespec, |
| 1788 | 1794 | ) KEventError!usize { |
| 1789 | 1795 | while (true) { |
| 1790 | const rc = system.kevent(kq, changelist, eventlist, timeout); | |
| 1796 | const rc = system.kevent( | |
| 1797 | kq, | |
| 1798 | changelist.ptr, | |
| 1799 | try math.cast(c_int, changelist.len), | |
| 1800 | eventlist.ptr, | |
| 1801 | try math.cast(c_int, eventlist.len), | |
| 1802 | timeout, | |
| 1803 | ); | |
| 1791 | 1804 | switch (errno(rc)) { |
| 1792 | 0 => return rc, | |
| 1805 | 0 => return @intCast(usize, rc), | |
| 1793 | 1806 | EACCES => return error.AccessDenied, |
| 1794 | 1807 | EFAULT => unreachable, |
| 1795 | 1808 | EBADF => unreachable, // Always a race condition. |
| ... | ... | @@ -2028,7 +2041,7 @@ pub const PipeError = error{ |
| 2028 | 2041 | |
| 2029 | 2042 | /// Creates a unidirectional data channel that can be used for interprocess communication. |
| 2030 | 2043 | pub fn pipe() PipeError![2]fd_t { |
| 2031 | var fds: [2]i32 = undefined; | |
| 2044 | var fds: [2]fd_t = undefined; | |
| 2032 | 2045 | switch (errno(system.pipe(&fds))) { |
| 2033 | 2046 | 0 => return fds, |
| 2034 | 2047 | EINVAL => unreachable, // Invalid parameters to pipe() |
| ... | ... | @@ -2040,7 +2053,7 @@ pub fn pipe() PipeError![2]fd_t { |
| 2040 | 2053 | } |
| 2041 | 2054 | |
| 2042 | 2055 | pub fn pipe2(flags: u32) PipeError![2]fd_t { |
| 2043 | var fds: [2]i32 = undefined; | |
| 2056 | var fds: [2]fd_t = undefined; | |
| 2044 | 2057 | switch (errno(system.pipe2(&fds, flags))) { |
| 2045 | 2058 | 0 => return fds, |
| 2046 | 2059 | EINVAL => unreachable, // Invalid flags |
std/os/bits/darwin.zig+1-23| ... | ... | @@ -1,32 +1,10 @@ |
| 1 | 1 | const std = @import("../../std.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | const maxInt = std.math.maxInt; | |
| 3 | 4 | |
| 4 | 5 | pub const fd_t = c_int; |
| 5 | 6 | pub const pid_t = c_int; |
| 6 | 7 | |
| 7 | pub fn sigaction(sig: u5, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize { | |
| 8 | assert(sig != SIGKILL); | |
| 9 | assert(sig != SIGSTOP); | |
| 10 | var cact = c.Sigaction{ | |
| 11 | .handler = @ptrCast(extern fn (c_int) void, act.handler), | |
| 12 | .sa_flags = @bitCast(c_int, act.flags), | |
| 13 | .sa_mask = act.mask, | |
| 14 | }; | |
| 15 | var coact: c.Sigaction = undefined; | |
| 16 | const result = errnoWrap(c.sigaction(sig, &cact, &coact)); | |
| 17 | if (result != 0) { | |
| 18 | return result; | |
| 19 | } | |
| 20 | if (oact) |old| { | |
| 21 | old.* = Sigaction{ | |
| 22 | .handler = @ptrCast(extern fn (i32) void, coact.handler), | |
| 23 | .flags = @bitCast(u32, coact.sa_flags), | |
| 24 | .mask = coact.sa_mask, | |
| 25 | }; | |
| 26 | } | |
| 27 | return result; | |
| 28 | } | |
| 29 | ||
| 30 | 8 | pub const in_port_t = u16; |
| 31 | 9 | pub const sa_family_t = u8; |
| 32 | 10 | pub const socklen_t = u32; |
std/os/bits/windows.zig-1| ... | ... | @@ -159,5 +159,4 @@ pub const EWOULDBLOCK = 140; |
| 159 | 159 | // for if branches that aren't taken. |
| 160 | 160 | pub const SIGKILL = @compileError("Windows libc does not have this"); |
| 161 | 161 | pub const EDQUOT = @compileError("Windows libc does not have this"); |
| 162 | pub const TIOCGWINSZ = @compileError("Windows libc does not have this"); | |
| 163 | 162 | pub const F_OK = 0; |
std/thread.zig+2-1| ... | ... | @@ -323,6 +323,7 @@ pub const Thread = struct { |
| 323 | 323 | pub const CpuCountError = error{ |
| 324 | 324 | OutOfMemory, |
| 325 | 325 | PermissionDenied, |
| 326 | SystemResources, | |
| 326 | 327 | Unexpected, |
| 327 | 328 | }; |
| 328 | 329 | |
| ... | ... | @@ -339,7 +340,7 @@ pub const Thread = struct { |
| 339 | 340 | var count: c_int = undefined; |
| 340 | 341 | var count_len: usize = @sizeOf(c_int); |
| 341 | 342 | const name = if (os.darwin.is_the_target) c"hw.logicalcpu" else c"hw.ncpu"; |
| 342 | try os.sysctlbyname(name, @ptrCast(*c_void, &count), &count_len, null, 0); | |
| 343 | try os.sysctlbynameC(name, @ptrCast(*c_void, &count), &count_len, null, 0); | |
| 343 | 344 | return @intCast(usize, count); |
| 344 | 345 | } |
| 345 | 346 | }; |