#Linux #memfd #memfd_create #seal

memfd

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

4 releases (breaking)

✓ Uses Rust 2018 edition

0.3.0 Jan 11, 2020
0.2.0 Sep 5, 2018
0.1.0 Aug 31, 2018
0.0.1-alpha.1 Aug 21, 2018

#31 in Unix APIs

Download history 499/week @ 2019-10-13 540/week @ 2019-10-20 367/week @ 2019-10-27 418/week @ 2019-11-03 362/week @ 2019-11-10 512/week @ 2019-11-17 160/week @ 2019-11-24 386/week @ 2019-12-01 274/week @ 2019-12-08 383/week @ 2019-12-15 30/week @ 2019-12-22 248/week @ 2019-12-29 397/week @ 2020-01-05 476/week @ 2020-01-12 622/week @ 2020-01-19

1,520 downloads per month

MIT/Apache

14KB
228 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

~0.5–0.9MB
~20K SLoC