snapshot: change 'struct SnapShotPage' to a simple typedef
authorBrian Norris <banorris@uci.edu>
Thu, 3 Jan 2013 00:41:35 +0000 (16:41 -0800)
committerBrian Norris <banorris@uci.edu>
Thu, 3 Jan 2013 03:12:02 +0000 (19:12 -0800)
The struct SnapShotPage was being used improperly; it was accessed as
simply an array of data, instead of explicitly accessing its member
variable (which itself was an array). So just make this more
straightforward as a typedef'd array.

This also corrects a pointer cast to use (void *) when appropriate.

snapshot.cc
snapshotimp.h

index 5ac9b46c92a43b402938167dc7eb8670322259c7..5cb920b1d156427c077b5c68ab942163fe926dc9 100644 (file)
@@ -66,9 +66,9 @@ static void initSnapShotRecord(unsigned int numbackingpages, unsigned int numsna
 {
        snapshotrecord = (struct SnapShot *)model_malloc(sizeof(struct SnapShot));
        snapshotrecord->regionsToSnapShot = (struct MemoryRegion *)model_malloc(sizeof(struct MemoryRegion) * nummemoryregions);
-       snapshotrecord->backingStoreBasePtr = (struct SnapShotPage *)model_malloc(sizeof(struct SnapShotPage) * (numbackingpages + 1));
+       snapshotrecord->backingStoreBasePtr = (void *)model_malloc(sizeof(snapshot_page_t) * (numbackingpages + 1));
        //Page align the backingstorepages
-       snapshotrecord->backingStore = (struct SnapShotPage *)PageAlignAddressUpward(snapshotrecord->backingStoreBasePtr);
+       snapshotrecord->backingStore = (snapshot_page_t *)PageAlignAddressUpward(snapshotrecord->backingStoreBasePtr);
        snapshotrecord->backingRecords = (struct BackingPageRecord *)model_malloc(sizeof(struct BackingPageRecord) * numbackingpages);
        snapshotrecord->snapShots = (struct SnapShotRecord *)model_malloc(sizeof(struct SnapShotRecord) * numsnapshots);
        snapshotrecord->lastSnapShot = 0;
@@ -100,11 +100,11 @@ static void HandlePF(int sig, siginfo_t *si, void *unused)
        }
 
        //copy page
-       memcpy(&(snapshotrecord->backingStore[backingpage]), addr, sizeof(struct SnapShotPage));
+       memcpy(&(snapshotrecord->backingStore[backingpage]), addr, sizeof(snapshot_page_t));
        //remember where to copy page back to
        snapshotrecord->backingRecords[backingpage].basePtrOfPage = addr;
        //set protection to read/write
-       if (mprotect(addr, sizeof(struct SnapShotPage), PROT_READ | PROT_WRITE)) {
+       if (mprotect(addr, sizeof(snapshot_page_t), PROT_READ | PROT_WRITE)) {
                perror("mprotect");
                // Handle error by quitting?
        }
@@ -270,7 +270,7 @@ 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) {
+               if (mprotect(snapshotrecord->regionsToSnapShot[region].basePtr, snapshotrecord->regionsToSnapShot[region].sizeInPages * sizeof(snapshot_page_t), PROT_READ) == -1) {
                        perror("mprotect");
                        model_print("Failed to mprotect inside of takeSnapShot\n");
                        exit(EXIT_FAILURE);
@@ -299,7 +299,7 @@ void rollBack(snapshot_id theID)
 #if USE_MPROTECT_SNAPSHOT == 2
        if (snapshotrecord->lastSnapShot == (theID + 1)) {
                for (unsigned int page = snapshotrecord->snapShots[theID].firstBackingPage; page < snapshotrecord->lastBackingPage; page++) {
-                       memcpy(snapshotrecord->backingRecords[page].basePtrOfPage, &snapshotrecord->backingStore[page], sizeof(struct SnapShotPage));
+                       memcpy(snapshotrecord->backingRecords[page].basePtrOfPage, &snapshotrecord->backingStore[page], sizeof(snapshot_page_t));
                }
                return;
        }
@@ -308,7 +308,7 @@ void rollBack(snapshot_id theID)
 #if USE_MPROTECT_SNAPSHOT
        HashTable< void *, bool, uintptr_t, 4, model_malloc, model_calloc, model_free> 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 (mprotect(snapshotrecord->regionsToSnapShot[region].basePtr, snapshotrecord->regionsToSnapShot[region].sizeInPages * sizeof(snapshot_page_t), PROT_READ | PROT_WRITE) == -1) {
                        perror("mprotect");
                        model_print("Failed to mprotect inside of takeSnapShot\n");
                        exit(EXIT_FAILURE);
@@ -317,7 +317,7 @@ void rollBack(snapshot_id theID)
        for (unsigned int page = snapshotrecord->snapShots[theID].firstBackingPage; page < snapshotrecord->lastBackingPage; page++) {
                if (!duplicateMap.contains(snapshotrecord->backingRecords[page].basePtrOfPage)) {
                        duplicateMap.put(snapshotrecord->backingRecords[page].basePtrOfPage, true);
-                       memcpy(snapshotrecord->backingRecords[page].basePtrOfPage, &snapshotrecord->backingStore[page], sizeof(struct SnapShotPage));
+                       memcpy(snapshotrecord->backingRecords[page].basePtrOfPage, &snapshotrecord->backingStore[page], sizeof(snapshot_page_t));
                }
        }
        snapshotrecord->lastSnapShot = theID;
index fbff35f42470e8d2604f0236690af2773c6c29dc..3999477a8e675174f204a4d3e47b213a1a5d5b8a 100644 (file)
@@ -18,10 +18,8 @@ struct SnapShotRecord {
        unsigned int firstBackingPage;
 };
 
-//Backing store page struct
-struct SnapShotPage {
-       char data[PAGESIZE];
-};
+/** @brief Backing store page */
+typedef unsigned char snapshot_page_t[PAGESIZE];
 
 //List the base address of the corresponding page in the backing store so we know where to copy it to
 struct BackingPageRecord {
@@ -37,7 +35,7 @@ struct MemoryRegion {
 //Primary struct for snapshotting system....
 struct SnapShot {
        struct MemoryRegion *regionsToSnapShot; //This pointer references an array of memory regions to snapshot
-       struct SnapShotPage *backingStore; //This pointer references an array of snapshotpage's that form the backing store
+       snapshot_page_t *backingStore; //This pointer references an array of snapshotpage's that form the backing store
        void *backingStoreBasePtr; //This pointer references an array of snapshotpage's that form the backing store
        struct BackingPageRecord *backingRecords; //This pointer references an array of backingpagerecord's (same number of elements as backingstore
        struct SnapShotRecord *snapShots; //This pointer references the snapshot array