@@ -1434,6 +1434,65 @@ pub fn process_vm_writev(pid: pid_t, local: [*]const iovec, local_count: usize,
1434
1434
);
1435
1435
}
1436
1436
1437
+ pub fn fadvise (fd : fd_t , offset : u64 , len : u64 , advice : usize ) usize {
1438
+ if (comptime std .Target .current .cpu .arch .isMIPS ()) {
1439
+ // MIPS requires a 7 argument syscall
1440
+
1441
+ const offset_halves = splitValue64 (@bitCast (u64 , offset ));
1442
+ const length_halves = splitValue64 (@bitCast (u64 , len ));
1443
+
1444
+ return syscall7 (
1445
+ .fadvise64 ,
1446
+ @bitCast (usize , @as (isize , fd )),
1447
+ 0 ,
1448
+ offset_halves [0 ],
1449
+ offset_halves [1 ],
1450
+ length_halves [0 ],
1451
+ length_halves [1 ],
1452
+ advice ,
1453
+ );
1454
+ } else if (comptime std .Target .current .cpu .arch .isARM ()) {
1455
+ // ARM reorders the arguments
1456
+
1457
+ const offset_halves = splitValue64 (@bitCast (u64 , offset ));
1458
+ const length_halves = splitValue64 (@bitCast (u64 , len ));
1459
+
1460
+ return syscall6 (
1461
+ .fadvise64_64 ,
1462
+ @bitCast (usize , @as (isize , fd )),
1463
+ advice ,
1464
+ offset_halves [0 ],
1465
+ offset_halves [1 ],
1466
+ length_halves [0 ],
1467
+ length_halves [1 ],
1468
+ );
1469
+ } else if (@hasField (SYS , "fadvise64_64" ) and usize_bits != 64 ) {
1470
+ // The extra usize check is needed to avoid SPARC64 because it provides both
1471
+ // fadvise64 and fadvise64_64 but the latter behaves differently than other platforms.
1472
+
1473
+ const offset_halves = splitValue64 (@bitCast (u64 , offset ));
1474
+ const length_halves = splitValue64 (@bitCast (u64 , len ));
1475
+
1476
+ return syscall6 (
1477
+ .fadvise64_64 ,
1478
+ @bitCast (usize , @as (isize , fd )),
1479
+ offset_halves [0 ],
1480
+ offset_halves [1 ],
1481
+ length_halves [0 ],
1482
+ length_halves [1 ],
1483
+ advice ,
1484
+ );
1485
+ } else {
1486
+ return syscall4 (
1487
+ .fadvise64 ,
1488
+ @bitCast (usize , @as (isize , fd )),
1489
+ @bitCast (usize , offset ),
1490
+ @bitCast (usize , len ),
1491
+ advice ,
1492
+ );
1493
+ }
1494
+ }
1495
+
1437
1496
test {
1438
1497
if (builtin .os .tag == .linux ) {
1439
1498
_ = @import ("linux/test.zig" );
0 commit comments