MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / instantiate

Function instantiate

crates/fuzzing/src/oracles.rs:198–232  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

196///
197/// The engine will be configured using provided config.
198pub 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)]

Callers 6

mainFunction · 0.50
load_pluginFunction · 0.50
mainFunction · 0.50
test_transmit_withFunction · 0.50
instantiateMethod · 0.50
executeFunction · 0.50

Calls 9

compile_moduleFunction · 0.85
instantiate_with_dummyFunction · 0.85
to_storeMethod · 0.80
run_periodicallyMethod · 0.80
engineMethod · 0.45
unwrapMethod · 0.45
set_fuelMethod · 0.45
cloneMethod · 0.45
increment_epochMethod · 0.45

Tested by 2

test_transmit_withFunction · 0.40
instantiateMethod · 0.40