VirtualBox

Changeset 53010 in vbox


Ignore:
Timestamp:
Oct 9, 2014 2:12:32 PM (10 years ago)
Author:
vboxsync
Message:

IPRT: Added electric fence allocator for ASN.1.

Location:
trunk
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asn1.h

    r52600 r53010  
    110110extern RTDATADECL(RTASN1ALLOCATORVTABLE const) g_RTAsn1DefaultAllocator;
    111111
     112/** The Electric Fence ASN.1 allocator. */
     113extern RTDATADECL(RTASN1ALLOCATORVTABLE const) g_RTAsn1EFenceAllocator;
     114
    112115
    113116/**
  • trunk/include/iprt/mangling.h

    r52944 r53010  
    29162916# define g_RTAsn1BitString_Vtable                       RT_MANGLER(g_RTAsn1BitString_Vtable)
    29172917# define g_RTAsn1DefaultAllocator                       RT_MANGLER(g_RTAsn1DefaultAllocator)
     2918# define g_RTAsn1EFenceAllocator                        RT_MANGLER(g_RTAsn1EFenceAllocator)
    29182919#if 0 /* Disabled for now as I'm not sure the assmbler supports mangling yet. */
    29192920# define g_abRTZeroPage                                 RT_MANGLER(g_abRTZeroPage)
  • trunk/src/VBox/Runtime/Makefile.kmk

    r52944 r53010  
    277277        common/asn1/asn1-cursor.cpp \
    278278        common/asn1/asn1-default-allocator.cpp \
     279        common/asn1/asn1-efence-allocator.cpp \
    279280        common/asn1/asn1-dump.cpp \
    280281        common/asn1/asn1-encode.cpp \
  • trunk/src/VBox/Runtime/common/asn1/asn1-efence-allocator.cpp

    r52965 r53010  
    11/* $Id$ */
    22/** @file
    3  * IPRT - ASN.1, Default Allocator.
     3 * IPRT - ASN.1, Electric Fense Allocator.
    44 */
    55
     
    3636
    3737
    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} */
     39static DECLCALLBACK(void) rtAsn1EFenceAllocator_Free(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, void *pv)
    4540{
    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);
    6042    pAllocation->cbAllocated = 0;
    6143}
     
    6345
    6446/** @interface_method_impl{RTASN1ALLOCATORVTABLE, pfnAlloc} */
    65 static DECLCALLBACK(int)  rtAsn1DefaultAllocator_Alloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
    66                                                        void **ppv, size_t cb)
     47static DECLCALLBACK(int)  rtAsn1EFenceAllocator_Alloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
     48                                                      void **ppv, size_t cb)
    6749{
    68     size_t cbAlloc = rtAsn1DefaultAllocator_AlignSize(cb);
    69     void *pv = RTMemAllocZ(cbAlloc);
     50    void *pv = RTMemEfAllocZNP(cb, RTMEM_TAG);
    7051    if (pv)
    7152    {
    7253        *ppv = pv;
    73         pAllocation->cbAllocated = (uint32_t)cbAlloc;
     54        pAllocation->cbAllocated = (uint32_t)cb;
    7455        return VINF_SUCCESS;
    7556    }
     
    7960
    8061/** @interface_method_impl{RTASN1ALLOCATORVTABLE, pfnRealloc} */
    81 static DECLCALLBACK(int)  rtAsn1DefaultAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
    82                                                          void *pvOld, void **ppvNew, size_t cbNew)
     62static DECLCALLBACK(int)  rtAsn1EFenceAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
     63                                                        void *pvOld, void **ppvNew, size_t cbNew)
    8364{
    8465    Assert(pvOld);
    8566    Assert(cbNew);
    86     size_t cbAlloc = rtAsn1DefaultAllocator_AlignSize(cbNew);
    87     void *pv = RTMemRealloc(pvOld, cbAlloc);
     67    void *pv = RTMemEfReallocNP(pvOld, cbNew, RTMEM_TAG);
    8868    if (pv)
    8969    {
    9070        *ppvNew = pv;
    91         pAllocation->cbAllocated = (uint32_t)cbAlloc;
     71        pAllocation->cbAllocated = (uint32_t)cbNew;
    9272        return VINF_SUCCESS;
    9373    }
     
    9676
    9777
    98 /** The default ASN.1 allocator. */
    99 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1DefaultAllocator =
     78/** The Electric Fence ASN.1 allocator. */
     79RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1EFenceAllocator =
    10080{
    101     rtAsn1DefaultAllocator_Free,
    102     rtAsn1DefaultAllocator_Alloc,
    103     rtAsn1DefaultAllocator_Realloc
     81    rtAsn1EFenceAllocator_Free,
     82    rtAsn1EFenceAllocator_Alloc,
     83    rtAsn1EFenceAllocator_Realloc
    10484};
    10585
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette