snapshot: remove duplicate definition of finalize()
[c11tester.git] / snapshotimp.h
1 #ifndef _SNAPSHOTIMP_H
2 #define _SNAPSHOTIMP_H
3 #include "snapshot.h"
4 #include <iostream>
5 #include <inttypes.h>
6 #include <fcntl.h>
7 #include <sys/mman.h>
8 #include <sys/types.h>
9 #include <csignal>
10 #define SHARED_MEMORY_DEFAULT ( 100 * ( 1 << 20 ) ) // 100mb for the shared memory
11 #define STACK_SIZE_DEFAULT  ( ( 1 << 20 ) * 20 ) //20 mb out of the above 100 mb for my stack.
12
13 #if USE_MPROTECT_SNAPSHOT
14 //Each snapshotrecord lists the firstbackingpage that must be written to revert to that snapshot
15 struct SnapShotRecord {
16   unsigned int firstBackingPage;
17 };
18
19 //Backing store page struct
20 struct SnapShotPage {
21   char data[PAGESIZE];
22 };
23
24 //List the base address of the corresponding page in the backing store so we know where to copy it to
25 struct BackingPageRecord {
26   void * basePtrOfPage;
27 };
28
29 //Stuct for each memory region
30 struct MemoryRegion {
31   void * basePtr; //base of memory region
32   int sizeInPages; //size of memory region in pages
33 };
34
35 //Primary struct for snapshotting system....
36 struct SnapShot {
37   struct MemoryRegion * regionsToSnapShot; //This pointer references an array of memory regions to snapshot
38   struct SnapShotPage * backingStore; //This pointer references an array of snapshotpage's that form the backing store
39   void * backingStoreBasePtr; //This pointer references an array of snapshotpage's that form the backing store
40   struct BackingPageRecord * backingRecords; //This pointer references an array of backingpagerecord's (same number of elements as backingstore
41   struct SnapShotRecord * snapShots; //This pointer references the snapshot array
42   
43   unsigned int lastSnapShot; //Stores the next snapshot record we should use
44   unsigned int lastBackingPage; //Stores the next backingpage we should use
45   unsigned int lastRegion; //Stores the next memory region to be used
46
47   unsigned int maxRegions; //Stores the max number of memory regions we support
48   unsigned int maxBackingPages; //Stores the total number of backing pages
49   unsigned int maxSnapShots; //Stores the total number of snapshots we allow
50 };
51
52 //Global reference to snapshot data structure
53 extern struct SnapShot * snapshotrecord;
54 void * ReturnPageAlignedAddress( void *);
55 void * PageAlignAddressUpward( void *);
56 #else
57 struct Snapshot_t{
58 char *mSharedMemoryBase;
59 char *mStackBase;
60 size_t mStackSize;
61 snapshot_id mIDToRollback;
62 ucontext_t mContextToRollback;
63 snapshot_id currSnapShotID;
64 volatile bool mbFinalize;
65 };
66 extern struct Snapshot_t * sTheRecord;
67 #endif
68 #endif