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
+46
View File
@@ -31,6 +31,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/arch.h>
#include <nuttx/tls.h>
#include <nuttx/board.h>
#include "z80_arch.h"
@@ -87,6 +88,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.
@@ -105,8 +124,28 @@ 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_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 */
@@ -121,6 +160,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? */
@@ -169,6 +209,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;
}
+13
View File
@@ -30,6 +30,7 @@
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/arch.h>
#include <nuttx/tls.h>
#include "z80_internal.h"
@@ -78,6 +79,12 @@ 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
/* Make certain that the user provided stack is properly aligned */
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
#endif
/* Is there already a stack allocated? */
if (tcb->stack_alloc_ptr)
@@ -111,5 +118,11 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
tcb->adj_stack_size = 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
return OK;
}