pub use gear_wasm_instrument::{InstrumentationError, ModuleError};
pub use wasmparser::BinaryReaderError;
#[derive(PartialEq, Eq, Debug, derive_more::Display)]
pub enum SectionName {
#[display("Type section")]
Type,
#[display("Import section")]
Import,
#[display("Function section")]
Function,
#[display("Data section")]
Data,
#[display("Global section")]
Global,
#[display("Table section")]
Table,
#[display("Element section")]
Element,
#[display("Export section")]
Export,
#[display("Start section")]
Start,
}
#[derive(Debug, derive_more::Display)]
pub enum SectionError {
#[display("{_0} not found")]
NotFound(SectionName),
#[display("{_0} not supported")]
NotSupported(SectionName),
}
#[derive(Debug, derive_more::Display)]
pub enum MemoryError {
#[display("Memory entry not found")]
EntryNotFound,
#[display("The WASM module has invalid count of static memory pages")]
InvalidStaticPageCount,
}
#[derive(Debug, derive_more::Display)]
pub enum StackEndError {
#[display("Unsupported initialization of gear stack end global")]
Initialization,
#[display("Gear stack end {_0:#x} is not aligned to wasm page size")]
NotAligned(u32),
#[display("Gear stack end {_0:#x} is out of static memory 0x0..{_1:#x}")]
OutOfStatic(u32, u64),
}
#[derive(Debug, derive_more::Display)]
pub enum DataSectionError {
#[display("Unsupported initialization of data segment")]
Initialization,
#[display("Data segment {_0:#x} overlaps gear stack 0x0..{_1:#x}")]
GearStackOverlaps(u32, u32),
#[display("Data segment {_0:#x} ends out of possible 32 bits address space")]
EndAddressOverflow(u32),
#[display("Data segment {_0:#x}..={_1:#x} is out of static memory 0x0..{_2:#x}")]
EndAddressOutOfStaticMemory(u32, u32, u64),
#[display("Data segment amount limit exceeded: limit={limit}, actual={actual}")]
DataSegmentsAmountLimit {
limit: u32,
actual: u32,
},
}
#[derive(Debug, derive_more::Display)]
pub enum TypeSectionError {
#[display("Type section length limit exceeded: limit={limit}, actual={actual}")]
LengthLimitExceeded {
limit: u32,
actual: u32,
},
#[display("Type section parameters per type limit exceeded: limit={limit}, actual={actual}")]
ParametersPerTypeLimitExceeded {
limit: u32,
actual: u32,
},
}
#[derive(Debug, derive_more::Display)]
pub enum ExportError {
#[display("Global index `{_0}` in export index `{_1}` is incorrect")]
IncorrectGlobalIndex(u32, u32),
#[display("Global index `{_0}` in export index `{_1}` cannot be mutable")]
MutableGlobalExport(u32, u32),
#[display("Export index `{_0}` references to imported function with index `{_1}`")]
ExportReferencesToImportFunction(u32, u32),
#[display("Export index `{_0}` references to imported global with index `{_1}`")]
ExportReferencesToImportGlobal(u32, u32),
#[display("Exported function with index `{_0}` must have signature `fn f() {{ ... }}`")]
InvalidExportFnSignature(u32),
#[display("Excess export with index `{_0}` found")]
ExcessExport(u32),
#[display("Required export function `init` or `handle` is not found")]
RequiredExportNotFound,
}
#[derive(Debug, derive_more::Display)]
pub enum ImportError {
#[display("Unknown imported function with index `{_0}`")]
UnknownImport(u32),
#[display("Imported function with index `{_0}` is declared multiple times")]
DuplicateImport(u32),
#[display("Invalid function signature for imported function with index `{_0}`")]
InvalidImportFnSignature(u32),
#[display("Unexpected import kind `{kind}` with index `{index}`")]
UnexpectedImportKind {
kind: &'static &'static str,
index: u32,
},
}
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum CodeError {
#[display("wasmparser validation error: {_0}")]
Validation(BinaryReaderError),
#[display("Codec error: {_0}")]
Module(ModuleError),
#[display("Section error: {_0}")]
Section(SectionError),
#[display("Memory error: {_0}")]
Memory(MemoryError),
#[display("Stack end error: {_0}")]
StackEnd(StackEndError),
#[display("Data section error: {_0}")]
DataSection(DataSectionError),
#[display("Type section error: {_0}")]
TypeSection(TypeSectionError),
#[display("Export error: {_0}")]
Export(ExportError),
#[display("Import error: {_0}")]
Import(ImportError),
#[display("Instrumentation error: {_0}")]
Instrumentation(InstrumentationError),
}
impl core::error::Error for CodeError {}