fix: make compiler_rt and std.Io.Writer compile on 16-bit platforms.

This commit is contained in:
GasInfinity 2025-10-27 11:17:48 +01:00
parent 914acf13cb
commit 55c0693c4a
No known key found for this signature in database
3 changed files with 24 additions and 21 deletions

View file

@ -74,7 +74,7 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul
const parts = math.frexp(a); const parts = math.frexp(a);
const significand_bits_adjusted_to_handle_smin = @as(i32, significand_bits) + const significand_bits_adjusted_to_handle_smin = @as(i32, significand_bits) +
@intFromBool(signedness == .signed and parts.exponent == 32 * result.len); @intFromBool(signedness == .signed and parts.exponent == 32 * result.len);
const exponent = @max(parts.exponent - significand_bits_adjusted_to_handle_smin, 0); const exponent: usize = @intCast(@max(parts.exponent - significand_bits_adjusted_to_handle_smin, 0));
const int: I = @intFromFloat(switch (exponent) { const int: I = @intFromFloat(switch (exponent) {
0 => a, 0 => a,
else => math.ldexp(parts.significand, significand_bits_adjusted_to_handle_smin), else => math.ldexp(parts.significand, significand_bits_adjusted_to_handle_smin),

View file

@ -604,7 +604,7 @@ pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {
@compileError("32 arguments max are supported per format call"); @compileError("32 arguments max are supported per format call");
} }
@setEvalBranchQuota(fmt.len * 1000); @setEvalBranchQuota(@as(comptime_int, fmt.len) * 1000); // NOTE: We're upcasting as 16-bit usize overflows.
comptime var arg_state: std.fmt.ArgState = .{ .args_len = fields_info.len }; comptime var arg_state: std.fmt.ArgState = .{ .args_len = fields_info.len };
comptime var i = 0; comptime var i = 0;
comptime var literal: []const u8 = ""; comptime var literal: []const u8 = "";

View file

@ -4634,25 +4634,28 @@ pub const TEB = extern struct {
}; };
comptime { comptime {
// Offsets taken from WinDbg info and Geoff Chappell[1] (RIP) // XXX: Without this check we cannot use `std.Io.Writer` on 16-bit platforms. `std.fmt.bufPrint` will hit the unreachable in `PEB.GdiHandleBuffer` without this guard.
// [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);
}
} }
} }