VirtualBox

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


Ignore:
Timestamp:
Jan 24, 2013 9:11:05 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
83329
Message:

PATM: Changed two Main APIs to use PUVM instead of PVM (one of them directly accessed it). Lot's of function scope cleanups.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/PATMAll.cpp

    r41965 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4747 * @see     pg_raw
    4848 */
    49 VMMDECL(void) PATMRawEnter(PVM pVM, PCPUMCTXCORE pCtxCore)
     49VMM_INT_DECL(void) PATMRawEnter(PVM pVM, PCPUMCTXCORE pCtxCore)
    5050{
    5151    bool fPatchCode = PATMIsPatchGCAddr(pVM, pCtxCore->eip);
     
    118118 * @see     @ref pg_raw
    119119 */
    120 VMMDECL(void) PATMRawLeave(PVM pVM, PCPUMCTXCORE pCtxCore, int rawRC)
     120VMM_INT_DECL(void) PATMRawLeave(PVM pVM, PCPUMCTXCORE pCtxCore, int rawRC)
    121121{
    122122    bool fPatchCode = PATMIsPatchGCAddr(pVM, pCtxCore->eip);
     
    158158                if (enmState == PATMTRANS_SAFE)
    159159                {
    160                     Assert(!PATMFindActivePatchByEntrypoint(pVM, pOrgInstrGC));
     160                    Assert(!patmFindActivePatchByEntrypoint(pVM, pOrgInstrGC));
    161161                    Log(("Switchback from %RRv to %RRv (Psp=%x)\n", pCtxCore->eip, pOrgInstrGC, CTXSUFF(pVM->patm.s.pGCState)->Psp));
    162162                    STAM_COUNTER_INC(&pVM->patm.s.StatSwitchBack);
     
    210210 * @param   pCtxCore    The context core.
    211211 */
    212 VMMDECL(uint32_t) PATMRawGetEFlags(PVM pVM, PCCPUMCTXCORE pCtxCore)
     212VMM_INT_DECL(uint32_t) PATMRawGetEFlags(PVM pVM, PCCPUMCTXCORE pCtxCore)
    213213{
    214214    uint32_t efl = pCtxCore->eflags.u32;
     
    226226 * @param   efl         The new EFLAGS value.
    227227 */
    228 VMMDECL(void) PATMRawSetEFlags(PVM pVM, PCPUMCTXCORE pCtxCore, uint32_t efl)
     228VMM_INT_DECL(void) PATMRawSetEFlags(PVM pVM, PCPUMCTXCORE pCtxCore, uint32_t efl)
    229229{
    230230    pVM->patm.s.CTXSUFF(pGCState)->uVMFlags = efl & PATM_VIRTUAL_FLAGS_MASK;
     
    240240 * @param   pAddrGC     Guest context address
    241241 */
    242 VMMDECL(bool) PATMShouldUseRawMode(PVM pVM, RTRCPTR pAddrGC)
     242VMM_INT_DECL(bool) PATMShouldUseRawMode(PVM pVM, RTRCPTR pAddrGC)
    243243{
    244244    return (    PATMIsEnabled(pVM)
     
    252252 * @param   pVM         Pointer to the VM.
    253253 */
    254 VMMDECL(RCPTRTYPE(PPATMGCSTATE)) PATMQueryGCState(PVM pVM)
     254VMM_INT_DECL(RCPTRTYPE(PPATMGCSTATE)) PATMQueryGCState(PVM pVM)
    255255{
    256256    return pVM->patm.s.pGCStateGC;
     
    263263 * @param   pVM         Pointer to the VM.
    264264 * @param   pAddrGC     Guest context address
     265 * @internal
    265266 */
    266267VMMDECL(bool) PATMIsPatchGCAddr(PVM pVM, RTRCUINTPTR pAddrGC)
     
    277278 * @param   pCachedData     GC pointer to cached data
    278279 */
    279 VMMDECL(int) PATMSetMMIOPatchInfo(PVM pVM, RTGCPHYS GCPhys, RTRCPTR pCachedData)
     280VMM_INT_DECL(int) PATMSetMMIOPatchInfo(PVM pVM, RTGCPHYS GCPhys, RTRCPTR pCachedData)
    280281{
    281282    pVM->patm.s.mmio.GCPhys = GCPhys;
     
    293294 * @param   pVM         Pointer to the VM.
    294295 */
    295 VMMDECL(bool) PATMAreInterruptsEnabled(PVM pVM)
     296VMM_INT_DECL(bool) PATMAreInterruptsEnabled(PVM pVM)
    296297{
    297298    PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(VMMGetCpu(pVM));
     
    309310 * @param   pCtxCore    CPU context
    310311 */
    311 VMMDECL(bool) PATMAreInterruptsEnabledByCtxCore(PVM pVM, PCPUMCTXCORE pCtxCore)
     312VMM_INT_DECL(bool) PATMAreInterruptsEnabledByCtxCore(PVM pVM, PCPUMCTXCORE pCtxCore)
    312313{
    313314    if (PATMIsEnabled(pVM))
     
    327328 *
    328329 */
    329 VMMDECL(PPATMPATCHREC) PATMQueryFunctionPatch(PVM pVM, RTRCPTR pInstrGC)
     330PPATMPATCHREC patmQueryFunctionPatch(PVM pVM, RTRCPTR pInstrGC)
    330331{
    331332    PPATMPATCHREC pRec;
     
    351352 * @param   pSize       Original instruction size (out, optional)
    352353 */
    353 VMMDECL(bool) PATMIsInt3Patch(PVM pVM, RTRCPTR pInstrGC, uint32_t *pOpcode, uint32_t *pSize)
     354VMM_INT_DECL(bool) PATMIsInt3Patch(PVM pVM, RTRCPTR pInstrGC, uint32_t *pOpcode, uint32_t *pSize)
    354355{
    355356    PPATMPATCHREC pRec;
     
    450451 * @param   pRelBranchPatch     Relative duplicated function address
    451452 */
    452 VMMDECL(int) PATMAddBranchToLookupCache(PVM pVM, RTRCPTR pJumpTableGC, RTRCPTR pBranchTarget, RTRCUINTPTR pRelBranchPatch)
     453int patmAddBranchToLookupCache(PVM pVM, RTRCPTR pJumpTableGC, RTRCPTR pBranchTarget, RTRCUINTPTR pRelBranchPatch)
    453454{
    454455    PPATCHJUMPTABLE pJumpTable;
     
    516517 * @param   fPatchFlags Patch flags
    517518 */
    518 VMMDECL(const char *) patmGetInstructionString(uint32_t opcode, uint32_t fPatchFlags)
     519const char *patmGetInstructionString(uint32_t opcode, uint32_t fPatchFlags)
    519520{
    520521    const char *pszInstr = NULL;
  • trunk/src/VBox/VMM/VMMAll/TRPMAll.cpp

    r42776 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/VMM/VMMR3/CPUM.cpp

    r44170 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/VMM/VMMR3/CSAM.cpp

    r43872 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    672672 * Convert guest context address to host context pointer
    673673 *
    674  * @returns VBox status code.
     674 * @returns Byte pointer (ring-3 context) corresponding to pGCPtr on success,
     675 *          NULL on failure.
    675676 * @param   pVM         Pointer to the VM.
    676677 * @param   pCacheRec   Address conversion cache record
     
    679680 *
    680681 */
    681 static R3PTRTYPE(void *) CSAMGCVirtToHCVirt(PVM pVM, PCSAMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr)
     682static uint8_t *csamR3GCVirtToHCVirt(PVM pVM, PCSAMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr)
    682683{
    683684    int rc;
    684     R3PTRTYPE(void *) pHCPtr;
     685    void *pHCPtr;
    685686    Assert(pVM->cCpus == 1);
    686687    PVMCPU pVCpu = VMMGetCpu0(pVM);
     
    690691    pHCPtr = PATMR3GCPtrToHCPtr(pVM, pGCPtr);
    691692    if (pHCPtr)
    692         return pHCPtr;
     693        return (uint8_t *)pHCPtr;
    693694
    694695    if (pCacheRec->pPageLocStartHC)
     
    717718    }
    718719
    719     pCacheRec->pPageLocStartHC = (R3PTRTYPE(uint8_t*))((RTHCUINTPTR)pHCPtr & PAGE_BASE_HC_MASK);
     720    pCacheRec->pPageLocStartHC = (uint8_t*)((uintptr_t)pHCPtr & PAGE_BASE_HC_MASK);
    720721    pCacheRec->pGuestLoc       = pGCPtr & PAGE_BASE_GC_MASK;
    721722    STAM_PROFILE_STOP(&pVM->csam.s.StatTimeAddrConv, a);
    722     return pHCPtr;
     723    return (uint8_t *)pHCPtr;
    723724}
    724725
     
    896897
    897898            {   /* Force pCurInstrHC out of scope after we stop using it (page lock!) */
    898                 uint8_t       *pCurInstrHC = 0;
    899                 pCurInstrHC = (uint8_t *)CSAMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
     899                uint8_t *pCurInstrHC = csamR3GCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
    900900                if (pCurInstrHC == NULL)
    901901                {
    902                     Log(("CSAMGCVirtToHCVirt failed for %RRv\n", pCurInstrGC));
     902                    Log(("csamR3GCVirtToHCVirt failed for %RRv\n", pCurInstrGC));
    903903                    break;
    904904                }
     
    10781078            for (int j = 0; j < 16; j++)
    10791079            {
    1080                 uint8_t *pCurInstrHC = (uint8_t *)CSAMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
     1080                uint8_t *pCurInstrHC = csamR3GCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
    10811081                if (pCurInstrHC == NULL)
    10821082                {
    1083                     Log(("CSAMGCVirtToHCVirt failed for %RRv\n", pCurInstrGC));
     1083                    Log(("csamR3GCVirtToHCVirt failed for %RRv\n", pCurInstrGC));
    10841084                    goto done;
    10851085                }
     
    12901290
    12911291        {   /* Force pCurInstrHC out of scope after we stop using it (page lock!) */
    1292             uint8_t *pCurInstrHC = (uint8_t *)CSAMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
     1292            uint8_t *pCurInstrHC = csamR3GCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
    12931293            if (pCurInstrHC == NULL)
    12941294            {
    1295                 Log(("CSAMGCVirtToHCVirt failed for %RRv\n", pCurInstrGC));
     1295                Log(("csamR3GCVirtToHCVirt failed for %RRv\n", pCurInstrGC));
    12961296                rc = VERR_PATCHING_REFUSED;
    12971297                goto done;
     
    23252325    if (CSAMIsEnabled(pVM))
    23262326    {
    2327         /* Cache record for CSAMGCVirtToHCVirt */
     2327        /* Cache record for csamR3GCVirtToHCVirt */
    23282328        CSAMP2GLOOKUPREC cacheRec;
    23292329        RT_ZERO(cacheRec);
     
    24912491            {
    24922492                PCSAMPAGE pPage = NULL;
    2493                 CSAMP2GLOOKUPREC cacheRec;                  /* Cache record for CSAMGCVirtToHCVirt. */
     2493                CSAMP2GLOOKUPREC cacheRec;                  /* Cache record for csamR3GCVirtToHCVirt. */
    24942494                RT_ZERO(cacheRec);
    24952495
     
    25482548            PCSAMPAGE pPage = NULL;
    25492549            DBGFSELINFO selInfo;
    2550             CSAMP2GLOOKUPREC cacheRec;                  /* Cache record for CSAMGCVirtToHCVirt. */
     2550            CSAMP2GLOOKUPREC cacheRec;                  /* Cache record for csamR3GCVirtToHCVirt. */
    25512551            RT_ZERO(cacheRec);
    25522552
  • trunk/src/VBox/VMM/VMMR3/EM.cpp

    r44340 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2011 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/VMM/VMMR3/EMRaw.cpp

    r44340 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/VMM/VMMR3/HM.cpp

    r44351 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    700700{
    701701    /* Disable PATM & CSAM. */
    702     PATMR3AllowPatching(pVM, false);
     702    PATMR3AllowPatching(pVM->pUVM, false);
    703703    CSAMDisableScanning(pVM);
    704704
  • trunk/src/VBox/VMM/VMMR3/PATM.cpp

    r42781 r44362  
    33 * PATM - Dynamic Guest OS Patching Manager
    44 *
    5  * NOTE: Never ever reuse patch memory!!
     5 * @note Never ever reuse patch memory!!
    66 */
    77
    88/*
    9  * Copyright (C) 2006-2012 Oracle Corporation
     9 * Copyright (C) 2006-2013 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3535#include <VBox/param.h>
    3636#include <VBox/vmm/selm.h>
     37#include <VBox/vmm/csam.h>
    3738#include <iprt/avl.h>
    3839#include "PATMInternal.h"
    3940#include "PATMPatch.h"
    4041#include <VBox/vmm/vm.h>
    41 #include <VBox/vmm/csam.h>
     42#include <VBox/vmm/uvm.h>
    4243#include <VBox/dbg.h>
    4344#include <VBox/err.h>
     
    108109static int               patmReinit(PVM pVM);
    109110static DECLCALLBACK(int) RelocatePatches(PAVLOU32NODECORE pNode, void *pParam);
     111static RTRCPTR      patmR3GuestGCPtrToPatchGCPtrSimple(PVM pVM, RCPTRTYPE(uint8_t*) pInstrGC);
     112static int          patmR3MarkDirtyPatch(PVM pVM, PPATCHINFO pPatch);
    110113
    111114#ifdef VBOX_WITH_DEBUGGER
     
    132135 * @param   pVM         Pointer to the VM.
    133136 */
    134 VMMR3DECL(int) PATMR3Init(PVM pVM)
     137VMMR3_INT_DECL(int) PATMR3Init(PVM pVM)
    135138{
    136139    int rc;
     
    308311 * @param   pVM     Pointer to the VM.
    309312 */
    310 VMMR3DECL(int) PATMR3InitFinalize(PVM pVM)
     313VMMR3_INT_DECL(int) PATMR3InitFinalize(PVM pVM)
    311314{
    312315    /* The GC state, stack and statistics must be read/write for the guest (supervisor only of course). */
     
    438441 * @param   pVM     The VM.
    439442 */
    440 VMMR3DECL(void) PATMR3Relocate(PVM pVM)
     443VMMR3_INT_DECL(void) PATMR3Relocate(PVM pVM)
    441444{
    442445    RTRCPTR     GCPtrNew = MMHyperR3ToRC(pVM, pVM->patm.s.pGCStateHC);
     
    493496 * @param   pVM         Pointer to the VM.
    494497 */
    495 VMMR3DECL(int) PATMR3Term(PVM pVM)
     498VMMR3_INT_DECL(int) PATMR3Term(PVM pVM)
    496499{
    497500    /* Memory was all allocated from the two MM heaps and requires no freeing. */
     
    507510 * @param   pVM     The VM which is reset.
    508511 */
    509 VMMR3DECL(int) PATMR3Reset(PVM pVM)
     512VMMR3_INT_DECL(int) PATMR3Reset(PVM pVM)
    510513{
    511514    Log(("PATMR3Reset\n"));
     
    516519        PPATMPATCHREC pPatchRec = (PPATMPATCHREC)RTAvloU32RemoveBestFit(&pVM->patm.s.PatchLookupTreeHC->PatchTree, 0, true);
    517520        if (pPatchRec)
    518         {
    519             PATMRemovePatch(pVM, pPatchRec, true);
    520         }
     521            patmR3RemovePatch(pVM, pPatchRec, true);
    521522        else
    522523            break;
     
    921922}
    922923
    923 
    924924#ifdef VBOX_WITH_DEBUGGER
     925
    925926/**
    926927 * Callback function for RTAvloU32DoWithAll
     
    939940    return 0;
    940941}
    941 #endif /* VBOX_WITH_DEBUGGER */
    942 
    943 
    944 #ifdef VBOX_WITH_DEBUGGER
     942
     943
    945944/**
    946945 * Callback function for RTAvloU32DoWithAll
     
    959958    return 0;
    960959}
    961 #endif
     960
     961#endif /* VBOX_WITH_DEBUGGER */
     962#ifdef UNUSED_FUNCTIONS
    962963
    963964/**
    964965 * Returns the host context pointer and size of the patch memory block
     966 *
     967 * @returns Host context pointer.
     968 * @param   pVM         Pointer to the VM.
     969 * @param   pcb         Size of the patch memory block
     970 * @internal
     971 */
     972VMMR3_INT_DECL(void *) PATMR3QueryPatchMemHC(PVM pVM, uint32_t *pcb)
     973{
     974    if (pcb)
     975        *pcb = pVM->patm.s.cbPatchMem;
     976
     977    return pVM->patm.s.pPatchMemHC;
     978}
     979
     980
     981/**
     982 * Returns the guest context pointer and size of the patch memory block
     983 *
     984 * @returns Guest context pointer.
     985 * @param   pVM         Pointer to the VM.
     986 * @param   pcb         Size of the patch memory block
     987 */
     988VMMR3_INT_DECL(RTRCPTR) PATMR3QueryPatchMemGC(PVM pVM, uint32_t *pcb)
     989{
     990    if (pcb)
     991        *pcb = pVM->patm.s.cbPatchMem;
     992
     993    return pVM->patm.s.pPatchMemGC;
     994}
     995
     996#endif /* UNUSED_FUNCTIONS */
     997
     998/**
     999 * Returns the host context pointer of the GC context structure
    9651000 *
    9661001 * @returns VBox status code.
    9671002 * @param   pVM         Pointer to the VM.
    968  * @param   pcb         Size of the patch memory block
    969  */
    970 VMMR3DECL(void *) PATMR3QueryPatchMemHC(PVM pVM, uint32_t *pcb)
    971 {
    972     if (pcb)
    973         *pcb = pVM->patm.s.cbPatchMem;
    974 
    975     return pVM->patm.s.pPatchMemHC;
    976 }
    977 
    978 
    979 /**
    980  * Returns the guest context pointer and size of the patch memory block
     1003 */
     1004VMMR3_INT_DECL(PPATMGCSTATE) PATMR3QueryGCStateHC(PVM pVM)
     1005{
     1006    return pVM->patm.s.pGCStateHC;
     1007}
     1008
     1009
     1010#ifdef UNUSED_FUNCTION
     1011/**
     1012 * Checks whether the HC address is part of our patch region
     1013 *
     1014 * @returns true/false.
     1015 * @param   pVM         Pointer to the VM.
     1016 * @param   pAddrHC     Host context ring-3 address to check.
     1017 */
     1018VMMR3_INT_DECL(bool) PATMR3IsPatchHCAddr(PVM pVM, void *pAddrHC)
     1019{
     1020    return (uintptr_t)pAddrHC >= (uintptr_t)pVM->patm.s.pPatchMemHC
     1021        && (uintptr_t)pAddrHC <  (uintptr_t)pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem;
     1022}
     1023#endif
     1024
     1025
     1026/**
     1027 * Allows or disallow patching of privileged instructions executed by the guest OS
    9811028 *
    9821029 * @returns VBox status code.
    983  * @param   pVM         Pointer to the VM.
    984  * @param   pcb         Size of the patch memory block
    985  */
    986 VMMR3DECL(RTRCPTR) PATMR3QueryPatchMemGC(PVM pVM, uint32_t *pcb)
    987 {
    988     if (pcb)
    989         *pcb = pVM->patm.s.cbPatchMem;
    990 
    991     return pVM->patm.s.pPatchMemGC;
    992 }
    993 
    994 
    995 /**
    996  * Returns the host context pointer of the GC context structure
    997  *
    998  * @returns VBox status code.
    999  * @param   pVM         Pointer to the VM.
    1000  */
    1001 VMMR3DECL(PPATMGCSTATE) PATMR3QueryGCStateHC(PVM pVM)
    1002 {
    1003     return pVM->patm.s.pGCStateHC;
    1004 }
    1005 
    1006 
    1007 /**
    1008  * Checks whether the HC address is part of our patch region
    1009  *
    1010  * @returns VBox status code.
    1011  * @param   pVM         Pointer to the VM.
    1012  * @param   pAddrGC     Guest context address
    1013  */
    1014 VMMR3DECL(bool) PATMR3IsPatchHCAddr(PVM pVM, R3PTRTYPE(uint8_t *) pAddrHC)
    1015 {
    1016     return (pAddrHC >= pVM->patm.s.pPatchMemHC && pAddrHC < pVM->patm.s.pPatchMemHC + pVM->patm.s.cbPatchMem) ? true : false;
    1017 }
    1018 
    1019 
    1020 /**
    1021  * Allows or disallow patching of privileged instructions executed by the guest OS
    1022  *
    1023  * @returns VBox status code.
    1024  * @param   pVM         Pointer to the VM.
    1025  * @param   fAllowPatching Allow/disallow patching
    1026  */
    1027 VMMR3DECL(int) PATMR3AllowPatching(PVM pVM, uint32_t fAllowPatching)
    1028 {
    1029     pVM->fPATMEnabled = (fAllowPatching) ? true : false;
     1030 * @param   pUVM        The user mode VM handle.
     1031 * @param   fAllowPatching  Allow/disallow patching
     1032 */
     1033VMMR3DECL(int) PATMR3AllowPatching(PUVM pUVM, bool fAllowPatching)
     1034{
     1035    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
     1036    PVM pVM = pUVM->pVM;
     1037    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     1038
     1039    pVM->fPATMEnabled = fAllowPatching;
    10301040    return VINF_SUCCESS;
    10311041}
     1042
     1043
     1044/**
     1045 * Checks if the patch manager is enabled or not.
     1046 *
     1047 * @returns true if enabled, false if not (or if invalid handle).
     1048 * @param   pUVM        The user mode VM handle.
     1049 */
     1050VMMR3DECL(bool) PATMR3IsEnabled(PUVM pUVM)
     1051{
     1052    UVM_ASSERT_VALID_EXT_RETURN(pUVM, false);
     1053    PVM pVM = pUVM->pVM;
     1054    VM_ASSERT_VALID_EXT_RETURN(pVM, false);
     1055    return PATMIsEnabled(pVM);
     1056}
     1057
    10321058
    10331059/**
     
    10381064 * @param   pAddrGC     GC pointer
    10391065 */
    1040 VMMR3DECL(R3PTRTYPE(void *)) PATMR3GCPtrToHCPtr(PVM pVM, RTRCPTR pAddrGC)
     1066VMMR3_INT_DECL(void *) PATMR3GCPtrToHCPtr(PVM pVM, RTRCPTR pAddrGC)
    10411067{
    10421068    if (pVM->patm.s.pPatchMemGC <= pAddrGC && pVM->patm.s.pPatchMemGC + pVM->patm.s.cbPatchMem > pAddrGC)
    10431069        return pVM->patm.s.pPatchMemHC + (pAddrGC - pVM->patm.s.pPatchMemGC);
    1044     else
    1045         return NULL;
    1046 }
    1047 
    1048 /**
    1049  * Query PATM state (enabled/disabled)
    1050  *
    1051  * @returns 0 - disabled, 1 - enabled
    1052  * @param   pVM         Pointer to the VM.
    1053  */
    1054 VMMR3DECL(int) PATMR3IsEnabled(PVM pVM)
    1055 {
    1056     return pVM->fPATMEnabled;
     1070    return NULL;
    10571071}
    10581072
     
    10691083 *
    10701084 */
    1071 R3PTRTYPE(uint8_t *) PATMGCVirtToHCVirt(PVM pVM, PPATMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr)
     1085R3PTRTYPE(uint8_t *) patmR3GCVirtToHCVirt(PVM pVM, PPATMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr)
    10721086{
    10731087    int rc;
     
    11411155            /* Special case: call function replacement patch from this patch block.
    11421156             */
    1143             PPATMPATCHREC pFunctionRec = PATMQueryFunctionPatch(pVM, pRec->pTargetGC);
     1157            PPATMPATCHREC pFunctionRec = patmQueryFunctionPatch(pVM, pRec->pTargetGC);
    11441158            if (!pFunctionRec)
    11451159            {
     
    12441258 */
    12451259 /** @note Be extremely careful with this function. Make absolutely sure the guest address is correct! (to avoid executing instructions twice!) */
    1246 void patmr3AddP2GLookupRecord(PVM pVM, PPATCHINFO pPatch, uint8_t *pPatchInstrHC, RTRCPTR pInstrGC, PATM_LOOKUP_TYPE enmType, bool fDirty)
     1260void patmR3AddP2GLookupRecord(PVM pVM, PPATCHINFO pPatch, uint8_t *pPatchInstrHC, RTRCPTR pInstrGC, PATM_LOOKUP_TYPE enmType, bool fDirty)
    12471261{
    12481262    bool ret;
     
    13491363 * @param   ppTree          Tree to empty
    13501364 */
    1351 void patmEmptyTree(PVM pVM, PAVLPVNODECORE *ppTree)
     1365static void patmEmptyTree(PVM pVM, PAVLPVNODECORE *ppTree)
    13521366{
    13531367    NOREF(pVM);
     
    13711385 * @param   ppTree          Tree to empty
    13721386 */
    1373 void patmEmptyTreeU32(PVM pVM, PPAVLU32NODECORE ppTree)
     1387static void patmEmptyTreeU32(PVM pVM, PPAVLU32NODECORE ppTree)
    13741388{
    13751389    NOREF(pVM);
     
    16941708
    16951709    /* Add lookup record for patch to guest address translation */
    1696     patmr3AddP2GLookupRecord(pVM, pPatch, PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset, pCurInstrGC, PATM_LOOKUP_BOTHDIR);
     1710    patmR3AddP2GLookupRecord(pVM, pPatch, PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset, pCurInstrGC, PATM_LOOKUP_BOTHDIR);
    16971711
    16981712    /* Update lowest and highest instruction address for this patch */
     
    18261840            pNextInstrGC = pCurInstrGC + pCpu->cbInstr;
    18271841            {   /* Force pNextInstrHC out of scope after using it */
    1828                 uint8_t *pNextInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pNextInstrGC);
     1842                uint8_t *pNextInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pNextInstrGC);
    18291843                if (pNextInstrHC == NULL)
    18301844                {
     
    21502164
    21512165        {   /* Force pOrgJumpHC out of scope after using it */
    2152             uint8_t *pOrgJumpHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pOrgJumpGC);
     2166            uint8_t *pOrgJumpHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pOrgJumpGC);
    21532167
    21542168            bool disret = patmR3DisInstr(pVM, pPatch, pOrgJumpGC, pOrgJumpHC, PATMREAD_ORGCODE, &cpu, NULL);
     
    22112225    while (rc == VWRN_CONTINUE_ANALYSIS)
    22122226    {
    2213         pCurInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
     2227        pCurInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
    22142228        if (pCurInstrHC == NULL)
    22152229        {
     
    23432357 *
    23442358 */
    2345 VMMR3DECL(int) PATMR3DetectConflict(PVM pVM, RTRCPTR pInstrGC, RTRCPTR pConflictGC)
    2346 {
    2347     PPATCHINFO pTargetPatch = PATMFindActivePatchByEntrypoint(pVM, pConflictGC, true /* include patch hints */);
     2359VMMR3_INT_DECL(int) PATMR3DetectConflict(PVM pVM, RTRCPTR pInstrGC, RTRCPTR pConflictGC)
     2360{
     2361    PPATCHINFO pTargetPatch = patmFindActivePatchByEntrypoint(pVM, pConflictGC, true /* include patch hints */);
    23482362    if (pTargetPatch)
    23492363    {
     
    23782392    while (rc == VWRN_CONTINUE_RECOMPILE)
    23792393    {
    2380         pCurInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
     2394        pCurInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
    23812395        if (pCurInstrHC == NULL)
    23822396        {
     
    23962410
    23972411            /* Add lookup record for patch to guest address translation */
    2398             patmr3AddP2GLookupRecord(pVM, pPatch, PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset, pCurInstrGC, PATM_LOOKUP_BOTHDIR);
     2412            patmR3AddP2GLookupRecord(pVM, pPatch, PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset, pCurInstrGC, PATM_LOOKUP_BOTHDIR);
    23992413            patmPatchGenIllegalInstr(pVM, pPatch);
    24002414            rc = VINF_SUCCESS;   /* Note: don't fail here; we might refuse an important patch!! */
     
    24192433                 * Recompile the next instruction as well
    24202434                 */
    2421                 pNextInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pNextInstrGC);
     2435                pNextInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pNextInstrGC);
    24222436                if (pNextInstrHC == NULL)
    24232437                {
     
    25122526                  * We rely on CSAM to detect and resolve conflicts
    25132527                  */
    2514                 PPATCHINFO pTargetPatch = PATMFindActivePatchByEntrypoint(pVM, addr);
     2528                PPATCHINFO pTargetPatch = patmFindActivePatchByEntrypoint(pVM, addr);
    25152529                if(pTargetPatch)
    25162530                {
     
    25672581    Assert(!(pPatch->flags & PATMFL_PATCHED_GUEST_CODE));
    25682582
    2569     pPB = PATMGCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC);
     2583    pPB = patmR3GCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC);
    25702584    Assert(pPB);
    25712585
     
    27072721    Assert(pPatch->cbPatchJump <= sizeof(temp));
    27082722
    2709     pPB = PATMGCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC);
     2723    pPB = patmR3GCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC);
    27102724    Assert(pPB);
    27112725
     
    27472761 *
    27482762 */
    2749 VMMR3DECL(int) PATMR3PatchBlock(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC,
    2750                                 uint32_t uOpcode, uint32_t uOpSize, PPATMPATCHREC pPatchRec)
     2763static int patmR3PatchBlock(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC,
     2764                            uint32_t uOpcode, uint32_t uOpSize, PPATMPATCHREC pPatchRec)
    27512765{
    27522766    PPATCHINFO pPatch = &pPatchRec->patch;
     
    27772791        if (!(pPatch->flags & PATMFL_IDTHANDLER))
    27782792        {
    2779             AssertMsg(0, ("PATMR3PatchBlock: Invalid opcode %x\n", uOpcode));
     2793            AssertMsg(0, ("patmR3PatchBlock: Invalid opcode %x\n", uOpcode));
    27802794            return VERR_INVALID_PARAMETER;
    27812795        }
     
    28502864        /* Most likely cause: we encountered an illegal instruction very early on. */
    28512865        /** @todo could turn it into an int3 callable patch. */
    2852         Log(("PATMR3PatchBlock: patch block too small -> refuse\n"));
     2866        Log(("patmR3PatchBlock: patch block too small -> refuse\n"));
    28532867        rc = VERR_PATCHING_REFUSED;
    28542868        goto failure;
     
    29072921        /*uint8_t bASMInt3 = 0xCC; - unused */
    29082922
    2909         Log(("PATMR3PatchBlock %RRv -> int 3 callable patch.\n", pPatch->pPrivInstrGC));
     2923        Log(("patmR3PatchBlock %RRv -> int 3 callable patch.\n", pPatch->pPrivInstrGC));
    29102924        /* Replace first opcode byte with 'int 3'. */
    29112925        rc = patmActivateInt3Patch(pVM, pPatch);
     
    29883002    uint32_t orgOffsetPatchMem = ~0;
    29893003
    2990     pInstrHC = pCurInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
     3004    pInstrHC = pCurInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);
    29913005    AssertReturn(pCurInstrHC, VERR_PAGE_NOT_PRESENT);
    29923006
     
    30433057
    30443058            /* Add lookup record for patch to guest address translation (for the push) */
    3045             patmr3AddP2GLookupRecord(pVM, pPatch, PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset, pInstrGC, PATM_LOOKUP_BOTHDIR);
     3059            patmR3AddP2GLookupRecord(pVM, pPatch, PATCHCODE_PTR_HC(pPatch) + pPatch->uCurPatchOffset, pInstrGC, PATM_LOOKUP_BOTHDIR);
    30463060
    30473061            /* Duplicate push. */
     
    30923106        pVM->patm.s.offPatchMem = orgOffsetPatchMem;
    30933107
    3094     return PATMR3PatchBlock(pVM, pInstrGC, pInstrHC, OP_CLI, uOpSize, pPatchRec);
     3108    return patmR3PatchBlock(pVM, pInstrGC, pInstrHC, OP_CLI, uOpSize, pPatchRec);
    30953109}
    30963110
     
    34963510 *
    34973511 */
    3498 VMMR3DECL(int) PATMR3DuplicateFunctionRequest(PVM pVM, PCPUMCTX pCtx)
     3512VMMR3_INT_DECL(int) PATMR3DuplicateFunctionRequest(PVM pVM, PCPUMCTX pCtx)
    34993513{
    35003514    RTRCPTR     pBranchTarget, pPage;
     
    35613575    }
    35623576    Assert(PATMIsPatchGCAddr(pVM, pCtx->edi));
    3563     rc = PATMAddBranchToLookupCache(pVM, pCtx->edi, pBranchTarget, pCtx->eax);
     3577    rc = patmAddBranchToLookupCache(pVM, pCtx->edi, pBranchTarget, pCtx->eax);
    35643578    AssertRC(rc);
    35653579
     
    36163630            uint8_t *pTmpInstrHC;
    36173631
    3618             pTmpInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pTargetGC);
     3632            pTmpInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pTargetGC);
    36193633            Assert(pTmpInstrHC);
    36203634            if (pTmpInstrHC == 0)
     
    36963710        goto failure;
    36973711
    3698     pPB = PATMGCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC);
     3712    pPB = patmR3GCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC);
    36993713    if (pPB == 0)
    37003714        goto failure;
     
    38533867 *
    38543868 */
    3855 VMMR3DECL(int) PATMR3PatchInstrInt3(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC, DISCPUSTATE *pCpu,
    3856                                     PPATCHINFO pPatch)
     3869int patmR3PatchInstrInt3(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC, DISCPUSTATE *pCpu, PPATCHINFO pPatch)
    38573870{
    38583871    uint8_t bASMInt3 = 0xCC;
     
    38603873
    38613874    /* Note: Do not use patch memory here! It might called during patch installation too. */
    3862     PATM_LOG_PATCH_INSTR(pVM, pPatch, PATMREAD_ORGCODE, "PATMR3PatchInstrInt3:", "");
     3875    PATM_LOG_PATCH_INSTR(pVM, pPatch, PATMREAD_ORGCODE, "patmR3PatchInstrInt3:", "");
    38633876
    38643877    /* Save the original instruction. */
     
    39693982     * references the target instruction in the conflict patch.
    39703983     */
    3971     RTRCPTR pJmpDest = PATMR3GuestGCPtrToPatchGCPtr(pVM, pInstrGC + pCpu->cbInstr + (int32_t)pCpu->Param1.uValue);
    3972 
    3973     AssertMsg(pJmpDest, ("PATMR3GuestGCPtrToPatchGCPtr failed for %RRv\n", pInstrGC + pCpu->cbInstr + (int32_t)pCpu->Param1.uValue));
     3984    RTRCPTR pJmpDest = patmR3GuestGCPtrToPatchGCPtrSimple(pVM, pInstrGC + pCpu->cbInstr + (int32_t)pCpu->Param1.uValue);
     3985
     3986    AssertMsg(pJmpDest, ("patmR3GuestGCPtrToPatchGCPtrSimple failed for %RRv\n", pInstrGC + pCpu->cbInstr + (int32_t)pCpu->Param1.uValue));
    39743987    pPatch->pPatchJumpDestGC = pJmpDest;
    39753988
     
    40204033 * @param   flags       Patch flags
    40214034 */
    4022 VMMR3DECL(int) PATMR3AddHint(PVM pVM, RTRCPTR pInstrGC, uint32_t flags)
     4035VMMR3_INT_DECL(int) PATMR3AddHint(PVM pVM, RTRCPTR pInstrGC, uint32_t flags)
    40234036{
    40244037    Assert(pInstrGC);
     
    40394052 * @note    returns failure if patching is not allowed or possible
    40404053 */
    4041 VMMR3DECL(int) PATMR3InstallPatch(PVM pVM, RTRCPTR pInstrGC, uint64_t flags)
     4054VMMR3_INT_DECL(int) PATMR3InstallPatch(PVM pVM, RTRCPTR pInstrGC, uint64_t flags)
    40424055{
    40434056    DISCPUSTATE cpu;
     
    40654078    if (!(flags & (PATMFL_GUEST_SPECIFIC|PATMFL_IDTHANDLER|PATMFL_INTHANDLER|PATMFL_TRAMPOLINE)))
    40664079    {
    4067         PPATCHINFO pConflictPatch = PATMFindActivePatchByEntrypoint(pVM, pInstrGC);
     4080        PPATCHINFO pConflictPatch = patmFindActivePatchByEntrypoint(pVM, pInstrGC);
    40684081        AssertReleaseMsg(pConflictPatch == 0, ("Unable to patch overwritten instruction at %RRv (%RRv)\n", pInstrGC, pConflictPatch->pPrivInstrGC));
    40694082        if (pConflictPatch != 0)
     
    42324245    RT_ZERO(cacheRec);
    42334246
    4234     pInstrHC = PATMGCVirtToHCVirt(pVM, &cacheRec, pInstrGC);
     4247    pInstrHC = patmR3GCVirtToHCVirt(pVM, &cacheRec, pInstrGC);
    42354248    AssertReturn(pInstrHC, VERR_PATCHING_REFUSED);
    42364249
     
    43374350    if (pPatchRec->patch.flags & PATMFL_INT3_REPLACEMENT)
    43384351    {
    4339         rc = PATMR3PatchInstrInt3(pVM, pInstrGC, pInstrHC, &cpu, &pPatchRec->patch);
     4352        rc = patmR3PatchInstrInt3(pVM, pInstrGC, pInstrHC, &cpu, &pPatchRec->patch);
    43404353    }
    43414354    else
     
    43664379        case OP_SYSENTER:
    43674380        case OP_PUSH:
    4368             rc = PATMInstallGuestSpecificPatch(pVM, &cpu, pInstrGC, pInstrHC, pPatchRec);
     4381            rc = patmR3InstallGuestSpecificPatch(pVM, &cpu, pInstrGC, pInstrHC, pPatchRec);
    43694382            if (rc == VINF_SUCCESS)
    43704383            {
     
    43854398        {
    43864399        case OP_SYSENTER:
    4387             rc = PATMInstallGuestSpecificPatch(pVM, &cpu, pInstrGC, pInstrHC, pPatchRec);
     4400            rc = patmR3InstallGuestSpecificPatch(pVM, &cpu, pInstrGC, pInstrHC, pPatchRec);
    43884401            if (rc == VINF_SUCCESS)
    43894402            {
     
    44264439        case OP_CLI:
    44274440            Log(("PATMR3InstallPatch %s %RRv code32=%d\n", patmGetInstructionString(pPatchRec->patch.opcode, pPatchRec->patch.flags), pInstrGC, (flags & PATMFL_CODE32) ? 1 : 0));
    4428             rc = PATMR3PatchBlock(pVM, pInstrGC, pInstrHC, cpu.pCurInstr->uOpcode, cbInstr, pPatchRec);
     4441            rc = patmR3PatchBlock(pVM, pInstrGC, pInstrHC, cpu.pCurInstr->uOpcode, cbInstr, pPatchRec);
    44294442            break;
    44304443
     
    44404453        case OP_VERR:
    44414454        case OP_IRET:
    4442             rc = PATMR3PatchInstrInt3(pVM, pInstrGC, pInstrHC, &cpu, &pPatchRec->patch);
     4455            rc = patmR3PatchInstrInt3(pVM, pInstrGC, pInstrHC, &cpu, &pPatchRec->patch);
    44434456            break;
    44444457
     
    47734786 * @param   pPatch      Patch record
    47744787 */
    4775 int patmRemovePatchPages(PVM pVM, PPATCHINFO pPatch)
     4788static int patmRemovePatchPages(PVM pVM, PPATCHINFO pPatch)
    47764789{
    47774790    int         rc;
     
    48084821 *
    48094822 */
    4810 VMMR3DECL(int) PATMR3PatchWrite(PVM pVM, RTRCPTR GCPtr, uint32_t cbWrite)
     4823VMMR3_INT_DECL(int) PATMR3PatchWrite(PVM pVM, RTRCPTR GCPtr, uint32_t cbWrite)
    48114824{
    48124825    RTRCUINTPTR          pWritePageStart, pWritePageEnd, pPage;
     
    49054918                                    LogRel(("PATM: Disable block at %RRv - write %RRv-%RRv\n", pPatch->pPrivInstrGC, pGuestPtrGC, pGuestPtrGC+cbWrite));
    49064919
    4907                                     PATMR3MarkDirtyPatch(pVM, pPatch);
     4920                                    patmR3MarkDirtyPatch(pVM, pPatch);
    49084921
    49094922                                    /* Note: jump back to the start as the pPatchPage has been deleted or changed */
     
    49584971                            {
    49594972                                LogRel(("PATM: Disable block at %RRv - invalid write %RRv-%RRv \n", pPatch->pPrivInstrGC, GCPtr, GCPtr+cbWrite));
    4960                                 PATMR3MarkDirtyPatch(pVM, pPatch);
     4973                                patmR3MarkDirtyPatch(pVM, pPatch);
    49614974                            }
    49624975                            /* Note: jump back to the start as the pPatchPage has been deleted or changed */
     
    49824995/** @note Currently only called by CSAMR3FlushPage; optimization to avoid having to double check if the physical address has changed
    49834996 */
    4984 VMMR3DECL(int) PATMR3FlushPage(PVM pVM, RTRCPTR addr)
     4997VMMR3_INT_DECL(int) PATMR3FlushPage(PVM pVM, RTRCPTR addr)
    49854998{
    49864999    addr &= PAGE_BASE_GC_MASK;
     
    49995012
    50005013                Log(("PATMR3FlushPage %RRv remove patch at %RRv\n", addr, pPatch->pPrivInstrGC));
    5001                 PATMR3MarkDirtyPatch(pVM, pPatch);
     5014                patmR3MarkDirtyPatch(pVM, pPatch);
    50025015            }
    50035016        }
     
    50145027 * @param   pInstrGC    Guest context pointer to instruction
    50155028 */
    5016 VMMR3DECL(bool) PATMR3HasBeenPatched(PVM pVM, RTRCPTR pInstrGC)
     5029VMMR3_INT_DECL(bool) PATMR3HasBeenPatched(PVM pVM, RTRCPTR pInstrGC)
    50175030{
    50185031    PPATMPATCHREC pPatchRec;
     
    50775090 * @param   pcbRead     Where to return the acutal number of bytes read.
    50785091 */
    5079 VMMR3DECL(int) PATMR3ReadOrgInstr(PVM pVM, RTGCPTR32 GCPtrInstr, uint8_t *pbDst, size_t cbToRead, size_t *pcbRead)
     5092VMMR3_INT_DECL(int) PATMR3ReadOrgInstr(PVM pVM, RTGCPTR32 GCPtrInstr, uint8_t *pbDst, size_t cbToRead, size_t *pcbRead)
    50805093{
    50815094    /* Shortcut. */
     
    51345147 *
    51355148 */
    5136 VMMR3DECL(int) PATMR3DisablePatch(PVM pVM, RTRCPTR pInstrGC)
     5149VMMR3_INT_DECL(int) PATMR3DisablePatch(PVM pVM, RTRCPTR pInstrGC)
    51375150{
    51385151    PPATMPATCHREC pPatchRec;
     
    52935306
    52945307    RT_ZERO(patch);
    5295     pInstrHC = PATMGCVirtToHCVirt(pVM, &patch, pInstrGC);
     5308    pInstrHC = patmR3GCVirtToHCVirt(pVM, &patch, pInstrGC);
    52965309    disret = patmR3DisInstr(pVM, &patch, pInstrGC, pInstrHC, PATMREAD_ORGCODE, &cpu, &cbInstr);
    52975310    /*
     
    53805393 *
    53815394 */
    5382 VMMR3DECL(int) PATMR3EnablePatch(PVM pVM, RTRCPTR pInstrGC)
     5395VMMR3_INT_DECL(int) PATMR3EnablePatch(PVM pVM, RTRCPTR pInstrGC)
    53835396{
    53845397    PPATMPATCHREC pPatchRec;
     
    54995512 * @param   fForceRemove    Remove *all* patches
    55005513 */
    5501 int PATMRemovePatch(PVM pVM, PPATMPATCHREC pPatchRec, bool fForceRemove)
     5514int patmR3RemovePatch(PVM pVM, PPATMPATCHREC pPatchRec, bool fForceRemove)
    55025515{
    55035516    PPATCHINFO    pPatch;
     
    57115724
    57125725        /* Remove old patch (only do that when everything is finished) */
    5713         int rc2 = PATMRemovePatch(pVM, pPatchRec, true /* force removal */);
     5726        int rc2 = patmR3RemovePatch(pVM, pPatchRec, true /* force removal */);
    57145727        AssertRC(rc2);
    57155728
     
    57885801 *
    57895802 */
    5790 PPATCHINFO PATMFindActivePatchByEntrypoint(PVM pVM, RTRCPTR pInstrGC, bool fIncludeHints)
     5803PPATCHINFO patmFindActivePatchByEntrypoint(PVM pVM, RTRCPTR pInstrGC, bool fIncludeHints)
    57915804{
    57925805    PPATMPATCHREC pPatchRec = (PPATMPATCHREC)RTAvloU32GetBestFit(&pVM->patm.s.PatchLookupTreeHC->PatchTree, pInstrGC, false);
     
    58215834 * @returns true -> yes, false -> no
    58225835 * @param   pVM         Pointer to the VM.
    5823  * @param   pAddr       Guest context address
    5824  * @param   pPatchAddr  Guest context patch address (if true)
    5825  */
    5826 VMMR3DECL(bool) PATMR3IsInsidePatchJump(PVM pVM, RTRCPTR pAddr, PRTGCPTR32 pPatchAddr)
     5836 * @param   pAddr       Guest context address.
     5837 * @param   pPatchAddr  Guest context patch address (if true).
     5838 */
     5839VMMR3_INT_DECL(bool) PATMR3IsInsidePatchJump(PVM pVM, RTRCPTR pAddr, PRTGCPTR32 pPatchAddr)
    58275840{
    58285841    RTRCPTR addr;
     
    58375850    *pPatchAddr = 0;
    58385851
    5839     pPatch = PATMFindActivePatchByEntrypoint(pVM, pAddr);
     5852    pPatch = patmFindActivePatchByEntrypoint(pVM, pAddr);
    58405853    if (pPatch)
    58415854        *pPatchAddr = pPatch->pPrivInstrGC;
     
    58545867 *
    58555868 */
    5856 VMMR3DECL(int) PATMR3RemovePatch(PVM pVM, RTRCPTR pInstrGC)
     5869VMMR3_INT_DECL(int) PATMR3RemovePatch(PVM pVM, RTRCPTR pInstrGC)
    58575870{
    58585871    PPATMPATCHREC pPatchRec;
     
    58655878            return VINF_SUCCESS;
    58665879
    5867         return PATMRemovePatch(pVM, pPatchRec, false);
     5880        return patmR3RemovePatch(pVM, pPatchRec, false);
    58685881    }
    58695882    AssertFailed();
     
    58815894 *
    58825895 */
    5883 VMMR3DECL(int) PATMR3MarkDirtyPatch(PVM pVM, PPATCHINFO pPatch)
     5896static int patmR3MarkDirtyPatch(PVM pVM, PPATCHINFO pPatch)
    58845897{
    58855898    if (pPatch->pPatchBlockOffset)
     
    59525965}
    59535966
    5954 /* Converts Guest code GC ptr to Patch code GC ptr (or nearest from below if no identical match)
     5967/**
     5968 * Converts Guest code GC ptr to Patch code GC ptr (if found)
     5969 *
     5970 * @returns corresponding GC pointer in patch block
     5971 * @param   pVM         Pointer to the VM.
     5972 * @param   pInstrGC    Guest context pointer to privileged instruction
     5973 */
     5974static RTRCPTR patmR3GuestGCPtrToPatchGCPtrSimple(PVM pVM, RCPTRTYPE(uint8_t*) pInstrGC)
     5975{
     5976    PPATMPATCHREC pPatchRec = (PPATMPATCHREC)RTAvloU32GetBestFit(&pVM->patm.s.PatchLookupTreeHC->PatchTree, pInstrGC, false);
     5977    if (pPatchRec && pPatchRec->patch.uState == PATCH_ENABLED && pInstrGC >= pPatchRec->patch.pPrivInstrGC)
     5978        return patmGuestGCPtrToPatchGCPtr(pVM, &pPatchRec->patch, pInstrGC);
     5979    return NIL_RTRCPTR;
     5980}
     5981
     5982/**
     5983 * Converts Guest code GC ptr to Patch code GC ptr (or nearest from below if no
     5984 * identical match)
    59555985 *
    59565986 * @returns corresponding GC pointer in patch block
     
    59625992RTRCPTR patmGuestGCPtrToClosestPatchGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t*) pInstrGC)
    59635993{
    5964         PRECGUESTTOPATCH pGuestToPatchRec = (PRECGUESTTOPATCH)RTAvlU32GetBestFit(&pPatch->Guest2PatchAddrTree, pInstrGC, false);
    5965         if (pGuestToPatchRec)
    5966             return pVM->patm.s.pPatchMemGC + pGuestToPatchRec->PatchOffset;
    5967 
    5968     return 0;
    5969 }
    5970 
    5971 /* Converts Guest code GC ptr to Patch code GC ptr (if found)
    5972  *
    5973  * @returns corresponding GC pointer in patch block
    5974  * @param   pVM         Pointer to the VM.
    5975  * @param   pInstrGC    Guest context pointer to privileged instruction
    5976  *
    5977  */
    5978 VMMR3DECL(RTRCPTR) PATMR3GuestGCPtrToPatchGCPtr(PVM pVM, RCPTRTYPE(uint8_t*) pInstrGC)
    5979 {
    5980     PPATMPATCHREC pPatchRec = (PPATMPATCHREC)RTAvloU32GetBestFit(&pVM->patm.s.PatchLookupTreeHC->PatchTree, pInstrGC, false);
    5981     if (pPatchRec && pPatchRec->patch.uState == PATCH_ENABLED && pInstrGC >= pPatchRec->patch.pPrivInstrGC)
    5982         return patmGuestGCPtrToPatchGCPtr(pVM, &pPatchRec->patch, pInstrGC);
    5983     else
    5984         return 0;
     5994    PRECGUESTTOPATCH pGuestToPatchRec = (PRECGUESTTOPATCH)RTAvlU32GetBestFit(&pPatch->Guest2PatchAddrTree, pInstrGC, false);
     5995    if (pGuestToPatchRec)
     5996        return pVM->patm.s.pPatchMemGC + pGuestToPatchRec->PatchOffset;
     5997    return NIL_RTRCPTR;
    59855998}
    59865999
     
    59946007 *
    59956008 */
    5996 VMMR3DECL(RTRCPTR) PATMR3PatchToGCPtr(PVM pVM, RTRCPTR pPatchGC, PATMTRANSSTATE *pEnmState)
     6009VMMR3_INT_DECL(RTRCPTR) PATMR3PatchToGCPtr(PVM pVM, RTRCPTR pPatchGC, PATMTRANSSTATE *pEnmState)
    59976010{
    59986011    PPATMPATCHREC pPatchRec;
     
    60386051        }
    60396052        else
    6040         if (PATMFindActivePatchByEntrypoint(pVM, pPrivInstrGC))
     6053        if (patmFindActivePatchByEntrypoint(pVM, pPrivInstrGC))
    60416054        {
    60426055            *pEnmState = PATMTRANS_OVERWRITTEN;
     
    60606073 * @param   pAddrGC     Guest context address
    60616074 */
    6062 VMMR3DECL(RTRCPTR) PATMR3QueryPatchGCPtr(PVM pVM, RTRCPTR pAddrGC)
     6075VMMR3_INT_DECL(RTRCPTR) PATMR3QueryPatchGCPtr(PVM pVM, RTRCPTR pAddrGC)
    60636076{
    60646077    PPATMPATCHREC pPatchRec;
     
    60696082    if (pPatchRec && (pPatchRec->patch.uState == PATCH_ENABLED || pPatchRec->patch.uState == PATCH_DIRTY))
    60706083        return PATCHCODE_PTR_GC(&pPatchRec->patch);
    6071     else
    6072         return 0;
     6084    return NIL_RTRCPTR;
    60736085}
    60746086
     
    62036215
    62046216                /* Add a new lookup record for the duplicated instruction. */
    6205                 patmr3AddP2GLookupRecord(pVM, &pPatch->patch, pCurPatchInstrHC, pCurInstrGC, PATM_LOOKUP_BOTHDIR);
     6217                patmR3AddP2GLookupRecord(pVM, &pPatch->patch, pCurPatchInstrHC, pCurInstrGC, PATM_LOOKUP_BOTHDIR);
    62066218            }
    62076219            else
     
    62146226#endif
    62156227                /* Restore the old lookup record for the duplicated instruction. */
    6216                 patmr3AddP2GLookupRecord(pVM, &pPatch->patch, pCurPatchInstrHC, pCurInstrGC, PATM_LOOKUP_BOTHDIR);
     6228                patmR3AddP2GLookupRecord(pVM, &pPatch->patch, pCurPatchInstrHC, pCurInstrGC, PATM_LOOKUP_BOTHDIR);
    62176229
    62186230                /** @todo in theory we need to restore the lookup records for the remaining dirty instructions too! */
     
    63096321 * @param   ppNewEip    GC pointer to new instruction.
    63106322 */
    6311 VMMR3DECL(int) PATMR3HandleTrap(PVM pVM, PCPUMCTX pCtx, RTRCPTR pEip, RTGCPTR *ppNewEip)
     6323VMMR3_INT_DECL(int) PATMR3HandleTrap(PVM pVM, PCPUMCTX pCtx, RTRCPTR pEip, RTGCPTR *ppNewEip)
    63126324{
    63136325    PPATMPATCHREC    pPatch = 0;
     
    65086520        cacheRec.pPatch = &pPatch->patch;
    65096521
    6510         disret = patmR3DisInstr(pVM, &pPatch->patch, pNewEip, PATMGCVirtToHCVirt(pVM, &cacheRec, pNewEip), PATMREAD_RAWCODE,
     6522        disret = patmR3DisInstr(pVM, &pPatch->patch, pNewEip, patmR3GCVirtToHCVirt(pVM, &cacheRec, pNewEip), PATMREAD_RAWCODE,
    65116523                                &cpu, &cbInstr);
    65126524        if (cacheRec.Lock.pvMap)
     
    65476559        cacheRec.pPatch = &pPatch->patch;
    65486560
    6549         disret = patmR3DisInstr(pVM, &pPatch->patch, pNewEip, PATMGCVirtToHCVirt(pVM, &cacheRec, pNewEip), PATMREAD_ORGCODE,
     6561        disret = patmR3DisInstr(pVM, &pPatch->patch, pNewEip, patmR3GCVirtToHCVirt(pVM, &cacheRec, pNewEip), PATMREAD_ORGCODE,
    65506562                                &cpu, &cbInstr);
    65516563        if (cacheRec.Lock.pvMap)
     
    65546566        if (disret && (cpu.pCurInstr->uOpcode == OP_SYSEXIT || cpu.pCurInstr->uOpcode == OP_HLT || cpu.pCurInstr->uOpcode == OP_INT3))
    65556567        {
    6556             disret = patmR3DisInstr(pVM, &pPatch->patch, pNewEip, PATMGCVirtToHCVirt(pVM, &cacheRec, pNewEip), PATMREAD_RAWCODE,
     6568            disret = patmR3DisInstr(pVM, &pPatch->patch, pNewEip, patmR3GCVirtToHCVirt(pVM, &cacheRec, pNewEip), PATMREAD_RAWCODE,
    65576569                                    &cpu, &cbInstr);
    65586570            if (cacheRec.Lock.pvMap)
     
    66016613 * @param   pVM         Pointer to the VM.
    66026614 */
    6603 VMMR3DECL(int) PATMR3HandleMonitoredPage(PVM pVM)
     6615VMMR3_INT_DECL(int) PATMR3HandleMonitoredPage(PVM pVM)
    66046616{
    66056617    RTRCPTR addr = pVM->patm.s.pvFaultMonitor;
     
    67756787
    67766788    RTAvloU32DoWithAll(&pVM->patm.s.PatchLookupTreeHC->PatchTree, true, DisableAllPatches, pVM);
    6777     PATMR3AllowPatching(pVM, false);
     6789    PATMR3AllowPatching(pVM->pUVM, false);
    67786790    return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Patching disabled\n");
    67796791}
     
    67986810        return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: The command requires VM to be selected.\n");
    67996811
    6800     PATMR3AllowPatching(pVM, true);
     6812    PATMR3AllowPatching(pVM->pUVM, true);
    68016813    RTAvloU32DoWithAll(&pVM->patm.s.PatchLookupTreeHC->PatchTree, true, EnableAllPatches, pVM);
    68026814    return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Patching enabled\n");
  • trunk/src/VBox/VMM/VMMR3/PATMGuest.cpp

    r41965 r44362  
    195195    /* Found it; patch the push cs */
    196196    pPatchRec->patch.flags &= ~(PATMFL_GUEST_SPECIFIC);  /* prevent a breakpoint from being triggered */
    197     return PATMR3PatchInstrInt3(pVM, pInstrGC, pInstrHC, pCpu, &pPatchRec->patch);
     197    return patmR3PatchInstrInt3(pVM, pInstrGC, pInstrHC, pCpu, &pPatchRec->patch);
    198198}
    199199
     
    210210 *
    211211 */
    212 int PATMInstallGuestSpecificPatch(PVM pVM, PDISCPUSTATE pCpu, RTGCPTR32 pInstrGC, uint8_t *pInstrHC, PPATMPATCHREC pPatchRec)
     212int patmR3InstallGuestSpecificPatch(PVM pVM, PDISCPUSTATE pCpu, RTGCPTR32 pInstrGC, uint8_t *pInstrHC, PPATMPATCHREC pPatchRec)
    213213{
    214214    int rc;
  • trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp

    r42481 r44362  
    374374        /* Add lookup record for patch to guest address translation */
    375375        Assert(pPB[pAsmRecord->offJump - 1] == 0xE9);
    376         patmr3AddP2GLookupRecord(pVM, pPatch, &pPB[pAsmRecord->offJump - 1], pReturnAddrGC, PATM_LOOKUP_PATCH2GUEST);
     376        patmR3AddP2GLookupRecord(pVM, pPatch, &pPB[pAsmRecord->offJump - 1], pReturnAddrGC, PATM_LOOKUP_PATCH2GUEST);
    377377
    378378        *(uint32_t *)&pPB[pAsmRecord->offJump] = displ;
     
    637637        /* If interrupted here, then jump to the target instruction. Used by PATM.cpp for jumping to known instructions. */
    638638        /* Add lookup record for patch to guest address translation */
    639         patmr3AddP2GLookupRecord(pVM, pPatch, pPB, pTargetGC, PATM_LOOKUP_PATCH2GUEST);
     639        patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pTargetGC, PATM_LOOKUP_PATCH2GUEST);
    640640
    641641        pPB[0] = 0xE9;
     
    866866
    867867    /* Jump back to the original instruction if IF is set again. */
    868     Assert(!PATMFindActivePatchByEntrypoint(pVM, pCurInstrGC));
     868    Assert(!patmFindActivePatchByEntrypoint(pVM, pCurInstrGC));
    869869    rc = patmPatchGenCheckIF(pVM, pPatch, pCurInstrGC);
    870870    AssertRCReturn(rc, rc);
     
    979979
    980980    /* Add lookup record for patch to guest address translation */
    981     patmr3AddP2GLookupRecord(pVM, pPatch, pPB, pCurInstrGC, PATM_LOOKUP_PATCH2GUEST);
     981    patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pCurInstrGC, PATM_LOOKUP_PATCH2GUEST);
    982982
    983983    /* Generate code to check for IF=1 before executing the call to the duplicated function. */
     
    10021002
    10031003    /* Add lookup record for patch to guest address translation */
    1004     patmr3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
     1004    patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
    10051005
    10061006    int size = patmPatchGenCode(pVM, pPatch, pPB, &PATMSetPIFRecord, 0, false);
     
    10231023
    10241024    /* Add lookup record for patch to guest address translation */
    1025     patmr3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
     1025    patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
    10261026
    10271027    int size = patmPatchGenCode(pVM, pPatch, pPB, &PATMClearPIFRecord, 0, false);
     
    10491049
    10501050    /* Add lookup record for patch to guest address translation */
    1051     patmr3AddP2GLookupRecord(pVM, pPatch, pPB, pNextInstrGC, PATM_LOOKUP_PATCH2GUEST);
     1051    patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pNextInstrGC, PATM_LOOKUP_PATCH2GUEST);
    10521052
    10531053    callInfo.pNextInstrGC = pNextInstrGC;
     
    10801080
    10811081    /* Add lookup record for patch to guest address translation */
    1082     patmr3AddP2GLookupRecord(pVM, pPatch, pPB, pIntHandlerGC, PATM_LOOKUP_PATCH2GUEST);
     1082    patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pIntHandlerGC, PATM_LOOKUP_PATCH2GUEST);
    10831083
    10841084    /* Generate entrypoint for the interrupt handler (correcting CS in the interrupt stack frame) */
     
    11111111
    11121112    /* Add lookup record for patch to guest address translation */
    1113     patmr3AddP2GLookupRecord(pVM, pPatch, pPB, pTrapHandlerGC, PATM_LOOKUP_PATCH2GUEST);
     1113    patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pTrapHandlerGC, PATM_LOOKUP_PATCH2GUEST);
    11141114
    11151115    /* Generate entrypoint for the trap handler (correcting CS in the interrupt stack frame) */
     
    11301130
    11311131    /* Add lookup record for stats code -> guest handler. */
    1132     patmr3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
     1132    patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);
    11331133
    11341134    /* Generate code to keep calling statistics for this patch */
     
    15451545
    15461546    /* Add lookup record for patch to guest address translation */
    1547     patmr3AddP2GLookupRecord(pVM, pPatch, pPB, pReturnAddrGC, PATM_LOOKUP_PATCH2GUEST);
     1547    patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pReturnAddrGC, PATM_LOOKUP_PATCH2GUEST);
    15481548
    15491549    /* Generate code to jump to guest code if IF=1, else fault. */
     
    15681568    {
    15691569        /* Add lookup record for patch to guest address translation */
    1570         patmr3AddP2GLookupRecord(pVM, pPatch, pPB, pCurInstrGC, PATM_LOOKUP_PATCH2GUEST);
     1570        patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pCurInstrGC, PATM_LOOKUP_PATCH2GUEST);
    15711571    }
    15721572
  • trunk/src/VBox/VMM/VMMR3/PATMSSM.cpp

    r41965 r44362  
    829829        cacheRec.pPatch = &pPatchRec->patch;
    830830
    831         uint8_t *pPrivInstrHC = PATMGCVirtToHCVirt(pVM, &cacheRec, pPatchRec->patch.pPrivInstrGC);
     831        uint8_t *pPrivInstrHC = patmR3GCVirtToHCVirt(pVM, &cacheRec, pPatchRec->patch.pPrivInstrGC);
    832832        /* Can fail due to page or page table not present. */
    833833
     
    895895                AssertRCReturn(rc, rc);
    896896
    897                 patmr3AddP2GLookupRecord(pVM, &pPatchRec->patch, (uintptr_t)rec.Core.Key + pVM->patm.s.pPatchMemHC, rec.pOrgInstrGC, rec.enmType, rec.fDirty);
     897                patmR3AddP2GLookupRecord(pVM, &pPatchRec->patch, (uintptr_t)rec.Core.Key + pVM->patm.s.pPatchMemHC, rec.pOrgInstrGC, rec.enmType, rec.fDirty);
    898898            }
    899899            Assert(pPatchRec->patch.Patch2GuestAddrTree);
  • trunk/src/VBox/VMM/VMMRC/CSAMRC.cpp

    r41965 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    109109    if (cpl != 3)
    110110    {
    111         rc = PATMGCHandleWriteToPatchPage(pVM, pRegFrame, (RTRCPTR)((RTRCUINTPTR)pvRange + offRange), 4 /** @todo */);
     111        rc = PATMRCHandleWriteToPatchPage(pVM, pRegFrame, (RTRCPTR)((RTRCUINTPTR)pvRange + offRange), 4 /** @todo */);
    112112        if (rc == VINF_SUCCESS)
    113113            return rc;
  • trunk/src/VBox/VMM/VMMRC/PATMRC.cpp

    r42706 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    7676 *
    7777 */
    78 VMMRCDECL(int) PATMGCHandleWriteToPatchPage(PVM pVM, PCPUMCTXCORE pRegFrame, RTRCPTR GCPtr, uint32_t cbWrite)
     78VMMRCDECL(int) PATMRCHandleWriteToPatchPage(PVM pVM, PCPUMCTXCORE pRegFrame, RTRCPTR GCPtr, uint32_t cbWrite)
    7979{
    8080    RTGCUINTPTR          pWritePageStart, pWritePageEnd;
     
    148148 * @param   pCtxCore    The relevant core context.
    149149 */
    150 VMMDECL(int) PATMRCHandleIllegalInstrTrap(PVM pVM, PCPUMCTXCORE pRegFrame)
     150VMMRC_INT_DECL(int) PATMRCHandleIllegalInstrTrap(PVM pVM, PCPUMCTXCORE pRegFrame)
    151151{
    152152    PPATMPATCHREC pRec;
     
    186186                Log(("PATMRC: lookup %x jump table=%x\n", pRegFrame->edx, pRegFrame->edi));
    187187
    188                 pRec = PATMQueryFunctionPatch(pVM, (RTRCPTR)(pRegFrame->edx));
     188                pRec = patmQueryFunctionPatch(pVM, (RTRCPTR)pRegFrame->edx);
    189189                if (pRec)
    190190                {
     
    192192                    {
    193193                        RTGCUINTPTR pRelAddr = pRec->patch.pPatchBlockOffset;   /* make it relative */
    194                         rc = PATMAddBranchToLookupCache(pVM, (RTRCPTR)pRegFrame->edi, (RTRCPTR)pRegFrame->edx, pRelAddr);
     194                        rc = patmAddBranchToLookupCache(pVM, (RTRCPTR)pRegFrame->edi, (RTRCPTR)pRegFrame->edx, pRelAddr);
    195195                        if (rc == VINF_SUCCESS)
    196196                        {
     
    450450 * @param   pCtxCore    The relevant core context.
    451451 */
    452 VMMRCDECL(int) PATMRCHandleInt3PatchTrap(PVM pVM, PCPUMCTXCORE pRegFrame)
     452VMMRC_INT_DECL(int) PATMRCHandleInt3PatchTrap(PVM pVM, PCPUMCTXCORE pRegFrame)
    453453{
    454454    PPATMPATCHREC pRec;
  • trunk/src/VBox/VMM/VMMRC/PDMRCDevice.cpp

    r41965 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2011 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/VMM/VMMRC/TRPMRCHandlers.cpp

    r42779 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/VMM/include/EMHandleRCTmpl.h

    r43394 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2009 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/VMM/include/PATMInternal.h

    r41897 r44362  
    55
    66/*
    7  * Copyright (C) 2006-2012 Oracle Corporation
     7 * Copyright (C) 2006-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3030
    3131
    32 
     32/** @name Saved state version numbers.
     33 * @{ */
    3334#define PATM_SSM_VERSION                    55
    3435#define PATM_SSM_VERSION_FIXUP_HACK         54
    3536#define PATM_SSM_VERSION_FIXUP_HACK         54
    3637#define PATM_SSM_VERSION_VER16              53
     38/** @}  */
    3739
    3840/* Enable for call patching. */
     
    554556
    555557#ifdef IN_RING3
    556 RTRCPTR patmPatchGCPtr2GuestGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t *) pPatchGC);
    557 RTRCPTR patmGuestGCPtrToPatchGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t*) pInstrGC);
    558 RTRCPTR patmGuestGCPtrToClosestPatchGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t*) pInstrGC);
    559 #endif
    560 
    561 /* Add a patch to guest lookup record
    562  *
    563  * @param   pVM             Pointer to the VM.
    564  * @param   pPatch          Patch structure ptr
    565  * @param   pPatchInstrHC   Guest context pointer to patch block
    566  * @param   pInstrGC        Guest context pointer to privileged instruction
    567  * @param   enmType         Lookup type
    568  * @param   fDirty          Dirty flag
    569  *
    570  */
    571 void patmr3AddP2GLookupRecord(PVM pVM, PPATCHINFO pPatch, uint8_t *pPatchInstrHC, RTRCPTR pInstrGC, PATM_LOOKUP_TYPE enmType, bool fDirty=false);
    572 
    573 /**
    574  * Insert page records for all guest pages that contain instructions that were recompiled for this patch
    575  *
    576  * @returns VBox status code.
    577  * @param   pVM         Pointer to the VM.
    578  * @param   pPatch      Patch record
    579  */
    580 int patmInsertPatchPages(PVM pVM, PPATCHINFO pPatch);
    581 
    582 /**
    583  * Remove page records for all guest pages that contain instructions that were recompiled for this patch
    584  *
    585  * @returns VBox status code.
    586  * @param   pVM         Pointer to the VM.
    587  * @param   pPatch      Patch record
    588  */
    589 int patmRemovePatchPages(PVM pVM, PPATCHINFO pPatch);
    590 
    591 /**
    592  * Returns the GC address of the corresponding patch statistics counter
    593  *
    594  * @returns Stat address
    595  * @param   pVM         Pointer to the VM.
    596  * @param   pPatch      Patch structure
    597  */
    598 RTRCPTR patmPatchQueryStatAddress(PVM pVM, PPATCHINFO pPatch);
    599 
    600 /**
    601  * Remove patch for privileged instruction at specified location
    602  *
    603  * @returns VBox status code.
    604  * @param   pVM             Pointer to the VM.
    605  * @param   pPatchRec       Patch record
    606  * @param   fForceRemove    Remove *all* patches
    607  */
    608 int PATMRemovePatch(PVM pVM, PPATMPATCHREC pPatchRec, bool fForceRemove);
     558RTRCPTR         patmPatchGCPtr2GuestGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t *) pPatchGC);
     559RTRCPTR         patmGuestGCPtrToPatchGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t*) pInstrGC);
     560RTRCPTR         patmGuestGCPtrToClosestPatchGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t*) pInstrGC);
     561#endif
     562
     563void            patmR3AddP2GLookupRecord(PVM pVM, PPATCHINFO pPatch, uint8_t *pPatchInstrHC, RTRCPTR pInstrGC,
     564                                         PATM_LOOKUP_TYPE enmType, bool fDirty = false);
     565int             patmInsertPatchPages(PVM pVM, PPATCHINFO pPatch);
     566RTRCPTR         patmPatchQueryStatAddress(PVM pVM, PPATCHINFO pPatch);
     567int             patmR3RemovePatch(PVM pVM, PPATMPATCHREC pPatchRec, bool fForceRemove);
    609568
    610569/**
     
    621580typedef int (VBOXCALL *PFN_PATMR3ANALYSE)(PVM pVM, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pInstrGC, RCPTRTYPE(uint8_t *) pCurInstrGC, PPATMP2GLOOKUPREC pCacheRec);
    622581
    623 /**
    624  * Install guest OS specific patch
    625  *
    626  * @returns VBox status code.
    627  * @param   pVM         Pointer to the VM.
    628  * @param   pCpu        Disassembly state of instruction.
    629  * @param   pInstrGC    GC Instruction pointer for instruction
    630  * @param   pInstrHC    GC Instruction pointer for instruction
    631  * @param   pPatchRec   Patch structure
    632  *
    633  */
    634 int PATMInstallGuestSpecificPatch(PVM pVM, PDISCPUSTATE pCpu, RTRCPTR pInstrGC, uint8_t *pInstrHC, PPATMPATCHREC pPatchRec);
    635 
    636 
    637 /**
    638  * Check if the instruction is patched as a duplicated function
    639  *
    640  * @returns patch record
    641  * @param   pVM         Pointer to the VM.
    642  * @param   pInstrGC    Guest context point to the instruction
    643  *
    644  */
    645 VMMDECL(PPATMPATCHREC) PATMQueryFunctionPatch(PVM pVM, RTRCPTR pInstrGC);
    646 
    647 
    648 /**
    649  * Empty the specified tree (PV tree, MMR3 heap)
    650  *
    651  * @param   pVM             Pointer to the VM.
    652  * @param   ppTree          Tree to empty
    653  */
    654 void patmEmptyTree(PVM pVM, PPAVLPVNODECORE ppTree);
    655 
    656 
    657 /**
    658  * Empty the specified tree (U32 tree, MMR3 heap)
    659  *
    660  * @param   pVM             Pointer to the VM.
    661  * @param   ppTree          Tree to empty
    662  */
    663 void patmEmptyTreeU32(PVM pVM, PPAVLU32NODECORE ppTree);
    664 
    665 
    666 /**
    667  * Return the name of the patched instruction
    668  *
    669  * @returns instruction name
    670  *
    671  * @param   opcode      DIS instruction opcode
    672  * @param   fPatchFlags Patch flags
    673  */
    674 VMMDECL(const char *) patmGetInstructionString(uint32_t opcode, uint32_t fPatchFlags);
    675 
    676 
     582int             patmR3InstallGuestSpecificPatch(PVM pVM, PDISCPUSTATE pCpu, RTRCPTR pInstrGC, uint8_t *pInstrHC, PPATMPATCHREC pPatchRec);
     583PPATMPATCHREC   patmQueryFunctionPatch(PVM pVM, RTRCPTR pInstrGC);
     584const char     *patmGetInstructionString(uint32_t opcode, uint32_t fPatchFlags);
     585
     586PPATCHINFO      patmFindActivePatchByEntrypoint(PVM pVM, RTRCPTR pInstrGC, bool fIncludeHints = false);
     587int             patmR3PatchInstrInt3(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC, DISCPUSTATE *pCpu, PPATCHINFO pPatch);
     588int             patmAddBranchToLookupCache(PVM pVM, RTRCPTR pJumpTableGC, RTRCPTR pBranchTarget, RTRCUINTPTR pRelBranchPatch);
     589R3PTRTYPE(uint8_t *) patmR3GCVirtToHCVirt(PVM pVM, PPATMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr);
    677590
    678591RT_C_DECLS_BEGIN
     
    691604VMMRCDECL(int) PATMGCMonitorPage(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
    692605
    693 /**
    694  * Find patch for privileged instruction at specified location
    695  *
    696  * @returns Patch structure pointer if found; else NULL
    697  * @param   pVM           Pointer to the VM.
    698  * @param   pInstr        Guest context point to instruction that might lie within 5 bytes of an existing patch jump
    699  * @param   fIncludeHints Include hinted patches or not
    700  *
    701  */
    702 PPATCHINFO PATMFindActivePatchByEntrypoint(PVM pVM, RTRCPTR pInstrGC, bool fIncludeHints=false);
    703 
    704 /**
    705  * Patch cli/sti pushf/popf instruction block at specified location
    706  *
    707  * @returns VBox status code.
    708  * @param   pVM         Pointer to the VM.
    709  * @param   pInstrGC    Guest context point to privileged instruction
    710  * @param   pInstrHC    Host context point to privileged instruction
    711  * @param   uOpcode     Instruction opcodee
    712  * @param   uOpSize     Size of starting instruction
    713  * @param   pPatchRec   Patch record
    714  *
    715  * @note    returns failure if patching is not allowed or possible
    716  *
    717  */
    718 VMMR3DECL(int) PATMR3PatchBlock(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC,
    719                                  uint32_t uOpcode, uint32_t uOpSize, PPATMPATCHREC pPatchRec);
    720 
    721 
    722 /**
    723  * Replace an instruction with a breakpoint (0xCC), that is handled dynamically in the guest context.
    724  *
    725  * @returns VBox status code.
    726  * @param   pVM         Pointer to the VM.
    727  * @param   pInstrGC    Guest context point to privileged instruction
    728  * @param   pInstrHC    Host context point to privileged instruction
    729  * @param   pCpu        Disassembly CPU structure ptr
    730  * @param   pPatch      Patch record
    731  *
    732  * @note    returns failure if patching is not allowed or possible
    733  *
    734  */
    735 VMMR3DECL(int) PATMR3PatchInstrInt3(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC, DISCPUSTATE *pCpu, PPATCHINFO pPatch);
    736 
    737 /**
    738  * Mark patch as dirty
    739  *
    740  * @returns VBox status code.
    741  * @param   pVM         Pointer to the VM.
    742  * @param   pPatch      Patch record
    743  *
    744  * @note    returns failure if patching is not allowed or possible
    745  *
    746  */
    747 VMMR3DECL(int) PATMR3MarkDirtyPatch(PVM pVM, PPATCHINFO pPatch);
    748 
    749 R3PTRTYPE(uint8_t *) PATMGCVirtToHCVirt(PVM pVM, PPATMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr);
     606RT_C_DECLS_END
    750607
    751608/**
     
    756613 * @param   pBranchInstrGC  GC pointer of branch instruction
    757614 */
    758 inline RTRCPTR PATMResolveBranch(PDISCPUSTATE pCpu, RTRCPTR pBranchInstrGC)
     615DECLINLINE(RTRCPTR) PATMResolveBranch(PDISCPUSTATE pCpu, RTRCPTR pBranchInstrGC)
    759616{
    760617    uint32_t disp;
     
    785642}
    786643
    787 RT_C_DECLS_END
    788 
    789644#ifdef LOG_ENABLED
    790645int patmr3DisasmCallback(PVM pVM, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pInstrGC, RCPTRTYPE(uint8_t *) pCurInstrGC, PPATMP2GLOOKUPREC pCacheRec);
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