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

Function instantiate_many

crates/fuzzing/src/oracles.rs:259–323  ·  view source on GitHub ↗

Instantiates many instances from the given modules. The engine will be configured using the provided config. The modules are expected to *not* have start functions as no timeouts are configured.

(
    modules: &[Vec<u8>],
    known_valid: KnownValid,
    config: &generators::Config,
    commands: &[Command],
)

Source from the content-addressed store, hash-verified

257///
258/// The modules are expected to *not* have start functions as no timeouts are configured.
259pub fn instantiate_many(
260 modules: &[Vec<u8>],
261 known_valid: KnownValid,
262 config: &generators::Config,
263 commands: &[Command],
264) {
265 log::debug!("instantiate_many: {commands:#?}");
266
267 assert!(!config.module_config.config.allow_start_export);
268
269 let engine = Engine::new(&config.to_wasmtime()).unwrap();
270
271 let modules = modules
272 .iter()
273 .enumerate()
274 .filter_map(
275 |(i, bytes)| match compile_module(&engine, bytes, known_valid, config) {
276 Some(m) => {
277 log::debug!("successfully compiled module {i}");
278 Some(m)
279 }
280 None => {
281 log::debug!("failed to compile module {i}");
282 None
283 }
284 },
285 )
286 .collect::<Vec<_>>();
287
288 // If no modules were valid, we're done
289 if modules.is_empty() {
290 return;
291 }
292
293 // This stores every `Store` where a successful instantiation takes place
294 let mut stores = Vec::new();
295 let limits = StoreLimits::new();
296
297 for command in commands {
298 match command {
299 Command::Instantiate(index) => {
300 let index = *index % modules.len();
301 log::info!("instantiating {index}");
302 let module = &modules[index];
303 let mut store = Store::new(&engine, limits.clone());
304 config.configure_store(&mut store);
305
306 if instantiate_with_dummy(&mut store, module).is_some() {
307 stores.push(Some(store));
308 } else {
309 log::warn!("instantiation failed");
310 }
311 }
312 Command::Terminate(index) => {
313 if stores.is_empty() {
314 continue;
315 }
316 let index = *index % stores.len();

Callers 1

execute_oneFunction · 0.85

Calls 13

compile_moduleFunction · 0.85
instantiate_with_dummyFunction · 0.85
configure_storeMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
to_wasmtimeMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45
is_someMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected