diff options
author | Andreas Fackler <AndreasFackler@gmx.de> | 2018-03-24 15:18:10 +0100 |
---|---|---|
committer | Andreas Fackler <AndreasFackler@gmx.de> | 2018-03-27 09:02:53 +0200 |
commit | 89a0b05862f8be723130c6bcb5bb742ee30452f3 (patch) | |
tree | 4c8b1da33e897c7053a1001ada944b628989c4bf /src/sys/mman.rs | |
parent | 0418d346c5343d4b55d580dc9fd66cd2a150a0c3 (diff) | |
download | nix-89a0b05862f8be723130c6bcb5bb742ee30452f3.zip |
add mlockall and munlockall
Diffstat (limited to 'src/sys/mman.rs')
-rw-r--r-- | src/sys/mman.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/sys/mman.rs b/src/sys/mman.rs index 9d1f88df..4aac67ac 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -205,6 +205,16 @@ 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; + } +} + pub unsafe fn mlock(addr: *const c_void, length: size_t) -> Result<()> { Errno::result(libc::mlock(addr, length)).map(drop) } @@ -213,6 +223,14 @@ pub unsafe fn munlock(addr: *const c_void, length: size_t) -> Result<()> { Errno::result(libc::munlock(addr, length)).map(drop) } +pub fn mlockall(flags: MlockAllFlags) -> Result<()> { + unsafe { Errno::result(libc::mlockall(flags.bits())) }.map(drop) +} + +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> { |