authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-28 16:12:29+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-28 18:23:58+02:00
log42e441137765f1d2edba06e9d66e8ff905e225fb
tree7f3fa098097e55e235a97926dd758b0b07c2aa38
parentba19c1104bab8cea50eff7fbdf3b04ca33891d0b
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.os.linux: delete SA.RESTORER and k_sigaction.restorer for hexagon, loongarch, mips, riscv

The kABIs for these architectures don't define these concepts.

1 files changed, 34 insertions(+), 12 deletions(-)

lib/std/os/linux.zig+34-12
......@@ -15,8 +15,10 @@ const dl = @import("../dynamic_library.zig");
1515const native_arch = builtin.cpu.arch;
1616const native_abi = builtin.abi;
1717const native_endian = native_arch.endian();
18const is_loongarch = native_arch.isLoongArch();
1819const is_mips = native_arch.isMIPS();
1920const is_ppc = native_arch.isPowerPC();
21const is_riscv = native_arch.isRISCV();
2022const is_sparc = native_arch.isSPARC();
2123const iovec = std.posix.iovec;
2224const iovec_const = std.posix.iovec_const;
......@@ -1868,15 +1870,23 @@ pub fn sigaction(sig: u8, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
18681870 const mask_size = @sizeOf(@TypeOf(ksa.mask));
18691871
18701872 if (act) |new| {
1871 // Zig needs to install our arch restorer function with any signal handler, so
1872 // must copy the Sigaction struct
1873 const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) &restore_rt else &restore;
1874 ksa = k_sigaction{
1875 .handler = new.handler.handler,
1876 .flags = new.flags | SA.RESTORER,
1877 .mask = new.mask,
1878 .restorer = @ptrCast(restorer_fn),
1879 };
1873 if (native_arch == .hexagon or is_loongarch or is_mips or is_riscv) {
1874 ksa = .{
1875 .handler = new.handler.handler,
1876 .flags = new.flags,
1877 .mask = new.mask,
1878 };
1879 } else {
1880 // Zig needs to install our arch restorer function with any signal handler, so
1881 // must copy the Sigaction struct
1882 const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) &restore_rt else &restore;
1883 ksa = .{
1884 .handler = new.handler.handler,
1885 .flags = new.flags | SA.RESTORER,
1886 .mask = new.mask,
1887 .restorer = @ptrCast(restorer_fn),
1888 };
1889 }
18801890 }
18811891
18821892 const ksa_arg = if (act != null) @intFromPtr(&ksa) else 0;
......@@ -3668,7 +3678,6 @@ pub const SA = if (is_mips) struct {
36683678 pub const RESETHAND = 0x80000000;
36693679 pub const ONSTACK = 0x08000000;
36703680 pub const NODEFER = 0x40000000;
3671 pub const RESTORER = 0x04000000;
36723681} else if (is_sparc) struct {
36733682 pub const NOCLDSTOP = 0x8;
36743683 pub const NOCLDWAIT = 0x100;
......@@ -3678,6 +3687,14 @@ pub const SA = if (is_mips) struct {
36783687 pub const ONSTACK = 0x1;
36793688 pub const NODEFER = 0x20;
36803689 pub const RESTORER = 0x04000000;
3690} else if (native_arch == .hexagon or is_loongarch or is_riscv) struct {
3691 pub const NOCLDSTOP = 1;
3692 pub const NOCLDWAIT = 2;
3693 pub const SIGINFO = 4;
3694 pub const RESTART = 0x10000000;
3695 pub const RESETHAND = 0x80000000;
3696 pub const ONSTACK = 0x08000000;
3697 pub const NODEFER = 0x40000000;
36813698} else struct {
36823699 pub const NOCLDSTOP = 1;
36833700 pub const NOCLDWAIT = 2;
......@@ -5743,13 +5760,18 @@ const k_sigaction_funcs = struct {
57435760 const restorer = *const fn () callconv(.c) void;
57445761};
57455762
5746/// Kernel sigaction struct, as expected by the `rt_sigaction` syscall. Includes restorer.
5763/// Kernel sigaction struct, as expected by the `rt_sigaction` syscall. Includes `restorer` on
5764/// targets where userspace is responsible for hooking up `rt_sigreturn`.
57475765pub const k_sigaction = switch (native_arch) {
57485766 .mips, .mipsel, .mips64, .mips64el => extern struct {
57495767 flags: c_uint,
57505768 handler: k_sigaction_funcs.handler,
57515769 mask: sigset_t,
5752 restorer: k_sigaction_funcs.restorer,
5770 },
5771 .hexagon, .loongarch32, .loongarch64, .riscv32, .riscv64 => extern struct {
5772 handler: k_sigaction_funcs.handler,
5773 flags: c_ulong,
5774 mask: sigset_t,
57535775 },
57545776 else => extern struct {
57555777 handler: k_sigaction_funcs.handler,