SYNC extension: misalignment of system counter structs?
Daniel Neugebauer
mailinglists at energiequant.de
Tue Feb 4 17:46:03 UTC 2025
Hi,
I've recently started using XCB for screen capture and was looking for a
good way to wait for events with a timeout. I'm aware of the hack to
monitor the socket/file descriptor but stumbled upon SYNC alarms based
on SERVERTIME [1] which actually looks like the clean solution to
eventually get unblocked if no other events arrive.
Following that article, I tried to iterate over all system counters as
returned by xcb_sync_list_system_counters but couldn't find SERVERTIME.
This is odd, also "VICEIDLETIME" and empty counter names made no sense
so I started looking into memory and noticed that XCB appears to have a
misalignment when accessing/iterating over xcb_sync_systemcounter_t:
Struct xcb_sync_systemcounter_t gets aligned to a length of 16 bytes but
actually ends after 14 bytes, followed by the counter's name (explaining
the missing 2 characters on [DE]VICEIDLETIME). This misalignment makes
both xcb_sync_systemcounter_next and xcb_sync_systemcounter_name unusable.
As I am compiling XCB myself for static linking, I wasn't sure if that's
a local (self-induced) issue or a bug, so I tried to link dynamically
against system libraries and also tried it on another system [2] but the
issue seems to be present in all cases.
Accessing the SYNC extension via XCB appears to be pretty rare, at least
I couldn't find any prior implementations for reference when I googled it.
I saw that events use a define XCB_PACKED and tried to apply that to the
xcb_sync_systemcounter_t struct but the iterator then (still?) ends up
miscalculating paddings (I end up 2 bytes past the struct).
It would be great if someone could confirm the issue. See [3] for a test
implementation incl. a local workaround. Is there anything I'm doing
wrong on my end?
Thanks,
Daniel
[1] https://nrk.neocities.org/articles/x11-timeout-with-xsyncalarm
[2] Gentoo on Ryzen 7800X3D | xorg 21.1.15, xcb 1.17.0
Ubuntu 24.04 on i5-1235U | xorg 21.1.12, xcb 1.15
[3] https://gist.github.com/dneuge/79795ea67a730d0a893239b92c220373
More information about the Xcb
mailing list