pub struct ShmRegion { /* private fields */ }Expand description
A mapped POSIX SHM region. Drop unmaps; unlink removes the
underlying name and any companion lock file (only the creator
should call it on shutdown).
Implementations§
Source§impl ShmRegion
impl ShmRegion
Sourcepub fn validate_existing(
name: &str,
minimum_size: usize,
) -> Result<ShmValidation>
pub fn validate_existing( name: &str, minimum_size: usize, ) -> Result<ShmValidation>
Validate an existing shared-memory object without creating, mapping, resetting, or unlinking it.
Returns ShmValidation::Missing when the name does not exist. A
present object must be at least minimum_size bytes; larger objects
are accepted because some platforms report page-rounded SHM sizes.
The owning ring or table remains responsible for validating its own
persisted ABI header after mapping.
The expected owner is the effective uid and the policy is OwnerOnly.
Sourcepub fn validate_existing_with_policy(
name: &str,
minimum_size: usize,
owner_uid: u32,
policy: ShmAccessPolicy,
) -> Result<ShmValidation>
pub fn validate_existing_with_policy( name: &str, minimum_size: usize, owner_uid: u32, policy: ShmAccessPolicy, ) -> Result<ShmValidation>
Validate size, expected owner and maximum permissions without mutation.
owner_uid is trusted configuration, not metadata read from the object.
Sourcepub fn open_or_create(name: &str, size: usize) -> Result<Self>
pub fn open_or_create(name: &str, size: usize) -> Result<Self>
Open or create a shared-memory segment of size bytes,
memory-mapped read/write. Idempotent: if the segment already
exists with the same name and enough mapped bytes, it is reused
(created = false). First creation does ftruncate(size);
later opens verify the existing object before mapping it. Some
platforms report a page-rounded SHM size, so a larger st_size
is valid; the owning data structure must verify its own header.
Existing objects must belong to the effective uid and satisfy OwnerOnly.
Sourcepub fn open_or_create_with_policy(
name: &str,
size: usize,
policy: ShmAccessPolicy,
) -> Result<Self>
pub fn open_or_create_with_policy( name: &str, size: usize, policy: ShmAccessPolicy, ) -> Result<Self>
Open or create using an explicit access policy. Existing objects must belong to the effective uid and pass the policy before being mapped. Rejection never resizes, chmods, chowns or unlinks an existing object.
Sourcepub fn open_or_create_locked(
name: &str,
size: usize,
) -> Result<(Self, ShmRegionLock)>
pub fn open_or_create_locked( name: &str, size: usize, ) -> Result<(Self, ShmRegionLock)>
Open or create a region while holding its process lock through caller
initialization. This prevents a peer from observing the interval
between shm_open and the owning data structure’s initialized header.
Sourcepub fn open_or_create_locked_with_policy(
name: &str,
size: usize,
policy: ShmAccessPolicy,
) -> Result<(Self, ShmRegionLock)>
pub fn open_or_create_locked_with_policy( name: &str, size: usize, policy: ShmAccessPolicy, ) -> Result<(Self, ShmRegionLock)>
Policy-aware creation with the existing owner-local initialization lock. Group permissions do not make that lock or fleet membership cross-user.
pub fn is_empty(&self) -> bool
Sourcepub fn created(&self) -> bool
pub fn created(&self) -> bool
True when this handle was the one that created the segment. Useful for picking which process performs first-time initialization of the header.
Sourcepub fn lock_exclusive(&self) -> Result<ShmRegionLock>
pub fn lock_exclusive(&self) -> Result<ShmRegionLock>
Acquire an exclusive cross-process lock tied to this SHM name.
flock ownership is held by the kernel and is released when a process
exits or the descriptor closes, including abnormal termination.