mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00:00
Merge branch 'main' into fix/bionic-honor-tinyxml2
This commit is contained in:
623 files changed
+64503
-5032
No files matched your search
@@ -36,9 +36,11 @@ GAMESCOPE_PATCHES="0117-wsi-cache-present-bypass-check.patch 0119-wsi-default-im
|
||||
VULKAN_HEADERS_TAG=v1.4.341
|
||||
# The bionic DroidDeck-Proton layer the pack is made for: linked against (libwayland-client) and checked against, not packed.
|
||||
# Layer v18: DroidDeck-Proton 11-14.1 (Valve Wine a47c73f52fd7, as GE-Proton11-14), the build Bannerlator ships; it
|
||||
# carries the ARM64EC code-map and unwind fixes the 12.8 layer had (5ebfaa6f, 2515a989, e88fab40).
|
||||
LAYER_URL=https://github.com/The412Banner/proton-wine/releases/download/build-bionic-layers-20261124-v18/DroidDeck-proton-11.0-14.1-arm64ec.wcp
|
||||
LAYER_SHA256=bf94176180e96584185835f9e80b168666f9fa752aa9583cfedb8fe493134ff6 # proton-wine 1a5735e7 (run 45926928349)
|
||||
# carries the ARM64EC code-map and unwind fixes the 12.8 layer had (5ebfaa6f, 2515a989, e88fab40). This build adds the
|
||||
# original Xbox fixes on top of v18 (special APC delivery, boot video aperture, 0 timer resolution: each off unless
|
||||
# droiddeck-game-env sets its variable; FileAllocationInfo, MFCreateWaveFormatEx NULL size).
|
||||
LAYER_URL=https://github.com/The412Banner/proton-wine/releases/download/build-bionic-layers-20261203-ogxbox/DroidDeck-proton-11.0-14.1-arm64ec.wcp
|
||||
LAYER_SHA256=a779747c880c64bacc0171cf26822f3398eaf32f0b214bca3448a95bf4127a90 # proton-wine ee646200 (run 47122517177)
|
||||
LAYER_VERSION=14.1
|
||||
# Packed into the DroidDeck-Bionic tool next to the layer: FEX with Android-built unix libraries, and default
|
||||
# DXVK / VKD3D-Proton (DroidDeck components can swap these in files/lib/wine/{dxvk,vkd3d-proton} later).
|
||||
@@ -184,7 +186,7 @@ echo "== DroidDeck fake input (app/src/main/cpp/fakeinput_steam.cpp), heap-taggi
|
||||
"$CXX" -shared -fPIC -O2 -Wall -Wno-attributes -pthread -std=c++17 "$ROOT/app/src/main/cpp/fakeinput_steam.cpp" \
|
||||
-ldl -static-libstdc++ -o "$PACK/preload/libfakeinput.so"
|
||||
"$CC" -shared -fPIC -O2 -Wall "$HERE/notag.c" -ldl -o "$PACK/preload/libnotag.so"
|
||||
"$CC" -shared -fPIC -O2 -Wall "$HERE/execshim.c" -ldl -o "$PACK/preload/libexecshim.so"
|
||||
"$CC" -shared -fPIC -O2 -Wall "$HERE/execshim.c" "$HERE/handoff.c" -ldl -o "$PACK/preload/libexecshim.so"
|
||||
"$CC" -shared -fPIC -O2 -Wall -Wextra -fvisibility=hidden "$HERE/steamshm.c" -ldl -o "$PACK/preload/libsteamshm.so"
|
||||
"$CC" -O2 -Wall "$HERE/gstag.c" -o "$PACK/bin/gstag"
|
||||
"$STRIP" --strip-unneeded "$PACK/layer/"*.so "$PACK/preload/"*.so "$PACK/bin/gstag"
|
||||
|
||||
@@ -25,6 +25,9 @@ typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t;
|
||||
|
||||
#define LINKER "/system/bin/linker64"
|
||||
|
||||
// handoff.c: returns unless the exec was handed to one of the app's worker processes
|
||||
void ddh_bionic_exec(const char *file, char *const args[], char *const envp[], const char *path, char *const argv[]);
|
||||
|
||||
enum kind { PASS, VIA_LINKER, VIA_INTERP };
|
||||
|
||||
// What starting `path` needs; for scripts, the interpreter and its optional argument.
|
||||
@@ -205,6 +208,8 @@ int execve(const char *path, char *const argv[], char *const envp[]) {
|
||||
char storage[6 * PATH_MAX]; // stack only: this may run in posix_spawn's vfork-like child (where it passes)
|
||||
const char *file = path;
|
||||
char **args = rewrite(path, argv, &file, storage);
|
||||
// the app may run it in a worker instead (handoff.c): matched by the program, sent as the start below
|
||||
ddh_bionic_exec(file, args ? args : argv, envp, path, argv);
|
||||
int ret = real(file, args ? args : argv, envp);
|
||||
int saved = errno;
|
||||
free(args);
|
||||
|
||||
@@ -0,0 +1,422 @@
|
||||
// handoff: part of libexecshim.so, preloaded into the bionic Wine processes. The native hook's exec
|
||||
// handoff (tools/nativeguest/hook/handoff.c, docs/phantom-processes.md) built for bionic: a program a
|
||||
// Wine process forks and execs runs as the main process of one of the app's worker processes instead of
|
||||
// as a child Android counts against its limit. The glibc session's hook cannot reach these processes
|
||||
// (they run on Android's libc), so without this every Wine process of a bionic game was counted.
|
||||
//
|
||||
// What the native hook does around the handoff and this file does too: fork() records the child for
|
||||
// its parent's table, close(), close_range(), dup2() and dup3() leave the table and the worker's binder
|
||||
// fds alone (hook/kept.c), and execve() offers the exec to the app before it runs (execshim.c calls
|
||||
// ddh_bionic_exec() with the start it is about to make: "/system/bin/linker64 PROGRAM ARGS" for a
|
||||
// program in the app's data, matched against DD_HANDOFF by PROGRAM). wait*(), kill() and _exit() are
|
||||
// the handoff's own (hook/handoff.c). Nothing here acts without DD_SPAWN and DD_HANDOFF in the
|
||||
// environment (tools/bionic-runtime/tool/launch.sh keeps them).
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <elf.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
// bionic has no thread cancellation: nothing can cancel the table's setup
|
||||
#ifndef PTHREAD_CANCEL_ENABLE
|
||||
#define PTHREAD_CANCEL_ENABLE 0
|
||||
#define PTHREAD_CANCEL_DISABLE 1
|
||||
static int pthread_setcancelstate(int state, int *old) {
|
||||
(void)state;
|
||||
if (old) *old = PTHREAD_CANCEL_ENABLE;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifndef CLOSE_RANGE_UNSHARE
|
||||
#define CLOSE_RANGE_UNSHARE (1U << 1)
|
||||
#endif
|
||||
#ifndef CLOSE_RANGE_CLOEXEC
|
||||
#define CLOSE_RANGE_CLOEXEC (1U << 2)
|
||||
#endif
|
||||
#ifndef __NR_close_range
|
||||
#define __NR_close_range 436
|
||||
#endif
|
||||
|
||||
#include <sys/sysmacros.h>
|
||||
static void pthread_testcancel(void) {}
|
||||
int close_range(unsigned int first, unsigned int last, int flags);
|
||||
|
||||
// bionic has no on_exit(): the handoff reports a program's exit status from it (exit() runs it).
|
||||
// atexit() handlers get no status, so exit() below notes it first; a return from main() reaches
|
||||
// exit() inside libc and reports 0.
|
||||
static void (*g_on_exit_fn)(int, void *);
|
||||
static void *g_on_exit_arg;
|
||||
static int g_exit_status;
|
||||
static void run_on_exit(void) {
|
||||
if (g_on_exit_fn) g_on_exit_fn(g_exit_status, g_on_exit_arg);
|
||||
}
|
||||
static int on_exit(void (*fn)(int, void *), void *arg) {
|
||||
g_on_exit_fn = fn;
|
||||
g_on_exit_arg = arg;
|
||||
return atexit(run_on_exit);
|
||||
}
|
||||
|
||||
// The native hook's names for the plain system call and for a guest path: here there is no guest root.
|
||||
static long call_orig_syscall(long nr, unsigned long a, unsigned long b, unsigned long c, unsigned long d,
|
||||
unsigned long e, unsigned long f) {
|
||||
return syscall(nr, a, b, c, d, e, f);
|
||||
}
|
||||
static const char *rewrite_path(const char *path, char *out, size_t size) {
|
||||
(void)out;
|
||||
(void)size;
|
||||
return path;
|
||||
}
|
||||
|
||||
// The native hook's SIGCHLD handling (hook/signals.c) is not part of this shim: its programs record their
|
||||
// first parent for the session's subreapers, and reap nothing themselves.
|
||||
static void ddnatv_manage_sigchld(void) {}
|
||||
static void ddh_reap_unclaimed(void) __attribute__((unused));
|
||||
|
||||
#include "../nativeguest/hook/kept.c"
|
||||
#include "../nativeguest/hook/handoff.c"
|
||||
|
||||
void exit(int status) {
|
||||
g_exit_status = status;
|
||||
void (*real)(int) = (void (*)(int))dlsym(RTLD_NEXT, "exit");
|
||||
if (real) real(status);
|
||||
syscall(SYS_exit_group, status);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
static int ddh_is_linker(const char *path) {
|
||||
const char *base = path ? strrchr(path, '/') : NULL;
|
||||
return base && strcmp(base + 1, "linker64") == 0;
|
||||
}
|
||||
|
||||
static int ddh_regular(const char *path, int mode) {
|
||||
struct stat st;
|
||||
return path && stat(path, &st) == 0 && S_ISREG(st.st_mode) && access(path, mode) == 0;
|
||||
}
|
||||
|
||||
// Android refuses execve() of a file in the app's data unless SELinux is permissive (execshim.c makes the
|
||||
// dynamic ones linker64 starts). An unreadable setting counts as enforcing.
|
||||
static int ddh_selinux_permissive(void) {
|
||||
char c = 0;
|
||||
int fd = (int)syscall(SYS_openat, AT_FDCWD, "/sys/fs/selinux/enforce", O_RDONLY | O_CLOEXEC, 0);
|
||||
if (fd < 0) return 0;
|
||||
long n = syscall(SYS_read, fd, &c, 1);
|
||||
syscall(SYS_close, fd);
|
||||
return n == 1 && c == '0';
|
||||
}
|
||||
|
||||
// A handed-off start that fails fails in the worker, where the caller cannot see it and try its next
|
||||
// candidate (Wine tries its preloader, then its loader), so only a start that would succeed here goes.
|
||||
static int ddh_bionic_startable(const char *file, char *const args[]) {
|
||||
char real[PATH_MAX];
|
||||
// env takes an argument with '=' for a variable, and looks a name without '/' up in PATH
|
||||
if (!file || strchr(file, '=') || !strchr(file, '/')) return 0;
|
||||
if (!ddh_regular(file, X_OK) || !realpath(file, real)) return 0;
|
||||
if (ddh_is_linker(real))
|
||||
return args && args[0] && args[1] && args[1][0] != '-' && ddh_regular(args[1], R_OK) && ddh_startable(args[1]);
|
||||
if (strncmp(real, "/data/", 6) == 0 && !ddh_selinux_permissive()) return 0;
|
||||
// env starts FILE with FILE as argv[0]
|
||||
return args && args[0] && strcmp(args[0], file) == 0 && ddh_startable(file);
|
||||
}
|
||||
|
||||
void ddh_bionic_exec(const char *file, char *const args[], char *const envp[], const char *path, char *const argv[]) {
|
||||
if (ddh_env(envp, "DD_HANDOFF_DEBUG")) {
|
||||
char why[200];
|
||||
struct ddh_table *own = __atomic_load_n(&g_ddh, __ATOMIC_ACQUIRE);
|
||||
snprintf(why, sizeof(why), "bionic exec (spawn %d list %d table %d owner %d up %d ppid %d) of", ddh_env(envp, "DD_SPAWN") != NULL,
|
||||
ddh_env(envp, "DD_HANDOFF") != NULL, own != NULL, own ? (int)g_ddh_owner : 0, g_ddh_up != NULL, (int)getppid());
|
||||
ddh_debug(envp, why, path ? path : "(null)");
|
||||
}
|
||||
if (!ddh_env(envp, "DD_SPAWN") || !ddh_env(envp, "DD_HANDOFF")) return;
|
||||
if (!ddh_bionic_startable(file, args)) {
|
||||
ddh_debug(envp, "bionic exec stays here (not startable as a handoff):", path ? path : "(null)");
|
||||
return;
|
||||
}
|
||||
// Wine's own starts through the system linker ("/system/bin/linker64 PROGRAM ARGS") are listed by PROGRAM
|
||||
const char *match = path;
|
||||
char *const *match_argv = argv;
|
||||
if (ddh_is_linker(path) && argv && argv[0] && argv[1]) {
|
||||
match = argv[1];
|
||||
match_argv = argv + 1;
|
||||
}
|
||||
// The app starts a handed-off program from the glibc root's shell (GuestWorkers), which cannot load this
|
||||
// runtime's LD_PRELOAD and LD_LIBRARY_PATH (bionic libraries). The request carries them as arguments of
|
||||
// Android's env instead, which the shell execs and which puts them back for the program: the worker's main
|
||||
// process ends up as the program all the same. Stack only (this may run in a vfork child).
|
||||
int nargs = 0, nenv = 0;
|
||||
while (args[nargs]) nargs++;
|
||||
while (envp && envp[nenv]) nenv++;
|
||||
// env, up to two loader variables, FILE, args[1..], NULL (nargs >= 1: ddh_bionic_startable)
|
||||
char *wrapped[nargs + 4];
|
||||
char *trimmed[nenv + 1];
|
||||
int w = 0, t = 0;
|
||||
wrapped[w++] = (char *)"/system/bin/env";
|
||||
for (int i = 0; i < nenv; i++) {
|
||||
if (strncmp(envp[i], "LD_PRELOAD=", 11) == 0 || strncmp(envp[i], "LD_LIBRARY_PATH=", 16) == 0) {
|
||||
if (w < 3) wrapped[w++] = envp[i];
|
||||
} else {
|
||||
trimmed[t++] = envp[i];
|
||||
}
|
||||
}
|
||||
trimmed[t] = NULL;
|
||||
// env runs the program by the path its first argument gives: the start's file, then the rest of its argv
|
||||
wrapped[w++] = (char *)file;
|
||||
for (int i = 1; i < nargs; i++) wrapped[w++] = args[i];
|
||||
wrapped[w] = NULL;
|
||||
ddh_try_as("/system/bin/env", wrapped, trimmed, match, match_argv);
|
||||
ddh_debug(envp, "bionic exec stays here:", path ? path : "(null)");
|
||||
}
|
||||
|
||||
// bionic's exec functions call the execve system call stub inside libc, past execshim.c's execve(): Wine
|
||||
// starts its programs with execv() (its preloader) and execvp(), so these go through execve() here.
|
||||
extern char **environ;
|
||||
|
||||
int execv(const char *path, char *const argv[]) { return execve(path, argv, environ); }
|
||||
|
||||
// bionic's execvpe(), through execve() here: an unset PATH is libc's default (Android 14's; an empty one, and an empty
|
||||
// entry, are the current directory), and a file the kernel cannot start (ENOEXEC) runs under /system/bin/sh.
|
||||
#define DDH_DEFPATH "/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin"
|
||||
|
||||
static int exec_as_script(const char *file, char *const argv[], char *const envp[]) {
|
||||
int n = 0;
|
||||
while (argv && argv[n]) n++;
|
||||
char *script[(n > 0 ? n : 1) + 2];
|
||||
int s = 0;
|
||||
script[s++] = (char *)"sh";
|
||||
script[s++] = (char *)file;
|
||||
for (int i = 1; i < n; i++) script[s++] = argv[i];
|
||||
script[s] = NULL;
|
||||
return execve("/system/bin/sh", script, envp);
|
||||
}
|
||||
|
||||
int execvpe(const char *file, char *const argv[], char *const envp[]) {
|
||||
if (!file || !*file) {
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
if (strchr(file, '/')) {
|
||||
execve(file, argv, envp);
|
||||
return errno == ENOEXEC ? exec_as_script(file, argv, envp) : -1;
|
||||
}
|
||||
const char *dirs = getenv("PATH");
|
||||
if (!dirs) dirs = DDH_DEFPATH;
|
||||
int saw_eacces = 0;
|
||||
size_t flen = strlen(file);
|
||||
for (const char *p = dirs;;) {
|
||||
const char *end = strchr(p, ':');
|
||||
size_t len = end ? (size_t)(end - p) : strlen(p);
|
||||
const char *dir = len ? p : ".";
|
||||
if (!len) len = 1;
|
||||
char full[PATH_MAX];
|
||||
if (len + flen + 2 > sizeof(full)) {
|
||||
errno = ENAMETOOLONG;
|
||||
} else {
|
||||
memcpy(full, dir, len);
|
||||
full[len] = '/';
|
||||
memcpy(full + len + 1, file, flen + 1);
|
||||
execve(full, argv, envp);
|
||||
}
|
||||
switch (errno) {
|
||||
case EISDIR:
|
||||
case ELOOP:
|
||||
case ENAMETOOLONG:
|
||||
case ENOENT:
|
||||
case ENOTDIR:
|
||||
break;
|
||||
case ENOEXEC:
|
||||
return exec_as_script(full, argv, envp);
|
||||
case EACCES:
|
||||
saw_eacces = 1;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
if (!end) break;
|
||||
p = end + 1;
|
||||
}
|
||||
if (saw_eacces) errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int execvp(const char *file, char *const argv[]) { return execvpe(file, argv, environ); }
|
||||
|
||||
// execl(), execlp(), execle(): the list as an argv on the stack
|
||||
#define EXECL_ARGV(first, ap, n) \
|
||||
do { \
|
||||
va_list count_ap; \
|
||||
va_copy(count_ap, ap); \
|
||||
n = first ? 1 : 0; \
|
||||
if (first) \
|
||||
while (va_arg(count_ap, const char *)) n++; \
|
||||
va_end(count_ap); \
|
||||
} while (0)
|
||||
|
||||
int execl(const char *path, const char *arg0, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, arg0);
|
||||
int n;
|
||||
EXECL_ARGV(arg0, ap, n);
|
||||
char *argv[n + 1];
|
||||
argv[0] = (char *)arg0;
|
||||
for (int i = 1; i < n; i++) argv[i] = va_arg(ap, char *);
|
||||
argv[n] = NULL;
|
||||
va_end(ap);
|
||||
return execve(path, argv, environ);
|
||||
}
|
||||
|
||||
int execlp(const char *file, const char *arg0, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, arg0);
|
||||
int n;
|
||||
EXECL_ARGV(arg0, ap, n);
|
||||
char *argv[n + 1];
|
||||
argv[0] = (char *)arg0;
|
||||
for (int i = 1; i < n; i++) argv[i] = va_arg(ap, char *);
|
||||
argv[n] = NULL;
|
||||
va_end(ap);
|
||||
return execvp(file, argv);
|
||||
}
|
||||
|
||||
int execle(const char *path, const char *arg0, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, arg0);
|
||||
int n;
|
||||
EXECL_ARGV(arg0, ap, n);
|
||||
char *argv[n + 1];
|
||||
argv[0] = (char *)arg0;
|
||||
for (int i = 1; i < n; i++) argv[i] = va_arg(ap, char *);
|
||||
argv[n] = NULL;
|
||||
if (arg0) (void)va_arg(ap, char *); // the list's NULL
|
||||
char *const *envp = va_arg(ap, char *const *);
|
||||
va_end(ap);
|
||||
return execve(path, argv, envp);
|
||||
}
|
||||
|
||||
pid_t fork(void) {
|
||||
static pid_t (*orig_fork)(void) = NULL;
|
||||
if (!orig_fork) orig_fork = (pid_t (*)(void))dlsym(RTLD_NEXT, "fork");
|
||||
if (!orig_fork) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
ddh_prepare();
|
||||
pid_t forker = (pid_t)syscall(SYS_gettid);
|
||||
pid_t forking = (pid_t)syscall(SYS_getpid);
|
||||
pid_t pid = orig_fork();
|
||||
if (pid == 0) {
|
||||
kept_forked();
|
||||
kept_close_forked();
|
||||
ddh_drop_worker_binder();
|
||||
ddh_forked(forker);
|
||||
ddh_record_parent((pid_t)syscall(SYS_getpid), forking);
|
||||
} else if (pid > 0) {
|
||||
ddh_child_created(pid, 1);
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
int close(int fd) {
|
||||
static int (*orig_close)(int) = NULL;
|
||||
if (!orig_close) orig_close = (int (*)(int))dlsym(RTLD_NEXT, "close");
|
||||
uint64_t ticket = kept_close_begin();
|
||||
if (kept_any() > 0 && is_kept_fd(fd)) {
|
||||
kept_close_end(ticket);
|
||||
return 0;
|
||||
}
|
||||
int r = orig_close ? orig_close(fd) : (errno = ENOSYS, -1);
|
||||
int saved = errno;
|
||||
kept_close_end(ticket);
|
||||
errno = saved;
|
||||
return r;
|
||||
}
|
||||
|
||||
static int dup_moved(int (*dup_fn)(int, int, int), int oldfd, int newfd, int flags) {
|
||||
int pidfd_from = -1, locked = 0;
|
||||
if (oldfd != newfd) {
|
||||
locked = ddh_parent_pidfd_lock(newfd);
|
||||
pidfd_from = ddh_parent_pidfd_moves(newfd);
|
||||
}
|
||||
int ret = dup_fn(oldfd, newfd, flags);
|
||||
ddh_parent_pidfd_settle(pidfd_from, ret >= 0);
|
||||
int saved = errno;
|
||||
ddh_parent_pidfd_unlock(locked);
|
||||
errno = saved;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int (*g_orig_dup2)(int, int);
|
||||
static int (*g_orig_dup3)(int, int, int);
|
||||
static int call_dup2(int oldfd, int newfd, int flags) {
|
||||
(void)flags;
|
||||
return g_orig_dup2 ? g_orig_dup2(oldfd, newfd) : (errno = ENOSYS, -1);
|
||||
}
|
||||
static int call_dup3(int oldfd, int newfd, int flags) {
|
||||
return g_orig_dup3 ? g_orig_dup3(oldfd, newfd, flags) : (errno = ENOSYS, -1);
|
||||
}
|
||||
|
||||
int dup2(int oldfd, int newfd) {
|
||||
if (!g_orig_dup2) g_orig_dup2 = (int (*)(int, int))dlsym(RTLD_NEXT, "dup2");
|
||||
return dup_moved(call_dup2, oldfd, newfd, 0);
|
||||
}
|
||||
|
||||
int dup3(int oldfd, int newfd, int flags) {
|
||||
if (!g_orig_dup3) g_orig_dup3 = (int (*)(int, int, int))dlsym(RTLD_NEXT, "dup3");
|
||||
return dup_moved(call_dup3, oldfd, newfd, flags);
|
||||
}
|
||||
|
||||
static int close_range_part(unsigned int first, unsigned int last, void *flags) {
|
||||
return (int)syscall(__NR_close_range, first, last, *(int *)flags);
|
||||
}
|
||||
|
||||
static int close_range_unshare(void) {
|
||||
return (int)syscall(__NR_close_range, ~0U, ~0U, CLOSE_RANGE_UNSHARE);
|
||||
}
|
||||
|
||||
int close_range(unsigned int first, unsigned int last, int flags) {
|
||||
// what the kernel refuses, refused before the range is split or the table unshared
|
||||
if (first > last || (flags & ~(int)(CLOSE_RANGE_UNSHARE | CLOSE_RANGE_CLOEXEC))) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
uint64_t ticket = kept_close_begin();
|
||||
int r = 0;
|
||||
// The table is unshared first, once, and this thread goes on with its own copy of the kept list
|
||||
// (kept_split())
|
||||
if (flags & CLOSE_RANGE_UNSHARE) {
|
||||
r = kept_split(close_range_unshare);
|
||||
flags &= ~(int)CLOSE_RANGE_UNSHARE;
|
||||
}
|
||||
if (r == 0) {
|
||||
int snapshot[DDNATV_MAX_KEPT_FDS];
|
||||
const int *kept = (flags & CLOSE_RANGE_CLOEXEC) ? g_cloexec_kept_fds : snapshot;
|
||||
int count = (flags & CLOSE_RANGE_CLOEXEC) ? g_cloexec_kept_count : kept_snapshot(snapshot);
|
||||
r = count == 0 ? close_range_part(first, last, &flags)
|
||||
: for_each_range_without(first, last, kept, count, close_range_part, &flags);
|
||||
}
|
||||
int saved = errno;
|
||||
kept_close_end(ticket);
|
||||
errno = saved;
|
||||
return r;
|
||||
}
|
||||
|
||||
// The native hook's own uses of these (exec.c) have no counterpart here
|
||||
__attribute__((unused)) static void *const glibc_only[] = {(void *)ddh_try, (void *)ddh_spawn_wanted};
|
||||
@@ -52,6 +52,13 @@ for v in $(env | sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p'); do
|
||||
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) ;;
|
||||
# droiddeck-game-env's original Xbox switches for this layer's Wine and the Xbox VKD3D-Proton build
|
||||
WINE_SPECIAL_APC_INTERRUPT|WINE_MF_DISPLAY_APERTURE|WINE_PRECISE_SLEEP) ;;
|
||||
VKD3D_INTEROP_PRESENT|VKD3D_PACKED_422|VKD3D_PACKED_422_SWIZZLE) ;;
|
||||
# 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
|
||||
@@ -86,7 +93,8 @@ 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=1
|
||||
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),
|
||||
@@ -258,7 +266,7 @@ prepare_prefix() {
|
||||
prefix_busy() { # a process of this prefix is running
|
||||
for p in /proc/[0-9]*; do
|
||||
[ "${p#/proc/}" = "$$" ] && continue
|
||||
tr '\0' '\n' < "$p/environ" 2>/dev/null | grep -qx "WINEPREFIX=$COMPAT/pfx" && return 0
|
||||
tr '\0' '\n' 2>/dev/null < "$p/environ" | grep -qx "WINEPREFIX=$COMPAT/pfx" && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
@@ -273,7 +281,7 @@ programs_left() { # a program of this prefix is still running, apart from Wine's
|
||||
""|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' < "$p/environ" 2>/dev/null | grep -qx "WINEPREFIX=$COMPAT/pfx" && return 0
|
||||
tr '\0' '\n' 2>/dev/null < "$p/environ" | grep -qx "WINEPREFIX=$COMPAT/pfx" && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
@@ -282,7 +290,7 @@ stop_wine() { # wineserver -k, then whatever of this prefix is left (e.g. a game
|
||||
wineserver_ -k 2>/dev/null
|
||||
sleep 1
|
||||
for p in /proc/[0-9]*; do
|
||||
tr '\0' '\n' < "$p/environ" 2>/dev/null | grep -qx "WINEPREFIX=$COMPAT/pfx" || continue
|
||||
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
|
||||
@@ -426,7 +434,7 @@ 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' < "$p/environ" 2>/dev/null | grep -qxF "WINEPREFIX=$COMPAT/pfx" && echo "${p#/proc/}"
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user