Skip to content

Conversation

@janvorli
Copy link
Member

@janvorli janvorli commented Oct 1, 2025

The CopyOSContext was skipping floating point registers on amd64. There was an obsolete comment that on some older Windows, the vector registers are not present in the context. I've found to be a problem when porting nativeAOT EH to CoreCLR and to make the context flags correct, I've removed the CONTEXT_FLOATING_POINT from the ContextFlags. But it now turned out that it prevents EH from correctly restoring non-volatile floating point registers after a catch. Since he ContextFlags don't contain the CONTEXT_FLOATING_POINT, the floating point registers were not restored during the resume.

This change fixes it by removing the amd64 specific handling and always copying the whole CONTEXT structure. It just masks off the CONTEXT_XSTATE, as the XSTATE is stored out of the basic CONTEXT.

Close #118564

The CopyOSContext was skipping floating point registers on amd64. There
was an obsolete comment that on some older Windows, the vector registers
are not present in the context. I've found to be a problem when porting
nativeAOT EH to CoreCLR and to make the context flags correct, I've
removed the CONTEXT_FLOATING_POINT from the ContextFlags. But it now
turned out that it prevents EH from correctly restoring non-volatile
floating point registers after a catch. Since he ContextFlags don't
contain the CONTEXT_FLOATING_POINT, the floating point registers were
not restored during the resume.

This change fixes it by removing the amd64 specific handling and always
copying the whole CONTEXT structure. It just masks off the
CONTEXT_XSTATE, as the XSTATE is stored out of the basic CONTEXT.

Close dotnet#118564
@janvorli janvorli requested a review from jkotas October 1, 2025 16:17
@janvorli janvorli self-assigned this Oct 1, 2025
@Copilot Copilot AI review requested due to automatic review settings October 1, 2025 16:17
Copy link
Contributor

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

Fix ensures floating point (non-volatile) registers are preserved/restored on AMD64 during exception handling by copying the full CONTEXT instead of omitting floating point parts.

  • Removes legacy partial copy logic specific to older AMD64 Windows platforms.
  • Adjusts ContextFlags post-copy to exclude XSTATE (stored separately).

@janvorli janvorli merged commit e36d92e into dotnet:main Oct 2, 2025
98 checks passed
@janvorli janvorli deleted the fix-copyoscontext branch October 2, 2025 15:21
@janvorli
Copy link
Member Author

janvorli commented Oct 2, 2025

/backport to release/10.0

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2025

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18197632320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test failure: System.Tests.ValueTupleTests.TestEquals_GetHashCode

2 participants