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

Function lookup_vmdef

crates/wasmtime/src/runtime/component/instance.rs:579–612  ·  view source on GitHub ↗

Translates a `CoreDef`, a definition of a core wasm item, to an [`Export`] which is the runtime core wasm definition.

(
    store: &mut StoreOpaque,
    id: ComponentInstanceId,
    def: &CoreDef,
)

Source from the content-addressed store, hash-verified

577/// Translates a `CoreDef`, a definition of a core wasm item, to an
578/// [`Export`] which is the runtime core wasm definition.
579pub(crate) fn lookup_vmdef(
580 store: &mut StoreOpaque,
581 id: ComponentInstanceId,
582 def: &CoreDef,
583) -> vm::Export {
584 match def {
585 CoreDef::Export(e) => lookup_vmexport(store, id, e),
586 CoreDef::Trampoline(idx) => {
587 let funcref = store
588 .store_data_mut()
589 .component_instance_mut(id)
590 .trampoline_func_ref(*idx);
591 // SAFETY: the `funcref` is owned by `store` and is valid within
592 // that store, so it's safe to create a `Func`.
593 vm::Export::Function(unsafe { crate::Func::from_vm_func_ref(store.id(), funcref) })
594 }
595 CoreDef::InstanceFlags(idx) => {
596 let id = StoreComponentInstanceId::new(store.id(), id);
597 vm::Export::Global(crate::Global::from_component_flags(id, *idx))
598 }
599 CoreDef::UnsafeIntrinsic(intrinsic) => {
600 let funcref = store
601 .store_data_mut()
602 .component_instance_mut(id)
603 .unsafe_intrinsic_func_ref(*intrinsic);
604 // SAFETY: as above, the `funcref` is owned by `store` and is valid
605 // within that store, so it's safe to create a `Func`.
606 vm::Export::Function(unsafe { crate::Func::from_vm_func_ref(store.id(), funcref) })
607 }
608 CoreDef::TaskMayBlock => vm::Export::Global(crate::Global::from_task_may_block(
609 StoreComponentInstanceId::new(store.id(), id),
610 )),
611 }
612}
613
614/// Translates a `CoreExport<T>`, an export of some core instance within
615/// this component, to the actual runtime definition of that item.

Callers 7

lookup_vmdefMethod · 0.85
resourceMethod · 0.85
extract_reallocMethod · 0.85
extract_callbackMethod · 0.85
extract_post_returnMethod · 0.85
build_importsMethod · 0.85
assert_type_matchesMethod · 0.85

Calls 9

lookup_vmexportFunction · 0.85
store_data_mutMethod · 0.80
FunctionClass · 0.50
newFunction · 0.50
GlobalClass · 0.50
trampoline_func_refMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected