From: Jacob Lifshay Date: Sun, 3 Dec 2023 08:47:05 +0000 (-0800) Subject: load_elf: set mem.heap_range so brk works X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b6d19fcb7c3011333013abe1bbc56a81d456128a;p=openpower-isa.git load_elf: set mem.heap_range so brk works --- 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