X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=blobdiff_plain;f=snapshot.cc;h=f129f4cc31da565aeed8bfd0b2a5d1f4b063e8a5;hp=9020bb70e840ab445ab059fe3a0a2cbda7fb7653;hb=2c830a91c32a55de67c21e03f36529f994d9139d;hpb=123c66e0c1b0f58aae2916cc22b2100143a2ceb4 diff --git a/snapshot.cc b/snapshot.cc index 9020bb7..f129f4c 100644 --- a/snapshot.cc +++ b/snapshot.cc @@ -3,7 +3,7 @@ #include #include #include -#include +#include "hashtable.h" #include #include #include "snapshot.h" @@ -17,6 +17,8 @@ #include #include +#include "common.h" + #define FAILURE(mesg) { printf("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit(EXIT_FAILURE); } #ifdef CONFIG_SSDEBUG @@ -65,13 +67,13 @@ static void * ReturnPageAlignedAddress(void * addr) { * structures for the mprotect based snapshot. */ static void initSnapShotRecord(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions) { - snapshotrecord=( struct SnapShot * )MYMALLOC(sizeof(struct SnapShot)); - snapshotrecord->regionsToSnapShot=( struct MemoryRegion * )MYMALLOC(sizeof(struct MemoryRegion)*nummemoryregions); - snapshotrecord->backingStoreBasePtr= ( struct SnapShotPage * )MYMALLOC( sizeof( struct SnapShotPage ) * (numbackingpages + 1) ); + snapshotrecord=( struct SnapShot * )model_malloc(sizeof(struct SnapShot)); + snapshotrecord->regionsToSnapShot=( struct MemoryRegion * )model_malloc(sizeof(struct MemoryRegion)*nummemoryregions); + snapshotrecord->backingStoreBasePtr= ( struct SnapShotPage * )model_malloc( sizeof( struct SnapShotPage ) * (numbackingpages + 1) ); //Page align the backingstorepages snapshotrecord->backingStore=( struct SnapShotPage * )PageAlignAddressUpward(snapshotrecord->backingStoreBasePtr); - snapshotrecord->backingRecords=( struct BackingPageRecord * )MYMALLOC(sizeof(struct BackingPageRecord)*numbackingpages); - snapshotrecord->snapShots= ( struct SnapShotRecord * )MYMALLOC(sizeof(struct SnapShotRecord)*numsnapshots); + snapshotrecord->backingRecords=( struct BackingPageRecord * )model_malloc(sizeof(struct BackingPageRecord)*numbackingpages); + snapshotrecord->snapShots= ( struct SnapShotRecord * )model_malloc(sizeof(struct SnapShotRecord)*numsnapshots); snapshotrecord->lastSnapShot=0; snapshotrecord->lastBackingPage=0; snapshotrecord->lastRegion=0; @@ -86,6 +88,7 @@ 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); + print_trace(); exit( EXIT_FAILURE ); } void* addr = ReturnPageAlignedAddress(si->si_addr); @@ -126,17 +129,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 = MYMALLOC(SIGSTACKSIZE); + ss.ss_sp = PageAlignAddressUpward(model_malloc(SIGSTACKSIZE+PAGESIZE-1)); ss.ss_size = SIGSTACKSIZE; ss.ss_flags = 0; sigaltstack(&ss, NULL); @@ -168,14 +171,14 @@ void initSnapShotLibrary(unsigned int numbackingpages, HandlePF(SIGSEGV, &si, NULL); snapshotrecord->lastBackingPage--; //remove the fake page we copied - basemySpace=MYMALLOC((numheappages+1)*PAGESIZE); + basemySpace=model_malloc((numheappages+1)*PAGESIZE); void * pagealignedbase=PageAlignAddressUpward(basemySpace); mySpace = 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); @@ -280,8 +283,17 @@ snapshot_id takeSnapshot( ){ * @param theID is the snapshot identifier to rollback to. */ void rollBack( snapshot_id theID ){ +#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)); + } + return; + } +#endif + #if USE_MPROTECT_SNAPSHOT - std::map< void *, bool, std::less< void * >, MyAlloc< std::pair< const void *, bool > > > duplicateMap; + HashTable< void *, bool, uintptr_t, 4, model_malloc, model_calloc, model_free> duplicateMap; 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"); @@ -290,14 +302,8 @@ void rollBack( snapshot_id theID ){ } } for(unsigned int page=snapshotrecord->snapShots[theID].firstBackingPage; pagelastBackingPage; page++) { - bool oldVal = false; - if( duplicateMap.find( snapshotrecord->backingRecords[page].basePtrOfPage ) != duplicateMap.end() ){ - oldVal = true; - } - else{ - duplicateMap[ snapshotrecord->backingRecords[page].basePtrOfPage ] = true; - } - if( !oldVal ){ + if( !duplicateMap.contains(snapshotrecord->backingRecords[page].basePtrOfPage )) { + duplicateMap.put(snapshotrecord->backingRecords[page].basePtrOfPage, true); memcpy(snapshotrecord->backingRecords[page].basePtrOfPage, &snapshotrecord->backingStore[page], sizeof(struct SnapShotPage)); } }