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 2020/06/30 13:59:02 UTC

[GitHub] [incubator-nuttx] ghn-certi commented on a change in pull request #1328: [DRAFT] pthread_cleanup functions must be called from user space

ghn-certi commented on a change in pull request #1328:
URL: https://github.com/apache/incubator-nuttx/pull/1328#discussion_r447699093



##########
File path: sched/pthread/pthread_create.c
##########
@@ -72,28 +72,29 @@ static const char g_pthreadname[] = "<pthread>";
  ****************************************************************************/
 
 /****************************************************************************
- * Name: pthread_argsetup
+ * Name: pthread_tcb_setup
  *
  * Description:
  *   This functions sets up parameters in the Task Control Block (TCB) in
  *   preparation for starting a new thread.
  *
- *   pthread_argsetup() is called from nxtask_init() and nxtask_start() to
+ *   pthread_tcb_setup() is called from nxtask_init() and nxtask_start() to
  *   create a new task (with arguments cloned via strdup) or pthread_create()
  *   which has one argument passed by value (distinguished by the pthread
  *   boolean argument).
  *
  * Input Parameters:
- *   tcb        - Address of the new task's TCB
- *   arg        - The argument to provide to the pthread on startup.
+ *   tcb     - Address of the new task's TCB
+ *   startup - User-space pthread startup function

Review comment:
       ```suggestion
    *   startup - User space pthread startup function
   ```

##########
File path: arch/arm/src/armv6-m/arm_svcall.c
##########
@@ -313,22 +313,22 @@ int arm_svcall(int irq, FAR void *context, FAR void *arg)
        *   R2 = arg
        */
 
-#if defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_DISABLE_PTHREAD)
+#if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD)
       case SYS_pthread_start:
         {
           /* Set up to return to the user-space pthread start-up function in
            * unprivileged mode.
            */
 
-          regs[REG_PC]         = (uint32_t)USERSPACE->pthread_startup;
+          regs[REG_PC]         = (uint32_t)regs[REG_R1]; /* startup */
           regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
 
-          /* Change the parameter ordering to match the expectation of struct
-           * userpace_s pthread_startup:
+          /* Change the parameter ordering to match the expectation of the
+           * useri space pthread_startup:

Review comment:
       ```suggestion
              * user space pthread_startup:
   ```

##########
File path: libs/libc/pthread/pthread_create.c
##########
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * libs/libc/pthread/pthread_create.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 <pthread.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pthread_startup
+ *
+ * Description:
+ *   This function is the user-space, pthread startup function.  Its purpose
+ *   is to to catch the return from the pthread main function so that

Review comment:
       ```suggestion
    *   is to catch the return from the pthread main function so that
   ```

##########
File path: libs/libc/pthread/pthread_create.c
##########
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * libs/libc/pthread/pthread_create.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 <pthread.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pthread_startup
+ *
+ * Description:
+ *   This function is the user-space, pthread startup function.  Its purpose

Review comment:
       ```suggestion
    *   This function is the user space pthread startup function.  Its purpose
   ```

##########
File path: sched/pthread/pthread_create.c
##########
@@ -72,28 +72,29 @@ static const char g_pthreadname[] = "<pthread>";
  ****************************************************************************/
 
 /****************************************************************************
- * Name: pthread_argsetup
+ * Name: pthread_tcb_setup
  *
  * Description:
  *   This functions sets up parameters in the Task Control Block (TCB) in

Review comment:
       ```suggestion
    *   This function sets up parameters in the Task Control Block (TCB) in
   ```

##########
File path: sched/pthread/pthread_create.c
##########
@@ -205,13 +210,14 @@ static void pthread_start(void)
  ****************************************************************************/
 
 /****************************************************************************
- * Name:  pthread_create
+ * Name:  nx_pthread_create
  *
  * Description:
  *   This function creates and activates a new thread with a specified

Review comment:
       ```suggestion
    *   This function creates and activates a new thread with specified
   ```

##########
File path: libs/libc/pthread/pthread_create.c
##########
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * libs/libc/pthread/pthread_create.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 <pthread.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pthread_startup
+ *
+ * Description:
+ *   This function is the user-space, pthread startup function.  Its purpose
+ *   is to to catch the return from the pthread main function so that
+ *   pthread_exit() can be called from user space
+ *
+ * Input Parameters:
+ *   entry - The user-space address of the pthread entry point
+ *   arg   - Standard argument for the pthread entry point
+ *
+ * Returned Value:
+ *   None.  This function does not return.
+ *
+ ****************************************************************************/
+
+static void pthread_startup(pthread_startroutine_t entry,
+                            pthread_addr_t arg)
+{
+  DEBUGASSERT(entry != NULL);
+
+  /* Pass control to the thread entry point.  Handle any returned value. */
+
+  pthread_exit(entry(arg));
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name:  pthread_create
+ *
+ * Description:
+ *   This function creates and activates a new thread with a specified

Review comment:
       ```suggestion
    *   This function creates and activates a new thread with specified
   ```




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

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