fix page alignment issue...
[model-checker.git] / snapshot.cc
index 9a92aac259d644a62c3fef5b672b621d55d4d888..83d22b4f5939b31ec7689177aed381b057966697 100644 (file)
@@ -91,7 +91,10 @@ void HandlePF( int sig, siginfo_t *si, void * unused){
        //remember where to copy page back to
        snapshotrecord->backingRecords[backingpage].basePtrOfPage=addr;
        //set protection to read/write
-       mprotect( addr, sizeof(struct SnapShotPage), PROT_READ | PROT_WRITE );  
+       if (mprotect( addr, sizeof(struct SnapShotPage), PROT_READ | PROT_WRITE )) {
+               perror("mprotect");
+               // Handle error by quitting?
+       }
 #endif //nothing to handle for non snapshotting case.
 }
 
@@ -134,8 +137,11 @@ void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots
                exit(-1);
        }
        initSnapShotRecord(numbackingpages, numsnapshots, nummemoryregions);
-       mySpace = create_mspace( numheappages*PAGESIZE, 1 );
-       addMemoryRegionToSnapShot(mySpace, numheappages);
+       
+       basemySpace=MYMALLOC((numheappages+1)*PAGESIZE);
+       void * pagealignedbase=(void *)((((uintptr_t)basemySpace)+PAGESIZE-1)&~(PAGESIZE-1));
+       mySpace = create_mspace_with_base(pagealignedbase,  numheappages*PAGESIZE, 1 );
+       addMemoryRegionToSnapShot(pagealignedbase, numheappages);
        entryPoint();
 #else
        //add a signal to indicate that the process is going to terminate.
@@ -226,6 +232,7 @@ snapshot_id takeSnapshot( ){
 #if USE_CHECKPOINTING
        for(unsigned int region=0; region<snapshotrecord->lastRegion;region++) {
                if( mprotect(snapshotrecord->regionsToSnapShot[region].basePtr, snapshotrecord->regionsToSnapShot[region].sizeInPages*sizeof(struct SnapShotPage), PROT_READ ) == -1 ){
+                       perror("mprotect");
                        printf("Failed to mprotect inside of takeSnapShot\n");
                        exit(-1);
                }               
@@ -248,6 +255,7 @@ void rollBack( snapshot_id theID ){
        std::map< void *, bool, std::less< void * >, MyAlloc< std::pair< const void *, bool > > > duplicateMap;
        for(unsigned int region=0; region<snapshotrecord->lastRegion;region++) {
                if( mprotect(snapshotrecord->regionsToSnapShot[region].basePtr, snapshotrecord->regionsToSnapShot[region].sizeInPages*sizeof(struct SnapShotPage), PROT_READ | PROT_WRITE ) == -1 ){
+                       perror("mprotect");
                        printf("Failed to mprotect inside of takeSnapShot\n");
                        exit(-1);
                }