made vmware-detect.c compile on all archs, implemented check for amd64
[grml-scripts.git] / compile / vmware-detect.c
1 #if defined (__i386__)
2 int checkVmware()
3 {
4     unsigned char idtr[6];
5     asm("sidt %0" : "=m" (idtr));
6     return (0xff==idtr[5]) ? 0 : 1;
7 }
8 #elif defined (__x86_64__)
9 // only guessed, possible need to check against 0xffff?
10 int checkVmware()
11 {
12     unsigned char idtr[10];
13     asm("sidt %0" : "=m" (idtr));
14     return (0xff==idtr[9]) ? 0 : 1;
15 }
16 #else
17 // vmware runs only on the archs above
18 int checkVmware() { return 1; }
19 #endif
20
21 int main() {
22     // returns 0 if running inside vmware, 1 otherwise
23     return checkVmware();
24 }