{
PKIPCR Pcr = (PKIPCR)KeGetPcr();
PKPROCESS OldProcess, NewProcess;
/* Setup ring 0 stack pointer */
Pcr->TssBase->Rsp0 = (ULONG64)NewThread->InitialStack; // FIXME: NPX save area?
Pcr->Prcb.RspBase = Pcr->TssBase->Rsp0;
/* Now we are the new thread. Check if it's in a new process */
OldProcess = OldThread->ApcState.Process;
NewProcess = NewThread->ApcState.Process;
if (OldProcess != NewProcess)
{
/* Switch address space and flush TLB */__writecr3(NewProcess->DirectoryTableBase[0]);
/* Set new TSS fields *///Pcr->TssBase->IoMapBase = NewProcess->IopmOffset;
}
/* Set TEB pointer and GS base */
Pcr->NtTib.Self = (PVOID)NewThread->Teb;
if (NewThread->Teb)
{
/* This will switch the usermode gs */__writemsr(MSR_GS_SWAP, (ULONG64)NewThread->Teb);
}
/* Increase context switch count */
Pcr->ContextSwitches++;
NewThread->ContextSwitches++;
/* DPCs shouldn't be active */if (Pcr->Prcb.DpcRoutineActive)
{
/* Crash the machine */KeBugCheckEx(ATTEMPTED_SWITCH_FROM_DPC,
(ULONG_PTR)OldThread,
(ULONG_PTR)NewThread,
(ULONG_PTR)OldThread->InitialStack,
0);
}
/* Kernel APCs may be pending */if (NewThread->ApcState.KernelApcPending)
{
/* Are APCs enabled? */if (!NewThread->SpecialApcDisable)
{
/* Request APC delivery */if (!ApcBypass)
HalRequestSoftwareInterrupt(APC_LEVEL);
elsereturnTRUE;
}
}
/* Return stating that no kernel APCs are pending*/returnFALSE;
}
Generated on Sun May 27 2012 06:07:50 for ReactOS by
1.7.6.1
ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.