pub struct PluginState { /* private fields */ }Expand description
State of a single plugin instance
Corresponds to Lean: @[ext] structure PluginState
INVARIANTS:
- heldCaps contains only capability IDs, not actual capabilities
- Validity of held capabilities is checked at use time via kernel lookup
- Memory bounds are immutable after creation
- Resource usage must not exceed quotas (DoS prevention)
Implementations§
Source§impl PluginState
impl PluginState
Sourcepub fn empty(level: SecurityLevel, mem_size: Size) -> Self
pub fn empty(level: SecurityLevel, mem_size: Size) -> Self
Create empty plugin with given security level and memory size
Corresponds to Lean: def PluginState.empty (level : SecurityLevel) (memSize : Nat) : PluginState
Sourcepub fn with_quotas(
level: SecurityLevel,
mem_size: Size,
memory_quota: u64,
cap_quota: u64,
ipc_queue_limit: u64,
) -> Self
pub fn with_quotas( level: SecurityLevel, mem_size: Size, memory_quota: u64, cap_quota: u64, ipc_queue_limit: u64, ) -> Self
Create plugin with custom quotas
Corresponds to Lean: def PluginState.withQuotas
Sourcepub fn holds_cap(&self, cap_id: CapId) -> bool
pub fn holds_cap(&self, cap_id: CapId) -> bool
Check if plugin holds a capability by ID
Corresponds to Lean: def PluginState.holds_cap (ps : PluginState) (capId : CapId) : Prop
Sourcepub fn grant_cap(&self, cap_id: CapId) -> Self
pub fn grant_cap(&self, cap_id: CapId) -> Self
Grant capability ID to plugin (idempotent)
Corresponds to Lean: def PluginState.grant_cap
Returns the new PluginState with the capability ID added.
Sourcepub fn grant_cap_mut(&mut self, cap_id: CapId)
pub fn grant_cap_mut(&mut self, cap_id: CapId)
Grant capability ID to plugin (mutating version)
Sourcepub fn revoke_cap(&self, cap_id: CapId) -> Self
pub fn revoke_cap(&self, cap_id: CapId) -> Self
Remove capability ID from plugin
Corresponds to Lean: def PluginState.revoke_cap
Returns the new PluginState with the capability ID removed.
Sourcepub fn revoke_cap_mut(&mut self, cap_id: CapId)
pub fn revoke_cap_mut(&mut self, cap_id: CapId)
Remove capability ID from plugin (mutating version)
Sourcepub fn level(&self) -> SecurityLevel
pub fn level(&self) -> SecurityLevel
Get the security level
Sourcepub fn memory(&self) -> &LinearMemory
pub fn memory(&self) -> &LinearMemory
Get a reference to the memory
Sourcepub fn held_cap_count(&self) -> usize
pub fn held_cap_count(&self) -> usize
Get the number of held capabilities
Sourcepub fn local_state(&self) -> PluginLocal
pub fn local_state(&self) -> PluginLocal
Get the local state
Sourcepub fn held_caps(&self) -> Vec<CapId> ⓘ
pub fn held_caps(&self) -> Vec<CapId> ⓘ
Get held capability IDs as a Vec
Note: Returns a cloned Vec. The Vec is maintained in sorted order.
Sourcepub fn held_caps_ref(&self) -> &Vec<CapId> ⓘ
pub fn held_caps_ref(&self) -> &Vec<CapId> ⓘ
Get a reference to held capability IDs
Sourcepub fn memory_bounds(&self) -> Size
pub fn memory_bounds(&self) -> Size
Get memory bounds
Sourcepub fn can_alloc_memory(&self, size: u64) -> bool
pub fn can_alloc_memory(&self, size: u64) -> bool
Check if memory allocation would exceed quota
Corresponds to Lean: def PluginState.canAllocMemory
Returns false if addition would overflow (DoS prevention)
Sourcepub fn can_hold_cap(&self) -> bool
pub fn can_hold_cap(&self) -> bool
Check if plugin can hold another capability
Corresponds to Lean: def PluginState.canHoldCap
Sourcepub fn can_queue_ipc(&self, queue_len: u64) -> bool
pub fn can_queue_ipc(&self, queue_len: u64) -> bool
Check if adding to IPC queue would exceed limit
Corresponds to Lean: def PluginState.canQueueIpc
Sourcepub fn alloc_memory(&mut self, size: u64) -> bool
pub fn alloc_memory(&mut self, size: u64) -> bool
Record memory allocation (update used counter)
Corresponds to Lean: def PluginState.allocMemory
Returns false if quota would be exceeded
Sourcepub fn free_memory(&mut self, size: u64)
pub fn free_memory(&mut self, size: u64)
Record memory deallocation (update used counter)
Corresponds to Lean: def PluginState.freeMemory
Sourcepub fn memory_used(&self) -> u64
pub fn memory_used(&self) -> u64
Get current memory usage
Sourcepub fn memory_quota(&self) -> u64
pub fn memory_quota(&self) -> u64
Get memory quota
Sourcepub fn ipc_queue_limit(&self) -> u64
pub fn ipc_queue_limit(&self) -> u64
Get IPC queue limit
Trait Implementations§
Source§impl Clone for PluginState
impl Clone for PluginState
Source§fn clone(&self) -> PluginState
fn clone(&self) -> PluginState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PluginState
impl Debug for PluginState
Source§impl Default for PluginState
impl Default for PluginState
Source§impl PartialEq for PluginState
impl PartialEq for PluginState
Source§fn eq(&self, other: &PluginState) -> bool
fn eq(&self, other: &PluginState) -> bool
self and other values to be equal, and is used by ==.