You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/02/08 12:37:52 UTC
[nuttx] 01/02: sim: fix color running stack crash when use -Os
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 8d0094f6c99a34d8f0f5f1b189e7c472a0ea825e
Author: ligd <li...@xiaomi.com>
AuthorDate: Wed Feb 1 18:37:14 2023 +0800
sim: fix color running stack crash when use -Os
Signed-off-by: ligd <li...@xiaomi.com>
---
arch/sim/src/sim/sim_createstack.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/arch/sim/src/sim/sim_createstack.c b/arch/sim/src/sim/sim_createstack.c
index cbadcb0528..fc7557b382 100644
--- a/arch/sim/src/sim/sim_createstack.c
+++ b/arch/sim/src/sim/sim_createstack.c
@@ -35,6 +35,12 @@
#include "sim_internal.h"
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define STACK_MARGIN_WORDS 32
+
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -171,7 +177,7 @@ void nostackprotect_function sim_stack_color(void *stackbase,
if (nbytes == 0) /* 0: colorize the running stack */
{
stkend = up_getsp();
- if (stkend > (uintptr_t)&sp)
+ if (stkend < (uintptr_t)&sp)
{
stkend = (uintptr_t)&sp;
}
@@ -183,6 +189,7 @@ void nostackprotect_function sim_stack_color(void *stackbase,
stkend = STACK_ALIGN_DOWN(stkend);
nwords = (stkend - (uintptr_t)stackbase) >> 2;
+ nwords = nwords > STACK_MARGIN_WORDS ? nwords - STACK_MARGIN_WORDS : 0;
/* Set the entire stack to the coloration value */