Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

MMInternal.h

Go to the documentation of this file.
/* $Id: MMInternal.h 4388 2007-08-27 14:26:05Z vboxsync $ */
/** @file
 * MM - Internal header file.
 */

/*
 * 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;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License 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.
 */

#ifndef ___MMInternal_h
#define ___MMInternal_h

#include <VBox/cdefs.h>
#include <VBox/types.h>
#include <VBox/sup.h>
#include <VBox/stam.h>
#include <iprt/avl.h>
#include <iprt/critsect.h>


#if !defined(IN_MM_R3) && !defined(IN_MM_R0) && !defined(IN_MM_GC)
# error "Not in MM! This is an internal header!"
#endif


/** @defgroup grp_mm_int   Internals
 * @internal
 * @ingroup grp_mm
 * @{
 */

/** @name VM Ring-3 Heap Internals
 * @{
 */

/** @def MMR3HEAP_WITH_STATISTICS
 * Enable MMR3Heap statistics.
 */
#if !defined(MMR3HEAP_WITH_STATISTICS) && defined(VBOX_WITH_STATISTICS)
# define MMR3HEAP_WITH_STATISTICS
#endif

/** @def MMR3HEAP_SIZE_ALIGNMENT
 * The allocation size alignment of the MMR3Heap.
 */
00054 #define MMR3HEAP_SIZE_ALIGNMENT     16

/**
 * Heap statistics record.
 * There is one global and one per allocation tag.
 */
00060 typedef struct MMHEAPSTAT
{
    /** Core avl node, key is the tag. */
00063     AVLULNODECORE   Core;
    /** Pointer to the heap the memory belongs to. */
00065     struct MMHEAP  *pHeap;
#ifdef MMR3HEAP_WITH_STATISTICS
    /** Number of allocation. */
    uint64_t        cAllocations;
    /** Number of reallocations. */
    uint64_t        cReallocations;
    /** Number of frees. */
    uint64_t        cFrees;
    /** Failures. */
    uint64_t        cFailures;
    /** Number of bytes allocated (sum). */
    uint64_t        cbAllocated;
    /** Number of bytes freed. */
    uint64_t        cbFreed;
    /** Number of bytes currently allocated. */
    size_t          cbCurAllocated;
#endif
} MMHEAPSTAT;
/** Pointer to heap statistics record. */
00084 typedef MMHEAPSTAT *PMMHEAPSTAT;



/**
 * Additional heap block header for relating allocations to the VM.
 */
00091 typedef struct MMHEAPHDR
{
    /** Pointer to the next record. */
00094     struct MMHEAPHDR   *pNext;
    /** Pointer to the previous record. */
00096     struct MMHEAPHDR   *pPrev;
    /** Pointer to the heap statistics record.
     * (Where the a PVM can be found.) */
00099     PMMHEAPSTAT         pStat;
    /** Size of the allocation (including this header). */
00101     size_t              cbSize;
} MMHEAPHDR;
/** Pointer to MM heap header. */
00104 typedef MMHEAPHDR *PMMHEAPHDR;


/** MM Heap structure. */
00108 typedef struct MMHEAP
{
    /** Lock protecting the heap. */
00111     RTCRITSECT          Lock;
    /** Heap block list head. */
00113     PMMHEAPHDR          pHead;
    /** Heap block list tail. */
00115     PMMHEAPHDR          pTail;
    /** Heap per tag statistics tree. */
00117     PAVLULNODECORE      pStatTree;
    /** The VM handle. */
00119     PVM                 pVM;
    /** Heap global statistics. */
00121     MMHEAPSTAT          Stat;
} MMHEAP;
/** Pointer to MM Heap structure. */
00124 typedef MMHEAP *PMMHEAP;

/** @} */



/** @name Hypervisor Heap Internals
 * @{
 */

/** @def MMHYPER_HEAP_FREE_DELAY
 * If defined, it indicates the number of frees that should be delayed.
 */
#if defined(__DOXYGEN__)
# define MMHYPER_HEAP_FREE_DELAY   64
#endif

/** @def MMHYPER_HEAP_FREE_POISON
 * If defined, it indicates that freed memory should be poisoned
 * with the value it has.
 */
#if defined(VBOX_STRICT) || defined(__DOXYGEN__)
# define MMHYPER_HEAP_FREE_POISON   0xCB
#endif

/**
 * Hypervisor heap statistics record.
 * There is one global and one per allocation tag.
 */
00153 typedef struct MMHYPERSTAT
{
    /** Core avl node, key is the tag.
     * @todo The type is wrong! Get your lazy a$$ over and create that offsetted uint32_t version we need here!  */
00157     AVLOGCPHYSNODECORE Core;
    /** Aligning the 64-bit fields on a 64-bit line. */
00159     uint32_t        u32Padding0;
    /** Indicator for whether these statistics are registered with STAM or not. */
00161     bool            fRegistered;
    /** Number of allocation. */
00163     uint64_t        cAllocations;
    /** Number of frees. */
00165     uint64_t        cFrees;
    /** Failures. */
00167     uint64_t        cFailures;
    /** Number of bytes allocated (sum). */
00169     uint64_t        cbAllocated;
    /** Number of bytes freed (sum). */
00171     uint64_t        cbFreed;
    /** Number of bytes currently allocated. */
00173     uint32_t        cbCurAllocated;
    /** Max number of bytes allocated. */
00175     uint32_t        cbMaxAllocated;
} MMHYPERSTAT;
/** Pointer to hypervisor heap statistics record. */
00178 typedef MMHYPERSTAT *PMMHYPERSTAT;

/**
 * Hypervisor heap chunk.
 */
00183 typedef struct MMHYPERCHUNK
{
    /** Previous block in the list of all blocks.
     * This is relative to the start of the heap. */
00187     uint32_t                offNext;
    /** Offset to the previous block relative to this one. */
00189     int32_t                 offPrev;
    /** The statistics record this allocation belongs to (self relative). */
00191     int32_t                 offStat;
    /** Offset to the heap block (self relative). */
00193     int32_t                 offHeap;
} MMHYPERCHUNK;
/** Pointer to a hypervisor heap chunk. */
00196 typedef MMHYPERCHUNK *PMMHYPERCHUNK;


/**
 * Hypervisor heap chunk.
 */
00202 typedef struct MMHYPERCHUNKFREE
{
    /** Main list. */
00205     MMHYPERCHUNK            core;
    /** Offset of the next chunk in the list of free nodes. */
00207     uint32_t                offNext;
    /** Offset of the previous chunk in the list of free nodes. */
00209     int32_t                 offPrev;
    /** Size of the block. */
00211     uint32_t                cb;
} MMHYPERCHUNKFREE;
/** Pointer to a free hypervisor heap chunk. */
00214 typedef MMHYPERCHUNKFREE *PMMHYPERCHUNKFREE;


/**
 * The hypervisor heap.
 */
