VirtualBox

Changeset 41671 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Jun 12, 2012 3:22:43 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
78478
Message:

DISInstr* -> DISInstrToStr + cbOutput argument.

Location:
trunk/src/VBox/VMM
Files:
5 edited

Legend:

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

    r41658 r41671  
    36763676    uint32_t cbInstr;
    36773677#ifndef LOG_ENABLED
    3678     rc = DISInstrWithReader(GCPtrPC, enmDisCpuMode, cpumR3DisasInstrRead, &State, pCpu, &cbInstr, NULL);
     3678    rc = DISCoreOneWithReader(GCPtrPC, enmDisCpuMode, cpumR3DisasInstrRead, &State, pCpu, &cbInstr);
    36793679    if (RT_SUCCESS(rc))
    36803680    {
    36813681#else
    36823682    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));
    36843685    if (RT_SUCCESS(rc))
    36853686    {
  • trunk/src/VBox/VMM/VMMR3/CSAM.cpp

    r41662 r41671  
    762762
    763763DECLINLINE(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)
    765765{
    766766    (pCpu)->apvUserData[1] = InstrHC;
    767767    (pCpu)->apvUserData[2] = (void *)(uintptr_t)InstrGC; Assert(sizeof(InstrGC) <= sizeof(pCpu->apvUserData[0]));
    768768#ifdef DEBUG
    769     return DISInstrEx(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);
    771771#else
    772772    /* 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);
    775778#endif
    776779}
     
    869872
    870873                rc = CSAMR3DISInstr(pVM, pCurInstrGC, pCurInstrHC, (fCode32) ? CPUMODE_32BIT : CPUMODE_16BIT,
    871                                     &cpu, &opsize, NULL);
     874                                    &cpu, &opsize, NULL, 0);
    872875            }
    873876            AssertRC(rc);
     
    10521055#ifdef DEBUG
    10531056                rc2 = CSAMR3DISInstr(pVM, pCurInstrGC, pCurInstrHC, (fCode32) ? CPUMODE_32BIT : CPUMODE_16BIT,
    1054                                      &cpu, &opsize, szOutput);
     1057                                     &cpu, &opsize, szOutput, sizeof(szOutput));
    10551058                if (RT_SUCCESS(rc2)) Log(("CSAM Call Analysis: %s", szOutput));
    10561059#else
    10571060                rc2 = CSAMR3DISInstr(pVM, pCurInstrGC, pCurInstrHC, (fCode32) ? CPUMODE_32BIT : CPUMODE_16BIT,
    1058                                      &cpu, &opsize, NULL);
     1061                                     &cpu, &opsize, NULL, 0);
    10591062#endif
    10601063                STAM_PROFILE_STOP(&pVM->csam.s.StatTimeDisasm, a);
     
    12651268#ifdef DEBUG
    12661269            rc2 = CSAMR3DISInstr(pVM, pCurInstrGC, pCurInstrHC, fCode32 ? CPUMODE_32BIT : CPUMODE_16BIT,
    1267                                  &cpu, &opsize, szOutput);
     1270                                 &cpu, &opsize, szOutput, sizeof(szOutput));
    12681271            if (RT_SUCCESS(rc2)) Log(("CSAM Analysis: %s", szOutput));
    12691272#else
    12701273            rc2 = CSAMR3DISInstr(pVM, pCurInstrGC, pCurInstrHC, fCode32 ? CPUMODE_32BIT : CPUMODE_16BIT,
    1271                                  &cpu, &opsize, NULL);
     1274                                 &cpu, &opsize, NULL, 0);
    12721275#endif
    12731276            STAM_PROFILE_STOP(&pVM->csam.s.StatTimeDisasm, a);
  • trunk/src/VBox/VMM/VMMR3/PATM.cpp

    r41663 r41671  
    6969
    7070
     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 */
     78typedef 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
    7188/*******************************************************************************
    7289*   Internal Functions                                                         *
     
    576593}
    577594
     595
     596DECLINLINE(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
     614DECLINLINE(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
     632DECLINLINE(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
     660static 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
    578678/**
    579679 * Callback function for RTAvloU32DoWithAll
     
    590690    PVM             pVM = (PVM)pParam;
    591691    RTRCINTPTR      delta;
    592 #ifdef LOG_ENABLED
    593     DISCPUSTATE     cpu;
    594     char            szOutput[256];
    595     uint32_t        opsize;
    596     bool            disret;
    597 #endif
    598692    int             rc;
    599693
     
    602696        return 0;
    603697
    604 #ifdef LOG_ENABLED
    605698    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:", "");
    612700
    613701    Log(("Nr of fixups %d\n", pPatch->patch.nrFixups));
     
    786874    }
    787875
    788 #ifdef LOG_ENABLED
    789876    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:", "");
    796878    return 0;
    797879}
     
    17381820
    17391821                // 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);
    17411823            }
    17421824            if (disret == false)
     
    20522134        uint32_t    dummy;
    20532135
    2054         cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;
    20552136        pOrgJumpGC = patmPatchGCPtr2GuestGCPtr(pVM, pPatch, pCurInstrGC);
    20562137
     
    20582139            uint8_t *pOrgJumpHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pOrgJumpGC);
    20592140
    2060             bool disret = PATMR3DISInstr(pVM, pPatch, &cpu, pOrgJumpGC, pOrgJumpHC, &dummy, NULL);
     2141            bool disret = patmR3DisInstr(pVM, pPatch, pOrgJumpGC, pOrgJumpHC, PATMREAD_ORGCODE, &cpu, NULL);
    20612142            if (!disret || cpu.pCurInstr->opcode != OP_CALL || cpu.param1.cb != 4 /* only near calls */)
    20622143                return VINF_SUCCESS;
     
    21152196    delta = pVM->patm.s.pPatchMemGC - (uintptr_t)pVM->patm.s.pPatchMemHC;
    21162197
    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    {
    21212200        pCurInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
    21222201        if (pCurInstrHC == NULL)
     
    21262205        }
    21272206
    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));
    21292209        if (PATMIsPatchGCAddr(pVM, pCurInstrGC))
    21302210        {
     
    22852365    while (rc == VWRN_CONTINUE_RECOMPILE)
    22862366    {
    2287         cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;
    2288 
    22892367        pCurInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
    22902368        if (pCurInstrHC == NULL)
     
    22942372        }
    22952373#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));
    22972376        Log(("Recompile: %s", szOutput));
    22982377#else
    2299         disret = PATMR3DISInstr(pVM, pPatch, &cpu, pCurInstrGC, pCurInstrHC, &opsize, NULL);
     2378        disret = patmR3DisInstr(pVM, pPatch, pCurInstrGC, pCurInstrHC, PATMREAD_ORGCODE, &cpu, &opsize);
    23002379#endif
    23012380        if (disret == false)
     
    23332412                    goto end;
    23342413                }
    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);
    23372415                if (disret == false)
    23382416                {
     
    25652643    while (i < pPatch->cbPrivInstr)
    25662644    {
    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));
    25692647        if (disret == false)
    25702648            break;
     
    25822660    {
    25832661        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));
    25882666            if (disret == false)
    25892667                break;
     
    26612739    PPATCHINFO pPatch = &pPatchRec->patch;
    26622740    int rc = VERR_PATCHING_REFUSED;
    2663     DISCPUSTATE cpu;
    26642741    uint32_t orgOffsetPatchMem = ~0;
    26652742    RTRCPTR pInstrStart;
    26662743    bool fInserted;
    2667 #ifdef LOG_ENABLED
    2668     uint32_t opsize;
    2669     char szOutput[256];
    2670     bool disret;
    2671 #endif
    26722744    NOREF(pInstrHC); NOREF(uOpSize);
    26732745
     
    27202792    pPatch->pPatchBlockOffset = pVM->patm.s.offPatchMem;
    27212793    pPatch->uCurPatchOffset = 0;
    2722 
    2723     cpu.mode = (pPatch->flags & PATMFL_CODE32) ? CPUMODE_32BIT : CPUMODE_16BIT;
    27242794
    27252795    if ((pPatch->flags & (PATMFL_IDTHANDLER|PATMFL_IDTHANDLER_WITHOUT_ENTRYPOINT|PATMFL_SYSENTER)) == PATMFL_IDTHANDLER)
     
    28482918    }
    28492919
    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));
    28552921
    28562922    patmEmptyTree(pVM, &pPatch->pTempInfo->IllegalInstrTree);
     
    29172983     * condition here and only patch the common entypoint once.
    29182984     */
    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);
    29212986    Assert(disret);
    29222987    if (disret && cpuPush.pCurInstr->opcode == OP_PUSH)
     
    29262991        pCurInstrGC += opsize;
    29272992
    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);
    29302994        if (   disret
    29312995            && cpuJmp.pCurInstr->opcode == OP_JMP
     
    30343098    uint32_t orgOffsetPatchMem = ~0;
    30353099    bool fInserted;
    3036 #ifdef LOG_ENABLED
    3037     bool disret;
    3038     DISCPUSTATE cpu;
    3039     uint32_t opsize;
    3040     char szOutput[256];
    3041 #endif
    30423100
    30433101    // save original offset (in case of failures later on)
     
    30743132    Log(("Patch code ends -----------------------------------------------------\n"));
    30753133#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");
    30823135    Log(("Successfully installed Trap Trampoline patch at %RRv\n", pInstrGC));
    30833136
     
    35613614                break;
    35623615
    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);
    35653617            if (disret == false || cpu.pCurInstr->opcode != OP_JMP)
    35663618                break;
     
    35983650    pPatch->pInstrGCLowest  = pInstrGC;
    35993651    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");
    36063653
    36073654    Log(("Successfully installed function replacement patch at %RRv\n", pInstrGC));
     
    36343681    uint8_t      *pPB;
    36353682    int           rc = VERR_PATCHING_REFUSED;
    3636 #ifdef LOG_ENABLED
    3637     DISCPUSTATE   cpu;
    3638     uint32_t      opsize;
    3639     bool          disret;
    3640     char          szOutput[256];
    3641 #endif
    36423683
    36433684    Assert(pVM->patm.s.mmio.pCachedData);
     
    36583699        return VERR_PATCHING_REFUSED;
    36593700    }
    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:", "");
    36653702
    36663703    /* Save original instruction. */
     
    36783715    }
    36793716
    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");
    36853718    pVM->patm.s.mmio.pCachedData = 0;
    36863719    pVM->patm.s.mmio.GCPhys = 0;
     
    37133746    bool          disret;
    37143747    uint8_t      *pInstrHC;
    3715 #ifdef LOG_ENABLED
    3716     char          szOutput[256];
    3717 #endif
    37183748
    37193749    AssertReturn(pVM->patm.s.mmio.pCachedData, VERR_INVALID_PARAMETER);
     
    37243754
    37253755    /* 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);
    37283758    if (disret == false)
    37293759    {
     
    37513781    pPatch->pInstrGCHighest = pInstrGC + cpu.opsize;
    37523782
    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");
    37593784    pVM->patm.s.mmio.pCachedData = 0;
    37603785    pVM->patm.s.mmio.GCPhys = 0;
     
    38283853
    38293854    /* 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:", "");
    38403856
    38413857    /* Save the original instruction. */
     
    38813897    PPATCHINFO pPatch = &pPatchRec->patch;
    38823898    int rc = VERR_PATCHING_REFUSED;
    3883 #ifdef LOG_ENABLED
    3884     bool disret;
    3885     DISCPUSTATE cpu;
    3886     uint32_t opsize;
    3887     char szOutput[256];
    3888 #endif
    38893899
    38903900    pPatch->pPatchBlockOffset = 0;  /* doesn't use patch memory */
     
    39743984    pPatch->flags |= PATMFL_MUST_INSTALL_PATCHJMP;
    39753985
    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));
    39823987    Log(("Successfully installed %s patch at %RRv\n", patmGetInstructionString(pPatch->opcode, pPatch->flags), pInstrGC));
    39833988
     
    42474252    }
    42484253
    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);
    42514255    if (disret == false)
    42524256    {
     
    45014505        uint32_t    opsize;
    45024506
    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);
    45054508        PGMPhysReleasePageMappingLock(pVM, &Lock);
    45064509        if (disret)
     
    52005203    RT_ZERO(patch);
    52015204    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);
    52045206    /*
    52055207     * If it's a 5 byte relative jump, then we can work around the problem by replacing the 32 bits relative offset
     
    53435345                        DISCPUSTATE cpu;
    53445346                        char szOutput[256];
    5345                         uint32_t opsize, i = 0;
     5347                        uint32_t opsize;
     5348                        uint32_t i = 0;
    53465349                        bool disret;
    5347                         i = 0;
    53485350                        while(i < pPatch->cbPatchJump)
    53495351                        {
    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));
    53525354                            Log(("Renewed patch instr: %s", szOutput));
    53535355                            i += opsize;
     
    64156417        cacheRec.pPatch = &pPatch->patch;
    64166418
    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);
    64196421        if (cacheRec.Lock.pvMap)
    64206422            PGMPhysReleasePageMappingLock(pVM, &cacheRec.Lock);
     
    64546456        cacheRec.pPatch = &pPatch->patch;
    64556457
    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);
    64586460        if (cacheRec.Lock.pvMap)
    64596461            PGMPhysReleasePageMappingLock(pVM, &cacheRec.Lock);
     
    64626464        {
    64636465            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);
    64656468            if (cacheRec.Lock.pvMap)
    64666469                PGMPhysReleasePageMappingLock(pVM, &cacheRec.Lock);
  • trunk/src/VBox/VMM/VMMR3/VMMSwitcher.cpp

    r41658 r41671  
    814814             */
    815815            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
    820817            while (cbCode > 0)
    821818            {
     
    835832
    836833                /* 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);
    842848                else
    843849                {
    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);
    846852                    cbInstr = 1;
    847853                }
  • trunk/src/VBox/VMM/include/PATMInternal.h

    r41658 r41671  
    678678
    679679
    680 #ifndef IN_RC
    681 
    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 disassembly
    688  */
    689 typedef struct
    690 {
    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 
    714680RT_C_DECLS_BEGIN
    715681/**
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette