fix(freertos): fix a bug in prvTaskDeleteWithCaps related to coprocessors

When a coprocessor is used, the stack pointer is altered. It must be restored
before freeing the memory allocated to the task.
This commit is contained in:
Omar Chebib 2025-02-12 10:27:27 +08:00
parent 15e75f21a7
commit 54f257b909

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -100,15 +100,18 @@ err:
configASSERT( eRunning != eTaskGetState( xTaskToDelete ) ); configASSERT( eRunning != eTaskGetState( xTaskToDelete ) );
/* We can delete the task and free the memory buffers.
* First, we must call `vTaskDelete` so that the port task delete callback is called.
* On targets that have coprocessors, it may be possible that the stack pointer is modified (restored)
* during this phase, hence, it must be done before getting the statuc buffers out of the task. */
vTaskDelete( xTaskToDelete );
/* Free the memory buffers */
xResult = xTaskGetStaticBuffers( xTaskToDelete, &puxStackBuffer, &pxTaskBuffer ); xResult = xTaskGetStaticBuffers( xTaskToDelete, &puxStackBuffer, &pxTaskBuffer );
configASSERT( xResult == pdTRUE ); configASSERT( xResult == pdTRUE );
configASSERT( puxStackBuffer != NULL ); configASSERT( puxStackBuffer != NULL );
configASSERT( pxTaskBuffer != NULL ); configASSERT( pxTaskBuffer != NULL );
/* We can delete the task and free the memory buffers. */
vTaskDelete( xTaskToDelete );
/* Free the memory buffers */
heap_caps_free( puxStackBuffer ); heap_caps_free( puxStackBuffer );
vPortFree( pxTaskBuffer ); vPortFree( pxTaskBuffer );
} }