This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 52bf792d02e9ad42f58494713c4ec15c2e3f59c8 Author: guoshichao <[email protected]> AuthorDate: Mon Nov 10 17:25:55 2025 +0800 environ: move the environ from sched/environ to libc/environ change the environ implementation from sched/environ to libc/environ, thus we can access the environ related API can vai libc directl, which could improve the access speed in kernel build. And in order to support this modification, we change the struct task_info_s's ta_lock from nxmutex_t to nxrmutex_t, this is because the env_*-related APIs require the ta_lock to be reentrant. If recursive locks are not supported, it may lead to deadlocks in certain scenarios. For example, during initialization on the qemu-miwear platform, it is necessary to call getenv while already holding the ta_lock. To support such cases, we need to change the ta_lock from nxmutex_t to nxrmutex_t. Signed-off-by: guoshichao <[email protected]> (cherry picked from commit 2c27af036bc927617fad72b85607bccad3c2564d in https://github.com/open-vela/nuttx) Port to Apache master: keep the master code around each conflict and change only the environ calls; move env_secureexec.c (env_sanitize_secure() takes the task info, declared in nuttx/environ.h); keep the clearenv() lock from dc4c846d329; task_uninit_info() releases the environment and stays where group_release() calls it; include the headers that openvela gets indirectly (nuttx/lib/lib.h, stdio.h, string.h). Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- binfmt/binfmt_execmodule.c | 4 +- fs/procfs/fs_procfsproc.c | 2 +- include/nuttx/environ.h | 71 ++++++++++++++++++- include/nuttx/tls.h | 2 +- include/sys/syscall_lookup.h | 11 --- libs/libc/Makefile | 1 + {sched => libs/libc}/environ/CMakeLists.txt | 30 ++++----- {sched => libs/libc}/environ/Make.defs | 2 +- {sched => libs/libc}/environ/env_clearenv.c | 27 ++------ {sched => libs/libc}/environ/env_dup.c | 33 +++------ {sched => libs/libc}/environ/env_findvar.c | 19 ++---- {sched => libs/libc}/environ/env_foreach.c | 20 ++---- {sched => libs/libc}/environ/env_getenv.c | 47 ++++--------- {sched => libs/libc}/environ/env_getenvironptr.c | 16 +---- {sched => libs/libc}/environ/env_putenv.c | 12 +--- {sched => libs/libc}/environ/env_release.c | 32 +++------ {sched => libs/libc}/environ/env_removevar.c | 29 ++------ {sched => libs/libc}/environ/env_secureexec.c | 17 ++--- {sched => libs/libc}/environ/env_setenv.c | 44 +++++------- {sched => libs/libc}/environ/env_unsetenv.c | 29 +++----- {sched => libs/libc}/environ/environ.h | 86 ++++-------------------- libs/libc/pthread/pthread_atfork.c | 4 +- libs/libc/pthread/pthread_keycreate.c | 4 +- libs/libc/pthread/pthread_keydelete.c | 4 +- libs/libc/stdlib/lib_atexit.c | 8 +-- libs/libc/unistd/lib_fork.c | 12 ++-- sched/Makefile | 1 - sched/group/group_join.c | 1 - sched/group/group_leave.c | 5 -- sched/task/task_fork.c | 4 +- sched/task/task_init.c | 4 +- sched/tls/task_initinfo.c | 2 +- sched/tls/task_uninitinfo.c | 7 +- syscall/syscall.csv | 6 -- 34 files changed, 220 insertions(+), 376 deletions(-) diff --git a/binfmt/binfmt_execmodule.c b/binfmt/binfmt_execmodule.c index dc33d9baee1..42b705d5634 100644 --- a/binfmt/binfmt_execmodule.c +++ b/binfmt/binfmt_execmodule.c @@ -44,9 +44,9 @@ #include <task/spawn.h> #include <nuttx/spawn.h> #include <nuttx/binfmt/binfmt.h> +#include <nuttx/environ.h> #include "binfmt.h" -#include "environ/environ.h" #ifndef CONFIG_BINFMT_DISABLE @@ -354,7 +354,7 @@ int exec_module(FAR struct binary_s *binp, group->tg_flags |= GROUP_FLAG_SECURE_EXEC; group->tg_flags &= ~(GROUP_FLAG_FD_BACKTRACE | GROUP_FLAG_DUMPABLE); #ifndef CONFIG_DISABLE_ENVIRON - env_sanitize_secure(group); + env_sanitize_secure(group->tg_info); #endif } #endif diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 26b31d2e7e4..e5e83f1933c 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -1568,7 +1568,7 @@ static ssize_t proc_groupenv(FAR struct proc_file_s *procfile, /* Generate output for each environment variable */ - env_foreach(group, proc_groupenv_callback, &info); + env_foreach(group->tg_info, proc_groupenv_callback, &info); #ifdef CONFIG_ARCH_ADDRENV if (tcb->addrenv_own != NULL) diff --git a/include/nuttx/environ.h b/include/nuttx/environ.h index e3ff666a3fd..4cbe7276658 100644 --- a/include/nuttx/environ.h +++ b/include/nuttx/environ.h @@ -28,8 +28,12 @@ ****************************************************************************/ #include <nuttx/config.h> +#include <nuttx/compiler.h> -#ifndef CONFIG_DISABLE_ENVIRON +#ifdef CONFIG_DISABLE_ENVIRON +# define env_dup(info, envp) (0) +# define env_release(info) ((void)0) +#else /**************************************************************************** * Pre-processor Definitions @@ -55,6 +59,8 @@ extern "C" #define EXTERN extern #endif +struct task_info_s; /* Forward reference */ + /**************************************************************************** * Name: env_foreach * @@ -80,10 +86,69 @@ extern "C" * ****************************************************************************/ -struct task_group_s; /* Forward reference */ -int env_foreach(FAR struct task_group_s *group, env_foreach_t cb, +int env_foreach(FAR struct task_info_s *info, env_foreach_t cb, FAR void *arg); +/**************************************************************************** + * Name: env_dup + * + * Description: + * Copy the internal environment structure of a task. This is the action + * that is performed when a new task is created: + * The new task has a private, exact duplicate of the parent task's + * environment. + * + * Input Parameters: + * info - The child task to receive the newly allocated copy of the + * parent task groups environment structure. + * envp - Pointer to the environment strings. + * + * Returned Value: + * zero on success + * + * Assumptions: + * Not called from an interrupt handler. + * + ****************************************************************************/ + +int env_dup(FAR struct task_info_s *info, FAR char * const *envp); + +/**************************************************************************** + * Name: env_release + * + * Description: + * env_release() is called only from group_leave() when the last member of + * a task group exits. The env_release() function clears the environment + * of all name-value pairs and sets the value of the external variable + * environ to NULL. + * + * Input Parameters: + * info - Identifies the task containing the environment structure + * to be released. + * + * Returned Value: + * None + * + * Assumptions: + * Not called from an interrupt handler + * + ****************************************************************************/ + +void env_release(FAR struct task_info_s *info); + +#ifdef CONFIG_SCHED_USER_IDENTITY +/**************************************************************************** + * Name: env_sanitize_secure + * + * Description: + * Remove environment variables that must not be inherited by a secure + * (set-user-ID or set-group-ID) executable. + * + ****************************************************************************/ + +void env_sanitize_secure(FAR struct task_info_s *info); +#endif + #undef EXTERN #ifdef __cplusplus } diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index e0464b3248e..2e802dd05cf 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -137,7 +137,7 @@ struct pthread_atfork_s struct task_info_s { - mutex_t ta_lock; + rmutex_t ta_lock; #if CONFIG_TLS_TASK_NELEM > 0 uintptr_t ta_telem[CONFIG_TLS_TASK_NELEM]; /* Task local storage elements */ #endif diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h index 9b106b5e997..dfdbe44316d 100644 --- a/include/sys/syscall_lookup.h +++ b/include/sys/syscall_lookup.h @@ -363,17 +363,6 @@ SYSCALL_LOOKUP(munlockall, 0) SYSCALL_LOOKUP(mq_unlink, 1) #endif -/* The following are defined only if environment variables are supported */ - -#ifndef CONFIG_DISABLE_ENVIRON - SYSCALL_LOOKUP(get_environ_ptr, 0) - SYSCALL_LOOKUP(clearenv, 0) - SYSCALL_LOOKUP(getenv, 1) - SYSCALL_LOOKUP(putenv, 1) - SYSCALL_LOOKUP(setenv, 3) - SYSCALL_LOOKUP(unsetenv, 1) -#endif - /* The following are defined only if networking AND sockets are supported */ #ifdef CONFIG_NET diff --git a/libs/libc/Makefile b/libs/libc/Makefile index a04fb9d393c..9cedb332839 100644 --- a/libs/libc/Makefile +++ b/libs/libc/Makefile @@ -29,6 +29,7 @@ include builtin/Make.defs include ctype/Make.defs include dirent/Make.defs include dlfcn/Make.defs +include environ/Make.defs include errno/Make.defs include eventfd/Make.defs include fixedmath/Make.defs diff --git a/sched/environ/CMakeLists.txt b/libs/libc/environ/CMakeLists.txt similarity index 73% rename from sched/environ/CMakeLists.txt rename to libs/libc/environ/CMakeLists.txt index dafb5d1fece..a721bcfb091 100644 --- a/sched/environ/CMakeLists.txt +++ b/libs/libc/environ/CMakeLists.txt @@ -1,5 +1,5 @@ # ############################################################################## -# sched/environ/CMakeLists.txt +# libs/libc/environ/CMakeLists.txt # # SPDX-License-Identifier: Apache-2.0 # @@ -21,18 +21,18 @@ # ############################################################################## if(NOT CONFIG_DISABLE_ENVIRON) - target_sources( - sched - PRIVATE env_getenvironptr.c - env_dup.c - env_release.c - env_findvar.c - env_removevar.c - env_clearenv.c - env_getenv.c - env_putenv.c - env_setenv.c - env_unsetenv.c - env_foreach.c - env_secureexec.c) + set(SRCS + env_getenvironptr.c + env_dup.c + env_release.c + env_findvar.c + env_removevar.c + env_clearenv.c + env_getenv.c + env_putenv.c + env_setenv.c + env_unsetenv.c + env_foreach.c + env_secureexec.c) + target_sources(c PRIVATE ${SRCS}) endif() diff --git a/sched/environ/Make.defs b/libs/libc/environ/Make.defs similarity index 97% rename from sched/environ/Make.defs rename to libs/libc/environ/Make.defs index 28e3d187171..3c74a82f5f7 100644 --- a/sched/environ/Make.defs +++ b/libs/libc/environ/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# sched/environ/Make.defs +# libs/libc/environ/Make.defs # # SPDX-License-Identifier: Apache-2.0 # diff --git a/sched/environ/env_clearenv.c b/libs/libc/environ/env_clearenv.c similarity index 80% rename from sched/environ/env_clearenv.c rename to libs/libc/environ/env_clearenv.c index df04888ce1b..a87bb3f7f94 100644 --- a/sched/environ/env_clearenv.c +++ b/libs/libc/environ/env_clearenv.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_clearenv.c + * libs/libc/environ/env_clearenv.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,16 +24,8 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <sched.h> -#include <stdlib.h> -#include <assert.h> - -#include "sched/sched.h" -#include "environ/environ.h" +#include <nuttx/environ.h> +#include <nuttx/tls.h> /**************************************************************************** * Public Functions @@ -59,15 +51,10 @@ int clearenv(void) { - FAR struct tcb_s *tcb = this_task(); - FAR struct task_group_s *group = tcb->group; + FAR struct task_info_s *info = task_get_info(); - DEBUGASSERT(group); - - nxrmutex_lock(&group->tg_mutex); - env_release(group); - nxrmutex_unlock(&group->tg_mutex); + nxrmutex_lock(&info->ta_lock); + env_release(info); + nxrmutex_unlock(&info->ta_lock); return OK; } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/env_dup.c b/libs/libc/environ/env_dup.c similarity index 83% rename from sched/environ/env_dup.c rename to libs/libc/environ/env_dup.c index d2f16bc8dd0..220392d24a5 100644 --- a/sched/environ/env_dup.c +++ b/libs/libc/environ/env_dup.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_dup.c + * libs/libc/environ/env_dup.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,21 +24,13 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <sys/types.h> -#include <sched.h> #include <string.h> #include <assert.h> #include <errno.h> -#include <nuttx/kmalloc.h> #include <nuttx/mutex.h> #include <nuttx/tls.h> -#include "sched/sched.h" #include "environ/environ.h" /**************************************************************************** @@ -54,7 +46,7 @@ * private, exact duplicate of the parent task's environment. * * Input Parameters: - * group - The child task group to receive the newly allocated copy of + * info - The child task to receive the newly allocated copy of * the parent task groups environment structure. * envcp - Pointer to the environment strings to copy. * Returned Value: @@ -65,17 +57,14 @@ * ****************************************************************************/ -int env_dup(FAR struct task_group_s *group, FAR char * const *envcp) +int env_dup(FAR struct task_info_s *info, FAR char * const *envcp) { - FAR struct task_info_s *info; FAR char **envp = NULL; size_t envc = 0; size_t size; int ret = OK; - DEBUGASSERT(group != NULL && group->tg_info != NULL); - - info = group->tg_info; + DEBUGASSERT(info != NULL); /* Is there an environment ? */ @@ -85,7 +74,7 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp) * environment may be shared. */ - nxrmutex_lock(&group->tg_mutex); + nxrmutex_lock(&info->ta_lock); /* Count the strings */ @@ -106,7 +95,7 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp) { /* There is an environment, duplicate it */ - envp = group_malloc(group, sizeof(*envp) * info->ta_envpc); + envp = lib_umalloc(sizeof(*envp) * info->ta_envpc); if (envp == NULL) { /* The parent's environment can not be inherited due to a @@ -124,15 +113,15 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp) while (envc-- > 0) { size = strlen(envcp[envc]) + 1; - envp[envc] = group_malloc(group, size); + envp[envc] = lib_umalloc(size); if (envp[envc] == NULL) { while (envp[++envc] != NULL) { - group_free(group, envp[envc]); + lib_ufree(envp[envc]); } - group_free(group, envp); + lib_ufree(envp); envp = NULL; ret = -ENOMEM; break; @@ -146,10 +135,8 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp) /* Save the child environment allocation. */ info->ta_envp = envp; - nxrmutex_unlock(&group->tg_mutex); + nxrmutex_unlock(&info->ta_lock); } return ret; } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/env_findvar.c b/libs/libc/environ/env_findvar.c similarity index 88% rename from sched/environ/env_findvar.c rename to libs/libc/environ/env_findvar.c index a0879a5454a..38d6245efd5 100644 --- a/sched/environ/env_findvar.c +++ b/libs/libc/environ/env_findvar.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_findvar.c + * libs/libc/environ/env_findvar.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,14 +24,8 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <stdbool.h> -#include <string.h> -#include <sched.h> #include <assert.h> +#include <errno.h> #include <nuttx/tls.h> @@ -87,16 +81,13 @@ static bool env_cmpname(const char *pszname, const char *peqname) * ****************************************************************************/ -ssize_t env_findvar(FAR struct task_group_s *group, FAR const char *pname) +ssize_t env_findvar(FAR struct task_info_s *info, FAR const char *pname) { - FAR struct task_info_s *info; ssize_t i; /* Verify input parameters */ - DEBUGASSERT(group != NULL && group->tg_info != NULL && pname != NULL); - - info = group->tg_info; + DEBUGASSERT(info != NULL && pname != NULL); if (info->ta_envp == NULL) { @@ -115,5 +106,3 @@ ssize_t env_findvar(FAR struct task_group_s *group, FAR const char *pname) return -ENOENT; } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/env_foreach.c b/libs/libc/environ/env_foreach.c similarity index 86% rename from sched/environ/env_foreach.c rename to libs/libc/environ/env_foreach.c index b552549bc4d..b26eb812ced 100644 --- a/sched/environ/env_foreach.c +++ b/libs/libc/environ/env_foreach.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_foreach.c + * libs/libc/environ/env_foreach.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,13 +24,6 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <stdbool.h> -#include <string.h> -#include <sched.h> #include <assert.h> #include <nuttx/environ.h> @@ -49,7 +42,7 @@ * Visit each name-value pair in the environment. * * Input Parameters: - * group - The task group containing environment array to be searched. + * info - The task containing environment array to be searched. * cb - The callback function to be invoked for each environment * variable. * @@ -64,19 +57,16 @@ * ****************************************************************************/ -int env_foreach(FAR struct task_group_s *group, +int env_foreach(FAR struct task_info_s *info, env_foreach_t cb, FAR void *arg) { - FAR struct task_info_s *info; int ret = OK; size_t i; /* Verify input parameters */ - DEBUGASSERT(group != NULL && group->tg_info != NULL && cb != NULL); - - info = group->tg_info; + DEBUGASSERT(info != NULL && cb != NULL); if (info->ta_envp == NULL) { @@ -103,5 +93,3 @@ int env_foreach(FAR struct task_group_s *group, return ret; } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/env_getenv.c b/libs/libc/environ/env_getenv.c similarity index 77% rename from sched/environ/env_getenv.c rename to libs/libc/environ/env_getenv.c index 34142490f7a..486f18fc3d9 100644 --- a/sched/environ/env_getenv.c +++ b/libs/libc/environ/env_getenv.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_getenv.c + * libs/libc/environ/env_getenv.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,19 +24,12 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <sched.h> -#include <string.h> -#include <stdlib.h> #include <errno.h> +#include <string.h> #include <nuttx/mutex.h> #include <nuttx/tls.h> -#include "sched/sched.h" #include "environ/environ.h" /**************************************************************************** @@ -63,48 +56,38 @@ FAR char *getenv(FAR const char *name) { - FAR struct tcb_s *rtcb; - FAR struct task_group_s *group; + FAR struct task_info_s *info = task_get_info(); FAR char *pvalue = NULL; ssize_t ret = OK; /* Verify that a string was passed */ - if (name == NULL || up_interrupt_context()) + if (name == NULL || info == NULL +#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) + || up_interrupt_context() || sched_idletask() +#endif + ) { ret = -EINVAL; goto errout; } - /* Get a reference to the thread-private environ in the TCB. */ - - rtcb = this_task(); - group = rtcb->group; - - /* Check if the variable exists */ - - if (group == NULL) - { - goto errout; - } - - nxrmutex_lock(&group->tg_mutex); - ret = env_findvar(group, name); + nxrmutex_lock(&info->ta_lock); + ret = env_findvar(info, name); if (ret < 0) { - nxrmutex_unlock(&group->tg_mutex); + nxrmutex_unlock(&info->ta_lock); goto errout; } /* It does! Get the value sub-string from the name=value string */ - pvalue = strchr(group->tg_info->ta_envp[ret], '='); + pvalue = strchr(info->ta_envp[ret], '='); if (pvalue == NULL) { - nxrmutex_unlock(&group->tg_mutex); - /* The name=value string has no '=' This is a bug! */ + nxrmutex_unlock(&info->ta_lock); ret = -EINVAL; goto errout; } @@ -112,12 +95,10 @@ FAR char *getenv(FAR const char *name) /* Adjust the pointer so that it points to the value right after the '=' */ pvalue++; - nxrmutex_unlock(&group->tg_mutex); + nxrmutex_unlock(&info->ta_lock); return pvalue; errout: set_errno(-ret); return NULL; } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/env_getenvironptr.c b/libs/libc/environ/env_getenvironptr.c similarity index 86% rename from sched/environ/env_getenvironptr.c rename to libs/libc/environ/env_getenvironptr.c index bf5be54bc30..81ed2ebfe0c 100644 --- a/sched/environ/env_getenvironptr.c +++ b/libs/libc/environ/env_getenvironptr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_getenvironptr.c + * libs/libc/environ/env_getenvironptr.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,16 +24,8 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <sched.h> -#include <stdlib.h> #include <nuttx/tls.h> -#include "sched/sched.h" - #undef get_environ_ptr /**************************************************************************** @@ -58,9 +50,5 @@ FAR char **get_environ_ptr(void) { - FAR struct tcb_s *tcb = this_task(); - - return tcb->group->tg_info->ta_envp; + return task_get_info()->ta_envp; } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/env_putenv.c b/libs/libc/environ/env_putenv.c similarity index 93% rename from sched/environ/env_putenv.c rename to libs/libc/environ/env_putenv.c index 8a7aad23002..bc4c330d232 100644 --- a/sched/environ/env_putenv.c +++ b/libs/libc/environ/env_putenv.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_putenv.c + * libs/libc/environ/env_putenv.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,12 +24,6 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <stdlib.h> -#include <sched.h> #include <string.h> #include <errno.h> @@ -93,12 +87,10 @@ int putenv(FAR const char *string) ret = setenv(pname, pequal + 1, TRUE); } - kmm_free(pname); + lib_ufree(pname); return ret; errout: set_errno(ret); return ERROR; } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/env_release.c b/libs/libc/environ/env_release.c similarity index 73% rename from sched/environ/env_release.c rename to libs/libc/environ/env_release.c index d9b090662c7..2728fd95aa1 100644 --- a/sched/environ/env_release.c +++ b/libs/libc/environ/env_release.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_release.c + * libs/libc/environ/env_release.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,15 +24,8 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <sched.h> #include <assert.h> -#include <errno.h> -#include <nuttx/kmalloc.h> #include <nuttx/tls.h> #include "environ/environ.h" @@ -45,14 +38,14 @@ * Name: env_release * * Description: - * env_release() is called only from group_leave() when the last member of - * a task group exits. The env_release() function clears the environment - * of all name-value pairs and sets the value of the external variable + * env_release() is called only from task_uninit_info() when the task is + * uninit. The env_release() function clears the environment of all + * name-value pairs and sets the value of the external variable * environ to NULL. * * Input Parameters: - * group - Identifies the task group containing the environment structure - * to be released. + * info - Identifies the task containing the environment structure + * to be released. * * Returned Value: * None @@ -62,14 +55,11 @@ * ****************************************************************************/ -void env_release(FAR struct task_group_s *group) +void env_release(FAR struct task_info_s *info) { - FAR struct task_info_s *info; int i; - DEBUGASSERT(group != NULL && group->tg_info != NULL); - - info = group->tg_info; + DEBUGASSERT(info != NULL); if (info->ta_envp) { @@ -77,12 +67,12 @@ void env_release(FAR struct task_group_s *group) for (i = 0; info->ta_envp[i] != NULL; i++) { - group_free(group, info->ta_envp[i]); + lib_ufree(info->ta_envp[i]); } /* Free the environment */ - group_free(group, info->ta_envp); + lib_ufree(info->ta_envp); } /* In any event, make sure that all environment-related variables in the @@ -93,5 +83,3 @@ void env_release(FAR struct task_group_s *group) info->ta_envpc = 0; info->ta_envc = 0; } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/env_removevar.c b/libs/libc/environ/env_removevar.c similarity index 81% rename from sched/environ/env_removevar.c rename to libs/libc/environ/env_removevar.c index fd6eb0ef994..4c4f5e5432b 100644 --- a/sched/environ/env_removevar.c +++ b/libs/libc/environ/env_removevar.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_removevar.c + * libs/libc/environ/env_removevar.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,15 +24,8 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <string.h> -#include <sched.h> #include <assert.h> -#include <nuttx/kmalloc.h> #include <nuttx/tls.h> #include "environ/environ.h" @@ -48,7 +41,7 @@ * Remove the referenced name=value pair from the environment * * Input Parameters: - * group - The task group with the environment containing the name=value + * info - The task with the environment containing the name=value * pair * index - A index to the name=value pair in the restroom * @@ -62,19 +55,13 @@ * ****************************************************************************/ -void env_removevar(FAR struct task_group_s *group, ssize_t index) +void env_removevar(FAR struct task_info_s *info, ssize_t index) { - FAR struct task_info_s *info; - - DEBUGASSERT(group != NULL && group->tg_info != NULL); - - info = group->tg_info; - - DEBUGASSERT(index >= 0 && index < info->ta_envc); + DEBUGASSERT(info != NULL && index >= 0 && index < info->ta_envc); /* Free the allocate environment string */ - group_free(group, info->ta_envp[index]); + lib_ufree(info->ta_envp[index]); /* Exchange the last env and the index env */ @@ -93,7 +80,7 @@ void env_removevar(FAR struct task_group_s *group, ssize_t index) if (info->ta_envc == 0) { - group_free(group, info->ta_envp); + lib_ufree(info->ta_envp); info->ta_envp = NULL; info->ta_envpc = 0; } @@ -104,10 +91,8 @@ void env_removevar(FAR struct task_group_s *group, ssize_t index) info->ta_envpc = info->ta_envc + SCHED_ENVIRON_RESERVED + 1; - info->ta_envp = group_realloc(group, info->ta_envp, + info->ta_envp = lib_urealloc(info->ta_envp, sizeof(*info->ta_envp) * info->ta_envpc); DEBUGASSERT(info->ta_envp != NULL); } } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/env_secureexec.c b/libs/libc/environ/env_secureexec.c similarity index 91% rename from sched/environ/env_secureexec.c rename to libs/libc/environ/env_secureexec.c index 231fd54ba37..f3ae0fcc3ec 100644 --- a/sched/environ/env_secureexec.c +++ b/libs/libc/environ/env_secureexec.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_secureexec.c + * libs/libc/environ/env_secureexec.c * * SPDX-License-Identifier: Apache-2.0 * @@ -31,9 +31,9 @@ #include <stdlib.h> #include <assert.h> +#include <nuttx/environ.h> #include <nuttx/tls.h> -#include "sched/sched.h" #include "environ/environ.h" /**************************************************************************** @@ -99,16 +99,13 @@ static bool env_is_unsafe(FAR const char *pair) ****************************************************************************/ #ifdef CONFIG_SCHED_USER_IDENTITY -void env_sanitize_secure(FAR struct task_group_s *group) +void env_sanitize_secure(FAR struct task_info_s *info) { - FAR struct task_info_s *info; ssize_t index; - DEBUGASSERT(group != NULL && group->tg_info != NULL); + DEBUGASSERT(info != NULL); - info = group->tg_info; - - nxrmutex_lock(&group->tg_mutex); + nxrmutex_lock(&info->ta_lock); for (index = info->ta_envc - 1; index >= 0; ) { @@ -116,7 +113,7 @@ void env_sanitize_secure(FAR struct task_group_s *group) if (pair != NULL && env_is_unsafe(pair)) { - env_removevar(group, index); + env_removevar(info, index); } else { @@ -124,7 +121,7 @@ void env_sanitize_secure(FAR struct task_group_s *group) } } - nxrmutex_unlock(&group->tg_mutex); + nxrmutex_unlock(&info->ta_lock); } #endif diff --git a/sched/environ/env_setenv.c b/libs/libc/environ/env_setenv.c similarity index 85% rename from sched/environ/env_setenv.c rename to libs/libc/environ/env_setenv.c index 115a45a68d6..0d2564b1b57 100644 --- a/sched/environ/env_setenv.c +++ b/libs/libc/environ/env_setenv.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_setenv.c + * libs/libc/environ/env_setenv.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,22 +24,14 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <stdio.h> -#include <stdlib.h> -#include <sched.h> -#include <string.h> #include <assert.h> #include <errno.h> +#include <stdio.h> +#include <string.h> -#include <nuttx/kmalloc.h> #include <nuttx/mutex.h> #include <nuttx/tls.h> -#include "sched/sched.h" #include "environ/environ.h" /**************************************************************************** @@ -71,8 +63,6 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) { - FAR struct tcb_s *rtcb; - FAR struct task_group_s *group; FAR struct task_info_s *info; FAR char *pvar; FAR char **envp; @@ -113,17 +103,15 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) /* Get a reference to the thread-private environ in the TCB. */ - rtcb = this_task(); - group = rtcb->group; - DEBUGASSERT(group && group->tg_info); + info = task_get_info(); - info = group->tg_info; + DEBUGASSERT(info != NULL); - nxrmutex_lock(&group->tg_mutex); + nxrmutex_lock(&info->ta_lock); /* Check if the variable already exists */ - if (info->ta_envp && (ret = env_findvar(group, name)) >= 0) + if (info->ta_envp && (ret = env_findvar(info, name)) >= 0) { /* It does! Do we have permission to overwrite the existing value? */ @@ -131,7 +119,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) { /* No.. then just return success */ - nxrmutex_unlock(&group->tg_mutex); + nxrmutex_unlock(&info->ta_lock); return OK; } @@ -140,7 +128,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) * the environment buffer; this will happen below. */ - env_removevar(group, ret); + env_removevar(info, ret); } /* Check current envirments count */ @@ -155,7 +143,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) /* Then allocate or reallocate the environment buffer */ - pvar = group_malloc(group, varlen); + pvar = lib_umalloc(varlen); if (pvar == NULL) { ret = ENOMEM; @@ -168,7 +156,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) { envpc = SCHED_ENVIRON_RESERVED + 2; - envp = group_malloc(group, sizeof(*envp) * envpc); + envp = lib_umalloc(sizeof(*envp) * envpc); if (envp == NULL) { ret = ENOMEM; @@ -182,7 +170,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) { envpc = envc + SCHED_ENVIRON_RESERVED + 2; - envp = group_realloc(group, info->ta_envp, sizeof(*envp) * envpc); + envp = lib_urealloc(info->ta_envp, sizeof(*envp) * envpc); if (envp == NULL) { ret = ENOMEM; @@ -202,16 +190,14 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite) /* Now, put the new name=value string into the environment buffer */ snprintf(pvar, varlen, "%s=%s", name, value); - nxrmutex_unlock(&group->tg_mutex); + nxrmutex_unlock(&info->ta_lock); return OK; errout_with_var: - group_free(group, pvar); + lib_ufree(pvar); errout_with_lock: - nxrmutex_unlock(&group->tg_mutex); + nxrmutex_unlock(&info->ta_lock); errout: set_errno(ret); return ERROR; } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/env_unsetenv.c b/libs/libc/environ/env_unsetenv.c similarity index 82% rename from sched/environ/env_unsetenv.c rename to libs/libc/environ/env_unsetenv.c index 5008ef7e01b..9e2dbfc48ae 100644 --- a/sched/environ/env_unsetenv.c +++ b/libs/libc/environ/env_unsetenv.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/env_unsetenv.c + * libs/libc/environ/env_unsetenv.c * * SPDX-License-Identifier: Apache-2.0 * @@ -24,18 +24,12 @@ * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#ifndef CONFIG_DISABLE_ENVIRON - -#include <sched.h> -#include <string.h> -#include <assert.h> #include <errno.h> +#include <string.h> -#include <nuttx/kmalloc.h> +#include <nuttx/mutex.h> +#include <nuttx/tls.h> -#include "sched/sched.h" #include "environ/environ.h" /**************************************************************************** @@ -61,12 +55,9 @@ int unsetenv(FAR const char *name) { - FAR struct tcb_s *rtcb = this_task(); - FAR struct task_group_s *group = rtcb->group; + FAR struct task_info_s *info = task_get_info(); ssize_t idx; - DEBUGASSERT(group); - /* Check the incoming parameter */ if (name == NULL || *name == '\0' || strchr(name, '=') != NULL) @@ -77,16 +68,14 @@ int unsetenv(FAR const char *name) /* Check if the variable exists */ - nxrmutex_lock(&group->tg_mutex); - if (group && (idx = env_findvar(group, name)) >= 0) + nxrmutex_lock(&info->ta_lock); + if (info && (idx = env_findvar(info, name)) >= 0) { /* It does! Remove the name=value pair from the environment. */ - env_removevar(group, idx); + env_removevar(info, idx); } - nxrmutex_unlock(&group->tg_mutex); + nxrmutex_unlock(&info->ta_lock); return OK; } - -#endif /* CONFIG_DISABLE_ENVIRON */ diff --git a/sched/environ/environ.h b/libs/libc/environ/environ.h similarity index 55% rename from sched/environ/environ.h rename to libs/libc/environ/environ.h index 31ad20e83b8..475007c9754 100644 --- a/sched/environ/environ.h +++ b/libs/libc/environ/environ.h @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/environ/environ.h + * libs/libc/environ/environ.h * * SPDX-License-Identifier: Apache-2.0 * @@ -20,24 +20,24 @@ * ****************************************************************************/ -#ifndef __SCHED_ENVIRON_ENVIRON_H -#define __SCHED_ENVIRON_ENVIRON_H +#ifndef __LIBS_LIBC_ENVIRON_ENVIRON_H +#define __LIBS_LIBC_ENVIRON_ENVIRON_H /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> -#include <nuttx/sched.h> + +#include <sys/types.h> + +#include <nuttx/lib/lib.h> /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#ifdef CONFIG_DISABLE_ENVIRON -# define env_dup(group, envp) (0) -# define env_release(group) ((void)0) -#else +#ifndef CONFIG_DISABLE_ENVIRON # define SCHED_ENVIRON_RESERVED (4) @@ -57,66 +57,6 @@ extern "C" * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * Name: env_dup - * - * Description: - * Copy the internal environment structure of a task. This is the action - * that is performed when a new task is created: - * The new task has a private, exact duplicate of the parent task's - * environment. - * - * Input Parameters: - * group - The child task group to receive the newly allocated copy of the - * parent task groups environment structure. - * envp - Pointer to the environment strings. - * - * Returned Value: - * zero on success - * - * Assumptions: - * Not called from an interrupt handler. - * - ****************************************************************************/ - -int env_dup(FAR struct task_group_s *group, FAR char * const *envp); - -/**************************************************************************** - * Name: env_release - * - * Description: - * env_release() is called only from group_leave() when the last member of - * a task group exits. The env_release() function clears the environment - * of all name-value pairs and sets the value of the external variable - * environ to NULL. - * - * Input Parameters: - * group - Identifies the task group containing the environment structure - * to be released. - * - * Returned Value: - * None - * - * Assumptions: - * Not called from an interrupt handler - * - ****************************************************************************/ - -void env_release(FAR struct task_group_s *group); - -#ifdef CONFIG_SCHED_USER_IDENTITY -/**************************************************************************** - * Name: env_sanitize_secure - * - * Description: - * Remove environment variables that must not be inherited by a secure - * (set-user-ID or set-group-ID) executable. - * - ****************************************************************************/ - -void env_sanitize_secure(FAR struct task_group_s *group); -#endif - /**************************************************************************** * Name: env_findvar * @@ -125,7 +65,7 @@ void env_sanitize_secure(FAR struct task_group_s *group); * specified name. * * Input Parameters: - * group - The task group containing environment array to be searched. + * info - The task containing environment array to be searched. * pname - The variable name to find * * Returned Value: @@ -137,7 +77,7 @@ void env_sanitize_secure(FAR struct task_group_s *group); * ****************************************************************************/ -ssize_t env_findvar(FAR struct task_group_s *group, FAR const char *pname); +ssize_t env_findvar(FAR struct task_info_s *info, FAR const char *pname); /**************************************************************************** * Name: env_removevar @@ -146,7 +86,7 @@ ssize_t env_findvar(FAR struct task_group_s *group, FAR const char *pname); * Remove the referenced name=value pair from the environment * * Input Parameters: - * group - The task group with the environment containing the name=value + * info - The task with the environment containing the name=value * pair * index - A index to the name=value pair in the restroom * @@ -160,7 +100,7 @@ ssize_t env_findvar(FAR struct task_group_s *group, FAR const char *pname); * ****************************************************************************/ -void env_removevar(FAR struct task_group_s *group, ssize_t index); +void env_removevar(FAR struct task_info_s *info, ssize_t index); #undef EXTERN #ifdef __cplusplus @@ -168,4 +108,4 @@ void env_removevar(FAR struct task_group_s *group, ssize_t index); #endif #endif /* !CONFIG_DISABLE_ENVIRON */ -#endif /* __SCHED_ENVIRON_ENVIRON_H */ +#endif /* __LIBS_LIBC_ENVIRON_ENVIRON_H */ diff --git a/libs/libc/pthread/pthread_atfork.c b/libs/libc/pthread/pthread_atfork.c index 9cc1082cb89..f2f835235c1 100644 --- a/libs/libc/pthread/pthread_atfork.c +++ b/libs/libc/pthread/pthread_atfork.c @@ -79,9 +79,9 @@ int pthread_atfork(CODE void (*prepare)(void), entry->parent = parent; entry->child = child; - nxmutex_lock(&info->ta_lock); + nxrmutex_lock(&info->ta_lock); list_add_head(list, &entry->node); - nxmutex_unlock(&info->ta_lock); + nxrmutex_unlock(&info->ta_lock); #endif return OK; diff --git a/libs/libc/pthread/pthread_keycreate.c b/libs/libc/pthread/pthread_keycreate.c index f819dd98e0a..1ea4cedc698 100644 --- a/libs/libc/pthread/pthread_keycreate.c +++ b/libs/libc/pthread/pthread_keycreate.c @@ -98,7 +98,7 @@ int pthread_key_create(FAR pthread_key_t *key, * avoid concurrent modification of the group TLS index set. */ - ret = nxmutex_lock(&info->ta_lock); + ret = nxrmutex_lock(&info->ta_lock); if (ret < 0) { return -ret; @@ -129,7 +129,7 @@ int pthread_key_create(FAR pthread_key_t *key, } } - nxmutex_unlock(&info->ta_lock); + nxrmutex_unlock(&info->ta_lock); return ret; } diff --git a/libs/libc/pthread/pthread_keydelete.c b/libs/libc/pthread/pthread_keydelete.c index a8e5ceaffbc..805c943801f 100644 --- a/libs/libc/pthread/pthread_keydelete.c +++ b/libs/libc/pthread/pthread_keydelete.c @@ -71,12 +71,12 @@ int pthread_key_delete(pthread_key_t key) * modification of the group TLS index set. */ - ret = nxmutex_lock(&info->ta_lock); + ret = nxrmutex_lock(&info->ta_lock); if (ret == OK) { info->ta_tlsdtor[key] = NULL; tls->tl_elem[key] = 0; - nxmutex_unlock(&info->ta_lock); + nxrmutex_unlock(&info->ta_lock); } else { diff --git a/libs/libc/stdlib/lib_atexit.c b/libs/libc/stdlib/lib_atexit.c index cbc1e072b7f..132ab302ff4 100644 --- a/libs/libc/stdlib/lib_atexit.c +++ b/libs/libc/stdlib/lib_atexit.c @@ -82,7 +82,7 @@ int atexit_register(int type, CODE void (*func)(void), FAR void *arg, if (func) { - ret = nxmutex_lock(&info->ta_lock); + ret = nxrmutex_lock(&info->ta_lock); if (ret < 0) { return -ret; @@ -101,7 +101,7 @@ int atexit_register(int type, CODE void (*func)(void), FAR void *arg, ret = ERROR; } - nxmutex_unlock(&info->ta_lock); + nxrmutex_unlock(&info->ta_lock); } return ret; @@ -128,7 +128,7 @@ void atexit_call_exitfuncs(int status, bool quick) * before the older remaining ones, as documented in exit(3). */ - if (nxmutex_lock(&info->ta_lock) < 0) + if (nxrmutex_lock(&info->ta_lock) < 0) { break; } @@ -145,7 +145,7 @@ void atexit_call_exitfuncs(int status, bool quick) aehead->funcs[idx].arg = NULL; aehead->nfuncs--; - nxmutex_unlock(&info->ta_lock); + nxrmutex_unlock(&info->ta_lock); if (!func) { diff --git a/libs/libc/unistd/lib_fork.c b/libs/libc/unistd/lib_fork.c index 84813db3265..29cd14a123f 100644 --- a/libs/libc/unistd/lib_fork.c +++ b/libs/libc/unistd/lib_fork.c @@ -58,7 +58,7 @@ static void atfork_prepare(void) * so we iterate over the func list in reverse order */ - nxmutex_lock(&info->ta_lock); + nxrmutex_lock(&info->ta_lock); list_for_every_entry_reverse(list, entry, struct pthread_atfork_s, node) { @@ -68,7 +68,7 @@ static void atfork_prepare(void) } } - nxmutex_unlock(&info->ta_lock); + nxrmutex_unlock(&info->ta_lock); } /**************************************************************************** @@ -87,7 +87,7 @@ static void atfork_child(void) /* The parent handlers are called in the order of registration */ - nxmutex_lock(&info->ta_lock); + nxrmutex_lock(&info->ta_lock); list_for_every_entry(list, entry, struct pthread_atfork_s, node) { @@ -97,7 +97,7 @@ static void atfork_child(void) } } - nxmutex_unlock(&info->ta_lock); + nxrmutex_unlock(&info->ta_lock); } /**************************************************************************** @@ -116,7 +116,7 @@ static void atfork_parent(void) /* The child handlers are called in the order of registration */ - nxmutex_lock(&info->ta_lock); + nxrmutex_lock(&info->ta_lock); list_for_every_entry(list, entry, struct pthread_atfork_s, node) { @@ -126,7 +126,7 @@ static void atfork_parent(void) } } - nxmutex_unlock(&info->ta_lock); + nxrmutex_unlock(&info->ta_lock); } #endif diff --git a/sched/Makefile b/sched/Makefile index 79e81e0bbe2..b042dec2e3c 100644 --- a/sched/Makefile +++ b/sched/Makefile @@ -24,7 +24,6 @@ include $(TOPDIR)/Make.defs include addrenv/Make.defs include clock/Make.defs -include environ/Make.defs include event/Make.defs include group/Make.defs include init/Make.defs diff --git a/sched/group/group_join.c b/sched/group/group_join.c index e2986b2bd09..8e22b5618b3 100644 --- a/sched/group/group_join.c +++ b/sched/group/group_join.c @@ -36,7 +36,6 @@ #include "sched/sched.h" #include "group/group.h" -#include "environ/environ.h" #ifndef CONFIG_DISABLE_PTHREAD diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index 5752d1c4375..80a8f1c7880 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -42,7 +42,6 @@ # include <nuttx/binfmt/binfmt.h> #endif -#include "environ/environ.h" #include "signal/signal.h" #include "pthread/pthread.h" #include "mqueue/mqueue.h" @@ -81,10 +80,6 @@ static inline void group_release(FAR struct task_group_s *group) nxrmutex_destroy(&group->tg_mutex); - /* Release all shared environment variables */ - - env_release(group); - task_uninit_info(group); #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) diff --git a/sched/task/task_fork.c b/sched/task/task_fork.c index ca7ff728636..0aabb955da7 100644 --- a/sched/task/task_fork.c +++ b/sched/task/task_fork.c @@ -37,9 +37,9 @@ #include <nuttx/kmalloc.h> #include <nuttx/queue.h> #include <nuttx/semaphore.h> +#include <nuttx/environ.h> #include "sched/sched.h" -#include "environ/environ.h" #include "group/group.h" #include "task/task.h" #include "tls/tls.h" @@ -317,7 +317,7 @@ FAR struct tcb_s *nxtask_setup_fork(start_t retaddr, bool vfork) /* Duplicate the parent tasks environment */ - ret = env_dup(child->group, environ); + ret = env_dup(child->group->tg_info, environ); if (ret < 0) { goto errout_with_tcb; diff --git a/sched/task/task_init.c b/sched/task/task_init.c index 6460dff6205..8af86f498cf 100644 --- a/sched/task/task_init.c +++ b/sched/task/task_init.c @@ -36,9 +36,9 @@ #include <nuttx/queue.h> #include <nuttx/sched.h> #include <nuttx/trace.h> +#include <nuttx/environ.h> #include "sched/sched.h" -#include "environ/environ.h" #include "group/group.h" #include "task/task.h" #include "tls/tls.h" @@ -128,7 +128,7 @@ int nxtask_init(FAR struct tcb_s *tcb, const char *name, int priority, /* Duplicate the parent tasks environment */ - ret = env_dup(tcb->group, envp); + ret = env_dup(tcb->group->tg_info, envp); if (ret < 0) { goto errout_with_group; diff --git a/sched/tls/task_initinfo.c b/sched/tls/task_initinfo.c index 20953aaa6a6..e268454608f 100644 --- a/sched/tls/task_initinfo.c +++ b/sched/tls/task_initinfo.c @@ -125,7 +125,7 @@ int task_init_info(FAR struct task_group_s *group) /* Initialize user space mutex */ - nxmutex_init(&info->ta_lock); + nxrmutex_init(&info->ta_lock); group->tg_info = info; #ifdef CONFIG_PTHREAD_ATFORK diff --git a/sched/tls/task_uninitinfo.c b/sched/tls/task_uninitinfo.c index da525445583..c6ff0c79c54 100644 --- a/sched/tls/task_uninitinfo.c +++ b/sched/tls/task_uninitinfo.c @@ -29,6 +29,7 @@ #include <nuttx/mutex.h> #include <nuttx/list.h> #include <nuttx/lib/lib.h> +#include <nuttx/environ.h> #include "tls.h" @@ -145,7 +146,11 @@ void task_uninit_info(FAR struct task_group_s *group) task_uninit_stream(group); #endif /* CONFIG_FILE_STREAM */ - nxmutex_destroy(&info->ta_lock); + /* Release all environment variables */ + + env_release(info); + + nxrmutex_destroy(&info->ta_lock); #ifdef CONFIG_MM_KERNEL_HEAP group_free(group, info); #endif diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 1b93dcc4d2d..1a88bd0045d 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -11,7 +11,6 @@ "chmod","sys/stat.h","","int","FAR const char *","mode_t" "chown","unistd.h","","int","FAR const char *","uid_t","gid_t" "chroot","unistd.h","defined(CONFIG_FS_CHROOT)","int","FAR const char *" -"clearenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int" "clock","time.h","","clock_t" "clock_adjtime","sys/timex.h","defined(CONFIG_CLOCK_ADJTIME)","int","clockid_t","struct timex *" "clock_getres","time.h","","int","clockid_t","FAR struct timespec *" @@ -39,11 +38,9 @@ "fsync","unistd.h","","int","int" "ftruncate","unistd.h","","int","int","off_t" "futimens","sys/stat.h","","int","int","const struct timespec [2]|FAR const struct timespec *" -"get_environ_ptr","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char **" "getegid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","gid_t" "getresgid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","int","gid_t *","gid_t *","gid_t *" "getresuid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","int","uid_t *","uid_t *","uid_t *" -"getenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char *","FAR const char *" "geteuid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","uid_t" "getgid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","gid_t" "getgroups","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY) && (CONFIG_SCHED_NGROUPS > 0)","int","int","FAR gid_t *" @@ -128,7 +125,6 @@ "pthread_setschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","int","FAR const struct sched_param *" "pthread_setschedprio","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","int" "pthread_sigmask","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","int","FAR const sigset_t *","FAR sigset_t *" -"putenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *" "pwrite","unistd.h","","ssize_t","int","FAR const void *","size_t","off_t" "read","unistd.h","","ssize_t","int","FAR void *","size_t" "readv","sys/uio.h","","ssize_t","int","FAR const struct iovec *","int" @@ -165,7 +161,6 @@ "setreuid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","int","uid_t","uid_t" "setresgid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","int","gid_t","gid_t","gid_t" "setresuid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","int","uid_t","uid_t","uid_t" -"setenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *","FAR const char *","int" "seteuid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","int","uid_t" "setgid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","int","gid_t" "sethostname","unistd.h","","int","FAR const char *","size_t" @@ -212,7 +207,6 @@ "timerfd_settime","sys/timerfd.h","defined(CONFIG_TIMER_FD)","int","int","int","FAR const struct itimerspec *","FAR struct itimerspec *" "umount2","sys/mount.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *","unsigned int" "unlink","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *" -"unsetenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *" "up_fork","nuttx/arch.h","defined(CONFIG_ARCH_HAVE_VFORK) || defined(CONFIG_ARCH_HAVE_FORK)","pid_t","bool" "utimens","sys/stat.h","","int","FAR const char *","const struct timespec [2]|FAR const struct timespec *" "wait","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","pid_t","FAR int *"
