From d6402955d962b1563378b44a82a9644cee344ff3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 13 Mar 2026 15:29:25 -0700 Subject: [PATCH] kernel32: another one bytes the dust --- lib/std/os/windows.zig | 16 ++-------------- lib/std/os/windows/kernel32.zig | 19 ------------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index f38b340703fcf4447e324f8ad6213acae39979cf..1dabd71422d8e715ec567011752df2acf452de0c 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -3211,21 +3211,9 @@ inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID { /// Call this when you made a windows DLL call or something that does SetLastError /// and you get an unexpected error. pub fn unexpectedError(err: Win32Error) UnexpectedError { + @branchHint(.cold); if (std.posix.unexpected_error_tracing) { - // 614 is the length of the longest windows error description - var buf_wstr: [614:0]WCHAR = undefined; - const len = kernel32.FormatMessageW( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - null, - err, - MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT), - &buf_wstr, - buf_wstr.len, - null, - ); - std.debug.print("error.Unexpected: GetLastError({d}): {f}\n", .{ - err, std.unicode.fmtUtf16Le(buf_wstr[0..len]), - }); + std.debug.print("error.Unexpected: GetLastError({d}): {t}\n", .{ err, err }); std.debug.dumpCurrentStackTrace(.{ .first_address = @returnAddress() }); } return error.Unexpected; diff --git a/lib/std/os/windows/kernel32.zig b/lib/std/os/windows/kernel32.zig index 894ef96a7ef0a2f4efde753c276c09bd0887bbc1..649d09cc6256cccc49d9a18d2834e16e5450e36c 100644 --- a/lib/std/os/windows/kernel32.zig +++ b/lib/std/os/windows/kernel32.zig @@ -4,7 +4,6 @@ const windows = std.os.windows; const BOOL = windows.BOOL; const DWORD = windows.DWORD; const HANDLE = windows.HANDLE; -const LPCVOID = windows.LPCVOID; const LPCWSTR = windows.LPCWSTR; const LPVOID = windows.LPVOID; const LPWSTR = windows.LPWSTR; @@ -13,10 +12,6 @@ const THREAD_START_ROUTINE = windows.THREAD_START_ROUTINE; const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES; const SIZE_T = windows.SIZE_T; const STARTUPINFOW = windows.STARTUPINFOW; -const va_list = windows.va_list; -const Win32Error = windows.Win32Error; - -// Process Management pub extern "kernel32" fn CreateProcessW( lpApplicationName: ?LPCWSTR, @@ -31,8 +26,6 @@ pub extern "kernel32" fn CreateProcessW( lpProcessInformation: *PROCESS.INFORMATION, ) callconv(.winapi) BOOL; -// Threading - // TODO: CreateRemoteThread with hProcess=NtCurrentProcess(). pub extern "kernel32" fn CreateThread( lpThreadAttributes: ?*SECURITY_ATTRIBUTES, @@ -42,15 +35,3 @@ pub extern "kernel32" fn CreateThread( dwCreationFlags: DWORD, lpThreadId: ?*DWORD, ) callconv(.winapi) ?HANDLE; - -// Error Management - -pub extern "kernel32" fn FormatMessageW( - dwFlags: DWORD, - lpSource: ?LPCVOID, - dwMessageId: Win32Error, - dwLanguageId: DWORD, - lpBuffer: LPWSTR, - nSize: DWORD, - Arguments: ?*va_list, -) callconv(.winapi) DWORD; -- 2.54.0