ENDM
-KI_PUSH_FAKE_ERROR_CODE = HEX(0001)
-KI_UNUSED = HEX(0002)
-KI_NONVOLATILES_ONLY = HEX(0004)
-KI_FAST_SYSTEM_CALL = HEX(0008)
-KI_SOFTWARE_TRAP = HEX(0010)
-KI_HARDWARE_INT = HEX(0020)
-KI_DONT_SAVE_SEGS = HEX(0100)
+#define KI_PUSH_FAKE_ERROR_CODE HEX(0001)
+#define KI_UNUSED HEX(0002)
+#define KI_NONVOLATILES_ONLY HEX(0004)
+#define KI_FAST_SYSTEM_CALL HEX(0008)
+#define KI_SOFTWARE_TRAP HEX(0010)
+#define KI_HARDWARE_INT HEX(0020)
+#define KI_DONT_SAVE_SEGS HEX(0100)
MACRO(KiEnterTrap, Flags)
- LOCAL kernel_trap
LOCAL not_v86_trap
LOCAL set_sane_segs
if (Flags AND KI_DONT_SAVE_SEGS)
/* Initialize TrapFrame segment registers with sane values */
- mov eax, KGDT_R3_DATA OR 3
+ mov eax, KGDT_R3_DATA OR RPL_MASK
mov ecx, fs
mov [esp + KTRAP_FRAME_DS], eax
mov [esp + KTRAP_FRAME_ES], eax
.ENDP
ENDM
-#define KI_RESTORE_EAX HEX(001)
-#define KI_RESTORE_ECX_EDX HEX(002)
-#define KI_RESTORE_FS HEX(004)
-#define KI_RESTORE_SEGMENTS HEX(008)
-#define KI_RESTORE_EFLAGS HEX(010)
-#define KI_EXIT_SYSCALL HEX(020)
-#define KI_EXIT_JMP HEX(040)
-#define KI_EXIT_RET HEX(080)
-#define KI_EXIT_IRET HEX(100)
-#define KI_EDITED_FRAME HEX(200)
-#define KI_EXIT_RET8 HEX(400)
+#define KI_RESTORE_EAX HEX(0001)
+#define KI_RESTORE_ECX_EDX HEX(0002)
+#define KI_RESTORE_FS HEX(0004)
+#define KI_RESTORE_SEGMENTS HEX(0008)
+#define KI_RESTORE_EFLAGS HEX(0010)
+#define KI_EXIT_SYSCALL HEX(0020)
+#define KI_EXIT_JMP HEX(0040)
+#define KI_EXIT_RET HEX(0080)
+#define KI_EXIT_IRET HEX(0100)
+#define KI_EDITED_FRAME HEX(0200)
+#define KI_EXIT_RET8 HEX(0400)
#define KI_RESTORE_VOLATILES (KI_RESTORE_EAX OR KI_RESTORE_ECX_EDX)
MACRO(KiTrapExitStub, Name, Flags)
IN ULONG Parameter3)
{
/* Check for VDM trap */
- ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
+ ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Enable interrupts if the trap came from user-mode */
if (KiUserTrap(TrapFrame)) _enable();
ULONG Cr0, Mask, Error, ErrorOffset, DataOffset;
/* Check for VDM trap */
- ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
+ ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Check for kernel trap */
if (!KiUserTrap(TrapFrame))
KiEnterTrap(TrapFrame);
/* Check for VDM trap */
- ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
+ ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Enable interrupts */
_enable();
KiEnterTrap(TrapFrame);
/* Check for VDM trap */
- ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
+ ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Check if this was a single step after sysenter */
if (TrapFrame->Eip == (ULONG)KiFastCallEntry)
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
- // normally already be set.
- //
- // For sanity's sake, make sure interrupts are disabled for sure.
- // NMIs will already be since the CPU does it for us.
- //
+ /*
+ * 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
+ * normally already be set.
+ *
+ * For sanity's sake, make sure interrupts are disabled for sure.
+ * NMIs will already be since the CPU does it for us.
+ */
_disable();
- //
- // Get the current TSS, thread, and process
- //
+ /* Get the current TSS, thread, and process */
Tss = PCR->TSS;
Thread = ((PKIPCR)PCR)->PrcbData.CurrentThread;
Process = Thread->ApcState.Process;
- //
- // Save data usually not in the TSS
- //
+ /* Save data usually not present 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
- //
+ /* Now get the base address of the NMI TSS */
TssGdt = &((PKIPCR)KeGetPcr())->GDT[KGDT_NMI_TSS / sizeof(KGDTENTRY)];
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
- //
- // Note that in reality, we are already on the NMI tss -- we just need to
- // update the PCR to reflect this
- //
+ /*
+ * Switch to it and activate it, masking off the nested flag.
+ *
+ * Note that in reality, we are already on the NMI TSS -- we just
+ * need to update the PCR to reflect this.
+ */
PCR->TSS = NmiTss;
__writeeflags(__readeflags() &~ EFLAGS_NESTED_TASK);
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
- //
- // The CPU does a hardware "Context switch" / task switch of sorts and so it
- // takes care of saving our context in the normal TSS.
- //
- // We just have to go get the values...
- //
+ /*
+ * Now build the trap frame based on the original TSS.
+ *
+ * The CPU does a hardware "Context switch" / task switch of sorts
+ * and so it takes care of saving our context in the normal TSS.
+ *
+ * We just have to go get the values...
+ */
RtlZeroMemory(&TrapFrame, sizeof(KTRAP_FRAME));
TrapFrame.HardwareSegSs = Tss->Ss0;
TrapFrame.HardwareEsp = Tss->Esp0;
TrapFrame.DbgEip = Tss->Eip;
TrapFrame.DbgEbp = Tss->Ebp;
- //
- // Store the trap frame in the KPRCB
- //
+ /* Store the trap frame in the KPRCB */
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 */
if (!KiHandleNmi())
{
- //
- // They did not, so call the platform HAL routine to bugcheck the system
- //
- // Make sure the HAL believes it's running at HIGH IRQL... we can't use
- // the normal APIs here as playing with the IRQL could change the system
- // state
- //
+ /*
+ * They did not, so call the platform HAL routine to bugcheck the system
+ *
+ * Make sure the HAL believes it's running at HIGH IRQL... we can't use
+ * the normal APIs here as playing with the IRQL could change the system
+ * state.
+ */
OldIrql = PCR->Irql;
PCR->Irql = HIGH_LEVEL;
HalHandleNMI(NULL);
PCR->Irql = OldIrql;
}
- //
- // Although the CPU disabled NMIs, we just did a BIOS Call, which could've
- // totally changed things.
- //
- // We have to make sure we're still in our original NMI -- a nested NMI
- // will point back to the NMI TSS, and in that case we're hosed.
- //
+ /*
+ * Although the CPU disabled NMIs, we just did a BIOS call, which could've
+ * totally changed things.
+ *
+ * We have to make sure we're still in our original NMI -- a nested NMI
+ * will point back to the NMI TSS, and in that case we're hosed.
+ */
if (PCR->TSS->Backlink != KGDT_NMI_TSS)
{
- //
- // Restore original TSS
- //
+ /* Restore original TSS */
PCR->TSS = Tss;
- //
- // Set it back to busy
- //
+ /* 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
- //
+ /* Restore nested flag */
__writeeflags(__readeflags() | EFLAGS_NESTED_TASK);
- //
- // Handled, return from interrupt
- //
+ /* Handled, return from interrupt */
KiIret();
}
- //
- // Unhandled: crash the system
- //
+ /* Unhandled: crash the system */
KiSystemFatalException(EXCEPTION_NMI, NULL);
}
KiEnterTrap(TrapFrame);
/* Check for VDM trap */
- ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
+ ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Enable interrupts */
_enable();
KiEnterTrap(TrapFrame);
/* Check for VDM trap */
- ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
+ ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Check for kernel-mode fault */
if (!KiUserTrap(TrapFrame)) KiSystemFatalException(EXCEPTION_BOUND_CHECK, TrapFrame);
KiEnterTrap(TrapFrame);
/* Check for VDM trap */
- ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
+ ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Kill the system */
KiSystemFatalException(EXCEPTION_INVALID_TSS, TrapFrame);
SaveArea = KiGetThreadNpxArea(Thread);
/* Check for VDM trap */
- ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
+ ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Check for user trap */
if (!KiUserTrap(TrapFrame))