[NTOS:KE][SDK:ASM] Code formatting/styling only.

- Un-hardcode the RPL_MASK value.
- s/KiUnexpectedInterrupt&Number/KiUnexpectedInterrupt&Vector/
- Use C-style comments in traphdlr.c as everywhere else in the file.
- Update the URLs for the MSDN "FPO" macro documentation.
This commit is contained in:
Hermès Bélusca-Maïto 2019-02-04 01:02:26 +01:00
parent 1dc4ba9da7
commit d15e36a1f1
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 86 additions and 101 deletions

View file

@ -66,16 +66,15 @@ MACRO(idt, Handler, Bits)
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
@ -145,7 +144,7 @@ MACRO(KiEnterTrap, Flags)
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
@ -250,17 +249,17 @@ MACRO(TRAP_ENTRY, Trap, Flags)
.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)

View file

@ -18,7 +18,7 @@ idt _KiUnexpectedInterrupt&Vector, INT_32_DPL0
ENDM
MACRO(GENERATE_INT_HANDLER, Vector)
//.func KiUnexpectedInterrupt&Number
//.func KiUnexpectedInterrupt&Vector
_KiUnexpectedInterrupt&Vector:
/* This is a push instruction with 8bit operand. Since the instruction
sign extends the value to 32 bits, we need to offset it */

View file

@ -222,7 +222,7 @@ KiDebugHandler(IN PKTRAP_FRAME TrapFrame,
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();
@ -248,7 +248,7 @@ KiNpxHandler(IN PKTRAP_FRAME TrapFrame,
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))
@ -410,7 +410,7 @@ KiTrap00Handler(IN PKTRAP_FRAME TrapFrame)
KiEnterTrap(TrapFrame);
/* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Enable interrupts */
_enable();
@ -430,7 +430,7 @@ KiTrap01Handler(IN PKTRAP_FRAME TrapFrame)
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)
@ -467,58 +467,52 @@ KiTrap02(VOID)
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;
@ -541,64 +535,50 @@ KiTrap02(VOID)
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);
}
@ -623,7 +603,7 @@ KiTrap04Handler(IN PKTRAP_FRAME TrapFrame)
KiEnterTrap(TrapFrame);
/* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Enable interrupts */
_enable();
@ -643,7 +623,7 @@ KiTrap05Handler(IN PKTRAP_FRAME TrapFrame)
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);
@ -878,7 +858,7 @@ KiTrap0AHandler(IN PKTRAP_FRAME TrapFrame)
KiEnterTrap(TrapFrame);
/* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Kill the system */
KiSystemFatalException(EXCEPTION_INVALID_TSS, TrapFrame);
@ -1485,7 +1465,7 @@ KiTrap13Handler(IN PKTRAP_FRAME TrapFrame)
SaveArea = KiGetThreadNpxArea(Thread);
/* Check for VDM trap */
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
/* Check for user trap */
if (!KiUserTrap(TrapFrame))

View file

@ -9,8 +9,10 @@
#ifndef __ASM_INC__
#define __ASM_INC__
/* Common definitions for FPO macro
see http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
/*
* Common definitions for the FPO macro.
* See https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_fpo_data
*/
#define FRAME_FPO 0
#define FRAME_TRAP 1
#define FRAME_TSS 2
@ -65,8 +67,10 @@ GLOBAL_LABEL MACRO label
%label::
ENDM
/* check http://msdn.microsoft.com/en-us/library/9c9k076y%28VS.80%29.aspx
and http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
/*
* See https://docs.microsoft.com/en-us/cpp/assembler/masm/dot-fpo
* and https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_fpo_data
*/
FPO MACRO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
.FPO (cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame)
ENDM
@ -317,8 +321,10 @@ ENDM
.section .rdata
.endm
/* check http://msdn.microsoft.com/en-us/library/9c9k076y%28VS.80%29.aspx
and http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
/*
* See https://docs.microsoft.com/en-us/cpp/assembler/masm/dot-fpo
* and https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_fpo_data
*/
.macro FPO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
.if (cbFrame == FRAME_TRAP)
.cfi_signal_frame