VirtualBox

Changeset 31157 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Jul 28, 2010 3:15:35 AM (14 years ago)
Author:
vboxsync
Message:

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

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

Legend:

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

    r28800 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
     
    3636
    3737#undef RTMemDup
     38#undef RTMemDupTag
    3839#undef RTMemDupEx
     40#undef RTMemDupExTag
    3941
    4042
    4143
    42 /**
    43  * Duplicates a chunk of memory into a new heap block.
    44  *
    45  * @returns New heap block with the duplicate data.
    46  * @returns NULL if we're out of memory.
    47  * @param   pvSrc   The memory to duplicate.
    48  * @param   cb      The amount of memory to duplicate.
    49  */
    50 RTDECL(void *) RTMemDup(const void *pvSrc, size_t cb) RT_NO_THROW
     44RTDECL(void *) RTMemDupTag(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW
    5145{
    52     void *pvDst = RTMemAlloc(cb);
     46    void *pvDst = RTMemAllocTag(cb, pszTag);
    5347    if (pvDst)
    5448        memcpy(pvDst, pvSrc, cb);
    5549    return pvDst;
    5650}
    57 RT_EXPORT_SYMBOL(RTMemDup);
     51RT_EXPORT_SYMBOL(RTMemDupTag);
    5852
    5953
    60 /**
    61  * Duplicates a chunk of memory into a new heap block with some
    62  * additional zeroed memory.
    63  *
    64  * @returns New heap block with the duplicate data.
    65  * @returns NULL if we're out of memory.
    66  * @param   pvSrc   The memory to duplicate.
    67  * @param   cbSrc   The amount of memory to duplicate.
    68  * @param   cbExtra The amount of extra memory to allocate and zero.
    69  */
    70 RTDECL(void *) RTMemDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra) RT_NO_THROW
     54RTDECL(void *) RTMemDupExTag(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag) RT_NO_THROW
    7155{
    72     void *pvDst = RTMemAlloc(cbSrc + cbExtra);
     56    void *pvDst = RTMemAllocTag(cbSrc + cbExtra, pszTag);
    7357    if (pvDst)
    7458    {
     
    7862    return pvDst;
    7963}
    80 RT_EXPORT_SYMBOL(RTMemDupEx);
     64RT_EXPORT_SYMBOL(RTMemDupExTag);
    8165
  • trunk/src/VBox/Runtime/common/string/straprintf.cpp

    r28800 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
     
    4343{
    4444    /** Pointer to current buffer position. */
    45     char   *psz;
     45    char       *psz;
    4646    /** Number of bytes left in the buffer - not including the trailing zero. */
    47     size_t  cch;
     47    size_t      cch;
    4848    /** Pointer to the start of the buffer. */
    49     char   *pszBuffer;
     49    char       *pszBuffer;
    5050    /** The number of bytes in the buffer. */
    51     size_t  cchBuffer;
     51    size_t      cchBuffer;
    5252    /** Set if the buffer was allocated using RTMemRealloc(). If clear
    5353     * pszBuffer points to the initial stack buffer. */
    54     bool    fAllocated;
     54    bool        fAllocated;
     55    /** Allocation tag used for statistics and such. */
     56    const char *pszTag;
    5557} STRALLOCARG;
    5658/** Pointer to a strallocoutput() argument structure. */
     
    100102        if (cbAdded <= _1G)
    101103        {
    102             char *pszBuffer = (char *)RTMemRealloc(pArg->fAllocated ? pArg->pszBuffer : NULL, cbAdded + pArg->cchBuffer);
     104            char *pszBuffer = (char *)RTMemReallocTag(pArg->fAllocated ? pArg->pszBuffer : NULL,
     105                                                      cbAdded + pArg->cchBuffer, pArg->pszTag);
    103106            if (pszBuffer)
    104107            {
     
    135138
    136139
    137 RTDECL(int) RTStrAPrintfV(char **ppszBuffer, const char *pszFormat, va_list args)
     140RTDECL(int) RTStrAPrintfVTag(char **ppszBuffer, const char *pszFormat, va_list args, const char *pszTag)
    138141{
    139142    char            szBuf[2048];
     
    144147    Arg.cch         = sizeof(szBuf) - 1;
    145148    Arg.psz         = szBuf;
     149    Arg.pszTag      = pszTag;
    146150    szBuf[0] = '\0';
    147151    int cbRet = (int)RTStrFormatV(strallocoutput, &Arg, NULL, NULL, pszFormat, args);
     
    152156            /* duplicate the string in szBuf */
    153157            Assert(Arg.pszBuffer == szBuf);
    154             char *psz = (char *)RTMemAlloc(cbRet + 1);
     158            char *psz = (char *)RTMemAllocTag(cbRet + 1, pszTag);
    155159            if (psz)
    156160                memcpy(psz, szBuf, cbRet + 1);
     
    160164        {
    161165            /* adjust the allocated buffer */
    162             char *psz = (char *)RTMemRealloc(Arg.pszBuffer, cbRet + 1);
     166            char *psz = (char *)RTMemReallocTag(Arg.pszBuffer, cbRet + 1, pszTag);
    163167            *ppszBuffer = psz ? psz : Arg.pszBuffer;
    164168        }
     
    177181    return cbRet;
    178182}
    179 RT_EXPORT_SYMBOL(RTStrAPrintfV);
     183RT_EXPORT_SYMBOL(RTStrAPrintfVTag);
    180184
    181185
    182 RTDECL(int) RTStrAPrintf(char **ppszBuffer, const char *pszFormat, ...)
    183 {
    184     va_list args;
    185     va_start(args, pszFormat);
    186     int cbRet = RTStrAPrintfV(ppszBuffer, pszFormat, args);
    187     va_end(args);
    188     return cbRet;
    189 }
    190 RT_EXPORT_SYMBOL(RTStrAPrintf);
    191 
    192 
    193 RTDECL(char *) RTStrAPrintf2V(const char *pszFormat, va_list args)
     186RTDECL(char *) RTStrAPrintf2VTag(const char *pszFormat, va_list args, const char *pszTag)
    194187{
    195188    char *pszBuffer;
    196     RTStrAPrintfV(&pszBuffer, pszFormat, args);
     189    RTStrAPrintfVTag(&pszBuffer, pszFormat, args, pszTag);
    197190    return pszBuffer;
    198191}
    199 RT_EXPORT_SYMBOL(RTStrAPrintf2V);
     192RT_EXPORT_SYMBOL(RTStrAPrintf2VTag);
    200193
    201 
    202 RTDECL(char *) RTStrAPrintf2(const char *pszFormat, ...)
    203 {
    204     va_list va;
    205     char   *pszBuffer;
    206 
    207     va_start(va, pszFormat);
    208     RTStrAPrintfV(&pszBuffer, pszFormat, va);
    209     va_end(va);
    210 
    211     return pszBuffer;
    212 }
    213 RT_EXPORT_SYMBOL(RTStrAPrintf2);
    214 
  • trunk/src/VBox/Runtime/common/string/stringalloc.cpp

    r30320 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
     
    4040
    4141
    42 RTDECL(char *) RTStrAlloc(size_t cb)
    43 {
    44     char *psz = (char *)RTMemAlloc(RT_MAX(cb, 1));
     42RTDECL(char *) RTStrAllocTag(size_t cb, const char *pszTag)
     43{
     44    char *psz = (char *)RTMemAllocTag(RT_MAX(cb, 1), pszTag);
    4545    if (psz)
    4646        *psz = '\0';
    4747    return psz;
    4848}
    49 RT_EXPORT_SYMBOL(RTStrAlloc);
    50 
    51 
    52 RTDECL(int) RTStrAllocEx(char **ppsz, size_t cb)
    53 {
    54     char *psz = *ppsz = (char *)RTMemAlloc(RT_MAX(cb, 1));
     49RT_EXPORT_SYMBOL(RTStrAllocTag);
     50
     51
     52RTDECL(int) RTStrAllocExTag(char **ppsz, size_t cb, const char *pszTag)
     53{
     54    char *psz = *ppsz = (char *)RTMemAllocTag(RT_MAX(cb, 1), pszTag);
    5555    if (psz)
    5656    {
     
    6060    return VERR_NO_STR_MEMORY;
    6161}
    62 RT_EXPORT_SYMBOL(RTStrAlloc);
    63 
    64 
    65 RTDECL(int) RTStrRealloc(char **ppsz, size_t cbNew)
     62RT_EXPORT_SYMBOL(RTStrAllocTag);
     63
     64
     65RTDECL(int) RTStrReallocTag(char **ppsz, size_t cbNew, const char *pszTag)
    6666{
    6767    char *pszOld = *ppsz;
     
    7373    else if (pszOld)
    7474    {
    75         char *pszNew = (char *)RTMemRealloc(pszOld, cbNew);
     75        char *pszNew = (char *)RTMemReallocTag(pszOld, cbNew, pszTag);
    7676        if (!pszNew)
    7777            return VERR_NO_STR_MEMORY;
     
    8181    else
    8282    {
    83         char *pszNew = (char *)RTMemAlloc(cbNew);
     83        char *pszNew = (char *)RTMemAllocTag(cbNew, pszTag);
    8484        if (!pszNew)
    8585            return VERR_NO_STR_MEMORY;
     
    9090    return VINF_SUCCESS;
    9191}
     92RT_EXPORT_SYMBOL(RTStrReallocTag);
    9293
    9394RTDECL(void)  RTStrFree(char *pszString)
     
    99100
    100101
    101 RTDECL(char *) RTStrDup(const char *pszString)
     102RTDECL(char *) RTStrDupTag(const char *pszString, const char *pszTag)
    102103{
    103104    AssertPtr(pszString);
    104105    size_t cch = strlen(pszString) + 1;
    105     char *psz = (char *)RTMemAlloc(cch);
     106    char *psz = (char *)RTMemAllocTag(cch, pszTag);
    106107    if (psz)
    107108        memcpy(psz, pszString, cch);
    108109    return psz;
    109110}
    110 RT_EXPORT_SYMBOL(RTStrDup);
    111 
    112 
    113 RTDECL(int)  RTStrDupEx(char **ppszString, const char *pszString)
     111RT_EXPORT_SYMBOL(RTStrDupTag);
     112
     113
     114RTDECL(int)  RTStrDupExTag(char **ppszString, const char *pszString, const char *pszTag)
    114115{
    115116    AssertPtr(ppszString);
     
    117118
    118119    size_t cch = strlen(pszString) + 1;
    119     char *psz = (char *)RTMemAlloc(cch);
     120    char *psz = (char *)RTMemAllocTag(cch, pszTag);
    120121    if (psz)
    121122    {
     
    126127    return VERR_NO_MEMORY;
    127128}
    128 RT_EXPORT_SYMBOL(RTStrDupEx);
    129 
    130 
    131 RTDECL(char *) RTStrDupN(const char *pszString, size_t cchMax)
     129RT_EXPORT_SYMBOL(RTStrDupExTag);
     130
     131
     132RTDECL(char *) RTStrDupNTag(const char *pszString, size_t cchMax, const char *pszTag)
    132133{
    133134    AssertPtr(pszString);
    134135    char const *pszEnd = RTStrEnd(pszString, cchMax);
    135136    size_t      cch    = pszEnd ? (uintptr_t)pszEnd - (uintptr_t)pszString : cchMax;
    136     char       *pszDst = (char *)RTMemAlloc(cch + 1);
     137    char       *pszDst = (char *)RTMemAllocTag(cch + 1, pszTag);
    137138    if (pszDst)
    138139    {
     
    142143    return pszDst;
    143144}
    144 RT_EXPORT_SYMBOL(RTStrDupN);
    145 
    146 
    147 RTDECL(int) RTStrAAppend(char **ppsz, const char *pszAppend)
     145RT_EXPORT_SYMBOL(RTStrDupNTag);
     146
     147
     148RTDECL(int) RTStrAAppendTag(char **ppsz, const char *pszAppend, const char *pszTag)
    148149{
    149150    if (!pszAppend)
    150151        return VINF_SUCCESS;
    151     return RTStrAAppendN(ppsz, pszAppend, RTSTR_MAX);
    152 }
    153 
    154 
    155 RTDECL(int) RTStrAAppendN(char **ppsz, const char *pszAppend, size_t cchAppend)
     152    return RTStrAAppendNTag(ppsz, pszAppend, RTSTR_MAX, pszTag);
     153}
     154
     155
     156RTDECL(int) RTStrAAppendNTag(char **ppsz, const char *pszAppend, size_t cchAppend, const char *pszTag)
    156157{
    157158    if (!cchAppend)
     
    163164
    164165    size_t const cchOrg = *ppsz ? strlen(*ppsz) : 0;
    165     char *pszNew = (char *)RTMemRealloc(*ppsz, cchOrg + cchAppend + 1);
     166    char *pszNew = (char *)RTMemReallocTag(*ppsz, cchOrg + cchAppend + 1, pszTag);
    166167    if (!pszNew)
    167168        return VERR_NO_STR_MEMORY;
     
    175176
    176177
    177 RTDECL(int) RTStrAAppendExNV(char **ppsz, size_t cPairs, va_list va)
     178RTDECL(int) RTStrAAppendExNVTag(char **ppsz, size_t cPairs, va_list va, const char *pszTag)
    178179{
    179180    AssertPtr(ppsz);
     
    212213     * Try reallocate the string.
    213214     */
    214     char *pszNew = (char *)RTMemRealloc(*ppsz, cchNewTotal);
     215    char *pszNew = (char *)RTMemReallocTag(*ppsz, cchNewTotal, pszTag);
    215216    if (!pszNew)
    216217        return VERR_NO_STR_MEMORY;
     
    232233    return VINF_SUCCESS;
    233234}
    234 RT_EXPORT_SYMBOL(RTStrAAppendExNV);
    235 
    236 
    237 RTDECL(int) RTStrAAppendExN(char **ppsz, size_t cPairs, ...)
    238 {
    239     va_list va;
    240     va_start(va, cPairs);
    241     int rc = RTStrAAppendExNV(ppsz, cPairs, va);
    242     va_end(va);
    243     return rc;
    244 }
    245 RT_EXPORT_SYMBOL(RTStrAAppendExN);
    246 
    247 
    248 RTDECL(int) RTStrATruncate(char **ppsz, size_t cchNew)
     235RT_EXPORT_SYMBOL(RTStrAAppendExNVTag);
     236
     237
     238RTDECL(int) RTStrATruncateTag(char **ppsz, size_t cchNew, const char *pszTag)
    249239{
    250240    char *pszOld = *ppsz;
     
    254244        {
    255245            *pszOld = '\0';
    256             char *pszNew = (char *)RTMemRealloc(pszOld, 1);
     246            char *pszNew = (char *)RTMemReallocTag(pszOld, 1, pszTag);
    257247            if (pszNew)
    258248                *ppsz = pszNew;
     
    268258        if (!pszZero)
    269259        {
    270             char *pszNew = (char *)RTMemRealloc(pszOld,  cchNew + 1);
     260            char *pszNew = (char *)RTMemReallocTag(pszOld,  cchNew + 1, pszTag);
    271261            if (pszNew)
    272262                *ppsz = pszNew;
     
    275265    return VINF_SUCCESS;
    276266}
    277 RT_EXPORT_SYMBOL(RTStrATruncate);
    278 
     267RT_EXPORT_SYMBOL(RTStrATruncateTag);
     268
  • trunk/src/VBox/Runtime/common/string/utf-16.cpp

    r30749 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
     
    4848
    4949
    50 RTDECL(PRTUTF16) RTUtf16Dup(PCRTUTF16 pwszString)
     50RTDECL(PRTUTF16) RTUtf16DupTag(PCRTUTF16 pwszString, const char *pszTag)
    5151{
    5252    Assert(pwszString);
    5353    size_t cb = (RTUtf16Len(pwszString) + 1) * sizeof(RTUTF16);
    54     PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc(cb);
     54    PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag(cb, pszTag);
    5555    if (pwsz)
    5656        memcpy(pwsz, pwszString, cb);
    5757    return pwsz;
    5858}
    59 RT_EXPORT_SYMBOL(RTUtf16Dup);
    60 
    61 
    62 RTDECL(int) RTUtf16DupEx(PRTUTF16 *ppwszString, PCRTUTF16 pwszString, size_t cwcExtra)
     59RT_EXPORT_SYMBOL(RTUtf16DupTag);
     60
     61
     62RTDECL(int) RTUtf16DupExTag(PRTUTF16 *ppwszString, PCRTUTF16 pwszString, size_t cwcExtra, const char *pszTag)
    6363{
    6464    Assert(pwszString);
    6565    size_t cb = (RTUtf16Len(pwszString) + 1) * sizeof(RTUTF16);
    66     PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc(cb + cwcExtra * sizeof(RTUTF16));
     66    PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag(cb + cwcExtra * sizeof(RTUTF16), pszTag);
    6767    if (pwsz)
    6868    {
     
    7373    return VERR_NO_MEMORY;
    7474}
    75 RT_EXPORT_SYMBOL(RTUtf16DupEx);
     75RT_EXPORT_SYMBOL(RTUtf16DupExTag);
    7676
    7777
     
    425425
    426426
    427 RTDECL(int)  RTUtf16ToUtf8(PCRTUTF16 pwszString, char **ppszString)
     427RTDECL(int)  RTUtf16ToUtf8Tag(PCRTUTF16 pwszString, char **ppszString, const char *pszTag)
    428428{
    429429    /*
     
    444444         * Allocate buffer and recode it.
    445445         */
    446         char *pszResult = (char *)RTMemAlloc(cch + 1);
     446        char *pszResult = (char *)RTMemAllocTag(cch + 1, pszTag);
    447447        if (pszResult)
    448448        {
     
    461461    return rc;
    462462}
    463 RT_EXPORT_SYMBOL(RTUtf16ToUtf8);
    464 
    465 
    466 RTDECL(int)  RTUtf16ToUtf8Ex(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch)
     463RT_EXPORT_SYMBOL(RTUtf16ToUtf8Tag);
     464
     465
     466RTDECL(int)  RTUtf16ToUtf8ExTag(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch, const char *pszTag)
    467467{
    468468    /*
     
    500500            fShouldFree = true;
    501501            cch = RT_MAX(cch, cchResult + 1);
    502             pszResult = (char *)RTStrAlloc(cch);
     502            pszResult = (char *)RTStrAllocTag(cch, pszTag);
    503503        }
    504504        if (pszResult)
     
    519519    return rc;
    520520}
    521 RT_EXPORT_SYMBOL(RTUtf16ToUtf8Ex);
     521RT_EXPORT_SYMBOL(RTUtf16ToUtf8ExTag);
    522522
    523523
     
    785785
    786786
    787 RTDECL(int)  RTUtf16ToLatin1(PCRTUTF16 pwszString, char **ppszString)
     787RTDECL(int)  RTUtf16ToLatin1Tag(PCRTUTF16 pwszString, char **ppszString, const char *pszTag)
    788788{
    789789    /*
     
    804804         * Allocate buffer and recode it.
    805805         */
    806         char *pszResult = (char *)RTMemAlloc(cch + 1);
     806        char *pszResult = (char *)RTMemAllocTag(cch + 1, pszTag);
    807807        if (pszResult)
    808808        {
     
    821821    return rc;
    822822}
    823 RT_EXPORT_SYMBOL(RTUtf16ToLatin1);
    824 
    825 
    826 RTDECL(int)  RTUtf16ToLatin1Ex(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch)
     823RT_EXPORT_SYMBOL(RTUtf16ToLatin1Tag);
     824
     825
     826RTDECL(int)  RTUtf16ToLatin1ExTag(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch, const char *pszTag)
    827827{
    828828    /*
     
    860860            fShouldFree = true;
    861861            cch = RT_MAX(cch, cchResult + 1);
    862             pszResult = (char *)RTMemAlloc(cch);
     862            pszResult = (char *)RTMemAllocTag(cch, pszTag);
    863863        }
    864864        if (pszResult)
     
    879879    return rc;
    880880}
    881 RT_EXPORT_SYMBOL(RTUtf16ToLatin1Ex);
     881RT_EXPORT_SYMBOL(RTUtf16ToLatin1ExTag);
    882882
    883883
     
    964964
    965965
    966 RTDECL(int) RTLatin1ToUtf16(const char *pszString, PRTUTF16 *ppwszString)
     966RTDECL(int) RTLatin1ToUtf16Tag(const char *pszString, PRTUTF16 *ppwszString, const char *pszTag)
    967967{
    968968    /*
     
    983983         * Allocate buffer.
    984984         */
    985         PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc((cwc + 1) * sizeof(RTUTF16));
     985        PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag((cwc + 1) * sizeof(RTUTF16), pszTag);
    986986        if (pwsz)
    987987        {
     
    10021002    return rc;
    10031003}
    1004 RT_EXPORT_SYMBOL(RTLatin1ToUtf16);
    1005 
    1006 
    1007 RTDECL(int)  RTLatin1ToUtf16Ex(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc)
     1004RT_EXPORT_SYMBOL(RTLatin1ToUtf16Tag);
     1005
     1006
     1007RTDECL(int)  RTLatin1ToUtf16ExTag(const char *pszString, size_t cchString,
     1008                                  PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag)
    10081009{
    10091010    /*
     
    10411042            fShouldFree = true;
    10421043            cwc = RT_MAX(cwcResult + 1, cwc);
    1043             pwszResult = (PRTUTF16)RTMemAlloc(cwc * sizeof(RTUTF16));
     1044            pwszResult = (PRTUTF16)RTMemAllocTag(cwc * sizeof(RTUTF16), pszTag);
    10441045        }
    10451046        if (pwszResult)
     
    10621063    return rc;
    10631064}
    1064 RT_EXPORT_SYMBOL(RTLatin1ToUtf16Ex);
     1065RT_EXPORT_SYMBOL(RTLatin1ToUtf16ExTag);
    10651066
    10661067
  • trunk/src/VBox/Runtime/common/string/utf-8.cpp

    r30859 r31157  
    55
    66/*
    7  * Copyright (C) 2006-2009 Oracle Corporation
     7 * Copyright (C) 2006-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    672672
    673673
    674 RTDECL(int) RTStrToUtf16(const char *pszString, PRTUTF16 *ppwszString)
     674RTDECL(int) RTStrToUtf16Tag(const char *pszString, PRTUTF16 *ppwszString, const char *pszTag)
    675675{
    676676    /*
     
    691691         * Allocate buffer.
    692692         */
    693         PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc((cwc + 1) * sizeof(RTUTF16));
     693        PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag((cwc + 1) * sizeof(RTUTF16), pszTag);
    694694        if (pwsz)
    695695        {
     
    710710    return rc;
    711711}
    712 RT_EXPORT_SYMBOL(RTStrToUtf16);
    713 
    714 
    715 RTDECL(int)  RTStrToUtf16Ex(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc)
     712RT_EXPORT_SYMBOL(RTStrToUtf16Tag);
     713
     714
     715RTDECL(int)  RTStrToUtf16ExTag(const char *pszString, size_t cchString,
     716                               PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag)
    716717{
    717718    /*
     
    749750            fShouldFree = true;
    750751            cwc = RT_MAX(cwcResult + 1, cwc);
    751             pwszResult = (PRTUTF16)RTMemAlloc(cwc * sizeof(RTUTF16));
     752            pwszResult = (PRTUTF16)RTMemAllocTag(cwc * sizeof(RTUTF16), pszTag);
    752753        }
    753754        if (pwszResult)
     
    770771    return rc;
    771772}
    772 RT_EXPORT_SYMBOL(RTStrToUtf16Ex);
     773RT_EXPORT_SYMBOL(RTStrToUtf16ExTag);
    773774
    774775
  • 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{
  • trunk/src/VBox/Runtime/r0drv/memobj-r0drv.cpp

    r29027 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
     
    405405
    406406
    407 /**
    408  * Allocates page aligned virtual kernel memory.
    409  *
    410  * The memory is taken from a non paged (= fixed physical memory backing) pool.
    411  *
    412  * @returns IPRT status code.
    413  * @param   pMemObj         Where to store the ring-0 memory object handle.
    414  * @param   cb              Number of bytes to allocate. This is rounded up to nearest page.
    415  * @param   fExecutable     Flag indicating whether it should be permitted to executed code in the memory object.
    416  */
    417 RTR0DECL(int) RTR0MemObjAllocPage(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable)
     407RTR0DECL(int) RTR0MemObjAllocPageTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag)
    418408{
    419409    /* sanity checks. */
     
    428418    return rtR0MemObjNativeAllocPage(pMemObj, cbAligned, fExecutable);
    429419}
    430 RT_EXPORT_SYMBOL(RTR0MemObjAllocPage);
    431 
    432 
    433 /**
    434  * Allocates page aligned virtual kernel memory with physical backing below 4GB.
    435  *
    436  * The physical memory backing the allocation is fixed.
    437  *
    438  * @returns IPRT status code.
    439  * @param   pMemObj         Where to store the ring-0 memory object handle.
    440  * @param   cb              Number of bytes to allocate. This is rounded up to nearest page.
    441  * @param   fExecutable     Flag indicating whether it should be permitted to executed code in the memory object.
    442  */
    443 RTR0DECL(int) RTR0MemObjAllocLow(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable)
     420RT_EXPORT_SYMBOL(RTR0MemObjAllocPageTag);
     421
     422
     423RTR0DECL(int) RTR0MemObjAllocLowTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag)
    444424{
    445425    /* sanity checks. */
     
    454434    return rtR0MemObjNativeAllocLow(pMemObj, cbAligned, fExecutable);
    455435}
    456 RT_EXPORT_SYMBOL(RTR0MemObjAllocLow);
    457 
    458 
    459 /**
    460  * Allocates page aligned virtual kernel memory with contiguous physical backing below 4GB.
    461  *
    462  * The physical memory backing the allocation is fixed.
    463  *
    464  * @returns IPRT status code.
    465  * @param   pMemObj         Where to store the ring-0 memory object handle.
    466  * @param   cb              Number of bytes to allocate. This is rounded up to nearest page.
    467  * @param   fExecutable     Flag indicating whether it should be permitted to executed code in the memory object.
    468  */
    469 RTR0DECL(int) RTR0MemObjAllocCont(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable)
     436RT_EXPORT_SYMBOL(RTR0MemObjAllocLowTag);
     437
     438
     439RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag)
    470440{
    471441    /* sanity checks. */
     
    480450    return rtR0MemObjNativeAllocCont(pMemObj, cbAligned, fExecutable);
    481451}
    482 RT_EXPORT_SYMBOL(RTR0MemObjAllocCont);
    483 
    484 
    485 /**
    486  * Locks a range of user virtual memory.
    487  *
    488  * @returns IPRT status code.
    489  * @param   pMemObj         Where to store the ring-0 memory object handle.
    490  * @param   R3Ptr           User virtual address. This is rounded down to a page
    491  *                          boundrary.
    492  * @param   cb              Number of bytes to lock. This is rounded up to
    493  *                          nearest page boundrary.
    494  * @param   fAccess         The desired access, a combination of RTMEM_PROT_READ
    495  *                          and RTMEM_PROT_WRITE.
    496  * @param   R0Process       The process to lock pages in. NIL_RTR0PROCESS is an
    497  *                          alias for the current one.
    498  *
    499  * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded
    500  *          down address.
    501  *
    502  * @remarks Linux: This API requires that the memory begin locked is in a memory
    503  *          mapping that is not required in any forked off child process. This
    504  *          is not intented as permanent restriction, feel free to help out
    505  *          lifting it.
    506  */
    507 RTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process)
     452RT_EXPORT_SYMBOL(RTR0MemObjAllocContTag);
     453
     454
     455RTR0DECL(int) RTR0MemObjLockUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb,
     456                                    uint32_t fAccess, RTR0PROCESS R0Process, const char *pszTag)
    508457{
    509458    /* sanity checks. */
     
    523472    return rtR0MemObjNativeLockUser(pMemObj, R3PtrAligned, cbAligned, fAccess, R0Process);
    524473}
    525 RT_EXPORT_SYMBOL(RTR0MemObjLockUser);
    526 
    527 
    528 /**
    529  * Locks a range of kernel virtual memory.
    530  *
    531  * @returns IPRT status code.
    532  * @param   pMemObj         Where to store the ring-0 memory object handle.
    533  * @param   pv              Kernel virtual address. This is rounded down to a page boundrary.
    534  * @param   cb              Number of bytes to lock. This is rounded up to nearest page boundrary.
    535  * @param   fAccess         The desired access, a combination of RTMEM_PROT_READ
    536  *                          and RTMEM_PROT_WRITE.
    537  *
    538  * @remark  RTR0MemGetAddress() will return the rounded down address.
    539  */
    540 RTR0DECL(int) RTR0MemObjLockKernel(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess)
     474RT_EXPORT_SYMBOL(RTR0MemObjLockUserTag);
     475
     476
     477RTR0DECL(int) RTR0MemObjLockKernelTag(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess, const char *pszTag)
    541478{
    542479    /* sanity checks. */
     
    555492    return rtR0MemObjNativeLockKernel(pMemObj, pvAligned, cbAligned, fAccess);
    556493}
    557 RT_EXPORT_SYMBOL(RTR0MemObjLockKernel);
    558 
    559 
    560 /**
    561  * Allocates contiguous page aligned physical memory without (necessarily) any kernel mapping.
    562  *
    563  * @returns IPRT status code.
    564  * @param   pMemObj         Where to store the ring-0 memory object handle.
    565  * @param   cb              Number of bytes to allocate. This is rounded up to nearest page.
    566  * @param   PhysHighest     The highest permittable address (inclusive).
    567  *                          Pass NIL_RTHCPHYS if any address is acceptable.
    568  */
    569 RTR0DECL(int) RTR0MemObjAllocPhys(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest)
     494RT_EXPORT_SYMBOL(RTR0MemObjLockKernelTag);
     495
     496
     497RTR0DECL(int) RTR0MemObjAllocPhysTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag)
    570498{
    571499    /* sanity checks. */
     
    581509    return rtR0MemObjNativeAllocPhys(pMemObj, cbAligned, PhysHighest, PAGE_SIZE /* page aligned */);
    582510}
    583 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhys);
    584 
    585 
    586 /**
    587  * Allocates contiguous physical memory without (necessarily) any kernel mapping.
    588  *
    589  * @returns IPRT status code.
    590  * @param   pMemObj         Where to store the ring-0 memory object handle.
    591  * @param   cb              Number of bytes to allocate. This is rounded up to nearest page.
    592  * @param   PhysHighest     The highest permittable address (inclusive).
    593  *                          Pass NIL_RTHCPHYS if any address is acceptable.
    594  * @param   uAlignment      The alignment of the physical memory to allocate.
    595  *                          Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G.
    596  */
    597 RTR0DECL(int) RTR0MemObjAllocPhysEx(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment)
     511RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysTag);
     512
     513
     514RTR0DECL(int) RTR0MemObjAllocPhysExTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment, const char *pszTag)
    598515{
    599516    /* sanity checks. */
     
    622539    return rtR0MemObjNativeAllocPhys(pMemObj, cbAligned, PhysHighest, uAlignment);
    623540}
    624 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysEx);
    625 
    626 
    627 /**
    628  * Allocates non-contiguous page aligned physical memory without (necessarily) any kernel mapping.
    629  *
    630  * @returns IPRT status code.
    631  * @param   pMemObj         Where to store the ring-0 memory object handle.
    632  * @param   cb              Number of bytes to allocate. This is rounded up to nearest page.
    633  * @param   PhysHighest     The highest permittable address (inclusive).
    634  *                          Pass NIL_RTHCPHYS if any address is acceptable.
    635  */
    636 RTR0DECL(int) RTR0MemObjAllocPhysNC(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest)
     541RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysExTag);
     542
     543
     544RTR0DECL(int) RTR0MemObjAllocPhysNCTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag)
    637545{
    638546    /* sanity checks. */
     
    648556    return rtR0MemObjNativeAllocPhysNC(pMemObj, cbAligned, PhysHighest);
    649557}
    650 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysNC);
    651 
    652 
    653 /**
    654  * Creates a page aligned, contiguous, physical memory object.
    655  *
    656  * No physical memory is allocated, we trust you do know what you're doing.
    657  *
    658  * @returns IPRT status code.
    659  * @param   pMemObj         Where to store the ring-0 memory object handle.
    660  * @param   Phys            The physical address to start at. This is rounded down to the
    661  *                          nearest page boundrary.
    662  * @param   cb              The size of the object in bytes. This is rounded up to nearest page boundrary.
    663  * @param   uCachePolicy    One of the RTMEM_CACHE_XXX modes.
    664  */
    665 RTR0DECL(int) RTR0MemObjEnterPhys(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy)
     558RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysNCTag);
     559
     560
     561RTR0DECL(int) RTR0MemObjEnterPhysTag(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy, const char *pszTag)
    666562{
    667563    /* sanity checks. */
     
    681577    return rtR0MemObjNativeEnterPhys(pMemObj, PhysAligned, cbAligned, uCachePolicy);
    682578}
    683 RT_EXPORT_SYMBOL(RTR0MemObjEnterPhys);
    684 
    685 
    686 /**
    687  * Reserves kernel virtual address space.
    688  *
    689  * @returns IPRT status code.
    690  * @param   pMemObj         Where to store the ring-0 memory object handle.
    691  * @param   pvFixed         Requested address. (void *)-1 means any address. This must match the alignment.
    692  * @param   cb              The number of bytes to reserve. This is rounded up to nearest page.
    693  * @param   uAlignment      The alignment of the reserved memory.
    694  *                          Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
    695  */
    696 RTR0DECL(int) RTR0MemObjReserveKernel(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment)
     579RT_EXPORT_SYMBOL(RTR0MemObjEnterPhysTag);
     580
     581
     582RTR0DECL(int) RTR0MemObjReserveKernelTag(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment, const char *pszTag)
    697583{
    698584    /* sanity checks. */
     
    712598    return rtR0MemObjNativeReserveKernel(pMemObj, pvFixed, cbAligned, uAlignment);
    713599}
    714 RT_EXPORT_SYMBOL(RTR0MemObjReserveKernel);
    715 
    716 
    717 /**
    718  * Reserves user virtual address space in the current process.
    719  *
    720  * @returns IPRT status code.
    721  * @param   pMemObj         Where to store the ring-0 memory object handle.
    722  * @param   R3PtrFixed      Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
    723  * @param   cb              The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
    724  * @param   uAlignment      The alignment of the reserved memory.
    725  *                          Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
    726  * @param   R0Process       The process to reserve the memory in. NIL_RTR0PROCESS is an alias for the current one.
    727  */
    728 RTR0DECL(int) RTR0MemObjReserveUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
     600RT_EXPORT_SYMBOL(RTR0MemObjReserveKernelTag);
     601
     602
     603RTR0DECL(int) RTR0MemObjReserveUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb,
     604                                       size_t uAlignment, RTR0PROCESS R0Process, const char *pszTag)
    729605{
    730606    /* sanity checks. */
     
    746622    return rtR0MemObjNativeReserveUser(pMemObj, R3PtrFixed, cbAligned, uAlignment, R0Process);
    747623}
    748 RT_EXPORT_SYMBOL(RTR0MemObjReserveUser);
    749 
    750 
    751 /**
    752  * Maps a memory object into kernel virtual address space.
    753  *
    754  * @returns IPRT status code.
    755  * @param   pMemObj         Where to store the ring-0 memory object handle of the mapping object.
    756  * @param   MemObjToMap     The object to be map.
    757  * @param   pvFixed         Requested address. (void *)-1 means any address. This must match the alignment.
    758  * @param   uAlignment      The alignment of the reserved memory.
    759  *                          Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
    760  * @param   fProt           Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
    761  */
    762 RTR0DECL(int) RTR0MemObjMapKernel(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt)
    763 {
    764     return RTR0MemObjMapKernelEx(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt, 0, 0);
    765 }
    766 RT_EXPORT_SYMBOL(RTR0MemObjMapKernel);
    767 
    768 
    769 /**
    770  * Maps a memory object into kernel virtual address space.
    771  *
    772  * The ability to map subsections of the object into kernel space is currently
    773  * not implemented on all platforms. All/Most of platforms supports mapping the
    774  * whole object into  kernel space.
    775  *
    776  * @returns IPRT status code.
    777  * @retval  VERR_NOT_SUPPORTED if it's not possible to map a subsection of a
    778  *          memory object on this platform. When you hit this, try implement it.
    779  *
    780  * @param   pMemObj         Where to store the ring-0 memory object handle of the mapping object.
    781  * @param   MemObjToMap     The object to be map.
    782  * @param   pvFixed         Requested address. (void *)-1 means any address. This must match the alignment.
    783  * @param   uAlignment      The alignment of the reserved memory.
    784  *                          Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
    785  * @param   fProt           Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
    786  * @param   offSub          Where in the object to start mapping. If non-zero
    787  *                          the value must be page aligned and cbSub must be
    788  *                          non-zero as well.
    789  * @param   cbSub           The size of the part of the object to be mapped. If
    790  *                          zero the entire object is mapped. The value must be
    791  *                          page aligned.
    792  */
    793 RTR0DECL(int) RTR0MemObjMapKernelEx(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment,
    794                                     unsigned fProt, size_t offSub, size_t cbSub)
     624RT_EXPORT_SYMBOL(RTR0MemObjReserveUserTag);
     625
     626
     627RTR0DECL(int) RTR0MemObjMapKernelTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed,
     628                                     size_t uAlignment, unsigned fProt, const char *pszTag)
     629{
     630    return RTR0MemObjMapKernelExTag(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt, 0, 0, pszTag);
     631}
     632RT_EXPORT_SYMBOL(RTR0MemObjMapKernelTag);
     633
     634
     635RTR0DECL(int) RTR0MemObjMapKernelExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment,
     636                                       unsigned fProt, size_t offSub, size_t cbSub, const char *pszTag)
    795637{
    796638    PRTR0MEMOBJINTERNAL pMemToMap;
     
    846688    return rc;
    847689}
    848 RT_EXPORT_SYMBOL(RTR0MemObjMapKernelEx);
    849 
    850 
    851 /**
    852  * Maps a memory object into user virtual address space in the current process.
    853  *
    854  * @returns IPRT status code.
    855  * @param   pMemObj         Where to store the ring-0 memory object handle of the mapping object.
    856  * @param   MemObjToMap     The object to be map.
    857  * @param   R3PtrFixed      Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
    858  * @param   uAlignment      The alignment of the reserved memory.
    859  *                          Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
    860  * @param   fProt           Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
    861  * @param   R0Process       The process to map the memory into. NIL_RTR0PROCESS is an alias for the current one.
    862  */
    863 RTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
     690RT_EXPORT_SYMBOL(RTR0MemObjMapKernelExTag);
     691
     692
     693RTR0DECL(int) RTR0MemObjMapUserTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed,
     694                                   size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process, const char *pszTag)
    864695{
    865696    /* sanity checks. */
     
    907738    return rc;
    908739}
    909 RT_EXPORT_SYMBOL(RTR0MemObjMapUser);
     740RT_EXPORT_SYMBOL(RTR0MemObjMapUserTag);
    910741
    911742
  • trunk/src/VBox/Runtime/r3/alloc-ef-cpp.cpp

    r28800 r31157  
    5858void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc)
    5959{
    60     void *pv = rtR3MemAlloc("new", RTMEMTYPE_NEW, cb, cb, ASMReturnAddress(), NULL, 0, NULL);
     60    void *pv = rtR3MemAlloc("new", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
    6161    if (!pv)
    6262        throw std::bad_alloc();
     
    6767void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
    6868{
    69     void *pv = rtR3MemAlloc("new nothrow", RTMEMTYPE_NEW, cb, cb, ASMReturnAddress(), NULL, 0, NULL);
     69    void *pv = rtR3MemAlloc("new nothrow", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
    7070    return pv;
    7171}
     
    9494void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc)
    9595{
    96     void *pv = rtR3MemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, cb, ASMReturnAddress(), NULL, 0, NULL);
     96    void *pv = rtR3MemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
    9797    if (!pv)
    9898        throw std::bad_alloc();
     
    103103void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
    104104{
    105     void *pv = rtR3MemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, cb, ASMReturnAddress(), NULL, 0, NULL);
     105    void *pv = rtR3MemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
    106106    return pv;
    107107}
  • trunk/src/VBox/Runtime/r3/alloc-ef.cpp

    r28800 r31157  
    127127 */
    128128DECLINLINE(PRTMEMBLOCK) rtmemBlockCreate(RTMEMTYPE enmType, size_t cbUnaligned, size_t cbAligned,
    129                                          void *pvCaller, RT_SRC_POS_DECL)
     129                                         const char *pszTag, void *pvCaller, RT_SRC_POS_DECL)
    130130{
    131131    PRTMEMBLOCK pBlock = (PRTMEMBLOCK)malloc(sizeof(*pBlock));
     
    135135        pBlock->cbUnaligned = cbUnaligned;
    136136        pBlock->cbAligned   = cbAligned;
     137        pBlock->pszTag      = pszTag;
    137138        pBlock->pvCaller    = pvCaller;
    138139        pBlock->iLine       = iLine;
     
    273274 */
    274275RTDECL(void *) rtR3MemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cbUnaligned, size_t cbAligned,
    275                             void *pvCaller, RT_SRC_POS_DECL)
     276                            const char *pszTag, void *pvCaller, RT_SRC_POS_DECL)
    276277{
    277278    /*
     
    305306     * Allocate the trace block.
    306307     */
    307     PRTMEMBLOCK pBlock = rtmemBlockCreate(enmType, cbUnaligned, cbAligned, pvCaller, RT_SRC_POS_ARGS);
     308    PRTMEMBLOCK pBlock = rtmemBlockCreate(enmType, cbUnaligned, cbAligned, pszTag, pvCaller, RT_SRC_POS_ARGS);
    308309    if (!pBlock)
    309310    {
     
    503504 * Internal realloc.
    504505 */
    505 RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, RT_SRC_POS_DECL)
     506RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew,
     507                              const char *pszTag, void *pvCaller, RT_SRC_POS_DECL)
    506508{
    507509    /*
     
    509511     */
    510512    if (!pvOld)
    511         return rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, pvCaller, RT_SRC_POS_ARGS);
     513        return rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, pszTag, pvCaller, RT_SRC_POS_ARGS);
    512514    if (!cbNew)
    513515    {
     
    524526    if (pBlock)
    525527    {
    526         void *pvRet = rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, pvCaller, RT_SRC_POS_ARGS);
     528        void *pvRet = rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, pszTag, pvCaller, RT_SRC_POS_ARGS);
    527529        if (pvRet)
    528530        {
     
    547549
    548550
    549 RTDECL(void *)  RTMemEfTmpAlloc(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW
    550 {
    551     return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);
    552 }
    553 
    554 
    555 RTDECL(void *)  RTMemEfTmpAllocZ(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW
    556 {
    557     return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);
     551RTDECL(void *)  RTMemEfTmpAlloc(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW
     552{
     553    return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS);
     554}
     555
     556
     557RTDECL(void *)  RTMemEfTmpAllocZ(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW
     558{
     559    return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS);
    558560}
    559561
     
    566568
    567569
    568 RTDECL(void *)  RTMemEfAlloc(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW
    569 {
    570     return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);
    571 }
    572 
    573 
    574 RTDECL(void *)  RTMemEfAllocZ(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW
    575 {
    576     return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);
    577 }
    578 
    579 
    580 RTDECL(void *)  RTMemEfAllocVar(size_t cbUnaligned, RT_SRC_POS_DECL) RT_NO_THROW
     570RTDECL(void *)  RTMemEfAlloc(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW
     571{
     572    return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS);
     573}
     574
     575
     576RTDECL(void *)  RTMemEfAllocZ(size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW
     577{
     578    return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS);
     579}
     580
     581
     582RTDECL(void *)  RTMemEfAllocVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW
    581583{
    582584    size_t cbAligned;
     
    585587    else
    586588        cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));
    587     return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, ASMReturnAddress(), RT_SRC_POS_ARGS);
    588 }
    589 
    590 
    591 RTDECL(void *)  RTMemEfAllocZVar(size_t cbUnaligned, RT_SRC_POS_DECL) RT_NO_THROW
     589    return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS);
     590}
     591
     592
     593RTDECL(void *)  RTMemEfAllocZVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW
    592594{
    593595    size_t cbAligned;
     
    596598    else
    597599        cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));
    598     return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, ASMReturnAddress(), RT_SRC_POS_ARGS);
    599 }
    600 
    601 
    602 RTDECL(void *)  RTMemEfRealloc(void *pvOld, size_t cbNew, RT_SRC_POS_DECL) RT_NO_THROW
    603 {
    604     return rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ASMReturnAddress(), RT_SRC_POS_ARGS);
     600    return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS);
     601}
     602
     603
     604RTDECL(void *)  RTMemEfRealloc(void *pvOld, size_t cbNew, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW
     605{
     606    return rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS);
    605607}
    606608
     
    613615
    614616
    615 RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW
    616 {
    617     void *pvDst = RTMemEfAlloc(cb, RT_SRC_POS_ARGS);
     617RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW
     618{
     619    void *pvDst = RTMemEfAlloc(cb, pszTag, RT_SRC_POS_ARGS);
    618620    if (pvDst)
    619621        memcpy(pvDst, pvSrc, cb);
     
    622624
    623625
    624 RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, RT_SRC_POS_DECL) RT_NO_THROW
    625 {
    626     void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, RT_SRC_POS_ARGS);
     626RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW
     627{
     628    void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, pszTag, RT_SRC_POS_ARGS);
    627629    if (pvDst)
    628630    {
     
    644646
    645647
    646 RTDECL(void *)  RTMemEfTmpAllocNP(size_t cb) RT_NO_THROW
    647 {
    648     return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL);
    649 }
    650 
    651 
    652 RTDECL(void *)  RTMemEfTmpAllocZNP(size_t cb) RT_NO_THROW
    653 {
    654     return rtR3MemAlloc("TmpAllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL);
     648RTDECL(void *)  RTMemEfTmpAllocNP(size_t cb, const char *pszTag) RT_NO_THROW
     649{
     650    return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL);
     651}
     652
     653
     654RTDECL(void *)  RTMemEfTmpAllocZNP(size_t cb, const char *pszTag) RT_NO_THROW
     655{
     656    return rtR3MemAlloc("TmpAllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL);
    655657}
    656658
     
    663665
    664666
    665 RTDECL(void *)  RTMemEfAllocNP(size_t cb) RT_NO_THROW
    666 {
    667     return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL);
    668 }
    669 
    670 
    671 RTDECL(void *)  RTMemEfAllocZNP(size_t cb) RT_NO_THROW
    672 {
    673     return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL);
    674 }
    675 
    676 
    677 RTDECL(void *)  RTMemEfAllocVarNP(size_t cbUnaligned) RT_NO_THROW
     667RTDECL(void *)  RTMemEfAllocNP(size_t cb, const char *pszTag) RT_NO_THROW
     668{
     669    return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL);
     670}
     671
     672
     673RTDECL(void *)  RTMemEfAllocZNP(size_t cb, const char *pszTag) RT_NO_THROW
     674{
     675    return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL);
     676}
     677
     678
     679RTDECL(void *)  RTMemEfAllocVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW
    678680{
    679681    size_t cbAligned;
     
    682684    else
    683685        cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));
    684     return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL);
    685 }
    686 
    687 
    688 RTDECL(void *)  RTMemEfAllocZVarNP(size_t cbUnaligned) RT_NO_THROW
     686    return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL);
     687}
     688
     689
     690RTDECL(void *)  RTMemEfAllocZVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW
    689691{
    690692    size_t cbAligned;
     
    693695    else
    694696        cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));
    695     return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL);
    696 }
    697 
    698 
    699 RTDECL(void *)  RTMemEfReallocNP(void *pvOld, size_t cbNew) RT_NO_THROW
    700 {
    701     return rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ASMReturnAddress(), NULL, 0, NULL);
     697    return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL);
     698}
     699
     700
     701RTDECL(void *)  RTMemEfReallocNP(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW
     702{
     703    return rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, pszTag, ASMReturnAddress(), NULL, 0, NULL);
    702704}
    703705
     
    710712
    711713
    712 RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb) RT_NO_THROW
    713 {
    714     void *pvDst = RTMemEfAlloc(cb, NULL, 0, NULL);
     714RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW
     715{
     716    void *pvDst = RTMemEfAlloc(cb, pszTag, NULL, 0, NULL);
    715717    if (pvDst)
    716718        memcpy(pvDst, pvSrc, cb);
     
    719721
    720722
    721 RTDECL(void *) RTMemEfDupExNP(const void *pvSrc, size_t cbSrc, size_t cbExtra) RT_NO_THROW
    722 {
    723     void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, NULL, 0, NULL);
     723RTDECL(void *) RTMemEfDupExNP(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag) RT_NO_THROW
     724{
     725    void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, pszTag, NULL, 0, NULL);
    724726    if (pvDst)
    725727    {
  • trunk/src/VBox/Runtime/r3/alloc-ef.h

    r28800 r31157  
    166166    /** The aligned size of the block. */
    167167    size_t          cbAligned;
     168    /** The allocation tag (read-only string). */
     169    const char     *pszTag;
    168170    /** The return address of the allocator function. */
    169171    void           *pvCaller;
     
    184186RT_C_DECLS_BEGIN
    185187RTDECL(void *)  rtR3MemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cbUnaligned, size_t cbAligned,
    186                              void *pvCaller, RT_SRC_POS_DECL);
    187 RTDECL(void *)  rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, RT_SRC_POS_DECL);
     188                             const char *pszTag, void *pvCaller, RT_SRC_POS_DECL);
     189RTDECL(void *)  rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew,
     190                               const char *pszTag, void *pvCaller, RT_SRC_POS_DECL);
    188191RTDECL(void)    rtR3MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, RT_SRC_POS_DECL);
    189192RT_C_DECLS_END
  • trunk/src/VBox/Runtime/r3/alloc.cpp

    r28800 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
     
    4848
    4949#undef RTMemTmpAlloc
     50#undef RTMemTmpAllocTag
    5051#undef RTMemTmpAllocZ
     52#undef RTMemTmpAllocZTag
    5153#undef RTMemTmpFree
    5254#undef RTMemAlloc
     55#undef RTMemAllocTag
    5356#undef RTMemAllocZ
     57#undef RTMemAllocZTag
    5458#undef RTMemAllocVar
     59#undef RTMemAllocVarTag
    5560#undef RTMemAllocZVar
     61#undef RTMemAllocZVarTag
    5662#undef RTMemRealloc
     63#undef RTMemReallocTag
    5764#undef RTMemFree
    5865#undef RTMemDup
     66#undef RTMemDupTag
    5967#undef RTMemDupEx
     68#undef RTMemDupExTag
    6069
    6170
    62 /**
    63  * Allocates temporary memory.
    64  *
    65  * Temporary memory blocks are used for not too large memory blocks which
    66  * are believed not to stick around for too long. Using this API instead
    67  * of RTMemAlloc() not only gives the heap manager room for optimization
    68  * but makes the code easier to read.
    69  *
    70  * @returns Pointer to the allocated memory.
    71  * @returns NULL on failure.
    72  * @param   cb      Size in bytes of the memory block to allocate.
    73  */
    74 RTDECL(void *)  RTMemTmpAlloc(size_t cb) RT_NO_THROW
     71RTDECL(void *)  RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
    7572{
    76     return RTMemAlloc(cb);
     73    return RTMemAllocTag(cb, pszTag);
    7774}
    7875
    7976
    80 /**
    81  * Allocates zero'ed temporary memory.
    82  *
    83  * Same as RTMemTmpAlloc() but the memory will be zero'ed.
    84  *
    85  * @returns Pointer to the allocated memory.
    86  * @returns NULL on failure.
    87  * @param   cb      Size in bytes of the memory block to allocate.
    88  */
    89 RTDECL(void *)  RTMemTmpAllocZ(size_t cb) RT_NO_THROW
     77RTDECL(void *)  RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW
    9078{
    91     return RTMemAllocZ(cb);
     79    return RTMemAllocZTag(cb, pszTag);
    9280}
    9381
    9482
    95 /**
    96  * Free temporary memory.
    97  *
    98  * @param   pv      Pointer to memory block.
    99  */
    100 RTDECL(void)    RTMemTmpFree(void *pv) RT_NO_THROW
     83RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW
    10184{
    10285    RTMemFree(pv);
     
    10487
    10588
    106 /**
    107  * Allocates memory.
    108  *
    109  * @returns Pointer to the allocated memory.
    110  * @returns NULL on failure.
    111  * @param   cb      Size in bytes of the memory block to allocate.
    112  */
    113 RTDECL(void *)  RTMemAlloc(size_t cb) RT_NO_THROW
     89RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
    11490{
    11591#ifdef RTALLOC_USE_EFENCE
    116     void *pv = rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL);
     92    void *pv = rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL);
    11793
    11894#else /* !RTALLOC_USE_EFENCE */
     
    130106
    131107
    132 /**
    133  * Allocates zero'ed memory.
    134  *
    135  * Instead of memset(pv, 0, sizeof()) use this when you want zero'ed
    136  * memory. This keeps the code smaller and the heap can skip the memset
    137  * in about 0.42% of the calls :-).
    138  *
    139  * @returns Pointer to the allocated memory.
    140  * @returns NULL on failure.
    141  * @param   cb      Size in bytes of the memory block to allocate.
    142  */
    143 RTDECL(void *)  RTMemAllocZ(size_t cb) RT_NO_THROW
     108RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW
    144109{
    145110#ifdef RTALLOC_USE_EFENCE
    146     void *pv = rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL);
     111    void *pv = rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL);
    147112
    148113#else /* !RTALLOC_USE_EFENCE */
     
    161126
    162127
    163 /**
    164  * Wrapper around RTMemAlloc for automatically aligning variable sized
    165  * allocations so that the various electric fence heaps works correctly.
    166  *
    167  * @returns See RTMemAlloc.
    168  * @param   cbUnaligned         The unaligned size.
    169  */
    170 RTDECL(void *) RTMemAllocVar(size_t cbUnaligned)
     128RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW
    171129{
    172130    size_t cbAligned;
     
    176134        cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));
    177135#ifdef RTALLOC_USE_EFENCE
    178     void *pv = rtR3MemAlloc("AllocVar", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL);
     136    void *pv = rtR3MemAlloc("AllocVar", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL);
    179137#else
    180     void *pv = RTMemAlloc(cbAligned);
     138    void *pv = RTMemAllocTag(cbAligned, pszTag);
    181139#endif
    182140    return pv;
     
    184142
    185143
    186 /**
    187  * Wrapper around RTMemAllocZ for automatically aligning variable sized
    188  * allocations so that the various electric fence heaps works correctly.
    189  *
    190  * @returns See RTMemAllocZ.
    191  * @param   cbUnaligned         The unaligned size.
    192  */
    193 RTDECL(void *) RTMemAllocZVar(size_t cbUnaligned)
     144RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW
    194145{
    195146    size_t cbAligned;
     
    199150        cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));
    200151#ifdef RTALLOC_USE_EFENCE
    201     void *pv = rtR3MemAlloc("AllocZVar", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL);
     152    void *pv = rtR3MemAlloc("AllocZVar", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL);
    202153#else
    203     void *pv = RTMemAllocZ(cbAligned);
     154    void *pv = RTMemAllocZTag(cbAligned, pszTag);
    204155#endif
    205156    return pv;
     
    207158
    208159
    209 /**
    210  * Reallocates memory.
    211  *
    212  * @returns Pointer to the allocated memory.
    213  * @returns NULL on failure.
    214  * @param   pvOld   The memory block to reallocate.
    215  * @param   cbNew   The new block size (in bytes).
    216  */
    217 RTDECL(void *)  RTMemRealloc(void *pvOld, size_t cbNew) RT_NO_THROW
     160RTDECL(void *)  RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW
    218161{
    219162#ifdef RTALLOC_USE_EFENCE
    220     void *pv = rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ASMReturnAddress(), NULL, 0, NULL);
     163    void *pv = rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, pszTag, ASMReturnAddress(), NULL, 0, NULL);
    221164
    222165#else /* !RTALLOC_USE_EFENCE */
     
    233176
    234177
    235 /**
    236  * Free memory related to a virtual machine
    237  *
    238  * @param   pv      Pointer to memory block.
    239  */
    240 RTDECL(void)    RTMemFree(void *pv) RT_NO_THROW
     178RTDECL(void) RTMemFree(void *pv) RT_NO_THROW
    241179{
    242180    if (pv)
  • trunk/src/VBox/Runtime/r3/darwin/alloc-darwin.cpp

    r28800 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
     
    4040
    4141
    42 /**
    43  * Allocates memory which may contain code.
    44  *
    45  * @returns Pointer to the allocated memory.
    46  * @returns NULL on failure.
    47  * @param   cb      Size in bytes of the memory block to allocate.
    48  */
    49 RTDECL(void *) RTMemExecAlloc(size_t cb) RT_NO_THROW
     42RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
    5043{
    5144    /*
     
    7467
    7568
    76 /**
    77  * Free executable/read/write memory allocated by RTMemExecAlloc().
    78  *
    79  * @param   pv      Pointer to memory block.
    80  */
    8169RTDECL(void)    RTMemExecFree(void *pv) RT_NO_THROW
    8270{
     
    8674
    8775
    88 /**
    89  * Allocate page aligned memory.
    90  *
    91  * @returns Pointer to the allocated memory.
    92  * @returns NULL if we're out of memory.
    93  * @param   cb  Size of the memory block. Will be rounded up to page size.
    94  */
    95 RTDECL(void *) RTMemPageAlloc(size_t cb) RT_NO_THROW
     76RTDECL(void *) RTMemPageAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
    9677{
    9778    return valloc(RT_ALIGN_Z(cb, PAGE_SIZE));
     
    9980
    10081
    101 /**
    102  * Allocate zero'ed page aligned memory.
    103  *
    104  * @returns Pointer to the allocated memory.
    105  * @returns NULL if we're out of memory.
    106  * @param   cb  Size of the memory block. Will be rounded up to page size.
    107  */
    108 RTDECL(void *) RTMemPageAllocZ(size_t cb) RT_NO_THROW
     82RTDECL(void *) RTMemPageAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW
    10983{
    11084    cb = RT_ALIGN_Z(cb, PAGE_SIZE);
     
    11690
    11791
    118 /**
    119  * Free a memory block allocated with RTMemPageAlloc() or RTMemPageAllocZ().
    120  *
    121  * @param   pv      Pointer to the block as it was returned by the allocation function.
    122  *                  NULL will be ignored.
    123  */
    12492RTDECL(void) RTMemPageFree(void *pv, size_t cb) RT_NO_THROW
    12593{
     
    12997
    13098
    131 /**
    132  * Change the page level protection of a memory region.
    133  *
    134  * @returns iprt status code.
    135  * @param   pv          Start of the region. Will be rounded down to nearest page boundary.
    136  * @param   cb          Size of the region. Will be rounded up to the nearest page boundary.
    137  * @param   fProtect    The new protection, a combination of the RTMEM_PROT_* defines.
    138  */
    13999RTDECL(int) RTMemProtect(void *pv, size_t cb, unsigned fProtect) RT_NO_THROW
    140100{
  • trunk/src/VBox/Runtime/r3/posix/utf8-posix.cpp

    r30294 r31157  
    413413
    414414
    415 /**
    416  * Allocates tmp buffer, translates pszString from UTF8 to current codepage.
    417  *
    418  * @returns iprt status code.
    419  * @param   ppszString      Receives pointer of allocated native CP string.
    420  *                          The returned pointer must be freed using RTStrFree().
    421  * @param   pszString       UTF-8 string to convert.
    422  */
    423 RTR3DECL(int)  RTStrUtf8ToCurrentCP(char **ppszString, const char *pszString)
     415RTR3DECL(int)  RTStrUtf8ToCurrentCPTag(char **ppszString, const char *pszString, const char *pszTag)
    424416{
    425417    Assert(ppszString);
     
    434426    {
    435427        /* zero length string passed. */
    436         *ppszString = (char *)RTMemTmpAllocZ(sizeof(char));
     428        *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag);
    437429        if (*ppszString)
    438430            return VINF_SUCCESS;
     
    443435
    444436
    445 /**
    446  * Allocates tmp buffer, translates pszString from current codepage to UTF-8.
    447  *
    448  * @returns iprt status code.
    449  * @param   ppszString      Receives pointer of allocated UTF-8 string.
    450  *                          The returned pointer must be freed using RTStrFree().
    451  * @param   pszString       Native string to convert.
    452  */
    453 RTR3DECL(int)  RTStrCurrentCPToUtf8(char **ppszString, const char *pszString)
     437RTR3DECL(int)  RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag)
    454438{
    455439    Assert(ppszString);
     
    464448    {
    465449        /* zero length string passed. */
    466         *ppszString = (char *)RTMemTmpAllocZ(sizeof(char));
     450        *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag);
    467451        if (*ppszString)
    468452            return VINF_SUCCESS;
  • trunk/src/VBox/Runtime/r3/win/utf8-win.cpp

    r28800 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
     
    3838
    3939
    40 /**
    41  * Allocates tmp buffer, translates pszString from UTF8 to current codepage.
    42  *
    43  * @returns iprt status code.
    44  * @param   ppszString      Receives pointer of allocated native CP string.
    45  *                          The returned pointer must be freed using RTStrFree().
    46  * @param   pszString       UTF-8 string to convert.
    47  */
    48 RTR3DECL(int)  RTStrUtf8ToCurrentCP(char **ppszString, const char *pszString)
     40RTR3DECL(int)  RTStrUtf8ToCurrentCPTag(char **ppszString, const char *pszString, const char *pszTag)
    4941{
    5042    Assert(ppszString);
     
    5648    if (!*pszString)
    5749    {
    58         *ppszString = (char *)RTMemTmpAllocZ(sizeof(char));
     50        *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag);
    5951        if (*ppszString)
    6052            return VINF_SUCCESS;
     
    8173         * Alloc space for result buffer.
    8274         */
    83         LPSTR lpString = (LPSTR)RTMemTmpAlloc(cbResult);
     75        LPSTR lpString = (LPSTR)RTMemTmpAllocTag(cbResult, pszTag);
    8476        if (lpString)
    8577        {
     
    115107}
    116108
    117 /**
    118  * Allocates tmp buffer, translates pszString from current codepage to UTF-8.
    119  *
    120  * @returns iprt status code.
    121  * @param   ppszString      Receives pointer of allocated UTF-8 string.
    122  *                          The returned pointer must be freed using RTStrFree().
    123  * @param   pszString       Native string to convert.
    124  */
    125 RTR3DECL(int)  RTStrCurrentCPToUtf8(char **ppszString, const char *pszString)
     109
     110RTR3DECL(int)  RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag)
    126111{
    127112    Assert(ppszString);
     
    135120    {
    136121        /* zero length string passed. */
    137         *ppszString = (char *)RTMemTmpAllocZ(sizeof(char));
     122        *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag);
    138123        if (*ppszString)
    139124            return VINF_SUCCESS;
  • trunk/src/VBox/Runtime/testcase/tstMemAutoPtr.cpp

    r28800 r31157  
    55
    66/*
    7  * Copyright (C) 2008 Oracle Corporation
     7 * Copyright (C) 2008-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    114114
    115115
    116 void *tstMemAutoPtrAllocatorNoZero(void *pvOld, size_t cbNew)
    117 {
    118     void *pvNew = RTMemRealloc(pvOld, cbNew);
     116void *tstMemAutoPtrAllocatorNoZero(void *pvOld, size_t cbNew, const char *pszTag)
     117{
     118    void *pvNew = RTMemReallocTag(pvOld, cbNew, pszTag);
    119119    if (pvNew)
    120120        memset(pvNew, 0xfe, cbNew);
  • trunk/src/VBox/Runtime/testcase/tstRTMemEf.cpp

    r28800 r31157  
    4747     * the word after the allocated block and the word before. One of them
    4848     * will crash no matter whether the fence is at the bottom or on top. */
    49     int32_t *p = (int32_t *)RTMemEfAllocNP(sizeof(int32_t));
     49    int32_t *p = (int32_t *)RTMemEfAllocNP(sizeof(int32_t), RTMEM_TAG);
    5050    RTPrintf("tstRTMemAllocEfAccess: allocated int32_t at %#p\n", p);
    5151    RTPrintf("tstRTMemAllocEfAccess: triggering buffer overrun...\n");
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