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],
)
| 257 | /// |
| 258 | /// The modules are expected to *not* have start functions as no timeouts are configured. |
| 259 | pub 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(); |
no test coverage detected