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/09/29 10:07:26 UTC

[GitHub] [incubator-nuttx] no1wudi opened a new pull request #4627: libc: Move atexit/on_exit to user space

no1wudi opened a new pull request #4627:
URL: https://github.com/apache/incubator-nuttx/pull/4627


   ## Summary
   
   1. Add a new non-standard signal `SIGEXIT`
   2. Use signal infrastructure in nxtask_exithook by `nxsig_tcbdispatch` instead of a new syscall to trigger user space callbacks
   
   ## Impact
   None
   ## Testing
   ostest on arm & riscv
   


-- 
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



[GitHub] [incubator-nuttx] no1wudi commented on a change in pull request #4627: libc: Move atexit/on_exit to user space

Posted by GitBox <gi...@apache.org>.
no1wudi commented on a change in pull request #4627:
URL: https://github.com/apache/incubator-nuttx/pull/4627#discussion_r730544038



##########
File path: syscall/syscall.csv
##########
@@ -79,6 +79,9 @@
 "nx_vsyslog","nuttx/syslog/syslog.h","","int","int","FAR const IPTR char *","FAR va_list *"
 "nxsched_get_stackinfo","nuttx/sched.h","","int","pid_t","FAR struct stackinfo_s *"
 "nxsched_get_streams","nuttx/sched.h","defined(CONFIG_FILE_STREAM)","FAR struct streamlist *"
+"nxsig_stop_task","nuttx/signal.h","defined(CONFIG_SIG_DEFAULT)","void","int"
+"nxsig_abnormal_termination","nuttx/signal.h","defined(CONFIG_SIG_DEFAULT)","int","int"
+"nxsig_action","nuttx/signal.h","","int","int","FAR const struct sigaction *","FAR struct sigaction *","bool"

Review comment:
       Some logic in default handler need to touch tcb, thus these handlers were separated as two part in libc and kernel




-- 
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



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4627: libc: Move atexit/on_exit to user space

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4627:
URL: https://github.com/apache/incubator-nuttx/pull/4627#discussion_r718429633



##########
File path: include/signal.h
##########
@@ -234,6 +234,14 @@
 #  endif
 #endif
 
+/* SIGEXIT is to trigger atext/on_exit logic */
+
+#ifndef CONFIG_SIG_SIGEXIT
+#  define SIGEXIT       18

Review comment:
       should we use SIGKILL for this?




-- 
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



[GitHub] [incubator-nuttx] no1wudi commented on a change in pull request #4627: libc: Move atexit/on_exit to user space

Posted by GitBox <gi...@apache.org>.
no1wudi commented on a change in pull request #4627:
URL: https://github.com/apache/incubator-nuttx/pull/4627#discussion_r730545710



