Instantiate the Wasm buffer, and implicitly fail if we have an unexpected panic or segfault or anything else that can be detected "passively". The engine will be configured using provided config.
(
wasm: &[u8],
known_valid: KnownValid,
config: &generators::Config,
timeout: Timeout,
)
| 196 | /// |
| 197 | /// The engine will be configured using provided config. |
| 198 | pub fn instantiate( |
| 199 | wasm: &[u8], |
| 200 | known_valid: KnownValid, |
| 201 | config: &generators::Config, |
| 202 | timeout: Timeout, |
| 203 | ) { |
| 204 | let mut store = config.to_store(); |
| 205 | |
| 206 | let module = match compile_module(store.engine(), wasm, known_valid, config) { |
| 207 | Some(module) => module, |
| 208 | None => return, |
| 209 | }; |
| 210 | |
| 211 | let mut timeout_state = HelperThread::default(); |
| 212 | match timeout { |
| 213 | Timeout::Fuel(fuel) => store.set_fuel(fuel).unwrap(), |
| 214 | |
| 215 | // If a timeout is requested then we spawn a helper thread to wait for |
| 216 | // the requested time and then send us a signal to get interrupted. We |
| 217 | // also arrange for the thread's sleep to get interrupted if we return |
| 218 | // early (or the wasm returns within the time limit), which allows the |
| 219 | // thread to get torn down. |
| 220 | // |
| 221 | // This prevents us from creating a huge number of sleeping threads if |
| 222 | // this function is executed in a loop, like it does on nightly fuzzing |
| 223 | // infrastructure. |
| 224 | Timeout::Epoch(timeout) => { |
| 225 | let engine = store.engine().clone(); |
| 226 | timeout_state.run_periodically(timeout, move || engine.increment_epoch()); |
| 227 | } |
| 228 | Timeout::None => {} |
| 229 | } |
| 230 | |
| 231 | instantiate_with_dummy(&mut store, &module); |
| 232 | } |
| 233 | |
| 234 | /// Represents supported commands to the `instantiate_many` function. |
| 235 | #[derive(Arbitrary, Debug)] |