mirror of
https://github.com/ziglang/zig.git
synced 2025-12-26 08:03:08 +00:00
NTSTATUS is a non-exhaustive enum
This commit is contained in:
parent
176bc53858
commit
7cf0b02ab4
@ -598,8 +598,8 @@ pub const Dir = struct {
|
||||
self.index = 0;
|
||||
self.end_index = io.Information;
|
||||
switch (rc) {
|
||||
w.STATUS.SUCCESS => {},
|
||||
w.STATUS.ACCESS_DENIED => return error.AccessDenied,
|
||||
.SUCCESS => {},
|
||||
.ACCESS_DENIED => return error.AccessDenied,
|
||||
else => return w.unexpectedStatus(rc),
|
||||
}
|
||||
}
|
||||
@ -837,16 +837,16 @@ pub const Dir = struct {
|
||||
0,
|
||||
);
|
||||
switch (rc) {
|
||||
w.STATUS.SUCCESS => return result,
|
||||
w.STATUS.OBJECT_NAME_INVALID => unreachable,
|
||||
w.STATUS.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
|
||||
w.STATUS.OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
|
||||
w.STATUS.INVALID_PARAMETER => unreachable,
|
||||
w.STATUS.SHARING_VIOLATION => return error.SharingViolation,
|
||||
w.STATUS.ACCESS_DENIED => return error.AccessDenied,
|
||||
w.STATUS.PIPE_BUSY => return error.PipeBusy,
|
||||
w.STATUS.OBJECT_PATH_SYNTAX_BAD => unreachable,
|
||||
w.STATUS.OBJECT_NAME_COLLISION => return error.PathAlreadyExists,
|
||||
.SUCCESS => return result,
|
||||
.OBJECT_NAME_INVALID => unreachable,
|
||||
.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
|
||||
.OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
|
||||
.INVALID_PARAMETER => unreachable,
|
||||
.SHARING_VIOLATION => return error.SharingViolation,
|
||||
.ACCESS_DENIED => return error.AccessDenied,
|
||||
.PIPE_BUSY => return error.PipeBusy,
|
||||
.OBJECT_PATH_SYNTAX_BAD => unreachable,
|
||||
.OBJECT_NAME_COLLISION => return error.PathAlreadyExists,
|
||||
else => return w.unexpectedStatus(rc),
|
||||
}
|
||||
}
|
||||
@ -990,11 +990,11 @@ pub const Dir = struct {
|
||||
0,
|
||||
);
|
||||
switch (rc) {
|
||||
w.STATUS.SUCCESS => return result,
|
||||
w.STATUS.OBJECT_NAME_INVALID => unreachable,
|
||||
w.STATUS.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
|
||||
w.STATUS.OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
|
||||
w.STATUS.INVALID_PARAMETER => unreachable,
|
||||
.SUCCESS => return result,
|
||||
.OBJECT_NAME_INVALID => unreachable,
|
||||
.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
|
||||
.OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
|
||||
.INVALID_PARAMETER => unreachable,
|
||||
else => return w.unexpectedStatus(rc),
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,10 +225,10 @@ pub const File = struct {
|
||||
var info: windows.FILE_ALL_INFORMATION = undefined;
|
||||
const rc = windows.ntdll.NtQueryInformationFile(self.handle, &io_status_block, &info, @sizeOf(windows.FILE_ALL_INFORMATION), .FileAllInformation);
|
||||
switch (rc) {
|
||||
windows.STATUS.SUCCESS => {},
|
||||
windows.STATUS.BUFFER_OVERFLOW => {},
|
||||
windows.STATUS.INVALID_PARAMETER => unreachable,
|
||||
windows.STATUS.ACCESS_DENIED => return error.AccessDenied,
|
||||
.SUCCESS => {},
|
||||
.BUFFER_OVERFLOW => {},
|
||||
.INVALID_PARAMETER => unreachable,
|
||||
.ACCESS_DENIED => return error.AccessDenied,
|
||||
else => return windows.unexpectedStatus(rc),
|
||||
}
|
||||
return Stat{
|
||||
|
||||
@ -126,7 +126,7 @@ else if (builtin.os == .windows)
|
||||
// then unset the WAKE bit so that another unlocker can wake up a thread.
|
||||
} else if (@cmpxchgWeak(u32, &self.waiters, waiters, (waiters + WAIT) | 1, .Monotonic, .Monotonic) == null) {
|
||||
const rc = windows.ntdll.NtWaitForKeyedEvent(handle, key, windows.FALSE, null);
|
||||
assert(rc == 0);
|
||||
assert(rc == .SUCCESS);
|
||||
_ = @atomicRmw(u32, &self.waiters, .Sub, WAKE, .Monotonic);
|
||||
}
|
||||
}
|
||||
@ -154,7 +154,7 @@ else if (builtin.os == .windows)
|
||||
// try to decrease the waiter count & set the WAKE bit meaning a thread is waking up
|
||||
if (@cmpxchgWeak(u32, &self.mutex.waiters, waiters, waiters - WAIT + WAKE, .Release, .Monotonic) == null) {
|
||||
const rc = windows.ntdll.NtReleaseKeyedEvent(handle, key, windows.FALSE, null);
|
||||
assert(rc == 0);
|
||||
assert(rc == .SUCCESS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1176,15 +1176,15 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*:0]const u16, flags: u32) UnlinkatEr
|
||||
null,
|
||||
0,
|
||||
);
|
||||
if (rc == w.STATUS.SUCCESS) {
|
||||
if (rc == .SUCCESS) {
|
||||
rc = w.ntdll.NtClose(tmp_handle);
|
||||
}
|
||||
switch (rc) {
|
||||
w.STATUS.SUCCESS => return,
|
||||
w.STATUS.OBJECT_NAME_INVALID => unreachable,
|
||||
w.STATUS.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
|
||||
w.STATUS.INVALID_PARAMETER => unreachable,
|
||||
w.STATUS.FILE_IS_A_DIRECTORY => return error.IsDir,
|
||||
.SUCCESS => return,
|
||||
.OBJECT_NAME_INVALID => unreachable,
|
||||
.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
|
||||
.INVALID_PARAMETER => unreachable,
|
||||
.FILE_IS_A_DIRECTORY => return error.IsDir,
|
||||
else => return w.unexpectedStatus(rc),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1057,7 +1057,7 @@ pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError {
|
||||
/// and you get an unexpected status.
|
||||
pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {
|
||||
if (std.os.unexpected_error_tracing) {
|
||||
std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", .{status});
|
||||
std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", .{@enumToInt(status)});
|
||||
std.debug.dumpCurrentStackTrace(null);
|
||||
}
|
||||
return error.Unexpected;
|
||||
|
||||
@ -6,7 +6,7 @@ const assert = std.debug.assert;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub const ERROR = @import("error.zig");
|
||||
pub const STATUS = @import("status.zig");
|
||||
pub usingnamespace @import("ntstatus.zig");
|
||||
pub const LANG = @import("lang.zig");
|
||||
pub const SUBLANG = @import("sublang.zig");
|
||||
|
||||
@ -62,7 +62,6 @@ pub const ULONGLONG = u64;
|
||||
pub const LONGLONG = i64;
|
||||
pub const HLOCAL = HANDLE;
|
||||
pub const LANGID = c_ushort;
|
||||
pub const NTSTATUS = ULONG;
|
||||
|
||||
pub const va_list = *@OpaqueType();
|
||||
|
||||
@ -929,9 +928,12 @@ pub usingnamespace switch (builtin.arch) {
|
||||
SegSs: DWORD,
|
||||
ExtendedRegisters: [512]BYTE,
|
||||
|
||||
pub fn getRegs(ctx: *const CONTEXT) struct {bp: usize, ip: usize} {
|
||||
return .{.bp = ctx.Ebp, .ip = ctx.Eip};
|
||||
}
|
||||
pub fn getRegs(ctx: *const CONTEXT) struct {
|
||||
bp: usize,
|
||||
ip: usize,
|
||||
} {
|
||||
return .{ .bp = ctx.Ebp, .ip = ctx.Eip };
|
||||
}
|
||||
};
|
||||
|
||||
pub const PCONTEXT = *CONTEXT;
|
||||
@ -1032,8 +1034,11 @@ pub usingnamespace switch (builtin.arch) {
|
||||
LastExceptionToRip: DWORD64,
|
||||
LastExceptionFromRip: DWORD64,
|
||||
|
||||
pub fn getRegs(ctx: *const CONTEXT) struct {bp: usize, ip: usize} {
|
||||
return .{.bp = ctx.Rbp, .ip = ctx.Rip};
|
||||
pub fn getRegs(ctx: *const CONTEXT) struct {
|
||||
bp: usize,
|
||||
ip: usize,
|
||||
} {
|
||||
return .{ .bp = ctx.Rbp, .ip = ctx.Rip };
|
||||
}
|
||||
};
|
||||
|
||||
@ -1100,8 +1105,11 @@ pub usingnamespace switch (builtin.arch) {
|
||||
Wcr: [2]DWORD,
|
||||
Wvr: [2]DWORD64,
|
||||
|
||||
pub fn getRegs(ctx: *const CONTEXT) struct {bp: usize, ip: usize} {
|
||||
return .{.bp = ctx.DUMMYUNIONNAME.DUMMYSTRUCTNAME.Fp, .ip = ctx.Pc};
|
||||
pub fn getRegs(ctx: *const CONTEXT) struct {
|
||||
bp: usize,
|
||||
ip: usize,
|
||||
} {
|
||||
return .{ .bp = ctx.DUMMYUNIONNAME.DUMMYSTRUCTNAME.Fp, .ip = ctx.Pc };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
5600
lib/std/os/windows/ntstatus.zig
Normal file
5600
lib/std/os/windows/ntstatus.zig
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -283,7 +283,7 @@ const AtomicEvent = struct {
|
||||
var waiting = wake_count;
|
||||
while (waiting != 0) : (waiting -= 1) {
|
||||
const rc = windows.ntdll.NtReleaseKeyedEvent(handle, key, windows.FALSE, null);
|
||||
assert(rc == 0);
|
||||
assert(rc == .SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -302,7 +302,7 @@ const AtomicEvent = struct {
|
||||
// NtWaitForKeyedEvent doesnt have spurious wake-ups
|
||||
var rc = windows.ntdll.NtWaitForKeyedEvent(handle, key, windows.FALSE, timeout_ptr);
|
||||
switch (rc) {
|
||||
windows.WAIT_TIMEOUT => {
|
||||
.TIMEOUT => {
|
||||
// update the wait count to signal that we're not waiting anymore.
|
||||
// if the .set() thread already observed that we are, perform a
|
||||
// matching NtWaitForKeyedEvent so that the .set() thread doesn't
|
||||
@ -311,7 +311,7 @@ const AtomicEvent = struct {
|
||||
while (true) {
|
||||
if (waiting == WAKE) {
|
||||
rc = windows.ntdll.NtWaitForKeyedEvent(handle, key, windows.FALSE, null);
|
||||
assert(rc == windows.WAIT_OBJECT_0);
|
||||
assert(rc == .WAIT_0);
|
||||
break;
|
||||
} else {
|
||||
waiting = @cmpxchgWeak(u32, waiters, waiting, waiting - WAIT, .Acquire, .Monotonic) orelse break;
|
||||
@ -320,7 +320,7 @@ const AtomicEvent = struct {
|
||||
}
|
||||
return error.TimedOut;
|
||||
},
|
||||
windows.WAIT_OBJECT_0 => {},
|
||||
.WAIT_0 => {},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@ -336,7 +336,7 @@ const AtomicEvent = struct {
|
||||
EMPTY => handle = @cmpxchgWeak(usize, &event_handle, EMPTY, LOADING, .Acquire, .Monotonic) orelse {
|
||||
const handle_ptr = @ptrCast(*windows.HANDLE, &handle);
|
||||
const access_mask = windows.GENERIC_READ | windows.GENERIC_WRITE;
|
||||
if (windows.ntdll.NtCreateKeyedEvent(handle_ptr, access_mask, null, 0) != 0)
|
||||
if (windows.ntdll.NtCreateKeyedEvent(handle_ptr, access_mask, null, 0) != .SUCCESS)
|
||||
handle = 0;
|
||||
@atomicStore(usize, &event_handle, handle, .Monotonic);
|
||||
return @intToPtr(?windows.HANDLE, handle);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user