From 0607bb0b3a3b1dc08665cbf0618db0993b3988f3 Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Mon, 5 Oct 2026 12:44:16 -0400 Subject: [PATCH 1/3] Fix Xwayland dma-buf leak: close Zink's emulated GEM handles on KGSL (#275) Close Zink's emulated GEM handles on KGSL (Xwayland dma-buf leak) The session preload hands out GEM handles on the KGSL render node by duplicating the dma-buf descriptor, and released them only through drmCloseBufferHandle. Zink gives handles back with drmIoctl(DRM_IOCTL_GEM_CLOSE) instead, which KGSL refuses, so every duplicated descriptor stayed open and kept its buffer alive. Xwayland asks for a handle for each buffer it imports through gbm. With "Force game windows fullscreen" fighting a game's own resolution (DiRT 3 at 1280x720), the game recreates its swapchain many times a second and Xwayland piled up ~2,000 old swapchain images (6+ GB) in seconds until Android killed the session. A preload trace on the device put 2,090 of 2,118 open dma-buf descriptors in Xwayland on drmPrimeFDToHandle called from Zink. Handle GEM_CLOSE on the KGSL node in drmIoctl, and check the three DRM symbols are exported in CI. Co-authored-by: The412Banner --- .github/workflows/build.yml | 2 +- tools/linuxfs/preload/drm.c | 51 +++++++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a9f186c82e..ca91945da5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -343,7 +343,7 @@ jobs: echo "::error::libfakeinput.so exports the C++ runtime"; exit 1 fi SESSION=$(syms "$D/libblsession.so") - for sym in socket bind getsockname setsockopt statfs statvfs syscall shm_open shm_unlink mmap mmap64 munmap; do + for sym in socket bind getsockname setsockopt statfs statvfs syscall shm_open shm_unlink mmap mmap64 munmap drmPrimeFDToHandle drmCloseBufferHandle drmIoctl; do grep -qx "$sym" <<<"$SESSION" || { echo "::error::libblsession.so does not export $sym"; exit 1; } done test -f "$D/usr/local/bin/droiddeck-session" diff --git a/tools/linuxfs/preload/drm.c b/tools/linuxfs/preload/drm.c index f2d3ae1926..82b072b1b1 100644 --- a/tools/linuxfs/preload/drm.c +++ b/tools/linuxfs/preload/drm.c @@ -12,11 +12,19 @@ #include #include #include +#include #include #include #define MAX_HANDLES 4096 +/* DRM_IOCTL_GEM_CLOSE from drm.h: _IOW('d', 0x09, struct drm_gem_close { u32 handle, pad; }). */ +struct gem_close { + uint32_t handle; + uint32_t pad; +}; +#define GEM_CLOSE _IOW('d', 0x09, struct gem_close) + static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; static int handle_fds[MAX_HANDLES]; static dev_t kgsl_dev; @@ -82,20 +90,47 @@ int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd) { return ret; } +/* Drops a handle's descriptor; false when the handle was never given out. */ +static int release_handle(uint32_t handle) { + int found = 0; + pthread_mutex_lock(&lock); + if (handle > 0 && handle < MAX_HANDLES && handle_fds[handle] > 0) { + close(handle_fds[handle]); + handle_fds[handle] = 0; + found = 1; + } + pthread_mutex_unlock(&lock); + return found; +} + int drmCloseBufferHandle(int fd, uint32_t handle) { if (!is_kgsl(fd)) { int (*fn)(int, uint32_t) = (int (*)(int, uint32_t)) real("drmCloseBufferHandle"); return fn ? fn(fd, handle) : -ENOSYS; } - int ret = -EINVAL; - pthread_mutex_lock(&lock); - if (handle > 0 && handle < MAX_HANDLES && handle_fds[handle] > 0) { - close(handle_fds[handle]); - handle_fds[handle] = 0; - ret = 0; + return release_handle(handle) ? 0 : -EINVAL; +} + +/* + * Zink gives its handles back with the GEM_CLOSE ioctl itself, not drmCloseBufferHandle + * (zink_bo.c, bo_destroy). KGSL refuses the ioctl, so the duplicated descriptor stayed open and + * kept the whole buffer alive: Xwayland asks for a handle for every buffer it imports, and a game + * whose swapchain was recreated on each resize piled up gigabytes of old swapchain images until + * Android killed the session. + */ +int drmIoctl(int fd, unsigned long request, void *arg) { + if (request == GEM_CLOSE && arg && is_kgsl(fd)) { + if (release_handle(((struct gem_close *) arg)->handle)) { + return 0; + } + errno = EINVAL; + return -1; } - pthread_mutex_unlock(&lock); - return ret; + int (*fn)(int, unsigned long, void *) = (int (*)(int, unsigned long, void *)) real("drmIoctl"); + if (!fn) { + return -1; + } + return fn(fd, request, arg); } /* From 9f46c7a50b6f583e0040040882a025d4e7813491 Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Mon, 5 Oct 2026 12:44:45 -0400 Subject: [PATCH 2/3] Force game windows fullscreen: off by default (#276) A game whose resolution differs from the screen's (DiRT 3 at 1280x720) fights --force-windows-fullscreen: every forced resize makes it rebuild its swapchain, and the picture flickers between its own size and the screen's - often from the first menu, before the player can reach the game's resolution setting. It also drove the Xwayland dma-buf leak fixed separately. The switch stays in Settings > Games and the session drawer, now off unless turned on; its hint says when to turn it on (a game coming back small or in a corner after switching apps, e.g. FlatOut) and when to leave it off (flicker). Users who already set it keep their choice. The session script's fallback when the app passes nothing is off as well. Co-authored-by: The412Banner --- app/src/main/java/com/droiddeck/launcher/MainActivity.kt | 2 +- .../java/com/droiddeck/launcher/session/SessionPrefs.kt | 7 +++++-- app/src/main/res/values/strings.xml | 4 ++-- tools/linuxfs/overlay/usr/local/bin/droiddeck-session | 9 +++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index 0df7b586fd..e4e719a313 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -152,7 +152,7 @@ class MainActivity : ComponentActivity() { private var showPhantomGate by mutableStateOf(false) private var directAudio by mutableStateOf(false) private var clientDirectAudio by mutableStateOf(false) - private var forceFullscreen by mutableStateOf(true) + private var forceFullscreen by mutableStateOf(false) private var stretch16x9 by mutableStateOf(false) private var launcherFullscreen by mutableStateOf(true) private var animationsEnabled by mutableStateOf(true) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index 2205446044..a32dd582eb 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -168,9 +168,12 @@ object SessionPrefs { * Steam only: gamescope makes every game window the size of the screen. A game that resizes * its own window when it loses focus (FlatOut) otherwise comes back smaller, drawn in a * corner; a game that sets its own resolution and never looks at its window again (Quake 3) - * instead draws small in the bottom-left of the stretched one. On unless turned off. + * instead draws small in the bottom-left of the stretched one. A game whose resolution differs + * from the screen's (DiRT 3 at 1280x720) fights it: it rebuilds its swapchain on every forced + * resize and the picture flickers between its own size and the screen's, often from the first + * menu, before the player can reach its resolution setting. Off unless turned on. */ - fun forceFullscreen(context: Context): Boolean = prefs(context).getBoolean("forceFullscreen", true) + fun forceFullscreen(context: Context): Boolean = prefs(context).getBoolean("forceFullscreen", false) fun setForceFullscreen(context: Context, on: Boolean) { prefs(context).edit().putBoolean("forceFullscreen", on).apply() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b75e9c932e..d3594e8941 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1039,8 +1039,8 @@ Frame rate Game window compatibility Force game windows fullscreen - Keeps games fullscreen after focus changes. Turn off if a game draws small. Applies live during a session. - Keeps games fullscreen after focus changes. Applies live. + Makes every game window the size of the screen. Turn on if a game comes back small or in a corner after switching apps; leave off if a game flickers between sizes. Applies live during a session. + Turn on if a game comes back small after switching; off if it flickers. Applies live. %1$s Sets scaling to %2$s. Match screen (%1$d×%2$d) Steam diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 91465d661e..b0e5cf1866 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -179,9 +179,10 @@ if [ -z "${BL_INSIDE:-}" ]; then [ "$mode" = steam ] && args+=(--default-touch-mode 4) # A game that resizes its own window when it loses focus (the Steam menu opening over it) comes # back smaller, and gamescope draws a window that is not flagged fullscreen at its own size in - # the top-left corner. Forcing every window to the output's size keeps it filling the screen. - # BL_GAMESCOPE_FORCE_FULLSCREEN=0 turns it off. - [ "$mode" = steam ] && [ "${BL_GAMESCOPE_FORCE_FULLSCREEN:-1}" = 1 ] && args+=(--force-windows-fullscreen) + # the top-left corner. Forcing every window to the output's size keeps it filling the screen, + # but a game running at a resolution other than the screen's fights it and flickers, so it is + # off unless the app asks for it: BL_GAMESCOPE_FORCE_FULLSCREEN=1 turns it on. + [ "$mode" = steam ] && [ "${BL_GAMESCOPE_FORCE_FULLSCREEN:-0}" = 1 ] && args+=(--force-windows-fullscreen) # HDR10: the app opened its compositor's colour-management gate for this session (BL_HDR=1); # gamescope then offers HDR to its clients through the same wp_color_manager_v1 it binds on ours. [ "${BL_HDR:-0}" = 1 ] && args+=(--hdr-enabled) @@ -445,7 +446,7 @@ case $mode in # the root window, which it watches. What gamescope was started with is where this begins. # Not on the desktop (BL_DESKTOP): no gamescope there, and the loop would outlive the client. [ -z "${BL_DESKTOP:-}" ] && ( - last=${BL_GAMESCOPE_FORCE_FULLSCREEN:-1} + last=${BL_GAMESCOPE_FORCE_FULLSCREEN:-0} while :; do nap 1 want= From 387572e73331f8324689071cf0e96789d5a55249 Mon Sep 17 00:00:00 2001 From: Lobanokivan11 <59411324+Lobanokivan11@users.noreply.github.com> Date: Mon, 5 Oct 2026 20:09:24 +0300 Subject: [PATCH 3/3] merge bridge to main (second time) (#279) --- app/src/debug/AndroidManifest.xml | 19 ------------------- app/src/main/AndroidManifest.xml | 14 ++++++++++++++ .../launcher/agent/AgentBridgeProvider.kt | 0 .../launcher/agent/AgentStartActivity.kt | 0 4 files changed, 14 insertions(+), 19 deletions(-) delete mode 100644 app/src/debug/AndroidManifest.xml rename app/src/{debug => main}/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt (100%) rename app/src/{debug => main}/java/com/droiddeck/launcher/agent/AgentStartActivity.kt (100%) diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml deleted file mode 100644 index 70db082b20..0000000000 --- a/app/src/debug/AndroidManifest.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f07b62f300..5d6d85cf71 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -123,6 +123,14 @@ android:screenOrientation="sensorLandscape" android:theme="@style/AppTheme" /> + + + diff --git a/app/src/debug/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt similarity index 100% rename from app/src/debug/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt rename to app/src/main/java/com/droiddeck/launcher/agent/AgentBridgeProvider.kt diff --git a/app/src/debug/java/com/droiddeck/launcher/agent/AgentStartActivity.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentStartActivity.kt similarity index 100% rename from app/src/debug/java/com/droiddeck/launcher/agent/AgentStartActivity.kt rename to app/src/main/java/com/droiddeck/launcher/agent/AgentStartActivity.kt