VirtualBox

Changeset 10377 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Jul 8, 2008 4:26:13 PM (17 years ago)
Author:
vboxsync
Message:

Implemented the IDC methods. Moved the setting of the R0Process and Process SUPDRVSESSION members to SUPDrv.c, and made SUPDrv.c provide default initialization of the Uid and Gid members.

Location:
trunk/src/VBox/HostDrivers/Support
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/Makefile.kmk

    r10267 r10377  
    335335
    336336
     337#
     338# SUPDrv.c needs the VBOX_SVN_REV.
     339#
     340SUPDrv.c_DEFS += VBOX_SVN_REV=$(VBOX_SVN_REV)
     341
     342
    337343include $(KBUILD_PATH)/subfooter.kmk
    338344
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r10265 r10377  
    4545#include <iprt/cpuset.h>
    4646#include <iprt/log.h>
     47#include <iprt/uuid.h>
     48#include <VBox/err.h>
    4749/* VBox/x86.h not compatible with the Linux kernel sources */
    4850#ifdef RT_OS_LINUX
     
    106108    (   VALID_PTR(pSession) \
    107109     && 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
    108116
    109117
     
    240248static int      supdrvIOCtl_LdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRFREE pReq);
    241249static int      supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL pReq);
     250static int      supdrvIDC_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPDRVIDCREQGETSYM pReq);
    242251static int      supdrvLdrSetR0EP(PSUPDRVDEVEXT pDevExt, void *pvVMMR0, void *pvVMMR0EntryInt, void *pvVMMR0EntryFast, void *pvVMMR0EntryEx);
    243252static void     supdrvLdrUnsetR0EP(PSUPDRVDEVEXT pDevExt);
    244 static void     supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage);
     253static int      supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage);
    245254static void     supdrvLdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage);
    246255static SUPPAGINGMODE supdrvIOCtl_GetPagingMode(void);
     
    276285        if (!rc)
    277286        {
    278             rc = RTSemFastMutexCreate(&pDevExt->mtxGip);
     287            rc = RTSemFastMutexCreate(&pDevExt->mtxComponentFactory);
    279288            if (!rc)
    280289            {
    281                 rc = supdrvGipCreate(pDevExt);
    282                 if (RT_SUCCESS(rc))
     290                rc = RTSemFastMutexCreate(&pDevExt->mtxGip);
     291                if (!rc)
    283292                {
    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;
    286302                }
    287 
    288                 RTSemFastMutexDestroy(pDevExt->mtxGip);
    289                 pDevExt->mtxGip = NIL_RTSEMFASTMUTEX;
     303                RTSemFastMutexDestroy(pDevExt->mtxComponentFactory);
     304                pDevExt->mtxComponentFactory = NIL_RTSEMFASTMUTEX;
    290305            }
    291306            RTSemFastMutexDestroy(pDevExt->mtxLdr);
     
    371386 * @returns IPRT status code.
    372387 * @param   pDevExt     Device extension.
     388 * @param   fUser       Flag indicating whether this is a user or kernel session.
    373389 * @param   ppSession   Where to store the pointer to the session data.
    374390 */
    375 int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION *ppSession)
     391int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, PSUPDRVSESSION *ppSession)
    376392{
    377393    /*
     
    391407            /*pSession->pLdrUsage         = NULL;
    392408            pSession->pPatchUsage       = NULL;
     409            pSession->pVM               = NULL;
    393410            pSession->pUsage            = NULL;
    394411            pSession->pGip              = NULL;
    395412            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            }
    397426
    398427            LogFlow(("Created session %p initial cookie=%#x\n", pSession, pSession->u32Cookie));
     
    569598
    570599    /*
     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    /*
    571640     * Loaded images needs to be dereferenced and possibly freed up.
    572641     */
     
    11641233 * @returns VBox status code.
    11651234 * @retval  VINF_SUCCESS on success.
     1235 * @retval  VERR_INVALID_PARAMETER if the request is invalid.
    11661236 * @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.
    11691237 *
    11701238 * @param   uReq        The request (function) code.
     
    12061274            REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_CONNECT, sizeof(*pReq));
    12071275
    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;
    12091341        }
    12101342
     
    12131345            REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_DISCONNECT, sizeof(*pReqHdr));
    12141346
    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;
    12161353        }
    12171354
    12181355        case SUPDRV_IDC_REQ_GET_SYMBOL:
    12191356        {
    1220             PSUPDRVIDCREQGETSYM pReq;
     1357            PSUPDRVIDCREQGETSYM pReq = (PSUPDRVIDCREQGETSYM)pReqHdr;
    12211358            REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_GET_SYMBOL, sizeof(*pReq));
    12221359
    1223             return VERR_NOT_IMPLEMENTED;
     1360            pReq->Hdr.rc = supdrvIDC_LdrGetSymbol(pDevExt, pSession, pReq);
     1361            return VINF_SUCCESS;
    12241362        }
    12251363
    12261364        case SUPDRV_IDC_REQ_COMPONENT_REGISTER_FACTORY:
    12271365        {
    1228             PSUPDRVIDCREQCOMPREGFACTORY pReq;
     1366            PSUPDRVIDCREQCOMPREGFACTORY pReq = (PSUPDRVIDCREQCOMPREGFACTORY)pReqHdr;
    12291367            REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_COMPONENT_REGISTER_FACTORY, sizeof(*pReq));
    12301368
    1231             return VERR_NOT_IMPLEMENTED;
     1369            pReq->Hdr.rc = SUPR0ComponentRegisterFactory(pSession, pReq->u.In.pFactory);
     1370            return VINF_SUCCESS;
    12321371        }
    12331372
    12341373        case SUPDRV_IDC_REQ_COMPONENT_DEREGISTER_FACTORY:
    12351374        {
    1236             PSUPDRVIDCREQCOMPDEREGFACTORY pReq;
     1375            PSUPDRVIDCREQCOMPDEREGFACTORY pReq = (PSUPDRVIDCREQCOMPDEREGFACTORY)pReqHdr;
    12371376            REQ_CHECK_IDC_SIZE(SUPDRV_IDC_REQ_COMPONENT_DEREGISTER_FACTORY, sizeof(*pReq));
    12381377
    1239             return VERR_NOT_IMPLEMENTED;
     1378            pReq->Hdr.rc = SUPR0ComponentDeregisterFactory(pSession, pReq->u.In.pFactory);
     1379            return VINF_SUCCESS;
    12401380        }
    12411381
     
    22882428    RTSemFastMutexRelease(pDevExt->mtxGip);
    22892429
     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 */
     2452SUPR0DECL(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 */
     2531SUPR0DECL(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 */
     2592SUPR0DECL(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    }
    22902644    return rc;
    22912645}
     
    34463800
    34473801    /*
    3448      * Search the symbol string.
     3802     * Search the symbol strings.
    34493803     */
    34503804    pchStrings = (const char *)((uint8_t *)pImage->pvImage + pImage->offStrTab);
     
    34633817    RTSemFastMutexRelease(pDevExt->mtxLdr);
    34643818    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 */
     3832static 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    }
    34653910    return rc;
    34663911}
     
    35664011 * Adds a usage reference in the specified session of an image.
    35674012 *
     4013 * Called while owning the loader semaphore.
     4014 *
     4015 * @returns VINF_SUCCESS on success and VERR_NO_MEMORY on failure.
    35684016 * @param   pSession    Session in question.
    35694017 * @param   pImage      Image which the session is using.
    35704018 */
    3571 static void supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage)
     4019static int supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage)
    35724020{
    35734021    PSUPDRVLDRUSAGE pUsage;
     
    35834031        {
    35844032            pUsage->cUsage++;
    3585             return;
     4033            return VINF_SUCCESS;
    35864034        }
    35874035        pUsage = pUsage->pNext;
     
    35924040     */
    35934041    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;
    36034048}
    36044049
     
    40894534    int         cLoops = 8;
    40904535    bool        fAsync = false;
    4091     int         rc;
     4536    int         rc = VINF_SUCCESS;
    40924537    uint64_t    offMax = 0;
    40934538    uint64_t    offMin = ~(uint64_t)0;
  • trunk/src/VBox/HostDrivers/Support/SUPDrvIDC.h

    r10264 r10377  
    112112        struct SUPDRVIDCREQCONNECTOUT
    113113        {
    114             /** The version of the IDC interface for this session. */
    115             uint32_t        uVersion;
    116114            /** The support driver session. (An opaque.) */
    117115            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;
    118123        } Out;
    119124    } u;
  • trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h

    r10256 r10377  
    370370    /** Offset of the symbol relative to the image load address. */
    371371    uint32_t        offSymbol;
    372 } SUPLDRSYM, *PSUPLDRSYM;
     372} SUPLDRSYM;
     373/** Pointer to a symbol table entry. */
     374typedef SUPLDRSYM *PSUPLDRSYM;
     375/** Pointer to a const symbol table entry. */
     376typedef SUPLDRSYM const *PCSUPLDRSYM;
    373377
    374378/**
  • trunk/src/VBox/HostDrivers/Support/SUPDrvInternal.h

    r10265 r10377  
    459459
    460460/**
     461 * Component factory registration record.
     462 */
     463typedef 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. */
     476typedef SUPDRVFACTORYREG *PSUPDRVFACTORYREG;
     477/** Pointer to a const component factory registration record. */
     478typedef SUPDRVFACTORYREG const *PCSUPDRVFACTORYREG;
     479
     480
     481/**
    461482 * Registered object.
    462483 * This takes care of reference counting and tracking data for access checks.
     
    539560    /** The group id of the session. (Set by the OS part.) */
    540561    RTGID                       Gid;
    541     /** The process (id) of the session. (Set by the OS part.) */
     562    /** The process (id) of the session. */
    542563    RTPROCESS                   Process;
    543564    /** Which process this session is associated with.
     
    621642     * This CPU is responsible for the updating the common GIP data. */
    622643    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;
    623650} SUPDRVDEVEXT;
    624651
     
    642669int  VBOXCALL   supdrvInitDevExt(PSUPDRVDEVEXT pDevExt);
    643670void VBOXCALL   supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);
    644 int  VBOXCALL   supdrvCreateSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION *ppSession);
     671int  VBOXCALL   supdrvCreateSession(PSUPDRVDEVEXT pDevExt, bool fUser, PSUPDRVSESSION *ppSession);
    645672void VBOXCALL   supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
    646673void VBOXCALL   supdrvCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);
  • trunk/src/VBox/HostDrivers/Support/SUPR0IdcClient.c

    r10258 r10377  
    4949 *
    5050 * @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 */
     58SUPR0DECL(int) SUPR0IdcOpen(PSUPDRVIDCHANDLE pHandle, uint32_t uReqVersion, uint32_t uMinVersion,
     59                            uint32_t *puSessionVersion, uint32_t *puDriverVersion, uint32_t *puDriverRevision)
    5760{
    5861    unsigned uDefaultMinVersion;
     
    6568    AssertPtrReturn(pHandle, VERR_INVALID_POINTER);
    6669    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
    7083    AssertReturn(!uMinVersion || (uMinVersion & UINT32_C(0xffff0000)) == (SUPDRV_IDC_VERSION & UINT32_C(0xffff0000)), VERR_INVALID_PARAMETER);
    7184    AssertReturn(!uReqVersion || (uReqVersion & UINT32_C(0xffff0000)) == (SUPDRV_IDC_VERSION & UINT32_C(0xffff0000)), VERR_INVALID_PARAMETER);
     
    100113    {
    101114        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;
    104121
    105122        /*
     
    108125         */
    109126        if (    VALID_PTR(Req.u.Out.pSession)
    110             &&  Req.u.Out.uVersion >= uMinVersion
    111             &&  (Req.u.Out.uVersion & 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)))
    112129        {
    113130            ASMAtomicCmpXchgPtr((void * volatile *)&g_pMainHandle, pHandle, NULL);
     
    115132        }
    116133
    117         AssertMsgFailed(("pSession=%p uVersion=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));
    118135        rc = VERR_VERSION_MISMATCH;
    119136        SUPR0IdcClose(pHandle);
  • trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp

    r10263 r10377  
    322322     * Create a new session.
    323323     */
    324     rc = supdrvCreateSession(&g_DevExt, &pSession);
     324    rc = supdrvCreateSession(&g_DevExt, true /* fUser */, &pSession);
    325325    if (RT_SUCCESS(rc))
    326326    {
     
    333333            pSession->Gid = pCred->cr_gid;
    334334        }
    335         pSession->Process = RTProcSelf();
    336         pSession->R0Process = RTR0ProcHandleSelf();
    337335
    338336        /*
  • trunk/src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c

    r10263 r10377  
    301301     * Create a new session.
    302302     */
    303     rc = supdrvCreateSession(&g_VBoxDrvFreeBSDDevExt, &pSession);
     303    rc = supdrvCreateSession(&g_VBoxDrvFreeBSDDevExt, true /* fUser */, &pSession);
    304304    if (RT_SUCCESS(rc))
    305305    {
    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; */
    310309        if (ASMAtomicCmpXchgPtr(&pDev->si_drv1, pSession, (void *)0x42))
    311310            return 0;
  • trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c

    r10263 r10377  
    679679     * Call common code for the rest.
    680680     */
    681     rc = supdrvCreateSession(&g_DevExt, (PSUPDRVSESSION *)&pSession);
     681    rc = supdrvCreateSession(&g_DevExt, true /* fUser */, (PSUPDRVSESSION *)&pSession);
    682682    if (!rc)
    683683    {
    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;
    688686    }
    689687
  • trunk/src/VBox/HostDrivers/Support/linux/files_vboxdrv

    r10258 r10377  
    5353    ${PATH_ROOT}/include/iprt/timer.h=>include/iprt/timer.h \
    5454    ${PATH_ROOT}/include/iprt/types.h=>include/iprt/types.h \
     55    ${PATH_ROOT}/include/iprt/uuid.h=>include/iprt/uuid.h \
    5556    ${PATH_ROOT}/include/iprt/nocrt/limits.h=>include/iprt/nocrt/limits.h \
    5657    ${PATH_ROOT}/include/VBox/cdefs.h=>include/VBox/cdefs.h \
     58    ${PATH_ROOT}/include/VBox/err.h=>include/VBox/err.h \
    5759    ${PATH_ROOT}/include/VBox/log.h=>include/VBox/log.h \
    5860    ${PATH_ROOT}/include/VBox/sup.h=>include/VBox/sup.h \
  • trunk/src/VBox/HostDrivers/Support/os2/SUPDrv-os2.cpp

    r10254 r10377  
    151151     * Create a new session.
    152152     */
    153     rc = supdrvCreateSession(&g_DevExt, &pSession);
     153    rc = supdrvCreateSession(&g_DevExt, true /* fUser */, &pSession);
    154154    if (RT_SUCCESS(rc))
    155155    {
    156         pSession->Process = RTProcSelf();
    157         pSession->R0Process = RTR0ProcHandleSelf();
    158156        pSession->sfn = sfn;
    159157
  • trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c

    r10263 r10377  
    420420     * Create a new session.
    421421     */
    422     rc = supdrvCreateSession(&g_DevExt, &pSession);
     422    rc = supdrvCreateSession(&g_DevExt, true /* fUser */, &pSession);
    423423    if (RT_SUCCESS(rc))
    424424    {
     425        pSession->Uid = crgetuid(pCred);
     426        pSession->Gid = crgetgid(pCred);
     427
    425428        pState->pSession = pSession;
    426429        *pDev = makedevice(getmajor(*pDev), iOpenInstance);
     
    440443     * in VBoxDrvSolarisIOCtlSlow() while calling supdrvIOCtl()
    441444     */
    442     rc = supdrvCreateSession(&g_DevExt, &pSession);
     445    rc = supdrvCreateSession(&g_DevExt, true /* fUser */, &pSession);
    443446    if (RT_SUCCESS(rc))
    444447    {
     
    446449        unsigned        iHash;
    447450
    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);
    452453
    453454        /*
  • trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp

    r10265 r10377  
    232232    pFileObj->FsContext = NULL;
    233233    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);
    235240    if (!rc)
    236     {
    237         pSession->Uid       = NIL_RTUID;
    238         pSession->Gid       = NIL_RTGID;
    239         pSession->Process   = RTProcSelf();
    240         pSession->R0Process = RTR0ProcHandleSelf();
    241241        pFileObj->FsContext = pSession;
    242     }
    243242
    244243    NTSTATUS    rcNt = pIrp->IoStatus.Status = VBoxDrvNtErr2NtStatus(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