[BUG] Renesas SH2A_FPU port: FPU context buffer leaked on task deletion (no `portCLEAN_UP_TCB`)
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- c
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Start in portable/Renesas/SH2A_FPU/port.c at xPortUsesFloatingPoint() and in portmacro.h where traceTASK_SWITCHED_OUT and traceTASK_SWITCHED_IN use pxTaskTag. Decide whether the buffer should be freed through a portCLEAN_UP_TCB definition or a port-specific TCB field, and check the open pull request #1444 before starting. Done means deleting a task that called the function frees its buffer, and a second call does not leak.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In portable/Renesas/SH2A_FPU/port.c, xPortUsesFloatingPoint() dynamically
allocates a 72-byte FPU register save buffer and hands ownership to the task by
storing a pointer to it in the task's application tag (pxTaskTag). The port
never defines portCLEAN_UP_TCB, so when a task that uses the FPU is deleted the
buffer is never freed and becomes unreachable. Calling the function twice on the
same task also leaks the first buffer immediately.
Affected code
portable/Renesas/SH2A_FPU/port.c, xPortUsesFloatingPoint():
#define portFLOP_REGISTERS_TO_STORE ( 18 )
#define portFLOP_STORAGE_SIZE ( portFLOP_REGISTERS_TO_STORE * 4 ) /* 72 bytes */
/* Allocate a buffer large enough to hold all the flop registers. */
pulFlopBuffer = ( uint32_t * ) pvPortMalloc( portFLOP_STORAGE_SIZE );
if( pulFlopBuffer != NULL )
{
memset( ( void * ) pulFlopBuffer, 0x00, portFLOP_STORAGE_SIZE );
*pulFlopBuffer = get_fpscr();
/* Use the task tag to point to the flop buffer. Pass pointer to just
* above the buffer because the flop save routine uses a pre-decrement. */
vTaskSetApplicationTaskTag( xTask,
( void * ) ( pulFlopBuffer + portFLOP_REGISTERS_TO_STORE ) );
xReturn = pdPASS;
}
else
{
xReturn = pdFAIL;
}
return xReturn;
The tag stores a pointer to just past the end of the buffer (the assembly save
routine pre-decrements), so the only reference to the original allocation base is
pxTaskTag - portFLOP_REGISTERS_TO_STORE.
portable/Renesas/SH2A_FPU/portmacro.h uses pxTaskTag exclusively for the FPU
context:
#define traceTASK_SWITCHED_OUT() do { if( pxCurrentTCB->pxTaskTag != NULL ) vPortSaveFlopRegisters( pxCurrentTCB->pxTaskTag ); } while( 0 )
#define traceTASK_SWITCHED_IN() do { if( pxCurrentTCB->pxTaskTag != NULL ) vPortRestoreFlopRegisters( pxCurrentTCB->pxTaskTag ); } while( 0 )
Problem
The buffer is not a leak on successful return — ownership legitimately escapes to
the task. But that transfer requires a matching destructor when the task is
deleted, and none exists:
-
prvDeleteTCB()callsportCLEAN_UP_TCB( pxTCB )precisely so a port can free
task-specific memory. -
portmacro.hfor SH2A_FPU does not defineportCLEAN_UP_TCB, so the
kernel default is used (include/FreeRTOS.h):#ifndef portCLEAN_UP_TCB #define portCLEAN_UP_TCB( pxTCB ) ( void ) ( pxTCB ) #endif -
The kernel does not free the application task tag as generic memory (in other
ports it may hold a user callback).
Result: deleting any task that called xPortUsesFloatingPoint() leaks 72 bytes.
Secondary: repeated calls leak immediately
xPortUsesFloatingPoint() does not check whether the task already has an FPU
buffer. A second call allocates a new buffer, overwrites pxTaskTag, and drops
the only pointer to the previous allocation — no task deletion required.
Trigger condition
- Target is
portable/Renesas/SH2A_FPU. - Dynamic allocation is enabled.
- A task calls
xPortUsesFloatingPoint(). - The task is deleted (or the function is called twice).
Each occurrence leaks 72 bytes. In a system that repeatedly creates, FPU-enables,
runs and deletes worker tasks, the leak accumulates steadily and can eventually
cause pvPortMalloc() to fail. Embedded systems have no process-exit reclamation,
so the loss persists until reboot.
Suggested fix
Define portCLEAN_UP_TCB for this port, recovering the base pointer from the
stored end pointer:
#define portCLEAN_UP_TCB( pxTCB ) \
do \
{ \
if( ( pxTCB )->pxTaskTag != NULL ) \
{ \
uint32_t * pulBufferEnd = ( uint32_t * ) ( pxTCB )->pxTaskTag; \
vPortFree( pulBufferEnd - portFLOP_REGISTERS_TO_STORE ); \
( pxTCB )->pxTaskTag = NULL; \
} \
} while( 0 )
Implementation notes:
portFLOP_REGISTERS_TO_STOREis currently defined inport.c; if the macro
lives inportmacro.h, the constant must be shared/moved.- The cleanup must only free tags created by this port's FPU init. Reusing the
application task tag makes this ambiguous ifconfigUSE_APPLICATION_TASK_TAG
lets users set the tag. A cleaner design stores the allocation base in a
port-specific TCB extension field instead of overloadingpxTaskTag.
For the repeated-call issue, guard the allocation (only safe if the tag is known
to be port-owned):
if( xTaskGetApplicationTaskTag( xTask ) != NULL )
{
return pdPASS;
}
- Ngôn ngữ chính
- C
- Star
- 4.6k
- Fork
- 1.6k
- Merge trung bình
- 2 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FreeRTOS/FreeRTOS-Kernel
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
FreeRTOS/FreeRTOS-Kernel#1542 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG] Release asset FreeRTOS-KernelV11.3.2.zip has the files of main, not of the tag V11.3.2Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
FreeRTOS/FreeRTOS-Kernel#1520 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
FreeRTOS/FreeRTOS-Kernel#1494 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
FreeRTOS/FreeRTOS-Kernel#1554 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG] event_wait_timed can't return falseCó thể đã có người làm @TedLyngmo đã nhận 39 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 38/100
FreeRTOS/FreeRTOS-Kernel#1546 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của FreeRTOS/FreeRTOS-Kernel
Issue tương tự
-
RecompLauncher supportĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
shinyquagsire23/OpenJKDF2#540 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Prison work hall: laundry and kitchen stations stand at bare walls, the hatch has no counter or signĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Life-Framework/Life-Framework#5939 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
autoconf failes to find libsodium even when present due to implicit function declarationCó thể đã có người làm @coderjoe đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 13 ngày
-
SessionInterfaceHandler is throwing a deprecation notice as a warning instead of a deprecationĐang mởBug Status: Needs Triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement_package: a site operand of another JSON type raises TypeError, not a named refusalĐang mởbug python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
Jstar269/nakagawa-recomp#3521 ·
Maintainer thường phản hồi trong vòng 1 ngày