-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Adds host function for handle panicking #7954
Conversation
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.
@@ -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>, |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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:
- 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.
- 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.
- 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.
Anyone working on this? |
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.