(
&mut self,
store: &mut StoreContextMut<'_, T>,
asyncness: Asyncness,
)
| 713 | } |
| 714 | |
| 715 | async fn run<T>( |
| 716 | &mut self, |
| 717 | store: &mut StoreContextMut<'_, T>, |
| 718 | asyncness: Asyncness, |
| 719 | ) -> Result<()> { |
| 720 | let env_component = self.component.env_component(); |
| 721 | |
| 722 | // Before all initializers are processed configure all destructors for |
| 723 | // host-defined resources. No initializer will correspond to these and |
| 724 | // it's required to happen before they're needed, so execute this first. |
| 725 | for (idx, import) in env_component.imported_resources.iter() { |
| 726 | let (ty, func_ref) = match &self.imports[*import] { |
| 727 | RuntimeImport::Resource { |
| 728 | ty, dtor_funcref, .. |
| 729 | } => (*ty, NonNull::from(dtor_funcref)), |
| 730 | _ => unreachable!(), |
| 731 | }; |
| 732 | let i = self.instance_resource_types_mut(store.0).push(ty)?; |
| 733 | assert_eq!(i, idx); |
| 734 | self.instance_mut(store.0) |
| 735 | .set_resource_destructor(idx, Some(func_ref)); |
| 736 | } |
| 737 | |
| 738 | // Next configure all `VMFuncRef`s for trampolines that this component |
| 739 | // will require. These functions won't actually get used until their |
| 740 | // associated state has been initialized through the global initializers |
| 741 | // below, but the funcrefs can all be configured here. |
| 742 | for (idx, sig) in env_component.trampolines.iter() { |
| 743 | let ptrs = self.component.trampoline_ptrs(idx); |
| 744 | let signature = match self.component.signatures().shared_type(*sig) { |
| 745 | Some(s) => s, |
| 746 | None => panic!("found unregistered signature: {sig:?}"), |
| 747 | }; |
| 748 | |
| 749 | self.instance_mut(store.0).set_trampoline( |
| 750 | idx, |
| 751 | ptrs.wasm_call, |
| 752 | ptrs.array_call, |
| 753 | signature, |
| 754 | ); |
| 755 | } |
| 756 | |
| 757 | // Initialize the unsafe intrinsics used by this component, if any. |
| 758 | for (i, module_ty) in env_component |
| 759 | .unsafe_intrinsics |
| 760 | .iter() |
| 761 | .enumerate() |
| 762 | .filter_map(|(i, ty)| ty.expand().map(|ty| (i, ty))) |
| 763 | { |
| 764 | let i = u32::try_from(i).unwrap(); |
| 765 | let intrinsic = UnsafeIntrinsic::from_u32(i); |
| 766 | let ptrs = self.component.unsafe_intrinsic_ptrs(intrinsic).expect( |
| 767 | "should have intrinsic pointers given that we assigned the intrinsic a type", |
| 768 | ); |
| 769 | let shared_ty = self |
| 770 | .component |
| 771 | .signatures() |
| 772 | .shared_type(module_ty) |
no test coverage detected