[PATCH 4/4] score: Ensure stack alignment requirement

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Mar 3 19:38:25 UTC 2021

On 03/03/2021 19:31, Gedare Bloom wrote:

>> Is there no guarantee that stack_size == config->stack_size?
> Suppose an application requests a stack size with
> config->stack_area = m*CPU_STACK_ALIGNMENT
> config->stack_size = (n*CPU_STACK_ALIGNMENT - 1)
> Then, you will get
>     stack_begin = config->stack_area;
> because it is already aligned
>     stack_end = (n-1)*CPU_STACK_ALIGNMENT;
> for the align_down
> and the stack size you get in the end is
> instead of
> so you lose CPU_STACK_ALIGNMENT-1 bytes from the stack, and the user
> doesn't get back the requested number of bytes, but they also don't
> get any kind of error or status. They just lose some bytes.
> I think this is wrong.

If you provide a stack, then it is up to you to provide properly aligned 
areas or you loose a couple of bytes. We check that a minimum size is 
met.We provide also an interface to properly align things 
(RTEMS_TASK_STORAGE_ALIGNMENT). I would also not fill up the stack to 
the last byte, so there will be a bit of waste anyway.

We could add alignment checks to _RTEMS_tasks_Prepare_user_stack(), but I am not sure if there is a real need for this. For some applications it might be better to just waste some bytes and not align everything to avoid padding through the linker.

embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
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:

More information about the devel mailing list