1#![forbid(unsafe_code)]
2#![deny(rustdoc::broken_intra_doc_links)]
3#![doc = include_str!("../README.md")]
4
5pub mod bootstrap;
66mod constants;
67pub mod declaration;
68pub mod diagnostics;
69pub mod key;
70pub mod ledger;
71pub mod physical;
72pub mod policy;
73pub mod registry;
74pub mod runtime;
75pub mod schema;
76pub mod session;
77pub mod slot;
78pub mod stable_cell;
79pub mod substrate;
80pub mod validation;
81
82pub use ic_stable_structures as stable_structures;
83
84pub use bootstrap::{
85 AllocationBootstrap, BootstrapCommit, BootstrapError, BootstrapReservationError,
86 BootstrapRetirementError,
87};
88pub use constants::WASM_PAGE_SIZE_BYTES;
89pub use declaration::{
90 AllocationDeclaration, DeclarationCollector, DeclarationSnapshot, DeclarationSnapshotError,
91};
92pub use diagnostics::{
93 DiagnosticExport, DiagnosticGeneration, DiagnosticMemorySize, DiagnosticRecord,
94};
95pub use key::{StableKey, StableKeyError};
96pub use ledger::{
97 AllocationHistory, AllocationLedger, AllocationRecord, AllocationReservationError,
98 AllocationRetirement, AllocationRetirementError, AllocationStageError, AllocationState,
99 GenerationRecord, LedgerCommitError, LedgerCommitStore, LedgerIntegrityError,
100 LedgerPayloadEnvelope, LedgerPayloadEnvelopeError, RecoveredLedger, SchemaMetadataRecord,
101};
102pub use physical::{
103 AuthoritativeSlot, CommitRecoveryError, CommitSlotDiagnostic, CommitSlotIndex,
104 CommitStoreDiagnostic, CommittedGenerationBytes, DualCommitStore, DualProtectedCommitStore,
105 ProtectedGenerationSlot, select_authoritative_slot,
106};
107pub use policy::AllocationPolicy;
108pub use registry::{
109 StaticMemoryDeclaration, StaticMemoryDeclarationError, StaticMemoryRangeDeclaration,
110 collect_static_memory_declarations, register_static_memory_declaration,
111 register_static_memory_manager_declaration,
112 register_static_memory_manager_declaration_with_schema, register_static_memory_manager_range,
113 register_static_memory_range_declaration, static_memory_declaration_snapshot,
114 static_memory_declarations, static_memory_range_authority, static_memory_range_declarations,
115};
116pub use runtime::{
117 RuntimeBootstrapError, RuntimeDiagnosticError, RuntimeOpenError, RuntimePolicyError,
118 bootstrap_default_memory_manager, bootstrap_default_memory_manager_with_policy,
119 default_memory_manager_commit_recovery_diagnostic, default_memory_manager_diagnostic_export,
120};
121pub use schema::{SchemaMetadata, SchemaMetadataError};
122pub use session::{AllocationSession, AllocationSessionError, ValidatedAllocations};
123pub use slot::{
124 AllocationSlot, AllocationSlotDescriptor, IC_MEMORY_AUTHORITY_OWNER,
125 IC_MEMORY_AUTHORITY_PURPOSE, IC_MEMORY_LEDGER_LABEL, IC_MEMORY_LEDGER_STABLE_KEY,
126 IC_MEMORY_STABLE_KEY_PREFIX, MEMORY_MANAGER_GOVERNANCE_MAX_ID, MEMORY_MANAGER_INVALID_ID,
127 MEMORY_MANAGER_LEDGER_ID, MEMORY_MANAGER_MAX_ID, MEMORY_MANAGER_MIN_ID,
128 MemoryManagerAuthorityRecord, MemoryManagerIdRange, MemoryManagerRangeAuthority,
129 MemoryManagerRangeAuthorityError, MemoryManagerRangeError, MemoryManagerRangeMode,
130 MemoryManagerSlotError, is_ic_memory_stable_key, memory_manager_governance_range,
131 validate_memory_manager_id,
132};
133pub use stable_cell::{
134 STABLE_CELL_HEADER_SIZE, STABLE_CELL_LAYOUT_VERSION, STABLE_CELL_MAGIC,
135 STABLE_CELL_VALUE_OFFSET, StableCellLedgerError, StableCellLedgerRecord,
136 StableCellPayloadError, decode_stable_cell_ledger_record, decode_stable_cell_payload,
137 validate_stable_cell_ledger_memory,
138};
139pub use substrate::{LedgerAnchor, StorageSubstrate};
140pub use validation::{AllocationValidationError, Validate, validate_allocations};
141
142#[doc(hidden)]
143pub mod __reexports {
144 pub use ctor;
145}
146
147#[macro_export]
153macro_rules! ic_memory_declaration {
154 (key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {
155 const _: () = {
156 #[allow(dead_code)]
157 type IcMemoryTypeCheck = $label;
158
159 #[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
160 fn __ic_memory_register_static_declaration() {
161 $crate::register_static_memory_manager_declaration(
162 $id,
163 env!("CARGO_PKG_NAME"),
164 stringify!($label),
165 $stable_key,
166 )
167 .expect("ic-memory static memory declaration failed");
168 }
169 };
170 };
171 (key = $stable_key:literal, label = $label:literal, id = $id:expr $(,)?) => {
172 const _: () = {
173 #[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
174 fn __ic_memory_register_static_declaration() {
175 $crate::register_static_memory_manager_declaration(
176 $id,
177 env!("CARGO_PKG_NAME"),
178 $label,
179 $stable_key,
180 )
181 .expect("ic-memory static memory declaration failed");
182 }
183 };
184 };
185}
186
187#[macro_export]
189macro_rules! ic_memory_range {
190 (start = $start:expr, end = $end:expr $(,)?) => {
191 $crate::ic_memory_range!(
192 start = $start,
193 end = $end,
194 mode = Reserved,
195 );
196 };
197 (start = $start:expr, end = $end:expr, mode = $mode:ident $(,)?) => {
198 const _: () = {
199 #[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
200 fn __ic_memory_register_static_range() {
201 $crate::register_static_memory_manager_range(
202 $start,
203 $end,
204 env!("CARGO_PKG_NAME"),
205 $crate::MemoryManagerRangeMode::$mode,
206 None,
207 )
208 .expect("ic-memory static memory range declaration failed");
209 }
210 };
211 };
212}
213
214#[macro_export]
219macro_rules! ic_memory_key {
220 ($stable_key:literal, $label:path, $id:expr $(,)?) => {{
221 $crate::ic_memory_declaration!(key = $stable_key, ty = $label, id = $id,);
222 $crate::runtime::open_default_memory_manager_memory($stable_key, $id)
223 .expect("ic-memory failed to open validated stable memory; bootstrap must run first and the stable key/id must match the validated declaration")
224 }};
225 (key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {{ $crate::ic_memory_key!($stable_key, $label, $id) }};
226 (key = $stable_key:literal, label = $label:literal, id = $id:expr $(,)?) => {{
227 $crate::ic_memory_declaration!(key = $stable_key, label = $label, id = $id,);
228 $crate::runtime::open_default_memory_manager_memory($stable_key, $id)
229 .expect("ic-memory failed to open validated stable memory; bootstrap must run first and the stable key/id must match the validated declaration")
230 }};
231}
232
233#[macro_export]
235macro_rules! eager_init {
236 ($body:block) => {
237 const _: () = {
238 fn __ic_memory_registered_eager_init_body() {
239 $body
240 }
241
242 #[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
243 fn __ic_memory_register_eager_init() {
244 $crate::runtime::defer_eager_init(__ic_memory_registered_eager_init_body);
245 }
246 };
247 };
248}