[PATCH v1 1/2] score: Enforce stack_end alignment

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Feb 19 06:12:47 UTC 2021


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.

-- 
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