From f3afb95aa1e6122df590828af663a1341f58c7b6 Mon Sep 17 00:00:00 2001 From: Paul Bartell Date: Thu, 30 Mar 2023 12:14:40 -0700 Subject: [PATCH] TLS: Add configRESET_TLS_BLOCK macro to reset TLS to default value Useful when calling libc functions in exception handlers. --- include/FreeRTOS.h | 12 ++++++++---- include/newlib-freertos.h | 9 +++++++++ include/picolibc-freertos.h | 4 ++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index f1ab32c6c1b..91fbf2fdd49 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -117,19 +117,23 @@ #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. + #error Missing definition: configTLS_BLOCK_TYPE must be defined when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. #endif #ifndef configINIT_TLS_BLOCK - #error Missing definition: configINIT_TLS_BLOCK must be defined in FreeRTOSConfig.h when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. + #error Missing definition: configINIT_TLS_BLOCK must be defined when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. #endif #ifndef configSET_TLS_BLOCK - #error Missing definition: configSET_TLS_BLOCK must be defined in FreeRTOSConfig.h when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. + #error Missing definition: configSET_TLS_BLOCK must be defined when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. + #endif + + #ifndef configRESET_TLS_BLOCK + #error Missing definition: configRESET_TLS_BLOCK must be defined when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. #endif #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. + #error Missing definition: configDEINIT_TLS_BLOCK must be defined when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. #endif #endif /* if ( configUSE_C_RUNTIME_TLS_SUPPORT == 1 ) */ diff --git a/include/newlib-freertos.h b/include/newlib-freertos.h index 23da603073d..7e9d366433a 100644 --- a/include/newlib-freertos.h +++ b/include/newlib-freertos.h @@ -65,6 +65,15 @@ while( 0 ) #endif /* configSET_TLS_BLOCK */ +#ifndef configRESET_TLS_BLOCK + #define configRESET_TLS_BLOCK() \ + do \ + { \ + _impure_ptr = _global_impure_ptr; \ + } \ + while( 0 ) +#endif /* configRESET_TLS_BLOCK */ + #ifndef configDEINIT_TLS_BLOCK #define configDEINIT_TLS_BLOCK( xTLSBlock ) \ do \ diff --git a/include/picolibc-freertos.h b/include/picolibc-freertos.h index 6be0b51de46..314725d5bfd 100644 --- a/include/picolibc-freertos.h +++ b/include/picolibc-freertos.h @@ -92,6 +92,10 @@ #define configSET_TLS_BLOCK( xTLSBlock ) _set_tls( xTLSBlock ) #endif /* configSET_TLS_BLOCK */ +#ifndef configRESET_TLS_BLOCK + #define configRESET_TLS_BLOCK( xTLSBlock ) +#endif /* configRESET_TLS_BLOCK */ + #ifndef configDEINIT_TLS_BLOCK #define configDEINIT_TLS_BLOCK( xTLSBlock ) #endif /* configDEINIT_TLS_BLOCK */