mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-16 08:10:49 +00:00
Rename internal enum to make less confusing
This commit is contained in:
parent
aa9cd84085
commit
14325c975e
@ -27,7 +27,7 @@ thread_local! {
|
||||
pub static TRAP_EARLY_DATA: Cell<Option<Box<dyn Any>>> = Cell::new(None);
|
||||
}
|
||||
|
||||
pub enum RunErr {
|
||||
pub enum CallProtError {
|
||||
Trap(WasmTrapInfo),
|
||||
Error(Box<dyn Any>),
|
||||
}
|
||||
@ -83,8 +83,8 @@ impl RunnableModule for Caller {
|
||||
match res {
|
||||
Err(err) => {
|
||||
match err {
|
||||
RunErr::Trap(info) => *trap_info = info,
|
||||
RunErr::Error(data) => *user_error = Some(data),
|
||||
CallProtError::Trap(info) => *trap_info = info,
|
||||
CallProtError::Error(data) => *user_error = Some(data),
|
||||
}
|
||||
false
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
//! unless you have memory unsafety elsewhere in your code.
|
||||
//!
|
||||
use crate::relocation::{TrapCode, TrapData};
|
||||
use crate::signal::{HandlerData, RunErr};
|
||||
use crate::signal::{CallProtError, HandlerData};
|
||||
use libc::{c_int, c_void, siginfo_t};
|
||||
use nix::sys::signal::{
|
||||
sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal, SIGBUS, SIGFPE, SIGILL, SIGSEGV,
|
||||
@ -62,7 +62,10 @@ pub unsafe fn trigger_trap() -> ! {
|
||||
longjmp(jmp_buf as *mut c_void, 0)
|
||||
}
|
||||
|
||||
pub fn call_protected<T>(handler_data: &HandlerData, f: impl FnOnce() -> T) -> Result<T, RunErr> {
|
||||
pub fn call_protected<T>(
|
||||
handler_data: &HandlerData,
|
||||
f: impl FnOnce() -> T,
|
||||
) -> Result<T, CallProtError> {
|
||||
unsafe {
|
||||
let jmp_buf = SETJMP_BUFFER.with(|buf| buf.get());
|
||||
let prev_jmp_buf = *jmp_buf;
|
||||
@ -76,7 +79,7 @@ pub fn call_protected<T>(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R
|
||||
*jmp_buf = prev_jmp_buf;
|
||||
|
||||
if let Some(data) = super::TRAP_EARLY_DATA.with(|cell| cell.replace(None)) {
|
||||
Err(RunErr::Error(data))
|
||||
Err(CallProtError::Error(data))
|
||||
} else {
|
||||
let (faulting_addr, inst_ptr) = CAUGHT_ADDRESSES.with(|cell| cell.get());
|
||||
|
||||
@ -85,7 +88,7 @@ pub fn call_protected<T>(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R
|
||||
srcloc: _,
|
||||
}) = handler_data.lookup(inst_ptr)
|
||||
{
|
||||
Err(RunErr::Trap(match Signal::from_c_int(signum) {
|
||||
Err(CallProtError::Trap(match Signal::from_c_int(signum) {
|
||||
Ok(SIGILL) => match trapcode {
|
||||
TrapCode::BadSignature => WasmTrapInfo::IncorrectCallIndirectSignature,
|
||||
TrapCode::IndirectCallToNull => WasmTrapInfo::CallIndirectOOB,
|
||||
@ -108,7 +111,7 @@ pub fn call_protected<T>(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R
|
||||
};
|
||||
// When the trap-handler is fully implemented, this will return more information.
|
||||
let s = format!("unknown trap at {:p} - {}", faulting_addr, signal);
|
||||
Err(RunErr::Error(Box::new(s)))
|
||||
Err(CallProtError::Error(Box::new(s)))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::relocation::{TrapCode, TrapData};
|
||||
use crate::signal::{HandlerData, RunErr};
|
||||
use crate::signal::{CallProtError, HandlerData};
|
||||
use crate::trampoline::Trampoline;
|
||||
use std::cell::Cell;
|
||||
use std::ffi::c_void;
|
||||
@ -29,7 +29,7 @@ pub fn call_protected(
|
||||
func: NonNull<Func>,
|
||||
param_vec: *const u64,
|
||||
return_vec: *mut u64,
|
||||
) -> Result<(), RunErr> {
|
||||
) -> Result<(), CallProtError> {
|
||||
// TODO: trap early
|
||||
// user code error
|
||||
// if let Some(msg) = super::TRAP_EARLY_DATA.with(|cell| cell.replace(None)) {
|
||||
@ -53,7 +53,7 @@ pub fn call_protected(
|
||||
srcloc: _,
|
||||
}) = handler_data.lookup(instruction_pointer as _)
|
||||
{
|
||||
Err(RunErr::Trap(match signum as DWORD {
|
||||
Err(CallProtError::Trap(match signum as DWORD {
|
||||
EXCEPTION_ACCESS_VIOLATION => WasmTrapInfo::MemoryOutOfBounds,
|
||||
EXCEPTION_ILLEGAL_INSTRUCTION => match trapcode {
|
||||
TrapCode::BadSignature => WasmTrapInfo::IncorrectCallIndirectSignature,
|
||||
@ -85,7 +85,7 @@ pub fn call_protected(
|
||||
|
||||
let s = format!("unknown trap at {} - {}", exception_address, signal);
|
||||
|
||||
Err(RunErr::Error(Box::new(s)))
|
||||
Err(CallProtError::Error(Box::new(s)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,8 +230,8 @@ impl RunnableModule for X64ExecutionContext {
|
||||
}
|
||||
Err(err) => {
|
||||
match err {
|
||||
protect_unix::RunErr::Trap(info) => *trap_info = info,
|
||||
protect_unix::RunErr::Error(data) => *user_error = Some(data),
|
||||
protect_unix::CallProtError::Trap(info) => *trap_info = info,
|
||||
protect_unix::CallProtError::Error(data) => *user_error = Some(data),
|
||||
}
|
||||
false
|
||||
}
|
||||
|
@ -62,12 +62,12 @@ pub unsafe fn trigger_trap() -> ! {
|
||||
longjmp(jmp_buf as *mut c_void, 0)
|
||||
}
|
||||
|
||||
pub enum RunErr {
|
||||
pub enum CallProtError {
|
||||
Trap(WasmTrapInfo),
|
||||
Error(Box<dyn Any>),
|
||||
}
|
||||
|
||||
pub fn call_protected<T>(f: impl FnOnce() -> T) -> Result<T, RunErr> {
|
||||
pub fn call_protected<T>(f: impl FnOnce() -> T) -> Result<T, CallProtError> {
|
||||
unsafe {
|
||||
let jmp_buf = SETJMP_BUFFER.with(|buf| buf.get());
|
||||
let prev_jmp_buf = *jmp_buf;
|
||||
@ -81,7 +81,7 @@ pub fn call_protected<T>(f: impl FnOnce() -> T) -> Result<T, RunErr> {
|
||||
*jmp_buf = prev_jmp_buf;
|
||||
|
||||
if let Some(data) = TRAP_EARLY_DATA.with(|cell| cell.replace(None)) {
|
||||
Err(RunErr::Error(data))
|
||||
Err(CallProtError::Error(data))
|
||||
} else {
|
||||
// let (faulting_addr, _inst_ptr) = CAUGHT_ADDRESSES.with(|cell| cell.get());
|
||||
|
||||
@ -98,7 +98,7 @@ pub fn call_protected<T>(f: impl FnOnce() -> T) -> Result<T, RunErr> {
|
||||
// msg: format!("unknown trap at {:p} - {}", faulting_addr, signal).into(),
|
||||
// }
|
||||
// .into())
|
||||
Err(RunErr::Trap(WasmTrapInfo::Unknown))
|
||||
Err(CallProtError::Trap(WasmTrapInfo::Unknown))
|
||||
}
|
||||
} else {
|
||||
let ret = f(); // TODO: Switch stack?
|
||||
|
Loading…
x
Reference in New Issue
Block a user