snapshot: rename USE_CHECKPOINTING to USE_MPROTECT_SNAPSHOT
authorBrian Norris <banorris@uci.edu>
Wed, 30 May 2012 06:20:37 +0000 (23:20 -0700)
committerBrian Norris <banorris@uci.edu>
Wed, 30 May 2012 06:20:37 +0000 (23:20 -0700)
"Checkpointing" is a generic name for either method. USE_MPROTECT_SNAPSHOT is a
more descriptive name.

mymemory.cc
snapshot.cc
snapshot.h
snapshotimp.h

index 11542bfa26af49c0b1f93c23841f6138b0354865..80c1b953ff6855e24d058ddffa6589f29a6dda1f 100644 (file)
@@ -3,12 +3,12 @@
 #include "snapshotimp.h"
 #include <stdio.h>
 #include <dlfcn.h>
-#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;
 
index 01e720113077ace8833d15a8b22849c6ce01c777..ff9fd56039bc6e01782bc43770c800fff3f2d6d3 100644 (file)
@@ -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; region<snapshotrecord->lastRegion;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; region<snapshotrecord->lastRegion;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
 }
index 819ea0a41b79ca25782b50e9f109df68b35dc041..53f97ba35c7020c2911b2cd8621f6dbfbe80c0cf 100644 (file)
@@ -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
 
index 2d18b94dc659e4fe4fb3d42c226e34f30d0878ea..8d935f238b81e3d43cf5ea1d7fdac07f583bc470 100644 (file)
@@ -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;