expression_with_stack_xtensa: fixed stack pointer to avoid its overflow on heap block metadata.

This commit is contained in:
Felipe Neves 2019-12-04 11:25:02 -03:00
parent 8bfb8e885e
commit e4fb50e6f3
2 changed files with 8 additions and 11 deletions

View file

@ -8,25 +8,22 @@
#include "esp_expression_with_stack.h"
//makes sure this is not the task stack...
void check_stack(portSTACK_TYPE *sp, portSTACK_TYPE *base_sp)
void another_external_stack_function(void)
{
StaticTask_t *hacked_task = (StaticTask_t *)xTaskGetCurrentTaskHandle();
portSTACK_TYPE *task_sp = (portSTACK_TYPE *)hacked_task->pxDummy1;
TEST_ASSERT((intptr_t)task_sp < (intptr_t)base_sp ||
(intptr_t)task_sp >= (intptr_t)sp);
//We can even use Freertos resources inside of this context.
vTaskDelay(100);
printf("Executing this another printf inside a function with external stack");
}
TEST_CASE("test printf using shared buffer stack", "[newlib]")
{
portSTACK_TYPE *shared_stack = malloc(8192 * sizeof(portSTACK_TYPE));
portSTACK_TYPE *ext_stack_top = (portSTACK_TYPE *)&shared_stack[0] +
((sizeof(8192 * sizeof(portSTACK_TYPE))) /
sizeof(portSTACK_TYPE));
TEST_ASSERT(shared_stack != NULL);
SemaphoreHandle_t printf_lock = xSemaphoreCreateMutex();
ESP_EXECUTE_EXPRESSION_WITH_STACK(printf_lock, shared_stack,8192,printf("Executing printf from external stack! \n"));
ESP_EXECUTE_EXPRESSION_WITH_STACK(printf_lock, shared_stack,8192,check_stack(ext_stack_top, shared_stack));
ESP_EXECUTE_EXPRESSION_WITH_STACK(printf_lock, shared_stack,8192,printf("Executing this printf from external stack! \n"));
ESP_EXECUTE_EXPRESSION_WITH_STACK(printf_lock, shared_stack,8192,another_external_stack_function());
vSemaphoreDelete(printf_lock);
free(shared_stack);
}

View file

@ -10,7 +10,7 @@ StackType_t * esp_switch_stack_setup(StackType_t *stack, size_t stack_size)
sizeof(StackType_t));
//Align stack to a 16byte boundary, as required by CPU specific:
top_of_stack = (StackType_t *)(((UBaseType_t)(top_of_stack - 1) -
top_of_stack = (StackType_t *)(((UBaseType_t)(top_of_stack - 31) -
ALIGNUP(0x10, sizeof(XtSolFrame) )) &
~0xf);