pub struct NativeRegion { /* private fields */ }Expand description
Common owner of the best private native shared-memory object on this target.
It exposes logical initialization bytes only through a closure. Consuming
NativeRegion::prepare_for_sharing hands the region to the existing
authenticated platform transfer typestate, which applies real native seals
and exact permissions. Growth and arbitrary permission changes are no longer
possible after that transition.
Implementations§
Source§impl NativeRegion
impl NativeRegion
Sourcepub fn allocate(options: RegionOptions) -> Result<Self, MemoryError>
pub fn allocate(options: RegionOptions) -> Result<Self, MemoryError>
Allocates a zeroed anonymous region with a non-executable library view.
Delegated native authority follows the documented target policy; on Linux, a malicious memfd holder may create a separate executable alias.
Sourcepub const fn options(&self) -> RegionOptions
pub const fn options(&self) -> RegionOptions
Returns the immutable allocation and authority policy.
Sourcepub fn status(&self) -> RegionStatus
pub fn status(&self) -> RegionStatus
Returns a portable status snapshot.
Sourcepub fn initialize<R>(&mut self, operation: impl FnOnce(&mut [u8]) -> R) -> R
pub fn initialize<R>(&mut self, operation: impl FnOnce(&mut [u8]) -> R) -> R
Runs one initialization operation over logical bytes only.
Page-rounded padding remains zero and inaccessible through this common method. No capability has escaped while the closure runs.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the complete page-rounded mapping and retains it for reuse.
Every byte, including native page padding, is overwritten through the live mapping before this method returns.
Sourcepub fn grow(&mut self, requested: usize) -> Result<(), MemoryError>
pub fn grow(&mut self, requested: usize) -> Result<(), MemoryError>
Grows by replacing the still-private mapping and preserving logical bytes.
Sourcepub fn destroy(self)
pub fn destroy(self)
Overwrites the complete mapping, then explicitly releases it.
This ignores CleanupPolicy and always performs the clearing pass.
It cannot erase copies previously made by a process, the kernel, or a
device. The region must still be quiescent and exclusively owned here;
shared regions are destroyed by their transferred lifecycle owner.
Sourcepub fn prepare_for_sharing(self) -> Result<NativeShareRequest, MemoryError>
pub fn prepare_for_sharing(self) -> Result<NativeShareRequest, MemoryError>
Freezes initialization/growth and creates an opaque native share request.
The private owner is consumed and cannot be reused after preparation.
use native_ipc::memory::{NativeRegion, RegionOptions, WriterOwner};
let mut region = NativeRegion::allocate(RegionOptions::fixed(
32,
WriterOwner::Creator,
)).unwrap();
let _prepared = region.prepare_for_sharing().unwrap();
region.clear();