VirtualBox

Changeset 92866 in vbox


Ignore:
Timestamp:
Dec 10, 2021 2:51:11 PM (3 years ago)
Author:
vboxsync
Message:

Guest Control/Main: When processing service callback messages for guest sessions, do the actual (write) locking much further down in GuestSession::i_setSessionStatus(), so that it can release the write lock right before firing off GuestSessionStateChanged events. This is needed in order to make session ID lookups via IGuestSessionStateChangedEvent::Id getter possible (takes the read lock).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp

    r92822 r92866  
    13151315}
    13161316
    1317 int GuestSession::i_dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
     1317/**
     1318 * Main handler for guest session messages from the guest.
     1319 *
     1320 * @returns VBox status code.
     1321 * @param   pCbCtx              Host callback context from HGCM service.
     1322 * @param   pSvcCbData          HGCM service callback data.
     1323 *
     1324 * @note    No locking!
     1325 */
     1326int GuestSession::i_dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData)
    13181327{
    13191328    AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
    1320     AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
    1321 
    1322     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1329    AssertPtrReturn(pSvcCbData, VERR_INVALID_POINTER);
    13231330
    13241331    LogFlowThisFunc(("sessionID=%RU32, CID=%RU32, uMessage=%RU32, pSvcCb=%p\n",
    1325                      mData.mSession.mID, pCbCtx->uContextID, pCbCtx->uMessage, pSvcCb));
     1332                     mData.mSession.mID, pCbCtx->uContextID, pCbCtx->uMessage, pSvcCbData));
    13261333    int rc;
    13271334    switch (pCbCtx->uMessage)
     
    13341341        case GUEST_MSG_SESSION_NOTIFY: /* Guest Additions >= 4.3.0. */
    13351342        {
    1336             rc = i_onSessionStatusChange(pCbCtx, pSvcCb);
     1343            rc = i_onSessionStatusChange(pCbCtx, pSvcCbData);
    13371344            break;
    13381345        }
    13391346
    13401347        default:
    1341             rc = dispatchGeneric(pCbCtx, pSvcCb);
     1348            rc = dispatchGeneric(pCbCtx, pSvcCbData);
    13421349            break;
    13431350    }
     
    18341841}
    18351842
    1836 /** No locking! */
     1843/**
     1844 * Handles guest session status changes from the guest.
     1845 *
     1846 * @returns VBox status code.
     1847 * @param   pCbCtx              Host callback context from HGCM service.
     1848 * @param   pSvcCbData          HGCM service callback data.
     1849 *
     1850 * @note    Takes the read lock (for session ID lookup).
     1851 */
    18371852int GuestSession::i_onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData)
    18381853{
     
    18501865    vrc = HGCMSvcGetU32(&pSvcCbData->mpaParms[2], &dataCb.uResult);
    18511866    AssertRCReturn(vrc, vrc);
     1867
     1868    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    18521869
    18531870    LogFlowThisFunc(("ID=%RU32, uType=%RU32, rcGuest=%Rrc\n",
     
    19161933    }
    19171934
     1935    /* Leave the lock, as i_setSessionStatus() below will require a write lock for actually
     1936     * committing the session state. */
     1937    alock.release();
     1938
    19181939    if (RT_SUCCESS(vrc))
    19191940    {
     
    26432664}
    26442665
    2645 /* Does not do locking; caller is responsible for that! */
     2666/**
     2667 * Sets the guest session's current status.
     2668 *
     2669 * @returns VBox status code.
     2670 * @param   sessionStatus       Session status to set.
     2671 * @param   sessionRc           Session result to set (for error handling).
     2672 *
     2673 * @note    Takes the write lock.
     2674 */
    26462675int GuestSession::i_setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc)
    26472676{
     
    26582687    else
    26592688        AssertMsg(RT_SUCCESS(sessionRc), ("Guest rc must not be an error (%Rrc)\n", sessionRc));
     2689
     2690    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    26602691
    26612692    int vrc = VINF_SUCCESS;
     
    26762707                                    i_guestErrorToString(sessionRc));
    26772708        AssertRC(rc2);
     2709
     2710        alock.release(); /* Release lock before firing off event. */
    26782711
    26792712        ::FireGuestSessionStateChangedEvent(mEventSource, this, mData.mSession.mID, sessionStatus, errorInfo);
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