From 6b3c8a5f9a2abc6f978164b8ffdbb8c93e86da6f Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Sat, 22 Oct 2005 14:05:20 +0000 Subject: [PATCH] - 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 svn path=/trunk/; revision=18676 --- reactos/lib/ntdll/main/dispatch.c | 26 +++++++++++++++++++------ reactos/lib/ntdll/main/i386/dispatch.S | 11 ++++++++++- reactos/lib/rtl/vectoreh.c | 2 +- reactos/subsys/system/vmwinst/vmwinst.c | 26 ++++++++++++++----------- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/reactos/lib/ntdll/main/dispatch.c b/reactos/lib/ntdll/main/dispatch.c index 9738e6e9b94..babb174cd96 100644 --- a/reactos/lib/ntdll/main/dispatch.c +++ b/reactos/lib/ntdll/main/dispatch.c @@ -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 @@ KiUserExceptionDispatcher(PEXCEPTION_RECORD ExceptionRecord, 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 */ diff --git a/reactos/lib/ntdll/main/i386/dispatch.S b/reactos/lib/ntdll/main/i386/dispatch.S index b3ba97e9f64..4389e931021 100644 --- a/reactos/lib/ntdll/main/i386/dispatch.S +++ b/reactos/lib/ntdll/main/i386/dispatch.S @@ -141,15 +141,24 @@ _KiUserExceptionDispatcher@8: 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 diff --git a/reactos/lib/rtl/vectoreh.c b/reactos/lib/rtl/vectoreh.c index 771dbb4b83b..ff74f676a11 100644 --- a/reactos/lib/rtl/vectoreh.c +++ b/reactos/lib/rtl/vectoreh.c @@ -28,7 +28,7 @@ typedef struct _RTL_VECTORED_EXCEPTION_HANDLER /* FUNCTIONS ***************************************************************/ -EXCEPTION_DISPOSITION +EXCEPTION_DISPOSITION NTAPI RtlpExecuteVectoredExceptionHandlers(IN PEXCEPTION_RECORD ExceptionRecord, IN PCONTEXT Context) { diff --git a/reactos/subsys/system/vmwinst/vmwinst.c b/reactos/subsys/system/vmwinst/vmwinst.c index c5e5642c21c..ce10e542989 100644 --- a/reactos/subsys/system/vmwinst/vmwinst.c +++ b/reactos/subsys/system/vmwinst/vmwinst.c @@ -60,10 +60,9 @@ static LONG AbortInstall = 0; /* 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 @@ WinMain(HINSTANCE hInstance, int nCmdShow) { - LPTOP_LEVEL_EXCEPTION_FILTER OldHandler; + PVOID ExceptionHandler; int Version; WCHAR *lc; hAppInstance = hInstance; - /* Setup our exception "handler" ;-) */ - OldHandler = SetUnhandledExceptionFilter(ExceptionHandler); - - if(!DetectVMware(&Version)) + /* 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))) { - ExitProcess(1); return 1; } - /* restore the exception handler */ - SetUnhandledExceptionFilter(OldHandler); + if(!DetectVMware(&Version)) + { + return 1; + } + + /* unregister the handler */ + RemoveVectoredExceptionHandler(ExceptionHandler); lc = DestinationPath; lc += GetSystemDirectory(DestinationPath, MAX_PATH) - 1;