2008-01-29 08:50:16 +08:00
|
|
|
/****************************************************************************
|
2014-08-09 06:44:08 +08:00
|
|
|
* sched/task/task_start.c
|
2007-03-12 06:19:01 +08:00
|
|
|
*
|
2024-09-11 19:45:11 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 23:33:58 +08: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-12 06:19:01 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-03-12 06:19:01 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08: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-12 06:19:01 +08:00
|
|
|
*
|
2008-01-29 08:50:16 +08:00
|
|
|
****************************************************************************/
|
2007-03-12 06:19:01 +08:00
|
|
|
|
2008-01-29 08:50:16 +08:00
|
|
|
/****************************************************************************
|
2007-03-12 06:19:01 +08:00
|
|
|
* Included Files
|
2008-01-29 08:50:16 +08:00
|
|
|
****************************************************************************/
|
2007-03-12 06:19:01 +08:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-15 02:39:29 +08:00
|
|
|
|
2007-03-12 06:19:01 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sched.h>
|
2021-05-18 14:59:14 +08:00
|
|
|
#include <assert.h>
|
2007-03-12 06:19:01 +08:00
|
|
|
#include <debug.h>
|
2018-08-26 22:49:08 +08:00
|
|
|
#include <string.h>
|
2009-12-15 02:39:29 +08:00
|
|
|
|
2013-03-15 06:44:06 +08:00
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/sched.h>
|
2022-05-27 10:05:43 +08:00
|
|
|
#include <nuttx/tls.h>
|
2013-03-15 06:44:06 +08:00
|
|
|
|
2018-08-26 22:49:08 +08:00
|
|
|
#include "group/group.h"
|
2014-08-09 07:53:55 +08:00
|
|
|
#include "sched/sched.h"
|
2018-08-28 01:40:09 +08:00
|
|
|
#include "signal/signal.h"
|
2014-08-09 06:44:08 +08:00
|
|
|
#include "task/task.h"
|
2007-03-12 06:19:01 +08:00
|
|
|
|
2018-08-26 22:49:08 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-01-29 08:50:16 +08:00
|
|
|
/****************************************************************************
|
2007-03-12 06:19:01 +08:00
|
|
|
* Public Functions
|
2008-01-29 08:50:16 +08:00
|
|
|
****************************************************************************/
|
2007-03-12 06:19:01 +08:00
|
|
|
|
2008-01-29 08:50:16 +08: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-05 03:42:51 +08:00
|
|
|
* Name: nxtask_start
|
2007-03-12 06:19:01 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2012-07-15 03:30:31 +08: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-12 06:19:01 +08:00
|
|
|
*
|
2018-02-02 00:00:02 +08:00
|
|
|
* Input Parameters:
|
2007-03-12 06:19:01 +08:00
|
|
|
* None
|
|
|
|
*
|
2018-02-02 00:00:02 +08:00
|
|
|
* Returned Value:
|
2007-03-12 06:19:01 +08:00
|
|
|
* None
|
|
|
|
*
|
2008-01-29 08:50:16 +08:00
|
|
|
****************************************************************************/
|
2007-03-12 06:19:01 +08: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-05 03:42:51 +08:00
|
|
|
void nxtask_start(void)
|
2007-03-12 06:19:01 +08:00
|
|
|
{
|
2024-03-05 12:11:47 +08:00
|
|
|
FAR struct tcb_s *tcb = this_task();
|
2024-05-17 06:11:52 +08:00
|
|
|
uint8_t ttype = tcb->flags & TCB_FLAG_TTYPE_MASK;
|
2024-03-05 12:11:47 +08:00
|
|
|
#ifdef CONFIG_SCHED_STARTHOOK
|
|
|
|
FAR struct task_tcb_s *ttcb = (FAR struct task_tcb_s *)tcb;
|
|
|
|
#endif
|
2020-07-01 01:58:58 +08:00
|
|
|
int exitcode = EXIT_FAILURE;
|
2024-05-17 06:11:52 +08:00
|
|
|
FAR char **argv;
|
2007-03-12 06:19:01 +08:00
|
|
|
int argc;
|
|
|
|
|
2024-05-17 06:11:52 +08:00
|
|
|
DEBUGASSERT(ttype != TCB_FLAG_TTYPE_PTHREAD);
|
2013-02-05 05:24:00 +08:00
|
|
|
|
2018-08-28 01:40:09 +08:00
|
|
|
#ifdef CONFIG_SIG_DEFAULT
|
2024-05-17 06:11:52 +08:00
|
|
|
if (ttype != TCB_FLAG_TTYPE_KERNEL)
|
2022-01-25 12:23:37 +08:00
|
|
|
{
|
|
|
|
/* Set up default signal actions for NON-kernel thread */
|
2018-08-26 22:49:08 +08:00
|
|
|
|
2024-03-05 12:11:47 +08:00
|
|
|
nxsig_default_initialize(tcb);
|
2022-01-25 12:23:37 +08:00
|
|
|
}
|
2018-08-26 22:49:08 +08:00
|
|
|
#endif
|
|
|
|
|
2013-01-27 23:52:58 +08:00
|
|
|
/* Execute the start hook if one has been registered */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_STARTHOOK
|
2024-05-17 06:11:52 +08:00
|
|
|
if (ttype != TCB_FLAG_TTYPE_KERNEL && ttcb->starthook != NULL)
|
2013-01-27 23:52:58 +08:00
|
|
|
{
|
2024-03-05 12:11:47 +08:00
|
|
|
ttcb->starthook(ttcb->starthookarg);
|
2013-01-27 23:52:58 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-05-17 06:11:52 +08:00
|
|
|
/* Take args from stack, as group is shared for kthreads */
|
2007-03-12 06:19:01 +08:00
|
|
|
|
2024-05-17 06:11:52 +08:00
|
|
|
argv = nxsched_get_stackargs(tcb);
|
|
|
|
for (argc = 0; argv && argv[argc]; argc++);
|
2007-03-12 06:19:01 +08:00
|
|
|
|
2013-03-15 06:44:06 +08: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-06 03:13:48 +08:00
|
|
|
*/
|
2007-03-12 06:19:01 +08:00
|
|
|
|
2024-05-17 06:11:52 +08:00
|
|
|
if (ttype == TCB_FLAG_TTYPE_KERNEL)
|
2013-03-15 06:44:06 +08:00
|
|
|
{
|
2024-05-17 06:11:52 +08:00
|
|
|
exitcode = tcb->entry.main(argc, argv);
|
2013-03-15 06:44:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-30 18:09:22 +08:00
|
|
|
#ifdef CONFIG_BUILD_FLAT
|
2024-05-17 06:11:52 +08:00
|
|
|
nxtask_startup(tcb->entry.main, argc, argv);
|
2020-07-01 01:58:58 +08:00
|
|
|
#else
|
2024-05-17 06:11:52 +08:00
|
|
|
up_task_start(tcb->entry.main, argc, argv);
|
2020-07-01 01:58:58 +08:00
|
|
|
#endif
|
2020-09-30 18:09:22 +08:00
|
|
|
}
|
2013-03-15 06:44:06 +08:00
|
|
|
|
2023-02-16 22:57:24 +08:00
|
|
|
/* Call _exit() if/when the task returns */
|
2013-03-15 06:44:06 +08:00
|
|
|
|
2023-02-16 22:57:24 +08:00
|
|
|
_exit(exitcode);
|
2007-03-12 06:19:01 +08:00
|
|
|
}
|