mirror of
https://github.com/apache/nuttx.git
synced 2026-08-12 07:55:32 +00:00
SIM: Add TLS support to to the simulator
This commit is contained in:
parent
4d484399a9
commit
a74c19bbae
4 changed files with 146 additions and 7 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/sim/src/up_createstack.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2013, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -41,8 +41,10 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/tls.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
|
@ -88,6 +90,22 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
|
|||
uint32_t *stack_alloc_ptr;
|
||||
int ret = ERROR;
|
||||
|
||||
#ifdef CONFIG_TLS
|
||||
/* Add the size of the TLS information structure */
|
||||
|
||||
stack_size += sizeof(struct tls_info_s);
|
||||
|
||||
/* The allocated stack size must not exceed the maximum possible for the
|
||||
* TLS feature.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(stack_size <= TLS_MAXSTACK);
|
||||
if (stack_size >= TLS_MAXSTACK)
|
||||
{
|
||||
stack_size = TLS_MAXSTACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Move up to next even word boundary if necessary */
|
||||
|
||||
size_t adj_stack_size = (stack_size + 3) & ~3;
|
||||
|
|
@ -95,7 +113,11 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
|
|||
|
||||
/* Allocate the memory for the stack */
|
||||
|
||||
#ifdef CONFIG_TLS
|
||||
stack_alloc_ptr = (FAR uint32_t *)kumm_memalign(TLS_STACK_ALIGN, adj_stack_size);
|
||||
#else /* CONFIG_TLS */
|
||||
stack_alloc_ptr = (FAR uint32_t *)kumm_malloc(adj_stack_size);
|
||||
#endif /* CONFIG_TLS */
|
||||
|
||||
/* Was the allocation successful? */
|
||||
|
||||
|
|
@ -103,13 +125,20 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
|
|||
{
|
||||
/* This is the address of the last word in the allocation */
|
||||
|
||||
void *adj_stack_ptr = &stack_alloc_ptr[adj_stack_words - 1];
|
||||
FAR void *adj_stack_ptr = &stack_alloc_ptr[adj_stack_words - 1];
|
||||
|
||||
/* Save the values in the TCB */
|
||||
|
||||
tcb->adj_stack_size = adj_stack_size;
|
||||
tcb->stack_alloc_ptr = stack_alloc_ptr;
|
||||
tcb->adj_stack_ptr = adj_stack_ptr;
|
||||
|
||||
#ifdef CONFIG_TLS
|
||||
/* Initialize the TLS data structure */
|
||||
|
||||
memset(stack_alloc_ptr, 0, sizeof(struct tls_info_s));
|
||||
#endif
|
||||
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/sim/src/up_usestack.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -38,9 +38,14 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/tls.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -75,21 +80,37 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
|
||||
int up_use_stack(FAR struct tcb_s *tcb, FAR void *stack, size_t stack_size)
|
||||
{
|
||||
FAR size_t *adj_stack_ptr;
|
||||
size_t adj_stack_size;
|
||||
size_t adj_stack_words;
|
||||
|
||||
#ifdef CONFIG_TLS
|
||||
/* Make certain that the user provided stack is properly aligned */
|
||||
|
||||
DEBUGASSERT(((uintptr_t)stack & TLS_STACK_MASK) == 0);
|
||||
#endif
|
||||
/* Move up to next even word boundary if necessary */
|
||||
|
||||
size_t adj_stack_size = stack_size & ~3;
|
||||
size_t adj_stack_words = adj_stack_size >> 2;
|
||||
adj_stack_size = stack_size & ~3;
|
||||
adj_stack_words = adj_stack_size >> 2;
|
||||
|
||||
/* This is the address of the last word in the allocation */
|
||||
|
||||
FAR size_t *adj_stack_ptr = &((FAR size_t *)stack)[adj_stack_words - 1];
|
||||
adj_stack_ptr = &((FAR size_t *)stack)[adj_stack_words - 1];
|
||||
|
||||
/* Save the values in the TCB */
|
||||
|
||||
tcb->adj_stack_size = adj_stack_size;
|
||||
tcb->stack_alloc_ptr = stack;
|
||||
tcb->adj_stack_ptr = adj_stack_ptr;
|
||||
|
||||
#ifdef CONFIG_TLS
|
||||
/* Initialize the TLS data structure */
|
||||
|
||||
memset(stack, 0, sizeof(struct tls_info_s));
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue