Skip to content

Commit

Permalink
fuck itt
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkFire01 committed Nov 24, 2024
1 parent e91f800 commit eec270d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions ntoskrnl/include/internal/i386/ke.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@ PFX_SAVE_AREA
KiGetThreadNpxArea(IN PKTHREAD Thread)
{
ASSERT((ULONG_PTR)Thread->InitialStack % 16 == 0);
if ((ULONG_PTR)Thread->InitialStack < sizeof(FX_SAVE_AREA))
return NULL;
return (PFX_SAVE_AREA)((ULONG_PTR)Thread->InitialStack - sizeof(FX_SAVE_AREA));
}

Expand Down
19 changes: 11 additions & 8 deletions ntoskrnl/ke/i386/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,8 @@ KiFlushNPXState(IN PFLOATING_SAVE_AREA SaveArea)

/* Now load NPX state from the NPX area */
FxSaveArea = KiGetThreadNpxArea(Thread);
Ke386FxStore(FxSaveArea);
if (FxSaveArea)
Ke386FxStore(FxSaveArea);
}
else
{
Expand All @@ -1308,7 +1309,7 @@ KiFlushNPXState(IN PFLOATING_SAVE_AREA SaveArea)
Thread->NpxState = NPX_STATE_NOT_LOADED;

/* Save state if supported by CPU */
if (KeI386FxsrPresent) Ke386FxSave(FxSaveArea);
if (KeI386FxsrPresent && FxSaveArea) Ke386FxSave(FxSaveArea);
}

/* Now save the FN state wherever it was requested */
Expand Down Expand Up @@ -1447,13 +1448,15 @@ KeSaveFloatingPointState(
{
/* Get the FX frame */
FxSaveAreaFrame = KiGetThreadNpxArea(CurrentPrcb->NpxThread);
if (FxSaveAreaFrame)
{
/* Save the FPU state */
Ke386SaveFpuState(FxSaveAreaFrame);

/* Save the FPU state */
Ke386SaveFpuState(FxSaveAreaFrame);

/* NPX thread has lost its state */
CurrentPrcb->NpxThread->NpxState = NPX_STATE_NOT_LOADED;
FxSaveAreaFrame->NpxSavedCpu = 0;
/* NPX thread has lost its state */
CurrentPrcb->NpxThread->NpxState = NPX_STATE_NOT_LOADED;
FxSaveAreaFrame->NpxSavedCpu = 0;
}
}

/* The new NPX thread is the current thread */
Expand Down
3 changes: 2 additions & 1 deletion ntoskrnl/ke/i386/traphdlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,8 @@ KiTrap07Handler(IN PKTRAP_FRAME TrapFrame)
NpxSaveArea = KiGetThreadNpxArea(NpxThread);

/* Save FPU state */
Ke386SaveFpuState(NpxSaveArea);
if (NpxSaveArea)
Ke386SaveFpuState(NpxSaveArea);

/* Update NPX state */
NpxThread->NpxState = NPX_STATE_NOT_LOADED;
Expand Down

0 comments on commit eec270d

Please sign in to comment.