Ensure Trap is returned for start function traps (#768)
* Ensure `Trap` is returned for start function traps Handle another case of errors coming out of instantiation, resolve a FIXME, and remove an unneeded dependency from the wast testsuite crate. * Run rustfmt
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2216,7 +2216,6 @@ version = "0.7.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"wasmtime",
|
"wasmtime",
|
||||||
"wasmtime-runtime",
|
|
||||||
"wast 4.0.0",
|
"wast 4.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ use anyhow::{Error, Result};
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wasmtime_jit::{instantiate, Resolver};
|
use wasmtime_jit::{instantiate, Resolver, SetupError};
|
||||||
use wasmtime_runtime::{Export, InstanceHandle};
|
use wasmtime_runtime::{Export, InstanceHandle, InstantiationError};
|
||||||
|
|
||||||
struct SimpleResolver {
|
struct SimpleResolver {
|
||||||
imports: Vec<(String, String, Extern)>,
|
imports: Vec<(String, String, Extern)>,
|
||||||
@@ -46,6 +46,8 @@ pub fn instantiate_in_context(
|
|||||||
.map_err(|e| -> Error {
|
.map_err(|e| -> Error {
|
||||||
if let Some(trap) = take_api_trap() {
|
if let Some(trap) = take_api_trap() {
|
||||||
Trap::from(trap).into()
|
Trap::from(trap).into()
|
||||||
|
} else if let SetupError::Instantiate(InstantiationError::StartTrap(msg)) = e {
|
||||||
|
Trap::new(msg).into()
|
||||||
} else {
|
} else {
|
||||||
e.into()
|
e.into()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ impl fmt::Debug for UnsafeTrapInfo {
|
|||||||
|
|
||||||
/// A struct representing an aborted instruction execution, with a message
|
/// A struct representing an aborted instruction execution, with a message
|
||||||
/// indicating the cause.
|
/// indicating the cause.
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug, Clone)]
|
||||||
#[error("Wasm trap: {message}")]
|
#[error("Wasm trap: {message}")]
|
||||||
pub struct Trap {
|
pub struct Trap {
|
||||||
message: String,
|
message: String,
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.19"
|
anyhow = "1.0.19"
|
||||||
wasmtime = { path = "../api" }
|
wasmtime = { path = "../api" }
|
||||||
wasmtime-runtime = { path = "../runtime" }
|
|
||||||
wast = "4.0.0"
|
wast = "4.0.0"
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
|
|||||||
@@ -93,15 +93,10 @@ impl WastContext {
|
|||||||
}
|
}
|
||||||
let instance = match Instance::new(&self.store, &module, &imports) {
|
let instance = match Instance::new(&self.store, &module, &imports) {
|
||||||
Ok(i) => i,
|
Ok(i) => i,
|
||||||
// FIXME(#683) shouldn't have to reach into runtime crate
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
use wasmtime_runtime::InstantiationError;
|
let err = e.chain().filter_map(|e| e.downcast_ref::<Trap>()).next();
|
||||||
let err = e
|
if let Some(trap) = err {
|
||||||
.chain()
|
return Ok(Outcome::Trap(trap.clone()));
|
||||||
.filter_map(|e| e.downcast_ref::<InstantiationError>())
|
|
||||||
.next();
|
|
||||||
if let Some(InstantiationError::StartTrap(msg)) = err {
|
|
||||||
return Ok(Outcome::Trap(Trap::new(msg.clone())));
|
|
||||||
}
|
}
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user