diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-08-31 20:39:33 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-08-31 20:39:47 -0700 |
| commit | fc23fe90ce1f3d28841c5a5a93a8bdf7edaefc54 (patch) | |
| tree | c5d5264758254f7c419141006a6ec3676fbe8b00 /lib/std | |
| parent | ec36e0609fb97fef96e72fb76f5515b751519a61 (diff) | |
| download | zig-fc23fe90ce1f3d28841c5a5a93a8bdf7edaefc54.tar.gz zig-fc23fe90ce1f3d28841c5a5a93a8bdf7edaefc54.zip | |
std.os.windows: avoid dragging in baggage on non-windows
particularly noticeable when usize is not 4 or 8 bytes
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/os/windows.zig | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 66583d21b2..5f7c900eb7 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -4621,25 +4621,28 @@ pub const TEB = extern struct { }; comptime { - // Offsets taken from WinDbg info and Geoff Chappell[1] (RIP) - // [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm - assert(@offsetOf(TEB, "NtTib") == 0x00); - if (@sizeOf(usize) == 4) { - assert(@offsetOf(TEB, "EnvironmentPointer") == 0x1C); - assert(@offsetOf(TEB, "ClientId") == 0x20); - assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x28); - assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x2C); - assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30); - assert(@offsetOf(TEB, "LastErrorValue") == 0x34); - assert(@offsetOf(TEB, "TlsSlots") == 0xe10); - } else if (@sizeOf(usize) == 8) { - assert(@offsetOf(TEB, "EnvironmentPointer") == 0x38); - assert(@offsetOf(TEB, "ClientId") == 0x40); - assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x50); - assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x58); - assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60); - assert(@offsetOf(TEB, "LastErrorValue") == 0x68); - assert(@offsetOf(TEB, "TlsSlots") == 0x1480); + // This file may be referenced for its error sets, so we must not assume target windows here. + if (builtin.os.tag == .windows) { + // Offsets taken from WinDbg info and Geoff Chappell[1] (RIP) + // [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm + assert(@offsetOf(TEB, "NtTib") == 0x00); + if (@sizeOf(usize) == 4) { + assert(@offsetOf(TEB, "EnvironmentPointer") == 0x1C); + assert(@offsetOf(TEB, "ClientId") == 0x20); + assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x28); + assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x2C); + assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30); + assert(@offsetOf(TEB, "LastErrorValue") == 0x34); + assert(@offsetOf(TEB, "TlsSlots") == 0xe10); + } else if (@sizeOf(usize) == 8) { + assert(@offsetOf(TEB, "EnvironmentPointer") == 0x38); + assert(@offsetOf(TEB, "ClientId") == 0x40); + assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x50); + assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x58); + assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60); + assert(@offsetOf(TEB, "LastErrorValue") == 0x68); + assert(@offsetOf(TEB, "TlsSlots") == 0x1480); + } } } |
