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