authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-05-11 15:49:53+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-05-11 15:49:53+02:00
log8bb58fb4286ad03a243e32e31d67dd2bb5c117ef
treef21df7a0f677224dee305aa48a0b8a54dbb9109a
parent2bb8e1ff550ef2b2676e4f7ec3fdaf17aee8d715

std: Fix offset param splitting for preadv/pwritev

The kernel interface expects the offset as a low+high pair even on BE systems.

1 files changed, 16 insertions(+), 2 deletions(-)

lib/std/os/linux.zig+16-2
...@@ -59,6 +59,20 @@ const require_aligned_register_pair =...@@ -59,6 +59,20 @@ const require_aligned_register_pair =
59 std.Target.current.cpu.arch.isThumb();59 std.Target.current.cpu.arch.isThumb();
6060
61// Split a 64bit value into a {LSB,MSB} pair.61// Split a 64bit value into a {LSB,MSB} pair.
62// The LE/BE variants specify the endianness to assume.
63fn splitValueLE64(val: i64) [2]u32 {
64 const u = @bitCast(u64, val);
65 return [2]u32{
66 @truncate(u32, u),
67 @truncate(u32, u >> 32),
68 };
69}
70fn splitValueBE64(val: i64) [2]u32 {
71 return [2]u32{
72 @truncate(u32, u >> 32),
73 @truncate(u32, u),
74 };
75}
62fn splitValue64(val: i64) [2]u32 {76fn splitValue64(val: i64) [2]u32 {
63 const u = @bitCast(u64, val);77 const u = @bitCast(u64, val);
64 switch (builtin.endian) {78 switch (builtin.endian) {
...@@ -310,7 +324,7 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {...@@ -310,7 +324,7 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
310}324}
311325
312pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize {326pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize {
313 const offset_halves = splitValue64(offset);327 const offset_halves = splitValueLE64(offset);
314 return syscall5(328 return syscall5(
315 .preadv,329 .preadv,
316 @bitCast(usize, @as(isize, fd)),330 @bitCast(usize, @as(isize, fd)),
...@@ -343,7 +357,7 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {...@@ -343,7 +357,7 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
343}357}
344358
345pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) usize {359pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) usize {
346 const offset_halves = splitValue64(offset);360 const offset_halves = splitValueLE64(offset);
347 return syscall5(361 return syscall5(
348 .pwritev,362 .pwritev,
349 @bitCast(usize, @as(isize, fd)),363 @bitCast(usize, @as(isize, fd)),