VirtualBox

Changeset 31253 in vbox


Ignore:
Timestamp:
Jul 30, 2010 3:41:43 PM (15 years ago)
Author:
vboxsync
Message:

xpcom/nspr: Use RTMem* for memory alloc so that we can more easily wrap direct it to the electric fence heap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/nsprpub/pr/src/malloc/prmem.c

    r11551 r31253  
    4141
    4242#include "primpl.h"
     43#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     44# include <iprt/mem.h>
     45#endif
    4346
    4447#ifdef _PR_ZONE_ALLOCATOR
     
    5457*/
    5558
    56 #include <string.h>     
     59#include <string.h>
    5760
    5861union memBlkHdrUn;
     
    9295void
    9396_PR_DestroyZones(void)
    94 {   
     97{
    9598    int i, j;
    9699
    97100    if (!use_zone_allocator)
    98101        return;
    99    
     102
    100103    for (j = 0; j < THREAD_POOLS; j++) {
    101104        for (i = 0; i < MEM_ZONES; i++) {
     
    109112            }
    110113        }
    111     } 
     114    }
    112115    use_zone_allocator = PR_FALSE;
    113 } 
     116}
    114117
    115118/*
     
    184187        return;
    185188
    186     for (j = 0; j < THREAD_POOLS; j++) { 
     189    for (j = 0; j < THREAD_POOLS; j++) {
    187190        for (i = 0; i < MEM_ZONES; i++) {
    188191            MemoryZone *mz = &zones[i][j];
     
    191194            if (rv != 0) {
    192195                goto loser;
    193             } 
     196            }
    194197            mz->blockSize = 16 << ( 2 * i);
    195198        }
     
    365368        PR_ASSERT(mt->s.zone  == mb->s.zone);
    366369        PR_ASSERT(mt->s.blockSize == blockSize);
    367        
     370
    368371        if (bytes <= blockSize) {
    369372            /* The block is already big enough. */
     
    373376        ours = 1;
    374377    }
    375    
     378
    376379    rv = pr_ZoneMalloc(bytes);
    377380    if (rv) {
     
    438441    if (!_pr_initialized) _PR_ImplicitInitialization();
    439442
     443#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     444    return use_zone_allocator ? pr_ZoneMalloc(size) : RTMemAlloc(size);
     445#else
    440446    return use_zone_allocator ? pr_ZoneMalloc(size) : malloc(size);
     447#endif
    441448}
    442449
     
    446453
    447454    return use_zone_allocator ?
     455#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     456        pr_ZoneCalloc(nelem, elsize) : RTMemAllocZ(nelem * (size_t)elsize);
     457#else
    448458        pr_ZoneCalloc(nelem, elsize) : calloc(nelem, elsize);
     459#endif
    449460}
    450461
     
    453464    if (!_pr_initialized) _PR_ImplicitInitialization();
    454465
     466#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     467    return use_zone_allocator ? pr_ZoneRealloc(ptr, size) : RTMemRealloc(ptr, size);
     468#else
    455469    return use_zone_allocator ? pr_ZoneRealloc(ptr, size) : realloc(ptr, size);
     470#endif
    456471}
    457472
     
    461476        pr_ZoneFree(ptr);
    462477    else
     478#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     479        RTMemFree(ptr);
     480#else
    463481        free(ptr);
     482#endif
    464483}
    465484
     
    479498    return PR_MD_malloc( (size_t) size);
    480499#else
     500# ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     501    return RTMemAlloc(size);
     502# else
    481503    return malloc(size);
     504# endif
    482505#endif
    483506}
     
    487510#if defined (WIN16)
    488511    return PR_MD_calloc( (size_t)nelem, (size_t)elsize );
    489    
    490 #else
     512
     513#else
     514# ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     515    return RTMemAllocZ(nelem * (size_t)elsize);
     516# else
    491517    return calloc(nelem, elsize);
     518# endif
    492519#endif
    493520}
     
    498525    return PR_MD_realloc( ptr, (size_t) size);
    499526#else
     527# ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     528    return RTMemRealloc(ptr, size);
     529# else
    500530    return realloc(ptr, size);
     531# endif
    501532#endif
    502533}
     
    507538    PR_MD_free( ptr );
    508539#else
     540# ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     541    RTMemFree(ptr);
     542# else
    509543    free(ptr);
     544# endif
    510545#endif
    511546}
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