| author | |
| committer | |
| log | 129714d077ca6f3f6d09300b1fa2171915f7c839 |
| tree | e71844723e23dc5dc991d6cb40dd56693caffa88 |
| parent | 6be79d79aab204718116428c9b23be7de54e14da |
| signature |
13 files changed, 118 insertions(+), 97 deletions(-)
CMakeLists.txt+1-1| ... | ... | @@ -616,7 +616,6 @@ set(ZIG_STD_FILES |
| 616 | 616 | "os/bits/wasi.zig" |
| 617 | 617 | "os/bits/windows.zig" |
| 618 | 618 | "os/darwin.zig" |
| 619 | "os/epoch.zig" | |
| 620 | 619 | "os/freebsd.zig" |
| 621 | 620 | "os/linux.zig" |
| 622 | 621 | "os/linux/arm64.zig" |
| ... | ... | @@ -723,6 +722,7 @@ set(ZIG_STD_FILES |
| 723 | 722 | "testing.zig" |
| 724 | 723 | "thread.zig" |
| 725 | 724 | "time.zig" |
| 725 | "time/epoch.zig" | |
| 726 | 726 | "unicode.zig" |
| 727 | 727 | "valgrind.zig" |
| 728 | 728 | "valgrind/callgrind.zig" |
std/event/loop.zig+36-36| ... | ... | @@ -32,7 +32,7 @@ pub const Loop = struct { |
| 32 | 32 | overlapped: Overlapped, |
| 33 | 33 | |
| 34 | 34 | pub const overlapped_init = switch (builtin.os) { |
| 35 | builtin.Os.windows => windows.OVERLAPPED{ | |
| 35 | .windows => windows.OVERLAPPED{ | |
| 36 | 36 | .Internal = 0, |
| 37 | 37 | .InternalHigh = 0, |
| 38 | 38 | .Offset = 0, |
| ... | ... | @@ -50,13 +50,13 @@ pub const Loop = struct { |
| 50 | 50 | }; |
| 51 | 51 | |
| 52 | 52 | pub const EventFd = switch (builtin.os) { |
| 53 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => KEventFd, | |
| 54 | builtin.Os.linux => struct { | |
| 53 | .macosx, .freebsd, .netbsd => KEventFd, | |
| 54 | .linux => struct { | |
| 55 | 55 | base: ResumeNode, |
| 56 | 56 | epoll_op: u32, |
| 57 | 57 | eventfd: i32, |
| 58 | 58 | }, |
| 59 | builtin.Os.windows => struct { | |
| 59 | .windows => struct { | |
| 60 | 60 | base: ResumeNode, |
| 61 | 61 | completion_key: usize, |
| 62 | 62 | }, |
| ... | ... | @@ -69,11 +69,11 @@ pub const Loop = struct { |
| 69 | 69 | }; |
| 70 | 70 | |
| 71 | 71 | pub const Basic = switch (builtin.os) { |
| 72 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => KEventBasic, | |
| 73 | builtin.Os.linux => struct { | |
| 72 | .macosx, .freebsd, .netbsd => KEventBasic, | |
| 73 | .linux => struct { | |
| 74 | 74 | base: ResumeNode, |
| 75 | 75 | }, |
| 76 | builtin.Os.windows => struct { | |
| 76 | .windows => struct { | |
| 77 | 77 | base: ResumeNode, |
| 78 | 78 | }, |
| 79 | 79 | else => @compileError("unsupported OS"), |
| ... | ... | @@ -147,7 +147,7 @@ pub const Loop = struct { |
| 147 | 147 | |
| 148 | 148 | fn initOsData(self: *Loop, extra_thread_count: usize) InitOsDataError!void { |
| 149 | 149 | switch (builtin.os) { |
| 150 | builtin.Os.linux => { | |
| 150 | .linux => { | |
| 151 | 151 | self.os_data.fs_queue = std.atomic.Queue(fs.Request).init(); |
| 152 | 152 | self.os_data.fs_queue_item = 0; |
| 153 | 153 | // we need another thread for the file system because Linux does not have an async |
| ... | ... | @@ -221,7 +221,7 @@ pub const Loop = struct { |
| 221 | 221 | self.extra_threads[extra_thread_index] = try Thread.spawn(self, workerRun); |
| 222 | 222 | } |
| 223 | 223 | }, |
| 224 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { | |
| 224 | .macosx, .freebsd, .netbsd => { | |
| 225 | 225 | self.os_data.kqfd = try os.bsdKQueue(); |
| 226 | 226 | errdefer os.close(self.os_data.kqfd); |
| 227 | 227 | |
| ... | ... | @@ -325,14 +325,14 @@ pub const Loop = struct { |
| 325 | 325 | self.extra_threads[extra_thread_index] = try Thread.spawn(self, workerRun); |
| 326 | 326 | } |
| 327 | 327 | }, |
| 328 | builtin.Os.windows => { | |
| 329 | self.os_data.io_port = try os.windowsCreateIoCompletionPort( | |
| 328 | .windows => { | |
| 329 | self.os_data.io_port = try windows.CreateIoCompletionPort( | |
| 330 | 330 | windows.INVALID_HANDLE_VALUE, |
| 331 | 331 | null, |
| 332 | 332 | undefined, |
| 333 | 333 | maxInt(windows.DWORD), |
| 334 | 334 | ); |
| 335 | errdefer os.close(self.os_data.io_port); | |
| 335 | errdefer windows.CloseHandle(self.os_data.io_port); | |
| 336 | 336 | |
| 337 | 337 | for (self.eventfd_resume_nodes) |*eventfd_node, i| { |
| 338 | 338 | eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{ |
| ... | ... | @@ -361,7 +361,7 @@ pub const Loop = struct { |
| 361 | 361 | while (i < extra_thread_index) : (i += 1) { |
| 362 | 362 | while (true) { |
| 363 | 363 | const overlapped = &self.final_resume_node.overlapped; |
| 364 | os.windowsPostQueuedCompletionStatus(self.os_data.io_port, undefined, undefined, overlapped) catch continue; | |
| 364 | windows.PostQueuedCompletionStatus(self.os_data.io_port, undefined, undefined, overlapped) catch continue; | |
| 365 | 365 | break; |
| 366 | 366 | } |
| 367 | 367 | } |
| ... | ... | @@ -380,18 +380,18 @@ pub const Loop = struct { |
| 380 | 380 | |
| 381 | 381 | fn deinitOsData(self: *Loop) void { |
| 382 | 382 | switch (builtin.os) { |
| 383 | builtin.Os.linux => { | |
| 383 | .linux => { | |
| 384 | 384 | os.close(self.os_data.final_eventfd); |
| 385 | 385 | while (self.available_eventfd_resume_nodes.pop()) |node| os.close(node.data.eventfd); |
| 386 | 386 | os.close(self.os_data.epollfd); |
| 387 | 387 | self.allocator.free(self.eventfd_resume_nodes); |
| 388 | 388 | }, |
| 389 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { | |
| 389 | .macosx, .freebsd, .netbsd => { | |
| 390 | 390 | os.close(self.os_data.kqfd); |
| 391 | 391 | os.close(self.os_data.fs_kqfd); |
| 392 | 392 | }, |
| 393 | builtin.Os.windows => { | |
| 394 | os.close(self.os_data.io_port); | |
| 393 | .windows => { | |
| 394 | windows.CloseHandle(self.os_data.io_port); | |
| 395 | 395 | }, |
| 396 | 396 | else => {}, |
| 397 | 397 | } |
| ... | ... | @@ -501,7 +501,7 @@ pub const Loop = struct { |
| 501 | 501 | const eventfd_node = &resume_stack_node.data; |
| 502 | 502 | eventfd_node.base.handle = next_tick_node.data; |
| 503 | 503 | switch (builtin.os) { |
| 504 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { | |
| 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 | 507 | _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { |
| ... | ... | @@ -510,7 +510,7 @@ pub const Loop = struct { |
| 510 | 510 | return; |
| 511 | 511 | }; |
| 512 | 512 | }, |
| 513 | builtin.Os.linux => { | |
| 513 | .linux => { | |
| 514 | 514 | // the pending count is already accounted for |
| 515 | 515 | const epoll_events = os.EPOLLONESHOT | os.linux.EPOLLIN | os.linux.EPOLLOUT | |
| 516 | 516 | os.linux.EPOLLET; |
| ... | ... | @@ -525,8 +525,8 @@ pub const Loop = struct { |
| 525 | 525 | return; |
| 526 | 526 | }; |
| 527 | 527 | }, |
| 528 | builtin.Os.windows => { | |
| 529 | os.windowsPostQueuedCompletionStatus( | |
| 528 | .windows => { | |
| 529 | windows.PostQueuedCompletionStatus( | |
| 530 | 530 | self.os_data.io_port, |
| 531 | 531 | undefined, |
| 532 | 532 | undefined, |
| ... | ... | @@ -623,13 +623,13 @@ pub const Loop = struct { |
| 623 | 623 | if (prev == 1) { |
| 624 | 624 | // cause all the threads to stop |
| 625 | 625 | switch (builtin.os) { |
| 626 | builtin.Os.linux => { | |
| 626 | .linux => { | |
| 627 | 627 | self.posixFsRequest(&self.os_data.fs_end_request); |
| 628 | 628 | // writing 8 bytes to an eventfd cannot fail |
| 629 | 629 | os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable; |
| 630 | 630 | return; |
| 631 | 631 | }, |
| 632 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { | |
| 632 | .macosx, .freebsd, .netbsd => { | |
| 633 | 633 | self.posixFsRequest(&self.os_data.fs_end_request); |
| 634 | 634 | const final_kevent = (*const [1]os.Kevent)(&self.os_data.final_kevent); |
| 635 | 635 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; |
| ... | ... | @@ -637,12 +637,12 @@ pub const Loop = struct { |
| 637 | 637 | _ = os.bsdKEvent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable; |
| 638 | 638 | return; |
| 639 | 639 | }, |
| 640 | builtin.Os.windows => { | |
| 640 | .windows => { | |
| 641 | 641 | var i: usize = 0; |
| 642 | 642 | while (i < self.extra_threads.len + 1) : (i += 1) { |
| 643 | 643 | while (true) { |
| 644 | 644 | const overlapped = &self.final_resume_node.overlapped; |
| 645 | os.windowsPostQueuedCompletionStatus(self.os_data.io_port, undefined, undefined, overlapped) catch continue; | |
| 645 | windows.PostQueuedCompletionStatus(self.os_data.io_port, undefined, undefined, overlapped) catch continue; | |
| 646 | 646 | break; |
| 647 | 647 | } |
| 648 | 648 | } |
| ... | ... | @@ -663,7 +663,7 @@ pub const Loop = struct { |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | switch (builtin.os) { |
| 666 | builtin.Os.linux => { | |
| 666 | .linux => { | |
| 667 | 667 | // only process 1 event so we don't steal from other threads |
| 668 | 668 | var events: [1]os.linux.epoll_event = undefined; |
| 669 | 669 | const count = os.epoll_wait(self.os_data.epollfd, events[0..], -1); |
| ... | ... | @@ -687,7 +687,7 @@ pub const Loop = struct { |
| 687 | 687 | } |
| 688 | 688 | } |
| 689 | 689 | }, |
| 690 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { | |
| 690 | .macosx, .freebsd, .netbsd => { | |
| 691 | 691 | var eventlist: [1]os.Kevent = undefined; |
| 692 | 692 | const empty_kevs = ([*]os.Kevent)(undefined)[0..0]; |
| 693 | 693 | const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; |
| ... | ... | @@ -713,16 +713,16 @@ pub const Loop = struct { |
| 713 | 713 | } |
| 714 | 714 | } |
| 715 | 715 | }, |
| 716 | builtin.Os.windows => { | |
| 716 | .windows => { | |
| 717 | 717 | var completion_key: usize = undefined; |
| 718 | 718 | const overlapped = while (true) { |
| 719 | 719 | var nbytes: windows.DWORD = undefined; |
| 720 | 720 | var overlapped: ?*windows.OVERLAPPED = undefined; |
| 721 | switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, &overlapped, windows.INFINITE)) { | |
| 722 | os.WindowsWaitResult.Aborted => return, | |
| 723 | os.WindowsWaitResult.Normal => {}, | |
| 724 | os.WindowsWaitResult.EOF => {}, | |
| 725 | os.WindowsWaitResult.Cancelled => continue, | |
| 721 | switch (windows.GetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, &overlapped, windows.INFINITE)) { | |
| 722 | .Aborted => return, | |
| 723 | .Normal => {}, | |
| 724 | .EOF => {}, | |
| 725 | .Cancelled => continue, | |
| 726 | 726 | } |
| 727 | 727 | if (overlapped) |o| break o; |
| 728 | 728 | } else unreachable; // TODO else unreachable should not be necessary |
| ... | ... | @@ -831,9 +831,9 @@ pub const Loop = struct { |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | const OsData = switch (builtin.os) { |
| 834 | builtin.Os.linux => LinuxOsData, | |
| 835 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => KEventData, | |
| 836 | builtin.Os.windows => struct { | |
| 834 | .linux => LinuxOsData, | |
| 835 | .macosx, .freebsd, .netbsd => KEventData, | |
| 836 | .windows => struct { | |
| 837 | 837 | io_port: windows.HANDLE, |
| 838 | 838 | extra_thread_count: usize, |
| 839 | 839 | }, |
std/fs/get_app_data_dir.zig+1-1| ... | ... | @@ -23,7 +23,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD |
| 23 | 23 | &dir_path_ptr, |
| 24 | 24 | )) { |
| 25 | 25 | os.windows.S_OK => { |
| 26 | defer os.windows.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr)); | |
| 26 | defer os.windows.ole32.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr)); | |
| 27 | 27 | const global_dir = unicode.utf16leToUtf8Alloc(allocator, utf16lePtrSlice(dir_path_ptr)) catch |err| switch (err) { |
| 28 | 28 | error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable, |
| 29 | 29 | error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable, |
std/heap.zig+6-6| ... | ... | @@ -261,7 +261,7 @@ pub const HeapAllocator = switch (builtin.os) { |
| 261 | 261 | |
| 262 | 262 | pub fn deinit(self: *HeapAllocator) void { |
| 263 | 263 | if (self.heap_handle) |heap_handle| { |
| 264 | _ = os.windows.HeapDestroy(heap_handle); | |
| 264 | os.windows.HeapDestroy(heap_handle); | |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | |
| ... | ... | @@ -274,12 +274,12 @@ pub const HeapAllocator = switch (builtin.os) { |
| 274 | 274 | const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, builtin.AtomicOrder.SeqCst); |
| 275 | 275 | const heap_handle = optional_heap_handle orelse blk: { |
| 276 | 276 | const options = if (builtin.single_threaded) os.windows.HEAP_NO_SERIALIZE else 0; |
| 277 | const hh = os.windows.HeapCreate(options, amt, 0) orelse return error.OutOfMemory; | |
| 277 | const hh = os.windows.kernel32.HeapCreate(options, amt, 0) orelse return error.OutOfMemory; | |
| 278 | 278 | const other_hh = @cmpxchgStrong(?HeapHandle, &self.heap_handle, null, hh, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) orelse break :blk hh; |
| 279 | _ = os.windows.HeapDestroy(hh); | |
| 279 | os.windows.HeapDestroy(hh); | |
| 280 | 280 | break :blk other_hh.?; // can't be null because of the cmpxchg |
| 281 | 281 | }; |
| 282 | const ptr = os.windows.HeapAlloc(heap_handle, 0, amt) orelse return error.OutOfMemory; | |
| 282 | const ptr = os.windows.kernel32.HeapAlloc(heap_handle, 0, amt) orelse return error.OutOfMemory; | |
| 283 | 283 | const root_addr = @ptrToInt(ptr); |
| 284 | 284 | const adjusted_addr = mem.alignForward(root_addr, alignment); |
| 285 | 285 | const record_addr = adjusted_addr + n; |
| ... | ... | @@ -309,12 +309,12 @@ pub const HeapAllocator = switch (builtin.os) { |
| 309 | 309 | const old_ptr = @intToPtr(*c_void, root_addr); |
| 310 | 310 | |
| 311 | 311 | if (new_size == 0) { |
| 312 | if (os.windows.HeapFree(self.heap_handle.?, 0, old_ptr) == 0) unreachable; | |
| 312 | os.windows.HeapFree(self.heap_handle.?, 0, old_ptr); | |
| 313 | 313 | return old_mem[0..0]; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | const amt = new_size + new_align + @sizeOf(usize); |
| 317 | const new_ptr = os.windows.HeapReAlloc( | |
| 317 | const new_ptr = os.windows.kernel32.HeapReAlloc( | |
| 318 | 318 | self.heap_handle.?, |
| 319 | 319 | 0, |
| 320 | 320 | old_ptr, |
std/os.zig+9-4| ... | ... | @@ -944,7 +944,7 @@ pub fn renameC(old_path: [*]const u8, new_path: [*]const u8) RenameError!void { |
| 944 | 944 | /// Assumes target is Windows. |
| 945 | 945 | pub fn renameW(old_path: [*]const u16, new_path: [*]const u16) RenameError!void { |
| 946 | 946 | const flags = windows.MOVEFILE_REPLACE_EXISTING | windows.MOVEFILE_WRITE_THROUGH; |
| 947 | return windows.MoveFileExW(old_path_w, new_path_w, flags); | |
| 947 | return windows.MoveFileExW(old_path, new_path, flags); | |
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | pub const MakeDirError = error{ |
| ... | ... | @@ -959,6 +959,8 @@ pub const MakeDirError = error{ |
| 959 | 959 | NoSpaceLeft, |
| 960 | 960 | NotDir, |
| 961 | 961 | ReadOnlyFileSystem, |
| 962 | InvalidUtf8, | |
| 963 | BadPathName, | |
| 962 | 964 | Unexpected, |
| 963 | 965 | }; |
| 964 | 966 | |
| ... | ... | @@ -2227,6 +2229,9 @@ pub const RealPathError = error{ |
| 2227 | 2229 | BadPathName, |
| 2228 | 2230 | DeviceBusy, |
| 2229 | 2231 | |
| 2232 | SharingViolation, | |
| 2233 | PipeBusy, | |
| 2234 | ||
| 2230 | 2235 | /// On Windows, file paths must be valid Unicode. |
| 2231 | 2236 | InvalidUtf8, |
| 2232 | 2237 | |
| ... | ... | @@ -2294,7 +2299,7 @@ pub fn realpathW(pathname: [*]const u16, out_buffer: *[MAX_PATH_BYTES]u8) RealPa |
| 2294 | 2299 | var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined; |
| 2295 | 2300 | const wide_len = try windows.GetFinalPathNameByHandleW(h_file, &wide_buf, wide_buf.len, windows.VOLUME_NAME_DOS); |
| 2296 | 2301 | assert(wide_len <= wide_buf.len); |
| 2297 | const wide_slice = wide_len[0..wide_len]; | |
| 2302 | const wide_slice = wide_buf[0..wide_len]; | |
| 2298 | 2303 | |
| 2299 | 2304 | // Windows returns \\?\ prepended to the path. |
| 2300 | 2305 | // We strip it to make this function consistent across platforms. |
| ... | ... | @@ -2311,13 +2316,13 @@ pub fn nanosleep(seconds: u64, nanoseconds: u64) void { |
| 2311 | 2316 | if (windows.is_the_target and !builtin.link_libc) { |
| 2312 | 2317 | // TODO https://github.com/ziglang/zig/issues/1284 |
| 2313 | 2318 | const small_s = math.cast(windows.DWORD, seconds) catch math.maxInt(windows.DWORD); |
| 2314 | const ms_from_s = math.mul(small_s, std.time.ms_per_s) catch math.maxInt(windows.DWORD); | |
| 2319 | const ms_from_s = math.mul(windows.DWORD, small_s, std.time.ms_per_s) catch math.maxInt(windows.DWORD); | |
| 2315 | 2320 | |
| 2316 | 2321 | const ns_per_ms = std.time.ns_per_s / std.time.ms_per_s; |
| 2317 | 2322 | const big_ms_from_ns = nanoseconds / ns_per_ms; |
| 2318 | 2323 | const ms_from_ns = math.cast(windows.DWORD, big_ms_from_ns) catch math.maxInt(windows.DWORD); |
| 2319 | 2324 | |
| 2320 | const ms = math.add(ms_from_s, ms_from_ns) catch math.maxInt(windows.DWORD); | |
| 2325 | const ms = math.add(windows.DWORD, ms_from_s, ms_from_ns) catch math.maxInt(windows.DWORD); | |
| 2321 | 2326 | windows.kernel32.Sleep(ms); |
| 2322 | 2327 | return; |
| 2323 | 2328 | } |
std/os/bits/wasi.zig-6| ... | ... | @@ -1,5 +1,3 @@ |
| 1 | use @import("../bits.zig"); | |
| 2 | ||
| 3 | 1 | pub const STDIN_FILENO = 0; |
| 4 | 2 | pub const STDOUT_FILENO = 1; |
| 5 | 3 | pub const STDERR_FILENO = 2; |
| ... | ... | @@ -12,8 +10,6 @@ pub const ADVICE_WILLNEED: advice_t = 3; |
| 12 | 10 | pub const ADVICE_DONTNEED: advice_t = 4; |
| 13 | 11 | pub const ADVICE_NOREUSE: advice_t = 5; |
| 14 | 12 | |
| 15 | pub const ciovec_t = iovec_const; | |
| 16 | ||
| 17 | 13 | pub const clockid_t = u32; |
| 18 | 14 | pub const CLOCK_REALTIME: clockid_t = 0; |
| 19 | 15 | pub const CLOCK_MONOTONIC: clockid_t = 1; |
| ... | ... | @@ -182,8 +178,6 @@ pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008; |
| 182 | 178 | |
| 183 | 179 | pub const inode_t = u64; |
| 184 | 180 | |
| 185 | pub const iovec_t = iovec; | |
| 186 | ||
| 187 | 181 | pub const linkcount_t = u32; |
| 188 | 182 | |
| 189 | 183 | pub const lookupflags_t = u32; |
std/os/bits/windows.zig+8| ... | ... | @@ -5,6 +5,13 @@ use @import("../windows/bits.zig"); |
| 5 | 5 | pub const fd_t = HANDLE; |
| 6 | 6 | pub const pid_t = HANDLE; |
| 7 | 7 | |
| 8 | pub const time_t = c_longlong; | |
| 9 | ||
| 10 | pub const timespec = extern struct { | |
| 11 | tv_sec: time_t, | |
| 12 | tv_nsec: c_long, | |
| 13 | }; | |
| 14 | ||
| 8 | 15 | pub const sig_atomic_t = c_int; |
| 9 | 16 | |
| 10 | 17 | /// maximum signal number + 1 |
| ... | ... | @@ -153,3 +160,4 @@ pub const EWOULDBLOCK = 140; |
| 153 | 160 | pub const SIGKILL = @compileError("Windows libc does not have this"); |
| 154 | 161 | pub const EDQUOT = @compileError("Windows libc does not have this"); |
| 155 | 162 | pub const TIOCGWINSZ = @compileError("Windows libc does not have this"); |
| 163 | pub const F_OK = 0; |
std/os/epoch.zig deleted-26| ... | ... | @@ -1,26 +0,0 @@ |
| 1 | /// Epoch reference times in terms of their difference from | |
| 2 | /// posix epoch in seconds. | |
| 3 | pub const posix = 0; //Jan 01, 1970 AD | |
| 4 | pub const dos = 315532800; //Jan 01, 1980 AD | |
| 5 | pub const ios = 978307200; //Jan 01, 2001 AD | |
| 6 | pub const openvms = -3506716800; //Nov 17, 1858 AD | |
| 7 | pub const zos = -2208988800; //Jan 01, 1900 AD | |
| 8 | pub const windows = -11644473600; //Jan 01, 1601 AD | |
| 9 | pub const amiga = 252460800; //Jan 01, 1978 AD | |
| 10 | pub const pickos = -63244800; //Dec 31, 1967 AD | |
| 11 | pub const gps = 315964800; //Jan 06, 1980 AD | |
| 12 | pub const clr = -62135769600; //Jan 01, 0001 AD | |
| 13 | ||
| 14 | pub const unix = posix; | |
| 15 | pub const android = posix; | |
| 16 | pub const os2 = dos; | |
| 17 | pub const bios = dos; | |
| 18 | pub const vfat = dos; | |
| 19 | pub const ntfs = windows; | |
| 20 | pub const ntp = zos; | |
| 21 | pub const jbase = pickos; | |
| 22 | pub const aros = amiga; | |
| 23 | pub const morphos = amiga; | |
| 24 | pub const brew = gps; | |
| 25 | pub const atsc = gps; | |
| 26 | pub const go = clr; |
std/os/wasi.zig+4-1| ... | ... | @@ -5,7 +5,7 @@ const std = @import("std"); |
| 5 | 5 | const assert = std.debug.assert; |
| 6 | 6 | |
| 7 | 7 | pub const is_the_target = builtin.os == .wasi; |
| 8 | pub use @import("bits/wasi.zig"); | |
| 8 | pub use @import("bits.zig"); | |
| 9 | 9 | |
| 10 | 10 | comptime { |
| 11 | 11 | assert(@alignOf(i8) == 1); |
| ... | ... | @@ -18,6 +18,9 @@ comptime { |
| 18 | 18 | assert(@alignOf(u64) == 8); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | pub const iovec_t = iovec; | |
| 22 | pub const ciovec_t = iovec_const; | |
| 23 | ||
| 21 | 24 | pub extern "wasi_unstable" fn args_get(argv: [*][*]u8, argv_buf: [*]u8) errno_t; |
| 22 | 25 | pub extern "wasi_unstable" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t; |
| 23 | 26 |
std/os/windows.zig+15-4| ... | ... | @@ -134,6 +134,9 @@ pub fn WaitForSingleObject(handle: HANDLE, milliseconds: DWORD) WaitForSingleObj |
| 134 | 134 | |
| 135 | 135 | pub const FindFirstFileError = error{ |
| 136 | 136 | FileNotFound, |
| 137 | InvalidUtf8, | |
| 138 | BadPathName, | |
| 139 | NameTooLong, | |
| 137 | 140 | Unexpected, |
| 138 | 141 | }; |
| 139 | 142 | |
| ... | ... | @@ -192,7 +195,7 @@ pub fn PostQueuedCompletionStatus( |
| 192 | 195 | ) PostQueuedCompletionStatusError!void { |
| 193 | 196 | if (kernel32.PostQueuedCompletionStatus(completion_port, bytes_transferred_count, completion_key, lpOverlapped) == 0) { |
| 194 | 197 | switch (kernel32.GetLastError()) { |
| 195 | else => return unexpectedError(err), | |
| 198 | else => |err| return unexpectedError(err), | |
| 196 | 199 | } |
| 197 | 200 | } |
| 198 | 201 | } |
| ... | ... | @@ -350,7 +353,7 @@ pub fn DeleteFile(filename: []const u8) DeleteFileError!void { |
| 350 | 353 | } |
| 351 | 354 | |
| 352 | 355 | pub fn DeleteFileW(filename: [*]const u16) DeleteFileError!void { |
| 353 | if (kernel32.DeleteFileW(file_path) == 0) { | |
| 356 | if (kernel32.DeleteFileW(filename) == 0) { | |
| 354 | 357 | switch (kernel32.GetLastError()) { |
| 355 | 358 | ERROR.FILE_NOT_FOUND => return error.FileNotFound, |
| 356 | 359 | ERROR.ACCESS_DENIED => return error.AccessDenied, |
| ... | ... | @@ -501,7 +504,7 @@ pub fn GetFinalPathNameByHandleW( |
| 501 | 504 | buf_len: DWORD, |
| 502 | 505 | flags: DWORD, |
| 503 | 506 | ) GetFinalPathNameByHandleError!DWORD { |
| 504 | const rc = kernel32.GetFinalPathNameByHandleW(h_file, buf_ptr, buf.len, flags); | |
| 507 | const rc = kernel32.GetFinalPathNameByHandleW(hFile, buf_ptr, buf_len, flags); | |
| 505 | 508 | if (rc == 0) { |
| 506 | 509 | switch (kernel32.GetLastError()) { |
| 507 | 510 | ERROR.FILE_NOT_FOUND => return error.FileNotFound, |
| ... | ... | @@ -539,7 +542,7 @@ pub fn GetFileAttributes(filename: []const u8) GetFileAttributesError!DWORD { |
| 539 | 542 | } |
| 540 | 543 | |
| 541 | 544 | pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD { |
| 542 | const rc = kernel32.GetFileAttributesW(path); | |
| 545 | const rc = kernel32.GetFileAttributesW(lpFileName); | |
| 543 | 546 | if (rc == INVALID_FILE_ATTRIBUTES) { |
| 544 | 547 | switch (kernel32.GetLastError()) { |
| 545 | 548 | ERROR.FILE_NOT_FOUND => return error.FileNotFound, |
| ... | ... | @@ -705,6 +708,14 @@ pub fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter |
| 705 | 708 | assert(kernel32.InitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context) != 0); |
| 706 | 709 | } |
| 707 | 710 | |
| 711 | pub fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void) void { | |
| 712 | assert(kernel32.HeapFree(hHeap, dwFlags, lpMem) != 0); | |
| 713 | } | |
| 714 | ||
| 715 | pub fn HeapDestroy(hHeap: HANDLE) void { | |
| 716 | assert(kernel32.HeapDestroy(hHeap) != 0); | |
| 717 | } | |
| 718 | ||
| 708 | 719 | pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 { |
| 709 | 720 | return sliceToPrefixedFileW(mem.toSliceConst(u8, s)); |
| 710 | 721 | } |
std/thread.zig+11-11| ... | ... | @@ -57,7 +57,7 @@ pub const Thread = struct { |
| 57 | 57 | } else |
| 58 | 58 | return switch (builtin.os) { |
| 59 | 59 | .linux => os.linux.gettid(), |
| 60 | .windows => windows.GetCurrentThreadId(), | |
| 60 | .windows => windows.kernel32.GetCurrentThreadId(), | |
| 61 | 61 | else => @compileError("Unsupported OS"), |
| 62 | 62 | }; |
| 63 | 63 | } |
| ... | ... | @@ -99,9 +99,9 @@ pub const Thread = struct { |
| 99 | 99 | os.munmap(self.data.memory); |
| 100 | 100 | }, |
| 101 | 101 | .windows => { |
| 102 | assert(windows.WaitForSingleObject(self.data.handle, windows.INFINITE) == windows.WAIT_OBJECT_0); | |
| 103 | assert(windows.CloseHandle(self.data.handle) != 0); | |
| 104 | assert(windows.HeapFree(self.data.heap_handle, 0, self.data.alloc_start) != 0); | |
| 102 | windows.WaitForSingleObject(self.data.handle, windows.INFINITE) catch unreachable; | |
| 103 | windows.CloseHandle(self.data.handle); | |
| 104 | windows.HeapFree(self.data.heap_handle, 0, self.data.alloc_start); | |
| 105 | 105 | }, |
| 106 | 106 | else => @compileError("Unsupported OS"), |
| 107 | 107 | } |
| ... | ... | @@ -171,10 +171,10 @@ pub const Thread = struct { |
| 171 | 171 | } |
| 172 | 172 | }; |
| 173 | 173 | |
| 174 | const heap_handle = windows.GetProcessHeap() orelse return error.OutOfMemory; | |
| 174 | const heap_handle = windows.kernel32.GetProcessHeap() orelse return error.OutOfMemory; | |
| 175 | 175 | const byte_count = @alignOf(WinThread.OuterContext) + @sizeOf(WinThread.OuterContext); |
| 176 | const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) orelse return error.OutOfMemory; | |
| 177 | errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0); | |
| 176 | const bytes_ptr = windows.kernel32.HeapAlloc(heap_handle, 0, byte_count) orelse return error.OutOfMemory; | |
| 177 | errdefer assert(windows.kernel32.HeapFree(heap_handle, 0, bytes_ptr) != 0); | |
| 178 | 178 | const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count]; |
| 179 | 179 | const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable; |
| 180 | 180 | outer_context.* = WinThread.OuterContext{ |
| ... | ... | @@ -189,9 +189,9 @@ pub const Thread = struct { |
| 189 | 189 | }; |
| 190 | 190 | |
| 191 | 191 | const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner); |
| 192 | outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse { | |
| 193 | switch (windows.GetLastError()) { | |
| 194 | else => |err| windows.unexpectedError(err), | |
| 192 | outer_context.thread.data.handle = windows.kernel32.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse { | |
| 193 | switch (windows.kernel32.GetLastError()) { | |
| 194 | else => |err| return windows.unexpectedError(err), | |
| 195 | 195 | } |
| 196 | 196 | }; |
| 197 | 197 | return &outer_context.thread; |
| ... | ... | @@ -333,7 +333,7 @@ pub const Thread = struct { |
| 333 | 333 | } |
| 334 | 334 | if (os.windows.is_the_target) { |
| 335 | 335 | var system_info: windows.SYSTEM_INFO = undefined; |
| 336 | windows.GetSystemInfo(&system_info); | |
| 336 | windows.kernel32.GetSystemInfo(&system_info); | |
| 337 | 337 | return @intCast(usize, system_info.dwNumberOfProcessors); |
| 338 | 338 | } |
| 339 | 339 | var count: c_int = undefined; |
std/time.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ const assert = std.debug.assert; |
| 4 | 4 | const testing = std.testing; |
| 5 | 5 | const os = std.os; |
| 6 | 6 | |
| 7 | pub const epoch = @import("epoch.zig"); | |
| 7 | pub const epoch = @import("time/epoch.zig"); | |
| 8 | 8 | |
| 9 | 9 | /// Spurious wakeups are possible and no precision of timing is guaranteed. |
| 10 | 10 | pub fn sleep(nanoseconds: u64) void { |
std/time/epoch.zig created+26| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | /// Epoch reference times in terms of their difference from | |
| 2 | /// posix epoch in seconds. | |
| 3 | pub const posix = 0; //Jan 01, 1970 AD | |
| 4 | pub const dos = 315532800; //Jan 01, 1980 AD | |
| 5 | pub const ios = 978307200; //Jan 01, 2001 AD | |
| 6 | pub const openvms = -3506716800; //Nov 17, 1858 AD | |
| 7 | pub const zos = -2208988800; //Jan 01, 1900 AD | |
| 8 | pub const windows = -11644473600; //Jan 01, 1601 AD | |
| 9 | pub const amiga = 252460800; //Jan 01, 1978 AD | |
| 10 | pub const pickos = -63244800; //Dec 31, 1967 AD | |
| 11 | pub const gps = 315964800; //Jan 06, 1980 AD | |
| 12 | pub const clr = -62135769600; //Jan 01, 0001 AD | |
| 13 | ||
| 14 | pub const unix = posix; | |
| 15 | pub const android = posix; | |
| 16 | pub const os2 = dos; | |
| 17 | pub const bios = dos; | |
| 18 | pub const vfat = dos; | |
| 19 | pub const ntfs = windows; | |
| 20 | pub const ntp = zos; | |
| 21 | pub const jbase = pickos; | |
| 22 | pub const aros = amiga; | |
| 23 | pub const morphos = amiga; | |
| 24 | pub const brew = gps; | |
| 25 | pub const atsc = gps; | |
| 26 | pub const go = clr; |