VirtualBox

Changeset 85999 in vbox for trunk


Ignore:
Timestamp:
Sep 2, 2020 2:38:09 PM (4 years ago)
Author:
vboxsync
Message:

Shared Clipboard/Host Service: Use and check for a context ID (CID) in ShClSvcGuestDataRequest() / shClSvcClientWriteData() for old(er) Guest Additions. Untested. bugref:9437

Location:
trunk/src/VBox/HostServices/SharedClipboard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-internal.h

    r85980 r85999  
    9999
    100100/**
     101 * Strucutre for keeping legacy state, required for keeping backwards compatibility
     102 * to old(er) Guest Additions.
     103 */
     104typedef struct SHCLCLIENTLEGACYSTATE
     105{
     106    /** Context ID required for an incoming VBOX_SHCL_GUEST_FN_DATA_WRITE call. Set to UINT64_MAX if not in use.
     107     *  Required for:
     108     *      - Guest Additions < 6.1. */
     109    uint64_t idCtxWriteData;
     110} SHCLCLIENTLEGACYSTATE;
     111
     112/**
    101113 * Structure for keeping generic client state data within the Shared Clipboard host service.
    102114 * This structure needs to be serializable by SSM (must be a POD type).
     
    123135    /** Client state flags of type SHCLCLIENTSTATE_FLAGS_. */
    124136    uint32_t                fFlags;
     137    /** Legacy cruft we have to keep to support old(er) Guest Additions. */
     138    SHCLCLIENTLEGACYSTATE   Legacy;
    125139    /** POD (plain old data) state. */
    126140    SHCLCLIENTPODSTATE      POD;
     
    149163#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    150164    /** Transfer contextdata. */
    151     SHCLTRANSFERCTX          TransferCtx;
     165    SHCLTRANSFERCTX             TransferCtx;
    152166#endif
    153167    /** Structure for keeping the client's pending (deferred return) state.
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc.cpp

    r85987 r85999  
    12431243                LogFlowFunc(("fFormats=%#x -> fFormat=%#x, idEvent=%#x\n", fFormats, fFormat, idEvent));
    12441244
    1245                 /*
    1246                  * Format the message.
    1247                  */
    1248                 if (pMsg->idMsg == VBOX_SHCL_HOST_MSG_READ_DATA_CID)
    1249                     HGCMSvcSetU64(&pMsg->aParms[0],
    1250                                   VBOX_SHCL_CONTEXTID_MAKE(pClient->State.uSessionID, pClient->EventSrc.uID, idEvent));
    1251                 else
    1252                     HGCMSvcSetU32(&pMsg->aParms[0], VBOX_SHCL_HOST_MSG_READ_DATA);
    1253                 HGCMSvcSetU32(&pMsg->aParms[1], fFormat);
    1254 
    1255                 shClSvcMsgAdd(pClient, pMsg, true /* fAppend */);
     1245                const uint64_t uCID = VBOX_SHCL_CONTEXTID_MAKE(pClient->State.uSessionID, pClient->EventSrc.uID, idEvent);
    12561246
    12571247                rc = VINF_SUCCESS;
     1248
     1249                /* Save the context ID in our legacy cruft if we have to deal with old(er) Guest Additions (< 6.1.). */
     1250                if (!(pClient->State.fGuestFeatures0 & VBOX_SHCL_GF_0_CONTEXT_ID))
     1251                {
     1252                    /* Only one data request at a time is supported. */
     1253                    AssertStmt(pClient->State.Legacy.idCtxWriteData == UINT64_MAX, rc = VERR_WRONG_ORDER);
     1254                    if (RT_SUCCESS(rc))
     1255                        pClient->State.Legacy.idCtxWriteData = uCID;
     1256                }
     1257
     1258                if (RT_SUCCESS(rc))
     1259                {
     1260                    /*
     1261                     * Format the message.
     1262                     */
     1263                    if (pMsg->idMsg == VBOX_SHCL_HOST_MSG_READ_DATA_CID)
     1264                        HGCMSvcSetU64(&pMsg->aParms[0], uCID);
     1265                    else
     1266                        HGCMSvcSetU32(&pMsg->aParms[0], VBOX_SHCL_HOST_MSG_READ_DATA);
     1267                    HGCMSvcSetU32(&pMsg->aParms[1], fFormat);
     1268
     1269                    shClSvcMsgAdd(pClient, pMsg, true /* fAppend */);
     1270                }
    12581271            }
    12591272            else
     
    12611274
    12621275            RTCritSectLeave(&pClient->CritSect);
     1276
     1277            if (RT_FAILURE(rc))
     1278                shClSvcMsgFree(pClient, pMsg);
    12631279        }
    12641280        else
     
    13111327    LogFlowFuncEnter();
    13121328
    1313     SHCLEVENTID idEvent;
    1314     if (!(pClient->State.fGuestFeatures0 & VBOX_SHCL_GF_0_CONTEXT_ID)) /* Legacy, Guest Additions < 6.1. */
    1315     {
    1316         /* Older Guest Additions (<= VBox 6.0) did not have any context ID handling, so we ASSUME that the last event registered
    1317          * is the one we want to handle (as this all was a synchronous protocol anyway). */
    1318         idEvent = ShClEventGetLast(&pClient->EventSrc);
    1319     }
    1320     else
    1321         idEvent = VBOX_SHCL_CONTEXTID_GET_EVENT(pCmdCtx->uContextID);
    1322 
    1323     if (idEvent == NIL_SHCLEVENTID) /* Event not found? Bail out early. */
    1324         return VERR_NOT_FOUND;
     1329    const SHCLEVENTID idEvent = VBOX_SHCL_CONTEXTID_GET_EVENT(pCmdCtx->uContextID);
     1330
     1331    AssertMsgReturn(idEvent != NIL_SHCLEVENTID,
     1332                    ("Event %RU64 empty within supplied context ID\n", idEvent), VERR_WRONG_ORDER);
     1333#ifdef VBOX_STRICT
     1334    AssertMsgReturn(ShClEventGet(&pClient->EventSrc, idEvent) != NULL,
     1335                    ("Event %RU64 not found, even if context ID was around\n", idEvent), VERR_NOT_FOUND);
     1336#endif
    13251337
    13261338    int rc = VINF_SUCCESS;
     
    16701682        ASSERT_GUEST_RETURN(paParms[iParm].type == VBOX_HGCM_SVC_PARM_64BIT, VERR_WRONG_PARAMETER_TYPE);
    16711683        cmdCtx.uContextID = paParms[iParm].u.uint64;
    1672         uint64_t const idCtxExpected = VBOX_SHCL_CONTEXTID_MAKE(pClient->State.uSessionID, pClient->EventSrc.uID,
    1673                                                                 VBOX_SHCL_CONTEXTID_GET_EVENT(cmdCtx.uContextID));
    1674         ASSERT_GUEST_MSG_RETURN(cmdCtx.uContextID == idCtxExpected,
    1675                                 ("Wrong context ID: %#RX64, expected %#RX64\n", cmdCtx.uContextID, idCtxExpected),
    1676                                 VERR_INVALID_CONTEXT);
    16771684        iParm++;
    16781685    }
    1679     else
    1680     {
    1681         /** @todo supply CID from client state? Setting it in ShClSvcGuestDataRequest? */
    1682     }
     1686    else /* Older Guest Additions (< 6.1) did not supply a context ID. Dig it out of our legacy cruft. */
     1687    {
     1688        cmdCtx.uContextID = pClient->State.Legacy.idCtxWriteData;
     1689        pClient->State.Legacy.idCtxWriteData = UINT64_MAX; /* Reset. */
     1690    }
     1691
     1692    uint64_t const idCtxExpected = VBOX_SHCL_CONTEXTID_MAKE(pClient->State.uSessionID, pClient->EventSrc.uID,
     1693                                                            VBOX_SHCL_CONTEXTID_GET_EVENT(cmdCtx.uContextID));
     1694    ASSERT_GUEST_MSG_RETURN(cmdCtx.uContextID == idCtxExpected,
     1695                            ("Wrong context ID: %#RX64, expected %#RX64\n", cmdCtx.uContextID, idCtxExpected),
     1696                            VERR_INVALID_CONTEXT);
     1697
    16831698    if (cParms == VBOX_SHCL_CPARMS_DATA_WRITE_61B)
    16841699    {
     
    21102125#endif
    21112126
    2112 
     2127    pClientState->Legacy.idCtxWriteData    = UINT64_MAX;
    21132128}
    21142129
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