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, non-executable native region.
Examples found in repository?
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let capabilities = native_memory_capabilities();
7 let options = RegionOptions::growable(128, 4096, WriterOwner::Creator);
8 let mut region = NativeRegion::allocate(options)?;
9
10 region.initialize(|bytes| bytes[..8].copy_from_slice(b"NIPCDEMO"));
11 region.grow(512)?;
12 region.initialize(|bytes| assert_eq!(&bytes[..8], b"NIPCDEMO"));
13
14 let status = region.status();
15 println!(
16 "backend={:?} authority={:?} logical={} mapped={} maximum={}",
17 capabilities.platform(),
18 capabilities.authority_mechanism(),
19 status.logical_len,
20 status.mapped_len,
21 status.maximum_len,
22 );
23
24 region.clear();
25 region.initialize(|bytes| bytes[..8].copy_from_slice(b"REUSABLE"));
26
27 // `destroy` explicitly clears the complete mapping before releasing it.
28 // Use `prepare_for_sharing` instead when handing the region to the
29 // authenticated platform transfer typestate.
30 region.destroy();
31 Ok(())
32}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.
Examples found in repository?
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let capabilities = native_memory_capabilities();
7 let options = RegionOptions::growable(128, 4096, WriterOwner::Creator);
8 let mut region = NativeRegion::allocate(options)?;
9
10 region.initialize(|bytes| bytes[..8].copy_from_slice(b"NIPCDEMO"));
11 region.grow(512)?;
12 region.initialize(|bytes| assert_eq!(&bytes[..8], b"NIPCDEMO"));
13
14 let status = region.status();
15 println!(
16 "backend={:?} authority={:?} logical={} mapped={} maximum={}",
17 capabilities.platform(),
18 capabilities.authority_mechanism(),
19 status.logical_len,
20 status.mapped_len,
21 status.maximum_len,
22 );
23
24 region.clear();
25 region.initialize(|bytes| bytes[..8].copy_from_slice(b"REUSABLE"));
26
27 // `destroy` explicitly clears the complete mapping before releasing it.
28 // Use `prepare_for_sharing` instead when handing the region to the
29 // authenticated platform transfer typestate.
30 region.destroy();
31 Ok(())
32}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.
Examples found in repository?
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let capabilities = native_memory_capabilities();
7 let options = RegionOptions::growable(128, 4096, WriterOwner::Creator);
8 let mut region = NativeRegion::allocate(options)?;
9
10 region.initialize(|bytes| bytes[..8].copy_from_slice(b"NIPCDEMO"));
11 region.grow(512)?;
12 region.initialize(|bytes| assert_eq!(&bytes[..8], b"NIPCDEMO"));
13
14 let status = region.status();
15 println!(
16 "backend={:?} authority={:?} logical={} mapped={} maximum={}",
17 capabilities.platform(),
18 capabilities.authority_mechanism(),
19 status.logical_len,
20 status.mapped_len,
21 status.maximum_len,
22 );
23
24 region.clear();
25 region.initialize(|bytes| bytes[..8].copy_from_slice(b"REUSABLE"));
26
27 // `destroy` explicitly clears the complete mapping before releasing it.
28 // Use `prepare_for_sharing` instead when handing the region to the
29 // authenticated platform transfer typestate.
30 region.destroy();
31 Ok(())
32}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.
Examples found in repository?
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let capabilities = native_memory_capabilities();
7 let options = RegionOptions::growable(128, 4096, WriterOwner::Creator);
8 let mut region = NativeRegion::allocate(options)?;
9
10 region.initialize(|bytes| bytes[..8].copy_from_slice(b"NIPCDEMO"));
11 region.grow(512)?;
12 region.initialize(|bytes| assert_eq!(&bytes[..8], b"NIPCDEMO"));
13
14 let status = region.status();
15 println!(
16 "backend={:?} authority={:?} logical={} mapped={} maximum={}",
17 capabilities.platform(),
18 capabilities.authority_mechanism(),
19 status.logical_len,
20 status.mapped_len,
21 status.maximum_len,
22 );
23
24 region.clear();
25 region.initialize(|bytes| bytes[..8].copy_from_slice(b"REUSABLE"));
26
27 // `destroy` explicitly clears the complete mapping before releasing it.
28 // Use `prepare_for_sharing` instead when handing the region to the
29 // authenticated platform transfer typestate.
30 region.destroy();
31 Ok(())
32}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.
Examples found in repository?
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let capabilities = native_memory_capabilities();
7 let options = RegionOptions::growable(128, 4096, WriterOwner::Creator);
8 let mut region = NativeRegion::allocate(options)?;
9
10 region.initialize(|bytes| bytes[..8].copy_from_slice(b"NIPCDEMO"));
11 region.grow(512)?;
12 region.initialize(|bytes| assert_eq!(&bytes[..8], b"NIPCDEMO"));
13
14 let status = region.status();
15 println!(
16 "backend={:?} authority={:?} logical={} mapped={} maximum={}",
17 capabilities.platform(),
18 capabilities.authority_mechanism(),
19 status.logical_len,
20 status.mapped_len,
21 status.maximum_len,
22 );
23
24 region.clear();
25 region.initialize(|bytes| bytes[..8].copy_from_slice(b"REUSABLE"));
26
27 // `destroy` explicitly clears the complete mapping before releasing it.
28 // Use `prepare_for_sharing` instead when handing the region to the
29 // authenticated platform transfer typestate.
30 region.destroy();
31 Ok(())
32}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.
Examples found in repository?
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let capabilities = native_memory_capabilities();
7 let options = RegionOptions::growable(128, 4096, WriterOwner::Creator);
8 let mut region = NativeRegion::allocate(options)?;
9
10 region.initialize(|bytes| bytes[..8].copy_from_slice(b"NIPCDEMO"));
11 region.grow(512)?;
12 region.initialize(|bytes| assert_eq!(&bytes[..8], b"NIPCDEMO"));
13
14 let status = region.status();
15 println!(
16 "backend={:?} authority={:?} logical={} mapped={} maximum={}",
17 capabilities.platform(),
18 capabilities.authority_mechanism(),
19 status.logical_len,
20 status.mapped_len,
21 status.maximum_len,
22 );
23
24 region.clear();
25 region.initialize(|bytes| bytes[..8].copy_from_slice(b"REUSABLE"));
26
27 // `destroy` explicitly clears the complete mapping before releasing it.
28 // Use `prepare_for_sharing` instead when handing the region to the
29 // authenticated platform transfer typestate.
30 region.destroy();
31 Ok(())
32}Sourcepub fn prepare_for_sharing(self) -> NativeShareRequest
pub fn prepare_for_sharing(self) -> NativeShareRequest
Freezes common initialization/growth and creates a native share request.
The request retains the permission and mandatory seal policy alongside the native region. Its platform parts must be consumed by the matching authenticated prepare/transfer operation.