"Checkpointing" is a generic name for either method. USE_MPROTECT_SNAPSHOT is a
more descriptive name.
#include "snapshotimp.h"
#include <stdio.h>
#include <dlfcn.h>
#include "snapshotimp.h"
#include <stdio.h>
#include <dlfcn.h>
+#if !USE_MPROTECT_SNAPSHOT
static mspace sStaticSpace = NULL;
#endif
void *MYMALLOC(size_t size) {
static mspace sStaticSpace = NULL;
#endif
void *MYMALLOC(size_t size) {
+#if USE_MPROTECT_SNAPSHOT
static void *(*mallocp)(size_t size);
char *error;
void *ptr;
static void *(*mallocp)(size_t size);
char *error;
void *ptr;
}
void MYFREE(void *ptr) {
}
void MYFREE(void *ptr) {
+#if USE_MPROTECT_SNAPSHOT
static void (*freep)(void *);
char *error;
static void (*freep)(void *);
char *error;
//extern declaration definition
#define FAILURE(mesg) { printf("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit( -1 ); }
//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_MPROTECT_SNAPSHOT
struct SnapShot * snapshotrecord = NULL;
struct Snapshot_t * sTheRecord = NULL;
#else
struct SnapShot * snapshotrecord = NULL;
struct Snapshot_t * sTheRecord = NULL;
#else
+#if !USE_MPROTECT_SNAPSHOT
static ucontext_t savedSnapshotContext;
static ucontext_t savedUserSnapshotContext;
static snapshot_id snapshotid = 0;
#endif
/* Initialize snapshot data structure */
static ucontext_t savedSnapshotContext;
static ucontext_t savedUserSnapshotContext;
static snapshot_id snapshotid = 0;
#endif
/* Initialize snapshot data structure */
+#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);
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);
#endif //nothing to initialize for the fork based snapshotting.
void HandlePF( int sig, siginfo_t *si, void * unused){
#endif //nothing to initialize for the fork based snapshotting.
void HandlePF( int sig, siginfo_t *si, void * unused){
+#if USE_MPROTECT_SNAPSHOT
if( si->si_code == SEGV_MAPERR ){
printf("Real Fault at %p\n", si->si_addr);
exit( EXIT_FAILURE );
if( si->si_code == SEGV_MAPERR ){
printf("Real Fault at %p\n", si->si_addr);
exit( EXIT_FAILURE );
extern "C" {
#endif
void createSharedLibrary(){
extern "C" {
#endif
void createSharedLibrary(){
+#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.
//step 1. create shared memory.
if( sTheRecord ) return;
int fd = shm_open( "/ModelChecker-Snapshotter", O_RDWR | O_CREAT, 0777 ); //universal permissions.
}
#endif
void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, unsigned int numheappages, MyFuncPtr entryPoint){
}
#endif
void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, unsigned int numheappages, MyFuncPtr entryPoint){
+#if USE_MPROTECT_SNAPSHOT
/* Setup a stack for our signal handler.... */
stack_t ss;
ss.ss_sp = MYMALLOC(SIGSTACKSIZE);
/* Setup a stack for our signal handler.... */
stack_t ss;
ss.ss_sp = MYMALLOC(SIGSTACKSIZE);
}
/* This function assumes that addr is page aligned */
void addMemoryRegionToSnapShot( void * addr, unsigned int numPages) {
}
/* This function assumes that addr is page aligned */
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");
unsigned int memoryregion=snapshotrecord->lastRegion++;
if (memoryregion==snapshotrecord->maxRegions) {
printf("Exceeded supported number of memory regions!\n");
}
//take snapshot
snapshot_id takeSnapshot( ){
}
//take snapshot
snapshot_id takeSnapshot( ){
+#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");
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");
#endif
}
void rollBack( snapshot_id theID ){
#endif
}
void rollBack( snapshot_id theID ){
+#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 ){
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 ){
+#if !USE_MPROTECT_SNAPSHOT
sTheRecord->mbFinalize = true;
#endif
}
sTheRecord->mbFinalize = true;
#endif
}
#ifndef _SNAPSHOT_H
#define _SNAPSHOT_H
#define PAGESIZE 4096
#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
/* Size of signal stack */
#define SIGSTACKSIZE 16384
#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.
#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_MPROTECT_SNAPSHOT
//Each snapshotrecord lists the firstbackingpage that must be written to revert to that snapshot
struct SnapShotRecord {
unsigned int firstBackingPage;
//Each snapshotrecord lists the firstbackingpage that must be written to revert to that snapshot
struct SnapShotRecord {
unsigned int firstBackingPage;