[PATCH v2] score: Ensure stack alignment requirement

Kinsey Moore kinsey.moore at oarcorp.com
Thu Mar 4 15:20:28 UTC 2021


Looks good other than a minor tweak.

Kinsey

-----Original Message-----
From: devel <devel-bounces at rtems.org> On Behalf Of Sebastian Huber
Sent: Thursday, March 4, 2021 03:17
To: devel at rtems.org
Subject: [PATCH v2] score: Ensure stack alignment requirement

> Make sure that a user-provided stack size is the minimum size allocated
> for the stack.
>
> Make sure we meet the stack alignment requirement also for CPU ports
> with CPU_STACK_ALIGNMENT > CPU_HEAP_ALIGNMENT.
> ---
> diff --git a/cpukit/include/rtems/score/stackimpl.h b/cpukit/include/rtems/score/stackimpl.h
> index 43b7c8151e..c15206002c 100644
> --- a/cpukit/include/rtems/score/stackimpl.h
> +++ b/cpukit/include/rtems/score/stackimpl.h
> @@ -135,6 +135,7 @@ RTEMS_INLINE_ROUTINE size_t _Stack_Extend_size(
>  )
>  {
>    size_t extra_size;
> +  size_t alignment_overhead;
>
>    extra_size = _TLS_Get_allocation_size();
>
> @@ -147,15 +148,32 @@ RTEMS_INLINE_ROUTINE size_t _Stack_Extend_size(
>    (void) is_fp;
>  #endif
>
> -  stack_size += extra_size;
> +  /*
> +   * In order to make sure that a user-provided stack size is the minimum which
> +   * can be allocated for the stack, we have to align it up to the next stack
> +   * boundary.
> +   */
> +  alignment_overhead = CPU_STACK_ALIGNMENT - 1;

This should be CPU_HEAP_ALIGNMENT given the #if below.

> +
> +#if CPU_STACK_ALIGNMENT > CPU_HEAP_ALIGNMENT
> +  /*
> +   * If the heap allocator does not meet the stack alignment requirement, then
> +   * we have to do the stack alignment manually in _Thread_Initialize() and
> +   * need to allocate extra space for this.
> +   */
> +  alignment_overhead += CPU_STACK_ALIGNMENT - CPU_HEAP_ALIGNMENT;
> +#endif


More information about the devel mailing list