#![deny(unsafe_code, unsafe_op_in_unsafe_fn)]
#![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 ic_stable_structures;
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::{
DiagnosticCheck, DiagnosticCode, DiagnosticDeclaration, DiagnosticExport, DiagnosticFailure,
DiagnosticGeneration, DiagnosticMemorySize, DiagnosticMemorySizeOutcome,
DiagnosticRangeAuthority, DiagnosticRecord, DiagnosticRuntimeBinding, DiagnosticStableCell,
DiagnosticStableCellStatus, MemoryRuntimeDoctorReport,
};
pub use key::{StableKey, StableKeyError};
pub use ledger::{
AllocationHistory, AllocationLedger, AllocationRecord, AllocationReservationError,
AllocationRetirement, AllocationRetirementError, AllocationStageError, AllocationState,
GenerationRecord, LEDGER_PAYLOAD_FORMAT_VERSION, LedgerCommitError, LedgerCommitStore,
LedgerIntegrityError, LedgerPayloadEnvelope, LedgerPayloadEnvelopeError, RecoveredLedger,
SchemaMetadataRecord,
};
pub use physical::{
CommitRecoveryError, CommitSlotDiagnostic, CommitStoreDiagnostic, CommittedGenerationBytes,
DualCommitStore,
};
pub use policy::{AllocationPolicy, PolicyIdentity, PolicyIdentityError, RuntimeBootstrapPolicy};
pub use registry::{
SealedDeclarationFingerprint, SealedDeclarationSnapshot, StaticMemoryDeclaration,
StaticMemoryDeclarationError, StaticMemoryRangeDeclaration, 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, sealed_declaration_snapshot,
};
pub use runtime::{
AllocationBinding, AllocationRangeClaim, MemoryAllocation, MemoryAllocations,
MemoryManagerConfig, MemoryManagerLayoutError, MemoryRuntime, RuntimeBootstrapError,
RuntimeConstructionError, RuntimeDiagnosticError, RuntimeMemory, RuntimeOpenError,
RuntimePolicyError, RuntimeStateError, bootstrap_default_memory_manager,
bootstrap_default_memory_manager_with_config, bootstrap_default_memory_manager_with_policy,
committed_allocations, default_memory_manager_commit_recovery_diagnostic,
default_memory_manager_diagnostic_export, default_memory_manager_doctor_report,
default_memory_manager_doctor_report_with_policy, default_memory_manager_memory_allocations,
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 registry::{defer_eager_init, defer_static_memory_registration};
#[doc(hidden)]
pub mod __reexports {
pub use ctor;
}
#[macro_export]
macro_rules! ic_memory_declaration {
(authority = $authority:expr, key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {
const _: () = {
const __IC_MEMORY_AUTHORITY: &str = $authority;
fn __ic_memory_register_static_declaration() -> Result<(), $crate::StaticMemoryDeclarationError> {
let _ = core::marker::PhantomData::<$label>;
$crate::register_static_memory_manager_declaration(
$id,
__IC_MEMORY_AUTHORITY,
stringify!($label),
$stable_key,
)
}
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __ic_memory_defer_static_declaration() {
$crate::defer_static_memory_registration(__ic_memory_register_static_declaration);
}
};
};
(authority = $authority:expr, key = $stable_key:literal, label = $label:literal, id = $id:expr $(,)?) => {
const _: () = {
const __IC_MEMORY_AUTHORITY: &str = $authority;
fn __ic_memory_register_static_declaration() -> Result<(), $crate::StaticMemoryDeclarationError> {
$crate::register_static_memory_manager_declaration(
$id,
__IC_MEMORY_AUTHORITY,
$label,
$stable_key,
)
}
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __ic_memory_defer_static_declaration() {
$crate::defer_static_memory_registration(__ic_memory_register_static_declaration);
}
};
};
}
#[macro_export]
macro_rules! ic_memory_range {
(authority = $authority:expr, start = $start:expr, end = $end:expr $(,)?) => {
$crate::ic_memory_range!(
authority = $authority,
start = $start,
end = $end,
mode = Reserved,
);
};
(authority = $authority:expr, start = $start:expr, end = $end:expr, mode = $mode:ident $(,)?) => {
const _: () = {
const __IC_MEMORY_AUTHORITY: &str = $authority;
fn __ic_memory_register_static_range() -> Result<(), $crate::StaticMemoryDeclarationError> {
$crate::register_static_memory_manager_range(
$start,
$end,
__IC_MEMORY_AUTHORITY,
$crate::MemoryManagerRangeMode::$mode,
None,
)
}
#[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
fn __ic_memory_defer_static_range() {
$crate::defer_static_memory_registration(__ic_memory_register_static_range);
}
};
};
}
#[macro_export]
macro_rules! ic_memory_key {
(authority = $authority:expr, 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)
}};
(authority = $authority:expr, 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)
}};
}
#[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);
}
};
};
}