Skip to content

Conversation

janvorli
Copy link
Member

The exception handling stack frame iterator adjusts IP it returns for all cases when the IP represents a return address. This is to make sure that if the last instruction in a try regios is a call, it is still covered by the try region (the return address would be right after it). For jit/aoted code, throwing a software exceptions results in a call. Only hardware exceptions like division by zero etc report the address of the failing instruction.
In the interpreter, when an exception is thrown, the IP address is always the address of the instruction that has triggered the exception. So we should not adjust the IP.
This change fixes that by marking exception throwing frame as "faulting", which ensures the adjustment doesn't occur. That information is recorded in the InterpreterFrame when an exception is thrown by the interpreter code and cleared when the execution resumes after catch.

The exception handling stack frame iterator adjusts IP it returns for
all cases when the IP represents a return address. This is to make sure
that if the last instruction in a try regios is a call, it is still covered
by the try region (the return address would be right after it).
For jit/aoted code, throwing a software exceptions results in a call.
Only hardware exceptions like division by zero etc report the address of
the failing instruction.
In the interpreter, when an exception is thrown, the IP address is
always the address of the instruction that has triggered the exception.
So we should not adjust the IP.
This change fixes that by marking exception throwing frame as
"faulting", which ensures the adjustment doesn't occur.
That information is recorded in the InterpreterFrame when an
exception is thrown by the interpreter code and cleared when the
execution resumes after catch.
@janvorli janvorli added this to the 10.0.0 milestone Jun 26, 2025
@janvorli janvorli self-assigned this Jun 26, 2025
@Copilot Copilot AI review requested due to automatic review settings June 26, 2025 15:06
@janvorli janvorli requested a review from BrzVlad as a code owner June 26, 2025 15:06
@janvorli janvorli requested a review from kg as a code owner June 26, 2025 15:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the IP adjustment for interpreter exception handling by marking interpreter frames as faulting when an exception is thrown, ensuring the IP remains unadjusted during interpreter exceptions. Key changes include:

  • Setting faulting flags in stackwalk.cpp when an exception context is detected.
  • Updating interpexec.cpp to mark interpreter frames as faulting during exception throw and rethrow.
  • Introducing a new faulting flag and related setter in InterpreterFrame (frames.h and frames.cpp) and applying it in excep.cpp.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/coreclr/vm/stackwalk.cpp Added faulting flag logic to set exception active context status.
src/coreclr/vm/interpexec.cpp Marked interpreter frames as faulting for throw and rethrow paths.
src/coreclr/vm/frames.h Added the m_isFaulting field and SetIsFaulting method to InterpreterFrame.
src/coreclr/vm/frames.cpp Updated context setting to reflect the faulting status.
src/coreclr/vm/excep.cpp Ensured interpreter frames are marked as faulting during unwind.
Comments suppressed due to low confidence (1)

src/coreclr/vm/stackwalk.cpp:2863

  • Consider adding a brief comment explaining why checking for CONTEXT_EXCEPTION_ACTIVE here leads to setting isInterrupted and hasFaulted. This will help maintainability by clarifying the relationship between the context flag and the interpreter frame state.
                    if (pRD->pCurrentContext->ContextFlags & CONTEXT_EXCEPTION_ACTIVE)

Copy link
Contributor

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

@janvorli janvorli merged commit 7b3c9ab into dotnet:main Jul 7, 2025
96 of 100 checks passed
@janvorli janvorli deleted the fix-interpreter-exception-offset-compensation branch July 7, 2025 14:05
@github-actions github-actions bot locked and limited conversation to collaborators Aug 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants