From b7cb2a38aa6f3daffcd8c7b0581be5e5822c58da Mon Sep 17 00:00:00 2001 From: "KJK::Hyperion" Date: Sat, 8 Aug 2009 18:03:48 +0000 Subject: [PATCH] modified base/setup/vmwinst/vmwinst.c modified base/setup/vmwinst/vmwinst.rbuild Implement VMWare detection for Visual C++ as well For cleaner code, use SEH instead of VEH, even if it means losing this pearl of ReactOS wisdom: /* 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... */ (www.passiveaggressivecommits.com, brought to you by Arch Blackmann!) Of course, it also means trading our VEH bugs for our SEH bugs, so I'm not sure if it was worth changing svn path=/trunk/; revision=42530 --- reactos/base/setup/vmwinst/vmwinst.c | 57 +++++++++++------------ reactos/base/setup/vmwinst/vmwinst.rbuild | 1 + 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/reactos/base/setup/vmwinst/vmwinst.c b/reactos/base/setup/vmwinst/vmwinst.c index dbfc9de36fa..e76a0e563b2 100644 --- a/reactos/base/setup/vmwinst/vmwinst.c +++ b/reactos/base/setup/vmwinst/vmwinst.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "vmwinst.h" #include @@ -61,14 +62,6 @@ static LONG AbortInstall = 0; #define WM_INSTSTATUSUPDATE (WM_USER + 4) /* Helper functions */ - -LONG CALLBACK VectoredExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) -{ - /* we're not running in VMware, just terminate the process */ - ExitProcess(ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION); - return EXCEPTION_CONTINUE_EXECUTION; -} - BOOL DetectVMware(int *Version) { @@ -77,16 +70,35 @@ DetectVMware(int *Version) magic = 0; ver = 0; - /* Try using a VMware I/O port. If not running in VMware this'll throw an - exception! */ -#ifndef _MSC_VER - __asm__ __volatile__("inl %%dx, %%eax" - : "=a" (ver), "=b" (magic) - : "0" (0x564d5868), "d" (0x5658), "c" (0xa)); + _SEH2_TRY + { + /* Try using a VMware I/O port. If not running in VMware this'll throw an + exception! */ +#if defined(__GNUC__) + __asm__ __volatile__("inl %%dx, %%eax" + : "=a" (ver), "=b" (magic) + : "0" (0x564d5868), "d" (0x5658), "c" (0xa)); +#elif defined(_MSC_VER) + __asm + { + push ebx + mov ecx, 0xa + mov edx, 0x5658 + mov eax, 0x564d5868 + in eax, dx + mov [ver], eax + mov [magic], ebx + pop ebx + } #else -#error PLEASE WRITE THIS IN ASSEMBLY +#error TODO #endif - + } + _SEH2_EXCEPT(_SEH2_GetExceptionCode() == EXCEPTION_PRIV_INSTRUCTION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) + { + return FALSE; + } + _SEH2_END; if(magic == 0x564d5868) { @@ -1036,29 +1048,16 @@ wWinMain(HINSTANCE hInstance, int nCmdShow) { - PVOID ExceptionHandler; int Version; WCHAR *lc; hAppInstance = hInstance; - /* 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)) { return 1; } - /* unregister the handler */ - RemoveVectoredExceptionHandler(ExceptionHandler); - lc = DestinationPath; lc += GetSystemDirectory(DestinationPath, MAX_PATH) - 1; if(lc >= DestinationPath && *lc != L'\\') diff --git a/reactos/base/setup/vmwinst/vmwinst.rbuild b/reactos/base/setup/vmwinst/vmwinst.rbuild index 343cb8e083f..a7c7fe15060 100644 --- a/reactos/base/setup/vmwinst/vmwinst.rbuild +++ b/reactos/base/setup/vmwinst/vmwinst.rbuild @@ -11,6 +11,7 @@ setupapi shell32 ntdll + pseh vmwinst.c vmwinst.rc