authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-16 22:12:22+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-16 22:12:42+02:00
log05b52da15eab66713beb867cbcfc52d8b53ca10b
tree1c7f1e9bb8ba1af68723e3e497600fded6faf94d
parent3b5376eff53964526bceb083bc6cc60a081d7f71
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.os.linux: fix a bunch of syscall and time ABI issues on hexagon

I'm not particularly happy with sprinkling this check everywhere, but the situation should improve once we complete the time64 migration.

2 files changed, 18 insertions(+), 17 deletions(-)

lib/std/os/linux.zig+17-16
...@@ -533,9 +533,10 @@ fn getauxvalImpl(index: usize) callconv(.c) usize {...@@ -533,9 +533,10 @@ fn getauxvalImpl(index: usize) callconv(.c) usize {
533// Some architectures (and some syscalls) require 64bit parameters to be passed533// Some architectures (and some syscalls) require 64bit parameters to be passed
534// in a even-aligned register pair.534// in a even-aligned register pair.
535const require_aligned_register_pair =535const require_aligned_register_pair =
536 builtin.cpu.arch.isPowerPC32() or536 builtin.cpu.arch.isArm() or
537 builtin.cpu.arch == .hexagon or
537 builtin.cpu.arch.isMIPS32() or538 builtin.cpu.arch.isMIPS32() or
538 builtin.cpu.arch.isArm();539 builtin.cpu.arch.isPowerPC32();
539540
540// Split a 64bit value into a {LSB,MSB} pair.541// Split a 64bit value into a {LSB,MSB} pair.
541// The LE/BE variants specify the endianness to assume.542// The LE/BE variants specify the endianness to assume.
...@@ -640,7 +641,7 @@ pub fn futimens(fd: i32, times: ?*const [2]timespec) usize {...@@ -640,7 +641,7 @@ pub fn futimens(fd: i32, times: ?*const [2]timespec) usize {
640641
641pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: ?*const [2]timespec, flags: u32) usize {642pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: ?*const [2]timespec, flags: u32) usize {
642 return syscall4(643 return syscall4(
643 if (@hasField(SYS, "utimensat")) .utimensat else .utimensat_time64,644 if (@hasField(SYS, "utimensat") and native_arch != .hexagon) .utimensat else .utimensat_time64,
644 @as(usize, @bitCast(@as(isize, dirfd))),645 @as(usize, @bitCast(@as(isize, dirfd))),
645 @intFromPtr(path),646 @intFromPtr(path),
646 @intFromPtr(times),647 @intFromPtr(times),
...@@ -688,7 +689,7 @@ pub const futex_param4 = extern union {...@@ -688,7 +689,7 @@ pub const futex_param4 = extern union {
688/// defines which of the subsequent paramters are relevant.689/// defines which of the subsequent paramters are relevant.
689pub fn futex(uaddr: *const anyopaque, futex_op: FUTEX_OP, val: u32, val2timeout: futex_param4, uaddr2: ?*const anyopaque, val3: u32) usize {690pub fn futex(uaddr: *const anyopaque, futex_op: FUTEX_OP, val: u32, val2timeout: futex_param4, uaddr2: ?*const anyopaque, val3: u32) usize {
690 return syscall6(691 return syscall6(
691 if (@hasField(SYS, "futex")) .futex else .futex_time64,692 if (@hasField(SYS, "futex") and native_arch != .hexagon) .futex else .futex_time64,
692 @intFromPtr(uaddr),693 @intFromPtr(uaddr),
693 @as(u32, @bitCast(futex_op)),694 @as(u32, @bitCast(futex_op)),
694 val,695 val,
...@@ -702,7 +703,7 @@ pub fn futex(uaddr: *const anyopaque, futex_op: FUTEX_OP, val: u32, val2timeout:...@@ -702,7 +703,7 @@ pub fn futex(uaddr: *const anyopaque, futex_op: FUTEX_OP, val: u32, val2timeout:
702/// futex_op that ignores the remaining arguments (e.g., FUTUX_OP.WAKE).703/// futex_op that ignores the remaining arguments (e.g., FUTUX_OP.WAKE).
703pub fn futex_3arg(uaddr: *const anyopaque, futex_op: FUTEX_OP, val: u32) usize {704pub fn futex_3arg(uaddr: *const anyopaque, futex_op: FUTEX_OP, val: u32) usize {
704 return syscall3(705 return syscall3(
705 if (@hasField(SYS, "futex")) .futex else .futex_time64,706 if (@hasField(SYS, "futex") and native_arch != .hexagon) .futex else .futex_time64,
706 @intFromPtr(uaddr),707 @intFromPtr(uaddr),
707 @as(u32, @bitCast(futex_op)),708 @as(u32, @bitCast(futex_op)),
708 val,709 val,
...@@ -713,7 +714,7 @@ pub fn futex_3arg(uaddr: *const anyopaque, futex_op: FUTEX_OP, val: u32) usize {...@@ -713,7 +714,7 @@ pub fn futex_3arg(uaddr: *const anyopaque, futex_op: FUTEX_OP, val: u32) usize {
713/// futex_op that ignores the remaining arguments (e.g., FUTEX_OP.WAIT).714/// futex_op that ignores the remaining arguments (e.g., FUTEX_OP.WAIT).
714pub fn futex_4arg(uaddr: *const anyopaque, futex_op: FUTEX_OP, val: u32, timeout: ?*const timespec) usize {715pub fn futex_4arg(uaddr: *const anyopaque, futex_op: FUTEX_OP, val: u32, timeout: ?*const timespec) usize {
715 return syscall4(716 return syscall4(
716 if (@hasField(SYS, "futex")) .futex else .futex_time64,717 if (@hasField(SYS, "futex") and native_arch != .hexagon) .futex else .futex_time64,
717 @intFromPtr(uaddr),718 @intFromPtr(uaddr),
718 @as(u32, @bitCast(futex_op)),719 @as(u32, @bitCast(futex_op)),
719 val,720 val,
...@@ -1093,7 +1094,7 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {...@@ -1093,7 +1094,7 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
10931094
1094pub fn ppoll(fds: [*]pollfd, n: nfds_t, timeout: ?*timespec, sigmask: ?*const sigset_t) usize {1095pub fn ppoll(fds: [*]pollfd, n: nfds_t, timeout: ?*timespec, sigmask: ?*const sigset_t) usize {
1095 return syscall5(1096 return syscall5(
1096 if (@hasField(SYS, "ppoll")) .ppoll else .ppoll_time64,1097 if (@hasField(SYS, "ppoll") and native_arch != .hexagon) .ppoll else .ppoll_time64,
1097 @intFromPtr(fds),1098 @intFromPtr(fds),
1098 n,1099 n,
1099 @intFromPtr(timeout),1100 @intFromPtr(timeout),
...@@ -1627,7 +1628,7 @@ pub fn clock_gettime(clk_id: clockid_t, tp: *timespec) usize {...@@ -1627,7 +1628,7 @@ pub fn clock_gettime(clk_id: clockid_t, tp: *timespec) usize {
1627 }1628 }
1628 }1629 }
1629 return syscall2(1630 return syscall2(
1630 if (@hasField(SYS, "clock_gettime")) .clock_gettime else .clock_gettime64,1631 if (@hasField(SYS, "clock_gettime") and native_arch != .hexagon) .clock_gettime else .clock_gettime64,
1631 @intFromEnum(clk_id),1632 @intFromEnum(clk_id),
1632 @intFromPtr(tp),1633 @intFromPtr(tp),
1633 );1634 );
...@@ -1645,7 +1646,7 @@ fn init_vdso_clock_gettime(clk: clockid_t, ts: *timespec) callconv(.c) usize {...@@ -1645,7 +1646,7 @@ fn init_vdso_clock_gettime(clk: clockid_t, ts: *timespec) callconv(.c) usize {
16451646
1646pub fn clock_getres(clk_id: i32, tp: *timespec) usize {1647pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
1647 return syscall2(1648 return syscall2(
1648 if (@hasField(SYS, "clock_getres")) .clock_getres else .clock_getres_time64,1649 if (@hasField(SYS, "clock_getres") and native_arch != .hexagon) .clock_getres else .clock_getres_time64,
1649 @as(usize, @bitCast(@as(isize, clk_id))),1650 @as(usize, @bitCast(@as(isize, clk_id))),
1650 @intFromPtr(tp),1651 @intFromPtr(tp),
1651 );1652 );
...@@ -1653,7 +1654,7 @@ pub fn clock_getres(clk_id: i32, tp: *timespec) usize {...@@ -1653,7 +1654,7 @@ pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
16531654
1654pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {1655pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {
1655 return syscall2(1656 return syscall2(
1656 if (@hasField(SYS, "clock_settime")) .clock_settime else .clock_settime64,1657 if (@hasField(SYS, "clock_settime") and native_arch != .hexagon) .clock_settime else .clock_settime64,
1657 @as(usize, @bitCast(@as(isize, clk_id))),1658 @as(usize, @bitCast(@as(isize, clk_id))),
1658 @intFromPtr(tp),1659 @intFromPtr(tp),
1659 );1660 );
...@@ -1661,7 +1662,7 @@ pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {...@@ -1661,7 +1662,7 @@ pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {
16611662
1662pub fn clock_nanosleep(clockid: clockid_t, flags: TIMER, request: *const timespec, remain: ?*timespec) usize {1663pub fn clock_nanosleep(clockid: clockid_t, flags: TIMER, request: *const timespec, remain: ?*timespec) usize {
1663 return syscall4(1664 return syscall4(
1664 if (@hasField(SYS, "clock_nanosleep")) .clock_nanosleep else .clock_nanosleep_time64,1665 if (@hasField(SYS, "clock_nanosleep") and native_arch != .hexagon) .clock_nanosleep else .clock_nanosleep_time64,
1665 @intFromEnum(clockid),1666 @intFromEnum(clockid),
1666 @as(u32, @bitCast(flags)),1667 @as(u32, @bitCast(flags)),
1667 @intFromPtr(request),1668 @intFromPtr(request),
...@@ -2071,7 +2072,7 @@ pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {...@@ -2071,7 +2072,7 @@ pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
20712072
2072pub fn recvmmsg(fd: i32, msgvec: ?[*]mmsghdr, vlen: u32, flags: u32, timeout: ?*timespec) usize {2073pub fn recvmmsg(fd: i32, msgvec: ?[*]mmsghdr, vlen: u32, flags: u32, timeout: ?*timespec) usize {
2073 return syscall5(2074 return syscall5(
2074 if (@hasField(SYS, "recvmmsg")) .recvmmsg else .recvmmsg_time64,2075 if (@hasField(SYS, "recvmmsg") and native_arch != .hexagon) .recvmmsg else .recvmmsg_time64,
2075 @as(usize, @bitCast(@as(isize, fd))),2076 @as(usize, @bitCast(@as(isize, fd))),
2076 @intFromPtr(msgvec),2077 @intFromPtr(msgvec),
2077 vlen,2078 vlen,
...@@ -2421,7 +2422,7 @@ pub const itimerspec = extern struct {...@@ -2421,7 +2422,7 @@ pub const itimerspec = extern struct {
24212422
2422pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {2423pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
2423 return syscall2(2424 return syscall2(
2424 if (@hasField(SYS, "timerfd_gettime")) .timerfd_gettime else .timerfd_gettime64,2425 if (@hasField(SYS, "timerfd_gettime") and native_arch != .hexagon) .timerfd_gettime else .timerfd_gettime64,
2425 @bitCast(@as(isize, fd)),2426 @bitCast(@as(isize, fd)),
2426 @intFromPtr(curr_value),2427 @intFromPtr(curr_value),
2427 );2428 );
...@@ -2429,7 +2430,7 @@ pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {...@@ -2429,7 +2430,7 @@ pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
24292430
2430pub fn timerfd_settime(fd: i32, flags: TFD.TIMER, new_value: *const itimerspec, old_value: ?*itimerspec) usize {2431pub fn timerfd_settime(fd: i32, flags: TFD.TIMER, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
2431 return syscall4(2432 return syscall4(
2432 if (@hasField(SYS, "timerfd_settime")) .timerfd_settime else .timerfd_settime64,2433 if (@hasField(SYS, "timerfd_settime") and native_arch != .hexagon) .timerfd_settime else .timerfd_settime64,
2433 @bitCast(@as(isize, fd)),2434 @bitCast(@as(isize, fd)),
2434 @as(u32, @bitCast(flags)),2435 @as(u32, @bitCast(flags)),
2435 @intFromPtr(new_value),2436 @intFromPtr(new_value),
...@@ -2632,7 +2633,7 @@ pub fn process_vm_writev(pid: pid_t, local: []const iovec_const, remote: []const...@@ -2632,7 +2633,7 @@ pub fn process_vm_writev(pid: pid_t, local: []const iovec_const, remote: []const
2632}2633}
26332634
2634pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {2635pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize {
2635 if (comptime native_arch.isArm() or native_arch.isPowerPC32()) {2636 if (comptime native_arch.isArm() or native_arch == .hexagon or native_arch.isPowerPC32()) {
2636 // These architectures reorder the arguments so that a register is not skipped to align the2637 // These architectures reorder the arguments so that a register is not skipped to align the
2637 // register number that `offset` is passed in.2638 // register number that `offset` is passed in.
26382639
...@@ -8367,7 +8368,7 @@ pub const kernel_timespec = extern struct {...@@ -8367,7 +8368,7 @@ pub const kernel_timespec = extern struct {
8367};8368};
83688369
8369// https://github.com/ziglang/zig/issues/4726#issuecomment-21903378778370// https://github.com/ziglang/zig/issues/4726#issuecomment-2190337877
8370pub const timespec = if (native_arch == .riscv32) kernel_timespec else extern struct {8371pub const timespec = if (native_arch == .hexagon or native_arch == .riscv32) kernel_timespec else extern struct {
8371 sec: isize,8372 sec: isize,
8372 nsec: isize,8373 nsec: isize,
8373};8374};
lib/std/os/linux/hexagon.zig+1-1
...@@ -170,7 +170,7 @@ pub const Flock = extern struct {...@@ -170,7 +170,7 @@ pub const Flock = extern struct {
170170
171pub const blksize_t = i32;171pub const blksize_t = i32;
172pub const nlink_t = u32;172pub const nlink_t = u32;
173pub const time_t = i32;173pub const time_t = i64;
174pub const mode_t = u32;174pub const mode_t = u32;
175pub const off_t = i64;175pub const off_t = i64;
176pub const ino_t = u64;176pub const ino_t = u64;