mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-31 04:39:28 +00:00
Remove wasmer-{artifact,engine} and merge it into wasmer-compiler and wasmer-vm
This commit is contained in:
61
Cargo.lock
generated
61
Cargo.lock
generated
@ -2789,13 +2789,11 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-test",
|
"wasm-bindgen-test",
|
||||||
"wasmer-artifact",
|
|
||||||
"wasmer-compiler",
|
"wasmer-compiler",
|
||||||
"wasmer-compiler-cranelift",
|
"wasmer-compiler-cranelift",
|
||||||
"wasmer-compiler-llvm",
|
"wasmer-compiler-llvm",
|
||||||
"wasmer-compiler-singlepass",
|
"wasmer-compiler-singlepass",
|
||||||
"wasmer-derive",
|
"wasmer-derive",
|
||||||
"wasmer-engine",
|
|
||||||
"wasmer-engine-universal",
|
"wasmer-engine-universal",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"wasmer-vm",
|
"wasmer-vm",
|
||||||
@ -2804,16 +2802,6 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasmer-artifact"
|
|
||||||
version = "2.3.0"
|
|
||||||
dependencies = [
|
|
||||||
"enumset",
|
|
||||||
"thiserror",
|
|
||||||
"wasmer-compiler",
|
|
||||||
"wasmer-types",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-bin-fuzz"
|
name = "wasmer-bin-fuzz"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
@ -2846,11 +2834,11 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
"typetag",
|
"typetag",
|
||||||
"wasmer",
|
"wasmer",
|
||||||
|
"wasmer-compiler",
|
||||||
"wasmer-compiler-cranelift",
|
"wasmer-compiler-cranelift",
|
||||||
"wasmer-compiler-llvm",
|
"wasmer-compiler-llvm",
|
||||||
"wasmer-compiler-singlepass",
|
"wasmer-compiler-singlepass",
|
||||||
"wasmer-emscripten",
|
"wasmer-emscripten",
|
||||||
"wasmer-engine",
|
|
||||||
"wasmer-engine-universal",
|
"wasmer-engine-universal",
|
||||||
"wasmer-middlewares",
|
"wasmer-middlewares",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
@ -2894,7 +2882,6 @@ dependencies = [
|
|||||||
"wasmer-compiler-llvm",
|
"wasmer-compiler-llvm",
|
||||||
"wasmer-compiler-singlepass",
|
"wasmer-compiler-singlepass",
|
||||||
"wasmer-emscripten",
|
"wasmer-emscripten",
|
||||||
"wasmer-engine",
|
|
||||||
"wasmer-engine-universal",
|
"wasmer-engine-universal",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"wasmer-vfs",
|
"wasmer-vfs",
|
||||||
@ -2908,15 +2895,21 @@ dependencies = [
|
|||||||
name = "wasmer-compiler"
|
name = "wasmer-compiler"
|
||||||
version = "2.3.0"
|
version = "2.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"backtrace",
|
||||||
"enumset",
|
"enumset",
|
||||||
"hashbrown 0.11.2",
|
"hashbrown 0.11.2",
|
||||||
|
"lazy_static",
|
||||||
|
"memmap2",
|
||||||
|
"more-asserts",
|
||||||
"rkyv",
|
"rkyv",
|
||||||
|
"rustc-demangle",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_bytes",
|
"serde_bytes",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"target-lexicon 0.12.4",
|
"target-lexicon 0.12.4",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
|
"wasmer-vm",
|
||||||
"wasmparser 0.83.0",
|
"wasmparser 0.83.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -3026,41 +3019,6 @@ dependencies = [
|
|||||||
"wasmer",
|
"wasmer",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasmer-engine"
|
|
||||||
version = "2.3.0"
|
|
||||||
dependencies = [
|
|
||||||
"backtrace",
|
|
||||||
"enumset",
|
|
||||||
"lazy_static",
|
|
||||||
"memmap2",
|
|
||||||
"more-asserts",
|
|
||||||
"rustc-demangle",
|
|
||||||
"serde",
|
|
||||||
"serde_bytes",
|
|
||||||
"target-lexicon 0.12.4",
|
|
||||||
"thiserror",
|
|
||||||
"wasmer-artifact",
|
|
||||||
"wasmer-compiler",
|
|
||||||
"wasmer-types",
|
|
||||||
"wasmer-vm",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasmer-engine-dummy"
|
|
||||||
version = "2.3.0"
|
|
||||||
dependencies = [
|
|
||||||
"bincode",
|
|
||||||
"enumset",
|
|
||||||
"serde",
|
|
||||||
"serde_bytes",
|
|
||||||
"wasmer-artifact",
|
|
||||||
"wasmer-compiler",
|
|
||||||
"wasmer-engine",
|
|
||||||
"wasmer-types",
|
|
||||||
"wasmer-vm",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-engine-universal"
|
name = "wasmer-engine-universal"
|
||||||
version = "2.3.0"
|
version = "2.3.0"
|
||||||
@ -3071,7 +3029,6 @@ dependencies = [
|
|||||||
"region",
|
"region",
|
||||||
"rkyv",
|
"rkyv",
|
||||||
"wasmer-compiler",
|
"wasmer-compiler",
|
||||||
"wasmer-engine",
|
|
||||||
"wasmer-engine-universal-artifact",
|
"wasmer-engine-universal-artifact",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"wasmer-vm",
|
"wasmer-vm",
|
||||||
@ -3086,7 +3043,6 @@ dependencies = [
|
|||||||
"enumset",
|
"enumset",
|
||||||
"rkyv",
|
"rkyv",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"wasmer-artifact",
|
|
||||||
"wasmer-compiler",
|
"wasmer-compiler",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
]
|
]
|
||||||
@ -3180,7 +3136,6 @@ dependencies = [
|
|||||||
"scopeguard",
|
"scopeguard",
|
||||||
"serde",
|
"serde",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"wasmer-artifact",
|
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
@ -3301,8 +3256,6 @@ dependencies = [
|
|||||||
"wasmer-compiler-llvm",
|
"wasmer-compiler-llvm",
|
||||||
"wasmer-compiler-singlepass",
|
"wasmer-compiler-singlepass",
|
||||||
"wasmer-emscripten",
|
"wasmer-emscripten",
|
||||||
"wasmer-engine",
|
|
||||||
"wasmer-engine-dummy",
|
|
||||||
"wasmer-engine-universal",
|
"wasmer-engine-universal",
|
||||||
"wasmer-middlewares",
|
"wasmer-middlewares",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
|
@ -16,7 +16,6 @@ wasmer-compiler-cranelift = { version = "=2.3.0", path = "lib/compiler-cranelift
|
|||||||
wasmer-compiler-singlepass = { version = "=2.3.0", path = "lib/compiler-singlepass", optional = true }
|
wasmer-compiler-singlepass = { version = "=2.3.0", path = "lib/compiler-singlepass", optional = true }
|
||||||
wasmer-compiler-llvm = { version = "=2.3.0", path = "lib/compiler-llvm", optional = true }
|
wasmer-compiler-llvm = { version = "=2.3.0", path = "lib/compiler-llvm", optional = true }
|
||||||
wasmer-emscripten = { version = "=2.3.0", path = "lib/emscripten", optional = true }
|
wasmer-emscripten = { version = "=2.3.0", path = "lib/emscripten", optional = true }
|
||||||
wasmer-engine = { version = "=2.3.0", path = "lib/engine" }
|
|
||||||
wasmer-engine-universal = { version = "=2.3.0", path = "lib/engine-universal", optional = true }
|
wasmer-engine-universal = { version = "=2.3.0", path = "lib/engine-universal", optional = true }
|
||||||
wasmer-wasi = { version = "=2.3.0", path = "lib/wasi", optional = true }
|
wasmer-wasi = { version = "=2.3.0", path = "lib/wasi", optional = true }
|
||||||
wasmer-wast = { version = "=2.3.0", path = "tests/lib/wast", optional = true }
|
wasmer-wast = { version = "=2.3.0", path = "tests/lib/wast", optional = true }
|
||||||
@ -39,7 +38,6 @@ members = [
|
|||||||
"lib/compiler-llvm",
|
"lib/compiler-llvm",
|
||||||
"lib/derive",
|
"lib/derive",
|
||||||
"lib/emscripten",
|
"lib/emscripten",
|
||||||
"lib/engine",
|
|
||||||
"lib/engine-universal",
|
"lib/engine-universal",
|
||||||
"lib/object",
|
"lib/object",
|
||||||
"lib/vfs",
|
"lib/vfs",
|
||||||
@ -72,7 +70,6 @@ anyhow = "1.0"
|
|||||||
criterion = "0.3"
|
criterion = "0.3"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
serial_test = "0.5"
|
serial_test = "0.5"
|
||||||
wasmer-engine-dummy = { path = "tests/lib/engine-dummy" }
|
|
||||||
compiler-test-derive = { path = "tests/lib/compiler-test-derive" }
|
compiler-test-derive = { path = "tests/lib/compiler-test-derive" }
|
||||||
tempfile = "3.1"
|
tempfile = "3.1"
|
||||||
# For logging tests using the `RUST_LOG=debug` when testing
|
# For logging tests using the `RUST_LOG=debug` when testing
|
||||||
@ -95,7 +92,6 @@ default = [
|
|||||||
engine = []
|
engine = []
|
||||||
universal = [
|
universal = [
|
||||||
"wasmer-engine-universal",
|
"wasmer-engine-universal",
|
||||||
"engine",
|
|
||||||
]
|
]
|
||||||
cache = ["wasmer-cache"]
|
cache = ["wasmer-cache"]
|
||||||
wast = ["wasmer-wast"]
|
wast = ["wasmer-wast"]
|
||||||
|
@ -22,7 +22,6 @@ edition = "2018"
|
|||||||
# Shared dependencies.
|
# Shared dependencies.
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# - Mandatory shared dependencies.
|
# - Mandatory shared dependencies.
|
||||||
wasmer-artifact = { path = "../artifact", version = "=2.3.0" }
|
|
||||||
indexmap = { version = "1.6", features = ["serde-1"] }
|
indexmap = { version = "1.6", features = ["serde-1"] }
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
@ -36,7 +35,6 @@ wat = { version = "1.0", optional = true }
|
|||||||
wasmer-vm = { path = "../vm", version = "=2.3.0" }
|
wasmer-vm = { path = "../vm", version = "=2.3.0" }
|
||||||
wasmer-compiler = { path = "../compiler", version = "=2.3.0" }
|
wasmer-compiler = { path = "../compiler", version = "=2.3.0" }
|
||||||
wasmer-derive = { path = "../derive", version = "=2.3.0" }
|
wasmer-derive = { path = "../derive", version = "=2.3.0" }
|
||||||
wasmer-engine = { path = "../engine", version = "=2.3.0" }
|
|
||||||
wasmer-types = { path = "../types", version = "=2.3.0" }
|
wasmer-types = { path = "../types", version = "=2.3.0" }
|
||||||
target-lexicon = { version = "0.12.2", default-features = false }
|
target-lexicon = { version = "0.12.2", default-features = false }
|
||||||
# - Optional dependencies for `sys`.
|
# - Optional dependencies for `sys`.
|
||||||
|
@ -90,7 +90,7 @@ pub enum WasmError {
|
|||||||
|
|
||||||
/// The Serialize error can occur when serializing a
|
/// The Serialize error can occur when serializing a
|
||||||
/// compiled Module into a binary.
|
/// compiled Module into a binary.
|
||||||
/// Copied from wasmer_engine::SerializeError
|
/// Copied from wasmer_compiler::SerializeError
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "std", derive(Error))]
|
#[cfg_attr(feature = "std", derive(Error))]
|
||||||
pub enum SerializeError {
|
pub enum SerializeError {
|
||||||
@ -104,7 +104,7 @@ pub enum SerializeError {
|
|||||||
|
|
||||||
/// The Deserialize error can occur when loading a
|
/// The Deserialize error can occur when loading a
|
||||||
/// compiled Module from a binary.
|
/// compiled Module from a binary.
|
||||||
/// Copied from wasmer_engine::DeSerializeError
|
/// Copied from wasmer_compiler::DeSerializeError
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum DeserializeError {
|
pub enum DeserializeError {
|
||||||
/// An IO error
|
/// An IO error
|
||||||
|
2
lib/api/src/js/externals/mod.rs
vendored
2
lib/api/src/js/externals/mod.rs
vendored
@ -44,7 +44,7 @@ impl Extern {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an `Extern` from an `wasmer_engine::Export`.
|
/// Create an `Extern` from an `wasmer_compiler::Export`.
|
||||||
pub fn from_vm_export(store: &Store, export: Export) -> Self {
|
pub fn from_vm_export(store: &Store, export: Export) -> Self {
|
||||||
match export {
|
match export {
|
||||||
Export::Function(f) => Self::Function(Function::from_vm_export(store, f)),
|
Export::Function(f) => Self::Function(Function::from_vm_export(store, f)),
|
||||||
|
@ -53,7 +53,7 @@ impl RuntimeError {
|
|||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// let trap = wasmer_engine::RuntimeError::new("unexpected error");
|
/// let trap = wasmer_compiler::RuntimeError::new("unexpected error");
|
||||||
/// assert_eq!("unexpected error", trap.message());
|
/// assert_eq!("unexpected error", trap.message());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<I: Into<String>>(message: I) -> Self {
|
pub fn new<I: Into<String>>(message: I) -> Self {
|
||||||
|
@ -5,7 +5,7 @@ use indexmap::IndexMap;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter::{ExactSizeIterator, FromIterator};
|
use std::iter::{ExactSizeIterator, FromIterator};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use wasmer_engine::Export;
|
use wasmer_compiler::Export;
|
||||||
|
|
||||||
/// The `ExportError` can happen when trying to get a specific
|
/// The `ExportError` can happen when trying to get a specific
|
||||||
/// export [`Extern`] from the [`Instance`] exports.
|
/// export [`Extern`] from the [`Instance`] exports.
|
||||||
|
2
lib/api/src/sys/externals/function.rs
vendored
2
lib/api/src/sys/externals/function.rs
vendored
@ -12,7 +12,7 @@ use std::cmp::max;
|
|||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasmer_engine::{Export, ExportFunction, ExportFunctionMetadata};
|
use wasmer_compiler::{Export, ExportFunction, ExportFunctionMetadata};
|
||||||
use wasmer_vm::{
|
use wasmer_vm::{
|
||||||
on_host_stack, raise_user_trap, resume_panic, wasmer_call_trampoline, ImportInitializerFuncPtr,
|
on_host_stack, raise_user_trap, resume_panic, wasmer_call_trampoline, ImportInitializerFuncPtr,
|
||||||
VMCallerCheckedAnyfunc, VMDynamicFunctionContext, VMFuncRef, VMFunction, VMFunctionBody,
|
VMCallerCheckedAnyfunc, VMDynamicFunctionContext, VMFuncRef, VMFunction, VMFunctionBody,
|
||||||
|
2
lib/api/src/sys/externals/global.rs
vendored
2
lib/api/src/sys/externals/global.rs
vendored
@ -7,7 +7,7 @@ use crate::sys::Mutability;
|
|||||||
use crate::sys::RuntimeError;
|
use crate::sys::RuntimeError;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasmer_engine::Export;
|
use wasmer_compiler::Export;
|
||||||
use wasmer_vm::{Global as RuntimeGlobal, VMGlobal};
|
use wasmer_vm::{Global as RuntimeGlobal, VMGlobal};
|
||||||
|
|
||||||
/// A WebAssembly `global` instance.
|
/// A WebAssembly `global` instance.
|
||||||
|
2
lib/api/src/sys/externals/memory.rs
vendored
2
lib/api/src/sys/externals/memory.rs
vendored
@ -8,7 +8,7 @@ use std::mem;
|
|||||||
use std::mem::MaybeUninit;
|
use std::mem::MaybeUninit;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasmer_engine::Export;
|
use wasmer_compiler::Export;
|
||||||
use wasmer_types::Pages;
|
use wasmer_types::Pages;
|
||||||
use wasmer_vm::{MemoryError, VMMemory};
|
use wasmer_vm::{MemoryError, VMMemory};
|
||||||
|
|
||||||
|
4
lib/api/src/sys/externals/mod.rs
vendored
4
lib/api/src/sys/externals/mod.rs
vendored
@ -15,7 +15,7 @@ use crate::sys::exports::{ExportError, Exportable};
|
|||||||
use crate::sys::store::{Store, StoreObject};
|
use crate::sys::store::{Store, StoreObject};
|
||||||
use crate::sys::ExternType;
|
use crate::sys::ExternType;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use wasmer_engine::Export;
|
use wasmer_compiler::Export;
|
||||||
|
|
||||||
/// An `Extern` is the runtime representation of an entity that
|
/// An `Extern` is the runtime representation of an entity that
|
||||||
/// can be imported or exported.
|
/// can be imported or exported.
|
||||||
@ -44,7 +44,7 @@ impl Extern {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an `Extern` from an `wasmer_engine::Export`.
|
/// Create an `Extern` from an `wasmer_compiler::Export`.
|
||||||
pub fn from_vm_export(store: &Store, export: Export) -> Self {
|
pub fn from_vm_export(store: &Store, export: Export) -> Self {
|
||||||
match export {
|
match export {
|
||||||
Export::Function(f) => Self::Function(Function::from_vm_export(store, f)),
|
Export::Function(f) => Self::Function(Function::from_vm_export(store, f)),
|
||||||
|
2
lib/api/src/sys/externals/table.rs
vendored
2
lib/api/src/sys/externals/table.rs
vendored
@ -5,7 +5,7 @@ use crate::sys::types::{Val, ValFuncRef};
|
|||||||
use crate::sys::RuntimeError;
|
use crate::sys::RuntimeError;
|
||||||
use crate::sys::TableType;
|
use crate::sys::TableType;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasmer_engine::Export;
|
use wasmer_compiler::Export;
|
||||||
use wasmer_vm::{Table as RuntimeTable, TableElement, VMTable};
|
use wasmer_vm::{Table as RuntimeTable, TableElement, VMTable};
|
||||||
|
|
||||||
/// A WebAssembly `table` instance.
|
/// A WebAssembly `table` instance.
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use crate::{Exports, Extern, Module};
|
use crate::{Exports, Extern, Module};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use wasmer_engine::LinkError;
|
use wasmer_compiler::LinkError;
|
||||||
use wasmer_types::ImportError;
|
use wasmer_types::ImportError;
|
||||||
|
|
||||||
/// All of the import data used when instantiating.
|
/// All of the import data used when instantiating.
|
||||||
|
@ -69,12 +69,12 @@ pub enum InstantiationError {
|
|||||||
HostEnvInitialization(HostEnvInitError),
|
HostEnvInitialization(HostEnvInitError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<wasmer_engine::InstantiationError> for InstantiationError {
|
impl From<wasmer_compiler::InstantiationError> for InstantiationError {
|
||||||
fn from(other: wasmer_engine::InstantiationError) -> Self {
|
fn from(other: wasmer_compiler::InstantiationError) -> Self {
|
||||||
match other {
|
match other {
|
||||||
wasmer_engine::InstantiationError::Link(e) => Self::Link(e),
|
wasmer_compiler::InstantiationError::Link(e) => Self::Link(e),
|
||||||
wasmer_engine::InstantiationError::Start(e) => Self::Start(e),
|
wasmer_compiler::InstantiationError::Start(e) => Self::Start(e),
|
||||||
wasmer_engine::InstantiationError::CpuFeature(e) => Self::CpuFeature(e),
|
wasmer_compiler::InstantiationError::CpuFeature(e) => Self::CpuFeature(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,9 +50,10 @@ pub use target_lexicon::{Architecture, CallingConvention, OperatingSystem, Tripl
|
|||||||
pub use wasmer_compiler::{
|
pub use wasmer_compiler::{
|
||||||
wasmparser, CompilerConfig, FunctionMiddleware, MiddlewareReaderState, ModuleMiddleware,
|
wasmparser, CompilerConfig, FunctionMiddleware, MiddlewareReaderState, ModuleMiddleware,
|
||||||
};
|
};
|
||||||
pub use wasmer_compiler::{CpuFeature, Features, Target};
|
pub use wasmer_compiler::{
|
||||||
|
CpuFeature, Engine, Export, Features, FrameInfo, LinkError, RuntimeError, Target, Tunables,
|
||||||
|
};
|
||||||
pub use wasmer_derive::ValueType;
|
pub use wasmer_derive::ValueType;
|
||||||
pub use wasmer_engine::{Engine, Export, FrameInfo, LinkError, RuntimeError, Tunables};
|
|
||||||
pub use wasmer_types::is_wasm;
|
pub use wasmer_types::is_wasm;
|
||||||
#[cfg(feature = "experimental-reference-types-extern-ref")]
|
#[cfg(feature = "experimental-reference-types-extern-ref")]
|
||||||
pub use wasmer_types::ExternRef;
|
pub use wasmer_types::ExternRef;
|
||||||
|
@ -7,7 +7,7 @@ use std::io;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use wasmer_engine::Artifact;
|
use wasmer_compiler::Artifact;
|
||||||
#[cfg(feature = "wat")]
|
#[cfg(feature = "wat")]
|
||||||
use wasmer_types::WasmError;
|
use wasmer_types::WasmError;
|
||||||
use wasmer_types::{
|
use wasmer_types::{
|
||||||
|
@ -12,7 +12,7 @@ use std::marker::PhantomData;
|
|||||||
use crate::sys::externals::function::{DynamicFunction, VMDynamicFunction};
|
use crate::sys::externals::function::{DynamicFunction, VMDynamicFunction};
|
||||||
use crate::sys::{FromToNativeWasmType, Function, RuntimeError, Store, WasmTypeList};
|
use crate::sys::{FromToNativeWasmType, Function, RuntimeError, Store, WasmTypeList};
|
||||||
use std::panic::{catch_unwind, AssertUnwindSafe};
|
use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||||
use wasmer_engine::ExportFunction;
|
use wasmer_compiler::ExportFunction;
|
||||||
use wasmer_types::NativeWasmType;
|
use wasmer_types::NativeWasmType;
|
||||||
use wasmer_vm::{VMDynamicFunctionContext, VMFunctionBody, VMFunctionEnvironment, VMFunctionKind};
|
use wasmer_vm::{VMDynamicFunctionContext, VMFunctionBody, VMFunctionEnvironment, VMFunctionKind};
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ use std::fmt;
|
|||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
#[cfg(all(feature = "compiler", feature = "engine"))]
|
#[cfg(all(feature = "compiler", feature = "engine"))]
|
||||||
use wasmer_compiler::CompilerConfig;
|
use wasmer_compiler::CompilerConfig;
|
||||||
use wasmer_engine::{Engine, Tunables};
|
use wasmer_compiler::{Engine, Tunables};
|
||||||
use wasmer_vm::{init_traps, TrapHandler, TrapHandlerFn};
|
use wasmer_vm::{init_traps, TrapHandler, TrapHandlerFn};
|
||||||
|
|
||||||
/// The store represents all global state that can be manipulated by
|
/// The store represents all global state that can be manipulated by
|
||||||
|
@ -2,8 +2,7 @@ use crate::sys::{MemoryType, Pages, TableType};
|
|||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use target_lexicon::PointerWidth;
|
use target_lexicon::PointerWidth;
|
||||||
use wasmer_compiler::Target;
|
use wasmer_compiler::{Target, Tunables};
|
||||||
use wasmer_engine::Tunables;
|
|
||||||
use wasmer_vm::MemoryError;
|
use wasmer_vm::MemoryError;
|
||||||
use wasmer_vm::{
|
use wasmer_vm::{
|
||||||
LinearMemory, LinearTable, Memory, MemoryStyle, Table, TableStyle, VMMemoryDefinition,
|
LinearMemory, LinearTable, Memory, MemoryStyle, Table, TableStyle, VMMemoryDefinition,
|
||||||
|
@ -70,7 +70,7 @@ impl ValFuncRef for Val {
|
|||||||
.engine()
|
.engine()
|
||||||
.lookup_signature(item.type_index)
|
.lookup_signature(item.type_index)
|
||||||
.expect("Signature not found in store");
|
.expect("Signature not found in store");
|
||||||
let export = wasmer_engine::ExportFunction {
|
let export = wasmer_compiler::ExportFunction {
|
||||||
// TODO:
|
// TODO:
|
||||||
// figure out if we ever need a value here: need testing with complicated import patterns
|
// figure out if we ever need a value here: need testing with complicated import patterns
|
||||||
metadata: None,
|
metadata: None,
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "wasmer-artifact"
|
|
||||||
version = "2.3.0"
|
|
||||||
description = "Wasmer Artifact abstraction"
|
|
||||||
categories = ["wasm"]
|
|
||||||
keywords = ["wasm", "webassembly", "engine"]
|
|
||||||
authors = ["Wasmer Engineering Team <engineering@wasmer.io>"]
|
|
||||||
repository = "https://github.com/wasmerio/wasmer"
|
|
||||||
license = "MIT OR Apache-2.0 WITH LLVM-exception "
|
|
||||||
readme = "README.md"
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
wasmer-types = { path = "../types", version = "=2.3.0" }
|
|
||||||
wasmer-compiler = { path = "../compiler", version = "=2.3.0" }
|
|
||||||
thiserror = "1.0"
|
|
||||||
enumset = "1.0"
|
|
||||||
|
|
||||||
[badges]
|
|
||||||
maintenance = { status = "actively-developed" }
|
|
@ -1,18 +0,0 @@
|
|||||||
# `wasmer-artifact` [](https://github.com/wasmerio/wasmer/actions?query=workflow%3Abuild) [](https://slack.wasmer.io) [](https://github.com/wasmerio/wasmer/blob/master/LICENSE)
|
|
||||||
|
|
||||||
|
|
||||||
This crate is the general abstraction for creating Artifacts in Wasmer.
|
|
||||||
|
|
||||||
### Acknowledgments
|
|
||||||
|
|
||||||
This project borrowed some of the code of the trap implementation from
|
|
||||||
the [`wasmtime-api`], the code since then has evolved significantly.
|
|
||||||
|
|
||||||
Please check [Wasmer `ATTRIBUTIONS`] to further see licenses and other
|
|
||||||
attributions of the project.
|
|
||||||
|
|
||||||
|
|
||||||
[`wasmer-engine-universal`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-universal
|
|
||||||
[`wasmer-engine-dummy`]: https://github.com/wasmerio/wasmer/tree/master/tests/lib/engine-dummy
|
|
||||||
[`wasmtime-api`]: https://crates.io/crates/wasmtime
|
|
||||||
[Wasmer `ATTRIBUTIONS`]: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md
|
|
@ -1,17 +0,0 @@
|
|||||||
/// A placeholder byte-sized type which is just used to provide some amount of type
|
|
||||||
/// safety when dealing with pointers to JIT-compiled function bodies. Note that it's
|
|
||||||
/// deliberately not Copy, as we shouldn't be carelessly copying function body bytes
|
|
||||||
/// around.
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct VMFunctionBody(u8);
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test_vmfunction_body {
|
|
||||||
use super::VMFunctionBody;
|
|
||||||
use std::mem::size_of;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn check_vmfunction_body_offsets() {
|
|
||||||
assert_eq!(size_of::<VMFunctionBody>(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
//! Generic Artifact abstraction for Wasmer Engines.
|
|
||||||
|
|
||||||
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
|
|
||||||
#![warn(unused_import_braces)]
|
|
||||||
#![cfg_attr(
|
|
||||||
feature = "cargo-clippy",
|
|
||||||
allow(clippy::new_without_default, clippy::new_without_default)
|
|
||||||
)]
|
|
||||||
#![cfg_attr(
|
|
||||||
feature = "cargo-clippy",
|
|
||||||
warn(
|
|
||||||
clippy::float_arithmetic,
|
|
||||||
clippy::mut_mut,
|
|
||||||
clippy::nonminimal_bool,
|
|
||||||
clippy::map_unwrap_or,
|
|
||||||
clippy::print_stdout,
|
|
||||||
clippy::unicode_not_nfc,
|
|
||||||
clippy::use_self
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
|
|
||||||
mod artifact;
|
|
||||||
mod funcbody;
|
|
||||||
|
|
||||||
pub use crate::artifact::{ArtifactCreate, MetadataHeader, Upcastable};
|
|
||||||
pub use crate::funcbody::VMFunctionBody;
|
|
||||||
|
|
||||||
/// Version number of this crate.
|
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
||||||
|
|
||||||
/// A safe wrapper around `VMFunctionBody`.
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
#[repr(transparent)]
|
|
||||||
pub struct FunctionBodyPtr(pub *const VMFunctionBody);
|
|
||||||
|
|
||||||
impl std::ops::Deref for FunctionBodyPtr {
|
|
||||||
type Target = *const VMFunctionBody;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// # Safety
|
|
||||||
/// The VMFunctionBody that this points to is opaque, so there's no data to
|
|
||||||
/// read or write through this pointer. This is essentially a usize.
|
|
||||||
unsafe impl Send for FunctionBodyPtr {}
|
|
||||||
/// # Safety
|
|
||||||
/// The VMFunctionBody that this points to is opaque, so there's no data to
|
|
||||||
/// read or write through this pointer. This is essentially a usize.
|
|
||||||
unsafe impl Sync for FunctionBodyPtr {}
|
|
@ -27,7 +27,7 @@ wasmer-compiler-cranelift = { version = "=2.3.0", path = "../compiler-cranelift"
|
|||||||
wasmer-compiler-singlepass = { version = "=2.3.0", path = "../compiler-singlepass", optional = true }
|
wasmer-compiler-singlepass = { version = "=2.3.0", path = "../compiler-singlepass", optional = true }
|
||||||
wasmer-compiler-llvm = { version = "=2.3.0", path = "../compiler-llvm", optional = true }
|
wasmer-compiler-llvm = { version = "=2.3.0", path = "../compiler-llvm", optional = true }
|
||||||
wasmer-emscripten = { version = "=2.3.0", path = "../emscripten", optional = true }
|
wasmer-emscripten = { version = "=2.3.0", path = "../emscripten", optional = true }
|
||||||
wasmer-engine = { version = "=2.3.0", path = "../engine" }
|
wasmer-compiler = { version = "=2.3.0", path = "../compiler" }
|
||||||
wasmer-engine-universal = { version = "=2.3.0", path = "../engine-universal", optional = true }
|
wasmer-engine-universal = { version = "=2.3.0", path = "../engine-universal", optional = true }
|
||||||
wasmer-middlewares = { version = "=2.3.0", path = "../middlewares", optional = true }
|
wasmer-middlewares = { version = "=2.3.0", path = "../middlewares", optional = true }
|
||||||
wasmer-wasi = { version = "=2.3.0", path = "../wasi", default-features = false, features = ["host-fs", "sys"], optional = true }
|
wasmer-wasi = { version = "=2.3.0", path = "../wasi", default-features = false, features = ["host-fs", "sys"], optional = true }
|
||||||
@ -55,14 +55,12 @@ default = [
|
|||||||
]
|
]
|
||||||
wat = ["wasmer-api/wat"]
|
wat = ["wasmer-api/wat"]
|
||||||
wasi = ["wasmer-wasi"]
|
wasi = ["wasmer-wasi"]
|
||||||
engine = []
|
|
||||||
middlewares = [
|
middlewares = [
|
||||||
"compiler",
|
"compiler",
|
||||||
"wasmer-middlewares",
|
"wasmer-middlewares",
|
||||||
]
|
]
|
||||||
universal = [
|
universal = [
|
||||||
"wasmer-engine-universal",
|
"wasmer-engine-universal",
|
||||||
"engine",
|
|
||||||
]
|
]
|
||||||
compiler = [
|
compiler = [
|
||||||
"wasmer-api/compiler",
|
"wasmer-api/compiler",
|
||||||
|
@ -31,7 +31,6 @@ wasmer-compiler-cranelift = { version = "=2.3.0", path = "../compiler-cranelift"
|
|||||||
wasmer-compiler-singlepass = { version = "=2.3.0", path = "../compiler-singlepass", optional = true }
|
wasmer-compiler-singlepass = { version = "=2.3.0", path = "../compiler-singlepass", optional = true }
|
||||||
wasmer-compiler-llvm = { version = "=2.3.0", path = "../compiler-llvm", optional = true }
|
wasmer-compiler-llvm = { version = "=2.3.0", path = "../compiler-llvm", optional = true }
|
||||||
wasmer-emscripten = { version = "=2.3.0", path = "../emscripten", optional = true }
|
wasmer-emscripten = { version = "=2.3.0", path = "../emscripten", optional = true }
|
||||||
wasmer-engine = { version = "=2.3.0", path = "../engine" }
|
|
||||||
wasmer-engine-universal = { version = "=2.3.0", path = "../engine-universal", optional = true }
|
wasmer-engine-universal = { version = "=2.3.0", path = "../engine-universal", optional = true }
|
||||||
wasmer-vm = { version = "=2.3.0", path = "../vm" }
|
wasmer-vm = { version = "=2.3.0", path = "../vm" }
|
||||||
wasmer-wasi = { version = "=2.3.0", path = "../wasi", optional = true }
|
wasmer-wasi = { version = "=2.3.0", path = "../wasi", optional = true }
|
||||||
|
@ -22,6 +22,15 @@ serde_bytes = { version = "0.11", optional = true }
|
|||||||
smallvec = "1.6"
|
smallvec = "1.6"
|
||||||
rkyv = { version = "0.7.38", features = ["indexmap"] }
|
rkyv = { version = "0.7.38", features = ["indexmap"] }
|
||||||
|
|
||||||
|
backtrace = "0.3"
|
||||||
|
rustc-demangle = "0.1"
|
||||||
|
memmap2 = "0.5"
|
||||||
|
more-asserts = "0.2"
|
||||||
|
lazy_static = "1.4"
|
||||||
|
|
||||||
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
|
wasmer-vm = { path = "../vm", version = "=2.3.0" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std", "enable-serde" ]
|
default = ["std", "enable-serde" ]
|
||||||
# This feature is for compiler implementors, it enables using `Compiler` and
|
# This feature is for compiler implementors, it enables using `Compiler` and
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
//! Generic Artifact abstraction for Wasmer Engines.
|
||||||
|
|
||||||
|
use crate::{CpuFeature, Features};
|
||||||
use enumset::EnumSet;
|
use enumset::EnumSet;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{fs, mem};
|
use std::{fs, mem};
|
||||||
use wasmer_compiler::{CpuFeature, Features};
|
|
||||||
use wasmer_types::entity::PrimaryMap;
|
use wasmer_types::entity::PrimaryMap;
|
||||||
use wasmer_types::{DeserializeError, SerializeError};
|
use wasmer_types::{DeserializeError, SerializeError};
|
||||||
use wasmer_types::{
|
use wasmer_types::{
|
@ -1,8 +1,7 @@
|
|||||||
|
use crate::CpuFeature;
|
||||||
use crate::{resolve_imports, Export, InstantiationError, RuntimeError, Tunables};
|
use crate::{resolve_imports, Export, InstantiationError, RuntimeError, Tunables};
|
||||||
|
use crate::{ArtifactCreate, Upcastable};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
pub use wasmer_artifact::MetadataHeader;
|
|
||||||
use wasmer_artifact::{ArtifactCreate, Upcastable};
|
|
||||||
use wasmer_compiler::CpuFeature;
|
|
||||||
use wasmer_types::entity::BoxedSlice;
|
use wasmer_types::entity::BoxedSlice;
|
||||||
use wasmer_types::{DataInitializer, FunctionIndex, LocalFunctionIndex, SignatureIndex};
|
use wasmer_types::{DataInitializer, FunctionIndex, LocalFunctionIndex, SignatureIndex};
|
||||||
use wasmer_vm::{
|
use wasmer_vm::{
|
@ -1,5 +1,5 @@
|
|||||||
//! The WebAssembly possible errors
|
//! The WebAssembly possible errors
|
||||||
use crate::trap::RuntimeError;
|
use crate::engine::trap::RuntimeError;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
pub use wasmer_types::{DeserializeError, ImportError, SerializeError};
|
pub use wasmer_types::{DeserializeError, ImportError, SerializeError};
|
||||||
|
|
@ -1,12 +1,12 @@
|
|||||||
//! Engine trait and associated types.
|
//! Engine trait and associated types.
|
||||||
|
|
||||||
use crate::tunables::Tunables;
|
use crate::engine::tunables::Tunables;
|
||||||
use crate::Artifact;
|
use crate::Artifact;
|
||||||
|
use crate::Target;
|
||||||
use memmap2::Mmap;
|
use memmap2::Mmap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasmer_compiler::Target;
|
|
||||||
use wasmer_types::{CompileError, DeserializeError, FunctionType};
|
use wasmer_types::{CompileError, DeserializeError, FunctionType};
|
||||||
use wasmer_vm::{VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex};
|
use wasmer_vm::{VMCallerCheckedAnyfunc, VMFuncRef, VMSharedSignatureIndex};
|
||||||
|
|
17
lib/compiler/src/engine/mod.rs
Normal file
17
lib/compiler/src/engine/mod.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
//! Generic Engine abstraction for Wasmer Engines.
|
||||||
|
|
||||||
|
mod artifact;
|
||||||
|
mod error;
|
||||||
|
mod export;
|
||||||
|
mod inner;
|
||||||
|
mod resolver;
|
||||||
|
mod trap;
|
||||||
|
mod tunables;
|
||||||
|
|
||||||
|
pub use self::artifact::Artifact;
|
||||||
|
pub use self::error::{InstantiationError, LinkError};
|
||||||
|
pub use self::export::{Export, ExportFunction, ExportFunctionMetadata};
|
||||||
|
pub use self::inner::{Engine, EngineId};
|
||||||
|
pub use self::resolver::resolve_imports;
|
||||||
|
pub use self::trap::*;
|
||||||
|
pub use self::tunables::Tunables;
|
@ -1,4 +1,4 @@
|
|||||||
use crate::error::LinkError;
|
use crate::engine::error::LinkError;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasmer_types::entity::{EntityRef, PrimaryMap};
|
use wasmer_types::entity::{EntityRef, PrimaryMap};
|
@ -9,7 +9,10 @@
|
|||||||
#![warn(unused_import_braces)]
|
#![warn(unused_import_braces)]
|
||||||
#![cfg_attr(feature = "std", deny(unstable_features))]
|
#![cfg_attr(feature = "std", deny(unstable_features))]
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))]
|
#![cfg_attr(
|
||||||
|
feature = "cargo-clippy",
|
||||||
|
allow(clippy::new_without_default, clippy::upper_case_acronyms)
|
||||||
|
)]
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
warn(
|
warn(
|
||||||
@ -48,6 +51,14 @@ mod lib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod artifact;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
mod engine;
|
||||||
|
|
||||||
|
pub use crate::artifact::*;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub use crate::engine::*;
|
||||||
|
|
||||||
#[cfg(feature = "translator")]
|
#[cfg(feature = "translator")]
|
||||||
mod compiler;
|
mod compiler;
|
||||||
mod target;
|
mod target;
|
||||||
|
@ -19,7 +19,6 @@ wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = [
|
|||||||
"translator",
|
"translator",
|
||||||
] }
|
] }
|
||||||
wasmer-vm = { path = "../vm", version = "=2.3.0" }
|
wasmer-vm = { path = "../vm", version = "=2.3.0" }
|
||||||
wasmer-engine = { path = "../engine", version = "=2.3.0" }
|
|
||||||
# flexbuffers = { path = "../../../flatbuffers/rust/flexbuffers", version = "0.1.0" }
|
# flexbuffers = { path = "../../../flatbuffers/rust/flexbuffers", version = "0.1.0" }
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
leb128 = "0.2"
|
leb128 = "0.2"
|
||||||
|
@ -7,12 +7,12 @@ use enumset::EnumSet;
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_compiler::ModuleEnvironment;
|
use wasmer_compiler::ModuleEnvironment;
|
||||||
use wasmer_compiler::{CpuFeature, Features, Triple};
|
use wasmer_compiler::{
|
||||||
use wasmer_engine::{
|
|
||||||
register_frame_info, Artifact, FunctionExtent, GlobalFrameInfoRegistration, MetadataHeader,
|
register_frame_info, Artifact, FunctionExtent, GlobalFrameInfoRegistration, MetadataHeader,
|
||||||
};
|
};
|
||||||
|
use wasmer_compiler::{CpuFeature, Features, Triple};
|
||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_engine::{Engine, Tunables};
|
use wasmer_compiler::{Engine, Tunables};
|
||||||
use wasmer_engine_universal_artifact::ArtifactCreate;
|
use wasmer_engine_universal_artifact::ArtifactCreate;
|
||||||
use wasmer_engine_universal_artifact::{SerializableModule, UniversalArtifactBuild};
|
use wasmer_engine_universal_artifact::{SerializableModule, UniversalArtifactBuild};
|
||||||
use wasmer_types::entity::{BoxedSlice, PrimaryMap};
|
use wasmer_types::entity::{BoxedSlice, PrimaryMap};
|
||||||
|
@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_compiler::Compiler;
|
use wasmer_compiler::Compiler;
|
||||||
use wasmer_compiler::Target;
|
use wasmer_compiler::Target;
|
||||||
use wasmer_engine::{Artifact, Engine, EngineId, FunctionExtent, Tunables};
|
use wasmer_compiler::{Artifact, Engine, EngineId, FunctionExtent, Tunables};
|
||||||
use wasmer_engine_universal_artifact::UniversalEngineBuilder;
|
use wasmer_engine_universal_artifact::UniversalEngineBuilder;
|
||||||
use wasmer_types::entity::PrimaryMap;
|
use wasmer_types::entity::PrimaryMap;
|
||||||
use wasmer_types::FunctionBody;
|
use wasmer_types::FunctionBody;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Linking for Universal-compiled code.
|
//! Linking for Universal-compiled code.
|
||||||
|
|
||||||
use std::ptr::{read_unaligned, write_unaligned};
|
use std::ptr::{read_unaligned, write_unaligned};
|
||||||
use wasmer_engine::FunctionExtent;
|
use wasmer_compiler::FunctionExtent;
|
||||||
use wasmer_engine_universal_artifact::get_libcall_trampoline;
|
use wasmer_engine_universal_artifact::get_libcall_trampoline;
|
||||||
use wasmer_types::entity::PrimaryMap;
|
use wasmer_types::entity::PrimaryMap;
|
||||||
use wasmer_types::{LocalFunctionIndex, ModuleInfo};
|
use wasmer_types::{LocalFunctionIndex, ModuleInfo};
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "wasmer-engine"
|
|
||||||
version = "2.3.0"
|
|
||||||
description = "Wasmer Engine abstraction"
|
|
||||||
categories = ["wasm"]
|
|
||||||
keywords = ["wasm", "webassembly", "engine"]
|
|
||||||
authors = ["Wasmer Engineering Team <engineering@wasmer.io>"]
|
|
||||||
repository = "https://github.com/wasmerio/wasmer"
|
|
||||||
license = "MIT OR Apache-2.0 WITH LLVM-exception "
|
|
||||||
readme = "README.md"
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
wasmer-types = { path = "../types", version = "=2.3.0" }
|
|
||||||
wasmer-compiler = { path = "../compiler", version = "=2.3.0" }
|
|
||||||
wasmer-artifact = { path = "../artifact", version = "=2.3.0" }
|
|
||||||
target-lexicon = { version = "0.12.2", default-features = false }
|
|
||||||
# flexbuffers = { path = "../../../flatbuffers/rust/flexbuffers", version = "0.1.0" }
|
|
||||||
backtrace = "0.3"
|
|
||||||
rustc-demangle = "0.1"
|
|
||||||
memmap2 = "0.5"
|
|
||||||
more-asserts = "0.2"
|
|
||||||
thiserror = "1.0"
|
|
||||||
serde = { version = "1.0", features = ["derive", "rc"] }
|
|
||||||
serde_bytes = { version = "0.11" }
|
|
||||||
lazy_static = "1.4"
|
|
||||||
enumset = "1.0"
|
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
||||||
wasmer-vm = { path = "../vm", version = "=2.3.0" }
|
|
||||||
|
|
||||||
[badges]
|
|
||||||
maintenance = { status = "actively-developed" }
|
|
@ -1,32 +0,0 @@
|
|||||||
# `wasmer-engine` [](https://github.com/wasmerio/wasmer/actions?query=workflow%3Abuild) [](https://slack.wasmer.io) [](https://github.com/wasmerio/wasmer/blob/master/LICENSE)
|
|
||||||
|
|
||||||
This crate is the general abstraction for creating Engines in Wasmer.
|
|
||||||
|
|
||||||
Wasmer Engines are mainly responsible for two things:
|
|
||||||
* Transform the compilation code (from any Wasmer Compiler) to
|
|
||||||
**create** an `Artifact`,
|
|
||||||
* **Load** an `Artifact` so it can be used by the user (normally,
|
|
||||||
pushing the code into executable memory and so on).
|
|
||||||
|
|
||||||
It currently has one implementation:
|
|
||||||
|
|
||||||
1. Universal with [`wasmer-engine-universal`],
|
|
||||||
|
|
||||||
## Example Implementation
|
|
||||||
|
|
||||||
Please check [`wasmer-engine-dummy`] for an example implementation for
|
|
||||||
an `Engine`.
|
|
||||||
|
|
||||||
### Acknowledgments
|
|
||||||
|
|
||||||
This project borrowed some of the code of the trap implementation from
|
|
||||||
the [`wasmtime-api`], the code since then has evolved significantly.
|
|
||||||
|
|
||||||
Please check [Wasmer `ATTRIBUTIONS`] to further see licenses and other
|
|
||||||
attributions of the project.
|
|
||||||
|
|
||||||
|
|
||||||
[`wasmer-engine-universal`]: https://github.com/wasmerio/wasmer/tree/master/lib/engine-universal
|
|
||||||
[`wasmer-engine-dummy`]: https://github.com/wasmerio/wasmer/tree/master/tests/lib/engine-dummy
|
|
||||||
[`wasmtime-api`]: https://crates.io/crates/wasmtime
|
|
||||||
[Wasmer `ATTRIBUTIONS`]: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md
|
|
@ -1,44 +0,0 @@
|
|||||||
//! Generic Engine abstraction for Wasmer Engines.
|
|
||||||
|
|
||||||
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
|
|
||||||
#![warn(unused_import_braces)]
|
|
||||||
#![cfg_attr(
|
|
||||||
feature = "cargo-clippy",
|
|
||||||
allow(
|
|
||||||
clippy::new_without_default,
|
|
||||||
clippy::upper_case_acronyms,
|
|
||||||
clippy::new_without_default
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
#![cfg_attr(
|
|
||||||
feature = "cargo-clippy",
|
|
||||||
warn(
|
|
||||||
clippy::float_arithmetic,
|
|
||||||
clippy::mut_mut,
|
|
||||||
clippy::nonminimal_bool,
|
|
||||||
clippy::map_unwrap_or,
|
|
||||||
clippy::print_stdout,
|
|
||||||
clippy::unicode_not_nfc,
|
|
||||||
clippy::use_self
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
|
|
||||||
mod artifact;
|
|
||||||
mod engine;
|
|
||||||
mod error;
|
|
||||||
mod export;
|
|
||||||
mod resolver;
|
|
||||||
mod trap;
|
|
||||||
mod tunables;
|
|
||||||
|
|
||||||
pub use crate::artifact::Artifact;
|
|
||||||
pub use crate::engine::{Engine, EngineId};
|
|
||||||
pub use crate::error::{InstantiationError, LinkError};
|
|
||||||
pub use crate::export::{Export, ExportFunction, ExportFunctionMetadata};
|
|
||||||
pub use crate::resolver::resolve_imports;
|
|
||||||
pub use crate::trap::*;
|
|
||||||
pub use crate::tunables::Tunables;
|
|
||||||
pub use wasmer_artifact::{ArtifactCreate, MetadataHeader};
|
|
||||||
|
|
||||||
/// Version number of this crate.
|
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
@ -11,7 +11,6 @@ readme = "README.md"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer-artifact = { path = "../artifact", version = "=2.3.0" }
|
|
||||||
wasmer-types = { path = "../types", version = "=2.3.0" }
|
wasmer-types = { path = "../types", version = "=2.3.0" }
|
||||||
wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = ["translator", ] }
|
wasmer-compiler = { path = "../compiler", version = "=2.3.0", features = ["translator", ] }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
@ -9,7 +9,7 @@ use crate::{ArtifactCreate, UniversalEngineBuilder};
|
|||||||
use enumset::EnumSet;
|
use enumset::EnumSet;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasmer_artifact::MetadataHeader;
|
use wasmer_compiler::MetadataHeader;
|
||||||
use wasmer_compiler::{
|
use wasmer_compiler::{
|
||||||
CpuFeature, Features, ModuleEnvironment, ModuleMiddlewareChain, Target, Triple,
|
CpuFeature, Features, ModuleEnvironment, ModuleMiddlewareChain, Target, Triple,
|
||||||
};
|
};
|
||||||
|
@ -28,7 +28,7 @@ pub use crate::artifact::UniversalArtifactBuild;
|
|||||||
pub use crate::engine::UniversalEngineBuilder;
|
pub use crate::engine::UniversalEngineBuilder;
|
||||||
pub use crate::serialize::SerializableModule;
|
pub use crate::serialize::SerializableModule;
|
||||||
pub use crate::trampoline::*;
|
pub use crate::trampoline::*;
|
||||||
pub use wasmer_artifact::{ArtifactCreate, MetadataHeader, Upcastable};
|
pub use wasmer_compiler::{ArtifactCreate, MetadataHeader, Upcastable};
|
||||||
|
|
||||||
/// Version number of this crate.
|
/// Version number of this crate.
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
@ -12,7 +12,6 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer-types = { path = "../types", version = "=2.3.0" }
|
wasmer-types = { path = "../types", version = "=2.3.0" }
|
||||||
wasmer-artifact = { path = "../artifact", version = "=2.3.0" }
|
|
||||||
libc = { version = "^0.2", default-features = false }
|
libc = { version = "^0.2", default-features = false }
|
||||||
memoffset = "0.6"
|
memoffset = "0.6"
|
||||||
indexmap = { version = "1.6", features = ["serde-1"] }
|
indexmap = { version = "1.6", features = ["serde-1"] }
|
||||||
|
@ -5,7 +5,8 @@ use crate::global::Global;
|
|||||||
use crate::instance::WeakOrStrongInstanceRef;
|
use crate::instance::WeakOrStrongInstanceRef;
|
||||||
use crate::memory::Memory;
|
use crate::memory::Memory;
|
||||||
use crate::table::Table;
|
use crate::table::Table;
|
||||||
use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMFunctionKind, VMTrampoline};
|
use crate::vmcontext::{VMFunctionEnvironment, VMFunctionKind, VMTrampoline};
|
||||||
|
use crate::VMFunctionBody;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasmer_types::{FunctionType, MemoryStyle, MemoryType, TableStyle, TableType};
|
use wasmer_types::{FunctionType, MemoryStyle, MemoryType, TableStyle, TableType};
|
||||||
|
|
||||||
|
@ -21,12 +21,11 @@ use crate::memory::{Memory, MemoryError};
|
|||||||
use crate::table::{Table, TableElement};
|
use crate::table::{Table, TableElement};
|
||||||
use crate::trap::{catch_traps, Trap, TrapCode, TrapHandler};
|
use crate::trap::{catch_traps, Trap, TrapCode, TrapHandler};
|
||||||
use crate::vmcontext::{
|
use crate::vmcontext::{
|
||||||
VMBuiltinFunctionsArray, VMCallerCheckedAnyfunc, VMContext, VMFunctionBody,
|
VMBuiltinFunctionsArray, VMCallerCheckedAnyfunc, VMContext, VMFunctionEnvironment,
|
||||||
VMFunctionEnvironment, VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport,
|
VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition,
|
||||||
VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport,
|
VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline,
|
||||||
VMTrampoline,
|
|
||||||
};
|
};
|
||||||
use crate::{FunctionBodyPtr, VMOffsets};
|
use crate::{FunctionBodyPtr, VMFunctionBody, VMOffsets};
|
||||||
use crate::{VMFunction, VMGlobal, VMMemory, VMTable};
|
use crate::{VMFunction, VMGlobal, VMMemory, VMTable};
|
||||||
use memoffset::offset_of;
|
use memoffset::offset_of;
|
||||||
use more_asserts::assert_lt;
|
use more_asserts::assert_lt;
|
||||||
|
@ -54,7 +54,6 @@ pub use crate::vmcontext::{
|
|||||||
VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition,
|
VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition,
|
||||||
VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline,
|
VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline,
|
||||||
};
|
};
|
||||||
pub use wasmer_artifact::{FunctionBodyPtr, VMFunctionBody};
|
|
||||||
pub use wasmer_types::LibCall;
|
pub use wasmer_types::LibCall;
|
||||||
pub use wasmer_types::MemoryStyle;
|
pub use wasmer_types::MemoryStyle;
|
||||||
pub use wasmer_types::TableStyle;
|
pub use wasmer_types::TableStyle;
|
||||||
@ -82,3 +81,43 @@ impl std::ops::Deref for SectionBodyPtr {
|
|||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A placeholder byte-sized type which is just used to provide some amount of type
|
||||||
|
/// safety when dealing with pointers to JIT-compiled function bodies. Note that it's
|
||||||
|
/// deliberately not Copy, as we shouldn't be carelessly copying function body bytes
|
||||||
|
/// around.
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct VMFunctionBody(u8);
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test_vmfunction_body {
|
||||||
|
use super::VMFunctionBody;
|
||||||
|
use std::mem::size_of;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_vmfunction_body_offsets() {
|
||||||
|
assert_eq!(size_of::<VMFunctionBody>(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A safe wrapper around `VMFunctionBody`.
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct FunctionBodyPtr(pub *const VMFunctionBody);
|
||||||
|
|
||||||
|
impl std::ops::Deref for FunctionBodyPtr {
|
||||||
|
type Target = *const VMFunctionBody;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// The VMFunctionBody that this points to is opaque, so there's no data to
|
||||||
|
/// read or write through this pointer. This is essentially a usize.
|
||||||
|
unsafe impl Send for FunctionBodyPtr {}
|
||||||
|
/// # Safety
|
||||||
|
/// The VMFunctionBody that this points to is opaque, so there's no data to
|
||||||
|
/// read or write through this pointer. This is essentially a usize.
|
||||||
|
unsafe impl Sync for FunctionBodyPtr {}
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
//! WebAssembly trap handling, which is built on top of the lower-level
|
//! WebAssembly trap handling, which is built on top of the lower-level
|
||||||
//! signalhandling mechanisms.
|
//! signalhandling mechanisms.
|
||||||
|
|
||||||
use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMTrampoline};
|
use crate::vmcontext::{VMFunctionEnvironment, VMTrampoline};
|
||||||
use crate::Trap;
|
use crate::{Trap, VMFunctionBody};
|
||||||
use backtrace::Backtrace;
|
use backtrace::Backtrace;
|
||||||
use core::ptr::{read, read_unaligned};
|
use core::ptr::{read, read_unaligned};
|
||||||
use corosensei::stack::DefaultStack;
|
use corosensei::stack::DefaultStack;
|
||||||
|
@ -12,13 +12,13 @@ use crate::table::Table;
|
|||||||
use crate::trap::{Trap, TrapCode};
|
use crate::trap::{Trap, TrapCode};
|
||||||
use crate::VMBuiltinFunctionIndex;
|
use crate::VMBuiltinFunctionIndex;
|
||||||
use crate::VMExternRef;
|
use crate::VMExternRef;
|
||||||
|
use crate::VMFunctionBody;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ptr::{self, NonNull};
|
use std::ptr::{self, NonNull};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
pub use wasmer_artifact::VMFunctionBody;
|
|
||||||
|
|
||||||
/// Union representing the first parameter passed when calling a function.
|
/// Union representing the first parameter passed when calling a function.
|
||||||
///
|
///
|
||||||
|
@ -57,8 +57,6 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn engine(&self, compiler_config: Box<dyn CompilerConfig>) -> Box<dyn WasmerEngine> {
|
pub fn engine(&self, compiler_config: Box<dyn CompilerConfig>) -> Box<dyn WasmerEngine> {
|
||||||
#[cfg(not(feature = "engine"))]
|
|
||||||
compile_error!("Plese enable at least one engine via the features");
|
|
||||||
match &self.engine {
|
match &self.engine {
|
||||||
#[cfg(feature = "universal")]
|
#[cfg(feature = "universal")]
|
||||||
Engine::Universal => {
|
Engine::Universal => {
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "wasmer-engine-dummy"
|
|
||||||
version = "2.3.0"
|
|
||||||
authors = ["Wasmer Engineering Team <engineering@wasmer.io>"]
|
|
||||||
description = "Wasmer placeholder engine"
|
|
||||||
license = "MIT"
|
|
||||||
edition = "2018"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
wasmer-artifact = { path = "../../../lib/artifact", version = "=2.3.0" }
|
|
||||||
wasmer-types = { path = "../../../lib/types", version = "=2.3.0" }
|
|
||||||
wasmer-compiler = { path = "../../../lib/compiler", version = "=2.3.0" }
|
|
||||||
wasmer-vm = { path = "../../../lib/vm", version = "=2.3.0" }
|
|
||||||
wasmer-engine = { path = "../../../lib/engine", version = "=2.3.0" }
|
|
||||||
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
|
|
||||||
serde_bytes = { version = "0.11", optional = true }
|
|
||||||
bincode = { version = "1.2", optional = true }
|
|
||||||
enumset = "1.0"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
# Enable the `compiler` feature if you want the engine to compile
|
|
||||||
# and not be only on headless mode.
|
|
||||||
default = ["serialize", "compiler"]
|
|
||||||
compiler = ["wasmer-compiler/translator"]
|
|
||||||
serialize = ["serde", "serde_bytes", "bincode"]
|
|
||||||
|
|
||||||
[badges]
|
|
||||||
# TODO: publish this crate again and deprecate it
|
|
||||||
maintenance = { status = "actively-developed" }
|
|
@ -1,10 +0,0 @@
|
|||||||
# Wasmer Dummy Engine
|
|
||||||
|
|
||||||
The Dummy engine is mainly using for testing and learning proposes.
|
|
||||||
We use it for testing compiler-less code on the `wasmer` API
|
|
||||||
to make sure the API behaves as we expect.
|
|
||||||
|
|
||||||
It can also be used to learn on how to implement a custom engine for Wasmer.
|
|
||||||
|
|
||||||
A dummy engine, can't instantiate a Module. However it can inspect the
|
|
||||||
information related to `ModuleInfo`.
|
|
@ -1,267 +0,0 @@
|
|||||||
//! Define `DummyArtifact` to allow compiling and instantiating to be
|
|
||||||
//! done as separate steps.
|
|
||||||
|
|
||||||
use crate::engine::DummyEngine;
|
|
||||||
use enumset::EnumSet;
|
|
||||||
#[cfg(feature = "serialize")]
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::sync::Arc;
|
|
||||||
use wasmer_artifact::ArtifactCreate;
|
|
||||||
use wasmer_compiler::CpuFeature;
|
|
||||||
#[cfg(feature = "compiler")]
|
|
||||||
use wasmer_compiler::ModuleEnvironment;
|
|
||||||
use wasmer_engine::{Artifact, Engine as _, Tunables};
|
|
||||||
use wasmer_types::entity::{BoxedSlice, PrimaryMap};
|
|
||||||
use wasmer_types::{
|
|
||||||
CompileError, DeserializeError, Features, FunctionIndex, LocalFunctionIndex, MemoryIndex,
|
|
||||||
ModuleInfo, OwnedDataInitializer, SerializeError, SignatureIndex, TableIndex,
|
|
||||||
};
|
|
||||||
use wasmer_vm::{
|
|
||||||
FuncDataRegistry, FunctionBodyPtr, MemoryStyle, TableStyle, VMContext, VMFunctionBody,
|
|
||||||
VMSharedSignatureIndex, VMTrampoline,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Serializable struct for the artifact
|
|
||||||
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
|
|
||||||
pub struct DummyArtifactMetadata {
|
|
||||||
pub module: Arc<ModuleInfo>,
|
|
||||||
pub features: Features,
|
|
||||||
pub data_initializers: Box<[OwnedDataInitializer]>,
|
|
||||||
// Plans for that module
|
|
||||||
pub memory_styles: PrimaryMap<MemoryIndex, MemoryStyle>,
|
|
||||||
pub table_styles: PrimaryMap<TableIndex, TableStyle>,
|
|
||||||
pub cpu_features: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A Dummy artifact.
|
|
||||||
///
|
|
||||||
/// This artifact will point to fake finished functions and trampolines
|
|
||||||
/// as no functions are really compiled.
|
|
||||||
pub struct DummyArtifact {
|
|
||||||
metadata: DummyArtifactMetadata,
|
|
||||||
finished_functions: BoxedSlice<LocalFunctionIndex, FunctionBodyPtr>,
|
|
||||||
finished_function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>,
|
|
||||||
finished_dynamic_function_trampolines: BoxedSlice<FunctionIndex, FunctionBodyPtr>,
|
|
||||||
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
|
|
||||||
func_data_registry: Arc<FuncDataRegistry>,
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn dummy_function(_context: *mut VMContext) {
|
|
||||||
panic!("Dummy engine can't generate functions")
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn dummy_trampoline(
|
|
||||||
_context: *mut VMContext,
|
|
||||||
_callee: *const VMFunctionBody,
|
|
||||||
_values: *mut u128,
|
|
||||||
) {
|
|
||||||
panic!("Dummy engine can't generate trampolines")
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DummyArtifact {
|
|
||||||
const MAGIC_HEADER: &'static [u8] = b"\0wasmer-dummy";
|
|
||||||
|
|
||||||
/// Check if the provided bytes look like a serialized `DummyArtifact`.
|
|
||||||
pub fn is_deserializable(bytes: &[u8]) -> bool {
|
|
||||||
bytes.starts_with(Self::MAGIC_HEADER)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "compiler")]
|
|
||||||
/// Compile a data buffer into a `DummyArtifact`, which may then be instantiated.
|
|
||||||
pub fn new(
|
|
||||||
engine: &DummyEngine,
|
|
||||||
data: &[u8],
|
|
||||||
tunables: &dyn Tunables,
|
|
||||||
) -> Result<Self, CompileError> {
|
|
||||||
let environ = ModuleEnvironment::new();
|
|
||||||
|
|
||||||
let translation = environ.translate(data).map_err(CompileError::Wasm)?;
|
|
||||||
|
|
||||||
let memory_styles: PrimaryMap<MemoryIndex, MemoryStyle> = translation
|
|
||||||
.module
|
|
||||||
.memories
|
|
||||||
.values()
|
|
||||||
.map(|memory_type| tunables.memory_style(memory_type))
|
|
||||||
.collect();
|
|
||||||
let table_styles: PrimaryMap<TableIndex, TableStyle> = translation
|
|
||||||
.module
|
|
||||||
.tables
|
|
||||||
.values()
|
|
||||||
.map(|table_type| tunables.table_style(table_type))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let data_initializers = translation
|
|
||||||
.data_initializers
|
|
||||||
.iter()
|
|
||||||
.map(OwnedDataInitializer::new)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.into_boxed_slice();
|
|
||||||
|
|
||||||
let metadata = DummyArtifactMetadata {
|
|
||||||
module: Arc::new(translation.module),
|
|
||||||
features: Features::default(),
|
|
||||||
data_initializers,
|
|
||||||
memory_styles,
|
|
||||||
table_styles,
|
|
||||||
cpu_features: engine.target().cpu_features().as_u64(),
|
|
||||||
};
|
|
||||||
Self::from_parts(engine, metadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "compiler"))]
|
|
||||||
pub fn new(engine: &DummyEngine, data: &[u8]) -> Result<Self, CompileError> {
|
|
||||||
CompileError::Generic("The compiler feature is not enabled in the DummyEngine")
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "serialize")]
|
|
||||||
/// Deserialize a DummyArtifact
|
|
||||||
pub fn deserialize(engine: &DummyEngine, bytes: &[u8]) -> Result<Self, DeserializeError> {
|
|
||||||
if !Self::is_deserializable(bytes) {
|
|
||||||
return Err(DeserializeError::Incompatible(
|
|
||||||
"The provided bytes are not of the dummy engine".to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let inner_bytes = &bytes[Self::MAGIC_HEADER.len()..];
|
|
||||||
|
|
||||||
let metadata: DummyArtifactMetadata = bincode::deserialize(inner_bytes)
|
|
||||||
.map_err(|e| DeserializeError::CorruptedBinary(format!("{:?}", e)))?;
|
|
||||||
|
|
||||||
Self::from_parts(engine, metadata).map_err(DeserializeError::Compiler)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "serialize"))]
|
|
||||||
pub fn deserialize(engine: &DummyEngine, bytes: &[u8]) -> Result<Self, DeserializeError> {
|
|
||||||
Err(DeserializeError::Generic(
|
|
||||||
"The serializer feature is not enabled in the DummyEngine",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Construct a `DummyArtifact` from component parts.
|
|
||||||
pub fn from_parts(
|
|
||||||
engine: &DummyEngine,
|
|
||||||
metadata: DummyArtifactMetadata,
|
|
||||||
) -> Result<Self, CompileError> {
|
|
||||||
let num_local_functions =
|
|
||||||
metadata.module.functions.len() - metadata.module.num_imported_functions;
|
|
||||||
// We prepare the pointers for the finished functions.
|
|
||||||
let finished_functions: PrimaryMap<LocalFunctionIndex, FunctionBodyPtr> = (0
|
|
||||||
..num_local_functions)
|
|
||||||
.map(|_| FunctionBodyPtr(dummy_function as _))
|
|
||||||
.collect::<PrimaryMap<_, _>>();
|
|
||||||
|
|
||||||
// We prepare the pointers for the finished function call trampolines.
|
|
||||||
let finished_function_call_trampolines: PrimaryMap<SignatureIndex, VMTrampoline> = (0
|
|
||||||
..metadata.module.signatures.len())
|
|
||||||
.map(|_| dummy_trampoline as VMTrampoline)
|
|
||||||
.collect::<PrimaryMap<_, _>>();
|
|
||||||
|
|
||||||
// We prepare the pointers for the finished dynamic function trampolines.
|
|
||||||
let finished_dynamic_function_trampolines: PrimaryMap<FunctionIndex, FunctionBodyPtr> = (0
|
|
||||||
..metadata.module.num_imported_functions)
|
|
||||||
.map(|_| FunctionBodyPtr(dummy_function as _))
|
|
||||||
.collect::<PrimaryMap<_, _>>();
|
|
||||||
|
|
||||||
// Compute indices into the shared signature table.
|
|
||||||
let signatures = {
|
|
||||||
metadata
|
|
||||||
.module
|
|
||||||
.signatures
|
|
||||||
.values()
|
|
||||||
.map(|sig| engine.register_signature(sig))
|
|
||||||
.collect::<PrimaryMap<_, _>>()
|
|
||||||
};
|
|
||||||
|
|
||||||
let finished_functions = finished_functions.into_boxed_slice();
|
|
||||||
let finished_function_call_trampolines =
|
|
||||||
finished_function_call_trampolines.into_boxed_slice();
|
|
||||||
let finished_dynamic_function_trampolines =
|
|
||||||
finished_dynamic_function_trampolines.into_boxed_slice();
|
|
||||||
let signatures = signatures.into_boxed_slice();
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
metadata,
|
|
||||||
finished_functions,
|
|
||||||
finished_function_call_trampolines,
|
|
||||||
finished_dynamic_function_trampolines,
|
|
||||||
signatures,
|
|
||||||
func_data_registry: engine.func_data().clone(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ArtifactCreate for DummyArtifact {
|
|
||||||
fn module(&self) -> Arc<ModuleInfo> {
|
|
||||||
self.metadata.module.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn module_ref(&self) -> &ModuleInfo {
|
|
||||||
&self.metadata.module
|
|
||||||
}
|
|
||||||
|
|
||||||
fn module_mut(&mut self) -> Option<&mut ModuleInfo> {
|
|
||||||
Arc::get_mut(&mut self.metadata.module)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn features(&self) -> &Features {
|
|
||||||
&self.metadata.features
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cpu_features(&self) -> EnumSet<CpuFeature> {
|
|
||||||
EnumSet::from_u64(self.metadata.cpu_features)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn data_initializers(&self) -> &[OwnedDataInitializer] {
|
|
||||||
&*self.metadata.data_initializers
|
|
||||||
}
|
|
||||||
|
|
||||||
fn memory_styles(&self) -> &PrimaryMap<MemoryIndex, MemoryStyle> {
|
|
||||||
&self.metadata.memory_styles
|
|
||||||
}
|
|
||||||
|
|
||||||
fn table_styles(&self) -> &PrimaryMap<TableIndex, TableStyle> {
|
|
||||||
&self.metadata.table_styles
|
|
||||||
}
|
|
||||||
#[cfg(feature = "serialize")]
|
|
||||||
fn serialize(&self) -> Result<Vec<u8>, SerializeError> {
|
|
||||||
let bytes = bincode::serialize(&self.metadata)
|
|
||||||
.map_err(|e| SerializeError::Generic(format!("{:?}", e)))?;
|
|
||||||
|
|
||||||
// Prepend the header.
|
|
||||||
let mut serialized = Self::MAGIC_HEADER.to_vec();
|
|
||||||
serialized.extend(bytes);
|
|
||||||
Ok(serialized)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "serialize"))]
|
|
||||||
fn serialize(&self) -> Result<Vec<u8>, SerializeError> {
|
|
||||||
Err(SerializeError::Generic(
|
|
||||||
"The serializer feature is not enabled in the DummyEngine",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Artifact for DummyArtifact {
|
|
||||||
fn register_frame_info(&self) {
|
|
||||||
// Do nothing, since functions are not generated for the dummy engine
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finished_functions(&self) -> &BoxedSlice<LocalFunctionIndex, FunctionBodyPtr> {
|
|
||||||
&self.finished_functions
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finished_function_call_trampolines(&self) -> &BoxedSlice<SignatureIndex, VMTrampoline> {
|
|
||||||
&self.finished_function_call_trampolines
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finished_dynamic_function_trampolines(&self) -> &BoxedSlice<FunctionIndex, FunctionBodyPtr> {
|
|
||||||
&self.finished_dynamic_function_trampolines
|
|
||||||
}
|
|
||||||
|
|
||||||
fn signatures(&self) -> &BoxedSlice<SignatureIndex, VMSharedSignatureIndex> {
|
|
||||||
&self.signatures
|
|
||||||
}
|
|
||||||
|
|
||||||
fn func_data_registry(&self) -> &FuncDataRegistry {
|
|
||||||
&self.func_data_registry
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
//! Dummy Engine.
|
|
||||||
|
|
||||||
use crate::DummyArtifact;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use wasmer_compiler::{Features, Target};
|
|
||||||
use wasmer_engine::{Artifact, Engine, EngineId, Tunables};
|
|
||||||
use wasmer_types::{CompileError, DeserializeError, FunctionType};
|
|
||||||
use wasmer_vm::{
|
|
||||||
FuncDataRegistry, SignatureRegistry, VMCallerCheckedAnyfunc, VMContext, VMFuncRef,
|
|
||||||
VMFunctionBody, VMSharedSignatureIndex,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
extern "C" fn dummy_trampoline(
|
|
||||||
_context: *mut VMContext,
|
|
||||||
_body: *const VMFunctionBody,
|
|
||||||
_values: *mut u128,
|
|
||||||
) {
|
|
||||||
panic!("Dummy engine can't call functions, since Wasm function bodies are not really compiled")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A WebAssembly `Dummy` Engine.
|
|
||||||
#[derive(Clone)]
|
|
||||||
#[cfg_attr(feature = "compiler", derive(Default))]
|
|
||||||
pub struct DummyEngine {
|
|
||||||
signatures: Arc<SignatureRegistry>,
|
|
||||||
func_data: Arc<FuncDataRegistry>,
|
|
||||||
features: Arc<Features>,
|
|
||||||
target: Arc<Target>,
|
|
||||||
engine_id: EngineId,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DummyEngine {
|
|
||||||
#[cfg(feature = "compiler")]
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Default::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn features(&self) -> &Features {
|
|
||||||
&self.features
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Shared func metadata registry.
|
|
||||||
pub(crate) fn func_data(&self) -> &Arc<FuncDataRegistry> {
|
|
||||||
&self.func_data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Engine for DummyEngine {
|
|
||||||
/// Get the tunables
|
|
||||||
fn target(&self) -> &Target {
|
|
||||||
&self.target
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Register a signature
|
|
||||||
fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex {
|
|
||||||
self.signatures.register(func_type)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_function_metadata(&self, func_data: VMCallerCheckedAnyfunc) -> VMFuncRef {
|
|
||||||
self.func_data.register(func_data)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Lookup a signature
|
|
||||||
fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType> {
|
|
||||||
self.signatures.lookup(sig)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "compiler")]
|
|
||||||
/// Validates a WebAssembly module
|
|
||||||
fn validate(&self, binary: &[u8]) -> Result<(), CompileError> {
|
|
||||||
use wasmer_compiler::wasmparser::{Validator, WasmFeatures};
|
|
||||||
|
|
||||||
let features = self.features();
|
|
||||||
let mut validator = Validator::new();
|
|
||||||
let wasm_features = WasmFeatures {
|
|
||||||
bulk_memory: features.bulk_memory,
|
|
||||||
threads: features.threads,
|
|
||||||
reference_types: features.reference_types,
|
|
||||||
multi_value: features.multi_value,
|
|
||||||
simd: features.simd,
|
|
||||||
tail_call: features.tail_call,
|
|
||||||
module_linking: features.module_linking,
|
|
||||||
multi_memory: features.multi_memory,
|
|
||||||
memory64: features.memory64,
|
|
||||||
exceptions: features.exceptions,
|
|
||||||
deterministic_only: false,
|
|
||||||
extended_const: features.extended_const,
|
|
||||||
relaxed_simd: features.relaxed_simd,
|
|
||||||
mutable_global: true,
|
|
||||||
saturating_float_to_int: true,
|
|
||||||
sign_extension: true,
|
|
||||||
};
|
|
||||||
validator.wasm_features(wasm_features);
|
|
||||||
validator
|
|
||||||
.validate_all(binary)
|
|
||||||
.map_err(|e| CompileError::Validate(format!("{}", e)))?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "compiler"))]
|
|
||||||
/// Validates a WebAssembly module
|
|
||||||
fn validate(&self, binary: &[u8]) -> Result<(), CompileError> {
|
|
||||||
// We mark all Wasm modules as valid
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compile a WebAssembly binary
|
|
||||||
fn compile(
|
|
||||||
&self,
|
|
||||||
binary: &[u8],
|
|
||||||
tunables: &dyn Tunables,
|
|
||||||
) -> Result<Arc<dyn Artifact>, CompileError> {
|
|
||||||
Ok(Arc::new(DummyArtifact::new(self, binary, tunables)?))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deserializes a WebAssembly module (binary content of a Shared Object file)
|
|
||||||
unsafe fn deserialize(&self, bytes: &[u8]) -> Result<Arc<dyn Artifact>, DeserializeError> {
|
|
||||||
Ok(Arc::new(DummyArtifact::deserialize(self, bytes)?))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn id(&self) -> &EngineId {
|
|
||||||
&self.engine_id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cloned(&self) -> Arc<dyn Engine + Send + Sync> {
|
|
||||||
Arc::new(self.clone())
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
mod artifact;
|
|
||||||
mod engine;
|
|
||||||
|
|
||||||
pub use artifact::DummyArtifact;
|
|
||||||
pub use engine::DummyEngine;
|
|
Reference in New Issue
Block a user