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 {...@@ -1118,6 +1118,14 @@ pub fn pivot_root(new_root: [*:0]const u8, put_old: [*:0]const u8) usize {
1118 return syscall2(.pivot_root, @intFromPtr(new_root), @intFromPtr(put_old));1118 return syscall2(.pivot_root, @intFromPtr(new_root), @intFromPtr(put_old));
1119}1119}
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
1121pub fn mmap(address: ?[*]u8, length: usize, prot: PROT, flags: MAP, fd: i32, offset: i64) usize {1129pub fn mmap(address: ?[*]u8, length: usize, prot: PROT, flags: MAP, fd: i32, offset: i64) usize {
1122 if (@hasField(SYS, "mmap2")) {1130 if (@hasField(SYS, "mmap2")) {
1123 return syscall6(1131 return syscall6(
...@@ -1127,7 +1135,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: PROT, flags: MAP, fd: i32, off...@@ -1127,7 +1135,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: PROT, flags: MAP, fd: i32, off
1127 @as(u32, @bitCast(prot)),1135 @as(u32, @bitCast(prot)),
1128 @as(u32, @bitCast(flags)),1136 @as(u32, @bitCast(flags)),
1129 @bitCast(@as(isize, fd)),1137 @bitCast(@as(isize, fd)),
1130 @truncate(@as(u64, @bitCast(offset)) / std.heap.pageSize()),1138 @truncate(@as(u64, @bitCast(offset)) / mmap2Unit()),
1131 );1139 );
1132 } else {1140 } else {
1133 // The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so1141 // The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so