You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/12/03 14:10:54 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4935: arch/arm: Implement TLS support

xiaoxiang781216 commented on a change in pull request #4935:
URL: https://github.com/apache/incubator-nuttx/pull/4935#discussion_r761961450



##########
File path: arch/arm/src/common/arm_tls.c
##########
@@ -0,0 +1,82 @@
+/****************************************************************************
+ * arch/arm/src/common/arm_tls.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/arch.h>
+#include <nuttx/tls.h>
+
+#include "arm_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_tls_size
+ *
+ * Description:
+ *   Get tls (tdata + tbss) section size
+ *
+ * Returned Value:
+ *   Size of (tdata + tbss)
+ *
+ ****************************************************************************/
+
+int up_tls_size(void)
+{
+  /* Extra 8 byte (2 pointer) according to GCC */
+
+  return _END_TBSS - _START_TDATA + 8;

Review comment:
       move +8 to first since the extra data locate at the beginning

##########
File path: sched/Kconfig
##########
@@ -600,6 +600,13 @@ config SCHED_USER_IDENTITY
 		Those can then be managed using the interfaces.  Child tasks will
 		inherit the UID and GID of its parent.
 
+config SCHED_THREAD_LOCAL
+	bool "Support __thread keyword"
+	default n
+	depends on ARCH_ARM

Review comment:
       ARCH_ARM to ARCH_HAVE_TLS

##########
File path: arch/Kconfig
##########
@@ -422,6 +427,14 @@ config ARCH_USE_TEXT_HEAP
 		regions for instruction and data and the memory region used for
 		usual malloc doesn't work for instruction.
 
+config ARCH_TLS
+	bool "Enable TLS"
+	default n
+	depends on ARCH_HAVE_TLS && BUILD_FLAT

Review comment:
       can we support TLS in protected build too?

##########
File path: arch/arm/src/common/arm_tls.c
##########
@@ -0,0 +1,82 @@
+/****************************************************************************
+ * arch/arm/src/common/arm_tls.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/arch.h>
+#include <nuttx/tls.h>
+
+#include "arm_internal.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_tls_size
+ *
+ * Description:
+ *   Get tls (tdata + tbss) section size
+ *
+ * Returned Value:
+ *   Size of (tdata + tbss)
+ *
+ ****************************************************************************/
+
+int up_tls_size(void)
+{
+  /* Extra 8 byte (2 pointer) according to GCC */
+
+  return _END_TBSS - _START_TDATA + 8;
+}
+
+/****************************************************************************
+ * Name: up_tls_initialize
+ *
+ * Description:
+ *   Initialize thread local region
+ *
+ * Input Parameters:
+ *   tls_data - The memory region to initialize
+ *
+ ****************************************************************************/
+
+void up_tls_initialize(uint8_t *tls_data)
+{
+  memcpy(&tls_data[8], _START_TDATA, _END_TDATA - _START_TDATA);
+  memset(&tls_data[_END_TDATA - _START_TDATA + 8], 0,

Review comment:
       move +8 to first

##########
File path: include/nuttx/arch.h
##########
@@ -2398,6 +2398,40 @@ int up_rtc_getdatetime_with_subseconds(FAR struct tm *tp, FAR long *nsec);
 int up_rtc_settime(FAR const struct timespec *tp);
 #endif
 
+/****************************************************************************
+ * Name: up_tls_size
+ *
+ * Description:
+ *   Get tls (tdata + tbss) section size
+ *
+ * Returned Value:
+ *   Size of (tdata + tbss)
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_TLS
+int up_tls_size(void);
+#else
+#define up_tls_size() 0
+#endif
+
+/****************************************************************************
+ * Name: up_tls_initialize
+ *
+ * Description:
+ *   Initialize thread local region
+ *
+ * Input Parameters:
+ *   tls_data - The memory region to initialize
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_TLS
+void up_tls_initialize(uint8_t *tls_data);

Review comment:
       uin8_t * to FAR void *

##########
File path: arch/Kconfig
##########
@@ -352,6 +353,10 @@ config ARCH_HAVE_TESTSET
 	bool
 	default n
 
+config ARCH_HAVE_TLS

Review comment:
       ARCH_HAVE_TLS to ARCH_HAVE_THREAD_LOCAL?
   the supported from tls can be done in the general way, only thread_local keyword need arch or compiler specific code

##########
File path: arch/Kconfig
##########
@@ -422,6 +427,14 @@ config ARCH_USE_TEXT_HEAP
 		regions for instruction and data and the memory region used for
 		usual malloc doesn't work for instruction.
 
+config ARCH_TLS

Review comment:
       is it enough to control thread_local only through SCHED_THREAD_LOCAL?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org