Fix hardware exception context extraction on Rosetta#107188
Merged
janvorli merged 1 commit intodotnet:mainfrom Aug 30, 2024
Merged
Fix hardware exception context extraction on Rosetta#107188janvorli merged 1 commit intodotnet:mainfrom
janvorli merged 1 commit intodotnet:mainfrom
Conversation
The recently added AVX support in hardware exception handling path on macOS x64 has introduced a problem when running under Rosetta. When we extract the floating point part of the context of the failing thread, the thread can have AVX or AVX512 active, or none of these. The code accidentally leaves CONTEXT_XSTATE set on the context even when no AVX was enabled on the thread. Rosetta doesn't support AVX, so having CONTEXT_XSTATE set in the context flags can lead to later call to RtlRestoreContext attempting to set ymm registers using instructions that Rosetta cannot emulate and the app crashes due to that. This doesn't happen in .NET 9, since we always clear the CONTEXT_XSTATE before exception handling stack unwinding. But in .NET 8, this causes stack overflow under Rosetta, since the attemt to execute the ymm instruction triggers the hardware exception handling again and again.
jkotas
approved these changes
Aug 30, 2024
Member
Author
|
/backport to release/8.0-staging |
Contributor
|
Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/10636388554 |
4 tasks
jtschuster
pushed a commit
to jtschuster/runtime
that referenced
this pull request
Sep 17, 2024
The recently added AVX support in hardware exception handling path on macOS x64 has introduced a problem when running under Rosetta. When we extract the floating point part of the context of the failing thread, the thread can have AVX or AVX512 active, or none of these. The code accidentally leaves CONTEXT_XSTATE set on the context even when no AVX was enabled on the thread. Rosetta doesn't support AVX, so having CONTEXT_XSTATE set in the context flags can lead to later call to RtlRestoreContext attempting to set ymm registers using instructions that Rosetta cannot emulate and the app crashes due to that. This doesn't happen in .NET 9, since we always clear the CONTEXT_XSTATE before exception handling stack unwinding. But in .NET 8, this causes stack overflow under Rosetta, since the attemt to execute the ymm instruction triggers the hardware exception handling again and again.
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The recently added AVX support in hardware exception handling path on macOS x64 has introduced a problem when running under Rosetta. When we extract the floating point part of the context of the failing thread, the thread can have AVX or AVX512 active, or none of these. The code accidentally leaves
CONTEXT_XSTATEset on the context even when no AVX was enabled on the thread.Rosetta doesn't support AVX, so having
CONTEXT_XSTATEset in the context flags can lead to later call toRtlRestoreContextattempting to set ymm registers using instructions that Rosetta cannot emulate and the app crashes due to that.This doesn't happen in .NET 9, since we always clear the
CONTEXT_XSTATEbefore exception handling stack unwinding. But in .NET 8, this causes stack overflow under Rosetta, since the attempt to execute the ymm instruction triggers the hardware exception handling again and again.