[NTOS:FORMATTING]

- Remove some trailing whitespace

svn path=/trunk/; revision=64518
This commit is contained in:
Thomas Faber 2014-10-04 08:43:15 +00:00
parent 317ae30716
commit 9d68ddc78c
4 changed files with 132 additions and 132 deletions

View file

@ -24,7 +24,7 @@ KiSwapProcess(IN PKPROCESS NewProcess,
PKIPCR Pcr = (PKIPCR)KeGetPcr(); PKIPCR Pcr = (PKIPCR)KeGetPcr();
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
LONG SetMember; LONG SetMember;
/* Update active processor mask */ /* Update active processor mask */
SetMember = (LONG)Pcr->SetMember; SetMember = (LONG)Pcr->SetMember;
InterlockedXor((PLONG)&NewProcess->ActiveProcessors, SetMember); InterlockedXor((PLONG)&NewProcess->ActiveProcessors, SetMember);
@ -38,13 +38,13 @@ KiSwapProcess(IN PKPROCESS NewProcess,
UNIMPLEMENTED_DBGBREAK(); UNIMPLEMENTED_DBGBREAK();
return; return;
} }
/* Update CR3 */ /* Update CR3 */
__writecr3(NewProcess->DirectoryTableBase[0]); __writecr3(NewProcess->DirectoryTableBase[0]);
/* Clear GS */ /* Clear GS */
Ke386SetGs(0); Ke386SetGs(0);
/* Update IOPM offset */ /* Update IOPM offset */
Pcr->TSS->IoMapBase = NewProcess->IopmOffset; Pcr->TSS->IoMapBase = NewProcess->IopmOffset;
} }

View file

@ -3,7 +3,7 @@
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/i386/ctxswitch.S * FILE: ntoskrnl/ke/i386/ctxswitch.S
* PURPOSE: Thread Context Switching * PURPOSE: Thread Context Switching
* *
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net) * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
* Gregor Anich (FPU Code) * Gregor Anich (FPU Code)
*/ */
@ -63,7 +63,7 @@ PUBLIC @KiSwitchThreads@8
/* Load the new kernel stack and switch OS to new thread */ /* Load the new kernel stack and switch OS to new thread */
mov esp, edx mov esp, edx
call @KiSwapContextExit@8 call @KiSwapContextExit@8
/* Now we're on the new thread. Return to the caller to restore registers */ /* Now we're on the new thread. Return to the caller to restore registers */
add esp, 2 * 4 add esp, 2 * 4
ret ret

View file

