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

Gedare Bloom gedare at rtems.org
Wed Mar 3 22:08:46 UTC 2021


On Wed, Mar 3, 2021 at 12:38 PM Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
>
> 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
> >      (n-1)*CPU_STACK_ALIGNMENT;
> > instead of
> >      n*CPU_STACK_ALIGNMENT-1;
> >
> > 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.
>

I think it is just invalid to shrink the stack size smaller than it is
requested.

If I call pthread_attr_setstacksize(), then "The stacksize attribute
shall define the minimum stack size (in bytes) allocated for the
created threads stack." I should not get back a stack size smaller
than I requested when I create the pthread. It's just wrong.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstacksize.html

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