mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-25 18:32:15 +00:00
Remove UserTrapper trait
This commit is contained in:
parent
ccad8874e9
commit
4dd64ed72e
@ -4,7 +4,7 @@ use crate::trampoline::Trampolines;
|
|||||||
use libc::c_void;
|
use libc::c_void;
|
||||||
use std::{any::Any, cell::Cell, ptr::NonNull, sync::Arc};
|
use std::{any::Any, cell::Cell, ptr::NonNull, sync::Arc};
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
backend::{RunnableModule, UserTrapper},
|
backend::RunnableModule,
|
||||||
module::ModuleInfo,
|
module::ModuleInfo,
|
||||||
typed_func::{Wasm, WasmTrapInfo},
|
typed_func::{Wasm, WasmTrapInfo},
|
||||||
types::{LocalFuncIndex, SigIndex},
|
types::{LocalFuncIndex, SigIndex},
|
||||||
@ -27,15 +27,6 @@ thread_local! {
|
|||||||
pub static TRAP_EARLY_DATA: Cell<Option<Box<dyn Any>>> = Cell::new(None);
|
pub static TRAP_EARLY_DATA: Cell<Option<Box<dyn Any>>> = Cell::new(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Trapper;
|
|
||||||
|
|
||||||
impl UserTrapper for Trapper {
|
|
||||||
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> ! {
|
|
||||||
TRAP_EARLY_DATA.with(|cell| cell.set(Some(data)));
|
|
||||||
trigger_trap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Caller {
|
pub struct Caller {
|
||||||
handler_data: HandlerData,
|
handler_data: HandlerData,
|
||||||
trampolines: Arc<Trampolines>,
|
trampolines: Arc<Trampolines>,
|
||||||
@ -101,8 +92,9 @@ impl RunnableModule for Caller {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_early_trapper(&self) -> Box<dyn UserTrapper> {
|
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> ! {
|
||||||
Box::new(Trapper)
|
TRAP_EARLY_DATA.with(|cell| cell.set(Some(data)));
|
||||||
|
trigger_trap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ use std::{
|
|||||||
sync::Once,
|
sync::Once,
|
||||||
};
|
};
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
backend::{RunnableModule, UserTrapper},
|
backend::RunnableModule,
|
||||||
module::ModuleInfo,
|
module::ModuleInfo,
|
||||||
structures::TypedIndex,
|
structures::TypedIndex,
|
||||||
typed_func::{Wasm, WasmTrapInfo},
|
typed_func::{Wasm, WasmTrapInfo},
|
||||||
@ -317,14 +317,6 @@ impl RunnableModule for LLVMBackend {
|
|||||||
Some(unsafe { Wasm::from_raw_parts(trampoline, invoke_trampoline, None) })
|
Some(unsafe { Wasm::from_raw_parts(trampoline, invoke_trampoline, None) })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_early_trapper(&self) -> Box<dyn UserTrapper> {
|
|
||||||
Box::new(Placeholder)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Placeholder;
|
|
||||||
|
|
||||||
impl UserTrapper for Placeholder {
|
|
||||||
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> ! {
|
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> ! {
|
||||||
throw_any(Box::leak(data))
|
throw_any(Box::leak(data))
|
||||||
}
|
}
|
||||||
|
@ -65,10 +65,6 @@ pub trait Compiler {
|
|||||||
unsafe fn from_cache(&self, cache: Artifact, _: Token) -> Result<ModuleInner, CacheError>;
|
unsafe fn from_cache(&self, cache: Artifact, _: Token) -> Result<ModuleInner, CacheError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait UserTrapper {
|
|
||||||
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> !;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait RunnableModule: Send + Sync {
|
pub trait RunnableModule: Send + Sync {
|
||||||
/// This returns a pointer to the function designated by the `local_func_index`
|
/// This returns a pointer to the function designated by the `local_func_index`
|
||||||
/// parameter.
|
/// parameter.
|
||||||
@ -83,7 +79,7 @@ pub trait RunnableModule: Send + Sync {
|
|||||||
/// signature and an invoke function that can call the trampoline.
|
/// signature and an invoke function that can call the trampoline.
|
||||||
fn get_trampoline(&self, info: &ModuleInfo, sig_index: SigIndex) -> Option<Wasm>;
|
fn get_trampoline(&self, info: &ModuleInfo, sig_index: SigIndex) -> Option<Wasm>;
|
||||||
|
|
||||||
fn get_early_trapper(&self) -> Box<dyn UserTrapper>;
|
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> !;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CacheGen: Send + Sync {
|
pub trait CacheGen: Send + Sync {
|
||||||
|
@ -4,7 +4,6 @@ use crate::{
|
|||||||
error,
|
error,
|
||||||
import::ImportObject,
|
import::ImportObject,
|
||||||
structures::{Map, TypedIndex},
|
structures::{Map, TypedIndex},
|
||||||
typed_func::EARLY_TRAPPER,
|
|
||||||
types::{
|
types::{
|
||||||
FuncIndex, FuncSig, GlobalDescriptor, GlobalIndex, GlobalInit, ImportedFuncIndex,
|
FuncIndex, FuncSig, GlobalDescriptor, GlobalIndex, GlobalInit, ImportedFuncIndex,
|
||||||
ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex, Initializer,
|
ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex, Initializer,
|
||||||
@ -92,10 +91,6 @@ pub struct Module {
|
|||||||
|
|
||||||
impl Module {
|
impl Module {
|
||||||
pub(crate) fn new(inner: Arc<ModuleInner>) -> Self {
|
pub(crate) fn new(inner: Arc<ModuleInner>) -> Self {
|
||||||
unsafe {
|
|
||||||
EARLY_TRAPPER
|
|
||||||
.with(|ucell| *ucell.get() = Some(inner.runnable_module.get_early_trapper()));
|
|
||||||
}
|
|
||||||
Module { inner }
|
Module { inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
backend::UserTrapper,
|
|
||||||
error::RuntimeError,
|
error::RuntimeError,
|
||||||
export::{Context, Export, FuncPointer},
|
export::{Context, Export, FuncPointer},
|
||||||
import::IsExport,
|
import::IsExport,
|
||||||
@ -8,7 +7,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
any::Any,
|
any::Any,
|
||||||
cell::UnsafeCell,
|
|
||||||
ffi::c_void,
|
ffi::c_void,
|
||||||
fmt,
|
fmt,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
@ -17,10 +15,6 @@ use std::{
|
|||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
thread_local! {
|
|
||||||
pub static EARLY_TRAPPER: UnsafeCell<Option<Box<dyn UserTrapper>>> = UnsafeCell::new(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum WasmTrapInfo {
|
pub enum WasmTrapInfo {
|
||||||
Unreachable = 0,
|
Unreachable = 0,
|
||||||
@ -354,12 +348,7 @@ macro_rules! impl_traits {
|
|||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if let Some(early_trapper) = &*EARLY_TRAPPER.with(|ucell| ucell.get()) {
|
(&*ctx.module).runnable_module.do_early_trap(err)
|
||||||
early_trapper.do_early_trap(err)
|
|
||||||
} else {
|
|
||||||
eprintln!("panic handling not setup");
|
|
||||||
std::process::exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ pub struct Ctx {
|
|||||||
|
|
||||||
local_backing: *mut LocalBacking,
|
local_backing: *mut LocalBacking,
|
||||||
import_backing: *mut ImportBacking,
|
import_backing: *mut ImportBacking,
|
||||||
module: *const ModuleInner,
|
pub(crate) module: *const ModuleInner,
|
||||||
|
|
||||||
pub data: *mut c_void,
|
pub data: *mut c_void,
|
||||||
pub data_finalizer: Option<fn(data: *mut c_void)>,
|
pub data_finalizer: Option<fn(data: *mut c_void)>,
|
||||||
|
@ -59,9 +59,9 @@ fn main() -> Result<(), error::Error> {
|
|||||||
},
|
},
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let foo = instance.dyn_func("dbz")?;
|
let foo: Func<(), i32> = instance.func("dbz")?;
|
||||||
|
|
||||||
let result = foo.call(&[]);
|
let result = foo.call();
|
||||||
|
|
||||||
println!("result: {:?}", result);
|
println!("result: {:?}", result);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use smallvec::SmallVec;
|
|||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::{any::Any, collections::HashMap, sync::Arc};
|
use std::{any::Any, collections::HashMap, sync::Arc};
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
backend::{RunnableModule, UserTrapper},
|
backend::RunnableModule,
|
||||||
memory::MemoryType,
|
memory::MemoryType,
|
||||||
module::ModuleInfo,
|
module::ModuleInfo,
|
||||||
structures::{Map, TypedIndex},
|
structures::{Map, TypedIndex},
|
||||||
@ -249,17 +249,9 @@ impl RunnableModule for X64ExecutionContext {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_early_trapper(&self) -> Box<dyn UserTrapper> {
|
unsafe fn do_early_trap(&self, data: Box<Any>) -> ! {
|
||||||
pub struct Trapper;
|
protect_unix::TRAP_EARLY_DATA.with(|x| x.set(Some(data)));
|
||||||
|
protect_unix::trigger_trap();
|
||||||
impl UserTrapper for Trapper {
|
|
||||||
unsafe fn do_early_trap(&self, data: Box<Any>) -> ! {
|
|
||||||
protect_unix::TRAP_EARLY_DATA.with(|x| x.set(Some(data)));
|
|
||||||
protect_unix::trigger_trap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Box::new(Trapper)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user