VirtualBox

Changeset 75746 in vbox


Ignore:
Timestamp:
Nov 26, 2018 6:34:21 PM (6 years ago)
Author:
vboxsync
Message:

GuestControl/service.cpp: Trying to make sense of things again...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/GuestControl/service.cpp

    r75737 r75746  
    137137
    138138    /**
    139      * Allocates the command with an HGCM request. Needs to be free'd using Free().
     139     * Allocates the command with an HGCM request - or put more accurately, it
     140     * duplicates the given HGCM reguest (it does not allocate a HostCommand).
     141     *
     142     * Needs to be freed using Free().
    140143     *
    141144     * @return  IPRT status code.
     
    168171        if (mParmCount)
    169172        {
    170             mpParms = (VBOXHGCMSVCPARM*)RTMemAllocZ(sizeof(VBOXHGCMSVCPARM) * mParmCount);
     173            mpParms = (VBOXHGCMSVCPARM *)RTMemAllocZ(sizeof(VBOXHGCMSVCPARM) * mParmCount);
    171174            if (NULL == mpParms)
    172175                rc = VERR_NO_MEMORY;
     
    193196                        {
    194197                            mpParms[i].u.pointer.addr = RTMemAlloc(mpParms[i].u.pointer.size);
    195                             if (NULL == mpParms[i].u.pointer.addr)
    196                             {
    197                                 rc = VERR_NO_MEMORY;
    198                                 break;
    199                             }
    200                             else
     198                            if (mpParms[i].u.pointer.addr != NULL)
    201199                                memcpy(mpParms[i].u.pointer.addr,
    202200                                       paParms[i].u.pointer.addr,
    203201                                       mpParms[i].u.pointer.size);
     202                            else
     203                                rc = VERR_NO_MEMORY;
    204204                        }
    205205                        else
     
    236236
    237237    /**
    238      * Frees the buffered HGCM request.
    239      *
    240      * @return  IPRT status code.
     238     * Frees the buffered HGCM request (not the HostCommand structure itself).
    241239     */
    242240    void Free(void)
     
    274272
    275273    /**
    276      * Copies data from the buffered HGCM request to the current HGCM request.
     274     * Worker for Assign() that opies data from the buffered HGCM request to the
     275     * current HGCM request.
    277276     *
    278277     * @return  IPRT status code.
     
    299298                if (paDstParms[i].type != mpParms[i].type)
    300299                {
    301                     LogFlowFunc(("Parameter %RU32 type mismatch (got %RU32, expected %RU32)\n",
    302                                  i, paDstParms[i].type, mpParms[i].type));
     300                    LogFunc(("Parameter %RU32 type mismatch (got %RU32, expected %RU32)\n", i, paDstParms[i].type, mpParms[i].type));
    303301                    rc = VERR_INVALID_PARAMETER;
    304302                }
     
    334332                            if (!paDstParms[i].u.pointer.addr)
    335333                                rc = VERR_INVALID_PARAMETER;
    336 
    337                             if (   RT_SUCCESS(rc)
    338                                 && paDstParms[i].u.pointer.size < mpParms[i].u.pointer.size)
     334                            else if (paDstParms[i].u.pointer.size < mpParms[i].u.pointer.size)
    339335                                rc = VERR_BUFFER_OVERFLOW;
    340 
    341                             if (RT_SUCCESS(rc))
    342                             {
     336                            else
    343337                                memcpy(paDstParms[i].u.pointer.addr,
    344338                                       mpParms[i].u.pointer.addr,
    345339                                       mpParms[i].u.pointer.size);
    346                             }
    347 
    348340                            break;
    349341                        }
    350342
    351343                        default:
    352                             LogFlowFunc(("Parameter %RU32 of type %RU32 is not supported yet\n",
    353                                          i, mpParms[i].type));
     344                            LogFunc(("Parameter %RU32 of type %RU32 is not supported yet\n", i, mpParms[i].type));
    354345                            rc = VERR_NOT_SUPPORTED;
    355346                            break;
     
    359350                if (RT_FAILURE(rc))
    360351                {
    361                     LogFlowFunc(("Parameter %RU32 invalid (%Rrc), refusing\n",
    362                                  i, rc));
     352                    LogFunc(("Parameter %RU32 invalid (%Rrc), refusing\n", i, rc));
    363353                    break;
    364354                }
     
    385375                             mMsgType, mParmCount, pConnection->mNumParms));
    386376            /*
    387             * So this call apparently failed because the guest wanted to peek
    388             * how much parameters it has to supply in order to successfully retrieve
    389             * this command. Let's tell him so!
    390             */
     377             * So this call apparently failed because the guest wanted to peek
     378             * how much parameters it has to supply in order to successfully retrieve
     379             * this command. Let's tell him so!
     380             */
    391381            rc = VERR_TOO_MUCH_DATA;
    392382        }
     
    446436    /** Array of HGCM parameters. */
    447437    PVBOXHGCMSVCPARM mpParms;
    448     /** Incoming timestamp (us). */
     438    /** Incoming timestamp (nanoseconds). */
    449439    uint64_t mTimestamp;
    450440} HostCommand;
     
    471461
    472462/**
    473  * Structure for holding a connected guest client
    474  * state.
     463 * Structure for holding a connected guest client state.
    475464 */
    476465typedef struct ClientState
     
    512501    HostCmdListIter Dequeue(HostCmdListIter &curItem)
    513502    {
    514         HostCommand *pHostCmd = (*curItem);
     503        HostCommand *pHostCmd = *curItem;
    515504        AssertPtr(pHostCmd);
    516505
     
    572561
    573562        /* Only process newer commands. */
     563        /** @todo r=bird: This seems extremely bogus given that I cannot see
     564         *        ClientState::mHostCmdTS being set anywhere at all. */
    574565        if (pHostCmd->mTimestamp <= mHostCmdTS)
    575566            return false;
    576567
    577568        /*
    578          * If a sesseion filter is set, only obey those commands we're interested in
     569         * If a session filter is set, only obey those commands we're interested in
    579570         * by applying our context ID filter mask and compare the result with the
    580571         * original context ID.
     
    582573        bool fWant;
    583574        if (mFlags & CLIENTSTATE_FLAG_CONTEXTFILTER)
    584         {
    585575            fWant = (pHostCmd->mContextID & mFilterMask) == mFilterValue;
    586         }
    587576        else /* Client is interested in all commands. */
    588577            fWant = true;
     
    640629    }
    641630
    642     int Run(const ClientConnection *pConnection,
    643                   HostCommand      *pHostCmd)
     631    int Run(ClientConnection const *pConnection,
     632            HostCommand            *pHostCmd)
    644633    {
    645634        AssertPtrReturn(pConnection, VERR_INVALID_POINTER);
    646635        AssertPtrReturn(pHostCmd, VERR_INVALID_POINTER);
    647636
    648         int rc = VINF_SUCCESS;
    649 
    650637        LogFlowFunc(("[Client %RU32] pConnection=%p, mHostCmdRc=%Rrc, mHostCmdTries=%RU32, mPeekCount=%RU32\n",
    651638                      mID, pConnection, mHostCmdRc, mHostCmdTries, mPeekCount));
    652639
    653         mHostCmdRc = SendReply(pConnection, pHostCmd);
     640        int rc = mHostCmdRc = SendReply(pConnection, pHostCmd);
    654641
    655642        LogFlowThisFunc(("[Client %RU32] Processing command %RU32 ended with rc=%Rrc\n", mID, pHostCmd->mMsgType, mHostCmdRc));
    656643
    657644        bool fRemove = false;
    658         if (RT_FAILURE(mHostCmdRc))
     645        if (RT_FAILURE(rc))
    659646        {
    660647            mHostCmdTries++;
     
    668655             *       To not get the actual command if the client actually only wants to peek for
    669656             *       the next command, there needs to be two rounds per try, e.g. 3 rounds = 6 tries.
    670              *
    671              ** @todo Fix the mess stated above. GUEST_MSG_WAIT should be become GUEST_MSG_PEEK, *only*
     657             */
     658            /** @todo Fix the mess stated above. GUEST_MSG_WAIT should be become GUEST_MSG_PEEK, *only*
    672659             *        (and every time) returning the next upcoming host command (if any, blocking). Then
    673660             *        it's up to the client what to do next, either peeking again or getting the actual
    674661             *        host command via an own GUEST_ type message.
    675662             */
    676             if (mHostCmdRc == VERR_TOO_MUCH_DATA)
     663            if (rc == VERR_TOO_MUCH_DATA)
    677664            {
    678665                if (mHostCmdTries == 6)
     
    688675
    689676        LogFlowThisFunc(("[Client %RU32] Tried command %RU32 for %RU32 times, (last result=%Rrc, fRemove=%RTbool)\n",
    690                          mID, pHostCmd->mMsgType, mHostCmdTries, mHostCmdRc, fRemove));
    691 
    692         if (RT_SUCCESS(rc)) /** @todo r=bird: confusing statement+state, rc hasn't been touched since the top and is always VINF_SUCCESS. */
    693             rc = mHostCmdRc;
     677                         mID, pHostCmd->mMsgType, mHostCmdTries, rc, fRemove));
    694678
    695679        if (fRemove)
     
    729713            HostCmdListIter curCmd = mHostCmdList.begin();
    730714            Assert(curCmd != mHostCmdList.end());
    731             HostCommand *pHostCmd = (*curCmd);
     715            HostCommand *pHostCmd = *curCmd;
    732716            AssertPtrReturn(pHostCmd, VERR_INVALID_POINTER);
    733717
     
    865849     * to be able to successfully retrieve.  */
    866850    uint32_t mHostCmdTries;
    867     /** Timestamp (us) of last host command processed. */
     851    /** Timestamp (nanoseconds) of last host command processed.
     852     * @todo r=bird: Where is this set?  */
    868853    uint64_t mHostCmdTS;
    869854    /** Flag indicating whether a client call (GUEST_MSG_WAIT) currently is pending.
     
    10611046
    10621047/**
    1063  * Handles a client which disconnected. This functiond does some
    1064  * internal cleanup as well as sends notifications to the host so
    1065  * that the host can do the same (if required).
     1048 * Handles a client which disconnected.
     1049 *
     1050 * This functiond does some internal cleanup as well as sends notifications to
     1051 * the host so that the host can do the same (if required).
    10661052 *
    10671053 * @return  IPRT status code.
     
    11011087         * via a (multi stage) progress object.
    11021088         */
     1089        /** @todo r=bird: We have RTListForEachSafe for this purpose...  Would save a
     1090         *        few lines and bother here. */
    11031091        HostCommand *pCurCmd = RTListGetFirst(&mHostCmdList, HostCommand, Node);
    11041092        while (pCurCmd)
     
    11521140{
    11531141    /*
    1154      * Lookup client in our list so that we can assign the context ID of
     1142     * Lookup client in our map so that we can assign the context ID of
    11551143     * a command to that client.
    11561144     */
     
    14131401#endif
    14141402    }
     1403    /** @todo r=bird: If pHostCmd->Allocate fails, you leak stuff.  It's not
     1404     *        likely, since it'll only fail if the host gives us an incorrect
     1405     *        parameter list (first param isn't uint32_t) or we're out of memory.
     1406     *        In the latter case, of course, you're not exactly helping...  */
    14151407
    14161408    return rc;
     
    14181410
    14191411/**
    1420  * @interface_method_impl{VBOXHGCMSVCFNTABLE,pfnCall}
     1412 * Worker for svcCall() that helps implement VBOXHGCMSVCFNTABLE::pfnCall.
    14211413 *
    14221414 * @note    All functions which do not involve an unreasonable delay will be
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