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

Checks for processor compatibility with different features. More...

#include "pch.h"

Functions

BOOLEAN CompatibilityCheckCpuSupportForRtm ()
 Check whether the processor supports RTM or not.
 
UINT32 CompatibilityCheckGetX86VirtualAddressWidth ()
 Get virtual address width for x86 processors.
 
UINT32 CompatibilityCheckGetX86PhysicalAddressWidth ()
 Get physical address width for x86 processors.
 
BOOLEAN CompatibilityCheckModeBasedExecution ()
 Check for mode-based execution.
 
BOOLEAN CompatibilityCheckPml ()
 Check for Page Modification Logging (PML) support.
 
VOID CompatibilityCheckPerformChecks ()
 Checks for the compatibility features based on current processor @detail NOTE: NOT ALL OF THE CHECKS ARE PERFORMED HERE.
 

Detailed Description

Checks for processor compatibility with different features.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.2
Date
2023-03-15

Function Documentation

◆ CompatibilityCheckCpuSupportForRtm()

BOOLEAN CompatibilityCheckCpuSupportForRtm ( )

Check whether the processor supports RTM or not.

Returns
BOOLEAN
22{
23 int Regs1[4];
24 int Regs2[4];
25 BOOLEAN Result;
26
27 //
28 // TSX is controlled via MSR_IA32_TSX_CTRL. However, support for this
29 // MSR is enumerated by ARCH_CAP_TSX_MSR bit in MSR_IA32_ARCH_CAPABILITIES.
30 //
31 // TSX control (aka MSR_IA32_TSX_CTRL) is only available after a
32 // microcode update on CPUs that have their MSR_IA32_ARCH_CAPABILITIES
33 // bit MDS_NO=1. CPUs with MDS_NO=0 are not planned to get
34 // MSR_IA32_TSX_CTRL support even after a microcode update. Thus,
35 // tsx= cmdline requests will do nothing on CPUs without
36 // MSR_IA32_TSX_CTRL support.
37 //
38
39 CommonCpuidInstruction(0, 0, Regs1);
40 CommonCpuidInstruction(7, 0, Regs2);
41
42 //
43 // Check RTM and MPX extensions in order to filter out TSX on Haswell CPUs
44 //
45 Result = Regs1[0] >= 0x7 && (Regs2[1] & 0x4800) == 0x4800;
46
47 return Result;
48}
UCHAR BOOLEAN
Definition BasicTypes.h:39
VOID CommonCpuidInstruction(UINT32 Func, UINT32 SubFunc, int *CpuInfo)
Get cpuid results.
Definition Common.c:85

◆ CompatibilityCheckGetX86PhysicalAddressWidth()

UINT32 CompatibilityCheckGetX86PhysicalAddressWidth ( )

Get physical address width for x86 processors.

Returns
UINT32
75{
76 int Regs[4];
77
79
80 //
81 // Extracting bit 7:0 from eax register
82 //
83 return (Regs[0] & 0x0ff);
84}
#define CPUID_ADDR_WIDTH
Cpuid to get virtual address width.
Definition Common.h:151

◆ CompatibilityCheckGetX86VirtualAddressWidth()

UINT32 CompatibilityCheckGetX86VirtualAddressWidth ( )

Get virtual address width for x86 processors.

Returns
UINT32
57{
58 int Regs[4];
59
61
62 //
63 // Extracting bit 15:8 from eax register
64 //
65 return ((Regs[0] >> 8) & 0x0ff);
66}

◆ CompatibilityCheckModeBasedExecution()

BOOLEAN CompatibilityCheckModeBasedExecution ( )

Check for mode-based execution.

