- re-add support for vectored exception handling which was removed by the major refactoring patch (r17811)
- make vmwinst depend on vectored exception handling so this doesn't happen again
Modified: trunk/reactos/lib/ntdll/main/dispatch.c
Modified: trunk/reactos/lib/ntdll/main/i386/dispatch.S
Modified: trunk/reactos/lib/rtl/vectoreh.c
Modified: trunk/reactos/subsys/system/vmwinst/vmwinst.c

Modified: trunk/reactos/lib/ntdll/main/dispatch.c
--- trunk/reactos/lib/ntdll/main/dispatch.c	2005-10-22 13:37:48 UTC (rev 18675)
+++ trunk/reactos/lib/ntdll/main/dispatch.c	2005-10-22 14:05:20 UTC (rev 18676)
@@ -14,6 +14,10 @@
 
 typedef NTSTATUS (NTAPI *USER_CALL)(PVOID Argument, ULONG ArgumentLength);
 
+EXCEPTION_DISPOSITION NTAPI
+RtlpExecuteVectoredExceptionHandlers(IN PEXCEPTION_RECORD  ExceptionRecord,
+                                     IN PCONTEXT  Context);
+
 /* FUNCTIONS ****************************************************************/
 
 /*
@@ -27,16 +31,26 @@
     EXCEPTION_RECORD NestedExceptionRecord;
     NTSTATUS Status;
 
-    /* Dispatch the exception and check the result */
-    if(RtlDispatchException(ExceptionRecord, Context))
+    /* call the vectored exception handlers */
+    if(RtlpExecuteVectoredExceptionHandlers(ExceptionRecord,
+                                            Context) != ExceptionContinueExecution)
     {
-        /* Continue executing */
-        Status = NtContinue(Context, FALSE);
+        goto ContinueExecution;
     }
     else
     {
-        /* Raise an exception */
-        Status = NtRaiseException(ExceptionRecord, Context, FALSE);
+        /* Dispatch the exception and check the result */
+        if(RtlDispatchException(ExceptionRecord, Context))
+        {
+ContinueExecution:
+            /* Continue executing */
+            Status = NtContinue(Context, FALSE);
+        }
+        else
+        {
+            /* Raise an exception */
+            Status = NtRaiseException(ExceptionRecord, Context, FALSE);
+        }
     }
 
     /* Setup the Exception record */

Modified: trunk/reactos/lib/ntdll/main/i386/dispatch.S
--- trunk/reactos/lib/ntdll/main/i386/dispatch.S	2005-10-22 13:37:48 UTC (rev 18675)
+++ trunk/reactos/lib/ntdll/main/i386/dispatch.S	2005-10-22 14:05:20 UTC (rev 18676)
@@ -141,15 +141,24 @@
     mov ecx, [esp+4]
     mov ebx, [esp]
 
-    /* Dispatch the exception */
     push ecx
     push ebx
+
+    /* Call the vectored exception handler */
+    call _RtlpExecuteVectoredExceptionHandlers@8
+
+    /* Check for success */
+    or al, al
+    jnz ContinueExecution
+
+    /* Dispatch the exception */
     call _RtlDispatchException@8
 
     /* Check for success */
     or al, al
     jz RaiseException
 
+ContinueExecution:
     /* Pop off the records */
     pop ebx
     pop ecx

Modified: trunk/reactos/lib/rtl/vectoreh.c
--- trunk/reactos/lib/rtl/vectoreh.c	2005-10-22 13:37:48 UTC (rev 18675)
+++ trunk/reactos/lib/rtl/vectoreh.c	2005-10-22 14:05:20 UTC (rev 18676)
@@ -28,7 +28,7 @@
 
 /* FUNCTIONS ***************************************************************/
 
-EXCEPTION_DISPOSITION
+EXCEPTION_DISPOSITION NTAPI
 RtlpExecuteVectoredExceptionHandlers(IN PEXCEPTION_RECORD  ExceptionRecord,
                                      IN PCONTEXT  Context)
 {

Modified: trunk/reactos/subsys/system/vmwinst/vmwinst.c
--- trunk/reactos/subsys/system/vmwinst/vmwinst.c	2005-10-22 13:37:48 UTC (rev 18675)
+++ trunk/reactos/subsys/system/vmwinst/vmwinst.c	2005-10-22 14:05:20 UTC (rev 18676)
@@ -60,10 +60,9 @@
 
 /* Helper functions */
 
-LONG WINAPI ExceptionHandler(LPEXCEPTION_POINTERS ExceptionInfo)
+LONG CALLBACK VectoredExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo)
 {
-  /* This is rude, but i don't know how to continue execution properly, that's why
-     we just exit here when we're not running inside of VMware */
+  /* we're not running in VMware, just terminate the process */
   ExitProcess(ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION);
   return EXCEPTION_CONTINUE_EXECUTION;
 }
@@ -1196,23 +1195,28 @@
 	int nCmdShow)
 {
 
-  LPTOP_LEVEL_EXCEPTION_FILTER OldHandler;
+  PVOID ExceptionHandler;
   int Version;
   WCHAR *lc;
 
   hAppInstance = hInstance;
 
-  /* Setup our exception "handler" ;-) */
-  OldHandler = SetUnhandledExceptionFilter(ExceptionHandler);
+  /* Setup a vectored exception handler to protect the detection. Don't use SEH
+     here so we notice the next time someone removes support for vectored
+     exception handling from ros... */
+  if (!(ExceptionHandler = AddVectoredExceptionHandler(0,
+                                                       VectoredExceptionHandler)))
+  {
+    return 1;
+  }
 
   if(!DetectVMware(&Version))
   {
-    ExitProcess(1);
     return 1;
   }
 
-  /* restore the exception handler */
-  SetUnhandledExceptionFilter(OldHandler);
+  /* unregister the handler */
+  RemoveVectoredExceptionHandler(ExceptionHandler);
 
   lc = DestinationPath;
   lc += GetSystemDirectory(DestinationPath, MAX_PATH) - 1;