[NTOS:KE] Improve NtRaiseException and NtContinue

- Fix annotations
- Don't use KiServiceExit to return to the caller with an error code, instead just return from the function, that is the same thing.
- Refactor failure path
- Add DPRINTs on failure
This commit is contained in:
Timo Kreuzer 2024-04-27 17:23:02 +03:00
parent 4bc591c6f0
commit 5c3b1c78a7

View file

@ -17,9 +17,10 @@
VOID VOID
NTAPI NTAPI
KiContinuePreviousModeUser(IN PCONTEXT Context, KiContinuePreviousModeUser(
IN PKEXCEPTION_FRAME ExceptionFrame, _In_ PCONTEXT Context,
IN PKTRAP_FRAME TrapFrame) _Out_ PKEXCEPTION_FRAME ExceptionFrame,
_Out_ PKTRAP_FRAME TrapFrame)
{ {
CONTEXT LocalContext; CONTEXT LocalContext;
@ -86,11 +87,12 @@ KiContinue(IN PCONTEXT Context,
NTSTATUS NTSTATUS
NTAPI NTAPI
KiRaiseException(IN PEXCEPTION_RECORD ExceptionRecord, KiRaiseException(
IN PCONTEXT Context, _In_ PEXCEPTION_RECORD ExceptionRecord,
IN PKEXCEPTION_FRAME ExceptionFrame, _In_ PCONTEXT Context,
IN PKTRAP_FRAME TrapFrame, _Out_ PKEXCEPTION_FRAME ExceptionFrame,
IN BOOLEAN SearchFrames) _Out_ PKTRAP_FRAME TrapFrame,
_In_ BOOLEAN SearchFrames)
{ {
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(); KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
CONTEXT LocalContext; CONTEXT LocalContext;
@ -168,9 +170,10 @@ KiRaiseException(IN PEXCEPTION_RECORD ExceptionRecord,
NTSTATUS NTSTATUS
NTAPI NTAPI
NtRaiseException(IN PEXCEPTION_RECORD ExceptionRecord, NtRaiseException(
IN PCONTEXT Context, _In_ PEXCEPTION_RECORD ExceptionRecord,
IN BOOLEAN FirstChance) _In_ PCONTEXT Context,
_In_ BOOLEAN FirstChance)
{ {
NTSTATUS Status; NTSTATUS Status;
PKTHREAD Thread; PKTHREAD Thread;
@ -198,27 +201,21 @@ NtRaiseException(IN PEXCEPTION_RECORD ExceptionRecord,
ExceptionFrame, ExceptionFrame,
TrapFrame, TrapFrame,
FirstChance); FirstChance);
if (NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* It was handled, so exit restoring all state */ DPRINT1("KiRaiseException failed. Status = 0x%lx\n", Status);
KiExceptionExit(TrapFrame, ExceptionFrame); return Status;
} }
#ifdef _M_IX86
else
{
/* Exit with error */
KiServiceExit(TrapFrame, Status);
}
#endif
/* Return to the caller */ /* It was handled, so exit restoring all state */
return Status; KiExceptionExit(TrapFrame, ExceptionFrame);
} }
NTSTATUS NTSTATUS
NTAPI NTAPI
NtContinue(IN PCONTEXT Context, NtContinue(
IN BOOLEAN TestAlert) _In_ PCONTEXT Context,
_In_ BOOLEAN TestAlert)
{ {
PKTHREAD Thread; PKTHREAD Thread;
NTSTATUS Status; NTSTATUS Status;
@ -237,24 +234,20 @@ NtContinue(IN PCONTEXT Context,
/* Continue from this point on */ /* Continue from this point on */
Status = KiContinue(Context, ExceptionFrame, TrapFrame); Status = KiContinue(Context, ExceptionFrame, TrapFrame);
if (NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* Check if alert was requested */ DPRINT1("KiContinue failed. Status = 0x%lx\n", Status);
if (TestAlert) KeTestAlertThread(Thread->PreviousMode); return Status;
/* Exit to new trap frame */
KiExceptionExit(TrapFrame, ExceptionFrame);
} }
#ifdef _M_IX86
else /* Check if alert was requested */
if (TestAlert)
{ {
/* Exit with an error */ KeTestAlertThread(Thread->PreviousMode);
KiServiceExit(TrapFrame, Status);
} }
#endif
/* Return to the caller */ /* Exit to new context */
return Status; KiExceptionExit(TrapFrame, ExceptionFrame);
} }
/* EOF */ /* EOF */