This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 895d6c171b6f51c68c8f32e5ae273f8f34113fcc Author: Marco Casaroli <[email protected]> AuthorDate: Tue Oct 20 11:22:02 2026 +0200 arch: Keep the user heap inside its region. up_addrenv_create() on RISC-V and arm64 adds pages to the heap size (the fix for #5811). libelf asks for the whole heap region (ARCH_HEAP_SIZE), so with fixed regions the heap passed ARCH_HEAP_VEND: the kernel mapped pages after the region, and mm_initialize() put the end node of the heap there. On rv-virt:knsh64_paging, the end node is at ARCH_HEAP_VEND + 0xff8, which only works because riscv_fillpage() also maps the page after the heap region. With fixed regions, limit the heap to ARCH_HEAP_SIZE on RISC-V and arm64. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- arch/arm64/src/common/arm64_addrenv_mmu.c | 9 +++++++++ arch/risc-v/src/common/riscv_addrenv.c | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/arch/arm64/src/common/arm64_addrenv_mmu.c b/arch/arm64/src/common/arm64_addrenv_mmu.c index 874a9eefba9..e25548bda7d 100644 --- a/arch/arm64/src/common/arm64_addrenv_mmu.c +++ b/arch/arm64/src/common/arm64_addrenv_mmu.c @@ -471,6 +471,15 @@ int up_addrenv_create(size_t textsize, size_t datasize, size_t heapsize, heapsize = heapsize + MM_PGALIGNUP(4*CONFIG_DEFAULT_TASK_STACKSIZE); +#if (CONFIG_ARCH_TEXT_VBASE != 0x0) && (CONFIG_ARCH_HEAP_VBASE != 0x0) + /* The heap must not pass the end of its region */ + + if (heapsize > ARCH_HEAP_SIZE) + { + heapsize = ARCH_HEAP_SIZE; + } +#endif + /* Map the reserved area */ ret = create_region(addrenv, resvbase, resvsize, MMU_UDATA_FLAGS); diff --git a/arch/risc-v/src/common/riscv_addrenv.c b/arch/risc-v/src/common/riscv_addrenv.c index 446256c41d8..f5d056cd945 100644 --- a/arch/risc-v/src/common/riscv_addrenv.c +++ b/arch/risc-v/src/common/riscv_addrenv.c @@ -457,6 +457,15 @@ int up_addrenv_create(size_t textsize, size_t datasize, size_t heapsize, heapsize = heapsize + MM_PGALIGNUP(CONFIG_DEFAULT_TASK_STACKSIZE); +#if (CONFIG_ARCH_TEXT_VBASE != 0x0) && (CONFIG_ARCH_HEAP_VBASE != 0x0) + /* The heap must not pass the end of its region */ + + if (heapsize > ARCH_HEAP_SIZE) + { + heapsize = ARCH_HEAP_SIZE; + } +#endif + /* Map the reserved area */ ret = create_region(addrenv, resvbase, resvsize, MMU_UDATA_FLAGS);
