commit b54bdace75df63e58892c65f97ff644b95a4b307 (tree)
parent e932ab003f8db74c5e4e95177eb02eb0cf0d8449
Author: Alex Rønne Petersen <alex@alexrp.com>
Date: Sat, 4 Oct 2025 07:09:59 +0200
Merge pull request #25457 from linusg/more-serenity
std.debug: Add unwind support for serenity
Diffstat:
4 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/lib/std/c.zig b/lib/std/c.zig
@@ -3140,8 +3140,17 @@ pub const SIG = switch (native_os) {
pub const UNBLOCK = 2;
pub const SETMASK = 3;
},
+ // https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal.h
// https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal_numbers.h
.serenity => struct {
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
+
+ pub const BLOCK = 1;
+ pub const UNBLOCK = 2;
+ pub const SETMASK = 3;
+
pub const INVAL = 0;
pub const HUP = 1;
pub const INT = 2;
@@ -3346,15 +3355,15 @@ pub const Sigaction = switch (native_os) {
},
// https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L39-L46
.serenity => extern struct {
- pub const handler_fn = *align(1) const fn (c_int) callconv(.c) void;
- pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.c) void;
+ pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
+ pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
handler: extern union {
handler: ?handler_fn,
sigaction: ?sigaction_fn,
},
mask: sigset_t,
- flags: c_int,
+ flags: c_uint,
},
else => void,
};
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
@@ -1288,6 +1288,7 @@ pub const have_segfault_handling_support = switch (native_os) {
.windows,
.freebsd,
.openbsd,
+ .serenity,
=> true,
else => false,
@@ -1371,7 +1372,7 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
}
const addr: usize = switch (native_os) {
.linux => @intFromPtr(info.fields.sigfault.addr),
- .freebsd, .macos => @intFromPtr(info.addr),
+ .freebsd, .macos, .serenity => @intFromPtr(info.addr),
.netbsd => @intFromPtr(info.info.reason.fault.addr),
.openbsd => @intFromPtr(info.data.fault.addr),
.solaris, .illumos => @intFromPtr(info.reason.fault.addr),
diff --git a/lib/std/debug/SelfInfo/Elf.zig b/lib/std/debug/SelfInfo/Elf.zig
@@ -114,6 +114,11 @@ pub const can_unwind: bool = s: {
.x86,
.x86_64,
},
+ .serenity => &.{
+ .x86_64,
+ .aarch64,
+ .riscv64,
+ },
else => unreachable,
};
for (archs) |a| {
diff --git a/lib/std/debug/cpu_context.zig b/lib/std/debug/cpu_context.zig
@@ -57,7 +57,7 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
.r15 = uc.mcontext.gregs[std.posix.REG.R15],
.rip = uc.mcontext.gregs[std.posix.REG.RIP],
}) },
- .freebsd => .{ .gprs = .init(.{
+ .freebsd, .serenity => .{ .gprs = .init(.{
.rax = uc.mcontext.rax,
.rdx = uc.mcontext.rdx,
.rcx = uc.mcontext.rcx,
@@ -174,6 +174,11 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
.sp = uc.mcontext.sp,
.pc = uc.mcontext.pc,
},
+ .serenity => .{
+ .x = uc.mcontext.x,
+ .sp = uc.mcontext.sp,
+ .pc = uc.mcontext.pc,
+ },
else => null,
},
.loongarch64 => switch (builtin.os.tag) {
@@ -188,6 +193,10 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
.r = [1]usize{0} ++ uc.mcontext.gregs[1..].*, // r0 position is used for pc; replace with zero
.pc = uc.mcontext.gregs[0],
},
+ .serenity => if (native_arch == .riscv32) null else .{
+ .r = [1]u64{0} ++ uc.mcontext.x,
+ .pc = uc.mcontext.pc,
+ },
else => null,
},
.s390x => switch (builtin.os.tag) {