Repository navigation
Conversation
|
/azp-run runtime-interpreter |
|
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. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli |
|
/azp run runtime-interpreter |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run runtime-interpreter |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run runtime-interpreter |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
A managed calli can enter the prestub and fail during compilation. The C++ exception is converted to managed SEH, but this call path was missing the SEH wrapper needed to reach interpreter catches. Adding the wrapper exposed missing personality routines on the interpreter call stubs: native unwinding left stale entries in the runtime frame chain (on windows, frames are popped explicitly in the SEH unwind handler, rather than relying on a destructor). Register the existing frame-chain cleanup handler on the Windows x64 and ARM64 call stubs.
Avoid using personality routines, pop frame explicitly in the prestub exception scenario Fix bug where we were clobbering callee saved register RSI and RDI.
* PreStubWorker needs to pop all explicit frames upto and including the PrestubMethodFrame * When propagating unhandled exception to the host, prevent it being caught and processed in the interpreter code.
5c3ceca to
2c245e0
Compare
|
/azp run runtime-interpreter |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run runtime-interpreter |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run runtime-interpreter |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
| #if defined(FEATURE_INTERPRETER) && !defined(DACCESS_COMPILE) | ||
| ~PrestubMethodFrame() noexcept | ||
| { | ||
| PopIfChained(); |
There was a problem hiding this comment.
Would it be better to just enable ~Frame() noexcept { PopIfChained(); } for interpreter instead of enabling it on individual Frames?
If this is necessary on PrestubMethodFrame, I would expect it to be needed on number of other similar Frames - ExternalMethodFrame, etc.
There was a problem hiding this comment.
Enabling it for all frames would require a number of methods to be split because the destructor would now occur in code that has SEH handling. That's why I have opted for changing only the ones that require it. It is possible that the ExternalMethodFrame may need it too, but I think that would be it.
Essentially, these are places where managed exception (SEH) can flow into the interpreter code.
There was a problem hiding this comment.
There used to be a CallDescrWorker whose personality routine popped explicit frames. Now it is gone.
The path before Jeremy's change was:
19 0000003e`c3f7b6c0 00007ffa`3fa96e25 coreclr!PreStubWorker+0x650 [D:\git\runtime2\src\coreclr\vm\prestub.cpp @ 1982]
1a 0000003e`c3f7b950 00007ffa`3fa959b3 coreclr!ThePreStub+0x55 [D:\git\runtime2\src\coreclr\vm\amd64\ThePreStubAMD64.asm @ 20]
1b 0000003e`c3f7ba00 00007ffa`3f90fae2 coreclr!CallDescrWorkerInternal+0x83 [D:\git\runtime2\src\coreclr\vm\amd64\CallDescrWorkerAMD64.asm @ 74]
1c 0000003e`c3f7ba40 00007ffa`3fa95244 coreclr!RuntimeMethodHandle_InvokeMethod+0xe92 [D:\git\runtime2\src\coreclr\vm\reflectioninvocation.cpp @ 645]
1d 0000003e`c3f7beb0 00007ffa`3f8439e4 coreclr!CallJittedMethodRetVoid+0x14 [D:\git\runtime2\src\coreclr\vm\amd64\AsmHelpers.asm @ 1089]
1e 0000003e`c3f7bef0 00007ffa`3f84503d coreclr!InvokeManagedMethod+0x554 [D:\git\runtime2\src\coreclr\vm\interpexec.cpp @ 487]
1f 0000003e`c3f7c0a0 00007ffa`3f844836 coreclr!`InvokeUnmanagedMethodWithTransition'::`3'::__Body::Run+0xcd [D:\git\runtime2\src\coreclr\vm\interpexec.cpp @ 294]
20 0000003e`c3f7c1b0 00007ffa`3f83eaeb coreclr!InvokeUnmanagedMethodWithTransition+0xe6 [D:\git\runtime2\src\coreclr\vm\interpexec.cpp @ 296]
21 0000003e`c3f7c310 00007ffa`3f664672 coreclr!InterpExecMethod+0x3f1b [D:\git\runtime2\src\coreclr\vm\interpexec.cpp @ 3489]
Now it is
19 0000000a`a0d7b0f0 00007ffa`e6f748a5 coreclr!PreStubWorker+0x650 [D:\git\runtime2\src\coreclr\vm\prestub.cpp @ 1982]
1a 0000000a`a0d7b380 00007ffa`e6f72cc4 coreclr!ThePreStub+0x55 [D:\git\runtime2\src\coreclr\vm\amd64\ThePreStubAMD64.asm @ 20]
1b 0000000a`a0d7b430 00007ffa`e6d22ac9 coreclr!CallJittedMethodRetVoid+0x14 [D:\git\runtime2\src\coreclr\vm\amd64\AsmHelpers.asm @ 1089]
1c 0000000a`a0d7b460 00007ffa`e6d1ea08 coreclr!InvokeCalliStub+0x409 [D:\git\runtime2\src\coreclr\vm\interpexec.cpp @ 597]
1d 0000000a`a0d7b610 00007ffa`e6b44622 coreclr!InterpExecMethod+0x3e88 [D:\git\runtime2\src\coreclr\vm\interpexec.cpp @ 3454]
There was a problem hiding this comment.
Introduced or exposed?
If I am understanding this correctly, this bug was there since forever, but it was not causing any tests to fail.
There was a problem hiding this comment.
Yeah, I should have said exposed. I meant it started to happen after that PR.
There was a problem hiding this comment.
@jkotas, I don't think the code that uses ExternalMethodFrame is invoked directly from the interpreter like the prestub. it would be called by R2R compiled code only, wouldn't it?
There was a problem hiding this comment.
ExternalMethodFrame is not invoked directly, but I believe it can end up as the next direct frame in the presence of tailcalls:
- Interpreted managed
callican enter R2R method - R2R method calls unresolved import that ends up inside ExternalMethodFrame
- Resolution of the unresolved import throws an exception
The stack layout at the time of the exception is going to be exactly same as if the managed calli called the ExternalMethodFrame directly.
There was a problem hiding this comment.
You are right, copilot was able to construct a test that hit the same issue with ExternalMethodFrame using your comment.
There was a problem hiding this comment.
Added the same treatment and a test
This comment was marked as resolved.
This comment was marked as resolved.
| @@ -267,16 +267,8 @@ std::invoke_result_t<Function> CallWithSEHWrapper(Function function) | |||
|
|
|||
| // Use the NOINLINE to ensure that the InlinedCallFrame in this method is a lower stack address than any InterpMethodContextFrame values. | |||
There was a problem hiding this comment.
Move this comment and the NOINLINE annotation to InvokeUnmanagedMethodWithTransition?
I do not see a reason for marking this method with NOINLINE
There was a problem hiding this comment.
Why was it necessary to split the original method into two? If there is a reason, it can use a comment.
There was a problem hiding this comment.
Since the InlinedCallFrame now has a destructor, it cannot be in the same function where we do SEH handling.
There was a problem hiding this comment.
SEH handling
Should this change be Windows-only so that we are not regressing non-Windows platforms that we ship?
There was a problem hiding this comment.
The NOINLINE on the internal method was an accidental leftover of a copy and paste split of the original method. It should not be there. I've fixed it and added FORCEINLINE to ensure that on non-windows, the Inner method is inlined into the outer to preserve the previous state.
* Add similar treatment to ExternalMethodFrame and related test * Add missing skip of handling of propagation of unhandled exception to host / external caller
|
/azp run runtime-interpreter |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
| <CLRTestTargetUnsupported Condition="'$(EnableNativeSanitizers)' != ''">true</CLRTestTargetUnsupported> | ||
| <CLRTestTargetUnsupported Condition="'$(TargetArchitecture)' == 'wasm'">true</CLRTestTargetUnsupported> | ||
| <CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true' or '$(TargetsAndroid)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'">true</CLRTestTargetUnsupported> | ||
| <!-- Compile only the helper: the calli caller must remain JITted or interpreted. --> |
There was a problem hiding this comment.
We can achieve this by [BypassReadyToRun] and then enable the test for all CI configurations and just use the default tests harness.
| ExternalMethodFrame(TransitionBlock * pTransitionBlock); | ||
|
|
||
| #if defined(FEATURE_INTERPRETER) && !defined(DACCESS_COMPILE) | ||
| ~ExternalMethodFrame() noexcept |
There was a problem hiding this comment.
How about StubDispatchFrame - can it hit the same problem? (Tailcall of an interface method.)
There was a problem hiding this comment.
Yes, it seems that is another one.
|
/azp run runtime-interpreter |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run runtime-coreclr outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
stackoverflowtester is falling on interpreter |
There was a problem hiding this comment.
🟡 Changes recommended
The test project does not force ReadyToRun compilation, so the import scenario can pass without exercising the new ExternalMethodFrame cleanup.
1 open issue
What changed in this PR
This PR fixes Windows CoreCLR interpreter exception handling for managed calli calls that fail during compilation or native resolution, addressing the failures reported in #136993, #136908, and #137173.
Changes:
- Wraps interpreter
calliexecution in structured exception handling while allowing unhandled exceptions to propagate outward. - Adds explicit-frame cleanup during unwinding and fixes register usage in the Windows x64 stack helper.
- Adds subprocess regression tests for tail-call import and ambiguous interface-dispatch failures.
| File | Description |
|---|---|
src/tests/readytorun/TailCallImportException/TailCallImportException.csproj |
Configures the isolated regression executable and platform exclusions. |
src/tests/readytorun/TailCallImportException/TailCallImportException.cs |
Runs child scenarios and checks exception diagnostics and exit codes. |
src/tests/readytorun/TailCallImportException/TailCallHelper.ilproj |
Builds the IL helper assembly. |
src/tests/readytorun/TailCallImportException/TailCallHelper.il |
Defines failing tail-call import and interface-dispatch scenarios. |
src/coreclr/vm/threads.h |
Renames the unhandled-exception propagation flag. |
src/coreclr/vm/interpexec.cpp |
Adds the exception wrapper and updates filtering and transition handling. |
src/coreclr/vm/frames.h |
Adds destructors that remove chained explicit frames. |
src/coreclr/vm/frames.cpp |
Makes conditional frame cleanup available on Windows and in either GC mode. |
src/coreclr/vm/exceptionhandling.cpp |
Updates references to the renamed propagation flag. |
src/coreclr/vm/amd64/AsmHelpers.asm |
Avoids modifying nonvolatile registers in Load_Stack_Ref. |
Review effort: Balanced
| <RequiresProcessIsolation>true</RequiresProcessIsolation> | ||
| <ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator> | ||
| <CLRTestPriority>1</CLRTestPriority> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> |
This is not related to this PR, it shows on normal scheduled runs as well. Seems to have regressed after #135807 |
Could you please open a known issue for this failure then? |

A managed calli can enter the prestub and fail during compilation. The C++ exception is converted to managed SEH, but this call path was missing the SEH wrapper needed to reach interpreter catches.
Adding the wrapper exposed missing cleanup of explicit frames in this call path. Adding destructors for
InlinedCallFrame,InterpreterFrameandPrestubMethodFramethat pop the frames in case they are on the explicit frames list fixes the problem.Fixes #136993
Fixes #136908
Fixes #137173