Changeset 44362 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Jan 24, 2013 9:11:05 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 83329
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/PATMAll.cpp
r41965 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 47 47 * @see pg_raw 48 48 */ 49 VMM DECL(void) PATMRawEnter(PVM pVM, PCPUMCTXCORE pCtxCore)49 VMM_INT_DECL(void) PATMRawEnter(PVM pVM, PCPUMCTXCORE pCtxCore) 50 50 { 51 51 bool fPatchCode = PATMIsPatchGCAddr(pVM, pCtxCore->eip); … … 118 118 * @see @ref pg_raw 119 119 */ 120 VMM DECL(void) PATMRawLeave(PVM pVM, PCPUMCTXCORE pCtxCore, int rawRC)120 VMM_INT_DECL(void) PATMRawLeave(PVM pVM, PCPUMCTXCORE pCtxCore, int rawRC) 121 121 { 122 122 bool fPatchCode = PATMIsPatchGCAddr(pVM, pCtxCore->eip); … … 158 158 if (enmState == PATMTRANS_SAFE) 159 159 { 160 Assert(! PATMFindActivePatchByEntrypoint(pVM, pOrgInstrGC));160 Assert(!patmFindActivePatchByEntrypoint(pVM, pOrgInstrGC)); 161 161 Log(("Switchback from %RRv to %RRv (Psp=%x)\n", pCtxCore->eip, pOrgInstrGC, CTXSUFF(pVM->patm.s.pGCState)->Psp)); 162 162 STAM_COUNTER_INC(&pVM->patm.s.StatSwitchBack); … … 210 210 * @param pCtxCore The context core. 211 211 */ 212 VMM DECL(uint32_t) PATMRawGetEFlags(PVM pVM, PCCPUMCTXCORE pCtxCore)212 VMM_INT_DECL(uint32_t) PATMRawGetEFlags(PVM pVM, PCCPUMCTXCORE pCtxCore) 213 213 { 214 214 uint32_t efl = pCtxCore->eflags.u32; … … 226 226 * @param efl The new EFLAGS value. 227 227 */ 228 VMM DECL(void) PATMRawSetEFlags(PVM pVM, PCPUMCTXCORE pCtxCore, uint32_t efl)228 VMM_INT_DECL(void) PATMRawSetEFlags(PVM pVM, PCPUMCTXCORE pCtxCore, uint32_t efl) 229 229 { 230 230 pVM->patm.s.CTXSUFF(pGCState)->uVMFlags = efl & PATM_VIRTUAL_FLAGS_MASK; … … 240 240 * @param pAddrGC Guest context address 241 241 */ 242 VMM DECL(bool) PATMShouldUseRawMode(PVM pVM, RTRCPTR pAddrGC)242 VMM_INT_DECL(bool) PATMShouldUseRawMode(PVM pVM, RTRCPTR pAddrGC) 243 243 { 244 244 return ( PATMIsEnabled(pVM) … … 252 252 * @param pVM Pointer to the VM. 253 253 */ 254 VMM DECL(RCPTRTYPE(PPATMGCSTATE)) PATMQueryGCState(PVM pVM)254 VMM_INT_DECL(RCPTRTYPE(PPATMGCSTATE)) PATMQueryGCState(PVM pVM) 255 255 { 256 256 return pVM->patm.s.pGCStateGC; … … 263 263 * @param pVM Pointer to the VM. 264 264 * @param pAddrGC Guest context address 265 * @internal 265 266 */ 266 267 VMMDECL(bool) PATMIsPatchGCAddr(PVM pVM, RTRCUINTPTR pAddrGC) … … 277 278 * @param pCachedData GC pointer to cached data 278 279 */ 279 VMM DECL(int) PATMSetMMIOPatchInfo(PVM pVM, RTGCPHYS GCPhys, RTRCPTR pCachedData)280 VMM_INT_DECL(int) PATMSetMMIOPatchInfo(PVM pVM, RTGCPHYS GCPhys, RTRCPTR pCachedData) 280 281 { 281 282 pVM->patm.s.mmio.GCPhys = GCPhys; … … 293 294 * @param pVM Pointer to the VM. 294 295 */ 295 VMM DECL(bool) PATMAreInterruptsEnabled(PVM pVM)296 VMM_INT_DECL(bool) PATMAreInterruptsEnabled(PVM pVM) 296 297 { 297 298 PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(VMMGetCpu(pVM)); … … 309 310 * @param pCtxCore CPU context 310 311 */ 311 VMM DECL(bool) PATMAreInterruptsEnabledByCtxCore(PVM pVM, PCPUMCTXCORE pCtxCore)312 VMM_INT_DECL(bool) PATMAreInterruptsEnabledByCtxCore(PVM pVM, PCPUMCTXCORE pCtxCore) 312 313 { 313 314 if (PATMIsEnabled(pVM)) … … 327 328 * 328 329 */ 329 VMMDECL(PPATMPATCHREC) PATMQueryFunctionPatch(PVM pVM, RTRCPTR pInstrGC)330 PPATMPATCHREC patmQueryFunctionPatch(PVM pVM, RTRCPTR pInstrGC) 330 331 { 331 332 PPATMPATCHREC pRec; … … 351 352 * @param pSize Original instruction size (out, optional) 352 353 */ 353 VMM DECL(bool) PATMIsInt3Patch(PVM pVM, RTRCPTR pInstrGC, uint32_t *pOpcode, uint32_t *pSize)354 VMM_INT_DECL(bool) PATMIsInt3Patch(PVM pVM, RTRCPTR pInstrGC, uint32_t *pOpcode, uint32_t *pSize) 354 355 { 355 356 PPATMPATCHREC pRec; … … 450 451 * @param pRelBranchPatch Relative duplicated function address 451 452 */ 452 VMMDECL(int) PATMAddBranchToLookupCache(PVM pVM, RTRCPTR pJumpTableGC, RTRCPTR pBranchTarget, RTRCUINTPTR pRelBranchPatch)453 int patmAddBranchToLookupCache(PVM pVM, RTRCPTR pJumpTableGC, RTRCPTR pBranchTarget, RTRCUINTPTR pRelBranchPatch) 453 454 { 454 455 PPATCHJUMPTABLE pJumpTable; … … 516 517 * @param fPatchFlags Patch flags 517 518 */ 518 VMMDECL(const char *)patmGetInstructionString(uint32_t opcode, uint32_t fPatchFlags)519 const char *patmGetInstructionString(uint32_t opcode, uint32_t fPatchFlags) 519 520 { 520 521 const char *pszInstr = NULL; -
trunk/src/VBox/VMM/VMMAll/TRPMAll.cpp
r42776 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/src/VBox/VMM/VMMR3/CPUM.cpp
r44170 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-201 2Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/src/VBox/VMM/VMMR3/CSAM.cpp
r43872 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-201 2Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 672 672 * Convert guest context address to host context pointer 673 673 * 674 * @returns VBox status code. 674 * @returns Byte pointer (ring-3 context) corresponding to pGCPtr on success, 675 * NULL on failure. 675 676 * @param pVM Pointer to the VM. 676 677 * @param pCacheRec Address conversion cache record … … 679 680 * 680 681 */ 681 static R3PTRTYPE(void *) CSAMGCVirtToHCVirt(PVM pVM, PCSAMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr)682 static uint8_t *csamR3GCVirtToHCVirt(PVM pVM, PCSAMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr) 682 683 { 683 684 int rc; 684 R3PTRTYPE(void *)pHCPtr;685 void *pHCPtr; 685 686 Assert(pVM->cCpus == 1); 686 687 PVMCPU pVCpu = VMMGetCpu0(pVM); … … 690 691 pHCPtr = PATMR3GCPtrToHCPtr(pVM, pGCPtr); 691 692 if (pHCPtr) 692 return pHCPtr;693 return (uint8_t *)pHCPtr; 693 694 694 695 if (pCacheRec->pPageLocStartHC) … … 717 718 } 718 719 719 pCacheRec->pPageLocStartHC = ( R3PTRTYPE(uint8_t*))((RTHCUINTPTR)pHCPtr & PAGE_BASE_HC_MASK);720 pCacheRec->pPageLocStartHC = (uint8_t*)((uintptr_t)pHCPtr & PAGE_BASE_HC_MASK); 720 721 pCacheRec->pGuestLoc = pGCPtr & PAGE_BASE_GC_MASK; 721 722 STAM_PROFILE_STOP(&pVM->csam.s.StatTimeAddrConv, a); 722 return pHCPtr;723 return (uint8_t *)pHCPtr; 723 724 } 724 725 … … 896 897 897 898 { /* 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); 900 900 if (pCurInstrHC == NULL) 901 901 { 902 Log((" CSAMGCVirtToHCVirt failed for %RRv\n", pCurInstrGC));902 Log(("csamR3GCVirtToHCVirt failed for %RRv\n", pCurInstrGC)); 903 903 break; 904 904 } … … 1078 1078 for (int j = 0; j < 16; j++) 1079 1079 { 1080 uint8_t *pCurInstrHC = (uint8_t *)CSAMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);1080 uint8_t *pCurInstrHC = csamR3GCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC); 1081 1081 if (pCurInstrHC == NULL) 1082 1082 { 1083 Log((" CSAMGCVirtToHCVirt failed for %RRv\n", pCurInstrGC));1083 Log(("csamR3GCVirtToHCVirt failed for %RRv\n", pCurInstrGC)); 1084 1084 goto done; 1085 1085 } … … 1290 1290 1291 1291 { /* 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); 1293 1293 if (pCurInstrHC == NULL) 1294 1294 { 1295 Log((" CSAMGCVirtToHCVirt failed for %RRv\n", pCurInstrGC));1295 Log(("csamR3GCVirtToHCVirt failed for %RRv\n", pCurInstrGC)); 1296 1296 rc = VERR_PATCHING_REFUSED; 1297 1297 goto done; … … 2325 2325 if (CSAMIsEnabled(pVM)) 2326 2326 { 2327 /* Cache record for CSAMGCVirtToHCVirt */2327 /* Cache record for csamR3GCVirtToHCVirt */ 2328 2328 CSAMP2GLOOKUPREC cacheRec; 2329 2329 RT_ZERO(cacheRec); … … 2491 2491 { 2492 2492 PCSAMPAGE pPage = NULL; 2493 CSAMP2GLOOKUPREC cacheRec; /* Cache record for CSAMGCVirtToHCVirt. */2493 CSAMP2GLOOKUPREC cacheRec; /* Cache record for csamR3GCVirtToHCVirt. */ 2494 2494 RT_ZERO(cacheRec); 2495 2495 … … 2548 2548 PCSAMPAGE pPage = NULL; 2549 2549 DBGFSELINFO selInfo; 2550 CSAMP2GLOOKUPREC cacheRec; /* Cache record for CSAMGCVirtToHCVirt. */2550 CSAMP2GLOOKUPREC cacheRec; /* Cache record for csamR3GCVirtToHCVirt. */ 2551 2551 RT_ZERO(cacheRec); 2552 2552 -
trunk/src/VBox/VMM/VMMR3/EM.cpp
r44340 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-201 1Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/src/VBox/VMM/VMMR3/EMRaw.cpp
r44340 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-201 2Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/src/VBox/VMM/VMMR3/HM.cpp
r44351 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-201 2Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 700 700 { 701 701 /* Disable PATM & CSAM. */ 702 PATMR3AllowPatching(pVM , false);702 PATMR3AllowPatching(pVM->pUVM, false); 703 703 CSAMDisableScanning(pVM); 704 704 -
trunk/src/VBox/VMM/VMMR3/PATM.cpp
r42781 r44362 3 3 * PATM - Dynamic Guest OS Patching Manager 4 4 * 5 * NOTE:Never ever reuse patch memory!!5 * @note Never ever reuse patch memory!! 6 6 */ 7 7 8 8 /* 9 * Copyright (C) 2006-201 2Oracle Corporation9 * Copyright (C) 2006-2013 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 35 35 #include <VBox/param.h> 36 36 #include <VBox/vmm/selm.h> 37 #include <VBox/vmm/csam.h> 37 38 #include <iprt/avl.h> 38 39 #include "PATMInternal.h" 39 40 #include "PATMPatch.h" 40 41 #include <VBox/vmm/vm.h> 41 #include <VBox/vmm/ csam.h>42 #include <VBox/vmm/uvm.h> 42 43 #include <VBox/dbg.h> 43 44 #include <VBox/err.h> … … 108 109 static int patmReinit(PVM pVM); 109 110 static DECLCALLBACK(int) RelocatePatches(PAVLOU32NODECORE pNode, void *pParam); 111 static RTRCPTR patmR3GuestGCPtrToPatchGCPtrSimple(PVM pVM, RCPTRTYPE(uint8_t*) pInstrGC); 112 static int patmR3MarkDirtyPatch(PVM pVM, PPATCHINFO pPatch); 110 113 111 114 #ifdef VBOX_WITH_DEBUGGER … … 132 135 * @param pVM Pointer to the VM. 133 136 */ 134 VMMR3 DECL(int) PATMR3Init(PVM pVM)137 VMMR3_INT_DECL(int) PATMR3Init(PVM pVM) 135 138 { 136 139 int rc; … … 308 311 * @param pVM Pointer to the VM. 309 312 */ 310 VMMR3 DECL(int) PATMR3InitFinalize(PVM pVM)313 VMMR3_INT_DECL(int) PATMR3InitFinalize(PVM pVM) 311 314 { 312 315 /* The GC state, stack and statistics must be read/write for the guest (supervisor only of course). */ … … 438 441 * @param pVM The VM. 439 442 */ 440 VMMR3 DECL(void) PATMR3Relocate(PVM pVM)443 VMMR3_INT_DECL(void) PATMR3Relocate(PVM pVM) 441 444 { 442 445 RTRCPTR GCPtrNew = MMHyperR3ToRC(pVM, pVM->patm.s.pGCStateHC); … … 493 496 * @param pVM Pointer to the VM. 494 497 */ 495 VMMR3 DECL(int) PATMR3Term(PVM pVM)498 VMMR3_INT_DECL(int) PATMR3Term(PVM pVM) 496 499 { 497 500 /* Memory was all allocated from the two MM heaps and requires no freeing. */ … … 507 510 * @param pVM The VM which is reset. 508 511 */ 509 VMMR3 DECL(int) PATMR3Reset(PVM pVM)512 VMMR3_INT_DECL(int) PATMR3Reset(PVM pVM) 510 513 { 511 514 Log(("PATMR3Reset\n")); … … 516 519 PPATMPATCHREC pPatchRec = (PPATMPATCHREC)RTAvloU32RemoveBestFit(&pVM->patm.s.PatchLookupTreeHC->PatchTree, 0, true); 517 520 if (pPatchRec) 518 { 519 PATMRemovePatch(pVM, pPatchRec, true); 520 } 521 patmR3RemovePatch(pVM, pPatchRec, true); 521 522 else 522 523 break; … … 921 922 } 922 923 923 924 924 #ifdef VBOX_WITH_DEBUGGER 925 925 926 /** 926 927 * Callback function for RTAvloU32DoWithAll … … 939 940 return 0; 940 941 } 941 #endif /* VBOX_WITH_DEBUGGER */ 942 943 944 #ifdef VBOX_WITH_DEBUGGER 942 943 945 944 /** 946 945 * Callback function for RTAvloU32DoWithAll … … 959 958 return 0; 960 959 } 961 #endif 960 961 #endif /* VBOX_WITH_DEBUGGER */ 962 #ifdef UNUSED_FUNCTIONS 962 963 963 964 /** 964 965 * 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 */ 972 VMMR3_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 */ 988 VMMR3_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 965 1000 * 966 1001 * @returns VBox status code. 967 1002 * @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 */ 1004 VMMR3_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 */ 1018 VMMR3_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 981 1028 * 982 1029 * @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 */ 1033 VMMR3DECL(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; 1030 1040 return VINF_SUCCESS; 1031 1041 } 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 */ 1050 VMMR3DECL(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 1032 1058 1033 1059 /** … … 1038 1064 * @param pAddrGC GC pointer 1039 1065 */ 1040 VMMR3 DECL(R3PTRTYPE(void *)) PATMR3GCPtrToHCPtr(PVM pVM, RTRCPTR pAddrGC)1066 VMMR3_INT_DECL(void *) PATMR3GCPtrToHCPtr(PVM pVM, RTRCPTR pAddrGC) 1041 1067 { 1042 1068 if (pVM->patm.s.pPatchMemGC <= pAddrGC && pVM->patm.s.pPatchMemGC + pVM->patm.s.cbPatchMem > pAddrGC) 1043 1069 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; 1057 1071 } 1058 1072 … … 1069 1083 * 1070 1084 */ 1071 R3PTRTYPE(uint8_t *) PATMGCVirtToHCVirt(PVM pVM, PPATMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr)1085 R3PTRTYPE(uint8_t *) patmR3GCVirtToHCVirt(PVM pVM, PPATMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr) 1072 1086 { 1073 1087 int rc; … … 1141 1155 /* Special case: call function replacement patch from this patch block. 1142 1156 */ 1143 PPATMPATCHREC pFunctionRec = PATMQueryFunctionPatch(pVM, pRec->pTargetGC);1157 PPATMPATCHREC pFunctionRec = patmQueryFunctionPatch(pVM, pRec->pTargetGC); 1144 1158 if (!pFunctionRec) 1145 1159 { … … 1244 1258 */ 1245 1259 /** @note Be extremely careful with this function. Make absolutely sure the guest address is correct! (to avoid executing instructions twice!) */ 1246 void patm r3AddP2GLookupRecord(PVM pVM, PPATCHINFO pPatch, uint8_t *pPatchInstrHC, RTRCPTR pInstrGC, PATM_LOOKUP_TYPE enmType, bool fDirty)1260 void patmR3AddP2GLookupRecord(PVM pVM, PPATCHINFO pPatch, uint8_t *pPatchInstrHC, RTRCPTR pInstrGC, PATM_LOOKUP_TYPE enmType, bool fDirty) 1247 1261 { 1248 1262 bool ret; … … 1349 1363 * @param ppTree Tree to empty 1350 1364 */ 1351 void patmEmptyTree(PVM pVM, PAVLPVNODECORE *ppTree)1365 static void patmEmptyTree(PVM pVM, PAVLPVNODECORE *ppTree) 1352 1366 { 1353 1367 NOREF(pVM); … … 1371 1385 * @param ppTree Tree to empty 1372 1386 */ 1373 void patmEmptyTreeU32(PVM pVM, PPAVLU32NODECORE ppTree)1387 static void patmEmptyTreeU32(PVM pVM, PPAVLU32NODECORE ppTree) 1374 1388 { 1375 1389 NOREF(pVM); … … 1694 1708 1695 1709 /* Add lookup record for patch to guest address translation */ 1696 patm r3AddP2GLookupRecord(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); 1697 1711 1698 1712 /* Update lowest and highest instruction address for this patch */ … … 1826 1840 pNextInstrGC = pCurInstrGC + pCpu->cbInstr; 1827 1841 { /* Force pNextInstrHC out of scope after using it */ 1828 uint8_t *pNextInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pNextInstrGC);1842 uint8_t *pNextInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pNextInstrGC); 1829 1843 if (pNextInstrHC == NULL) 1830 1844 { … … 2150 2164 2151 2165 { /* Force pOrgJumpHC out of scope after using it */ 2152 uint8_t *pOrgJumpHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pOrgJumpGC);2166 uint8_t *pOrgJumpHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pOrgJumpGC); 2153 2167 2154 2168 bool disret = patmR3DisInstr(pVM, pPatch, pOrgJumpGC, pOrgJumpHC, PATMREAD_ORGCODE, &cpu, NULL); … … 2211 2225 while (rc == VWRN_CONTINUE_ANALYSIS) 2212 2226 { 2213 pCurInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);2227 pCurInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC); 2214 2228 if (pCurInstrHC == NULL) 2215 2229 { … … 2343 2357 * 2344 2358 */ 2345 VMMR3 DECL(int) PATMR3DetectConflict(PVM pVM, RTRCPTR pInstrGC, RTRCPTR pConflictGC)2346 { 2347 PPATCHINFO pTargetPatch = PATMFindActivePatchByEntrypoint(pVM, pConflictGC, true /* include patch hints */);2359 VMMR3_INT_DECL(int) PATMR3DetectConflict(PVM pVM, RTRCPTR pInstrGC, RTRCPTR pConflictGC) 2360 { 2361 PPATCHINFO pTargetPatch = patmFindActivePatchByEntrypoint(pVM, pConflictGC, true /* include patch hints */); 2348 2362 if (pTargetPatch) 2349 2363 { … … 2378 2392 while (rc == VWRN_CONTINUE_RECOMPILE) 2379 2393 { 2380 pCurInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);2394 pCurInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC); 2381 2395 if (pCurInstrHC == NULL) 2382 2396 { … … 2396 2410 2397 2411 /* Add lookup record for patch to guest address translation */ 2398 patm r3AddP2GLookupRecord(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); 2399 2413 patmPatchGenIllegalInstr(pVM, pPatch); 2400 2414 rc = VINF_SUCCESS; /* Note: don't fail here; we might refuse an important patch!! */ … … 2419 2433 * Recompile the next instruction as well 2420 2434 */ 2421 pNextInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pNextInstrGC);2435 pNextInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pNextInstrGC); 2422 2436 if (pNextInstrHC == NULL) 2423 2437 { … … 2512 2526 * We rely on CSAM to detect and resolve conflicts 2513 2527 */ 2514 PPATCHINFO pTargetPatch = PATMFindActivePatchByEntrypoint(pVM, addr);2528 PPATCHINFO pTargetPatch = patmFindActivePatchByEntrypoint(pVM, addr); 2515 2529 if(pTargetPatch) 2516 2530 { … … 2567 2581 Assert(!(pPatch->flags & PATMFL_PATCHED_GUEST_CODE)); 2568 2582 2569 pPB = PATMGCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC);2583 pPB = patmR3GCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC); 2570 2584 Assert(pPB); 2571 2585 … … 2707 2721 Assert(pPatch->cbPatchJump <= sizeof(temp)); 2708 2722 2709 pPB = PATMGCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC);2723 pPB = patmR3GCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC); 2710 2724 Assert(pPB); 2711 2725 … … 2747 2761 * 2748 2762 */ 2749 VMMR3DECL(int) PATMR3PatchBlock(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC,2750 2763 static int patmR3PatchBlock(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC, 2764 uint32_t uOpcode, uint32_t uOpSize, PPATMPATCHREC pPatchRec) 2751 2765 { 2752 2766 PPATCHINFO pPatch = &pPatchRec->patch; … … 2777 2791 if (!(pPatch->flags & PATMFL_IDTHANDLER)) 2778 2792 { 2779 AssertMsg(0, (" PATMR3PatchBlock: Invalid opcode %x\n", uOpcode));2793 AssertMsg(0, ("patmR3PatchBlock: Invalid opcode %x\n", uOpcode)); 2780 2794 return VERR_INVALID_PARAMETER; 2781 2795 } … … 2850 2864 /* Most likely cause: we encountered an illegal instruction very early on. */ 2851 2865 /** @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")); 2853 2867 rc = VERR_PATCHING_REFUSED; 2854 2868 goto failure; … … 2907 2921 /*uint8_t bASMInt3 = 0xCC; - unused */ 2908 2922 2909 Log((" PATMR3PatchBlock %RRv -> int 3 callable patch.\n", pPatch->pPrivInstrGC));2923 Log(("patmR3PatchBlock %RRv -> int 3 callable patch.\n", pPatch->pPrivInstrGC)); 2910 2924 /* Replace first opcode byte with 'int 3'. */ 2911 2925 rc = patmActivateInt3Patch(pVM, pPatch); … … 2988 3002 uint32_t orgOffsetPatchMem = ~0; 2989 3003 2990 pInstrHC = pCurInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC);3004 pInstrHC = pCurInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pCurInstrGC); 2991 3005 AssertReturn(pCurInstrHC, VERR_PAGE_NOT_PRESENT); 2992 3006 … … 3043 3057 3044 3058 /* Add lookup record for patch to guest address translation (for the push) */ 3045 patm r3AddP2GLookupRecord(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); 3046 3060 3047 3061 /* Duplicate push. */ … … 3092 3106 pVM->patm.s.offPatchMem = orgOffsetPatchMem; 3093 3107 3094 return PATMR3PatchBlock(pVM, pInstrGC, pInstrHC, OP_CLI, uOpSize, pPatchRec);3108 return patmR3PatchBlock(pVM, pInstrGC, pInstrHC, OP_CLI, uOpSize, pPatchRec); 3095 3109 } 3096 3110 … … 3496 3510 * 3497 3511 */ 3498 VMMR3 DECL(int) PATMR3DuplicateFunctionRequest(PVM pVM, PCPUMCTX pCtx)3512 VMMR3_INT_DECL(int) PATMR3DuplicateFunctionRequest(PVM pVM, PCPUMCTX pCtx) 3499 3513 { 3500 3514 RTRCPTR pBranchTarget, pPage; … … 3561 3575 } 3562 3576 Assert(PATMIsPatchGCAddr(pVM, pCtx->edi)); 3563 rc = PATMAddBranchToLookupCache(pVM, pCtx->edi, pBranchTarget, pCtx->eax);3577 rc = patmAddBranchToLookupCache(pVM, pCtx->edi, pBranchTarget, pCtx->eax); 3564 3578 AssertRC(rc); 3565 3579 … … 3616 3630 uint8_t *pTmpInstrHC; 3617 3631 3618 pTmpInstrHC = PATMGCVirtToHCVirt(pVM, pCacheRec, pTargetGC);3632 pTmpInstrHC = patmR3GCVirtToHCVirt(pVM, pCacheRec, pTargetGC); 3619 3633 Assert(pTmpInstrHC); 3620 3634 if (pTmpInstrHC == 0) … … 3696 3710 goto failure; 3697 3711 3698 pPB = PATMGCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC);3712 pPB = patmR3GCVirtToHCVirt(pVM, pCacheRec, pPatch->pPrivInstrGC); 3699 3713 if (pPB == 0) 3700 3714 goto failure; … … 3853 3867 * 3854 3868 */ 3855 VMMR3DECL(int) PATMR3PatchInstrInt3(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC, DISCPUSTATE *pCpu, 3856 PPATCHINFO pPatch) 3869 int patmR3PatchInstrInt3(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC, DISCPUSTATE *pCpu, PPATCHINFO pPatch) 3857 3870 { 3858 3871 uint8_t bASMInt3 = 0xCC; … … 3860 3873 3861 3874 /* 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:", ""); 3863 3876 3864 3877 /* Save the original instruction. */ … … 3969 3982 * references the target instruction in the conflict patch. 3970 3983 */ 3971 RTRCPTR pJmpDest = PATMR3GuestGCPtrToPatchGCPtr(pVM, pInstrGC + pCpu->cbInstr + (int32_t)pCpu->Param1.uValue);3972 3973 AssertMsg(pJmpDest, (" PATMR3GuestGCPtrToPatchGCPtrfailed 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)); 3974 3987 pPatch->pPatchJumpDestGC = pJmpDest; 3975 3988 … … 4020 4033 * @param flags Patch flags 4021 4034 */ 4022 VMMR3 DECL(int) PATMR3AddHint(PVM pVM, RTRCPTR pInstrGC, uint32_t flags)4035 VMMR3_INT_DECL(int) PATMR3AddHint(PVM pVM, RTRCPTR pInstrGC, uint32_t flags) 4023 4036 { 4024 4037 Assert(pInstrGC); … … 4039 4052 * @note returns failure if patching is not allowed or possible 4040 4053 */ 4041 VMMR3 DECL(int) PATMR3InstallPatch(PVM pVM, RTRCPTR pInstrGC, uint64_t flags)4054 VMMR3_INT_DECL(int) PATMR3InstallPatch(PVM pVM, RTRCPTR pInstrGC, uint64_t flags) 4042 4055 { 4043 4056 DISCPUSTATE cpu; … … 4065 4078 if (!(flags & (PATMFL_GUEST_SPECIFIC|PATMFL_IDTHANDLER|PATMFL_INTHANDLER|PATMFL_TRAMPOLINE))) 4066 4079 { 4067 PPATCHINFO pConflictPatch = PATMFindActivePatchByEntrypoint(pVM, pInstrGC);4080 PPATCHINFO pConflictPatch = patmFindActivePatchByEntrypoint(pVM, pInstrGC); 4068 4081 AssertReleaseMsg(pConflictPatch == 0, ("Unable to patch overwritten instruction at %RRv (%RRv)\n", pInstrGC, pConflictPatch->pPrivInstrGC)); 4069 4082 if (pConflictPatch != 0) … … 4232 4245 RT_ZERO(cacheRec); 4233 4246 4234 pInstrHC = PATMGCVirtToHCVirt(pVM, &cacheRec, pInstrGC);4247 pInstrHC = patmR3GCVirtToHCVirt(pVM, &cacheRec, pInstrGC); 4235 4248 AssertReturn(pInstrHC, VERR_PATCHING_REFUSED); 4236 4249 … … 4337 4350 if (pPatchRec->patch.flags & PATMFL_INT3_REPLACEMENT) 4338 4351 { 4339 rc = PATMR3PatchInstrInt3(pVM, pInstrGC, pInstrHC, &cpu, &pPatchRec->patch);4352 rc = patmR3PatchInstrInt3(pVM, pInstrGC, pInstrHC, &cpu, &pPatchRec->patch); 4340 4353 } 4341 4354 else … … 4366 4379 case OP_SYSENTER: 4367 4380 case OP_PUSH: 4368 rc = PATMInstallGuestSpecificPatch(pVM, &cpu, pInstrGC, pInstrHC, pPatchRec);4381 rc = patmR3InstallGuestSpecificPatch(pVM, &cpu, pInstrGC, pInstrHC, pPatchRec); 4369 4382 if (rc == VINF_SUCCESS) 4370 4383 { … … 4385 4398 { 4386 4399 case OP_SYSENTER: 4387 rc = PATMInstallGuestSpecificPatch(pVM, &cpu, pInstrGC, pInstrHC, pPatchRec);4400 rc = patmR3InstallGuestSpecificPatch(pVM, &cpu, pInstrGC, pInstrHC, pPatchRec); 4388 4401 if (rc == VINF_SUCCESS) 4389 4402 { … … 4426 4439 case OP_CLI: 4427 4440 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); 4429 4442 break; 4430 4443 … … 4440 4453 case OP_VERR: 4441 4454 case OP_IRET: 4442 rc = PATMR3PatchInstrInt3(pVM, pInstrGC, pInstrHC, &cpu, &pPatchRec->patch);4455 rc = patmR3PatchInstrInt3(pVM, pInstrGC, pInstrHC, &cpu, &pPatchRec->patch); 4443 4456 break; 4444 4457 … … 4773 4786 * @param pPatch Patch record 4774 4787 */ 4775 int patmRemovePatchPages(PVM pVM, PPATCHINFO pPatch)4788 static int patmRemovePatchPages(PVM pVM, PPATCHINFO pPatch) 4776 4789 { 4777 4790 int rc; … … 4808 4821 * 4809 4822 */ 4810 VMMR3 DECL(int) PATMR3PatchWrite(PVM pVM, RTRCPTR GCPtr, uint32_t cbWrite)4823 VMMR3_INT_DECL(int) PATMR3PatchWrite(PVM pVM, RTRCPTR GCPtr, uint32_t cbWrite) 4811 4824 { 4812 4825 RTRCUINTPTR pWritePageStart, pWritePageEnd, pPage; … … 4905 4918 LogRel(("PATM: Disable block at %RRv - write %RRv-%RRv\n", pPatch->pPrivInstrGC, pGuestPtrGC, pGuestPtrGC+cbWrite)); 4906 4919 4907 PATMR3MarkDirtyPatch(pVM, pPatch);4920 patmR3MarkDirtyPatch(pVM, pPatch); 4908 4921 4909 4922 /* Note: jump back to the start as the pPatchPage has been deleted or changed */ … … 4958 4971 { 4959 4972 LogRel(("PATM: Disable block at %RRv - invalid write %RRv-%RRv \n", pPatch->pPrivInstrGC, GCPtr, GCPtr+cbWrite)); 4960 PATMR3MarkDirtyPatch(pVM, pPatch);4973 patmR3MarkDirtyPatch(pVM, pPatch); 4961 4974 } 4962 4975 /* Note: jump back to the start as the pPatchPage has been deleted or changed */ … … 4982 4995 /** @note Currently only called by CSAMR3FlushPage; optimization to avoid having to double check if the physical address has changed 4983 4996 */ 4984 VMMR3 DECL(int) PATMR3FlushPage(PVM pVM, RTRCPTR addr)4997 VMMR3_INT_DECL(int) PATMR3FlushPage(PVM pVM, RTRCPTR addr) 4985 4998 { 4986 4999 addr &= PAGE_BASE_GC_MASK; … … 4999 5012 5000 5013 Log(("PATMR3FlushPage %RRv remove patch at %RRv\n", addr, pPatch->pPrivInstrGC)); 5001 PATMR3MarkDirtyPatch(pVM, pPatch);5014 patmR3MarkDirtyPatch(pVM, pPatch); 5002 5015 } 5003 5016 } … … 5014 5027 * @param pInstrGC Guest context pointer to instruction 5015 5028 */ 5016 VMMR3 DECL(bool) PATMR3HasBeenPatched(PVM pVM, RTRCPTR pInstrGC)5029 VMMR3_INT_DECL(bool) PATMR3HasBeenPatched(PVM pVM, RTRCPTR pInstrGC) 5017 5030 { 5018 5031 PPATMPATCHREC pPatchRec; … … 5077 5090 * @param pcbRead Where to return the acutal number of bytes read. 5078 5091 */ 5079 VMMR3 DECL(int) PATMR3ReadOrgInstr(PVM pVM, RTGCPTR32 GCPtrInstr, uint8_t *pbDst, size_t cbToRead, size_t *pcbRead)5092 VMMR3_INT_DECL(int) PATMR3ReadOrgInstr(PVM pVM, RTGCPTR32 GCPtrInstr, uint8_t *pbDst, size_t cbToRead, size_t *pcbRead) 5080 5093 { 5081 5094 /* Shortcut. */ … … 5134 5147 * 5135 5148 */ 5136 VMMR3 DECL(int) PATMR3DisablePatch(PVM pVM, RTRCPTR pInstrGC)5149 VMMR3_INT_DECL(int) PATMR3DisablePatch(PVM pVM, RTRCPTR pInstrGC) 5137 5150 { 5138 5151 PPATMPATCHREC pPatchRec; … … 5293 5306 5294 5307 RT_ZERO(patch); 5295 pInstrHC = PATMGCVirtToHCVirt(pVM, &patch, pInstrGC);5308 pInstrHC = patmR3GCVirtToHCVirt(pVM, &patch, pInstrGC); 5296 5309 disret = patmR3DisInstr(pVM, &patch, pInstrGC, pInstrHC, PATMREAD_ORGCODE, &cpu, &cbInstr); 5297 5310 /* … … 5380 5393 * 5381 5394 */ 5382 VMMR3 DECL(int) PATMR3EnablePatch(PVM pVM, RTRCPTR pInstrGC)5395 VMMR3_INT_DECL(int) PATMR3EnablePatch(PVM pVM, RTRCPTR pInstrGC) 5383 5396 { 5384 5397 PPATMPATCHREC pPatchRec; … … 5499 5512 * @param fForceRemove Remove *all* patches 5500 5513 */ 5501 int PATMRemovePatch(PVM pVM, PPATMPATCHREC pPatchRec, bool fForceRemove)5514 int patmR3RemovePatch(PVM pVM, PPATMPATCHREC pPatchRec, bool fForceRemove) 5502 5515 { 5503 5516 PPATCHINFO pPatch; … … 5711 5724 5712 5725 /* 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 */); 5714 5727 AssertRC(rc2); 5715 5728 … … 5788 5801 * 5789 5802 */ 5790 PPATCHINFO PATMFindActivePatchByEntrypoint(PVM pVM, RTRCPTR pInstrGC, bool fIncludeHints)5803 PPATCHINFO patmFindActivePatchByEntrypoint(PVM pVM, RTRCPTR pInstrGC, bool fIncludeHints) 5791 5804 { 5792 5805 PPATMPATCHREC pPatchRec = (PPATMPATCHREC)RTAvloU32GetBestFit(&pVM->patm.s.PatchLookupTreeHC->PatchTree, pInstrGC, false); … … 5821 5834 * @returns true -> yes, false -> no 5822 5835 * @param pVM Pointer to the VM. 5823 * @param pAddr Guest context address 5824 * @param pPatchAddr Guest context patch address (if true) 5825 */ 5826 VMMR3 DECL(bool) PATMR3IsInsidePatchJump(PVM pVM, RTRCPTR pAddr, PRTGCPTR32 pPatchAddr)5836 * @param pAddr Guest context address. 5837 * @param pPatchAddr Guest context patch address (if true). 5838 */ 5839 VMMR3_INT_DECL(bool) PATMR3IsInsidePatchJump(PVM pVM, RTRCPTR pAddr, PRTGCPTR32 pPatchAddr) 5827 5840 { 5828 5841 RTRCPTR addr; … … 5837 5850 *pPatchAddr = 0; 5838 5851 5839 pPatch = PATMFindActivePatchByEntrypoint(pVM, pAddr);5852 pPatch = patmFindActivePatchByEntrypoint(pVM, pAddr); 5840 5853 if (pPatch) 5841 5854 *pPatchAddr = pPatch->pPrivInstrGC; … … 5854 5867 * 5855 5868 */ 5856 VMMR3 DECL(int) PATMR3RemovePatch(PVM pVM, RTRCPTR pInstrGC)5869 VMMR3_INT_DECL(int) PATMR3RemovePatch(PVM pVM, RTRCPTR pInstrGC) 5857 5870 { 5858 5871 PPATMPATCHREC pPatchRec; … … 5865 5878 return VINF_SUCCESS; 5866 5879 5867 return PATMRemovePatch(pVM, pPatchRec, false);5880 return patmR3RemovePatch(pVM, pPatchRec, false); 5868 5881 } 5869 5882 AssertFailed(); … … 5881 5894 * 5882 5895 */ 5883 VMMR3DECL(int) PATMR3MarkDirtyPatch(PVM pVM, PPATCHINFO pPatch)5896 static int patmR3MarkDirtyPatch(PVM pVM, PPATCHINFO pPatch) 5884 5897 { 5885 5898 if (pPatch->pPatchBlockOffset) … … 5952 5965 } 5953 5966 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 */ 5974 static 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) 5955 5985 * 5956 5986 * @returns corresponding GC pointer in patch block … … 5962 5992 RTRCPTR patmGuestGCPtrToClosestPatchGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t*) pInstrGC) 5963 5993 { 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; 5985 5998 } 5986 5999 … … 5994 6007 * 5995 6008 */ 5996 VMMR3 DECL(RTRCPTR) PATMR3PatchToGCPtr(PVM pVM, RTRCPTR pPatchGC, PATMTRANSSTATE *pEnmState)6009 VMMR3_INT_DECL(RTRCPTR) PATMR3PatchToGCPtr(PVM pVM, RTRCPTR pPatchGC, PATMTRANSSTATE *pEnmState) 5997 6010 { 5998 6011 PPATMPATCHREC pPatchRec; … … 6038 6051 } 6039 6052 else 6040 if ( PATMFindActivePatchByEntrypoint(pVM, pPrivInstrGC))6053 if (patmFindActivePatchByEntrypoint(pVM, pPrivInstrGC)) 6041 6054 { 6042 6055 *pEnmState = PATMTRANS_OVERWRITTEN; … … 6060 6073 * @param pAddrGC Guest context address 6061 6074 */ 6062 VMMR3 DECL(RTRCPTR) PATMR3QueryPatchGCPtr(PVM pVM, RTRCPTR pAddrGC)6075 VMMR3_INT_DECL(RTRCPTR) PATMR3QueryPatchGCPtr(PVM pVM, RTRCPTR pAddrGC) 6063 6076 { 6064 6077 PPATMPATCHREC pPatchRec; … … 6069 6082 if (pPatchRec && (pPatchRec->patch.uState == PATCH_ENABLED || pPatchRec->patch.uState == PATCH_DIRTY)) 6070 6083 return PATCHCODE_PTR_GC(&pPatchRec->patch); 6071 else 6072 return 0; 6084 return NIL_RTRCPTR; 6073 6085 } 6074 6086 … … 6203 6215 6204 6216 /* Add a new lookup record for the duplicated instruction. */ 6205 patm r3AddP2GLookupRecord(pVM, &pPatch->patch, pCurPatchInstrHC, pCurInstrGC, PATM_LOOKUP_BOTHDIR);6217 patmR3AddP2GLookupRecord(pVM, &pPatch->patch, pCurPatchInstrHC, pCurInstrGC, PATM_LOOKUP_BOTHDIR); 6206 6218 } 6207 6219 else … … 6214 6226 #endif 6215 6227 /* Restore the old lookup record for the duplicated instruction. */ 6216 patm r3AddP2GLookupRecord(pVM, &pPatch->patch, pCurPatchInstrHC, pCurInstrGC, PATM_LOOKUP_BOTHDIR);6228 patmR3AddP2GLookupRecord(pVM, &pPatch->patch, pCurPatchInstrHC, pCurInstrGC, PATM_LOOKUP_BOTHDIR); 6217 6229 6218 6230 /** @todo in theory we need to restore the lookup records for the remaining dirty instructions too! */ … … 6309 6321 * @param ppNewEip GC pointer to new instruction. 6310 6322 */ 6311 VMMR3 DECL(int) PATMR3HandleTrap(PVM pVM, PCPUMCTX pCtx, RTRCPTR pEip, RTGCPTR *ppNewEip)6323 VMMR3_INT_DECL(int) PATMR3HandleTrap(PVM pVM, PCPUMCTX pCtx, RTRCPTR pEip, RTGCPTR *ppNewEip) 6312 6324 { 6313 6325 PPATMPATCHREC pPatch = 0; … … 6508 6520 cacheRec.pPatch = &pPatch->patch; 6509 6521 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, 6511 6523 &cpu, &cbInstr); 6512 6524 if (cacheRec.Lock.pvMap) … … 6547 6559 cacheRec.pPatch = &pPatch->patch; 6548 6560 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, 6550 6562 &cpu, &cbInstr); 6551 6563 if (cacheRec.Lock.pvMap) … … 6554 6566 if (disret && (cpu.pCurInstr->uOpcode == OP_SYSEXIT || cpu.pCurInstr->uOpcode == OP_HLT || cpu.pCurInstr->uOpcode == OP_INT3)) 6555 6567 { 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, 6557 6569 &cpu, &cbInstr); 6558 6570 if (cacheRec.Lock.pvMap) … … 6601 6613 * @param pVM Pointer to the VM. 6602 6614 */ 6603 VMMR3 DECL(int) PATMR3HandleMonitoredPage(PVM pVM)6615 VMMR3_INT_DECL(int) PATMR3HandleMonitoredPage(PVM pVM) 6604 6616 { 6605 6617 RTRCPTR addr = pVM->patm.s.pvFaultMonitor; … … 6775 6787 6776 6788 RTAvloU32DoWithAll(&pVM->patm.s.PatchLookupTreeHC->PatchTree, true, DisableAllPatches, pVM); 6777 PATMR3AllowPatching(pVM , false);6789 PATMR3AllowPatching(pVM->pUVM, false); 6778 6790 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Patching disabled\n"); 6779 6791 } … … 6798 6810 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: The command requires VM to be selected.\n"); 6799 6811 6800 PATMR3AllowPatching(pVM , true);6812 PATMR3AllowPatching(pVM->pUVM, true); 6801 6813 RTAvloU32DoWithAll(&pVM->patm.s.PatchLookupTreeHC->PatchTree, true, EnableAllPatches, pVM); 6802 6814 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Patching enabled\n"); -
trunk/src/VBox/VMM/VMMR3/PATMGuest.cpp
r41965 r44362 195 195 /* Found it; patch the push cs */ 196 196 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); 198 198 } 199 199 … … 210 210 * 211 211 */ 212 int PATMInstallGuestSpecificPatch(PVM pVM, PDISCPUSTATE pCpu, RTGCPTR32 pInstrGC, uint8_t *pInstrHC, PPATMPATCHREC pPatchRec)212 int patmR3InstallGuestSpecificPatch(PVM pVM, PDISCPUSTATE pCpu, RTGCPTR32 pInstrGC, uint8_t *pInstrHC, PPATMPATCHREC pPatchRec) 213 213 { 214 214 int rc; -
trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp
r42481 r44362 374 374 /* Add lookup record for patch to guest address translation */ 375 375 Assert(pPB[pAsmRecord->offJump - 1] == 0xE9); 376 patm r3AddP2GLookupRecord(pVM, pPatch, &pPB[pAsmRecord->offJump - 1], pReturnAddrGC, PATM_LOOKUP_PATCH2GUEST);376 patmR3AddP2GLookupRecord(pVM, pPatch, &pPB[pAsmRecord->offJump - 1], pReturnAddrGC, PATM_LOOKUP_PATCH2GUEST); 377 377 378 378 *(uint32_t *)&pPB[pAsmRecord->offJump] = displ; … … 637 637 /* If interrupted here, then jump to the target instruction. Used by PATM.cpp for jumping to known instructions. */ 638 638 /* Add lookup record for patch to guest address translation */ 639 patm r3AddP2GLookupRecord(pVM, pPatch, pPB, pTargetGC, PATM_LOOKUP_PATCH2GUEST);639 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pTargetGC, PATM_LOOKUP_PATCH2GUEST); 640 640 641 641 pPB[0] = 0xE9; … … 866 866 867 867 /* Jump back to the original instruction if IF is set again. */ 868 Assert(! PATMFindActivePatchByEntrypoint(pVM, pCurInstrGC));868 Assert(!patmFindActivePatchByEntrypoint(pVM, pCurInstrGC)); 869 869 rc = patmPatchGenCheckIF(pVM, pPatch, pCurInstrGC); 870 870 AssertRCReturn(rc, rc); … … 979 979 980 980 /* Add lookup record for patch to guest address translation */ 981 patm r3AddP2GLookupRecord(pVM, pPatch, pPB, pCurInstrGC, PATM_LOOKUP_PATCH2GUEST);981 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pCurInstrGC, PATM_LOOKUP_PATCH2GUEST); 982 982 983 983 /* Generate code to check for IF=1 before executing the call to the duplicated function. */ … … 1002 1002 1003 1003 /* Add lookup record for patch to guest address translation */ 1004 patm r3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);1004 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST); 1005 1005 1006 1006 int size = patmPatchGenCode(pVM, pPatch, pPB, &PATMSetPIFRecord, 0, false); … … 1023 1023 1024 1024 /* Add lookup record for patch to guest address translation */ 1025 patm r3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);1025 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST); 1026 1026 1027 1027 int size = patmPatchGenCode(pVM, pPatch, pPB, &PATMClearPIFRecord, 0, false); … … 1049 1049 1050 1050 /* Add lookup record for patch to guest address translation */ 1051 patm r3AddP2GLookupRecord(pVM, pPatch, pPB, pNextInstrGC, PATM_LOOKUP_PATCH2GUEST);1051 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pNextInstrGC, PATM_LOOKUP_PATCH2GUEST); 1052 1052 1053 1053 callInfo.pNextInstrGC = pNextInstrGC; … … 1080 1080 1081 1081 /* Add lookup record for patch to guest address translation */ 1082 patm r3AddP2GLookupRecord(pVM, pPatch, pPB, pIntHandlerGC, PATM_LOOKUP_PATCH2GUEST);1082 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pIntHandlerGC, PATM_LOOKUP_PATCH2GUEST); 1083 1083 1084 1084 /* Generate entrypoint for the interrupt handler (correcting CS in the interrupt stack frame) */ … … 1111 1111 1112 1112 /* Add lookup record for patch to guest address translation */ 1113 patm r3AddP2GLookupRecord(pVM, pPatch, pPB, pTrapHandlerGC, PATM_LOOKUP_PATCH2GUEST);1113 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pTrapHandlerGC, PATM_LOOKUP_PATCH2GUEST); 1114 1114 1115 1115 /* Generate entrypoint for the trap handler (correcting CS in the interrupt stack frame) */ … … 1130 1130 1131 1131 /* Add lookup record for stats code -> guest handler. */ 1132 patm r3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST);1132 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pInstrGC, PATM_LOOKUP_PATCH2GUEST); 1133 1133 1134 1134 /* Generate code to keep calling statistics for this patch */ … … 1545 1545 1546 1546 /* Add lookup record for patch to guest address translation */ 1547 patm r3AddP2GLookupRecord(pVM, pPatch, pPB, pReturnAddrGC, PATM_LOOKUP_PATCH2GUEST);1547 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pReturnAddrGC, PATM_LOOKUP_PATCH2GUEST); 1548 1548 1549 1549 /* Generate code to jump to guest code if IF=1, else fault. */ … … 1568 1568 { 1569 1569 /* Add lookup record for patch to guest address translation */ 1570 patm r3AddP2GLookupRecord(pVM, pPatch, pPB, pCurInstrGC, PATM_LOOKUP_PATCH2GUEST);1570 patmR3AddP2GLookupRecord(pVM, pPatch, pPB, pCurInstrGC, PATM_LOOKUP_PATCH2GUEST); 1571 1571 } 1572 1572 -
trunk/src/VBox/VMM/VMMR3/PATMSSM.cpp
r41965 r44362 829 829 cacheRec.pPatch = &pPatchRec->patch; 830 830 831 uint8_t *pPrivInstrHC = PATMGCVirtToHCVirt(pVM, &cacheRec, pPatchRec->patch.pPrivInstrGC);831 uint8_t *pPrivInstrHC = patmR3GCVirtToHCVirt(pVM, &cacheRec, pPatchRec->patch.pPrivInstrGC); 832 832 /* Can fail due to page or page table not present. */ 833 833 … … 895 895 AssertRCReturn(rc, rc); 896 896 897 patm r3AddP2GLookupRecord(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); 898 898 } 899 899 Assert(pPatchRec->patch.Patch2GuestAddrTree); -
trunk/src/VBox/VMM/VMMRC/CSAMRC.cpp
r41965 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 109 109 if (cpl != 3) 110 110 { 111 rc = PATM GCHandleWriteToPatchPage(pVM, pRegFrame, (RTRCPTR)((RTRCUINTPTR)pvRange + offRange), 4 /** @todo */);111 rc = PATMRCHandleWriteToPatchPage(pVM, pRegFrame, (RTRCPTR)((RTRCUINTPTR)pvRange + offRange), 4 /** @todo */); 112 112 if (rc == VINF_SUCCESS) 113 113 return rc; -
trunk/src/VBox/VMM/VMMRC/PATMRC.cpp
r42706 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-201 2Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 76 76 * 77 77 */ 78 VMMRCDECL(int) PATM GCHandleWriteToPatchPage(PVM pVM, PCPUMCTXCORE pRegFrame, RTRCPTR GCPtr, uint32_t cbWrite)78 VMMRCDECL(int) PATMRCHandleWriteToPatchPage(PVM pVM, PCPUMCTXCORE pRegFrame, RTRCPTR GCPtr, uint32_t cbWrite) 79 79 { 80 80 RTGCUINTPTR pWritePageStart, pWritePageEnd; … … 148 148 * @param pCtxCore The relevant core context. 149 149 */ 150 VMM DECL(int) PATMRCHandleIllegalInstrTrap(PVM pVM, PCPUMCTXCORE pRegFrame)150 VMMRC_INT_DECL(int) PATMRCHandleIllegalInstrTrap(PVM pVM, PCPUMCTXCORE pRegFrame) 151 151 { 152 152 PPATMPATCHREC pRec; … … 186 186 Log(("PATMRC: lookup %x jump table=%x\n", pRegFrame->edx, pRegFrame->edi)); 187 187 188 pRec = PATMQueryFunctionPatch(pVM, (RTRCPTR)(pRegFrame->edx));188 pRec = patmQueryFunctionPatch(pVM, (RTRCPTR)pRegFrame->edx); 189 189 if (pRec) 190 190 { … … 192 192 { 193 193 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); 195 195 if (rc == VINF_SUCCESS) 196 196 { … … 450 450 * @param pCtxCore The relevant core context. 451 451 */ 452 VMMRC DECL(int) PATMRCHandleInt3PatchTrap(PVM pVM, PCPUMCTXCORE pRegFrame)452 VMMRC_INT_DECL(int) PATMRCHandleInt3PatchTrap(PVM pVM, PCPUMCTXCORE pRegFrame) 453 453 { 454 454 PPATMPATCHREC pRec; -
trunk/src/VBox/VMM/VMMRC/PDMRCDevice.cpp
r41965 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-201 1Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/src/VBox/VMM/VMMRC/TRPMRCHandlers.cpp
r42779 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-201 2Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/src/VBox/VMM/include/EMHandleRCTmpl.h
r43394 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-20 09Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/src/VBox/VMM/include/PATMInternal.h
r41897 r44362 5 5 6 6 /* 7 * Copyright (C) 2006-201 2Oracle Corporation7 * Copyright (C) 2006-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 30 30 31 31 32 32 /** @name Saved state version numbers. 33 * @{ */ 33 34 #define PATM_SSM_VERSION 55 34 35 #define PATM_SSM_VERSION_FIXUP_HACK 54 35 36 #define PATM_SSM_VERSION_FIXUP_HACK 54 36 37 #define PATM_SSM_VERSION_VER16 53 38 /** @} */ 37 39 38 40 /* Enable for call patching. */ … … 554 556 555 557 #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); 558 RTRCPTR patmPatchGCPtr2GuestGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t *) pPatchGC); 559 RTRCPTR patmGuestGCPtrToPatchGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t*) pInstrGC); 560 RTRCPTR patmGuestGCPtrToClosestPatchGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t*) pInstrGC); 561 #endif 562 563 void patmR3AddP2GLookupRecord(PVM pVM, PPATCHINFO pPatch, uint8_t *pPatchInstrHC, RTRCPTR pInstrGC, 564 PATM_LOOKUP_TYPE enmType, bool fDirty = false); 565 int patmInsertPatchPages(PVM pVM, PPATCHINFO pPatch); 566 RTRCPTR patmPatchQueryStatAddress(PVM pVM, PPATCHINFO pPatch); 567 int patmR3RemovePatch(PVM pVM, PPATMPATCHREC pPatchRec, bool fForceRemove); 609 568 610 569 /** … … 621 580 typedef int (VBOXCALL *PFN_PATMR3ANALYSE)(PVM pVM, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pInstrGC, RCPTRTYPE(uint8_t *) pCurInstrGC, PPATMP2GLOOKUPREC pCacheRec); 622 581 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 582 int patmR3InstallGuestSpecificPatch(PVM pVM, PDISCPUSTATE pCpu, RTRCPTR pInstrGC, uint8_t *pInstrHC, PPATMPATCHREC pPatchRec); 583 PPATMPATCHREC patmQueryFunctionPatch(PVM pVM, RTRCPTR pInstrGC); 584 const char *patmGetInstructionString(uint32_t opcode, uint32_t fPatchFlags); 585 586 PPATCHINFO patmFindActivePatchByEntrypoint(PVM pVM, RTRCPTR pInstrGC, bool fIncludeHints = false); 587 int patmR3PatchInstrInt3(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC, DISCPUSTATE *pCpu, PPATCHINFO pPatch); 588 int patmAddBranchToLookupCache(PVM pVM, RTRCPTR pJumpTableGC, RTRCPTR pBranchTarget, RTRCUINTPTR pRelBranchPatch); 589 R3PTRTYPE(uint8_t *) patmR3GCVirtToHCVirt(PVM pVM, PPATMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr); 677 590 678 591 RT_C_DECLS_BEGIN … … 691 604 VMMRCDECL(int) PATMGCMonitorPage(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange); 692 605 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); 606 RT_C_DECLS_END 750 607 751 608 /** … … 756 613 * @param pBranchInstrGC GC pointer of branch instruction 757 614 */ 758 inline RTRCPTRPATMResolveBranch(PDISCPUSTATE pCpu, RTRCPTR pBranchInstrGC)615 DECLINLINE(RTRCPTR) PATMResolveBranch(PDISCPUSTATE pCpu, RTRCPTR pBranchInstrGC) 759 616 { 760 617 uint32_t disp; … … 785 642 } 786 643 787 RT_C_DECLS_END788 789 644 #ifdef LOG_ENABLED 790 645 int 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.