VirtualBox

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

Last change on this file since 29491 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1/** @file
2 * CSAM - Guest OS Code Scanning and Analyis Manager. (VMM)
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
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
52RT_C_DECLS_BEGIN
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 */
71VMMDECL(bool) CSAMDoesPageNeedScanning(PVM pVM, RTRCUINTPTR 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 */
80VMMDECL(bool) CSAMIsPageScanned(PVM pVM, RTRCPTR 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 */
93VMMDECL(int) CSAMMarkPage(PVM pVM, RTRCUINTPTR 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 */
103VMMDECL(void) CSAMMarkPossibleCodePage(PVM pVM, RTRCPTR 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 */
119VMMDECL(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 */
127VMMDECL(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 */
137VMMDECL(int) CSAMExecFault(PVM pVM, RTRCPTR 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 */
147VMMDECL(bool) CSAMIsKnownDangerousInstr(PVM pVM, RTRCUINTPTR 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 */
162VMMR3DECL(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 */
170VMMR3DECL(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 */
182VMMR3DECL(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 */
193VMMR3DECL(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 */
201VMMR3DECL(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 */
211VMMR3DECL(int) CSAMR3FlushPage(PVM pVM, RTRCPTR 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 */
220VMMR3DECL(int) CSAMR3RemovePage(PVM pVM, RTRCPTR addr);
221
222/**
223 * Scan and analyse code
224 *
225 * @returns VBox status code.
226 * @param pVM The VM to operate on.
227 * @param pCtxCore CPU context
228 * @param pInstrGC Instruction pointer
229 */
230VMMR3DECL(int) CSAMR3CheckCodeEx(PVM pVM, PCPUMCTXCORE pCtxCore, RTRCPTR pInstrGC);
231
232/**
233 * Scan and analyse code
234 *
235 * @returns VBox status code.
236 * @param pVM The VM to operate on.
237 * @param pInstrGC Instruction pointer (0:32 virtual address)
238 */
239VMMR3DECL(int) CSAMR3CheckCode(PVM pVM, RTRCPTR pInstrGC);
240
241/**
242 * Mark an instruction in a page as scanned/not scanned
243 *
244 * @returns VBox status code.
245 * @param pVM The VM to operate on.
246 * @param pInstr Instruction pointer
247 * @param opsize Instruction size
248 * @param fScanned Mark as scanned or not
249 */
250VMMR3DECL(int) CSAMR3MarkCode(PVM pVM, RTRCPTR pInstr, uint32_t opsize, bool fScanned);
251
252/**
253 * Perform any pending actions
254 *
255 * @returns VBox status code.
256 * @param pVM The VM to operate on.
257 * @param pVCpu The VMCPU to operate on.
258 */
259VMMR3DECL(int) CSAMR3DoPendingAction(PVM pVM, PVMCPU pVCpu);
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 */
269VMMR3DECL(int) CSAMR3MonitorPage(PVM pVM, RTRCPTR pPageAddrGC, CSAMTAG enmTag);
270
271/**
272 * Unmonitors a code page
273 *
274 * @returns VBox status code
275 * @param pVM The VM to operate on.
276 * @param pPageAddrGC The page to monitor
277 * @param enmTag Monitor tag
278 */
279VMMR3DECL(int) CSAMR3UnmonitorPage(PVM pVM, RTRCPTR pPageAddrGC, CSAMTAG enmTag);
280
281/**
282 * Analyse interrupt and trap gates
283 *
284 * @returns VBox status code.
285 * @param pVM The VM to operate on.
286 * @param iGate Start gate
287 * @param cGates Number of gates to check
288 */
289VMMR3DECL(int) CSAMR3CheckGates(PVM pVM, uint32_t iGate, uint32_t cGates);
290
291/**
292 * Record previous call instruction addresses
293 *
294 * @returns VBox status code.
295 * @param pVM The VM to operate on.
296 * @param GCPtrCall Call address
297 */
298VMMR3DECL(int) CSAMR3RecordCallAddress(PVM pVM, RTRCPTR GCPtrCall);
299
300/** @} */
301#endif
302
303
304/** @} */
305RT_C_DECLS_END
306
307#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