Skip to content

CopyContext in Thread::RedirectCurrentThreadAtHandledJITCase sometimes fails #65776

@janvorli

Description

@janvorli

I have noticed that on my machine the CopyContext call in the Thread::RedirectCurrentThreadAtHandledJITCase sometimes fails with the ERROR_INSUFFICIENT_BUFFER. I have debugged it and found the culprit. The issue is that the target context that we've just allocated in AllocateOSContextHelper doesn't have enough space in the XState due to the fact that we set too small XState compaction mask in the InitializeContext2 call. We set just XSTATE_MASK_LEGACY | XSTATE_MASK_AVX, but the source context that we get from the vectored exception handler was created with XSTATE_MASK_LEGACY | XSTATE_MASK_AVX | XSTATE_MASK_AVX512 | XSTATE_MASK_MPX (in other words, the masks returned by the GetEnabledXStateFeatures(). While the CopyContext can copy only parts of the legacy context based on the context flags, it obviously cannot copy only part of the xstate from the source context.

I am not sure what makes OS to call the vectored exception handler with this full AVX state only in some cases, because I hit this problem only with one of the coreclr tests and only when tiered compilation is disabled.

It seems that we need to pass the result of the GetEnabledXStateFeatures() as xStateCompactionMask to the InitializeContext2.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions