Fixes in AMD64 version of KepInitializeThreadContext() to get rid of PageFault exception
All checks were successful
Builds / ExectOS (amd64) (push) Successful in 58s
Builds / ExectOS (i686) (push) Successful in 31s

This commit is contained in:
Rafal Kupiec 2023-11-07 15:34:49 +01:00
parent 91ce0f9947
commit 362eefc2b3
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
2 changed files with 13 additions and 7 deletions

View File

@ -139,6 +139,11 @@
/* Size of legacy 387 registers */
#define SIZE_OF_80387_REGISTERS 80
/* NPX state definitions */
#define NPX_STATE_UNUSED 0x0
#define NPX_STATE_SCRUB 0x1
#define NPX_STATE_SWITCH 0x2
/* Floating point state storing structure */
typedef struct _FLOATING_SAVE_AREA
{
@ -352,7 +357,8 @@ typedef struct _KSWITCH_FRAME
ULONG64 P4Home;
ULONG64 P5Home;
ULONG MxCsr;
UCHAR Reserved[4];
KIRQL ApcBypass;
UCHAR Reserved[3];
ULONG64 Rbp;
ULONG64 Return;
} KSWITCH_FRAME, *PKSWITCH_FRAME;

View File

@ -42,7 +42,7 @@ KepInitializeThreadContext(IN PKTHREAD Thread,
PKTHREAD_INIT_FRAME ThreadFrame;
/* Set initial thread frame */
ThreadFrame = (PKTHREAD_INIT_FRAME)Thread->InitialStack - sizeof(KTHREAD_INIT_FRAME);
ThreadFrame = ((PKTHREAD_INIT_FRAME)Thread->InitialStack) - 1;
/* Fill floating point save area with zeroes */
RtlZeroMemory(&ThreadFrame->NpxFrame, sizeof(FLOATING_SAVE_AREA));
@ -68,7 +68,7 @@ KepInitializeThreadContext(IN PKTHREAD Thread,
Thread->PreviousMode = UserMode;
/* Enable floating point state */
Thread->NpxState = 1;
Thread->NpxState = NPX_STATE_SCRUB;
/* Set initial floating point state */
ThreadFrame->NpxFrame.ControlWord = 0x27F;
@ -93,9 +93,9 @@ KepInitializeThreadContext(IN PKTHREAD Thread,
Thread->PreviousMode = KernelMode;
/* Disable floating point state */
Thread->NpxState = 0;
Thread->NpxState = NPX_STATE_UNUSED;
/* Set thread startup frame return information */
/* Set thread start address */
ThreadFrame->StartFrame.Return = (ULONG64)NULL;
}
@ -106,10 +106,10 @@ KepInitializeThreadContext(IN PKTHREAD Thread,
ThreadFrame->StartFrame.P4Home = (ULONG64)SystemRoutine;
/* Initialize switch frame */
ThreadFrame->SwitchFrame.Rbp = (ULONG64)&ThreadFrame->TrapFrame + 128;
ThreadFrame->SwitchFrame.ApcBypass = APC_LEVEL;
ThreadFrame->SwitchFrame.MxCsr = INITIAL_MXCSR;
ThreadFrame->SwitchFrame.Rbp = (ULONG64)&ThreadFrame->TrapFrame;
/* Set thread stack */
Thread->InitialStack = &ThreadFrame->NpxFrame;
Thread->KernelStack = &ThreadFrame->SwitchFrame;
}