diff --git a/lib/std/c.zig b/lib/std/c.zig index 4c139d5023..39ee688563 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; @@ -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 index 4846b3ce93..5b4c5c873c 100644 --- 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 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) {