mirror of https://github.com/status-im/evmc.git
rust: catch exceptions in the entire execute() wrapper
This commit is contained in:
parent
e3463a379c
commit
99ca1e2b63
|
@ -337,34 +337,40 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
|
|||
{
|
||||
use evmc_vm::EvmcVm;
|
||||
|
||||
assert!(!instance.is_null());
|
||||
// TODO: context is optional in case of the "precompiles" capability
|
||||
assert!(!context.is_null());
|
||||
assert!(!msg.is_null());
|
||||
|
||||
let execution_message: ::evmc_vm::ExecutionMessage = unsafe {
|
||||
msg.as_ref().expect("EVMC message is null").into()
|
||||
};
|
||||
|
||||
let empty_code = [0u8;0];
|
||||
let code_ref: &[u8] = if code.is_null() {
|
||||
assert_eq!(code_size, 0);
|
||||
&empty_code
|
||||
} else {
|
||||
unsafe {
|
||||
::std::slice::from_raw_parts(code, code_size)
|
||||
}
|
||||
};
|
||||
|
||||
let container = unsafe {
|
||||
::evmc_vm::EvmcContainer::<#type_name_ident>::from_ffi_pointer(instance)
|
||||
};
|
||||
|
||||
let result = ::std::panic::catch_unwind(|| {
|
||||
assert!(!instance.is_null());
|
||||
// TODO: context is optional in case of the "precompiles" capability
|
||||
assert!(!context.is_null());
|
||||
assert!(!msg.is_null());
|
||||
|
||||
let execution_message: ::evmc_vm::ExecutionMessage = unsafe {
|
||||
msg.as_ref().expect("EVMC message is null").into()
|
||||
};
|
||||
|
||||
let empty_code = [0u8;0];
|
||||
let code_ref: &[u8] = if code.is_null() {
|
||||
assert_eq!(code_size, 0);
|
||||
&empty_code
|
||||
} else {
|
||||
unsafe {
|
||||
::std::slice::from_raw_parts(code, code_size)
|
||||
}
|
||||
};
|
||||
|
||||
let container = unsafe {
|
||||
::evmc_vm::EvmcContainer::<#type_name_ident>::from_ffi_pointer(instance)
|
||||
};
|
||||
|
||||
let mut execution_context = unsafe {
|
||||
::evmc_vm::ExecutionContext::new(context.as_mut().expect("EVMC context is null"))
|
||||
};
|
||||
container.execute(revision, code_ref, &execution_message, &mut execution_context)
|
||||
let result = container.execute(revision, code_ref, &execution_message, &mut execution_context);
|
||||
|
||||
unsafe {
|
||||
::evmc_vm::EvmcContainer::into_ffi_pointer(container);
|
||||
}
|
||||
|
||||
result
|
||||
});
|
||||
|
||||
let result = if result.is_err() {
|
||||
|
@ -374,10 +380,6 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
|
|||
result.unwrap()
|
||||
};
|
||||
|
||||
unsafe {
|
||||
::evmc_vm::EvmcContainer::into_ffi_pointer(container);
|
||||
}
|
||||
|
||||
result.into()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue