VirtualBox

Changeset 81590 in vbox for trunk/include


Ignore:
Timestamp:
Oct 30, 2019 2:13:37 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134345
Message:

pdmdev.h: Adding type-safer PDMDEVINS_2_DATA and PDMDEVINS_2_DATA_CC macros that replaces PDMINS_2_DATA and PDMINS_2_DATA_CC for device instances. On modern compilers these macros will check the size type against the size in the device registration structure, though only in strict builds of course. bugref:9218

Location:
trunk/include/VBox/vmm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmdev.h

    r81575 r81590  
    57255725
    57265726
     5727/** @def PDMDEVINS_2_DATA
     5728 * This is a safer edition of PDMINS_2_DATA that checks that the size of the
     5729 * target type is same as PDMDEVREG::cbInstanceShared in strict builds.
     5730 *
     5731 * @note Do no use this macro in common code working on a core structure which
     5732 *       device specific code has expanded.
     5733 */
     5734#if defined(VBOX_STRICT) && defined(RT_COMPILER_SUPPORTS_LAMBDA)
     5735# define PDMDEVINS_2_DATA(a_pDevIns, a_PtrType)  \
     5736    ([](PPDMDEVINS a_pLambdaDevIns) -> a_PtrType \
     5737    { \
     5738        a_PtrType pLambdaRet = (a_PtrType)(a_pLambdaDevIns)->CTX_SUFF(pvInstanceData); \
     5739        Assert(sizeof(*pLambdaRet) == a_pLambdaDevIns->pReg->cbInstanceShared); \
     5740        return pLambdaRet; \
     5741    }(a_pDevIns))
     5742#else
     5743# define PDMDEVINS_2_DATA(a_pDevIns, a_PtrType)  ( (a_PtrType)(a_pDevIns)->CTX_SUFF(pvInstanceData) )
     5744#endif
     5745
     5746/** @def PDMDEVINS_2_DATA_CC
     5747 * This is a safer edition of PDMINS_2_DATA_CC that checks that the size of the
     5748 * target type is same as PDMDEVREG::cbInstanceCC in strict builds.
     5749 *
     5750 * @note Do no use this macro in common code working on a core structure which
     5751 *       device specific code has expanded.
     5752 */
     5753#if defined(VBOX_STRICT) && defined(RT_COMPILER_SUPPORTS_LAMBDA)
     5754# define PDMDEVINS_2_DATA_CC(a_pDevIns, a_PtrType)  \
     5755    ([](PPDMDEVINS a_pLambdaDevIns) -> a_PtrType \
     5756    { \
     5757        a_PtrType pLambdaRet = (a_PtrType)&(a_pLambdaDevIns)->achInstanceData[0]; \
     5758        Assert(sizeof(*pLambdaRet) == a_pLambdaDevIns->pReg->cbInstanceCC); \
     5759        return pLambdaRet; \
     5760    }(a_pDevIns))
     5761#else
     5762# define PDMDEVINS_2_DATA_CC(a_pDevIns, a_PtrType)  ( (a_PtrType)(void *)&(a_pDevIns)->achInstanceData[0] )
     5763#endif
     5764
     5765
    57275766#ifdef IN_RING3
    57285767
  • trunk/include/VBox/vmm/pdmins.h

    r80531 r81590  
    5151/** @def PDMINS_2_DATA
    5252 * Gets the shared instance data for a PDM device, USB device, or driver instance.
     53 * @note For devices using PDMDEVINS_2_DATA is highly recommended.
    5354 */
    5455#define PDMINS_2_DATA(pIns, type)       ( (type)(pIns)->CTX_SUFF(pvInstanceData) )
     
    5657/** @def PDMINS_2_DATA_CC
    5758 * Gets the current context instance data for a PDM device, USB device, or driver instance.
     59 * @note For devices using PDMDEVINS_2_DATA_CC is highly recommended.
    5860 */
    5961#define PDMINS_2_DATA_CC(pIns, type)    ( (type)(void *)&(pIns)->achInstanceData[0] )
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