Skip to content

Skip unwinding interpreter frames from FaultingExceptionFrame - #137928

Merged
BrzVlad merged 4 commits into
dotnet:mainfrom
BrzVlad:fix-clrinterp-stackoverflow
Nov 25, 2026
Merged

BrzVlad merged 4 commits into
dotnet:mainfrom
BrzVlad:fix-clrinterp-stackoverflow

Conversation

@BrzVlad

@BrzVlad BrzVlad commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Interpreter throws StackOverflow via explicit checks, when the interpreter stack overflows (this is a different path from the overflow of the native stack pointer). When doing this, we were creating a context to be passed further to HandleFatalStackOverflow, which would end up creating a FaultingExceptionFrame. The problem was that we were initializing this context with SetContextToInterpMethodContextFrame which makes the unwinder iterate over all interpreter frames when handling this explicit frame. After we process all these frames, we find the next explicit frame, the InterpreterFrame which links to all these frames again. Due to some recent condition enforcement (done in e8b295c1ba0), this resulted in an assert while unwinding.

The fix follows the InlinedCallFrame approach of skipping iteration from these interpreter frames, when the FaultingExceptionFrame points inside the interpreter.

Should fix stackoverflowtester runtime test, which was failing with assertion due to incorrect ordering of stack pointers:

BEGIN EXECUTION
/datadisks/disk1/work/AEF6091D/p/corerun -p System.Reflection.Metadata.MetadataUpdater.IsSupported=false -p System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=true stackoverflowtester.dll ''
Running stackoverflow test(smallframe main)
"Stack overflow."
"ASSERT FAILED"
"	Expression: (m_crawl.pFrame == FRAME_TOP) || (dac_cast<TADDR>(m_crawl.pFrame) >= (TADDR)GetRegdisplaySP(m_crawl.pRD)) || (m_crawl.pFrame->GetFrameIdentifier() == FrameIdentifier::FaultingExceptionFrame)"
"	Location:   /__w/1/s/src/coreclr/vm/stackwalk.cpp:2248"
"	Function:   NextRaw"
"	Process:    8150"
System.Exception: Missing "Main" method frame at the last line
   at TestStackOverflow.Program.TestStackOverflowSmallFrameMainThread()
   at __GeneratedMainWrapper.Main()
Expected: 100
Actual: 101
END EXECUTION - FAILED

Interpreter throws StackOverflow via explicit checks, when the interpreter stack overflows (this is a different path from the overflow of the native stack pointer). When doing this, we were creating a context to be passed further to HandleFatalStackOverflow, which would end up creating a FaultingExceptionFrame. The problem was that we were initializing this context with `SetContextToInterpMethodContextFrame` which makes the unwinder iterate over all interpreter frames when handling this explicit frame. After we process all these frames, we find the next explicit frame, the `InterpreterFrame` which links to all these frames again. Due to some recent condition enforcement (done in dotnet@e8b295c1ba0), this resulted in an assert while unwinding.

The fix stops creating this context altogether. When `HandleFatalStackOverflow` begins processing the overflow, it sees that we have no context, in which case it no longer pushes the `FaultingExceptionFrame`. This frame was not needed, the unwinder can reach all frames from the already pushed `InterpreterFrame`, the faulting frame's IP is already stored in the top `InterpMethodContextFrame`'s ip.

Should fix stackoverflowtester runtime test.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli
See info in area-owners.md if you want to be subscribed.

@BrzVlad

BrzVlad commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

/azp run runtime-interpreter

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@janvorli janvorli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@BrzVlad

BrzVlad commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

/azp run runtime-interpreter

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

This was done from hardware stack overflows.
Comment thread src/coreclr/vm/eepolicy.cpp Resolved
@BrzVlad
BrzVlad requested a review from janvorli November 20, 2026 16:25
@BrzVlad

BrzVlad commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

/azp run runtime-interpreter

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@BrzVlad BrzVlad changed the title Don't push a FaultingExceptionFrame for interpreter stack overflow Skip unwinding interpreter frames from FaultingExceptionFrame Nov 23, 2026

@janvorli janvorli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@BrzVlad

BrzVlad commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

/ba-g failures unrelated

@BrzVlad
BrzVlad merged commit 14d4cb6 into dotnet:main Nov 25, 2026
101 of 103 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants