Uh oh!
There was an error while loading. Please reload this page.
Wasm: stop R2R stack walk at reverse-pinvoke frames - #131668
Conversation
Fixes a failure seen in dotnet#131493 (enable SPC R2R). We were walking off the end of the managed part of the shadow stack at a reverse pinvoke boundary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 89caa9c8-5b0f-4fcc-a8c4-726ac8535110
AndyAyersMS
commented
Jul 31, 2026
@dotnet/wasm-contrib PTAL Not sure who best to tag as a reviewer given that David is away for a few days. @janvorli ? |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Updates the WASM RtlVirtualUnwind implementation to stop R2R shadow-stack-based unwinding when the current frame is a reverse-P/Invoke boundary (i.e., the managed frame’s caller is native), preventing the unwind from treating a native caller SP as a managed shadow frame.
Changes:
- Extends
WasmUnwindStackFrameCoreto optionally leave the caller IP unset when the caller is native. - Detects reverse-P/Invoke frames via GC info (
DECODE_REVERSE_PINVOKE_VAR) and uses that to terminate the R2R walk at the native boundary.
Uh oh!
There was an error while loading. Please reload this page.
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
lewing
commented
Aug 2, 2026
Holistic ReviewMotivation: Real and well-founded. Approach: Directionally right and consistent with the existing precedent in Summary: Detailed Findings
|
pavelsavara
commented
Aug 3, 2026
@janvorli is copilot right here ? |
janvorli
commented
Aug 4, 2026
Hmm, actually, I think copilot is right w.r.t. non-exceptionally called finallys inside [UnmanagedCallersOnly] marked method. This code would detect them as being called from native code. |
janvorli
commented
Aug 4, 2026
@AndyAyersMS I wonder how we can recognize this case (finally called non-exceptionally). |
AndyAyersMS
commented
Aug 4, 2026
We can tell if the virtual IP is in a funclet (we report all funclet IP ranges to the runtime in the unwind info), so we should be able to add this condition as a guard. Let me find the right logic. |
janvorli
commented
Aug 4, 2026
It is not just about whether it is in a funclet. For exceptionally called R2R funclet, the caller is native. For non-exceptionally called ones, it is R2R. |
AndyAyersMS
commented
Aug 4, 2026
Maybe I'm missing the point of what you say, but it seems like the suggested fix above is sufficient? R2R funclets are either called by the runtime (with a special frame marker setup) or by R2R managed code (with normal R2R frame setup), so it should be safe to assume that if we are in an R2R funclet the caller has made proper arrangements and we can probe the caller's frame value to see which is which. So it's only for non-funclet UCO cases where we can't make any assumptions about the caller and need to be careful. And |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 89caa9c8-5b0f-4fcc-a8c4-726ac8535110
janvorli
commented
Aug 4, 2026
I didn't know we call finally funclets in the exceptional case through a special helper written in WASM "asm" that takes care of this transition. |
Fixes a failure seen in #131493 (enable SPC R2R). We were walking off the end of the managed part of the shadow stack at a reverse pinvoke boundary.