PGMAllHandler.cpp revision 577154491a40bad4fc91210cde223e23c61208d1
/* $Id$ */
/** @file
* PGM - Page Manager / Monitor, Access Handlers.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_PGM
#include "PGMInternal.h"
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static int pgmHandlerPhysicalSetRamFlagsAndFlushShadowPTs(PVM pVM, PPGMPHYSHANDLER pCur, PPGMRAMRANGE pRam);
/**
* Register a access handler for a physical range.
*
* @returns VBox status code.
* @retval VINF_SUCCESS when successfully installed.
* @retval VINF_PGM_GCPHYS_ALIASED when the shadow PTs could be updated because
* flagged together with a pool clearing.
* @retval VERR_PGM_HANDLER_PHYSICAL_CONFLICT if the range conflicts with an existing
* one. A debug assertion is raised.
*
* @param pVM VM Handle.
* @param enmType Handler type. Any of the PGMPHYSHANDLERTYPE_PHYSICAL* enums.
* @param GCPhys Start physical address.
* @param GCPhysLast Last physical address. (inclusive)
* @param pfnHandlerR3 The R3 handler.
* @param pvUserR3 User argument to the R3 handler.
* @param pfnHandlerR0 The R0 handler.
* @param pvUserR0 User argument to the R0 handler.
* @param pfnHandlerGC The GC handler.
* @param pvUserGC User argument to the GC handler.
* This must be a GC pointer because it will be relocated!
* @param pszDesc Pointer to description string. This must not be freed.
*/
PGMDECL(int) PGMHandlerPhysicalRegisterEx(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
{
Log(("PGMHandlerPhysicalRegisterEx: enmType=%d GCPhys=%VGp GCPhysLast=%VGp pfnHandlerR3=%VHv pvUserR3=%VHv pfnHandlerR0=%VHv pvUserR0=%VHv pfnHandlerGC=%VGv pvUserGC=%VGv pszDesc=%s\n",
enmType, GCPhys, GCPhysLast, pfnHandlerR3, pvUserR3, pfnHandlerR0, pvUserR0, pfnHandlerGC, pvUserGC, HCSTRING(pszDesc)));
/*
* Validate input.
*/
if (GCPhys >= GCPhysLast)
{
return VERR_INVALID_PARAMETER;
}
switch (enmType)
{
case PGMPHYSHANDLERTYPE_MMIO:
break;
default:
return VERR_INVALID_PARAMETER;
}
{
return VERR_INVALID_PARAMETER;
}
/*
* We require the range to be within registered ram.
* There is no apparent need to support ranges which cover more than one ram range.
*/
if ( !pRam
{
#ifdef IN_RING3
/*
* If this is an MMIO registration, we'll just add a range for it.
*/
if ( enmType == PGMPHYSHANDLERTYPE_MMIO
&& ( !pRam
)
{
int rc = PGMR3PhysRegister(pVM, NULL, GCPhys, cb, MM_RAM_FLAGS_RESERVED | MM_RAM_FLAGS_MMIO, NULL, pszDesc);
if (VBOX_FAILURE(rc))
return rc;
/* search again. */
}
if ( !pRam
#endif /* IN_RING3 */
{
#ifdef IN_RING3
#endif
}
}
/*
* Allocate and initialize the new entry.
*/
if (VBOX_FAILURE(rc))
return rc;
/*
* Try insert into list.
*/
{
if (rc == VINF_PGM_GCPHYS_ALIASED)
{
}
#ifndef IN_RING3
#else
#endif
if (rc != VINF_SUCCESS)
return rc;
}
#if defined(IN_RING3) && defined(VBOX_STRICT)
#endif
AssertMsgFailed(("Conflict! GCPhys=%VGp GCPhysLast=%VGp pszDesc=%s\n", GCPhys, GCPhysLast, pszDesc));
}
/**
* Sets ram range flags and attempts updating shadow PTs.
*
* @returns VBox status code.
* @retval VINF_SUCCESS when shadow PTs was successfully updated.
* @retval VINF_PGM_GCPHYS_ALIASED when the shadow PTs could be updated because
* @param pVM The VM handle.
* @param pCur The physical handler.
* @param pRam The RAM range.
*/
static int pgmHandlerPhysicalSetRamFlagsAndFlushShadowPTs(PVM pVM, PPGMPHYSHANDLER pCur, PPGMRAMRANGE pRam)
{
/*
* Iterate the guest ram pages updating the flags and flushing PT entries
* mapping the page.
*/
bool fFlushTLBs = false;
#if defined(PGMPOOL_WITH_GCPHYS_TRACKING) || defined(PGMPOOL_WITH_CACHE)
int rc = VINF_SUCCESS;
#else
const int rc = VINF_PGM_GCPHYS_ALIASED;
#endif
for (;;)
{
/* Physical chunk in dynamically allocated range not present? */
{
#ifdef IN_RING3
#else
#endif
if (rc2 != VINF_SUCCESS)
return rc2;
}
/* Only do upgrades. */
{
#ifdef PGMPOOL_WITH_GCPHYS_TRACKING
/* This code also makes ASSUMPTIONS about the cRefs and stuff. */
if (u16)
{
else if (u16 != ((MM_RAM_FLAGS_CREFS_PHYSEXT << (MM_RAM_FLAGS_CREFS_SHIFT - MM_RAM_FLAGS_IDX_SHIFT)) | MM_RAM_FLAGS_IDX_OVERFLOWED))
else
fFlushTLBs = true;
}
#elif defined(PGMPOOL_WITH_CACHE)
fFlushTLBs = true;
#endif
}
/* next */
if (--cPages == 0)
break;
i++;
}
{
Log(("pgmHandlerPhysicalSetRamFlagsAndFlushShadowPTs: flushing guest TLBs\n"));
}
else
return rc;
}
/**
* Register a physical page access handler.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param GCPhys Start physical address.
*/
{
/*
* Find the handler.
*/
PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)RTAvlroGCPhysRemove(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhys);
if (pCur)
{
LogFlow(("PGMHandlerPhysicalDeregister: Removing Range %#VGp-%#VGp %s\n",
/*
* Clear the page bits and notify the REM about this change.
*/
return VINF_SUCCESS;
}
return VERR_PGM_HANDLER_NOT_FOUND;
}
/**
* Shared code with modify.
*/
{
/*
* Page align the range.
*
* Since we've reset (recalculated) the physical handler state of all pages
* we can make use of the page states to figure out whether a page should be
* included in the REM notification or not.
*/
{
if (GCPhysStart & PAGE_OFFSET_MASK)
{
if ( pPage
{
if ( GCPhys > GCPhysLast
|| GCPhys < GCPhysStart)
return;
}
else
}
if (GCPhysLast & PAGE_OFFSET_MASK)
{
if ( pPage
{
if ( GCPhys < GCPhysStart
|| GCPhys > GCPhysLast)
return;
GCPhysLast = GCPhys;
}
else
}
}
/*
* Tell REM.
*/
#ifndef IN_RING3
REMNotifyHandlerPhysicalDeregister(pVM, pCur->enmType, GCPhysStart, GCPhysLast - GCPhysStart + 1, !!pCur->pfnHandlerR3, fRestoreAsRAM);
#else
REMR3NotifyHandlerPhysicalDeregister(pVM, pCur->enmType, GCPhysStart, GCPhysLast - GCPhysStart + 1, !!pCur->pfnHandlerR3, fRestoreAsRAM);
#endif
}
/**
* pgmHandlerPhysicalResetRamFlags helper that checks for
* other handlers on edge pages.
*/
DECLINLINE(void) pgmHandlerPhysicalRecalcPageState(PPGM pPGM, RTGCPHYS GCPhys, bool fAbove, PPGMRAMRANGE *ppRamHint)
{
/*
* Look for other handlers.
*/
unsigned uState = PGM_PAGE_HNDL_PHYS_STATE_NONE;
for (;;)
{
PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)RTAvlroGCPhysGetBestFit(&pPGM->CTXSUFF(pTrees)->PhysHandlers, GCPhys, fAbove);
if ( !pCur
break;
/* next? */
break;
GCPhys = GCPhysNext;
}
/*
* Update if we found something that is a higher priority
* state than the current.
*/
if (uState != PGM_PAGE_HNDL_PHYS_STATE_NONE)
{
if ( RT_SUCCESS(rc)
else
}
}
/**
* Resets ram range flags.
*
* @returns VBox status code.
* @retval VINF_SUCCESS when shadow PTs was successfully updated.
* @param pVM The VM handle.
* @param pCur The physical handler.
*
* @remark We don't start messing with the shadow page tables, as we've already got code
* in Trap0e which deals with out of sync handler flags (originally conceived for
* global pages).
*/
{
/*
* Iterate the guest ram pages updating the state.
*/
for (;;)
{
if (RT_SUCCESS(rc))
else
/* next */
if (--cPages == 0)
break;
}
/*
* Check for partial start and end pages.
*/
}
/**
* Modify a physical page access handler.
*
* Modification can only be done to the range it self, not the type or anything else.
*
* @returns VBox status code.
* For all return codes other than VERR_PGM_HANDLER_NOT_FOUND and VINF_SUCCESS the range is deregistered
* and a new registration must be performed!
* @param pVM VM handle.
* @param GCPhysCurrent Current location.
* @param GCPhys New location.
* @param GCPhysLast New last location.
*/
PGMDECL(int) PGMHandlerPhysicalModify(PVM pVM, RTGCPHYS GCPhysCurrent, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast)
{
/*
* Remove it.
*/
int rc;
PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)RTAvlroGCPhysRemove(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhysCurrent);
if (pCur)
{
/*
* Clear the ram flags. (We're gonna move or free it!)
*/
/*
* Validate the new range, modify and reinsert.
*/
if (GCPhysLast >= GCPhys)
{
/*
* We require the range to be within registered ram.
* There is no apparent need to support ranges which cover more than one ram range.
*/
if ( pRam
{
{
/*
* Set ram flags, flush shadow PT entries and finally tell REM about this.
*/
if (rc == VINF_PGM_GCPHYS_ALIASED)
{
}
#ifndef IN_RING3
#else
#endif
Log(("PGMHandlerPhysicalModify: GCPhysCurrent=%VGp -> GCPhys=%VGp GCPhysLast=%VGp\n",
return VINF_SUCCESS;
}
}
else
{
}
}
else
{
}
/*
* Invalid new location, free it.
* We've only gotta notify REM and free the memory.
*/
}
else
{
}
return rc;
}
/**
* Changes the callbacks associated with a physical access handler.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param GCPhys Start physical address.
* @param pfnHandlerR3 The R3 handler.
* @param pvUserR3 User argument to the R3 handler.
* @param pfnHandlerR0 The R0 handler.
* @param pvUserR0 User argument to the R0 handler.
* @param pfnHandlerGC The GC handler.
* @param pvUserGC User argument to the GC handler.
* This must be a GC pointer because it will be relocated!
* @param pszDesc Pointer to description string. This must not be freed.
*/
{
/*
* Get the handler.
*/
int rc = VINF_SUCCESS;
PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)RTAvlroGCPhysGet(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhys);
if (pCur)
{
/*
* Change callbacks.
*/
}
else
{
}
return rc;
}
/**
* Splitts a physical access handler in two.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param GCPhys Start physical address of the handler.
* @param GCPhysSplit The split address.
*/
{
/*
* Do the allocation without owning the lock.
*/
if (VBOX_FAILURE(rc))
return rc;
/*
* Get the handler.
*/
PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)RTAvlroGCPhysGet(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhys);
if (pCur)
{
{
/*
* Create new handler node for the 2nd half.
*/
pNew->cPages = (pNew->Core.KeyLast - (pNew->Core.Key & X86_PTE_PAE_PG_MASK) + PAGE_SIZE) >> PAGE_SHIFT;
pCur->cPages = (pCur->Core.KeyLast - (pCur->Core.Key & X86_PTE_PAE_PG_MASK) + PAGE_SIZE) >> PAGE_SHIFT;
{
LogFlow(("PGMHandlerPhysicalSplit: %VGp-%VGp and %VGp-%VGp\n",
return VINF_SUCCESS;
}
AssertMsgFailed(("whu?\n"));
}
else
{
AssertMsgFailed(("outside range: %VGp-%VGp split %VGp\n", pCur->Core.Key, pCur->Core.KeyLast, GCPhysSplit));
}
}
else
{
}
return rc;
}
/**
* Joins up two adjacent physical access handlers which has the same callbacks.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param GCPhys1 Start physical address of the first handler.
* @param GCPhys2 Start physical address of the second handler.
*/
{
/*
* Get the handlers.
*/
int rc;
PPGMPHYSHANDLER pCur1 = (PPGMPHYSHANDLER)RTAvlroGCPhysGet(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhys1);
if (pCur1)
{
PPGMPHYSHANDLER pCur2 = (PPGMPHYSHANDLER)RTAvlroGCPhysGet(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhys2);
if (pCur2)
{
/*
* Make sure that they are adjacent, and that they've got the same callbacks.
*/
{
{
PPGMPHYSHANDLER pCur3 = (PPGMPHYSHANDLER)RTAvlroGCPhysRemove(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhys2);
{
pCur1->cPages = (pCur1->Core.KeyLast - (pCur1->Core.Key & X86_PTE_PAE_PG_MASK) + PAGE_SIZE) >> PAGE_SHIFT;
LogFlow(("PGMHandlerPhysicalJoin: %VGp-%VGp %VGp-%VGp\n",
return VINF_SUCCESS;
}
}
else
{
AssertMsgFailed(("mismatching handlers\n"));
}
}
else
{
AssertMsgFailed(("not adjacent: %VGp-%VGp %VGp-%VGp\n",
}
}
else
{
}
}
else
{
}
return rc;
}
/**
* Resets any modifications to individual pages in a physical
* page access handler region.
*
* This is used in pair with PGMHandlerPhysicalPageTempOff().
*
* @returns VBox status code.
* @param pVM VM Handle
* @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
*/
{
/*
* Find the handler.
*/
int rc;
PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)RTAvlroGCPhysGet(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhys);
if (pCur)
{
/*
* Validate type.
*/
{
{
/*
* Set the flags and flush shadow PT entries.
*/
if (rc == VINF_PGM_GCPHYS_ALIASED)
{
}
rc = VINF_SUCCESS;
break;
}
/*
* Invalid.
*/
case PGMPHYSHANDLERTYPE_MMIO:
break;
default:
break;
}
}
else
{
}
return rc;
}
/**
* Temporarily turns off the access monitoring of a page within a monitored
*
* Use this when no further \#PFs are required for that page. Be aware that
* a page directory sync might reset the flags, and turn on access monitoring
* for the page.
*
* The caller must do required page table modifications.
*
* @returns VBox status code.
* @param pVM VM Handle
* @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
* This must be a fully page aligned range or we risk messing up other
* handlers installed for the start and end pages.
* @param GCPhysPage Physical address of the page to turn off access monitoring for.
*/
{
/*
* Validate the range.
*/
PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)RTAvlroGCPhysGet(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhys);
if (pCur)
{
{
/*
* Change the page status.
*/
return VINF_SUCCESS;
}
AssertMsgFailed(("The page %#x is outside the range %#x-%#x\n",
return VERR_INVALID_PARAMETER;
}
return VERR_PGM_HANDLER_NOT_FOUND;
}
/**
* Turns access monitoring of a page within a monitored
*
* The caller must do required page table modifications.
*
* @returns VBox status code.
* @param pVM VM Handle
* @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
* This must be a fully page aligned range or we risk messing up other
* handlers installed for the start and end pages.
* @param GCPhysPage Physical address of the page to turn on access monitoring for.
*/
{
/*
* Validate the range.
*/
PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)RTAvlroGCPhysGet(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhys);
if (pCur)
{
{
/*
* Change the page status.
*/
return VINF_SUCCESS;
}
AssertMsgFailed(("The page %#x is outside the range %#x-%#x\n",
return VERR_INVALID_PARAMETER;
}
return VERR_PGM_HANDLER_NOT_FOUND;
}
/**
* Checks if a physical range is handled
*
* @returns boolean
* @param pVM VM Handle
* @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
*/
{
/*
* Find the handler.
*/
PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)RTAvlroGCPhysRangeGet(&pVM->pgm.s.CTXSUFF(pTrees)->PhysHandlers, GCPhys);
if (pCur)
{
{
return true;
}
}
return false;
}
/**
* Search for virtual handler with matching physical address
*
* @returns VBox status code
* @param pVM The VM handle.
* @param GCPhys GC physical address to search for.
* @param ppVirt Where to store the pointer to the virtual handler structure.
* @param piPage Where to store the pointer to the index of the cached physical page.
*/
int pgmHandlerVirtualFindByPhysAddr(PVM pVM, RTGCPHYS GCPhys, PPGMVIRTHANDLER *ppVirt, unsigned *piPage)
{
pCur = (PPGMPHYS2VIRTHANDLER)RTAvlroGCPhysRangeGet(&CTXSUFF(pVM->pgm.s.pTrees)->PhysToVirtHandlers, GCPhys);
if (pCur)
{
/* found a match! */
#endif
LogFlow(("PHYS2VIRT: found match for %VGp -> %VGv *piPage=%#x\n",
return VINF_SUCCESS;
}
return VERR_PGM_HANDLER_NOT_FOUND;
}
/**
* Deal with aliases in phys2virt.
*
* @param pVM The VM handle.
* @param pPhys2Virt The node we failed insert.
*/
{
/*
* First find the node which is conflicting with us.
*/
/** @todo Deal with partial overlapping. (Unlikly situation, so I'm too lazy to do anything about it now.) */
PPGMPHYS2VIRTHANDLER pHead = (PPGMPHYS2VIRTHANDLER)RTAvlroGCPhysGet(&pVM->pgm.s.CTXSUFF(pTrees)->PhysToVirtHandlers, pPhys2Virt->Core.Key);
if (!pHead)
{
/** @todo do something clever here... */
#ifdef IN_RING3
LogRel(("pgmHandlerVirtualInsertAliased: %VGp-%VGp\n", pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast));
#endif
pPhys2Virt->offNextAlias = 0;
return;
}
#endif
/** @todo check if the current head node covers the ground we do. This is highly unlikely
* and I'm too lazy to implement this now as it will require sorting the list and stuff like that. */
/*
* Insert ourselves as the next node.
*/
else
{
PPGMPHYS2VIRTHANDLER pNext = (PPGMPHYS2VIRTHANDLER)((intptr_t)pHead + (pHead->offNextAlias & PGMPHYS2VIRTHANDLER_OFF_MASK));
}
Log(("pgmHandlerVirtualInsertAliased: %VGp-%VGp offNextAlias=%#RX32\n", pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offNextAlias));
}
/**
* Resets one virtual handler range.
*
* @returns 0
* @param pNode Pointer to a PGMVIRTHANDLER.
* @param pvUser The VM handle.
*/
{
/*
* Calc flags.
*/
unsigned fFlags;
{
case PGMVIRTHANDLERTYPE_EIP:
case PGMVIRTHANDLERTYPE_WRITE: fFlags = MM_RAM_FLAGS_VIRTUAL_HANDLER | MM_RAM_FLAGS_VIRTUAL_WRITE; break;
case PGMVIRTHANDLERTYPE_ALL: fFlags = MM_RAM_FLAGS_VIRTUAL_HANDLER | MM_RAM_FLAGS_VIRTUAL_ALL; break;
/* hypervisor handlers need no flags and wouldn't have nowhere to put them in any case. */
return 0;
default:
return 0;
}
/*
* Iterate the pages and apply the flags.
*/
{
{
/* Update the flags. */
/* Need to insert the page in the Phys2Virt lookup tree? */
{
#endif
else
else
AssertReleaseMsg(RTAvlroGCPhysGet(&pVM->pgm.s.CTXSUFF(pTrees)->PhysToVirtHandlers, pPhys2Virt->Core.Key) == &pPhys2Virt->Core,
("%VGp-%VGp offNextAlias=%#RX32\n",
#endif
Log2(("PHYS2VIRT: Insert physical range %VGp-%VGp offNextAlias=%#RX32 %s\n",
pPhys2Virt->Core.Key, pPhys2Virt->Core.KeyLast, pPhys2Virt->offNextAlias, R3STRING(pCur->pszDesc)));
}
}
offPage = 0;
}
return 0;
}
#if defined(VBOX_STRICT) || defined(LOG_ENABLED)
/**
* Worker for pgmHandlerVirtualDumpPhysPages.
*
* @returns 0 (continue enumeration).
* @param pNode The virtual handler node.
* @param pvUser User argument, unused.
*/
static DECLCALLBACK(int) pgmHandlerVirtualDumpPhysPagesCallback(PAVLROGCPHYSNODECORE pNode, void *pvUser)
{
Log(("PHYS2VIRT: Range %VGp-%VGp for virtual handler: %s\n", pCur->Core.Key, pCur->Core.KeyLast, pVirt->pszDesc));
return 0;
}
/**
* Assertion / logging helper for dumping all the
* virtual handlers to the log.
*
* @param pVM Pointer to the shared VM structure.
*/
{
}
#endif /* VBOX_STRICT || LOG_ENABLED */
#ifdef VBOX_STRICT
/**
* State structure used by the PGMAssertHandlerAndFlagsInSync() function
* and its AVL enumerators.
*/
typedef struct PGMAHAFIS
{
/** The VM handle. */
/** Number of errors. */
unsigned cErrors;
/** The flags we've found. */
unsigned fFlagsFound;
/** The flags we're matching up to.
* This is also on the stack as a const, thus only valid during enumeration. */
unsigned fFlags;
/** The current physical address. */
} PGMAHAFIS, *PPGMAHAFIS;
/**
* Verify virtual handler by matching physical address.
*
* @returns 0
* @param pNode Pointer to a PGMVIRTHANDLER.
* @param pvUser Pointer to user parameter.
*/
{
{
{
{
case PGMVIRTHANDLERTYPE_EIP:
case PGMVIRTHANDLERTYPE_WRITE: pState->fFlagsFound |= MM_RAM_FLAGS_VIRTUAL_HANDLER | MM_RAM_FLAGS_VIRTUAL_WRITE; break;
case PGMVIRTHANDLERTYPE_ALL: pState->fFlagsFound |= MM_RAM_FLAGS_VIRTUAL_HANDLER | MM_RAM_FLAGS_VIRTUAL_ALL; break;
/* hypervisor handlers need no flags and wouldn't have nowhere to put them in any case. */
return 0;
}
if ( (pState->fFlags & (MM_RAM_FLAGS_VIRTUAL_HANDLER | MM_RAM_FLAGS_VIRTUAL_WRITE | MM_RAM_FLAGS_VIRTUAL_ALL))
== pState->fFlagsFound)
break;
}
}
return 0;
}
/**
* Verify a virtual handler.
*
* @returns 0
* @param pNode Pointer to a PGMVIRTHANDLER.
* @param pvUser Pointer to user parameter.
*/
{
&& (pVirt->aPhysToVirt[0].Core.Key & PAGE_OFFSET_MASK) != ((RTGCUINTPTR)pVirt->GCPtr & PAGE_OFFSET_MASK))
{
AssertMsgFailed(("virt handler phys out has incorrect key! %VGp %VGv %s\n",
}
/*
* Calc flags.
*/
unsigned fFlags;
{
case PGMVIRTHANDLERTYPE_EIP:
case PGMVIRTHANDLERTYPE_WRITE: fFlags = MM_RAM_FLAGS_VIRTUAL_HANDLER | MM_RAM_FLAGS_VIRTUAL_WRITE; break;
case PGMVIRTHANDLERTYPE_ALL: fFlags = MM_RAM_FLAGS_VIRTUAL_HANDLER | MM_RAM_FLAGS_VIRTUAL_ALL; break;
/* hypervisor handlers need no flags and wouldn't have nowhere to put them in any case. */
return 0;
default:
return 0;
}
/*
* Check pages against flags.
*/
{
if ( rc == VERR_PAGE_NOT_PRESENT
|| rc == VERR_PAGE_TABLE_NOT_PRESENT)
{
{
AssertMsgFailed(("virt handler phys out of sync. %VGp GCPhysNew=~0 iPage=%#x %VGv %s\n",
}
continue;
}
AssertRCReturn(rc, 0);
{
AssertMsgFailed(("virt handler phys out of sync. %VGp GCPhysGst=%VGp iPage=%#x %VGv %s\n",
continue;
}
if (!pPage)
{
AssertMsgFailed(("virt handler getting ram flags. GCPhysGst=%VGp iPage=%#x %VGv %s\n",
continue;
}
{
AssertMsgFailed(("virt handler flags mismatch. HCPhys=%VHp fFlags=%#x GCPhysGst=%VGp iPage=%#x %VGv %s\n",
continue;
}
} /* for pages in virtual mapping. */
return 0;
}
/**
* Asserts that the handlers+guest-page-tables == ramrange-flags and
* that the physical addresses associated with virtual handlers are correct.
*
* @returns Number of mismatches.
* @param pVM The VM handle.
*/
{
/*
* Check the RAM flags against the handlers.
*/
{
{
{
/*
* Physical first - calculate the state based on the handlers
* active on the page, then compare.
*/
{
/* the first */
PPGMPHYSHANDLER pPhys = (PPGMPHYSHANDLER)RTAvlroGCPhysRangeGet(&pPGM->CTXSUFF(pTrees)->PhysHandlers, State.GCPhys);
if (!pPhys)
{
pPhys = (PPGMPHYSHANDLER)RTAvlroGCPhysGetBestFit(&pPGM->CTXSUFF(pTrees)->PhysHandlers, State.GCPhys, true);
if ( pPhys
}
if (pPhys)
{
/* more? */
{
PPGMPHYSHANDLER pPhys2 = (PPGMPHYSHANDLER)RTAvlroGCPhysGetBestFit(&pPGM->CTXSUFF(pTrees)->PhysHandlers,
if ( !pPhys2
break;
}
/* compare.*/
{
AssertMsgFailed(("ram range vs phys handler flags mismatch. GCPhys=%RGp state=%d expected=%d %s\n",
}
#ifdef IN_RING3
/* validate that REM is handling it. */
/* ignore shadowed ROM for the time being. */ /// @todo PAGE FLAGS
&& (pPage->HCPhys & (MM_RAM_FLAGS_ROM | MM_RAM_FLAGS_MMIO2)) != (MM_RAM_FLAGS_ROM | MM_RAM_FLAGS_MMIO2))
{
AssertMsgFailed(("ram range vs phys handler REM mismatch. GCPhys=%RGp state=%d %s\n",
}
#endif
}
else
{
AssertMsgFailed(("ram range vs phys handler mismatch. no handler for GCPhys=%RGp\n", State.GCPhys));
}
}
/* virtual flags. */
{
State.fFlags = pPage->HCPhys & (MM_RAM_FLAGS_VIRTUAL_HANDLER | MM_RAM_FLAGS_VIRTUAL_WRITE | MM_RAM_FLAGS_VIRTUAL_ALL); /// @todo PAGE FLAGS
RTAvlroGCPtrDoWithAll(CTXSUFF(&pVM->pgm.s.pTrees)->VirtHandlers, true, pgmVirtHandlerVerifyOneByPhysAddr, &State);
{
AssertMsgFailed(("ram range vs virt handler flags mismatch. GCPhys=%RGp fFlags=%#x fFlagsFound=%#x\n",
}
}
}
} /* foreach page in ram range. */
} /* foreach ram range. */
/*
* Check that the physical addresses of the virtual handlers matches up.
*/
RTAvlroGCPtrDoWithAll(CTXSUFF(&pVM->pgm.s.pTrees)->VirtHandlers, true, pgmVirtHandlerVerifyOne, &State);
/*
* Do the reverse check for physical handlers.
*/
/** @todo */
}
#endif /* VBOX_STRICT */