mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-12 08:31:21 +00:00
For error handling and breakpoints, use Box<Any + Send> instead of Box<Any>.
This commit is contained in:
@ -271,7 +271,7 @@ pub trait RunnableModule: Send + Sync {
|
||||
/// signature and an invoke function that can call the trampoline.
|
||||
fn get_trampoline(&self, info: &ModuleInfo, sig_index: SigIndex) -> Option<Wasm>;
|
||||
|
||||
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> !;
|
||||
unsafe fn do_early_trap(&self, data: Box<dyn Any + Send>) -> !;
|
||||
|
||||
/// Returns the machine code associated with this module.
|
||||
fn get_code(&self) -> Option<&[u8]> {
|
||||
|
@ -23,7 +23,7 @@ use wasmparser::{Operator, Type as WpType};
|
||||
|
||||
/// A type that defines a function pointer, which is called when breakpoints occur.
|
||||
pub type BreakpointHandler =
|
||||
Box<dyn Fn(BreakpointInfo) -> Result<(), Box<dyn Any>> + Send + Sync + 'static>;
|
||||
Box<dyn Fn(BreakpointInfo) -> Result<(), Box<dyn Any + Send>> + Send + Sync + 'static>;
|
||||
|
||||
/// Maps instruction pointers to their breakpoint handlers.
|
||||
pub type BreakpointMap = Arc<HashMap<usize, BreakpointHandler>>;
|
||||
|
@ -187,7 +187,7 @@ pub enum RuntimeError {
|
||||
/// Error.
|
||||
Error {
|
||||
/// Error data.
|
||||
data: Box<dyn Any>,
|
||||
data: Box<dyn Any + Send>,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ type SetJmpBuffer = [i32; SETJMP_BUFFER_LEN];
|
||||
struct UnwindInfo {
|
||||
jmpbuf: SetJmpBuffer, // in
|
||||
breakpoints: Option<BreakpointMap>,
|
||||
payload: Option<Box<dyn Any>>, // out
|
||||
payload: Option<Box<dyn Any + Send>>, // out
|
||||
}
|
||||
|
||||
/// A store for boundary register preservation.
|
||||
@ -182,7 +182,7 @@ pub unsafe fn clear_wasm_interrupt() {
|
||||
pub unsafe fn catch_unsafe_unwind<R, F: FnOnce() -> R>(
|
||||
f: F,
|
||||
breakpoints: Option<BreakpointMap>,
|
||||
) -> Result<R, Box<dyn Any>> {
|
||||
) -> Result<R, Box<dyn Any + Send>> {
|
||||
let unwind = UNWIND.with(|x| x.get());
|
||||
let old = (*unwind).take();
|
||||
*unwind = Some(UnwindInfo {
|
||||
@ -205,7 +205,7 @@ pub unsafe fn catch_unsafe_unwind<R, F: FnOnce() -> R>(
|
||||
}
|
||||
|
||||
/// Begins an unsafe unwind.
|
||||
pub unsafe fn begin_unsafe_unwind(e: Box<dyn Any>) -> ! {
|
||||
pub unsafe fn begin_unsafe_unwind(e: Box<dyn Any + Send>) -> ! {
|
||||
let unwind = UNWIND.with(|x| x.get());
|
||||
let inner = (*unwind)
|
||||
.as_mut()
|
||||
@ -283,7 +283,7 @@ extern "C" fn signal_trap_handler(
|
||||
static ARCH: Architecture = Architecture::Aarch64;
|
||||
|
||||
let mut should_unwind = false;
|
||||
let mut unwind_result: Box<dyn Any> = Box::new(());
|
||||
let mut unwind_result: Box<dyn Any + Send> = Box::new(());
|
||||
|
||||
unsafe {
|
||||
let fault = get_fault_info(siginfo as _, ucontext);
|
||||
@ -307,7 +307,7 @@ extern "C" fn signal_trap_handler(
|
||||
match ib.ty {
|
||||
InlineBreakpointType::Trace => {}
|
||||
InlineBreakpointType::Middleware => {
|
||||
let out: Option<Result<(), Box<dyn Any>>> =
|
||||
let out: Option<Result<(), Box<dyn Any + Send>>> =
|
||||
with_breakpoint_map(|bkpt_map| {
|
||||
bkpt_map.and_then(|x| x.get(&ip)).map(|x| {
|
||||
x(BreakpointInfo {
|
||||
@ -348,13 +348,14 @@ extern "C" fn signal_trap_handler(
|
||||
match Signal::from_c_int(signum) {
|
||||
Ok(SIGTRAP) => {
|
||||
// breakpoint
|
||||
let out: Option<Result<(), Box<dyn Any>>> = with_breakpoint_map(|bkpt_map| {
|
||||
bkpt_map.and_then(|x| x.get(&(fault.ip.get()))).map(|x| {
|
||||
x(BreakpointInfo {
|
||||
fault: Some(&fault),
|
||||
let out: Option<Result<(), Box<dyn Any + Send>>> =
|
||||
with_breakpoint_map(|bkpt_map| {
|
||||
bkpt_map.and_then(|x| x.get(&(fault.ip.get()))).map(|x| {
|
||||
x(BreakpointInfo {
|
||||
fault: Some(&fault),
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
match out {
|
||||
Some(Ok(())) => {
|
||||
return false;
|
||||
|
@ -652,7 +652,7 @@ pub mod x64 {
|
||||
image: InstanceImage,
|
||||
vmctx: &mut Ctx,
|
||||
breakpoints: Option<BreakpointMap>,
|
||||
) -> Result<u64, Box<dyn Any>> {
|
||||
) -> Result<u64, Box<dyn Any + Send>> {
|
||||
let mut stack: Vec<u64> = vec![0; 1048576 * 8 / 8]; // 8MB stack
|
||||
let mut stack_offset: usize = stack.len();
|
||||
|
||||
|
@ -78,7 +78,7 @@ pub type Invoke = unsafe extern "C" fn(
|
||||
args: *const u64,
|
||||
rets: *mut u64,
|
||||
trap_info: *mut WasmTrapInfo,
|
||||
user_error: *mut Option<Box<dyn Any>>,
|
||||
user_error: *mut Option<Box<dyn Any + Send>>,
|
||||
extra: Option<NonNull<c_void>>,
|
||||
) -> bool;
|
||||
|
||||
@ -201,7 +201,7 @@ where
|
||||
Rets: WasmTypeList,
|
||||
{
|
||||
/// The error type for this trait.
|
||||
type Error: 'static;
|
||||
type Error: Send + 'static;
|
||||
/// Get returns or error result.
|
||||
fn report(self) -> Result<Rets, Self::Error>;
|
||||
}
|
||||
@ -219,7 +219,7 @@ where
|
||||
impl<Rets, E> TrapEarly<Rets> for Result<Rets, E>
|
||||
where
|
||||
Rets: WasmTypeList,
|
||||
E: 'static,
|
||||
E: Send + 'static,
|
||||
{
|
||||
type Error = E;
|
||||
fn report(self) -> Result<Rets, E> {
|
||||
@ -507,7 +507,7 @@ macro_rules! impl_traits {
|
||||
Ok(Ok(returns)) => return returns.into_c_struct(),
|
||||
Ok(Err(err)) => {
|
||||
let b: Box<_> = err.into();
|
||||
b as Box<dyn Any>
|
||||
b as Box<dyn Any + Send>
|
||||
},
|
||||
Err(err) => err,
|
||||
};
|
||||
@ -619,7 +619,7 @@ macro_rules! impl_traits {
|
||||
Ok(Ok(returns)) => return returns.into_c_struct(),
|
||||
Ok(Err(err)) => {
|
||||
let b: Box<_> = err.into();
|
||||
b as Box<dyn Any>
|
||||
b as Box<dyn Any + Send>
|
||||
},
|
||||
Err(err) => err,
|
||||
};
|
||||
|
@ -1069,7 +1069,7 @@ mod vm_ctx_tests {
|
||||
fn get_trampoline(&self, _module: &ModuleInfo, _sig_index: SigIndex) -> Option<Wasm> {
|
||||
unimplemented!("generate_module::get_trampoline")
|
||||
}
|
||||
unsafe fn do_early_trap(&self, _: Box<dyn Any>) -> ! {
|
||||
unsafe fn do_early_trap(&self, _: Box<dyn Any + Send>) -> ! {
|
||||
unimplemented!("generate_module::do_early_trap")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user