On Mon, Sep 01, 2025 at 05:44:38PM +0200, "Gustavo A. R. Silva" 
<[email protected]> wrote:
> Oh, a correction about this. Actually, if we need to use __packed, we would
> have to pass it as an argument to TRAILING_OVERLAP(), like this:
> 
> -#define TRAILING_OVERLAP(TYPE, NAME, FAM, MEMBERS)                           
>   \
> +#define TRAILING_OVERLAP(TYPE, NAME, FAM, MEMBERS, ATTRS)                    
>           \
>         union {                                                               
>   \
>                 TYPE NAME;                                                    
>   \
>                 struct {                                                      
>   \
>                         unsigned char __offset_to_##FAM[offsetof(TYPE, FAM)]; 
>   \
>                         MEMBERS                                               
>   \
> -               };                                                            
>   \
> +               } ATTRS;                                                      
>           \
>         }
> 
> However, in this case MEMBERS is only cgrp_ancestor_storage, and it's 
> correctly
> aligned to __offset_to_##FAM[offsetof(TYPE, FAM)]; inside the helper. So, we
> don't really need to pack that internal struct.

My intention with the attribute was to prevent a gap (padding) occurring
between 
        unsigned char __offset_to_##FAM
and
        MEMBERS                                                 
which would make the address of the first member to mismatch the address
of FAM (the example in struct cgroup_root notwithstanding).

(But perhaps it's guaranteed that first member's offset in the struct is
always equal to offsetof(TYPE, FAM).)

Michal

Attachment: signature.asc
Description: PGP signature

Reply via email to