Blame SOURCES/fix-llvmpipe-remote-shm.patch

dc310b
From 607a59f2922b1261920bae94efe4dc87da18d576 Mon Sep 17 00:00:00 2001
dc310b
From: Adam Jackson <ajax@redhat.com>
dc310b
Date: Tue, 5 Mar 2019 15:31:51 -0500
dc310b
Subject: [PATCH] drisw: Try harder to probe whether MIT-SHM works
dc310b
dc310b
XQueryExtension merely tells you whether the extension exists, it
dc310b
doesn't tell you whether you're local enough for it to work.
dc310b
XShmQueryVersion is not enough to discover this either, you need to
dc310b
provoke the server to do actual work, and if it thinks you're remote it
dc310b
will throw BadRequest at you. So send an invalid ShmDetach and use the
dc310b
error code to distinguish local from remote.
dc310b
dc310b
Signed-off-by: Adam Jackson <ajax@redhat.com>
dc310b
---
dc310b
 src/glx/drisw_glx.c | 26 ++++++++++++++++++++++----
dc310b
 1 file changed, 22 insertions(+), 4 deletions(-)
dc310b
dc310b
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
dc310b
index c63b097a71a..67698d1c450 100644
dc310b
--- a/src/glx/drisw_glx.c
dc310b
+++ b/src/glx/drisw_glx.c
dc310b
@@ -73,11 +73,10 @@ handle_xerror(Display *dpy, XErrorEvent *event)
dc310b
    (void) dpy;
dc310b
 
dc310b
    assert(xshm_opcode != -1);
dc310b
-   if (event->request_code != xshm_opcode ||
dc310b
-       event->minor_code != X_ShmAttach)
dc310b
+   if (event->request_code != xshm_opcode)
dc310b
       return 0;
dc310b
 
dc310b
-   xshm_error = 1;
dc310b
+   xshm_error = event->error_code;
dc310b
    return 0;
dc310b
 }
dc310b
 
dc310b
@@ -826,9 +825,28 @@ driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions)
dc310b
 static int
dc310b
 check_xshm(Display *dpy)
dc310b
 {
dc310b
+   int (*old_handler)(Display *, XErrorEvent *);
dc310b
+
dc310b
    int ignore;
dc310b
+   XShmSegmentInfo info = { 0, };
dc310b
+
dc310b
+   if (!XQueryExtension(dpy, "MIT-SHM", &xshm_opcode, &ignore, &ignore))
dc310b
+      return False;
dc310b
+
dc310b
+   old_handler = XSetErrorHandler(handle_xerror);
dc310b
+   XShmDetach(dpy, &info;;
dc310b
+   XSync(dpy, False);
dc310b
+   (void) XSetErrorHandler(old_handler);
dc310b
 
dc310b
-   return XQueryExtension(dpy, "MIT-SHM", &xshm_opcode, &ignore, &ignore);
dc310b
+   /* BadRequest means we're a remote client. If we were local we'd
dc310b
+    * expect BadValue since 'info' has an invalid segment name.
dc310b
+    */
dc310b
+   if (xshm_error == BadRequest)
dc310b
+      return False;
dc310b
+
dc310b
+   /* reset this as others read it later */
dc310b
+   xshm_error = 0;
dc310b
+   return True;
dc310b
 }
dc310b
 
dc310b
 static struct glx_screen *
dc310b
-- 
dc310b
2.20.1
dc310b