[release/10.0] Fix ARM64 ThreadAbort issue #120579
Merged
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.
Backport of #120552 to release/10.0
/cc @janvorli
Customer Impact
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 the runtime ends up crashing with an assert in debug/checked build and causing some unexpected behavior and random crashes in release builds.
Regression
Testing
CI tests - libraries tests contain controlled execution tests that started to fail on some CI runs, probably due to added machines with enabled SVE or upgraded Windows with enabled SVE.
Risk
Low, the fix just removes the CONTEXT_XSTATE from the copied context and makes it valid.