VirtualBox

Changeset 46150 in vbox for trunk/src


Ignore:
Timestamp:
May 17, 2013 5:21:45 PM (12 years ago)
Author:
vboxsync
Message:

PATM: Patch symbols.

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

Legend:

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

    r46137 r46150  
    182182    pVM->patm.s.pGCStackGC  = MMHyperR3ToRC(pVM, pVM->patm.s.pGCStackHC);
    183183
     184    patmR3DbgInit(pVM);
     185
    184186    /*
    185187     * Hypervisor memory for GC status data (read/write)
     
    30003002    }
    30013003
     3004    patmR3DbgAddPatch(pVM, pPatchRec);
     3005
    30023006    PATM_LOG_RAW_PATCH_INSTR(pVM, pPatch, patmGetInstructionString(pPatch->opcode, pPatch->flags));
    30033007
     
    31503154            fInserted = RTAvloU32Insert(&pVM->patm.s.PatchLookupTreeHC->PatchTreeByPatchAddr, &pPatchRec->CoreOffset);
    31513155            AssertMsg(fInserted, ("RTAvlULInsert failed for %x\n", pPatchRec->CoreOffset.Key));
     3156            patmR3DbgAddPatch(pVM, pPatchRec);
    31523157
    31533158            pPatch->uState = PATCH_ENABLED;
     
    32243229    fInserted = RTAvloU32Insert(&pVM->patm.s.PatchLookupTreeHC->PatchTreeByPatchAddr, &pPatchRec->CoreOffset);
    32253230    AssertMsg(fInserted, ("RTAvlULInsert failed for %x\n", pPatchRec->CoreOffset.Key));
     3231    patmR3DbgAddPatch(pVM, pPatchRec);
    32263232
    32273233    pPatch->uState = PATCH_ENABLED;
     
    33523358        goto failure;
    33533359    }
     3360
     3361    patmR3DbgAddPatch(pVM, pPatchRec);
    33543362
    33553363#ifdef LOG_ENABLED
     
    35033511        goto failure;
    35043512    }
     3513    patmR3DbgAddPatch(pVM, pPatchRec);
    35053514
    35063515    /* size of patch block */
     
    45864595        }
    45874596#endif
     4597
     4598        /* Add debug symbol. */
     4599        patmR3DbgAddPatch(pVM, pPatchRec);
    45884600    }
    45894601    /* Free leftover lock if any. */
  • trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp

    r45485 r46150  
    2323#define LOG_GROUP LOG_GROUP_PATM
    2424#include <VBox/vmm/patm.h>
    25 #include <VBox/vmm/stam.h>
    2625#include <VBox/vmm/pgm.h>
    2726#include <VBox/vmm/cpum.h>
     
    2928#include <VBox/vmm/em.h>
    3029#include <VBox/vmm/trpm.h>
    31 #include <VBox/param.h>
    32 #include <iprt/avl.h>
     30#include <VBox/vmm/csam.h>
    3331#include "PATMInternal.h"
    3432#include <VBox/vmm/vm.h>
    35 #include <VBox/vmm/csam.h>
    36 
    37 #include <VBox/dbg.h>
     33#include <VBox/param.h>
     34
    3835#include <VBox/err.h>
    3936#include <VBox/log.h>
     37#include <VBox/dis.h>
     38#include <VBox/disopcode.h>
     39
    4040#include <iprt/assert.h>
    4141#include <iprt/asm.h>
    4242#include <iprt/string.h>
    43 #include <VBox/dis.h>
    44 #include <VBox/disopcode.h>
    45 
    46 #include <stdlib.h>
    47 #include <stdio.h>
     43
    4844#include "PATMA.h"
    4945#include "PATMPatch.h"
  • trunk/src/VBox/VMM/VMMR3/PATMR3Dbg.cpp

    r46137 r46150  
    2121#define LOG_GROUP LOG_GROUP_PATM
    2222#include <VBox/vmm/patm.h>
     23#include <VBox/vmm/dbgf.h>
    2324#include <VBox/vmm/hm.h>
    2425#include "PATMInternal.h"
     26#include "PATMA.h"
    2527#include <VBox/vmm/vm.h>
    2628#include <VBox/err.h>
     
    4345        } while (0)
    4446
    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 */
    4763void patmR3DbgInit(PVM pVM)
    4864{
     
    5167
    5268
     69/**
     70 * Called by PATMR3Term.
     71 *
     72 * @param   pVM                 The cross context VM structure.
     73 */
    5374void patmR3DbgTerm(PVM pVM)
    5475{
     
    6182
    6283
     84/**
     85 * Called by when the patch memory is reinitialized.
     86 *
     87 * @param   pVM                 The cross context VM structure.
     88 */
    6389void patmR3DbgReset(PVM pVM)
    6490{
     
    6995}
    7096
     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 */
     104void 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 */
     214static 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 */
     227static 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}
    71242
    72243
     
    120291    if (RT_SUCCESS(rc))
    121292    {
    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/*/);
    125297        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  
    657657void patmR3DbgTerm(PVM pVM);
    658658void patmR3DbgReset(PVM pVM);
    659 //void patmR3DbgNewPatch(PVM pVM, );
    660 
    661 #endif
     659void patmR3DbgAddPatch(PVM pVM, PPATMPATCHREC pPatchRec);
     660
     661#endif
Note: See TracChangeset for help on using the changeset viewer.

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