-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix ARM64 ThreadAbort issue #120552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ARM64 ThreadAbort issue #120552
Conversation
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. Close dotnet#120437
There was a problem hiding this 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 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 |
|
/azp run runtime-coreclr libraries-jitstress |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Backport candidate? |
Yes |
|
There is a couple of failing System.Net.XXX tests. All of the failures in these tests are asserting on |
|
/ba-g test failures are #120577 |
|
/backport to release/10.0 |
|
Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18388537629 |
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