Changeset 10377 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Jul 8, 2008 4:26:13 PM (17 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/Makefile.kmk
r10267 r10377 335 335 336 336 337 # 338 # SUPDrv.c needs the VBOX_SVN_REV. 339 # 340 SUPDrv.c_DEFS += VBOX_SVN_REV=$(VBOX_SVN_REV) 341 342 337 343 include $(KBUILD_PATH)/subfooter.kmk 338 344 -
trunk/src/VBox/HostDrivers/Support/SUPDrv.c
r10265 r10377 45 45 #include <iprt/cpuset.h> 46 46 #include <iprt/log.h> 47 #include <iprt/uuid.h> 48 #include <VBox/err.h> 47 49 /* VBox/x86.h not compatible with the Linux kernel sources */ 48 50 #ifdef RT_OS_LINUX … … 106 108 ( VALID_PTR(pSession) \ 107 109 && pSession->u32Cookie == BIRD_INV) 110 111 /** @def VBOX_SVN_REV 112 * The makefile should define this if it can. */ 113 #ifndef VBOX_SVN_REV 114 # define VBOX_SVN_REV 0 115 #endif 108 116 109 117 … … 240 248 static int supdrvIOCtl_LdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRFREE pReq); 241 249 static int supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL pReq); 250 static int supdrvIDC_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQGETSYM pReq); 242 251 static int supdrvLdrSetR0EP(PSUPDRVDEVEXT pDevExt, void *pvVMMR0, void *pvVMMR0EntryInt, void *pvVMMR0EntryFast, void *pvVMMR0EntryEx); 243 252 static void supdrvLdrUnsetR0EP(PSUPDRVDEVEXT pDevExt); 244 static voidsupdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage);253 static int supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage); 245 254 static void supdrvLdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage); 246 255 static SUPPAGINGMODE supdrvIOCtl_GetPagingMode(void); … … 276 285 if (!rc) 277 286 { 278 rc = RTSemFastMutexCreate(&pDevExt->mtx Gip);287 rc = RTSemFastMutexCreate(&pDevExt->mtxComponentFactory); 279 288 if (!rc) 280 289 { 281 rc = supdrvGipCreate(pDevExt);282 if ( RT_SUCCESS(rc))290 rc = RTSemFastMutexCreate(&pDevExt->mtxGip); 291 if (!rc) 283 292 { 284 pDevExt->u32Cookie = BIRD; /** @todo make this random? */ 285 return VINF_SUCCESS; 293 rc = supdrvGipCreate(pDevExt); 294 if (RT_SUCCESS(rc)) 295 { 296 pDevExt->u32Cookie = BIRD; /** @todo make this random? */ 297 return VINF_SUCCESS; 298 } 299 300 RTSemFastMutexDestroy(pDevExt->mtxGip); 301 pDevExt->mtxGip = NIL_RTSEMFASTMUTEX; 286 302 } 287 288 RTSemFastMutexDestroy(pDevExt->mtxGip); 289 pDevExt->mtxGip = NIL_RTSEMFASTMUTEX; 303 RTSemFastMutexDestroy(pDevExt->mtxComponentFactory); 304 pDevExt->mtxComponentFactory = NIL_RTSEMFASTMUTEX; 290 305 } 291 306 RTSemFastMutexDestroy(pDevExt->mtxLdr); … … 371 386 * @returns IPRT status code. 372 387 * @param pDevExt Device extension. 388 * @param fUser Flag indicating whether this is a user or kernel session. 373 389 * @param ppSession Where to store the pointer to the session data. 374 390 */ 375 int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION *ppSession)391 int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, PSUPDRVSESSION *ppSession) 376 392 { 377 393 /* … … 391 407 /*pSession->pLdrUsage = NULL; 392 408 pSession->pPatchUsage = NULL; 409 pSession->pVM = NULL; 393 410 pSession->pUsage = NULL; 394 411 pSession->pGip = NULL; 395 412 pSession->fGipReferenced = false; 396 pSession->Bundle.cUsed = 0 */ 413 pSession->Bundle.cUsed = 0; */ 414 pSession->Uid = NIL_RTUID; 415 pSession->Gid = NIL_RTGID; 416 if (fUser) 417 { 418 pSession->Process = RTProcSelf(); 419 pSession->R0Process = RTR0ProcHandleSelf(); 420 } 421 else 422 { 423 pSession->Process = NIL_RTPROCESS; 424 pSession->R0Process = NIL_RTR0PROCESS; 425 } 397 426 398 427 LogFlow(("Created session %p initial cookie=%#x\n", pSession, pSession->u32Cookie)); … … 569 598 570 599 /* 600 * Deregister component factories. 601 */ 602 RTSemFastMutexRequest(pDevExt->mtxComponentFactory); 603 Log2(("deregistering component factories:\n")); 604 if (pDevExt->pComponentFactoryHead) 605 { 606 PSUPDRVFACTORYREG pPrev = NULL; 607 PSUPDRVFACTORYREG pCur = pDevExt->pComponentFactoryHead; 608 while (pCur) 609 { 610 if (pCur->pSession == pSession) 611 { 612 /* unlink it */ 613 PSUPDRVFACTORYREG pNext = pCur->pNext; 614 if (pPrev) 615 pPrev->pNext = pNext; 616 else 617 pDevExt->pComponentFactoryHead = pNext; 618 619 /* free it */ 620 pCur->pNext = NULL; 621 pCur->pSession = NULL; 622 pCur->pFactory = NULL; 623 RTMemFree(pCur); 624 625 /* next */ 626 pCur = pNext; 627 } 628 else 629 { 630 /* next */ 631 pPrev = pCur; 632 pCur = pCur->pNext; 633 } 634 } 635 } 636 RTSemFastMutexRelease(pDevExt->mtxComponentFactory); 637 Log2(("deregistering component factories - done\n")); 638 639 /* 571 640 * Loaded images needs to be dereferenced and possibly freed up. 572 641 */ … … 1164 1233 * @returns VBox status code. 1165 1234 * @retval VINF_SUCCESS on success. 1235 * @retval VERR_INVALID_PARAMETER if the request is invalid. 1166 1236 * @retval VERR_NOT_SUPPORTED if the request isn't supported. 1167 * @retval VERR_NOT_IMPLEMENTED if during development.1168 * @retval VERR_INVALID_PARAMETER if the request is invalid.1169 1237 * 1170 1238 * @param uReq The request (function) code. … … 1206 1274 REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_CONNECT, sizeof(*pReq)); 1207 1275 1208 return VERR_NOT_IMPLEMENTED; 1276 /* 1277 * Validate the cookie and other input. 1278 */ 1279 if (pReq->Hdr.pSession != NULL) 1280 { 1281 OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: pSession=%p expected NULL!\n", pReq->Hdr.pSession)); 1282 return pReqHdr->rc = VERR_INVALID_PARAMETER; 1283 } 1284 if (pReq->u.In.u32MagicCookie != SUPDRVIDCREQ_CONNECT_MAGIC_COOKIE) 1285 { 1286 OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: u32MagicCookie=%#x expected %#x!\n", 1287 pReq->u.In.u32MagicCookie, SUPDRVIDCREQ_CONNECT_MAGIC_COOKIE)); 1288 return pReqHdr->rc = VERR_INVALID_PARAMETER; 1289 } 1290 if ( pReq->u.In.uMinVersion > pReq->u.In.uReqVersion 1291 || (pReq->u.In.uMinVersion & UINT32_C(0xffff0000)) != (pReq->u.In.uReqVersion & UINT32_C(0xffff0000))) 1292 { 1293 OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: uMinVersion=%#x uMaxVersion=%#x doesn't match!\n", 1294 pReq->u.In.uMinVersion, pReq->u.In.uReqVersion)); 1295 return pReqHdr->rc = VERR_INVALID_PARAMETER; 1296 } 1297 1298 /* 1299 * Match the version. 1300 * The current logic is very simple, match the major interface version. 1301 */ 1302 if ( pReq->u.In.uMinVersion > SUPDRV_IDC_VERSION 1303 || (pReq->u.In.uMinVersion & 0xffff0000) != (SUPDRV_IDC_VERSION & 0xffff0000)) 1304 { 1305 OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: Version mismatch. Requested: %#x Min: %#x Current: %#x\n", 1306 pReq->u.In.uReqVersion, pReq->u.In.uMinVersion, SUPDRV_IDC_VERSION)); 1307 pReq->u.Out.pSession = NULL; 1308 pReq->u.Out.uSessionVersion = 0xffffffff; 1309 pReq->u.Out.uDriverVersion = SUPDRVIOC_VERSION; 1310 pReq->u.Out.uDriverRevision = VBOX_SVN_REV; 1311 pReq->Hdr.rc = VERR_VERSION_MISMATCH; 1312 return VINF_SUCCESS; 1313 } 1314 1315 pReq->u.Out.pSession = NULL; 1316 pReq->u.Out.uSessionVersion = SUPDRVIOC_VERSION; 1317 pReq->u.Out.uDriverVersion = SUPDRVIOC_VERSION; 1318 pReq->u.Out.uDriverRevision = VBOX_SVN_REV; 1319 1320 /* 1321 * On NT we will already have a session associated with the 1322 * client, just like with the SUP_IOCTL_COOKIE request, while 1323 * the other doesn't. 1324 */ 1325 #ifdef RT_OS_WINDOWS 1326 pReq->Hdr.rc = VINF_SUCCESS; 1327 #else 1328 AssertReturn(!pSession, VERR_INTERNAL_ERROR); 1329 pReq->Hdr.rc = supdrvCreateSession(pDevExt, false /* fUser */, &pSession); 1330 if (RT_FAILURE(pReq->Hdr.rc)) 1331 { 1332 OSDBGPRINT(("SUPDRV_IDC_REQ_CONNECT: failed to create session, rc=%d\n", pReq->Hdr.rc)); 1333 return VINF_SUCCESS; 1334 } 1335 #endif 1336 1337 pReq->u.Out.pSession = pSession; 1338 pReq->Hdr.pSession = pSession; 1339 1340 return VINF_SUCCESS; 1209 1341 } 1210 1342 … … 1213 1345 REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_DISCONNECT, sizeof(*pReqHdr)); 1214 1346 1215 return VERR_NOT_IMPLEMENTED; 1347 #ifdef RT_OS_WINDOWS 1348 /* Windows will destroy the session when the file object is destroyed. */ 1349 #else 1350 supdrvCloseSession(pDevExt, pSession); 1351 #endif 1352 return pReqHdr->rc = VINF_SUCCESS; 1216 1353 } 1217 1354 1218 1355 case SUPDRV_IDC_REQ_GET_SYMBOL: 1219 1356 { 1220 PSUPDRVIDCREQGETSYM pReq ;1357 PSUPDRVIDCREQGETSYM pReq = (PSUPDRVIDCREQGETSYM)pReqHdr; 1221 1358 REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_GET_SYMBOL, sizeof(*pReq)); 1222 1359 1223 return VERR_NOT_IMPLEMENTED; 1360 pReq->Hdr.rc = supdrvIDC_LdrGetSymbol(pDevExt, pSession, pReq); 1361 return VINF_SUCCESS; 1224 1362 } 1225 1363 1226 1364 case SUPDRV_IDC_REQ_COMPONENT_REGISTER_FACTORY: 1227 1365 { 1228 PSUPDRVIDCREQCOMPREGFACTORY pReq ;1366 PSUPDRVIDCREQCOMPREGFACTORY pReq = (PSUPDRVIDCREQCOMPREGFACTORY)pReqHdr; 1229 1367 REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_COMPONENT_REGISTER_FACTORY, sizeof(*pReq)); 1230 1368 1231 return VERR_NOT_IMPLEMENTED; 1369 pReq->Hdr.rc = SUPR0ComponentRegisterFactory(pSession, pReq->u.In.pFactory); 1370 return VINF_SUCCESS; 1232 1371 } 1233 1372 1234 1373 case SUPDRV_IDC_REQ_COMPONENT_DEREGISTER_FACTORY: 1235 1374 { 1236 PSUPDRVIDCREQCOMPDEREGFACTORY pReq ;1375 PSUPDRVIDCREQCOMPDEREGFACTORY pReq = (PSUPDRVIDCREQCOMPDEREGFACTORY)pReqHdr; 1237 1376 REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_COMPONENT_DEREGISTER_FACTORY, sizeof(*pReq)); 1238 1377 1239 return VERR_NOT_IMPLEMENTED; 1378 pReq->Hdr.rc = SUPR0ComponentDeregisterFactory(pSession, pReq->u.In.pFactory); 1379 return VINF_SUCCESS; 1240 1380 } 1241 1381 … … 2288 2428 RTSemFastMutexRelease(pDevExt->mtxGip); 2289 2429 2430 return rc; 2431 } 2432 2433 2434 /** 2435 * Register a component factory with the support driver. 2436 * 2437 * This is currently restricted to kernel sessions only. 2438 * 2439 * @returns VBox status code. 2440 * @retval VINF_SUCCESS on success. 2441 * @retval VERR_NO_MEMORY if we're out of memory. 2442 * @retval VERR_ALREADY_EXISTS if the factory has already been registered. 2443 * @retval VERR_ACCESS_DENIED if it isn't a kernel session. 2444 * @retval VERR_INVALID_PARAMETER on invalid parameter. 2445 * @retval VERR_INVALID_POINTER on invalid pointer parameter. 2446 * 2447 * @param pSession The SUPDRV session (must be a ring-0 session). 2448 * @param pFactory Pointer to the component factory registration structure. 2449 * 2450 * @remarks This interface is also available via SUPR0IdcComponentRegisterFactory. 2451 */ 2452 SUPR0DECL(int) SUPR0ComponentRegisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory) 2453 { 2454 PSUPDRVFACTORYREG pNewReg; 2455 const char *psz; 2456 int rc; 2457 2458 /* 2459 * Validate parameters. 2460 */ 2461 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 2462 AssertReturn(pSession->R0Process == NIL_RTR0PROCESS, VERR_ACCESS_DENIED); 2463 AssertPtrReturn(pFactory, VERR_INVALID_POINTER); 2464 AssertPtrReturn(pFactory->pfnQueryFactoryInterface, VERR_INVALID_POINTER); 2465 psz = (const char *)memchr(pFactory->szName, '\0', sizeof(pFactory->szName)); 2466 AssertReturn(psz, VERR_INVALID_PARAMETER); 2467 2468 /* 2469 * Allocate and initialize a new registration structure. 2470 */ 2471 pNewReg = (PSUPDRVFACTORYREG)RTMemAlloc(sizeof(SUPDRVFACTORYREG)); 2472 if (pNewReg) 2473 { 2474 pNewReg->pNext = NULL; 2475 pNewReg->pFactory = pFactory; 2476 pNewReg->pSession = pSession; 2477 pNewReg->cchName = psz - &pFactory->szName[0]; 2478 2479 /* 2480 * Add it to the tail of the list after checking for prior registration. 2481 */ 2482 rc = RTSemFastMutexRequest(pSession->pDevExt->mtxComponentFactory); 2483 if (RT_SUCCESS(rc)) 2484 { 2485 PSUPDRVFACTORYREG pPrev = NULL; 2486 PSUPDRVFACTORYREG pCur = pSession->pDevExt->pComponentFactoryHead; 2487 while (pCur && pCur->pFactory != pFactory) 2488 { 2489 pPrev = pCur; 2490 pCur = pCur->pNext; 2491 } 2492 if (!pCur) 2493 { 2494 if (pPrev) 2495 pPrev->pNext = pNewReg; 2496 else 2497 pSession->pDevExt->pComponentFactoryHead = pNewReg; 2498 rc = VINF_SUCCESS; 2499 } 2500 else 2501 rc = VERR_ALREADY_EXISTS; 2502 2503 RTSemFastMutexRelease(pSession->pDevExt->mtxComponentFactory); 2504 } 2505 2506 if (RT_FAILURE(rc)) 2507 RTMemFree(pNewReg); 2508 } 2509 else 2510 rc = VERR_NO_MEMORY; 2511 return rc; 2512 } 2513 2514 2515 /** 2516 * Deregister a component factory. 2517 * 2518 * @returns VBox status code. 2519 * @retval VINF_SUCCESS on success. 2520 * @retval VERR_NOT_FOUND if the factory wasn't registered. 2521 * @retval VERR_ACCESS_DENIED if it isn't a kernel session. 2522 * @retval VERR_INVALID_PARAMETER on invalid parameter. 2523 * @retval VERR_INVALID_POINTER on invalid pointer parameter. 2524 * 2525 * @param pSession The SUPDRV session (must be a ring-0 session). 2526 * @param pFactory Pointer to the component factory registration structure 2527 * previously passed SUPR0ComponentRegisterFactory(). 2528 * 2529 * @remarks This interface is also available via SUPR0IdcComponentDeregisterFactory. 2530 */ 2531 SUPR0DECL(int) SUPR0ComponentDeregisterFactory(PSUPDRVSESSION pSession, PCSUPDRVFACTORY pFactory) 2532 { 2533 int rc; 2534 2535 /* 2536 * Validate parameters. 2537 */ 2538 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 2539 AssertReturn(pSession->R0Process == NIL_RTR0PROCESS, VERR_ACCESS_DENIED); 2540 AssertPtrReturn(pFactory, VERR_INVALID_POINTER); 2541 2542 /* 2543 * Take the lock and look for the registration record. 2544 */ 2545 rc = RTSemFastMutexRequest(pSession->pDevExt->mtxComponentFactory); 2546 if (RT_SUCCESS(rc)) 2547 { 2548 PSUPDRVFACTORYREG pPrev = NULL; 2549 PSUPDRVFACTORYREG pCur = pSession->pDevExt->pComponentFactoryHead; 2550 while (pCur && pCur->pFactory != pFactory) 2551 { 2552 pPrev = pCur; 2553 pCur = pCur->pNext; 2554 } 2555 if (pCur) 2556 { 2557 if (!pPrev) 2558 pSession->pDevExt->pComponentFactoryHead = pCur->pNext; 2559 else 2560 pPrev->pNext = pCur->pNext; 2561 2562 pCur->pNext = NULL; 2563 pCur->pFactory = NULL; 2564 pCur->pSession = NULL; 2565 rc = VINF_SUCCESS; 2566 } 2567 else 2568 rc = VERR_NOT_FOUND; 2569 2570 RTSemFastMutexRelease(pSession->pDevExt->mtxComponentFactory); 2571 2572 RTMemFree(pCur); 2573 } 2574 return rc; 2575 } 2576 2577 2578 /** 2579 * Queries a component factory. 2580 * 2581 * @returns VBox status code. 2582 * @retval VERR_INVALID_PARAMETER on invalid parameter. 2583 * @retval VERR_INVALID_POINTER on invalid pointer parameter. 2584 * @retval VERR_SUPDRV_COMPONENT_NOT_FOUND if the component factory wasn't found. 2585 * @retval VERR_SUPDRV_INTERFACE_NOT_SUPPORTED if the interface wasn't supported. 2586 * 2587 * @param pSession The SUPDRV session. 2588 * @param pszName The name of the component factory. 2589 * @param pszInterfaceUuid The UUID of the factory interface (stringified). 2590 * @param ppvFactoryIf Where to store the factory interface. 2591 */ 2592 SUPR0DECL(int) SUPR0ComponentQueryFactory(PSUPDRVSESSION pSession, const char *pszName, const char *pszInterfaceUuid, void **ppvFactoryIf) 2593 { 2594 const char *pszEnd; 2595 size_t cchName; 2596 int rc; 2597 2598 /* 2599 * Validate parameters. 2600 */ 2601 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 2602 2603 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 2604 pszEnd = memchr(pszName, '\0', RT_SIZEOFMEMB(SUPDRVFACTORY, szName)); 2605 AssertReturn(pszEnd, VERR_INVALID_PARAMETER); 2606 cchName = pszEnd - pszName; 2607 2608 AssertPtrReturn(pszInterfaceUuid, VERR_INVALID_POINTER); 2609 pszEnd = memchr(pszInterfaceUuid, '\0', RTUUID_STR_LENGTH); 2610 AssertReturn(pszEnd, VERR_INVALID_PARAMETER); 2611 2612 AssertPtrReturn(ppvFactoryIf, VERR_INVALID_POINTER); 2613 *ppvFactoryIf = NULL; 2614 2615 /* 2616 * Take the lock and try all factories by this name. 2617 */ 2618 rc = RTSemFastMutexRequest(pSession->pDevExt->mtxComponentFactory); 2619 if (RT_SUCCESS(rc)) 2620 { 2621 PSUPDRVFACTORYREG pCur = pSession->pDevExt->pComponentFactoryHead; 2622 rc = VERR_SUPDRV_COMPONENT_NOT_FOUND; 2623 while (pCur) 2624 { 2625 if ( pCur->cchName == cchName 2626 && !memcmp(pCur->pFactory->szName, pszName, cchName)) 2627 { 2628 void *pvFactory = pCur->pFactory->pfnQueryFactoryInterface(pCur->pFactory, pSession, pszInterfaceUuid); 2629 if (pvFactory) 2630 { 2631 *ppvFactoryIf = pvFactory; 2632 rc = VINF_SUCCESS; 2633 break; 2634 } 2635 rc = VERR_SUPDRV_INTERFACE_NOT_SUPPORTED; 2636 } 2637 2638 /* next */ 2639 pCur = pCur->pNext; 2640 } 2641 2642 RTSemFastMutexRelease(pSession->pDevExt->mtxComponentFactory); 2643 } 2290 2644 return rc; 2291 2645 } … … 3446 3800 3447 3801 /* 3448 * Search the symbol string .3802 * Search the symbol strings. 3449 3803 */ 3450 3804 pchStrings = (const char *)((uint8_t *)pImage->pvImage + pImage->offStrTab); … … 3463 3817 RTSemFastMutexRelease(pDevExt->mtxLdr); 3464 3818 pReq->u.Out.pvSymbol = pvSymbol; 3819 return rc; 3820 } 3821 3822 3823 /** 3824 * Gets the address of a symbol in an open image or the support driver. 3825 * 3826 * @returns VINF_SUCCESS on success. 3827 * @returns 3828 * @param pDevExt Device globals. 3829 * @param pSession Session data. 3830 * @param pReq The request buffer. 3831 */ 3832 static int supdrvIDC_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQGETSYM pReq) 3833 { 3834 int rc = VINF_SUCCESS; 3835 const char *pszSymbol = pReq->u.In.pszSymbol; 3836 const char *pszModule = pReq->u.In.pszModule; 3837 size_t cbSymbol; 3838 char const *pszEnd; 3839 uint32_t i; 3840 3841 /* 3842 * Input validation. 3843 */ 3844 AssertPtrReturn(pszSymbol, VERR_INVALID_POINTER); 3845 pszEnd = (char *)memchr(pszSymbol, '\0', 512); 3846 AssertReturn(pszEnd, VERR_INVALID_PARAMETER); 3847 cbSymbol = pszEnd - pszSymbol + 1; 3848 3849 if (pszModule) 3850 { 3851 AssertPtrReturn(pszModule, VERR_INVALID_POINTER); 3852 pszEnd = (char *)memchr(pszModule, '\0', 64); 3853 AssertReturn(pszEnd, VERR_INVALID_PARAMETER); 3854 } 3855 Log3(("supdrvIDC_LdrGetSymbol: pszModule=%p:{%s} pszSymbol=%p:{%s}\n", pszModule, pszModule, pszSymbol, pszSymbol)); 3856 3857 3858 if ( !pszModule 3859 || !strcmp(pszModule, "SupDrv")) 3860 { 3861 /* 3862 * Search the support driver export table. 3863 */ 3864 for (i = 0; i < RT_ELEMENTS(g_aFunctions); i++) 3865 if (!strcmp(g_aFunctions[i].szName, pszSymbol)) 3866 { 3867 pReq->u.Out.pfnSymbol = g_aFunctions[i].pfn; 3868 break; 3869 } 3870 } 3871 else 3872 { 3873 /* 3874 * Find the loader image. 3875 */ 3876 PSUPDRVLDRIMAGE pImage; 3877 3878 RTSemFastMutexRequest(pDevExt->mtxLdr); 3879 3880 for (pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext) 3881 if (!strcmp(pImage->szName, pszModule)) 3882 break; 3883 if (pImage && pImage->uState == SUP_IOCTL_LDR_LOAD) 3884 { 3885 /* 3886 * Search the symbol strings. 3887 */ 3888 const char *pchStrings = (const char *)((uint8_t *)pImage->pvImage + pImage->offStrTab); 3889 PCSUPLDRSYM paSyms = (PCSUPLDRSYM)((uint8_t *)pImage->pvImage + pImage->offSymbols); 3890 for (i = 0; i < pImage->cSymbols; i++) 3891 { 3892 if ( paSyms[i].offSymbol < pImage->cbImage /* paranoia */ 3893 && paSyms[i].offName + cbSymbol <= pImage->cbStrTab 3894 && !memcmp(pchStrings + paSyms[i].offName, pszSymbol, cbSymbol)) 3895 { 3896 /* 3897 * Found it! Calc the symbol address and add a reference to the module. 3898 */ 3899 pReq->u.Out.pfnSymbol = (PFNRT)((uint8_t *)pImage->pvImage + paSyms[i].offSymbol); 3900 rc = supdrvLdrAddUsage(pSession, pImage); 3901 break; 3902 } 3903 } 3904 } 3905 else 3906 rc = pImage ? VERR_WRONG_ORDER : VERR_MODULE_NOT_FOUND; 3907 3908 RTSemFastMutexRelease(pDevExt->mtxLdr); 3909 } 3465 3910 return rc; 3466 3911 } … … 3566 4011 * Adds a usage reference in the specified session of an image. 3567 4012 * 4013 * Called while owning the loader semaphore. 4014 * 4015 * @returns VINF_SUCCESS on success and VERR_NO_MEMORY on failure. 3568 4016 * @param pSession Session in question. 3569 4017 * @param pImage Image which the session is using. 3570 4018 */ 3571 static voidsupdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage)4019 static int supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage) 3572 4020 { 3573 4021 PSUPDRVLDRUSAGE pUsage; … … 3583 4031 { 3584 4032 pUsage->cUsage++; 3585 return ;4033 return VINF_SUCCESS; 3586 4034 } 3587 4035 pUsage = pUsage->pNext; … … 3592 4040 */ 3593 4041 pUsage = (PSUPDRVLDRUSAGE)RTMemAlloc(sizeof(*pUsage)); 3594 Assert(pUsage); 3595 if (pUsage) 3596 { 3597 pUsage->cUsage = 1; 3598 pUsage->pImage = pImage; 3599 pUsage->pNext = pSession->pLdrUsage; 3600 pSession->pLdrUsage = pUsage; 3601 } 3602 /* ignore errors... */ 4042 AssertReturn(pUsage, VERR_NO_MEMORY); 4043 pUsage->cUsage = 1; 4044 pUsage->pImage = pImage; 4045 pUsage->pNext = pSession->pLdrUsage; 4046 pSession->pLdrUsage = pUsage; 4047 return VINF_SUCCESS; 3603 4048 } 3604 4049 … … 4089 4534 int cLoops = 8; 4090 4535 bool fAsync = false; 4091 int rc ;4536 int rc = VINF_SUCCESS; 4092 4537 uint64_t offMax = 0; 4093 4538 uint64_t offMin = ~(uint64_t)0; -
trunk/src/VBox/HostDrivers/Support/SUPDrvIDC.h
r10264 r10377 112 112 struct SUPDRVIDCREQCONNECTOUT 113 113 { 114 /** The version of the IDC interface for this session. */115 uint32_t uVersion;116 114 /** The support driver session. (An opaque.) */ 117 115 PSUPDRVSESSION pSession; 116 /** The version of the IDC interface for this session. */ 117 uint32_t uSessionVersion; 118 /** The version of the IDC interface . */ 119 uint32_t uDriverVersion; 120 /** The SVN revision of the driver. 121 * This will be set to 0 if not compiled into the driver. */ 122 uint32_t uDriverRevision; 118 123 } Out; 119 124 } u; -
trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h
r10256 r10377 370 370 /** Offset of the symbol relative to the image load address. */ 371 371 uint32_t offSymbol; 372 } SUPLDRSYM, *PSUPLDRSYM; 372 } SUPLDRSYM; 373 /** Pointer to a symbol table entry. */ 374 typedef SUPLDRSYM *PSUPLDRSYM; 375 /** Pointer to a const symbol table entry. */ 376 typedef SUPLDRSYM const *PCSUPLDRSYM; 373 377 374 378 /** -
trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h
r10265 r10377 459 459 460 460 /** 461 * Component factory registration record. 462 */ 463 typedef struct SUPDRVFACTORYREG 464 { 465 /** Pointer to the next registration. */ 466 struct SUPDRVFACTORYREG *pNext; 467 /** Pointer to the registered factory. */ 468 PCSUPDRVFACTORY pFactory; 469 /** The session owning the factory. 470 * Used for deregistration and session cleanup. */ 471 PSUPDRVSESSION pSession; 472 /** Length of the name. */ 473 size_t cchName; 474 } SUPDRVFACTORYREG; 475 /** Pointer to a component factory registration record. */ 476 typedef SUPDRVFACTORYREG *PSUPDRVFACTORYREG; 477 /** Pointer to a const component factory registration record. */ 478 typedef SUPDRVFACTORYREG const *PCSUPDRVFACTORYREG; 479 480 481 /** 461 482 * Registered object. 462 483 * This takes care of reference counting and tracking data for access checks. … … 539 560 /** The group id of the session. (Set by the OS part.) */ 540 561 RTGID Gid; 541 /** The process (id) of the session. (Set by the OS part.)*/562 /** The process (id) of the session. */ 542 563 RTPROCESS Process; 543 564 /** Which process this session is associated with. … … 621 642 * This CPU is responsible for the updating the common GIP data. */ 622 643 RTCPUID volatile idGipMaster; 644 645 /** Component factory mutex. 646 * This protects pComponentFactoryHead and component factory querying. */ 647 RTSEMFASTMUTEX mtxComponentFactory; 648 /** The head of the list of registered component factories. */ 649 PSUPDRVFACTORYREG pComponentFactoryHead; 623 650 } SUPDRVDEVEXT; 624 651 … … 642 669 int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt); 643 670 void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt); 644 int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION *ppSession);671 int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, PSUPDRVSESSION *ppSession); 645 672 void VBOXCALL supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession); 646 673 void VBOXCALL supdrvCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession); -
trunk/src/VBox/HostDrivers/Support/SUPR0IdcClient.c
r10258 r10377 49 49 * 50 50 * @returns VBox status code. 51 * @param pHandle The handle structure (output). 52 * @param uReqVersion The requested version. Pass 0 for default. 53 * @param uMinVersion The minimum required version. Pass 0 for default. 54 * @param puVersion Where to store the version of the IDC interface. Optional. 55 */ 56 SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion, uint32_t *puVersion) 51 * @param pHandle The handle structure (output). 52 * @param uReqVersion The requested version. Pass 0 for default. 53 * @param uMinVersion The minimum required version. Pass 0 for default. 54 * @param puSessionVersion Where to store the session version. Optional. 55 * @param puDriverVersion Where to store the session version. Optional. 56 * @param puDriverRevision Where to store the SVN revision of the driver. Optional. 57 */ 58 SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion, 59 uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision) 57 60 { 58 61 unsigned uDefaultMinVersion; … … 65 68 AssertPtrReturn(pHandle, VERR_INVALID_POINTER); 66 69 pHandle->s.pSession = NULL; 67 AssertPtrNullReturn(puVersion, VERR_INVALID_POINTER); 68 if (puVersion) 69 *puVersion = 0; 70 71 AssertPtrNullReturn(puSessionVersion, VERR_INVALID_POINTER); 72 if (puSessionVersion) 73 *puSessionVersion = 0; 74 75 AssertPtrNullReturn(puDriverVersion, VERR_INVALID_POINTER); 76 if (puDriverVersion) 77 *puDriverVersion = 0; 78 79 AssertPtrNullReturn(puDriverRevision, VERR_INVALID_POINTER); 80 if (puDriverRevision) 81 *puDriverRevision = 0; 82 70 83 AssertReturn(!uMinVersion || (uMinVersion & UINT32_C(0xffff0000)) == (SUPDRV_IDC_VERSION & UINT32_C(0xffff0000)), VERR_INVALID_PARAMETER); 71 84 AssertReturn(!uReqVersion || (uReqVersion & UINT32_C(0xffff0000)) == (SUPDRV_IDC_VERSION & UINT32_C(0xffff0000)), VERR_INVALID_PARAMETER); … … 100 113 { 101 114 pHandle->s.pSession = Req.u.Out.pSession; 102 if (puVersion) 103 *puVersion = Req.u.Out.uVersion; 115 if (puSessionVersion) 116 *puSessionVersion = Req.u.Out.uSessionVersion; 117 if (puDriverVersion) 118 *puDriverVersion = Req.u.Out.uDriverVersion; 119 if (puDriverRevision) 120 *puDriverRevision = Req.u.Out.uDriverRevision; 104 121 105 122 /* … … 108 125 */ 109 126 if ( VALID_PTR(Req.u.Out.pSession) 110 && Req.u.Out.u Version >= uMinVersion111 && (Req.u.Out.u Version & UINT32_C(0xffff0000)) == (SUPDRV_IDC_VERSION & UINT32_C(0xffff0000)))127 && Req.u.Out.uSessionVersion >= uMinVersion 128 && (Req.u.Out.uSessionVersion & UINT32_C(0xffff0000)) == (SUPDRV_IDC_VERSION & UINT32_C(0xffff0000))) 112 129 { 113 130 ASMAtomicCmpXchgPtr((void * volatile *)&g_pMainHandle, pHandle, NULL); … … 115 132 } 116 133 117 AssertMsgFailed(("pSession=%p u Version=0x%x\n", Req.u.Out.pSession, Req.u.Out.uVersion));134 AssertMsgFailed(("pSession=%p uSessionVersion=0x%x (r%u)\n", Req.u.Out.pSession, Req.u.Out.uSessionVersion, Req.u.Out.uDriverRevision)); 118 135 rc = VERR_VERSION_MISMATCH; 119 136 SUPR0IdcClose(pHandle); -
trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp
r10263 r10377 322 322 * Create a new session. 323 323 */ 324 rc = supdrvCreateSession(&g_DevExt, &pSession);324 rc = supdrvCreateSession(&g_DevExt, true /* fUser */, &pSession); 325 325 if (RT_SUCCESS(rc)) 326 326 { … … 333 333 pSession->Gid = pCred->cr_gid; 334 334 } 335 pSession->Process = RTProcSelf();336 pSession->R0Process = RTR0ProcHandleSelf();337 335 338 336 /* -
trunk/src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c
r10263 r10377 301 301 * Create a new session. 302 302 */ 303 rc = supdrvCreateSession(&g_VBoxDrvFreeBSDDevExt, &pSession);303 rc = supdrvCreateSession(&g_VBoxDrvFreeBSDDevExt, true /* fUser */, &pSession); 304 304 if (RT_SUCCESS(rc)) 305 305 { 306 pSession->Uid = 0; 307 pSession->Gid = 0; 308 pSession->Process = RTProcSelf(); 309 pSession->R0Process = RTR0ProcHandleSelf(); 306 /** @todo get (e)uid and (e)gid. 307 pSession->Uid = stuff; 308 pSession->Gid = stuff; */ 310 309 if (ASMAtomicCmpXchgPtr(&pDev->si_drv1, pSession, (void *)0x42)) 311 310 return 0; -
trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c
r10263 r10377 679 679 * Call common code for the rest. 680 680 */ 681 rc = supdrvCreateSession(&g_DevExt, (PSUPDRVSESSION *)&pSession);681 rc = supdrvCreateSession(&g_DevExt, true /* fUser */, (PSUPDRVSESSION *)&pSession); 682 682 if (!rc) 683 683 { 684 pSession->Uid = current->euid; 685 pSession->Gid = current->egid; 686 pSession->Process = RTProcSelf(); 687 pSession->R0Process = RTR0ProcHandleSelf(); 684 pSession->Uid = current->euid; 685 pSession->Gid = current->egid; 688 686 } 689 687 -
trunk/src/VBox/HostDrivers/Support/linux/files_vboxdrv
r10258 r10377 53 53 ${PATH_ROOT}/include/iprt/timer.h=>include/iprt/timer.h \ 54 54 ${PATH_ROOT}/include/iprt/types.h=>include/iprt/types.h \ 55 ${PATH_ROOT}/include/iprt/uuid.h=>include/iprt/uuid.h \ 55 56 ${PATH_ROOT}/include/iprt/nocrt/limits.h=>include/iprt/nocrt/limits.h \ 56 57 ${PATH_ROOT}/include/VBox/cdefs.h=>include/VBox/cdefs.h \ 58 ${PATH_ROOT}/include/VBox/err.h=>include/VBox/err.h \ 57 59 ${PATH_ROOT}/include/VBox/log.h=>include/VBox/log.h \ 58 60 ${PATH_ROOT}/include/VBox/sup.h=>include/VBox/sup.h \ -
trunk/src/VBox/HostDrivers/Support/os2/SUPDrv-os2.cpp
r10254 r10377 151 151 * Create a new session. 152 152 */ 153 rc = supdrvCreateSession(&g_DevExt, &pSession);153 rc = supdrvCreateSession(&g_DevExt, true /* fUser */, &pSession); 154 154 if (RT_SUCCESS(rc)) 155 155 { 156 pSession->Process = RTProcSelf();157 pSession->R0Process = RTR0ProcHandleSelf();158 156 pSession->sfn = sfn; 159 157 -
trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c
r10263 r10377 420 420 * Create a new session. 421 421 */ 422 rc = supdrvCreateSession(&g_DevExt, &pSession);422 rc = supdrvCreateSession(&g_DevExt, true /* fUser */, &pSession); 423 423 if (RT_SUCCESS(rc)) 424 424 { 425 pSession->Uid = crgetuid(pCred); 426 pSession->Gid = crgetgid(pCred); 427 425 428 pState->pSession = pSession; 426 429 *pDev = makedevice(getmajor(*pDev), iOpenInstance); … … 440 443 * in VBoxDrvSolarisIOCtlSlow() while calling supdrvIOCtl() 441 444 */ 442 rc = supdrvCreateSession(&g_DevExt, &pSession);445 rc = supdrvCreateSession(&g_DevExt, true /* fUser */, &pSession); 443 446 if (RT_SUCCESS(rc)) 444 447 { … … 446 449 unsigned iHash; 447 450 448 pSession->Uid = crgetuid(pCred); 449 pSession->Gid = crgetgid(pCred); 450 pSession->Process = RTProcSelf(); 451 pSession->R0Process = RTR0ProcHandleSelf(); 451 pSession->Uid = crgetuid(pCred); 452 pSession->Gid = crgetgid(pCred); 452 453 453 454 /* -
trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp
r10265 r10377 232 232 pFileObj->FsContext = NULL; 233 233 PSUPDRVSESSION pSession; 234 int rc = supdrvCreateSession(pDevExt, &pSession); 234 #if 0 /** @todo check if this works, consider OBJ_KERNEL_HANDLE too. */ 235 bool fUser = pIrp->RequestorMode != KernelMode; 236 #else 237 bool fUser = true; 238 #endif 239 int rc = supdrvCreateSession(pDevExt, fUser, &pSession); 235 240 if (!rc) 236 {237 pSession->Uid = NIL_RTUID;238 pSession->Gid = NIL_RTGID;239 pSession->Process = RTProcSelf();240 pSession->R0Process = RTR0ProcHandleSelf();241 241 pFileObj->FsContext = pSession; 242 }243 242 244 243 NTSTATUS rcNt = pIrp->IoStatus.Status = VBoxDrvNtErr2NtStatus(rc);
Note:
See TracChangeset
for help on using the changeset viewer.