authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-13 15:29:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-14 06:06:03+01:00
logd6402955d962b1563378b44a82a9644cee344ff3
tree8bc9357d8242601e12e2c3810cbcbb6fbd534d57
parente0d38561f09c1cf06535153ba4cd0564f5e7bcf1

kernel32: another one bytes the dust


2 files changed, 2 insertions(+), 33 deletions(-)

lib/std/os/windows.zig+2-14
...@@ -3211,21 +3211,9 @@ inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID {...@@ -3211,21 +3211,9 @@ inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID {
3211/// Call this when you made a windows DLL call or something that does SetLastError3211/// Call this when you made a windows DLL call or something that does SetLastError
3212/// and you get an unexpected error.3212/// and you get an unexpected error.
3213pub fn unexpectedError(err: Win32Error) UnexpectedError {3213pub fn unexpectedError(err: Win32Error) UnexpectedError {
3214 @branchHint(.cold);
3214 if (std.posix.unexpected_error_tracing) {3215 if (std.posix.unexpected_error_tracing) {
3215 // 614 is the length of the longest windows error description3216 std.debug.print("error.Unexpected: GetLastError({d}): {t}\n", .{ err, err });
3216 var buf_wstr: [614:0]WCHAR = undefined;
3217 const len = kernel32.FormatMessageW(
3218 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
3219 null,
3220 err,
3221 MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT),
3222 &buf_wstr,
3223 buf_wstr.len,
3224 null,
3225 );
3226 std.debug.print("error.Unexpected: GetLastError({d}): {f}\n", .{
3227 err, std.unicode.fmtUtf16Le(buf_wstr[0..len]),
3228 });
3229 std.debug.dumpCurrentStackTrace(.{ .first_address = @returnAddress() });3217 std.debug.dumpCurrentStackTrace(.{ .first_address = @returnAddress() });
3230 }3218 }
3231 return error.Unexpected;3219 return error.Unexpected;
lib/std/os/windows/kernel32.zig-19
...@@ -4,7 +4,6 @@ const windows = std.os.windows;...@@ -4,7 +4,6 @@ const windows = std.os.windows;
4const BOOL = windows.BOOL;4const BOOL = windows.BOOL;
5const DWORD = windows.DWORD;5const DWORD = windows.DWORD;
6const HANDLE = windows.HANDLE;6const HANDLE = windows.HANDLE;
7const LPCVOID = windows.LPCVOID;
8const LPCWSTR = windows.LPCWSTR;7const LPCWSTR = windows.LPCWSTR;
9const LPVOID = windows.LPVOID;8const LPVOID = windows.LPVOID;
10const LPWSTR = windows.LPWSTR;9const LPWSTR = windows.LPWSTR;
...@@ -13,10 +12,6 @@ const THREAD_START_ROUTINE = windows.THREAD_START_ROUTINE;...@@ -13,10 +12,6 @@ const THREAD_START_ROUTINE = windows.THREAD_START_ROUTINE;
13const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES;12const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES;
14const SIZE_T = windows.SIZE_T;13const SIZE_T = windows.SIZE_T;
15const STARTUPINFOW = windows.STARTUPINFOW;14const STARTUPINFOW = windows.STARTUPINFOW;
16const va_list = windows.va_list;
17const Win32Error = windows.Win32Error;
18
19// Process Management
2015
21pub extern "kernel32" fn CreateProcessW(16pub extern "kernel32" fn CreateProcessW(
22 lpApplicationName: ?LPCWSTR,17 lpApplicationName: ?LPCWSTR,
...@@ -31,8 +26,6 @@ pub extern "kernel32" fn CreateProcessW(...@@ -31,8 +26,6 @@ pub extern "kernel32" fn CreateProcessW(
31 lpProcessInformation: *PROCESS.INFORMATION,26 lpProcessInformation: *PROCESS.INFORMATION,
32) callconv(.winapi) BOOL;27) callconv(.winapi) BOOL;
3328
34// Threading
35
36// TODO: CreateRemoteThread with hProcess=NtCurrentProcess().29// TODO: CreateRemoteThread with hProcess=NtCurrentProcess().
37pub extern "kernel32" fn CreateThread(30pub extern "kernel32" fn CreateThread(
38 lpThreadAttributes: ?*SECURITY_ATTRIBUTES,31 lpThreadAttributes: ?*SECURITY_ATTRIBUTES,
...@@ -42,15 +35,3 @@ pub extern "kernel32" fn CreateThread(...@@ -42,15 +35,3 @@ pub extern "kernel32" fn CreateThread(
42 dwCreationFlags: DWORD,35 dwCreationFlags: DWORD,
43 lpThreadId: ?*DWORD,36 lpThreadId: ?*DWORD,
44) callconv(.winapi) ?HANDLE;37) callconv(.winapi) ?HANDLE;
45
46// Error Management
47
48pub extern "kernel32" fn FormatMessageW(
49 dwFlags: DWORD,
50 lpSource: ?LPCVOID,
51 dwMessageId: Win32Error,
52 dwLanguageId: DWORD,
53 lpBuffer: LPWSTR,
54 nSize: DWORD,
55 Arguments: ?*va_list,
56) callconv(.winapi) DWORD;