diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index 0d66a6055c..0b49476965 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -219,6 +219,7 @@ struct tls_info_s int16_t tl_cpcount; /* Nested cancellation point count */ #endif + uint16_t tl_size; /* Actual size with alignments */ int tl_errno; /* Per-thread error number */ }; diff --git a/sched/sched/sched.h b/sched/sched/sched.h index b5f39f1fae..bdf3a60097 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -393,5 +393,6 @@ bool nxsched_verify_tcb(FAR struct tcb_s *tcb); struct tls_info_s; /* Forward declare */ FAR struct tls_info_s *nxsched_get_tls(FAR struct tcb_s *tcb); +FAR char **nxsched_get_stackargs(FAR struct tcb_s *tcb); #endif /* __SCHED_SCHED_SCHED_H */ diff --git a/sched/sched/sched_get_tls.c b/sched/sched/sched_get_tls.c index ed8352ed89..63517429ed 100644 --- a/sched/sched/sched_get_tls.c +++ b/sched/sched/sched_get_tls.c @@ -53,3 +53,25 @@ FAR struct tls_info_s *nxsched_get_tls(FAR struct tcb_s *tcb) return (FAR struct tls_info_s *)tcb->stack_alloc_ptr; } + +/**************************************************************************** + * Name: nxsched_get_stackargs + * + * Description: + * Get args from thread's stack w/o security checks. The args are setup in + * nxtask_setup_stackargs(). + * + * Input Parameters: + * tcb - The tcb to query. + * + * Returned Value: + * Pointer to a list of stack arguments ended by a NULL pointer. + * + ****************************************************************************/ + +FAR char **nxsched_get_stackargs(FAR struct tcb_s *tcb) +{ + /* The args data follows the TLS data */ + + return (FAR char**)(tcb->stack_alloc_ptr + nxsched_get_tls(tcb)->tl_size); +} diff --git a/sched/tls/tls_initinfo.c b/sched/tls/tls_initinfo.c index ad4bf3719b..67792004e4 100644 --- a/sched/tls/tls_initinfo.c +++ b/sched/tls/tls_initinfo.c @@ -63,6 +63,10 @@ int tls_init_info(FAR struct tcb_s *tcb) up_tls_initialize(info); + /* Derive tl_size w/o arch knowledge */ + + info->tl_size = tcb->stack_base_ptr - tcb->stack_alloc_ptr; + /* Attach per-task info in group to TLS */ info->tl_task = tcb->group->tg_info;