Changeset 28271 in vbox for trunk/src/VBox/Runtime/r3
- Timestamp:
- Apr 13, 2010 7:29:42 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime/r3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/alloc-ef-cpp.cpp
r8245 r28271 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Sun Microsystems, Inc.7 * Copyright (C) 2006-2010 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 34 34 #include "alloc-ef.h" 35 35 36 #ifdef RTALLOC_EFENCE_CPP /* rest of the file */ 36 37 #if defined(RTALLOC_EFENCE_CPP) || defined(RTMEM_WRAP_TO_EF_APIS) /* rest of the file */ 37 38 38 39 #include <new> … … 122 123 } 123 124 124 #endif /* RTALLOC_EFENCE_CPP */125 #endif /* RTALLOC_EFENCE_CPP || RTMEM_WRAP_TO_EF_APIS */ -
trunk/src/VBox/Runtime/r3/alloc-ef.cpp
r27575 r28271 34 34 *******************************************************************************/ 35 35 #include "alloc-ef.h" 36 #include <iprt/mem.h> 36 37 #include <iprt/log.h> 37 38 #include <iprt/asm.h> … … 272 273 * Internal allocator. 273 274 */ 274 void *rtMemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cb, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction)275 RTDECL(void *) rtMemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cb, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction) 275 276 { 276 277 /* … … 372 373 * Internal free. 373 374 */ 374 voidrtMemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction)375 RTDECL(void) rtMemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction) 375 376 { 376 377 /* … … 498 499 } 499 500 501 500 502 /** 501 503 * Internal realloc. 502 504 */ 503 void *rtMemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction)505 RTDECL(void *) rtMemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction) 504 506 { 505 507 /* … … 609 611 610 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 620 { 621 size_t cbAligned; 622 if (cbUnaligned >= 16) 623 cbAligned = RT_ALIGN_Z(cbUnaligned, 16); 624 else 625 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 638 { 639 size_t cbAligned; 640 if (cbUnaligned >= 16) 641 cbAligned = RT_ALIGN_Z(cbUnaligned, 16); 642 else 643 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 644 return rtMemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cbAligned, ((void **)&cbUnaligned)[-1], 0, NULL, NULL); 645 } 646 647 648 /** 611 649 * Same as RTMemRealloc() except that it's fenced. 612 650 * -
trunk/src/VBox/Runtime/r3/alloc-ef.h
r27297 r28271 45 45 * RTMemAllocZ(), RTMemRealloc(), RTMemTmpAlloc() and RTMemTmpAllocZ(). 46 46 */ 47 #if 0//defined(DEBUG_bird)47 #if defined(DEBUG_bird) 48 48 # define RTALLOC_USE_EFENCE 49 49 #endif … … 57 57 * The allocation alignment, power of two of course. 58 58 * 59 * Normally, 1 would be the perfect choice here, except that there is code, like 60 * the atomic operations in iprt/asm.h, that makes assumptions about naturally 61 * aligned data members. If the code you're working against doesn't have strict 62 * alignment requirements, changing this to 1 is highly desirable. 59 * Use this for working around misaligned sizes, usually stemming from 60 * allocating a string or something after the main structure. When you 61 * encounter this, please fix the allocation to RTMemAllocVar or RTMemAllocZVar. 63 62 */ 64 #if 163 #if 0 65 64 # define RTALLOC_EFENCE_ALIGNMENT (ARCH_BITS / 8) 66 65 #else … … 186 185 ******************************************************************************/ 187 186 RT_C_DECLS_BEGIN 188 void *rtMemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cb, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);189 void *rtMemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);190 voidrtMemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);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); 191 190 RT_C_DECLS_END 192 191 -
trunk/src/VBox/Runtime/r3/alloc.cpp
r24958 r28271 28 28 * additional information or have any questions. 29 29 */ 30 31 32 /******************************************************************************* 33 * Defined Constants And Macros * 34 *******************************************************************************/ 35 #ifdef RTMEM_WRAP_TO_EF_APIS 36 # undef RTMEM_WRAP_TO_EF_APIS 37 # define RTALLOC_USE_EFENCE 1 38 #endif 30 39 31 40 … … 103 112 void *pv = malloc(cb); 104 113 AssertMsg(pv, ("malloc(%#zx) failed!!!\n", cb)); 105 #ifdef RT_OS_OS2 /* temporary workaround until libc062. */106 AssertMsg( cb < 32107 || !((uintptr_t)pv & (RTMEM_ALIGNMENT - 1)), ("pv=%p RTMEM_ALIGNMENT=%#x\n", pv, RTMEM_ALIGNMENT));108 #else109 114 AssertMsg( cb < RTMEM_ALIGNMENT 110 || !((uintptr_t)pv & (RTMEM_ALIGNMENT - 1)), ("pv=%p RTMEM_ALIGNMENT=%#x\n", pv, RTMEM_ALIGNMENT)); 111 #endif 115 || !((uintptr_t)pv & (RTMEM_ALIGNMENT - 1)) 116 || ( (cb & RTMEM_ALIGNMENT) + ((uintptr_t)pv & RTMEM_ALIGNMENT)) == RTMEM_ALIGNMENT 117 , ("pv=%p RTMEM_ALIGNMENT=%#x\n", pv, RTMEM_ALIGNMENT)); 112 118 #endif /* !RTALLOC_USE_EFENCE */ 113 119 return pv; … … 137 143 void *pv = calloc(1, cb); 138 144 AssertMsg(pv, ("calloc(1,%#zx) failed!!!\n", cb)); 139 #ifdef RT_OS_OS2 /* temporary workaround until libc062. */140 AssertMsg( cb < 32141 || !((uintptr_t)pv & (RTMEM_ALIGNMENT - 1)), ("pv=%p RTMEM_ALIGNMENT=%#x\n", pv, RTMEM_ALIGNMENT));142 #else143 145 AssertMsg( cb < RTMEM_ALIGNMENT 144 || !((uintptr_t)pv & (RTMEM_ALIGNMENT - 1)), ("pv=%p RTMEM_ALIGNMENT=%#x\n", pv, RTMEM_ALIGNMENT)); 145 #endif 146 || !((uintptr_t)pv & (RTMEM_ALIGNMENT - 1)) 147 || ( (cb & RTMEM_ALIGNMENT) + ((uintptr_t)pv & RTMEM_ALIGNMENT)) == RTMEM_ALIGNMENT 148 , ("pv=%p RTMEM_ALIGNMENT=%#x\n", pv, RTMEM_ALIGNMENT)); 146 149 #endif /* !RTALLOC_USE_EFENCE */ 147 150 return pv; … … 166 169 void *pv = realloc(pvOld, cbNew); 167 170 AssertMsg(pv && cbNew, ("realloc(%p, %#zx) failed!!!\n", pvOld, cbNew)); 168 #ifdef RT_OS_OS2 /* temporary workaround until libc062. */169 AssertMsg( cbNew < 32170 || !((uintptr_t)pv & (RTMEM_ALIGNMENT - 1)), ("pv=%p RTMEM_ALIGNMENT=%#x\n", pv, RTMEM_ALIGNMENT));171 #else172 171 AssertMsg( cbNew < RTMEM_ALIGNMENT 173 || !((uintptr_t)pv & (RTMEM_ALIGNMENT - 1)), ("pv=%p RTMEM_ALIGNMENT=%#x\n", pv, RTMEM_ALIGNMENT)); 174 #endif 172 || !((uintptr_t)pv & (RTMEM_ALIGNMENT - 1)) 173 || ( (cbNew & RTMEM_ALIGNMENT) + ((uintptr_t)pv & RTMEM_ALIGNMENT)) == RTMEM_ALIGNMENT 174 , ("pv=%p RTMEM_ALIGNMENT=%#x\n", pv, RTMEM_ALIGNMENT)); 175 175 #endif /* !RTALLOC_USE_EFENCE */ 176 176 return pv;
Note:
See TracChangeset
for help on using the changeset viewer.