From c309112b8a9b3d1891ad0ad4e83518495aa5de95 Mon Sep 17 00:00:00 2001 From: Felipe Neves Date: Mon, 6 Jan 2020 17:01:53 -0300 Subject: [PATCH] expression_with_stack:make stack overflow detection watchpoint optional --- .../xtensa/expression_with_stack_xtensa.c | 19 +++++++++++++++++++ .../xtensa/expression_with_stack_xtensa_asm.S | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/components/xtensa/expression_with_stack_xtensa.c b/components/xtensa/expression_with_stack_xtensa.c index 6f9cf4ca3c..74829d7e8b 100644 --- a/components/xtensa/expression_with_stack_xtensa.c +++ b/components/xtensa/expression_with_stack_xtensa.c @@ -1,10 +1,26 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include #include #include StackType_t * esp_switch_stack_setup(StackType_t *stack, size_t stack_size) { +#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK int watchpoint_place = (((int)stack + 31) & ~31); +#endif StackType_t *top_of_stack = (StackType_t *)&stack[0] + ((stack_size * sizeof(StackType_t)) / sizeof(StackType_t)); @@ -18,6 +34,9 @@ StackType_t * esp_switch_stack_setup(StackType_t *stack, size_t stack_size) frame->a0 = 0; frame->a1 = (UBaseType_t)top_of_stack; +#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK esp_set_watchpoint(2, (char*)watchpoint_place, 32, ESP_WATCHPOINT_STORE); +#endif + return top_of_stack; } \ No newline at end of file diff --git a/components/xtensa/expression_with_stack_xtensa_asm.S b/components/xtensa/expression_with_stack_xtensa_asm.S index 106eb6f9c4..f868131ba0 100644 --- a/components/xtensa/expression_with_stack_xtensa_asm.S +++ b/components/xtensa/expression_with_stack_xtensa_asm.S @@ -46,9 +46,13 @@ esp_switch_stack_exit: #ifndef __XTENSA_CALL0_ABI__ entry sp, 0x10 + +#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK movi a6, 2 movi a4, esp_clear_watchpoint callx4 a4 /* clear the watchpoint before releasing stack */ +#endif + l32i a4, a2, 0 /* recover the original task stack */ mov a1, a4 /* put it on sp register again */ retw