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_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
85pub use bug::WasmtimeBug;
86pub(crate) use bug::{bail_bug, bug};
87pub use code_memory::CodeMemory;
88#[cfg(feature = "debug")]
89pub use debug::*;
90pub use exception::*;
91pub use externals::*;
92pub use func::*;
93pub use gc::*;
94pub use instance::{Instance, InstancePre};
95pub use instantiate::CompiledModule;
96pub use limits::*;
97pub use linker::*;
98pub use memory::*;
99pub use module::{Module, ModuleExport, ModuleFunction};
100pub use resources::*;
101#[cfg(all(feature = "async", feature = "call-hook"))]
102pub use store::CallHookHandler;
103pub use store::{
104 AsContext, AsContextMut, CallHook, Store, StoreContext, StoreContextMut, UpdateDeadline,
105};
106pub use trap::*;
107pub use types::*;
108pub use v128::V128;
109pub use values::*;
110
111#[cfg(feature = "pooling-allocator")]
112pub use vm::{PoolConcurrencyLimitError, PoolingAllocatorMetrics};
113
114#[cfg(feature = "profiling")]
115mod profiling;
116#[cfg(feature = "profiling")]
117pub use profiling::GuestProfiler;
118
119#[cfg(feature = "async")]
120pub(crate) mod stack;
121#[cfg(feature = "async")]
122pub use stack::*;
123
124#[cfg(feature = "coredump")]
125mod coredump;
126#[cfg(feature = "coredump")]
127pub use coredump::*;
128
129#[cfg(feature = "wave")]
130mod wave;
131
132fn box_future<'a, F, T, E>(future: F) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'a>>
138where
139 F: Future<Output = Result<T, E>> + Send + 'a,
140 T: 'a,
141 E: From<OutOfMemory> + 'a,
142{
143 if let Ok(future) = try_new::<Box<F>>(future) {
144 return Pin::from(future);
145 }
146
147 struct OomFuture<F, T, E>(marker::PhantomData<fn() -> (T, F, E)>);
150
151 impl<F, T, E> Future for OomFuture<F, T, E>
152 where
153 E: From<OutOfMemory>,
154 {
155 type Output = Result<T, E>;
156
157 fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
158 Poll::Ready(Err(OutOfMemory::new(size_of::<F>()).into()))
159 }
160 }
161
162 let future = OomFuture::<F, T, E>(marker::PhantomData);
165 assert_eq!(size_of_val(&future), 0);
166 Box::pin(future)
167}
168
169fn _assertions_runtime() {
170 use crate::_assert_send_and_sync;
171
172 #[cfg(feature = "async")]
173 fn _assert_send<T: Send>(_t: T) {}
174
175 _assert_send_and_sync::<Caller<'_, ()>>();
176 _assert_send_and_sync::<ExternRef>();
177 _assert_send_and_sync::<(Func, TypedFunc<(), ()>, Global, Table, Memory)>();
178 _assert_send_and_sync::<Instance>();
179 _assert_send_and_sync::<InstancePre<()>>();
180 _assert_send_and_sync::<InstancePre<*mut u8>>();
181 _assert_send_and_sync::<Linker<()>>();
182 _assert_send_and_sync::<Linker<*mut u8>>();
183 _assert_send_and_sync::<Module>();
184 _assert_send_and_sync::<Store<()>>();
185 _assert_send_and_sync::<StoreContext<'_, ()>>();
186 _assert_send_and_sync::<StoreContextMut<'_, ()>>();
187
188 #[cfg(feature = "async")]
189 fn _call_async(s: &mut Store<()>, f: Func) {
190 _assert_send(f.call_async(&mut *s, &[], &mut []))
191 }
192 #[cfg(feature = "async")]
193 fn _typed_call_async(s: &mut Store<()>, f: TypedFunc<(), ()>) {
194 _assert_send(f.call_async(&mut *s, ()))
195 }
196 #[cfg(feature = "async")]
197 fn _instantiate_async(s: &mut Store<()>, m: &Module) {
198 _assert_send(Instance::new_async(s, m, &[]))
199 }
200}