Skip to main content

NativeRegion

Struct NativeRegion 

Source
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

Source

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.

Source

pub const fn options(&self) -> RegionOptions

Returns the immutable allocation and authority policy.

Source

pub fn status(&self) -> RegionStatus

Returns a portable status snapshot.

Source

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.

Source

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.

Source

pub fn grow(&mut self, requested: usize) -> Result<(), MemoryError>

Grows by replacing the still-private mapping and preserving logical bytes.

Source

pub fn close(self)

Explicitly clears according to policy and releases the anonymous object.

Source

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.

Source

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();

Trait Implementations§

Source§

impl Drop for NativeRegion

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.