Commit cd6795fc06

Alex Rønne Petersen <alex@alexrp.com>
2024-10-01 12:15:10
std.os.linux: Fix mmap() syscall invocation for s390x.
The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so it takes a single pointer to an array of arguments instead.
1 parent 07c9435
Changed files (2)
lib
std
lib/std/os/linux/tls.zig
@@ -541,7 +541,19 @@ inline fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: linux.MAP, fd
             @as(usize, @truncate(@as(u64, @bitCast(offset)) / linux.MMAP2_UNIT)),
         });
     } else {
-        return @call(.always_inline, linux.syscall6, .{
+        // The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so
+        // it takes a single pointer to an array of arguments instead.
+        return if (native_arch == .s390x) @call(.always_inline, linux.syscall1, .{
+            .mmap,
+            @intFromPtr(&[_]usize{
+                @intFromPtr(address),
+                length,
+                prot,
+                @as(u32, @bitCast(flags)),
+                @as(usize, @bitCast(@as(isize, fd))),
+                @as(u64, @bitCast(offset)),
+            }),
+        }) else @call(.always_inline, linux.syscall6, .{
             .mmap,
             @intFromPtr(address),
             length,
lib/std/os/linux.zig
@@ -904,7 +904,19 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: MAP, fd: i32, of
             @truncate(@as(u64, @bitCast(offset)) / MMAP2_UNIT),
         );
     } else {
-        return syscall6(
+        // The s390x mmap() syscall existed before Linux supported syscalls with 5+ parameters, so
+        // it takes a single pointer to an array of arguments instead.
+        return if (native_arch == .s390x) syscall1(
+            .mmap,
+            @intFromPtr(&[_]usize{
+                @intFromPtr(address),
+                length,
+                prot,
+                @as(u32, @bitCast(flags)),
+                @bitCast(@as(isize, fd)),
+                @as(u64, @bitCast(offset)),
+            }),
+        ) else syscall6(
             .mmap,
             @intFromPtr(address),
             length,