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 70431ab2abda4caeb178780e06b930caa104ced0
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Oct 20 10:54:54 2026 +0200

    arch/risc-v: Do not map the page after a region on a page fault.
    
    riscv_fillpage() maps a page of the .text, .data or heap region on
    demand.  It compared the page address with "<= ARCH_xxx_VEND", but
    ARCH_TEXT_VEND, ARCH_DATA_VEND and ARCH_HEAP_VEND are the first address
    after each region.  An access to the first page after a region did not
    fault: the kernel mapped a new page there with the flags of the region.
    
    Compare with "<", so that an access after the region ends the program
    with SIGSEGV.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 arch/risc-v/src/common/riscv_exception.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/risc-v/src/common/riscv_exception.c 
b/arch/risc-v/src/common/riscv_exception.c
index 1865af7d355..8316fc580a3 100644
--- a/arch/risc-v/src/common/riscv_exception.c
+++ b/arch/risc-v/src/common/riscv_exception.c
@@ -222,7 +222,7 @@ int riscv_fillpage(int mcause, void *regs, void *args)
         mcause > RISCV_MAX_EXCEPTION ? "Unknown" : g_reasons_str[cause],
         cause, READ_CSR(CSR_EPC), READ_CSR(CSR_TVAL));
   vaddr = MM_PGALIGNDOWN(READ_CSR(CSR_TVAL));
-  if (vaddr >= CONFIG_ARCH_TEXT_VBASE && vaddr <= ARCH_TEXT_VEND)
+  if (vaddr >= CONFIG_ARCH_TEXT_VBASE && vaddr < ARCH_TEXT_VEND)
     {
       mmuflags = MMU_UTEXT_FLAGS;
 
@@ -232,11 +232,11 @@ int riscv_fillpage(int mcause, void *regs, void *args)
 
       mmuflags |= PTE_W;
     }
-  else if (vaddr >= CONFIG_ARCH_DATA_VBASE && vaddr <= ARCH_DATA_VEND)
+  else if (vaddr >= CONFIG_ARCH_DATA_VBASE && vaddr < ARCH_DATA_VEND)
     {
       mmuflags = MMU_UDATA_FLAGS;
     }
-  else if (vaddr >= CONFIG_ARCH_HEAP_VBASE && vaddr <= ARCH_HEAP_VEND)
+  else if (vaddr >= CONFIG_ARCH_HEAP_VBASE && vaddr < ARCH_HEAP_VEND)
     {
       mmuflags = MMU_UDATA_FLAGS;
     }

Reply via email to