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