static void * (*real_malloc)(size_t) = NULL;
static void (*real_free)(void *ptr) = NULL;
-static void __my_alloc_init(void)
-{
-
- real_malloc = (void *(*)(size_t))dlsym(RTLD_NEXT, "malloc");
- real_free = (void (*)(void *))dlsym(RTLD_NEXT, "free");
- if (real_malloc == NULL || real_free == NULL) {
- fprintf(stderr, "Error in `dlsym`: %s\n", dlerror());
- return;
- }
+static void __my_alloc_init(void) {
+ real_malloc = (void *(*)(size_t))dlsym(RTLD_NEXT, "malloc");
+ real_free = (void (*)(void *))dlsym(RTLD_NEXT, "free");
+ if (real_malloc == NULL || real_free == NULL) {
+ fprintf(stderr, "Error in `dlsym`: %s\n", dlerror());
+ return;
+ }
}
-void * myMalloc(size_t size)
-{
- if (real_malloc == NULL)
- __my_alloc_init();
+void * myMalloc(size_t size) {
+ if (real_malloc == NULL)
+ __my_alloc_init();
- return real_malloc(size);
+ return real_malloc(size);
}
void myFree(void *ptr)
{
- if (real_free == NULL)
- __my_alloc_init();
+ if (real_free == NULL)
+ __my_alloc_init();
- real_free(ptr);
+ real_free(ptr);
}
void * operator new(size_t size) throw(std::bad_alloc)
{
- return myMalloc(size);
+ return myMalloc(size);
}
void operator delete(void *p) throw()
{
- myFree(p);
+ myFree(p);
}
-
#include "mymemory.h"
#include "snapshot.h"
#include "snapshotimp.h"
#if !USE_CHECKPOINTING
static mspace sStaticSpace = NULL;
#endif
-void *MYMALLOC(size_t size)
-{
+
+void *MYMALLOC(size_t size) {
#if USE_CHECKPOINTING
static void *(*mallocp)(size_t size);
char *error;
/* get address of libc malloc */
if (!mallocp) {
- mallocp = ( void * ( * )( size_t ) )dlsym(RTLD_NEXT, "malloc");
- if ((error = dlerror()) != NULL) {
+ mallocp = ( void * ( * )( size_t ) )dlsym(RTLD_NEXT, "malloc");
+ if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
- }
+ }
}
ptr = mallocp(size);
return ptr;
createSharedLibrary();
}
if( NULL == sStaticSpace )
- sStaticSpace = create_mspace_with_base( ( void * )( sTheRecord->mSharedMemoryBase ), SHARED_MEMORY_DEFAULT -sizeof( struct Snapshot_t ), 1 );
+ sStaticSpace = create_mspace_with_base( ( void * )( sTheRecord->mSharedMemoryBase ), SHARED_MEMORY_DEFAULT -sizeof( struct Snapshot_t ), 1 );
return mspace_malloc( sStaticSpace, size );
#endif
}
-void MYFREE(void *ptr)
-{
+void MYFREE(void *ptr) {
#if USE_CHECKPOINTING
static void (*freep)(void *);
char *error;
#endif
}
static mspace mySpace = NULL;
-void *malloc( size_t size ){
- if( NULL == mySpace ){
- //void * mem = MYMALLOC( MSPACE_SIZE );
- mySpace = create_mspace( MSPACE_SIZE, 1 );
- AddUserHeapToSnapshot();
- }
- return mspace_malloc( mySpace, size );
+void *malloc( size_t size ) {
+ if( NULL == mySpace ){
+ //void * mem = MYMALLOC( MSPACE_SIZE );
+ mySpace = create_mspace( MSPACE_SIZE, 1 );
+ AddUserHeapToSnapshot();
+ }
+ return mspace_malloc( mySpace, size );
}
void free( void * ptr ){
- mspace_free( mySpace, ptr );
+ mspace_free( mySpace, ptr );
}
void AddUserHeapToSnapshot(){
- static bool alreadySnapshotted = false;
- if( alreadySnapshotted ) return;
- addMemoryRegionToSnapShot( mySpace, MSPACE_SIZE / PAGESIZE );
+ static bool alreadySnapshotted = false;
+ if( alreadySnapshotted ) return;
+ addMemoryRegionToSnapShot( mySpace, MSPACE_SIZE / PAGESIZE );
+}
+
+
+void * operator new(size_t size) throw(std::bad_alloc) {
+ return MYMALLOC(size);
+}
+
+void operator delete(void *p) throw() {
+ MYFREE(p);
}