PGMDbg.cpp revision 6730a3c4d4b7eebe2ff0712db8d93f8757f1c8e4
/* $Id$ */
/** @file
* PGM - Page Manager and Monitor - Debugger & Debugging APIs.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_PGM
#include "PGMInternal.h"
/** The max needle size that we will bother searching for
* This must not be more than half a page! */
#define MAX_NEEDLE_SIZE 256
/**
* Converts a R3 pointer to a GC physical address.
*
* Only for the debugger.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success, *pGCPhys is set.
* @retval VERR_INVALID_POINTER if the pointer is not within the GC physical memory.
*
* @param pVM The VM handle.
* @param R3Ptr The R3 pointer to convert.
* @param pGCPhys Where to store the GC physical address on success.
*/
{
*pGCPhys = NIL_RTGCPHYS;
return VERR_NOT_IMPLEMENTED;
}
/**
* Converts a R3 pointer to a HC physical address.
*
* Only for the debugger.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success, *pHCPhys is set.
* @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical page but has no physical backing.
* @retval VERR_INVALID_POINTER if the pointer is not within the GC physical memory.
*
* @param pVM The VM handle.
* @param R3Ptr The R3 pointer to convert.
* @param pHCPhys Where to store the HC physical address on success.
*/
{
*pHCPhys = NIL_RTHCPHYS;
return VERR_NOT_IMPLEMENTED;
}
/**
* Converts a HC physical address to a GC physical address.
*
* Only for the debugger.
*
* @returns VBox status code
* @retval VINF_SUCCESS on success, *pGCPhys is set.
* @retval VERR_INVALID_POINTER if the HC physical address is not within the GC physical memory.
*
* @param pVM The VM handle.
* @param HCPhys The HC physical address to convert.
* @param pGCPhys Where to store the GC physical address on success.
*/
{
/*
* Validate and adjust the input a bit.
*/
if (HCPhys == NIL_RTHCPHYS)
return VERR_INVALID_POINTER;
if (HCPhys == 0)
return VERR_INVALID_POINTER;
pRam;
{
while (iPage-- > 0)
{
return VINF_SUCCESS;
}
}
return VERR_INVALID_POINTER;
}
/**
* Read physical memory API for the debugger, similar to
* PGMPhysSimpleReadGCPhys.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pvDst Where to store what's read.
* @param GCPhysDst Where to start reading from.
* @param cb The number of bytes to attempt reading.
* @param fFlags Flags, MBZ.
* @param pcbRead For store the actual number of bytes read, pass NULL if
* partial reads are unwanted.
* @todo Unused?
*/
VMMR3DECL(int) PGMR3DbgReadGCPhys(PVM pVM, void *pvDst, RTGCPHYS GCPhysSrc, size_t cb, uint32_t fFlags, size_t *pcbRead)
{
/* validate */
/* try simple first. */
return rc;
/* partial read that failed, chop it up in pages. */
*pcbRead = 0;
rc = VINF_SUCCESS;
while (cb > 0)
{
/* advance */
if (RT_FAILURE(rc))
break;
}
}
/**
* Write physical memory API for the debugger, similar to
* PGMPhysSimpleWriteGCPhys.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param GCPhysDst Where to start writing.
* @param pvSrc What to write.
* @param cb The number of bytes to attempt writing.
* @param fFlags Flags, MBZ.
* @param pcbWritten For store the actual number of bytes written, pass NULL
* if partial writes are unwanted.
* @todo Unused?
*/
VMMR3DECL(int) PGMR3DbgWriteGCPhys(PVM pVM, RTGCPHYS GCPhysDst, const void *pvSrc, size_t cb, uint32_t fFlags, size_t *pcbWritten)
{
/* validate */
/* try simple first. */
return rc;
/* partial write that failed, chop it up in pages. */
*pcbWritten = 0;
rc = VINF_SUCCESS;
while (cb > 0)
{
/* advance */
if (RT_FAILURE(rc))
break;
*pcbWritten += cbChunk;
}
}
/**
* Read virtual memory API for the debugger, similar to PGMPhysSimpleReadGCPtr.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pvDst Where to store what's read.
* @param GCPtrDst Where to start reading from.
* @param cb The number of bytes to attempt reading.
* @param fFlags Flags, MBZ.
* @param pcbRead For store the actual number of bytes read, pass NULL if
* partial reads are unwanted.
* @todo Unused?
*/
VMMR3DECL(int) PGMR3DbgReadGCPtr(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb, uint32_t fFlags, size_t *pcbRead)
{
/* validate */
/* @todo SMP support! */
/** @todo deal with HMA */
/* try simple first. */
return rc;
/* partial read that failed, chop it up in pages. */
*pcbRead = 0;
rc = VINF_SUCCESS;
while (cb > 0)
{
/* advance */
if (RT_FAILURE(rc))
break;
}
}
/**
* Write virtual memory API for the debugger, similar to
* PGMPhysSimpleWriteGCPtr.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param GCPtrDst Where to start writing.
* @param pvSrc What to write.
* @param cb The number of bytes to attempt writing.
* @param fFlags Flags, MBZ.
* @param pcbWritten For store the actual number of bytes written, pass NULL
* if partial writes are unwanted.
* @todo Unused?
*/
VMMR3DECL(int) PGMR3DbgWriteGCPtr(PVM pVM, RTGCPTR GCPtrDst, void const *pvSrc, size_t cb, uint32_t fFlags, size_t *pcbWritten)
{
/* validate */
/* @todo SMP support! */
/** @todo deal with HMA */
/* try simple first. */
return rc;
/* partial write that failed, chop it up in pages. */
*pcbWritten = 0;
rc = VINF_SUCCESS;
while (cb > 0)
{
/* advance */
if (RT_FAILURE(rc))
break;
*pcbWritten += cbChunk;
}
}
/**
* memchr() with alignment considerations.
*
* @returns Pointer to matching byte, NULL if none found.
* @param pb Where to search. Aligned.
* @param b What to search for.
* @param cb How much to search .
* @param uAlign The alignment restriction of the result.
*/
static const uint8_t *pgmR3DbgAlignedMemChr(const uint8_t *pb, uint8_t b, size_t cb, uint32_t uAlign)
{
if (uAlign <= 32)
{
{
do
{
pbRet++;
if (!cbLeft)
{
break;
}
}
}
else
{
if (cb)
{
for (;;)
{
if (*pb == b)
{
break;
}
break;
}
}
}
return pbRet;
}
/**
* Scans a page for a byte string, keeping track of potential
* cross page matches.
*
* @returns true and *poff on match.
* false on mismatch.
* @param pbPage Pointer to the current page.
* @param poff Input: The offset into the page (aligned).
* Output: The page offset of the match on success.
* @param cb The number of bytes to search, starting of *poff.
* @param uAlign The needle alignment. This is of course less than a page.
* @param pabNeedle The byte string to search for.
* @param cbNeedle The length of the byte string.
* @param pabPrev The buffer that keeps track of a partial match that we
* bring over from the previous page. This buffer must be
* at least cbNeedle - 1 big.
* @param pcbPrev Input: The number of partial matching bytes from the previous page.
* Output: The number of partial matching bytes from this page.
* Initialize to 0 before the first call to this function.
*/
{
/*
* Try complete any partial match from the previous page.
*/
if (*pcbPrev > 0)
{
{
return false;
return true;
}
/* check out the remainder of the previous page. */
for (;;)
{
break;
if (!pb)
break;
{
return false;
return true;
}
}
*pcbPrev = 0;
}
/*
* Match the body of the page.
*/
for (;;)
{
if (!pb)
break;
{
/* match? */
{
return true;
}
}
else
{
/* paritial match at the end of the page? */
{
/* We're copying one byte more that we really need here, but wtf. */
return false;
}
}
/* no match, skip ahead. */
break;
}
return false;
}
/**
* Scans guest physical memory for a byte string.
*
* @returns VBox status codes:
* @retval VINF_SUCCESS and *pGCPtrHit on success.
* @retval VERR_DBGF_MEM_NOT_FOUND if not found.
* @retval VERR_INVALID_POINTER if any of the pointer arguments are invalid.
* @retval VERR_INVALID_ARGUMENT if any other arguments are invalid.
*
* @param pVM Pointer to the shared VM structure.
* @param GCPhys Where to start searching.
* @param cbRange The number of bytes to search.
* @param GCPhysAlign The alignment of the needle. Must be a power of two
* and less or equal to 4GB.
* @param pabNeedle The byte string to search for.
* @param cbNeedle The length of the byte string. Max 256 bytes.
* @param pGCPhysHit Where to store the address of the first occurence on success.
*/
VMMR3DECL(int) PGMR3DbgScanPhysical(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cbRange, RTGCPHYS GCPhysAlign,
{
/*
* Validate and adjust the input a bit.
*/
if (!VALID_PTR(pGCPhysHit))
return VERR_INVALID_POINTER;
|| GCPhys == NIL_RTGCPHYS)
return VERR_INVALID_POINTER;
if (!cbNeedle)
return VERR_INVALID_PARAMETER;
if (cbNeedle > MAX_NEEDLE_SIZE)
return VERR_INVALID_PARAMETER;
if (!cbRange)
return VERR_DBGF_MEM_NOT_FOUND;
return VERR_DBGF_MEM_NOT_FOUND;
if (!GCPhysAlign)
return VERR_INVALID_PARAMETER;
if (GCPhysAlign > UINT32_MAX)
return VERR_NOT_POWER_OF_TWO;
return VERR_INVALID_PARAMETER;
{
return VERR_DBGF_MEM_NOT_FOUND;
}
? 1
: GCPhysAlign >> PAGE_SHIFT;
: ~(RTGCPHYS)0;
/*
* Search the memory - ignore MMIO and zero pages, also don't
* bother to match across ranges.
*/
pRam;
{
/*
* If the search range starts prior to the current ram range record,
* adjust the search range and possibly conclude the search.
*/
{
break;
off = 0;
}
else
{
/*
* Iterate the relevant pages.
*/
for (;; offPage = 0)
{
if ( ( !PGM_PAGE_IS_ZERO(pPage)
|| fAllZero)
&& !PGM_PAGE_IS_MMIO(pPage))
{
void const *pvPage;
if (RT_SUCCESS(rc))
{
bool fRc;
if (GCPhysAlign < PAGE_SIZE)
{
}
else
if (fRc)
{
return VINF_SUCCESS;
}
}
else
cbPrev = 0; /* ignore error. */
}
else
cbPrev = 0;
/* advance to the next page. */
{
return VERR_DBGF_MEM_NOT_FOUND;
}
break;
}
}
}
return VERR_DBGF_MEM_NOT_FOUND;
}
/**
* Scans (guest) virtual memory for a byte string.
*
* @returns VBox status codes:
* @retval VINF_SUCCESS and *pGCPtrHit on success.
* @retval VERR_DBGF_MEM_NOT_FOUND if not found.
* @retval VERR_INVALID_POINTER if any of the pointer arguments are invalid.
* @retval VERR_INVALID_ARGUMENT if any other arguments are invalid.
*
* @param pVM Pointer to the shared VM structure.
* @param pVCpu The CPU context to search in.
* @param GCPtr Where to start searching.
* @param GCPtrAlign The alignment of the needle. Must be a power of two
* and less or equal to 4GB.
* @param cbRange The number of bytes to search. Max 256 bytes.
* @param pabNeedle The byte string to search for.
* @param cbNeedle The length of the byte string.
* @param pGCPtrHit Where to store the address of the first occurence on success.
*/
VMMR3DECL(int) PGMR3DbgScanVirtual(PVM pVM, PVMCPU pVCpu, RTGCPTR GCPtr, RTGCPTR cbRange, RTGCPTR GCPtrAlign,
{
/*
* Validate and adjust the input a bit.
*/
return VERR_INVALID_POINTER;
*pGCPtrHit = 0;
return VERR_INVALID_POINTER;
if (!cbNeedle)
return VERR_INVALID_PARAMETER;
if (cbNeedle > MAX_NEEDLE_SIZE)
return VERR_INVALID_PARAMETER;
if (!cbRange)
return VERR_DBGF_MEM_NOT_FOUND;
return VERR_DBGF_MEM_NOT_FOUND;
if (!GCPtrAlign)
return VERR_INVALID_PARAMETER;
if (GCPtrAlign > UINT32_MAX)
return VERR_NOT_POWER_OF_TWO;
return VERR_INVALID_PARAMETER;
{
return VERR_DBGF_MEM_NOT_FOUND;
}
/*
* Search the memory - ignore MMIO, zero and not-present pages.
*/
? 1
: GCPtrAlign >> PAGE_SHIFT;
: GCPtrMask;
for (;; offPage = 0)
{
if (RT_SUCCESS(rc))
{
if ( pPage
&& ( !PGM_PAGE_IS_ZERO(pPage)
|| fAllZero)
&& !PGM_PAGE_IS_MMIO(pPage))
{
void const *pvPage;
if (RT_SUCCESS(rc))
{
bool fRc;
if (GCPtrAlign < PAGE_SIZE)
{
}
else
if (fRc)
{
return VINF_SUCCESS;
}
}
else
cbPrev = 0; /* ignore error. */
}
else
cbPrev = 0;
}
else
cbPrev = 0; /* ignore error. */
/* advance to the next page. */
break;
}
return VERR_DBGF_MEM_NOT_FOUND;
}