VirtualBox

Changeset 71605 in vbox


Ignore:
Timestamp:
Apr 1, 2018 8:28:00 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
121632
Message:

iprt/string.h: Added RT_COPY_VOLATILE & RT_BCOPY_VOLATILE for helping copying volatile data into non-volatile buffers. Saves on casting and highlights what we're up to.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/include/iprt/string.h

    r70092 r71605  
    142142#define RT_BZERO(pv, cb)    do { memset((pv), 0, cb); } while (0)
    143143
     144
     145/**
     146 * For copying a volatile variable to a non-volatile one.
     147 * @param   a_Dst           The non-volatile destination variable.
     148 * @param   a_VolatileSrc   The volatile source variable / dereferenced pointer.
     149 */
     150#define RT_COPY_VOLATILE(a_Dst, a_VolatileSrc) \
     151    do { \
     152        void const volatile *a_pvVolatileSrc_BCopy_Volatile = &(a_VolatileSrc); \
     153        AssertCompile(sizeof(a_Dst) == sizeof(a_VolatileSrc)); \
     154        memcpy(&(a_Dst), (void const *)a_pvVolatileSrc_BCopy_Volatile, sizeof(a_Dst)); \
     155    } while (0)
     156
     157/**
     158 * For copy a number of bytes from a volatile buffer to a non-volatile one.
     159 *
     160 * @param   a_pDst          Pointer to the destination buffer.
     161 * @param   a_pVolatileSrc  Pointer to the volatile source buffer.
     162 * @param   a_cbToCopy      Number of bytes to copy.
     163 */
     164#define RT_BCOPY_VOLATILE(a_pDst, a_pVolatileSrc, a_cbToCopy) \
     165    do { \
     166        void const volatile *a_pvVolatileSrc_BCopy_Volatile = (a_pVolatileSrc); \
     167        memcpy((a_pDst), (void const *)a_pvVolatileSrc_BCopy_Volatile, (a_cbToCopy)); \
     168    } while (0)
    144169
    145170
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