mirror of
https://github.com/reactos/reactos.git
synced 2024-07-01 02:10:07 +00:00
[NTOS:PS/x64] Fix PspGetOrSetContextKernelRoutine
It now uses KiSetTrapContext to set the non-volatile context on the stack and the volatile context in the trap frame.
This commit is contained in:
parent
f1ed97d6cc
commit
e8496b4fbf
|
@ -449,6 +449,12 @@ KiGetUserModeStackAddress(void)
|
||||||
return &PsGetCurrentThread()->Tcb.TrapFrame->Rsp;
|
return &PsGetCurrentThread()->Tcb.TrapFrame->Rsp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID
|
||||||
|
KiSetTrapContext(
|
||||||
|
_Out_ PKTRAP_FRAME TrapFrame,
|
||||||
|
_In_ PCONTEXT Context,
|
||||||
|
_In_ KPROCESSOR_MODE RequestorMode);
|
||||||
|
|
||||||
#endif /* __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H */
|
#endif /* __NTOSKRNL_INCLUDE_INTERNAL_AMD64_KE_H */
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -15,81 +15,57 @@
|
||||||
|
|
||||||
/* FUNCTIONS ******************************************************************/
|
/* FUNCTIONS ******************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
_IRQL_requires_(APC_LEVEL)
|
||||||
VOID
|
VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
PspGetContext(IN PKTRAP_FRAME TrapFrame,
|
PspGetOrSetContextKernelRoutine(
|
||||||
IN PVOID NonVolatileContext,
|
_In_ PKAPC Apc,
|
||||||
IN OUT PCONTEXT Context)
|
_Inout_ PKNORMAL_ROUTINE* NormalRoutine,
|
||||||
{
|
_Inout_ PVOID* NormalContext,
|
||||||
PAGED_CODE();
|
_Inout_ PVOID* SystemArgument1,
|
||||||
|
_Inout_ PVOID* SystemArgument2)
|
||||||
/* Convert the trap frame to a context */
|
|
||||||
KeTrapFrameToContext(TrapFrame, NULL, Context);
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID
|
|
||||||
NTAPI
|
|
||||||
PspSetContext(OUT PKTRAP_FRAME TrapFrame,
|
|
||||||
OUT PVOID NonVolatileContext,
|
|
||||||
IN PCONTEXT Context,
|
|
||||||
IN KPROCESSOR_MODE Mode)
|
|
||||||
{
|
|
||||||
PAGED_CODE();
|
|
||||||
|
|
||||||
/* Convert the context to a trap frame structure */
|
|
||||||
KeContextToTrapFrame(Context, NULL, TrapFrame, Context->ContextFlags, Mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID
|
|
||||||
NTAPI
|
|
||||||
PspGetOrSetContextKernelRoutine(IN PKAPC Apc,
|
|
||||||
IN OUT PKNORMAL_ROUTINE* NormalRoutine,
|
|
||||||
IN OUT PVOID* NormalContext,
|
|
||||||
IN OUT PVOID* SystemArgument1,
|
|
||||||
IN OUT PVOID* SystemArgument2)
|
|
||||||
{
|
{
|
||||||
PGET_SET_CTX_CONTEXT GetSetContext;
|
PGET_SET_CTX_CONTEXT GetSetContext;
|
||||||
PKEVENT Event;
|
|
||||||
PCONTEXT Context;
|
|
||||||
PKTHREAD Thread;
|
PKTHREAD Thread;
|
||||||
KPROCESSOR_MODE Mode;
|
|
||||||
PKTRAP_FRAME TrapFrame = NULL;
|
PKTRAP_FRAME TrapFrame = NULL;
|
||||||
|
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Get the Context Structure */
|
/* Get the Context Structure */
|
||||||
GetSetContext = CONTAINING_RECORD(Apc, GET_SET_CTX_CONTEXT, Apc);
|
GetSetContext = CONTAINING_RECORD(Apc, GET_SET_CTX_CONTEXT, Apc);
|
||||||
Context = &GetSetContext->Context;
|
|
||||||
Event = &GetSetContext->Event;
|
|
||||||
Mode = GetSetContext->Mode;
|
|
||||||
Thread = Apc->SystemArgument2;
|
Thread = Apc->SystemArgument2;
|
||||||
|
NT_ASSERT(KeGetCurrentThread() == Thread);
|
||||||
|
|
||||||
/* If this is a kernel-mode request, grab the saved trap frame */
|
/* If this is a kernel-mode request, grab the saved trap frame */
|
||||||
if (Mode == KernelMode) TrapFrame = Thread->TrapFrame;
|
if (GetSetContext->Mode == KernelMode)
|
||||||
|
{
|
||||||
|
TrapFrame = Thread->TrapFrame;
|
||||||
|
}
|
||||||
|
|
||||||
/* If we don't have one, grab it from the stack */
|
/* If we don't have one, grab it from the stack */
|
||||||
if (!TrapFrame)
|
if (TrapFrame == NULL)
|
||||||
{
|
{
|
||||||
DPRINT1("FIXME!!!!\n");
|
/* Get the thread's base trap frame */
|
||||||
/* Trap frame is right under our initial stack */
|
TrapFrame = KeGetTrapFrame(KeGetCurrentThread());
|
||||||
// TrapFrame = (PKTRAP_FRAME)((ULONG_PTR)Thread->InitialStack -
|
|
||||||
// ROUND_UP(sizeof(KTRAP_FRAME), KTRAP_FRAME_ALIGN) -
|
|
||||||
// sizeof(FX_SAVE_AREA));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if it's a set or get */
|
/* Check if it's a set or get */
|
||||||
if (Apc->SystemArgument1)
|
if (Apc->SystemArgument1 != 0)
|
||||||
{
|
{
|
||||||
/* Get the Context */
|
/* Set the nonvolatiles on the stack, target frame is the trap frame */
|
||||||
PspSetContext(TrapFrame, NULL, Context, Mode);
|
KiSetTrapContext(TrapFrame, &GetSetContext->Context, GetSetContext->Mode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Set the Context */
|
/* Convert the trap frame to a context */
|
||||||
PspGetContext(TrapFrame, NULL, Context);
|
KeTrapFrameToContext(TrapFrame,
|
||||||
|
NULL,
|
||||||
|
&GetSetContext->Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Notify the Native API that we are done */
|
/* Notify the Native API that we are done */
|
||||||
KeSetEvent(Event, IO_NO_INCREMENT, FALSE);
|
KeSetEvent(&GetSetContext->Event, IO_NO_INCREMENT, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
Loading…
Reference in a new issue