@ -143,7 +143,7 @@ KiExitInterrupt(IN PKTRAP_FRAME TrapFrame,
_disable(); _disable();
HalEndSystemInterrupt(OldIrql, TrapFrame); HalEndSystemInterrupt(OldIrql, TrapFrame);
} }
/* Now exit the trap */ /* Now exit the trap */
KiEoiHelper(TrapFrame); KiEoiHelper(TrapFrame);
} }
@ -154,25 +154,25 @@ KiUnexpectedInterrupt(VOID)
/* Crash the machine */ /* Crash the machine */
KeBugCheck(TRAP_CAUSE_UNKNOWN); KeBugCheck(TRAP_CAUSE_UNKNOWN);
} }
VOID VOID
FASTCALL FASTCALL
KiUnexpectedInterruptTailHandler(IN PKTRAP_FRAME TrapFrame) KiUnexpectedInterruptTailHandler(IN PKTRAP_FRAME TrapFrame)
{ {
KIRQL OldIrql; KIRQL OldIrql;
/* Enter trap */ /* Enter trap */
KiEnterInterruptTrap(TrapFrame); KiEnterInterruptTrap(TrapFrame);
/* Increase interrupt count */ /* Increase interrupt count */
KeGetCurrentPrcb()->InterruptCount++; KeGetCurrentPrcb()->InterruptCount++;
/* Start the interrupt */ /* Start the interrupt */
if (HalBeginSystemInterrupt(HIGH_LEVEL, TrapFrame->ErrCode, &OldIrql)) if (HalBeginSystemInterrupt(HIGH_LEVEL, TrapFrame->ErrCode, &OldIrql))
{ {
/* Warn user */ /* Warn user */
DPRINT1("\n\x7\x7!!! Unexpected Interrupt 0x%02lx !!!\n", TrapFrame->ErrCode); DPRINT1("\n\x7\x7!!! Unexpected Interrupt 0x%02lx !!!\n", TrapFrame->ErrCode);
/* Now call the epilogue code */ /* Now call the epilogue code */
KiExitInterrupt(TrapFrame, OldIrql, FALSE); KiExitInterrupt(TrapFrame, OldIrql, FALSE);
} }
@ -194,12 +194,12 @@ VOID
FASTCALL FASTCALL
KiInterruptDispatch(IN PKTRAP_FRAME TrapFrame, KiInterruptDispatch(IN PKTRAP_FRAME TrapFrame,
IN PKINTERRUPT Interrupt) IN PKINTERRUPT Interrupt)
{ {
KIRQL OldIrql; KIRQL OldIrql;
/* Increase interrupt count */ /* Increase interrupt count */
KeGetCurrentPrcb()->InterruptCount++; KeGetCurrentPrcb()->InterruptCount++;
/* Begin the interrupt, making sure it's not spurious */ /* Begin the interrupt, making sure it's not spurious */
if (HalBeginSystemInterrupt(Interrupt->SynchronizeIrql, if (HalBeginSystemInterrupt(Interrupt->SynchronizeIrql,
Interrupt->Vector, Interrupt->Vector,
@ -207,13 +207,13 @@ KiInterruptDispatch(IN PKTRAP_FRAME TrapFrame,
{ {
/* Acquire interrupt lock */ /* Acquire interrupt lock */
KxAcquireSpinLock(Interrupt->ActualLock); KxAcquireSpinLock(Interrupt->ActualLock);
/* Call the ISR */ /* Call the ISR */
Interrupt->ServiceRoutine(Interrupt, Interrupt->ServiceContext); Interrupt->ServiceRoutine(Interrupt, Interrupt->ServiceContext);
/* Release interrupt lock */ /* Release interrupt lock */
KxReleaseSpinLock(Interrupt->ActualLock); KxReleaseSpinLock(Interrupt->ActualLock);
/* Now call the epilogue code */ /* Now call the epilogue code */
KiExitInterrupt(TrapFrame, OldIrql, FALSE); KiExitInterrupt(TrapFrame, OldIrql, FALSE);
} }
@ -252,7 +252,7 @@ KiChainedDispatch(IN PKTRAP_FRAME TrapFrame,
/* Raise to higher IRQL */ /* Raise to higher IRQL */
OldInterruptIrql = KfRaiseIrql(Interrupt->SynchronizeIrql); OldInterruptIrql = KfRaiseIrql(Interrupt->SynchronizeIrql);
} }
/* Acquire interrupt lock */ /* Acquire interrupt lock */
KxAcquireSpinLock(Interrupt->ActualLock); KxAcquireSpinLock(Interrupt->ActualLock);
@ -262,7 +262,7 @@ KiChainedDispatch(IN PKTRAP_FRAME TrapFrame,
/* Release interrupt lock */ /* Release interrupt lock */
KxReleaseSpinLock(Interrupt->ActualLock); KxReleaseSpinLock(Interrupt->ActualLock);
/* Check if this interrupt's IRQL is higher than the current one */ /* Check if this interrupt's IRQL is higher than the current one */
if (Interrupt->SynchronizeIrql > Interrupt->Irql) if (Interrupt->SynchronizeIrql > Interrupt->Irql)
{ {
@ -270,23 +270,23 @@ KiChainedDispatch(IN PKTRAP_FRAME TrapFrame,
ASSERT(OldInterruptIrql == Interrupt->Irql); ASSERT(OldInterruptIrql == Interrupt->Irql);
KfLowerIrql(OldInterruptIrql); KfLowerIrql(OldInterruptIrql);
} }
/* Check if the interrupt got handled and it's level */ /* Check if the interrupt got handled and it's level */
if ((Handled) && (Interrupt->Mode == LevelSensitive)) break; if ((Handled) && (Interrupt->Mode == LevelSensitive)) break;
/* What's next? */ /* What's next? */
NextEntry = NextEntry->Flink; NextEntry = NextEntry->Flink;
/* Is this the last one? */ /* Is this the last one? */
if (NextEntry == ListHead) if (NextEntry == ListHead)
{ {
/* Level should not have gotten here */ /* Level should not have gotten here */
if (Interrupt->Mode == LevelSensitive) break; if (Interrupt->Mode == LevelSensitive) break;
/* As for edge, we can only exit once nobody can handle the interrupt */ /* As for edge, we can only exit once nobody can handle the interrupt */
if (!Handled) break; if (!Handled) break;
} }
/* Get the interrupt object for the next pass */ /* Get the interrupt object for the next pass */
Interrupt = CONTAINING_RECORD(NextEntry, KINTERRUPT, InterruptListEntry); Interrupt = CONTAINING_RECORD(NextEntry, KINTERRUPT, InterruptListEntry);
} }
@ -575,22 +575,22 @@ KeSynchronizeExecution(IN OUT PKINTERRUPT Interrupt,
{ {
BOOLEAN Success; BOOLEAN Success;
KIRQL OldIrql; KIRQL OldIrql;
/* Raise IRQL */ /* Raise IRQL */
OldIrql = KfRaiseIrql(Interrupt->SynchronizeIrql); OldIrql = KfRaiseIrql(Interrupt->SynchronizeIrql);
/* Acquire interrupt spinlock */ /* Acquire interrupt spinlock */
KeAcquireSpinLockAtDpcLevel(Interrupt->ActualLock); KeAcquireSpinLockAtDpcLevel(Interrupt->ActualLock);
/* Call the routine */ /* Call the routine */
Success = SynchronizeRoutine(SynchronizeContext); Success = SynchronizeRoutine(SynchronizeContext);
/* Release lock */ /* Release lock */
KeReleaseSpinLockFromDpcLevel(Interrupt->ActualLock); KeReleaseSpinLockFromDpcLevel(Interrupt->ActualLock);
/* Lower IRQL */ /* Lower IRQL */
KfLowerIrql(OldIrql); KfLowerIrql(OldIrql);
/* Return status */ /* Return status */
return Success; return Success;
} }

View file

@ -147,13 +147,13 @@ KiServiceExit(IN PKTRAP_FRAME TrapFrame,
{ {
ASSERT((TrapFrame->EFlags & EFLAGS_V86_MASK) == 0); ASSERT((TrapFrame->EFlags & EFLAGS_V86_MASK) == 0);
ASSERT(!KiIsFrameEdited(TrapFrame)); ASSERT(!KiIsFrameEdited(TrapFrame));
/* Copy the status into EAX */ /* Copy the status into EAX */
TrapFrame->Eax = Status; TrapFrame->Eax = Status;
/* Common trap exit code */ /* Common trap exit code */
KiCommonExit(TrapFrame, FALSE); KiCommonExit(TrapFrame, FALSE);
/* Restore previous mode */ /* Restore previous mode */
KeGetCurrentThread()->PreviousMode = (CCHAR)TrapFrame->PreviousPreviousMode; KeGetCurrentThread()->PreviousMode = (CCHAR)TrapFrame->PreviousPreviousMode;
@ -184,10 +184,10 @@ KiServiceExit2(IN PKTRAP_FRAME TrapFrame)
{ {
/* Common trap exit code */ /* Common trap exit code */
KiCommonExit(TrapFrame, FALSE); KiCommonExit(TrapFrame, FALSE);
/* Restore previous mode */ /* Restore previous mode */
KeGetCurrentThread()->PreviousMode = (CCHAR)TrapFrame->PreviousPreviousMode; KeGetCurrentThread()->PreviousMode = (CCHAR)TrapFrame->PreviousPreviousMode;
/* Check if this was a V8086 trap */ /* Check if this was a V8086 trap */
if (TrapFrame->EFlags & EFLAGS_V86_MASK) KiTrapReturnNoSegments(TrapFrame); if (TrapFrame->EFlags & EFLAGS_V86_MASK) KiTrapReturnNoSegments(TrapFrame);
@ -282,14 +282,14 @@ KiNpxHandler(IN PKTRAP_FRAME TrapFrame,
/* Clear the TS bit and re-enable interrupts */ /* Clear the TS bit and re-enable interrupts */
SaveArea->Cr0NpxState &= ~CR0_TS; SaveArea->Cr0NpxState &= ~CR0_TS;
_enable(); _enable();
/* Check if we should get the FN or FX error */ /* Check if we should get the FN or FX error */
if (KeI386FxsrPresent) if (KeI386FxsrPresent)
{ {
/* Get it from FX */ /* Get it from FX */
Mask = SaveArea->U.FxArea.ControlWord; Mask = SaveArea->U.FxArea.ControlWord;
Error = SaveArea->U.FxArea.StatusWord; Error = SaveArea->U.FxArea.StatusWord;
/* Get the FPU exception address too */ /* Get the FPU exception address too */
ErrorOffset = SaveArea->U.FxArea.ErrorOffset; ErrorOffset = SaveArea->U.FxArea.ErrorOffset;
DataOffset = SaveArea->U.FxArea.DataOffset; DataOffset = SaveArea->U.FxArea.DataOffset;
@ -299,7 +299,7 @@ KiNpxHandler(IN PKTRAP_FRAME TrapFrame,
/* Get it from FN */ /* Get it from FN */
Mask = SaveArea->U.FnArea.ControlWord; Mask = SaveArea->U.FnArea.ControlWord;
Error = SaveArea->U.FnArea.StatusWord; Error = SaveArea->U.FnArea.StatusWord;
/* Get the FPU exception address too */ /* Get the FPU exception address too */
ErrorOffset = SaveArea->U.FnArea.ErrorOffset; ErrorOffset = SaveArea->U.FnArea.ErrorOffset;
DataOffset = SaveArea->U.FnArea.DataOffset; DataOffset = SaveArea->U.FnArea.DataOffset;
@ -338,7 +338,7 @@ KiNpxHandler(IN PKTRAP_FRAME TrapFrame,
0, 0,
TrapFrame); TrapFrame);
} }
/* Check for divide by zero */ /* Check for divide by zero */
if (Error & FSW_ZERO_DIVIDE) if (Error & FSW_ZERO_DIVIDE)
{ {
@ -348,7 +348,7 @@ KiNpxHandler(IN PKTRAP_FRAME TrapFrame,
0, 0,
TrapFrame); TrapFrame);
} }
/* Check for denormal */ /* Check for denormal */
if (Error & FSW_DENORMAL) if (Error & FSW_DENORMAL)
{ {
@ -358,7 +358,7 @@ KiNpxHandler(IN PKTRAP_FRAME TrapFrame,
0, 0,
TrapFrame); TrapFrame);
} }
/* Check for overflow */ /* Check for overflow */
if (Error & FSW_OVERFLOW) if (Error & FSW_OVERFLOW)
{ {
@ -368,7 +368,7 @@ KiNpxHandler(IN PKTRAP_FRAME TrapFrame,
0, 0,
TrapFrame); TrapFrame);
} }
/* Check for underflow */ /* Check for underflow */
if (Error & FSW_UNDERFLOW) if (Error & FSW_UNDERFLOW)
{ {
@ -388,7 +388,7 @@ KiNpxHandler(IN PKTRAP_FRAME TrapFrame,
0, 0,
TrapFrame); TrapFrame);
} }
/* Unknown FPU fault */ /* Unknown FPU fault */
KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 1, Error, 0, 0, TrapFrame); KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 1, Error, 0, 0, TrapFrame);
} }
@ -400,13 +400,13 @@ KiTrap00Handler(IN PKTRAP_FRAME TrapFrame)
{ {
/* Save trap frame */ /* Save trap frame */
KiEnterTrap(TrapFrame); KiEnterTrap(TrapFrame);
/* Check for VDM trap */ /* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE); ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
/* Enable interrupts */ /* Enable interrupts */
_enable(); _enable();
/* Dispatch the exception */ /* Dispatch the exception */
KiDispatchException0Args(STATUS_INTEGER_DIVIDE_BY_ZERO, KiDispatchException0Args(STATUS_INTEGER_DIVIDE_BY_ZERO,
TrapFrame->Eip, TrapFrame->Eip,
@ -458,7 +458,7 @@ KiTrap02(VOID)
PKGDTENTRY TssGdt; PKGDTENTRY TssGdt;
KTRAP_FRAME TrapFrame; KTRAP_FRAME TrapFrame;
KIRQL OldIrql; KIRQL OldIrql;
// //
// In some sort of strange recursion case, we might end up here with the IF // In some sort of strange recursion case, we might end up here with the IF
// flag incorrectly on the interrupt frame -- during a normal NMI this would // flag incorrectly on the interrupt frame -- during a normal NMI this would
@ -475,14 +475,14 @@ KiTrap02(VOID)
Tss = PCR->TSS; Tss = PCR->TSS;
Thread = ((PKIPCR)PCR)->PrcbData.CurrentThread; Thread = ((PKIPCR)PCR)->PrcbData.CurrentThread;
Process = Thread->ApcState.Process; Process = Thread->ApcState.Process;
// //
// Save data usually not in the TSS // Save data usually not in the TSS
// //
Tss->CR3 = Process->DirectoryTableBase[0]; Tss->CR3 = Process->DirectoryTableBase[0];
Tss->IoMapBase = Process->IopmOffset; Tss->IoMapBase = Process->IopmOffset;
Tss->LDT = Process->LdtDescriptor.LimitLow ? KGDT_LDT : 0; Tss->LDT = Process->LdtDescriptor.LimitLow ? KGDT_LDT : 0;
// //
// Now get the base address of the NMI TSS // Now get the base address of the NMI TSS
// //
@ -490,7 +490,7 @@ KiTrap02(VOID)
NmiTss = (PKTSS)(ULONG_PTR)(TssGdt->BaseLow | NmiTss = (PKTSS)(ULONG_PTR)(TssGdt->BaseLow |
TssGdt->HighWord.Bytes.BaseMid << 16 | TssGdt->HighWord.Bytes.BaseMid << 16 |
TssGdt->HighWord.Bytes.BaseHi << 24); TssGdt->HighWord.Bytes.BaseHi << 24);
// //
// Switch to it and activate it, masking off the nested flag // Switch to it and activate it, masking off the nested flag
// //
@ -502,7 +502,7 @@ KiTrap02(VOID)
TssGdt->HighWord.Bits.Dpl = 0; TssGdt->HighWord.Bits.Dpl = 0;
TssGdt->HighWord.Bits.Pres = 1; TssGdt->HighWord.Bits.Pres = 1;
TssGdt->HighWord.Bits.Type = I386_TSS; TssGdt->HighWord.Bits.Type = I386_TSS;
// //
// Now build the trap frame based on the original TSS // Now build the trap frame based on the original TSS
// //
@ -532,12 +532,12 @@ KiTrap02(VOID)
TrapFrame.SegGs = Tss->Gs; TrapFrame.SegGs = Tss->Gs;
TrapFrame.DbgEip = Tss->Eip; TrapFrame.DbgEip = Tss->Eip;
TrapFrame.DbgEbp = Tss->Ebp; TrapFrame.DbgEbp = Tss->Ebp;
// //
// Store the trap frame in the KPRCB // Store the trap frame in the KPRCB
// //
KiSaveProcessorState(&TrapFrame, NULL); KiSaveProcessorState(&TrapFrame, NULL);
// //
// Call any registered NMI handlers and see if they handled it or not // Call any registered NMI handlers and see if they handled it or not
// //
@ -569,25 +569,25 @@ KiTrap02(VOID)
// Restore original TSS // Restore original TSS
// //
PCR->TSS = Tss; PCR->TSS = Tss;
// //
// Set it back to busy // Set it back to busy
// //
TssGdt->HighWord.Bits.Dpl = 0; TssGdt->HighWord.Bits.Dpl = 0;
TssGdt->HighWord.Bits.Pres = 1; TssGdt->HighWord.Bits.Pres = 1;
TssGdt->HighWord.Bits.Type = I386_ACTIVE_TSS; TssGdt->HighWord.Bits.Type = I386_ACTIVE_TSS;
// //
// Restore nested flag // Restore nested flag
// //
__writeeflags(__readeflags() | EFLAGS_NESTED_TASK); __writeeflags(__readeflags() | EFLAGS_NESTED_TASK);
// //
// Handled, return from interrupt // Handled, return from interrupt
// //
KiIret(); KiIret();
} }
// //
// Unhandled: crash the system // Unhandled: crash the system
// //
@ -601,7 +601,7 @@ KiTrap03Handler(IN PKTRAP_FRAME TrapFrame)
{ {
/* Save trap frame */ /* Save trap frame */
KiEnterTrap(TrapFrame); KiEnterTrap(TrapFrame);
/* Continue with the common handler */ /* Continue with the common handler */
KiDebugHandler(TrapFrame, BREAKPOINT_BREAK, 0, 0); KiDebugHandler(TrapFrame, BREAKPOINT_BREAK, 0, 0);
} }
@ -613,13 +613,13 @@ KiTrap04Handler(IN PKTRAP_FRAME TrapFrame)
{ {
/* Save trap frame */ /* Save trap frame */
KiEnterTrap(TrapFrame); KiEnterTrap(TrapFrame);
/* Check for VDM trap */ /* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE); ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
/* Enable interrupts */ /* Enable interrupts */
_enable(); _enable();
/* Dispatch the exception */ /* Dispatch the exception */
KiDispatchException0Args(STATUS_INTEGER_OVERFLOW, KiDispatchException0Args(STATUS_INTEGER_OVERFLOW,
TrapFrame->Eip - 1, TrapFrame->Eip - 1,
@ -633,16 +633,16 @@ KiTrap05Handler(IN PKTRAP_FRAME TrapFrame)
{ {
/* Save trap frame */ /* Save trap frame */
KiEnterTrap(TrapFrame); KiEnterTrap(TrapFrame);
/* Check for VDM trap */ /* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE); ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
/* Check for kernel-mode fault */ /* Check for kernel-mode fault */
if (!KiUserTrap(TrapFrame)) KiSystemFatalException(EXCEPTION_BOUND_CHECK, TrapFrame); if (!KiUserTrap(TrapFrame)) KiSystemFatalException(EXCEPTION_BOUND_CHECK, TrapFrame);
/* Enable interrupts */ /* Enable interrupts */
_enable(); _enable();
/* Dispatch the exception */ /* Dispatch the exception */
KiDispatchException0Args(STATUS_ARRAY_BOUNDS_EXCEEDED, KiDispatchException0Args(STATUS_ARRAY_BOUNDS_EXCEEDED,
TrapFrame->Eip, TrapFrame->Eip,
@ -657,56 +657,56 @@ KiTrap06Handler(IN PKTRAP_FRAME TrapFrame)
PUCHAR Instruction; PUCHAR Instruction;
ULONG i; ULONG i;
KIRQL OldIrql; KIRQL OldIrql;
/* Check for V86 GPF */ /* Check for V86 GPF */
if (__builtin_expect(KiV86Trap(TrapFrame), 1)) if (__builtin_expect(KiV86Trap(TrapFrame), 1))
{ {
/* Enter V86 trap */ /* Enter V86 trap */
KiEnterV86Trap(TrapFrame); KiEnterV86Trap(TrapFrame);
/* Must be a VDM process */ /* Must be a VDM process */
if (__builtin_expect(!PsGetCurrentProcess()->VdmObjects, 0)) if (__builtin_expect(!PsGetCurrentProcess()->VdmObjects, 0))
{ {
/* Enable interrupts */ /* Enable interrupts */
_enable(); _enable();
/* Setup illegal instruction fault */ /* Setup illegal instruction fault */
KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION, KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION,
TrapFrame->Eip, TrapFrame->Eip,
TrapFrame); TrapFrame);
} }
/* Go to APC level */ /* Go to APC level */
OldIrql = KfRaiseIrql(APC_LEVEL); OldIrql = KfRaiseIrql(APC_LEVEL);
_enable(); _enable();
/* Check for BOP */ /* Check for BOP */
if (!VdmDispatchBop(TrapFrame)) if (!VdmDispatchBop(TrapFrame))
{ {
/* Should only happen in VDM mode */ /* Should only happen in VDM mode */
UNIMPLEMENTED_FATAL(); UNIMPLEMENTED_FATAL();
} }
/* Bring IRQL back */ /* Bring IRQL back */
KfLowerIrql(OldIrql); KfLowerIrql(OldIrql);
_disable(); _disable();
/* Do a quick V86 exit if possible */ /* Do a quick V86 exit if possible */
KiExitV86Trap(TrapFrame); KiExitV86Trap(TrapFrame);
} }
/* Save trap frame */ /* Save trap frame */
KiEnterTrap(TrapFrame); KiEnterTrap(TrapFrame);
/* Enable interrupts */ /* Enable interrupts */
Instruction = (PUCHAR)TrapFrame->Eip; Instruction = (PUCHAR)TrapFrame->Eip;
_enable(); _enable();
/* Check for user trap */ /* Check for user trap */
if (KiUserTrap(TrapFrame)) if (KiUserTrap(TrapFrame))
{ {
/* FIXME: Use SEH */ /* FIXME: Use SEH */
/* Scan next 4 opcodes */ /* Scan next 4 opcodes */
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
@ -719,15 +719,15 @@ KiTrap06Handler(IN PKTRAP_FRAME TrapFrame)
TrapFrame); TrapFrame);
} }
} }
/* FIXME: SEH ends here */ /* FIXME: SEH ends here */
} }
/* Kernel-mode or user-mode fault (but not LOCK) */ /* Kernel-mode or user-mode fault (but not LOCK) */
KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION, KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION,
TrapFrame->Eip, TrapFrame->Eip,
TrapFrame); TrapFrame);
} }
DECLSPEC_NORETURN DECLSPEC_NORETURN
@ -738,7 +738,7 @@ KiTrap07Handler(IN PKTRAP_FRAME TrapFrame)
PKTHREAD Thread, NpxThread; PKTHREAD Thread, NpxThread;
PFX_SAVE_AREA SaveArea, NpxSaveArea; PFX_SAVE_AREA SaveArea, NpxSaveArea;
ULONG Cr0; ULONG Cr0;
/* Save trap frame */ /* Save trap frame */
KiEnterTrap(TrapFrame); KiEnterTrap(TrapFrame);
@ -757,7 +757,7 @@ KiTrap07Handler(IN PKTRAP_FRAME TrapFrame)
/* Not implemented */ /* Not implemented */
UNIMPLEMENTED_FATAL(); UNIMPLEMENTED_FATAL();
} }
/* Save CR0 and check NPX state */ /* Save CR0 and check NPX state */
Cr0 = __readcr0(); Cr0 = __readcr0();
if (Thread->NpxState != NPX_STATE_LOADED) if (Thread->NpxState != NPX_STATE_LOADED)
@ -765,14 +765,14 @@ KiTrap07Handler(IN PKTRAP_FRAME TrapFrame)
/* Update CR0 */ /* Update CR0 */
Cr0 &= ~(CR0_MP | CR0_EM | CR0_TS); Cr0 &= ~(CR0_MP | CR0_EM | CR0_TS);
__writecr0(Cr0); __writecr0(Cr0);
/* Get the NPX thread */ /* Get the NPX thread */
NpxThread = KeGetCurrentPrcb()->NpxThread; NpxThread = KeGetCurrentPrcb()->NpxThread;
if (NpxThread) if (NpxThread)
{ {
/* Get the NPX frame */ /* Get the NPX frame */
NpxSaveArea = KiGetThreadNpxArea(NpxThread); NpxSaveArea = KiGetThreadNpxArea(NpxThread);
/* Save FPU state */ /* Save FPU state */
DPRINT("FIXME: Save FPU state: %p\n", NpxSaveArea); DPRINT("FIXME: Save FPU state: %p\n", NpxSaveArea);
//Ke386SaveFpuState(NpxSaveArea); //Ke386SaveFpuState(NpxSaveArea);
@ -780,32 +780,32 @@ KiTrap07Handler(IN PKTRAP_FRAME TrapFrame)
/* Update NPX state */ /* Update NPX state */
NpxThread->NpxState = NPX_STATE_NOT_LOADED; NpxThread->NpxState = NPX_STATE_NOT_LOADED;
} }
/* Load FPU state */ /* Load FPU state */
//Ke386LoadFpuState(SaveArea); //Ke386LoadFpuState(SaveArea);
/* Update NPX state */ /* Update NPX state */
Thread->NpxState = NPX_STATE_LOADED; Thread->NpxState = NPX_STATE_LOADED;
KeGetCurrentPrcb()->NpxThread = Thread; KeGetCurrentPrcb()->NpxThread = Thread;
/* Enable interrupts */ /* Enable interrupts */
_enable(); _enable();
/* Check if CR0 needs to be reloaded due to context switch */ /* Check if CR0 needs to be reloaded due to context switch */
if (!SaveArea->Cr0NpxState) KiEoiHelper(TrapFrame); if (!SaveArea->Cr0NpxState) KiEoiHelper(TrapFrame);
/* Otherwise, we need to reload CR0, disable interrupts */ /* Otherwise, we need to reload CR0, disable interrupts */
_disable(); _disable();
/* Reload CR0 */ /* Reload CR0 */
Cr0 = __readcr0(); Cr0 = __readcr0();
Cr0 |= SaveArea->Cr0NpxState; Cr0 |= SaveArea->Cr0NpxState;
__writecr0(Cr0); __writecr0(Cr0);
/* Now restore interrupts and check for TS */ /* Now restore interrupts and check for TS */
_enable(); _enable();
if (Cr0 & CR0_TS) KiEoiHelper(TrapFrame); if (Cr0 & CR0_TS) KiEoiHelper(TrapFrame);
/* We're still here -- clear TS and try again */ /* We're still here -- clear TS and try again */
__writecr0(__readcr0() &~ CR0_TS); __writecr0(__readcr0() &~ CR0_TS);
_disable(); _disable();
@ -816,7 +816,7 @@ KiTrap07Handler(IN PKTRAP_FRAME TrapFrame)
break; break;
} }
} }
/* TS should not be set */ /* TS should not be set */
if (Cr0 & CR0_TS) if (Cr0 & CR0_TS)
{ {
@ -831,11 +831,11 @@ KiTrap07Handler(IN PKTRAP_FRAME TrapFrame)
__writecr0(__readcr0() &~ CR0_TS); __writecr0(__readcr0() &~ CR0_TS);
KiEoiHelper(TrapFrame); KiEoiHelper(TrapFrame);
} }
/* Otherwise, something strange is going on */ /* Otherwise, something strange is going on */
KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 2, Cr0, 0, 0, TrapFrame); KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 2, Cr0, 0, 0, TrapFrame);
} }
/* It's not a delayed load, so process this trap as an NPX fault */ /* It's not a delayed load, so process this trap as an NPX fault */
KiNpxHandler(TrapFrame, Thread, SaveArea); KiNpxHandler(TrapFrame, Thread, SaveArea);
} }
@ -913,44 +913,44 @@ KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame)
PUCHAR Instructions; PUCHAR Instructions;
UCHAR Instruction = 0; UCHAR Instruction = 0;
KIRQL OldIrql; KIRQL OldIrql;
/* Check for V86 GPF */ /* Check for V86 GPF */
if (__builtin_expect(KiV86Trap(TrapFrame), 1)) if (__builtin_expect(KiV86Trap(TrapFrame), 1))
{ {
/* Enter V86 trap */ /* Enter V86 trap */
KiEnterV86Trap(TrapFrame); KiEnterV86Trap(TrapFrame);
/* Must be a VDM process */ /* Must be a VDM process */
if (__builtin_expect(!PsGetCurrentProcess()->VdmObjects, 0)) if (__builtin_expect(!PsGetCurrentProcess()->VdmObjects, 0))
{ {
/* Enable interrupts */ /* Enable interrupts */
_enable(); _enable();
/* Setup illegal instruction fault */ /* Setup illegal instruction fault */
KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION, KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION,
TrapFrame->Eip, TrapFrame->Eip,
TrapFrame); TrapFrame);
} }
/* Go to APC level */ /* Go to APC level */
OldIrql = KfRaiseIrql(APC_LEVEL); OldIrql = KfRaiseIrql(APC_LEVEL);
_enable(); _enable();
/* Handle the V86 opcode */ /* Handle the V86 opcode */
if (__builtin_expect(Ki386HandleOpcodeV86(TrapFrame) == 0xFF, 0)) if (__builtin_expect(Ki386HandleOpcodeV86(TrapFrame) == 0xFF, 0))
{ {
/* Should only happen in VDM mode */ /* Should only happen in VDM mode */
UNIMPLEMENTED_FATAL(); UNIMPLEMENTED_FATAL();
} }
/* Bring IRQL back */ /* Bring IRQL back */
KfLowerIrql(OldIrql); KfLowerIrql(OldIrql);
_disable(); _disable();
/* Do a quick V86 exit if possible */ /* Do a quick V86 exit if possible */
KiExitV86Trap(TrapFrame); KiExitV86Trap(TrapFrame);
} }
/* Save trap frame */ /* Save trap frame */
KiEnterTrap(TrapFrame); KiEnterTrap(TrapFrame);
@ -959,14 +959,14 @@ KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame)
{ {
/* Should not be VDM */ /* Should not be VDM */
ASSERT(KiVdmTrap(TrapFrame) == FALSE); ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Enable interrupts and check error code */ /* Enable interrupts and check error code */
_enable(); _enable();
if (!TrapFrame->ErrCode) if (!TrapFrame->ErrCode)
{ {
/* FIXME: Use SEH */ /* FIXME: Use SEH */
Instructions = (PUCHAR)TrapFrame->Eip; Instructions = (PUCHAR)TrapFrame->Eip;
/* Scan next 15 bytes */ /* Scan next 15 bytes */
for (i = 0; i < 15; i++) for (i = 0; i < 15; i++)
{ {
@ -980,7 +980,7 @@ KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame)
break; break;
} }
} }
/* Is this NOT any prefix instruction? */ /* Is this NOT any prefix instruction? */
if (j == sizeof(KiTrapPrefixTable)) if (j == sizeof(KiTrapPrefixTable))
{ {
@ -989,7 +989,7 @@ KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame)
break; break;
} }
} }
/* If all we found was prefixes, then this instruction is too long */ /* If all we found was prefixes, then this instruction is too long */
if (i == 15) if (i == 15)
{ {
@ -998,7 +998,7 @@ KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame)
TrapFrame->Eip, TrapFrame->Eip,
TrapFrame); TrapFrame);
} }
/* Check for privileged instructions */ /* Check for privileged instructions */
DPRINT("Instruction (%lu) at fault: %lx %lx %lx %lx\n", DPRINT("Instruction (%lu) at fault: %lx %lx %lx %lx\n",
i, i,
@ -1065,7 +1065,7 @@ KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame)
} }
} }
} }
/* So now... was the instruction privileged or not? */ /* So now... was the instruction privileged or not? */
if (Privileged) if (Privileged)
{ {
@ -1075,7 +1075,7 @@ KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame)
TrapFrame); TrapFrame);
} }
} }
/* If we got here, send an access violation */ /* If we got here, send an access violation */
KiDispatchException2Args(STATUS_ACCESS_VIOLATION, KiDispatchException2Args(STATUS_ACCESS_VIOLATION,
TrapFrame->Eip, TrapFrame->Eip,
@ -1123,7 +1123,7 @@ KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame)
* when the user is purposedly trying to create one from kernel-mode, so * when the user is purposedly trying to create one from kernel-mode, so
* we should probably table this for now since it's not a "real" issue. * we should probably table this for now since it's not a "real" issue.
*/ */
/* /*
* NOTE2: Another scenario is the IRET during a V8086 restore (BIOS Call) * NOTE2: Another scenario is the IRET during a V8086 restore (BIOS Call)
* which will cause a GPF since the trap frame is a total mess (on purpose) * which will cause a GPF since the trap frame is a total mess (on purpose)
@ -1153,7 +1153,7 @@ KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame)
UNIMPLEMENTED_FATAL(); UNIMPLEMENTED_FATAL();
} }
} }
/* So since we're not dealing with the above case, check for RDMSR/WRMSR */ /* So since we're not dealing with the above case, check for RDMSR/WRMSR */
if ((Instructions[0] == 0xF) && // 2-byte opcode if ((Instructions[0] == 0xF) && // 2-byte opcode
((Instructions[1] == 0x32) || // RDMSR ((Instructions[1] == 0x32) || // RDMSR
@ -1181,7 +1181,7 @@ KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame)
/* Whatever it is, we can't handle it */ /* Whatever it is, we can't handle it */
KiSystemFatalException(EXCEPTION_GP_FAULT, TrapFrame); KiSystemFatalException(EXCEPTION_GP_FAULT, TrapFrame);
} }
/* Return to where we came from */ /* Return to where we came from */
KiTrapReturn(TrapFrame); KiTrapReturn(TrapFrame);
} }
@ -1287,7 +1287,7 @@ KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame)
#endif #endif
/* Check for VDM trap */ /* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE); ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
/* Either kernel or user trap (non VDM) so dispatch exception */ /* Either kernel or user trap (non VDM) so dispatch exception */
if (Status == STATUS_ACCESS_VIOLATION) if (Status == STATUS_ACCESS_VIOLATION)
{ {
@ -1308,7 +1308,7 @@ KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame)
Cr2, Cr2,
TrapFrame); TrapFrame);
} }
/* Only other choice is an in-page error, with 3 parameters */ /* Only other choice is an in-page error, with 3 parameters */
KiDispatchExceptionFromTrapFrame(STATUS_IN_PAGE_ERROR, KiDispatchExceptionFromTrapFrame(STATUS_IN_PAGE_ERROR,
TrapFrame->Eip, TrapFrame->Eip,
@ -1339,7 +1339,7 @@ KiTrap10Handler(IN PKTRAP_FRAME TrapFrame)
{ {
PKTHREAD Thread; PKTHREAD Thread;
PFX_SAVE_AREA SaveArea; PFX_SAVE_AREA SaveArea;
/* Save trap frame */ /* Save trap frame */
KiEnterTrap(TrapFrame); KiEnterTrap(TrapFrame);
@ -1351,11 +1351,11 @@ KiTrap10Handler(IN PKTRAP_FRAME TrapFrame)
/* It isn't, enable interrupts and set delayed error */ /* It isn't, enable interrupts and set delayed error */
_enable(); _enable();
SaveArea->Cr0NpxState |= CR0_TS; SaveArea->Cr0NpxState |= CR0_TS;
/* End trap */ /* End trap */
KiEoiHelper(TrapFrame); KiEoiHelper(TrapFrame);
} }
/* Otherwise, proceed with NPX fault handling */ /* Otherwise, proceed with NPX fault handling */
KiNpxHandler(TrapFrame, Thread, SaveArea); KiNpxHandler(TrapFrame, Thread, SaveArea);
} }
@ -1381,7 +1381,7 @@ KiTrap13Handler(IN PKTRAP_FRAME TrapFrame)
PKTHREAD Thread; PKTHREAD Thread;
PFX_SAVE_AREA SaveArea; PFX_SAVE_AREA SaveArea;
ULONG Cr0, MxCsrMask, Error; ULONG Cr0, MxCsrMask, Error;
/* Save trap frame */ /* Save trap frame */
KiEnterTrap(TrapFrame); KiEnterTrap(TrapFrame);
@ -1405,31 +1405,31 @@ KiTrap13Handler(IN PKTRAP_FRAME TrapFrame)
/* Kernel should not fault on XMMI */ /* Kernel should not fault on XMMI */
KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 13, 0, 0, 2, TrapFrame); KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 13, 0, 0, 2, TrapFrame);
} }
/* Update CR0 */ /* Update CR0 */
Cr0 = __readcr0(); Cr0 = __readcr0();
Cr0 &= ~(CR0_MP | CR0_EM | CR0_TS); Cr0 &= ~(CR0_MP | CR0_EM | CR0_TS);
__writecr0(Cr0); __writecr0(Cr0);
/* Save FPU state */ /* Save FPU state */
Ke386SaveFpuState(SaveArea); Ke386SaveFpuState(SaveArea);
/* Mark CR0 state dirty */ /* Mark CR0 state dirty */
Cr0 |= NPX_STATE_NOT_LOADED; Cr0 |= NPX_STATE_NOT_LOADED;
Cr0 |= SaveArea->Cr0NpxState; Cr0 |= SaveArea->Cr0NpxState;
__writecr0(Cr0); __writecr0(Cr0);
/* Update NPX state */ /* Update NPX state */
Thread->NpxState = NPX_STATE_NOT_LOADED; Thread->NpxState = NPX_STATE_NOT_LOADED;
KeGetCurrentPrcb()->NpxThread = NULL; KeGetCurrentPrcb()->NpxThread = NULL;
/* Clear the TS bit and re-enable interrupts */ /* Clear the TS bit and re-enable interrupts */
SaveArea->Cr0NpxState &= ~CR0_TS; SaveArea->Cr0NpxState &= ~CR0_TS;
_enable(); _enable();
/* Now look at MxCsr to get the mask of errors we should care about */ /* Now look at MxCsr to get the mask of errors we should care about */
MxCsrMask = ~((USHORT)SaveArea->U.FxArea.MXCsr >> 7); MxCsrMask = ~((USHORT)SaveArea->U.FxArea.MXCsr >> 7);
/* Get legal exceptions that software should handle */ /* Get legal exceptions that software should handle */
Error = (USHORT)SaveArea->U.FxArea.MXCsr & (FSW_INVALID_OPERATION | Error = (USHORT)SaveArea->U.FxArea.MXCsr & (FSW_INVALID_OPERATION |
FSW_DENORMAL | FSW_DENORMAL |
@ -1453,7 +1453,7 @@ KiTrap13Handler(IN PKTRAP_FRAME TrapFrame)
0, 0,
TrapFrame); TrapFrame);
} }
/* Unknown XMMI fault */ /* Unknown XMMI fault */
KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 13, 0, 0, 1, TrapFrame); KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 13, 0, 0, 1, TrapFrame);
} }
@ -1507,10 +1507,10 @@ KiDebugServiceHandler(IN PKTRAP_FRAME TrapFrame)
{ {
/* Save trap frame */ /* Save trap frame */
KiEnterTrap(TrapFrame); KiEnterTrap(TrapFrame);
/* Increment EIP to skip the INT3 instruction */ /* Increment EIP to skip the INT3 instruction */
TrapFrame->Eip++; TrapFrame->Eip++;
/* Continue with the common handler */ /* Continue with the common handler */
KiDebugHandler(TrapFrame, TrapFrame->Eax, TrapFrame->Ecx, TrapFrame->Edx); KiDebugHandler(TrapFrame, TrapFrame->Eax, TrapFrame->Ecx, TrapFrame->Edx);
} }
@ -1548,7 +1548,7 @@ KiSystemServiceHandler(IN PKTRAP_FRAME TrapFrame,
ULONG Id, Offset, StackBytes, Result; ULONG Id, Offset, StackBytes, Result;
PVOID Handler; PVOID Handler;
ULONG SystemCallNumber = TrapFrame->Eax; ULONG SystemCallNumber = TrapFrame->Eax;
/* Get the current thread */ /* Get the current thread */
Thread = KeGetCurrentThread(); Thread = KeGetCurrentThread();
@ -1629,43 +1629,43 @@ KiSystemServiceHandler(IN PKTRAP_FRAME TrapFrame,
goto ExitCall; goto ExitCall;
} }
} }
/* Check if this is a GUI call */ /* Check if this is a GUI call */
if (__builtin_expect(Offset & SERVICE_TABLE_TEST, 0)) if (__builtin_expect(Offset & SERVICE_TABLE_TEST, 0))
{ {
/* Get the batch count and flush if necessary */ /* Get the batch count and flush if necessary */
if (NtCurrentTeb()->GdiBatchCount) KeGdiFlushUserBatch(); if (NtCurrentTeb()->GdiBatchCount) KeGdiFlushUserBatch();
} }
/* Increase system call count */ /* Increase system call count */
KeGetCurrentPrcb()->KeSystemCalls++; KeGetCurrentPrcb()->KeSystemCalls++;
/* FIXME: Increase individual counts on debug systems */ /* FIXME: Increase individual counts on debug systems */
//KiIncreaseSystemCallCount(DescriptorTable, Id); //KiIncreaseSystemCallCount(DescriptorTable, Id);
/* Get stack bytes */ /* Get stack bytes */
StackBytes = DescriptorTable->Number[Id]; StackBytes = DescriptorTable->Number[Id];
/* Probe caller stack */ /* Probe caller stack */
if (__builtin_expect((Arguments < (PVOID)MmUserProbeAddress) && !(KiUserTrap(TrapFrame)), 0)) if (__builtin_expect((Arguments < (PVOID)MmUserProbeAddress) && !(KiUserTrap(TrapFrame)), 0))
{ {
/* Access violation */ /* Access violation */
UNIMPLEMENTED_FATAL(); UNIMPLEMENTED_FATAL();
} }
/* Call pre-service debug hook */ /* Call pre-service debug hook */
KiDbgPreServiceHook(SystemCallNumber, Arguments); KiDbgPreServiceHook(SystemCallNumber, Arguments);
/* Get the handler and make the system call */ /* Get the handler and make the system call */
Handler = (PVOID)DescriptorTable->Base[Id]; Handler = (PVOID)DescriptorTable->Base[Id];
Result = KiSystemCallTrampoline(Handler, Arguments, StackBytes); Result = KiSystemCallTrampoline(Handler, Arguments, StackBytes);
/* Call post-service debug hook */ /* Call post-service debug hook */
Result = KiDbgPostServiceHook(SystemCallNumber, Result); Result = KiDbgPostServiceHook(SystemCallNumber, Result);
/* Make sure we're exiting correctly */ /* Make sure we're exiting correctly */
KiExitSystemCallDebugChecks(Id, TrapFrame); KiExitSystemCallDebugChecks(Id, TrapFrame);
/* Restore the old trap frame */ /* Restore the old trap frame */
ExitCall: ExitCall:
Thread->TrapFrame = (PKTRAP_FRAME)TrapFrame->Edx; Thread->TrapFrame = (PKTRAP_FRAME)TrapFrame->Edx;