From: Florian Menne Date: Sun, 21 Nov 2010 21:11:07 +0000 (+0100) Subject: Some function to check if a host is running in a virtual environment. X-Git-Tag: v0.2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cd8b976810f2ce8076b19d7e9f4351181528a31;p=oddments%2Ffireinfo.git Some function to check if a host is running in a virtual environment. --- diff --git a/src/fireinfo.c b/src/fireinfo.c index c9c5700..1ff0ae0 100644 --- a/src/fireinfo.c +++ b/src/fireinfo.c @@ -19,6 +19,7 @@ #include +#include #include /* @@ -396,6 +397,22 @@ read_hypervisor(struct lscpu_desc *desc) } } +static bool +is_virtualized() { + unsigned int eax, ebx, ecx, edx; + + cpuid(0x1, &eax, &ebx, &ecx, &edx); + + /* + Bitwise detection of the 31st bit. + This indicates if a host runs in a virtual environment. + */ + if (ecx & (1<<31)) + return true; + + return false; +} + static PyObject * do_cpuinfo() { /*