| ... | @@ -39,6 +39,13 @@ pub fn getauxval(index: usize) usize { | ... | @@ -39,6 +39,13 @@ pub fn getauxval(index: usize) usize { |
| 39 | return 0; | 39 | return 0; |
| 40 | } | 40 | } |
| 41 | | 41 | |
| | 42 | // Some architectures require 64bit parameters for some syscalls to be passed in |
| | 43 | // even-aligned register pair |
| | 44 | const require_aligned_register_pair = // |
| | 45 | comptime builtin.arch.isMIPS() or |
| | 46 | comptime builtin.arch.isARM() or |
| | 47 | comptime builtin.arch.isThumb(); |
| | 48 | |
| 42 | /// Get the errno from a syscall return value, or 0 for no error. | 49 | /// Get the errno from a syscall return value, or 0 for no error. |
| 43 | pub fn getErrno(r: usize) u12 { | 50 | pub fn getErrno(r: usize) u12 { |
| 44 | const signed_r = @bitCast(isize, r); | 51 | const signed_r = @bitCast(isize, r); |
| ... | @@ -318,14 +325,26 @@ pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) us | ... | @@ -318,14 +325,26 @@ pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) us |
| 318 | | 325 | |
| 319 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { | 326 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { |
| 320 | if (@hasDecl(@This(), "SYS_pread64")) { | 327 | if (@hasDecl(@This(), "SYS_pread64")) { |
| 321 | return syscall5( | 328 | if (require_aligned_register_pair) { |
| 322 | SYS_pread64, | 329 | return syscall6( |
| 323 | @bitCast(usize, @as(isize, fd)), | 330 | SYS_pread64, |
| 324 | @ptrToInt(buf), | 331 | @bitCast(usize, @as(isize, fd)), |
| 325 | count, | 332 | @ptrToInt(buf), |
| 326 | @truncate(usize, offset), | 333 | count, |
| 327 | @truncate(usize, offset >> 32), | 334 | 0, |
| 328 | ); | 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 | } |
| 329 | } else { | 348 | } else { |
| 330 | return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset); | 349 | return syscall4(SYS_pread, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count, offset); |
| 331 | } | 350 | } |
| ... | @@ -344,7 +363,7 @@ pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize { | ... | @@ -344,7 +363,7 @@ pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize { |
| 344 | } | 363 | } |
| 345 | | 364 | |
| 346 | pub fn pipe(fd: *[2]i32) usize { | 365 | pub fn pipe(fd: *[2]i32) usize { |
| 347 | if (builtin.arch == .mipsel) { | 366 | if (comptime builtin.arch.isMIPS()) { |
| 348 | return syscall_pipe(fd); | 367 | return syscall_pipe(fd); |
| 349 | } else if (@hasDecl(@This(), "SYS_pipe")) { | 368 | } else if (@hasDecl(@This(), "SYS_pipe")) { |
| 350 | return syscall1(SYS_pipe, @ptrToInt(fd)); | 369 | return syscall1(SYS_pipe, @ptrToInt(fd)); |