[systemd-devel] [PATCH] libsystemd-bus: make sure buf transfered into kenrel is 8 aligned

Kay Sievers kay at vrfy.org
Mon Dec 16 07:09:45 PST 2013


On Mon, Dec 16, 2013 at 4:01 PM, Lennart Poettering
<lennart at poettering.net> wrote:
> On Mon, 16.12.13 15:50, Lennart Poettering (lennart at poettering.net) wrote:
>
>> > diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
>> > index 0072c37..6b2790d 100644
>> > --- a/src/libsystemd-bus/bus-control.c
>> > +++ b/src/libsystemd-bus/bus-control.c
>> > @@ -207,7 +207,7 @@ _public_ int sd_bus_release_name(sd_bus *bus, const char *name) {
>> >  }
>> >
>> >  static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
>> > -        struct kdbus_cmd_name_list cmd = {};
>> > +        struct kdbus_cmd_name_list __attribute__ ((__aligned__(8)))
>> > cmd = {};
>>
>> Hmm, this feels a bit like this would be better part of the type rather
>> than the variable. THus, kdbus.h should add this to all is structs,
>> rather then we decorate the variables...
>>
>> Kay, would this make sense to you to add to kdbus.h?
>
> Hmm, so thinking about this: the kdbus_cmd_name_list structure contains
> 64bit values anyway, so should naturally be aligned to 64bit boundaries
> anyway... Or am I mistaken there and you are suggesting that on your
> 32bit architecture (which one is it if I may ask?) 64bit values don't
> have to be aligned on an even 8byte boundary, but instead because the
> arch is 32bit anyway and thus 64bit values need to be read in two steps
> alignment on 4 is done in the abi?

We could try to define "size", which is the first member in the struct, as:
  __aligned_u64
instead of the current:
  u64

That might do the trick. Could you test that if it works on your
platform/setup instead of patching the lib?

Thanks,
Kay


More information about the systemd-devel mailing list