Module: wine Branch: master Commit: 8fe95d29d32533e8fa28383c0211555eb71ea6c1 URL: https://gitlab.winehq.org/wine/wine/-/commit/8fe95d29d32533e8fa28383c0211555...
Author: Alexandre Julliard julliard@winehq.org Date: Wed Jan 31 12:13:55 2024 +0100
ntdll: Only call TEB handlers for frames inside the current stack.
---
dlls/ntdll/signal_arm.c | 8 +++++--- dlls/ntdll/signal_arm64.c | 8 +++++--- dlls/ntdll/signal_x86_64.c | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/dlls/ntdll/signal_arm.c b/dlls/ntdll/signal_arm.c index d347004b601..7a6c71927f6 100644 --- a/dlls/ntdll/signal_arm.c +++ b/dlls/ntdll/signal_arm.c @@ -445,7 +445,7 @@ static NTSTATUS call_function_handlers( EXCEPTION_RECORD *rec, CONTEXT *orig_con } } /* hack: call wine handlers registered in the tib list */ - else while ((DWORD)teb_frame < context.Sp) + else while (is_valid_frame( (ULONG_PTR)teb_frame ) && (DWORD)teb_frame < context.Sp) { TRACE( "found wine frame %p rsp %lx handler %p\n", teb_frame, context.Sp, teb_frame->Handler ); @@ -1294,7 +1294,7 @@ void CDECL RtlRestoreContext( CONTEXT *context, EXCEPTION_RECORD *rec ) }
/* hack: remove no longer accessible TEB frames */ - while ((DWORD)teb_frame < context->Sp) + while (is_valid_frame( (ULONG_PTR)teb_frame ) && (DWORD)teb_frame < context->Sp) { TRACE( "removing TEB frame: %p\n", teb_frame ); teb_frame = __wine_pop_frame( teb_frame ); @@ -1394,7 +1394,9 @@ void WINAPI RtlUnwindEx( PVOID end_frame, PVOID target_ip, EXCEPTION_RECORD *rec else /* hack: call builtin handlers registered in the tib list */ { DWORD backup_frame = dispatch.EstablisherFrame; - while ((DWORD)teb_frame < new_context.Sp && (DWORD)teb_frame < (DWORD)end_frame) + while (is_valid_frame( (ULONG_PTR)teb_frame ) && + (DWORD)teb_frame < new_context.Sp && + (DWORD)teb_frame < (DWORD)end_frame) { TRACE( "found builtin frame %p handler %p\n", teb_frame, teb_frame->Handler ); dispatch.EstablisherFrame = (DWORD)teb_frame; diff --git a/dlls/ntdll/signal_arm64.c b/dlls/ntdll/signal_arm64.c index c487e07a336..9e2431a6b33 100644 --- a/dlls/ntdll/signal_arm64.c +++ b/dlls/ntdll/signal_arm64.c @@ -418,7 +418,7 @@ static NTSTATUS call_function_handlers( EXCEPTION_RECORD *rec, CONTEXT *orig_con } } /* hack: call wine handlers registered in the tib list */ - else while ((ULONG64)teb_frame < context.Sp) + else while (is_valid_frame( (ULONG_PTR)teb_frame ) && (ULONG64)teb_frame < context.Sp) { TRACE( "found wine frame %p rsp %I64x handler %p\n", teb_frame, context.Sp, teb_frame->Handler ); @@ -1188,7 +1188,7 @@ void CDECL RtlRestoreContext( CONTEXT *context, EXCEPTION_RECORD *rec ) }
/* hack: remove no longer accessible TEB frames */ - while ((ULONG64)teb_frame < context->Sp) + while (is_valid_frame( (ULONG_PTR)teb_frame ) && (ULONG64)teb_frame < context->Sp) { TRACE( "removing TEB frame: %p\n", teb_frame ); teb_frame = __wine_pop_frame( teb_frame ); @@ -1295,7 +1295,9 @@ void WINAPI RtlUnwindEx( PVOID end_frame, PVOID target_ip, EXCEPTION_RECORD *rec else /* hack: call builtin handlers registered in the tib list */ { DWORD64 backup_frame = dispatch.EstablisherFrame; - while ((ULONG64)teb_frame < new_context.Sp && (ULONG64)teb_frame < (ULONG64)end_frame) + while (is_valid_frame( (ULONG_PTR)teb_frame ) && + (ULONG64)teb_frame < new_context.Sp && + (ULONG64)teb_frame < (ULONG64)end_frame) { TRACE( "found builtin frame %p handler %p\n", teb_frame, teb_frame->Handler ); dispatch.EstablisherFrame = (ULONG64)teb_frame; diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c index 30014d925d9..998e09179b4 100644 --- a/dlls/ntdll/signal_x86_64.c +++ b/dlls/ntdll/signal_x86_64.c @@ -491,7 +491,7 @@ static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *orig_contex } } /* hack: call wine handlers registered in the tib list */ - else while ((ULONG64)teb_frame < context.Rsp) + else while (is_valid_frame( (ULONG_PTR)teb_frame ) && (ULONG64)teb_frame < context.Rsp) { TRACE_(seh)( "found wine frame %p rsp %p handler %p\n", teb_frame, (void *)context.Rsp, teb_frame->Handler ); @@ -1321,7 +1321,7 @@ void CDECL RtlRestoreContext( CONTEXT *context, EXCEPTION_RECORD *rec ) }
/* hack: remove no longer accessible TEB frames */ - while ((ULONG64)teb_frame < context->Rsp) + while (is_valid_frame( (ULONG_PTR)teb_frame ) && (ULONG64)teb_frame < context->Rsp) { TRACE_(seh)( "removing TEB frame: %p\n", teb_frame ); teb_frame = __wine_pop_frame( teb_frame ); @@ -1422,7 +1422,9 @@ void WINAPI RtlUnwindEx( PVOID end_frame, PVOID target_ip, EXCEPTION_RECORD *rec else /* hack: call builtin handlers registered in the tib list */ { DWORD64 backup_frame = dispatch.EstablisherFrame; - while ((ULONG64)teb_frame < new_context.Rsp && (ULONG64)teb_frame < (ULONG64)end_frame) + while (is_valid_frame( (ULONG_PTR)teb_frame ) && + (ULONG64)teb_frame < new_context.Rsp && + (ULONG64)teb_frame < (ULONG64)end_frame) { TRACE( "found builtin frame %p handler %p\n", teb_frame, teb_frame->Handler ); dispatch.EstablisherFrame = (ULONG64)teb_frame;