From 291ca5779e8f753f4b7d3590466ec6e6d603044e Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Sun, 3 Dec 2023 00:47:05 -0800 Subject: [PATCH] load_elf: set mem.heap_range so brk works --- src/openpower/decoder/isa/mem.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/openpower/decoder/isa/mem.py b/src/openpower/decoder/isa/mem.py index c4744b87..a2a84c53 100644 --- a/src/openpower/decoder/isa/mem.py +++ b/src/openpower/decoder/isa/mem.py @@ -1091,6 +1091,7 @@ def load_elf(mem, elf_file, args=(), env=(), stack_size=DEFAULT_INIT_STACK_SZ): if elf_file.header['e_type'] != 'ET_EXEC': raise NotImplementedError("dynamic binaries aren't implemented") fd = elf_file.stream.fileno() + heap_start = -1 for segment in elf_file.iter_segments(): if segment.header['p_type'] in ('PT_DYNAMIC', 'PT_INTERP'): raise NotImplementedError("dynamic binaries aren't implemented") @@ -1122,6 +1123,9 @@ def load_elf(mem, elf_file, args=(), env=(), stack_size=DEFAULT_INIT_STACK_SZ): # page-align, rounding up filesz_aligned = ( filesz + MMAP_PAGE_SIZE - 1) & ~(MMAP_PAGE_SIZE - 1) + # page-align, rounding up + memsz_aligned = ( + memsz + MMAP_PAGE_SIZE - 1) & ~(MMAP_PAGE_SIZE - 1) page_end_init_needed = filesz < memsz and filesz < filesz_aligned zero_pages_needed = memsz > filesz_aligned adj_prot = prot # adjust prot for initialization @@ -1142,6 +1146,7 @@ def load_elf(mem, elf_file, args=(), env=(), stack_size=DEFAULT_INIT_STACK_SZ): vaddr + filesz_aligned, memsz - filesz_aligned, prot, flags, fd=-1, offset=0, is_mmap2=False) raise_if_syscall_err(result) + heap_start = max(heap_start, vaddr + memsz_aligned) else: log("ignoring ELF segment of type " + segment.header['p_type']) # page-align stack_size, rounding up @@ -1163,6 +1168,9 @@ def load_elf(mem, elf_file, args=(), env=(), stack_size=DEFAULT_INIT_STACK_SZ): else: envp = 0 + if heap_start > 0: + mem.heap_range = range(heap_start, heap_start) # empty heap to start + # FIXME: incorrect, should point to the aux vector allocated on the stack auxv = 0 -- 2.30.2