authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-01 14:15:08+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-01 15:20:10+02:00
logeda296c24a80f15b4f28b985fa7ff782bb6b731e
treee4581d0f81754f21dd90337e21c2ab65afc2eb6d
parent2085096f50fe235e9b6ddff8abc04daa4e5e7667
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.os.linux: fix restore_rt() on sparc/sparc64

Not really sure what this function was trying to do before, but it seems kind of nonsensical. All it needs to do is perform an rt_sigreturn syscall, with the gotcha that it needs two nop instructions at the beginning to accommodate the way that ret instructions are done in the SPARC ABI (%i7 + 8 to skip the call instruction and delay slot). The callconv(.c) is certainly not necessary and probably caused bugs on its own.

2 files changed, 16 insertions(+), 10 deletions(-)

lib/std/os/linux/sparc.zig+8-5
...@@ -260,13 +260,16 @@ pub fn clone() callconv(.naked) u32 {...@@ -260,13 +260,16 @@ pub fn clone() callconv(.naked) u32 {
260260
261pub const restore = restore_rt;261pub const restore = restore_rt;
262262
263// Need to use C ABI here instead of naked263pub fn restore_rt() callconv(.naked) noreturn {
264// to prevent an infinite loop when calling rt_sigreturn.264 asm volatile (
265pub fn restore_rt() callconv(.c) void {265 \\ nop
266 return asm volatile ("t 0x10"266 \\ nop
267 );
268 asm volatile (
269 \\ t 0x10
267 :270 :
268 : [number] "{g1}" (@backingInt(SYS.rt_sigreturn)),271 : [number] "{g1}" (@backingInt(SYS.rt_sigreturn)),
269 : .{ .memory = true, .xcc = true, .o0 = true, .o1 = true, .o2 = true, .o3 = true, .o4 = true, .o5 = true, .o7 = true });272 );
270}273}
271274
272pub const VDSO = struct {275pub const VDSO = struct {
lib/std/os/linux/sparc64.zig+8-5
...@@ -259,13 +259,16 @@ pub fn clone() callconv(.naked) u64 {...@@ -259,13 +259,16 @@ pub fn clone() callconv(.naked) u64 {
259259
260pub const restore = restore_rt;260pub const restore = restore_rt;
261261
262// Need to use C ABI here instead of naked262pub fn restore_rt() callconv(.naked) noreturn {
263// to prevent an infinite loop when calling rt_sigreturn.263 asm volatile (
264pub fn restore_rt() callconv(.c) void {264 \\ nop
265 return asm volatile ("t 0x6d"265 \\ nop
266 );
267 asm volatile (
268 \\ t 0x6d
266 :269 :
267 : [number] "{g1}" (@backingInt(SYS.rt_sigreturn)),270 : [number] "{g1}" (@backingInt(SYS.rt_sigreturn)),
268 : .{ .memory = true, .xcc = true, .o0 = true, .o1 = true, .o2 = true, .o3 = true, .o4 = true, .o5 = true, .o7 = true });271 );
269}272}
270273
271pub const VDSO = struct {274pub const VDSO = struct {