diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index 967c6194bbc..8b685a456c8 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -316,28 +316,9 @@ uintptr_t task_tls_get_value(int tlsindex); #elif defined(CONFIG_TLS_ALIGNED) && !defined(__KERNEL__) # define tls_get_info() TLS_INFO(up_getsp()) #else -# define tls_get_info() tls_get_info_pid(0) +FAR struct tls_info_s *tls_get_info(void); #endif -/**************************************************************************** - * Name: tls_get_info_pid - * - * Description: - * Return a reference to the tls_info_s structure. This is used as part - * of the internal implementation of tls_get/set_elem() and ONLY for the - * where CONFIG_TLS_ALIGNED is *not* defined or __KERNEL__ is defined. - * - * Input Parameters: - * pid - Thread ID to query, set to 0 to query own - * - * Returned Value: - * A reference to the thread-specific tls_info_s structure is return on - * success. NULL would be returned in the event of any failure. - * - ****************************************************************************/ - -FAR struct tls_info_s *tls_get_info_pid(pid_t pid); - /**************************************************************************** * Name: tls_destruct * diff --git a/libs/libc/tls/tls_getinfo.c b/libs/libc/tls/tls_getinfo.c index f613ea85a4c..25ed601280c 100644 --- a/libs/libc/tls/tls_getinfo.c +++ b/libs/libc/tls/tls_getinfo.c @@ -36,7 +36,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: tls_get_info_pid + * Name: tls_get_info * * Description: * Return a reference to the tls_info_s structure. This is used as part @@ -44,7 +44,7 @@ * where CONFIG_TLS_ALIGNED is *not* defined or __KERNEL__ is defined. * * Input Parameters: - * pid - Thread ID to query, set to 0 to query own + * None. * * Returned Value: * A reference to the thread-specific tls_info_s structure is return on @@ -52,13 +52,13 @@ * ****************************************************************************/ -FAR struct tls_info_s *tls_get_info_pid(pid_t pid) +FAR struct tls_info_s *tls_get_info(void) { FAR struct tls_info_s *info = NULL; struct stackinfo_s stackinfo; int ret; - ret = nxsched_get_stackinfo(pid, &stackinfo); + ret = nxsched_get_stackinfo(0, &stackinfo); if (ret >= 0) { /* The TLS data lies at the lowest address of the stack allocation. diff --git a/sched/sched/CMakeLists.txt b/sched/sched/CMakeLists.txt index f7616d9ece0..29ac1b63460 100644 --- a/sched/sched/CMakeLists.txt +++ b/sched/sched/CMakeLists.txt @@ -43,6 +43,7 @@ set(SRCS sched_idletask.c sched_self.c sched_get_stackinfo.c + sched_get_tls.c sched_sysinfo.c sched_reprioritizertr.c sched_get_stateinfo.c) diff --git a/sched/sched/Make.defs b/sched/sched/Make.defs index ddcb6c75801..422f0107380 100644 --- a/sched/sched/Make.defs +++ b/sched/sched/Make.defs @@ -27,7 +27,7 @@ CSRCS += sched_setparam.c sched_setpriority.c sched_getparam.c CSRCS += sched_setscheduler.c sched_getscheduler.c CSRCS += sched_yield.c sched_rrgetinterval.c sched_foreach.c CSRCS += sched_lock.c sched_unlock.c sched_lockcount.c -CSRCS += sched_idletask.c sched_self.c sched_get_stackinfo.c +CSRCS += sched_idletask.c sched_self.c sched_get_stackinfo.c sched_get_tls.c CSRCS += sched_sysinfo.c sched_reprioritizertr.c sched_get_stateinfo.c ifeq ($(CONFIG_PRIORITY_INHERITANCE),y) diff --git a/sched/sched/sched.h b/sched/sched/sched.h index 79a5736b9b3..104d19ed8e2 100644 --- a/sched/sched/sched.h +++ b/sched/sched/sched.h @@ -417,4 +417,9 @@ void nxsched_suspend_critmon(FAR struct tcb_s *tcb); bool nxsched_verify_tcb(FAR struct tcb_s *tcb); +/* Obtain TLS from kernel */ + +struct tls_info_s; /* Forward declare */ +FAR struct tls_info_s *nxsched_get_tls(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 new file mode 100644 index 00000000000..ed8352ed89b --- /dev/null +++ b/sched/sched/sched_get_tls.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * sched/sched/sched_get_tls.c + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "nuttx/sched.h" +#include "sched/sched.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxsched_get_tls + * + * Description: + * Get TLS of any task / tcb with no security checks. + * + * Input Parameters: + * tcb - The tcb to query. + * + * Returned Value: + * Pointer to the TLS structure. + * + ****************************************************************************/ + +FAR struct tls_info_s *nxsched_get_tls(FAR struct tcb_s *tcb) +{ + /* The TLS data lies at the lowest address of the stack allocation. + * This is true for both push-up and push-down stacks. + */ + + return (FAR struct tls_info_s *)tcb->stack_alloc_ptr; +} diff --git a/sched/task/task_cancelpt.c b/sched/task/task_cancelpt.c index 4001152d181..834644fada4 100644 --- a/sched/task/task_cancelpt.c +++ b/sched/task/task_cancelpt.c @@ -88,7 +88,7 @@ bool nxnotify_cancellation(FAR struct tcb_s *tcb) { - FAR struct tls_info_s *tls = tls_get_info_pid(tcb->pid); + FAR struct tls_info_s *tls = nxsched_get_tls(tcb); irqstate_t flags; bool ret = false;