VirtualBox

Changeset 93718 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 14, 2022 11:09:36 AM (3 years ago)
Author:
vboxsync
Message:

VMM/MM: Removed the hyper heap. bugref:10093 bugref:9517

Location:
trunk/src/VBox/VMM
Files:
3 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/Makefile.kmk

    r93650 r93718  
    134134        VMMR3/MM.cpp \
    135135        VMMR3/MMHeap.cpp \
    136         VMMR3/MMHyper.cpp \
    137136        VMMR3/NEMR3.cpp \
    138137        VMMR3/PDM.cpp \
     
    183182        VMMAll/IOMAllMmioNew.cpp \
    184183        VMMAll/MMAll.cpp \
    185         VMMAll/MMAllHyper.cpp \
    186184        VMMAll/NEMAll.cpp \
    187185        VMMAll/PDMAll.cpp \
     
    517515        VMMAll/IOMAllMmioNew.cpp \
    518516        VMMAll/MMAll.cpp \
    519         VMMAll/MMAllHyper.cpp \
    520517        VMMAll/NEMAll.cpp \
    521518        VMMAll/PDMAll.cpp \
  • trunk/src/VBox/VMM/VMMAll/MMAll.cpp

    r93629 r93718  
    2929#include <iprt/assert.h>
    3030#include <iprt/string.h>
    31 
    32 
    33 
    34 /**
    35  * Lookup a host context ring-3 address.
    36  *
    37  * @returns Pointer to the corresponding lookup record.
    38  * @returns NULL on failure.
    39  * @param   pVM     The cross context VM structure.
    40  * @param   R3Ptr   The host context ring-3 address to lookup.
    41  * @param   poff    Where to store the offset into the HMA memory chunk.
    42  */
    43 DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupR3(PVM pVM, RTR3PTR R3Ptr, uint32_t *poff)
    44 {
    45     /** @todo cache last lookup, this stuff ain't cheap! */
    46     PMMLOOKUPHYPER  pLookup = (PMMLOOKUPHYPER)((uint8_t *)pVM->mm.s.CTX_SUFF(pHyperHeap) + pVM->mm.s.offLookupHyper);
    47     for (;;)
    48     {
    49         switch (pLookup->enmType)
    50         {
    51             case MMLOOKUPHYPERTYPE_LOCKED:
    52             {
    53                 const RTR3UINTPTR off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.Locked.pvR3;
    54                 if (off < pLookup->cb)
    55                 {
    56                     *poff = off;
    57                     return pLookup;
    58                 }
    59                 break;
    60             }
    61 
    62             case MMLOOKUPHYPERTYPE_HCPHYS:
    63             {
    64                 const RTR3UINTPTR off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.HCPhys.pvR3;
    65                 if (off < pLookup->cb)
    66                 {
    67                     *poff = off;
    68                     return pLookup;
    69                 }
    70                 break;
    71             }
    72 
    73             case MMLOOKUPHYPERTYPE_GCPHYS:  /* (for now we'll not allow these kind of conversions) */
    74             case MMLOOKUPHYPERTYPE_MMIO2:
    75             case MMLOOKUPHYPERTYPE_DYNAMIC:
    76                 break;
    77 
    78             default:
    79                 AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
    80                 break;
    81         }
    82 
    83         /* next */
    84         if (pLookup->offNext ==  (int32_t)NIL_OFFSET)
    85             break;
    86         pLookup = (PMMLOOKUPHYPER)((uint8_t *)pLookup + pLookup->offNext);
    87     }
    88 
    89     AssertMsgFailed(("R3Ptr=%RHv is not inside the hypervisor memory area!\n", R3Ptr));
    90     return NULL;
    91 }
    92 
    93 
    94 /**
    95  * Calculate the host context ring-0 address of an offset into the HMA memory chunk.
    96  *
    97  * @returns the host context ring-0 address.
    98  * @param   pVM         The cross context VM structure.
    99  * @param   pLookup     The HMA lookup record.
    100  * @param   off         The offset into the HMA memory chunk.
    101  */
    102 DECLINLINE(RTR0PTR) mmHyperLookupCalcR0(PVM pVM, PMMLOOKUPHYPER pLookup, uint32_t off)
    103 {
    104     switch (pLookup->enmType)
    105     {
    106         case MMLOOKUPHYPERTYPE_LOCKED:
    107             if (pLookup->u.Locked.pvR0)
    108                 return (RTR0PTR)((RTR0UINTPTR)pLookup->u.Locked.pvR0 + off);
    109 #ifdef IN_RING3
    110             AssertMsg(SUPR3IsDriverless(), ("%s\n", R3STRING(pLookup->pszDesc)));
    111 #else
    112             AssertMsgFailed(("%s\n", R3STRING(pLookup->pszDesc)));
    113 #endif
    114             NOREF(pVM);
    115             return NIL_RTR0PTR;
    116 
    117         case MMLOOKUPHYPERTYPE_HCPHYS:
    118             if (pLookup->u.HCPhys.pvR0)
    119                 return (RTR0PTR)((RTR0UINTPTR)pLookup->u.HCPhys.pvR0 + off);
    120 #ifdef IN_RING3
    121             AssertMsg(SUPR3IsDriverless(), ("%s\n", R3STRING(pLookup->pszDesc)));
    122 #else
    123             AssertMsgFailed(("%s\n", R3STRING(pLookup->pszDesc)));
    124 #endif
    125             return NIL_RTR0PTR;
    126 
    127         default:
    128             AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
    129             return NIL_RTR0PTR;
    130     }
    131 }
    132 
    133 
    134 /**
    135  * Converts a ring-3 host context address in the Hypervisor memory region to a ring-0 host context address.
    136  *
    137  * @returns ring-0 host context address.
    138  * @param   pVM         The cross context VM structure.
    139  * @param   R3Ptr       The ring-3 host context address.
    140  *                      You'll be damned if this is not in the HMA! :-)
    141  * @thread  The Emulation Thread.
    142  */
    143 VMMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr)
    144 {
    145     uint32_t off;
    146     PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
    147     if (pLookup)
    148         return mmHyperLookupCalcR0(pVM, pLookup, off);
    149     AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
    150     return NIL_RTR0PTR;
    151 }
    152 
    153 
    154 #ifdef IN_RING0
    155 /**
    156  * Converts a ring-3 host context address in the Hypervisor memory region to a current context address.
    157  *
    158  * @returns current context address.
    159  * @param   pVM         The cross context VM structure.
    160  * @param   R3Ptr       The ring-3 host context address.
    161  *                      You'll be damned if this is not in the HMA! :-)
    162  * @thread  The Emulation Thread.
    163  */
    164 VMMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
    165 {
    166     uint32_t off;
    167     PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
    168     if (pLookup)
    169         return mmHyperLookupCalcR0(pVM, pLookup, off);
    170     return NULL;
    171 }
    172 #endif
    17331
    17432
  • trunk/src/VBox/VMM/VMMR3/EM.cpp

    r93204 r93718  
    10591059    STAM_REL_PROFILE_ADV_START(&pVCpu->em.s.StatREMTotal, a);
    10601060
    1061 #if defined(VBOX_STRICT) && defined(DEBUG_bird)
    1062     AssertMsg(   VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL)
    1063               || !MMHyperIsInsideArea(pVM, CPUMGetGuestEIP(pVCpu)),  /** @todo @bugref{1419} - get flat address. */
    1064               ("cs:eip=%RX16:%RX32\n", CPUMGetGuestCS(pVCpu), CPUMGetGuestEIP(pVCpu)));
    1065 #endif
    1066 
    10671061    /*
    10681062     * Spin till we get a forced action which returns anything but VINF_SUCCESS
  • trunk/src/VBox/VMM/VMMR3/MM.cpp

    r93598 r93718  
    233233    AssertRelease(!(RT_UOFFSETOF(VM, mm.s) & 31));
    234234    AssertRelease(sizeof(pVM->mm.s) <= sizeof(pVM->mm.padding));
    235     AssertMsg(pVM->mm.s.offVM == 0, ("Already initialized!\n"));
    236 
    237     /*
    238      * Init the structure.
    239      */
    240     pVM->mm.s.offVM = RT_UOFFSETOF(VM, mm);
    241     pVM->mm.s.offLookupHyper = NIL_OFFSET;
    242 
    243     /*
    244      * Init the hypervisor related stuff.
    245      */
    246     int rc = mmR3HyperInit(pVM);
    247     if (RT_SUCCESS(rc))
    248     {
    249         /*
    250          * Register the saved state data unit.
    251          */
    252         rc = SSMR3RegisterInternal(pVM, "mm", 1, MM_SAVED_STATE_VERSION, sizeof(uint32_t) * 2,
     235
     236    /*
     237     * Register the saved state data unit.
     238     */
     239    int rc = SSMR3RegisterInternal(pVM, "mm", 1, MM_SAVED_STATE_VERSION, sizeof(uint32_t) * 2,
    253240                                   NULL, NULL, NULL,
    254241                                   NULL, mmR3Save, NULL,
    255242                                   NULL, mmR3Load, NULL);
    256         if (RT_SUCCESS(rc))
    257         {
    258             /*
    259              * Statistics.
    260              */
    261             STAM_REG(pVM, &pVM->mm.s.cBasePages,   STAMTYPE_U64, "/MM/Reserved/cBasePages",   STAMUNIT_PAGES, "Reserved number of base pages, ROM and Shadow ROM included.");
    262             STAM_REG(pVM, &pVM->mm.s.cHandyPages,  STAMTYPE_U32, "/MM/Reserved/cHandyPages",  STAMUNIT_PAGES, "Reserved number of handy pages.");
    263             STAM_REG(pVM, &pVM->mm.s.cShadowPages, STAMTYPE_U32, "/MM/Reserved/cShadowPages", STAMUNIT_PAGES, "Reserved number of shadow paging pages.");
    264             STAM_REG(pVM, &pVM->mm.s.cFixedPages,  STAMTYPE_U32, "/MM/Reserved/cFixedPages",  STAMUNIT_PAGES, "Reserved number of fixed pages (MMIO2).");
    265             STAM_REG(pVM, &pVM->mm.s.cbRamBase,    STAMTYPE_U64, "/MM/cbRamBase",             STAMUNIT_BYTES, "Size of the base RAM.");
    266 
    267             return rc;
    268         }
    269 
    270         /* .... failure .... */
    271     }
    272     MMR3Term(pVM);
     243    if (RT_SUCCESS(rc))
     244    {
     245        /*
     246         * Statistics.
     247         */
     248        STAM_REG(pVM, &pVM->mm.s.cBasePages,   STAMTYPE_U64, "/MM/Reserved/cBasePages",   STAMUNIT_PAGES, "Reserved number of base pages, ROM and Shadow ROM included.");
     249        STAM_REG(pVM, &pVM->mm.s.cHandyPages,  STAMTYPE_U32, "/MM/Reserved/cHandyPages",  STAMUNIT_PAGES, "Reserved number of handy pages.");
     250        STAM_REG(pVM, &pVM->mm.s.cShadowPages, STAMTYPE_U32, "/MM/Reserved/cShadowPages", STAMUNIT_PAGES, "Reserved number of shadow paging pages.");
     251        STAM_REG(pVM, &pVM->mm.s.cFixedPages,  STAMTYPE_U32, "/MM/Reserved/cFixedPages",  STAMUNIT_PAGES, "Reserved number of fixed pages (MMIO2).");
     252        STAM_REG(pVM, &pVM->mm.s.cbRamBase,    STAMTYPE_U64, "/MM/cbRamBase",             STAMUNIT_BYTES, "Size of the base RAM.");
     253
     254        return rc;
     255    }
     256
    273257    return rc;
    274258}
     
    451435VMMR3DECL(int) MMR3Term(PVM pVM)
    452436{
    453     /*
    454      * Clean up the hypervisor heap.
    455      */
    456     mmR3HyperTerm(pVM);
    457 
    458     /*
    459      * Zero stuff to detect after termination use of the MM interface
    460      */
    461     pVM->mm.s.offLookupHyper = NIL_OFFSET;
    462     pVM->mm.s.pHyperHeapR3   = NULL;        /* freed above. */
    463     pVM->mm.s.pHyperHeapR0   = NIL_RTR0PTR; /* freed above. */
    464     pVM->mm.s.pHyperHeapRC   = NIL_RTRCPTR; /* freed above. */
    465     pVM->mm.s.offVM          = 0;           /* init assertion on this */
    466 
     437    RT_NOREF(pVM);
    467438    return VINF_SUCCESS;
    468439}
     
    485456    mmR3HeapDestroy(pUVM->mm.s.pHeap);
    486457    pUVM->mm.s.pHeap = NULL;
    487 }
    488 
    489 
    490 /**
    491  * Checks if the both VM and UVM parts of MM have been initialized.
    492  *
    493  * @returns true if initialized, false if not.
    494  * @param   pVM         The cross context VM structure.
    495  */
    496 VMMR3_INT_DECL(bool) MMR3IsInitialized(PVM pVM)
    497 {
    498     return pVM->mm.s.pHyperHeapR3 != NULL;
    499458}
    500459
  • trunk/src/VBox/VMM/VMMR3/PDMLdr.cpp

    r93554 r93718  
    475475     * Validate input.
    476476     */
    477     AssertMsg(MMR3IsInitialized(pVM), ("bad init order!\n"));
    478477    AssertReturn(VM_IS_RAW_MODE_ENABLED(pVM), VERR_PDM_HM_IPE);
    479478
     
    968967    AssertPtrNull(pszModule);
    969968    AssertPtr(pRCPtrValue);
    970     AssertMsg(MMR3IsInitialized(pVM), ("bad init order!\n"));
    971969
    972970    if (!pszModule)
     
    10371035    AssertPtr(pszModule);
    10381036    AssertPtr(pRCPtrValue);
    1039     AssertMsg(MMR3IsInitialized(pVM), ("bad init order!\n"));
    10401037
    10411038    /*
  • trunk/src/VBox/VMM/VMMR3/VM.cpp

    r93554 r93718  
    885885                                                                if (RT_SUCCESS(rc))
    886886                                                                {
    887                                                                     rc = MMR3HyperInitFinalize(pVM);
    888                                                                     if (RT_SUCCESS(rc))
    889                                                                         rc = PGMR3InitFinalize(pVM);
     887                                                                    rc = PGMR3InitFinalize(pVM);
    890888                                                                    if (RT_SUCCESS(rc))
    891889                                                                        rc = TMR3InitFinalize(pVM);
  • trunk/src/VBox/VMM/include/MMInternal.h

    r93595 r93718  
    133133/** @} */
    134134
    135 
    136 /** @name MMUkHeap - VM User-kernel Heap Internals
    137  * @{
    138  */
    139 
    140 /** @def MMUKHEAP_SIZE_ALIGNMENT
    141  * The allocation size alignment of the MMR3UkHeap.
    142  */
    143 #define MMUKHEAP_SIZE_ALIGNMENT   16
    144 
    145 /** @def MMUKHEAP_WITH_STATISTICS
    146  * Enable MMUkHeap statistics.
    147  */
    148 #if !defined(MMUKHEAP_WITH_STATISTICS) && defined(VBOX_WITH_STATISTICS)
    149 # define MMUKHEAP_WITH_STATISTICS
    150 #endif
    151 
    152 
    153 /**
    154  * Heap statistics record.
    155  * There is one global and one per allocation tag.
    156  */
    157 typedef struct MMUKHEAPSTAT
    158 {
    159     /** Core avl node, key is the tag. */
    160     AVLULNODECORE           Core;
    161     /** Number of allocation. */
    162     uint64_t                cAllocations;
    163     /** Number of reallocations. */
    164     uint64_t                cReallocations;
    165     /** Number of frees. */
    166     uint64_t                cFrees;
    167     /** Failures. */
    168     uint64_t                cFailures;
    169     /** Number of bytes allocated (sum). */
    170     uint64_t                cbAllocated;
    171     /** Number of bytes freed. */
    172     uint64_t                cbFreed;
    173     /** Number of bytes currently allocated. */
    174     size_t                  cbCurAllocated;
    175 } MMUKHEAPSTAT;
    176 #ifdef IN_RING3
    177 AssertCompileMemberAlignment(MMUKHEAPSTAT, cAllocations, 8);
    178 #endif
    179 /** Pointer to heap statistics record. */
    180 typedef MMUKHEAPSTAT *PMMUKHEAPSTAT;
    181 
    182 /**
    183  * Sub heap tracking record.
    184  */
    185 typedef struct MMUKHEAPSUB
    186 {
    187     /** Pointer to the next sub-heap. */
    188     struct MMUKHEAPSUB     *pNext;
    189     /** The base address of the sub-heap. */
    190     void                   *pv;
    191     /** The size of the sub-heap.  */
    192     size_t                  cb;
    193     /** The handle of the simple block pointer. */
    194     RTHEAPSIMPLE            hSimple;
    195     /** The ring-0 address corresponding to MMUKHEAPSUB::pv. */
    196     RTR0PTR                 pvR0;
    197 } MMUKHEAPSUB;
    198 /** Pointer to a sub-heap tracking record. */
    199 typedef MMUKHEAPSUB *PMMUKHEAPSUB;
    200 
    201 
    202 /** MM User-kernel Heap structure. */
    203 typedef struct MMUKHEAP
    204 {
    205     /** Lock protecting the heap. */
    206     RTCRITSECT              Lock;
    207     /** Head of the sub-heap LIFO. */
    208     PMMUKHEAPSUB            pSubHeapHead;
    209     /** Heap per tag statistics tree. */
    210     PAVLULNODECORE          pStatTree;
    211     /** The VM handle. */
    212     PUVM                    pUVM;
    213 #if HC_ARCH_BITS == 32
    214     /** Aligning the statistics on an 8 byte boundary (for uint64_t and STAM). */
    215     void                   *pvAlignment;
    216 #endif
    217     /** Heap global statistics. */
    218     MMUKHEAPSTAT            Stat;
    219 } MMUKHEAP;
    220 #ifdef IN_RING3
    221 AssertCompileMemberAlignment(MMUKHEAP, Stat, 8);
    222 #endif
    223 /** Pointer to MM Heap structure. */
    224 typedef MMUKHEAP *PMMUKHEAP;
    225 
    226 /** @} */
    227 
    228 
    229 
    230 /** @name Hypervisor Heap Internals
    231  * @{
    232  */
    233 
    234 /** @def MMHYPER_HEAP_FREE_DELAY
    235  * If defined, it indicates the number of frees that should be delayed.
    236  */
    237 #if defined(DOXYGEN_RUNNING)
    238 # define MMHYPER_HEAP_FREE_DELAY            64
    239 #endif
    240 
    241 /** @def MMHYPER_HEAP_FREE_POISON
    242  * If defined, it indicates that freed memory should be poisoned
    243  * with the value it has.
    244  */
    245 #if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
    246 # define MMHYPER_HEAP_FREE_POISON           0xcb
    247 #endif
    248 
    249 /** @def MMHYPER_HEAP_STRICT
    250  * Enables a bunch of assertions in the heap code. */
    251 #if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
    252 # define MMHYPER_HEAP_STRICT 1
    253 # if 0 || defined(DOXYGEN_RUNNING)
    254 /** @def MMHYPER_HEAP_STRICT_FENCE
    255  * Enables tail fence. */
    256 #  define MMHYPER_HEAP_STRICT_FENCE
    257 /** @def MMHYPER_HEAP_STRICT_FENCE_SIZE
    258  * The fence size in bytes. */
    259 #  define MMHYPER_HEAP_STRICT_FENCE_SIZE    256
    260 /** @def MMHYPER_HEAP_STRICT_FENCE_U32
    261  * The fence filler. */
    262 #  define MMHYPER_HEAP_STRICT_FENCE_U32     UINT32_C(0xdeadbeef)
    263 # endif
    264 #endif
    265 
    266 /**
    267  * Hypervisor heap statistics record.
    268  * There is one global and one per allocation tag.
    269  */
    270 typedef struct MMHYPERSTAT
    271 {
    272     /** Core avl node, key is the tag.
    273      * @todo The type is wrong! Get your lazy a$$ over and create that offsetted uint32_t version we need here!  */
    274     AVLOGCPHYSNODECORE      Core;
    275     /** Aligning the 64-bit fields on a 64-bit line. */
    276     uint32_t                u32Padding0;
    277     /** Indicator for whether these statistics are registered with STAM or not. */
    278     bool                    fRegistered;
    279     /** Number of allocation. */
    280     uint64_t                cAllocations;
    281     /** Number of frees. */
    282     uint64_t                cFrees;
    283     /** Failures. */
    284     uint64_t                cFailures;
    285     /** Number of bytes allocated (sum). */
    286     uint64_t                cbAllocated;
    287     /** Number of bytes freed (sum). */
    288     uint64_t                cbFreed;
    289     /** Number of bytes currently allocated. */
    290     uint32_t                cbCurAllocated;
    291     /** Max number of bytes allocated. */
    292     uint32_t                cbMaxAllocated;
    293 } MMHYPERSTAT;
    294 AssertCompileMemberAlignment(MMHYPERSTAT, cAllocations, 8);
    295 /** Pointer to hypervisor heap statistics record. */
    296 typedef MMHYPERSTAT *PMMHYPERSTAT;
    297 
    298 /**
    299  * Hypervisor heap chunk.
    300  */
    301 typedef struct MMHYPERCHUNK
    302 {
    303     /** Previous block in the list of all blocks.
    304      * This is relative to the start of the heap. */
    305     uint32_t                offNext;
    306     /** Offset to the previous block relative to this one. */
    307     int32_t                 offPrev;
    308     /** The statistics record this allocation belongs to (self relative). */
    309     int32_t                 offStat;
    310     /** Offset to the heap block (self relative). */
    311     int32_t                 offHeap;
    312 } MMHYPERCHUNK;
    313 /** Pointer to a hypervisor heap chunk. */
    314 typedef MMHYPERCHUNK *PMMHYPERCHUNK;
    315 
    316 
    317 /**
    318  * Hypervisor heap chunk.
    319  */
    320 typedef struct MMHYPERCHUNKFREE
    321 {
    322     /** Main list. */
    323     MMHYPERCHUNK            core;
    324     /** Offset of the next chunk in the list of free nodes. */
    325     uint32_t                offNext;
    326     /** Offset of the previous chunk in the list of free nodes. */
    327     int32_t                 offPrev;
    328     /** Size of the block. */
    329     uint32_t                cb;
    330 } MMHYPERCHUNKFREE;
    331 /** Pointer to a free hypervisor heap chunk. */
    332 typedef MMHYPERCHUNKFREE *PMMHYPERCHUNKFREE;
    333 
    334 
    335 /**
    336  * The hypervisor heap.
    337  */
    338 typedef struct MMHYPERHEAP
    339 {
    340     /** The typical magic (MMHYPERHEAP_MAGIC). */
    341     uint32_t                u32Magic;
    342     /** The heap size. (This structure is not included!) */
    343     uint32_t                cbHeap;
    344     /** Lock protecting the heap. */
    345     PDMCRITSECT             Lock;
    346     /** The HC ring-3 address of the heap. */
    347     R3PTRTYPE(uint8_t *)    pbHeapR3;
    348     /** The HC ring-3 address of the shared VM structure. */
    349     PVMR3                   pVMR3;
    350     /** The HC ring-0 address of the heap. */
    351     R0PTRTYPE(uint8_t *)    pbHeapR0;
    352     /** The HC ring-0 address of the shared VM structure. */
    353     PVMR0                   pVMR0;
    354     /** The RC address of the heap. */
    355     RCPTRTYPE(uint8_t *)    pbHeapRC;
    356     /** The RC address of the shared VM structure. */
    357     PVMRC                   pVMRC;
    358     /** The amount of free memory in the heap. */
    359     uint32_t                cbFree;
    360     /** Offset of the first free chunk in the heap.
    361      * The offset is relative to the start of the heap. */
    362     uint32_t                offFreeHead;
    363     /** Offset of the last free chunk in the heap.
    364      * The offset is relative to the start of the heap. */
    365     uint32_t                offFreeTail;
    366     /** Offset of the first page aligned block in the heap.
    367      * The offset is equal to cbHeap initially. */
    368     uint32_t                offPageAligned;
    369     /** Tree of hypervisor heap statistics. */
    370     AVLOGCPHYSTREE          HyperHeapStatTree;
    371 #ifdef MMHYPER_HEAP_FREE_DELAY
    372     /** Where to insert the next free. */
    373     uint32_t                iDelayedFree;
    374     /** Array of delayed frees. Circular. Offsets relative to this structure. */
    375     struct
    376     {
    377         /** The free caller address. */
    378         RTUINTPTR           uCaller;
    379         /** The offset of the freed chunk. */
    380         uint32_t            offChunk;
    381     } aDelayedFrees[MMHYPER_HEAP_FREE_DELAY];
    382 #else
    383     /** Padding the structure to a 64-bit aligned size. */
    384     uint32_t                u32Padding0;
    385 #endif
    386     /** The heap physical pages. */
    387     R3PTRTYPE(PSUPPAGE)     paPages;
    388 #if HC_ARCH_BITS == 32
    389     /** Padding the structure to a 64-bit aligned size. */
    390     uint32_t                u32Padding1;
    391 #endif
    392 } MMHYPERHEAP;
    393 /** Pointer to the hypervisor heap. */
    394 typedef MMHYPERHEAP *PMMHYPERHEAP;
    395 
    396 /** Magic value for MMHYPERHEAP. (C. S. Lewis) */
    397 #define MMHYPERHEAP_MAGIC               UINT32_C(0x18981129)
    398 
    399 
    400 /**
    401  * Hypervisor heap minimum alignment (16 bytes).
    402  */
    403 #define MMHYPER_HEAP_ALIGN_MIN          16
    404 
    405 /**
    406  * The aligned size of the MMHYPERHEAP structure.
    407  */
    408 #define MMYPERHEAP_HDR_SIZE             RT_ALIGN_Z(sizeof(MMHYPERHEAP), MMHYPER_HEAP_ALIGN_MIN * 4)
    409 
    410 /** @name Hypervisor heap chunk flags.
    411  * The flags are put in the first bits of the MMHYPERCHUNK::offPrev member.
    412  * These bits aren't used anyway because of the chunk minimal alignment (16 bytes).
    413  * @{ */
    414 /** The chunk is free. (The code ASSUMES this is 0!) */
    415 #define MMHYPERCHUNK_FLAGS_FREE         0x0
    416 /** The chunk is in use. */
    417 #define MMHYPERCHUNK_FLAGS_USED         0x1
    418 /** The type mask. */
    419 #define MMHYPERCHUNK_FLAGS_TYPE_MASK    0x1
    420 /** The flag mask */
    421 #define MMHYPERCHUNK_FLAGS_MASK         0x1
    422 
    423 /** Checks if the chunk is free. */
    424 #define MMHYPERCHUNK_ISFREE(pChunk)                 ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_FREE )
    425 /** Checks if the chunk is used. */
    426 #define MMHYPERCHUNK_ISUSED(pChunk)                 ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_USED )
    427 /** Toggles FREE/USED flag of a chunk. */
    428 #define MMHYPERCHUNK_SET_TYPE(pChunk, type)         do { (pChunk)->offPrev = ((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_TYPE_MASK) | ((type) & MMHYPERCHUNK_FLAGS_TYPE_MASK); } while (0)
    429 
    430 /** Gets the prev offset without the flags. */
    431 #define MMHYPERCHUNK_GET_OFFPREV(pChunk)            ((int32_t)((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_MASK))
    432 /** Sets the prev offset without changing the flags. */
    433 #define MMHYPERCHUNK_SET_OFFPREV(pChunk, off)       do { (pChunk)->offPrev = (off) | ((pChunk)->offPrev & MMHYPERCHUNK_FLAGS_MASK); } while (0)
    434 #if 0
    435 /** Clears one or more flags. */
    436 #define MMHYPERCHUNK_FLAGS_OP_CLEAR(pChunk, fFlags) do { ((pChunk)->offPrev) &= ~((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
    437 /** Sets one or more flags. */
    438 #define MMHYPERCHUNK_FLAGS_OP_SET(pChunk, fFlags)   do { ((pChunk)->offPrev) |=  ((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
    439 /** Checks if one is set. */
    440 #define MMHYPERCHUNK_FLAGS_OP_ISSET(pChunk, fFlag)  (!!(((pChunk)->offPrev) & ((fFlag) & MMHYPERCHUNK_FLAGS_MASK)))
    441 #endif
    442 /** @} */
    443 
    444 /** @} */
    445 
    446 /**
    447  * Hypervisor memory mapping type.
    448  */
    449 typedef enum MMLOOKUPHYPERTYPE
    450 {
    451     /** Invalid record. This is used for record which are incomplete. */
    452     MMLOOKUPHYPERTYPE_INVALID = 0,
    453     /** Mapping of locked memory. */
    454     MMLOOKUPHYPERTYPE_LOCKED,
    455     /** Mapping of contiguous HC physical memory. */
    456     MMLOOKUPHYPERTYPE_HCPHYS,
    457     /** Mapping of contiguous GC physical memory. */
    458     MMLOOKUPHYPERTYPE_GCPHYS,
    459     /** Mapping of MMIO2 memory. */
    460     MMLOOKUPHYPERTYPE_MMIO2,
    461     /** Dynamic mapping area (MMR3HyperReserve).
    462      * A conversion will require to check what's in the page table for the pages. */
    463     MMLOOKUPHYPERTYPE_DYNAMIC
    464 } MMLOOKUPHYPERTYPE;
    465 
    466 /**
    467  * Lookup record for the hypervisor memory area.
    468  */
    469 typedef struct MMLOOKUPHYPER
    470 {
    471     /** Byte offset from the start of this record to the next.
    472      * If the value is NIL_OFFSET the chain is terminated. */
    473     int32_t                 offNext;
    474     /** Offset into the hypervisor memory area. */
    475     uint32_t                off;
    476     /** Size of this part. */
    477     uint32_t                cb;
    478     /** Locking type. */
    479     MMLOOKUPHYPERTYPE       enmType;
    480     /** Type specific data */
    481     union
    482     {
    483         /** Locked memory. */
    484         struct
    485         {
    486             /** Host context ring-3 pointer. */
    487             R3PTRTYPE(void *)       pvR3;
    488             /** Host context ring-0 pointer. Optional. */
    489             RTR0PTR                 pvR0;
    490             /** Pointer to an array containing the physical address of each page
    491              * (HOST_PAGE_SIZE). */
    492             R3PTRTYPE(PRTHCPHYS)    paHCPhysPages;
    493         } Locked;
    494 
    495         /** Contiguous physical memory. */
    496         struct
    497         {
    498             /** Host context ring-3 pointer. */
    499             R3PTRTYPE(void *)       pvR3;
    500             /** Host context ring-0 pointer. Optional. */
    501             RTR0PTR                 pvR0;
    502             /** HC physical address corresponding to pvR3/pvR0. */
    503             RTHCPHYS                HCPhys;
    504         } HCPhys;
    505 
    506         /** Contiguous guest physical memory. */
    507         struct
    508         {
    509             /** The memory address (Guest Context). */
    510             RTGCPHYS                GCPhys;
    511         } GCPhys;
    512 
    513         /** MMIO2 memory. */
    514         struct
    515         {
    516             /** The device instance owning the MMIO2 region. */
    517             PPDMDEVINSR3            pDevIns;
    518             /** The sub-device number. */
    519             uint32_t                iSubDev;
    520             /** The region number. */
    521             uint32_t                iRegion;
    522 #if HC_ARCH_BITS == 32
    523             /** Alignment padding. */
    524             uint32_t                uPadding;
    525 #endif
    526             /** The offset into the MMIO2 region. */
    527             RTGCPHYS                off;
    528         } MMIO2;
    529     } u;
    530     /** Description. */
    531     R3PTRTYPE(const char *) pszDesc;
    532 } MMLOOKUPHYPER;
    533 /** Pointer to a hypervisor memory lookup record. */
    534 typedef MMLOOKUPHYPER *PMMLOOKUPHYPER;
    535 
    536 
    537 /**
    538  * Converts a MM pointer into a VM pointer.
    539  * @returns Pointer to the VM structure the MM is part of.
    540  * @param   pMM   Pointer to MM instance data.
    541  */
    542 #define MM2VM(pMM)  ( (PVM)((uint8_t *)pMM - pMM->offVM) )
    543 
    544 
    545135/**
    546136 * MM Data (part of VM)
     
    548138typedef struct MM
    549139{
    550     /** Offset to the VM structure.
    551      * See MM2VM(). */
    552     RTINT                       offVM;
    553 
    554140    /** Set if MMR3InitPaging has been called. */
    555141    bool                        fDoneMMR3InitPaging;
    556     /** Set if PGM has been initialized and we can safely call PGMR3Map(). */
    557     bool                        fPGMInitialized;
    558 #if GC_ARCH_BITS == 64 || HC_ARCH_BITS == 64
    559     uint32_t                    u32Padding1; /**< alignment padding. */
    560 #endif
    561 
    562     /** Lookup list for the Hypervisor Memory Area.
    563      * The offset is relative to the start of the heap.
    564      * Use pHyperHeapR3, pHyperHeapR0 or pHypeRHeapRC to calculate the address.
    565      */
    566     RTUINT                      offLookupHyper;
    567 
    568     /** The offset of the next static mapping in the Hypervisor Memory Area. */
    569     RTUINT                      offHyperNextStatic;
    570     /** The size of the HMA.
    571      * Starts at 12MB and will be fixed late in the init process. */
    572     RTUINT                      cbHyperArea;
    573 
    574     /** Guest address of the Hypervisor Memory Area.
    575      * @remarks It's still a bit open whether this should be change to RTRCPTR or
    576      *          remain a RTGCPTR. */
    577     RTGCPTR                     pvHyperAreaGC;
    578 
    579     /** The hypervisor heap (GC Ptr). */
    580     RCPTRTYPE(PMMHYPERHEAP)     pHyperHeapRC;
    581 #if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 64
    582     uint32_t                    u32Padding2;
    583 #endif
    584 
    585     /** The hypervisor heap (R0 Ptr). */
    586     R0PTRTYPE(PMMHYPERHEAP)     pHyperHeapR0;
    587 
    588     /** The hypervisor heap (R3 Ptr). */
    589     R3PTRTYPE(PMMHYPERHEAP)     pHyperHeapR3;
     142    /** Padding. */
     143    bool                        afPadding1[7];
    590144
    591145    /** Size of the base RAM in bytes. (The CFGM RamSize value.) */
     
    609163    uint32_t                    cFixedPages;
    610164    /** Padding. */
    611     uint32_t                    u32Padding0;
     165    uint32_t                    u32Padding2;
    612166} MM;
    613167/** Pointer to MM Data (part of VM). */
     
    634188void mmR3HeapDestroy(PMMHEAP pHeap);
    635189
    636 int  mmR3HyperInit(PVM pVM);
    637 int  mmR3HyperTerm(PVM pVM);
    638 int  mmR3HyperInitPaging(PVM pVM);
    639 
    640190const char *mmGetTagName(MMTAG enmTag);
    641191
  • trunk/src/VBox/VMM/testcase/Makefile.kmk

    r93609 r93718  
    6161 ifdef VBOX_WITH_TESTCASES
    6262  if defined(VBOX_WITH_HARDENING) && "$(KBUILD_TARGET)" == "win"
    63 PROGRAMS += tstCFGMHardened tstVMREQHardened tstMMHyperHeapHardened tstAnimateHardened
    64 DLLS     += tstCFGM tstVMREQ tstMMHyperHeap tstAnimate
     63PROGRAMS += tstCFGMHardened tstVMREQHardened tstAnimateHardened
     64DLLS     += tstCFGM tstVMREQ tstAnimate
    6565  else
    66 PROGRAMS += tstCFGM tstVMREQ tstMMHyperHeap tstAnimate
     66PROGRAMS += tstCFGM tstVMREQ tstAnimate
    6767  endif
    6868PROGRAMS += \
     
    243243tstIEMCheckMc_CXXFLAGS  = $(VBOX_C_CXX_FLAGS_NO_UNUSED_PARAMETERS) -Wno-unused-value -Wno-unused-variable
    244244endif
    245 
    246 #
    247 # VMM heap testcase.
    248 #
    249 if defined(VBOX_WITH_HARDENING) && "$(KBUILD_TARGET)" == "win"
    250 tstMMHyperHeapHardened_TEMPLATE = VBoxR3HardenedTstExe
    251 tstMMHyperHeapHardened_NAME     = tstMMHyperHeap
    252  ifdef VBOX_WITH_AUTOMATIC_DEFS_QUOTING
    253 tstMMHyperHeapHardened_DEFS     = PROGRAM_NAME_STR="tstMMHyperHeap"
    254  else
    255 tstMMHyperHeapHardened_DEFS     = PROGRAM_NAME_STR=\"tstMMHyperHeap\"
    256  endif
    257 tstMMHyperHeapHardened_SOURCES  = ../../HostDrivers/Support/SUPR3HardenedMainTemplateTestcase.cpp
    258 tstMMHyperHeap_TEMPLATE = VBoxR3HardenedTstDll
    259 else
    260 tstMMHyperHeap_TEMPLATE = VBOXR3TSTEXE
    261 endif
    262 tstMMHyperHeap_DEFS     = $(VMM_COMMON_DEFS)
    263 tstMMHyperHeap_SOURCES  = tstMMHyperHeap.cpp
    264 tstMMHyperHeap_LIBS     = $(LIB_VMM) $(LIB_REM) $(LIB_RUNTIME)
    265245
    266246#
  • trunk/src/VBox/VMM/testcase/tstVMStructSize.cpp

    r93656 r93718  
    371371    CHECK_MEMBER_ALIGNMENT(PGM, CritSectX, sizeof(uintptr_t));
    372372    CHECK_MEMBER_ALIGNMENT(PDM, CritSect, sizeof(uintptr_t));
    373     CHECK_MEMBER_ALIGNMENT(MMHYPERHEAP, Lock, sizeof(uintptr_t));
    374373
    375374    /* hm - 32-bit gcc won't align uint64_t naturally, so check. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette