Bitdefender Hypervisor Memory Introspection
stats.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Bitdefender
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #ifndef _STATS_H_
6 #define _STATS_H_
7 
8 #include "introdefs.h"
9 
16 typedef enum _STAT_ID
17 {
28 
38 
41 
43 
49 
53 
55 
58 
64 
66 
68 
75 
77 
82 
85 
92 
95 
98 
101 
103 
105 
107 
109 
112 } STAT_ID;
113 
114 
115 #ifndef DEBUG
116 #define STATS_DISABLE_TIMER 1
117 #endif
118 
119 #if defined(USER_MODE) && !defined(CFG_DISABLE_HIRES_COUNTERS) && !defined(STATS_DISABLE_TIMER)
120 # include <time.h>
121 # define STATS_HAS_HIGHRES_TIMER 1
122 #endif
123 
124 #ifdef STATS_HAS_HIGHRES_TIMER
125 typedef struct timespec TIMESPEC;
126 #else
127 typedef QWORD TIMESPEC;
128 #endif
129 
133 typedef struct _STAT_COUNTER
134 {
136 
137 #ifndef STATS_DISABLE_TIMER
138  TIMESPEC Start;
139 
141  QWORD StartEventId;
142  QWORD Max;
143  QWORD StatCalls;
147 
148  TIMESPEC Total;
149 #endif
151 
152 #ifdef STATS_DISABLE_TIMER
153 #define STATS_ENTER(id)
154 #define STATS_DISCARD(id)
155 #else
156 #define STATS_ENTER(id) IntStatStart(id)
157 #define STATS_DISCARD(id) IntStatDiscard(id)
158 #endif
159 
160 #define STATS_EXIT(id) IntStatStop(id)
161 
162 void
164  void
165  );
166 
167 #ifdef STATS_DISABLE_TIMER
168 
170 
171 __forceinline void
173  _In_ STAT_ID StatId
174  )
175 {
176  UNREFERENCED_PARAMETER(StatId);
177 }
178 
179 __forceinline void
181  _In_ STAT_ID StatId
182  )
183 {
184  gCounters[StatId].TotalCount++;
185 }
186 
187 #else
188 
189 void
191  _In_ STAT_ID StatId
192  );
193 
194 void
196  _In_ STAT_ID StatId
197  );
198 
199 #endif // STATS_DISABLE_TIMER
200 
201 void
203  _In_ STAT_ID StatId
204  );
205 
206 void
208  void
209  );
210 
211 void
213  _In_ STAT_ID StatId
214  );
215 
216 void
218  void
219  );
220 
221 #endif // _STATS_H_
Measures kernel mode exceptions checks.
Definition: stats.h:51
Measures IntWinHandleException invocations done for DEP violations.
Definition: stats.h:76
Measures the integrity checks on the process security descriptor.
Definition: stats.h:108
Measures the security descriptor DPI protection information gathering.
Definition: stats.h:102
Measures the pivoted stack DPI protection information gathering.
Definition: stats.h:87
Measures CR violation exits.
Definition: stats.h:30
#define _In_
Definition: intro_sal.h:21
Measures the debug flag DPI protection information gathering.
Definition: stats.h:86
Measures page table writes emulation.
Definition: stats.h:45
Measures user mode exceptions checks.
Definition: stats.h:50
Measures page table writes.
Definition: stats.h:44
Measures page tables integrity checks.
Definition: stats.h:59
STAT_COUNTER gCounters[statsMaxCounter]
The list of counters.
Definition: stats.c:21
Measures the instruction search done for the page table filtering agent.
Definition: stats.h:62
Measures XCR violation exits.
Definition: stats.h:32
Measures all EPT violations.
Definition: stats.h:18
void IntStatsInit(void)
Initialization routine.
Definition: stats.c:448
Measures reads done from the kernel EAT.
Definition: stats.h:93
Measures the IntWinProcHandleCopyMemory detour handler.
Definition: stats.h:67
Measures page table writes done by the VAS monitor.
Definition: stats.h:56
Measures the checks done on SharedUserData.
Definition: stats.h:104
Measures all the page table writes.
Definition: stats.h:46
Measures the stolen token flag DPI protection information gathering.
Definition: stats.h:88
Writes done from kernel mode over user mode.
Definition: stats.h:99
Token writes.
Definition: stats.h:94
Measures the DTR violation exits.
Definition: stats.h:35
Measures the cases in which the stack trace mechanism encounters a JMP after a CALL.
Definition: stats.h:81
Measures the thread start DPI protection information gathering.
Definition: stats.h:91
void IntStatsResetAll(void)
Resets all the stats.
Definition: stats.c:299
Measures the process creation checks.
Definition: stats.h:84
Measures the heap spray DPI protection information gathering.
Definition: stats.h:89
Measures the EPT violations for which the instruction does a read and a write.
Definition: stats.h:27
void IntStatStop(STAT_ID StatId)
Definition: stats.h:180
Measures the execution handling on SharedUserData page.
Definition: stats.h:106
Measures page table entries writes.
Definition: stats.h:47
Measures event injections.
Definition: stats.h:36
Measures the handling of VMCALL exits.
Definition: stats.h:29
Measures the hook commits.
Definition: stats.h:42
_STAT_ID
Stat IDs.
Definition: stats.h:16
Measures the execution of EPT violation handlers.
Definition: stats.h:26
Measures the INT3 exits generated by the page table filtering mechanism.
Definition: stats.h:60
Measures EPT violations generated while the guest was in kernel mode.
Definition: stats.h:22
unsigned long long QWORD
Definition: intro_types.h:53
A stats counter.
Definition: stats.h:133
Measures the IntWinVadHandleCommit detour handler.
Definition: stats.h:57
Measures the deletion of HOOK_REGION_DESCRIPTOR objects.
Definition: stats.h:39
Measures the stack trace mechanism for 32-bit execution contexts.
Definition: stats.h:78
Measures the handling of memory reads in which a write protection policy exists.
Definition: stats.h:74
Measures the decoding of instructions that generate EPT violations.
Definition: stats.h:24
Measures the checks to see if the token has been changed when a token swap occurs.
Definition: stats.h:97
Measures EPT violations generated while the guest was in user mode.
Definition: stats.h:23
Measures the INT3 events.
Definition: stats.h:34
struct _STAT_COUNTER STAT_COUNTER
A stats counter.
Measures page table writes that are actually relevant for Introcore.
Definition: stats.h:48
void IntStatsReset(STAT_ID StatId)
Resets a stat.
Definition: stats.c:276
void IntStatDiscard(STAT_ID StatId)
Discards the current measurement for a stat counter.
Definition: stats.c:431
Measures the checks to see if the token has been changed when a write occurs over the token...
Definition: stats.h:96
#define UNREFERENCED_PARAMETER(P)
Definition: introdefs.h:29
void IntStatsDumpAll(void)
Prints all the non-zero stats.
Definition: stats.c:220
#define __forceinline
Definition: introtypes.h:61
Measures the timer events.
Definition: stats.h:33
Measures the VMCALL exists generated by the page table filtering agent.
Definition: stats.h:61
QWORD TotalCount
The total number of times an event was measured.
Definition: stats.h:135
struct _STAT_COUNTER * PSTAT_COUNTER
QWORD TIMESPEC
Definition: stats.h:127
Measures IntWinProcHandleCopyMemory invocations done for memory reads.
Definition: stats.h:69
Measures the self map entry validation.
Definition: stats.h:65
The number of valid stats IDs. Not a valid ID. Must always be the last entry in the enum...
Definition: stats.h:111
Measures the instruction search done for the SWAPGS protection.
Definition: stats.h:63
Measures MSR violation exits.
Definition: stats.h:31
Measures write EPT violations.
Definition: stats.h:20
enum _STAT_ID STAT_ID
Stat IDs.
void IntStatStart(STAT_ID StatId)
Definition: stats.h:172
Measures the handling of memory reads in which a read protection policy exists.
Definition: stats.h:72
Measures the look-up of EPT violation handlers.
Definition: stats.h:25
Measures the information gathering for the DPI mechanism.
Definition: stats.h:83
Measures exits on NtSetInformationProcess.
Definition: stats.h:100
Measures module load violation handling.
Definition: stats.h:37
Measures user mode crash handlers.
Definition: stats.h:54
Measures execute EPT violations.
Definition: stats.h:21
Measures glob-match exceptions.
Definition: stats.h:52
Measures read EPT violations.
Definition: stats.h:19
Measures the deletion of HOOK_GVA objects.
Definition: stats.h:40
Measures the token privileges DPI protection information gathering.
Definition: stats.h:90