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/05/27 17:39:41 UTC

[GitHub] [incubator-nuttx] patacongo opened a new pull request #1141: sched/sched/sched_releasetcb.c: Handle custom stack allocations.

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


   ## Summary
   
   sched_releasetcb() will normally free the stack allocated for a task.  However, a task with a custom, user-managed stack may be created using` nxtask_init()` followed by `nxtask_activate()`.  If such a custom stack is used then it must not be free in this many or a crash will most likely result.
   
   This change addes a flag call `TCB_FLAG_CUSTOM_STACK` that may be passed in the the pre-alloacted TCB to `nxtask_init()`.  This flag is not used internally anywhere in the OS except that if set, it will prevent `sched_releasetcb()` from attempting to free that custom stack.
   
   ## Impact
   
   None expected
   
   ## Testing
   
   sim:nsh
   
   


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



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #1141: sched/sched/sched_releasetcb.c: Handle custom stack allocations.

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



##########
File path: include/nuttx/sched.h
##########
@@ -103,9 +103,10 @@
 #  define TCB_FLAG_SCHED_SPORADIC  (2 << TCB_FLAG_POLICY_SHIFT)  /* Sporadic scheding policy */
 #  define TCB_FLAG_SCHED_OTHER     (3 << TCB_FLAG_POLICY_SHIFT)  /* Other scheding policy */
 #define TCB_FLAG_CPU_LOCKED        (1 << 7)                      /* Bit 7: Locked to this CPU */
-#define TCB_FLAG_SIGNAL_ACTION     (1 << 8)                      /* Bit 8: In a signal handler */
-#define TCB_FLAG_SYSCALL           (1 << 9)                      /* Bit 9: In a system call */
-#define TCB_FLAG_EXIT_PROCESSING   (1 << 10)                     /* Bit 10: Exitting */
+#define TCB_FLAG_CUSTOM_STACK      (1 << 8)                      /* Bit 8: Thread uses a custom stack */

Review comment:
       @patacongo TCB_FLAG_CUSTOM_STACK is redundancy because up_release_stack already call xmm_heapmember before free the memory:
   ```
   void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
   {
     /* Is there a stack allocated? */
   
     if (dtcb->stack_alloc_ptr)
       {
   #ifdef CONFIG_MM_KERNEL_HEAP
         /* Use the kernel allocator if this is a kernel thread */
   
         if (ttype == TCB_FLAG_TTYPE_KERNEL)
           {
             if (kmm_heapmember(dtcb->stack_alloc_ptr))
               {
                 kmm_free(dtcb->stack_alloc_ptr);
               }
           }
         else
   #endif
           {
             /* Use the user-space allocator if this is a task or pthread */
   
             if (umm_heapmember(dtcb->stack_alloc_ptr))
               {
                 kumm_free(dtcb->stack_alloc_ptr);
               }
           }
   
         /* Mark the stack freed */
   
         dtcb->stack_alloc_ptr = NULL;
       }
   
     /* The size of the allocated stack is now zero */
   
     dtcb->adj_stack_size = 0;
   }
   ```




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



[GitHub] [incubator-nuttx] patacongo commented on pull request #1141: sched/sched/sched_releasetcb.c: Handle custom stack allocations.

Posted by GitBox <gi...@apache.org>.
patacongo commented on pull request #1141:
URL: https://github.com/apache/incubator-nuttx/pull/1141#issuecomment-634849576


   Refer to https://cwiki.apache.org/confluence/display/NUTTX/Kernel+Threads+with+Custom+Stacks for a discussion of how the `TCB_FLAG_CUSTOM_STACK` is used.


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



[GitHub] [incubator-nuttx] Ouss4 merged pull request #1141: sched/sched/sched_releasetcb.c: Handle custom stack allocations.

Posted by GitBox <gi...@apache.org>.
Ouss4 merged pull request #1141:
URL: https://github.com/apache/incubator-nuttx/pull/1141


   


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