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 2022/04/14 08:48:26 UTC

[incubator-nuttx] branch master updated (c2b69cc2c9 -> b3d47e246f)

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

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


    from c2b69cc2c9 RISC-V: mtimer register via SBI when S-mode is in use
     new 0c79ad9d8d arch/[arm|sparc]: replace INT32_ALIGN_* to STACK_ALIGN_*
     new b3d47e246f arch/stack_color: correct the stack top of running task

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/arm/src/common/arm_checkstack.c        | 56 +++++++++++++----------------
 arch/ceva/src/common/up_createstack.c       | 23 +++++++++---
 arch/or1k/src/common/up_createstack.c       | 23 +++++++++---
 arch/risc-v/src/common/riscv_createstack.c  | 30 ++++++++++------
 arch/sim/src/sim/up_createstack.c           | 23 +++++++++---
 arch/sparc/src/common/up_checkstack.c       | 54 ++++++++++++----------------
 arch/xtensa/src/common/xtensa_createstack.c | 30 ++++++++++------
 7 files changed, 139 insertions(+), 100 deletions(-)


[incubator-nuttx] 02/02: arch/stack_color: correct the stack top of running task

Posted by xi...@apache.org.
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/incubator-nuttx.git

commit b3d47e246fe62d0ad06ed7d7b719cdfd4f73681b
Author: chao.an <an...@xiaomi.com>
AuthorDate: Wed Apr 13 18:09:27 2022 +0800

    arch/stack_color: correct the stack top of running task
    
    This PR to ensure the stack pointer is locate to the stack top
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 arch/arm/src/common/arm_checkstack.c        | 30 ++++++++++++++++++-----------
 arch/ceva/src/common/up_createstack.c       | 23 +++++++++++++++++-----
 arch/or1k/src/common/up_createstack.c       | 23 +++++++++++++++++-----
 arch/risc-v/src/common/riscv_createstack.c  | 30 ++++++++++++++++++-----------
 arch/sim/src/sim/up_createstack.c           | 23 +++++++++++++++++-----
 arch/sparc/src/common/up_checkstack.c       | 30 ++++++++++++++++++-----------
 arch/xtensa/src/common/xtensa_createstack.c | 30 ++++++++++++++++++-----------
 7 files changed, 130 insertions(+), 59 deletions(-)

diff --git a/arch/arm/src/common/arm_checkstack.c b/arch/arm/src/common/arm_checkstack.c
index 54fc37917c..31d583be7c 100644
--- a/arch/arm/src/common/arm_checkstack.c
+++ b/arch/arm/src/common/arm_checkstack.c
@@ -148,28 +148,36 @@ static size_t do_stackcheck(FAR void *stackbase, size_t nbytes)
 
 void arm_stack_color(FAR void *stackbase, size_t nbytes)
 {
-  uintptr_t start;
-  uintptr_t end;
-  size_t nwords;
-  FAR uint32_t *ptr;
+  uint32_t *stkptr;
+  uintptr_t stkend;
+  size_t    nwords;
   uintptr_t sp;
 
   /* Take extra care that we do not write outside the stack boundaries */
 
-  start = STACK_ALIGN_UP((uintptr_t)stackbase);
-  end   = nbytes ? STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes) :
-          (uintptr_t)&sp; /* 0: colorize the running stack */
+  stkptr = (uint32_t *)STACK_ALIGN_UP((uintptr_t)stackbase);
 
-  /* Get the adjusted size based on the top and bottom of the stack */
+  if (nbytes == 0) /* 0: colorize the running stack */
+    {
+      stkend = up_getsp();
+      if (stkend > (uintptr_t)&sp)
+        {
+          stkend = (uintptr_t)&sp;
+        }
+    }
+  else
+    {
+      stkend = (uintptr_t)stackbase + nbytes;
+    }
 
-  nwords = (end - start) >> 2;
-  ptr  = (FAR uint32_t *)start;
+  stkend = STACK_ALIGN_DOWN(stkend);
+  nwords = (stkend - (uintptr_t)stackbase) >> 2;
 
   /* Set the entire stack to the coloration value */
 
   while (nwords-- > 0)
     {
-      *ptr++ = STACK_COLOR;
+      *stkptr++ = STACK_COLOR;
     }
 }
 
diff --git a/arch/ceva/src/common/up_createstack.c b/arch/ceva/src/common/up_createstack.c
index d0ba7d28ac..1f4eacd886 100644
--- a/arch/ceva/src/common/up_createstack.c
+++ b/arch/ceva/src/common/up_createstack.c
@@ -230,16 +230,29 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
 #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;
   uintptr_t stkend;
   size_t    nwords;
   uintptr_t sp;
 
-  stkptr = (uint32_t *)(((uintptr_t)stackbase + 3) & ~3);
-  stkend = nbytes ? (((uintptr_t)stackbase + nbytes) & ~3) :
-           (uintptr_t)&sp; /* 0: colorize the running stack */
+  /* Take extra care that we do not write outside the stack boundaries */
+
+  stkptr = (uint32_t *)STACK_ALIGN_UP((uintptr_t)stackbase);
+
+  if (nbytes == 0) /* 0: colorize the running stack */
+    {
+      stkend = up_getsp();
+      if (stkend > (uintptr_t)&sp)
+        {
+          stkend = (uintptr_t)&sp;
+        }
+    }
+  else
+    {
+      stkend = (uintptr_t)stackbase + nbytes;
+    }
+
+  stkend = STACK_ALIGN_DOWN(stkend);
   nwords = (stkend - (uintptr_t)stackbase) >> 2;
 
   /* Set the entire stack to the coloration value */
diff --git a/arch/or1k/src/common/up_createstack.c b/arch/or1k/src/common/up_createstack.c
index 731c5b64b0..983e9d4d12 100644
--- a/arch/or1k/src/common/up_createstack.c
+++ b/arch/or1k/src/common/up_createstack.c
@@ -203,16 +203,29 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
 #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;
   uintptr_t stkend;
   size_t    nwords;
   uintptr_t sp;
 
-  stkptr = (uint32_t *)(((uintptr_t)stackbase + 3) & ~3);
-  stkend = nbytes ? (((uintptr_t)stackbase + nbytes) & ~3) :
-           (uintptr_t)&sp; /* 0: colorize the running stack */
+  /* Take extra care that we do not write outside the stack boundaries */
+
+  stkptr = (uint32_t *)STACK_ALIGN_UP((uintptr_t)stackbase);
+
+  if (nbytes == 0) /* 0: colorize the running stack */
+    {
+      stkend = up_getsp();
+      if (stkend > (uintptr_t)&sp)
+        {
+          stkend = (uintptr_t)&sp;
+        }
+    }
+  else
+    {
+      stkend = (uintptr_t)stackbase + nbytes;
+    }
+
+  stkend = STACK_ALIGN_DOWN(stkend);
   nwords = (stkend - (uintptr_t)stackbase) >> 2;
 
   /* Set the entire stack to the coloration value */
diff --git a/arch/risc-v/src/common/riscv_createstack.c b/arch/risc-v/src/common/riscv_createstack.c
index d8a27bcb42..c15e1b0e81 100644
--- a/arch/risc-v/src/common/riscv_createstack.c
+++ b/arch/risc-v/src/common/riscv_createstack.c
@@ -213,28 +213,36 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
 #ifdef CONFIG_STACK_COLORATION
 void riscv_stack_color(void *stackbase, size_t nbytes)
 {
-  uintptr_t start;
-  uintptr_t end;
-  size_t nwords;
-  uint32_t *ptr;
+  uint32_t *stkptr;
+  uintptr_t stkend;
+  size_t    nwords;
   uintptr_t sp;
 
   /* Take extra care that we do not write outside the stack boundaries */
 
-  start = STACK_ALIGN_UP((uintptr_t)stackbase);
-  end   = nbytes ? STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes) :
-          (uintptr_t)&sp; /* 0: colorize the running stack */
+  stkptr = (uint32_t *)STACK_ALIGN_UP((uintptr_t)stackbase);
 
