Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Commit

Permalink
Implement check tool for HAXM
Browse files Browse the repository at this point in the history
It is required that the host operating system to meet the environmental
requirements to execute HAXM. This utility is used to check the system
environment for HAXM.

It supports:

* To check below system status:
  - Intel CPU vendor
  - Long (64-bit) mode support status
  - VMX support status
  - VMX enabling status
  - EPT support status
  - NX support status
  - NX enabling status
  - Hyper-V disabling status
  - OS version
  - OS architecture
  - Guest occupancy status
* Running on Windows and macOS.

Signed-off-by: Wenchao Wang <[email protected]>
  • Loading branch information
wcwang committed Oct 1, 2020
1 parent 68fdb30 commit dc038c0
Show file tree
Hide file tree
Showing 21 changed files with 1,813 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CheckTool/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Refer to:
# https://android.googlesource.com/platform/external/qemu/+/emu-master-dev/android/.clang-format

BasedOnStyle: Chromium
IndentWidth: 4
ContinuationIndentWidth: 8
AccessModifierOffset: -4
6 changes: 6 additions & 0 deletions CheckTool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Windows
*.obj

# macOS
*.o

54 changes: 54 additions & 0 deletions CheckTool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Minimum requirement for CMake version
cmake_minimum_required(VERSION 3.4)

# Project information
project(checktool)

set(CMAKE_CXX_STANDARD 11)

set(COMMON_SRCS)
list(APPEND COMMON_SRCS
${PROJECT_SOURCE_DIR}/arg_parser.cpp
${PROJECT_SOURCE_DIR}/common.cpp
${PROJECT_SOURCE_DIR}/cpuid.cpp
${PROJECT_SOURCE_DIR}/feature_detector.cpp
${PROJECT_SOURCE_DIR}/main.cpp
)

set(PLATFORM_SRCS)
if(WIN32)
list(APPEND PLATFORM_SRCS
${PROJECT_SOURCE_DIR}/os_windows.cpp
)
# Replace MDd/MD with MTd/MT to use a multi-threaded statically-linked
# runtime library for building a standalone executable.
set(CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
)
foreach(flag ${CXX_FLAGS})
string(REPLACE "/MD" "/MT" ${flag} "${${flag}}")
endforeach()
elseif(APPLE)
list(APPEND PLATFORM_SRCS
${PROJECT_SOURCE_DIR}/os_darwin.cpp
)
else()
message(FATAL_ERROR "Unsupported Platform")
endif()

if(WIN32)
set(RESOURCES)
list(APPEND RESOURCES
${PROJECT_SOURCE_DIR}/version.rc
)
endif()

# Target
add_executable(checktool ${COMMON_SRCS} ${PLATFORM_SRCS} ${RESOURCES})

if(APPLE)
target_link_options(checktool PRIVATE
LINKER:-sectcreate,__TEXT,__info_plist,${PROJECT_SOURCE_DIR}/Info.plist
)
endif()
59 changes: 59 additions & 0 deletions CheckTool/CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"configurations": [
{
"name": "x86-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x86"
],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\build\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},

{
"name": "x86-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x86"
],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\build\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},

{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\build\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},

{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\build\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""

This comment has been minimized.

Copy link
@tullisk74

tullisk74 Nov 18, 2020

fuck you

}
]
}
49 changes: 49 additions & 0 deletions CheckTool/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
Copyright (c) 2020 Intel Corporation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-->
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>checktool</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string>&#xA9; 2020 Intel Corporation</string>
<key>CFBundleGetInfoString</key>
<string>Intel&#xAE; HAXM Check Tool 1.0.0</string>
<key>CFBundleLongVersionString</key>
<string>1.0.0.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
</dict>
</plist>
136 changes: 136 additions & 0 deletions CheckTool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Check Tool for Intel Hardware Accelerated Execution Manager

It is required that the host operating system to meet the environmental
requirements to install HAXM. These requirements include Intel CPU verdor,
enabling VMX, disabling Hyper-V, etc. Only when all the requirements are met,
HAXM can be installed and executed properly. These wiki pages (installation
instructions on [Windows][install-on-windows] and [macOS][install-on-macos])
describe the configuration methods of HAXM installation prerequisites.

This utility is a command line tool for system checking for HAXM. It is used to
help user to check the status of each condition in the current system
environment, so as to determine whether the hardware configuration meets the
requirements or which system settings need to be changed. This software
currently supports running on Windows and macOS.

## Downloads

The latest release of HAXM **Check Tool** for Windows and macOS hosts are
available [here][checktool-release].

