You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2023/08/28 08:02:25 UTC

[nuttx] branch master updated: tls: Move task_tls_alloc and task_tls_destruct to libc

This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 47faeeb360 tls: Move task_tls_alloc and task_tls_destruct to libc
47faeeb360 is described below

commit 47faeeb360b5f14d2486cc30e786f29be5115a7f
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Aug 21 10:26:41 2023 +0800

    tls: Move task_tls_alloc and task_tls_destruct to libc
    
    so task_tls_destruct can be called from usrspace, which is required by:
    https://github.com/apache/nuttx/pull/10288
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/sim/src/nuttx-names.in                                      | 4 ++--
 boards/arm/imx6/sabre-6quad/configs/netknsh/defconfig            | 1 -
 boards/arm/imx6/sabre-6quad/configs/netknsh_smp/defconfig        | 1 -
 include/nuttx/tls.h                                              | 6 +++---
 include/sys/syscall_lookup.h                                     | 4 ----
 libs/libc/pthread/pthread_exit.c                                 | 2 +-
 libs/libc/pthread/pthread_getspecific.c                          | 2 +-
 libs/libc/pthread/pthread_keycreate.c                            | 2 +-
 libs/libc/pthread/pthread_keydelete.c                            | 2 +-
 libs/libc/pthread/pthread_setspecific.c                          | 2 +-
 libs/libc/stdlib/lib_exit.c                                      | 4 ++--
 libs/libc/tls/CMakeLists.txt                                     | 2 +-
 libs/libc/tls/Kconfig                                            | 2 ++
 libs/libc/tls/Make.defs                                          | 2 +-
 libs/libc/tls/task_tls.c                                         | 2 +-
 sched/task/task_tls_alloc.c => libs/libc/tls/task_tls_destruct.c | 6 +++---
 libs/libc/tls/tls_destruct.c                                     | 2 +-
 sched/group/group_leave.c                                        | 2 +-
 sched/task/CMakeLists.txt                                        | 3 +--
 sched/task/Make.defs                                             | 1 -
 syscall/syscall.csv                                              | 1 -
 21 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/arch/sim/src/nuttx-names.in b/arch/sim/src/nuttx-names.in
index ace70ee1b0..1545dfd5c0 100644
--- a/arch/sim/src/nuttx-names.in
+++ b/arch/sim/src/nuttx-names.in
@@ -96,7 +96,7 @@ NXSYMBOLS(pthread_cond_init)
 NXSYMBOLS(pthread_cond_signal)
 NXSYMBOLS(pthread_cond_wait)
 NXSYMBOLS(pthread_create)
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
 NXSYMBOLS(pthread_getspecific)
 NXSYMBOLS(pthread_key_create)
 #endif
@@ -105,7 +105,7 @@ NXSYMBOLS(pthread_mutex_destroy)
 NXSYMBOLS(pthread_mutex_init)
 NXSYMBOLS(pthread_mutex_lock)
 NXSYMBOLS(pthread_mutex_unlock)
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
 NXSYMBOLS(pthread_setspecific)
 #endif
 NXSYMBOLS(pthread_sigmask)
diff --git a/boards/arm/imx6/sabre-6quad/configs/netknsh/defconfig b/boards/arm/imx6/sabre-6quad/configs/netknsh/defconfig
index 15eac965a9..f0102b7d6c 100644
--- a/boards/arm/imx6/sabre-6quad/configs/netknsh/defconfig
+++ b/boards/arm/imx6/sabre-6quad/configs/netknsh/defconfig
@@ -118,5 +118,4 @@ CONFIG_SYSTEM_NSH=y
 CONFIG_SYSTEM_NSH_PROGNAME="init"
 CONFIG_SYSTEM_PING=y
 CONFIG_TESTING_GETPRIME=y
-CONFIG_TLS_TASK_NELEM=4
 CONFIG_UART1_SERIAL_CONSOLE=y
diff --git a/boards/arm/imx6/sabre-6quad/configs/netknsh_smp/defconfig b/boards/arm/imx6/sabre-6quad/configs/netknsh_smp/defconfig
index 124532795c..8d42d52dd7 100644
--- a/boards/arm/imx6/sabre-6quad/configs/netknsh_smp/defconfig
+++ b/boards/arm/imx6/sabre-6quad/configs/netknsh_smp/defconfig
@@ -120,5 +120,4 @@ CONFIG_SYSTEM_NSH_PROGNAME="init"
 CONFIG_SYSTEM_PING=y
 CONFIG_TESTING_GETPRIME=y
 CONFIG_TESTING_SMP=y
-CONFIG_TLS_TASK_NELEM=4
 CONFIG_UART1_SERIAL_CONSOLE=y
diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h
index dfcef94cb9..6843cec0eb 100644
--- a/include/nuttx/tls.h
+++ b/include/nuttx/tls.h
@@ -120,7 +120,7 @@ struct task_info_s
 #if CONFIG_TLS_TASK_NELEM > 0
   uintptr_t       ta_telem[CONFIG_TLS_TASK_NELEM]; /* Task local storage elements */
 #endif
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
   tls_dtor_t      ta_tlsdtor[CONFIG_TLS_NELEM]; /* List of TLS destructors      */
 #endif
 #ifndef CONFIG_BUILD_KERNEL
