wasmer_vm/
export.rs

1// This file contains code from external sources.
2// Attributions: https://github.com/wasmerio/wasmer/blob/main/docs/ATTRIBUTIONS.md
3
4use crate::global::VMGlobal;
5use crate::memory::VMMemory;
6use crate::store::InternalStoreHandle;
7use crate::table::VMTable;
8use crate::vmcontext::VMFunctionKind;
9use crate::{MaybeInstanceOwned, VMCallerCheckedAnyfunc};
10use std::any::Any;
11use wasmer_types::{FunctionType, TagKind};
12
13/// The value of an export passed from one instance to another.
14#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))]
15pub enum VMExtern {
16    /// A function export value.
17    Function(InternalStoreHandle<VMFunction>),
18
19    /// A table export value.
20    Table(InternalStoreHandle<VMTable>),
21
22    /// A memory export value.
23    Memory(InternalStoreHandle<VMMemory>),
24
25    /// A global export value.
26    Global(InternalStoreHandle<VMGlobal>),
27
28    /// A tag export value.
29    Tag(InternalStoreHandle<VMTag>),
30}
31
32/// A function export value.
33#[derive(Debug)]
34pub struct VMFunction {
35    /// Pointer to the `VMCallerCheckedAnyfunc` which contains data needed to
36    /// call the function and check its signature.
37    pub anyfunc: MaybeInstanceOwned<VMCallerCheckedAnyfunc>,
38
39    /// The function type, used for compatibility checking.
40    pub signature: FunctionType,
41
42    /// The function kind (specifies the calling convention for the
43    /// function).
44    pub kind: VMFunctionKind,
45
46    /// Associated data owned by a host function.
47    pub host_data: Box<dyn Any>,
48}
49
50/// A tag export value.
51#[derive(Debug, Clone, Eq, PartialEq)]
52pub struct VMTag {
53    /// The kind of tag.
54    // Note: currently it can only be exception.
55    pub kind: TagKind,
56    /// The tag type, used for compatibility checking.
57    pub signature: FunctionType,
58}
59
60impl VMTag {
61    /// Create a new [`VMTag`].
62    pub fn new(kind: TagKind, signature: FunctionType) -> Self {
63        Self { kind, signature }
64    }
65}