VirtualBox

Changeset 41770 in vbox


Ignore:
Timestamp:
Jun 15, 2012 7:34:43 PM (12 years ago)
Author:
vboxsync
Message:

PATM: patmReadBytes read more and use PATMR3ReadOrgInstr.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/PATM.cpp

    r41768 r41770  
    549549    if (pDisInfo->fReadFlags & PATMREAD_ORGCODE)
    550550    {
    551         for (;;)
    552         {
    553             int rc = PATMR3QueryOpcode(pDisInfo->pVM, (RTGCPTR32)pDis->uInstrAddr + offInstr, &pDis->abInstr[offInstr]);
    554             if (RT_FAILURE(rc))
    555                 break; /* VERR_PATCH_NOT_FOUND */
    556             offInstr++;
    557             cbMinRead--;
    558             if (cbMinRead == 0)
     551        size_t      cbRead   = cbMaxRead;
     552        RTUINTPTR   uSrcAddr = pDis->uInstrAddr + offInstr;
     553        int rc = PATMR3ReadOrgInstr(pDisInfo->pVM, pDis->uInstrAddr + offInstr, &pDis->abInstr[offInstr], cbRead, &cbRead);
     554        if (RT_SUCCESS(rc))
     555        {
     556            if (cbRead >= cbMinRead)
    559557            {
    560                 pDis->cbCachedInstr = offInstr;
     558                pDis->cbCachedInstr = offInstr + cbRead;
    561559                return VINF_SUCCESS;
    562560            }
    563             cbMaxRead--;
     561
     562            cbMinRead -= cbRead;
     563            cbMaxRead -= cbRead;
     564            offInstr  += cbRead;
     565            uSrcAddr  += cbRead;
    564566        }
    565567
     
    586588    else
    587589    {
    588         /* pbInstrHC is the base address; adjust according to the GC pointer. */
     590        /*
     591         * pbInstrHC is the base address; adjust according to the GC pointer.
     592         *
     593         * Try read the max number of bytes here.  Since the disassembler only
     594         * ever uses these bytes for the current instruction, it doesn't matter
     595         * much if we accidentally read the start of the next instruction even
     596         * if it happens to be a patch jump or int3.
     597         */
    589598        uint8_t const *pbInstrHC = pDisInfo->pbInstrHC; AssertPtr(pbInstrHC);
    590599        pbInstrHC += uSrcAddr - pDisInfo->pInstrGC;
    591600
    592         memcpy(&pDis->abInstr[offInstr], pbInstrHC, cbMinRead);
    593         offInstr += cbMinRead;
     601        size_t cbMaxRead1 = PAGE_SIZE - (uSrcAddr & PAGE_OFFSET_MASK);
     602        size_t cbMaxRead2 = PAGE_SIZE - ((uintptr_t)pbInstrHC & PAGE_OFFSET_MASK);
     603        size_t cbToRead   = RT_MIN(cbMaxRead1, RT_MAX(cbMaxRead2, cbMinRead));
     604        if (cbToRead > cbMaxRead)
     605            cbToRead = cbMaxRead;
     606
     607        memcpy(&pDis->abInstr[offInstr], pbInstrHC, cbToRead);
     608        offInstr += (uint8_t)cbToRead;
    594609    }
    595610
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