VirtualBox

Changeset 36795 in vbox


Ignore:
Timestamp:
Apr 21, 2011 3:41:39 PM (14 years ago)
Author:
vboxsync
Message:

IEM: Verify memory writes, fixed bugs found doing so.

Location:
trunk/src/VBox/VMM/VMMAll
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAll.cpp

    r36794 r36795  
    190190/** Temporary hack to disable the double execution.  Will be removed in favor
    191191 * of a dedicated execution mode in EM. */
    192 //#define IEM_VERIFICATION_MODE_NO_REM
     192#define IEM_VERIFICATION_MODE_NO_REM
    193193
    194194/** Used to shut up GCC warnings about variables that 'may be used uninitialized'
     
    36043604    else
    36053605    {
     3606        GCPtrBottom--;
    36063607        uint16_t *pa16Mem = NULL;
    36073608        rcStrict = iemMemMap(pIemCpu, (void **)&pa16Mem, 16, X86_SREG_SS, GCPtrBottom, IEM_ACCESS_STACK_W);
     
    36753676    else
    36763677    {
     3678        GCPtrBottom--;
    36773679        uint32_t *pa32Mem;
    36783680        rcStrict = iemMemMap(pIemCpu, (void **)&pa32Mem, 32, X86_SREG_SS, GCPtrBottom, IEM_ACCESS_STACK_W);
     
    41684170
    41694171        /* Check stack first - may #SS(0). */
    4170         rcStrict = iemMemStackPushBeginSpecial(pIemCpu, 4 + (enmOpSize == IEMMODE_32BIT) * 2,
     4172        rcStrict = iemMemStackPushBeginSpecial(pIemCpu, enmOpSize == IEMMODE_32BIT ? 6 : 4,
    41714173                                               &pvRet, &uNewRsp);
    41724174        if (rcStrict != VINF_SUCCESS)
     
    41804182        if (enmOpSize == IEMMODE_16BIT)
    41814183        {
    4182             ((uint16_t *)pvRet)[0] = pCtx->ip;
     4184            ((uint16_t *)pvRet)[0] = pCtx->ip + cbInstr;
    41834185            ((uint16_t *)pvRet)[1] = pCtx->cs;
    41844186        }
    41854187        else
    41864188        {
    4187             ((uint32_t *)pvRet)[0] = pCtx->eip;
     4189            ((uint32_t *)pvRet)[0] = pCtx->eip + cbInstr;
    41884190            ((uint16_t *)pvRet)[3] = pCtx->cs;
    41894191        }
     
    43734375        pu16Frame[2] = (uint16_t)pCtx->eflags.u;
    43744376        pu16Frame[1] = (uint16_t)pCtx->cs;
    4375         pu16Frame[0] = (uint16_t)pCtx->ip;
     4377        pu16Frame[0] = pCtx->ip + cbInstr;
    43764378        rcStrict = iemMemStackPushCommitSpecial(pIemCpu, pu16Frame, uNewRsp);
    43774379        if (RT_UNLIKELY(rcStrict != VINF_SUCCESS))
     
    61886190}
    61896191
     6192
     6193# ifndef IEM_VERIFICATION_MODE_NO_REM
    61906194/**
    61916195 * Allocate an event record.
     
    62106214    return pEvtRec;
    62116215}
     6216# endif
    62126217
    62136218
     
    63156320}
    63166321
     6322# ifndef IEM_VERIFICATION_MODE_NO_REM
    63176323
    63186324/**
     
    64416447
    64426448/**
     6449 * Verifies a write record.
     6450 *
     6451 * @param   pIemCpu         The IEM per CPU data.
     6452 * @param   pEvtRec         The write record.
     6453 */
     6454static void iemVerifyWriteRecord(PIEMCPU pIemCpu, PIEMVERIFYEVTREC pEvtRec)
     6455{
     6456    uint8_t abBuf[sizeof(pEvtRec->u.RamWrite.ab)]; RT_ZERO(abBuf);
     6457    int rc = PGMPhysSimpleReadGCPhys(IEMCPU_TO_VM(pIemCpu), abBuf, pEvtRec->u.RamWrite.GCPhys, pEvtRec->u.RamWrite.cb);
     6458    if (   RT_FAILURE(rc)
     6459        || memcmp(abBuf, pEvtRec->u.RamWrite.ab, pEvtRec->u.RamWrite.cb) )
     6460    {
     6461        /* fend off ins */
     6462        if (   !pIemCpu->cIOReads
     6463            || pEvtRec->u.RamWrite.ab[0] != 0xcc
     6464            || (   pEvtRec->u.RamWrite.cb != 1
     6465                && pEvtRec->u.RamWrite.cb != 2
     6466                && pEvtRec->u.RamWrite.cb != 4) )
     6467        {
     6468            RTAssertMsg1(NULL, __LINE__, __FILE__, __PRETTY_FUNCTION__);
     6469            RTAssertMsg2Weak("Memory at %RGv differs\n", pEvtRec->u.RamWrite.GCPhys);
     6470            RTAssertMsg2Add("REM: %.*Rhxs\n"
     6471                            "IEM: %.*Rhxs\n",
     6472                            pEvtRec->u.RamWrite.cb, abBuf
     6473                            pEvtRec->u.RamWrite.cb, pEvtRec->u.RamWrite.ab);
     6474            iemVerifyAssertAddRecordDump(pEvtRec);
     6475            RTAssertPanic();
     6476        }
     6477    }
     6478
     6479}
     6480
     6481# endif /* !IEM_VERIFICATION_MODE_NO_REM */
     6482
     6483/**
    64436484 * Performs the post-execution verfication checks.
    64446485 */
     
    64596500    int rc = REMR3EmulateInstruction(IEMCPU_TO_VM(pIemCpu), IEMCPU_TO_VMCPU(pIemCpu));
    64606501    AssertRC(rc);
    6461 #if 0
    6462     if (pIemCpu->fPrefixes & (IEM_OP_PRF_REPNZ | IEM_OP_PRF_REPZ))
    6463     {
    6464         while (    pOrgCtx->rip == pDebugCtx->rip - pIemCpu->offOpcode
    6465                &&  pOrgCtx->rcx != pDebugCtx->rcx
    6466                &&  pOrgCtx->rsi != pDebugCtx->rsi
    6467                &&  pOrgCtx->rdi != pDebugCtx->rdi)
    6468         {
    6469             rc = REMR3EmulateInstruction(IEMCPU_TO_VM(pIemCpu), IEMCPU_TO_VMCPU(pIemCpu));
    6470             AssertRC(rc);
    6471         }
    6472     }
    6473 #endif
    64746502
    64756503    /*
     
    66426670        while (pIemRec && pOtherRec)
    66436671        {
    6644             /* Since we might miss RAM writes and reads, ignore extra ones
    6645                made by IEM.  */
     6672            /* Since we might miss RAM writes and reads, ignore reads and check
     6673               that any written memory is the same extra ones.  */
    66466674            while (   IEMVERIFYEVENT_IS_RAM(pIemRec->enmEvent)
    66476675                   && !IEMVERIFYEVENT_IS_RAM(pOtherRec->enmEvent)
    66486676                   && pIemRec->pNext)
     6677            {
     6678                if (pIemRec->enmEvent == IEMVERIFYEVENT_RAM_WRITE)
     6679                    iemVerifyWriteRecord(pIemCpu, pIemRec);
    66496680                pIemRec = pIemRec->pNext;
     6681            }
    66506682
    66516683            /* Do the compare. */
     
    66936725        /* Ignore extra writes and reads. */
    66946726        while (pIemRec && IEMVERIFYEVENT_IS_RAM(pIemRec->enmEvent))
     6727        {
     6728            if (pIemRec->enmEvent == IEMVERIFYEVENT_RAM_WRITE)
     6729                iemVerifyWriteRecord(pIemCpu, pIemRec);
    66956730            pIemRec = pIemRec->pNext;
     6731        }
    66966732        if (pIemRec != NULL)
    66976733            iemVerifyAssertRecord(pIemRec, "Extra IEM record!");
  • trunk/src/VBox/VMM/VMMAll/IEMAllInstructions.cpp.h

    r36794 r36795  
    81378137                IEM_MC_FETCH_MEM_U32(offSeg, pIemCpu->iEffSeg, GCPtrEffSrc);
    81388138                IEM_MC_FETCH_MEM_U16(u16Sel, pIemCpu->iEffSeg, GCPtrEffSrc + 4);
    8139                 IEM_MC_CALL_CIMPL_3(iemCImpl_callf, u16Sel, offSeg, IEMMODE_16BIT);
     8139                IEM_MC_CALL_CIMPL_3(iemCImpl_callf, u16Sel, offSeg, IEMMODE_32BIT);
    81408140                IEM_MC_END();
    81418141            }
     
    81508150                IEM_MC_FETCH_MEM_S32_SX_U64(offSeg, pIemCpu->iEffSeg, GCPtrEffSrc);
    81518151                IEM_MC_FETCH_MEM_U16(u16Sel, pIemCpu->iEffSeg, GCPtrEffSrc + 4);
    8152                 IEM_MC_CALL_CIMPL_3(iemCImpl_callf, u16Sel, offSeg, IEMMODE_16BIT);
     8152                IEM_MC_CALL_CIMPL_3(iemCImpl_callf, u16Sel, offSeg, IEMMODE_32BIT);
    81538153                IEM_MC_END();
    81548154            }
     
    81648164            IEM_MC_FETCH_MEM_U64(offSeg, pIemCpu->iEffSeg, GCPtrEffSrc);
    81658165            IEM_MC_FETCH_MEM_U16(u16Sel, pIemCpu->iEffSeg, GCPtrEffSrc + 8);
    8166             IEM_MC_CALL_CIMPL_3(iemCImpl_callf, u16Sel, offSeg, IEMMODE_16BIT);
     8166            IEM_MC_CALL_CIMPL_3(iemCImpl_callf, u16Sel, offSeg, IEMMODE_64BIT);
    81678167            IEM_MC_END();
    81688168            return VINF_SUCCESS;
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