_disable();
HalEndSystemInterrupt(OldIrql, TrapFrame);
}
-
+
/* Now exit the trap */
KiEoiHelper(TrapFrame);
}
/* Crash the machine */
KeBugCheck(TRAP_CAUSE_UNKNOWN);
}
-
+
VOID
FASTCALL
KiUnexpectedInterruptTailHandler(IN PKTRAP_FRAME TrapFrame)
{
KIRQL OldIrql;
-
+
/* Enter trap */
KiEnterInterruptTrap(TrapFrame);
-
+
/* Increase interrupt count */
KeGetCurrentPrcb()->InterruptCount++;
-
+
/* Start the interrupt */
if (HalBeginSystemInterrupt(HIGH_LEVEL, TrapFrame->ErrCode, &OldIrql))
{
/* Warn user */
DPRINT1("\n\x7\x7!!! Unexpected Interrupt 0x%02lx !!!\n", TrapFrame->ErrCode);
-
+
/* Now call the epilogue code */
KiExitInterrupt(TrapFrame, OldIrql, FALSE);
}
FASTCALL
KiInterruptDispatch(IN PKTRAP_FRAME TrapFrame,
IN PKINTERRUPT Interrupt)
-{
+{
KIRQL OldIrql;
/* Increase interrupt count */
KeGetCurrentPrcb()->InterruptCount++;
-
+
/* Begin the interrupt, making sure it's not spurious */
if (HalBeginSystemInterrupt(Interrupt->SynchronizeIrql,
Interrupt->Vector,
{
/* Acquire interrupt lock */
KxAcquireSpinLock(Interrupt->ActualLock);
-
+
/* Call the ISR */
Interrupt->ServiceRoutine(Interrupt, Interrupt->ServiceContext);
-
+
/* Release interrupt lock */
KxReleaseSpinLock(Interrupt->ActualLock);
-
+
/* Now call the epilogue code */
KiExitInterrupt(TrapFrame, OldIrql, FALSE);
}
/* Raise to higher IRQL */
OldInterruptIrql = KfRaiseIrql(Interrupt->SynchronizeIrql);
}
-
+
/* Acquire interrupt lock */
KxAcquireSpinLock(Interrupt->ActualLock);
/* Release interrupt lock */
KxReleaseSpinLock(Interrupt->ActualLock);
-
+
/* Check if this interrupt's IRQL is higher than the current one */
if (Interrupt->SynchronizeIrql > Interrupt->Irql)
{
ASSERT(OldInterruptIrql == Interrupt->Irql);
KfLowerIrql(OldInterruptIrql);
}
-
+
/* Check if the interrupt got handled and it's level */
if ((Handled) && (Interrupt->Mode == LevelSensitive)) break;
-
+
/* What's next? */
NextEntry = NextEntry->Flink;
-
+
/* Is this the last one? */
if (NextEntry == ListHead)
{
/* Level should not have gotten here */
if (Interrupt->Mode == LevelSensitive) break;
-
+
/* As for edge, we can only exit once nobody can handle the interrupt */
if (!Handled) break;
}
-
+
/* Get the interrupt object for the next pass */
Interrupt = CONTAINING_RECORD(NextEntry, KINTERRUPT, InterruptListEntry);
}
{
BOOLEAN Success;
KIRQL OldIrql;
-
+
/* Raise IRQL */
OldIrql = KfRaiseIrql(Interrupt->SynchronizeIrql);
-
+
/* Acquire interrupt spinlock */
KeAcquireSpinLockAtDpcLevel(Interrupt->ActualLock);
-
+
/* Call the routine */
Success = SynchronizeRoutine(SynchronizeContext);
-
+
/* Release lock */
KeReleaseSpinLockFromDpcLevel(Interrupt->ActualLock);
-
+
/* Lower IRQL */
KfLowerIrql(OldIrql);
-
+
/* Return status */
return Success;
}
{
ASSERT((TrapFrame->EFlags & EFLAGS_V86_MASK) == 0);
ASSERT(!KiIsFrameEdited(TrapFrame));
-
+
/* Copy the status into EAX */
TrapFrame->Eax = Status;
-
+
/* Common trap exit code */
KiCommonExit(TrapFrame, FALSE);
-
+
/* Restore previous mode */
KeGetCurrentThread()->PreviousMode = (CCHAR)TrapFrame->PreviousPreviousMode;
{
/* Common trap exit code */
KiCommonExit(TrapFrame, FALSE);
-
+
/* Restore previous mode */
KeGetCurrentThread()->PreviousMode = (CCHAR)TrapFrame->PreviousPreviousMode;
-
+
/* Check if this was a V8086 trap */
if (TrapFrame->EFlags & EFLAGS_V86_MASK) KiTrapReturnNoSegments(TrapFrame);
/* Clear the TS bit and re-enable interrupts */
SaveArea->Cr0NpxState &= ~CR0_TS;
_enable();
-
+
/* Check if we should get the FN or FX error */
if (KeI386FxsrPresent)
{
/* Get it from FX */
Mask = SaveArea->U.FxArea.ControlWord;
Error = SaveArea->U.FxArea.StatusWord;
-
+
/* Get the FPU exception address too */
ErrorOffset = SaveArea->U.FxArea.ErrorOffset;
DataOffset = SaveArea->U.FxArea.DataOffset;
/* Get it from FN */
Mask = SaveArea->U.FnArea.ControlWord;
Error = SaveArea->U.FnArea.StatusWord;
-
+
/* Get the FPU exception address too */
ErrorOffset = SaveArea->U.FnArea.ErrorOffset;
DataOffset = SaveArea->U.FnArea.DataOffset;
0,
TrapFrame);
}
-
+
/* Check for divide by zero */
if (Error & FSW_ZERO_DIVIDE)
{
0,
TrapFrame);
}
-
+
/* Check for denormal */
if (Error & FSW_DENORMAL)
{
0,
TrapFrame);
}
-
+
/* Check for overflow */
if (Error & FSW_OVERFLOW)
{
0,
TrapFrame);
}
-
+
/* Check for underflow */
if (Error & FSW_UNDERFLOW)
{
0,
TrapFrame);
}
-
+
/* Unknown FPU fault */
KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 1, Error, 0, 0, TrapFrame);
}
{
/* Save trap frame */
KiEnterTrap(TrapFrame);
-
+
/* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
/* Enable interrupts */
_enable();
-
+
/* Dispatch the exception */
KiDispatchException0Args(STATUS_INTEGER_DIVIDE_BY_ZERO,
TrapFrame->Eip,
PKGDTENTRY TssGdt;
KTRAP_FRAME TrapFrame;
KIRQL OldIrql;
-
+
//
// 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
Tss = PCR->TSS;
Thread = ((PKIPCR)PCR)->PrcbData.CurrentThread;
Process = Thread->ApcState.Process;
-
+
//
// Save data usually not in the TSS
//
Tss->CR3 = Process->DirectoryTableBase[0];
Tss->IoMapBase = Process->IopmOffset;
Tss->LDT = Process->LdtDescriptor.LimitLow ? KGDT_LDT : 0;
-
+
//
// Now get the base address of the NMI TSS
//
NmiTss = (PKTSS)(ULONG_PTR)(TssGdt->BaseLow |
TssGdt->HighWord.Bytes.BaseMid << 16 |
TssGdt->HighWord.Bytes.BaseHi << 24);
-
+
//
// Switch to it and activate it, masking off the nested flag
//
TssGdt->HighWord.Bits.Dpl = 0;
TssGdt->HighWord.Bits.Pres = 1;
TssGdt->HighWord.Bits.Type = I386_TSS;
-
+
//
// Now build the trap frame based on the original TSS
//
TrapFrame.SegGs = Tss->Gs;
TrapFrame.DbgEip = Tss->Eip;
TrapFrame.DbgEbp = Tss->Ebp;
-
+
//
// Store the trap frame in the KPRCB
//
KiSaveProcessorState(&TrapFrame, NULL);
-
+
//
// Call any registered NMI handlers and see if they handled it or not
//
// Restore original TSS
//
PCR->TSS = Tss;
-
+
//
// Set it back to busy
//
TssGdt->HighWord.Bits.Dpl = 0;
TssGdt->HighWord.Bits.Pres = 1;
TssGdt->HighWord.Bits.Type = I386_ACTIVE_TSS;
-
+
//
// Restore nested flag
//
__writeeflags(__readeflags() | EFLAGS_NESTED_TASK);
-
+
//
// Handled, return from interrupt
//
KiIret();
}
-
+
//
// Unhandled: crash the system
//
{
/* Save trap frame */
KiEnterTrap(TrapFrame);
-
+
/* Continue with the common handler */
KiDebugHandler(TrapFrame, BREAKPOINT_BREAK, 0, 0);
}
{
/* Save trap frame */
KiEnterTrap(TrapFrame);
-
+
/* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
/* Enable interrupts */
_enable();
-
+
/* Dispatch the exception */
KiDispatchException0Args(STATUS_INTEGER_OVERFLOW,
TrapFrame->Eip - 1,
{
/* Save trap frame */
KiEnterTrap(TrapFrame);
-
+
/* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
-
+
/* Check for kernel-mode fault */
if (!KiUserTrap(TrapFrame)) KiSystemFatalException(EXCEPTION_BOUND_CHECK, TrapFrame);
/* Enable interrupts */
_enable();
-
+
/* Dispatch the exception */
KiDispatchException0Args(STATUS_ARRAY_BOUNDS_EXCEEDED,
TrapFrame->Eip,
PUCHAR Instruction;
ULONG i;
KIRQL OldIrql;
-
+
/* Check for V86 GPF */
if (__builtin_expect(KiV86Trap(TrapFrame), 1))
{
/* Enter V86 trap */
KiEnterV86Trap(TrapFrame);
-
+
/* Must be a VDM process */
if (__builtin_expect(!PsGetCurrentProcess()->VdmObjects, 0))
{
/* Enable interrupts */
_enable();
-
+
/* Setup illegal instruction fault */
KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION,
TrapFrame->Eip,
TrapFrame);
}
-
+
/* Go to APC level */
OldIrql = KfRaiseIrql(APC_LEVEL);
_enable();
-
+
/* Check for BOP */
if (!VdmDispatchBop(TrapFrame))
{
/* Should only happen in VDM mode */
UNIMPLEMENTED_FATAL();
}
-
+
/* Bring IRQL back */
KfLowerIrql(OldIrql);
_disable();
-
+
/* Do a quick V86 exit if possible */
KiExitV86Trap(TrapFrame);
}
/* Save trap frame */
KiEnterTrap(TrapFrame);
-
+
/* Enable interrupts */
Instruction = (PUCHAR)TrapFrame->Eip;
_enable();
-
+
/* Check for user trap */
if (KiUserTrap(TrapFrame))
{
/* FIXME: Use SEH */
-
+
/* Scan next 4 opcodes */
for (i = 0; i < 4; i++)
{
TrapFrame);
}
}
-
+
/* FIXME: SEH ends here */
}
-
+
/* Kernel-mode or user-mode fault (but not LOCK) */
KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION,
TrapFrame->Eip,
TrapFrame);
-
+
}
DECLSPEC_NORETURN
PKTHREAD Thread, NpxThread;
PFX_SAVE_AREA SaveArea, NpxSaveArea;
ULONG Cr0;
-
+
/* Save trap frame */
KiEnterTrap(TrapFrame);
/* Not implemented */
UNIMPLEMENTED_FATAL();
}
-
+
/* Save CR0 and check NPX state */
Cr0 = __readcr0();
if (Thread->NpxState != NPX_STATE_LOADED)
/* Update CR0 */
Cr0 &= ~(CR0_MP | CR0_EM | CR0_TS);
__writecr0(Cr0);
-
+
/* Get the NPX thread */
NpxThread = KeGetCurrentPrcb()->NpxThread;
if (NpxThread)
{
/* Get the NPX frame */
NpxSaveArea = KiGetThreadNpxArea(NpxThread);
-
+
/* Save FPU state */
DPRINT("FIXME: Save FPU state: %p\n", NpxSaveArea);
//Ke386SaveFpuState(NpxSaveArea);
/* Update NPX state */
NpxThread->NpxState = NPX_STATE_NOT_LOADED;
}
-
+
/* Load FPU state */
//Ke386LoadFpuState(SaveArea);
-
+
/* Update NPX state */
Thread->NpxState = NPX_STATE_LOADED;
KeGetCurrentPrcb()->NpxThread = Thread;
-
+
/* Enable interrupts */
_enable();
-
+
/* Check if CR0 needs to be reloaded due to context switch */
if (!SaveArea->Cr0NpxState) KiEoiHelper(TrapFrame);
-
+
/* Otherwise, we need to reload CR0, disable interrupts */
_disable();
-
+
/* Reload CR0 */
Cr0 = __readcr0();
Cr0 |= SaveArea->Cr0NpxState;
__writecr0(Cr0);
-
+
/* Now restore interrupts and check for TS */
_enable();
if (Cr0 & CR0_TS) KiEoiHelper(TrapFrame);
-
+
/* We're still here -- clear TS and try again */
__writecr0(__readcr0() &~ CR0_TS);
_disable();
break;
}
}
-
+
/* TS should not be set */
if (Cr0 & CR0_TS)
{
__writecr0(__readcr0() &~ CR0_TS);
KiEoiHelper(TrapFrame);
}
-
+
/* Otherwise, something strange is going on */
KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 2, Cr0, 0, 0, TrapFrame);
}
-
+
/* It's not a delayed load, so process this trap as an NPX fault */
KiNpxHandler(TrapFrame, Thread, SaveArea);
}
PUCHAR Instructions;
UCHAR Instruction = 0;
KIRQL OldIrql;
-
+
/* Check for V86 GPF */
if (__builtin_expect(KiV86Trap(TrapFrame), 1))
{
/* Enter V86 trap */
KiEnterV86Trap(TrapFrame);
-
+
/* Must be a VDM process */
if (__builtin_expect(!PsGetCurrentProcess()->VdmObjects, 0))
{
/* Enable interrupts */
_enable();
-
+
/* Setup illegal instruction fault */
KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION,
TrapFrame->Eip,
TrapFrame);
}
-
+
/* Go to APC level */
OldIrql = KfRaiseIrql(APC_LEVEL);
_enable();
-
+
/* Handle the V86 opcode */
if (__builtin_expect(Ki386HandleOpcodeV86(TrapFrame) == 0xFF, 0))
{
/* Should only happen in VDM mode */
UNIMPLEMENTED_FATAL();
}
-
+
/* Bring IRQL back */
KfLowerIrql(OldIrql);
_disable();
-
+
/* Do a quick V86 exit if possible */
KiExitV86Trap(TrapFrame);
}
-
+
/* Save trap frame */
KiEnterTrap(TrapFrame);
{
/* Should not be VDM */
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
-
+
/* Enable interrupts and check error code */
_enable();
if (!TrapFrame->ErrCode)
{
/* FIXME: Use SEH */
Instructions = (PUCHAR)TrapFrame->Eip;
-
+
/* Scan next 15 bytes */
for (i = 0; i < 15; i++)
{
break;
}
}
-
+
/* Is this NOT any prefix instruction? */
if (j == sizeof(KiTrapPrefixTable))
{
break;
}
}
-
+
/* If all we found was prefixes, then this instruction is too long */
if (i == 15)
{
TrapFrame->Eip,
TrapFrame);
}
-
+
/* Check for privileged instructions */
DPRINT("Instruction (%lu) at fault: %lx %lx %lx %lx\n",
i,
}
}
}
-
+
/* So now... was the instruction privileged or not? */
if (Privileged)
{
TrapFrame);
}
}
-
+
/* If we got here, send an access violation */
KiDispatchException2Args(STATUS_ACCESS_VIOLATION,
TrapFrame->Eip,
* 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.
*/
-
+
/*
* 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)
UNIMPLEMENTED_FATAL();
}
}
-
+
/* So since we're not dealing with the above case, check for RDMSR/WRMSR */
if ((Instructions[0] == 0xF) && // 2-byte opcode
((Instructions[1] == 0x32) || // RDMSR
/* Whatever it is, we can't handle it */
KiSystemFatalException(EXCEPTION_GP_FAULT, TrapFrame);
}
-
+
/* Return to where we came from */
KiTrapReturn(TrapFrame);
}
#endif
/* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
-
+
/* Either kernel or user trap (non VDM) so dispatch exception */
if (Status == STATUS_ACCESS_VIOLATION)
{
Cr2,
TrapFrame);
}
-
+
/* Only other choice is an in-page error, with 3 parameters */
KiDispatchExceptionFromTrapFrame(STATUS_IN_PAGE_ERROR,
TrapFrame->Eip,
{
PKTHREAD Thread;
PFX_SAVE_AREA SaveArea;
-
+
/* Save trap frame */
KiEnterTrap(TrapFrame);
/* It isn't, enable interrupts and set delayed error */
_enable();
SaveArea->Cr0NpxState |= CR0_TS;
-
+
/* End trap */
KiEoiHelper(TrapFrame);
}
-
+
/* Otherwise, proceed with NPX fault handling */
KiNpxHandler(TrapFrame, Thread, SaveArea);
}
PKTHREAD Thread;
PFX_SAVE_AREA SaveArea;
ULONG Cr0, MxCsrMask, Error;
-
+
/* Save trap frame */
KiEnterTrap(TrapFrame);
/* Kernel should not fault on XMMI */
KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 13, 0, 0, 2, TrapFrame);
}
-
+
/* Update CR0 */
Cr0 = __readcr0();
Cr0 &= ~(CR0_MP | CR0_EM | CR0_TS);
__writecr0(Cr0);
-
+
/* Save FPU state */
Ke386SaveFpuState(SaveArea);
-
+
/* Mark CR0 state dirty */
Cr0 |= NPX_STATE_NOT_LOADED;
Cr0 |= SaveArea->Cr0NpxState;
__writecr0(Cr0);
-
+
/* Update NPX state */
Thread->NpxState = NPX_STATE_NOT_LOADED;
KeGetCurrentPrcb()->NpxThread = NULL;
-
+
/* Clear the TS bit and re-enable interrupts */
SaveArea->Cr0NpxState &= ~CR0_TS;
_enable();
/* Now look at MxCsr to get the mask of errors we should care about */
MxCsrMask = ~((USHORT)SaveArea->U.FxArea.MXCsr >> 7);
-
+
/* Get legal exceptions that software should handle */
Error = (USHORT)SaveArea->U.FxArea.MXCsr & (FSW_INVALID_OPERATION |
FSW_DENORMAL |
0,
TrapFrame);
}
-
+
/* Unknown XMMI fault */
KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN, 13, 0, 0, 1, TrapFrame);
}
{
/* Save trap frame */
KiEnterTrap(TrapFrame);
-
+
/* Increment EIP to skip the INT3 instruction */
TrapFrame->Eip++;
-
+
/* Continue with the common handler */
KiDebugHandler(TrapFrame, TrapFrame->Eax, TrapFrame->Ecx, TrapFrame->Edx);
}
ULONG Id, Offset, StackBytes, Result;
PVOID Handler;
ULONG SystemCallNumber = TrapFrame->Eax;
-
+
/* Get the current thread */
Thread = KeGetCurrentThread();
goto ExitCall;
}
}
-
+
/* Check if this is a GUI call */
if (__builtin_expect(Offset & SERVICE_TABLE_TEST, 0))
{
/* Get the batch count and flush if necessary */
if (NtCurrentTeb()->GdiBatchCount) KeGdiFlushUserBatch();
}
-
+
/* Increase system call count */
KeGetCurrentPrcb()->KeSystemCalls++;
-
+
/* FIXME: Increase individual counts on debug systems */
//KiIncreaseSystemCallCount(DescriptorTable, Id);
-
+
/* Get stack bytes */
StackBytes = DescriptorTable->Number[Id];
-
+
/* Probe caller stack */
if (__builtin_expect((Arguments < (PVOID)MmUserProbeAddress) && !(KiUserTrap(TrapFrame)), 0))
{
/* Access violation */
UNIMPLEMENTED_FATAL();
}
-
+
/* Call pre-service debug hook */
KiDbgPreServiceHook(SystemCallNumber, Arguments);
/* Get the handler and make the system call */
Handler = (PVOID)DescriptorTable->Base[Id];
Result = KiSystemCallTrampoline(Handler, Arguments, StackBytes);
-
+
/* Call post-service debug hook */
Result = KiDbgPostServiceHook(SystemCallNumber, Result);
/* Make sure we're exiting correctly */
KiExitSystemCallDebugChecks(Id, TrapFrame);
-
+
/* Restore the old trap frame */
ExitCall:
Thread->TrapFrame = (PKTRAP_FRAME)TrapFrame->Edx;