VirtualBox

Changeset 18431 in vbox


Ignore:
Timestamp:
Mar 28, 2009 2:10:03 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
45238
Message:

PDMLdr.cpp: Another annoying conversion warning, made the code paranoid while at it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PDMLdr.cpp

    r16933 r18431  
    460460         * Allocate space in the hypervisor.
    461461         */
    462         size_t      cb = RTLdrSize(pModule->hLdrMod);
     462        size_t          cb = RTLdrSize(pModule->hLdrMod);
    463463        cb = RT_ALIGN_Z(cb, PAGE_SIZE);
    464         uint32_t    cPages = cb >> PAGE_SHIFT;
    465         PSUPPAGE    paPages = (PSUPPAGE)RTMemTmpAlloc(cPages * sizeof(paPages[0]));
    466         if (paPages)
    467         {
    468             rc = SUPR3PageAllocEx(cPages, 0 /*fFlags*/, &pModule->pvBits, NULL /*pR0Ptr*/, paPages);
    469             if (RT_SUCCESS(rc))
    470             {
    471                 RTGCPTR GCPtr;
    472                 rc = MMR3HyperMapPages(pVM, pModule->pvBits, NIL_RTR0PTR,
    473                                        cPages, paPages, pModule->szName, &GCPtr);
     464        uint32_t        cPages = (uint32_t)(cb >> PAGE_SHIFT);
     465        if (((size_t)cPages << PAGE_SHIFT) == cb)
     466        {
     467            PSUPPAGE    paPages = (PSUPPAGE)RTMemTmpAlloc(cPages * sizeof(paPages[0]));
     468            if (paPages)
     469            {
     470                rc = SUPR3PageAllocEx(cPages, 0 /*fFlags*/, &pModule->pvBits, NULL /*pR0Ptr*/, paPages);
    474471                if (RT_SUCCESS(rc))
    475472                {
    476                     MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL);
    477 
    478                     /*
    479                      * Get relocated image bits.
    480                      */
    481                     Assert(MMHyperR3ToRC(pVM, pModule->pvBits) == GCPtr);
    482                     pModule->ImageBase = GCPtr;
    483                     PDMGETIMPORTARGS Args;
    484                     Args.pVM = pVM;
    485                     Args.pModule = pModule;
    486                     rc = RTLdrGetBits(pModule->hLdrMod, pModule->pvBits, pModule->ImageBase, pdmR3GetImportRC, &Args);
     473                    RTGCPTR GCPtr;
     474                    rc = MMR3HyperMapPages(pVM, pModule->pvBits, NIL_RTR0PTR,
     475                                           cPages, paPages, pModule->szName, &GCPtr);
    487476                    if (RT_SUCCESS(rc))
    488477                    {
     478                        MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL);
     479
    489480                        /*
    490                          * Insert the module.
     481                         * Get relocated image bits.
    491482                         */
    492                         PUVM pUVM = pVM->pUVM;
    493                         if (pUVM->pdm.s.pModules)
     483                        Assert(MMHyperR3ToRC(pVM, pModule->pvBits) == GCPtr);
     484                        pModule->ImageBase = GCPtr;
     485                        PDMGETIMPORTARGS Args;
     486                        Args.pVM = pVM;
     487                        Args.pModule = pModule;
     488                        rc = RTLdrGetBits(pModule->hLdrMod, pModule->pvBits, pModule->ImageBase, pdmR3GetImportRC, &Args);
     489                        if (RT_SUCCESS(rc))
    494490                        {
    495                             /* we don't expect this list to be very long, so rather save the tail pointer. */
    496                             PPDMMOD pCur = pUVM->pdm.s.pModules;
    497                             while (pCur->pNext)
    498                                 pCur = pCur->pNext;
    499                             pCur->pNext = pModule;
     491                            /*
     492                             * Insert the module.
     493                             */
     494                            PUVM pUVM = pVM->pUVM;
     495                            if (pUVM->pdm.s.pModules)
     496                            {
     497                                /* we don't expect this list to be very long, so rather save the tail pointer. */
     498                                PPDMMOD pCur = pUVM->pdm.s.pModules;
     499                                while (pCur->pNext)
     500                                    pCur = pCur->pNext;
     501                                pCur->pNext = pModule;
     502                            }
     503                            else
     504                                pUVM->pdm.s.pModules = pModule; /* (pNext is zeroed by alloc) */
     505                            Log(("PDM: RC Module at %RRv %s (%s)\n", (RTRCPTR)pModule->ImageBase, pszName, pszFilename));
     506                            RTMemTmpFree(pszFile);
     507                            RTMemTmpFree(paPages);
     508                            return VINF_SUCCESS;
    500509                        }
    501                         else
    502                             pUVM->pdm.s.pModules = pModule; /* (pNext is zeroed by alloc) */
    503                         Log(("PDM: RC Module at %RRv %s (%s)\n", (RTRCPTR)pModule->ImageBase, pszName, pszFilename));
    504                         RTMemTmpFree(pszFile);
    505                         RTMemTmpFree(paPages);
    506                         return VINF_SUCCESS;
     510                    }
     511                    else
     512                    {
     513                        AssertRC(rc);
     514                        SUPR3PageFreeEx(pModule->pvBits, cPages);
    507515                    }
    508516                }
    509517                else
    510                 {
    511                     AssertRC(rc);
    512                     SUPR3PageFreeEx(pModule->pvBits, cPages);
    513                 }
     518                    AssertMsgFailed(("SUPPageAlloc(%d,) -> %Rrc\n", cPages, rc));
     519                RTMemTmpFree(paPages);
    514520            }
    515521            else
    516                 AssertMsgFailed(("SUPPageAlloc(%d,) -> %Rrc\n", cPages, rc));
    517             RTMemTmpFree(paPages);
     522                rc = VERR_NO_TMP_MEMORY;
    518523        }
    519524        else
    520             rc = VERR_NO_TMP_MEMORY;
     525            rc = VERR_OUT_OF_RANGE;
    521526        int rc2 = RTLdrClose(pModule->hLdrMod);
    522527        AssertRC(rc2);
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