mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
chore: merge main to resolve conflicts with the API 36 target
This commit is contained in:
commit
4a93663d14
793 files changed
+103885
-10000
No files matched your search
@@ -91,7 +91,8 @@ static int enabled(void) {
|
||||
if (cached < 0) {
|
||||
const char *off = getenv("BL_NO_DIR_CACHE");
|
||||
cached = strcmp(program_invocation_short_name, "steam") == 0 &&
|
||||
strstr(program_invocation_name, "steamrtarm64") != NULL && !(off && strcmp(off, "1") == 0);
|
||||
(strstr(program_invocation_name, "steamrtarm64") != NULL ||
|
||||
strstr(program_invocation_name, "steamrt64") != NULL) && !(off && strcmp(off, "1") == 0);
|
||||
if (cached) pthread_atfork(NULL, NULL, after_fork);
|
||||
}
|
||||
return cached && !forked;
|
||||
@@ -256,9 +257,10 @@ static void install(struct listing *l) {
|
||||
int slot = find(l->dev, l->ino);
|
||||
if (slot >= 0) {
|
||||
struct listing *old = table[slot];
|
||||
int old_wd = old->wd;
|
||||
table[slot] = l;
|
||||
detach(old);
|
||||
if (old->wd != l->wd) release(old->wd);
|
||||
if (old_wd != l->wd) release(old_wd);
|
||||
return;
|
||||
}
|
||||
int victim = -1;
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <limits.h>
|
||||
#include <linux/input.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -176,6 +178,24 @@ static int caller_is_winebus(void *caller) {
|
||||
return strstr(info.dli_fname, "winebus.so") != NULL;
|
||||
}
|
||||
|
||||
/* Wine's HID haptics give every XInput rumble a 1000 ms cutoff and xinput only writes on a change,
|
||||
* but XInput motors hold their speed until the next XInputSetState; evdev's length 0 holds until
|
||||
* stopped. Only this library, preloaded first, sees winebus as the caller. The length is put back
|
||||
* because winebus compares its copy with the next state to decide whether to upload again. */
|
||||
__attribute__((visibility("hidden"))) int bl_winebus_rumble_ioctl(int (*real)(int, unsigned long, void *), int fd,
|
||||
unsigned long request, void *arg, void *caller,
|
||||
int *rc) {
|
||||
struct ff_effect *effect = arg;
|
||||
__u16 length;
|
||||
|
||||
if (request != EVIOCSFF || effect == NULL || effect->type != FF_RUMBLE || !caller_is_winebus(caller)) return 0;
|
||||
length = effect->replay.length;
|
||||
effect->replay.length = 0;
|
||||
*rc = real(fd, request, arg);
|
||||
effect->replay.length = length;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *realpath(const char *path, char *resolved) {
|
||||
static char *(*real_realpath)(const char *, char *);
|
||||
void *caller = __builtin_return_address(0);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <linux/netlink.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -262,6 +263,7 @@ __attribute__((visibility("hidden"))) void bl_binfmt_before(const char *path, ch
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_retry(const char *path, char *const argv[], char *const envp[], int error);
|
||||
__attribute__((visibility("hidden"))) void bl_binfmt_before_search(const char *file, char *const argv[], char *const envp[]);
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_after_search(const char *file, char *const argv[], char *const envp[], int error);
|
||||
__attribute__((visibility("hidden"))) char *const *bl_webhelper_argv(const char *path, char *const argv[]);
|
||||
__attribute__((visibility("hidden"))) int bl_binfmt_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *fa,
|
||||
const posix_spawnattr_t *attr, char *const argv[], char *const envp[],
|
||||
spawn_fn real);
|
||||
@@ -308,10 +310,39 @@ static int maybe_answer_lsof(const char *path, char *const argv[]) {
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
int execve(const char *path, char *const argv[], char *const envp[]) {
|
||||
static char **web_helper_redirect(const char *path, char *const argv[], const char **launcher) {
|
||||
const char *want = getenv("BL_X64_ARM_WEBHELPER");
|
||||
if (!want || !*want || !path) return NULL;
|
||||
const char *base = strrchr(path, '/');
|
||||
if (strcmp(base ? base + 1 : path, "steamwebhelper") != 0) return NULL;
|
||||
if (!strstr(path, "/steamrt64/")) {
|
||||
char cwd[PATH_MAX];
|
||||
size_t n;
|
||||
if (path[0] == '/' || !getcwd(cwd, sizeof(cwd))) return NULL;
|
||||
n = strlen(cwd);
|
||||
if (n < 10 || strcmp(cwd + n - 10, "/steamrt64") != 0) return NULL;
|
||||
}
|
||||
int argc = 0;
|
||||
while (argv && argv[argc]) argc++;
|
||||
char **out = calloc((size_t)argc + 2, sizeof(char *));
|
||||
if (!out) return NULL;
|
||||
out[0] = (char *)want;
|
||||
for (int i = 1; i < argc; i++) out[i] = argv[i];
|
||||
*launcher = want;
|
||||
return out;
|
||||
}
|
||||
|
||||
int execve(const char *path, char *const argv_in[], char *const envp[]) {
|
||||
char *const *argv = bl_webhelper_argv(path, argv_in);
|
||||
static int (*real)(const char *, char *const[], char *const[]);
|
||||
if (!real) real = (int (*)(const char *, char *const[], char *const[]))dlsym(RTLD_NEXT, "execve");
|
||||
maybe_answer_lsof(path, argv);
|
||||
const char *launcher = NULL;
|
||||
char **redirected = web_helper_redirect(path, argv, &launcher);
|
||||
if (redirected) {
|
||||
real(launcher, redirected, envp);
|
||||
free(redirected);
|
||||
}
|
||||
bl_binfmt_before(path, argv, envp);
|
||||
real(path, argv, envp);
|
||||
return bl_binfmt_retry(path, argv, envp, errno);
|
||||
@@ -332,7 +363,8 @@ static int answer_lsof_via_spawn(const char *path, char *const argv[], pid_t *pi
|
||||
return 0;
|
||||
}
|
||||
|
||||
int execvp(const char *file, char *const argv[]) {
|
||||
int execvp(const char *file, char *const argv_in[]) {
|
||||
char *const *argv = bl_webhelper_argv(file, argv_in);
|
||||
static int (*real)(const char *, char *const[]);
|
||||
if (!real) real = (int (*)(const char *, char *const[]))dlsym(RTLD_NEXT, "execvp");
|
||||
maybe_answer_lsof(file, argv);
|
||||
@@ -341,10 +373,17 @@ int execvp(const char *file, char *const argv[]) {
|
||||
return bl_binfmt_after_search(file, argv, environ, errno);
|
||||
}
|
||||
|
||||
int execv(const char *path, char *const argv[]) {
|
||||
int execv(const char *path, char *const argv_in[]) {
|
||||
char *const *argv = bl_webhelper_argv(path, argv_in);
|
||||
static int (*real)(const char *, char *const[]);
|
||||
if (!real) real = (int (*)(const char *, char *const[]))dlsym(RTLD_NEXT, "execv");
|
||||
maybe_answer_lsof(path, argv);
|
||||
const char *launcher = NULL;
|
||||
char **redirected = web_helper_redirect(path, argv, &launcher);
|
||||
if (redirected) {
|
||||
real(launcher, redirected);
|
||||
free(redirected);
|
||||
}
|
||||
bl_binfmt_before(path, argv, environ);
|
||||
real(path, argv);
|
||||
return bl_binfmt_retry(path, argv, environ, errno);
|
||||
|
||||
@@ -406,6 +406,8 @@ int bl_kgsl_poll(int (*real)(int, unsigned long, void *), int fd, unsigned long
|
||||
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")));
|
||||
int bl_winebus_rumble_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request,
|
||||
void *arg, void *caller, int *rc) __attribute__((visibility("hidden")));
|
||||
|
||||
int ioctl(int fd, unsigned long request, ...) {
|
||||
typedef int (*ioctl_fn)(int, unsigned long, void *);
|
||||
@@ -419,6 +421,7 @@ int ioctl(int fd, unsigned long request, ...) {
|
||||
if (bl_ntsync_ioctl(fd, request, arg, &rc)) return rc;
|
||||
if (bl_drm_gem_close(fd, request, arg, &rc)) return rc;
|
||||
if (real == NULL) real = (ioctl_fn) dlsym(RTLD_NEXT, "ioctl");
|
||||
if (bl_winebus_rumble_ioctl(real, fd, request, arg, __builtin_return_address(0), &rc)) return rc;
|
||||
if (!bl_kgsl_poll(real, fd, request, arg, &rc)) rc = quest_kgsl_ioctl(real, fd, request, arg);
|
||||
bl_kgsl_chip_id_fixup(request, arg, rc);
|
||||
if (arg == NULL || !is_link_query(request)) return rc;
|
||||
@@ -535,11 +538,11 @@ static FILE *synthesize(const char *table) {
|
||||
return out;
|
||||
}
|
||||
|
||||
int bl_status_without_tracer(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_status_without_tracer(const char *path, int flags, const void *caller) __attribute__((visibility("hidden")));
|
||||
|
||||
static FILE *open_stream(fopen_fn real, const char *path, const char *mode) {
|
||||
static FILE *open_stream(fopen_fn real, const char *path, const char *mode, const void *caller) {
|
||||
int status = mode && mode[0] == 'r' && !strchr(mode, '+')
|
||||
? bl_status_without_tracer(path, O_RDONLY | O_CLOEXEC) : -1;
|
||||
? bl_status_without_tracer(path, O_RDONLY | O_CLOEXEC, caller) : -1;
|
||||
if (status >= 0) {
|
||||
FILE *copy = fdopen(status, "r");
|
||||
if (copy == NULL) close(status);
|
||||
@@ -557,11 +560,11 @@ static FILE *open_stream(fopen_fn real, const char *path, const char *mode) {
|
||||
FILE *fopen(const char *path, const char *mode) {
|
||||
static fopen_fn real;
|
||||
if (real == NULL) real = (fopen_fn) dlsym(RTLD_NEXT, "fopen");
|
||||
return open_stream(real, path, mode);
|
||||
return open_stream(real, path, mode, __builtin_return_address(0));
|
||||
}
|
||||
|
||||
FILE *fopen64(const char *path, const char *mode) {
|
||||
static fopen_fn real;
|
||||
if (real == NULL) real = (fopen_fn) dlsym(RTLD_NEXT, "fopen64");
|
||||
return open_stream(real, path, mode);
|
||||
return open_stream(real, path, mode, __builtin_return_address(0));
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int bl_status_without_tracer(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_status_without_tracer(const char *path, int flags, const void *caller) __attribute__((visibility("hidden")));
|
||||
int bl_writable_retry(int dirfd, const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_ntsync_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_dircache_create(int dirfd, const char *path, int flags, mode_t mode,
|
||||
@@ -51,7 +51,7 @@ int open(const char *path, int flags, ...) {
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
if ((fd = bl_status_without_tracer(path, flags)) >= 0) return fd;
|
||||
if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd;
|
||||
if ((fd = bl_ntsync_open(path, flags)) != -2) return fd;
|
||||
if (real_open == NULL) real_open = dlsym(RTLD_NEXT, "open");
|
||||
if (real_open == NULL) {
|
||||
@@ -76,7 +76,7 @@ int openat(int dirfd, const char *path, int flags, ...) {
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
if ((fd = bl_status_without_tracer(path, flags)) >= 0) return fd;
|
||||
if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd;
|
||||
if ((fd = bl_ntsync_open(path, flags)) != -2) return fd;
|
||||
if (real_openat == NULL) real_openat = dlsym(RTLD_NEXT, "openat");
|
||||
if (real_openat == NULL) {
|
||||
|
||||
@@ -42,7 +42,8 @@ static int enabled(void) {
|
||||
if (cached >= 0) return cached;
|
||||
off = getenv("BL_NO_PATH_CACHE");
|
||||
cached = strcmp(program_invocation_short_name, "steam") == 0 &&
|
||||
strstr(program_invocation_name, "steamrtarm64") != NULL &&
|
||||
(strstr(program_invocation_name, "steamrtarm64") != NULL ||
|
||||
strstr(program_invocation_name, "steamrt64") != NULL) &&
|
||||
!(off != NULL && off[0] == '1');
|
||||
return cached;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
static int in_steam_dirs(const char *path) {
|
||||
return path != NULL && (strstr(path, "/Steam/steamrtarm64/") != NULL
|
||||
return path != NULL && (strstr(path, "/Steam/steamrtarm64/") != NULL || strstr(path, "/Steam/steamrt64/") != NULL
|
||||
|| strstr(path, "/Steam/ubuntu12_64/") != NULL || strstr(path, "/Steam/linuxarm64/") != NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/* In Deck mode (-steamos3) the x86-64 client's SteamOS audio manager passes libpulse the NULL operation of a
|
||||
* failed request, and libpulse aborts on it ("Assertion 'o' failed ... pa_operation_get_state()"). */
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct pa_operation pa_operation;
|
||||
|
||||
#define PA_OPERATION_CANCELLED 2
|
||||
|
||||
/* A libpulse loaded with RTLD_LOCAL (Wine's winepulse.so) is not in RTLD_NEXT's scope. */
|
||||
static void *libpulse(const char *name) {
|
||||
void *fn = dlsym(RTLD_NEXT, name);
|
||||
if (!fn) {
|
||||
void *handle = dlopen("libpulse.so.0", RTLD_LAZY | RTLD_NOLOAD);
|
||||
if (handle) {
|
||||
fn = dlsym(handle, name);
|
||||
dlclose(handle);
|
||||
}
|
||||
}
|
||||
return fn;
|
||||
}
|
||||
|
||||
int pa_operation_get_state(pa_operation *o) {
|
||||
static int (*next)(pa_operation *);
|
||||
if (!o)
|
||||
return PA_OPERATION_CANCELLED;
|
||||
if (!next)
|
||||
next = (int (*)(pa_operation *))libpulse("pa_operation_get_state");
|
||||
return next ? next(o) : PA_OPERATION_CANCELLED;
|
||||
}
|
||||
|
||||
void pa_operation_unref(pa_operation *o) {
|
||||
static void (*next)(pa_operation *);
|
||||
if (!o)
|
||||
return;
|
||||
if (!next)
|
||||
next = (void (*)(pa_operation *))libpulse("pa_operation_unref");
|
||||
if (next)
|
||||
next(o);
|
||||
}
|
||||
|
||||
void pa_operation_cancel(pa_operation *o) {
|
||||
static void (*next)(pa_operation *);
|
||||
if (!o)
|
||||
return;
|
||||
if (!next)
|
||||
next = (void (*)(pa_operation *))libpulse("pa_operation_cancel");
|
||||
if (next)
|
||||
next(o);
|
||||
}
|
||||
#else
|
||||
typedef int pulseguard_arm_build_has_nothing_to_do;
|
||||
#endif
|
||||
@@ -2,13 +2,18 @@
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <linux/futex.h>
|
||||
#include <linux/magic.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef SYS_openat2
|
||||
@@ -17,6 +22,17 @@
|
||||
|
||||
#define BL_RESOLVE_BENEATH 0x08
|
||||
#define BL_RESOLVE_IN_ROOT 0x10
|
||||
// The kernel's MAXSYMLINKS.
|
||||
#define BL_MAX_SYMLINKS 40
|
||||
#define BL_PROC_ROOT_INO 1
|
||||
|
||||
#ifdef SYS_newfstatat
|
||||
#define BL_SYS_FSTATAT SYS_newfstatat
|
||||
typedef struct stat bl_stat;
|
||||
#else
|
||||
#define BL_SYS_FSTATAT SYS_fstatat64
|
||||
typedef struct stat64 bl_stat;
|
||||
#endif
|
||||
|
||||
struct bl_open_how {
|
||||
uint64_t flags;
|
||||
@@ -25,8 +41,22 @@ struct bl_open_how {
|
||||
};
|
||||
|
||||
static long (*real_syscall)(long, ...);
|
||||
static void *(*real_dlopen)(const char *, int);
|
||||
static int openat2_missing;
|
||||
|
||||
void *dlopen(const char *filename, int flags) {
|
||||
if (!real_dlopen) {
|
||||
real_dlopen = (void *(*)(const char *, int))dlsym(RTLD_NEXT, "dlopen");
|
||||
}
|
||||
const char *basename = filename ? strrchr(filename, '/') : NULL;
|
||||
basename = basename ? basename + 1 : filename;
|
||||
// Steam's deep binding bypasses the robust-list shim under PRoot.
|
||||
if (basename && strcmp(basename, "vrclient.so") == 0) {
|
||||
flags &= ~RTLD_DEEPBIND;
|
||||
}
|
||||
return real_dlopen(filename, flags);
|
||||
}
|
||||
|
||||
int bl_fsync_syscall(long number, const long *args, long *ret) __attribute__((visibility("hidden")));
|
||||
|
||||
static struct robust_list_head *thread_robust_head(void) {
|
||||
@@ -61,6 +91,151 @@ static struct robust_list_head *thread_robust_head(void) {
|
||||
return head;
|
||||
}
|
||||
|
||||
// Magic links are procfs links below a process's directory; procfs's root holds only plain ones (self, thread-self, mounts).
|
||||
static int is_magic_link(int dirfd, char *link, size_t parent_len) {
|
||||
int fd = (int)real_syscall(SYS_openat, (long)dirfd, (long)link, (long)(O_PATH | O_NOFOLLOW | O_CLOEXEC), 0L);
|
||||
if (fd < 0) {
|
||||
return 0;
|
||||
}
|
||||
struct statfs fs;
|
||||
int procfs = real_syscall(SYS_fstatfs, (long)fd, (long)&fs) == 0 && fs.f_type == PROC_SUPER_MAGIC;
|
||||
real_syscall(SYS_close, (long)fd);
|
||||
if (!procfs) {
|
||||
return 0;
|
||||
}
|
||||
char saved = link[parent_len];
|
||||
link[parent_len] = 0;
|
||||
bl_stat parent;
|
||||
long result = real_syscall(BL_SYS_FSTATAT, (long)dirfd, (long)(parent_len ? link : "."), (long)&parent, 0L);
|
||||
link[parent_len] = saved;
|
||||
return result != 0 || parent.st_ino != BL_PROC_ROOT_INO;
|
||||
}
|
||||
|
||||
// RESOLVE_IN_ROOT walked one component at a time: absolute symlinks restart at dirfd and ".." stops there.
|
||||
static long openat_in_root(int dirfd, const char *path, int flags, long mode) {
|
||||
char resolved[PATH_MAX];
|
||||
char pending[PATH_MAX];
|
||||
size_t resolved_len = 0;
|
||||
int symlinks = 0;
|
||||
int have_root = 0;
|
||||
int root_on_procfs = 0;
|
||||
dev_t root_dev = 0;
|
||||
// O_NOFOLLOW and O_CREAT | O_EXCL leave a final symlink alone, unless a trailing slash follows it.
|
||||
int nofollow = (flags & O_NOFOLLOW) || (flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL);
|
||||
const char *rest = path;
|
||||
for (;;) {
|
||||
while (*rest == '/') {
|
||||
rest++;
|
||||
}
|
||||
if (!*rest) {
|
||||
break;
|
||||
}
|
||||
const char *name = rest;
|
||||
const char *end = name;
|
||||
while (*end && *end != '/') {
|
||||
end++;
|
||||
}
|
||||
size_t len = (size_t)(end - name);
|
||||
rest = end;
|
||||
while (*rest == '/') {
|
||||
rest++;
|
||||
}
|
||||
int last = !*rest;
|
||||
int trailing_slash = last && rest != end;
|
||||
if (len == 1 && name[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
if (len == 2 && name[0] == '.' && name[1] == '.') {
|
||||
while (resolved_len > 0 && resolved[resolved_len - 1] != '/') {
|
||||
resolved_len--;
|
||||
}
|
||||
if (resolved_len > 0) {
|
||||
resolved_len--;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
size_t separator = resolved_len > 0;
|
||||
size_t candidate_len = resolved_len + separator + len;
|
||||
if (candidate_len + 1 >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
if (separator) {
|
||||
resolved[resolved_len] = '/';
|
||||
}
|
||||
memcpy(resolved + resolved_len + separator, name, len);
|
||||
resolved[candidate_len] = 0;
|
||||
bl_stat st;
|
||||
int follow = !last || trailing_slash || !nofollow;
|
||||
long stat_result = follow ? real_syscall(BL_SYS_FSTATAT, (long)dirfd, (long)resolved, (long)&st, (long)AT_SYMLINK_NOFOLLOW) : -1;
|
||||
if (stat_result == 0 && S_ISLNK(st.st_mode)) {
|
||||
if (++symlinks > BL_MAX_SYMLINKS) {
|
||||
errno = ELOOP;
|
||||
return -1;
|
||||
}
|
||||
if (!have_root) {
|
||||
bl_stat root;
|
||||
struct statfs root_fs;
|
||||
if (real_syscall(BL_SYS_FSTATAT, (long)dirfd, (long)".", (long)&root, 0L) != 0) {
|
||||
return -1;
|
||||
}
|
||||
root_dev = root.st_dev;
|
||||
root_on_procfs = real_syscall(SYS_fstatfs, (long)dirfd, (long)&root_fs) == 0 && root_fs.f_type == PROC_SUPER_MAGIC;
|
||||
have_root = 1;
|
||||
}
|
||||
if ((st.st_dev != root_dev || root_on_procfs) && is_magic_link(dirfd, resolved, resolved_len)) {
|
||||
// RESOLVE_IN_ROOT refuses magic links.
|
||||
errno = EXDEV;
|
||||
return -1;
|
||||
}
|
||||
size_t rest_len = strlen(end);
|
||||
if (rest_len + 1 >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
char *tail = pending + PATH_MAX - rest_len - 1;
|
||||
memmove(tail, end, rest_len + 1);
|
||||
long target_len = real_syscall(SYS_readlinkat, (long)dirfd, (long)resolved, (long)pending, (long)(PATH_MAX - rest_len));
|
||||
if (target_len <= 0) {
|
||||
if (target_len == 0) {
|
||||
errno = ENOENT;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if ((size_t)target_len + rest_len >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
memmove(pending + target_len, tail, rest_len + 1);
|
||||
if (pending[0] == '/') {
|
||||
resolved_len = 0;
|
||||
}
|
||||
rest = pending;
|
||||
continue;
|
||||
}
|
||||
if (last) {
|
||||
resolved_len = candidate_len;
|
||||
if (trailing_slash) {
|
||||
resolved[resolved_len++] = '/';
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (stat_result != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (!S_ISDIR(st.st_mode)) {
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
resolved_len = candidate_len;
|
||||
}
|
||||
if (resolved_len == 0) {
|
||||
resolved[resolved_len++] = '.';
|
||||
}
|
||||
resolved[resolved_len] = 0;
|
||||
return real_syscall(SYS_openat, (long)dirfd, (long)resolved, (long)flags, mode);
|
||||
}
|
||||
|
||||
static long openat2_via_openat(const long *args) {
|
||||
const char *path = (const char *)args[1];
|
||||
const struct bl_open_how *how = (const struct bl_open_how *)args[2];
|
||||
@@ -68,6 +243,9 @@ static long openat2_via_openat(const long *args) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if ((how->resolve & BL_RESOLVE_IN_ROOT) && (int)args[0] != AT_FDCWD) {
|
||||
return openat_in_root((int)args[0], path, (int)how->flags, (long)how->mode);
|
||||
}
|
||||
if (how->resolve & BL_RESOLVE_IN_ROOT) {
|
||||
while (*path == '/') {
|
||||
path++;
|
||||
|
||||
@@ -145,7 +145,8 @@ static int steam_client(void) {
|
||||
static int cached = -1;
|
||||
if (cached < 0)
|
||||
cached = strcmp(program_invocation_short_name, "steam") == 0 &&
|
||||
strstr(program_invocation_name, "steamrtarm64") != NULL;
|
||||
(strstr(program_invocation_name, "steamrtarm64") != NULL ||
|
||||
strstr(program_invocation_name, "steamrt64") != NULL);
|
||||
return cached;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <ctype.h>
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
@@ -31,9 +33,16 @@ static int is_status_path(const char *path) {
|
||||
return strcmp(rest, "/status") == 0;
|
||||
}
|
||||
|
||||
static int is_web_helper(void) {
|
||||
return strcmp(program_invocation_short_name, "steamwebhelper") == 0 ||
|
||||
strcmp(program_invocation_short_name, "vrwebhelper") == 0;
|
||||
static int is_web_helper(const void *caller) {
|
||||
if (strcmp(program_invocation_short_name, "steamwebhelper") != 0 &&
|
||||
strcmp(program_invocation_short_name, "vrwebhelper") != 0)
|
||||
return 0;
|
||||
const char *hide = getenv("BL_WEBHELPER_HIDE_TRACER");
|
||||
Dl_info info;
|
||||
if (hide && hide[0] == '1' && caller && dladdr(caller, &info) && info.dli_fname
|
||||
&& strstr(info.dli_fname, "libtier0_s.so"))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int write_all(int fd, const char *data, size_t len) {
|
||||
@@ -47,13 +56,13 @@ static int write_all(int fd, const char *data, size_t len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_status_without_tracer(const char *path, int flags) {
|
||||
__attribute__((visibility("hidden"))) int bl_status_without_tracer(const char *path, int flags, const void *caller) {
|
||||
char text[STATUS_MAX];
|
||||
size_t len = 0;
|
||||
int saved = errno;
|
||||
int out = -1;
|
||||
|
||||
if ((flags & O_ACCMODE) != O_RDONLY || !is_status_path(path) || is_web_helper()) return -1;
|
||||
if ((flags & O_ACCMODE) != O_RDONLY || !is_status_path(path) || is_web_helper(caller)) return -1;
|
||||
int in = (int)syscall(SYS_openat, AT_FDCWD, path, O_RDONLY | O_CLOEXEC);
|
||||
if (in < 0) goto done;
|
||||
for (;;) {
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef WEBHELPER_DEFAULT
|
||||
#define WEBHELPER_DEFAULT "--no-zygote --in-process-gpu -AudioServiceOutOfProcess"
|
||||
#endif
|
||||
|
||||
static int is_webhelper_browser(const char *path, char *const argv[]) {
|
||||
if (!path || !argv) return 0;
|
||||
const char *base = strrchr(path, '/');
|
||||
base = base ? base + 1 : path;
|
||||
if (strcmp(base, "steamwebhelper")) return 0;
|
||||
for (int i = 1; argv[i]; i++)
|
||||
if (!strncmp(argv[i], "--type=", 7)) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *join_features(const char *have, const char *add) {
|
||||
size_t a = have ? strlen(have) : 0, b = strlen(add);
|
||||
char *out = malloc(a + b + 2);
|
||||
if (!out) return NULL;
|
||||
out[0] = 0;
|
||||
if (a) strcat(strcat(out, have), ",");
|
||||
return strcat(out, add);
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) char *const *bl_webhelper_argv(const char *path, char *const argv[]) {
|
||||
if (!is_webhelper_browser(path, argv)) return argv;
|
||||
const char *spec = getenv("BL_WEBHELPER_ARGS");
|
||||
if (!spec || !*spec) spec = WEBHELPER_DEFAULT;
|
||||
if (!strcmp(spec, "stock")) return argv;
|
||||
|
||||
int argc = 0;
|
||||
while (argv[argc]) argc++;
|
||||
char *tokens = strdup(spec);
|
||||
if (!tokens) return argv;
|
||||
int extra = 0;
|
||||
for (char *c = tokens; *c; c++)
|
||||
if (*c == ' ') extra++;
|
||||
char **out = calloc(argc + extra + 4, sizeof *out);
|
||||
if (!out) return argv;
|
||||
|
||||
const char *enable = NULL, *disable = NULL;
|
||||
int n = 0;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
if (i && !strncmp(argv[i], "--enable-features=", 18)) enable = argv[i] + 18;
|
||||
else if (i && !strncmp(argv[i], "--disable-features=", 19)) disable = argv[i] + 19;
|
||||
else out[n++] = argv[i];
|
||||
}
|
||||
char *add_enable = NULL, *add_disable = NULL, *save = NULL;
|
||||
for (char *t = strtok_r(tokens, " ", &save); t; t = strtok_r(NULL, " ", &save)) {
|
||||
if (t[0] == '+' && t[1]) {
|
||||
char *joined = join_features(add_enable, t + 1);
|
||||
free(add_enable);
|
||||
add_enable = joined;
|
||||
} else if (t[0] == '-' && t[1] && t[1] != '-') {
|
||||
char *joined = join_features(add_disable, t + 1);
|
||||
free(add_disable);
|
||||
add_disable = joined;
|
||||
} else if (!strncmp(t, "--", 2)) {
|
||||
out[n++] = t;
|
||||
}
|
||||
}
|
||||
char *merged;
|
||||
if (add_enable && (merged = join_features(enable, add_enable))) enable = merged;
|
||||
if (add_disable && (merged = join_features(disable, add_disable))) disable = merged;
|
||||
char *flag;
|
||||
if (enable && (flag = malloc(strlen(enable) + 19))) out[n++] = strcat(strcpy(flag, "--enable-features="), enable);
|
||||
if (disable && (flag = malloc(strlen(disable) + 20))) out[n++] = strcat(strcpy(flag, "--disable-features="), disable);
|
||||
out[n] = NULL;
|
||||
return out;
|
||||
}
|
||||
Reference in new issue
Block a user