|
|
@ -3,7 +3,7 @@
|
|
|
|
auto vmxlaunch::init_vmcs(cr3 cr3_value) -> void
|
|
|
|
auto vmxlaunch::init_vmcs(cr3 cr3_value) -> void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const auto vcpu =
|
|
|
|
const auto vcpu =
|
|
|
|
vmxon::g_vmx_ctx->vcpus[
|
|
|
|
&vmxon::g_vmx_ctx.vcpus[
|
|
|
|
KeGetCurrentProcessorNumber()];
|
|
|
|
KeGetCurrentProcessorNumber()];
|
|
|
|
|
|
|
|
|
|
|
|
__vmx_vmclear(&vcpu->vmcs_phys);
|
|
|
|
__vmx_vmclear(&vcpu->vmcs_phys);
|
|
|
@ -15,27 +15,21 @@ auto vmxlaunch::init_vmcs(cr3 cr3_value) -> void
|
|
|
|
const auto [tr_descriptor, tr_rights, tr_limit, tr_base] =
|
|
|
|
const auto [tr_descriptor, tr_rights, tr_limit, tr_base] =
|
|
|
|
gdt::get_info(gdt_value, segment_selector{ readtr() });
|
|
|
|
gdt::get_info(gdt_value, segment_selector{ readtr() });
|
|
|
|
|
|
|
|
|
|
|
|
// copy windows TSS and windows GDT...
|
|
|
|
|
|
|
|
// change TSS base to new TSS...
|
|
|
|
|
|
|
|
hv::segment_descriptor_addr_t tss{ &vcpu->tss };
|
|
|
|
hv::segment_descriptor_addr_t tss{ &vcpu->tss };
|
|
|
|
memcpy(&vcpu->tss, (void*)tr_base, sizeof hv::tss64);
|
|
|
|
memcpy(&vcpu->tss, reinterpret_cast<void*>(tr_base), sizeof hv::tss64);
|
|
|
|
memcpy(vcpu->gdt, (void*)gdt_value.base_address, PAGE_SIZE);
|
|
|
|
memcpy(vcpu->gdt, reinterpret_cast<void*>(gdt_value.base_address), PAGE_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
vcpu->tss.interrupt_stack_table[idt::ist_idx::pf] =
|
|
|
|
vcpu->tss.interrupt_stack_table[idt::ist_idx::pf] =
|
|
|
|
reinterpret_cast<u64>(ExAllocatePool(NonPagedPool,
|
|
|
|
reinterpret_cast<u64>(idt::pf_stk) + sizeof idt::pf_stk;
|
|
|
|
PAGE_SIZE * HOST_STACK_PAGES)) + (PAGE_SIZE * HOST_STACK_PAGES);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vcpu->tss.interrupt_stack_table[idt::ist_idx::gp] =
|
|
|
|
vcpu->tss.interrupt_stack_table[idt::ist_idx::gp] =
|
|
|
|
reinterpret_cast<u64>(ExAllocatePool(NonPagedPool,
|
|
|
|
reinterpret_cast<u64>(idt::gp_stk) + sizeof idt::gp_stk;
|
|
|
|
PAGE_SIZE * HOST_STACK_PAGES)) + (PAGE_SIZE * HOST_STACK_PAGES);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vcpu->tss.interrupt_stack_table[idt::ist_idx::de] =
|
|
|
|
vcpu->tss.interrupt_stack_table[idt::ist_idx::de] =
|
|
|
|
reinterpret_cast<u64>(ExAllocatePool(NonPagedPool,
|
|
|
|
reinterpret_cast<u64>(idt::de_stk) + sizeof idt::de_stk;
|
|
|
|
PAGE_SIZE * HOST_STACK_PAGES)) + (PAGE_SIZE * HOST_STACK_PAGES);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vcpu->tss.interrupt_stack_table[idt::ist_idx::nmi] =
|
|
|
|
vcpu->tss.interrupt_stack_table[idt::ist_idx::nmi] =
|
|
|
|
reinterpret_cast<u64>(ExAllocatePool(NonPagedPool,
|
|
|
|
reinterpret_cast<u64>(idt::nmi_stk) + sizeof idt::nmi_stk;
|
|
|
|
PAGE_SIZE * HOST_STACK_PAGES)) + (PAGE_SIZE * HOST_STACK_PAGES);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto tr_idx = segment_selector{ readtr() }.idx;
|
|
|
|
const auto tr_idx = segment_selector{ readtr() }.idx;
|
|
|
|
vcpu->gdt[tr_idx].base_address_upper = tss.upper;
|
|
|
|
vcpu->gdt[tr_idx].base_address_upper = tss.upper;
|
|
|
@ -44,7 +38,8 @@ auto vmxlaunch::init_vmcs(cr3 cr3_value) -> void
|
|
|
|
vcpu->gdt[tr_idx].base_address_low = tss.low;
|
|
|
|
vcpu->gdt[tr_idx].base_address_low = tss.low;
|
|
|
|
|
|
|
|
|
|
|
|
vmcs::setup_host(&vmxexit_handler,
|
|
|
|
vmcs::setup_host(&vmxexit_handler,
|
|
|
|
vcpu->host_stack, cr3_value, (u64)vcpu->gdt);
|
|
|
|
reinterpret_cast<u64>(vcpu->host_stack),
|
|
|
|
|
|
|
|
cr3_value, reinterpret_cast<u64>(vcpu->gdt));
|
|
|
|
|
|
|
|
|
|
|
|
vmcs::setup_guest();
|
|
|
|
vmcs::setup_guest();
|
|
|
|
vmcs::setup_controls();
|
|
|
|
vmcs::setup_controls();
|
|
|
|