1 // Wasmtime's runtime has lots of fiddly bits where we're doing operations like
2 // casting between wasm i32/i64 and host `usize` values. There's also in general
3 // just lots of pieces of low-level manipulation of memory and internals of VM
4 // runtime state. To help keep all the integer casts correct be a bit more
5 // strict than the default settings to help weed out bugs ahead of time.
6 //
7 // This inevitably leads to wordier code than might otherwise be used because,
8 // for example, `u64 as usize` is warned against and will be an error on CI.
9 // This happens pretty frequently and needs to be replaced with `val.try_into()`
10 // or `usize::try_from(val)` where the error is handled. In some cases the
11 // correct thing to do is to `.unwrap()` the error to indicate a fatal mistake,
12 // but in some cases the correct thing is to propagate the error.
13 //
14 // Some niche cases that explicitly want truncation are recommended to have a
15 // function along the lines of
16 //
17 //     #[allow(clippy::cast_possible_truncation)]
18 //     fn truncate_i32_to_i8(a: i32) -> i8 { a as i8 }
19 //
20 // as this explicitly indicates the intent of truncation is desired. Other
21 // locations should use fallible conversions.
22 //
23 // If performance is absolutely critical then it's recommended to use `#[allow]`
24 // with a comment indicating why performance is critical as well as a short
25 // explanation of why truncation shouldn't be happening at runtime. This
26 // situation should be pretty rare though.
27 #![warn(clippy::cast_possible_truncation)]
28 
29 #[cfg(feature = "component-model-async")]
30 mod bug;
31 
32 #[macro_use]
33 pub(crate) mod func;
34 
35 pub(crate) mod code;
36 pub(crate) mod code_memory;
37 #[cfg(feature = "debug")]
38 pub(crate) mod debug;
39 #[cfg(feature = "gc")]
40 pub(crate) mod exception;
41 pub(crate) mod externals;
42 #[cfg(feature = "async")]
43 pub(crate) mod fiber;
44 pub(crate) mod gc;
45 pub(crate) mod instance;
46 pub(crate) mod instantiate;
47 pub(crate) mod limits;
48 pub(crate) mod linker;
49 pub(crate) mod memory;
50 pub(crate) mod module;
51 #[cfg(feature = "debug-builtins")]
52 pub(crate) mod native_debug;
53 pub(crate) mod resources;
54 pub(crate) mod store;
55 pub(crate) mod trampoline;
56 pub(crate) mod trap;
57 pub(crate) mod type_registry;
58 pub(crate) mod types;
59 pub(crate) mod v128;
60 pub(crate) mod values;
61 pub(crate) mod vm;
62 
63 #[cfg(feature = "component-model")]
64 pub mod component;
65 
66 cfg_if::cfg_if! {
67     if #[cfg(miri)] {
68         // no extensions on miri
69     } else if #[cfg(not(feature = "std"))] {
70         // no extensions on no-std
71     } else if #[cfg(unix)] {
72         pub mod unix;
73     } else if #[cfg(windows)] {
74         pub mod windows;
75     } else {
76         // ... unknown os!
77     }
78 }
79 
80 #[cfg(feature = "component-model-async")]
81 pub use bug::WasmtimeBug;
82 #[cfg(feature = "component-model-async")]
83 pub(crate) use bug::bail_bug;
84 pub use code_memory::CodeMemory;
85 #[cfg(feature = "debug")]
86 pub use debug::*;
87 #[cfg(feature = "gc")]
88 pub use exception::*;
89 pub use externals::*;
90 pub use func::*;
91 pub use gc::*;
92 pub use instance::{Instance, InstancePre};
93 pub use instantiate::CompiledModule;
94 pub use limits::*;
95 pub use linker::*;
96 pub use memory::*;
97 pub use module::{Module, ModuleExport};
98 pub use resources::*;
99 #[cfg(all(feature = "async", feature = "call-hook"))]
100 pub use store::CallHookHandler;
101 pub use store::{
102     AsContext, AsContextMut, CallHook, Store, StoreContext, StoreContextMut, UpdateDeadline,
103 };
104 pub use trap::*;
105 pub use types::*;
106 pub use v128::V128;
107 pub use values::*;
108 
109 #[cfg(feature = "pooling-allocator")]
110 pub use vm::{PoolConcurrencyLimitError, PoolingAllocatorMetrics};
111 
112 #[cfg(feature = "profiling")]
113 mod profiling;
114 #[cfg(feature = "profiling")]
115 pub use profiling::GuestProfiler;
116 
117 #[cfg(feature = "async")]
118 pub(crate) mod stack;
119 #[cfg(feature = "async")]
120 pub use stack::*;
121 
122 #[cfg(feature = "coredump")]
123 mod coredump;
124 #[cfg(feature = "coredump")]
125 pub use coredump::*;
126 
127 #[cfg(feature = "wave")]
128 mod wave;
129 
130 fn _assertions_runtime() {
131     use crate::_assert_send_and_sync;
132 
133     #[cfg(feature = "async")]
134     fn _assert_send<T: Send>(_t: T) {}
135 
136     _assert_send_and_sync::<Caller<'_, ()>>();
137     _assert_send_and_sync::<ExternRef>();
138     _assert_send_and_sync::<(Func, TypedFunc<(), ()>, Global, Table, Memory)>();
139     _assert_send_and_sync::<Instance>();
140     _assert_send_and_sync::<InstancePre<()>>();
141     _assert_send_and_sync::<InstancePre<*mut u8>>();
142     _assert_send_and_sync::<Linker<()>>();
143     _assert_send_and_sync::<Linker<*mut u8>>();
144     _assert_send_and_sync::<Module>();
145     _assert_send_and_sync::<Store<()>>();
146     _assert_send_and_sync::<StoreContext<'_, ()>>();
147     _assert_send_and_sync::<StoreContextMut<'_, ()>>();
148 
149     #[cfg(feature = "async")]
150     fn _call_async(s: &mut Store<()>, f: Func) {
151         _assert_send(f.call_async(&mut *s, &[], &mut []))
152     }
153     #[cfg(feature = "async")]
154     fn _typed_call_async(s: &mut Store<()>, f: TypedFunc<(), ()>) {
155         _assert_send(f.call_async(&mut *s, ()))
156     }
157     #[cfg(feature = "async")]
158     fn _instantiate_async(s: &mut Store<()>, m: &Module) {
159         _assert_send(Instance::new_async(s, m, &[]))
160     }
161 }
162