[PATCH] ntdll: Clear CONTEXT_XSTATE flag in RtlUnwindEx().

Paul Gofman pgofman at codeweavers.com
Mon Aug 31 12:46:41 CDT 2020


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49749
Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
    The unwind handler which is called from Windows clr.dll which after processing ACCESS_VIOLATION
    exception sets the CONTEXT_XSTATE flag in unwind context (probably just copis the original
    exception context at some moment which has this flag since 16ed88a95234d844fee9fc19053c5c7f618f92ba).
    Meanwhile the CONTEXT_EX structure is garbage. The consequet NtSetContextThread() is crashing
    trying to restore xstate from invalid location.

 dlls/ntdll/signal_x86_64.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c
index ba91cc13dfe..6fbb612825b 100644
--- a/dlls/ntdll/signal_x86_64.c
+++ b/dlls/ntdll/signal_x86_64.c
@@ -1244,7 +1244,9 @@ void WINAPI RtlUnwindEx( PVOID end_frame, PVOID target_ip, EXCEPTION_RECORD *rec
             {
                 ULONG64 frame;
 
-                *context = new_context = *dispatch.ContextRecord;
+                new_context = *dispatch.ContextRecord;
+                new_context.ContextFlags &= ~0x40;
+                *context = new_context;
                 dispatch.ContextRecord = context;
                 RtlVirtualUnwind( UNW_FLAG_NHANDLER, dispatch.ImageBase,
                         dispatch.ControlPc, dispatch.FunctionEntry,
@@ -1267,7 +1269,9 @@ void WINAPI RtlUnwindEx( PVOID end_frame, PVOID target_ip, EXCEPTION_RECORD *rec
 
                     teb_frame = __wine_pop_frame( teb_frame );
 
-                    *context = new_context = *dispatch.ContextRecord;
+                    new_context = *dispatch.ContextRecord;
+                    new_context.ContextFlags &= ~0x40;
+                    *context = new_context;
                     dispatch.ContextRecord = context;
                     RtlVirtualUnwind( UNW_FLAG_NHANDLER, dispatch.ImageBase,
                             dispatch.ControlPc, dispatch.FunctionEntry,
-- 
2.26.2




More information about the wine-devel mailing list