Repository navigation
Commit 6593571
authored
[wasm] Publish __stack_pointer before SuppressGCTransition native calls (#130924)
## Summary
On `FEATURE_PORTABLE_ENTRYPOINTS` (wasm) R2R, generated code keeps its
shadow stack pointer in a local and leaves the `__stack_pointer` global
stale. The P/Invoke prolog (`JIT_PInvokeBegin`) normally publishes it
before native code runs, but that prolog is **skipped for
`SuppressGCTransition` calls**. A native `SuppressGCTransition` callee
(emscripten, which uses `__stack_pointer`) then allocates its shadow
frame from the stale global — the caller's SP, *above* the R2R frame —
and clobbers the caller's address-taken locals.
This manifests in R2R exception handling: `FindFirstPassHandler` spills
its by-ref `StackFrameIterator`, calls the `SuppressGCTransition` QCall
`RhpEHEnumInitFromStackFrameIterator`, the callee clobbers the spilled
pointer, and the next `frameIter.ControlPC` read faults with a spurious
`NullReferenceException`. EH dispatch can't GC-transition mid-unwind,
which is why its QCalls are `SuppressGCTransition` and hit this path.
Fixes #130923.
## Fix
Publish the shadow SP to the `__stack_pointer` global just before the
call, so the callee allocates its shadow frame below the current frame.
The publish is net-zero on the wasm operand stack, so it is safe to emit
after the call arguments are pushed. The `stackPointer` global handle
comes from the `getWasmWellKnownGlobals` JIT-EE API (added in #129717)
and is referenced via a `WASM_GLOBAL_INDEX_LEB` relocation, matching the
existing `global.get` uses in wasm codegen.
## Validation
The bug only *reproduces* with the (not-yet-merged) R2R-on-wasm bring-up
stack, so there is no wasm-R2R CI leg on `main` yet. Verified
`codegenwasm.cpp` compiles clean in the wasm JIT (`clr.jit`, 0 errors).
Behaviorally validated on the R2R-on-wasm prototype: unfixed crashes,
fixed passes, plus a byte-identical R2R↔interpreter battery.
## Notes for reviewers
- Draft because it cannot be CI-validated on `main` until the
R2R-on-wasm consumption path lands.
- Depends on the `getWasmWellKnownGlobals` API from #129717 (fixes
#129712), now on `main`.
- Related bring-up family: #130634.
> [!NOTE]
> This pull request was authored with the assistance of GitHub Copilot.1 parent 189c884 commit 6593571
1 file changed
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2914 | 2914 | | |
2915 | 2915 | | |
2916 | 2916 | | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
| 2921 | + | |
| 2922 | + | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
2917 | 2931 | | |
2918 | 2932 | | |
2919 | 2933 | | |
| |||
0 commit comments