Skip to content

arch: fall back to the kernel heap when there is no separate text heap#19256

Open
ricardgb wants to merge 1 commit into
apache:masterfrom
ricardgb:rp23xx-textheap
Open

arch: fall back to the kernel heap when there is no separate text heap#19256
ricardgb wants to merge 1 commit into
apache:masterfrom
ricardgb:rp23xx-textheap

Conversation

@ricardgb

@ricardgb ricardgb commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Reworked per review: instead of adding a per-arch text-heap stub for rp23xx, the text heap API now falls back to the normal kernel heap at the common layer, as suggested by @xiaoxiang781216.

  • include/nuttx/arch.h: when CONFIG_ARCH_USE_TEXT_HEAP is not set, up_textheap_memalign()/up_textheap_free()/up_textheap_heapmember() redirect to kmm_memalign()/kmm_free()/kmm_heapmember(), and the up_textheap_data_address()/up_textheap_data_sync() identity fallbacks become available unconditionally. On flat-memory architectures the kernel heap is executable, so code written against the portable text-heap API works on every such port (rp23xx included) with no per-arch boilerplate.
  • arch/sim/src/sim/sim_sectionheap.c: gate the sim text-heap implementation on CONFIG_ARCH_USE_TEXT_HEAP — it was compiled unconditionally (harmless before, but it would collide with the fallback macros), and every other implementation is already gated this way in its Make.defs/CMakeLists.
  • The rp23xx up_textheap_* stub from the previous revision is dropped entirely.

Existing common consumers (libs/libc/elf) are unchanged — they already carry their own lib_memalign() fallbacks when CONFIG_ARCH_USE_TEXT_HEAP is unset.

Impact

Direct callers of the text-heap API now build and work on flat-memory ports without the architecture claiming ARCH_HAVE_TEXT_HEAP. No change in behavior where CONFIG_ARCH_USE_TEXT_HEAP is enabled.

Testing

  • sim:nsh builds clean both with and without CONFIG_ARCH_USE_TEXT_HEAP (both sides of the new gating).
  • raspberrypi-pico-2:nsh builds clean.
  • A test translation unit calling up_textheap_memalign(), up_textheap_heapmember(), up_textheap_data_address(), up_textheap_data_sync() and up_textheap_free() through the fallback macros compiles clean for Cortex-M33 (arm-none-eabi-gcc, -Wall -Werror).
  • The previous revision of this PR (kmm-backed allocator) was exercised on a Raspberry Pi Pico 2 W by loading and running a Thumb code image allocated from the text heap; the fallback maps to the same kmm calls.
  • checkpatch.sh clean.

Disclosure: this change was developed with an AI agent (Claude Code, Anthropic) and human-reviewed before submission.

@ricardgb
ricardgb requested a review from jerpelea as a code owner July 1, 2026 17:32
@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Size: M The size of the change in this PR is medium labels Jul 2, 2026
Comment thread arch/arm/src/rp23xx/rp23xx_textheap.c Outdated
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@linguini1 linguini1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for consensus about fully generated PRs.

@ricardgb

Copy link
Copy Markdown
Contributor Author

Rebased onto the latest master (patch unchanged) and updated the commit trailer to the Assisted-by: form per the contribution guide.

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>
@ricardgb
ricardgb requested review from Donny9 and pussuw as code owners July 24, 2026 06:48
@ricardgb ricardgb changed the title arch/arm/rp23xx: add text heap (up_textheap_memalign) support arch: fall back to the kernel heap when there is no separate text heap Jul 24, 2026
@github-actions github-actions Bot added Arch: simulator Issues related to the SIMulator Area: OS Components OS Components issues Size: S The size of the change in this PR is small and removed Arch: arm Issues related to ARM (32-bit) architecture Size: M The size of the change in this PR is medium labels Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: simulator Issues related to the SIMulator Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants