Skip to main content

ic_memory/runtime/
policy.rs

1use crate::{
2    MemoryManagerSlot, PolicyIdentity, PolicyIdentityError, RuntimeBootstrapPolicy, StableKey,
3};
4use std::convert::Infallible;
5
6///
7/// GenericAllocationPolicy
8///
9/// Built-in bootstrap policy for hosts needing no additional application checks.
10/// The runtime enforces host namespace grants, the common pool and governance;
11/// this policy adds no application-specific restrictions.
12///
13/// Use with configured bootstrap when the host does not require a custom
14/// policy. It retains the built-in policy identity and does not authorize
15/// replacing a different policy already bound to the runtime.
16///
17pub struct GenericAllocationPolicy;
18
19impl RuntimeBootstrapPolicy for GenericAllocationPolicy {
20    type Error = Infallible;
21
22    fn validate_key(&self, _key: &StableKey) -> Result<(), Self::Error> {
23        Ok(())
24    }
25
26    fn validate_slot(
27        &self,
28        _key: &StableKey,
29        _slot: &MemoryManagerSlot,
30    ) -> Result<(), Self::Error> {
31        Ok(())
32    }
33
34    fn runtime_bootstrap_identity(&self) -> Result<PolicyIdentity, PolicyIdentityError> {
35        PolicyIdentity::new("ic-memory.noop-policy", 1)
36    }
37}