mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
arch: complete logic in create/use stack to support stack coloration.
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
@@ -159,5 +159,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||||||
|
|
||||||
memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
|
memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
|
||||||
|
|
||||||
|
#if defined(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((FAR void *)((uintptr_t)tcb->stack_alloc_ptr +
|
||||||
|
sizeof(struct tls_info_s)),
|
||||||
|
tcb->adj_stack_size - sizeof(struct tls_info_s));
|
||||||
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,5 +130,16 @@ int up_use_stack(FAR struct tcb_s *tcb, FAR void *stack, size_t stack_size)
|
|||||||
|
|
||||||
memset(stack, 0, sizeof(struct tls_info_s));
|
memset(stack, 0, sizeof(struct tls_info_s));
|
||||||
|
|
||||||
|
#if defined(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((FAR void *)((uintptr_t)tcb->stack_alloc_ptr +
|
||||||
|
sizeof(struct tls_info_s)),
|
||||||
|
tcb->adj_stack_size - sizeof(struct tls_info_s));
|
||||||
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,5 +342,11 @@ void up_usbuninitialize(void);
|
|||||||
# define up_usbuninitialize()
|
# define up_usbuninitialize()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Debug ********************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_STACK_COLORATION
|
||||||
|
void up_stack_color(FAR void *stackbase, size_t nbytes);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __ASSEMBLY__ */
|
#endif /* __ASSEMBLY__ */
|
||||||
#endif /* __ARCH_XTENSA_SRC_COMMON_XTENSA_H */
|
#endif /* __ARCH_XTENSA_SRC_COMMON_XTENSA_H */
|
||||||
|
|||||||
@@ -221,20 +221,14 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
|
|||||||
size_t size_of_stack;
|
size_t size_of_stack;
|
||||||
|
|
||||||
#ifdef CONFIG_STACK_COLORATION
|
#ifdef CONFIG_STACK_COLORATION
|
||||||
uint32_t *ptr;
|
/* If stack debug is enabled, then fill the stack with a
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Yes.. If stack debug is enabled, then fill the stack with a
|
|
||||||
* recognizable value that we can use later to test for high
|
* recognizable value that we can use later to test for high
|
||||||
* water marks.
|
* water marks.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (i = 0, ptr = (uint32_t *)tcb->stack_alloc_ptr;
|
up_stack_color((FAR void *)tcb->stack_alloc_ptr +
|
||||||
i < stack_size;
|
sizeof(struct tls_info_s),
|
||||||
i += sizeof(uint32_t))
|
stack_size - sizeof(struct tls_info_s));
|
||||||
{
|
|
||||||
*ptr++ = STACK_COLOR;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* XTENSA uses a push-down stack: the stack grows toward lower
|
/* XTENSA uses a push-down stack: the stack grows toward lower
|
||||||
@@ -295,3 +289,29 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
|
|||||||
|
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_stack_color
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write a well know value into the stack
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#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 = (uint32_t *)(((uintptr_t)stackbase + 3) & ~3);
|
||||||
|
uintptr_t stkend = (((uintptr_t)stackbase + nbytes) & ~3);
|
||||||
|
size_t nwords = (stkend - (uintptr_t)stackbase) >> 2;
|
||||||
|
|
||||||
|
/* Set the entire stack to the coloration value */
|
||||||
|
|
||||||
|
while (nwords-- > 0)
|
||||||
|
{
|
||||||
|
*stkptr++ = STACK_COLOR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -151,5 +151,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||||||
|
|
||||||
memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
|
memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
|
||||||
|
|
||||||
|
#if defined(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((FAR void *)((uintptr_t)tcb->stack_alloc_ptr +
|
||||||
|
sizeof(struct tls_info_s)),
|
||||||
|
tcb->adj_stack_size - sizeof(struct tls_info_s));
|
||||||
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user