Skip to content

Commit 51156d4

Browse files
committed
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 parent d0d7a87 commit 51156d4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/std/os/linux.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6264,12 +6264,13 @@ pub const POSIX_FADV = switch (native_arch) {
62646264
};
62656265

62666266
/// The timespec struct used by the kernel.
6267-
pub const kernel_timespec = if (@sizeOf(usize) >= 8) timespec else extern struct {
6267+
pub const kernel_timespec = extern struct {
62686268
sec: i64,
62696269
nsec: i64,
62706270
};
62716271

6272-
pub const timespec = extern struct {
6272+
// https://github.com/ziglang/zig/issues/4726#issuecomment-2190337877
6273+
pub const timespec = if (!builtin.link_libc and native_arch == .riscv32) kernel_timespec else extern struct {
62736274
sec: isize,
62746275
nsec: isize,
62756276
};

0 commit comments

Comments
 (0)