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

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