main_args=args;
/* Let's jump in quickly and start running stuff */
- initSnapShotLibrary(10000 /*int numbackingpages*/, 1024 /*unsigned int numsnapshots*/, 1024 /*unsigned int nummemoryregions*/ , &real_main /*MyFuncPtr entryPoint*/);
+ initSnapShotLibrary(10000 /*int numbackingpages*/, 1024 /*unsigned int numsnapshots*/, 1024 /*unsigned int nummemoryregions*/ , 1000 /*int numheappages*/, &real_main /*MyFuncPtr entryPoint*/);
}
mspace_free( sStaticSpace, ptr );
#endif
}
-static mspace mySpace = NULL;
+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 );
}
mspace_free( mySpace, ptr );
}
-void AddUserHeapToSnapshot(){
- 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 *MYMALLOC(size_t size);
void MYFREE(void *ptr);
-void AddUserHeapToSnapshot();
/*
The following code example is taken from the book
The C++ Standard Library - A Tutorial and Reference
return false;
}
-
#ifdef __cplusplus
extern "C" {
#endif
extern void mspace_free(mspace msp, void* mem);
extern mspace create_mspace_with_base(void* base, size_t capacity, int locked);
extern mspace create_mspace(size_t capacity, int locked);
+extern mspace mySpace;
#ifdef __cplusplus
}; /* end of extern "C" */
#endif
//declaration of constructor....
snapshotStack::snapshotStack(){
SnapshotGlobalSegments();
- AddUserHeapToSnapshot();
stack=NULL;
}
#ifdef __cplusplus
}
#endif
-void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions , MyFuncPtr entryPoint){
+void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, unsigned int numheappages, MyFuncPtr entryPoint){
#if USE_CHECKPOINTING
struct sigaction sa;
sa.sa_flags = SA_SIGINFO | SA_NODEFER | SA_RESTART;
exit(-1);
}
initSnapShotRecord(numbackingpages, numsnapshots, nummemoryregions);
+ mySpace = create_mspace( numheappages*PAGESIZE, 1 );
+ addMemoryRegionToSnapShot(mySpace, numheappages);
entryPoint();
#else
//add a signal to indicate that the process is going to terminate.
typedef unsigned int snapshot_id;
typedef void (*MyFuncPtr)();
-void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, MyFuncPtr entryPoint);
+void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, unsigned int numheappages, MyFuncPtr entryPoint);
void addMemoryRegionToSnapShot( void * ptr, unsigned int numPages );