snapshot: change 'struct SnapShotPage' to a simple typedef
[model-checker.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 #define SHARED_MEMORY_DEFAULT  (100 * ((size_t)1 << 20)) // 100mb for the shared memory
13 #define STACK_SIZE_DEFAULT      (((size_t)1 << 20) * 20)  // 20 mb out of the above 100 mb for my stack
14
15 #if USE_MPROTECT_SNAPSHOT
16 //Each snapshotrecord lists the firstbackingpage that must be written to revert to that snapshot
17 struct SnapShotRecord {
18         unsigned int firstBackingPage;
19 };
20
21 /** @brief Backing store page */
22 typedef unsigned char snapshot_page_t[PAGESIZE];
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         snapshot_page_t *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 #else
53
54 #include <ucontext.h>
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__ */