- Fix a build issue.

- Added more DBG checks for trap exits:
  * Detect if exiting with incorrect IF state.
  * Detect if exiting with broken stack.
  * Detect if exiting with a broken trap frame (note: Disabled in Kei386EoiHelper beause this raises the assertion. The trap frame is valid, it's just that some old code is using DbgArgMark for other purposes. Will fix.)
  * Detect if exiting with invalid FS.
  * Detect if exiting with invalid Exception List.
  * Detect if exiting with incorrect exception list and/or incorrect previmous mode on the stack (to detect macro/calling type mismatch).
The trap exit code is now complete and shareable across all 3 trap exit types, except for one broken assertion left to fix.

svn path=/trunk/; revision=20923
This commit is contained in:
Alex Ionescu 2006-01-16 22:07:38 +00:00
parent b311311796
commit f5e9486425
3 changed files with 178 additions and 8 deletions

View file

@ -356,7 +356,9 @@ Author:
//
// NTSTATUS Codes
//
#ifdef __ASM__
#define STATUS_INVALID_SYSTEM_SERVICE 0xC000001C
#endif
//
// Generic Definitions

View file

@ -495,9 +495,6 @@ KiTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr)
ASSERT(ExceptionNr != 14);
/* Store the exception number in an unused field in the trap frame. */
Tf->DbgArgMark = ExceptionNr;
/* Use the address of the trap frame as approximation to the ring0 esp */
Esp0 = (ULONG)&Tf->Eip;

View file

@ -484,13 +484,74 @@ ApcLoop:
KiRosTrapReturn:
// ========================= COMMON TRAP EXIT CODE ===================//
/* Restore exception list */
#ifdef DBG
/* Assert the flags */
pushfd
pop edx
test edx, EFLAGS_INTERRUPT_MASK
jnz InvalidExitState
/* Assert the stack */
cmp esp, ebp
jnz InvalidExitState
/* Assert the trap frame */
StateCheckDone:
sub dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
jnz InvalidTrapFrame
/* Assert FS */
mov bx, fs
cmp bx, KGDT_R0_PCR
jnz InvalidFs
/* Assert exception list */
cmp dword ptr fs:[KPCR_EXCEPTION_LIST], 0
jnz ExceptionListOK
InvalidFs:
push -1
call _KeBugCheck@4
InvalidTrapFrame:
add dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
InvalidExitState:
int 3
jmp StateCheckDone
ExceptionListOK:
#endif
/* Get exception list */
mov edx, [esp+KTRAP_FRAME_EXCEPTION_LIST]
#ifdef DBG
/* Assert the saved exception list */
or edx, edx
jnz ListOk
int 3
ListOk:
#endif
/* Restore it */
mov [fs:KPCR_EXCEPTION_LIST], edx
// ==================== ONLY IF PREVIOUS MODE NEEDED ==================//
/* Restore previous mode */
/* Get previous mode */
mov ecx, [esp+KTRAP_FRAME_PREVIOUS_MODE]
#ifdef DBG
/* Assert the saved previous mode */
cmp ecx, -1
jnz ModeOk
int 3
ModeOk:
#endif
/* Restore the previous mode */
mov esi, [fs:KPCR_CURRENT_THREAD]
mov byte ptr [esi+KTHREAD_PREVIOUS_MODE], cl
// ==================== END IF PREVIOUS MODE NEEDED ===================//
@ -766,13 +827,74 @@ ApcLoop2:
jmp ApcLoop2
KiRosTrapReturn2:
#ifdef DBG
/* Assert the flags */
pushfd
pop edx
test edx, EFLAGS_INTERRUPT_MASK
jnz InvalidExitState2
/* Restore exception list */
/* Assert the stack */
cmp esp, ebp
jnz InvalidExitState2
/* Assert the trap frame */
StateCheckDone2:
sub dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
jnz InvalidTrapFrame2
/* Assert FS */
mov bx, fs
cmp bx, KGDT_R0_PCR
jnz InvalidFs2
/* Assert exception list */
cmp dword ptr fs:[KPCR_EXCEPTION_LIST], 0
jnz ExceptionListOK2
InvalidFs2:
push -1
call _KeBugCheck@4
InvalidTrapFrame2:
add dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
InvalidExitState2:
int 3
jmp StateCheckDone2
ExceptionListOK2:
#endif
/* Get exception list */
mov edx, [esp+KTRAP_FRAME_EXCEPTION_LIST]
#ifdef DBG
/* Assert the saved exception list */
or edx, edx
jnz ListOk2
int 3
ListOk2:
#endif
/* Restore it */
mov [fs:KPCR_EXCEPTION_LIST], edx
/* Restore previous mode */
// ==================== ONLY IF PREVIOUS MODE NEEDED ==================//
/* Get previous mode */
mov ecx, [esp+KTRAP_FRAME_PREVIOUS_MODE]
#ifdef DBG
/* Assert the saved previous mode */
cmp ecx, -1
jnz ModeOk2
int 3
ModeOk2:
#endif
/* Restore previous mode */
mov esi, [fs:KPCR_CURRENT_THREAD]
mov byte ptr [esi+KTHREAD_PREVIOUS_MODE], cl
@ -957,9 +1079,58 @@ ApcLoop3:
jmp ApcLoop3
KiRosTrapReturn3:
#ifdef DBG
/* Assert the flags */
pushfd
pop edx
test edx, EFLAGS_INTERRUPT_MASK
jnz InvalidExitState3
/* Assert the stack */
cmp esp, ebp
jnz InvalidExitState3
/* Assert the trap frame */
StateCheckDone3:
//sub dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
//jnz InvalidTrapFrame3
/* Assert FS */
mov bx, fs
cmp bx, KGDT_R0_PCR
jnz InvalidFs3
/* Assert exception list */
cmp dword ptr fs:[KPCR_EXCEPTION_LIST], 0
jnz ExceptionListOK3
InvalidFs3:
push -1
call _KeBugCheck@4
InvalidTrapFrame3:
add dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
InvalidExitState3:
int 3
jmp StateCheckDone3
ExceptionListOK3:
#endif
/* Get exception list */
mov edx, [esp+KTRAP_FRAME_EXCEPTION_LIST]
#ifdef DBG
/* Assert the saved exception list */
or edx, edx
jnz ListOk3
int 3
ListOk3:
#endif
/* Restore exception list */
mov edx, [esp+KTRAP_FRAME_EXCEPTION_LIST]
mov [fs:KPCR_EXCEPTION_LIST], edx
/* Check for V86 */