authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-03 17:19:40+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-03 11:59:16-05:00
loga6fb6dcfc96ad63f9a21110165728da0b8311660
treee45d24811bdcb06dfb258c1f59f074b2a8bf21d5
parent226b801830857a9075fdd8180739105bb73eed0e

linux: Correct pread64 syscall for ARM/MIPS

Closes #4615

2 files changed, 28 insertions(+), 13 deletions(-)

lib/std/os/linux.zig+28-9
......@@ -39,6 +39,13 @@ pub fn getauxval(index: usize) usize {
3939 return 0;
4040}
4141
42// Some architectures require 64bit parameters for some syscalls to be passed in
43// even-aligned register pair
44const require_aligned_register_pair = //
45 comptime builtin.arch.isMIPS() or
46 comptime builtin.arch.isARM() or
47 comptime builtin.arch.isThumb();
48
4249/// Get the errno from a syscall return value, or 0 for no error.
4350pub fn getErrno(r: usize) u12 {
4451 const signed_r = @bitCast(isize, r);
......@@ -318,14 +325,26 @@ pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) us
318325
319326pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
320327 if (@hasDecl(@This(), "SYS_pread64")) {
321 return syscall5(
322 SYS_pread64,
323 @bitCast(usize, @as(isize, fd)),
324 @ptrToInt(buf),
325 count,
326 @truncate(usize, offset),
327 @truncate(usize, offset >> 32),
328 );
328 if (require_aligned_register_pair) {
329 return syscall6(
330 SYS_pread64,
331 @bitCast(usize, @as(isize, fd)),
332 @ptrToInt(buf),
333 count,
334 0,
335 @truncate(usize, offset),
336 @truncate(usize, offset >> 32),
337 );
338 } else {
339 return syscall5(
340 SYS_pread64,
341 @bitCast(usize, @as(isize, fd)),
342 @ptrToInt(buf),
343 count,
344 @truncate(usize, offset),
345 @truncate(usize, offset >> 32),
346 );
347 }
329348 } else {
330349 return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset);
331350 }
......@@ -344,7 +363,7 @@ pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {
344363}
345364
346365pub fn pipe(fd: *[2]i32) usize {
347 if (builtin.arch == .mipsel) {
366 if (comptime builtin.arch.isMIPS()) {
348367 return syscall_pipe(fd);
349368 } else if (@hasDecl(@This(), "SYS_pipe")) {
350369 return syscall1(SYS_pipe, @ptrToInt(fd));
lib/std/os/test.zig-4
......@@ -45,10 +45,6 @@ fn testThreadIdFn(thread_id: *Thread.Id) void {
4545}
4646
4747test "sendfile" {
48 if (std.Target.current.cpu.arch == .mipsel) {
49 // https://github.com/ziglang/zig/issues/4615
50 return error.SkipZigTest;
51 }
5248 try fs.makePath(a, "os_test_tmp");
5349 defer fs.deleteTree("os_test_tmp") catch {};
5450