authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2023-01-17 18:14:53-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-18 02:50:11-05:00
logc9f7b32fbd4ea99da7fdf435b83ce0e582f33c08
tree0d777b728b0ae376990048059f99a42fa535a7fe
parent7f604b6f48905faf0bbe1ad795b53aeb11332063

netbsd: add mcontext_t for aarch64

- test `lib/std/std.zig` passes - stack traces work

3 files changed, 33 insertions(+), 9 deletions(-)

lib/std/c/netbsd.zig+29-9
...@@ -1061,17 +1061,37 @@ pub const sigset_t = extern struct {...@@ -1061,17 +1061,37 @@ pub const sigset_t = extern struct {
10611061
1062pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };1062pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };
10631063
1064// XXX x86_64 specific1064pub const mcontext_t = switch (builtin.cpu.arch) {
1065pub const mcontext_t = extern struct {1065 .aarch64 => extern struct {
1066 gregs: [26]u64,1066 gregs: [35]u64,
1067 mc_tlsbase: u64,1067 fregs: [528]u8 align(16),
1068 fpregs: [512]u8 align(8),1068 spare: [8]u64,
1069 },
1070 .x86_64 => extern struct {
1071 gregs: [26]u64,
1072 mc_tlsbase: u64,
1073 fpregs: [512]u8 align(8),
1074 },
1075 else => struct {},
1069};1076};
10701077
1071pub const REG = struct {1078pub const REG = switch (builtin.cpu.arch) {
1072 pub const RBP = 12;1079 .aarch64 => struct {
1073 pub const RIP = 21;1080 pub const FP = 29;
1074 pub const RSP = 24;1081 pub const SP = 31;
1082 pub const PC = 32;
1083 },
1084 .arm => struct {
1085 pub const FP = 11;
1086 pub const SP = 13;
1087 pub const PC = 15;
1088 },
1089 .x86_64 => struct {
1090 pub const RBP = 12;
1091 pub const RIP = 21;
1092 pub const RSP = 24;
1093 },
1094 else => struct {},
1075};1095};
10761096
1077pub const ucontext_t = extern struct {1097pub const ucontext_t = extern struct {
lib/std/debug.zig+2
...@@ -1985,11 +1985,13 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any...@@ -1985,11 +1985,13 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
1985 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));1985 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
1986 const ip = switch (native_os) {1986 const ip = switch (native_os) {
1987 .macos => @intCast(usize, ctx.mcontext.ss.pc),1987 .macos => @intCast(usize, ctx.mcontext.ss.pc),
1988 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),
1988 else => @intCast(usize, ctx.mcontext.pc),1989 else => @intCast(usize, ctx.mcontext.pc),
1989 };1990 };
1990 // x29 is the ABI-designated frame pointer1991 // x29 is the ABI-designated frame pointer
1991 const bp = switch (native_os) {1992 const bp = switch (native_os) {
1992 .macos => @intCast(usize, ctx.mcontext.ss.fp),1993 .macos => @intCast(usize, ctx.mcontext.ss.fp),
1994 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),
1993 else => @intCast(usize, ctx.mcontext.regs[29]),1995 else => @intCast(usize, ctx.mcontext.regs[29]),
1994 };1996 };
1995 dumpStackTraceFromBase(bp, ip);1997 dumpStackTraceFromBase(bp, ip);
src/crash_report.zig+2
...@@ -237,11 +237,13 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any...@@ -237,11 +237,13 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
237 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));237 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
238 const ip = switch (native_os) {238 const ip = switch (native_os) {
239 .macos => @intCast(usize, ctx.mcontext.ss.pc),239 .macos => @intCast(usize, ctx.mcontext.ss.pc),
240 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),
240 else => @intCast(usize, ctx.mcontext.pc),241 else => @intCast(usize, ctx.mcontext.pc),
241 };242 };
242 // x29 is the ABI-designated frame pointer243 // x29 is the ABI-designated frame pointer
243 const bp = switch (native_os) {244 const bp = switch (native_os) {
244 .macos => @intCast(usize, ctx.mcontext.ss.fp),245 .macos => @intCast(usize, ctx.mcontext.ss.fp),
246 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),
245 else => @intCast(usize, ctx.mcontext.regs[29]),247 else => @intCast(usize, ctx.mcontext.regs[29]),
246 };248 };
247 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };249 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };