PATMInternal.h revision 10f18618390096a9c968016b6ca94d77b91618fb
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync * PATM - Internal header file.
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync * Copyright (C) 2006-2012 Oracle Corporation
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync * available from http://www.virtualbox.org. This file is free software;
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync * you can redistribute it and/or modify it under the terms of the GNU
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync * General Public License (GPL) as published by the Free Software
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync/* Enable for call patching. */
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync * Internal patch type flags (starts at RT_BIT(11))
03532efdc331b598d3dedc8cc7477641c3b0dd12vboxsync#define PATMFL_READ_ORIGINAL_BYTES RT_BIT_64(16) /** opcode might have already been patched */
#define PATMFL_IDTHANDLER_WITHOUT_ENTRYPOINT RT_BIT_64(20) /** internal flag to avoid duplicate entrypoints */
#define PATMFL_CODE_MONITORED RT_BIT_64(24) /** code pages of guest monitored for self-modifying code. */
#define PATMFL_CALLABLE_AS_FUNCTION RT_BIT_64(25) /** cli and pushf blocks can be used as callable functions. */
#define PATMFL_TRAMPOLINE RT_BIT_64(27) /** trampoline patch that clears PATM_INTERRUPTFLAG and jumps to patch destination */
#define PATMFL_MUST_INSTALL_PATCHJMP RT_BIT_64(31) /** Need to patch guest code in order to activate patch. */
#define PATMFL_EXTERNAL_JUMP_INSIDE RT_BIT_64(33) /** A trampoline patch was created that jumps to an instruction in the patch block */
#define PATMFL_CODE_REFERENCED RT_BIT_64(34) /** patch block referenced (called, jumped to) by another patch. */
#define FIXUP_ABSOLUTE 0
#define PATM_STAT_INDEX_DUMMY 0
#ifdef VBOX_WITH_STATISTICS
/** aCpus[0].fLocalForcedActions fixup (must be uneven to avoid theoretical clashes with valid pointers) */
struct _PATCHINFO;
typedef struct RECPATCHTOGUEST
bool fDirty;
bool fJumpTarget;
typedef struct RECGUESTTOPATCH
typedef struct _PATCHINFO
typedef struct PATMPATCHREC
typedef struct TRAMPREC
} TRAMPREC;
typedef struct PATMPATCHPAGE
#define PATM_PATCHREC_FROM_COREOFFSET(a) (PPATMPATCHREC)((uintptr_t)a - RT_OFFSETOF(PATMPATCHREC, CoreOffset))
#define PATM_PATCHREC_FROM_PATCHINFO(a) (PPATMPATCHREC)((uintptr_t)a - RT_OFFSETOF(PATMPATCHREC, patch))
typedef struct PATMTREES
typedef struct PATM
bool fOutOfMemory;
/** PATM stack page for call instruction execution. (2 parts: one for our private stack and one to store the original return address */
/* Current free index value (uPatchRun/uPatchTrap arrays). */
/** GC address of fault in monitored page (set by PATMGCMonitorPage, used by PATMR3HandleMonitoredPage)- */
} mmio;
} savedstate;
DECLCALLBACK(int) patmVirtPageHandler(PVM pVM, RTGCPTR GCPtr, void *pvPtr, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
#ifdef IN_RING3
RTRCPTR patmGuestGCPtrToClosestPatchGCPtr(PVM pVM, PPATCHINFO pPatch, RCPTRTYPE(uint8_t*) pInstrGC);
void patmr3AddP2GLookupRecord(PVM pVM, PPATCHINFO pPatch, uint8_t *pPatchInstrHC, RTRCPTR pInstrGC, PATM_LOOKUP_TYPE enmType, bool fDirty=false);
* Insert page records for all guest pages that contain instructions that were recompiled for this patch
* Remove page records for all guest pages that contain instructions that were recompiled for this patch
* Call for analysing the instructions following the privileged instr. for compliance with our heuristics
typedef int (VBOXCALL *PFN_PATMR3ANALYSE)(PVM pVM, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pInstrGC, RCPTRTYPE(uint8_t *) pCurInstrGC, PPATMP2GLOOKUPREC pCacheRec);
int PATMInstallGuestSpecificPatch(PVM pVM, PDISCPUSTATE pCpu, RTRCPTR pInstrGC, uint8_t *pInstrHC, PPATMPATCHREC pPatchRec);
VMMRCDECL(int) PATMGCMonitorPage(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
* @param pInstr Guest context point to instruction that might lie within 5 bytes of an existing patch jump
* Replace an instruction with a breakpoint (0xCC), that is handled dynamically in the guest context.
VMMR3DECL(int) PATMR3PatchInstrInt3(PVM pVM, RTRCPTR pInstrGC, R3PTRTYPE(uint8_t *) pInstrHC, DISCPUSTATE *pCpu, PPATCHINFO pPatch);
R3PTRTYPE(uint8_t *) PATMGCVirtToHCVirt(PVM pVM, PPATMP2GLOOKUPREC pCacheRec, RCPTRTYPE(uint8_t *) pGCPtr);
#ifdef IN_RC
#ifdef LOG_ENABLED
int patmr3DisasmCallback(PVM pVM, DISCPUSTATE *pCpu, RCPTRTYPE(uint8_t *) pInstrGC, RCPTRTYPE(uint8_t *) pCurInstrGC, PPATMP2GLOOKUPREC pCacheRec);