mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-04 18:10:18 +00:00
Fix new RuntimeError integration with the LLVM-backend
This commit is contained in:
parent
2bbe3406cf
commit
cffdb387f7
@ -4,7 +4,6 @@ extern "C" {
|
||||
fn host_callback() -> u32;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
fn test_callback() -> u32 {
|
||||
42
|
||||
}
|
||||
|
Binary file not shown.
@ -13,7 +13,7 @@ MemoryManager::~MemoryManager() {
|
||||
callbacks.dealloc_memory(read_section.base, read_section.size);
|
||||
callbacks.dealloc_memory(readwrite_section.base, readwrite_section.size);
|
||||
}
|
||||
void unwinding_setjmp(jmp_buf stack_out, void (*func)(void *), void *userdata) {
|
||||
void unwinding_setjmp(jmp_buf &stack_out, void (*func)(void *), void *userdata) {
|
||||
if (setjmp(stack_out)) {
|
||||
|
||||
} else {
|
||||
|
@ -63,6 +63,8 @@ enum WasmTrapType {
|
||||
|
||||
extern "C" void callback_trampoline(void *, void *);
|
||||
|
||||
extern "C" void copy_runtime_error(runtime_error_t src, runtime_error_t dst);
|
||||
|
||||
struct MemoryManager : llvm::RuntimeDyld::MemoryManager {
|
||||
public:
|
||||
MemoryManager(callbacks_t callbacks) : callbacks(callbacks) {}
|
||||
@ -159,7 +161,7 @@ public:
|
||||
runtime_error_t error_data;
|
||||
|
||||
virtual void write_error(WasmErrorSink &out) const noexcept override {
|
||||
out.user_error = error_data;
|
||||
copy_runtime_error(error_data, out.user_error);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -69,6 +69,16 @@ extern "C" {
|
||||
) -> bool;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn copy_runtime_error(
|
||||
src: *mut Option<RuntimeError>,
|
||||
dst: *mut Option<RuntimeError>,
|
||||
) {
|
||||
assert_eq!(src as usize % mem::align_of::<Option<RuntimeError>>(), 0);
|
||||
assert_eq!(dst as usize % mem::align_of::<Option<RuntimeError>>(), 0);
|
||||
ptr::copy::<Option<RuntimeError>>(src, dst, 1);
|
||||
}
|
||||
|
||||
/// `invoke_trampoline` is a wrapper around `cxx_invoke_trampoline`, for fixing up the obsoleted
|
||||
/// `trap_out` in the C++ part.
|
||||
unsafe extern "C" fn invoke_trampoline(
|
||||
|
@ -944,10 +944,8 @@ pub unsafe extern "C" fn callback_trampoline(
|
||||
b: *mut Option<RuntimeError>,
|
||||
callback: *mut BreakpointHandler,
|
||||
) {
|
||||
dbg!("In llvm's callback_trampoline");
|
||||
let callback = Box::from_raw(callback);
|
||||
let result: Result<(), RuntimeError> = callback(BreakpointInfo { fault: None });
|
||||
dbg!(&*b);
|
||||
match result {
|
||||
Ok(()) => *b = None,
|
||||
Err(e) => *b = Some(e),
|
||||
|
@ -281,7 +281,7 @@ extern "C" fn signal_trap_handler(
|
||||
let mut should_unwind = false;
|
||||
let mut unwind_result: Option<Box<RuntimeError>> = None;
|
||||
let get_unwind_result = |uw_result: Option<Box<RuntimeError>>| -> Box<RuntimeError> {
|
||||
dbg!(uw_result)
|
||||
uw_result
|
||||
.unwrap_or_else(|| Box::new(RuntimeError::InvokeError(InvokeError::FailedWithNoError)))
|
||||
};
|
||||
|
||||
|
@ -602,8 +602,10 @@ pub(crate) fn call_func_with_index_inner(
|
||||
if success {
|
||||
Ok(())
|
||||
} else {
|
||||
let error: RuntimeError = dbg!(error_out)
|
||||
.map_or_else(|| RuntimeError::InvokeError(InvokeError::FailedWithNoError), Into::into);
|
||||
let error: RuntimeError = error_out.map_or_else(
|
||||
|| RuntimeError::InvokeError(InvokeError::FailedWithNoError),
|
||||
Into::into,
|
||||
);
|
||||
dbg!(&error);
|
||||
Err(error.into())
|
||||
}
|
||||
|
@ -590,7 +590,7 @@ macro_rules! impl_traits {
|
||||
) {
|
||||
Ok(Rets::from_ret_array(rets))
|
||||
} else {
|
||||
Err(dbg!(error_out).map_or_else(|| RuntimeError::InvokeError(InvokeError::FailedWithNoError), Into::into))
|
||||
Err(error_out.map_or_else(|| RuntimeError::InvokeError(InvokeError::FailedWithNoError), Into::into))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -268,18 +268,7 @@ wasmer_backends! {
|
||||
|
||||
let result = foo.call();
|
||||
|
||||
dbg!(&result);
|
||||
if let Err(e) = &result {
|
||||
dbg!(&e);
|
||||
eprintln!("{}", &e);
|
||||
}
|
||||
match &result {
|
||||
Err(RuntimeError::User(e)) => { dbg!("USER", &e); } ,
|
||||
Err(e) => {dbg!("GENERIC",&e); } ,
|
||||
_ => { dbg!("OKaY!"); },
|
||||
}
|
||||
if let Err(RuntimeError::User(e)) = result {
|
||||
dbg!("WAT");
|
||||
let exit_code = e.downcast::<ExitCode>().unwrap();
|
||||
assert_eq!(exit_code.code, 42);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user