From ef7dc394e12cc0ef6ab433d6fc8fa7bf21e99cc8 Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Sat, 4 Jan 2020 23:39:25 +0200 Subject: [PATCH] mesa: force link with shm* functions from libandroid-shmem --- x11-packages/mesa/build.sh | 2 +- x11-packages/mesa/shm-hook.patch | 191 +++++++++++++++++++++++++++++++ 2 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 x11-packages/mesa/shm-hook.patch diff --git a/x11-packages/mesa/build.sh b/x11-packages/mesa/build.sh index 89d126bf6..dd795182f 100644 --- a/x11-packages/mesa/build.sh +++ b/x11-packages/mesa/build.sh @@ -4,7 +4,7 @@ TERMUX_PKG_LICENSE="MIT" TERMUX_PKG_MAINTAINER="Leonid Plyushch " ## 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 diff --git a/x11-packages/mesa/shm-hook.patch b/x11-packages/mesa/shm-hook.patch new file mode 100644 index 000000000..b3b78076a --- /dev/null +++ b/x11-packages/mesa/shm-hook.patch @@ -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 + #include + #include +-#include + #include + ++#include ++#include ++ ++#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 + # ifdef USE_XSHM /* was SHM */ + # include +-# include + # include + # endif + # include +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 ++#include ++ ++#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; + + /**