snapshot: remove unused 'uc_link' context
[model-checker.git] / snapshot.cc
index e9a9783be7b0cbd9a3115076409abeb83f4a8dfa..d8eda7f5a3dd8448f0091af1e420e73bf7fb743f 100644 (file)
@@ -72,13 +72,11 @@ static void initSnapShotRecord(unsigned int numbackingpages, unsigned int numsna
        snapshotrecord->maxBackingPages=numbackingpages;
        snapshotrecord->maxSnapShots=numsnapshots;
 }
-#endif //nothing to initialize for the fork based snapshotting.
 
 /** HandlePF is the page fault handler for mprotect based snapshotting
  * algorithm.
  */
 static void HandlePF( int sig, siginfo_t *si, void * unused){
-#if USE_MPROTECT_SNAPSHOT
        if( si->si_code == SEGV_MAPERR ){
                printf("Real Fault at %p\n", si->si_addr);
                exit( EXIT_FAILURE );
@@ -100,21 +98,25 @@ static void HandlePF( int sig, siginfo_t *si, void * unused){
                perror("mprotect");
                // Handle error by quitting?
        }
-#endif //nothing to handle for non snapshotting case.
 }
+#endif //nothing to handle for non snapshotting case.
 
 void createSharedLibrary(){
 #if !USE_MPROTECT_SNAPSHOT
        //step 1. create shared memory.
-       if( sTheRecord ) return;
+       if ( sTheRecord )
+               return;
        int fd = shm_open( "/ModelChecker-Snapshotter", O_RDWR | O_CREAT, 0777 ); //universal permissions.
-       if( -1 == fd ) FAILURE("shm_open");
-       if( -1 == ftruncate( fd, ( size_t )SHARED_MEMORY_DEFAULT + ( size_t )STACK_SIZE_DEFAULT ) ) FAILURE( "ftruncate" );
-       char * memMapBase = ( char * ) mmap( 0, ( size_t )SHARED_MEMORY_DEFAULT + ( size_t )STACK_SIZE_DEFAULT, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
-       if( MAP_FAILED == memMapBase ) FAILURE("mmap");
+       if ( -1 == fd )
+               FAILURE("shm_open");
+       if ( -1 == ftruncate( fd, SHARED_MEMORY_DEFAULT + STACK_SIZE_DEFAULT ) )
+               FAILURE( "ftruncate" );
+       void * memMapBase = mmap( 0, SHARED_MEMORY_DEFAULT + STACK_SIZE_DEFAULT, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
+       if( MAP_FAILED == memMapBase )
+               FAILURE("mmap");
        sTheRecord = ( struct Snapshot * )memMapBase;
-       sTheRecord->mSharedMemoryBase = memMapBase + sizeof( struct Snapshot );
-       sTheRecord->mStackBase = ( char * )memMapBase + ( size_t )SHARED_MEMORY_DEFAULT;
+       sTheRecord->mSharedMemoryBase = (void *)((uintptr_t)memMapBase + sizeof(struct Snapshot));
+       sTheRecord->mStackBase = (void *)((uintptr_t)memMapBase + SHARED_MEMORY_DEFAULT);
        sTheRecord->mStackSize = STACK_SIZE_DEFAULT;
        sTheRecord->mIDToRollback = -1;
        sTheRecord->currSnapShotID = 0;
@@ -181,11 +183,10 @@ void initSnapShotLibrary(unsigned int numbackingpages,
        getcontext( &savedSnapshotContext );
        if( !alreadySwapped ){
                alreadySwapped = 1;
-               ucontext_t currentContext, swappedContext, newContext;
+               ucontext_t swappedContext, newContext;
                getcontext( &newContext );
                newContext.uc_stack.ss_sp = sTheRecord->mStackBase;
                newContext.uc_stack.ss_size = STACK_SIZE_DEFAULT;
-               newContext.uc_link = &currentContext;
                makecontext( &newContext, entryPoint, 0 );
                swapcontext( &swappedContext, &newContext );
        }
@@ -249,7 +250,6 @@ void addMemoryRegionToSnapShot( void * addr, unsigned int numPages) {
 /** The takeSnapshot function takes a snapshot.
  * @return The snapshot identifier.
  */
-
 snapshot_id takeSnapshot( ){
 #if USE_MPROTECT_SNAPSHOT
        for(unsigned int region=0; region<snapshotrecord->lastRegion;region++) {
@@ -276,7 +276,6 @@ snapshot_id takeSnapshot( ){
 /** The rollBack function rollback to the given snapshot identifier.
  *  @param theID is the snapshot identifier to rollback to.
  */
-
 void rollBack( snapshot_id theID ){
 #if USE_MPROTECT_SNAPSHOT
        std::map< void *, bool, std::less< void * >, MyAlloc< std::pair< const void *, bool > > > duplicateMap;
@@ -317,10 +316,8 @@ void rollBack( snapshot_id theID ){
 /** The finalize method shuts down the snapshotting system.  */
 //Subramanian -- remove this function from the external interface and
 //have us call it internally
-
 void finalize(){
 #if !USE_MPROTECT_SNAPSHOT
        sTheRecord->mbFinalize = true;
 #endif
 }
-