Changeset 41671 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Jun 12, 2012 3:22:43 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 78478
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/CPUM.cpp
r41658 r41671 3676 3676 uint32_t cbInstr; 3677 3677 #ifndef LOG_ENABLED 3678 rc = DIS InstrWithReader(GCPtrPC, enmDisCpuMode, cpumR3DisasInstrRead, &State, pCpu, &cbInstr, NULL);3678 rc = DISCoreOneWithReader(GCPtrPC, enmDisCpuMode, cpumR3DisasInstrRead, &State, pCpu, &cbInstr); 3679 3679 if (RT_SUCCESS(rc)) 3680 3680 { 3681 3681 #else 3682 3682 char szOutput[160]; 3683 rc = DISInstrWithReader(GCPtrPC, enmDisCpuMode, cpumR3DisasInstrRead, &State, pCpu, &cbInstr, szOutput); 3683 rc = DISInstrToStrWithReader(GCPtrPC, enmDisCpuMode, cpumR3DisasInstrRead, &State, 3684 pCpu, &cbInstr, szOutput, sizeof(szOutput)); 3684 3685 if (RT_SUCCESS(rc)) 3685 3686 { -
trunk/src/VBox/VMM/VMMR3/CSAM.cpp
r41662 r41671 762 762 763 763 DECLINLINE(int) CSAMR3DISInstr(PVM pVM, RTRCPTR InstrGC, uint8_t *InstrHC, DISCPUMODE enmCpuMode, 764 PDISCPUSTATE pCpu, uint32_t *pcbInstr, char *pszOutput )764 PDISCPUSTATE pCpu, uint32_t *pcbInstr, char *pszOutput, size_t cbOutput) 765 765 { 766 766 (pCpu)->apvUserData[1] = InstrHC; 767 767 (pCpu)->apvUserData[2] = (void *)(uintptr_t)InstrGC; Assert(sizeof(InstrGC) <= sizeof(pCpu->apvUserData[0])); 768 768 #ifdef DEBUG 769 return DISInstr Ex(InstrGC, 0, enmCpuMode, CSAMR3ReadBytes, pVM, OPTYPE_ALL,770 pCpu, pcbInstr, pszOutput);769 return DISInstrToStrEx(InstrGC, enmCpuMode, CSAMR3ReadBytes, pVM, OPTYPE_ALL, 770 pCpu, pcbInstr, pszOutput, cbOutput); 771 771 #else 772 772 /* We are interested in everything except harmless stuff */ 773 return DISInstrEx(InstrGC, 0, enmCpuMode, CSAMR3ReadBytes, pVM, ~(OPTYPE_INVALID | OPTYPE_HARMLESS | OPTYPE_RRM_MASK), 774 pCpu, pcbInstr, pszOutput); 773 if (pszOutput) 774 return DISInstrToStrEx(InstrGC, enmCpuMode, CSAMR3ReadBytes, pVM, ~(OPTYPE_INVALID | OPTYPE_HARMLESS | OPTYPE_RRM_MASK), 775 pCpu, pcbInstr, pszOutput, cbOutput); 776 return DISCoreOneExEx(InstrGC, enmCpuMode, CSAMR3ReadBytes, pVM, ~(OPTYPE_INVALID | OPTYPE_HARMLESS | OPTYPE_RRM_MASK), 777 pCpu, pcbInstr); 775 778 #endif 776 779 } … … 869 872 870 873 rc = CSAMR3DISInstr(pVM, pCurInstrGC, pCurInstrHC, (fCode32) ? CPUMODE_32BIT : CPUMODE_16BIT, 871 &cpu, &opsize, NULL );874 &cpu, &opsize, NULL, 0); 872 875 } 873 876 AssertRC(rc); … … 1052 1055 #ifdef DEBUG 1053 1056 rc2 = CSAMR3DISInstr(pVM, pCurInstrGC, pCurInstrHC, (fCode32) ? CPUMODE_32BIT : CPUMODE_16BIT, 1054 &cpu, &opsize, szOutput );1057 &cpu, &opsize, szOutput, sizeof(szOutput)); 1055 1058 if (RT_SUCCESS(rc2)) Log(("CSAM Call Analysis: %s", szOutput)); 1056 1059 #else 1057 1060 rc2 = CSAMR3DISInstr(pVM, pCurInstrGC, pCurInstrHC, (fCode32) ? CPUMODE_32BIT : CPUMODE_16BIT, 1058 &cpu, &opsize, NULL );1061 &cpu, &opsize, NULL, 0); 1059 1062 #endif 1060 1063 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeDisasm, a); … … 1265 1268 #ifdef DEBUG 1266 1269 rc2 = CSAMR3DISInstr(pVM, pCurInstrGC, pCurInstrHC, fCode32 ? CPUMODE_32BIT : CPUMODE_16BIT, 1267 &cpu, &opsize, szOutput );1270 &cpu, &opsize, szOutput, sizeof(szOutput)); 1268 1271 if (RT_SUCCESS(rc2)) Log(("CSAM Analysis: %s", szOutput)); 1269 1272 #else 1270 1273 rc2 = CSAMR3DISInstr(pVM, pCurInstrGC, pCurInstrHC, fCode32 ? CPUMODE_32BIT : CPUMODE_16BIT, 1271 &cpu, &opsize, NULL );1274 &cpu, &opsize, NULL, 0); 1272 1275 #endif 1273 1276 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeDisasm, a); -
trunk/src/VBox/VMM/VMMR3/PATM.cpp
r41663 r41671 69 69 70 70 71 #define PATMREAD_RAWCODE 1 /* read code as-is */ 72 #define PATMREAD_ORGCODE 2 /* read original guest opcode bytes; not the patched bytes */ 73 #define PATMREAD_NOCHECK 4 /* don't check for patch conflicts */ 74 75 /* 76 * Private structure used during disassembly 77 */ 78 typedef struct 79 { 80 PVM pVM; 81 PPATCHINFO pPatchInfo; 82 R3PTRTYPE(uint8_t *) pInstrHC; 83 RTRCPTR pInstrGC; 84 uint32_t fReadFlags; 85 } PATMDISASM, *PPATMDISASM; 86 87 71 88 /******************************************************************************* 72 89 * Internal Functions * … … 576 593 } 577 594 595 596 DECLINLINE(bool) patmR3DisInstrToStr(PVM pVM, PPATCHINFO pPatch, RTGCPTR32 InstrGCPtr32, uint8_t *pbInstrHC, uint32_t fReadFlags, 597 PDISCPUSTATE pCpu, uint32_t *pcbInstr, char *pszOutput, size_t cbOutput) 598 { 599 PATMDISASM disinfo; 600 disinfo.pVM = pVM; 601 disinfo.pPatchInfo = pPatch; 602 disinfo.pInstrHC = pbInstrHC; 603 disinfo.pInstrGC = InstrGCPtr32; 604 disinfo.fReadFlags = fReadFlags; 605 (pCpu)->pfnReadBytes = patmReadBytes; 606 (pCpu)->apvUserData[0] = &disinfo; 607 return RT_SUCCESS(DISInstrToStrWithReader(InstrGCPtr32, 608 (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT, 609 patmReadBytes, &disinfo, 610 pCpu, pcbInstr, pszOutput, cbOutput)); 611 } 612 613 614 DECLINLINE(bool) patmR3DisInstr(PVM pVM, PPATCHINFO pPatch, RTGCPTR32 InstrGCPtr32, uint8_t *pbInstrHC, uint32_t fReadFlags, 615 PDISCPUSTATE pCpu, uint32_t *pcbInstr) 616 { 617 PATMDISASM disinfo; 618 disinfo.pVM = pVM; 619 disinfo.pPatchInfo = pPatch; 620 disinfo.pInstrHC = pbInstrHC; 621 disinfo.pInstrGC = InstrGCPtr32; 622 disinfo.fReadFlags = fReadFlags; 623 (pCpu)->pfnReadBytes = patmReadBytes; 624 (pCpu)->apvUserData[0] = &disinfo; 625 return RT_SUCCESS(DISCoreOneWithReader(InstrGCPtr32, 626 (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT, 627 patmReadBytes, &disinfo, 628 pCpu, pcbInstr)); 629 } 630 631 632 DECLINLINE(bool) patmR3DisInstrNoStrOpMode(PVM pVM, PPATCHINFO pPatch, RTGCPTR32 InstrGCPtr32, uint8_t *pbInstrHC, 633 uint32_t fReadFlags, 634 PDISCPUSTATE pCpu, uint32_t *pcbInstr) 635 { 636 PATMDISASM disinfo; 637 disinfo.pVM = pVM; 638 disinfo.pPatchInfo = pPatch; 639 disinfo.pInstrHC = pbInstrHC; 640 disinfo.pInstrGC = InstrGCPtr32; 641 disinfo.fReadFlags = fReadFlags; 642 (pCpu)->pfnReadBytes = patmReadBytes; 643 (pCpu)->apvUserData[0] = &disinfo; 644 return RT_SUCCESS(DISCoreOneWithReader(InstrGCPtr32, pPatch->uOpMode, patmReadBytes, &disinfo, 645 pCpu, pcbInstr)); 646 } 647 648 #ifdef LOG_ENABLED 649 # define PATM_LOG_ORG_PATCH_INSTR(a_pVM, a_pPatch, a_szComment) \ 650 PATM_LOG_PATCH_INSTR(a_pVM, a_pPatch, PATMREAD_ORGCODE, a_szComment, " patch:") 651 # define PATM_LOG_RAW_PATCH_INSTR(a_pVM, a_pPatch, a_szComment) \ 652 PATM_LOG_PATCH_INSTR(a_pVM, a_pPatch, PATMREAD_RAWCODE, a_szComment, " patch:") 653 654 # define PATM_LOG_PATCH_INSTR(a_pVM, a_pPatch, a_fFlags, a_szComment1, a_szComment2) \ 655 do { \ 656 if (LogIsEnabled()) \ 657 patmLogRawPatchInstr(a_pVM, a_pPatch, a_fFlags, a_szComment1, a_szComment2); \ 658 } while (0) 659 660 static void patmLogRawPatchInstr(PVM pVM, PPATCHINFO pPatch, uint32_t fFlags, 661 const char *pszComment1, const char *pszComment2) 662 { 663 DISCPUSTATE DisState; 664 char szOutput[128]; 665 szOutput[0] = '\0'; 666 patmR3DisInstrToStr(pVM, pPatch, pPatch->pPrivInstrGC, NULL, fFlags, 667 &DisState, NULL, szOutput, sizeof(szOutput)); 668 Log(("%s%s %s", pszComment1, pszComment2, szOutput)); 669 } 670 671 #else 672 # define PATM_LOG_ORG_PATCH_INSTR(a_pVM, a_pPatch, a_szComment) do { } while (0) 673 # define PATM_LOG_RAW_PATCH_INSTR(a_pVM, a_pPatch, a_szComment) do { } while (0) 674 # define PATM_LOG_PATCH_INSTR(a_pVM, a_pPatch, a_fFlags, a_szComment1, a_szComment2) do { } while (0) 675 #endif 676 677 578 678 /** 579 679 * Callback function for RTAvloU32DoWithAll … … 590 690 PVM pVM = (PVM)pParam; 591 691 RTRCINTPTR delta; 592 #ifdef LOG_ENABLED593 DISCPUSTATE cpu;594 char szOutput[256];595 uint32_t opsize;596 bool disret;597 #endif598 692 int rc; 599 693 … … 602 696 return 0; 603 697 604 #ifdef LOG_ENABLED605 698 if (pPatch->patch.flags & PATMFL_PATCHED_GUEST_CODE) 606 { 607 cpu.mode = (pPatch->patch.flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 608 disret = PATMR3DISInstr(pVM, &pPatch->patch, &cpu, pPatch->patch.pPrivInstrGC, NULL, &opsize, szOutput, PATMREAD_RAWCODE); 609 Log(("Org patch jump: %s", szOutput)); 610 } 611 #endif 699 PATM_LOG_PATCH_INSTR(pVM, &pPatch->patch, PATMREAD_RAWCODE, "Org patch jump:", ""); 612 700 613 701 Log(("Nr of fixups %d\n", pPatch->patch.nrFixups)); … … 786 874 } 787 875 788 #ifdef LOG_ENABLED789 876 if (pPatch->patch.flags & PATMFL_PATCHED_GUEST_CODE) 790 { 791 cpu.mode = (pPatch->patch.flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 792 disret = PATMR3DISInstr(pVM, &pPatch->patch, &cpu, pPatch->patch.pPrivInstrGC, NULL, &opsize, szOutput, PATMREAD_RAWCODE); 793 Log(("Rel patch jump: %s", szOutput)); 794 } 795 #endif 877 PATM_LOG_PATCH_INSTR(pVM, &pPatch->patch, PATMREAD_RAWCODE, "Rel patch jump:", ""); 796 878 return 0; 797 879 } … … 1738 1820 1739 1821 // Disassemble the next instruction 1740 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pNextInstrGC, pNextInstrHC, &opsize, NULL);1822 disret = patmR3DisInstr(pVM, pPatch, pNextInstrGC, pNextInstrHC, PATMREAD_ORGCODE, &cpu, &opsize); 1741 1823 } 1742 1824 if (disret == false) … … 2052 2134 uint32_t dummy; 2053 2135 2054 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;2055 2136 pOrgJumpGC = patmPatchGCPtr2GuestGCPtr(pVM, pPatch, pCurInstrGC); 2056 2137 … … 2058 2139 uint8_t *pOrgJumpHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pOrgJumpGC); 2059 2140 2060 bool disret = PATMR3DISInstr(pVM, pPatch, &cpu, pOrgJumpGC, pOrgJumpHC, &dummy, NULL);2141 bool disret = patmR3DisInstr(pVM, pPatch, pOrgJumpGC, pOrgJumpHC, PATMREAD_ORGCODE, &cpu, NULL); 2061 2142 if (!disret || cpu.pCurInstr->opcode != OP_CALL || cpu.param1.cb != 4 /* only near calls */) 2062 2143 return VINF_SUCCESS; … … 2115 2196 delta = pVM->patm.s.pPatchMemGC - (uintptr_t)pVM->patm.s.pPatchMemHC; 2116 2197 2117 while(rc == VWRN_CONTINUE_ANALYSIS) 2118 { 2119 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 2120 2198 while (rc == VWRN_CONTINUE_ANALYSIS) 2199 { 2121 2200 pCurInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC); 2122 2201 if (pCurInstrHC == NULL) … … 2126 2205 } 2127 2206 2128 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pCurInstrGC, pCurInstrHC, &opsize, szOutput, PATMREAD_RAWCODE); 2207 disret = patmR3DisInstrToStr(pVM, pPatch, pCurInstrGC, pCurInstrHC, PATMREAD_RAWCODE, 2208 &cpu, &opsize, szOutput, sizeof(szOutput)); 2129 2209 if (PATMIsPatchGCAddr(pVM, pCurInstrGC)) 2130 2210 { … … 2285 2365 while (rc == VWRN_CONTINUE_RECOMPILE) 2286 2366 { 2287 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;2288 2289 2367 pCurInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC); 2290 2368 if (pCurInstrHC == NULL) … … 2294 2372 } 2295 2373 #ifdef LOG_ENABLED 2296 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pCurInstrGC, pCurInstrHC, &opsize, szOutput); 2374 disret = patmR3DisInstrToStr(pVM, pPatch, pCurInstrGC, pCurInstrHC, PATMREAD_ORGCODE, 2375 &cpu, &opsize, szOutput, sizeof(szOutput)); 2297 2376 Log(("Recompile: %s", szOutput)); 2298 2377 #else 2299 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pCurInstrGC, pCurInstrHC, &opsize, NULL);2378 disret = patmR3DisInstr(pVM, pPatch, pCurInstrGC, pCurInstrHC, PATMREAD_ORGCODE, &cpu, &opsize); 2300 2379 #endif 2301 2380 if (disret == false) … … 2333 2412 goto end; 2334 2413 } 2335 cpunext.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 2336 disret = PATMR3DISInstr(pVM, pPatch, &cpunext, pNextInstrGC, pNextInstrHC, &opsizenext, NULL); 2414 disret = patmR3DisInstr(pVM, pPatch, pNextInstrGC, pNextInstrHC, PATMREAD_ORGCODE, &cpunext, &opsizenext); 2337 2415 if (disret == false) 2338 2416 { … … 2565 2643 while (i < pPatch->cbPrivInstr) 2566 2644 { 2567 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;2568 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pPatch->pPrivInstrGC + i, NULL, &opsize, szOutput);2645 disret = patmR3DisInstrToStr(pVM, pPatch, pPatch->pPrivInstrGC + i, NULL, PATMREAD_ORGCODE, 2646 &cpu, &opsize, szOutput, sizeof(szOutput)); 2569 2647 if (disret == false) 2570 2648 break; … … 2582 2660 { 2583 2661 i = 0; 2584 while (i < pPatch->cbPrivInstr)2585 { 2586 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;2587 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pPatch->pPrivInstrGC + i, NULL, &opsize, szOutput);2662 while (i < pPatch->cbPrivInstr) 2663 { 2664 disret = patmR3DisInstrToStr(pVM, pPatch, pPatch->pPrivInstrGC + i, NULL, PATMREAD_ORGCODE, 2665 &cpu, &opsize, szOutput, sizeof(szOutput)); 2588 2666 if (disret == false) 2589 2667 break; … … 2661 2739 PPATCHINFO pPatch = &pPatchRec->patch; 2662 2740 int rc = VERR_PATCHING_REFUSED; 2663 DISCPUSTATE cpu;2664 2741 uint32_t orgOffsetPatchMem = ~0; 2665 2742 RTRCPTR pInstrStart; 2666 2743 bool fInserted; 2667 #ifdef LOG_ENABLED2668 uint32_t opsize;2669 char szOutput[256];2670 bool disret;2671 #endif2672 2744 NOREF(pInstrHC); NOREF(uOpSize); 2673 2745 … … 2720 2792 pPatch->pPatchBlockOffset = pVM->patm.s.offPatchMem; 2721 2793 pPatch->uCurPatchOffset = 0; 2722 2723 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;2724 2794 2725 2795 if ((pPatch->flags & (PATMFL_IDTHANDLER|PATMFL_IDTHANDLER_WITHOUT_ENTRYPOINT|PATMFL_SYSENTER)) == PATMFL_IDTHANDLER) … … 2848 2918 } 2849 2919 2850 #ifdef LOG_ENABLED 2851 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 2852 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pPatch->pPrivInstrGC, NULL, &opsize, szOutput, PATMREAD_RAWCODE); 2853 Log(("%s patch: %s", patmGetInstructionString(pPatch->opcode, pPatch->flags), szOutput)); 2854 #endif 2920 PATM_LOG_RAW_PATCH_INSTR(pVM, pPatch, patmGetInstructionString(pPatch->opcode, pPatch->flags)); 2855 2921 2856 2922 patmEmptyTree(pVM, &pPatch->pTempInfo->IllegalInstrTree); … … 2917 2983 * condition here and only patch the common entypoint once. 2918 2984 */ 2919 cpuPush.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 2920 disret = PATMR3DISInstr(pVM, pPatch, &cpuPush, pCurInstrGC, pCurInstrHC, &opsize, NULL); 2985 disret = patmR3DisInstr(pVM, pPatch, pCurInstrGC, pCurInstrHC, PATMREAD_ORGCODE, &cpuPush, &opsize); 2921 2986 Assert(disret); 2922 2987 if (disret && cpuPush.pCurInstr->opcode == OP_PUSH) … … 2926 2991 pCurInstrGC += opsize; 2927 2992 2928 cpuJmp.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 2929 disret = PATMR3DISInstr(pVM, pPatch, &cpuJmp, pCurInstrGC, pCurInstrHC, &opsize, NULL); 2993 disret = patmR3DisInstr(pVM, pPatch, pCurInstrGC, pCurInstrHC, PATMREAD_ORGCODE, &cpuJmp, &opsize); 2930 2994 if ( disret 2931 2995 && cpuJmp.pCurInstr->opcode == OP_JMP … … 3034 3098 uint32_t orgOffsetPatchMem = ~0; 3035 3099 bool fInserted; 3036 #ifdef LOG_ENABLED3037 bool disret;3038 DISCPUSTATE cpu;3039 uint32_t opsize;3040 char szOutput[256];3041 #endif3042 3100 3043 3101 // save original offset (in case of failures later on) … … 3074 3132 Log(("Patch code ends -----------------------------------------------------\n")); 3075 3133 #endif 3076 3077 #ifdef LOG_ENABLED 3078 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 3079 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pPatch->pPrivInstrGC, NULL, &opsize, szOutput); 3080 Log(("TRAP handler patch: %s", szOutput)); 3081 #endif 3134 PATM_LOG_ORG_PATCH_INSTR(pVM, pPatch, "TRAP handler"); 3082 3135 Log(("Successfully installed Trap Trampoline patch at %RRv\n", pInstrGC)); 3083 3136 … … 3561 3614 break; 3562 3615 3563 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 3564 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pTargetGC, pTmpInstrHC, &opsize, NULL); 3616 disret = patmR3DisInstr(pVM, pPatch, pTargetGC, pTmpInstrHC, PATMREAD_ORGCODE, &cpu, &opsize); 3565 3617 if (disret == false || cpu.pCurInstr->opcode != OP_JMP) 3566 3618 break; … … 3598 3650 pPatch->pInstrGCLowest = pInstrGC; 3599 3651 pPatch->pInstrGCHighest = pInstrGC + pCpu->opsize; 3600 3601 #ifdef LOG_ENABLED 3602 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 3603 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pPatch->pPrivInstrGC, NULL, &opsize, szOutput); 3604 Log(("Call patch: %s", szOutput)); 3605 #endif 3652 PATM_LOG_ORG_PATCH_INSTR(pVM, pPatch, "Call"); 3606 3653 3607 3654 Log(("Successfully installed function replacement patch at %RRv\n", pInstrGC)); … … 3634 3681 uint8_t *pPB; 3635 3682 int rc = VERR_PATCHING_REFUSED; 3636 #ifdef LOG_ENABLED3637 DISCPUSTATE cpu;3638 uint32_t opsize;3639 bool disret;3640 char szOutput[256];3641 #endif3642 3683 3643 3684 Assert(pVM->patm.s.mmio.pCachedData); … … 3658 3699 return VERR_PATCHING_REFUSED; 3659 3700 } 3660 #ifdef LOG_ENABLED 3661 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 3662 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pPatch->pPrivInstrGC, NULL, &opsize, szOutput); 3663 Log(("MMIO patch old instruction: %s", szOutput)); 3664 #endif 3701 PATM_LOG_PATCH_INSTR(pVM, pPatch, PATMREAD_ORGCODE, "MMIO patch old instruction:", ""); 3665 3702 3666 3703 /* Save original instruction. */ … … 3678 3715 } 3679 3716 3680 #ifdef LOG_ENABLED 3681 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 3682 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pPatch->pPrivInstrGC, NULL, &opsize, szOutput); 3683 Log(("MMIO patch: %s", szOutput)); 3684 #endif 3717 PATM_LOG_ORG_PATCH_INSTR(pVM, pPatch, "MMIO"); 3685 3718 pVM->patm.s.mmio.pCachedData = 0; 3686 3719 pVM->patm.s.mmio.GCPhys = 0; … … 3713 3746 bool disret; 3714 3747 uint8_t *pInstrHC; 3715 #ifdef LOG_ENABLED3716 char szOutput[256];3717 #endif3718 3748 3719 3749 AssertReturn(pVM->patm.s.mmio.pCachedData, VERR_INVALID_PARAMETER); … … 3724 3754 3725 3755 /* Disassemble mmio instruction. */ 3726 cpu.mode = pPatch->uOpMode;3727 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pInstrGC, pInstrHC, &opsize, NULL);3756 disret = patmR3DisInstrNoStrOpMode(pVM, pPatch, pInstrGC, pInstrHC, PATMREAD_ORGCODE, 3757 &cpu, &opsize); 3728 3758 if (disret == false) 3729 3759 { … … 3751 3781 pPatch->pInstrGCHighest = pInstrGC + cpu.opsize; 3752 3782 3753 #ifdef LOG_ENABLED 3754 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 3755 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pInstrGC, pInstrHC, &opsize, szOutput); 3756 Log(("MMIO patch: %s", szOutput)); 3757 #endif 3758 3783 PATM_LOG_ORG_PATCH_INSTR(pVM, pPatch, "MMIO"); 3759 3784 pVM->patm.s.mmio.pCachedData = 0; 3760 3785 pVM->patm.s.mmio.GCPhys = 0; … … 3828 3853 3829 3854 /* Note: Do not use patch memory here! It might called during patch installation too. */ 3830 3831 #ifdef LOG_ENABLED 3832 DISCPUSTATE cpu; 3833 char szOutput[256]; 3834 uint32_t opsize; 3835 3836 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 3837 PATMR3DISInstr(pVM, pPatch, &cpu, pInstrGC, pInstrHC, &opsize, szOutput); 3838 Log(("PATMR3PatchInstrInt3: %s", szOutput)); 3839 #endif 3855 PATM_LOG_PATCH_INSTR(pVM, pPatch, PATMREAD_ORGCODE, "PATMR3PatchInstrInt3:", ""); 3840 3856 3841 3857 /* Save the original instruction. */ … … 3881 3897 PPATCHINFO pPatch = &pPatchRec->patch; 3882 3898 int rc = VERR_PATCHING_REFUSED; 3883 #ifdef LOG_ENABLED3884 bool disret;3885 DISCPUSTATE cpu;3886 uint32_t opsize;3887 char szOutput[256];3888 #endif3889 3899 3890 3900 pPatch->pPatchBlockOffset = 0; /* doesn't use patch memory */ … … 3974 3984 pPatch->flags |= PATMFL_MUST_INSTALL_PATCHJMP; 3975 3985 3976 #ifdef LOG_ENABLED 3977 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 3978 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pPatch->pPrivInstrGC, NULL, &opsize, szOutput); 3979 Log(("%s patch: %s", patmGetInstructionString(pPatch->opcode, pPatch->flags), szOutput)); 3980 #endif 3981 3986 PATM_LOG_ORG_PATCH_INSTR(pVM, pPatch, patmGetInstructionString(pPatch->opcode, pPatch->flags)); 3982 3987 Log(("Successfully installed %s patch at %RRv\n", patmGetInstructionString(pPatch->opcode, pPatch->flags), pInstrGC)); 3983 3988 … … 4247 4252 } 4248 4253 4249 cpu.mode = pPatchRec->patch.uOpMode; 4250 disret = PATMR3DISInstr(pVM, &pPatchRec->patch, &cpu, pInstrGC, NULL, &opsize, NULL); 4254 disret = patmR3DisInstrNoStrOpMode(pVM, &pPatchRec->patch, pInstrGC, NULL, PATMREAD_ORGCODE, &cpu, &opsize); 4251 4255 if (disret == false) 4252 4256 { … … 4501 4505 uint32_t opsize; 4502 4506 4503 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 4504 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pInstrGC, pInstrHC, &opsize, NULL, PATMREAD_ORGCODE | PATMREAD_NOCHECK); 4507 disret = patmR3DisInstr(pVM, pPatch, pInstrGC, pInstrHC, PATMREAD_ORGCODE | PATMREAD_NOCHECK, &cpu, &opsize); 4505 4508 PGMPhysReleasePageMappingLock(pVM, &Lock); 4506 4509 if (disret) … … 5200 5203 RT_ZERO(patch); 5201 5204 pInstrHC = PATMGCVirtToHCVirt(pVM, &patch, pInstrGC); 5202 cpu.mode = (pConflictPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 5203 disret = PATMR3DISInstr(pVM, &patch, &cpu, pInstrGC, pInstrHC, &opsize, NULL); 5205 disret = patmR3DisInstr(pVM, &patch, pInstrGC, pInstrHC, PATMREAD_ORGCODE, &cpu, &opsize); 5204 5206 /* 5205 5207 * If it's a 5 byte relative jump, then we can work around the problem by replacing the 32 bits relative offset … … 5343 5345 DISCPUSTATE cpu; 5344 5346 char szOutput[256]; 5345 uint32_t opsize, i = 0; 5347 uint32_t opsize; 5348 uint32_t i = 0; 5346 5349 bool disret; 5347 i = 0;5348 5350 while(i < pPatch->cbPatchJump) 5349 5351 { 5350 cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;5351 disret = PATMR3DISInstr(pVM, pPatch, &cpu, pPatch->pPrivInstrGC + i, NULL, &opsize, szOutput);5352 disret = patmR3DisInstrToStr(pVM, pPatch, pPatch->pPrivInstrGC + i, NULL, PATMREAD_ORGCODE, 5353 &cpu, &opsize, szOutput, sizeof(szOutput)); 5352 5354 Log(("Renewed patch instr: %s", szOutput)); 5353 5355 i += opsize; … … 6415 6417 cacheRec.pPatch = &pPatch->patch; 6416 6418 6417 cpu.mode = (pPatch->patch.flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;6418 disret = PATMR3DISInstr(pVM, &pPatch->patch, &cpu, pNewEip, PATMGCVirtToHCVirt(pVM, &cacheRec, pNewEip), &opsize, NULL, PATMREAD_RAWCODE);6419 disret = patmR3DisInstr(pVM, &pPatch->patch, pNewEip, PATMGCVirtToHCVirt(pVM, &cacheRec, pNewEip), PATMREAD_RAWCODE, 6420 &cpu, &opsize); 6419 6421 if (cacheRec.Lock.pvMap) 6420 6422 PGMPhysReleasePageMappingLock(pVM, &cacheRec.Lock); … … 6454 6456 cacheRec.pPatch = &pPatch->patch; 6455 6457 6456 cpu.mode = (pPatch->patch.flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;6457 disret = PATMR3DISInstr(pVM, &pPatch->patch, &cpu, pNewEip, PATMGCVirtToHCVirt(pVM, &cacheRec, pNewEip), &opsize, NULL, PATMREAD_ORGCODE);6458 disret = patmR3DisInstr(pVM, &pPatch->patch, pNewEip, PATMGCVirtToHCVirt(pVM, &cacheRec, pNewEip), PATMREAD_ORGCODE, 6459 &cpu, &opsize); 6458 6460 if (cacheRec.Lock.pvMap) 6459 6461 PGMPhysReleasePageMappingLock(pVM, &cacheRec.Lock); … … 6462 6464 { 6463 6465 cpu.mode = (pPatch->patch.flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT; 6464 disret = PATMR3DISInstr(pVM, &pPatch->patch, &cpu, pNewEip, PATMGCVirtToHCVirt(pVM, &cacheRec, pNewEip), &opsize, NULL, PATMREAD_RAWCODE); 6466 disret = patmR3DisInstr(pVM, &pPatch->patch, pNewEip, PATMGCVirtToHCVirt(pVM, &cacheRec, pNewEip), PATMREAD_RAWCODE, 6467 &cpu, &opsize); 6465 6468 if (cacheRec.Lock.pvMap) 6466 6469 PGMPhysReleasePageMappingLock(pVM, &cacheRec.Lock); -
trunk/src/VBox/VMM/VMMR3/VMMSwitcher.cpp
r41658 r41671 814 814 */ 815 815 RTLogPrintf(" %s: offCode=%#x cbCode=%#x\n", pszDesc, offCode, cbCode); 816 DISCPUSTATE Cpu; 817 818 memset(&Cpu, 0, sizeof(Cpu)); 819 Cpu.mode = CPUMODE_32BIT; 816 820 817 while (cbCode > 0) 821 818 { … … 835 832 836 833 /* disas */ 837 uint32_t cbInstr = 0; 838 char szDisas[256]; 839 if (RT_SUCCESS(DISInstrWithOff(&Cpu, (uintptr_t)pu8CodeR3 + offCode, uBase - (uintptr_t)pu8CodeR3, 840 &cbInstr, szDisas))) 841 RTLogPrintf(" %04x: %s", offCode, szDisas); //for whatever reason szDisas includes '\n'. 834 uint32_t cbInstr = 0; 835 DISCPUSTATE Cpu; 836 char szDisas[256]; 837 int rc = DISCoreOne((uintptr_t)pu8CodeR3 + offCode, CPUMODE_32BIT, &Cpu, &cbInstr); 838 if (RT_SUCCESS(rc)) 839 { 840 Cpu.uInstrAddr += uBase - (uintptr_t)pu8CodeR3; 841 rc = DISFormatYasmEx(&Cpu, szDisas, sizeof(szDisas), 842 DIS_FMT_FLAGS_ADDR_LEFT | DIS_FMT_FLAGS_BYTES_LEFT | DIS_FMT_FLAGS_BYTES_SPACED 843 | DIS_FMT_FLAGS_RELATIVE_BRANCH, 844 NULL, NULL); 845 } 846 if (RT_SUCCESS(rc)) 847 RTLogPrintf(" %04x: %s\n", offCode, szDisas); 842 848 else 843 849 { 844 RTLogPrintf(" %04x: %02x '%c' \n",845 offCode, pu8CodeR3[offCode], RT_C_IS_PRINT(pu8CodeR3[offCode]) ? pu8CodeR3[offCode] : ' ' );850 RTLogPrintf(" %04x: %02x '%c' (rc=%Rrc\n", 851 offCode, pu8CodeR3[offCode], RT_C_IS_PRINT(pu8CodeR3[offCode]) ? pu8CodeR3[offCode] : ' ', rc); 846 852 cbInstr = 1; 847 853 } -
trunk/src/VBox/VMM/include/PATMInternal.h
r41658 r41671 678 678 679 679 680 #ifndef IN_RC681 682 #define PATMREAD_RAWCODE 1 /* read code as-is */683 #define PATMREAD_ORGCODE 2 /* read original guest opcode bytes; not the patched bytes */684 #define PATMREAD_NOCHECK 4 /* don't check for patch conflicts */685 686 /*687 * Private structure used during disassembly688 */689 typedef struct690 {691 PVM pVM;692 PPATCHINFO pPatchInfo;693 R3PTRTYPE(uint8_t *) pInstrHC;694 RTRCPTR pInstrGC;695 uint32_t fReadFlags;696 } PATMDISASM, *PPATMDISASM;697 698 DECLINLINE(bool) PATMR3DISInstr(PVM pVM, PPATCHINFO pPatch, PDISCPUSTATE pCpu, RTRCPTR InstrGC,699 uint8_t *InstrHC, uint32_t *pOpsize, char *pszOutput,700 uint32_t fReadFlags = PATMREAD_ORGCODE)701 {702 PATMDISASM disinfo;703 disinfo.pVM = pVM;704 disinfo.pPatchInfo = pPatch;705 disinfo.pInstrHC = InstrHC;706 disinfo.pInstrGC = InstrGC;707 disinfo.fReadFlags = fReadFlags;708 (pCpu)->pfnReadBytes = patmReadBytes;709 (pCpu)->apvUserData[0] = &disinfo;710 return RT_SUCCESS(DISInstrWithReader(InstrGC, pCpu->mode, patmReadBytes, &disinfo, pCpu, pOpsize, pszOutput));711 }712 #endif /* !IN_RC */713 714 680 RT_C_DECLS_BEGIN 715 681 /**
Note:
See TracChangeset
for help on using the changeset viewer.