#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
-#include "hashtable.h"
-#include <cstring>
-#include <cstdio>
-#include "snapshot.h"
-#include "snapshotimp.h"
-#include "mymemory.h"
-#include <fcntl.h>
-#include <assert.h>
-#include <pthread.h>
-#include <semaphore.h>
+#include <string.h>
#include <errno.h>
#include <sys/wait.h>
#include <ucontext.h>
+#include "hashtable.h"
+#include "snapshot.h"
+#include "snapshotimp.h"
+#include "mymemory.h"
#include "common.h"
-#define FAILURE(mesg) { printf("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit(EXIT_FAILURE); }
+#define FAILURE(mesg) { model_print("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit(EXIT_FAILURE); }
#ifdef CONFIG_SSDEBUG
-#define SSDEBUG printf
+#define SSDEBUG model_print
#else
#define SSDEBUG(...) do { } while (0)
#endif
/* extern declaration definition */
struct SnapShot * snapshotrecord = NULL;
+/** PageAlignedAdressUpdate return a page aligned address for the
+ * address being added as a side effect the numBytes are also changed.
+ */
+static void * PageAlignAddressUpward(void * addr) {
+ return (void *)((((uintptr_t)addr)+PAGESIZE-1)&~(PAGESIZE-1));
+}
+
#if !USE_MPROTECT_SNAPSHOT
/** @statics
* These variables are necessary because the stack is shared region and
#else /* USE_MPROTECT_SNAPSHOT */
-/** PageAlignedAdressUpdate return a page aligned address for the
- * address being added as a side effect the numBytes are also changed.
- */
-static void * PageAlignAddressUpward(void * addr) {
- return (void *)((((uintptr_t)addr)+PAGESIZE-1)&~(PAGESIZE-1));
-}
-
/** ReturnPageAlignedAddress returns a page aligned address for the
* address being added as a side effect the numBytes are also changed.
*/
*/
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);
+ model_print("Real Fault at %p\n", si->si_addr);
print_trace();
+ model_print("For debugging, place breakpoint at: %s:%d\n",
+ __FILE__, __LINE__);
exit( EXIT_FAILURE );
}
void* addr = ReturnPageAlignedAddress(si->si_addr);
unsigned int backingpage=snapshotrecord->lastBackingPage++; //Could run out of pages...
if (backingpage==snapshotrecord->maxBackingPages) {
- printf("Out of backing pages at %p\n", si->si_addr);
+ model_print("Out of backing pages at %p\n", si->si_addr);
exit( EXIT_FAILURE );
}
sa.sa_sigaction = HandlePF;
#ifdef MAC
if( sigaction( SIGBUS, &sa, NULL ) == -1 ){
- printf("SIGACTION CANNOT BE INSTALLED\n");
+ model_print("SIGACTION CANNOT BE INSTALLED\n");
exit(EXIT_FAILURE);
}
#endif
if( sigaction( SIGSEGV, &sa, NULL ) == -1 ){
- printf("SIGACTION CANNOT BE INSTALLED\n");
+ model_print("SIGACTION CANNOT BE INSTALLED\n");
exit(EXIT_FAILURE);
}
void *basemySpace = model_malloc((numheappages+1)*PAGESIZE);
void * pagealignedbase=PageAlignAddressUpward(basemySpace);
- snapshot_space = create_mspace_with_base(pagealignedbase, numheappages*PAGESIZE, 1 );
+ user_snapshot_space = create_mspace_with_base(pagealignedbase, numheappages * PAGESIZE, 1);
+ addMemoryRegionToSnapShot(pagealignedbase, numheappages);
+
+ void *base_model_snapshot_space = model_malloc((numheappages + 1) * PAGESIZE);
+ pagealignedbase = PageAlignAddressUpward(base_model_snapshot_space);
+ model_snapshot_space = create_mspace_with_base(pagealignedbase, numheappages * PAGESIZE, 1);
addMemoryRegionToSnapShot(pagealignedbase, numheappages);
+
entryPoint();
}
#else
if (!snapshotrecord)
createSharedMemory();
+ void *base_model_snapshot_space = malloc((numheappages + 1) * PAGESIZE);
+ void *pagealignedbase = PageAlignAddressUpward(base_model_snapshot_space);
+ model_snapshot_space = create_mspace_with_base(pagealignedbase, numheappages * PAGESIZE, 1);
+
//step 2 setup the stack context.
ucontext_t newContext;
getcontext( &newContext );
#if USE_MPROTECT_SNAPSHOT
unsigned int memoryregion=snapshotrecord->lastRegion++;
if (memoryregion==snapshotrecord->maxRegions) {
- printf("Exceeded supported number of memory regions!\n");
+ model_print("Exceeded supported number of memory regions!\n");
exit(EXIT_FAILURE);
}
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");
- printf("Failed to mprotect inside of takeSnapShot\n");
+ model_print("Failed to mprotect inside of takeSnapShot\n");
exit(EXIT_FAILURE);
}
}
unsigned int snapshot=snapshotrecord->lastSnapShot++;
if (snapshot==snapshotrecord->maxSnapShots) {
- printf("Out of snapshots\n");
+ model_print("Out of snapshots\n");
exit(EXIT_FAILURE);
}
snapshotrecord->snapShots[snapshot].firstBackingPage=snapshotrecord->lastBackingPage;
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 ){
perror("mprotect");
- printf("Failed to mprotect inside of takeSnapShot\n");
+ model_print("Failed to mprotect inside of takeSnapShot\n");
exit(EXIT_FAILURE);
}
}