use std::fs::File;
use crate::error::Result;
use crate::advanced::{HugePageSize, NumaPolicy};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Advice {
Normal,
Random,
Sequential,
WillNeed,
DontNeed,
SequentialOnce,
RandomOnce,
Free,
}
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub use self::linux::*;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(windows)]
mod windows;
#[cfg(windows)]
pub use self::windows::*;
#[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
mod unsupported;
#[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
pub use self::unsupported::*;
pub unsafe fn map_file(
file: &File,
offset: u64,
len: usize,
readable: bool,
writable: bool,
executable: bool,
huge_pages: Option<HugePageSize>,
numa_policy: Option<NumaPolicy>,
stack: bool,
copy_on_write: bool,
populate: bool,
alignment: Option<usize>,
) -> Result<crate::mmap::MmapRaw> {
#[cfg(target_os = "linux")]
return linux::map_file(file, offset, len, readable, writable, executable, huge_pages, numa_policy, stack, copy_on_write, populate, alignment);
#[cfg(target_os = "macos")]
return macos::map_file(file, offset, len, readable, writable, executable, huge_pages, numa_policy, stack, copy_on_write, populate, alignment);
#[cfg(windows)]
return windows::map_file(file, offset, len, readable, writable, executable, huge_pages, numa_policy, stack, copy_on_write, populate, alignment);
#[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
return unsupported::map_file(file, offset, len, readable, writable, executable, huge_pages, numa_policy, stack, copy_on_write, populate, alignment);
}
pub unsafe fn map_anon(
len: usize,
readable: bool,
writable: bool,
executable: bool,
huge_pages: Option<HugePageSize>,
numa_policy: Option<NumaPolicy>,
stack: bool,
populate: bool,
alignment: Option<usize>,
) -> Result<crate::mmap::MmapRaw> {
#[cfg(target_os = "linux")]
return linux::map_anon(len, readable, writable, executable, huge_pages, numa_policy, stack, populate, alignment);
#[cfg(target_os = "macos")]
return macos::map_anon(len, readable, writable, executable, huge_pages, numa_policy, stack, populate, alignment);
#[cfg(windows)]
return windows::map_anon(len, readable, writable, executable, huge_pages, numa_policy, stack, populate, alignment);
#[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
return unsupported::map_anon(len, readable, writable, executable, huge_pages, numa_policy, stack, populate, alignment);
}
pub unsafe fn flush(addr: *mut u8, len: usize, async_flush: bool) -> Result<()> {
#[cfg(target_os = "linux")]
return linux::flush(addr, len, async_flush);
#[cfg(target_os = "macos")]
return macos::flush(addr, len, async_flush);
#[cfg(windows)]
return windows::flush(addr, len, async_flush);
#[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
return unsupported::flush(addr, len, async_flush);
}
pub unsafe fn unmap(addr: *mut u8, len: usize) -> Result<()> {
#[cfg(target_os = "linux")]
return linux::unmap(addr, len);
#[cfg(target_os = "macos")]
return macos::unmap(addr, len);
#[cfg(windows)]
return windows::unmap(addr, len);
#[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
return unsupported::unmap(addr, len);
}
pub unsafe fn advise(addr: *mut u8, len: usize, advice: Advice) -> Result<()> {
#[cfg(target_os = "linux")]
return linux::advise(addr, len, advice);
#[cfg(target_os = "macos")]
return macos::advise(addr, len, advice);
#[cfg(windows)]
return windows::advise(addr, len, advice);
#[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
return unsupported::advise(addr, len, advice);
}