https://git.reactos.org/?p=reactos.git;a=commitdiff;h=39f11249ff93f3a362a89…
commit 39f11249ff93f3a362a89694de0cbe43ef52a158
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sat Jul 23 13:31:27 2022 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Mon Aug 22 11:22:08 2022 +0200
[NTOS][RTL] Initialize MxCsr where missing
---
dll/win32/kernel32/client/utils.c | 3 +++
ntoskrnl/ke/amd64/context.c | 6 +++---
ntoskrnl/ke/amd64/cpu.c | 4 ++--
ntoskrnl/ke/amd64/kiinit.c | 6 ++++++
sdk/lib/rtl/amd64/stubs.c | 7 +++++--
5 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/dll/win32/kernel32/client/utils.c b/dll/win32/kernel32/client/utils.c
index c10d2d45004..54a6f05fa5c 100644
--- a/dll/win32/kernel32/client/utils.c
+++ b/dll/win32/kernel32/client/utils.c
@@ -600,6 +600,9 @@ BaseInitializeContext(IN PCONTEXT Context,
/* Set the EFLAGS */
Context->EFlags = 0x3000 | EFLAGS_INTERRUPT_MASK; /* IOPL 3 */
+ /* Set MXCSR */
+ Context->MxCsr = INITIAL_MXCSR;
+
if (ContextType == 1) /* For Threads */
{
Context->Rip = (ULONG_PTR)BaseThreadStartup;
diff --git a/ntoskrnl/ke/amd64/context.c b/ntoskrnl/ke/amd64/context.c
index 0decbde88f9..1e9900af11f 100644
--- a/ntoskrnl/ke/amd64/context.c
+++ b/ntoskrnl/ke/amd64/context.c
@@ -56,7 +56,7 @@ KeContextToTrapFrame(IN PCONTEXT Context,
}
/* Handle floating point registers */
- if ((ContextFlags & CONTEXT_FLOATING_POINT))
+ if (ContextFlags & CONTEXT_FLOATING_POINT)
{
TrapFrame->MxCsr = Context->MxCsr;
TrapFrame->Xmm0 = Context->Xmm0;
@@ -207,9 +207,9 @@ KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame,
}
/* Handle floating point registers */
- if ((ContextFlags & CONTEXT_FLOATING_POINT) &&
- ((TrapFrame->SegCs & MODE_MASK) != KernelMode))
+ if (ContextFlags & CONTEXT_FLOATING_POINT)
{
+ Context->MxCsr = TrapFrame->MxCsr;
Context->Xmm0 = TrapFrame->Xmm0;
Context->Xmm1 = TrapFrame->Xmm1;
Context->Xmm2 = TrapFrame->Xmm2;
diff --git a/ntoskrnl/ke/amd64/cpu.c b/ntoskrnl/ke/amd64/cpu.c
index d4a8888c664..0967411e644 100644
--- a/ntoskrnl/ke/amd64/cpu.c
+++ b/ntoskrnl/ke/amd64/cpu.c
@@ -375,7 +375,7 @@ KiRestoreProcessorControlState(PKPROCESSOR_STATE ProcessorState)
// __ltr(&ProcessorState->SpecialRegisters.Tr);
__lidt(&ProcessorState->SpecialRegisters.Idtr.Limit);
-// __ldmxcsr(&ProcessorState->SpecialRegisters.MxCsr); // FIXME
+ _mm_setcsr(ProcessorState->SpecialRegisters.MxCsr);
// ProcessorState->SpecialRegisters.DebugControl
// ProcessorState->SpecialRegisters.LastBranchToRip
// ProcessorState->SpecialRegisters.LastBranchFromRip
@@ -417,7 +417,7 @@ KiSaveProcessorControlState(OUT PKPROCESSOR_STATE ProcessorState)
__str(&ProcessorState->SpecialRegisters.Tr);
__sidt(&ProcessorState->SpecialRegisters.Idtr.Limit);
-// __stmxcsr(&ProcessorState->SpecialRegisters.MxCsr);
+ ProcessorState->SpecialRegisters.MxCsr = _mm_getcsr();
// ProcessorState->SpecialRegisters.DebugControl =
// ProcessorState->SpecialRegisters.LastBranchToRip =
// ProcessorState->SpecialRegisters.LastBranchFromRip =
diff --git a/ntoskrnl/ke/amd64/kiinit.c b/ntoskrnl/ke/amd64/kiinit.c
index d9c8807bf34..310810475ea 100644
--- a/ntoskrnl/ke/amd64/kiinit.c
+++ b/ntoskrnl/ke/amd64/kiinit.c
@@ -152,6 +152,9 @@ KiInitializePcr(IN PKIPCR Pcr,
Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr6 = 0;
Pcr->Prcb.ProcessorState.SpecialRegisters.KernelDr7 = 0;
+ /* Initialize MXCSR (all exceptions masked) */
+ Pcr->Prcb.MxCsr = INITIAL_MXCSR;
+
/* Set the Current Thread */
Pcr->Prcb.CurrentThread = IdleThread;
@@ -231,6 +234,9 @@ KiInitializeCpu(PKIPCR Pcr)
Pat = (PAT_WB << 0) | (PAT_WC << 8) | (PAT_UCM << 16) | (PAT_UC
<< 24) |
(PAT_WB << 32) | (PAT_WC << 40) | (PAT_UCM << 48) | (PAT_UC
<< 56);
__writemsr(MSR_PAT, Pat);
+
+ /* Initialize MXCSR */
+ _mm_setcsr(INITIAL_MXCSR);
}
VOID
diff --git a/sdk/lib/rtl/amd64/stubs.c b/sdk/lib/rtl/amd64/stubs.c
index 7ffc4fb9658..0f02e60a41a 100644
--- a/sdk/lib/rtl/amd64/stubs.c
+++ b/sdk/lib/rtl/amd64/stubs.c
@@ -23,7 +23,7 @@ NTAPI
RtlInitializeContext(
_Reserved_ HANDLE ProcessHandle,
_Out_ PCONTEXT ThreadContext,
- _In_ PVOID ThreadStartParam OPTIONAL,
+ _In_opt_ PVOID ThreadStartParam,
_In_ PTHREAD_START_ROUTINE ThreadStartAddress,
_In_ PINITIAL_TEB StackBase)
{
@@ -66,10 +66,13 @@ RtlInitializeContext(
ThreadContext->SegSs = KGDT64_R3_DATA | RPL_MASK;
}
+ ThreadContext->MxCsr = INITIAL_MXCSR;
+
/* Only the basic Context is initialized */
ThreadContext->ContextFlags = CONTEXT_CONTROL |
CONTEXT_INTEGER |
- CONTEXT_SEGMENTS;
+ CONTEXT_SEGMENTS |
+ CONTEXT_FLOATING_POINT;
return;
}