diff --git a/src/header/sys_mman/mod.rs b/src/header/sys_mman/mod.rs index 3133a74159..f3f6f628b9 100644 --- a/src/header/sys_mman/mod.rs +++ b/src/header/sys_mman/mod.rs @@ -1,3 +1,7 @@ +//! `sys/mman.h` implementation. +//! +//! See . + use crate::{ c_str::{CStr, CString}, error::{Errno, ResultExt}, @@ -44,16 +48,27 @@ pub const POSIX_MADV_SEQUENTIAL: c_int = 2; pub const POSIX_MADV_WILLNEED: c_int = 3; pub const POSIX_MADV_WONTNEED: c_int = 4; +/// Non-POSIX, see . +#[no_mangle] +pub unsafe extern "C" fn madvise(addr: *mut c_void, len: size_t, flags: c_int) -> c_int { + Sys::madvise(addr, len, flags) + .map(|()| 0) + .or_minus_one_errno() +} + +/// See . #[no_mangle] pub unsafe extern "C" fn mlock(addr: *const c_void, len: usize) -> c_int { Sys::mlock(addr, len).map(|()| 0).or_minus_one_errno() } +/// See . #[no_mangle] pub unsafe extern "C" fn mlockall(flags: c_int) -> c_int { Sys::mlockall(flags).map(|()| 0).or_minus_one_errno() } +/// See . #[no_mangle] pub unsafe extern "C" fn mmap( addr: *mut c_void, @@ -72,8 +87,17 @@ pub unsafe extern "C" fn mmap( } } +/// See . #[no_mangle] -unsafe extern "C" fn mremap( +pub unsafe extern "C" fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int { + Sys::mprotect(addr, len, prot) + .map(|()| 0) + .or_minus_one_errno() +} + +/// Non-POSIX, see . +#[no_mangle] +pub unsafe extern "C" fn mremap( old_address: *mut c_void, old_size: usize, new_size: usize, @@ -90,13 +114,7 @@ unsafe extern "C" fn mremap( } } -#[no_mangle] -pub unsafe extern "C" fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int { - Sys::mprotect(addr, len, prot) - .map(|()| 0) - .or_minus_one_errno() -} - +/// See . #[no_mangle] pub unsafe extern "C" fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int { Sys::msync(addr, len, flags) @@ -104,28 +122,24 @@ pub unsafe extern "C" fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> .or_minus_one_errno() } +/// See . #[no_mangle] pub unsafe extern "C" fn munlock(addr: *const c_void, len: usize) -> c_int { Sys::munlock(addr, len).map(|()| 0).or_minus_one_errno() } +/// See . #[no_mangle] pub unsafe extern "C" fn munlockall() -> c_int { Sys::munlockall().map(|()| 0).or_minus_one_errno() } +/// See . #[no_mangle] pub unsafe extern "C" fn munmap(addr: *mut c_void, len: size_t) -> c_int { Sys::munmap(addr, len).map(|()| 0).or_minus_one_errno() } -#[no_mangle] -pub unsafe extern "C" fn madvise(addr: *mut c_void, len: size_t, flags: c_int) -> c_int { - Sys::madvise(addr, len, flags) - .map(|()| 0) - .or_minus_one_errno() -} - #[cfg(target_os = "linux")] static SHM_PATH: &'static [u8] = b"/dev/shm/"; @@ -152,12 +166,14 @@ unsafe fn shm_path(name: *const c_char) -> CString { CString::from_vec_unchecked(path) } +/// See . #[no_mangle] pub unsafe extern "C" fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t) -> c_int { let path = shm_path(name); fcntl::open(path.as_ptr(), oflag, mode) } +/// See . #[no_mangle] pub unsafe extern "C" fn shm_unlink(name: *const c_char) -> c_int { let path = shm_path(name);