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

Update how exits are modeled in the C API #5215

Merged

Conversation

alexcrichton
Copy link
Member

Previously extracting an exit code was only possibly on a wasm_trap_t which will never successfully have an exit code on it, so the exit code extractor is moved over to wasmtime_error_t. Additionally extracting a wasm trace from a wasmtime_error_t is added since traces happen on both traps and errors now.

Previously extracting an exit code was only possibly on a `wasm_trap_t`
which will never successfully have an exit code on it, so the exit code
extractor is moved over to `wasmtime_error_t`. Additionally extracting a
wasm trace from a `wasmtime_error_t` is added since traces happen on
both traps and errors now.
@alexcrichton
Copy link
Member Author

As a note to myself, I want to test this against our C-API-based bindings and then if this is sufficient this'll need a backport to the 3.0.0 branch before release.

@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Nov 7, 2022
@github-actions
Copy link

github-actions bot commented Nov 7, 2022

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "wasmtime:c-api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:c-api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@alexcrichton alexcrichton merged commit b07b067 into bytecodealliance:main Nov 7, 2022
@alexcrichton alexcrichton deleted the update-c-api-traps branch November 7, 2022 17:35
kpreisser added a commit to kpreisser/wasmtime-dotnet that referenced this pull request Nov 7, 2022
This moves the ExitStatus from TrapException/TrapAccessor to WasmtimeException.
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Nov 8, 2022
Previously extracting an exit code was only possibly on a `wasm_trap_t`
which will never successfully have an exit code on it, so the exit code
extractor is moved over to `wasmtime_error_t`. Additionally extracting a
wasm trace from a `wasmtime_error_t` is added since traces happen on
both traps and errors now.
alexcrichton added a commit that referenced this pull request Nov 8, 2022
* c-api: Avoid losing error context with instance traps

This commit was a mistake from #5149

* Update how exits are modeled in the C API (#5215)

Previously extracting an exit code was only possibly on a `wasm_trap_t`
which will never successfully have an exit code on it, so the exit code
extractor is moved over to `wasmtime_error_t`. Additionally extracting a
wasm trace from a `wasmtime_error_t` is added since traces happen on
both traps and errors now.
peterhuene added a commit to bytecodealliance/wasmtime-dotnet that referenced this pull request Nov 10, 2022
* Update some tests for the new trap behavior.

See #173

Currently, tests that are still failing are the following:
- ExitTrapTests: It is not clear how to get the WASI exit code from a `wasmtime_error_t*` instead of an `wasmtime_trap_t*` via the C API.
- FuelConsumptionTests: `wasmtime_trap_code` unexpectedly fails (SEHException) even though a trap was returned.
- TrapTests: The tests introduced with #172 fail as the inner exception would need to be set on the WasmtimeException instead of TrapException. Need to check how to solve this.

* Update for the changes in bytecodealliance/wasmtime#5215.

This moves the ExitStatus from TrapException/TrapAccessor to WasmtimeException.

* Follow-Up: Add a Frames property to WasmtimeException which allows to retrieve the frames for a wasmtime_error_t* using the new wasmtime_error_wasm_trace function.

TODO: Add tests.

* Use nuint instead of UIntPtr for sizes (size_t) as they don't actually represent a pointer, but a platform-sized integer.

Note that nint/nuint in C# will behave like regular numeric types like int/uint, so e.g. the checked/unchecked context is respected, which is not the case with IntPtr/UIntPtr until .NET 7.

* Move the functionality of passing the original .NET exception as InnerException from the TrapException to the WasmtimeException, since host-created traps (with wasm_trap_new) are now returned as error (wasmtime_error_t*).

While theoretically it could happen that the returned wasmtime_error_t* has actually another cause than the error returned at the host-to-wasm transition, I assume this is not the case, similar as to a .NET exception that would just bubble up the stack once thrown.

* Fix the definition of wasmtime_trap_code to match the signature from trap.h header file.

See GHSA-h84q-m8rr-3v9q

Previously, we were passing a pointer to an Int32 (4-byte buffer), so the definition actually matched the Rust code, and therefore prior versions of wasmtime-dotnet are not impacted by that issue.

* Add TrapCode.OutOfFuel.

See bytecodealliance/wasmtime#5230

* Follow-Up: Update for the changed exception message.

* Update the consume-fuel example.

This commit updates the consume-fuel example to catch `WasmtimeException`
instead of `TrapException`.

The change is due to the `ConsumeFuel` call returning an error when it
fails to consume the given amount of fuel and that propagates properly now.

Co-authored-by: Peter Huene <phuene@fastly.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:c-api Issues pertaining to the C API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants