From b7f958a02ebf0dde83c5022e79e7f8a55939565f Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 26 Jan 2019 11:36:38 -0600 Subject: [PATCH] binfmt/, binfmt/libelf: binfmt/elf: Call umm_initialize as soon as possible otherwise elf_loadctors/elf_loaddtors will fail to allocate memory. --- binfmt/binfmt_execmodule.c | 5 ----- binfmt/libelf/libelf_load.c | 7 ++++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/binfmt/binfmt_execmodule.c b/binfmt/binfmt_execmodule.c index 9e161c01e7..ae6e12dccc 100644 --- a/binfmt/binfmt_execmodule.c +++ b/binfmt/binfmt_execmodule.c @@ -164,11 +164,6 @@ int exec_module(FAR const struct binary_s *binp) berr("ERROR: up_addrenv_select() failed: %d\n", ret); goto errout_with_tcb; } - - /* Initialize the user heap */ - - umm_initialize((FAR void *)CONFIG_ARCH_HEAP_VBASE, - up_addrenv_heapsize(&binp->addrenv)); #endif /* Allocate the stack for the new task. diff --git a/binfmt/libelf/libelf_load.c b/binfmt/libelf/libelf_load.c index 9808aca6ec..661186e752 100644 --- a/binfmt/libelf/libelf_load.c +++ b/binfmt/libelf/libelf_load.c @@ -277,7 +277,7 @@ int elf_load(FAR struct elf_loadinfo_s *loadinfo) #elif defined(CONFIG_ARCH_STACK_DYNAMIC) heapsize = ARCH_HEAP_SIZE; #else - heapsize = MIN(ARCH_HEAP_SIZE, CONFIG_ELF_STACKSIZE); + heapsize = MAX(ARCH_HEAP_SIZE, CONFIG_ELF_STACKSIZE); #endif /* Allocate (and zero) memory for the ELF file. */ @@ -301,6 +301,11 @@ int elf_load(FAR struct elf_loadinfo_s *loadinfo) berr("ERROR: elf_addrenv_select() failed: %d\n", ret); goto errout_with_buffers; } + + /* Initialize the user heap */ + + umm_initialize((FAR void *)CONFIG_ARCH_HEAP_VBASE, + up_addrenv_heapsize(&loadinfo->addrenv)); #endif /* Load ELF section data into memory */