summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorMatt Joyce <matthew.joyce@embedded-brains.de>2022-05-23 12:27:56 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2022-07-21 07:22:13 +0200
commit6d4b390f99af0e9d5873a3cb8ebaccfa05cbe37b (patch)
tree69d86bdace4793f3546d387fc00297917c234467 /cpukit
parentsptests: Disable Newlib reentrancy (diff)
downloadrtems-6d4b390f99af0e9d5873a3cb8ebaccfa05cbe37b.tar.bz2
Support _REENT_THREAD_LOCAL Newlib configuration
In case the Newlib _REENT_THREAD_LOCAL configuration option is enabled, the struct _reent is not defined (there is only a forward declaration in <sys/reent.h>). Instead, the usual members of struct _reent are available as dedicatd thread-local storage objects. Update #4560.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/include/rtems/confdefs/newlib.h3
-rw-r--r--cpukit/include/rtems/confdefs/threads.h6
-rw-r--r--cpukit/include/rtems/libcsupport.h28
-rw-r--r--cpukit/include/rtems/score/thread.h4
-rw-r--r--cpukit/libcsupport/src/getreentglobal.c2
-rw-r--r--cpukit/libcsupport/src/newlibc_reent.c6
6 files changed, 35 insertions, 14 deletions
diff --git a/cpukit/include/rtems/confdefs/newlib.h b/cpukit/include/rtems/confdefs/newlib.h
index 96bf850163..fef71a8855 100644
--- a/cpukit/include/rtems/confdefs/newlib.h
+++ b/cpukit/include/rtems/confdefs/newlib.h
@@ -57,7 +57,8 @@
extern "C" {
#endif
-#ifdef _CONFIGURE_ENABLE_NEWLIB_REENTRANCY
+#if defined(_CONFIGURE_ENABLE_NEWLIB_REENTRANCY) && \
+ !defined(_REENT_THREAD_LOCAL)
struct _reent *__getreent( void )
{
return _Thread_Get_executing()->libc_reent;
diff --git a/cpukit/include/rtems/confdefs/threads.h b/cpukit/include/rtems/confdefs/threads.h
index 503a4b20ec..8e4537f90b 100644
--- a/cpukit/include/rtems/confdefs/threads.h
+++ b/cpukit/include/rtems/confdefs/threads.h
@@ -159,7 +159,8 @@ struct Thread_Configured_control {
#if CONFIGURE_MAXIMUM_THREAD_NAME_SIZE > 1
char name[ CONFIGURE_MAXIMUM_THREAD_NAME_SIZE ];
#endif
- #ifdef _CONFIGURE_ENABLE_NEWLIB_REENTRANCY
+ #if defined(_CONFIGURE_ENABLE_NEWLIB_REENTRANCY) && \
+ !defined(_REENT_THREAD_LOCAL)
struct _reent Newlib;
#endif
};
@@ -175,7 +176,8 @@ const Thread_Control_add_on _Thread_Control_add_ons[] = {
),
offsetof( Thread_Configured_control, API_RTEMS )
}
- #ifdef _CONFIGURE_ENABLE_NEWLIB_REENTRANCY
+ #if defined(_CONFIGURE_ENABLE_NEWLIB_REENTRANCY) && \
+ !defined(_REENT_THREAD_LOCAL)
, {
offsetof(
Thread_Configured_control,
diff --git a/cpukit/include/rtems/libcsupport.h b/cpukit/include/rtems/libcsupport.h
index 212eb16e59..67a09dc2a2 100644
--- a/cpukit/include/rtems/libcsupport.h
+++ b/cpukit/include/rtems/libcsupport.h
@@ -96,27 +96,33 @@ extern int malloc_info(Heap_Information_block *the_info);
/*
* Prototypes required to install newlib reentrancy user extension
*/
+
+#ifdef _REENT_THREAD_LOCAL
+#define _NEWLIB_CREATE_HOOK NULL
+#else
bool newlib_create_hook(
rtems_tcb *current_task,
rtems_tcb *creating_task
);
+#define _NEWLIB_CREATE_HOOK newlib_create_hook
+#endif
void newlib_terminate_hook(
rtems_tcb *current_task
);
#define RTEMS_NEWLIB_EXTENSION \
-{ \
- newlib_create_hook, /* rtems_task_create */ \
- 0, /* rtems_task_start */ \
- 0, /* rtems_task_restart */ \
- 0, /* rtems_task_delete */ \
- 0, /* task_switch */ \
- 0, /* task_begin */ \
- 0, /* task_exitted */ \
- 0, /* fatal */ \
- newlib_terminate_hook /* thread terminate */ \
-}
+ { \
+ _NEWLIB_CREATE_HOOK, /* thread_create */ \
+ NULL, /* thread_start */ \
+ NULL, /* thread_restart */ \
+ NULL, /* thread_delete */ \
+ NULL, /* thread_switch */ \
+ NULL, /* thread_begin */ \
+ NULL, /* thread_exitted */ \
+ NULL, /* fatal */ \
+ newlib_terminate_hook /* thread_terminate */ \
+ }
typedef struct {
uint32_t active_barriers;
diff --git a/cpukit/include/rtems/score/thread.h b/cpukit/include/rtems/score/thread.h
index 2833a81710..f5a56887a4 100644
--- a/cpukit/include/rtems/score/thread.h
+++ b/cpukit/include/rtems/score/thread.h
@@ -921,8 +921,12 @@ struct _Thread_Control {
*/
Context_Control_fp *fp_context;
#endif
+
+#ifndef _REENT_THREAD_LOCAL
/** This field points to the newlib reentrancy structure for this thread. */
struct _reent *libc_reent;
+#endif
+
/** This array contains the API extension area pointers. */
void *API_Extensions[ THREAD_API_LAST + 1 ];
diff --git a/cpukit/libcsupport/src/getreentglobal.c b/cpukit/libcsupport/src/getreentglobal.c
index 72b513ee81..c64f09ac2c 100644
--- a/cpukit/libcsupport/src/getreentglobal.c
+++ b/cpukit/libcsupport/src/getreentglobal.c
@@ -15,8 +15,10 @@
#if defined(RTEMS_NEWLIB)
#include <sys/reent.h>
+#ifndef _REENT_THREAD_LOCAL
struct _reent *__getreent(void)
{
return _GLOBAL_REENT;
}
#endif
+#endif
diff --git a/cpukit/libcsupport/src/newlibc_reent.c b/cpukit/libcsupport/src/newlibc_reent.c
index 2dccfd0375..ee82f00858 100644
--- a/cpukit/libcsupport/src/newlibc_reent.c
+++ b/cpukit/libcsupport/src/newlibc_reent.c
@@ -29,6 +29,7 @@
#include <rtems/libcsupport.h>
#include <rtems/score/threadimpl.h>
+#ifndef _REENT_THREAD_LOCAL
bool newlib_create_hook(
rtems_tcb *current_task RTEMS_UNUSED,
rtems_tcb *creating_task
@@ -38,12 +39,17 @@ bool newlib_create_hook(
return true;
}
+#endif
void newlib_terminate_hook(
rtems_tcb *current_task
)
{
+#ifdef _REENT_THREAD_LOCAL
+ _reclaim_reent(NULL);
+#else
_reclaim_reent(current_task->libc_reent);
+#endif
}
#endif