TLS: Move up_tls_info() to an inline function. Simplify TLS implementation.
This commit is contained in:
parent
78e4ca2bc7
commit
1909dc8239
@ -219,11 +219,8 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
|
||||
|
||||
if (tcb->stack_alloc_ptr)
|
||||
{
|
||||
#ifdef CONFIG_TLS
|
||||
FAR struct tls_info_s *info;
|
||||
#ifdef CONFIG_STACK_COLORATION
|
||||
#if defined(CONFIG_TLS) && defined(CONFIG_STACK_COLORATION)
|
||||
uinptr_t stack_base;
|
||||
#endif
|
||||
#endif
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
@ -259,9 +256,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
|
||||
#ifdef CONFIG_TLS
|
||||
/* Initialize the TLS data structure */
|
||||
|
||||
info = (FAR struct tls_info_s *)tcb->stack_alloc_ptr;
|
||||
memset(info, 0, sizeof(struct tls_info_s));
|
||||
info->tl_tcb = tcb;
|
||||
memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
|
||||
|
||||
#ifdef CONFIG_STACK_COLORATION
|
||||
/* If stack debug is enabled, then fill the stack with a
|
||||
@ -269,7 +264,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
|
||||
* water marks.
|
||||
*/
|
||||
|
||||
stackbase = (uintptr_t)info + sizeof(struct tls_info_s);
|
||||
stackbase = (uintptr_t)tcb->stack_alloc_ptr + sizeof(struct tls_info_s);
|
||||
stack_size = tcb->adj_stack_size - sizeof(struct tls_info_s);
|
||||
up_stack_color((FAR void *)stack_base, stack_size);
|
||||
|
||||
|
@ -1,109 +0,0 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/common/up_tlsinfo.c
|
||||
*
|
||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/tls.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#ifdef CONFIG_TLS
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_getsp
|
||||
****************************************************************************/
|
||||
|
||||
/* I don't know if the builtin to get SP is enabled */
|
||||
|
||||
static inline uint32_t up_getsp(void)
|
||||
{
|
||||
uint32_t sp;
|
||||
__asm__
|
||||
(
|
||||
"\tmov %0, sp\n\t"
|
||||
: "=r"(sp)
|
||||
);
|
||||
|
||||
return sp;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_tls_info
|
||||
*
|
||||
* Description:
|
||||
* Return the TLS information structure for the currently executing thread.
|
||||
* When TLS is enabled, up_createstack() will align allocated stacks to
|
||||
* the TLS_STACK_ALIGN value. An instance of the following structure will
|
||||
* be implicitly positioned at the "lower" end of the stack. Assuming a
|
||||
* "push down" stack, this is at the "far" end of the stack (and can be
|
||||
* clobbered if the stack overflows).
|
||||
*
|
||||
* If an MCU has a "push up" then that TLS structure will lie at the top
|
||||
* of the stack and stack allocation and initialization logic must take
|
||||
* care to preserve this structure content.
|
||||
*
|
||||
* The stack memory is fully accessible to user mode threads but will
|
||||
* contain references to OS internal, private data structures (such as the
|
||||
* TCB)
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* A pointer to TLS info structure at the beginning of the STACK memory
|
||||
* allocation. This is essentially an application of the TLS_INFO(sp)
|
||||
* macro and has a platform dependency only in the manner in which the
|
||||
* stack pointer (sp) is obtained and interpreted.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct tls_info_s *up_tls_info(void)
|
||||
{
|
||||
uintptr_s sp = (uintptr_t)up_getsp();
|
||||
return TLS_INFO(sp);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_TLS */
|
@ -113,9 +113,6 @@
|
||||
|
||||
int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
||||
{
|
||||
#ifdef CONFIG_TLS
|
||||
FAR struct tls_info_s *info;
|
||||
#endif
|
||||
size_t top_of_stack;
|
||||
size_t size_of_stack;
|
||||
|
||||
@ -169,9 +166,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
||||
#ifdef CONFIG_TLS
|
||||
/* Initialize the TLS data structure */
|
||||
|
||||
info = (FAR struct tls_info_s *)tcb->stack_alloc_ptr;
|
||||
memset(info, 0, sizeof(struct tls_info_s));
|
||||
info->tl_tcb = tcb;
|
||||
memset(tcb->stack_alloc_ptr, 0, sizeof(struct tls_info_s));
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STACK_COLORATION
|
||||
|
Loading…
Reference in New Issue
Block a user