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
|
|
|
*
|
2024-09-11 13:45:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
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>
|
2022-05-27 04:05:43 +02:00
|
|
|
#include <nuttx/tls.h>
|
2013-03-14 23:44:06 +01:00
|
|
|
|
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
|
|
|
|
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
|
|
|
{
|
2024-03-05 05:11:47 +01:00
|
|
|
FAR struct tcb_s *tcb = this_task();
|
2024-05-17 00:11:52 +02:00
|
|
|
uint8_t ttype = tcb->flags & TCB_FLAG_TTYPE_MASK;
|
2024-03-05 05:11:47 +01:00
|
|
|
#ifdef CONFIG_SCHED_STARTHOOK
|
|
|
|
FAR struct task_tcb_s *ttcb = (FAR struct task_tcb_s *)tcb;
|
|
|
|
#endif
|
2020-06-30 19:58:58 +02:00
|
|
|
int exitcode = EXIT_FAILURE;
|
2024-05-17 00:11:52 +02:00
|
|
|
FAR char **argv;
|
2007-03-11 23:19:01 +01:00
|
|
|
int argc;
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
DEBUGASSERT(ttype != TCB_FLAG_TTYPE_PTHREAD);
|
2013-02-04 22:24:00 +01:00
|
|
|
|
2018-08-27 19:40:09 +02:00
|
|
|
#ifdef CONFIG_SIG_DEFAULT
|
2024-05-17 00:11:52 +02:00
|
|
|
if (ttype != TCB_FLAG_TTYPE_KERNEL)
|
2022-01-25 05:23:37 +01:00
|
|
|
{
|
|
|
|
/* Set up default signal actions for NON-kernel thread */
|
2018-08-26 16:49:08 +02:00
|
|
|
|
2024-03-05 05:11:47 +01:00
|
|
|
nxsig_default_initialize(tcb);
|
2022-01-25 05:23:37 +01:00
|
|
|
}
|
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
|
2024-05-17 00:11:52 +02:00
|
|
|
if (ttype != TCB_FLAG_TTYPE_KERNEL && ttcb->starthook != NULL)
|
2013-01-27 16:52:58 +01:00
|
|
|
{
|
2024-03-05 05:11:47 +01:00
|
|
|
ttcb->starthook(ttcb->starthookarg);
|
2013-01-27 16:52:58 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
/* Take args from stack, as group is shared for kthreads */
|
2007-03-11 23:19:01 +01:00
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
argv = nxsched_get_stackargs(tcb);
|
|
|
|
for (argc = 0; argv && argv[argc]; argc++);
|
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
|
|
|
|
2024-05-17 00:11:52 +02:00
|
|
|
if (ttype == TCB_FLAG_TTYPE_KERNEL)
|
2013-03-14 23:44:06 +01:00
|
|
|
{
|
2024-05-17 00:11:52 +02:00
|
|
|
exitcode = tcb->entry.main(argc, argv);
|
2013-03-14 23:44:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-30 12:09:22 +02:00
|
|
|
#ifdef CONFIG_BUILD_FLAT
|
2024-05-17 00:11:52 +02:00
|
|
|
nxtask_startup(tcb->entry.main, argc, argv);
|
2020-06-30 19:58:58 +02:00
|
|
|
#else
|
2024-05-17 00:11:52 +02:00
|
|
|
up_task_start(tcb->entry.main, argc, 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
|
|
|
|
2023-02-16 15:57:24 +01:00
|
|
|
/* Call _exit() if/when the task returns */
|
2013-03-14 23:44:06 +01:00
|
|
|
|
2023-02-16 15:57:24 +01:00
|
|
|
_exit(exitcode);
|
2007-03-11 23:19:01 +01:00
|
|
|
}
|