1
0
mirror of https://github.com/fluencelabs/wasmer synced 2025-04-30 12:52:14 +00:00

56 lines
1.1 KiB
Rust
Raw Normal View History

2019-04-09 16:50:33 -07:00
use std::ptr::NonNull;
use wasmer_runtime_core::{
typed_func::Trampoline,
vm::{Ctx, Func},
};
type CallProtectedResult = Result<(), CallProtectedData>;
#[repr(C)]
pub struct CallProtectedData {
pub code: u64,
2019-03-15 14:10:17 -07:00
pub exception_address: u64,
pub instruction_pointer: u64,
}
extern "C" {
#[link_name = "callProtected"]
pub fn __call_protected(
trampoline: Trampoline,
ctx: *mut Ctx,
2019-04-09 16:50:33 -07:00
func: NonNull<Func>,
param_vec: *const u64,
return_vec: *mut u64,
out_result: *mut CallProtectedData,
) -> u8;
}
pub fn _call_protected(
trampoline: Trampoline,
ctx: *mut Ctx,
2019-04-09 16:50:33 -07:00
func: NonNull<Func>,
param_vec: *const u64,
return_vec: *mut u64,
) -> CallProtectedResult {
let mut out_result = CallProtectedData {
code: 0,
2019-03-15 14:10:17 -07:00
exception_address: 0,
instruction_pointer: 0,
};
let result = unsafe {
__call_protected(
trampoline,
ctx,
func,
param_vec,
return_vec,
&mut out_result,
)
};
if result == 1 {
Ok(())
} else {
Err(out_result)
}
}