13 unstable releases

0.6.4 Sep 18, 2023
0.6.3 Mar 29, 2023
0.6.2 Nov 10, 2022
0.6.1 Jun 29, 2022
0.2.0 Sep 5, 2018

#14 in Unix APIs

Download history 145135/week @ 2024-07-21 133799/week @ 2024-07-28 111389/week @ 2024-08-04 123144/week @ 2024-08-11 110537/week @ 2024-08-18 114557/week @ 2024-08-25 125590/week @ 2024-09-01 123318/week @ 2024-09-08 121483/week @ 2024-09-15 119558/week @ 2024-09-22 131491/week @ 2024-09-29 133535/week @ 2024-10-06 121491/week @ 2024-10-13 136072/week @ 2024-10-20 123404/week @ 2024-10-27 147520/week @ 2024-11-03

535,911 downloads per month
Used in 526 crates (12 directly)

MIT/Apache

17KB
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.5–9.5MB
~109K SLoC