PATMInternal.h revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
0N/A * PATM - Internal header file. 0N/A * Copyright (C) 2006 InnoTek Systemberatung GmbH 0N/A * This file is part of VirtualBox Open Source Edition (OSE), as 0N/A * you can redistribute it and/or modify it under the terms of the GNU 0N/A * General Public License as published by the Free Software Foundation, 0N/A * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE 0N/A * distribution. VirtualBox OSE is distributed in the hope that it will 0N/A * be useful, but WITHOUT ANY WARRANTY of any kind. 0N/A * If you received this file as part of a commercial VirtualBox 0N/A * distribution, then only the terms of your commercial VirtualBox 2362N/A * license agreement apply instead of the previous paragraph. 0N/A#
error "Not in PATM! This is an internal header!" 0N/A/* Enable for call patching. */ 0N/A * Internal patch type flags (starts at BIT(11)) /* Maximum nr of writes before a patch is marked dirty. (disabled) */ /* Maximum nr of invalid writes before a patch is disabled. */ /** Size of the instruction that's used for requests from patch code (currently only call) */ /** No statistics counter index allocated just yet */ /** Dummy counter to handle overflows */ /** Maximum number of stat counters. */ /** Size of memory allocated for patch statistics. */ /** The key is a HC virtual address. */ /** The key is a GC virtual address. */ * Patch to guest lookup type (single or both direction) * Patch to guest address lookup record /** The key is an offset inside the patch memory block. */ * Guest to patch address lookup record /** The key is a GC virtual address. */ * Temporary information used in ring 3 only; no need to waste memory in the patch record itself. /* Temporary tree for storing the addresses of illegal instructions. */ /* Temporary tree of encountered jumps. (debug only) */ /** Last original guest instruction pointer; used for disassmebly log. */ /** Keeping track of multiple ret instructions. */ /* Only valid for PATMFL_JUMP_CONFLICT patches */ * Lowest and highest patched GC instruction address. To optimize searches. /* Tree of fixup records for the patch. */ /* Tree of jumps inside the generated patch code. */ * Lookup trees for determining the corresponding guest address of an * instruction in the patch block. // Cache record for PATMGCVirtToHCVirt /* Temporary information during patch creation. Don't waste hypervisor memory for this. */ /* Count the number of writes to the corresponding guest code. */ /* Count the number of invalid writes to pages monitored for the patch. */ //some statistics to determine if we should keep this patch activated // Index into the uPatchRun and uPatchTrap arrays (0..MAX_PATCHES-1) /* First opcode byte, that's overwritten when a patch is marked dirty. */ * Lookup record for patches /** The key is a GC virtual address. */ /** The key is a patch offset. */ /** Increment for allocating room for pointer array */ * Lookup record for patch pages /** The key is a GC virtual address. */ /** Region to monitor. */ /** Number of patches for this page. */ /** Maximum nr of pointers in the array. */ /** Array of patch pointers for this page. */ * AVL tree with all patches (active or disabled) sorted by guest instruction address * AVL tree with all patches sorted by patch address (offset actually) * AVL tree with all pages which were (partly) patched * Changes to this must checked against the padding of the patm union in VM! /** Offset to the VM structure. /* GC PATM state pointers */ /** PATM stack page for call instruction execution. (2 parts: one for our private stack and one to store the original return address */ /** GC pointer to CPUMCTX structure. */ /* GC statistics pointers */ /* Temporary counter for patch installation call depth. (in order not to go on forever) */ /** Number of page lookup records. */ * Lowest and highest patched GC instruction addresses. To optimize searches. /** Pointer to the patch tree for instructions replaced by 'int 3'. */ /** Global PATM lookup and call function (used by call patches). */ /** Global PATM return function (used by ret patches). */ /** Global PATM jump function (used by indirect jmp patches). */ /** Fake patch record for global functions. */ /** Pointer to original sysenter handler */ /** Pointer to sysenter handler trampoline */ /** Sysenter patch index (for stats only) */ // GC address of fault in monitored page (set by PATMGCMonitorPage, used by PATMR3HandleMonitoredPage) /* Temporary information for pending MMIO patch. Set in GC or R0 context. */ /* Temporary storage during load/save state */ * Execute state save operation. * @returns VBox status code. * @param pSSM SSM operation handle. * Execute state load operation. * @returns VBox status code. * @param pSSM SSM operation handle. * @param u32Version Data layout version. /* Add a patch to guest lookup record * @param pVM The VM to operate on. * @param pPatch Patch structure ptr * @param pPatchInstrHC Guest context pointer to patch block * @param pInstrGC Guest context pointer to privileged instruction * @param enmType Lookup type * @param fDirty Dirty flag * Insert page records for all guest pages that contain instructions that were recompiled for this patch * @returns VBox status code. * @param pVM The VM to operate on. * @param pPatch Patch record * Remove page records for all guest pages that contain instructions that were recompiled for this patch * @returns VBox status code. * @param pVM The VM to operate on. * @param pPatch Patch record * Returns the GC address of the corresponding patch statistics counter * @param pVM The VM to operate on. * @param pPatch Patch structure * Remove patch for privileged instruction at specified location * @returns VBox status code. * @param pVM The VM to operate on. * @param pPatchRec Patch record * @param fForceRemove Remove *all* patches * Call for analysing the instructions following the privileged instr. for compliance with our heuristics * @returns VBox status code. * @param pVM The VM to operate on. * @param pCpu CPU disassembly state * @param pInstrHC Guest context pointer to privileged instruction * @param pCurInstrHC Guest context pointer to current instruction * @param pUserData User pointer * Install guest OS specific patch * @returns VBox status code. * @param pVM The VM to operate on * @param pCpu Disassembly state of instruction. * @param pInstrGC GC Instruction pointer for instruction * @param pInstrHC GC Instruction pointer for instruction * @param pPatchRec Patch structure * Convert guest context address to host context pointer * @returns VBox status code. * @param pVM The VM to operate on. * @param pPatch Patch block structure pointer * @param pGCPtr Guest context pointer * @returns Host context pointer or NULL in case of an error * Check if the instruction is patched as a duplicated function * @param pVM The VM to operate on. * @param pInstrGC Guest context point to the instruction /* Empty the specified tree (PV tree, MMR3 heap) * @param pVM The VM to operate on. * @param ppTree Tree to empty * Return the name of the patched instruction * @returns instruction name * @param opcode DIS instruction opcode * @param fPatchFlags Patch flags * Read callback for disassembly function; supports reading bytes that cross a page boundary * @returns VBox status code. * @param pSrc GC source pointer * @param pDest HC destination pointer * @param size Number of bytes to read * @param dwUserdata Callback specific user data (pCpu) #
define PATMREAD_ORGCODE 2 /* read original guest opcode bytes; not the patched bytes */ * Private structure used during disassembly * #PF Virtual Handler callback for Guest access a page monitored by PATM * @returns VBox status code (appropritate for trap handling and GC return). * @param uErrorCode CPU Error code. * @param pRegFrame Trap register frame. * @param pvFault The fault address (cr2). * @param pvRange The base address of the handled virtual range. * @param offRange The offset of the access into this range. * (If it's a EIP range this's the EIP, if not it's pvFault.) * Find patch for privileged instruction at specified location * @returns Patch structure pointer if found; else NULL * @param pVM The VM to operate on. * @param pInstr Guest context point to instruction that might lie within 5 bytes of an existing patch jump * @param fIncludeHints Include hinted patches or not * @returns VBox status code. * @param pVM The VM to operate on. * @param pInstrGC Guest context point to privileged instruction * @param pInstrHC Host context point to privileged instruction * @param uOpcode Instruction opcodee * @param uOpSize Size of starting instruction * @param pPatchRec Patch record * @note returns failure if patching is not allowed or possible * @returns VBox status code. * @param pVM The VM to operate on. * @param pPatch Patch record * @note returns failure if patching is not allowed or possible * Calculate the branch destination * @returns branch destination or 0 if failed * @param pCpu Disassembly state of instruction. * @param pBranchInstrGC GC pointer of branch instruction