00220 typedef struct MMHYPERHEAP
{
    /** The typical magic (MMHYPERHEAP_MAGIC). */
00223     uint32_t                u32Magic;
    /** The heap size. (This structure is not included!) */
00225     uint32_t                cbHeap;
    /** The HC Ring-3 address of the VM. */
    HCPTRTYPE(PVM)          pVMHC;
    /** The HC Ring-3 address of the heap. */
    HCPTRTYPE(uint8_t *)    pbHeapHC;
    /** The GC address of the heap. */
    GCPTRTYPE(uint8_t *)    pbHeapGC;
    /** The GC address of the VM. */
    GCPTRTYPE(PVM)          pVMGC;
    /** The amount of free memory in the heap. */
00235     uint32_t                cbFree;
    /** Offset of the first free chunk in the heap.
     * The offset is relative to the start of the heap. */
00238     uint32_t                offFreeHead;
    /** Offset of the last free chunk in the heap.
     * The offset is relative to the start of the heap. */
00241     uint32_t                offFreeTail;
    /** Offset of the first page aligned block in the heap.
     * The offset is equal to cbHeap initially. */
00244     uint32_t                offPageAligned;
    /** Tree of hypervisor heap statistics. */
00246     AVLOGCPHYSTREE          HyperHeapStatTree;
#ifdef MMHYPER_HEAP_FREE_DELAY
    /** Where to insert the next free. */
    uint32_t                iDelayedFree;
    /** Array of delayed frees. Circular. Offsets relative to this structure. */
    struct
    {
        /** The free caller address. */
        RTUINTPTR           uCaller;
        /** The offset of the freed chunk. */
        uint32_t            offChunk;
    }                   aDelayedFrees[MMHYPER_HEAP_FREE_DELAY];
#else
    /** Padding the structure to a 64-bit aligned size. */
00260     uint32_t            u32Padding0;
#endif
} MMHYPERHEAP;
/** Pointer to the hypervisor heap. */
00264 typedef MMHYPERHEAP *PMMHYPERHEAP;

/** Magic value for MMHYPERHEAP. (C. S. Lewis) */
00267 #define MMHYPERHEAP_MAGIC   0x18981129


/**
 * Hypervisor heap minimum alignment (16 bytes).
 */
00273 #define MMHYPER_HEAP_ALIGN_MIN          16

/**
 * The aligned size of the the MMHYPERHEAP structure.
 */
00278 #define MMYPERHEAP_HDR_SIZE             RT_ALIGN_Z(sizeof(MMHYPERHEAP), MMHYPER_HEAP_ALIGN_MIN * 4)

/** @name Hypervisor heap chunk flags.
 * The flags are put in the first bits of the MMHYPERCHUNK::offPrev member.
 * These bits aren't used anyway because of the chunk minimal alignment (16 bytes).
 * @{ */
/** The chunk is free. (The code ASSUMES this is 0!) */
00285 #define MMHYPERCHUNK_FLAGS_FREE         0x0
/** The chunk is in use. */
00287 #define MMHYPERCHUNK_FLAGS_USED         0x1
/** The type mask. */
00289 #define MMHYPERCHUNK_FLAGS_TYPE_MASK    0x1
/** The flag mask */
00291 #define MMHYPERCHUNK_FLAGS_MASK         0x1

/** Checks if the chunk is free. */
00294 #define MMHYPERCHUNK_ISFREE(pChunk)                 ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_FREE )
/** Checks if the chunk is used. */
00296 #define MMHYPERCHUNK_ISUSED(pChunk)                 ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_USED )
/** Toggles FREE/USED flag of a chunk. */
00298 #define MMHYPERCHUNK_SET_TYPE(pChunk, type)         do { (pChunk)->offPrev = ((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_TYPE_MASK) | ((type) & MMHYPERCHUNK_FLAGS_TYPE_MASK); } while (0)

/** Gets the prev offset without the flags. */
00301 #define MMHYPERCHUNK_GET_OFFPREV(pChunk)            ((int32_t)((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_MASK))
/** Sets the prev offset without changing the flags. */
00303 #define MMHYPERCHUNK_SET_OFFPREV(pChunk, off)       do { (pChunk)->offPrev = (off) | ((pChunk)->offPrev & MMHYPERCHUNK_FLAGS_MASK); } while (0)
#if 0
/** Clears one or more flags. */
#define MMHYPERCHUNK_FLAGS_OP_CLEAR(pChunk, fFlags) do { ((pChunk)->offPrev) &= ~((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
/** Sets one or more flags. */
#define MMHYPERCHUNK_FLAGS_OP_SET(pChunk, fFlags)   do { ((pChunk)->offPrev) |=  ((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
/** Checks if one is set. */
#define MMHYPERCHUNK_FLAGS_OP_ISSET(pChunk, fFlag)  (!!(((pChunk)->offPrev) & ((fFlag) & MMHYPERCHUNK_FLAGS_MASK)))
#endif
/** @} */

/** @} */


/** @name Page Pool Internals
 * @{
 */

/**
 * Page sub pool
 *
 * About the allocation of this structrue. To keep the number of heap blocks,
 * the number of heap calls, and fragmentation low we allocate all the data
 * related to a MMPAGESUBPOOL node in one chunk. That means that after the
 * bitmap (which is of variable size) comes the SUPPAGE records and then
 * follows the lookup tree nodes.
 */
00330 typedef struct MMPAGESUBPOOL
{
    /** Pointer to next sub pool. */
00333     struct MMPAGESUBPOOL   *pNext;
    /** Pointer to next sub pool in the free chain.
     * This is NULL if we're not in the free chain or at the end of it. */
00336     struct MMPAGESUBPOOL   *pNextFree;
    /** Pointer to array of lock ranges.
     * This is allocated together with the MMPAGESUBPOOL and thus needs no freeing.
     * It follows immediately after the bitmap.
     * The reserved field is a pointer to this structure.
     */
00342     PSUPPAGE                paPhysPages;
    /** Pointer to the first page. */
00344     void                   *pvPages;
    /** Size of the subpool. */
00346     unsigned                cPages;
    /** Number of free pages. */
00348     unsigned                cPagesFree;
    /** The allocation bitmap.
     * This may extend beyond the end of the defined array size.
     */
00352     unsigned                auBitmap[1];
    /* ... SUPPAGE          aRanges[1]; */
} MMPAGESUBPOOL;
/** Pointer to page sub pool. */
00356 typedef MMPAGESUBPOOL *PMMPAGESUBPOOL;

/**
 * Page pool.
 */
00361 typedef struct MMPAGEPOOL
{
    /** List of subpools. */
00364     PMMPAGESUBPOOL      pHead;
    /** Head of subpools with free pages. */
00366     PMMPAGESUBPOOL      pHeadFree;
    /** AVLPV tree for looking up HC virtual addresses.
     * The tree contains MMLOOKUPVIRTPP records.
     */
00370     PAVLPVNODECORE      pLookupVirt;
    /** Tree for looking up HC physical addresses.
     * The tree contains MMLOOKUPPHYSHC records.
     */
00374     AVLHCPHYSTREE       pLookupPhys;
    /** Pointer to the VM this pool belongs. */
00376     PVM                 pVM;
    /** Flag indicating the allocation method.
     * Set: SUPLowAlloc().
     * Clear: SUPPageAlloc() + SUPPageLock(). */
00380     bool                fLow;
    /** Number of subpools. */
00382     uint32_t            cSubPools;
    /** Number of pages in pool. */
00384     uint32_t            cPages;
#ifdef VBOX_WITH_STATISTICS
    /** Number of free pages in pool. */
    uint32_t            cFreePages;
    /** Number of alloc calls. */
    STAMCOUNTER         cAllocCalls;
    /** Number of free calls. */
    STAMCOUNTER         cFreeCalls;
    /** Number of to phys conversions. */
    STAMCOUNTER         cToPhysCalls;
    /** Number of to virtual conversions. */
    STAMCOUNTER         cToVirtCalls;
    /** Number of real errors. */
    STAMCOUNTER         cErrors;
#endif
} MMPAGEPOOL;
/** Pointer to page pool. */
00401 typedef MMPAGEPOOL     *PMMPAGEPOOL;

/**
 * Lookup record for HC virtual memory in the page pool.
 */
00406 typedef struct MMPPLOOKUPHCPTR
{
    /** The key is virtual address. */
00409     AVLPVNODECORE   Core;
    /** Pointer to subpool if lookup record for a pool. */
00411     struct MMPAGESUBPOOL   *pSubPool;
} MMPPLOOKUPHCPTR;
/** Pointer to virtual memory lookup record. */
00414 typedef MMPPLOOKUPHCPTR *PMMPPLOOKUPHCPTR;

