|
44 | 44 | namespace haxm {
|
45 | 45 | namespace check_util {
|
46 | 46 |
|
| 47 | +enum Check { |
| 48 | + // Hardware support bit |
| 49 | + kCpuSupported = 0, |
| 50 | + kVmxSupported = 1, |
| 51 | + kNxSupported = 2, |
| 52 | + kEm64tSupported = 3, |
| 53 | + kEptSupported = 4, |
| 54 | + // BIOS configuration bit |
| 55 | + kVmxEnabled = 8, |
| 56 | + kNxEnabled = 9, |
| 57 | + kEm64tEnabled = 10, |
| 58 | + // Host status bit |
| 59 | + kOsVerSupported = 16, |
| 60 | + kOsArchSupported = 17, |
| 61 | + kHypervDisabled = 18, |
| 62 | + kSandboxDisabled = 19, |
| 63 | + // Guest status bit |
| 64 | + kGuestUnoccupied = 24, |
| 65 | + kMaxCheck = 32 |
| 66 | +}; |
| 67 | + |
| 68 | +enum CheckFlag { |
| 69 | + // Hardware support flag |
| 70 | + kFlagCpuSupported = 1 << kCpuSupported, |
| 71 | + kFlagVmxSupported = 1 << kVmxSupported, |
| 72 | + kFlagNxSupported = 1 << kNxSupported, |
| 73 | + kFlagEm64tSupported = 1 << kEm64tSupported, |
| 74 | + kFlagEptSupported = 1 << kEptSupported, |
| 75 | + // BIOS configuration flag |
| 76 | + kFlagVmxEnabled = 1 << kVmxEnabled, |
| 77 | + kFlagNxEnabled = 1 << kNxEnabled, |
| 78 | + kFlagEm64tEnabled = 1 << kEm64tEnabled, |
| 79 | + // Host status flag |
| 80 | + kFlagOsverSupported = 1 << kOsVerSupported, |
| 81 | + kFlagOsarchSupported = 1 << kOsArchSupported, |
| 82 | + kFlagHypervDisabled = 1 << kHypervDisabled, |
| 83 | + kFlagSandboxDisabled = 1 << kSandboxDisabled, |
| 84 | + // Guest status flag |
| 85 | + kFlagGuestUnoccupied = 1 << kGuestUnoccupied |
| 86 | +}; |
| 87 | + |
47 | 88 | FeatureDetector::FeatureDetector() {
|
| 89 | + status_ = 0; |
48 | 90 | os_ = new OsImpl();
|
49 | 91 | }
|
50 | 92 |
|
@@ -145,47 +187,52 @@ std::string FeatureDetector::ToString(OsType os_type) {
|
145 | 187 | }
|
146 | 188 | }
|
147 | 189 |
|
148 |
| -CheckResult FeatureDetector::Detect() const { |
149 |
| - CheckResult res[11]; |
150 |
| - |
151 |
| - res[0] = CheckCpuVendor(); |
152 |
| - res[1] = CheckLongModeSupported(); |
153 |
| - res[2] = CheckNxSupported(); |
154 |
| - res[3] = CheckNxEnabled(); |
155 |
| - res[4] = CheckOsVersion(); |
156 |
| - res[5] = CheckOsArchitecture(); |
157 |
| - res[6] = CheckGuestOccupied(); |
158 |
| - res[7] = CheckHyperVDisabled(); |
159 |
| - res[8] = CheckVmxSupported(); |
160 |
| - res[9] = CheckVmxEnabled(); |
161 |
| - res[10] = CheckEptSupported(); |
162 |
| - |
163 |
| - int check_num = 11; |
| 190 | +CheckResult FeatureDetector::Detect() { |
| 191 | + CheckResult res[kMaxCheck] = {}; |
| 192 | + int i; |
| 193 | + |
| 194 | + res[kCpuSupported] = CheckCpuVendor(); |
| 195 | + res[kNxSupported] = CheckNxSupported(); |
| 196 | + res[kEm64tSupported] = CheckLongModeSupported(); |
| 197 | + res[kNxEnabled] = CheckNxEnabled(); |
| 198 | + res[kOsVerSupported] = CheckOsVersion(); |
| 199 | + res[kOsArchSupported] = CheckOsArchitecture(); |
| 200 | + res[kHypervDisabled] = CheckHyperVDisabled(); |
| 201 | + res[kGuestUnoccupied] = CheckGuestOccupied(); |
| 202 | + |
164 | 203 | // When Hyper-V is enabled, it will affect the checking results of VMX
|
165 |
| - // supported, VMX enabled and EPT supported, so only the first 8 items are |
| 204 | + // supported, EPT supported and VMX enabled, so only the first 8 items are |
166 | 205 | // checked. When Hyper-V is disabled, all items are checked.
|
167 |
| - if (res[7] == kFail) { |
168 |
| - check_num = 8; |
| 206 | + if (res[kHypervDisabled] != kFail) { |
| 207 | + res[kVmxSupported] = CheckVmxSupported(); |
| 208 | + res[kEptSupported] = CheckEptSupported(); |
| 209 | + res[kVmxEnabled] = CheckVmxEnabled(); |
| 210 | + } |
| 211 | + |
| 212 | + for (i = 0; i < kMaxCheck; ++i) { |
| 213 | + if (res[i] == kFail) { |
| 214 | + status_ |= 1 << i; |
| 215 | + } |
169 | 216 | }
|
170 | 217 |
|
171 |
| - int detector[5] = {}; |
| 218 | + int detector[kMaxResult] = {}; |
172 | 219 |
|
173 |
| - for (int i = 0; i < check_num; ++i) { |
| 220 | + for (i = 0; i < kMaxCheck; ++i) { |
174 | 221 | ++detector[static_cast<int>(res[i])];
|
175 | 222 | }
|
176 | 223 |
|
177 | 224 | if (detector[static_cast<int>(kError)] > 0) {
|
178 | 225 | return kError;
|
179 | 226 | }
|
180 | 227 |
|
181 |
| - if (detector[static_cast<int>(kUnknown)] > 0) { |
182 |
| - return kUnknown; |
183 |
| - } |
184 |
| - |
185 | 228 | if (detector[static_cast<int>(kFail)] > 0) {
|
186 | 229 | return kFail;
|
187 | 230 | }
|
188 | 231 |
|
| 232 | + if (detector[static_cast<int>(kUnknown)] > 0) { |
| 233 | + return kUnknown; |
| 234 | + } |
| 235 | + |
189 | 236 | return kPass;
|
190 | 237 | }
|
191 | 238 |
|
@@ -265,5 +312,9 @@ void FeatureDetector::Print() const {
|
265 | 312 | << occupied_count << " guest(s)" << std::endl;
|
266 | 313 | }
|
267 | 314 |
|
| 315 | +int FeatureDetector::status() const { |
| 316 | + return status_; |
| 317 | +} |
| 318 | + |
268 | 319 | } // namespace check_util
|
269 | 320 | } // namespace haxm
|
0 commit comments