#shared-memory #file-descriptor #shm

no-std bin+lib shm-fd

Like systemfd/listenfd but with a shared-memory file descriptor

3 releases (breaking)

0.5.0 Jan 20, 2024
0.4.0 Jan 16, 2024
0.2.0 Apr 8, 2022

#666 in Unix APIs


Used in shm-snapshot

MPL-2.0 license

26KB
452 lines

shm-fd

This crate is part of a group that enables using shared-memory files conveniently for persisting state across program restarts. Programs can access this file via language and runtime independent means from the environment. This crate contains a simple binary to configure such an environment, and a library to consume it.

Usage

use shm_fd::SharedFd;

// Trust the environment..
let fd = unsafe { SharedFd::from_env() }?;
let memfile = fd.into_file()?;

// Example: utilize the shared memory via memmap2 crate
use memmap2::MmapMut;
let mapping = unsafe { MmapMut::map_mut(file.as_raw_fd()) }?;
let memory = &mut mapping[..];

Dependencies

~20KB