mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 20:56:26 +00:00
Optimize NtGetContextThread a bit and fix use of unitinialized memory if PreviousMode == KernelMode and Thread ==
CurrentThread (thanks to Thomas for spotting!) svn path=/trunk/; revision=18967
This commit is contained in:
parent
662797cc94
commit
55db859f00
1 changed files with 12 additions and 3 deletions
|
@ -86,6 +86,7 @@ NtGetContextThread(IN HANDLE ThreadHandle,
|
||||||
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
||||||
GET_SET_CTX_CONTEXT GetSetContext;
|
GET_SET_CTX_CONTEXT GetSetContext;
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
PCONTEXT SafeThreadContext = NULL;
|
||||||
|
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
|
@ -98,6 +99,7 @@ NtGetContextThread(IN HANDLE ThreadHandle,
|
||||||
sizeof(CONTEXT),
|
sizeof(CONTEXT),
|
||||||
sizeof(ULONG));
|
sizeof(ULONG));
|
||||||
GetSetContext.Context = *ThreadContext;
|
GetSetContext.Context = *ThreadContext;
|
||||||
|
SafeThreadContext = &GetSetContext.Context;
|
||||||
|
|
||||||
} _SEH_HANDLE {
|
} _SEH_HANDLE {
|
||||||
|
|
||||||
|
@ -106,6 +108,8 @@ NtGetContextThread(IN HANDLE ThreadHandle,
|
||||||
} _SEH_END;
|
} _SEH_END;
|
||||||
|
|
||||||
if(!NT_SUCCESS(Status)) return Status;
|
if(!NT_SUCCESS(Status)) return Status;
|
||||||
|
} else {
|
||||||
|
SafeThreadContext = ThreadContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the Thread Object */
|
/* Get the Thread Object */
|
||||||
|
@ -121,15 +125,20 @@ NtGetContextThread(IN HANDLE ThreadHandle,
|
||||||
|
|
||||||
/* Check if we're running in the same thread */
|
/* Check if we're running in the same thread */
|
||||||
if(Thread == PsGetCurrentThread()) {
|
if(Thread == PsGetCurrentThread()) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* I don't know if trying to get your own context makes much
|
* I don't know if trying to get your own context makes much
|
||||||
* sense but we can handle it more efficently.
|
* sense but we can handle it more efficently.
|
||||||
*/
|
*/
|
||||||
KeTrapFrameToContext(Thread->Tcb.TrapFrame, NULL, &GetSetContext.Context);
|
KeTrapFrameToContext(Thread->Tcb.TrapFrame, NULL, SafeThreadContext);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
/* Copy context into GetSetContext if not already done */
|
||||||
|
if(PreviousMode == KernelMode) {
|
||||||
|
GetSetContext.Context = *ThreadContext;
|
||||||
|
SafeThreadContext = &GetSetContext.Context;
|
||||||
|
}
|
||||||
|
|
||||||
/* Use an APC... Initialize the Event */
|
/* Use an APC... Initialize the Event */
|
||||||
KeInitializeEvent(&GetSetContext.Event,
|
KeInitializeEvent(&GetSetContext.Event,
|
||||||
NotificationEvent,
|
NotificationEvent,
|
||||||
|
@ -173,7 +182,7 @@ NtGetContextThread(IN HANDLE ThreadHandle,
|
||||||
ObDereferenceObject(Thread);
|
ObDereferenceObject(Thread);
|
||||||
|
|
||||||
/* Check for success and return the Context */
|
/* Check for success and return the Context */
|
||||||
if(NT_SUCCESS(Status)) {
|
if(NT_SUCCESS(Status) && SafeThreadContext != ThreadContext) {
|
||||||
_SEH_TRY {
|
_SEH_TRY {
|
||||||
|
|
||||||
*ThreadContext = GetSetContext.Context;
|
*ThreadContext = GetSetContext.Context;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue