about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-10-01 11:15:45 -0700
committerKartik Agaram <vc@akkartik.com>2018-10-01 11:28:46 -0700
commitdf39c0c8dee65a10dfc339a970a3beb4d0e481f3 (patch)
tree18113c438cc65bded12b87ac746e42160cad85ad /subx
parentca00f6b97c52262b39c28cccb76b52e059553f13 (diff)
downloadmu-df39c0c8dee65a10dfc339a970a3beb4d0e481f3.tar.gz
4635
Another sanity check.

We don't really have a clear big picture yet. But I've now slapped on checks
for all the issues I was worrying about.

A more rigorous solution would be some sort of interval tree. We'd also
need to track segments generated at translation time. We don't do that
so far.
Diffstat (limited to 'subx')
-rw-r--r--subx/010---vm.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/subx/010---vm.cc b/subx/010---vm.cc
index e2fab9fa..57e29433 100644
--- a/subx/010---vm.cc
+++ b/subx/010---vm.cc
@@ -118,17 +118,34 @@ struct vma {
   }
   void grow_until(uint32_t new_end_address) {
     if (new_end_address < end) return;
+    // Ugly: vma knows about the global Memory list of vmas
+    void sanity_check(uint32_t start, uint32_t end);
+    sanity_check(start, new_end_address);
     end = new_end_address;
     _data.resize(new_end_address - start);
   }
   // End vma Methods
 };
+:(code)
+void sanity_check(uint32_t start, uint32_t end) {
+  bool dup_found = false;
+  for (int i = 0;  i < SIZE(Mem);  ++i) {
+    const vma& curr = Mem.at(i);
+    if (curr.start == start) {
+      assert(!dup_found);
+      dup_found = true;
+    }
+    else if (curr.start > start) {
+      assert(curr.start > end);
+    }
+    else if (curr.start < start) {
+      assert(curr.end < start);
+    }
+  }
+}
 
 :(before "End Globals")
 // RAM is made of VMAs.
-//
-// We currently have zero tests for overlapping VMAs. Particularly after
-// growing segments.
 vector<vma> Mem;
 :(code)
 // The first 3 VMAs are special. When loading ELF binaries in later layers,