[NTOSKRNL]

Implement Ke386SetGdtEntryBase and KiSetTebBase and use it in the appropriate places.

svn path=/trunk/; revision=58460
This commit is contained in:
Timo Kreuzer 2013-03-10 11:44:04 +00:00
parent e850321ffc
commit 8cb3ec617f
3 changed files with 103 additions and 105 deletions

View file

@ -279,6 +279,23 @@ KiRundownThread(IN PKTHREAD Thread)
#endif
}
FORCEINLINE
VOID
Ke386SetGdtEntryBase(PKGDTENTRY GdtEntry, PVOID BaseAddress)
{
GdtEntry->BaseLow = (USHORT)((ULONG_PTR)BaseAddress & 0xFFFF);
GdtEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)BaseAddress >> 16);
GdtEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)BaseAddress >> 24);
}
FORCEINLINE
VOID
KiSetTebBase(PKPCR Pcr, PVOID TebAddress)
{
Pcr->NtTib.Self = TebAddress;
Ke386SetGdtEntryBase(&Pcr->GDT[KGDT_R3_TEB / sizeof(KGDTENTRY)], TebAddress);
}
VOID
FASTCALL
Ki386InitializeTss(

View file

@ -332,7 +332,6 @@ KiSwapContextExit(IN PKTHREAD OldThread,
{
PKIPCR Pcr = (PKIPCR)KeGetPcr();
PKPROCESS OldProcess, NewProcess;
PKGDTENTRY GdtEntry;
PKTHREAD NewThread;
/* We are on the new thread stack now */
@ -358,11 +357,7 @@ KiSwapContextExit(IN PKTHREAD OldThread,
Ke386SetGs(0);
/* Set the TEB */
Pcr->NtTib.Self = (PVOID)NewThread->Teb;
GdtEntry = &Pcr->GDT[KGDT_R3_TEB / sizeof(KGDTENTRY)];
GdtEntry->BaseLow = (USHORT)((ULONG_PTR)NewThread->Teb & 0xFFFF);
GdtEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)NewThread->Teb >> 16);
GdtEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)NewThread->Teb >> 24);
KiSetTebBase((PKPCR)Pcr, NewThread->Teb);
/* Set new TSS fields */
Pcr->TSS->Esp0 = (ULONG_PTR)NewThread->InitialStack;

View file

@ -450,7 +450,6 @@ FASTCALL
KiExitV86Mode(IN PKTRAP_FRAME TrapFrame)
{
PKV8086_STACK_FRAME StackFrame;
PKGDTENTRY GdtEntry;
PKTHREAD Thread;
PKTRAP_FRAME PmTrapFrame;
PKV86_FRAME V86Frame;
@ -474,13 +473,7 @@ KiExitV86Mode(IN PKTRAP_FRAME TrapFrame)
/* Restore TEB addresses */
Thread->Teb = V86Frame->ThreadTeb;
KeGetPcr()->NtTib.Self = V86Frame->PcrTeb;
/* Setup real TEB descriptor */
GdtEntry = &((PKIPCR)KeGetPcr())->GDT[KGDT_R3_TEB / sizeof(KGDTENTRY)];
GdtEntry->BaseLow = (USHORT)((ULONG_PTR)Thread->Teb & 0xFFFF);
GdtEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)Thread->Teb >> 16);
GdtEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)Thread->Teb >> 24);
KiSetTebBase(KeGetPcr(), V86Frame->ThreadTeb);
/* Enable interrupts and return a pointer to the trap frame */
_enable();
@ -492,7 +485,6 @@ FASTCALL
KiEnterV86Mode(IN PKV8086_STACK_FRAME StackFrame)
{
PKTHREAD Thread;
PKGDTENTRY GdtEntry;
PKTRAP_FRAME TrapFrame = &StackFrame->TrapFrame;
PKV86_FRAME V86Frame = &StackFrame->V86Frame;
PFX_SAVE_AREA NpxFrame = &StackFrame->NpxArea;
@ -547,13 +539,7 @@ KiEnterV86Mode(IN PKV8086_STACK_FRAME StackFrame)
/* Set VDM TEB */
Thread->Teb = (PTEB)TRAMPOLINE_TEB;
KeGetPcr()->NtTib.Self = (PVOID)TRAMPOLINE_TEB;
/* Setup VDM TEB descriptor */
GdtEntry = &((PKIPCR)KeGetPcr())->GDT[KGDT_R3_TEB / sizeof(KGDTENTRY)];
GdtEntry->BaseLow = (USHORT)((ULONG_PTR)TRAMPOLINE_TEB & 0xFFFF);
GdtEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)TRAMPOLINE_TEB >> 16);
GdtEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)TRAMPOLINE_TEB >> 24);
KiSetTebBase(KeGetPcr(), (PVOID)TRAMPOLINE_TEB);
/* Enable interrupts */
_enable();