HyperDbg Debugger
Loading...
Searching...
No Matches
Hv.c File Reference

This file describes the routines in Hypervisor. More...

#include "pch.h"

Functions

UINT32 HvAdjustControls (UINT32 Ctl, UINT32 Msr)
 Adjust controls for VMCS based on processor capability.
BOOLEAN HvSetGuestSelector (PVOID GdtBase, UINT32 SegmentRegister, UINT16 Selector)
 Set guest's selector registers.
VOID HvHandleCpuid (VIRTUAL_MACHINE_STATE *VCpu)
 Handle Cpuid Vmexits.
VOID HvHandleControlRegisterAccess (VIRTUAL_MACHINE_STATE *VCpu, VMX_EXIT_QUALIFICATION_MOV_CR *CrExitQualification)
 Handles Guest Access to control registers.
VOID HvFillGuestSelectorData (PVOID GdtBase, UINT32 SegmentRegister, UINT16 Selector)
 Fill the guest's selector data.
VOID HvResumeToNextInstruction ()
 Add the current instruction length to guest rip to resume to next instruction.
VOID HvSuppressRipIncrement (VIRTUAL_MACHINE_STATE *VCpu)
 Suppress the incrementation of RIP.
VOID HvPerformRipIncrement (VIRTUAL_MACHINE_STATE *VCpu)
 Perform the incrementation of RIP.
VOID HvSetMonitorTrapFlag (BOOLEAN Set)
 Set the monitor trap flag.
VOID HvSetRflagTrapFlag (BOOLEAN Set)
 Set the rflag's trap flag.
