From: Michael Gebetsroither Date: Sun, 24 Dec 2006 11:37:36 +0000 (+0100) Subject: made vmware-detect.c compile on all archs, implemented check for amd64 X-Git-Tag: 0.9.12~7 X-Git-Url: http://git.grml.org/?p=grml-scripts.git;a=commitdiff_plain;h=8d76b94df26f5ab327a69a036a664872f2df9fca made vmware-detect.c compile on all archs, implemented check for amd64 --- diff --git a/compile/vmware-detect.c b/compile/vmware-detect.c index d242a38..f3875a7 100644 --- a/compile/vmware-detect.c +++ b/compile/vmware-detect.c @@ -1,13 +1,24 @@ -#include +#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(); }