VirtualBox

Ignore:
Timestamp:
Jul 28, 2010 3:15:35 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64135
Message:

iprt,++: Tag allocation in all builds with a string, defaulting to FILE.

File:
1 edited

Legend:

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

    r29250 r31157  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    8181
    8282
    83 
    84 /**
    85  * Allocates temporary memory.
    86  *
    87  * Temporary memory blocks are used for not too large memory blocks which
    88  * are believed not to stick around for too long. Using this API instead
    89  * of RTMemAlloc() not only gives the heap manager room for optimization
    90  * but makes the code easier to read.
    91  *
    92  * @returns Pointer to the allocated memory.
    93  * @returns NULL on failure.
    94  * @param   cb      Size in bytes of the memory block to allocated.
    95  */
    96 RTDECL(void *)  RTMemTmpAlloc(size_t cb) RT_NO_THROW
    97 {
    98     return RTMemAlloc(cb);
    99 }
    100 RT_EXPORT_SYMBOL(RTMemTmpAlloc);
    101 
    102 
    103 /**
    104  * Allocates zero'ed temporary memory.
    105  *
    106  * Same as RTMemTmpAlloc() but the memory will be zero'ed.
    107  *
    108  * @returns Pointer to the allocated memory.
    109  * @returns NULL on failure.
    110  * @param   cb      Size in bytes of the memory block to allocated.
    111  */
    112 RTDECL(void *)  RTMemTmpAllocZ(size_t cb) RT_NO_THROW
    113 {
    114     return RTMemAllocZ(cb);
    115 }
    116 RT_EXPORT_SYMBOL(RTMemTmpAllocZ);
    117 
    118 
    119 /**
    120  * Free temporary memory.
    121  *
    122  * @param   pv      Pointer to memory block.
    123  */
     83#undef RTMemTmpAlloc
     84#undef RTMemTmpAllocTag
     85#undef RTMemTmpAllocZ
     86#undef RTMemTmpAllocZTag
     87#undef RTMemTmpFree
     88#undef RTMemAlloc
     89#undef RTMemAllocTag
     90#undef RTMemAllocZ
     91#undef RTMemAllocZTag
     92#undef RTMemAllocVar
     93#undef RTMemAllocVarTag
     94#undef RTMemAllocZVar
     95#undef RTMemAllocZVarTag
     96#undef RTMemRealloc
     97#undef RTMemReallocTag
     98#undef RTMemFree
     99#undef RTMemDup
     100#undef RTMemDupTag
     101#undef RTMemDupEx
     102#undef RTMemDupExTag
     103
     104
     105
     106RTDECL(void *)  RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
     107{
     108    return RTMemAllocTag(cb, pszTag);
     109}
     110RT_EXPORT_SYMBOL(RTMemTmpAllocTag);
     111
     112
     113RTDECL(void *)  RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW
     114{
     115    return RTMemAllocZTag(cb, pszTag);
     116}
     117RT_EXPORT_SYMBOL(RTMemTmpAllocZTag);
     118
     119
    124120RTDECL(void)    RTMemTmpFree(void *pv) RT_NO_THROW
    125121{
     
    129125
    130126
    131 /**
    132  * Allocates memory.
    133  *
    134  * @returns Pointer to the allocated memory.
    135  * @returns NULL on failure.
    136  * @param   cb      Size in bytes of the memory block to allocated.
    137  */
    138 RTDECL(void *)  RTMemAlloc(size_t cb) RT_NO_THROW
     127
     128
     129
     130RTDECL(void *)  RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
    139131{
    140132    PRTMEMHDR pHdr;
     
    152144    return NULL;
    153145}
    154 RT_EXPORT_SYMBOL(RTMemAlloc);
    155 
    156 
    157 /**
    158  * Allocates zero'ed memory.
    159  *
    160  * Instead of memset(pv, 0, sizeof()) use this when you want zero'ed
    161  * memory. This keeps the code smaller and the heap can skip the memset
    162  * in about 0.42% of calls :-).
    163  *
    164  * @returns Pointer to the allocated memory.
    165  * @returns NULL on failure.
    166  * @param   cb      Size in bytes of the memory block to allocated.
    167  */
    168 RTDECL(void *)  RTMemAllocZ(size_t cb) RT_NO_THROW
     146RT_EXPORT_SYMBOL(RTMemAllocTag);
     147
     148
     149RTDECL(void *)  RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW
    169150{
    170151    PRTMEMHDR pHdr;
     
    184165    return NULL;
    185166}
    186 RT_EXPORT_SYMBOL(RTMemAllocZ);
    187 
    188 
    189 /**
    190  * Wrapper around RTMemAlloc for automatically aligning variable sized
    191  * allocations so that the various electric fence heaps works correctly.
    192  *
    193  * @returns See RTMemAlloc.
    194  * @param   cbUnaligned         The unaligned size.
    195  */
    196 RTDECL(void *) RTMemAllocVar(size_t cbUnaligned)
     167RT_EXPORT_SYMBOL(RTMemAllocZTag);
     168
     169
     170RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag)
    197171{
    198172    size_t cbAligned;
     
    201175    else
    202176        cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));
    203     return RTMemAlloc(cbAligned);
    204 }
    205 RT_EXPORT_SYMBOL(RTMemAllocVar);
    206 
    207 
    208 /**
    209  * Wrapper around RTMemAllocZ for automatically aligning variable sized
    210  * allocations so that the various electric fence heaps works correctly.
    211  *
    212  * @returns See RTMemAllocZ.
    213  * @param   cbUnaligned         The unaligned size.
    214  */
    215 RTDECL(void *) RTMemAllocZVar(size_t cbUnaligned)
     177    return RTMemAllocTag(cbAligned, pszTag);
     178}
     179RT_EXPORT_SYMBOL(RTMemAllocVarTag);
     180
     181
     182RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag)
    216183{
    217184    size_t cbAligned;
     
    220187    else
    221188        cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));
    222     return RTMemAllocZ(cbAligned);
    223 }
    224 RT_EXPORT_SYMBOL(RTMemAllocZVar);
    225 
    226 
    227 /**
    228  * Reallocates memory.
    229  *
    230  * @returns Pointer to the allocated memory.
    231  * @returns NULL on failure.
    232  * @param   pvOld   The memory block to reallocate.
    233  * @param   cbNew   The new block size (in bytes).
    234  */
    235 RTDECL(void *) RTMemRealloc(void *pvOld, size_t cbNew) RT_NO_THROW
     189    return RTMemAllocZTag(cbAligned, pszTag);
     190}
     191RT_EXPORT_SYMBOL(RTMemAllocZVarTag);
     192
     193
     194RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW
    236195{
    237196    if (!cbNew)
    238197        RTMemFree(pvOld);
    239198    else if (!pvOld)
    240         return RTMemAlloc(cbNew);
     199        return RTMemAllocTag(cbNew, pszTag);
    241200    else
    242201    {
     
    275234    return NULL;
    276235}
    277 RT_EXPORT_SYMBOL(RTMemRealloc);
    278 
    279 
    280 /**
    281  * Free memory related to an virtual machine
    282  *
    283  * @param   pv      Pointer to memory block.
    284  */
     236RT_EXPORT_SYMBOL(RTMemReallocTag);
     237
     238
    285239RTDECL(void) RTMemFree(void *pv) RT_NO_THROW
    286240{
     
    311265
    312266
    313 /**
    314  * Allocates memory which may contain code.
    315  *
    316  * @returns Pointer to the allocated memory.
    317  * @returns NULL on failure.
    318  * @param   cb      Size in bytes of the memory block to allocate.
    319  */
    320 RTDECL(void *)    RTMemExecAlloc(size_t cb) RT_NO_THROW
     267
     268
     269
     270
     271RTDECL(void *)    RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
    321272{
    322273    PRTMEMHDR pHdr;
     
    338289    return NULL;
    339290}
    340 RT_EXPORT_SYMBOL(RTMemExecAlloc);
    341 
    342 
    343 /**
    344  * Free executable/read/write memory allocated by RTMemExecAlloc().
    345  *
    346  * @param   pv      Pointer to memory block.
    347  */
     291RT_EXPORT_SYMBOL(RTMemExecAllocTag);
     292
     293
    348294RTDECL(void)      RTMemExecFree(void *pv) RT_NO_THROW
    349295{
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