patacongo edited a comment on pull request #1099:
URL: https://github.com/apache/incubator-nuttx/pull/1099#issuecomment-633719356


   Here is a summary of the relevant lines from binfmt/binfmt_execmodule.c 
(with a few embellishments).  This is all that you need to do:
   
       135   /* Allocate a TCB for the new task. */
       136
       137   tcb = (FAR struct task_tcb_s *)kmm_zalloc(sizeof(struct 
task_tcb_s));
       138   if (tcb == NULL)
       139     {
       140       return -ENOMEM;
       141     }
       
                 tcb->flags = TCB_FLAG_TTYPE_KERNEL;
       153
       154   /* Allocate the stack for the new task.
       155    *
       156    * REVISIT:  This allocation is currently always from the user 
heap.  That
       157    * will need to change if/when we want to support dynamic stack 
allocation.
       158    */
       159
       160   stack = (FAR uint32_t *)kumm_malloc(binp->stacksize);
       161   if (stack == NULL)
       162     {
                 kmm_free(tcb);
                 return -ENOMEM;
       165     }
       166
       167   /* Initialize the task */
       168
       169   ret = task_init((FAR struct tcb_s *)tcb, binp->filename, 
binp->priority,
       170                   stack, binp->stacksize, binp->entrypt, binp->argv);
       171   if (ret < 0)
       172     {
                 kmm_free(tcb);
       174       kumm_free(stack);
                 return ret;
       176     }
       254
       255   /* Then activate the task at the provided priority */
       256
       257   ret = task_activate((FAR struct tcb_s *)tcb);
       258   if (ret < 0)
       259     {
                 kmm_free(tcb);
                 kumm_free(stack);
                 return ret;
       262     }
   
   the task_init() and task_activate interfaces were created to permit complete 
control over how tasks are created.  You have complete flexibility but with the 
cost of some slightly more complex interfaces.  This is a good thing and a 
proper use of the interfaces within the OS.


----------------------------------------------------------------
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:
[email protected]


Reply via email to