From: Brian Norris Date: Wed, 30 May 2012 06:20:37 +0000 (-0700) Subject: snapshot: rename USE_CHECKPOINTING to USE_MPROTECT_SNAPSHOT X-Git-Tag: pldi2013~392^2~2 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=commitdiff_plain;h=de6eda345f07ad17b886a96ff49bcecc705c7a45 snapshot: rename USE_CHECKPOINTING to USE_MPROTECT_SNAPSHOT "Checkpointing" is a generic name for either method. USE_MPROTECT_SNAPSHOT is a more descriptive name. --- diff --git a/mymemory.cc b/mymemory.cc index 11542bf..80c1b95 100644 --- a/mymemory.cc +++ b/mymemory.cc @@ -3,12 +3,12 @@ #include "snapshotimp.h" #include #include -#if !USE_CHECKPOINTING +#if !USE_MPROTECT_SNAPSHOT static mspace sStaticSpace = NULL; #endif void *MYMALLOC(size_t size) { -#if USE_CHECKPOINTING +#if USE_MPROTECT_SNAPSHOT static void *(*mallocp)(size_t size); char *error; void *ptr; @@ -34,7 +34,7 @@ void *MYMALLOC(size_t size) { } void MYFREE(void *ptr) { -#if USE_CHECKPOINTING +#if USE_MPROTECT_SNAPSHOT static void (*freep)(void *); char *error; diff --git a/snapshot.cc b/snapshot.cc index 01e7201..ff9fd56 100644 --- a/snapshot.cc +++ b/snapshot.cc @@ -19,7 +19,7 @@ //extern declaration definition #define FAILURE(mesg) { printf("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit( -1 ); } -#if USE_CHECKPOINTING +#if USE_MPROTECT_SNAPSHOT struct SnapShot * snapshotrecord = NULL; struct Snapshot_t * sTheRecord = NULL; #else @@ -37,13 +37,13 @@ void DumpIntoLog( const char * filename, const char * message ){ myFile = NULL; #endif } -#if !USE_CHECKPOINTING +#if !USE_MPROTECT_SNAPSHOT static ucontext_t savedSnapshotContext; static ucontext_t savedUserSnapshotContext; static snapshot_id snapshotid = 0; #endif /* Initialize snapshot data structure */ -#if USE_CHECKPOINTING +#if USE_MPROTECT_SNAPSHOT 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); @@ -62,7 +62,7 @@ void initSnapShotRecord(unsigned int numbackingpages, unsigned int numsnapshots, #endif //nothing to initialize for the fork based snapshotting. void HandlePF( int sig, siginfo_t *si, void * unused){ -#if USE_CHECKPOINTING +#if USE_MPROTECT_SNAPSHOT if( si->si_code == SEGV_MAPERR ){ printf("Real Fault at %p\n", si->si_addr); exit( EXIT_FAILURE ); @@ -101,7 +101,7 @@ void * PageAlignAddressUpward(void * addr) { extern "C" { #endif void createSharedLibrary(){ -#if !USE_CHECKPOINTING +#if !USE_MPROTECT_SNAPSHOT //step 1. create shared memory. if( sTheRecord ) return; int fd = shm_open( "/ModelChecker-Snapshotter", O_RDWR | O_CREAT, 0777 ); //universal permissions. @@ -121,7 +121,7 @@ extern "C" { } #endif void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, unsigned int numheappages, MyFuncPtr entryPoint){ -#if USE_CHECKPOINTING +#if USE_MPROTECT_SNAPSHOT /* Setup a stack for our signal handler.... */ stack_t ss; ss.ss_sp = MYMALLOC(SIGSTACKSIZE); @@ -214,7 +214,7 @@ void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots } /* This function assumes that addr is page aligned */ void addMemoryRegionToSnapShot( void * addr, unsigned int numPages) { -#if USE_CHECKPOINTING +#if USE_MPROTECT_SNAPSHOT unsigned int memoryregion=snapshotrecord->lastRegion++; if (memoryregion==snapshotrecord->maxRegions) { printf("Exceeded supported number of memory regions!\n"); @@ -227,7 +227,7 @@ void addMemoryRegionToSnapShot( void * addr, unsigned int numPages) { } //take snapshot snapshot_id takeSnapshot( ){ -#if USE_CHECKPOINTING +#if USE_MPROTECT_SNAPSHOT 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"); @@ -249,7 +249,7 @@ snapshot_id takeSnapshot( ){ #endif } void rollBack( snapshot_id theID ){ -#if USE_CHECKPOINTING +#if USE_MPROTECT_SNAPSHOT std::map< void *, bool, std::less< void * >, MyAlloc< std::pair< const void *, bool > > > 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 ){ @@ -288,7 +288,7 @@ void rollBack( snapshot_id theID ){ } void finalize(){ -#if !USE_CHECKPOINTING +#if !USE_MPROTECT_SNAPSHOT sTheRecord->mbFinalize = true; #endif } diff --git a/snapshot.h b/snapshot.h index 819ea0a..53f97ba 100644 --- a/snapshot.h +++ b/snapshot.h @@ -1,7 +1,11 @@ #ifndef _SNAPSHOT_H #define _SNAPSHOT_H #define PAGESIZE 4096 -#define USE_CHECKPOINTING 1 + +/* If USE_MPROTECT_SNAPSHOT=1, then snapshot by using mmap() and mprotect() + If USE_MPROTECT_SNAPSHOT=0, then snapshot by using fork() */ +#define USE_MPROTECT_SNAPSHOT 1 + /* Size of signal stack */ #define SIGSTACKSIZE 16384 diff --git a/snapshotimp.h b/snapshotimp.h index 2d18b94..8d935f2 100644 --- a/snapshotimp.h +++ b/snapshotimp.h @@ -10,7 +10,7 @@ #define SHARED_MEMORY_DEFAULT ( 100 * ( 1 << 20 ) ) // 100mb for the shared memory #define STACK_SIZE_DEFAULT ( ( 1 << 20 ) * 20 ) //20 mb out of the above 100 mb for my stack. -#if USE_CHECKPOINTING +#if USE_MPROTECT_SNAPSHOT //Each snapshotrecord lists the firstbackingpage that must be written to revert to that snapshot struct SnapShotRecord { unsigned int firstBackingPage;