Alexandre Julliard : ntdll: Add a helper function for checking stack frame limits.
Alexandre Julliard
julliard at winehq.org
Tue Feb 1 12:24:58 CST 2011
Module: wine
Branch: master
Commit: efbe69514759930257ccaf131563fd3af563677f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=efbe69514759930257ccaf131563fd3af563677f
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Feb 1 12:18:39 2011 +0100
ntdll: Add a helper function for checking stack frame limits.
---
dlls/ntdll/signal_i386.c | 27 ++++++++++++++-------------
1 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c
index 69c9c3f..13444ae 100644
--- a/dlls/ntdll/signal_i386.c
+++ b/dlls/ntdll/signal_i386.c
@@ -548,6 +548,16 @@ static inline TEB *get_current_teb(void)
/*******************************************************************
+ * is_valid_frame
+ */
+static inline BOOL is_valid_frame( void *frame )
+{
+ if ((ULONG_PTR)frame & 3) return FALSE;
+ return (frame >= NtCurrentTeb()->Tib.StackLimit &&
+ (void **)frame < (void **)NtCurrentTeb()->Tib.StackBase - 1);
+}
+
+/*******************************************************************
* raise_handler
*
* Handler for exceptions happening inside a handler.
@@ -594,9 +604,7 @@ static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
while (frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL)
{
/* Check frame address */
- if (((void*)frame < NtCurrentTeb()->Tib.StackLimit) ||
- ((void*)(frame+1) > NtCurrentTeb()->Tib.StackBase) ||
- (ULONG_PTR)frame & 3)
+ if (!is_valid_frame( frame ))
{
rec->ExceptionFlags |= EH_STACK_INVALID;
break;
@@ -2381,10 +2389,7 @@ void WINAPI __regs_RtlUnwind( EXCEPTION_REGISTRATION_RECORD* pEndFrame, PVOID ta
if (pEndFrame && (frame > pEndFrame))
raise_status( STATUS_INVALID_UNWIND_TARGET, pRecord );
- if (((void*)frame < NtCurrentTeb()->Tib.StackLimit) ||
- ((void*)(frame+1) > NtCurrentTeb()->Tib.StackBase) ||
- (UINT_PTR)frame & 3)
- raise_status( STATUS_BAD_STACK, pRecord );
+ if (!is_valid_frame( frame )) raise_status( STATUS_BAD_STACK, pRecord );
/* Call handler */
TRACE( "calling handler at %p code=%x flags=%x\n",
@@ -2453,17 +2458,13 @@ USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer,
while (skip--)
{
- if (((void *)frame < NtCurrentTeb()->Tib.StackLimit) ||
- ((void *)(frame + 1) >= NtCurrentTeb()->Tib.StackBase) ||
- ((ULONG_PTR)frame & 3)) return 0;
+ if (!is_valid_frame( frame )) return 0;
frame = (ULONG *)*frame;
}
for (i = 0; i < count; i++)
{
- if (((void *)frame < NtCurrentTeb()->Tib.StackLimit) ||
- ((void *)(frame + 1) >= NtCurrentTeb()->Tib.StackBase) ||
- ((ULONG_PTR)frame & 3)) break;
+ if (!is_valid_frame( frame )) break;
buffer[i] = (void *)frame[1];
if (hash) *hash += frame[1];
frame = (ULONG *)*frame;
More information about the wine-cvs
mailing list