pub mod common;
pub mod posix;
pub mod process_local;
use core::{fmt::Debug, time::Duration};
pub use crate::shm_allocator::*;
use crate::static_storage::file::{NamedConcept, NamedConceptBuilder, NamedConceptMgmt};
use iceoryx2_bb_system_types::file_name::*;
use pool_allocator::PoolAllocator;
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum SharedMemoryCreateError {
AlreadyExists,
SizeIsZero,
InsufficientPermissions,
InternalError,
}
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum SharedMemoryOpenError {
DoesNotExist,
InsufficientPermissions,
SizeIsZero,
SizeDoesNotFit,
WrongAllocatorSelected,
InitializationNotYetFinalized,
VersionMismatch,
InternalError,
}
#[derive(Debug)]
pub struct ShmPointer {
pub offset: PointerOffset,
pub data_ptr: *mut u8,
}
#[doc(hidden)]
pub(crate) mod details {
use super::*;
pub trait SharedMemoryLowLevelAPI<Allocator: ShmAllocator> {
fn allocator(&self) -> &Allocator;
}
}
pub trait SharedMemoryBuilder<Allocator: ShmAllocator, Shm: SharedMemory<Allocator>>:
NamedConceptBuilder<Shm>
{
fn has_ownership(self, value: bool) -> Self;
fn size(self, value: usize) -> Self;
fn timeout(self, value: Duration) -> Self;
fn create(
self,
allocator_config: &Allocator::Configuration,
) -> Result<Shm, SharedMemoryCreateError>;
fn open(self) -> Result<Shm, SharedMemoryOpenError>;
}
pub trait SharedMemory<Allocator: ShmAllocator>:
Sized + Debug + NamedConcept + NamedConceptMgmt + details::SharedMemoryLowLevelAPI<Allocator>
{
type Builder: SharedMemoryBuilder<Allocator, Self>;
fn size(&self) -> usize;
fn max_alignment(&self) -> usize;
fn payload_start_address(&self) -> usize;
fn allocate(&self, layout: core::alloc::Layout) -> Result<ShmPointer, ShmAllocationError>;
unsafe fn deallocate(&self, offset: PointerOffset, layout: core::alloc::Layout);
fn does_support_persistency() -> bool;
fn has_ownership(&self) -> bool;
fn acquire_ownership(&self);
fn release_ownership(&self);
fn default_suffix() -> FileName {
unsafe { FileName::new_unchecked(b".shm") }
}
}
pub trait SharedMemoryForPoolAllocator: SharedMemory<PoolAllocator> {
unsafe fn deallocate_bucket(&self, offset: PointerOffset);
fn bucket_size(&self) -> usize;
}