File nspluginwrapper-noshm.patch of Package nspluginwrapper
2008-06-22 08:26 Gwenole Beauchesne <gb.public@free.fr>
* Makefile, src/libnoxshm.c, src/npw-viewer.sh: Don't allow
MIT-SHM (XShm, XVideo) when using QEMU as it causes some
endianness issues. Initial patch by Alexander Graf. Note that
you may also disable MIT-SHM for other platforms through
NPW_USE_XSHM set to no.
Index: src/libnoxshm.c
================================================================================
--- Makefile
+++ Makefile
@@ -131,6 +131,12 @@
libxpcom_LDFLAGS = $(LDFLAGS_32) -L$(LSB_OBJ_DIR)
endif
+libnoxshm_LIBRARY = libnoxshm.so
+libnoxshm_RAWSRCS = libnoxshm.c
+libnoxshm_SOURCES = $(libnoxshm_RAWSRCS:%.c=$(SRC_PATH)/src/%.c)
+libnoxshm_OBJECTS = $(libnoxshm_RAWSRCS:%.c=libnoxshm-%.o)
+libnoxshm_CFLAGS = $(PIC_CFLAGS)
+
npconfig_PROGRAM = npconfig
npconfig_RAWSRCS = npw-config.c
npconfig_SOURCES = $(npconfig_RAWSRCS:%.c=$(SRC_PATH)/src/%.c)
@@ -154,6 +160,7 @@
ifeq ($(build_viewer),yes)
TARGETS += $(npviewer_PROGRAM)
TARGETS += $(libxpcom_LIBRARY)
+TARGETS += $(libnoxshm_LIBRARY)
endif
archivedir = files/
@@ -192,7 +199,7 @@
distclean: clean
rm -f config-host.* config.*
-uninstall: uninstall.wrapper uninstall.viewer uninstall.libxpcom uninstall.loader uninstall.config uninstall.mkruntime uninstall.dirs
+uninstall: uninstall.wrapper uninstall.viewer uninstall.libxpcom uninstall.libnoxshm uninstall.loader uninstall.config uninstall.mkruntime uninstall.dirs
uninstall.dirs:
rmdir $(DESTDIR)$(pkglibdir)/noarch
rmdir $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)
@@ -208,6 +215,8 @@
rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(npviewer_PROGRAM:%.bin=%)
uninstall.libxpcom:
rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(libxpcom_LIBRARY)
+uninstall.libnoxshm:
+ rm -f $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(libnoxshm_LIBRARY)
uninstall.loader:
rm -f $(DESTDIR)$(pkglibdir)/noarch/$(nploader_PROGRAM)
uninstall.config:
@@ -216,7 +225,7 @@
uninstall.mkruntime:
rm -f $(DESTDIR)$(pkglibdir)/noarch/mkruntime
-install: install.dirs install.wrapper install.viewer install.libxpcom install.loader install.config install.mkruntime
+install: install.dirs install.wrapper install.viewer install.libxpcom install.libnoxshm install.loader install.config install.mkruntime
install.dirs:
mkdir -p $(DESTDIR)$(pkglibdir)/noarch
mkdir -p $(DESTDIR)$(pkglibdir)/$(ARCH)
@@ -230,9 +239,11 @@
ifeq ($(build_viewer),yes)
install.viewer: install.viewer.bin install.viewer.glue
install.libxpcom: do.install.libxpcom
+install.libnoxshm: do.install.libnoxshm
else
install.viewer:
install.libxpcom:
+install.libnoxshm:
endif
install.viewer.bin: $(npviewer_PROGRAM)
install -m 755 $(STRIP_OPT) $(npviewer_PROGRAM) $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(npviewer_PROGRAM)
@@ -245,6 +256,8 @@
chmod 755 $$p
do.install.libxpcom: $(libxpcom_LIBRARY)
install -m 755 $(STRIP_OPT) $(libxpcom_LIBRARY) $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(libxpcom_LIBRARY)
+do.install.libnoxshm: $(libnoxshm_LIBRARY)
+ install -m 755 $(STRIP_OPT) $(libnoxshm_LIBRARY) $(DESTDIR)$(pkglibdir)/$(ARCH_32)/$(TARGET_OS)/$(libnoxshm_LIBRARY)
install.config: $(npconfig_PROGRAM)
install -m 755 $(STRIP_OPT) $(npconfig_PROGRAM) $(DESTDIR)$(pkglibdir)/$(ARCH)/$(OS)/$(npconfig_PROGRAM)
mkdir -p $(DESTDIR)$(bindir)
@@ -315,6 +328,12 @@
libxpcom-%.o: $(SRC_PATH)/src/%.c
$(CC) $(CFLAGS_32) -o $@ -c $< $(CPPFLAGS) $(libxpcom_CFLAGS) -DBUILD_XPCOM
+$(libnoxshm_LIBRARY): $(libnoxshm_OBJECTS) $(LSB_OBJ_DIR) $(LSB_LIBS)
+ $(CC) $(LDFLAGS_32) $(DSO_LDFLAGS) -o $@ $(libnoxshm_OBJECTS) $(libnoxshm_LDFLAGS) -Wl,--soname,libnoxshm.so
+
+libnoxshm-%.o: $(SRC_PATH)/src/%.c
+ $(CC) $(CFLAGS_32) -o $@ -c $< $(CPPFLAGS) $(libnoxshm_CFLAGS)
+
$(npconfig_PROGRAM): $(npconfig_OBJECTS)
$(CC) -o $@ $(npconfig_OBJECTS) $(npconfig_LDFLAGS)
--- src/libnoxshm.c
+++ src/libnoxshm.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <string.h>
+
+/*
+ * This is a simple hacky library that disables the SHM-MIT and XVideo extenstions on any X application requesting
+ * it. To compile this run
+ *
+ * gcc -shared -ldl -o noshm.so noshm.c
+ *
+ * Author: Alexander Graf
+ * SuSE Linux Products GmbH
+ *
+ * License: Public Domain
+ *
+ */
+
+int (*real_XQueryExtension)(register void *dpy,const char *name,int *major_opcode,int *first_event,int *first_error) = NULL;
+void *RTLD_NEXT = (void*)-1l;
+void *dlsym(void *handle, const char *symbol);
+
+int
+XQueryExtension(
+ register void *dpy,
+ const char *name,
+ int *major_opcode,
+ int *first_event,
+ int *first_error)
+{
+ if(!strcmp(name, "MIT-SHM")) return 0;
+ if(!strcmp(name, "XVideo")) return 0;
+ if(!real_XQueryExtension) {
+ *(void **) (&real_XQueryExtension) = dlsym(RTLD_NEXT, "XQueryExtension");
+ }
+ return real_XQueryExtension(dpy, name, major_opcode, first_event, first_error);
+}
--- src/npw-viewer.sh
+++ src/npw-viewer.sh
@@ -21,6 +21,11 @@
# Set a new LD_LIBRARY_PATH that is TARGET specific
export LD_LIBRARY_PATH=$NPW_VIEWER_DIR
+# Note that a clever DBT will work at the function level and XShm
+# should be possible with a proper native replacement to emulated code
+# XXX: BTW, anything other than "yes" is interpreted as "no"
+NPW_USE_XSHM=${NPW_USE_XSHM:-yes}
+
case $ARCH in
i?86)
ARCH=i386
@@ -49,6 +54,8 @@
LOADER="none"
else
LOADER=`which qemu-i386`
+ # Don't allow Xshm with qemu
+ NPW_USE_XSHM=no
fi
;;
ppc)
@@ -60,6 +67,8 @@
esac
else
LOADER=`which qemu-ppc`
+ # Don't allow Xshm with qemu
+ NPW_USE_XSHM=no
fi
;;
esac
@@ -71,6 +80,18 @@
fi
fi
+# Disallow Xshm (implying XVideo too)
+if test "$NPW_USE_XSHM" != "yes"; then
+ if test -x "$NPW_VIEWER_DIR/libnoxshm.so"; then
+ if test -n "$LD_PRELOAD"; then
+ LD_PRELOAD="$LD_PRELOAD:$NPW_VIEWER_DIR/libnoxshm.so"
+ else
+ LD_PRELOAD="$NPW_VIEWER_DIR/libnoxshm.so"
+ fi
+ export LD_PRELOAD
+ fi
+fi
+
# Expand PATH for RealPlayer package on NetBSD (realplay)
if test "$OS" = "NetBSD"; then
REALPLAYER_HOME="/usr/pkg/lib/RealPlayer"