[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,38 +19,19 @@ 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;
{
/* Unwind to the caller of this function */
RtlVirtualUnwind(UNW_FLAG_NHANDLER,
ImageBase,
Context.Rip,
FunctionEntry,
&Context,
&HandlerData,
&EstablisherFrame,
NULL);
/* Save the exception address */ /* Save the exception address */
ExceptionRecord->ExceptionAddress = (PVOID)Context.Rip; ExceptionRecord->ExceptionAddress = (PVOID)Context.Rip;
/* Write the context flag */
Context.ContextFlags = CONTEXT_FULL;
/* Check if user mode debugger is active */ /* Check if user mode debugger is active */
if (RtlpCheckForActiveDebugger()) if (RtlpCheckForActiveDebugger())
{ {
@ -71,7 +52,6 @@ RtlRaiseException(IN PEXCEPTION_RECORD ExceptionRecord)
Status = ZwContinue(&Context, FALSE); Status = ZwContinue(&Context, FALSE);
} }
} }
}
/* If we returned, raise a status */ /* If we returned, raise a status */
RtlRaiseStatus(Status); RtlRaiseStatus(Status);