arch/: Implement Thread Local Storage for the rest of the architectures.

The change consisted on modifying *_usestack.c and *_createstack.c
This commit is contained in:
Ouss4
2020-05-06 00:45:16 +01:00
committed by patacongo
parent 3e00d182d2
commit 1e3ec6ecd0
26 changed files with 819 additions and 23 deletions
+45
View File
@@ -47,6 +47,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/arch.h>
#include <nuttx/tls.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
@@ -123,6 +124,24 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
#ifdef CONFIG_TLS
/* Add the size of the TLS information structure */
stack_size += sizeof(struct tls_info_s);
#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
#endif
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
@@ -143,6 +162,25 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* then create a zeroed stack to make stack dumps easier to trace.
*/
#ifdef CONFIG_TLS_ALIGNED
#ifdef CONFIG_MM_KERNEL_HEAP
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
tcb->stack_alloc_ptr =
(uint32_t *)kmm_memalign(TLS_STACK_ALIGN, stack_size);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
tcb->stack_alloc_ptr =
(uint32_t *)kumm_memalign(TLS_STACK_ALIGN, stack_size);
}
#else /* CONFIG_TLS_ALIGNED */
#ifdef CONFIG_MM_KERNEL_HEAP
/* Use the kernel allocator if this is a kernel thread */
@@ -157,6 +195,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
tcb->stack_alloc_ptr = (uint32_t *)kumm_malloc(stack_size);
}
#endif /* CONFIG_TLS_ALIGNED */
#ifdef CONFIG_DEBUG_FEATURES
/* Was the allocation successful? */
@@ -206,6 +245,12 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
tcb->adj_stack_ptr = (FAR uint32_t *)top_of_stack;
tcb->adj_stack_size = size_of_stack;
#ifdef CONFIG_TLS
/* Initialize the TLS data structure */
memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
#endif
board_autoled_on(LED_STACKCREATED);
return OK;
}
+48 -2
View File
@@ -47,6 +47,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/arch.h>
#include <nuttx/tls.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
@@ -115,6 +116,24 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
#ifdef CONFIG_TLS
/* Add the size of the TLS information structure */
stack_size += sizeof(struct tls_info_s);
#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
#endif
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
@@ -133,23 +152,44 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
/* Allocate the stack. If DEBUG is enabled (but not stack debug), then
* create a zeroed stack to make stack dumps easier to trace.
* If TLS is enabled, then we must allocate aligned stacks.
*/
#ifdef CONFIG_TLS_ALIGNED
#ifdef CONFIG_MM_KERNEL_HEAP
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
tcb->stack_alloc_ptr = (uint32_t *) kmm_malloc(stack_size);
tcb->stack_alloc_ptr =
(uint32_t *)kmm_memalign(TLS_STACK_ALIGN, stack_size);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
tcb->stack_alloc_ptr = (uint32_t *) kumm_malloc(stack_size);
tcb->stack_alloc_ptr =
(uint32_t *)kumm_memalign(TLS_STACK_ALIGN, stack_size);
}
#else /* CONFIG_TLS_ALIGNED */
#ifdef CONFIG_MM_KERNEL_HEAP
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
tcb->stack_alloc_ptr = (uint32_t *)kmm_malloc(stack_size);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
tcb->stack_alloc_ptr = (uint32_t *)kumm_malloc(stack_size);
}
#endif /* CONFIG_TLS_ALIGNED */
#ifdef CONFIG_DEBUG_FEATURES
/* Was the allocation successful? */
@@ -198,6 +238,12 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
tcb->adj_stack_ptr = (FAR uint32_t *) top_of_stack;
tcb->adj_stack_size = size_of_stack;
#ifdef CONFIG_TLS
/* Initialize the TLS data structure */
memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
#endif
board_autoled_on(LED_STACKCREATED);
return OK;
}