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 =
5959 std.Target.current.cpu.arch.isThumb();
6060
6161// 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}
6276fn splitValue64(val: i64) [2]u32 {
6377 const u = @bitCast(u64, val);
6478 switch (builtin.endian) {
......@@ -310,7 +324,7 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
310324}
311325
312326pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize {
313 const offset_halves = splitValue64(offset);
327 const offset_halves = splitValueLE64(offset);
314328 return syscall5(
315329 .preadv,
316330 @bitCast(usize, @as(isize, fd)),
......@@ -343,7 +357,7 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
343357}
344358
345359pub 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);
347361 return syscall5(
348362 .pwritev,
349363 @bitCast(usize, @as(isize, fd)),