#[doc(hidden)]
#[macro_export]
macro_rules! __canic_ic_memory_key {
($authority:expr, $stable_key:literal, $label:path, $id:expr) => {{
const _: () = {
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __canic_register_static_memory_declaration() {
let _ = core::marker::PhantomData::<$label>;
$crate::__reexports::ic_memory::register_static_memory_manager_declaration(
$id,
$authority,
stringify!($label),
$stable_key,
)
.expect("Canic static memory declaration failed");
}
};
$crate::memory::runtime::assert_memory_bootstrap_ready(stringify!($label), $id);
$crate::__reexports::ic_memory::open_default_memory_manager_memory($stable_key, $id)
.expect("Canic failed to open committed stable memory; bootstrap must run first and the stable key/id must match the committed declaration")
}};
}
#[macro_export]
macro_rules! ic_memory_key {
(authority = CANIC_CORE_MEMORY_AUTHORITY, key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {
$crate::__canic_ic_memory_key!(
$crate::memory::CANIC_CORE_MEMORY_AUTHORITY,
$stable_key,
$label,
$id
)
};
(authority = CANIC_CONTROL_PLANE_MEMORY_AUTHORITY, key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {{
$crate::__canic_ic_memory_key!(
$crate::memory::CANIC_CONTROL_PLANE_MEMORY_AUTHORITY,
$stable_key,
$label,
$id
)
}};
(authority = $authority:literal, key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {{ $crate::__canic_ic_memory_key!($authority, $stable_key, $label, $id) }};
(authority = $authority:path, key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {{ $crate::__canic_ic_memory_key!($authority, $stable_key, $label, $id) }};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __canic_ic_memory_range {
($authority:expr, $start:expr, $end:expr, $mode:ident) => {
const _: () = {
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __canic_register_static_memory_range() {
$crate::__reexports::ic_memory::register_static_memory_manager_range(
$start,
$end,
$authority,
$crate::__reexports::ic_memory::MemoryManagerRangeMode::$mode,
None,
)
.expect("Canic static memory range declaration failed");
}
};
};
}
#[macro_export]
macro_rules! ic_memory_range {
(authority = CANIC_CORE_MEMORY_AUTHORITY, start = $start:expr, end = $end:expr $(,)?) => {
$crate::__canic_ic_memory_range!(
$crate::memory::CANIC_CORE_MEMORY_AUTHORITY,
$start,
$end,
Reserved
);
};
(authority = CANIC_CORE_MEMORY_AUTHORITY, start = $start:expr, end = $end:expr, mode = $mode:ident $(,)?) => {
$crate::__canic_ic_memory_range!(
$crate::memory::CANIC_CORE_MEMORY_AUTHORITY,
$start,
$end,
$mode
);
};
(authority = CANIC_CONTROL_PLANE_MEMORY_AUTHORITY, start = $start:expr, end = $end:expr $(,)?) => {
$crate::__canic_ic_memory_range!(
$crate::memory::CANIC_CONTROL_PLANE_MEMORY_AUTHORITY,
$start,
$end,
Reserved
);
};
(authority = CANIC_CONTROL_PLANE_MEMORY_AUTHORITY, start = $start:expr, end = $end:expr, mode = $mode:ident $(,)?) => {
$crate::__canic_ic_memory_range!(
$crate::memory::CANIC_CONTROL_PLANE_MEMORY_AUTHORITY,
$start,
$end,
$mode
);
};
(authority = $authority:literal, start = $start:expr, end = $end:expr $(,)?) => {
$crate::__canic_ic_memory_range!($authority, $start, $end, Reserved);
};
(authority = $authority:literal, start = $start:expr, end = $end:expr, mode = $mode:ident $(,)?) => {
$crate::__canic_ic_memory_range!($authority, $start, $end, $mode);
};
(authority = $authority:path, start = $start:expr, end = $end:expr $(,)?) => {
$crate::__canic_ic_memory_range!($authority, $start, $end, Reserved);
};
(authority = $authority:path, start = $start:expr, end = $end:expr, mode = $mode:ident $(,)?) => {
$crate::__canic_ic_memory_range!($authority, $start, $end, $mode);
};
}
#[macro_export]
macro_rules! eager_init {
($body:block) => {
$crate::__reexports::ic_memory::eager_init!($body);
};
}
#[macro_export]
macro_rules! eager_static {
($vis:vis static $name:ident : $ty:ty = $init:expr;) => {
thread_local! {
$vis static $name: $ty = $init;
}
const _: () = {
fn __canic_touch_tls() {
$name.with(|_| {});
}
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __canic_register_eager_tls() {
$crate::memory::runtime::defer_tls_initializer(__canic_touch_tls);
}
};
};
}