[ntdll] Don't use esp returned from exception handler

Glenn Wurster gwurster at scs.carleton.ca
Sat Aug 20 16:30:22 CDT 2005


Windows does not honour changes to the ESP variable made by a
userspace exception handler.  Therefore we should not either.

Changelog:
  Ignore modifications to ESP made by a userspace exception handler.

Glenn.

Index: dlls/ntdll/exception.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/exception.c,v
retrieving revision 1.81
diff -u -r1.81 exception.c
--- dlls/ntdll/exception.c	25 Jun 2005 18:31:00 -0000	1.81
+++ dlls/ntdll/exception.c	20 Aug 2005 20:46:15 -0000
@@ -227,6 +227,9 @@
     EXCEPTION_REGISTRATION_RECORD *frame, *dispatch, *nested_frame;
     EXCEPTION_RECORD newrec;
     DWORD res, c;
+#ifdef __i386__
+    DWORD old_esp = context->Esp;
+#endif
 
     TRACE( "code=%lx flags=%lx addr=%p\n", rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
     for (c=0; c<rec->NumberParameters; c++) TRACE(" info[%ld]=%08lx\n", c, rec->ExceptionInformation[c]);
@@ -255,7 +258,12 @@
 
     if (send_debug_event( rec, TRUE, context ) == DBG_CONTINUE) return;  /* continue execution */
 
-    if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION) return;
+    if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION) {
+#ifdef __i386__
+        context->Esp = old_esp;
+#endif
+        return;
+    }
 
     frame = NtCurrentTeb()->Tib.ExceptionList;
     nested_frame = NULL;
@@ -272,6 +280,9 @@
 
         /* Call handler */
         res = EXC_CallHandler( rec, frame, context, &dispatch, frame->Handler, EXC_RaiseHandler );
+#ifdef __i386__
+        context->Esp = old_esp;
+#endif
         if (frame == nested_frame)
         {
             /* no longer nested */



More information about the wine-patches mailing list