Add MIT-SHM 1.2 (XShm fd passing) support to the xshm, xv, xcbshm
and xcbxv video outputs.

Also make xcbxv check that MIT-SHM is present before using it.


Index: Makefile
===================================================================
RCS file: /cvs/ports/multimedia/xine-lib/Makefile,v
retrieving revision 1.159
diff -u -p -u -p -r1.159 Makefile
--- Makefile    8 Feb 2026 15:44:47 -0000       1.159
+++ Makefile    15 Nov 2026 03:12:05 -0000
@@ -4,6 +4,7 @@ DISTNAME=       xine-lib-1.2.13pl20260207
 GH_ACCOUNT=    brad0
 GH_PROJECT=    xine-lib-1.2
 GH_COMMIT=     50d068edeaf3760eceaf537e1f8e9700e03f246c
+REVISION=      0
 CATEGORIES=    multimedia
 
 SHARED_LIBS=   xine    38.1
Index: patches/patch-m4_video_out_m4
===================================================================
RCS file: /cvs/ports/multimedia/xine-lib/patches/patch-m4_video_out_m4,v
retrieving revision 1.1
diff -u -p -u -p -r1.1 patch-m4_video_out_m4
--- patches/patch-m4_video_out_m4       8 Feb 2026 15:44:47 -0000       1.1
+++ patches/patch-m4_video_out_m4       15 Nov 2026 03:12:05 -0000
@@ -1,5 +1,8 @@
 Enable VA-API support.
 
+Add MIT-SHM 1.2 (fd passing) support, so frames no longer sit in world
+readable SysV shared memory segments.
+
 Index: m4/video_out.m4
 --- m4/video_out.m4.orig
 +++ m4/video_out.m4
@@ -14,3 +17,34 @@ Index: m4/video_out.m4
          gnu*)
              default_enable_vdpau=yes
              ;;
