VirtualBox

root/trunk/include/VBox/csam.h

Revision 12989, 8.1 kB (checked in by vboxsync, 2 months ago)

VMM + VBox/cdefs.h: consolidated all the XYZ*DECLS of the VMM into VMM*DECL. Removed dead DECL and IN_XYZ* macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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  */
46 typedef 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  */
75 VMMDECL(bool) CSAMDoesPageNeedScanning(PVM pVM, RTRCPTR 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  */
84 VMMDECL(bool) CSAMIsPageScanned(PVM pVM, RTRCPTR 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  */
97 VMMDECL(int) CSAMMarkPage(PVM pVM, RTRCPTR 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  */
107 VMMDECL(void) CSAMMarkPossibleCodePage(PVM pVM, RTRCPTR 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  */
123 VMMDECL(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  */
131 VMMDECL(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  */
141 VMMDECL(int) CSAMExecFault(PVM pVM, RTRCPTR 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  */
151 VMMDECL(bool) CSAMIsKnownDangerousInstr(PVM pVM, RTRCPTR 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  */
166 VMMR3DECL(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  */
174 VMMR3DECL(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  */
186 VMMR3DECL(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  */
197 VMMR3DECL(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  */
205 VMMR3DECL(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  */
215 VMMR3DECL(int) CSAMR3FlushPage(PVM pVM, RTRCPTR 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  */
224 VMMR3DECL(int) CSAMR3RemovePage(PVM pVM, RTRCPTR addr);
225
226 /**
227  * Scan and analyse code
228  *
229  * @returns VBox status code.
230  * @param   pVM         The VM to operate on.
231  * @param   pCtxCore    CPU context
232  * @param   pInstrGC    Instruction pointer
233  */
234 VMMR3DECL(int) CSAMR3CheckCodeEx(PVM pVM, PCPUMCTXCORE pCtxCore, RTRCPTR pInstrGC);
235
236 /**
237  * Scan and analyse code
238  *
239  * @returns VBox status code.
240  * @param   pVM         The VM to operate on.
241  * @param   pInstrGC    Instruction pointer (0:32 virtual address)
242  */
243 VMMR3DECL(int) CSAMR3CheckCode(PVM pVM, RTRCPTR pInstrGC);
244
245 /**
246  * Mark an instruction in a page as scanned/not scanned
247  *
248  * @returns VBox status code.
249  * @param   pVM         The VM to operate on.
250  * @param   pInstr      Instruction pointer
251  * @param   opsize      Instruction size
252  * @param   fScanned    Mark as scanned or not
253  */
254 VMMR3DECL(int) CSAMR3MarkCode(PVM pVM, RTRCPTR pInstr, uint32_t opsize, bool fScanned);
255
256 /**
257  * Perform any pending actions
258  *
259  * @returns VBox status code.
260  * @param   pVM         The VM to operate on.
261  */
262 VMMR3DECL(int) CSAMR3DoPendingAction(PVM pVM);
263
264 /**
265  * Monitors a code page (if not already monitored)
266  *
267  * @returns VBox status code
268  * @param   pVM         The VM to operate on.
269  * @param   pPageAddrGC The page to monitor
270  * @param   enmTag      Monitor tag
271  */
272 VMMR3DECL(int) CSAMR3MonitorPage(PVM pVM, RTRCPTR pPageAddrGC, CSAMTAG enmTag);
273
274 /**
275  * Unmonitors a code page
276  *
277  * @returns VBox status code
278  * @param   pVM         The VM to operate on.
279  * @param   pPageAddrGC The page to monitor
280  * @param   enmTag      Monitor tag
281  */
282 VMMR3DECL(int) CSAMR3UnmonitorPage(PVM pVM, RTRCPTR pPageAddrGC, CSAMTAG enmTag);
283
284 /**
285  * Analyse interrupt and trap gates
286  *
287  * @returns VBox status code.
288  * @param   pVM         The VM to operate on.
289  * @param   iGate       Start gate
290  * @param   cGates      Number of gates to check
291  */
292 VMMR3DECL(int) CSAMR3CheckGates(PVM pVM, uint32_t iGate, uint32_t cGates);
293
294 /**
295  * Record previous call instruction addresses
296  *
297  * @returns VBox status code.
298  * @param   pVM         The VM to operate on.
299  * @param   GCPtrCall   Call address
300  */
301 VMMR3DECL(int) CSAMR3RecordCallAddress(PVM pVM, RTRCPTR GCPtrCall);
302
303 /** @} */
304 #endif
305
306
307 /** @} */
308 __END_DECLS
309
310 #endif
Note: See TracBrowser for help on using the browser.

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy