mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
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.
This commit is contained in:
parent
d16079d79a
commit
f0aefa625b
@ -412,9 +412,10 @@ pub fn start(options: Options) Node {
|
|||||||
if (have_sigwinch) {
|
if (have_sigwinch) {
|
||||||
var act: posix.Sigaction = .{
|
var act: posix.Sigaction = .{
|
||||||
.handler = .{ .sigaction = handleSigWinch },
|
.handler = .{ .sigaction = handleSigWinch },
|
||||||
.mask = posix.empty_sigset,
|
.mask = undefined,
|
||||||
.flags = (posix.SA.SIGINFO | posix.SA.RESTART),
|
.flags = (posix.SA.SIGINFO | posix.SA.RESTART),
|
||||||
};
|
};
|
||||||
|
posix.sigemptyset(&act.mask);
|
||||||
posix.sigaction(posix.SIG.WINCH, &act, null);
|
posix.sigaction(posix.SIG.WINCH, &act, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1389,9 +1389,10 @@ pub fn attachSegfaultHandler() void {
|
|||||||
}
|
}
|
||||||
var act = posix.Sigaction{
|
var act = posix.Sigaction{
|
||||||
.handler = .{ .sigaction = handleSegfaultPosix },
|
.handler = .{ .sigaction = handleSegfaultPosix },
|
||||||
.mask = posix.empty_sigset,
|
.mask = undefined,
|
||||||
.flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND),
|
.flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND),
|
||||||
};
|
};
|
||||||
|
posix.sigemptyset(&act.mask);
|
||||||
|
|
||||||
updateSegfaultHandler(&act);
|
updateSegfaultHandler(&act);
|
||||||
}
|
}
|
||||||
@ -1406,9 +1407,10 @@ fn resetSegfaultHandler() void {
|
|||||||
}
|
}
|
||||||
var act = posix.Sigaction{
|
var act = posix.Sigaction{
|
||||||
.handler = .{ .handler = posix.SIG.DFL },
|
.handler = .{ .handler = posix.SIG.DFL },
|
||||||
.mask = posix.empty_sigset,
|
.mask = undefined,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
};
|
};
|
||||||
|
posix.sigemptyset(&act.mask);
|
||||||
updateSegfaultHandler(&act);
|
updateSegfaultHandler(&act);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -127,7 +127,6 @@ pub const timerfd_clockid_t = system.timerfd_clockid_t;
|
|||||||
pub const cpu_set_t = system.cpu_set_t;
|
pub const cpu_set_t = system.cpu_set_t;
|
||||||
pub const dev_t = system.dev_t;
|
pub const dev_t = system.dev_t;
|
||||||
pub const dl_phdr_info = system.dl_phdr_info;
|
pub const dl_phdr_info = system.dl_phdr_info;
|
||||||
pub const empty_sigset = system.empty_sigset;
|
|
||||||
pub const fd_t = system.fd_t;
|
pub const fd_t = system.fd_t;
|
||||||
pub const file_obj = system.file_obj;
|
pub const file_obj = system.file_obj;
|
||||||
pub const gid_t = system.gid_t;
|
pub const gid_t = system.gid_t;
|
||||||
@ -691,14 +690,14 @@ pub fn abort() noreturn {
|
|||||||
// Install default handler so that the tkill below will terminate.
|
// Install default handler so that the tkill below will terminate.
|
||||||
const sigact = Sigaction{
|
const sigact = Sigaction{
|
||||||
.handler = .{ .handler = SIG.DFL },
|
.handler = .{ .handler = SIG.DFL },
|
||||||
.mask = empty_sigset,
|
.mask = linux.empty_sigset,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
};
|
};
|
||||||
sigaction(SIG.ABRT, &sigact, null);
|
sigaction(SIG.ABRT, &sigact, null);
|
||||||
|
|
||||||
_ = linux.tkill(linux.gettid(), SIG.ABRT);
|
_ = linux.tkill(linux.gettid(), SIG.ABRT);
|
||||||
|
|
||||||
var sigabrtmask = empty_sigset;
|
var sigabrtmask = linux.empty_sigset;
|
||||||
sigaddset(&sigabrtmask, SIG.ABRT);
|
sigaddset(&sigabrtmask, SIG.ABRT);
|
||||||
sigprocmask(SIG.UNBLOCK, &sigabrtmask, null);
|
sigprocmask(SIG.UNBLOCK, &sigabrtmask, null);
|
||||||
|
|
||||||
@ -5831,7 +5830,7 @@ pub fn sigemptyset(set: *sigset_t) void {
|
|||||||
else => unreachable,
|
else => unreachable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set.* = system.empty_sigset;
|
set.* = mem.zeroes(sigset_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sigaddset(set: *sigset_t, sig: u8) void {
|
pub fn sigaddset(set: *sigset_t, sig: u8) void {
|
||||||
|
|||||||
@ -887,7 +887,8 @@ test "sigset add/del" {
|
|||||||
if (native_os == .wasi or native_os == .windows)
|
if (native_os == .wasi or native_os == .windows)
|
||||||
return error.SkipZigTest;
|
return error.SkipZigTest;
|
||||||
|
|
||||||
var sigset = posix.empty_sigset;
|
var sigset: posix.sigset_t = undefined;
|
||||||
|
posix.sigemptyset(&sigset);
|
||||||
|
|
||||||
// See that none are set, then set each one, see that they're all set, then
|
// See that none are set, then set each one, see that they're all set, then
|
||||||
// remove them all, and then see that none are set.
|
// remove them all, and then see that none are set.
|
||||||
@ -903,7 +904,6 @@ test "sigset add/del" {
|
|||||||
if (!reserved_signo(i)) {
|
if (!reserved_signo(i)) {
|
||||||
try expectEqual(true, posix.sigismember(&sigset, @truncate(i)));
|
try expectEqual(true, posix.sigismember(&sigset, @truncate(i)));
|
||||||
}
|
}
|
||||||
try expectEqual(false, posix.sigismember(&posix.empty_sigset, @truncate(i)));
|
|
||||||
}
|
}
|
||||||
for (1..posix.NSIG) |i| {
|
for (1..posix.NSIG) |i| {
|
||||||
if (!reserved_signo(i)) {
|
if (!reserved_signo(i)) {
|
||||||
@ -944,9 +944,10 @@ test "sigaction" {
|
|||||||
|
|
||||||
var sa: posix.Sigaction = .{
|
var sa: posix.Sigaction = .{
|
||||||
.handler = .{ .sigaction = &S.handler },
|
.handler = .{ .sigaction = &S.handler },
|
||||||
.mask = posix.empty_sigset,
|
.mask = undefined,
|
||||||
.flags = posix.SA.SIGINFO | posix.SA.RESETHAND,
|
.flags = posix.SA.SIGINFO | posix.SA.RESETHAND,
|
||||||
};
|
};
|
||||||
|
posix.sigemptyset(&sa.mask);
|
||||||
var old_sa: posix.Sigaction = undefined;
|
var old_sa: posix.Sigaction = undefined;
|
||||||
|
|
||||||
// Install the new signal handler.
|
// Install the new signal handler.
|
||||||
@ -1019,17 +1020,19 @@ test "sigset_t bits" {
|
|||||||
|
|
||||||
var sa: posix.Sigaction = .{
|
var sa: posix.Sigaction = .{
|
||||||
.handler = .{ .sigaction = &S.handler },
|
.handler = .{ .sigaction = &S.handler },
|
||||||
.mask = posix.empty_sigset,
|
.mask = undefined,
|
||||||
.flags = posix.SA.SIGINFO | posix.SA.RESETHAND,
|
.flags = posix.SA.SIGINFO | posix.SA.RESETHAND,
|
||||||
};
|
};
|
||||||
|
posix.sigemptyset(&sa.mask);
|
||||||
var old_sa: posix.Sigaction = undefined;
|
var old_sa: posix.Sigaction = undefined;
|
||||||
|
|
||||||
// Install the new signal handler.
|
// Install the new signal handler.
|
||||||
posix.sigaction(test_signo, &sa, &old_sa);
|
posix.sigaction(test_signo, &sa, &old_sa);
|
||||||
|
|
||||||
// block the signal and see that its delayed until unblocked
|
// block the signal and see that its delayed until unblocked
|
||||||
var block_one = posix.empty_sigset;
|
var block_one: posix.sigset_t = undefined;
|
||||||
_ = posix.sigaddset(&block_one, test_signo);
|
posix.sigemptyset(&block_one);
|
||||||
|
posix.sigaddset(&block_one, test_signo);
|
||||||
posix.sigprocmask(posix.SIG.BLOCK, &block_one, null);
|
posix.sigprocmask(posix.SIG.BLOCK, &block_one, null);
|
||||||
|
|
||||||
// qemu maps target signals to host signals 1-to-1, so targets
|
// qemu maps target signals to host signals 1-to-1, so targets
|
||||||
|
|||||||
@ -745,13 +745,14 @@ fn maybeIgnoreSigpipe() void {
|
|||||||
|
|
||||||
if (have_sigpipe_support and !std.options.keep_sigpipe) {
|
if (have_sigpipe_support and !std.options.keep_sigpipe) {
|
||||||
const posix = std.posix;
|
const posix = std.posix;
|
||||||
const act: posix.Sigaction = .{
|
var act: posix.Sigaction = .{
|
||||||
// Set handler to a noop function instead of `SIG.IGN` to prevent
|
// Set handler to a noop function instead of `SIG.IGN` to prevent
|
||||||
// leaking signal disposition to a child process.
|
// leaking signal disposition to a child process.
|
||||||
.handler = .{ .handler = noopSigHandler },
|
.handler = .{ .handler = noopSigHandler },
|
||||||
.mask = posix.empty_sigset,
|
.mask = undefined,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
};
|
};
|
||||||
|
posix.sigemptyset(&act.mask);
|
||||||
posix.sigaction(posix.SIG.PIPE, &act, null);
|
posix.sigaction(posix.SIG.PIPE, &act, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -177,10 +177,10 @@ pub fn attachSegfaultHandler() void {
|
|||||||
}
|
}
|
||||||
var act: posix.Sigaction = .{
|
var act: posix.Sigaction = .{
|
||||||
.handler = .{ .sigaction = handleSegfaultPosix },
|
.handler = .{ .sigaction = handleSegfaultPosix },
|
||||||
.mask = posix.empty_sigset,
|
.mask = undefined,
|
||||||
.flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND),
|
.flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND),
|
||||||
};
|
};
|
||||||
|
posix.sigemptyset(&act.mask);
|
||||||
debug.updateSegfaultHandler(&act);
|
debug.updateSegfaultHandler(&act);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,11 +16,12 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
// This test runs "breakpipe" as a child process and that process
|
// This test runs "breakpipe" as a child process and that process
|
||||||
// depends on inheriting a SIGPIPE disposition of "default".
|
// depends on inheriting a SIGPIPE disposition of "default".
|
||||||
{
|
{
|
||||||
const act = posix.Sigaction{
|
var act = posix.Sigaction{
|
||||||
.handler = .{ .handler = posix.SIG.DFL },
|
.handler = .{ .handler = posix.SIG.DFL },
|
||||||
.mask = posix.empty_sigset,
|
.mask = undefined,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
};
|
};
|
||||||
|
posix.sigemptyset(&act.mask);
|
||||||
try posix.sigaction(posix.SIG.PIPE, &act, null);
|
try posix.sigaction(posix.SIG.PIPE, &act, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user