{
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;
}
//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?
}
{
#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);
#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;
}
#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);
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;
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 {
//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