Skip to content

Commit b54bdac

Browse files
authored
Merge pull request #25457 from linusg/more-serenity
std.debug: Add unwind support for serenity
2 parents e932ab0 + b0f280f commit b54bdac

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

lib/std/c.zig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,8 +3140,17 @@ pub const SIG = switch (native_os) {
31403140
pub const UNBLOCK = 2;
31413141
pub const SETMASK = 3;
31423142
},
3143+
// https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal.h
31433144
// https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal_numbers.h
31443145
.serenity => struct {
3146+
pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
3147+
pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
3148+
pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
3149+
3150+
pub const BLOCK = 1;
3151+
pub const UNBLOCK = 2;
3152+
pub const SETMASK = 3;
3153+
31453154
pub const INVAL = 0;
31463155
pub const HUP = 1;
31473156
pub const INT = 2;
@@ -3346,15 +3355,15 @@ pub const Sigaction = switch (native_os) {
33463355
},
33473356
// https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L39-L46
33483357
.serenity => extern struct {
3349-
pub const handler_fn = *align(1) const fn (c_int) callconv(.c) void;
3350-
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3358+
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
3359+
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;
33513360

33523361
handler: extern union {
33533362
handler: ?handler_fn,
33543363
sigaction: ?sigaction_fn,
33553364
},
33563365
mask: sigset_t,
3357-
flags: c_int,
3366+
flags: c_uint,
33583367
},
33593368
else => void,
33603369
};

lib/std/debug.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,7 @@ pub const have_segfault_handling_support = switch (native_os) {
12881288
.windows,
12891289
.freebsd,
12901290
.openbsd,
1291+
.serenity,
12911292
=> true,
12921293

12931294
else => false,
@@ -1371,7 +1372,7 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
13711372
}
13721373
const addr: usize = switch (native_os) {
13731374
.linux => @intFromPtr(info.fields.sigfault.addr),
1374-
.freebsd, .macos => @intFromPtr(info.addr),
1375+
.freebsd, .macos, .serenity => @intFromPtr(info.addr),
13751376
.netbsd => @intFromPtr(info.info.reason.fault.addr),
13761377
.openbsd => @intFromPtr(info.data.fault.addr),
13771378
.solaris, .illumos => @intFromPtr(info.reason.fault.addr),

lib/std/debug/SelfInfo/Elf.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ pub const can_unwind: bool = s: {
114114
.x86,
115115
.x86_64,
116116
},
117+
.serenity => &.{
118+
.x86_64,
119+
.aarch64,
120+
.riscv64,
121+
},
117122
else => unreachable,
118123
};
119124
for (archs) |a| {

lib/std/debug/cpu_context.zig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
5757
.r15 = uc.mcontext.gregs[std.posix.REG.R15],
5858
.rip = uc.mcontext.gregs[std.posix.REG.RIP],
5959
}) },
60-
.freebsd => .{ .gprs = .init(.{
60+
.freebsd, .serenity => .{ .gprs = .init(.{
6161
.rax = uc.mcontext.rax,
6262
.rdx = uc.mcontext.rdx,
6363
.rcx = uc.mcontext.rcx,
@@ -174,6 +174,11 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
174174
.sp = uc.mcontext.sp,
175175
.pc = uc.mcontext.pc,
176176
},
177+
.serenity => .{
178+
.x = uc.mcontext.x,
179+
.sp = uc.mcontext.sp,
180+
.pc = uc.mcontext.pc,
181+
},
177182
else => null,
178183
},
179184
.loongarch64 => switch (builtin.os.tag) {
@@ -188,6 +193,10 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
188193
.r = [1]usize{0} ++ uc.mcontext.gregs[1..].*, // r0 position is used for pc; replace with zero
189194
.pc = uc.mcontext.gregs[0],
190195
},
196+
.serenity => if (native_arch == .riscv32) null else .{
197+
.r = [1]u64{0} ++ uc.mcontext.x,
198+
.pc = uc.mcontext.pc,
199+
},
191200
else => null,
192201
},
193202
.s390x => switch (builtin.os.tag) {

0 commit comments

Comments
 (0)