Merge org main a5b035b2 (0.6.7 and later) into the non-Adreno test branch

13 conflicts, resolved as:
- build.yml: both checkout steps keep the MaliBridge submodule and take main's sparse checkout.
- SessionActivity: main moved the session drawer into SessionMenu(); its DrawerActions get the
  test branch's systemPowerVr line, the only test-branch change in that call.
- TurnipDriver: the Mali check stays first, then main's injected detector (non-Adreno: system driver).
- BwrapSpawner: the bridge ICD check stays first, then main's runtimeLib() lookup (Ubuntu 26.04 paths).
- SessionArtifacts.finishAbandoned: main's beforeGuestStart flow and recovery markers, plus the test
  branch's Android exit reasons in the recovery note and the low-memory notice (returns Boolean);
  main's in-loop return becomes break so the notice is still left.
- SessionService: pruneSystemVulkanRuntime() kept before main's finishSessionStop(..., collectEnded).
- strings.xml, test_game_environment.py: both sides' additions.
- build_local.sh, test_local.sh: main's docker_platform.sh; local-cross.Dockerfile: main's
  arm64-aware layout plus libvulkan-dev, image tag 24.04-v4.
- gamescope/release.env: the p23-nonadreno pin stays until this round's gamescope build.
- check_session_assets.py: the test branch's pattern (any usr/ target) covers main's.
Workflow step names checked: none lost from either side.
This commit is contained in:
The412Banner committed 2026-10-30 19:37:31 +00:00
commit 380a70b485
700 files changed
+50259 -2255

No files matched your search

