|
@@ -41,6 +41,8 @@
|
|
|
|
|
|
#define _BASEBOARD_PATH "/tmp/BASEBOARD"
|
|
#define _BASEBOARD_PATH "/tmp/BASEBOARD"
|
|
#define _DISPLAY_SIG_TIVA "DISPLAY001"
|
|
#define _DISPLAY_SIG_TIVA "DISPLAY001"
|
|
|
|
+#define _CPUINFO_PATH "/proc/cpuinfo"
|
|
|
|
+#define _VM_TAG "hypervisor"
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
@@ -109,12 +111,12 @@ CSysInfo::~CSysInfo(void)
|
|
|
|
|
|
static const char* _FileToStdString(const char *pszFilepath, std::string &str)
|
|
static const char* _FileToStdString(const char *pszFilepath, std::string &str)
|
|
{
|
|
{
|
|
- std::ifstream fBoot(pszFilepath);
|
|
|
|
|
|
+ std::ifstream ifs(pszFilepath);
|
|
str.clear();
|
|
str.clear();
|
|
|
|
|
|
- if(fBoot.good())
|
|
|
|
|
|
+ if(ifs.good())
|
|
{
|
|
{
|
|
- str.assign((std::istreambuf_iterator<char>(fBoot)), std::istreambuf_iterator<char>());
|
|
|
|
|
|
+ str.assign((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
|
return str.c_str();
|
|
return str.c_str();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -201,6 +203,47 @@ GfATargetTypes CSysInfo::GetTargetType(char *pszTargetType, size_t nCChTargetTyp
|
|
return tt;
|
|
return tt;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/////////////////////////////////////////////////////////////////////////////
|
|
|
|
+
|
|
|
|
+bool CSysInfo::IsHypervised(void)
|
|
|
|
+{
|
|
|
|
+ std::string sCpuInfo;
|
|
|
|
+ if(_FileToStdString(_CPUINFO_PATH, sCpuInfo))
|
|
|
|
+ {
|
|
|
|
+ size_t nPos = sCpuInfo.find("\nflags\t\t:");
|
|
|
|
+
|
|
|
|
+ if(nPos != std::string::npos)
|
|
|
|
+ {
|
|
|
|
+ const char *pszStart = sCpuInfo.c_str() + nPos + 9;
|
|
|
|
+ const char *pszEnd = strchrnul(pszStart, '\n');
|
|
|
|
+ std::string sFlags(pszStart, pszEnd);
|
|
|
|
+
|
|
|
|
+ if((nPos = sFlags.find(_VM_TAG)) != std::string::npos)
|
|
|
|
+ {
|
|
|
|
+ const char *pszStart2 = &sFlags[nPos];
|
|
|
|
+ const char *pszEnd2 = pszStart2 + 10;
|
|
|
|
+
|
|
|
|
+ if(pszStart2 > pszStart)
|
|
|
|
+ {
|
|
|
|
+ if(isalnum((uint8_t)*(pszStart2 - 1)))
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(pszEnd2 < pszEnd)
|
|
|
|
+ {
|
|
|
|
+ if(isalnum((uint8_t)*pszEnd2))
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ //
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// https://github.com/torvalds/linux/blob/master/Documentation/filesystems/proc.rst
|
|
// https://github.com/torvalds/linux/blob/master/Documentation/filesystems/proc.rst
|
|
|
|
|
|
@@ -279,3 +322,8 @@ extern "C" GfATargetTypes GfAIpcGetTargetType(char *pszTargetType, size_t nCChTa
|
|
{
|
|
{
|
|
return CSysInfo::GetTargetType(pszTargetType, nCChTargetType);
|
|
return CSysInfo::GetTargetType(pszTargetType, nCChTargetType);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+extern "C" bool GfAIpcSystemIsHypervised(void)
|
|
|
|
+{
|
|
|
|
+ return CSysInfo::IsHypervised();
|
|
|
|
+}
|