mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
cleanup (#764)
This commit is contained in:
1 parent
5fd47421f9
commit
aecd2ebe1d
852 files changed
+4844
-46144
No files matched your search
@@ -1,11 +1,3 @@
|
||||
/*
|
||||
* binfmt_misc for the desktop, which proot does not have: an exec of an x86 Linux program, a Windows
|
||||
* program, or a program or script on noexec shared storage goes to droiddeck-open --exec, which runs
|
||||
* it under FEX, Proton or its interpreter. x86 and Windows programs are caught before the exec: proot
|
||||
* loads a static x86 program as a native one, which dies on its first instruction, and execvp runs a
|
||||
* Windows program as a shell script. A program on noexec storage also passes access(X_OK), which KIO
|
||||
* and Qt ask before they start one. Only in the desktop session.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <elf.h>
|
||||
@@ -27,7 +19,6 @@
|
||||
typedef int (*spawn_fn)(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *,
|
||||
char *const[], char *const[]);
|
||||
|
||||
/* BINFMT_TEST: tools/tests builds it for the host, whose own x86 programs stand in for foreign ones. */
|
||||
#if defined(__aarch64__) || defined(BINFMT_TEST)
|
||||
|
||||
static int desktop(void) {
|
||||
@@ -35,7 +26,6 @@ static int desktop(void) {
|
||||
return value && value[0] == '1' && value[1] == 0;
|
||||
}
|
||||
|
||||
/* 1: x86 program or noexec storage, 2: Windows program, 3: script; 0 for anything else. */
|
||||
static int foreign(const char *path, int error) {
|
||||
if (!path || !strcmp(path, BINFMT_HANDLER)) return 0;
|
||||
int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
@@ -52,7 +42,6 @@ static int foreign(const char *path, int error) {
|
||||
} else if (n >= 2 && head[0] == '#' && head[1] == '!' && error == EACCES) {
|
||||
kind = 3;
|
||||
}
|
||||
/* What the kernel refuses for its permissions stays refused; noexec storage has no execute bits to give. */
|
||||
struct statvfs vfs;
|
||||
int allowed = kind && (((st.st_mode & 0111) && error != EACCES) || (fstatvfs(fd, &vfs) == 0 && (vfs.f_flag & ST_NOEXEC)));
|
||||
close(fd);
|
||||
@@ -63,7 +52,6 @@ static int wanted(const char *path, int error) {
|
||||
return (error == ENOEXEC || error == ENOENT || error == EACCES) && desktop() && foreign(path, error);
|
||||
}
|
||||
|
||||
/* The program on PATH as execvp would find it, into [out]. */
|
||||
static int lookup(const char *file, char *out, size_t size) {
|
||||
if (!file || !*file) return 0;
|
||||
if (strchr(file, '/')) return snprintf(out, size, "%s", file) < (int)size;
|
||||
@@ -111,19 +99,16 @@ static int spawn_handler(pid_t *pid, const char *path, const posix_spawn_file_ac
|
||||
return real(pid, BINFMT_HANDLER, fa, attr, args, envp);
|
||||
}
|
||||
|
||||
/* Before an exec of [path]: an x86 or Windows program goes to the handler instead. */
|
||||
__attribute__((visibility("hidden"))) void bl_binfmt_before(const char *path, char *const argv[], char *const envp[]) {
|
||||
if (desktop() && foreign(path, ENOEXEC)) hand_off(path, argv, envp);
|
||||
}
|
||||
|
||||
/* After a failed exec of [path]: the handler takes it over, or the exec's own error stands. */
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_retry(const char *path, char *const argv[], char *const envp[], int error) {
|
||||
if (wanted(path, error)) hand_off(path, argv, envp);
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* The same around execvp, for the program it finds on PATH. */
|
||||
__attribute__((visibility("hidden"))) void bl_binfmt_before_search(const char *file, char *const argv[], char *const envp[]) {
|
||||
char path[PATH_MAX];
|
||||
if (desktop() && lookup(file, path, sizeof path)) bl_binfmt_before(path, argv, envp);
|
||||
@@ -136,7 +121,6 @@ __attribute__((visibility("hidden"))) int bl_binfmt_after_search(const char *fil
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* After access(X_OK) of [path] was refused (pathcache.c): a program on noexec storage runs all the same. */
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_runnable(const char *path, int mode) {
|
||||
if (mode != X_OK || !desktop()) return 0;
|
||||
int runs = foreign(path, EACCES) != 0;
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
/*
|
||||
* The Steam client lists a whole content directory about ten times per file it creates, moves or
|
||||
* deletes, to match names case-insensitively. On Android's FUSE storage that made reserving space
|
||||
* quadratic. Listings under steamapps/ on FUSE are kept for at most DIR_TTL_NS and dropped on any
|
||||
* inotify event the client's own patched changes don't account for; directory timestamps alone
|
||||
* can't be trusted, as NTFS volumes report whole seconds. BL_NO_DIR_CACHE=1 turns it off.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dirent.h>
|
||||
#include <dlfcn.h>
|
||||
@@ -32,7 +25,6 @@
|
||||
#define FUSE_MAGIC 0x65735546
|
||||
#define WATCHED (IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO | IN_DELETE_SELF | IN_MOVE_SELF | IN_ONLYDIR)
|
||||
|
||||
/* The client is 64-bit; 32-bit builds only pass creates through. */
|
||||
#if __SIZEOF_POINTER__ == 8
|
||||
|
||||
_Static_assert(sizeof(struct dirent) == sizeof(struct dirent64), "dirent layouts differ");
|
||||
@@ -88,7 +80,6 @@ static long long now_ns(void) {
|
||||
return (long long)t.tv_sec * 1000000000LL + t.tv_nsec;
|
||||
}
|
||||
|
||||
/* A child shares the parent's inotify queue, so it stops keeping listings. */
|
||||
static void after_fork(void) {
|
||||
pthread_mutex_init(&lock, NULL);
|
||||
pthread_mutex_init(&oplock, NULL);
|
||||
@@ -162,7 +153,6 @@ static void unref(struct listing *l) {
|
||||
if (--l->refs == 0 && l->detached) destroy(l);
|
||||
}
|
||||
|
||||
/* The rest is called with lock held. */
|
||||
|
||||
static void release(int wd) {
|
||||
if (wd < 0 || notify < 0) return;
|
||||
@@ -179,7 +169,6 @@ static void detach(struct listing *l) {
|
||||
if (l->refs == 0) destroy(l);
|
||||
}
|
||||
|
||||
/* Takes the listing out of the table; freed now or when its last reader closes. */
|
||||
static void drop(int slot) {
|
||||
struct listing *l = table[slot];
|
||||
int wd = l->wd;
|
||||
@@ -195,7 +184,6 @@ static void changed(int wd) {
|
||||
if (handles[i] && (handles[i]->wd == wd || wd < 0)) __atomic_store_n(&handles[i]->dirty, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
/* Applies queued events; the expected ones are the client's own changes, already patched in. */
|
||||
static void pump(struct expect *x, int nx) {
|
||||
char buf[4096] __attribute__((aligned(__alignof__(struct inotify_event))));
|
||||
if (notify < 0 || forked) return;
|
||||
@@ -302,7 +290,6 @@ static DIR *wrap(struct handle *h) {
|
||||
|
||||
#define RECLEN(namelen) ((offsetof(struct dirent64, d_name) + (namelen) + 1 + 7) & ~(size_t)7)
|
||||
|
||||
/* The listing as packed dirent64 records, built once per version. */
|
||||
static int records(struct listing *l) {
|
||||
if (l->recs) return 0;
|
||||
size_t len = 0;
|
||||
@@ -326,7 +313,6 @@ static int records(struct listing *l) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Lock-free from here on unless noted: a stream is only ever used by one thread at a time. */
|
||||
|
||||
static struct handle *lookup(DIR *d) {
|
||||
return registered(d) >= 0 ? (struct handle *)d : NULL;
|
||||
@@ -356,7 +342,6 @@ REAL(symlink);
|
||||
REAL(readdir64_r);
|
||||
REAL(readdir_r);
|
||||
|
||||
/* Resolved before the client starts threads; the calls below only fill gaps for earlier callers. */
|
||||
__attribute__((constructor)) static void resolve(void) {
|
||||
NEXT(opendir);
|
||||
NEXT(readdir64);
|
||||
@@ -378,7 +363,6 @@ __attribute__((constructor)) static void resolve(void) {
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/* A reader of the kept listing when it is still current. */
|
||||
static DIR *hit(const struct stat *st, struct handle *h, long long now) {
|
||||
pthread_mutex_lock(&lock);
|
||||
if (!changing) pump(NULL, 0);
|
||||
@@ -401,7 +385,6 @@ static DIR *hit(const struct stat *st, struct handle *h, long long now) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Registers the stream and its watch before anything is read, so no change goes unseen. */
|
||||
static int track(struct handle *h, const char *path) {
|
||||
pthread_mutex_lock(&lock);
|
||||
h->wd = watch(path);
|
||||
@@ -411,7 +394,6 @@ static int track(struct handle *h, const char *path) {
|
||||
return d != NULL;
|
||||
}
|
||||
|
||||
/* Reads through the real stream, keeping what it returns. */
|
||||
static void filling(struct handle *h, DIR *real, const struct stat *st, long long now) {
|
||||
h->real = real;
|
||||
h->fill = calloc(1, sizeof(*h->fill));
|
||||
@@ -625,7 +607,6 @@ static int watching(const char *path) {
|
||||
return eligible(path) && __atomic_load_n(&cached_listings, __ATOMIC_ACQUIRE) > 0;
|
||||
}
|
||||
|
||||
/* Called with oplock held: the client's tracked changes happen one at a time. */
|
||||
static void begin(void) {
|
||||
pthread_mutex_lock(&lock);
|
||||
pump(NULL, 0);
|
||||
@@ -639,7 +620,6 @@ static void before(struct side *s) {
|
||||
|
||||
enum { ADDED, REMOVED };
|
||||
|
||||
/* Patches the listing after the client's own change, or drops it when unsure. Called with lock held. */
|
||||
static int patch(struct side *s, int what, uint32_t event, int ok, int error, const char *target, struct expect *x) {
|
||||
struct stat now;
|
||||
if (!s->known) return 0;
|
||||
@@ -795,7 +775,6 @@ ONE_PATH(remove, REMOVED, IN_DELETE, next_remove(path))
|
||||
return r; \
|
||||
}
|
||||
|
||||
/* A refused hard link to a lock file is taken as a symlink (links.c). */
|
||||
int bl_link_lock(const char *oldpath, const char *newpath, int result) __attribute__((visibility("hidden")));
|
||||
static int link_or_lock(const char *from, const char *to) { return bl_link_lock(from, to, next_link(from, to)); }
|
||||
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
/*
|
||||
* GEM handle emulation for the KGSL device presented as a DRM render node.
|
||||
*
|
||||
* Compositors and Mesa validate or convert dma-bufs with PRIME ioctls on the render node; KGSL
|
||||
* has no GEM. Handles only serve as tokens to these callers, so a table of duplicated dma-buf
|
||||
* descriptors stands in for the kernel's, and every other device is left to libdrm.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -19,7 +12,6 @@
|
||||
|
||||
#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;
|
||||
@@ -36,7 +28,7 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct handle_entry handle_entries[MAX_HANDLES];
|
||||
static uint32_t next_handle = 1;
|
||||
static dev_t kgsl_dev;
|
||||
static int kgsl_state; /* 0 unknown, 1 known, -1 absent */
|
||||
static int kgsl_state;
|
||||
|
||||
static int is_kgsl(int fd) {
|
||||
struct stat st;
|
||||
@@ -63,7 +55,7 @@ static int same_file_description(int a, int b) {
|
||||
}
|
||||
#ifdef SYS_kcmp
|
||||
int saved_errno = errno;
|
||||
long ret = syscall(SYS_kcmp, getpid(), getpid(), 0 /* KCMP_FILE */, a, b);
|
||||
long ret = syscall(SYS_kcmp, getpid(), getpid(), 0 , a, b);
|
||||
errno = saved_errno;
|
||||
return ret == 0;
|
||||
#else
|
||||
@@ -81,11 +73,6 @@ static int find_handle_locked(int fd, uint32_t handle) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* The old table used its slot index as the public handle. Once #275 started freeing slots,
|
||||
* rapidly recreated swapchains immediately reused those numbers. Keep storage slots reusable but
|
||||
* make the public token monotonic so a stale handle can fail instead of aliasing a newer buffer.
|
||||
*/
|
||||
static uint32_t alloc_handle_locked(void) {
|
||||
for (int tries = 0; tries <= MAX_HANDLES; tries++) {
|
||||
uint32_t candidate = next_handle++;
|
||||
@@ -157,7 +144,6 @@ int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Drops only a handle belonging to this KGSL file description. */
|
||||
static int release_handle(int fd, uint32_t handle) {
|
||||
int found = 0;
|
||||
pthread_mutex_lock(&lock);
|
||||
@@ -179,16 +165,6 @@ int drmCloseBufferHandle(int fd, uint32_t handle) {
|
||||
return release_handle(fd, 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. Preserve #275's reclamation without letting another KGSL file
|
||||
* description release the token or making a new buffer immediately inherit a retired token.
|
||||
*
|
||||
* Caught at ioctl() (netif.c), which libdrm's drmIoctl calls, rather than by exporting drmIoctl:
|
||||
* every session process preloads this library, and exporting drmIoctl from it brought on a
|
||||
* judder replaying old frames in No Man's Sky on an Adreno 840 even with no handle released.
|
||||
*/
|
||||
__attribute__((visibility("hidden"))) int bl_drm_gem_close(int fd, unsigned long request, void *arg, int *rc) {
|
||||
if (request != GEM_CLOSE || !arg || !is_kgsl(fd)) {
|
||||
return 0;
|
||||
@@ -202,12 +178,6 @@ __attribute__((visibility("hidden"))) int bl_drm_gem_close(int fd, unsigned long
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* fork() carries over only the calling thread, so a lock another thread was holding at that
|
||||
* instant stays held in the child by a thread that is not there to release it. Taking it before
|
||||
* the fork makes the copy consistent; the parent then unlocks it and the child, whose one thread
|
||||
* never locked it, gets a fresh one. (WinNative 79aa7f68.)
|
||||
*/
|
||||
static void drm_lock_before_fork(void) { pthread_mutex_lock(&lock); }
|
||||
static void drm_unlock_after_fork(void) { pthread_mutex_unlock(&lock); }
|
||||
static void drm_reset_after_fork(void) { pthread_mutex_init(&lock, NULL); }
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/* droiddeck-fsync: futex_waitv(2) in userspace, so Proton's own fsync runs where the app sandbox refuses the syscall.
|
||||
* Credit: fsync, the futex-based synchronization in Proton, by Elizabeth Figura and Paul Gofman;
|
||||
* futex_waitv(2) by André Almeida. */
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -1,34 +1,7 @@
|
||||
/*
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with names
|
||||
* changed to this project's. The reasoning below is the original author's.
|
||||
*
|
||||
* The session's controllers, described to libudev's callers.
|
||||
*
|
||||
* The pads are evdev nodes the app backs with its own input rings, bound over /dev/input. Wine's
|
||||
* HID bus finds them there, but it identifies a node by resolving /sys/class/input/<name> and
|
||||
* asking libudev about the result: on Android that resolves to whatever real input device the
|
||||
* host numbered the same, whose device node libudev cannot read, so every pad is discarded before
|
||||
* its identity is ever looked at. The fallback is Wine's SDL bus, and SDL enumerates through udev
|
||||
* too, over a netlink socket the app sandbox refuses. A game was left with no controller at all
|
||||
* while the Steam client, which reads the nodes itself, had one.
|
||||
*
|
||||
* So the pads are described here instead: the resolved path is answered for the session's own
|
||||
* nodes, and libudev's accessors answer for that path from what the app already knows. They carry
|
||||
* the identity of the pad Steam Input would present if it could - it has no /dev/uinput here to
|
||||
* make one - which is the one identity Wine's own bus keeps rather than handing on to SDL.
|
||||
*
|
||||
* Only Wine's device host is answered, and only for the session's own nodes: the Steam client
|
||||
* enumerates the same nodes for itself and would take a pad wearing Steam Input's identity for one
|
||||
* of its own and ignore it. Every other caller, path and device object goes straight through.
|
||||
*
|
||||
* With libfakeinput's /dev/uinput stand-in (FAKE_EVDEV_UINPUT=1) Steam Input's own virtual pads
|
||||
* exist too, as event16 and up, and those are what Wine is meant to read: each is described with
|
||||
* the identity the client gave it, from the .uevent file libfakeinput writes beside the node.
|
||||
* While one exists the app's pads are described as what they are, an Xbox 360 controller, which
|
||||
* Wine's HID bus leaves alone - the game reads Steam Input's output, not the pad under it, as on
|
||||
* a Steam Deck. With none (Steam Input off for the game) they keep the virtual identity, so the
|
||||
* game still has a controller.
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <limits.h>
|
||||
@@ -39,20 +12,16 @@
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* The app opens one ring per configured controller; four is what its launcher offers. Nodes from
|
||||
* UINPUT_BASE up are the virtual pads made through libfakeinput's /dev/uinput stand-in. */
|
||||
#define RING_MAX 4
|
||||
#define UINPUT_BASE 16
|
||||
#define PAD_MAX 64
|
||||
#define EVENT_MINOR_BASE 64
|
||||
|
||||
/* BUS_VIRTUAL, and the identity Steam Input gives the gamepad it presents to a game. */
|
||||
#define PAD_UEVENT_FORMAT \
|
||||
"PRODUCT=6/28de/11ff/110\n" \
|
||||
"NAME=\"Generic HID Gamepad %d\"\n" \
|
||||
"PHYS=\"usb-fakeinput/input%d\"\n"
|
||||
|
||||
/* The identity libfakeinput gives the pad itself (FAKE_EVDEV_IDENTITY=xbox360). */
|
||||
#define PAD_PHYSICAL_UEVENT_FORMAT \
|
||||
"PRODUCT=3/45e/28e/110\n" \
|
||||
"NAME=\"Xbox 360 Controller (%d)\"\n" \
|
||||
@@ -70,11 +39,6 @@ static struct pad pads[PAD_MAX];
|
||||
static int pad_count;
|
||||
static pthread_mutex_t virtual_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/*
|
||||
* The slots the app published rings for, named in FAKE_EVDEV_MEMFD_PATHS as "<slot>=<path>"
|
||||
* separated by semicolons. Without it the process has no pads of the session's and every call
|
||||
* here is a passthrough.
|
||||
*/
|
||||
static void discover_pads(void) {
|
||||
const char *spec = getenv("FAKE_EVDEV_MEMFD_PATHS");
|
||||
const char *entry;
|
||||
@@ -113,7 +77,6 @@ static int uinput_enabled(void) {
|
||||
return enabled != NULL && atoi(enabled) != 0;
|
||||
}
|
||||
|
||||
/* Reads the .uevent libfakeinput wrote for virtual pad <node> into buf; 0 when there is none. */
|
||||
static int read_virtual_uevent(int node, char *buf, size_t size) {
|
||||
const char *dir = getenv("FAKE_EVDEV_DIR");
|
||||
char path[PATH_MAX];
|
||||
@@ -138,10 +101,6 @@ static int any_virtual_pad(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Brings the entry for event<node> up to date before Wine resolves it: a virtual pad comes and
|
||||
* goes with the client, and the app's pads change identity with it.
|
||||
*/
|
||||
static void refresh_pad(int node) {
|
||||
struct pad *pad;
|
||||
|
||||
@@ -168,7 +127,6 @@ static void refresh_pad(int node) {
|
||||
pthread_mutex_unlock(&virtual_lock);
|
||||
}
|
||||
|
||||
/* The pad a synthetic syspath names, or NULL when the path is not one of ours. */
|
||||
static struct pad *pad_for_syspath(const char *syspath) {
|
||||
int i;
|
||||
|
||||
@@ -180,7 +138,6 @@ static struct pad *pad_for_syspath(const char *syspath) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* A device object is ours exactly when it is one of the pads. */
|
||||
static struct pad *pad_for_device(void *device) {
|
||||
int i;
|
||||
|
||||
@@ -192,7 +149,6 @@ static struct pad *pad_for_device(void *device) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The pad /sys/class/input/<name> stands for, or NULL when the path names something else. */
|
||||
static struct pad *pad_for_syslink(const char *path) {
|
||||
static const char prefix[] = "/sys/class/input/";
|
||||
const char *name;
|
||||
@@ -213,7 +169,6 @@ static void *next_symbol(const char *name) { return dlsym(RTLD_NEXT, name); }
|
||||
char *bl_cached_realpath(const char *path, char *resolved, char *(*real)(const char *, char *))
|
||||
__attribute__((visibility("hidden")));
|
||||
|
||||
/* Wine reaches libudev from its HID bus driver, which is the only caller these pads are for. */
|
||||
static int caller_is_winebus(void *caller) {
|
||||
Dl_info info;
|
||||
|
||||
@@ -228,7 +183,6 @@ char *realpath(const char *path, char *resolved) {
|
||||
|
||||
if (pad != NULL) {
|
||||
if (resolved == NULL) return strdup(pad->syspath);
|
||||
/* PATH_MAX is what the caller promises when it passes a buffer. */
|
||||
memcpy(resolved, pad->syspath, strlen(pad->syspath) + 1);
|
||||
return resolved;
|
||||
}
|
||||
@@ -336,10 +290,6 @@ dev_t udev_device_get_devnum(void *device) {
|
||||
return real_get(device);
|
||||
}
|
||||
|
||||
/*
|
||||
* A pad has no bus behind it, so it stands in for its own input device and has no other parent.
|
||||
* The reference is a borrowed one either way.
|
||||
*/
|
||||
void *udev_device_get_parent_with_subsystem_devtype(void *device, const char *subsystem,
|
||||
const char *devtype) {
|
||||
static void *(*real_get)(void *, const char *, const char *);
|
||||
|
||||
@@ -1,16 +1,3 @@
|
||||
/*
|
||||
* Adreno revisions the runtime's Turnip does not know, reported as the revision it does.
|
||||
*
|
||||
* Retail SM8850 phones report their A840 as chip_id 0x44050A21 (KGSL gpu_model "Adreno840v2").
|
||||
* Mesa only lists 0x44050A31, so the runtime's glibc Turnip refuses the device outright
|
||||
* ("device (chip_id = 44050A21, gpu_id = 6860) is unsupported") and gamescope exits before Steam
|
||||
* starts. Banners-Turnip fixes its own builds by registering the v2 id on the same A840 GPU info
|
||||
* (patches/a840v2.py); answering KGSL's device-info query with the known id has the same effect
|
||||
* on any Turnip in the session, including the one the runtime was built with. A driver that
|
||||
* already knows the v2 id resolves the rewritten one to the same entry.
|
||||
*
|
||||
* Only the KGSL device-info property is touched. Its layout is the kernel's uapi (msm_kgsl.h).
|
||||
*/
|
||||
#define _GNU_SOURCE 1
|
||||
#include <stddef.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -38,7 +25,7 @@ static const struct {
|
||||
unsigned int reported;
|
||||
unsigned int known;
|
||||
} CHIP_IDS[] = {
|
||||
{0x44050A21, 0x44050A31}, /* Adreno 840v2 -> Adreno 840 */
|
||||
{0x44050A21, 0x44050A31},
|
||||
};
|
||||
|
||||
void bl_kgsl_chip_id_fixup(unsigned long request, void *arg, int rc) {
|
||||
|
||||
@@ -1,19 +1,3 @@
|
||||
/*
|
||||
* A zero-timeout KGSL timestamp wait answered as the poll it was meant to be.
|
||||
*
|
||||
* Turnip's KGSL backend emulates timeline semaphores with timestamps, and asks "has this one
|
||||
* retired yet?" by waiting on it with IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID and a timeout of 0.
|
||||
* KGSL reads a timeout of 0 as no timeout at all, so the poll blocks until the GPU gets there.
|
||||
* Mesa's timeline bookkeeping polls like that under a lock on every signalling submit, which put
|
||||
* vkd3d-proton, DXVK, gamescope and Zink in lock-step with the GPU: one frame queued, never two.
|
||||
* Found and measured by Bannerlator (PROGRESS_LOG 2026-09-29: a D3D12 demo went from 614 to
|
||||
* 4335 fps with the same answer given in its Vulkan adapter); the driver-side fix is on
|
||||
* Banners-Turnip, and this covers the drivers that do not carry it yet.
|
||||
*
|
||||
* The answer comes from the context's retired timestamp, compared the way KGSL compares them
|
||||
* (with wrap-around). Anything the read does not answer - an unknown context, a device that is not
|
||||
* KGSL - goes to the kernel as before. BL_NO_KGSL_POLL_FIX=1 turns it off.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
@@ -50,7 +34,6 @@ static int enabled(void) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
/* True when the call was answered here, with its result in *rc (and errno set on failure). */
|
||||
__attribute__((visibility("hidden"))) int bl_kgsl_poll(int (*real)(int, unsigned long, void *),
|
||||
int fd, unsigned long request, void *arg,
|
||||
int *rc) {
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
/*
|
||||
* Lock files taken by hard link, which Android denies apps.
|
||||
*
|
||||
* libICE and libXau lock an authority file the classic way: create "<file>-c", then link() it to
|
||||
* "<file>-l" - the link either appears or fails because the other holder's is there. Android's
|
||||
* SELinux policy refuses hard links in an app's data, so the link fails for everyone, the lock is
|
||||
* never taken, and Plasma's session manager gives up at "Could not lock ICEAuthority file". With
|
||||
* no session manager there is no Plasma desktop.
|
||||
*
|
||||
* Only that convention is answered here: when the real link is refused and the new name ends in
|
||||
* "-l", a symlink stands in. Creating a symlink fails on an existing name just as a link does, so
|
||||
* the lock excludes as before, and the holder removes both names when it is done. Every other
|
||||
* link keeps the real answer: a program that links a file into place and then deletes the
|
||||
* original would be left with a dangling symlink.
|
||||
*
|
||||
* That pattern itself is answered for one caller that asks: with DROIDDECK_LINK_RENAME=1 (the
|
||||
* session sets it for localedef, which names a finished locale archive that way) a refused link
|
||||
* becomes a rename that will not replace an existing name, which is all the link promised there.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -38,9 +19,7 @@ static int lock_name(const char *path) {
|
||||
return n > 2 && strcmp(path + n - 2, "-l") == 0;
|
||||
}
|
||||
|
||||
/* The answer to link(oldpath, newpath), given the real call's: a refused lock link becomes a symlink. */
|
||||
__attribute__((visibility("hidden"))) int bl_link_lock(const char *oldpath, const char *newpath, int result) {
|
||||
/* libc's own symlink: dircache.c's wrapper may be holding its lock around this call. */
|
||||
static int (*real_symlink)(const char *, const char *);
|
||||
if (result == 0 || !refused(errno)) return result;
|
||||
if (moves_instead()) return renameat2(AT_FDCWD, oldpath, AT_FDCWD, newpath, RENAME_NOREPLACE);
|
||||
@@ -49,7 +28,6 @@ __attribute__((visibility("hidden"))) int bl_link_lock(const char *oldpath, cons
|
||||
return real_symlink(oldpath, newpath);
|
||||
}
|
||||
|
||||
/* 64-bit builds wrap link() in dircache.c, which hands its result to bl_link_lock. */
|
||||
#if __SIZEOF_POINTER__ != 8
|
||||
int link(const char *oldpath, const char *newpath) {
|
||||
static int (*real_link)(const char *, const char *);
|
||||
@@ -64,7 +42,6 @@ int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath,
|
||||
int result = real_linkat(olddirfd, oldpath, newdirfd, newpath, flags);
|
||||
if (result != 0 && refused(errno) && flags == 0 && moves_instead())
|
||||
return renameat2(olddirfd, oldpath, newdirfd, newpath, RENAME_NOREPLACE);
|
||||
/* A relative old name would resolve against the new name's directory as a symlink's target. */
|
||||
if (result != 0 && refused(errno) && lock_name(newpath) && oldpath[0] == '/' && flags == 0)
|
||||
return symlinkat(oldpath, newdirfd, newpath);
|
||||
return result;
|
||||
|
||||
@@ -1,24 +1,7 @@
|
||||
/*
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with names
|
||||
* changed to this project's. The reasoning below is the original author's.
|
||||
*
|
||||
* File locking for the game library on external storage.
|
||||
*
|
||||
* The user's games are bound in from /storage/emulated, which Android serves over FUSE, and that
|
||||
* filesystem implements no locking at all: flock() and fcntl()'s lock commands answer ENOSYS for
|
||||
* every file under it. The Steam client takes a shared lock on each content file as it validates
|
||||
* or updates a title and treats the refusal as a failure, so a download walks its progress back
|
||||
* and forth instead of finishing; a game reading its own data hits the same wall.
|
||||
*
|
||||
* Where the kernel can lock, it does: the real call runs first and its answer stands, so files on
|
||||
* the app's own f2fs storage keep genuine cross-process exclusion. Only the filesystem that cannot
|
||||
* lock at all is answered here, and granting is the honest reading of it - a filesystem with no
|
||||
* lock state has nothing to contend over, and the one other party that could contend is inside
|
||||
* this same session. Reporting failure instead buys no safety and costs the download.
|
||||
*
|
||||
* F_GETLK is the exception: it asks who holds a lock, and on a filesystem holding none the true
|
||||
* answer is "nobody", so it is reported unlocked rather than granted.
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -28,7 +11,6 @@
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* The filesystem refuses the whole operation, rather than declining this particular lock. */
|
||||
static int unsupported(int error) {
|
||||
return error == ENOSYS || error == ENOTSUP || error == EOPNOTSUPP;
|
||||
}
|
||||
@@ -44,12 +26,6 @@ int flock(int fd, int operation) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* fcntl()'s third argument is an int, a pointer, or absent depending on the command; only the
|
||||
* lock commands are of interest here and all of those take a struct flock *. Anything else is
|
||||
* passed straight through as a void * - wide enough for both an int and a pointer on every ABI
|
||||
* the runtime is built for.
|
||||
*/
|
||||
static int is_lock_command(int cmd) {
|
||||
switch (cmd) {
|
||||
case F_SETLK:
|
||||
@@ -104,6 +80,5 @@ int fcntl(int fd, int cmd, ...) {
|
||||
}
|
||||
|
||||
#if defined(__GLIBC__) && defined(F_SETLK64)
|
||||
/* glibc's large-file build redirects both names; the runtime is 64-bit, so they are the same call. */
|
||||
int fcntl64(int fd, int cmd, ...) __attribute__((alias("fcntl")));
|
||||
#endif
|
||||
@@ -1,11 +1,3 @@
|
||||
/*
|
||||
* Loopback socket ownership for Steam's IPC peer check.
|
||||
*
|
||||
* Steam validates a websocket peer by running lsof to find which process owns a 127.0.0.1 port.
|
||||
* The Android sandbox denies both /proc/net/tcp and sock_diag, so no tool can answer. Every Steam
|
||||
* process is preloaded with this library, so each records the ports it binds and connects, and the
|
||||
* lsof Steam spawns is answered from that shared registry instead of being run.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <arpa/inet.h>
|
||||
#include <spawn.h>
|
||||
@@ -54,8 +46,6 @@ static int loopback_family(const struct sockaddr *address, socklen_t length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Record that this process owns a loopback socket on its local port; peer is the far end's port,
|
||||
* 0 for a listening socket. */
|
||||
static void record_port(int fd, unsigned peer) {
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t len = sizeof(ss);
|
||||
@@ -119,7 +109,6 @@ typedef int (*connect_fn)(int, const struct sockaddr *, socklen_t);
|
||||
typedef int (*accept4_fn)(int, struct sockaddr *, socklen_t *, int);
|
||||
static unsigned guarded_port(void);
|
||||
|
||||
/* udevmon.c: a stand-in for the netlink socket the sandbox refuses, bound here without the kernel. */
|
||||
__attribute__((visibility("hidden"))) int bl_udevmon_stand_in(int fd);
|
||||
|
||||
int bind(int fd, const struct sockaddr *addr, socklen_t len) {
|
||||
@@ -239,7 +228,6 @@ int connect(int fd, const struct sockaddr *addr, socklen_t len) {
|
||||
if (peer) record_port(fd, peer);
|
||||
int ret = real(fd, addr, len);
|
||||
if (ret == 0 || errno == EINPROGRESS) {
|
||||
/* The caller goes on to test for EINPROGRESS, which the bookkeeping must not disturb. */
|
||||
int saved = errno;
|
||||
record_port(fd, peer);
|
||||
errno = saved;
|
||||
@@ -267,7 +255,6 @@ int accept(int fd, struct sockaddr *addr, socklen_t *len) {
|
||||
return accept4(fd, addr, len, 0);
|
||||
}
|
||||
|
||||
/* binfmt.c: an exec of a program the kernel cannot run, handed to droiddeck-open in the desktop. */
|
||||
extern char **environ;
|
||||
typedef int (*spawn_fn)(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *,
|
||||
char *const[], char *const[]);
|
||||
@@ -279,8 +266,6 @@ __attribute__((visibility("hidden"))) int bl_binfmt_spawn(pid_t *pid, const char
|
||||
const posix_spawnattr_t *attr, char *const argv[], char *const envp[],
|
||||
spawn_fn real);
|
||||
|
||||
/* lsof would read the denied /proc/net/tcp; answer its -i TCP@host:port query from the registry
|
||||
* instead of executing it. Recognised only when invoked as lsof with that query. */
|
||||
static int maybe_answer_lsof(const char *path, char *const argv[]) {
|
||||
const char *base = strrchr(path, '/');
|
||||
base = base ? base + 1 : path;
|
||||
@@ -302,7 +287,7 @@ static int maybe_answer_lsof(const char *path, char *const argv[]) {
|
||||
snprintf(path_buf, sizeof(path_buf), "%s/p%u", net_dir(), (unsigned)atoi(port_str));
|
||||
int in = open(path_buf, O_RDONLY);
|
||||
if (in < 0) {
|
||||
_exit(1); /* lsof exit code for "nothing found" */
|
||||
_exit(1);
|
||||
}
|
||||
char buf[64];
|
||||
int n = read(in, buf, sizeof(buf) - 1);
|
||||
@@ -314,14 +299,12 @@ static int maybe_answer_lsof(const char *path, char *const argv[]) {
|
||||
int pid = 0, ppid = 0, uid = 0;
|
||||
unsigned peer = 0;
|
||||
sscanf(buf, "%d %d %d %u", &pid, &ppid, &uid, &peer);
|
||||
/* Steam splits the address on "->" and wants exactly two halves, taking the port it asked
|
||||
* about from the left one; only a listening socket has no far end. */
|
||||
char out[160];
|
||||
int m = peer ? snprintf(out, sizeof(out), "p%d\nR%d\nu%d\nn127.0.0.1:%u->127.0.0.1:%u\n",
|
||||
pid, ppid, uid, (unsigned)atoi(port_str), peer)
|
||||
: snprintf(out, sizeof(out), "p%d\nR%d\nu%d\nn127.0.0.1:%u\n",
|
||||
pid, ppid, uid, (unsigned)atoi(port_str));
|
||||
if (write(1, out, m) != m) { /* best effort */ }
|
||||
if (write(1, out, m) != m) { }
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
@@ -334,8 +317,6 @@ int execve(const char *path, char *const argv[], char *const envp[]) {
|
||||
return bl_binfmt_retry(path, argv, envp, errno);
|
||||
}
|
||||
|
||||
/* popen(3) and posix_spawn(3) reach lsof without going through the execve symbol above. The
|
||||
* check is cheap, so a spawned lsof is answered here too by handling it in a short-lived child. */
|
||||
static int answer_lsof_via_spawn(const char *path, char *const argv[], pid_t *pid) {
|
||||
pid_t child = fork();
|
||||
if (child < 0) {
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
/*
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with names
|
||||
* changed to this project's. The reasoning below is the original author's.
|
||||
*
|
||||
* Network interfaces for a sandbox that hides them.
|
||||
*
|
||||
* Android denies an app the rtnetlink dump behind getifaddrs() and if_nameindex(), the hardware
|
||||
* address ioctl, and every table under /proc/net. Wine builds its adapter, address, route and
|
||||
* neighbour tables from exactly those, so a game saw a machine with no adapter, no address, no
|
||||
* gateway and no MAC, and one that checks its adapters before going online waited for good.
|
||||
* The app knows the real link from ConnectivityManager and writes it to /etc/droiddeck-net;
|
||||
* whatever the kernel refuses is answered from that file. Anything the kernel does answer wins.
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
#include <arpa/inet.h>
|
||||
#include <dlfcn.h>
|
||||
@@ -108,9 +99,6 @@ static int fresh(long long *at) {
|
||||
return then != 0 && now_ns() - then < FRESH_NS;
|
||||
}
|
||||
|
||||
/* Wine's network driver reads the link several times for each table it builds, and some games
|
||||
* have it build them all hundreds of times a second. The app rewrites the file when the device
|
||||
* changes network, so a reading stands for a second. */
|
||||
static pthread_mutex_t link_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct link link_read;
|
||||
static int link_ok;
|
||||
@@ -128,7 +116,6 @@ static int load_link(struct link *link) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* See drm.c: a fork must not leave the lock held by a thread the child does not have. */
|
||||
static void link_lock_before_fork(void) { pthread_mutex_lock(&link_lock); }
|
||||
static void link_unlock_after_fork(void) { pthread_mutex_unlock(&link_lock); }
|
||||
static void link_reset_after_fork(void) { pthread_mutex_init(&link_lock, NULL); }
|
||||
@@ -137,8 +124,6 @@ __attribute__((constructor)) static void install_link_fork_handlers(void) {
|
||||
pthread_atfork(link_lock_before_fork, link_unlock_after_fork, link_reset_after_fork);
|
||||
}
|
||||
|
||||
/* When the kernel's own list was of no use, it is not asked again for a second: each asking binds
|
||||
* a netlink socket, a stop in the tracer, only to be refused again. */
|
||||
static long long ifaddrs_unusable_at, nameindex_unusable_at;
|
||||
|
||||
static void prefix_mask(int family, unsigned prefix, unsigned char *out) {
|
||||
@@ -152,8 +137,6 @@ static int is_link_local(const struct link_addr *addr) {
|
||||
return addr->family == AF_INET6 && addr->bytes[0] == 0xfe && (addr->bytes[1] & 0xc0) == 0x80;
|
||||
}
|
||||
|
||||
/* One allocation per list. ifa_data of the head points at the head itself, which glibc never
|
||||
* does, so freeifaddrs() can tell the two kinds of list apart without keeping any state. */
|
||||
struct entry {
|
||||
struct ifaddrs ifa;
|
||||
struct sockaddr_storage addr, mask, extra;
|
||||
@@ -246,7 +229,6 @@ int getifaddrs(struct ifaddrs **out) {
|
||||
if (asked) __atomic_store_n(&ifaddrs_unusable_at, now_ns(), __ATOMIC_RELAXED);
|
||||
if (rc == 0 && list) real_freeifaddrs(list);
|
||||
|
||||
/* A leading slot keeps fill_entry()'s back link in bounds; the list starts after it. */
|
||||
struct entry *block = calloc((size_t) link.addr_count + 5, sizeof(*block));
|
||||
if (block == NULL) {
|
||||
errno = ENOMEM;
|
||||
@@ -277,7 +259,6 @@ void freeifaddrs(struct ifaddrs *list) {
|
||||
real_freeifaddrs(list);
|
||||
}
|
||||
|
||||
/* Names live in the same allocation as the array, right behind it; glibc strdup()s each one. */
|
||||
struct name_block {
|
||||
struct if_nameindex index[3];
|
||||
char names[2][IFNAMSIZ];
|
||||
@@ -353,7 +334,6 @@ char *if_indextoname(unsigned int index, char name[IF_NAMESIZE]) {
|
||||
static int mac_unusable(const struct ifreq *ifr) {
|
||||
const unsigned char *a = (const unsigned char *) ifr->ifr_hwaddr.sa_data;
|
||||
if (ifr->ifr_hwaddr.sa_family != ARPHRD_ETHER) return 1;
|
||||
/* Android hands out 02:00:00:00:00:00 where it hides the real address. */
|
||||
int rest = a[1] | a[2] | a[3] | a[4] | a[5];
|
||||
return (a[0] & 0x03) || (rest == 0 && (a[0] == 0 || a[0] == 0x02));
|
||||
}
|
||||
@@ -420,15 +400,13 @@ static int is_link_query(unsigned long request) {
|
||||
|| request == SIOCGIFBRDADDR;
|
||||
}
|
||||
|
||||
void bl_kgsl_chip_id_fixup(unsigned long request, void *arg, int rc); /* kgslid.c */
|
||||
void bl_kgsl_chip_id_fixup(unsigned long request, void *arg, int rc);
|
||||
#include "../../quest/kgsl_compat.h"
|
||||
int bl_kgsl_poll(int (*real)(int, unsigned long, void *), int fd, unsigned long request,
|
||||
void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_ntsync_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_drm_gem_close(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
|
||||
/* Every DRM and evdev call comes through here, so the lookup is done once. Two threads racing
|
||||
* to store it store the same pointer. */
|
||||
int ioctl(int fd, unsigned long request, ...) {
|
||||
typedef int (*ioctl_fn)(int, unsigned long, void *);
|
||||
static ioctl_fn real;
|
||||
@@ -538,7 +516,6 @@ static const char *denied_table(const char *path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* A memfd rather than fmemopen(): the stream owns its contents, so fclose() frees everything. */
|
||||
static FILE *synthesize(const char *table) {
|
||||
struct link link;
|
||||
if (!load_link(&link)) return NULL;
|
||||
@@ -558,7 +535,6 @@ static FILE *synthesize(const char *table) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/* tracer.c */
|
||||
int bl_status_without_tracer(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
|
||||
static FILE *open_stream(fopen_fn real, const char *path, const char *mode) {
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
/*
|
||||
* noexec.c: FEX runs an x86 program and its libraries where they lie, on noexec shared storage too.
|
||||
* FEX maps them with the guest's PROT_EXEC, which the kernel refuses for a file on a noexec mount,
|
||||
* but it never runs those pages itself - it runs its own translation of them - so a mapping or an
|
||||
* mprotect refused for that alone is made without PROT_EXEC. Only in FEX's own processes.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -12,7 +6,6 @@
|
||||
#include <sys/statvfs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* NOEXEC_TEST: tools/tests builds it for the host. */
|
||||
#if defined(__aarch64__) || defined(NOEXEC_TEST)
|
||||
|
||||
static int in_fex(void) {
|
||||
@@ -28,7 +21,6 @@ static int in_fex(void) {
|
||||
return known;
|
||||
}
|
||||
|
||||
/* After an mmap failed (fsync.c's mmap asks): whether to map it again without PROT_EXEC. */
|
||||
__attribute__((visibility("hidden"))) int bl_noexec_retry(int prot, int flags, int fd) {
|
||||
int error = errno;
|
||||
struct statvfs vfs;
|
||||
@@ -40,7 +32,6 @@ __attribute__((visibility("hidden"))) int bl_noexec_retry(int prot, int flags, i
|
||||
|
||||
static int (*real_mprotect)(void *, size_t, int);
|
||||
|
||||
/* Looked up before anything runs: Wine calls mprotect from its signal handlers, where dlsym is unsafe. */
|
||||
__attribute__((constructor)) static void noexec_init(void) {
|
||||
real_mprotect = (int (*)(void *, size_t, int))dlsym(RTLD_NEXT, "mprotect");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* droiddeck-ntsync: a userspace implementation of the /dev/ntsync interface for kernels without the driver.
|
||||
* Credit: ntsync, the kernel driver and its Wine client, by Elizabeth Figura. */
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -1243,7 +1241,6 @@ int bl_udevmon_recvmsg(int fd, struct msghdr *msg, int flags, ssize_t (*real_rec
|
||||
ssize_t recvmsg(int fd, struct msghdr *msg, int flags) {
|
||||
static ssize_t (*real)(int, struct msghdr *, int);
|
||||
if (!real) real = (ssize_t (*)(int, struct msghdr *, int))dlsym(RTLD_NEXT, "recvmsg");
|
||||
/* udevmon.c's stand-in netlink sockets first: their messages are dressed as udevd's. */
|
||||
ssize_t answered;
|
||||
if (msg && bl_udevmon_recvmsg(fd, msg, flags, real, &answered)) return answered;
|
||||
ssize_t r = real(fd, msg, flags);
|
||||
|
||||
@@ -1,29 +1,7 @@
|
||||
/*
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with names
|
||||
* changed to this project's. The reasoning below is the original author's.
|
||||
*
|
||||
* The adjustments a session's opens need.
|
||||
*
|
||||
* O_NOATIME on the game library: the user's games are bound in from shared storage, which Android
|
||||
* serves over FUSE with every file owned by its media provider rather than by the app. O_NOATIME
|
||||
* is reserved for a file's owner, so the kernel refuses such an open outright with EPERM. The
|
||||
* Steam client opens every content file it reads that way, and treats the refusal as the file
|
||||
* being unreadable or missing: a validation reports corrupt or missing files and an update is
|
||||
* cancelled. The flag only asks the filesystem to skip an access-time update; the open is retried
|
||||
* without it. Every other refusal is passed through untouched, and a file the process may open
|
||||
* with the flag still is.
|
||||
*
|
||||
* The kernel's trace marker: tracefs is world-writable here, so the client's tier0 opens
|
||||
* /sys/kernel/tracing/trace_marker at startup - three times over, once per module that profiles -
|
||||
* and writes a "[%s] tgid=%d begin_ctx=%lld" line for every scope it enters. Nothing in the
|
||||
* session reads those markers, and they are one more thing that can land in the wrong file when
|
||||
* a descriptor number changes hands (tracer.c has the cause). They have been found appended to an
|
||||
* app manifest, which the client then cannot parse, to a download's state file, and to content
|
||||
* chunks, which it quarantines as corrupt. Refused the descriptor, tier0 writes nothing at all and
|
||||
* has nothing to lose.
|
||||
*
|
||||
* A process status is served without the container's tracer in it; see tracer.c.
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -55,7 +33,6 @@ static int retry_without_noatime(int fd, int flags) {
|
||||
return fd < 0 && errno == EPERM && (flags & O_NOATIME);
|
||||
}
|
||||
|
||||
/* Both spellings tier0 tries, the debugfs one first. */
|
||||
static int is_trace_marker(const char *path) {
|
||||
return path != NULL
|
||||
&& (strcmp(path, "/sys/kernel/tracing/trace_marker") == 0
|
||||
@@ -83,7 +60,6 @@ int open(const char *path, int flags, ...) {
|
||||
}
|
||||
fd = bl_dircache_create(AT_FDCWD, path, flags, mode, via_open);
|
||||
if (retry_without_noatime(fd, flags)) fd = real_open(path, flags & ~O_NOATIME, mode);
|
||||
/* A read-only file the Steam client rewrites (perms.c). */
|
||||
if (fd < 0 && bl_writable_retry(AT_FDCWD, path, flags)) fd = real_open(path, flags & ~O_NOATIME, mode);
|
||||
return fd;
|
||||
}
|
||||
@@ -113,6 +89,5 @@ int openat(int dirfd, const char *path, int flags, ...) {
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* The runtime is 64-bit, so the large-file names are the same calls. */
|
||||
int open64(const char *path, int flags, ...) __attribute__((alias("open")));
|
||||
int openat64(int dirfd, const char *path, int flags, ...) __attribute__((alias("openat")));
|
||||
@@ -1,18 +1,3 @@
|
||||
/*
|
||||
* Path lookups the Steam client repeats, answered from a short-lived cache.
|
||||
*
|
||||
* While it registers its compatibility tools after logon, the client resolves the same few
|
||||
* directories - its local tools under compatibilitytools.d and its own platform directory - with
|
||||
* realpath() and access() thousands of times a second. Each realpath() is one readlinkat() per
|
||||
* path component, and under proot every one of those is a trapped syscall with a round trip
|
||||
* through the tracer. Measured on an AYN Thor, that loop was 23 of the client's 31 seconds of
|
||||
* startup, with proot busy for 16 of them.
|
||||
*
|
||||
* Only the client itself uses the cache, never a game or a helper. Only successful answers are
|
||||
* kept, and only for a moment: a path that stops existing is noticed within PATH_CACHE_TTL_NS, and
|
||||
* one that starts existing is never hidden, since failures always go to the filesystem.
|
||||
* BL_NO_PATH_CACHE=1 turns it off.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -152,7 +137,6 @@ static int (*next_faccessat(void))(int, const char *, int, int) {
|
||||
return real;
|
||||
}
|
||||
|
||||
/* binfmt.c: a program on noexec storage, which the desktop runs all the same. */
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_runnable(const char *path, int mode);
|
||||
|
||||
static int check_cwd(const char *path, int mode, int flags) {
|
||||
|
||||
@@ -1,20 +1,3 @@
|
||||
/*
|
||||
* Root's way past a read-only file, for the Steam client.
|
||||
*
|
||||
* The client runs as "root" inside the session - the rootfs names the app's own uid root, and
|
||||
* proot (-i) shows it that uid - but the kernel treats it as the ordinary user it is. The client
|
||||
* leaves many content files read-only (r-x------,
|
||||
* ~290 files of Proton Experimental (ARM64) alone), and when an update later rewrites one of them
|
||||
* it opens the file for writing expecting root's permission to override the mode. The kernel
|
||||
* refuses (EACCES), the client reports "Missing file permissions" and cancels the update
|
||||
* (2026-09-26: Proton Experimental (ARM64), "CFileWriter: errno: 13 ... wineopenxr.dll").
|
||||
*
|
||||
* So for the client's own processes, a refused write-open of a file this user owns is answered the
|
||||
* way root's would be: the owner's write bit is added - to the file, or to the directory a new
|
||||
* file is being created in - and the open is tried once more. chmod only succeeds on what the app
|
||||
* owns, so nothing it could not already change is touched. Games, Wine and everything else keep
|
||||
* ordinary permissions: only the processes started from the client's own directories take this.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@@ -28,11 +11,6 @@ static int in_steam_dirs(const char *path) {
|
||||
|| strstr(path, "/Steam/ubuntu12_64/") != NULL || strstr(path, "/Steam/linuxarm64/") != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* The client and its helpers run from the Steam root's platform directories. The kernel's
|
||||
* /proc/self/exe names proot's loader for every process in the session, so the program's own
|
||||
* name - the path it was started by - is asked as well.
|
||||
*/
|
||||
static int is_steam_client(void) {
|
||||
static int cached = -1;
|
||||
char exe[PATH_MAX];
|
||||
@@ -52,10 +30,6 @@ static int grant_owner_write(int dirfd, const char *path) {
|
||||
return fchmodat(dirfd, path, (st.st_mode & 07777) | S_IWUSR, 0) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* After an open refused with EACCES: returns 1 when a write bit was added and the open is worth
|
||||
* one more try. errno is left as the open set it.
|
||||
*/
|
||||
__attribute__((visibility("hidden")))
|
||||
int bl_writable_retry(int dirfd, const char *path, int flags) {
|
||||
int saved = errno;
|
||||
@@ -67,7 +41,6 @@ int bl_writable_retry(int dirfd, const char *path, int flags) {
|
||||
if (faccessat(dirfd, path, F_OK, 0) == 0) {
|
||||
granted = grant_owner_write(dirfd, path);
|
||||
} else if (flags & O_CREAT) {
|
||||
/* A new file in a read-only directory. */
|
||||
slash = strrchr(path, '/');
|
||||
if (slash == NULL) {
|
||||
granted = grant_owner_write(dirfd, ".");
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Shared with the Android driver wrapper so the two translation paths cannot drift. */
|
||||
#include "../../quest/kgsl_compat.c"
|
||||
@@ -1,11 +1,3 @@
|
||||
/*
|
||||
* get_robust_list(2) for the session's own threads.
|
||||
*
|
||||
* Android's app policy refuses the call, and Steam's cross-process mutex insists on seeing the
|
||||
* head glibc registered. The kernel's list protocol gives it away: a robust mutex this thread
|
||||
* holds is linked directly behind the registered head, so locking a private one and following
|
||||
* the link back finds the head without depending on libc's layout.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -48,8 +40,6 @@ static struct robust_list_head *thread_robust_head(void) {
|
||||
if (pthread_mutex_lock(&mutex) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
/* The mutex holds tids and lock words beside the link, so a word is only followed
|
||||
* through a read that fails instead of faulting on a non-pointer. */
|
||||
uintptr_t lo = (uintptr_t)&mutex, hi = lo + sizeof(mutex);
|
||||
for (uintptr_t p = lo; p + sizeof(void *) <= hi && !head; p += sizeof(void *)) {
|
||||
struct robust_list_head *candidate = *(struct robust_list_head **)p;
|
||||
|
||||
@@ -1,23 +1,3 @@
|
||||
/*
|
||||
* The free space a library reports.
|
||||
*
|
||||
* A library's games can live somewhere the folder that names the library does not. The card
|
||||
* library is exactly that: its steamapps/common is bound to the card, but the directory above it
|
||||
* belongs to the runtime image in the phone's own storage, and that directory is what the client
|
||||
* measures. So it offers both install locations with the phone's free space against each, and the
|
||||
* card's real figure - seventeen gigabytes more, on the device this was found on - never appears.
|
||||
*
|
||||
* The number is not only cosmetic: the client refuses an install it believes will not fit. Once
|
||||
* the phone fills up it would turn down a card install with room to spare, and say nothing about
|
||||
* why.
|
||||
*
|
||||
* Moving the whole library onto the card would fix the number and break something worse. The
|
||||
* prefixes under steamapps/compatdata want symlinks and file locks, and the card is served over
|
||||
* FUSE, which gives us neither - that is why they are kept in the runtime image in the first
|
||||
* place. So the question is answered where the content actually is: a query about a library root
|
||||
* named in BL_LIBRARY_SPACE is served from its steamapps/common, the bind that points at the
|
||||
* card. Every other path is passed through untouched.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <stddef.h>
|
||||
@@ -26,8 +6,6 @@
|
||||
#include <sys/statfs.h>
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
/* A library root, or its steamapps, resolved to the directory that holds the games. Returns the
|
||||
* rewritten path in `buf`, or NULL when `path` is not one of ours and should be left alone. */
|
||||
static const char *content_of(const char *path, char *buf, size_t len) {
|
||||
const char *roots = getenv("BL_LIBRARY_SPACE");
|
||||
if (!path || !roots || !*roots)
|
||||
@@ -38,8 +16,6 @@ static const char *content_of(const char *path, char *buf, size_t len) {
|
||||
const char *end = strchr(roots, ':');
|
||||
size_t root_len = end ? (size_t)(end - roots) : strlen(roots);
|
||||
if (root_len > 0) {
|
||||
/* The root itself, or the steamapps directly beneath it. Anything deeper is already inside
|
||||
* a bind and answers for itself. */
|
||||
int match = (path_len == root_len && !strncmp(path, roots, root_len)) ||
|
||||
(path_len == root_len + 10 && !strncmp(path, roots, root_len) &&
|
||||
!strcmp(path + root_len, "/steamapps"));
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
/*
|
||||
* Opt-in observations for file allocation and writes to the selected Steam library.
|
||||
*
|
||||
* The session enables them only when storage diagnostics are turned on. Counters are local to
|
||||
* each process, allocation details are capped, writes are sampled, and storage.log has a global
|
||||
* size limit because every Steam child shares it.
|
||||
*
|
||||
* LD_PRELOAD cannot see direct syscalls or libc-internal calls that bypass public symbols. A
|
||||
* missing entry therefore does not prove the operation did not happen.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -126,7 +116,6 @@ static void append_line(const char *line, size_t length) {
|
||||
syscall(SYS_close, (long)fd, 0L, 0L, 0L, 0L, 0L);
|
||||
goto done;
|
||||
}
|
||||
/* One small append write per complete line; no per-write log flood. */
|
||||
(void)syscall(SYS_write, (long)fd, (long)line, (long)length, 0L, 0L, 0L);
|
||||
syscall(SYS_close, (long)fd, 0L, 0L, 0L, 0L, 0L);
|
||||
done:
|
||||
@@ -223,7 +212,7 @@ int posix_fallocate(int fd, off_t offset, off_t length) {
|
||||
int call_errno = errno;
|
||||
uint64_t elapsed = now_ns() - start;
|
||||
allocation_line("posix_fallocate", result, call_errno, 0, offset, length, elapsed);
|
||||
errno = entry_errno; /* POSIX requires the error to be returned, leaving errno unchanged. */
|
||||
errno = entry_errno;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -262,8 +251,6 @@ int ftruncate(int fd, off_t length) {
|
||||
int known = 0;
|
||||
if (steam_client()) {
|
||||
if (next_fstat == NULL) next_fstat = dlsym(RTLD_NEXT, "fstat");
|
||||
/* staging_file() reads /proc/self/fd, a round trip through proot: skip it for a shrink, which
|
||||
* is passed through untouched either way. */
|
||||
known = next_fstat != NULL && next_fstat(fd, &st) == 0 && S_ISREG(st.st_mode) &&
|
||||
length >= st.st_size && staging_file(fd);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
/* System V semaphores and shared memory for programs in the Linux runtime.
|
||||
*
|
||||
* Android kernels are built without System V IPC, so semget/shmget fail with ENOSYS. Steam's tier0
|
||||
* creates its client-instance semaphore with semget and gives up when that fails. This library is
|
||||
* LD_PRELOADed into the session and keeps each object in a file under /dev/shm (a bound directory
|
||||
* the whole session shares): a semaphore set is an array of counters waited on with futexes, a
|
||||
* segment is a plain file that shmat maps. Objects are found by the inode of their file, which is
|
||||
* what the id is. semop applies its operations one by one (no all-or-nothing across a set) and
|
||||
* SEM_UNDO is accepted but not performed - enough for the client, which uses single-counter sets.
|
||||
* A message queue is a table of slots in its file: gamescope hands mangoapp (Deck mode's performance
|
||||
* overlay) each frame's timings through one. */
|
||||
#define _GNU_SOURCE
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
@@ -34,7 +23,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#define DIR_DEFAULT "/dev/shm/wnsysv"
|
||||
#define SEM_MAGIC 0x574e5345u /* "WNSE" */
|
||||
#define SEM_MAGIC 0x574e5345u
|
||||
#define MAX_OBJECTS 64
|
||||
|
||||
struct sem_header {
|
||||
@@ -43,15 +32,11 @@ struct sem_header {
|
||||
uint32_t key;
|
||||
uint32_t mode;
|
||||
int32_t creator_pid;
|
||||
/* What IPC_STAT reports as sem_otime / sem_ctime (seconds). The usual race-free init has the
|
||||
* creator semop the new set once, and every other process wait until sem_otime is non-zero;
|
||||
* SteamVR's web helper spins on exactly that. */
|
||||
_Atomic uint32_t otime;
|
||||
_Atomic uint32_t ctime;
|
||||
int32_t pad[9];
|
||||
};
|
||||
_Static_assert(sizeof(struct sem_header) == 64, "semaphore files written by older sessions keep their layout");
|
||||
/* The counters follow the header, one 32-bit word each (a futex word). */
|
||||
|
||||
struct sem_map { int id; struct sem_header *hdr; size_t len; };
|
||||
struct shm_map { void *addr; size_t len; int id; };
|
||||
@@ -76,7 +61,6 @@ static int object_id(int fd) {
|
||||
return (int)(st.st_ino & 0x7fffffff);
|
||||
}
|
||||
|
||||
/* Open the object file of kind ("sem"/"shm") for key, creating it as flags ask. */
|
||||
static int open_object(const char *kind, key_t key, int flags, int *created) {
|
||||
char path[PATH_MAX];
|
||||
int oflags = O_RDWR | O_CLOEXEC;
|
||||
@@ -98,7 +82,6 @@ static int open_object(const char *kind, key_t key, int flags, int *created) {
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* The object file for an id, found by inode. */
|
||||
static int open_by_id(const char *kind, int id) {
|
||||
DIR *d = opendir(object_dir());
|
||||
if (!d) return -1;
|
||||
@@ -141,7 +124,6 @@ static long futex(void *addr, int op, int val, const struct timespec *timeout) {
|
||||
return syscall(SYS_futex, addr, op, val, timeout, NULL, 0);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ semaphores */
|
||||
|
||||
static struct sem_map *sem_lookup(int id) {
|
||||
for (int i = 0; i < MAX_OBJECTS; i++)
|
||||
@@ -227,7 +209,7 @@ int semtimedop(int semid, struct sembuf *sops, size_t nsops, const struct timesp
|
||||
} else if (sem_wait_op(w, sops[i].sem_op, sops[i].sem_flg, timeout) != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (sops[i].sem_op < 0) futex(w, FUTEX_WAKE, INT_MAX, NULL); /* zero-waiters see the change */
|
||||
if (sops[i].sem_op < 0) futex(w, FUTEX_WAKE, INT_MAX, NULL);
|
||||
}
|
||||
atomic_store(&h->otime, (uint32_t)time(NULL));
|
||||
return 0;
|
||||
@@ -293,11 +275,7 @@ int semctl(int semid, int semnum, int cmd, ...) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ shared memory */
|
||||
|
||||
/* Linux keeps a removed segment attachable until the last detach, which X clients rely on: they
|
||||
* remove the segment right after asking the server to attach it. A removed segment is renamed out
|
||||
* of key lookup instead, and removed for good once it has been out of use for a while. */
|
||||
static int remove_shm(int id) {
|
||||
DIR *d = opendir(object_dir());
|
||||
if (!d) return -1;
|
||||
@@ -411,18 +389,18 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ message queues */
|
||||
|
||||
/* Only what gamescope and mangoapp use: msgtyp 0 or > 0, IPC_NOWAIT and IPC_RMID. */
|
||||
#define MSG_MAGIC 0x574e4d51u /* "WNMQ" */
|
||||
|
||||
|
||||
#define MSG_MAGIC 0x574e4d51u
|
||||
#define MSG_SLOTS 32
|
||||
|
||||
struct msg_queue {
|
||||
uint32_t magic;
|
||||
_Atomic int32_t lock; /* 0 free, else the holder's pid */
|
||||
_Atomic int32_t changed; /* bumped on every send and receive; waiters sleep on it */
|
||||
_Atomic int32_t lock;
|
||||
_Atomic int32_t changed;
|
||||
uint64_t next_seq;
|
||||
struct { uint64_t seq; long mtype; size_t len; char data[2048]; } slot[MSG_SLOTS]; /* seq 0: free */
|
||||
struct { uint64_t seq; long mtype; size_t len; char data[2048]; } slot[MSG_SLOTS];
|
||||
};
|
||||
|
||||
static struct msg_queue *msg_map(int id) {
|
||||
@@ -437,7 +415,6 @@ static struct msg_queue *msg_map(int id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* A process killed while holding the lock (Android ends sessions without warning) loses it. */
|
||||
static void msg_lock(struct msg_queue *q) {
|
||||
for (int32_t owner = 0; !atomic_compare_exchange_strong(&q->lock, &owner, getpid()); owner = 0) {
|
||||
if (kill(owner, 0) != 0 && errno == ESRCH) atomic_compare_exchange_strong(&q->lock, &owner, 0);
|
||||
@@ -531,12 +508,6 @@ int msgctl(int msqid, int cmd, struct msqid_ds *buf) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* fork() carries over only the calling thread, so a lock another thread was holding at that
|
||||
* instant stays held in the child by a thread that is not there to release it. Taking it before
|
||||
* the fork makes the copy consistent; the parent then unlocks it and the child, whose one thread
|
||||
* never locked it, gets a fresh one. (WinNative 79aa7f68.)
|
||||
*/
|
||||
static void sysv_lock_before_fork(void) { pthread_mutex_lock(&g_lock); }
|
||||
static void sysv_unlock_after_fork(void) { pthread_mutex_unlock(&g_lock); }
|
||||
static void sysv_reset_after_fork(void) { pthread_mutex_init(&g_lock, NULL); }
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
/*
|
||||
* A trace instance for mangoapp where the kernel's tracefs is closed to the app.
|
||||
*
|
||||
* Valve's mangoapp (Deck mode's performance overlay) reads the GPU memory total on a Qualcomm
|
||||
* display driver (msm_dpu / msm_drm) from the gpu_mem_total event, through a tracefs instance of
|
||||
* its own - and aborts when tracefs_instance_create() fails, taking the whole overlay with it.
|
||||
* Android mounts tracefs for root and the readtracefs group only, so it always fails here.
|
||||
*
|
||||
* The real calls run first. Only when they fail is the instance placed in an empty directory of
|
||||
* the session's own, and reading its events answers with one gpu_mem_total record carrying the
|
||||
* total KGSL - the GPU driver of every Adreno under Android - reports to the app.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <limits.h>
|
||||
@@ -25,7 +13,6 @@ struct tracefs_instance;
|
||||
struct tep_handle;
|
||||
struct tep_event;
|
||||
|
||||
/* The head of libtraceevent 1.8's struct tep_record (the version tools/mangoapp/packages.txt pins). */
|
||||
struct tep_record {
|
||||
unsigned long long ts, offset;
|
||||
long long missed_events;
|
||||
@@ -35,7 +22,6 @@ struct tep_record {
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/* The event as Android kernels declare it (trace/events/gpu_mem.h). */
|
||||
static const char gpu_mem_total_format[] =
|
||||
"name: gpu_mem_total\n"
|
||||
"ID: 1\n"
|
||||
|
||||
@@ -1,21 +1,7 @@
|
||||
/*
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with names
|
||||
* changed to this project's. The reasoning below is the original author's.
|
||||
*
|
||||
* A process status without the container's tracer in it.
|
||||
*
|
||||
* proot runs the session under ptrace, so every process here reads a TracerPid in its
|
||||
* /proc/<pid>/status. The Steam client takes that to mean a debugger is attached, and its arm64
|
||||
* build breaks into the supposed debugger with a bare "svc #0" after every failed assertion. That
|
||||
* is no breakpoint: the registers still hold the call Plat_IsInDebugSession() just made, close(),
|
||||
* with its own result, 1, as the argument - so each assertion closes descriptor 1. The number then
|
||||
* goes to whatever the client opens next, and its standard output is written into that: app
|
||||
* manifests and content chunks, its own connections, and the socket a game's Steam API talks
|
||||
* over, which is how a game that stayed silent while loading found its pipe dead.
|
||||
*
|
||||
* The tracer is part of the container, not something a program should react to, so the status
|
||||
* files are served with TracerPid 0.
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
@@ -34,7 +20,6 @@ static const char *skip_digits(const char *s) {
|
||||
return end == s ? NULL : end;
|
||||
}
|
||||
|
||||
/* /proc/{self,thread-self,<pid>}[/task/<tid>]/status */
|
||||
static int is_status_path(const char *path) {
|
||||
const char *rest;
|
||||
if (path == NULL || strncmp(path, "/proc/", 6) != 0) return 0;
|
||||
@@ -46,9 +31,6 @@ static int is_status_path(const char *path) {
|
||||
return strcmp(rest, "/status") == 0;
|
||||
}
|
||||
|
||||
/* Chromium stands its hang watchdogs down when it sees a tracer, and the client's web helper does
|
||||
* not come up within their patience here: it is left reading the truth. SteamVR's web helper (the
|
||||
* dashboard, Cardboard mode's SteamVR) is the same Chromium and stalls the same way. */
|
||||
static int is_web_helper(void) {
|
||||
return strcmp(program_invocation_short_name, "steamwebhelper") == 0 ||
|
||||
strcmp(program_invocation_short_name, "vrwebhelper") == 0;
|
||||
@@ -65,8 +47,6 @@ static int write_all(int fd, const char *data, size_t len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The descriptor to hand back for a read-only open of a status file, or -1 with errno untouched
|
||||
* when the path is something else or the copy cannot be made, and the real open should run. */
|
||||
__attribute__((visibility("hidden"))) int bl_status_without_tracer(const char *path, int flags) {
|
||||
char text[STATUS_MAX];
|
||||
size_t len = 0;
|
||||
|
||||
@@ -1,29 +1,7 @@
|
||||
/*
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with the
|
||||
* symbol prefix changed to match this library. The reasoning below is the original author's.
|
||||
*
|
||||
* udev's netlink monitor, stood in for where the sandbox refuses the socket it is built on.
|
||||
*
|
||||
* The app sandbox denies a NETLINK_KOBJECT_UEVENT socket outright. libudev cannot create a
|
||||
* monitor without one, and SDL's HID layer cannot start without a monitor: every SDL_hid_init()
|
||||
* fails, the Steam client's controller code retries it hundreds of times a second, its main loop
|
||||
* stalls, and the client asserts out from under the running game. Refusing SDL the library
|
||||
* altogether (the earlier answer here) is what produced that failure.
|
||||
*
|
||||
* So the socket is answered instead: one end of a datagram socketpair stands in for the netlink
|
||||
* socket, its peer held open so it never reads as hung up, and the few calls libudev makes on
|
||||
* the socket that only a netlink one could answer are answered here. Nothing is ever written to
|
||||
* it, so the monitor is live and silent, which is the most the kernel would deliver in a
|
||||
* container anyway. The real socket is tried first, so this stays out of the way wherever a
|
||||
* monitor could genuinely be created.
|
||||
*
|
||||
* The stand-in can also carry events after all (bl_udevmon_inject, below): libfakeinput plugs
|
||||
* Steam's touch controller in and out of the client that way.
|
||||
*
|
||||
* Wine is left without one. Its HID bus reads the session's pads itself only when its SDL bus
|
||||
* cannot start, and that is the path inputudev.c describes them on. Given a monitor the SDL bus
|
||||
* comes up and takes the pads over from it.
|
||||
* Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
@@ -39,9 +17,9 @@
|
||||
#include <unistd.h>
|
||||
|
||||
struct stand_in {
|
||||
int fd; /* the descriptor handed out, -1 when the slot is free */
|
||||
int peer; /* the other end, kept open */
|
||||
ino_t inode; /* identifies the socket after fd is closed and its number reused */
|
||||
int fd;
|
||||
int peer;
|
||||
ino_t inode;
|
||||
};
|
||||
|
||||
static struct stand_in stand_ins[16];
|
||||
@@ -62,8 +40,6 @@ static ino_t socket_inode(int fd) {
|
||||
return fstat(fd, &st) == 0 ? st.st_ino : 0;
|
||||
}
|
||||
|
||||
/* Whether fd is one of the stand-in sockets. A slot whose descriptor was closed and reused by
|
||||
* something else is retired on sight, so a later socket with the same number is not mistaken. */
|
||||
static int is_stand_in(int fd) {
|
||||
int found = 0;
|
||||
if (fd < 0)
|
||||
@@ -108,7 +84,6 @@ static int make_stand_in(int type) {
|
||||
errno = saved;
|
||||
return -1;
|
||||
}
|
||||
/* The peer is ours alone: it must not follow the socket into a child. */
|
||||
fcntl(sv[1], F_SETFD, FD_CLOEXEC);
|
||||
pthread_mutex_lock(&lock);
|
||||
for (size_t i = 0; i < sizeof(stand_ins) / sizeof(stand_ins[0]); i++) {
|
||||
@@ -147,7 +122,6 @@ int socket(int domain, int type, int protocol) {
|
||||
return make_stand_in(type);
|
||||
}
|
||||
|
||||
/* For net.c's bind(): whether fd is a stand-in, which accepts any netlink address as bound. */
|
||||
__attribute__((visibility("hidden"))) int bl_udevmon_stand_in(int fd) {
|
||||
return is_stand_in(fd);
|
||||
}
|
||||
@@ -180,8 +154,6 @@ int setsockopt(int fd, int level, int optname, const void *optval, socklen_t opt
|
||||
static int (*real_setsockopt)(int, int, int, const void *, socklen_t);
|
||||
|
||||
if (is_stand_in(fd)) {
|
||||
/* Group membership and packet filters only mean something on a socket that receives; this
|
||||
* one never does, so they are accepted as set. The rest is genuine on a unix socket. */
|
||||
if (level == SOL_NETLINK)
|
||||
return 0;
|
||||
if (level == SOL_SOCKET && (optname == SO_ATTACH_FILTER || optname == SO_DETACH_FILTER))
|
||||
@@ -195,8 +167,6 @@ int setsockopt(int fd, int level, int optname, const void *optval, socklen_t opt
|
||||
return real_setsockopt(fd, level, optname, optval, optlen);
|
||||
}
|
||||
|
||||
/* udevd's message to the "udev" multicast group (systemd, device-monitor.c): this header, then the
|
||||
* properties as NUL-separated KEY=VALUE strings. */
|
||||
struct monitor_netlink_header {
|
||||
char prefix[8];
|
||||
unsigned magic;
|
||||
@@ -209,7 +179,6 @@ struct monitor_netlink_header {
|
||||
unsigned filter_tag_bloom_lo;
|
||||
};
|
||||
|
||||
/* systemd's string_hash32: MurmurHash2, seed 0. */
|
||||
static unsigned murmur_hash2(const char *key, size_t len) {
|
||||
const unsigned m = 0x5bd1e995;
|
||||
unsigned h = (unsigned)len;
|
||||
@@ -236,8 +205,6 @@ static unsigned murmur_hash2(const char *key, size_t len) {
|
||||
return h;
|
||||
}
|
||||
|
||||
/* Sends a device event to every stand-in in this process, as udevd would; returns how many got it.
|
||||
* For libfakeinput (found with dlsym), which knows when its devices come and go. */
|
||||
__attribute__((visibility("default"))) int bl_udevmon_inject(const char *action, const char *devpath,
|
||||
const char *subsystem, const char *devname,
|
||||
unsigned major, unsigned minor) {
|
||||
@@ -247,7 +214,7 @@ __attribute__((visibility("default"))) int bl_udevmon_inject(const char *action,
|
||||
action, 0, devpath, 0, subsystem, 0, devname, 0, major, 0, minor, 0,
|
||||
__atomic_add_fetch(&seqnum, 1, __ATOMIC_RELAXED));
|
||||
if (used <= 0 || (size_t)used >= sizeof(props)) return -1;
|
||||
used++; /* the last string's NUL */
|
||||
used++;
|
||||
struct monitor_netlink_header header;
|
||||
memset(&header, 0, sizeof(header));
|
||||
memcpy(header.prefix, "libudev", 8);
|
||||
@@ -269,10 +236,6 @@ __attribute__((visibility("default"))) int bl_udevmon_inject(const char *action,
|
||||
return sent;
|
||||
}
|
||||
|
||||
/* For ntsync.c's recvmsg(), which owns the symbol: 1 when fd is a stand-in, answered here (*result
|
||||
* is what recvmsg returns), 0 otherwise. A message is dressed as udevd's: libudev drops one that
|
||||
* does not come from the udev multicast group with root credentials. The sender address goes in
|
||||
* the room msg_namelen had before the call; a unix socket sets it to 0. */
|
||||
__attribute__((visibility("hidden"))) int bl_udevmon_recvmsg(int fd, struct msghdr *msg, int flags,
|
||||
ssize_t (*real_recvmsg)(int, struct msghdr *, int),
|
||||
ssize_t *result) {
|
||||
@@ -286,7 +249,7 @@ __attribute__((visibility("hidden"))) int bl_udevmon_recvmsg(int fd, struct msgh
|
||||
struct sockaddr_nl nl;
|
||||
memset(&nl, 0, sizeof(nl));
|
||||
nl.nl_family = AF_NETLINK;
|
||||
nl.nl_groups = 2; /* udev's group */
|
||||
nl.nl_groups = 2;
|
||||
memcpy(msg->msg_name, &nl, sizeof(nl));
|
||||
msg->msg_namelen = sizeof(nl);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,9 @@
|
||||
/*
|
||||
* The Steam client's own screen, in a Follow screen session.
|
||||
*
|
||||
* With two Xwayland servers the client sizes them through GAMESCOPE_XWAYLAND_MODE_CONTROL
|
||||
* ({server, width, height, allow_super_res} on the root window): the games' server (1) to a game's
|
||||
* Game Resolution, and its own (0) to what it recommends for the display - 1920x1080 on a Fold's
|
||||
* 2448x1848 inner panel. From then on it reads that 16:9 size back as the display's "native" one,
|
||||
* so its interface and every game it starts are 16:9 with bars on a near-square panel, and stay so
|
||||
* when the phone folds onto the cover screen.
|
||||
*
|
||||
* gamescope already keeps server 0 at the output's size and resizes it when the output changes (a
|
||||
* Steam Deck docking; here, the app resizing the output as the phone folds and unfolds). So in a
|
||||
* Follow screen session (BL_FOLLOW_OUTPUT=1) a request for server 0 is dropped and the client's
|
||||
* screen stays the panel's; requests for the games' servers pass through untouched. Any other
|
||||
* session, and any other property, is passed straight on.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Xlib's types, without needing its headers in the build image. */
|
||||
typedef struct _XDisplay Display;
|
||||
typedef unsigned long Atom;
|
||||
typedef unsigned long Window;
|
||||
@@ -48,12 +31,10 @@ int XChangeProperty(Display *dpy, Window w, Atom property, Atom type, int format
|
||||
static Display *atom_dpy;
|
||||
static Atom mode_control;
|
||||
if (!intern) intern = (intern_atom_fn)dlsym(RTLD_NEXT, "XInternAtom");
|
||||
/* Atoms belong to a connection; the client's is the one that writes this. */
|
||||
if (intern && atom_dpy != dpy) {
|
||||
mode_control = intern(dpy, "GAMESCOPE_XWAYLAND_MODE_CONTROL", 1);
|
||||
atom_dpy = dpy;
|
||||
}
|
||||
/* Format-32 property data is an array of long in Xlib. */
|
||||
const long *v = (const long *)data;
|
||||
if (mode_control && property == mode_control && v[0] == 0) {
|
||||
static int said;
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* zRAM for the Steam client while a game runs: on SIGURG the process pages its private anonymous
|
||||
* memory out (ZR_CTL holds 1) or reads it back (0). Raw syscalls only, as this library wraps
|
||||
* close(), openat() and syscall(). */
|
||||
|
||||
#ifndef MADV_PAGEOUT
|
||||
#define MADV_PAGEOUT 21
|
||||
@@ -56,8 +53,6 @@ static unsigned long zr_hex(const char **p) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Paged out: private writable anonymous memory (the heap, unnamed and [anon:name] mappings).
|
||||
* Read back: every private readable mapping, as the kernel may have swapped others meanwhile. */
|
||||
static int zr_eligible(const char *line, int compress, unsigned long *start, unsigned long *end) {
|
||||
const char *p = line;
|
||||
*start = zr_hex(&p);
|
||||
|
||||
Reference in new issue
Block a user