You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/05/18 13:30:55 UTC
[incubator-nuttx] branch master updated: arch: complete logic in
create/use stack to support stack coloration.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 05ebb39 arch: complete logic in create/use stack to support stack coloration.
05ebb39 is described below
commit 05ebb39998d0bf8449a714f01c311fd9bb82729f
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon May 18 16:23:39 2020 +0800
arch: complete logic in create/use stack to support stack coloration.
Signed-off-by: chao.an <an...@xiaomi.com>
---
arch/risc-v/src/common/riscv_usestack.c | 11 ++++++++
arch/sim/src/sim/up_usestack.c | 11 ++++++++
arch/xtensa/src/common/xtensa.h | 6 +++++
arch/xtensa/src/common/xtensa_createstack.c | 40 +++++++++++++++++++++--------
arch/xtensa/src/common/xtensa_usestack.c | 11 ++++++++
5 files changed, 69 insertions(+), 10 deletions(-)
diff --git a/arch/risc-v/src/common/riscv_usestack.c b/arch/risc-v/src/common/riscv_usestack.c
index a6e07d9..5cad246 100644
--- a/arch/risc-v/src/common/riscv_usestack.c
+++ b/arch/risc-v/src/common/riscv_usestack.c
@@ -159,5 +159,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
+#if defined(CONFIG_STACK_COLORATION)
+ /* If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
+
+ up_stack_color((FAR void *)((uintptr_t)tcb->stack_alloc_ptr +
+ sizeof(struct tls_info_s)),
+ tcb->adj_stack_size - sizeof(struct tls_info_s));
+#endif
+
return OK;
}
diff --git a/arch/sim/src/sim/up_usestack.c b/arch/sim/src/sim/up_usestack.c
index 7174e2b..1a53a08 100644
--- a/arch/sim/src/sim/up_usestack.c
+++ b/arch/sim/src/sim/up_usestack.c
@@ -130,5 +130,16 @@ int up_use_stack(FAR struct tcb_s *tcb, FAR void *stack, size_t stack_size)
memset(stack, 0, sizeof(struct tls_info_s));
+#if defined(CONFIG_STACK_COLORATION)
+ /* If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
+
+ up_stack_color((FAR void *)((uintptr_t)tcb->stack_alloc_ptr +
+ sizeof(struct tls_info_s)),
+ tcb->adj_stack_size - sizeof(struct tls_info_s));
+#endif
+
return OK;
}
diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h
index bff7093..5133f53 100644
--- a/arch/xtensa/src/common/xtensa.h
+++ b/arch/xtensa/src/common/xtensa.h
@@ -342,5 +342,11 @@ void up_usbuninitialize(void);
# define up_usbuninitialize()
#endif
+/* Debug ********************************************************************/
+
+#ifdef CONFIG_STACK_COLORATION
+void up_stack_color(FAR void *stackbase, size_t nbytes);
+#endif
+
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_XTENSA_SRC_COMMON_XTENSA_H */
diff --git a/arch/xtensa/src/common/xtensa_createstack.c b/arch/xtensa/src/common/xtensa_createstack.c
index 3f81596..a9148fd 100644
--- a/arch/xtensa/src/common/xtensa_createstack.c
+++ b/arch/xtensa/src/common/xtensa_createstack.c
@@ -221,20 +221,14 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
size_t size_of_stack;
#ifdef CONFIG_STACK_COLORATION
- uint32_t *ptr;
- int i;
-
- /* Yes.. If stack debug is enabled, then fill the stack with a
+ /* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
- for (i = 0, ptr = (uint32_t *)tcb->stack_alloc_ptr;
- i < stack_size;
- i += sizeof(uint32_t))
- {
- *ptr++ = STACK_COLOR;
- }
+ up_stack_color((FAR void *)tcb->stack_alloc_ptr +
+ sizeof(struct tls_info_s),
+ stack_size - sizeof(struct tls_info_s));
#endif
/* XTENSA uses a push-down stack: the stack grows toward lower
@@ -295,3 +289,29 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
return ERROR;
}
+
+/****************************************************************************
+ * Name: up_stack_color
+ *
+ * Description:
+ * Write a well know value into the stack
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_STACK_COLORATION
+void up_stack_color(FAR void *stackbase, size_t nbytes)
+{
+ /* Take extra care that we do not write outsize the stack boundaries */
+
+ uint32_t *stkptr = (uint32_t *)(((uintptr_t)stackbase + 3) & ~3);
+ uintptr_t stkend = (((uintptr_t)stackbase + nbytes) & ~3);
+ size_t nwords = (stkend - (uintptr_t)stackbase) >> 2;
+
+ /* Set the entire stack to the coloration value */
+
+ while (nwords-- > 0)
+ {
+ *stkptr++ = STACK_COLOR;
+ }
+}
+#endif
diff --git a/arch/xtensa/src/common/xtensa_usestack.c b/arch/xtensa/src/common/xtensa_usestack.c
index b40f078..40681ef 100644
--- a/arch/xtensa/src/common/xtensa_usestack.c
+++ b/arch/xtensa/src/common/xtensa_usestack.c
@@ -151,5 +151,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
+#if defined(CONFIG_STACK_COLORATION)
+ /* If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
+
+ up_stack_color((FAR void *)((uintptr_t)tcb->stack_alloc_ptr +
+ sizeof(struct tls_info_s)),
+ tcb->adj_stack_size - sizeof(struct tls_info_s));
+#endif
+
return OK;
}