/**
 * Lookup record for HC physical memory.
 */
00419 typedef struct MMPPLOOKUPHCPHYS
{
    /** The key is physical address. */
00422     AVLHCPHYSNODECORE   Core;
    /** Pointer to SUPPAGE record for this physical address. */
00424     PSUPPAGE            pPhysPage;
} MMPPLOOKUPHCPHYS;
/** Pointer to physical memory lookup record. */
00427 typedef MMPPLOOKUPHCPHYS *PMMPPLOOKUPHCPHYS;

/** @} */



/**
 * Type of memory that's locked.
 */
00436 typedef enum MMLOCKEDTYPE
{
    /** Hypervisor: Ring-3 memory locked by MM. */
00439     MM_LOCKED_TYPE_HYPER,
    /** Hypervisor: Ring-3 memory locked by MM that shouldn't be freed up. */
00441     MM_LOCKED_TYPE_HYPER_NOFREE,
    /** Hypervisor: Pre-locked ring-3 pages. */
00443     MM_LOCKED_TYPE_HYPER_PAGES,
    /** Guest: Physical VM memory (RAM & MMIO2). */
00445     MM_LOCKED_TYPE_PHYS
} MMLOCKEDTYPE;
/** Pointer to memory type. */
00448 typedef MMLOCKEDTYPE *PMMLOCKEDTYPE;


/**
 * Converts a SUPPAGE pointer to a MMLOCKEDMEM pointer.
 * @returns Pointer to the MMLOCKEDMEM record the range is associated with.
 * @param   pSupPage    Pointer to SUPPAGE structure managed by MM.
 */
00456 #define MM_SUPRANGE_TO_MMLOCKEDMEM(pSupPage) ((PMMLOCKEDMEM)pSupPage->uReserved)


/**
 * Locked memory record.
 */
00462 typedef struct MMLOCKEDMEM
{
    /** Address (host mapping). */
00465     void               *pv;
    /** Size. */
00467     size_t              cb;
    /** Next record. */
00469     struct MMLOCKEDMEM *pNext;
    /** Record type. */
00471     MMLOCKEDTYPE        eType;
    /** Type specific data. */
    union
    {
        /** Data for MM_LOCKED_TYPE_HYPER, MM_LOCKED_TYPE_HYPER_NOFREE and MM_LOCKED_TYPE_HYPER_PAGES. */
        struct
        {
            unsigned    uNothing;
        } hyper;

        /** Data for MM_LOCKED_TYPE_PHYS. */
        struct
        {
            /** The GC physical address.
             * (Assuming that this is a linear range of GC physical pages.)
             */
00487             RTGCPHYS    GCPhys;
        } phys;
    } u;

    /** Physical Page Array. (Variable length.)
     * The uReserved field contains pointer to the MMLOCKMEM record.
     * Use the macro MM_SUPPAGE_TO_MMLOCKEDMEM() to convert.
     *
     * For MM_LOCKED_TYPE_PHYS the low 12 bits of the pvPhys member
     * are bits (MM_RAM_FLAGS_*) and not part of the physical address.
     */
00498     SUPPAGE             aPhysPages[1];
} MMLOCKEDMEM;
/** Pointer to locked memory. */
00501 typedef MMLOCKEDMEM *PMMLOCKEDMEM;


/**
 * A registered Rom range.
 * 
 * This is used to track ROM registrations both for debug reasons
 * and for resetting shadow ROM at reset.
 * 
 * This is allocated of the MMR3Heap and thus only accessibel from ring-3.
 */
