Skip to content

Commit

Permalink
feat(runtime): upgrade to Wasmer 0.17 and nightly 2020-05-15
Browse files Browse the repository at this point in the history
Used https://crates.io/crates/rust-latest to find latest suitable nightly.

Fixes #2055

Test plan
---------
cargo test --all
  • Loading branch information
olonho committed May 18, 2020
1 parent 48fa6b4 commit 29147ff
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 71 deletions.
101 changes: 41 additions & 60 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions runtime/near-vm-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pub enum WasmTrap {
IllegalArithmetic,
/// Misaligned atomic access trap.
MisalignedAtomicAccess,
/// Breakpoint trap.
BreakpointTrap,
/// Generic trap.
GenericTrap,
}

#[derive(
Expand Down Expand Up @@ -244,6 +248,8 @@ impl fmt::Display for WasmTrap {
write!(f, "An arithmetic exception, e.g. divided by zero.")
}
WasmTrap::MisalignedAtomicAccess => write!(f, "Misaligned atomic access trap."),
WasmTrap::GenericTrap => write!(f, "Generic trap."),
WasmTrap::BreakpointTrap => write!(f, "Breakpoint trap."),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/near-vm-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ This crate implements the specification of the interface that Near blockchain ex

[dependencies]
cached = "0.12"
wasmer-runtime = { version = "0.13.1", features = ["default-backend-singlepass"], default-features = false }
wasmer-runtime-core = { version = "0.13.1" }
wasmer-runtime = { version = "0.17", features = ["default-backend-singlepass"], default-features = false }
wasmer-runtime-core = { version = "0.17" }
pwasm-utils = "0.12"
parity-wasm = "0.41"

Expand Down
30 changes: 25 additions & 5 deletions runtime/near-vm-runner/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_vm_errors::FunctionCallError::WasmUnknownError;
use near_vm_errors::FunctionCallError::{WasmTrap, WasmUnknownError};
use near_vm_errors::{CompilationError, FunctionCallError, MethodResolveError, VMError};
use near_vm_logic::VMLogicError;

Expand Down Expand Up @@ -65,10 +65,31 @@ impl IntoVMError for wasmer_runtime::error::ResolveError {

impl IntoVMError for wasmer_runtime::error::RuntimeError {
fn into_vm_error(self) -> VMError {
use near_vm_errors::WasmTrap::{BreakpointTrap, GenericTrap};
use wasmer_runtime::error::InvokeError;
use wasmer_runtime::error::RuntimeError;
match &self {
RuntimeError::Trap { msg: _ } => VMError::FunctionCallError(WasmUnknownError),
RuntimeError::Error { data } => {
RuntimeError::InvokeError(invoke_error) => match invoke_error {
InvokeError::FailedWithNoError => VMError::FunctionCallError(WasmUnknownError),
InvokeError::UnknownTrap { address: _, signal: _ } => {
VMError::FunctionCallError(WasmTrap(GenericTrap))
}
InvokeError::TrapCode { code: _, srcloc: _ } => {
VMError::FunctionCallError(WasmTrap(GenericTrap))
}
InvokeError::UnknownTrapCode { trap_code: _, srcloc: _ } => {
VMError::FunctionCallError(WasmTrap(GenericTrap))
}
InvokeError::EarlyTrap(_) => VMError::FunctionCallError(WasmTrap(GenericTrap)),
InvokeError::Breakpoint(_) => VMError::FunctionCallError(WasmTrap(BreakpointTrap)),
},
RuntimeError::Metering(_x) => {
panic!("Support metering errors properly");
}
RuntimeError::InstanceImage(_x) => {
panic!("Support instance image errors properly");
}
RuntimeError::User(data) => {
if let Some(err) = data.downcast_ref::<VMLogicError>() {
match err {
VMLogicError::HostError(h) => {
Expand All @@ -80,12 +101,11 @@ impl IntoVMError for wasmer_runtime::error::RuntimeError {
}
}
} else {
eprintln!(
panic!(
"Bad error case! Output is non-deterministic {:?} {:?}",
data.type_id(),
self.to_string()
);
VMError::FunctionCallError(WasmUnknownError)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime-params-estimator/emu-cost/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LABEL description="Container for builds"
# RUN rustup update nightly
RUN rustup toolchain uninstall nightly
# Must match nearcore/rust-toolchain.
RUN rustup default nightly-2020-03-19
RUN rustup default nightly-2020-05-15
RUN rustup target add wasm32-unknown-unknown

# install build dependencies for QEMU
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime-params-estimator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(asm)]
#![feature(llvm_asm)]

// Lists all cases that we want to measure.
pub mod cases;
Expand Down
3 changes: 2 additions & 1 deletion runtime/runtime-params-estimator/src/testbed_runners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ pub fn measure_actions(
}

// TODO: super-ugly, can achieve the same via higher-level wrappers over POSIX read().
#[cfg(any(target_arch = "x86_64"))]
#[inline(always)]
pub unsafe fn syscall3(mut n: usize, a1: usize, a2: usize, a3: usize) -> usize {
asm!("syscall"
llvm_asm!("syscall"
: "+{rax}"(n)
: "{rdi}"(a1) "{rsi}"(a2) "{rdx}"(a3)
: "rcx", "r11", "memory"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2020-03-19
nightly-2020-05-15

0 comments on commit 29147ff

Please sign in to comment.