11 releases (6 breaking)

0.6.2 Nov 10, 2022
0.6.1 Jun 29, 2022
0.5.1 Apr 13, 2022
0.5.0 Mar 26, 2022
0.2.0 Sep 5, 2018

#56 in Unix APIs

Download history 23086/week @ 2022-11-29 22155/week @ 2022-12-06 20055/week @ 2022-12-13 17453/week @ 2022-12-20 11665/week @ 2022-12-27 20124/week @ 2023-01-03 21070/week @ 2023-01-10 26093/week @ 2023-01-17 24027/week @ 2023-01-24 23904/week @ 2023-01-31 26368/week @ 2023-02-07 29918/week @ 2023-02-14 34945/week @ 2023-02-21 36974/week @ 2023-02-28 37566/week @ 2023-03-07 30357/week @ 2023-03-14

145,655 downloads per month
Used in 245 crates (6 directly)

MIT/Apache

16KB
257 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

~1.2–6MB
~102K SLoC