PGMAllGst.h revision f70ef34415a9ed747c4f89047a8cdcc453552c40
/* $Id$ */
/** @file
* VBox - Page Manager, Guest Paging Template - All context code.
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
#if PGM_GST_TYPE == PGM_TYPE_32BIT \
|| PGM_GST_TYPE == PGM_TYPE_PAE \
|| PGM_GST_TYPE == PGM_TYPE_AMD64
#endif
PGM_GST_DECL(int, ModifyPage)(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
#if PGM_GST_TYPE == PGM_TYPE_32BIT \
|| PGM_GST_TYPE == PGM_TYPE_PAE \
|| PGM_GST_TYPE == PGM_TYPE_AMD64
{
return VERR_PAGE_TABLE_NOT_PRESENT;
}
DECLINLINE(int) PGM_GST_NAME(WalkReturnBadPhysAddr)(PVMCPU pVCpu, PGSTPTWALK pWalk, int rc, int iLevel)
{
return VERR_PAGE_TABLE_NOT_PRESENT;
}
{
return VERR_PAGE_TABLE_NOT_PRESENT;
}
/**
* Performs a guest page table walk.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_PAGE_TABLE_NOT_PRESENT on failure. Check pWalk for details.
*
* @param pVCpu The current CPU.
* @param GCPtr The guest virtual address to walk by.
* @param pWalk Where to return the walk result. This is always set.
*/
{
int rc;
/*
* Init the walking structure.
*/
# if PGM_GST_TYPE == PGM_TYPE_32BIT \
|| PGM_GST_TYPE == PGM_TYPE_PAE
/*
* Boundary check for PAE and 32-bit (prevents trouble further down).
*/
# endif
{
# if PGM_GST_TYPE == PGM_TYPE_AMD64
/*
* The PMLE4.
*/
if (RT_FAILURE(rc))
/*
* The PDPE.
*/
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
# endif
}
{
/*
* The PDE.
*/
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
# endif
}
{
{
| (GCPtr & GST_BIG_PAGE_OFFSET_MASK);
# if PGM_GST_TYPE == PGM_TYPE_AMD64
# endif
;
# if PGM_GST_TYPE == PGM_TYPE_AMD64
# endif
) && GST_IS_NX_ACTIVE(pVCpu);
# else
# endif
return VINF_SUCCESS;
}
/*
* The PTE.
*/
if (RT_FAILURE(rc))
}
{
/*
* We're done.
*/
| (GCPtr & PAGE_OFFSET_MASK);
# if PGM_GST_TYPE == PGM_TYPE_AMD64
# endif
;
# if PGM_GST_TYPE == PGM_TYPE_AMD64
# endif
) && GST_IS_NX_ACTIVE(pVCpu);
# else
# endif
return VINF_SUCCESS;
}
}
#endif /* 32BIT, PAE, AMD64 */
/**
* Gets effective Guest OS page information.
*
* When GCPtr is in a big page, the function will return as if it was a normal
* 4KB page. If the need for distinguishing between big and normal page becomes
* necessary at a later point, a PGMGstGetPage Ex() will be created for that
* purpose.
*
* @returns VBox status.
* @param pVCpu The VMCPU handle.
* @param GCPtr Guest Context virtual address of the page.
* @param pfFlags Where to store the flags. These are X86_PTE_*, even for big pages.
* @param pGCPhys Where to store the GC physical address of the page.
* This is page aligned!
*/
{
#if PGM_GST_TYPE == PGM_TYPE_REAL \
|| PGM_GST_TYPE == PGM_TYPE_PROT
/*
* Fake it.
*/
if (pfFlags)
if (pGCPhys)
return VINF_SUCCESS;
|| PGM_GST_TYPE == PGM_TYPE_PAE \
|| PGM_GST_TYPE == PGM_TYPE_AMD64
if (RT_FAILURE(rc))
return rc;
if (pGCPhys)
if (pfFlags)
{
# endif
;
else
{
*pfFlags = (Walk.Pde.u & ~(GST_PTE_PG_MASK | X86_PDE4M_RW | X86_PDE4M_US | X86_PDE4M_PS)) /* NX not needed */
# endif
;
}
}
return VINF_SUCCESS;
#else
# error "shouldn't be here!"
/* something else... */
return VERR_NOT_SUPPORTED;
#endif
}
/**
* Modify page flags for a range of pages in the guest's tables
*
* The existing flags are ANDed with the fMask and ORed with the fFlags.
*
* @returns VBox status code.
* @param pVCpu The VMCPU handle.
* @param GCPtr Virtual address of the first page in the range. Page aligned!
* @param cb Size (in bytes) of the page range to apply the modification to. Page aligned!
* @param fFlags The OR mask - page flags X86_PTE_*, excluding the page mask of course.
* @param fMask The AND mask - page flags X86_PTE_*.
*/
PGM_GST_DECL(int, ModifyPage)(PVMCPU pVCpu, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask)
{
#if PGM_GST_TYPE == PGM_TYPE_32BIT \
|| PGM_GST_TYPE == PGM_TYPE_PAE \
|| PGM_GST_TYPE == PGM_TYPE_AMD64
for (;;)
{
if (RT_FAILURE(rc))
return rc;
{
/*
* 4KB Page table, process
*
* Walk pages till we're done.
*/
{
| (fFlags & ~GST_PTE_PG_MASK);
/* next page */
if (!cb)
return VINF_SUCCESS;
iPTE++;
}
}
else
{
/*
* 4MB Page table
*/
# if PGM_GST_TYPE == PGM_TYPE_32BIT
PdeNew.u = (Walk.Pde.u & (fMask | ((fMask & X86_PTE_PAT) << X86_PDE4M_PAT_SHIFT) | GST_PDE_BIG_PG_MASK | X86_PDE4M_PG_HIGH_MASK | X86_PDE4M_PS))
# else
PdeNew.u = (Walk.Pde.u & (fMask | ((fMask & X86_PTE_PAT) << X86_PDE4M_PAT_SHIFT) | GST_PDE_BIG_PG_MASK | X86_PDE4M_PS))
# endif
| (fFlags & ~GST_PTE_PG_MASK)
/* advance */
return VINF_SUCCESS;
}
}
#else
/* real / protected mode: ignore. */
return VINF_SUCCESS;
#endif
}
/**
* Retrieve guest PDE information.
*
* @returns VBox status code.
* @param pVCpu The VMCPU handle.
* @param GCPtr Guest context pointer.
* @param pPDE Pointer to guest PDE structure.
*/
{
#if PGM_GST_TYPE == PGM_TYPE_32BIT \
|| PGM_GST_TYPE == PGM_TYPE_PAE \
|| PGM_GST_TYPE == PGM_TYPE_AMD64
# if PGM_GST_TYPE != PGM_TYPE_AMD64
/* Boundary check. */
return VERR_PAGE_TABLE_NOT_PRESENT;
# endif
# if PGM_GST_TYPE == PGM_TYPE_32BIT
unsigned iPd = 0; /* shut up gcc */
unsigned iPd = 0; /* shut up gcc */
/* Note! We do not return an effective PDE here like we do for the PTE in GetPage method. */
# endif
else
pPDE->u = 0;
return VINF_SUCCESS;
#else
AssertFailed();
return VERR_NOT_IMPLEMENTED;
#endif
}
#if PGM_GST_TYPE == PGM_TYPE_32BIT \
|| PGM_GST_TYPE == PGM_TYPE_PAE \
|| PGM_GST_TYPE == PGM_TYPE_AMD64
/**
* Updates one virtual handler range.
*
* @returns 0
* @param pNode Pointer to a PGMVIRTHANDLER.
* @param pvUser Pointer to a PGMVHUARGS structure (see PGM.cpp).
*/
static DECLCALLBACK(int) PGM_GST_NAME(VirtHandlerUpdateOne)(PAVLROGCPTRNODECORE pNode, void *pvUser)
{
# if PGM_GST_TYPE == PGM_TYPE_32BIT
# endif
# if PGM_GST_TYPE != PGM_TYPE_AMD64
/* skip all stuff above 4GB if not AMD64 mode. */
return 0;
# endif
unsigned iPage = 0;
{
# if PGM_GST_TYPE == PGM_TYPE_32BIT
# endif
# if PGM_GST_TYPE == PGM_TYPE_32BIT
# else
# endif
&& ( !fBigPage
{
if (!fBigPage)
{
/*
* Normal page table.
*/
if (RT_SUCCESS(rc))
{
{
else
{
("{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32} GCPhysNew=%RGp\n",
#endif
}
}
}
else
{
/* not-present. */
offPage = 0;
{
{
("{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32}\n",
#endif
}
}
}
}
else
{
/*
* 2/4MB page.
*/
{
{
("{.Core.Key=%RGp, .Core.KeyLast=%RGp, .offVirtHandler=%#RX32, .offNextAlias=%#RX32} GCPhysNew=%RGp\n",
#endif
}
}
} /* pde type */
}
else
{
/* not-present / invalid. */
{
{
}
}
offPage = 0;
}
} /* for pages in virtual mapping. */
return 0;
}
#endif /* 32BIT, PAE and AMD64 */
/**
* Updates the virtual page access handlers.
*
* @returns true if bits were flushed.
* @returns false if bits weren't flushed.
* @param pVM VM handle.
* @param pPDSrc The page directory.
* @param cr4 The cr4 register value.
*/
{
#if PGM_GST_TYPE == PGM_TYPE_32BIT \
|| PGM_GST_TYPE == PGM_TYPE_PAE \
|| PGM_GST_TYPE == PGM_TYPE_AMD64
/** @todo
* In theory this is not sufficient: the guest can change a single page in a range with invlpg
*/
/*
* Resolve any virtual address based access handlers to GC physical addresses.
* This should be fairly quick.
*/
{
RTAvlroGCPtrDoWithAll(&pVM->pgm.s.CTX_SUFF(pTrees)->VirtHandlers, true, PGM_GST_NAME(VirtHandlerUpdateOne), &State);
}
/*
* Set / reset bits?
*/
{
Log(("HandlerVirtualUpdate: resets bits\n"));
RTAvlroGCPtrDoWithAll(&pVM->pgm.s.CTX_SUFF(pTrees)->VirtHandlers, true, pgmHandlerVirtualResetOne, pVM);
{
}
}
return !!(fTodo & PGM_SYNC_UPDATE_PAGE_BIT_VIRTUAL);
#else /* real / protected */
return false;
#endif
}