Skip to content

Enhance wiggle to permit WebAssembly runtimes to customize their response to fatal errors in hostcall implementations. #2418

@fst-crenshaw

Description

@fst-crenshaw

Feature

The wasmtime and lucet runtimes take different approaches when a hostcall reaches a fatal error. Wasmtime expects a Err(wasmtime::Trap::new()) from the hostcall indicating that an instance ought to be terminated. The lucet runtime uses a panic!() to indicate a fatal error. To allow for an agnostic support of these two different approaches, wiggle requires an enhancement that allows each of these runtimes to customize their reaction to a fatal error.

Implementation

Currently, the wiggle procedural macro generates a UserErrorConversion trait that, when implemented, specifies how to transform a hostcall error into an abi error, or i32. For wasmtime, that trait is generated by wiggle like so:

pub trait UserErrorConversion {
    fn errno_from_error(&self, e: Error) -> Errno;
} 

One approach to enhance wiggle so that runtimes to react to fatal errors in a custom way follows:

  1. Wiggle generates its UserErrorConversion trait to return a Result instead of an i32. The FatalError portion of the result must contain info describing the nature of the fatal error.
pub trait UserErrorConversion {
    		fn errno_from_error(&self, e: Error) -> Result<Errno, FatalError>;
} 
  1. Wasmtime alters its wiggle integration to handle a Result instead of an i32. When a FatalError is received, it must Trap(“info”).

Benefit

Enhancing the UserErrorConversion trait to return a Result means that runtimes may customize their reaction to a fatal error inside of a hostcall.

Metadata

Metadata

Assignees

Labels

enhancementwiggleIssues relating to the wiggle code generator.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions