DBGFMem.cpp revision c458503b85d643d51c5287959b8d96a3e32d9499
/* $Id$ */
/** @file
* DBGF - Debugger Facility, Memory Methods.
*/
/*
* Copyright (C) 2007-2010 Oracle Corporation
*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DBGF
#include "DBGFInternal.h"
/**
* Scan guest memory for an exact byte string.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param idCpu The ID of the CPU context to search in.
* @param pAddress Where to store the mixed address.
* @param puAlign The alignment restriction imposed on the search result.
* @param pcbRange The number of bytes to scan. Passed as a pointer because
* it may be 64-bit.
* @param pabNeedle What to search for - exact search.
* @param cbNeedle Size of the search byte string.
* @param pHitAddress Where to put the address of the first hit.
*/
static DECLCALLBACK(int) dbgfR3MemScan(PVM pVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, PCRTGCUINTPTR pcbRange, RTGCUINTPTR *puAlign,
{
/*
* Validate the input we use, PGM does the rest.
*/
return VERR_INVALID_POINTER;
if (!VALID_PTR(pHitAddress))
return VERR_INVALID_POINTER;
if (DBGFADDRESS_IS_HMA(pAddress))
return VERR_INVALID_POINTER;
/*
* Select DBGF worker by addressing mode.
*/
int rc;
if ( enmMode == PGMMODE_REAL
|| enmMode == PGMMODE_PROTECTED
)
{
if (GCPhysAlign != *puAlign)
return VERR_OUT_OF_RANGE;
rc = PGMR3DbgScanPhysical(pVM, pAddress->FlatPtr, cbRange, GCPhysAlign, pabNeedle, cbNeedle, &PhysHit);
if (RT_SUCCESS(rc))
}
else
{
#if GC_ARCH_BITS > 32
&& enmMode != PGMMODE_AMD64
&& enmMode != PGMMODE_AMD64_NX)
return VERR_DBGF_MEM_NOT_FOUND;
#endif
rc = PGMR3DbgScanVirtual(pVM, pVCpu, pAddress->FlatPtr, cbRange, *puAlign, pabNeedle, cbNeedle, &GCPtrHit);
if (RT_SUCCESS(rc))
}
return rc;
}
/**
* Scan guest memory for an exact 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 The VM handle.
* @param idCpu The ID of the CPU context to search in.
* @param pAddress Where to store the mixed address.
* @param cbRange The number of bytes to scan.
* @param uAlign The alignment restriction imposed on the result.
* Usually set to 1.
* @param pvNeedle What to search for - exact search.
* @param cbNeedle Size of the search byte string.
* @param pHitAddress Where to put the address of the first hit.
*
* @thread Any thread.
*/
VMMR3DECL(int) DBGFR3MemScan(PVM pVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, RTGCUINTPTR cbRange, RTGCUINTPTR uAlign,
{
}
/**
* Read guest memory.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param pAddress Where to start reading.
* @param pvBuf Where to store the data we've read.
* @param cbRead The number of bytes to read.
*/
static DECLCALLBACK(int) dbgfR3MemRead(PVM pVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead)
{
/*
* Validate the input we use, PGM does the rest.
*/
return VERR_INVALID_POINTER;
return VERR_INVALID_POINTER;
/*
* HMA is special
*/
int rc;
if (DBGFADDRESS_IS_HMA(pAddress))
{
if (DBGFADDRESS_IS_PHYS(pAddress))
else
}
else
{
/*
* Select DBGF worker by addressing mode.
*/
if ( enmMode == PGMMODE_REAL
|| enmMode == PGMMODE_PROTECTED
|| DBGFADDRESS_IS_PHYS(pAddress) )
else
{
#if GC_ARCH_BITS > 32
&& enmMode != PGMMODE_AMD64
&& enmMode != PGMMODE_AMD64_NX)
return VERR_PAGE_TABLE_NOT_PRESENT;
#endif
}
}
return rc;
}
/**
* Read guest memory.
*
* @returns VBox status code.
*
* @param pVM Pointer to the VM.
* @param idCpu The ID of the source CPU context (for the address).
* @param pAddress Where to start reading.
* @param pvBuf Where to store the data we've read.
* @param cbRead The number of bytes to read.
*/
VMMR3DECL(int) DBGFR3MemRead(PVM pVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead)
{
{
}
return VMR3ReqPriorityCallWait(pVM, idCpu, (PFNRT)dbgfR3MemRead, 5, pVM, idCpu, pAddress, pvBuf, cbRead);
}
/**
* Read a zero terminated string from guest memory.
*
* @returns VBox status code.
*
* @param pVM Pointer to the VM.
* @param idCpu The ID of the source CPU context (for the address).
* @param pAddress Where to start reading.
* @param pszBuf Where to store the string.
* @param cchBuf The size of the buffer.
*/
static DECLCALLBACK(int) dbgfR3MemReadString(PVM pVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, char *pszBuf, size_t cchBuf)
{
/*
* Validate the input we use, PGM does the rest.
*/
return VERR_INVALID_POINTER;
return VERR_INVALID_POINTER;
/*
* Let dbgfR3MemRead do the job.
*/
/*
* Make sure the result is terminated and that overflow is signaled.
* This may look a bit reckless with the rc but, it should be fine.
*/
{
}
/*
* Handle partial reads (not perfect).
*/
else if (RT_FAILURE(rc))
{
if (pszBuf[0])
rc = VINF_SUCCESS;
}
return rc;
}
/**
* Read a zero terminated string from guest memory.
*
* @returns VBox status code.
*
* @param pVM Pointer to the VM.
* @param idCpu The ID of the source CPU context (for the address).
* @param pAddress Where to start reading.
* @param pszBuf Where to store the string.
* @param cchBuf The size of the buffer.
*/
VMMR3DECL(int) DBGFR3MemReadString(PVM pVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, char *pszBuf, size_t cchBuf)
{
/*
* Validate and zero output.
*/
return VERR_INVALID_POINTER;
if (cchBuf <= 0)
return VERR_INVALID_PARAMETER;
/*
* Pass it on to the EMT.
*/
return VMR3ReqPriorityCallWait(pVM, idCpu, (PFNRT)dbgfR3MemReadString, 5, pVM, idCpu, pAddress, pszBuf, cchBuf);
}
/**
* Writes guest memory.
*
* @returns VBox status code.
*
* @param pVM Pointer to the VM.
* @param idCpu The ID of the target CPU context (for the address).
* @param pAddress Where to start writing.
* @param pvBuf The data to write.
* @param cbWrite The number of bytes to write.
*/
static DECLCALLBACK(int) dbgfR3MemWrite(PVM pVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, void const *pvBuf, size_t cbWrite)
{
/*
* Validate the input we use, PGM does the rest.
*/
return VERR_INVALID_POINTER;
return VERR_INVALID_POINTER;
/*
* HMA is always special.
*/
int rc;
if (DBGFADDRESS_IS_HMA(pAddress))
{
/** @todo write to HMA. */
}
else
{
/*
* Select PGM function by addressing mode.
*/
if ( enmMode == PGMMODE_REAL
|| enmMode == PGMMODE_PROTECTED
|| DBGFADDRESS_IS_PHYS(pAddress) )
else
{
#if GC_ARCH_BITS > 32
&& enmMode != PGMMODE_AMD64
&& enmMode != PGMMODE_AMD64_NX)
return VERR_PAGE_TABLE_NOT_PRESENT;
#endif
}
}
return rc;
}
/**
* Read guest memory.
*
* @returns VBox status code.
*
* @param pVM Pointer to the VM.
* @param idCpu The ID of the target CPU context (for the address).
* @param pAddress Where to start writing.
* @param pvBuf The data to write.
* @param cbRead The number of bytes to write.
*/
VMMR3DECL(int) DBGFR3MemWrite(PVM pVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, void const *pvBuf, size_t cbWrite)
{
return VMR3ReqPriorityCallWait(pVM, idCpu, (PFNRT)dbgfR3MemWrite, 5, pVM, idCpu, pAddress, pvBuf, cbWrite);
}
/**
* Worker for DBGFR3SelQueryInfo that calls into SELM.
*/
static DECLCALLBACK(int) dbgfR3SelQueryInfo(PVM pVM, VMCPUID idCpu, RTSEL Sel, uint32_t fFlags, PDBGFSELINFO pSelInfo)
{
/*
* Make the query.
*/
int rc;
if (!(fFlags & DBGFSELQI_FLAGS_DT_SHADOW))
{
/*
* 64-bit mode HACKS for making data and stack selectors wide open when
* queried. This is voodoo magic.
*/
{
/* Expand 64-bit data and stack selectors. The check is a bit bogus... */
if ( RT_SUCCESS(rc)
&& (pSelInfo->fFlags & ( DBGFSELINFO_FLAGS_LONG_MODE | DBGFSELINFO_FLAGS_REAL_MODE | DBGFSELINFO_FLAGS_PROT_MODE
{
}
else if ( Sel == 0
{
rc = VINF_SUCCESS;
}
}
}
else
{
if (HWACCMIsEnabled(pVM))
else
}
return rc;
}
/**
* Gets information about a selector.
*
* Intended for the debugger mostly and will prefer the guest
* descriptor tables over the shadow ones.
*
* @returns VBox status code, the following are the common ones.
* @retval VINF_SUCCESS on success.
* @retval VERR_INVALID_SELECTOR if the selector isn't fully inside the
* descriptor table.
* @retval VERR_SELECTOR_NOT_PRESENT if the LDT is invalid or not present. This
* is not returned if the selector itself isn't present, you have to
* check that for yourself (see DBGFSELINFO::fFlags).
* @retval VERR_PAGE_TABLE_NOT_PRESENT or VERR_PAGE_NOT_PRESENT if the
* pagetable or page backing the selector table wasn't present.
*
* @param pVM VM handle.
* @param idCpu The ID of the virtual CPU context.
* @param Sel The selector to get info about.
* @param fFlags Flags, see DBGFQSEL_FLAGS_*.
* @param pSelInfo Where to store the information. This will always be
* updated.
*
* @remarks This is a wrapper around SELMR3GetSelectorInfo and
* SELMR3GetShadowSelectorInfo.
*/
VMMR3DECL(int) DBGFR3SelQueryInfo(PVM pVM, VMCPUID idCpu, RTSEL Sel, uint32_t fFlags, PDBGFSELINFO pSelInfo)
{
AssertReturn(!(fFlags & ~(DBGFSELQI_FLAGS_DT_GUEST | DBGFSELQI_FLAGS_DT_SHADOW | DBGFSELQI_FLAGS_DT_ADJ_64BIT_MODE)), VERR_INVALID_PARAMETER);
/* Clear the return data here on this thread. */
/*
* Dispatch the request to a worker running on the target CPU.
*/
return VMR3ReqPriorityCallWait(pVM, idCpu, (PFNRT)dbgfR3SelQueryInfo, 5, pVM, idCpu, Sel, fFlags, pSelInfo);
}
/**
* Validates a CS selector.
*
* @returns VBox status code.
* @param pSelInfo Pointer to the selector information for the CS selector.
* @param SelCPL The selector defining the CPL (SS).
*/
{
/*
* Check if present.
*/
{
/*
* Type check.
*/
{
/*
* Check level.
*/
)
return VINF_SUCCESS;
return VERR_INVALID_RPL;
}
return VERR_NOT_CODE_SELECTOR;
}
return VERR_SELECTOR_NOT_PRESENT;
}
/**
* Converts a PGM paging mode to a set of DBGFPGDMP_XXX flags.
*
* @returns Flags. UINT32_MAX if the mode is invalid (asserted).
* @param enmMode The mode.
*/
{
switch (enmMode)
{
case PGMMODE_32_BIT:
return DBGFPGDMP_FLAGS_PSE;
case PGMMODE_PAE:
return DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE;
case PGMMODE_PAE_NX:
case PGMMODE_AMD64:
case PGMMODE_AMD64_NX:
case PGMMODE_NESTED:
return DBGFPGDMP_FLAGS_NP;
case PGMMODE_EPT:
return DBGFPGDMP_FLAGS_EPT;
default:
}
}
/**
* EMT worker for DBGFR3PagingDumpEx.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param idCpu The current CPU ID.
* @param fFlags The flags, DBGFPGDMP_FLAGS_XXX. Valid.
* @param pcr3 The CR3 to use (unless we're getting the current
* state, see @a fFlags).
* @param pu64FirstAddr The first address.
* @param pu64LastAddr The last address.
* @param cMaxDepth The depth.
* @param pHlp The output callbacks.
*/
static DECLCALLBACK(int) dbgfR3PagingDumpEx(PVM pVM, VMCPUID idCpu, uint32_t fFlags, uint64_t *pcr3,
{
/*
* Implement dumping both context by means of recursion.
*/
if ((fFlags & (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW)) == (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW))
{
}
/*
*/
{
if (fFlags & DBGFPGDMP_FLAGS_SHADOW)
{
{
if (fFlags & DBGFPGDMP_FLAGS_NP)
{
}
}
}
else
{
{
AssertCompile(DBGFPGDMP_FLAGS_PSE == X86_CR4_PSE); AssertCompile(DBGFPGDMP_FLAGS_PAE == X86_CR4_PAE);
AssertCompile(DBGFPGDMP_FLAGS_LME == MSR_K6_EFER_LME); AssertCompile(DBGFPGDMP_FLAGS_NXE == MSR_K6_EFER_NXE);
}
}
}
/*
* Call PGM to do the real work.
*/
int rc;
if (fFlags & DBGFPGDMP_FLAGS_SHADOW)
else
return rc;
}
/**
* Dump paging structures.
*
* This API can be used to dump both guest and shadow structures.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param idCpu The current CPU ID.
* @param fFlags The flags, DBGFPGDMP_FLAGS_XXX.
* @param cr3 The CR3 to use (unless we're getting the current
* state, see @a fFlags).
* @param u64FirstAddr The address to start dumping at.
* @param u64LastAddr The address to end dumping after.
* @param cMaxDepth The depth.
* @param pHlp The output callbacks. Defaults to the debug log if
* NULL.
*/
VMMDECL(int) DBGFR3PagingDumpEx(PVM pVM, VMCPUID idCpu, uint32_t fFlags, uint64_t cr3, uint64_t u64FirstAddr,
{
/*
* Input validation.
*/
AssertReturn((fFlags & DBGFPGDMP_FLAGS_CURRENT_MODE) || !(fFlags & DBGFPGDMP_FLAGS_MODE_MASK), VERR_INVALID_PARAMETER);
|| !(fFlags & (DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_NXE))
/*
* Forward the request to the target CPU.
*/
}