[1] | 1 | /** @file
|
---|
| 2 | * CSAM - Guest OS Code Scanning and Analyis Manager.
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[8155] | 6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
[1] | 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
|
---|
[5999] | 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.
|
---|
[8155] | 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.
|
---|
[1] | 28 | */
|
---|
| 29 |
|
---|
[3632] | 30 | #ifndef ___VBox_csam_h
|
---|
| 31 | #define ___VBox_csam_h
|
---|
[1] | 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 | CSAMDECL(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 | */
|
---|
| 84 | CSAMDECL(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 | */
|
---|
| 97 | CSAMDECL(int) CSAMMarkPage(PVM pVM, RTGCPTR pPage, bool fScanned);
|
---|
| 98 |
|
---|
[1829] | 99 |
|
---|
[1] | 100 | /**
|
---|
[1829] | 101 | * Remember a possible code page for later inspection
|
---|
[1] | 102 | *
|
---|
| 103 | * @returns VBox status code.
|
---|
| 104 | * @param pVM The VM to operate on.
|
---|
[1829] | 105 | * @param GCPtr GC pointer of page
|
---|
[1] | 106 | */
|
---|
[1829] | 107 | CSAMDECL(void) CSAMMarkPossibleCodePage(PVM pVM, RTGCPTR GCPtr);
|
---|
[1] | 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 | CSAMDECL(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 | CSAMDECL(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 | CSAMDECL(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 | */
|
---|
| 151 | CSAMDECL(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 | */
|
---|
| 166 | CSAMR3DECL(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 | CSAMR3DECL(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 | CSAMR3DECL(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 | CSAMR3DECL(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 | CSAMR3DECL(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 | CSAMR3DECL(int) CSAMR3FlushPage(PVM pVM, RTGCPTR addr);
|
---|
| 216 |
|
---|
[1993] | 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 | CSAMR3DECL(int) CSAMR3RemovePage(PVM pVM, RTGCPTR addr);
|
---|
[1] | 225 |
|
---|
| 226 | /**
|
---|
[881] | 227 | * Scan and analyse code
|
---|
[1] | 228 | *
|
---|
| 229 | * @returns VBox status code.
|
---|
| 230 | * @param pVM The VM to operate on.
|
---|
[1085] | 231 | * @param Sel selector
|
---|
| 232 | * @param pHiddenSel The hidden selector register.
|
---|
[881] | 233 | * @param pInstrGC Instruction pointer
|
---|
[1] | 234 | */
|
---|
[7133] | 235 | CSAMR3DECL(int) CSAMR3CheckCodeEx(PVM pVM, RTSEL Sel, PCPUMSELREGHID pHiddenSel, RTGCPTR pInstrGC);
|
---|
[1] | 236 |
|
---|
| 237 | /**
|
---|
[1085] | 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 | */
|
---|
| 244 | CSAMR3DECL(int) CSAMR3CheckCode(PVM pVM, RTGCPTR pInstrGC);
|
---|
| 245 |
|
---|
| 246 | /**
|
---|
[1829] | 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 | */
|
---|
| 255 | CSAMR3DECL(int) CSAMR3MarkCode(PVM pVM, RTGCPTR pInstr, uint32_t opsize, bool fScanned);
|
---|
| 256 |
|
---|
| 257 | /**
|
---|
[1832] | 258 | * Perform any pending actions
|
---|
[1] | 259 | *
|
---|
| 260 | * @returns VBox status code.
|
---|
| 261 | * @param pVM The VM to operate on.
|
---|
| 262 | */
|
---|
[1832] | 263 | CSAMR3DECL(int) CSAMR3DoPendingAction(PVM pVM);
|
---|
[1] | 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 | */
|
---|
| 273 | CSAMR3DECL(int) CSAMR3MonitorPage(PVM pVM, RTGCPTR pPageAddrGC, CSAMTAG enmTag);
|
---|
| 274 |
|
---|
| 275 | /**
|
---|
| 276 | * Analyse interrupt and trap gates
|
---|
| 277 | *
|
---|
| 278 | * @returns VBox status code.
|
---|
| 279 | * @param pVM The VM to operate on.
|
---|
| 280 | * @param iGate Start gate
|
---|
| 281 | * @param cGates Number of gates to check
|
---|
| 282 | */
|
---|
| 283 | CSAMR3DECL(int) CSAMR3CheckGates(PVM pVM, uint32_t iGate, uint32_t cGates);
|
---|
| 284 |
|
---|
[5198] | 285 | /**
|
---|
| 286 | * Record previous call instruction addresses
|
---|
| 287 | *
|
---|
| 288 | * @returns VBox status code.
|
---|
| 289 | * @param pVM The VM to operate on.
|
---|
| 290 | * @param GCPtrCall Call address
|
---|
| 291 | */
|
---|
| 292 | CSAMR3DECL(int) CSAMR3RecordCallAddress(PVM pVM, RTGCPTR GCPtrCall);
|
---|
| 293 |
|
---|
[1] | 294 | /** @} */
|
---|
| 295 | #endif
|
---|
| 296 |
|
---|
| 297 |
|
---|
| 298 | /** @} */
|
---|
| 299 | __END_DECLS
|
---|
| 300 |
|
---|
| 301 | #endif
|
---|