Skip to content

Commit

Permalink
fuck itt
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkFire01 committed Dec 7, 2024
1 parent 45ed097 commit da7599d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 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
22 changes: 13 additions & 9 deletions ntoskrnl/ke/i386/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,15 +1283,17 @@ KiFlushNPXState(IN PFLOATING_SAVE_AREA SaveArea)
{
/* Get the FX frame and store the state there */
FxSaveArea = KiGetThreadNpxArea(NpxThread);
Ke386FxSave(FxSaveArea);
if (FxSaveArea)
Ke386FxSave(FxSaveArea);

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

/* Now load NPX state from the NPX area */
FxSaveArea = KiGetThreadNpxArea(Thread);
Ke386FxStore(FxSaveArea);
if (FxSaveArea)
Ke386FxStore(FxSaveArea);
}
else
{
Expand All @@ -1308,7 +1310,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 +1449,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 da7599d

Please sign in to comment.