1 | /** @file
|
---|
2 | * CSAM - Guest OS Code Scanning and Analyis Manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * If you received this file as part of a commercial VirtualBox
|
---|
17 | * distribution, then only the terms of your commercial VirtualBox
|
---|
18 | * license agreement apply instead of the previous paragraph.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef __VBox_csam_h__
|
---|
22 | #define __VBox_csam_h__
|
---|
23 |
|
---|
24 | #include <VBox/cdefs.h>
|
---|
25 | #include <VBox/types.h>
|
---|
26 | #include <VBox/cpum.h>
|
---|
27 | #include <VBox/em.h>
|
---|
28 |
|
---|
29 |
|
---|
30 | /** @defgroup grp_csam The Code Scanning and Analysis API
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * CSAM monitoring tag
|
---|
36 | * For use with CSAMR3MonitorPage
|
---|
37 | */
|
---|
38 | typedef enum CSAMTAG
|
---|
39 | {
|
---|
40 | CSAM_TAG_INVALID = 0,
|
---|
41 | CSAM_TAG_REM,
|
---|
42 | CSAM_TAG_PATM,
|
---|
43 | CSAM_TAG_CSAM,
|
---|
44 | CSAM_TAG_32BIT_HACK = 0x7fffffff
|
---|
45 | } CSAMTAG;
|
---|
46 |
|
---|
47 |
|
---|
48 | __BEGIN_DECLS
|
---|
49 |
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Check if this page needs to be analysed by CSAM.
|
---|
53 | *
|
---|
54 | * This function should only be called for supervisor pages and
|
---|
55 | * only when CSAM is enabled. Leaving these selection criteria
|
---|
56 | * to the caller simplifies the interface (PTE passing).
|
---|
57 | *
|
---|
58 | * Note the the page has not yet been synced, so the TLB trick
|
---|
59 | * (which wasn't ever active anyway) cannot be applied.
|
---|
60 | *
|
---|
61 | * @returns true if the page should be marked not present because
|
---|
62 | * CSAM want need to scan it.
|
---|
63 | * @returns false if the page was already scanned.
|
---|
64 | * @param pVM The VM to operate on.
|
---|
65 | * @param GCPtr GC pointer of page table entry
|
---|
66 | */
|
---|
67 | CSAMDECL(bool) CSAMDoesPageNeedScanning(PVM pVM, RTGCPTR GCPtr);
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Check if this page was previously scanned by CSAM
|
---|
71 | *
|
---|
72 | * @returns true -> scanned, false -> not scanned
|
---|
73 | * @param pVM The VM to operate on.
|
---|
74 | * @param pPage GC page address
|
---|
75 | */
|
---|
76 | CSAMDECL(bool) CSAMIsPageScanned(PVM pVM, RTGCPTR pPage);
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Mark a page as scanned/not scanned
|
---|
80 | *
|
---|
81 | * @note: we always mark it as scanned, even if we haven't completely done so
|
---|
82 | *
|
---|
83 | * @returns VBox status code.
|
---|
84 | * @param pVM The VM to operate on.
|
---|
85 | * @param pPage GC page address (not necessarily aligned)
|
---|
86 | * @param fScanned Mark as scanned or not scanned
|
---|
87 | *
|
---|
88 | */
|
---|
89 | CSAMDECL(int) CSAMMarkPage(PVM pVM, RTGCPTR pPage, bool fScanned);
|
---|
90 |
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Remember a possible code page for later inspection
|
---|
94 | *
|
---|
95 | * @returns VBox status code.
|
---|
96 | * @param pVM The VM to operate on.
|
---|
97 | * @param GCPtr GC pointer of page
|
---|
98 | */
|
---|
99 | CSAMDECL(void) CSAMMarkPossibleCodePage(PVM pVM, RTGCPTR GCPtr);
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Query CSAM state (enabled/disabled)
|
---|
103 | *
|
---|
104 | * @returns 0 - disabled, 1 - enabled
|
---|
105 | * @param pVM The VM to operate on.
|
---|
106 | */
|
---|
107 | #define CSAMIsEnabled(pVM) (pVM->fCSAMEnabled && EMIsRawRing0Enabled(pVM))
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Turn on code scanning
|
---|
111 | *
|
---|
112 | * @returns VBox status code. (trap handled or not)
|
---|
113 | * @param pVM The VM to operate on.
|
---|
114 | */
|
---|
115 | CSAMDECL(int) CSAMEnableScanning(PVM pVM);
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Turn off code scanning
|
---|
119 | *
|
---|
120 | * @returns VBox status code. (trap handled or not)
|
---|
121 | * @param pVM The VM to operate on.
|
---|
122 | */
|
---|
123 | CSAMDECL(int) CSAMDisableScanning(PVM pVM);
|
---|
124 |
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Check if this page needs to be analysed by CSAM
|
---|
128 | *
|
---|
129 | * @returns 0 - disabled, 1 - enabled
|
---|
130 | * @param pVM The VM to operate on.
|
---|
131 | * @param pvFault Fault address
|
---|
132 | */
|
---|
133 | CSAMDECL(int) CSAMExecFault(PVM pVM, RTGCPTR pvFault);
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Check if we've scanned this instruction before. If true, then we can emulate
|
---|
137 | * it instead of returning to ring 3.
|
---|
138 | *
|
---|
139 | * @returns boolean
|
---|
140 | * @param pVM The VM to operate on.
|
---|
141 | * @param GCPtr GC pointer of page table entry
|
---|
142 | */
|
---|
143 | CSAMDECL(bool) CSAMIsKnownDangerousInstr(PVM pVM, RTGCPTR GCPtr);
|
---|
144 |
|
---|
145 |
|
---|
146 | #ifdef IN_RING3
|
---|
147 | /** @defgroup grp_csam_r3 The Code Scanning and Analysis API
|
---|
148 | * @ingroup grp_csam
|
---|
149 | * @{
|
---|
150 | */
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Query CSAM state (enabled/disabled)
|
---|
154 | *
|
---|
155 | * @returns 0 - disabled, 1 - enabled
|
---|
156 | * @param pVM The VM to operate on.
|
---|
157 | */
|
---|
158 | CSAMR3DECL(int) CSAMR3IsEnabled(PVM pVM);
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Initializes the csam.
|
---|
162 | *
|
---|
163 | * @returns VBox status code.
|
---|
164 | * @param pVM The VM to operate on.
|
---|
165 | */
|
---|
166 | CSAMR3DECL(int) CSAMR3Init(PVM pVM);
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Applies relocations to data and code managed by this
|
---|
170 | * component. This function will be called at init and
|
---|
171 | * whenever the VMM need to relocate it self inside the GC.
|
---|
172 | *
|
---|
173 | * The csam will update the addresses used by the switcher.
|
---|
174 | *
|
---|
175 | * @param pVM The VM.
|
---|
176 | * @param offDelta Relocation delta.
|
---|
177 | */
|
---|
178 | CSAMR3DECL(void) CSAMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Terminates the csam.
|
---|
182 | *
|
---|
183 | * Termination means cleaning up and freeing all resources,
|
---|
184 | * the VM it self is at this point powered off or suspended.
|
---|
185 | *
|
---|
186 | * @returns VBox status code.
|
---|
187 | * @param pVM The VM to operate on.
|
---|
188 | */
|
---|
189 | CSAMR3DECL(int) CSAMR3Term(PVM pVM);
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * CSAM reset callback.
|
---|
193 | *
|
---|
194 | * @returns VBox status code.
|
---|
195 | * @param pVM The VM which is reset.
|
---|
196 | */
|
---|
197 | CSAMR3DECL(int) CSAMR3Reset(PVM pVM);
|
---|
198 |
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Notify CSAM of a page flush
|
---|
202 | *
|
---|
203 | * @returns VBox status code
|
---|
204 | * @param pVM The VM to operate on.
|
---|
205 | * @param addr GC address of the page to flush
|
---|
206 | */
|
---|
207 | CSAMR3DECL(int) CSAMR3FlushPage(PVM pVM, RTGCPTR addr);
|
---|
208 |
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Scan and analyse code
|
---|
212 | *
|
---|
213 | * @returns VBox status code.
|
---|
214 | * @param pVM The VM to operate on.
|
---|
215 | * @param Sel selector
|
---|
216 | * @param pHiddenSel The hidden selector register.
|
---|
217 | * @param pInstrGC Instruction pointer
|
---|
218 | */
|
---|
219 | CSAMR3DECL(int) CSAMR3CheckCodeEx(PVM pVM, RTSEL Sel, CPUMSELREGHID *pHiddenSel, RTGCPTR pInstrGC);
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Scan and analyse code
|
---|
223 | *
|
---|
224 | * @returns VBox status code.
|
---|
225 | * @param pVM The VM to operate on.
|
---|
226 | * @param pInstrGC Instruction pointer (0:32 virtual address)
|
---|
227 | */
|
---|
228 | CSAMR3DECL(int) CSAMR3CheckCode(PVM pVM, RTGCPTR pInstrGC);
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Mark an instruction in a page as scanned/not scanned
|
---|
232 | *
|
---|
233 | * @returns VBox status code.
|
---|
234 | * @param pVM The VM to operate on.
|
---|
235 | * @param pInstr Instruction pointer
|
---|
236 | * @param opsize Instruction size
|
---|
237 | * @param fScanned Mark as scanned or not
|
---|
238 | */
|
---|
239 | CSAMR3DECL(int) CSAMR3MarkCode(PVM pVM, RTGCPTR pInstr, uint32_t opsize, bool fScanned);
|
---|
240 |
|
---|
241 | /**
|
---|
242 | * Perform any pending actions
|
---|
243 | *
|
---|
244 | * @returns VBox status code.
|
---|
245 | * @param pVM The VM to operate on.
|
---|
246 | */
|
---|
247 | CSAMR3DECL(int) CSAMR3DoPendingAction(PVM pVM);
|
---|
248 |
|
---|
249 | /**
|
---|
250 | * Monitors a code page (if not already monitored)
|
---|
251 | *
|
---|
252 | * @returns VBox status code
|
---|
253 | * @param pVM The VM to operate on.
|
---|
254 | * @param pPageAddrGC The page to monitor
|
---|
255 | * @param enmTag Monitor tag
|
---|
256 | */
|
---|
257 | CSAMR3DECL(int) CSAMR3MonitorPage(PVM pVM, RTGCPTR pPageAddrGC, CSAMTAG enmTag);
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * Analyse interrupt and trap gates
|
---|
261 | *
|
---|
262 | * @returns VBox status code.
|
---|
263 | * @param pVM The VM to operate on.
|
---|
264 | * @param iGate Start gate
|
---|
265 | * @param cGates Number of gates to check
|
---|
266 | */
|
---|
267 | CSAMR3DECL(int) CSAMR3CheckGates(PVM pVM, uint32_t iGate, uint32_t cGates);
|
---|
268 |
|
---|
269 | /** @} */
|
---|
270 | #endif
|
---|
271 |
|
---|
272 |
|
---|
273 | /** @} */
|
---|
274 | __END_DECLS
|
---|
275 |
|
---|
276 | #endif
|
---|