4 #include "snapshotimp.h"
7 #define MSPACE_SIZE ( 1 << 20 )
9 static mspace sStaticSpace = NULL;
11 void *MYMALLOC(size_t size)
14 static void *(*mallocp)(size_t size);
18 /* get address of libc malloc */
20 mallocp = ( void * ( * )( size_t ) )dlsym(RTLD_NEXT, "malloc");
21 if ((error = dlerror()) != NULL) {
30 createSharedLibrary();
32 if( NULL == sStaticSpace )
33 sStaticSpace = create_mspace_with_base( ( void * )( sTheRecord->mSharedMemoryBase ), SHARED_MEMORY_DEFAULT -sizeof( struct Snapshot_t ), 1 );
34 return mspace_malloc( sStaticSpace, size );
38 void MYFREE(void *ptr)
41 static void (*freep)(void *);
44 /* get address of libc free */
46 freep = ( void ( * )( void * ) )dlsym(RTLD_NEXT, "free");
47 if ((error = dlerror()) != NULL) {
54 mspace_free( sStaticSpace, ptr );
57 static mspace mySpace = NULL;
58 void *malloc( size_t size ){
59 if( NULL == mySpace ){
60 //void * mem = MYMALLOC( MSPACE_SIZE );
61 mySpace = create_mspace( MSPACE_SIZE, 1 );
63 return mspace_malloc( mySpace, size );
66 void free( void * ptr ){
67 mspace_free( mySpace, ptr );