std: Add support for SerenityOS in various places

Not nearly the entire downstream patchset but these are completely
uncontroversial and known to work.
This commit is contained in:
Linus Groh
2025-03-10 22:48:21 +00:00
parent 79a0de2a2f
commit f660675467
7 changed files with 56 additions and 16 deletions

View File

@@ -122,6 +122,8 @@ pub const max_name_len = switch (native_os) {
.openbsd => 23,
.dragonfly => 1023,
.solaris, .illumos => 31,
// https://github.com/SerenityOS/serenity/blob/6b4c300353da49d3508b5442cf61da70bd04d757/Kernel/Tasks/Thread.h#L102
.serenity => 63,
else => 0,
};
@@ -201,6 +203,15 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
else => |e| return posix.unexpectedErrno(e),
}
},
.serenity => if (use_pthreads) {
const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr);
switch (@as(posix.E, @enumFromInt(err))) {
.SUCCESS => return,
.NAMETOOLONG => unreachable,
.SRCH => unreachable,
else => |e| return posix.unexpectedErrno(e),
}
},
.netbsd, .solaris, .illumos => if (use_pthreads) {
const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null);
switch (@as(posix.E, @enumFromInt(err))) {
@@ -302,6 +313,16 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
else => |e| return posix.unexpectedErrno(e),
}
},
.serenity => if (use_pthreads) {
const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
switch (@as(posix.E, @enumFromInt(err))) {
.SUCCESS => return,
.NAMETOOLONG => unreachable,
.SRCH => unreachable,
.FAULT => unreachable,
else => |e| return posix.unexpectedErrno(e),
}
},
.netbsd, .solaris, .illumos => if (use_pthreads) {
const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
switch (@as(posix.E, @enumFromInt(err))) {
@@ -342,6 +363,7 @@ pub const Id = switch (native_os) {
.openbsd,
.haiku,
.wasi,
.serenity,
=> u32,
.macos, .ios, .watchos, .tvos, .visionos => u64,
.windows => windows.DWORD,
@@ -692,6 +714,9 @@ const PosixThreadImpl = struct {
.haiku => {
return @as(u32, @bitCast(c.find_thread(null)));
},
.serenity => {
return @as(u32, @bitCast(c.pthread_self()));
},
else => {
return @intFromPtr(c.pthread_self());
},
@@ -713,11 +738,11 @@ const PosixThreadImpl = struct {
};
return @as(usize, @intCast(count));
},
.solaris, .illumos => {
.solaris, .illumos, .serenity => {
// The "proper" way to get the cpu count would be to query
// /dev/kstat via ioctls, and traverse a linked list for each
// cpu.
const rc = c.sysconf(std.c._SC.NPROCESSORS_ONLN);
// cpu. (solaris, illumos)
const rc = c.sysconf(@intFromEnum(std.c._SC.NPROCESSORS_ONLN));
return switch (posix.errno(rc)) {
.SUCCESS => @as(usize, @intCast(rc)),
else => |err| posix.unexpectedErrno(err),