| ... | @@ -15,8 +15,10 @@ const dl = @import("../dynamic_library.zig"); | ... | @@ -15,8 +15,10 @@ const dl = @import("../dynamic_library.zig"); |
| 15 | const native_arch = builtin.cpu.arch; | 15 | const native_arch = builtin.cpu.arch; |
| 16 | const native_abi = builtin.abi; | 16 | const native_abi = builtin.abi; |
| 17 | const native_endian = native_arch.endian(); | 17 | const native_endian = native_arch.endian(); |
| | 18 | const is_loongarch = native_arch.isLoongArch(); |
| 18 | const is_mips = native_arch.isMIPS(); | 19 | const is_mips = native_arch.isMIPS(); |
| 19 | const is_ppc = native_arch.isPowerPC(); | 20 | const is_ppc = native_arch.isPowerPC(); |
| | 21 | const is_riscv = native_arch.isRISCV(); |
| 20 | const is_sparc = native_arch.isSPARC(); | 22 | const is_sparc = native_arch.isSPARC(); |
| 21 | const iovec = std.posix.iovec; | 23 | const iovec = std.posix.iovec; |
| 22 | const iovec_const = std.posix.iovec_const; | 24 | const 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)); |
| 1869 | | 1871 | |
| 1870 | if (act) |new| { | 1872 | if (act) |new| { |
| 1871 | // Zig needs to install our arch restorer function with any signal handler, so | 1873 | if (native_arch == .hexagon or is_loongarch or is_mips or is_riscv) { |
| 1872 | // must copy the Sigaction struct | 1874 | 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 | } |
| 1881 | | 1891 | |
| 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 | }; |
| 5745 | | 5762 | |
| 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`. |
| 5747 | pub const k_sigaction = switch (native_arch) { | 5765 | pub 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, |