MMAll.cpp revision a398a6b71443e0db13c67141e6815225a6275408
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * MM - Memory Monitor(/Manager) - Any Context.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Copyright (C) 2006-2007 innotek GmbH
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * available from http://www.virtualbox.org. This file is free software;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * General Public License (GPL) as published by the Free Software
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync/*******************************************************************************
a180a41bba1d50822df23fff0099e90b86638b89vboxsync* Header Files *
a180a41bba1d50822df23fff0099e90b86638b89vboxsync*******************************************************************************/
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Lookup a host context ring-3 address.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @returns Pointer to the corresponding lookup record.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @returns NULL on failure.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param pVM The VM handle.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param R3Ptr The host context ring-3 address to lookup.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param poff Where to store the offset into the HMA memory chunk.
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncDECLINLINE(PMMLOOKUPHYPER) mmHyperLookupR3(PVM pVM, RTR3PTR R3Ptr, uint32_t *poff)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /** @todo cache last lookup this stuff ain't cheap! */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync const uint32_t off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.Locked.pvHC;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync const uint32_t off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.HCPhys.pvHC;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case MMLOOKUPHYPERTYPE_GCPHYS: /* (for now we'll not allow these kind of conversions) */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync pLookup = (PMMLOOKUPHYPER)((char *)pLookup + pLookup->offNext);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Lookup a host context ring-0 address.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @returns Pointer to the corresponding lookup record.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @returns NULL on failure.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param pVM The VM handle.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param R0Ptr The host context ring-0 address to lookup.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param poff Where to store the offset into the HMA memory chunk.
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncDECLINLINE(PMMLOOKUPHYPER) mmHyperLookupR0(PVM pVM, RTR0PTR R0Ptr, uint32_t *poff)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Translate Ring-0 VM addresses into Ring-3 VM addresses before feeding it to mmHyperLookupR3.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /** @todo fix this properly; the ring 0 pVM address differs from the R3 one. (#1865) */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync RTR0UINTPTR offVM = (RTR0UINTPTR)R0Ptr - (RTR0UINTPTR)pVM->pVMR0;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Lookup a guest context address.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @returns Pointer to the corresponding lookup record.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @returns NULL on failure.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param pVM The VM handle.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param GCPtr The guest context address to lookup.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param poff Where to store the offset into the HMA memory chunk.
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncDECLINLINE(PMMLOOKUPHYPER) mmHyperLookupGC(PVM pVM, RTGCPTR GCPtr, uint32_t *poff)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /** @todo cache last lookup this stuff ain't cheap! */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync unsigned offGC = (RTGCUINTPTR)GCPtr - (RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync pLookup = (PMMLOOKUPHYPER)((char *)pLookup + pLookup->offNext);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync AssertMsgFailed(("GCPtr=%p is not inside the hypervisor memory area!\n", GCPtr));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Lookup a current context address.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @returns Pointer to the corresponding lookup record.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @returns NULL on failure.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param pVM The VM handle.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * @param pv The current context address to lookup.
#ifdef IN_GC
case MMLOOKUPHYPERTYPE_LOCKED:
case MMLOOKUPHYPERTYPE_HCPHYS:
return NIL_RTR3PTR;
case MMLOOKUPHYPERTYPE_LOCKED:
case MMLOOKUPHYPERTYPE_HCPHYS:
return NIL_RTR0PTR;
#ifdef IN_GC
* Converts a ring-0 host context address in the Hypervisor memory region to a ring-3 host context address.
if (pLookup)
return NIL_RTR3PTR;
* Converts a ring-0 host context address in the Hypervisor memory region to a guest context address.
if (pLookup)
return NIL_RTGCPTR;
#ifndef IN_RING0
* Converts a ring-0 host context address in the Hypervisor memory region to a current context address.
if (pLookup)
return NULL;
* Converts a ring-3 host context address in the Hypervisor memory region to a ring-0 host context address.
if (pLookup)
return NIL_RTR0PTR;
* Converts a ring-3 host context address in the Hypervisor memory region to a guest context address.
if (pLookup)
return NIL_RTGCPTR;
* Converts a ring-3 host context address in the Hypervisor memory region to a current context address.
#ifndef IN_RING3
if (pLookup)
return NULL;
if (pLookup)
return NIL_RTR3PTR;
* Converts a guest context address in the Hypervisor memory region to a ring-0 host context address.
if (pLookup)
return NIL_RTR0PTR;
#ifndef IN_GC
if (pLookup)
return NULL;
* Converts a current context address in the Hypervisor memory region to a ring-3 host context address.
#ifndef IN_RING3
if (pLookup)
return NIL_RTR3PTR;
* Converts a current context address in the Hypervisor memory region to a ring-0 host context address.
#ifndef IN_RING0
if (pLookup)
return NIL_RTR0PTR;
#ifndef IN_GC
if (pLookup)
return NIL_RTGCPTR;
PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
case MMLOOKUPHYPERTYPE_LOCKED:
case MMLOOKUPHYPERTYPE_HCPHYS:
return (RTGCPTR)0;
PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
case MMLOOKUPHYPERTYPE_LOCKED:
case MMLOOKUPHYPERTYPE_HCPHYS:
return (RTHCPTR)0;
return (RTHCPTR)0;
#ifdef IN_GC