authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-13 20:45:29+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-22 22:15:31+02:00
log84745e1eb25c369611aaab9d9041e76b9e1613c4
treea22b6fa9094dc9454552aba338ae2b801834fd40
parent10ecbd71deaab97378b2aadd603abb2a4f233e2f
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.c: fix mremap() signature for serenity


2 files changed, 10 insertions(+), 1 deletions(-)

lib/std/c.zig+5-1
...@@ -10905,7 +10905,10 @@ pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;...@@ -10905,7 +10905,10 @@ pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;
10905pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: off_t) isize;10905pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: off_t) isize;
10906pub extern "c" fn mmap(addr: ?*align(page_size) anyopaque, len: usize, prot: PROT, flags: MAP, fd: fd_t, offset: off_t) *anyopaque;10906pub extern "c" fn mmap(addr: ?*align(page_size) anyopaque, len: usize, prot: PROT, flags: MAP, fd: fd_t, offset: off_t) *anyopaque;
10907pub extern "c" fn munmap(addr: *align(page_size) const anyopaque, len: usize) c_int;10907pub extern "c" fn munmap(addr: *align(page_size) const anyopaque, len: usize) c_int;
10908pub extern "c" fn mremap(addr: ?*align(page_size) const anyopaque, old_len: usize, new_len: usize, flags: MREMAP, ...) *anyopaque;10908pub const mremap = switch (native_os) {
10909 .serenity => serenity.mremap,
10910 else => private.mremap,
10911};
10909pub extern "c" fn mprotect(addr: *align(page_size) anyopaque, len: usize, prot: PROT) c_int;10912pub extern "c" fn mprotect(addr: *align(page_size) anyopaque, len: usize, prot: PROT) c_int;
10910pub extern "c" fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8) c_int;10913pub extern "c" fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8) c_int;
10911pub extern "c" fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: c_uint) c_int;10914pub 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 {...@@ -11849,6 +11852,7 @@ const private = struct {
11849 extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;11852 extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
11850 extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int;11853 extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int;
11851 extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;11854 extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
11855 extern "c" fn mremap(addr: ?*align(page_size) const anyopaque, old_len: usize, new_len: usize, flags: MREMAP, ...) *anyopaque;
11852 extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;11856 extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
11853 extern "c" fn pipe2(fds: *[2]fd_t, flags: O) c_int;11857 extern "c" fn pipe2(fds: *[2]fd_t, flags: O) c_int;
11854 extern "c" fn readdir(dir: *DIR) ?*dirent;11858 extern "c" fn readdir(dir: *DIR) ?*dirent;
lib/std/c/serenity.zig+5
...@@ -1,10 +1,12 @@...@@ -1,10 +1,12 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const MAP = std.c.MAP;
4const O = std.c.O;5const O = std.c.O;
5const clockid_t = std.c.clockid_t;6const clockid_t = std.c.clockid_t;
6const pid_t = std.c.pid_t;7const pid_t = std.c.pid_t;
7const timespec = std.c.timespec;8const timespec = std.c.timespec;
9const page_size = std.heap.page_size_min;
810
9comptime {11comptime {
10 assert(builtin.os.tag == .serenity); // Prevent access of std.c symbols on wrong OS.12 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;...@@ -68,6 +70,9 @@ pub extern "c" fn anon_create(size: usize, options: O) c_int;
68pub 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;70pub 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;
69pub 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;71pub 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;
7072
73// https://github.com/SerenityOS/serenity/blob/fe4f3879551f2fdd8a24de06b88f4450e2f3b93d/Userland/Libraries/LibC/sys/mman.h#L17
74pub extern "c" fn mremap(old_address: ?*align(page_size) anyopaque, old_size: usize, new_size: usize, flags: MAP) *anyopaque;
75
71// https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/netinet/in.h#L2976// https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/netinet/in.h#L29
72pub const IP = struct {77pub const IP = struct {
73 pub const TOS = 1;78 pub const TOS = 1;