authorgravatar for semarie@online.frSébastien Marie <semarie@online.fr> 2020-12-23 12:39:20+00:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-12-23 20:47:06+02:00
log6e2622661cdf9dd48cf962e5d6902324b15468c3
tree18375a45631eaf93c9249c4f9429969adf88f5f6
parent588e8287594803fdc06b6dfc3d7591075b88ff1e

openbsd: implement segfault handling on openbsd x86_64


2 files changed, 58 insertions(+), 1 deletions(-)

lib/std/debug.zig+4-1
...@@ -1696,7 +1696,7 @@ fn getDebugInfoAllocator() *mem.Allocator {...@@ -1696,7 +1696,7 @@ fn getDebugInfoAllocator() *mem.Allocator {
1696pub const have_segfault_handling_support = switch (builtin.os.tag) {1696pub const have_segfault_handling_support = switch (builtin.os.tag) {
1697 .linux, .netbsd => true,1697 .linux, .netbsd => true,
1698 .windows => true,1698 .windows => true,
1699 .freebsd => @hasDecl(os, "ucontext_t"),1699 .freebsd, .openbsd => @hasDecl(os, "ucontext_t"),
1700 else => false,1700 else => false,
1701};1701};
1702pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler"))1702pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler"))
...@@ -1760,6 +1760,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v...@@ -1760,6 +1760,7 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
1760 .linux => @ptrToInt(info.fields.sigfault.addr),1760 .linux => @ptrToInt(info.fields.sigfault.addr),
1761 .freebsd => @ptrToInt(info.addr),1761 .freebsd => @ptrToInt(info.addr),
1762 .netbsd => @ptrToInt(info.info.reason.fault.addr),1762 .netbsd => @ptrToInt(info.info.reason.fault.addr),
1763 .openbsd => @ptrToInt(info.data.fault.addr),
1763 else => unreachable,1764 else => unreachable,
1764 };1765 };
17651766
...@@ -1786,10 +1787,12 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v...@@ -1786,10 +1787,12 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
1786 const ip = switch (builtin.os.tag) {1787 const ip = switch (builtin.os.tag) {
1787 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]),1788 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]),
1788 .freebsd => @intCast(usize, ctx.mcontext.rip),1789 .freebsd => @intCast(usize, ctx.mcontext.rip),
1790 .openbsd => @intCast(usize, ctx.sc_rip),
1789 else => unreachable,1791 else => unreachable,
1790 };1792 };
1791 const bp = switch (builtin.os.tag) {1793 const bp = switch (builtin.os.tag) {
1792 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]),1794 .linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]),
1795 .openbsd => @intCast(usize, ctx.sc_rbp),
1793 .freebsd => @intCast(usize, ctx.mcontext.rbp),1796 .freebsd => @intCast(usize, ctx.mcontext.rbp),
1794 else => unreachable,1797 else => unreachable,
1795 };1798 };
lib/std/os/bits/openbsd.zig+54
...@@ -809,6 +809,60 @@ comptime {...@@ -809,6 +809,60 @@ comptime {
809 std.debug.assert(@sizeOf(siginfo_t) == 136);809 std.debug.assert(@sizeOf(siginfo_t) == 136);
810}810}
811811
812pub usingnamespace switch (builtin.arch) {
813 .x86_64 => struct {
814 pub const ucontext_t = extern struct {
815 sc_rdi: c_long,
816 sc_rsi: c_long,
817 sc_rdx: c_long,
818 sc_rcx: c_long,
819 sc_r8: c_long,
820 sc_r9: c_long,
821 sc_r10: c_long,
822 sc_r11: c_long,
823 sc_r12: c_long,
824 sc_r13: c_long,
825 sc_r14: c_long,
826 sc_r15: c_long,
827 sc_rbp: c_long,
828 sc_rbx: c_long,
829 sc_rax: c_long,
830 sc_gs: c_long,
831 sc_fs: c_long,
832 sc_es: c_long,
833 sc_ds: c_long,
834 sc_trapno: c_long,
835 sc_err: c_long,
836 sc_rip: c_long,
837 sc_cs: c_long,
838 sc_rflags: c_long,
839 sc_rsp: c_long,
840 sc_ss: c_long,
841
842 sc_fpstate: fxsave64,
843 __sc_unused: c_int,
844 sc_mask: c_int,
845 sc_cookie: c_long,
846 };
847
848 pub const fxsave64 = packed struct {
849 fx_fcw: u16,
850 fx_fsw: u16,
851 fx_ftw: u8,
852 fx_unused1: u8,
853 fx_fop: u16,
854 fx_rip: u64,
855 fx_rdp: u64,
856 fx_mxcsr: u32,
857 fx_mxcsr_mask: u32,
858 fx_st: [8][2]u64,
859 fx_xmm: [16][2]u64,
860 fx_unused3: [96]u8,
861 };
862 },
863 else => struct {},
864};
865
812pub const sigset_t = c_uint;866pub const sigset_t = c_uint;
813pub const empty_sigset: sigset_t = 0;867pub const empty_sigset: sigset_t = 0;
814868