X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=snapshot.cc;h=8bc685c57c146f6bd7767b2476e9d74f6b963ea5;hb=f41ab746f55e04e33a15c41fa61aa084d2f98ed2;hp=f129f4cc31da565aeed8bfd0b2a5d1f4b063e8a5;hpb=f4d77c40b4029cdc18f4aaa5a4e01dfbcfca5f7b;p=model-checker.git diff --git a/snapshot.cc b/snapshot.cc index f129f4c..8bc685c 100644 --- a/snapshot.cc +++ b/snapshot.cc @@ -3,26 +3,21 @@ #include #include #include -#include "hashtable.h" -#include -#include -#include "snapshot.h" -#include "snapshotimp.h" -#include "mymemory.h" -#include -#include -#include -#include +#include #include #include #include +#include "hashtable.h" +#include "snapshot.h" +#include "snapshotimp.h" +#include "mymemory.h" #include "common.h" -#define FAILURE(mesg) { printf("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit(EXIT_FAILURE); } +#define FAILURE(mesg) { model_print("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit(EXIT_FAILURE); } #ifdef CONFIG_SSDEBUG -#define SSDEBUG printf +#define SSDEBUG model_print #else #define SSDEBUG(...) do { } while (0) #endif @@ -30,6 +25,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 +47,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. @@ -87,15 +81,17 @@ static void initSnapShotRecord(unsigned int numbackingpages, unsigned int numsna */ static void HandlePF( int sig, siginfo_t *si, void * unused){ if( si->si_code == SEGV_MAPERR ){ - printf("Real Fault at %p\n", si->si_addr); + model_print("Real Fault at %p\n", si->si_addr); print_trace(); + model_print("For debugging, place breakpoint at: %s:%d\n", + __FILE__, __LINE__); exit( EXIT_FAILURE ); } void* addr = ReturnPageAlignedAddress(si->si_addr); unsigned int backingpage=snapshotrecord->lastBackingPage++; //Could run out of pages... if (backingpage==snapshotrecord->maxBackingPages) { - printf("Out of backing pages at %p\n", si->si_addr); + model_print("Out of backing pages at %p\n", si->si_addr); exit( EXIT_FAILURE ); } @@ -109,7 +105,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(){ @@ -150,12 +146,12 @@ void initSnapshotLibrary(unsigned int numbackingpages, sa.sa_sigaction = HandlePF; #ifdef MAC if( sigaction( SIGBUS, &sa, NULL ) == -1 ){ - printf("SIGACTION CANNOT BE INSTALLED\n"); + model_print("SIGACTION CANNOT BE INSTALLED\n"); exit(EXIT_FAILURE); } #endif if( sigaction( SIGSEGV, &sa, NULL ) == -1 ){ - printf("SIGACTION CANNOT BE INSTALLED\n"); + model_print("SIGACTION CANNOT BE INSTALLED\n"); exit(EXIT_FAILURE); } @@ -171,22 +167,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 ); @@ -243,7 +246,7 @@ void addMemoryRegionToSnapShot( void * addr, unsigned int numPages) { #if USE_MPROTECT_SNAPSHOT unsigned int memoryregion=snapshotrecord->lastRegion++; if (memoryregion==snapshotrecord->maxRegions) { - printf("Exceeded supported number of memory regions!\n"); + model_print("Exceeded supported number of memory regions!\n"); exit(EXIT_FAILURE); } @@ -260,13 +263,13 @@ snapshot_id takeSnapshot( ){ for(unsigned int region=0; regionlastRegion;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"); + model_print("Failed to mprotect inside of takeSnapShot\n"); exit(EXIT_FAILURE); } } unsigned int snapshot=snapshotrecord->lastSnapShot++; if (snapshot==snapshotrecord->maxSnapShots) { - printf("Out of snapshots\n"); + model_print("Out of snapshots\n"); exit(EXIT_FAILURE); } snapshotrecord->snapShots[snapshot].firstBackingPage=snapshotrecord->lastBackingPage; @@ -297,7 +300,7 @@ void rollBack( snapshot_id theID ){ for(unsigned int region=0; regionlastRegion;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"); + model_print("Failed to mprotect inside of takeSnapShot\n"); exit(EXIT_FAILURE); } }