@@ -192,7 +192,7 @@ struct tls_info_s
 {
   FAR struct task_info_s * tl_task;
 
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
   uintptr_t tl_elem[CONFIG_TLS_NELEM]; /* TLS elements */
 #endif
 
@@ -326,7 +326,7 @@ FAR struct tls_info_s *tls_get_info(void);
  *
  ****************************************************************************/
 
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
 void tls_destruct(void);
 #endif
 
diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h
index 0f31c28b3a..e8d2a4ae97 100644
--- a/include/sys/syscall_lookup.h
+++ b/include/sys/syscall_lookup.h
@@ -112,10 +112,6 @@ SYSCALL_LOOKUP(task_setcancelstate,        2)
   SYSCALL_LOOKUP(task_testcancel,          0)
 #endif
 
-#if CONFIG_TLS_TASK_NELEM > 0
-  SYSCALL_LOOKUP(task_tls_alloc,           1)
-#endif
-
 /* The following can be individually enabled */
 
 #ifdef CONFIG_ARCH_HAVE_FORK
diff --git a/libs/libc/pthread/pthread_exit.c b/libs/libc/pthread/pthread_exit.c
index a927dbf263..b18953c198 100644
--- a/libs/libc/pthread/pthread_exit.c
+++ b/libs/libc/pthread/pthread_exit.c
@@ -64,7 +64,7 @@ void pthread_exit(FAR void *exit_value)
   pthread_cleanup_popall(tls_get_info());
 #endif
 
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
   tls_destruct();
 #endif
 
diff --git a/libs/libc/pthread/pthread_getspecific.c b/libs/libc/pthread/pthread_getspecific.c
index 318ba01270..b1a2e62047 100644
--- a/libs/libc/pthread/pthread_getspecific.c
+++ b/libs/libc/pthread/pthread_getspecific.c
@@ -29,7 +29,7 @@
 
 #include <nuttx/tls.h>
 
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
 
 /****************************************************************************
  * Public Functions
diff --git a/libs/libc/pthread/pthread_keycreate.c b/libs/libc/pthread/pthread_keycreate.c
index f4d00e234f..f82aec64bb 100644
--- a/libs/libc/pthread/pthread_keycreate.c
+++ b/libs/libc/pthread/pthread_keycreate.c
@@ -31,7 +31,7 @@
 #include <nuttx/mutex.h>
 #include <nuttx/tls.h>
 
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
 
 /****************************************************************************
  * Private Functions
diff --git a/libs/libc/pthread/pthread_keydelete.c b/libs/libc/pthread/pthread_keydelete.c
index 1ade48412f..6cf16bcdbf 100644
--- a/libs/libc/pthread/pthread_keydelete.c
+++ b/libs/libc/pthread/pthread_keydelete.c
@@ -31,7 +31,7 @@
 #include <nuttx/mutex.h>
 #include <nuttx/tls.h>
 
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
 
 /****************************************************************************
  * Public Functions
diff --git a/libs/libc/pthread/pthread_setspecific.c b/libs/libc/pthread/pthread_setspecific.c
index 53c543a6da..226610b3e1 100644
--- a/libs/libc/pthread/pthread_setspecific.c
+++ b/libs/libc/pthread/pthread_setspecific.c
@@ -29,7 +29,7 @@
 
 #include <nuttx/tls.h>
 
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
 
 /****************************************************************************
  * Public Functions
diff --git a/libs/libc/stdlib/lib_exit.c b/libs/libc/stdlib/lib_exit.c
index 4f76a67256..1eee064e0b 100644
--- a/libs/libc/stdlib/lib_exit.c
+++ b/libs/libc/stdlib/lib_exit.c
@@ -100,7 +100,7 @@ void exit(int status)
   pthread_cleanup_popall(tls_get_info());
 #endif
 
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
   tls_destruct();
 #endif
 
@@ -149,7 +149,7 @@ void quick_exit(int status)
   pthread_cleanup_popall(tls_get_info());
 #endif
 
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
   tls_destruct();
 #endif
 
diff --git a/libs/libc/tls/CMakeLists.txt b/libs/libc/tls/CMakeLists.txt
index 2f73278a0a..6943471948 100644
--- a/libs/libc/tls/CMakeLists.txt
+++ b/libs/libc/tls/CMakeLists.txt
@@ -21,7 +21,7 @@
 set(SRCS task_getinfo.c tls_getinfo.c)
 
 if(NOT CONFIG_TLS_TASK_NELEM EQUAL 0)
-  list(APPEND SRCS task_tls.c)
+  list(APPEND SRCS task_tls.c task_tls_destruct.c)
 endif()
 
 if(NOT CONFIG_TLS_NELEM EQUAL 0)
diff --git a/libs/libc/tls/Kconfig b/libs/libc/tls/Kconfig
index cf4b6e60d5..aaa38ffa5e 100644
--- a/libs/libc/tls/Kconfig
+++ b/libs/libc/tls/Kconfig
@@ -44,6 +44,7 @@ config TLS_LOG2_MAXSTACK
 
 config TLS_NELEM
 	int "Number of TLS elements"
+	depends on !DISABLE_PTHREAD
 	default 0
 	range 0 255
 	---help---
@@ -56,6 +57,7 @@ config TLS_NELEM
 
 config TLS_TASK_NELEM
 	int "Number of Task Local Storage elements"
+	depends on !BUILD_KERNEL
 	default 0
 	range 0 255
 	---help---
diff --git a/libs/libc/tls/Make.defs b/libs/libc/tls/Make.defs
index f1e929b8e8..834df9bc2d 100644
--- a/libs/libc/tls/Make.defs
+++ b/libs/libc/tls/Make.defs
@@ -21,7 +21,7 @@
 CSRCS += task_getinfo.c tls_getinfo.c
 
 ifneq ($(CONFIG_TLS_TASK_NELEM),0)
-CSRCS += task_tls.c
+CSRCS += task_tls.c task_tls_destruct.c
 endif
 
 ifneq ($(CONFIG_TLS_NELEM),0)
diff --git a/libs/libc/tls/task_tls.c b/libs/libc/tls/task_tls.c
index 9c115eef55..5330e5201e 100644
--- a/libs/libc/tls/task_tls.c
+++ b/libs/libc/tls/task_tls.c
@@ -27,7 +27,7 @@
 #include <errno.h>
 #include <nuttx/tls.h>
 
-#if CONFIG_TLS_TASK_NELEM > 0
+#if defined(CONFIG_TLS_TASK_NELEM) && CONFIG_TLS_TASK_NELEM > 0
 
 /****************************************************************************
  * Public Functions
diff --git a/sched/task/task_tls_alloc.c b/libs/libc/tls/task_tls_destruct.c
similarity index 96%
rename from sched/task/task_tls_alloc.c
rename to libs/libc/tls/task_tls_destruct.c
index 668726964a..7e068afafe 100644
--- a/sched/task/task_tls_alloc.c
+++ b/libs/libc/tls/task_tls_destruct.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * sched/task/task_tls_alloc.c
+ * libs/libc/tls/task_tls_destruct.c
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -34,7 +34,7 @@
  * Private Data
  ****************************************************************************/
 
-#if CONFIG_TLS_TASK_NELEM > 0
+#if defined(CONFIG_TLS_TASK_NELEM) && CONFIG_TLS_TASK_NELEM > 0
 
 static mutex_t g_tlslock = NXMUTEX_INITIALIZER;
 static tls_dtor_t g_tlsdtor[CONFIG_TLS_TASK_NELEM];
@@ -57,7 +57,7 @@ static void tls_dtor(FAR void *arg)
  ****************************************************************************/
 
 /****************************************************************************
- * Name: task_tls_allocs
+ * Name: task_tls_alloc
  *
  * Description:
  *   Allocate a global-unique task local storage data index
diff --git a/libs/libc/tls/tls_destruct.c b/libs/libc/tls/tls_destruct.c
index baa857d4b9..bf72040bd7 100644
--- a/libs/libc/tls/tls_destruct.c
+++ b/libs/libc/tls/tls_destruct.c
@@ -28,7 +28,7 @@
 
 #include <nuttx/tls.h>
 
-#if CONFIG_TLS_NELEM > 0
+#if defined(CONFIG_TLS_NELEM) && CONFIG_TLS_NELEM > 0
 
 /****************************************************************************
  * Public Functions
diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c
index 0f3337a43e..6d2a8c1012 100644
--- a/sched/group/group_leave.c
+++ b/sched/group/group_leave.c
@@ -128,7 +128,7 @@ static void group_remove(FAR struct task_group_s *group)
 
 static inline void group_release(FAR struct task_group_s *group)
 {
-#if CONFIG_TLS_TASK_NELEM > 0
+#if defined(CONFIG_TLS_TASK_NELEM) && CONFIG_TLS_TASK_NELEM > 0
   task_tls_destruct();
 #endif
 
diff --git a/sched/task/CMakeLists.txt b/sched/task/CMakeLists.txt
index 6453fda69f..5f3f54e3ee 100644
--- a/sched/task/CMakeLists.txt
+++ b/sched/task/CMakeLists.txt
@@ -41,8 +41,7 @@ list(
   task_cancelpt.c
   task_terminate.c
   task_gettid.c
-  exit.c
-  task_tls_alloc.c)
+  exit.c)
 
 if(CONFIG_SCHED_HAVE_PARENT)
   list(APPEND SRCS task_getppid.c task_reparent.c)
diff --git a/sched/task/Make.defs b/sched/task/Make.defs
index 39d861bfa6..41124aff07 100644
--- a/sched/task/Make.defs
+++ b/sched/task/Make.defs
@@ -23,7 +23,6 @@ CSRCS += task_start.c task_delete.c task_exit.c task_exithook.c
 CSRCS += task_getgroup.c task_getpid.c task_prctl.c task_recover.c
 CSRCS += task_restart.c task_spawnparms.c task_setcancelstate.c
 CSRCS += task_cancelpt.c task_terminate.c task_gettid.c exit.c
-CSRCS += task_tls_alloc.c
 
 ifeq ($(CONFIG_SCHED_HAVE_PARENT),y)
 CSRCS += task_getppid.c task_reparent.c
diff --git a/syscall/syscall.csv b/syscall/syscall.csv
index 3fea87ecd5..837ae8dfb3 100644
--- a/syscall/syscall.csv
+++ b/syscall/syscall.csv
@@ -189,7 +189,6 @@
 "task_setcanceltype","sched.h","defined(CONFIG_CANCELLATION_POINTS)","int","int","FAR int *"
 "task_spawn","nuttx/spawn.h","!defined(CONFIG_BUILD_KERNEL)","int","FAR const char *","main_t","FAR const posix_spawn_file_actions_t *","FAR const posix_spawnattr_t *","FAR char * const []|FAR char * const *","FAR char * const []|FAR char * const *"
 "task_testcancel","sched.h","defined(CONFIG_CANCELLATION_POINTS)","void"
-"task_tls_alloc","nuttx/tls.h","CONFIG_TLS_TASK_NELEM > 0","int","tls_dtor_t"
 "tgkill","signal.h","","int","pid_t","pid_t","int"
 "time","time.h","","time_t","FAR time_t *"
 "timer_create","time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","clockid_t","FAR struct sigevent *","FAR timer_t *"