VirtualBox

source: vbox/trunk/include/VBox/csam.h@ 8377

Last change on this file since 8377 was 8217, checked in by vboxsync, 17 years ago

Added CSAMR3UnmonitorPage

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/** @file
2 * CSAM - Guest OS Code Scanning and Analyis Manager.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_csam_h
31#define ___VBox_csam_h
32
33#include <VBox/cdefs.h>
34#include <VBox/types.h>
35#include <VBox/em.h>
36
37
38/** @defgroup grp_csam The Code Scanning and Analysis API
39 * @{
40 */
41
42/**
43 * CSAM monitoring tag
44 * For use with CSAMR3MonitorPage
45 */
46typedef enum CSAMTAG
47{
48 CSAM_TAG_INVALID = 0,
49 CSAM_TAG_REM,
50 CSAM_TAG_PATM,
51 CSAM_TAG_CSAM,
52 CSAM_TAG_32BIT_HACK = 0x7fffffff
53} CSAMTAG;
54
55
56__BEGIN_DECLS
57
58
59/**
60 * Check if this page needs to be analysed by CSAM.
61 *
62 * This function should only be called for supervisor pages and
63 * only when CSAM is enabled. Leaving these selection criteria
64 * to the caller simplifies the interface (PTE passing).
65 *
66 * Note the the page has not yet been synced, so the TLB trick
67 * (which wasn't ever active anyway) cannot be applied.
68 *
69 * @returns true if the page should be marked not present because
70 * CSAM want need to scan it.
71 * @returns false if the page was already scanned.
72 * @param pVM The VM to operate on.
73 * @param GCPtr GC pointer of page table entry
74 */
75CSAMDECL(bool) CSAMDoesPageNeedScanning(PVM pVM, RTGCPTR GCPtr);
76
77/**
78 * Check if this page was previously scanned by CSAM
79 *
80 * @returns true -> scanned, false -> not scanned
81 * @param pVM The VM to operate on.
82 * @param pPage GC page address
83 */
84CSAMDECL(bool) CSAMIsPageScanned(PVM pVM, RTGCPTR pPage);
85
86/**
87 * Mark a page as scanned/not scanned
88 *
89 * @note: we always mark it as scanned, even if we haven't completely done so
90 *
91 * @returns VBox status code.
92 * @param pVM The VM to operate on.
93 * @param pPage GC page address (not necessarily aligned)
94 * @param fScanned Mark as scanned or not scanned
95 *
96 */
97CSAMDECL(int) CSAMMarkPage(PVM pVM, RTGCPTR pPage, bool fScanned);
98
99
100/**
101 * Remember a possible code page for later inspection
102 *
103 * @returns VBox status code.
104 * @param pVM The VM to operate on.
105 * @param GCPtr GC pointer of page
106 */
107CSAMDECL(void) CSAMMarkPossibleCodePage(PVM pVM, RTGCPTR GCPtr);
108
109/**
110 * Query CSAM state (enabled/disabled)
111 *
112 * @returns 0 - disabled, 1 - enabled
113 * @param pVM The VM to operate on.
114 */
115#define CSAMIsEnabled(pVM) (pVM->fCSAMEnabled && EMIsRawRing0Enabled(pVM))
116
117/**
118 * Turn on code scanning
119 *
120 * @returns VBox status code. (trap handled or not)
121 * @param pVM The VM to operate on.
122 */
123CSAMDECL(int) CSAMEnableScanning(PVM pVM);
124
125/**
126 * Turn off code scanning
127 *
128 * @returns VBox status code. (trap handled or not)
129 * @param pVM The VM to operate on.
130 */
131CSAMDECL(int) CSAMDisableScanning(PVM pVM);
132
133
134/**
135 * Check if this page needs to be analysed by CSAM
136 *
137 * @returns 0 - disabled, 1 - enabled
138 * @param pVM The VM to operate on.
139 * @param pvFault Fault address
140 */
141CSAMDECL(int) CSAMExecFault(PVM pVM, RTGCPTR pvFault);
142
143/**
144 * Check if we've scanned this instruction before. If true, then we can emulate
145 * it instead of returning to ring 3.
146 *
147 * @returns boolean
148 * @param pVM The VM to operate on.
149 * @param GCPtr GC pointer of page table entry
150 */
151CSAMDECL(bool) CSAMIsKnownDangerousInstr(PVM pVM, RTGCPTR GCPtr);
152
153
154#ifdef IN_RING3
155/** @defgroup grp_csam_r3 The Code Scanning and Analysis API
156 * @ingroup grp_csam
157 * @{
158 */
159
160/**
161 * Query CSAM state (enabled/disabled)
162 *
163 * @returns 0 - disabled, 1 - enabled
164 * @param pVM The VM to operate on.
165 */
166CSAMR3DECL(int) CSAMR3IsEnabled(PVM pVM);
167
168/**
169 * Initializes the csam.
170 *
171 * @returns VBox status code.
172 * @param pVM The VM to operate on.
173 */
174CSAMR3DECL(int) CSAMR3Init(PVM pVM);
175
176/**
177 * Applies relocations to data and code managed by this
178 * component. This function will be called at init and
179 * whenever the VMM need to relocate it self inside the GC.
180 *
181 * The csam will update the addresses used by the switcher.
182 *
183 * @param pVM The VM.
184 * @param offDelta Relocation delta.
185 */
186CSAMR3DECL(void) CSAMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
187
188/**
189 * Terminates the csam.
190 *
191 * Termination means cleaning up and freeing all resources,
192 * the VM it self is at this point powered off or suspended.
193 *
194 * @returns VBox status code.
195 * @param pVM The VM to operate on.
196 */
197CSAMR3DECL(int) CSAMR3Term(PVM pVM);
198
199/**
200 * CSAM reset callback.
201 *
202 * @returns VBox status code.
203 * @param pVM The VM which is reset.
204 */
205CSAMR3DECL(int) CSAMR3Reset(PVM pVM);
206
207
208/**
209 * Notify CSAM of a page flush
210 *
211 * @returns VBox status code
212 * @param pVM The VM to operate on.
213 * @param addr GC address of the page to flush
214 */
215CSAMR3DECL(int) CSAMR3FlushPage(PVM pVM, RTGCPTR addr);
216
217/**
218 * Remove a CSAM monitored page. Use with care!
219 *
220 * @returns VBox status code
221 * @param pVM The VM to operate on.
222 * @param addr GC address of the page to flush
223 */
224CSAMR3DECL(int) CSAMR3RemovePage(PVM pVM, RTGCPTR addr);
225
226/**
227 * Scan and analyse code
228 *
229 * @returns VBox status code.
230 * @param pVM The VM to operate on.
231 * @param Sel selector
232 * @param pHiddenSel The hidden selector register.
233 * @param pInstrGC Instruction pointer
234 */
235CSAMR3DECL(int) CSAMR3CheckCodeEx(PVM pVM, RTSEL Sel, PCPUMSELREGHID pHiddenSel, RTGCPTR pInstrGC);
236
237/**
238 * Scan and analyse code
239 *
240 * @returns VBox status code.
241 * @param pVM The VM to operate on.
242 * @param pInstrGC Instruction pointer (0:32 virtual address)
243 */
244CSAMR3DECL(int) CSAMR3CheckCode(PVM pVM, RTGCPTR pInstrGC);
245
246/**
247 * Mark an instruction in a page as scanned/not scanned
248 *
249 * @returns VBox status code.
250 * @param pVM The VM to operate on.
251 * @param pInstr Instruction pointer
252 * @param opsize Instruction size
253 * @param fScanned Mark as scanned or not
254 */
255CSAMR3DECL(int) CSAMR3MarkCode(PVM pVM, RTGCPTR pInstr, uint32_t opsize, bool fScanned);
256
257/**
258 * Perform any pending actions
259 *
260 * @returns VBox status code.
261 * @param pVM The VM to operate on.
262 */
263CSAMR3DECL(int) CSAMR3DoPendingAction(PVM pVM);
264
265/**
266 * Monitors a code page (if not already monitored)
267 *
268 * @returns VBox status code
269 * @param pVM The VM to operate on.
270 * @param pPageAddrGC The page to monitor
271 * @param enmTag Monitor tag
272 */
273CSAMR3DECL(int) CSAMR3MonitorPage(PVM pVM, RTGCPTR pPageAddrGC, CSAMTAG enmTag);
274
275/**
276 * Unmonitors a code page
277 *
278 * @returns VBox status code
279 * @param pVM The VM to operate on.
280 * @param pPageAddrGC The page to monitor
281 * @param enmTag Monitor tag
282 */
283CSAMR3DECL(int) CSAMR3UnmonitorPage(PVM pVM, RTGCPTR pPageAddrGC, CSAMTAG enmTag);
284
285/**
286 * Analyse interrupt and trap gates
287 *
288 * @returns VBox status code.
289 * @param pVM The VM to operate on.
290 * @param iGate Start gate
291 * @param cGates Number of gates to check
292 */
293CSAMR3DECL(int) CSAMR3CheckGates(PVM pVM, uint32_t iGate, uint32_t cGates);
294
295/**
296 * Record previous call instruction addresses
297 *
298 * @returns VBox status code.
299 * @param pVM The VM to operate on.
300 * @param GCPtrCall Call address
301 */
302CSAMR3DECL(int) CSAMR3RecordCallAddress(PVM pVM, RTGCPTR GCPtrCall);
303
304/** @} */
305#endif
306
307
308/** @} */
309__END_DECLS
310
311#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette