mirror of
https://github.com/momo5502/hypervisor.git
synced 2025-04-19 21:52:55 +00:00
Prepare hypervisor
This commit is contained in:
parent
49d259f3ae
commit
6ce3597bd3
@ -3,6 +3,7 @@
|
|||||||
#include "sleep_callback.hpp"
|
#include "sleep_callback.hpp"
|
||||||
#include "irp.hpp"
|
#include "irp.hpp"
|
||||||
#include "exception.hpp"
|
#include "exception.hpp"
|
||||||
|
#include "hypervisor.hpp"
|
||||||
|
|
||||||
#define DOS_DEV_NAME L"\\DosDevices\\HelloDev"
|
#define DOS_DEV_NAME L"\\DosDevices\\HelloDev"
|
||||||
#define DEV_NAME L"\\Device\\HelloDev"
|
#define DEV_NAME L"\\Device\\HelloDev"
|
||||||
@ -38,17 +39,20 @@ public:
|
|||||||
private:
|
private:
|
||||||
sleep_callback sleep_callback_{};
|
sleep_callback sleep_callback_{};
|
||||||
irp irp_{};
|
irp irp_{};
|
||||||
|
hypervisor hypervisor_{};
|
||||||
|
|
||||||
void sleep_notification(const sleep_callback::type type)
|
void sleep_notification(const sleep_callback::type type)
|
||||||
{
|
{
|
||||||
if (type == sleep_callback::type::sleep)
|
if (type == sleep_callback::type::sleep)
|
||||||
{
|
{
|
||||||
debug_log("Going to sleep!");
|
debug_log("Going to sleep!");
|
||||||
|
this->hypervisor_.on_sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == sleep_callback::type::wakeup)
|
if (type == sleep_callback::type::wakeup)
|
||||||
{
|
{
|
||||||
debug_log("Waking up!");
|
debug_log("Waking up!");
|
||||||
|
this->hypervisor_.on_wakeup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
54
src/driver/hypervisor.cpp
Normal file
54
src/driver/hypervisor.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include "std_include.hpp"
|
||||||
|
#include "hypervisor.hpp"
|
||||||
|
#include "exception.hpp"
|
||||||
|
#include "logging.hpp"
|
||||||
|
|
||||||
|
#define IA32_FEATURE_CONTROL_MSR 0x3A
|
||||||
|
#define IA32_FEATURE_CONTROL_MSR_LOCK 0x0001
|
||||||
|
#define IA32_FEATURE_CONTROL_MSR_ENABLE_VMXON_OUTSIDE_SMX 0x0004
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
bool is_vmx_supported()
|
||||||
|
{
|
||||||
|
int cpuid_data[4] = {0};
|
||||||
|
__cpuid(cpuid_data, 1);
|
||||||
|
return cpuid_data[2] & 0x20;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_vmx_available()
|
||||||
|
{
|
||||||
|
const auto feature_control = __readmsr(IA32_FEATURE_CONTROL_MSR);
|
||||||
|
const auto is_locked = (feature_control & IA32_FEATURE_CONTROL_MSR_LOCK) != 0;
|
||||||
|
const auto is_enabled_outside_smx = (feature_control & IA32_FEATURE_CONTROL_MSR_ENABLE_VMXON_OUTSIDE_SMX) != 0;
|
||||||
|
|
||||||
|
return is_locked && is_enabled_outside_smx;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_virtualization_supported()
|
||||||
|
{
|
||||||
|
return is_vmx_supported() && is_vmx_available();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hypervisor::hypervisor()
|
||||||
|
{
|
||||||
|
if(!is_virtualization_supported())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("VMX not supported on this machine");
|
||||||
|
}
|
||||||
|
|
||||||
|
debug_log("VMX supported!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
hypervisor::~hypervisor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void hypervisor::on_sleep()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void hypervisor::on_wakeup()
|
||||||
|
{
|
||||||
|
}
|
19
src/driver/hypervisor.hpp
Normal file
19
src/driver/hypervisor.hpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class hypervisor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
hypervisor();
|
||||||
|
~hypervisor();
|
||||||
|
|
||||||
|
hypervisor(hypervisor&& obj) noexcept = delete;
|
||||||
|
hypervisor& operator=(hypervisor&& obj) noexcept = delete;
|
||||||
|
|
||||||
|
hypervisor(const hypervisor& obj) = delete;
|
||||||
|
hypervisor& operator=(const hypervisor& obj) = delete;
|
||||||
|
|
||||||
|
void on_sleep();
|
||||||
|
void on_wakeup();
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
@ -3,5 +3,5 @@
|
|||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
#define debug_log(...)
|
#define debug_log(...)
|
||||||
#else
|
#else
|
||||||
#define debug_log(...) DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__)
|
#define debug_log(msg, ...) DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[MOMO] " msg, __VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ntddk.h>
|
#include <ntddk.h>
|
||||||
|
#include <intrin.h>
|
||||||
#include "nt_ext.hpp"
|
#include "nt_ext.hpp"
|
||||||
#include "new.hpp"
|
#include "new.hpp"
|
Loading…
x
Reference in New Issue
Block a user