action: add NULL dereference assertion
[c11tester.git] / snapshot.cc
index 0c90da839912c59ff1b5db675efec367796328bc..e006189c44ba1741208183ea8cbddd222b381dfd 100644 (file)
 /* 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
@@ -48,13 +55,6 @@ static snapshot_id snapshotid = 0;
 
 #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.
  */
@@ -172,8 +172,14 @@ void initSnapshotLibrary(unsigned int numbackingpages,
 
        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
@@ -183,6 +189,10 @@ void initSnapshotLibrary(unsigned int numbackingpages,
        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 );