More cleanup

This commit is contained in:
momo5502 2022-04-05 18:17:54 +02:00
parent 4f2b1e79a7
commit d317a308c5
2 changed files with 22 additions and 13 deletions

View File

@ -7,6 +7,7 @@
#include "memory.hpp" #include "memory.hpp"
#include "thread.hpp" #include "thread.hpp"
#include "assembly.hpp" #include "assembly.hpp"
#include "string.hpp"
namespace namespace
{ {
@ -53,8 +54,8 @@ namespace
special_registers.debug_control = __readmsr(IA32_DEBUGCTL); special_registers.debug_control = __readmsr(IA32_DEBUGCTL);
special_registers.msr_gs_base = __readmsr(IA32_GS_BASE); special_registers.msr_gs_base = __readmsr(IA32_GS_BASE);
special_registers.kernel_dr7 = __readdr(7); special_registers.kernel_dr7 = __readdr(7);
_sgdt(&special_registers.gdtr.limit); _sgdt(&special_registers.gdtr);
__sidt(&special_registers.idtr.limit); __sidt(&special_registers.idtr);
_str(&special_registers.tr); _str(&special_registers.tr);
_sldt(&special_registers.ldtr); _sldt(&special_registers.ldtr);
} }
@ -68,8 +69,8 @@ namespace
void restore_descriptor_tables(vmx::launch_context& launch_context) void restore_descriptor_tables(vmx::launch_context& launch_context)
{ {
__lgdt(&launch_context.special_registers.gdtr.limit); __lgdt(&launch_context.special_registers.gdtr);
__lidt(&launch_context.special_registers.idtr.limit); __lidt(&launch_context.special_registers.idtr);
} }
vmx::state* resolve_vm_state_from_context(CONTEXT& context) vmx::state* resolve_vm_state_from_context(CONTEXT& context)
@ -1056,7 +1057,7 @@ INT32 ShvVmxLaunchOnVp(vmx::state* VpData)
// back to the caller on failure. // back to the caller on failure.
// //
auto error_code = launch_vmx(); auto error_code = launch_vmx();
throw std::runtime_error("Failed to launch vmx"); throw std::runtime_error(string::va("Failed to launch vmx: %X", error_code));
} }
@ -1068,7 +1069,9 @@ void hypervisor::enable_core(const uint64_t system_directory_table_base)
vm_state->launch_context.system_directory_table_base = system_directory_table_base; vm_state->launch_context.system_directory_table_base = system_directory_table_base;
capture_cpu_context(vm_state->launch_context); capture_cpu_context(vm_state->launch_context);
if ((__readeflags() & EFLAGS_ALIGNMENT_CHECK_FLAG_FLAG) == 0)
const rflags rflags{.flags = __readeflags()};
if (!rflags.alignment_check_flag)
{ {
ShvVmxLaunchOnVp(vm_state); ShvVmxLaunchOnVp(vm_state);
} }

View File

@ -1,7 +1,7 @@
#include "std_include.hpp"
#include "irp.hpp" #include "irp.hpp"
#include "finally.hpp" #include "finally.hpp"
#include "logging.hpp" #include "logging.hpp"
#include "exception.hpp"
#include "string.hpp" #include "string.hpp"
#include "memory.hpp" #include "memory.hpp"
@ -68,7 +68,7 @@ namespace
debug_log("Hello from the Driver!\n"); debug_log("Hello from the Driver!\n");
break; break;
case HOOK_DRV_IOCTL: case HOOK_DRV_IOCTL:
apply_hook(static_cast<hook_request*>(irp_sp->Parameters.DeviceIoControl.Type3InputBuffer)); //apply_hook(static_cast<hook_request*>(irp_sp->Parameters.DeviceIoControl.Type3InputBuffer));
break; break;
default: default:
debug_log("Invalid IOCTL Code: 0x%X\n", ioctr_code); debug_log("Invalid IOCTL Code: 0x%X\n", ioctr_code);
@ -127,6 +127,8 @@ irp::irp(const PDRIVER_OBJECT driver_object, const wchar_t* device_name, const w
} }
irp::~irp() irp::~irp()
{
try
{ {
PAGED_CODE() PAGED_CODE()
@ -136,6 +138,10 @@ irp::~irp()
IoDeleteDevice(this->device_object_); IoDeleteDevice(this->device_object_);
} }
} }
catch (...)
{
}
}
irp::irp(irp&& obj) noexcept irp::irp(irp&& obj) noexcept
: irp() : irp()