#[repr(i32)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum Advice {
Normal = libc::MADV_NORMAL,
Random = libc::MADV_RANDOM,
Sequential = libc::MADV_SEQUENTIAL,
WillNeed = libc::MADV_WILLNEED,
#[cfg(target_os = "linux")]
DontFork = libc::MADV_DONTFORK,
#[cfg(target_os = "linux")]
DoFork = libc::MADV_DOFORK,
#[cfg(target_os = "linux")]
Mergeable = libc::MADV_MERGEABLE,
#[cfg(target_os = "linux")]
Unmergeable = libc::MADV_UNMERGEABLE,
#[cfg(target_os = "linux")]
HugePage = libc::MADV_HUGEPAGE,
#[cfg(target_os = "linux")]
NoHugePage = libc::MADV_NOHUGEPAGE,
#[cfg(target_os = "linux")]
DontDump = libc::MADV_DONTDUMP,
#[cfg(target_os = "linux")]
DoDump = libc::MADV_DODUMP,
#[cfg(target_os = "linux")]
HwPoison = libc::MADV_HWPOISON,
#[cfg(target_os = "linux")]
PopulateRead = libc::MADV_POPULATE_READ,
#[cfg(target_os = "linux")]
PopulateWrite = libc::MADV_POPULATE_WRITE,
#[cfg(target_vendor = "apple")]
ZeroWiredPages = libc::MADV_ZERO_WIRED_PAGES,
}
#[repr(i32)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum UncheckedAdvice {
DontNeed = libc::MADV_DONTNEED,
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
Free = libc::MADV_FREE,
#[cfg(target_os = "linux")]
Remove = libc::MADV_REMOVE,
#[cfg(target_vendor = "apple")]
FreeReusable = libc::MADV_FREE_REUSABLE,
#[cfg(target_vendor = "apple")]
FreeReuse = libc::MADV_FREE_REUSE,
}
#[cfg(target_os = "linux")]
impl Advice {
pub fn is_supported(self) -> bool {
(unsafe { libc::madvise(std::ptr::null_mut(), 0, self as libc::c_int) }) == 0
}
}
#[cfg(target_os = "linux")]
impl UncheckedAdvice {
pub fn is_supported(self) -> bool {
(unsafe { libc::madvise(std::ptr::null_mut(), 0, self as libc::c_int) }) == 0
}
}
#[cfg(test)]
mod tests {
#[cfg(target_os = "linux")]
#[test]
fn test_is_supported() {
use super::*;
assert!(Advice::Normal.is_supported());
assert!(Advice::Random.is_supported());
assert!(Advice::Sequential.is_supported());
assert!(Advice::WillNeed.is_supported());
assert!(UncheckedAdvice::DontNeed.is_supported());
}
}