Available on Android or Linux only.
Expand description
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.
use memfd;
fn new_sized_memfd() -> Result<memfd::Memfd, Box<dyn std::error::Error>> {
// 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.
mfd.add_seals(&[
memfd::FileSeal::SealShrink,
memfd::FileSeal::SealGrow
])?;
// Prevent further sealing changes.
mfd.add_seal(memfd::FileSeal::SealSeal)?;
Ok(mfd)
}
Structs§
- Memfd
- An anonymous volatile file, with sealing capabilities.
- Memfd
Options - A
Memfd
builder, providing advanced options and flags for specifying its behavior.
Enums§
- Error
- Enumeration of errors possible in this library
- File
Seal - Seal that can be applied to a
Memfd
. - Hugetlb
Size - Page size for a hugetlb anonymous file.
Type Aliases§
- Seals
Hash Set - An
HashSet
specialized onFileSeal
.