VirtualBox

Changeset 14966 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Dec 4, 2008 1:54:38 AM (16 years ago)
Author:
vboxsync
Message:

PDM, DBGC: debugger read and write APIs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PGMDbg.cpp

    r14299 r14966  
    197197    return VERR_INVALID_POINTER;
    198198}
     199
     200
     201/**
     202 * Read physical memory API for the debugger, similar to
     203 * PGMPhysSimpleReadGCPhys.
     204 *
     205 * @returns VBox status code.
     206 *
     207 * @param   pVM         The VM handle.
     208 * @param   pvDst       Where to store what's read.
     209 * @param   GCPhysDst   Where to start reading from.
     210 * @param   cb          The number of bytes to attempt reading.
     211 * @param   fFlags      Flags, MBZ.
     212 * @param   pcbRead     For store the actual number of bytes read, pass NULL if
     213 *                      partial reads are unwanted.
     214 */
     215VMMR3DECL(int) PGMR3DbgReadGCPhys(PVM pVM, void *pvDst, RTGCPHYS GCPhysSrc, size_t cb, uint32_t fFlags, size_t *pcbRead)
     216{
     217    /* validate */
     218    AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
     219    AssertReturn(pVM, VERR_INVALID_PARAMETER);
     220
     221    /* try simple first. */
     222    int rc = PGMPhysSimpleReadGCPhys(pVM, pvDst, GCPhysSrc, cb);
     223    if (RT_SUCCESS(rc) || !pcbRead)
     224        return rc;
     225
     226    /* partial read that failed, chop it up in pages. */
     227    *pcbRead = 0;
     228    size_t const cbReq = cb;
     229    rc = VINF_SUCCESS;
     230    while (cb > 0)
     231    {
     232        size_t cbChunk = PAGE_SIZE;
     233        cbChunk -= GCPhysSrc & PAGE_OFFSET_MASK;
     234        if (cbChunk > cb)
     235            cbChunk = cb;
     236
     237        rc = PGMPhysSimpleReadGCPhys(pVM, pvDst, GCPhysSrc, cbChunk);
     238
     239        /* advance */
     240        if (RT_FAILURE(rc))
     241            break;
     242        *pcbRead  += cbChunk;
     243        cb        -= cbChunk;
     244        GCPhysSrc += cbChunk;
     245        pvDst = (uint8_t *)pvDst + cbChunk;
     246    }
     247
     248    return *pcbRead && RT_FAILURE(rc) ? -rc : rc;
     249}
     250
     251
     252/**
     253 * Write physical memory API for the debugger, similar to
     254 * PGMPhysSimpleWriteGCPhys.
     255 *
     256 * @returns VBox status code.
     257 *
     258 * @param   pVM         The VM handle.
     259 * @param   GCPhysDst   Where to start writing.
     260 * @param   pvSrc       What to write.
     261 * @param   cb          The number of bytes to attempt writing.
     262 * @param   fFlags      Flags, MBZ.
     263 * @param   pcbWritten  For store the actual number of bytes written, pass NULL
     264 *                      if partial writes are unwanted.
     265 */
     266VMMR3DECL(int) PGMR3DbgWriteGCPhys(PVM pVM, RTGCPHYS GCPhysDst, const void *pvSrc, size_t cb, uint32_t fFlags, size_t *pcbWritten)
     267{
     268    /* validate */
     269    AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
     270    AssertReturn(pVM, VERR_INVALID_PARAMETER);
     271
     272    /* try simple first. */
     273    int rc = PGMPhysSimpleWriteGCPhys(pVM, GCPhysDst, pvSrc, cb);
     274    if (RT_SUCCESS(rc) || !pcbWritten)
     275        return rc;
     276
     277    /* partial write that failed, chop it up in pages. */
     278    *pcbWritten = 0;
     279    rc = VINF_SUCCESS;
     280    while (cb > 0)
     281    {
     282        size_t cbChunk = PAGE_SIZE;
     283        cbChunk -= GCPhysDst & PAGE_OFFSET_MASK;
     284        if (cbChunk > cb)
     285            cbChunk = cb;
     286
     287        rc = PGMPhysSimpleWriteGCPhys(pVM, GCPhysDst, pvSrc, cbChunk);
     288
     289        /* advance */
     290        if (RT_FAILURE(rc))
     291            break;
     292        *pcbWritten += cbChunk;
     293        cb          -= cbChunk;
     294        GCPhysDst   += cbChunk;
     295        pvSrc = (uint8_t const *)pvSrc + cbChunk;
     296    }
     297
     298    return *pcbWritten && RT_FAILURE(rc) ? -rc : rc;
     299
     300}
     301
     302
     303/**
     304 * Read virtual memory API for the debugger, similar to PGMPhysSimpleReadGCPtr.
     305 *
     306 * @returns VBox status code.
     307 *
     308 * @param   pVM         The VM handle.
     309 * @param   pvDst       Where to store what's read.
     310 * @param   GCPtrDst    Where to start reading from.
     311 * @param   cb          The number of bytes to attempt reading.
     312 * @param   fFlags      Flags, MBZ.
     313 * @param   pcbRead     For store the actual number of bytes read, pass NULL if
     314 *                      partial reads are unwanted.
     315 */
     316VMMR3DECL(int) PGMR3DbgReadGCPtr(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb, uint32_t fFlags, size_t *pcbRead)
     317{
     318    /* validate */
     319    AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
     320    AssertReturn(pVM, VERR_INVALID_PARAMETER);
     321
     322/** @todo deal with HMA */
     323    /* try simple first. */
     324    int rc = PGMPhysSimpleReadGCPtr(pVM, pvDst, GCPtrSrc, cb);
     325    if (RT_SUCCESS(rc) || !pcbRead)
     326        return rc;
     327
     328    /* partial read that failed, chop it up in pages. */
     329    *pcbRead = 0;
     330    rc = VINF_SUCCESS;
     331    while (cb > 0)
     332    {
     333        size_t cbChunk = PAGE_SIZE;
     334        cbChunk -= GCPtrSrc & PAGE_OFFSET_MASK;
     335        if (cbChunk > cb)
     336            cbChunk = cb;
     337
     338        rc = PGMPhysSimpleReadGCPtr(pVM, pvDst, GCPtrSrc, cbChunk);
     339
     340        /* advance */
     341        if (RT_FAILURE(rc))
     342            break;
     343        *pcbRead  += cbChunk;
     344        cb        -= cbChunk;
     345        GCPtrSrc  += cbChunk;
     346        pvDst = (uint8_t *)pvDst + cbChunk;
     347    }
     348
     349    return *pcbRead && RT_FAILURE(rc) ? -rc : rc;
     350
     351}
     352
     353
     354/**
     355 * Write virtual memory API for the debugger, similar to
     356 * PGMPhysSimpleWriteGCPtr.
     357 *
     358 * @returns VBox status code.
     359 *
     360 * @param   pVM         The VM handle.
     361 * @param   GCPtrDst    Where to start writing.
     362 * @param   pvSrc       What to write.
     363 * @param   cb          The number of bytes to attempt writing.
     364 * @param   fFlags      Flags, MBZ.
     365 * @param   pcbWritten  For store the actual number of bytes written, pass NULL
     366 *                      if partial writes are unwanted.
     367 */
     368VMMR3DECL(int) PGMR3DbgWriteGCPtr(PVM pVM, RTGCPTR GCPtrDst, void const *pvSrc, size_t cb, uint32_t fFlags, size_t *pcbWritten)
     369{
     370    /* validate */
     371    AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
     372    AssertReturn(pVM, VERR_INVALID_PARAMETER);
     373
     374/** @todo deal with HMA */
     375    /* try simple first. */
     376    int rc = PGMPhysSimpleWriteGCPtr(pVM, GCPtrDst, pvSrc, cb);
     377    if (RT_SUCCESS(rc) || !pcbWritten)
     378        return rc;
     379
     380    /* partial write that failed, chop it up in pages. */
     381    *pcbWritten = 0;
     382    rc = VINF_SUCCESS;
     383    while (cb > 0)
     384    {
     385        size_t cbChunk = PAGE_SIZE;
     386        cbChunk -= GCPtrDst & PAGE_OFFSET_MASK;
     387        if (cbChunk > cb)
     388            cbChunk = cb;
     389
     390        rc = PGMPhysSimpleWriteGCPtr(pVM, GCPtrDst, pvSrc, cbChunk);
     391
     392        /* advance */
     393        if (RT_FAILURE(rc))
     394            break;
     395        *pcbWritten += cbChunk;
     396        cb          -= cbChunk;
     397        GCPtrDst    += cbChunk;
     398        pvSrc = (uint8_t const *)pvSrc + cbChunk;
     399    }
     400
     401    return *pcbWritten && RT_FAILURE(rc) ? -rc : rc;
     402
     403}
     404
    199405
    200406
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette