Changeset 31157 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jul 28, 2010 3:15:35 AM (14 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/alloc/alloc.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 36 36 37 37 #undef RTMemDup 38 #undef RTMemDupTag 38 39 #undef RTMemDupEx 40 #undef RTMemDupExTag 39 41 40 42 41 43 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 44 RTDECL(void *) RTMemDupTag(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW 51 45 { 52 void *pvDst = RTMemAlloc (cb);46 void *pvDst = RTMemAllocTag(cb, pszTag); 53 47 if (pvDst) 54 48 memcpy(pvDst, pvSrc, cb); 55 49 return pvDst; 56 50 } 57 RT_EXPORT_SYMBOL(RTMemDup );51 RT_EXPORT_SYMBOL(RTMemDupTag); 58 52 59 53 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 54 RTDECL(void *) RTMemDupExTag(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag) RT_NO_THROW 71 55 { 72 void *pvDst = RTMemAlloc (cbSrc + cbExtra);56 void *pvDst = RTMemAllocTag(cbSrc + cbExtra, pszTag); 73 57 if (pvDst) 74 58 { … … 78 62 return pvDst; 79 63 } 80 RT_EXPORT_SYMBOL(RTMemDupEx );64 RT_EXPORT_SYMBOL(RTMemDupExTag); 81 65 -
trunk/src/VBox/Runtime/common/string/straprintf.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 43 43 { 44 44 /** Pointer to current buffer position. */ 45 char *psz;45 char *psz; 46 46 /** Number of bytes left in the buffer - not including the trailing zero. */ 47 size_t cch;47 size_t cch; 48 48 /** Pointer to the start of the buffer. */ 49 char *pszBuffer;49 char *pszBuffer; 50 50 /** The number of bytes in the buffer. */ 51 size_t cchBuffer;51 size_t cchBuffer; 52 52 /** Set if the buffer was allocated using RTMemRealloc(). If clear 53 53 * 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; 55 57 } STRALLOCARG; 56 58 /** Pointer to a strallocoutput() argument structure. */ … … 100 102 if (cbAdded <= _1G) 101 103 { 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); 103 106 if (pszBuffer) 104 107 { … … 135 138 136 139 137 RTDECL(int) RTStrAPrintfV (char **ppszBuffer, const char *pszFormat, va_list args)140 RTDECL(int) RTStrAPrintfVTag(char **ppszBuffer, const char *pszFormat, va_list args, const char *pszTag) 138 141 { 139 142 char szBuf[2048]; … … 144 147 Arg.cch = sizeof(szBuf) - 1; 145 148 Arg.psz = szBuf; 149 Arg.pszTag = pszTag; 146 150 szBuf[0] = '\0'; 147 151 int cbRet = (int)RTStrFormatV(strallocoutput, &Arg, NULL, NULL, pszFormat, args); … … 152 156 /* duplicate the string in szBuf */ 153 157 Assert(Arg.pszBuffer == szBuf); 154 char *psz = (char *)RTMemAlloc (cbRet + 1);158 char *psz = (char *)RTMemAllocTag(cbRet + 1, pszTag); 155 159 if (psz) 156 160 memcpy(psz, szBuf, cbRet + 1); … … 160 164 { 161 165 /* adjust the allocated buffer */ 162 char *psz = (char *)RTMemRealloc (Arg.pszBuffer, cbRet + 1);166 char *psz = (char *)RTMemReallocTag(Arg.pszBuffer, cbRet + 1, pszTag); 163 167 *ppszBuffer = psz ? psz : Arg.pszBuffer; 164 168 } … … 177 181 return cbRet; 178 182 } 179 RT_EXPORT_SYMBOL(RTStrAPrintfV );183 RT_EXPORT_SYMBOL(RTStrAPrintfVTag); 180 184 181 185 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) 186 RTDECL(char *) RTStrAPrintf2VTag(const char *pszFormat, va_list args, const char *pszTag) 194 187 { 195 188 char *pszBuffer; 196 RTStrAPrintfV (&pszBuffer, pszFormat, args);189 RTStrAPrintfVTag(&pszBuffer, pszFormat, args, pszTag); 197 190 return pszBuffer; 198 191 } 199 RT_EXPORT_SYMBOL(RTStrAPrintf2V );192 RT_EXPORT_SYMBOL(RTStrAPrintf2VTag); 200 193 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 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 40 40 41 41 42 RTDECL(char *) RTStrAlloc (size_t cb)43 { 44 char *psz = (char *)RTMemAlloc (RT_MAX(cb, 1));42 RTDECL(char *) RTStrAllocTag(size_t cb, const char *pszTag) 43 { 44 char *psz = (char *)RTMemAllocTag(RT_MAX(cb, 1), pszTag); 45 45 if (psz) 46 46 *psz = '\0'; 47 47 return psz; 48 48 } 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));49 RT_EXPORT_SYMBOL(RTStrAllocTag); 50 51 52 RTDECL(int) RTStrAllocExTag(char **ppsz, size_t cb, const char *pszTag) 53 { 54 char *psz = *ppsz = (char *)RTMemAllocTag(RT_MAX(cb, 1), pszTag); 55 55 if (psz) 56 56 { … … 60 60 return VERR_NO_STR_MEMORY; 61 61 } 62 RT_EXPORT_SYMBOL(RTStrAlloc );63 64 65 RTDECL(int) RTStrRealloc (char **ppsz, size_t cbNew)62 RT_EXPORT_SYMBOL(RTStrAllocTag); 63 64 65 RTDECL(int) RTStrReallocTag(char **ppsz, size_t cbNew, const char *pszTag) 66 66 { 67 67 char *pszOld = *ppsz; … … 73 73 else if (pszOld) 74 74 { 75 char *pszNew = (char *)RTMemRealloc (pszOld, cbNew);75 char *pszNew = (char *)RTMemReallocTag(pszOld, cbNew, pszTag); 76 76 if (!pszNew) 77 77 return VERR_NO_STR_MEMORY; … … 81 81 else 82 82 { 83 char *pszNew = (char *)RTMemAlloc (cbNew);83 char *pszNew = (char *)RTMemAllocTag(cbNew, pszTag); 84 84 if (!pszNew) 85 85 return VERR_NO_STR_MEMORY; … … 90 90 return VINF_SUCCESS; 91 91 } 92 RT_EXPORT_SYMBOL(RTStrReallocTag); 92 93 93 94 RTDECL(void) RTStrFree(char *pszString) … … 99 100 100 101 101 RTDECL(char *) RTStrDup (const char *pszString)102 RTDECL(char *) RTStrDupTag(const char *pszString, const char *pszTag) 102 103 { 103 104 AssertPtr(pszString); 104 105 size_t cch = strlen(pszString) + 1; 105 char *psz = (char *)RTMemAlloc (cch);106 char *psz = (char *)RTMemAllocTag(cch, pszTag); 106 107 if (psz) 107 108 memcpy(psz, pszString, cch); 108 109 return psz; 109 110 } 110 RT_EXPORT_SYMBOL(RTStrDup );111 112 113 RTDECL(int) RTStrDupEx (char **ppszString, const char *pszString)111 RT_EXPORT_SYMBOL(RTStrDupTag); 112 113 114 RTDECL(int) RTStrDupExTag(char **ppszString, const char *pszString, const char *pszTag) 114 115 { 115 116 AssertPtr(ppszString); … … 117 118 118 119 size_t cch = strlen(pszString) + 1; 119 char *psz = (char *)RTMemAlloc (cch);120 char *psz = (char *)RTMemAllocTag(cch, pszTag); 120 121 if (psz) 121 122 { … … 126 127 return VERR_NO_MEMORY; 127 128 } 128 RT_EXPORT_SYMBOL(RTStrDupEx );129 130 131 RTDECL(char *) RTStrDupN (const char *pszString, size_t cchMax)129 RT_EXPORT_SYMBOL(RTStrDupExTag); 130 131 132 RTDECL(char *) RTStrDupNTag(const char *pszString, size_t cchMax, const char *pszTag) 132 133 { 133 134 AssertPtr(pszString); 134 135 char const *pszEnd = RTStrEnd(pszString, cchMax); 135 136 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); 137 138 if (pszDst) 138 139 { … … 142 143 return pszDst; 143 144 } 144 RT_EXPORT_SYMBOL(RTStrDupN );145 146 147 RTDECL(int) RTStrAAppend (char **ppsz, const char *pszAppend)145 RT_EXPORT_SYMBOL(RTStrDupNTag); 146 147 148 RTDECL(int) RTStrAAppendTag(char **ppsz, const char *pszAppend, const char *pszTag) 148 149 { 149 150 if (!pszAppend) 150 151 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 156 RTDECL(int) RTStrAAppendNTag(char **ppsz, const char *pszAppend, size_t cchAppend, const char *pszTag) 156 157 { 157 158 if (!cchAppend) … … 163 164 164 165 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); 166 167 if (!pszNew) 167 168 return VERR_NO_STR_MEMORY; … … 175 176 176 177 177 RTDECL(int) RTStrAAppendExNV (char **ppsz, size_t cPairs, va_list va)178 RTDECL(int) RTStrAAppendExNVTag(char **ppsz, size_t cPairs, va_list va, const char *pszTag) 178 179 { 179 180 AssertPtr(ppsz); … … 212 213 * Try reallocate the string. 213 214 */ 214 char *pszNew = (char *)RTMemRealloc (*ppsz, cchNewTotal);215 char *pszNew = (char *)RTMemReallocTag(*ppsz, cchNewTotal, pszTag); 215 216 if (!pszNew) 216 217 return VERR_NO_STR_MEMORY; … … 232 233 return VINF_SUCCESS; 233 234 } 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) 235 RT_EXPORT_SYMBOL(RTStrAAppendExNVTag); 236 237 238 RTDECL(int) RTStrATruncateTag(char **ppsz, size_t cchNew, const char *pszTag) 249 239 { 250 240 char *pszOld = *ppsz; … … 254 244 { 255 245 *pszOld = '\0'; 256 char *pszNew = (char *)RTMemRealloc (pszOld, 1);246 char *pszNew = (char *)RTMemReallocTag(pszOld, 1, pszTag); 257 247 if (pszNew) 258 248 *ppsz = pszNew; … … 268 258 if (!pszZero) 269 259 { 270 char *pszNew = (char *)RTMemRealloc (pszOld, cchNew + 1);260 char *pszNew = (char *)RTMemReallocTag(pszOld, cchNew + 1, pszTag); 271 261 if (pszNew) 272 262 *ppsz = pszNew; … … 275 265 return VINF_SUCCESS; 276 266 } 277 RT_EXPORT_SYMBOL(RTStrATruncate );278 267 RT_EXPORT_SYMBOL(RTStrATruncateTag); 268 -
trunk/src/VBox/Runtime/common/string/utf-16.cpp
r30749 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 48 48 49 49 50 RTDECL(PRTUTF16) RTUtf16Dup (PCRTUTF16 pwszString)50 RTDECL(PRTUTF16) RTUtf16DupTag(PCRTUTF16 pwszString, const char *pszTag) 51 51 { 52 52 Assert(pwszString); 53 53 size_t cb = (RTUtf16Len(pwszString) + 1) * sizeof(RTUTF16); 54 PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc (cb);54 PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag(cb, pszTag); 55 55 if (pwsz) 56 56 memcpy(pwsz, pwszString, cb); 57 57 return pwsz; 58 58 } 59 RT_EXPORT_SYMBOL(RTUtf16Dup );60 61 62 RTDECL(int) RTUtf16DupEx (PRTUTF16 *ppwszString, PCRTUTF16 pwszString, size_t cwcExtra)59 RT_EXPORT_SYMBOL(RTUtf16DupTag); 60 61 62 RTDECL(int) RTUtf16DupExTag(PRTUTF16 *ppwszString, PCRTUTF16 pwszString, size_t cwcExtra, const char *pszTag) 63 63 { 64 64 Assert(pwszString); 65 65 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); 67 67 if (pwsz) 68 68 { … … 73 73 return VERR_NO_MEMORY; 74 74 } 75 RT_EXPORT_SYMBOL(RTUtf16DupEx );75 RT_EXPORT_SYMBOL(RTUtf16DupExTag); 76 76 77 77 … … 425 425 426 426 427 RTDECL(int) RTUtf16ToUtf8 (PCRTUTF16 pwszString, char **ppszString)427 RTDECL(int) RTUtf16ToUtf8Tag(PCRTUTF16 pwszString, char **ppszString, const char *pszTag) 428 428 { 429 429 /* … … 444 444 * Allocate buffer and recode it. 445 445 */ 446 char *pszResult = (char *)RTMemAlloc (cch + 1);446 char *pszResult = (char *)RTMemAllocTag(cch + 1, pszTag); 447 447 if (pszResult) 448 448 { … … 461 461 return rc; 462 462 } 463 RT_EXPORT_SYMBOL(RTUtf16ToUtf8 );464 465 466 RTDECL(int) RTUtf16ToUtf8Ex (PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch)463 RT_EXPORT_SYMBOL(RTUtf16ToUtf8Tag); 464 465 466 RTDECL(int) RTUtf16ToUtf8ExTag(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch, const char *pszTag) 467 467 { 468 468 /* … … 500 500 fShouldFree = true; 501 501 cch = RT_MAX(cch, cchResult + 1); 502 pszResult = (char *)RTStrAlloc (cch);502 pszResult = (char *)RTStrAllocTag(cch, pszTag); 503 503 } 504 504 if (pszResult) … … 519 519 return rc; 520 520 } 521 RT_EXPORT_SYMBOL(RTUtf16ToUtf8Ex );521 RT_EXPORT_SYMBOL(RTUtf16ToUtf8ExTag); 522 522 523 523 … … 785 785 786 786 787 RTDECL(int) RTUtf16ToLatin1 (PCRTUTF16 pwszString, char **ppszString)787 RTDECL(int) RTUtf16ToLatin1Tag(PCRTUTF16 pwszString, char **ppszString, const char *pszTag) 788 788 { 789 789 /* … … 804 804 * Allocate buffer and recode it. 805 805 */ 806 char *pszResult = (char *)RTMemAlloc (cch + 1);806 char *pszResult = (char *)RTMemAllocTag(cch + 1, pszTag); 807 807 if (pszResult) 808 808 { … … 821 821 return rc; 822 822 } 823 RT_EXPORT_SYMBOL(RTUtf16ToLatin1 );824 825 826 RTDECL(int) RTUtf16ToLatin1Ex (PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch)823 RT_EXPORT_SYMBOL(RTUtf16ToLatin1Tag); 824 825 826 RTDECL(int) RTUtf16ToLatin1ExTag(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch, const char *pszTag) 827 827 { 828 828 /* … … 860 860 fShouldFree = true; 861 861 cch = RT_MAX(cch, cchResult + 1); 862 pszResult = (char *)RTMemAlloc (cch);862 pszResult = (char *)RTMemAllocTag(cch, pszTag); 863 863 } 864 864 if (pszResult) … … 879 879 return rc; 880 880 } 881 RT_EXPORT_SYMBOL(RTUtf16ToLatin1Ex );881 RT_EXPORT_SYMBOL(RTUtf16ToLatin1ExTag); 882 882 883 883 … … 964 964 965 965 966 RTDECL(int) RTLatin1ToUtf16 (const char *pszString, PRTUTF16 *ppwszString)966 RTDECL(int) RTLatin1ToUtf16Tag(const char *pszString, PRTUTF16 *ppwszString, const char *pszTag) 967 967 { 968 968 /* … … 983 983 * Allocate buffer. 984 984 */ 985 PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc ((cwc + 1) * sizeof(RTUTF16));985 PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag((cwc + 1) * sizeof(RTUTF16), pszTag); 986 986 if (pwsz) 987 987 { … … 1002 1002 return rc; 1003 1003 } 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) 1004 RT_EXPORT_SYMBOL(RTLatin1ToUtf16Tag); 1005 1006 1007 RTDECL(int) RTLatin1ToUtf16ExTag(const char *pszString, size_t cchString, 1008 PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag) 1008 1009 { 1009 1010 /* … … 1041 1042 fShouldFree = true; 1042 1043 cwc = RT_MAX(cwcResult + 1, cwc); 1043 pwszResult = (PRTUTF16)RTMemAlloc (cwc * sizeof(RTUTF16));1044 pwszResult = (PRTUTF16)RTMemAllocTag(cwc * sizeof(RTUTF16), pszTag); 1044 1045 } 1045 1046 if (pwszResult) … … 1062 1063 return rc; 1063 1064 } 1064 RT_EXPORT_SYMBOL(RTLatin1ToUtf16Ex );1065 RT_EXPORT_SYMBOL(RTLatin1ToUtf16ExTag); 1065 1066 1066 1067 -
trunk/src/VBox/Runtime/common/string/utf-8.cpp
r30859 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 09Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 672 672 673 673 674 RTDECL(int) RTStrToUtf16 (const char *pszString, PRTUTF16 *ppwszString)674 RTDECL(int) RTStrToUtf16Tag(const char *pszString, PRTUTF16 *ppwszString, const char *pszTag) 675 675 { 676 676 /* … … 691 691 * Allocate buffer. 692 692 */ 693 PRTUTF16 pwsz = (PRTUTF16)RTMemAlloc ((cwc + 1) * sizeof(RTUTF16));693 PRTUTF16 pwsz = (PRTUTF16)RTMemAllocTag((cwc + 1) * sizeof(RTUTF16), pszTag); 694 694 if (pwsz) 695 695 { … … 710 710 return rc; 711 711 } 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) 712 RT_EXPORT_SYMBOL(RTStrToUtf16Tag); 713 714 715 RTDECL(int) RTStrToUtf16ExTag(const char *pszString, size_t cchString, 716 PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc, const char *pszTag) 716 717 { 717 718 /* … … 749 750 fShouldFree = true; 750 751 cwc = RT_MAX(cwcResult + 1, cwc); 751 pwszResult = (PRTUTF16)RTMemAlloc (cwc * sizeof(RTUTF16));752 pwszResult = (PRTUTF16)RTMemAllocTag(cwc * sizeof(RTUTF16), pszTag); 752 753 } 753 754 if (pwszResult) … … 770 771 return rc; 771 772 } 772 RT_EXPORT_SYMBOL(RTStrToUtf16Ex );773 RT_EXPORT_SYMBOL(RTStrToUtf16ExTag); 773 774 774 775 -
trunk/src/VBox/Runtime/r0drv/alloc-r0drv.cpp
r29250 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 81 81 82 82 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 106 RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 107 { 108 return RTMemAllocTag(cb, pszTag); 109 } 110 RT_EXPORT_SYMBOL(RTMemTmpAllocTag); 111 112 113 RTDECL(void *) RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 114 { 115 return RTMemAllocZTag(cb, pszTag); 116 } 117 RT_EXPORT_SYMBOL(RTMemTmpAllocZTag); 118 119 124 120 RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW 125 121 { … … 129 125 130 126 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 130 RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 139 131 { 140 132 PRTMEMHDR pHdr; … … 152 144 return NULL; 153 145 } 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 146 RT_EXPORT_SYMBOL(RTMemAllocTag); 147 148 149 RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 169 150 { 170 151 PRTMEMHDR pHdr; … … 184 165 return NULL; 185 166 } 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) 167 RT_EXPORT_SYMBOL(RTMemAllocZTag); 168 169 170 RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag) 197 171 { 198 172 size_t cbAligned; … … 201 175 else 202 176 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 } 179 RT_EXPORT_SYMBOL(RTMemAllocVarTag); 180 181 182 RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag) 216 183 { 217 184 size_t cbAligned; … … 220 187 else 221 188 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 } 191 RT_EXPORT_SYMBOL(RTMemAllocZVarTag); 192 193 194 RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW 236 195 { 237 196 if (!cbNew) 238 197 RTMemFree(pvOld); 239 198 else if (!pvOld) 240 return RTMemAlloc (cbNew);199 return RTMemAllocTag(cbNew, pszTag); 241 200 else 242 201 { … … 275 234 return NULL; 276 235 } 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 */ 236 RT_EXPORT_SYMBOL(RTMemReallocTag); 237 238 285 239 RTDECL(void) RTMemFree(void *pv) RT_NO_THROW 286 240 { … … 311 265 312 266 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 271 RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 321 272 { 322 273 PRTMEMHDR pHdr; … … 338 289 return NULL; 339 290 } 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 */ 291 RT_EXPORT_SYMBOL(RTMemExecAllocTag); 292 293 348 294 RTDECL(void) RTMemExecFree(void *pv) RT_NO_THROW 349 295 { -
trunk/src/VBox/Runtime/r0drv/memobj-r0drv.cpp
r29027 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 405 405 406 406 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) 407 RTR0DECL(int) RTR0MemObjAllocPageTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag) 418 408 { 419 409 /* sanity checks. */ … … 428 418 return rtR0MemObjNativeAllocPage(pMemObj, cbAligned, fExecutable); 429 419 } 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) 420 RT_EXPORT_SYMBOL(RTR0MemObjAllocPageTag); 421 422 423 RTR0DECL(int) RTR0MemObjAllocLowTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag) 444 424 { 445 425 /* sanity checks. */ … … 454 434 return rtR0MemObjNativeAllocLow(pMemObj, cbAligned, fExecutable); 455 435 } 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) 436 RT_EXPORT_SYMBOL(RTR0MemObjAllocLowTag); 437 438 439 RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag) 470 440 { 471 441 /* sanity checks. */ … … 480 450 return rtR0MemObjNativeAllocCont(pMemObj, cbAligned, fExecutable); 481 451 } 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) 452 RT_EXPORT_SYMBOL(RTR0MemObjAllocContTag); 453 454 455 RTR0DECL(int) RTR0MemObjLockUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, 456 uint32_t fAccess, RTR0PROCESS R0Process, const char *pszTag) 508 457 { 509 458 /* sanity checks. */ … … 523 472 return rtR0MemObjNativeLockUser(pMemObj, R3PtrAligned, cbAligned, fAccess, R0Process); 524 473 } 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) 474 RT_EXPORT_SYMBOL(RTR0MemObjLockUserTag); 475 476 477 RTR0DECL(int) RTR0MemObjLockKernelTag(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess, const char *pszTag) 541 478 { 542 479 /* sanity checks. */ … … 555 492 return rtR0MemObjNativeLockKernel(pMemObj, pvAligned, cbAligned, fAccess); 556 493 } 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) 494 RT_EXPORT_SYMBOL(RTR0MemObjLockKernelTag); 495 496 497 RTR0DECL(int) RTR0MemObjAllocPhysTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag) 570 498 { 571 499 /* sanity checks. */ … … 581 509 return rtR0MemObjNativeAllocPhys(pMemObj, cbAligned, PhysHighest, PAGE_SIZE /* page aligned */); 582 510 } 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) 511 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysTag); 512 513 514 RTR0DECL(int) RTR0MemObjAllocPhysExTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment, const char *pszTag) 598 515 { 599 516 /* sanity checks. */ … … 622 539 return rtR0MemObjNativeAllocPhys(pMemObj, cbAligned, PhysHighest, uAlignment); 623 540 } 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) 541 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysExTag); 542 543 544 RTR0DECL(int) RTR0MemObjAllocPhysNCTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag) 637 545 { 638 546 /* sanity checks. */ … … 648 556 return rtR0MemObjNativeAllocPhysNC(pMemObj, cbAligned, PhysHighest); 649 557 } 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) 558 RT_EXPORT_SYMBOL(RTR0MemObjAllocPhysNCTag); 559 560 561 RTR0DECL(int) RTR0MemObjEnterPhysTag(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy, const char *pszTag) 666 562 { 667 563 /* sanity checks. */ … … 681 577 return rtR0MemObjNativeEnterPhys(pMemObj, PhysAligned, cbAligned, uCachePolicy); 682 578 } 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) 579 RT_EXPORT_SYMBOL(RTR0MemObjEnterPhysTag); 580 581 582 RTR0DECL(int) RTR0MemObjReserveKernelTag(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment, const char *pszTag) 697 583 { 698 584 /* sanity checks. */ … … 712 598 return rtR0MemObjNativeReserveKernel(pMemObj, pvFixed, cbAligned, uAlignment); 713 599 } 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) 600 RT_EXPORT_SYMBOL(RTR0MemObjReserveKernelTag); 601 602 603 RTR0DECL(int) RTR0MemObjReserveUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, 604 size_t uAlignment, RTR0PROCESS R0Process, const char *pszTag) 729 605 { 730 606 /* sanity checks. */ … … 746 622 return rtR0MemObjNativeReserveUser(pMemObj, R3PtrFixed, cbAligned, uAlignment, R0Process); 747 623 } 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) 624 RT_EXPORT_SYMBOL(RTR0MemObjReserveUserTag); 625 626 627 RTR0DECL(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 } 632 RT_EXPORT_SYMBOL(RTR0MemObjMapKernelTag); 633 634 635 RTR0DECL(int) RTR0MemObjMapKernelExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, 636 unsigned fProt, size_t offSub, size_t cbSub, const char *pszTag) 795 637 { 796 638 PRTR0MEMOBJINTERNAL pMemToMap; … … 846 688 return rc; 847 689 } 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) 690 RT_EXPORT_SYMBOL(RTR0MemObjMapKernelExTag); 691 692 693 RTR0DECL(int) RTR0MemObjMapUserTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, 694 size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process, const char *pszTag) 864 695 { 865 696 /* sanity checks. */ … … 907 738 return rc; 908 739 } 909 RT_EXPORT_SYMBOL(RTR0MemObjMapUser );740 RT_EXPORT_SYMBOL(RTR0MemObjMapUserTag); 910 741 911 742 -
trunk/src/VBox/Runtime/r3/alloc-ef-cpp.cpp
r28800 r31157 58 58 void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc) 59 59 { 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); 61 61 if (!pv) 62 62 throw std::bad_alloc(); … … 67 67 void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw() 68 68 { 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); 70 70 return pv; 71 71 } … … 94 94 void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc) 95 95 { 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); 97 97 if (!pv) 98 98 throw std::bad_alloc(); … … 103 103 void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw() 104 104 { 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); 106 106 return pv; 107 107 } -
trunk/src/VBox/Runtime/r3/alloc-ef.cpp
r28800 r31157 127 127 */ 128 128 DECLINLINE(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) 130 130 { 131 131 PRTMEMBLOCK pBlock = (PRTMEMBLOCK)malloc(sizeof(*pBlock)); … … 135 135 pBlock->cbUnaligned = cbUnaligned; 136 136 pBlock->cbAligned = cbAligned; 137 pBlock->pszTag = pszTag; 137 138 pBlock->pvCaller = pvCaller; 138 139 pBlock->iLine = iLine; … … 273 274 */ 274 275 RTDECL(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) 276 277 { 277 278 /* … … 305 306 * Allocate the trace block. 306 307 */ 307 PRTMEMBLOCK pBlock = rtmemBlockCreate(enmType, cbUnaligned, cbAligned, p vCaller, RT_SRC_POS_ARGS);308 PRTMEMBLOCK pBlock = rtmemBlockCreate(enmType, cbUnaligned, cbAligned, pszTag, pvCaller, RT_SRC_POS_ARGS); 308 309 if (!pBlock) 309 310 { … … 503 504 * Internal realloc. 504 505 */ 505 RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, RT_SRC_POS_DECL) 506 RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, 507 const char *pszTag, void *pvCaller, RT_SRC_POS_DECL) 506 508 { 507 509 /* … … 509 511 */ 510 512 if (!pvOld) 511 return rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, p vCaller, RT_SRC_POS_ARGS);513 return rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, pszTag, pvCaller, RT_SRC_POS_ARGS); 512 514 if (!cbNew) 513 515 { … … 524 526 if (pBlock) 525 527 { 526 void *pvRet = rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, p vCaller, RT_SRC_POS_ARGS);528 void *pvRet = rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, pszTag, pvCaller, RT_SRC_POS_ARGS); 527 529 if (pvRet) 528 530 { … … 547 549 548 550 549 RTDECL(void *) RTMemEfTmpAlloc(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW550 { 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_THROW556 { 557 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS);551 RTDECL(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 557 RTDECL(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); 558 560 } 559 561 … … 566 568 567 569 568 RTDECL(void *) RTMemEfAlloc(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW569 { 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_THROW575 { 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_THROW570 RTDECL(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 576 RTDECL(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 582 RTDECL(void *) RTMemEfAllocVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 581 583 { 582 584 size_t cbAligned; … … 585 587 else 586 588 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_THROW589 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), RT_SRC_POS_ARGS); 590 } 591 592 593 RTDECL(void *) RTMemEfAllocZVar(size_t cbUnaligned, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW 592 594 { 593 595 size_t cbAligned; … … 596 598 else 597 599 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_THROW603 { 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 604 RTDECL(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); 605 607 } 606 608 … … 613 615 614 616 615 RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW616 { 617 void *pvDst = RTMemEfAlloc(cb, RT_SRC_POS_ARGS);617 RTDECL(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); 618 620 if (pvDst) 619 621 memcpy(pvDst, pvSrc, cb); … … 622 624 623 625 624 RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, RT_SRC_POS_DECL) RT_NO_THROW625 { 626 void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, RT_SRC_POS_ARGS);626 RTDECL(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); 627 629 if (pvDst) 628 630 { … … 644 646 645 647 646 RTDECL(void *) RTMemEfTmpAllocNP(size_t cb ) RT_NO_THROW647 { 648 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL);649 } 650 651 652 RTDECL(void *) RTMemEfTmpAllocZNP(size_t cb ) RT_NO_THROW653 { 654 return rtR3MemAlloc("TmpAllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL);648 RTDECL(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 654 RTDECL(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); 655 657 } 656 658 … … 663 665 664 666 665 RTDECL(void *) RTMemEfAllocNP(size_t cb ) RT_NO_THROW666 { 667 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL);668 } 669 670 671 RTDECL(void *) RTMemEfAllocZNP(size_t cb ) RT_NO_THROW672 { 673 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL);674 } 675 676 677 RTDECL(void *) RTMemEfAllocVarNP(size_t cbUnaligned ) RT_NO_THROW667 RTDECL(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 673 RTDECL(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 679 RTDECL(void *) RTMemEfAllocVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW 678 680 { 679 681 size_t cbAligned; … … 682 684 else 683 685 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_THROW686 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL); 687 } 688 689 690 RTDECL(void *) RTMemEfAllocZVarNP(size_t cbUnaligned, const char *pszTag) RT_NO_THROW 689 691 { 690 692 size_t cbAligned; … … 693 695 else 694 696 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_THROW700 { 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 701 RTDECL(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); 702 704 } 703 705 … … 710 712 711 713 712 RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb ) RT_NO_THROW713 { 714 void *pvDst = RTMemEfAlloc(cb, NULL, 0, NULL);714 RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW 715 { 716 void *pvDst = RTMemEfAlloc(cb, pszTag, NULL, 0, NULL); 715 717 if (pvDst) 716 718 memcpy(pvDst, pvSrc, cb); … … 719 721 720 722 721 RTDECL(void *) RTMemEfDupExNP(const void *pvSrc, size_t cbSrc, size_t cbExtra ) RT_NO_THROW722 { 723 void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, NULL, 0, NULL);723 RTDECL(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); 724 726 if (pvDst) 725 727 { -
trunk/src/VBox/Runtime/r3/alloc-ef.h
r28800 r31157 166 166 /** The aligned size of the block. */ 167 167 size_t cbAligned; 168 /** The allocation tag (read-only string). */ 169 const char *pszTag; 168 170 /** The return address of the allocator function. */ 169 171 void *pvCaller; … … 184 186 RT_C_DECLS_BEGIN 185 187 RTDECL(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); 189 RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, 190 const char *pszTag, void *pvCaller, RT_SRC_POS_DECL); 188 191 RTDECL(void) rtR3MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, RT_SRC_POS_DECL); 189 192 RT_C_DECLS_END -
trunk/src/VBox/Runtime/r3/alloc.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 48 48 49 49 #undef RTMemTmpAlloc 50 #undef RTMemTmpAllocTag 50 51 #undef RTMemTmpAllocZ 52 #undef RTMemTmpAllocZTag 51 53 #undef RTMemTmpFree 52 54 #undef RTMemAlloc 55 #undef RTMemAllocTag 53 56 #undef RTMemAllocZ 57 #undef RTMemAllocZTag 54 58 #undef RTMemAllocVar 59 #undef RTMemAllocVarTag 55 60 #undef RTMemAllocZVar 61 #undef RTMemAllocZVarTag 56 62 #undef RTMemRealloc 63 #undef RTMemReallocTag 57 64 #undef RTMemFree 58 65 #undef RTMemDup 66 #undef RTMemDupTag 59 67 #undef RTMemDupEx 68 #undef RTMemDupExTag 60 69 61 70 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 71 RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 75 72 { 76 return RTMemAlloc (cb);73 return RTMemAllocTag(cb, pszTag); 77 74 } 78 75 79 76 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 77 RTDECL(void *) RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 90 78 { 91 return RTMemAllocZ (cb);79 return RTMemAllocZTag(cb, pszTag); 92 80 } 93 81 94 82 95 /** 96 * Free temporary memory. 97 * 98 * @param pv Pointer to memory block. 99 */ 100 RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW 83 RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW 101 84 { 102 85 RTMemFree(pv); … … 104 87 105 88 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 89 RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 114 90 { 115 91 #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); 117 93 118 94 #else /* !RTALLOC_USE_EFENCE */ … … 130 106 131 107 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 108 RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 144 109 { 145 110 #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); 147 112 148 113 #else /* !RTALLOC_USE_EFENCE */ … … 161 126 162 127 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) 128 RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW 171 129 { 172 130 size_t cbAligned; … … 176 134 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 177 135 #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); 179 137 #else 180 void *pv = RTMemAlloc (cbAligned);138 void *pv = RTMemAllocTag(cbAligned, pszTag); 181 139 #endif 182 140 return pv; … … 184 142 185 143 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) 144 RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW 194 145 { 195 146 size_t cbAligned; … … 199 150 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 200 151 #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); 202 153 #else 203 void *pv = RTMemAllocZ (cbAligned);154 void *pv = RTMemAllocZTag(cbAligned, pszTag); 204 155 #endif 205 156 return pv; … … 207 158 208 159 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 160 RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW 218 161 { 219 162 #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); 221 164 222 165 #else /* !RTALLOC_USE_EFENCE */ … … 233 176 234 177 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 178 RTDECL(void) RTMemFree(void *pv) RT_NO_THROW 241 179 { 242 180 if (pv) -
trunk/src/VBox/Runtime/r3/darwin/alloc-darwin.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 40 40 41 41 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 42 RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 50 43 { 51 44 /* … … 74 67 75 68 76 /**77 * Free executable/read/write memory allocated by RTMemExecAlloc().78 *79 * @param pv Pointer to memory block.80 */81 69 RTDECL(void) RTMemExecFree(void *pv) RT_NO_THROW 82 70 { … … 86 74 87 75 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 76 RTDECL(void *) RTMemPageAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 96 77 { 97 78 return valloc(RT_ALIGN_Z(cb, PAGE_SIZE)); … … 99 80 100 81 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 82 RTDECL(void *) RTMemPageAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 109 83 { 110 84 cb = RT_ALIGN_Z(cb, PAGE_SIZE); … … 116 90 117 91 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 */124 92 RTDECL(void) RTMemPageFree(void *pv, size_t cb) RT_NO_THROW 125 93 { … … 129 97 130 98 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 */139 99 RTDECL(int) RTMemProtect(void *pv, size_t cb, unsigned fProtect) RT_NO_THROW 140 100 { -
trunk/src/VBox/Runtime/r3/posix/utf8-posix.cpp
r30294 r31157 413 413 414 414 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) 415 RTR3DECL(int) RTStrUtf8ToCurrentCPTag(char **ppszString, const char *pszString, const char *pszTag) 424 416 { 425 417 Assert(ppszString); … … 434 426 { 435 427 /* zero length string passed. */ 436 *ppszString = (char *)RTMemTmpAllocZ (sizeof(char));428 *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag); 437 429 if (*ppszString) 438 430 return VINF_SUCCESS; … … 443 435 444 436 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) 437 RTR3DECL(int) RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag) 454 438 { 455 439 Assert(ppszString); … … 464 448 { 465 449 /* zero length string passed. */ 466 *ppszString = (char *)RTMemTmpAllocZ (sizeof(char));450 *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag); 467 451 if (*ppszString) 468 452 return VINF_SUCCESS; -
trunk/src/VBox/Runtime/r3/win/utf8-win.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 38 38 39 39 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) 40 RTR3DECL(int) RTStrUtf8ToCurrentCPTag(char **ppszString, const char *pszString, const char *pszTag) 49 41 { 50 42 Assert(ppszString); … … 56 48 if (!*pszString) 57 49 { 58 *ppszString = (char *)RTMemTmpAllocZ (sizeof(char));50 *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag); 59 51 if (*ppszString) 60 52 return VINF_SUCCESS; … … 81 73 * Alloc space for result buffer. 82 74 */ 83 LPSTR lpString = (LPSTR)RTMemTmpAlloc (cbResult);75 LPSTR lpString = (LPSTR)RTMemTmpAllocTag(cbResult, pszTag); 84 76 if (lpString) 85 77 { … … 115 107 } 116 108 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 110 RTR3DECL(int) RTStrCurrentCPToUtf8Tag(char **ppszString, const char *pszString, const char *pszTag) 126 111 { 127 112 Assert(ppszString); … … 135 120 { 136 121 /* zero length string passed. */ 137 *ppszString = (char *)RTMemTmpAllocZ (sizeof(char));122 *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag); 138 123 if (*ppszString) 139 124 return VINF_SUCCESS; -
trunk/src/VBox/Runtime/testcase/tstMemAutoPtr.cpp
r28800 r31157 5 5 6 6 /* 7 * Copyright (C) 2008 Oracle Corporation7 * Copyright (C) 2008-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 114 114 115 115 116 void *tstMemAutoPtrAllocatorNoZero(void *pvOld, size_t cbNew )117 { 118 void *pvNew = RTMemRealloc (pvOld, cbNew);116 void *tstMemAutoPtrAllocatorNoZero(void *pvOld, size_t cbNew, const char *pszTag) 117 { 118 void *pvNew = RTMemReallocTag(pvOld, cbNew, pszTag); 119 119 if (pvNew) 120 120 memset(pvNew, 0xfe, cbNew); -
trunk/src/VBox/Runtime/testcase/tstRTMemEf.cpp
r28800 r31157 47 47 * the word after the allocated block and the word before. One of them 48 48 * 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); 50 50 RTPrintf("tstRTMemAllocEfAccess: allocated int32_t at %#p\n", p); 51 51 RTPrintf("tstRTMemAllocEfAccess: triggering buffer overrun...\n");
Note:
See TracChangeset
for help on using the changeset viewer.