/__w/smoldot/smoldot/repo/lib/src/executor/vm.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Smoldot |
2 | | // Copyright (C) 2019-2022 Parity Technologies (UK) Ltd. |
3 | | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 |
4 | | |
5 | | // This program is free software: you can redistribute it and/or modify |
6 | | // it under the terms of the GNU General Public License as published by |
7 | | // the Free Software Foundation, either version 3 of the License, or |
8 | | // (at your option) any later version. |
9 | | |
10 | | // This program is distributed in the hope that it will be useful, |
11 | | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | // GNU General Public License for more details. |
14 | | |
15 | | // You should have received a copy of the GNU General Public License |
16 | | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | | |
18 | | //! General-purpose WebAssembly virtual machine. |
19 | | //! |
20 | | //! Contains code related to running a WebAssembly virtual machine. Contrary to |
21 | | //! (`HostVm`)[`super::host::HostVm`], this module isn't aware of any of the host |
22 | | //! functions available to Substrate runtimes. It only contains the code required to run a virtual |
23 | | //! machine, with some adjustments explained below. |
24 | | //! |
25 | | //! # Usage |
26 | | //! |
27 | | //! Call [`VirtualMachinePrototype::new`] in order to parse and/or compile some WebAssembly code. |
28 | | //! One of the parameters of this function is a function that is passed the name of functions |
29 | | //! imported by the Wasm code, and must return an opaque `usize`. This `usize` doesn't have any |
30 | | //! meaning, but will later be passed back to the user through [`ExecOutcome::Interrupted::id`] |
31 | | //! when the corresponding function is called. |
32 | | //! |
33 | | //! Use [`VirtualMachinePrototype::prepare`] then [`Prepare::start`] in order to start executing |
34 | | //! a function exported through an `(export)` statement. |
35 | | //! |
36 | | //! Call [`VirtualMachine::run`] on the [`VirtualMachine`] returned by `start` in order to run the |
37 | | //! WebAssembly code. The `run` method returns either if the function being called returns, or if |
38 | | //! the WebAssembly code calls a host function. In the latter case, [`ExecOutcome::Interrupted`] |
39 | | //! is returned and the virtual machine is now paused. Once the logic of the host function has |
40 | | //! been executed, call `run` again, passing the return value of that host function. |
41 | | //! |
42 | | //! # About imported vs exported memory |
43 | | //! |
44 | | //! WebAssembly supports, in theory, addressing multiple different memory objects. The WebAssembly |
45 | | //! module can declare memory in two ways: |
46 | | //! |
47 | | //! - Either by exporting a memory object in the `(export)` section under the name `memory`. |
48 | | //! - Or by importing a memory object in its `(import)` section. |
49 | | //! |
50 | | //! The virtual machine in this module supports both variants. However, no more than one memory |
51 | | //! object can be exported or imported, and it is illegal to not use any memory. |
52 | | //! |
53 | | //! The first variant used to be the default model when compiling to WebAssembly, but the second |
54 | | //! variant (importing memory objects) is preferred nowadays. |
55 | | //! |
56 | | //! # Wasm features |
57 | | //! |
58 | | //! The WebAssembly specification is a moving one. The specification as it was when it launched |
59 | | //! in 2017 is commonly referred to as "the MVP" (minimum viable product). Since then, various |
60 | | //! extensions have been added to the WebAssembly format. |
61 | | //! |
62 | | //! The code in this module, however, doesn't allow any of the feature that were added post-MVP. |
63 | | //! Trying to use WebAssembly code that uses one of these features will result in an error. |
64 | | //! |
65 | | |
66 | | mod interpreter; |
67 | | |
68 | | // This list of targets matches the one in the `Cargo.toml` file. |
69 | | #[cfg(all( |
70 | | any( |
71 | | all( |
72 | | target_arch = "x86_64", |
73 | | any( |
74 | | target_os = "windows", |
75 | | all(target_os = "linux", target_env = "gnu"), |
76 | | target_os = "macos" |
77 | | ) |
78 | | ), |
79 | | all(target_arch = "aarch64", target_os = "linux", target_env = "gnu"), |
80 | | all(target_arch = "s390x", target_os = "linux", target_env = "gnu") |
81 | | ), |
82 | | feature = "wasmtime" |
83 | | ))] |
84 | | mod jit; |
85 | | |
86 | | mod tests; |
87 | | |
88 | | use alloc::{string::String, vec::Vec}; |
89 | | use core::{fmt, iter}; |
90 | | use smallvec::SmallVec; |
91 | | |
92 | | /// Configuration to pass to [`VirtualMachinePrototype::new`]. |
93 | | pub struct Config<'a> { |
94 | | /// Encoded wasm bytecode. |
95 | | pub module_bytes: &'a [u8], |
96 | | |
97 | | /// Hint about how to execute the WebAssembly code. |
98 | | pub exec_hint: ExecHint, |
99 | | |
100 | | /// Called for each import that the module has. It must assign a number to each import, or |
101 | | /// return an error if the import can't be resolved. When the VM calls one of these functions, |
102 | | /// this number will be returned back in order for the user to know how to handle the call. |
103 | | pub symbols: &'a mut dyn FnMut(&str, &str, &Signature) -> Result<usize, ()>, |
104 | | } |
105 | | |
106 | | /// Virtual machine ready to start executing a function. |
107 | | /// |
108 | | /// > **Note**: This struct implements `Clone`. Cloning a [`VirtualMachinePrototype`] allocates |
109 | | /// > memory necessary for the clone to run. |
110 | | #[derive(Clone)] |
111 | | pub struct VirtualMachinePrototype { |
112 | | inner: VirtualMachinePrototypeInner, |
113 | | } |
114 | | |
115 | | #[derive(Clone)] |
116 | | enum VirtualMachinePrototypeInner { |
117 | | #[cfg(all( |
118 | | any( |
119 | | all( |
120 | | target_arch = "x86_64", |
121 | | any( |
122 | | target_os = "windows", |
123 | | all(target_os = "linux", target_env = "gnu"), |
124 | | target_os = "macos" |
125 | | ) |
126 | | ), |
127 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
128 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
129 | | ), |
130 | | feature = "wasmtime" |
131 | | ))] |
132 | | Jit(jit::JitPrototype), |
133 | | Interpreter(interpreter::InterpreterPrototype), |
134 | | } |
135 | | |
136 | | impl VirtualMachinePrototype { |
137 | | /// Creates a new process state machine from the given module. This method notably allocates |
138 | | /// the memory necessary for the virtual machine to run. |
139 | | /// |
140 | | /// |
141 | | /// See [the module-level documentation](..) for an explanation of the parameters. |
142 | 233 | pub fn new(config: Config) -> Result<Self, NewErr> { |
143 | 233 | Ok(VirtualMachinePrototype { |
144 | 233 | inner: match config.exec_hint { |
145 | | #[cfg(all( |
146 | | any( |
147 | | all( |
148 | | target_arch = "x86_64", |
149 | | any( |
150 | | target_os = "windows", |
151 | | all(target_os = "linux", target_env = "gnu"), |
152 | | target_os = "macos" |
153 | | ) |
154 | | ), |
155 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
156 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
157 | | ), |
158 | | feature = "wasmtime" |
159 | | ))] |
160 | | ExecHint::ValidateAndCompile => VirtualMachinePrototypeInner::Jit( |
161 | 23 | jit::JitPrototype::new(config.module_bytes, config.symbols)?0 , |
162 | | ), |
163 | | #[cfg(not(all( |
164 | | any( |
165 | | all( |
166 | | target_arch = "x86_64", |
167 | | any( |
168 | | target_os = "windows", |
169 | | all(target_os = "linux", target_env = "gnu"), |
170 | | target_os = "macos" |
171 | | ) |
172 | | ), |
173 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
174 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
175 | | ), |
176 | | feature = "wasmtime" |
177 | | )))] |
178 | | ExecHint::ValidateAndCompile => VirtualMachinePrototypeInner::Interpreter( |
179 | | interpreter::InterpreterPrototype::new( |
180 | | config.module_bytes, |
181 | | interpreter::CompilationMode::Eager, |
182 | | config.symbols, |
183 | | )?, |
184 | | ), |
185 | | ExecHint::ValidateAndExecuteOnce | ExecHint::Untrusted => { |
186 | | VirtualMachinePrototypeInner::Interpreter( |
187 | 43 | interpreter::InterpreterPrototype::new( |
188 | 43 | config.module_bytes, |
189 | 43 | interpreter::CompilationMode::Eager, |
190 | 43 | config.symbols, |
191 | 43 | )?0 , |
192 | | ) |
193 | | } |
194 | | ExecHint::CompileWithNonDeterministicValidation |
195 | | | ExecHint::ExecuteOnceWithNonDeterministicValidation => { |
196 | | VirtualMachinePrototypeInner::Interpreter( |
197 | 26 | interpreter::InterpreterPrototype::new( |
198 | 26 | config.module_bytes, |
199 | 26 | interpreter::CompilationMode::Lazy, |
200 | 26 | config.symbols, |
201 | 26 | )?0 , |
202 | | ) |
203 | | } |
204 | 72 | ExecHint::ForceWasmi { lazy_validation } => { |
205 | 72 | VirtualMachinePrototypeInner::Interpreter( |
206 | 72 | interpreter::InterpreterPrototype::new( |
207 | 72 | config.module_bytes, |
208 | 72 | if lazy_validation { |
209 | 0 | interpreter::CompilationMode::Lazy |
210 | | } else { |
211 | 72 | interpreter::CompilationMode::Eager |
212 | | }, |
213 | 72 | config.symbols, |
214 | 25 | )?, |
215 | | ) |
216 | | } |
217 | | |
218 | | #[cfg(all( |
219 | | any( |
220 | | all( |
221 | | target_arch = "x86_64", |
222 | | any( |
223 | | target_os = "windows", |
224 | | all(target_os = "linux", target_env = "gnu"), |
225 | | target_os = "macos" |
226 | | ) |
227 | | ), |
228 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
229 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
230 | | ), |
231 | | feature = "wasmtime" |
232 | | ))] |
233 | | ExecHint::ForceWasmtime => VirtualMachinePrototypeInner::Jit( |
234 | 69 | jit::JitPrototype::new(config.module_bytes, config.symbols)?21 , |
235 | | ), |
236 | | }, |
237 | | }) |
238 | 233 | } _RNvMNtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB2_23VirtualMachinePrototype3new Line | Count | Source | 142 | 147 | pub fn new(config: Config) -> Result<Self, NewErr> { | 143 | 147 | Ok(VirtualMachinePrototype { | 144 | 147 | inner: match config.exec_hint { | 145 | | #[cfg(all( | 146 | | any( | 147 | | all( | 148 | | target_arch = "x86_64", | 149 | | any( | 150 | | target_os = "windows", | 151 | | all(target_os = "linux", target_env = "gnu"), | 152 | | target_os = "macos" | 153 | | ) | 154 | | ), | 155 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 156 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 157 | | ), | 158 | | feature = "wasmtime" | 159 | | ))] | 160 | | ExecHint::ValidateAndCompile => VirtualMachinePrototypeInner::Jit( | 161 | 0 | jit::JitPrototype::new(config.module_bytes, config.symbols)?, | 162 | | ), | 163 | | #[cfg(not(all( | 164 | | any( | 165 | | all( | 166 | | target_arch = "x86_64", | 167 | | any( | 168 | | target_os = "windows", | 169 | | all(target_os = "linux", target_env = "gnu"), | 170 | | target_os = "macos" | 171 | | ) | 172 | | ), | 173 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 174 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 175 | | ), | 176 | | feature = "wasmtime" | 177 | | )))] | 178 | | ExecHint::ValidateAndCompile => VirtualMachinePrototypeInner::Interpreter( | 179 | | interpreter::InterpreterPrototype::new( | 180 | | config.module_bytes, | 181 | | interpreter::CompilationMode::Eager, | 182 | | config.symbols, | 183 | | )?, | 184 | | ), | 185 | | ExecHint::ValidateAndExecuteOnce | ExecHint::Untrusted => { | 186 | | VirtualMachinePrototypeInner::Interpreter( | 187 | 1 | interpreter::InterpreterPrototype::new( | 188 | 1 | config.module_bytes, | 189 | 1 | interpreter::CompilationMode::Eager, | 190 | 1 | config.symbols, | 191 | 1 | )?0 , | 192 | | ) | 193 | | } | 194 | | ExecHint::CompileWithNonDeterministicValidation | 195 | | | ExecHint::ExecuteOnceWithNonDeterministicValidation => { | 196 | | VirtualMachinePrototypeInner::Interpreter( | 197 | 5 | interpreter::InterpreterPrototype::new( | 198 | 5 | config.module_bytes, | 199 | 5 | interpreter::CompilationMode::Lazy, | 200 | 5 | config.symbols, | 201 | 5 | )?0 , | 202 | | ) | 203 | | } | 204 | 72 | ExecHint::ForceWasmi { lazy_validation } => { | 205 | 72 | VirtualMachinePrototypeInner::Interpreter( | 206 | 72 | interpreter::InterpreterPrototype::new( | 207 | 72 | config.module_bytes, | 208 | 72 | if lazy_validation { | 209 | 0 | interpreter::CompilationMode::Lazy | 210 | | } else { | 211 | 72 | interpreter::CompilationMode::Eager | 212 | | }, | 213 | 72 | config.symbols, | 214 | 25 | )?, | 215 | | ) | 216 | | } | 217 | | | 218 | | #[cfg(all( | 219 | | any( | 220 | | all( | 221 | | target_arch = "x86_64", | 222 | | any( | 223 | | target_os = "windows", | 224 | | all(target_os = "linux", target_env = "gnu"), | 225 | | target_os = "macos" | 226 | | ) | 227 | | ), | 228 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 229 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 230 | | ), | 231 | | feature = "wasmtime" | 232 | | ))] | 233 | | ExecHint::ForceWasmtime => VirtualMachinePrototypeInner::Jit( | 234 | 69 | jit::JitPrototype::new(config.module_bytes, config.symbols)?21 , | 235 | | ), | 236 | | }, | 237 | | }) | 238 | 147 | } |
_RNvMNtNtCseuYC0Zibziv_7smoldot8executor2vmNtB2_23VirtualMachinePrototype3new Line | Count | Source | 142 | 86 | pub fn new(config: Config) -> Result<Self, NewErr> { | 143 | 86 | Ok(VirtualMachinePrototype { | 144 | 86 | inner: match config.exec_hint { | 145 | | #[cfg(all( | 146 | | any( | 147 | | all( | 148 | | target_arch = "x86_64", | 149 | | any( | 150 | | target_os = "windows", | 151 | | all(target_os = "linux", target_env = "gnu"), | 152 | | target_os = "macos" | 153 | | ) | 154 | | ), | 155 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 156 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 157 | | ), | 158 | | feature = "wasmtime" | 159 | | ))] | 160 | | ExecHint::ValidateAndCompile => VirtualMachinePrototypeInner::Jit( | 161 | 23 | jit::JitPrototype::new(config.module_bytes, config.symbols)?0 , | 162 | | ), | 163 | | #[cfg(not(all( | 164 | | any( | 165 | | all( | 166 | | target_arch = "x86_64", | 167 | | any( | 168 | | target_os = "windows", | 169 | | all(target_os = "linux", target_env = "gnu"), | 170 | | target_os = "macos" | 171 | | ) | 172 | | ), | 173 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 174 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 175 | | ), | 176 | | feature = "wasmtime" | 177 | | )))] | 178 | | ExecHint::ValidateAndCompile => VirtualMachinePrototypeInner::Interpreter( | 179 | | interpreter::InterpreterPrototype::new( | 180 | | config.module_bytes, | 181 | | interpreter::CompilationMode::Eager, | 182 | | config.symbols, | 183 | | )?, | 184 | | ), | 185 | | ExecHint::ValidateAndExecuteOnce | ExecHint::Untrusted => { | 186 | | VirtualMachinePrototypeInner::Interpreter( | 187 | 42 | interpreter::InterpreterPrototype::new( | 188 | 42 | config.module_bytes, | 189 | 42 | interpreter::CompilationMode::Eager, | 190 | 42 | config.symbols, | 191 | 42 | )?0 , | 192 | | ) | 193 | | } | 194 | | ExecHint::CompileWithNonDeterministicValidation | 195 | | | ExecHint::ExecuteOnceWithNonDeterministicValidation => { | 196 | | VirtualMachinePrototypeInner::Interpreter( | 197 | 21 | interpreter::InterpreterPrototype::new( | 198 | 21 | config.module_bytes, | 199 | 21 | interpreter::CompilationMode::Lazy, | 200 | 21 | config.symbols, | 201 | 21 | )?0 , | 202 | | ) | 203 | | } | 204 | 0 | ExecHint::ForceWasmi { lazy_validation } => { | 205 | 0 | VirtualMachinePrototypeInner::Interpreter( | 206 | 0 | interpreter::InterpreterPrototype::new( | 207 | 0 | config.module_bytes, | 208 | 0 | if lazy_validation { | 209 | 0 | interpreter::CompilationMode::Lazy | 210 | | } else { | 211 | 0 | interpreter::CompilationMode::Eager | 212 | | }, | 213 | 0 | config.symbols, | 214 | 0 | )?, | 215 | | ) | 216 | | } | 217 | | | 218 | | #[cfg(all( | 219 | | any( | 220 | | all( | 221 | | target_arch = "x86_64", | 222 | | any( | 223 | | target_os = "windows", | 224 | | all(target_os = "linux", target_env = "gnu"), | 225 | | target_os = "macos" | 226 | | ) | 227 | | ), | 228 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 229 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 230 | | ), | 231 | | feature = "wasmtime" | 232 | | ))] | 233 | | ExecHint::ForceWasmtime => VirtualMachinePrototypeInner::Jit( | 234 | 0 | jit::JitPrototype::new(config.module_bytes, config.symbols)?, | 235 | | ), | 236 | | }, | 237 | | }) | 238 | 86 | } |
|
239 | | |
240 | | /// Returns the value of a global that the module exports. |
241 | | /// |
242 | | /// The global variable must be a `i32`, otherwise an error is returned. Negative values are |
243 | | /// silently reinterpreted as an unsigned integer. |
244 | 154 | pub fn global_value(&mut self, name: &str) -> Result<u32, GlobalValueErr> { |
245 | 154 | match &mut self.inner { |
246 | | #[cfg(all( |
247 | | any( |
248 | | all( |
249 | | target_arch = "x86_64", |
250 | | any( |
251 | | target_os = "windows", |
252 | | all(target_os = "linux", target_env = "gnu"), |
253 | | target_os = "macos" |
254 | | ) |
255 | | ), |
256 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
257 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
258 | | ), |
259 | | feature = "wasmtime" |
260 | | ))] |
261 | 54 | VirtualMachinePrototypeInner::Jit(inner) => inner.global_value(name), |
262 | 100 | VirtualMachinePrototypeInner::Interpreter(inner) => inner.global_value(name), |
263 | | } |
264 | 154 | } _RNvMNtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB2_23VirtualMachinePrototype12global_value Line | Count | Source | 244 | 68 | pub fn global_value(&mut self, name: &str) -> Result<u32, GlobalValueErr> { | 245 | 68 | match &mut self.inner { | 246 | | #[cfg(all( | 247 | | any( | 248 | | all( | 249 | | target_arch = "x86_64", | 250 | | any( | 251 | | target_os = "windows", | 252 | | all(target_os = "linux", target_env = "gnu"), | 253 | | target_os = "macos" | 254 | | ) | 255 | | ), | 256 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 257 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 258 | | ), | 259 | | feature = "wasmtime" | 260 | | ))] | 261 | 31 | VirtualMachinePrototypeInner::Jit(inner) => inner.global_value(name), | 262 | 37 | VirtualMachinePrototypeInner::Interpreter(inner) => inner.global_value(name), | 263 | | } | 264 | 68 | } |
_RNvMNtNtCseuYC0Zibziv_7smoldot8executor2vmNtB2_23VirtualMachinePrototype12global_value Line | Count | Source | 244 | 86 | pub fn global_value(&mut self, name: &str) -> Result<u32, GlobalValueErr> { | 245 | 86 | match &mut self.inner { | 246 | | #[cfg(all( | 247 | | any( | 248 | | all( | 249 | | target_arch = "x86_64", | 250 | | any( | 251 | | target_os = "windows", | 252 | | all(target_os = "linux", target_env = "gnu"), | 253 | | target_os = "macos" | 254 | | ) | 255 | | ), | 256 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 257 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 258 | | ), | 259 | | feature = "wasmtime" | 260 | | ))] | 261 | 23 | VirtualMachinePrototypeInner::Jit(inner) => inner.global_value(name), | 262 | 63 | VirtualMachinePrototypeInner::Interpreter(inner) => inner.global_value(name), | 263 | | } | 264 | 86 | } |
|
265 | | |
266 | | /// Returns the maximum number of pages that the memory can have. |
267 | | /// |
268 | | /// `None` if there is no limit. |
269 | 144 | pub fn memory_max_pages(&self) -> Option<HeapPages> { |
270 | 144 | match &self.inner { |
271 | | #[cfg(all( |
272 | | any( |
273 | | all( |
274 | | target_arch = "x86_64", |
275 | | any( |
276 | | target_os = "windows", |
277 | | all(target_os = "linux", target_env = "gnu"), |
278 | | target_os = "macos" |
279 | | ) |
280 | | ), |
281 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
282 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
283 | | ), |
284 | | feature = "wasmtime" |
285 | | ))] |
286 | 49 | VirtualMachinePrototypeInner::Jit(inner) => inner.memory_max_pages(), |
287 | 95 | VirtualMachinePrototypeInner::Interpreter(inner) => inner.memory_max_pages(), |
288 | | } |
289 | 144 | } _RNvMNtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB2_23VirtualMachinePrototype16memory_max_pages Line | Count | Source | 269 | 58 | pub fn memory_max_pages(&self) -> Option<HeapPages> { | 270 | 58 | match &self.inner { | 271 | | #[cfg(all( | 272 | | any( | 273 | | all( | 274 | | target_arch = "x86_64", | 275 | | any( | 276 | | target_os = "windows", | 277 | | all(target_os = "linux", target_env = "gnu"), | 278 | | target_os = "macos" | 279 | | ) | 280 | | ), | 281 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 282 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 283 | | ), | 284 | | feature = "wasmtime" | 285 | | ))] | 286 | 26 | VirtualMachinePrototypeInner::Jit(inner) => inner.memory_max_pages(), | 287 | 32 | VirtualMachinePrototypeInner::Interpreter(inner) => inner.memory_max_pages(), | 288 | | } | 289 | 58 | } |
_RNvMNtNtCseuYC0Zibziv_7smoldot8executor2vmNtB2_23VirtualMachinePrototype16memory_max_pages Line | Count | Source | 269 | 86 | pub fn memory_max_pages(&self) -> Option<HeapPages> { | 270 | 86 | match &self.inner { | 271 | | #[cfg(all( | 272 | | any( | 273 | | all( | 274 | | target_arch = "x86_64", | 275 | | any( | 276 | | target_os = "windows", | 277 | | all(target_os = "linux", target_env = "gnu"), | 278 | | target_os = "macos" | 279 | | ) | 280 | | ), | 281 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 282 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 283 | | ), | 284 | | feature = "wasmtime" | 285 | | ))] | 286 | 23 | VirtualMachinePrototypeInner::Jit(inner) => inner.memory_max_pages(), | 287 | 63 | VirtualMachinePrototypeInner::Interpreter(inner) => inner.memory_max_pages(), | 288 | | } | 289 | 86 | } |
|
290 | | |
291 | | /// Prepares the prototype for running a function. |
292 | | /// |
293 | | /// This preliminary step is necessary as it allows reading and writing memory before starting |
294 | | /// the actual execution.. |
295 | 211 | pub fn prepare(self) -> Prepare { |
296 | 211 | match self.inner { |
297 | | #[cfg(all( |
298 | | any( |
299 | | all( |
300 | | target_arch = "x86_64", |
301 | | any( |
302 | | target_os = "windows", |
303 | | all(target_os = "linux", target_env = "gnu"), |
304 | | target_os = "macos" |
305 | | ) |
306 | | ), |
307 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
308 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
309 | | ), |
310 | | feature = "wasmtime" |
311 | | ))] |
312 | 37 | VirtualMachinePrototypeInner::Jit(inner) => Prepare { |
313 | 37 | inner: PrepareInner::Jit(inner.prepare()), |
314 | 37 | }, |
315 | 174 | VirtualMachinePrototypeInner::Interpreter(inner) => Prepare { |
316 | 174 | inner: PrepareInner::Interpreter(inner.prepare()), |
317 | 174 | }, |
318 | | } |
319 | 211 | } _RNvMNtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB2_23VirtualMachinePrototype7prepare Line | Count | Source | 295 | 84 | pub fn prepare(self) -> Prepare { | 296 | 84 | match self.inner { | 297 | | #[cfg(all( | 298 | | any( | 299 | | all( | 300 | | target_arch = "x86_64", | 301 | | any( | 302 | | target_os = "windows", | 303 | | all(target_os = "linux", target_env = "gnu"), | 304 | | target_os = "macos" | 305 | | ) | 306 | | ), | 307 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 308 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 309 | | ), | 310 | | feature = "wasmtime" | 311 | | ))] | 312 | 36 | VirtualMachinePrototypeInner::Jit(inner) => Prepare { | 313 | 36 | inner: PrepareInner::Jit(inner.prepare()), | 314 | 36 | }, | 315 | 48 | VirtualMachinePrototypeInner::Interpreter(inner) => Prepare { | 316 | 48 | inner: PrepareInner::Interpreter(inner.prepare()), | 317 | 48 | }, | 318 | | } | 319 | 84 | } |
_RNvMNtNtCseuYC0Zibziv_7smoldot8executor2vmNtB2_23VirtualMachinePrototype7prepare Line | Count | Source | 295 | 127 | pub fn prepare(self) -> Prepare { | 296 | 127 | match self.inner { | 297 | | #[cfg(all( | 298 | | any( | 299 | | all( | 300 | | target_arch = "x86_64", | 301 | | any( | 302 | | target_os = "windows", | 303 | | all(target_os = "linux", target_env = "gnu"), | 304 | | target_os = "macos" | 305 | | ) | 306 | | ), | 307 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 308 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 309 | | ), | 310 | | feature = "wasmtime" | 311 | | ))] | 312 | 1 | VirtualMachinePrototypeInner::Jit(inner) => Prepare { | 313 | 1 | inner: PrepareInner::Jit(inner.prepare()), | 314 | 1 | }, | 315 | 126 | VirtualMachinePrototypeInner::Interpreter(inner) => Prepare { | 316 | 126 | inner: PrepareInner::Interpreter(inner.prepare()), | 317 | 126 | }, | 318 | | } | 319 | 127 | } |
|
320 | | } |
321 | | |
322 | | impl fmt::Debug for VirtualMachinePrototype { |
323 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
324 | 0 | match &self.inner { |
325 | | #[cfg(all( |
326 | | any( |
327 | | all( |
328 | | target_arch = "x86_64", |
329 | | any( |
330 | | target_os = "windows", |
331 | | all(target_os = "linux", target_env = "gnu"), |
332 | | target_os = "macos" |
333 | | ) |
334 | | ), |
335 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
336 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
337 | | ), |
338 | | feature = "wasmtime" |
339 | | ))] |
340 | 0 | VirtualMachinePrototypeInner::Jit(inner) => fmt::Debug::fmt(inner, f), |
341 | 0 | VirtualMachinePrototypeInner::Interpreter(inner) => fmt::Debug::fmt(inner, f), |
342 | | } |
343 | 0 | } Unexecuted instantiation: _RNvXs_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB4_23VirtualMachinePrototypeNtNtCsaYZPK01V26L_4core3fmt5Debug3fmt Unexecuted instantiation: _RNvXs_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB4_23VirtualMachinePrototypeNtNtCsaYZPK01V26L_4core3fmt5Debug3fmt |
344 | | } |
345 | | |
346 | | pub struct Prepare { |
347 | | inner: PrepareInner, |
348 | | } |
349 | | |
350 | | enum PrepareInner { |
351 | | #[cfg(all( |
352 | | any( |
353 | | all( |
354 | | target_arch = "x86_64", |
355 | | any( |
356 | | target_os = "windows", |
357 | | all(target_os = "linux", target_env = "gnu"), |
358 | | target_os = "macos" |
359 | | ) |
360 | | ), |
361 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
362 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
363 | | ), |
364 | | feature = "wasmtime" |
365 | | ))] |
366 | | Jit(jit::Prepare), |
367 | | Interpreter(interpreter::Prepare), |
368 | | } |
369 | | |
370 | | impl Prepare { |
371 | | /// Turns back this virtual machine into a prototype. |
372 | 2 | pub fn into_prototype(self) -> VirtualMachinePrototype { |
373 | 2 | VirtualMachinePrototype { |
374 | 2 | inner: match self.inner { |
375 | | #[cfg(all( |
376 | | any( |
377 | | all( |
378 | | target_arch = "x86_64", |
379 | | any( |
380 | | target_os = "windows", |
381 | | all(target_os = "linux", target_env = "gnu"), |
382 | | target_os = "macos" |
383 | | ) |
384 | | ), |
385 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
386 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
387 | | ), |
388 | | feature = "wasmtime" |
389 | | ))] |
390 | 1 | PrepareInner::Jit(inner) => { |
391 | 1 | VirtualMachinePrototypeInner::Jit(inner.into_prototype()) |
392 | | } |
393 | 1 | PrepareInner::Interpreter(inner) => { |
394 | 1 | VirtualMachinePrototypeInner::Interpreter(inner.into_prototype()) |
395 | | } |
396 | | }, |
397 | | } |
398 | 2 | } _RNvMs0_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_7Prepare14into_prototype Line | Count | Source | 372 | 2 | pub fn into_prototype(self) -> VirtualMachinePrototype { | 373 | 2 | VirtualMachinePrototype { | 374 | 2 | inner: match self.inner { | 375 | | #[cfg(all( | 376 | | any( | 377 | | all( | 378 | | target_arch = "x86_64", | 379 | | any( | 380 | | target_os = "windows", | 381 | | all(target_os = "linux", target_env = "gnu"), | 382 | | target_os = "macos" | 383 | | ) | 384 | | ), | 385 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 386 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 387 | | ), | 388 | | feature = "wasmtime" | 389 | | ))] | 390 | 1 | PrepareInner::Jit(inner) => { | 391 | 1 | VirtualMachinePrototypeInner::Jit(inner.into_prototype()) | 392 | | } | 393 | 1 | PrepareInner::Interpreter(inner) => { | 394 | 1 | VirtualMachinePrototypeInner::Interpreter(inner.into_prototype()) | 395 | | } | 396 | | }, | 397 | | } | 398 | 2 | } |
Unexecuted instantiation: _RNvMs0_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_7Prepare14into_prototype |
399 | | |
400 | | /// Returns the size of the memory, in bytes. |
401 | 358 | pub fn memory_size(&self) -> HeapPages { |
402 | 358 | match &self.inner { |
403 | | #[cfg(all( |
404 | | any( |
405 | | all( |
406 | | target_arch = "x86_64", |
407 | | any( |
408 | | target_os = "windows", |
409 | | all(target_os = "linux", target_env = "gnu"), |
410 | | target_os = "macos" |
411 | | ) |
412 | | ), |
413 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
414 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
415 | | ), |
416 | | feature = "wasmtime" |
417 | | ))] |
418 | 42 | PrepareInner::Jit(inner) => inner.memory_size(), |
419 | 316 | PrepareInner::Interpreter(inner) => inner.memory_size(), |
420 | | } |
421 | 358 | } _RNvMs0_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_7Prepare11memory_size Line | Count | Source | 401 | 104 | pub fn memory_size(&self) -> HeapPages { | 402 | 104 | match &self.inner { | 403 | | #[cfg(all( | 404 | | any( | 405 | | all( | 406 | | target_arch = "x86_64", | 407 | | any( | 408 | | target_os = "windows", | 409 | | all(target_os = "linux", target_env = "gnu"), | 410 | | target_os = "macos" | 411 | | ) | 412 | | ), | 413 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 414 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 415 | | ), | 416 | | feature = "wasmtime" | 417 | | ))] | 418 | 40 | PrepareInner::Jit(inner) => inner.memory_size(), | 419 | 64 | PrepareInner::Interpreter(inner) => inner.memory_size(), | 420 | | } | 421 | 104 | } |
_RNvMs0_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_7Prepare11memory_size Line | Count | Source | 401 | 254 | pub fn memory_size(&self) -> HeapPages { | 402 | 254 | match &self.inner { | 403 | | #[cfg(all( | 404 | | any( | 405 | | all( | 406 | | target_arch = "x86_64", | 407 | | any( | 408 | | target_os = "windows", | 409 | | all(target_os = "linux", target_env = "gnu"), | 410 | | target_os = "macos" | 411 | | ) | 412 | | ), | 413 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 414 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 415 | | ), | 416 | | feature = "wasmtime" | 417 | | ))] | 418 | 2 | PrepareInner::Jit(inner) => inner.memory_size(), | 419 | 252 | PrepareInner::Interpreter(inner) => inner.memory_size(), | 420 | | } | 421 | 254 | } |
|
422 | | |
423 | | /// Copies the given memory range into a `Vec<u8>`. |
424 | | /// |
425 | | /// Returns an error if the range is invalid or out of range. |
426 | 8 | pub fn read_memory( |
427 | 8 | &'_ self, |
428 | 8 | offset: u32, |
429 | 8 | size: u32, |
430 | 8 | ) -> Result<impl AsRef<[u8]> + '_, OutOfBoundsError> { |
431 | 8 | Ok(match &self.inner { |
432 | | #[cfg(all( |
433 | | any( |
434 | | all( |
435 | | target_arch = "x86_64", |
436 | | any( |
437 | | target_os = "windows", |
438 | | all(target_os = "linux", target_env = "gnu"), |
439 | | target_os = "macos" |
440 | | ) |
441 | | ), |
442 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
443 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
444 | | ), |
445 | | feature = "wasmtime" |
446 | | ))] |
447 | 4 | PrepareInner::Jit(inner) => either::Left(inner.read_memory(offset, size)?0 ), |
448 | | #[cfg(all( |
449 | | any( |
450 | | all( |
451 | | target_arch = "x86_64", |
452 | | any( |
453 | | target_os = "windows", |
454 | | all(target_os = "linux", target_env = "gnu"), |
455 | | target_os = "macos" |
456 | | ) |
457 | | ), |
458 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
459 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
460 | | ), |
461 | | feature = "wasmtime" |
462 | | ))] |
463 | 4 | PrepareInner::Interpreter(inner) => either::Right(inner.read_memory(offset, size)?0 ), |
464 | | #[cfg(not(all( |
465 | | any( |
466 | | all( |
467 | | target_arch = "x86_64", |
468 | | any( |
469 | | target_os = "windows", |
470 | | all(target_os = "linux", target_env = "gnu"), |
471 | | target_os = "macos" |
472 | | ) |
473 | | ), |
474 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
475 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
476 | | ), |
477 | | feature = "wasmtime" |
478 | | )))] |
479 | | PrepareInner::Interpreter(inner) => inner.read_memory(offset, size)?, |
480 | | }) |
481 | 8 | } _RNvMs0_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_7Prepare11read_memory Line | Count | Source | 426 | 8 | pub fn read_memory( | 427 | 8 | &'_ self, | 428 | 8 | offset: u32, | 429 | 8 | size: u32, | 430 | 8 | ) -> Result<impl AsRef<[u8]> + '_, OutOfBoundsError> { | 431 | 8 | Ok(match &self.inner { | 432 | | #[cfg(all( | 433 | | any( | 434 | | all( | 435 | | target_arch = "x86_64", | 436 | | any( | 437 | | target_os = "windows", | 438 | | all(target_os = "linux", target_env = "gnu"), | 439 | | target_os = "macos" | 440 | | ) | 441 | | ), | 442 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 443 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 444 | | ), | 445 | | feature = "wasmtime" | 446 | | ))] | 447 | 4 | PrepareInner::Jit(inner) => either::Left(inner.read_memory(offset, size)?0 ), | 448 | | #[cfg(all( | 449 | | any( | 450 | | all( | 451 | | target_arch = "x86_64", | 452 | | any( | 453 | | target_os = "windows", | 454 | | all(target_os = "linux", target_env = "gnu"), | 455 | | target_os = "macos" | 456 | | ) | 457 | | ), | 458 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 459 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 460 | | ), | 461 | | feature = "wasmtime" | 462 | | ))] | 463 | 4 | PrepareInner::Interpreter(inner) => either::Right(inner.read_memory(offset, size)?0 ), | 464 | | #[cfg(not(all( | 465 | | any( | 466 | | all( | 467 | | target_arch = "x86_64", | 468 | | any( | 469 | | target_os = "windows", | 470 | | all(target_os = "linux", target_env = "gnu"), | 471 | | target_os = "macos" | 472 | | ) | 473 | | ), | 474 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 475 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 476 | | ), | 477 | | feature = "wasmtime" | 478 | | )))] | 479 | | PrepareInner::Interpreter(inner) => inner.read_memory(offset, size)?, | 480 | | }) | 481 | 8 | } |
Unexecuted instantiation: _RNvMs0_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_7Prepare11read_memory |
482 | | |
483 | | /// Write the data at the given memory location. |
484 | | /// |
485 | | /// Returns an error if the range is invalid or out of range. |
486 | 249 | pub fn write_memory(&mut self, offset: u32, value: &[u8]) -> Result<(), OutOfBoundsError> { |
487 | 249 | match &mut self.inner { |
488 | | #[cfg(all( |
489 | | any( |
490 | | all( |
491 | | target_arch = "x86_64", |
492 | | any( |
493 | | target_os = "windows", |
494 | | all(target_os = "linux", target_env = "gnu"), |
495 | | target_os = "macos" |
496 | | ) |
497 | | ), |
498 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
499 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
500 | | ), |
501 | | feature = "wasmtime" |
502 | | ))] |
503 | 40 | PrepareInner::Jit(inner) => inner.write_memory(offset, value), |
504 | 209 | PrepareInner::Interpreter(inner) => inner.write_memory(offset, value), |
505 | | } |
506 | 249 | } _RNvMs0_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_7Prepare12write_memory Line | Count | Source | 486 | 122 | pub fn write_memory(&mut self, offset: u32, value: &[u8]) -> Result<(), OutOfBoundsError> { | 487 | 122 | match &mut self.inner { | 488 | | #[cfg(all( | 489 | | any( | 490 | | all( | 491 | | target_arch = "x86_64", | 492 | | any( | 493 | | target_os = "windows", | 494 | | all(target_os = "linux", target_env = "gnu"), | 495 | | target_os = "macos" | 496 | | ) | 497 | | ), | 498 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 499 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 500 | | ), | 501 | | feature = "wasmtime" | 502 | | ))] | 503 | 39 | PrepareInner::Jit(inner) => inner.write_memory(offset, value), | 504 | 83 | PrepareInner::Interpreter(inner) => inner.write_memory(offset, value), | 505 | | } | 506 | 122 | } |
_RNvMs0_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_7Prepare12write_memory Line | Count | Source | 486 | 127 | pub fn write_memory(&mut self, offset: u32, value: &[u8]) -> Result<(), OutOfBoundsError> { | 487 | 127 | match &mut self.inner { | 488 | | #[cfg(all( | 489 | | any( | 490 | | all( | 491 | | target_arch = "x86_64", | 492 | | any( | 493 | | target_os = "windows", | 494 | | all(target_os = "linux", target_env = "gnu"), | 495 | | target_os = "macos" | 496 | | ) | 497 | | ), | 498 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 499 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 500 | | ), | 501 | | feature = "wasmtime" | 502 | | ))] | 503 | 1 | PrepareInner::Jit(inner) => inner.write_memory(offset, value), | 504 | 126 | PrepareInner::Interpreter(inner) => inner.write_memory(offset, value), | 505 | | } | 506 | 127 | } |
|
507 | | |
508 | | /// Increases the size of the memory by the given number of pages. |
509 | | /// |
510 | | /// Returns an error if the size of the memory can't be expanded more. This can be known ahead |
511 | | /// of time by using [`VirtualMachinePrototype::memory_max_pages`]. |
512 | 193 | pub fn grow_memory(&mut self, additional: HeapPages) -> Result<(), OutOfBoundsError> { |
513 | 193 | match &mut self.inner { |
514 | | #[cfg(all( |
515 | | any( |
516 | | all( |
517 | | target_arch = "x86_64", |
518 | | any( |
519 | | target_os = "windows", |
520 | | all(target_os = "linux", target_env = "gnu"), |
521 | | target_os = "macos" |
522 | | ) |
523 | | ), |
524 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
525 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
526 | | ), |
527 | | feature = "wasmtime" |
528 | | ))] |
529 | 28 | PrepareInner::Jit(inner) => inner.grow_memory(additional), |
530 | 165 | PrepareInner::Interpreter(inner) => inner.grow_memory(additional), |
531 | | } |
532 | 193 | } _RNvMs0_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_7Prepare11grow_memory Line | Count | Source | 512 | 66 | pub fn grow_memory(&mut self, additional: HeapPages) -> Result<(), OutOfBoundsError> { | 513 | 66 | match &mut self.inner { | 514 | | #[cfg(all( | 515 | | any( | 516 | | all( | 517 | | target_arch = "x86_64", | 518 | | any( | 519 | | target_os = "windows", | 520 | | all(target_os = "linux", target_env = "gnu"), | 521 | | target_os = "macos" | 522 | | ) | 523 | | ), | 524 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 525 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 526 | | ), | 527 | | feature = "wasmtime" | 528 | | ))] | 529 | 27 | PrepareInner::Jit(inner) => inner.grow_memory(additional), | 530 | 39 | PrepareInner::Interpreter(inner) => inner.grow_memory(additional), | 531 | | } | 532 | 66 | } |
_RNvMs0_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_7Prepare11grow_memory Line | Count | Source | 512 | 127 | pub fn grow_memory(&mut self, additional: HeapPages) -> Result<(), OutOfBoundsError> { | 513 | 127 | match &mut self.inner { | 514 | | #[cfg(all( | 515 | | any( | 516 | | all( | 517 | | target_arch = "x86_64", | 518 | | any( | 519 | | target_os = "windows", | 520 | | all(target_os = "linux", target_env = "gnu"), | 521 | | target_os = "macos" | 522 | | ) | 523 | | ), | 524 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 525 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 526 | | ), | 527 | | feature = "wasmtime" | 528 | | ))] | 529 | 1 | PrepareInner::Jit(inner) => inner.grow_memory(additional), | 530 | 126 | PrepareInner::Interpreter(inner) => inner.grow_memory(additional), | 531 | | } | 532 | 127 | } |
|
533 | | |
534 | | /// Turns this prototype into an actual virtual machine. This requires choosing which function |
535 | | /// to execute. |
536 | 207 | pub fn start( |
537 | 207 | self, |
538 | 207 | function_name: &str, |
539 | 207 | params: &[WasmValue], |
540 | 207 | ) -> Result<VirtualMachine, (StartErr, VirtualMachinePrototype)> { |
541 | 207 | Ok(VirtualMachine { |
542 | 207 | inner: match self.inner { |
543 | | #[cfg(all( |
544 | | any( |
545 | | all( |
546 | | target_arch = "x86_64", |
547 | | any( |
548 | | target_os = "windows", |
549 | | all(target_os = "linux", target_env = "gnu"), |
550 | | target_os = "macos" |
551 | | ) |
552 | | ), |
553 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
554 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
555 | | ), |
556 | | feature = "wasmtime" |
557 | | ))] |
558 | 35 | PrepareInner::Jit(inner) => match inner.start(function_name, params) { |
559 | 29 | Ok(vm) => VirtualMachineInner::Jit(vm), |
560 | 6 | Err((err, proto)) => { |
561 | 6 | return Err(( |
562 | 6 | err, |
563 | 6 | VirtualMachinePrototype { |
564 | 6 | inner: VirtualMachinePrototypeInner::Jit(proto), |
565 | 6 | }, |
566 | 6 | )); |
567 | | } |
568 | | }, |
569 | 172 | PrepareInner::Interpreter(inner) => match inner.start(function_name, params) { |
570 | 166 | Ok(vm) => VirtualMachineInner::Interpreter(vm), |
571 | 6 | Err((err, proto)) => { |
572 | 6 | return Err(( |
573 | 6 | err, |
574 | 6 | VirtualMachinePrototype { |
575 | 6 | inner: VirtualMachinePrototypeInner::Interpreter(proto), |
576 | 6 | }, |
577 | 6 | )); |
578 | | } |
579 | | }, |
580 | | }, |
581 | | }) |
582 | 207 | } _RNvMs0_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_7Prepare5start Line | Count | Source | 536 | 80 | pub fn start( | 537 | 80 | self, | 538 | 80 | function_name: &str, | 539 | 80 | params: &[WasmValue], | 540 | 80 | ) -> Result<VirtualMachine, (StartErr, VirtualMachinePrototype)> { | 541 | 80 | Ok(VirtualMachine { | 542 | 80 | inner: match self.inner { | 543 | | #[cfg(all( | 544 | | any( | 545 | | all( | 546 | | target_arch = "x86_64", | 547 | | any( | 548 | | target_os = "windows", | 549 | | all(target_os = "linux", target_env = "gnu"), | 550 | | target_os = "macos" | 551 | | ) | 552 | | ), | 553 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 554 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 555 | | ), | 556 | | feature = "wasmtime" | 557 | | ))] | 558 | 34 | PrepareInner::Jit(inner) => match inner.start(function_name, params) { | 559 | 28 | Ok(vm) => VirtualMachineInner::Jit(vm), | 560 | 6 | Err((err, proto)) => { | 561 | 6 | return Err(( | 562 | 6 | err, | 563 | 6 | VirtualMachinePrototype { | 564 | 6 | inner: VirtualMachinePrototypeInner::Jit(proto), | 565 | 6 | }, | 566 | 6 | )); | 567 | | } | 568 | | }, | 569 | 46 | PrepareInner::Interpreter(inner) => match inner.start(function_name, params) { | 570 | 40 | Ok(vm) => VirtualMachineInner::Interpreter(vm), | 571 | 6 | Err((err, proto)) => { | 572 | 6 | return Err(( | 573 | 6 | err, | 574 | 6 | VirtualMachinePrototype { | 575 | 6 | inner: VirtualMachinePrototypeInner::Interpreter(proto), | 576 | 6 | }, | 577 | 6 | )); | 578 | | } | 579 | | }, | 580 | | }, | 581 | | }) | 582 | 80 | } |
_RNvMs0_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_7Prepare5start Line | Count | Source | 536 | 127 | pub fn start( | 537 | 127 | self, | 538 | 127 | function_name: &str, | 539 | 127 | params: &[WasmValue], | 540 | 127 | ) -> Result<VirtualMachine, (StartErr, VirtualMachinePrototype)> { | 541 | 127 | Ok(VirtualMachine { | 542 | 127 | inner: match self.inner { | 543 | | #[cfg(all( | 544 | | any( | 545 | | all( | 546 | | target_arch = "x86_64", | 547 | | any( | 548 | | target_os = "windows", | 549 | | all(target_os = "linux", target_env = "gnu"), | 550 | | target_os = "macos" | 551 | | ) | 552 | | ), | 553 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 554 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 555 | | ), | 556 | | feature = "wasmtime" | 557 | | ))] | 558 | 1 | PrepareInner::Jit(inner) => match inner.start(function_name, params) { | 559 | 1 | Ok(vm) => VirtualMachineInner::Jit(vm), | 560 | 0 | Err((err, proto)) => { | 561 | 0 | return Err(( | 562 | 0 | err, | 563 | 0 | VirtualMachinePrototype { | 564 | 0 | inner: VirtualMachinePrototypeInner::Jit(proto), | 565 | 0 | }, | 566 | 0 | )); | 567 | | } | 568 | | }, | 569 | 126 | PrepareInner::Interpreter(inner) => match inner.start(function_name, params) { | 570 | 126 | Ok(vm) => VirtualMachineInner::Interpreter(vm), | 571 | 0 | Err((err, proto)) => { | 572 | 0 | return Err(( | 573 | 0 | err, | 574 | 0 | VirtualMachinePrototype { | 575 | 0 | inner: VirtualMachinePrototypeInner::Interpreter(proto), | 576 | 0 | }, | 577 | 0 | )); | 578 | | } | 579 | | }, | 580 | | }, | 581 | | }) | 582 | 127 | } |
|
583 | | } |
584 | | |
585 | | impl fmt::Debug for Prepare { |
586 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
587 | 0 | match &self.inner { |
588 | | #[cfg(all( |
589 | | any( |
590 | | all( |
591 | | target_arch = "x86_64", |
592 | | any( |
593 | | target_os = "windows", |
594 | | all(target_os = "linux", target_env = "gnu"), |
595 | | target_os = "macos" |
596 | | ) |
597 | | ), |
598 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
599 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
600 | | ), |
601 | | feature = "wasmtime" |
602 | | ))] |
603 | 0 | PrepareInner::Jit(inner) => fmt::Debug::fmt(inner, f), |
604 | 0 | PrepareInner::Interpreter(inner) => fmt::Debug::fmt(inner, f), |
605 | | } |
606 | 0 | } Unexecuted instantiation: _RNvXs1_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_7PrepareNtNtCsaYZPK01V26L_4core3fmt5Debug3fmt Unexecuted instantiation: _RNvXs1_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_7PrepareNtNtCsaYZPK01V26L_4core3fmt5Debug3fmt |
607 | | } |
608 | | |
609 | | pub struct VirtualMachine { |
610 | | inner: VirtualMachineInner, |
611 | | } |
612 | | |
613 | | enum VirtualMachineInner { |
614 | | #[cfg(all( |
615 | | any( |
616 | | all( |
617 | | target_arch = "x86_64", |
618 | | any( |
619 | | target_os = "windows", |
620 | | all(target_os = "linux", target_env = "gnu"), |
621 | | target_os = "macos" |
622 | | ) |
623 | | ), |
624 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
625 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
626 | | ), |
627 | | feature = "wasmtime" |
628 | | ))] |
629 | | Jit(jit::Jit), |
630 | | Interpreter(interpreter::Interpreter), |
631 | | } |
632 | | |
633 | | impl VirtualMachine { |
634 | | /// Starts or continues execution of this thread. |
635 | | /// |
636 | | /// If this is the first call you call [`run`](VirtualMachine::run) for this thread, then you |
637 | | /// must pass a value of `None`. |
638 | | /// If, however, you call this function after a previous call to [`run`](VirtualMachine::run) |
639 | | /// that was interrupted by a host function call, then you must pass back the outcome of |
640 | | /// that call. |
641 | 34.4k | pub fn run(&mut self, value: Option<WasmValue>) -> Result<ExecOutcome, RunErr> { |
642 | 34.4k | match &mut self.inner { |
643 | | #[cfg(all( |
644 | | any( |
645 | | all( |
646 | | target_arch = "x86_64", |
647 | | any( |
648 | | target_os = "windows", |
649 | | all(target_os = "linux", target_env = "gnu"), |
650 | | target_os = "macos" |
651 | | ) |
652 | | ), |
653 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
654 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
655 | | ), |
656 | | feature = "wasmtime" |
657 | | ))] |
658 | 4.21k | VirtualMachineInner::Jit(inner) => inner.run(value), |
659 | 30.2k | VirtualMachineInner::Interpreter(inner) => inner.run(value), |
660 | | } |
661 | 34.4k | } _RNvMs2_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_14VirtualMachine3run Line | Count | Source | 641 | 29.2k | pub fn run(&mut self, value: Option<WasmValue>) -> Result<ExecOutcome, RunErr> { | 642 | 29.2k | match &mut self.inner { | 643 | | #[cfg(all( | 644 | | any( | 645 | | all( | 646 | | target_arch = "x86_64", | 647 | | any( | 648 | | target_os = "windows", | 649 | | all(target_os = "linux", target_env = "gnu"), | 650 | | target_os = "macos" | 651 | | ) | 652 | | ), | 653 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 654 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 655 | | ), | 656 | | feature = "wasmtime" | 657 | | ))] | 658 | 66 | VirtualMachineInner::Jit(inner) => inner.run(value), | 659 | 29.1k | VirtualMachineInner::Interpreter(inner) => inner.run(value), | 660 | | } | 661 | 29.2k | } |
_RNvMs2_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_14VirtualMachine3run Line | Count | Source | 641 | 5.20k | pub fn run(&mut self, value: Option<WasmValue>) -> Result<ExecOutcome, RunErr> { | 642 | 5.20k | match &mut self.inner { | 643 | | #[cfg(all( | 644 | | any( | 645 | | all( | 646 | | target_arch = "x86_64", | 647 | | any( | 648 | | target_os = "windows", | 649 | | all(target_os = "linux", target_env = "gnu"), | 650 | | target_os = "macos" | 651 | | ) | 652 | | ), | 653 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 654 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 655 | | ), | 656 | | feature = "wasmtime" | 657 | | ))] | 658 | 4.15k | VirtualMachineInner::Jit(inner) => inner.run(value), | 659 | 1.05k | VirtualMachineInner::Interpreter(inner) => inner.run(value), | 660 | | } | 661 | 5.20k | } |
|
662 | | |
663 | | /// Returns the size of the memory, in bytes. |
664 | | /// |
665 | | /// > **Note**: This can change over time if the Wasm code uses the `grow` opcode. |
666 | 82.2k | pub fn memory_size(&self) -> HeapPages { |
667 | 82.2k | match &self.inner { |
668 | | #[cfg(all( |
669 | | any( |
670 | | all( |
671 | | target_arch = "x86_64", |
672 | | any( |
673 | | target_os = "windows", |
674 | | all(target_os = "linux", target_env = "gnu"), |
675 | | target_os = "macos" |
676 | | ) |
677 | | ), |
678 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
679 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
680 | | ), |
681 | | feature = "wasmtime" |
682 | | ))] |
683 | 8.76k | VirtualMachineInner::Jit(inner) => inner.memory_size(), |
684 | 73.5k | VirtualMachineInner::Interpreter(inner) => inner.memory_size(), |
685 | | } |
686 | 82.2k | } _RNvMs2_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_14VirtualMachine11memory_size Line | Count | Source | 666 | 71.6k | pub fn memory_size(&self) -> HeapPages { | 667 | 71.6k | match &self.inner { | 668 | | #[cfg(all( | 669 | | any( | 670 | | all( | 671 | | target_arch = "x86_64", | 672 | | any( | 673 | | target_os = "windows", | 674 | | all(target_os = "linux", target_env = "gnu"), | 675 | | target_os = "macos" | 676 | | ) | 677 | | ), | 678 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 679 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 680 | | ), | 681 | | feature = "wasmtime" | 682 | | ))] | 683 | 95 | VirtualMachineInner::Jit(inner) => inner.memory_size(), | 684 | 71.5k | VirtualMachineInner::Interpreter(inner) => inner.memory_size(), | 685 | | } | 686 | 71.6k | } |
_RNvMs2_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_14VirtualMachine11memory_size Line | Count | Source | 666 | 10.6k | pub fn memory_size(&self) -> HeapPages { | 667 | 10.6k | match &self.inner { | 668 | | #[cfg(all( | 669 | | any( | 670 | | all( | 671 | | target_arch = "x86_64", | 672 | | any( | 673 | | target_os = "windows", | 674 | | all(target_os = "linux", target_env = "gnu"), | 675 | | target_os = "macos" | 676 | | ) | 677 | | ), | 678 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 679 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 680 | | ), | 681 | | feature = "wasmtime" | 682 | | ))] | 683 | 8.67k | VirtualMachineInner::Jit(inner) => inner.memory_size(), | 684 | 1.97k | VirtualMachineInner::Interpreter(inner) => inner.memory_size(), | 685 | | } | 686 | 10.6k | } |
|
687 | | |
688 | | /// Copies the given memory range into a `Vec<u8>`. |
689 | | /// |
690 | | /// Returns an error if the range is invalid or out of range. |
691 | 36.6k | pub fn read_memory( |
692 | 36.6k | &'_ self, |
693 | 36.6k | offset: u32, |
694 | 36.6k | size: u32, |
695 | 36.6k | ) -> Result<impl AsRef<[u8]> + '_, OutOfBoundsError> { |
696 | 36.6k | Ok(match &self.inner { |
697 | | #[cfg(all( |
698 | | any( |
699 | | all( |
700 | | target_arch = "x86_64", |
701 | | any( |
702 | | target_os = "windows", |
703 | | all(target_os = "linux", target_env = "gnu"), |
704 | | target_os = "macos" |
705 | | ) |
706 | | ), |
707 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
708 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
709 | | ), |
710 | | feature = "wasmtime" |
711 | | ))] |
712 | 2.48k | VirtualMachineInner::Jit(inner) => either::Left(inner.read_memory(offset, size)?0 ), |
713 | | #[cfg(all( |
714 | | any( |
715 | | all( |
716 | | target_arch = "x86_64", |
717 | | any( |
718 | | target_os = "windows", |
719 | | all(target_os = "linux", target_env = "gnu"), |
720 | | target_os = "macos" |
721 | | ) |
722 | | ), |
723 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
724 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
725 | | ), |
726 | | feature = "wasmtime" |
727 | | ))] |
728 | 34.1k | VirtualMachineInner::Interpreter(inner) => { |
729 | 34.1k | either::Right(inner.read_memory(offset, size)?0 ) |
730 | | } |
731 | | #[cfg(not(all( |
732 | | any( |
733 | | all( |
734 | | target_arch = "x86_64", |
735 | | any( |
736 | | target_os = "windows", |
737 | | all(target_os = "linux", target_env = "gnu"), |
738 | | target_os = "macos" |
739 | | ) |
740 | | ), |
741 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
742 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
743 | | ), |
744 | | feature = "wasmtime" |
745 | | )))] |
746 | | VirtualMachineInner::Interpreter(inner) => inner.read_memory(offset, size)?, |
747 | | }) |
748 | 36.6k | } _RNvMs2_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_14VirtualMachine11read_memory Line | Count | Source | 691 | 33.2k | pub fn read_memory( | 692 | 33.2k | &'_ self, | 693 | 33.2k | offset: u32, | 694 | 33.2k | size: u32, | 695 | 33.2k | ) -> Result<impl AsRef<[u8]> + '_, OutOfBoundsError> { | 696 | 33.2k | Ok(match &self.inner { | 697 | | #[cfg(all( | 698 | | any( | 699 | | all( | 700 | | target_arch = "x86_64", | 701 | | any( | 702 | | target_os = "windows", | 703 | | all(target_os = "linux", target_env = "gnu"), | 704 | | target_os = "macos" | 705 | | ) | 706 | | ), | 707 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 708 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 709 | | ), | 710 | | feature = "wasmtime" | 711 | | ))] | 712 | 38 | VirtualMachineInner::Jit(inner) => either::Left(inner.read_memory(offset, size)?0 ), | 713 | | #[cfg(all( | 714 | | any( | 715 | | all( | 716 | | target_arch = "x86_64", | 717 | | any( | 718 | | target_os = "windows", | 719 | | all(target_os = "linux", target_env = "gnu"), | 720 | | target_os = "macos" | 721 | | ) | 722 | | ), | 723 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 724 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 725 | | ), | 726 | | feature = "wasmtime" | 727 | | ))] | 728 | 33.2k | VirtualMachineInner::Interpreter(inner) => { | 729 | 33.2k | either::Right(inner.read_memory(offset, size)?0 ) | 730 | | } | 731 | | #[cfg(not(all( | 732 | | any( | 733 | | all( | 734 | | target_arch = "x86_64", | 735 | | any( | 736 | | target_os = "windows", | 737 | | all(target_os = "linux", target_env = "gnu"), | 738 | | target_os = "macos" | 739 | | ) | 740 | | ), | 741 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 742 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 743 | | ), | 744 | | feature = "wasmtime" | 745 | | )))] | 746 | | VirtualMachineInner::Interpreter(inner) => inner.read_memory(offset, size)?, | 747 | | }) | 748 | 33.2k | } |
_RNvMs2_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_14VirtualMachine11read_memory Line | Count | Source | 691 | 3.32k | pub fn read_memory( | 692 | 3.32k | &'_ self, | 693 | 3.32k | offset: u32, | 694 | 3.32k | size: u32, | 695 | 3.32k | ) -> Result<impl AsRef<[u8]> + '_, OutOfBoundsError> { | 696 | 3.32k | Ok(match &self.inner { | 697 | | #[cfg(all( | 698 | | any( | 699 | | all( | 700 | | target_arch = "x86_64", | 701 | | any( | 702 | | target_os = "windows", | 703 | | all(target_os = "linux", target_env = "gnu"), | 704 | | target_os = "macos" | 705 | | ) | 706 | | ), | 707 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 708 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 709 | | ), | 710 | | feature = "wasmtime" | 711 | | ))] | 712 | 2.44k | VirtualMachineInner::Jit(inner) => either::Left(inner.read_memory(offset, size)?0 ), | 713 | | #[cfg(all( | 714 | | any( | 715 | | all( | 716 | | target_arch = "x86_64", | 717 | | any( | 718 | | target_os = "windows", | 719 | | all(target_os = "linux", target_env = "gnu"), | 720 | | target_os = "macos" | 721 | | ) | 722 | | ), | 723 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 724 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 725 | | ), | 726 | | feature = "wasmtime" | 727 | | ))] | 728 | 882 | VirtualMachineInner::Interpreter(inner) => { | 729 | 882 | either::Right(inner.read_memory(offset, size)?0 ) | 730 | | } | 731 | | #[cfg(not(all( | 732 | | any( | 733 | | all( | 734 | | target_arch = "x86_64", | 735 | | any( | 736 | | target_os = "windows", | 737 | | all(target_os = "linux", target_env = "gnu"), | 738 | | target_os = "macos" | 739 | | ) | 740 | | ), | 741 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 742 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 743 | | ), | 744 | | feature = "wasmtime" | 745 | | )))] | 746 | | VirtualMachineInner::Interpreter(inner) => inner.read_memory(offset, size)?, | 747 | | }) | 748 | 3.32k | } |
|
749 | | |
750 | | /// Write the data at the given memory location. |
751 | | /// |
752 | | /// Returns an error if the range is invalid or out of range. |
753 | 39.3k | pub fn write_memory(&mut self, offset: u32, value: &[u8]) -> Result<(), OutOfBoundsError> { |
754 | 39.3k | match &mut self.inner { |
755 | | #[cfg(all( |
756 | | any( |
757 | | all( |
758 | | target_arch = "x86_64", |
759 | | any( |
760 | | target_os = "windows", |
761 | | all(target_os = "linux", target_env = "gnu"), |
762 | | target_os = "macos" |
763 | | ) |
764 | | ), |
765 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
766 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
767 | | ), |
768 | | feature = "wasmtime" |
769 | | ))] |
770 | 4.20k | VirtualMachineInner::Jit(inner) => inner.write_memory(offset, value), |
771 | 35.1k | VirtualMachineInner::Interpreter(inner) => inner.write_memory(offset, value), |
772 | | } |
773 | 39.3k | } _RNvMs2_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_14VirtualMachine12write_memory Line | Count | Source | 753 | 34.0k | pub fn write_memory(&mut self, offset: u32, value: &[u8]) -> Result<(), OutOfBoundsError> { | 754 | 34.0k | match &mut self.inner { | 755 | | #[cfg(all( | 756 | | any( | 757 | | all( | 758 | | target_arch = "x86_64", | 759 | | any( | 760 | | target_os = "windows", | 761 | | all(target_os = "linux", target_env = "gnu"), | 762 | | target_os = "macos" | 763 | | ) | 764 | | ), | 765 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 766 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 767 | | ), | 768 | | feature = "wasmtime" | 769 | | ))] | 770 | 49 | VirtualMachineInner::Jit(inner) => inner.write_memory(offset, value), | 771 | 33.9k | VirtualMachineInner::Interpreter(inner) => inner.write_memory(offset, value), | 772 | | } | 773 | 34.0k | } |
_RNvMs2_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_14VirtualMachine12write_memory Line | Count | Source | 753 | 5.36k | pub fn write_memory(&mut self, offset: u32, value: &[u8]) -> Result<(), OutOfBoundsError> { | 754 | 5.36k | match &mut self.inner { | 755 | | #[cfg(all( | 756 | | any( | 757 | | all( | 758 | | target_arch = "x86_64", | 759 | | any( | 760 | | target_os = "windows", | 761 | | all(target_os = "linux", target_env = "gnu"), | 762 | | target_os = "macos" | 763 | | ) | 764 | | ), | 765 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 766 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 767 | | ), | 768 | | feature = "wasmtime" | 769 | | ))] | 770 | 4.15k | VirtualMachineInner::Jit(inner) => inner.write_memory(offset, value), | 771 | 1.21k | VirtualMachineInner::Interpreter(inner) => inner.write_memory(offset, value), | 772 | | } | 773 | 5.36k | } |
|
774 | | |
775 | | /// Increases the size of the memory by the given number of pages. |
776 | | /// |
777 | | /// Returns an error if the size of the memory can't be expanded more. This can be known ahead |
778 | | /// of time by using [`VirtualMachinePrototype::memory_max_pages`]. |
779 | 50 | pub fn grow_memory(&mut self, additional: HeapPages) -> Result<(), OutOfBoundsError> { |
780 | 50 | match &mut self.inner { |
781 | | #[cfg(all( |
782 | | any( |
783 | | all( |
784 | | target_arch = "x86_64", |
785 | | any( |
786 | | target_os = "windows", |
787 | | all(target_os = "linux", target_env = "gnu"), |
788 | | target_os = "macos" |
789 | | ) |
790 | | ), |
791 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
792 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
793 | | ), |
794 | | feature = "wasmtime" |
795 | | ))] |
796 | 9 | VirtualMachineInner::Jit(inner) => inner.grow_memory(additional), |
797 | 41 | VirtualMachineInner::Interpreter(inner) => inner.grow_memory(additional), |
798 | | } |
799 | 50 | } _RNvMs2_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_14VirtualMachine11grow_memory Line | Count | Source | 779 | 44 | pub fn grow_memory(&mut self, additional: HeapPages) -> Result<(), OutOfBoundsError> { | 780 | 44 | match &mut self.inner { | 781 | | #[cfg(all( | 782 | | any( | 783 | | all( | 784 | | target_arch = "x86_64", | 785 | | any( | 786 | | target_os = "windows", | 787 | | all(target_os = "linux", target_env = "gnu"), | 788 | | target_os = "macos" | 789 | | ) | 790 | | ), | 791 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 792 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 793 | | ), | 794 | | feature = "wasmtime" | 795 | | ))] | 796 | 3 | VirtualMachineInner::Jit(inner) => inner.grow_memory(additional), | 797 | 41 | VirtualMachineInner::Interpreter(inner) => inner.grow_memory(additional), | 798 | | } | 799 | 44 | } |
_RNvMs2_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_14VirtualMachine11grow_memory Line | Count | Source | 779 | 6 | pub fn grow_memory(&mut self, additional: HeapPages) -> Result<(), OutOfBoundsError> { | 780 | 6 | match &mut self.inner { | 781 | | #[cfg(all( | 782 | | any( | 783 | | all( | 784 | | target_arch = "x86_64", | 785 | | any( | 786 | | target_os = "windows", | 787 | | all(target_os = "linux", target_env = "gnu"), | 788 | | target_os = "macos" | 789 | | ) | 790 | | ), | 791 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 792 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 793 | | ), | 794 | | feature = "wasmtime" | 795 | | ))] | 796 | 6 | VirtualMachineInner::Jit(inner) => inner.grow_memory(additional), | 797 | 0 | VirtualMachineInner::Interpreter(inner) => inner.grow_memory(additional), | 798 | | } | 799 | 6 | } |
|
800 | | |
801 | | /// Turns back this virtual machine into a prototype. |
802 | 147 | pub fn into_prototype(self) -> VirtualMachinePrototype { |
803 | 147 | VirtualMachinePrototype { |
804 | 147 | inner: match self.inner { |
805 | | #[cfg(all( |
806 | | any( |
807 | | all( |
808 | | target_arch = "x86_64", |
809 | | any( |
810 | | target_os = "windows", |
811 | | all(target_os = "linux", target_env = "gnu"), |
812 | | target_os = "macos" |
813 | | ) |
814 | | ), |
815 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
816 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
817 | | ), |
818 | | feature = "wasmtime" |
819 | | ))] |
820 | 7 | VirtualMachineInner::Jit(inner) => { |
821 | 7 | VirtualMachinePrototypeInner::Jit(inner.into_prototype()) |
822 | | } |
823 | 140 | VirtualMachineInner::Interpreter(inner) => { |
824 | 140 | VirtualMachinePrototypeInner::Interpreter(inner.into_prototype()) |
825 | | } |
826 | | }, |
827 | | } |
828 | 147 | } _RNvMs2_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_14VirtualMachine14into_prototype Line | Count | Source | 802 | 21 | pub fn into_prototype(self) -> VirtualMachinePrototype { | 803 | 21 | VirtualMachinePrototype { | 804 | 21 | inner: match self.inner { | 805 | | #[cfg(all( | 806 | | any( | 807 | | all( | 808 | | target_arch = "x86_64", | 809 | | any( | 810 | | target_os = "windows", | 811 | | all(target_os = "linux", target_env = "gnu"), | 812 | | target_os = "macos" | 813 | | ) | 814 | | ), | 815 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 816 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 817 | | ), | 818 | | feature = "wasmtime" | 819 | | ))] | 820 | 7 | VirtualMachineInner::Jit(inner) => { | 821 | 7 | VirtualMachinePrototypeInner::Jit(inner.into_prototype()) | 822 | | } | 823 | 14 | VirtualMachineInner::Interpreter(inner) => { | 824 | 14 | VirtualMachinePrototypeInner::Interpreter(inner.into_prototype()) | 825 | | } | 826 | | }, | 827 | | } | 828 | 21 | } |
_RNvMs2_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_14VirtualMachine14into_prototype Line | Count | Source | 802 | 126 | pub fn into_prototype(self) -> VirtualMachinePrototype { | 803 | 126 | VirtualMachinePrototype { | 804 | 126 | inner: match self.inner { | 805 | | #[cfg(all( | 806 | | any( | 807 | | all( | 808 | | target_arch = "x86_64", | 809 | | any( | 810 | | target_os = "windows", | 811 | | all(target_os = "linux", target_env = "gnu"), | 812 | | target_os = "macos" | 813 | | ) | 814 | | ), | 815 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 816 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 817 | | ), | 818 | | feature = "wasmtime" | 819 | | ))] | 820 | 0 | VirtualMachineInner::Jit(inner) => { | 821 | 0 | VirtualMachinePrototypeInner::Jit(inner.into_prototype()) | 822 | | } | 823 | 126 | VirtualMachineInner::Interpreter(inner) => { | 824 | 126 | VirtualMachinePrototypeInner::Interpreter(inner.into_prototype()) | 825 | | } | 826 | | }, | 827 | | } | 828 | 126 | } |
|
829 | | } |
830 | | |
831 | | impl fmt::Debug for VirtualMachine { |
832 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
833 | 0 | match &self.inner { |
834 | | #[cfg(all( |
835 | | any( |
836 | | all( |
837 | | target_arch = "x86_64", |
838 | | any( |
839 | | target_os = "windows", |
840 | | all(target_os = "linux", target_env = "gnu"), |
841 | | target_os = "macos" |
842 | | ) |
843 | | ), |
844 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
845 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
846 | | ), |
847 | | feature = "wasmtime" |
848 | | ))] |
849 | 0 | VirtualMachineInner::Jit(inner) => fmt::Debug::fmt(inner, f), |
850 | 0 | VirtualMachineInner::Interpreter(inner) => fmt::Debug::fmt(inner, f), |
851 | | } |
852 | 0 | } Unexecuted instantiation: _RNvXs3_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_14VirtualMachineNtNtCsaYZPK01V26L_4core3fmt5Debug3fmt Unexecuted instantiation: _RNvXs3_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_14VirtualMachineNtNtCsaYZPK01V26L_4core3fmt5Debug3fmt |
853 | | } |
854 | | |
855 | | /// Hint used by the implementation to decide which kind of virtual machine to use. |
856 | | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
857 | | pub enum ExecHint { |
858 | | /// The WebAssembly code will be instantiated once and run many times. |
859 | | /// If possible, compile this WebAssembly code ahead of time. |
860 | | ValidateAndCompile, |
861 | | |
862 | | /// The WebAssembly code will be instantiated once and run many times. |
863 | | /// Contrary to [`ExecHint::ValidateAndCompile`], the WebAssembly code isn't fully validated |
864 | | /// ahead of time, meaning that invalid WebAssembly modules might successfully be compiled, |
865 | | /// which is an indesirable property in some contexts. |
866 | | CompileWithNonDeterministicValidation, |
867 | | |
868 | | /// The WebAssembly code is expected to be only run once. |
869 | | /// |
870 | | /// > **Note**: This isn't a hard requirement but a hint. |
871 | | ValidateAndExecuteOnce, |
872 | | |
873 | | /// The WebAssembly code will be instantiated once and run many times. |
874 | | /// Contrary to [`ExecHint::ValidateAndExecuteOnce`], the WebAssembly code isn't fully |
875 | | /// validated ahead of time, meaning that invalid WebAssembly modules might successfully be |
876 | | /// compiled, which is an indesirable property in some contexts. |
877 | | ExecuteOnceWithNonDeterministicValidation, |
878 | | |
879 | | /// The WebAssembly code running through this VM is untrusted. |
880 | | Untrusted, |
881 | | |
882 | | /// Forces using the `wasmi` backend. |
883 | | /// |
884 | | /// This variant is useful for testing purposes. |
885 | | ForceWasmi { |
886 | | /// If `true`, lazy validation is enabled. This leads to a faster initialization time, |
887 | | /// but can also successfully validate invalid modules, which is an indesirable property |
888 | | /// in some contexts. |
889 | | lazy_validation: bool, |
890 | | }, |
891 | | /// Forces using the `wasmtime` backend. |
892 | | /// |
893 | | /// This variant is useful for testing purposes. |
894 | | #[cfg(all( |
895 | | any( |
896 | | all( |
897 | | target_arch = "x86_64", |
898 | | any( |
899 | | target_os = "windows", |
900 | | all(target_os = "linux", target_env = "gnu"), |
901 | | target_os = "macos" |
902 | | ) |
903 | | ), |
904 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
905 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
906 | | ), |
907 | | feature = "wasmtime" |
908 | | ))] |
909 | | #[cfg_attr( |
910 | | docsrs, |
911 | | doc(cfg(all( |
912 | | any( |
913 | | all( |
914 | | target_arch = "x86_64", |
915 | | any( |
916 | | target_os = "windows", |
917 | | all(target_os = "linux", target_env = "gnu"), |
918 | | target_os = "macos" |
919 | | ) |
920 | | ), |
921 | | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
922 | | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
923 | | ), |
924 | | feature = "wasmtime" |
925 | | ))) |
926 | | )] |
927 | | ForceWasmtime, |
928 | | } |
929 | | |
930 | | impl ExecHint { |
931 | | /// Returns an iterator of all the [`ExecHint`] values corresponding to execution engines. |
932 | | /// |
933 | | /// > **Note**: This function is most useful for testing purposes. |
934 | 71 | pub fn available_engines() -> impl Iterator<Item = ExecHint> { |
935 | 71 | iter::once(ExecHint::ForceWasmi { |
936 | 71 | lazy_validation: false, |
937 | 71 | }) |
938 | 71 | .chain(Self::force_wasmtime_if_available()) |
939 | 71 | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_8ExecHint17available_engines Line | Count | Source | 934 | 71 | pub fn available_engines() -> impl Iterator<Item = ExecHint> { | 935 | 71 | iter::once(ExecHint::ForceWasmi { | 936 | 71 | lazy_validation: false, | 937 | 71 | }) | 938 | 71 | .chain(Self::force_wasmtime_if_available()) | 939 | 71 | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_8ExecHint17available_engines |
940 | | |
941 | | /// Returns `ForceWasmtime` if it is available on the current platform, and `None` otherwise. |
942 | 77 | pub fn force_wasmtime_if_available() -> Option<ExecHint> { |
943 | 77 | #[cfg(all( |
944 | 77 | any( |
945 | 77 | all( |
946 | 77 | target_arch = "x86_64", |
947 | 77 | any( |
948 | 77 | target_os = "windows", |
949 | 77 | all(target_os = "linux", target_env = "gnu"), |
950 | 77 | target_os = "macos" |
951 | 77 | ) |
952 | 77 | ), |
953 | 77 | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
954 | 77 | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
955 | 77 | ), |
956 | 77 | feature = "wasmtime" |
957 | 77 | ))] |
958 | 77 | fn value() -> Option<ExecHint> { |
959 | 77 | Some(ExecHint::ForceWasmtime) |
960 | 77 | } _RNvNvMs4_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB7_8ExecHint27force_wasmtime_if_available5value Line | Count | Source | 958 | 77 | fn value() -> Option<ExecHint> { | 959 | 77 | Some(ExecHint::ForceWasmtime) | 960 | 77 | } |
Unexecuted instantiation: _RNvNvMs4_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB7_8ExecHint27force_wasmtime_if_available5value |
961 | 77 | #[cfg(not(all( |
962 | 77 | any( |
963 | 77 | all( |
964 | 77 | target_arch = "x86_64", |
965 | 77 | any( |
966 | 77 | target_os = "windows", |
967 | 77 | all(target_os = "linux", target_env = "gnu"), |
968 | 77 | target_os = "macos" |
969 | 77 | ) |
970 | 77 | ), |
971 | 77 | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), |
972 | 77 | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) |
973 | 77 | ), |
974 | 77 | feature = "wasmtime" |
975 | 77 | )))] |
976 | 77 | fn value() -> Option<ExecHint> { |
977 | 77 | None |
978 | 77 | } |
979 | 77 | value() |
980 | 77 | } _RNvMs4_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_8ExecHint27force_wasmtime_if_available Line | Count | Source | 942 | 77 | pub fn force_wasmtime_if_available() -> Option<ExecHint> { | 943 | 77 | #[cfg(all( | 944 | 77 | any( | 945 | 77 | all( | 946 | 77 | target_arch = "x86_64", | 947 | 77 | any( | 948 | 77 | target_os = "windows", | 949 | 77 | all(target_os = "linux", target_env = "gnu"), | 950 | 77 | target_os = "macos" | 951 | 77 | ) | 952 | 77 | ), | 953 | 77 | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 954 | 77 | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 955 | 77 | ), | 956 | 77 | feature = "wasmtime" | 957 | 77 | ))] | 958 | 77 | fn value() -> Option<ExecHint> { | 959 | 77 | Some(ExecHint::ForceWasmtime) | 960 | 77 | } | 961 | 77 | #[cfg(not(all( | 962 | 77 | any( | 963 | 77 | all( | 964 | 77 | target_arch = "x86_64", | 965 | 77 | any( | 966 | 77 | target_os = "windows", | 967 | 77 | all(target_os = "linux", target_env = "gnu"), | 968 | 77 | target_os = "macos" | 969 | 77 | ) | 970 | 77 | ), | 971 | 77 | all(target_arch = "aarch64", all(target_os = "linux", target_env = "gnu")), | 972 | 77 | all(target_arch = "s390x", all(target_os = "linux", target_env = "gnu")) | 973 | 77 | ), | 974 | 77 | feature = "wasmtime" | 975 | 77 | )))] | 976 | 77 | fn value() -> Option<ExecHint> { | 977 | 77 | None | 978 | 77 | } | 979 | 77 | value() | 980 | 77 | } |
Unexecuted instantiation: _RNvMs4_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_8ExecHint27force_wasmtime_if_available |
981 | | } |
982 | | |
983 | | /// Number of heap pages available to the Wasm code. |
984 | | /// |
985 | | /// Each page is `64kiB`. |
986 | | #[derive( |
987 | 314 | Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, derive_more::Add, derive_more::Sub58 , _RNvXsF_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9HeapPagesNtNtNtCsaYZPK01V26L_4core3ops5arith3Add3add Line | Count | Source | 987 | 136 | Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, derive_more::Add, derive_more::Sub, |
_RNvXsF_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9HeapPagesNtNtNtCsaYZPK01V26L_4core3ops5arith3Add3add Line | Count | Source | 987 | 178 | Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, derive_more::Add, derive_more::Sub, |
_RNvXsG_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9HeapPagesNtNtNtCsaYZPK01V26L_4core3ops5arith3Sub3sub Line | Count | Source | 987 | 52 | Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, derive_more::Add, derive_more::Sub, |
_RNvXsG_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9HeapPagesNtNtNtCsaYZPK01V26L_4core3ops5arith3Sub3sub Line | Count | Source | 987 | 6 | Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, derive_more::Add, derive_more::Sub, |
|
988 | | )] |
989 | | pub struct HeapPages(u32); |
990 | | |
991 | | impl HeapPages { |
992 | 119k | pub const fn new(v: u32) -> Self { |
993 | 119k | HeapPages(v) |
994 | 119k | } _RNvMs5_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9HeapPages3new Line | Count | Source | 992 | 97.5k | pub const fn new(v: u32) -> Self { | 993 | 97.5k | HeapPages(v) | 994 | 97.5k | } |
_RNvMs5_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9HeapPages3new Line | Count | Source | 992 | 22.3k | pub const fn new(v: u32) -> Self { | 993 | 22.3k | HeapPages(v) | 994 | 22.3k | } |
|
995 | | } |
996 | | |
997 | | impl From<u32> for HeapPages { |
998 | 179 | fn from(v: u32) -> Self { |
999 | 179 | HeapPages(v) |
1000 | 179 | } _RNvXs6_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9HeapPagesINtNtCsaYZPK01V26L_4core7convert4FrommE4from Line | Count | Source | 998 | 52 | fn from(v: u32) -> Self { | 999 | 52 | HeapPages(v) | 1000 | 52 | } |
_RNvXs6_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9HeapPagesINtNtCsaYZPK01V26L_4core7convert4FrommE4from Line | Count | Source | 998 | 127 | fn from(v: u32) -> Self { | 999 | 127 | HeapPages(v) | 1000 | 127 | } |
|
1001 | | } |
1002 | | |
1003 | | impl From<HeapPages> for u32 { |
1004 | 150k | fn from(v: HeapPages) -> Self { |
1005 | 150k | v.0 |
1006 | 150k | } _RNvXs7_NtNtCsN16ciHI6Qf_7smoldot8executor2vmmINtNtCsaYZPK01V26L_4core7convert4FromNtB5_9HeapPagesE4from Line | Count | Source | 1004 | 129k | fn from(v: HeapPages) -> Self { | 1005 | 129k | v.0 | 1006 | 129k | } |
_RNvXs7_NtNtCseuYC0Zibziv_7smoldot8executor2vmmINtNtCsaYZPK01V26L_4core7convert4FromNtB5_9HeapPagesE4from Line | Count | Source | 1004 | 21.1k | fn from(v: HeapPages) -> Self { | 1005 | 21.1k | v.0 | 1006 | 21.1k | } |
|
1007 | | } |
1008 | | |
1009 | | /// Low-level Wasm function signature. |
1010 | | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1011 | | pub struct Signature { |
1012 | | params: SmallVec<[ValueType; 8]>, |
1013 | | ret_ty: Option<ValueType>, |
1014 | | } |
1015 | | |
1016 | | // TODO: figure out how to optimize so that we can use this macro in a const context |
1017 | | #[macro_export] |
1018 | | macro_rules! signature { |
1019 | | (($($param:expr),* $(,)?) => ()) => { |
1020 | | $crate::executor::vm::Signature::from_components(smallvec::smallvec!($($param),*), None) |
1021 | | }; |
1022 | | (($($param:expr),* $(,)?) => $ret:expr) => { |
1023 | | $crate::executor::vm::Signature::from_components(smallvec::smallvec!($($param),*), Some($ret)) |
1024 | | }; |
1025 | | } |
1026 | | |
1027 | | impl Signature { |
1028 | | /// Creates a [`Signature`] from the given parameter types and return type. |
1029 | 0 | pub fn new( |
1030 | 0 | params: impl Iterator<Item = ValueType>, |
1031 | 0 | ret_ty: impl Into<Option<ValueType>>, |
1032 | 0 | ) -> Signature { |
1033 | 0 | Signature { |
1034 | 0 | params: params.collect(), |
1035 | 0 | ret_ty: ret_ty.into(), |
1036 | 0 | } |
1037 | 0 | } Unexecuted instantiation: _RINvMs8_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB6_9Signature3newppEBa_ Unexecuted instantiation: _RINvMs8_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB6_9Signature3newppEBa_ |
1038 | | |
1039 | | // TODO: find a way to remove? it is used only by the signature! macro |
1040 | | #[doc(hidden)] |
1041 | 2.94k | pub(crate) fn from_components( |
1042 | 2.94k | params: SmallVec<[ValueType; 8]>, |
1043 | 2.94k | ret_ty: Option<ValueType>, |
1044 | 2.94k | ) -> Self { |
1045 | 2.94k | Signature { params, ret_ty } |
1046 | 2.94k | } _RNvMs8_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9Signature15from_components Line | Count | Source | 1041 | 446 | pub(crate) fn from_components( | 1042 | 446 | params: SmallVec<[ValueType; 8]>, | 1043 | 446 | ret_ty: Option<ValueType>, | 1044 | 446 | ) -> Self { | 1045 | 446 | Signature { params, ret_ty } | 1046 | 446 | } |
_RNvMs8_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9Signature15from_components Line | Count | Source | 1041 | 2.49k | pub(crate) fn from_components( | 1042 | 2.49k | params: SmallVec<[ValueType; 8]>, | 1043 | 2.49k | ret_ty: Option<ValueType>, | 1044 | 2.49k | ) -> Self { | 1045 | 2.49k | Signature { params, ret_ty } | 1046 | 2.49k | } |
|
1047 | | |
1048 | | /// Returns a list of all the types of the parameters. |
1049 | 394 | pub fn parameters(&self) -> impl ExactSizeIterator<Item = &ValueType> { |
1050 | 394 | self.params.iter() |
1051 | 394 | } _RNvMs8_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9Signature10parameters Line | Count | Source | 1049 | 140 | pub fn parameters(&self) -> impl ExactSizeIterator<Item = &ValueType> { | 1050 | 140 | self.params.iter() | 1051 | 140 | } |
_RNvMs8_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9Signature10parameters Line | Count | Source | 1049 | 254 | pub fn parameters(&self) -> impl ExactSizeIterator<Item = &ValueType> { | 1050 | 254 | self.params.iter() | 1051 | 254 | } |
|
1052 | | |
1053 | | /// Returns the type of the return type of the function. `None` means "void". |
1054 | 24 | pub fn return_type(&self) -> Option<&ValueType> { |
1055 | 24 | self.ret_ty.as_ref() |
1056 | 24 | } _RNvMs8_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9Signature11return_type Line | Count | Source | 1054 | 23 | pub fn return_type(&self) -> Option<&ValueType> { | 1055 | 23 | self.ret_ty.as_ref() | 1056 | 23 | } |
_RNvMs8_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9Signature11return_type Line | Count | Source | 1054 | 1 | pub fn return_type(&self) -> Option<&ValueType> { | 1055 | 1 | self.ret_ty.as_ref() | 1056 | 1 | } |
|
1057 | | } |
1058 | | |
1059 | | impl<'a> From<&'a Signature> for wasmi::FuncType { |
1060 | 0 | fn from(sig: &'a Signature) -> Self { |
1061 | 0 | wasmi::FuncType::new( |
1062 | 0 | sig.params |
1063 | 0 | .iter() |
1064 | 0 | .copied() |
1065 | 0 | .map(wasmi::core::ValType::from) |
1066 | 0 | .collect::<Vec<_>>(), |
1067 | 0 | sig.ret_ty.map(wasmi::core::ValType::from), |
1068 | 0 | ) |
1069 | 0 | } Unexecuted instantiation: _RNvXs9_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtNtNtCs8aZSoSaEfbY_5wasmi4func9func_type8FuncTypeINtNtCsaYZPK01V26L_4core7convert4FromRNtB5_9SignatureE4from Unexecuted instantiation: _RNvXs9_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtNtNtCs8aZSoSaEfbY_5wasmi4func9func_type8FuncTypeINtNtCsaYZPK01V26L_4core7convert4FromRNtB5_9SignatureE4from |
1070 | | } |
1071 | | |
1072 | | impl From<Signature> for wasmi::FuncType { |
1073 | 0 | fn from(sig: Signature) -> wasmi::FuncType { |
1074 | 0 | wasmi::FuncType::from(&sig) |
1075 | 0 | } Unexecuted instantiation: _RNvXsa_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtNtNtCs8aZSoSaEfbY_5wasmi4func9func_type8FuncTypeINtNtCsaYZPK01V26L_4core7convert4FromNtB5_9SignatureE4from Unexecuted instantiation: _RNvXsa_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtNtNtCs8aZSoSaEfbY_5wasmi4func9func_type8FuncTypeINtNtCsaYZPK01V26L_4core7convert4FromNtB5_9SignatureE4from |
1076 | | } |
1077 | | |
1078 | | impl<'a> TryFrom<&'a wasmi::FuncType> for Signature { |
1079 | | type Error = UnsupportedTypeError; |
1080 | | |
1081 | 2.40k | fn try_from(sig: &'a wasmi::FuncType) -> Result<Self, Self::Error> { |
1082 | 2.40k | if sig.results().len() > 1 { |
1083 | 0 | return Err(UnsupportedTypeError); |
1084 | 2.40k | } |
1085 | 2.40k | |
1086 | 2.40k | Ok(Signature { |
1087 | 2.40k | params: sig |
1088 | 2.40k | .params() |
1089 | 2.40k | .iter() |
1090 | 2.40k | .copied() |
1091 | 2.40k | .map(ValueType::try_from) |
1092 | 2.40k | .collect::<Result<_, _>>()?1 , |
1093 | 2.40k | ret_ty: sig |
1094 | 2.40k | .results() |
1095 | 2.40k | .first() |
1096 | 2.40k | .copied() |
1097 | 2.40k | .map(ValueType::try_from) |
1098 | 2.40k | .transpose()?1 , |
1099 | | }) |
1100 | 2.40k | } _RNvXsb_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9SignatureINtNtCsaYZPK01V26L_4core7convert7TryFromRNtNtNtCs8aZSoSaEfbY_5wasmi4func9func_type8FuncTypeE8try_from Line | Count | Source | 1081 | 454 | fn try_from(sig: &'a wasmi::FuncType) -> Result<Self, Self::Error> { | 1082 | 454 | if sig.results().len() > 1 { | 1083 | 0 | return Err(UnsupportedTypeError); | 1084 | 454 | } | 1085 | 454 | | 1086 | 454 | Ok(Signature { | 1087 | 454 | params: sig | 1088 | 454 | .params() | 1089 | 454 | .iter() | 1090 | 454 | .copied() | 1091 | 454 | .map(ValueType::try_from) | 1092 | 454 | .collect::<Result<_, _>>()?1 , | 1093 | 453 | ret_ty: sig | 1094 | 453 | .results() | 1095 | 453 | .first() | 1096 | 453 | .copied() | 1097 | 453 | .map(ValueType::try_from) | 1098 | 453 | .transpose()?1 , | 1099 | | }) | 1100 | 454 | } |
_RNvXsb_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9SignatureINtNtCsaYZPK01V26L_4core7convert7TryFromRNtNtNtCs8aZSoSaEfbY_5wasmi4func9func_type8FuncTypeE8try_from Line | Count | Source | 1081 | 1.95k | fn try_from(sig: &'a wasmi::FuncType) -> Result<Self, Self::Error> { | 1082 | 1.95k | if sig.results().len() > 1 { | 1083 | 0 | return Err(UnsupportedTypeError); | 1084 | 1.95k | } | 1085 | 1.95k | | 1086 | 1.95k | Ok(Signature { | 1087 | 1.95k | params: sig | 1088 | 1.95k | .params() | 1089 | 1.95k | .iter() | 1090 | 1.95k | .copied() | 1091 | 1.95k | .map(ValueType::try_from) | 1092 | 1.95k | .collect::<Result<_, _>>()?0 , | 1093 | 1.95k | ret_ty: sig | 1094 | 1.95k | .results() | 1095 | 1.95k | .first() | 1096 | 1.95k | .copied() | 1097 | 1.95k | .map(ValueType::try_from) | 1098 | 1.95k | .transpose()?0 , | 1099 | | }) | 1100 | 1.95k | } |
|
1101 | | } |
1102 | | |
1103 | | #[cfg(all( |
1104 | | any( |
1105 | | all( |
1106 | | target_arch = "x86_64", |
1107 | | any( |
1108 | | target_os = "windows", |
1109 | | all(target_os = "linux", target_env = "gnu"), |
1110 | | target_os = "macos" |
1111 | | ) |
1112 | | ), |
1113 | | all(target_arch = "aarch64", target_os = "linux", target_env = "gnu"), |
1114 | | all(target_arch = "s390x", target_os = "linux", target_env = "gnu") |
1115 | | ), |
1116 | | feature = "wasmtime" |
1117 | | ))] |
1118 | | impl<'a> TryFrom<&'a wasmtime::FuncType> for Signature { |
1119 | | type Error = UnsupportedTypeError; |
1120 | | |
1121 | 889 | fn try_from(sig: &'a wasmtime::FuncType) -> Result<Self, Self::Error> { |
1122 | 889 | if sig.results().len() > 1 { |
1123 | 0 | return Err(UnsupportedTypeError); |
1124 | 889 | } |
1125 | 889 | |
1126 | 889 | Ok(Signature { |
1127 | 889 | params: sig |
1128 | 889 | .params() |
1129 | 889 | .map(ValueType::try_from) |
1130 | 889 | .collect::<Result<_, _>>()?1 , |
1131 | 888 | ret_ty: sig.results().next().map(ValueType::try_from).transpose()?1 , |
1132 | | }) |
1133 | 889 | } _RNvXsc_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9SignatureINtNtCsaYZPK01V26L_4core7convert7TryFromRNtNtNtCsc4mtb4KvHAY_8wasmtime7runtime5types8FuncTypeE8try_from Line | Count | Source | 1121 | 220 | fn try_from(sig: &'a wasmtime::FuncType) -> Result<Self, Self::Error> { | 1122 | 220 | if sig.results().len() > 1 { | 1123 | 0 | return Err(UnsupportedTypeError); | 1124 | 220 | } | 1125 | 220 | | 1126 | 220 | Ok(Signature { | 1127 | 220 | params: sig | 1128 | 220 | .params() | 1129 | 220 | .map(ValueType::try_from) | 1130 | 220 | .collect::<Result<_, _>>()?1 , | 1131 | 219 | ret_ty: sig.results().next().map(ValueType::try_from).transpose()?1 , | 1132 | | }) | 1133 | 220 | } |
_RNvXsc_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9SignatureINtNtCsaYZPK01V26L_4core7convert7TryFromRNtNtNtCsc4mtb4KvHAY_8wasmtime7runtime5types8FuncTypeE8try_from Line | Count | Source | 1121 | 669 | fn try_from(sig: &'a wasmtime::FuncType) -> Result<Self, Self::Error> { | 1122 | 669 | if sig.results().len() > 1 { | 1123 | 0 | return Err(UnsupportedTypeError); | 1124 | 669 | } | 1125 | 669 | | 1126 | 669 | Ok(Signature { | 1127 | 669 | params: sig | 1128 | 669 | .params() | 1129 | 669 | .map(ValueType::try_from) | 1130 | 669 | .collect::<Result<_, _>>()?0 , | 1131 | 669 | ret_ty: sig.results().next().map(ValueType::try_from).transpose()?0 , | 1132 | | }) | 1133 | 669 | } |
|
1134 | | } |
1135 | | |
1136 | | impl TryFrom<wasmi::FuncType> for Signature { |
1137 | | type Error = UnsupportedTypeError; |
1138 | | |
1139 | 169 | fn try_from(sig: wasmi::FuncType) -> Result<Self, Self::Error> { |
1140 | 169 | Signature::try_from(&sig) |
1141 | 169 | } _RNvXsd_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9SignatureINtNtCsaYZPK01V26L_4core7convert7TryFromNtNtNtCs8aZSoSaEfbY_5wasmi4func9func_type8FuncTypeE8try_from Line | Count | Source | 1139 | 43 | fn try_from(sig: wasmi::FuncType) -> Result<Self, Self::Error> { | 1140 | 43 | Signature::try_from(&sig) | 1141 | 43 | } |
_RNvXsd_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9SignatureINtNtCsaYZPK01V26L_4core7convert7TryFromNtNtNtCs8aZSoSaEfbY_5wasmi4func9func_type8FuncTypeE8try_from Line | Count | Source | 1139 | 126 | fn try_from(sig: wasmi::FuncType) -> Result<Self, Self::Error> { | 1140 | 126 | Signature::try_from(&sig) | 1141 | 126 | } |
|
1142 | | } |
1143 | | |
1144 | | /// Value that a Wasm function can accept or produce. |
1145 | | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
1146 | | pub enum WasmValue { |
1147 | | /// A 32-bits integer. There is no fundamental difference between signed and unsigned |
1148 | | /// integer, and the signed-ness should be determined depending on the context. |
1149 | | I32(i32), |
1150 | | /// A 32-bits integer. There is no fundamental difference between signed and unsigned |
1151 | | /// integer, and the signed-ness should be determined depending on the context. |
1152 | | I64(i64), |
1153 | | } |
1154 | | |
1155 | | /// Type of a value passed as parameter or returned by a function. |
1156 | | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
1157 | | pub enum ValueType { |
1158 | | /// A 32-bits integer. Used for both signed and unsigned integers. |
1159 | | I32, |
1160 | | /// A 64-bits integer. Used for both signed and unsigned integers. |
1161 | | I64, |
1162 | | } |
1163 | | |
1164 | | impl WasmValue { |
1165 | | /// Returns the type corresponding to this value. |
1166 | 17.4k | pub fn ty(&self) -> ValueType { |
1167 | 17.4k | match self { |
1168 | 16.7k | WasmValue::I32(_) => ValueType::I32, |
1169 | 685 | WasmValue::I64(_) => ValueType::I64, |
1170 | | } |
1171 | 17.4k | } _RNvMse_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9WasmValue2ty Line | Count | Source | 1166 | 14.4k | pub fn ty(&self) -> ValueType { | 1167 | 14.4k | match self { | 1168 | 13.8k | WasmValue::I32(_) => ValueType::I32, | 1169 | 601 | WasmValue::I64(_) => ValueType::I64, | 1170 | | } | 1171 | 14.4k | } |
_RNvMse_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9WasmValue2ty Line | Count | Source | 1166 | 2.91k | pub fn ty(&self) -> ValueType { | 1167 | 2.91k | match self { | 1168 | 2.83k | WasmValue::I32(_) => ValueType::I32, | 1169 | 84 | WasmValue::I64(_) => ValueType::I64, | 1170 | | } | 1171 | 2.91k | } |
|
1172 | | |
1173 | | /// Unwraps [`WasmValue::I32`] into its value. |
1174 | 0 | pub fn into_i32(self) -> Option<i32> { |
1175 | 0 | if let WasmValue::I32(v) = self { |
1176 | 0 | Some(v) |
1177 | | } else { |
1178 | 0 | None |
1179 | | } |
1180 | 0 | } Unexecuted instantiation: _RNvMse_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9WasmValue8into_i32 Unexecuted instantiation: _RNvMse_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9WasmValue8into_i32 |
1181 | | |
1182 | | /// Unwraps [`WasmValue::I64`] into its value. |
1183 | 0 | pub fn into_i64(self) -> Option<i64> { |
1184 | 0 | if let WasmValue::I64(v) = self { |
1185 | 0 | Some(v) |
1186 | | } else { |
1187 | 0 | None |
1188 | | } |
1189 | 0 | } Unexecuted instantiation: _RNvMse_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9WasmValue8into_i64 Unexecuted instantiation: _RNvMse_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9WasmValue8into_i64 |
1190 | | } |
1191 | | |
1192 | | impl TryFrom<wasmi::Val> for WasmValue { |
1193 | | type Error = UnsupportedTypeError; |
1194 | | |
1195 | 156 | fn try_from(val: wasmi::Val) -> Result<Self, Self::Error> { |
1196 | 156 | match val { |
1197 | 3 | wasmi::Val::I32(v) => Ok(WasmValue::I32(v)), |
1198 | 153 | wasmi::Val::I64(v) => Ok(WasmValue::I64(v)), |
1199 | 0 | _ => Err(UnsupportedTypeError), |
1200 | | } |
1201 | 156 | } _RNvXsf_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9WasmValueINtNtCsaYZPK01V26L_4core7convert7TryFromNtNtCs8aZSoSaEfbY_5wasmi5value3ValE8try_from Line | Count | Source | 1195 | 30 | fn try_from(val: wasmi::Val) -> Result<Self, Self::Error> { | 1196 | 30 | match val { | 1197 | 3 | wasmi::Val::I32(v) => Ok(WasmValue::I32(v)), | 1198 | 27 | wasmi::Val::I64(v) => Ok(WasmValue::I64(v)), | 1199 | 0 | _ => Err(UnsupportedTypeError), | 1200 | | } | 1201 | 30 | } |
_RNvXsf_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9WasmValueINtNtCsaYZPK01V26L_4core7convert7TryFromNtNtCs8aZSoSaEfbY_5wasmi5value3ValE8try_from Line | Count | Source | 1195 | 126 | fn try_from(val: wasmi::Val) -> Result<Self, Self::Error> { | 1196 | 126 | match val { | 1197 | 0 | wasmi::Val::I32(v) => Ok(WasmValue::I32(v)), | 1198 | 126 | wasmi::Val::I64(v) => Ok(WasmValue::I64(v)), | 1199 | 0 | _ => Err(UnsupportedTypeError), | 1200 | | } | 1201 | 126 | } |
|
1202 | | } |
1203 | | |
1204 | | impl<'a> TryFrom<&'a wasmi::Val> for WasmValue { |
1205 | | type Error = UnsupportedTypeError; |
1206 | | |
1207 | 30.3k | fn try_from(val: &'a wasmi::Val) -> Result<Self, Self::Error> { |
1208 | 30.3k | match val { |
1209 | 26.7k | wasmi::Val::I32(v) => Ok(WasmValue::I32(*v)), |
1210 | 3.61k | wasmi::Val::I64(v) => Ok(WasmValue::I64(*v)), |
1211 | 0 | _ => Err(UnsupportedTypeError), |
1212 | | } |
1213 | 30.3k | } _RNvXsg_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9WasmValueINtNtCsaYZPK01V26L_4core7convert7TryFromRNtNtCs8aZSoSaEfbY_5wasmi5value3ValE8try_from Line | Count | Source | 1207 | 29.5k | fn try_from(val: &'a wasmi::Val) -> Result<Self, Self::Error> { | 1208 | 29.5k | match val { | 1209 | 26.0k | wasmi::Val::I32(v) => Ok(WasmValue::I32(*v)), | 1210 | 3.45k | wasmi::Val::I64(v) => Ok(WasmValue::I64(*v)), | 1211 | 0 | _ => Err(UnsupportedTypeError), | 1212 | | } | 1213 | 29.5k | } |
_RNvXsg_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9WasmValueINtNtCsaYZPK01V26L_4core7convert7TryFromRNtNtCs8aZSoSaEfbY_5wasmi5value3ValE8try_from Line | Count | Source | 1207 | 798 | fn try_from(val: &'a wasmi::Val) -> Result<Self, Self::Error> { | 1208 | 798 | match val { | 1209 | 630 | wasmi::Val::I32(v) => Ok(WasmValue::I32(*v)), | 1210 | 168 | wasmi::Val::I64(v) => Ok(WasmValue::I64(*v)), | 1211 | 0 | _ => Err(UnsupportedTypeError), | 1212 | | } | 1213 | 798 | } |
|
1214 | | } |
1215 | | |
1216 | | impl From<WasmValue> for wasmi::Val { |
1217 | 15.2k | fn from(val: WasmValue) -> Self { |
1218 | 15.2k | match val { |
1219 | 14.5k | WasmValue::I32(v) => wasmi::Val::I32(v), |
1220 | 683 | WasmValue::I64(v) => wasmi::Val::I64(v), |
1221 | | } |
1222 | 15.2k | } _RNvXsh_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtNtCs8aZSoSaEfbY_5wasmi5value3ValINtNtCsaYZPK01V26L_4core7convert4FromNtB5_9WasmValueE4from Line | Count | Source | 1217 | 14.4k | fn from(val: WasmValue) -> Self { | 1218 | 14.4k | match val { | 1219 | 13.8k | WasmValue::I32(v) => wasmi::Val::I32(v), | 1220 | 599 | WasmValue::I64(v) => wasmi::Val::I64(v), | 1221 | | } | 1222 | 14.4k | } |
_RNvXsh_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtNtCs8aZSoSaEfbY_5wasmi5value3ValINtNtCsaYZPK01V26L_4core7convert4FromNtB5_9WasmValueE4from Line | Count | Source | 1217 | 840 | fn from(val: WasmValue) -> Self { | 1218 | 840 | match val { | 1219 | 756 | WasmValue::I32(v) => wasmi::Val::I32(v), | 1220 | 84 | WasmValue::I64(v) => wasmi::Val::I64(v), | 1221 | | } | 1222 | 840 | } |
|
1223 | | } |
1224 | | |
1225 | | #[cfg(all( |
1226 | | any( |
1227 | | all( |
1228 | | target_arch = "x86_64", |
1229 | | any( |
1230 | | target_os = "windows", |
1231 | | all(target_os = "linux", target_env = "gnu"), |
1232 | | target_os = "macos" |
1233 | | ) |
1234 | | ), |
1235 | | all(target_arch = "aarch64", target_os = "linux", target_env = "gnu"), |
1236 | | all(target_arch = "s390x", target_os = "linux", target_env = "gnu") |
1237 | | ), |
1238 | | feature = "wasmtime" |
1239 | | ))] |
1240 | | impl From<WasmValue> for wasmtime::Val { |
1241 | 2.14k | fn from(val: WasmValue) -> Self { |
1242 | 2.14k | match val { |
1243 | 2.14k | WasmValue::I32(v) => wasmtime::Val::I32(v), |
1244 | 0 | WasmValue::I64(v) => wasmtime::Val::I64(v), |
1245 | | } |
1246 | 2.14k | } _RNvXsi_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtNtNtCsc4mtb4KvHAY_8wasmtime7runtime6values3ValINtNtCsaYZPK01V26L_4core7convert4FromNtB5_9WasmValueE4from Line | Count | Source | 1241 | 65 | fn from(val: WasmValue) -> Self { | 1242 | 65 | match val { | 1243 | 65 | WasmValue::I32(v) => wasmtime::Val::I32(v), | 1244 | 0 | WasmValue::I64(v) => wasmtime::Val::I64(v), | 1245 | | } | 1246 | 65 | } |
_RNvXsi_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtNtNtCsc4mtb4KvHAY_8wasmtime7runtime6values3ValINtNtCsaYZPK01V26L_4core7convert4FromNtB5_9WasmValueE4from Line | Count | Source | 1241 | 2.07k | fn from(val: WasmValue) -> Self { | 1242 | 2.07k | match val { | 1243 | 2.07k | WasmValue::I32(v) => wasmtime::Val::I32(v), | 1244 | 0 | WasmValue::I64(v) => wasmtime::Val::I64(v), | 1245 | | } | 1246 | 2.07k | } |
|
1247 | | } |
1248 | | |
1249 | | #[cfg(all( |
1250 | | any( |
1251 | | all( |
1252 | | target_arch = "x86_64", |
1253 | | any( |
1254 | | target_os = "windows", |
1255 | | all(target_os = "linux", target_env = "gnu"), |
1256 | | target_os = "macos" |
1257 | | ) |
1258 | | ), |
1259 | | all(target_arch = "aarch64", target_os = "linux", target_env = "gnu"), |
1260 | | all(target_arch = "s390x", target_os = "linux", target_env = "gnu") |
1261 | | ), |
1262 | | feature = "wasmtime" |
1263 | | ))] |
1264 | | impl<'a> TryFrom<&'a wasmtime::Val> for WasmValue { |
1265 | | type Error = UnsupportedTypeError; |
1266 | | |
1267 | 4.21k | fn try_from(val: &'a wasmtime::Val) -> Result<Self, Self::Error> { |
1268 | 4.21k | match val { |
1269 | 4.18k | wasmtime::Val::I32(v) => Ok(WasmValue::I32(*v)), |
1270 | 24 | wasmtime::Val::I64(v) => Ok(WasmValue::I64(*v)), |
1271 | 0 | _ => Err(UnsupportedTypeError), |
1272 | | } |
1273 | 4.21k | } _RNvXsj_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9WasmValueINtNtCsaYZPK01V26L_4core7convert7TryFromRNtNtNtCsc4mtb4KvHAY_8wasmtime7runtime6values3ValE8try_from Line | Count | Source | 1267 | 59 | fn try_from(val: &'a wasmtime::Val) -> Result<Self, Self::Error> { | 1268 | 59 | match val { | 1269 | 36 | wasmtime::Val::I32(v) => Ok(WasmValue::I32(*v)), | 1270 | 23 | wasmtime::Val::I64(v) => Ok(WasmValue::I64(*v)), | 1271 | 0 | _ => Err(UnsupportedTypeError), | 1272 | | } | 1273 | 59 | } |
_RNvXsj_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9WasmValueINtNtCsaYZPK01V26L_4core7convert7TryFromRNtNtNtCsc4mtb4KvHAY_8wasmtime7runtime6values3ValE8try_from Line | Count | Source | 1267 | 4.15k | fn try_from(val: &'a wasmtime::Val) -> Result<Self, Self::Error> { | 1268 | 4.15k | match val { | 1269 | 4.15k | wasmtime::Val::I32(v) => Ok(WasmValue::I32(*v)), | 1270 | 1 | wasmtime::Val::I64(v) => Ok(WasmValue::I64(*v)), | 1271 | 0 | _ => Err(UnsupportedTypeError), | 1272 | | } | 1273 | 4.15k | } |
|
1274 | | } |
1275 | | |
1276 | | impl From<ValueType> for wasmi::core::ValType { |
1277 | 0 | fn from(ty: ValueType) -> wasmi::core::ValType { |
1278 | 0 | match ty { |
1279 | 0 | ValueType::I32 => wasmi::core::ValType::I32, |
1280 | 0 | ValueType::I64 => wasmi::core::ValType::I64, |
1281 | | } |
1282 | 0 | } Unexecuted instantiation: _RNvXsk_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtNtCsw1RH8GKEuj_10wasmi_core5value7ValTypeINtNtCsaYZPK01V26L_4core7convert4FromNtB5_9ValueTypeE4from Unexecuted instantiation: _RNvXsk_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtNtCsw1RH8GKEuj_10wasmi_core5value7ValTypeINtNtCsaYZPK01V26L_4core7convert4FromNtB5_9ValueTypeE4from |
1283 | | } |
1284 | | |
1285 | | impl TryFrom<wasmi::core::ValType> for ValueType { |
1286 | | type Error = UnsupportedTypeError; |
1287 | | |
1288 | 20.0k | fn try_from(val: wasmi::core::ValType) -> Result<Self, Self::Error> { |
1289 | 20.0k | match val { |
1290 | 16.5k | wasmi::core::ValType::I32 => Ok(ValueType::I32), |
1291 | 3.56k | wasmi::core::ValType::I64 => Ok(ValueType::I64), |
1292 | 2 | _ => Err(UnsupportedTypeError), |
1293 | | } |
1294 | 20.0k | } _RNvXsl_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9ValueTypeINtNtCsaYZPK01V26L_4core7convert7TryFromNtNtCsw1RH8GKEuj_10wasmi_core5value7ValTypeE8try_from Line | Count | Source | 1288 | 15.3k | fn try_from(val: wasmi::core::ValType) -> Result<Self, Self::Error> { | 1289 | 15.3k | match val { | 1290 | 14.1k | wasmi::core::ValType::I32 => Ok(ValueType::I32), | 1291 | 1.15k | wasmi::core::ValType::I64 => Ok(ValueType::I64), | 1292 | 2 | _ => Err(UnsupportedTypeError), | 1293 | | } | 1294 | 15.3k | } |
_RNvXsl_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9ValueTypeINtNtCsaYZPK01V26L_4core7convert7TryFromNtNtCsw1RH8GKEuj_10wasmi_core5value7ValTypeE8try_from Line | Count | Source | 1288 | 4.74k | fn try_from(val: wasmi::core::ValType) -> Result<Self, Self::Error> { | 1289 | 4.74k | match val { | 1290 | 2.33k | wasmi::core::ValType::I32 => Ok(ValueType::I32), | 1291 | 2.41k | wasmi::core::ValType::I64 => Ok(ValueType::I64), | 1292 | 0 | _ => Err(UnsupportedTypeError), | 1293 | | } | 1294 | 4.74k | } |
|
1295 | | } |
1296 | | |
1297 | | #[cfg(all( |
1298 | | any( |
1299 | | all( |
1300 | | target_arch = "x86_64", |
1301 | | any( |
1302 | | target_os = "windows", |
1303 | | all(target_os = "linux", target_env = "gnu"), |
1304 | | target_os = "macos" |
1305 | | ) |
1306 | | ), |
1307 | | all(target_arch = "aarch64", target_os = "linux", target_env = "gnu"), |
1308 | | all(target_arch = "s390x", target_os = "linux", target_env = "gnu") |
1309 | | ), |
1310 | | feature = "wasmtime" |
1311 | | ))] |
1312 | | impl TryFrom<wasmtime::ValType> for ValueType { |
1313 | | type Error = UnsupportedTypeError; |
1314 | | |
1315 | 2.50k | fn try_from(val: wasmtime::ValType) -> Result<Self, Self::Error> { |
1316 | 2.50k | match val { |
1317 | 1.20k | wasmtime::ValType::I32 => Ok(ValueType::I32), |
1318 | 1.29k | wasmtime::ValType::I64 => Ok(ValueType::I64), |
1319 | 2 | _ => Err(UnsupportedTypeError), |
1320 | | } |
1321 | 2.50k | } _RNvXsm_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB5_9ValueTypeINtNtCsaYZPK01V26L_4core7convert7TryFromNtNtNtCsc4mtb4KvHAY_8wasmtime7runtime5types7ValTypeE8try_from Line | Count | Source | 1315 | 611 | fn try_from(val: wasmtime::ValType) -> Result<Self, Self::Error> { | 1316 | 611 | match val { | 1317 | 310 | wasmtime::ValType::I32 => Ok(ValueType::I32), | 1318 | 299 | wasmtime::ValType::I64 => Ok(ValueType::I64), | 1319 | 2 | _ => Err(UnsupportedTypeError), | 1320 | | } | 1321 | 611 | } |
_RNvXsm_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB5_9ValueTypeINtNtCsaYZPK01V26L_4core7convert7TryFromNtNtNtCsc4mtb4KvHAY_8wasmtime7runtime5types7ValTypeE8try_from Line | Count | Source | 1315 | 1.89k | fn try_from(val: wasmtime::ValType) -> Result<Self, Self::Error> { | 1316 | 1.89k | match val { | 1317 | 891 | wasmtime::ValType::I32 => Ok(ValueType::I32), | 1318 | 999 | wasmtime::ValType::I64 => Ok(ValueType::I64), | 1319 | 0 | _ => Err(UnsupportedTypeError), | 1320 | | } | 1321 | 1.89k | } |
|
1322 | | } |
1323 | | |
1324 | | /// Error used in the conversions between VM implementation and the public API. |
1325 | 0 | #[derive(Debug, derive_more::Display)] Unexecuted instantiation: _RNvXs11_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB6_20UnsupportedTypeErrorNtNtCsaYZPK01V26L_4core3fmt7Display3fmt Unexecuted instantiation: _RNvXs11_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB6_20UnsupportedTypeErrorNtNtCsaYZPK01V26L_4core3fmt7Display3fmt |
1326 | | pub struct UnsupportedTypeError; |
1327 | | |
1328 | | /// Outcome of the [`run`](VirtualMachine::run) function. |
1329 | | #[derive(Debug)] |
1330 | | pub enum ExecOutcome { |
1331 | | /// The execution has finished. |
1332 | | /// |
1333 | | /// The state machine is now in a poisoned state, and calling [`run`](VirtualMachine::run) |
1334 | | /// will return [`RunErr::Poisoned`]. |
1335 | | Finished { |
1336 | | /// Return value of the function. |
1337 | | return_value: Result<Option<WasmValue>, Trap>, |
1338 | | }, |
1339 | | |
1340 | | /// The virtual machine has been paused due to a call to a host function. |
1341 | | /// |
1342 | | /// This variant contains the identifier of the host function that is expected to be |
1343 | | /// called, and its parameters. When you call [`run`](VirtualMachine::run) again, you must |
1344 | | /// pass back the outcome of calling that function. |
1345 | | /// |
1346 | | /// > **Note**: The type of the return value of the function is called is not specified, as the |
1347 | | /// > user is supposed to know it based on the identifier. It is an error to call |
1348 | | /// > [`run`](VirtualMachine::run) with a value of the wrong type. |
1349 | | Interrupted { |
1350 | | /// Identifier of the function to call. Corresponds to the value provided at |
1351 | | /// initialization when resolving imports. |
1352 | | id: usize, |
1353 | | |
1354 | | /// Parameters of the function call. |
1355 | | params: Vec<WasmValue>, |
1356 | | }, |
1357 | | } |
1358 | | |
1359 | | /// Opaque error that happened during execution, such as an `unreachable` instruction. |
1360 | 0 | #[derive(Debug, derive_more::Display, Clone)] Unexecuted instantiation: _RNvXs14_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB6_4TrapNtNtCsaYZPK01V26L_4core3fmt7Display3fmt Unexecuted instantiation: _RNvXs14_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB6_4TrapNtNtCsaYZPK01V26L_4core3fmt7Display3fmt |
1361 | | #[display(fmt = "{_0}")] |
1362 | | pub struct Trap(String); |
1363 | | |
1364 | | /// Error that can happen when initializing a [`VirtualMachinePrototype`]. |
1365 | 1 | #[derive(Debug, derive_more::Displa0 y, Clone)] _RNvXs17_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB6_6NewErrNtNtCsaYZPK01V26L_4core3fmt7Display3fmt Line | Count | Source | 1365 | 1 | #[derive(Debug, derive_more::Displa0 y, Clone)] |
Unexecuted instantiation: _RNvXs17_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB6_6NewErrNtNtCsaYZPK01V26L_4core3fmt7Display3fmt |
1366 | | pub enum NewErr { |
1367 | | /// Error while compiling the WebAssembly code. |
1368 | | /// |
1369 | | /// Contains an opaque error message. |
1370 | | #[display(fmt = "{_0}")] |
1371 | | InvalidWasm(String), |
1372 | | /// Error while instantiating the WebAssembly module. |
1373 | | /// |
1374 | | /// Contains an opaque error message. |
1375 | | #[display(fmt = "{_0}")] |
1376 | | Instantiation(String), |
1377 | | /// Failed to resolve a function imported by the module. |
1378 | | #[display(fmt = "Unresolved function `{module_name}`:`{function}`")] |
1379 | | UnresolvedFunctionImport { |
1380 | | /// Name of the function that was unresolved. |
1381 | | function: String, |
1382 | | /// Name of module associated with the unresolved function. |
1383 | | module_name: String, |
1384 | | }, |
1385 | | /// Smoldot doesn't support wasm runtime that have a start function. It is unclear whether |
1386 | | /// this is allowed in the Substrate/Polkadot specification. |
1387 | | #[display(fmt = "Start function not supported")] |
1388 | | // TODO: figure this out |
1389 | | StartFunctionNotSupported, |
1390 | | /// If a "memory" symbol is provided, it must be a memory. |
1391 | | #[display(fmt = "If a \"memory\" symbol is provided, it must be a memory.")] |
1392 | | MemoryIsntMemory, |
1393 | | /// Wasm module imports a memory that isn't named "memory". |
1394 | | MemoryNotNamedMemory, |
1395 | | /// Wasm module doesn't contain any memory. |
1396 | | NoMemory, |
1397 | | /// Wasm module both imports and exports a memory. |
1398 | | TwoMemories, |
1399 | | /// Failed to allocate memory for the virtual machine. |
1400 | | CouldntAllocateMemory, |
1401 | | /// The Wasm module requires importing a global or a table, which isn't supported. |
1402 | | ImportTypeNotSupported, |
1403 | | } |
1404 | | |
1405 | | // TODO: an implementation of the `Error` trait is required in order to interact with wasmtime, but it's not possible to implement this trait on non-std yet |
1406 | | #[cfg(feature = "wasmtime")] |
1407 | | #[cfg_attr(docsrs, doc(cfg(feature = "wasmtime")))] |
1408 | | impl std::error::Error for NewErr {} |
1409 | | |
1410 | | /// Error that can happen when calling [`Prepare::start`]. |
1411 | 0 | #[derive(Debug, Clone, derive_more::Display)] Unexecuted instantiation: _RNvXs1b_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB6_8StartErrNtNtCsaYZPK01V26L_4core3fmt7Display3fmt Unexecuted instantiation: _RNvXs1b_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB6_8StartErrNtNtCsaYZPK01V26L_4core3fmt7Display3fmt |
1412 | | pub enum StartErr { |
1413 | | /// Couldn't find the requested function. |
1414 | | #[display(fmt = "Function to start was not found.")] |
1415 | | FunctionNotFound, |
1416 | | /// The requested function has been found in the list of exports, but it is not a function. |
1417 | | #[display(fmt = "Symbol to start is not a function.")] |
1418 | | NotAFunction, |
1419 | | /// The requested function has a signature that isn't supported. |
1420 | | #[display(fmt = "Function to start uses unsupported signature.")] |
1421 | | SignatureNotSupported, |
1422 | | /// The types of the provided parameters don't match the signature. |
1423 | | #[display(fmt = "The types of the provided parameters don't match the signature.")] |
1424 | | InvalidParameters, |
1425 | | } |
1426 | | |
1427 | | /// Error while reading memory. |
1428 | 0 | #[derive(Debug, derive_more::Display)] Unexecuted instantiation: _RNvXs1d_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB6_16OutOfBoundsErrorNtNtCsaYZPK01V26L_4core3fmt7Display3fmt Unexecuted instantiation: _RNvXs1d_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB6_16OutOfBoundsErrorNtNtCsaYZPK01V26L_4core3fmt7Display3fmt |
1429 | | #[display(fmt = "Out of bounds when accessing virtual machine memory")] |
1430 | | pub struct OutOfBoundsError; |
1431 | | |
1432 | | /// Error that can happen when resuming the execution of a function. |
1433 | 0 | #[derive(Debug, derive_more::Display)] Unexecuted instantiation: _RNvXs1f_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB6_6RunErrNtNtCsaYZPK01V26L_4core3fmt7Display3fmt Unexecuted instantiation: _RNvXs1f_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB6_6RunErrNtNtCsaYZPK01V26L_4core3fmt7Display3fmt |
1434 | | pub enum RunErr { |
1435 | | /// The state machine is poisoned. |
1436 | | #[display(fmt = "State machine is poisoned")] |
1437 | | Poisoned, |
1438 | | /// Passed a wrong value back. |
1439 | | #[display(fmt = "Expected value of type {expected:?} but got {obtained:?} instead")] |
1440 | | BadValueTy { |
1441 | | /// Type of the value that was expected. |
1442 | | expected: Option<ValueType>, |
1443 | | /// Type of the value that was actually passed. |
1444 | | obtained: Option<ValueType>, |
1445 | | }, |
1446 | | } |
1447 | | |
1448 | | /// Error that can happen when calling [`VirtualMachinePrototype::global_value`]. |
1449 | 0 | #[derive(Debug, derive_more::Display)] Unexecuted instantiation: _RNvXs1h_NtNtCsN16ciHI6Qf_7smoldot8executor2vmNtB6_14GlobalValueErrNtNtCsaYZPK01V26L_4core3fmt7Display3fmt Unexecuted instantiation: _RNvXs1h_NtNtCseuYC0Zibziv_7smoldot8executor2vmNtB6_14GlobalValueErrNtNtCsaYZPK01V26L_4core3fmt7Display3fmt |
1450 | | pub enum GlobalValueErr { |
1451 | | /// Couldn't find requested symbol. |
1452 | | NotFound, |
1453 | | /// Requested symbol isn't a `u32`. |
1454 | | Invalid, |
1455 | | } |