#linux #memfd #memfd-create #seal

memfd

A pure-Rust library to work with Linux memfd and sealing

6 releases (breaking)

0.4.1 Sep 6, 2021
0.4.0 Feb 10, 2021
0.3.0 Jan 11, 2020
0.2.0 Sep 5, 2018
0.0.1-alpha.1 Aug 21, 2018

#187 in Unix APIs

Download history 646/week @ 2021-06-06 553/week @ 2021-06-13 803/week @ 2021-06-20 1134/week @ 2021-06-27 890/week @ 2021-07-04 802/week @ 2021-07-11 780/week @ 2021-07-18 829/week @ 2021-07-25 1015/week @ 2021-08-01 876/week @ 2021-08-08 1182/week @ 2021-08-15 797/week @ 2021-08-22 590/week @ 2021-08-29 809/week @ 2021-09-05 598/week @ 2021-09-12 719/week @ 2021-09-19

3,582 downloads per month
Used in 5 crates (3 directly)

MIT/Apache

18KB
282 lines

memfd

Build Status crates.io Documentation

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.

Example

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.

License

Licensed under either of

at your option.

Dependencies

~30KB