VirtualBox

Changeset 83546 in vbox for trunk/src


Ignore:
Timestamp:
Apr 4, 2020 10:46:18 AM (5 years ago)
Author:
vboxsync
Message:

IPRT: Added RTMemFreeZ, RTMemTmpFreeZ, and RTMemEf* variants. bugref:9698

Location:
trunk/src/VBox/Runtime
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/alloc-ef-r0drv.cpp

    r83368 r83546  
    137137    RTMEMTYPE_RTMEMREALLOC,
    138138    RTMEMTYPE_RTMEMFREE,
     139    RTMEMTYPE_RTMEMFREEZ,
    139140
    140141    RTMEMTYPE_NEW,
     
    645646 * Internal free.
    646647 */
    647 static void rtR0MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, RT_SRC_POS_DECL)
     648static void rtR0MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, size_t cbUser, void *pvCaller, RT_SRC_POS_DECL)
    648649{
    649650    NOREF(enmType); RT_SRC_POS_NOREF();
     
    694695#endif
    695696
    696 #ifdef RTR0MEM_EF_FREE_FILL
    697697        /*
    698698         * Fill the user part of the block.
    699699         */
    700         memset(pv, RTR0MEM_EF_FREE_FILL, pBlock->cbUnaligned);
     700        AssertMsg(enmType != RTMEMTYPE_RTMEMFREEZ || cbUser == pBlock->cbUnaligned,
     701                  ("cbUser=%#zx cbUnaligned=%#zx\n", cbUser, pBlock->cbUnaligned));
     702        if (enmType == RTMEMTYPE_RTMEMFREEZ)
     703            RT_BZERO(pv, pBlock->cbUnaligned);
     704#ifdef RTR0MEM_EF_FREE_FILL
     705        else
     706            memset(pv, RTR0MEM_EF_FREE_FILL, pBlock->cbUnaligned);
    701707#endif
    702708
     
    748754    if (!cbNew)
    749755    {
    750         rtR0MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, pvCaller, RT_SRC_POS_ARGS);
     756        rtR0MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, 0, pvCaller, RT_SRC_POS_ARGS);
    751757        return NULL;
    752758    }
     
    762768        {
    763769            memcpy(pvRet, pvOld, RT_MIN(cbNew, pBlock->cbUnaligned));
    764             rtR0MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, pvCaller, RT_SRC_POS_ARGS);
     770            rtR0MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, 0, pvCaller, RT_SRC_POS_ARGS);
    765771        }
    766772        return pvRet;
     
    788794{
    789795    if (pv)
    790         rtR0MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), RT_SRC_POS_ARGS);
     796        rtR0MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, 0, ASMReturnAddress(), RT_SRC_POS_ARGS);
     797}
     798
     799
     800RTDECL(void)    RTMemEfTmpFreeZ(void *pv, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW_DEF
     801{
     802    if (pv)
     803        rtR0MemFree("FreeZ", RTMEMTYPE_RTMEMFREEZ, pv, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);
    791804}
    792805
     
    843856{
    844857    if (pv)
    845         rtR0MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), RT_SRC_POS_ARGS);
     858        rtR0MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, 0, ASMReturnAddress(), RT_SRC_POS_ARGS);
     859}
     860
     861
     862RTDECL(void)    RTMemEfFreeZ(void *pv, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW_DEF
     863{
     864    if (pv)
     865        rtR0MemFree("Free", RTMEMTYPE_RTMEMFREEZ, pv, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);
    846866}
    847867
     
    893913{
    894914    if (pv)
    895         rtR0MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), NULL, 0, NULL);
     915        rtR0MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
     916}
     917
     918
     919RTDECL(void)    RTMemEfTmpFreeZNP(void *pv, size_t cb) RT_NO_THROW_DEF
     920{
     921    if (pv)
     922        rtR0MemFree("FreeZ", RTMEMTYPE_RTMEMFREEZ, pv, cb, ASMReturnAddress(), NULL, 0, NULL);
    896923}
    897924
     
    949976{
    950977    if (pv)
    951         rtR0MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), NULL, 0, NULL);
     978        rtR0MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
     979}
     980
     981
     982RTDECL(void)    RTMemEfFreeZNP(void *pv, size_t cb) RT_NO_THROW_DEF
     983{
     984    if (pv)
     985        rtR0MemFree("FreeZ", RTMEMTYPE_RTMEMFREEZ, pv, cb, ASMReturnAddress(), NULL, 0, NULL);
    952986}
    953987
  • trunk/src/VBox/Runtime/r0drv/alloc-r0drv.cpp

    r82968 r83546  
    112112
    113113
     114RTDECL(void)    RTMemTmpFreeZ(void *pv, size_t cb) RT_NO_THROW_DEF
     115{
     116    return RTMemFreeZ(pv, cb);
     117}
     118RT_EXPORT_SYMBOL(RTMemTmpFreeZ);
     119
     120
    114121
    115122
     
    274281}
    275282RT_EXPORT_SYMBOL(RTMemFree);
     283
     284
     285RTDECL(void) RTMemFreeZ(void *pv, size_t cb) RT_NO_THROW_DEF
     286{
     287    PRTMEMHDR pHdr;
     288    RT_ASSERT_INTS_ON();
     289
     290    if (!pv)
     291        return;
     292    pHdr = (PRTMEMHDR)pv - 1;
     293    if (pHdr->u32Magic == RTMEMHDR_MAGIC)
     294    {
     295        Assert(!(pHdr->fFlags & RTMEMHDR_FLAG_ALLOC_EX));
     296        Assert(!(pHdr->fFlags & RTMEMHDR_FLAG_EXEC));
     297#ifdef RTR0MEM_STRICT
     298        AssertReleaseMsg(!memcmp((uint8_t *)(pHdr + 1) + pHdr->cbReq, &g_abFence[0], RTR0MEM_FENCE_EXTRA),
     299                         ("pHdr=%p pv=%p cbReq=%u cb=%u fFlags=%#x\n"
     300                          "fence:    %.*Rhxs\n"
     301                          "expected: %.*Rhxs\n",
     302                          pHdr, pv, pHdr->cbReq, pHdr->cb, pHdr->fFlags,
     303                          RTR0MEM_FENCE_EXTRA, (uint8_t *)(pHdr + 1) + pHdr->cbReq,
     304                          RTR0MEM_FENCE_EXTRA, &g_abFence[0]));
     305#endif
     306        AssertMsgStmt(cb == pHdr->cbReq, ("cb=%#zx cbReq=%#x\n", cb, pHdr->cbReq), cb = pHdr->cbReq);
     307        RT_BZERO(pv, cb);
     308        rtR0MemFree(pHdr);
     309    }
     310    else
     311        AssertMsgFailed(("pHdr->u32Magic=%RX32 pv=%p\n", pHdr->u32Magic, pv));
     312}
     313RT_EXPORT_SYMBOL(RTMemFreeZ);
    276314
    277315
  • trunk/src/VBox/Runtime/r3/alloc-ef-cpp.cpp

    r82968 r83546  
    9191void RT_EF_CDECL operator delete(void *pv) RT_EF_NOTHROW
    9292{
    93     rtR3MemFree("delete", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
     93    rtR3MemFree("delete", RTMEMTYPE_DELETE, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
    9494}
    9595
     
    100100    NOREF(cb);
    101101    AssertMsgFailed(("cb ignored!\n"));
    102     rtR3MemFree("delete", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
     102    rtR3MemFree("delete", RTMEMTYPE_DELETE, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
    103103}
    104104#endif
     
    107107void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) RT_EF_NOTHROW
    108108{
    109     rtR3MemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
     109    rtR3MemFree("delete nothrow", RTMEMTYPE_DELETE, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
    110110}
    111111
     
    137137void RT_EF_CDECL operator delete[](void * pv) RT_EF_NOTHROW
    138138{
    139     rtR3MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
     139    rtR3MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
    140140}
    141141
     
    146146    NOREF(cb);
    147147    AssertMsgFailed(("cb ignored!\n"));
    148     rtR3MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
     148    rtR3MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
    149149}
    150150#endif
     
    153153void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) RT_EF_NOTHROW
    154154{
    155     rtR3MemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
     155    rtR3MemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
    156156}
    157157
  • trunk/src/VBox/Runtime/r3/alloc-ef.cpp

    r83368 r83546  
    368368        PRTMEMBLOCK pBlock = rtmemBlockGet(pv);
    369369        if (pBlock)
    370             rtR3MemFree("r-free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), RT_SRC_POS);
     370            rtR3MemFree("r-free", RTMEMTYPE_RTMEMFREE, pv, 0, ASMReturnAddress(), RT_SRC_POS);
    371371        else
    372372            g_pfnOrgFree(pv);
     
    649649 * Internal free.
    650650 */
    651 RTDECL(void) rtR3MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, RT_SRC_POS_DECL)
     651RTDECL(void) rtR3MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, size_t cbUser, void *pvCaller, RT_SRC_POS_DECL)
    652652{
    653653    NOREF(enmType); RT_SRC_POS_NOREF();
     
    699699# endif
    700700
    701 # ifdef RTALLOC_EFENCE_FREE_FILL
    702701        /*
    703702         * Fill the user part of the block.
    704703         */
    705         memset(pv, RTALLOC_EFENCE_FREE_FILL, pBlock->cbUnaligned);
     704        AssertMsg(enmType != RTMEMTYPE_RTMEMFREEZ || cbUser == pBlock->cbUnaligned,
     705                  ("cbUser=%#zx cbUnaligned=%#zx\n", cbUser, pBlock->cbUnaligned));
     706        if (enmType == RTMEMTYPE_RTMEMFREEZ)
     707            RT_BZERO(pv, pBlock->cbUnaligned);
     708#ifdef RTALLOC_EFENCE_FREE_FILL
     709        else
     710            memset(pv, RTALLOC_EFENCE_FREE_FILL, pBlock->cbUnaligned);
    706711# endif
    707712
     
    790795    if (!cbNew)
    791796    {
    792         rtR3MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, pvCaller, RT_SRC_POS_ARGS);
     797        rtR3MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, 0, pvCaller, RT_SRC_POS_ARGS);
    793798        return NULL;
    794799    }
     
    806811        {
    807812            memcpy(pvRet, pvOld, RT_MIN(cbNew, pBlock->cbUnaligned));
    808             rtR3MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, pvCaller, RT_SRC_POS_ARGS);
     813            rtR3MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, 0, pvCaller, RT_SRC_POS_ARGS);
    809814        }
    810815        return pvRet;
     
    840845{
    841846    if (pv)
    842         rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), RT_SRC_POS_ARGS);
     847        rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, 0, ASMReturnAddress(), RT_SRC_POS_ARGS);
     848}
     849
     850
     851RTDECL(void)    RTMemEfTmpFreeZ(void *pv, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW_DEF
     852{
     853    if (pv)
     854        rtR3MemFree("FreeZ", RTMEMTYPE_RTMEMFREEZ, pv, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);
    843855}
    844856
     
    896908{
    897909    if (pv)
    898         rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), RT_SRC_POS_ARGS);
     910        rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, 0, ASMReturnAddress(), RT_SRC_POS_ARGS);
     911}
     912
     913
     914RTDECL(void)    RTMemEfFreeZ(void *pv, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW_DEF
     915{
     916    if (pv)
     917        rtR3MemFree("FreeZ", RTMEMTYPE_RTMEMFREEZ, pv, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);
    899918}
    900919
     
    946965{
    947966    if (pv)
    948         rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), NULL, 0, NULL);
     967        rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
     968}
     969
     970
     971RTDECL(void)    RTMemEfTmpFreeZNP(void *pv, size_t cb) RT_NO_THROW_DEF
     972{
     973    if (pv)
     974        rtR3MemFree("FreeZ", RTMEMTYPE_RTMEMFREEZ, pv, cb, ASMReturnAddress(), NULL, 0, NULL);
    949975}
    950976
     
    10021028{
    10031029    if (pv)
    1004         rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), NULL, 0, NULL);
     1030        rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
     1031}
     1032
     1033
     1034RTDECL(void)    RTMemEfFreeZNP(void *pv, size_t cb) RT_NO_THROW_DEF
     1035{
     1036    if (pv)
     1037        rtR3MemFree("Free", RTMEMTYPE_RTMEMFREEZ, pv, cb, ASMReturnAddress(), NULL, 0, NULL);
    10051038}
    10061039
  • trunk/src/VBox/Runtime/r3/alloc-ef.h

    r82968 r83546  
    157157    RTMEMTYPE_RTMEMREALLOC,
    158158    RTMEMTYPE_RTMEMFREE,
     159    RTMEMTYPE_RTMEMFREEZ,
    159160
    160161    RTMEMTYPE_NEW,
     
    201202RTDECL(void *)  rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew,
    202203                               const char *pszTag, void *pvCaller, RT_SRC_POS_DECL);
    203 RTDECL(void)    rtR3MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, RT_SRC_POS_DECL);
     204RTDECL(void)    rtR3MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, size_t cbUser, void *pvCaller, RT_SRC_POS_DECL);
    204205RT_C_DECLS_END
    205206
  • trunk/src/VBox/Runtime/r3/alloc.cpp

    r82968 r83546  
    6767#undef RTMemTmpAllocZTag
    6868#undef RTMemTmpFree
     69#undef RTMemTmpFreeZ
    6970#undef RTMemAlloc
    7071#undef RTMemAllocTag
     
    7879#undef RTMemReallocTag
    7980#undef RTMemFree
     81#undef RTMemFreeZ
    8082#undef RTMemDup
    8183#undef RTMemDupTag
     
    139141
    140142
     143RTDECL(void) RTMemTmpFreeZ(void *pv, size_t cb) RT_NO_THROW_DEF
     144{
     145    RTMemFreeZ(pv, cb);
     146}
     147
     148
    141149RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_DEF
    142150{
     
    255263    if (pv)
    256264#ifdef RTALLOC_USE_EFENCE
    257         rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), NULL, 0, NULL);
     265        rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, 0, ASMReturnAddress(), NULL, 0, NULL);
    258266#else
    259267# ifdef RTMEMALLOC_USE_TRACKER
     
    265273
    266274
     275RTDECL(void) RTMemFreeZ(void *pv, size_t cb) RT_NO_THROW_DEF
     276{
     277    if (pv)
     278    {
     279#ifdef RTALLOC_USE_EFENCE
     280        rtR3MemFree("Free", RTMEMTYPE_RTMEMFREEZ, pv, cb, ASMReturnAddress(), NULL, 0, NULL);
     281#else
     282# ifdef RTMEMALLOC_USE_TRACKER
     283        pv = RTMemTrackerHdrFree(pv, cb, NULL, ASMReturnAddress(), RTMEMTRACKERMETHOD_FREE);
     284# endif
     285        RT_BZERO(pv, cb);
     286        free(pv);
     287#endif
     288    }
     289}
     290
     291
    267292
    268293DECLHIDDEN(void *)  rtMemBaseAlloc(size_t cb)
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