1#![warn(clippy::cast_possible_truncation)]
28
29use crate::prelude::*;
30use core::marker;
31use core::pin::Pin;
32use core::task::{Context, Poll};
33
34mod bug;
35
36#[macro_use]
37pub(crate) mod func;
38
39pub(crate) mod code;
40pub(crate) mod code_memory;
41#[cfg(feature = "debug")]
42pub(crate) mod debug;
43pub(crate) mod exception;
44pub(crate) mod externals;
45#[cfg(feature = "async")]
46pub(crate) mod fiber;
47pub(crate) mod gc;
48pub(crate) mod instance;
49pub(crate) mod instantiate;
50pub(crate) mod limits;
51pub(crate) mod linker;
52pub(crate) mod memory;
53pub(crate) mod module;
54#[cfg(feature = "debug-builtins")]
55pub(crate) mod native_debug;
56pub(crate) mod resources;
57pub(crate) mod store;
58pub(crate) mod trampoline;
59pub(crate) mod trap;
60#[cfg(feature = "component-model-async")]
61pub(crate) mod try_mutex;
62pub(crate) mod type_registry;
63pub(crate) mod types;
64pub(crate) mod v128;
65pub(crate) mod values;
66pub(crate) mod vm;
67
68#[cfg(feature = "component-model")]
69pub mod component;
70
71cfg_select! {
72 miri => {
73 }
75 not(feature = "std") => {
76 }
78 unix => {
79 pub mod unix;
80 }
81 windows => {
82 pub mod windows;
83 }
84 _ => {
85 }
87}
88
89pub use bug::WasmtimeBug;
90pub(crate) use bug::{bail_bug, bug};
91pub use code_memory::CodeMemory;
92#[cfg(feature = "debug")]
93pub use debug::*;
94pub use exception::*;
95pub use externals::*;
96pub use func::*;
97pub use gc::*;
98pub use instance::{Instance, InstancePre};
99pub use instantiate::CompiledModule;
100pub use limits::*;
101pub use linker::*;
102pub use memory::*;
103pub use module::{Module, ModuleExport, ModuleFunction};
104pub use resources::*;
105#[cfg(all(feature = "async", feature = "call-hook"))]
106pub use store::CallHookHandler;
107pub use store::{
108 AsContext, AsContextMut, CallHook, Store, StoreContext, StoreContextMut, StoreHookState,
109 UpdateDeadline,
110};
111pub use trap::*;
112pub use types::*;
113pub use v128::V128;
114pub use values::*;
115
116#[cfg(feature = "pooling-allocator")]
117pub use vm::{PoolConcurrencyLimitError, PoolingAllocatorMetrics};
118
119#[cfg(feature = "profiling")]
120mod profiling;
121#[cfg(feature = "profiling")]
122pub use profiling::GuestProfiler;
123
124#[cfg(feature = "async")]
125pub(crate) mod stack;
126#[cfg(feature = "async")]
127pub use stack::*;
128
129#[cfg(feature = "coredump")]
130mod coredump;
131#[cfg(feature = "coredump")]
132pub use coredump::*;
133
134#[cfg(feature = "wave")]
135mod wave;
136
137fn box_future<'a, F, T, E>(future: F) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'a>>
143where
144 F: Future<Output = Result<T, E>> + Send + 'a,
145 T: 'a,
146 E: From<OutOfMemory> + 'a,
147{
148 if let Ok(future) = try_new::<Box<F>>(future) {
149 return Pin::from(future);
150 }
151
152 struct OomFuture<F, T, E>(marker::PhantomData<fn() -> (T, F, E)>);
155
156 impl<F, T, E> Future for OomFuture<F, T, E>
157 where
158 E: From<OutOfMemory>,
159 {
160 type Output = Result<T, E>;
161
162 fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
163 Poll::Ready(Err(OutOfMemory::new(size_of::<F>()).into()))
164 }
165 }
166
167 let future = OomFuture::<F, T, E>(marker::PhantomData);
170 assert_eq!(size_of_val(&future), 0);
171 Box::pin(future)
172}
173
174fn _assertions_runtime() {
175 use crate::_assert_send_and_sync;
176
177 #[cfg(feature = "async")]
178 fn _assert_send<T: Send>(_t: T) {}
179
180 _assert_send_and_sync::<Caller<'_, ()>>();
181 _assert_send_and_sync::<ExternRef>();
182 _assert_send_and_sync::<(Func, TypedFunc<(), ()>, Global, Table, Memory)>();
183 _assert_send_and_sync::<Instance>();
184 _assert_send_and_sync::<InstancePre<()>>();
185 _assert_send_and_sync::<InstancePre<*mut u8>>();
186 _assert_send_and_sync::<Linker<()>>();
187 _assert_send_and_sync::<Linker<*mut u8>>();
188 _assert_send_and_sync::<Module>();
189 _assert_send_and_sync::<Store<()>>();
190 _assert_send_and_sync::<StoreContext<'_, ()>>();
191 _assert_send_and_sync::<StoreContextMut<'_, ()>>();
192
193 #[cfg(feature = "async")]
194 fn _call_async(s: &mut Store<()>, f: Func) {
195 _assert_send(f.call_async(&mut *s, &[], &mut []))
196 }
197 #[cfg(feature = "async")]
198 fn _typed_call_async(s: &mut Store<()>, f: TypedFunc<(), ()>) {
199 _assert_send(f.call_async(&mut *s, ()))
200 }
201 #[cfg(feature = "async")]
202 fn _instantiate_async(s: &mut Store<()>, m: &Module) {
203 _assert_send(Instance::new_async(s, m, &[]))
204 }
205}