VirtualBox

Changeset 51271 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
May 16, 2014 12:08:42 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
93734
Message:

VMM: Implemented hyper heap realloc. and adjusted CPUM CpuId arrays and MSR ranges handling to optionally work with the hyper heap.

Location:
trunk/src/VBox/VMM
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/MMAllHyper.cpp

    r49893 r51271  
    342342/**
    343343 * Duplicates a block of memory.
     344 *
     345 * @returns VBox status code.
     346 * @param   pVM         Pointer to the VM.
     347 * @param   pvSrc       The source memory block to copy from.
     348 * @param   cb          Size of the source memory block.
     349 * @param   uAlignment  Required memory alignment in bytes.
     350 *                      Values are 0,8,16,32,64 and PAGE_SIZE.
     351 *                      0 -> default alignment, i.e. 8 bytes.
     352 * @param   enmTag      The statistics tag.
     353 * @param   ppv         Where to store the address to the allocated
     354 *                      memory.
    344355 */
    345356VMMDECL(int) MMHyperDupMem(PVM pVM, const void *pvSrc, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv)
  • trunk/src/VBox/VMM/VMMR3/CPUM.cpp

    r50873 r51271  
    776776         * MSR ranges).
    777777         */
    778         rc = cpumR3MsrRangesInsert(&pVM->cpum.s.GuestInfo.paMsrRangesR3, &pVM->cpum.s.GuestInfo.cMsrRanges, &MsrRange);
     778        rc = cpumR3MsrRangesInsert(NULL /* pVM */, &pVM->cpum.s.GuestInfo.paMsrRangesR3, &pVM->cpum.s.GuestInfo.cMsrRanges,
     779                                   &MsrRange);
    779780        if (RT_FAILURE(rc))
    780781            return VMSetError(pVM, rc, RT_SRC_POS, "Error adding MSR entry '%s': %Rrc\n", MsrRange.szName, rc);
     
    870871         * Insert the leaf into the table (replaces existing ones).
    871872         */
    872         rc = cpumR3CpuIdInsert(&pVM->cpum.s.GuestInfo.paCpuIdLeavesR3, &pVM->cpum.s.GuestInfo.cCpuIdLeaves, &Leaf);
     873        rc = cpumR3CpuIdInsert(NULL /* pVM */, &pVM->cpum.s.GuestInfo.paCpuIdLeavesR3, &pVM->cpum.s.GuestInfo.cCpuIdLeaves,
     874                               &Leaf);
    873875        if (RT_FAILURE(rc))
    874876            return VMSetError(pVM, rc, RT_SRC_POS, "Error adding CPUID leaf entry '%s': %Rrc\n", szName, rc);
     
    976978
    977979    AssertLogRelRCReturn(rc, rc);
     980
    978981
    979982    pCPUM->GuestInfo.paCpuIdLeavesR0 = MMHyperR3ToR0(pVM, pCPUM->GuestInfo.paCpuIdLeavesR3);
     
    14671470        }
    14681471#endif
    1469         rc = cpumR3CpuIdInsert(&pCPUM->GuestInfo.paCpuIdLeavesR3, &pCPUM->GuestInfo.cCpuIdLeaves, &NewLeaf);
     1472        rc = cpumR3CpuIdInsert(NULL /* pVM */, &pCPUM->GuestInfo.paCpuIdLeavesR3, &pCPUM->GuestInfo.cCpuIdLeaves, &NewLeaf);
    14701473        AssertLogRelRCReturn(rc, rc);
    14711474    }
     
    16681671    NewLeaf.uEdx         = 0x786f4256 /* 'VBox' */;
    16691672    NewLeaf.fFlags       = 0;
    1670     rc = cpumR3CpuIdInsert(&pCPUM->GuestInfo.paCpuIdLeavesR3, &pCPUM->GuestInfo.cCpuIdLeaves, &NewLeaf);
     1673    rc = cpumR3CpuIdInsert(NULL /* pVM */, &pCPUM->GuestInfo.paCpuIdLeavesR3, &pCPUM->GuestInfo.cCpuIdLeaves, &NewLeaf);
    16711674    AssertLogRelRCReturn(rc, rc);
    16721675
     
    16771680    NewLeaf.uEdx         = 0;
    16781681    NewLeaf.fFlags       = 0;
    1679     rc = cpumR3CpuIdInsert(&pCPUM->GuestInfo.paCpuIdLeavesR3, &pCPUM->GuestInfo.cCpuIdLeaves, &NewLeaf);
     1682    rc = cpumR3CpuIdInsert(NULL /* pVM */, &pCPUM->GuestInfo.paCpuIdLeavesR3, &pCPUM->GuestInfo.cCpuIdLeaves, &NewLeaf);
    16801683    AssertLogRelRCReturn(rc, rc);
    16811684
     
    20682071                NewLeaf.uEdx            = CpuId.edx;
    20692072                NewLeaf.fFlags          = 0;
    2070                 rc = cpumR3CpuIdInsert(ppaLeaves, pcLeaves, &NewLeaf);
     2073                rc = cpumR3CpuIdInsert(NULL /* pVM */, ppaLeaves, pcLeaves, &NewLeaf);
    20712074            }
    20722075        }
     
    47174720    LogRel(("******************** End of CPUID dump **********************\n"));
    47184721}
     4722
  • trunk/src/VBox/VMM/VMMR3/CPUMR3CpuId.cpp

    r50607 r51271  
    2323#include "CPUMInternal.h"
    2424#include <VBox/vmm/vm.h>
     25#include <VBox/vmm/mm.h>
    2526
    2627#include <VBox/err.h>
     
    553554 * @returns Pointer to the CPUID leaf array (*ppaLeaves) on success.  NULL on
    554555 *          failure.
    555  * @param   ppaLeaves           Pointer to the variable holding the array
    556  *                              pointer (input/output).
    557  * @param   cLeaves             The current array size.
    558  */
    559 static PCPUMCPUIDLEAF cpumR3CpuIdEnsureSpace(PCPUMCPUIDLEAF *ppaLeaves, uint32_t cLeaves)
     556 * @param   pVM         Pointer to the VM, used as the heap selector. Passing
     557 *                      NULL uses the host-context heap, otherwise the VM's
     558 *                      hyper heap is used.
     559 * @param   ppaLeaves   Pointer to the variable holding the array pointer
     560 *                      (input/output).
     561 * @param   cLeaves     The current array size.
     562 *
     563 * @remarks This function will automatically update the R0 and RC pointers when
     564 *          using the hyper heap, which means @a ppaLeaves and @a cLeaves must
     565 *          be the corresponding VM's CPUID arrays (which is asserted).
     566 */
     567static PCPUMCPUIDLEAF cpumR3CpuIdEnsureSpace(PVM pVM, PCPUMCPUIDLEAF *ppaLeaves, uint32_t cLeaves)
    560568{
    561569    uint32_t cAllocated = RT_ALIGN(cLeaves, 16);
    562570    if (cLeaves + 1 > cAllocated)
    563571    {
    564         void *pvNew = RTMemRealloc(*ppaLeaves, (cAllocated + 16) * sizeof(**ppaLeaves));
    565         if (!pvNew)
    566         {
    567             RTMemFree(*ppaLeaves);
    568             *ppaLeaves = NULL;
    569             return NULL;
     572        void *pvNew;
     573#ifndef IN_VBOX_CPU_REPORT
     574        if (pVM)
     575        {
     576            Assert(ppaLeaves == &pVM->cpum.s.GuestInfo.paCpuIdLeavesR3);
     577            Assert(cLeaves == pVM->cpum.s.GuestInfo.cCpuIdLeaves);
     578
     579            size_t cb    = cAllocated * sizeof(**ppaLeaves);
     580            size_t cbNew = (cAllocated + 16) * sizeof(**ppaLeaves);
     581            int rc = MMR3HyperRealloc(pVM, *ppaLeaves, cb, 32, MM_TAG_CPUM_CPUID, cbNew, &pvNew);
     582            if (RT_FAILURE(rc))
     583            {
     584                *ppaLeaves = NULL;
     585                pVM->cpum.s.GuestInfo.paCpuIdLeavesR0 = NIL_RTR0PTR;
     586                pVM->cpum.s.GuestInfo.paCpuIdLeavesRC = NIL_RTRCPTR;
     587                return NULL;
     588            }
     589
     590            /* Update the R0 and RC pointers. */
     591            pVM->cpum.s.GuestInfo.paCpuIdLeavesR0 = MMHyperR3ToR0(pVM, *ppaLeaves);
     592            pVM->cpum.s.GuestInfo.paCpuIdLeavesRC = MMHyperR3ToRC(pVM, *ppaLeaves);
     593        }
     594        else
     595#endif
     596        {
     597            pvNew = RTMemRealloc(*ppaLeaves, (cAllocated + 16) * sizeof(**ppaLeaves));
     598            if (!pvNew)
     599            {
     600                RTMemFree(*ppaLeaves);
     601                *ppaLeaves = NULL;
     602                return NULL;
     603            }
    570604        }
    571605        *ppaLeaves   = (PCPUMCPUIDLEAF)pvNew;
     
    579613 *
    580614 * ASSUMES linear insertion order, so we'll won't need to do any searching or
    581  * replace anything.  Use cpumR3CpuIdInsert for those cases.
     615 * replace anything.  Use cpumR3CpuIdInsert() for those cases.
    582616 *
    583617 * @returns VINF_SUCCESS or VERR_NO_MEMORY.  On error, *ppaLeaves is freed, so
     
    599633                                        uint32_t uEax, uint32_t uEbx, uint32_t uEcx, uint32_t uEdx, uint32_t fFlags)
    600634{
    601     if (!cpumR3CpuIdEnsureSpace(ppaLeaves, *pcLeaves))
     635    if (!cpumR3CpuIdEnsureSpace(NULL /* pVM */, ppaLeaves, *pcLeaves))
    602636        return VERR_NO_MEMORY;
    603637
     
    627661 * the same leaf number (eax), the simple leaf will replace the whole series.
    628662 *
    629  * This ASSUMES that the leave array is still on the normal heap and has only
    630  * been allocated/reallocated by the cpumR3CpuIdEnsureSpace function.
     663 * When pVM is NULL, this ASSUMES that the leaves array is still on the normal
     664 * host-context heap and has only been allocated/reallocated by the
     665 * cpumR3CpuIdEnsureSpace function.
    631666 *
    632667 * @returns VBox status code.
     668 * @param   pVM             Pointer to the VM, used as the heap selector.
     669 *                          Passing NULL uses the host-context heap, otherwise
     670 *                          the VM's hyper heap is used.
    633671 * @param   ppaLeaves       Pointer to the the pointer to the array of sorted
    634  *                          CPUID leaves and sub-leaves.
    635  * @param   pcLeaves        Where we keep the leaf count for *ppaLeaves.
     672 *                          CPUID leaves and sub-leaves. Must be NULL if using
     673 *                          the hyper heap.
     674 * @param   pcLeaves        Where we keep the leaf count for *ppaLeaves. Must be
     675 *                          NULL if using the hyper heap.
    636676 * @param   pNewLeaf        Pointer to the data of the new leaf we're about to
    637677 *                          insert.
    638678 */
    639 int cpumR3CpuIdInsert(PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves, PCPUMCPUIDLEAF pNewLeaf)
     679int cpumR3CpuIdInsert(PVM pVM, PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves, PCPUMCPUIDLEAF pNewLeaf)
    640680{
    641681    PCPUMCPUIDLEAF  paLeaves = *ppaLeaves;
    642682    uint32_t        cLeaves  = *pcLeaves;
     683
     684    /*
     685     * Validate input parameters if we are using the hyper heap and use the VM's CPUID arrays.
     686     */
     687    if (pVM)
     688    {
     689        AssertReturn(!ppaLeaves, VERR_INVALID_PARAMETER);
     690        AssertReturn(!pcLeaves, VERR_INVALID_PARAMETER);
     691
     692        ppaLeaves = &pVM->cpum.s.GuestInfo.paCpuIdLeavesR3;
     693        pcLeaves  = &pVM->cpum.s.GuestInfo.cCpuIdLeaves;
     694    }
    643695
    644696    /*
     
    649701    AssertReturn(RT_IS_POWER_OF_TWO(pNewLeaf->fSubLeafMask + 1), VERR_INVALID_PARAMETER);
    650702    AssertReturn((pNewLeaf->fSubLeafMask & pNewLeaf->uSubLeaf) == pNewLeaf->uSubLeaf, VERR_INVALID_PARAMETER);
    651 
    652703
    653704    /*
     
    701752     * Adding a new leaf at 'i'.
    702753     */
    703     paLeaves = cpumR3CpuIdEnsureSpace(ppaLeaves, cLeaves);
     754    paLeaves = cpumR3CpuIdEnsureSpace(pVM, ppaLeaves, cLeaves);
    704755    if (!paLeaves)
    705756        return VERR_NO_MEMORY;
     
    864915    return true;
    865916}
     917
     918
     919#if 0
     920/**
     921 * Inserts a CPU ID leaf, replacing any existing ones.
     922 *
     923 * @returns VBox status code.
     924 * @param   pVM         Pointer to the VM.
     925 * @param   pNewLeaf    Pointer to the leaf being inserted.
     926 */
     927VMMR3DECL(int) CPUMR3CpuIdInsert(PVM pVM, PCPUMCPUIDLEAF pNewLeaf)
     928{
     929    /** @todo Should we disallow here inserting/replacing the standard leaves that
     930     *        PATM relies on? See @bugref{7270}. */
     931    return cpumR3CpuIdInsert(pVM, NULL /* ppaLeaves */, NULL /* pcLeaves */, pNewLeaf);
     932}
     933#endif
    866934
    867935
  • trunk/src/VBox/VMM/VMMR3/CPUMR3Db.cpp

    r50656 r51271  
    2323#include "CPUMInternal.h"
    2424#include <VBox/vmm/vm.h>
     25#include <VBox/vmm/mm.h>
    2526
    2627#include <VBox/err.h>
     
    297298 * @returns Pointer to the MSR ranges on success, NULL on failure.  On failure
    298299 *          @a *ppaMsrRanges is freed and set to NULL.
     300 * @param   pVM             Pointer to the VM, used as the heap selector.
     301 *                          Passing NULL uses the host-context heap, otherwise
     302 *                          the VM's hyper heap is used.
    299303 * @param   ppaMsrRanges    The variable pointing to the ranges (input/output).
    300304 * @param   cMsrRanges      The current number of ranges.
    301305 * @param   cNewRanges      The number of ranges to be added.
    302306 */
    303 static PCPUMMSRRANGE cpumR3MsrRangesEnsureSpace(PCPUMMSRRANGE *ppaMsrRanges, uint32_t cMsrRanges, uint32_t cNewRanges)
     307static PCPUMMSRRANGE cpumR3MsrRangesEnsureSpace(PVM pVM, PCPUMMSRRANGE *ppaMsrRanges, uint32_t cMsrRanges, uint32_t cNewRanges)
    304308{
    305309    uint32_t cMsrRangesAllocated = RT_ALIGN_32(cMsrRanges, 16);
    306310    if (cMsrRangesAllocated < cMsrRanges + cNewRanges)
    307311    {
     312        void    *pvNew;
    308313        uint32_t cNew = RT_ALIGN_32(cMsrRanges + cNewRanges, 16);
    309         void *pvNew = RTMemRealloc(*ppaMsrRanges, cNew * sizeof(**ppaMsrRanges));
    310         if (!pvNew)
    311         {
    312             RTMemFree(*ppaMsrRanges);
    313             *ppaMsrRanges = NULL;
    314             return NULL;
     314        if (pVM)
     315        {
     316            Assert(ppaMsrRanges == &pVM->cpum.s.GuestInfo.paMsrRangesR3);
     317            Assert(cMsrRanges   == pVM->cpum.s.GuestInfo.cMsrRanges);
     318
     319            size_t cb    = cMsrRangesAllocated * sizeof(**ppaMsrRanges);
     320            size_t cbNew = cNew * sizeof(**ppaMsrRanges);
     321            int rc = MMR3HyperRealloc(pVM, *ppaMsrRanges, cb, 32, MM_TAG_CPUM_MSRS, cbNew, &pvNew);
     322            if (RT_FAILURE(rc))
     323            {
     324                *ppaMsrRanges = NULL;
     325                pVM->cpum.s.GuestInfo.paMsrRangesR0 = NIL_RTR0PTR;
     326                pVM->cpum.s.GuestInfo.paMsrRangesRC = NIL_RTRCPTR;
     327                return NULL;
     328            }
     329
     330            pVM->cpum.s.GuestInfo.paMsrRangesR0 = MMHyperR3ToR0(pVM, *ppaMsrRanges);
     331            pVM->cpum.s.GuestInfo.paMsrRangesR0 = MMHyperR3ToRC(pVM, *ppaMsrRanges);
     332            /** @todo Update R0 and RC pointers here?  */
     333        }
     334        else
     335        {
     336            pvNew = RTMemRealloc(*ppaMsrRanges, cNew * sizeof(**ppaMsrRanges));
     337            if (!pvNew)
     338            {
     339                RTMemFree(*ppaMsrRanges);
     340                *ppaMsrRanges = NULL;
     341                return NULL;
     342            }
    315343        }
    316344        *ppaMsrRanges = (PCPUMMSRRANGE)pvNew;
     
    330358 * @retval  VERR_NO_MEMORY
    331359 *
     360 * @param   pVM             Pointer to the VM, used as the heap selector.
     361 *                          Passing NULL uses the host-context heap, otherwise
     362 *                          the hyper heap.
    332363 * @param   ppaMsrRanges    The variable pointing to the ranges (input/output).
    333  * @param   pcMsrRanges     The variable holding number of ranges.
     364 *                          Must be NULL if using the hyper heap.
     365 * @param   pcMsrRanges     The variable holding number of ranges. Must be NULL
     366 *                          if using the hyper heap.
    334367 * @param   pNewRange       The new range.
    335368 */
    336 int cpumR3MsrRangesInsert(PCPUMMSRRANGE *ppaMsrRanges, uint32_t *pcMsrRanges, PCCPUMMSRRANGE pNewRange)
     369int cpumR3MsrRangesInsert(PVM pVM, PCPUMMSRRANGE *ppaMsrRanges, uint32_t *pcMsrRanges, PCCPUMMSRRANGE pNewRange)
    337370{
    338371    uint32_t        cMsrRanges  = *pcMsrRanges;
     
    342375    Assert(pNewRange->enmRdFn > kCpumMsrRdFn_Invalid && pNewRange->enmRdFn < kCpumMsrRdFn_End);
    343376    Assert(pNewRange->enmWrFn > kCpumMsrWrFn_Invalid && pNewRange->enmWrFn < kCpumMsrWrFn_End);
     377
     378    /*
     379     * Validate and use the VM's MSR ranges array if we are using the hyper heap.
     380     */
     381    if (pVM)
     382    {
     383        AssertReturn(!ppaMsrRanges, VERR_INVALID_PARAMETER);
     384        AssertReturn(!pcMsrRanges,  VERR_INVALID_PARAMETER);
     385
     386        ppaMsrRanges = &pVM->cpum.s.GuestInfo.paMsrRangesR3;
     387        pcMsrRanges  = &pVM->cpum.s.GuestInfo.cMsrRanges;
     388    }
    344389
    345390    /*
     
    349394        && paMsrRanges[cMsrRanges - 1].uLast < pNewRange->uFirst)
    350395    {
    351         paMsrRanges = cpumR3MsrRangesEnsureSpace(ppaMsrRanges, cMsrRanges, 1);
     396        paMsrRanges = cpumR3MsrRangesEnsureSpace(pVM, ppaMsrRanges, cMsrRanges, 1);
    352397        if (!paMsrRanges)
    353398            return VERR_NO_MEMORY;
     
    367412            || pNewRange->uLast < paMsrRanges[i].uFirst)
    368413        {
    369             paMsrRanges = cpumR3MsrRangesEnsureSpace(ppaMsrRanges, cMsrRanges, 1);
     414            paMsrRanges = cpumR3MsrRangesEnsureSpace(pVM, ppaMsrRanges, cMsrRanges, 1);
    370415            if (!paMsrRanges)
    371416                return VERR_NO_MEMORY;
     
    387432                 && pNewRange->uLast  < paMsrRanges[i].uLast)
    388433        {
    389             paMsrRanges = cpumR3MsrRangesEnsureSpace(ppaMsrRanges, cMsrRanges, 2);
     434            paMsrRanges = cpumR3MsrRangesEnsureSpace(pVM, ppaMsrRanges, cMsrRanges, 2);
    390435            if (!paMsrRanges)
    391436                return VERR_NO_MEMORY;
     
    447492
    448493            /* Now, perform a normal insertion. */
    449             paMsrRanges = cpumR3MsrRangesEnsureSpace(ppaMsrRanges, cMsrRanges, 1);
     494            paMsrRanges = cpumR3MsrRangesEnsureSpace(pVM, ppaMsrRanges, cMsrRanges, 1);
    450495            if (!paMsrRanges)
    451496                return VERR_NO_MEMORY;
     
    475520        {
    476521            LogRel(("CPUM: MSR fudge: %#010x %s\n", paRanges[i].uFirst, paRanges[i].szName));
    477             int rc = cpumR3MsrRangesInsert(&pVM->cpum.s.GuestInfo.paMsrRangesR3, &pVM->cpum.s.GuestInfo.cMsrRanges,
     522            int rc = cpumR3MsrRangesInsert(pVM, &pVM->cpum.s.GuestInfo.paMsrRangesR3, &pVM->cpum.s.GuestInfo.cMsrRanges,
    478523                                           &paRanges[i]);
    479524            if (RT_FAILURE(rc))
     
    694739    while (cLeft-- > 0)
    695740    {
    696         rc = cpumR3MsrRangesInsert(&paMsrs, &cMsrs, pCurMsr);
     741        rc = cpumR3MsrRangesInsert(NULL /* pVM */, &paMsrs, &cMsrs, pCurMsr);
    697742        if (RT_FAILURE(rc))
    698743        {
     
    709754    return VINF_SUCCESS;
    710755}
     756
     757
     758#if 0
     759/**
     760 * Insert an MSR range into the VM.
     761 *
     762 * If the new MSR range overlaps existing ranges, the existing ones will be
     763 * adjusted/removed to fit in the new one.
     764 *
     765 * @returns VBox status code.
     766 * @param   pVM                 Pointer to the cross context VM structure.
     767 * @param   pNewRange           Pointer to the MSR range being inserted.
     768 */
     769VMMR3DECL(int) CPUMR3MsrRangesInsert(PVM pVM, PCCPUMMSRRANGE pNewRange)
     770{
     771    return cpumR3MsrRangesInsert(pVM, NULL /* ppaMsrRanges */, NULL /* pcMsrRanges */, pNewRange);
     772}
     773#endif
    711774
    712775
  • trunk/src/VBox/VMM/VMMR3/MMHyper.cpp

    r50113 r51271  
    14371437}
    14381438
     1439
     1440/**
     1441 * Re-allocates memory from the hyper heap.
     1442 *
     1443 * @returns VBox status code.
     1444 * @param   pVM             Pointer to the VM.
     1445 * @param   pvOld           The existing block of memory in the
     1446 *                          hyper heap to re-allocate (can be
     1447 *                          NULL).
     1448 * @param   cbOld           Size of the existing block.
     1449 * @param   uAlignmentNew   Required memory alignment in bytes.
     1450 *                          Values are 0,8,16,32 and PAGE_SIZE.
     1451 *                          0 -> default alignment, i.e. 8 bytes.
     1452 * @param   enmTagNew       The statistics tag.
     1453 * @param   cbNew           The required size of the new block.
     1454 * @param   ppv             Where to store the address to the
     1455 *                          re-allocated block.
     1456 *
     1457 * @remarks This does not work like normal realloc()
     1458 *          on failure, the memory pointed to by @a pvOld is
     1459 *          lost if there isn't sufficient space on the hyper
     1460 *          heap for the re-allocation to succeed.
     1461*/
     1462VMMR3DECL(int) MMR3HyperRealloc(PVM pVM, void *pvOld, size_t cbOld, unsigned uAlignmentNew, MMTAG enmTagNew, size_t cbNew,
     1463                                void **ppv)
     1464{
     1465    if (!pvOld)
     1466        return MMHyperAlloc(pVM, cbNew, uAlignmentNew, enmTagNew, ppv);
     1467
     1468    if (!cbNew && pvOld)
     1469        return MMHyperFree(pVM, pvOld);
     1470
     1471    if (cbOld == cbNew)
     1472        return VINF_SUCCESS;
     1473
     1474    size_t cbData = RT_MIN(cbNew, cbOld);
     1475    void *pvTmp = RTMemTmpAlloc(cbData);
     1476    if (RT_UNLIKELY(!pvTmp))
     1477    {
     1478        MMHyperFree(pVM, pvOld);
     1479        return VERR_NO_TMP_MEMORY;
     1480    }
     1481    memcpy(pvTmp, pvOld, cbData);
     1482
     1483    int rc = MMHyperFree(pVM, pvOld);
     1484    if (RT_SUCCESS(rc))
     1485    {
     1486        rc = MMHyperAlloc(pVM, cbNew, uAlignmentNew, enmTagNew, ppv);
     1487        if (RT_SUCCESS(rc))
     1488        {
     1489            Assert(cbData <= cbNew);
     1490            memcpy(*ppv, pvTmp, cbData);
     1491        }
     1492    }
     1493    else
     1494        AssertMsgFailed(("Failed to free hyper heap block pvOld=%p cbOld=%u\n", pvOld, cbOld));
     1495
     1496    RTMemTmpFree(pvTmp);
     1497    return rc;
     1498}
     1499
  • trunk/src/VBox/VMM/include/CPUMInternal.h

    r50617 r51271  
    11151115bool                cpumR3CpuIdGetLeafLegacy(PCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, uint32_t uLeaf, uint32_t uSubLeaf,
    11161116                                             PCPUMCPUID pLeagcy);
    1117 int                 cpumR3CpuIdInsert(PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves, PCPUMCPUIDLEAF pNewLeaf);
     1117int                 cpumR3CpuIdInsert(PVM pVM, PCPUMCPUIDLEAF *ppaLeaves, uint32_t *pcLeaves, PCPUMCPUIDLEAF pNewLeaf);
    11181118void                cpumR3CpuIdRemoveRange(PCPUMCPUIDLEAF paLeaves, uint32_t *pcLeaves, uint32_t uFirst, uint32_t uLast);
    11191119int                 cpumR3CpuIdExplodeFeatures(PCCPUMCPUIDLEAF paLeaves, uint32_t cLeaves, PCPUMFEATURES pFeatures);
    11201120int                 cpumR3DbGetCpuInfo(const char *pszName, PCPUMINFO pInfo);
    1121 int                 cpumR3MsrRangesInsert(PCPUMMSRRANGE *ppaMsrRanges, uint32_t *pcMsrRanges, PCCPUMMSRRANGE pNewRange);
     1121int                 cpumR3MsrRangesInsert(PVM pVM, PCPUMMSRRANGE *ppaMsrRanges, uint32_t *pcMsrRanges, PCCPUMMSRRANGE pNewRange);
    11221122int                 cpumR3MsrApplyFudge(PVM pVM);
    11231123int                 cpumR3MsrRegStats(PVM pVM);
Note: See TracChangeset for help on using the changeset viewer.

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