-  /* Get the adjusted size based on the top and bottom of the stack */
+  if (nbytes == 0) /* 0: colorize the running stack */
+    {
+      stkend = up_getsp();
+      if (stkend > (uintptr_t)&sp)
+        {
+          stkend = (uintptr_t)&sp;
+        }
+    }
+  else
+    {
+      stkend = (uintptr_t)stackbase + nbytes;
+    }
 
-  nwords = (end - start) >> 2;
-  ptr  = (uint32_t *)start;
+  stkend = STACK_ALIGN_DOWN(stkend);
+  nwords = (stkend - (uintptr_t)stackbase) >> 2;
 
   /* Set the entire stack to the coloration value */
 
   while (nwords-- > 0)
     {
-      *ptr++ = STACK_COLOR;
+      *stkptr++ = STACK_COLOR;
     }
 }
 #endif
diff --git a/arch/sim/src/sim/up_createstack.c b/arch/sim/src/sim/up_createstack.c
index 71381f3b29..a079abab68 100644
--- a/arch/sim/src/sim/up_createstack.c
+++ b/arch/sim/src/sim/up_createstack.c
@@ -159,16 +159,29 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
 void nostackprotect_function up_stack_color(FAR void *stackbase,
                                             size_t nbytes)
 {
-  /* Take extra care that we do not write outsize the stack boundaries */
-
   uint32_t *stkptr;
   uintptr_t stkend;
   size_t    nwords;
   uintptr_t sp;
 
-  stkptr = (uint32_t *)(((uintptr_t)stackbase + 3) & ~3);
-  stkend = nbytes ? (((uintptr_t)stackbase + nbytes) & ~3) :
-           (uintptr_t)&sp; /* 0: colorize the running stack */
+  /* Take extra care that we do not write outside the stack boundaries */
+
+  stkptr = (uint32_t *)STACK_ALIGN_UP((uintptr_t)stackbase);
+
+  if (nbytes == 0) /* 0: colorize the running stack */
+    {
+      stkend = up_getsp();
+      if (stkend > (uintptr_t)&sp)
+        {
+          stkend = (uintptr_t)&sp;
+        }
+    }
+  else
+    {
+      stkend = (uintptr_t)stackbase + nbytes;
+    }
+
+  stkend = STACK_ALIGN_DOWN(stkend);
   nwords = (stkend - (uintptr_t)stackbase) >> 2;
 
   /* Set the entire stack to the coloration value */
diff --git a/arch/sparc/src/common/up_checkstack.c b/arch/sparc/src/common/up_checkstack.c
index ca80866696..50825498de 100644
--- a/arch/sparc/src/common/up_checkstack.c
+++ b/arch/sparc/src/common/up_checkstack.c
@@ -149,28 +149,36 @@ static size_t do_stackcheck(FAR void *stackbase, size_t nbytes)
 
 void up_stack_color(FAR void *stackbase, size_t nbytes)
 {
-  uintptr_t start;
-  uintptr_t end;
-  size_t nwords;
-  FAR uint32_t *ptr;
+  uint32_t *stkptr;
+  uintptr_t stkend;
+  size_t    nwords;
   uintptr_t sp;
 
   /* Take extra care that we do not write outside the stack boundaries */
 
-  start = STACK_ALIGN_UP((uintptr_t)stackbase);
-  end   = nbytes ? STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes) :
-          (uintptr_t)&sp; /* 0: colorize the running stack */
+  stkptr = (uint32_t *)STACK_ALIGN_UP((uintptr_t)stackbase);
 
-  /* Get the adjusted size based on the top and bottom of the stack */
+  if (nbytes == 0) /* 0: colorize the running stack */
+    {
+      stkend = up_getsp();
+      if (stkend > (uintptr_t)&sp)
+        {
+          stkend = (uintptr_t)&sp;
+        }
+    }
+  else
+    {
+      stkend = (uintptr_t)stackbase + nbytes;
+    }
 
-  nwords = (end - start) >> 2;
-  ptr  = (FAR uint32_t *)start;
+  stkend = STACK_ALIGN_DOWN(stkend);
+  nwords = (stkend - (uintptr_t)stackbase) >> 2;
 
   /* Set the entire stack to the coloration value */
 
   while (nwords-- > 0)
     {
-      *ptr++ = STACK_COLOR;
+      *stkptr++ = STACK_COLOR;
     }
 }
 
