mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
arch: Add stack alignment and stack size checking when CONFIG_TLS_ALIGNED=y
Add validation to ensure allocated stack size does not exceed TLS_MAXSTACK when CONFIG_TLS_ALIGNED is enabled, and verify proper stack alignment using STACK_ALIGN_MASK across all architectures. This improves stack safety and prevents potential TLS overflow conditions. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
parent
3522ee372d
commit
a3273e6a96
20 changed files with 245 additions and 41 deletions
|
|
@ -77,10 +77,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -88,10 +88,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -74,10 +74,20 @@
|
|||
int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
||||
{
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -71,13 +71,21 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
uintptr_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT((uintptr_t)stack & (TLS_STACK_ALIGN - 1) == 0);
|
||||
#else
|
||||
DEBUGASSERT((uintptr_t)stack & STACK_ALIGN_MASK == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -75,10 +75,20 @@ int up_use_stack(FAR struct tcb_s *tcb, FAR void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -75,10 +75,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -73,6 +73,22 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,20 @@ int up_use_stack(FAR struct tcb_s *tcb, FAR void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
|
|
@ -75,10 +75,20 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
|||
size_t size_of_stack;
|
||||
|
||||
#ifdef CONFIG_TLS_ALIGNED
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
DEBUGASSERT(((uintptr_t)stack & STACK_ALIGN_MASK) == 0);
|
||||
|
||||
/* Is there already a stack allocated? */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue