authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-05-01 15:46:28+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-05-01 15:46:28+02:00
log718b43504eae6af063f8b9cf5803a82758c7e37b
treef2562920ce2921b3495a6fc1332a6d9d93d6aee9
parent69a9c1488d901e45440c195d42e7837a4c247f2b

std: Fix pwrite/pread syscalls on SPARC targets


1 files changed, 9 insertions(+), 5 deletions(-)

lib/std/os/linux.zig+9-5
...@@ -386,7 +386,7 @@ pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) us...@@ -386,7 +386,7 @@ pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) us
386}386}
387387
388pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {388pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
389 if (@hasField(SYS, "pread64")) {389 if (@hasField(SYS, "pread64") and usize_bits < 64) {
390 const offset_halves = splitValue64(offset);390 const offset_halves = splitValue64(offset);
391 if (require_aligned_register_pair) {391 if (require_aligned_register_pair) {
392 return syscall6(392 return syscall6(
...@@ -409,8 +409,10 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {...@@ -409,8 +409,10 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
409 );409 );
410 }410 }
411 } else {411 } else {
412 // Some architectures (eg. 64bit SPARC) pread is called pread64.
413 const S = if (!@hasField(SYS, "pread") and @hasField(SYS, "pread64")) .pread64 else .pread;
412 return syscall4(414 return syscall4(
413 .pread,415 S,
414 @bitCast(usize, @as(isize, fd)),416 @bitCast(usize, @as(isize, fd)),
415 @ptrToInt(buf),417 @ptrToInt(buf),
416 count,418 count,
...@@ -450,7 +452,7 @@ pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {...@@ -450,7 +452,7 @@ pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
450}452}
451453
452pub fn ftruncate(fd: i32, length: u64) usize {454pub fn ftruncate(fd: i32, length: u64) usize {
453 if (@hasField(SYS, "ftruncate64")) {455 if (@hasField(SYS, "ftruncate64") and usize_bits < 64) {
454 const length_halves = splitValue64(length);456 const length_halves = splitValue64(length);
455 if (require_aligned_register_pair) {457 if (require_aligned_register_pair) {
456 return syscall4(458 return syscall4(
...@@ -478,7 +480,7 @@ pub fn ftruncate(fd: i32, length: u64) usize {...@@ -478,7 +480,7 @@ pub fn ftruncate(fd: i32, length: u64) usize {
478}480}
479481
480pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize {482pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize {
481 if (@hasField(SYS, "pwrite64")) {483 if (@hasField(SYS, "pwrite64") and usize_bits < 64) {
482 const offset_halves = splitValue64(offset);484 const offset_halves = splitValue64(offset);
483485
484 if (require_aligned_register_pair) {486 if (require_aligned_register_pair) {
...@@ -502,8 +504,10 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize {...@@ -502,8 +504,10 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize {
502 );504 );
503 }505 }
504 } else {506 } else {
507 // Some architectures (eg. 64bit SPARC) pwrite is called pread64.
508 const S = if (!@hasField(SYS, "pwrite") and @hasField(SYS, "pwrite64")) .pwrite64 else .pwrite;
505 return syscall4(509 return syscall4(
506 .pwrite,510 S,
507 @bitCast(usize, @as(isize, fd)),511 @bitCast(usize, @as(isize, fd)),
508 @ptrToInt(buf),512 @ptrToInt(buf),
509 count,513 count,