authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-31 20:39:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-31 20:39:47-07:00
logfc23fe90ce1f3d28841c5a5a93a8bdf7edaefc54
treec5d5264758254f7c419141006a6ec3676fbe8b00
parentec36e0609fb97fef96e72fb76f5515b751519a61

std.os.windows: avoid dragging in baggage on non-windows

particularly noticeable when usize is not 4 or 8 bytes

1 files changed, 22 insertions(+), 19 deletions(-)

lib/std/os/windows.zig+22-19
......@@ -4621,25 +4621,28 @@ pub const TEB = extern struct {
46214621};
46224622
46234623comptime {
4624 // Offsets taken from WinDbg info and Geoff Chappell[1] (RIP)
4625 // [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm
4626 assert(@offsetOf(TEB, "NtTib") == 0x00);
4627 if (@sizeOf(usize) == 4) {
4628 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x1C);
4629 assert(@offsetOf(TEB, "ClientId") == 0x20);
4630 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x28);
4631 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x2C);
4632 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30);
4633 assert(@offsetOf(TEB, "LastErrorValue") == 0x34);
4634 assert(@offsetOf(TEB, "TlsSlots") == 0xe10);
4635 } else if (@sizeOf(usize) == 8) {
4636 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x38);
4637 assert(@offsetOf(TEB, "ClientId") == 0x40);
4638 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x50);
4639 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x58);
4640 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60);
4641 assert(@offsetOf(TEB, "LastErrorValue") == 0x68);
4642 assert(@offsetOf(TEB, "TlsSlots") == 0x1480);
4624 // This file may be referenced for its error sets, so we must not assume target windows here.
4625 if (builtin.os.tag == .windows) {
4626 // Offsets taken from WinDbg info and Geoff Chappell[1] (RIP)
4627 // [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm
4628 assert(@offsetOf(TEB, "NtTib") == 0x00);
4629 if (@sizeOf(usize) == 4) {
4630 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x1C);
4631 assert(@offsetOf(TEB, "ClientId") == 0x20);
4632 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x28);
4633 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x2C);
4634 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30);
4635 assert(@offsetOf(TEB, "LastErrorValue") == 0x34);
4636 assert(@offsetOf(TEB, "TlsSlots") == 0xe10);
4637 } else if (@sizeOf(usize) == 8) {
4638 assert(@offsetOf(TEB, "EnvironmentPointer") == 0x38);
4639 assert(@offsetOf(TEB, "ClientId") == 0x40);
4640 assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x50);
4641 assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x58);
4642 assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60);
4643 assert(@offsetOf(TEB, "LastErrorValue") == 0x68);
4644 assert(@offsetOf(TEB, "TlsSlots") == 0x1480);
4645 }
46434646 }
46444647}
46454648