netbsd: add mcontext_t for aarch64

- test `lib/std/std.zig` passes
- stack traces work
This commit is contained in:
Michael Dusan 2023-01-17 18:14:53 -05:00 committed by Andrew Kelley
parent 7f604b6f48
commit c9f7b32fbd
3 changed files with 33 additions and 9 deletions

View File

@ -1061,17 +1061,37 @@ pub const sigset_t = extern struct {
pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };
// XXX x86_64 specific
pub const mcontext_t = extern struct {
gregs: [26]u64,
mc_tlsbase: u64,
fpregs: [512]u8 align(8),
pub const mcontext_t = switch (builtin.cpu.arch) {
.aarch64 => extern struct {
gregs: [35]u64,
fregs: [528]u8 align(16),
spare: [8]u64,
},
.x86_64 => extern struct {
gregs: [26]u64,
mc_tlsbase: u64,
fpregs: [512]u8 align(8),
},
else => struct {},
};
pub const REG = struct {
pub const RBP = 12;
pub const RIP = 21;
pub const RSP = 24;
pub const REG = switch (builtin.cpu.arch) {
.aarch64 => struct {
pub const FP = 29;
pub const SP = 31;
pub const PC = 32;
},
.arm => struct {
pub const FP = 11;
pub const SP = 13;
pub const PC = 15;
},
.x86_64 => struct {
pub const RBP = 12;
pub const RIP = 21;
pub const RSP = 24;
},
else => struct {},
};
pub const ucontext_t = extern struct {

View File

@ -1985,11 +1985,13 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
const ip = switch (native_os) {
.macos => @intCast(usize, ctx.mcontext.ss.pc),
.netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),
else => @intCast(usize, ctx.mcontext.pc),
};
// x29 is the ABI-designated frame pointer
const bp = switch (native_os) {
.macos => @intCast(usize, ctx.mcontext.ss.fp),
.netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),
else => @intCast(usize, ctx.mcontext.regs[29]),
};
dumpStackTraceFromBase(bp, ip);

View File

@ -237,11 +237,13 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
const ip = switch (native_os) {
.macos => @intCast(usize, ctx.mcontext.ss.pc),
.netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.PC]),
else => @intCast(usize, ctx.mcontext.pc),
};
// x29 is the ABI-designated frame pointer
const bp = switch (native_os) {
.macos => @intCast(usize, ctx.mcontext.ss.fp),
.netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.FP]),
else => @intCast(usize, ctx.mcontext.regs[29]),
};
break :ctx StackContext{ .exception = .{ .bp = bp, .ip = ip } };