authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-03-18 23:18:35-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-03-20 02:25:16+01:00
log3c8b96df6d146e6ae820f58ec993510d1eedf2c0
tree17a3c1e211b3f6384f4ceec0a60684cf588fd0b9
parent30de1678a624bb90a8664a10f8c15a81382f749e

windows: use enums for boolean types


9 files changed, 85 insertions(+), 92 deletions(-)

lib/std/Build/Watch.zig+2-2
...@@ -345,7 +345,7 @@ const Os = switch (builtin.os.tag) {...@@ -345,7 +345,7 @@ const Os = switch (builtin.os.tag) {
345 .LAST_WRITE = true,345 .LAST_WRITE = true,
346 .CREATION = true,346 .CREATION = true,
347 },347 },
348 windows.FALSE,348 .FALSE,
349 .Notify,349 .Notify,
350 )) {350 )) {
351 .SUCCESS, .PENDING => dir.state = .listening,351 .SUCCESS, .PENDING => dir.state = .listening,
...@@ -632,7 +632,7 @@ const Os = switch (builtin.os.tag) {...@@ -632,7 +632,7 @@ const Os = switch (builtin.os.tag) {
632 .none => std.math.minInt(windows.LARGE_INTEGER),632 .none => std.math.minInt(windows.LARGE_INTEGER),
633 .ms => |ms| -@as(windows.LARGE_INTEGER, ms) * (std.time.ns_per_ms / 100),633 .ms => |ms| -@as(windows.LARGE_INTEGER, ms) * (std.time.ns_per_ms / 100),
634 };634 };
635 _ = windows.ntdll.NtDelayExecution(windows.TRUE, &delay_interval);635 _ = windows.ntdll.NtDelayExecution(.TRUE, &delay_interval);
636 } else unreachable;636 } else unreachable;
637 }637 }
638 },638 },
lib/std/Io/Threaded.zig+35-37
...@@ -1572,7 +1572,7 @@ const AlertableSyscall = struct {...@@ -1572,7 +1572,7 @@ const AlertableSyscall = struct {
15721572
1573pub fn waitForApcOrAlert() void {1573pub fn waitForApcOrAlert() void {
1574 const infinite_timeout: windows.LARGE_INTEGER = std.math.minInt(windows.LARGE_INTEGER);1574 const infinite_timeout: windows.LARGE_INTEGER = std.math.minInt(windows.LARGE_INTEGER);
1575 _ = windows.ntdll.NtDelayExecution(windows.TRUE, &infinite_timeout);1575 _ = windows.ntdll.NtDelayExecution(.TRUE, &infinite_timeout);
1576}1576}
15771577
1578pub const max_iovecs_len = 8;1578pub const max_iovecs_len = 8;
...@@ -2735,7 +2735,7 @@ fn batchAwaitConcurrent(userdata: ?*anyopaque, b: *Io.Batch, timeout: Io.Timeout...@@ -2735,7 +2735,7 @@ fn batchAwaitConcurrent(userdata: ?*anyopaque, b: *Io.Batch, timeout: Io.Timeout
2735 break :interval timeoutToWindowsInterval(.{ .deadline = d }).?;2735 break :interval timeoutToWindowsInterval(.{ .deadline = d }).?;
2736 };2736 };
2737 const alertable_syscall = try AlertableSyscall.start();2737 const alertable_syscall = try AlertableSyscall.start();
2738 const delay_rc = windows.ntdll.NtDelayExecution(windows.TRUE, &delay_interval);2738 const delay_rc = windows.ntdll.NtDelayExecution(.TRUE, &delay_interval);
2739 alertable_syscall.finish();2739 alertable_syscall.finish();
2740 switch (delay_rc) {2740 switch (delay_rc) {
2741 .SUCCESS, .TIMEOUT => {2741 .SUCCESS, .TIMEOUT => {
...@@ -4533,8 +4533,8 @@ fn dirCreateFileWindows(...@@ -4533,8 +4533,8 @@ fn dirCreateFileWindows(
4533 &windows_lock_range_off,4533 &windows_lock_range_off,
4534 &windows_lock_range_len,4534 &windows_lock_range_len,
4535 null,4535 null,
4536 @intFromBool(flags.lock_nonblocking),4536 .fromBool(flags.lock_nonblocking),
4537 @intFromBool(exclusive),4537 .fromBool(exclusive),
4538 )) {4538 )) {
4539 .SUCCESS => {4539 .SUCCESS => {
4540 syscall.finish();4540 syscall.finish();
...@@ -5129,8 +5129,8 @@ pub fn dirOpenFileWtf16(...@@ -5129,8 +5129,8 @@ pub fn dirOpenFileWtf16(
5129 &windows_lock_range_off,5129 &windows_lock_range_off,
5130 &windows_lock_range_len,5130 &windows_lock_range_len,
5131 null,5131 null,
5132 @intFromBool(flags.lock_nonblocking),5132 .fromBool(flags.lock_nonblocking),
5133 @intFromBool(exclusive),5133 .fromBool(exclusive),
5134 )) {5134 )) {
5135 .SUCCESS => break syscall.finish(),5135 .SUCCESS => break syscall.finish(),
5136 .INSUFFICIENT_RESOURCES => return syscall.fail(error.SystemResources),5136 .INSUFFICIENT_RESOURCES => return syscall.fail(error.SystemResources),
...@@ -5886,9 +5886,9 @@ fn dirReadWindows(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) D...@@ -5886,9 +5886,9 @@ fn dirReadWindows(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) D
5886 unreserved_buffer.ptr,5886 unreserved_buffer.ptr,
5887 std.math.lossyCast(w.ULONG, unreserved_buffer.len),5887 std.math.lossyCast(w.ULONG, unreserved_buffer.len),
5888 .BothDirectory,5888 .BothDirectory,
5889 w.FALSE,5889 .FALSE,
5890 null,5890 null,
5891 @intFromBool(dr.state == .reset),5891 .fromBool(dr.state == .reset),
5892 )) {5892 )) {
5893 .CANCELLED => {5893 .CANCELLED => {
5894 try syscall.checkCancel();5894 try syscall.checkCancel();
...@@ -7229,9 +7229,7 @@ fn dirDeleteWindows(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, remov...@@ -7229,9 +7229,7 @@ fn dirDeleteWindows(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, remov
72297229
7230 // Deletion with file pending semantics, which requires waiting or moving7230 // Deletion with file pending semantics, which requires waiting or moving
7231 // files to get them removed (from here).7231 // files to get them removed (from here).
7232 var file_dispo: w.FILE.DISPOSITION.INFORMATION = .{7232 var file_dispo: w.FILE.DISPOSITION.INFORMATION = .{ .DeleteFile = .TRUE };
7233 .DeleteFile = w.TRUE,
7234 };
72357233
7236 while (true) switch (w.ntdll.NtSetInformationFile(7234 while (true) switch (w.ntdll.NtSetInformationFile(
7237 tmp_handle,7235 tmp_handle,
...@@ -9188,8 +9186,8 @@ fn fileLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockError!v...@@ -9188,8 +9186,8 @@ fn fileLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockError!v
9188 &windows_lock_range_off,9186 &windows_lock_range_off,
9189 &windows_lock_range_len,9187 &windows_lock_range_len,
9190 null,9188 null,
9191 windows.FALSE,9189 .FALSE,
9192 @intFromBool(exclusive),9190 .fromBool(exclusive),
9193 )) {9191 )) {
9194 .SUCCESS => return syscall.finish(),9192 .SUCCESS => return syscall.finish(),
9195 .CANCELLED => {9193 .CANCELLED => {
...@@ -9269,8 +9267,8 @@ fn fileTryLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockErro...@@ -9269,8 +9267,8 @@ fn fileTryLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockErro
9269 &windows_lock_range_off,9267 &windows_lock_range_off,
9270 &windows_lock_range_len,9268 &windows_lock_range_len,
9271 null,9269 null,
9272 windows.TRUE,9270 .TRUE,
9273 @intFromBool(exclusive),9271 .fromBool(exclusive),
9274 )) {9272 )) {
9275 .SUCCESS => {9273 .SUCCESS => {
9276 syscall.finish();9274 syscall.finish();
...@@ -9382,8 +9380,8 @@ fn fileDowngradeLock(userdata: ?*anyopaque, file: File) File.DowngradeLockError!...@@ -9382,8 +9380,8 @@ fn fileDowngradeLock(userdata: ?*anyopaque, file: File) File.DowngradeLockError!
9382 &windows_lock_range_off,9380 &windows_lock_range_off,
9383 &windows_lock_range_len,9381 &windows_lock_range_len,
9384 null,9382 null,
9385 windows.TRUE,9383 .TRUE,
9386 windows.FALSE,9384 .FALSE,
9387 )) {9385 )) {
9388 .SUCCESS => break syscall.finish(),9386 .SUCCESS => break syscall.finish(),
9389 .CANCELLED => {9387 .CANCELLED => {
...@@ -11469,7 +11467,7 @@ fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Clock.ResolutionEr...@@ -11469,7 +11467,7 @@ fn clockResolution(userdata: ?*anyopaque, clock: Io.Clock) Io.Clock.ResolutionEr
11469 // https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/ns-ntddk-kuser_shared_data11467 // https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/ns-ntddk-kuser_shared_data
11470 // https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntexapi_x/kuser_shared_data/index.htm11468 // https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntexapi_x/kuser_shared_data/index.htm
11471 var qpf: windows.LARGE_INTEGER = undefined;11469 var qpf: windows.LARGE_INTEGER = undefined;
11472 if (windows.ntdll.RtlQueryPerformanceFrequency(&qpf) != 0) {11470 if (windows.ntdll.RtlQueryPerformanceFrequency(&qpf).toBool()) {
11473 recoverableOsBugDetected();11471 recoverableOsBugDetected();
11474 return .zero;11472 return .zero;
11475 }11473 }
...@@ -11523,14 +11521,14 @@ fn nowWindows(clock: Io.Clock) Io.Timestamp {...@@ -11523,14 +11521,14 @@ fn nowWindows(clock: Io.Clock) Io.Timestamp {
11523 // https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntexapi_x/kuser_shared_data/index.htm11521 // https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntexapi_x/kuser_shared_data/index.htm
11524 const qpf: u64 = qpf: {11522 const qpf: u64 = qpf: {
11525 var qpf: windows.LARGE_INTEGER = undefined;11523 var qpf: windows.LARGE_INTEGER = undefined;
11526 assert(windows.ntdll.RtlQueryPerformanceFrequency(&qpf) != windows.FALSE);11524 assert(windows.ntdll.RtlQueryPerformanceFrequency(&qpf).toBool());
11527 break :qpf @bitCast(qpf);11525 break :qpf @bitCast(qpf);
11528 };11526 };
1152911527
11530 // QPC on windows doesn't fail on >= XP/2000 and includes time suspended.11528 // QPC on windows doesn't fail on >= XP/2000 and includes time suspended.
11531 const qpc: u64 = qpc: {11529 const qpc: u64 = qpc: {
11532 var qpc: windows.LARGE_INTEGER = undefined;11530 var qpc: windows.LARGE_INTEGER = undefined;
11533 assert(windows.ntdll.RtlQueryPerformanceCounter(&qpc) != windows.FALSE);11531 assert(windows.ntdll.RtlQueryPerformanceCounter(&qpc).toBool());
11534 break :qpc @bitCast(qpc);11532 break :qpc @bitCast(qpc);
11535 };11533 };
1153611534
...@@ -11745,9 +11743,9 @@ fn netListenIpWindows(...@@ -11745,9 +11743,9 @@ fn netListenIpWindows(
11745 .file = .{ .handle = socket_handle, .flags = .{ .nonblocking = true } },11743 .file = .{ .handle = socket_handle, .flags = .{ .nonblocking = true } },
11746 .code = windows.IOCTL.AFD.START_LISTEN,11744 .code = windows.IOCTL.AFD.START_LISTEN,
11747 .in = @ptrCast(&windows.AFD.LISTEN_INFO{11745 .in = @ptrCast(&windows.AFD.LISTEN_INFO{
11748 .UseSAN = windows.FALSE,11746 .UseSAN = .FALSE,
11749 .MaximumConnectionQueue = options.kernel_backlog,11747 .MaximumConnectionQueue = options.kernel_backlog,
11750 .UseDelayedAcceptance = windows.FALSE,11748 .UseDelayedAcceptance = .FALSE,
11751 }),11749 }),
11752 })).u.Status) {11750 })).u.Status) {
11753 .SUCCESS => {},11751 .SUCCESS => {},
...@@ -11830,9 +11828,9 @@ fn netListenUnixWindows(...@@ -11830,9 +11828,9 @@ fn netListenUnixWindows(
11830 .file = .{ .handle = socket_handle, .flags = .{ .nonblocking = true } },11828 .file = .{ .handle = socket_handle, .flags = .{ .nonblocking = true } },
11831 .code = windows.IOCTL.AFD.START_LISTEN,11829 .code = windows.IOCTL.AFD.START_LISTEN,
11832 .in = @ptrCast(&windows.AFD.LISTEN_INFO{11830 .in = @ptrCast(&windows.AFD.LISTEN_INFO{
11833 .UseSAN = windows.FALSE,11831 .UseSAN = .FALSE,
11834 .MaximumConnectionQueue = options.kernel_backlog,11832 .MaximumConnectionQueue = options.kernel_backlog,
11835 .UseDelayedAcceptance = windows.FALSE,11833 .UseDelayedAcceptance = .FALSE,
11836 }),11834 }),
11837 })).u.Status) {11835 })).u.Status) {
11838 .SUCCESS => {},11836 .SUCCESS => {},
...@@ -12529,7 +12527,7 @@ fn netAcceptWindows(userdata: ?*anyopaque, listen_handle: net.Socket.Handle, opt...@@ -12529,7 +12527,7 @@ fn netAcceptWindows(userdata: ?*anyopaque, listen_handle: net.Socket.Handle, opt
12529 .file = .{ .handle = listen_handle, .flags = .{ .nonblocking = true } },12527 .file = .{ .handle = listen_handle, .flags = .{ .nonblocking = true } },
12530 .code = windows.IOCTL.AFD.ACCEPT,12528 .code = windows.IOCTL.AFD.ACCEPT,
12531 .in = @ptrCast(&windows.AFD.ACCEPT_INFO{12529 .in = @ptrCast(&windows.AFD.ACCEPT_INFO{
12532 .UseSAN = windows.FALSE,12530 .UseSAN = .FALSE,
12533 .Sequence = storage.Info.Sequence,12531 .Sequence = storage.Info.Sequence,
12534 .AcceptHandle = accept_handle,12532 .AcceptHandle = accept_handle,
12535 }),12533 }),
...@@ -12550,7 +12548,7 @@ fn deferAcceptAfd(t: *Threaded, listen_handle: net.Socket.Handle, info: windows....@@ -12550,7 +12548,7 @@ fn deferAcceptAfd(t: *Threaded, listen_handle: net.Socket.Handle, info: windows.
12550 .code = windows.IOCTL.AFD.DEFER_ACCEPT,12548 .code = windows.IOCTL.AFD.DEFER_ACCEPT,
12551 .in = @ptrCast(&windows.AFD.DEFER_ACCEPT_INFO{12549 .in = @ptrCast(&windows.AFD.DEFER_ACCEPT_INFO{
12552 .Sequence = info.Sequence,12550 .Sequence = info.Sequence,
12553 .Reject = windows.FALSE,12551 .Reject = .FALSE,
12554 }),12552 }),
12555 }) catch |err| switch (err) {12553 }) catch |err| switch (err) {
12556 error.Canceled => unreachable, // blocked12554 error.Canceled => unreachable, // blocked
...@@ -15098,7 +15096,7 @@ fn childKillWindows(t: *Threaded, child: *process.Child, exit_code: windows.UINT...@@ -15098,7 +15096,7 @@ fn childKillWindows(t: *Threaded, child: *process.Child, exit_code: windows.UINT
15098 switch (windows.ntdll.NtTerminateProcess(handle, @enumFromInt(exit_code))) {15096 switch (windows.ntdll.NtTerminateProcess(handle, @enumFromInt(exit_code))) {
15099 .SUCCESS, .PROCESS_IS_TERMINATING => {15097 .SUCCESS, .PROCESS_IS_TERMINATING => {
15100 const infinite_timeout: windows.LARGE_INTEGER = std.math.minInt(windows.LARGE_INTEGER);15098 const infinite_timeout: windows.LARGE_INTEGER = std.math.minInt(windows.LARGE_INTEGER);
15101 _ = windows.ntdll.NtWaitForSingleObject(handle, windows.FALSE, &infinite_timeout);15099 _ = windows.ntdll.NtWaitForSingleObject(handle, .FALSE, &infinite_timeout);
15102 childCleanupWindows(child);15100 childCleanupWindows(child);
15103 },15101 },
15104 .ACCESS_DENIED => {15102 .ACCESS_DENIED => {
...@@ -15108,7 +15106,7 @@ fn childKillWindows(t: *Threaded, child: *process.Child, exit_code: windows.UINT...@@ -15108,7 +15106,7 @@ fn childKillWindows(t: *Threaded, child: *process.Child, exit_code: windows.UINT
15108 // PROCESS_TERMINATE access right, so let's do another check to make15106 // PROCESS_TERMINATE access right, so let's do another check to make
15109 // sure the process is really no longer running:15107 // sure the process is really no longer running:
15110 const minimal_timeout: windows.LARGE_INTEGER = -1;15108 const minimal_timeout: windows.LARGE_INTEGER = -1;
15111 return switch (windows.ntdll.NtWaitForSingleObject(handle, windows.FALSE, &minimal_timeout)) {15109 return switch (windows.ntdll.NtWaitForSingleObject(handle, .FALSE, &minimal_timeout)) {
15112 windows.NTSTATUS.WAIT_0 => error.AlreadyTerminated,15110 windows.NTSTATUS.WAIT_0 => error.AlreadyTerminated,
15113 else => error.AccessDenied,15111 else => error.AccessDenied,
15114 };15112 };
...@@ -15122,7 +15120,7 @@ fn childWaitWindows(child: *process.Child) process.Child.WaitError!process.Child...@@ -15122,7 +15120,7 @@ fn childWaitWindows(child: *process.Child) process.Child.WaitError!process.Child
1512215120
15123 const alertable_syscall: AlertableSyscall = try .start();15121 const alertable_syscall: AlertableSyscall = try .start();
15124 const infinite_timeout: windows.LARGE_INTEGER = std.math.minInt(windows.LARGE_INTEGER);15122 const infinite_timeout: windows.LARGE_INTEGER = std.math.minInt(windows.LARGE_INTEGER);
15125 while (true) switch (windows.ntdll.NtWaitForSingleObject(handle, windows.TRUE, &infinite_timeout)) {15123 while (true) switch (windows.ntdll.NtWaitForSingleObject(handle, .TRUE, &infinite_timeout)) {
15126 windows.NTSTATUS.WAIT_0 => break alertable_syscall.finish(),15124 windows.NTSTATUS.WAIT_0 => break alertable_syscall.finish(),
15127 .USER_APC, .ALERTED, .TIMEOUT => {15125 .USER_APC, .ALERTED, .TIMEOUT => {
15128 try alertable_syscall.checkCancel();15126 try alertable_syscall.checkCancel();
...@@ -15458,7 +15456,7 @@ fn processSpawnWindows(userdata: ?*anyopaque, options: process.SpawnOptions) pro...@@ -15458,7 +15456,7 @@ fn processSpawnWindows(userdata: ?*anyopaque, options: process.SpawnOptions) pro
15458 .sa = &.{15456 .sa = &.{
15459 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),15457 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
15460 .lpSecurityDescriptor = null,15458 .lpSecurityDescriptor = null,
15461 .bInheritHandle = windows.TRUE,15459 .bInheritHandle = .TRUE,
15462 },15460 },
15463 .creation = .OPEN,15461 .creation = .OPEN,
15464 }),15462 }),
...@@ -15477,7 +15475,7 @@ fn processSpawnWindows(userdata: ?*anyopaque, options: process.SpawnOptions) pro...@@ -15477,7 +15475,7 @@ fn processSpawnWindows(userdata: ?*anyopaque, options: process.SpawnOptions) pro
15477 .sa = &.{15475 .sa = &.{
15478 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),15476 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
15479 .lpSecurityDescriptor = null,15477 .lpSecurityDescriptor = null,
15480 .bInheritHandle = windows.TRUE,15478 .bInheritHandle = .TRUE,
15481 },15479 },
15482 .creation = .OPEN,15480 .creation = .OPEN,
15483 }),15481 }),
...@@ -15496,7 +15494,7 @@ fn processSpawnWindows(userdata: ?*anyopaque, options: process.SpawnOptions) pro...@@ -15496,7 +15494,7 @@ fn processSpawnWindows(userdata: ?*anyopaque, options: process.SpawnOptions) pro
15496 .sa = &.{15494 .sa = &.{
15497 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),15495 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
15498 .lpSecurityDescriptor = null,15496 .lpSecurityDescriptor = null,
15499 .bInheritHandle = windows.TRUE,15497 .bInheritHandle = .TRUE,
15500 },15498 },
15501 .creation = .OPEN,15499 .creation = .OPEN,
15502 }),15500 }),
...@@ -16021,9 +16019,9 @@ fn windowsCreateProcessPathExt(...@@ -16021,9 +16019,9 @@ fn windowsCreateProcessPathExt(
16021 &file_information_buf,16019 &file_information_buf,
16022 file_information_buf.len,16020 file_information_buf.len,
16023 .Directory,16021 .Directory,
16024 windows.FALSE, // single result16022 .FALSE, // single result
16025 &.init(app_name_wildcard),16023 &.init(app_name_wildcard),
16026 windows.FALSE, // restart iteration16024 .FALSE, // restart iteration
16027 )) {16025 )) {
16028 .SUCCESS => {},16026 .SUCCESS => {},
16029 .NO_SUCH_FILE => return error.FileNotFound,16027 .NO_SUCH_FILE => return error.FileNotFound,
...@@ -16184,13 +16182,13 @@ fn windowsCreateProcess(...@@ -16184,13 +16182,13 @@ fn windowsCreateProcess(
16184 cmd_line,16182 cmd_line,
16185 null,16183 null,
16186 null,16184 null,
16187 windows.TRUE,16185 .TRUE,
16188 flags,16186 flags,
16189 if (env_block) |block| block.slice.ptr else null,16187 if (env_block) |block| block.slice.ptr else null,
16190 cwd_ptr,16188 cwd_ptr,
16191 lpStartupInfo,16189 lpStartupInfo,
16192 lpProcessInformation,16190 lpProcessInformation,
16193 ) != 0) {16191 ).toBool()) {
16194 return syscall.finish();16192 return syscall.finish();
16195 } else switch (windows.GetLastError()) {16193 } else switch (windows.GetLastError()) {
16196 .INVALID_PARAMETER => unreachable,16194 .INVALID_PARAMETER => unreachable,
...@@ -18742,7 +18740,7 @@ fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!windows...@@ -18742,7 +18740,7 @@ fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!windows
1874218740
18743 const attr: windows.OBJECT.ATTRIBUTES = .{18741 const attr: windows.OBJECT.ATTRIBUTES = .{
18744 .RootDirectory = if (Dir.path.isAbsoluteWindowsWtf16(sub_path_w)) null else options.dir,18742 .RootDirectory = if (Dir.path.isAbsoluteWindowsWtf16(sub_path_w)) null else options.dir,
18745 .Attributes = .{ .INHERIT = if (options.sa) |sa| sa.bInheritHandle != windows.FALSE else false },18743 .Attributes = .{ .INHERIT = if (options.sa) |sa| sa.bInheritHandle.toBool() else false },
18746 .ObjectName = @constCast(&windows.UNICODE_STRING.init(sub_path_w)),18744 .ObjectName = @constCast(&windows.UNICODE_STRING.init(sub_path_w)),
18747 .SecurityDescriptor = if (options.sa) |ptr| ptr.lpSecurityDescriptor else null,18745 .SecurityDescriptor = if (options.sa) |ptr| ptr.lpSecurityDescriptor else null,
18748 };18746 };
lib/std/Io/Threaded/test.zig+1-2
...@@ -285,8 +285,7 @@ test "memory mapping fallback" {...@@ -285,8 +285,7 @@ test "memory mapping fallback" {
285/// because it allocates.285/// because it allocates.
286fn RtlDosPathNameToNtPathName_U(path: [:0]const u16) !Io.Threaded.WindowsPathSpace {286fn RtlDosPathNameToNtPathName_U(path: [:0]const u16) !Io.Threaded.WindowsPathSpace {
287 var out: windows.UNICODE_STRING = undefined;287 var out: windows.UNICODE_STRING = undefined;
288 const rc = windows.ntdll.RtlDosPathNameToNtPathName_U(path, &out, null, null);288 if (!windows.ntdll.RtlDosPathNameToNtPathName_U(path, &out, null, null).toBool()) return error.BadPathName;
289 if (rc != windows.TRUE) return error.BadPathName;
290 defer windows.ntdll.RtlFreeUnicodeString(&out);289 defer windows.ntdll.RtlFreeUnicodeString(&out);
291290
292 var path_space: Io.Threaded.WindowsPathSpace = undefined;291 var path_space: Io.Threaded.WindowsPathSpace = undefined;
lib/std/Thread.zig+1-1
...@@ -646,7 +646,7 @@ const WindowsThreadImpl = struct {...@@ -646,7 +646,7 @@ const WindowsThreadImpl = struct {
646646
647 fn join(self: Impl) void {647 fn join(self: Impl) void {
648 const infinite_timeout: windows.LARGE_INTEGER = std.math.minInt(windows.LARGE_INTEGER);648 const infinite_timeout: windows.LARGE_INTEGER = std.math.minInt(windows.LARGE_INTEGER);
649 switch (windows.ntdll.NtWaitForSingleObject(self.thread.thread_handle, windows.FALSE, &infinite_timeout)) {649 switch (windows.ntdll.NtWaitForSingleObject(self.thread.thread_handle, .FALSE, &infinite_timeout)) {
650 windows.NTSTATUS.WAIT_0 => {},650 windows.NTSTATUS.WAIT_0 => {},
651 else => |status| windows.unexpectedStatus(status) catch unreachable,651 else => |status| windows.unexpectedStatus(status) catch unreachable,
652 }652 }
lib/std/os/windows.zig+32-13
...@@ -895,9 +895,9 @@ pub const CONSOLE = struct {...@@ -895,9 +895,9 @@ pub const CONSOLE = struct {
895 /// input895 /// input
896 Mode: MODE,896 Mode: MODE,
897897
898 pub const MODE = enum(BOOLEAN) {898 pub const MODE = enum(BOOLEAN.Backing) {
899 Input = FALSE,899 Input,
900 Output = TRUE,900 Output,
901 };901 };
902 };902 };
903903
...@@ -907,9 +907,9 @@ pub const CONSOLE = struct {...@@ -907,9 +907,9 @@ pub const CONSOLE = struct {
907 /// input907 /// input
908 Mode: MODE,908 Mode: MODE,
909909
910 pub const MODE = enum(BOOLEAN) {910 pub const MODE = enum(BOOLEAN.Backing) {
911 Character = FALSE,911 Character,
912 WideCharacter = TRUE,912 WideCharacter,
913 };913 };
914 };914 };
915915
...@@ -1930,7 +1930,7 @@ pub const DNS = struct {...@@ -1930,7 +1930,7 @@ pub const DNS = struct {
19301930
1931 pub const @"3" = extern struct {1931 pub const @"3" = extern struct {
1932 Base: REQUEST,1932 Base: REQUEST,
1933 IsNetworkQueryRequired: BOOL = FALSE,1933 IsNetworkQueryRequired: BOOL = .FALSE,
1934 RequiredNetworkIndex: DWORD = 0,1934 RequiredNetworkIndex: DWORD = 0,
1935 cCustomServers: DWORD = 0,1935 cCustomServers: DWORD = 0,
1936 pCustomServers: ?*CUSTOM_SERVER = null,1936 pCustomServers: ?*CUSTOM_SERVER = null,
...@@ -4018,7 +4018,7 @@ pub fn eqlIgnoreCaseWtf16(a: []const u16, b: []const u16) bool {...@@ -4018,7 +4018,7 @@ pub fn eqlIgnoreCaseWtf16(a: []const u16, b: []const u16) bool {
4018 }4018 }
4019 // Use RtlEqualUnicodeString on Windows when not in comptime to avoid including a4019 // Use RtlEqualUnicodeString on Windows when not in comptime to avoid including a
4020 // redundant copy of the uppercase data.4020 // redundant copy of the uppercase data.
4021 return ntdll.RtlEqualUnicodeString(&.init(a), &.init(b), TRUE) == TRUE;4021 return ntdll.RtlEqualUnicodeString(&.init(a), &.init(b), .TRUE).toBool();
4022}4022}
40234023
4024/// Compares two WTF-8 strings using the equivalent functionality of4024/// Compares two WTF-8 strings using the equivalent functionality of
...@@ -4270,8 +4270,8 @@ pub const Win32Error = @import("windows/win32error.zig").Win32Error;...@@ -4270,8 +4270,8 @@ pub const Win32Error = @import("windows/win32error.zig").Win32Error;
4270pub const LANG = @import("windows/lang.zig");4270pub const LANG = @import("windows/lang.zig");
4271pub const SUBLANG = @import("windows/sublang.zig");4271pub const SUBLANG = @import("windows/sublang.zig");
42724272
4273pub const BOOL = c_int;4273pub const BOOL = Bool(c_int);
4274pub const BOOLEAN = BYTE;4274pub const BOOLEAN = Bool(BYTE);
4275pub const BYTE = u8;4275pub const BYTE = u8;
4276pub const CHAR = u8;4276pub const CHAR = u8;
4277pub const UCHAR = u8;4277pub const UCHAR = u8;
...@@ -4376,8 +4376,27 @@ fn STRING(comptime C: type) type {...@@ -4376,8 +4376,27 @@ fn STRING(comptime C: type) type {
4376pub const ANSI_STRING = STRING(CHAR);4376pub const ANSI_STRING = STRING(CHAR);
4377pub const UNICODE_STRING = STRING(WCHAR);4377pub const UNICODE_STRING = STRING(WCHAR);
43784378
4379pub const TRUE = 1;4379fn Bool(comptime BackingInteger: type) type {
4380pub const FALSE = 0;4380 return enum(Backing) {
4381 /// false
4382 FALSE = 0,
4383 /// true
4384 _,
4385
4386 /// This is not the only truthy value, comparisons against this value are always a bug.
4387 pub const TRUE: @This() = @enumFromInt(1);
4388
4389 pub const Backing = BackingInteger;
4390
4391 pub fn toBool(b: @This()) bool {
4392 return b != .FALSE;
4393 }
4394
4395 pub fn fromBool(b: bool) @This() {
4396 return @enumFromInt(@intFromBool(b));
4397 }
4398 };
4399}
43814400
4382pub const INVALID_HANDLE_VALUE: HANDLE = @ptrFromInt(maxInt(usize));4401pub const INVALID_HANDLE_VALUE: HANDLE = @ptrFromInt(maxInt(usize));
43834402
...@@ -6087,7 +6106,7 @@ pub const SharedUserData: *const KUSER_SHARED_DATA = @ptrFromInt(0x7FFE0000);...@@ -6087,7 +6106,7 @@ pub const SharedUserData: *const KUSER_SHARED_DATA = @ptrFromInt(0x7FFE0000);
60876106
6088pub fn IsProcessorFeaturePresent(feature: PF) bool {6107pub fn IsProcessorFeaturePresent(feature: PF) bool {
6089 if (@intFromEnum(feature) >= PROCESSOR_FEATURE_MAX) return false;6108 if (@intFromEnum(feature) >= PROCESSOR_FEATURE_MAX) return false;
6090 return SharedUserData.ProcessorFeatures[@intFromEnum(feature)] == 1;6109 return SharedUserData.ProcessorFeatures[@intFromEnum(feature)].toBool();
6091}6110}
60926111
6093// https://github.com/reactos/reactos/blob/master/sdk/include/ndk/pstypes.h#L977-L9836112// https://github.com/reactos/reactos/blob/master/sdk/include/ndk/pstypes.h#L977-L983
lib/std/process.zig+1-1
...@@ -800,7 +800,7 @@ pub fn abort() noreturn {...@@ -800,7 +800,7 @@ pub fn abort() noreturn {
800 // even when linking libc on Windows we use our own abort implementation.800 // even when linking libc on Windows we use our own abort implementation.
801 // See https://github.com/ziglang/zig/issues/2071 for more details.801 // See https://github.com/ziglang/zig/issues/2071 for more details.
802 if (native_os == .windows) {802 if (native_os == .windows) {
803 if (builtin.mode == .Debug and windows.peb().BeingDebugged != 0) {803 if (builtin.mode == .Debug and windows.peb().BeingDebugged.toBool()) {
804 @breakpoint();804 @breakpoint();
805 }805 }
806 windows.ntdll.RtlExitUserProcess(3);806 windows.ntdll.RtlExitUserProcess(3);
lib/std/start.zig+1-1
...@@ -84,7 +84,7 @@ fn _DllMainCRTStartup(...@@ -84,7 +84,7 @@ fn _DllMainCRTStartup(
84 return root.DllMain(hinstDLL, fdwReason, lpReserved);84 return root.DllMain(hinstDLL, fdwReason, lpReserved);
85 }85 }
8686
87 return std.os.windows.TRUE;87 return .TRUE;
88}88}
8989
90fn wasm_freestanding_start() callconv(.c) void {90fn wasm_freestanding_start() callconv(.c) void {
test/standalone/windows_argv/fuzz.zig+4-6
...@@ -129,20 +129,18 @@ fn spawnVerify(verify_path: [:0]const u16, cmd_line: [:0]const u16) !windows.DWO...@@ -129,20 +129,18 @@ fn spawnVerify(verify_path: [:0]const u16, cmd_line: [:0]const u16) !windows.DWO
129 };129 };
130 var proc_info: windows.PROCESS.INFORMATION = undefined;130 var proc_info: windows.PROCESS.INFORMATION = undefined;
131131
132 if (windows.kernel32.CreateProcessW(132 if (!windows.kernel32.CreateProcessW(
133 @constCast(verify_path.ptr),133 @constCast(verify_path.ptr),
134 @constCast(cmd_line.ptr),134 @constCast(cmd_line.ptr),
135 null,135 null,
136 null,136 null,
137 windows.TRUE,137 .TRUE,
138 .{},138 .{},
139 null,139 null,
140 null,140 null,
141 &startup_info,141 &startup_info,
142 &proc_info,142 &proc_info,
143 ) == 0) {143 ).toBool()) std.process.fatal("kernel32 CreateProcessW failed with {t}", .{windows.GetLastError()});
144 std.process.fatal("kernel32 CreateProcessW failed with {t}", .{windows.GetLastError()});
145 }
146144
147 windows.CloseHandle(proc_info.hThread);145 windows.CloseHandle(proc_info.hThread);
148146
...@@ -150,7 +148,7 @@ fn spawnVerify(verify_path: [:0]const u16, cmd_line: [:0]const u16) !windows.DWO...@@ -150,7 +148,7 @@ fn spawnVerify(verify_path: [:0]const u16, cmd_line: [:0]const u16) !windows.DWO
150 };148 };
151 defer windows.CloseHandle(child_proc);149 defer windows.CloseHandle(child_proc);
152 const infinite_timeout: windows.LARGE_INTEGER = std.math.minInt(windows.LARGE_INTEGER);150 const infinite_timeout: windows.LARGE_INTEGER = std.math.minInt(windows.LARGE_INTEGER);
153 switch (windows.ntdll.NtWaitForSingleObject(child_proc, windows.FALSE, &infinite_timeout)) {151 switch (windows.ntdll.NtWaitForSingleObject(child_proc, .FALSE, &infinite_timeout)) {
154 windows.NTSTATUS.WAIT_0 => {},152 windows.NTSTATUS.WAIT_0 => {},
155 .TIMEOUT => return error.WaitTimeOut,153 .TIMEOUT => return error.WaitTimeOut,
156 else => |status| return windows.unexpectedStatus(status),154 else => |status| return windows.unexpectedStatus(status),
test/standalone/windows_spawn/main.zig+8-29
...@@ -29,16 +29,10 @@ pub fn main(init: std.process.Init) !void {...@@ -29,16 +29,10 @@ pub fn main(init: std.process.Init) !void {
29 defer gpa.free(tmp_relative_path);29 defer gpa.free(tmp_relative_path);
3030
31 // Clear PATH31 // Clear PATH
32 std.debug.assert(SetEnvironmentVariableW(32 std.debug.assert(SetEnvironmentVariableW(utf16Literal("PATH"), null).toBool());
33 utf16Literal("PATH"),
34 null,
35 ) == windows.TRUE);
3633
37 // Set PATHEXT to something predictable34 // Set PATHEXT to something predictable
38 std.debug.assert(SetEnvironmentVariableW(35 std.debug.assert(SetEnvironmentVariableW(utf16Literal("PATHEXT"), utf16Literal(".COM;.EXE;.BAT;.CMD;.JS")).toBool());
39 utf16Literal("PATHEXT"),
40 utf16Literal(".COM;.EXE;.BAT;.CMD;.JS"),
41 ) == windows.TRUE);
4236
43 // No PATH, so it should fail to find anything not in the cwd37 // No PATH, so it should fail to find anything not in the cwd
44 try testExecError(error.FileNotFound, gpa, io, "something_missing");38 try testExecError(error.FileNotFound, gpa, io, "something_missing");
...@@ -46,10 +40,7 @@ pub fn main(init: std.process.Init) !void {...@@ -46,10 +40,7 @@ pub fn main(init: std.process.Init) !void {
46 // make sure we don't get error.BadPath traversing out of cwd with a relative path40 // make sure we don't get error.BadPath traversing out of cwd with a relative path
47 try testExecError(error.FileNotFound, gpa, io, "..\\.\\.\\.\\\\..\\more_missing");41 try testExecError(error.FileNotFound, gpa, io, "..\\.\\.\\.\\\\..\\more_missing");
4842
49 std.debug.assert(SetEnvironmentVariableW(43 std.debug.assert(SetEnvironmentVariableW(utf16Literal("PATH"), tmp_absolute_path_w).toBool());
50 utf16Literal("PATH"),
51 tmp_absolute_path_w,
52 ) == windows.TRUE);
5344
54 // Move hello.exe into the tmp dir which is now added to the path45 // Move hello.exe into the tmp dir which is now added to the path
55 try Io.Dir.cwd().copyFile(hello_exe_cache_path, tmp_dir, "hello.exe", io, .{});46 try Io.Dir.cwd().copyFile(hello_exe_cache_path, tmp_dir, "hello.exe", io, .{});
...@@ -129,10 +120,7 @@ pub fn main(init: std.process.Init) !void {...@@ -129,10 +120,7 @@ pub fn main(init: std.process.Init) !void {
129 const something_subdir_abs_path = try std.mem.concatWithSentinel(gpa, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0);120 const something_subdir_abs_path = try std.mem.concatWithSentinel(gpa, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0);
130 defer gpa.free(something_subdir_abs_path);121 defer gpa.free(something_subdir_abs_path);
131122
132 std.debug.assert(SetEnvironmentVariableW(123 std.debug.assert(SetEnvironmentVariableW(utf16Literal("PATH"), something_subdir_abs_path).toBool());
133 utf16Literal("PATH"),
134 something_subdir_abs_path,
135 ) == windows.TRUE);
136124
137 // Now trying to execute goodbye should give error.InvalidExe since it's the original125 // Now trying to execute goodbye should give error.InvalidExe since it's the original
138 // error that we got when trying within the cwd126 // error that we got when trying within the cwd
...@@ -169,18 +157,12 @@ pub fn main(init: std.process.Init) !void {...@@ -169,18 +157,12 @@ pub fn main(init: std.process.Init) !void {
169 defer gpa.free(denormed_something_subdir_wtf8);157 defer gpa.free(denormed_something_subdir_wtf8);
170158
171 // clear the path to ensure that the match comes from the cwd159 // clear the path to ensure that the match comes from the cwd
172 std.debug.assert(SetEnvironmentVariableW(160 std.debug.assert(SetEnvironmentVariableW(utf16Literal("PATH"), null).toBool());
173 utf16Literal("PATH"),
174 null,
175 ) == windows.TRUE);
176161
177 try testExecWithCwd(gpa, io, "goodbye", denormed_something_subdir_wtf8, "hello from exe\n");162 try testExecWithCwd(gpa, io, "goodbye", denormed_something_subdir_wtf8, "hello from exe\n");
178163
179 // normalization should also work if the non-normalized path is found in the PATH var.164 // normalization should also work if the non-normalized path is found in the PATH var.
180 std.debug.assert(SetEnvironmentVariableW(165 std.debug.assert(SetEnvironmentVariableW(utf16Literal("PATH"), denormed_something_subdir_abs_path).toBool());
181 utf16Literal("PATH"),
182 denormed_something_subdir_abs_path,
183 ) == windows.TRUE);
184 try testExec(gpa, io, "goodbye", "hello from exe\n");166 try testExec(gpa, io, "goodbye", "hello from exe\n");
185167
186 // now make sure we can launch executables "outside" of the cwd168 // now make sure we can launch executables "outside" of the cwd
...@@ -191,10 +173,7 @@ pub fn main(init: std.process.Init) !void {...@@ -191,10 +173,7 @@ pub fn main(init: std.process.Init) !void {
191 try std.process.setCurrentDir(io, subdir_cwd);173 try std.process.setCurrentDir(io, subdir_cwd);
192174
193 // clear the PATH again175 // clear the PATH again
194 std.debug.assert(SetEnvironmentVariableW(176 std.debug.assert(SetEnvironmentVariableW(utf16Literal("PATH"), null).toBool());
195 utf16Literal("PATH"),
196 null,
197 ) == windows.TRUE);
198177
199 // while we're at it make sure non-windows separators work fine178 // while we're at it make sure non-windows separators work fine
200 try testExec(gpa, io, "../hello", "hello from exe\n");179 try testExec(gpa, io, "../hello", "hello from exe\n");
...@@ -237,7 +216,7 @@ fn renameExe(dir: Io.Dir, io: Io, old_sub_path: []const u8, new_sub_path: []cons...@@ -237,7 +216,7 @@ fn renameExe(dir: Io.Dir, io: Io, old_sub_path: []const u8, new_sub_path: []cons
237 if (attempt == 26) return error.AccessDenied;216 if (attempt == 26) return error.AccessDenied;
238 // give the kernel a chance to finish closing the executable handle217 // give the kernel a chance to finish closing the executable handle
239 const interval = @as(std.os.windows.LARGE_INTEGER, -1) << attempt;218 const interval = @as(std.os.windows.LARGE_INTEGER, -1) << attempt;
240 _ = std.os.windows.ntdll.NtDelayExecution(std.os.windows.FALSE, &interval);219 _ = std.os.windows.ntdll.NtDelayExecution(.FALSE, &interval);
241 attempt += 1;220 attempt += 1;
242 continue;221 continue;
243 },222 },