diff options
| author | Linus Groh <mail@linusgroh.de> | 2025-03-10 22:48:21 +0000 |
|---|---|---|
| committer | Linus Groh <mail@linusgroh.de> | 2025-03-11 14:59:42 +0000 |
| commit | f66067546775a04ca0cda1c74cb9002d02dc49d5 (patch) | |
| tree | bc8b5a6b84a4179a4092fd299693d568c185ed68 /lib | |
| parent | 79a0de2a2f5467e0ac7a20743e21a409677bfd95 (diff) | |
| download | zig-f66067546775a04ca0cda1c74cb9002d02dc49d5.tar.gz zig-f66067546775a04ca0cda1c74cb9002d02dc49d5.zip | |
std: Add support for SerenityOS in various places
Not nearly the entire downstream patchset but these are completely
uncontroversial and known to work.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/Thread.zig | 31 | ||||
| -rw-r--r-- | lib/std/crypto/Certificate/Bundle.zig | 16 | ||||
| -rw-r--r-- | lib/std/fs.zig | 8 | ||||
| -rw-r--r-- | lib/std/fs/get_app_data_dir.zig | 2 | ||||
| -rw-r--r-- | lib/std/os.zig | 3 | ||||
| -rw-r--r-- | lib/std/process.zig | 1 | ||||
| -rw-r--r-- | lib/std/zig/target.zig | 11 |
7 files changed, 56 insertions, 16 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 27b2b11c4a..fe3bf0fcea 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -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), diff --git a/lib/std/crypto/Certificate/Bundle.zig b/lib/std/crypto/Certificate/Bundle.zig index 627cd4172b..a74eb44a91 100644 --- a/lib/std/crypto/Certificate/Bundle.zig +++ b/lib/std/crypto/Certificate/Bundle.zig @@ -50,7 +50,7 @@ pub fn deinit(cb: *Bundle, gpa: Allocator) void { cb.* = undefined; } -pub const RescanError = RescanLinuxError || RescanMacError || RescanBSDError || RescanWindowsError; +pub const RescanError = RescanLinuxError || RescanMacError || RescanWithPathError || RescanWindowsError; /// Clears the set of certificates and then scans the host operating system /// file system standard locations for certificates. @@ -60,10 +60,12 @@ pub fn rescan(cb: *Bundle, gpa: Allocator) RescanError!void { switch (builtin.os.tag) { .linux => return rescanLinux(cb, gpa), .macos => return rescanMac(cb, gpa), - .freebsd, .openbsd => return rescanBSD(cb, gpa, "/etc/ssl/cert.pem"), - .netbsd => return rescanBSD(cb, gpa, "/etc/openssl/certs/ca-certificates.crt"), - .dragonfly => return rescanBSD(cb, gpa, "/usr/local/etc/ssl/cert.pem"), - .solaris, .illumos => return rescanBSD(cb, gpa, "/etc/ssl/cacert.pem"), + .freebsd, .openbsd => return rescanWithPath(cb, gpa, "/etc/ssl/cert.pem"), + .netbsd => return rescanWithPath(cb, gpa, "/etc/openssl/certs/ca-certificates.crt"), + .dragonfly => return rescanWithPath(cb, gpa, "/usr/local/etc/ssl/cert.pem"), + .solaris, .illumos => return rescanWithPath(cb, gpa, "/etc/ssl/cacert.pem"), + // https://github.com/SerenityOS/serenity/blob/222acc9d389bc6b490d4c39539761b043a4bfcb0/Ports/ca-certificates/package.sh#L19 + .serenity => return rescanWithPath(cb, gpa, "/etc/ssl/certs/ca-certificates.crt"), .windows => return rescanWindows(cb, gpa), else => {}, } @@ -116,9 +118,9 @@ fn rescanLinux(cb: *Bundle, gpa: Allocator) RescanLinuxError!void { cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len); } -const RescanBSDError = AddCertsFromFilePathError; +const RescanWithPathError = AddCertsFromFilePathError; -fn rescanBSD(cb: *Bundle, gpa: Allocator, cert_file_path: []const u8) RescanBSDError!void { +fn rescanWithPath(cb: *Bundle, gpa: Allocator, cert_file_path: []const u8) RescanWithPathError!void { cb.bytes.clearRetainingCapacity(); cb.map.clearRetainingCapacity(); try addCertsFromFilePathAbsolute(cb, gpa, cert_file_path); diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 99936e9abd..fc2da3de72 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -52,7 +52,7 @@ pub const MAX_PATH_BYTES = @compileError("deprecated; renamed to max_path_bytes" /// * On other platforms, `[]u8` file paths are opaque sequences of bytes with /// no particular encoding. pub const max_path_bytes = switch (native_os) { - .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9, .emscripten, .wasi => posix.PATH_MAX, + .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9, .emscripten, .wasi, .serenity => posix.PATH_MAX, // Each WTF-16LE code unit may be expanded to 3 WTF-8 bytes. // If it would require 4 WTF-8 bytes, then there would be a surrogate // pair in the WTF-16LE, and we (over)account 3 bytes for it that way. @@ -73,7 +73,7 @@ pub const max_path_bytes = switch (native_os) { /// On WASI, file name components are encoded as valid UTF-8. /// On other platforms, `[]u8` components are an opaque sequence of bytes with no particular encoding. pub const max_name_bytes = switch (native_os) { - .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .solaris, .illumos => posix.NAME_MAX, + .linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .solaris, .illumos, .serenity => posix.NAME_MAX, // Haiku's NAME_MAX includes the null terminator, so subtract one. .haiku => posix.NAME_MAX - 1, // Each WTF-16LE character may be expanded to 3 WTF-8 bytes. @@ -466,7 +466,7 @@ pub fn symLinkAbsoluteZ( pub const OpenSelfExeError = posix.OpenError || SelfExePathError || posix.FlockError; pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File { - if (native_os == .linux) { + if (native_os == .linux or native_os == .serenity) { return openFileAbsoluteZ("/proc/self/exe", flags); } if (native_os == .windows) { @@ -572,7 +572,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { return result; } switch (native_os) { - .linux => return posix.readlinkZ("/proc/self/exe", out_buffer) catch |err| switch (err) { + .linux, .serenity => return posix.readlinkZ("/proc/self/exe", out_buffer) catch |err| switch (err) { error.InvalidUtf8 => unreachable, // WASI-only error.InvalidWtf8 => unreachable, // Windows-only error.UnsupportedReparsePointType => unreachable, // Windows-only diff --git a/lib/std/fs/get_app_data_dir.zig b/lib/std/fs/get_app_data_dir.zig index cce99ea8cc..a256758a07 100644 --- a/lib/std/fs/get_app_data_dir.zig +++ b/lib/std/fs/get_app_data_dir.zig @@ -30,7 +30,7 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi }; return fs.path.join(allocator, &[_][]const u8{ home_dir, "Library", "Application Support", appname }); }, - .linux, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris, .illumos => { + .linux, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris, .illumos, .serenity => { if (posix.getenv("XDG_DATA_HOME")) |xdg| { if (xdg.len > 0) { return fs.path.join(allocator, &[_][]const u8{ xdg, appname }); diff --git a/lib/std/os.zig b/lib/std/os.zig index 80f45dd59d..45568caf3c 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -82,6 +82,7 @@ pub fn isGetFdPathSupportedOnTarget(os: std.Target.Os) bool { .solaris, .illumos, .freebsd, + .serenity, => true, .dragonfly => os.version_range.semver.max.order(.{ .major = 6, .minor = 0, .patch = 0 }) != .lt, @@ -127,7 +128,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix. const len = mem.indexOfScalar(u8, out_buffer[0..], 0) orelse max_path_bytes; return out_buffer[0..len]; }, - .linux => { + .linux, .serenity => { var procfs_buf: ["/proc/self/fd/-2147483648\x00".len]u8 = undefined; const proc_path = std.fmt.bufPrintZ(procfs_buf[0..], "/proc/self/fd/{d}", .{fd}) catch unreachable; diff --git a/lib/std/process.zig b/lib/std/process.zig index dd08e88af2..b734276444 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -1539,6 +1539,7 @@ pub fn getUserInfo(name: []const u8) !UserInfo { .haiku, .solaris, .illumos, + .serenity, => posixGetUserInfo(name), else => @compileError("Unsupported OS"), }; diff --git a/lib/std/zig/target.zig b/lib/std/zig/target.zig index f4c6ae6885..ee46288903 100644 --- a/lib/std/zig/target.zig +++ b/lib/std/zig/target.zig @@ -318,6 +318,17 @@ pub fn isLibCLibName(target: std.Target, name: []const u8) bool { return true; } + if (target.os.tag == .serenity) { + if (eqlIgnoreCase(ignore_case, name, "dl")) + return true; + if (eqlIgnoreCase(ignore_case, name, "m")) + return true; + if (eqlIgnoreCase(ignore_case, name, "pthread")) + return true; + if (eqlIgnoreCase(ignore_case, name, "ssp")) + return true; + } + return false; } |
