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