https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5eab2ddb2eb362eb2d5c327003d5193e071c573a
commit 5eab2ddb2eb362eb2d5c327003d5193e071c573a Author: Timo Kreuzer <timo.kreu...@reactos.org> AuthorDate: Sat Sep 7 22:10:28 2024 +0300 Commit: Timo Kreuzer <timo.kreu...@reactos.org> CommitDate: Thu Sep 12 17:07:59 2024 +0300 [RTL/x64] Do not overwrite the original context during exception handling This fixes ExceptionContinueExecution cases, where we want to continue execution on the original context (or as modified by the handler), not on some halfway unwinded one. --- sdk/lib/rtl/amd64/unwind.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sdk/lib/rtl/amd64/unwind.c b/sdk/lib/rtl/amd64/unwind.c index 4a5903361b9..ee7313bc62f 100644 --- a/sdk/lib/rtl/amd64/unwind.c +++ b/sdk/lib/rtl/amd64/unwind.c @@ -679,7 +679,7 @@ RtlpUnwindInternal( ULONG64 ImageBase, EstablisherFrame; CONTEXT UnwindContext; - /* Get the current stack limits and registration frame */ + /* Get the current stack limits */ RtlpGetStackLimits(&StackLow, &StackHigh); /* If we have a target frame, then this is our high limit */ @@ -708,8 +708,11 @@ RtlpUnwindInternal( UnwindContext.Rip = *(DWORD64*)UnwindContext.Rsp; UnwindContext.Rsp += sizeof(DWORD64); - /* Copy the context back for the next iteration */ - *ContextRecord = UnwindContext; + if (HandlerType == UNW_FLAG_UHANDLER) + { + /* Copy the context back for the next iteration */ + *ContextRecord = UnwindContext; + } continue; } @@ -756,7 +759,7 @@ RtlpUnwindInternal( /* Log the exception if it's enabled */ RtlpCheckLogException(ExceptionRecord, - ContextRecord, + &UnwindContext, &DispatcherContext, sizeof(DispatcherContext)); @@ -844,8 +847,11 @@ RtlpUnwindInternal( break; } - /* We have successfully unwound a frame. Copy the unwind context back. */ - *ContextRecord = UnwindContext; + if (HandlerType == UNW_FLAG_UHANDLER) + { + /* We have successfully unwound a frame. Copy the unwind context back. */ + *ContextRecord = UnwindContext; + } } if (ExceptionRecord->ExceptionCode != STATUS_UNWIND_CONSOLIDATE)