@@ -59,15 +59,16 @@ const require_aligned_register_pair =
5959 std .Target .current .cpu .arch .isThumb ();
6060
6161// Split a 64bit value into a {LSB,MSB} pair.
62- fn splitValue64 (val : u64 ) [2 ]u32 {
62+ fn splitValue64 (val : i64 ) [2 ]u32 {
63+ const u = @bitCast (u64 , val );
6364 switch (builtin .endian ) {
6465 .Little = > return [2 ]u32 {
65- @truncate (u32 , val ),
66- @truncate (u32 , val >> 32 ),
66+ @truncate (u32 , u ),
67+ @truncate (u32 , u >> 32 ),
6768 },
6869 .Big = > return [2 ]u32 {
69- @truncate (u32 , val >> 32 ),
70- @truncate (u32 , val ),
70+ @truncate (u32 , u >> 32 ),
71+ @truncate (u32 , u ),
7172 },
7273 }
7374}
@@ -243,7 +244,7 @@ pub fn umount2(special: [*:0]const u8, flags: u32) usize {
243244 return syscall2 (.umount2 , @ptrToInt (special ), flags );
244245}
245246
246- pub fn mmap (address : ? [* ]u8 , length : usize , prot : usize , flags : u32 , fd : i32 , offset : u64 ) usize {
247+ pub fn mmap (address : ? [* ]u8 , length : usize , prot : usize , flags : u32 , fd : i32 , offset : i64 ) usize {
247248 if (@hasField (SYS , "mmap2" )) {
248249 // Make sure the offset is also specified in multiples of page size
249250 if ((offset & (MMAP2_UNIT - 1 )) != 0 )
@@ -256,7 +257,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
256257 prot ,
257258 flags ,
258259 @bitCast (usize , @as (isize , fd )),
259- @truncate (usize , offset / MMAP2_UNIT ),
260+ @truncate (usize , @bitCast ( u64 , offset ) / MMAP2_UNIT ),
260261 );
261262 } else {
262263 return syscall6 (
@@ -266,7 +267,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
266267 prot ,
267268 flags ,
268269 @bitCast (usize , @as (isize , fd )),
269- offset ,
270+ @bitCast ( u64 , offset ) ,
270271 );
271272 }
272273}
@@ -308,7 +309,7 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
308309 return syscall3 (.read , @bitCast (usize , @as (isize , fd )), @ptrToInt (buf ), count );
309310}
310311
311- pub fn preadv (fd : i32 , iov : [* ]const iovec , count : usize , offset : u64 ) usize {
312+ pub fn preadv (fd : i32 , iov : [* ]const iovec , count : usize , offset : i64 ) usize {
312313 const offset_halves = splitValue64 (offset );
313314 return syscall5 (
314315 .preadv ,
@@ -320,7 +321,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
320321 );
321322}
322323
323- pub fn preadv2 (fd : i32 , iov : [* ]const iovec , count : usize , offset : u64 , flags : kernel_rwf ) usize {
324+ pub fn preadv2 (fd : i32 , iov : [* ]const iovec , count : usize , offset : i64 , flags : kernel_rwf ) usize {
324325 const offset_halves = splitValue64 (offset );
325326 return syscall6 (
326327 .preadv2 ,
@@ -341,7 +342,7 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
341342 return syscall3 (.writev , @bitCast (usize , @as (isize , fd )), @ptrToInt (iov ), count );
342343}
343344
344- pub fn pwritev (fd : i32 , iov : [* ]const iovec_const , count : usize , offset : u64 ) usize {
345+ pub fn pwritev (fd : i32 , iov : [* ]const iovec_const , count : usize , offset : i64 ) usize {
345346 const offset_halves = splitValue64 (offset );
346347 return syscall5 (
347348 .pwritev ,
@@ -353,7 +354,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us
353354 );
354355}
355356
356- pub fn pwritev2 (fd : i32 , iov : [* ]const iovec_const , count : usize , offset : u64 , flags : kernel_rwf ) usize {
357+ pub fn pwritev2 (fd : i32 , iov : [* ]const iovec_const , count : usize , offset : i64 , flags : kernel_rwf ) usize {
357358 const offset_halves = splitValue64 (offset );
358359 return syscall6 (
359360 .pwritev2 ,
@@ -386,7 +387,7 @@ pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) us
386387 return syscall3 (.symlinkat , @ptrToInt (existing ), @bitCast (usize , @as (isize , newfd )), @ptrToInt (newpath ));
387388}
388389
389- pub fn pread (fd : i32 , buf : [* ]u8 , count : usize , offset : u64 ) usize {
390+ pub fn pread (fd : i32 , buf : [* ]u8 , count : usize , offset : i64 ) usize {
390391 if (@hasField (SYS , "pread64" ) and usize_bits < 64 ) {
391392 const offset_halves = splitValue64 (offset );
392393 if (require_aligned_register_pair ) {
@@ -417,7 +418,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
417418 @bitCast (usize , @as (isize , fd )),
418419 @ptrToInt (buf ),
419420 count ,
420- offset ,
421+ @bitCast ( u64 , offset ) ,
421422 );
422423 }
423424}
@@ -452,7 +453,7 @@ pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
452453 return syscall3 (.write , @bitCast (usize , @as (isize , fd )), @ptrToInt (buf ), count );
453454}
454455
455- pub fn ftruncate (fd : i32 , length : u64 ) usize {
456+ pub fn ftruncate (fd : i32 , length : i64 ) usize {
456457 if (@hasField (SYS , "ftruncate64" ) and usize_bits < 64 ) {
457458 const length_halves = splitValue64 (length );
458459 if (require_aligned_register_pair ) {
@@ -475,12 +476,12 @@ pub fn ftruncate(fd: i32, length: u64) usize {
475476 return syscall2 (
476477 .ftruncate ,
477478 @bitCast (usize , @as (isize , fd )),
478- @truncate (usize , length ),
479+ @bitCast (usize , length ),
479480 );
480481 }
481482}
482483
483- pub fn pwrite (fd : i32 , buf : [* ]const u8 , count : usize , offset : u64 ) usize {
484+ pub fn pwrite (fd : i32 , buf : [* ]const u8 , count : usize , offset : i64 ) usize {
484485 if (@hasField (SYS , "pwrite64" ) and usize_bits < 64 ) {
485486 const offset_halves = splitValue64 (offset );
486487
@@ -512,7 +513,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize {
512513 @bitCast (usize , @as (isize , fd )),
513514 @ptrToInt (buf ),
514515 count ,
515- offset ,
516+ @bitCast ( u64 , offset ) ,
516517 );
517518 }
518519}
0 commit comments