authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 01:35:58-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 01:35:58-04:00
log129714d077ca6f3f6d09300b1fa2171915f7c839
treee71844723e23dc5dc991d6cb40dd56693caffa88
parent6be79d79aab204718116428c9b23be7de54e14da
signaturelock-open Commit is signed but in an unrecognized format.

more fixes for windows and wasi


13 files changed, 118 insertions(+), 97 deletions(-)

CMakeLists.txt+1-1
......@@ -616,7 +616,6 @@ set(ZIG_STD_FILES
616616 "os/bits/wasi.zig"
617617 "os/bits/windows.zig"
618618 "os/darwin.zig"
619 "os/epoch.zig"
620619 "os/freebsd.zig"
621620 "os/linux.zig"
622621 "os/linux/arm64.zig"
......@@ -723,6 +722,7 @@ set(ZIG_STD_FILES
723722 "testing.zig"
724723 "thread.zig"
725724 "time.zig"
725 "time/epoch.zig"
726726 "unicode.zig"
727727 "valgrind.zig"
728728 "valgrind/callgrind.zig"
std/event/loop.zig+36-36
......@@ -32,7 +32,7 @@ pub const Loop = struct {
3232 overlapped: Overlapped,
3333
3434 pub const overlapped_init = switch (builtin.os) {
35 builtin.Os.windows => windows.OVERLAPPED{
35 .windows => windows.OVERLAPPED{
3636 .Internal = 0,
3737 .InternalHigh = 0,
3838 .Offset = 0,
......@@ -50,13 +50,13 @@ pub const Loop = struct {
5050 };
5151
5252 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 {
5555 base: ResumeNode,
5656 epoll_op: u32,
5757 eventfd: i32,
5858 },
59 builtin.Os.windows => struct {
59 .windows => struct {
6060 base: ResumeNode,
6161 completion_key: usize,
6262 },
......@@ -69,11 +69,11 @@ pub const Loop = struct {
6969 };
7070
7171 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 {
7474 base: ResumeNode,
7575 },
76 builtin.Os.windows => struct {
76 .windows => struct {
7777 base: ResumeNode,
7878 },
7979 else => @compileError("unsupported OS"),
......@@ -147,7 +147,7 @@ pub const Loop = struct {
147147
148148 fn initOsData(self: *Loop, extra_thread_count: usize) InitOsDataError!void {
149149 switch (builtin.os) {
150 builtin.Os.linux => {
150 .linux => {
151151 self.os_data.fs_queue = std.atomic.Queue(fs.Request).init();
152152 self.os_data.fs_queue_item = 0;
153153 // we need another thread for the file system because Linux does not have an async
......@@ -221,7 +221,7 @@ pub const Loop = struct {
221221 self.extra_threads[extra_thread_index] = try Thread.spawn(self, workerRun);
222222 }
223223 },
224 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
224 .macosx, .freebsd, .netbsd => {
225225 self.os_data.kqfd = try os.bsdKQueue();
226226 errdefer os.close(self.os_data.kqfd);
227227
......@@ -325,14 +325,14 @@ pub const Loop = struct {
325325 self.extra_threads[extra_thread_index] = try Thread.spawn(self, workerRun);
326326 }
327327 },
328 builtin.Os.windows => {
329 self.os_data.io_port = try os.windowsCreateIoCompletionPort(
328 .windows => {
329 self.os_data.io_port = try windows.CreateIoCompletionPort(
330330 windows.INVALID_HANDLE_VALUE,
331331 null,
332332 undefined,
333333 maxInt(windows.DWORD),
334334 );
335 errdefer os.close(self.os_data.io_port);
335 errdefer windows.CloseHandle(self.os_data.io_port);
336336
337337 for (self.eventfd_resume_nodes) |*eventfd_node, i| {
338338 eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{
......@@ -361,7 +361,7 @@ pub const Loop = struct {
361361 while (i < extra_thread_index) : (i += 1) {
362362 while (true) {
363363 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;
365365 break;
366366 }
367367 }
......@@ -380,18 +380,18 @@ pub const Loop = struct {
380380
381381 fn deinitOsData(self: *Loop) void {
382382 switch (builtin.os) {
383 builtin.Os.linux => {
383 .linux => {
384384 os.close(self.os_data.final_eventfd);
385385 while (self.available_eventfd_resume_nodes.pop()) |node| os.close(node.data.eventfd);
386386 os.close(self.os_data.epollfd);
387387 self.allocator.free(self.eventfd_resume_nodes);
388388 },
389 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
389 .macosx, .freebsd, .netbsd => {
390390 os.close(self.os_data.kqfd);
391391 os.close(self.os_data.fs_kqfd);
392392 },
393 builtin.Os.windows => {
394 os.close(self.os_data.io_port);
393 .windows => {
394 windows.CloseHandle(self.os_data.io_port);
395395 },
396396 else => {},
397397 }
......@@ -501,7 +501,7 @@ pub const Loop = struct {
501501 const eventfd_node = &resume_stack_node.data;
502502 eventfd_node.base.handle = next_tick_node.data;
503503 switch (builtin.os) {
504 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
504 .macosx, .freebsd, .netbsd => {
505505 const kevent_array = (*const [1]os.Kevent)(&eventfd_node.kevent);
506506 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
507507 _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {
......@@ -510,7 +510,7 @@ pub const Loop = struct {
510510 return;
511511 };
512512 },
513 builtin.Os.linux => {
513 .linux => {
514514 // the pending count is already accounted for
515515 const epoll_events = os.EPOLLONESHOT | os.linux.EPOLLIN | os.linux.EPOLLOUT |
516516 os.linux.EPOLLET;
......@@ -525,8 +525,8 @@ pub const Loop = struct {
525525 return;
526526 };
527527 },
528 builtin.Os.windows => {
529 os.windowsPostQueuedCompletionStatus(
528 .windows => {
529 windows.PostQueuedCompletionStatus(
530530 self.os_data.io_port,
531531 undefined,
532532 undefined,
......@@ -623,13 +623,13 @@ pub const Loop = struct {
623623 if (prev == 1) {
624624 // cause all the threads to stop
625625 switch (builtin.os) {
626 builtin.Os.linux => {
626 .linux => {
627627 self.posixFsRequest(&self.os_data.fs_end_request);
628628 // writing 8 bytes to an eventfd cannot fail
629629 os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
630630 return;
631631 },
632 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
632 .macosx, .freebsd, .netbsd => {
633633 self.posixFsRequest(&self.os_data.fs_end_request);
634634 const final_kevent = (*const [1]os.Kevent)(&self.os_data.final_kevent);
635635 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
......@@ -637,12 +637,12 @@ pub const Loop = struct {
637637 _ = os.bsdKEvent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable;
638638 return;
639639 },
640 builtin.Os.windows => {
640 .windows => {
641641 var i: usize = 0;
642642 while (i < self.extra_threads.len + 1) : (i += 1) {
643643 while (true) {
644644 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;
646646 break;
647647 }
648648 }
......@@ -663,7 +663,7 @@ pub const Loop = struct {
663663 }
664664
665665 switch (builtin.os) {
666 builtin.Os.linux => {
666 .linux => {
667667 // only process 1 event so we don't steal from other threads
668668 var events: [1]os.linux.epoll_event = undefined;
669669 const count = os.epoll_wait(self.os_data.epollfd, events[0..], -1);
......@@ -687,7 +687,7 @@ pub const Loop = struct {
687687 }
688688 }
689689 },
690 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
690 .macosx, .freebsd, .netbsd => {
691691 var eventlist: [1]os.Kevent = undefined;
692692 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
693693 const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
......@@ -713,16 +713,16 @@ pub const Loop = struct {
713713 }
714714 }
715715 },
716 builtin.Os.windows => {
716 .windows => {
717717 var completion_key: usize = undefined;
718718 const overlapped = while (true) {
719719 var nbytes: windows.DWORD = undefined;
720720 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,
726726 }
727727 if (overlapped) |o| break o;
728728 } else unreachable; // TODO else unreachable should not be necessary
......@@ -831,9 +831,9 @@ pub const Loop = struct {
831831 }
832832
833833 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 {
837837 io_port: windows.HANDLE,
838838 extra_thread_count: usize,
839839 },
std/fs/get_app_data_dir.zig+1-1
......@@ -23,7 +23,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
2323 &dir_path_ptr,
2424 )) {
2525 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));
2727 const global_dir = unicode.utf16leToUtf8Alloc(allocator, utf16lePtrSlice(dir_path_ptr)) catch |err| switch (err) {
2828 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
2929 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
std/heap.zig+6-6
......@@ -261,7 +261,7 @@ pub const HeapAllocator = switch (builtin.os) {
261261
262262 pub fn deinit(self: *HeapAllocator) void {
263263 if (self.heap_handle) |heap_handle| {
264 _ = os.windows.HeapDestroy(heap_handle);
264 os.windows.HeapDestroy(heap_handle);
265265 }
266266 }
267267
......@@ -274,12 +274,12 @@ pub const HeapAllocator = switch (builtin.os) {
274274 const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, builtin.AtomicOrder.SeqCst);
275275 const heap_handle = optional_heap_handle orelse blk: {
276276 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;
278278 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);
280280 break :blk other_hh.?; // can't be null because of the cmpxchg
281281 };
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;
283283 const root_addr = @ptrToInt(ptr);
284284 const adjusted_addr = mem.alignForward(root_addr, alignment);
285285 const record_addr = adjusted_addr + n;
......@@ -309,12 +309,12 @@ pub const HeapAllocator = switch (builtin.os) {
309309 const old_ptr = @intToPtr(*c_void, root_addr);
310310
311311 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);
313313 return old_mem[0..0];
314314 }
315315
316316 const amt = new_size + new_align + @sizeOf(usize);
317 const new_ptr = os.windows.HeapReAlloc(
317 const new_ptr = os.windows.kernel32.HeapReAlloc(
318318 self.heap_handle.?,
319319 0,
320320 old_ptr,
std/os.zig+9-4
......@@ -944,7 +944,7 @@ pub fn renameC(old_path: [*]const u8, new_path: [*]const u8) RenameError!void {
944944/// Assumes target is Windows.
945945pub fn renameW(old_path: [*]const u16, new_path: [*]const u16) RenameError!void {
946946 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);
948948}
949949
950950pub const MakeDirError = error{
......@@ -959,6 +959,8 @@ pub const MakeDirError = error{
959959 NoSpaceLeft,
960960 NotDir,
961961 ReadOnlyFileSystem,
962 InvalidUtf8,
963 BadPathName,
962964 Unexpected,
963965};
964966
......@@ -2227,6 +2229,9 @@ pub const RealPathError = error{
22272229 BadPathName,
22282230 DeviceBusy,
22292231
2232 SharingViolation,
2233 PipeBusy,
2234
22302235 /// On Windows, file paths must be valid Unicode.
22312236 InvalidUtf8,
22322237
......@@ -2294,7 +2299,7 @@ pub fn realpathW(pathname: [*]const u16, out_buffer: *[MAX_PATH_BYTES]u8) RealPa
22942299 var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined;
22952300 const wide_len = try windows.GetFinalPathNameByHandleW(h_file, &wide_buf, wide_buf.len, windows.VOLUME_NAME_DOS);
22962301 assert(wide_len <= wide_buf.len);
2297 const wide_slice = wide_len[0..wide_len];
2302 const wide_slice = wide_buf[0..wide_len];
22982303
22992304 // Windows returns \\?\ prepended to the path.
23002305 // We strip it to make this function consistent across platforms.
......@@ -2311,13 +2316,13 @@ pub fn nanosleep(seconds: u64, nanoseconds: u64) void {
23112316 if (windows.is_the_target and !builtin.link_libc) {
23122317 // TODO https://github.com/ziglang/zig/issues/1284
23132318 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);
23152320
23162321 const ns_per_ms = std.time.ns_per_s / std.time.ms_per_s;
23172322 const big_ms_from_ns = nanoseconds / ns_per_ms;
23182323 const ms_from_ns = math.cast(windows.DWORD, big_ms_from_ns) catch math.maxInt(windows.DWORD);
23192324
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);
23212326 windows.kernel32.Sleep(ms);
23222327 return;
23232328 }
std/os/bits/wasi.zig-6
......@@ -1,5 +1,3 @@
1use @import("../bits.zig");
2
31pub const STDIN_FILENO = 0;
42pub const STDOUT_FILENO = 1;
53pub const STDERR_FILENO = 2;
......@@ -12,8 +10,6 @@ pub const ADVICE_WILLNEED: advice_t = 3;
1210pub const ADVICE_DONTNEED: advice_t = 4;
1311pub const ADVICE_NOREUSE: advice_t = 5;
1412
15pub const ciovec_t = iovec_const;
16
1713pub const clockid_t = u32;
1814pub const CLOCK_REALTIME: clockid_t = 0;
1915pub const CLOCK_MONOTONIC: clockid_t = 1;
......@@ -182,8 +178,6 @@ pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
182178
183179pub const inode_t = u64;
184180
185pub const iovec_t = iovec;
186
187181pub const linkcount_t = u32;
188182
189183pub const lookupflags_t = u32;
std/os/bits/windows.zig+8
......@@ -5,6 +5,13 @@ use @import("../windows/bits.zig");
55pub const fd_t = HANDLE;
66pub const pid_t = HANDLE;
77
8pub const time_t = c_longlong;
9
10pub const timespec = extern struct {
11 tv_sec: time_t,
12 tv_nsec: c_long,
13};
14
815pub const sig_atomic_t = c_int;
916
1017/// maximum signal number + 1
......@@ -153,3 +160,4 @@ pub const EWOULDBLOCK = 140;
153160pub const SIGKILL = @compileError("Windows libc does not have this");
154161pub const EDQUOT = @compileError("Windows libc does not have this");
155162pub const TIOCGWINSZ = @compileError("Windows libc does not have this");
163pub 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.
3pub const posix = 0; //Jan 01, 1970 AD
4pub const dos = 315532800; //Jan 01, 1980 AD
5pub const ios = 978307200; //Jan 01, 2001 AD
6pub const openvms = -3506716800; //Nov 17, 1858 AD
7pub const zos = -2208988800; //Jan 01, 1900 AD
8pub const windows = -11644473600; //Jan 01, 1601 AD
9pub const amiga = 252460800; //Jan 01, 1978 AD
10pub const pickos = -63244800; //Dec 31, 1967 AD
11pub const gps = 315964800; //Jan 06, 1980 AD
12pub const clr = -62135769600; //Jan 01, 0001 AD
13
14pub const unix = posix;
15pub const android = posix;
16pub const os2 = dos;
17pub const bios = dos;
18pub const vfat = dos;
19pub const ntfs = windows;
20pub const ntp = zos;
21pub const jbase = pickos;
22pub const aros = amiga;
23pub const morphos = amiga;
24pub const brew = gps;
25pub const atsc = gps;
26pub const go = clr;
std/os/wasi.zig+4-1
......@@ -5,7 +5,7 @@ const std = @import("std");
55const assert = std.debug.assert;
66
77pub const is_the_target = builtin.os == .wasi;
8pub use @import("bits/wasi.zig");
8pub use @import("bits.zig");
99
1010comptime {
1111 assert(@alignOf(i8) == 1);
......@@ -18,6 +18,9 @@ comptime {
1818 assert(@alignOf(u64) == 8);
1919}
2020
21pub const iovec_t = iovec;
22pub const ciovec_t = iovec_const;
23
2124pub extern "wasi_unstable" fn args_get(argv: [*][*]u8, argv_buf: [*]u8) errno_t;
2225pub extern "wasi_unstable" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t;
2326
std/os/windows.zig+15-4
......@@ -134,6 +134,9 @@ pub fn WaitForSingleObject(handle: HANDLE, milliseconds: DWORD) WaitForSingleObj
134134
135135pub const FindFirstFileError = error{
136136 FileNotFound,
137 InvalidUtf8,
138 BadPathName,
139 NameTooLong,
137140 Unexpected,
138141};
139142
......@@ -192,7 +195,7 @@ pub fn PostQueuedCompletionStatus(
192195) PostQueuedCompletionStatusError!void {
193196 if (kernel32.PostQueuedCompletionStatus(completion_port, bytes_transferred_count, completion_key, lpOverlapped) == 0) {
194197 switch (kernel32.GetLastError()) {
195 else => return unexpectedError(err),
198 else => |err| return unexpectedError(err),
196199 }
197200 }
198201}
......@@ -350,7 +353,7 @@ pub fn DeleteFile(filename: []const u8) DeleteFileError!void {
350353}
351354
352355pub fn DeleteFileW(filename: [*]const u16) DeleteFileError!void {
353 if (kernel32.DeleteFileW(file_path) == 0) {
356 if (kernel32.DeleteFileW(filename) == 0) {
354357 switch (kernel32.GetLastError()) {
355358 ERROR.FILE_NOT_FOUND => return error.FileNotFound,
356359 ERROR.ACCESS_DENIED => return error.AccessDenied,
......@@ -501,7 +504,7 @@ pub fn GetFinalPathNameByHandleW(
501504 buf_len: DWORD,
502505 flags: DWORD,
503506) 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);
505508 if (rc == 0) {
506509 switch (kernel32.GetLastError()) {
507510 ERROR.FILE_NOT_FOUND => return error.FileNotFound,
......@@ -539,7 +542,7 @@ pub fn GetFileAttributes(filename: []const u8) GetFileAttributesError!DWORD {
539542}
540543
541544pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD {
542 const rc = kernel32.GetFileAttributesW(path);
545 const rc = kernel32.GetFileAttributesW(lpFileName);
543546 if (rc == INVALID_FILE_ATTRIBUTES) {
544547 switch (kernel32.GetLastError()) {
545548 ERROR.FILE_NOT_FOUND => return error.FileNotFound,
......@@ -705,6 +708,14 @@ pub fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter
705708 assert(kernel32.InitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context) != 0);
706709}
707710
711pub fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void) void {
712 assert(kernel32.HeapFree(hHeap, dwFlags, lpMem) != 0);
713}
714
715pub fn HeapDestroy(hHeap: HANDLE) void {
716 assert(kernel32.HeapDestroy(hHeap) != 0);
717}
718
708719pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {
709720 return sliceToPrefixedFileW(mem.toSliceConst(u8, s));
710721}
std/thread.zig+11-11
......@@ -57,7 +57,7 @@ pub const Thread = struct {
5757 } else
5858 return switch (builtin.os) {
5959 .linux => os.linux.gettid(),
60 .windows => windows.GetCurrentThreadId(),
60 .windows => windows.kernel32.GetCurrentThreadId(),
6161 else => @compileError("Unsupported OS"),
6262 };
6363 }
......@@ -99,9 +99,9 @@ pub const Thread = struct {
9999 os.munmap(self.data.memory);
100100 },
101101 .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);
105105 },
106106 else => @compileError("Unsupported OS"),
107107 }
......@@ -171,10 +171,10 @@ pub const Thread = struct {
171171 }
172172 };
173173
174 const heap_handle = windows.GetProcessHeap() orelse return error.OutOfMemory;
174 const heap_handle = windows.kernel32.GetProcessHeap() orelse return error.OutOfMemory;
175175 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);
178178 const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];
179179 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable;
180180 outer_context.* = WinThread.OuterContext{
......@@ -189,9 +189,9 @@ pub const Thread = struct {
189189 };
190190
191191 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),
195195 }
196196 };
197197 return &outer_context.thread;
......@@ -333,7 +333,7 @@ pub const Thread = struct {
333333 }
334334 if (os.windows.is_the_target) {
335335 var system_info: windows.SYSTEM_INFO = undefined;
336 windows.GetSystemInfo(&system_info);
336 windows.kernel32.GetSystemInfo(&system_info);
337337 return @intCast(usize, system_info.dwNumberOfProcessors);
338338 }
339339 var count: c_int = undefined;
std/time.zig+1-1
......@@ -4,7 +4,7 @@ const assert = std.debug.assert;
44const testing = std.testing;
55const os = std.os;
66
7pub const epoch = @import("epoch.zig");
7pub const epoch = @import("time/epoch.zig");
88
99/// Spurious wakeups are possible and no precision of timing is guaranteed.
1010pub 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.
3pub const posix = 0; //Jan 01, 1970 AD
4pub const dos = 315532800; //Jan 01, 1980 AD
5pub const ios = 978307200; //Jan 01, 2001 AD
6pub const openvms = -3506716800; //Nov 17, 1858 AD
7pub const zos = -2208988800; //Jan 01, 1900 AD
8pub const windows = -11644473600; //Jan 01, 1601 AD
9pub const amiga = 252460800; //Jan 01, 1978 AD
10pub const pickos = -63244800; //Dec 31, 1967 AD
11pub const gps = 315964800; //Jan 06, 1980 AD
12pub const clr = -62135769600; //Jan 01, 0001 AD
13
14pub const unix = posix;
15pub const android = posix;
16pub const os2 = dos;
17pub const bios = dos;
18pub const vfat = dos;
19pub const ntfs = windows;
20pub const ntp = zos;
21pub const jbase = pickos;
22pub const aros = amiga;
23pub const morphos = amiga;
24pub const brew = gps;
25pub const atsc = gps;
26pub const go = clr;