mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-08-19 09:38:32 -04:00
Add Thread Local Storage (TLS) support using Picolibc functions (#343)
* Pass top of stack to configINIT_TLS_BLOCK Picolibc wants to allocate the per-task TLS block within the stack segment, so it will need to modify the top of stack value. Pass the pxTopOfStack variable to make this explicit. Signed-off-by: Keith Packard <keithpac@amazon.com> * Move newlib-specific definitions to separate file This reduces the clutter in FreeRTOS.h caused by having newlib-specific macros present there. Signed-off-by: Keith Packard <keithpac@amazon.com> * Make TLS code depend only on configUSE_C_RUNTIME_TLS_SUPPORT Remove reference to configUSE_NEWLIB_REENTRANT as that only works when using newlib. configUSE_C_RUNTIME_TLS_SUPPORT is always set when configUSE_NEWLIB_REENTRANT is set, so using both was redundant in that case. Signed-off-by: Keith Packard <keithpac@amazon.com> * portable-ARC: Adapt ARC support to use generalized TLS support With generalized thread local storage (TLS) support present in the core, the two ARC ports need to have the changes to the TCB mirrored to them. Signed-off-by: Keith Packard <keithpac@amazon.com> * Add Thread Local Storage (TLS) support using Picolibc functions This patch provides definitions of the general TLS support macros in terms of the Picolibc TLS support functions. Picolibc is normally configured to use TLS internally for all variables that are intended to be task-local, so these changes are necessary for picolibc to work correctly with FreeRTOS. The picolibc helper functions rely on elements within the linker script to arrange the TLS data in memory and define some symbols. Applications wanting to use this mechanism will need changes in their linker script when migrating to picolibc. Signed-off-by: Keith Packard <keithpac@amazon.com> --------- Signed-off-by: Keith Packard <keithpac@amazon.com> Co-authored-by: Keith Packard <keithpac@amazon.com> Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
This commit is contained in:
parent
e6514fb1ed
commit
c3e1df031e
7 changed files with 158 additions and 56 deletions
|
@ -95,41 +95,26 @@
|
|||
/* Required if struct _reent is used. */
|
||||
#if ( configUSE_NEWLIB_REENTRANT == 1 )
|
||||
|
||||
/* Note Newlib support has been included by popular demand, but is not
|
||||
* used by the FreeRTOS maintainers themselves. FreeRTOS is not
|
||||
* responsible for resulting newlib operation. User must be familiar with
|
||||
* newlib and must provide system-wide implementations of the necessary
|
||||
* stubs. Be warned that (at the time of writing) the current newlib design
|
||||
* implements a system-wide malloc() that must be provided with locks.
|
||||
*
|
||||
* See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html
|
||||
* for additional information. */
|
||||
#include <reent.h>
|
||||
#include "newlib-freertos.h"
|
||||
|
||||
#define configUSE_C_RUNTIME_TLS_SUPPORT 1
|
||||
|
||||
#ifndef configTLS_BLOCK_TYPE
|
||||
#define configTLS_BLOCK_TYPE struct _reent
|
||||
#endif
|
||||
|
||||
#ifndef configINIT_TLS_BLOCK
|
||||
#define configINIT_TLS_BLOCK( xTLSBlock ) _REENT_INIT_PTR( &( xTLSBlock ) )
|
||||
#endif
|
||||
|
||||
#ifndef configSET_TLS_BLOCK
|
||||
#define configSET_TLS_BLOCK( xTLSBlock ) ( _impure_ptr = &( xTLSBlock ) )
|
||||
#endif
|
||||
|
||||
#ifndef configDEINIT_TLS_BLOCK
|
||||
#define configDEINIT_TLS_BLOCK( xTLSBlock ) _reclaim_reent( &( xTLSBlock ) )
|
||||
#endif
|
||||
#endif /* if ( configUSE_NEWLIB_REENTRANT == 1 ) */
|
||||
|
||||
/* Must be defaulted before configUSE_PICOLIBC_TLS is used below. */
|
||||
#ifndef configUSE_PICOLIBC_TLS
|
||||
#define configUSE_PICOLIBC_TLS 0
|
||||
#endif
|
||||
|
||||
#if ( configUSE_PICOLIBC_TLS == 1 )
|
||||
|
||||
#include "picolibc-freertos.h"
|
||||
|
||||
#endif /* if ( configUSE_PICOLIBC_TLS == 1 ) */
|
||||
|
||||
#ifndef configUSE_C_RUNTIME_TLS_SUPPORT
|
||||
#define configUSE_C_RUNTIME_TLS_SUPPORT 0
|
||||
#endif
|
||||
|
||||
#if ( ( configUSE_NEWLIB_REENTRANT == 0 ) && ( configUSE_C_RUNTIME_TLS_SUPPORT == 1 ) )
|
||||
#if ( configUSE_C_RUNTIME_TLS_SUPPORT == 1 )
|
||||
|
||||
#ifndef configTLS_BLOCK_TYPE
|
||||
#error Missing definition: configTLS_BLOCK_TYPE must be defined in FreeRTOSConfig.h when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1.
|
||||
|
@ -146,7 +131,7 @@
|
|||
#ifndef configDEINIT_TLS_BLOCK
|
||||
#error Missing definition: configDEINIT_TLS_BLOCK must be defined in FreeRTOSConfig.h when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1.
|
||||
#endif
|
||||
#endif /* if ( ( configUSE_NEWLIB_REENTRANT == 0 ) && ( configUSE_C_RUNTIME_TLS_SUPPORT == 1 ) ) */
|
||||
#endif /* if ( configUSE_C_RUNTIME_TLS_SUPPORT == 1 ) */
|
||||
|
||||
/*
|
||||
* Check all the required application specific macros have been defined.
|
||||
|
@ -1306,7 +1291,7 @@ typedef struct xSTATIC_TCB
|
|||
#if ( configGENERATE_RUN_TIME_STATS == 1 )
|
||||
configRUN_TIME_COUNTER_TYPE ulDummy16;
|
||||
#endif
|
||||
#if ( ( configUSE_NEWLIB_REENTRANT == 1 ) || ( configUSE_C_RUNTIME_TLS_SUPPORT == 1 ) )
|
||||
#if ( configUSE_C_RUNTIME_TLS_SUPPORT == 1 )
|
||||
configTLS_BLOCK_TYPE xDummy17;
|
||||
#endif
|
||||
#if ( configUSE_TASK_NOTIFICATIONS == 1 )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue