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

File for protected hypervisor resources. More...

#include "pch.h"

Functions

VOID ProtectedHvChangeExceptionBitmapWithIntegrityCheck (VIRTUAL_MACHINE_STATE *VCpu, UINT32 CurrentMask, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Add extra mask to this resource and write it.
 
VOID ProtectedHvSetExceptionBitmap (VIRTUAL_MACHINE_STATE *VCpu, UINT32 IdtIndex)
 Set exception bitmap in VMCS.
 
VOID ProtectedHvUnsetExceptionBitmap (VIRTUAL_MACHINE_STATE *VCpu, UINT32 IdtIndex)
 Unset exception bitmap in VMCS.
 
VOID ProtectedHvResetExceptionBitmapToClearEvents (VIRTUAL_MACHINE_STATE *VCpu)
 Reset exception bitmap in VMCS because of clearing !exception commands.
 
VOID ProtectedHvRemoveUndefinedInstructionForDisablingSyscallSysretCommands (VIRTUAL_MACHINE_STATE *VCpu)
 Reset exception bitmap in VMCS because of clearing !exception commands.
 
VOID ProtectedHvApplySetExternalInterruptExiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Set the External Interrupt Exiting.
 
VOID ProtectedHvSetExternalInterruptExiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set the External Interrupt Exiting.
 
VOID ProtectedHvExternalInterruptExitingForDisablingInterruptCommands (VIRTUAL_MACHINE_STATE *VCpu)
 Clear events of !interrupt.
 
VOID ProtectedHvSetTscVmexit (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Set vm-exit for tsc instructions (rdtsc/rdtscp)
 
VOID ProtectedHvSetMovDebugRegsVmexit (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Set vm-exit for mov to debug registers.
 
VOID ProtectedHvSetMovToCrVmexit (BOOLEAN Set, UINT64 ControlRegister, UINT64 MaskRegister)
 Set vm-exit for mov to cr0 / cr4 register.
 
VOID ProtectedHvSetMovControlRegsVmexit (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver, UINT64 ControlRegister, UINT64 MaskRegister)
 Set vm-exit for mov to control registers.
 
VOID ProtectedHvSetMovToCr3Vmexit (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
 Set vm-exit for mov to cr3 register.
 
VOID ProtectedHvSetRdtscExiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set the RDTSC/P Exiting.
 
VOID ProtectedHvDisableRdtscExitingForDisablingTscCommands (VIRTUAL_MACHINE_STATE *VCpu)
 Clear events of !tsc.
 
VOID ProtectedHvSetMovDebugRegsExiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set MOV to HW Debug Regs Exiting.
 
VOID ProtectedHvDisableMovDebugRegsExitingForDisablingDrCommands (VIRTUAL_MACHINE_STATE *VCpu)
 Clear events of !dr.
 
VOID ProtectedHvDisableMovControlRegsExitingForDisablingCrCommands (VIRTUAL_MACHINE_STATE *VCpu, UINT64 ControlRegister, UINT64 MaskRegister)
 Clear events of !crwrite.
 
VOID ProtectedHvSetMov2Cr3Exiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set MOV to CR3 Exiting.
 
VOID ProtectedHvSetMov2CrExiting (BOOLEAN Set, UINT64 ControlRegister, UINT64 MaskRegister)
 Set MOV to CR0/4 Exiting.
 

Detailed Description

File for protected hypervisor resources.

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

Protected Hypervisor Routines are those resource that are used in different parts of the debugger or hypervisor, these resources need extra checks to avoid integrity problems

Version
0.1
Date
2021-10-04

Function Documentation

◆ ProtectedHvApplySetExternalInterruptExiting()

VOID ProtectedHvApplySetExternalInterruptExiting ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Set the External Interrupt Exiting.

Parameters
VCpuThe virtual processor's state
SetSet or unset the External Interrupt Exiting
PassOverAdds some pass over to the checks thus we won't check for interrupts
Returns
VOID
192{
193 UINT32 PinBasedControls = 0;
194 UINT32 VmExitControls = 0;
195
196 //
197 // The protected checks are only performed if the "Set" is "FALSE",
198 // because if sb wants to set it to "TRUE" then we're no need to
199 // worry about it as it remains enabled
200 //
201 if (Set == FALSE)
202 {
203 //
204 // Ask the top-level driver whether to terminate this operation or not
205 //
208 NULL,
209 PassOver))
210 {
211 return;
212 }
213 }
214
215 //
216 // In order to enable External Interrupt Exiting we have to set
217 // PIN_BASED_VM_EXECUTION_CONTROLS_EXTERNAL_INTERRUPT in vmx
218 // pin-based controls (PIN_BASED_VM_EXEC_CONTROL) and also
219 // we should enable VM_EXIT_ACK_INTR_ON_EXIT on vmx vm-exit
220 // controls (VMCS_CTRL_VMEXIT_CONTROLS), also this function might not
221 // always be successful if the guest is not in the interruptible
222 // state so it wait for and interrupt-window exiting to re-inject
223 // the interrupt into the guest
224 //
225
226 //
227 // Read the previous flags
228 //
229 VmxVmread32P(VMCS_CTRL_PIN_BASED_VM_EXECUTION_CONTROLS, &PinBasedControls);
230 VmxVmread32P(VMCS_CTRL_PRIMARY_VMEXIT_CONTROLS, &VmExitControls);
231
232 if (Set)
233 {
235 VmExitControls |= VM_EXIT_ACK_INTR_ON_EXIT;
236 }
237 else
238 {
239 PinBasedControls &= ~PIN_BASED_VM_EXECUTION_CONTROLS_EXTERNAL_INTERRUPT;
240 VmExitControls &= ~VM_EXIT_ACK_INTR_ON_EXIT;
241 }
242
243 //
244 // Set the new value
245 //
246 VmxVmwrite64(VMCS_CTRL_PIN_BASED_VM_EXECUTION_CONTROLS, PinBasedControls);
247 VmxVmwrite64(VMCS_CTRL_PRIMARY_VMEXIT_CONTROLS, VmExitControls);
248}
#define FALSE
Definition BasicTypes.h:54
unsigned int UINT32
Definition BasicTypes.h:48
BOOLEAN VmmCallbackQueryTerminateProtectedResource(UINT32 CoreId, PROTECTED_HV_RESOURCES_TYPE ResourceType, PVOID Context, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
routine callback to query for termination of protected resources
Definition Callback.c:271
UCHAR VmxVmwrite64(size_t Field, UINT64 FieldValue)
VMX VMWRITE instruction (64-bit)
Definition Vmx.c:122
UCHAR VmxVmread32P(size_t Field, UINT32 *FieldValue)
VMX VMREAD instruction (32-bit)
Definition Vmx.c:86
#define PIN_BASED_VM_EXECUTION_CONTROLS_EXTERNAL_INTERRUPT
PIN-Based Execution.
Definition Vmx.h:34
#define VM_EXIT_ACK_INTR_ON_EXIT
Definition Vmx.h:86
@ PROTECTED_HV_RESOURCES_EXTERNAL_INTERRUPT_EXITING
Definition Events.h:328
UINT32 CoreId
Definition State.h:306

◆ ProtectedHvChangeExceptionBitmapWithIntegrityCheck()

VOID ProtectedHvChangeExceptionBitmapWithIntegrityCheck ( VIRTUAL_MACHINE_STATE * VCpu,
UINT32 CurrentMask,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Add extra mask to this resource and write it.

As exception bitmap is a protected resource, this routine makes sure that modifying exception bitmap won't break the debugger's integrity

Parameters
VCpuThe virtual processor's state
CurrentMaskThe mask that debugger wants to write
PassOverAdds some pass over to the checks thus we won't check for exceptions
Returns
VOID
32{
33 //
34 // Ask the top-level module to reshape the mask
35 //
38 &CurrentMask,
39 PassOver))
40 {
41 return;
42 }
43
44 //
45 // Check for #PF by thread interception mechanism in user debugger
46 //
48 {
49 CurrentMask |= 1 << EXCEPTION_VECTOR_PAGE_FAULT;
50 }
51
52 //
53 // Check for possible EPT Hooks (Hidden Breakpoints)
54 //
56 {
57 CurrentMask |= 1 << EXCEPTION_VECTOR_BREAKPOINT;
58 }
59
60 //
61 // Write the final value
62 //
63 HvWriteExceptionBitmap(CurrentMask);
64}
UINT32 EptHookGetCountOfEpthooks(BOOLEAN IsEptHook2)
get the length of active EPT hooks (!epthook and !epthook2)
Definition EptHook.c:1865
BOOLEAN g_CheckPageFaultsAndMov2Cr3VmexitsWithUserDebugger
Whether the page-fault and cr3 vm-exits in vmx-root should check the #PFs or the PML4....
Definition GlobalVariables.h:114
VOID HvWriteExceptionBitmap(UINT32 BitmapMask)
Write on exception bitmap in VMCS DO NOT CALL IT DIRECTLY, instead use HvSetExceptionBitmap.
Definition Hv.c:572
@ PROTECTED_HV_RESOURCES_EXCEPTION_BITMAP
Definition Events.h:326
@ EXCEPTION_VECTOR_PAGE_FAULT
Definition Events.h:38
@ EXCEPTION_VECTOR_BREAKPOINT
Definition Events.h:27

◆ ProtectedHvDisableMovControlRegsExitingForDisablingCrCommands()

VOID ProtectedHvDisableMovControlRegsExitingForDisablingCrCommands ( VIRTUAL_MACHINE_STATE * VCpu,
UINT64 ControlRegister,
UINT64 MaskRegister )

Clear events of !crwrite.

Parameters
VCpuThe virtual processor's state
ControlRegister
MaskRegister
Returns
VOID
610{
612}
VOID ProtectedHvSetMovControlRegsVmexit(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver, UINT64 ControlRegister, UINT64 MaskRegister)
Set vm-exit for mov to control registers.
Definition ProtectedHv.c:448
@ PASSING_OVER_MOV_TO_CONTROL_REGS_EVENTS
Definition Events.h:316

◆ ProtectedHvDisableMovDebugRegsExitingForDisablingDrCommands()

VOID ProtectedHvDisableMovDebugRegsExitingForDisablingDrCommands ( VIRTUAL_MACHINE_STATE * VCpu)

Clear events of !dr.

Parameters
VCpuThe virtual processor's state
Returns
VOID
596{
598}
VOID ProtectedHvSetMovDebugRegsVmexit(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Set vm-exit for mov to debug registers.
Definition ProtectedHv.c:351
@ PASSING_OVER_MOV_TO_HW_DEBUG_REGS_EVENTS
Definition Events.h:311

◆ ProtectedHvDisableRdtscExitingForDisablingTscCommands()

VOID ProtectedHvDisableRdtscExitingForDisablingTscCommands ( VIRTUAL_MACHINE_STATE * VCpu)

Clear events of !tsc.

Parameters
VCpuThe virtual processor's state
Returns
VOID
571{
573}
VOID ProtectedHvSetTscVmexit(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Set vm-exit for tsc instructions (rdtsc/rdtscp)
Definition ProtectedHv.c:286
@ PASSING_OVER_TSC_EVENTS
Definition Events.h:306

◆ ProtectedHvExternalInterruptExitingForDisablingInterruptCommands()

VOID ProtectedHvExternalInterruptExitingForDisablingInterruptCommands ( VIRTUAL_MACHINE_STATE * VCpu)

Clear events of !interrupt.

Returns
VOID
270{
272}
VOID ProtectedHvApplySetExternalInterruptExiting(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Set the External Interrupt Exiting.
Definition ProtectedHv.c:191
@ PASSING_OVER_INTERRUPT_EVENTS
Definition Events.h:301

◆ ProtectedHvRemoveUndefinedInstructionForDisablingSyscallSysretCommands()

VOID ProtectedHvRemoveUndefinedInstructionForDisablingSyscallSysretCommands ( VIRTUAL_MACHINE_STATE * VCpu)

Reset exception bitmap in VMCS because of clearing !exception commands.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
Returns
VOID
161{
162 UINT32 ExceptionBitmap = 0;
163
164 //
165 // Read the current bitmap
166 //
167 ExceptionBitmap = HvReadExceptionBitmap();
168
169 //
170 // Unset exception bitmap for #UD
171 //
172 ExceptionBitmap &= ~(1 << EXCEPTION_VECTOR_UNDEFINED_OPCODE);
173
174 //
175 // Set the new value
176 //
178}
UINT32 HvReadExceptionBitmap()
Read exception bitmap in VMCS.
Definition Hv.c:587
VOID ProtectedHvChangeExceptionBitmapWithIntegrityCheck(VIRTUAL_MACHINE_STATE *VCpu, UINT32 CurrentMask, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Add extra mask to this resource and write it.
Definition ProtectedHv.c:31
@ PASSING_OVER_UD_EXCEPTIONS_FOR_SYSCALL_SYSRET_HOOK
Definition Events.h:295
@ EXCEPTION_VECTOR_UNDEFINED_OPCODE
Definition Events.h:30

◆ ProtectedHvResetExceptionBitmapToClearEvents()

VOID ProtectedHvResetExceptionBitmapToClearEvents ( VIRTUAL_MACHINE_STATE * VCpu)

Reset exception bitmap in VMCS because of clearing !exception commands.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
Returns
VOID
142{
143 UINT32 ExceptionBitmap = 0;
144
145 //
146 // Set the new value
147 //
149}
@ PASSING_OVER_EXCEPTION_EVENTS
Definition Events.h:296

◆ ProtectedHvSetExceptionBitmap()

VOID ProtectedHvSetExceptionBitmap ( 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
76{
77 UINT32 ExceptionBitmap = 0;
78
79 //
80 // Read the current bitmap
81 //
82 ExceptionBitmap = HvReadExceptionBitmap();
83
85 {
86 ExceptionBitmap = 0xffffffff;
87 }
88 else
89 {
90 ExceptionBitmap |= 1 << IdtIndex;
91 }
92
93 //
94 // Set the new value
95 //
97}
#define DEBUGGER_EVENT_EXCEPTIONS_ALL_FIRST_32_ENTRIES
Apply to all first 32 exceptions.
Definition Constants.h:629
@ PASSING_OVER_NONE
Definition Events.h:294

◆ ProtectedHvSetExternalInterruptExiting()

VOID ProtectedHvSetExternalInterruptExiting ( 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

◆ ProtectedHvSetMov2Cr3Exiting()

VOID ProtectedHvSetMov2Cr3Exiting ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set MOV to CR3 Exiting.

Parameters
VCpuThe virtual processor's state
SetSet or unset the MOV to CR3 Exiting
Returns
VOID
623{
625}
VOID ProtectedHvSetMovToCr3Vmexit(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Set vm-exit for mov to cr3 register.
Definition ProtectedHv.c:484

◆ ProtectedHvSetMov2CrExiting()

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

Set MOV to CR0/4 Exiting.

Parameters
Setor unset the MOV to CR0/4 Exiting
ControlRegister
MaskRegister
Returns
VOID
637{
638 ProtectedHvSetMovToCrVmexit(Set, ControlRegister, MaskRegister);
639}
VOID ProtectedHvSetMovToCrVmexit(BOOLEAN Set, UINT64 ControlRegister, UINT64 MaskRegister)
Set vm-exit for mov to cr0 / cr4 register.
Definition ProtectedHv.c:405

◆ ProtectedHvSetMovControlRegsVmexit()

VOID ProtectedHvSetMovControlRegsVmexit ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver,
UINT64 ControlRegister,
UINT64 MaskRegister )

Set vm-exit for mov to control registers.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
Setor unset the vm-exits
PassOverAdds some pass over to the checks
ControlRegister
MaskRegister
Returns
VOID
449{
450 //
451 // The protected checks are only performed if the "Set" is "FALSE",
452 // because if sb wants to set it to "TRUE" then we're no need to
453 // worry about it as it remains enabled
454 //
455 if (Set == FALSE)
456 {
457 //
458 // Check the state of top-level driver
459 //
462 NULL,
463 PassOver))
464 {
465 return;
466 }
467 }
468
469 ProtectedHvSetMovToCrVmexit(Set, ControlRegister, MaskRegister);
470}
@ PROTECTED_HV_RESOURCES_MOV_CONTROL_REGISTER_EXITING
Definition Events.h:334

◆ ProtectedHvSetMovDebugRegsExiting()

VOID ProtectedHvSetMovDebugRegsExiting ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set MOV to HW Debug Regs Exiting.

Parameters
VCpuThe virtual processor's state
SetSet or unset the MOV to HW Debug Regs Exiting
Returns
VOID

◆ ProtectedHvSetMovDebugRegsVmexit()

VOID ProtectedHvSetMovDebugRegsVmexit ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Set vm-exit for mov to debug registers.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
SetSet or unset the vm-exits
PassOverAdds some pass over to the checks thus we won't check for dr
Returns
VOID
352{
353 UINT32 CpuBasedVmExecControls = 0;
354
355 //
356 // The protected checks are only performed if the "Set" is "FALSE",
357 // because if sb wants to set it to "TRUE" then we're no need to
358 // worry about it as it remains enabled
359 //
360 if (Set == FALSE)
361 {
362 //
363 // Check the top-level driver's state
364 //
367 NULL,
368 PassOver))
369 {
370 return;
371 }
372 }
373
374 //
375 // Read the previous flags
376 //
377 VmxVmread32P(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, &CpuBasedVmExecControls);
378
379 if (Set)
380 {
381 CpuBasedVmExecControls |= CPU_BASED_MOV_DR_EXITING;
382 }
383 else
384 {
385 CpuBasedVmExecControls &= ~CPU_BASED_MOV_DR_EXITING;
386 }
387
388 //
389 // Set the new value
390 //
391 VmxVmwrite64(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, CpuBasedVmExecControls);
392}
#define CPU_BASED_MOV_DR_EXITING
Definition Vmx.h:57
@ PROTECTED_HV_RESOURCES_MOV_TO_DEBUG_REGISTER_EXITING
Definition Events.h:332

◆ ProtectedHvSetMovToCr3Vmexit()

VOID ProtectedHvSetMovToCr3Vmexit ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Set vm-exit for mov to cr3 register.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
SetSet or unset the vm-exits
PassOverAdds some pass over to the checks thus we won't check for dr
Returns
VOID
485{
486 UINT32 CpuBasedVmExecControls = 0;
487
488 //
489 // The protected checks are only performed if the "Set" is "FALSE",
490 // because if sb wants to set it to "TRUE" then we're no need to
491 // worry about it as it remains enabled
492 //
493 if (Set == FALSE)
494 {
495 //
496 // Check the top-level driver's state
497 //
500 NULL,
501 PassOver))
502 {
503 return;
504 }
505
506 //
507 // Check if use debugger is in intercepting phase for threads or not
508 //
510 {
511 //
512 // The user debugger needs mov2cr3s
513 //
514 return;
515 }
516
517 //
518 // Check if the trap execution is enabled or not, and whether the
519 // uninitialization phase started or not
520 //
522 {
523 //
524 // The VMM needs mov2cr3s
525 //
526 return;
527 }
528 }
529
530 //
531 // Read the previous flags
532 //
533 VmxVmread32P(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, &CpuBasedVmExecControls);
534
535 if (Set)
536 {
537 CpuBasedVmExecControls |= CPU_BASED_CR3_LOAD_EXITING;
538 }
539 else
540 {
541 CpuBasedVmExecControls &= ~CPU_BASED_CR3_LOAD_EXITING;
542 }
543
544 //
545 // Set the new value
546 //
547 VmxVmwrite64(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, CpuBasedVmExecControls);
548}
BOOLEAN g_ExecTrapUnInitializationStarted
Showes whether the uninitialization of the exec trap is started or not.
Definition GlobalVariables.h:156
BOOLEAN g_ExecTrapInitialized
Showes whether the execution trap handler is allowed to trigger an event or not.
Definition GlobalVariables.h:149
#define CPU_BASED_CR3_LOAD_EXITING
Definition Vmx.h:51
@ PROTECTED_HV_RESOURCES_MOV_TO_CR3_EXITING
Definition Events.h:336

◆ ProtectedHvSetMovToCrVmexit()

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

Set vm-exit for mov to cr0 / cr4 register.

Should be called in vmx-root

Parameters
Setor unset the vm-exits
ControlRegister
MaskRegister
Returns
VOID
406{
407 if (ControlRegister == VMX_EXIT_QUALIFICATION_REGISTER_CR0)
408 {
409 if (Set)
410 {
411 VmxVmwrite64(VMCS_CTRL_CR0_GUEST_HOST_MASK, MaskRegister);
412 VmxVmwrite64(VMCS_CTRL_CR0_READ_SHADOW, __readcr0());
413 }
414 else
415 {
416 VmxVmwrite64(VMCS_CTRL_CR0_GUEST_HOST_MASK, 0);
417 VmxVmwrite64(VMCS_CTRL_CR0_READ_SHADOW, 0);
418 }
419 }
420 else if (ControlRegister == VMX_EXIT_QUALIFICATION_REGISTER_CR4)
421 {
422 if (Set)
423 {
424 VmxVmwrite64(VMCS_CTRL_CR4_GUEST_HOST_MASK, MaskRegister);
425 VmxVmwrite64(VMCS_CTRL_CR4_READ_SHADOW, __readcr0());
426 }
427 else
428 {
429 VmxVmwrite64(VMCS_CTRL_CR4_GUEST_HOST_MASK, 0);
430 VmxVmwrite64(VMCS_CTRL_CR4_READ_SHADOW, 0);
431 }
432 }
433}

◆ ProtectedHvSetRdtscExiting()

VOID ProtectedHvSetRdtscExiting ( 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
559{
561}

◆ ProtectedHvSetTscVmexit()

VOID ProtectedHvSetTscVmexit ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set,
PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver )

Set vm-exit for tsc instructions (rdtsc/rdtscp)

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
SetSet or unset the vm-exits
PassOverAdds some pass over to the checks thus we won't check for tsc
Returns
VOID
287{
288 UINT32 CpuBasedVmExecControls = 0;
289
290 //
291 // The protected checks are only performed if the "Set" is "FALSE",
292 // because if sb wants to set it to "TRUE" then we're no need to
293 // worry about it as it remains enabled
294 //
295 if (Set == FALSE)
296 {
297 //
298 // Check the top-level driver's state
299 //
302 NULL,
303 PassOver))
304 {
305 return;
306 }
307
308 //
309 // Check if transparent mode is enabled
310 //
312 {
313 //
314 // We should ignore it as we want this bit on transparent mode
315 //
316 return;
317 }
318 }
319
320 //
321 // Read the previous flags
322 //
323 VmxVmread32P(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, &CpuBasedVmExecControls);
324
325 if (Set)
326 {
327 CpuBasedVmExecControls |= CPU_BASED_RDTSC_EXITING;
328 }
329 else
330 {
331 CpuBasedVmExecControls &= ~CPU_BASED_RDTSC_EXITING;
332 }
333 //
334 // Set the new value
335 //
336 VmxVmwrite64(VMCS_CTRL_PROCESSOR_BASED_VM_EXECUTION_CONTROLS, CpuBasedVmExecControls);
337}
BOOLEAN g_TransparentMode
Shows whether the debugger transparent mode is enabled (true) or not (false)
Definition GlobalVariables.h:75
#define CPU_BASED_RDTSC_EXITING
Definition Vmx.h:50
@ PROTECTED_HV_RESOURCES_RDTSC_RDTSCP_EXITING
Definition Events.h:330

◆ ProtectedHvUnsetExceptionBitmap()

VOID ProtectedHvUnsetExceptionBitmap ( 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
109{
110 UINT32 ExceptionBitmap = 0;
111
112 //
113 // Read the current bitmap
114 //
115 ExceptionBitmap = HvReadExceptionBitmap();
116
118 {
119 ExceptionBitmap = 0x0;
120 }
121 else
122 {
123 ExceptionBitmap &= ~(1 << IdtIndex);
124 }
125
126 //
127 // Set the new value
128 //
130}