wasmer_wasix/state/linker/
error.rs1use std::path::PathBuf;
2
3use crate::SpawnError;
4use virtual_fs::FsError;
5use wasmer::{ExportError, ExternType, InstantiationError, MemoryError, RuntimeError};
6
7use super::ModuleHandle;
8
9#[derive(thiserror::Error, Debug)]
10pub enum LinkError {
11 #[error("Cannot access linker through a dead instance group")]
12 InstanceGroupIsDead,
13
14 #[error("Main module is missing a required import: {0}")]
15 MissingMainModuleImport(String),
16
17 #[error("Failed to spawn module: {0}")]
18 SpawnError(#[from] SpawnError),
19
20 #[error("Failed to instantiate module: {0}")]
21 InstantiationError(#[from] InstantiationError),
22
23 #[error("Memory allocation error: {0}")]
24 MemoryAllocationError(#[from] MemoryError),
25
26 #[error("Failed to allocate function table indices: {0}")]
27 TableAllocationError(RuntimeError),
28
29 #[error("Failed to find shared library {0}: {1}")]
30 SharedLibraryMissing(String, LocateModuleError),
31
32 #[error("Module is not a dynamic library")]
33 NotDynamicLibrary,
34
35 #[error("Module's memory is not shared")]
36 MemoryNotShared,
37
38 #[error("Failed to parse dylink.0 section: {0}")]
39 Dylink0SectionParseError(#[from] wasmparser::BinaryReaderError),
40
41 #[error("Unresolved global '{0}'.{1} due to: {2}")]
42 UnresolvedGlobal(String, String, Box<ResolveError>),
43
44 #[error("Failed to update global {0} due to: {1}")]
45 GlobalUpdateFailed(String, RuntimeError),
46
47 #[error("Expected global to be of type I32 or I64: '{0}'.{1}")]
48 NonIntegerGlobal(String, String),
49
50 #[error("Bad known import: '{0}'.{1} of type {2:?}")]
51 BadImport(String, String, ExternType),
52
53 #[error(
54 "Import could not be satisfied because of type mismatch: '{0}'.{1}, expected {2:?}, found {3:?}"
55 )]
56 ImportTypeMismatch(String, String, ExternType, ExternType),
57
58 #[error("Expected import to be a function: '{0}'.{1}")]
59 ImportMustBeFunction(&'static str, String),
60
61 #[error("Expected export {0} to be a function, found: {1:?}")]
62 ExportMustBeFunction(String, ExternType),
63
64 #[error("Failed to initialize instance: {0}")]
65 InitializationError(anyhow::Error),
66
67 #[error("Initialization function has invalid signature: {0}")]
68 InitFuncWithInvalidSignature(String),
69
70 #[error("Initialization function {0} failed to run: {1}")]
71 InitFunctionFailed(String, RuntimeError),
72
73 #[error("Failed to initialize WASI(X) module handles: {0}")]
74 MainModuleHandleInitFailed(ExportError),
75
76 #[error("Bad __tls_base export, expected a global of type I32 or I64")]
77 BadTlsBaseExport,
78
79 #[error(
80 "TLS symbol {0} cannot be resolved from module {1} because it does not export its __tls_base"
81 )]
82 MissingTlsBaseExport(String, ModuleHandle),
83}
84
85#[derive(Debug)]
86pub enum LocateModuleError {
87 Single(FsError),
88 Multiple(Vec<(PathBuf, FsError)>),
89}
90
91impl std::fmt::Display for LocateModuleError {
92 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
93 match self {
94 LocateModuleError::Single(e) => std::fmt::Display::fmt(&e, f),
95 LocateModuleError::Multiple(errors) => {
96 for (path, error) in errors {
97 write!(f, "\n {}: {}", path.display(), error)?;
98 }
99 Ok(())
100 }
101 }
102 }
103}
104
105#[derive(thiserror::Error, Debug)]
106pub enum ResolveError {
107 #[error("Linker not initialized")]
108 NotInitialized,
109
110 #[error("Invalid module handle")]
111 InvalidModuleHandle,
112
113 #[error("Missing export")]
114 MissingExport,
115
116 #[error("Invalid export type: {0:?}")]
117 InvalidExportType(ExternType),
118
119 #[error("Failed to allocate function table indices: {0}")]
120 TableAllocationError(RuntimeError),
121
122 #[error("Cannot access linker through a dead instance group")]
123 InstanceGroupIsDead,
124
125 #[error("Failed to perform pending DL operation: {0}")]
126 PendingDlOperationFailed(#[from] LinkError),
127
128 #[error("Module must export its __tls_base for exported TLS symbols to be resolved correctly")]
129 NoTlsBaseGlobalExport,
130}