[PATCH] fixup! common: introduce bthreads, co-operative barebox threads

Sascha Hauer sha at pengutronix.de
Mon Mar 22 04:54:18 GMT 2021


On Sun, Mar 21, 2021 at 04:00:50PM +0100, Ahmad Fatoum wrote:
> Specifying __aligned for a struct member only ensures a relative
> alignment to the start of the struct. To get an absolute alignment,
> we must ensure the struct itself is aligned suitably as well. Do so.
> 
> This fixes an issue where printf("%llu" printed bogus values when
> run from a bthread, because gcc va_arg on RISC-V requires 16-bit
> stack alignment.
> 
> Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
> ---
>  common/bthread.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/bthread.c b/common/bthread.c
> index 80b486c99af7..ece02e091da9 100644
> --- a/common/bthread.c
> +++ b/common/bthread.c
> @@ -88,7 +88,7 @@ struct bthread *bthread_create(int (*threadfn)(void *), void *data,
>  	va_list ap;
>  	int len;
>  
> -	bthread = malloc(struct_size(bthread, stack_space, CONFIG_STACK_SIZE));
> +	bthread = memalign(16, struct_size(bthread, stack_space, CONFIG_STACK_SIZE));

Wouldn't it be clearer to make the stack an extra allocation instead of
attaching it to struct bthread?

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list