1 #include "snapshot-interface.h"
16 #define MYBINARYNAME "model"
17 #define MYLIBRARYNAME "libmodel.so"
18 #define MAPFILE "/proc/self/maps"
20 SnapshotStack * snapshotObject;
23 /** The SnapshotGlobalSegments function computes the memory regions
24 * that may contain globals and then configures the snapshotting
25 * library to snapshot them.
27 static void SnapshotGlobalSegments(){
29 char buf[9000], execname[100];
32 sprintf(execname, "vmmap -interleaved %d", pid);
33 map=popen(execname, "r");
40 /* Wait for correct part */
41 while (fgets(buf, sizeof(buf), map)) {
42 if (strstr(buf, "==== regions for process"))
46 while (fgets(buf, sizeof(buf), map)) {
47 char regionname[200] = "";
55 //Skip out at the end of the section
59 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);
61 if (w == 'w' && (strstr(regionname, MYBINARYNAME) || strstr(regionname, MYLIBRARYNAME))) {
62 size_t len = ((uintptr_t)end - (uintptr_t)begin) / PAGESIZE;
64 addMemoryRegionToSnapShot(begin, len);
70 /** The SnapshotGlobalSegments function computes the memory regions
71 * that may contain globals and then configures the snapshotting
72 * library to snapshot them.
74 static void SnapshotGlobalSegments(){
78 map = fopen(MAPFILE, "r");
83 while (fgets(buf, sizeof(buf), map)) {
84 char regionname[200] = "";
88 sscanf(buf, "%p-%p %c%c%c%c %*x %*x:%*x %*u %200s\n", &begin, &end, &r, &w, &x, &p, regionname);
89 if (w == 'w' && (strstr(regionname, MYBINARYNAME) || strstr(regionname, MYLIBRARYNAME))) {
90 size_t len = ((uintptr_t)end - (uintptr_t)begin) / PAGESIZE;
92 addMemoryRegionToSnapShot(begin, len);
93 DEBUG("%55s: %18p - %18p\t%c%c%c%c\n", regionname, begin, end, r, w, x, p);
100 SnapshotStack::SnapshotStack(){
101 SnapshotGlobalSegments();
105 SnapshotStack::~SnapshotStack(){
109 /** This method returns to the last snapshot before the inputted
110 * sequence number. This function must be called from the model
111 * checking thread and not from a snapshotted stack.
112 * @param seqindex is the sequence number to rollback before.
113 * @return is the sequence number we actually rolled back to.
115 int SnapshotStack::backTrackBeforeStep(int seqindex) {
117 if (stack->index<=seqindex) {
119 rollBack(stack->snapshotid);
122 struct stackEntry *tmp=stack;
128 /** This method takes a snapshot at the given sequence number. */
129 void SnapshotStack::snapshotStep(int seqindex) {
130 struct stackEntry *tmp=(struct stackEntry *)model_malloc(sizeof(struct stackEntry));
133 tmp->snapshotid=takeSnapshot();