Add Wasm EH R2R infrastructure#129197
Open
davidwrighton wants to merge 4 commits into
Open
Conversation
- Make STACKWALK_CONTROLPC_ADJUST_OFFSET 2 so that it doesn't break the IsVirtualIP check - Avoid using STACKWALK_CONTROLPC_ADJUST_OFFSET in most cases with virtual ips - Implement EECodeManager::CallFunclet for WASM - Add GetWasmFunctionTableIndexFromVirtualIP for use by CallFunclet - Add exception tag type for RtlRestoreContext to be used during EH flow
…reContextTag into modules
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds WebAssembly ReadyToRun (R2R) exception-handling plumbing across the runtime, toolchain, and hosts by introducing a CoreCLR-specific Wasm exception tag for RtlRestoreContext, wiring it through Webcil import/export, and extending relocation/JIT-interface support so R2R code can reference that tag.
Changes:
- Export/import a new Wasm exception tag (
__coreclr_wasm_rtlrestorecontext_tag) and plumb it through the JS hosts and build/link flags. - Implement Wasm
RtlRestoreContextusing a tagthrowwith (ip, sp) payload, and add Wasm-specific funclet invocation helpers + stackwalk adjustments for virtual IPs. - Add a new Wasm relocation kind to reference the restore-context exception tag in object writing / relocation resolution, and update the JIT-EE interface version.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/native/corehost/browserhost/CMakeLists.txt | Exports the restore-context tag from the CoreCLR browserhost Wasm module. |
| src/mono/browser/build/BrowserWasmApp.CoreCLR.targets | Ensures the restore-context tag is exported during app relink. |
| src/coreclr/vm/wasm/helpers.cpp | Defines/throws the new tag for RtlRestoreContext; adds Wasm funclet call helpers via call_indirect. |
| src/coreclr/vm/wasm/cgencpu.h | Adjusts Wasm stackwalk ControlPC adjust offset. |
| src/coreclr/vm/exceptionhandling.cpp | Skips ControlPC adjustment for Wasm virtual IP frames during EH stack walks. |
| src/coreclr/vm/eetwain.cpp | Enables invoking Wasm EH funclets via function table indices and Wasm frame pointer recovery. |
| src/coreclr/vm/codeman.h | Declares a new ExecutionManager mapping from virtual IP to function table index. |
| src/coreclr/vm/codeman.cpp | Implements virtualIP→functionIndex mapping; decodes Wasm virtual IP encoding for EH clauses. |
| src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs | Adds a new CorInfoReloc value for the Wasm restore-context exception tag. |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Maps the new CorInfoReloc to the internal RelocType. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs | Imports the restore-context tag into Webcil modules; resolves the new relocation kind. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmNative.cs | Adds tag-import encoding support (WasmTagImportType). |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs | Allows emitting placeholder bytes for the new relocation kind. |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs | Defines/handles the new relocation type for padded ULEB32 write/read/size. |
| src/coreclr/inc/jiteeversionguid.h | Updates JIT-EE interface version GUID due to interface surface changes. |
| src/coreclr/inc/corinfo.h | Adds the new relocation kind to the native JIT-EE contract. |
| src/coreclr/hosts/corerun/wasm/libCorerun.js | Passes the exported tag as a Webcil import; validates it exists post-link. |
| src/coreclr/hosts/corerun/CMakeLists.txt | Exports the restore-context tag from the corerun Wasm build. |
| eng/native.wasm.targets | Adds the tag to the exported-symbol preservation list for Wasm builds. |
Use the Wasm R2R stack-walk terminator in funclet helpers, clarify the virtual IP parameter name, and skip stack-trace IP adjustment for Wasm virtual IPs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR description was generated by GitHub Copilot.
Summary
RtlRestoreContextexception tag for Wasm modulesRtlRestoreContexttagTesting
Notes:
The exception thrown for catch downstream carries with it the "IP" and SP of the context we want to resume to. The JIT team can decide if this is actually useful. Be aware that the "IP" in this case is simply the return value from the catch clause.