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 
97 
100 } STAT_ID;
101 
102 
103 #ifndef DEBUG
104 #define STATS_DISABLE_TIMER 1
105 #endif
106 
107 #if defined(USER_MODE) && !defined(CFG_DISABLE_HIRES_COUNTERS) && !defined(STATS_DISABLE_TIMER)
108 # include <time.h>
109 # define STATS_HAS_HIGHRES_TIMER 1
110 #endif
111 
112 #ifdef STATS_HAS_HIGHRES_TIMER
113 typedef struct timespec TIMESPEC;
114 #else
115 typedef QWORD TIMESPEC;
116 #endif
117 
121 typedef struct _STAT_COUNTER
122 {
124 
125 #ifndef STATS_DISABLE_TIMER
126  TIMESPEC Start;
127 
129  QWORD StartEventId;
130  QWORD Max;
131  QWORD StatCalls;
135 
136  TIMESPEC Total;
137 #endif
139 
140 #ifdef STATS_DISABLE_TIMER
141 #define STATS_ENTER(id)
142 #define STATS_DISCARD(id)
143 #else
144 #define STATS_ENTER(id) IntStatStart(id)
145 #define STATS_DISCARD(id) IntStatDiscard(id)
146 #endif
147 
148 #define STATS_EXIT(id) IntStatStop(id)
149 
150 void
152  void
153  );
154 
155 #ifdef STATS_DISABLE_TIMER
156 
158 
159 __forceinline void
161  _In_ STAT_ID StatId
162  )
163 {
164  UNREFERENCED_PARAMETER(StatId);
165 }
166 
167 __forceinline void
169  _In_ STAT_ID StatId
170  )
171 {
172  gCounters[StatId].TotalCount++;
173 }
174 
175 #else
176 
177 void
179  _In_ STAT_ID StatId
180  );
181 
182 void
184  _In_ STAT_ID StatId
185  );
186 
187 #endif // STATS_DISABLE_TIMER
188 
189 void
191  _In_ STAT_ID StatId
192  );
193 
194 void
196  void
197  );
198 
199 void
201  _In_ STAT_ID StatId
202  );
203 
204 void
206  void
207  );
208 
209 #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 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:441
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 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:96
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:292
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:168
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:121
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 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:269
void IntStatDiscard(STAT_ID StatId)
Discards the current measurement for a stat counter.
Definition: stats.c:424
#define UNREFERENCED_PARAMETER(P)
Definition: introdefs.h:29
void IntStatsDumpAll(void)
Prints all the non-zero stats.
Definition: stats.c:213
#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:123
struct _STAT_COUNTER * PSTAT_COUNTER
QWORD TIMESPEC
Definition: stats.h:115
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:99
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:160
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 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