VirtualBox

Changeset 107091 in vbox


Ignore:
Timestamp:
Nov 21, 2024 4:12:02 PM (8 weeks ago)
Author:
vboxsync
Message:

iprt/cdefs.h,SUPDrvIOC.h,VBoxGuestR0Lib: Added a RT_UOFFSETOF_FLEX_ARRAY macro for calculating the size of structures ending with an variables length arrays. Only tested on windows... bugref:10585

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cdefs.h

    r106565 r107091  
    29782978 * @param   type        Structure type.
    29792979 * @param   memberarray Member.
     2980 * @deprecated Use RT_UOFFSETOF_FLEX_ARRAY when possible.
    29802981 */
    29812982#if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4)
     
    29842985# define RT_UOFFSETOF_DYN(type, memberarray)    ( (uintptr_t)&( ((type *)(void *)0)->memberarray) )
    29852986#endif
     2987
     2988/** @def RT_UOFFSETOF_FLEX_ARRAY
     2989 * Calculates the size of a structure that ends with a flexible array.
     2990 *
     2991 * @returns offset into the structure of the specified member. signed.
     2992 * @param   a_Type          Structure type.
     2993 * @param   a_ArrayMember   The name of flexible array member.
     2994 * @param   a_cEntries      The number of array entries to include in the
     2995 *                          offset.
     2996 */
     2997#define RT_UOFFSETOF_FLEX_ARRAY(a_Type, a_ArrayMember, a_cEntries) \
     2998        ( RT_UOFFSETOF(a_Type, a_ArrayMember) + RT_SIZEOFMEMB(a_Type, a_ArrayMember[0]) * (a_cEntries) )
    29862999
    29873000
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibHGCMInternal.cpp

    r107089 r107091  
    437437                    {
    438438                        size_t const cPages = RTR0MemObjSize(hObj) >> PAGE_SHIFT;
    439                         *pcbExtra += RT_UOFFSETOF_DYN(HGCMPageListInfo, aPages)
    440                                      + RT_SIZEOFMEMB(HGCMPageListInfo, aPages) * cPages;
     439                        *pcbExtra += RT_UOFFSETOF_FLEX_ARRAY(HGCMPageListInfo, aPages, cPages);
    441440                    }
    442441                }
     
    647646                        }
    648647
    649                         offExtra += (uint32_t)(RT_UOFFSETOF_DYN(HGCMPageListInfo, aPages)
    650                                     + RT_SIZEOFMEMB(HGCMPageListInfo, aPages) * cPages);
     648                        offExtra += (uint32_t)RT_UOFFSETOF_FLEX_ARRAY(HGCMPageListInfo, aPages, cPages);
    651649                    }
    652650                    else
  • trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h

    r107085 r107091  
    278278 */
    279279#define SUP_IOCTL_QUERY_FUNCS(cFuncs)                   SUP_CTL_CODE_BIG(2)
    280 #define SUP_IOCTL_QUERY_FUNCS_SIZE(cFuncs)              ((uint32_t)(RT_UOFFSETOF_DYN(SUPQUERYFUNCS, u.Out.aFunctions) \
    281                                                         + RT_SIZEOFMEMB(SUPQUERYFUNCS, u.Out.aFunctions) * (cFuncs)))
     280#define SUP_IOCTL_QUERY_FUNCS_SIZE(cFuncs)              ((uint32_t)RT_UOFFSETOF_FLEX_ARRAY(SUPQUERYFUNCS, u.Out.aFunctions, (cFuncs)))
    282281#define SUP_IOCTL_QUERY_FUNCS_SIZE_IN                   sizeof(SUPREQHDR)
    283282#define SUP_IOCTL_QUERY_FUNCS_SIZE_OUT(cFuncs)          SUP_IOCTL_QUERY_FUNCS_SIZE(cFuncs)
     
    362361 */
    363362#define SUP_IOCTL_LDR_LOAD                              SUP_CTL_CODE_BIG(4)
    364 #define SUP_IOCTL_LDR_LOAD_SIZE_IN(cbImage)             ((uint32_t)(RT_UOFFSETOF_DYN(SUPLDRLOAD, u.In.abImage) \
    365                                                         + RT_SIZEOFMEMB(SUPLDRLOAD, u.In.abImage) * (cbImage)))
     363#define SUP_IOCTL_LDR_LOAD_SIZE_IN(cbImage)             ((uint32_t)RT_UOFFSETOF_FLEX_ARRAY(SUPLDRLOAD, u.In.abImage, (cbImage)))
    366364#define SUP_IOCTL_LDR_LOAD_SIZE_OUT                     (RT_UOFFSETOF(SUPLDRLOAD, u.Out.szError) + RT_SIZEOFMEMB(SUPLDRLOAD, u.Out.szError))
    367365#define SUP_IOCTL_LDR_LOAD_SIZE(cbImage)                RT_MAX(SUP_IOCTL_LDR_LOAD_SIZE_IN(cbImage), SUP_IOCTL_LDR_LOAD_SIZE_OUT)
     
    638636 */
    639637#define SUP_IOCTL_LOW_ALLOC                             SUP_CTL_CODE_BIG(8)
    640 #define SUP_IOCTL_LOW_ALLOC_SIZE(cPages)                ((uint32_t)(RT_UOFFSETOF_DYN(SUPLOWALLOC, u.Out.aPages) \
    641                                                         + RT_SIZEOFMEMB(SUPLOWALLOC, u.Out.aPages) * (cPages)))
     638#define SUP_IOCTL_LOW_ALLOC_SIZE(cPages)                ((uint32_t)RT_UOFFSETOF_FLEX_ARRAY(SUPLOWALLOC, u.Out.aPages, (cPages)))
    642639#define SUP_IOCTL_LOW_ALLOC_SIZE_IN                     (sizeof(SUPREQHDR) + RT_SIZEOFMEMB(SUPLOWALLOC, u.In))
    643640#define SUP_IOCTL_LOW_ALLOC_SIZE_OUT(cPages)            SUP_IOCTL_LOW_ALLOC_SIZE(cPages)
     
    701698 */
    702699#define SUP_IOCTL_PAGE_ALLOC_EX                         SUP_CTL_CODE_BIG(10)
    703 #define SUP_IOCTL_PAGE_ALLOC_EX_SIZE(cPages)            ((uint32_t)(RT_UOFFSETOF_DYN(SUPPAGEALLOCEX, u.Out.aPages) \
    704                                                         + RT_SIZEOFMEMB(SUPPAGEALLOCEX, u.Out.aPages) * (cPages)))
     700#define SUP_IOCTL_PAGE_ALLOC_EX_SIZE(cPages)            ((uint32_t)RT_UOFFSETOF_FLEX_ARRAY(SUPPAGEALLOCEX, u.Out.aPages, (cPages)))
    705701#define SUP_IOCTL_PAGE_ALLOC_EX_SIZE_IN                 (sizeof(SUPREQHDR) + RT_SIZEOFMEMB(SUPPAGEALLOCEX, u.In))
    706702#define SUP_IOCTL_PAGE_ALLOC_EX_SIZE_OUT(cPages)        SUP_IOCTL_PAGE_ALLOC_EX_SIZE(cPages)
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