[NTOS:KE]

- Make decoding of the error code more obvious in KiTrap0EHandler
- Avoid or make explicit some signed/unsigned conversions

svn path=/trunk/; revision=74304
This commit is contained in:
Thomas Faber 2017-04-14 10:39:07 +00:00
parent 21b119daec
commit 8c82e4261d
2 changed files with 25 additions and 18 deletions

View file

@ -83,7 +83,7 @@ KiFillTrapFrameDebug(IN PKTRAP_FRAME TrapFrame)
TrapFrame->DbgArgMark = 0xBADB0D00; TrapFrame->DbgArgMark = 0xBADB0D00;
TrapFrame->DbgEip = TrapFrame->Eip; TrapFrame->DbgEip = TrapFrame->Eip;
TrapFrame->DbgEbp = TrapFrame->Ebp; TrapFrame->DbgEbp = TrapFrame->Ebp;
TrapFrame->PreviousPreviousMode = -1; TrapFrame->PreviousPreviousMode = (ULONG)-1;
} }
#define DR7_RESERVED_READ_AS_1 0x400 #define DR7_RESERVED_READ_AS_1 0x400

View file

@ -529,7 +529,7 @@ KiTrap02(VOID)
TrapFrame.Edi = Tss->Edi; TrapFrame.Edi = Tss->Edi;
TrapFrame.SegFs = Tss->Fs; TrapFrame.SegFs = Tss->Fs;
TrapFrame.ExceptionList = PCR->NtTib.ExceptionList; TrapFrame.ExceptionList = PCR->NtTib.ExceptionList;
TrapFrame.PreviousPreviousMode = -1; TrapFrame.PreviousPreviousMode = (ULONG)-1;
TrapFrame.Eax = Tss->Eax; TrapFrame.Eax = Tss->Eax;
TrapFrame.Ecx = Tss->Ecx; TrapFrame.Ecx = Tss->Ecx;
TrapFrame.Edx = Tss->Edx; TrapFrame.Edx = Tss->Edx;
@ -1197,6 +1197,8 @@ FASTCALL
KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame) KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame)
{ {
PKTHREAD Thread; PKTHREAD Thread;
BOOLEAN Present;
BOOLEAN StoreInstruction;
ULONG_PTR Cr2; ULONG_PTR Cr2;
NTSTATUS Status; NTSTATUS Status;
@ -1222,14 +1224,18 @@ KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame)
/* Enable interrupts */ /* Enable interrupts */
_enable(); _enable();
/* Interpret the error code */
Present = (TrapFrame->ErrCode & 1) != 0;
StoreInstruction = (TrapFrame->ErrCode & 2) != 0;
/* Check if we came in with interrupts disabled */ /* Check if we came in with interrupts disabled */
if (!(TrapFrame->EFlags & EFLAGS_INTERRUPT_MASK)) if (!(TrapFrame->EFlags & EFLAGS_INTERRUPT_MASK))
{ {
/* This is completely illegal, bugcheck the system */ /* This is completely illegal, bugcheck the system */
KeBugCheckWithTf(IRQL_NOT_LESS_OR_EQUAL, KeBugCheckWithTf(IRQL_NOT_LESS_OR_EQUAL,
Cr2, Cr2,
-1, (ULONG_PTR)-1,
TrapFrame->ErrCode & 2 ? TRUE : FALSE, StoreInstruction,
TrapFrame->Eip, TrapFrame->Eip,
TrapFrame); TrapFrame);
} }
@ -1267,7 +1273,7 @@ KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame)
/* Do what windows does and issue an invalid access violation */ /* Do what windows does and issue an invalid access violation */
KiDispatchException2Args(KI_EXCEPTION_ACCESS_VIOLATION, KiDispatchException2Args(KI_EXCEPTION_ACCESS_VIOLATION,
TrapFrame->Eip, TrapFrame->Eip,
TrapFrame->ErrCode & 2 ? TRUE : FALSE, StoreInstruction,
Cr2, Cr2,
TrapFrame); TrapFrame);
#endif #endif
@ -1275,7 +1281,7 @@ KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame)
} }
/* Call the access fault handler */ /* Call the access fault handler */
Status = MmAccessFault(TrapFrame->ErrCode & 1, Status = MmAccessFault(Present,
(PVOID)Cr2, (PVOID)Cr2,
KiUserTrap(TrapFrame), KiUserTrap(TrapFrame),
TrapFrame); TrapFrame);
@ -1307,7 +1313,7 @@ KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame)
/* This status code is repurposed so we can recognize it later */ /* This status code is repurposed so we can recognize it later */
KiDispatchException2Args(KI_EXCEPTION_ACCESS_VIOLATION, KiDispatchException2Args(KI_EXCEPTION_ACCESS_VIOLATION,
TrapFrame->Eip, TrapFrame->Eip,
TrapFrame->ErrCode & 2 ? TRUE : FALSE, StoreInstruction,
Cr2, Cr2,
TrapFrame); TrapFrame);
} }
@ -1317,7 +1323,7 @@ KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame)
/* These faults only have two parameters */ /* These faults only have two parameters */
KiDispatchException2Args(Status, KiDispatchException2Args(Status,
TrapFrame->Eip, TrapFrame->Eip,
TrapFrame->ErrCode & 2 ? TRUE : FALSE, StoreInstruction,
Cr2, Cr2,
TrapFrame); TrapFrame);
} }
@ -1327,7 +1333,7 @@ KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame)
0, 0,
TrapFrame->Eip, TrapFrame->Eip,
3, 3,
TrapFrame->ErrCode & 2 ? TRUE : FALSE, StoreInstruction,
Cr2, Cr2,
Status, Status,
TrapFrame); TrapFrame);
@ -1623,7 +1629,8 @@ KiSystemServiceHandler(IN PKTRAP_FRAME TrapFrame,
{ {
PKTHREAD Thread; PKTHREAD Thread;
PKSERVICE_TABLE_DESCRIPTOR DescriptorTable; PKSERVICE_TABLE_DESCRIPTOR DescriptorTable;
ULONG Id, Offset, StackBytes, Result; ULONG Id, Offset, StackBytes;
NTSTATUS Status;
PVOID Handler; PVOID Handler;
ULONG SystemCallNumber = TrapFrame->Eax; ULONG SystemCallNumber = TrapFrame->Eax;
@ -1681,18 +1688,18 @@ KiSystemServiceHandler(IN PKTRAP_FRAME TrapFrame,
if (!(Offset & SERVICE_TABLE_TEST)) if (!(Offset & SERVICE_TABLE_TEST))
{ {
/* Fail the call */ /* Fail the call */
Result = STATUS_INVALID_SYSTEM_SERVICE; Status = STATUS_INVALID_SYSTEM_SERVICE;
goto ExitCall; goto ExitCall;
} }
/* Convert us to a GUI thread -- must wrap in ASM to get new EBP */ /* Convert us to a GUI thread -- must wrap in ASM to get new EBP */
Result = KiConvertToGuiThread(); Status = KiConvertToGuiThread();
/* Reload trap frame and descriptor table pointer from new stack */ /* Reload trap frame and descriptor table pointer from new stack */
TrapFrame = *(volatile PVOID*)&Thread->TrapFrame; TrapFrame = *(volatile PVOID*)&Thread->TrapFrame;
DescriptorTable = (PVOID)(*(volatile ULONG_PTR*)&Thread->ServiceTable + Offset); DescriptorTable = (PVOID)(*(volatile ULONG_PTR*)&Thread->ServiceTable + Offset);
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Status))
{ {
/* Set the last error and fail */ /* Set the last error and fail */
goto ExitCall; goto ExitCall;
@ -1702,7 +1709,7 @@ KiSystemServiceHandler(IN PKTRAP_FRAME TrapFrame,
if (Id >= DescriptorTable->Limit) if (Id >= DescriptorTable->Limit)
{ {
/* Fail the call */ /* Fail the call */
Result = STATUS_INVALID_SYSTEM_SERVICE; Status = STATUS_INVALID_SYSTEM_SERVICE;
goto ExitCall; goto ExitCall;
} }
} }
@ -1735,10 +1742,10 @@ KiSystemServiceHandler(IN PKTRAP_FRAME TrapFrame,
/* 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); Status = KiSystemCallTrampoline(Handler, Arguments, StackBytes);
/* Call post-service debug hook */ /* Call post-service debug hook */
Result = KiDbgPostServiceHook(SystemCallNumber, Result); Status = KiDbgPostServiceHook(SystemCallNumber, Status);
/* Make sure we're exiting correctly */ /* Make sure we're exiting correctly */
KiExitSystemCallDebugChecks(Id, TrapFrame); KiExitSystemCallDebugChecks(Id, TrapFrame);
@ -1748,7 +1755,7 @@ ExitCall:
Thread->TrapFrame = (PKTRAP_FRAME)TrapFrame->Edx; Thread->TrapFrame = (PKTRAP_FRAME)TrapFrame->Edx;
/* Exit from system call */ /* Exit from system call */
KiServiceExit(TrapFrame, Result); KiServiceExit(TrapFrame, Status);
} }
VOID VOID