| author | |
| committer | |
| log | f624191f9a759c0d310f3615c10dbfbbc6ae511e |
| tree | 78a8231fb05e38cfa91cfe41b1f7875617032128 |
| parent | f90510b081e06449ab0bd97a1254c78f5be6a8d4 |
| parent | fe468e4fa3538ad4de7c890b4d971f74092d9f7b |
| signature |
`std.os.linux`: Fix `k_sigaction` ABI issue on platforms w/o `SA_RESTORER`14 files changed, 34 insertions(+), 132 deletions(-)
lib/libc/musl/arch/hexagon/bits/signal.h-1| ... | ... | @@ -61,7 +61,6 @@ typedef struct __ucontext { |
| 61 | 61 | #define SA_RESTART 0x10000000 |
| 62 | 62 | #define SA_NODEFER 0x40000000 |
| 63 | 63 | #define SA_RESETHAND 0x80000000 |
| 64 | #define SA_RESTORER 0x04000000 | |
| 65 | 64 | |
| 66 | 65 | #endif |
| 67 | 66 |
lib/libc/musl/arch/riscv32/bits/signal.h-1| ... | ... | @@ -78,7 +78,6 @@ typedef struct __ucontext |
| 78 | 78 | #define SA_RESTART 0x10000000 |
| 79 | 79 | #define SA_NODEFER 0x40000000 |
| 80 | 80 | #define SA_RESETHAND 0x80000000 |
| 81 | #define SA_RESTORER 0x04000000 | |
| 82 | 81 | |
| 83 | 82 | #endif |
| 84 | 83 |
lib/libc/musl/src/signal/hexagon/restore.s deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | // TODO - Test this if sa_restorer is ever supported in our kernel | |
| 2 | .global __restore | |
| 3 | .type __restore,%function | |
| 4 | .global __restore_rt | |
| 5 | .type __restore_rt,%function | |
| 6 | __restore: | |
| 7 | __restore_rt: | |
| 8 | 	r6 = #139				// SYS_rt_sigreturn | |
| 9 | 	trap0(#0) | |
| 10 | .size __restore, .-__restore | |
| 11 | .size __restore_rt, .-__restore_rt |
lib/libc/musl/src/signal/loongarch64/restore.s deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | .global __restore_rt | |
| 2 | .global __restore | |
| 3 | .hidden __restore_rt | |
| 4 | .hidden __restore | |
| 5 | .type __restore_rt,@function | |
| 6 | .type __restore,@function | |
| 7 | __restore_rt: | |
| 8 | __restore: | |
| 9 | 	li.w $a7, 139 | |
| 10 | 	syscall 0 |
lib/libc/musl/src/signal/riscv32/restore.s deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | .global __restore | |
| 2 | .hidden __restore | |
| 3 | .type __restore, %function | |
| 4 | __restore: | |
| 5 | .global __restore_rt | |
| 6 | .hidden __restore_rt | |
| 7 | .type __restore_rt, %function | |
| 8 | __restore_rt: | |
| 9 | 	li a7, 139 # SYS_rt_sigreturn | |
| 10 | 	ecall |
lib/libc/musl/src/signal/riscv64/restore.s deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | .global __restore | |
| 2 | .hidden __restore | |
| 3 | .type __restore, %function | |
| 4 | __restore: | |
| 5 | .global __restore_rt | |
| 6 | .hidden __restore_rt | |
| 7 | .type __restore_rt, %function | |
| 8 | __restore_rt: | |
| 9 | 	li a7, 139 # SYS_rt_sigreturn | |
| 10 | 	ecall |
lib/std/os/linux.zig+34-12| ... | ... | @@ -15,8 +15,10 @@ const dl = @import("../dynamic_library.zig"); |
| 15 | 15 | const native_arch = builtin.cpu.arch; |
| 16 | 16 | const native_abi = builtin.abi; |
| 17 | 17 | const native_endian = native_arch.endian(); |
| 18 | const is_loongarch = native_arch.isLoongArch(); | |
| 18 | 19 | const is_mips = native_arch.isMIPS(); |
| 19 | 20 | const is_ppc = native_arch.isPowerPC(); |
| 21 | const is_riscv = native_arch.isRISCV(); | |
| 20 | 22 | const is_sparc = native_arch.isSPARC(); |
| 21 | 23 | const iovec = std.posix.iovec; |
| 22 | 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 | 1870 | const mask_size = @sizeOf(@TypeOf(ksa.mask)); |
| 1869 | 1871 | |
| 1870 | 1872 | 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 | } | |
| 1880 | 1890 | } |
| 1881 | 1891 | |
| 1882 | 1892 | const ksa_arg = if (act != null) @intFromPtr(&ksa) else 0; |
| ... | ... | @@ -3668,7 +3678,6 @@ pub const SA = if (is_mips) struct { |
| 3668 | 3678 | pub const RESETHAND = 0x80000000; |
| 3669 | 3679 | pub const ONSTACK = 0x08000000; |
| 3670 | 3680 | pub const NODEFER = 0x40000000; |
| 3671 | pub const RESTORER = 0x04000000; | |
| 3672 | 3681 | } else if (is_sparc) struct { |
| 3673 | 3682 | pub const NOCLDSTOP = 0x8; |
| 3674 | 3683 | pub const NOCLDWAIT = 0x100; |
| ... | ... | @@ -3678,6 +3687,14 @@ pub const SA = if (is_mips) struct { |
| 3678 | 3687 | pub const ONSTACK = 0x1; |
| 3679 | 3688 | pub const NODEFER = 0x20; |
| 3680 | 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 | 3698 | } else struct { |
| 3682 | 3699 | pub const NOCLDSTOP = 1; |
| 3683 | 3700 | pub const NOCLDWAIT = 2; |
| ... | ... | @@ -5743,13 +5760,18 @@ const k_sigaction_funcs = struct { |
| 5743 | 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 | 5765 | pub const k_sigaction = switch (native_arch) { |
| 5748 | 5766 | .mips, .mipsel, .mips64, .mips64el => extern struct { |
| 5749 | 5767 | flags: c_uint, |
| 5750 | 5768 | handler: k_sigaction_funcs.handler, |
| 5751 | 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 | 5776 | else => extern struct { |
| 5755 | 5777 | handler: k_sigaction_funcs.handler, |
lib/std/os/linux/hexagon.zig-10| ... | ... | @@ -128,16 +128,6 @@ pub fn clone() callconv(.naked) usize { |
| 128 | 128 | ); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | pub const restore = restore_rt; | |
| 132 | ||
| 133 | pub fn restore_rt() callconv(.naked) noreturn { | |
| 134 | asm volatile ( | |
| 135 | \\ trap0(#0) | |
| 136 | : | |
| 137 | : [number] "{r6}" (@intFromEnum(SYS.rt_sigreturn)), | |
| 138 | ); | |
| 139 | } | |
| 140 | ||
| 141 | 131 | pub const F = struct { |
| 142 | 132 | pub const DUPFD = 0; |
| 143 | 133 | pub const GETFD = 1; |
lib/std/os/linux/loongarch64.zig-11| ... | ... | @@ -135,17 +135,6 @@ pub fn clone() callconv(.naked) usize { |
| 135 | 135 | ); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | pub const restore = restore_rt; | |
| 139 | ||
| 140 | pub fn restore_rt() callconv(.naked) noreturn { | |
| 141 | asm volatile ( | |
| 142 | \\ or $a7, $zero, %[number] | |
| 143 | \\ syscall 0 | |
| 144 | : | |
| 145 | : [number] "r" (@intFromEnum(SYS.rt_sigreturn)), | |
| 146 | ); | |
| 147 | } | |
| 148 | ||
| 149 | 138 | pub const msghdr = extern struct { |
| 150 | 139 | name: ?*sockaddr, |
| 151 | 140 | namelen: socklen_t, |
lib/std/os/linux/mips.zig-16| ... | ... | @@ -241,22 +241,6 @@ pub fn clone() callconv(.naked) usize { |
| 241 | 241 | ); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | pub fn restore() callconv(.naked) noreturn { | |
| 245 | asm volatile ( | |
| 246 | \\ syscall | |
| 247 | : | |
| 248 | : [number] "{$2}" (@intFromEnum(SYS.sigreturn)), | |
| 249 | : .{ .r1 = true, .r3 = true, .r4 = true, .r5 = true, .r6 = true, .r7 = true, .r8 = true, .r9 = true, .r10 = true, .r11 = true, .r12 = true, .r13 = true, .r14 = true, .r15 = true, .r24 = true, .r25 = true, .hi = true, .lo = true, .memory = true }); | |
| 250 | } | |
| 251 | ||
| 252 | pub fn restore_rt() callconv(.naked) noreturn { | |
| 253 | asm volatile ( | |
| 254 | \\ syscall | |
| 255 | : | |
| 256 | : [number] "{$2}" (@intFromEnum(SYS.rt_sigreturn)), | |
| 257 | ); | |
| 258 | } | |
| 259 | ||
| 260 | 244 | pub const F = struct { |
| 261 | 245 | pub const DUPFD = 0; |
| 262 | 246 | pub const GETFD = 1; |
lib/std/os/linux/mips64.zig-16| ... | ... | @@ -220,22 +220,6 @@ pub fn clone() callconv(.naked) usize { |
| 220 | 220 | ); |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | pub fn restore() callconv(.naked) noreturn { | |
| 224 | asm volatile ( | |
| 225 | \\ syscall | |
| 226 | : | |
| 227 | : [number] "{$2}" (@intFromEnum(SYS.rt_sigreturn)), | |
| 228 | : .{ .r1 = true, .r3 = true, .r4 = true, .r5 = true, .r6 = true, .r7 = true, .r8 = true, .r9 = true, .r10 = true, .r11 = true, .r12 = true, .r13 = true, .r14 = true, .r15 = true, .r24 = true, .r25 = true, .hi = true, .lo = true, .memory = true }); | |
| 229 | } | |
| 230 | ||
| 231 | pub fn restore_rt() callconv(.naked) noreturn { | |
| 232 | asm volatile ( | |
| 233 | \\ syscall | |
| 234 | : | |
| 235 | : [number] "{$2}" (@intFromEnum(SYS.rt_sigreturn)), | |
| 236 | ); | |
| 237 | } | |
| 238 | ||
| 239 | 223 | pub const F = struct { |
| 240 | 224 | pub const DUPFD = 0; |
| 241 | 225 | pub const GETFD = 1; |
lib/std/os/linux/riscv32.zig-10| ... | ... | @@ -135,16 +135,6 @@ pub fn clone() callconv(.naked) usize { |
| 135 | 135 | ); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | pub const restore = restore_rt; | |
| 139 | ||
| 140 | pub fn restore_rt() callconv(.naked) noreturn { | |
| 141 | asm volatile ( | |
| 142 | \\ ecall | |
| 143 | : | |
| 144 | : [number] "{x17}" (@intFromEnum(SYS.rt_sigreturn)), | |
| 145 | ); | |
| 146 | } | |
| 147 | ||
| 148 | 138 | pub const F = struct { |
| 149 | 139 | pub const DUPFD = 0; |
| 150 | 140 | pub const GETFD = 1; |
lib/std/os/linux/riscv64.zig-10| ... | ... | @@ -135,16 +135,6 @@ pub fn clone() callconv(.naked) usize { |
| 135 | 135 | ); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | pub const restore = restore_rt; | |
| 139 | ||
| 140 | pub fn restore_rt() callconv(.naked) noreturn { | |
| 141 | asm volatile ( | |
| 142 | \\ ecall | |
| 143 | : | |
| 144 | : [number] "{x17}" (@intFromEnum(SYS.rt_sigreturn)), | |
| 145 | ); | |
| 146 | } | |
| 147 | ||
| 148 | 138 | pub const F = struct { |
| 149 | 139 | pub const DUPFD = 0; |
| 150 | 140 | pub const GETFD = 1; |
src/libs/musl.zig-4| ... | ... | @@ -1538,13 +1538,11 @@ const src_files = [_][]const u8{ |
| 1538 | 1538 | "musl/src/signal/arm/sigsetjmp.s", |
| 1539 | 1539 | "musl/src/signal/block.c", |
| 1540 | 1540 | "musl/src/signal/getitimer.c", |
| 1541 | "musl/src/signal/hexagon/restore.s", | |
| 1542 | 1541 | "musl/src/signal/hexagon/sigsetjmp.s", |
| 1543 | 1542 | "musl/src/signal/i386/restore.s", |
| 1544 | 1543 | "musl/src/signal/i386/sigsetjmp.s", |
| 1545 | 1544 | "musl/src/signal/kill.c", |
| 1546 | 1545 | "musl/src/signal/killpg.c", |
| 1547 | "musl/src/signal/loongarch64/restore.s", | |
| 1548 | 1546 | "musl/src/signal/loongarch64/sigsetjmp.s", |
| 1549 | 1547 | "musl/src/signal/m68k/sigsetjmp.s", |
| 1550 | 1548 | "musl/src/signal/mips64/sigsetjmp.s", |
| ... | ... | @@ -1558,9 +1556,7 @@ const src_files = [_][]const u8{ |
| 1558 | 1556 | "musl/src/signal/psignal.c", |
| 1559 | 1557 | "musl/src/signal/raise.c", |
| 1560 | 1558 | "musl/src/signal/restore.c", |
| 1561 | "musl/src/signal/riscv32/restore.s", | |
| 1562 | 1559 | "musl/src/signal/riscv32/sigsetjmp.s", |
| 1563 | "musl/src/signal/riscv64/restore.s", | |
| 1564 | 1560 | "musl/src/signal/riscv64/sigsetjmp.s", |
| 1565 | 1561 | "musl/src/signal/s390x/restore.s", |
| 1566 | 1562 | "musl/src/signal/s390x/sigsetjmp.s", |