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:
ptitSeb
2022-05-02 10:12:35 +02:00
parent 8010cb88e7
commit 0c7ea79bfc
17 changed files with 140 additions and 186 deletions

2
Cargo.lock generated
View File

@@ -2870,7 +2870,6 @@ dependencies = [
"tempfile",
"unix_mode",
"wasmer",
"wasmer-artifact",
"wasmer-cache",
"wasmer-compiler",
"wasmer-compiler-cranelift",
@@ -2925,7 +2924,6 @@ dependencies = [
"wasmer-compiler-singlepass",
"wasmer-engine-universal-artifact",
"wasmer-types",
"wasmer-vfs",
]
[[package]]

View File

@@ -21,7 +21,6 @@ doc = false
wasmer-engine-universal-artifact = { version = "=2.2.1", path = "../universal-artifact", features = ["compiler"] }
wasmer-compiler = { version = "=2.2.1", path = "../compiler" }
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"
colored = "2.0"
anyhow = "1.0"

View File

@@ -24,12 +24,19 @@ doc = false
required-features = ["headless"]
[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-cranelift = { version = "=2.2.1", path = "../compiler-cranelift", 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-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-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-cache = { version = "=2.2.1", path = "../cache", optional = true }
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 }
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]
unix_mode = "0.1.3"
@@ -125,4 +119,4 @@ headless-minimal = ["headless", "disable-all-logging", "wasi", "dylib", "univers
# Deprecated features.
jit = ["universal"]
native = ["dylib"]
native = ["dylib"]

View File

@@ -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();
}

View File

@@ -35,7 +35,7 @@ maintenance = { status = "actively-developed" }
[features]
default = ["std", "rayon", "unwind", "avx"]
wasm = ["std", "avx"]
wasm = ["std", "unwind", "avx"]
std = ["wasmer-compiler/std", "wasmer-types/std"]
core = ["hashbrown", "wasmer-types/core"]
unwind = ["gimli"]

View File

@@ -100,9 +100,9 @@ pub use types::{
pub use archives::ArchivableIndexMap;
pub use crate::libcalls::LibCall;
pub use crate::memory::{MemoryError, MemoryStyle};
pub use crate::memory::MemoryStyle;
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::utils::is_wasm;

View File

@@ -4,49 +4,6 @@ use loupe::MemoryUsage;
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
#[cfg(feature = "enable-serde")]
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.
#[derive(Debug, Clone, PartialEq, Eq, Hash, MemoryUsage)]

View File

@@ -3,7 +3,6 @@
//! Trap codes describing the reason for a trap.
use backtrace::Backtrace;
use core::fmt::{self, Display, Formatter};
use core::str::FromStr;
use loupe::MemoryUsage;
@@ -11,7 +10,6 @@ use loupe::MemoryUsage;
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
use std::error::Error;
use thiserror::Error;
/// A trap code describing the reason for a trap.
@@ -166,72 +164,3 @@ mod tests {
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 }
}
}

View File

@@ -9,8 +9,6 @@ use std::fs;
use std::io::{self, Read, Seek, Write};
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, RawFd};
#[cfg(target_arch = "wasm32")]
use std::os::wasi::io::{AsRawFd, RawFd};
#[cfg(windows)]
use std::os::windows::io::{AsRawHandle, RawHandle};
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)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub struct FileSystem;

View File

@@ -26,8 +26,6 @@ loupe = { version = "0.1", features = ["enable-indexmap"] }
enum-iterator = "0.7.0"
scopeguard = "1.1.0"
lazy_static = "1.4.0"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
region = { version = "3.0" }
corosensei = { version = "0.1.2" }

View File

