Changeset 53010 in vbox
- Timestamp:
- Oct 9, 2014 2:12:32 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/asn1.h
r52600 r53010 110 110 extern RTDATADECL(RTASN1ALLOCATORVTABLE const) g_RTAsn1DefaultAllocator; 111 111 112 /** The Electric Fence ASN.1 allocator. */ 113 extern RTDATADECL(RTASN1ALLOCATORVTABLE const) g_RTAsn1EFenceAllocator; 114 112 115 113 116 /** -
trunk/include/iprt/mangling.h
r52944 r53010 2916 2916 # define g_RTAsn1BitString_Vtable RT_MANGLER(g_RTAsn1BitString_Vtable) 2917 2917 # define g_RTAsn1DefaultAllocator RT_MANGLER(g_RTAsn1DefaultAllocator) 2918 # define g_RTAsn1EFenceAllocator RT_MANGLER(g_RTAsn1EFenceAllocator) 2918 2919 #if 0 /* Disabled for now as I'm not sure the assmbler supports mangling yet. */ 2919 2920 # define g_abRTZeroPage RT_MANGLER(g_abRTZeroPage) -
trunk/src/VBox/Runtime/Makefile.kmk
r52944 r53010 277 277 common/asn1/asn1-cursor.cpp \ 278 278 common/asn1/asn1-default-allocator.cpp \ 279 common/asn1/asn1-efence-allocator.cpp \ 279 280 common/asn1/asn1-dump.cpp \ 280 281 common/asn1/asn1-encode.cpp \ -
trunk/src/VBox/Runtime/common/asn1/asn1-efence-allocator.cpp
r52965 r53010 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - ASN.1, DefaultAllocator.3 * IPRT - ASN.1, Electric Fense Allocator. 4 4 */ 5 5 … … 36 36 37 37 38 /** 39 * Aligns allocation sizes a little. 40 * 41 * @returns Aligned size. 42 * @param cb Requested size. 43 */ 44 static size_t rtAsn1DefaultAllocator_AlignSize(size_t cb) 38 /** @interface_method_impl{RTASN1ALLOCATORVTABLE, pfnFree} */ 39 static DECLCALLBACK(void) rtAsn1EFenceAllocator_Free(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, void *pv) 45 40 { 46 if (cb >= 64) 47 return RT_ALIGN_Z(cb, 64); 48 if (cb >= 32) 49 return RT_ALIGN_Z(cb, 32); 50 if (cb >= 16) 51 return RT_ALIGN_Z(cb, 16); 52 return cb; 53 } 54 55 56 /** @interface_method_impl{RTASN1ALLOCATORVTABLE, pfnFree} */ 57 static DECLCALLBACK(void) rtAsn1DefaultAllocator_Free(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, void *pv) 58 { 59 RTMemFree(pv); 41 RTMemEfFreeNP(pv); 60 42 pAllocation->cbAllocated = 0; 61 43 } … … 63 45 64 46 /** @interface_method_impl{RTASN1ALLOCATORVTABLE, pfnAlloc} */ 65 static DECLCALLBACK(int) rtAsn1 DefaultAllocator_Alloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,66 47 static DECLCALLBACK(int) rtAsn1EFenceAllocator_Alloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, 48 void **ppv, size_t cb) 67 49 { 68 size_t cbAlloc = rtAsn1DefaultAllocator_AlignSize(cb); 69 void *pv = RTMemAllocZ(cbAlloc); 50 void *pv = RTMemEfAllocZNP(cb, RTMEM_TAG); 70 51 if (pv) 71 52 { 72 53 *ppv = pv; 73 pAllocation->cbAllocated = (uint32_t)cb Alloc;54 pAllocation->cbAllocated = (uint32_t)cb; 74 55 return VINF_SUCCESS; 75 56 } … … 79 60 80 61 /** @interface_method_impl{RTASN1ALLOCATORVTABLE, pfnRealloc} */ 81 static DECLCALLBACK(int) rtAsn1 DefaultAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,82 62 static DECLCALLBACK(int) rtAsn1EFenceAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, 63 void *pvOld, void **ppvNew, size_t cbNew) 83 64 { 84 65 Assert(pvOld); 85 66 Assert(cbNew); 86 size_t cbAlloc = rtAsn1DefaultAllocator_AlignSize(cbNew); 87 void *pv = RTMemRealloc(pvOld, cbAlloc); 67 void *pv = RTMemEfReallocNP(pvOld, cbNew, RTMEM_TAG); 88 68 if (pv) 89 69 { 90 70 *ppvNew = pv; 91 pAllocation->cbAllocated = (uint32_t)cb Alloc;71 pAllocation->cbAllocated = (uint32_t)cbNew; 92 72 return VINF_SUCCESS; 93 73 } … … 96 76 97 77 98 /** The defaultASN.1 allocator. */99 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1 DefaultAllocator =78 /** The Electric Fence ASN.1 allocator. */ 79 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1EFenceAllocator = 100 80 { 101 rtAsn1 DefaultAllocator_Free,102 rtAsn1 DefaultAllocator_Alloc,103 rtAsn1 DefaultAllocator_Realloc81 rtAsn1EFenceAllocator_Free, 82 rtAsn1EFenceAllocator_Alloc, 83 rtAsn1EFenceAllocator_Realloc 104 84 }; 105 85
Note:
See TracChangeset
for help on using the changeset viewer.