1//! The `madvise` function. 2//! 3//! # Safety 4//! 5//! `madvise` operates on a raw pointer. Some forms of `madvise` may 6//! mutate the memory or have other side effects. 7#![allow(unsafe_code)] 8 9use crate::{backend, io}; 10use core::ffi::c_void; 11 12pub use backend::mm::types::Advice; 13 14/// `posix_madvise(addr, len, advice)`—Declares an expected access pattern 15/// for a memory-mapped file. 16/// 17/// # Safety 18/// 19/// `addr` must be a valid pointer to memory that is appropriate to 20/// call `posix_madvise` on. Some forms of `advice` may mutate the memory 21/// or evoke a variety of side-effects on the mapping and/or the file. 22/// 23/// # References 24/// - [POSIX] 25/// - [Linux `madvise`] 26/// - [Linux `posix_madvise`] 27/// 28/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_madvise.html 29/// [Linux `madvise`]: https://man7.org/linux/man-pages/man2/madvise.2.html 30/// [Linux `posix_madvise`]: https://man7.org/linux/man-pages/man3/posix_madvise.3.html 31#[inline] 32#[doc(alias = "posix_madvise")] 33pub unsafe fn madvise(addr: *mut c_void, len: usize, advice: Advice) -> io::Result<()> { 34 backend::mm::syscalls::madvise(addr, len, advice) 35} 36