VirtualBox

Ignore:
Timestamp:
Oct 14, 2021 9:01:31 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
147506
Message:

HGCM: Some updates for bugref:6724.

File:
1 edited

Legend:

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

    r91100 r91748  
    213213            , idxCategory(a_idxCategory)
    214214            , cPendingCalls(0)
     215            , m_fGuestAccessible(false)
    215216        {
    216217            Assert(idxCategory < HGCM_CLIENT_CATEGORY_MAX);
     
    219220
    220221        int Init(HGCMService *pSvc);
     222
     223        /** Lookups a client object by its handle. */
     224        static HGCMClient *ReferenceByHandle(uint32_t idClient)
     225        {
     226            return (HGCMClient *)hgcmObjReference(idClient, HGCMOBJ_CLIENT);
     227        }
     228
     229        /** Lookups a client object by its handle and makes sure that it's accessible to the guest. */
     230        static HGCMClient *ReferenceByHandleForGuest(uint32_t idClient)
     231        {
     232            HGCMClient *pClient = (HGCMClient *)hgcmObjReference(idClient, HGCMOBJ_CLIENT);
     233            if (pClient)
     234            {
     235                if (RT_LIKELY(pClient->m_fGuestAccessible))
     236                    return pClient;
     237                pClient->Dereference();
     238            }
     239            return NULL;
     240        }
     241
     242        /** Make the client object accessible to the guest. */
     243        void makeAccessibleToGuest()
     244        {
     245            ASMAtomicWriteBool(&m_fGuestAccessible, true);
     246        }
    221247
    222248        /** Service that the client is connected to. */
     
    235261        /** Number of pending calls. */
    236262        uint32_t volatile cPendingCalls;
     263
     264    protected:
     265        /** Set if the client is accessible to the guest, clear if not. */
     266        bool volatile m_fGuestAccessible;
    237267
    238268    private: /* none of this: */
     
    675705                LogFlowFunc(("SVC_MSG_CONNECT u32ClientId = %d\n", pMsg->u32ClientId));
    676706
    677                 HGCMClient *pClient = (HGCMClient *)hgcmObjReference(pMsg->u32ClientId, HGCMOBJ_CLIENT);
     707                HGCMClient *pClient = HGCMClient::ReferenceByHandle(pMsg->u32ClientId);
    678708
    679709                if (pClient)
     
    719749                             pMsg->u32ClientId, pMsg->u32Function, pMsg->cParms, pMsg->paParms));
    720750
    721                 HGCMClient *pClient = (HGCMClient *)hgcmObjReference(pMsg->u32ClientId, HGCMOBJ_CLIENT);
     751                HGCMClient *pClient = HGCMClient::ReferenceByHandleForGuest(pMsg->u32ClientId);
    722752
    723753                if (pClient)
     
    741771                LogFlowFunc(("SVC_MSG_GUESTCANCELLED idClient = %d\n", pMsg->idClient));
    742772
    743                 HGCMClient *pClient = (HGCMClient *)hgcmObjReference(pMsg->idClient, HGCMOBJ_CLIENT);
     773                HGCMClient *pClient = HGCMClient::ReferenceByHandleForGuest(pMsg->idClient);
    744774
    745775                if (pClient)
     
    771801                LogFlowFunc(("SVC_MSG_LOADSTATE\n"));
    772802
    773                 HGCMClient *pClient = (HGCMClient *)hgcmObjReference(pMsg->u32ClientId, HGCMOBJ_CLIENT);
     803                HGCMClient *pClient = HGCMClient::ReferenceByHandle(pMsg->u32ClientId);
    774804
    775805                if (pClient)
     
    804834                LogFlowFunc(("SVC_MSG_SAVESTATE\n"));
    805835
    806                 HGCMClient *pClient = (HGCMClient *)hgcmObjReference(pMsg->u32ClientId, HGCMOBJ_CLIENT);
     836                HGCMClient *pClient = HGCMClient::ReferenceByHandle(pMsg->u32ClientId);
    807837
    808838                rc = VINF_SUCCESS;
     
    940970        trying to disconnect it. */
    941971     int rc = VERR_NOT_FOUND;
    942      HGCMClient * const pClient = (HGCMClient *)hgcmObjReference(idClient, HGCMOBJ_CLIENT);
     972     HGCMClient * const pClient = HGCMClient::ReferenceByHandle(idClient);
    943973     if (pClient)
    944974     {
     
    14831513        {
    14841514            uint32_t const     idClient = pSvc->m_paClientIds[0];
    1485             HGCMClient * const pClient  = (HGCMClient *)hgcmObjReference(idClient, HGCMOBJ_CLIENT);
     1515            HGCMClient * const pClient  = HGCMClient::ReferenceByHandle(idClient);
    14861516            Assert(pClient);
    14871517            LogFlowFunc(("handle %d/%p\n", pSvc->m_paClientIds[0], pClient));
     
    17891819
    17901820        ReferenceService();
     1821
     1822        /* The guest may now use this client object. */
     1823        pClient->makeAccessibleToGuest();
    17911824    }
    17921825    else
     
    23162349                             pMsg->u32ClientId));
    23172350
    2318                 HGCMClient *pClient = (HGCMClient *)hgcmObjReference(pMsg->u32ClientId, HGCMOBJ_CLIENT);
     2351                HGCMClient *pClient = HGCMClient::ReferenceByHandle(pMsg->u32ClientId);
    23192352
    23202353                if (!pClient)
     
    27682801
    27692802    /* Resolve the client handle to the client instance pointer. */
    2770     HGCMClient *pClient = (HGCMClient *)hgcmObjReference(u32ClientId, HGCMOBJ_CLIENT);
     2803    HGCMClient *pClient = HGCMClient::ReferenceByHandleForGuest(u32ClientId);
    27712804
    27722805    if (pClient)
     
    27982831
    27992832    /* Resolve the client handle to the client instance pointer. */
    2800     HGCMClient *pClient = (HGCMClient *)hgcmObjReference(idClient, HGCMOBJ_CLIENT);
     2833    HGCMClient *pClient = HGCMClient::ReferenceByHandleForGuest(idClient);
    28012834
    28022835    if (pClient)
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette