Skip to content

Commit

Permalink
sched/tls: drop ta_argv and g_idleargv
Browse files Browse the repository at this point in the history
- replaces `ta_argv` with `stackargs`
- drops `ta_argv` from `task_info_s`
- drops `g_idleargv` and checks idle accordingly

Signed-off-by: Yanfeng Liu <[email protected]>
  • Loading branch information
yf13 committed Jun 7, 2024
1 parent d7bb28c commit 80dc819
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 44 deletions.
2 changes: 0 additions & 2 deletions include/nuttx/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ struct pthread_atfork_s
struct task_info_s
{
mutex_t ta_lock;
int ta_argc; /* Number of arguments */
FAR char **ta_argv; /* Name+start-up parameters */
#if CONFIG_TLS_TASK_NELEM > 0
uintptr_t ta_telem[CONFIG_TLS_TASK_NELEM]; /* Task local storage elements */
#endif
Expand Down
14 changes: 10 additions & 4 deletions libs/libc/stdlib/lib_getprogname.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,26 @@
#include <nuttx/config.h>

#include <stdlib.h>
#include <nuttx/tls.h>
#include <nuttx/sched.h>

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: getprogname
*
* Note that previous impl returns address in the stack of main thread when
* used from a pthread, that is dangerous as main thread may end earlier.
****************************************************************************/

FAR const char *getprogname(void)
{
FAR struct task_info_s *info;
struct stackinfo_s si;
FAR struct tls_info_s *ti = tls_get_info();
uintptr_t ret = ti ? (uintptr_t)ti + ti->tl_size : 0;
int rc = nxsched_get_stackinfo(0, &si);

info = task_get_info();
return info->ta_argv[0];
return (rc >= 0 && ret && ((uintptr_t)si.stack_base_ptr) > ret) ?
((FAR char **)ret)[0] : NULL;
}
9 changes: 4 additions & 5 deletions sched/group/group_argvstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ size_t group_argvstr(FAR struct tcb_s *tcb, FAR char *args, size_t size)
FAR struct addrenv_s *oldenv;
#endif

/* Perform sanity checks */
/* Sanity checks and idle tasks */

if (!tcb || !tcb->group || !tcb->group->tg_info)
if (!tcb || !tcb->group || !tcb->group->tg_info || size < 1 ||
is_idle_task(tcb))
{
/* Something is very wrong -> get out */

*args = '\0';
return 0;
}
Expand All @@ -90,7 +89,7 @@ size_t group_argvstr(FAR struct tcb_s *tcb, FAR char *args, size_t size)
else
#endif
{
FAR char **argv = tcb->group->tg_info->ta_argv + 1;
FAR char **argv = nxsched_get_stackargs(tcb) + 1;

while (*argv != NULL && n < size)
{
Expand Down
25 changes: 1 addition & 24 deletions sched/init/nx_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,10 @@ static struct tcb_s g_idletcb[CONFIG_SMP_NCPUS];

/* This is the name of the idle task */

#if CONFIG_TASK_NAME_SIZE <= 0 || !defined(CONFIG_SMP)
# ifdef CONFIG_SMP
static const char g_idlename[] = "CPU_Idle";
# else
#if CONFIG_TASK_NAME_SIZE > 0 && !defined(CONFIG_SMP)
static const char g_idlename[] = "Idle_Task";
# endif
#endif

/* This is IDLE threads argument list. NOTE: Normally the argument
* list is created on the stack prior to starting the task. We have to
* do things little differently here for the IDLE tasks.
*/

static FAR char *g_idleargv[CONFIG_SMP_NCPUS][2];

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -419,17 +408,6 @@ static void idle_task_initialize(void)
strlcpy(tcb->name, g_idlename, CONFIG_TASK_NAME_SIZE);
# endif

/* Configure the task name in the argument list. The IDLE task does
* not really have an argument list, but this name is still useful
* for things like the NSH PS command.
*
* In the kernel mode build, the arguments are saved on the task's
* stack and there is no support that yet.
*/

g_idleargv[i][0] = tcb->name;
#else
g_idleargv[i][0] = (FAR char *)g_idlename;
#endif /* CONFIG_TASK_NAME_SIZE */

/* Then add the idle task's TCB to the head of the current ready to
Expand Down Expand Up @@ -476,7 +454,6 @@ static void idle_group_initialize(void)

DEBUGVERIFY(
group_initialize((FAR struct task_tcb_s *)tcb, tcb->flags));
tcb->group->tg_info->ta_argv = &g_idleargv[i][0];

/* Initialize the task join */

Expand Down
5 changes: 3 additions & 2 deletions sched/task/task_fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
FAR struct tcb_s *ptcb = this_task();
FAR struct tcb_s *parent;
FAR struct task_tcb_s *child;
FAR char **argv;
size_t stack_size;
uint8_t ttype;
int priority;
Expand Down Expand Up @@ -211,8 +212,8 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)

/* Setup to pass parameters to the new task */

ret = nxtask_setup_arguments(child, parent->group->tg_info->ta_argv[0],
&parent->group->tg_info->ta_argv[1]);
argv = nxsched_get_stackargs(parent);
ret = nxtask_setup_arguments(child, argv[0], &argv[1]);
if (ret < OK)
{
goto errout_with_tcb;
Expand Down
7 changes: 0 additions & 7 deletions sched/task/task_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ static int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,
FAR const char *name,
FAR char * const argv[])
{
const uint8_t ttype = tcb->cmn.flags & TCB_FLAG_TTYPE_MASK;
FAR char **stackargv;
FAR char *str;
size_t strtablen;
Expand Down Expand Up @@ -632,12 +631,6 @@ static int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,

stackargv[argc + 1] = NULL;

if (ttype != TCB_FLAG_TTYPE_KERNEL)
{
tcb->cmn.group->tg_info->ta_argc = argc;
tcb->cmn.group->tg_info->ta_argv = stackargv;
}

return OK;
}

Expand Down

0 comments on commit 80dc819

Please sign in to comment.