[NTOS:KE/x64] Initialize FP control word to INITIAL_FPCSR

This commit is contained in:
Timo Kreuzer
2025-07-02 21:38:19 +03:00
parent 80bef4fe40
commit f709f6f22f

View File

@@ -58,14 +58,24 @@ KiInitializeContextThread(IN PKTHREAD Thread,
Thread->StateSaveArea = InitialStack;
RtlZeroMemory(Thread->StateSaveArea, KeXStateLength);
Thread->StateSaveArea->MxCsr = INITIAL_MXCSR;
Thread->StateSaveArea->ControlWord = INITIAL_FPCSR;
/* Special initialization for XSAVES */
if (KeFeatureBits & KF_XSAVES)
/* Check if we use XSAVE */
if (KeFeatureBits & KF_XSTATE)
{
/* Set bit 63 in XCOMP_BV to mark the area as compacted.
XRSTORS requires this and will #GP otherwise. */
/* Enable the mask for legacy floating point state */
PXSAVE_AREA XSaveArea = (PXSAVE_AREA)Thread->StateSaveArea;
XSaveArea->Header.CompactionMask = 0x8000000000000000ULL;
XSaveArea->Header.Mask |= XSTATE_MASK_LEGACY_FLOATING_POINT;
/* Special initialization for XSAVES */
if (KeFeatureBits & KF_XSAVES)
{
/* Set bit 63 in XCOMP_BV to mark the area as compacted.
XRSTORS requires this and will #GP otherwise.
Also mark legacy FP as compacted. */
XSaveArea->Header.CompactionMask |= 0x8000000000000000ULL |
XSTATE_MASK_LEGACY_FLOATING_POINT;
}
}
/* Check if this is a With-Context Thread */