VirtualBox

Changeset 55353 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Apr 21, 2015 1:10:25 PM (10 years ago)
Author:
vboxsync
Message:

include/VBox/HostServices/Service.h: adjusted Message implementation to not allow callers to reallocate HGCM pointers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/HostServices/Service.h

    r50561 r55353  
    4141class Message
    4242{
     43    /* Contains a copy of HGCM parameters. */
    4344public:
    4445    Message(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[])
     
    4748        , m_paParms(0)
    4849    {
    49         setData(uMsg, cParms, aParms);
     50        initData(uMsg, cParms, aParms);
    5051    }
    5152    ~Message()
     
    7273        }
    7374
    74         int rc = copyParms(cParms, m_paParms, &aParms[0], false /* fCreatePtrs */);
     75        int rc = copyParmsInternal(cParms, m_paParms, &aParms[0], false /* fCreatePtrs */);
    7576
    7677//        if (RT_FAILURE(rc))
    7778//            cleanup(aParms);
    78         return rc;
    79     }
    80     int setData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[])
    81     {
    82         AssertReturn(cParms < 256, VERR_INVALID_PARAMETER);
    83         AssertPtrNullReturn(aParms, VERR_INVALID_PARAMETER);
    84 
    85         /* Cleanup old messages. */
    86         cleanup();
    87 
    88         m_uMsg = uMsg;
    89         m_cParms = cParms;
    90 
    91         if (cParms > 0)
    92         {
    93             m_paParms = (VBOXHGCMSVCPARM*)RTMemAllocZ(sizeof(VBOXHGCMSVCPARM) * m_cParms);
    94             if (!m_paParms)
    95                 return VERR_NO_MEMORY;
    96         }
    97 
    98         int rc = copyParms(cParms, &aParms[0], m_paParms, true /* fCreatePtrs */);
    99 
    100         if (RT_FAILURE(rc))
    101             cleanup();
    102 
    10379        return rc;
    10480    }
     
    137113    }
    138114
    139     int copyParms(uint32_t cParms, PVBOXHGCMSVCPARM paParmsSrc, PVBOXHGCMSVCPARM paParmsDst, bool fCreatePtrs) const
     115    int copyParms(uint32_t cParms, PVBOXHGCMSVCPARM paParmsSrc, PVBOXHGCMSVCPARM paParmsDst) const
     116    {
     117        return copyParmsInternal(cParms, paParmsSrc, paParmsDst, false /* fCreatePtrs */);
     118    }
     119
     120private:
     121    uint32_t m_uMsg;
     122    uint32_t m_cParms;
     123    PVBOXHGCMSVCPARM m_paParms;
     124
     125    int initData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[])
     126    {
     127        AssertReturn(cParms < 256, VERR_INVALID_PARAMETER);
     128        AssertPtrNullReturn(aParms, VERR_INVALID_PARAMETER);
     129
     130        /* Cleanup old messages. */
     131        cleanup();
     132
     133        m_uMsg = uMsg;
     134        m_cParms = cParms;
     135
     136        if (cParms > 0)
     137        {
     138            m_paParms = (VBOXHGCMSVCPARM*)RTMemAllocZ(sizeof(VBOXHGCMSVCPARM) * m_cParms);
     139            if (!m_paParms)
     140                return VERR_NO_MEMORY;
     141        }
     142
     143        int rc = copyParmsInternal(cParms, &aParms[0], m_paParms, true /* fCreatePtrs */);
     144
     145        if (RT_FAILURE(rc))
     146            cleanup();
     147
     148        return rc;
     149    }
     150
     151    int copyParmsInternal(uint32_t cParms, PVBOXHGCMSVCPARM paParmsSrc, PVBOXHGCMSVCPARM paParmsDst, bool fCreatePtrs) const
    140152    {
    141153        int rc = VINF_SUCCESS;
     
    219231        m_uMsg = 0;
    220232    }
    221 
    222 protected:
    223     uint32_t m_uMsg;
    224     uint32_t m_cParms;
    225     PVBOXHGCMSVCPARM m_paParms;
    226233};
    227234
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