#![forbid(unsafe_code)]
#![deny(rustdoc::broken_intra_doc_links)]
#![doc = include_str!("../README.md")]
mod bootstrap;
mod capability;
mod cbor;
mod constants;
mod declaration;
mod diagnostics;
mod key;
mod ledger;
mod physical;
mod policy;
mod registry;
mod runtime;
mod schema;
mod slot;
mod stable_cell;
mod validation;
#[cfg(test)]
mod test_cbor {
use serde::{Serialize, de::DeserializeOwned};
pub use ciborium::Value;
pub fn to_vec<T: Serialize>(
value: &T,
) -> Result<Vec<u8>, ciborium::ser::Error<std::io::Error>> {
let mut bytes = Vec::new();
ciborium::into_writer(value, &mut bytes)?;
Ok(bytes)
}
pub fn from_slice<T: DeserializeOwned>(
bytes: &[u8],
) -> Result<T, ciborium::de::Error<std::io::Error>> {
crate::cbor::from_slice_exact(bytes)
}
pub fn to_value<T: Serialize>(value: T) -> Result<Value, ciborium::value::Error> {
Value::serialized(&value)
}
pub fn map_insert(map: &mut Vec<(Value, Value)>, key: Value, value: Value) {
map.push((key, value));
}
}
pub use bootstrap::{
AllocationBootstrap, BootstrapError, BootstrapReservationError, BootstrapRetirementError,
PendingBootstrapCommit,
};
pub use capability::{CommittedAllocations, ValidatedAllocations};
pub use constants::WASM_PAGE_SIZE_BYTES;
pub use declaration::{
AllocationDeclaration, DeclarationCollector, DeclarationSnapshot, DeclarationSnapshotError,
};
pub use diagnostics::{
DefaultMemoryManagerDoctorReport, DiagnosticCheck, DiagnosticDeclaration, DiagnosticExport,
DiagnosticGeneration, DiagnosticMemorySize, DiagnosticRangeAuthority, DiagnosticRecord,
DiagnosticStableCell, DiagnosticStableCellStatus,
};
pub use key::{StableKey, StableKeyError};
pub use ledger::{
AllocationHistory, AllocationLedger, AllocationRecord, AllocationReservationError,
AllocationRetirement, AllocationRetirementError, AllocationStageError, AllocationState,
GenerationRecord, LedgerCommitError, LedgerCommitStore, LedgerIntegrityError,
LedgerPayloadEnvelope, LedgerPayloadEnvelopeError, RecoveredLedger, SchemaMetadataRecord,
};
pub use physical::{
CommitRecoveryError, CommitSlotDiagnostic, CommitStoreDiagnostic, CommittedGenerationBytes,
DualCommitStore,
};
pub use policy::AllocationPolicy;
pub use registry::{
StaticMemoryDeclaration, StaticMemoryDeclarationError, StaticMemoryRangeDeclaration,
collect_static_memory_declarations, register_static_memory_declaration,
register_static_memory_manager_declaration,
register_static_memory_manager_declaration_with_schema, register_static_memory_manager_range,
register_static_memory_range_declaration, static_memory_declaration_snapshot,
static_memory_declarations, static_memory_range_authority, static_memory_range_declarations,
};
pub use runtime::{
RuntimeBootstrapError, RuntimeDiagnosticError, RuntimeOpenError, RuntimePolicyError,
bootstrap_default_memory_manager, bootstrap_default_memory_manager_with_policy,
committed_allocations, default_memory_manager_commit_recovery_diagnostic,
default_memory_manager_diagnostic_export, default_memory_manager_doctor_report,
is_default_memory_manager_bootstrapped, open_default_memory_manager_memory,
};
pub use schema::{SchemaMetadata, SchemaMetadataError};
pub use slot::{
AllocationSlot, AllocationSlotDescriptor, IC_MEMORY_AUTHORITY_OWNER,
IC_MEMORY_AUTHORITY_PURPOSE, IC_MEMORY_LEDGER_LABEL, IC_MEMORY_LEDGER_STABLE_KEY,
IC_MEMORY_STABLE_KEY_PREFIX, MEMORY_MANAGER_GOVERNANCE_MAX_ID, MEMORY_MANAGER_INVALID_ID,
MEMORY_MANAGER_LEDGER_ID, MEMORY_MANAGER_MAX_ID, MEMORY_MANAGER_MIN_ID,
MemoryManagerAuthorityRecord, MemoryManagerIdRange, MemoryManagerRangeAuthority,
MemoryManagerRangeAuthorityError, MemoryManagerRangeError, MemoryManagerRangeMode,
MemoryManagerSlotError, is_ic_memory_stable_key, memory_manager_governance_range,
validate_memory_manager_id,
};
pub use stable_cell::{
STABLE_CELL_HEADER_SIZE, STABLE_CELL_LAYOUT_VERSION, STABLE_CELL_MAGIC,
STABLE_CELL_VALUE_OFFSET, StableCellLedgerError, StableCellLedgerRecord,
StableCellPayloadError, decode_stable_cell_ledger_record, decode_stable_cell_payload,
validate_stable_cell_ledger_memory,
};
pub use validation::{AllocationValidationError, Validate, validate_allocations};
#[doc(hidden)]
pub use runtime::defer_eager_init;
#[doc(hidden)]
pub mod __reexports {
pub use ctor;
}
#[macro_export]
macro_rules! ic_memory_declaration {
(authority = $authority:literal, key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {
const _: () = {
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __ic_memory_register_static_declaration() {
let _ = core::marker::PhantomData::<$label>;
$crate::register_static_memory_manager_declaration(
$id,
$authority,
stringify!($label),
$stable_key,
)
.expect("ic-memory static memory declaration failed");
}
};
};
(authority = $authority:literal, key = $stable_key:literal, label = $label:literal, id = $id:expr $(,)?) => {
const _: () = {
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __ic_memory_register_static_declaration() {
$crate::register_static_memory_manager_declaration(
$id,
$authority,
$label,
$stable_key,
)
.expect("ic-memory static memory declaration failed");
}
};
};
}
#[macro_export]
macro_rules! ic_memory_range {
(authority = $authority:literal, start = $start:expr, end = $end:expr $(,)?) => {
$crate::ic_memory_range!(
authority = $authority,
start = $start,
end = $end,
mode = Reserved,
);
};
(authority = $authority:literal, start = $start:expr, end = $end:expr, mode = $mode:ident $(,)?) => {
const _: () = {
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __ic_memory_register_static_range() {
$crate::register_static_memory_manager_range(
$start,
$end,
$authority,
$crate::MemoryManagerRangeMode::$mode,
None,
)
.expect("ic-memory static memory range declaration failed");
}
};
};
}
#[macro_export]
macro_rules! ic_memory_key {
(authority = $authority:literal, key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {{
$crate::ic_memory_declaration!(authority = $authority, key = $stable_key, ty = $label, id = $id,);
$crate::open_default_memory_manager_memory($stable_key, $id)
.expect("ic-memory failed to open committed stable memory; bootstrap must run first and the stable key/id must match the committed declaration")
}};
(authority = $authority:literal, key = $stable_key:literal, label = $label:literal, id = $id:expr $(,)?) => {{
$crate::ic_memory_declaration!(authority = $authority, key = $stable_key, label = $label, id = $id,);
$crate::open_default_memory_manager_memory($stable_key, $id)
.expect("ic-memory failed to open committed stable memory; bootstrap must run first and the stable key/id must match the committed declaration")
}};
}
#[macro_export]
macro_rules! eager_init {
($body:block) => {
const _: () = {
fn __ic_memory_registered_eager_init_body() {
$body
}
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __ic_memory_register_eager_init() {
$crate::defer_eager_init(__ic_memory_registered_eager_init_body);
}
};
};
}