[PATCH v1 1/2] score: Enforce stack_end alignment
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Feb 19 07:07:43 UTC 2021
On 19/02/2021 07:12, Sebastian Huber wrote:
> On 18/02/2021 19:59, Kinsey Moore wrote:
>
>> The size of the reserved TLS space is not guaranteed to adhere to stack
>> alignment requirements which can cause stack_end to become misaligned.
>> This enforces the alignment of stack_end.
>> ---
>> cpukit/score/src/threadinitialize.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/cpukit/score/src/threadinitialize.c
>> b/cpukit/score/src/threadinitialize.c
>> index 05c30c3d43..ad5dccbbb2 100644
>> --- a/cpukit/score/src/threadinitialize.c
>> +++ b/cpukit/score/src/threadinitialize.c
>> @@ -108,6 +108,10 @@ bool _Thread_Initialize(
>> ( ( (uintptr_t) stack_end + tls_align - 1 ) & ~( tls_align -
>> 1 ) );
>> }
>> + /* Enforce stack alignment */
>> + stack_end = (char *)((uintptr_t) stack_end &
>> + ~( (uintptr_t) CPU_STACK_ALIGNMENT - 1 ));
>> +
>> _Stack_Initialize(
>> &the_thread->Start.Initial_stack,
>> stack_begin,
> I think the bug is in _TLS_Get_allocation_size(). It assumes
> CPU_HEAP_ALIGNMENT >= CPU_STACK_ALIGNMENT. It should probably use the
> maximum of these two values.
There is also an issue in the stack allocation, for example
static rtems_status_code _RTEMS_tasks_Allocate_and_prepare_stack(
Thread_Configuration *thread_config,
const rtems_task_config *config
)
{
size_t size;
thread_config->stack_free = _Stack_Free;
size = _Stack_Ensure_minimum( config->storage_size );
size = _Stack_Extend_size( size, thread_config->is_fp );
thread_config->stack_size = size;
thread_config->stack_area = _Stack_Allocate( size );
if ( thread_config->stack_area == NULL ) {
return RTEMS_UNSATISFIED;
}
return RTEMS_SUCCESSFUL;
}
and
/* Generated from spec:/rtems/task/if/storage-alignment */
/**
* @ingroup RTEMSAPIClassicTasks
*
* @brief This constant defines the recommended alignment of a task storage
* area in bytes.
*
* @par Notes
* Use it with RTEMS_ALIGNED() to define the alignment of a statically
* allocated task storage area.
*/
#define RTEMS_TASK_STORAGE_ALIGNMENT CPU_HEAP_ALIGNMENT
--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber at embedded-brains.de
phone: +49-89-18 94 741 - 16
fax: +49-89-18 94 741 - 08
Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
More information about the devel
mailing list