VirtualBox

Changeset 73097 in vbox for trunk/include


Ignore:
Timestamp:
Jul 12, 2018 9:06:33 PM (6 years ago)
Author:
vboxsync
Message:

*: Made RT_UOFFSETOF, RT_OFFSETOF, RT_UOFFSETOF_ADD and RT_OFFSETOF_ADD work like builtin_offsetof() and require compile time resolvable requests, adding RT_UOFFSETOF_DYN for the dynamic questions that can only be answered at runtime.

Location:
trunk/include
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/Graphics/VBoxVideo.h

    r71602 r73097  
    651651} VBOXVHWACMD_QUERYINFO2;
    652652
    653 #define VBOXVHWAINFO2_SIZE(_cFourCC) RT_OFFSETOF(VBOXVHWACMD_QUERYINFO2, FourCC[_cFourCC])
     653#define VBOXVHWAINFO2_SIZE(_cFourCC) RT_UOFFSETOF_DYN(VBOXVHWACMD_QUERYINFO2, FourCC[_cFourCC])
    654654
    655655typedef struct VBOXVHWACMD_SURF_CANCREATE
     
    15631563} VBOXVDMACMD_SYSMEMEL, *PVBOXVDMACMD_SYSMEMEL;
    15641564
    1565 #define VBOXVDMACMD_SYSMEMEL_NEXT(_pEl) (((_pEl)->fFlags & VBOXVDMACMD_SYSMEMEL_F_PAGELIST) ? \
    1566         ((PVBOXVDMACMD_SYSMEMEL)(((uint8_t*)(_pEl))+RT_OFFSETOF(VBOXVDMACMD_SYSMEMEL, phBuf[(_pEl)->cPages]))) \
    1567         : \
    1568         ((_pEl)+1)
     1565#define VBOXVDMACMD_SYSMEMEL_NEXT(_pEl) ( ((_pEl)->fFlags & VBOXVDMACMD_SYSMEMEL_F_PAGELIST) \
     1566        ? ((PVBOXVDMACMD_SYSMEMEL)(((uint8_t*)(_pEl)) + RT_UOFFSETOF_DYN(VBOXVDMACMD_SYSMEMEL, phBuf[(_pEl)->cPages]))) \
     1567        : ((_pEl) + 1) )
    15691568
    15701569#define VBOXVDMACMD_DMA_BPB_TRANSFER_VRAMSYS_SYS2VRAM 0x00000001
  • trunk/include/VBox/VMMDev.h

    r72627 r73097  
    477477DECLINLINE(size_t) vmmdevGetMousePointerReqSize(uint32_t width, uint32_t height)
    478478{
    479     size_t cbBase = RT_OFFSETOF(VMMDevReqMousePointer, pointerData[0]);
     479    size_t cbBase = RT_UOFFSETOF(VMMDevReqMousePointer, pointerData[0]);
    480480    size_t cbMask = (width + 7) / 8 * height;
    481481    size_t cbArgb = width * height * 4;
  • trunk/include/VBox/com/microatl.h

    r69107 r73097  
    110110
    111111#define COM_INTERFACE_ENTRY_AGGREGATE(iid, pUnk) \
    112     { &iid, (DWORD_PTR)RT_OFFSETOF(_ComClass, pUnk), _Delegate},
     112    { &iid, (DWORD_PTR)RT_UOFFSETOF(_ComClass, pUnk), _Delegate},
    113113
    114114#define END_COM_MAP() \
  • trunk/include/VBox/intnet.h

    r69107 r73097  
    170170        Assert((pBuf)->u32Magic == INTNETBUF_MAGIC); \
    171171        { \
    172             uint32_t const offRecvStart = (pBuf)->Recv.offStart + RT_OFFSETOF(INTNETBUF, Recv); \
    173             uint32_t const offRecvEnd   = (pBuf)->Recv.offStart + RT_OFFSETOF(INTNETBUF, Recv); \
    174             uint32_t const offSendStart = (pBuf)->Send.offStart + RT_OFFSETOF(INTNETBUF, Send); \
    175             uint32_t const offSendEnd   = (pBuf)->Send.offStart + RT_OFFSETOF(INTNETBUF, Send); \
     172            uint32_t const offRecvStart = (pBuf)->Recv.offStart + RT_UOFFSETOF(INTNETBUF, Recv); \
     173            uint32_t const offRecvEnd   = (pBuf)->Recv.offStart + RT_UOFFSETOF(INTNETBUF, Recv); \
     174            uint32_t const offSendStart = (pBuf)->Send.offStart + RT_UOFFSETOF(INTNETBUF, Send); \
     175            uint32_t const offSendEnd   = (pBuf)->Send.offStart + RT_UOFFSETOF(INTNETBUF, Send); \
    176176            \
    177177            Assert(offRecvEnd > offRecvStart); \
  • trunk/include/VBox/intnetinline.h

    r69107 r73097  
    802802
    803803    /* receive ring buffer. */
    804     uint32_t offBuf = RT_ALIGN_32(sizeof(INTNETBUF), INTNETRINGBUF_ALIGNMENT) - RT_OFFSETOF(INTNETBUF, Recv);
     804    uint32_t offBuf = RT_ALIGN_32(sizeof(INTNETBUF), INTNETRINGBUF_ALIGNMENT) - RT_UOFFSETOF(INTNETBUF, Recv);
    805805    pIntBuf->Recv.offStart      = offBuf;
    806806    pIntBuf->Recv.offReadX      = offBuf;
     
    810810
    811811    /* send ring buffer. */
    812     offBuf += cbRecv + RT_OFFSETOF(INTNETBUF, Recv) - RT_OFFSETOF(INTNETBUF, Send);
     812    offBuf += cbRecv + RT_UOFFSETOF(INTNETBUF, Recv) - RT_UOFFSETOF(INTNETBUF, Send);
    813813    pIntBuf->Send.offStart      = offBuf;
    814814    pIntBuf->Send.offReadX      = offBuf;
  • trunk/include/VBox/vmm/pdmdev.h

    r71764 r73097  
    41194119
    41204120/** Converts a pointer to the PDMDEVINS::IBase to a pointer to PDMDEVINS. */
    4121 #define PDMIBASE_2_PDMDEV(pInterface) ( (PPDMDEVINS)((char *)(pInterface) - RT_OFFSETOF(PDMDEVINS, IBase)) )
     4121#define PDMIBASE_2_PDMDEV(pInterface) ( (PPDMDEVINS)((char *)(pInterface) - RT_UOFFSETOF(PDMDEVINS, IBase)) )
    41224122
    41234123/**
     
    42254225 * Converts a PDM Device instance pointer a RC PDM Device instance pointer.
    42264226 */
    4227 #define PDMDEVINS_2_RCPTR(pDevIns)  ( (RCPTRTYPE(PPDMDEVINS))((RTGCUINTPTR)(pDevIns)->pvInstanceDataRC - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
     4227#define PDMDEVINS_2_RCPTR(pDevIns)  ( (RCPTRTYPE(PPDMDEVINS))((RTRCUINTPTR)(pDevIns)->pvInstanceDataRC - (RTRCUINTPTR)RT_UOFFSETOF(PDMDEVINS, achInstanceData)) )
    42284228
    42294229/** @def PDMDEVINS_2_R3PTR
    42304230 * Converts a PDM Device instance pointer a R3 PDM Device instance pointer.
    42314231 */
    4232 #define PDMDEVINS_2_R3PTR(pDevIns)  ( (R3PTRTYPE(PPDMDEVINS))((RTHCUINTPTR)(pDevIns)->pvInstanceDataR3 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
     4232#define PDMDEVINS_2_R3PTR(pDevIns)  ( (R3PTRTYPE(PPDMDEVINS))((RTHCUINTPTR)(pDevIns)->pvInstanceDataR3 - RT_UOFFSETOF(PDMDEVINS, achInstanceData)) )
    42334233
    42344234/** @def PDMDEVINS_2_R0PTR
    42354235 * Converts a PDM Device instance pointer a R0 PDM Device instance pointer.
    42364236 */
    4237 #define PDMDEVINS_2_R0PTR(pDevIns)  ( (R0PTRTYPE(PPDMDEVINS))((RTR0UINTPTR)(pDevIns)->pvInstanceDataR0 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
     4237#define PDMDEVINS_2_R0PTR(pDevIns)  ( (R0PTRTYPE(PPDMDEVINS))((RTR0UINTPTR)(pDevIns)->pvInstanceDataR0 - RT_UOFFSETOF(PDMDEVINS, achInstanceData)) )
    42384238
    42394239
  • trunk/include/VBox/vmm/pdmdrv.h

    r69475 r73097  
    413413
    414414/** Converts a pointer to the PDMDRVINS::IBase to a pointer to PDMDRVINS. */
    415 #define PDMIBASE_2_PDMDRV(pInterface)   ( (PPDMDRVINS)((char *)(pInterface) - RT_OFFSETOF(PDMDRVINS, IBase)) )
     415#define PDMIBASE_2_PDMDRV(pInterface)   ( (PPDMDRVINS)((char *)(pInterface) - RT_UOFFSETOF(PDMDRVINS, IBase)) )
    416416
    417417/** @def PDMDRVINS_2_RCPTR
    418418 * Converts a PDM Driver instance pointer a RC PDM Driver instance pointer.
    419419 */
    420 #define PDMDRVINS_2_RCPTR(pDrvIns)      ( (RCPTRTYPE(PPDMDRVINS))((RTGCUINTPTR)(pDrvIns)->pvInstanceDataRC - RT_OFFSETOF(PDMDRVINS, achInstanceData)) )
     420#define PDMDRVINS_2_RCPTR(pDrvIns)      ( (RCPTRTYPE(PPDMDRVINS))((RTRCUINTPTR)(pDrvIns)->pvInstanceDataRC - (RTRCUINTPTR)RT_UOFFSETOF(PDMDRVINS, achInstanceData)) )
    421421
    422422/** @def PDMDRVINS_2_R3PTR
    423423 * Converts a PDM Driver instance pointer a R3 PDM Driver instance pointer.
    424424 */
    425 #define PDMDRVINS_2_R3PTR(pDrvIns)      ( (R3PTRTYPE(PPDMDRVINS))((RTHCUINTPTR)(pDrvIns)->pvInstanceDataR3 - RT_OFFSETOF(PDMDRVINS, achInstanceData)) )
     425#define PDMDRVINS_2_R3PTR(pDrvIns)      ( (R3PTRTYPE(PPDMDRVINS))((RTHCUINTPTR)(pDrvIns)->pvInstanceDataR3 - RT_UOFFSETOF(PDMDRVINS, achInstanceData)) )
    426426
    427427/** @def PDMDRVINS_2_R0PTR
    428428 * Converts a PDM Driver instance pointer a R0 PDM Driver instance pointer.
    429429 */
    430 #define PDMDRVINS_2_R0PTR(pDrvIns)      ( (R0PTRTYPE(PPDMDRVINS))((RTR0UINTPTR)(pDrvIns)->pvInstanceDataR0 - RT_OFFSETOF(PDMDRVINS, achInstanceData)) )
     430#define PDMDRVINS_2_R0PTR(pDrvIns)      ( (R0PTRTYPE(PPDMDRVINS))((RTR0UINTPTR)(pDrvIns)->pvInstanceDataR0 - RT_UOFFSETOF(PDMDRVINS, achInstanceData)) )
    431431
    432432
  • trunk/include/VBox/vmm/pdmsrv.h

    r69475 r73097  
    285285
    286286/** Converts a pointer to the PDMSRVINS::IBase to a pointer to PDMSRVINS. */
    287 #define PDMIBASE_2_PDMSRV(pInterface) ( (PPDMSRVINS)((char *)(pInterface) - RT_OFFSETOF(PDMSRVINS, IBase)) )
     287#define PDMIBASE_2_PDMSRV(pInterface) ( (PPDMSRVINS)((char *)(pInterface) - RT_UOFFSETOF(PDMSRVINS, IBase)) )
    288288
    289289
  • trunk/include/VBox/vmm/pdmusb.h

    r70322 r73097  
    842842
    843843/** Converts a pointer to the PDMUSBINS::IBase to a pointer to PDMUSBINS. */
    844 #define PDMIBASE_2_PDMUSB(pInterface) ( (PPDMUSBINS)((char *)(pInterface) - RT_OFFSETOF(PDMUSBINS, IBase)) )
     844#define PDMIBASE_2_PDMUSB(pInterface) ( (PPDMUSBINS)((char *)(pInterface) - RT_UOFFSETOF(PDMUSBINS, IBase)) )
    845845
    846846
  • trunk/include/VBox/vmm/ssm.h

    r69107 r73097  
    239239 * @internal  */
    240240#define SSMFIELD_ENTRY_TF_INT(Type, Field, enmTransformer, uFirstVer) \
    241     SSMFIELD_ENTRY_INT(#Type "::" #Field, RT_OFFSETOF(Type, Field), RT_SIZEOFMEMB(Type, Field), enmTransformer, uFirstVer)
     241    SSMFIELD_ENTRY_INT(#Type "::" #Field, RT_UOFFSETOF(Type, Field), RT_SIZEOFMEMB(Type, Field), enmTransformer, uFirstVer)
    242242/** Emit a SSMFIELD array entry for an old field.
    243243 * @internal  */
     
    247247 * @internal  */
    248248#define SSMFIELD_ENTRY_PAD_INT(Type, Field, cb32, cb64, enmTransformer) \
    249     SSMFIELD_ENTRY_INT(#Type "::" #Field, RT_OFFSETOF(Type, Field), \
     249    SSMFIELD_ENTRY_INT(#Type "::" #Field, RT_UOFFSETOF(Type, Field), \
    250250                       (RT_SIZEOFMEMB(Type, Field) << 16) | (cb32) | ((cb64) << 8), enmTransformer, 0)
    251251/** Emit a SSMFIELD array entry for an alignment padding.
     
    369369/** Emit a SSMFIELD array entry for a field with a custom callback. */
    370370#define SSMFIELD_ENTRY_CALLBACK(Type, Field, pfnGetPut) \
    371     { (pfnGetPut), RT_OFFSETOF(Type, Field), RT_SIZEOFMEMB(Type, Field), 0, #Type "::" #Field }
     371    { (pfnGetPut), RT_UOFFSETOF(Type, Field), RT_SIZEOFMEMB(Type, Field), 0, #Type "::" #Field }
    372372/** Emit the terminating entry of a SSMFIELD array. */
    373373#define SSMFIELD_ENTRY_TERM() \
  • trunk/include/iprt/cdefs.h

    r72774 r73097  
    22652265 * Our own special offsetof() variant, returns a signed result.
    22662266 *
    2267  * This differs from the usual offsetof() in that it's not relying on builtin
    2268  * compiler stuff and thus can use variables in arrays the structure may
    2269  * contain. This is useful to determine the sizes of structures ending
    2270  * with a variable length field. For gcc >= 4.4 see @bugref{7775}.
    2271  *
    22722267 * @returns offset into the structure of the specified member. signed.
    22732268 * @param   type    Structure type.
    22742269 * @param   member  Member.
    2275  */
    2276 #if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4)
    2277 # define RT_OFFSETOF(type, member)              ( (int)(uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 )
    2278 #else
    2279 # define RT_OFFSETOF(type, member)              ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
     2270 *
     2271 * @remarks Only use this for static offset calculations. Please
     2272 *          use RT_UOFFSETOF_DYN for dynamic ones (i.e. involves
     2273 *          non-constant array indexing).
     2274 *
     2275 */
     2276#if RT_GNUC_PREREQ(4, 0)
     2277# define RT_OFFSETOF(type, member)              ( (int)__builtin_offsetof(type, member) )
     2278#else
     2279# define RT_OFFSETOF(type, member)              ( (int)(intptr_t)&( ((type *)(void *)0)->member) )
    22802280#endif
    22812281
    22822282/** @def RT_UOFFSETOF
    2283  * Our own special offsetof() variant, returns an unsigned result.
    2284  *
    2285  * This differs from the usual offsetof() in that it's not relying on builtin
    2286  * compiler stuff and thus can use variables in arrays the structure may
    2287  * contain. This is useful to determine the sizes of structures ending
    2288  * with a variable length field. For gcc >= 4.4 see @bugref{7775}.
     2283 * Our own offsetof() variant, returns an unsigned result.
    22892284 *
    22902285 * @returns offset into the structure of the specified member. unsigned.
    22912286 * @param   type    Structure type.
    22922287 * @param   member  Member.
    2293  */
    2294 #if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4)
    2295 # define RT_UOFFSETOF(type, member)             ( (uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 )
     2288 *
     2289 * @remarks Only use this for static offset calculations. Please
     2290 *          use RT_UOFFSETOF_DYN for dynamic ones (i.e. involves
     2291 *          non-constant array indexing).
     2292 */
     2293#if RT_GNUC_PREREQ(4, 0)
     2294# define RT_UOFFSETOF(type, member)             ( (uintptr_t)__builtin_offsetof(type, member) )
    22962295#else
    22972296# define RT_UOFFSETOF(type, member)             ( (uintptr_t)&( ((type *)(void *)0)->member) )
     
    23052304 * @param   member  Member.
    23062305 * @param   addend  The addend to add to the offset.
     2306 *
     2307 * @remarks Only use this for static offset calculations.
    23072308 */
    23082309#define RT_OFFSETOF_ADD(type, member, addend)   ( (int)RT_UOFFSETOF_ADD(type, member, addend) )
     
    23152316 * @param   member  Member.
    23162317 * @param   addend  The addend to add to the offset.
    2317  */
    2318 #define RT_UOFFSETOF_ADD(type, member, addend)  ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
     2318 *
     2319 * @remarks Only use this for static offset calculations.
     2320 */
     2321#if RT_GNUC_PREREQ(4, 0)
     2322# define RT_UOFFSETOF_ADD(type, member, addend)  ( (uintptr_t)(__builtin_offsetof(type, member) + (addend)))
     2323#else
     2324# define RT_UOFFSETOF_ADD(type, member, addend)  ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
     2325#endif
     2326
     2327/** @def RT_UOFFSETOF_DYN
     2328 * Dynamic (runtime) structure offset calculations, involving
     2329 * indexing of array members via variable.
     2330 *
     2331 * @returns offset into the structure of the specified member. signed.
     2332 * @param   type        Structure type.
     2333 * @param   memberarray Member.
     2334 */
     2335#if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4)
     2336# define RT_UOFFSETOF_DYN(type, memberarray)    ( (uintptr_t)&( ((type *)(void *)0x1000)->memberarray) - 0x1000 )
     2337#else
     2338# define RT_UOFFSETOF_DYN(type, memberarray)    ( (uintptr_t)&( ((type *)(void *)0)->memberarray) )
     2339#endif
     2340
    23192341
    23202342/** @def RT_SIZEOFMEMB
  • trunk/include/iprt/nt/nt.h

    r72639 r73097  
    14941494#if !defined(NtCurrentTeb) && !defined(IPRT_NT_HAVE_CURRENT_TEB_MACRO)
    14951495# ifdef RT_ARCH_X86
    1496 DECL_FORCE_INLINE(PTEB)     RTNtCurrentTeb(void) { return (PTEB)__readfsdword(RT_OFFSETOF(TEB_COMMON, NtTib.Self)); }
    1497 DECL_FORCE_INLINE(PPEB)     RTNtCurrentPeb(void) { return (PPEB)__readfsdword(RT_OFFSETOF(TEB_COMMON, ProcessEnvironmentBlock)); }
    1498 DECL_FORCE_INLINE(uint32_t) RTNtCurrentThreadId(void) { return __readfsdword(RT_OFFSETOF(TEB_COMMON, ClientId.UniqueThread)); }
    1499 DECL_FORCE_INLINE(NTSTATUS) RTNtLastStatusValue(void) { return (NTSTATUS)__readfsdword(RT_OFFSETOF(TEB_COMMON, LastStatusValue)); }
    1500 DECL_FORCE_INLINE(uint32_t) RTNtLastErrorValue(void)  { return __readfsdword(RT_OFFSETOF(TEB_COMMON, LastErrorValue)); }
     1496DECL_FORCE_INLINE(PTEB)     RTNtCurrentTeb(void) { return (PTEB)__readfsdword(RT_UOFFSETOF(TEB_COMMON, NtTib.Self)); }
     1497DECL_FORCE_INLINE(PPEB)     RTNtCurrentPeb(void) { return (PPEB)__readfsdword(RT_UOFFSETOF(TEB_COMMON, ProcessEnvironmentBlock)); }
     1498DECL_FORCE_INLINE(uint32_t) RTNtCurrentThreadId(void) { return __readfsdword(RT_UOFFSETOF(TEB_COMMON, ClientId.UniqueThread)); }
     1499DECL_FORCE_INLINE(NTSTATUS) RTNtLastStatusValue(void) { return (NTSTATUS)__readfsdword(RT_UOFFSETOF(TEB_COMMON, LastStatusValue)); }
     1500DECL_FORCE_INLINE(uint32_t) RTNtLastErrorValue(void)  { return __readfsdword(RT_UOFFSETOF(TEB_COMMON, LastErrorValue)); }
    15011501# elif defined(RT_ARCH_AMD64)
    1502 DECL_FORCE_INLINE(PTEB)     RTNtCurrentTeb(void) { return (PTEB)__readgsqword(RT_OFFSETOF(TEB_COMMON, NtTib.Self)); }
    1503 DECL_FORCE_INLINE(PPEB)     RTNtCurrentPeb(void) { return (PPEB)__readgsqword(RT_OFFSETOF(TEB_COMMON, ProcessEnvironmentBlock)); }
    1504 DECL_FORCE_INLINE(uint32_t) RTNtCurrentThreadId(void) { return __readgsdword(RT_OFFSETOF(TEB_COMMON, ClientId.UniqueThread)); }
    1505 DECL_FORCE_INLINE(NTSTATUS) RTNtLastStatusValue(void) { return (NTSTATUS)__readgsdword(RT_OFFSETOF(TEB_COMMON, LastStatusValue)); }
    1506 DECL_FORCE_INLINE(uint32_t) RTNtLastErrorValue(void)  { return __readgsdword(RT_OFFSETOF(TEB_COMMON, LastErrorValue)); }
     1502DECL_FORCE_INLINE(PTEB)     RTNtCurrentTeb(void) { return (PTEB)__readgsqword(RT_UOFFSETOF(TEB_COMMON, NtTib.Self)); }
     1503DECL_FORCE_INLINE(PPEB)     RTNtCurrentPeb(void) { return (PPEB)__readgsqword(RT_UOFFSETOF(TEB_COMMON, ProcessEnvironmentBlock)); }
     1504DECL_FORCE_INLINE(uint32_t) RTNtCurrentThreadId(void) { return __readgsdword(RT_UOFFSETOF(TEB_COMMON, ClientId.UniqueThread)); }
     1505DECL_FORCE_INLINE(NTSTATUS) RTNtLastStatusValue(void) { return (NTSTATUS)__readgsdword(RT_UOFFSETOF(TEB_COMMON, LastStatusValue)); }
     1506DECL_FORCE_INLINE(uint32_t) RTNtLastErrorValue(void)  { return __readgsdword(RT_UOFFSETOF(TEB_COMMON, LastErrorValue)); }
    15071507# else
    15081508#  error "Port me"
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