[Xcb] Proposal: solution for alignment problem from using pointer addresses

Christian Linhart chris at DemoRecorder.com
Fri Jun 12 04:06:01 PDT 2015

Some time ago, I have implemented a compromise for implementing
alignment in structs or switches which start at positions that start with
an offset to alignment.

That compromise uses the pointer address for finding out the alignment offset. see:

The generally agreed assumption was that pointer addresses only come from properly aligned data such as read buffer for the display connection.

It turned out that the assumption was false:
In some cases the pointer addresses come from user-code, i.e., they are essentially random.
Thanks to Peter Hutterer for pointing that out.

So, we need another solution that does not require ABI/API changes.

Here's what I propose:
* Let the generator compute the initial alignment-offset for <switch> constructs.
  See for example the switch in <struct name="InputState"> in xinput.xml.
  It is possible to do such computations, but it is not entirely trivial.

* Make the initial alignment-offset of a struct explicit in the XML for those structs that start
  with an alignment offset.
  (I don't have an example at hand but these kind of structs do exist somewhere as far as I know.)

This solution will work under the condition that each specific struct or switch is used consistently with the same alignment offset everywhere.
(Which is a good idea anyways.)

Here's how this will look like for structs::

    <struct name="Foo">
        <initial-align-offset base="4" offset="2" />

This means that struct Foo will start with a 2-byte offset with respect to 4-byte alignment.

Default will be 0-byte offset with respect to 4-byte alignment.
So, most of the XML does not need to be changed.

For <switch>, no change in the xml will be necessary.

What do you think about that?


More information about the Xcb mailing list