pub struct MmapRegion { /* private fields */ }Expand description
File-backed memory-mapped region for cross-process shared memory.
shm[impl shm.file.mmap-posix]
Implementations§
Source§impl MmapRegion
impl MmapRegion
Sourcepub fn create(path: &Path, size: usize, cleanup: FileCleanup) -> Result<Self>
pub fn create(path: &Path, size: usize, cleanup: FileCleanup) -> Result<Self>
Create a new file-backed region.
This creates the file, truncates it to the given size, and maps it
into memory with MAP_SHARED. The file is created with permissions 0600.
shm[impl shm.file.create] shm[impl shm.file.permissions]
Sourcepub fn attach(path: &Path) -> Result<Self>
pub fn attach(path: &Path) -> Result<Self>
Attach to an existing file-backed region.
This opens the file and maps it into memory with MAP_SHARED.
The file size determines the mapping size.
shm[impl shm.file.attach]
Sourcepub fn take_ownership(&mut self)
pub fn take_ownership(&mut self)
Take ownership of the file for cleanup purposes.
After calling this, the file will be deleted when this region is dropped.
Sourcepub fn release_ownership(&mut self)
pub fn release_ownership(&mut self)
Release ownership of the file.
After calling this, the file will NOT be deleted when this region is dropped.
Sourcepub fn resize(&mut self, new_size: usize) -> Result<()>
pub fn resize(&mut self, new_size: usize) -> Result<()>
Resize the region by growing the backing file and remapping.
This is typically a host-only operation. The base pointer may change,
so callers must update any cached Region references after calling this.
§Errors
Returns an error if the new size is smaller than current size (shrinking is not supported), or if the underlying file/mmap operations fail.
shm[impl shm.varslot.extents]
Sourcepub fn check_and_remap(&mut self) -> Result<bool>
pub fn check_and_remap(&mut self) -> Result<bool>
Check if the backing file has grown and remap if needed.
This is useful for guests to detect when the host has grown the segment.
Returns true if the region was remapped, false if no change.
§Errors
Returns an error if file metadata cannot be read or remapping fails.