This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit cb7199809075a6f222a9180f756f5ebda7348aca
Author: Marco Casaroli <[email protected]>
AuthorDate: Sat Oct 31 23:52:36 2026 +0100

    arch/x86_64: Grow the heap of the address environment that is selected.
    
    pgalloc() mapped the new heap pages in the address environment of the
    group of the caller (addrenv_own).  While exec() loads a new program,
    the caller selects the address environment of the new program
    (addrenv_curr): when the heap of the new program grows then (a stack
    larger than the initial heap), the pages went to the caller, and the
    loader faulted on the heap of the new program.  For example
    posix_spawn() with a stack size of 1 MiB on qemu-intel64:knsh_romfs.
    Use addrenv_curr, as arm64, ARMv7-A and RISC-V do.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 arch/x86_64/src/common/x86_64_pgalloc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86_64/src/common/x86_64_pgalloc.c 
b/arch/x86_64/src/common/x86_64_pgalloc.c
index 009c0fb55b5..ac31a1ebd35 100644
--- a/arch/x86_64/src/common/x86_64_pgalloc.c
+++ b/arch/x86_64/src/common/x86_64_pgalloc.c
@@ -171,8 +171,12 @@ uintptr_t pgalloc(uintptr_t brkaddr, unsigned int npages)
   uintptr_t              paddr;
   uintptr_t              vaddr;
 
-  DEBUGASSERT(tcb && tcb->addrenv_own);
-  addrenv = &tcb->addrenv_own->addrenv;
+  /* The address environment that is selected: exec() selects the one of
+   * the new program while it loads it
+   */
+
+  DEBUGASSERT(tcb && tcb->addrenv_curr);
+  addrenv = &tcb->addrenv_curr->addrenv;
 
   /* The current implementation only supports extending the user heap
    * region as part of the implementation of user sbrk().  This function

Reply via email to