PGMAll.cpp revision d32c860c64e340970271b4113a6a67cad64460b4
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * PGM - Page Manager and Monitor - All context code.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 2006-2007 Sun Microsystems, Inc.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * This file is part of VirtualBox Open Source Edition (OSE), as
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * available from http://www.virtualbox.org. This file is free software;
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * you can redistribute it and/or modify it under the terms of the GNU
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * General Public License (GPL) as published by the Free Software
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Foundation, in version 2 as it comes in the "COPYING" file of the
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
f41f183f628a148860a6d1f0070208cddd45b0c6Bob Halley * Clara, CA 95054 USA or visit http://www.sun.com if you need
f41f183f628a148860a6d1f0070208cddd45b0c6Bob Halley * additional information or have any questions.
9a2127f8335bad323451d7825119cd9f72e32464Mark Andrews/*******************************************************************************
9a2127f8335bad323451d7825119cd9f72e32464Mark Andrews* Header Files *
9a2127f8335bad323451d7825119cd9f72e32464Mark Andrews*******************************************************************************/
76117ff568dc788ed24937cfea916a18db285960Mark Andrews/*******************************************************************************
37dee1ff94960a61243f611c0f87f8c316815c53Mark Andrews* Structures and Typedefs *
76117ff568dc788ed24937cfea916a18db285960Mark Andrews*******************************************************************************/
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews * Stated structure for PGM_GST_NAME(HandlerVirtualUpdate) that's
76117ff568dc788ed24937cfea916a18db285960Mark Andrews * passed to PGM_GST_NAME(VirtHandlerUpdateOne) during enumeration.
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson /** The VM handle. */
e334405421979688f2d838805ac67ee47bd62976Mark Andrews /** The todo flags. */
e334405421979688f2d838805ac67ee47bd62976Mark Andrews /** The CR4 register value. */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews/*******************************************************************************
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews* Internal Functions *
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews*******************************************************************************/
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Shadow - 32-bit mode
5c6762838c9e423753723ec2a963164e3d66ac32Mark Andrews#define PGM_SHW_NAME(name) PGM_SHW_NAME_32BIT(name)
37dee1ff94960a61243f611c0f87f8c316815c53Mark Andrews/* Guest - real mode */
76117ff568dc788ed24937cfea916a18db285960Mark Andrews#define PGM_GST_NAME(name) PGM_GST_NAME_REAL(name)
76117ff568dc788ed24937cfea916a18db285960Mark Andrews#define PGM_BTH_NAME(name) PGM_BTH_NAME_32BIT_REAL(name)
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews#define BTH_PGMPOOLKIND_PT_FOR_PT PGMPOOLKIND_32BIT_PT_FOR_PHYS
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt/* Guest - protected mode */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#define PGM_GST_NAME(name) PGM_GST_NAME_PROT(name)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#define PGM_BTH_NAME(name) PGM_BTH_NAME_32BIT_PROT(name)
3cd88f71b01833d5c2474638854dfa5c4244a22aBrian Wellington#define BTH_PGMPOOLKIND_PT_FOR_PT PGMPOOLKIND_32BIT_PT_FOR_PHYS
494576ce20cfd98d74955698cf8f7b37dce2f740Mark Andrews/* Guest - 32-bit mode */
4fd3e3482c7e4ce01e2cf28f13e0152c8e50d746Mark Andrews#define PGM_GST_NAME(name) PGM_GST_NAME_32BIT(name)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley#define PGM_BTH_NAME(name) PGM_BTH_NAME_32BIT_32BIT(name)
d2b5fe92a4755ce67f2dd6050955782b4fd6b3f3Mark Andrews#define BTH_PGMPOOLKIND_PT_FOR_PT PGMPOOLKIND_32BIT_PT_FOR_32BIT_PT
d2b5fe92a4755ce67f2dd6050955782b4fd6b3f3Mark Andrews#define BTH_PGMPOOLKIND_PT_FOR_BIG PGMPOOLKIND_32BIT_PT_FOR_32BIT_4MB
fd35453765c6494d077edca44f4d998af5fd4cfaDavid Lawrence * Shadow - PAE mode
74cb99072c4b0ebd2ccafcfa284288fa760f7a1aMark Andrews#define PGM_SHW_NAME(name) PGM_SHW_NAME_PAE(name)
9f7d51ee3290e2a064d71016a6bd555b47134a7cMark Andrews#define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_REAL(name)
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley/* Guest - real mode */
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley#define PGM_GST_NAME(name) PGM_GST_NAME_REAL(name)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley#define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_REAL(name)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley#define BTH_PGMPOOLKIND_PT_FOR_PT PGMPOOLKIND_PAE_PT_FOR_PHYS
fd35453765c6494d077edca44f4d998af5fd4cfaDavid Lawrence/* Guest - protected mode */
4fd3e3482c7e4ce01e2cf28f13e0152c8e50d746Mark Andrews#define PGM_GST_NAME(name) PGM_GST_NAME_PROT(name)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_PROT(name)
6ef838d427c1ea858d2f09194a369134babf8b98Mark Andrews#define BTH_PGMPOOLKIND_PT_FOR_PT PGMPOOLKIND_PAE_PT_FOR_PHYS
64e41159a919b0711321fe688ca5da4f4d1b7d80Bob Halley/* Guest - 32-bit mode */
6d7585b3e948dd31bf78321d83ac0e024f44a71bMark Andrews#define PGM_GST_NAME(name) PGM_GST_NAME_32BIT(name)
6d5dcd0dc9bdbd679282b1ffc47987d24c3a1346Bob Halley#define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_32BIT(name)
6d7585b3e948dd31bf78321d83ac0e024f44a71bMark Andrews#define BTH_PGMPOOLKIND_PT_FOR_PT PGMPOOLKIND_PAE_PT_FOR_32BIT_PT
6d7585b3e948dd31bf78321d83ac0e024f44a71bMark Andrews#define BTH_PGMPOOLKIND_PT_FOR_BIG PGMPOOLKIND_PAE_PT_FOR_32BIT_4MB
4fd3e3482c7e4ce01e2cf28f13e0152c8e50d746Mark Andrews/* Guest - PAE mode */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_PAE(name)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define BTH_PGMPOOLKIND_PT_FOR_PT PGMPOOLKIND_PAE_PT_FOR_PAE_PT
118394ef2ec7cef253c55359a3d70d202ddc2fa0Mark Andrews#define BTH_PGMPOOLKIND_PT_FOR_BIG PGMPOOLKIND_PAE_PT_FOR_PAE_2MB
#include "PGMAllShw.h"
#include "PGMAllBth.h"
#include "PGMAllGst.h"
#include "PGMAllBth.h"
#include "PGMAllShw.h"
#include "PGMAllBth.h"
#include "PGMAllBth.h"
#include "PGMAllBth.h"
#include "PGMAllBth.h"
#include "PGMAllBth.h"
LogFlow(("PGMTrap0eHandler: uErr=%#x pvFault=%VGv eip=%VGv\n", (uint32_t)uErr, pvFault, pRegFrame->rip));
#ifdef VBOX_WITH_STATISTICS
return rc;
return rc;
while (pMapping)
return pMapping;
return NULL;
* @param fAccess Access type (r/w, user/supervisor (X86_PTE_*))
return VERR_INVALID_PARAMETER;
return VINF_EM_RAW_GUEST_TRAP;
Log(("PGMIsValidAccess: access violation for %VGv attr %#llx vs %d:%d\n", Addr, fPage, fWrite, fUser));
return VINF_EM_RAW_GUEST_TRAP;
return PGMIsValidAccess(pVM, Addr + PAGE_SIZE, (cbSize > PAGE_SIZE) ? cbSize - PAGE_SIZE : 1, fAccess);
return rc;
* @param fAccess Access type (r/w, user/supervisor (X86_PTE_*))
return VERR_INVALID_PARAMETER;
return VINF_EM_RAW_GUEST_TRAP;
Log(("PGMVerifyAccess: access violation for %VGv attr %#llx vs %d:%d\n", Addr, fPageGst, fWrite, fUser));
return VINF_EM_RAW_GUEST_TRAP;
return rc;
return VINF_EM_RAW_GUEST_TRAP;
return rc;
#ifndef IN_GC
int rc;
#ifndef IN_RING3
return rc;
#ifndef IN_RING0
#ifdef IN_RING3
/** @note this is to check if monitored pages have been changed; when we implement callbacks for virtual handlers, this is no longer required. */
return rc;
return rc;
return VERR_INVALID_PARAMETER;
if (!cb)
AssertFailed();
return VERR_INVALID_PARAMETER;
GCPtr = (RTGCPTR)((RTGCUINTPTR)GCPtr & PAGE_BASE_GC_MASK); /** @todo this ain't necessary, right... */
#ifndef IN_GC
PGMDECL(int) PGMShwSyncLongModePDPtr(PVM pVM, RTGCUINTPTR64 GCPtr, PX86PML4E pGstPml4e, PX86PDPE pGstPdpe, PX86PDPAE *ppPD)
int rc;
rc = pgmPoolAlloc(pVM, pPml4eGst->u & X86_PML4E_PG_MASK, PGMPOOLKIND_64BIT_PDPT_FOR_64BIT_PDPT, PGMPOOL_IDX_PML4, iPml4e, &pShwPage);
return VINF_PGM_SYNC_CR3;
rc = pgmPoolAlloc(pVM, pPdptGst->a[iPdPt].u & X86_PDPE_PG_MASK, PGMPOOLKIND_PAE_PD_FOR_PAE_PD, PGMPOOL_IDX_PDPT, iPdPt, &pShwPage);
return VINF_PGM_SYNC_CR3;
return VINF_SUCCESS;
PGMDECL(int) PGMShwGetLongModePDPtr(PVM pVM, RTGCUINTPTR64 GCPtr, PX86PDPT *ppPdpt, PX86PDPAE *ppPD)
return VERR_PAGE_MAP_LEVEL4_NOT_PRESENT;
return VINF_SUCCESS;
return VERR_INVALID_PARAMETER;
if (!cb)
AssertFailed();
return VERR_INVALID_PARAMETER;
return rc;
switch (enmShadowMode)
case PGMMODE_32_BIT:
case PGMMODE_PAE:
case PGMMODE_PAE_NX:
case PGMMODE_AMD64:
case PGMMODE_AMD64_NX:
case PGMMODE_NESTED:
switch (enmShadowMode)
case PGMMODE_32_BIT:
case PGMMODE_PAE:
case PGMMODE_PAE_NX:
case PGMMODE_AMD64:
case PGMMODE_AMD64_NX:
case SUPPAGINGMODE_32_BIT:
case SUPPAGINGMODE_PAE:
case SUPPAGINGMODE_PAE_GLOBAL:
case SUPPAGINGMODE_PAE_NX:
case SUPPAGINGMODE_AMD64:
case SUPPAGINGMODE_AMD64_NX:
case PGMMODE_32_BIT:
case PGMMODE_PAE:
case PGMMODE_PAE_NX:
case PGMMODE_AMD64:
case PGMMODE_AMD64_NX:
case PGMMODE_NESTED:
if (fGlobal)
if (fGlobal)
if (fGlobal)
return rc;
return rc;
return VINF_SUCCESS;
fGlobal = true;
return rc;
return VINF_SUCCESS;
#ifdef IN_RING3
return VINF_PGM_CHANGE_MODE;
case SUPPAGINGMODE_32_BIT:
return PGMMODE_32_BIT;
case SUPPAGINGMODE_PAE:
case SUPPAGINGMODE_PAE_GLOBAL:
return PGMMODE_PAE;
case SUPPAGINGMODE_PAE_NX:
return PGMMODE_PAE_NX;
case SUPPAGINGMODE_AMD64:
return PGMMODE_AMD64;
case SUPPAGINGMODE_AMD64_NX:
return PGMMODE_AMD64_NX;
return PGMMODE_INVALID;
switch (enmMode)
#ifdef IN_GC
return rc;
#ifdef VBOX_STRICT
unsigned cErrors = 0;
cErrors++;
return cErrors;
return cErrors;