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

Add support for ext_panic_handler_abort_on_panic_version_1 #1573

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lib/src/executor/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,7 @@ impl ReadyToRun {
return HostVm::Error {
error: Error::Utf8Error {
function: host_fn.name(),
param_num: 2,
param_num: 1,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very small side fix. Usually I like to open separate PRs, but this is not worth it.

error,
},
prototype: self.inner.into_prototype(),
Expand Down Expand Up @@ -2183,6 +2183,27 @@ impl ReadyToRun {
HostFunction::ext_logging_max_level_version_1 => {
HostVm::GetMaxLogLevel(GetMaxLogLevel { inner: self.inner })
}
HostFunction::ext_panic_handler_abort_on_panic_version_1 => {
let message = {
let message_bytes = expect_pointer_size!(0);
str::from_utf8(message_bytes.as_ref()).map(|msg| msg.to_owned())
};

match message {
Ok(message) => HostVm::Error {
error: Error::AbortOnPanic { message },
prototype: self.inner.into_prototype(),
},
Err(error) => HostVm::Error {
error: Error::Utf8Error {
function: host_fn.name(),
param_num: 0,
error,
},
prototype: self.inner.into_prototype(),
},
}
}
}
}
}
Expand Down Expand Up @@ -3901,6 +3922,12 @@ pub enum Error {
/// Error in the Wasm code execution.
#[display(fmt = "{_0}")]
Trap(vm::Trap),
/// Runtime has called the `ext_panic_handler_abort_on_panic_version_1` host function.
#[display(fmt = "Runtime has aborted: {message:?}")]
AbortOnPanic {
/// Message generated by the runtime.
message: String,
},
/// A non-`i64` value has been returned by the Wasm entry point.
#[display(fmt = "A non-I64 value has been returned: {actual:?}")]
BadReturnValue {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/executor/host/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ host_functions! {
ext_allocator_free_version_1,
ext_logging_log_version_1,
ext_logging_max_level_version_1,
ext_panic_handler_abort_on_panic_version_1,
}

impl HostFunction {
Expand Down Expand Up @@ -448,6 +449,9 @@ impl HostFunction {
HostFunction::ext_logging_max_level_version_1 => {
crate::signature!(() => vm::ValueType::I32)
}
HostFunction::ext_panic_handler_abort_on_panic_version_1 => {
crate::signature!((vm::ValueType::I64) => ())
}
}
}
}
1 change: 1 addition & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed

- Most of the log messages emitted by smoldot have been modified in order to unify their syntax and be easier to parse programatically. ([#1560](https://github.com/smol-dot/smoldot/pull/1560))
- Added support for the `ext_panic_handler_abort_on_panic_version_1` host function. ([#1573](https://github.com/smol-dot/smoldot/pull/1573))

### Fixed

Expand Down
Loading