aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2022-01-17 17:46:48 +0100
committerAndrew Kelley <andrew@ziglang.org>2022-01-18 15:10:49 -0500
commit305a7def136580e7a05652a95c1d2ff338541607 (patch)
tree56018e77d507252d36a393d6fbe81abd55751a48 /src
parentf423b5949b8722d4b290f57c3d06d015e39217b0 (diff)
downloadzig-305a7def136580e7a05652a95c1d2ff338541607.tar.gz
zig-305a7def136580e7a05652a95c1d2ff338541607.zip
Implement segfault handler for macOS x86_64
Diffstat (limited to 'src')
-rw-r--r--src/crash_report.zig10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/crash_report.zig b/src/crash_report.zig
index 88b59e8952..724269556b 100644
--- a/src/crash_report.zig
+++ b/src/crash_report.zig
@@ -169,7 +169,7 @@ pub fn attachSegfaultHandler() void {
return;
}
var act = os.Sigaction{
- .handler = .{ .sigaction = handleSegfaultLinux },
+ .handler = .{ .sigaction = handleSegfaultPosix },
.mask = os.empty_sigset,
.flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND),
};
@@ -179,17 +179,17 @@ pub fn attachSegfaultHandler() void {
os.sigaction(os.SIG.BUS, &act, null);
}
-fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const anyopaque) callconv(.C) noreturn {
+fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const anyopaque) callconv(.C) noreturn {
// TODO: use alarm() here to prevent infinite loops
PanicSwitch.preDispatch();
const addr = switch (builtin.os.tag) {
.linux => @ptrToInt(info.fields.sigfault.addr),
- .freebsd => @ptrToInt(info.addr),
+ .freebsd, .macos => @ptrToInt(info.addr),
.netbsd => @ptrToInt(info.info.reason.fault.addr),
.openbsd => @ptrToInt(info.data.fault.addr),
.solaris => @ptrToInt(info.reason.fault.addr),
- else => @compileError("TODO implement handleSegfaultLinux for new linux OS"),
+ else => @compileError("TODO implement handleSegfaultPosix for new POSIX OS"),
};
var err_buffer: [128]u8 = undefined;
@@ -213,12 +213,14 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
.linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]),
.freebsd => @intCast(usize, ctx.mcontext.rip),
.openbsd => @intCast(usize, ctx.sc_rip),
+ .macos => @intCast(usize, ctx.mcontext.ss.rip),
else => unreachable,
};
const bp = switch (builtin.os.tag) {
.linux, .netbsd, .solaris => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]),
.openbsd => @intCast(usize, ctx.sc_rbp),
.freebsd => @intCast(usize, ctx.mcontext.rbp),
+ .macos => @intCast(usize, ctx.mcontext.ss.rbp),
else => unreachable,
};
break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };