made vmware-detect.c compile on all archs, implemented check for amd64
authorMichael Gebetsroither <michael.geb@gmx.at>
Sun, 24 Dec 2006 11:37:36 +0000 (12:37 +0100)
committerMichael Gebetsroither <michael.geb@gmx.at>
Sun, 24 Dec 2006 11:37:36 +0000 (12:37 +0100)
compile/vmware-detect.c

index d242a38..f3875a7 100644 (file)
@@ -1,13 +1,24 @@
-#include <stdio.h>
+#if defined (__i386__)
+int checkVmware()
+{
+    unsigned char idtr[6];
+    asm("sidt %0" : "=m" (idtr));
+    return (0xff==idtr[5]) ? 0 : 1;
+}
+#elif defined (__x86_64__)
+// only guessed, possible need to check against 0xffff?
+int checkVmware()
+{
+    unsigned char idtr[10];
+    asm("sidt %0" : "=m" (idtr));
+    return (0xff==idtr[9]) ? 0 : 1;
+}
+#else
+// vmware runs only on the archs above
+int checkVmware() { return 1; }
+#endif
+
 int main() {
-  unsigned char idtr[6];
-  asm("sidt %0" : "=m" (idtr));
-  if(0xff==idtr[5])
-  {
-    return 0;
-  }
-  else
-  {
-    return 1;
-  }
+    // returns 0 if running inside vmware, 1 otherwise
+    return checkVmware();
 }