HyperDbg Debugger
Loading...
Searching...
No Matches
Vmx.h
Go to the documentation of this file.
1
12#pragma once
13
15// Constants //
17
22#define VMCS_SIZE 4096
23
28#define VMXON_SIZE 4096
29
34#define HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS 0x40000000
35#define HYPERV_CPUID_INTERFACE 0x40000001
36#define HYPERV_CPUID_VERSION 0x40000002
37#define HYPERV_CPUID_FEATURES 0x40000003
38#define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004
39#define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005
40#define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000
41#define HYPERV_CPUID_MIN 0x40000005
42#define HYPERV_CPUID_MAX 0x4000ffff
43
48#define GUEST_INTR_STATE_STI 0x00000001
49#define GUEST_INTR_STATE_MOV_SS 0x00000002
50#define GUEST_INTR_STATE_SMI 0x00000004
51#define GUEST_INTR_STATE_NMI 0x00000008
52#define GUEST_INTR_STATE_ENCLAVE_INTR 0x00000010
53
58#define SHADOW_INT_MOV_SS 0x01
59#define SHADOW_INT_STI 0x02
60
65#define VMM_STACK_SIZE 0x8000
66
67#define IS_VALID_DEBUG_REGISTER(DebugRegister) \
68 (((DebugRegister <= VMX_EXIT_QUALIFICATION_REGISTER_DR0) && (DebugRegister <= VMX_EXIT_QUALIFICATION_REGISTER_DR7)) && (DebugRegister != 0x00000004 && DebugRegister != 0x00000005))
69
75{
76 UINT64 Flags;
77 struct
78 {
79 UINT64 CallCode : 16; // HYPERCALL_CODE
80 UINT64 Fast : 1;
82 UINT64 IsNested : 1;
83 UINT64 Reserved0 : 5;
84 UINT64 RepCount : 12;
85 UINT64 Reserved1 : 4;
86 UINT64 RepStartIndex : 12;
87 UINT64 Reserved2 : 4;
89
91
97{
102 // 0x0005..0x0007 are reserved
116 // 0x0016..0x003F are reserved
131 HvCreateVp = 0x004E,
132 HvDeleteVp = 0x004F,
136 HvReadGpa = 0x0053,
137 HvWriteGpa = 0x0054,
138 // 0x0055 is deprecated
140 // 0x0057 is deprecated
141 HvDeletePort = 0x0058,
166 // 0x0071..0x0075 are reserved
176 // 0x007F is reserved
200 // 0x0098 is reserved
203 // 0x009A..0x00AE are reserved
206};
207
210#define HYPERV_CPUID_VENDOR_MICROSOFT_EBX 0x7263694d // "Micr"
211#define HYPERV_CPUID_VENDOR_MICROSOFT_ECX 0x666f736f // "osof"
212#define HYPERV_CPUID_VENDOR_MICROSOFT_EDX 0x76482074 // "t Hv"
213
215// Enums //
217
221#define VMCS_GUEST_DEBUGCTL_HIGH 0x00002803
222#define VIRTUAL_PROCESSOR_ID 0x00000000
223
233
235// Functions //
237
240
243
246
249
252
255
258
261
264
267
269VmxSetupVmcs(_In_ VIRTUAL_MACHINE_STATE * VCpu, _In_ PVOID GuestStack);
270
271VOID
273
274VOID
276
277VOID
279
280VOID
282
283VOID
285
286VOID
288
289VOID
291
292VOID
294
295VOID
296VmxCompatibleMicroSleep(UINT64 ns);
297
298UINT64
300
301UINT64
303
306
309
310UINT32
311VmxCompatibleStrlen(const CHAR * S);
312
313UINT32
314VmxCompatibleWcslen(const WCHAR * S);
315
316INT32
317VmxCompatibleStrcmp(const CHAR * Address1,
318 const CHAR * Address2,
319 SIZE_T Num,
320 BOOLEAN IsStrncmp);
321
322INT32
323VmxCompatibleWcscmp(const WCHAR * Address1,
324 const WCHAR * Address2,
325 SIZE_T Num,
326 BOOLEAN IsWcsncmp);
327
328INT32
329VmxCompatibleMemcmp(const CHAR * Address1,
330 const CHAR * Address2,
331 SIZE_T Count);
ThreeOpFunc1 interlocked_compare_exchange ThreeOpFunc2 event_inject_error_code memcpy memcpy_pa TwoOpFunc1 ed eb eq interlocked_exchange interlocked_exchange_add eb_pa ed_pa eq_pa TwoOpFunc2 spinlock_lock_custom_wait event_inject OneOpFunc1 poi db dd dw dq neg hi low not check_address disassemble_len disassemble_len32 disassemble_len64 interlocked_increment interlocked_decrement reference physical_to_virtual virtual_to_physical poi_pa hi_pa low_pa db_pa dd_pa dw_pa dq_pa lbr_restore_by_filter OneOpFunc2 print formats event_enable event_disable event_clear test_statement spinlock_lock spinlock_unlock event_sc microsleep OneOpFunc3 strlen TwoOpFunc3 strcmp ThreeOpFunc3 memcmp strncmp ThreeOpFunc4 wcsncmp OneOpFunc4 wcslen TwoOpFunc4 wcscmp ZeroOpFunc1 pause flush event_trace_step event_trace_step_in event_trace_step_out event_trace_instrumentation_step event_trace_instrumentation_step_in ZeroOpFunc2 rdtsc rdtscp lbr_save lbr_dump lbr_print lbr_restore lbr_check VarArgFunc1 printf OperatorsTwoOperand or xor and asr asl add sub mul div mod gt lt egt elt equal neq OperatorsOneOperand inc dec reference AssignmentOperator add_assignment sub_assignment mul_assignment div_assignment mod_assignment asl_assignment asr_assignment and_assignment xor_assignment or_assignment SemantiRules jmp jz jnz mov start_of_do_while start_of_do_while_commands end_of_do_while start_of_for for_inc_dec start_of_for_ommands end_of_if ignore_lvalue push pop call ret Registers rax eax ax ah al rcx ecx cx ch cl rdx edx dx dh dl rbx ebx bx bh bl rsp esp sp spl rbp ebp bp bpl rsi esi si sil rdi edi di dil r8 r8d r8w r8h r8l r9 r9d r9w r9h r9l r10 r10d r10w r10h r10l r11 r11d r11w r11h r11l r12 r12d r12w r12h r12l r13 r13d r13w r13h r13l r14 r14d r14w r14h r14l r15 r15d r15w r15h r15l ds es fs gs cs ss rflags eflags flags cf pf af zf sf tf if df of iopl nt rf vm ac vif vip id rip eip ip idtr ldtr gdtr tr cr0 cr2 cr3 cr4 cr8 dr0 dr1 dr2 dr3 dr6 dr7 PseudoRegisters pid tid pname core proc thread peb teb ip buffer context event_tag event_id event_stage date time S STATEMENT S S
Definition Grammar.txt:57
union _HYPERCALL_INPUT_VALUE * PHYPERCALL_INPUT_VALUE
INT32 VmxCompatibleMemcmp(const CHAR *Address1, const CHAR *Address2, SIZE_T Count)
implementation of vmx-root mode compatible memcmp
Definition Vmx.c:1674
UINT64 VmxReturnInstructionPointerForVmxoff()
Get the RIP of guest (VMCS_GUEST_RIP) in the case of return from VMXOFF.
Definition Vmx.c:1093
UINT64 VmxReturnStackPointerForVmxoff()
Get the RIP of guest (VMCS_GUEST_RIP) in the case of return from VMXOFF.
Definition Vmx.c:1082
VOID VmxPerformVmresume()
Resume VM using the VMRESUME instruction.
Definition Vmx.c:906
BOOLEAN VmxGetCurrentExecutionMode()
Check current execution mode (vmx-root and non-root).
Definition Vmx.c:76
VOID VmxHandleTripleFaults(VIRTUAL_MACHINE_STATE *VCpu)
Handling triple fault VM-exits.
Definition CrossVmexits.c:70
BOOLEAN VmxSetupVmcs(_In_ VIRTUAL_MACHINE_STATE *VCpu, _In_ PVOID GuestStack)
VOID VmxPerformTermination()
Terminate Vmx on all logical cores.
Definition Vmx.c:1104
BOOLEAN VmxPerformVirtualizationOnAllCores()
Initialize essential VMX Operation tasks.
Definition Vmx.c:267
VOID VmxPerformVmptrst()
Implementation of VMPTRST instruction.
Definition Vmx.c:610
BOOLEAN VmxGetCurrentLaunchState()
Check if the VMX is launched or not.
Definition Vmx.c:100
VOID VmxFixCr4AndCr0Bits()
Fix values for cr0 and cr4 bits.
Definition Vmx.c:403
enum _MOV_TO_DEBUG_REG MOV_TO_DEBUG_REG
MOV to debug registers states.
_MOV_TO_DEBUG_REG
MOV to debug registers states.
Definition Vmx.h:229
@ AccessFromDebugRegister
Definition Vmx.h:231
@ AccessToDebugRegister
Definition Vmx.h:230
VOID VmxHandleVmxPreemptionTimerVmexit(VIRTUAL_MACHINE_STATE *VCpu)
Handling VMX Preemption Timer vm-exits.
Definition CrossVmexits.c:53
UINT32 VmxCompatibleStrlen(const CHAR *S)
implementation of vmx-root mode compatible strlen
Definition Vmx.c:1192
HYPERCALL_CODE
Hyper-V Hypercalls.
Definition Vmx.h:97
@ HvUnmapStatsPage
Definition Vmx.h:162
@ HvClearVirtualInterrupt
Definition Vmx.h:139
@ HvGetPartitionId
Definition Vmx.h:123
@ HvCallParkedVirtualProcessors
Definition Vmx.h:104
@ HvCallConnectPort
Definition Vmx.h:198
@ HvCallEnableVpVtl
Definition Vmx.h:109
@ HvInstallIntercept
Definition Vmx.h:130
@ HvMapGpaPages
Definition Vmx.h:128
@ HvSwitchVirtualAddressSpace
Definition Vmx.h:98
@ HvCallMapSparseGpaPages
Definition Vmx.h:163
@ HvCallSendSyntheticClusterIpiEx
Definition Vmx.h:115
@ HvInitializePartition
Definition Vmx.h:118
@ HvCallPrepareForHibernate
Definition Vmx.h:183
@ HvCallQueryNumaDistance
Definition Vmx.h:169
@ HvCallVtlReturn
Definition Vmx.h:112
@ HvFinalizeEventLogBufferGroup
Definition Vmx.h:150
@ HvCallEnablePartitionVtl
Definition Vmx.h:107
@ HvCallAddLogicalProcessor
Definition Vmx.h:167
@ HvCallMapDevicePages
Definition Vmx.h:177
@ HvCallCreatePort
Definition Vmx.h:197
@ HvDepositMemory
Definition Vmx.h:125
@ HvCallGetLogicalProcessorRegisters
Definition Vmx.h:185
@ HvCallSetSystemProperty
Definition Vmx.h:164
@ HvCallFlushVirtualAddressListEx
Definition Vmx.h:114
@ HvCallRegisterInterceptResult
Definition Vmx.h:194
@ HvDeleteVp
Definition Vmx.h:132
@ HvSavePartitionState
Definition Vmx.h:147
@ HvReadGpa
Definition Vmx.h:136
@ HvCallModifyVtlProtectionMask
Definition Vmx.h:106
@ HvCallNotifyStandbyTransition
Definition Vmx.h:181
@ HvCallGetSpaPageList
Definition Vmx.h:199
@ HvGetLogicalProcessorRunTime
Definition Vmx.h:101
@ HvFlushEventLogBuffer
Definition Vmx.h:157
@ HvCallModifySparseGpaPages
Definition Vmx.h:193
@ HvDeletePort
Definition Vmx.h:141
@ HvCallDisablePartitionVtl
Definition Vmx.h:108
@ HvCallUnmapDevicePages
Definition Vmx.h:178
@ HvCallRemoveLogicalProcessor
Definition Vmx.h:168
@ HvCallRetargetDeviceInterrupt
Definition Vmx.h:175
@ HvCallSetPortProperty
Definition Vmx.h:165
@ HvSetEventLogGroupSources
Definition Vmx.h:155
@ HvCreatePartition
Definition Vmx.h:117
@ HvDeleteEventLogBuffer
Definition Vmx.h:152
@ HvGetPartitionProperty
Definition Vmx.h:121
@ HvCallVtlCall
Definition Vmx.h:111
@ HvCallPrepareForSleep
Definition Vmx.h:182
@ HvWithdrawMemory
Definition Vmx.h:126
@ HvFinalizePartition
Definition Vmx.h:119
@ HvCallNotifyPartitionEvent
Definition Vmx.h:184
@ HvSetVpRegisters
Definition Vmx.h:134
@ HvMapStatsPage
Definition Vmx.h:161
@ HvSetPartitionProperty
Definition Vmx.h:122
@ HvCallCollectLivedump
Definition Vmx.h:191
@ HvCallGetLogicalProcessorProperty
Definition Vmx.h:171
@ HvPostMessage
Definition Vmx.h:145
@ HvFlushVirtualAddressList
Definition Vmx.h:100
@ HvCallGetVpIndexFromApicId
Definition Vmx.h:202
@ HvCallSyntheticClusterIpi
Definition Vmx.h:105
@ HvCallScrubPartition
Definition Vmx.h:190
@ HvCallSetLogicalProcessorProperty
Definition Vmx.h:170
@ HvSignalEvent
Definition Vmx.h:146
@ HvUnmapEventLogBuffer
Definition Vmx.h:154
@ HvCallDisableVpVtl
Definition Vmx.h:110
@ HvInitializeEventLogBufferGroup
Definition Vmx.h:149
@ HvCreateVp
Definition Vmx.h:131
@ HvCallUnmapDeviceInterrupt
Definition Vmx.h:174
@ HvCallStartVirtualProcessor
Definition Vmx.h:201
@ HvGetNextChildPartition
Definition Vmx.h:124
@ HvCallMapDeviceInterrupt
Definition Vmx.h:173
@ HvResetDebugSession
Definition Vmx.h:160
@ HvCallDetachDevice
Definition Vmx.h:180
@ HvRetrieveDebugData
Definition Vmx.h:159
@ HvDeletePartition
Definition Vmx.h:120
@ HvCallUnregisterInterceptResult
Definition Vmx.h:195
@ HvCallNotifyRingEmpty
Definition Vmx.h:188
@ HvGetVpRegisters
Definition Vmx.h:133
@ HvFlushVirtualAddressSpace
Definition Vmx.h:99
@ HvDisconnectPort
Definition Vmx.h:144
@ HvCallAttachDevice
Definition Vmx.h:179
@ HvCallDisableHypervisor
Definition Vmx.h:192
@ HvPostDebugData
Definition Vmx.h:158
@ HvCallQueryAssotiatedLpsforMca
Definition Vmx.h:187
@ HvGetMemoryBalance
Definition Vmx.h:127
@ HvTranslateVirtualAddress
Definition Vmx.h:135
@ HvCallGetSystemProperty
Definition Vmx.h:172
@ HvUnmapGpaPages
Definition Vmx.h:129
@ HvCreateEventLogBuffer
Definition Vmx.h:151
@ HvConnectPort
Definition Vmx.h:142
@ HvCallAssertVirtualInterrupt
Definition Vmx.h:196
@ HvCallFlushVirtualAddressSpaceEx
Definition Vmx.h:113
@ HvCallSetLogicalProcessorRegisters
Definition Vmx.h:186
@ HvGetPortProperty
Definition Vmx.h:143
@ HvWriteGpa
Definition Vmx.h:137
@ HvCallNotifyLongSpinWait
Definition Vmx.h:103
@ HvReleaseEventLogBuffer
Definition Vmx.h:156
@ HvCallFlushGuestPhysicalAddressList
Definition Vmx.h:205
@ HvCallFlushGuestPhysicalAddressSpace
Definition Vmx.h:204
@ HvRestorePartitionState
Definition Vmx.h:148
@ HvCallInjectSyntheticMachineCheck
Definition Vmx.h:189
@ HvMapEventLogBuffer
Definition Vmx.h:153
BOOLEAN VmxIsTopLevelHypervisorHyperV()
checks if the current top level hypervisor is Hyper-V
Definition Vmx.c:1785
BOOLEAN VmxLoadVmcs(_In_ VIRTUAL_MACHINE_STATE *VCpu)
BOOLEAN VmxClearVmcsState(_In_ VIRTUAL_MACHINE_STATE *VCpu)
INT32 VmxCompatibleStrcmp(const CHAR *Address1, const CHAR *Address2, SIZE_T Num, BOOLEAN IsStrncmp)
implementation of vmx-root mode compatible strcmp and strncmp
Definition Vmx.c:1398
BOOLEAN VmxCheckVmxSupport()
Check whether VMX Feature is supported or not.
Definition Vmx.c:20
INT32 VmxCompatibleWcscmp(const WCHAR *Address1, const WCHAR *Address2, SIZE_T Num, BOOLEAN IsWcsncmp)
implementation of vmx-root mode compatible wcscmp and wcsncmp
Definition Vmx.c:1536
VOID VmxCompatibleMicroSleep(UINT64 ns)
VMX-root compatible micro sleep.
Definition Vmx.c:1371
VOID VmxHandleXsetbv(VIRTUAL_MACHINE_STATE *VCpu)
Handling XSETBV Instruction vm-exits.
Definition CrossVmexits.c:21
BOOLEAN VmxPerformVirtualizationOnSpecificCore()
Allocates Vmx regions for all logical cores (Vmxon region and Vmcs region).
Definition Vmx.c:362
UINT32 VmxCompatibleWcslen(const WCHAR *S)
implementation of vmx-root mode compatible wcslen
Definition Vmx.c:1281
BOOLEAN VmxCheckIsOnVmxRoot()
It can deterministically check whether the caller is on vmx-root mode or not.
Definition Vmx.c:438
BOOLEAN VmxTerminate()
Broadcast to terminate VMX on all logical cores.
Definition Vmx.c:561
BOOLEAN VmxInitialize()
Initialize the VMX operation.
Definition Vmx.c:114
union _HYPERCALL_INPUT_VALUE HYPERCALL_INPUT_VALUE
Hypercalls for Hyper-V.
VOID VmxPerformVmxoff(VIRTUAL_MACHINE_STATE *VCpu)
Prepare and execute Vmxoff instruction.
Definition Vmx.c:991
BOOLEAN VmxVirtualizeCurrentSystem(PVOID GuestStack)
Initialize VMX Operation.
Definition Vmx.c:467
signed int INT32
Definition BasicTypes.h:50
UCHAR BOOLEAN
Definition BasicTypes.h:35
void * PVOID
Definition BasicTypes.h:56
unsigned int UINT32
Definition BasicTypes.h:54
char CHAR
Definition BasicTypes.h:33
@ Num
Definition commands.h:167
struct _VIRTUAL_MACHINE_STATE VIRTUAL_MACHINE_STATE
The status of each core after and before VMX.
Hypercalls for Hyper-V.
Definition Vmx.h:75
UINT64 RepStartIndex
Definition Vmx.h:86
UINT64 CallCode
Definition Vmx.h:79
UINT64 RepCount
Definition Vmx.h:84
UINT64 Fast
Definition Vmx.h:80
UINT64 VariableHeaderSize
Definition Vmx.h:81
UINT64 IsNested
Definition Vmx.h:82
UINT64 Flags
Definition Vmx.h:76
UINT64 Reserved0
Definition Vmx.h:83
UINT64 Reserved2
Definition Vmx.h:87
UINT64 Reserved1
Definition Vmx.h:85
struct _HYPERCALL_INPUT_VALUE::@010010145126055261317211351336342156317071247225 Fields