@@ -17,7 +17,7 @@ use crate::export::VMExtern;
use crate::func_data_registry::VMFuncRef;
use crate::global::Global;
use crate::imports::Imports;
use crate::memory::Memory;
use crate::memory::{Memory, MemoryError};
use crate::table::{Table, TableElement};
use crate::trap::{catch_traps, Trap, TrapCode, TrapHandler};
use crate::vmcontext::{
@@ -44,8 +44,8 @@ use std::sync::Arc;
use wasmer_types::entity::{packed_option::ReservedValue, BoxedSlice, EntityRef, PrimaryMap};
use wasmer_types::{
DataIndex, DataInitializer, ElemIndex, ExportIndex, FunctionIndex, GlobalIndex, GlobalInit,
LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryError,
MemoryIndex, ModuleInfo, Pages, SignatureIndex, TableIndex, TableInitializer,
LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryIndex,
ModuleInfo, Pages, SignatureIndex, TableIndex, TableInitializer,
};
/// The function pointer to call with data and an [`Instance`] pointer to

View File

@@ -43,7 +43,7 @@ pub use crate::instance::{
ImportFunctionEnv, ImportInitializerFuncPtr, InstanceAllocator, InstanceHandle,
WeakOrStrongInstanceRef,
};
pub use crate::memory::{LinearMemory, Memory};
pub use crate::memory::{LinearMemory, Memory, MemoryError};
pub use crate::mmap::Mmap;
pub use crate::probestack::PROBESTACK;
pub use crate::sig_registry::SignatureRegistry;
@@ -56,13 +56,13 @@ pub use crate::vmcontext::{
};
pub use wasmer_artifact::{FunctionBodyPtr, VMFunctionBody};
pub use wasmer_types::LibCall;
pub use wasmer_types::MemoryStyle;
pub use wasmer_types::TableStyle;
#[deprecated(
since = "2.1.0",
note = "ModuleInfo, ExportsIterator, ImportsIterator should be imported from wasmer_types."
)]
pub use wasmer_types::{ExportsIterator, ImportsIterator, ModuleInfo};
pub use wasmer_types::{MemoryError, MemoryStyle};
pub use wasmer_types::{
TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMExternRef, VMOffsets,
};

View File

@@ -15,7 +15,50 @@ use std::convert::TryInto;
use std::fmt;
use std::ptr::NonNull;
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.
pub trait Memory: fmt::Debug + Send + Sync + MemoryUsage {

View File

@@ -7,6 +7,7 @@
use crate::func_data_registry::VMFuncRef;
use crate::vmcontext::VMTableDefinition;
use crate::Trap;
use crate::VMExternRef;
use loupe::{MemoryUsage, MemoryUsageTracker};
use std::borrow::{Borrow, BorrowMut};
@@ -15,7 +16,7 @@ use std::convert::TryFrom;
use std::fmt;
use std::ptr::NonNull;
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.
pub trait Table: fmt::Debug + Send + Sync + MemoryUsage {

View File

@@ -3,11 +3,13 @@
//! This is the module that facilitates the usage of Traps
//! in Wasmer Runtime
mod trap;
mod traphandlers;
pub use trap::Trap;
pub use traphandlers::{
catch_traps, on_host_stack, raise_lib_trap, raise_user_trap, wasmer_call_trampoline,
TrapHandler, TrapHandlerFn,
};
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
View 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 }
}
}

View File

@@ -5,6 +5,7 @@
//! signalhandling mechanisms.
use crate::vmcontext::{VMFunctionBody, VMFunctionEnvironment, VMTrampoline};
use crate::Trap;
use backtrace::Backtrace;
use corosensei::stack::DefaultStack;
use corosensei::trap::{CoroutineTrapHandler, TrapHandlerRegs};
@@ -20,7 +21,7 @@ use std::mem::MaybeUninit;
use std::ptr::{self, NonNull};
use std::sync::atomic::{compiler_fence, AtomicPtr, Ordering};
use std::sync::{Mutex, Once};
use wasmer_types::{Trap, TrapCode};
use wasmer_types::TrapCode;
cfg_if::cfg_if! {
if #[cfg(unix)] {