| author | |
| committer | |
| log | c6cf40a0c03822cac3112be58c61ca55d436b5d0 |
| tree | bbdfd198a258464b23ed84b1534d7f193d646e07 |
| parent | d62b1c932e5c5ff9cd3e14b4f3f8c078a0fb43f9 |
Fixes #83574 files changed, 19 insertions(+), 15 deletions(-)
lib/std/debug.zig+11-6| ... | ... | @@ -1689,6 +1689,12 @@ pub fn maybeEnableSegfaultHandler() void { |
| 1689 | 1689 | |
| 1690 | 1690 | var windows_segfault_handle: ?windows.HANDLE = null; |
| 1691 | 1691 | |
| 1692 | pub fn updateSegfaultHandler(act: ?*const os.Sigaction) error{OperationNotSupported}!void { | |
| 1693 | try os.sigaction(os.SIG.SEGV, act, null); | |
| 1694 | try os.sigaction(os.SIG.ILL, act, null); | |
| 1695 | try os.sigaction(os.SIG.BUS, act, null); | |
| 1696 | } | |
| 1697 | ||
| 1692 | 1698 | /// Attaches a global SIGSEGV handler which calls @panic("segmentation fault"); |
| 1693 | 1699 | pub fn attachSegfaultHandler() void { |
| 1694 | 1700 | if (!have_segfault_handling_support) { |
| ... | ... | @@ -1704,9 +1710,9 @@ pub fn attachSegfaultHandler() void { |
| 1704 | 1710 | .flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND), |
| 1705 | 1711 | }; |
| 1706 | 1712 | |
| 1707 | os.sigaction(os.SIG.SEGV, &act, null); | |
| 1708 | os.sigaction(os.SIG.ILL, &act, null); | |
| 1709 | os.sigaction(os.SIG.BUS, &act, null); | |
| 1713 | updateSegfaultHandler(&act) catch { | |
| 1714 | @panic("unable to install segfault handler, maybe adjust have_segfault_handling_support in std/debug.zig"); | |
| 1715 | }; | |
| 1710 | 1716 | } |
| 1711 | 1717 | |
| 1712 | 1718 | fn resetSegfaultHandler() void { |
| ... | ... | @@ -1722,9 +1728,8 @@ fn resetSegfaultHandler() void { |
| 1722 | 1728 | .mask = os.empty_sigset, |
| 1723 | 1729 | .flags = 0, |
| 1724 | 1730 | }; |
| 1725 | os.sigaction(os.SIG.SEGV, &act, null); | |
| 1726 | os.sigaction(os.SIG.ILL, &act, null); | |
| 1727 | os.sigaction(os.SIG.BUS, &act, null); | |
| 1731 | // do nothing if an error happens to avoid a double-panic | |
| 1732 | updateSegfaultHandler(&act) catch {}; | |
| 1728 | 1733 | } |
| 1729 | 1734 | |
| 1730 | 1735 | fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const anyopaque) callconv(.C) noreturn { |
lib/std/os.zig+2-3| ... | ... | @@ -5521,11 +5521,10 @@ pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void { |
| 5521 | 5521 | } |
| 5522 | 5522 | |
| 5523 | 5523 | /// Examine and change a signal action. |
| 5524 | pub fn sigaction(sig: u6, act: ?*const Sigaction, oact: ?*Sigaction) void { | |
| 5524 | pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) error{OperationNotSupported}!void { | |
| 5525 | 5525 | switch (errno(system.sigaction(sig, act, oact))) { |
| 5526 | 5526 | .SUCCESS => return, |
| 5527 | .FAULT => unreachable, | |
| 5528 | .INVAL => unreachable, | |
| 5527 | .INVAL, .NOSYS => return error.OperationNotSupported, | |
| 5529 | 5528 | else => unreachable, |
| 5530 | 5529 | } |
| 5531 | 5530 | } |
lib/std/os/test.zig+3-3| ... | ... | @@ -772,16 +772,16 @@ test "sigaction" { |
| 772 | 772 | }; |
| 773 | 773 | var old_sa: os.Sigaction = undefined; |
| 774 | 774 | // Install the new signal handler. |
| 775 | os.sigaction(os.SIG.USR1, &sa, null); | |
| 775 | try os.sigaction(os.SIG.USR1, &sa, null); | |
| 776 | 776 | // Check that we can read it back correctly. |
| 777 | os.sigaction(os.SIG.USR1, null, &old_sa); | |
| 777 | try os.sigaction(os.SIG.USR1, null, &old_sa); | |
| 778 | 778 | try testing.expectEqual(S.handler, old_sa.handler.sigaction.?); |
| 779 | 779 | try testing.expect((old_sa.flags & os.SA.SIGINFO) != 0); |
| 780 | 780 | // Invoke the handler. |
| 781 | 781 | try os.raise(os.SIG.USR1); |
| 782 | 782 | try testing.expect(signal_test_failed == false); |
| 783 | 783 | // Check if the handler has been correctly reset to SIG_DFL |
| 784 | os.sigaction(os.SIG.USR1, null, &old_sa); | |
| 784 | try os.sigaction(os.SIG.USR1, null, &old_sa); | |
| 785 | 785 | try testing.expectEqual(os.SIG.DFL, old_sa.handler.sigaction); |
| 786 | 786 | } |
| 787 | 787 |
src/crash_report.zig+3-3| ... | ... | @@ -175,9 +175,9 @@ pub fn attachSegfaultHandler() void { |
| 175 | 175 | .flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND), |
| 176 | 176 | }; |
| 177 | 177 | |
| 178 | os.sigaction(os.SIG.SEGV, &act, null); | |
| 179 | os.sigaction(os.SIG.ILL, &act, null); | |
| 180 | os.sigaction(os.SIG.BUS, &act, null); | |
| 178 | debug.updateSegfaultHandler(&act) catch { | |
| 179 | @panic("unable to install segfault handler, maybe adjust have_segfault_handling_support in std/debug.zig"); | |
| 180 | }; | |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const anyopaque) callconv(.C) noreturn { |