VOID HvSetLoadDebugControls (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set LOAD DEBUG CONTROLS on Vm-entry controls.
VOID HvSetLoadGuestIa32LbrCtl (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set LOAD GUEST IA32_LBR_CTL on Vm-entry controls.
VOID HvSetSaveDebugControls (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set SAVE DEBUG CONTROLS on Vm-exit controls.
VOID HvSetClearGuestIa32LbrCtl (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set SAVE GUEST IA32_LBR_CTL on Vm-exit controls.
VOID HvRestoreRegisters ()
 Reset GDTR/IDTR and other old when you do vmxoff as the patchguard will detect them left modified.
VOID HvSetPmcVmexit (BOOLEAN Set)
 Set vm-exit for rdpmc instructions.
VOID HvSetMovControlRegsExiting (BOOLEAN Set, UINT64 ControlRegister, UINT64 MaskRegister)
 Set vm-exit for mov-to-cr0/4.
VOID HvSetMovToCr3Vmexit (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set vm-exit for mov-to-cr3.
VOID HvWriteExceptionBitmap (UINT32 BitmapMask)
 Write on exception bitmap in VMCS DO NOT CALL IT DIRECTLY, instead use HvSetExceptionBitmap.
UINT32 HvReadExceptionBitmap ()
 Read exception bitmap in VMCS.
VOID HvSetInterruptWindowExiting (BOOLEAN Set)
 Set Interrupt-window exiting.
VOID HvSetPmlEnableFlag (BOOLEAN Set)
 Set Page Modification Logging Enable bit.
VOID HvSetModeBasedExecutionEnableFlag (BOOLEAN Set)
 Set Mode-based Execution Control (MBEC) Enable bit.
VOID HvSetNmiWindowExiting (BOOLEAN Set)
 Set NMI-window exiting.
VOID HvHandleMovDebugRegister (VIRTUAL_MACHINE_STATE *VCpu)
 Handle Mov to Debug Registers Exitings.
VOID HvSetNmiExiting (BOOLEAN Set)
 Set the NMI Exiting.
VOID HvSetVmxPreemptionTimerExiting (BOOLEAN Set)
 Set the VMX preemption timer.
VOID HvSetExceptionBitmap (VIRTUAL_MACHINE_STATE *VCpu, UINT32 IdtIndex)
 Set exception bitmap in VMCS.
VOID HvUnsetExceptionBitmap (VIRTUAL_MACHINE_STATE *VCpu, UINT32 IdtIndex)
 Unset exception bitmap in VMCS.
VOID HvSetExternalInterruptExiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set the External Interrupt Exiting.
VOID HvEnableAndCheckForPreviousExternalInterrupts (VIRTUAL_MACHINE_STATE *VCpu)
 Checks to enable and reinject previous interrupts.
VOID HvSetRdtscExiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set the RDTSC/P Exiting.
VOID HvSetMovDebugRegsExiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set or unset the Mov to Debug Registers Exiting.
UINT16 HvGetCsSelector ()
 Read CS selector.
UINT64 HvGetRflags ()
 Read guest's RFLAGS.
VOID HvSetRflags (UINT64 Rflags)
 Set guest's RFLAGS.
UINT64 HvGetRip ()
 Read guest's RIP.
VOID HvSetRip (UINT64 Rip)
 Set guest's RIP.
UINT64 HvGetInterruptibilityState ()
 Read guest's interruptibility state.
UINT64 HvClearSteppingBits (UINT64 Interruptibility)
 Clear STI and MOV SS bits.
VOID HvSetInterruptibilityState (UINT64 InterruptibilityState)
 Set guest's interruptibility state.
VOID HvInjectPendingExternalInterrupts (VIRTUAL_MACHINE_STATE *VCpu)
 Inject pending external interrupts.
VOID HvCheckAndEnableExternalInterrupts (VIRTUAL_MACHINE_STATE *VCpu)
 Check and enable external interrupts.
VOID HvDisableExternalInterruptsAndInterruptWindow (VIRTUAL_MACHINE_STATE *VCpu)
 Disable external-interrupts and interrupt window.
BOOLEAN HvInitVmm (VMM_CALLBACKS *VmmCallbacks)
 Initializes the hypervisor.
VOID HvEnableMtfAndChangeExternalInterruptState (VIRTUAL_MACHINE_STATE *VCpu)
 Enables MTF and adjust external interrupt state.
VOID HvPreventExternalInterrupts (VIRTUAL_MACHINE_STATE *VCpu)
 Adjust external interrupt state.
UINT64 HvGetPendingDebugExceptions ()
 Get the guest state of pending debug exceptions.
VOID HvSetPendingDebugExceptions (UINT64 Value)
 Set the guest state of pending debug exceptions.
UINT64 HvGetDebugctl ()
 Get the guest state of IA32_DEBUGCTL.
UINT64 HvGetGuestIa32LbrCtl ()
 Get the guest state of IA32_LBR_CTL.
VOID HvGetAndStoreDebugctl (UINT64 *StoreDebugctl)
 Get and store the guest state of IA32_DEBUGCTL.
VOID HvGetAndStoreGuestIa32LbrCtl (UINT64 *StoreGuestIa32Lbr)
 Get and store the guest state of IA32_LBR_CTL.
VOID HvSetDebugctl (UINT64 Value)
 Set the guest state of IA32_DEBUGCTL.
VOID HvSetGuestIa32LbrCtl (UINT64 Value)
 Set the guest state of IA32_LBR_CTL.
VOID HvSetLbrSelect (UINT64 FilterOptions)
 Set LBR selector.
BOOLEAN HvCheckCpuSupportForSaveAndLoadDebugControls ()
 Check if CPU support save and load debug controls on exit and load entries.
BOOLEAN HvCheckCpuSupportForLoadAndClearGuestIa32LbrCtlControls ()
 Check if CPU support load and clear guest IA32_LBR_CTL controls on entry and exit.
VOID HvSetDebugReg7 (UINT64 Value)
 Set the guest state of DR7.
VOID HvHandleTrapFlag ()
 Handle the case when the trap flag is set, and we need to inject the single-step exception right after vm-entry.

Detailed Description

This file describes the routines in Hypervisor.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)

vmx related routines

Version
0.1
Date
2020-04-11

Function Documentation

◆ HvAdjustControls()

UINT32 HvAdjustControls ( UINT32 Ctl,
UINT32 Msr )

Adjust controls for VMCS based on processor capability.

Returns the Cpu Based and Secondary Processor Based Controls and other controls based on hardware support.

Parameters
Ctl
Msr
Returns
UINT32 Returns the Cpu Based and Secondary Processor Based Controls and other controls based on hardware support

Adjust controls for VMCS based on processor capability.

Parameters
Ctl
Msr
Returns
UINT32
24{
25 MSR MsrValue = {0};
26
27 MsrValue.Flags = CpuReadMsr(Msr);
28 Ctl &= MsrValue.Fields.High; /* bit == 0 in high word ==> must be zero */
29 Ctl |= MsrValue.Fields.Low; /* bit == 1 in low word ==> must be one */
30 return Ctl;
31}
union _MSR MSR
General MSR Structure.
UINT64 CpuReadMsr(ULONG MsrAddress)
Read an MSR.
Definition PlatformIntrinsics.c:213
UINT64 Flags
Definition Msr.h:42
ULONG Low
Definition Msr.h:38
struct _MSR::@027346114345265205246155043220371021005105071041 Fields
ULONG High
Definition Msr.h:39

◆ HvCheckAndEnableExternalInterrupts()

VOID HvCheckAndEnableExternalInterrupts ( VIRTUAL_MACHINE_STATE * VCpu)

Check and enable external interrupts.

Parameters
VCpuThe virtual processor's state
Returns
VOID
1318{
1319 //
1320 // Check if we should enable interrupts in this core or not
1321 //
1323 {
1324 //
1325 // Enable normal interrupts
1326 //
1328
1329 //
1330 // Check if there is at least an interrupt that needs to be delivered
1331 //
1333
1335 }
1336}
VOID HvSetExternalInterruptExiting(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
Set the External Interrupt Exiting.
Definition Hv.c:1102
VOID HvInjectPendingExternalInterrupts(VIRTUAL_MACHINE_STATE *VCpu)
Inject pending external interrupts.
Definition Hv.c:1295
#define FALSE
Definition BasicTypes.h:113
BOOLEAN EnableExternalInterruptsOnContinue
Definition State.h:317

◆ HvCheckCpuSupportForLoadAndClearGuestIa32LbrCtlControls()

BOOLEAN HvCheckCpuSupportForLoadAndClearGuestIa32LbrCtlControls ( )

Check if CPU support load and clear guest IA32_LBR_CTL controls on entry and exit.

Check if CPU support load and clear guest IA32_LBR_CTL controls on VM-entry and VM-exit.

Returns
BOOLEAN

Check if CPU support load and clear guest IA32_LBR_CTL controls on entry and exit.

Returns
BOOLEAN
1693{
1694 IA32_VMX_BASIC_REGISTER VmxBasicMsr = {0};
1695
1696 //
1697 // Reading IA32_VMX_BASIC_MSR
1698 //
1699 VmxBasicMsr.AsUInt = CpuReadMsr(IA32_VMX_BASIC);
1700
1701 //
1702 // Read 1-settings of save debug controls (exit controls)
1703 //
1704 UINT32 ExitCtls = HvAdjustControls(
1705 IA32_VMX_EXIT_CTLS_CLEAR_IA32_LBR_CTL_FLAG,
1706 VmxBasicMsr.VmxControls ? IA32_VMX_TRUE_EXIT_CTLS : IA32_VMX_EXIT_CTLS);
1707
1708 //
1709 // Read 1-settings of load debug controls (entry controls)
1710 //
1711 UINT32 EntryCtls = HvAdjustControls(
1712 IA32_VMX_ENTRY_CTLS_LOAD_IA32_LBR_CTL_FLAG,
1713 VmxBasicMsr.VmxControls ? IA32_VMX_TRUE_ENTRY_CTLS : IA32_VMX_ENTRY_CTLS);
1714
1715 //
1716 // Check if entry and exit controls are supported on this system
1717 //
1718 if (ExitCtls != NULL_ZERO && EntryCtls != NULL_ZERO)
1719 {
1720 //
1721 // Supported
1722 //
1723 return TRUE;
1724 }
1725 else
1726 {
1727 //
1728 // Not supported
1729 //
1730 return FALSE;
1731 }
1732}
UINT32 HvAdjustControls(UINT32 Ctl, UINT32 Msr)
Adjust controls for VMCS based on processor capability.
Definition Hv.c:23
#define NULL_ZERO
Definition BasicTypes.h:110
#define TRUE
Definition BasicTypes.h:114
unsigned int UINT32
Definition BasicTypes.h:54

◆ HvCheckCpuSupportForSaveAndLoadDebugControls()

BOOLEAN HvCheckCpuSupportForSaveAndLoadDebugControls ( )

Check if CPU support save and load debug controls on exit and load entries.

Returns
BOOLEAN
1645{
1646 IA32_VMX_BASIC_REGISTER VmxBasicMsr = {0};
1647
1648 //
1649 // Reading IA32_VMX_BASIC_MSR
1650 //
1651 VmxBasicMsr.AsUInt = CpuReadMsr(IA32_VMX_BASIC);
1652
1653 //
1654 // Read 1-settings of save debug controls (exit controls)
1655 //
1656 UINT32 ExitCtls = HvAdjustControls(
1657 IA32_VMX_EXIT_CTLS_SAVE_DEBUG_CONTROLS_FLAG,
1658 VmxBasicMsr.VmxControls ? IA32_VMX_TRUE_EXIT_CTLS : IA32_VMX_EXIT_CTLS);
1659
1660 //
1661 // Read 1-settings of load debug controls (entry controls)
1662 //
1663 UINT32 EntryCtls = HvAdjustControls(
1664 IA32_VMX_ENTRY_CTLS_LOAD_DEBUG_CONTROLS_FLAG,
1665 VmxBasicMsr.VmxControls ? IA32_VMX_TRUE_ENTRY_CTLS : IA32_VMX_ENTRY_CTLS);
1666
1667 //
1668 // Check if entry and exit controls are supported on this system
1669 //
1670 if (ExitCtls != NULL_ZERO && EntryCtls != NULL_ZERO)
1671 {
1672 //
1673 // Supported
1674 //
1675 return TRUE;
1676 }
1677 else
1678 {
1679 //
1680 // Not supported
1681 //
1682 return FALSE;
1683 }
1684}

◆ HvClearSteppingBits()

UINT64 HvClearSteppingBits ( UINT64 Interruptibility)

Clear STI and MOV SS bits.

Returns
UINT64
1267{
1268 UINT64 InterruptibilityState = Interruptibility;
1269
1270 InterruptibilityState &= ~(GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS);
1271
1272 return InterruptibilityState;
1273}
#define GUEST_INTR_STATE_STI
GUEST_INTERRUPTIBILITY_INFO flags.
Definition Vmx.h:48
#define GUEST_INTR_STATE_MOV_SS
Definition Vmx.h:49

◆ HvDisableExternalInterruptsAndInterruptWindow()

VOID HvDisableExternalInterruptsAndInterruptWindow ( VIRTUAL_MACHINE_STATE * VCpu)

Disable external-interrupts and interrupt window.

Parameters
VCpuThe virtual processor's state
Returns
VOID
1347{
1348 //
1349 // Change guest interrupt-state
1350 //
1352
1353 //
1354 // Do not vm-exit on interrupt windows
1355 //
1357
1359}
VOID HvSetInterruptWindowExiting(BOOLEAN Set)
Set Interrupt-window exiting.
Definition Hv.c:650

◆ HvEnableAndCheckForPreviousExternalInterrupts()

VOID HvEnableAndCheckForPreviousExternalInterrupts ( VIRTUAL_MACHINE_STATE * VCpu)

Checks to enable and reinject previous interrupts.

Parameters
VCpuThe virtual processor's state
Returns
VOID
Parameters
VCpuThe virtual processor's state
SetSet or unset the External Interrupt Exiting
Returns
VOID
1119{
1120 //
1121 // Check if we should enable interrupts in this core or not,
1122 // we have another same check in SWITCHING CORES too
1123 //
1125 {
1126 //
1127 // Enable normal interrupts
1128 //
1130
1131 //
1132 // Check if there is at least an interrupt that needs to be delivered
1133 //
1134 if (VCpu->PendingExternalInterrupts[0] != NULL_ZERO)
1135 {
1136 //
1137 // Enable Interrupt-window exiting.
1138 //
1140 }
1141
1143 }
1144}
BOOLEAN EnableExternalInterruptsOnContinueMtf
Definition State.h:318
UINT32 PendingExternalInterrupts[PENDING_INTERRUPTS_BUFFER_CAPACITY]
Definition State.h:344

◆ HvEnableMtfAndChangeExternalInterruptState()

VOID HvEnableMtfAndChangeExternalInterruptState ( VIRTUAL_MACHINE_STATE * VCpu)

Enables MTF and adjust external interrupt state.

Parameters
VCpuThe virtual processor's state
Returns
VOID
VOID
1439{
1440 //
1441 // We have to set Monitor trap flag and give it the HookedEntry to work with
1442 //
1444
1445 //
1446 // The following codes are added because we realized if the execution takes long then
1447 // the execution might be switched to another routines, thus, MTF might conclude on
1448 // another routine and we might (and will) trigger the same instruction soon
1449 //
1450
1451 //
1452 // Change guest interrupt-state
1453 //
1455
1456 //
1457 // Do not vm-exit on interrupt windows
1458 //
1460
1461 //
1462 // Indicate that we should enable external interrupts and configure external interrupt
1463 // window exiting somewhere at MTF
1464 //
1466}
VOID HvSetMonitorTrapFlag(BOOLEAN Set)
Set the monitor trap flag.
Definition Hv.c:345

◆ HvFillGuestSelectorData()

VOID HvFillGuestSelectorData ( PVOID GdtBase,
UINT32 SegmentRegister,
UINT16 Selector )

Fill the guest's selector data.

Fill guest selector data.

Parameters
GdtBase
SegmentRegister
Selector
Returns
VOID

Fill the guest's selector data.

Parameters
GdtBase
SegmentRegister
Selector
Returns
VOID
273{
275
277
278 if (Selector == 0x0)
279 {
280 SegmentSelector.Attributes.Unusable = TRUE;
281 }
282
283 SegmentSelector.Attributes.Reserved1 = 0;
284 SegmentSelector.Attributes.Reserved2 = 0;
285
286 VmxVmwrite64(VMCS_GUEST_ES_SELECTOR + SegmentRegister * 2, Selector);
287 VmxVmwrite64(VMCS_GUEST_ES_LIMIT + SegmentRegister * 2, SegmentSelector.Limit);
288 VmxVmwrite64(VMCS_GUEST_ES_ACCESS_RIGHTS + SegmentRegister * 2, SegmentSelector.Attributes.AsUInt);
289 VmxVmwrite64(VMCS_GUEST_ES_BASE + SegmentRegister * 2, SegmentSelector.Base);
290}
UCHAR VmxVmwrite64(size_t Field, UINT64 FieldValue)
VMX VMWRITE instruction (64-bit).
Definition PlatformIntrinsicsVmx.c:273
_Use_decl_annotations_ BOOLEAN SegmentGetDescriptor(PUCHAR GdtBase, UINT16 Selector, PVMX_SEGMENT_SELECTOR SegmentSelector)
Get Segment Descriptor.
Definition Segmentation.c:24
_In_ UINT16 Selector
Definition Segmentation.h:50
_In_ UINT16 _Out_ PVMX_SEGMENT_SELECTOR SegmentSelector
Definition Segmentation.h:51
struct _VMX_SEGMENT_SELECTOR VMX_SEGMENT_SELECTOR
Segment selector.

◆ HvGetAndStoreDebugctl()

VOID HvGetAndStoreDebugctl ( UINT64 * StoreDebugctl)

Get and store the guest state of IA32_DEBUGCTL.

mainly used from the VMCALL handler

Parameters
StoreDebugctl
Returns
VOID
1562{
1563 UINT64 DebugctlValue;
1564
1565 //
1566 // Read DEBUGCTL from VMCS
1567 //
1568 DebugctlValue = HvGetDebugctl();
1569
1570 //
1571 // Store the DEBUGCTL
1572 //
1573 *StoreDebugctl = DebugctlValue;
1574}
UINT64 HvGetDebugctl()
Get the guest state of IA32_DEBUGCTL.
Definition Hv.c:1526

◆ HvGetAndStoreGuestIa32LbrCtl()

VOID HvGetAndStoreGuestIa32LbrCtl ( UINT64 * StoreGuestIa32Lbr)

Get and store the guest state of IA32_LBR_CTL.

mainly used from the VMCALL handler

Parameters
StoreGuestIa32Lbr
Returns
VOID
1586{
1587 UINT64 GuestIa32LbrCtl;
1588
1589 //
1590 // Read IA32_LBR_CTL from VMCS
1591 //
1592 GuestIa32LbrCtl = HvGetGuestIa32LbrCtl();
1593
1594 //
1595 // Store the IA32_LBR_CTL
1596 //
1597 *StoreGuestIa32Lbr = GuestIa32LbrCtl;
1598}
UINT64 HvGetGuestIa32LbrCtl()
Get the guest state of IA32_LBR_CTL.
Definition Hv.c:1543

◆ HvGetCsSelector()

UINT16 HvGetCsSelector ( )

Read CS selector.

Returns
UINT16
1179{
1180 //
1181 // Only 16 bit is needed however, vmwrite might write on other bits
1182 // and corrupt other variables, that's why we get 64bit
1183 //
1184 UINT64 CsSel = NULL64_ZERO;
1185
1186 VmxVmread64P(VMCS_GUEST_CS_SELECTOR, &CsSel);
1187
1188 return CsSel & 0xffff;
1189}
UCHAR VmxVmread64P(size_t Field, UINT64 *FieldValue)
VMX VMREAD instruction (64-bit, pointer variant).
Definition PlatformIntrinsicsVmx.c:207
#define NULL64_ZERO
Definition BasicTypes.h:111

◆ HvGetDebugctl()

UINT64 HvGetDebugctl ( )

Get the guest state of IA32_DEBUGCTL.

Returns
UINT64
1527{
1528 UINT32 LowPart;
1529 UINT32 HighPart;
1530
1531 VmxVmread32P(VMCS_GUEST_DEBUGCTL, &LowPart);
1533
1534 return (UINT64)HighPart << 32 | LowPart;
1535}
UCHAR VmxVmread32P(size_t Field, UINT32 *FieldValue)
VMX VMREAD instruction (32-bit, pointer variant).
Definition PlatformIntrinsicsVmx.c:227
#define VMCS_GUEST_DEBUGCTL_HIGH
Definition Vmx.h:221

◆ HvGetGuestIa32LbrCtl()

UINT64 HvGetGuestIa32LbrCtl ( )

Get the guest state of IA32_LBR_CTL.

Returns
UINT64
1544{
1545 UINT64 GuestIa32LbrCtl;
1546
1547 VmxVmread64P(VMCS_GUEST_LBR_CTL, &GuestIa32LbrCtl);
1548
1549 return GuestIa32LbrCtl;
1550}

◆ HvGetInterruptibilityState()

UINT64 HvGetInterruptibilityState ( )

Read guest's interruptibility state.

Returns
UINT64
1252{
1253 UINT64 InterruptibilityState = NULL64_ZERO;
1254
1255 VmxVmread64P(VMCS_GUEST_INTERRUPTIBILITY_STATE, &InterruptibilityState);
1256
1257 return InterruptibilityState;
1258}

◆ HvGetPendingDebugExceptions()

UINT64 HvGetPendingDebugExceptions ( )

Get the guest state of pending debug exceptions.

Returns
UINT64
1501{
1502 UINT64 Value;
1503 VmxVmread64P(VMCS_GUEST_PENDING_DEBUG_EXCEPTIONS, &Value);
1504
1505 return Value;
1506}
RequestedActionOfThePacket Value(0x1) 00000000

◆ HvGetRflags()

UINT64 HvGetRflags ( )

Read guest's RFLAGS.

Returns
UINT64
1198{
1199 UINT64 Rflags = NULL64_ZERO;
1200
1201 VmxVmread64P(VMCS_GUEST_RFLAGS, &Rflags);
1202
1203 return Rflags;
1204}

◆ HvGetRip()

UINT64 HvGetRip ( )

Read guest's RIP.

Returns
UINT64
1225{
1226 UINT64 Rip = NULL64_ZERO;
1227
1228 VmxVmread64P(VMCS_GUEST_RIP, &Rip);
1229
1230 return Rip;
1231}

◆ HvHandleControlRegisterAccess()

VOID HvHandleControlRegisterAccess ( VIRTUAL_MACHINE_STATE * VCpu,
VMX_EXIT_QUALIFICATION_MOV_CR * CrExitQualification )

Handles Guest Access to control registers.

Handle Guest's Control Registers Access.

Parameters
VCpuThe virtual processor's state
Returns
VOID

Handles Guest Access to control registers.

Parameters
VCpu
Returns
VOID
142{
143 UINT64 * RegPtr;
144 UINT64 NewCr3;
145 CR3_TYPE NewCr3Reg;
146
147 RegPtr = (UINT64 *)&VCpu->Regs->rax + CrExitQualification->GeneralPurposeRegister;
148
149 //
150 // Because its RSP and as we didn't save RSP correctly (because of pushes)
151 // so we have make it points to the GUEST_RSP
152 //
153
154 //
155 // We handled it in vm-exit handler, commented
156 //
157
158 /*
159 if (CrExitQualification->Fields.Register == 4)
160 {
161 VmxVmread64P(VMCS_GUEST_RSP, &GuestRsp);
162 *RegPtr = GuestRsp;
163 }
164 */
165
166 switch (CrExitQualification->AccessType)
167 {
168 case VMX_EXIT_QUALIFICATION_ACCESS_MOV_TO_CR:
169 {
170 switch (CrExitQualification->ControlRegister)
171 {
172 case VMX_EXIT_QUALIFICATION_REGISTER_CR0:
173
174 VmxVmwrite64(VMCS_GUEST_CR0, *RegPtr);
175 VmxVmwrite64(VMCS_CTRL_CR0_READ_SHADOW, *RegPtr);
176
177 break;
178
179 case VMX_EXIT_QUALIFICATION_REGISTER_CR3:
180
181 NewCr3 = (*RegPtr & ~(1ULL << 63));
182 NewCr3Reg.Flags = NewCr3;
183
184 //
185 // Apply the new cr3
186 //
187 VmxVmwrite64(VMCS_GUEST_CR3, NewCr3Reg.Flags);
188
189 //
190 // Invalidate as we used VPID tags so the vm-exit won't
191 // normally (automatically) flush the TLB, we have to do
192 // it manually
193 //
195
196 //
197 // Call kernel debugger handler for mov to cr3 in kernel debugger
198 //
200
201 //
202 // Call handler of the reversing machine
203 //
205 {
207 }
208
209 break;
210
211 case VMX_EXIT_QUALIFICATION_REGISTER_CR4:
212
213 VmxVmwrite64(VMCS_GUEST_CR4, *RegPtr);
214 VmxVmwrite64(VMCS_CTRL_CR4_READ_SHADOW, *RegPtr);
215
216 break;
217
218 default:
219 LogWarning("Unsupported register 0x%x in handling control registers access",
220 CrExitQualification->ControlRegister);
221 break;
222 }
223 }
224 break;
225
226 case VMX_EXIT_QUALIFICATION_ACCESS_MOV_FROM_CR:
227 {
228 switch (CrExitQualification->ControlRegister)
229 {
230 case VMX_EXIT_QUALIFICATION_REGISTER_CR0:
231
232 VmxVmread64P(VMCS_GUEST_CR0, RegPtr);
233
234 break;
235
236 case VMX_EXIT_QUALIFICATION_REGISTER_CR3:
237
238 VmxVmread64P(VMCS_GUEST_CR3, RegPtr);
239
240 break;
241
242 case VMX_EXIT_QUALIFICATION_REGISTER_CR4:
243
244 VmxVmread64P(VMCS_GUEST_CR4, RegPtr);
245
246 break;
247
248 default:
249 LogWarning("Unsupported register 0x%x in handling control registers access",
250 CrExitQualification->ControlRegister);
251 break;
252 }
253 }
254 break;
255
256 default:
257 LogWarning("Unsupported operation 0x%x in handling control registers access",
258 CrExitQualification->AccessType);
259 break;
260 }
261}
VOID InterceptionCallbackTriggerCr3ProcessChange(UINT32 CoreId)
routine callback to handle cr3 process change
Definition Callback.c:398
VOID ExecTrapHandleCr3Vmexit(VIRTUAL_MACHINE_STATE *VCpu)
Handle MOV to CR3 vm-exits for hooking mode execution.
Definition ExecTrap.c:778
VOID VpidInvvpidSingleContext(UINT16 Vpid)
INVVPID Single Context.
Definition Vpid.c:68
#define VPID_TAG
VPID Tag.
Definition Vpid.h:30
struct _CR3_TYPE CR3_TYPE
CR3 Structure.
#define LogWarning(format,...)
Log in the case of warning.
Definition HyperDbgHyperLogIntrinsics.h:99
BOOLEAN g_ExecTrapInitialized
Showes whether the execution trap handler is allowed to trigger an event or not.
Definition GlobalVariables.h:162
GUEST_REGS * Regs
Definition State.h:326
UINT32 CoreId
Definition State.h:328
UINT64 rax
Definition BasicTypes.h:141

◆ HvHandleCpuid()

VOID HvHandleCpuid ( VIRTUAL_MACHINE_STATE * VCpu)

Handle Cpuid Vmexits.

Handle Cpuid.

Parameters
VCpuThe virtual processor's state
Returns
VOID

Handle Cpuid Vmexits.

Parameters
VCpu
Returns
VOID
68{
69 INT32 CpuInfo[4];
70 PGUEST_REGS Regs = VCpu->Regs;
71
72 //
73 // Otherwise, issue the CPUID to the logical processor based on the indexes
74 // on the VP's GPRs.
75 //
76 CpuCpuIdEx(CpuInfo, (INT32)Regs->rax, (INT32)Regs->rcx);
77
78 //
79 // check whether we are in transparent mode or not
80 // if we are in transparent mode then ignore the
81 // cpuid modifications e.g. hyperviosr name or bit
82 //
84 {
85 //
86 // Check if this was CPUID 1h, which is the features request
87 //
89 {
90 //
91 // Set the Hypervisor Present-bit in RCX, which Intel and AMD have both
92 // reserved for this indication
93 //
95 }
96 else if (Regs->rax == CPUID_HV_VENDOR_AND_MAX_FUNCTIONS)
97 {
98 //
99 // Return a maximum supported hypervisor CPUID leaf range and a vendor
100 // ID signature as required by the spec
101 //
102
103 CpuInfo[0] = HYPERV_CPUID_INTERFACE;
104 CpuInfo[1] = 'epyH'; // [HyperDbg]
105 CpuInfo[2] = 'gbDr';
106 CpuInfo[3] = 0;
107 }
108 else if (Regs->rax == HYPERV_CPUID_INTERFACE)
109 {
110 //
111 // Return non Hv#1 value. This indicate that our hypervisor does NOT
112 // conform to the Microsoft hypervisor interface.
113 //
114
115 CpuInfo[0] = '0#vH'; // Hv#0
116 CpuInfo[1] = CpuInfo[2] = CpuInfo[3] = 0;
117 }
118 }
119 else
120 {
121 TransparentCheckAndModifyCpuid(Regs, CpuInfo);
122 }
123
124 //
125 // Copy the values from the logical processor registers into the VP GPRs
126 //
127 Regs->rax = CpuInfo[0];
128 Regs->rbx = CpuInfo[1];
129 Regs->rcx = CpuInfo[2];
130 Regs->rdx = CpuInfo[3];
131}
VOID CpuCpuIdEx(INT32 *CpuInfo, INT32 FunctionId, INT32 SubFunctionId)
Execute CPUID with sub-leaf.
Definition PlatformIntrinsics.c:274
#define HYPERV_CPUID_INTERFACE
Definition Vmx.h:35
#define HYPERV_HYPERVISOR_PRESENT_BIT
Definition Vmx.h:40
signed int INT32
Definition BasicTypes.h:50
struct GUEST_REGS * PGUEST_REGS
#define CPUID_PROCESSOR_AND_PROCESSOR_FEATURE_IDENTIFIERS
CPUID Features.
Definition Constants.h:701
#define CPUID_HV_VENDOR_AND_MAX_FUNCTIONS
The Microsoft Hypervisor interface defined constants.
Definition Constants.h:676
IMPORT_EXPORT_HYPEREVADE VOID TransparentCheckAndModifyCpuid(PGUEST_REGS Regs, INT32 CpuInfo[])
Handle Cpuid Vmexits when the Transparent mode is enabled.
Definition VmxFootprints.c:24
BOOLEAN g_CheckForFootprints
Shows whether the footprints (anti-debugging and anti-hypervisor) should be checked or not.
Definition GlobalVariables.h:131
UINT64 rbx
Definition BasicTypes.h:144
UINT64 rcx
Definition BasicTypes.h:142
UINT64 rdx
Definition BasicTypes.h:143

◆ HvHandleMovDebugRegister()

VOID HvHandleMovDebugRegister ( VIRTUAL_MACHINE_STATE * VCpu)

Handle Mov to Debug Registers Exitings.

Parameters
VCpuThe virtual processor's state
Returns
VOID
Parameters
VCpu
Returns
VOID
793{
794 VMX_EXIT_QUALIFICATION_MOV_DR ExitQualification;
795 CR4 Cr4;
796 DR7 Dr7;
798 UINT64 * GpRegs = (UINT64 *)VCpu->Regs;
799
800 //
801 // The implementation is derived from Hvpp
802 //
803 VmxVmread64P(VMCS_EXIT_QUALIFICATION, &ExitQualification.AsUInt);
804
805 UINT64 GpRegister = GpRegs[ExitQualification.GeneralPurposeRegister];
806
807 //
808 // The MOV DR instruction causes a VM exit if the "MOV-DR exiting"
809 // VM-execution control is 1. Such VM exits represent an exception
810 // to the principles identified in Section 25.1.1 (Relative Priority
811 // of Faults and VM Exits) in that they take priority over the
812 // following: general-protection exceptions based on privilege level;
813 // and invalid-opcode exceptions that occur because CR4.DE = 1 and the
814 // instruction specified access to DR4 or DR5.
815 // (ref: Vol3C[25.1.3(Instructions That Cause VM Exits Conditionally)])
816 //
817 // TL;DR:
818 // CPU usually prioritizes exceptions. For example RDMSR executed
819 // at CPL = 3 won't cause VM-exit - it causes #GP instead. MOV DR
820 // is exception to this rule, as it ALWAYS cause VM-exit.
821 //
822 // Normally, CPU allows you to write to DR registers only at CPL=0,
823 // otherwise it causes #GP. Therefore we'll simulate the exact same
824 // behavior here.
825 //
826
827 Cs = GetGuestCs();
828
829 if (Cs.Attributes.DescriptorPrivilegeLevel != 0)
830 {
832
833 //
834 // Redo the instruction
835 //
837 return;
838 }
839
840 //
841 // Debug registers DR4 and DR5 are reserved when debug extensions
842 // are enabled (when the DE flag in control register CR4 is set)
843 // and attempts to reference the DR4 and DR5 registers cause
844 // invalid-opcode exceptions (#UD).
845 // When debug extensions are not enabled (when the DE flag is clear),
846 // these registers are aliased to debug registers DR6 and DR7.
847 // (ref: Vol3B[17.2.2(Debug Registers DR4 and DR5)])
848 //
849
850 //
851 // Read guest cr4
852 //
853 VmxVmread64P(VMCS_GUEST_CR4, &Cr4.AsUInt);
854
855 if (ExitQualification.DebugRegister == 4 || ExitQualification.DebugRegister == 5)
856 {
857 if (Cr4.DebuggingExtensions)
858 {
859 //
860 // re-inject #UD
861 //
863 return;
864 }
865 else
866 {
867 ExitQualification.DebugRegister += 2;
868 }
869 }
870
871 //
872 // Enables (when set) debug-register protection, which causes a
873 // debug exception to be generated prior to any MOV instruction
874 // that accesses a debug register. When such a condition is
875 // detected, the BD flag in debug status register DR6 is set prior
876 // to generating the exception. This condition is provided to
877 // support in-circuit emulators.
878 // When the emulator needs to access the debug registers, emulator
879 // software can set the GD flag to prevent interference from the
880 // program currently executing on the processor.
881 // The processor clears the GD flag upon entering to the debug
882 // exception handler, to allow the handler access to the debug
883 // registers.
884 // (ref: Vol3B[17.2.4(Debug Control Register (DR7)])
885 //
886
887 //
888 // Read the DR7
889 //
890 VmxVmread64P(VMCS_GUEST_DR7, &Dr7.AsUInt);
891
892 if (Dr7.GeneralDetect)
893 {
894 DR6 Dr6 = {
895 .AsUInt = CpuReadDr(6),
896 .BreakpointCondition = 0,
897 .DebugRegisterAccessDetected = TRUE};
898
899 CpuWriteDr(6, Dr6.AsUInt);
900
901 Dr7.GeneralDetect = FALSE;
902
903 VmxVmwrite64(VMCS_GUEST_DR7, Dr7.AsUInt);
904
906
907 //
908 // Redo the instruction
909 //
911
912 return;
913 }
914
915 //
916 // In 64-bit mode, the upper 32 bits of DR6 and DR7 are reserved
917 // and must be written with zeros. Writing 1 to any of the upper
918 // 32 bits results in a #GP(0) exception.
919 // (ref: Vol3B[17.2.6(Debug Registers and Intel 64 Processors)])
920 //
921 if (ExitQualification.DirectionOfAccess == VMX_EXIT_QUALIFICATION_DIRECTION_MOV_TO_DR &&
922 (ExitQualification.DebugRegister == VMX_EXIT_QUALIFICATION_REGISTER_DR6 ||
923 ExitQualification.DebugRegister == VMX_EXIT_QUALIFICATION_REGISTER_DR7) &&
924 (GpRegister >> 32) != 0)
925 {
927
928 //
929 // Redo the instruction
930 //
932 return;
933 }
934
935 switch (ExitQualification.DirectionOfAccess)
936 {
937 case VMX_EXIT_QUALIFICATION_DIRECTION_MOV_TO_DR:
938 switch (ExitQualification.DebugRegister)
939 {
940 case VMX_EXIT_QUALIFICATION_REGISTER_DR0:
941 CpuWriteDr(VMX_EXIT_QUALIFICATION_REGISTER_DR0, GpRegister);
942 break;
943 case VMX_EXIT_QUALIFICATION_REGISTER_DR1:
944 CpuWriteDr(VMX_EXIT_QUALIFICATION_REGISTER_DR1, GpRegister);
945 break;
946 case VMX_EXIT_QUALIFICATION_REGISTER_DR2:
947 CpuWriteDr(VMX_EXIT_QUALIFICATION_REGISTER_DR2, GpRegister);
948 break;
949 case VMX_EXIT_QUALIFICATION_REGISTER_DR3:
950 CpuWriteDr(VMX_EXIT_QUALIFICATION_REGISTER_DR3, GpRegister);
951 break;
952 case VMX_EXIT_QUALIFICATION_REGISTER_DR6:
953 CpuWriteDr(VMX_EXIT_QUALIFICATION_REGISTER_DR6, GpRegister);
954 break;
955 case VMX_EXIT_QUALIFICATION_REGISTER_DR7:
956 CpuWriteDr(VMX_EXIT_QUALIFICATION_REGISTER_DR7, GpRegister);
957 break;
958 default:
959 break;
960 }
961 break;
962
963 case VMX_EXIT_QUALIFICATION_DIRECTION_MOV_FROM_DR:
964 switch (ExitQualification.DebugRegister)
965 {
966 case VMX_EXIT_QUALIFICATION_REGISTER_DR0:
967 GpRegister = CpuReadDr(VMX_EXIT_QUALIFICATION_REGISTER_DR0);
968 break;
969 case VMX_EXIT_QUALIFICATION_REGISTER_DR1:
970 GpRegister = CpuReadDr(VMX_EXIT_QUALIFICATION_REGISTER_DR1);
971 break;
972 case VMX_EXIT_QUALIFICATION_REGISTER_DR2:
973 GpRegister = CpuReadDr(VMX_EXIT_QUALIFICATION_REGISTER_DR2);
974 break;
975 case VMX_EXIT_QUALIFICATION_REGISTER_DR3:
976 GpRegister = CpuReadDr(VMX_EXIT_QUALIFICATION_REGISTER_DR3);
977 break;
978 case VMX_EXIT_QUALIFICATION_REGISTER_DR6:
979 GpRegister = CpuReadDr(VMX_EXIT_QUALIFICATION_REGISTER_DR6);
980 break;
981 case VMX_EXIT_QUALIFICATION_REGISTER_DR7:
982 GpRegister = CpuReadDr(VMX_EXIT_QUALIFICATION_REGISTER_DR7);
983 break;
984 default:
985 break;
986 }
987
988 default:
989 break;
990 }
991}
VOID EventInjectUndefinedOpcode(VIRTUAL_MACHINE_STATE *VCpu)
Inject UD to the guest (Invalid Opcode - Undefined Opcode).
Definition Events.c:79
VOID EventInjectDebugBreakpoint()
Inject Debug Breakpoint Exception.
Definition Events.c:112
VOID EventInjectGeneralProtection()
Inject GP to the guest (Event Injection).
Definition Events.c:62
VOID HvSuppressRipIncrement(VIRTUAL_MACHINE_STATE *VCpu)
Suppress the incrementation of RIP.
Definition Hv.c:320
IMPORT_EXPORT_VMM VMX_SEGMENT_SELECTOR GetGuestCs()
Get the Guest Cs Selector.
Definition ManageRegs.c:49

◆ HvHandleTrapFlag()

VOID HvHandleTrapFlag ( )

Handle the case when the trap flag is set, and we need to inject the single-step exception right after vm-entry.

Returns
VOID
1755{
1756 IA32_DEBUGCTL_REGISTER Debugctl = {.AsUInt = HvGetDebugctl()};
1757 RFLAGS GuestRFlags = {.AsUInt = GetGuestRFlags()};
1758 VMX_PENDING_DEBUG_EXCEPTIONS PendingDebugExceptions;
1759 VMX_INTERRUPTIBILITY_STATE InterruptibilityState;
1760
1761 //
1762 // The btf flag means that the trap flag generates the single-step exception
1763 // only for branch instructions
1764 //
1765 if (GuestRFlags.TrapFlag && !Debugctl.Btf)
1766 {
1767 PendingDebugExceptions.AsUInt = HvGetPendingDebugExceptions();
1768 PendingDebugExceptions.Bs = 1;
1769 HvSetPendingDebugExceptions(PendingDebugExceptions.AsUInt);
1770
1771 InterruptibilityState.AsUInt = (UINT32)HvGetInterruptibilityState();
1772
1773 //
1774 // We also must clear this flag in case of instruction emulation to achieve
1775 // correctness of the single-step exception
1776 //
1777 if (InterruptibilityState.BlockingByMovSs)
1778 {
1779 InterruptibilityState.BlockingByMovSs = 0;
1780 HvSetInterruptibilityState(InterruptibilityState.AsUInt);
1781 }
1782 }
1783}
UINT64 HvGetInterruptibilityState()
Read guest's interruptibility state.
Definition Hv.c:1251
VOID HvSetPendingDebugExceptions(UINT64 Value)
Set the guest state of pending debug exceptions.
Definition Hv.c:1515
VOID HvSetInterruptibilityState(UINT64 InterruptibilityState)
Set guest's interruptibility state.
Definition Hv.c:1282
UINT64 HvGetPendingDebugExceptions()
Get the guest state of pending debug exceptions.
Definition Hv.c:1500
IMPORT_EXPORT_VMM UINT64 GetGuestRFlags()
Get the Guest Rflags value.
Definition ManageRegs.c:409

◆ HvInitVmm()

BOOLEAN HvInitVmm ( VMM_CALLBACKS * VmmCallbacks)

Initializes the hypervisor.

Parameters
VmmCallbacks
Returns
BOOLEAN
1369{
1370 ULONG ProcessorsCount;
1371 BOOLEAN Result = FALSE;
1372
1373 //
1374 // Save the callbacks
1375 //
1376 RtlCopyMemory(&g_Callbacks, VmmCallbacks, sizeof(VMM_CALLBACKS));
1377
1378 //
1379 // Check and define compatibility checks and processor constraints
1380 //
1382
1383 //
1384 // we allocate virtual machine here because
1385 // we want to use its state (vmx-root or vmx non-root) in logs
1386 //
1388
1389 if (!Result)
1390 {
1391 return FALSE;
1392 }
1393
1394 //
1395 // We have a zeroed guest state
1396 //
1397 ProcessorsCount = KeQueryActiveProcessorCount(0);
1398
1399 //
1400 // Set the core's id and initialize memory mapper
1401 //
1402 for (UINT32 i = 0; i < ProcessorsCount; i++)
1403 {
1404 g_GuestState[i].CoreId = i;
1405 }
1406
1407 //
1408 // Initialize memory mapper
1409 //
1411
1412 //
1413 // Make sure that transparent-mode is disabled
1414 //
1416 {
1418 }
1419
1420 //
1421 // Not waiting for the interrupt-window to inject page-faults
1422 //
1424
1425 //
1426 // Initializes VMX
1427 //
1428 return VmxInitialize();
1429}
VOID CompatibilityCheckPerformChecks()
Checks for the compatibility features based on current processor @detail NOTE: NOT ALL OF THE CHECKS ...
Definition CompatibilityChecks.c:183
BOOLEAN GlobalGuestStateAllocateZeroedMemory(VOID)
Allocate guest state memory.
Definition GlobalVariableManagement.c:20
VOID MemoryMapperInitialize()
Initialize the Memory Mapper.
Definition MemoryMapper.c:661
BOOLEAN VmxInitialize()
Initialize the VMX operation.
Definition Vmx.c:114
UCHAR BOOLEAN
Definition BasicTypes.h:35
unsigned long ULONG
Definition BasicTypes.h:31
IMPORT_EXPORT_VMM BOOLEAN TransparentUnhideDebuggerWrapper(DEBUGGER_HIDE_AND_TRANSPARENT_DEBUGGER_MODE *TransparentModeRequest)
Deactivate transparent-mode.
Definition HyperEvade.c:125
struct _VMM_CALLBACKS VMM_CALLBACKS
Prototype of each function needed by VMM module.
HYPEREVADE_CALLBACKS g_Callbacks
List of callbacks.
Definition Transparency.h:23
VIRTUAL_MACHINE_STATE * g_GuestState
Save the state and variables related to virtualization on each to logical core.
Definition GlobalVariables.h:38
BOOLEAN g_WaitingForInterruptWindowToInjectPageFault
Shows whether the VMM is waiting to inject a page-fault or not.
Definition GlobalVariables.h:192

◆ HvInjectPendingExternalInterrupts()

VOID HvInjectPendingExternalInterrupts ( VIRTUAL_MACHINE_STATE * VCpu)

Inject pending external interrupts.

Parameters
VCpuThe virtual processor's state
Returns
VOID
1296{
1297 //
1298 // Check if there is at least an interrupt that needs to be delivered
1299 //
1300 if (VCpu->PendingExternalInterrupts[0] != NULL_ZERO)
1301 {
1302 //
1303 // Enable Interrupt-window exiting.
1304 //
1306 }
1307}

◆ HvPerformRipIncrement()

VOID HvPerformRipIncrement ( VIRTUAL_MACHINE_STATE * VCpu)
inline

Perform the incrementation of RIP.

Parameters
VCpuThe virtual processor's state
Returns
VOID
334{
335 VCpu->IncrementRip = TRUE;
336}
BOOLEAN IncrementRip
Definition State.h:313

◆ HvPreventExternalInterrupts()

VOID HvPreventExternalInterrupts ( VIRTUAL_MACHINE_STATE * VCpu)

Adjust external interrupt state.

Parameters
VCpuThe virtual processor's state
Returns
VOID
1476{
1477 //
1478 // Change guest interrupt-state
1479 //
1481
1482 //
1483 // Do not vm-exit on interrupt windows
1484 //
1486
1487 //
1488 // Indicate that we should enable external interrupts and configure external interrupt
1489 // window exiting somewhere at MTF
1490 //
1492}

◆ HvReadExceptionBitmap()

UINT32 HvReadExceptionBitmap ( )

Read exception bitmap in VMCS.

Read the exception bitmap.

Should be called in vmx-root

Returns
UINT32

Read exception bitmap in VMCS.

Returns
UINT32
632{
633 UINT32 ExceptionBitmap = 0;
634
635 //
636 // Read the current bitmap
637 //
638 VmxVmread32P(VMCS_CTRL_EXCEPTION_BITMAP, &ExceptionBitmap);
639
640 return ExceptionBitmap;
641}

◆ HvRestoreRegisters()

VOID HvRestoreRegisters ( )

Reset GDTR/IDTR and other old when you do vmxoff as the patchguard will detect them left modified.

Returns
VOID
492{
493 UINT64 FsBase;
494 UINT64 GsBase;
495 UINT64 GdtrBase;
496 UINT64 GdtrLimit;
497 UINT64 IdtrBase;
498 UINT64 IdtrLimit;
499 UINT16 DsSelector;
500 UINT16 EsSelector;
501 UINT16 SsSelector;
502 UINT16 FsSelector;
503
504 //
505 // Restore FS Base
506 //
507 VmxVmread64P(VMCS_GUEST_FS_BASE, &FsBase);
508 CpuWriteMsr(IA32_FS_BASE, FsBase);
509
510 //
511 // Restore Gs Base
512 //
513 VmxVmread64P(VMCS_GUEST_GS_BASE, &GsBase);
514 CpuWriteMsr(IA32_GS_BASE, GsBase);
515
516 //
517 // Restore GDTR
518 //
519 VmxVmread64P(VMCS_GUEST_GDTR_BASE, &GdtrBase);
520 VmxVmread64P(VMCS_GUEST_GDTR_LIMIT, &GdtrLimit);
521
522 AsmReloadGdtr((PVOID)GdtrBase, (ULONG)GdtrLimit);
523
524 //
525 // Restore Segment Selector
526 //
527 VmxVmread16P(VMCS_GUEST_DS_SELECTOR, &DsSelector);
528 AsmSetDs(DsSelector);
529 VmxVmread16P(VMCS_GUEST_ES_SELECTOR, &EsSelector);
530 AsmSetEs(EsSelector);
531 VmxVmread16P(VMCS_GUEST_SS_SELECTOR, &SsSelector);
532 AsmSetSs(SsSelector);
533 VmxVmread16P(VMCS_GUEST_FS_SELECTOR, &FsSelector);
534 AsmSetFs(FsSelector);
535
536 //
537 // Restore IDTR
538 //
539 VmxVmread64P(VMCS_GUEST_IDTR_BASE, &IdtrBase);
540 VmxVmread64P(VMCS_GUEST_IDTR_LIMIT, &IdtrLimit);
541
542 AsmReloadIdtr((PVOID)IdtrBase, (ULONG)IdtrLimit);
543}
VOID AsmSetFs(UINT16 FsSelector)
VOID AsmReloadIdtr(PVOID IdtrBase, ULONG IdtrLimit)
Reload new IDTR.
VOID AsmSetEs(UINT16 EsSelector)
VOID AsmSetSs(UINT16 SsSelector)
VOID AsmReloadGdtr(PVOID GdtBase, ULONG GdtLimit)
Reload new GDTR.
VOID AsmSetDs(UINT16 DsSelector)
VOID CpuWriteMsr(ULONG MsrAddress, UINT64 MsrValue)
Write an MSR.
Definition PlatformIntrinsics.c:233
UCHAR VmxVmread16P(size_t Field, UINT16 *FieldValue)
VMX VMREAD instruction (16-bit, pointer variant).
Definition PlatformIntrinsicsVmx.c:250
unsigned short UINT16
Definition BasicTypes.h:53
void * PVOID
Definition BasicTypes.h:56

◆ HvResumeToNextInstruction()

VOID HvResumeToNextInstruction ( )

Add the current instruction length to guest rip to resume to next instruction.

Resume GUEST_RIP to next instruction.

Returns
VOID

Add the current instruction length to guest rip to resume to next instruction.

Returns
VOID
299{
300 UINT64 ResumeRIP = NULL64_ZERO;
301 UINT64 CurrentRIP = NULL64_ZERO;
302 SIZE_T ExitInstructionLength = 0;
303
304 VmxVmread64P(VMCS_GUEST_RIP, &CurrentRIP);
305 VmxVmread64P(VMCS_VMEXIT_INSTRUCTION_LENGTH, &ExitInstructionLength);
306
307 ResumeRIP = CurrentRIP + ExitInstructionLength;
308
309 VmxVmwrite64(VMCS_GUEST_RIP, ResumeRIP);
310}

◆ HvSetClearGuestIa32LbrCtl()

VOID HvSetClearGuestIa32LbrCtl ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set SAVE GUEST IA32_LBR_CTL on Vm-exit controls.

Parameters
VCpu
SetSet or unset
Returns
VOID
460{
461 UNREFERENCED_PARAMETER(VCpu);
462
463 UINT32 VmexitControls = 0;
464
465 //
466 // Read the previous flags
467 //
468 VmxVmread32P(VMCS_CTRL_PRIMARY_VMEXIT_CONTROLS, &VmexitControls);
469
470 if (Set)
471 {
472 VmexitControls |= IA32_VMX_EXIT_CTLS_CLEAR_IA32_LBR_CTL_FLAG;
473 }
474 else
475 {
476 VmexitControls &= ~IA32_VMX_EXIT_CTLS_CLEAR_IA32_LBR_CTL_FLAG;
477 }
478
479 //
480 // Set the new value
481 //
482 VmxVmwrite32(VMCS_CTRL_PRIMARY_VMEXIT_CONTROLS, VmexitControls);
483}
UCHAR VmxVmwrite32(size_t Field, UINT32 FieldValue)
VMX VMWRITE instruction (32-bit).
Definition PlatformIntrinsicsVmx.c:293

◆ HvSetDebugctl()

VOID HvSetDebugctl ( UINT64 Value)

Set the guest state of IA32_DEBUGCTL.

Parameters
ValueThe new state
Returns
VOID
1608{
1609 VmxVmwrite32(VMCS_GUEST_DEBUGCTL, Value & 0xFFFFFFFF);
1611}

◆ HvSetDebugReg7()

VOID HvSetDebugReg7 ( UINT64 Value)

Set the guest state of DR7.

Parameters
ValueThe new value for DR7
Returns
VOID
1742{
1743 VmxVmwrite64(VMCS_GUEST_DR7, Value);
1744}

◆ HvSetExceptionBitmap()

VOID HvSetExceptionBitmap ( VIRTUAL_MACHINE_STATE * VCpu,
UINT32 IdtIndex )

Set exception bitmap in VMCS.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
IdtIndexInterrupt Descriptor Table index of exception
Returns
VOID

Should be called in vmx-root

Parameters
IdtIndex
Returns
VOID
1070{
1071 //
1072 // This is a wrapper to perform extra checks
1073 //
1074 ProtectedHvSetExceptionBitmap(VCpu, IdtIndex);
1075}
VOID ProtectedHvSetExceptionBitmap(VIRTUAL_MACHINE_STATE *VCpu, UINT32 IdtIndex)
Set exception bitmap in VMCS.
Definition ProtectedHv.c:76

◆ HvSetExternalInterruptExiting()

VOID HvSetExternalInterruptExiting ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set the External Interrupt Exiting.

Parameters
VCpuThe virtual processor's state
SetSet or unset the External Interrupt Exiting
Returns
VOID
Parameters
Set
Returns
VOID
1103{
1104 //
1105 // This is a wrapper to perform extra checks
1106 //
1108}
VOID ProtectedHvSetExternalInterruptExiting(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
Set the External Interrupt Exiting.
Definition ProtectedHv.c:259

◆ HvSetGuestIa32LbrCtl()

VOID HvSetGuestIa32LbrCtl ( UINT64 Value)

Set the guest state of IA32_LBR_CTL.

Parameters
ValueThe new state
Returns
VOID
1621{
1622 VmxVmwrite64(VMCS_GUEST_LBR_CTL, Value);
1623}

◆ HvSetGuestSelector()

BOOLEAN HvSetGuestSelector ( PVOID GdtBase,
UINT32 SegmentRegister,
UINT16 Selector )

Set guest's selector registers.

Set Guest Selector Registers.

Parameters
GdtBase
SegmentRegister
Selector
Returns
BOOLEAN

Set guest's selector registers.

Parameters
GdtBase
SegmentRegister
Selector
Returns
BOOLEAN
43{
46
47 if (Selector == 0x0)
48 {
49 SegmentSelector.Attributes.Unusable = TRUE;
50 }
51
52 VmxVmwrite64(VMCS_GUEST_ES_SELECTOR + SegmentRegister * 2, Selector);
53 VmxVmwrite64(VMCS_GUEST_ES_LIMIT + SegmentRegister * 2, SegmentSelector.Limit);
54 VmxVmwrite64(VMCS_GUEST_ES_ACCESS_RIGHTS + SegmentRegister * 2, SegmentSelector.Attributes.AsUInt);
55 VmxVmwrite64(VMCS_GUEST_ES_BASE + SegmentRegister * 2, SegmentSelector.Base);
56
57 return TRUE;
58}

◆ HvSetInterruptibilityState()

VOID HvSetInterruptibilityState ( UINT64 InterruptibilityState)

Set guest's interruptibility state.

Parameters
InterruptibilityState
Returns
VOID
1283{
1284 VmxVmwrite64(VMCS_GUEST_INTERRUPTIBILITY_STATE, InterruptibilityState);
1285}

◆ HvSetInterruptWindowExiting()

VOID HvSetInterruptWindowExiting ( BOOLEAN Set)

Set Interrupt-window exiting.

Parameters
SetSet or unset the Interrupt-window exiting
Returns
VOID
Parameters
Set
Returns
VOID
651{
652 UINT32 CpuBasedVmExecControls = 0;
653
654 //
655 // Read the previous flags
656 //
657 VmxVmread32P(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, &CpuBasedVmExecControls);
658
659 //
660 // interrupt-window exiting
661 //
662 if (Set)
663 {
664 CpuBasedVmExecControls |= IA32_VMX_PROCBASED_CTLS_INTERRUPT_WINDOW_EXITING_FLAG;
665 }
666 else
667 {
668 CpuBasedVmExecControls &= ~IA32_VMX_PROCBASED_CTLS_INTERRUPT_WINDOW_EXITING_FLAG;
669 }
670
671 //
672 // Set the new value
673 //
674 VmxVmwrite64(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, CpuBasedVmExecControls);
675}

◆ HvSetLbrSelect()

VOID HvSetLbrSelect ( UINT64 FilterOptions)

Set LBR selector.

If VMM is active, this should be done in vmx-root, otherwise, it doesn't work

Parameters
FilterOptionsThe value to write on MSR_LEGACY_LBR_SELECT
Returns
VOID
1634{
1635 CpuWriteMsr(MSR_LEGACY_LBR_SELECT, FilterOptions);
1636}
#define MSR_LEGACY_LBR_SELECT
MSR address of LBR_SELECT, which is used to configure the LBR filtering options.
Definition LbrDefinitions.h:21

◆ HvSetLoadDebugControls()

VOID HvSetLoadDebugControls ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set LOAD DEBUG CONTROLS on Vm-entry controls.

Parameters
VCpu
SetSet or unset
Returns
VOID
400{
402}
VOID ProtectedHvSetLoadDebugControls(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
Set SAVE DEBUG CONTROLS on VM-exit controls.
Definition ProtectedHv.c:658

◆ HvSetLoadGuestIa32LbrCtl()

VOID HvSetLoadGuestIa32LbrCtl ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set LOAD GUEST IA32_LBR_CTL on Vm-entry controls.

Parameters
VCpu
SetSet or unset
Returns
VOID
413{
414 UNREFERENCED_PARAMETER(VCpu);
415
416 UINT32 VmentryControls = 0;
417
418 //
419 // Read the previous flags
420 //
421 VmxVmread32P(VMCS_CTRL_VMENTRY_CONTROLS, &VmentryControls);
422
423 if (Set)
424 {
425 VmentryControls |= IA32_VMX_ENTRY_CTLS_LOAD_IA32_LBR_CTL_FLAG;
426 }
427 else
428 {
429 VmentryControls &= ~IA32_VMX_ENTRY_CTLS_LOAD_IA32_LBR_CTL_FLAG;
430 }
431
432 //
433 // Set the new value
434 //
435 VmxVmwrite32(VMCS_CTRL_VMENTRY_CONTROLS, VmentryControls);
436}

◆ HvSetModeBasedExecutionEnableFlag()

VOID HvSetModeBasedExecutionEnableFlag ( BOOLEAN Set)

Set Mode-based Execution Control (MBEC) Enable bit.

Parameters
SetSet or unset the MBEC
Returns
VOID
722{
723 UINT32 AdjSecCtrl;
724 UINT32 SecondaryProcBasedVmExecControls = 0;
725
726 //
727 // Read the previous flags
728 //
729 VmxVmread32P(VMCS_CTRL_SECONDARY_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, &SecondaryProcBasedVmExecControls);
730
731 //
732 // PML enable flag
733 //
734 if (Set)
735 {
736 SecondaryProcBasedVmExecControls |= IA32_VMX_PROCBASED_CTLS2_MODE_BASED_EXECUTE_CONTROL_FOR_EPT_FLAG;
737 }
738 else
739 {
740 SecondaryProcBasedVmExecControls &= ~IA32_VMX_PROCBASED_CTLS2_MODE_BASED_EXECUTE_CONTROL_FOR_EPT_FLAG;
741 }
742
743 AdjSecCtrl = HvAdjustControls(SecondaryProcBasedVmExecControls, IA32_VMX_PROCBASED_CTLS2);
744
745 //
746 // Set the new value
747 //
748 VmxVmwrite64(VMCS_CTRL_SECONDARY_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, AdjSecCtrl);
749}

◆ HvSetMonitorTrapFlag()

VOID HvSetMonitorTrapFlag ( BOOLEAN Set)

Set the monitor trap flag.

Set or unset the monitor trap flags.

Parameters
SetSet or unset the MTFs
Returns
VOID

Set the monitor trap flag.

Parameters
Set
Returns
VOID
346{
347 UINT32 CpuBasedVmExecControls = 0;
348
349 //
350 // Read the previous flags
351 //
352 VmxVmread32P(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, &CpuBasedVmExecControls);
353
354 if (Set)
355 {
356 CpuBasedVmExecControls |= IA32_VMX_PROCBASED_CTLS_MONITOR_TRAP_FLAG_FLAG;
357 }
358 else
359 {
360 CpuBasedVmExecControls &= ~IA32_VMX_PROCBASED_CTLS_MONITOR_TRAP_FLAG_FLAG;
361 }
362
363 //
364 // Set the new value
365 //
366 VmxVmwrite64(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, CpuBasedVmExecControls);
367}

◆ HvSetMovControlRegsExiting()

VOID HvSetMovControlRegsExiting ( BOOLEAN Set,
UINT64 ControlRegister,
UINT64 MaskRegister )

Set vm-exit for mov-to-cr0/4.

Should be called in vmx-root

Parameters
Setor unset the vm-exits
ControlRegister
MaskRegister
Returns
VOID
Parameters
Set
ControlRegister
MaskRegister
Returns
VOID
588{
589 ProtectedHvSetMov2CrExiting(Set, ControlRegister, MaskRegister);
590}
VOID ProtectedHvSetMov2CrExiting(BOOLEAN Set, UINT64 ControlRegister, UINT64 MaskRegister)
Set MOV to CR0/4 Exiting.
Definition ProtectedHv.c:749

◆ HvSetMovDebugRegsExiting()

VOID HvSetMovDebugRegsExiting ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set or unset the Mov to Debug Registers Exiting.

Set the Mov to Debug Registers Exiting.

Parameters
VCpuThe virtual processor's state
SetSet or unset the Mov to Debug Registers Exiting
Returns
VOID

Set or unset the Mov to Debug Registers Exiting.

Parameters
Set
Returns
VOID
1168{
1170}
VOID ProtectedHvSetMovDebugRegsExiting(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
Set MOV to HW Debug Regs Exiting.
Definition ProtectedHv.c:696

◆ HvSetMovToCr3Vmexit()

VOID HvSetMovToCr3Vmexit ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set vm-exit for mov-to-cr3.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
SetSet or unset the vm-exits
Returns
VOID
Parameters
Set
Returns
VOID
603{
605}
VOID ProtectedHvSetMov2Cr3Exiting(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
Set MOV to CR3 Exiting.
Definition ProtectedHv.c:735

◆ HvSetNmiExiting()

VOID HvSetNmiExiting ( BOOLEAN Set)

Set the NMI Exiting.

Parameters
SetSet or unset the NMI Exiting
Returns
VOID
Parameters
Set
Returns
VOID
1001{
1002 UINT32 PinBasedControls = 0;
1003 UINT32 VmExitControls = 0;
1004
1005 //
1006 // Read the previous flags
1007 //
1008 VmxVmread32P(VMCS_CTRL_PIN_BASED_VM_EXECUTION_CONTROLS, &PinBasedControls);
1009 VmxVmread32P(VMCS_CTRL_PRIMARY_VMEXIT_CONTROLS, &VmExitControls);
1010
1011 if (Set)
1012 {
1013 PinBasedControls |= IA32_VMX_PINBASED_CTLS_NMI_EXITING_FLAG;
1014 VmExitControls |= IA32_VMX_EXIT_CTLS_ACKNOWLEDGE_INTERRUPT_ON_EXIT_FLAG;
1015 }
1016 else
1017 {
1018 PinBasedControls &= ~IA32_VMX_PINBASED_CTLS_NMI_EXITING_FLAG;
1019 VmExitControls &= ~IA32_VMX_EXIT_CTLS_ACKNOWLEDGE_INTERRUPT_ON_EXIT_FLAG;
1020 }
1021
1022 //
1023 // Set the new value
1024 //
1025 VmxVmwrite64(VMCS_CTRL_PIN_BASED_VM_EXECUTION_CONTROLS, PinBasedControls);
1026 VmxVmwrite64(VMCS_CTRL_PRIMARY_VMEXIT_CONTROLS, VmExitControls);
1027}

◆ HvSetNmiWindowExiting()

VOID HvSetNmiWindowExiting ( BOOLEAN Set)

Set NMI-window exiting.

Parameters
SetSet or unset the NMI-window exiting
Returns
VOID
Parameters
Set
Returns
VOID
759{
760 UINT32 CpuBasedVmExecControls = 0;
761
762 //
763 // Read the previous flags
764 //
765 VmxVmread32P(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, &CpuBasedVmExecControls);
766
767 //
768 // interrupt-window exiting
769 //
770 if (Set)
771 {
772 CpuBasedVmExecControls |= IA32_VMX_PROCBASED_CTLS_NMI_WINDOW_EXITING_FLAG;
773 }
774 else
775 {
776 CpuBasedVmExecControls &= ~IA32_VMX_PROCBASED_CTLS_NMI_WINDOW_EXITING_FLAG;
777 }
778
779 //
780 // Set the new value
781 //
782 VmxVmwrite64(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, CpuBasedVmExecControls);
783}

◆ HvSetPendingDebugExceptions()

VOID HvSetPendingDebugExceptions ( UINT64 Value)

Set the guest state of pending debug exceptions.

Parameters
ValueThe new state
Returns
VOID
1516{
1517 VmxVmwrite64(VMCS_GUEST_PENDING_DEBUG_EXCEPTIONS, Value);
1518}

◆ HvSetPmcVmexit()

VOID HvSetPmcVmexit ( BOOLEAN Set)

Set vm-exit for rdpmc instructions.

Should be called in vmx-root

Parameters
SetSet or unset the vm-exits
Returns
VOID
Parameters
Set
Returns
VOID
554{
555 UINT32 CpuBasedVmExecControls = 0;
556
557 //
558 // Read the previous flags
559 //
560 VmxVmread32P(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, &CpuBasedVmExecControls);
561
562 if (Set)
563 {
564 CpuBasedVmExecControls |= IA32_VMX_PROCBASED_CTLS_RDPMC_EXITING_FLAG;
565 }
566 else
567 {
568 CpuBasedVmExecControls &= ~IA32_VMX_PROCBASED_CTLS_RDPMC_EXITING_FLAG;
569 }
570
571 //
572 // Set the new value
573 //
574 VmxVmwrite64(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, CpuBasedVmExecControls);
575}

◆ HvSetPmlEnableFlag()

VOID HvSetPmlEnableFlag ( BOOLEAN Set)

Set Page Modification Logging Enable bit.

Parameters
SetSet or unset the PML
Returns
VOID
685{
686 UINT32 AdjSecCtrl;
687 UINT32 SecondaryProcBasedVmExecControls = 0;
688
689 //
690 // Read the previous flags
691 //
692 VmxVmread32P(VMCS_CTRL_SECONDARY_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, &SecondaryProcBasedVmExecControls);
693
694 //
695 // PML enable flag
696 //
697 if (Set)
698 {
699 SecondaryProcBasedVmExecControls |= IA32_VMX_PROCBASED_CTLS2_ENABLE_PML_FLAG;
700 }
701 else
702 {
703 SecondaryProcBasedVmExecControls &= ~IA32_VMX_PROCBASED_CTLS2_ENABLE_PML_FLAG;
704 }
705
706 AdjSecCtrl = HvAdjustControls(SecondaryProcBasedVmExecControls, IA32_VMX_PROCBASED_CTLS2);
707
708 //
709 // Set the new value
710 //
711 VmxVmwrite64(VMCS_CTRL_SECONDARY_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, AdjSecCtrl);
712}

◆ HvSetRdtscExiting()

VOID HvSetRdtscExiting ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set the RDTSC/P Exiting.

Parameters
VCpuThe virtual processor's state
SetSet or unset the RDTSC/P Exiting
Returns
VOID
Parameters
Set
Returns
VOID
1155{
1156 ProtectedHvSetRdtscExiting(VCpu, Set);
1157}
VOID ProtectedHvSetRdtscExiting(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
Set the RDTSC/P Exiting.
Definition ProtectedHv.c:671

◆ HvSetRflags()

VOID HvSetRflags ( UINT64 Rflags)

Set guest's RFLAGS.

Parameters
Rflags
Returns
VOID
1214{
1215 VmxVmwrite64(VMCS_GUEST_RFLAGS, Rflags);
1216}

◆ HvSetRflagTrapFlag()

VOID HvSetRflagTrapFlag ( BOOLEAN Set)

Set the rflag's trap flag.

Parameters
SetSet or unset the TF
Returns
VOID
378{
379 RFLAGS Rflags = {0};
380
381 //
382 // Unset the trap-flag, as we set it before we have to mask it now
383 //
384 Rflags.AsUInt = HvGetRflags();
385
386 Rflags.TrapFlag = Set;
387
388 HvSetRflags(Rflags.AsUInt);
389}
UINT64 HvGetRflags()
Read guest's RFLAGS.
Definition Hv.c:1197
VOID HvSetRflags(UINT64 Rflags)
Set guest's RFLAGS.
Definition Hv.c:1213

◆ HvSetRip()

VOID HvSetRip ( UINT64 Rip)

Set guest's RIP.

Parameters
Rip
Returns
VOID
1241{
1242 VmxVmwrite64(VMCS_GUEST_RIP, Rip);
1243}

◆ HvSetSaveDebugControls()

VOID HvSetSaveDebugControls ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set SAVE DEBUG CONTROLS on Vm-exit controls.

Parameters
VCpu
SetSet or unset
Returns
VOID
447{
449}
VOID ProtectedHvSetSaveDebugControls(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
Set LOAD DEBUG CONTROLS on VM-entry controls.
Definition ProtectedHv.c:644

◆ HvSetVmxPreemptionTimerExiting()

VOID HvSetVmxPreemptionTimerExiting ( BOOLEAN Set)

Set the VMX preemption timer.

Set the VMX Preemptiom Timer.

Parameters
SetSet or unset the VMX preemption timer
Returns
VOID

Set the VMX preemption timer.

Parameters
Set
Returns
VOID
1037{
1038 UINT32 PinBasedControls = 0;
1039
1040 //
1041 // Read the previous flags
1042 //
1043 VmxVmread32P(VMCS_CTRL_PIN_BASED_VM_EXECUTION_CONTROLS, &PinBasedControls);
1044
1045 if (Set)
1046 {
1047 PinBasedControls |= IA32_VMX_PINBASED_CTLS_ACTIVATE_VMX_PREEMPTION_TIMER_FLAG;
1048 }
1049 else
1050 {
1051 PinBasedControls &= ~IA32_VMX_PINBASED_CTLS_ACTIVATE_VMX_PREEMPTION_TIMER_FLAG;
1052 }
1053
1054 //
1055 // Set the new value
1056 //
1057 VmxVmwrite64(VMCS_CTRL_PIN_BASED_VM_EXECUTION_CONTROLS, PinBasedControls);
1058}

◆ HvSuppressRipIncrement()

VOID HvSuppressRipIncrement ( VIRTUAL_MACHINE_STATE * VCpu)
inline

Suppress the incrementation of RIP.

Parameters
VCpuThe virtual processor's state
Returns
VOID
321{
322 VCpu->IncrementRip = FALSE;
323}

◆ HvUnsetExceptionBitmap()

VOID HvUnsetExceptionBitmap ( VIRTUAL_MACHINE_STATE * VCpu,
UINT32 IdtIndex )

Unset exception bitmap in VMCS.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
IdtIndexInterrupt Descriptor Table index of exception
Returns
VOID

Should be called in vmx-root

Parameters
IdtIndex
Returns
VOID
1087{
1088 //
1089 // This is a wrapper to perform extra checks
1090 //
1091 ProtectedHvUnsetExceptionBitmap(VCpu, IdtIndex);
1092}
VOID ProtectedHvUnsetExceptionBitmap(VIRTUAL_MACHINE_STATE *VCpu, UINT32 IdtIndex)
Unset exception bitmap in VMCS.
Definition ProtectedHv.c:109

◆ HvWriteExceptionBitmap()

VOID HvWriteExceptionBitmap ( UINT32 BitmapMask)

Write on exception bitmap in VMCS DO NOT CALL IT DIRECTLY, instead use HvSetExceptionBitmap.

Write to the exception bitmap.

Should be called in vmx-root

Parameters
BitmapMaskThe content to write on exception bitmap
Returns
VOID

Write on exception bitmap in VMCS DO NOT CALL IT DIRECTLY, instead use HvSetExceptionBitmap.

Parameters
BitmapMask
Returns
VOID
617{
618 //
619 // Set the new value
620 //
621 VmxVmwrite64(VMCS_CTRL_EXCEPTION_BITMAP, BitmapMask);
622}