mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
system: enable shared stack watchpoint
Enable shared stack watchpoint for overflow detection Enable unit tests: * "test printf using shared buffer stack" for C3 * "Test vTaskDelayUntil" for S2 * "UART can do poll()" for C3
This commit is contained in:
parent
e52e75f2de
commit
eec2419390
@ -551,7 +551,7 @@ UT_046:
|
||||
|
||||
UT_C3:
|
||||
extends: .unit_test_esp32c3_template
|
||||
parallel: 28
|
||||
parallel: 29
|
||||
tags:
|
||||
- ESP32C3_IDF
|
||||
- UT_T1_1
|
||||
|
@ -81,6 +81,7 @@
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/periph_defs.h"
|
||||
#include "soc/system_reg.h"
|
||||
#include "hal/systimer_hal.h"
|
||||
@ -302,11 +303,13 @@ void vPortYield(void)
|
||||
}
|
||||
|
||||
#define STACK_WATCH_AREA_SIZE 32
|
||||
#define STACK_WATCH_POINT_NUMBER (SOC_CPU_WATCHPOINTS_NUM - 1)
|
||||
|
||||
void vPortSetStackWatchpoint(void *pxStackStart)
|
||||
{
|
||||
uint32_t addr = (uint32_t)pxStackStart;
|
||||
addr = (addr + (STACK_WATCH_AREA_SIZE - 1)) & (~(STACK_WATCH_AREA_SIZE - 1));
|
||||
esp_set_watchpoint(7, (char *)addr, STACK_WATCH_AREA_SIZE, ESP_WATCHPOINT_STORE);
|
||||
esp_set_watchpoint(STACK_WATCH_POINT_NUMBER, (char *)addr, STACK_WATCH_AREA_SIZE, ESP_WATCHPOINT_STORE);
|
||||
}
|
||||
|
||||
BaseType_t xPortInIsrContext(void)
|
||||
|
@ -416,6 +416,9 @@ void vPortAssertIfInISR(void)
|
||||
configASSERT(xPortInIsrContext());
|
||||
}
|
||||
|
||||
#define STACK_WATCH_AREA_SIZE 32
|
||||
#define STACK_WATCH_POINT_NUMBER (SOC_CPU_WATCHPOINTS_NUM - 1)
|
||||
|
||||
void vPortSetStackWatchpoint( void* pxStackStart ) {
|
||||
//Set watchpoint 1 to watch the last 32 bytes of the stack.
|
||||
//Unfortunately, the Xtensa watchpoints can't set a watchpoint on a random [base - base+n] region because
|
||||
@ -425,7 +428,7 @@ void vPortSetStackWatchpoint( void* pxStackStart ) {
|
||||
//This way, we make sure we trigger before/when the stack canary is corrupted, not after.
|
||||
int addr=(int)pxStackStart;
|
||||
addr=(addr+31)&(~31);
|
||||
esp_set_watchpoint(1, (char*)addr, 32, ESP_WATCHPOINT_STORE);
|
||||
esp_set_watchpoint(STACK_WATCH_POINT_NUMBER, (char*)addr, 32, ESP_WATCHPOINT_STORE);
|
||||
}
|
||||
|
||||
uint32_t xPortGetTickRateHz(void) {
|
||||
|
@ -24,8 +24,6 @@
|
||||
#define TICKS_TO_MS(x) (((x)*1000)/TICK_RATE)
|
||||
#define REF_TO_ROUND_MS(x) (((x)+500)/1000)
|
||||
|
||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2)
|
||||
|
||||
static SemaphoreHandle_t task_delete_semphr;
|
||||
|
||||
static void delaying_task(void* arg)
|
||||
@ -73,5 +71,3 @@ TEST_CASE("Test vTaskDelayUntil", "[freertos]")
|
||||
vSemaphoreDelete(task_delete_semphr);
|
||||
ref_clock_deinit();
|
||||
}
|
||||
|
||||
#endif // CONFIG_IDF_TARGET_ESP32S2
|
||||
|
@ -26,8 +26,6 @@ void another_external_stack_function(void)
|
||||
shared_stack_sp = (StackType_t *)get_sp();
|
||||
}
|
||||
|
||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C3)
|
||||
|
||||
TEST_CASE("test printf using shared buffer stack", "[newlib]")
|
||||
{
|
||||
portSTACK_TYPE *shared_stack = malloc(SHARED_STACK_SIZE);
|
||||
@ -60,5 +58,3 @@ TEST_CASE("test printf using shared buffer stack", "[newlib]")
|
||||
vSemaphoreDelete(printf_lock);
|
||||
free(shared_stack);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include <esp_expression_with_stack.h>
|
||||
#include <riscv/rvruntime-frames.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/portmacro.h"
|
||||
|
||||
static portMUX_TYPE shared_stack_spinlock = portMUX_INITIALIZER_UNLOCKED;
|
||||
static void *current_task_stack = NULL;
|
||||
@ -23,11 +25,6 @@ extern void esp_shared_stack_invoke_function(shared_stack_function function, voi
|
||||
|
||||
static StackType_t *esp_switch_stack_setup(StackType_t *stack, size_t stack_size)
|
||||
{
|
||||
#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
|
||||
// TODO ESP32-C3 IDF-2207
|
||||
// esp_clear_watchpoint(1);
|
||||
// uint32_t watchpoint_place = ((uint32_t)stack + 32) & ~0x1f ;
|
||||
#endif
|
||||
//We need also to tweak current task stackpointer to avoid erroneous
|
||||
//stack overflow indication, so fills the stack with freertos known pattern:
|
||||
memset(stack, 0xa5U, stack_size * sizeof(StackType_t));
|
||||
@ -45,10 +42,8 @@ static StackType_t *esp_switch_stack_setup(StackType_t *stack, size_t stack_size
|
||||
adjusted_top_of_stack--;
|
||||
|
||||
#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
|
||||
// TODO ESP32-C3 IDF-2207
|
||||
//esp_set_watchpoint(1, (uint8_t *)watchpoint_place, 32, ESP_WATCHPOINT_STORE);
|
||||
vPortSetStackWatchpoint(stack);
|
||||
#endif
|
||||
|
||||
return ((StackType_t *)adjusted_top_of_stack);
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ TEST_CASE("Can mmap into instruction address space", "[spi_flash][mmap]")
|
||||
|
||||
}
|
||||
|
||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C3)
|
||||
#endif //!DISABLED_FOR_TARGETS(ESP32C3)
|
||||
|
||||
|
||||
TEST_CASE("Can mmap unordered pages into contiguous memory", "[spi_flash][mmap]")
|
||||
|
@ -206,9 +206,6 @@ TEST_CASE("UART can do select()", "[vfs]")
|
||||
deinit(uart_fd, socket_fd);
|
||||
}
|
||||
|
||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C3)
|
||||
// TODO ESP32C3 IDF-2457
|
||||
|
||||
TEST_CASE("UART can do poll()", "[vfs]")
|
||||
{
|
||||
int uart_fd;
|
||||
@ -270,9 +267,6 @@ TEST_CASE("UART can do poll()", "[vfs]")
|
||||
deinit(uart_fd, socket_fd);
|
||||
}
|
||||
|
||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C3)
|
||||
|
||||
|
||||
TEST_CASE("socket can do select()", "[vfs]")
|
||||
{
|
||||
int uart_fd;
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include <freertos/xtensa_context.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/portmacro.h"
|
||||
|
||||
StackType_t *xtensa_shared_stack;
|
||||
shared_stack_function xtensa_shared_stack_callback;
|
||||
@ -29,10 +31,6 @@ extern void esp_shared_stack_invoke_function(void);
|
||||
|
||||
static void esp_switch_stack_setup(StackType_t *stack, size_t stack_size)
|
||||
{
|
||||
#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
|
||||
esp_clear_watchpoint(1);
|
||||
uint32_t watchpoint_place = ((uint32_t)stack + 32) & ~0x1f ;
|
||||
#endif
|
||||
//We need also to tweak current task stackpointer to avoid erroneous
|
||||
//stack overflow indication, so fills the stack with freertos known pattern:
|
||||
memset(stack, 0xa5U, stack_size * sizeof(StackType_t));
|
||||
@ -48,7 +46,7 @@ static void esp_switch_stack_setup(StackType_t *stack, size_t stack_size)
|
||||
top_of_stack = (StackType_t *)(((UBaseType_t)(top_of_stack - 16) & ~0xf));
|
||||
|
||||
#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
|
||||
esp_set_watchpoint(1, (uint8_t *)watchpoint_place, 32, ESP_WATCHPOINT_STORE);
|
||||
vPortSetStackWatchpoint(stack);
|
||||
#endif
|
||||
|
||||
xtensa_shared_stack = top_of_stack;
|
||||
|
Loading…
x
Reference in New Issue
Block a user