From 467a1f4a1c58bc17b80e8af88ac8c7f6ba3d2035 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 30 Jul 2025 23:19:29 +0100 Subject: [PATCH 1/4] std.c: Fix msghdr_const for serenity --- lib/std/c.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index e2f55dd6fb..a12312ba39 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -4121,7 +4121,7 @@ pub const msghdr_const = switch (native_os) { .serenity => extern struct { name: ?*const anyopaque, namelen: socklen_t, - iov: [*]const iovec, + iov: [*]const iovec_const, iovlen: c_uint, control: ?*const anyopaque, controllen: socklen_t, From f5e938433555fb8cb0719d63e842ea26d012bb1d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 30 Jul 2025 23:22:06 +0100 Subject: [PATCH 2/4] std.c: Fix MAP for serenity I accidentally translated MAP_ constants representing the type as individual fields. MAP_FILE is for compatibility only and not needed here. --- lib/std/c.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index a12312ba39..b9a659cae6 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -8760,10 +8760,10 @@ pub const MAP = switch (native_os) { }, // https://github.com/SerenityOS/serenity/blob/6d59d4d3d9e76e39112842ec487840828f1c9bfe/Kernel/API/POSIX/sys/mman.h#L16-L26 .serenity => packed struct(c_int) { - FILE: bool = false, - SHARED: bool = false, - PRIVATE: bool = false, - _3: u2 = 0, + TYPE: enum(u4) { + SHARED = 0x01, + PRIVATE = 0x02, + }, FIXED: bool = false, ANONYMOUS: bool = false, STACK: bool = false, @@ -8771,7 +8771,7 @@ pub const MAP = switch (native_os) { RANDOMIZED: bool = false, PURGEABLE: bool = false, FIXED_NOREPLACE: bool = false, - _: std.meta.Int(.unsigned, @bitSizeOf(c_int) - 12) = 0, + _: std.meta.Int(.unsigned, @bitSizeOf(c_int) - 11) = 0, }, else => void, }; From 813a0f125e2619f0a056d675339cab6ce34a2cbf Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 30 Jul 2025 23:27:32 +0100 Subject: [PATCH 3/4] std.posix: Default ACCMODE to NONE for serenity Unlike all other platforms where RDONLY is 0 it does not work as a default for the O flags on serenity - various syscalls other than 'open', e.g. 'pipe', return EINVAL if unexpected bits are set in the flags. --- lib/std/c.zig | 2 +- lib/std/posix.zig | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index b9a659cae6..2339ede076 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -8604,7 +8604,7 @@ pub const O = switch (native_os) { }, // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L28-L43 .serenity => packed struct(c_int) { - ACCMODE: std.posix.ACCMODE = .RDONLY, + ACCMODE: std.posix.ACCMODE = .NONE, EXEC: bool = false, CREAT: bool = false, EXCL: bool = false, diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 54c6470d2c..e10023f6b1 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -204,6 +204,7 @@ pub const ACCMODE = switch (native_os) { // implements this suggestion. // https://github.com/SerenityOS/serenity/blob/4adc51fdf6af7d50679c48b39362e062f5a3b2cb/Kernel/API/POSIX/fcntl.h#L28-L30 .serenity => enum(u2) { + NONE = 0, RDONLY = 1, WRONLY = 2, RDWR = 3, From ce776d32455f5ac43f91cc8904765836c00605cf Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 30 Jul 2025 23:28:58 +0100 Subject: [PATCH 4/4] std: Add serenity to more OS checks --- lib/std/Progress.zig | 1 + lib/std/heap.zig | 2 +- lib/std/posix.zig | 3 ++- lib/std/start.zig | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index 2806c1a09c..8b741187e7 100644 --- a/lib/std/Progress.zig +++ b/lib/std/Progress.zig @@ -1548,6 +1548,7 @@ const have_sigwinch = switch (builtin.os.tag) { .visionos, .dragonfly, .freebsd, + .serenity, => true, else => false, diff --git a/lib/std/heap.zig b/lib/std/heap.zig index 51e4fe44a2..a39cf5e1cb 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -146,7 +146,7 @@ const CAllocator = struct { else {}; pub const supports_posix_memalign = switch (builtin.os.tag) { - .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .linux, .macos, .ios, .tvos, .watchos, .visionos => true, + .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .linux, .macos, .ios, .tvos, .watchos, .visionos, .serenity => true, else => false, }; diff --git a/lib/std/posix.zig b/lib/std/posix.zig index e10023f6b1..fefb57de1c 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -1129,8 +1129,9 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { /// * Windows /// On these systems, the read races with concurrent writes to the same file descriptor. pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { + // NOTE: serenity does not have preadv but it *does* have pwritev. const have_pread_but_not_preadv = switch (native_os) { - .windows, .macos, .ios, .watchos, .tvos, .visionos, .haiku => true, + .windows, .macos, .ios, .watchos, .tvos, .visionos, .haiku, .serenity => true, else => false, }; if (have_pread_but_not_preadv) { diff --git a/lib/std/start.zig b/lib/std/start.zig index f889885c84..30543ead8a 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -699,6 +699,7 @@ fn maybeIgnoreSigpipe() void { .visionos, .dragonfly, .freebsd, + .serenity, => true, else => false,