- initSnapShotRecord(numbackingpages, numsnapshots, nummemoryregions);
-
- // EVIL HACK: We need to make sure that calls into the HandlePF method don't cause dynamic links
- // The problem is that we end up protecting state in the dynamic linker...
- // Solution is to call our signal handler before we start protecting stuff...
-
- siginfo_t si;
- memset(&si, 0, sizeof(si));
- si.si_addr=ss.ss_sp;
- HandlePF(SIGSEGV, &si, NULL);
- snapshotrecord->lastBackingPage--; //remove the fake page we copied
-
- basemySpace=MYMALLOC((numheappages+1)*PAGESIZE);
- void * pagealignedbase=PageAlignAddressUpward(basemySpace);
- mySpace = create_mspace_with_base(pagealignedbase, numheappages*PAGESIZE, 1 );
- addMemoryRegionToSnapShot(pagealignedbase, numheappages);
- entryPoint();
-#else
-
- basemySpace=system_malloc((numheappages+1)*PAGESIZE);
- void * pagealignedbase=PageAlignAddressUpward(basemySpace);
- mySpace = create_mspace_with_base(pagealignedbase, numheappages*PAGESIZE, 1 );
- createSharedLibrary();
-
- //step 2 setup the stack context.
- ucontext_t newContext;
- getcontext( &newContext );
- newContext.uc_stack.ss_sp = sTheRecord->mStackBase;
- newContext.uc_stack.ss_size = STACK_SIZE_DEFAULT;
- makecontext( &newContext, entryPoint, 0 );
- /* switch to a new entryPoint context, on a new stack */
- swapcontext(&savedSnapshotContext, &newContext);
-
- //add the code to take a snapshot here...
- //to return to user process, do a second swapcontext...
- pid_t forkedID = 0;
- snapshotid = sTheRecord->currSnapShotID;
- bool swapContext = false;
- while( true ){
- sTheRecord->currSnapShotID=snapshotid+1;
- forkedID = fork();
- if( 0 == forkedID ){
- ucontext_t currentContext;
-#if 0
- int dbg = 0;
- while( !dbg );
-#endif
- if( swapContext )
- swapcontext( ¤tContext, &( sTheRecord->mContextToRollback ) );
- else{
- swapcontext( ¤tContext, &savedUserSnapshotContext );
- }
- } else {
- int status;
- int retVal;