MMAll.cpp revision 1c94c0a63ba68be1a7b2c640e70d7a06464e4fca
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync/* $Id$ */
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync/** @file
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * MM - Memory Monitor(/Manager) - Any Context.
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync */
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync/*
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync *
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * available from http://www.virtualbox.org. This file is free software;
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * you can redistribute it and/or modify it under the terms of the GNU
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * General Public License (GPL) as published by the Free Software
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync *
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * additional information or have any questions.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync */
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync/*******************************************************************************
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync* Header Files *
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync*******************************************************************************/
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync#define LOG_GROUP LOG_GROUP_MM_HYPER
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync#include <VBox/mm.h>
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync#include "MMInternal.h"
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync#include <VBox/vm.h>
f40255ebb8e145bc49daa701edf16f1596cc93cevboxsync#include <VBox/log.h>
f40255ebb8e145bc49daa701edf16f1596cc93cevboxsync#include <iprt/assert.h>
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync/**
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Lookup a host context ring-3 address.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync *
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @returns Pointer to the corresponding lookup record.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @returns NULL on failure.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @param pVM The VM handle.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @param R3Ptr The host context ring-3 address to lookup.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @param poff Where to store the offset into the HMA memory chunk.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync */
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsyncDECLINLINE(PMMLOOKUPHYPER) mmHyperLookupR3(PVM pVM, RTR3PTR R3Ptr, uint32_t *poff)
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync{
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync /** @todo cache last lookup this stuff ain't cheap! */
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync for (;;)
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync {
f05c9726893158b78436cc78907835367d922de9vboxsync switch (pLookup->enmType)
f05c9726893158b78436cc78907835367d922de9vboxsync {
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync case MMLOOKUPHYPERTYPE_LOCKED:
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync {
0a249d1fff442e1f0f29959e2a0da91d024554fcvboxsync const uint32_t off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.Locked.pvHC;
0a249d1fff442e1f0f29959e2a0da91d024554fcvboxsync if (off < pLookup->cb)
f40255ebb8e145bc49daa701edf16f1596cc93cevboxsync {
f40255ebb8e145bc49daa701edf16f1596cc93cevboxsync *poff = off;
f40255ebb8e145bc49daa701edf16f1596cc93cevboxsync return pLookup;
f40255ebb8e145bc49daa701edf16f1596cc93cevboxsync }
f05c9726893158b78436cc78907835367d922de9vboxsync break;
f05c9726893158b78436cc78907835367d922de9vboxsync }
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync case MMLOOKUPHYPERTYPE_HCPHYS:
0a249d1fff442e1f0f29959e2a0da91d024554fcvboxsync {
0a249d1fff442e1f0f29959e2a0da91d024554fcvboxsync const uint32_t off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.HCPhys.pvHC;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync if (off < pLookup->cb)
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync {
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync *poff = off;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync return pLookup;
0a249d1fff442e1f0f29959e2a0da91d024554fcvboxsync }
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync break;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync }
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync case MMLOOKUPHYPERTYPE_GCPHYS: /* (for now we'll not allow these kind of conversions) */
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync case MMLOOKUPHYPERTYPE_MMIO2:
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync case MMLOOKUPHYPERTYPE_DYNAMIC:
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync break;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync default:
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync break;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync }
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync /* next */
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync if (pLookup->offNext == (int32_t)NIL_OFFSET)
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync break;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync pLookup = (PMMLOOKUPHYPER)((char *)pLookup + pLookup->offNext);
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync }
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync return NULL;
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync}
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync/**
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * Lookup a host context ring-0 address.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync *
1ab75e3bb644b29eb1cadd4f6075147012c22757vboxsync * @returns Pointer to the corresponding lookup record.
ebd3c63c626c8039fdb7b95570390699333a7072vboxsync * @returns NULL on failure.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * @param pVM The VM handle.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * @param R0Ptr The host context ring-0 address to lookup.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync * @param poff Where to store the offset into the HMA memory chunk.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync */
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsyncDECLINLINE(PMMLOOKUPHYPER) mmHyperLookupR0(PVM pVM, RTR0PTR R0Ptr, uint32_t *poff)
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync{
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync AssertCompile(sizeof(RTR0PTR) == sizeof(RTR3PTR));
78d5c1f3e0c4c4dce02baa0be07e616bc212f441vboxsync
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync /*
38e7976384c17215607055e2574ae71d386ba7bbvboxsync * Translate Ring-0 VM addresses into Ring-3 VM addresses before feeding it to mmHyperLookupR3.
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync */
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync /** @todo fix this properly; the ring 0 pVM address differs from the R3 one. (#1865) */
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync RTR0UINTPTR offVM = (RTR0UINTPTR)R0Ptr - (RTR0UINTPTR)pVM->pVMR0;
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync RTR3PTR R3Ptr = offVM < sizeof(*pVM)
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync ? (RTR3PTR)((RTR3UINTPTR)pVM->pVMR3 + offVM)
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync : (RTR3PTR)R0Ptr;
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync return mmHyperLookupR3(pVM, R3Ptr, poff);
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync}
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync
be75da5235e6ed26c171a06f0a7d0e718bd7f60bvboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync/**
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Lookup a guest context address.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync *
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @returns Pointer to the corresponding lookup record.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @returns NULL on failure.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @param pVM The VM handle.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @param GCPtr The guest context address to lookup.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @param poff Where to store the offset into the HMA memory chunk.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync */
f55e40eab578fb43357fe057f8088cc16bb1a9e9vboxsyncDECLINLINE(PMMLOOKUPHYPER) mmHyperLookupGC(PVM pVM, RTGCPTR GCPtr, uint32_t *poff)
f55e40eab578fb43357fe057f8088cc16bb1a9e9vboxsync{
f55e40eab578fb43357fe057f8088cc16bb1a9e9vboxsync /** @todo cache last lookup this stuff ain't cheap! */
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync unsigned offGC = (RTGCUINTPTR)GCPtr - (RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync for (;;)
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync {
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync const uint32_t off = offGC - pLookup->off;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync if (off < pLookup->cb)
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync {
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync switch (pLookup->enmType)
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync {
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync case MMLOOKUPHYPERTYPE_LOCKED:
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync case MMLOOKUPHYPERTYPE_HCPHYS:
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync *poff = off;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync return pLookup;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync default:
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync break;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync }
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync return NULL;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync }
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync /* next */
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync if (pLookup->offNext == (int32_t)NIL_OFFSET)
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync break;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync pLookup = (PMMLOOKUPHYPER)((char *)pLookup + pLookup->offNext);
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync }
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync AssertMsgFailed(("GCPtr=%p is not inside the hypervisor memory area!\n", GCPtr));
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync return NULL;
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync}
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync/**
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * Lookup a current context address.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync *
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @returns Pointer to the corresponding lookup record.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @returns NULL on failure.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @param pVM The VM handle.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @param pv The current context address to lookup.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync * @param poff Where to store the offset into the HMA memory chunk.
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync */
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsyncDECLINLINE(PMMLOOKUPHYPER) mmHyperLookupCC(PVM pVM, void *pv, uint32_t *poff)
320484435d67c1fb90dca3e8836d81bf939c8ba2vboxsync{
38e7976384c17215607055e2574ae71d386ba7bbvboxsync#ifdef IN_GC
return mmHyperLookupGC(pVM, pv, poff);
#elif defined(IN_RING0)
return mmHyperLookupR0(pVM, pv, poff);
#else
return mmHyperLookupR3(pVM, pv, poff);
#endif
}
/**
* Calculate the host context ring-3 address of an offset into the HMA memory chunk.
*
* @returns the host context ring-3 address.
* @param pLookup The HMA lookup record.
* @param off The offset into the HMA memory chunk.
*/
DECLINLINE(RTR3PTR) mmHyperLookupCalcR3(PMMLOOKUPHYPER pLookup, uint32_t off)
{
switch (pLookup->enmType)
{
case MMLOOKUPHYPERTYPE_LOCKED:
return (RTR3PTR)((RTR3UINTPTR)pLookup->u.Locked.pvHC + off);
case MMLOOKUPHYPERTYPE_HCPHYS:
return (RTR3PTR)((RTR3UINTPTR)pLookup->u.HCPhys.pvHC + off);
default:
AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
return NIL_RTR3PTR;
}
}
/**
* Calculate the host context ring-0 address of an offset into the HMA memory chunk.
*
* @returns the host context ring-0 address.
* @param pLookup The HMA lookup record.
* @param off The offset into the HMA memory chunk.
*/
DECLINLINE(RTR0PTR) mmHyperLookupCalcR0(PMMLOOKUPHYPER pLookup, uint32_t off)
{
switch (pLookup->enmType)
{
case MMLOOKUPHYPERTYPE_LOCKED:
if (pLookup->u.Locked.pvR0)
return (RTR0PTR)((RTR0UINTPTR)pLookup->u.Locked.pvR0 + off);
return (RTR0PTR)((RTR3UINTPTR)pLookup->u.Locked.pvHC + off);
case MMLOOKUPHYPERTYPE_HCPHYS:
return (RTR0PTR)((RTR3UINTPTR)pLookup->u.HCPhys.pvHC + off);
default:
AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
return NIL_RTR0PTR;
}
}
/**
* Calculate the guest context address of an offset into the HMA memory chunk.
*
* @returns the guest context base address.
* @param pVM The the VM handle.
* @param pLookup The HMA lookup record.
* @param off The offset into the HMA memory chunk.
*/
DECLINLINE(RTGCPTR) mmHyperLookupCalcGC(PVM pVM, PMMLOOKUPHYPER pLookup, uint32_t off)
{
return (RTGCPTR)((RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC + pLookup->off + off);
}
/**
* Calculate the guest context address of an offset into the HMA memory chunk.
*
* @returns the guest context base address.
* @param pVM The the VM handle.
* @param pLookup The HMA lookup record.
* @param off The offset into the HMA memory chunk.
*/
DECLINLINE(void *) mmHyperLookupCalcCC(PVM pVM, PMMLOOKUPHYPER pLookup, uint32_t off)
{
#ifdef IN_GC
return mmHyperLookupCalcGC(pVM, pLookup, off);
#elif defined(IN_RING0)
return mmHyperLookupCalcR0(pLookup, off);
#else
return mmHyperLookupCalcR3(pLookup, off);
#endif
}
/**
* Converts a ring-0 host context address in the Hypervisor memory region to a ring-3 host context address.
*
* @returns ring-3 host context address.
* @param pVM The VM to operate on.
* @param R0Ptr The ring-0 host context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
MMDECL(RTR3PTR) MMHyperR0ToR3(PVM pVM, RTR0PTR R0Ptr)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupR0(pVM, R0Ptr, &off);
if (pLookup)
return mmHyperLookupCalcR3(pLookup, off);
return NIL_RTR3PTR;
}
/**
* Converts a ring-0 host context address in the Hypervisor memory region to a guest context address.
*
* @returns guest context address.
* @param pVM The VM to operate on.
* @param R0Ptr The ring-0 host context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
MMDECL(RTGCPTR) MMHyperR0ToGC(PVM pVM, RTR0PTR R0Ptr)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupR0(pVM, R0Ptr, &off);
if (pLookup)
return mmHyperLookupCalcGC(pVM, pLookup, off);
return NIL_RTGCPTR;
}
#ifndef IN_RING0
/**
* Converts a ring-0 host context address in the Hypervisor memory region to a current context address.
*
* @returns current context address.
* @param pVM The VM to operate on.
* @param R0Ptr The ring-0 host context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
MMDECL(void *) MMHyperR0ToCC(PVM pVM, RTR0PTR R0Ptr)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupR0(pVM, R0Ptr, &off);
if (pLookup)
return mmHyperLookupCalcCC(pVM, pLookup, off);
return NULL;
}
#endif
/**
* Converts a ring-3 host context address in the Hypervisor memory region to a ring-0 host context address.
*
* @returns ring-0 host context address.
* @param pVM The VM to operate on.
* @param R3Ptr The ring-3 host context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
MMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
if (pLookup)
return mmHyperLookupCalcR0(pLookup, off);
AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
return NIL_RTR0PTR;
}
/**
* Converts a ring-3 host context address in the Hypervisor memory region to a guest context address.
*
* @returns guest context address.
* @param pVM The VM to operate on.
* @param R3Ptr The ring-3 host context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
MMDECL(RTGCPTR) MMHyperR3ToGC(PVM pVM, RTR3PTR R3Ptr)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
if (pLookup)
return mmHyperLookupCalcGC(pVM, pLookup, off);
AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
return NIL_RTGCPTR;
}
/**
* Converts a ring-3 host context address in the Hypervisor memory region to a current context address.
*
* @returns current context address.
* @param pVM The VM to operate on.
* @param R3Ptr The ring-3 host context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
#ifndef IN_RING3
MMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
if (pLookup)
return mmHyperLookupCalcCC(pVM, pLookup, off);
return NULL;
}
#endif
/**
* Converts a guest context address in the Hypervisor memory region to a ring-3 context address.
*
* @returns ring-3 host context address.
* @param pVM The VM to operate on.
* @param GCPtr The guest context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
MMDECL(RTR3PTR) MMHyperGCToR3(PVM pVM, RTGCPTR GCPtr)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupGC(pVM, GCPtr, &off);
if (pLookup)
return mmHyperLookupCalcR3(pLookup, off);
return NIL_RTR3PTR;
}
/**
* Converts a guest context address in the Hypervisor memory region to a ring-0 host context address.
*
* @returns ring-0 host context address.
* @param pVM The VM to operate on.
* @param GCPtr The guest context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
MMDECL(RTR0PTR) MMHyperGCToR0(PVM pVM, RTGCPTR GCPtr)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupGC(pVM, GCPtr, &off);
if (pLookup)
return mmHyperLookupCalcR0(pLookup, off);
return NIL_RTR0PTR;
}
/**
* Converts a guest context address in the Hypervisor memory region to a current context address.
*
* @returns current context address.
* @param pVM The VM to operate on.
* @param GCPtr The guest host context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
#ifndef IN_GC
MMDECL(void *) MMHyperGCToCC(PVM pVM, RTGCPTR GCPtr)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupGC(pVM, GCPtr, &off);
if (pLookup)
return mmHyperLookupCalcCC(pVM, pLookup, off);
return NULL;
}
#endif
/**
* Converts a current context address in the Hypervisor memory region to a ring-3 host context address.
*
* @returns ring-3 host context address.
* @param pVM The VM to operate on.
* @param pv The current context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
#ifndef IN_RING3
MMDECL(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupCC(pVM, pv, &off);
if (pLookup)
return mmHyperLookupCalcR3(pLookup, off);
return NIL_RTR3PTR;
}
#endif
/**
* Converts a current context address in the Hypervisor memory region to a ring-0 host context address.
*
* @returns ring-0 host context address.
* @param pVM The VM to operate on.
* @param pv The current context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
#ifndef IN_RING0
MMDECL(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupCC(pVM, pv, &off);
if (pLookup)
return mmHyperLookupCalcR0(pLookup, off);
return NIL_RTR0PTR;
}
#endif
/**
* Converts a current context address in the Hypervisor memory region to a guest context address.
*
* @returns guest context address.
* @param pVM The VM to operate on.
* @param pv The current context address.
* You'll be damned if this is not in the HMA! :-)
* @thread The Emulation Thread.
*/
#ifndef IN_GC
MMDECL(RTGCPTR) MMHyperCCToGC(PVM pVM, void *pv)
{
uint32_t off;
PMMLOOKUPHYPER pLookup = mmHyperLookupCC(pVM, pv, &off);
if (pLookup)
return mmHyperLookupCalcGC(pVM, pLookup, off);
return NIL_RTGCPTR;
}
#endif
/**
* Converts a HC address in the Hypervisor memory region to a GC address.
* The memory must have been allocated with MMGCHyperAlloc() or MMR3HyperAlloc().
*
* @returns GC address.
* @param pVM The VM to operate on.
* @param HCPtr The host context address.
* You'll be damed if this is not in the hypervisor region! :-)
* @deprecated
*/
MMDECL(RTGCPTR) MMHyperHC2GC(PVM pVM, RTHCPTR HCPtr)
{
PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
for (;;)
{
switch (pLookup->enmType)
{
case MMLOOKUPHYPERTYPE_LOCKED:
{
unsigned off = (RTHCUINTPTR)HCPtr - (RTHCUINTPTR)pLookup->u.Locked.pvHC;
if (off < pLookup->cb)
return (RTGCPTR)((RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC + pLookup->off + off);
break;
}
case MMLOOKUPHYPERTYPE_HCPHYS:
{
unsigned off = (RTHCUINTPTR)HCPtr - (RTHCUINTPTR)pLookup->u.HCPhys.pvHC;
if (off < pLookup->cb)
return (RTGCPTR)((RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC + pLookup->off + off);
break;
}
case MMLOOKUPHYPERTYPE_GCPHYS: /* (for now we'll not allow these kind of conversions) */
case MMLOOKUPHYPERTYPE_MMIO2:
case MMLOOKUPHYPERTYPE_DYNAMIC:
break;
default:
AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
break;
}
/* next */
if ((unsigned)pLookup->offNext == NIL_OFFSET)
break;
pLookup = (PMMLOOKUPHYPER)((char *)pLookup + pLookup->offNext);
}
AssertMsgFailed(("HCPtr=%p is not inside the hypervisor memory area!\n", HCPtr));
return (RTGCPTR)0;
}
/**
* Converts a GC address in the Hypervisor memory region to a HC address.
* The memory must have been allocated with MMHyperAlloc().
*
* @returns HC address.
* @param pVM The VM to operate on.
* @param GCPtr The guest context address.
* You'll be damed if this is not in the hypervisor region! :-)
* @deprecated
*/
MMDECL(RTHCPTR) MMHyperGC2HC(PVM pVM, RTGCPTR GCPtr)
{
unsigned offGC = (RTGCUINTPTR)GCPtr - (RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC;
PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
for (;;)
{
unsigned off = offGC - pLookup->off;
if (off < pLookup->cb)
{
switch (pLookup->enmType)
{
case MMLOOKUPHYPERTYPE_LOCKED:
return (RTHCPTR)((RTHCUINTPTR)pLookup->u.Locked.pvHC + off);
case MMLOOKUPHYPERTYPE_HCPHYS:
return (RTHCPTR)((RTHCUINTPTR)pLookup->u.HCPhys.pvHC + off);
default:
break;
}
AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
return (RTHCPTR)0;
}
/* next */
if ((unsigned)pLookup->offNext == NIL_OFFSET)
break;
pLookup = (PMMLOOKUPHYPER)((char *)pLookup + pLookup->offNext);
}
AssertMsgFailed(("GCPtr=%p is not inside the hypervisor memory area!\n", GCPtr));
return (RTHCPTR)0;
}
#ifdef IN_GC
/**
* Converts a current context address in the Hypervisor memory region to a HC address.
* The memory must have been allocated with MMGCHyperAlloc() or MMR3HyperAlloc().
*
* @returns HC address.
* @param pVM The VM to operate on.
* @param Ptr The current context address.
* @deprecated
*/
MMDECL(RTHCPTR) MMHyper2HC(PVM pVM, uintptr_t Ptr)
{
return MMHyperGC2HC(pVM, (RTGCPTR)Ptr);
}
#else /* !IN_GC */
/**
* Converts a current context address in the Hypervisor memory region to a GC address.
* The memory must have been allocated with MMHyperAlloc().
*
* @returns HC address.
* @param pVM The VM to operate on.
* @param Ptr The current context address.
* @thread The Emulation Thread.
* @deprecated
*/
MMDECL(RTGCPTR) MMHyper2GC(PVM pVM, uintptr_t Ptr)
{
return MMHyperHC2GC(pVM, (RTHCPTR)Ptr);
}
#endif /* !IN_GC */