mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-02 20:21:59 -05:00
* docs: research Android's child-process limit without developer options * docs: confirm the child-process gaps on the Thor * feat(session): start long-lived daemons in uncounted worker processes * feat(nativeguest): hand long-lived programs to uncounted worker processes * test(session): run the session bus block with dd_spawn * test(nativeguest): cover the exec handoff's wait and kill * feat(session): run the session root, its jobs and the gamescope chain outside the child-process count * feat(setup): the child-process limit no longer blocks Steam while the session runs in workers * feat(audio): run PulseAudio outside the child-process count * feat(nativeguest): hand off posix_spawn children and keep handed-off daemons alive * fix(nativeguest): let Steam end a handed-off game and keep process-group signals * perf(session): exec a worker as soon as its reply is in and keep two bound ahead; fix review findings * fix(nativeguest): address review findings in handoff waits, signals and spawn errors * fix(session): commit each worker launch explicitly and keep workers with the session that asked * fix(session): let a worker wait for its launch commit on the main thread * fix(session): confirm handoffs, honour wait selectors and stop spawns at teardown * fix(session): one owner per handoff exit, worker launch answers and spawn edge cases * fix(session): send a working directory outside the program's root by its real path * fix(session): recheck a taken exit's child and commit a launch only on a whole go line * fix(session): three-step launch, tagged exit reports and lock-free popen and system children * test(native): popen test shell is static, as the other hook fixtures * test(native): run the popen test program with a clean environment * test(native): skip the popen test where a spawn child cannot exec aarch64 * fix(session): confirm the hook before the worker runs, prefer a late report and free a reused pid * fix(session): tell a reused pid's old entry by start time, not the reaped flag * fix(session): silent failed launches, bounded spawn requests and held check-gone writes * test(native): check the unlisted child's status only where a child can exec aarch64 * fix(session): every exit-only waitid goes through the handoff wait * fix(handoff): exact waitid events, safe exit timer, bounded request receipt * feat(handoff): hand off shell children near Android's process limit * fix(agent): tag handed-off game windows outside the reaper * fix(handoff): a handed-off program's getppid() is its forking process * fix(handoff): exact waitid selection, kept Steam and pipe readers, held reports * fix(handoff): getppid() gives init for an exited or replaced parent * fix(handoff): keep __WALL waitid calls on the handoff path * test(handoff): require a zombie parent in the unreaped-parent case * fix(handoff): honor __WNOTHREAD and check every argument for Steam * fix(handoff): stop waiting on a held entry once its parent has exited * fix(handoff): __WNOTHREAD on waits for a pid, flags on every shim reap * fix(handoff): keep the forking thread of each child in the parent * fix(handoff): a wait that finds no child rechecks live handoffs * fix(handoff): keep a child's forking thread until its end is taken * fix(handoff): the thread selector applies to claims in progress too * fix(handoff): controlling-terminal check via /dev/tty, owned records only * fix(handoff): a child whose forking thread ended is any thread's * fix(handoff): a parent /proc cannot read is checked with kill(), then given up * fix(handoff): one-word fork records, changed only by compare-and-swap * fix(handoff): watch the forking parent through a pidfd opened at start * fix(handoff): fork records by pid, a gone thread's children go to the main one * fix(handoff): keep the parent pidfd through dup2 and check it before use * fix(handoff): no handoff without fork records, unknown thread state keeps the owner * fix(handoff): undo a pidfd move when dup fails, recheck it after the poll * fix(handoff): fresh fork records in a forked child, heir is the first live thread * fix(handoff): one lock over a pidfd move, its dup and the undo * fix(handoff): liveness check under the pidfd lock, forget only a reaped pid's record * fix(handoff): lock only dups onto the pidfd, with signals blocked * fix(handoff): fork record generations, no pidfd restore after a failed move * fix(handoff): every dup in a pidfd process locks, fork prep blocks signals * test(semaphores): tell a child hung in qemu-user from a guest deadlock * fix(handoff): fork records matched by the child's start time, never removed * test(semaphores): count only reaped children, only futex waits as emulator stalls * fix(handoff): a known-start bit in fork records * fix(handoff): dup bookkeeping before the pidfd lock, newer fork records kept * fix(handoff): a fork record stays only for the pid's current process * fix(handoff): keep a pending child's fork record when an older fork records late * fix(handoff): an unknown-start fork record never replaces a pending one * fix(handoff): self-recorded forks, ELF and wait option checks, both nofile limits * test(handoff): find the module in the namespace run under discover too * fix(handoff): a spare parent pidfd made at start, so a dup2 onto it makes no fd * test(handoff): require ENOEXEC for an ELF stub; skip the namespace run without binfmt * fix(hook): change the kept fd list under a sequence lock; readers take a copy * fix(handoff): one report per handed-off child; stops keep a claim; nested waits keep their selector * fix(hook): a table made at runtime outlives closes begun before it; unknown-start fork records kept * fix(handoff): waits look before they reap, so a handed-off fork's child is never reported * fix(hook): settle waits out earlier epochs; unknown-start fork records kept for any handoff under way * fix(handoff): generation-checked reap marks, stops taken as stops, close counts reset in a fork * fix(handoff): one given-up table at most, whole stop codes and rusage, WNOWAIT exits rechecked * fix(handoff): requests name their session; stops of handed-off programs reported; cancellable look * fix(handoff): table setup not cancellable; test spawner never runs what it cannot end * fix(handoff): job-control jobs stay counted; unnamed requests refused; cancel-safe setup * docs(phantom): job-control jobs stay counted; listed programs report no stops * fix(handoff): a listed program a shell runs as a job-control job stays counted * refactor(hook): kept descriptors in their own part, a handoff matched by another program The descriptors close(), close_range() and closefrom() leave open move from privileged.c to hook/kept.c (unchanged), so the bionic runtime's exec shim can build the handoff with them. ddh_try_as() matches DD_HANDOFF against one program and sends another: the bionic shim sends "/system/bin/linker64 PROGRAM ARGS" and lists it by PROGRAM. ddh_try() is ddh_try_as() with both the same. * feat(bionic): hand the bionic runtime's Wine programs to the app's workers The glibc session's hook never sees DroidDeck-Bionic's processes (Wine on Android's libc), so a bionic game's Wine programs all stayed counted under the worker running the tool's launch.sh. The handoff is now built into the runtime's exec shim (tools/bionic-runtime/handoff.c, part of libexecshim.so): - hook/handoff.c and hook/kept.c with what the native hook's other parts do around them: fork(), close(), close_range(), dup2(), dup3(), and exit() for the on_exit() bionic lacks - bionic's execv(), execvp(), execl*() reach the execve system call inside libc, past execshim's execve(); Wine starts its preloader with execv(), so the shim defines them on top of its execve() - a linker64 start is listed by its program - the app starts a handed-off program from the glibc root's bash, which cannot load the runtime's LD_PRELOAD/LD_LIBRARY_PATH: they go as arguments of /system/bin/env, which puts them back for the program - launch.sh keeps DD_SPAWN, DD_SPAWN_SESSION, DD_HANDOFF*, DDH_* and DDNATV_ROOT, and its /proc/N/environ reads no longer print "Permission denied" for idle workers (2>/dev/null before the redirect) Pocket FIT, DroidDeck-Bionic 14.1-r67 with this shim and launcher, handoff on: counted during Brawlhalla 25 -> 17, DiRT Showdown 24-27 -> 16, whole run 28 -> 19-20; with Android's limit on no DroidDeck process and no other app's process was killed (before: Discord, BatteryLog helpers); DiRT 75 fps either way. docs/phantom-processes.md: "The bionic runtime". * fix(bionic): hand off only starts that would succeed here; bionic's execvp fallbacks Review follow-ups on the bionic runtime's handoff (tools/bionic-runtime/handoff.c): - A start is handed to a worker only when it would get past execve() in this process: the file is a regular executable outside the app's data (Android refuses execve() there), and for a linker64 start the program it loads is a readable regular file. A start that failed in the worker failed where the caller could not see it, so Wine never tried its next candidate. The hook's own check looked at /system/bin/env, not the program. - A start whose argv[0] is not its file stays here: env starts FILE with FILE as argv[0]. linker64 and interpreter starts are unaffected (their argv[0] is the file). An empty argv stays here too. - Nothing is built for the handoff without DD_SPAWN and DD_HANDOFF. - execvp()/execvpe()/execlp() follow bionic's: an unset PATH is libc's default, an empty PATH or entry is the current directory, and a file the kernel cannot start (ENOEXEC) runs under /system/bin/sh. - close_range() refuses first > last and unknown flags before it splits the range or unshares the table. - The debug line reads the table's owner only once the table is seen published. * fix(bionic): hand off app-data starts only where SELinux lets them run; bare names stay here Follow-up to7d95564f7(review, and a Pocket FIT test of its pack): -7d95564f7kept every start of a file in the app's data here. Wine's preloader is one (a static ELF, so execshim.c cannot make it a linker64 start), and where SELinux is permissive, as on AYANEO's firmware, it runs: Wine then never reached its loader, and its programs ran here, counted again (Pocket FIT: Brawlhalla 26-28 counted vs 16-17 before). Where SELinux enforces, Android refuses the exec, here and in a worker alike, and Wine falls back to its loader, which goes as a linker64 start. Such a start is now handed off when /sys/fs/selinux/enforce reads 0, and stays here otherwise (also when the setting cannot be read). - The program a start would run is checked with the hook's own ddh_startable() (an ELF the kernel loads with its interpreter there, or a script with its interpreter): for a linker64 start, the program it loads. - A file name without '/' stays here: env would look it up in PATH, the exec here in the caller's working directory. - execvpe() skips a PATH entry whose candidate exceeds PATH_MAX (ENAMETOOLONG) instead of copying it onto the stack. * fix(handoff): spawn blocks signals and cancellation across the fork; root flag stored under the stop lock * fix(handoff): a thread that unshares its fd table keeps its own copy of the kept fds * fix(handoff): register the kept list's fork handlers before a split takes its lock * test(handoff): cover WNOHANG with a held forked child, early reaps, blocked waitid and pidfd parents; keep the counted-process exception in translations * test(handoff): exited-entry precondition, atomic checkpoints, a pidfd-only zombie check; validate the shim hold fd * test(handoff): WNOHANG with two handed-off children and for a group; a program's exit while its entry is held * test(handoff): a held exit with no free fd, with and without the parent's pidfd * test(handoff): held-exit tests require the program's own exit status * test(handoff): time held exits from the run, and only once the program is at its exit * perf(handoff): keep the asker's priority, quick tools local, workers bound ahead of a game (#3582) Three fixes that bring handoff-on speed to within 1-2 % of handoff off (AIO D3D11 same session: 3196 -> 3520 fps, 1 % low 444 -> 637) with the same counted processes (benchmark mean 18.5, peak 23): - A handed-off program keeps its asker's priority. Workers are bound from the top app with BIND_IMPORTANT, so Android boosts their main thread to THREAD_PRIORITY_TOP_APP_BOOST (-10); the program the worker execs inherited it. The asker's nice value is sent with the request and set before execve, and a watcher resets it if Android boosts it again. - Quick script tools (awk, sed, grep, cat, ...) stay where they are when the count is near the limit. Sent to a worker, the forked child waits (counted) while a worker starts; run locally it is counted for a few ms. - Workers are bound ahead when a Steam game is queued (16 for 20 s), so Wine's services do not wait on zygote forks at game start. --------- Co-authored-by: The412Banner <[email protected]> Co-authored-by: The412Banner <[email protected]>
472 lines
27 KiB
Bash
472 lines
27 KiB
Bash
#!/system/bin/sh
|
|
# DroidDeck-Bionic launcher, Android side. ../proton calls it: launch.sh <verb> <compatdata dir> <exe> [args...]
|
|
# Runs <exe> on the bionic Proton layer in ../files with the prefix <compatdata>/pfx, inside DroidDeck's
|
|
# gamescope session. Every program from app data starts through /system/bin/linker64 (targetSdk 29+ refuses
|
|
# execve of app data files); the runtime pack's execshim does the same for Wine's own starts.
|
|
verb=$1; COMPAT=$2; EXE=$3
|
|
shift 3
|
|
TOOL=$(cd "$(dirname "$0")/.." && pwd)
|
|
F=$TOOL/files
|
|
PACK=$F/runtime
|
|
ROOTFS=${DROIDDECK_BIONIC_ROOT:?started without DROIDDECK_BIONIC_ROOT}
|
|
APP=${ROOTFS%/linuxfs}
|
|
LINKER=/system/bin/linker64
|
|
VERSION=$(awk '{print $2}' "$TOOL/version" 2>/dev/null)
|
|
LOGS=${DROIDDECK_BIONIC_LOGS:-}
|
|
|
|
mkdir -p "$COMPAT"
|
|
LOG=$COMPAT/droiddeck-bionic.log
|
|
[ "$verb" = runinprefix ] || { [ -f "$LOG" ] && mv -f "$LOG" "$LOG.1"; }
|
|
# A game's log is written into DroidDeck's session folder (../proton names it), which Share logs takes only as a
|
|
# file with one name; the usual name here points to it, and dangles once that session's folder is removed.
|
|
[ -L "$LOG" ] && [ ! -e "$LOG" ] && rm -f "$LOG"
|
|
if [ -n "$LOGS" ] && [ ! -e "$LOG" ] && mkdir -p "$LOGS" 2>/dev/null && : >> "$LOGS/droiddeck-bionic.log" 2>/dev/null; then
|
|
ln -s "$LOGS/droiddeck-bionic.log" "$LOG" 2>/dev/null
|
|
fi
|
|
exec >> "$LOG" 2>&1
|
|
echo "$(date +%H:%M:%S) $verb $EXE ($VERSION, uid $(id -u), DISPLAY ${DISPLAY:-unset})"
|
|
|
|
# Keep Steam's game identity, DroidDeck's input/display/driver/sync settings and its game environment (the names
|
|
# ../proton lists in DROIDDECK_BIONIC_KEEP); drop the rest of the glibc guest's environment.
|
|
KEEP=" ${DROIDDECK_BIONIC_KEEP:-} "
|
|
# The built-in DirectAudio driver reads DroidDeck's AUDIO_DIRECT_* settings (the microphone switch among them) under
|
|
# the BANNER_ names droiddeck-proton gives them for Proton.
|
|
for v in $(env | sed -n 's/^\(AUDIO_DIRECT_[A-Za-z0-9_]*\)=.*/\1/p'); do
|
|
eval "export BANNER_$v=\"\$$v\""
|
|
done
|
|
for v in $(env | sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p'); do
|
|
case "$KEEP" in *" $v "*) continue ;; esac
|
|
case "$v" in
|
|
SteamAppId|SteamGameId|SteamOverlayGameId|SteamClientLaunch|SteamEnv|SteamAppUser|SteamUser|STEAM_COMPAT_*) ;;
|
|
ANDROID_*|BOOTCLASSPATH|DEX2OATBOOTCLASSPATH|SYSTEMSERVERCLASSPATH|EXTERNAL_STORAGE|ASEC_MOUNTPOINT) ;;
|
|
FAKE_*|SDL_*|DD_WIDTH|DD_HEIGHT|DD_VK_DRIVER|WINEDLLOVERRIDES) ;;
|
|
DISPLAY|GAMESCOPE_WAYLAND_DISPLAY|FEX_*) ;;
|
|
TU_DEBUG|MESA_NO_ERROR|DXVK_CONFIG|DXVK_HUD|DROIDDECK_FORCE_SSBS|BANNER_AUDIO_DIRECT_*) ;;
|
|
mesa_glthread|vblank_mode|ZINK_*|GALLIUM_HUD|GALLIUM_THREAD) ;;
|
|
DD_SYNC|DD_FSYNC_FIRST|DD_SYNC_FALLBACK|PROTON_NO_ESYNC|PROTON_NO_FSYNC|PROTON_NO_NTSYNC|WINEESYNC) ;;
|
|
PROTON_USE_D7VK) ;;
|
|
XODUS_*|RUST_LOG) ;;
|
|
WINE_OFFSCREEN_CHECK_MS|WINE_CPU_TOPOLOGY|WINE_LARGE_ADDRESS_AWARE|WINESTEAMNOEXEC|TZ) ;;
|
|
DXVK_LOG_LEVEL|DXVK_HDR|VKD3D_DEBUG|VKD3D_SHADER_DEBUG) ;;
|
|
DXVK_LOG_PATH|VKD3D_LOG_FILE|MESA_LOG_FILE) ;;
|
|
DROIDDECK_GPU_LOAD|DROIDDECK_GPU_LOAD_DIR|DROIDDECK_VRAM_CAP|DROIDDECK_VRAM_CAP_MB|DROIDDECK_DISPLAY_DRIVER) ;;
|
|
DROIDDECK_GUEST_ROOT) ;;
|
|
VKD3D_FEATURE_LEVEL|VKD3D_SHADER_MODEL|vk_x11_strict_image_count) ;;
|
|
# The exec handoff (../handoff.c): the app's spawn socket and list (the app starts a handed-off program from the
|
|
# glibc root's shell, so its path too), and what a worker hands the program it runs (this script, when it runs
|
|
# in one): the first Wine process's hook knows the worker's binder fds are not its own.
|
|
DD_SPAWN|DD_SPAWN_SESSION|DD_HANDOFF|DD_HANDOFF_DEBUG|DD_HANDOFF_PRESSURE|DDH_*|DDNATV_ROOT) ;;
|
|
*) unset "$v" 2>/dev/null ;;
|
|
esac
|
|
done
|
|
export PATH=/system/bin:/system/xbin
|
|
# DISPLAY: the X server Steam gives games. DroidDeck's gamescope runs two (Steam's UI on :0, games on
|
|
# STEAM_GAME_DISPLAY_0), so Steam's menus do not take X focus from the game.
|
|
export HOME=$COMPAT WINEPREFIX=$COMPAT/pfx TMPDIR=$ROOTFS/tmp LANG=en_US.UTF-8 DISPLAY=${DISPLAY:-:0}
|
|
# Proton's user name: the same C:\users\steamuser (saves, settings) as DroidDeck-Proton in a shared prefix
|
|
export USER=steamuser LOGNAME=steamuser
|
|
|
|
# Graphics: DroidDeck's chosen Turnip (its Android half) through Bannerlator's Wayland adapter, and gamescope's
|
|
# WSI layer handing the swapchain to gamescope (zero copy).
|
|
drvlib() { # an Android driver folder's library: meta.json's libraryName, else libvulkan_freedreno.so
|
|
l=$(sed -n 's/.*"libraryName"[[:space:]]*:[[:space:]]*"\([^"/]*\)".*/\1/p' "$1/meta.json" 2>/dev/null | head -1)
|
|
echo "${l:-libvulkan_freedreno.so}"
|
|
}
|
|
DRV=$(basename "$(dirname "${DD_VK_DRIVER:-/x/none/icd.json}")")
|
|
DRVDIR=$APP/graphics_driver/$DRV
|
|
if [ ! -f "$DRVDIR/$(drvlib "$DRVDIR")" ]; then
|
|
# The runtime driver has no Android build: the one DroidDeck's display uses, else the first one installed.
|
|
DRVDIR=
|
|
if [ -n "${DROIDDECK_DISPLAY_DRIVER:-}" ] && [ "${DROIDDECK_DISPLAY_DRIVER#*/}" = "$DROIDDECK_DISPLAY_DRIVER" ] && \
|
|
[ -f "$APP/graphics_driver/$DROIDDECK_DISPLAY_DRIVER/$(drvlib "$APP/graphics_driver/$DROIDDECK_DISPLAY_DRIVER")" ]; then
|
|
DRVDIR=$APP/graphics_driver/$DROIDDECK_DISPLAY_DRIVER
|
|
else
|
|
for d in "$APP"/graphics_driver/*/; do [ -f "$d$(drvlib "${d%/}")" ] && { DRVDIR=${d%/}; break; }; done
|
|
fi
|
|
echo "driver $DRV has no Android build; using ${DRVDIR:+$(basename "$DRVDIR")}${DRVDIR:-none} (display driver ${DROIDDECK_DISPLAY_DRIVER:-unknown})"
|
|
fi
|
|
echo "driver $DRVDIR"
|
|
RTD=$APP/.wayland-rt
|
|
export VK_ICD_FILENAMES=$PACK/adapter/icd.json ADRENOTOOLS_DRIVER_PATH=$DRVDIR/ ADRENOTOOLS_HOOKS_PATH=$PACK/lib
|
|
export ADRENOTOOLS_DRIVER_NAME=$(drvlib "$DRVDIR")
|
|
export VK_ADD_IMPLICIT_LAYER_PATH=$PACK/layer ENABLE_GAMESCOPE_WSI=1 GAMESCOPE_WAYLAND_DISPLAY=${GAMESCOPE_WAYLAND_DISPLAY:-gamescope-0}
|
|
export XDG_RUNTIME_DIR=$RTD DROIDDECK_WSI_BYPASS_CHECK_MS=100 GAMESCOPE_WSI_FORCE_BYPASS=0
|
|
echo "WSI forced XWayland bypass disabled (GAMESCOPE_WSI_FORCE_BYPASS=$GAMESCOPE_WSI_FORCE_BYPASS)"
|
|
[ -e "$RTD/droiddeck-gamescope-limiter" ] && export GAMESCOPE_LIMITER_FILE=$RTD/droiddeck-gamescope-limiter
|
|
|
|
# Wine: DXVK/VKD3D over the builtins, X11 inside gamescope (winewayland would pick DroidDeck's compositor),
|
|
# FEX for x86 code, userspace ntsync (no /dev/ntsync on Android), Valve's Android Steam client library.
|
|
export WINEDLLOVERRIDES="${WINEDLLOVERRIDES:+$WINEDLLOVERRIDES;}d3d8,d3d9,d3d10core,d3d11,dxgi,d3d12,d3d12core=n,b;winewayland.drv=d"
|
|
# Sync as chosen in DroidDeck (Wine sync, per-game PROTON_NO_*): ntsync is userspace ntsync (no /dev/ntsync on
|
|
# Android) with esync as its fallback; Android has no futex_waitv, so an fsync choice runs ntsync.
|
|
on() { case "$1" in 1|on|true|yes) return 0 ;; esac; return 1; }
|
|
NT=1; ES=1
|
|
[ "${DD_SYNC:-1}" = 0 ] && NT=0
|
|
[ "${DD_FSYNC_FIRST:-0}" = 1 ] && NT=1
|
|
[ "${DD_SYNC:-1}" = 0 ] && [ "${DD_SYNC_FALLBACK:-1}" = 0 ] && ES=0
|
|
on "${PROTON_NO_NTSYNC:-}" && NT=0
|
|
{ on "${PROTON_NO_ESYNC:-}" || [ "${WINEESYNC:-}" = 0 ]; } && ES=0
|
|
export WINENTSYNC=$NT WINEESYNC=$ES
|
|
# Userspace ntsync keeps its state in one file. Per prefix, not in the shared TMPDIR (DroidDeck-Proton's ntsync
|
|
# uses that too), and cleared before Wine starts in this prefix: a process killed while it held the file's lock
|
|
# leaves it held, and every later start in that prefix hangs at its first ntsync wait.
|
|
export NTSYNC_SHM=$COMPAT/ntsync-shm
|
|
# DroidDeck's Force SSBS (its glibc libssbs.so preload) is bionic Wine's own WINE_FORCE_SSBS
|
|
on "${DROIDDECK_FORCE_SSBS:-}" && export WINE_FORCE_SSBS=1
|
|
export HODLL=libwow64fex.dll WINEDEBUG=err+all,fixme-all
|
|
# The network adapter list (GetAdaptersAddresses) from the layer's getifaddrs code: its default if_nameindex code never
|
|
# answered here, and the Paradox Launcher (Europa Universalis IV) waited on it forever.
|
|
export WINE_NEW_NDIS=${WINE_NEW_NDIS:-1}
|
|
export XENVIRONMENT=$TOOL/bionic/Xdefaults
|
|
# The adapter's Wayland swapchain gets its buffers back from gamescope later than DroidDeck-Proton's Turnip does;
|
|
# with gamescope's default three images the game waits for one about a fifth of the time at high frame rates.
|
|
# droiddeck-game-env's fix for a game that needs its own image count sets vk_x11_strict_image_count instead.
|
|
case "${vk_x11_strict_image_count:-}" in
|
|
true|1) ;;
|
|
*) export GAMESCOPE_WSI_MIN_IMAGE_COUNT=${GAMESCOPE_WSI_MIN_IMAGE_COUNT:-4} GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT=${GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT:-1} ;;
|
|
esac
|
|
# FEX: DroidDeck-Proton's defaults (its share/fex-emu/Config.json: x87 in 64-bit precision, TSO without the vector
|
|
# and memcpy parts); droiddeck-game-env's per-game choices (FEX_* in the environment, e.g. .NET, Unity) win.
|
|
export FEX_TSOENABLED=${FEX_TSOENABLED:-1} FEX_VECTORTSOENABLED=${FEX_VECTORTSOENABLED:-0} \
|
|
FEX_MEMCPYSETTSOENABLED=${FEX_MEMCPYSETTSOENABLED:-0} FEX_HALFBARRIERTSOENABLED=${FEX_HALFBARRIERTSOENABLED:-1} \
|
|
FEX_X87REDUCEDPRECISION=${FEX_X87REDUCEDPRECISION:-1} FEX_MULTIBLOCK=${FEX_MULTIBLOCK:-1} FEX_MAXINST=${FEX_MAXINST:-500} FEX_DISKCACHE=${FEX_DISKCACHE:-1}
|
|
echo "fex $(env | grep '^FEX_' | sort | tr '\n' ' ')"
|
|
echo "sync ntsync=$WINENTSYNC esync=$WINEESYNC ssbs=${WINE_FORCE_SSBS:-0} tu_debug=${TU_DEBUG:-} kept=$(echo $KEEP)"
|
|
export WINESTEAMCLIENTPATH64=$ROOTFS/root/.local/share/Steam/androidarm64/libsteamclient.so
|
|
# The layer sends a game's steamclient(64).dll to lsteamclient (and so to DroidDeck's Steam through the library
|
|
# above) only with WINE_LSTEAMCLIENT set; without it Valve's Windows steamclient runs alone and SteamAPI_Init fails.
|
|
export WINE_LSTEAMCLIENT=${WINE_LSTEAMCLIENT:-1}
|
|
# Steam Input data (Valve's Steam Deck layouts with game actions) lives in DroidDeck's /dev/shm; libsteamshm.so
|
|
# points the Android library's shared memory there (it keeps its own in-process otherwise) and gives it the
|
|
# sem_open Android lacks (without it the game hangs once that data arrives).
|
|
export DROIDDECK_BIONIC_SHM_DIR=${APP%/files}/no_backup/guest-runtime/shm
|
|
export DXVK_LOG_PATH=${DXVK_LOG_PATH:-$COMPAT} PULSE_SERVER=unix:$APP/pulseaudio/PS0
|
|
export ANDROID_SYSVSHM_SERVER=$COMPAT/.no-sysvshm-server # its client faults on an unset name, inside a Wine lock
|
|
|
|
# The pack's imagefs libraries carry Winlator's prefix for plugins and X11 data. No FONTCONFIG_*: with the
|
|
# imagefs fonts.conf (Android's /system/fonts) DiRT Showdown quit right after start.
|
|
export GST_PLUGIN_SYSTEM_PATH=$PACK/lib/gstreamer-1.0 GST_REGISTRY=$COMPAT/gst-registry.bin GST_REGISTRY_FORK=no
|
|
export XLOCALEDIR=$PACK/share/X11/locale XKB_CONFIG_ROOT=$PACK/share/X11/xkb
|
|
export SSL_CERT_FILE=$PACK/etc/tls/cert.pem SSL_CERT_DIR=$PACK/etc/tls/certs OPENSSL_CONF=$PACK/etc/tls/openssl.cnf
|
|
export WINE_ADDITIONAL_CERTS_DIR=$PACK/etc/tls/cert.pem
|
|
|
|
# Controller: the bionic winebus has no udev bus, so Steam's virtual pad is shown to it as an Xbox 360 pad;
|
|
# Steam's ignore list names that id because of the built-in pad, which Wine does not see here.
|
|
export FAKE_EVDEV_STEAM_PAD_AS_X360=1
|
|
export SDL_GAMECONTROLLER_IGNORE_DEVICES="$(echo "${SDL_GAMECONTROLLER_IGNORE_DEVICES:-}" | sed -e 's#0x045e/0x028e,##' -e 's#,0x045e/0x028e$##')"
|
|
|
|
# OpenGL, and WineD3D on it (DirectDraw, Direct3D 1-8 without DXVK): Mesa's Zink on Vulkan through winex11's EGL
|
|
# backend (the runtime's egl/), the way Bannerlator's Fast OpenGL runs it; DroidDeck's GL settings above are kept.
|
|
export WINE_USE_EGL=1 WINE_X11FORCEGLX=1 GALLIUM_DRIVER=zink MESA_LOADER_DRIVER_OVERRIDE=zink LIBGL_KOPPER_DRI2=1
|
|
export ZINK_DESCRIPTORS=${ZINK_DESCRIPTORS:-lazy} ZINK_DEBUG=${ZINK_DEBUG:-compact} vblank_mode=${vblank_mode:-0}
|
|
# Gallium's threaded context off, as in Bannerlator's Fast OpenGL: with it, WineD3D (DirectDraw / Direct3D 1-7)
|
|
# crashed in native code within seconds (AIO Direct3D 7, SIGSEGV).
|
|
export GALLIUM_THREAD=${GALLIUM_THREAD:-0}
|
|
# Mesa's GL thread off unless the game's own DroidDeck environment sets it: with DroidDeck's session-wide
|
|
# mesa_glthread=true, WineD3D's persistent buffer writes lost vertex colours on this Mesa build (AIO 64-bit
|
|
# Direct3D 7 drew its cube white; DroidDeck-Proton's Mesa does not do this).
|
|
case "$KEEP" in *" mesa_glthread "*) ;; *) export mesa_glthread=false ;; esac
|
|
|
|
# egl/ first: the layer's own lib/ carries a Wayland-only Mesa EGL of the same names, which winex11 cannot use
|
|
LIBS=$PACK/egl:$F/lib:$PACK/lib:/system/lib64
|
|
PRELOAD=$PACK/preload/libexecshim.so:$PACK/preload/libnotag.so:$PACK/preload/libfakeinput.so:$PACK/preload/libsteamshm.so
|
|
wine_() { LD_LIBRARY_PATH=$LIBS LD_PRELOAD=$PRELOAD "$LINKER" "$F/lib/wine/aarch64-unix/wine" "$@"; }
|
|
wineserver_() { LD_LIBRARY_PATH=$LIBS LD_PRELOAD=$PRELOAD "$LINKER" "$F/bin/wineserver" "$@"; }
|
|
|
|
is_builtin() { head -c 128 "$1" 2>/dev/null | grep -q "Wine builtin DLL"; }
|
|
# Names wine.inf has Wine's update delete from system32 (section FakeDlls) or syswow64 (FakeDllsWow64), "11,,name,-":
|
|
# in Windows they live only under Microsoft.NET or winsxs. Wine deletes through a link, so a link there cost this
|
|
# tool its own fusion.dll, ngen.exe, comctl32_v6.dll and the rest, and later prefixes their .NET stubs and comctl32 v6.
|
|
inf_drops() {
|
|
awk -v s="[$1]" '/^\[/ { h = $0; sub(/[ \t\r]+$/, "", h); on = (h == s); next }
|
|
on && /^11,,[^,]+,-[ \t\r]*$/ { split($0, a, ","); print a[3] }' "$F/share/wine/wine.inf" 2>/dev/null
|
|
}
|
|
dropped() { # name patterns
|
|
set -f
|
|
for p in $2; do case "$1" in $p) set +f; return 0 ;; esac; done
|
|
set +f; return 1
|
|
}
|
|
link_dir() { # src dst [names]: links every file of src into dst; replaces links and Wine builtin copies, keeps native
|
|
# DLLs; names (wine.inf patterns) are not linked and a link left under one is removed
|
|
[ -d "$1" ] || return 0
|
|
for f in "$1"/*; do
|
|
[ -f "$f" ] || continue
|
|
t=$2/${f##*/}
|
|
if [ -n "${3:-}" ] && dropped "${f##*/}" "$3"; then
|
|
[ -L "$t" ] && rm -f "$t"
|
|
continue
|
|
fi
|
|
if [ -L "$t" ]; then
|
|
[ "$(readlink "$t")" = "$f" ] && continue
|
|
rm -f "$t"
|
|
elif [ -e "$t" ]; then
|
|
is_builtin "$t" || continue
|
|
rm -f "$t"
|
|
fi
|
|
ln -s "$f" "$t"
|
|
done
|
|
}
|
|
winpath() { echo "Z:$1" | sed 's#/#\\#g'; }
|
|
|
|
# The prefix carries this tool's builtins when it was last set up by this version; another Proton (or an
|
|
# older DroidDeck-Bionic) leaves its own links there, and the compatdata version file tells DroidDeck-Proton
|
|
# to relink when it runs this prefix again.
|
|
# Drive Z: is the whole device for this tool: winpath, getcompatpath and the Xbox paths name Android paths on Z:.
|
|
# Proton copies a prefix's links as relative ones, and DroidDeck-Proton's relative z: reaches only the Linux userland
|
|
# here, so a game outside it (SD card, shared storage) was on no drive and Wine crashed on its path at start.
|
|
# DroidDeck-Proton follows z: -> / in the guest's view, with proot and without.
|
|
drive_z() {
|
|
z=$1/dosdevices/z:
|
|
[ -d "$1/dosdevices" ] || return 0
|
|
[ -L "$z" ] || { [ -e "$z" ] && return 0; }
|
|
old=$(readlink "$z" 2>/dev/null)
|
|
[ "$old" = / ] && return 0
|
|
rm -f "$z" && ln -s / "$z" && echo "$(date +%H:%M:%S) drive z: -> / (was ${old:-missing})"
|
|
}
|
|
|
|
prepare_prefix() {
|
|
P=$COMPAT/pfx
|
|
drive_z "$P"
|
|
if [ -f "$P/.droiddeck-bionic" ] && [ "$(cat "$P/.droiddeck-bionic")" = "$VERSION" ] && \
|
|
[ "$(cat "$COMPAT/version" 2>/dev/null)" = "$VERSION" ]; then return 0; fi
|
|
if [ ! -f "$P/system.reg" ]; then
|
|
echo "$(date +%H:%M:%S) new prefix from the layer's template"
|
|
mkdir -p "$P" && cp -a "$F/default_pfx/." "$P/"
|
|
fi
|
|
W=$P/drive_c/windows
|
|
mkdir -p "$W/system32" "$W/syswow64" "$P/dosdevices"
|
|
echo "$(date +%H:%M:%S) linking builtins"
|
|
link_dir "$F/lib/wine/aarch64-windows" "$W/system32" "$(inf_drops FakeDlls)"
|
|
link_dir "$F/lib/wine/i386-windows" "$W/syswow64" "$(inf_drops FakeDllsWow64)"
|
|
for c in dxvk vkd3d-proton; do
|
|
link_dir "$F/lib/wine/$c/aarch64-windows" "$W/system32"
|
|
link_dir "$F/lib/wine/$c/i386-windows" "$W/syswow64"
|
|
done
|
|
# This layer's Wine always uses the profile C:\users\xuser, Proton's is C:\users\steamuser: one links to the
|
|
# other so saves and settings are the same whichever tool runs the game.
|
|
U=$P/drive_c/users
|
|
if [ -d "$U/steamuser" ] && [ ! -e "$U/xuser" ]; then ln -s steamuser "$U/xuser"
|
|
elif [ -d "$U/xuser" ] && [ ! -L "$U/xuser" ] && [ ! -e "$U/steamuser" ]; then ln -s xuser "$U/steamuser"; fi
|
|
[ -e "$P/dosdevices/c:" ] || ln -s ../drive_c "$P/dosdevices/c:"
|
|
[ -e "$P/dosdevices/z:" ] || ln -s / "$P/dosdevices/z:"
|
|
wine_ regedit /S "$(winpath "$TOOL/bionic/desktop.reg")"
|
|
wineserver_ -w
|
|
echo "$VERSION" > "$P/.droiddeck-bionic"
|
|
echo "$VERSION" > "$COMPAT/version"
|
|
# Proton (DroidDeck-Proton, GE, ...) reads tracked_files when it takes this prefix over; one this tool made has
|
|
# none. The version above is not a Proton prefix version, so Proton updates the prefix and never treats it as
|
|
# one from a newer Proton (which would delete its tracked files).
|
|
[ -e "$COMPAT/tracked_files" ] || : > "$COMPAT/tracked_files"
|
|
echo "$(date +%H:%M:%S) prefix ready"
|
|
}
|
|
|
|
prefix_busy() { # a process of this prefix is running
|
|
for p in /proc/[0-9]*; do
|
|
[ "${p#/proc/}" = "$$" ] && continue
|
|
tr '\0' '\n' 2>/dev/null < "$p/environ" | grep -qx "WINEPREFIX=$COMPAT/pfx" && return 0
|
|
done
|
|
return 1
|
|
}
|
|
|
|
programs_left() { # a program of this prefix is still running, apart from Wine's own services and this script's helpers
|
|
for p in /proc/[0-9]*; do
|
|
q=${p#/proc/}
|
|
[ -O "$p" ] || continue
|
|
[ "$q" = "$$" ] || [ "$q" = "${GT:-x}" ] && continue
|
|
c=; read -r c < "$p/comm" 2>/dev/null
|
|
case "$c" in
|
|
""|wineserver|services.exe|winedevice.exe|plugplay.exe|explorer.exe|svchost.exe|rpcss.exe|conhost.exe|start.exe|\
|
|
winemenubuilder|wineboot.exe|tabtip.exe) continue ;;
|
|
esac
|
|
tr '\0' '\n' 2>/dev/null < "$p/environ" | grep -qx "WINEPREFIX=$COMPAT/pfx" && return 0
|
|
done
|
|
return 1
|
|
}
|
|
|
|
stop_wine() { # wineserver -k, then whatever of this prefix is left (e.g. a game's crash reporter)
|
|
wineserver_ -k 2>/dev/null
|
|
sleep 1
|
|
for p in /proc/[0-9]*; do
|
|
tr '\0' '\n' 2>/dev/null < "$p/environ" | grep -qx "WINEPREFIX=$COMPAT/pfx" || continue
|
|
[ "${p#/proc/}" = "$$" ] && continue
|
|
echo "$(date +%H:%M:%S) left over: ${p#/proc/} $(cat "$p/comm" 2>/dev/null)"
|
|
kill -9 "${p#/proc/}" 2>/dev/null
|
|
done
|
|
}
|
|
|
|
# A FEX from DroidDeck's components runs here only as an Android build (its unix libraries link Android's libc).
|
|
# Missing or glibc unix libraries (an older app put its glibc FEX here): put the tool's own FEX back.
|
|
fex_ok=1
|
|
for f in aarch64-unix/libwow64fex.so aarch64-unix/libarm64ecfex.so; do
|
|
if [ ! -f "$F/lib/wine/$f" ] || grep -q "ld-linux-aarch64" "$F/lib/wine/$f"; then fex_ok=0; fi
|
|
done
|
|
if [ $fex_ok = 0 ]; then
|
|
for f in aarch64-unix/libwow64fex.so aarch64-unix/libarm64ecfex.so aarch64-windows/libwow64fex.dll aarch64-windows/libarm64ecfex.dll; do
|
|
[ -f "$PACK/fex/$f" ] || continue
|
|
cmp -s "$PACK/fex/$f" "$F/lib/wine/$f" || { cat "$PACK/fex/$f" > "$F/lib/wine/$f" && echo "$(date +%H:%M:%S) restored the tool's FEX $f"; }
|
|
done
|
|
fi
|
|
echo "fex build: $(grep -a -o -m1 'FEX-[0-9][0-9.]*[0-9A-Za-z.+-]*' "$F/lib/wine/aarch64-windows/libarm64ecfex.dll" | head -1)"
|
|
|
|
if [ "$verb" != runinprefix ] && prefix_busy; then
|
|
echo "$(date +%H:%M:%S) Wine left running in this prefix; stopping it"
|
|
stop_wine
|
|
fi
|
|
prefix_busy || rm -f "$NTSYNC_SHM".v*
|
|
|
|
# Steam's running client, as a game's steam_api checks it: Proton names its steam.exe (the prefix's first program,
|
|
# alive while the game runs), which this tool does not start. Here the first program is the one Steam started, so a
|
|
# launcher that starts the game and quits (EU4's dowser.exe) left a game that reported "Steam not detected". The
|
|
# PID is the one this tool's own prefixes carry.
|
|
steam_pid() {
|
|
R=$COMPAT/pfx/user.reg
|
|
[ -f "$R" ] || return 0
|
|
awk '/^\[/ { on = index($0, "[Software\\\\Valve\\\\Steam\\\\ActiveProcess]") == 1 }
|
|
on && /^"PID"=dword:/ && $0 != "\"PID\"=dword:0000fffe" { found = 1 } END { exit !found }' "$R" || return 0
|
|
awk '/^\[/ { on = index($0, "[Software\\\\Valve\\\\Steam\\\\ActiveProcess]") == 1 }
|
|
on && /^"PID"=dword:/ { print "\"PID\"=dword:0000fffe"; next } { print }' "$R" > "$R.dd-new.$$" && mv -f "$R.dd-new.$$" "$R" &&
|
|
echo "$(date +%H:%M:%S) Steam's process ID in the registry set to this tool's"
|
|
}
|
|
prefix_busy || steam_pid
|
|
|
|
# Links into a tool that is gone (an older DroidDeck-Bionic, a deleted DroidDeck-Proton) or to a file it no longer has.
|
|
# Wine's update cannot write over them, so drivers (network, controller) and other files stay missing. Drop them and
|
|
# clear both stamps: prepare_prefix relinks this tool's files and Wine's update puts its own back.
|
|
dead=0
|
|
for d in system32 syswow64 system32/drivers Fonts; do
|
|
for f in "$COMPAT/pfx/drive_c/windows/$d"/*; do
|
|
[ -L "$f" ] && [ ! -e "$f" ] && rm -f "$f" && dead=$((dead + 1))
|
|
done
|
|
done
|
|
if [ $dead -gt 0 ]; then
|
|
rm -f "$COMPAT/pfx/.update-timestamp" "$COMPAT/pfx/.droiddeck-bionic"
|
|
echo "$(date +%H:%M:%S) removed $dead dead link(s) from the prefix; relinking and Wine's update follow"
|
|
fi
|
|
|
|
prepare_prefix
|
|
|
|
# FEX keeps translated code per program in the prefix (AppData/Local/fex-emu/DiskCache) and reuses it with whatever FEX
|
|
# runs the prefix next. Code cached by another FEX build (DroidDeck-Proton's, or a different FEX picked in the
|
|
# Components tab) made this FEX crash in Steam's install-script step, and Wine then looped on the crash, so Steam never
|
|
# started the game. The cache is cleared when the FEX that runs the prefix is not the one that filled it.
|
|
# The stamp holds this FEX's ID and what the caches held when this tool last finished with the prefix, so a cache that
|
|
# another FEX wrote to since (DroidDeck-Proton running the same game) is cleared too.
|
|
fexid=$(cat "$F/lib/wine/aarch64-windows/libarm64ecfex.dll" "$F/lib/wine/aarch64-windows/libwow64fex.dll" \
|
|
"$F/lib/wine/aarch64-unix/libarm64ecfex.so" "$F/lib/wine/aarch64-unix/libwow64fex.so" 2>/dev/null | md5sum | cut -c1-16)
|
|
fex_cache_sum() { # names, sizes and times of the files in the prefix's FEX code caches
|
|
for u in "$COMPAT/pfx/drive_c/users"/*; do
|
|
[ -L "$u" ] && continue
|
|
c=$u/AppData/Local/fex-emu/DiskCache
|
|
[ -d "$c" ] && find "$c" -type f -exec stat -c '%n %s %Y' {} + 2>/dev/null
|
|
done | sort | md5sum | cut -c1-16
|
|
}
|
|
save_fex_stamp() { echo "$fexid $(fex_cache_sum)" > "$COMPAT/pfx/.droiddeck-fex-cache" 2>/dev/null; }
|
|
if [ "$(cat "$COMPAT/pfx/.droiddeck-fex-cache" 2>/dev/null)" != "$fexid $(fex_cache_sum)" ]; then
|
|
for u in "$COMPAT/pfx/drive_c/users"/*; do
|
|
c=$u/AppData/Local/fex-emu/DiskCache
|
|
[ -L "$u" ] || [ ! -d "$c" ] && continue
|
|
rm -rf "$c" && echo "$(date +%H:%M:%S) FEX code cache of ${u##*/} cleared (another FEX build wrote to it, or it is unknown)"
|
|
done
|
|
save_fex_stamp
|
|
fi
|
|
|
|
# Steam's Windows client files in the prefix, the ones Proton copies from Steam's legacycompat folder: a game's
|
|
# steam_api loads C:\Program Files (x86)\Steam\steamclient64.dll, and a prefix this tool made has none.
|
|
SC=$ROOTFS/root/.local/share/Steam/legacycompat
|
|
D="$COMPAT/pfx/drive_c/Program Files (x86)/Steam"
|
|
if [ -d "$SC" ]; then
|
|
mkdir -p "$D"
|
|
for c in steamclient.dll:steamclient.dll steamclient64.dll:steamclient64.dll GameOverlayRenderer64.dll:GameOverlayRenderer64.dll \
|
|
SteamService.exe:steam.exe Steam.dll:Steam.dll; do
|
|
s=$SC/${c%%:*}; d=$D/${c#*:}
|
|
[ -f "$s" ] || continue
|
|
[ -f "$d" ] && [ ! "$s" -nt "$d" ] && continue
|
|
cp "$s" "$d.new" && mv -f "$d.new" "$d" && touch -r "$s" "$d" && echo "$(date +%H:%M:%S) Steam client file ${c#*:}"
|
|
done
|
|
fi
|
|
|
|
# DXVK and VKD3D-Proton: the prefix uses this tool's files, where DroidDeck puts its component choices. Another Proton
|
|
# that ran this prefix left its own copies, which link_dir keeps as native DLLs. A name the tool's DXVK does not ship
|
|
# (d3d10.dll, d3d10_1.dll) goes back to Wine's own.
|
|
for a in aarch64-windows:system32 i386-windows:syswow64; do
|
|
arch=${a%%:*}; W=$COMPAT/pfx/drive_c/windows/${a#*:}
|
|
[ -d "$W" ] || continue
|
|
for n in d3d8 d3d9 d3d10 d3d10_1 d3d10core d3d11 dxgi d3d12 d3d12core; do
|
|
s=$F/lib/wine/dxvk/$arch/$n.dll
|
|
[ -f "$s" ] || s=$F/lib/wine/vkd3d-proton/$arch/$n.dll
|
|
[ -f "$s" ] || s=$F/lib/wine/$arch/$n.dll
|
|
[ -f "$s" ] || continue
|
|
t=$W/$n.dll
|
|
[ -L "$t" ] && [ "$(readlink "$t")" = "$s" ] && continue
|
|
rm -f "$t" && ln -s "$s" "$t" && echo "$(date +%H:%M:%S) ${a#*:}/$n.dll -> ${s#$F/lib/wine/}"
|
|
done
|
|
done
|
|
|
|
# D7VK (Direct3D 7 and older on Vulkan) for 32-bit games when PROTON_USE_D7VK is set and not 0, as DroidDeck-Proton:
|
|
# its ddraw.dll in syswow64 with Wine's own beside it as ddraw_.dll. Switched off, Wine's link goes back. Only the
|
|
# links in the prefix are removed, never the files they point to.
|
|
S=$COMPAT/pfx/drive_c/windows/syswow64
|
|
if [ -n "${PROTON_USE_D7VK:-}" ] && [ "$PROTON_USE_D7VK" != 0 ] && [ -f "$PACK/d7vk/ddraw.dll" ]; then
|
|
rm -f "$S/ddraw.dll" "$S/ddraw_.dll"
|
|
ln -s "$PACK/d7vk/ddraw.dll" "$S/ddraw.dll" && ln -s "$F/lib/wine/i386-windows/ddraw.dll" "$S/ddraw_.dll"
|
|
export WINEDLLOVERRIDES="$WINEDLLOVERRIDES;ddraw=n,b"
|
|
echo "$(date +%H:%M:%S) D7VK on (32-bit ddraw)"
|
|
elif [ -L "$S/ddraw_.dll" ] || [ -e "$S/ddraw_.dll" ]; then
|
|
rm -f "$S/ddraw.dll" "$S/ddraw_.dll"
|
|
ln -s "$F/lib/wine/i386-windows/ddraw.dll" "$S/ddraw.dll"
|
|
echo "$(date +%H:%M:%S) D7VK off: Wine's ddraw again"
|
|
fi
|
|
# A Windows path (an Xbox game on its own drive letter) starts in the folder Steam gave.
|
|
case "$EXE" in [A-Za-z]:[\\/]*) ;; *) cd "$(dirname "$EXE")" || exit 1 ;; esac
|
|
|
|
if [ "$verb" = runinprefix ]; then
|
|
wine_ "$EXE" "$@"
|
|
rc=$?
|
|
save_fex_stamp
|
|
exit $rc
|
|
fi
|
|
|
|
name=${EXE##*/}; name=${name##*\\}
|
|
comm=$(echo "$name" | cut -c1-15)
|
|
game_pids() { # processes of this prefix with the game's name (two prefixes can run programs with the same name)
|
|
for p in $(grep -lFx "$comm" /proc/[0-9]*/comm 2>/dev/null); do
|
|
p=${p%/comm}
|
|
tr '\0' '\n' 2>/dev/null < "$p/environ" | grep -qxF "WINEPREFIX=$COMPAT/pfx" && echo "${p#/proc/}"
|
|
done
|
|
}
|
|
# The game's windows go straight to gamescope's X server, as with DroidDeck-Proton (no Wine desktop): the game
|
|
# sees gamescope's real modes and refresh rate, and gamescope manages its windows.
|
|
wine_ "$EXE" "$@" &
|
|
WP=$!
|
|
# Steam's overlay library marks a game's windows with the app ID Steam tracks (STEAM_GAME); that library is
|
|
# glibc-only, so this prefix's windows (WM_CLASS = the Windows program name) are tagged from outside, or gamescope
|
|
# never shows them.
|
|
GT=
|
|
if [ "${SteamAppId:-0}" != 0 ]; then
|
|
XD=${DISPLAY#*:}; XD=${XD%%.*}
|
|
"$LINKER" "$PACK/bin/gstag" "${XD:-0}" "$SteamAppId" .exe 86400 > "$COMPAT/gstag.log" 2>&1 &
|
|
GT=$!
|
|
fi
|
|
trap 'echo "$(date +%H:%M:%S) stopped by Steam"; [ -n "$GT" ] && kill $GT 2>/dev/null; stop_wine; save_fex_stamp; exit 0' TERM INT HUP
|
|
n=0
|
|
while [ $n -lt 90 ] && [ -z "$(game_pids)" ]; do
|
|
# A program that ended before it was seen (Steam's install-script step takes about a second) leaves nothing
|
|
# to wait for; a launcher that left a game running is still waited for as before.
|
|
if [ $n -ge 2 ] && ! kill -0 $WP 2>/dev/null && ! programs_left; then break; fi
|
|
sleep 1; n=$((n + 1))
|
|
done
|
|
echo "$(date +%H:%M:%S) game process $(game_pids | tr '\n' ' ')after ${n}s"
|
|
# The program Steam started counts while it runs: a program that names its main thread (Chromium-based games call
|
|
# it CrBrowserMain) changes its process name, which Wine copies, and is then no longer found by name. A launcher
|
|
# that started the game and ended leaves the game as another program of this prefix, so the wait goes on while any
|
|
# program of the prefix runs, apart from Wine's own services (Proton waits for the prefix's programs the same way).
|
|
while [ -n "$(game_pids)" ] || kill -0 $WP 2>/dev/null || programs_left; do sleep 2; done
|
|
echo "$(date +%H:%M:%S) game exited"
|
|
[ -n "$GT" ] && kill $GT 2>/dev/null
|
|
stop_wine
|
|
wait $WP
|
|
rc=$?
|
|
save_fex_stamp
|
|
echo "$(date +%H:%M:%S) done (exit $rc)"
|
|
exit $rc
|