You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/01/18 20:29:44 UTC

[incubator-nuttx] branch master updated: nRF52: support stack coloration

This is an automated email from the ASF dual-hosted git repository.

acassis 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 5fc34a6  nRF52: support stack coloration
5fc34a6 is described below

commit 5fc34a6e8c471504b1f63fe0f7d3e729cfb2f68d
Author: Matias N <ma...@protobits.dev>
AuthorDate: Mon Jan 18 13:42:20 2021 -0300

    nRF52: support stack coloration
---
 arch/arm/src/nrf52/nrf52_start.c | 53 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/arch/arm/src/nrf52/nrf52_start.c b/arch/arm/src/nrf52/nrf52_start.c
index 06a6116..328f308 100644
--- a/arch/arm/src/nrf52/nrf52_start.c
+++ b/arch/arm/src/nrf52/nrf52_start.c
@@ -81,6 +81,11 @@
  * Private Functions
  ****************************************************************************/
 
+#ifdef CONFIG_STACK_COLORATION
+static void go_nx_start(void *pv, unsigned int nbytes)
+  __attribute__ ((naked, no_instrument_function, noreturn));
+#endif
+
 /****************************************************************************
  * Name: nrf52_fpuconfig
  *
@@ -169,6 +174,47 @@ static inline void nrf52_fpuconfig(void)
 #endif
 
 /****************************************************************************
+ * Name: go_nx_start
+ *
+ * Description:
+ *   Set the IDLE stack to the coloration value and jump into nx_start()
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_STACK_COLORATION
+static void go_nx_start(void *pv, unsigned int nbytes)
+{
+  /* Set the IDLE stack to the stack coloration value then jump to
+   * nx_start().  We take extreme care here because were currently
+   * executing on this stack.
+   *
+   * We want to avoid sneak stack access generated by the compiler.
+   */
+
+  __asm__ __volatile__
+  (
+    "\tmovs r1, r1, lsr #2\n"   /* R1 = nwords = nbytes >> 2 */
+    "\tcmp  r1, #0\n"           /* Check (nwords == 0) */
+    "\tbeq  2f\n"               /* (should not happen) */
+
+    "\tbic  r0, r0, #3\n"       /* R0 = Aligned stackptr */
+    "\tmovw r2, #0xbeef\n"      /* R2 = STACK_COLOR = 0xdeadbeef */
+    "\tmovt r2, #0xdead\n"
+
+    "1:\n"                      /* Top of the loop */
+    "\tsub  r1, r1, #1\n"       /* R1 nwords-- */
+    "\tcmp  r1, #0\n"           /* Check (nwords == 0) */
+    "\tstr  r2, [r0], #4\n"     /* Save stack color word, increment stackptr */
+    "\tbne  1b\n"               /* Bottom of the loop */
+
+    "2:\n"
+    "\tmov  r14, #0\n"          /* LR = return address (none) */
+    "\tb    nx_start\n"         /* Branch to nx_start */
+  );
+}
+#endif
+
+/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -266,9 +312,16 @@ void __start(void)
 
   showprogress('\r');
   showprogress('\n');
+
+#ifdef CONFIG_STACK_COLORATION
+  /* Set the IDLE stack to the coloration value and jump into nx_start() */
+
+  go_nx_start((FAR void *)&_ebss, CONFIG_IDLETHREAD_STACKSIZE);
+#else
   nx_start();
 
   /* Shouldn't get here */
 
   for (; ; );
+#endif
 }