VirtualBox

source: vbox/trunk/src/VBox/VMM/DBGFMem.cpp@ 8800

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

Started digging into the solaris guest kernel. Added DBGFR3MemRead.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1/* $Id: DBGFMem.cpp 8800 2008-05-14 03:03:54Z vboxsync $ */
2/** @file
3 * VMM DBGF - Debugger Facility, Memory Methods.
4 */
5
6/*
7 * Copyright (C) 2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_DBGF
27#include <VBox/dbgf.h>
28#include <VBox/pgm.h>
29#include "DBGFInternal.h"
30#include <VBox/vm.h>
31#include <VBox/err.h>
32#include <VBox/log.h>
33
34
35
36/**
37 * Scan guest memory for an exact byte string.
38 *
39 * @returns VBox status code.
40 * @param pVM The VM handle.
41 * @param pAddress Where to store the mixed address.
42 * @param cbRange The number of bytes to scan.
43 * @param pabNeedle What to search for - exact search.
44 * @param cbNeedle Size of the search byte string.
45 * @param pHitAddress Where to put the address of the first hit.
46 */
47static DECLCALLBACK(int) dbgfR3MemScan(PVM pVM, PCDBGFADDRESS pAddress, RTGCUINTPTR cbRange, const uint8_t *pabNeedle, size_t cbNeedle,
48 PDBGFADDRESS pHitAddress)
49{
50 /*
51 * Validate the input we use, PGM does the rest.
52 */
53 if (!DBGFR3AddrIsValid(pVM, pAddress))
54 return VERR_INVALID_POINTER;
55 if (!VALID_PTR(pHitAddress))
56 return VERR_INVALID_POINTER;
57 if (DBGFADDRESS_IS_HMA(pAddress))
58 return VERR_INVALID_POINTER;
59
60 /*
61 * Select DBGF worker by addressing mode.
62 */
63 int rc;
64 PGMMODE enmMode = PGMGetGuestMode(pVM);
65 if ( enmMode == PGMMODE_REAL
66 || enmMode == PGMMODE_PROTECTED
67 || DBGFADDRESS_IS_PHYS(pAddress)
68 )
69 {
70 RTGCPHYS PhysHit;
71 rc = PGMR3DbgScanPhysical(pVM, pAddress->FlatPtr, cbRange, pabNeedle, cbNeedle, &PhysHit);
72 if (RT_SUCCESS(rc))
73 DBGFR3AddrFromPhys(pVM, pHitAddress, PhysHit);
74 }
75 else
76 {
77 RTGCUINTPTR GCPtrHit;
78 rc = PGMR3DbgScanVirtual(pVM, pAddress->FlatPtr, cbRange, pabNeedle, cbNeedle, &GCPtrHit);
79 if (RT_SUCCESS(rc))
80 DBGFR3AddrFromFlat(pVM, pHitAddress, GCPtrHit);
81 }
82
83 return rc;
84}
85
86
87/**
88 * Scan guest memory for an exact byte string.
89 *
90 * @returns VBox status codes:
91 * @retval VINF_SUCCESS and *pGCPtrHit on success.
92 * @retval VERR_DBGF_MEM_NOT_FOUND if not found.
93 * @retval VERR_INVALID_POINTER if any of the pointer arguments are invalid.
94 * @retval VERR_INVALID_ARGUMENT if any other arguments are invalid.
95 *
96 * @param pVM The VM handle.
97 * @param pAddress Where to store the mixed address.
98 * @param cbRange The number of bytes to scan.
99 * @param pabNeedle What to search for - exact search.
100 * @param cbNeedle Size of the search byte string.
101 * @param pHitAddress Where to put the address of the first hit.
102 *
103 * @thread Any thread.
104 */
105DBGFR3DECL(int) DBGFR3MemScan(PVM pVM, PCDBGFADDRESS pAddress, RTGCUINTPTR cbRange, const uint8_t *pabNeedle, size_t cbNeedle, PDBGFADDRESS pHitAddress)
106{
107 PVMREQ pReq;
108 int rc = VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT, (PFNRT)dbgfR3MemScan, 6,
109 pVM, pAddress, cbRange, pabNeedle, cbNeedle, pHitAddress);
110 if (VBOX_SUCCESS(rc))
111 rc = pReq->iStatus;
112 VMR3ReqFree(pReq);
113
114 return rc;
115}
116
117
118/**
119 * Read guest memory.
120 *
121 * @returns VBox status code.
122 * @param pVM Pointer to the shared VM structure.
123 * @param pAddress Where to start reading.
124 * @param pvBuf Where to store the data we've read.
125 * @param cbRead The number of bytes to read.
126 */
127static DECLCALLBACK(int) dbgfR3MemRead(PVM pVM, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead)
128{
129 /*
130 * Validate the input we use, PGM does the rest.
131 */
132 if (!DBGFR3AddrIsValid(pVM, pAddress))
133 return VERR_INVALID_POINTER;
134 if (!VALID_PTR(pvBuf))
135 return VERR_INVALID_POINTER;
136 if (DBGFADDRESS_IS_HMA(pAddress))
137 return VERR_INVALID_POINTER;
138
139 /*
140 * Select DBGF worker by addressing mode.
141 */
142 int rc;
143 PGMMODE enmMode = PGMGetGuestMode(pVM);
144 if ( enmMode == PGMMODE_REAL
145 || enmMode == PGMMODE_PROTECTED
146 || DBGFADDRESS_IS_PHYS(pAddress) )
147 rc = PGMPhysReadGCPhys(pVM, pvBuf, pAddress->FlatPtr, cbRead);
148 else
149 rc = PGMPhysReadGCPtr(pVM, pvBuf, pAddress->FlatPtr, cbRead);
150 return rc;
151}
152
153
154/**
155 * Read guest memory.
156 *
157 * @returns VBox status code.
158 * @param pVM Pointer to the shared VM structure.
159 * @param pAddress Where to start reading.
160 * @param pvBuf Where to store the data we've read.
161 * @param cbRead The number of bytes to read.
162 */
163DBGFR3DECL(int) DBGFR3MemRead(PVM pVM, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead)
164{
165 PVMREQ pReq;
166 int rc = VMR3ReqCallU(pVM->pUVM, &pReq, RT_INDEFINITE_WAIT, 0, (PFNRT)dbgfR3MemRead, 4,
167 pVM, pAddress, pvBuf, cbRead);
168 if (VBOX_SUCCESS(rc))
169 rc = pReq->iStatus;
170 VMR3ReqFree(pReq);
171
172 return rc;
173}
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