diff --git a/arch/xtensa/src/common/xtensa_createstack.c b/arch/xtensa/src/common/xtensa_createstack.c
index aeea6c2c8a..d8a972ee08 100644
--- a/arch/xtensa/src/common/xtensa_createstack.c
+++ b/arch/xtensa/src/common/xtensa_createstack.c
@@ -219,28 +219,36 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
 #ifdef CONFIG_STACK_COLORATION
 void xtensa_stack_color(void *stackbase, size_t nbytes)
 {
-  uintptr_t start;
-  uintptr_t end;
-  size_t nwords;
-  uint32_t *ptr;
+  uint32_t *stkptr;
+  uintptr_t stkend;
+  size_t    nwords;
   uintptr_t sp;
 
   /* Take extra care that we do not write outside the stack boundaries */
 
-  start = STACK_ALIGN_UP((uintptr_t)stackbase);
-  end   = nbytes ? STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes) :
-          (uintptr_t)&sp; /* 0: colorize the running stack */
+  stkptr = (uint32_t *)STACK_ALIGN_UP((uintptr_t)stackbase);
 
-  /* Get the adjusted size based on the top and bottom of the stack */
+  if (nbytes == 0) /* 0: colorize the running stack */
+    {
+      stkend = up_getsp();
+      if (stkend > (uintptr_t)&sp)
+        {
+          stkend = (uintptr_t)&sp;
+        }
+    }
+  else
+    {
+      stkend = (uintptr_t)stackbase + nbytes;
+    }
 
-  nwords = (end - start) >> 2;
-  ptr  = (uint32_t *)start;
+  stkend = STACK_ALIGN_DOWN(stkend);
+  nwords = (stkend - (uintptr_t)stackbase) >> 2;
 
   /* Set the entire stack to the coloration value */
 
   while (nwords-- > 0)
     {
-      *ptr++ = STACK_COLOR;
+      *stkptr++ = STACK_COLOR;
     }
 }
 #endif


[incubator-nuttx] 01/02: arch/[arm|sparc]: replace INT32_ALIGN_* to STACK_ALIGN_*

Posted by xi...@apache.org.
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/incubator-nuttx.git

commit 0c79ad9d8d16acbcb98108a4d673e13d19f06322
Author: chao.an <an...@xiaomi.com>
AuthorDate: Wed Apr 13 18:04:41 2022 +0800

    arch/[arm|sparc]: replace INT32_ALIGN_* to STACK_ALIGN_*
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 arch/arm/src/common/arm_checkstack.c  | 30 +++++++-----------------------
 arch/sparc/src/common/up_checkstack.c | 28 ++++++----------------------
 2 files changed, 13 insertions(+), 45 deletions(-)

diff --git a/arch/arm/src/common/arm_checkstack.c b/arch/arm/src/common/arm_checkstack.c
index 08dd03a0b4..54fc37917c 100644
--- a/arch/arm/src/common/arm_checkstack.c
+++ b/arch/arm/src/common/arm_checkstack.c
@@ -38,22 +38,6 @@
 
 #ifdef CONFIG_STACK_COLORATION
 
-/****************************************************************************
- * Pre-processor Macros
- ****************************************************************************/
-
-/* 32bit alignment macros */
-
-#define INT32_ALIGN_MASK    (3)
-#define INT32_ALIGN_DOWN(a) ((a) & ~INT32_ALIGN_MASK)
-#define INT32_ALIGN_UP(a)   (((a) + INT32_ALIGN_MASK) & ~INT32_ALIGN_MASK)
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static size_t do_stackcheck(FAR void *stackbase, size_t nbytes);
-
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -89,8 +73,8 @@ static size_t do_stackcheck(FAR void *stackbase, size_t nbytes)
 
   /* Take extra care that we do not check outside the stack boundaries */
 
