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");...@@ -15,8 +15,10 @@ const dl = @import("../dynamic_library.zig");
15const native_arch = builtin.cpu.arch;15const native_arch = builtin.cpu.arch;
16const native_abi = builtin.abi;16const native_abi = builtin.abi;
17const native_endian = native_arch.endian();17const native_endian = native_arch.endian();
18const is_loongarch = native_arch.isLoongArch();
18const is_mips = native_arch.isMIPS();19const is_mips = native_arch.isMIPS();
19const is_ppc = native_arch.isPowerPC();20const is_ppc = native_arch.isPowerPC();
21const is_riscv = native_arch.isRISCV();
20const is_sparc = native_arch.isSPARC();22const is_sparc = native_arch.isSPARC();
21const iovec = std.posix.iovec;23const iovec = std.posix.iovec;
22const iovec_const = std.posix.iovec_const;24const iovec_const = std.posix.iovec_const;
...@@ -1868,15 +1870,23 @@ pub fn sigaction(sig: u8, noalias act: ?*const Sigaction, noalias oact: ?*Sigact...@@ -1868,15 +1870,23 @@ pub fn sigaction(sig: u8, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
1868 const mask_size = @sizeOf(@TypeOf(ksa.mask));1870 const mask_size = @sizeOf(@TypeOf(ksa.mask));
18691871
1870 if (act) |new| {1872 if (act) |new| {
1871 // Zig needs to install our arch restorer function with any signal handler, so1873 if (native_arch == .hexagon or is_loongarch or is_mips or is_riscv) {
1872 // must copy the Sigaction struct1874 ksa = .{
1873 const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) &restore_rt else &restore;1875 .handler = new.handler.handler,
1874 ksa = k_sigaction{1876 .flags = new.flags,
1875 .handler = new.handler.handler,1877 .mask = new.mask,
1876 .flags = new.flags | SA.RESTORER,1878 };
1877 .mask = new.mask,1879 } else {
1878 .restorer = @ptrCast(restorer_fn),1880 // Zig needs to install our arch restorer function with any signal handler, so
1879 };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 }
1880 }1890 }
18811891
1882 const ksa_arg = if (act != null) @intFromPtr(&ksa) else 0;1892 const ksa_arg = if (act != null) @intFromPtr(&ksa) else 0;
...@@ -3668,7 +3678,6 @@ pub const SA = if (is_mips) struct {...@@ -3668,7 +3678,6 @@ pub const SA = if (is_mips) struct {
3668 pub const RESETHAND = 0x80000000;3678 pub const RESETHAND = 0x80000000;
3669 pub const ONSTACK = 0x08000000;3679 pub const ONSTACK = 0x08000000;
3670 pub const NODEFER = 0x40000000;3680 pub const NODEFER = 0x40000000;
3671 pub const RESTORER = 0x04000000;
3672} else if (is_sparc) struct {3681} else if (is_sparc) struct {
3673 pub const NOCLDSTOP = 0x8;3682 pub const NOCLDSTOP = 0x8;
3674 pub const NOCLDWAIT = 0x100;3683 pub const NOCLDWAIT = 0x100;
...@@ -3678,6 +3687,14 @@ pub const SA = if (is_mips) struct {...@@ -3678,6 +3687,14 @@ pub const SA = if (is_mips) struct {
3678 pub const ONSTACK = 0x1;3687 pub const ONSTACK = 0x1;
3679 pub const NODEFER = 0x20;3688 pub const NODEFER = 0x20;
3680 pub const RESTORER = 0x04000000;3689 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;
3681} else struct {3698} else struct {
3682 pub const NOCLDSTOP = 1;3699 pub const NOCLDSTOP = 1;
3683 pub const NOCLDWAIT = 2;3700 pub const NOCLDWAIT = 2;
...@@ -5743,13 +5760,18 @@ const k_sigaction_funcs = struct {...@@ -5743,13 +5760,18 @@ const k_sigaction_funcs = struct {
5743 const restorer = *const fn () callconv(.c) void;5760 const restorer = *const fn () callconv(.c) void;
5744};5761};
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`.
5747pub const k_sigaction = switch (native_arch) {5765pub const k_sigaction = switch (native_arch) {
5748 .mips, .mipsel, .mips64, .mips64el => extern struct {5766 .mips, .mipsel, .mips64, .mips64el => extern struct {
5749 flags: c_uint,5767 flags: c_uint,
5750 handler: k_sigaction_funcs.handler,5768 handler: k_sigaction_funcs.handler,
5751 mask: sigset_t,5769 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,
5753 },5775 },
5754 else => extern struct {5776 else => extern struct {
5755 handler: k_sigaction_funcs.handler,5777 handler: k_sigaction_funcs.handler,