summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cpukit/include/rtems/confdefs.h17
-rw-r--r--cpukit/include/rtems/libio_.h4
-rw-r--r--cpukit/include/rtems/score/interr.h2
-rw-r--r--cpukit/include/rtems/score/thread.h7
-rw-r--r--cpukit/include/rtems/sysinit.h1
-rw-r--r--cpukit/include/rtems/userenv.h6
-rw-r--r--cpukit/libcsupport/src/__usrenv.c14
-rw-r--r--cpukit/libcsupport/src/libio_init.c12
-rw-r--r--cpukit/libcsupport/src/privateenv.c67
-rw-r--r--cpukit/sapi/src/sysinitverbose.c10
10 files changed, 82 insertions, 58 deletions
diff --git a/cpukit/include/rtems/confdefs.h b/cpukit/include/rtems/confdefs.h
index 3741c9a706..0191392cfc 100644
--- a/cpukit/include/rtems/confdefs.h
+++ b/cpukit/include/rtems/confdefs.h
@@ -139,11 +139,6 @@ extern "C" {
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 3
#endif
-/*
- * POSIX key count used by the IO library.
- */
-#define _CONFIGURE_LIBIO_POSIX_KEYS 1
-
#ifdef CONFIGURE_INIT
rtems_libio_t rtems_libio_iops[CONFIGURE_MAXIMUM_FILE_DESCRIPTORS];
@@ -2073,14 +2068,6 @@ struct _reent *__getreent(void)
(CONFIGURE_MAXIMUM_POSIX_THREADS + CONFIGURE_MAXIMUM_TASKS))
#endif
-/*
- * This macro is calculated to specify the total number of
- * POSIX API keys required by the application and configured
- * system capabilities.
- */
-#define _CONFIGURE_POSIX_KEYS \
- (CONFIGURE_MAXIMUM_POSIX_KEYS + _CONFIGURE_LIBIO_POSIX_KEYS)
-
/**
* This configuration parameter specifies the maximum number of
* POSIX API threads.
@@ -2550,8 +2537,8 @@ struct _reent *__getreent(void)
CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS;
#endif
- #if _CONFIGURE_POSIX_KEYS > 0
- POSIX_KEYS_INFORMATION_DEFINE( _CONFIGURE_POSIX_KEYS );
+ #if CONFIGURE_MAXIMUM_POSIX_KEYS > 0
+ POSIX_KEYS_INFORMATION_DEFINE( CONFIGURE_MAXIMUM_POSIX_KEYS );
#endif
#if CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES > 0
diff --git a/cpukit/include/rtems/libio_.h b/cpukit/include/rtems/libio_.h
index cf80ea8075..2473bb5e5a 100644
--- a/cpukit/include/rtems/libio_.h
+++ b/cpukit/include/rtems/libio_.h
@@ -336,10 +336,6 @@ void rtems_filesystem_location_free( rtems_filesystem_location_info_t *loc );
*/
#include <rtems/userenv.h>
-void rtems_libio_free_user_env( void *env );
-
-extern pthread_key_t rtems_current_user_env_key;
-
void rtems_libio_lock( void );
void rtems_libio_unlock( void );
diff --git a/cpukit/include/rtems/score/interr.h b/cpukit/include/rtems/score/interr.h
index e57c415eed..2f449deedb 100644
--- a/cpukit/include/rtems/score/interr.h
+++ b/cpukit/include/rtems/score/interr.h
@@ -197,7 +197,7 @@ typedef enum {
INTERNAL_ERROR_BAD_THREAD_DISPATCH_ENVIRONMENT = 31,
INTERNAL_ERROR_RTEMS_INIT_TASK_CREATE_FAILED = 32,
INTERNAL_ERROR_POSIX_INIT_THREAD_CREATE_FAILED = 33,
- INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED = 34,
+ /* INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED = 34, */
/* INTERNAL_ERROR_LIBIO_SEM_CREATE_FAILED = 35, */
INTERNAL_ERROR_LIBIO_STDOUT_FD_OPEN_FAILED = 36,
INTERNAL_ERROR_LIBIO_STDERR_FD_OPEN_FAILED = 37,
diff --git a/cpukit/include/rtems/score/thread.h b/cpukit/include/rtems/score/thread.h
index 3e2e0638f8..2e7380f99a 100644
--- a/cpukit/include/rtems/score/thread.h
+++ b/cpukit/include/rtems/score/thread.h
@@ -43,6 +43,8 @@
#include <rtems/score/processormask.h>
#endif
+struct rtems_user_env_t;
+
struct _pthread_cleanup_context;
struct Per_CPU_Control;
@@ -859,6 +861,11 @@ struct _Thread_Control {
Thread_Capture_control Capture;
/**
+ * @brief Pointer to an optional thread-specific POSIX user environment.
+ */
+ struct rtems_user_env_t *user_environment;
+
+ /**
* @brief LIFO list of POSIX cleanup contexts.
*/
struct _pthread_cleanup_context *last_cleanup_context;
diff --git a/cpukit/include/rtems/sysinit.h b/cpukit/include/rtems/sysinit.h
index d181c42780..245da74f2c 100644
--- a/cpukit/include/rtems/sysinit.h
+++ b/cpukit/include/rtems/sysinit.h
@@ -68,6 +68,7 @@ extern "C" {
#define RTEMS_SYSINIT_POSIX_CLEANUP 001c00
#define RTEMS_SYSINIT_IDLE_THREADS 001d00
#define RTEMS_SYSINIT_LIBIO 001e00
+#define RTEMS_SYSINIT_USER_ENVIRONMENT 001e80
#define RTEMS_SYSINIT_ROOT_FILESYSTEM 001f00
#define RTEMS_SYSINIT_DRVMGR 002000
#define RTEMS_SYSINIT_MP_SERVER 002100
diff --git a/cpukit/include/rtems/userenv.h b/cpukit/include/rtems/userenv.h
index 7d6ffb05a5..2b66ee0951 100644
--- a/cpukit/include/rtems/userenv.h
+++ b/cpukit/include/rtems/userenv.h
@@ -53,10 +53,12 @@ extern "C" {
#endif
#endif
+typedef struct rtems_user_env_t rtems_user_env_t;
+
/**
* @brief User environment.
*/
-typedef struct {
+struct rtems_user_env_t {
/**
* @brief The anchor directory for relative paths.
*/
@@ -111,7 +113,7 @@ typedef struct {
* @brief The list of supplementary group IDs.
*/
gid_t groups[NGROUPS];
-} rtems_user_env_t;
+};
extern rtems_user_env_t rtems_global_user_env;
diff --git a/cpukit/libcsupport/src/__usrenv.c b/cpukit/libcsupport/src/__usrenv.c
index 611e0d7a92..cd191f33ea 100644
--- a/cpukit/libcsupport/src/__usrenv.c
+++ b/cpukit/libcsupport/src/__usrenv.c
@@ -24,6 +24,8 @@
#include <sys/stat.h>
#include <rtems/libio_.h>
+#include <rtems/score/percpu.h>
+#include <rtems/score/thread.h>
static int null_handler_open(
rtems_libio_t *iop,
@@ -249,4 +251,14 @@ rtems_user_env_t rtems_global_user_env = {
.umask = S_IWGRP | S_IWOTH
};
-pthread_key_t rtems_current_user_env_key;
+rtems_user_env_t *rtems_current_user_env_get(void)
+{
+ Thread_Control *executing = _Thread_Get_executing();
+ rtems_user_env_t *env = executing->user_environment;
+
+ if (env == NULL) {
+ return &rtems_global_user_env;
+ }
+
+ return env;
+}
diff --git a/cpukit/libcsupport/src/libio_init.c b/cpukit/libcsupport/src/libio_init.c
index 5b951ef2be..eccd5b2cd7 100644
--- a/cpukit/libcsupport/src/libio_init.c
+++ b/cpukit/libcsupport/src/libio_init.c
@@ -49,7 +49,6 @@ static void rtems_libio_init( void )
{
uint32_t i;
rtems_libio_t *iop;
- int eno;
if (rtems_libio_number_iops > 0)
{
@@ -59,17 +58,6 @@ static void rtems_libio_init( void )
iop->data1 = NULL;
rtems_libio_iop_free_tail = &iop->data1;
}
-
- /*
- * Create the posix key for user environment.
- */
- eno = pthread_key_create(
- &rtems_current_user_env_key,
- rtems_libio_free_user_env
- );
- if (eno != 0) {
- _Internal_error( INTERNAL_ERROR_LIBIO_USER_ENV_KEY_CREATE_FAILED );
- }
}
RTEMS_SYSINIT_ITEM(
diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c
index d7f5090c33..cd0154ba38 100644
--- a/cpukit/libcsupport/src/privateenv.c
+++ b/cpukit/libcsupport/src/privateenv.c
@@ -24,23 +24,15 @@
#include <rtems/libio_.h>
#include <rtems/score/threadimpl.h>
+#include <rtems/score/userextimpl.h>
+#include <rtems/sysinit.h>
/**
* Instantiate a private user environment for the calling thread.
*/
-rtems_user_env_t * rtems_current_user_env_get(void)
+static void rtems_libio_free_user_env(rtems_user_env_t *env)
{
- void *ptr = pthread_getspecific(rtems_current_user_env_key);
- if (ptr == NULL) {
- ptr = &rtems_global_user_env;
- }
- return (rtems_user_env_t *) ptr;
-}
-
-void rtems_libio_free_user_env(void *arg)
-{
- rtems_user_env_t *env = arg;
bool uses_global_env = env == &rtems_global_user_env;
if (!uses_global_env) {
@@ -72,16 +64,9 @@ rtems_status_code rtems_libio_set_private_env(void)
!rtems_filesystem_global_location_is_null(new_env->root_directory)
&& !rtems_filesystem_global_location_is_null(new_env->current_directory)
) {
- int eno = pthread_setspecific(
- rtems_current_user_env_key,
- new_env
- );
-
- if (eno == 0) {
- rtems_libio_free_user_env(old_env);
- } else {
- sc = RTEMS_TOO_MANY;
- }
+ Thread_Control *executing = _Thread_Get_executing();
+
+ executing->user_environment = new_env;
} else {
sc = RTEMS_UNSATISFIED;
}
@@ -107,10 +92,48 @@ void rtems_libio_use_global_env(void)
if (uses_private_env) {
Thread_Life_state life_state =
_Thread_Set_life_protection(THREAD_LIFE_PROTECTED);
+ Thread_Control *executing;
rtems_libio_free_user_env(env);
- pthread_setspecific(rtems_current_user_env_key, NULL);
+ executing = _Thread_Get_executing();
+ executing->user_environment = NULL;
_Thread_Set_life_protection(life_state);
}
}
+
+static void rtems_libio_env_thread_terminate(Thread_Control *the_thread)
+{
+ rtems_user_env_t *env = the_thread->user_environment;
+
+ if (env != NULL) {
+ rtems_libio_free_user_env(env);
+ }
+}
+
+static void rtems_libio_env_thread_restart(
+ Thread_Control *executing,
+ Thread_Control *the_thread
+)
+{
+ (void) executing;
+ rtems_libio_env_thread_terminate( the_thread );
+}
+
+static User_extensions_Control rtems_libio_env_extensions = {
+ .Callouts = {
+ .thread_restart = rtems_libio_env_thread_restart,
+ .thread_terminate = rtems_libio_env_thread_terminate
+ }
+};
+
+static void rtems_libio_env_init(void)
+{
+ _User_extensions_Add_API_set(&rtems_libio_env_extensions);
+}
+
+RTEMS_SYSINIT_ITEM(
+ rtems_libio_env_init,
+ RTEMS_SYSINIT_USER_ENVIRONMENT,
+ RTEMS_SYSINIT_ORDER_MIDDLE
+);
diff --git a/cpukit/sapi/src/sysinitverbose.c b/cpukit/sapi/src/sysinitverbose.c
index 7c8db2e5eb..50bc152bfd 100644
--- a/cpukit/sapi/src/sysinitverbose.c
+++ b/cpukit/sapi/src/sysinitverbose.c
@@ -86,6 +86,7 @@ SYSINIT_VERBOSE( POSIX_KEYS );
SYSINIT_VERBOSE( POSIX_CLEANUP );
SYSINIT_VERBOSE( IDLE_THREADS );
SYSINIT_VERBOSE( LIBIO );
+SYSINIT_VERBOSE( USER_ENVIRONMENT );
SYSINIT_VERBOSE( ROOT_FILESYSTEM );
SYSINIT_VERBOSE( DRVMGR );
SYSINIT_VERBOSE( MP_SERVER );
@@ -468,9 +469,16 @@ static void _Sysinit_Verbose_LIBIO( void )
}
}
+static void _Sysinit_Verbose_USER_ENVIRONMENT( void )
+{
+ if ( !SYSINIT_IS_ADJACENT( LIBIO, USER_ENVIRONMENT ) ) {
+ printk( "sysinit: USER_ENVIRONMENT: done\n" );
+ }
+}
+
static void _Sysinit_Verbose_ROOT_FILESYSTEM( void )
{
- if ( !SYSINIT_IS_ADJACENT( LIBIO, ROOT_FILESYSTEM ) ) {
+ if ( !SYSINIT_IS_ADJACENT( USER_ENVIRONMENT, ROOT_FILESYSTEM ) ) {
printk( "sysinit: ROOT_FILESYSTEM: done\n" );
}
}