Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: unwind execution panics in evmc-declare #316

Merged
merged 1 commit into from
Jun 6, 2019
Merged

rust: unwind execution panics in evmc-declare #316

merged 1 commit into from
Jun 6, 2019

Conversation

axic
Copy link
Member

@axic axic commented Jun 5, 2019

Fixes #310.

@axic axic requested a review from jakelang June 5, 2019 22:38
@@ -363,7 +363,15 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
::evmc_vm::EvmcContainer::<#type_name_ident>::from_ffi_pointer(instance)
};

let result = container.execute(code_ref, &execution_context);
let result = ::std::panic::catch_unwind(|| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not recommended to use this function for a general try/catch mechanism. The Result type is more appropriate to use for functions that can fail on a regular basis. Additionally, this function is not guaranteed to catch all panics, see the "Notes" section below.

https://doc.rust-lang.org/std/panic/fn.catch_unwind.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason for this change is exactly listed in your link:

It is currently undefined behavior to unwind from Rust code into foreign code, so this function is particularly useful when Rust is called from another language (normally C). This can run arbitrary Rust code, capturing a panic and allowing a graceful handling of the error.

@axic axic merged commit 9b2de67 into master Jun 6, 2019
@axic axic deleted the rust-panic branch June 6, 2019 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rust: unwind panics for the execute method
2 participants