From fe001d5742c1c9368ccc32ef4960af2e09d27f20 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Tue, 3 Nov 2026 14:01:54 -0800 Subject: [PATCH] Use the interpreter GC decoder when inspecting interpreted frames (#136553) ## Summary Use `InterpreterGcInfoDecoder` rather than the target-native `GcInfoDecoder` when inspecting an interpreted frame in: - `SfiNextWorker`, for reverse-P/Invoke detection during exception propagation. - `SafeToReportGenericParamContext`, for the generic-context prolog length. - `FindFirstInterruptiblePoint`, for the GC-reporting location when unwinding between funclets. Interpreter GC metadata has different encoding parameters and normalization from native metadata. Select the decoder using the frame's code manager, guarded by `FEATURE_INTERPRETER`, and preserve the existing decoder for native frames. Found while investigating dotnet/runtime#135821. This PR is independently based on `main` and contains no Wasm metadata-format or code-generation changes. The decoder mismatch predates that work; an observable release-mode iOS failure has not been demonstrated. ## Validation - `./build.sh clr.runtime -rc Checked` on this standalone branch: passed, zero warnings and errors. - Session-local caught-exception, generic-GC, and uncaught reverse-P/Invoke probes on this standalone branch: passed with normal execution and with `DOTNET_Interpreter='*' DOTNET_ReadyToRun=0`. The uncaught probe terminated as expected and retained `MessageFromMyException`. - On the Wasm metadata branch, the reverse-P/Invoke probe reproduced the missing-message/assertion failure before this fix and preserved the exception message afterward; the checked browser runtime build also passed. This is supplementary evidence, not a standalone-branch browser test. - `git diff upstream/main...HEAD --check`: passed. - No new checked-in regression test; existing `WasmBuildAppTest.ExceptionFromMain` caught the EH regression. - iOS execution and the full test suites were not run. > [!NOTE] > This pull request description and code changes were generated with GitHub Copilot. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 798665fd-8e9d-46c8-b56c-843764cdb3d1 --- src/coreclr/vm/exceptionhandling.cpp | 14 +++++++++++-- src/coreclr/vm/gcenv.ee.common.cpp | 30 +++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index aedbadd131e999..99f5efa93c0b27 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -4155,8 +4155,18 @@ CLR_BOOL SfiNextWorker(StackFrameIterator* pThis, uint* uExCollideClauseIdx, CLR if (!doingFuncletUnwind) { #ifdef USE_GC_INFO_DECODER - GcInfoDecoder gcInfoDecoder(codeInfo.GetGCInfoToken(), DECODE_REVERSE_PINVOKE_VAR); - isPropagatingToNativeCode = gcInfoDecoder.GetReversePInvokeFrameStackSlot() != NO_REVERSE_PINVOKE_FRAME; +#ifdef FEATURE_INTERPRETER + if (codeInfo.GetCodeManager() == ExecutionManager::GetInterpreterCodeManager()) + { + InterpreterGcInfoDecoder gcInfoDecoder(codeInfo.GetGCInfoToken(), DECODE_REVERSE_PINVOKE_VAR); + isPropagatingToNativeCode = gcInfoDecoder.GetReversePInvokeFrameStackSlot() != NO_REVERSE_PINVOKE_FRAME; + } + else +#endif // FEATURE_INTERPRETER + { + GcInfoDecoder gcInfoDecoder(codeInfo.GetGCInfoToken(), DECODE_REVERSE_PINVOKE_VAR); + isPropagatingToNativeCode = gcInfoDecoder.GetReversePInvokeFrameStackSlot() != NO_REVERSE_PINVOKE_FRAME; + } #else // USE_GC_INFO_DECODER hdrInfo *hdrInfoBody; codeInfo.DecodeGCHdrInfo(&hdrInfoBody); diff --git a/src/coreclr/vm/gcenv.ee.common.cpp b/src/coreclr/vm/gcenv.ee.common.cpp index fb2e6b52f493fa..57510abdd1ddec 100644 --- a/src/coreclr/vm/gcenv.ee.common.cpp +++ b/src/coreclr/vm/gcenv.ee.common.cpp @@ -59,14 +59,24 @@ bool FindFirstInterruptiblePointStateCB( unsigned FindFirstInterruptiblePoint(CrawlFrame* pCF, unsigned offs, unsigned endOffs) { GCInfoToken gcInfoToken = pCF->GetGCInfoToken(); - GcInfoDecoder gcInfoDecoder(gcInfoToken, DECODE_FOR_RANGES_CALLBACK); FindFirstInterruptiblePointState state; state.offs = offs; state.endOffs = endOffs; state.returnOffs = -1; - gcInfoDecoder.EnumerateInterruptibleRanges(&FindFirstInterruptiblePointStateCB, &state); +#ifdef FEATURE_INTERPRETER + if (pCF->GetCodeManager() == ExecutionManager::GetInterpreterCodeManager()) + { + InterpreterGcInfoDecoder gcInfoDecoder(gcInfoToken, DECODE_FOR_RANGES_CALLBACK); + gcInfoDecoder.EnumerateInterruptibleRanges(&FindFirstInterruptiblePointStateCB, &state); + } + else +#endif // FEATURE_INTERPRETER + { + GcInfoDecoder gcInfoDecoder(gcInfoToken, DECODE_FOR_RANGES_CALLBACK); + gcInfoDecoder.EnumerateInterruptibleRanges(&FindFirstInterruptiblePointStateCB, &state); + } return state.returnOffs; } @@ -132,9 +142,19 @@ bool SafeToReportGenericParamContext(CrawlFrame* pCF) #else // USE_GC_INFO_DECODER - GcInfoDecoder gcInfoDecoder(pCF->GetGCInfoToken(), - DECODE_PROLOG_LENGTH); - UINT32 prologLength = gcInfoDecoder.GetPrologSize(); + UINT32 prologLength; +#ifdef FEATURE_INTERPRETER + if (pCF->GetCodeManager() == ExecutionManager::GetInterpreterCodeManager()) + { + InterpreterGcInfoDecoder gcInfoDecoder(pCF->GetGCInfoToken(), DECODE_PROLOG_LENGTH); + prologLength = gcInfoDecoder.GetPrologSize(); + } + else +#endif // FEATURE_INTERPRETER + { + GcInfoDecoder gcInfoDecoder(pCF->GetGCInfoToken(), DECODE_PROLOG_LENGTH); + prologLength = gcInfoDecoder.GetPrologSize(); + } if (pCF->GetRelOffset() < prologLength) { return false;