arch: Colorize the idle thread stack in an unified way

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Idae8da53e5a4799a8edc0e882f17fd515b70cb14
This commit is contained in:
Xiang Xiao 2021-06-08 17:55:04 +08:00 committed by David Sidrane
parent dbf9c87a42
commit fa0d123f87
29 changed files with 352 additions and 53 deletions

View File

@ -62,8 +62,17 @@ void up_initial_state(struct tcb_s *tcb)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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.
*/
arm_stack_color(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
/* Initialize the initial exception register context structure */

View File

@ -64,8 +64,17 @@ void up_initial_state(struct tcb_s *tcb)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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.
*/
arm_stack_color(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
/* Initialize the initial exception register context structure */

View File

@ -62,8 +62,17 @@ void up_initial_state(struct tcb_s *tcb)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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.
*/
arm_stack_color(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
/* Initialize the initial exception register context structure */

View File

@ -65,8 +65,17 @@ void up_initial_state(struct tcb_s *tcb)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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.
*/
arm_stack_color(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
/* Initialize the initial exception register context structure */

View File

@ -62,8 +62,17 @@ void up_initial_state(struct tcb_s *tcb)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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.
*/
arm_stack_color(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
/* Initialize the initial exception register context structure */

View File

@ -65,8 +65,17 @@ void up_initial_state(struct tcb_s *tcb)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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.
*/
arm_stack_color(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
/* Initialize the initial exception register context structure */

View File

@ -173,7 +173,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 = INT32_ALIGN_DOWN((uintptr_t)stackbase + nbytes);
end = nbytes ? INT32_ALIGN_DOWN((uintptr_t)stackbase + nbytes) :
up_getsp(); /* 0: colorize the running stack */
/* Get the adjusted size based on the top and bottom of the stack */

View File

@ -61,9 +61,24 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)avr_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = STACK_COLOR;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -58,9 +58,24 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)avr_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = STACK_COLOR;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -58,9 +58,24 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -62,9 +62,24 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -59,9 +59,24 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -63,9 +63,24 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -225,7 +225,8 @@ 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);
uintptr_t stkend = nbytes ? (((uintptr_t)stackbase + nbytes) & ~3) :
up_getsp(); /* 0: colorize the running stack */
size_t nwords = (stkend - (uintptr_t)stackbase) >> 2;
/* Set the entire stack to the coloration value */

View File

@ -79,8 +79,17 @@ void up_initial_state(struct tcb_s *tcb)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
/* Initialize the initial exception register context structure */

View File

@ -60,9 +60,24 @@ void up_initial_state(FAR struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -65,9 +65,24 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -77,9 +77,24 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -238,7 +238,8 @@ void riscv_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);
uintptr_t stkend = nbytes ? (((uintptr_t)stackbase + nbytes) & ~3):
up_getsp(); /* 0: colorize the running stack */
size_t nwords = (stkend - (uintptr_t)stackbase) >> 2;
/* Set the entire stack to the coloration value */

View File

@ -63,8 +63,17 @@ void up_initial_state(struct tcb_s *tcb)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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.
*/
riscv_stack_color(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
/* Initialize the initial exception register context structure */

View File

@ -63,8 +63,17 @@ void up_initial_state(struct tcb_s *tcb)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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.
*/
riscv_stack_color(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
/* Initialize the initial exception register context structure */

View File

@ -156,7 +156,8 @@ 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);
uintptr_t stkend = nbytes ? (((uintptr_t)stackbase + nbytes) & ~3) :
up_getsp(); /* 0: colorize the running stack */
size_t nwords = (stkend - (uintptr_t)stackbase) >> 2;
/* Set the entire stack to the coloration value */

View File

@ -55,8 +55,17 @@ void up_initial_state(struct tcb_s *tcb)
{
tcb->stack_alloc_ptr = (void *)(up_getsp() -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
memset(&tcb->xcp, 0, sizeof(struct xcptcontext));

View File

@ -58,9 +58,24 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -59,9 +59,24 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)(g_idle_topstack -
CONFIG_IDLETHREAD_STACKSIZE);
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -280,7 +280,8 @@ void up_stack_color(FAR void *stackbase, size_t nbytes)
/* Take extra care that we do not write outside the stack boundaries */
start = STACK_ALIGN_UP((uintptr_t)stackbase);
end = STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes);
end = nbytes ? STACK_ALIGN_DOWN((uintptr_t)stackbase + nbytes) :
up_getsp(); /* 0: colorize the running stack */
/* Get the adjusted size based on the top and bottom of the stack */

View File

@ -63,8 +63,17 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = g_idlestack;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
#ifdef 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(tcb->stack_alloc_ptr, 0);
#endif /* CONFIG_STACK_COLORATION */
}
/* Initialize the initial exception register context structure */

View File

@ -57,8 +57,23 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)CONFIG_STACK_BASE;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)CONFIG_STACK_BASE;
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}

View File

@ -57,8 +57,23 @@ void up_initial_state(struct tcb_s *tcb)
if (tcb->pid == 0)
{
tcb->stack_alloc_ptr = (void *)CONFIG_STACK_BASE;
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
char *stack_ptr = (char *)CONFIG_STACK_BASE;
#ifdef CONFIG_STACK_COLORATION
char *stack_end = (char *)up_getsp();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
* water marks.
*/
while (stack_ptr < stack_end)
{
*--stack_end = 0xaa;
}
#endif /* CONFIG_STACK_COLORATION */
tcb->stack_alloc_ptr = stack_ptr;
tcb->stack_base_ptr = stack_ptr;
tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE;
}