Skip to content

Fix SH2A_FPU FPU context cleanup#1444

Open
Old-Ding wants to merge 1 commit into
FreeRTOS:mainfrom
Old-Ding:codex/fix-sh2a-fpu-context-cleanup
Open

Fix SH2A_FPU FPU context cleanup#1444
Old-Ding wants to merge 1 commit into
FreeRTOS:mainfrom
Old-Ding:codex/fix-sh2a-fpu-context-cleanup

Conversation

@Old-Ding

@Old-Ding Old-Ding commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add portCLEAN_UP_TCB for the Renesas SH2A_FPU port so task deletion releases the FPU context buffer stored through pxTaskTag.
  • Make xPortUsesFloatingPoint() idempotent when the task already has an FPU buffer, avoiding an immediate leak on repeated calls.
  • Move the FPU buffer sizing macros to portmacro.h so port.c and the cleanup macro use the same constants.

Root cause

xPortUsesFloatingPoint() allocates the FPU context buffer and stores a pointer just past the allocation in pxTaskTag, because the save routine uses a pre-decrement. The port did not define portCLEAN_UP_TCB, so prvDeleteTCB() used the default no-op cleanup and the allocation became unreachable when the task was deleted.

Fixes #1443

Validation

  • git diff --check
  • rg confirmed the FPU buffer constants and portCLEAN_UP_TCB override are scoped to portable/Renesas/SH2A_FPU, with prvDeleteTCB() calling portCLEAN_UP_TCB( pxTCB ) before freeing the TCB/stack.
  • Renesas SH toolchain/hardware build not run locally; no shc, ccsh, sh-elf-gcc, sh-none-elf-gcc, rx-elf-gcc, or ccrx command was found on this machine.

@Old-Ding Old-Ding changed the title [codex] Fix SH2A_FPU FPU context cleanup Fix SH2A_FPU FPU context cleanup Jul 4, 2026
@Old-Ding Old-Ding marked this pull request as ready for review July 4, 2026 18:15
@Old-Ding Old-Ding force-pushed the codex/fix-sh2a-fpu-context-cleanup branch from fe68ff1 to a7a9134 Compare July 9, 2026 02:01
Keep the per-task FPU context allocation reachable, avoid replacing an existing task tag buffer, and free the allocation from portCLEAN_UP_TCB using the saved buffer end pointer.

Signed-off-by: Old-Ding <ai.neo.ae86@gmail.com>
@rawalexe rawalexe force-pushed the codex/fix-sh2a-fpu-context-cleanup branch from a7a9134 to 389e7bc Compare July 9, 2026 23:27
@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

@rawalexe rawalexe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Buffer-reuse fix and portCLEAN_UP_TCB look correct. Confirmed the task tag stores the buffer end pointer (pulFlopBuffer + portFLOP_REGISTERS_TO_STORE), matching the pre-decrement convention used by the FPU save routine and the - portFLOP_REGISTERS_TO_STORE recovery in the cleanup macro. This correctly fixes the original leak/overwrite bug where a second call to xPortUsesFloatingPoint would silently drop the existing allocation. LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Renesas SH2A_FPU port: FPU context buffer leaked on task deletion (no portCLEAN_UP_TCB)

3 participants