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
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-03-11 23:19:01 +01:00
|
|
|
*
|
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>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2007-03-11 23:19:01 +01:00
|
|
|
#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();
|
2020-06-30 19:58:58 +02:00
|
|
|
int exitcode = EXIT_FAILURE;
|
2007-03-11 23:19:01 +01:00
|
|
|
int argc;
|
|
|
|
|
2020-03-08 13:51:35 +01:00
|
|
|
DEBUGASSERT((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) != \
|
|
|
|
TCB_FLAG_TTYPE_PTHREAD);
|
2013-02-04 22:24:00 +01:00
|
|
|
|
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
|
|
|
|
2020-09-30 12:09:22 +02:00
|
|
|
if ((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL)
|
2013-03-14 23:44:06 +01:00
|
|
|
{
|
2020-09-30 12:09:22 +02:00
|
|
|
exitcode = tcb->cmn.entry.main(argc, tcb->argv);
|
2013-03-14 23:44:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-30 12:09:22 +02:00
|
|
|
#ifdef CONFIG_BUILD_FLAT
|
|
|
|
nxtask_startup(tcb->cmn.entry.main, argc, tcb->argv);
|
2020-06-30 19:58:58 +02:00
|
|
|
#else
|
2020-09-30 12:09:22 +02:00
|
|
|
up_task_start(tcb->cmn.entry.main, argc, tcb->argv);
|
2020-06-30 19:58:58 +02:00
|
|
|
#endif
|
2020-09-30 12:09:22 +02:00
|
|
|
}
|
2013-03-14 23:44:06 +01:00
|
|
|
|
|
|
|
/* Call exit() if/when the task returns */
|
|
|
|
|
|
|
|
exit(exitcode);
|
2007-03-11 23:19:01 +01:00
|
|
|
}
|