1#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
4#![warn(unused_import_braces)]
5#![allow(clippy::new_without_default, ambiguous_wide_pointer_comparisons)]
6#![warn(
7 clippy::float_arithmetic,
8 clippy::mut_mut,
9 clippy::nonminimal_bool,
10 clippy::map_unwrap_or,
11 clippy::print_stdout,
12 clippy::unicode_not_nfc,
13 clippy::use_self
14)]
15#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
16
17mod exception;
18mod export;
19mod extern_ref;
20mod function_env;
21mod global;
22mod imports;
23mod instance;
24mod memory;
25mod mmap;
26mod probestack;
27mod sig_registry;
28mod store;
29mod table;
30mod threadconditions;
31mod trap;
32mod vmcontext;
33
34pub mod libcalls;
35
36use std::ptr::NonNull;
37
38pub use crate::exception::{VMExceptionObj, VMExceptionRef};
39pub use crate::export::*;
40pub use crate::extern_ref::{VMExternObj, VMExternRef};
41pub use crate::function_env::VMFunctionEnvironment;
42pub use crate::global::*;
43pub use crate::imports::Imports;
44pub use crate::instance::{InstanceAllocator, VMInstance};
45pub use crate::memory::{
46 LinearMemory, NotifyLocation, VMMemory, VMOwnedMemory, VMSharedMemory,
47 initialize_memory_with_data,
48};
49pub use crate::mmap::{Mmap, MmapType};
50pub use crate::probestack::PROBESTACK;
51pub use crate::sig_registry::SignatureRegistry;
52pub use crate::store::{InternalStoreHandle, MaybeInstanceOwned, StoreHandle, StoreObjects};
53pub use crate::table::{TableElement, VMTable};
54#[doc(hidden)]
55pub use crate::threadconditions::{
56 ExpectedValue, ThreadConditions, ThreadConditionsHandle, WaiterError,
57};
58pub use crate::trap::*;
59pub use crate::vmcontext::{
60 VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext, VMFunctionContext,
61 VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition,
62 VMMemoryImport, VMSharedSignatureIndex, VMSharedTagIndex, VMTableDefinition, VMTableImport,
63 VMTrampoline,
64};
65pub use store::StoreObject;
66pub use wasmer_types::LibCall;
67pub use wasmer_types::MemoryError;
68pub use wasmer_types::MemoryStyle;
69use wasmer_types::RawValue;
70pub use wasmer_types::TableStyle;
71pub use wasmer_types::{StoreId, TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};
72
73pub const VERSION: &str = env!("CARGO_PKG_VERSION");
75
76#[derive(Clone, Copy, Debug)]
78#[repr(transparent)]
79pub struct SectionBodyPtr(pub *const u8);
80
81impl std::ops::Deref for SectionBodyPtr {
82 type Target = *const u8;
83
84 fn deref(&self) -> &Self::Target {
85 &self.0
86 }
87}
88
89#[repr(C)]
94pub struct VMFunctionBody(u8);
95
96#[derive(Clone, Copy, Debug)]
98#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))]
99#[repr(transparent)]
100pub struct FunctionBodyPtr(pub *const VMFunctionBody);
101
102impl std::ops::Deref for FunctionBodyPtr {
103 type Target = *const VMFunctionBody;
104
105 fn deref(&self) -> &Self::Target {
106 &self.0
107 }
108}
109
110unsafe impl Send for FunctionBodyPtr {}
114unsafe impl Sync for FunctionBodyPtr {}
118
119#[repr(transparent)]
121#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
122pub struct VMFuncRef(pub NonNull<VMCallerCheckedAnyfunc>);
123
124impl VMFuncRef {
125 pub fn into_raw(self) -> RawValue {
127 RawValue {
128 funcref: self.0.as_ptr() as usize,
129 }
130 }
131
132 pub unsafe fn from_raw(raw: RawValue) -> Option<Self> {
137 unsafe { NonNull::new(raw.funcref as *mut VMCallerCheckedAnyfunc).map(Self) }
138 }
139}
140
141#[cfg(test)]
142mod test_vmfunction_body {
143 use super::VMFunctionBody;
144 use std::mem::size_of;
145
146 #[test]
147 fn check_vmfunction_body_offsets() {
148 assert_eq!(size_of::<VMFunctionBody>(), 1);
149 }
150}