Merge branch 'sys-mman-docs' into 'master'
Add docs for sys/mman.h, make mremap pub See merge request redox-os/relibc!543
This commit is contained in:
+31
-15
@@ -1,3 +1,7 @@
|
||||
//! `sys/mman.h` implementation.
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_mman.h.html>.
|
||||
|
||||
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 <https://www.man7.org/linux/man-pages/man2/madvise.2.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlock.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlockall.html>.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn mlockall(flags: c_int) -> c_int {
|
||||
Sys::mlockall(flags).map(|()| 0).or_minus_one_errno()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mmap.html>.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn mmap(
|
||||
addr: *mut c_void,
|
||||
@@ -72,8 +87,17 @@ pub unsafe extern "C" fn mmap(
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mprotect.html>.
|
||||
#[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 <https://www.man7.org/linux/man-pages/man2/mremap.2.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/msync.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlock.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mlockall.html>.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn munlockall() -> c_int {
|
||||
Sys::munlockall().map(|()| 0).or_minus_one_errno()
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/munmap.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/shm_open.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/shm_unlink.html>.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn shm_unlink(name: *const c_char) -> c_int {
|
||||
let path = shm_path(name);
|
||||
|
||||
Reference in New Issue
Block a user