Bitdefender Hypervisor Memory Introspection
vasmonitor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Bitdefender
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #ifndef _VASMONITOR_H_
6 #define _VASMONITOR_H_
7 
8 #include "hook_ptwh.h"
9 
10 
25 typedef INTSTATUS
27  _In_ void *Context,
28  _In_ QWORD VirtualAddress,
29  _In_ QWORD OldEntry,
30  _In_ QWORD NewEntry,
31  _In_ QWORD PageSize
32  );
33 
34 
35 #define VAS_COMPUTE_GLA_64(Base, Index, Level) (PAGE_SX((Base) | ((QWORD)(Index) << ((((Level) - 1) * 9) + 12))))
36 #define VAS_COMPUTE_GLA_PAE(Base, Index, Level) ((Base) | ((QWORD)(Index) << ((((Level) - 1) * 9) + 12)))
37 #define VAS_COMPUTE_GLA_32(Base, Index, Level) ((Base) | ((QWORD)(Index) << ((((Level) - 1) * 10) + 12)))
38 
39 #define VAS_COMPUTE_GLA(Base, Index, Level, Pg) ( \
40  (Pg) == PAGING_5_LEVEL_MODE ? VAS_COMPUTE_GLA_64((Base), (Index), (Level)) : \
41  (Pg) == PAGING_4_LEVEL_MODE ? VAS_COMPUTE_GLA_64((Base), (Index), (Level)) : \
42  (Pg) == PAGING_PAE_MODE ? VAS_COMPUTE_GLA_PAE((Base), (Index), (Level)) : \
43  (Pg) == PAGING_NORMAL_MODE ? VAS_COMPUTE_GLA_32((Base), (Index), (Level)) : 0 \
44  )
45 
46 #define VAS_TRANSITIONS_THRESHOLD 64
47 #define VAS_TOTAL_WRITES_THESHOLD 4096
48 
49 
53 typedef struct _VAS_TABLE_ENTRY
54 {
57 
58 
62 typedef struct _VAS_TABLE
63 {
64  struct _VAS_ROOT *Root;
65  void *WriteHook;
66  PVAS_TABLE_ENTRY Entries;
67  struct _VAS_TABLE **Tables;
75 
76 
80 typedef struct _VAS_ROOT
81 {
84  void *Context;
87  PVAS_TABLE Table;
90 
91 
92 
93 //
94 // API
95 //
98  _In_ QWORD Cr3,
100  _In_ void *Context,
101  _In_ QWORD MonitoredBits,
102  _Out_ void **Root
103  );
104 
105 INTSTATUS
107  _In_opt_ QWORD Cr3,
108  _In_opt_ PVAS_ROOT Root
109  );
110 
111 INTSTATUS
112 IntVasDump(
113  _In_ QWORD Cr3
114  );
115 
116 INTSTATUS
117 IntVasInit(
118  void
119  );
120 
121 INTSTATUS
123  void
124  );
125 
126 
127 #endif // _VASMONITOR_H_
#define _In_opt_
Definition: intro_sal.h:16
DWORD WriteCount
Definition: vasmonitor.h:69
#define _Out_
Definition: intro_sal.h:22
INTSTATUS IntVasUnInit(void)
Uninit the VAS monitor state.
Definition: vasmonitor.c:1143
uint8_t BYTE
Definition: intro_types.h:47
#define _In_
Definition: intro_sal.h:21
uint16_t WORD
Definition: intro_types.h:48
INTSTATUS IntVasInit(void)
Initialize the VAS monitor state.
Definition: vasmonitor.c:1125
QWORD LinearAddress
The first linear address translated by this table.
Definition: vasmonitor.h:68
BYTE PagingMode
Paging mode.
Definition: vasmonitor.h:73
INTSTATUS IntVasDump(QWORD Cr3)
Dump the monitored tables for the indicated Cr3.
Definition: vasmonitor.c:1077
BYTE Level
The level of the current page table.
Definition: vasmonitor.h:72
int INTSTATUS
The status data type.
Definition: introstatus.h:24
LIST_ENTRY Link
List entry link.
Definition: vasmonitor.h:82
struct _VAS_ROOT * PVAS_ROOT
struct _VAS_TABLE_ENTRY * PVAS_TABLE_ENTRY
struct _VAS_ROOT * Root
The root handle.
Definition: vasmonitor.h:64
HOOK_PTEWS WriteState
Write state of each page-table entry.
Definition: vasmonitor.h:55
struct _VAS_TABLE VAS_TABLE
struct _VAS_TABLE * PVAS_TABLE
INTSTATUS IntVasStopMonitorVaSpace(QWORD Cr3, PVAS_ROOT Root)
Stops monitoring the indicated virtual address space.
Definition: vasmonitor.c:979
unsigned long long QWORD
Definition: intro_types.h:53
void * Context
Optional context, will be passed to the callback.
Definition: vasmonitor.h:84
void * WriteHook
The write hook handle.
Definition: vasmonitor.h:65
struct _VAS_TABLE ** Tables
Pointer to children tables, for each valid entry. NULL for leafs.
Definition: vasmonitor.h:67
PVAS_TABLE_ENTRY Entries
Children entries.
Definition: vasmonitor.h:66
uint32_t DWORD
Definition: intro_types.h:49
QWORD MonitoredBits
Monitored bits inside page-table entries.
Definition: vasmonitor.h:85
PFUNC_VaSpaceModificationCallback Callback
Definition: vasmonitor.h:86
WORD EntriesCount
The number of entries. It can vary from 4 to 512 to 1024, depending on mode.
Definition: vasmonitor.h:71
struct _VAS_ROOT VAS_ROOT
INTSTATUS(* PFUNC_VaSpaceModificationCallback)(void *Context, QWORD VirtualAddress, QWORD OldEntry, QWORD NewEntry, QWORD PageSize)
Translation modification callback.
Definition: vasmonitor.h:26
INTSTATUS IntVasStartMonitorVaSpace(QWORD Cr3, PFUNC_VaSpaceModificationCallback Callback, void *Context, QWORD MonitoredBits, void **Root)
Start monitoring the indicated virtual address space.
Definition: vasmonitor.c:877
QWORD Cr3
Monitored virtual address space.
Definition: vasmonitor.h:83
struct _VAS_TABLE_ENTRY VAS_TABLE_ENTRY