Changeset 55937 in vbox for trunk/src/VBox/VMM/VMMRC
- Timestamp:
- May 19, 2015 2:27:00 PM (10 years ago)
- Location:
- trunk/src/VBox/VMM/VMMRC
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMRC/CSAMRC.cpp
r55900 r55937 72 72 PPATMGCSTATE pPATMGCState; 73 73 bool fPatchCode = PATMIsPatchGCAddr(pVM, pRegFrame->eip); 74 int rc;75 74 NOREF(uErrorCode); 76 75 … … 96 95 * Make this particular page R/W. 97 96 */ 98 rc = PGMShwMakePageWritable(pVCpu, pvFault, PGM_MK_PG_IS_WRITE_FAULT);97 int rc = PGMShwMakePageWritable(pVCpu, pvFault, PGM_MK_PG_IS_WRITE_FAULT); 99 98 AssertMsgRC(rc, ("PGMShwModifyPage -> rc=%Rrc\n", rc)); 100 99 ASMInvalidatePage((void *)(uintptr_t)pvFault); … … 114 113 if (cpl != 3) 115 114 { 116 rc = PATMRCHandleWriteToPatchPage(pVM, pRegFrame, (RTRCPTR)((RTRCUINTPTR)pvRange + offRange), 4 /** @todo */); 117 if (rc == VINF_SUCCESS) 118 return rc; 119 if (rc == VINF_EM_RAW_EMULATE_INSTR) 115 VBOXSTRICTRC rcStrict = PATMRCHandleWriteToPatchPage(pVM, pRegFrame, (RTRCPTR)((RTRCUINTPTR)pvRange + offRange), 116 4 /** @todo */); 117 if (rcStrict == VINF_SUCCESS) 118 return rcStrict; 119 if (rcStrict == VINF_EM_RAW_EMULATE_INSTR) 120 120 { 121 121 STAM_COUNTER_INC(&pVM->csam.s.StatDangerousWrite); 122 122 return VINF_EM_RAW_EMULATE_INSTR; 123 123 } 124 Assert(rc == VERR_PATCH_NOT_FOUND);124 Assert(rcStrict == VERR_PATCH_NOT_FOUND); 125 125 } 126 126 … … 129 129 /* Note that pvFault might be a different address in case of aliases. So use pvRange + offset instead!. */ 130 130 pVM->csam.s.pvDirtyBasePage[pVM->csam.s.cDirtyPages] = (RTRCPTR)((RTRCUINTPTR)pvRange + offRange); 131 pVM->csam.s.pvDirtyFaultPage[pVM->csam.s.cDirtyPages] = (RTRCPTR) ((RTRCUINTPTR)pvRange + offRange);131 pVM->csam.s.pvDirtyFaultPage[pVM->csam.s.cDirtyPages] = (RTRCPTR)pvFault; 132 132 if (++pVM->csam.s.cDirtyPages == CSAM_MAX_DIRTY_PAGES) 133 133 return VINF_CSAM_PENDING_ACTION; … … 137 137 */ 138 138 Log(("csamRCCodePageWriteHandler: enabled r/w for page %RGv\n", pvFault)); 139 rc = PGMShwMakePageWritable(pVCpu, pvFault, PGM_MK_PG_IS_WRITE_FAULT);139 int rc = PGMShwMakePageWritable(pVCpu, pvFault, PGM_MK_PG_IS_WRITE_FAULT); 140 140 AssertMsgRC(rc, ("PGMShwModifyPage -> rc=%Rrc\n", rc)); 141 141 ASMInvalidatePage((void *)(uintptr_t)pvFault); -
trunk/src/VBox/VMM/VMMRC/PATMRC.cpp
r55900 r55937 63 63 RTGCPTR pvRange, uintptr_t offRange, void *pvUser) 64 64 { 65 NOREF(pVCpu); NOREF(uErrorCode); NOREF(pRegFrame); NOREF(pvFault); NOREF(pvRange); NOREF(offRange); NOREF(pvUser); 66 pVM->patm.s.pvFaultMonitor = (RTRCPTR)(RTRCUINTPTR)pvFault; 65 NOREF(pVCpu); NOREF(uErrorCode); NOREF(pRegFrame); NOREF(pvFault); NOREF(pvRange); NOREF(offRange); 66 Assert(pvUser); Assert(!((uintptr_t)pvUser & PAGE_OFFSET_MASK)); 67 pVM->patm.s.pvFaultMonitor = (RTRCPTR)((uintptr_t)pvUser + (pvFault & PAGE_OFFSET_MASK)); 67 68 return VINF_PATM_CHECK_PATCH_PAGE; 68 69 } … … 73 74 * (if so, then we are not allowed to turn on r/w) 74 75 * 75 * @returns VBox status 76 * @returns Strict VBox status code. 77 * @retval VINF_SUCCESS if access interpreted (@a pRegFrame != NULL). 78 * @retval VINF_PGM_HANDLER_DO_DEFAULT (@a pRegFrame == NULL). 79 * @retval VINF_EM_RAW_EMULATE_INSTR on needing to go to ring-3 to do this. 80 * @retval VERR_PATCH_NOT_FOUND if no patch was found. 81 * 76 82 * @param pVM Pointer to the VM. 77 * @param pRegFrame CPU context 78 * @param GCPtr GC pointer to write address 79 * @param cbWrite N r of bytes to write83 * @param pRegFrame CPU context if \#PF, NULL if other write.. 84 * @param GCPtr GC pointer to write address. 85 * @param cbWrite Number of bytes to write. 80 86 * 81 87 */ 82 VMMRC_INT_DECL( int) PATMRCHandleWriteToPatchPage(PVM pVM, PCPUMCTXCORE pRegFrame, RTRCPTR GCPtr, uint32_t cbWrite)88 VMMRC_INT_DECL(VBOXSTRICTRC) PATMRCHandleWriteToPatchPage(PVM pVM, PCPUMCTXCORE pRegFrame, RTRCPTR GCPtr, uint32_t cbWrite) 83 89 { 84 RTGCUINTPTR pWritePageStart, pWritePageEnd; 85 PPATMPATCHPAGE pPatchPage; 90 Assert(cbWrite > 0); 86 91 87 92 /* Quick boundary check */ 88 if ( PAGE_ADDRESS(GCPtr) < PAGE_ADDRESS(pVM->patm.s.pPatchedInstrGCLowest) 89 || PAGE_ADDRESS(GCPtr) > PAGE_ADDRESS(pVM->patm.s.pPatchedInstrGCHighest) 90 ) 91 return VERR_PATCH_NOT_FOUND; 93 if ( PAGE_ADDRESS(GCPtr) < PAGE_ADDRESS(pVM->patm.s.pPatchedInstrGCLowest) 94 || PAGE_ADDRESS(GCPtr) > PAGE_ADDRESS(pVM->patm.s.pPatchedInstrGCHighest)) 95 return VERR_PATCH_NOT_FOUND; 92 96 93 97 STAM_PROFILE_ADV_START(&pVM->patm.s.StatPatchWriteDetect, a); 94 98 95 pWritePageStart = (RTRCUINTPTR)GCPtr & PAGE_BASE_GC_MASK; 96 pWritePageEnd = ((RTRCUINTPTR)GCPtr + cbWrite - 1) & PAGE_BASE_GC_MASK; 97 98 pPatchPage = (PPATMPATCHPAGE)RTAvloU32Get(CTXSUFF(&pVM->patm.s.PatchLookupTree)->PatchTreeByPage, (AVLOU32KEY)pWritePageStart); 99 /* 100 * Lookup the patch page record for the write. 101 */ 102 RTRCUINTPTR pWritePageStart = (RTRCUINTPTR)GCPtr & PAGE_BASE_GC_MASK; 103 RTRCUINTPTR pWritePageEnd = ((RTRCUINTPTR)GCPtr + cbWrite - 1) & PAGE_BASE_GC_MASK; 104 105 PPATMPATCHPAGE pPatchPage; 106 pPatchPage = (PPATMPATCHPAGE)RTAvloU32Get(&pVM->patm.s.CTXSUFF(PatchLookupTree)->PatchTreeByPage, pWritePageStart); 99 107 if ( !pPatchPage 100 && pWritePageStart != pWritePageEnd 101 ) 102 { 103 pPatchPage = (PPATMPATCHPAGE)RTAvloU32Get(CTXSUFF(&pVM->patm.s.PatchLookupTree)->PatchTreeByPage, (AVLOU32KEY)pWritePageEnd); 104 } 105 106 #ifdef LOG_ENABLED 107 if (pPatchPage) 108 Log(("PATMGCHandleWriteToPatchPage: Found page %RRv for write to %RRv %d bytes (page low:high %RRv:%RRv\n", pPatchPage->Core.Key, GCPtr, cbWrite, pPatchPage->pLowestAddrGC, pPatchPage->pHighestAddrGC)); 109 #endif 110 108 && pWritePageStart != pWritePageEnd) 109 pPatchPage = (PPATMPATCHPAGE)RTAvloU32Get(&pVM->patm.s.CTXSUFF(PatchLookupTree)->PatchTreeByPage, pWritePageEnd); 111 110 if (pPatchPage) 112 111 { 113 if ( pPatchPage->pLowestAddrGC > (RTRCPTR)((RTRCUINTPTR)GCPtr + cbWrite - 1) 114 || pPatchPage->pHighestAddrGC < (RTRCPTR)GCPtr) 112 Log(("PATMGCHandleWriteToPatchPage: Found page %RRv for write to %RRv %d bytes (page low:high %RRv:%RRv\n", 113 pPatchPage->Core.Key, GCPtr, cbWrite, pPatchPage->pLowestAddrGC, pPatchPage->pHighestAddrGC)); 114 if ( (RTRCUINTPTR)pPatchPage->pLowestAddrGC > (RTRCUINTPTR)GCPtr + cbWrite - 1U 115 || (RTRCUINTPTR)pPatchPage->pHighestAddrGC < (RTRCUINTPTR)GCPtr) 115 116 { 116 /* This part of the page was not patched; try to emulate the instruction. */ 117 /* This part of the page was not patched; try to emulate the instruction / tell the caller to do so. */ 118 if (!pRegFrame) 119 { 120 LogFlow(("PATMHandleWriteToPatchPage: Allow writing %RRv LB %#x\n", pRegFrame->eip, GCPtr, cbWrite)); 121 STAM_COUNTER_INC(&pVM->patm.s.StatPatchWriteInterpreted); 122 STAM_PROFILE_ADV_STOP(&pVM->patm.s.StatPatchWriteDetect, a); 123 return VINF_PGM_HANDLER_DO_DEFAULT; 124 } 117 125 LogFlow(("PATMHandleWriteToPatchPage: Interpret %x accessing %RRv\n", pRegFrame->eip, GCPtr)); 118 126 int rc = EMInterpretInstruction(VMMGetCpu0(pVM), pRegFrame, (RTGCPTR)(RTRCUINTPTR)GCPtr);
Note:
See TracChangeset
for help on using the changeset viewer.