VirtualBox

Changeset 78337 in vbox for trunk


Ignore:
Timestamp:
Apr 26, 2019 8:30:19 PM (6 years ago)
Author:
vboxsync
Message:

IPRT/memsafer: Added RTMemSaferGetSize.

Location:
trunk
Files:
4 edited

Legend:

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

    r78334 r78337  
    38103810# define RTMemSaferAllocZTag                            RT_MANGLER(RTMemSaferAllocZTag)
    38113811# define RTMemSaferFree                                 RT_MANGLER(RTMemSaferFree)
     3812# define RTMemSaferGetSize                              RT_MANGLER(RTMemSaferGetSize)
    38123813# define RTMemSaferReallocZExTag                        RT_MANGLER(RTMemSaferReallocZExTag)
    38133814# define RTMemSaferReallocZTag                          RT_MANGLER(RTMemSaferReallocZTag)
  • trunk/include/iprt/memsafer.h

    r76585 r78337  
    241241RTDECL(void) RTMemSaferFree(void *pv, size_t cb) RT_NO_THROW_PROTO;
    242242
     243/**
     244 * Gets the amount of memory allocated at @a pv.
     245 *
     246 * This can be used to check if the allocation was made using an RTMemSafer API.
     247 *
     248 * @returns Allocation size in bytes, 0 if not a RTMemSafer allocation.
     249 * @param   pv          The alleged RTMemSafer allocation.
     250 *
     251 * @note    Not supported in all contexts and implementations of the API.
     252 */
     253RTDECL(size_t) RTMemSaferGetSize(void *pv) RT_NO_THROW_PROTO;
     254
     255
    243256/** @}  */
    244257RT_C_DECLS_END
  • trunk/src/VBox/Runtime/generic/memsafer-generic.cpp

    r76553 r78337  
    150150    if (pv)
    151151    {
    152         Assert(cb);
     152        Assert(cb); /* does not support openssl. */
    153153        void *pvStart = (char *)pv - RTMEMSAFER_PAD_BEFORE;
    154154        AssertMsg(*(size_t *)pvStart == cb, ("*pvStart=%#zx cb=%#zx\n", *(size_t *)pvStart, cb));
  • trunk/src/VBox/Runtime/r3/memsafer-r3.cpp

    r78335 r78337  
    442442        PRTMEMSAFERNODE pThis = rtMemSaferNodeRemove(pv);
    443443        AssertReturnVoid(pThis);
    444         AssertMsg(cb == pThis->cbUser, ("cb=%#zx != %#zx\n", cb, pThis->cbUser));
     444        if (cb == 0) /* for openssl use */
     445            cb = pThis->cbUser;
     446        else
     447            AssertMsg(cb == pThis->cbUser, ("cb=%#zx != %#zx\n", cb, pThis->cbUser));
    445448
    446449        /*
     
    485488}
    486489RT_EXPORT_SYMBOL(RTMemSaferFree);
     490
     491
     492RTDECL(size_t) RTMemSaferGetSize(void *pv) RT_NO_THROW_DEF
     493{
     494    size_t cbRet = 0;
     495    if (pv)
     496    {
     497        void *pvKey = rtMemSaferScramblePointer(pv);
     498        RTCritSectRwEnterShared(&g_MemSaferCritSect);
     499        PRTMEMSAFERNODE pThis = (PRTMEMSAFERNODE)RTAvlPVGet(&g_pMemSaferTree, pvKey);
     500        if (pThis)
     501            cbRet = pThis->cbUser;
     502        RTCritSectRwLeaveShared(&g_MemSaferCritSect);
     503    }
     504    return cbRet;
     505}
     506RT_EXPORT_SYMBOL(RTMemSaferGetSize);
    487507
    488508
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