diff options
author | David Henningsson <diwic@ubuntu.com> | 2015-08-23 07:41:33 +0200 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2015-08-25 15:56:04 -0700 |
commit | 4f69bc358d7ab644ae766fde8bb5bdfd631f789b (patch) | |
tree | bad01ac6570ac623577f6a940dfe298e7c27fb27 /src/sys | |
parent | 1020c6417a47e5abcc2ddce8f0c0c014f52ad60d (diff) | |
download | nix-4f69bc358d7ab644ae766fde8bb5bdfd631f789b.zip |
Add memfd functionality
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/memfd.rs | 18 | ||||
-rw-r--r-- | src/sys/mod.rs | 3 | ||||
-rw-r--r-- | src/sys/syscall.rs | 3 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/sys/memfd.rs b/src/sys/memfd.rs new file mode 100644 index 00000000..e142218f --- /dev/null +++ b/src/sys/memfd.rs @@ -0,0 +1,18 @@ +use libc; +use std::os::unix::io::RawFd; +use {Error, Result}; +use std::ffi::CStr; + +bitflags!( + flags MemFdCreateFlag: libc::c_uint { + const MFD_CLOEXEC = 0x0001, + const MFD_ALLOW_SEALING = 0x0002, + } +); + +pub fn memfd_create(name: &CStr, flags: MemFdCreateFlag) -> Result<RawFd> { + use sys::syscall::{syscall, MEMFD_CREATE}; + let res = unsafe { syscall(MEMFD_CREATE, name.as_ptr(), flags.bits()) }; + if res == -1 { Err(Error::last()) } + else { Ok(res as RawFd) } +} diff --git a/src/sys/mod.rs b/src/sys/mod.rs index c124359d..3df06c44 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -9,6 +9,9 @@ pub mod event; #[cfg(feature = "eventfd")] pub mod eventfd; +#[cfg(target_os = "linux")] +pub mod memfd; + #[cfg(not(any(target_os = "ios", target_os = "freebsd")))] pub mod ioctl; diff --git a/src/sys/syscall.rs b/src/sys/syscall.rs index 0f6a5e0b..c80defa2 100644 --- a/src/sys/syscall.rs +++ b/src/sys/syscall.rs @@ -11,6 +11,7 @@ mod arch { pub type Syscall = c_long; pub static SYSPIVOTROOT: Syscall = 155; + pub static MEMFD_CREATE: Syscall = 319; } #[cfg(target_arch = "x86")] @@ -20,6 +21,7 @@ mod arch { pub type Syscall = c_long; pub static SYSPIVOTROOT: Syscall = 217; + pub static MEMFD_CREATE: Syscall = 356; } #[cfg(target_arch = "arm")] @@ -29,6 +31,7 @@ mod arch { pub type Syscall = c_long; pub static SYSPIVOTROOT: Syscall = 218; + pub static MEMFD_CREATE: Syscall = 385; } |