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

Method run

crates/wasmtime/src/runtime/component/instance.rs:715–879  ·  view source on GitHub ↗
(
        &mut self,
        store: &mut StoreContextMut<'_, T>,
        asyncness: Asyncness,
    )

Source from the content-addressed store, hash-verified

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)

Callers 1

_instantiateMethod · 0.45

Calls 15

fromFunction · 0.85
OkFunction · 0.85
env_componentMethod · 0.80
trampoline_ptrsMethod · 0.80
shared_typeMethod · 0.80
set_trampolineMethod · 0.80
unsafe_intrinsic_ptrsMethod · 0.80
set_intrinsicMethod · 0.80
static_moduleMethod · 0.80
build_importsMethod · 0.80

Tested by

no test coverage detected