davids5 commented on a change in pull request #1369:
URL: https://github.com/apache/incubator-nuttx/pull/1369#discussion_r488176858



##########
File path: arch/arm/src/arm/arm_initialstate.c
##########
@@ -52,13 +52,7 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
+#define IDLETHREAD_STACKMARGIN    128

Review comment:
       @xiaoxiang781216  Does this 
   ```
   diff --git a/arch/arm/src/common/arm_usestack.c 
b/arch/arm/src/common/arm_usestack.c
   index b59b3baf39..6cef37b595 100644
   --- a/arch/arm/src/common/arm_usestack.c
   +++ b/arch/arm/src/common/arm_usestack.c
   @@ -153,11 +153,54 @@ int up_use_stack(struct tcb_s *tcb, void *stack, 
size_t stack_size)
      if (tcb->pid == 0)
        {
          /* The whole idle thread stack can't be colored here
   -       * because the code is running on the idle thead now.
   +       * because the code is running on the idle thread now.
   +       *
   +       * So let's see what we can do
           */
    
   +
   +      /* Some address on stack */
   +
   +      volatile uint32_t marker1;
   +
   +      /* Use register based variables */
   +
   +      register volatile uint32_t *sp;
   +      register uint32_t size;
   +
   +      /* Another address on stack */
   +
   +      volatile uint32_t marker2;
   +
   +      /* Assume we can not get a better value. */
   +
   +      size = tcb->adj_stack_size - STACK_MARGIN_IDLE;
   +
   +      /* point to the lower or the 2 address on the stack */
   +
   +      sp   = (&marker1 > &marker2) ? &marker2 : &marker1;
   +
   +
   +      /* Do a sanity check,
   +       * a) markers 1 and 2 are not the same
   +       * b) markers 1 and 2 are next each other (nothing in between)
   +       * c) sp is in this stack's extent 
   +       */
   +
   +      if (&marker1 != &marker2 &&
   +          sizeof(uint32_t) == (&marker1 > &marker2 ?
   +                              (uint8_t *)&marker1 - (uint8_t *)&marker2 :
   +                              (uint8_t *)&marker2 - (uint8_t *)&marker1) &&
   +                              (sp > (volatile uint32_t *)stack &&
   +                              sp < (volatile uint32_t *) 
tcb->adj_stack_ptr) &&
   +              (uintptr_t)sp  - (uintptr_t)stack >  size)
   +        {
   +          /* Use the batter value */
   +
   +          size = (uintptr_t) sp - (uintptr_t)stack;
   +        }
          arm_stack_color((FAR void *)((uintptr_t)tcb->adj_stack_ptr -
   -          tcb->adj_stack_size), tcb->adj_stack_size - STACK_MARGIN_IDLE);
   +          tcb->adj_stack_size), size);
        }
      else
        {
   ```
   address all you concerns.
   
   Full Stack colorizing  
   
![image](https://user-images.githubusercontent.com/1945821/93130126-f08c5280-f686-11ea-98df-13d06b36704e.png)
   
   119 bytes better
   
![image](https://user-images.githubusercontent.com/1945821/93130610-a061c000-f687-11ea-8c27-e5d732e191ac.png)
   
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to