Skip to content
/ zig Public
forked from ziglang/zig

Commit

Permalink
std.os.linux: Define timespec as kernel_timespec (64-bit) for riscv32.
Browse files Browse the repository at this point in the history
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.
See issue ziglang#4726 for that.
  • Loading branch information
alexrp committed Jun 26, 2024
1 parent bae50f3 commit 6eba159
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/std/os/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6113,12 +6113,13 @@ pub const POSIX_FADV = switch (native_arch) {
};

/// The timespec struct used by the kernel.
pub const kernel_timespec = if (@sizeOf(usize) >= 8) timespec else extern struct {
pub const kernel_timespec = extern struct {
tv_sec: i64,
tv_nsec: i64,
};

pub const timespec = extern struct {
// TODO: This is a temporary hack until we figure out a coherent Y2038 strategy.
pub const timespec = if (!builtin.link_libc and native_arch == .riscv32) kernel_timespec else extern struct {
tv_sec: isize,
tv_nsec: isize,
};
Expand Down

0 comments on commit 6eba159

Please sign in to comment.