authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-06-26 02:48:03+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-29 09:50:41+02:00
log890433e292da449e79c5a8c2efb91f65555da775
tree458ce0f353eaee091e8ea35c0fc8450dcb336629
parentcafce8c7670e90969b1bedae0efab3df583b11dd
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.os.linux: Define timespec as kernel_timespec (64-bit) for riscv32.

This is kind of a hack because the timespec in UAPI headers is actually still 32-bit while __kernel_timespec is 64-bit. But, importantly, all the syscalls take __kernel_timespec from the get-go (because riscv32 support is so recent). Defining our timespec this way will allow all the syscall wrappers in std.os.linux to do the right thing for riscv32. For other 32-bit architectures, we have to use the 64-bit time syscalls explicitly to solve the Y2038 problem.

1 files changed, 3 insertions(+), 2 deletions(-)

lib/std/os/linux.zig+3-2
......@@ -6327,12 +6327,13 @@ pub const POSIX_FADV = switch (native_arch) {
63276327};
63286328
63296329/// The timespec struct used by the kernel.
6330pub const kernel_timespec = if (@sizeOf(usize) >= 8) timespec else extern struct {
6330pub const kernel_timespec = extern struct {
63316331 sec: i64,
63326332 nsec: i64,
63336333};
63346334
6335pub const timespec = extern struct {
6335// https://github.com/ziglang/zig/issues/4726#issuecomment-2190337877
6336pub const timespec = if (!builtin.link_libc and native_arch == .riscv32) kernel_timespec else extern struct {
63366337 sec: isize,
63376338 nsec: isize,
63386339};