From 5b82ada2eda0e0579d98051e781c47a1b3015a23 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Thu, 15 Dec 2022 20:58:32 +0100 Subject: [PATCH] [NTOS:Ke/x64] Improve KiDispatchExceptionToUser Return back to the caller instead of exiting through KiServiceExit2, which is broken and needs to be changed to allow restoring of an exception frame. --- ntoskrnl/ke/amd64/except.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ntoskrnl/ke/amd64/except.c b/ntoskrnl/ke/amd64/except.c index eed182cf6b6..1912ddd8ae4 100644 --- a/ntoskrnl/ke/amd64/except.c +++ b/ntoskrnl/ke/amd64/except.c @@ -93,7 +93,7 @@ KeInitExceptions(VOID) } static -VOID +BOOLEAN KiDispatchExceptionToUser( IN PKTRAP_FRAME TrapFrame, IN PCONTEXT Context, @@ -147,7 +147,7 @@ KiDispatchExceptionToUser( /* Nothing we can do here */ _disable(); - _SEH2_YIELD(return); + return FALSE; } _SEH2_END; @@ -172,7 +172,7 @@ KiDispatchExceptionToUser( _disable(); /* Exit to usermode */ - KiServiceExit2(TrapFrame); + return TRUE; } static @@ -361,8 +361,12 @@ KiDispatchException(IN PEXCEPTION_RECORD ExceptionRecord, /* Forward exception to user mode debugger */ if (DbgkForwardException(ExceptionRecord, TRUE, FALSE)) return; - /* Forward exception to user mode (does not return, if successful) */ - KiDispatchExceptionToUser(TrapFrame, &Context, ExceptionRecord); + /* Forward exception to user mode */ + if (KiDispatchExceptionToUser(TrapFrame, &Context, ExceptionRecord)) + { + /* Success, the exception will be handled by KiUserExceptionDispatcher */ + return; + } /* Failed to dispatch, fall through for second chance handling */ }