00512 typedef struct MMROMRANGE
{
    /** Pointer to the next */
00515     struct MMROMRANGE  *pNext;
    /** Address of the range. */
00517     RTGCPHYS            GCPhys;
    /** Size of the range. */
00519     uint32_t            cbRange;
    /** Shadow ROM? */
00521     bool                fShadow;
    /** Is the shadow ROM currently wriable? */
00523     bool                fWritable;
    /** The address of the virgin ROM image for shadow ROM. */
00525     const void         *pvBinary;
    /** The address of the guest RAM that's shadowing the ROM. (lazy bird) */
00527     void               *pvCopy;
    /** The ROM description. */
00529     const char         *pszDesc;
} MMROMRANGE;
/** Pointer to a ROM range. */
00532 typedef MMROMRANGE *PMMROMRANGE;


/**
 * Hypervisor memory mapping type.
 */
00538 typedef enum MMLOOKUPHYPERTYPE
{
    /** Invalid record. This is used for record which are incomplete. */
00541     MMLOOKUPHYPERTYPE_INVALID = 0,
    /** Mapping of locked memory. */
00543     MMLOOKUPHYPERTYPE_LOCKED,
    /** Mapping of contiguous HC physical memory. */
00545     MMLOOKUPHYPERTYPE_HCPHYS,
    /** Mapping of contiguous GC physical memory. */
00547     MMLOOKUPHYPERTYPE_GCPHYS,
    /** Dynamic mapping area (MMR3HyperReserve).
     * A conversion will require to check what's in the page table for the pages. */
00550     MMLOOKUPHYPERTYPE_DYNAMIC
};

/**
 * Lookup record for the hypervisor memory area.
 */
00556 typedef struct MMLOOKUPHYPER
{
    /** Byte offset from the start of this record to the next.
     * If the value is NIL_OFFSET the chain is terminated. */
00560     int32_t                 offNext;
    /** Offset into the hypvervisor memory area. */
00562     uint32_t                off;
    /** Size of this part. */
00564     uint32_t                cb;
    /** Locking type. */
00566     MMLOOKUPHYPERTYPE       enmType;
    /** Type specific data */
    union
    {
        /** Locked memory. */
        struct
        {
            /** Host context pointer. */
            HCPTRTYPE(void *)       pvHC;
            /** Host context ring-0 pointer. */
00576             RTR0PTR                 pvR0;
            /** Pointer to the locked mem record. */
            HCPTRTYPE(PMMLOCKEDMEM) pLockedMem;
        } Locked;

        /** Contiguous physical memory. */
        struct
        {
            /** Host context pointer. */
            HCPTRTYPE(void *)       pvHC;
            /** HC physical address corresponding to pvHC. */
00587             RTHCPHYS                HCPhys;
        } HCPhys;
        /** Contiguous guest physical memory. */
        struct
        {
            /** HC physical address corresponding to pvHC. */
00593             RTGCPHYS                GCPhys;
        } GCPhys;
    } u;
    /** Description. */
    HCPTRTYPE(const char *) pszDesc;
} MMLOOKUPHYPER;
/** Pointer to a hypervisor memory lookup record. */
00600 typedef MMLOOKUPHYPER *PMMLOOKUPHYPER;


/**
 * Converts a MM pointer into a VM pointer.
 * @returns Pointer to the VM structure the MM is part of.
 * @param   pMM   Pointer to MM instance data.
 */
00608 #define MM2VM(pMM)  ( (PVM)((char*)pMM - pMM->offVM) )


/**
 * MM Data (part of VM)
 */
