Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Adds host function for handle panicking #7954

Closed
wants to merge 1 commit into from
Closed

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Jan 21, 2021

This pr adds an extra host function that should be called by the wasm
instance when its panicking. Currently we only log such a panic with an
error severity. In the future we would call this host function and
have the advantage that the panic message would be returned as error,
instead of just some generic "panicked" message.

This pr only adds the host function and the client side implementation.
Some future pr would switch over the runtime to use this functionality.

This pr adds an extra host function that should be called by the wasm
instance when its panicking. Currently we only log such a panic with an
error severity. In the future we would call this host function and
have the advantage that the panic message would be returned as error,
instead of just some generic "panicked" message.

This pr only adds the host function and the client side implementation.
Some future pr would switch over the runtime to use this functionality.
@bkchr bkchr added A0-please_review Pull request needs code review. B5-clientnoteworthy C1-low PR touches the given topic and has a low impact on builders. labels Jan 21, 2021
@bkchr bkchr requested a review from pepyakin January 21, 2021 23:44
@@ -46,6 +46,7 @@ struct FunctionExecutor<'a> {
host_functions: &'a [&'static dyn Function],
allow_missing_func_imports: bool,
missing_functions: &'a [String],
instance_panicked: Option<Error>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be just panicked maybe?

/// Should be called when the wasm instance is panicking.
///
/// The given `message` should correspond to the reason the instance panicked.
fn panicking(&mut self, message: &str) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just panicked for consistency?

trait PanicHandler {
/// Should be called when the wasm instance is panicking.
///
/// The given `message` should correspond to the reason the instance panicked.
Copy link
Contributor

Choose a reason for hiding this comment

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

Some points that should be IMO addressed in the docs:

  1. It's not mandatory to call this function when "panic" happens, but if the user does it, then they will get a proper message and not a message some general trap message.
  2. panicking is a Rust term. I would suggest we use the pharsing: "when the wasm instance entered an unrecoverable state and needs to terminate" or something along these lines.
  3. there is nothing said what are the semantics if called more than once. The last call wins?

UPD: I also see in the code that if this function was called at least once, then it will return an error, even if there were no traps within the call. That should be either documented as well.

Alternatively, we could just give trapping semantics to this call. I.e. when it's called it stashes the message and then traps.

UPD2: I see that wasmi doesn't have the same behavior. If panicked was called but no trap happened we do return with success.

@gnunicorn gnunicorn added A3-needsresolving A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. and removed A0-please_review Pull request needs code review. labels Mar 4, 2021
@gnunicorn
Copy link
Contributor

Anyone working on this?

@bkchr bkchr removed A3-needsresolving A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. labels Mar 4, 2021
@bkchr bkchr closed this Mar 20, 2021
@bkchr bkchr deleted the bkchr-runtime-panic branch March 20, 2021 23:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants