Changeset 41768 in vbox
- Timestamp:
- Jun 15, 2012 7:15:22 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
include/VBox/vmm/patm.h (modified) (1 diff)
-
src/VBox/VMM/VMMR3/PATM.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/vmm/patm.h
r41658 r41768 558 558 */ 559 559 VMMR3DECL(int) PATMR3QueryOpcode(PVM pVM, RTRCPTR pInstrGC, uint8_t *pByte); 560 VMMR3DECL(int) PATMR3ReadOrgInstr(PVM pVM, RTGCPTR32 GCPtrInstr, uint8_t *pbDst, size_t cbToRead, size_t *pcbRead); 560 561 561 562 /** -
trunk/src/VBox/VMM/VMMR3/PATM.cpp
r41764 r41768 5026 5026 5027 5027 /** 5028 * Read instruction bytes of the original code that was overwritten by the 5 5029 * bytes patch jump. 5030 * 5031 * @returns VINF_SUCCESS or VERR_PATCH_NOT_FOUND. 5032 * @param pVM The VM to operate on. 5033 * @param GCPtrInstr GC address of instr 5034 * @param pbDst The output buffer. 5035 * @param cbToRead The maximum number bytes to read. 5036 * @param pcbRead Where to return the acutal number of bytes read. 5037 */ 5038 VMMR3DECL(int) PATMR3ReadOrgInstr(PVM pVM, RTGCPTR32 GCPtrInstr, uint8_t *pbDst, size_t cbToRead, size_t *pcbRead) 5039 { 5040 /* Shortcut. */ 5041 if ( !PATMIsEnabled(pVM) 5042 || GCPtrInstr < pVM->patm.s.pPatchedInstrGCLowest 5043 || GCPtrInstr > pVM->patm.s.pPatchedInstrGCHighest) 5044 return VERR_PATCH_NOT_FOUND; 5045 5046 /** @todo this will not work for aliased pages! (never has, but so far not a problem for us) */ 5047 5048 /* 5049 * If the patch is enabled and the pointer lies within 5 bytes of this 5050 * priv instr ptr, then we've got a hit! 5051 */ 5052 RTGCPTR32 off; 5053 PPATMPATCHREC pPatchRec = (PPATMPATCHREC)RTAvloU32GetBestFit(&pVM->patm.s.PatchLookupTreeHC->PatchTree, 5054 GCPtrInstr, false /*fAbove*/); 5055 if ( pPatchRec 5056 && pPatchRec->patch.uState == PATCH_ENABLED 5057 && (off = GCPtrInstr - pPatchRec->patch.pPrivInstrGC) < pPatchRec->patch.cbPatchJump) 5058 { 5059 uint8_t const *pbSrc = &pPatchRec->patch.aPrivInstr[off]; 5060 uint32_t const cbMax = pPatchRec->patch.cbPatchJump - off; 5061 if (cbToRead > cbMax) 5062 cbToRead = cbMax; 5063 switch (cbToRead) 5064 { 5065 case 5: pbDst[4] = pbSrc[4]; 5066 case 4: pbDst[3] = pbSrc[3]; 5067 case 3: pbDst[2] = pbSrc[2]; 5068 case 2: pbDst[1] = pbSrc[1]; 5069 case 1: pbDst[0] = pbSrc[0]; 5070 break; 5071 default: 5072 memcpy(pbDst, pbSrc, cbToRead); 5073 } 5074 *pcbRead = cbToRead; 5075 5076 if (pPatchRec->patch.cbPatchJump == 1) 5077 Log(("PATMR3ReadOrgInstr: returning opcode %.*Rhxs for instruction at %RX32\n", cbToRead, pbSrc, GCPtrInstr)); 5078 STAM_COUNTER_ADD(&pVM->patm.s.StatNrOpcodeRead, 1); 5079 return VINF_SUCCESS; 5080 } 5081 5082 return VERR_PATCH_NOT_FOUND; 5083 } 5084 5085 /** 5028 5086 * Disable patch for privileged instruction at specified location 5029 5087 *
Note:
See TracChangeset
for help on using the changeset viewer.

