Skip to content

Commit

Permalink
Cleanup:
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ptitSeb committed May 3, 2022
1 parent 8010cb8 commit 0c7ea79
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 186 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/cli-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 9 additions & 15 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"

Expand Down Expand Up @@ -125,4 +119,4 @@ headless-minimal = ["headless", "disable-all-logging", "wasi", "dylib", "univers

# Deprecated features.
jit = ["universal"]
native = ["dylib"]
native = ["dylib"]
13 changes: 0 additions & 13 deletions lib/cli/src/bin/wasmer_compiler.rs

This file was deleted.

2 changes: 1 addition & 1 deletion lib/compiler-singlepass/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions lib/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 0 additions & 43 deletions lib/types/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
71 changes: 0 additions & 71 deletions lib/types/src/trapcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

//! Trap codes describing the reason for a trap.
use backtrace::Backtrace;
use core::fmt::{self, Display, Formatter};
use core::str::FromStr;
use loupe::MemoryUsage;
#[cfg(feature = "enable-rkyv")]
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.
Expand Down Expand Up @@ -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 }
}
}
27 changes: 0 additions & 27 deletions lib/vfs/src/host_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions lib/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
6 changes: 3 additions & 3 deletions lib/vm/src/instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
};
Expand Down
45 changes: 44 additions & 1 deletion lib/vm/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 0c7ea79

Please sign in to comment.