| ... | ... | @@ -39,6 +39,13 @@ pub fn getauxval(index: usize) usize { |
| 39 | 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 | 49 | /// Get the errno from a syscall return value, or 0 for no error. |
| 43 | 50 | pub fn getErrno(r: usize) u12 { |
| 44 | 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 | 325 | |
| 319 | 326 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { |
| 320 | 327 | 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 | } |
| 329 | 348 | } else { |
| 330 | 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 | 363 | } |
| 345 | 364 | |
| 346 | 365 | pub fn pipe(fd: *[2]i32) usize { |
| 347 | | if (builtin.arch == .mipsel) { |
| 366 | if (comptime builtin.arch.isMIPS()) { |
| 348 | 367 | return syscall_pipe(fd); |
| 349 | 368 | } else if (@hasDecl(@This(), "SYS_pipe")) { |
| 350 | 369 | return syscall1(SYS_pipe, @ptrToInt(fd)); |