PGMAllPool.cpp revision 03b30e5529d152055c46b6a3d9798bbdebb98f82
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * PGM Shadow Page Pool.
5654aa8329bbe2838fa5733f28c1a0461c9e6453vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * available from http://www.virtualbox.org. This file is free software;
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * additional information or have any questions.
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync/*******************************************************************************
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync* Header Files *
2508d15edddcae0b79002fae3fe103d6c4836810vboxsync*******************************************************************************/
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync/*******************************************************************************
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsync* Internal Functions *
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsync*******************************************************************************/
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsyncDECLINLINE(unsigned) pgmPoolTrackGetShadowEntrySize(PGMPOOLKIND enmKind);
289060a0c3cb1d509f2cb01fca060796212376f6vboxsyncDECLINLINE(unsigned) pgmPoolTrackGetGuestEntrySize(PGMPOOLKIND enmKind);
289060a0c3cb1d509f2cb01fca060796212376f6vboxsyncstatic void pgmPoolTrackDeref(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsyncstatic void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint);
6420f75ffc86ab6494eb5e95418f0c95e71e8068vboxsyncstatic int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable);
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsyncstatic void pgmPoolMonitorModifiedRemove(PPGMPOOL pPool, PPGMPOOLPAGE pPage);
faf968cea88f2ab4bcc3325b17bc8b095a8e3642vboxsyncDECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Checks if the specified page pool kind is for a 4MB or 2MB guest page.
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync * @returns true if it's the shadow of a 4MB or 2MB guest page, otherwise false.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * @param enmKind The page kind.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsyncDECLINLINE(bool) pgmPoolIsBigPage(PGMPOOLKIND enmKind)
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync return true;
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync return false;
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync * Maps a pool page into the current context.
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync * @returns Pointer to the mapping.
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync * @param pVM The VM handle.
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync * @param pPage The page to map.
43dff6077acb4176145b18bdb862eb73620182d2vboxsync /* general pages. */
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync Assert(pPage->idx < pVM->pgm.s.pPoolGC->cCurPages);
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync int rc = PGMGCDynMapHCPage(pVM, pPage->Core.Key, &pv);
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync /* special pages. */
5654aa8329bbe2838fa5733f28c1a0461c9e6453vboxsync AssertReleaseMsgFailed(("Invalid index %d\n", pPage->idx));
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync#endif /* IN_GC */
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * Determin the size of a write instruction.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * @returns number of bytes written.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * @param pDis The disassembler state.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsyncstatic unsigned pgmPoolDisasWriteSize(PDISCPUSTATE pDis)
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * This is very crude and possibly wrong for some opcodes,
b40179b44fea65b72b2f226f62af1ed7bd3c48fcvboxsync * but since it's not really supposed to be called we can
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * probably live with that.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * Flushes a chain of pages sharing the same access monitor.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * @returns VBox status code suitable for scheduling.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * @param pPool The pool.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * @param pPage A page in the chain.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsyncint pgmPoolMonitorChainFlush(PPGMPOOL pPool, PPGMPOOLPAGE pPage)
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync LogFlow(("pgmPoolMonitorChainFlush: Flush page %VGp type=%d\n", pPage->GCPhys, pPage->enmKind));
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * Find the list head.
30868e719f5a45ec4689ecb2616767cb1fd02c28vboxsync * Iterate the list flushing each shadow page.
c7a00ac75c7941df2afb62e6fd7ffdf1795e6c76vboxsync if (rc2 == VERR_PGM_POOL_CLEARED && rc == VINF_SUCCESS)
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * Wrapper for getting the current context pointer to the entry being modified.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * @returns Pointer to the current context mapping of the entry.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * @param pPool The pool.
2508d15edddcae0b79002fae3fe103d6c4836810vboxsync * @param pvFault The fault virtual address.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * @param GCPhysFault The fault physical address.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * @param cbEntry The entry size.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsyncDECLINLINE(const void *) pgmPoolMonitorGCPtr2CCPtr(PPGMPOOL pPool, RTHCPTR pvFault, RTGCPHYS GCPhysFault, const unsigned cbEntry)
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsyncDECLINLINE(const void *) pgmPoolMonitorGCPtr2CCPtr(PPGMPOOL pPool, RTGCPTR pvFault, RTGCPHYS GCPhysFault, const unsigned cbEntry)
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync return (const void *)((RTGCUINTPTR)pvFault & ~(RTGCUINTPTR)(cbEntry - 1));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync int rc = pgmRamGCPhys2HCPtr(&pPool->pVMHC->pgm.s, GCPhysFault & ~(RTGCPHYS)(cbEntry - 1), &pvRet);
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync return (RTHCPTR)((uintptr_t)pvFault & ~(RTHCUINTPTR)(cbEntry - 1));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * Process shadow entries before they are changed by the guest.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * For PT entries we will clear them. For PD entries, we'll simply check
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * for mapping conflicts and set the SyncCR3 FF if found.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * @param pPool The pool.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * @param pPage The head page.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * @param GCPhysFault The guest physical fault address.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * @param uAddress In R0 and GC this is the guest context fault address (flat).
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * In R3 this is the host context 'fault' address.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * @param pCpu The disassembler state for figuring out the write size.
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync * This need not be specified if the caller knows we won't do cross entry accesses.
2508d15edddcae0b79002fae3fe103d6c4836810vboxsyncvoid pgmPoolMonitorChainChanging(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, RTHCPTR pvAddress, PDISCPUSTATE pCpu)
2508d15edddcae0b79002fae3fe103d6c4836810vboxsyncvoid pgmPoolMonitorChainChanging(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhysFault, RTGCPTR pvAddress, PDISCPUSTATE pCpu)
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync const unsigned off = GCPhysFault & PAGE_OFFSET_MASK;
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync LogFlow(("pgmPoolMonitorChainChanging: %VGv phys=%VGp kind=%d\n", pvAddress, GCPhysFault, pPage->enmKind));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync uShw.pv = PGMPOOL_PAGE_2_PTR(pPool->CTXSUFF(pVM), pPage);
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync PCX86PTE pGstPte = (PCX86PTE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync Log4(("pgmPoolMonitorChainChanging 32_32: deref %VHp GCPhys %VGp\n", uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PG_MASK));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync /* page/2 sized */
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync const unsigned iShw = (off / sizeof(X86PTE)) & (X86_PG_PAE_ENTRIES - 1);
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync PCX86PTE pGstPte = (PCX86PTE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync Log4(("pgmPoolMonitorChainChanging pae_32: deref %VHp GCPhys %VGp\n", uShw.pPT->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PG_MASK));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync PCX86PTEPAE pGstPte = (PCX86PTEPAE)pgmPoolMonitorGCPtr2CCPtr(pPool, pvAddress, GCPhysFault, sizeof(*pGstPte));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync Log4(("pgmPoolMonitorChainChanging pae_32: deref %VHp GCPhys %VGp\n", uShw.pPTPae->a[iShw].u & X86_PTE_PAE_PG_MASK, pGstPte->u & X86_PTE_PAE_PG_MASK));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync /* paranoia / a bit assumptive. */
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync && (off & 7) + pgmPoolDisasWriteSize(pCpu) > sizeof(X86PTEPAE))
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync const unsigned iShw = off / sizeof(X86PTE); // ASSUMING 32-bit guest paging!
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync /* paranoia / a bit assumptive. */
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync const unsigned iShw2 = (off + pgmPoolDisasWriteSize(pCpu) - 1) / sizeof(X86PTE);
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync && !VM_FF_ISSET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3))
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX32 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync# ifdef IN_GC /* TLB load - we're pushing things a bit... */
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPD->a[iShw].u & X86_PDE_PG_MASK, pPage->idx, iShw);
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync unsigned iShw = (off / sizeof(X86PTE)) * 2; // ASSUMING 32-bit guest paging!
e2bd93b4f9c38c9b01eb960ba7bc1fc9c4d38ce8vboxsync if ((uShw.pPDPae->a[iShw].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync /* paranoia / a bit assumptive. */
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync && (uShw.pPDPae->a[iShw2].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync#if 0 /* useful when running PGMAssertCR3(), a bit too troublesome for general use (TLBs). */
7c9a5eca233baf6ede345ace077a00bd0b7af1efvboxsync && !VM_FF_ISSET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3))
7c9a5eca233baf6ede345ace077a00bd0b7af1efvboxsync LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync# ifdef IN_GC /* TLB load - we're pushing things a bit... */
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK, pPage->idx, iShw);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
1986f56777969a25707ab214f8dd070804be666cvboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
1986f56777969a25707ab214f8dd070804be666cvboxsync /* causes trouble when the guest uses a PDE to refer to the whole page table level structure. (invalidate here; faults later on when it tries
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * to change the page table entries
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Note: hardcoded PAE implementation dependency */
1986f56777969a25707ab214f8dd070804be666cvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? PGMPOOL_IDX_PAE_PD : pPage->idx,
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? iShw + (pPage->idx - PGMPOOL_IDX_PAE_PD_0) * X86_PG_PAE_ENTRIES : iShw);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* paranoia / a bit assumptive. */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync && (off & 7) + pgmPoolDisasWriteSize(pCpu) > sizeof(X86PDEPAE))
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync const unsigned iShw2 = (off + pgmPoolDisasWriteSize(pCpu) - 1) / sizeof(X86PDEPAE);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync AssertReturnVoid(iShw2 < ELEMENTS(uShw.pPDPae->a));
0bc7c910e57c78c68e89122e2244cc073d1ef06evboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPae->a[iShw2].u));
7c9a5eca233baf6ede345ace077a00bd0b7af1efvboxsync /* Note: hardcoded PAE implementation dependency */
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? PGMPOOL_IDX_PAE_PD : pPage->idx,
7c9a5eca233baf6ede345ace077a00bd0b7af1efvboxsync (pPage->enmKind == PGMPOOLKIND_PAE_PD_FOR_PAE_PD) ? iShw2 + (pPage->idx - PGMPOOL_IDX_PAE_PD_0) * X86_PG_PAE_ENTRIES : iShw2);
0bc7c910e57c78c68e89122e2244cc073d1ef06evboxsync /* Hopefully this doesn't happen very often:
addc480d0d7650db6323467bbdab6c21836a2928vboxsync * - touching unused parts of the page
0bc7c910e57c78c68e89122e2244cc073d1ef06evboxsync * - messing with the bits of pd pointers without changing the physical address
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync if (iShw < X86_PG_PAE_PDPE_ENTRIES) /* don't use ELEMENTS(uShw.pPDPT->a), because that's for long mode only */
7c9a5eca233baf6ede345ace077a00bd0b7af1efvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
7c9a5eca233baf6ede345ace077a00bd0b7af1efvboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
7c9a5eca233baf6ede345ace077a00bd0b7af1efvboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync /* paranoia / a bit assumptive. */
3c941112ffb137d71a8e457fcc3915f2d464ed2avboxsync && (off & 7) + pgmPoolDisasWriteSize(pCpu) > sizeof(X86PDPE))
3c941112ffb137d71a8e457fcc3915f2d464ed2avboxsync const unsigned iShw2 = (off + pgmPoolDisasWriteSize(pCpu) - 1) / sizeof(X86PDPE);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync Assert(pgmMapAreMappingsEnabled(&pPool->CTXSUFF(pVM)->pgm.s));
6f516ad9911d9037a18778742caa955fe362f8ffvboxsync VM_FF_SET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3);
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync /* Hopefully this doesn't happen very often:
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync * - messing with the bits of pd pointers without changing the physical address
150283991b1a312acbe86c67d3420f6463b38878vboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync if (!VM_FF_ISSET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3))
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPT->a[iShw].u));
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPDPT->a[iShw].u & X86_PDPE_PG_MASK, pPage->idx, iShw);
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync /* paranoia / a bit assumptive. */
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync && (off & 7) + pgmPoolDisasWriteSize(pCpu) > sizeof(X86PDPE))
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync const unsigned iShw2 = (off + pgmPoolDisasWriteSize(pCpu) - 1) / sizeof(X86PDPE);
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync LogFlow(("pgmPoolMonitorChainChanging: pdpt iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPDPT->a[iShw2].u));
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPDPT->a[iShw2].u & X86_PDPE_PG_MASK, pPage->idx, iShw2);
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync /* Hopefully this doesn't happen very often:
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync * - messing with the bits of pd pointers without changing the physical address
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync#ifdef PGMPOOL_INVALIDATE_UPPER_SHADOW_TABLE_ENTRIES
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync if (!VM_FF_ISSET(pPool->CTXSUFF(pVM), VM_FF_PGM_SYNC_CR3))
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPML4->a[iShw].u));
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPML4->a[iShw].u & X86_PML4E_PG_MASK, pPage->idx, iShw);
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync /* paranoia / a bit assumptive. */
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync && (off & 7) + pgmPoolDisasWriteSize(pCpu) > sizeof(X86PDPE))
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync const unsigned iShw2 = (off + pgmPoolDisasWriteSize(pCpu) - 1) / sizeof(X86PML4E);
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync LogFlow(("pgmPoolMonitorChainChanging: pml4 iShw2=%#x: %RX64 -> freeing it!\n", iShw2, uShw.pPML4->a[iShw2].u));
6e4b0f4821f335d37975004f6a7badab8bc48b6fvboxsync pgmPoolFree(pPool->CTXSUFF(pVM), uShw.pPML4->a[iShw2].u & X86_PML4E_PG_MASK, pPage->idx, iShw2);
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync AssertFatalMsgFailed(("enmKind=%d\n", pPage->enmKind));
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync * Checks if a access could be a fork operation in progress.
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync * Meaning, that the guest is setuping up the parent process for Copy-On-Write.
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync * @returns true if it's likly that we're forking, otherwise false.
683371bbf37760161d1b8454ce978acf89bbb04fvboxsync * @param pPool The pool.
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync * @param pCpu The disassembled instruction.
cc723cf07e365cd40b517b9c5da4f113e9469745vboxsync * @param offFault The access offset.
case OP_PUSH:
case OP_PUSHF:
case OP_PUSHA:
case OP_FXSAVE:
static int pgmPoolAccessHandlerFlush(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
#ifdef IN_GC
LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for patch code %04x:%RGv, ignoring.\n",
return rc;
DECLINLINE(int) pgmPoolAccessHandlerSTOSD(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
#ifdef IN_GC
return VINF_SUCCESS;
DECLINLINE(int) pgmPoolAccessHandlerSimple(PVM pVM, PPGMPOOL pPool, PPGMPOOLPAGE pPage, PDISCPUSTATE pCpu,
LogFlow(("pgmPoolAccessHandlerPTWorker: Interpretation failed for patch code %04x:%RGv - opcode=%d\n",
return rc;
DECLEXPORT(int) pgmPoolAccessHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser)
LogFlow(("pgmPoolAccessHandler: pvFault=%VGv pPage=%p:{.idx=%d} GCPhysFault=%VGp\n", pvFault, pPage, pPage->idx, GCPhysFault));
bool fReused = false;
if ( ( pPage->cModifications < 48 /** @todo #define */ /** @todo need to check that it's not mapping EIP. */ /** @todo adjust this! */
STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTXSUFF(pPool)->CTXSUFF(StatMonitor), &pPool->CTXMID(StatMonitor,Handled), a);
return rc;
STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTXSUFF(pPool)->CTXSUFF(StatMonitor), &pPool->CTXMID(StatMonitor,RepStosd), a);
return rc;
pRegFrame->eax, pRegFrame->ecx, pRegFrame->edi, pRegFrame->esi, pRegFrame->rip, Cpu.pCurInstr->opcode, Cpu.prefix));
STAM_PROFILE_STOP_EX(&pVM->pgm.s.CTXSUFF(pPool)->CTXSUFF(StatMonitor), &pPool->CTXMID(StatMonitor,FlushPage), a);
return rc;
#ifdef PGMPOOL_WITH_CACHE
if (i == NIL_PGMPOOL_IDX)
iPrev = i;
* @retval VERR_PGM_POOL_CLEARED if the deregistration of a physical handler will cause a light weight pool flush.
#ifndef IN_GC
return rc;
switch (enmKind1)
switch (enmKind2)
switch (enmKind2)
case PGMPOOLKIND_ROOT_PAE_PD:
case PGMPOOLKIND_ROOT_PDPT:
case PGMPOOLKIND_ROOT_NESTED:
static int pgmPoolCacheAlloc(PPGMPOOL pPool, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
#ifndef IN_GC
Log3(("pgmPoolCacheAlloc: %VGp kind %d iUser=%d iUserTable=%x SLOT=%d\n", GCPhys, enmKind, iUser, iUserTable, i));
if (i != NIL_PGMPOOL_IDX)
return VINF_PGM_CACHED_PAGE;
return rc;
pgmPoolFlushPage(pPool, pPage); /* ASSUMES that VERR_PGM_POOL_CLEARED will be returned by pgmPoolTracInsert. */
} while (i != NIL_PGMPOOL_IDX);
return VERR_FILE_NOT_FOUND;
if (fCanBeCached)
#ifdef PGMPOOL_WITH_MONITORING
#ifdef PGMPOOL_WITH_CACHE
if (i == NIL_PGMPOOL_IDX)
return NULL;
case PGMPOOLKIND_ROOT_PAE_PD:
case PGMPOOLKIND_ROOT_PDPT:
return pPage;
case PGMPOOLKIND_ROOT_NESTED:
} while (i != NIL_PGMPOOL_IDX);
return NULL;
* @retval VERR_PGM_POOL_CLEARED if the registration of the physical handler will cause a light weight pool flush.
case PGMPOOLKIND_ROOT_PDPT:
case PGMPOOLKIND_ROOT_NESTED:
return VINF_SUCCESS;
case PGMPOOLKIND_ROOT_PAE_PD:
#ifdef PGMPOOL_WITH_MIXED_PT_CR3
int rc;
if (pPageHead)
return rc;
* @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
case PGMPOOLKIND_ROOT_PDPT:
case PGMPOOLKIND_ROOT_NESTED:
return VINF_SUCCESS;
case PGMPOOLKIND_ROOT_PAE_PD:
#ifdef PGMPOOL_WITH_MIXED_PT_CR3
int rc;
return rc;
#ifdef PGMPOOL_WITH_MIXED_PT_CR3
LogFlow(("pgmPoolMonitorMonitorCR3: idxRoot=%d pPage=%p:{.GCPhys=%VGp, .fMonitored=%d} GCPhysCR3=%VGp\n",
return VINF_SUCCESS;
return rc;
return VINF_SUCCESS;
return rc;
#ifdef VBOX_WITH_STATISTICS
Log3(("pgmPoolMonitorModifiedRemove: idx=%d cModifications=%d\n", pPage->idx, pPage->cModifications));
#ifdef PGMPOOL_WITH_USER_TRACKING
#ifdef PGMPOOL_WITH_USER_TRACKING
if (!--cLeft)
#ifndef DEBUG_michael
AssertMsg(cModifiedPages == pPool->cModifiedPages, ("%d != %d\n", cModifiedPages, pPool->cModifiedPages));
#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
pRam;
while (iPage-- > 0)
for (unsigned i = 0; i < cMaxPhysExts; i++)
#ifdef PGMPOOL_WITH_USER_TRACKING
#ifdef PGMPOOL_WITH_CACHE
return rc;
return VERR_PGM_POOL_FLUSHED;
* @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
DECLINLINE(int) pgmPoolTrackInsert(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTGCPHYS GCPhys, uint16_t iUser, uint32_t iUserTable)
if (i == NIL_PGMPOOL_USER_INDEX)
return rc;
# ifdef PGMPOOL_WITH_MIXED_PT_CR3
const bool fCanBeMonitored = true;
|| (GCPhys & X86_PTE_PAE_PG_MASK) != (pPool->CTXSUFF(pVM)->pgm.s.GCPhysGstCR3Monitored & X86_PTE_PAE_PG_MASK)
# ifdef PGMPOOL_WITH_CACHE
if (fCanBeMonitored)
# ifdef PGMPOOL_WITH_MONITORING
# ifndef PGMPOOL_WITH_CACHE
return rc;
static int pgmPoolTrackAddUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
# ifdef VBOX_STRICT
AssertMsg(paUsers[i].iUser != iUser || paUsers[i].iUserTable != iUserTable, ("%x %x vs new %x %x\n", paUsers[i].iUser, paUsers[i].iUserTable, iUser, iUserTable));
} while (i != NIL_PGMPOOL_USER_INDEX);
if (i == NIL_PGMPOOL_USER_INDEX)
return rc;
# ifdef PGMPOOL_WITH_CACHE
return VINF_SUCCESS;
static void pgmPoolTrackFreeUser(PPGMPOOL pPool, PPGMPOOLPAGE pPage, uint16_t iUser, uint32_t iUserTable)
if ( i != NIL_PGMPOOL_USER_INDEX
while (i != NIL_PGMPOOL_USER_INDEX)
iPrev = i;
switch (enmKind)
case PGMPOOLKIND_ROOT_PAE_PD:
case PGMPOOLKIND_ROOT_PDPT:
case PGMPOOLKIND_ROOT_NESTED:
switch (enmKind)
case PGMPOOLKIND_ROOT_PAE_PD:
case PGMPOOLKIND_ROOT_PDPT:
case PGMPOOLKIND_ROOT_NESTED:
AssertFailed();
#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
static void pgmPoolTrackFlushGCPhysPTInt(PVM pVM, PCPGMPAGE pPhysPage, uint16_t iShw, uint16_t cRefs)
LogFlow(("pgmPoolTrackFlushGCPhysPT: HCPhys=%RHp iShw=%d cRefs=%d\n", pPhysPage->HCPhys, iShw, cRefs));
pPT->a[i].u = 0;
cRefs--;
if (!cRefs)
RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
pPT->a[i].u = 0;
AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
pPT->a[i].u = 0;
cRefs--;
if (!cRefs)
RTLogPrintf("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent);
pPT->a[i].u = 0;
AssertFatalMsgFailed(("cRefs=%d iFirstPresent=%d cPresent=%d\n", cRefs, pPage->iFirstPresent, pPage->cPresent));
LogFlow(("pgmPoolTrackFlushGCPhysPT: HCPhys=%RHp iShw=%d cRefs=%d\n", pPhysPage->HCPhys, iShw, cRefs));
return VINF_PGM_GCPHYS_ALIASED;
pPT->a[i].u = 0;
if (!--cPresent)
pPT->a[i].u = 0;
if (!--cPresent)
if (!--cLeft)
return VINF_SUCCESS;
#ifdef VBOX_STRICT
case PGMPOOLKIND_ROOT_PAE_PD:
case PGMPOOLKIND_ROOT_PDPT:
case PGMPOOLKIND_ROOT_NESTED:
case PGMPOOLKIND_ROOT_PAE_PD:
case PGMPOOLKIND_ROOT_PDPT:
case PGMPOOLKIND_ROOT_NESTED:
AssertFatalMsgFailed(("enmKind=%d iUser=%#x iUserTable=%#x\n", pUserPage->enmKind, pUser->iUser, pUser->iUserTable));
while (i != NIL_PGMPOOL_USER_INDEX)
i = iNext;
#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
return NULL;
return pPhysExt;
return iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
return iPhysExtStart | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
if (!--cMax)
return MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
if (!pNew)
return MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
LogFlow(("pgmPoolTrackPhysExtAddref: added new extent %d:{%d}->%d\n", iPhysExt, iShwPT, iPhysExtStart));
return iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
if (pPhysExt)
LogFlow(("pgmPoolTrackPhysExtAddref: new extent: %d:{%d, %d}\n", iPhysExt, u16 & MM_RAM_FLAGS_IDX_MASK, iShwPT));
u16 = iPhysExt | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
u16 = MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT));
else if (u16 != (MM_RAM_FLAGS_IDX_OVERFLOWED | (MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT))))
return u16;
AssertFatalMsg(cRefs == MM_RAM_FLAGS_CREFS_PHYSEXT, ("cRefs=%d HCPhys=%RHp pPage=%p:{.idx=%d}\n", cRefs, pPhysPage->HCPhys, pPage, pPage->idx));
LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d lonely\n", pPhysPage->HCPhys, pPage->idx));
LogFlow(("pgmPoolTrackPhysExtDerefGCPhys: HCPhys=%RX64 idx=%d head\n", pPhysPage->HCPhys, pPage->idx));
AssertFatalMsgFailed(("not-found! cRefs=%d HCPhys=%RHp pPage=%p:{.idx=%d}\n", cRefs, pPhysPage->HCPhys, pPage, pPage->idx));
static void pgmPoolTracDerefGCPhys(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhys)
while (pRam)
static void pgmPoolTracDerefGCPhysHint(PPGMPOOL pPool, PPGMPOOLPAGE pPage, RTHCPHYS HCPhys, RTGCPHYS GCPhysHint)
while (pRam)
while (pRam)
while (iPage-- > 0)
DECLINLINE(void) pgmPoolTrackDerefPT32Bit32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PT pShwPT, PCX86PT pGstPT)
pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK);
DECLINLINE(void) pgmPoolTrackDerefPTPae32Bit(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PT pGstPT)
pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PG_MASK);
DECLINLINE(void) pgmPoolTrackDerefPTPaePae(PPGMPOOL pPool, PPGMPOOLPAGE pPage, PX86PTPAE pShwPT, PCX86PTPAE pGstPT)
pgmPoolTracDerefGCPhysHint(pPool, pPage, pShwPT->a[i].u & X86_PTE_PAE_PG_MASK, pGstPT->a[i].u & X86_PTE_PAE_PG_MASK);
PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPD->a[i].u & X86_PDE_PAE_PG_MASK);
if (pSubPage)
PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPDPT->a[i].u & X86_PDPE_PG_MASK);
if (pSubPage)
PPGMPOOLPAGE pSubPage = (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, pShwPML4->a[i].u & X86_PDPE_PG_MASK);
if (pSubPage)
#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
void *pvGst;
void *pvGst;
void *pvGst;
case PGMPOOLKIND_ROOT_PAE_PD:
case PGMPOOLKIND_ROOT_PDPT:
case PGMPOOLKIND_ROOT_NESTED:
#ifdef IN_RING3
#ifdef PGMPOOL_WITH_MONITORING
#ifdef PGMPOOL_WITH_USER_TRACKING
#ifdef PGMPOOL_WITH_CACHE
#ifdef PGMPOOL_WITH_USER_TRACKING
for (unsigned i = 0; i < cMaxUsers; i++)
#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
pRam;
while (iPage-- > 0)
for (unsigned i = 0; i < cMaxPhysExts; i++)
#ifdef PGMPOOL_WITH_MONITORING
#ifdef PGMPOOL_WITH_CACHE
#ifdef PGMPOOL_WITH_MONITORING
# ifdef PGMPOOL_WITH_CACHE
#ifdef PGMPOOL_WITH_USER_TRACKING
#ifdef PGMPOOL_WITH_CACHE
* @retval VERR_PGM_POOL_CLEARED if the deregistration of the physical handler will cause a light weight pool flush.
Log(("pgmPoolFlushPage: special root page, rejected. enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
return VINF_SUCCESS;
Log(("pgmPoolFlushPage: current active shadow CR3, rejected. enmKind=%d idx=%d\n", pPage->enmKind, pPage->idx));
return VINF_SUCCESS;
#ifdef PGMPOOL_WITH_USER_TRACKING
#ifdef PGMPOOL_WITH_CACHE
#ifdef PGMPOOL_WITH_MONITORING
return rc;
#ifdef PGMPOOL_WITH_USER_TRACKING
#ifdef PGMPOOL_WITH_CACHE
#ifdef IN_RING3
return rc;
return VINF_SUCCESS;
#ifdef PGMPOOL_WITH_CACHE
return VERR_PGM_POOL_FLUSHED;
int pgmPoolAlloc(PVM pVM, RTGCPHYS GCPhys, PGMPOOLKIND enmKind, uint16_t iUser, uint32_t iUserTable, PPPGMPOOLPAGE ppPage)
LogFlow(("pgmPoolAlloc: GCPhys=%VGp enmKind=%d iUser=%#x iUserTable=%#x\n", GCPhys, enmKind, iUser, iUserTable));
#ifdef PGMPOOL_WITH_CACHE
LogFlow(("pgmPoolAlloc: cached returns %Vrc *ppPage=%p:{.Key=%VHp, .idx=%d}\n", rc2, *ppPage, (*ppPage)->Core.Key, (*ppPage)->idx));
return rc2;
return rc;
pPool->cUsedPages++; /* physical handler registration / pgmPoolTrackFlushGCPhysPTsSlow requirement. */
#ifdef PGMPOOL_WITH_MONITORING
#ifdef PGMPOOL_WITH_USER_TRACKING
return rc3;
#ifdef VBOX_WITH_STATISTICS
LogFlow(("pgmPoolAlloc: returns %Vrc *ppPage=%p:{.Key=%VHp, .idx=%d, .fCached=%RTbool, .fMonitored=%RTbool}\n",
return rc;
return pPage;