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; /**