VirtualBox

Changeset 62177 in vbox


Ignore:
Timestamp:
Jul 12, 2016 8:27:21 AM (8 years ago)
Author:
vboxsync
Message:

use RTHandleTable to maintain handles

Location:
trunk/src/VBox/HostDrivers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.cpp

    r61843 r62177  
    468468    /* VBoxUSB */
    469469    (PFNRT)RTPathStripFilename,
     470    (PFNRT)RTHandleTableAlloc,
    470471#if !defined(RT_OS_FREEBSD)
    471472    (PFNRT)RTStrPurgeEncoding,
  • trunk/src/VBox/HostDrivers/VBoxUSB/VBoxUSBFilterMgr.cpp

    r58340 r62177  
    2323#include "VBoxUSBFilterMgr.h"
    2424
     25#include <iprt/handletable.h>
    2526#include <iprt/mem.h>
    2627#ifdef VBOXUSBFILTERMGR_USB_SPINLOCK
     
    7778{
    7879    /** The core filter. */
    79     USBFILTER       Core;
     80    USBFILTER             Core;
    8081    /** The filter owner. */
    81     VBOXUSBFILTER_CONTEXT       Owner;
     82    VBOXUSBFILTER_CONTEXT Owner;
    8283    /** The filter Id. */
    83     uintptr_t       uId;
     84    uint32_t              uHnd;
    8485    /** Pointer to the next filter in the list. */
    85     PVBOXUSBFILTER  pNext;
     86    PVBOXUSBFILTER        pNext;
    8687} VBOXUSBFILTER;
    8788
     
    113114 * @remark The first entry is empty (USBFILTERTYPE_INVALID). */
    114115static VBOXUSBFILTERLIST    g_aLists[USBFILTERTYPE_END];
     116/** The handle table to match handles to the right filter. */
     117static RTHANDLETABLE        g_hHndTableFilters = NIL_RTHANDLETABLE;
    115118
    116119
     
    130133    if (RT_SUCCESS(rc))
    131134    {
    132         /* not really required, but anyway... */
    133         for (unsigned i = USBFILTERTYPE_FIRST; i < RT_ELEMENTS(g_aLists); i++)
    134             g_aLists[i].pHead = g_aLists[i].pTail = NULL;
     135        uint32_t fFlags;
     136#ifdef VBOXUSBFILTERMGR_USB_SPINLOCK
     137        fFlags = RTHANDLETABLE_FLAGS_LOCKED_IRQ_SAFE;
     138#else
     139        fFlags = RTHANDLETABLE_FLAGS_LOCKED;
     140#endif
     141        rc = RTHandleTableCreateEx(&g_hHndTableFilters, fFlags, 1 /* uBase */, 32768 /* cMax */,
     142                                   NULL, NULL);
     143        if (RT_SUCCESS(rc))
     144        {
     145            /* not really required, but anyway... */
     146            for (unsigned i = USBFILTERTYPE_FIRST; i < RT_ELEMENTS(g_aLists); i++)
     147                g_aLists[i].pHead = g_aLists[i].pTail = NULL;
     148        }
     149        else
     150        {
     151#ifdef VBOXUSBFILTERMGR_USB_SPINLOCK
     152            RTSpinlockDestroy(g_Spinlock);
     153            g_Spinlock = NIL_RTSPINLOCK;
     154#else
     155            RTSemFastMutexDestroy(g_Mtx);
     156            g_Mtx = NIL_RTSEMFASTMUTEX;
     157#endif
     158        }
    135159    }
    136160    return rc;
     
    172196        {
    173197            PVBOXUSBFILTER pNext = pCur->pNext;
     198            RTHandleTableFree(g_hHndTableFilters, pCur->uHnd);
    174199            vboxUSBFilterFree(pCur);
    175200            pCur = pNext;
    176201        }
    177202    }
     203
     204    RTHandleTableDestroy(g_hHndTableFilters, NULL, NULL);
    178205}
    179206
     
    210237    memcpy(&pNew->Core, pFilter, sizeof(pNew->Core));
    211238    pNew->Owner = Owner;
    212     pNew->uId   = (uintptr_t)pNew;
    213239    pNew->pNext = NULL;
    214240
    215     *puId = pNew->uId;
    216 
    217     /*
    218      * Insert it.
    219      */
    220     PVBOXUSBFILTERLIST pList = &g_aLists[pFilter->enmType];
    221 
    222     VBOXUSBFILTERMGR_LOCK();
    223 
    224     if (pList->pTail)
    225         pList->pTail->pNext = pNew;
    226     else
    227         pList->pHead = pNew;
    228     pList->pTail = pNew;
    229 
    230     VBOXUSBFILTERMGR_UNLOCK();
    231 
    232     return VINF_SUCCESS;
     241    rc = RTHandleTableAlloc(g_hHndTableFilters, pNew, &pNew->uHnd);
     242    if (RT_SUCCESS(rc))
     243    {
     244        *puId = pNew->uHnd;
     245
     246        /*
     247         * Insert it.
     248         */
     249        PVBOXUSBFILTERLIST pList = &g_aLists[pFilter->enmType];
     250
     251        VBOXUSBFILTERMGR_LOCK();
     252
     253        if (pList->pTail)
     254            pList->pTail->pNext = pNew;
     255        else
     256            pList->pHead = pNew;
     257        pList->pTail = pNew;
     258
     259        VBOXUSBFILTERMGR_UNLOCK();
     260    }
     261
     262    return rc;
    233263}
    234264
     
    252282     * Validate input.
    253283     */
    254     if (!uId)
     284    if (!uId || uId != (uint32_t)uId)
    255285        return VERR_INVALID_PARAMETER;
    256286    if (!Owner || Owner == VBOXUSBFILTER_CONTEXT_NIL)
     
    260290     * Locate and unlink it.
    261291     */
     292    uint32_t uHnd = (uint32_t)uId;
    262293    PVBOXUSBFILTER pCur = NULL;
    263294
     
    270301        while (pCur)
    271302        {
    272             if (    pCur->uId == uId
     303            if (    pCur->uHnd == uHnd
    273304                &&  pCur->Owner == Owner)
    274305            {
     
    295326    if (pCur)
    296327    {
     328        void *pv = RTHandleTableFree(g_hHndTableFilters, pCur->uHnd);
     329        Assert(pv == pCur);
    297330        vboxUSBFilterFree(pCur);
    298331        return VINF_SUCCESS;
     
    308341     * Validate input.
    309342     */
    310     if (!uId)
     343    if (!uId || uId != (uint32_t)uId)
    311344        return VBOXUSBFILTER_CONTEXT_NIL;
    312345
     
    318351    VBOXUSBFILTERMGR_LOCK();
    319352
    320     for (unsigned i = USBFILTERTYPE_FIRST; i < RT_ELEMENTS(g_aLists); i++)
    321     {
    322         for (PVBOXUSBFILTER pCur = g_aLists[i].pHead; pCur; pCur = pCur->pNext)
    323         {
    324             if (pCur->uId == uId)
    325             {
    326                 Owner = pCur->Owner;
    327                 Assert(Owner != VBOXUSBFILTER_CONTEXT_NIL);
    328                 break;
    329             }
    330         }
    331     }
     353    PVBOXUSBFILTER pCur = (PVBOXUSBFILTER)RTHandleTableLookup(g_hHndTableFilters, (uint32_t)uId);
     354    if (pCur)
     355        Owner = pCur->Owner;
    332356
    333357    Assert(Owner != VBOXUSBFILTER_CONTEXT_NIL);
     
    392416    {
    393417        PVBOXUSBFILTER pNext = pToFree->pNext;
     418        void *pv = RTHandleTableFree(g_hHndTableFilters, pToFree->uHnd);
     419        Assert(pv == pToFree);
    394420        vboxUSBFilterFree(pToFree);
    395421        pToFree = pNext;
     
    448474                 */
    449475                if (puId)
    450                     *puId = pCur->uId;
     476                    *puId = pCur->uHnd;
    451477                VBOXUSBFILTER_CONTEXT Owner = pCur->Owner;
    452478                *pfFilter = !!(i != USBFILTERTYPE_IGNORE
     
    476502                    if (fRemoveFltIfOneShot)
    477503                    {
     504                        void *pv = RTHandleTableFree(g_hHndTableFilters, pCur->uHnd);
     505                        Assert(pv == pCur);
    478506                        vboxUSBFilterFree(pCur);
    479507                    }
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