mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
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 <anchao@xiaomi.com>
This commit is contained in:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user