VirtualBox

Changeset 57009 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 19, 2015 5:57:02 PM (9 years ago)
Author:
vboxsync
Message:

PATM: Fixed assertion in patmSaveFixupRecords when re-saving a restored machine.

File:
1 edited

Legend:

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

    r55889 r57009  
    138138    PATCHINFOSSM     patch;
    139139} PATMPATCHRECSSM, *PPATMPATCHRECSSM;
     140
     141
     142/**
     143 * Callback arguments.
     144 */
     145typedef struct PATMCALLBACKARGS
     146{
     147    PVM             pVM;
     148    PSSMHANDLE      pSSM;
     149    PPATMPATCHREC   pPatchRec;
     150} PATMCALLBACKARGS;
     151typedef PATMCALLBACKARGS *PPATMCALLBACKARGS;
    140152
    141153
     
    522534 * @returns VBox status code.
    523535 * @param   pNode           Current node
    524  * @param   pVM1            Pointer to the VM
    525  */
    526 static DECLCALLBACK(int) patmSaveP2GLookupRecords(PAVLU32NODECORE pNode, void *pVM1)
    527 {
    528     PVM                 pVM    = (PVM)pVM1;
    529     PSSMHANDLE          pSSM   = pVM->patm.s.savedstate.pSSM;
     536 * @param   pvUser          Pointer to PATMCALLBACKARGS.
     537 */
     538static DECLCALLBACK(int) patmSaveP2GLookupRecords(PAVLU32NODECORE pNode, void *pvUser)
     539{
     540    PPATMCALLBACKARGS   pArgs = (PPATMCALLBACKARGS)pvUser;
    530541    PRECPATCHTOGUEST    pPatchToGuestRec = (PRECPATCHTOGUEST)pNode;
    531542
    532543    /* Save the lookup record. */
    533     int rc = SSMR3PutStructEx(pSSM, pPatchToGuestRec, sizeof(RECPATCHTOGUEST), 0 /*fFlags*/, &g_aPatmRecPatchToGuest[0], NULL);
     544    int rc = SSMR3PutStructEx(pArgs->pSSM, pPatchToGuestRec, sizeof(RECPATCHTOGUEST), 0 /*fFlags*/,
     545                              &g_aPatmRecPatchToGuest[0], NULL);
    534546    AssertRCReturn(rc, rc);
    535547
     
    544556 * @returns VBox status code.
    545557 * @param   pNode           Current node
    546  * @param   pVM1            Pointer to the VM
    547  */
    548 static DECLCALLBACK(int) patmSaveFixupRecords(PAVLPVNODECORE pNode, void *pVM1)
    549 {
    550     PVM                 pVM  = (PVM)pVM1;
    551     PSSMHANDLE          pSSM = pVM->patm.s.savedstate.pSSM;
     558 * @param   pvUser          Pointer to PATMCALLBACKARGS.
     559 */
     560static DECLCALLBACK(int) patmSaveFixupRecords(PAVLPVNODECORE pNode, void *pvUser)
     561{
     562    PPATMCALLBACKARGS   pArgs = (PPATMCALLBACKARGS)pvUser;
    552563    RELOCREC            rec  = *(PRELOCREC)pNode;
    553     RTRCPTR            *pFixup = (RTRCPTR *)rec.pRelocPos;
    554564
    555565    /* Convert pointer to an offset into patch memory.  May not be applicable
    556566       to all fixup types, thus the UINT32_MAX. */
    557     Assert(rec.pRelocPos);
    558     uintptr_t offRelocPos = (uintptr_t)rec.pRelocPos - (uintptr_t)pVM->patm.s.pPatchMemHC;
    559     if (offRelocPos > pVM->patm.s.cbPatchMem)
     567    AssertMsg(   rec.pRelocPos
     568              || (   rec.uType == FIXUP_REL_JMPTOPATCH
     569                  && !(pArgs->pPatchRec->patch.flags & PATMFL_PATCHED_GUEST_CODE)),
     570             ("uState=%#x uType=%#x flags=%#RX64\n", pArgs->pPatchRec->patch.uState, rec.uType, pArgs->pPatchRec->patch.flags));
     571    uintptr_t offRelocPos = (uintptr_t)rec.pRelocPos - (uintptr_t)pArgs->pVM->patm.s.pPatchMemHC;
     572    if (offRelocPos > pArgs->pVM->patm.s.cbPatchMem)
    560573        offRelocPos = UINT32_MAX;
    561574    rec.pRelocPos = (uint8_t *)offRelocPos;
     
    564577    rec.Core.Key = 0;
    565578
    566 
    567579    /* Save the lookup record. */
    568     int rc = SSMR3PutStructEx(pSSM, &rec, sizeof(rec), 0 /*fFlags*/, &g_aPatmRelocRec[0], NULL);
     580    int rc = SSMR3PutStructEx(pArgs->pSSM, &rec, sizeof(rec), 0 /*fFlags*/, &g_aPatmRelocRec[0], NULL);
    569581    AssertRCReturn(rc, rc);
    570582
     
    669681 * @returns VBox status code.
    670682 * @param   pNode           Current node
    671  * @param   pVM1            Pointer to the VM
    672  */
    673 static DECLCALLBACK(int) patmSavePatchState(PAVLOU32NODECORE pNode, void *pVM1)
    674 {
    675     PVM             pVM    = (PVM)pVM1;
    676     PPATMPATCHREC   pPatch = (PPATMPATCHREC)pNode;
    677     PATMPATCHRECSSM patch;
    678     PSSMHANDLE      pSSM   = pVM->patm.s.savedstate.pSSM;
    679     int             rc;
    680 
     683 * @param   pvUser          Pointer to PATMCALLBACKARGS.
     684 */
     685static DECLCALLBACK(int) patmSavePatchState(PAVLOU32NODECORE pNode, void *pvUser)
     686{
     687    PPATMCALLBACKARGS   pArgs  = (PPATMCALLBACKARGS)pvUser;
     688    PPATMPATCHREC       pPatch = (PPATMPATCHREC)pNode;
     689    PATMPATCHRECSSM     patch;
     690    int                 rc;
     691
     692    pArgs->pPatchRec = pPatch;
    681693    Assert(!(pPatch->patch.flags & PATMFL_GLOBAL_FUNCTIONS));
    682694
     
    689701     * Reset HC pointers that need to be recalculated when loading the state
    690702     */
     703#ifdef VBOX_STRICT
     704    PVM pVM = pArgs->pVM; /* For PATCHCODE_PTR_HC. */
    691705    AssertMsg(patch.patch.uState == PATCH_REFUSED || (patch.patch.pPatchBlockOffset || (patch.patch.flags & (PATMFL_SYSENTER_XP|PATMFL_INT3_REPLACEMENT))),
    692706              ("State = %x pPatchBlockHC=%08x flags=%x\n", patch.patch.uState, PATCHCODE_PTR_HC(&patch.patch), patch.patch.flags));
     707#endif
    693708    Assert(pPatch->patch.JumpTree == 0);
    694709    Assert(!pPatch->patch.pTempInfo || pPatch->patch.pTempInfo->DisasmJumpTree == 0);
     
    696711
    697712    /* Save the patch record itself */
    698     rc = SSMR3PutStructEx(pSSM, &patch, sizeof(patch), 0 /*fFlags*/, &g_aPatmPatchRecFields[0], NULL);
     713    rc = SSMR3PutStructEx(pArgs->pSSM, &patch, sizeof(patch), 0 /*fFlags*/, &g_aPatmPatchRecFields[0], NULL);
    699714    AssertRCReturn(rc, rc);
    700715
     
    707722    AssertMsg(nrFixupRecs == pPatch->patch.nrFixups, ("Fixup inconsistency! counted %d vs %d\n", nrFixupRecs, pPatch->patch.nrFixups));
    708723#endif
    709     rc = RTAvlPVDoWithAll(&pPatch->patch.FixupTree, true, patmSaveFixupRecords, pVM);
     724    rc = RTAvlPVDoWithAll(&pPatch->patch.FixupTree, true, patmSaveFixupRecords, pArgs);
    710725    AssertRCReturn(rc, rc);
    711726
     
    716731#endif
    717732
    718     rc = RTAvlU32DoWithAll(&pPatch->patch.Patch2GuestAddrTree, true, patmSaveP2GLookupRecords, pVM);
     733    rc = RTAvlU32DoWithAll(&pPatch->patch.Patch2GuestAddrTree, true, patmSaveP2GLookupRecords, pArgs);
    719734    AssertRCReturn(rc, rc);
    720735
     736    pArgs->pPatchRec = NULL;
    721737    return VINF_SUCCESS;
    722738}
     
    779795     * Save all patches
    780796     */
    781     rc = RTAvloU32DoWithAll(&pVM->patm.s.PatchLookupTreeHC->PatchTree, true, patmSavePatchState, pVM);
     797    PATMCALLBACKARGS Args;
     798    Args.pVM = pVM;
     799    Args.pSSM = pSSM;
     800    rc = RTAvloU32DoWithAll(&pVM->patm.s.PatchLookupTreeHC->PatchTree, true, patmSavePatchState, &Args);
    782801    AssertRCReturn(rc, rc);
    783802
    784     /** @note patch statistics are not saved. */
     803    /* Note! Patch statistics are not saved. */
    785804
    786805    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