PGMPhys.cpp revision b63d03870b3af0500db26555533205f0cce02f6b
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * PGM - Page Manager and Monitor, Physical Memory Addressing.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * available from http://www.virtualbox.org. This file is free software;
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * you can redistribute it and/or modify it under the terms of the GNU
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * General Public License (GPL) as published by the Free Software
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * additional information or have any questions.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync/*******************************************************************************
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync* Header Files *
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync*******************************************************************************/
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/*******************************************************************************
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync* Defined Constants And Macros *
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync*******************************************************************************/
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/** The number of pages to free in one batch. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync/*******************************************************************************
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync* Internal Functions *
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync*******************************************************************************/
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncstatic DECLCALLBACK(int) pgmR3PhysRomWriteHandler(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncstatic int pgmPhysFreePage(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t *pcPendingPages, PPGMPAGE pPage, RTGCPHYS GCPhys);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * PGMR3PhysReadU8-64
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * PGMR3PhysWriteU8-64
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * EMT worker for PGMR3PhysReadExternal.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncstatic DECLCALLBACK(int) pgmR3PhysReadExternalEMT(PVM pVM, PRTGCPHYS pGCPhys, void *pvBuf, size_t cbRead)
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync * Write to physical memory, external users.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @returns VBox status code.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @retval VINF_SUCCESS.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @param pVM VM Handle.
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync * @param GCPhys Physical address to write to.
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync * @param pvBuf What to write.
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync * @param cbWrite How many bytes to write.
db22a92f701bfcc17823963d6c8b745f68d44e30vboxsync * @thread Any but EMTs.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncVMMR3DECL(int) PGMR3PhysReadExternal(PVM pVM, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertMsgReturn(cbRead > 0, ("don't even think about reading zero bytes!\n"), VINF_SUCCESS);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync LogFlow(("PGMR3PhysReadExternal: %RGp %d\n", GCPhys, cbRead));
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Copy loop on ram ranges.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(pRamRanges);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /* Find range. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /* Inside range or not? */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Must work our way thru this page by page.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * If the page has an ALL access handler, we'll have to
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * delegate the job to EMT.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync int rc = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq, RT_INDEFINITE_WAIT,
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync (PFNRT)pgmR3PhysReadExternalEMT, 4, pVM, &GCPhys, pvBuf, cbRead);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Simple stuff, go ahead.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync const void *pvSrc;
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync int rc = pgmPhysGCPhys2CCPtrInternalReadOnly(pVM, pPage, pRam->GCPhys + off, &pvSrc);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertLogRelMsgFailed(("pgmPhysGCPhys2CCPtrInternalReadOnly failed on %RGp / %R[pgmpage] -> %Rrc\n",
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /* next page */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync } /* walk pages in ram range. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync LogFlow(("PGMPhysRead: Unassigned %RGp size=%u\n", GCPhys, cbRead));
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Unassigned address space.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync } /* Ram range walk */
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * EMT worker for PGMR3PhysWriteExternal.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsyncstatic DECLCALLBACK(int) pgmR3PhysWriteExternalEMT(PVM pVM, PRTGCPHYS pGCPhys, const void *pvBuf, size_t cbWrite)
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync /** @todo VERR_EM_NO_MEMORY */
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * Write to physical memory, external users.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * @returns VBox status code.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * @retval VINF_SUCCESS.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * @retval VERR_EM_NO_MEMORY.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * @param pVM VM Handle.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * @param GCPhys Physical address to write to.
835ac9173220411ef9fe578c3d4c03e5edfa20bevboxsync * @param pvBuf What to write.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @param cbWrite How many bytes to write.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * @thread Any but EMTs.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsyncVMMDECL(int) PGMR3PhysWriteExternal(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertMsg(!pVM->pgm.s.fNoMorePhysWrites, ("Calling PGMR3PhysWriteExternal after pgmR3Save()!\n"));
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync AssertMsgReturn(cbWrite > 0, ("don't even think about writing zero bytes!\n"), VINF_SUCCESS);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync LogFlow(("PGMR3PhysWriteExternal: %RGp %d\n", GCPhys, cbWrite));
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Copy loop on ram ranges, stop when we hit something difficult.
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync PPGMRAMRANGE pRam = pVM->pgm.s.CTX_SUFF(pRamRanges);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /* Find range. */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync /* Inside range or not? */
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Must work our way thru this page by page.
a917e98de4393d1090e536fdbeb04c285f98c92evboxsync * It the page is in any way problematic, we have to
a917e98de4393d1090e536fdbeb04c285f98c92evboxsync * do the work on the EMT. Anything that needs to be made
a917e98de4393d1090e536fdbeb04c285f98c92evboxsync * writable or involves access handlers is problematic.
a917e98de4393d1090e536fdbeb04c285f98c92evboxsync || PGM_PAGE_GET_STATE(pPage) != PGM_PAGE_STATE_ALLOCATED)
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync int rc = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq, RT_INDEFINITE_WAIT,
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync (PFNRT)pgmR3PhysWriteExternalEMT, 4, pVM, &GCPhys, pvBuf, cbWrite);
f1f5335f9ec8e56fe0e3e27f253e24b10ff20f2evboxsync * Simple stuff, go ahead.
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync int rc = pgmPhysGCPhys2CCPtrInternal(pVM, pPage, pRam->GCPhys + off, &pvDst);
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync AssertLogRelMsgFailed(("pgmPhysGCPhys2CCPtrInternal failed on %RGp / %R[pgmpage] -> %Rrc\n",
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync /* next page */
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync } /* walk pages in ram range */
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Unassigned address space, skip it.
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync } /* Ram range walk */
ac1200e63b58a0451085add197084e5a4a1bb4cavboxsync * VMR3ReqCall worker for PGMR3PhysGCPhys2CCPtrExternal to make pages writable.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * @returns see PGMR3PhysGCPhys2CCPtrExternal
510dd1bd989d25f95680fc2a3b51bf11854bc6a4vboxsync * @param pVM The VM handle.
510dd1bd989d25f95680fc2a3b51bf11854bc6a4vboxsync * @param pGCPhys Pointer to the guest physical address.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * @param ppv Where to store the mapping address.
44918d7b9fb45f0d3e2ba56bf6d2cede9a2ae566vboxsync * @param pLock Where to store the lock.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsyncstatic DECLCALLBACK(int) pgmR3PhysGCPhys2CCPtrDelegated(PVM pVM, PRTGCPHYS pGCPhys, void **ppv, PPGMPAGEMAPLOCK pLock)
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * Just hand it to PGMPhysGCPhys2CCPtr and check that it's not a page with
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * an access handler after it succeeds.
84c4a51d2a3c1a5c3f7d6902a8ac8c2eb267f4e0vboxsync rc = PGMPhysGCPhys2CCPtr(pVM, *pGCPhys, ppv, pLock);
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync int rc2 = pgmPhysPageQueryTlbe(&pVM->pgm.s, *pGCPhys, &pTlbe);
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync * Requests the mapping of a guest page into ring-3, external threads.
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync * When you're done with the page, call PGMPhysReleasePageMappingLock() ASAP to
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync * release it.
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync * This API will assume your intention is to write to the page, and will
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync * therefore replace shared and zero pages. If you do not intend to modify the
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync * page, use the PGMR3PhysGCPhys2CCPtrReadOnlyExternal() API.
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync * @returns VBox status code.
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync * @retval VINF_SUCCESS on success.
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
382dd16193dd5770e53a99d3e3f3bc4e96f1ddd8vboxsync * backing or if the page has any active access handlers. The caller
42f4857b15e5d875e39345f1d1b804c2c1313e91vboxsync * must fall back on using PGMR3PhysWriteExternal.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * @param pVM The VM handle.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * @param GCPhys The guest physical address of the page that should be mapped.
44918d7b9fb45f0d3e2ba56bf6d2cede9a2ae566vboxsync * @param ppv Where to store the address corresponding to GCPhys.
c40afa339b10a23d6fffcbeb7d4572bb494685f0vboxsync * @param pLock Where to store the lock information that PGMPhysReleasePageMappingLock needs.
VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrExternal(PVM pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock)
return rc;
return rc;
VMMR3DECL(int) PGMR3PhysGCPhys2CCPtrReadOnlyExternal(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock)
return rc;
#ifdef VBOX_STRICT
if (pCur)
if (pPrev)
if (pPrev)
static int pgmR3PhysFreePageRange(PVM pVM, PPGMRAMRANGE pRam, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast, uint8_t uType)
while (cPagesLeft-- > 0)
pPageDst++;
if (cPendingPages)
return rc;
static void pgmR3PhysInitAndLinkRamRange(PVM pVM, PPGMRAMRANGE pNew, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
while (iPage-- > 0)
static DECLCALLBACK(bool) pgmR3PhysRamRangeRelocate(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser)
switch (enmMode)
case PGMRELOCATECALL_SUGGEST:
case PGMRELOCATECALL_RELOCATE:
AssertFailedReturn(false);
? pszDesc
size_t const cChunkPages = RT_ALIGN_Z(RT_UOFFSETOF(PGMRAMRANGE, aPages[cRamPages]), PAGE_SIZE) >> PAGE_SHIFT;
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
NULL,
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
rc = PGMR3MapPT(pVM, GCPtrChunkMap, cbChunk, 0 /*fFlags*/, pgmR3PhysRamRangeRelocate, pNew, pszDescChunk);
return rc;
AssertMsgReturn(GCPhysLast > GCPhys, ("The range wraps! GCPhys=%RGp cb=%RGp\n", GCPhys, cb), VERR_INVALID_PARAMETER);
return rc;
while (cPagesLeft > 0)
rc = pgmR3PhysRegisterHighRamChunk(pVM, GCPhysChunk, cPagesInChunk, cbChunk, iChunk, pszDesc, &pPrev);
iChunk++;
pgmR3PhysInitAndLinkRamRange(pVM, pNew, GCPhys, GCPhysLast, NIL_RTRCPTR, NIL_RTR0PTR, pszDesc, pPrev);
return VINF_SUCCESS;
while (cLeft-- > 0)
case PGM_PAGE_STATE_ZERO:
LogRel(("PGM: RAM Pre-allocation failed at %RGp (in %s) with rc=%Rrc\n", GCPhys, pRam->pszDesc, rc));
return rc;
cPages++;
case PGM_PAGE_STATE_ALLOCATED:
case PGM_PAGE_STATE_SHARED:
pPage++;
return VINF_SUCCESS;
AssertMsg(((RTGCPHYS)iPage << PAGE_SHIFT) == pRam->cb, ("%RGp %RGp\n", (RTGCPHYS)iPage << PAGE_SHIFT, pRam->cb));
while (iPage-- > 0)
case PGMPAGETYPE_RAM:
rc = pgmPhysFreePage(pVM, pReq, &cPendingPages, pPage, pRam->GCPhys + ((RTGCPHYS)iPage << PAGE_SHIFT));
case PGMPAGETYPE_MMIO2:
case PGMPAGETYPE_ROM:
case PGMPAGETYPE_MMIO:
AssertFailed();
while (iPage-- > 0)
case PGMPAGETYPE_RAM:
case PGM_PAGE_STATE_ZERO:
case PGM_PAGE_STATE_SHARED:
case PGM_PAGE_STATE_ALLOCATED:
void *pvPage;
rc = pgmPhysPageMap(pVM, pPage, pRam->GCPhys + ((RTGCPHYS)iPage << PAGE_SHIFT), &pMapIgnored, &pvPage);
case PGMPAGETYPE_MMIO2:
case PGMPAGETYPE_ROM_SHADOW:
case PGMPAGETYPE_ROM:
case PGMPAGETYPE_MMIO:
AssertFailed();
if (cPendingPages)
return VINF_SUCCESS;
int rc;
bool fRamExists = false;
while (cLeft-- > 0)
pPage++;
fRamExists = true;
if (fRamExists)
Log(("PGMR3PhysMMIORegister: Adding ad-hoc MMIO range for %RGp-%RGp %s\n", GCPhys, GCPhysLast, pszDesc));
rc = MMHyperAlloc(pVM, RT_OFFSETOF(PGMRAMRANGE, aPages[cPages]), 16, MM_TAG_PGM_PHYS, (void **)&pNew);
while (iPage-- > 0)
&& !fRamExists)
return rc;
bool fAllMMIO = true;
while (cLeft-- > 0)
fAllMMIO = false;
pPage++;
if (fAllMMIO)
* Range match? It will all be within one range (see PGMAllHandler.cpp).
while (cLeft--)
AssertMsg(PGM_PAGE_IS_MMIO(pPage), ("%RGp %R[pgmpage]\n", pRam->GCPhys + ((RTGCPHYS)iPage << PAGE_SHIFT), pPage));
AssertMsg(PGM_PAGE_IS_ZERO(pPage), ("%RGp %R[pgmpage]\n", pRam->GCPhys + ((RTGCPHYS)iPage << PAGE_SHIFT), pPage));
return rc;
return pCur;
return NULL;
VMMR3DECL(int) PGMR3PhysMMIO2Register(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc)
if (!pszDesc)
return VERR_NO_MEMORY;
void *pvPages;
while (iPage-- > 0)
return VINF_SUCCESS;
return rc;
unsigned cFound = 0;
while (pCur)
cFound++;
if (pPrev)
bool fRamExists = false;
fRamExists = true;
if (fRamExists)
while (cPagesLeft-- > 0)
pPage++;
if (fRamExists)
while (cPagesLeft-- > 0)
pPageSrc++;
pPageDst++;
if (cPendingPages)
return VINF_SUCCESS;
while (cPagesLeft-- > 0)
pPageDst++;
return VINF_SUCCESS;
VMMR3DECL(int) PGMR3PhysMMIO2GetHCPhys(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, PRTHCPHYS pHCPhys)
return VINF_SUCCESS;
VMMR3DECL(int) PGMR3PhysMMIO2MapKernel(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
return rc;
Log(("PGMR3PhysRomRegister: pDevIns=%p GCPhys=%RGp(-%RGp) cb=%RGp pvBinary=%p fFlags=%#x pszDesc=%s\n",
AssertReturn(!(fFlags & ~(PGMPHYS_ROM_FLAGS_SHADOWED | PGMPHYS_ROM_FLAGS_PERMANENT_BINARY)), VERR_INVALID_PARAMETER);
bool fRamExists = false;
fRamExists = true;
if (fRamExists)
while (cPagesLeft-- > 0)
pPage++;
if (cExtraBaseCost)
return rc;
return rc;
rc = MMHyperAlloc(pVM, RT_OFFSETOF(PGMROMRANGE, aPages[cPages]), 0, MM_TAG_PGM_PHYS, (void **)&pRomNew);
if (!fRamExists)
rc = MMHyperAlloc(pVM, RT_OFFSETOF(PGMRAMRANGE, aPages[cPages]), sizeof(PGMPAGE), MM_TAG_PGM_PHYS, (void **)&pRamNew);
if (!fRamExists)
void *pvDstPage;
if (pRomPrev)
return VINF_SUCCESS;
if (!fRamExists)
return rc;
static DECLCALLBACK(int) pgmR3PhysRomWriteHandler(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser)
Log5(("pgmR3PhysRomWriteHandler: %d %c %#08RGp %#04zx\n", pRomPage->enmProt, enmAccessType == PGMACCESSTYPE_READ ? 'R' : 'W', GCPhys, cbBuf));
return VINF_PGM_HANDLER_DO_DEFAULT;
return VINF_SUCCESS;
return rc;
void *pvDstPage;
return rc;
rc = pgmPhysFreePage(pVM, pReq, &cPendingPages, &pRom->aPages[iPage].Shadow, pRom->GCPhys + (iPage << PAGE_SHIFT));
if (cPendingPages)
void *pvDstPage;
#ifdef VBOX_STRICT
void *pvDstPage;
return VINF_SUCCESS;
if (!cb)
return VINF_SUCCESS;
bool fFlushTLB = false;
bool fChanges = false;
iPage++)
fChanges = true;
if (fChanges)
if (fFlushTLB)
return rc;
RTAvlU32DoWithAll(&pVM->pgm.s.ChunkR3Map.pTree, true /*fFromLeft*/, pgmR3PhysChunkAgeingRolloverCallback, pVM);
RTAvlU32DoWithAll(&pVM->pgm.s.ChunkR3Map.pTree, true /*fFromLeft*/, pgmR3PhysChunkAgeingCallback, pVM);
typedef struct PGMR3PHYSCHUNKUNMAPCB
if (pChunk)
if (pChunk)
/* next with the same age - this version of the AVL API doesn't enumerate the list, so we have to do it. */
} while (pNode);
if (RTAvllU32DoWithAll(&pVM->pgm.s.ChunkR3Map.pAgeTree, true /*fFromLeft*/, pgmR3PhysChunkUnmapCandidateCallback, pVM))
return INT32_MAX;
int rc;
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
PPGMCHUNKR3MAP pChunk = (PPGMCHUNKR3MAP)MMR3HeapAlloc(pVM, MM_TAG_PGM_CHUNK_MAPPING, sizeof(*pChunk));
PPGMCHUNKR3MAP pChunk = (PPGMCHUNKR3MAP)MMR3UkHeapAlloc(pVM, MM_TAG_PGM_CHUNK_MAPPING, sizeof(*pChunk), NULL);
PPGMCHUNKR3MAP pUnmappedChunk = (PPGMCHUNKR3MAP)RTAvlU32Remove(&pVM->pgm.s.ChunkR3Map.pTree, Req.idChunkUnmap);
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
return rc;
* in EM.cpp and shouldn't be propagated outside TRPM, HWACCM, EM and
AssertMsgReturn(iClear <= RT_ELEMENTS(pVM->pgm.s.aHandyPages), ("%d", iClear), VERR_INTERNAL_ERROR);
void *pvChunk;
void *pv;
AssertLogRelMsgBreak(RT_SUCCESS(rc), ("idPage=%#x HCPhysGCPhys=%RHp rc=%Rrc", pPage->idPage, pPage->HCPhysGCPhys, rc));
iClear++;
Log3(("PGMR3PhysAllocateHandyPages: idPage=%#x HCPhys=%RGp\n", pPage->idPage, pPage->HCPhysGCPhys));
pRam;
return rc;
static int pgmPhysFreePage(PVM pVM, PGMMFREEPAGESREQ pReq, uint32_t *pcPendingPages, PPGMPAGE pPage, RTGCPHYS GCPhys)
return VMSetError(pVM, VERR_PGM_PHYS_NOT_RAM, RT_SRC_POS, "GCPhys=%RGp type=%d", GCPhys, PGM_PAGE_GET_TYPE(pPage));
return VINF_SUCCESS;
return VMSetError(pVM, VERR_PGM_PHYS_INVALID_PAGE_ID, RT_SRC_POS, "GCPhys=%RGp idPage=%#x", GCPhys, pPage);
return VINF_SUCCESS;
*pcPendingPages = 0;
return rc;
/** @todo Handle TLB loads of virtual handlers so ./test.sh can be made to work
if (fWritable)
int rc2;
case PGM_PAGE_STATE_ALLOCATED:
case PGM_PAGE_STATE_ZERO:
case PGM_PAGE_STATE_SHARED:
Log6(("PGMR3PhysTlbGCPhys2Ptr: GCPhys=%RGp rc=%Rrc pPage=%R[pgmpage] *ppv=%p\n", GCPhys, rc, pPage, *ppv));
return rc;