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

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


The following commit(s) were added to refs/heads/master by this push:
     new aa1aaa2e969 arch: fall back to the kernel heap when there is no 
separate text heap
aa1aaa2e969 is described below

commit aa1aaa2e9692c879c906c688a35750c928c60188
Author: Ricard Rosson <[email protected]>
AuthorDate: Fri Jul 24 07:48:17 2026 +0100

    arch: fall back to the kernel heap when there is no separate text heap
    
    When an architecture does not provide a separate text heap
    (CONFIG_ARCH_USE_TEXT_HEAP is not selected), redirect the text heap
    API to the normal kernel heap in include/nuttx/arch.h.  On
    flat-memory architectures the kernel heap is executable, so code
    written against the portable API (up_textheap_memalign() and
    friends) now works on every such port without per-arch stubs that
    just wrap kmm_memalign().  Suggested by review on the previous
    revision of this change, which added exactly such a stub for rp23xx.
    
    up_textheap_data_address() and up_textheap_data_sync() identity
    fallbacks become available unconditionally as well.
    
    Gate the sim implementation on CONFIG_ARCH_USE_TEXT_HEAP: it was
    compiled unconditionally (harmless before, but it would now collide
    with the fallback macros), matching how every other implementation
    is already gated in its Make.defs/CMakeLists.
    
    Assisted-by: Claude (Anthropic Claude Code)
    Signed-off-by: Ricard Rosson <[email protected]>
---
 arch/sim/src/sim/sim_sectionheap.c |  4 ++++
 include/nuttx/arch.h               | 25 +++++++++++++++++++------
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/arch/sim/src/sim/sim_sectionheap.c 
b/arch/sim/src/sim/sim_sectionheap.c
index 8a9e0b3625b..5e3db77fd1a 100644
--- a/arch/sim/src/sim/sim_sectionheap.c
+++ b/arch/sim/src/sim/sim_sectionheap.c
@@ -33,7 +33,9 @@
  * Private Data
  ****************************************************************************/
 
+#ifdef CONFIG_ARCH_USE_TEXT_HEAP
 static struct mm_heap_s *g_textheap;
+#endif
 static struct mm_heap_s *g_dataheap;
 
 /****************************************************************************
@@ -48,6 +50,7 @@ static struct mm_heap_s *g_dataheap;
  *
  ****************************************************************************/
 
+#ifdef CONFIG_ARCH_USE_TEXT_HEAP
 #ifdef CONFIG_ARCH_USE_SEPARATED_SECTION
 void *up_textheap_memalign(const char *sectname, size_t align, size_t size)
 #else
@@ -92,6 +95,7 @@ bool up_textheap_heapmember(void *p)
 {
   return g_textheap != NULL && mm_heapmember(g_textheap, p);
 }
+#endif /* CONFIG_ARCH_USE_TEXT_HEAP */
 
 /****************************************************************************
  * Name: up_dataheap_memalign
diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h
index 5480a0a3a25..83fd3dc9848 100644
--- a/include/nuttx/arch.h
+++ b/include/nuttx/arch.h
@@ -862,6 +862,11 @@ void up_extraheaps_init(void);
  * Description:
  *   Allocate memory for text with the specified alignment and sectname.
  *
+ *   If the architecture does not provide a separate text heap
+ *   (CONFIG_ARCH_USE_TEXT_HEAP is not set), the text heap API falls back
+ *   to the normal kernel heap: on flat-memory architectures the kernel
+ *   heap is executable, so no separate allocator is needed.
+ *
  ****************************************************************************/
 
 #if defined(CONFIG_ARCH_USE_TEXT_HEAP)
@@ -871,6 +876,12 @@ FAR void *up_textheap_memalign(FAR const char *sectname,
 #  else
 FAR void *up_textheap_memalign(size_t align, size_t size);
 #  endif
+#else
+#  if defined(CONFIG_ARCH_USE_SEPARATED_SECTION)
+#    define up_textheap_memalign(s,a,z) kmm_memalign(a,z)
+#  else
+#    define up_textheap_memalign(a,z) kmm_memalign(a,z)
+#  endif
 #endif
 
 /****************************************************************************
@@ -883,6 +894,8 @@ FAR void *up_textheap_memalign(size_t align, size_t size);
 
 #if defined(CONFIG_ARCH_USE_TEXT_HEAP)
 void up_textheap_free(FAR void *p);
+#else
+#  define up_textheap_free(p) kmm_free(p)
 #endif
 
 /****************************************************************************
@@ -895,6 +908,8 @@ void up_textheap_free(FAR void *p);
 
 #if defined(CONFIG_ARCH_USE_TEXT_HEAP)
 bool up_textheap_heapmember(FAR void *p);
+#else
+#  define up_textheap_heapmember(p) kmm_heapmember(p)
 #endif
 
 /****************************************************************************
@@ -915,13 +930,12 @@ bool up_textheap_heapmember(FAR void *p);
  *
  ****************************************************************************/
 
-#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
-#if defined(CONFIG_ARCH_HAVE_TEXT_HEAP_SEPARATE_DATA_ADDRESS)
+#if defined(CONFIG_ARCH_USE_TEXT_HEAP) && \
+    defined(CONFIG_ARCH_HAVE_TEXT_HEAP_SEPARATE_DATA_ADDRESS)
 FAR void *up_textheap_data_address(FAR void *p);
 #else
 #define up_textheap_data_address(p) ((FAR void *)p)
 #endif
-#endif
 
 /****************************************************************************
  * Name: up_textheap_data_sync
@@ -933,13 +947,12 @@ FAR void *up_textheap_data_address(FAR void *p);
  *
  ****************************************************************************/
 
-#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
-#if defined(CONFIG_ARCH_HAVE_TEXT_HEAP_SEPARATE_DATA_ADDRESS)
+#if defined(CONFIG_ARCH_USE_TEXT_HEAP) && \
+    defined(CONFIG_ARCH_HAVE_TEXT_HEAP_SEPARATE_DATA_ADDRESS)
 void up_textheap_data_sync(void);
 #else
 #define up_textheap_data_sync() do {} while (0)
 #endif
-#endif
 
 /****************************************************************************
  * Name: up_dataheap_memalign

Reply via email to