diff --git a/CheckTool/README.md b/CheckTool/README.md index ff4ac2bb..74bed648 100644 --- a/CheckTool/README.md +++ b/CheckTool/README.md @@ -23,7 +23,7 @@ available [here][checktool-release]. ### Usage 1. `cd X:\path\to\CheckTool` -1. `checktool.exe --verbose` +1. `checktool.exe` The output will be as below. @@ -98,7 +98,7 @@ be omitted. ### Usage 1. `cd /path/to/CheckTool` -1. `./checktool --verbose` +1. `./checktool` ### Build @@ -126,7 +126,7 @@ below. | `cmake -DCMAKE_BUILD_TYPE=Release -B build/Release` | `make -C build/Release` -[checktool-release]: https://github.com/intel/haxm/releases/tag/checktool-v1.0.0 +[checktool-release]: https://github.com/intel/haxm/releases/tag/checktool-v1.1.0 [cmake]: https://cmake.org/download/ [install-on-macos]: https://github.com/intel/haxm/wiki/Installation-Instructions-on-macOS diff --git a/CheckTool/common.cpp b/CheckTool/common.cpp index 1c80dd22..8d486842 100644 --- a/CheckTool/common.cpp +++ b/CheckTool/common.cpp @@ -37,49 +37,48 @@ namespace haxm { namespace check_util { -CheckResult ParseArguments(int &argc, char* argv[], bool &is_verbose) { - haxm::check_util::ArgParser arg_parser(argc, argv, {"-h", "--help", "-v", - "--verbose"}); +CheckResult ParseArguments(int &argc, char* argv[]) { + CheckResult res = kPass; + ArgParser arg_parser(argc, argv, {"-h", "--help", "-v", "--version"}); if (!arg_parser.Verify()) { std::cout << "checktool unknown option: " << arg_parser.error() << std::endl; - std::cout << "Usage: checktool [-h | --help] [-v | --verbose]" + std::cout << "Usage: checktool [-h | --help] [-v | --version]" << std::endl; - return haxm::check_util::kError; + return kError; } - if (arg_parser.Test("-h") || arg_parser.Test("--help")) { - std::cout << "CheckTool version " << APP_VERSION << std::endl; - std::cout << "-v, --verbose Show detailed system information" - << std::endl; - return haxm::check_util::kFail; + if (arg_parser.Test("-v") || arg_parser.Test("--version")) { + std::cout << "checktool " << APP_VERSION << std::endl; + std::cout << APP_COPYRIGHT << std::endl; + + res = kFail; } - if (arg_parser.Test("-v") || arg_parser.Test("--verbose")) { - is_verbose = true; + if (arg_parser.Test("-h") || arg_parser.Test("--help")) { + std::cout << "Usage: checktool [-v | --version]" << std::endl; + std::cout << "Check system environment for HAXM." << std::endl; + std::cout << "'*' means passed, while '-' means failed." << std::endl; + + res = kFail; } - return haxm::check_util::kPass; + return res; } -int Check(bool is_verbose) { - int ret = 0; - - haxm::check_util::FeatureDetector fd; - haxm::check_util::CheckResult detect_res = fd.Detect(); +int Check() { + FeatureDetector fd; - if (detect_res == haxm::check_util::kError) { - ret = -1; - } else if (detect_res == haxm::check_util::kFail) { - ret = 1; + if (fd.Detect() == kError) { + std::cout << "The handle is invalid or the system command is executed " + "exceptionally." << std::endl; + return -1; } - if (is_verbose) { - fd.Print(); - } + fd.Print(); - return ret; + return fd.status(); } } // namespace check_util diff --git a/CheckTool/common.h b/CheckTool/common.h index 5b21c1ce..e4c7a087 100644 --- a/CheckTool/common.h +++ b/CheckTool/common.h @@ -36,7 +36,8 @@ namespace haxm { namespace check_util { -#define APP_VERSION "1.0.0" +#define APP_VERSION "1.1.0" +#define APP_COPYRIGHT "Copyright (C) 2020 Intel Corporation" enum CheckResult { kUnknown = 0, @@ -44,6 +45,7 @@ enum CheckResult { kFail, kNotApplicable, // e.g., CheckHypervDisabled() on macOS kError, + kMaxResult }; // Source: @@ -52,8 +54,8 @@ inline static bool IsBitSet(uint32_t reg, int bit) { return (reg >> bit) & 0x1; } -CheckResult ParseArguments(int &argc, char* argv[], bool &is_verbose); -int Check(bool is_verbose); +CheckResult ParseArguments(int &argc, char* argv[]); +int Check(); } // namespace check_util } // namespace haxm diff --git a/CheckTool/feature_detector.cpp b/CheckTool/feature_detector.cpp index daeabf72..a7a9570a 100644 --- a/CheckTool/feature_detector.cpp +++ b/CheckTool/feature_detector.cpp @@ -44,7 +44,49 @@ namespace haxm { namespace check_util { +enum Check { + // Hardware support bit + kCpuSupported = 0, + kVmxSupported = 1, + kNxSupported = 2, + kEm64tSupported = 3, + kEptSupported = 4, + // BIOS configuration bit + kVmxEnabled = 8, + kNxEnabled = 9, + kEm64tEnabled = 10, + // Host status bit + kOsVerSupported = 16, + kOsArchSupported = 17, + kHypervDisabled = 18, + kSandboxDisabled = 19, + // Guest status bit + kGuestUnoccupied = 24, + kMaxCheck = 32 +}; + +enum CheckFlag { + // Hardware support flag + kFlagCpuSupported = 1 << kCpuSupported, + kFlagVmxSupported = 1 << kVmxSupported, + kFlagNxSupported = 1 << kNxSupported, + kFlagEm64tSupported = 1 << kEm64tSupported, + kFlagEptSupported = 1 << kEptSupported, + // BIOS configuration flag + kFlagVmxEnabled = 1 << kVmxEnabled, + kFlagNxEnabled = 1 << kNxEnabled, + kFlagEm64tEnabled = 1 << kEm64tEnabled, + // Host status flag + kFlagOsverSupported = 1 << kOsVerSupported, + kFlagOsarchSupported = 1 << kOsArchSupported, + kFlagHypervDisabled = 1 << kHypervDisabled, + kFlagSandboxDisabled = 1 << kSandboxDisabled, + // Guest status flag + kFlagGuestUnoccupied = 1 << kGuestUnoccupied +}; + FeatureDetector::FeatureDetector() { + status_ = 0; os_ = new OsImpl(); } @@ -145,32 +187,37 @@ std::string FeatureDetector::ToString(OsType os_type) { } } -CheckResult FeatureDetector::Detect() const { - CheckResult res[11]; - - res[0] = CheckCpuVendor(); - res[1] = CheckLongModeSupported(); - res[2] = CheckNxSupported(); - res[3] = CheckNxEnabled(); - res[4] = CheckOsVersion(); - res[5] = CheckOsArchitecture(); - res[6] = CheckGuestOccupied(); - res[7] = CheckHyperVDisabled(); - res[8] = CheckVmxSupported(); - res[9] = CheckVmxEnabled(); - res[10] = CheckEptSupported(); - - int check_num = 11; +CheckResult FeatureDetector::Detect() { + CheckResult res[kMaxCheck] = {}; + int i; + + res[kCpuSupported] = CheckCpuVendor(); + res[kNxSupported] = CheckNxSupported(); + res[kEm64tSupported] = CheckLongModeSupported(); + res[kNxEnabled] = CheckNxEnabled(); + res[kOsVerSupported] = CheckOsVersion(); + res[kOsArchSupported] = CheckOsArchitecture(); + res[kHypervDisabled] = CheckHyperVDisabled(); + res[kGuestUnoccupied] = CheckGuestOccupied(); + // When Hyper-V is enabled, it will affect the checking results of VMX - // supported, VMX enabled and EPT supported, so only the first 8 items are + // supported, EPT supported and VMX enabled, so only the first 8 items are // checked. When Hyper-V is disabled, all items are checked. - if (res[7] == kFail) { - check_num = 8; + if (res[kHypervDisabled] != kFail) { + res[kVmxSupported] = CheckVmxSupported(); + res[kEptSupported] = CheckEptSupported(); + res[kVmxEnabled] = CheckVmxEnabled(); + } + + for (i = 0; i < kMaxCheck; ++i) { + if (res[i] == kFail) { + status_ |= 1 << i; + } } - int detector[5] = {}; + int detector[kMaxResult] = {}; - for (int i = 0; i < check_num; ++i) { + for (i = 0; i < kMaxCheck; ++i) { ++detector[static_cast(res[i])]; } @@ -178,14 +225,14 @@ CheckResult FeatureDetector::Detect() const { return kError; } - if (detector[static_cast(kUnknown)] > 0) { - return kUnknown; - } - if (detector[static_cast(kFail)] > 0) { return kFail; } + if (detector[static_cast(kUnknown)] > 0) { + return kUnknown; + } + return kPass; } @@ -265,5 +312,9 @@ void FeatureDetector::Print() const { << occupied_count << " guest(s)" << std::endl; } +int FeatureDetector::status() const { + return status_; +} + } // namespace check_util } // namespace haxm diff --git a/CheckTool/feature_detector.h b/CheckTool/feature_detector.h index 060f35f9..7b79b46a 100644 --- a/CheckTool/feature_detector.h +++ b/CheckTool/feature_detector.h @@ -44,8 +44,9 @@ class FeatureDetector { public: FeatureDetector(); ~FeatureDetector(); - CheckResult Detect() const; + CheckResult Detect(); void Print() const; + int status() const; private: CheckResult CheckCpuVendor(std::string* vendor = nullptr) const; @@ -62,6 +63,7 @@ class FeatureDetector { static std::string ToString(CheckResult res); static std::string ToString(OsType os_type); static std::string ToString(OsArchitecture os_arch); + int status_; Cpuid cpuid_; Os* os_; }; diff --git a/CheckTool/main.cpp b/CheckTool/main.cpp index 7b1849fc..4697be88 100644 --- a/CheckTool/main.cpp +++ b/CheckTool/main.cpp @@ -32,18 +32,14 @@ int main(int argc, char* argv[]) { int ret = 0; - haxm::check_util::CheckResult result; - bool is_verbose = false; - result = haxm::check_util::ParseArguments(argc, argv, is_verbose); - - switch (result) { + switch (haxm::check_util::ParseArguments(argc, argv)) { case haxm::check_util::kPass: { - ret = haxm::check_util::Check(is_verbose); + ret = haxm::check_util::Check(); break; } case haxm::check_util::kError: { - ret = -1; + ret = 1; break; } default: { diff --git a/CheckTool/version.rc b/CheckTool/version.rc index 1925c849..6edd12ff 100644 --- a/CheckTool/version.rc +++ b/CheckTool/version.rc @@ -30,11 +30,11 @@ #include -#define FILE_VERSION 1,0,0,0 -#define FILE_VERSION_STR "1.0.0.0" +#define FILE_VERSION 1,1,0,0 +#define FILE_VERSION_STR "1.1.0.0" -#define PRODUCT_VERSION 7,6,5,0 -#define PRODUCT_VERSION_STR "7.6.5.0" +#define PRODUCT_VERSION 7,8,0,0 +#define PRODUCT_VERSION_STR "7.8.0.0" #ifdef DEBUG #define FILE_FLAGS (VS_FF_PRIVATEBUILD | VS_FF_PRERELEASE | VERSION_DEBUG)