+314
View File
@@ -0,0 +1,314 @@
#define _GNU_SOURCE
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/futex.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdint.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/timerfd.h>
#include <time.h>
#include <unistd.h>
#if defined(__aarch64__) || defined(BL_CLOCK_ANY_ARCH)
#ifndef CP_CTL
#define CP_CTL "/tmp/.bl-clock"
#endif
#ifndef FUTEX_LOCK_PI2
#define FUTEX_LOCK_PI2 13
#endif
#define CP_FDS 65536
static const int64_t *cp_shift;
static int cp_state;
static size_t cp_cond_byte;
static unsigned char cp_cond_mask;
static unsigned char cp_fds[CP_FDS / 8];
static int (*cp_gettime)(clockid_t, struct timespec *);
static int (*cp_nanosleep)(clockid_t, int, const struct timespec *, struct timespec *);
static int (*cp_cond_timedwait)(pthread_cond_t *, pthread_mutex_t *, const struct timespec *);
static int (*cp_cond_clockwait)(pthread_cond_t *, pthread_mutex_t *, clockid_t, const struct timespec *);
static int (*cp_sem_clockwait)(sem_t *, clockid_t, const struct timespec *);
static int (*cp_mutex_clocklock)(pthread_mutex_t *, clockid_t, const struct timespec *);
static int (*cp_rdlock)(pthread_rwlock_t *, clockid_t, const struct timespec *);
static int (*cp_wrlock)(pthread_rwlock_t *, clockid_t, const struct timespec *);
static int (*cp_join)(pthread_t, void **, clockid_t, const struct timespec *);
static int (*cp_tfd_create)(int, int);
static int (*cp_tfd_settime)(int, int, const struct itimerspec *, struct itimerspec *);
static void *cp_real(const char *name) {
return dlsym(RTLD_NEXT, name);
}
#define CP_REAL(var, name) (var ? var : (var = cp_real(name)))
static int cp_find_cond_bit(void) {
pthread_condattr_t attr;
pthread_cond_t mono, real;
const unsigned char *a = (const unsigned char *)&mono, *b = (const unsigned char *)&real;
int found = 0;
memset(&mono, 0, sizeof(mono));
memset(&real, 0, sizeof(real));
if (pthread_condattr_init(&attr) != 0) return 0;
if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) == 0 && pthread_cond_init(&mono, &attr) == 0) {
if (pthread_cond_init(&real, NULL) == 0) {
for (size_t i = 0; i < sizeof(pthread_cond_t); i++) {
unsigned char diff = a[i] ^ b[i];
if (!diff) continue;
if (found || (diff & (diff - 1))) {
found = -1;
break;
}
cp_cond_byte = i;
cp_cond_mask = diff;
found = 1;
}
pthread_cond_destroy(&real);
}
pthread_cond_destroy(&mono);
}
pthread_condattr_destroy(&attr);
return found == 1;
}
static void cp_init(void) {
struct stat st;
void *map;
int fd;
if (strcmp(program_invocation_short_name, "plasmashell") != 0) return;
if (!cp_find_cond_bit()) return;
fd = open(CP_CTL, O_RDONLY | O_CLOEXEC);
if (fd < 0) return;
if (fstat(fd, &st) != 0 || st.st_size < (off_t)sizeof(int64_t)) {
close(fd);
return;
}
map = mmap(NULL, sizeof(int64_t), PROT_READ, MAP_SHARED, fd, 0);
close(fd);
if (map != MAP_FAILED) __atomic_store_n(&cp_shift, (const int64_t *)map, __ATOMIC_RELEASE);
}
static int64_t cp_offset(void) {
const int64_t *shift;
int state = __atomic_load_n(&cp_state, __ATOMIC_ACQUIRE);
if (state == 0) {
int expected = 0;
if (__atomic_compare_exchange_n(&cp_state, &expected, 1, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) {
cp_init();
__atomic_store_n(&cp_state, 2, __ATOMIC_RELEASE);
}
return 0;
}
if (state != 2) return 0;
shift = __atomic_load_n(&cp_shift, __ATOMIC_ACQUIRE);
if (!shift) return 0;
int64_t value = __atomic_load_n(shift, __ATOMIC_RELAXED);
return value > 0 ? value : 0;
}
__attribute__((constructor)) static void cp_start(void) {
cp_offset();
}
static int cp_mono(clockid_t clock) {
return clock == CLOCK_MONOTONIC || clock == CLOCK_MONOTONIC_RAW || clock == CLOCK_MONOTONIC_COARSE;
}
static void cp_move(struct timespec *ts, int64_t ns) {
int64_t total = (int64_t)ts->tv_nsec + ns % 1000000000LL;
ts->tv_sec += (time_t)(ns / 1000000000LL);
while (total < 0) {
total += 1000000000LL;
ts->tv_sec--;
}
while (total >= 1000000000LL) {
total -= 1000000000LL;
ts->tv_sec++;
}
ts->tv_nsec = (long)total;
}
static const struct timespec *cp_later(const struct timespec *ts, struct timespec *out, int64_t shift) {
if (!ts || !shift) return ts;
*out = *ts;
cp_move(out, shift);
return out;
}
static void cp_mark(int fd, int mono) {
if (fd < 0 || fd >= CP_FDS) return;
if (mono) __atomic_or_fetch(&cp_fds[fd / 8], (unsigned char)(1u << (fd % 8)), __ATOMIC_RELAXED);
else __atomic_and_fetch(&cp_fds[fd / 8], (unsigned char)~(1u << (fd % 8)), __ATOMIC_RELAXED);
}
static int cp_marked(int fd) {
return fd >= 0 && fd < CP_FDS && (__atomic_load_n(&cp_fds[fd / 8], __ATOMIC_RELAXED) & (1u << (fd % 8)));
}
static int cp_cond_mono(const pthread_cond_t *cond) {
return (((const volatile unsigned char *)cond)[cp_cond_byte] & cp_cond_mask) != 0;
}
int clock_gettime(clockid_t clock, struct timespec *ts) {
if (!CP_REAL(cp_gettime, "clock_gettime")) {
errno = ENOSYS;
return -1;
}
int rc = cp_gettime(clock, ts);
if (rc == 0 && cp_mono(clock)) {
int64_t shift = cp_offset();
if (shift) cp_move(ts, -shift);
}
return rc;
}
int clock_nanosleep(clockid_t clock, int flags, const struct timespec *req, struct timespec *rem) {
struct timespec moved;
if (!CP_REAL(cp_nanosleep, "clock_nanosleep")) return ENOSYS;
if ((flags & TIMER_ABSTIME) && cp_mono(clock)) req = cp_later(req, &moved, cp_offset());
return cp_nanosleep(clock, flags, req, rem);
}
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) {
struct timespec moved;
if (!CP_REAL(cp_cond_timedwait, "pthread_cond_timedwait")) return ENOSYS;
int64_t shift = cp_offset();
if (shift && cp_cond_mono(cond)) abstime = cp_later(abstime, &moved, shift);
return cp_cond_timedwait(cond, mutex, abstime);
}
int pthread_cond_clockwait(pthread_cond_t *cond, pthread_mutex_t *mutex, clockid_t clock, const struct timespec *abstime) {
struct timespec moved;
if (!CP_REAL(cp_cond_clockwait, "pthread_cond_clockwait")) return ENOSYS;
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
return cp_cond_clockwait(cond, mutex, clock, abstime);
}
int sem_clockwait(sem_t *sem, clockid_t clock, const struct timespec *abstime) {
struct timespec moved;
if (!CP_REAL(cp_sem_clockwait, "sem_clockwait")) {
errno = ENOSYS;
return -1;
}
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
return cp_sem_clockwait(sem, clock, abstime);
}
int pthread_mutex_clocklock(pthread_mutex_t *mutex, clockid_t clock, const struct timespec *abstime) {
struct timespec moved;
if (!CP_REAL(cp_mutex_clocklock, "pthread_mutex_clocklock")) return ENOSYS;
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
return cp_mutex_clocklock(mutex, clock, abstime);
}
int pthread_rwlock_clockrdlock(pthread_rwlock_t *lock, clockid_t clock, const struct timespec *abstime) {
struct timespec moved;
if (!CP_REAL(cp_rdlock, "pthread_rwlock_clockrdlock")) return ENOSYS;
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
return cp_rdlock(lock, clock, abstime);
}
int pthread_rwlock_clockwrlock(pthread_rwlock_t *lock, clockid_t clock, const struct timespec *abstime) {
struct timespec moved;
if (!CP_REAL(cp_wrlock, "pthread_rwlock_clockwrlock")) return ENOSYS;
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
return cp_wrlock(lock, clock, abstime);
}
int pthread_clockjoin_np(pthread_t thread, void **result, clockid_t clock, const struct timespec *abstime) {
struct timespec moved;
if (!CP_REAL(cp_join, "pthread_clockjoin_np")) return ENOSYS;
if (cp_mono(clock)) abstime = cp_later(abstime, &moved, cp_offset());
return cp_join(thread, result, clock, abstime);
}
int timerfd_create(int clock, int flags) {
if (!CP_REAL(cp_tfd_create, "timerfd_create")) {
errno = ENOSYS;
return -1;
}
int fd = cp_tfd_create(clock, flags);
cp_mark(fd, cp_mono(clock));
return fd;
}
static const struct itimerspec *cp_timer(int fd, int flags, const struct itimerspec *value, struct itimerspec *out) {
int64_t shift;
if (!value || !(flags & TFD_TIMER_ABSTIME) || !cp_marked(fd)) return value;
if ((value->it_value.tv_sec == 0 && value->it_value.tv_nsec == 0) || !(shift = cp_offset())) return value;
*out = *value;
cp_move(&out->it_value, shift);
return out;
}
int timerfd_settime(int fd, int flags, const struct itimerspec *value, struct itimerspec *old) {
struct itimerspec moved;
if (!CP_REAL(cp_tfd_settime, "timerfd_settime")) {
errno = ENOSYS;
return -1;
}
return cp_tfd_settime(fd, flags, cp_timer(fd, flags, value, &moved), old);
}
__attribute__((visibility("hidden"))) int bl_clock_syscall(long number, const long *args, long (*real)(long, ...), long *ret) {
struct timespec moved;
struct itimerspec timer;
int64_t shift;
if (number == SYS_clock_gettime) {
*ret = real(number, args[0], args[1]);
if (*ret == 0 && args[1] && cp_mono((clockid_t)args[0]) && (shift = cp_offset()))
cp_move((struct timespec *)args[1], -shift);
return 1;
}
if (number == SYS_timerfd_create) {
*ret = real(number, args[0], args[1]);
cp_mark((int)*ret, cp_mono((clockid_t)args[0]));
return 1;
}
if (number == SYS_timerfd_settime) {
const struct itimerspec *value = cp_timer((int)args[0], (int)args[1], (const struct itimerspec *)args[2], &timer);
if (value == (const struct itimerspec *)args[2]) return 0;
*ret = real(number, args[0], args[1], (long)value, args[3]);
return 1;
}
if (number == SYS_clock_nanosleep) {
if (!((int)args[1] & TIMER_ABSTIME) || !cp_mono((clockid_t)args[0]) || !args[2] || !(shift = cp_offset())) return 0;
*ret = real(number, args[0], args[1], (long)cp_later((const struct timespec *)args[2], &moved, shift), args[3]);
return 1;
}
if (number == SYS_futex) {
int op = (int)args[1];
int cmd = op & FUTEX_CMD_MASK;
if (op & FUTEX_CLOCK_REALTIME) return 0;
if (cmd != FUTEX_WAIT_BITSET && cmd != FUTEX_WAIT_REQUEUE_PI && cmd != FUTEX_LOCK_PI2) return 0;
if (!args[3] || !(shift = cp_offset())) return 0;
*ret = real(number, args[0], args[1], args[2], (long)cp_later((const struct timespec *)args[3], &moved, shift), args[4], args[5]);
return 1;
}
#ifdef SYS_futex_waitv
if (number == SYS_futex_waitv) {
if (!args[3] || (clockid_t)args[4] != CLOCK_MONOTONIC || !(shift = cp_offset())) return 0;
*ret = real(number, args[0], args[1], args[2], (long)cp_later((const struct timespec *)args[3], &moved, shift), args[4]);
return 1;
}
#endif
return 0;
}
#else
__attribute__((visibility("hidden"))) int bl_clock_syscall(long number, const long *args, long (*real)(long, ...), long *ret) {
(void)number;
(void)args;
(void)real;
(void)ret;
return 0;
}
#endif
+41
View File
@@ -0,0 +1,41 @@
#define _GNU_SOURCE
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <unistd.h>
#define FUSE_MAGIC 0x65735546
#define SDCARDFS_MAGIC 0x5dca2df5
static int is_wineserver(void) {
static int cached = -1;
char exe[PATH_MAX];
const char *base;
ssize_t n;
if (cached >= 0) return cached;
n = readlink("/proc/self/exe", exe, sizeof(exe) - 1);
if (n <= 0) {
cached = 0;
return cached;
}
exe[n] = '\0';
base = strrchr(exe, '/');
cached = strcmp(base ? base + 1 : exe, "wineserver") == 0;
return cached;
}
__attribute__((visibility("hidden")))
void bl_storage_owner(int fd, struct stat *st) {
struct statfs fs;
int saved = errno;
uid_t uid;
if (st != NULL && is_wineserver()) {
uid = getuid();
if (st->st_uid != uid && fstatfs(fd, &fs) == 0 && (fs.f_type == FUSE_MAGIC || fs.f_type == SDCARDFS_MAGIC)) st->st_uid = uid;
}
errno = saved;
}
+21 -2
View File
@@ -139,17 +139,31 @@ static int (*next_faccessat(void))(int, const char *, int, int) {
}
__attribute__((visibility("hidden"))) int bl_binfmt_runnable(const char *path, int mode);
__attribute__((visibility("hidden"))) int bl_writable_access(int dirfd, const char *path, int mode, int flags);
static int writable_as_owner(int (*real)(int, const char *, int, int), int dirfd, const char *path, int mode, int flags) {
if (!bl_writable_access(dirfd, path, mode, flags)) return -1;
if ((mode & ~W_OK) == 0 || real(dirfd, path, mode & ~W_OK, flags) == 0) return 0;
return -1;
}
static int check_cwd(const char *path, int mode, int flags) {
int (*real)(int, const char *, int, int) = next_faccessat();
int result;
int err;
if (real == NULL) {
errno = ENOSYS;
return -1;
}
result = real(AT_FDCWD, path, mode, flags);
return result != 0 && errno == EACCES && bl_binfmt_runnable(path, mode) ? 0 : result;
if (result == 0) return 0;
err = errno;
if (err == EACCES && bl_binfmt_runnable(path, mode)) return 0;
errno = err;
if (writable_as_owner(real, AT_FDCWD, path, mode, flags) == 0) return 0;
errno = err;
return result;
}
int access(const char *path, int mode) {
@@ -166,6 +180,7 @@ int eaccess(const char *path, int mode) {
int faccessat(int dirfd, const char *path, int mode, int flags) {
int (*real)(int, const char *, int, int);
int err;
if (dirfd == AT_FDCWD) {
return cached_access(path, mode, flags, check_cwd);
@@ -175,5 +190,9 @@ int faccessat(int dirfd, const char *path, int mode, int flags) {
errno = ENOSYS;
return -1;
}
return real(dirfd, path, mode, flags);
if (real(dirfd, path, mode, flags) == 0) return 0;
err = errno;
if (writable_as_owner(real, dirfd, path, mode, flags) == 0) return 0;
errno = err;
return -1;
}
+42 -1
View File
@@ -3,6 +3,7 @@
#include <fcntl.h>
#include <limits.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -23,6 +24,34 @@ static int is_steam_client(void) {
return cached;
}
static int wine_name(const char *path) {
const char *base;
size_t n;
if (path == NULL) return 0;
base = strrchr(path, '/');
base = base ? base + 1 : path;
n = strlen(path);
return strncmp(base, "wine", 4) == 0 || strstr(path, "/lib/wine/") != NULL
|| (n > 4 && strcasecmp(path + n - 4, ".exe") == 0);
}
static int is_wine(void) {
static int cached = -1;
char exe[PATH_MAX];
ssize_t n;
if (cached >= 0) return cached;
n = readlink("/proc/self/exe", exe, sizeof(exe) - 1);
if (n > 0) exe[n] = '\0';
cached = (n > 0 && wine_name(exe)) || wine_name(program_invocation_name);
return cached;
}
static int acts_as_root(void) {
return is_steam_client() || !is_wine();
}
static int grant_owner_write(int dirfd, const char *path) {
struct stat st;
@@ -37,7 +66,7 @@ int bl_writable_retry(int dirfd, const char *path, int flags) {
char parent[PATH_MAX];
const char *slash;
if (saved != EACCES || path == NULL || (flags & O_ACCMODE) == O_RDONLY || !is_steam_client()) return 0;
if (saved != EACCES || path == NULL || (flags & O_ACCMODE) == O_RDONLY || !acts_as_root()) return 0;
if (faccessat(dirfd, path, F_OK, 0) == 0) {
granted = grant_owner_write(dirfd, path);
} else if (flags & O_CREAT) {
@@ -53,3 +82,15 @@ int bl_writable_retry(int dirfd, const char *path, int flags) {
errno = saved;
return granted;
}
__attribute__((visibility("hidden")))
int bl_writable_access(int dirfd, const char *path, int mode, int flags) {
int saved = errno;
struct stat st;
int owned;
if (saved != EACCES || path == NULL || !(mode & W_OK) || !acts_as_root()) return 0;
owned = fstatat(dirfd, path, &st, flags & AT_SYMLINK_NOFOLLOW) == 0 && st.st_uid == geteuid();
errno = saved;
return owned;
}
+43 -8
View File
@@ -49,6 +49,7 @@ static int openat2_missing;
static int (*next_fstatat)(int, const char *, bl_stat *, int);
static int (*next_openat)(int, const char *, int, ...);
static ssize_t (*next_readlinkat)(int, const char *, char *, size_t);
static int (*next_statx)(int, const char *, int, unsigned int, struct statx *);
static int find_fastpath(struct dl_phdr_info *info, size_t size, void *name) {
(void)size;
@@ -68,6 +69,7 @@ __attribute__((constructor)) static void find_fastpath_calls(void) {
next_fstatat = (int (*)(int, const char *, bl_stat *, int))dlsym(fastpath, BL_FSTATAT_NAME);
next_openat = (int (*)(int, const char *, int, ...))dlsym(fastpath, "openat");
next_readlinkat = (ssize_t (*)(int, const char *, char *, size_t))dlsym(fastpath, "readlinkat");
next_statx = (int (*)(int, const char *, int, unsigned int, struct statx *))dlsym(fastpath, "statx");
}
}
@@ -92,6 +94,13 @@ static long path_readlink(int dirfd, const char *path, char *buf, size_t size) {
return next_readlinkat(dirfd, path, buf, size);
}
static long path_statx(int dirfd, const char *path, int flags, unsigned int mask, struct statx *out) {
if (!next_statx) {
return real_syscall(SYS_statx, (long)dirfd, (long)path, (long)flags, (long)mask, (long)out);
}
return next_statx(dirfd, path, flags, mask, out);
}
void *dlopen(const char *filename, int flags) {
if (!real_dlopen) {
real_dlopen = (void *(*)(const char *, int))dlsym(RTLD_NEXT, "dlopen");
@@ -329,7 +338,28 @@ static int execveat_is_execve(const long *args) {
return path[0] == '/' || (int)args[0] == AT_FDCWD;
}
static long openat2_call(const long *args) {
if (!real_syscall) {
real_syscall = (long (*)(long, ...)) dlsym(RTLD_NEXT, "syscall");
}
if (!__atomic_load_n(&openat2_missing, __ATOMIC_RELAXED)) {
long fd = real_syscall(SYS_openat2, args[0], args[1], args[2], args[3]);
if (fd != -1 || errno != ENOSYS) {
return fd;
}
__atomic_store_n(&openat2_missing, 1, __ATOMIC_RELAXED);
}
return openat2_via_openat(args);
}
int bl_openat2(int dirfd, const char *path, void *how, size_t size) __asm__("openat2");
int bl_openat2(int dirfd, const char *path, void *how, size_t size) {
long args[6] = {dirfd, (long)path, (long)how, (long)size, 0, 0};
return (int)openat2_call(args);
}
int bl_writewatch_syscall(long number, const long *args, long (*real)(long, ...), long *rc) __attribute__((visibility("hidden")));
int bl_clock_syscall(long number, const long *args, long (*real)(long, ...), long *ret) __attribute__((visibility("hidden")));
long syscall(long number, ...) {
va_list ap;
@@ -356,22 +386,27 @@ long syscall(long number, ...) {
if (!real_syscall) {
real_syscall = (long (*)(long, ...)) dlsym(RTLD_NEXT, "syscall");
}
if (bl_clock_syscall(number, args, real_syscall, &handled)) {
return handled;
}
if (bl_writewatch_syscall(number, args, real_syscall, &handled)) {
return handled;
}
if (number == SYS_openat2) {
if (!__atomic_load_n(&openat2_missing, __ATOMIC_RELAXED)) {
long fd = real_syscall(number, args[0], args[1], args[2], args[3]);
if (fd != -1 || errno != ENOSYS) {
return fd;
}
__atomic_store_n(&openat2_missing, 1, __ATOMIC_RELAXED);
}
return openat2_via_openat(args);
return openat2_call(args);
}
if (number == SYS_openat) {
return path_open((int)args[0], (const char *)args[1], (int)args[2], args[3]);
}
if (number == BL_SYS_FSTATAT) {
return path_stat((int)args[0], (const char *)args[1], (bl_stat *)args[2], (int)args[3]);
}
if (number == SYS_readlinkat) {
return path_readlink((int)args[0], (const char *)args[1], (char *)args[2], (size_t)args[3]);
}
if (number == SYS_statx) {
return path_statx((int)args[0], (const char *)args[1], (int)args[2], (unsigned int)args[3], (struct statx *)args[4]);
}
if (number == SYS_execveat && execveat_is_execve(args)) {
return real_syscall(SYS_execve, args[1], args[2], args[3]);
}
+7 -1
View File
@@ -13,6 +13,7 @@
#include <unistd.h>
static int (*next_fstat)(int, struct stat *);
void bl_storage_owner(int fd, struct stat *st) __attribute__((visibility("hidden")));
static int (*next_fallocate)(int, int, off_t, off_t);
static int (*next_posix_fallocate)(int, off_t, off_t);
static ssize_t (*next_pwrite)(int, const void *, size_t, off_t);
@@ -285,12 +286,17 @@ int fstat(int fd, struct stat *out) {
if (next_fstat == NULL) { errno = ENOSYS; return -1; }
initialize();
errno = entry_errno;
if (!enabled) return next_fstat(fd, out);
if (!enabled) {
int result = next_fstat(fd, out);
if (result == 0) bl_storage_owner(fd, out);
return result;
}
uint64_t start = now_ns();
errno = entry_errno;
int result = next_fstat(fd, out);
int call_errno = errno;
uint64_t elapsed = now_ns() - start;
if (result == 0) bl_storage_owner(fd, out);
if (result == 0 && on_selected_device(fd, out)) {
add(&stats.fstat_calls, 1);
add(&stats.fstat_elapsed_ns, elapsed);
+24 -1
View File
@@ -1,6 +1,7 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifndef WEBHELPER_DEFAULT
#define WEBHELPER_DEFAULT "--no-zygote --in-process-gpu -AudioServiceOutOfProcess"
@@ -25,8 +26,30 @@ static char *join_features(const char *have, const char *add) {
return strcat(out, add);
}
static char *const *chromium_argv(const char *path, char *const argv[]) {
const char *slash = path ? strrchr(path, '/') : NULL;
if (!slash || !argv || !argv[0]) return argv;
int argc = 0;
for (; argv[argc]; argc++)
if (argc && (!strncmp(argv[argc], "--type=", 7) || !strcmp(argv[argc], "--no-sandbox"))) return argv;
size_t dir = (size_t)(slash - path) + 1;
char *sandbox = malloc(dir + sizeof "chrome-sandbox");
if (!sandbox) return argv;
memcpy(sandbox, path, dir);
strcpy(sandbox + dir, "chrome-sandbox");
int chromium = access(sandbox, F_OK) == 0;
free(sandbox);
if (!chromium) return argv;
char **out = calloc((size_t)argc + 2, sizeof *out);
if (!out) return argv;
out[0] = argv[0];
out[1] = (char *)"--no-sandbox";
for (int i = 1; i < argc; i++) out[i + 1] = argv[i];
return out;
}
__attribute__((visibility("hidden"))) char *const *bl_webhelper_argv(const char *path, char *const argv[]) {
if (!is_webhelper_browser(path, argv)) return argv;
if (!is_webhelper_browser(path, argv)) return chromium_argv(path, argv);
const char *spec = getenv("BL_WEBHELPER_ARGS");
if (!spec || !*spec) spec = WEBHELPER_DEFAULT;
if (!strcmp(spec, "stock")) return argv;