From 75f52d0cff026fc4ec4ed2ade4f93d37faa160e9 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 11 Jan 2024 10:51:30 +0100 Subject: [PATCH 1/2] Add support for `ext_panic_handler_abort_on_panic_version_1` --- lib/src/executor/host.rs | 29 ++++++++++++++++++++++++++++- lib/src/executor/host/functions.rs | 4 ++++ wasm-node/CHANGELOG.md | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/src/executor/host.rs b/lib/src/executor/host.rs index 5fdca98779..f1fe25afa6 100644 --- a/lib/src/executor/host.rs +++ b/lib/src/executor/host.rs @@ -2142,7 +2142,7 @@ impl ReadyToRun { return HostVm::Error { error: Error::Utf8Error { function: host_fn.name(), - param_num: 2, + param_num: 1, error, }, prototype: self.inner.into_prototype(), @@ -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(), + }, + } + } } } } @@ -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 { diff --git a/lib/src/executor/host/functions.rs b/lib/src/executor/host/functions.rs index f70399cdf6..0a41952651 100644 --- a/lib/src/executor/host/functions.rs +++ b/lib/src/executor/host/functions.rs @@ -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 { @@ -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) => ()) + } } } } diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index e590c6b436..dd6c31a542 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -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. ### Fixed From 59caebe74b449a8aae498d64870421f10a4d68f6 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 11 Jan 2024 10:52:23 +0100 Subject: [PATCH 2/2] PR link --- wasm-node/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index dd6c31a542..84a6ba647f 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -5,7 +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. +- Added support for the `ext_panic_handler_abort_on_panic_version_1` host function. ([#1573](https://github.com/smol-dot/smoldot/pull/1573)) ### Fixed