## Windows

### Usage

1. `cd X:\path\to\CheckTool`
1. `checktool.exe --verbose`

The output will be as below.

CPU vendor * GenuineIntel
Intel64 supported * Yes
VMX supported * Yes
VMX enabled * Yes
EPT supported * Yes
NX supported * Yes
NX enabled * Yes
Hyper-V disabled - No
OS version * Windows 10.0.18363
OS architecture * x86_64
Guest unoccupied * Yes. 0 guest(s)

"*" represents the item is passed, while "-" represents the item is failed.

### Build

#### Prerequisites

[Visual Studio][visualstudio] 2017 or later

Install the following components: **Desktop development with C++** (**C++ CMake
tools for Windows** is included)

#### Build steps

**Option A (Visual Studio)**

1. Open _CheckTool_ project in Visual Studio.

**File** > **Open** > **Folder...** > **Select Folder** "CheckTool"
(containing _CMakeLists.txt_)
1. Select proper configuration, e.g., "x86-Debug".
1. Build project.

**Build** > **Build All**

The executable program (_checktool.exe_) will be generated in
_X:\path\to\CheckTool\build\x86-Debug\\_. The 32-bit executable can run on both
32-bit and 64-bit Windows, while the 64-bit executable can run on 64-bit Windows
only.

**Option B (CMake)**

1. `set PATH=C:\Program Files (x86)\Microsoft Visual `
`Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;%PATH%`
1. `cd X:\path\to\CheckTool`
1. `mkdir build && cd build && cmake .. && cmake --build .`

The executable program (_checktool.exe_) will be generated in
_X:\path\to\CheckTool\build\Debug\\_. It is easy to clean the build just by
removing the _build_ folder manually.

The full matrix for building 32-bit/64-bit Windows with Debug/Release
configuration can be referred as below.

| | 32-bit Build | 64-bit Build
----------- | -------------------------------------------- | ------------------------------------------
| | `cmake -A Win32 -B build\Win32` | `cmake -A x64 -B build\x64`
**Debug** | `cmake --build build\Win32 --config Debug` | `cmake --build build\x64 --config Debug`
**Release** | `cmake --build build\Win32 --config Release` | `cmake --build build\x64 --config Release`

The path in the first step is the CMake default extension path installed in
Visual Studio 2019. If [CMake][cmake] (3.17 or later) has been installed
independently and added to the system path, the first step of setting path can
be omitted.

## macOS

### Usage

1. `cd /path/to/CheckTool`
1. `./checktool --verbose`

### Build

#### Prerequisites

* [Xcode][xcode] 7.2.1 or later
* [CMake][cmake] 3.17 or later

#### Build steps

1. `cd /path/to/CheckTool`
1. `mkdir build && cd build && cmake .. && make`

The binary (_checktool_) will be generated in _/path/to/CheckTool/build/_. It is
easy to clean the build just by removing the _build_ folder manually.

The full list for building Debug/Release configuration can be referred as
below.

| Debug
| :--------------------------------------------------
| `cmake -DCMAKE_BUILD_TYPE=Debug -B build/Debug`
| `make -C build/Debug`
| **Release**
| `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
[cmake]: https://cmake.org/download/
[install-on-macos]:
https://github.com/intel/haxm/wiki/Installation-Instructions-on-macOS
[install-on-windows]:
https://github.com/intel/haxm/wiki/Installation-Instructions-on-Windows
[visualstudio]: https://www.visualstudio.com/downloads/
[xcode]: https://developer.apple.com/xcode/
66 changes: 66 additions & 0 deletions CheckTool/arg_parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2020 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include "arg_parser.h"

namespace haxm {
namespace check_util {

ArgParser::ArgParser(int &argc, char *argv[],
const std::vector<std::string> &valid_options) {
valid_options_ = valid_options;

for (int i = 1; i < argc; ++i) {
args_.push_back(std::string(argv[i]));
}
}

bool ArgParser::Verify() {
for (std::vector<std::string>::const_iterator it = args_.begin();
it != args_.end(); ++it) {
if (std::find(valid_options_.begin(), valid_options_.end(), *it)
== valid_options_.end()) {
error_ = *it;
return false;
}
}
return true;
}

bool ArgParser::Test(const std::string &option) const {
return std::find(args_.begin(), args_.end(), option) != args_.end();
}

std::string ArgParser::error() const {
return error_;
}

} // namespace check_util
} // namespace haxm
Loading

0 comments on commit dc038c0

Please sign in to comment.