Expand description
Implementation of personality function and unwinding support for Wasmer.
On a native platform, when an exception is thrown, the type info of the exception is known, and can be matched against the LSDA table within the personality function (e.g. __gxx_personality_v0 for Itanium ABI).
However, in WASM, the exception “type” can change between compilation and instantiation because tags can be imported from other modules. Also, a single module can be instantiated many times, but all instances share the same code, differing only in their VMContext data. This means that, to be able to match the thrown exception against the expected tag in catch clauses, we need to go through the VMContext of the specific instance to which the stack frame belongs; nothing else can tell us exactly which instance we’re currently looking at, including the IP which will be the same for all instances of the same module.
To achieve this, we use a two-stage personality function. The first stage is the normal personality function which is called by libunwind; this function always catches the exception as long as it’s a Wasmer exception, without looking at the specific tags. Afterwards, control is transferred to the module’s landing pad, which can load its VMContext and pass it to the second stage of the personality function. Afterwards, the second stage can take the “local tag number” (the tag index as seen from the WASM module’s point of view) from the LSDA and translate it to the unique tag within the Store, and match that against the thrown exception’s tag.
The throw function also uses the VMContext of its own instance to get the unique tag from the Store, and uses that as the final exception tag.
It’s important to note that we can’t count on libunwind behaving properly if we make calls from the second stage of the personality function; this is why the first stage has to extract all the data necessary for the second stage and place it in the exception object. The second stage will clear out the data before returning, so further stack frames will not get stale data by mistake.
Structs§
Constants§
Statics§
- CANARY 🔒
Functions§
- find_
eh_ 🔒 ⚠action - The implementation of Wasmer’s personality function.
- The second stage of the personality function. See module level documentation for an explanation of the exact procedure used during unwinding.