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