added exception error codes, added g_vcpu global...

merge-requests/1/head
_xeroxz 4 years ago
parent c9731f604b
commit 57176e1639

@ -68,7 +68,9 @@ auto exit_handler(hv::pguest_registers regs) -> void
interrupt.flags = interruption_type::hardware_exception;
interrupt.vector = EXCEPTION_GP_FAULT;
interrupt.valid = true;
__vmx_vmwrite(VMCS_CTRL_VMENTRY_INTERRUPTION_INFORMATION_FIELD, interrupt.flags);
__vmx_vmwrite(VMCS_VMEXIT_INTERRUPTION_ERROR_CODE, g_vcpu->error_code);
}
return; // dont advance rip...
}
@ -95,7 +97,9 @@ auto exit_handler(hv::pguest_registers regs) -> void
interrupt.flags = interruption_type::hardware_exception;
interrupt.vector = EXCEPTION_GP_FAULT;
interrupt.valid = true;
__vmx_vmwrite(VMCS_CTRL_VMENTRY_INTERRUPTION_INFORMATION_FIELD, interrupt.flags);
__vmx_vmwrite(VMCS_VMEXIT_INTERRUPTION_ERROR_CODE, g_vcpu->error_code);
}
return; // dont advance rip...
}
@ -122,7 +126,9 @@ auto exit_handler(hv::pguest_registers regs) -> void
interrupt.flags = interruption_type::hardware_exception;
interrupt.vector = EXCEPTION_GP_FAULT;
interrupt.valid = true;
__vmx_vmwrite(VMCS_CTRL_VMENTRY_INTERRUPTION_INFORMATION_FIELD, interrupt.flags);
__vmx_vmwrite(VMCS_VMEXIT_INTERRUPTION_ERROR_CODE, g_vcpu->error_code);
}
return; // dont advance rip...
}
@ -210,7 +216,10 @@ auto exit_handler(hv::pguest_registers regs) -> void
interrupt.flags = interruption_type::hardware_exception;
interrupt.vector = EXCEPTION_INVALID_OPCODE;
interrupt.valid = true;
__vmx_vmwrite(VMCS_CTRL_VMENTRY_INTERRUPTION_INFORMATION_FIELD, interrupt.flags);
__vmx_vmwrite(VMCS_VMEXIT_INTERRUPTION_ERROR_CODE, NULL);
return; // dont advance rip...
}
break;
}
@ -226,7 +235,10 @@ auto exit_handler(hv::pguest_registers regs) -> void
interrupt.flags = interruption_type::hardware_exception;
interrupt.vector = EXCEPTION_INVALID_OPCODE;
interrupt.valid = true;
__vmx_vmwrite(VMCS_CTRL_VMENTRY_INTERRUPTION_INFORMATION_FIELD, interrupt.flags);
// manual says there will never be an error code... so just put null...
__vmx_vmwrite(VMCS_VMEXIT_INTERRUPTION_ERROR_CODE, NULL);
return; // dont advance rip...
}
default:

@ -657,7 +657,7 @@ namespace hv
u64 vmcs_phys;
u64 vmxon_phys;
u64 host_stack;
u64 error_code;
tss64 tss;
segment_descriptor_64* gdt;
} vcpu_ctx, * pvcpu_ctx;

@ -2,6 +2,7 @@
auto seh_handler(hv::pidt_regs_t regs) -> void
{
g_vcpu->error_code = regs->error_code;
const auto rva = regs->rip - reinterpret_cast<u64>(idt::image_base);
const auto nt_headers = reinterpret_cast<IMAGE_NT_HEADERS64*>(
reinterpret_cast<u64>(idt::image_base) +

@ -2,6 +2,7 @@
#include "hv_types.hpp"
#include "segment_intrin.h"
#include "debug.hpp"
#include "vmxon.hpp"
#pragma section(".idt", read, write)
extern "C" void __gp_handler(void);

@ -33,7 +33,7 @@ namespace vmcs
fs.request_privilege_level = NULL;
fs.table = NULL;
__vmx_vmwrite(VMCS_HOST_FS_SELECTOR, fs.flags);
__vmx_vmwrite(VMCS_HOST_GS_BASE, __readmsr(IA32_FS_BASE));
__vmx_vmwrite(VMCS_HOST_FS_BASE, __readmsr(IA32_FS_BASE));
segment_selector gs{ readgs() };
gs.request_privilege_level = NULL;

@ -3,6 +3,7 @@
#include "debug.hpp"
#include "invd.hpp"
#include "mm.hpp"
#include "vmxon.hpp"
enum class vmcall_option
{

@ -1,6 +1,19 @@
#pragma once
#include "hv_types.hpp"
inline auto get_cpu_num() -> u32
{
cpuid_eax_01 cpuid_value;
__cpuid((int*)&cpuid_value, 1);
return cpuid_value
.cpuid_additional_information
.initial_apic_id;
}
#define g_vcpu \
vmxon::g_vmx_ctx->vcpus[get_cpu_num()]
namespace vmxon
{
auto create_vmxon_region(hv::pvcpu_ctx vcpu_ctx) -> void;

Loading…
Cancel
Save