3 #include "snapshotimp.h"
6 #define MSPACE_SIZE ( 1 << 20 )
8 static mspace sStaticSpace = NULL;
10 void *MYMALLOC(size_t size)
13 static void *(*mallocp)(size_t size);
17 /* get address of libc malloc */
19 mallocp = ( void * ( * )( size_t ) )dlsym(RTLD_NEXT, "malloc");
20 if ((error = dlerror()) != NULL) {
29 createSharedLibrary();
31 if( NULL == sStaticSpace )
32 sStaticSpace = create_mspace_with_base( ( void * )( sTheRecord->mSharedMemoryBase ), SHARED_MEMORY_DEFAULT -sizeof( struct Snapshot_t ), 1 );
33 return mspace_malloc( sStaticSpace, size );
37 void MYFREE(void *ptr)
40 static void (*freep)(void *);
43 /* get address of libc free */
45 freep = ( void ( * )( void * ) )dlsym(RTLD_NEXT, "free");
46 if ((error = dlerror()) != NULL) {
53 mspace_free( sStaticSpace, ptr );
56 static mspace mySpace = NULL;
57 void *malloc( size_t size ){
58 if( NULL == mySpace ){
59 //void * mem = MYMALLOC( MSPACE_SIZE );
60 mySpace = create_mspace( MSPACE_SIZE, 1 );
62 return mspace_malloc( mySpace, size );
65 void free( void * ptr ){
66 mspace_free( mySpace, ptr );