- //step 1. create shared memory.
- if( sTheRecord ) return;
- int fd = shm_open( "/ModelChecker-Snapshotter", O_RDWR | O_CREAT, 0777 ); //universal permissions.
- if( -1 == fd ) FAILURE("shm_open");
- if( -1 == ftruncate( fd, ( size_t )SHARED_MEMORY_DEFAULT + ( size_t )STACK_SIZE_DEFAULT ) ) FAILURE( "ftruncate" );
- char * memMapBase = ( char * ) mmap( 0, ( size_t )SHARED_MEMORY_DEFAULT + ( size_t )STACK_SIZE_DEFAULT, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
- if( MAP_FAILED == memMapBase ) FAILURE("mmap");
- sTheRecord = ( struct Snapshot_t * )memMapBase;
- sTheRecord->mSharedMemoryBase = memMapBase + sizeof( struct Snapshot_t );
- sTheRecord->mStackBase = ( char * )memMapBase + ( size_t )SHARED_MEMORY_DEFAULT;
- sTheRecord->mStackSize = STACK_SIZE_DEFAULT;
- sTheRecord->mIDToRollback = -1;
- sTheRecord->currSnapShotID = 0;
- sTheRecord->mbFinalize = false;
-#endif
- }
-#ifdef __cplusplus
+void createSharedMemory(){
+ //step 1. create shared memory.
+ void * memMapBase = mmap( 0, SHARED_MEMORY_DEFAULT + STACK_SIZE_DEFAULT, PROT_READ | PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0 );
+ if( MAP_FAILED == memMapBase )
+ FAILURE("mmap");
+
+ //Setup snapshot record at top of free region
+ snapshotrecord = ( struct SnapShot * )memMapBase;
+ snapshotrecord->mSharedMemoryBase = (void *)((uintptr_t)memMapBase + sizeof(struct SnapShot));
+ snapshotrecord->mStackBase = (void *)((uintptr_t)memMapBase + SHARED_MEMORY_DEFAULT);
+ snapshotrecord->mStackSize = STACK_SIZE_DEFAULT;
+ snapshotrecord->mIDToRollback = -1;
+ snapshotrecord->currSnapShotID = 0;