X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=snapshot.cc;h=59aad7220dc2388d2337f30cedb4584ecd6720e8;hb=99928ab8d61239d499f5bf45ae9a2b41595350f8;hp=dadb75956c1f4254c3ecc84d519cd7431a8910af;hpb=c80c149893770f4b86b3578a827c6a028985de7f;p=model-checker.git diff --git a/snapshot.cc b/snapshot.cc index dadb759..59aad72 100644 --- a/snapshot.cc +++ b/snapshot.cc @@ -45,7 +45,8 @@ struct SnapShot * snapshotrecord = NULL; static ucontext_t savedSnapshotContext; static ucontext_t savedUserSnapshotContext; static snapshot_id snapshotid = 0; -#endif + +#else /* USE_MPROTECT_SNAPSHOT */ /** PageAlignedAdressUpdate return a page aligned address for the * address being added as a side effect the numBytes are also changed. @@ -54,8 +55,6 @@ static void * PageAlignAddressUpward(void * addr) { return (void *)((((uintptr_t)addr)+PAGESIZE-1)&~(PAGESIZE-1)); } -#if USE_MPROTECT_SNAPSHOT - /** ReturnPageAlignedAddress returns a page aligned address for the * address being added as a side effect the numBytes are also changed. */ @@ -109,7 +108,7 @@ static void HandlePF( int sig, siginfo_t *si, void * unused){ // Handle error by quitting? } } -#endif //nothing to handle for non snapshotting case. +#endif /* USE_MPROTECT_SNAPSHOT */ #if !USE_MPROTECT_SNAPSHOT void createSharedMemory(){ @@ -129,17 +128,17 @@ void createSharedMemory(){ #endif -/** The initSnapShotLibrary function initializes the Snapshot library. +/** The initSnapshotLibrary function initializes the snapshot library. * @param entryPoint the function that should run the program. */ #if USE_MPROTECT_SNAPSHOT -void initSnapShotLibrary(unsigned int numbackingpages, +void initSnapshotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, unsigned int numheappages, VoidFuncPtr entryPoint) { /* Setup a stack for our signal handler.... */ stack_t ss; - ss.ss_sp = model_malloc(SIGSTACKSIZE); + ss.ss_sp = PageAlignAddressUpward(model_malloc(SIGSTACKSIZE+PAGESIZE-1)); ss.ss_size = SIGSTACKSIZE; ss.ss_flags = 0; sigaltstack(&ss, NULL); @@ -171,19 +170,16 @@ void initSnapShotLibrary(unsigned int numbackingpages, HandlePF(SIGSEGV, &si, NULL); snapshotrecord->lastBackingPage--; //remove the fake page we copied - basemySpace=model_malloc((numheappages+1)*PAGESIZE); + void *basemySpace = model_malloc((numheappages+1)*PAGESIZE); void * pagealignedbase=PageAlignAddressUpward(basemySpace); - mySpace = create_mspace_with_base(pagealignedbase, numheappages*PAGESIZE, 1 ); + user_snapshot_space = create_mspace_with_base(pagealignedbase, numheappages * PAGESIZE, 1); addMemoryRegionToSnapShot(pagealignedbase, numheappages); entryPoint(); } #else -void initSnapShotLibrary(unsigned int numbackingpages, +void initSnapshotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, unsigned int numheappages, VoidFuncPtr entryPoint) { - basemySpace=system_malloc((numheappages+1)*PAGESIZE); - void * pagealignedbase=PageAlignAddressUpward(basemySpace); - mySpace = create_mspace_with_base(pagealignedbase, numheappages*PAGESIZE, 1 ); if (!snapshotrecord) createSharedMemory(); @@ -283,7 +279,7 @@ snapshot_id takeSnapshot( ){ * @param theID is the snapshot identifier to rollback to. */ void rollBack( snapshot_id theID ){ -#if USE_MPOTECT_SNAPSHOT==2 +#if USE_MPROTECT_SNAPSHOT==2 if (snapshotrecord->lastSnapShot==(theID+1)) { for(unsigned int page=snapshotrecord->snapShots[theID].firstBackingPage; pagelastBackingPage; page++) { memcpy(snapshotrecord->backingRecords[page].basePtrOfPage, &snapshotrecord->backingStore[page], sizeof(struct SnapShotPage));