authorgravatar for pat.github@tullmann.orgPat Tullmann <pat.github@tullmann.org> 2025-04-22 09:31:14-07:00
committergravatar for pat.github@tullmann.orgPat Tullmann <pat.github@tullmann.org> 2025-04-30 20:32:04-07:00
logf0aefa625b5b0d0b3612cfba9bd25c825a71818f
treeb4b4d660ed9d2795a7bacf454ba4d803b49d8450
parentd16079d79a6b7963db05253b6a3fe57a7e19d813

posix: remove empty_sigset

When linking a libc, Zig should defer to the C library for sigset operations. The pre-filled constants signal sets (empty_sigset, filled_sigset) are not compatible with C library initialization, so remove them and use the runtime `sigemptyset` and `sigfillset` methods to initialize any sigset.

7 files changed, 26 insertions(+), 19 deletions(-)

lib/std/Progress.zig+2-1
...@@ -412,9 +412,10 @@ pub fn start(options: Options) Node {...@@ -412,9 +412,10 @@ pub fn start(options: Options) Node {
412 if (have_sigwinch) {412 if (have_sigwinch) {
413 var act: posix.Sigaction = .{413 var act: posix.Sigaction = .{
414 .handler = .{ .sigaction = handleSigWinch },414 .handler = .{ .sigaction = handleSigWinch },
415 .mask = posix.empty_sigset,415 .mask = undefined,
416 .flags = (posix.SA.SIGINFO | posix.SA.RESTART),416 .flags = (posix.SA.SIGINFO | posix.SA.RESTART),
417 };417 };
418 posix.sigemptyset(&act.mask);
418 posix.sigaction(posix.SIG.WINCH, &act, null);419 posix.sigaction(posix.SIG.WINCH, &act, null);
419 }420 }
420421
lib/std/debug.zig+4-2
...@@ -1389,9 +1389,10 @@ pub fn attachSegfaultHandler() void {...@@ -1389,9 +1389,10 @@ pub fn attachSegfaultHandler() void {
1389 }1389 }
1390 var act = posix.Sigaction{1390 var act = posix.Sigaction{
1391 .handler = .{ .sigaction = handleSegfaultPosix },1391 .handler = .{ .sigaction = handleSegfaultPosix },
1392 .mask = posix.empty_sigset,1392 .mask = undefined,
1393 .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND),1393 .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND),
1394 };1394 };
1395 posix.sigemptyset(&act.mask);
13951396
1396 updateSegfaultHandler(&act);1397 updateSegfaultHandler(&act);
1397}1398}
...@@ -1406,9 +1407,10 @@ fn resetSegfaultHandler() void {...@@ -1406,9 +1407,10 @@ fn resetSegfaultHandler() void {
1406 }1407 }
1407 var act = posix.Sigaction{1408 var act = posix.Sigaction{
1408 .handler = .{ .handler = posix.SIG.DFL },1409 .handler = .{ .handler = posix.SIG.DFL },
1409 .mask = posix.empty_sigset,1410 .mask = undefined,
1410 .flags = 0,1411 .flags = 0,
1411 };1412 };
1413 posix.sigemptyset(&act.mask);
1412 updateSegfaultHandler(&act);1414 updateSegfaultHandler(&act);
1413}1415}
14141416
lib/std/posix.zig+3-4
...@@ -127,7 +127,6 @@ pub const timerfd_clockid_t = system.timerfd_clockid_t;...@@ -127,7 +127,6 @@ pub const timerfd_clockid_t = system.timerfd_clockid_t;
127pub const cpu_set_t = system.cpu_set_t;127pub const cpu_set_t = system.cpu_set_t;
128pub const dev_t = system.dev_t;128pub const dev_t = system.dev_t;
129pub const dl_phdr_info = system.dl_phdr_info;129pub const dl_phdr_info = system.dl_phdr_info;
130pub const empty_sigset = system.empty_sigset;
131pub const fd_t = system.fd_t;130pub const fd_t = system.fd_t;
132pub const file_obj = system.file_obj;131pub const file_obj = system.file_obj;
133pub const gid_t = system.gid_t;132pub const gid_t = system.gid_t;
...@@ -691,14 +690,14 @@ pub fn abort() noreturn {...@@ -691,14 +690,14 @@ pub fn abort() noreturn {
691 // Install default handler so that the tkill below will terminate.690 // Install default handler so that the tkill below will terminate.
692 const sigact = Sigaction{691 const sigact = Sigaction{
693 .handler = .{ .handler = SIG.DFL },692 .handler = .{ .handler = SIG.DFL },
694 .mask = empty_sigset,693 .mask = linux.empty_sigset,
695 .flags = 0,694 .flags = 0,
696 };695 };
697 sigaction(SIG.ABRT, &sigact, null);696 sigaction(SIG.ABRT, &sigact, null);
698697
699 _ = linux.tkill(linux.gettid(), SIG.ABRT);698 _ = linux.tkill(linux.gettid(), SIG.ABRT);
700699
701 var sigabrtmask = empty_sigset;700 var sigabrtmask = linux.empty_sigset;
702 sigaddset(&sigabrtmask, SIG.ABRT);701 sigaddset(&sigabrtmask, SIG.ABRT);
703 sigprocmask(SIG.UNBLOCK, &sigabrtmask, null);702 sigprocmask(SIG.UNBLOCK, &sigabrtmask, null);
704703
...@@ -5831,7 +5830,7 @@ pub fn sigemptyset(set: *sigset_t) void {...@@ -5831,7 +5830,7 @@ pub fn sigemptyset(set: *sigset_t) void {
5831 else => unreachable,5830 else => unreachable,
5832 }5831 }
5833 }5832 }
5834 set.* = system.empty_sigset;5833 set.* = mem.zeroes(sigset_t);
5835}5834}
58365835
5837pub fn sigaddset(set: *sigset_t, sig: u8) void {5836pub fn sigaddset(set: *sigset_t, sig: u8) void {
lib/std/posix/test.zig+9-6
...@@ -887,7 +887,8 @@ test "sigset add/del" {...@@ -887,7 +887,8 @@ test "sigset add/del" {
887 if (native_os == .wasi or native_os == .windows)887 if (native_os == .wasi or native_os == .windows)
888 return error.SkipZigTest;888 return error.SkipZigTest;
889889
890 var sigset = posix.empty_sigset;890 var sigset: posix.sigset_t = undefined;
891 posix.sigemptyset(&sigset);
891892
892 // See that none are set, then set each one, see that they're all set, then893 // See that none are set, then set each one, see that they're all set, then
893 // remove them all, and then see that none are set.894 // remove them all, and then see that none are set.
...@@ -903,7 +904,6 @@ test "sigset add/del" {...@@ -903,7 +904,6 @@ test "sigset add/del" {
903 if (!reserved_signo(i)) {904 if (!reserved_signo(i)) {
904 try expectEqual(true, posix.sigismember(&sigset, @truncate(i)));905 try expectEqual(true, posix.sigismember(&sigset, @truncate(i)));
905 }906 }
906 try expectEqual(false, posix.sigismember(&posix.empty_sigset, @truncate(i)));
907 }907 }
908 for (1..posix.NSIG) |i| {908 for (1..posix.NSIG) |i| {
909 if (!reserved_signo(i)) {909 if (!reserved_signo(i)) {
...@@ -944,9 +944,10 @@ test "sigaction" {...@@ -944,9 +944,10 @@ test "sigaction" {
944944
945 var sa: posix.Sigaction = .{945 var sa: posix.Sigaction = .{
946 .handler = .{ .sigaction = &S.handler },946 .handler = .{ .sigaction = &S.handler },
947 .mask = posix.empty_sigset,947 .mask = undefined,
948 .flags = posix.SA.SIGINFO | posix.SA.RESETHAND,948 .flags = posix.SA.SIGINFO | posix.SA.RESETHAND,
949 };949 };
950 posix.sigemptyset(&sa.mask);
950 var old_sa: posix.Sigaction = undefined;951 var old_sa: posix.Sigaction = undefined;
951952
952 // Install the new signal handler.953 // Install the new signal handler.
...@@ -1019,17 +1020,19 @@ test "sigset_t bits" {...@@ -1019,17 +1020,19 @@ test "sigset_t bits" {
10191020
1020 var sa: posix.Sigaction = .{1021 var sa: posix.Sigaction = .{
1021 .handler = .{ .sigaction = &S.handler },1022 .handler = .{ .sigaction = &S.handler },
1022 .mask = posix.empty_sigset,1023 .mask = undefined,
1023 .flags = posix.SA.SIGINFO | posix.SA.RESETHAND,1024 .flags = posix.SA.SIGINFO | posix.SA.RESETHAND,
1024 };1025 };
1026 posix.sigemptyset(&sa.mask);
1025 var old_sa: posix.Sigaction = undefined;1027 var old_sa: posix.Sigaction = undefined;
10261028
1027 // Install the new signal handler.1029 // Install the new signal handler.
1028 posix.sigaction(test_signo, &sa, &old_sa);1030 posix.sigaction(test_signo, &sa, &old_sa);
10291031
1030 // block the signal and see that its delayed until unblocked1032 // block the signal and see that its delayed until unblocked
1031 var block_one = posix.empty_sigset;1033 var block_one: posix.sigset_t = undefined;
1032 _ = posix.sigaddset(&block_one, test_signo);1034 posix.sigemptyset(&block_one);
1035 posix.sigaddset(&block_one, test_signo);
1033 posix.sigprocmask(posix.SIG.BLOCK, &block_one, null);1036 posix.sigprocmask(posix.SIG.BLOCK, &block_one, null);
10341037
1035 // qemu maps target signals to host signals 1-to-1, so targets1038 // qemu maps target signals to host signals 1-to-1, so targets
lib/std/start.zig+3-2
...@@ -745,13 +745,14 @@ fn maybeIgnoreSigpipe() void {...@@ -745,13 +745,14 @@ fn maybeIgnoreSigpipe() void {
745745
746 if (have_sigpipe_support and !std.options.keep_sigpipe) {746 if (have_sigpipe_support and !std.options.keep_sigpipe) {
747 const posix = std.posix;747 const posix = std.posix;
748 const act: posix.Sigaction = .{748 var act: posix.Sigaction = .{
749 // Set handler to a noop function instead of `SIG.IGN` to prevent749 // Set handler to a noop function instead of `SIG.IGN` to prevent
750 // leaking signal disposition to a child process.750 // leaking signal disposition to a child process.
751 .handler = .{ .handler = noopSigHandler },751 .handler = .{ .handler = noopSigHandler },
752 .mask = posix.empty_sigset,752 .mask = undefined,
753 .flags = 0,753 .flags = 0,
754 };754 };
755 posix.sigemptyset(&act.mask);
755 posix.sigaction(posix.SIG.PIPE, &act, null);756 posix.sigaction(posix.SIG.PIPE, &act, null);
756 }757 }
757}758}
src/crash_report.zig+2-2
...@@ -177,10 +177,10 @@ pub fn attachSegfaultHandler() void {...@@ -177,10 +177,10 @@ pub fn attachSegfaultHandler() void {
177 }177 }
178 var act: posix.Sigaction = .{178 var act: posix.Sigaction = .{
179 .handler = .{ .sigaction = handleSegfaultPosix },179 .handler = .{ .sigaction = handleSegfaultPosix },
180 .mask = posix.empty_sigset,180 .mask = undefined,
181 .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND),181 .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND),
182 };182 };
183183 posix.sigemptyset(&act.mask);
184 debug.updateSegfaultHandler(&act);184 debug.updateSegfaultHandler(&act);
185}185}
186186
test/standalone/sigpipe/build.zig+3-2
...@@ -16,11 +16,12 @@ pub fn build(b: *std.build.Builder) !void {...@@ -16,11 +16,12 @@ pub fn build(b: *std.build.Builder) !void {
16 // This test runs "breakpipe" as a child process and that process16 // This test runs "breakpipe" as a child process and that process
17 // depends on inheriting a SIGPIPE disposition of "default".17 // depends on inheriting a SIGPIPE disposition of "default".
18 {18 {
19 const act = posix.Sigaction{19 var act = posix.Sigaction{
20 .handler = .{ .handler = posix.SIG.DFL },20 .handler = .{ .handler = posix.SIG.DFL },
21 .mask = posix.empty_sigset,21 .mask = undefined,
22 .flags = 0,22 .flags = 0,
23 };23 };
24 posix.sigemptyset(&act.mask);
24 try posix.sigaction(posix.SIG.PIPE, &act, null);25 try posix.sigaction(posix.SIG.PIPE, &act, null);
25 }26 }
2627