VirtualBox

Changeset 21704 in vbox


Ignore:
Timestamp:
Jul 17, 2009 3:25:35 PM (16 years ago)
Author:
vboxsync
Message:

Added patch removal.

File:
1 edited

Legend:

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

    r21700 r21704  
    13911391
    13921392/**
     1393 * Callback to patch a TPR instruction (vmmcall or mov cr8)
     1394 *
     1395 * @returns VBox status code.
     1396 * @param   pVM     The VM handle.
     1397 * @param   pVCpu   The VMCPU for the EMT we're being called on.
     1398 * @param   pvUser  Unused
     1399 *
     1400 */
     1401DECLCALLBACK(int) hwaccmR3RemovePatches(PVM pVM, PVMCPU pVCpu, void *pvUser)
     1402{
     1403    for (unsigned i = 0; i < pVM->hwaccm.s.svm.cPatches; i++)
     1404    {
     1405        uint8_t         szInstr[15];
     1406        PHWACCMTPRPATCH pPatch = &pVM->hwaccm.s.svm.aPatches[i];
     1407        RTGCPTR         pInstrGC = (RTGCPTR)pPatch->Core.Key;
     1408
     1409#ifdef LOG_ENABLED
     1410        char            szOutput[256];
     1411
     1412        int rc = DBGFR3DisasInstrEx(pVM, pVCpu->idCpu, CPUMGetGuestCS(pVCpu), pInstrGC, 0, szOutput, sizeof(szOutput), 0);
     1413        if (VBOX_SUCCESS(rc))
     1414            Log(("Patched instr: %s\n", szOutput));
     1415#endif
     1416
     1417        /* Check if the instruction is still the same. */
     1418        rc = PGMPhysSimpleReadGCPtr(pVCpu, szInstr, pInstrGC, pPatch->cbOp);
     1419        if (rc != VINF_SUCCESS)
     1420        {
     1421            Log(("Patched code removed? (rc=%Rrc0\n", rc));
     1422            continue;   /* swapped out or otherwise removed; skip it. */
     1423        }
     1424
     1425        if (memcmp(szInstr, pPatch->aOpcode, pPatch->cbOp))
     1426        {
     1427            Log(("Patched instruction was changed! (rc=%Rrc0\n", rc));
     1428            continue;   /* skip it. */
     1429        }
     1430
     1431        rc = PGMPhysSimpleWriteGCPtr(pVCpu, pInstrGC, pPatch->aOpcode, pPatch->cbOp);
     1432        AssertRC(rc);
     1433
     1434#ifdef LOG_ENABLED
     1435        rc = DBGFR3DisasInstrEx(pVM, pVCpu->idCpu, CPUMGetGuestCS(pVCpu), pInstrGC, 0, szOutput, sizeof(szOutput), 0);
     1436        if (VBOX_SUCCESS(rc))
     1437            Log(("Original instr: %s\n", szOutput));
     1438#endif
     1439    }
     1440    pVM->hwaccm.s.svm.cPatches        = 0;
     1441    pVM->hwaccm.s.svm.PatchTree       = 0;
     1442    pVM->hwaccm.s.pFreeGuestPatchMem  = pVM->hwaccm.s.pGuestPatchMem;
     1443    return VINF_SUCCESS;
     1444}
     1445
     1446/**
    13931447 * Enable patching in a VT-x/AMD-V guest
    13941448 *
     
    14061460        return VERR_NOT_SUPPORTED;
    14071461
     1462    int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ONCE, hwaccmR3RemovePatches, NULL);
     1463    AssertRC(rc);
     1464
    14081465    pVM->hwaccm.s.pGuestPatchMem      = pPatchMem;
    14091466    pVM->hwaccm.s.pFreeGuestPatchMem  = pPatchMem;
     
    14241481    Assert(pVM->hwaccm.s.pGuestPatchMem == pPatchMem);
    14251482    Assert(pVM->hwaccm.s.cbGuestPatchMem == cbPatchMem);
     1483
     1484    int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ONCE, hwaccmR3RemovePatches, NULL);
     1485    AssertRC(rc);
    14261486
    14271487    pVM->hwaccm.s.pGuestPatchMem      = 0;
     
    14941554}
    14951555
     1556
    14961557/**
    14971558 * Callback to patch a TPR instruction (vmmcall or mov cr8)
     
    15151576    AssertRC(rc);
    15161577    if (    rc == VINF_SUCCESS
    1517         &&  pDis->pCurInstr->opcode == OP_MOV)
     1578        &&  pDis->pCurInstr->opcode == OP_MOV
     1579        &&  cbOp >= 3)
    15181580    {
    15191581        if (pVM->hwaccm.s.svm.cPatches < RT_ELEMENTS(pVM->hwaccm.s.svm.aPatches))
     
    16201682        return hwaccmR0EmulateTprMov(pVCpu, pDis, pCtx, cbOp);
    16211683    }
     1684    else
     1685        AssertFailed(); /* deal with failures. */
    16221686    return VERR_ACCESS_DENIED;
    16231687}
     
    16481712    AssertRC(rc);
    16491713    if (    rc == VINF_SUCCESS
    1650         &&  pDis->pCurInstr->opcode == OP_MOV)
     1714        &&  pDis->pCurInstr->opcode == OP_MOV
     1715        &&  cbOp >= 5)
    16511716    {
    16521717        if (pVM->hwaccm.s.svm.cPatches < RT_ELEMENTS(pVM->hwaccm.s.svm.aPatches))
     
    18161881        return hwaccmR0EmulateTprMov(pVCpu, pDis, pCtx, cbOp);
    18171882    }
     1883    else
     1884        AssertFailed(); /* deal with failures. */
    18181885    return VERR_ACCESS_DENIED;
    18191886}
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