| ... | @@ -1454,6 +1454,65 @@ pub fn process_vm_writev(pid: pid_t, local: [*]const iovec, local_count: usize, | ... | @@ -1454,6 +1454,65 @@ pub fn process_vm_writev(pid: pid_t, local: [*]const iovec, local_count: usize, |
| 1454 | ); | 1454 | ); |
| 1455 | } | 1455 | } |
| 1456 | | 1456 | |
| | 1457 | pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize { |
| | 1458 | if (comptime std.Target.current.cpu.arch.isMIPS()) { |
| | 1459 | // MIPS requires a 7 argument syscall |
| | 1460 | |
| | 1461 | const offset_halves = splitValue64(offset); |
| | 1462 | const length_halves = splitValue64(len); |
| | 1463 | |
| | 1464 | return syscall7( |
| | 1465 | .fadvise64, |
| | 1466 | @bitCast(usize, @as(isize, fd)), |
| | 1467 | 0, |
| | 1468 | offset_halves[0], |
| | 1469 | offset_halves[1], |
| | 1470 | length_halves[0], |
| | 1471 | length_halves[1], |
| | 1472 | advice, |
| | 1473 | ); |
| | 1474 | } else if (comptime std.Target.current.cpu.arch.isARM()) { |
| | 1475 | // ARM reorders the arguments |
| | 1476 | |
| | 1477 | const offset_halves = splitValue64(offset); |
| | 1478 | const length_halves = splitValue64(len); |
| | 1479 | |
| | 1480 | return syscall6( |
| | 1481 | .fadvise64_64, |
| | 1482 | @bitCast(usize, @as(isize, fd)), |
| | 1483 | advice, |
| | 1484 | offset_halves[0], |
| | 1485 | offset_halves[1], |
| | 1486 | length_halves[0], |
| | 1487 | length_halves[1], |
| | 1488 | ); |
| | 1489 | } else if (@hasField(SYS, "fadvise64_64") and usize_bits != 64) { |
| | 1490 | // The extra usize check is needed to avoid SPARC64 because it provides both |
| | 1491 | // fadvise64 and fadvise64_64 but the latter behaves differently than other platforms. |
| | 1492 | |
| | 1493 | const offset_halves = splitValue64(offset); |
| | 1494 | const length_halves = splitValue64(len); |
| | 1495 | |
| | 1496 | return syscall6( |
| | 1497 | .fadvise64_64, |
| | 1498 | @bitCast(usize, @as(isize, fd)), |
| | 1499 | offset_halves[0], |
| | 1500 | offset_halves[1], |
| | 1501 | length_halves[0], |
| | 1502 | length_halves[1], |
| | 1503 | advice, |
| | 1504 | ); |
| | 1505 | } else { |
| | 1506 | return syscall4( |
| | 1507 | .fadvise64, |
| | 1508 | @bitCast(usize, @as(isize, fd)), |
| | 1509 | @bitCast(usize, offset), |
| | 1510 | @bitCast(usize, len), |
| | 1511 | advice, |
| | 1512 | ); |
| | 1513 | } |
| | 1514 | } |
| | 1515 | |
| 1457 | test { | 1516 | test { |
| 1458 | if (std.Target.current.os.tag == .linux) { | 1517 | if (std.Target.current.os.tag == .linux) { |
| 1459 | _ = @import("linux/test.zig"); | 1518 | _ = @import("linux/test.zig"); |