diff options
| author | Lucas Santos <117400842+LucasSantos91@users.noreply.github.com> | 2024-07-15 14:49:51 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-15 10:49:51 -0700 |
| commit | 89942ebd03b2943cbbe84b575a024e156ca5bf52 (patch) | |
| tree | 0892910484a47d30d4c5f2dccff9f16d0162687e /lib/std/process | |
| parent | cf36d3fdd3674bfb95f22aa7bc7ff450ebdc1c08 (diff) | |
| download | zig-89942ebd03b2943cbbe84b575a024e156ca5bf52.tar.gz zig-89942ebd03b2943cbbe84b575a024e156ca5bf52.zip | |
Better implementation of GetLastError. (#20623)
Instead of calling the dynamically loaded kernel32.GetLastError, we can extract it from the TEB.
As shown by [Wine](https://github.com/wine-mirror/wine/blob/34b1606019982b71818780bc84b76460f650af31/include/winternl.h#L439), the last error lives at offset 0x34 of the TEB in 32-bit Windows and at offset 0x68 in 64-bit Windows.
Diffstat (limited to 'lib/std/process')
| -rw-r--r-- | lib/std/process/Child.zig | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/std/process/Child.zig b/lib/std/process/Child.zig index 2f86794208..c4a7911e21 100644 --- a/lib/std/process/Child.zig +++ b/lib/std/process/Child.zig @@ -1358,7 +1358,7 @@ fn windowsMakeAsyncPipe(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *cons sattr, ); if (read_handle == windows.INVALID_HANDLE_VALUE) { - switch (windows.kernel32.GetLastError()) { + switch (windows.GetLastError()) { else => |err| return windows.unexpectedError(err), } } @@ -1375,7 +1375,7 @@ fn windowsMakeAsyncPipe(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *cons null, ); if (write_handle == windows.INVALID_HANDLE_VALUE) { - switch (windows.kernel32.GetLastError()) { + switch (windows.GetLastError()) { else => |err| return windows.unexpectedError(err), } } @@ -1529,7 +1529,7 @@ fn windowsCmdExePath(allocator: mem.Allocator) error{ OutOfMemory, Unexpected }! // TODO: Get the system directory from PEB.ReadOnlyStaticServerData const len = windows.kernel32.GetSystemDirectoryW(@ptrCast(unused_slice), @intCast(unused_slice.len)); if (len == 0) { - switch (windows.kernel32.GetLastError()) { + switch (windows.GetLastError()) { else => |err| return windows.unexpectedError(err), } } |
