mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 12:48:20 +00:00
Cleanup:
Removed conditionnal toml on wasm for VM as it's not builded in that configuration Added unwind to wasm build Moved Trap back to vm (from types) as it's used only on Runtime Move MemoryError back to vm (from types) as it's used on Runtime only scenario Some cleanup and lint fixes Removed wasm build case from vfs/host_fs as it's not used
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2870,7 +2870,6 @@ dependencies = [
|
|||||||
"tempfile",
|
"tempfile",
|
||||||
"unix_mode",
|
"unix_mode",
|
||||||
"wasmer",
|
"wasmer",
|
||||||
"wasmer-artifact",
|
|
||||||
"wasmer-cache",
|
"wasmer-cache",
|
||||||
"wasmer-compiler",
|
"wasmer-compiler",
|
||||||
"wasmer-compiler-cranelift",
|
"wasmer-compiler-cranelift",
|
||||||
@@ -2925,7 +2924,6 @@ dependencies = [
|
|||||||
"wasmer-compiler-singlepass",
|
"wasmer-compiler-singlepass",
|
||||||
"wasmer-engine-universal-artifact",
|
"wasmer-engine-universal-artifact",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"wasmer-vfs",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ doc = false
|
|||||||
wasmer-engine-universal-artifact = { version = "=2.2.1", path = "../universal-artifact", features = ["compiler"] }
|
wasmer-engine-universal-artifact = { version = "=2.2.1", path = "../universal-artifact", features = ["compiler"] }
|
||||||
wasmer-compiler = { version = "=2.2.1", path = "../compiler" }
|
wasmer-compiler = { version = "=2.2.1", path = "../compiler" }
|
||||||
wasmer-types = { version = "=2.2.1", path = "../types" }
|
wasmer-types = { version = "=2.2.1", path = "../types" }
|
||||||
wasmer-vfs = { version = "=2.2.1", path = "../vfs", default-features = false, features = ["host-fs"] }
|
|
||||||
atty = "0.2"
|
atty = "0.2"
|
||||||
colored = "2.0"
|
colored = "2.0"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
|||||||
@@ -24,12 +24,19 @@ doc = false
|
|||||||
required-features = ["headless"]
|
required-features = ["headless"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmer-artifact = { version = "=2.2.1", path = "../artifact" }
|
wasmer = { version = "=2.2.1", path = "../api", default-features = false }
|
||||||
wasmer-compiler = { version = "=2.2.1", path = "../compiler" }
|
wasmer-compiler = { version = "=2.2.1", path = "../compiler" }
|
||||||
|
wasmer-compiler-cranelift = { version = "=2.2.1", path = "../compiler-cranelift", optional = true }
|
||||||
wasmer-compiler-singlepass = { version = "=2.2.1", path = "../compiler-singlepass", optional = true }
|
wasmer-compiler-singlepass = { version = "=2.2.1", path = "../compiler-singlepass", optional = true }
|
||||||
|
wasmer-compiler-llvm = { version = "=2.2.1", path = "../compiler-llvm", optional = true }
|
||||||
|
wasmer-emscripten = { version = "=2.2.1", path = "../emscripten", optional = true }
|
||||||
wasmer-engine = { version = "=2.2.1", path = "../engine" }
|
wasmer-engine = { version = "=2.2.1", path = "../engine" }
|
||||||
wasmer-engine-universal = { version = "=2.2.1", path = "../engine-universal", optional = true }
|
wasmer-engine-universal = { version = "=2.2.1", path = "../engine-universal", optional = true }
|
||||||
|
wasmer-engine-dylib = { version = "=2.2.1", path = "../engine-dylib", optional = true }
|
||||||
|
wasmer-engine-staticlib = { version = "=2.2.1", path = "../engine-staticlib", optional = true }
|
||||||
|
wasmer-vm = { version = "=2.2.1", path = "../vm" }
|
||||||
wasmer-wasi = { version = "=2.2.1", path = "../wasi", optional = true }
|
wasmer-wasi = { version = "=2.2.1", path = "../wasi", optional = true }
|
||||||
|
wasmer-wasi-experimental-io-devices = { version = "=2.2.1", path = "../wasi-experimental-io-devices", optional = true }
|
||||||
wasmer-wast = { version = "=2.2.1", path = "../../tests/lib/wast", optional = true }
|
wasmer-wast = { version = "=2.2.1", path = "../../tests/lib/wast", optional = true }
|
||||||
wasmer-cache = { version = "=2.2.1", path = "../cache", optional = true }
|
wasmer-cache = { version = "=2.2.1", path = "../cache", optional = true }
|
||||||
wasmer-types = { version = "=2.2.1", path = "../types" }
|
wasmer-types = { version = "=2.2.1", path = "../types" }
|
||||||
@@ -48,19 +55,6 @@ fern = { version = "0.6", features = ["colored"], optional = true }
|
|||||||
log = { version = "0.4", optional = true }
|
log = { version = "0.4", optional = true }
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
||||||
wasmer = { version = "=2.2.1", path = "../api", default-features = false, features = ["js-default"] }
|
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
||||||
wasmer = { version = "=2.2.1", path = "../api", default-features = false }
|
|
||||||
wasmer-vm = { version = "=2.2.1", path = "../vm" }
|
|
||||||
wasmer-compiler-cranelift = { version = "=2.2.1", path = "../compiler-cranelift", optional = true }
|
|
||||||
wasmer-compiler-llvm = { version = "=2.2.1", path = "../compiler-llvm", optional = true }
|
|
||||||
wasmer-wasi-experimental-io-devices = { version = "=2.2.1", path = "../wasi-experimental-io-devices", optional = true }
|
|
||||||
wasmer-emscripten = { version = "=2.2.1", path = "../emscripten", optional = true }
|
|
||||||
wasmer-engine-dylib = { version = "=2.2.1", path = "../engine-dylib", optional = true }
|
|
||||||
wasmer-engine-staticlib = { version = "=2.2.1", path = "../engine-staticlib", optional = true }
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
unix_mode = "0.1.3"
|
unix_mode = "0.1.3"
|
||||||
|
|
||||||
@@ -125,4 +119,4 @@ headless-minimal = ["headless", "disable-all-logging", "wasi", "dylib", "univers
|
|||||||
|
|
||||||
# Deprecated features.
|
# Deprecated features.
|
||||||
jit = ["universal"]
|
jit = ["universal"]
|
||||||
native = ["dylib"]
|
native = ["dylib"]
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
use wasmer_cli::cli::wasmer_main;
|
|
||||||
|
|
||||||
#[cfg(not(any(feature = "cranelift", feature = "singlepass", feature = "llvm")))]
|
|
||||||
compile_error!(
|
|
||||||
"Either enable at least one compiler, or compile the wasmer-headless binary instead"
|
|
||||||
);
|
|
||||||
|
|
||||||
#[cfg(featue = "run")]
|
|
||||||
compile_error!("Cannot enable run with the compile-only build");
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
wasmer_main();
|
|
||||||
}
|
|
||||||
@@ -35,7 +35,7 @@ maintenance = { status = "actively-developed" }
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std", "rayon", "unwind", "avx"]
|
default = ["std", "rayon", "unwind", "avx"]
|
||||||
wasm = ["std", "avx"]
|
wasm = ["std", "unwind", "avx"]
|
||||||
std = ["wasmer-compiler/std", "wasmer-types/std"]
|
std = ["wasmer-compiler/std", "wasmer-types/std"]
|
||||||
core = ["hashbrown", "wasmer-types/core"]
|
core = ["hashbrown", "wasmer-types/core"]
|
||||||
unwind = ["gimli"]
|
unwind = ["gimli"]
|
||||||
|
|||||||
@@ -100,9 +100,9 @@ pub use types::{
|
|||||||
pub use archives::ArchivableIndexMap;
|
pub use archives::ArchivableIndexMap;
|
||||||
|
|
||||||
pub use crate::libcalls::LibCall;
|
pub use crate::libcalls::LibCall;
|
||||||
pub use crate::memory::{MemoryError, MemoryStyle};
|
pub use crate::memory::MemoryStyle;
|
||||||
pub use crate::table::TableStyle;
|
pub use crate::table::TableStyle;
|
||||||
pub use crate::trapcode::{Trap, TrapCode};
|
pub use crate::trapcode::TrapCode;
|
||||||
pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};
|
pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};
|
||||||
|
|
||||||
pub use crate::utils::is_wasm;
|
pub use crate::utils::is_wasm;
|
||||||
|
|||||||
@@ -4,49 +4,6 @@ use loupe::MemoryUsage;
|
|||||||
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
|
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
|
||||||
#[cfg(feature = "enable-serde")]
|
#[cfg(feature = "enable-serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
/// Error type describing things that can go wrong when operating on Wasm Memories.
|
|
||||||
#[derive(Error, Debug, Clone, PartialEq, Hash)]
|
|
||||||
pub enum MemoryError {
|
|
||||||
/// Low level error with mmap.
|
|
||||||
#[error("Error when allocating memory: {0}")]
|
|
||||||
Region(String),
|
|
||||||
/// The operation would cause the size of the memory to exceed the maximum or would cause
|
|
||||||
/// an overflow leading to unindexable memory.
|
|
||||||
#[error("The memory could not grow: current size {} pages, requested increase: {} pages", current.0, attempted_delta.0)]
|
|
||||||
CouldNotGrow {
|
|
||||||
/// The current size in pages.
|
|
||||||
current: Pages,
|
|
||||||
/// The attempted amount to grow by in pages.
|
|
||||||
attempted_delta: Pages,
|
|
||||||
},
|
|
||||||
/// The operation would cause the size of the memory size exceed the maximum.
|
|
||||||
#[error("The memory is invalid because {}", reason)]
|
|
||||||
InvalidMemory {
|
|
||||||
/// The reason why the provided memory is invalid.
|
|
||||||
reason: String,
|
|
||||||
},
|
|
||||||
/// Caller asked for more minimum memory than we can give them.
|
|
||||||
#[error("The minimum requested ({} pages) memory is greater than the maximum allowed memory ({} pages)", min_requested.0, max_allowed.0)]
|
|
||||||
MinimumMemoryTooLarge {
|
|
||||||
/// The number of pages requested as the minimum amount of memory.
|
|
||||||
min_requested: Pages,
|
|
||||||
/// The maximum amount of memory we can allocate.
|
|
||||||
max_allowed: Pages,
|
|
||||||
},
|
|
||||||
/// Caller asked for a maximum memory greater than we can give them.
|
|
||||||
#[error("The maximum requested memory ({} pages) is greater than the maximum allowed memory ({} pages)", max_requested.0, max_allowed.0)]
|
|
||||||
MaximumMemoryTooLarge {
|
|
||||||
/// The number of pages requested as the maximum amount of memory.
|
|
||||||
max_requested: Pages,
|
|
||||||
/// The number of pages requested as the maximum amount of memory.
|
|
||||||
max_allowed: Pages,
|
|
||||||
},
|
|
||||||
/// A user defined error value, used for error cases not listed above.
|
|
||||||
#[error("A user-defined error occurred: {0}")]
|
|
||||||
Generic(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implementation styles for WebAssembly linear memory.
|
/// Implementation styles for WebAssembly linear memory.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, MemoryUsage)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, MemoryUsage)]
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
//! Trap codes describing the reason for a trap.
|
//! Trap codes describing the reason for a trap.
|
||||||
|
|
||||||
use backtrace::Backtrace;
|
|
||||||
use core::fmt::{self, Display, Formatter};
|
use core::fmt::{self, Display, Formatter};
|
||||||
use core::str::FromStr;
|
use core::str::FromStr;
|
||||||
use loupe::MemoryUsage;
|
use loupe::MemoryUsage;
|
||||||
@@ -11,7 +10,6 @@ use loupe::MemoryUsage;
|
|||||||
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
|
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
|
||||||
#[cfg(feature = "enable-serde")]
|
#[cfg(feature = "enable-serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::error::Error;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
/// A trap code describing the reason for a trap.
|
/// A trap code describing the reason for a trap.
|
||||||
@@ -166,72 +164,3 @@ mod tests {
|
|||||||
assert_eq!("users".parse::<TrapCode>(), Err(()));
|
assert_eq!("users".parse::<TrapCode>(), Err(()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores trace message with backtrace.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Trap {
|
|
||||||
/// A user-raised trap through `raise_user_trap`.
|
|
||||||
User(Box<dyn Error + Send + Sync>),
|
|
||||||
|
|
||||||
/// A trap raised from the Wasm generated code
|
|
||||||
///
|
|
||||||
/// Note: this trap is deterministic (assuming a deterministic host implementation)
|
|
||||||
Wasm {
|
|
||||||
/// The program counter in generated code where this trap happened.
|
|
||||||
pc: usize,
|
|
||||||
/// Native stack backtrace at the time the trap occurred
|
|
||||||
backtrace: Backtrace,
|
|
||||||
/// Optional trapcode associated to the signal that caused the trap
|
|
||||||
signal_trap: Option<TrapCode>,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// A trap raised from a wasm libcall
|
|
||||||
///
|
|
||||||
/// Note: this trap is deterministic (assuming a deterministic host implementation)
|
|
||||||
Lib {
|
|
||||||
/// Code of the trap.
|
|
||||||
trap_code: TrapCode,
|
|
||||||
/// Native stack backtrace at the time the trap occurred
|
|
||||||
backtrace: Backtrace,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// A trap indicating that the runtime was unable to allocate sufficient memory.
|
|
||||||
///
|
|
||||||
/// Note: this trap is nondeterministic, since it depends on the host system.
|
|
||||||
OOM {
|
|
||||||
/// Native stack backtrace at the time the OOM occurred
|
|
||||||
backtrace: Backtrace,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Trap {
|
|
||||||
/// Construct a new Wasm trap with the given source location and backtrace.
|
|
||||||
///
|
|
||||||
/// Internally saves a backtrace when constructed.
|
|
||||||
pub fn wasm(pc: usize, backtrace: Backtrace, signal_trap: Option<TrapCode>) -> Self {
|
|
||||||
Trap::Wasm {
|
|
||||||
pc,
|
|
||||||
backtrace,
|
|
||||||
signal_trap,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Construct a new Wasm trap with the given trap code.
|
|
||||||
///
|
|
||||||
/// Internally saves a backtrace when constructed.
|
|
||||||
pub fn lib(trap_code: TrapCode) -> Self {
|
|
||||||
let backtrace = Backtrace::new_unresolved();
|
|
||||||
Trap::Lib {
|
|
||||||
trap_code,
|
|
||||||
backtrace,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Construct a new OOM trap with the given source location and trap code.
|
|
||||||
///
|
|
||||||
/// Internally saves a backtrace when constructed.
|
|
||||||
pub fn oom() -> Self {
|
|
||||||
let backtrace = Backtrace::new_unresolved();
|
|
||||||
Trap::OOM { backtrace }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ use std::fs;
|
|||||||
use std::io::{self, Read, Seek, Write};
|
use std::io::{self, Read, Seek, Write};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
use std::os::wasi::io::{AsRawFd, RawFd};
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use std::os::windows::io::{AsRawHandle, RawHandle};
|
use std::os::windows::io::{AsRawHandle, RawHandle};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@@ -69,31 +67,6 @@ impl TryInto<RawHandle> for FileDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
impl<T> TryIntoFileDescriptor for T
|
|
||||||
where
|
|
||||||
T: AsRawFd,
|
|
||||||
{
|
|
||||||
type Error = FsError;
|
|
||||||
|
|
||||||
fn try_into_filedescriptor(&self) -> std::result::Result<FileDescriptor, Self::Error> {
|
|
||||||
Ok(FileDescriptor(
|
|
||||||
self.as_raw_fd()
|
|
||||||
.try_into()
|
|
||||||
.map_err(|_| FsError::InvalidFd)?,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
impl TryInto<RawFd> for FileDescriptor {
|
|
||||||
type Error = FsError;
|
|
||||||
|
|
||||||
fn try_into(self) -> std::result::Result<RawFd, Self::Error> {
|
|
||||||
self.0.try_into().map_err(|_| FsError::InvalidFd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||||
pub struct FileSystem;
|
pub struct FileSystem;
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ loupe = { version = "0.1", features = ["enable-indexmap"] }
|
|||||||
enum-iterator = "0.7.0"
|
enum-iterator = "0.7.0"
|
||||||
scopeguard = "1.1.0"
|
scopeguard = "1.1.0"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
||||||
region = { version = "3.0" }
|
region = { version = "3.0" }
|
||||||
corosensei = { version = "0.1.2" }
|
corosensei = { version = "0.1.2" }
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use crate::export::VMExtern;
|
|||||||
use crate::func_data_registry::VMFuncRef;
|
use crate::func_data_registry::VMFuncRef;
|
||||||
use crate::global::Global;
|
use crate::global::Global;
|
||||||
use crate::imports::Imports;
|
use crate::imports::Imports;
|
||||||
use crate::memory::Memory;
|
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::{
|
||||||
@@ -44,8 +44,8 @@ use std::sync::Arc;
|
|||||||
use wasmer_types::entity::{packed_option::ReservedValue, BoxedSlice, EntityRef, PrimaryMap};
|
use wasmer_types::entity::{packed_option::ReservedValue, BoxedSlice, EntityRef, PrimaryMap};
|
||||||
use wasmer_types::{
|
use wasmer_types::{
|
||||||
DataIndex, DataInitializer, ElemIndex, ExportIndex, FunctionIndex, GlobalIndex, GlobalInit,
|
DataIndex, DataInitializer, ElemIndex, ExportIndex, FunctionIndex, GlobalIndex, GlobalInit,
|
||||||
LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryError,
|
LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryIndex,
|
||||||
MemoryIndex, ModuleInfo, Pages, SignatureIndex, TableIndex, TableInitializer,
|
ModuleInfo, Pages, SignatureIndex, TableIndex, TableInitializer,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The function pointer to call with data and an [`Instance`] pointer to
|
/// The function pointer to call with data and an [`Instance`] pointer to
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub use crate::instance::{
|
|||||||
ImportFunctionEnv, ImportInitializerFuncPtr, InstanceAllocator, InstanceHandle,
|
ImportFunctionEnv, ImportInitializerFuncPtr, InstanceAllocator, InstanceHandle,
|
||||||
WeakOrStrongInstanceRef,
|
WeakOrStrongInstanceRef,
|
||||||
};
|
};
|
||||||
pub use crate::memory::{LinearMemory, Memory};
|
pub use crate::memory::{LinearMemory, Memory, MemoryError};
|
||||||
pub use crate::mmap::Mmap;
|
pub use crate::mmap::Mmap;
|
||||||
pub use crate::probestack::PROBESTACK;
|
pub use crate::probestack::PROBESTACK;
|
||||||
pub use crate::sig_registry::SignatureRegistry;
|
pub use crate::sig_registry::SignatureRegistry;
|
||||||
@@ -56,13 +56,13 @@ pub use crate::vmcontext::{
|
|||||||
};
|
};
|
||||||
pub use wasmer_artifact::{FunctionBodyPtr, VMFunctionBody};
|
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::TableStyle;
|
pub use wasmer_types::TableStyle;
|
||||||
#[deprecated(
|
#[deprecated(
|
||||||
since = "2.1.0",
|
since = "2.1.0",
|
||||||
note = "ModuleInfo, ExportsIterator, ImportsIterator should be imported from wasmer_types."
|
note = "ModuleInfo, ExportsIterator, ImportsIterator should be imported from wasmer_types."
|
||||||
)]
|
)]
|
||||||
pub use wasmer_types::{ExportsIterator, ImportsIterator, ModuleInfo};
|
pub use wasmer_types::{ExportsIterator, ImportsIterator, ModuleInfo};
|
||||||
pub use wasmer_types::{MemoryError, MemoryStyle};
|
|
||||||
pub use wasmer_types::{
|
pub use wasmer_types::{
|
||||||
TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMExternRef, VMOffsets,
|
TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMExternRef, VMOffsets,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,50 @@ use std::convert::TryInto;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use wasmer_types::{Bytes, MemoryError, MemoryStyle, MemoryType, Pages};
|
use thiserror::Error;
|
||||||
|
use wasmer_types::{Bytes, MemoryStyle, MemoryType, Pages};
|
||||||
|
|
||||||
|
/// Error type describing things that can go wrong when operating on Wasm Memories.
|
||||||
|
#[derive(Error, Debug, Clone, PartialEq, Hash)]
|
||||||
|
pub enum MemoryError {
|
||||||
|
/// Low level error with mmap.
|
||||||
|
#[error("Error when allocating memory: {0}")]
|
||||||
|
Region(String),
|
||||||
|
/// The operation would cause the size of the memory to exceed the maximum or would cause
|
||||||
|
/// an overflow leading to unindexable memory.
|
||||||
|
#[error("The memory could not grow: current size {} pages, requested increase: {} pages", current.0, attempted_delta.0)]
|
||||||
|
CouldNotGrow {
|
||||||
|
/// The current size in pages.
|
||||||
|
current: Pages,
|
||||||
|
/// The attempted amount to grow by in pages.
|
||||||
|
attempted_delta: Pages,
|
||||||
|
},
|
||||||
|
/// The operation would cause the size of the memory size exceed the maximum.
|
||||||
|
#[error("The memory is invalid because {}", reason)]
|
||||||
|
InvalidMemory {
|
||||||
|
/// The reason why the provided memory is invalid.
|
||||||
|
reason: String,
|
||||||
|
},
|
||||||
|
/// Caller asked for more minimum memory than we can give them.
|
||||||
|
#[error("The minimum requested ({} pages) memory is greater than the maximum allowed memory ({} pages)", min_requested.0, max_allowed.0)]
|
||||||
|
MinimumMemoryTooLarge {
|
||||||
|
/// The number of pages requested as the minimum amount of memory.
|
||||||
|
min_requested: Pages,
|
||||||
|
/// The maximum amount of memory we can allocate.
|
||||||
|
max_allowed: Pages,
|
||||||
|
},
|
||||||
|
/// Caller asked for a maximum memory greater than we can give them.
|
||||||
|
#[error("The maximum requested memory ({} pages) is greater than the maximum allowed memory ({} pages)", max_requested.0, max_allowed.0)]
|
||||||
|
MaximumMemoryTooLarge {
|
||||||
|
/// The number of pages requested as the maximum amount of memory.
|
||||||
|
max_requested: Pages,
|
||||||
|
/// The number of pages requested as the maximum amount of memory.
|
||||||
|
max_allowed: Pages,
|
||||||
|
},
|
||||||
|
/// A user defined error value, used for error cases not listed above.
|
||||||
|
#[error("A user-defined error occurred: {0}")]
|
||||||
|
Generic(String),
|
||||||
|
}
|
||||||
|
|
||||||
/// Trait for implementing Wasm Memory used by Wasmer.
|
/// Trait for implementing Wasm Memory used by Wasmer.
|
||||||
pub trait Memory: fmt::Debug + Send + Sync + MemoryUsage {
|
pub trait Memory: fmt::Debug + Send + Sync + MemoryUsage {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
use crate::func_data_registry::VMFuncRef;
|
use crate::func_data_registry::VMFuncRef;
|
||||||
use crate::vmcontext::VMTableDefinition;
|
use crate::vmcontext::VMTableDefinition;
|
||||||
|
use crate::Trap;
|
||||||
use crate::VMExternRef;
|
use crate::VMExternRef;
|
||||||
use loupe::{MemoryUsage, MemoryUsageTracker};
|
use loupe::{MemoryUsage, MemoryUsageTracker};
|
||||||
use std::borrow::{Borrow, BorrowMut};
|
use std::borrow::{Borrow, BorrowMut};
|
||||||
@@ -15,7 +16,7 @@ use std::convert::TryFrom;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use wasmer_types::{ExternRef, TableStyle, TableType, Trap, TrapCode, Type as ValType};
|
use wasmer_types::{ExternRef, TableStyle, TableType, TrapCode, Type as ValType};
|
||||||
|
|
||||||
/// Trait for implementing the interface of a Wasm table.
|
/// Trait for implementing the interface of a Wasm table.
|
||||||
pub trait Table: fmt::Debug + Send + Sync + MemoryUsage {
|
pub trait Table: fmt::Debug + Send + Sync + MemoryUsage {
|
||||||
|
|||||||
@@ -3,11 +3,13 @@
|
|||||||
|
|
||||||
//! This is the module that facilitates the usage of Traps
|
//! This is the module that facilitates the usage of Traps
|
||||||
//! in Wasmer Runtime
|
//! in Wasmer Runtime
|
||||||
|
mod trap;
|
||||||
mod traphandlers;
|
mod traphandlers;
|
||||||
|
|
||||||
|
pub use trap::Trap;
|
||||||
pub use traphandlers::{
|
pub use traphandlers::{
|
||||||
catch_traps, on_host_stack, raise_lib_trap, raise_user_trap, wasmer_call_trampoline,
|
catch_traps, on_host_stack, raise_lib_trap, raise_user_trap, wasmer_call_trampoline,
|
||||||
TrapHandler, TrapHandlerFn,
|
TrapHandler, TrapHandlerFn,
|
||||||
};
|
};
|
||||||
pub use traphandlers::{init_traps, resume_panic};
|
pub use traphandlers::{init_traps, resume_panic};
|
||||||
pub use wasmer_types::{Trap, TrapCode};
|
pub use wasmer_types::TrapCode;
|
||||||
|
|||||||
72
lib/vm/src/trap/trap.rs
Normal file
72
lib/vm/src/trap/trap.rs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
use backtrace::Backtrace;
|
||||||
|
use std::error::Error;
|
||||||
|
use wasmer_types::TrapCode;
|
||||||
|
|
||||||
|
/// Stores trace message with backtrace.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Trap {
|
||||||
|
/// A user-raised trap through `raise_user_trap`.
|
||||||
|
User(Box<dyn Error + Send + Sync>),
|
||||||
|
|
||||||
|
/// A trap raised from the Wasm generated code
|
||||||
|
///
|
||||||
|
/// Note: this trap is deterministic (assuming a deterministic host implementation)
|
||||||
|
Wasm {
|
||||||
|
/// The program counter in generated code where this trap happened.
|
||||||
|
pc: usize,
|
||||||
|
/// Native stack backtrace at the time the trap occurred
|
||||||
|
backtrace: Backtrace,
|
||||||
|
/// Optional trapcode associated to the signal that caused the trap
|
||||||
|
signal_trap: Option<TrapCode>,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// A trap raised from a wasm libcall
|
||||||
|
///
|
||||||
|
/// Note: this trap is deterministic (assuming a deterministic host implementation)
|
||||||
|
Lib {
|
||||||
|
/// Code of the trap.
|
||||||
|
trap_code: TrapCode,
|
||||||
|
/// Native stack backtrace at the time the trap occurred
|
||||||
|
backtrace: Backtrace,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// A trap indicating that the runtime was unable to allocate sufficient memory.
|
||||||
|
///
|
||||||
|
/// Note: this trap is nondeterministic, since it depends on the host system.
|
||||||
|
OOM {
|
||||||
|
/// Native stack backtrace at the time the OOM occurred
|
||||||
|
backtrace: Backtrace,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Trap {
|
||||||
|
/// Construct a new Wasm trap with the given source location and backtrace.
|
||||||
|
///
|
||||||
|
/// Internally saves a backtrace when constructed.
|
||||||
|
pub fn wasm(pc: usize, backtrace: Backtrace, signal_trap: Option<TrapCode>) -> Self {
|
||||||
|
Trap::Wasm {
|
||||||
|
pc,
|
||||||
|
backtrace,
|
||||||
|
signal_trap,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Construct a new Wasm trap with the given trap code.
|
||||||
|
///
|
||||||
|
/// Internally saves a backtrace when constructed.
|
||||||
|
pub fn lib(trap_code: TrapCode) -> Self {
|
||||||
|
let backtrace = Backtrace::new_unresolved();
|
||||||
|
Trap::Lib {
|
||||||
|
trap_code,
|
||||||
|
backtrace,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Construct a new OOM trap with the given source location and trap code.
|
||||||
|
///
|
||||||
|
/// Internally saves a backtrace when constructed.
|
||||||
|
pub fn oom() -> Self {
|
||||||
|
let backtrace = Backtrace::new_unresolved();
|
||||||
|
Trap::OOM { backtrace }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
//! signalhandling mechanisms.
|
//! signalhandling mechanisms.
|
||||||
|
|
||||||
use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMTrampoline};
|
use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMTrampoline};
|
||||||
|
use crate::Trap;
|
||||||
use backtrace::Backtrace;
|
use backtrace::Backtrace;
|
||||||
use corosensei::stack::DefaultStack;
|
use corosensei::stack::DefaultStack;
|
||||||
use corosensei::trap::{CoroutineTrapHandler, TrapHandlerRegs};
|
use corosensei::trap::{CoroutineTrapHandler, TrapHandlerRegs};
|
||||||
@@ -20,7 +21,7 @@ use std::mem::MaybeUninit;
|
|||||||
use std::ptr::{self, NonNull};
|
use std::ptr::{self, NonNull};
|
||||||
use std::sync::atomic::{compiler_fence, AtomicPtr, Ordering};
|
use std::sync::atomic::{compiler_fence, AtomicPtr, Ordering};
|
||||||
use std::sync::{Mutex, Once};
|
use std::sync::{Mutex, Once};
|
||||||
use wasmer_types::{Trap, TrapCode};
|
use wasmer_types::TrapCode;
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(unix)] {
|
if #[cfg(unix)] {
|
||||||
|
|||||||
Reference in New Issue
Block a user