diff options
author | Philipp Matthias Schaefer <philipp.matthias.schaefer@posteo.de> | 2016-01-23 15:00:47 +0100 |
---|---|---|
committer | Philipp Matthias Schaefer <philipp.matthias.schaefer@posteo.de> | 2016-01-28 20:46:55 +0100 |
commit | 85482abfde981e5419cee338d111c352cb457151 (patch) | |
tree | 0a1f6bbb15ea0afed8e743d97bd2bc373b9cc2a8 /src/sys/mman.rs | |
parent | 1d5c77ce2808da0e4108c4713aea3ae47b1dc328 (diff) | |
download | nix-85482abfde981e5419cee338d111c352cb457151.zip |
Convert PROT_ flags to bitflags! type.
Diffstat (limited to 'src/sys/mman.rs')
-rw-r--r-- | src/sys/mman.rs | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/src/sys/mman.rs b/src/sys/mman.rs index 1dd0b94d..9785db3c 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -1,11 +1,24 @@ use {Errno, Error, Result, NixPath}; use fcntl::OFlag; -use libc::{c_void, size_t, off_t, mode_t}; +use libc::{self, c_void, size_t, off_t, mode_t}; use sys::stat::Mode; use std::os::unix::io::RawFd; pub use self::consts::*; +bitflags!{ + flags ProtFlags : libc::c_int { + const PROT_NONE = libc::PROT_NONE, + const PROT_READ = libc::PROT_READ, + const PROT_WRITE = libc::PROT_WRITE, + const PROT_EXEC = libc::PROT_EXEC, + #[cfg(any(target_os = "linux", target_os = "android"))] + const PROT_GROWSDOWN = libc::PROT_GROWSDOWN, + #[cfg(any(target_os = "linux", target_os = "android"))] + const PROT_GROWSUP = libc::PROT_GROWSUP, + } +} + #[cfg(any(target_os = "linux", target_os = "android"))] mod consts { use libc::{self, c_int}; @@ -31,15 +44,6 @@ mod consts { } } - pub type MmapProt = c_int; - - pub const PROT_READ: MmapProt = 0x1; - pub const PROT_WRITE: MmapProt = 0x2; - pub const PROT_EXEC: MmapProt = 0x4; - pub const PROT_NONE: MmapProt = 0x0; - pub const PROT_GROWSDOWN: MmapProt = 0x01000000; - pub const PROT_GROWSUP: MmapProt = 0x02000000; - pub type MmapAdvise = c_int; pub const MADV_NORMAL : MmapAdvise = 0; /* No further special treatment. */ @@ -84,13 +88,6 @@ mod consts { } } - pub type MmapProt = c_int; - - pub const PROT_READ: MmapProt = 0x1; - pub const PROT_WRITE: MmapProt = 0x2; - pub const PROT_EXEC: MmapProt = 0x4; - pub const PROT_NONE: MmapProt = 0x0; - pub type MmapAdvise = c_int; pub const MADV_NORMAL : MmapAdvise = 0; /* No further special treatment. */ @@ -138,13 +135,6 @@ mod consts { } } - pub type MmapProt = c_int; - - pub const PROT_READ: MmapProt = 0x1; - pub const PROT_WRITE: MmapProt = 0x2; - pub const PROT_EXEC: MmapProt = 0x4; - pub const PROT_NONE: MmapProt = 0x0; - pub type MmapAdvise = c_int; pub const MADV_NORMAL : MmapAdvise = 0; /* No further special treatment. */ @@ -205,8 +195,8 @@ pub fn munlock(addr: *const c_void, length: size_t) -> Result<()> { /// 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 fn mmap(addr: *mut c_void, length: size_t, prot: MmapProt, flags: MmapFlags, fd: RawFd, offset: off_t) -> Result<*mut c_void> { - let ret = unsafe { ffi::mmap(addr, length, prot, flags.bits(), fd, offset) }; +pub fn mmap(addr: *mut c_void, length: size_t, prot: ProtFlags, flags: MmapFlags, fd: RawFd, offset: off_t) -> Result<*mut c_void> { + let ret = unsafe { ffi::mmap(addr, length, prot.bits(), flags.bits(), fd, offset) }; if ret as isize == MAP_FAILED { Err(Error::Sys(Errno::last())) |