- Timestamp:
- May 17, 2013 5:21:45 PM (12 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/PATM.cpp
r46137 r46150 182 182 pVM->patm.s.pGCStackGC = MMHyperR3ToRC(pVM, pVM->patm.s.pGCStackHC); 183 183 184 patmR3DbgInit(pVM); 185 184 186 /* 185 187 * Hypervisor memory for GC status data (read/write) … … 3000 3002 } 3001 3003 3004 patmR3DbgAddPatch(pVM, pPatchRec); 3005 3002 3006 PATM_LOG_RAW_PATCH_INSTR(pVM, pPatch, patmGetInstructionString(pPatch->opcode, pPatch->flags)); 3003 3007 … … 3150 3154 fInserted = RTAvloU32Insert(&pVM->patm.s.PatchLookupTreeHC->PatchTreeByPatchAddr, &pPatchRec->CoreOffset); 3151 3155 AssertMsg(fInserted, ("RTAvlULInsert failed for %x\n", pPatchRec->CoreOffset.Key)); 3156 patmR3DbgAddPatch(pVM, pPatchRec); 3152 3157 3153 3158 pPatch->uState = PATCH_ENABLED; … … 3224 3229 fInserted = RTAvloU32Insert(&pVM->patm.s.PatchLookupTreeHC->PatchTreeByPatchAddr, &pPatchRec->CoreOffset); 3225 3230 AssertMsg(fInserted, ("RTAvlULInsert failed for %x\n", pPatchRec->CoreOffset.Key)); 3231 patmR3DbgAddPatch(pVM, pPatchRec); 3226 3232 3227 3233 pPatch->uState = PATCH_ENABLED; … … 3352 3358 goto failure; 3353 3359 } 3360 3361 patmR3DbgAddPatch(pVM, pPatchRec); 3354 3362 3355 3363 #ifdef LOG_ENABLED … … 3503 3511 goto failure; 3504 3512 } 3513 patmR3DbgAddPatch(pVM, pPatchRec); 3505 3514 3506 3515 /* size of patch block */ … … 4586 4595 } 4587 4596 #endif 4597 4598 /* Add debug symbol. */ 4599 patmR3DbgAddPatch(pVM, pPatchRec); 4588 4600 } 4589 4601 /* Free leftover lock if any. */ -
trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp
r45485 r46150 23 23 #define LOG_GROUP LOG_GROUP_PATM 24 24 #include <VBox/vmm/patm.h> 25 #include <VBox/vmm/stam.h>26 25 #include <VBox/vmm/pgm.h> 27 26 #include <VBox/vmm/cpum.h> … … 29 28 #include <VBox/vmm/em.h> 30 29 #include <VBox/vmm/trpm.h> 31 #include <VBox/param.h> 32 #include <iprt/avl.h> 30 #include <VBox/vmm/csam.h> 33 31 #include "PATMInternal.h" 34 32 #include <VBox/vmm/vm.h> 35 #include <VBox/vmm/csam.h> 36 37 #include <VBox/dbg.h> 33 #include <VBox/param.h> 34 38 35 #include <VBox/err.h> 39 36 #include <VBox/log.h> 37 #include <VBox/dis.h> 38 #include <VBox/disopcode.h> 39 40 40 #include <iprt/assert.h> 41 41 #include <iprt/asm.h> 42 42 #include <iprt/string.h> 43 #include <VBox/dis.h> 44 #include <VBox/disopcode.h> 45 46 #include <stdlib.h> 47 #include <stdio.h> 43 48 44 #include "PATMA.h" 49 45 #include "PATMPatch.h" -
trunk/src/VBox/VMM/VMMR3/PATMR3Dbg.cpp
r46137 r46150 21 21 #define LOG_GROUP LOG_GROUP_PATM 22 22 #include <VBox/vmm/patm.h> 23 #include <VBox/vmm/dbgf.h> 23 24 #include <VBox/vmm/hm.h> 24 25 #include "PATMInternal.h" 26 #include "PATMA.h" 25 27 #include <VBox/vmm/vm.h> 26 28 #include <VBox/err.h> … … 43 45 } while (0) 44 46 45 46 47 /** Adds a structure member to a debug (pseudo) module as a symbol. */ 48 #define ADD_FUNC(a_hDbgMod, a_BaseRCPtr, a_FuncRCPtr, a_cbFunc, a_pszName) \ 49 do { \ 50 int rcAddFunc = RTDbgModSymbolAdd(hDbgMod, a_pszName, 0 /*iSeg*/, \ 51 (RTRCUINTPTR)a_FuncRCPtr - (RTRCUINTPTR)(a_BaseRCPtr), \ 52 a_cbFunc, 0 /*fFlags*/, NULL /*piOrdinal*/); \ 53 AssertRC(rcAddFunc); \ 54 } while (0) 55 56 57 58 /** 59 * Called by PATMR3Init. 60 * 61 * @param pVM The cross context VM structure. 62 */ 47 63 void patmR3DbgInit(PVM pVM) 48 64 { … … 51 67 52 68 69 /** 70 * Called by PATMR3Term. 71 * 72 * @param pVM The cross context VM structure. 73 */ 53 74 void patmR3DbgTerm(PVM pVM) 54 75 { … … 61 82 62 83 84 /** 85 * Called by when the patch memory is reinitialized. 86 * 87 * @param pVM The cross context VM structure. 88 */ 63 89 void patmR3DbgReset(PVM pVM) 64 90 { … … 69 95 } 70 96 97 98 /** 99 * Called when a new patch is added or when first populating the address space. 100 * 101 * @param pVM The cross context VM structure. 102 * @param pPatchRec The patch record. 103 */ 104 void patmR3DbgAddPatch(PVM pVM, PPATMPATCHREC pPatchRec) 105 { 106 if ( pVM->patm.s.hDbgModPatchMem != NIL_RTDBGMOD 107 && pPatchRec->patch.pPatchBlockOffset > 0 108 && !(pPatchRec->patch.flags & PATMFL_GLOBAL_FUNCTIONS)) 109 { 110 /** @todo find a cheap way of checking whether we've already added the patch. 111 * Using a flag would be nice, except I don't want to consider saved 112 * state considerations right now (I don't recall if we're still 113 * depending on structure layout there or not). */ 114 int rc; 115 char szName[256]; 116 117 #define ADD_SZ(a_sz) \ 118 do { \ 119 if (cbLeft >= sizeof(a_sz)) \ 120 { \ 121 memcpy(pszName, a_sz, sizeof(a_sz)); \ 122 pszName += sizeof(a_sz); \ 123 cbLeft -= sizeof(a_sz);\ 124 }\ 125 } while (0) 126 127 /* Start the name off with the address of the guest code. */ 128 size_t cch = RTStrPrintf(szName, sizeof(szName), "Patch_%#08x", pPatchRec->patch.pPrivInstrGC); 129 char *pszName = &szName[cch]; 130 size_t cbLeft = sizeof(szName) - cch; 131 132 /* Append flags. */ 133 uint64_t fFlags = pPatchRec->patch.flags; 134 if (fFlags & PATMFL_INTHANDLER) 135 ADD_SZ("_IntHandler"); 136 if (fFlags & PATMFL_SYSENTER) 137 ADD_SZ("_SysEnter"); 138 if (fFlags & PATMFL_GUEST_SPECIFIC) 139 ADD_SZ("_GuestSpecific"); 140 if (fFlags & PATMFL_USER_MODE) 141 ADD_SZ("_UserMode"); 142 if (fFlags & PATMFL_IDTHANDLER) 143 ADD_SZ("_IdtHandler"); 144 if (fFlags & PATMFL_TRAPHANDLER) 145 ADD_SZ("_TrapHandler"); 146 if (fFlags & PATMFL_DUPLICATE_FUNCTION) 147 ADD_SZ("_DupFunc"); 148 if (fFlags & PATMFL_REPLACE_FUNCTION_CALL) 149 ADD_SZ("_ReplFunc"); 150 if (fFlags & PATMFL_TRAPHANDLER_WITH_ERRORCODE) 151 ADD_SZ("_TrapHandlerErrCd"); 152 if (fFlags & PATMFL_MMIO_ACCESS) 153 ADD_SZ("_MmioAccess"); 154 if (fFlags & PATMFL_SYSENTER_XP) 155 ADD_SZ("_SysEnterXP"); 156 if (fFlags & PATMFL_INT3_REPLACEMENT) 157 ADD_SZ("_Int3Replacement"); 158 if (fFlags & PATMFL_SUPPORT_CALLS) 159 ADD_SZ("_SupportCalls"); 160 if (fFlags & PATMFL_SUPPORT_INDIRECT_CALLS) 161 ADD_SZ("_SupportIndirectCalls"); 162 if (fFlags & PATMFL_IDTHANDLER_WITHOUT_ENTRYPOINT) 163 ADD_SZ("_IdtHandlerWE"); 164 if (fFlags & PATMFL_INHIBIT_IRQS) 165 ADD_SZ("_InhibitIrqs"); 166 if (fFlags & PATMFL_RECOMPILE_NEXT) 167 ADD_SZ("_RecompileNext"); 168 if (fFlags & PATMFL_CALLABLE_AS_FUNCTION) 169 ADD_SZ("_Callable"); 170 if (fFlags & PATMFL_TRAMPOLINE) 171 ADD_SZ("_Trampoline"); 172 if (fFlags & PATMFL_PATCHED_GUEST_CODE) 173 ADD_SZ("_PatchedGuestCode"); 174 if (fFlags & PATMFL_MUST_INSTALL_PATCHJMP) 175 ADD_SZ("_MustInstallPatchJmp"); 176 if (fFlags & PATMFL_INT3_REPLACEMENT_BLOCK) 177 ADD_SZ("_Int3ReplacementBlock"); 178 if (fFlags & PATMFL_EXTERNAL_JUMP_INSIDE) 179 ADD_SZ("_ExtJmp"); 180 if (fFlags & PATMFL_CODE_REFERENCED) 181 ADD_SZ("_CodeRefed"); 182 183 /* If we have a symbol near the guest address, append that. */ 184 if (cbLeft > 8) 185 { 186 DBGFSYMBOL Symbol; 187 RTGCINTPTR offDisp; 188 189 rc = DBGFR3SymbolByAddr(pVM, pPatchRec->patch.pPrivInstrGC, &offDisp, &Symbol); 190 if (RT_SUCCESS(rc)) 191 { 192 ADD_SZ("__"); 193 RTStrCopy(pszName, cbLeft, Symbol.szName); 194 } 195 } 196 197 /* Add it (may fail due to enable/disable patches). */ 198 RTDbgModSymbolAdd(pVM->patm.s.hDbgModPatchMem, szName, 0 /*iSeg*/, 199 pPatchRec->patch.pPatchBlockOffset, 200 pPatchRec->patch.cbPatchBlockSize, 201 0 /*fFlags*/, NULL /*piOrdinal*/); 202 203 } 204 } 205 206 207 /** 208 * Enumeration callback used by patmR3DbgAddPatches 209 * 210 * @returns 0 (continue enum) 211 * @param pNode The patch record node. 212 * @param pvUser The cross context VM structure. 213 */ 214 static DECLCALLBACK(int) patmR3DbgAddPatchCallback(PAVLOU32NODECORE pNode, void *pvUser) 215 { 216 patmR3DbgAddPatch((PVM)pvUser, (PPATMPATCHREC)pNode); 217 return 0; 218 } 219 220 221 /** 222 * Populates an empty "patches" (hDbgModPatchMem) module with patch symbols. 223 * 224 * @param pVM The cross context VM structure. 225 * @param hDbgMod The debug module handle. 226 */ 227 static void patmR3DbgAddPatches(PVM pVM, RTDBGMOD hDbgMod) 228 { 229 /* 230 * Global functions. 231 */ 232 ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperCallGC, PATMLookupAndCallRecord.size, "PATMLookupAndCall"); 233 ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperRetGC, PATMRetFunctionRecord.size, "PATMRetFunction"); 234 ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperJumpGC, PATMLookupAndJumpRecord.size, "PATMLookupAndJump"); 235 ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperIretGC, PATMIretFunctionRecord.size, "PATMIretFunction"); 236 237 /* 238 * The patches. 239 */ 240 RTAvloU32DoWithAll(&pVM->patm.s.PatchLookupTreeHC->PatchTree, true /*fFromLeft*/, patmR3DbgAddPatchCallback, pVM); 241 } 71 242 72 243 … … 120 291 if (RT_SUCCESS(rc)) 121 292 { 122 /** @todo add global functions and all existing patches. */ 123 124 rc = RTDbgAsModuleLink(hDbgAs, hDbgMod, pVM->patm.s.pGCStateGC, 0 /*fFlags/*/); 293 pVM->patm.s.hDbgModPatchMem = hDbgMod; 294 patmR3DbgAddPatches(pVM, hDbgMod); 295 296 rc = RTDbgAsModuleLink(hDbgAs, hDbgMod, pVM->patm.s.pPatchMemGC, 0 /*fFlags/*/); 125 297 AssertLogRelRC(rc); 126 pVM->patm.s.hDbgModPatchMem = hDbgMod; 127 } 128 } 129 130 298 } 299 } 300 301 -
trunk/src/VBox/VMM/include/PATMInternal.h
r46135 r46150 657 657 void patmR3DbgTerm(PVM pVM); 658 658 void patmR3DbgReset(PVM pVM); 659 //void patmR3DbgNewPatch(PVM pVM,);660 661 #endif 659 void patmR3DbgAddPatch(PVM pVM, PPATMPATCHREC pPatchRec); 660 661 #endif
Note:
See TracChangeset
for help on using the changeset viewer.