Author: hyperion
Date: Sat Aug 8 20:03:48 2009
New Revision: 42530
URL:
http://svn.reactos.org/svn/reactos?rev=42530&view=rev
Log:
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
Modified:
trunk/reactos/base/setup/vmwinst/vmwinst.c
trunk/reactos/base/setup/vmwinst/vmwinst.rbuild
Modified: trunk/reactos/base/setup/vmwinst/vmwinst.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/vmwinst/vmwinst…
==============================================================================
--- trunk/reactos/base/setup/vmwinst/vmwinst.c [iso-8859-1] (original)
+++ trunk/reactos/base/setup/vmwinst/vmwinst.c [iso-8859-1] Sat Aug 8 20:03:48 2009
@@ -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 @@
#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 @@
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,28 +1048,15 @@
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)))
+ if(!DetectVMware(&Version))
{
return 1;
}
-
- if(!DetectVMware(&Version))
- {
- return 1;
- }
-
- /* unregister the handler */
- RemoveVectoredExceptionHandler(ExceptionHandler);
lc = DestinationPath;
lc += GetSystemDirectory(DestinationPath, MAX_PATH) - 1;
Modified: trunk/reactos/base/setup/vmwinst/vmwinst.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/setup/vmwinst/vmwinst…
==============================================================================
--- trunk/reactos/base/setup/vmwinst/vmwinst.rbuild [iso-8859-1] (original)
+++ trunk/reactos/base/setup/vmwinst/vmwinst.rbuild [iso-8859-1] Sat Aug 8 20:03:48 2009
@@ -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>