From 84745e1eb25c369611aaab9d9041e76b9e1613c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 13 Oct 2026 20:45:29 +0200 Subject: [PATCH] std.c: fix mremap() signature for serenity --- lib/std/c.zig | 6 +++++- lib/std/c/serenity.zig | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 556d2124168b81b44436530988bf49f99c683679..7a9b706d0a06ab0fd51a40634ed3fbf92a36d28b 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -10905,7 +10905,10 @@ pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize; pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: off_t) isize; pub extern "c" fn mmap(addr: ?*align(page_size) anyopaque, len: usize, prot: PROT, flags: MAP, fd: fd_t, offset: off_t) *anyopaque; pub extern "c" fn munmap(addr: *align(page_size) const anyopaque, len: usize) c_int; -pub extern "c" fn mremap(addr: ?*align(page_size) const anyopaque, old_len: usize, new_len: usize, flags: MREMAP, ...) *anyopaque; +pub const mremap = switch (native_os) { + .serenity => serenity.mremap, + else => private.mremap, +}; pub extern "c" fn mprotect(addr: *align(page_size) anyopaque, len: usize, prot: PROT) c_int; pub extern "c" fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8) c_int; pub extern "c" fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: c_uint) c_int; @@ -11849,6 +11852,7 @@ const private = struct { extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int; extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int; + extern "c" fn mremap(addr: ?*align(page_size) const anyopaque, old_len: usize, new_len: usize, flags: MREMAP, ...) *anyopaque; extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; extern "c" fn pipe2(fds: *[2]fd_t, flags: O) c_int; extern "c" fn readdir(dir: *DIR) ?*dirent; diff --git a/lib/std/c/serenity.zig b/lib/std/c/serenity.zig index d391f9d82ce080b9b9e602e8bf75865290e47ae4..eb416e7f18a7756725d3e1b10da028045da99fe8 100644 --- a/lib/std/c/serenity.zig +++ b/lib/std/c/serenity.zig @@ -1,10 +1,12 @@ const std = @import("../std.zig"); const assert = std.debug.assert; const builtin = @import("builtin"); +const MAP = std.c.MAP; const O = std.c.O; const clockid_t = std.c.clockid_t; const pid_t = std.c.pid_t; const timespec = std.c.timespec; +const page_size = std.heap.page_size_min; comptime { assert(builtin.os.tag == .serenity); // Prevent access of std.c symbols on wrong OS. @@ -68,6 +70,9 @@ pub extern "c" fn anon_create(size: usize, options: O) c_int; pub extern "c" fn getkeymap(name_buffer: [*]u8, name_buffer_size: usize, map: [*]u32, shift_map: [*]u32, alt_map: [*]u32, altgr_map: [*]u32, shift_altgr_map: [*]u32) c_int; pub extern "c" fn setkeymap(name: [*]const u8, map: [*]const u32, shift_map: [*]const u32, alt_map: [*]const u32, altgr_map: [*]const u32, shift_altgr_map: [*]const u32) c_int; +// https://github.com/SerenityOS/serenity/blob/fe4f3879551f2fdd8a24de06b88f4450e2f3b93d/Userland/Libraries/LibC/sys/mman.h#L17 +pub extern "c" fn mremap(old_address: ?*align(page_size) anyopaque, old_size: usize, new_size: usize, flags: MAP) *anyopaque; + // https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/netinet/in.h#L29 pub const IP = struct { pub const TOS = 1; -- 2.54.0