rust: catch exceptions in the entire execute() wrapper

This commit is contained in:
Alex Beregszaszi 2019-07-15 13:07:42 +01:00
parent e3463a379c
commit 99ca1e2b63
1 changed files with 30 additions and 28 deletions

View File

@ -337,6 +337,7 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
{
use evmc_vm::EvmcVm;
let result = ::std::panic::catch_unwind(|| {
assert!(!instance.is_null());
// TODO: context is optional in case of the "precompiles" capability
assert!(!context.is_null());
@ -360,11 +361,16 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
::evmc_vm::EvmcContainer::<#type_name_ident>::from_ffi_pointer(instance)
};
let result = ::std::panic::catch_unwind(|| {
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()
}
}