Mesa (master): drisw: Port the MIT-SHM check to XCB

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Aug 17 16:32:53 UTC 2020


Module: Mesa
Branch: master
Commit: aeba69deaa536776452ec8b22a3131f187e82cac
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=aeba69deaa536776452ec8b22a3131f187e82cac

Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Aug 12 13:54:46 2020 -0400

drisw: Port the MIT-SHM check to XCB

The old version isn't thread-safe, and xlib makes it unreasonably
difficult to write thread-safely.

Fixes: mesa/mesa#3398
Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>
Reviewed-by: Michel Dänzer <mdaenzer at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6294>

---

 .gitlab-ci.yml                      |  2 +-
 .gitlab-ci/container/x86_test-gl.sh |  1 +
 meson.build                         |  2 ++
 src/glx/drisw_glx.c                 | 32 +++++++++++++++++---------------
 src/glx/meson.build                 |  2 +-
 5 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ed6dabce0ba..22c2ef57cb9 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -294,7 +294,7 @@ x86_test-base:
 x86_test-gl:
   extends: .use-x86_test-base
   variables:
-    FDO_DISTRIBUTION_TAG: &x86_test-gl "2020-07-28-x86-2"
+    FDO_DISTRIBUTION_TAG: &x86_test-gl "2020-08-14-xcb-shm"
 
 # Debian 10 based x86 test image for VK
 x86_test-vk:
diff --git a/.gitlab-ci/container/x86_test-gl.sh b/.gitlab-ci/container/x86_test-gl.sh
index d7672d9de87..aaed8ec1459 100644
--- a/.gitlab-ci/container/x86_test-gl.sh
+++ b/.gitlab-ci/container/x86_test-gl.sh
@@ -33,6 +33,7 @@ STABLE_EPHEMERAL=" \
       "
 
 apt-get install -y --no-remove \
+      libxcb-shm0 \
       $STABLE_EPHEMERAL
 
 
diff --git a/meson.build b/meson.build
index db4f8fc551b..2478753f2af 100644
--- a/meson.build
+++ b/meson.build
@@ -1701,6 +1701,7 @@ dep_xcb_sync = null_dep
 dep_xcb_xfixes = null_dep
 dep_xshmfence = null_dep
 dep_xcb_xrandr = null_dep
+dep_xcb_shm = null_dep
 dep_xlib_xrandr = null_dep
 if with_platform_x11
   if with_glx == 'xlib' or with_glx == 'gallium-xlib'
@@ -1713,6 +1714,7 @@ if with_platform_x11
     dep_xdamage = dependency('xdamage', version : '>= 1.1')
     dep_xfixes = dependency('xfixes')
     dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
+    dep_xcb_shm = dependency('xcb-shm')
   endif
   if (with_any_vk or with_glx == 'dri' or with_egl or
        (with_gallium_vdpau or with_gallium_xvmc or with_gallium_va or
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index 07ace2c82b1..b282db8cf83 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -23,7 +23,10 @@
 
 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
 
+#include <xcb/xproto.h>
+#include <xcb/shm.h>
 #include <X11/Xlib.h>
+#include <X11/Xlib-xcb.h>
 #include "glxclient.h"
 #include <dlfcn.h>
 #include "dri_common.h"
@@ -823,27 +826,26 @@ driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions)
 static int
 check_xshm(Display *dpy)
 {
-   int (*old_handler)(Display *, XErrorEvent *);
-
+   xcb_connection_t *c = XGetXCBConnection(dpy);
+   xcb_void_cookie_t cookie;
+   xcb_generic_error_t *error;
+   int ret = True;
    int ignore;
-   XShmSegmentInfo info = { 0, };
 
    if (!XQueryExtension(dpy, "MIT-SHM", &xshm_opcode, &ignore, &ignore))
       return False;
 
-   old_handler = XSetErrorHandler(handle_xerror);
-   XShmDetach(dpy, &info);
-   XSync(dpy, False);
-   (void) XSetErrorHandler(old_handler);
-
-   /* BadRequest means we're a remote client. If we were local we'd
-    * expect BadValue since 'info' has an invalid segment name.
-    */
-   if (xshm_error == BadRequest)
-      return False;
+   cookie = xcb_shm_detach_checked(c, 0);
+   if ((error = xcb_request_check(c, cookie))) {
+      /* BadRequest means we're a remote client. If we were local we'd
+       * expect BadValue since 'info' has an invalid segment name.
+       */
+      if (error->error_code == BadRequest)
+         ret = False;
+      free(error);
+   }
 
-   xshm_error = 0;
-   return True;
+   return ret;
 }
 
 static struct glx_screen *
diff --git a/src/glx/meson.build b/src/glx/meson.build
index bceed2f5fc7..d602bc14306 100644
--- a/src/glx/meson.build
+++ b/src/glx/meson.build
@@ -159,7 +159,7 @@ libgl = shared_library(
   dependencies : [
     dep_libdrm, dep_dl, dep_m, dep_thread, dep_x11, dep_xcb_glx, dep_xcb,
     dep_x11_xcb, dep_xcb_dri2, dep_xext, dep_xfixes, dep_xdamage, dep_xxf86vm,
-    extra_deps_libgl,
+    dep_xcb_shm, extra_deps_libgl,
   ],
   version : gl_lib_version,
   install : true,



More information about the mesa-commit mailing list