Crates.io | memfd |
lib.rs | memfd |
version | 0.6.4 |
source | src |
created_at | 2018-08-21 20:31:36.2765 |
updated_at | 2023-09-18 16:13:10.828118 |
description | A pure-Rust library to work with Linux memfd and sealing |
homepage | |
repository | https://github.com/lucab/memfd-rs |
max_upload_size | |
id | 80626 |
size | 41,342 |
A pure-Rust library to work with Linux memfd and seals.
It provides support for creating memfd
objects on Linux
and handling seals on them. This was first introduced in
Linux kernel 3.17.
For further details, see memfd_create(2)
manpage.
extern crate memfd;
use memfd::errors::Result;
fn new_sized_memfd() -> Result<memfd::Memfd> {
// Create a sealable memfd.
let opts = memfd::MemfdOptions::default().allow_sealing(true);
let mfd = opts.create("sized-1K")?;
// Resize to 1024B.
mfd.as_file().set_len(1024)?;
// Add seals to prevent further resizing.
let mut seals = memfd::SealsHashSet::new();
seals.insert(memfd::FileSeal::SealShrink);
seals.insert(memfd::FileSeal::SealGrow);
mfd.add_seals(&seals)?;
// Prevent further sealing changes.
mfd.add_seal(memfd::FileSeal::SealSeal);
Ok(mfd)
}
Some more examples are available under examples.
Licensed under either of
at your option.