summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-03-29 03:40:58 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-03-29 03:40:58 +0000
commit2def43d3bcb4de42d4783e4c18413f7999ee5caf (patch)
tree6a498c0e0e2d461cf8ca65fcf3405c58794639e7 /src
parent0800daf01eeb8fc3a861454f25877d6e55853a47 (diff)
parente262fd0b88e0a2e16228cebf8e3da0f2bc110c77 (diff)
downloadnix-2def43d3bcb4de42d4783e4c18413f7999ee5caf.zip
Merge #876
876: add mlockall and munlockall r=asomers a=afck Closes #875
Diffstat (limited to 'src')
-rw-r--r--src/sys/mman.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/sys/mman.rs b/src/sys/mman.rs
index 9d1f88df..f2cc699b 100644
--- a/src/sys/mman.rs
+++ b/src/sys/mman.rs
@@ -205,14 +205,39 @@ libc_bitflags!{
}
}
+libc_bitflags!{
+ /// Flags for `mlockall`.
+ pub struct MlockAllFlags: c_int {
+ /// Lock pages that are currently mapped into the address space of the process.
+ MCL_CURRENT;
+ /// Lock pages which will become mapped into the address space of the process in the future.
+ MCL_FUTURE;
+ }
+}
+
+/// Locks all memory pages that contain part of the address range with `length` bytes starting at
+/// `addr`. Locked pages never move to the swap area.
pub unsafe fn mlock(addr: *const c_void, length: size_t) -> Result<()> {
Errno::result(libc::mlock(addr, length)).map(drop)
}
+/// Unlocks all memory pages that contain part of the address range with `length` bytes starting at
+/// `addr`.
pub unsafe fn munlock(addr: *const c_void, length: size_t) -> Result<()> {
Errno::result(libc::munlock(addr, length)).map(drop)
}
+/// Locks all memory pages mapped into this process' address space. Locked pages never move to the
+/// swap area.
+pub fn mlockall(flags: MlockAllFlags) -> Result<()> {
+ unsafe { Errno::result(libc::mlockall(flags.bits())) }.map(drop)
+}
+
+/// Unlocks all memory pages mapped into this process' address space.
+pub fn munlockall() -> Result<()> {
+ unsafe { Errno::result(libc::munlockall()) }.map(drop)
+}
+
/// Calls to mmap are inherently unsafe, so they must be made in an unsafe block. Typically
/// a higher-level abstraction will hide the unsafe interactions with the mmap'd region.
pub unsafe fn mmap(addr: *mut c_void, length: size_t, prot: ProtFlags, flags: MapFlags, fd: RawFd, offset: off_t) -> Result<*mut c_void> {