+@@ -373,6 +377,30 @@ AC_DEFUN([XINE_VIDEO_OUT_PLUGINS], [
+     AM_CONDITIONAL([ENABLE_XCBXV], [test x"$have_xcbxv" = x"yes"])
+ 
+ 
++    dnl MIT-SHM 1.2 (fd passing)
++    if test x"$no_x" != x"yes" || test x"$have_xcbshm" = x"yes"; then
++        PKG_CHECK_EXISTS([xcb-shm >= 1.10], [have_xcbshm_fd=yes], 
[have_xcbshm_fd=no])
++        if test x"$have_xcbshm_fd" = x"yes"; then
++            AC_CHECK_FUNCS([memfd_create shm_mkstemp])
++            AC_CHECK_DECLS([SHM_ANON], [], [], [[#include <sys/mman.h>]])
++            saved_LIBS="$LIBS"
++            AC_SEARCH_LIBS([shm_open], [rt], [AC_DEFINE([HAVE_SHM_OPEN], 1, 
[Define this if you have shm_open()])])
++            LIBS="$saved_LIBS"
++            if test x"$ac_cv_search_shm_open" != x"no" && test 
x"$ac_cv_search_shm_open" != x"none required"; then
++                SHM_LIBS="$ac_cv_search_shm_open"
++            fi
++            AC_DEFINE([HAVE_XCB_SHM_FD], 1, [Define this if xcb-shm supports 
fd passing])
++            if test x"$no_x" != x"yes"; then
++                PKG_CHECK_MODULES([X11XCB], [x11-xcb xcb-shm >= 1.10], 
[have_x11xcb=yes], [have_x11xcb=no])
++                if test x"$have_x11xcb" = x"yes"; then
++                    AC_DEFINE([HAVE_X11_XCB], 1, [Define this if you have 
libX11-xcb])
++                fi
++            fi
++        fi
++    fi
++    AC_SUBST(SHM_LIBS)
++
++
+     dnl vidix/libdha
+     dnl Requires X11 or Linux framebuffer
+     XINE_ARG_ENABLE([vidix], [enable support for Vidix])
Index: patches/patch-src_video_out_Makefile_am
===================================================================
RCS file: patches/patch-src_video_out_Makefile_am
diff -N patches/patch-src_video_out_Makefile_am
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_video_out_Makefile_am     15 Nov 2026 03:12:05 -0000
@@ -0,0 +1,42 @@
+Add MIT-SHM 1.2 (fd passing) support, so frames no longer sit in world
+readable SysV shared memory segments.
+
+Index: src/video_out/Makefile.am
+--- src/video_out/Makefile.am.orig
++++ src/video_out/Makefile.am
+@@ -14,7 +14,7 @@ endif
+ 
+ EXTRA_DIST = video_out_macosx.m color_matrix.c
+ 
+-noinst_HEADERS = xv_common.h
++noinst_HEADERS = xv_common.h xshm_fd.h
+ 
+ # helper libraries
+ 
+@@ -175,20 +175,20 @@ xineplug_vo_out_vaapi_la_LIBADD = $(XINE
+ xineplug_vo_out_vaapi_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(XV_CFLAGS) 
$(LIBVA_CFLAGS) $(LIBVA_GLX_CFLAGS) $(LIBVA_X11_CFLAGS)
+ 
+ xineplug_vo_out_xcbshm_la_SOURCES = video_out_xcbshm.c
+-xineplug_vo_out_xcbshm_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(XCB_LIBS) 
$(XCBSHM_LIBS) $(LTLIBINTL) $(XCBOSD_LIB)
++xineplug_vo_out_xcbshm_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(XCB_LIBS) 
$(XCBSHM_LIBS) $(SHM_LIBS) $(LTLIBINTL) $(XCBOSD_LIB)
+ xineplug_vo_out_xcbshm_la_CFLAGS = $(AM_CFLAGS) $(XCB_CFLAGS) $(XCBSHM_CFLAGS)
+ 
+ xineplug_vo_out_xcbxv_la_SOURCES = video_out_xcbxv.c
+-xineplug_vo_out_xcbxv_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) 
$(XCBXV_LIBS) $(XCB_LIBS) $(XCBSHM_LIBS) $(XCBOSD_LIB)
++xineplug_vo_out_xcbxv_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) 
$(XCBXV_LIBS) $(XCB_LIBS) $(XCBSHM_LIBS) $(SHM_LIBS) $(XCBOSD_LIB)
+ xineplug_vo_out_xcbxv_la_CFLAGS = $(AM_CFLAGS) $(XCB_CFLAGS) $(XCBXV_CFLAGS)
+ 
+ xineplug_vo_out_xshm_la_SOURCES = video_out_xshm.c
+-xineplug_vo_out_xshm_la_LIBADD = $(XINE_LIB) $(X_LIBS) $(PTHREAD_LIBS) 
$(LTLIBINTL) $(X11OSD_LIB)
+-xineplug_vo_out_xshm_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS)
++xineplug_vo_out_xshm_la_LIBADD = $(XINE_LIB) $(X_LIBS) $(X11XCB_LIBS) 
$(SHM_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) $(X11OSD_LIB)
++xineplug_vo_out_xshm_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(X11XCB_CFLAGS)
+ 
+ xineplug_vo_out_xv_la_SOURCES = video_out_xv.c
+-xineplug_vo_out_xv_la_LIBADD = $(XINE_LIB) $(XV_LIBS) $(X_LIBS) 
$(PTHREAD_LIBS) $(LTLIBINTL) $(X11OSD_LIB)
+-xineplug_vo_out_xv_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(XV_CFLAGS)
++xineplug_vo_out_xv_la_LIBADD = $(XINE_LIB) $(XV_LIBS) $(X_LIBS) 
$(X11XCB_LIBS) $(SHM_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) $(X11OSD_LIB)
++xineplug_vo_out_xv_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(XV_CFLAGS) 
$(X11XCB_CFLAGS)
+ 
+ xineplug_vo_out_xvmc_la_SOURCES = video_out_xvmc.c
+ xineplug_vo_out_xvmc_la_LIBADD = $(XINE_LIB) $(XVMC_LIBS) $(XV_LIBS) 
$(X_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL)
Index: patches/patch-src_video_out_video_out_xcbshm_c
===================================================================
RCS file: patches/patch-src_video_out_video_out_xcbshm_c
diff -N patches/patch-src_video_out_video_out_xcbshm_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_video_out_video_out_xcbshm_c      15 Nov 2026 03:12:05 
-0000
@@ -0,0 +1,83 @@
+Add MIT-SHM 1.2 (fd passing) support, so frames no longer sit in world
+readable SysV shared memory segments.
+
+Index: src/video_out/video_out_xcbshm.c
+--- src/video_out/video_out_xcbshm.c.orig
++++ src/video_out/video_out_xcbshm.c
+@@ -65,6 +65,7 @@
+ #include <xine/xineutils.h>
+ #include <xine/vo_scale.h>
+ #include "xcbosd.h"
++#include "xshm_fd.h"
+ 
+ #include "xine_mmx.h"
+ 
+@@ -81,6 +82,7 @@ typedef struct {
+   uint8_t           *image;
+   int                bytes_per_line;
+   xcb_shm_seg_t      shmseg;
++  size_t             shm_size;   /* != 0: attached by fd, mmap()ed */
+ 
+   yuv2rgb_t         *yuv2rgb; /* yuv2rgb converter set up for this frame */
+   uint8_t           *rgb_dst;
+@@ -108,6 +110,7 @@ typedef struct {
+   int                bpp;
+   int                scanline_pad;
+   int                use_shm;
++  int                use_shm_fd;
+ 
+   int                brightness;
+   int                contrast;
+@@ -159,6 +162,27 @@ static void create_ximage(xshm_driver_t
+     xcb_void_cookie_t shm_attach_cookie;
+     xcb_generic_error_t *generic_error;
+ 
++#ifdef XINE_XSHM_FD
++    if (this->use_shm_fd) {
++      size_t size = (size_t)frame->bytes_per_line * height;
++      int fd;
++
++      frame->image = xine_shm_fd_alloc(size, &fd);
++      if (frame->image) {
++        frame->shmseg = xcb_generate_id(this->connection);
++        if (xine_xcb_shm_fd_attach(this->connection, frame->shmseg, fd)) {
++          frame->shm_size = size;
++          return;
++        }
++        frame->shmseg = 0;
++        munmap(frame->image, size);
++      }
++      xprintf(this->xine, XINE_VERBOSITY_LOG,
++            "%s: MIT-SHM fd passing failed, using SysV shared memory.\n", 
LOG_MODULE);
++      this->use_shm_fd = 0;
++    }
++#endif
++
+     /*
+      * try shm
+      */
+@@ -228,6 +252,12 @@ static void dispose_ximage(xshm_driver_t
+   if (frame->shmseg) {
+     xcb_shm_detach(this->connection, frame->shmseg);
+     frame->shmseg = 0;
++#ifdef XINE_XSHM_FD
++    if (frame->shm_size) {
++      munmap(frame->image, frame->shm_size);
++      frame->shm_size = 0;
++    } else
++#endif
+     shmdt(frame->image);
+   } else
+     free(frame->image);
+@@ -1279,6 +1309,11 @@ static vo_driver_t *xshm_open_plugin(vid
+   query_extension_reply = xcb_get_extension_data(this->connection, 
&xcb_shm_id);
+   if (query_extension_reply && query_extension_reply->present) {
+     this->use_shm = 1;
++#ifdef XINE_XSHM_FD
++    this->use_shm_fd = xine_xcb_shm_fd_usable(this->connection);
++    xprintf(this->xine, XINE_VERBOSITY_DEBUG, "%s: MIT-SHM fd passing %s.\n",
++          LOG_MODULE, this->use_shm_fd ? "enabled" : "not available");
++#endif
+   }
+   else {
+     xprintf(this->xine, XINE_VERBOSITY_LOG,
Index: patches/patch-src_video_out_video_out_xcbxv_c
===================================================================
RCS file: patches/patch-src_video_out_video_out_xcbxv_c
diff -N patches/patch-src_video_out_video_out_xcbxv_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_video_out_video_out_xcbxv_c       15 Nov 2026 03:12:05 
-0000
@@ -0,0 +1,107 @@
+Add MIT-SHM 1.2 (fd passing) support, so frames no longer sit in world
+readable SysV shared memory segments.
+
+Index: src/video_out/video_out_xcbxv.c
+--- src/video_out/video_out_xcbxv.c.orig
++++ src/video_out/video_out_xcbxv.c
+@@ -66,6 +66,7 @@
+ #include <xine/xineutils.h>
+ #include <xine/vo_scale.h>
+ #include "xcbosd.h"
++#include "xshm_fd.h"
+ #define XV_PROPS
+ #include "xv_common.h"
+ 
+@@ -95,6 +96,7 @@ typedef struct {
+   int                width, height, xvformat;
+   uint8_t           *image;
+   xcb_shm_seg_t      shmseg;
++  size_t             shm_size;   /* != 0: attached by fd, mmap()ed */
+   unsigned int       xv_format;
+   unsigned int       xv_data_size;
+   unsigned int       xv_width;
+@@ -121,6 +123,7 @@ struct xv_driver_s {
+   xcb_xv_port_t      xv_port;
+ 
+   int                use_shm;
++  int                use_shm_fd;
+   int                use_pitch_alignment;
+   uint32_t           capabilities;
+   xv_property_t      props[XV_NUM_PROPERTIES];
+@@ -186,6 +189,11 @@ static void xv_frame_dispose (vo_frame_t
+     xcb_shm_detach(this->connection, frame->shmseg);
+     frame->shmseg = 0;
+     pthread_mutex_unlock(&this->main_mutex);
++#ifdef XINE_XSHM_FD
++    if (frame->shm_size)
++      munmap(frame->image, frame->shm_size);
++    else
++#endif
+     shmdt(frame->image);
+   }
+   else
+@@ -293,6 +301,27 @@ static void create_ximage(xv_driver_t *t
+       goto shm_fail1;
+     }
+ 
++#ifdef XINE_XSHM_FD
++    if (this->use_shm_fd) {
++      size_t size = frame->xv_data_size;
++      int fd;
++
++      frame->image = xine_shm_fd_alloc(size, &fd);
++      if (frame->image) {
++        frame->shmseg = xcb_generate_id(this->connection);
++        if (xine_xcb_shm_fd_attach(this->connection, frame->shmseg, fd)) {
++          frame->shm_size = size;
++          return;
++        }
++        frame->shmseg = 0;
++        munmap(frame->image, size);
++      }
++      xprintf(this->xine, XINE_VERBOSITY_LOG,
++            "%s: MIT-SHM fd passing failed, using SysV shared memory.\n", 
LOG_MODULE);
++      this->use_shm_fd = 0;
++    }
++#endif
++
+     shmid = shmget(IPC_PRIVATE, frame->xv_data_size, IPC_CREAT | 0777);
+ 
+     if (shmid < 0 ) {
+@@ -368,6 +397,12 @@ static void dispose_ximage(xv_driver_t *
+   if (frame->shmseg) {
+     xcb_shm_detach(this->connection, frame->shmseg);
+     frame->shmseg = 0;
++#ifdef XINE_XSHM_FD
++    if (frame->shm_size) {
++      munmap(frame->image, frame->shm_size);
++      frame->shm_size = 0;
++    } else
++#endif
+     shmdt(frame->image);
+   } else
+     free(frame->image);
+@@ -1430,6 +1465,23 @@ static vo_driver_t *open_plugin(video_dr
+   }
+ 
+   /*
++   * check for X shared memory support
++   */
++  query_extension_reply = xcb_get_extension_data(this->connection, 
&xcb_shm_id);
++  if (!query_extension_reply || !query_extension_reply->present) {
++    xprintf(this->xine, XINE_VERBOSITY_LOG,
++          _("%s: MIT shared memory extension not present on display.\n"), 
LOG_MODULE);
++    this->use_shm = 0;
++  }
++#ifdef XINE_XSHM_FD
++  else {
++    this->use_shm_fd = xine_xcb_shm_fd_usable(this->connection);
++    xprintf(this->xine, XINE_VERBOSITY_DEBUG, "%s: MIT-SHM fd passing %s.\n",
++          LOG_MODULE, this->use_shm_fd ? "enabled" : "not available");
++  }
++#endif
++
++  /*
+    * check adaptors, search for one that supports (at least) yuv12
+    */
+   {
Index: patches/patch-src_video_out_video_out_xshm_c
===================================================================
RCS file: patches/patch-src_video_out_video_out_xshm_c
diff -N patches/patch-src_video_out_video_out_xshm_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_video_out_video_out_xshm_c        15 Nov 2026 03:12:05 
-0000
@@ -0,0 +1,84 @@
+Add MIT-SHM 1.2 (fd passing) support, so frames no longer sit in world
+readable SysV shared memory segments.
+
+Index: src/video_out/video_out_xshm.c
+--- src/video_out/video_out_xshm.c.orig
++++ src/video_out/video_out_xshm.c
+@@ -64,6 +64,11 @@
+ #include <xine/xineutils.h>
+ #include <xine/vo_scale.h>
+ #include "x11osd.h"
++#include "xshm_fd.h"
++#if defined(XINE_XSHM_FD) && defined(HAVE_X11_XCB)
++#  include <X11/Xlib-xcb.h>
++#  define XSHM_FD 1
++#endif
+ #include "xine_mmx.h"
+ 
+ #define LOCK_DISPLAY(this) {if(this->lock_display) 
this->lock_display(this->user_data); \
+@@ -107,6 +112,7 @@ typedef struct {
+   GC                 gc;
+   int                depth, bpp, bytes_per_pixel, image_byte_order;
+   int                use_shm;
++  int                use_shm_fd;
+   XColor             black;
+ 
+   int                brightness;
+@@ -219,6 +225,29 @@ static XImage *create_ximage (xshm_drive
+     this->bytes_per_pixel = this->bpp / 8;
+     this->image_byte_order = myimage->byte_order;
+ 
++#ifdef XSHM_FD
++    if (this->use_shm_fd) {
++      xcb_connection_t *c = XGetXCBConnection (this->display);
++      size_t size = (size_t)myimage->bytes_per_line * myimage->height;
++      int fd;
++
++      shminfo->shmaddr = xine_shm_fd_alloc (size, &fd);
++      if (shminfo->shmaddr) {
++        shminfo->shmid    = XINE_XSHM_FD_SHMID;
++        shminfo->shmseg   = xcb_generate_id (c);
++        shminfo->readOnly = False;
++        if (xine_xcb_shm_fd_attach (c, shminfo->shmseg, fd)) {
++          myimage->data = shminfo->shmaddr;
++          goto finishShmTesting;
++        }
++        munmap (shminfo->shmaddr, size);
++      }
++      xprintf(this->xine, XINE_VERBOSITY_LOG,
++            "%s: MIT-SHM fd passing failed, using SysV shared memory.\n", 
LOG_MODULE);
++      this->use_shm_fd = 0;
++    }
++#endif
++
+     shminfo->shmid=shmget(IPC_PRIVATE,
+                         myimage->bytes_per_line * myimage->height,
+                         IPC_CREAT | 0777);
+@@ -312,6 +341,15 @@ static void dispose_ximage (xshm_driver_
+   if (this->use_shm) {
+ 
+     XShmDetach (this->display, shminfo);
++#ifdef XSHM_FD
++    if (shminfo->shmid == XINE_XSHM_FD_SHMID) {
++      size_t size = (size_t)myimage->bytes_per_line * myimage->height;
++      XDestroyImage (myimage);
++      munmap (shminfo->shmaddr, size);
++      shminfo->shmid = -1;
++      return;
++    }
++#endif
+     XDestroyImage (myimage);
+     shmdt (shminfo->shmaddr);
+     if (shminfo->shmid >= 0) {
+@@ -1309,6 +1347,11 @@ static vo_driver_t *xshm_open_plugin_2 (
+   LOCK_DISPLAY(this);
+   if (XShmQueryExtension(this->display)) {
+     this->use_shm = 1;
++#ifdef XSHM_FD
++    this->use_shm_fd = xine_xcb_shm_fd_usable (XGetXCBConnection 
(this->display));
++    xprintf(this->xine, XINE_VERBOSITY_DEBUG, "%s: MIT-SHM fd passing %s.\n",
++          LOG_MODULE, this->use_shm_fd ? "enabled" : "not available");
++#endif
+   }
+   else {
+     xprintf(this->xine, XINE_VERBOSITY_LOG,
Index: patches/patch-src_video_out_video_out_xv_c
===================================================================
RCS file: patches/patch-src_video_out_video_out_xv_c
diff -N patches/patch-src_video_out_video_out_xv_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_video_out_video_out_xv_c  15 Nov 2026 03:12:05 -0000
@@ -0,0 +1,123 @@
+Add MIT-SHM 1.2 (fd passing) support, so frames no longer sit in world
+readable SysV shared memory segments.
+
+Index: src/video_out/video_out_xv.c
+--- src/video_out/video_out_xv.c.orig
++++ src/video_out/video_out_xv.c
+@@ -71,6 +71,11 @@
+ #include <xine/xineutils.h>
+ #include <xine/vo_scale.h>
+ #include "x11osd.h"
++#include "xshm_fd.h"
++#if defined(XINE_XSHM_FD) && defined(HAVE_X11_XCB)
++#  include <X11/Xlib-xcb.h>
++#  define XSHM_FD 1
++#endif
+ #define XV_PROPS
+ #include "xv_common.h"
+ 
+@@ -125,6 +130,7 @@ struct xv_driver_s {
+   XColor             black;
+ 
+   int                use_shm;
++  int                use_shm_fd;
+   int                use_pitch_alignment;
+   xv_property_t      props[XV_NUM_PROPERTIES];
+   uint32_t           capabilities;
+@@ -196,13 +202,23 @@ static void xv_frame_dispose (vo_frame_t
+   if (frame->image) {
+ 
+     if (frame->shminfo.shmaddr) {
++#ifdef XSHM_FD
++      size_t size = frame->image->data_size;
++#endif
+       LOCK_DISPLAY(this);
+       XShmDetach (this->display, &frame->shminfo);
+       XFree (frame->image);
+       UNLOCK_DISPLAY(this);
+ 
+-      shmdt (frame->shminfo.shmaddr);
+-      shmctl (frame->shminfo.shmid, IPC_RMID, NULL);
++#ifdef XSHM_FD
++      if (frame->shminfo.shmid == XINE_XSHM_FD_SHMID) {
++        munmap (frame->shminfo.shmaddr, size);
++      } else
++#endif
++      {
++        shmdt (frame->shminfo.shmaddr);
++        shmctl (frame->shminfo.shmid, IPC_RMID, NULL);
++      }
+     }
+     else {
+       LOCK_DISPLAY(this);
+@@ -337,8 +353,6 @@ static XvImage *create_ximage (xv_driver
+         }
+     }
+ 
+-    shminfo->shmid = shmget(IPC_PRIVATE, image->data_size, IPC_CREAT | 0777);
+-
+     if (image->data_size==0) {
+       xprintf(this->xine, XINE_VERBOSITY_LOG,
+             _("%s: XvShmCreateImage returned a zero size\n"), LOG_MODULE);
+@@ -348,6 +362,32 @@ static XvImage *create_ximage (xv_driver
+       goto finishShmTesting;
+     }
+ 
++#ifdef XSHM_FD
++    if (this->use_shm_fd) {
++      xcb_connection_t *c = XGetXCBConnection (this->display);
++      size_t size = image->data_size;
++      int fd;
++
++      shminfo->shmaddr = xine_shm_fd_alloc (size, &fd);
++      if (shminfo->shmaddr) {
++        shminfo->shmid    = XINE_XSHM_FD_SHMID;
++        shminfo->shmseg   = xcb_generate_id (c);
++        shminfo->readOnly = False;
++        if (xine_xcb_shm_fd_attach (c, shminfo->shmseg, fd)) {
++          image->data = shminfo->shmaddr;
++          goto finishShmTesting;
++        }
++        munmap (shminfo->shmaddr, size);
++        shminfo->shmaddr = NULL;
++      }
++      xprintf(this->xine, XINE_VERBOSITY_LOG,
++            "%s: MIT-SHM fd passing failed, using SysV shared memory.\n", 
LOG_MODULE);
++      this->use_shm_fd = 0;
++    }
++#endif
++
++    shminfo->shmid = shmget(IPC_PRIVATE, image->data_size, IPC_CREAT | 0777);
++
+     if (shminfo->shmid < 0 ) {
+       xprintf(this->xine, XINE_VERBOSITY_LOG,
+             _("%s: shared memory error in shmget: %s\n"), LOG_MODULE, 
strerror(errno));
+@@ -435,6 +475,16 @@ static void dispose_ximage (xv_driver_t
+   if (shminfo->shmaddr) {
+ 
+     XShmDetach (this->display, shminfo);
++#ifdef XSHM_FD
++    if (shminfo->shmid == XINE_XSHM_FD_SHMID) {
++      size_t size = myimage->data_size;
++      XFree (myimage);
++      munmap (shminfo->shmaddr, size);
++      shminfo->shmaddr = NULL;
++      shminfo->shmid = -1;
++      return;
++    }
++#endif
+     XFree (myimage);
+     shmdt (shminfo->shmaddr);
+     if (shminfo->shmid >= 0) {
+@@ -1749,6 +1799,11 @@ static vo_driver_t *open_plugin_2 (video
+    * to find out if MIT shm really works, using supported format
+    */
+   LOCK_DISPLAY(this);
++#ifdef XSHM_FD
++  this->use_shm_fd = xine_xcb_shm_fd_usable (XGetXCBConnection 
(this->display));
++  xprintf(this->xine, XINE_VERBOSITY_DEBUG, "%s: MIT-SHM fd passing %s.\n",
++        LOG_MODULE, this->use_shm_fd ? "enabled" : "not available");
++#endif
+   {
+     XvImage         *myimage;
+     XShmSegmentInfo  myshminfo;
Index: patches/patch-src_video_out_xshm_fd_h
===================================================================
RCS file: patches/patch-src_video_out_xshm_fd_h
diff -N patches/patch-src_video_out_xshm_fd_h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_video_out_xshm_fd_h       15 Nov 2026 03:12:05 -0000
@@ -0,0 +1,156 @@
+Add MIT-SHM 1.2 (fd passing) support, so frames no longer sit in world
+readable SysV shared memory segments.
+
+Index: src/video_out/xshm_fd.h
+--- src/video_out/xshm_fd.h.orig
++++ src/video_out/xshm_fd.h
+@@ -0,0 +1,149 @@
++/*
++ * Copyright (C) 2026 the xine project
++ *
++ * This file is part of xine, a free video player.
++ *
++ * xine is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * xine is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA
++ *
++ * xshm_fd.h: MIT-SHM 1.2 (fd passing) helpers.
++ *
++ * With fd passing the shared memory is an unlinked shm object owned by
++ * the client, instead of a world accessible SysV segment.
++ */
++
++#ifndef XINE_XSHM_FD_H
++#define XINE_XSHM_FD_H
++
++#if defined(HAVE_XCB_SHM_FD) && \
++    (defined(HAVE_MEMFD_CREATE) || (defined(HAVE_DECL_SHM_ANON) && 
HAVE_DECL_SHM_ANON) || \
++     defined(HAVE_SHM_MKSTEMP) || defined(HAVE_SHM_OPEN))
++
++#define XINE_XSHM_FD 1
++
++/* Fake shmid marking a segment that was attached by fd. */
++#define XINE_XSHM_FD_SHMID (-2)
++
++#include <sys/types.h>
++#include <sys/mman.h>
++#include <sys/socket.h>
++#include <errno.h>
++#include <fcntl.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <time.h>
++#include <unistd.h>
++
++#include <xcb/xcb.h>
++#include <xcb/shm.h>
++
++/* Return an unlinked shared memory object, or -1. */
++static inline int xine_shm_fd_open (void) {
++  int fd;
++#if defined(HAVE_MEMFD_CREATE)
++  fd = memfd_create ("xine-shm", MFD_CLOEXEC);
++#elif defined(HAVE_DECL_SHM_ANON) && HAVE_DECL_SHM_ANON
++  fd = shm_open (SHM_ANON, O_RDWR, 0600);
++#elif defined(HAVE_SHM_MKSTEMP)
++  char name[] = "/xine-shm-XXXXXXXXXX";
++  fd = shm_mkstemp (name);
++  if (fd >= 0) {
++    shm_unlink (name);
++    fcntl (fd, F_SETFD, FD_CLOEXEC);
++  }
++#else
++  static unsigned int count;
++  char name[64];
++  int i;
++  fd = -1;
++  for (i = 0; i < 100; i++) {
++    snprintf (name, sizeof (name), "/xine-shm-%ld-%lx-%u",
++              (long)getpid (), (unsigned long)time (NULL), count++);
++    fd = shm_open (name, O_RDWR | O_CREAT | O_EXCL, 0600);
++    if (fd >= 0) {
++      shm_unlink (name);
++      break;
++    }
++    if (errno != EEXIST)
++      break;
++  }
++#endif
++  return fd;
++}
++
++/* Map size bytes of new shared memory. Returns the mapping and its fd
++ * in *fdp, or NULL. */
++static inline void *xine_shm_fd_alloc (size_t size, int *fdp) {
++  void *p;
++  int fd;
++
++  if (size == 0)
++    return NULL;
++  fd = xine_shm_fd_open ();
++  if (fd < 0)
++    return NULL;
++  if (ftruncate (fd, (off_t)size) < 0) {
++    close (fd);
++    return NULL;
++  }
++  p = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
++  if (p == MAP_FAILED) {
++    close (fd);
++    return NULL;
++  }
++  *fdp = fd;
++  return p;
++}
++
++/* fd passing needs MIT-SHM 1.2 and a local (unix socket) connection. */
++static inline int xine_xcb_shm_fd_usable (xcb_connection_t *c) {
++  const xcb_query_extension_reply_t *ext;
++  xcb_shm_query_version_reply_t *reply;
++  union {
++    struct sockaddr         sa;
++    struct sockaddr_storage ss;
++  } addr;
++  socklen_t len = sizeof (addr);
++  int ok;
++
++  if (getsockname (xcb_get_file_descriptor (c), &addr.sa, &len) < 0 ||
++      addr.sa.sa_family != AF_UNIX)
++    return 0;
++  ext = xcb_get_extension_data (c, &xcb_shm_id);
++  if (!ext || !ext->present)
++    return 0;
++  reply = xcb_shm_query_version_reply (c, xcb_shm_query_version (c), NULL);
++  if (!reply)
++    return 0;
++  ok = reply->major_version > 1 ||
++       (reply->major_version == 1 && reply->minor_version >= 2);
++  free (reply);
++  return ok;
++}
++
++/* Attach the memory behind fd as segment seg. xcb always closes fd. */
++static inline int xine_xcb_shm_fd_attach (xcb_connection_t *c, xcb_shm_seg_t 
seg, int fd) {
++  xcb_generic_error_t *error;
++
++  error = xcb_request_check (c, xcb_shm_attach_fd_checked (c, seg, fd, 0));
++  if (error) {
++    free (error);
++    return 0;
++  }
++  return 1;
++}
++
++#endif
++
++#endif

Reply via email to