[Mesa-dev] [PATCH 3/3] xlib: use X error handler to catch XShmQueryVersion() failure
Adam Jackson
ajax at redhat.com
Wed Jan 11 07:13:49 PST 2012
On Tue, 2012-01-10 at 19:46 -0700, Brian Paul wrote:
> From: Brian Paul <brianp at vmware.com>
>
> This is a follow-on to the previous commits. It seems that
> XShmQueryVersion() can trigger an X error after the first X
> connection is closed and we start using a new connection.
I assume this is when you switch which Display you're talking to as
well.
> +static int
> +xshm_query_version_err_handler( XMesaDisplay* dpy, XErrorEvent* xerr )
> +{
> + /* If this function gets called, it's because XShmQuerryVersion()
> + * has failed.
> + */
> + XShmErrorFlag = True;
> + return 0;
> +}
Not safe against a process using multiple Display connections, which is
admittedly quite rare. There's a few instances of that kind of bug
already though, I wouldn't call it a blocker.
> + /* Install X error handler before calling XShmQueryVersion() to catch
> + * a spurious X error.
> + */
> + XShmErrorFlag = False;
> + old_handler = XSetErrorHandler(xshm_query_version_err_handler);
> + ok = XShmQueryVersion( display, &major, &minor, &pixmaps );
> + XSetErrorHandler(old_handler);
> + if (XShmErrorFlag)
> + ok = False;
> +
> + if (ok) {
Not thread-safe, though it's tough to hit. You want an XLockDisplay
before the first XSetErrorHandler and the matching XUnlockDisplay after
the second, otherwise your handler can get called for errors on other
threads.
- ajax
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20120111/fef68ece/attachment.pgp>
More information about the mesa-dev
mailing list