| 86 | ****************************************************************************/ |
| 87 | |
| 88 | int nxtask_init(FAR struct tcb_s *tcb, const char *name, int priority, |
| 89 | FAR void *stack, uint32_t stack_size, |
| 90 | main_t entry, FAR char * const argv[], |
| 91 | FAR char * const envp[], |
| 92 | FAR const posix_spawn_file_actions_t *actions) |
| 93 | { |
| 94 | uint8_t ttype = tcb->flags & TCB_FLAG_TTYPE_MASK; |
| 95 | int ret; |
| 96 | |
| 97 | sched_trace_begin(); |
| 98 | |
| 99 | #ifndef CONFIG_DISABLE_PTHREAD |
| 100 | /* Only tasks and kernel threads can be initialized in this way */ |
| 101 | |
| 102 | DEBUGASSERT(tcb && ttype != TCB_FLAG_TTYPE_PTHREAD); |
| 103 | #endif |
| 104 | |
| 105 | #ifdef CONFIG_ARCH_ADDRENV |
| 106 | /* Kernel threads do not own any address environment */ |
| 107 | |
| 108 | if (ttype == TCB_FLAG_TTYPE_KERNEL) |
| 109 | { |
| 110 | tcb->addrenv_own = NULL; |
| 111 | } |
| 112 | #endif |
| 113 | |
| 114 | /* Create a new task group */ |
| 115 | |
| 116 | ret = group_allocate(tcb, tcb->flags); |
| 117 | if (ret < 0) |
| 118 | { |
| 119 | sched_trace_end(); |
| 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | #ifndef CONFIG_DISABLE_PTHREAD |
| 124 | /* Initialize the task join */ |
| 125 | |
| 126 | nxtask_joininit(tcb); |
| 127 | #endif |
| 128 | |
| 129 | /* Duplicate the parent tasks environment */ |
| 130 | |
| 131 | ret = env_dup(tcb->group, envp); |
| 132 | if (ret < 0) |
| 133 | { |
| 134 | goto errout_with_group; |
| 135 | } |
| 136 | |
| 137 | /* Associate file descriptors with the new task */ |
| 138 | |
| 139 | ret = group_setuptaskfiles(tcb, actions, true); |
| 140 | if (ret < 0) |
| 141 | { |
| 142 | goto errout_with_group; |
| 143 | } |
| 144 | |
| 145 | /* Set the task name */ |
no test coverage detected