wasmtime_environ/
component.rs

1//! Support for the component model in Wasmtime.
2//!
3//! This module contains all of the internal type definitions used by Wasmtime
4//! to process the component model. Despite everything being `pub` here this is
5//! not the public interface of Wasmtime to the component model. Instead this is
6//! the internal support to mirror the core wasm support that Wasmtime already
7//! implements.
8//!
9//! Some main items contained within here are:
10//!
11//! * Type hierarchy information for the component model
12//! * Translation of a component into Wasmtime's representation
13//! * Type information about a component used at runtime
14//!
15//! This module also contains a lot of Serialize/Deserialize types which are
16//! encoded in the final compiled image for a component.
17//!
18//! Note that this entire module is gated behind the `component-model` Cargo
19//! feature.
20//!
21//! ## Warning: In-progress
22//!
23//! As-of the time of this writing this module is incomplete and under
24//! development. It will be added to incrementally over time as more features
25//! are implemented. Current design decisions are also susceptible to change at
26//! any time. Some comments may reflect historical rather than current state as
27//! well (sorry).
28
29/// Canonical ABI-defined constant for the maximum number of "flat" parameters
30/// to a wasm function, or the maximum number of parameters a core wasm function
31/// will take for just the parameters used. Over this number the heap is used
32/// for transferring parameters.
33pub const MAX_FLAT_PARAMS: usize = 16;
34
35/// Canonical ABI-defined constant for the maximum number of "flat" results.
36/// This number of results are returned directly from wasm and otherwise results
37/// are transferred through memory.
38pub const MAX_FLAT_RESULTS: usize = 1;
39
40mod artifacts;
41mod info;
42mod names;
43mod types;
44mod vmcomponent_offsets;
45pub use self::artifacts::*;
46pub use self::info::*;
47pub use self::names::*;
48pub use self::types::*;
49pub use self::vmcomponent_offsets::*;
50
51#[cfg(feature = "compile")]
52mod compiler;
53#[cfg(feature = "compile")]
54pub mod dfg;
55#[cfg(feature = "compile")]
56mod translate;
57#[cfg(feature = "compile")]
58mod types_builder;
59#[cfg(feature = "compile")]
60pub use self::compiler::*;
61#[cfg(feature = "compile")]
62pub use self::translate::*;
63#[cfg(feature = "compile")]
64pub use self::types_builder::*;
65
66/// Helper macro, like `foreach_transcoder`, to iterate over builtins for
67/// components unrelated to transcoding.
68#[macro_export]
69macro_rules! foreach_builtin_component_function {
70    ($mac:ident) => {
71        $mac! {
72            resource_new32(vmctx: vmctx, resource: u32, rep: u32) -> u64;
73            resource_rep32(vmctx: vmctx, resource: u32, idx: u32) -> u64;
74
75            // Returns an `Option<u32>` where `None` is "no destructor needed"
76            // and `Some(val)` is "run the destructor on this rep". The option
77            // is encoded as a 64-bit integer where the low bit is Some/None
78            // and bits 1-33 are the payload.
79            resource_drop(vmctx: vmctx, resource: u32, idx: u32) -> u64;
80
81            resource_transfer_own(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
82            resource_transfer_borrow(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
83            resource_enter_call(vmctx: vmctx);
84            resource_exit_call(vmctx: vmctx) -> bool;
85
86            future_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
87            stream_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
88            error_context_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
89
90            trap(vmctx: vmctx, code: u8);
91
92            utf8_to_utf8(src: ptr_u8, len: size, dst: ptr_u8) -> bool;
93            utf16_to_utf16(src: ptr_u16, len: size, dst: ptr_u16) -> bool;
94            latin1_to_latin1(src: ptr_u8, len: size, dst: ptr_u8) -> bool;
95            latin1_to_utf16(src: ptr_u8, len: size, dst: ptr_u16) -> bool;
96            utf8_to_utf16(src: ptr_u8, len: size, dst: ptr_u16) -> size;
97            utf16_to_utf8(src: ptr_u16, src_len: size, dst: ptr_u8, dst_len: size, ret2: ptr_size) -> size;
98            latin1_to_utf8(src: ptr_u8, src_len: size, dst: ptr_u8, dst_len: size, ret2: ptr_size) -> size;
99            utf16_to_compact_probably_utf16(src: ptr_u16, len: size, dst: ptr_u16) -> size;
100            utf8_to_latin1(src: ptr_u8, len: size, dst: ptr_u8, ret2: ptr_size) -> size;
101            utf16_to_latin1(src: ptr_u16, len: size, dst: ptr_u8, ret2: ptr_size) -> size;
102            utf8_to_compact_utf16(src: ptr_u8, src_len: size, dst: ptr_u16, dst_len: size, bytes_so_far: size) -> size;
103            utf16_to_compact_utf16(src: ptr_u16, src_len: size, dst: ptr_u16, dst_len: size, bytes_so_far: size) -> size;
104        }
105    };
106}
107
108// Define `struct ComponentBuiltinFunctionIndex`
109declare_builtin_index!(
110    ComponentBuiltinFunctionIndex,
111    foreach_builtin_component_function
112);