From 4a99a6e0dd3000d8e595ec7b4b04f637e66ded6d Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 23 Nov 2018 00:21:41 -0800 Subject: 4761 Bugfix: I forgot about ELF segment offsets when implementing VMAs. Eventually segments grew large enough that I started seeing overlaps. --- subx/010---vm.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'subx/010---vm.cc') diff --git a/subx/010---vm.cc b/subx/010---vm.cc index 47b2c3da..7e5b8d79 100644 --- a/subx/010---vm.cc +++ b/subx/010---vm.cc @@ -112,9 +112,10 @@ SF = ZF = OF = false; //:: simulated RAM :(before "End Types") -const uint32_t INITIAL_SEGMENT_SIZE = 0x1000000 - 1; -// Subtract one just so we can start the first segment at address 1 without -// overflowing the first segment. Other segments will learn to adjust. +const uint32_t SEGMENT_ALIGNMENT = 0x1000000; +inline uint32_t align_upwards(uint32_t x, uint32_t align) { + return (x+align-1) & -(align); +} // Like in real-world Linux, we'll allocate RAM for our programs in disjoint // slabs called VMAs or Virtual Memory Areas. @@ -123,7 +124,7 @@ struct vma { uint32_t end; // exclusive vector _data; vma(uint32_t s, uint32_t e) :start(s), end(e) {} - vma(uint32_t s) :start(s), end(s+INITIAL_SEGMENT_SIZE) {} + vma(uint32_t s) :start(s), end(align_upwards(s+1, SEGMENT_ALIGNMENT)) {} bool match(uint32_t a) { return a >= start && a < end; } @@ -136,9 +137,7 @@ struct vma { if (_data.size() <= result_index) { const int align = 0x1000; uint32_t result_size = result_index + 1; // size needed for result_index to be valid - #define align_upwards(x, align) (((x)+(align)-1) & -(align)) uint32_t new_size = align_upwards(result_size, align); - #undef align_upwards // grow at least 2x to maintain some amortized complexity guarantees if (new_size < _data.size() * 2) new_size = _data.size() * 2; -- cgit 1.4.1-2-gfad0