You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a problem with RtlRestoreContext not restoring context during thread abort if that abort comes from injected APC callback on ARM64 and the processor supports SVE. In that case, the context provided by the APC callback can contain XSTATE and when we start walking stack from that context, we copy that context into the REGDISPLAY. The problem is that we copy the ContextFlags without changes, so if they contained CONTEXT_XSTATE flag, it is kept set even though the REGDISPLAY has only plain old CONTEXT without any XSTATE.
When we call RtlRestoreContext in the ResumeAfterCatch, it fails because the XSTATE is not valid and so it returns. That's unexpected and we end up crashing with an assert.
The fix clears the CONTEXT_XSTATE in ResumableFrame::UpdateRegDisplay so that the REGDISPLAY's contexts ContextFlags are validly representing the context stored in the REGDISPLAY.
There is a problem with RtlRestoreContext not restoring context during
ThreadAbort if that abort comes from injected APC callback on ARM64 and
the processor supports SVE. In that case, the context provided by the
APC callback can contain XSTATE and when we start walking stack from
that context, we copy that context into the REGDISPLAY. The problem is
that we copy the ContextFlags without changes, so if they contained
CONTEXT_XSTATE flag, it is kept set even though the REGDISPLAY has only
plain old CONTEXT without any xstate.
When we call RtlRestoreContext in the ResumeAfterCatch, it fails because
the XSTATE is not valid and so it returns. That's unexpected and we end
up crashing with an assert.
The fix clears the CONTEXT_XSTATE in ResumableFrame::UpdateRegDisplay so
that the REGDISPLAY ContextFlags are validly representing the context.
Closedotnet#120437
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a ThreadAbort issue on ARM64 processors with SVE support where RtlRestoreContext fails during thread abort recovery. The issue occurs when an APC callback provides a context with XSTATE flags that are copied to a REGDISPLAY without the corresponding XSTATE data, causing RtlRestoreContext to fail.
Clears invalid CONTEXT_XSTATE flags in ResumableFrame::UpdateRegDisplay_Impl for both ARM64 and AMD64
Adds UNREACHABLE() marker after RtlRestoreContext call to indicate expected control flow
Ensures ContextFlags accurately represent the actual context data stored in REGDISPLAY
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File
Description
src/coreclr/vm/threads.cpp
Adds UNREACHABLE() after RtlRestoreContext call
src/coreclr/vm/arm64/stubs.cpp
Clears CONTEXT_XSTATE flags in ARM64 ResumableFrame implementation
src/coreclr/vm/amd64/cgenamd64.cpp
Clears CONTEXT_XSTATE flags in AMD64 ResumableFrame implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is a problem with
RtlRestoreContextnot restoring context during thread abort if that abort comes from injected APC callback on ARM64 and the processor supports SVE. In that case, the context provided by the APC callback can contain XSTATE and when we start walking stack from that context, we copy that context into theREGDISPLAY. The problem is that we copy theContextFlagswithout changes, so if they containedCONTEXT_XSTATEflag, it is kept set even though theREGDISPLAYhas only plain oldCONTEXTwithout any XSTATE.When we call
RtlRestoreContextin theResumeAfterCatch, it fails because the XSTATE is not valid and so it returns. That's unexpected and we end up crashing with an assert.The fix clears the
CONTEXT_XSTATEinResumableFrame::UpdateRegDisplayso that theREGDISPLAY's contextsContextFlagsare validly representing the context stored in the REGDISPLAY.Close#120437