From d5d43e044d16335a3a865a8c9f5aea5cbad73360 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 11 May 2019 23:10:42 -0700 Subject: 5157 Support allocating more than 0x01000000 bytes (8MB) to a segment in the VM. --- subx/012elf.cc | 4 +++- subx/020syscalls.cc | 16 +++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'subx') diff --git a/subx/012elf.cc b/subx/012elf.cc index 2fea60db..0fa9d793 100644 --- a/subx/012elf.cc +++ b/subx/012elf.cc @@ -149,7 +149,9 @@ void load_segment_from_program_header(uint8_t* elf_contents, int segment_index, // Once we do, we can go up to 0xc0000000; higher addresses are reserved for // the Linux kernel. const int CODE_SEGMENT = 0x09000000; -const int DATA_SEGMENT = 0x0a000000; +const int DATA_SEGMENT = 0x0a000000; +const int START_HEAP = 0x0b000000; +const int END_HEAP = 0x7d000000; const int STACK_SEGMENT = 0x7d000000; const int AFTER_STACK = 0x7e000000; const int ARGV_DATA_SEGMENT = 0x7f000000; diff --git a/subx/020syscalls.cc b/subx/020syscalls.cc index 444c9fd5..eb8ebcce 100644 --- a/subx/020syscalls.cc +++ b/subx/020syscalls.cc @@ -111,21 +111,19 @@ void check_mode(int reg) { :(before "End Globals") // Very primitive/fixed/insecure mmap segments for now. -// For now we avoid addresses with the most significant bit set; SubX doesn't -// support unsigned comparison yet (https://github.com/akkartik/mu/issues/30) -// Once we do, we can go up to 0xc0000000; higher addresses are reserved for -// the Linux kernel. -uint32_t Next_segment = 0x7c000000; +uint32_t Segments_allocated_above = END_HEAP; const uint32_t SPACE_FOR_SEGMENT = 0x01000000; :(code) +// always allocate multiples of the segment size uint32_t new_segment(uint32_t length) { - uint32_t result = Next_segment; - Mem.push_back(vma(Next_segment, Next_segment+length)); - Next_segment -= SPACE_FOR_SEGMENT; - if (Next_segment <= DATA_SEGMENT) { + assert(length > 0); + uint32_t result = (Segments_allocated_above - length) & 0xff000000; + if (result <= START_HEAP) { raise << "Allocated too many segments; the VM ran out of memory. " << "Maybe SPACE_FOR_SEGMENT can be smaller?\n" << end(); exit(1); } + Mem.push_back(vma(result, result+length)); + Segments_allocated_above = result; return result; } -- cgit 1.4.1-2-gfad0