2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2014-08-09 00:44:08 +02:00
|
|
|
* sched/task/task_start.c
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2018-08-27 19:40:09 +02:00
|
|
|
* Copyright (C) 2007-2010, 2013, 2018 Gregory Nutt. All rights reserved.
|
2012-07-14 21:30:31 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2008-01-29 01:50:16 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-03-11 23:19:01 +01:00
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2007-03-11 23:19:01 +01:00
|
|
|
* Included Files
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-14 19:39:29 +01:00
|
|
|
|
2007-03-11 23:19:01 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <debug.h>
|
2018-08-26 16:49:08 +02:00
|
|
|
#include <string.h>
|
2009-12-14 19:39:29 +01:00
|
|
|
|
2013-03-14 23:44:06 +01:00
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/sched.h>
|
|
|
|
|
2018-08-26 16:49:08 +02:00
|
|
|
#include "group/group.h"
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2018-08-27 19:40:09 +02:00
|
|
|
#include "signal/signal.h"
|
2014-08-09 00:44:08 +02:00
|
|
|
#include "task/task.h"
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2013-03-14 23:44:06 +01:00
|
|
|
* Pre-processor Definitions
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2018-08-26 16:49:08 +02:00
|
|
|
|
2014-11-13 01:54:35 +01:00
|
|
|
/* This is an artificial limit to detect error conditions where an argv[]
|
|
|
|
* list is not properly terminated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_START_ARGS 256
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2018-08-26 16:49:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
2007-03-11 23:19:01 +01:00
|
|
|
* Public Functions
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2008-01-29 01:50:16 +01:00
|
|
|
/****************************************************************************
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
* Name: nxtask_start
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2012-07-14 21:30:31 +02:00
|
|
|
* This function is the low level entry point into the main thread of
|
|
|
|
* execution of a task. It receives initial control when the task is
|
|
|
|
* started and calls main entry point of the newly started task.
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2007-03-11 23:19:01 +01:00
|
|
|
* None
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-03-11 23:19:01 +01:00
|
|
|
* None
|
|
|
|
*
|
2008-01-29 01:50:16 +01:00
|
|
|
****************************************************************************/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 20:42:51 +01:00
|
|
|
void nxtask_start(void)
|
2007-03-11 23:19:01 +01:00
|
|
|
{
|
2016-02-07 00:44:41 +01:00
|
|
|
FAR struct task_tcb_s *tcb = (FAR struct task_tcb_s *)this_task();
|
2013-03-14 23:44:06 +01:00
|
|
|
int exitcode;
|
2007-03-11 23:19:01 +01:00
|
|
|
int argc;
|
|
|
|
|
2013-02-04 22:24:00 +01:00
|
|
|
DEBUGASSERT((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD);
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
#ifdef CONFIG_SIG_DEFAULT
|
2018-08-26 16:49:08 +02:00
|
|
|
/* Set up default signal actions */
|
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
nxsig_default_initialize(&tcb->cmn);
|
2018-08-26 16:49:08 +02:00
|
|
|
#endif
|
|
|
|
|
2013-01-27 16:52:58 +01:00
|
|
|
/* Execute the start hook if one has been registered */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_STARTHOOK
|
2017-10-02 22:04:25 +02:00
|
|
|
if (tcb->starthook != NULL)
|
2013-01-27 16:52:58 +01:00
|
|
|
{
|
|
|
|
tcb->starthook(tcb->starthookarg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-11-13 02:01:29 +01:00
|
|
|
/* Count how many non-null arguments we are passing. The first non-null
|
|
|
|
* argument terminates the list .
|
|
|
|
*/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2014-11-13 02:01:29 +01:00
|
|
|
argc = 1;
|
|
|
|
while (tcb->argv[argc])
|
2007-03-11 23:19:01 +01:00
|
|
|
{
|
2014-11-13 02:01:29 +01:00
|
|
|
/* Increment the number of args. Here is a sanity check to
|
|
|
|
* prevent running away with an unterminated argv[] list.
|
|
|
|
* MAX_START_ARGS should be sufficiently large that this never
|
|
|
|
* happens in normal usage.
|
|
|
|
*/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2014-11-13 02:01:29 +01:00
|
|
|
if (++argc > MAX_START_ARGS)
|
2012-07-14 21:30:31 +02:00
|
|
|
{
|
2014-11-13 02:01:29 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2012-07-14 21:30:31 +02:00
|
|
|
}
|
2007-03-11 23:19:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-14 23:44:06 +01:00
|
|
|
/* Call the 'main' entry point passing argc and argv. In the kernel build
|
|
|
|
* this has to be handled differently if we are starting a user-space task;
|
|
|
|
* we have to switch to user-mode before calling the task.
|
2010-09-05 21:13:48 +02:00
|
|
|
*/
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2014-08-29 22:47:22 +02:00
|
|
|
#if defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)
|
2013-03-14 23:44:06 +01:00
|
|
|
if ((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL)
|
|
|
|
{
|
|
|
|
up_task_start(tcb->cmn.entry.main, argc, tcb->argv);
|
|
|
|
exitcode = EXIT_FAILURE; /* Should not get here */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
exitcode = tcb->cmn.entry.main(argc, tcb->argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call exit() if/when the task returns */
|
|
|
|
|
|
|
|
exit(exitcode);
|
2007-03-11 23:19:01 +01:00
|
|
|
}
|