MMInternal.h revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
0N/A/** @file
5539N/A *
0N/A * MM - Internal header file.
0N/A */
0N/A
0N/A/*
2362N/A * Copyright (C) 2006 InnoTek Systemberatung GmbH
0N/A *
2362N/A * This file is part of VirtualBox Open Source Edition (OSE), as
0N/A * available from http://www.virtualbox.org. This file is free software;
0N/A * you can redistribute it and/or modify it under the terms of the GNU
0N/A * General Public License as published by the Free Software Foundation,
0N/A * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
0N/A * distribution. VirtualBox OSE is distributed in the hope that it will
0N/A * be useful, but WITHOUT ANY WARRANTY of any kind.
0N/A *
0N/A * If you received this file as part of a commercial VirtualBox
0N/A * distribution, then only the terms of your commercial VirtualBox
0N/A * license agreement apply instead of the previous paragraph.
0N/A */
2362N/A
2362N/A#ifndef __MMInternal_h__
2362N/A#define __MMInternal_h__
0N/A
0N/A#include <VBox/cdefs.h>
0N/A#include <VBox/types.h>
0N/A#include <VBox/sup.h>
0N/A#include <VBox/stam.h>
0N/A#include <iprt/avl.h>
0N/A#include <iprt/critsect.h>
0N/A
0N/A
0N/A#if !defined(IN_MM_R3) && !defined(IN_MM_R0) && !defined(IN_MM_GC)
0N/A# error "Not in MM! This is an internal header!"
0N/A#endif
0N/A
0N/A
0N/A/** @defgroup grp_mm_int Internals
0N/A * @internal
0N/A * @ingroup grp_mm
0N/A * @{
0N/A */
0N/A
0N/A/** @name VM Ring-3 Heap Internals
0N/A * @{
0N/A */
0N/A
0N/A/** @def MMR3HEAP_WITH_STATISTICS
0N/A * Enable MMR3Heap statistics.
0N/A */
0N/A#if !defined(MMR3HEAP_WITH_STATISTICS) && defined(VBOX_WITH_STATISTICS)
0N/A# define MMR3HEAP_WITH_STATISTICS
0N/A#endif
0N/A
0N/A/** @def MMR3HEAP_SIZE_ALIGNMENT
0N/A * The allocation size alignment of the MMR3Heap.
0N/A */
0N/A#define MMR3HEAP_SIZE_ALIGNMENT 16
0N/A
0N/A/**
0N/A * Heap statistics record.
0N/A * There is one global and one per allocation tag.
0N/A */
0N/Atypedef struct MMHEAPSTAT
0N/A{
0N/A /** Core avl node, key is the tag. */
0N/A AVLULNODECORE Core;
0N/A /** Pointer to the heap the memory belongs to. */
0N/A struct MMHEAP *pHeap;
0N/A#ifdef MMR3HEAP_WITH_STATISTICS
0N/A /** Number of allocation. */
0N/A uint64_t cAllocations;
0N/A /** Number of reallocations. */
0N/A uint64_t cReallocations;
0N/A /** Number of frees. */
0N/A uint64_t cFrees;
0N/A /** Failures. */
0N/A uint64_t cFailures;
0N/A /** Number of bytes allocated (sum). */
0N/A uint64_t cbAllocated;
0N/A /** Number of bytes freed. */
0N/A uint64_t cbFreed;
0N/A /** Number of bytes currently allocated. */
0N/A size_t cbCurAllocated;
0N/A#endif
0N/A} MMHEAPSTAT;
0N/A/** Pointer to heap statistics record. */
0N/Atypedef MMHEAPSTAT *PMMHEAPSTAT;
0N/A
0N/A
0N/A
0N/A/**
0N/A * Additional heap block header for relating allocations to the VM.
0N/A */
0N/Atypedef struct MMHEAPHDR
0N/A{
0N/A /** Pointer to the next record. */
0N/A struct MMHEAPHDR *pNext;
0N/A /** Pointer to the previous record. */
0N/A struct MMHEAPHDR *pPrev;
0N/A /** Pointer to the heap statistics record.
0N/A * (Where the a PVM can be found.) */
0N/A PMMHEAPSTAT pStat;
0N/A /** Size of the allocation (including this header). */
0N/A size_t cbSize;
0N/A} MMHEAPHDR;
0N/A/** Pointer to MM heap header. */
0N/Atypedef MMHEAPHDR *PMMHEAPHDR;
0N/A
0N/A
0N/A/** MM Heap structure. */
0N/Atypedef struct MMHEAP
0N/A{
0N/A /** Lock protecting the heap. */
0N/A RTCRITSECT Lock;
0N/A /** Heap block list head. */
0N/A PMMHEAPHDR pHead;
0N/A /** Heap block list tail. */
0N/A PMMHEAPHDR pTail;
0N/A /** Heap per tag statistics tree. */
0N/A PAVLULNODECORE pStatTree;
0N/A /** The VM handle. */
0N/A PVM pVM;
0N/A /** Heap global statistics. */
0N/A MMHEAPSTAT Stat;
0N/A} MMHEAP;
0N/A/** Pointer to MM Heap structure. */
0N/Atypedef MMHEAP *PMMHEAP;
0N/A
0N/A/** @} */
0N/A
0N/A
0N/A
0N/A/** @name Hypervisor Heap Internals
0N/A * @{
0N/A */
0N/A
0N/A/** @def MMHYPER_HEAP_FREE_DELAY
0N/A * If defined, it indicates the number of frees that should be delayed.
0N/A */
0N/A#if defined(__DOXYGEN__)
0N/A# define MMHYPER_HEAP_FREE_DELAY 64
0N/A#endif
0N/A
0N/A/** @def MMHYPER_HEAP_FREE_POISON
0N/A * If defined, it indicates that freed memory should be poisoned
5539N/A * with the value it has.
5539N/A */
5539N/A#if defined(VBOX_STRICT) || defined(__DOXYGEN__)
0N/A# define MMHYPER_HEAP_FREE_POISON 0xCB
0N/A#endif
0N/A
0N/A/**
0N/A * Hypervisor heap statistics record.
0N/A * There is one global and one per allocation tag.
0N/A */
0N/Atypedef struct MMHYPERSTAT
0N/A{
0N/A /** Core avl node, key is the tag.
0N/A * @todo The type is wrong! Get your lazy a$$ over and create that offsetted uint32_t version we need here! */
0N/A AVLOGCPHYSNODECORE Core;
0N/A /** Aligning the 64-bit fields on a 64-bit line. */
0N/A uint32_t u32Padding0;
0N/A /** Indicator for whether these statistics are registered with STAM or not. */
0N/A bool fRegistered;
0N/A /** Number of allocation. */
0N/A uint64_t cAllocations;
0N/A /** Number of frees. */
0N/A uint64_t cFrees;
0N/A /** Failures. */
0N/A uint64_t cFailures;
0N/A /** Number of bytes allocated (sum). */
0N/A uint64_t cbAllocated;
0N/A /** Number of bytes freed (sum). */
0N/A uint64_t cbFreed;
0N/A /** Number of bytes currently allocated. */
0N/A uint32_t cbCurAllocated;
0N/A /** Max number of bytes allocated. */
0N/A uint32_t cbMaxAllocated;
0N/A} MMHYPERSTAT;
0N/A/** Pointer to hypervisor heap statistics record. */
0N/Atypedef MMHYPERSTAT *PMMHYPERSTAT;
0N/A
0N/A/**
0N/A * Hypervisor heap chunk.
0N/A */
0N/Atypedef struct MMHYPERCHUNK
0N/A{
0N/A /** Previous block in the list of all blocks.
0N/A * This is relative to the start of the heap. */
0N/A uint32_t offNext;
0N/A /** Offset to the previous block relative to this one. */
0N/A int32_t offPrev;
0N/A /** The statistics record this allocation belongs to (self relative). */
0N/A int32_t offStat;
0N/A /** Offset to the heap block (self relative). */
0N/A int32_t offHeap;
0N/A} MMHYPERCHUNK;
0N/A/** Pointer to a hypervisor heap chunk. */
0N/Atypedef MMHYPERCHUNK *PMMHYPERCHUNK;
0N/A
0N/A
0N/A/**
0N/A * Hypervisor heap chunk.
0N/A */
0N/Atypedef struct MMHYPERCHUNKFREE
0N/A{
0N/A /** Main list. */
0N/A MMHYPERCHUNK core;
0N/A /** Offset of the next chunk in the list of free nodes. */
0N/A uint32_t offNext;
0N/A /** Offset of the previous chunk in the list of free nodes. */
0N/A int32_t offPrev;
0N/A /** Size of the block. */
0N/A uint32_t cb;
0N/A} MMHYPERCHUNKFREE;
0N/A/** Pointer to a free hypervisor heap chunk. */
0N/Atypedef MMHYPERCHUNKFREE *PMMHYPERCHUNKFREE;
0N/A
0N/A
0N/A/**
0N/A * The hypervisor heap.
0N/A */
0N/Atypedef struct MMHYPERHEAP
0N/A{
0N/A /** The typical magic (MMHYPERHEAP_MAGIC). */
0N/A uint32_t u32Magic;
0N/A /** The heap size. (This structure is not included!) */
0N/A uint32_t cbHeap;
0N/A /** The HC Ring-3 address of the VM. */
0N/A HCPTRTYPE(PVM) pVMHC;
0N/A /** The HC Ring-3 address of the heap. */
0N/A HCPTRTYPE(uint8_t *) pbHeapHC;
0N/A /** The GC address of the heap. */
0N/A GCPTRTYPE(uint8_t *) pbHeapGC;
0N/A /** The GC address of the VM. */
0N/A GCPTRTYPE(PVM) pVMGC;
0N/A /** The amount of free memory in the heap. */
0N/A uint32_t cbFree;
0N/A /** Offset of the first free chunk in the heap.
0N/A * The offset is relative to the start of the heap. */
0N/A uint32_t offFreeHead;
0N/A /** Offset of the last free chunk in the heap.
0N/A * The offset is relative to the start of the heap. */
0N/A uint32_t offFreeTail;
0N/A /** Offset of the first page aligned block in the heap.
0N/A * The offset is equal to cbHeap initially. */
0N/A uint32_t offPageAligned;
0N/A /** Tree of hypervisor heap statistics. */
0N/A AVLOGCPHYSTREE HyperHeapStatTree;
0N/A#ifdef MMHYPER_HEAP_FREE_DELAY
0N/A /** Where to insert the next free. */
0N/A uint32_t iDelayedFree;
0N/A /** Array of delayed frees. Circular. Offsets relative to this structure. */
0N/A struct
0N/A {
0N/A /** The free caller address. */
0N/A RTUINTPTR uCaller;
0N/A /** The offset of the freed chunk. */
0N/A uint32_t offChunk;
0N/A } aDelayedFrees[MMHYPER_HEAP_FREE_DELAY];
0N/A#else
0N/A /** Padding the structure to a 64-bit aligned size. */
0N/A uint32_t u32Padding0;
0N/A#endif
0N/A} MMHYPERHEAP;
0N/A/** Pointer to the hypervisor heap. */
0N/Atypedef MMHYPERHEAP *PMMHYPERHEAP;
0N/A
0N/A/** Magic value for MMHYPERHEAP. (C. S. Lewis) */
0N/A#define MMHYPERHEAP_MAGIC 0x18981129
0N/A
0N/A
0N/A/**
0N/A * Hypervisor heap minimum alignment (16 bytes).
0N/A */
0N/A#define MMHYPER_HEAP_ALIGN_MIN 16
0N/A
0N/A/**
0N/A * The aligned size of the the MMHYPERHEAP structure.
0N/A */
0N/A#define MMYPERHEAP_HDR_SIZE RT_ALIGN_Z(sizeof(MMHYPERHEAP), MMHYPER_HEAP_ALIGN_MIN * 4)
0N/A
0N/A/** @name Hypervisor heap chunk flags.
0N/A * The flags are put in the first bits of the MMHYPERCHUNK::offPrev member.
0N/A * These bits aren't used anyway because of the chunk minimal alignment (16 bytes).
0N/A * @{ */
0N/A/** The chunk is free. (The code ASSUMES this is 0!) */
0N/A#define MMHYPERCHUNK_FLAGS_FREE 0x0
0N/A/** The chunk is in use. */
0N/A#define MMHYPERCHUNK_FLAGS_USED 0x1
0N/A/** The type mask. */
0N/A#define MMHYPERCHUNK_FLAGS_TYPE_MASK 0x1
0N/A/** The flag mask */
0N/A#define MMHYPERCHUNK_FLAGS_MASK 0x1
0N/A
0N/A/** Checks if the chunk is free. */
0N/A#define MMHYPERCHUNK_ISFREE(pChunk) ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_FREE )
0N/A/** Checks if the chunk is used. */
0N/A#define MMHYPERCHUNK_ISUSED(pChunk) ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_USED )
0N/A/** Toggles FREE/USED flag of a chunk. */
0N/A#define MMHYPERCHUNK_SET_TYPE(pChunk, type) do { (pChunk)->offPrev = ((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_TYPE_MASK) | ((type) & MMHYPERCHUNK_FLAGS_TYPE_MASK); } while (0)
0N/A
0N/A/** Gets the prev offset without the flags. */
0N/A#define MMHYPERCHUNK_GET_OFFPREV(pChunk) ((int32_t)((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_MASK))
0N/A/** Sets the prev offset without changing the flags. */
0N/A#define MMHYPERCHUNK_SET_OFFPREV(pChunk, off) do { (pChunk)->offPrev = (off) | ((pChunk)->offPrev & MMHYPERCHUNK_FLAGS_MASK); } while (0)
0N/A#if 0
0N/A/** Clears one or more flags. */
0N/A#define MMHYPERCHUNK_FLAGS_OP_CLEAR(pChunk, fFlags) do { ((pChunk)->offPrev) &= ~((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
0N/A/** Sets one or more flags. */
0N/A#define MMHYPERCHUNK_FLAGS_OP_SET(pChunk, fFlags) do { ((pChunk)->offPrev) |= ((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
0N/A/** Checks if one is set. */
0N/A#define MMHYPERCHUNK_FLAGS_OP_ISSET(pChunk, fFlag) (!!(((pChunk)->offPrev) & ((fFlag) & MMHYPERCHUNK_FLAGS_MASK)))
0N/A#endif
0N/A/** @} */
0N/A
0N/A/** @} */
0N/A
0N/A
0N/A/** @name Page Pool Internals
0N/A * @{
0N/A */
0N/A
0N/A/**
0N/A * Page sub pool
0N/A *
0N/A * About the allocation of this structrue. To keep the number of heap blocks,
0N/A * the number of heap calls, and fragmentation low we allocate all the data
0N/A * related to a MMPAGESUBPOOL node in one chunk. That means that after the
0N/A * bitmap (which is of variable size) comes the SUPPAGE records and then
0N/A * follows the lookup tree nodes.
0N/A */
0N/Atypedef struct MMPAGESUBPOOL
0N/A{
0N/A /** Pointer to next sub pool. */
0N/A struct MMPAGESUBPOOL *pNext;
0N/A /** Pointer to next sub pool in the free chain.
0N/A * This is NULL if we're not in the free chain or at the end of it. */
0N/A struct MMPAGESUBPOOL *pNextFree;
0N/A /** Pointer to array of lock ranges.
0N/A * This is allocated together with the MMPAGESUBPOOL and thus needs no freeing.
0N/A * It follows immediately after the bitmap.
0N/A * The reserved field is a pointer to this structure.
0N/A */
0N/A PSUPPAGE paPhysPages;
0N/A /** Pointer to the first page. */
0N/A void *pvPages;
0N/A /** Size of the subpool. */
0N/A unsigned cPages;
0N/A /** Number of free pages. */
0N/A unsigned cPagesFree;
0N/A /** The allocation bitmap.
0N/A * This may extend beyond the end of the defined array size.
0N/A */
0N/A unsigned auBitmap[1];
0N/A /* ... SUPPAGE aRanges[1]; */
0N/A} MMPAGESUBPOOL;
0N/A/** Pointer to page sub pool. */
0N/Atypedef MMPAGESUBPOOL *PMMPAGESUBPOOL;
0N/A
0N/A/**
0N/A * Page pool.
0N/A */
0N/Atypedef struct MMPAGEPOOL
0N/A{
0N/A /** List of subpools. */
0N/A PMMPAGESUBPOOL pHead;
0N/A /** Head of subpools with free pages. */
0N/A PMMPAGESUBPOOL pHeadFree;
0N/A /** AVLPV tree for looking up HC virtual addresses.
0N/A * The tree contains MMLOOKUPVIRTPP records.
0N/A */
0N/A PAVLPVNODECORE pLookupVirt;
0N/A /** Tree for looking up HC physical addresses.
0N/A * The tree contains MMLOOKUPPHYSHC records.
0N/A */
0N/A AVLHCPHYSTREE pLookupPhys;
0N/A /** Pointer to the VM this pool belongs. */
0N/A PVM pVM;
0N/A /** Flag indicating the allocation method.
0N/A * Set: SUPLowAlloc().
0N/A * Clear: SUPPageAlloc() + SUPPageLock(). */
0N/A bool fLow;
0N/A /** Number of subpools. */
0N/A uint32_t cSubPools;
0N/A /** Number of pages in pool. */
0N/A uint32_t cPages;
0N/A#ifdef VBOX_WITH_STATISTICS
0N/A /** Number of free pages in pool. */
0N/A uint32_t cFreePages;
0N/A /** Number of alloc calls. */
0N/A STAMCOUNTER cAllocCalls;
0N/A /** Number of free calls. */
0N/A STAMCOUNTER cFreeCalls;
0N/A /** Number of to phys conversions. */
0N/A STAMCOUNTER cToPhysCalls;
0N/A /** Number of to virtual conversions. */
0N/A STAMCOUNTER cToVirtCalls;
0N/A /** Number of real errors. */
0N/A STAMCOUNTER cErrors;
0N/A#endif
0N/A} MMPAGEPOOL;
0N/A/** Pointer to page pool. */
0N/Atypedef MMPAGEPOOL *PMMPAGEPOOL;
0N/A
0N/A/**
0N/A * Lookup record for HC virtual memory in the page pool.
0N/A */
0N/Atypedef struct MMPPLOOKUPHCPTR
0N/A{
0N/A /** The key is virtual address. */
0N/A AVLPVNODECORE Core;
0N/A /** Pointer to subpool if lookup record for a pool. */
0N/A struct MMPAGESUBPOOL *pSubPool;
0N/A} MMPPLOOKUPHCPTR;
0N/A/** Pointer to virtual memory lookup record. */
0N/Atypedef MMPPLOOKUPHCPTR *PMMPPLOOKUPHCPTR;
0N/A
0N/A/**
0N/A * Lookup record for HC physical memory.
0N/A */
0N/Atypedef struct MMPPLOOKUPHCPHYS
0N/A{
0N/A /** The key is physical address. */
0N/A AVLHCPHYSNODECORE Core;
0N/A /** Pointer to SUPPAGE record for this physical address. */
0N/A PSUPPAGE pPhysPage;
0N/A} MMPPLOOKUPHCPHYS;
0N/A/** Pointer to physical memory lookup record. */
0N/Atypedef MMPPLOOKUPHCPHYS *PMMPPLOOKUPHCPHYS;
0N/A
0N/A/** @} */
0N/A
0N/A
0N/A
0N/A/**
0N/A * Type of memory that's locked.
0N/A */
0N/Atypedef enum MMLOCKEDTYPE
0N/A{
0N/A /** Hypervisor memory (VMM GC). */
0N/A MM_LOCKED_TYPE_HYPER,
0N/A /** Hypervisor memory to be mapped from HC. */
0N/A MM_LOCKED_TYPE_HYPER_NOFREE,
0N/A /** Physical VM memory (RAM & MMIO2). */
0N/A MM_LOCKED_TYPE_PHYS
0N/A} MMLOCKEDTYPE;
0N/A/** Pointer to memory type. */
0N/Atypedef MMLOCKEDTYPE *PMMLOCKEDTYPE;
0N/A
0N/A
0N/A/**
0N/A * Converts a SUPPAGE pointer to a MMLOCKEDMEM pointer.
0N/A * @returns Pointer to the MMLOCKEDMEM record the range is associated with.
0N/A * @param pSupPage Pointer to SUPPAGE structure managed by MM.
0N/A */
0N/A#define MM_SUPRANGE_TO_MMLOCKEDMEM(pSupPage) ((PMMLOCKEDMEM)pSupPage->uReserved)
0N/A
0N/A
0N/A/**
0N/A * Locked memory record.
0N/A */
0N/Atypedef struct MMLOCKEDMEM
0N/A{
0N/A /** Address (host mapping). */
0N/A void *pv;
0N/A /** Size. */
0N/A size_t cb;
0N/A /** Next record. */
0N/A struct MMLOCKEDMEM *pNext;
0N/A /** Record type. */
0N/A MMLOCKEDTYPE eType;
0N/A /** Type specific data. */
0N/A union
0N/A {
0N/A /** Data for MM_LOCKED_TYPE_HYPER. */
439N/A struct
0N/A {
0N/A unsigned uNothing;
0N/A } hyper;
0N/A
0N/A /** Data for MM_LOCKED_TYPE_PHYS. */
0N/A struct
0N/A {
0N/A /** The GC physical address.
0N/A * (Assuming that this is a linear range of GC physical pages.)
0N/A */
0N/A RTGCPHYS GCPhys;
0N/A } phys;
0N/A } u;
0N/A
0N/A /** Physical Page Array. (Variable length.)
0N/A * The uReserved field contains pointer to the MMLOCKMEM record.
0N/A * Use the macro MM_SUPPAGE_TO_MMLOCKEDMEM() to convert.
0N/A *
0N/A * For MM_LOCKED_TYPE_PHYS the low 12 bits of the pvPhys member
0N/A * are bits (MM_RAM_FLAGS_*) and not part of the physical address.
0N/A */
0N/A SUPPAGE aPhysPages[1];
0N/A} MMLOCKEDMEM;
0N/A/** Pointer to locked memory. */
0N/Atypedef MMLOCKEDMEM *PMMLOCKEDMEM;
0N/A
0N/A
0N/A/**
0N/A * Hypervisor memory mapping type.
0N/A */
0N/Atypedef enum MMLOOKUPHYPERTYPE
0N/A{
0N/A /** Invalid record. This is used for record which are incomplete. */
0N/A MMLOOKUPHYPERTYPE_INVALID = 0,
0N/A /** Mapping of locked memory. */
0N/A MMLOOKUPHYPERTYPE_LOCKED,
0N/A /** Mapping of contiguous HC physical memory. */
0N/A MMLOOKUPHYPERTYPE_HCPHYS,
0N/A /** Mapping of contiguous GC physical memory. */
0N/A MMLOOKUPHYPERTYPE_GCPHYS,
0N/A /** Dynamic mapping area (MMR3HyperReserve).
0N/A * A conversion will require to check what's in the page table for the pages. */
0N/A MMLOOKUPHYPERTYPE_DYNAMIC
0N/A};
0N/A
0N/A/**
0N/A * Lookup record for the hypervisor memory area.
0N/A */
0N/Atypedef struct MMLOOKUPHYPER
0N/A{
0N/A /** Byte offset from the start of this record to the next.
0N/A * If the value is NIL_OFFSET the chain is terminated. */
0N/A int32_t offNext;
0N/A /** Offset into the hypvervisor memory area. */
0N/A uint32_t off;
0N/A /** Size of this part. */
0N/A uint32_t cb;
0N/A /** Locking type. */
0N/A MMLOOKUPHYPERTYPE enmType;
0N/A /** Type specific data */
0N/A union
0N/A {
0N/A /** Locked memory. */
0N/A struct
0N/A {
0N/A /** Host context pointer. */
0N/A HCPTRTYPE(void *) pvHC;
0N/A /** Pointer to the locked mem record. */
0N/A HCPTRTYPE(PMMLOCKEDMEM) pLockedMem;
0N/A } Locked;
0N/A
0N/A /** Contiguous physical memory. */
0N/A struct
0N/A {
0N/A /** Host context pointer. */
0N/A HCPTRTYPE(void *) pvHC;
0N/A /** HC physical address corresponding to pvHC. */
0N/A RTHCPHYS HCPhys;
0N/A } HCPhys;
0N/A /** Contiguous guest physical memory. */
0N/A struct
0N/A {
0N/A /** HC physical address corresponding to pvHC. */
0N/A RTGCPHYS GCPhys;
0N/A } GCPhys;
0N/A } u;
0N/A /** Description. */
0N/A HCPTRTYPE(const char *) pszDesc;
0N/A} MMLOOKUPHYPER;
0N/A/** Pointer to a hypervisor memory lookup record. */
0N/Atypedef MMLOOKUPHYPER *PMMLOOKUPHYPER;
0N/A
0N/A
0N/A/**
0N/A * Converts a MM pointer into a VM pointer.
0N/A * @returns Pointer to the VM structure the MM is part of.
0N/A * @param pMM Pointer to MM instance data.
0N/A */
0N/A#define MM2VM(pMM) ( (PVM)((char*)pMM - pMM->offVM) )
0N/A
0N/A
0N/A/**
0N/A * MM Data (part of VM)
0N/A */
0N/Atypedef struct MM
0N/A{
0N/A /** Offset to the VM structure.
0N/A * See MM2VM(). */
0N/A RTINT offVM;
0N/A
0N/A /** Set if PGM has been initialized and we can safely call PGMR3Map(). */
0N/A bool fPGMInitialized;
0N/A#if GC_ARCH_BITS == 64
0N/A uint32_t u32Padding1; /**< alignment padding. */
0N/A#endif
0N/A
0N/A /** Lookup list for the Hypervisor Memory Area.
0N/A * The offset is relative to the start of the heap.
0N/A * Use pHyperHeapHC or pHyperHeapGC to calculate the address.
0N/A */
0N/A RTUINT offLookupHyper;
0N/A
0N/A /** The offset of the next static mapping in the Hypervisor Memory Area. */
0N/A RTUINT offHyperNextStatic;
0N/A /** The size of the HMA.
0N/A * Starts at 12MB and will be fixed late in the init process. */
0N/A RTUINT cbHyperArea;
0N/A
0N/A /** Guest address of the Hypervisor Memory Area. */
0N/A RTGCPTR pvHyperAreaGC;
0N/A
0N/A /** The hypervisor heap (GC Ptr). */
0N/A GCPTRTYPE(PMMHYPERHEAP) pHyperHeapGC;
0N/A /** The hypervisor heap (HC Ptr). */
0N/A HCPTRTYPE(PMMHYPERHEAP) pHyperHeapHC;
0N/A
0N/A /** List of memory locks. (HC only) */
0N/A HCPTRTYPE(PMMLOCKEDMEM) pLockedMem;
0N/A
0N/A /** 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. */
RTHCPHYS HCPhysDummyPage;
/** Size of the currently allocated guest RAM.
* Mark that this is the actual size, not the end address. */
RTUINT cbRAMSize;
/** Size of the base RAM in bytes. */
RTUINT cbRamBase;
/** Pointer to the base RAM. */
HCPTRTYPE(void *) pvRamBaseHC;
/** Pointer to the MM R3 Heap. */
HCPTRTYPE(PMMHEAP) pHeap;
} MM;
/** Pointer to MM Data (part of VM). */
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);
int mmr3MapLocked(PVM pVM, PMMLOCKEDMEM pLockedMem, RTGCPTR Addr, unsigned iPage, size_t cPages, unsigned fFlags);
const char *mmR3GetTagName(MMTAG enmTag);
/**
* 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