MCPcopy Create free account
hub / github.com/apache/nuttx / nxtask_setup_stackargs

Function nxtask_setup_stackargs

sched/task/task_setup.c:521–651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

519 ****************************************************************************/
520
521int nxtask_setup_stackargs(FAR struct tcb_s *tcb,
522 FAR const char *name,
523 FAR char * const argv[])
524{
525 FAR char **stackargv;
526 FAR char *str;
527 size_t strtablen;
528 size_t argvlen;
529 int nbytes;
530 int argc;
531 int i;
532 int ret = OK;
533
534 /* Give a name to the unnamed tasks */
535
536 if (!name)
537 {
538 name = g_noname;
539 }
540
541 /* Get the size of the task name (including the NUL terminator) */
542
543 strtablen = (strlen(name) + 1);
544
545 /* Count the number of arguments and get the accumulated size of the
546 * argument strings (including the null terminators). The argument count
547 * does not include the task name in that will be in argv[0].
548 */
549
550 argc = 0;
551 if (argv != NULL)
552 {
553 /* A NULL argument terminates the list */
554
555 while (argv[argc])
556 {
557 /* Add the size of this argument (with NUL terminator).
558 * Check each time if the accumulated size exceeds the
559 * size of the allocated stack.
560 */
561
562 strtablen += (strlen(argv[argc]) + 1);
563 DEBUGASSERT(strtablen < tcb->adj_stack_size);
564 if (strtablen >= tcb->adj_stack_size)
565 {
566 ret = -ENAMETOOLONG;
567 }
568 else
569 {
570 /* Increment the number of args. Here is a sanity check to
571 * prevent running away with an unterminated argv[] list.
572 * MAX_STACK_ARGS should be sufficiently large that this never
573 * happens in normal usage.
574 */
575
576 DEBUGASSERT(argc <= MAX_STACK_ARGS);
577 if (++argc > MAX_STACK_ARGS)
578 {

Callers 2

nxtask_setup_forkFunction · 0.85
nxtask_initFunction · 0.85

Calls 4

nxsched_get_tlsFunction · 0.85
strlenFunction · 0.50
up_stack_frameFunction · 0.50
strlcpyFunction · 0.50

Tested by

no test coverage detected