Allocates a new `ComponentInstance + VMComponentContext` pair on the heap with `malloc` and configures it for the `component` specified.
(
id: ComponentInstanceId,
component: &Component,
resource_types: Arc<TryPrimaryMap<ResourceIndex, ResourceType>>,
imports: &Arc<PrimaryMap<RuntimeImportIndex, RuntimeI
| 317 | /// Allocates a new `ComponentInstance + VMComponentContext` pair on the |
| 318 | /// heap with `malloc` and configures it for the `component` specified. |
| 319 | pub(crate) fn new( |
| 320 | id: ComponentInstanceId, |
| 321 | component: &Component, |
| 322 | resource_types: Arc<TryPrimaryMap<ResourceIndex, ResourceType>>, |
| 323 | imports: &Arc<PrimaryMap<RuntimeImportIndex, RuntimeImport>>, |
| 324 | store: NonNull<dyn VMStore>, |
| 325 | ) -> Result<OwnedComponentInstance, OutOfMemory> { |
| 326 | let offsets = VMComponentOffsets::new(HostPtr, component.env_component()); |
| 327 | let num_instances = component.env_component().num_runtime_component_instances; |
| 328 | let mut instance_states = TryPrimaryMap::with_capacity(num_instances.try_into().unwrap())?; |
| 329 | for _ in 0..num_instances { |
| 330 | instance_states.push(InstanceState::default())?; |
| 331 | } |
| 332 | |
| 333 | let instances = TryPrimaryMap::with_capacity( |
| 334 | component |
| 335 | .env_component() |
| 336 | .num_runtime_instances |
| 337 | .try_into() |
| 338 | .unwrap(), |
| 339 | )?; |
| 340 | |
| 341 | let mut ret = OwnedInstance::new(ComponentInstance { |
| 342 | id, |
| 343 | offsets, |
| 344 | instance_states, |
| 345 | instances, |
| 346 | component: component.clone(), |
| 347 | resource_types, |
| 348 | imports: imports.clone(), |
| 349 | store: VMStoreRawPtr(store), |
| 350 | vmctx: OwnedVMContext::new(), |
| 351 | })?; |
| 352 | unsafe { |
| 353 | ret.get_mut().initialize_vmctx(); |
| 354 | } |
| 355 | Ok(ret) |
| 356 | } |
| 357 | |
| 358 | #[inline] |
| 359 | pub fn vmctx(&self) -> NonNull<VMComponentContext> { |
nothing calls this directly
no test coverage detected