Changeset 28271 in vbox for trunk/src/VBox
- Timestamp:
- Apr 13, 2010 7:29:42 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r28053 r28271 186 186 RuntimeR3_SDKS.win = WINPSDK W2K3DDK 187 187 RuntimeR3_DEFS = IN_RT_R3 IN_SUP_R3 LDR_WITH_NATIVE LDR_WITH_ELF32 LDR_WITH_PE RT_WITH_VBOX RT_NO_GIP 188 #RuntimeR3_DEFS += RTMEM_WRAP_TO_EF_APIS 188 189 ifdef IPRT_WITH_KSTUFF 189 190 RuntimeR3_DEFS += LDR_WITH_KLDR … … 1740 1741 # Static library for new & delete for the electric fence. 1741 1742 # 1742 RuntimeEFCPP_TEMPLATE = $( RuntimeR3_TEMPLATE)1743 RuntimeEFCPP_TEMPLATE = $(VBoxRT_TEMPLATE) 1743 1744 RuntimeEFCPP_SDKS = $(RuntimeR3_SDKS) 1744 1745 RuntimeEFCPP_SDKS.$(KBUILD_TARGET) = $(RuntimeR3_SDKS.$(KBUILD_TARGET)) -
trunk/src/VBox/Runtime/common/alloc/alloc.cpp
r26344 r28271 38 38 #include <iprt/assert.h> 39 39 #include <iprt/string.h> 40 41 #ifdef RTMEM_WRAP_TO_EF_APIS 42 # undef RTMemAllocVar 43 # undef RTMemAllocZVar 44 # undef RTMemDup 45 # undef RTMemDupEx 46 #endif 47 48 49 50 /** 51 * Wrapper around RTMemAlloc for automatically aligning variable sized 52 * 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 else 63 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 64 return RTMemAlloc(cbAligned); 65 } 66 67 68 /** 69 * Wrapper around RTMemAllocZ for automatically aligning variable sized 70 * 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 else 81 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 82 return RTMemAllocZ(cbAligned); 83 } 40 84 41 85 -
trunk/src/VBox/Runtime/common/log/log.cpp
r27807 r28271 276 276 */ 277 277 cb = RT_OFFSETOF(RTLOGGER, afGroups[cGroups + 1]) + RTPATH_MAX; 278 pLogger = (PRTLOGGER)RTMemAllocZ (cb);278 pLogger = (PRTLOGGER)RTMemAllocZVar(cb); 279 279 if (pLogger) 280 280 { -
trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp
r28267 r28271 1072 1072 size_t const cbFile = pSrcPos->pszFile ? strlen(pSrcPos->pszFile) + 1 : 0; 1073 1073 size_t const cbFunction = pSrcPos->pszFile ? strlen(pSrcPos->pszFunction) + 1 : 0; 1074 RTLOCKVALCLASSINT *pThis = (RTLOCKVALCLASSINT *)RTMemAlloc (sizeof(*pThis) + cbFile + cbFunction + cbName);1074 RTLOCKVALCLASSINT *pThis = (RTLOCKVALCLASSINT *)RTMemAllocVar(sizeof(*pThis) + cbFile + cbFunction + cbName); 1075 1075 if (!pThis) 1076 1076 return VERR_NO_MEMORY; -
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.