Create and Configure a Vmcs Layout.
821{
822 UINT32 CpuBasedVmExecControls;
823 UINT32 SecondaryProcBasedVmExecControls;
824 PVOID HostRsp;
826 IA32_VMX_BASIC_REGISTER VmxBasicMsr = {0};
828
829
830
831
832 VmxBasicMsr.AsUInt = __readmsr(IA32_VMX_BASIC);
833
841
842
843
844
846
847 VmxVmwrite64(VMCS_GUEST_DEBUGCTL, __readmsr(IA32_DEBUGCTL) & 0xFFFFFFFF);
849
850
851
852
854
857
860
862 VmxVmwrite64(VMCS_CTRL_VMENTRY_INTERRUPTION_INFORMATION_FIELD, 0);
863
865
874
875 VmxVmwrite64(VMCS_GUEST_FS_BASE, __readmsr(IA32_FS_BASE));
876 VmxVmwrite64(VMCS_GUEST_GS_BASE, __readmsr(IA32_GS_BASE));
877
879 VmxBasicMsr.VmxControls ? IA32_VMX_TRUE_PROCBASED_CTLS : IA32_VMX_PROCBASED_CTLS);
880
881 VmxVmwrite64(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, CpuBasedVmExecControls);
882
883 LogDebugInfo(
"CPU Based VM Exec Controls (Based on %s) : 0x%x",
884 VmxBasicMsr.VmxControls ? "IA32_VMX_TRUE_PROCBASED_CTLS" : "IA32_VMX_PROCBASED_CTLS",
885 CpuBasedVmExecControls);
886
888 IA32_VMX_PROCBASED_CTLS2);
889
890 VmxVmwrite64(VMCS_CTRL_SECONDARY_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, SecondaryProcBasedVmExecControls);
891
892 LogDebugInfo(
"Secondary Proc Based VM Exec Controls (IA32_VMX_PROCBASED_CTLS2) : 0x%x", SecondaryProcBasedVmExecControls);
893
894 VmxVmwrite64(VMCS_CTRL_PIN_BASED_VM_EXECUTION_CONTROLS,
HvAdjustControls(0, VmxBasicMsr.VmxControls ? IA32_VMX_TRUE_PINBASED_CTLS : IA32_VMX_PINBASED_CTLS));
895
897
899
902
905
909
911
914
915
916
917
918
919
921
924
927
929
930 VmxVmwrite64(VMCS_GUEST_SYSENTER_CS, __readmsr(IA32_SYSENTER_CS));
931 VmxVmwrite64(VMCS_GUEST_SYSENTER_EIP, __readmsr(IA32_SYSENTER_EIP));
932 VmxVmwrite64(VMCS_GUEST_SYSENTER_ESP, __readmsr(IA32_SYSENTER_ESP));
933
934#if USE_DEFAULT_OS_GDT_AS_HOST_GDT == FALSE
935
937
940
941#else
942
944
947
948#endif
949
950 VmxVmwrite64(VMCS_HOST_FS_BASE, __readmsr(IA32_FS_BASE));
951 VmxVmwrite64(VMCS_HOST_GS_BASE, __readmsr(IA32_GS_BASE));
952
953#if USE_DEFAULT_OS_IDT_AS_HOST_IDT == FALSE
954
956
957#else
958
960
961#endif
962
963 VmxVmwrite64(VMCS_HOST_SYSENTER_CS, __readmsr(IA32_SYSENTER_CS));
964 VmxVmwrite64(VMCS_HOST_SYSENTER_EIP, __readmsr(IA32_SYSENTER_EIP));
965 VmxVmwrite64(VMCS_HOST_SYSENTER_ESP, __readmsr(IA32_SYSENTER_ESP));
966
967
968
969
971
972
973
974
977
978
979
980
982
983
984
985
986
987
988
989
991
992
993
994
996
997
998
999
1001
1002
1003
1004
1005
1007 HostRsp = ((PVOID)((ULONG_PTR)(HostRsp) & ~(16 - 1)));
1010
1012}
UINT32 HvAdjustControls(UINT32 Ctl, UINT32 Msr)
Adjust controls for VMCS based on processor capability.
Definition Hv.c:23
VOID HvFillGuestSelectorData(PVOID GdtBase, UINT32 SegmentRegister, UINT16 Selector)
Fill the guest's selector data.
Definition Hv.c:276
unsigned short AsmGetGs()
Get GS Register.
void AsmVmexitHandler()
Vm-exit handler.
unsigned short AsmGetTr()
Get TR Register.
unsigned short AsmGetDs()
Get DS Register.
unsigned short AsmGetSs()
Get SS Register.
unsigned short AsmGetGdtLimit()
Get GDT Limit.
unsigned long long AsmGetIdtBase()
Get IDT base.
unsigned short AsmGetLdtr()
Get LDTR Register.
unsigned short AsmGetCs()
Get CS Register.
unsigned short AsmGetFs()
Get FS Register.
unsigned short AsmGetEs()
Get ES Register.
unsigned long long AsmGetGdtBase()
get GDT base
unsigned short AsmGetRflags()
Get R/EFLAGS.
void AsmVmxRestoreState()
Restore state on vmx.
unsigned short AsmGetIdtLimit()
Get IDT limit.
UINT64 LayoutGetSystemDirectoryTableBase()
Find cr3 of system process.
Definition Layout.c:90
_Use_decl_annotations_ BOOLEAN SegmentGetDescriptor(PUCHAR GdtBase, UINT16 Selector, PVMX_SEGMENT_SELECTOR SegmentSelector)
Get Segment Descriptor.
Definition Segmentation.c:24
_In_ UINT16 _Out_ PVMX_SEGMENT_SELECTOR SegmentSelector
Definition Segmentation.h:51
UCHAR VmxVmwrite64(size_t Field, UINT64 FieldValue)
VMX VMWRITE instruction (64-bit)
Definition Vmx.c:122
#define CPU_BASED_CTL2_ENABLE_VPID
Definition Vmx.h:72
#define VIRTUAL_PROCESSOR_ID
Definition Vmx.h:291
#define CPU_BASED_ACTIVATE_MSR_BITMAP
Definition Vmx.h:61
#define VM_EXIT_HOST_ADDR_SPACE_SIZE
Definition Vmx.h:84
#define CPU_BASED_ACTIVATE_SECONDARY_CONTROLS
Definition Vmx.h:64
#define CPU_BASED_ACTIVATE_IO_BITMAP
Definition Vmx.h:59
#define CPU_BASED_CTL2_ENABLE_XSAVE_XRSTORS
Definition Vmx.h:77
#define CPU_BASED_CTL2_ENABLE_INVPCID
Definition Vmx.h:75
#define CPU_BASED_CTL2_ENABLE_EPT
Secondary CPU-Based Controls.
Definition Vmx.h:70
#define VM_ENTRY_IA32E_MODE
Definition Vmx.h:98
#define CPU_BASED_CTL2_RDTSCP
Definition Vmx.h:71
#define VMM_STACK_SIZE
Stack Size.
Definition Vmx.h:140
#define VMCS_GUEST_DEBUGCTL_HIGH
Definition Vmx.h:290
#define VPID_TAG
VPID Tag.
Definition Vpid.h:30
UINT64 MsrBitmapPhysicalAddress
Definition State.h:316
UINT64 HostGdt
Definition State.h:334
EPT_POINTER EptPointer
Definition State.h:341
UINT64 IoBitmapPhysicalAddressA
Definition State.h:318
UINT64 VmmStack
Definition State.h:314
UINT64 HostIdt
Definition State.h:333
UINT64 IoBitmapPhysicalAddressB
Definition State.h:320
Segment selector.
Definition DataTypes.h:436
UINT64 Base
Definition DataTypes.h:440