Skip to main content

substrate_wasmtime_runtime/
export.rs

1use crate::vmcontext::{
2    VMContext, VMFunctionBody, VMGlobalDefinition, VMMemoryDefinition, VMSharedSignatureIndex,
3    VMTableDefinition,
4};
5use wasmtime_environ::wasm::Global;
6use wasmtime_environ::{MemoryPlan, TablePlan};
7
8/// The value of an export passed from one instance to another.
9#[derive(Debug, Clone)]
10pub enum Export {
11    /// A function export value.
12    Function(ExportFunction),
13
14    /// A table export value.
15    Table(ExportTable),
16
17    /// A memory export value.
18    Memory(ExportMemory),
19
20    /// A global export value.
21    Global(ExportGlobal),
22}
23
24/// A function export value.
25#[derive(Debug, Clone)]
26pub struct ExportFunction {
27    /// The address of the native-code function.
28    pub address: *const VMFunctionBody,
29    /// Pointer to the containing `VMContext`.
30    pub vmctx: *mut VMContext,
31    /// The function signature declaration, used for compatibilty checking.
32    ///
33    /// Note that this indexes within the module associated with `vmctx`.
34    pub signature: VMSharedSignatureIndex,
35}
36
37impl From<ExportFunction> for Export {
38    fn from(func: ExportFunction) -> Export {
39        Export::Function(func)
40    }
41}
42
43/// A table export value.
44#[derive(Debug, Clone)]
45pub struct ExportTable {
46    /// The address of the table descriptor.
47    pub definition: *mut VMTableDefinition,
48    /// Pointer to the containing `VMContext`.
49    pub vmctx: *mut VMContext,
50    /// The table declaration, used for compatibilty checking.
51    pub table: TablePlan,
52}
53
54impl From<ExportTable> for Export {
55    fn from(func: ExportTable) -> Export {
56        Export::Table(func)
57    }
58}
59
60/// A memory export value.
61#[derive(Debug, Clone)]
62pub struct ExportMemory {
63    /// The address of the memory descriptor.
64    pub definition: *mut VMMemoryDefinition,
65    /// Pointer to the containing `VMContext`.
66    pub vmctx: *mut VMContext,
67    /// The memory declaration, used for compatibilty checking.
68    pub memory: MemoryPlan,
69}
70
71impl From<ExportMemory> for Export {
72    fn from(func: ExportMemory) -> Export {
73        Export::Memory(func)
74    }
75}
76
77/// A global export value.
78#[derive(Debug, Clone)]
79pub struct ExportGlobal {
80    /// The address of the global storage.
81    pub definition: *mut VMGlobalDefinition,
82    /// Pointer to the containing `VMContext`.
83    pub vmctx: *mut VMContext,
84    /// The global declaration, used for compatibilty checking.
85    pub global: Global,
86}
87
88impl From<ExportGlobal> for Export {
89    fn from(func: ExportGlobal) -> Export {
90        Export::Global(func)
91    }
92}