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

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