VirtualBox

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

Last change on this file since 7637 was 7133, checked in by vboxsync, 17 years ago

Eliminate cpum.h dependency (shuts up a bunch of .c warnings). Fixed the header tests.

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