| ... | ... | @@ -1080,12 +1080,19 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact |
| 1080 | 1080 | const mask_size = @sizeOf(@TypeOf(ksa.mask)); |
| 1081 | 1081 | |
| 1082 | 1082 | if (act) |new| { |
| 1083 | | const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) restore_rt else restore; |
| 1083 | const restore_rt_ptr = if (builtin.zig_backend == .stage1) restore_rt else &syscall_bits.restore_rt; |
| 1084 | // TODO https://github.com/ziglang/zig/issues/11227 |
| 1085 | const restore_ptr = if (builtin.zig_backend == .stage1) restore else switch (native_arch) { |
| 1086 | .arm, .thumb, .mips, .mipsel, .i386 => &syscall_bits.restore, |
| 1087 | .x86_64, .aarch64, .riscv64, .sparcv9, .powerpc, .powerpc64, .powerpc64le => &syscall_bits.restore_rt, |
| 1088 | else => unreachable, |
| 1089 | }; |
| 1090 | const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) restore_rt_ptr else restore_ptr; |
| 1084 | 1091 | ksa = k_sigaction{ |
| 1085 | 1092 | .handler = new.handler.handler, |
| 1086 | 1093 | .flags = new.flags | SA.RESTORER, |
| 1087 | 1094 | .mask = undefined, |
| 1088 | | .restorer = @ptrCast(fn () callconv(.C) void, restorer_fn), |
| 1095 | .restorer = @ptrCast(k_sigaction_funcs.restorer, restorer_fn), |
| 1089 | 1096 | }; |
| 1090 | 1097 | @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &new.mask), mask_size); |
| 1091 | 1098 | } |
| ... | ... | @@ -3047,39 +3054,55 @@ pub const sigset_t = [1024 / 32]u32; |
| 3047 | 3054 | pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len; |
| 3048 | 3055 | pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30; |
| 3049 | 3056 | |
| 3057 | const k_sigaction_funcs = if (builtin.zig_backend == .stage1) struct { |
| 3058 | const handler = ?fn (c_int) callconv(.C) void; |
| 3059 | const restorer = fn () callconv(.C) void; |
| 3060 | } else struct { |
| 3061 | const handler = ?*const fn (c_int) callconv(.C) void; |
| 3062 | const restorer = *const fn () callconv(.C) void; |
| 3063 | }; |
| 3064 | |
| 3050 | 3065 | pub const k_sigaction = switch (native_arch) { |
| 3051 | 3066 | .mips, .mipsel => extern struct { |
| 3052 | 3067 | flags: c_uint, |
| 3053 | | handler: ?fn (c_int) callconv(.C) void, |
| 3068 | handler: k_sigaction_funcs.handler, |
| 3054 | 3069 | mask: [4]c_ulong, |
| 3055 | | restorer: fn () callconv(.C) void, |
| 3070 | restorer: k_sigaction_funcs.restorer, |
| 3056 | 3071 | }, |
| 3057 | 3072 | .mips64, .mips64el => extern struct { |
| 3058 | 3073 | flags: c_uint, |
| 3059 | | handler: ?fn (c_int) callconv(.C) void, |
| 3074 | handler: k_sigaction_funcs.handler, |
| 3060 | 3075 | mask: [2]c_ulong, |
| 3061 | | restorer: fn () callconv(.C) void, |
| 3076 | restorer: k_sigaction_funcs.restorer, |
| 3062 | 3077 | }, |
| 3063 | 3078 | else => extern struct { |
| 3064 | | handler: ?fn (c_int) callconv(.C) void, |
| 3079 | handler: k_sigaction_funcs.handler, |
| 3065 | 3080 | flags: c_ulong, |
| 3066 | | restorer: fn () callconv(.C) void, |
| 3081 | restorer: k_sigaction_funcs.restorer, |
| 3067 | 3082 | mask: [2]c_uint, |
| 3068 | 3083 | }, |
| 3069 | 3084 | }; |
| 3070 | 3085 | |
| 3071 | 3086 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 3072 | 3087 | pub const Sigaction = extern struct { |
| 3073 | | pub const handler_fn = fn (c_int) callconv(.C) void; |
| 3074 | | pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void; |
| 3088 | pub usingnamespace if (builtin.zig_backend == .stage1) struct { |
| 3089 | pub const handler_fn = fn (c_int) callconv(.C) void; |
| 3090 | pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void; |
| 3091 | } else struct { |
| 3092 | pub const handler_fn = *const fn (c_int) callconv(.C) void; |
| 3093 | pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void; |
| 3094 | }; |
| 3075 | 3095 | |
| 3076 | 3096 | handler: extern union { |
| 3077 | | handler: ?handler_fn, |
| 3078 | | sigaction: ?sigaction_fn, |
| 3097 | handler: ?Sigaction.handler_fn, |
| 3098 | sigaction: ?Sigaction.sigaction_fn, |
| 3079 | 3099 | }, |
| 3080 | 3100 | mask: sigset_t, |
| 3081 | 3101 | flags: c_uint, |
| 3082 | | restorer: ?fn () callconv(.C) void = null, |
| 3102 | restorer: ?if (builtin.zig_backend == .stage1) |
| 3103 | fn () callconv(.C) void |
| 3104 | else |
| 3105 | *const fn () callconv(.C) void = null, |
| 3083 | 3106 | }; |
| 3084 | 3107 | |
| 3085 | 3108 | pub const empty_sigset = [_]u32{0} ** @typeInfo(sigset_t).Array.len; |