From 36ce07093b68b07513149577c209ae7a57ab356b Mon Sep 17 00:00:00 2001
From: Gabriele Contini <contini.mailing@gmail.com>
Date: 周日, 15 3月 2020 16:26:21 +0800
Subject: [PATCH] Merge branch 'feature/pc_identifiers' into develop issues #2 #3 #14 #49

---
 src/library/os/cpu_info_common.cpp |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/library/os/cpu_info_common.cpp b/src/library/os/cpu_info_common.cpp
new file mode 100644
index 0000000..1ddf5ba
--- /dev/null
+++ b/src/library/os/cpu_info_common.cpp
@@ -0,0 +1,45 @@
+/*
+ * cpu_info_common.cpp
+ *
+ *  Created on: Jan 19, 2020
+ *      Author: GC
+ */
+#include <unordered_map>
+#include "cpu_info.hpp"
+
+namespace license {
+namespace os {
+using namespace std;
+
+const unordered_map<string, VIRTUALIZATION_DETAIL> virtual_cpu_names{
+	{"bhyve bhyve ", V_OTHER}, {"KVMKVMKVM", KVM},		  {"Microsoft Hv", HV},
+	{" lrpepyh vr", HV},	   {"prl hyperv  ", V_OTHER}, {"VMwareVMware", VMWARE},
+	{"XenVMMXenVMM", V_XEN},   {"ACRNACRNACRN", V_OTHER}, {"VBoxVBoxVBox", VIRTUALBOX}};
+
+/**
+ * Detect Virtual machine using hypervisor bit.
+ * @return true if the cpu hypervisor bit is set to 1
+ */
+bool CpuInfo::cpu_virtual() const {
+	bool is_virtual = is_hypervisor_set();
+	if (!is_virtual) {
+		string cpu_vendor = vendor();
+		auto it = virtual_cpu_names.find(cpu_vendor);
+		is_virtual = (it != virtual_cpu_names.end());
+	}
+	return is_virtual;
+}
+
+VIRTUALIZATION_DETAIL CpuInfo::virtualization_details() const {
+	string cpu_vendor = vendor();
+	auto it = virtual_cpu_names.find(cpu_vendor);
+	VIRTUALIZATION_DETAIL result = BARE_TO_METAL;
+	if (it != virtual_cpu_names.end()) {
+		result = it->second;
+	} else if (is_hypervisor_set()) {
+		result = (VIRTUALIZATION_DETAIL)V_OTHER;
+	}
+	return result;
+}
+}  // namespace os
+}  // namespace license

--
Gitblit v1.9.1