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
This commit is contained in:
KJK::Hyperion 2009-08-08 18:03:48 +00:00
parent e50fa1e50e
commit b7cb2a38aa
2 changed files with 29 additions and 29 deletions

View file

@ -29,6 +29,7 @@
#include <newdev.h>
#include <stdio.h>
#include <string.h>
#include <pseh/pseh2.h>
#include "vmwinst.h"
#include <debug.h>
@ -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'\\')

View file

@ -11,6 +11,7 @@
<library>setupapi</library>
<library>shell32</library>
<library>ntdll</library>
<library>pseh</library>
<file>vmwinst.c</file>
<file>vmwinst.rc</file>
</module>