00614 typedef struct MM
{
    /** Offset to the VM structure.
     * See MM2VM(). */
00618     RTINT                       offVM;

    /** Set if PGM has been initialized and we can safely call PGMR3Map(). */
00621     bool                        fPGMInitialized;
#if GC_ARCH_BITS == 64 || HC_ARCH_BITS == 64
    uint32_t                    u32Padding1; /**< alignment padding. */
#endif

    /** Lookup list for the Hypervisor Memory Area.
     * The offset is relative to the start of the heap.
     * Use pHyperHeapHC or pHyperHeapGC to calculate the address.
     */
00630     RTUINT                      offLookupHyper;

    /** The offset of the next static mapping in the Hypervisor Memory Area. */
00633     RTUINT                      offHyperNextStatic;
    /** The size of the HMA.
     * Starts at 12MB and will be fixed late in the init process. */
00636     RTUINT                      cbHyperArea;

    /** Guest address of the Hypervisor Memory Area. */
00639     RTGCPTR                     pvHyperAreaGC;

    /** The hypervisor heap (GC Ptr). */
    GCPTRTYPE(PMMHYPERHEAP)     pHyperHeapGC;
    /** The hypervisor heap (HC Ptr). */
    HCPTRTYPE(PMMHYPERHEAP)     pHyperHeapHC;

    /** List of memory locks. (HC only) */
    HCPTRTYPE(PMMLOCKEDMEM)     pLockedMem;

    /** Page pool. (HC only) */
    HCPTRTYPE(PMMPAGEPOOL)      pPagePool;
    /** Page pool pages in low memory. (HC only) */
    HCPTRTYPE(PMMPAGEPOOL)      pPagePoolLow;

    /** Pointer to the dummy page.
     * The dummy page is a paranoia thingy used for instance for pure MMIO RAM ranges
     * to make sure any bugs will not harm whatever the system stores in the first
     * physical page. */
    HCPTRTYPE(void *)           pvDummyPage;
    /** Physical address of the dummy page. */
00660     RTHCPHYS                    HCPhysDummyPage;

    /** Size of the currently allocated guest RAM.
     * Mark that this is the actual size, not the end address. */
00664     RTUINT                      cbRAMSize;
    /** Size of the base RAM in bytes. */
00666     RTUINT                      cbRamBase;
    /** Pointer to the base RAM. */
    HCPTRTYPE(void *)           pvRamBaseHC;
    /** The head of the ROM ranges. */
    R3PTRTYPE(PMMROMRANGE)      pRomHead;

    /** Pointer to the MM R3 Heap. */
    HCPTRTYPE(PMMHEAP)          pHeap;

} MM;
/** Pointer to MM Data (part of VM). */
00677 typedef MM *PMM;

__BEGIN_DECLS


int  mmr3PagePoolInit(PVM pVM);
void mmr3PagePoolTerm(PVM pVM);

int  mmr3HeapCreate(PVM pVM, PMMHEAP *ppHeap);
void mmr3HeapDestroy(PMMHEAP pHeap);

int  mmr3HyperInit(PVM pVM);
int  mmR3HyperInitPaging(PVM pVM);

int  mmr3LockMem(PVM pVM, void *pv, size_t cb, MMLOCKEDTYPE eType, PMMLOCKEDMEM *ppLockedMem, bool fSilentFailure);
int  mmr3MapLocked(PVM pVM, PMMLOCKEDMEM pLockedMem, RTGCPTR Addr, unsigned iPage, size_t cPages, unsigned fFlags);

const char *mmR3GetTagName(MMTAG enmTag);

void mmR3PhysRomReset(PVM pVM);

/**
 * Converts a pool address to a physical address.
 * The specified allocation type must match with the address.
 *
 * @returns Physical address.
 * @returns NIL_RTHCPHYS if not found or eType is not matching.
 * @param   pPool   Pointer to the page pool.
 * @param   pv      The address to convert.
 * @thread  The Emulation Thread.
 */
MMDECL(RTHCPHYS) mmPagePoolPtr2Phys(PMMPAGEPOOL pPool, void *pv);

/**
 * Converts a pool physical address to a linear address.
 * The specified allocation type must match with the address.
 *
 * @returns Physical address.
 * @returns NULL if not found or eType is not matching.
 * @param   pPool       Pointer to the page pool.
 * @param   HCPhys      The address to convert.
 * @thread  The Emulation Thread.
 */
MMDECL(void *) mmPagePoolPhys2Ptr(PMMPAGEPOOL pPool, RTHCPHYS HCPhys);

__END_DECLS

/** @} */

#endif

Generated by  Doxygen 1.6.0   Back to index