VirtualBox

Changeset 97610 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 18, 2022 5:29:35 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154654
Message:

Guest Control/Main: Also catch (and handle) OOM situations in GuestFile notification callbacks better.

File:
1 edited

Legend:

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

    r97609 r97610  
    534534        case GUEST_FILE_NOTIFYTYPE_READ:
    535535        {
    536             if (pSvcCbData->mParms == 4)
     536            ASSERT_GUEST_MSG_STMT_BREAK(pSvcCbData->mParms == 4, ("mParms=%u\n", pSvcCbData->mParms),
     537                                        vrc = VERR_WRONG_PARAMETER_COUNT);
     538            ASSERT_GUEST_MSG_STMT_BREAK(pSvcCbData->mpaParms[idx].type == VBOX_HGCM_SVC_PARM_PTR,
     539                                        ("type=%u\n", pSvcCbData->mpaParms[idx].type),
     540                                        vrc = VERR_WRONG_PARAMETER_TYPE);
     541
     542            vrc = HGCMSvcGetPv(&pSvcCbData->mpaParms[idx++], &dataCb.u.read.pvData, &dataCb.u.read.cbData);
     543            if (RT_FAILURE(vrc))
     544                break;
     545
     546            const uint32_t cbRead = dataCb.u.read.cbData;
     547            Log3ThisFunc(("cbRead=%RU32\n", cbRead));
     548
     549            AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     550            mData.mOffCurrent += cbRead; /* Bogus for readAt, which is why we've got GUEST_FILE_NOTIFYTYPE_READ_OFFSET. */
     551            alock.release();
     552
     553            try
    537554            {
    538                 vrc = HGCMSvcGetPv(&pSvcCbData->mpaParms[idx++], &dataCb.u.read.pvData,
    539                                   &dataCb.u.read.cbData);
    540                 if (RT_FAILURE(vrc))
    541                     break;
    542 
    543                 const uint32_t cbRead = dataCb.u.read.cbData;
    544 
    545                 Log3ThisFunc(("cbRead=%RU32\n", cbRead));
    546 
    547                 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    548 
    549                 mData.mOffCurrent += cbRead; /* Bogus for readAt, which is why we've got GUEST_FILE_NOTIFYTYPE_READ_OFFSET. */
    550 
    551                 alock.release();
    552 
    553555                com::SafeArray<BYTE> data((size_t)cbRead);
     556                AssertBreakStmt(data.size() == cbRead, vrc = VERR_NO_MEMORY);
    554557                data.initFrom((BYTE *)dataCb.u.read.pvData, cbRead);
    555 
    556558                ::FireGuestFileReadEvent(mEventSource, mSession, this, mData.mOffCurrent, cbRead, ComSafeArrayAsInParam(data));
     559            }
     560            catch (std::bad_alloc &)
     561            {
     562                vrc = VERR_NO_MEMORY;
    557563            }
    558564            break;
     
    567573                                        vrc = VERR_WRONG_PARAMETER_TYPE);
    568574            ASSERT_GUEST_MSG_STMT_BREAK(pSvcCbData->mpaParms[idx + 1].type == VBOX_HGCM_SVC_PARM_64BIT,
    569                                         ("type=%u\n", pSvcCbData->mpaParms[idx].type),
     575                                        ("type=%u\n", pSvcCbData->mpaParms[idx + 1].type),
    570576                                        vrc = VERR_WRONG_PARAMETER_TYPE);
    571577            BYTE const * const pbData = (BYTE const *)pSvcCbData->mpaParms[idx].u.pointer.addr;
     
    583589            {
    584590                com::SafeArray<BYTE> data((size_t)cbRead);
     591                AssertBreakStmt(data.size() == cbRead, vrc = VERR_NO_MEMORY);
    585592                data.initFrom(pbData, cbRead);
    586593                ::FireGuestFileReadEvent(mEventSource, mSession, this, offNew, cbRead, ComSafeArrayAsInParam(data));
     
    596603        case GUEST_FILE_NOTIFYTYPE_WRITE:
    597604        {
    598             if (pSvcCbData->mParms == 4)
    599             {
    600                 vrc = HGCMSvcGetU32(&pSvcCbData->mpaParms[idx++], &dataCb.u.write.cbWritten);
    601                 if (RT_FAILURE(vrc))
    602                     break;
    603 
    604                 const uint32_t cbWritten = dataCb.u.write.cbWritten;
    605 
    606                 Log3ThisFunc(("cbWritten=%RU32\n", cbWritten));
    607 
    608                 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    609 
    610                 mData.mOffCurrent += cbWritten; /* Bogus for writeAt and append mode, thus GUEST_FILE_NOTIFYTYPE_WRITE_OFFSET. */
    611 
    612                 alock.release();
    613 
    614                 ::FireGuestFileWriteEvent(mEventSource, mSession, this, mData.mOffCurrent, cbWritten);
    615             }
     605            ASSERT_GUEST_MSG_STMT_BREAK(pSvcCbData->mParms == 4, ("mParms=%u\n", pSvcCbData->mParms),
     606                                        vrc = VERR_WRONG_PARAMETER_COUNT);
     607            ASSERT_GUEST_MSG_STMT_BREAK(pSvcCbData->mpaParms[idx].type == VBOX_HGCM_SVC_PARM_32BIT,
     608                                        ("type=%u\n", pSvcCbData->mpaParms[idx].type),
     609                                        vrc = VERR_WRONG_PARAMETER_TYPE);
     610
     611            uint32_t const cbWritten = pSvcCbData->mpaParms[idx].u.uint32;
     612
     613            Log3ThisFunc(("cbWritten=%RU32\n", cbWritten));
     614
     615            AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     616            mData.mOffCurrent += cbWritten; /* Bogus for writeAt and append mode, thus GUEST_FILE_NOTIFYTYPE_WRITE_OFFSET. */
     617            alock.release();
     618
     619            ::FireGuestFileWriteEvent(mEventSource, mSession, this, mData.mOffCurrent, cbWritten);
    616620            break;
    617621        }
     
    644648        case GUEST_FILE_NOTIFYTYPE_SEEK:
    645649        {
    646             if (pSvcCbData->mParms == 4)
    647             {
    648                 vrc = HGCMSvcGetU64(&pSvcCbData->mpaParms[idx++], &dataCb.u.seek.uOffActual);
    649                 if (RT_FAILURE(vrc))
    650                     break;
    651 
    652                 Log3ThisFunc(("uOffActual=%RU64\n", dataCb.u.seek.uOffActual));
    653 
    654                 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    655 
    656                 mData.mOffCurrent = dataCb.u.seek.uOffActual;
    657 
    658                 alock.release();
    659 
    660                 ::FireGuestFileOffsetChangedEvent(mEventSource, mSession, this, dataCb.u.seek.uOffActual, 0 /* Processed */);
    661             }
     650            ASSERT_GUEST_MSG_STMT_BREAK(pSvcCbData->mParms == 4, ("mParms=%u\n", pSvcCbData->mParms),
     651                                        vrc = VERR_WRONG_PARAMETER_COUNT);
     652
     653            vrc = HGCMSvcGetU64(&pSvcCbData->mpaParms[idx++], &dataCb.u.seek.uOffActual);
     654            if (RT_FAILURE(vrc))
     655                break;
     656
     657            Log3ThisFunc(("uOffActual=%RU64\n", dataCb.u.seek.uOffActual));
     658
     659            AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     660            mData.mOffCurrent = dataCb.u.seek.uOffActual;
     661            alock.release();
     662
     663            ::FireGuestFileOffsetChangedEvent(mEventSource, mSession, this, dataCb.u.seek.uOffActual, 0 /* Processed */);
    662664            break;
    663665        }
     
    685687    }
    686688
    687     if (RT_SUCCESS(vrc))
    688     {
    689         try
     689    try
     690    {
     691        if (RT_SUCCESS(vrc))
    690692        {
    691693            GuestWaitEventPayload payload(dataCb.uType, &dataCb, sizeof(dataCb));
     
    694696            signalWaitEventInternal(pCbCtx, vrcGuest, &payload);
    695697        }
    696         catch (int vrcEx) /* Thrown by GuestWaitEventPayload constructor. */
    697         {
    698             vrc = vrcEx;
    699         }
     698        else /* OOM situation, wrong HGCM parameters or smth. not expected. */
     699        {
     700            /* Ignore rc, as the event to signal might not be there (anymore). */
     701            signalWaitEventInternalEx(pCbCtx, vrc, 0 /* guestRc */, NULL /* pPayload */);
     702        }
     703    }
     704    catch (int vrcEx) /* Thrown by GuestWaitEventPayload constructor. */
     705    {
     706        /* Also try to signal the waiter, to let it know of the OOM situation.
     707         * Ignore rc, as the event to signal might not be there (anymore). */
     708        signalWaitEventInternalEx(pCbCtx, vrcEx, 0 /* guestRc */, NULL /* pPayload */);
     709        vrc = vrcEx;
    700710    }
    701711
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