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

particularly noticeable when usize is not 4 or 8 bytes
This commit is contained in:
Andrew Kelley 2025-08-31 20:39:33 -07:00
parent ec36e0609f
commit fc23fe90ce

View file

@ -4621,25 +4621,28 @@ pub const TEB = extern struct {
}; };
comptime { comptime {
// Offsets taken from WinDbg info and Geoff Chappell[1] (RIP) // This file may be referenced for its error sets, so we must not assume target windows here.
// [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm if (builtin.os.tag == .windows) {
assert(@offsetOf(TEB, "NtTib") == 0x00); // Offsets taken from WinDbg info and Geoff Chappell[1] (RIP)
if (@sizeOf(usize) == 4) { // [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm
assert(@offsetOf(TEB, "EnvironmentPointer") == 0x1C); assert(@offsetOf(TEB, "NtTib") == 0x00);
assert(@offsetOf(TEB, "ClientId") == 0x20); if (@sizeOf(usize) == 4) {
assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x28); assert(@offsetOf(TEB, "EnvironmentPointer") == 0x1C);
assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x2C); assert(@offsetOf(TEB, "ClientId") == 0x20);
assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30); assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x28);
assert(@offsetOf(TEB, "LastErrorValue") == 0x34); assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x2C);
assert(@offsetOf(TEB, "TlsSlots") == 0xe10); assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x30);
} else if (@sizeOf(usize) == 8) { assert(@offsetOf(TEB, "LastErrorValue") == 0x34);
assert(@offsetOf(TEB, "EnvironmentPointer") == 0x38); assert(@offsetOf(TEB, "TlsSlots") == 0xe10);
assert(@offsetOf(TEB, "ClientId") == 0x40); } else if (@sizeOf(usize) == 8) {
assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x50); assert(@offsetOf(TEB, "EnvironmentPointer") == 0x38);
assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x58); assert(@offsetOf(TEB, "ClientId") == 0x40);
assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60); assert(@offsetOf(TEB, "ActiveRpcHandle") == 0x50);
assert(@offsetOf(TEB, "LastErrorValue") == 0x68); assert(@offsetOf(TEB, "ThreadLocalStoragePointer") == 0x58);
assert(@offsetOf(TEB, "TlsSlots") == 0x1480); assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60);
assert(@offsetOf(TEB, "LastErrorValue") == 0x68);
assert(@offsetOf(TEB, "TlsSlots") == 0x1480);
}
} }
} }