Adding fixes for the fork based implementation, also removed some redundant code...
authorSubramanian Ganapathy <sganapat@uci.edu>
Wed, 30 May 2012 23:52:38 +0000 (16:52 -0700)
committerBrian Norris <banorris@uci.edu>
Thu, 31 May 2012 01:24:01 +0000 (18:24 -0700)
main.cc
mymemory.cc
mymemory.h
snapshot-interface.h
snapshot.cc

diff --git a/main.cc b/main.cc
index e8a2b3317dc4ebedc235735fef32d272259d4215..be4c58db7aac6411dd77ed26d7835d42f9f92479 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -65,6 +65,7 @@ void real_main() {
        delete model;
 
        DEBUG("Exiting\n");
+       finalize();
 }
 
 int main_numargs;
index 80c1b953ff6855e24d058ddffa6589f29a6dda1f..0bbb7492dd3c1aef9987304a326678cde9484330 100644 (file)
@@ -33,6 +33,37 @@ void *MYMALLOC(size_t size) {
 #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 *);
@@ -62,6 +93,10 @@ void free( void * ptr ){
        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);
 }
index 90b27844f5f8e025c68ef8be56d50f93cbdf2a72..f928797bc30f4aac90b45d25a342ab588cfa6a14 100644 (file)
@@ -23,6 +23,8 @@
 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
@@ -119,6 +121,8 @@ extern "C" {
 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;
index e9746e1ebb35468ff20e0ea68fd9ee364a0e7cd6..7e501fea4214292244273ebb806a3472591a8e09 100644 (file)
@@ -8,6 +8,7 @@ typedef void (*VoidFuncPtr)();
 void initSnapShotLibrary(unsigned int numbackingpages,
                unsigned int numsnapshots, unsigned int nummemoryregions,
                unsigned int numheappages, VoidFuncPtr entryPoint);
+void finalize();
 
 void SnapshotGlobalSegments();
 
index 4d71babeb967f9b8daba74542b6fa8044f120380..3c5e515103e6b6f4699e7ccf6cf67a69c2f27a49 100644 (file)
@@ -115,6 +115,7 @@ extern "C" {
                sTheRecord->mStackSize = STACK_SIZE_DEFAULT;
                sTheRecord->mIDToRollback = -1;
                sTheRecord->currSnapShotID = 0;
+               sTheRecord->mbFinalize = false;
 #endif
        }
 #ifdef __cplusplus
@@ -156,19 +157,10 @@ void initSnapShotLibrary(unsigned int numbackingpages,
        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.