VirtualBox

Changeset 8819

Show
Ignore:
Timestamp:
05/14/08 21:46:18 (8 months ago)
Author:
vboxsync
Message:

Added DBGFR3MemReadString and made DBGFR3AddrFromFlat return pAddress.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/dbgf.h

    r8800 r8819  
    186186 * Creates a mixed address from a flat address. 
    187187 * 
     188 * @returns pAddress. 
    188189 * @param   pVM         The VM handle. 
    189190 * @param   pAddress    Where to store the mixed address. 
    190191 * @param   FlatPtr     The flat pointer. 
    191192 */ 
    192 DBGFR3DECL(void) DBGFR3AddrFromFlat(PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR FlatPtr); 
     193DBGFR3DECL(PDBGFADDRESS) DBGFR3AddrFromFlat(PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR FlatPtr); 
    193194 
    194195/** 
     
    15321533DBGFR3DECL(int) DBGFR3MemScan(PVM pVM, PCDBGFADDRESS pAddress, RTGCUINTPTR cbRange, const uint8_t *pabNeedle, size_t cbNeedle, PDBGFADDRESS pHitAddress); 
    15331534DBGFR3DECL(int) DBGFR3MemRead(PVM pVM, PCDBGFADDRESS pAddress, void *pvBuf, size_t cbRead); 
     1535DBGFR3DECL(int) DBGFR3MemReadString(PVM pVM, PCDBGFADDRESS pAddress, char *pszBuf, size_t cbBuf); 
    15341536 
    15351537 
  • trunk/src/VBox/VMM/DBGFAddr.cpp

    r8155 r8819  
    113113 * @param   FlatPtr     The flat pointer. 
    114114 */ 
    115 DBGFR3DECL(void) DBGFR3AddrFromFlat(PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR FlatPtr) 
     115DBGFR3DECL(PDBGFADDRESS) DBGFR3AddrFromFlat(PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR FlatPtr) 
    116116{ 
    117117    pAddress->Sel     = DBGF_SEL_FLAT; 
     
    121121    if (dbgfR3IsHMA(pVM, pAddress->FlatPtr)) 
    122122        pAddress->fFlags |= DBGFADDRESS_FLAGS_HMA; 
     123    return pAddress; 
    123124} 
    124125 
  • trunk/src/VBox/VMM/DBGFMem.cpp

    r8800 r8819  
    172172    return rc; 
    173173} 
     174 
     175 
     176/** 
     177 * Read a zero terminated string from guest memory. 
     178 * 
     179 * @returns VBox status code. 
     180 * @param   pVM             Pointer to the shared VM structure. 
     181 * @param   pAddress        Where to start reading. 
     182 * @param   pszBuf          Where to store the string. 
     183 * @param   cchBuf          The size of the buffer. 
     184 */ 
     185static DECLCALLBACK(int) dbgfR3MemReadString(PVM pVM, PCDBGFADDRESS pAddress, char *pszBuf, size_t cchBuf) 
     186{ 
     187    /* 
     188     * Validate the input we use, PGM does the rest. 
     189     */ 
     190    if (!DBGFR3AddrIsValid(pVM, pAddress)) 
     191        return VERR_INVALID_POINTER; 
     192    if (!VALID_PTR(pszBuf)) 
     193        return VERR_INVALID_POINTER; 
     194    if (DBGFADDRESS_IS_HMA(pAddress)) 
     195        return VERR_INVALID_POINTER; 
     196 
     197    /* 
     198     * Select DBGF worker by addressing mode. 
     199     */ 
     200    int rc; 
     201    PGMMODE enmMode = PGMGetGuestMode(pVM); 
     202    if (    enmMode == PGMMODE_REAL 
     203        ||  enmMode == PGMMODE_PROTECTED 
     204        ||  DBGFADDRESS_IS_PHYS(pAddress) ) 
     205        rc = PGMPhysReadGCPhys(pVM, pszBuf, pAddress->FlatPtr, cchBuf); 
     206    else 
     207        rc = PGMPhysReadGCPtr(pVM, pszBuf, pAddress->FlatPtr, cchBuf); 
     208 
     209    /* 
     210     * Make sure the result is terminated and that overflow is signaled. 
     211     */ 
     212    if (!memchr(pszBuf, '\0', cchBuf)) 
     213    { 
     214        pszBuf[cchBuf - 1] = '\0'; 
     215        rc = VINF_BUFFER_OVERFLOW; 
     216    } 
     217    /* 
     218     * Handle partial reads (not perfect). 
     219     */ 
     220    else if (RT_FAILURE(rc)) 
     221    { 
     222        if (pszBuf[0]) 
     223            rc = VINF_SUCCESS; 
     224    } 
     225 
     226    return rc; 
     227} 
     228 
     229 
     230/** 
     231 * Read a zero terminated string from guest memory. 
     232 * 
     233 * @returns VBox status code. 
     234 * @param   pVM             Pointer to the shared VM structure. 
     235 * @param   pAddress        Where to start reading. 
     236 * @param   pszBuf          Where to store the string. 
     237 * @param   cchBuf          The size of the buffer. 
     238 */ 
     239DBGFR3DECL(int) DBGFR3MemReadString(PVM pVM, PCDBGFADDRESS pAddress, char *pszBuf, size_t cchBuf) 
     240{ 
     241    /* 
     242     * Validate and zero output. 
     243     */ 
     244    if (!VALID_PTR(pszBuf)) 
     245        return VERR_INVALID_POINTER; 
     246    if (cchBuf <= 0) 
     247        return VERR_INVALID_PARAMETER; 
     248    memset(pszBuf, 0, cchBuf); 
     249 
     250    /* 
     251     * Pass it on to the EMT. 
     252     */ 
     253    PVMREQ pReq; 
     254    int rc = VMR3ReqCallU(pVM->pUVM, &pReq, RT_INDEFINITE_WAIT, 0, (PFNRT)dbgfR3MemReadString, 4, 
     255                          pVM, pAddress, pszBuf, cchBuf); 
     256    if (VBOX_SUCCESS(rc)) 
     257        rc = pReq->iStatus; 
     258    VMR3ReqFree(pReq); 
     259 
     260    return rc; 
     261} 
     262 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy