Skip to main content

wasmtime/runtime/
trampoline.rs

1//! Utility module to create trampolines in/out WebAssembly module.
2
3mod global;
4mod memory;
5mod table;
6mod tag;
7
8pub use self::global::*;
9
10use self::memory::create_memory;
11use self::table::create_table;
12use self::tag::create_tag;
13use crate::prelude::*;
14use crate::runtime::vm::{ExportMemory, SharedMemory};
15use crate::store::{StoreOpaque, StoreResourceLimiter};
16use crate::{MemoryType, TableType, TagType};
17use wasmtime_environ::{MemoryIndex, TableIndex, TagIndex};
18
19pub async fn generate_memory_export(
20    store: &mut StoreOpaque,
21    limiter: Option<&mut StoreResourceLimiter<'_>>,
22    m: &MemoryType,
23    preallocation: Option<&SharedMemory>,
24) -> Result<ExportMemory> {
25    let id = store.id();
26    let instance = create_memory(store, limiter, m, preallocation).await?;
27    Ok(store
28        .instance_mut(instance)
29        .get_exported_memory(id, MemoryIndex::from_u32(0)))
30}
31
32pub async fn generate_table_export(
33    store: &mut StoreOpaque,
34    limiter: Option<&mut StoreResourceLimiter<'_>>,
35    t: &TableType,
36) -> Result<crate::Table> {
37    let id = store.id();
38    let instance = create_table(store, limiter, t).await?;
39    Ok(store
40        .instance_mut(instance)
41        .get_exported_table(id, TableIndex::from_u32(0)))
42}
43
44pub fn generate_tag_export(store: &mut StoreOpaque, t: &TagType) -> Result<crate::Tag> {
45    let id = store.id();
46    let instance = create_tag(store, t)?;
47    Ok(store
48        .instance_mut(instance)
49        .get_exported_tag(id, TagIndex::from_u32(0)))
50}