VirtualBox

Changeset 24272 in vbox for trunk/src


Ignore:
Timestamp:
Nov 2, 2009 4:44:27 PM (15 years ago)
Author:
vboxsync
Message:

PDMDevice.cpp: Check the number of devices instances against the max number.

File:
1 edited

Legend:

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

    r23077 r24272  
    209209
    210210        /* Enumerate the device instances. */
     211        uint32_t const iStart = i;
    211212        for (pInstanceNode = CFGMR3GetFirstChild(pCur); pInstanceNode; pInstanceNode = CFGMR3GetNextChild(pInstanceNode))
    212213        {
     
    227228            i++;
    228229        }
     230
     231        /* check the number of instances */
     232        if (i - iStart > pDev->pDevReg->cMaxInstances)
     233            AssertLogRelMsgFailedReturn(("Configuration error: Too many instances of %s was configured: %u, max %u\n",
     234                                         szName, i - iStart, pDev->pDevReg->cMaxInstances),
     235                                        VERR_PDM_TOO_MANY_DEVICE_INSTANCES);
    229236    } /* devices */
    230237    Assert(i == cDevs);
     
    285292         * Allocate the device instance.
    286293         */
     294        AssertReturn(paDevs[i].pDev->cInstances < paDevs[i].pDev->pDevReg->cMaxInstances, VERR_PDM_TOO_MANY_DEVICE_INSTANCES);
    287295        size_t cb = RT_OFFSETOF(PDMDEVINS, achInstanceData[paDevs[i].pDev->pDevReg->cbInstance]);
    288296        cb = RT_ALIGN_Z(cb, 16);
     
    357365         * Call the constructor.
    358366         */
     367        paDevs[i].pDev->cInstances++;
    359368        Log(("PDM: Constructing device '%s' instance %d...\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance));
    360369        rc = pDevIns->pDevReg->pfnConstruct(pDevIns, pDevIns->iInstance, pDevIns->pCfgHandle);
     
    362371        {
    363372            LogRel(("PDM: Failed to construct '%s'/%d! %Rra\n", pDevIns->pDevReg->szDeviceName, pDevIns->iInstance, rc));
     373            paDevs[i].pDev->cInstances--;
    364374            /* because we're damn lazy right now, we'll say that the destructor will be called even if the constructor fails. */
    365375            return rc;
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