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))]
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
34#[cfg(feature = "experimental-host-interrupt")]
35pub mod interrupt_registry;
36pub mod libcalls;
37
38use std::ptr::NonNull;
39
40pub use crate::exception::{VMExceptionObj, VMExceptionRef};
41pub use crate::export::*;
42pub use crate::extern_ref::{VMExternObj, VMExternRef};
43pub use crate::function_env::VMFunctionEnvironment;
44pub use crate::global::*;
45pub use crate::imports::Imports;
46pub use crate::instance::{InstanceAllocator, VMInstance};
47pub use crate::memory::{
48 LinearMemory, NotifyLocation, VMMemory, VMOwnedMemory, VMSharedMemory,
49 initialize_memory_with_data,
50};
51pub use crate::mmap::{Mmap, MmapType};
52pub use crate::probestack::PROBESTACK;
53pub use crate::sig_registry::SignatureRegistry;
54pub use crate::store::{InternalStoreHandle, MaybeInstanceOwned, StoreHandle, StoreObjects};
55pub use crate::table::{TableElement, VMTable};
56#[doc(hidden)]
57pub use crate::threadconditions::{
58 ExpectedValue, ThreadConditions, ThreadConditionsHandle, WaiterError,
59};
60pub use crate::trap::*;
61pub use crate::vmcontext::{
62 VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext, VMFunctionContext,
63 VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition,
64 VMMemoryImport, VMSharedTagIndex, VMSignatureHash, VMTableDefinition, VMTableImport,
65 VMTrampoline,
66};
67pub use store::StoreObject;
68pub use wasmer_types::LibCall;
69pub use wasmer_types::MemoryError;
70pub use wasmer_types::MemoryStyle;
71use wasmer_types::RawValue;
72pub use wasmer_types::TableStyle;
73pub use wasmer_types::{StoreId, VMBuiltinFunctionIndex, VMOffsets};
74
75pub const VERSION: &str = env!("CARGO_PKG_VERSION");
77
78#[derive(Clone, Copy, Debug)]
80#[repr(transparent)]
81pub struct SectionBodyPtr(pub *const u8);
82
83impl std::ops::Deref for SectionBodyPtr {
84 type Target = *const u8;
85
86 fn deref(&self) -> &Self::Target {
87 &self.0
88 }
89}
90
91#[repr(C)]
96pub struct VMFunctionBody(u8);
97
98#[derive(Clone, Copy, Debug)]
100#[cfg_attr(feature = "artifact-size", derive(loupe::MemoryUsage))]
101#[repr(transparent)]
102pub struct FunctionBodyPtr(pub *const VMFunctionBody);
103
104impl std::ops::Deref for FunctionBodyPtr {
105 type Target = *const VMFunctionBody;
106
107 fn deref(&self) -> &Self::Target {
108 &self.0
109 }
110}
111
112unsafe impl Send for FunctionBodyPtr {}
116unsafe impl Sync for FunctionBodyPtr {}
120
121#[repr(transparent)]
123#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
124pub struct VMFuncRef(pub NonNull<VMCallerCheckedAnyfunc>);
125
126impl VMFuncRef {
127 pub fn into_raw(self) -> RawValue {
129 RawValue {
130 funcref: self.0.as_ptr() as usize,
131 }
132 }
133
134 pub unsafe fn from_raw(raw: RawValue) -> Option<Self> {
139 unsafe { NonNull::new(raw.funcref as *mut VMCallerCheckedAnyfunc).map(Self) }
140 }
141}
142
143#[cfg(test)]
144mod test_vmfunction_body {
145 use super::VMFunctionBody;
146 use std::mem::size_of;
147
148 #[test]
149 fn check_vmfunction_body_offsets() {
150 assert_eq!(size_of::<VMFunctionBody>(), 1);
151 }
152}