-#include <cassert>
-
-/*This looks like it might leak memory... Subramanian should fix this. */
-
-typedef std::basic_stringstream< char, std::char_traits< char >, MyAlloc< char > > MyStringStream;
-std::vector< MyString, MyAlloc< MyString> > splitString( MyString input, char delim ){
- std::vector< MyString, MyAlloc< MyString > > splits;
- MyStringStream ss( input );
- MyString item;
- while( std::getline( ss, item, delim ) ){
- splits.push_back( item );
- }
- return splits;
+#include <inttypes.h>
+#include <vector>
+
+#include "snapshot-interface.h"
+#include "snapshot.h"
+#include "common.h"
+#include "mymemory.h"
+
+/* MYBINARYNAME only works because our pathname usually includes 'model' (e.g.,
+ * /.../model-checker/test/userprog.o) */
+#define MYBINARYNAME "model"
+#define MYLIBRARYNAME "libmodel.so"
+#define MAPFILE "/proc/self/maps"
+
+struct snapshot_entry {
+ snapshot_entry(snapshot_id id, int idx) : snapshotid(id), index(idx) { }
+ snapshot_id snapshotid;
+ int index;
+ MEMALLOC
+};
+
+class SnapshotStack {
+ public:
+ int backTrackBeforeStep(int seq_index);
+ void snapshotStep(int seq_index);
+
+ MEMALLOC
+ private:
+ std::vector<struct snapshot_entry, ModelAlloc<struct snapshot_entry> > stack;
+};
+
+static SnapshotStack *snap_stack;
+
+#ifdef MAC
+/** The SnapshotGlobalSegments function computes the memory regions
+ * that may contain globals and then configures the snapshotting
+ * library to snapshot them.
+ */
+static void SnapshotGlobalSegments()
+{
+ int pid = getpid();
+ char buf[9000], execname[100];
+ FILE *map;
+
+ sprintf(execname, "vmmap -interleaved %d", pid);
+ map = popen(execname, "r");
+
+ if (!map) {
+ perror("popen");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Wait for correct part */
+ while (fgets(buf, sizeof(buf), map)) {
+ if (strstr(buf, "==== regions for process"))
+ break;
+ }
+
+ while (fgets(buf, sizeof(buf), map)) {
+ char regionname[200] = "";
+ char type[23];
+ char smstr[23];
+ char r, w, x;
+ char mr, mw, mx;
+ int size;
+ void *begin, *end;
+
+ //Skip out at the end of the section
+ if (buf[0] == '\n')
+ break;
+
+ 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);
+
+ if (w == 'w' && (strstr(regionname, MYBINARYNAME) || strstr(regionname, MYLIBRARYNAME))) {
+ size_t len = ((uintptr_t)end - (uintptr_t)begin) / PAGESIZE;
+ if (len != 0)
+ snapshot_add_memory_region(begin, len);
+ }
+ }
+ pclose(map);