From: Brian Demsky Date: Thu, 24 May 2012 18:50:19 +0000 (-0700) Subject: factor page alignment into function call...place near existing call X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=7320a16b1a16bf1f803bc43856b24a94c0fb4c8e factor page alignment into function call...place near existing call --- diff --git a/snapshot.cc b/snapshot.cc index 83d22b4f..20980015 100644 --- a/snapshot.cc +++ b/snapshot.cc @@ -61,7 +61,7 @@ void initSnapShotRecord(unsigned int numbackingpages, unsigned int numsnapshots, snapshotrecord->regionsToSnapShot=( struct MemoryRegion * )MYMALLOC(sizeof(struct MemoryRegion)*nummemoryregions); snapshotrecord->backingStoreBasePtr= ( struct SnapShotPage * )MYMALLOC( sizeof( struct SnapShotPage ) * (numbackingpages + 1) ); //Page align the backingstorepages - snapshotrecord->backingStore=( struct SnapShotPage * )ReturnPageAlignedAddress((void*) ((uintptr_t)(snapshotrecord->backingStoreBasePtr)+sizeof(struct SnapShotPage)-1)); + snapshotrecord->backingStore=( struct SnapShotPage * )PageAlignAddressUpward(snapshotrecord->backingStoreBasePtr); snapshotrecord->backingRecords=( struct BackingPageRecord * )MYMALLOC(sizeof(struct BackingPageRecord)*numbackingpages); snapshotrecord->snapShots= ( struct SnapShotRecord * )MYMALLOC(sizeof(struct SnapShotRecord)*numsnapshots); snapshotrecord->lastSnapShot=0; @@ -103,6 +103,12 @@ void HandlePF( int sig, siginfo_t *si, void * unused){ void * ReturnPageAlignedAddress(void * addr) { return (void *)(((uintptr_t)addr)&~(PAGESIZE-1)); } + +//Return a page aligned address for the address being added +//as a side effect the numBytes are also changed. +void * PageAlignAddressUpward(void * addr) { + return (void *)((((uintptr_t)addr)+PAGESIZE-1)&~(PAGESIZE-1)); +} #ifdef __cplusplus extern "C" { #endif @@ -139,7 +145,7 @@ void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots initSnapShotRecord(numbackingpages, numsnapshots, nummemoryregions); basemySpace=MYMALLOC((numheappages+1)*PAGESIZE); - void * pagealignedbase=(void *)((((uintptr_t)basemySpace)+PAGESIZE-1)&~(PAGESIZE-1)); + void * pagealignedbase=PageAlignAddressUpward(basemySpace); mySpace = create_mspace_with_base(pagealignedbase, numheappages*PAGESIZE, 1 ); addMemoryRegionToSnapShot(pagealignedbase, numheappages); entryPoint(); diff --git a/snapshot.h b/snapshot.h index a0f2757d..4625c5d5 100644 --- a/snapshot.h +++ b/snapshot.h @@ -3,6 +3,7 @@ #define PAGESIZE 4096 #define USE_CHECKPOINTING 1 + typedef unsigned int snapshot_id; typedef void (*MyFuncPtr)(); void initSnapShotLibrary(unsigned int numbackingpages, unsigned int numsnapshots, unsigned int nummemoryregions, unsigned int numheappages, MyFuncPtr entryPoint); diff --git a/snapshotimp.h b/snapshotimp.h index 0f2d4b80..4991845c 100644 --- a/snapshotimp.h +++ b/snapshotimp.h @@ -52,6 +52,7 @@ struct SnapShot { //Global reference to snapshot data structure extern struct SnapShot * snapshotrecord; void * ReturnPageAlignedAddress( void *); +void * PageAlignAddressUpward( void *); #else struct Snapshot_t{ char *mSharedMemoryBase;