From bccaa72227a5d12932b1d34ae045ffc5689a76e8 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Thu, 4 Oct 2018 23:02:00 -0700 Subject: 4661 Make segment management a little more consistent between initial segments and add-on segments (using `mmap`). --- subx/012elf.cc | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'subx/012elf.cc') diff --git a/subx/012elf.cc b/subx/012elf.cc index 85eb406a..2e10246e 100644 --- a/subx/012elf.cc +++ b/subx/012elf.cc @@ -80,7 +80,7 @@ void load_elf_contents(uint8_t* elf_contents, size_t size, int argc, char* argv[ assert(overlap.find(argv_data) == overlap.end()); // don't bother comparing ARGV and STACK write_mem_u8(argv_data, argv[i][j]); argv_data += sizeof(char); - assert(argv_data < ARGV_DATA_SEGMENT + SEGMENT_SIZE); + assert(argv_data < ARGV_DATA_SEGMENT + INITIAL_SEGMENT_SIZE); } } push(argc-/*skip 'subx_bin' and 'run'*/2); @@ -111,7 +111,7 @@ void load_segment_from_program_header(uint8_t* elf_contents, int segment_index, if (p_offset + p_filesz > size) raise << "Invalid binary; segment at offset " << offset << " is too large: wants to end at " << p_offset+p_filesz << " but the file ends at " << size << '\n' << die(); - if (p_memsz > INITIAL_SEGMENT_SIZE) { + if (p_memsz >= INITIAL_SEGMENT_SIZE) { raise << "Code segment too small for SubX; for now please manually increase INITIAL_SEGMENT_SIZE.\n" << end(); return; } @@ -129,16 +129,14 @@ void load_segment_from_program_header(uint8_t* elf_contents, int segment_index, :(before "End Includes") // Very primitive/fixed/insecure ELF segments for now. -// code: 0x08048000 -> 0x08048fff -// data/heap: 0x08050000 -> 0x08050fff -// stack: 0x08060fff -> 0x08060000 (downward) -const int SEGMENT_SIZE = 0x1000; -const int CODE_START = 0x08048000; -const int DATA_SEGMENT = 0x08050000; -const int HEAP_SEGMENT = DATA_SEGMENT; -const int STACK_SEGMENT = 0x08060000; -const int AFTER_STACK = 0x08060ffc; // forget final word because of the off-by-one with INITIAL_SEGMENT_SIZE; -const int ARGV_DATA_SEGMENT = 0x08070000; +// code: 0x09000000 -> 0x09ffffff +// data/heap: 0x0a000000 -> 0x0affffff +// stack: 0x0b000ffc -> 0x0b000000 (downward) +const int CODE_SEGMENT = 0x09000000; +const int DATA_SEGMENT = 0x0a000000; +const int STACK_SEGMENT = 0x0b000000; +const int AFTER_STACK = 0x0b000ffc; // forget final word because of the off-by-one with INITIAL_SEGMENT_SIZE; +const int ARGV_DATA_SEGMENT = 0x0c000000; :(code) inline uint32_t u32_in(uint8_t* p) { return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; -- cgit 1.4.1-2-gfad0