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