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

pull/4618/head
Felipe Neves 2019-12-04 11:25:02 -03:00
rodzic 8bfb8e885e
commit e4fb50e6f3
2 zmienionych plików z 8 dodań i 11 usunięć

Wyświetl plik

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

Wyświetl plik

@ -10,7 +10,7 @@ StackType_t * esp_switch_stack_setup(StackType_t *stack, size_t stack_size)
sizeof(StackType_t)); sizeof(StackType_t));
//Align stack to a 16byte boundary, as required by CPU specific: //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) )) & ALIGNUP(0x10, sizeof(XtSolFrame) )) &
~0xf); ~0xf);