Returns
BOOLEAN
93{
94 //
95 // The PML address and PML index fields exist only on processors that support the 1-setting of
96 // the "enable PML" VM - execution control
97 //
98 UINT32 SecondaryProcBasedVmExecControls = HvAdjustControls(IA32_VMX_PROCBASED_CTLS2_MODE_BASED_EXECUTE_CONTROL_FOR_EPT_FLAG,
99 IA32_VMX_PROCBASED_CTLS2);
100
101 if (SecondaryProcBasedVmExecControls & IA32_VMX_PROCBASED_CTLS2_MODE_BASED_EXECUTE_CONTROL_FOR_EPT_FLAG)
102 {
103 //
104 // The processor support PML
105 //
106 return TRUE;
107 }
108 else
109 {
110 //
111 // Not supported
112 //
113 return FALSE;
114 }
115}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned int UINT32
Definition BasicTypes.h:48
UINT32 HvAdjustControls(UINT32 Ctl, UINT32 Msr)
Adjust controls for VMCS based on processor capability.
Definition Hv.c:23

◆ CompatibilityCheckPerformChecks()

VOID CompatibilityCheckPerformChecks ( )

Checks for the compatibility features based on current processor @detail NOTE: NOT ALL OF THE CHECKS ARE PERFORMED HERE.

Returns
VOID
154{
155 //
156 // Check if processor supports TSX (RTM)
157 //
159
160 //
161 // Get x86 processor width for virtual address
162 //
164
165 //
166 // Get x86 processor width for physical address
167 //
169
170 //
171 // Check Mode-based execution compatibility
172 //
174
175 //
176 // Check PML support
177 //
179
180 //
181 // Log for testing
182 //
183 LogDebugInfo("Mode based execution: %s | PML: %s",
185 g_CompatibilityCheck.PmlSupport ? "true" : "false");
186}
BOOLEAN CompatibilityCheckModeBasedExecution()
Check for mode-based execution.
Definition CompatibilityChecks.c:92
BOOLEAN CompatibilityCheckPml()
Check for Page Modification Logging (PML) support.
Definition CompatibilityChecks.c:123
BOOLEAN CompatibilityCheckCpuSupportForRtm()
Check whether the processor supports RTM or not.
Definition CompatibilityChecks.c:21
UINT32 CompatibilityCheckGetX86PhysicalAddressWidth()
Get physical address width for x86 processors.
Definition CompatibilityChecks.c:74
UINT32 CompatibilityCheckGetX86VirtualAddressWidth()
Get virtual address width for x86 processors.
Definition CompatibilityChecks.c:56
COMPATIBILITY_CHECKS_STATUS g_CompatibilityCheck
Different attributes and compatibility checks of the current processor.
Definition GlobalVariables.h:26
#define LogDebugInfo(format,...)
Log, initialize boot information and debug information.
Definition HyperDbgHyperLogIntrinsics.h:155
BOOLEAN ModeBasedExecutionSupport
Definition CompatibilityChecks.h:28
UINT32 VirtualAddressWidth
Definition CompatibilityChecks.h:30
UINT32 PhysicalAddressWidth
Definition CompatibilityChecks.h:31
BOOLEAN PmlSupport
Definition CompatibilityChecks.h:27
BOOLEAN RtmSupport
Definition CompatibilityChecks.h:26

◆ CompatibilityCheckPml()

BOOLEAN CompatibilityCheckPml ( )

Check for Page Modification Logging (PML) support.

Returns
BOOLEAN
124{
125 //
126 // The PML address and PML index fields exist only on processors that support the 1-setting of
127 // the "enable PML" VM - execution control
128 //
129 UINT32 SecondaryProcBasedVmExecControls = HvAdjustControls(IA32_VMX_PROCBASED_CTLS2_ENABLE_PML_FLAG, IA32_VMX_PROCBASED_CTLS2);
130
131 if (SecondaryProcBasedVmExecControls & IA32_VMX_PROCBASED_CTLS2_ENABLE_PML_FLAG)
132 {
133 //
134 // The processor support MBEC
135 //
136 return TRUE;
137 }
138 else
139 {
140 //
141 // Not supported
142 //
143 return FALSE;
144 }
145}