delete model;
DEBUG("Exiting\n");
+ finalize();
}
int main_numargs;
#endif
}
+void *system_malloc( size_t size ){
+ static void *(*mallocp)(size_t size);
+ char *error;
+ void *ptr;
+
+ /* get address of libc malloc */
+ if (!mallocp) {
+ mallocp = ( void * ( * )( size_t ) )dlsym(RTLD_NEXT, "malloc");
+ if ((error = dlerror()) != NULL) {
+ fputs(error, stderr);
+ exit(1);
+ }
+ }
+ ptr = mallocp(size);
+ return ptr;
+}
+
+void system_free( void * ptr ){
+ static void (*freep)(void *);
+ char *error;
+
+ /* get address of libc free */
+ if (!freep) {
+ freep = ( void ( * )( void * ) )dlsym(RTLD_NEXT, "free");
+ if ((error = dlerror()) != NULL) {
+ fputs(error, stderr);
+ exit(1);
+ }
+ }
+ freep(ptr);
+}
void MYFREE(void *ptr) {
#if USE_MPROTECT_SNAPSHOT
static void (*freep)(void *);
mspace_free( mySpace, ptr );
}
+void *realloc( void *ptr, size_t size ){
+ return mspace_realloc( mySpace, ptr, size );
+}
+
void * operator new(size_t size) throw(std::bad_alloc) {
return malloc(size);
}
void *MYMALLOC(size_t size);
void MYFREE(void *ptr);
+void system_free( void * ptr );
+void *system_malloc( size_t size );
/*
The following code example is taken from the book
The C++ Standard Library - A Tutorial and Reference
typedef void * mspace;
extern void* mspace_malloc(mspace msp, size_t bytes);
extern void mspace_free(mspace msp, void* mem);
+extern void* mspace_realloc(mspace msp, void* mem, size_t newsize);
+extern void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
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;
void initSnapShotLibrary(unsigned int numbackingpages,
unsigned int numsnapshots, unsigned int nummemoryregions,
unsigned int numheappages, VoidFuncPtr entryPoint);
+void finalize();
void SnapshotGlobalSegments();
sTheRecord->mStackSize = STACK_SIZE_DEFAULT;
sTheRecord->mIDToRollback = -1;
sTheRecord->currSnapShotID = 0;
+ sTheRecord->mbFinalize = false;
#endif
}
#ifdef __cplusplus
addMemoryRegionToSnapShot(pagealignedbase, numheappages);
entryPoint();
#else
- //SUBRAMANIAN: WHY IS THIS SIGNAL HANDLER HERE FOR THE FORK BASED APPROACH????
- //IT LOOKS LIKE SOME CODE WAS REMOVED FROM SIGNAL HANDLER...
- //IN ANY CASE, DO NOT REUSE THE HANDLEPF CALL!!!!
- //add a signal to indicate that the process is going to terminate.
- struct sigaction sa;
- sa.sa_flags = SA_SIGINFO | SA_NODEFER | SA_RESTART;
- sigemptyset( &sa.sa_mask );
- sa.sa_sigaction = HandlePF;
- if( sigaction( SIGUSR1, &sa, NULL ) == -1 ){
- printf("SIGACTION CANNOT BE INSTALLED\n");
- exit(-1);
- }
+ basemySpace=system_malloc((numheappages+1)*PAGESIZE);
+ void * pagealignedbase=PageAlignAddressUpward(basemySpace);
+ mySpace = create_mspace_with_base(pagealignedbase, numheappages*PAGESIZE, 1 );
createSharedLibrary();
//step 2 setup the stack context.