1pub use gear_wasm_instrument::{InstrumentationError, ModuleError};
7pub use wasmparser::BinaryReaderError;
8
9#[derive(PartialEq, Eq, Debug, derive_more::Display)]
11pub enum SectionName {
12 #[display("Type section")]
14 Type,
15 #[display("Import section")]
17 Import,
18 #[display("Function section")]
20 Function,
21 #[display("Data section")]
23 Data,
24 #[display("Global section")]
26 Global,
27 #[display("Table section")]
29 Table,
30 #[display("Element section")]
32 Element,
33 #[display("Export section")]
35 Export,
36 #[display("Start section")]
38 Start,
39}
40
41#[derive(Debug, derive_more::Display)]
43pub enum SectionError {
44 #[display("{_0} not found")]
46 NotFound(SectionName),
47 #[display("{_0} not supported")]
49 NotSupported(SectionName),
50}
51
52#[derive(Debug, derive_more::Display)]
54pub enum MemoryError {
55 #[display("Memory entry not found")]
57 EntryNotFound,
58 #[display("The WASM module has invalid count of static memory pages")]
60 InvalidStaticPageCount,
61}
62
63#[derive(Debug, derive_more::Display)]
65pub enum StackEndError {
66 #[display("Unsupported initialization of gear stack end global")]
68 Initialization,
69 #[display("Gear stack end {_0:#x} is not aligned to wasm page size")]
71 NotAligned(u32),
72 #[display("Gear stack end {_0:#x} is out of static memory 0x0..{_1:#x}")]
74 OutOfStatic(u32, u64),
75}
76
77#[derive(Debug, derive_more::Display)]
79pub enum DataSectionError {
80 #[display("Unsupported initialization of data segment")]
82 Initialization,
83 #[display("Data segment {_0:#x} overlaps gear stack 0x0..{_1:#x}")]
85 GearStackOverlaps(u32, u32),
86 #[display("Data segment {_0:#x} ends out of possible 32 bits address space")]
88 EndAddressOverflow(u32),
89 #[display("Data segment {_0:#x}..={_1:#x} is out of static memory 0x0..{_2:#x}")]
91 EndAddressOutOfStaticMemory(u32, u32, u64),
92 #[display("Data segment amount limit exceeded: limit={limit}, actual={actual}")]
94 DataSegmentsAmountLimit {
95 limit: u32,
97 actual: u32,
99 },
100}
101
102#[derive(Debug, derive_more::Display)]
104pub enum TypeSectionError {
105 #[display("Type section length limit exceeded: limit={limit}, actual={actual}")]
107 LengthLimitExceeded {
108 limit: u32,
110 actual: u32,
112 },
113 #[display("Type section parameters per type limit exceeded: limit={limit}, actual={actual}")]
115 ParametersPerTypeLimitExceeded {
116 limit: u32,
118 actual: u32,
120 },
121}
122
123#[derive(Debug, derive_more::Display)]
125pub enum ExportError {
126 #[display("Global index `{_0}` in export index `{_1}` is incorrect")]
128 IncorrectGlobalIndex(u32, u32),
129 #[display("Global index `{_0}` in export index `{_1}` cannot be mutable")]
131 MutableGlobalExport(u32, u32),
132 #[display("Export index `{_0}` references to imported function with index `{_1}`")]
134 ExportReferencesToImportFunction(u32, u32),
135 #[display("Export index `{_0}` references to imported global with index `{_1}`")]
137 ExportReferencesToImportGlobal(u32, u32),
138 #[display("Exported function with index `{_0}` must have signature `fn f() {{ ... }}`")]
140 InvalidExportFnSignature(u32),
141 #[display("Excess export with index `{_0}` found")]
143 ExcessExport(u32),
144 #[display("Required export function `init` or `handle` is not found")]
146 RequiredExportNotFound,
147}
148
149#[derive(Debug, derive_more::Display)]
151pub enum ImportError {
152 #[display("Unknown imported function with index `{_0}`")]
154 UnknownImport(u32),
155 #[display("Imported function with index `{_0}` is declared multiple times")]
157 DuplicateImport(u32),
158 #[display("Invalid function signature for imported function with index `{_0}`")]
160 InvalidImportFnSignature(u32),
161 #[display("Unexpected import kind `{kind}` with index `{index}`")]
163 UnexpectedImportKind {
164 kind: &'static &'static str,
166 index: u32,
168 },
169}
170
171#[derive(Debug, derive_more::Display, derive_more::From)]
173pub enum CodeError {
174 #[display("wasmparser validation error: {_0}")]
176 Validation(BinaryReaderError),
177 #[display("Codec error: {_0}")]
179 Module(ModuleError),
180 #[display("Section error: {_0}")]
182 Section(SectionError),
183 #[display("Memory error: {_0}")]
185 Memory(MemoryError),
186 #[display("Stack end error: {_0}")]
188 StackEnd(StackEndError),
189 #[display("Data section error: {_0}")]
191 DataSection(DataSectionError),
192 #[display("Type section error: {_0}")]
194 TypeSection(TypeSectionError),
195 #[display("Export error: {_0}")]
197 Export(ExportError),
198 #[display("Import error: {_0}")]
200 Import(ImportError),
201 #[display("Instrumentation error: {_0}")]
203 Instrumentation(InstrumentationError),
204}
205
206impl core::error::Error for CodeError {}