authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-02-20 01:27:54+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-02-20 04:56:07+01:00
loge95132476dfd26b28b55f7656f03dd1ec338b509
tree97cf18cef46cd273d71beef10b09184200cfb314
parent7dddcd043f23fe05f3333ec10a5592f385a46e49

std.os.linux: fix the mmap2 unit for various architectures

closes https://codeberg.org/ziglang/zig/issues/31033

1 files changed, 9 insertions(+), 1 deletions(-)

lib/std/os/linux.zig+9-1
......@@ -1118,6 +1118,14 @@ pub fn pivot_root(new_root: [*:0]const u8, put_old: [*:0]const u8) usize {
11181118 return syscall2(.pivot_root, @intFromPtr(new_root), @intFromPtr(put_old));
11191119}
11201120
1121fn mmap2Unit() u64 {
1122 return switch (native_arch) {
1123 .arc, .arceb, .m68k => std.heap.pageSize(),
1124 .or1k => 8 << 10,
1125 else => 4 << 10,
1126 };
1127}
1128
11211129pub fn mmap(address: ?[*]u8, length: usize, prot: PROT, flags: MAP, fd: i32, offset: i64) usize {
11221130 if (@hasField(SYS, "mmap2")) {
11231131 return syscall6(
......@@ -1127,7 +1135,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: PROT, flags: MAP, fd: i32, off
11271135 @as(u32, @bitCast(prot)),
11281136 @as(u32, @bitCast(flags)),
11291137 @bitCast(@as(isize, fd)),
1130 @truncate(@as(u64, @bitCast(offset)) / std.heap.pageSize()),
1138 @truncate(@as(u64, @bitCast(offset)) / mmap2Unit()),
11311139 );
11321140 } else {
11331141 // The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so