VirtualBox

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

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

Added CSAMR3RemovePage

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
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 */
38typedef 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 */
67CSAMDECL(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 */
76CSAMDECL(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 */
89CSAMDECL(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 */
99CSAMDECL(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 */
115CSAMDECL(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 */
123CSAMDECL(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 */
133CSAMDECL(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 */
143CSAMDECL(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 */
158CSAMR3DECL(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 */
166CSAMR3DECL(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 */
178CSAMR3DECL(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 */
189CSAMR3DECL(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 */
197CSAMR3DECL(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 */
207CSAMR3DECL(int) CSAMR3FlushPage(PVM pVM, RTGCPTR addr);
208
209/**
210 * Remove a CSAM monitored page. Use with care!
211 *
212 * @returns VBox status code
213 * @param pVM The VM to operate on.
214 * @param addr GC address of the page to flush
215 */
216CSAMR3DECL(int) CSAMR3RemovePage(PVM pVM, RTGCPTR addr);
217
218/**
219 * Scan and analyse code
220 *
221 * @returns VBox status code.
222 * @param pVM The VM to operate on.
223 * @param Sel selector
224 * @param pHiddenSel The hidden selector register.
225 * @param pInstrGC Instruction pointer
226 */
227CSAMR3DECL(int) CSAMR3CheckCodeEx(PVM pVM, RTSEL Sel, CPUMSELREGHID *pHiddenSel, RTGCPTR pInstrGC);
228
229/**
230 * Scan and analyse code
231 *
232 * @returns VBox status code.
233 * @param pVM The VM to operate on.
234 * @param pInstrGC Instruction pointer (0:32 virtual address)
235 */
236CSAMR3DECL(int) CSAMR3CheckCode(PVM pVM, RTGCPTR pInstrGC);
237
238/**
239 * Mark an instruction in a page as scanned/not scanned
240 *
241 * @returns VBox status code.
242 * @param pVM The VM to operate on.
243 * @param pInstr Instruction pointer
244 * @param opsize Instruction size
245 * @param fScanned Mark as scanned or not
246 */
247CSAMR3DECL(int) CSAMR3MarkCode(PVM pVM, RTGCPTR pInstr, uint32_t opsize, bool fScanned);
248
249/**
250 * Perform any pending actions
251 *
252 * @returns VBox status code.
253 * @param pVM The VM to operate on.
254 */
255CSAMR3DECL(int) CSAMR3DoPendingAction(PVM pVM);
256
257/**
258 * Monitors a code page (if not already monitored)
259 *
260 * @returns VBox status code
261 * @param pVM The VM to operate on.
262 * @param pPageAddrGC The page to monitor
263 * @param enmTag Monitor tag
264 */
265CSAMR3DECL(int) CSAMR3MonitorPage(PVM pVM, RTGCPTR pPageAddrGC, CSAMTAG enmTag);
266
267/**
268 * Analyse interrupt and trap gates
269 *
270 * @returns VBox status code.
271 * @param pVM The VM to operate on.
272 * @param iGate Start gate
273 * @param cGates Number of gates to check
274 */
275CSAMR3DECL(int) CSAMR3CheckGates(PVM pVM, uint32_t iGate, uint32_t cGates);
276
277/** @} */
278#endif
279
280
281/** @} */
282__END_DECLS
283
284#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