VirtualBox

Ignore:
Timestamp:
Jul 19, 2012 2:44:57 PM (12 years ago)
Author:
vboxsync
Message:

Additions/solaris/vboxms: try to fix the ::Open and ::Close call-backs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/solaris/Mouse/vboxmouse.c

    r42205 r42230  
    439439    NOREF(fFlag);
    440440    NOREF(pCred);
    441     LogRelFlow((DEVICE_NAME "::Open\n"));
    442 
    443     /*
    444      * Initialize IPRT R0 driver, which internally calls OS-specific r0 init.
    445      */
    446     mutex_enter(&g_OpenNodeState.InitMtx);
    447     if (!g_OpenNodeState.cInits)
    448     {
    449         rc = VbglInit();
    450         if (RT_SUCCESS(rc))
    451         {
    452             rc = VbglGRAlloc((VMMDevRequestHeader **)
    453                              &g_OpenNodeState.pMouseStatusReq,
    454                              sizeof(*g_OpenNodeState.pMouseStatusReq),
    455                              VMMDevReq_GetMouseStatus);
    456             if (RT_FAILURE(rc))
    457                 VbglTerminate();
    458         }
    459     }
    460     ++g_OpenNodeState.cInits;
    461     mutex_exit(&g_OpenNodeState.InitMtx);
    462     if (RT_FAILURE(rc))
    463     {
    464         cmn_err(CE_NOTE, "_init: VbglInit failed. rc=%d\n", rc);
    465         return EINVAL;
    466     }
     441    LogRelFlow((DEVICE_NAME "::Open, pWriteQueue=%p\n", WR(pReadQueue)));
     442
    467443    /*
    468444     * Sanity check on the mode parameter - only open as a driver, not a
     
    471447    if (fMode)
    472448    {
    473         LogRelFlow((DEVICE_NAME "::Open: invalid attempt to clone device."));
     449        LogRel(("::Open: invalid attempt to clone device."));
    474450        return EINVAL;
    475451    }
    476452
    477     if (!ASMAtomicCmpXchgPtr(&g_OpenNodeState.pWriteQueue,
    478                              WR(pReadQueue), NULL))
    479     {
    480         LogRelFlow((DEVICE_NAME "::Open: only one instance allowed."));
    481         return ENXIO;
    482     }
    483453    pState = &g_OpenNodeState;
    484 
     454    mutex_enter(&pState->InitMtx);
    485455    /*
    486      * Create a new session.
     456     * Check and remember our STREAM queue.
    487457     */
    488     if (VbglIsReady())
    489     {
    490         /* Initialise user data for the queues to our state and vice-versa. */
    491         WR(pReadQueue)->q_ptr = (char *)pState;
    492         pReadQueue->q_ptr = (char *)pState;
    493         /* Enable our IRQ handler. */
    494         VbglSetMouseNotifyCallback(vbmsSolNotify, (void *)pState);
    495         qprocson(pReadQueue);
    496         LogRel((DEVICE_NAME "::Open\n"));
    497         return 0;
    498     }
    499 
    500     /* Failed, clean up. */
    501     ASMAtomicWriteNullPtr(&pState->pWriteQueue);
    502 
    503     LogRel((DEVICE_NAME "::Open: VBoxGuestCreateUserSession failed. rc=EFAULT\n"));
    504     return EFAULT;
     458    if (   pState->pWriteQueue
     459        && (pState->pWriteQueue != WR(pReadQueue)))
     460    {
     461        mutex_exit(&pState->InitMtx);
     462        LogRel((DEVICE_NAME "::Open: unexpectedly called with a different queue to previous calls.  Exiting.\n"));
     463        return EINVAL;
     464    }
     465    if (!pState->cInits)
     466    {
     467        /*
     468         * Initialize IPRT R0 driver, which internally calls OS-specific r0
     469         * init, and create a new session.
     470         */
     471        rc = VbglInit();
     472        if (RT_SUCCESS(rc))
     473        {
     474            rc = VbglGRAlloc((VMMDevRequestHeader **)
     475                             &pState->pMouseStatusReq,
     476                             sizeof(*pState->pMouseStatusReq),
     477                             VMMDevReq_GetMouseStatus);
     478            if (RT_FAILURE(rc))
     479                VbglTerminate();
     480            else
     481            {
     482                int rc2;
     483                /* Initialise user data for the queues to our state and
     484                 * vice-versa. */
     485                pState->pWriteQueue = WR(pReadQueue);
     486                WR(pReadQueue)->q_ptr = (char *)pState;
     487                pReadQueue->q_ptr = (char *)pState;
     488                qprocson(pReadQueue);
     489                /* Enable our IRQ handler. */
     490                rc2 = VbglSetMouseNotifyCallback(vbmsSolNotify,
     491                                                 (void *)pState);
     492                if (RT_FAILURE(rc2))
     493                    /* Log the failure.  I may well have not understood what
     494                     * is going on here, and the logging may help me. */
     495                    LogRelFlow(("Failed to install the event handler call-back, rc=%Rrc\n",
     496                                rc2));
     497            }
     498        }
     499    }
     500    if (RT_SUCCESS(rc))
     501        ++pState->cInits;
     502    mutex_exit(&pState->InitMtx);
     503    if (RT_FAILURE(rc))
     504    {
     505        LogRel(("open time initialisation failed. rc=%d\n", rc));
     506        ASMAtomicWriteNullPtr(&pState->pWriteQueue);
     507        return EINVAL;
     508    }
     509    return 0;
    505510}
    506511
     
    571576    PVBMSSTATE pState = (PVBMSSTATE)pReadQueue->q_ptr;
    572577
    573     LogRelFlow((DEVICE_NAME "::Close\n"));
     578    LogRelFlow((DEVICE_NAME "::Close, pWriteQueue=%p\n", WR(pReadQueue)));
    574579    NOREF(fFlag);
    575580    NOREF(pCred);
     
    581586    }
    582587
    583     VbglSetMouseStatus(0);
    584     /* Disable our IRQ handler. */
    585     VbglSetMouseNotifyCallback(NULL, NULL);
    586     qprocsoff(pReadQueue);
    587 
    588     /*
    589      * Close the session.
    590      */
    591     ASMAtomicWriteNullPtr(&pState->pWriteQueue);
    592     pReadQueue->q_ptr = NULL;
    593     mutex_enter(&g_OpenNodeState.InitMtx);
    594     --g_OpenNodeState.cInits;
    595     if (!g_OpenNodeState.cInits)
    596     {
    597         VbglGRFree(&g_OpenNodeState.pMouseStatusReq->header);
     588    mutex_enter(&pState->InitMtx);
     589    --pState->cInits;
     590    if (!pState->cInits)
     591    {
     592        VbglSetMouseStatus(0);
     593        /* Disable our IRQ handler. */
     594        VbglSetMouseNotifyCallback(NULL, NULL);
     595        qprocsoff(pReadQueue);
     596
     597        /*
     598         * Close the session.
     599         */
     600        ASMAtomicWriteNullPtr(&pState->pWriteQueue);
     601        pReadQueue->q_ptr = NULL;
     602        VbglGRFree(&pState->pMouseStatusReq->header);
    598603        VbglTerminate();
    599604    }
    600     mutex_exit(&g_OpenNodeState.InitMtx);
     605    mutex_exit(&pState->InitMtx);
    601606    return 0;
    602607}
     
    632637int vbmsSolWPut(queue_t *pWriteQueue, mblk_t *pMBlk)
    633638{
     639    PVBMSSTATE pState = (PVBMSSTATE)pWriteQueue->q_ptr;
    634640    LogRelFlowFunc((DEVICE_NAME "::"));
    635641    switch (pMBlk->b_datap->db_type)
     
    654660        case M_IOCDATA:
    655661        {
    656             PVBMSSTATE pState = (PVBMSSTATE)pWriteQueue->q_ptr;
    657662            int err;
    658663
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