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

Routines relating to Monitor Trap Flag (MTF) More...

#include "pch.h"

Functions

VOID MtfHandleVmexit (VIRTUAL_MACHINE_STATE *VCpu)
 Handle Monitor Trap Flag vm-exits.
 

Detailed Description

Routines relating to Monitor Trap Flag (MTF)

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2021-01-27

Function Documentation

◆ MtfHandleVmexit()

VOID MtfHandleVmexit ( VIRTUAL_MACHINE_STATE * VCpu)

Handle Monitor Trap Flag vm-exits.

Parameters
VCpuThe virtual processor's state
Returns
VOID
22{
23 BOOLEAN IsMtfHandled = FALSE;
24
25 //
26 // Redo the instruction
27 //
29
30 //
31 // Explicitly say that we want to unset MTFs
32 //
33 VCpu->IgnoreMtfUnset = FALSE;
34
35 //
36 // Check if we need to re-apply a breakpoint or not
37 // We check it separately because the guest might step
38 // instructions on an MTF so we want to check for the step too
39 //
42 {
43 //
44 // MTF is handled
45 //
46 IsMtfHandled = TRUE;
47 }
48
49 //
50 // *** Regular Monitor Trap Flag functionalities ***
51 //
52 if (VCpu->MtfEptHookRestorePoint)
53 {
54 //
55 // MTF is handled
56 //
57 IsMtfHandled = TRUE;
58
59 //
60 // Restore the previous state
61 //
63
64 //
65 // Set it to NULL
66 //
68
69 //
70 // Check for reenabling external interrupts
71 //
73 }
74
75 //
76 // Check for instrumentation step-in
77 //
78 if (VCpu->RegisterBreakOnMtf)
79 {
80 //
81 // MTF is handled
82 //
83 IsMtfHandled = TRUE;
84
85 //
86 // Change the MTF registration state (might be changed in the caller)
87 //
89
90 //
91 // Handle MTF in the debugger
92 //
94 }
95
96 //
97 // check the condition of passing the execution to NMIs
98 //
99 // This one wastes one week of my life!
100 // During the testing we realized the !epthook command in Debugger Mode
101 // is not working. After some tests, it's because if in the middle of a
102 // command in vmx-root and NMI is sent and the debugger waits for another
103 // MTF, we'll ignore that MTF and a new MTF is not set again.
104 // That's why we moved this check here so every command that needs a task
105 // from MTF is doing its tasks and when we reached here, the check for halting
106 // the debuggee in MTF is performed
107 //
108 else if (g_Callbacks.KdCheckAndHandleNmiCallback != NULL &&
110 {
111 //
112 // MTF is handled
113 //
114 IsMtfHandled = TRUE;
115 }
116
117 //
118 // Check for ignored MTFs
119 //
120 if (VCpu->IgnoreOneMtf)
121 {
122 //
123 // MTF is handled
124 //
125 IsMtfHandled = TRUE;
126
127 VCpu->IgnoreOneMtf = FALSE;
128 }
129
130 //
131 // Check for possible unhandled MTFs to avoid setting unusable MTFs
132 //
133 if (!IsMtfHandled)
134 {
135 LogError("Err, why MTF occurred?!");
136 }
137
138 //
139 // Final check to unset MTF
140 //
141 if (!VCpu->IgnoreMtfUnset)
142 {
143 //
144 // We don't need MTF anymore if it set to disable MTF
145 //
147 }
148 else
149 {
150 //
151 // Set it to false to avoid future errors
152 //
153 VCpu->IgnoreMtfUnset = FALSE;
154 }
155}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
VOID VmmCallbackRegisteredMtfHandler(UINT32 CoreId)
routine callback to handle registered MTF
Definition Callback.c:225
VOID EptHookHandleMonitorTrapFlag(VIRTUAL_MACHINE_STATE *VCpu)
Handle vm-exits for Monitor Trap Flag to restore previous state.
Definition EptHook.c:1963
VMM_CALLBACKS g_Callbacks
List of callbacks.
Definition GlobalVariables.h:32
VOID HvSuppressRipIncrement(VIRTUAL_MACHINE_STATE *VCpu)
Suppress the incrementation of RIP.
Definition Hv.c:324
VOID HvEnableAndCheckForPreviousExternalInterrupts(VIRTUAL_MACHINE_STATE *VCpu)
Checks to enable and reinject previous interrupts.
Definition Hv.c:1072
VOID HvSetMonitorTrapFlag(BOOLEAN Set)
Set the monitor trap flag.
Definition Hv.c:349
#define LogError(format,...)
Log in the case of error.
Definition HyperDbgHyperLogIntrinsics.h:113
NULL()
Definition test-case-generator.py:530
BOOLEAN IgnoreMtfUnset
Definition State.h:294
BOOLEAN IgnoreOneMtf
Definition State.h:299
PEPT_HOOKED_PAGE_DETAIL MtfEptHookRestorePoint
Definition State.h:331
BOOLEAN RegisterBreakOnMtf
Definition State.h:298
UINT32 CoreId
Definition State.h:306
BREAKPOINT_CHECK_AND_HANDLE_REAPPLYING_BREAKPOINT BreakpointCheckAndHandleReApplyingBreakpoint
Definition VMM.h:216
KD_CHECK_AND_HANDLE_NMI_CALLBACK KdCheckAndHandleNmiCallback
Definition VMM.h:218