##########
File path: sched/task/task_cancelpt.c
##########
@@ -153,7 +153,20 @@ bool enter_cancellation_point(void)
               else
 #endif
                 {
+#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)

Review comment:
       Since there are no actual difference with user space and kernel space, call exit direct is more efficient, IMHO.




-- 
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



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4627: libc: Move atexit/on_exit to user space

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4627:
URL: https://github.com/apache/incubator-nuttx/pull/4627#discussion_r730456350



##########
File path: syscall/syscall.csv
##########
@@ -79,6 +79,9 @@
 "nx_vsyslog","nuttx/syslog/syslog.h","","int","int","FAR const IPTR char *","FAR va_list *"
 "nxsched_get_stackinfo","nuttx/sched.h","","int","pid_t","FAR struct stackinfo_s *"
 "nxsched_get_streams","nuttx/sched.h","defined(CONFIG_FILE_STREAM)","FAR struct streamlist *"
+"nxsig_stop_task","nuttx/signal.h","defined(CONFIG_SIG_DEFAULT)","void","int"
+"nxsig_abnormal_termination","nuttx/signal.h","defined(CONFIG_SIG_DEFAULT)","int","int"
+"nxsig_action","nuttx/signal.h","","int","int","FAR const struct sigaction *","FAR struct sigaction *","bool"

Review comment:
       Why add the libc function into syscall.csv?

##########
File path: sched/task/task_cancelpt.c
##########
@@ -153,7 +153,20 @@ bool enter_cancellation_point(void)
               else
 #endif
                 {
+#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)

Review comment:
       why not use the same method for flat build?

##########
File path: libs/libc/sched/task_exit.c
##########
@@ -0,0 +1,115 @@
+/****************************************************************************
+ * libs/libc/sched/task_exit.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 <assert.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/sched.h>
+#include <nuttx/tls.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_SCHED_ATEXIT) || defined(CONFIG_SCHED_ONEXIT)
+
+/****************************************************************************
+ * Name: nxtask_onexit
+ *
+ * Description:
+ *   Handle SIGEXIT (Call atexit/on_exit callbacks on exit).
+ *
+ ****************************************************************************/
+
+static void nxtask_onexit(FAR struct task_info_s *info, int status)
+{
+  int index;
+
+  DEBUGASSERT(info);
+
+  /* Call each on_exit function in reverse order of registration.
+       * on_exit() functions are registered from lower to higher array
+       * indices; they must be called in the reverse order of registration
+       * when the task group exits, i.e., from higher to lower indices.
+       */
+
+  for (index = CONFIG_SCHED_EXIT_MAX - 1; index >= 0; index--)
+    {
+      if (info->ta_exit[index].func.on)
+        {
+          onexitfunc_t func;
+          FAR void *arg;
+
+          /* Nullify the on_exit function to prevent its reuse. */
+
+          func = info->ta_exit[index].func.on;
+          arg = info->ta_exit[index].arg;
+
+          info->ta_exit[index].func.on = NULL;
+          info->ta_exit[index].arg = NULL;
+
+          /* Call the on_exit function */
+
+          (*func)(status, arg);
+        }
+    }
+}
+
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: exit
+ *
+ * Description:
+ *   The exit() function causes normal process termination and the value of
+ *   status & 0377 to be returned to the parent.
+ *
+ *   All open streams are flushed and closed.
+ *
+ ****************************************************************************/
+
+void exit(int status)
+{
+#if defined(CONFIG_SCHED_ATEXIT) || defined(CONFIG_SCHED_ONEXIT)
+  FAR struct task_info_s *info = task_get_info();
+
+  DEBUGASSERT(info);
+
+  if (info->ta_nmembers == 1)

Review comment:
       why need do nxtask_onexit specially?




-- 
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



[GitHub] [incubator-nuttx] no1wudi commented on a change in pull request #4627: libc: Move atexit/on_exit to user space

Posted by GitBox <gi...@apache.org>.
no1wudi commented on a change in pull request #4627:
URL: https://github.com/apache/incubator-nuttx/pull/4627#discussion_r730544651



##########
File path: libs/libc/sched/task_exit.c
##########
@@ -0,0 +1,115 @@
+/****************************************************************************
+ * libs/libc/sched/task_exit.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 <assert.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/sched.h>
+#include <nuttx/tls.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_SCHED_ATEXIT) || defined(CONFIG_SCHED_ONEXIT)
+
+/****************************************************************************
+ * Name: nxtask_onexit
+ *
+ * Description:
+ *   Handle SIGEXIT (Call atexit/on_exit callbacks on exit).
+ *
+ ****************************************************************************/
+
+static void nxtask_onexit(FAR struct task_info_s *info, int status)
+{
+  int index;
+
+  DEBUGASSERT(info);
+
+  /* Call each on_exit function in reverse order of registration.
+       * on_exit() functions are registered from lower to higher array
+       * indices; they must be called in the reverse order of registration
+       * when the task group exits, i.e., from higher to lower indices.
+       */
+
+  for (index = CONFIG_SCHED_EXIT_MAX - 1; index >= 0; index--)
+    {
+      if (info->ta_exit[index].func.on)
+        {
+          onexitfunc_t func;
+          FAR void *arg;
+
+          /* Nullify the on_exit function to prevent its reuse. */
+
+          func = info->ta_exit[index].func.on;
+          arg = info->ta_exit[index].arg;
+
+          info->ta_exit[index].func.on = NULL;
+          info->ta_exit[index].arg = NULL;
+
+          /* Call the on_exit function */
+
+          (*func)(status, arg);
+        }
+    }
+}
+
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: exit
+ *
+ * Description:
+ *   The exit() function causes normal process termination and the value of
+ *   status & 0377 to be returned to the parent.
+ *
+ *   All open streams are flushed and closed.
+ *
+ ****************************************************************************/
+
+void exit(int status)
+{
+#if defined(CONFIG_SCHED_ATEXIT) || defined(CONFIG_SCHED_ONEXIT)
+  FAR struct task_info_s *info = task_get_info();
+
+  DEBUGASSERT(info);
+
+  if (info->ta_nmembers == 1)

Review comment:
       We must ensure it is the last thread in group.




-- 
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



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4627: libc: Move atexit/on_exit to user space

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4627:
URL: https://github.com/apache/incubator-nuttx/pull/4627#discussion_r719109893



##########
File path: include/signal.h
##########
@@ -234,6 +234,14 @@
 #  endif
 #endif
 
+/* SIGEXIT is to trigger atext/on_exit logic */
+
+#ifndef CONFIG_SIG_SIGEXIT
+#  define SIGEXIT       18

Review comment:
       Yes. BTW, to follow the strict user/kernel separation, it's better to move all default signal handler to userspace side.




-- 
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



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #4627: libc: Move atexit/on_exit to user space

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #4627:
URL: https://github.com/apache/incubator-nuttx/pull/4627#discussion_r718429633



##########
File path: include/signal.h
##########
@@ -234,6 +234,14 @@
 #  endif
 #endif
 
+/* SIGEXIT is to trigger atext/on_exit logic */
+
+#ifndef CONFIG_SIG_SIGEXIT
+#  define SIGEXIT       18

Review comment:
       should we use SIGKILL for this?




-- 
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



[GitHub] [incubator-nuttx] no1wudi commented on a change in pull request #4627: libc: Move atexit/on_exit to user space

Posted by GitBox <gi...@apache.org>.
no1wudi commented on a change in pull request #4627:
URL: https://github.com/apache/incubator-nuttx/pull/4627#discussion_r719106603



##########
File path: include/signal.h
##########
@@ -234,6 +234,14 @@
 #  endif
 #endif
 
+/* SIGEXIT is to trigger atext/on_exit logic */
+
+#ifndef CONFIG_SIG_SIGEXIT
+#  define SIGEXIT       18

Review comment:
       Did you mean move default SIGKILL to user space, and redirect all task exit request to it ?




-- 
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



[GitHub] [incubator-nuttx] no1wudi closed pull request #4627: libc: Move atexit/on_exit to user space

Posted by GitBox <gi...@apache.org>.
no1wudi closed pull request #4627:
URL: https://github.com/apache/incubator-nuttx/pull/4627


   


-- 
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