pgm.h revision 98427c0ab08697e468c26dc33ee9571308577867
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * PGM - Page Monitor / Monitor.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Copyright (C) 2006-2013 Oracle Corporation
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * available from http://www.virtualbox.org. This file is free software;
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * General Public License (GPL) as published by the Free Software
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * The contents of this file may alternatively be used under the terms
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * of the Common Development and Distribution License Version 1.0
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * VirtualBox OSE distribution, in which case the provisions of the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * CDDL are applicable instead of those of the GPL.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * You may elect to license modified versions of this file under the
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * terms and conditions of either the GPL or the CDDL or both.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync#include <VBox/vmm/gmm.h> /* for PGMMREGISTERSHAREDMODULEREQ */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync#include <VBox/VMMDev.h> /* for VMMDEVSHAREDREGIONDESC */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync/** @defgroup grp_pgm The Page Monitor / Manager API
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * FNPGMRELOCATE callback mode.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync /** The callback is for checking if the suggested address is suitable. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync /** The callback is for executing the relocation. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Callback function which will be called when PGM is trying to find
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * a new location for the mapping.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * The callback is called in two modes, 1) the check mode and 2) the relocate mode.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * In 1) the callback should say if it objects to a suggested new location. If it
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * accepts the new location, it is called again for doing it's relocation.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @returns true if the location is ok.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @returns false if another location should be found.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param GCPtrOld The old virtual address.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param GCPtrNew The new virtual address.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param enmMode Used to indicate the callback mode.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param pvUser User argument.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @remark The return value is no a failure indicator, it's an acceptance
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * indicator. Relocation can not fail!
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynctypedef DECLCALLBACK(bool) FNPGMRELOCATE(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser);
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync/** Pointer to a relocation callback function. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Physical page access handler type.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync /** MMIO range. Pages are not present, all access is done in interpreter or recompiler. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync /** Handler all write access to a physical page range. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync /** Handler all access to a physical page range. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * \#PF Handler callback for physical access handler ranges in RC.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @returns VBox status code (appropriate for RC return).
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param pVM VM Handle.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param uErrorCode CPU Error code.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param pRegFrame Trap register frame.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * NULL on DMA and other non CPU access.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param pvFault The fault address (cr2).
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param pvUser User argument.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynctypedef DECLCALLBACK(int) FNPGMRCPHYSHANDLER(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync/** Pointer to PGM access callback. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * \#PF Handler callback for physical access handler ranges in R0.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @returns VBox status code (appropriate for R0 return).
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param pVM VM Handle.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param uErrorCode CPU Error code.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param pRegFrame Trap register frame.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * NULL on DMA and other non CPU access.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param pvFault The fault address (cr2).
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param GCPhysFault The GC physical address corresponding to pvFault.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * @param pvUser User argument.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynctypedef DECLCALLBACK(int) FNPGMR0PHYSHANDLER(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync/** Pointer to PGM access callback. */
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync * Guest Access type
typedef DECLCALLBACK(int) FNPGMR3PHYSHANDLER(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
typedef enum PGMVIRTHANDLERTYPE
typedef DECLCALLBACK(int) FNPGMRCVIRTHANDLER(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
typedef DECLCALLBACK(int) FNPGMR3VIRTHANDLER(PVM pVM, RTGCPTR GCPtr, void *pvPtr, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
typedef DECLCALLBACK(int) FNPGMENUMDIRTYFTPAGES(PVM pVM, RTGCPHYS GCPhys, uint8_t *pRange, unsigned cbRange, void *pvUser);
typedef enum PGMMODE
PGMMODE_INVALID = 0,
} PGMMODE;
VMMDECL(int) PGMTrap0eHandler(PVMCPU pVCpu, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault);
VMMDECL(VBOXSTRICTRC) PGMInterpretInstruction(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault);
#ifndef IN_RING0
#ifdef VBOX_STRICT
VMMDECL(int) PGMGstModifyPage(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
VMMDECL(int) PGMHandlerPhysicalRegisterEx(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
VMMDECL(int) PGMHandlerPhysicalModify(PVM pVM, RTGCPHYS GCPhysCurrent, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast);
VMMDECL(int) PGMHandlerPhysicalPageAlias(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage, RTGCPHYS GCPhysPageRemap);
VMMDECL(int) PGMHandlerPhysicalPageAliasHC(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage, RTHCPHYS HCPhysPageRemap);
VMMDECL(int) PGMPhysSimpleDirtyWriteGCPtr(PVMCPU pVCpu, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
VMMDECL(int) PGMPhysInterpretedRead(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
VMMDECL(int) PGMPhysInterpretedReadNoHandlers(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCUINTPTR GCPtrSrc, size_t cb, bool fRaiseTrap);
VMMDECL(int) PGMPhysInterpretedWriteNoHandlers(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, RTGCPTR GCPtrDst, void const *pvSrc, size_t cb, bool fRaiseTrap);
VMM_INT_DECL(int) PGMPhysIemGCPhys2Ptr(PVM pVM, RTGCPHYS GCPhys, bool fWritable, bool fByPassHandlers, void **ppv, PPGMPAGEMAPLOCK pLock);
#ifdef VBOX_STRICT
#ifdef IN_RC
#ifdef IN_RING0
VMMR0DECL(int) PGMR0SharedModuleCheck(PVM pVM, PGVM pGVM, VMCPUID idCpu, PGMMSHAREDMODULE pModule, PCRTGCPTR64 paRegionsGCPtrs);
VMMR0DECL(int) PGMR0Trap0eHandlerNestedPaging(PVM pVM, PVMCPU pVCpu, PGMMODE enmShwPagingMode, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPHYS pvFault);
VMMR0DECL(VBOXSTRICTRC) PGMR0Trap0eHandlerNPMisconfig(PVM pVM, PVMCPU pVCpu, PGMMODE enmShwPagingMode, PCPUMCTXCORE pRegFrame, RTGCPHYS GCPhysFault, uint32_t uErr);
# ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
#ifdef IN_RING3
VMMR3DECL(int) PGMR3PhysChangeMemBalloon(PVM pVM, bool fInflate, unsigned cPages, RTGCPHYS *paPhysPage);
VMMR3DECL(int) PGMR3PhysGetRange(PVM pVM, uint32_t iRange, PRTGCPHYS pGCPhysStart, PRTGCPHYS pGCPhysLast,
VMMR3DECL(int) PGMR3QueryMemoryStats(PUVM pUVM, uint64_t *pcbTotalMem, uint64_t *pcbPrivateMem, uint64_t *pcbSharedMem, uint64_t *pcbZeroMem);
VMMR3DECL(int) PGMR3QueryGlobalMemoryStats(PUVM pUVM, uint64_t *pcbAllocMem, uint64_t *pcbFreeMem, uint64_t *pcbBallonedMem, uint64_t *pcbSharedMem);
VMMR3DECL(int) PGMR3PhysMMIO2Register(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc);
VMMR3DECL(int) PGMR3PhysMMIO2GetHCPhys(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, PRTHCPHYS pHCPhys);
VMMR3DECL(int) PGMR3PhysMMIO2MapKernel(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb, const char *pszDesc, PRTR0PTR pR0Ptr);
VMMR3DECL(int) PGMR3PhysRegister(PVM pVM, void *pvRam, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, const SUPPAGE *paPages, const char *pszDesc);
VMMR3DECL(int) PGMR3MapPT(PVM pVM, RTGCPTR GCPtr, uint32_t cb, uint32_t fFlags, PFNPGMRELOCATE pfnRelocate, void *pvUser, const char *pszDesc);
#ifdef VBOX_WITH_RAW_MODE
VMMR3DECL(int) PGMR3HandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
VMMDECL(int) PGMR3HandlerVirtualRegisterEx(PVM pVM, PGMVIRTHANDLERTYPE enmType, RTGCPTR GCPtr, RTGCPTR GCPtrLast,
VMMR3DECL(int) PGMR3HandlerVirtualRegister(PVM pVM, PGMVIRTHANDLERTYPE enmType, RTGCPTR GCPtr, RTGCPTR GCPtrLast,
VMMDECL(int) PGMHandlerVirtualChangeInvalidateCallback(PVM pVM, RTGCPTR GCPtr, R3PTRTYPE(PFNPGMR3VIRTINVALIDATE) pfnInvalidateR3);
VMMR3DECL(int) PGMR3PhysWriteExternal(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, const char *pszWho);
VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrExternal(PVM pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock);
VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrReadOnlyExternal(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock);
VMMR3_INT_DECL(int) PGMR3DbgReadGCPhys(PVM pVM, void *pvDst, RTGCPHYS GCPhysSrc, size_t cb, uint32_t fFlags, size_t *pcbRead);
VMMR3_INT_DECL(int) PGMR3DbgWriteGCPhys(PVM pVM, RTGCPHYS GCPhysDst, const void *pvSrc, size_t cb, uint32_t fFlags, size_t *pcbWritten);
VMMR3_INT_DECL(int) PGMR3DbgReadGCPtr(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb, uint32_t fFlags, size_t *pcbRead);
VMMR3_INT_DECL(int) PGMR3DbgWriteGCPtr(PVM pVM, RTGCPTR GCPtrDst, void const *pvSrc, size_t cb, uint32_t fFlags, size_t *pcbWritten);
VMMR3_INT_DECL(int) PGMR3DbgScanPhysical(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cbRange, RTGCPHYS GCPhysAlign, const uint8_t *pabNeedle, size_t cbNeedle, PRTGCPHYS pGCPhysHit);
VMMR3_INT_DECL(int) PGMR3DbgScanVirtual(PVM pVM, PVMCPU pVCpu, RTGCPTR GCPtr, RTGCPTR cbRange, RTGCPTR GCPtrAlign, const uint8_t *pabNeedle, size_t cbNeedle, PRTGCUINTPTR pGCPhysHit);
VMMR3_INT_DECL(int) PGMR3DumpHierarchyShw(PVM pVM, uint64_t cr3, uint32_t fFlags, uint64_t u64FirstAddr, uint64_t u64LastAddr, uint32_t cMaxDepth, PCDBGFINFOHLP pHlp);
VMMR3_INT_DECL(int) PGMR3DumpHierarchyGst(PVM pVM, uint64_t cr3, uint32_t fFlags, RTGCPTR FirstAddr, RTGCPTR LastAddr, uint32_t cMaxDepth, PCDBGFINFOHLP pHlp);
VMMR3DECL(int) PGMR3SharedModuleRegister(PVM pVM, VBOXOSFAMILY enmGuestOS, char *pszModuleName, char *pszVersion,
VMMR3DECL(int) PGMR3SharedModuleGetPageState(PVM pVM, RTGCPTR GCPtrPage, bool *pfShared, uint64_t *pfPageFlags);