X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=blobdiff_plain;f=snapshot.cc;h=e006189c44ba1741208183ea8cbddd222b381dfd;hp=f129f4cc31da565aeed8bfd0b2a5d1f4b063e8a5;hb=9db4729d3e6ab5f3ec5fd8a2560d95026332fecf;hpb=85683f798e0955c43cf6cd8099713c45d9ce882b diff --git a/snapshot.cc b/snapshot.cc index f129f4c..e006189 100644 --- a/snapshot.cc +++ b/snapshot.cc @@ -30,6 +30,13 @@ /* extern declaration definition */ struct SnapShot * snapshotrecord = NULL; +/** PageAlignedAdressUpdate return a page aligned address for the + * address being added as a side effect the numBytes are also changed. + */ +static void * PageAlignAddressUpward(void * addr) { + return (void *)((((uintptr_t)addr)+PAGESIZE-1)&~(PAGESIZE-1)); +} + #if !USE_MPROTECT_SNAPSHOT /** @statics * These variables are necessary because the stack is shared region and @@ -45,16 +52,8 @@ struct SnapShot * snapshotrecord = NULL; static ucontext_t savedSnapshotContext; static ucontext_t savedUserSnapshotContext; static snapshot_id snapshotid = 0; -#endif -/** PageAlignedAdressUpdate return a page aligned address for the - * address being added as a side effect the numBytes are also changed. - */ -static void * PageAlignAddressUpward(void * addr) { - return (void *)((((uintptr_t)addr)+PAGESIZE-1)&~(PAGESIZE-1)); -} - -#if USE_MPROTECT_SNAPSHOT +#else /* 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(){ @@ -171,22 +170,29 @@ 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); + + void *base_model_snapshot_space = model_malloc((numheappages + 1) * PAGESIZE); + pagealignedbase = PageAlignAddressUpward(base_model_snapshot_space); + model_snapshot_space = create_mspace_with_base(pagealignedbase, numheappages * PAGESIZE, 1); + addMemoryRegionToSnapShot(pagealignedbase, numheappages); + entryPoint(); } #else 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(); + void *base_model_snapshot_space = malloc((numheappages + 1) * PAGESIZE); + void *pagealignedbase = PageAlignAddressUpward(base_model_snapshot_space); + model_snapshot_space = create_mspace_with_base(pagealignedbase, numheappages * PAGESIZE, 1); + //step 2 setup the stack context. ucontext_t newContext; getcontext( &newContext );