forked from Imagelibrary/rtems
score: Add stack free handler to TCB
This avoids a dependency to the stack free function in the thread destruction. Update #3959.
This commit is contained in:
@@ -933,6 +933,7 @@ librtemscpu_a_SOURCES += score/src/schedulercbsreleasejob.c
|
|||||||
librtemscpu_a_SOURCES += score/src/schedulercbsunblock.c
|
librtemscpu_a_SOURCES += score/src/schedulercbsunblock.c
|
||||||
librtemscpu_a_SOURCES += score/src/stackallocator.c
|
librtemscpu_a_SOURCES += score/src/stackallocator.c
|
||||||
librtemscpu_a_SOURCES += score/src/stackallocatorfree.c
|
librtemscpu_a_SOURCES += score/src/stackallocatorfree.c
|
||||||
|
librtemscpu_a_SOURCES += score/src/stackallocatorfreenothing.c
|
||||||
librtemscpu_a_SOURCES += score/src/stackallocatorinit.c
|
librtemscpu_a_SOURCES += score/src/stackallocatorinit.c
|
||||||
librtemscpu_a_SOURCES += score/src/pheapallocate.c
|
librtemscpu_a_SOURCES += score/src/pheapallocate.c
|
||||||
librtemscpu_a_SOURCES += score/src/pheapextend.c
|
librtemscpu_a_SOURCES += score/src/pheapextend.c
|
||||||
|
|||||||
@@ -166,6 +166,13 @@ void *_Stack_Allocate( size_t stack_size );
|
|||||||
*/
|
*/
|
||||||
void _Stack_Free( void *stack_area );
|
void _Stack_Free( void *stack_area );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function does nothing.
|
||||||
|
*
|
||||||
|
* @param stack_area is not used.
|
||||||
|
*/
|
||||||
|
void _Stack_Free_nothing( void *stack_area );
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -194,10 +194,9 @@ typedef struct {
|
|||||||
/** This field is the initial priority. */
|
/** This field is the initial priority. */
|
||||||
Priority_Control initial_priority;
|
Priority_Control initial_priority;
|
||||||
/**
|
/**
|
||||||
* @brief This field is a pointer to the allocated stack area, otherwise it
|
* @brief This field points to the handler which should free the stack.
|
||||||
* is NULL.
|
|
||||||
*/
|
*/
|
||||||
void *allocated_stack;
|
void ( *stack_free )( void * );
|
||||||
/** This field is the stack information. */
|
/** This field is the stack information. */
|
||||||
Stack_Control Initial_stack;
|
Stack_Control Initial_stack;
|
||||||
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
|
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
|
||||||
|
|||||||
@@ -144,9 +144,11 @@ typedef struct {
|
|||||||
size_t stack_size;
|
size_t stack_size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The address of the allocated stack area or NULL.
|
* @brief This member contains the handler to free the stack.
|
||||||
|
*
|
||||||
|
* It shall not be NULL. Use _Stack_Free_nothing() if nothing is to free.
|
||||||
*/
|
*/
|
||||||
void *allocated_stack;
|
void ( *stack_free )( void * );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The new thread's priority.
|
* @brief The new thread's priority.
|
||||||
|
|||||||
@@ -218,8 +218,10 @@ int pthread_create(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( config.stack_area == NULL ) {
|
if ( config.stack_area == NULL ) {
|
||||||
|
config.stack_free = _Stack_Free;
|
||||||
config.stack_area = _Stack_Allocate( config.stack_size );
|
config.stack_area = _Stack_Allocate( config.stack_size );
|
||||||
config.allocated_stack = config.stack_area;
|
} else {
|
||||||
|
config.stack_free = _Stack_Free_nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = ( config.stack_area != NULL );
|
status = ( config.stack_area != NULL );
|
||||||
|
|||||||
@@ -146,8 +146,8 @@ rtems_status_code rtems_task_create(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
config.stack_free = _Stack_Free;
|
||||||
config.stack_area = _Stack_Allocate( config.stack_size );
|
config.stack_area = _Stack_Allocate( config.stack_size );
|
||||||
config.allocated_stack = config.stack_area;
|
|
||||||
status = ( config.stack_area != NULL );
|
status = ( config.stack_area != NULL );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
45
cpukit/score/src/stackallocatorfreenothing.c
Normal file
45
cpukit/score/src/stackallocatorfreenothing.c
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
*
|
||||||
|
* @ingroup RTEMSScoreStack
|
||||||
|
*
|
||||||
|
* @brief _Stack_Free_nothing() Implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <rtems/score/stackimpl.h>
|
||||||
|
|
||||||
|
void _Stack_Free_nothing( void *stack_area )
|
||||||
|
{
|
||||||
|
(void) stack_area;
|
||||||
|
}
|
||||||
@@ -36,8 +36,8 @@ bool _Thread_Initialize(
|
|||||||
uintptr_t tls_size;
|
uintptr_t tls_size;
|
||||||
bool extension_status;
|
bool extension_status;
|
||||||
size_t i;
|
size_t i;
|
||||||
char *stack_area;
|
char *stack_begin;
|
||||||
size_t stack_size;
|
char *stack_end;
|
||||||
Scheduler_Node *scheduler_node;
|
Scheduler_Node *scheduler_node;
|
||||||
#if defined(RTEMS_SMP)
|
#if defined(RTEMS_SMP)
|
||||||
Scheduler_Node *scheduler_node_for_index;
|
Scheduler_Node *scheduler_node_for_index;
|
||||||
@@ -61,7 +61,7 @@ bool _Thread_Initialize(
|
|||||||
|
|
||||||
/* Set everything to perform the error case clean up */
|
/* Set everything to perform the error case clean up */
|
||||||
scheduler_index = 0;
|
scheduler_index = 0;
|
||||||
the_thread->Start.allocated_stack = config->allocated_stack;
|
the_thread->Start.stack_free = config->stack_free;
|
||||||
|
|
||||||
#if defined(RTEMS_SMP)
|
#if defined(RTEMS_SMP)
|
||||||
if (
|
if (
|
||||||
@@ -83,16 +83,15 @@ bool _Thread_Initialize(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
stack_area = config->stack_area;
|
stack_begin = config->stack_area;
|
||||||
stack_size = config->stack_size;
|
stack_end = stack_begin + config->stack_size;
|
||||||
|
|
||||||
/* Allocate floating-point context in stack area */
|
/* Allocate floating-point context in stack area */
|
||||||
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
|
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
|
||||||
if ( config->is_fp ) {
|
if ( config->is_fp ) {
|
||||||
the_thread->fp_context = ( Context_Control_fp *) stack_area;
|
stack_end -= CONTEXT_FP_SIZE;
|
||||||
the_thread->Start.fp_context = ( Context_Control_fp *) stack_area;
|
the_thread->fp_context = (Context_Control_fp *) stack_end;
|
||||||
stack_size -= CONTEXT_FP_SIZE;
|
the_thread->Start.fp_context = (Context_Control_fp *) stack_end;
|
||||||
stack_area += CONTEXT_FP_SIZE;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -102,17 +101,16 @@ bool _Thread_Initialize(
|
|||||||
if ( tls_size > 0 ) {
|
if ( tls_size > 0 ) {
|
||||||
uintptr_t tls_align;
|
uintptr_t tls_align;
|
||||||
|
|
||||||
|
stack_end -= tls_size;
|
||||||
tls_align = (uintptr_t) _TLS_Alignment;
|
tls_align = (uintptr_t) _TLS_Alignment;
|
||||||
the_thread->Start.tls_area = (void *)
|
the_thread->Start.tls_area = (void *)
|
||||||
( ( (uintptr_t) stack_area + tls_align - 1 ) & ~( tls_align - 1 ) );
|
( ( (uintptr_t) stack_end + tls_align - 1 ) & ~( tls_align - 1 ) );
|
||||||
stack_size -= tls_size;
|
|
||||||
stack_area += tls_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_Stack_Initialize(
|
_Stack_Initialize(
|
||||||
&the_thread->Start.Initial_stack,
|
&the_thread->Start.Initial_stack,
|
||||||
stack_area,
|
stack_begin,
|
||||||
stack_size
|
stack_end - stack_begin
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -279,6 +277,6 @@ failed:
|
|||||||
&information->Thread_queue_heads.Free,
|
&information->Thread_queue_heads.Free,
|
||||||
the_thread->Wait.spare_heads
|
the_thread->Wait.spare_heads
|
||||||
);
|
);
|
||||||
_Stack_Free( the_thread->Start.allocated_stack );
|
( *the_thread->Start.stack_free )( the_thread->Start.Initial_stack.area );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ static void _Thread_Free( Thread_Control *the_thread )
|
|||||||
* Free the rest of the memory associated with this task
|
* Free the rest of the memory associated with this task
|
||||||
* and set the associated pointers to NULL for safety.
|
* and set the associated pointers to NULL for safety.
|
||||||
*/
|
*/
|
||||||
_Stack_Free( the_thread->Start.allocated_stack );
|
( *the_thread->Start.stack_free )( the_thread->Start.Initial_stack.area );
|
||||||
|
|
||||||
#if defined(RTEMS_SMP)
|
#if defined(RTEMS_SMP)
|
||||||
_ISR_lock_Destroy( &the_thread->Scheduler.Lock );
|
_ISR_lock_Destroy( &the_thread->Scheduler.Lock );
|
||||||
|
|||||||
Reference in New Issue
Block a user