Naive short circuiting implementation for user panics and results. (#167)

* Add panic and result catching

* exit process on panic and user runtime error

* Complete initial implementation
This commit is contained in:
Lachlan Sneff
2019-02-08 13:08:03 -08:00
committed by GitHub
parent 4e1bc483a8
commit 1886b3d3c1
10 changed files with 171 additions and 60 deletions

View File

@ -2,9 +2,9 @@ use crate::relocation::{TrapData, TrapSink};
use crate::trampoline::Trampolines;
use hashbrown::HashSet;
use libc::c_void;
use std::sync::Arc;
use std::{cell::Cell, sync::Arc};
use wasmer_runtime_core::{
backend::{ProtectedCaller, Token},
backend::{ProtectedCaller, Token, UserTrapper},
error::RuntimeResult,
export::Context,
module::{ExportIndex, ModuleInfo, ModuleInner},
@ -24,6 +24,19 @@ pub use self::unix::*;
#[cfg(windows)]
pub use self::windows::*;
thread_local! {
pub static TRAP_EARLY_DATA: Cell<Option<String>> = Cell::new(None);
}
pub struct Trapper;
impl UserTrapper for Trapper {
unsafe fn do_early_trap(&self, msg: String) -> ! {
TRAP_EARLY_DATA.with(|cell| cell.set(Some(msg)));
trigger_trap()
}
}
pub struct Caller {
func_export_set: HashSet<FuncIndex>,
handler_data: HandlerData,
@ -118,6 +131,10 @@ impl ProtectedCaller for Caller {
})
.collect())
}
fn get_early_trapper(&self) -> Box<dyn UserTrapper> {
Box::new(Trapper)
}
}
fn get_func_from_index(