/src/wasmer/lib/compiler/src/engine/inner.rs
Line | Count | Source (jump to first uncovered line) |
1 | | //! Universal compilation. |
2 | | |
3 | | use crate::engine::builder::EngineBuilder; |
4 | | #[cfg(not(target_arch = "wasm32"))] |
5 | | use crate::Artifact; |
6 | | #[cfg(not(target_arch = "wasm32"))] |
7 | | use crate::BaseTunables; |
8 | | #[cfg(not(target_arch = "wasm32"))] |
9 | | use crate::CodeMemory; |
10 | | #[cfg(not(target_arch = "wasm32"))] |
11 | | use crate::GlobalFrameInfoRegistration; |
12 | | #[cfg(feature = "compiler")] |
13 | | use crate::{Compiler, CompilerConfig}; |
14 | | #[cfg(not(target_arch = "wasm32"))] |
15 | | use crate::{FunctionExtent, Tunables}; |
16 | | #[cfg(not(target_arch = "wasm32"))] |
17 | | use shared_buffer::OwnedBuffer; |
18 | | #[cfg(not(target_arch = "wasm32"))] |
19 | | use std::path::Path; |
20 | | use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; |
21 | | use std::sync::{Arc, Mutex}; |
22 | | use wasmer_types::HashAlgorithm; |
23 | | #[cfg(not(target_arch = "wasm32"))] |
24 | | use wasmer_types::{ |
25 | | entity::PrimaryMap, DeserializeError, FunctionBodyLike, FunctionIndex, FunctionType, |
26 | | LocalFunctionIndex, SignatureIndex, |
27 | | }; |
28 | | use wasmer_types::{CompileError, Features, ModuleInfo, Target}; |
29 | | #[cfg(not(target_arch = "wasm32"))] |
30 | | use wasmer_types::{CustomSectionLike, CustomSectionProtection, SectionIndex}; |
31 | | #[cfg(not(target_arch = "wasm32"))] |
32 | | use wasmer_vm::{ |
33 | | FunctionBodyPtr, SectionBodyPtr, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex, |
34 | | VMTrampoline, |
35 | | }; |
36 | | |
37 | | /// A WebAssembly `Universal` Engine. |
38 | | #[derive(Clone)] |
39 | | pub struct Engine { |
40 | | inner: Arc<Mutex<EngineInner>>, |
41 | | /// The target for the compiler |
42 | | target: Arc<Target>, |
43 | | engine_id: EngineId, |
44 | | #[cfg(not(target_arch = "wasm32"))] |
45 | | tunables: Arc<dyn Tunables + Send + Sync>, |
46 | | name: String, |
47 | | hash_algorithm: Option<HashAlgorithm>, |
48 | | } |
49 | | |
50 | | impl Engine { |
51 | | /// Create a new `Engine` with the given config |
52 | | #[cfg(feature = "compiler")] |
53 | 27.9k | pub fn new( |
54 | 27.9k | compiler_config: Box<dyn CompilerConfig>, |
55 | 27.9k | target: Target, |
56 | 27.9k | features: Features, |
57 | 27.9k | ) -> Self { |
58 | 27.9k | #[cfg(not(target_arch = "wasm32"))] |
59 | 27.9k | let tunables = BaseTunables::for_target(&target); |
60 | 27.9k | let compiler = compiler_config.compiler(); |
61 | 27.9k | let name = format!("engine-{}", compiler.name()); |
62 | 27.9k | Self { |
63 | 27.9k | inner: Arc::new(Mutex::new(EngineInner { |
64 | 27.9k | compiler: Some(compiler), |
65 | 27.9k | features, |
66 | 27.9k | #[cfg(not(target_arch = "wasm32"))] |
67 | 27.9k | code_memory: vec![], |
68 | 27.9k | #[cfg(not(target_arch = "wasm32"))] |
69 | 27.9k | signatures: SignatureRegistry::new(), |
70 | 27.9k | })), |
71 | 27.9k | target: Arc::new(target), |
72 | 27.9k | engine_id: EngineId::default(), |
73 | 27.9k | #[cfg(not(target_arch = "wasm32"))] |
74 | 27.9k | tunables: Arc::new(tunables), |
75 | 27.9k | name, |
76 | 27.9k | hash_algorithm: None, |
77 | 27.9k | } |
78 | 27.9k | } <wasmer_compiler::engine::inner::Engine>::new Line | Count | Source | 53 | 15.2k | pub fn new( | 54 | 15.2k | compiler_config: Box<dyn CompilerConfig>, | 55 | 15.2k | target: Target, | 56 | 15.2k | features: Features, | 57 | 15.2k | ) -> Self { | 58 | 15.2k | #[cfg(not(target_arch = "wasm32"))] | 59 | 15.2k | let tunables = BaseTunables::for_target(&target); | 60 | 15.2k | let compiler = compiler_config.compiler(); | 61 | 15.2k | let name = format!("engine-{}", compiler.name()); | 62 | 15.2k | Self { | 63 | 15.2k | inner: Arc::new(Mutex::new(EngineInner { | 64 | 15.2k | compiler: Some(compiler), | 65 | 15.2k | features, | 66 | 15.2k | #[cfg(not(target_arch = "wasm32"))] | 67 | 15.2k | code_memory: vec![], | 68 | 15.2k | #[cfg(not(target_arch = "wasm32"))] | 69 | 15.2k | signatures: SignatureRegistry::new(), | 70 | 15.2k | })), | 71 | 15.2k | target: Arc::new(target), | 72 | 15.2k | engine_id: EngineId::default(), | 73 | 15.2k | #[cfg(not(target_arch = "wasm32"))] | 74 | 15.2k | tunables: Arc::new(tunables), | 75 | 15.2k | name, | 76 | 15.2k | hash_algorithm: None, | 77 | 15.2k | } | 78 | 15.2k | } |
<wasmer_compiler::engine::inner::Engine>::new Line | Count | Source | 53 | 12.6k | pub fn new( | 54 | 12.6k | compiler_config: Box<dyn CompilerConfig>, | 55 | 12.6k | target: Target, | 56 | 12.6k | features: Features, | 57 | 12.6k | ) -> Self { | 58 | 12.6k | #[cfg(not(target_arch = "wasm32"))] | 59 | 12.6k | let tunables = BaseTunables::for_target(&target); | 60 | 12.6k | let compiler = compiler_config.compiler(); | 61 | 12.6k | let name = format!("engine-{}", compiler.name()); | 62 | 12.6k | Self { | 63 | 12.6k | inner: Arc::new(Mutex::new(EngineInner { | 64 | 12.6k | compiler: Some(compiler), | 65 | 12.6k | features, | 66 | 12.6k | #[cfg(not(target_arch = "wasm32"))] | 67 | 12.6k | code_memory: vec![], | 68 | 12.6k | #[cfg(not(target_arch = "wasm32"))] | 69 | 12.6k | signatures: SignatureRegistry::new(), | 70 | 12.6k | })), | 71 | 12.6k | target: Arc::new(target), | 72 | 12.6k | engine_id: EngineId::default(), | 73 | 12.6k | #[cfg(not(target_arch = "wasm32"))] | 74 | 12.6k | tunables: Arc::new(tunables), | 75 | 12.6k | name, | 76 | 12.6k | hash_algorithm: None, | 77 | 12.6k | } | 78 | 12.6k | } |
|
79 | | |
80 | | #[cfg(not(feature = "compiler"))] |
81 | | pub fn new( |
82 | | compiler_config: Box<dyn CompilerConfig>, |
83 | | target: Target, |
84 | | features: Features, |
85 | | ) -> Self { |
86 | | panic!("The engine is not compiled with any compiler support") |
87 | | } |
88 | | |
89 | | /// Returns the name of this engine |
90 | 0 | pub fn name(&self) -> &str { |
91 | 0 | self.name.as_str() |
92 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::name Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::name |
93 | | |
94 | | /// Sets the hash algorithm |
95 | 27.9k | pub fn set_hash_algorithm(&mut self, hash_algorithm: Option<HashAlgorithm>) { |
96 | 27.9k | self.hash_algorithm = hash_algorithm; |
97 | 27.9k | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::set_hash_algorithm <wasmer_compiler::engine::inner::Engine>::set_hash_algorithm Line | Count | Source | 95 | 15.2k | pub fn set_hash_algorithm(&mut self, hash_algorithm: Option<HashAlgorithm>) { | 96 | 15.2k | self.hash_algorithm = hash_algorithm; | 97 | 15.2k | } |
Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::set_hash_algorithm <wasmer_compiler::engine::inner::Engine>::set_hash_algorithm Line | Count | Source | 95 | 12.6k | pub fn set_hash_algorithm(&mut self, hash_algorithm: Option<HashAlgorithm>) { | 96 | 12.6k | self.hash_algorithm = hash_algorithm; | 97 | 12.6k | } |
|
98 | | |
99 | | /// Returns the hash algorithm |
100 | 0 | pub fn hash_algorithm(&self) -> Option<HashAlgorithm> { |
101 | 0 | self.hash_algorithm |
102 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::hash_algorithm Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::hash_algorithm |
103 | | |
104 | | /// Returns the deterministic id of this engine |
105 | 0 | pub fn deterministic_id(&self) -> &str { |
106 | 0 | // TODO: add a `deterministic_id` to the Compiler, so two |
107 | 0 | // compilers can actually serialize into a different deterministic_id |
108 | 0 | // if their configuration is different (eg. LLVM with optimizations vs LLVM |
109 | 0 | // without optimizations) |
110 | 0 | self.name.as_str() |
111 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deterministic_id Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deterministic_id |
112 | | |
113 | | /// Create a headless `Engine` |
114 | | /// |
115 | | /// A headless engine is an engine without any compiler attached. |
116 | | /// This is useful for assuring a minimal runtime for running |
117 | | /// WebAssembly modules. |
118 | | /// |
119 | | /// For example, for running in IoT devices where compilers are very |
120 | | /// expensive, or also to optimize startup speed. |
121 | | /// |
122 | | /// # Important |
123 | | /// |
124 | | /// Headless engines can't compile or validate any modules, |
125 | | /// they just take already processed Modules (via `Module::serialize`). |
126 | 0 | pub fn headless() -> Self { |
127 | 0 | let target = Target::default(); |
128 | 0 | #[cfg(not(target_arch = "wasm32"))] |
129 | 0 | let tunables = BaseTunables::for_target(&target); |
130 | 0 | Self { |
131 | 0 | inner: Arc::new(Mutex::new(EngineInner { |
132 | 0 | #[cfg(feature = "compiler")] |
133 | 0 | compiler: None, |
134 | 0 | #[cfg(feature = "compiler")] |
135 | 0 | features: Features::default(), |
136 | 0 | #[cfg(not(target_arch = "wasm32"))] |
137 | 0 | code_memory: vec![], |
138 | 0 | #[cfg(not(target_arch = "wasm32"))] |
139 | 0 | signatures: SignatureRegistry::new(), |
140 | 0 | })), |
141 | 0 | target: Arc::new(target), |
142 | 0 | engine_id: EngineId::default(), |
143 | 0 | #[cfg(not(target_arch = "wasm32"))] |
144 | 0 | tunables: Arc::new(tunables), |
145 | 0 | name: "engine-headless".to_string(), |
146 | 0 | hash_algorithm: None, |
147 | 0 | } |
148 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::headless Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::headless |
149 | | |
150 | | /// Get reference to `EngineInner`. |
151 | 42.9k | pub fn inner(&self) -> std::sync::MutexGuard<'_, EngineInner> { |
152 | 42.9k | self.inner.lock().unwrap() |
153 | 42.9k | } <wasmer_compiler::engine::inner::Engine>::inner Line | Count | Source | 151 | 30.2k | pub fn inner(&self) -> std::sync::MutexGuard<'_, EngineInner> { | 152 | 30.2k | self.inner.lock().unwrap() | 153 | 30.2k | } |
<wasmer_compiler::engine::inner::Engine>::inner Line | Count | Source | 151 | 12.6k | pub fn inner(&self) -> std::sync::MutexGuard<'_, EngineInner> { | 152 | 12.6k | self.inner.lock().unwrap() | 153 | 12.6k | } |
|
154 | | |
155 | | /// Get mutable reference to `EngineInner`. |
156 | 42.4k | pub fn inner_mut(&self) -> std::sync::MutexGuard<'_, EngineInner> { |
157 | 42.4k | self.inner.lock().unwrap() |
158 | 42.4k | } <wasmer_compiler::engine::inner::Engine>::inner_mut Line | Count | Source | 156 | 30.2k | pub fn inner_mut(&self) -> std::sync::MutexGuard<'_, EngineInner> { | 157 | 30.2k | self.inner.lock().unwrap() | 158 | 30.2k | } |
<wasmer_compiler::engine::inner::Engine>::inner_mut Line | Count | Source | 156 | 12.2k | pub fn inner_mut(&self) -> std::sync::MutexGuard<'_, EngineInner> { | 157 | 12.2k | self.inner.lock().unwrap() | 158 | 12.2k | } |
|
159 | | |
160 | | /// Gets the target |
161 | 84.9k | pub fn target(&self) -> &Target { |
162 | 84.9k | &self.target |
163 | 84.9k | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::target <wasmer_compiler::engine::inner::Engine>::target Line | Count | Source | 161 | 60.5k | pub fn target(&self) -> &Target { | 162 | 60.5k | &self.target | 163 | 60.5k | } |
Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::target <wasmer_compiler::engine::inner::Engine>::target Line | Count | Source | 161 | 24.4k | pub fn target(&self) -> &Target { | 162 | 24.4k | &self.target | 163 | 24.4k | } |
|
164 | | |
165 | | /// Register a signature |
166 | | #[cfg(not(target_arch = "wasm32"))] |
167 | 0 | pub fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex { |
168 | 0 | let compiler = self.inner(); |
169 | 0 | compiler.signatures().register(func_type) |
170 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::register_signature Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::register_signature |
171 | | |
172 | | /// Lookup a signature |
173 | | #[cfg(not(target_arch = "wasm32"))] |
174 | 0 | pub fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType> { |
175 | 0 | let compiler = self.inner(); |
176 | 0 | compiler.signatures().lookup(sig) |
177 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::lookup_signature Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::lookup_signature |
178 | | |
179 | | /// Validates a WebAssembly module |
180 | | #[cfg(feature = "compiler")] |
181 | 42.9k | pub fn validate(&self, binary: &[u8]) -> Result<(), CompileError> { |
182 | 42.9k | self.inner().validate(binary) |
183 | 42.9k | } <wasmer_compiler::engine::inner::Engine>::validate Line | Count | Source | 181 | 30.2k | pub fn validate(&self, binary: &[u8]) -> Result<(), CompileError> { | 182 | 30.2k | self.inner().validate(binary) | 183 | 30.2k | } |
<wasmer_compiler::engine::inner::Engine>::validate Line | Count | Source | 181 | 12.6k | pub fn validate(&self, binary: &[u8]) -> Result<(), CompileError> { | 182 | 12.6k | self.inner().validate(binary) | 183 | 12.6k | } |
|
184 | | |
185 | | /// Compile a WebAssembly binary |
186 | | #[cfg(feature = "compiler")] |
187 | | #[cfg(not(target_arch = "wasm32"))] |
188 | 42.4k | pub fn compile(&self, binary: &[u8]) -> Result<Arc<Artifact>, CompileError> { |
189 | 42.4k | Ok(Arc::new(Artifact::new( |
190 | 42.4k | self, |
191 | 42.4k | binary, |
192 | 42.4k | self.tunables.as_ref(), |
193 | 42.4k | self.hash_algorithm, |
194 | 42.4k | )?)) |
195 | 42.4k | } <wasmer_compiler::engine::inner::Engine>::compile Line | Count | Source | 188 | 30.2k | pub fn compile(&self, binary: &[u8]) -> Result<Arc<Artifact>, CompileError> { | 189 | 30.2k | Ok(Arc::new(Artifact::new( | 190 | 30.2k | self, | 191 | 30.2k | binary, | 192 | 30.2k | self.tunables.as_ref(), | 193 | 30.2k | self.hash_algorithm, | 194 | 30.2k | )?)) | 195 | 30.2k | } |
<wasmer_compiler::engine::inner::Engine>::compile Line | Count | Source | 188 | 12.2k | pub fn compile(&self, binary: &[u8]) -> Result<Arc<Artifact>, CompileError> { | 189 | 12.2k | Ok(Arc::new(Artifact::new( | 190 | 12.2k | self, | 191 | 12.2k | binary, | 192 | 12.2k | self.tunables.as_ref(), | 193 | 12.2k | self.hash_algorithm, | 194 | 12.2k | )?)) | 195 | 12.2k | } |
|
196 | | |
197 | | /// Compile a WebAssembly binary |
198 | | #[cfg(not(feature = "compiler"))] |
199 | | #[cfg(not(target_arch = "wasm32"))] |
200 | | pub fn compile( |
201 | | &self, |
202 | | _binary: &[u8], |
203 | | _tunables: &dyn Tunables, |
204 | | ) -> Result<Arc<Artifact>, CompileError> { |
205 | | Err(CompileError::Codegen( |
206 | | "The Engine is operating in headless mode, so it can not compile Modules.".to_string(), |
207 | | )) |
208 | | } |
209 | | |
210 | | #[cfg(not(target_arch = "wasm32"))] |
211 | | /// Deserializes a WebAssembly module which was previously serialized with |
212 | | /// [`Module::serialize`]. |
213 | | /// |
214 | | /// # Safety |
215 | | /// |
216 | | /// See [`Artifact::deserialize_unchecked`]. |
217 | 0 | pub unsafe fn deserialize_unchecked( |
218 | 0 | &self, |
219 | 0 | bytes: OwnedBuffer, |
220 | 0 | ) -> Result<Arc<Artifact>, DeserializeError> { |
221 | 0 | Ok(Arc::new(Artifact::deserialize_unchecked(self, bytes)?)) |
222 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize_unchecked Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize_unchecked |
223 | | |
224 | | /// Deserializes a WebAssembly module which was previously serialized with |
225 | | /// [`Module::serialize`]. |
226 | | /// |
227 | | /// # Safety |
228 | | /// |
229 | | /// See [`Artifact::deserialize`]. |
230 | | #[cfg(not(target_arch = "wasm32"))] |
231 | 0 | pub unsafe fn deserialize( |
232 | 0 | &self, |
233 | 0 | bytes: OwnedBuffer, |
234 | 0 | ) -> Result<Arc<Artifact>, DeserializeError> { |
235 | 0 | Ok(Arc::new(Artifact::deserialize(self, bytes)?)) |
236 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize |
237 | | |
238 | | /// Deserializes a WebAssembly module from a path. |
239 | | /// |
240 | | /// # Safety |
241 | | /// See [`Artifact::deserialize`]. |
242 | | #[cfg(not(target_arch = "wasm32"))] |
243 | 0 | pub unsafe fn deserialize_from_file( |
244 | 0 | &self, |
245 | 0 | file_ref: &Path, |
246 | 0 | ) -> Result<Arc<Artifact>, DeserializeError> { |
247 | 0 | let file = std::fs::File::open(file_ref)?; |
248 | 0 | self.deserialize( |
249 | 0 | OwnedBuffer::from_file(&file).map_err(|e| DeserializeError::Generic(e.to_string()))?, Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize_from_file::{closure#0}Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize_from_file::{closure#0} |
250 | | ) |
251 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize_from_file Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize_from_file |
252 | | |
253 | | /// Deserialize from a file path. |
254 | | /// |
255 | | /// # Safety |
256 | | /// |
257 | | /// See [`Artifact::deserialize_unchecked`]. |
258 | | #[cfg(not(target_arch = "wasm32"))] |
259 | 0 | pub unsafe fn deserialize_from_file_unchecked( |
260 | 0 | &self, |
261 | 0 | file_ref: &Path, |
262 | 0 | ) -> Result<Arc<Artifact>, DeserializeError> { |
263 | 0 | let file = std::fs::File::open(file_ref)?; |
264 | 0 | self.deserialize_unchecked( |
265 | 0 | OwnedBuffer::from_file(&file).map_err(|e| DeserializeError::Generic(e.to_string()))?, Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize_from_file_unchecked::{closure#0}Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize_from_file_unchecked::{closure#0} |
266 | | ) |
267 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize_from_file_unchecked Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::deserialize_from_file_unchecked |
268 | | |
269 | | /// A unique identifier for this object. |
270 | | /// |
271 | | /// This exists to allow us to compare two Engines for equality. Otherwise, |
272 | | /// comparing two trait objects unsafely relies on implementation details |
273 | | /// of trait representation. |
274 | 0 | pub fn id(&self) -> &EngineId { |
275 | 0 | &self.engine_id |
276 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::id Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::id |
277 | | |
278 | | /// Clone the engine |
279 | 0 | pub fn cloned(&self) -> Self { |
280 | 0 | self.clone() |
281 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::cloned Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::cloned |
282 | | |
283 | | /// Attach a Tunable to this engine |
284 | | #[cfg(not(target_arch = "wasm32"))] |
285 | 0 | pub fn set_tunables(&mut self, tunables: impl Tunables + Send + Sync + 'static) { |
286 | 0 | self.tunables = Arc::new(tunables); |
287 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::set_tunables::<wasmer_compiler::engine::tunables::BaseTunables> Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::set_tunables::<_> Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::set_tunables::<wasmer_compiler::engine::tunables::BaseTunables> Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::set_tunables::<_> |
288 | | |
289 | | /// Get a reference to attached Tunable of this engine |
290 | | #[cfg(not(target_arch = "wasm32"))] |
291 | 24.8k | pub fn tunables(&self) -> &dyn Tunables { |
292 | 24.8k | self.tunables.as_ref() |
293 | 24.8k | } <wasmer_compiler::engine::inner::Engine>::tunables Line | Count | Source | 291 | 428 | pub fn tunables(&self) -> &dyn Tunables { | 292 | 428 | self.tunables.as_ref() | 293 | 428 | } |
Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::tunables Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::tunables <wasmer_compiler::engine::inner::Engine>::tunables Line | Count | Source | 291 | 24.4k | pub fn tunables(&self) -> &dyn Tunables { | 292 | 24.4k | self.tunables.as_ref() | 293 | 24.4k | } |
Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::tunables Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::tunables Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::tunables Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine>::tunables |
294 | | } |
295 | | |
296 | | impl std::fmt::Debug for Engine { |
297 | 0 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
298 | 0 | f.debug_struct("Engine") |
299 | 0 | .field("target", &self.target) |
300 | 0 | .field("engine_id", &self.engine_id) |
301 | 0 | .field("name", &self.name) |
302 | 0 | .finish() |
303 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine as core::fmt::Debug>::fmt Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine as core::fmt::Debug>::fmt |
304 | | } |
305 | | |
306 | | /// The inner contents of `Engine` |
307 | | pub struct EngineInner { |
308 | | #[cfg(feature = "compiler")] |
309 | | /// The compiler and cpu features |
310 | | compiler: Option<Box<dyn Compiler>>, |
311 | | #[cfg(feature = "compiler")] |
312 | | /// The compiler and cpu features |
313 | | features: Features, |
314 | | /// The code memory is responsible of publishing the compiled |
315 | | /// functions to memory. |
316 | | #[cfg(not(target_arch = "wasm32"))] |
317 | | code_memory: Vec<CodeMemory>, |
318 | | /// The signature registry is used mainly to operate with trampolines |
319 | | /// performantly. |
320 | | #[cfg(not(target_arch = "wasm32"))] |
321 | | signatures: SignatureRegistry, |
322 | | } |
323 | | |
324 | | impl EngineInner { |
325 | | /// Gets the compiler associated to this engine. |
326 | | #[cfg(feature = "compiler")] |
327 | 85.3k | pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> { |
328 | 85.3k | match self.compiler.as_ref() { |
329 | 0 | None => Err(CompileError::Codegen( |
330 | 0 | "No compiler compiled into executable".to_string(), |
331 | 0 | )), |
332 | 85.3k | Some(compiler) => Ok(&**compiler), |
333 | | } |
334 | 85.3k | } <wasmer_compiler::engine::inner::EngineInner>::compiler Line | Count | Source | 327 | 60.5k | pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> { | 328 | 60.5k | match self.compiler.as_ref() { | 329 | 0 | None => Err(CompileError::Codegen( | 330 | 0 | "No compiler compiled into executable".to_string(), | 331 | 0 | )), | 332 | 60.5k | Some(compiler) => Ok(&**compiler), | 333 | | } | 334 | 60.5k | } |
<wasmer_compiler::engine::inner::EngineInner>::compiler Line | Count | Source | 327 | 24.8k | pub fn compiler(&self) -> Result<&dyn Compiler, CompileError> { | 328 | 24.8k | match self.compiler.as_ref() { | 329 | 0 | None => Err(CompileError::Codegen( | 330 | 0 | "No compiler compiled into executable".to_string(), | 331 | 0 | )), | 332 | 24.8k | Some(compiler) => Ok(&**compiler), | 333 | | } | 334 | 24.8k | } |
|
335 | | |
336 | | /// Validate the module |
337 | | #[cfg(feature = "compiler")] |
338 | 42.9k | pub fn validate(&self, data: &[u8]) -> Result<(), CompileError> { |
339 | 42.9k | let compiler = self.compiler()?; |
340 | 42.9k | compiler.validate_module(&self.features, data) |
341 | 42.9k | } <wasmer_compiler::engine::inner::EngineInner>::validate Line | Count | Source | 338 | 30.2k | pub fn validate(&self, data: &[u8]) -> Result<(), CompileError> { | 339 | 30.2k | let compiler = self.compiler()?; | 340 | 30.2k | compiler.validate_module(&self.features, data) | 341 | 30.2k | } |
<wasmer_compiler::engine::inner::EngineInner>::validate Line | Count | Source | 338 | 12.6k | pub fn validate(&self, data: &[u8]) -> Result<(), CompileError> { | 339 | 12.6k | let compiler = self.compiler()?; | 340 | 12.6k | compiler.validate_module(&self.features, data) | 341 | 12.6k | } |
|
342 | | |
343 | | /// The Wasm features |
344 | | #[cfg(feature = "compiler")] |
345 | 42.4k | pub fn features(&self) -> &Features { |
346 | 42.4k | &self.features |
347 | 42.4k | } <wasmer_compiler::engine::inner::EngineInner>::features Line | Count | Source | 345 | 30.2k | pub fn features(&self) -> &Features { | 346 | 30.2k | &self.features | 347 | 30.2k | } |
<wasmer_compiler::engine::inner::EngineInner>::features Line | Count | Source | 345 | 12.2k | pub fn features(&self) -> &Features { | 346 | 12.2k | &self.features | 347 | 12.2k | } |
|
348 | | |
349 | | /// Allocate compiled functions into memory |
350 | | #[cfg(not(target_arch = "wasm32"))] |
351 | | #[allow(clippy::type_complexity)] |
352 | 42.4k | pub(crate) fn allocate<'a, FunctionBody, CustomSection>( |
353 | 42.4k | &'a mut self, |
354 | 42.4k | _module: &ModuleInfo, |
355 | 42.4k | functions: impl ExactSizeIterator<Item = &'a FunctionBody> + 'a, |
356 | 42.4k | function_call_trampolines: impl ExactSizeIterator<Item = &'a FunctionBody> + 'a, |
357 | 42.4k | dynamic_function_trampolines: impl ExactSizeIterator<Item = &'a FunctionBody> + 'a, |
358 | 42.4k | custom_sections: impl ExactSizeIterator<Item = &'a CustomSection> + Clone + 'a, |
359 | 42.4k | ) -> Result< |
360 | 42.4k | ( |
361 | 42.4k | PrimaryMap<LocalFunctionIndex, FunctionExtent>, |
362 | 42.4k | PrimaryMap<SignatureIndex, VMTrampoline>, |
363 | 42.4k | PrimaryMap<FunctionIndex, FunctionBodyPtr>, |
364 | 42.4k | PrimaryMap<SectionIndex, SectionBodyPtr>, |
365 | 42.4k | ), |
366 | 42.4k | CompileError, |
367 | 42.4k | > |
368 | 42.4k | where |
369 | 42.4k | FunctionBody: FunctionBodyLike<'a> + 'a, |
370 | 42.4k | CustomSection: CustomSectionLike<'a> + 'a, |
371 | 42.4k | { |
372 | 42.4k | let functions_len = functions.len(); |
373 | 42.4k | let function_call_trampolines_len = function_call_trampolines.len(); |
374 | 42.4k | |
375 | 42.4k | let function_bodies = functions |
376 | 42.4k | .chain(function_call_trampolines) |
377 | 42.4k | .chain(dynamic_function_trampolines) |
378 | 42.4k | .collect::<Vec<_>>(); |
379 | 42.4k | let (executable_sections, data_sections): (Vec<_>, _) = custom_sections |
380 | 42.4k | .clone() |
381 | 190k | .partition(|section| *section.protection() == CustomSectionProtection::ReadExecute); <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#0}Line | Count | Source | 381 | 167k | .partition(|section| *section.protection() == CustomSectionProtection::ReadExecute); |
Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#0}<wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#0}Line | Count | Source | 381 | 23.5k | .partition(|section| *section.protection() == CustomSectionProtection::ReadExecute); |
Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#0} |
382 | 42.4k | self.code_memory.push(CodeMemory::new()); |
383 | | |
384 | 42.4k | let (mut allocated_functions, allocated_executable_sections, allocated_data_sections) = |
385 | 42.4k | self.code_memory |
386 | 42.4k | .last_mut() |
387 | 42.4k | .unwrap() |
388 | 42.4k | .allocate( |
389 | 42.4k | function_bodies.as_slice(), |
390 | 42.4k | executable_sections.as_slice(), |
391 | 42.4k | data_sections.as_slice(), |
392 | 42.4k | ) |
393 | 42.4k | .map_err(|message| { |
394 | 0 | CompileError::Resource(format!( |
395 | 0 | "failed to allocate memory for functions: {}", |
396 | 0 | message |
397 | 0 | )) |
398 | 42.4k | })?; Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#1}Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#1}Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#1}Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#1} |
399 | | |
400 | 42.4k | let allocated_functions_result = allocated_functions |
401 | 42.4k | .drain(0..functions_len) |
402 | 471k | .map(|slice| FunctionExtent { |
403 | 471k | ptr: FunctionBodyPtr(slice.as_ptr()), |
404 | 471k | length: slice.len(), |
405 | 471k | }) <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#2}Line | Count | Source | 402 | 277k | .map(|slice| FunctionExtent { | 403 | 277k | ptr: FunctionBodyPtr(slice.as_ptr()), | 404 | 277k | length: slice.len(), | 405 | 277k | }) |
Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#2}<wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#2}Line | Count | Source | 402 | 193k | .map(|slice| FunctionExtent { | 403 | 193k | ptr: FunctionBodyPtr(slice.as_ptr()), | 404 | 193k | length: slice.len(), | 405 | 193k | }) |
Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#2} |
406 | 42.4k | .collect::<PrimaryMap<LocalFunctionIndex, _>>(); |
407 | 42.4k | |
408 | 42.4k | let mut allocated_function_call_trampolines: PrimaryMap<SignatureIndex, VMTrampoline> = |
409 | 42.4k | PrimaryMap::new(); |
410 | 179k | for ptr in allocated_functions |
411 | 42.4k | .drain(0..function_call_trampolines_len) |
412 | 179k | .map(|slice| slice.as_ptr()) <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#3}Line | Count | Source | 412 | 160k | .map(|slice| slice.as_ptr()) |
Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#3}<wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#3}Line | Count | Source | 412 | 18.8k | .map(|slice| slice.as_ptr()) |
Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#3} |
413 | 179k | { |
414 | 179k | let trampoline = |
415 | 179k | unsafe { std::mem::transmute::<*const VMFunctionBody, VMTrampoline>(ptr) }; |
416 | 179k | allocated_function_call_trampolines.push(trampoline); |
417 | 179k | } |
418 | | |
419 | 42.4k | let allocated_dynamic_function_trampolines = allocated_functions |
420 | 42.4k | .drain(..) |
421 | 42.4k | .map(|slice| FunctionBodyPtr(slice.as_ptr())) Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#4}Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#4}Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#4}Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#4} |
422 | 42.4k | .collect::<PrimaryMap<FunctionIndex, _>>(); |
423 | 42.4k | |
424 | 42.4k | let mut exec_iter = allocated_executable_sections.iter(); |
425 | 42.4k | let mut data_iter = allocated_data_sections.iter(); |
426 | 42.4k | let allocated_custom_sections = custom_sections |
427 | 190k | .map(|section| { |
428 | 190k | SectionBodyPtr( |
429 | 190k | if *section.protection() == CustomSectionProtection::ReadExecute { |
430 | 42.4k | exec_iter.next() |
431 | | } else { |
432 | 148k | data_iter.next() |
433 | | } |
434 | 190k | .unwrap() |
435 | 190k | .as_ptr(), |
436 | 190k | ) |
437 | 190k | }) <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#5}Line | Count | Source | 427 | 167k | .map(|section| { | 428 | 167k | SectionBodyPtr( | 429 | 167k | if *section.protection() == CustomSectionProtection::ReadExecute { | 430 | 30.2k | exec_iter.next() | 431 | | } else { | 432 | 137k | data_iter.next() | 433 | | } | 434 | 167k | .unwrap() | 435 | 167k | .as_ptr(), | 436 | 167k | ) | 437 | 167k | }) |
Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#5}<wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>>::{closure#5}Line | Count | Source | 427 | 23.5k | .map(|section| { | 428 | 23.5k | SectionBodyPtr( | 429 | 23.5k | if *section.protection() == CustomSectionProtection::ReadExecute { | 430 | 12.2k | exec_iter.next() | 431 | | } else { | 432 | 11.3k | data_iter.next() | 433 | | } | 434 | 23.5k | .unwrap() | 435 | 23.5k | .as_ptr(), | 436 | 23.5k | ) | 437 | 23.5k | }) |
Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>>::{closure#5} |
438 | 42.4k | .collect::<PrimaryMap<SectionIndex, _>>(); |
439 | 42.4k | |
440 | 42.4k | Ok(( |
441 | 42.4k | allocated_functions_result, |
442 | 42.4k | allocated_function_call_trampolines, |
443 | 42.4k | allocated_dynamic_function_trampolines, |
444 | 42.4k | allocated_custom_sections, |
445 | 42.4k | )) |
446 | 42.4k | } <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>> Line | Count | Source | 352 | 30.2k | pub(crate) fn allocate<'a, FunctionBody, CustomSection>( | 353 | 30.2k | &'a mut self, | 354 | 30.2k | _module: &ModuleInfo, | 355 | 30.2k | functions: impl ExactSizeIterator<Item = &'a FunctionBody> + 'a, | 356 | 30.2k | function_call_trampolines: impl ExactSizeIterator<Item = &'a FunctionBody> + 'a, | 357 | 30.2k | dynamic_function_trampolines: impl ExactSizeIterator<Item = &'a FunctionBody> + 'a, | 358 | 30.2k | custom_sections: impl ExactSizeIterator<Item = &'a CustomSection> + Clone + 'a, | 359 | 30.2k | ) -> Result< | 360 | 30.2k | ( | 361 | 30.2k | PrimaryMap<LocalFunctionIndex, FunctionExtent>, | 362 | 30.2k | PrimaryMap<SignatureIndex, VMTrampoline>, | 363 | 30.2k | PrimaryMap<FunctionIndex, FunctionBodyPtr>, | 364 | 30.2k | PrimaryMap<SectionIndex, SectionBodyPtr>, | 365 | 30.2k | ), | 366 | 30.2k | CompileError, | 367 | 30.2k | > | 368 | 30.2k | where | 369 | 30.2k | FunctionBody: FunctionBodyLike<'a> + 'a, | 370 | 30.2k | CustomSection: CustomSectionLike<'a> + 'a, | 371 | 30.2k | { | 372 | 30.2k | let functions_len = functions.len(); | 373 | 30.2k | let function_call_trampolines_len = function_call_trampolines.len(); | 374 | 30.2k | | 375 | 30.2k | let function_bodies = functions | 376 | 30.2k | .chain(function_call_trampolines) | 377 | 30.2k | .chain(dynamic_function_trampolines) | 378 | 30.2k | .collect::<Vec<_>>(); | 379 | 30.2k | let (executable_sections, data_sections): (Vec<_>, _) = custom_sections | 380 | 30.2k | .clone() | 381 | 30.2k | .partition(|section| *section.protection() == CustomSectionProtection::ReadExecute); | 382 | 30.2k | self.code_memory.push(CodeMemory::new()); | 383 | | | 384 | 30.2k | let (mut allocated_functions, allocated_executable_sections, allocated_data_sections) = | 385 | 30.2k | self.code_memory | 386 | 30.2k | .last_mut() | 387 | 30.2k | .unwrap() | 388 | 30.2k | .allocate( | 389 | 30.2k | function_bodies.as_slice(), | 390 | 30.2k | executable_sections.as_slice(), | 391 | 30.2k | data_sections.as_slice(), | 392 | 30.2k | ) | 393 | 30.2k | .map_err(|message| { | 394 | | CompileError::Resource(format!( | 395 | | "failed to allocate memory for functions: {}", | 396 | | message | 397 | | )) | 398 | 30.2k | })?; | 399 | | | 400 | 30.2k | let allocated_functions_result = allocated_functions | 401 | 30.2k | .drain(0..functions_len) | 402 | 30.2k | .map(|slice| FunctionExtent { | 403 | | ptr: FunctionBodyPtr(slice.as_ptr()), | 404 | | length: slice.len(), | 405 | 30.2k | }) | 406 | 30.2k | .collect::<PrimaryMap<LocalFunctionIndex, _>>(); | 407 | 30.2k | | 408 | 30.2k | let mut allocated_function_call_trampolines: PrimaryMap<SignatureIndex, VMTrampoline> = | 409 | 30.2k | PrimaryMap::new(); | 410 | 160k | for ptr in allocated_functions | 411 | 30.2k | .drain(0..function_call_trampolines_len) | 412 | 30.2k | .map(|slice| slice.as_ptr()) | 413 | 160k | { | 414 | 160k | let trampoline = | 415 | 160k | unsafe { std::mem::transmute::<*const VMFunctionBody, VMTrampoline>(ptr) }; | 416 | 160k | allocated_function_call_trampolines.push(trampoline); | 417 | 160k | } | 418 | | | 419 | 30.2k | let allocated_dynamic_function_trampolines = allocated_functions | 420 | 30.2k | .drain(..) | 421 | 30.2k | .map(|slice| FunctionBodyPtr(slice.as_ptr())) | 422 | 30.2k | .collect::<PrimaryMap<FunctionIndex, _>>(); | 423 | 30.2k | | 424 | 30.2k | let mut exec_iter = allocated_executable_sections.iter(); | 425 | 30.2k | let mut data_iter = allocated_data_sections.iter(); | 426 | 30.2k | let allocated_custom_sections = custom_sections | 427 | 30.2k | .map(|section| { | 428 | | SectionBodyPtr( | 429 | | if *section.protection() == CustomSectionProtection::ReadExecute { | 430 | | exec_iter.next() | 431 | | } else { | 432 | | data_iter.next() | 433 | | } | 434 | | .unwrap() | 435 | | .as_ptr(), | 436 | | ) | 437 | 30.2k | }) | 438 | 30.2k | .collect::<PrimaryMap<SectionIndex, _>>(); | 439 | 30.2k | | 440 | 30.2k | Ok(( | 441 | 30.2k | allocated_functions_result, | 442 | 30.2k | allocated_function_call_trampolines, | 443 | 30.2k | allocated_dynamic_function_trampolines, | 444 | 30.2k | allocated_custom_sections, | 445 | 30.2k | )) | 446 | 30.2k | } |
Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>> <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::FunctionBody, wasmer_types::compilation::section::CustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::FunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::CustomSection>> Line | Count | Source | 352 | 12.2k | pub(crate) fn allocate<'a, FunctionBody, CustomSection>( | 353 | 12.2k | &'a mut self, | 354 | 12.2k | _module: &ModuleInfo, | 355 | 12.2k | functions: impl ExactSizeIterator<Item = &'a FunctionBody> + 'a, | 356 | 12.2k | function_call_trampolines: impl ExactSizeIterator<Item = &'a FunctionBody> + 'a, | 357 | 12.2k | dynamic_function_trampolines: impl ExactSizeIterator<Item = &'a FunctionBody> + 'a, | 358 | 12.2k | custom_sections: impl ExactSizeIterator<Item = &'a CustomSection> + Clone + 'a, | 359 | 12.2k | ) -> Result< | 360 | 12.2k | ( | 361 | 12.2k | PrimaryMap<LocalFunctionIndex, FunctionExtent>, | 362 | 12.2k | PrimaryMap<SignatureIndex, VMTrampoline>, | 363 | 12.2k | PrimaryMap<FunctionIndex, FunctionBodyPtr>, | 364 | 12.2k | PrimaryMap<SectionIndex, SectionBodyPtr>, | 365 | 12.2k | ), | 366 | 12.2k | CompileError, | 367 | 12.2k | > | 368 | 12.2k | where | 369 | 12.2k | FunctionBody: FunctionBodyLike<'a> + 'a, | 370 | 12.2k | CustomSection: CustomSectionLike<'a> + 'a, | 371 | 12.2k | { | 372 | 12.2k | let functions_len = functions.len(); | 373 | 12.2k | let function_call_trampolines_len = function_call_trampolines.len(); | 374 | 12.2k | | 375 | 12.2k | let function_bodies = functions | 376 | 12.2k | .chain(function_call_trampolines) | 377 | 12.2k | .chain(dynamic_function_trampolines) | 378 | 12.2k | .collect::<Vec<_>>(); | 379 | 12.2k | let (executable_sections, data_sections): (Vec<_>, _) = custom_sections | 380 | 12.2k | .clone() | 381 | 12.2k | .partition(|section| *section.protection() == CustomSectionProtection::ReadExecute); | 382 | 12.2k | self.code_memory.push(CodeMemory::new()); | 383 | | | 384 | 12.2k | let (mut allocated_functions, allocated_executable_sections, allocated_data_sections) = | 385 | 12.2k | self.code_memory | 386 | 12.2k | .last_mut() | 387 | 12.2k | .unwrap() | 388 | 12.2k | .allocate( | 389 | 12.2k | function_bodies.as_slice(), | 390 | 12.2k | executable_sections.as_slice(), | 391 | 12.2k | data_sections.as_slice(), | 392 | 12.2k | ) | 393 | 12.2k | .map_err(|message| { | 394 | | CompileError::Resource(format!( | 395 | | "failed to allocate memory for functions: {}", | 396 | | message | 397 | | )) | 398 | 12.2k | })?; | 399 | | | 400 | 12.2k | let allocated_functions_result = allocated_functions | 401 | 12.2k | .drain(0..functions_len) | 402 | 12.2k | .map(|slice| FunctionExtent { | 403 | | ptr: FunctionBodyPtr(slice.as_ptr()), | 404 | | length: slice.len(), | 405 | 12.2k | }) | 406 | 12.2k | .collect::<PrimaryMap<LocalFunctionIndex, _>>(); | 407 | 12.2k | | 408 | 12.2k | let mut allocated_function_call_trampolines: PrimaryMap<SignatureIndex, VMTrampoline> = | 409 | 12.2k | PrimaryMap::new(); | 410 | 18.8k | for ptr in allocated_functions | 411 | 12.2k | .drain(0..function_call_trampolines_len) | 412 | 12.2k | .map(|slice| slice.as_ptr()) | 413 | 18.8k | { | 414 | 18.8k | let trampoline = | 415 | 18.8k | unsafe { std::mem::transmute::<*const VMFunctionBody, VMTrampoline>(ptr) }; | 416 | 18.8k | allocated_function_call_trampolines.push(trampoline); | 417 | 18.8k | } | 418 | | | 419 | 12.2k | let allocated_dynamic_function_trampolines = allocated_functions | 420 | 12.2k | .drain(..) | 421 | 12.2k | .map(|slice| FunctionBodyPtr(slice.as_ptr())) | 422 | 12.2k | .collect::<PrimaryMap<FunctionIndex, _>>(); | 423 | 12.2k | | 424 | 12.2k | let mut exec_iter = allocated_executable_sections.iter(); | 425 | 12.2k | let mut data_iter = allocated_data_sections.iter(); | 426 | 12.2k | let allocated_custom_sections = custom_sections | 427 | 12.2k | .map(|section| { | 428 | | SectionBodyPtr( | 429 | | if *section.protection() == CustomSectionProtection::ReadExecute { | 430 | | exec_iter.next() | 431 | | } else { | 432 | | data_iter.next() | 433 | | } | 434 | | .unwrap() | 435 | | .as_ptr(), | 436 | | ) | 437 | 12.2k | }) | 438 | 12.2k | .collect::<PrimaryMap<SectionIndex, _>>(); | 439 | 12.2k | | 440 | 12.2k | Ok(( | 441 | 12.2k | allocated_functions_result, | 442 | 12.2k | allocated_function_call_trampolines, | 443 | 12.2k | allocated_dynamic_function_trampolines, | 444 | 12.2k | allocated_custom_sections, | 445 | 12.2k | )) | 446 | 12.2k | } |
Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::allocate::<wasmer_types::compilation::function::ArchivedFunctionBody, wasmer_types::compilation::section::ArchivedCustomSection, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::function::ArchivedFunctionBody>, core::slice::iter::Iter<wasmer_types::compilation::section::ArchivedCustomSection>> |
447 | | |
448 | | #[cfg(not(target_arch = "wasm32"))] |
449 | | /// Make memory containing compiled code executable. |
450 | 42.4k | pub(crate) fn publish_compiled_code(&mut self) { |
451 | 42.4k | self.code_memory.last_mut().unwrap().publish(); |
452 | 42.4k | } <wasmer_compiler::engine::inner::EngineInner>::publish_compiled_code Line | Count | Source | 450 | 30.2k | pub(crate) fn publish_compiled_code(&mut self) { | 451 | 30.2k | self.code_memory.last_mut().unwrap().publish(); | 452 | 30.2k | } |
<wasmer_compiler::engine::inner::EngineInner>::publish_compiled_code Line | Count | Source | 450 | 12.2k | pub(crate) fn publish_compiled_code(&mut self) { | 451 | 12.2k | self.code_memory.last_mut().unwrap().publish(); | 452 | 12.2k | } |
|
453 | | |
454 | | #[cfg(not(target_arch = "wasm32"))] |
455 | | /// Register DWARF-type exception handling information associated with the code. |
456 | 42.4k | pub(crate) fn publish_eh_frame(&mut self, eh_frame: Option<&[u8]>) -> Result<(), CompileError> { |
457 | 42.4k | self.code_memory |
458 | 42.4k | .last_mut() |
459 | 42.4k | .unwrap() |
460 | 42.4k | .unwind_registry_mut() |
461 | 42.4k | .publish(eh_frame) |
462 | 42.4k | .map_err(|e| { |
463 | 0 | CompileError::Resource(format!("Error while publishing the unwind code: {}", e)) |
464 | 42.4k | })?; Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::publish_eh_frame::{closure#0}Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineInner>::publish_eh_frame::{closure#0} |
465 | 42.4k | Ok(()) |
466 | 42.4k | } <wasmer_compiler::engine::inner::EngineInner>::publish_eh_frame Line | Count | Source | 456 | 30.2k | pub(crate) fn publish_eh_frame(&mut self, eh_frame: Option<&[u8]>) -> Result<(), CompileError> { | 457 | 30.2k | self.code_memory | 458 | 30.2k | .last_mut() | 459 | 30.2k | .unwrap() | 460 | 30.2k | .unwind_registry_mut() | 461 | 30.2k | .publish(eh_frame) | 462 | 30.2k | .map_err(|e| { | 463 | | CompileError::Resource(format!("Error while publishing the unwind code: {}", e)) | 464 | 30.2k | })?; | 465 | 30.2k | Ok(()) | 466 | 30.2k | } |
<wasmer_compiler::engine::inner::EngineInner>::publish_eh_frame Line | Count | Source | 456 | 12.2k | pub(crate) fn publish_eh_frame(&mut self, eh_frame: Option<&[u8]>) -> Result<(), CompileError> { | 457 | 12.2k | self.code_memory | 458 | 12.2k | .last_mut() | 459 | 12.2k | .unwrap() | 460 | 12.2k | .unwind_registry_mut() | 461 | 12.2k | .publish(eh_frame) | 462 | 12.2k | .map_err(|e| { | 463 | | CompileError::Resource(format!("Error while publishing the unwind code: {}", e)) | 464 | 12.2k | })?; | 465 | 12.2k | Ok(()) | 466 | 12.2k | } |
|
467 | | |
468 | | /// Shared signature registry. |
469 | | #[cfg(not(target_arch = "wasm32"))] |
470 | 42.4k | pub fn signatures(&self) -> &SignatureRegistry { |
471 | 42.4k | &self.signatures |
472 | 42.4k | } <wasmer_compiler::engine::inner::EngineInner>::signatures Line | Count | Source | 470 | 30.2k | pub fn signatures(&self) -> &SignatureRegistry { | 471 | 30.2k | &self.signatures | 472 | 30.2k | } |
<wasmer_compiler::engine::inner::EngineInner>::signatures Line | Count | Source | 470 | 12.2k | pub fn signatures(&self) -> &SignatureRegistry { | 471 | 12.2k | &self.signatures | 472 | 12.2k | } |
|
473 | | |
474 | | #[cfg(not(target_arch = "wasm32"))] |
475 | | /// Register the frame info for the code memory |
476 | 37.1k | pub(crate) fn register_frame_info(&mut self, frame_info: GlobalFrameInfoRegistration) { |
477 | 37.1k | self.code_memory |
478 | 37.1k | .last_mut() |
479 | 37.1k | .unwrap() |
480 | 37.1k | .register_frame_info(frame_info); |
481 | 37.1k | } <wasmer_compiler::engine::inner::EngineInner>::register_frame_info Line | Count | Source | 476 | 25.7k | pub(crate) fn register_frame_info(&mut self, frame_info: GlobalFrameInfoRegistration) { | 477 | 25.7k | self.code_memory | 478 | 25.7k | .last_mut() | 479 | 25.7k | .unwrap() | 480 | 25.7k | .register_frame_info(frame_info); | 481 | 25.7k | } |
<wasmer_compiler::engine::inner::EngineInner>::register_frame_info Line | Count | Source | 476 | 11.3k | pub(crate) fn register_frame_info(&mut self, frame_info: GlobalFrameInfoRegistration) { | 477 | 11.3k | self.code_memory | 478 | 11.3k | .last_mut() | 479 | 11.3k | .unwrap() | 480 | 11.3k | .register_frame_info(frame_info); | 481 | 11.3k | } |
|
482 | | } |
483 | | |
484 | | #[cfg(feature = "compiler")] |
485 | | impl From<Box<dyn CompilerConfig>> for Engine { |
486 | 0 | fn from(config: Box<dyn CompilerConfig>) -> Self { |
487 | 0 | EngineBuilder::new(config).engine() |
488 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine as core::convert::From<alloc::boxed::Box<dyn wasmer_compiler::compiler::CompilerConfig>>>::from Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine as core::convert::From<alloc::boxed::Box<dyn wasmer_compiler::compiler::CompilerConfig>>>::from |
489 | | } |
490 | | |
491 | | impl From<EngineBuilder> for Engine { |
492 | 0 | fn from(engine_builder: EngineBuilder) -> Self { |
493 | 0 | engine_builder.engine() |
494 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine as core::convert::From<wasmer_compiler::engine::builder::EngineBuilder>>::from Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine as core::convert::From<wasmer_compiler::engine::builder::EngineBuilder>>::from |
495 | | } |
496 | | |
497 | | impl From<&Self> for Engine { |
498 | 0 | fn from(engine_ref: &Self) -> Self { |
499 | 0 | engine_ref.cloned() |
500 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine as core::convert::From<&wasmer_compiler::engine::inner::Engine>>::from Unexecuted instantiation: <wasmer_compiler::engine::inner::Engine as core::convert::From<&wasmer_compiler::engine::inner::Engine>>::from |
501 | | } |
502 | | |
503 | | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] |
504 | | #[repr(transparent)] |
505 | | /// A unique identifier for an Engine. |
506 | | pub struct EngineId { |
507 | | id: usize, |
508 | | } |
509 | | |
510 | | impl EngineId { |
511 | | /// Format this identifier as a string. |
512 | 0 | pub fn id(&self) -> String { |
513 | 0 | format!("{}", &self.id) |
514 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineId>::id Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineId>::id |
515 | | } |
516 | | |
517 | | impl Clone for EngineId { |
518 | 0 | fn clone(&self) -> Self { |
519 | 0 | Self::default() |
520 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineId as core::clone::Clone>::clone Unexecuted instantiation: <wasmer_compiler::engine::inner::EngineId as core::clone::Clone>::clone |
521 | | } |
522 | | |
523 | | impl Default for EngineId { |
524 | 27.9k | fn default() -> Self { |
525 | 27.9k | static NEXT_ID: AtomicUsize = AtomicUsize::new(0); |
526 | 27.9k | Self { |
527 | 27.9k | id: NEXT_ID.fetch_add(1, SeqCst), |
528 | 27.9k | } |
529 | 27.9k | } <wasmer_compiler::engine::inner::EngineId as core::default::Default>::default Line | Count | Source | 524 | 15.2k | fn default() -> Self { | 525 | 15.2k | static NEXT_ID: AtomicUsize = AtomicUsize::new(0); | 526 | 15.2k | Self { | 527 | 15.2k | id: NEXT_ID.fetch_add(1, SeqCst), | 528 | 15.2k | } | 529 | 15.2k | } |
<wasmer_compiler::engine::inner::EngineId as core::default::Default>::default Line | Count | Source | 524 | 12.6k | fn default() -> Self { | 525 | 12.6k | static NEXT_ID: AtomicUsize = AtomicUsize::new(0); | 526 | 12.6k | Self { | 527 | 12.6k | id: NEXT_ID.fetch_add(1, SeqCst), | 528 | 12.6k | } | 529 | 12.6k | } |
|
530 | | } |