1#![forbid(unsafe_code)]
2#![deny(rustdoc::broken_intra_doc_links)]
3#![doc = include_str!("../README.md")]
4
5mod bootstrap;
73mod capability;
74mod cbor;
75mod constants;
76mod declaration;
77mod diagnostics;
78mod key;
79mod ledger;
80mod physical;
81mod policy;
82mod registry;
83mod runtime;
84mod schema;
85mod slot;
86mod stable_cell;
87mod validation;
88
89#[cfg(test)]
90mod test_cbor {
91 use serde::{Serialize, de::DeserializeOwned};
92
93 pub use ciborium::Value;
94
95 pub fn to_vec<T: Serialize>(
96 value: &T,
97 ) -> Result<Vec<u8>, ciborium::ser::Error<std::io::Error>> {
98 let mut bytes = Vec::new();
99 ciborium::into_writer(value, &mut bytes)?;
100 Ok(bytes)
101 }
102
103 pub fn from_slice<T: DeserializeOwned>(
104 bytes: &[u8],
105 ) -> Result<T, ciborium::de::Error<std::io::Error>> {
106 crate::cbor::from_slice_exact(bytes)
107 }
108
109 pub fn to_value<T: Serialize>(value: T) -> Result<Value, ciborium::value::Error> {
110 Value::serialized(&value)
111 }
112
113 pub fn map_insert(map: &mut Vec<(Value, Value)>, key: Value, value: Value) {
114 map.push((key, value));
115 }
116}
117
118pub use bootstrap::{
119 AllocationBootstrap, BootstrapError, BootstrapReservationError, BootstrapRetirementError,
120 PendingBootstrapCommit,
121};
122pub use capability::{CommittedAllocations, ValidatedAllocations};
123pub use constants::WASM_PAGE_SIZE_BYTES;
124pub use declaration::{
125 AllocationDeclaration, DeclarationCollector, DeclarationSnapshot, DeclarationSnapshotError,
126};
127pub use diagnostics::{
128 DiagnosticCheck, DiagnosticCode, DiagnosticDeclaration, DiagnosticExport, DiagnosticFailure,
129 DiagnosticGeneration, DiagnosticMemorySize, DiagnosticRangeAuthority, DiagnosticRecord,
130 DiagnosticStableCell, DiagnosticStableCellStatus, MemoryRuntimeDoctorReport,
131};
132pub use key::{StableKey, StableKeyError};
133pub use ledger::{
134 AllocationHistory, AllocationLedger, AllocationRecord, AllocationReservationError,
135 AllocationRetirement, AllocationRetirementError, AllocationStageError, AllocationState,
136 GenerationRecord, LEDGER_PAYLOAD_FORMAT_VERSION, LedgerCommitError, LedgerCommitStore,
137 LedgerIntegrityError, LedgerPayloadEnvelope, LedgerPayloadEnvelopeError, RecoveredLedger,
138 SchemaMetadataRecord,
139};
140pub use physical::{
141 CommitRecoveryError, CommitSlotDiagnostic, CommitStoreDiagnostic, CommittedGenerationBytes,
142 DualCommitStore,
143};
144pub use policy::{AllocationPolicy, RuntimeBootstrapPolicy};
145pub use registry::{
146 SealedDeclarationSnapshot, StaticMemoryDeclaration, StaticMemoryDeclarationError,
147 StaticMemoryRangeDeclaration, register_static_memory_declaration,
148 register_static_memory_manager_declaration,
149 register_static_memory_manager_declaration_with_schema, register_static_memory_manager_range,
150 register_static_memory_range_declaration, sealed_declaration_snapshot,
151};
152pub use runtime::{
153 MemoryRuntime, RuntimeBootstrapError, RuntimeConstructionError, RuntimeDiagnosticError,
154 RuntimeOpenError, RuntimePolicyError, RuntimeStateError, bootstrap_default_memory_manager,
155 bootstrap_default_memory_manager_with_policy, committed_allocations,
156 default_memory_manager_commit_recovery_diagnostic, default_memory_manager_diagnostic_export,
157 default_memory_manager_doctor_report, is_default_memory_manager_bootstrapped,
158 open_default_memory_manager_memory,
159};
160pub use schema::{SchemaMetadata, SchemaMetadataError};
161pub use slot::{
162 AllocationSlot, AllocationSlotDescriptor, IC_MEMORY_AUTHORITY_OWNER,
163 IC_MEMORY_AUTHORITY_PURPOSE, IC_MEMORY_LEDGER_LABEL, IC_MEMORY_LEDGER_STABLE_KEY,
164 IC_MEMORY_STABLE_KEY_PREFIX, MEMORY_MANAGER_GOVERNANCE_MAX_ID, MEMORY_MANAGER_INVALID_ID,
165 MEMORY_MANAGER_LEDGER_ID, MEMORY_MANAGER_MAX_ID, MEMORY_MANAGER_MIN_ID,
166 MemoryManagerAuthorityRecord, MemoryManagerIdRange, MemoryManagerRangeAuthority,
167 MemoryManagerRangeAuthorityError, MemoryManagerRangeError, MemoryManagerRangeMode,
168 MemoryManagerSlotError, is_ic_memory_stable_key, memory_manager_governance_range,
169 validate_memory_manager_id,
170};
171pub use stable_cell::{
172 STABLE_CELL_HEADER_SIZE, STABLE_CELL_LAYOUT_VERSION, STABLE_CELL_MAGIC,
173 STABLE_CELL_VALUE_OFFSET, StableCellLedgerError, StableCellLedgerRecord,
174 StableCellPayloadError, decode_stable_cell_ledger_record, decode_stable_cell_payload,
175 validate_stable_cell_ledger_memory,
176};
177pub use validation::{AllocationValidationError, Validate, validate_allocations};
178
179#[doc(hidden)]
180pub use registry::{defer_eager_init, defer_static_memory_registration};
181
182#[doc(hidden)]
183pub mod __reexports {
184 pub use ctor;
185}
186
187#[macro_export]
197macro_rules! ic_memory_declaration {
198 (authority = $authority:expr, key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {
199 const _: () = {
200 const __IC_MEMORY_AUTHORITY: &str = $authority;
201
202 fn __ic_memory_register_static_declaration() -> Result<(), $crate::StaticMemoryDeclarationError> {
203 let _ = core::marker::PhantomData::<$label>;
204 $crate::register_static_memory_manager_declaration(
205 $id,
206 __IC_MEMORY_AUTHORITY,
207 stringify!($label),
208 $stable_key,
209 )
210 }
211
212 #[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
213 fn __ic_memory_defer_static_declaration() {
214 $crate::defer_static_memory_registration(__ic_memory_register_static_declaration);
215 }
216 };
217 };
218 (authority = $authority:expr, key = $stable_key:literal, label = $label:literal, id = $id:expr $(,)?) => {
219 const _: () = {
220 const __IC_MEMORY_AUTHORITY: &str = $authority;
221
222 fn __ic_memory_register_static_declaration() -> Result<(), $crate::StaticMemoryDeclarationError> {
223 $crate::register_static_memory_manager_declaration(
224 $id,
225 __IC_MEMORY_AUTHORITY,
226 $label,
227 $stable_key,
228 )
229 }
230
231 #[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
232 fn __ic_memory_defer_static_declaration() {
233 $crate::defer_static_memory_registration(__ic_memory_register_static_declaration);
234 }
235 };
236 };
237}
238
239#[macro_export]
244macro_rules! ic_memory_range {
245 (authority = $authority:expr, start = $start:expr, end = $end:expr $(,)?) => {
246 $crate::ic_memory_range!(
247 authority = $authority,
248 start = $start,
249 end = $end,
250 mode = Reserved,
251 );
252 };
253 (authority = $authority:expr, start = $start:expr, end = $end:expr, mode = $mode:ident $(,)?) => {
254 const _: () = {
255 const __IC_MEMORY_AUTHORITY: &str = $authority;
256
257 fn __ic_memory_register_static_range() -> Result<(), $crate::StaticMemoryDeclarationError> {
258 $crate::register_static_memory_manager_range(
259 $start,
260 $end,
261 __IC_MEMORY_AUTHORITY,
262 $crate::MemoryManagerRangeMode::$mode,
263 None,
264 )
265 }
266
267 #[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
268 fn __ic_memory_defer_static_range() {
269 $crate::defer_static_memory_registration(__ic_memory_register_static_range);
270 }
271 };
272 };
273}
274
275#[macro_export]
280macro_rules! ic_memory_key {
281 (authority = $authority:expr, key = $stable_key:literal, ty = $label:path, id = $id:expr $(,)?) => {{
282 $crate::ic_memory_declaration!(
283 authority = $authority,
284 key = $stable_key,
285 ty = $label,
286 id = $id,
287 );
288 $crate::open_default_memory_manager_memory($stable_key, $id)
289 }};
290 (authority = $authority:expr, key = $stable_key:literal, label = $label:literal, id = $id:expr $(,)?) => {{
291 $crate::ic_memory_declaration!(
292 authority = $authority,
293 key = $stable_key,
294 label = $label,
295 id = $id,
296 );
297 $crate::open_default_memory_manager_memory($stable_key, $id)
298 }};
299}
300
301#[macro_export]
303macro_rules! eager_init {
304 ($body:block) => {
305 const _: () = {
306 fn __ic_memory_registered_eager_init_body() {
307 $body
308 }
309
310 #[ $crate::__reexports::ctor::ctor(unsafe, anonymous, crate_path = $crate::__reexports::ctor) ]
311 fn __ic_memory_register_eager_init() {
312 $crate::defer_eager_init(__ic_memory_registered_eager_init_body);
313 }
314 };
315 };
316}