[Xcb] xcb recursive write not protected in all cases?

Keith Packard keithp at keithp.com
Thu Dec 26 10:07:40 PST 2013


Uli Schlachter <psychon at znc.in> writes:

> Hi again,
>
> TL;DR: I think that having to call get_socket_back() and waiting for
> c->out.writing to go to zero in a loop is the only issue we have due to the
> iolock getting dropped. The send_sync()s that were mentioned before
> seem safe to me.

Thanks for your careful analysis. I think you've correctly identified
all of the requirements for making sure we don't have inconsistencies in
the various paths related to writing requests.

The one thing that I think is still broken is the sequence number
requirements around wrapping and taking care of long periods without a
reply or event. In either case, we must atomically test the sequence
number condition and generate a request. That means we must not drop
iolock between the condition test and the request generation, and my
proposed patch of sticking the check for the socket inside send_request
would break that.

I think it's actually pretty easy to fix though. This patch creates a
new function, prepare_socket_request, which makes sure the current
thread can write a request, and then uses it in xcb_send_request and
_xcb_out_send_sync to fix the issues identified above. Then, it sticks
the sequence number checks in a loop and calls send_sync() *and*
prepare_socket_request() until both sequence conditions are
simultaneously true. At that point, it can call send_request knowing
that the socket is ready to send the request and the sequence number has
been cleaned up.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Ensure-xcb-owns-socket-and-no-other-threads-are-writ.patch
Type: text/x-diff
Size: 4417 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20131226/75e1e599/attachment.patch>
-------------- next part --------------

-- 
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20131226/75e1e599/attachment.pgp>


More information about the Xcb mailing list