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 {
10611061
10621062pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };
10631063
1064// XXX x86_64 specific
1065pub const mcontext_t = extern struct {
1066 gregs: [26]u64,
1067 mc_tlsbase: u64,
1068 fpregs: [512]u8 align(8),
1064pub const mcontext_t = switch (builtin.cpu.arch) {
1065 .aarch64 => extern struct {
1066 gregs: [35]u64,
1067 fregs: [528]u8 align(16),
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 {},
10691076};
10701077
1071pub const REG = struct {
1072 pub const RBP = 12;
1073 pub const RIP = 21;
1074 pub const RSP = 24;
1078pub const REG = switch (builtin.cpu.arch) {
1079 .aarch64 => struct {
1080 pub const FP = 29;
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 {},
10751095};
10761096
10771097pub 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
19851985 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
19861986 const ip = switch (native_os) {
19871987 .macos => @intCast(usize, ctx.mcontext.ss.pc),
1988 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),
19881989 else => @intCast(usize, ctx.mcontext.pc),
19891990 };
19901991 // x29 is the ABI-designated frame pointer
19911992 const bp = switch (native_os) {
19921993 .macos => @intCast(usize, ctx.mcontext.ss.fp),
1994 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),
19931995 else => @intCast(usize, ctx.mcontext.regs[29]),
19941996 };
19951997 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
237237 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
238238 const ip = switch (native_os) {
239239 .macos => @intCast(usize, ctx.mcontext.ss.pc),
240 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),
240241 else => @intCast(usize, ctx.mcontext.pc),
241242 };
242243 // x29 is the ABI-designated frame pointer
243244 const bp = switch (native_os) {
244245 .macos => @intCast(usize, ctx.mcontext.ss.fp),
246 .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),
245247 else => @intCast(usize, ctx.mcontext.regs[29]),
246248 };
247249 break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };