authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-11 13:30:57+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-12 10:31:37+02:00
log9f6927ba3abad4949c2c50145a35c0106ff24f8d
treedc9df3b97c6e19dcacb4700c7f079c335724ecd2
parent53aa372d03a4770ad12b3d3b11efe6d509d1a5eb
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.debug.cpu_context: signal context conversion for sparc*-netbsd/openbsd


1 files changed, 46 insertions(+), 8 deletions(-)

lib/std/debug/cpu_context.zig+46-8
......@@ -42,7 +42,7 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
4242 // Deal with some special cases first.
4343 if (native_arch.isArc() and native_os == .linux) {
4444 var native: Native = .{
45 .r = [_]u32{ uc.mcontext.r31, uc.mcontext.r30, 0, uc.mcontext.r28 } ++
45 .r = [_]Arc.Gpr{ uc.mcontext.r31, uc.mcontext.r30, 0, uc.mcontext.r28 } ++
4646 uc.mcontext.r27_26 ++
4747 uc.mcontext.r25_13 ++
4848 uc.mcontext.r12_0,
......@@ -100,15 +100,29 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
100100 .i = frame.i,
101101 .pc = uc.mcontext.pc,
102102 };
103 } else if (native_arch.isSparc() and native_os == .netbsd) {
104 // The kernel flushes all user windows before delivering a signal.
105 const save: *const [16]usize = @ptrFromInt(uc.mcontext.o[6] +% if (native_arch == .sparc64) 2047 else 0);
106
107 return .{
108 .g = [_]Sparc.Gpr{0} ++ uc.mcontext.g1_7,
109 .o = uc.mcontext.o,
110 .l = save[0..8].*,
111 .i = save[8..16].*,
112 .pc = uc.mcontext.pc,
113 };
114 } else if (native_arch == .sparc64 and native_os == .openbsd) {
115 // https://codeberg.org/ziglang/zig/issues/30958
116 return null;
103117 }
104118
105119 // Only unified conversions from here.
106120 return switch (native_arch) {
107121 .arm, .armeb, .thumb, .thumbeb => .{
108 .r = uc.mcontext.r ++ [_]u32{uc.mcontext.pc},
122 .r = uc.mcontext.r ++ [_]Arm.Gpr{uc.mcontext.pc},
109123 },
110124 .aarch64, .aarch64_be => .{
111 .x = uc.mcontext.x ++ [_]u64{uc.mcontext.lr},
125 .x = uc.mcontext.x ++ [_]Aarch64.Gpr{uc.mcontext.lr},
112126 .sp = uc.mcontext.sp,
113127 .pc = uc.mcontext.pc,
114128 },
......@@ -118,9 +132,9 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
118132 },
119133 .csky => .{
120134 .r = uc.mcontext.r0_13 ++
121 [_]u32{ uc.mcontext.r14, uc.mcontext.r15 } ++
135 [_]Csky.Gpr{ uc.mcontext.r14, uc.mcontext.r15 } ++
122136 uc.mcontext.r16_30 ++
123 [_]u32{uc.mcontext.r31},
137 [_]Csky.Gpr{uc.mcontext.r31},
124138 .pc = uc.mcontext.pc,
125139 },
126140 .hexagon, .loongarch32, .loongarch64, .mips, .mipsel, .mips64, .mips64el, .or1k => .{
......@@ -2557,7 +2571,17 @@ const signal_ucontext_t = switch (native_os) {
25572571 },
25582572 },
25592573 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/sparc64/include/signal.h
2560 .sparc64 => @compileError("sparc64-openbsd ucontext_t missing"),
2574 .sparc64 => extern struct {
2575 _cookie: i64,
2576 mcontext: extern struct {
2577 sp: u64,
2578 pc: u64,
2579 _npc: i64,
2580 _tstate: i64,
2581 g1: u64,
2582 o0: u64,
2583 },
2584 },
25612585 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/sh/include/signal.h
25622586 .sh => extern struct {
25632587 pc: u32,
......@@ -2694,8 +2718,22 @@ const signal_ucontext_t = switch (native_os) {
26942718 pc: usize,
26952719 },
26962720 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/sparc/include/mcontext.h
2697 .sparc => @compileError("sparc-netbsd mcontext_t missing"),
2698 .sparc64 => @compileError("sparc64-netbsd mcontext_t missing"),
2721 .sparc => extern struct {
2722 _psr: i32 align(8),
2723 pc: u32,
2724 _npc: i32,
2725 _y: i32,
2726 g1_7: [7]u32,
2727 o: [8]u32,
2728 },
2729 .sparc64 => extern struct {
2730 _ccr: i64 align(16),
2731 pc: u64,
2732 _npc: i64,
2733 _y: i64,
2734 g1_7: [7]u64,
2735 o: [8]u64,
2736 },
26992737 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/sh3/include/mcontext.h
27002738 .sh, .sheb => extern struct {
27012739 _gbr: i32,