1#![deny(unsafe_code, unsafe_op_in_unsafe_fn)]
2#![deny(rustdoc::broken_intra_doc_links)]
3#![doc = include_str!("../README.md")]
4
5mod allocation_pool;
78mod bootstrap;
79mod bounded_writer;
80mod capability;
81mod cbor;
82mod constants;
83mod declaration;
84mod diagnostics;
85mod hash;
86mod key;
87mod ledger;
88mod physical;
89mod policy;
90mod requests;
91mod runtime;
92mod schema;
93mod slot;
94mod sort;
95mod stable_cell;
96mod text;
97mod validation;
98
99#[cfg(test)]
100mod test_cbor {
101 use serde::{Serialize, de::DeserializeOwned};
102
103 pub use ciborium::Value;
104
105 pub fn to_vec<T: Serialize>(
106 value: &T,
107 ) -> Result<Vec<u8>, ciborium::ser::Error<std::io::Error>> {
108 let mut bytes = Vec::new();
109 ciborium::into_writer(value, &mut bytes)?;
110 Ok(bytes)
111 }
112
113 pub fn from_slice<T: DeserializeOwned>(
114 bytes: &[u8],
115 ) -> Result<T, ciborium::de::Error<std::io::Error>> {
116 crate::cbor::from_slice_exact(bytes)
117 }
118
119 pub fn to_value<T: Serialize>(value: T) -> Result<Value, ciborium::value::Error> {
120 Value::serialized(&value)
121 }
122
123 pub fn hex_fixture(contents: &str) -> Vec<u8> {
124 let hex = contents
125 .chars()
126 .filter(|char| !char.is_whitespace())
127 .collect::<String>();
128 assert_eq!(hex.len() % 2, 0, "fixture hex must have byte pairs");
129 hex.as_bytes()
130 .as_chunks::<2>()
131 .0
132 .iter()
133 .map(|pair| {
134 let pair = std::str::from_utf8(pair).expect("fixture hex is utf8");
135 u8::from_str_radix(pair, 16).expect("fixture hex byte")
136 })
137 .collect()
138 }
139}
140
141pub use ic_stable_structures;
146
147pub use allocation_pool::{MemoryAllocationPool, MemoryAllocationPoolError, MemoryAuthority};
148pub use bootstrap::BootstrapError;
149pub use capability::CommittedAllocations;
150pub use constants::{
151 MAX_LEDGER_BYTES, MAX_LEDGER_NESTING, MAX_LEDGER_RECORD_BYTES, WASM_PAGE_SIZE_BYTES,
152};
153pub use declaration::{AllocationDeclaration, DeclarationSnapshot, DeclarationSnapshotError};
154pub use diagnostics::{
155 DiagnosticCheck, DiagnosticCode, DiagnosticExport, DiagnosticFailure, DiagnosticMemorySize,
156 DiagnosticRecord, DiagnosticRuntimeBinding, DiagnosticStableCell, DiagnosticStableCellStatus,
157 MemoryRuntimeDoctorReport,
158};
159pub use key::{StableKey, StableKeyError};
160pub(crate) use ledger::LedgerCommitStore;
161#[cfg(test)]
162pub(crate) use ledger::LedgerPayloadEnvelope;
163pub use ledger::{
164 AllocationLedger, AllocationRecord, AllocationReservationError, AllocationRetirement,
165 AllocationRetirementError, AllocationStageError, AllocationState,
166 LEDGER_PAYLOAD_FORMAT_VERSION, LedgerCommitError, LedgerIntegrityError,
167 LedgerPayloadEnvelopeError, RecoveredLedger,
168};
169pub use physical::{CommitRecoveryError, CommitSnapshotDiagnostic, CommitStoreDiagnostic};
170#[cfg(test)]
171pub(crate) use physical::{CommittedGenerationBytes, SnapshotCommitStore};
172pub use policy::{AllocationPolicy, PolicyIdentity, PolicyIdentityError, RuntimeBootstrapPolicy};
173pub use requests::{
174 MemoryDeclarationError, MemoryRequest, SealedDeclarationFingerprint, SealedDeclarationSnapshot,
175};
176pub use runtime::{
177 AllocationBinding, BootstrapAdmission, BootstrapAdmissionError, GenericAllocationPolicy,
178 MemoryAllocation, MemoryAllocationSummary, MemoryAllocations, MemoryBindingSummary,
179 MemoryManagerConfig, MemoryManagerLayoutError, MemoryResolutionError, MemoryRuntime,
180 RecoveredAllocationMetadata, RuntimeAdoptionError, RuntimeBootstrapError,
181 RuntimeConstructionError, RuntimeDiagnosticError, RuntimeGrowError, RuntimeMemory,
182 RuntimeOpenError, RuntimeStateError, bootstrap_default_memory_manager,
183 bootstrap_default_memory_manager_with_config, bootstrap_default_memory_manager_with_policy,
184 committed_allocations, default_memory_manager_commit_recovery_diagnostic,
185 default_memory_manager_diagnostic_export, default_memory_manager_doctor_report,
186 default_memory_manager_doctor_report_with_policy,
187 default_memory_manager_memory_allocation_summary, default_memory_manager_memory_allocations,
188 default_memory_manager_memory_id, is_default_memory_manager_bootstrapped,
189 open_default_memory_manager_memory, verify_default_memory_manager_authority,
190};
191pub use schema::{SchemaMetadata, SchemaMetadataError};
192pub use slot::{
193 IC_MEMORY_AUTHORITY_OWNER, IC_MEMORY_LEDGER_LABEL, IC_MEMORY_LEDGER_STABLE_KEY,
194 IC_MEMORY_STABLE_KEY_PREFIX, MEMORY_MANAGER_GOVERNANCE_MAX_ID, MEMORY_MANAGER_INVALID_ID,
195 MEMORY_MANAGER_LEDGER_ID, MEMORY_MANAGER_MAX_ID, MEMORY_MANAGER_MIN_ID, MemoryManagerIdRange,
196 MemoryManagerRangeError, MemoryManagerSlot, MemoryManagerSlotError, is_ic_memory_stable_key,
197 memory_manager_governance_range, validate_memory_manager_id,
198};
199pub use stable_cell::{
200 STABLE_CELL_HEADER_SIZE, STABLE_CELL_LAYOUT_VERSION, STABLE_CELL_MAGIC,
201 STABLE_CELL_VALUE_OFFSET, StableCellLedgerError, StableCellLedgerRecord,
202 StableCellPayloadError, decode_stable_cell_ledger_record,
203 decode_stable_cell_ledger_record_from_memory, decode_stable_cell_payload,
204};
205pub use validation::AllocationValidationError;
206#[cfg(test)]
207pub(crate) use validation::validate_allocations;
208
209#[cfg(test)]
210mod allocation_measurements_tests;