1 #include "snapshot-interface.h"
17 #define MYBINARYNAME "model"
18 #define MYLIBRARYNAME "libmodel.so"
19 #define MAPFILE_FORMAT "/proc/%d/maps"
21 SnapshotStack * snapshotObject;
24 /** The SnapshotGlobalSegments function computes the memory regions
25 * that may contain globals and then configures the snapshotting
26 * library to snapshot them.
29 void SnapshotGlobalSegments(){
31 char buf[9000], execname[100];
34 sprintf(execname, "vmmap -interleaved %d", pid);
35 map=popen(execname, "r");
42 /* Wait for correct part */
43 while (fgets(buf, sizeof(buf), map)) {
44 if (strstr(buf, "==== regions for process"))
48 while (fgets(buf, sizeof(buf), map)) {
49 char regionname[200] = "";
57 //Skip out at the end of the section
61 sscanf(buf, "%22s %p-%p [%5dK] %c%c%c/%c%c%c SM=%3s %200s\n", &type, &begin, &end, &size, &r, &w, &x, &mr, &mw, &mx, smstr, regionname);
63 if (w == 'w' && (strstr(regionname, MYBINARYNAME) || strstr(regionname, MYLIBRARYNAME))) {
64 size_t len = ((uintptr_t)end - (uintptr_t)begin) / PAGESIZE;
66 addMemoryRegionToSnapShot(begin, len);
68 DEBUG("%45s: %18p - %18p\t%c%c%c%c\n", regionname, begin, end, r, w, x, p);
74 /** The SnapshotGlobalSegments function computes the memory regions
75 * that may contain globals and then configures the snapshotting
76 * library to snapshot them.
78 void SnapshotGlobalSegments(){
80 char buf[9000], filename[100];
83 sprintf(filename, MAPFILE_FORMAT, pid);
84 map = fopen(filename, "r");
89 while (fgets(buf, sizeof(buf), map)) {
90 char regionname[200] = "";
94 sscanf(buf, "%p-%p %c%c%c%c %*x %*x:%*x %*u %200s\n", &begin, &end, &r, &w, &x, &p, regionname);
95 if (w == 'w' && (strstr(regionname, MYBINARYNAME) || strstr(regionname, MYLIBRARYNAME))) {
96 size_t len = ((uintptr_t)end - (uintptr_t)begin) / PAGESIZE;
98 addMemoryRegionToSnapShot(begin, len);
99 DEBUG("%45s: %18p - %18p\t%c%c%c%c\n", regionname, begin, end, r, w, x, p);
106 SnapshotStack::SnapshotStack(){
107 SnapshotGlobalSegments();
111 SnapshotStack::~SnapshotStack(){
115 /** This method returns to the last snapshot before the inputted
116 * sequence number. This function must be called from the model
117 * checking thread and not from a snapshotted stack.
118 * @param seqindex is the sequence number to rollback before.
119 * @return is the sequence number we actually rolled back to.
122 int SnapshotStack::backTrackBeforeStep(int seqindex) {
124 if (stack->index<=seqindex) {
126 rollBack(stack->snapshotid);
129 struct stackEntry *tmp=stack;
135 /** This method takes a snapshot at the given sequence number.
138 void SnapshotStack::snapshotStep(int seqindex) {
139 struct stackEntry *tmp=(struct stackEntry *)MYMALLOC(sizeof(struct stackEntry));
142 tmp->snapshotid=takeSnapshot();