-  start = INT32_ALIGN_UP((uintptr_t)stackbase);
-  end   = INT32_ALIGN_DOWN((uintptr_t)stackbase + nbytes);
+  start = STACK_ALIGN_UP((uintptr_t)stackbase);
+  end   = STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes);
 
   /* Get the adjusted size based on the top and bottom of the stack */
 
@@ -172,8 +156,8 @@ void arm_stack_color(FAR void *stackbase, size_t nbytes)
 
   /* Take extra care that we do not write outside the stack boundaries */
 
-  start = INT32_ALIGN_UP((uintptr_t)stackbase);
-  end   = nbytes ? INT32_ALIGN_DOWN((uintptr_t)stackbase + nbytes) :
+  start = STACK_ALIGN_UP((uintptr_t)stackbase);
+  end   = nbytes ? STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes) :
           (uintptr_t)&sp; /* 0: colorize the running stack */
 
   /* Get the adjusted size based on the top and bottom of the stack */
@@ -230,16 +214,16 @@ size_t up_check_intstack(void)
 {
 #ifdef CONFIG_SMP
   return do_stackcheck((FAR void *)arm_intstack_alloc(),
-                        INT32_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
+                        STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
 #else
   return do_stackcheck((FAR void *)&g_intstackalloc,
-                        INT32_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
+                        STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
 #endif
 }
 
 size_t up_check_intstack_remain(void)
 {
-  return INT32_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK) - up_check_intstack();
+  return STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK) - up_check_intstack();
 }
 #endif
 
diff --git a/arch/sparc/src/common/up_checkstack.c b/arch/sparc/src/common/up_checkstack.c
index b1d9cca520..ca80866696 100644
--- a/arch/sparc/src/common/up_checkstack.c
+++ b/arch/sparc/src/common/up_checkstack.c
@@ -39,22 +39,6 @@
 
 #ifdef CONFIG_STACK_COLORATION
 
-/****************************************************************************
- * Pre-processor Macros
- ****************************************************************************/
-
-/* 32bit alignment macros */
-
-#define INT32_ALIGN_MASK    (3)
-#define INT32_ALIGN_DOWN(a) ((a) & ~INT32_ALIGN_MASK)
-#define INT32_ALIGN_UP(a)   (((a) + INT32_ALIGN_MASK) & ~INT32_ALIGN_MASK)
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static size_t do_stackcheck(FAR void *stackbase, size_t nbytes);
-
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -90,8 +74,8 @@ static size_t do_stackcheck(FAR void *stackbase, size_t nbytes)
 
   /* Take extra care that we do not check outside the stack boundaries */
 
-  start = INT32_ALIGN_UP((uintptr_t)stackbase);
-  end   = INT32_ALIGN_DOWN((uintptr_t)stackbase + nbytes);
+  start = STACK_ALIGN_UP((uintptr_t)stackbase);
+  end   = STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes);
 
   /* Get the adjusted size based on the top and bottom of the stack */
 
@@ -173,8 +157,8 @@ void up_stack_color(FAR void *stackbase, size_t nbytes)
 
   /* Take extra care that we do not write outside the stack boundaries */
 
-  start = INT32_ALIGN_UP((uintptr_t)stackbase);
-  end   = nbytes ? INT32_ALIGN_DOWN((uintptr_t)stackbase + nbytes) :
+  start = STACK_ALIGN_UP((uintptr_t)stackbase);
+  end   = nbytes ? STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes) :
           (uintptr_t)&sp; /* 0: colorize the running stack */
 
   /* Get the adjusted size based on the top and bottom of the stack */
@@ -230,12 +214,12 @@ ssize_t up_check_stack_remain(void)
 size_t up_check_intstack(void)
 {
   return do_stackcheck((uintptr_t)&g_intstackalloc,
-                       (CONFIG_ARCH_INTERRUPTSTACK & ~3));
+                       STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
 }
 
 size_t up_check_intstack_remain(void)
 {
-  return (CONFIG_ARCH_INTERRUPTSTACK & ~3) - up_check_intstack();
+  return STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK) - up_check_intstack();
 }
 #endif