/** * Convert a page in the page pool to a HC physical address. * This works for pages allocated by MMR3PageAlloc(), MMR3PageAllocPhys() * and MMR3PageAllocLow(). * * @returns Physical address for the specified page table. * @param pVM The cross context VM structure. * @param pvPage Page which physical address we query. * @thread The Emulation Thread. */ VMMDECL(RTHCPHYS) MMPage2Phys(PVM pVM, void *pvPage) { RTHCPHYS HCPhys = mmPagePoolPtr2Phys(pVM->mm.s.CTX_SUFF(pPagePool), pvPage); if (HCPhys == NIL_RTHCPHYS) { HCPhys = mmPagePoolPtr2Phys(pVM->mm.s.CTX_SUFF(pPagePoolLow), pvPage); if (HCPhys == NIL_RTHCPHYS) { STAM_COUNTER_INC(&pVM->mm.s.CTX_SUFF(pPagePool)->cErrors); AssertMsgFailed(("Invalid pvPage=%p specified\n", pvPage)); } } return HCPhys; }
/** * Allocates a page from the page pool and return its physical address. * * This function may returns pages which has physical addresses any * where. If you require a page to be within the first 4GB of physical * memory, use MMR3PageAllocLow(). * * @returns Pointer to the allocated page page. * @returns NIL_RTHCPHYS on failure. * @param pVM The cross context VM structure. * @thread The Emulation Thread. */ VMMR3DECL(RTHCPHYS) MMR3PageAllocPhys(PVM pVM) { /* Note: unprotected by locks; currently fine as it's used during init or under the PGM lock */ /** @todo optimize this, it's the most common case now. */ void *pv = mmR3PagePoolAlloc(pVM->mm.s.pPagePoolR3); if (pv) return mmPagePoolPtr2Phys(pVM->mm.s.pPagePoolR3, pv); return NIL_RTHCPHYS; }
/** * Gets the HC pointer to the dummy page. * * The dummy page is used as a place holder to prevent potential bugs * from doing really bad things to the system. * * @returns Pointer to the dummy page. * @param pVM The cross context VM structure. * @thread The Emulation Thread. */ VMMR3DECL(void *) MMR3PageDummyHCPtr(PVM pVM) { VM_ASSERT_EMT(pVM); if (!pVM->mm.s.pvDummyPage) { pVM->mm.s.pvDummyPage = mmR3PagePoolAlloc(pVM->mm.s.pPagePoolR3); AssertRelease(pVM->mm.s.pvDummyPage); pVM->mm.s.HCPhysDummyPage = mmPagePoolPtr2Phys(pVM->mm.s.pPagePoolR3, pVM->mm.s.pvDummyPage); AssertRelease(!(pVM->mm.s.HCPhysDummyPage & ~X86_PTE_PAE_PG_MASK)); } return pVM->mm.s.pvDummyPage; }