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 #[macro_use]
30 pub(crate) mod func;
31 
32 pub(crate) mod code;
33 pub(crate) mod code_memory;
34 pub(crate) mod debug;
35 pub(crate) mod externals;
36 pub(crate) mod gc;
37 pub(crate) mod instance;
38 pub(crate) mod instantiate;
39 pub(crate) mod limits;
40 pub(crate) mod linker;
41 pub(crate) mod memory;
42 pub(crate) mod module;
43 pub(crate) mod resources;
44 pub(crate) mod store;
45 pub(crate) mod trampoline;
46 pub(crate) mod trap;
47 pub(crate) mod type_registry;
48 pub(crate) mod types;
49 pub(crate) mod uninhabited;
50 pub(crate) mod v128;
51 pub(crate) mod values;
52 pub(crate) mod vm;
53 
54 #[cfg(feature = "component-model")]
55 pub mod component;
56 
57 cfg_if::cfg_if! {
58     if #[cfg(miri)] {
59         // no extensions on miri
60     } else if #[cfg(unix)] {
61         pub mod unix;
62     } else if #[cfg(windows)] {
63         pub mod windows;
64     } else {
65         // ... unknown os!
66     }
67 }
68 
69 pub use code_memory::CodeMemory;
70 pub use externals::*;
71 pub use func::*;
72 pub use gc::*;
73 pub use instance::{Instance, InstancePre};
74 pub use instantiate::CompiledModule;
75 pub use limits::*;
76 pub use linker::*;
77 pub use memory::*;
78 pub use module::{Module, ModuleExport};
79 pub use resources::*;
80 #[cfg(all(feature = "async", feature = "call-hook"))]
81 pub use store::CallHookHandler;
82 pub use store::{
83     AsContext, AsContextMut, CallHook, Store, StoreContext, StoreContextMut, UpdateDeadline,
84 };
85 pub use trap::*;
86 pub use types::*;
87 pub use v128::V128;
88 pub use values::*;
89 
90 pub(crate) use uninhabited::*;
91 
92 #[cfg(feature = "pooling-allocator")]
93 pub use vm::PoolConcurrencyLimitError;
94 
95 #[cfg(feature = "profiling")]
96 mod profiling;
97 #[cfg(feature = "profiling")]
98 pub use profiling::GuestProfiler;
99 
100 #[cfg(feature = "async")]
101 pub(crate) mod stack;
102 #[cfg(feature = "async")]
103 pub use stack::*;
104 
105 #[cfg(feature = "coredump")]
106 mod coredump;
107 #[cfg(feature = "coredump")]
108 pub use coredump::*;
109 
110 fn _assertions_runtime() {
111     use crate::_assert_send_and_sync;
112 
113     #[cfg(feature = "async")]
114     fn _assert_send<T: Send>(_t: T) {}
115 
116     _assert_send_and_sync::<Caller<'_, ()>>();
117     _assert_send_and_sync::<ExternRef>();
118     _assert_send_and_sync::<(Func, TypedFunc<(), ()>, Global, Table, Memory)>();
119     _assert_send_and_sync::<Instance>();
120     _assert_send_and_sync::<InstancePre<()>>();
121     _assert_send_and_sync::<InstancePre<*mut u8>>();
122     _assert_send_and_sync::<Linker<()>>();
123     _assert_send_and_sync::<Linker<*mut u8>>();
124     _assert_send_and_sync::<Module>();
125     _assert_send_and_sync::<Store<()>>();
126     _assert_send_and_sync::<StoreContext<'_, ()>>();
127     _assert_send_and_sync::<StoreContextMut<'_, ()>>();
128 
129     #[cfg(feature = "async")]
130     fn _call_async(s: &mut Store<()>, f: Func) {
131         _assert_send(f.call_async(&mut *s, &[], &mut []))
132     }
133     #[cfg(feature = "async")]
134     fn _typed_call_async(s: &mut Store<()>, f: TypedFunc<(), ()>) {
135         _assert_send(f.call_async(&mut *s, ()))
136     }
137     #[cfg(feature = "async")]
138     fn _instantiate_async(s: &mut Store<()>, m: &Module) {
139         _assert_send(Instance::new_async(s, m, &[]))
140     }
141 }
142