1pub use gear_wasm_instrument::{InstrumentationError, ModuleError};
22pub use wasmparser::BinaryReaderError;
23
24#[derive(PartialEq, Eq, Debug, derive_more::Display)]
26pub enum SectionName {
27 #[display("Type section")]
29 Type,
30 #[display("Import section")]
32 Import,
33 #[display("Function section")]
35 Function,
36 #[display("Data section")]
38 Data,
39 #[display("Global section")]
41 Global,
42 #[display("Table section")]
44 Table,
45 #[display("Element section")]
47 Element,
48 #[display("Export section")]
50 Export,
51 #[display("Start section")]
53 Start,
54}
55
56#[derive(Debug, derive_more::Display)]
58pub enum SectionError {
59 #[display("{_0} not found")]
61 NotFound(SectionName),
62 #[display("{_0} not supported")]
64 NotSupported(SectionName),
65}
66
67#[derive(Debug, derive_more::Display)]
69pub enum MemoryError {
70 #[display("Memory entry not found")]
72 EntryNotFound,
73 #[display("The WASM module has invalid count of static memory pages")]
75 InvalidStaticPageCount,
76}
77
78#[derive(Debug, derive_more::Display)]
80pub enum StackEndError {
81 #[display("Unsupported initialization of gear stack end global")]
83 Initialization,
84 #[display("Gear stack end {_0:#x} is not aligned to wasm page size")]
86 NotAligned(u32),
87 #[display("Gear stack end {_0:#x} is out of static memory 0x0..{_1:#x}")]
89 OutOfStatic(u32, u64),
90}
91
92#[derive(Debug, derive_more::Display)]
94pub enum DataSectionError {
95 #[display("Unsupported initialization of data segment")]
97 Initialization,
98 #[display("Data segment {_0:#x} overlaps gear stack 0x0..{_1:#x}")]
100 GearStackOverlaps(u32, u32),
101 #[display("Data segment {_0:#x} ends out of possible 32 bits address space")]
103 EndAddressOverflow(u32),
104 #[display("Data segment {_0:#x}..={_1:#x} is out of static memory 0x0..{_2:#x}")]
106 EndAddressOutOfStaticMemory(u32, u32, u64),
107 #[display("Data segment amount limit exceeded: limit={limit}, actual={actual}")]
109 DataSegmentsAmountLimit {
110 limit: u32,
112 actual: u32,
114 },
115}
116
117#[derive(Debug, derive_more::Display)]
119pub enum TypeSectionError {
120 #[display("Type section length limit exceeded: limit={limit}, actual={actual}")]
122 LengthLimitExceeded {
123 limit: u32,
125 actual: u32,
127 },
128 #[display("Type section parameters per type limit exceeded: limit={limit}, actual={actual}")]
130 ParametersPerTypeLimitExceeded {
131 limit: u32,
133 actual: u32,
135 },
136}
137
138#[derive(Debug, derive_more::Display)]
140pub enum ExportError {
141 #[display("Global index `{_0}` in export index `{_1}` is incorrect")]
143 IncorrectGlobalIndex(u32, u32),
144 #[display("Global index `{_0}` in export index `{_1}` cannot be mutable")]
146 MutableGlobalExport(u32, u32),
147 #[display("Export index `{_0}` references to imported function with index `{_1}`")]
149 ExportReferencesToImportFunction(u32, u32),
150 #[display("Export index `{_0}` references to imported global with index `{_1}`")]
152 ExportReferencesToImportGlobal(u32, u32),
153 #[display("Exported function with index `{_0}` must have signature `fn f() {{ ... }}`")]
155 InvalidExportFnSignature(u32),
156 #[display("Excess export with index `{_0}` found")]
158 ExcessExport(u32),
159 #[display("Required export function `init` or `handle` is not found")]
161 RequiredExportNotFound,
162}
163
164#[derive(Debug, derive_more::Display)]
166pub enum ImportError {
167 #[display("Unknown imported function with index `{_0}`")]
169 UnknownImport(u32),
170 #[display("Imported function with index `{_0}` is declared multiple times")]
172 DuplicateImport(u32),
173 #[display("Invalid function signature for imported function with index `{_0}`")]
175 InvalidImportFnSignature(u32),
176 #[display("Unexpected import kind `{kind}` with index `{index}`")]
178 UnexpectedImportKind {
179 kind: &'static &'static str,
181 index: u32,
183 },
184}
185
186#[derive(Debug, derive_more::Display, derive_more::From)]
188pub enum CodeError {
189 #[display("wasmparser validation error: {_0}")]
191 Validation(BinaryReaderError),
192 #[display("Codec error: {_0}")]
194 Module(ModuleError),
195 #[display("Section error: {_0}")]
197 Section(SectionError),
198 #[display("Memory error: {_0}")]
200 Memory(MemoryError),
201 #[display("Stack end error: {_0}")]
203 StackEnd(StackEndError),
204 #[display("Data section error: {_0}")]
206 DataSection(DataSectionError),
207 #[display("Type section error: {_0}")]
209 TypeSection(TypeSectionError),
210 #[display("Export error: {_0}")]
212 Export(ExportError),
213 #[display("Import error: {_0}")]
215 Import(ImportError),
216 #[display("Instrumentation error: {_0}")]
218 Instrumentation(InstrumentationError),
219}
220
221impl core::error::Error for CodeError {}