use super::{
AccountingPosture, AttestationEvidence, JournalDisposition, PhysicalProtection,
ProtectionError, ProtectionRequest, ProviderHealth, ProviderLimits, ProviderReport,
TeardownCursor, WipeEvidence,
};
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum ProviderOperationResult {
Applied,
NotApplied,
Indeterminate,
}
impl ProviderOperationResult {
pub(crate) const fn journal_disposition(self) -> JournalDisposition {
match self {
Self::Applied => JournalDisposition::Applied,
Self::NotApplied => JournalDisposition::NotApplied,
Self::Indeterminate => JournalDisposition::Indeterminate,
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct WipeConfirmation {
pub result: ProviderOperationResult,
pub evidence: WipeEvidence,
}
pub enum DisposalResult<Handle> {
Applied,
NotApplied(Handle),
AllocationPresenceUnknown,
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct QuarantineRecord {
pub pending_stage: super::PendingStage,
pub wipe: WipeEvidence,
pub physical_protection: PhysicalProtection,
pub accounting: AccountingPosture,
pub cursor: TeardownCursor,
pub retry_attempt: usize,
}
pub struct ProviderAccess {
_private: (),
}
impl ProviderAccess {
pub(crate) const fn new() -> Self {
Self { _private: () }
}
}
#[allow(unsafe_code)]
pub unsafe trait ProtectedMemoryProvider {
type Handle;
type Reservation;
fn provider_identity(&self) -> usize;
fn provider_generation(&self) -> usize;
fn health_generation(&self) -> usize;
fn protection_generation(&self) -> usize;
fn health(&self) -> ProviderHealth;
fn limits(&self) -> ProviderLimits;
fn report(&self) -> ProviderReport;
fn reserve(
&self,
access: &ProviderAccess,
request: ProtectionRequest,
) -> Result<Self::Reservation, ProtectionError>;
fn materialize(
&self,
access: &ProviderAccess,
reservation: Self::Reservation,
) -> Result<Self::Handle, ProtectionError>;
fn logical_len(&self, access: &ProviderAccess, handle: &Self::Handle) -> usize;
fn physical_protection(
&self,
access: &ProviderAccess,
handle: &Self::Handle,
) -> PhysicalProtection;
fn bytes<'handle>(
&self,
access: &ProviderAccess,
handle: &'handle Self::Handle,
) -> &'handle [u8];
fn bytes_mut<'handle>(
&self,
access: &ProviderAccess,
handle: &'handle mut Self::Handle,
) -> &'handle mut [u8];
fn confirm_wipe(
&self,
access: &ProviderAccess,
handle: &Self::Handle,
attestation: Option<AttestationEvidence>,
cursor: &mut TeardownCursor,
) -> WipeConfirmation;
fn remove_protection(
&self,
access: &ProviderAccess,
handle: &mut Self::Handle,
cursor: &mut TeardownCursor,
) -> ProviderOperationResult;
fn reconcile_accounting(
&self,
access: &ProviderAccess,
handle: &mut Self::Handle,
cursor: &mut TeardownCursor,
) -> ProviderOperationResult;
fn dispose(
&self,
access: &ProviderAccess,
handle: Self::Handle,
cursor: &mut TeardownCursor,
) -> DisposalResult<Self::Handle>;
fn quarantine(&self, access: &ProviderAccess, handle: Self::Handle, record: QuarantineRecord);
}
mod sealed {
pub trait ThreadMovable {}
}
pub trait ThreadMovableProvider: ProtectedMemoryProvider + sealed::ThreadMovable {}