mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 07:45:16 +08:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user