mesa: force link with shm* functions from libandroid-shmem

This commit is contained in:
Leonid Pliushch 2020-01-04 23:39:25 +02:00 committed by Yaksh Bariya
parent 80ddd807ee
commit ef7dc394e1
No known key found for this signature in database
GPG Key ID: F7486BA7D3D27581
2 changed files with 192 additions and 1 deletions

View File

@ -4,7 +4,7 @@ TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="Leonid Plyushch <leonid.plyushch@gmail.com>"
## Use 17.3.x branch because 18.x.x requires 'pthread_barrier_t'.
TERMUX_PKG_VERSION=17.3.9
TERMUX_PKG_REVISION=14
TERMUX_PKG_REVISION=15
TERMUX_PKG_SRCURL=https://mesa.freedesktop.org/archive/older-versions/${TERMUX_PKG_VERSION:0:2}.x/mesa-$TERMUX_PKG_VERSION.tar.xz
TERMUX_PKG_SHA256=c5beb5fc05f0e0c294fefe1a393ee118cb67e27a4dca417d77c297f7d4b6e479

View File

@ -0,0 +1,191 @@
diff -uNr mesa-17.3.9/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c mesa-17.3.9.mod/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c
--- mesa-17.3.9/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c 2018-04-18 11:44:00.000000000 +0300
+++ mesa-17.3.9.mod/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c 2020-01-04 23:30:19.874977603 +0200
@@ -46,9 +46,84 @@
#include <X11/Xlibint.h>
#include <X11/Xutil.h>
#include <sys/ipc.h>
-#include <sys/shm.h>
#include <X11/extensions/XShm.h>
+#include <linux/shm.h>
+#include <dlfcn.h>
+
+#ifndef shmid_ds
+# define shmid_ds shmid64_ds
+#endif
+
+static void * (*android_shmat)(int shmid, const void *shmaddr, int shmflg) = NULL;
+static int (*android_shmdt)(const void *shmaddr) = NULL;
+static int (*android_shmget)(key_t key, size_t size, int shmflg) = NULL;
+static int (*android_shmctl)(int shmid, int cmd, struct shmid_ds *buf) = NULL;
+
+static void * shmat(int shmid, const void *shmaddr, int shmflg) {
+ if (!android_shmat) {
+ void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+ if (!handle) {
+ abort();
+ }
+
+ android_shmat = dlsym(handle, "shmat");
+
+ dlclose(handle);
+ }
+
+ return android_shmat(shmid, shmaddr, shmflg);
+}
+
+static int shmdt(const void *shmaddr) {
+ if (!android_shmdt) {
+ void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+ if (!handle) {
+ abort();
+ }
+
+ android_shmdt = dlsym(handle, "shmdt");
+
+ dlclose(handle);
+ }
+
+ return android_shmdt(shmaddr);
+}
+
+static int shmget(key_t key, size_t size, int shmflg) {
+ if (!android_shmget) {
+ void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+ if (!handle) {
+ abort();
+ }
+
+ android_shmget = dlsym(handle, "shmget");
+
+ dlclose(handle);
+ }
+
+ return android_shmget(key, size, shmflg);
+}
+
+static int shmctl(int shmid, int cmd, struct shmid_ds *buf) {
+ if (!android_shmctl) {
+ void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+ if (!handle) {
+ abort();
+ }
+
+ android_shmctl = dlsym(handle, "shmctl");
+
+ dlclose(handle);
+ }
+
+ return android_shmctl(shmid, cmd, buf);
+}
+
DEBUG_GET_ONCE_BOOL_OPTION(xlib_no_shm, "XLIB_NO_SHM", FALSE)
/**
diff -uNr mesa-17.3.9/src/mesa/drivers/x11/glxheader.h mesa-17.3.9.mod/src/mesa/drivers/x11/glxheader.h
--- mesa-17.3.9/src/mesa/drivers/x11/glxheader.h 2018-04-18 11:44:00.000000000 +0300
+++ mesa-17.3.9.mod/src/mesa/drivers/x11/glxheader.h 2020-01-04 23:38:48.043159877 +0200
@@ -34,7 +34,6 @@
# include <X11/Xutil.h>
# ifdef USE_XSHM /* was SHM */
# include <sys/ipc.h>
-# include <sys/shm.h>
# include <X11/extensions/XShm.h>
# endif
# include <GL/glx.h>
diff -uNr mesa-17.3.9/src/mesa/drivers/x11/xm_buffer.c mesa-17.3.9.mod/src/mesa/drivers/x11/xm_buffer.c
--- mesa-17.3.9/src/mesa/drivers/x11/xm_buffer.c 2018-04-18 11:44:00.000000000 +0300
+++ mesa-17.3.9.mod/src/mesa/drivers/x11/xm_buffer.c 2020-01-04 23:29:44.585678356 +0200
@@ -37,11 +37,86 @@
#include "main/renderbuffer.h"
#include "swrast/s_renderbuffer.h"
-
#define XMESA_RENDERBUFFER 0x1234
#if defined(USE_XSHM)
+#include <linux/shm.h>
+#include <dlfcn.h>
+
+#ifndef shmid_ds
+# define shmid_ds shmid64_ds
+#endif
+
+static void * (*android_shmat)(int shmid, const void *shmaddr, int shmflg) = NULL;
+static int (*android_shmdt)(const void *shmaddr) = NULL;
+static int (*android_shmget)(key_t key, size_t size, int shmflg) = NULL;
+static int (*android_shmctl)(int shmid, int cmd, struct shmid_ds *buf) = NULL;
+
+static void * shmat(int shmid, const void *shmaddr, int shmflg) {
+ if (!android_shmat) {
+ void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+ if (!handle) {
+ abort();
+ }
+
+ android_shmat = dlsym(handle, "shmat");
+
+ dlclose(handle);
+ }
+
+ return android_shmat(shmid, shmaddr, shmflg);
+}
+
+static int shmdt(const void *shmaddr) {
+ if (!android_shmdt) {
+ void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+ if (!handle) {
+ abort();
+ }
+
+ android_shmdt = dlsym(handle, "shmdt");
+
+ dlclose(handle);
+ }
+
+ return android_shmdt(shmaddr);
+}
+
+static int shmget(key_t key, size_t size, int shmflg) {
+ if (!android_shmget) {
+ void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+ if (!handle) {
+ abort();
+ }
+
+ android_shmget = dlsym(handle, "shmget");
+
+ dlclose(handle);
+ }
+
+ return android_shmget(key, size, shmflg);
+}
+
+static int shmctl(int shmid, int cmd, struct shmid_ds *buf) {
+ if (!android_shmctl) {
+ void *handle = dlopen("@TERMUX_PREFIX@/lib/libandroid-shmem.so", RTLD_LOCAL | RTLD_LAZY);
+
+ if (!handle) {
+ abort();
+ }
+
+ android_shmctl = dlsym(handle, "shmctl");
+
+ dlclose(handle);
+ }
+
+ return android_shmctl(shmid, cmd, buf);
+}
+
static volatile int mesaXErrorFlag = 0;
/**