diff options
| author | zseri <zseri.devel@ytrizja.de> | 2022-01-21 10:14:44 +0100 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-03-19 19:13:31 +0200 |
| commit | c6cf40a0c03822cac3112be58c61ca55d436b5d0 (patch) | |
| tree | bbdfd198a258464b23ed84b1534d7f193d646e07 /lib/std/debug.zig | |
| parent | d62b1c932e5c5ff9cd3e14b4f3f8c078a0fb43f9 (diff) | |
| download | zig-c6cf40a0c03822cac3112be58c61ca55d436b5d0.tar.gz zig-c6cf40a0c03822cac3112be58c61ca55d436b5d0.zip | |
fix sigaction double panic
Fixes #8357
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index c50cdc2df8..b095464762 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1689,6 +1689,12 @@ pub fn maybeEnableSegfaultHandler() void { var windows_segfault_handle: ?windows.HANDLE = null; +pub fn updateSegfaultHandler(act: ?*const os.Sigaction) error{OperationNotSupported}!void { + try os.sigaction(os.SIG.SEGV, act, null); + try os.sigaction(os.SIG.ILL, act, null); + try os.sigaction(os.SIG.BUS, act, null); +} + /// Attaches a global SIGSEGV handler which calls @panic("segmentation fault"); pub fn attachSegfaultHandler() void { if (!have_segfault_handling_support) { @@ -1704,9 +1710,9 @@ pub fn attachSegfaultHandler() void { .flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND), }; - os.sigaction(os.SIG.SEGV, &act, null); - os.sigaction(os.SIG.ILL, &act, null); - os.sigaction(os.SIG.BUS, &act, null); + updateSegfaultHandler(&act) catch { + @panic("unable to install segfault handler, maybe adjust have_segfault_handling_support in std/debug.zig"); + }; } fn resetSegfaultHandler() void { @@ -1722,9 +1728,8 @@ fn resetSegfaultHandler() void { .mask = os.empty_sigset, .flags = 0, }; - os.sigaction(os.SIG.SEGV, &act, null); - os.sigaction(os.SIG.ILL, &act, null); - os.sigaction(os.SIG.BUS, &act, null); + // do nothing if an error happens to avoid a double-panic + updateSegfaultHandler(&act) catch {}; } fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const anyopaque) callconv(.C) noreturn { |
