Changeset 62177 in vbox
- Timestamp:
- Jul 12, 2016 8:27:21 AM (8 years ago)
- Location:
- trunk/src/VBox/HostDrivers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPDrv.cpp
r61843 r62177 468 468 /* VBoxUSB */ 469 469 (PFNRT)RTPathStripFilename, 470 (PFNRT)RTHandleTableAlloc, 470 471 #if !defined(RT_OS_FREEBSD) 471 472 (PFNRT)RTStrPurgeEncoding, -
trunk/src/VBox/HostDrivers/VBoxUSB/VBoxUSBFilterMgr.cpp
r58340 r62177 23 23 #include "VBoxUSBFilterMgr.h" 24 24 25 #include <iprt/handletable.h> 25 26 #include <iprt/mem.h> 26 27 #ifdef VBOXUSBFILTERMGR_USB_SPINLOCK … … 77 78 { 78 79 /** The core filter. */ 79 USBFILTER Core;80 USBFILTER Core; 80 81 /** The filter owner. */ 81 VBOXUSBFILTER_CONTEXT 82 VBOXUSBFILTER_CONTEXT Owner; 82 83 /** The filter Id. */ 83 uint ptr_t uId;84 uint32_t uHnd; 84 85 /** Pointer to the next filter in the list. */ 85 PVBOXUSBFILTER pNext;86 PVBOXUSBFILTER pNext; 86 87 } VBOXUSBFILTER; 87 88 … … 113 114 * @remark The first entry is empty (USBFILTERTYPE_INVALID). */ 114 115 static VBOXUSBFILTERLIST g_aLists[USBFILTERTYPE_END]; 116 /** The handle table to match handles to the right filter. */ 117 static RTHANDLETABLE g_hHndTableFilters = NIL_RTHANDLETABLE; 115 118 116 119 … … 130 133 if (RT_SUCCESS(rc)) 131 134 { 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 } 135 159 } 136 160 return rc; … … 172 196 { 173 197 PVBOXUSBFILTER pNext = pCur->pNext; 198 RTHandleTableFree(g_hHndTableFilters, pCur->uHnd); 174 199 vboxUSBFilterFree(pCur); 175 200 pCur = pNext; 176 201 } 177 202 } 203 204 RTHandleTableDestroy(g_hHndTableFilters, NULL, NULL); 178 205 } 179 206 … … 210 237 memcpy(&pNew->Core, pFilter, sizeof(pNew->Core)); 211 238 pNew->Owner = Owner; 212 pNew->uId = (uintptr_t)pNew;213 239 pNew->pNext = NULL; 214 240 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; 233 263 } 234 264 … … 252 282 * Validate input. 253 283 */ 254 if (!uId )284 if (!uId || uId != (uint32_t)uId) 255 285 return VERR_INVALID_PARAMETER; 256 286 if (!Owner || Owner == VBOXUSBFILTER_CONTEXT_NIL) … … 260 290 * Locate and unlink it. 261 291 */ 292 uint32_t uHnd = (uint32_t)uId; 262 293 PVBOXUSBFILTER pCur = NULL; 263 294 … … 270 301 while (pCur) 271 302 { 272 if ( pCur->u Id == uId303 if ( pCur->uHnd == uHnd 273 304 && pCur->Owner == Owner) 274 305 { … … 295 326 if (pCur) 296 327 { 328 void *pv = RTHandleTableFree(g_hHndTableFilters, pCur->uHnd); 329 Assert(pv == pCur); 297 330 vboxUSBFilterFree(pCur); 298 331 return VINF_SUCCESS; … … 308 341 * Validate input. 309 342 */ 310 if (!uId )343 if (!uId || uId != (uint32_t)uId) 311 344 return VBOXUSBFILTER_CONTEXT_NIL; 312 345 … … 318 351 VBOXUSBFILTERMGR_LOCK(); 319 352 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; 332 356 333 357 Assert(Owner != VBOXUSBFILTER_CONTEXT_NIL); … … 392 416 { 393 417 PVBOXUSBFILTER pNext = pToFree->pNext; 418 void *pv = RTHandleTableFree(g_hHndTableFilters, pToFree->uHnd); 419 Assert(pv == pToFree); 394 420 vboxUSBFilterFree(pToFree); 395 421 pToFree = pNext; … … 448 474 */ 449 475 if (puId) 450 *puId = pCur->u Id;476 *puId = pCur->uHnd; 451 477 VBOXUSBFILTER_CONTEXT Owner = pCur->Owner; 452 478 *pfFilter = !!(i != USBFILTERTYPE_IGNORE … … 476 502 if (fRemoveFltIfOneShot) 477 503 { 504 void *pv = RTHandleTableFree(g_hHndTableFilters, pCur->uHnd); 505 Assert(pv == pCur); 478 506 vboxUSBFilterFree(pCur); 479 507 }
Note:
See TracChangeset
for help on using the changeset viewer.