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 <ricard@groundbits.com>
This commit is contained in:
Ricard Rosson 2026-07-24 07:48:17 +01:00
parent 2cb7b7c03e
commit 0a7171bc62
2 changed files with 23 additions and 6 deletions

View file

@ -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

View file

@ -847,6 +847,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)
@ -856,6 +861,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
/****************************************************************************
@ -868,6 +879,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
/****************************************************************************
@ -880,6 +893,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
/****************************************************************************
@ -900,13 +915,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
@ -918,13 +932,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