[Xcb] ListHosts entry lengths and padding to 4-byte alignment

Josh Triplett josh at joshtriplett.org
Mon Oct 11 23:39:32 PDT 2010


On Tue, Oct 12, 2010 at 01:56:39PM +1100, Nigel Tao wrote:
> Hi. I maintain x-go-binding, a port of xcb to the Go programming language.

Wow.  Awesome. :)

We really need to put up a page on the wiki to point at known XCB
bindings in other languages.  We didn't know about this one at all.

> I'm hoping someone can clarify the rules about padding list replies so
> that their elements' lengths are a multiple of 4.
> 
> For example, the X11 spec at
> ftp://ftp.x.org/pub/X11R7.0/doc/PDF/proto.pdf says that ListHosts
> (opcode 110, page 148) is marked "n always a multiple of 4" but
> ListExtensions (opcode 99, page 145) is not similarly marked.
> 
> IIUC the relevent parts of xcb's xproto.xml are:
> 
> -----------
>   <request name="ListExtensions" opcode="99">
>     <reply>
>       <field type="CARD8" name="names_len" />
>       <pad bytes="24" />
>       <list type="STR" name="names">
>         <fieldref>names_len</fieldref>
>       </list>
>     </reply>
>   </request>
> 
> <!-- other elements elided -->
> 
>   <struct name="HOST">
>     <field type="CARD8" name="family" enum="Family" />
>     <pad bytes="1" />
>     <field type="CARD16" name="address_len" />
>     <list type="BYTE" name="address">
>       <fieldref>address_len</fieldref>
>     </list>
>   </struct>
> 
>   <request name="ListHosts" opcode="110">
>     <reply>
>       <field type="BYTE" name="mode" enum="AccessControl" />
>       <field type="CARD16" name="hosts_len" />
>       <pad bytes="22" />
>       <list type="HOST" name="hosts">
>         <fieldref>hosts_len</fieldref>
>       </list>
>     </reply>
>   </request>
> -----------
> 
> How am I supposed to tell, from the XML file, that the elements of a
> <list type="HOST"> should be 4-padded (and not 1-padded or 2-padded),
> but a <list type="STR"> is 1-padded?

I think you can apply the rule that anything in the protocol has padding
to its own natural alignment, with a max of 4.  So, a list of bytes has
padding to byte alignment, but a HOST has size of at least 4, so it gets
padded to 4-byte alignment.  So, figure out the size of the type you
have a list of, and align the elements of the list to the natural
alignment for things of that size.

> I can make up a number of rules that each seem to match what I see for
> the core protocol, but I'd like to know the actual rule so that I can
> also handle any extensions.

In *theory*, extensions could choose to do any arbitrary crazy thing
(including change the core protocol, like BigRequests or XGE), but if
they do then they probably won't work with XCB without some extra
hackery. :)

> Apologies if this is documented somewhere and I've simply missed it,

Probably not, at least not to the level of detail you needed.

- Josh Triplett


More information about the Xcb mailing list