Changeset 28298 in vbox for trunk/src/VBox
- Timestamp:
- Apr 14, 2010 12:20:39 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/alloc/alloc.cpp
r28271 r28298 39 39 #include <iprt/string.h> 40 40 41 #ifdef RTMEM_WRAP_TO_EF_APIS 42 # undef RTMemAllocVar 43 # undef RTMemAllocZVar 44 # undef RTMemDup 45 # undef RTMemDupEx 46 #endif 41 #undef RTMemDup 42 #undef RTMemDupEx 47 43 48 49 50 /**51 * Wrapper around RTMemAlloc for automatically aligning variable sized52 * allocations so that the various electric fence heaps works correctly.53 *54 * @returns See RTMemAlloc.55 * @param cbUnaligned The unaligned size.56 */57 RTDECL(void *) RTMemAllocVar(size_t cbUnaligned)58 {59 size_t cbAligned;60 if (cbUnaligned >= 16)61 cbAligned = RT_ALIGN_Z(cbUnaligned, 16);62 else63 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));64 return RTMemAlloc(cbAligned);65 }66 67 68 /**69 * Wrapper around RTMemAllocZ for automatically aligning variable sized70 * allocations so that the various electric fence heaps works correctly.71 *72 * @returns See RTMemAllocZ.73 * @param cbUnaligned The unaligned size.74 */75 RTDECL(void *) RTMemAllocZVar(size_t cbUnaligned)76 {77 size_t cbAligned;78 if (cbUnaligned >= 16)79 cbAligned = RT_ALIGN_Z(cbUnaligned, 16);80 else81 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));82 return RTMemAllocZ(cbAligned);83 }84 44 85 45 -
trunk/src/VBox/Runtime/r0drv/alloc-r0drv.cpp
r22174 r28298 43 43 #include "r0drv/alloc-r0drv.h" 44 44 45 #undef RTMemTmpAlloc 46 #undef RTMemTmpAllocZ 47 #undef RTMemTmpFree 48 #undef RTMemAlloc 49 #undef RTMemAllocZ 50 #undef RTMemAllocVar 51 #undef RTMemAllocZVar 52 #undef RTMemRealloc 53 #undef RTMemFree 54 #undef RTMemDup 55 #undef RTMemDupEx 56 45 57 46 58 /******************************************************************************* … … 131 143 RT_ASSERT_INTS_ON(); 132 144 133 pHdr = rt MemAlloc(cb + RTR0MEM_FENCE_EXTRA, 0);145 pHdr = rtR0MemAlloc(cb + RTR0MEM_FENCE_EXTRA, 0); 134 146 if (pHdr) 135 147 { … … 161 173 RT_ASSERT_INTS_ON(); 162 174 163 pHdr = rt MemAlloc(cb + RTR0MEM_FENCE_EXTRA, RTMEMHDR_FLAG_ZEROED);175 pHdr = rtR0MemAlloc(cb + RTR0MEM_FENCE_EXTRA, RTMEMHDR_FLAG_ZEROED); 164 176 if (pHdr) 165 177 { … … 178 190 179 191 /** 192 * Wrapper around RTMemAlloc for automatically aligning variable sized 193 * allocations so that the various electric fence heaps works correctly. 194 * 195 * @returns See RTMemAlloc. 196 * @param cbUnaligned The unaligned size. 197 */ 198 RTDECL(void *) RTMemAllocVar(size_t cbUnaligned) 199 { 200 size_t cbAligned; 201 if (cbUnaligned >= 16) 202 cbAligned = RT_ALIGN_Z(cbUnaligned, 16); 203 else 204 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 205 return RTMemAlloc(cbAligned); 206 } 207 RT_EXPORT_SYMBOL(RTMemAllocVar); 208 209 210 /** 211 * Wrapper around RTMemAllocZ for automatically aligning variable sized 212 * allocations so that the various electric fence heaps works correctly. 213 * 214 * @returns See RTMemAllocZ. 215 * @param cbUnaligned The unaligned size. 216 */ 217 RTDECL(void *) RTMemAllocZVar(size_t cbUnaligned) 218 { 219 size_t cbAligned; 220 if (cbUnaligned >= 16) 221 cbAligned = RT_ALIGN_Z(cbUnaligned, 16); 222 else 223 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 224 return RTMemAllocZ(cbAligned); 225 } 226 RT_EXPORT_SYMBOL(RTMemAllocZVar); 227 228 229 /** 180 230 * Reallocates memory. 181 231 * … … 201 251 if (pHdrOld->cb >= cbNew && pHdrOld->cb - cbNew <= 128) 202 252 return pvOld; 203 pHdrNew = rt MemAlloc(cbNew + RTR0MEM_FENCE_EXTRA, 0);253 pHdrNew = rtR0MemAlloc(cbNew + RTR0MEM_FENCE_EXTRA, 0); 204 254 if (pHdrNew) 205 255 { … … 217 267 RTR0MEM_FENCE_EXTRA, &g_abFence[0])); 218 268 #endif 219 rt MemFree(pHdrOld);269 rtR0MemFree(pHdrOld); 220 270 return pHdrNew + 1; 221 271 } … … 255 305 RTR0MEM_FENCE_EXTRA, &g_abFence[0])); 256 306 #endif 257 rt MemFree(pHdr);307 rtR0MemFree(pHdr); 258 308 } 259 309 else … … 279 329 #endif 280 330 281 pHdr = rt MemAlloc(cb + RTR0MEM_FENCE_EXTRA, RTMEMHDR_FLAG_EXEC);331 pHdr = rtR0MemAlloc(cb + RTR0MEM_FENCE_EXTRA, RTMEMHDR_FLAG_EXEC); 282 332 if (pHdr) 283 333 { … … 317 367 RTR0MEM_FENCE_EXTRA, &g_abFence[0])); 318 368 #endif 319 rt MemFree(pHdr);369 rtR0MemFree(pHdr); 320 370 } 321 371 else -
trunk/src/VBox/Runtime/r0drv/alloc-r0drv.h
r20374 r28298 65 65 66 66 67 PRTMEMHDR rt MemAlloc(size_t cb, uint32_t fFlags);68 void rt MemFree(PRTMEMHDR pHdr);67 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags); 68 void rtR0MemFree(PRTMEMHDR pHdr); 69 69 70 70 RT_C_DECLS_END -
trunk/src/VBox/Runtime/r0drv/darwin/alloc-r0drv-darwin.cpp
r22052 r28298 45 45 * OS specific allocation function. 46 46 */ 47 PRTMEMHDR rt MemAlloc(size_t cb, uint32_t fFlags)47 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 48 48 { 49 49 PRTMEMHDR pHdr = (PRTMEMHDR)IOMalloc(cb + sizeof(*pHdr)); … … 64 64 * OS specific free function. 65 65 */ 66 void rt MemFree(PRTMEMHDR pHdr)66 void rtR0MemFree(PRTMEMHDR pHdr) 67 67 { 68 68 pHdr->u32Magic += 1; -
trunk/src/VBox/Runtime/r0drv/freebsd/alloc-r0drv-freebsd.c
r19761 r28298 50 50 51 51 52 PRTMEMHDR rt MemAlloc(size_t cb, uint32_t fFlags)52 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 53 53 { 54 54 size_t cbAllocated = cb; … … 141 141 142 142 143 void rt MemFree(PRTMEMHDR pHdr)143 void rtR0MemFree(PRTMEMHDR pHdr) 144 144 { 145 145 pHdr->u32Magic += 1; -
trunk/src/VBox/Runtime/r0drv/linux/alloc-r0drv-linux.c
r25642 r28298 115 115 * OS specific allocation function. 116 116 */ 117 PRTMEMHDR rt MemAlloc(size_t cb, uint32_t fFlags)117 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 118 118 { 119 119 /* … … 173 173 * OS specific free function. 174 174 */ 175 void rt MemFree(PRTMEMHDR pHdr)175 void rtR0MemFree(PRTMEMHDR pHdr) 176 176 { 177 177 pHdr->u32Magic += 1; -
trunk/src/VBox/Runtime/r0drv/nt/alloc-r0drv-nt.cpp
r14069 r28298 43 43 * OS specific allocation function. 44 44 */ 45 PRTMEMHDR rt MemAlloc(size_t cb, uint32_t fFlags)45 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 46 46 { 47 47 PRTMEMHDR pHdr = (PRTMEMHDR)ExAllocatePoolWithTag(NonPagedPool, cb + sizeof(*pHdr), IPRT_NT_POOL_TAG); … … 60 60 * OS specific free function. 61 61 */ 62 void rt MemFree(PRTMEMHDR pHdr)62 void rtR0MemFree(PRTMEMHDR pHdr) 63 63 { 64 64 pHdr->u32Magic += 1; -
trunk/src/VBox/Runtime/r0drv/os2/alloc-r0drv-os2.cpp
r8245 r28298 41 41 42 42 43 PRTMEMHDR rt MemAlloc(size_t cb, uint32_t fFlags)43 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 44 44 { 45 45 void *pv = NULL; … … 58 58 59 59 60 void rt MemFree(PRTMEMHDR pHdr)60 void rtR0MemFree(PRTMEMHDR pHdr) 61 61 { 62 62 pHdr->u32Magic += 1; -
trunk/src/VBox/Runtime/r0drv/solaris/vbi/alloc-r0drv-solaris.c
r27050 r28298 48 48 * OS specific allocation function. 49 49 */ 50 PRTMEMHDR rt MemAlloc(size_t cb, uint32_t fFlags)50 PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags) 51 51 { 52 52 size_t cbAllocated = cb; … … 80 80 * OS specific free function. 81 81 */ 82 void rt MemFree(PRTMEMHDR pHdr)82 void rtR0MemFree(PRTMEMHDR pHdr) 83 83 { 84 84 pHdr->u32Magic += 1; -
trunk/src/VBox/Runtime/r3/alloc-ef-cpp.cpp
r28271 r28298 34 34 #include "alloc-ef.h" 35 35 36 37 36 #if defined(RTALLOC_EFENCE_CPP) || defined(RTMEM_WRAP_TO_EF_APIS) /* rest of the file */ 38 37 38 #include <iprt/asm.h> 39 39 #include <new> 40 40 … … 62 62 void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc) 63 63 { 64 void *pv = rt MemAlloc("new", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);64 void *pv = rtR3MemAlloc("new", RTMEMTYPE_NEW, cb, cb, ASMReturnAddress(), NULL, 0, NULL); 65 65 if (!pv) 66 66 throw std::bad_alloc(); … … 71 71 void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw() 72 72 { 73 void *pv = rt MemAlloc("new nothrow", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);73 void *pv = rtR3MemAlloc("new nothrow", RTMEMTYPE_NEW, cb, cb, ASMReturnAddress(), NULL, 0, NULL); 74 74 return pv; 75 75 } … … 78 78 void RT_EF_CDECL operator delete(void *pv) throw() 79 79 { 80 rt MemFree("delete", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);80 rtR3MemFree("delete", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL); 81 81 } 82 82 … … 84 84 void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) throw() 85 85 { 86 rt MemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);86 rtR3MemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL); 87 87 } 88 88 … … 98 98 void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc) 99 99 { 100 void *pv = rt MemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);100 void *pv = rtR3MemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, cb, ASMReturnAddress(), NULL, 0, NULL); 101 101 if (!pv) 102 102 throw std::bad_alloc(); … … 107 107 void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw() 108 108 { 109 void *pv = rt MemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);109 void *pv = rtR3MemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, cb, ASMReturnAddress(), NULL, 0, NULL); 110 110 return pv; 111 111 } … … 114 114 void RT_EF_CDECL operator delete[](void * pv) throw() 115 115 { 116 rt MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);116 rtR3MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL); 117 117 } 118 118 … … 120 120 void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) throw() 121 121 { 122 rt MemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);122 rtR3MemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL); 123 123 } 124 124 -
trunk/src/VBox/Runtime/r3/alloc-ef.cpp
r28273 r28298 92 92 * Log an event. 93 93 */ 94 static inline voidrtmemLog(const char *pszOp, const char *pszFormat, ...)94 DECLINLINE(void) rtmemLog(const char *pszOp, const char *pszFormat, ...) 95 95 { 96 96 #if 0 … … 109 109 * Aquires the lock. 110 110 */ 111 static inline voidrtmemBlockLock(void)111 DECLINLINE(void) rtmemBlockLock(void) 112 112 { 113 113 unsigned c = 0; … … 120 120 * Releases the lock. 121 121 */ 122 static inline voidrtmemBlockUnlock(void)122 DECLINLINE(void) rtmemBlockUnlock(void) 123 123 { 124 124 Assert(g_BlocksLock == 1); … … 130 130 * Creates a block. 131 131 */ 132 static inline PRTMEMBLOCK rtmemBlockCreate(RTMEMTYPE enmType, size_t cb, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction) 132 DECLINLINE(PRTMEMBLOCK) rtmemBlockCreate(RTMEMTYPE enmType, size_t cbUnaligned, size_t cbAligned, 133 void *pvCaller, RT_SRC_POS_DECL) 133 134 { 134 135 PRTMEMBLOCK pBlock = (PRTMEMBLOCK)malloc(sizeof(*pBlock)); 135 136 if (pBlock) 136 137 { 137 pBlock->enmType = enmType; 138 pBlock->cb = cb; 139 pBlock->pvCaller = pvCaller; 140 pBlock->iLine = iLine; 141 pBlock->pszFile = pszFile; 138 pBlock->enmType = enmType; 139 pBlock->cbUnaligned = cbUnaligned; 140 pBlock->cbAligned = cbAligned; 141 pBlock->pvCaller = pvCaller; 142 pBlock->iLine = iLine; 143 pBlock->pszFile = pszFile; 142 144 pBlock->pszFunction = pszFunction; 143 145 } … … 149 151 * Frees a block. 150 152 */ 151 static inline voidrtmemBlockFree(PRTMEMBLOCK pBlock)153 DECLINLINE(void) rtmemBlockFree(PRTMEMBLOCK pBlock) 152 154 { 153 155 free(pBlock); … … 158 160 * Insert a block from the tree. 159 161 */ 160 static inline voidrtmemBlockInsert(PRTMEMBLOCK pBlock, void *pv)162 DECLINLINE(void) rtmemBlockInsert(PRTMEMBLOCK pBlock, void *pv) 161 163 { 162 164 pBlock->Core.Key = pv; … … 171 173 * Remove a block from the tree and returns it to the caller. 172 174 */ 173 static inline PRTMEMBLOCKrtmemBlockRemove(void *pv)175 DECLINLINE(PRTMEMBLOCK) rtmemBlockRemove(void *pv) 174 176 { 175 177 rtmemBlockLock(); … … 182 184 * Gets a block. 183 185 */ 184 static inline PRTMEMBLOCKrtmemBlockGet(void *pv)186 DECLINLINE(PRTMEMBLOCK) rtmemBlockGet(void *pv) 185 187 { 186 188 rtmemBlockLock(); … … 196 198 { 197 199 PRTMEMBLOCK pBlock = (PRTMEMBLOCK)pNode; 198 fprintf(stderr, "%p %08lx %p\n",200 fprintf(stderr, "%p %08lx(+%02lx) %p\n", 199 201 pBlock->Core.Key, 200 (long)pBlock->cb, 202 (unsigned long)pBlock->cbUnaligned, 203 (unsigned long)(pBlock->cbAligned - pBlock->cbUnaligned), 201 204 pBlock->pvCaller); 202 205 return 0; … … 210 213 void RTMemDump(void) 211 214 { 212 fprintf(stderr, "address size caller\n");215 fprintf(stderr, "address size(alg) caller\n"); 213 216 RTAvlPVDoWithAll(&g_BlocksTree, true, RTMemDumpOne, NULL); 214 217 } … … 219 222 * Insert a delayed block. 220 223 */ 221 static inline voidrtmemBlockDelayInsert(PRTMEMBLOCK pBlock)222 { 223 size_t cbBlock = RT_ALIGN_Z(pBlock->cb , PAGE_SIZE) + RTALLOC_EFENCE_SIZE;224 DECLINLINE(void) rtmemBlockDelayInsert(PRTMEMBLOCK pBlock) 225 { 226 size_t cbBlock = RT_ALIGN_Z(pBlock->cbAligned, PAGE_SIZE) + RTALLOC_EFENCE_SIZE; 224 227 pBlock->Core.pRight = NULL; 225 228 pBlock->Core.pLeft = NULL; … … 243 246 * Removes a delayed block. 244 247 */ 245 static inline PRTMEMBLOCKrtmemBlockDelayRemove(void)248 DECLINLINE(PRTMEMBLOCK) rtmemBlockDelayRemove(void) 246 249 { 247 250 PRTMEMBLOCK pBlock = NULL; … … 257 260 else 258 261 g_pBlocksDelayHead = NULL; 259 g_cbBlocksDelay -= RT_ALIGN_Z(pBlock->cb , PAGE_SIZE) + RTALLOC_EFENCE_SIZE;262 g_cbBlocksDelay -= RT_ALIGN_Z(pBlock->cbAligned, PAGE_SIZE) + RTALLOC_EFENCE_SIZE; 260 263 } 261 264 } … … 273 276 * Internal allocator. 274 277 */ 275 RTDECL(void *) rtMemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cb, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction) 278 RTDECL(void *) rtR3MemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cbUnaligned, size_t cbAligned, 279 void *pvCaller, RT_SRC_POS_DECL) 276 280 { 277 281 /* … … 284 288 return NULL; 285 289 } 286 if (!cb )290 if (!cbUnaligned) 287 291 { 288 292 #if 0 … … 290 294 return NULL; 291 295 #else 292 cb = 1; 293 #endif 294 } 296 cbAligned = cbUnaligned = 1; 297 #endif 298 } 299 295 300 #ifndef RTALLOC_EFENCE_IN_FRONT 296 301 /* Alignment decreases fence accuracy, but this is at least partially 297 302 * counteracted by filling and checking the alignment padding. When the 298 303 * fence is in front then then no extra alignment is needed. */ 299 size_t cbAligned = RT_ALIGN_Z(cb, RTALLOC_EFENCE_ALIGNMENT);304 cbAligned = RT_ALIGN_Z(cbAligned, RTALLOC_EFENCE_ALIGNMENT); 300 305 #endif 301 306 … … 304 309 * Allocate the trace block. 305 310 */ 306 PRTMEMBLOCK pBlock = rtmemBlockCreate(enmType, cb , pvCaller, iLine, pszFile, pszFunction);311 PRTMEMBLOCK pBlock = rtmemBlockCreate(enmType, cbUnaligned, cbAligned, pvCaller, RT_SRC_POS_ARGS); 307 312 if (!pBlock) 308 313 { … … 315 320 * Allocate a block with page alignment space + the size of the E-fence. 316 321 */ 317 size_t cbBlock = RT_ALIGN_Z(cb , PAGE_SIZE) + RTALLOC_EFENCE_SIZE;322 size_t cbBlock = RT_ALIGN_Z(cbAligned, PAGE_SIZE) + RTALLOC_EFENCE_SIZE; 318 323 void *pvBlock = RTMemPageAlloc(cbBlock); 319 324 if (pvBlock) … … 325 330 #ifdef RTALLOC_EFENCE_IN_FRONT 326 331 void *pvEFence = pvBlock; 327 void *pv = (char *)pvEFence + RTALLOC_EFENCE_SIZE;332 void *pv = (char *)pvEFence + RTALLOC_EFENCE_SIZE; 328 333 # ifdef RTALLOC_EFENCE_NOMAN_FILLER 329 memset((char *)pv + cb, RTALLOC_EFENCE_NOMAN_FILLER, cbBlock - RTALLOC_EFENCE_SIZE - cb );334 memset((char *)pv + cb, RTALLOC_EFENCE_NOMAN_FILLER, cbBlock - RTALLOC_EFENCE_SIZE - cbUnaligned); 330 335 # endif 331 336 #else 332 337 void *pvEFence = (char *)pvBlock + (cbBlock - RTALLOC_EFENCE_SIZE); 333 void *pv = (char *)pvEFence - cbAligned;338 void *pv = (char *)pvEFence - cbAligned; 334 339 # ifdef RTALLOC_EFENCE_NOMAN_FILLER 335 340 memset(pvBlock, RTALLOC_EFENCE_NOMAN_FILLER, cbBlock - RTALLOC_EFENCE_SIZE - cbAligned); 336 memset((char *)pv + cb , RTALLOC_EFENCE_NOMAN_FILLER, cbAligned - cb);341 memset((char *)pv + cbUnaligned, RTALLOC_EFENCE_NOMAN_FILLER, cbAligned - cbUnaligned); 337 342 # endif 338 343 #endif … … 348 353 #endif 349 354 if (enmType == RTMEMTYPE_RTMEMALLOCZ) 350 memset(pv, 0, cb );355 memset(pv, 0, cbUnaligned); 351 356 #ifdef RTALLOC_EFENCE_FILLER 352 357 else 353 memset(pv, RTALLOC_EFENCE_FILLER, cb );354 #endif 355 356 rtmemLog(pszOp, "returns %p (pvBlock=%p cbBlock=%#x pvEFence=%p cb =%#x)\n", pv, pvBlock, cbBlock, pvEFence, cb);358 memset(pv, RTALLOC_EFENCE_FILLER, cbUnaligned); 359 #endif 360 361 rtmemLog(pszOp, "returns %p (pvBlock=%p cbBlock=%#x pvEFence=%p cbUnaligned=%#x)\n", pv, pvBlock, cbBlock, pvEFence, cbUnaligned); 357 362 return pv; 358 363 } … … 361 366 } 362 367 else 363 rtmemComplain(pszOp, "Failed to allocated % d bytes.\n", cb);368 rtmemComplain(pszOp, "Failed to allocated %lu (%lu) bytes.\n", (unsigned long)cbBlock, (unsigned long)cbUnaligned); 364 369 365 370 #ifdef RTALLOC_EFENCE_TRACE … … 373 378 * Internal free. 374 379 */ 375 RTDECL(void) rt MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction)380 RTDECL(void) rtR3MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, RT_SRC_POS_DECL) 376 381 { 377 382 /* … … 396 401 { 397 402 if (gfRTMemFreeLog) 398 RTLogPrintf("RTMem %s: pv=%p pvCaller=%p cb =%#x\n", pszOp, pv, pvCaller, pBlock->cb);403 RTLogPrintf("RTMem %s: pv=%p pvCaller=%p cbUnaligned=%#x\n", pszOp, pv, pvCaller, pBlock->cbUnaligned); 399 404 400 405 # ifdef RTALLOC_EFENCE_NOMAN_FILLER … … 408 413 # else 409 414 /* Alignment must match allocation alignment in rtMemAlloc(). */ 410 size_t cbAligned = RT_ALIGN_Z(pBlock->cb, RTALLOC_EFENCE_ALIGNMENT); 411 void *pvWrong = ASMMemIsAll8((char *)pv + pBlock->cb, 412 cbAligned - pBlock->cb, 415 void *pvWrong = ASMMemIsAll8((char *)pv + pBlock->cbUnaligned, 416 pBlock->cbAligned - pBlock->cbUnaligned, 413 417 RTALLOC_EFENCE_NOMAN_FILLER); 414 418 if (pvWrong) 415 419 RTAssertDoPanic(); 416 420 pvWrong = ASMMemIsAll8((void *)((uintptr_t)pv & ~PAGE_OFFSET_MASK), 417 RT_ALIGN_Z( cbAligned, PAGE_SIZE) -cbAligned,421 RT_ALIGN_Z(pBlock->cbAligned, PAGE_SIZE) - pBlock->cbAligned, 418 422 RTALLOC_EFENCE_NOMAN_FILLER); 419 423 # endif … … 426 430 * Fill the user part of the block. 427 431 */ 428 memset(pv, RTALLOC_EFENCE_FREE_FILL, pBlock->cb );432 memset(pv, RTALLOC_EFENCE_FREE_FILL, pBlock->cbUnaligned); 429 433 # endif 430 434 … … 434 438 * That means we'll expand the E-fence to cover the entire block. 435 439 */ 436 int rc = RTMemProtect(pv, pBlock->cb , RTMEM_PROT_NONE);440 int rc = RTMemProtect(pv, pBlock->cbAligned, RTMEM_PROT_NONE); 437 441 if (RT_SUCCESS(rc)) 438 442 { … … 445 449 pv = pBlock->Core.Key; 446 450 # ifdef RTALLOC_EFENCE_IN_FRONT 447 void *pvBlock = (char *)pv - RTALLOC_EFENCE_SIZE;451 void *pvBlock = (char *)pv - RTALLOC_EFENCE_SIZE; 448 452 # else 449 void *pvBlock = (void *)((uintptr_t)pv & ~PAGE_OFFSET_MASK);453 void *pvBlock = (void *)((uintptr_t)pv & ~PAGE_OFFSET_MASK); 450 454 # endif 451 size_t cbBlock = RT_ALIGN_Z(pBlock->cb , PAGE_SIZE) + RTALLOC_EFENCE_SIZE;455 size_t cbBlock = RT_ALIGN_Z(pBlock->cbAligned, PAGE_SIZE) + RTALLOC_EFENCE_SIZE; 452 456 rc = RTMemProtect(pvBlock, cbBlock, RTMEM_PROT_READ | RTMEM_PROT_WRITE); 453 457 if (RT_SUCCESS(rc)) … … 503 507 * Internal realloc. 504 508 */ 505 RTDECL(void *) rt MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction)509 RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, RT_SRC_POS_DECL) 506 510 { 507 511 /* … … 509 513 */ 510 514 if (!pvOld) 511 return rt MemAlloc(pszOp, enmType, cbNew, pvCaller, iLine, pszFile, pszFunction);515 return rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, pvCaller, RT_SRC_POS_ARGS); 512 516 if (!cbNew) 513 517 { 514 rt MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, pvCaller, iLine, pszFile, pszFunction);518 rtR3MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, pvCaller, RT_SRC_POS_ARGS); 515 519 return NULL; 516 520 } … … 524 528 if (pBlock) 525 529 { 526 void *pvRet = rt MemAlloc(pszOp, enmType, cbNew, pvCaller, iLine, pszFile, pszFunction);530 void *pvRet = rtR3MemAlloc(pszOp, enmType, cbNew, cbNew, pvCaller, RT_SRC_POS_ARGS); 527 531 if (pvRet) 528 532 { 529 memcpy(pvRet, pvOld, RT_MIN(cbNew, pBlock->cb ));530 rt MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, pvCaller, iLine, pszFile, pszFunction);533 memcpy(pvRet, pvOld, RT_MIN(cbNew, pBlock->cbUnaligned)); 534 rtR3MemFree(pszOp, RTMEMTYPE_RTMEMREALLOC, pvOld, pvCaller, RT_SRC_POS_ARGS); 531 535 } 532 536 return pvRet; … … 547 551 548 552 549 /** 550 * Same as RTMemTmpAlloc() except that it's fenced. 551 * 552 * @returns Pointer to the allocated memory. 553 * @returns NULL on failure. 554 * @param cb Size in bytes of the memory block to allocate. 555 */ 556 RTDECL(void *) RTMemEfTmpAlloc(size_t cb) RT_NO_THROW 557 { 558 return RTMemEfAlloc(cb); 559 } 560 561 562 /** 563 * Same as RTMemTmpAllocZ() except that it's fenced. 564 * 565 * @returns Pointer to the allocated memory. 566 * @returns NULL on failure. 567 * @param cb Size in bytes of the memory block to allocate. 568 */ 569 RTDECL(void *) RTMemEfTmpAllocZ(size_t cb) RT_NO_THROW 570 { 571 return RTMemEfAllocZ(cb); 572 } 573 574 575 /** 576 * Same as RTMemTmpFree() except that it's for fenced memory. 577 * 578 * @param pv Pointer to memory block. 579 */ 580 RTDECL(void) RTMemEfTmpFree(void *pv) RT_NO_THROW 581 { 582 RTMemEfFree(pv); 583 } 584 585 586 /** 587 * Same as RTMemAlloc() except that it's fenced. 588 * 589 * @returns Pointer to the allocated memory. Free with RTMemEfFree(). 590 * @returns NULL on failure. 591 * @param cb Size in bytes of the memory block to allocate. 592 */ 593 RTDECL(void *) RTMemEfAlloc(size_t cb) RT_NO_THROW 594 { 595 return rtMemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, ((void **)&cb)[-1], 0, NULL, NULL); 596 } 597 598 599 /** 600 * Same as RTMemAllocZ() except that it's fenced. 601 * 602 * @returns Pointer to the allocated memory. 603 * @returns NULL on failure. 604 * @param cb Size in bytes of the memory block to allocate. 605 */ 606 RTDECL(void *) RTMemEfAllocZ(size_t cb) RT_NO_THROW 607 { 608 return rtMemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, ((void **)&cb)[-1], 0, NULL, NULL); 609 } 610 611 612 /** 613 * Same as RTMemAllocVar() except that it's fenced. 614 * 615 * @returns Pointer to the allocated memory. Free with RTMemEfFree(). 616 * @returns NULL on failure. 617 * @param cbUnaligned Size in bytes of the memory block to allocate. 618 */ 619 RTDECL(void *) RTMemEfAllocVar(size_t cbUnaligned) RT_NO_THROW 553 RTDECL(void *) RTMemEfTmpAlloc(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW 554 { 555 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS); 556 } 557 558 559 RTDECL(void *) RTMemEfTmpAllocZ(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW 560 { 561 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS); 562 } 563 564 565 RTDECL(void) RTMemEfTmpFree(void *pv, RT_SRC_POS_DECL) RT_NO_THROW 566 { 567 if (pv) 568 rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), RT_SRC_POS_ARGS); 569 } 570 571 572 RTDECL(void *) RTMemEfAlloc(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW 573 { 574 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS); 575 } 576 577 578 RTDECL(void *) RTMemEfAllocZ(size_t cb, RT_SRC_POS_DECL) RT_NO_THROW 579 { 580 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), RT_SRC_POS_ARGS); 581 } 582 583 584 RTDECL(void *) RTMemEfAllocVar(size_t cbUnaligned, RT_SRC_POS_DECL) RT_NO_THROW 620 585 { 621 586 size_t cbAligned; … … 624 589 else 625 590 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 626 return rtMemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbAligned, ((void **)&cbUnaligned)[-1], 0, NULL, NULL); 627 } 628 629 630 /** 631 * Same as RTMemAllocZVar() except that it's fenced. 632 * 633 * @returns Pointer to the allocated memory. 634 * @returns NULL on failure. 635 * @param cbUnaligned Size in bytes of the memory block to allocate. 636 */ 637 RTDECL(void *) RTMemEfAllocZVar(size_t cbUnaligned) RT_NO_THROW 591 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, ASMReturnAddress(), RT_SRC_POS_ARGS); 592 } 593 594 595 RTDECL(void *) RTMemEfAllocZVar(size_t cbUnaligned, RT_SRC_POS_DECL) RT_NO_THROW 638 596 { 639 597 size_t cbAligned; … … 642 600 else 643 601 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 644 return rtMemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbAligned, ((void **)&cbUnaligned)[-1], 0, NULL, NULL); 645 } 646 647 648 /** 649 * Same as RTMemRealloc() except that it's fenced. 650 * 651 * @returns Pointer to the allocated memory. 652 * @returns NULL on failure. 653 * @param pvOld The memory block to reallocate. 654 * @param cbNew The new block size (in bytes). 655 */ 656 RTDECL(void *) RTMemEfRealloc(void *pvOld, size_t cbNew) RT_NO_THROW 657 { 658 return rtMemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ((void **)&pvOld)[-1], 0, NULL, NULL); 659 } 660 661 662 /** 663 * Free memory allocated by any of the RTMemEf* allocators. 664 * 665 * @param pv Pointer to memory block. 666 */ 667 RTDECL(void) RTMemEfFree(void *pv) RT_NO_THROW 602 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, ASMReturnAddress(), RT_SRC_POS_ARGS); 603 } 604 605 606 RTDECL(void *) RTMemEfRealloc(void *pvOld, size_t cbNew, RT_SRC_POS_DECL) RT_NO_THROW 607 { 608 return rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ASMReturnAddress(), RT_SRC_POS_ARGS); 609 } 610 611 612 RTDECL(void) RTMemEfFree(void *pv, RT_SRC_POS_DECL) RT_NO_THROW 668 613 { 669 614 if (pv) 670 rtMemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ((void **)&pv)[-1], 0, NULL, NULL); 671 } 672 673 674 /** 675 * Same as RTMemDup() except that it's fenced. 676 * 677 * @returns New heap block with the duplicate data. 678 * @returns NULL if we're out of memory. 679 * @param pvSrc The memory to duplicate. 680 * @param cb The amount of memory to duplicate. 681 */ 682 RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb) RT_NO_THROW 683 { 684 void *pvDst = RTMemEfAlloc(cb); 615 rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), RT_SRC_POS_ARGS); 616 } 617 618 619 RTDECL(void *) RTMemEfDup(const void *pvSrc, size_t cb, RT_SRC_POS_DECL) RT_NO_THROW 620 { 621 void *pvDst = RTMemEfAlloc(cb, RT_SRC_POS_ARGS); 685 622 if (pvDst) 686 623 memcpy(pvDst, pvSrc, cb); … … 689 626 690 627 691 /** 692 * Same as RTMemDupEx except that it's fenced. 693 * 694 * @returns New heap block with the duplicate data. 695 * @returns NULL if we're out of memory. 696 * @param pvSrc The memory to duplicate. 697 * @param cbSrc The amount of memory to duplicate. 698 * @param cbExtra The amount of extra memory to allocate and zero. 699 */ 700 RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra) RT_NO_THROW 701 { 702 void *pvDst = RTMemEfAlloc(cbSrc + cbExtra); 628 RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, RT_SRC_POS_DECL) RT_NO_THROW 629 { 630 void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, RT_SRC_POS_ARGS); 703 631 if (pvDst) 704 632 { … … 709 637 } 710 638 639 640 641 642 /* 643 * 644 * The NP (no position) versions. 645 * 646 */ 647 648 649 650 RTDECL(void *) RTMemEfTmpAllocNP(size_t cb) RT_NO_THROW 651 { 652 return rtR3MemAlloc("TmpAlloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL); 653 } 654 655 656 RTDECL(void *) RTMemEfTmpAllocZNP(size_t cb) RT_NO_THROW 657 { 658 return rtR3MemAlloc("TmpAllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL); 659 } 660 661 662 RTDECL(void) RTMemEfTmpFreeNP(void *pv) RT_NO_THROW 663 { 664 if (pv) 665 rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), NULL, 0, NULL); 666 } 667 668 669 RTDECL(void *) RTMemEfAllocNP(size_t cb) RT_NO_THROW 670 { 671 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL); 672 } 673 674 675 RTDECL(void *) RTMemEfAllocZNP(size_t cb) RT_NO_THROW 676 { 677 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL); 678 } 679 680 681 RTDECL(void *) RTMemEfAllocVarNP(size_t cbUnaligned) RT_NO_THROW 682 { 683 size_t cbAligned; 684 if (cbUnaligned >= 16) 685 cbAligned = RT_ALIGN_Z(cbUnaligned, 16); 686 else 687 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 688 return rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL); 689 } 690 691 692 RTDECL(void *) RTMemEfAllocZVarNP(size_t cbUnaligned) RT_NO_THROW 693 { 694 size_t cbAligned; 695 if (cbUnaligned >= 16) 696 cbAligned = RT_ALIGN_Z(cbUnaligned, 16); 697 else 698 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 699 return rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL); 700 } 701 702 703 RTDECL(void *) RTMemEfReallocNP(void *pvOld, size_t cbNew) RT_NO_THROW 704 { 705 return rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ASMReturnAddress(), NULL, 0, NULL); 706 } 707 708 709 RTDECL(void) RTMemEfFreeNP(void *pv) RT_NO_THROW 710 { 711 if (pv) 712 rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), NULL, 0, NULL); 713 } 714 715 716 RTDECL(void *) RTMemEfDupNP(const void *pvSrc, size_t cb) RT_NO_THROW 717 { 718 void *pvDst = RTMemEfAlloc(cb, NULL, 0, NULL); 719 if (pvDst) 720 memcpy(pvDst, pvSrc, cb); 721 return pvDst; 722 } 723 724 725 RTDECL(void *) RTMemEfDupExNP(const void *pvSrc, size_t cbSrc, size_t cbExtra) RT_NO_THROW 726 { 727 void *pvDst = RTMemEfAlloc(cbSrc + cbExtra, NULL, 0, NULL); 728 if (pvDst) 729 { 730 memcpy(pvDst, pvSrc, cbSrc); 731 memset((uint8_t *)pvDst + cbSrc, 0, cbExtra); 732 } 733 return pvDst; 734 } 735 736 -
trunk/src/VBox/Runtime/r3/alloc-ef.h
r28271 r28298 45 45 * RTMemAllocZ(), RTMemRealloc(), RTMemTmpAlloc() and RTMemTmpAllocZ(). 46 46 */ 47 #if defined(DEBUG_bird)47 #if 0 48 48 # define RTALLOC_USE_EFENCE 49 49 #endif … … 166 166 /** Allocation type. */ 167 167 RTMEMTYPE enmType; 168 /** The size of the block. */ 169 size_t cb; 168 /** The unaligned size of the block. */ 169 size_t cbUnaligned; 170 /** The aligned size of the block. */ 171 size_t cbAligned; 170 172 /** The return address of the allocator function. */ 171 173 void *pvCaller; … … 185 187 ******************************************************************************/ 186 188 RT_C_DECLS_BEGIN 187 RTDECL(void *) rtMemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cb, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction); 188 RTDECL(void *) rtMemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction); 189 RTDECL(void) rtMemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction); 189 RTDECL(void *) rtR3MemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cbUnaligned, size_t cbAligned, 190 void *pvCaller, RT_SRC_POS_DECL); 191 RTDECL(void *) rtR3MemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, RT_SRC_POS_DECL); 192 RTDECL(void) rtR3MemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, RT_SRC_POS_DECL); 190 193 RT_C_DECLS_END 191 194 -
trunk/src/VBox/Runtime/r3/alloc.cpp
r28271 r28298 44 44 #include "alloc-ef.h" 45 45 #include <iprt/alloc.h> 46 #include <iprt/asm.h> 46 47 #include <iprt/assert.h> 47 48 #include <iprt/param.h> … … 49 50 50 51 #include <stdlib.h> 52 53 #undef RTMemTmpAlloc 54 #undef RTMemTmpAllocZ 55 #undef RTMemTmpFree 56 #undef RTMemAlloc 57 #undef RTMemAllocZ 58 #undef RTMemAllocVar 59 #undef RTMemAllocZVar 60 #undef RTMemRealloc 61 #undef RTMemFree 62 #undef RTMemDup 63 #undef RTMemDupEx 51 64 52 65 … … 105 118 { 106 119 #ifdef RTALLOC_USE_EFENCE 107 void *pv = rt MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, ((void **)&cb)[-1], 0, NULL, NULL);120 void *pv = rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL); 108 121 109 122 #else /* !RTALLOC_USE_EFENCE */ … … 135 148 { 136 149 #ifdef RTALLOC_USE_EFENCE 137 void *pv = rt MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, ((void **)&cb)[-1], 0, NULL, NULL);150 void *pv = rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL); 138 151 139 152 #else /* !RTALLOC_USE_EFENCE */ … … 153 166 154 167 /** 168 * Wrapper around RTMemAlloc for automatically aligning variable sized 169 * allocations so that the various electric fence heaps works correctly. 170 * 171 * @returns See RTMemAlloc. 172 * @param cbUnaligned The unaligned size. 173 */ 174 RTDECL(void *) RTMemAllocVar(size_t cbUnaligned) 175 { 176 size_t cbAligned; 177 if (cbUnaligned >= 16) 178 cbAligned = RT_ALIGN_Z(cbUnaligned, 16); 179 else 180 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 181 #ifdef RTALLOC_USE_EFENCE 182 void *pv = RTMemAlloc(cbAligned); 183 #else 184 void *pv = rtR3MemAlloc("AllocVar", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL); 185 #endif 186 return pv; 187 } 188 189 190 /** 191 * Wrapper around RTMemAllocZ for automatically aligning variable sized 192 * allocations so that the various electric fence heaps works correctly. 193 * 194 * @returns See RTMemAllocZ. 195 * @param cbUnaligned The unaligned size. 196 */ 197 RTDECL(void *) RTMemAllocZVar(size_t cbUnaligned) 198 { 199 size_t cbAligned; 200 if (cbUnaligned >= 16) 201 cbAligned = RT_ALIGN_Z(cbUnaligned, 16); 202 else 203 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 204 #ifdef RTALLOC_USE_EFENCE 205 void *pv = RTMemAllocZ(cbAligned); 206 #else 207 void *pv = rtR3MemAlloc("AllocZVar", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL); 208 #endif 209 return pv; 210 } 211 212 213 /** 155 214 * Reallocates memory. 156 215 * … … 163 222 { 164 223 #ifdef RTALLOC_USE_EFENCE 165 void *pv = rt MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ((void **)&pvOld)[-1], 0, NULL, NULL);224 void *pv = rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ASMReturnAddress(), NULL, 0, NULL); 166 225 167 226 #else /* !RTALLOC_USE_EFENCE */ … … 187 246 if (pv) 188 247 #ifdef RTALLOC_USE_EFENCE 189 rt MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ((void **)&pv)[-1], 0, NULL, NULL);248 rtR3MemFree("Free", RTMEMTYPE_RTMEMFREE, pv, ASMReturnAddress(), NULL, 0, NULL); 190 249 #else 191 250 free(pv); -
trunk/src/VBox/Runtime/testcase/tstMemAutoPtr.cpp
r11822 r28298 113 113 g_cErrors++; 114 114 } 115 RTMemEfFree (aMem);115 RTMemEfFreeNP(aMem); 116 116 g_cFrees++; 117 117 } … … 165 165 */ 166 166 { 167 RTMemAutoPtr<char, RTMemEfAutoFree<char>, RTMemEfRealloc > Electric(10);167 RTMemAutoPtr<char, RTMemEfAutoFree<char>, RTMemEfReallocNP> Electric(10); 168 168 CHECK_EXPR(Electric.get() != NULL); 169 169 Electric[0] = '0'; … … 182 182 g_cFrees = 0; 183 183 { 184 RTMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfRealloc > FreeIt(128);184 RTMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfReallocNP> FreeIt(128); 185 185 FreeIt[127] = '0'; 186 186 } … … 189 189 g_cFrees = 0; 190 190 { 191 RTMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfRealloc > FreeIt2(128);191 RTMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfReallocNP> FreeIt2(128); 192 192 FreeIt2[127] = '1'; 193 193 FreeIt2.reset(); … … 200 200 g_cFrees = 0; 201 201 { 202 RTMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfRealloc > DontFreeIt(256);202 RTMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfReallocNP> DontFreeIt(256); 203 203 DontFreeIt[255] = '0'; 204 RTMemEfFree (DontFreeIt.release());204 RTMemEfFreeNP(DontFreeIt.release()); 205 205 } 206 206 CHECK_EXPR(g_cFrees == 0); … … 208 208 g_cFrees = 0; 209 209 { 210 RTMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfRealloc > FreeIt3(128);210 RTMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfReallocNP> FreeIt3(128); 211 211 FreeIt3[127] = '0'; 212 212 CHECK_EXPR(FreeIt3.realloc(128)); … … 223 223 g_cFrees = 0; 224 224 { 225 RTMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfRealloc > FreeIt4;225 RTMemAutoPtr<char, tstMemAutoPtrDestructorCounter, RTMemEfReallocNP> FreeIt4; 226 226 CHECK_EXPR(FreeIt4.alloc(123)); 227 227 CHECK_EXPR(FreeIt4.realloc(543)); -
trunk/src/VBox/Runtime/testcase/tstRTMemEf.cpp
r27283 r28298 51 51 * the word after the allocated block and the word before. One of them 52 52 * will crash no matter whether the fence is at the bottom or on top. */ 53 int32_t *p = (int32_t *)RTMemEfAlloc (sizeof(int32_t));53 int32_t *p = (int32_t *)RTMemEfAllocNP(sizeof(int32_t)); 54 54 RTPrintf("tstRTMemAllocEfAccess: allocated int32_t at %#p\n", p); 55 55 RTPrintf("tstRTMemAllocEfAccess: triggering buffer overrun...\n");
Note:
See TracChangeset
for help on using the changeset viewer.