From 701a6f394cd96074a3258fc5545e7b278c13ef97 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 3 Oct 2025 22:15:38 +0100 Subject: [PATCH 1/3] std.c: Add missing SIG constants for serenity --- lib/std/c.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/std/c.zig b/lib/std/c.zig index 4c139d5023..f6462dcbe0 100644 --- 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; From a76851b2ef8f22fb318573b33c973cf768423b5e Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 3 Oct 2025 22:19:25 +0100 Subject: [PATCH 2/3] std.c: Also make Sigaction flags a c_uint for serenity This matches all other platforms. Even if this field is defined as 'int' in the C definition, the expectation is that the full 32-bit unsigned integer range can be used. In particular this Sigaction initializer in the new std.debug code was causing a build failure: ```zig .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND) ``` --- lib/std/c.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index f6462dcbe0..39ee688563 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -3355,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, }; From b0f280f4a4f3b1f804d84cc71c3e1be54d6e05a8 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 3 Oct 2025 22:37:05 +0100 Subject: [PATCH 3/3] std.debug: Add unwind support for serenity --- lib/std/debug.zig | 3 ++- lib/std/debug/SelfInfo/Elf.zig | 5 +++++ lib/std/debug/cpu_context.zig | 11 ++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 6d705f3c86..7d0990ae00 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1276,6 +1276,7 @@ pub const have_segfault_handling_support = switch (native_os) { .windows, .freebsd, .openbsd, + .serenity, => true, else => false, @@ -1359,7 +1360,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 index 9772ec0aac..c31af53cd6 100644 --- 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 index 0e25d00480..121245ac7b 100644 --- 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) {