canic_core/
memory_macros.rs1#[macro_export]
12macro_rules! ic_memory_key {
13 (authority = CANIC_CORE_MEMORY_AUTHORITY, $($rest:tt)*) => {
14 $crate::ic_memory_key!(authority = $crate::memory::CANIC_CORE_MEMORY_AUTHORITY, $($rest)*)
15 };
16 (authority = CANIC_CONTROL_PLANE_MEMORY_AUTHORITY, $($rest:tt)*) => {
17 $crate::ic_memory_key!(authority = $crate::memory::CANIC_CONTROL_PLANE_MEMORY_AUTHORITY, $($rest)*)
18 };
19 (authority = $authority:expr, key = $stable_key:literal $(,)?) => {{
20 $crate::__reexports::ic_memory::ic_memory_declaration!(authority = $authority, key = $stable_key);
21 $crate::memory::runtime::assert_memory_bootstrap_ready($stable_key);
22 $crate::__reexports::ic_memory::open_default_memory_manager_memory($stable_key)
23 .expect("ic-memory committed key binding must exist before opening stable memory")
24 }};
25}
26
27#[macro_export]
33macro_rules! memory_allocation_pool {
34 (authorities = [$(($owner:expr, $prefix:expr)),* $(,)?], exclusions = [$(($start:expr, $end:expr)),* $(,)?] $(,)?) => {
35 const _: () = {
36 #[$crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor)]
37 fn __canic_register_memory_pool() {
38 let pool = $crate::memory::pool::framework_pool(
39 vec![$($crate::__reexports::ic_memory::MemoryAuthority::new($owner, $prefix).expect("valid host memory grant")),*],
40 vec![$($crate::__reexports::ic_memory::MemoryManagerIdRange::new($start, $end).expect("valid unmanaged exclusion")),*],
41 ).expect("disjoint host memory grants");
42 $crate::memory::pool::register(pool).expect("one host memory pool before bootstrap");
43 }
44 };
45 };
46}
47
48#[macro_export]
55macro_rules! memory_bootstrap_admission {
56 (identity = $identity:expr, prepare = $prepare:path $(,)?) => {
57 const _: () = {
58 #[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
59 fn __canic_register_memory_admission() {
60 fn __canic_prepare_memory_admission(admission: &mut $crate::__reexports::ic_memory::BootstrapAdmission<'_>)
61 -> ::core::result::Result<(), $crate::memory::registry::MemoryRegistryError>
62 {
63 $prepare(admission).map_err(|source| $crate::memory::registry::MemoryRegistryError::Admission { source: ::std::boxed::Box::new(source) })
64 }
65 $crate::memory::admission::register(
66 $crate::memory::admission::MemoryBootstrapAdmission::new($identity, __canic_prepare_memory_admission),
67 ).expect("Canic memory admission registration failed");
68 }
69 };
70 };
71}