[RTL] Simplify RtlRaiseException

This commit is contained in:
Timo Kreuzer 2018-03-02 07:48:34 +01:00
parent 3ec1ca9b46
commit e6af7d9dfe

View file

@ -19,57 +19,37 @@ RtlRaiseException(IN PEXCEPTION_RECORD ExceptionRecord)
{ {
CONTEXT Context; CONTEXT Context;
NTSTATUS Status = STATUS_INVALID_DISPOSITION; NTSTATUS Status = STATUS_INVALID_DISPOSITION;
ULONG64 ImageBase;
PRUNTIME_FUNCTION FunctionEntry;
PVOID HandlerData;
ULONG64 EstablisherFrame;
/* Capture the context */ /* Capture the current context */
RtlCaptureContext(&Context); RtlCaptureContext(&Context);
/* Get the function entry for this function */ /* Fix up Context.Rip for the caller */
FunctionEntry = RtlLookupFunctionEntry(Context.Rip, Context.Rip = (ULONG64)_ReturnAddress();
&ImageBase,
NULL);
/* Check if we found it */ /* Fix up Context.Rsp for the caller */
if (FunctionEntry) Context.Rsp = (ULONG64)_AddressOfReturnAddress() + 8;
/* Save the exception address */
ExceptionRecord->ExceptionAddress = (PVOID)Context.Rip;
/* Check if user mode debugger is active */
if (RtlpCheckForActiveDebugger())
{ {
/* Unwind to the caller of this function */ /* Raise an exception immediately */
RtlVirtualUnwind(UNW_FLAG_NHANDLER, Status = ZwRaiseException(ExceptionRecord, &Context, TRUE);
ImageBase, }
Context.Rip, else
FunctionEntry, {
&Context, /* Dispatch the exception and check if we should continue */
&HandlerData, if (!RtlDispatchException(ExceptionRecord, &Context))
&EstablisherFrame,
NULL);
/* Save the exception address */
ExceptionRecord->ExceptionAddress = (PVOID)Context.Rip;
/* Write the context flag */
Context.ContextFlags = CONTEXT_FULL;
/* Check if user mode debugger is active */
if (RtlpCheckForActiveDebugger())
{ {
/* Raise an exception immediately */ /* Raise the exception */
Status = ZwRaiseException(ExceptionRecord, &Context, TRUE); Status = ZwRaiseException(ExceptionRecord, &Context, FALSE);
} }
else else
{ {
/* Dispatch the exception and check if we should continue */ /* Continue, go back to previous context */
if (!RtlDispatchException(ExceptionRecord, &Context)) Status = ZwContinue(&Context, FALSE);
{
/* Raise the exception */
Status = ZwRaiseException(ExceptionRecord, &Context, FALSE);
}
else
{
/* Continue, go back to previous context */
Status = ZwContinue(&Context, FALSE);
}
} }
} }