diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/ProotFastPath.kt b/app/src/main/java/com/droiddeck/launcher/runtime/ProotFastPath.kt index 9b78180466..10538c5bc6 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/ProotFastPath.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/ProotFastPath.kt @@ -24,8 +24,15 @@ object ProotFastPath { /** MAX_BINDS in fastpath.c: past it the library turns itself off, so the session keeps it off. */ const val MAX_BINDS = 256 + /** + * Only the app's own proot (libproot.so, built with patches/0014) lets the trampoline through. + * The runtime's fallback copy (LinuxRuntime.prootBinary) is Termux's, which traps those calls + * too and translates their host paths a second time: every lookup then fails inside the + * process and goes to proot anyway, paying for both. + */ fun enabled(context: Context): Boolean = - SessionPrefs.prootFastPath(context) && !SessionPrefs.prootNoSeccomp(context) + SessionPrefs.prootFastPath(context) && !SessionPrefs.prootNoSeccomp(context) && + LinuxRuntime.prootBinary(context).parent == context.applicationInfo.nativeLibraryDir /** The key for this rootfs and these binds, or null when the library cannot be told them. */ fun key(root: File, binds: List): String? { diff --git a/tools/linuxfs/preload/storage.c b/tools/linuxfs/preload/storage.c index fb85d1b6f6..201f93cd40 100644 --- a/tools/linuxfs/preload/storage.c +++ b/tools/linuxfs/preload/storage.c @@ -262,7 +262,10 @@ int ftruncate(int fd, off_t length) { int known = 0; if (steam_client()) { if (next_fstat == NULL) next_fstat = dlsym(RTLD_NEXT, "fstat"); - known = next_fstat != NULL && next_fstat(fd, &st) == 0 && S_ISREG(st.st_mode) && staging_file(fd); + /* 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); } int result = 0, call_errno = entry_errno; if (!known || length <= st.st_size || !cannot_reserve((long long)st.st_dev)) { diff --git a/tools/proot/fastpath/fastpath.c b/tools/proot/fastpath/fastpath.c index a48b201f89..3a3a10c14c 100644 --- a/tools/proot/fastpath/fastpath.c +++ b/tools/proot/fastpath/fastpath.c @@ -464,6 +464,26 @@ int lstat(const char *path, struct stat *st) { } int lstat64(const char *p, struct stat64 *st) { return lstat(p, (struct stat *)st); } +/* + * The pre-2.33 entry points. Programs linked against an older glibc - the Steam client, + * steamclient.so and filesystem_stdio.so among them - call these rather than stat(), so without + * them every stat the client makes goes to proot: a download's preallocation stats each file it + * creates. On aarch64 the only version is 0 (_STAT_VER), whose struct stat is the one above; + * glibc refuses any other with EINVAL, and so does this. + */ +#define FP_STAT_VER 0 +static int xstat_common(int ver, int dirfd, const char *path, struct stat *st, int flags) { + REAL(fstatat, int (*)(int, const char *, struct stat *, int)); + if (ver != FP_STAT_VER) { errno = EINVAL; return -1; } + return stat_common(dirfd, path, st, flags, real_fstatat); +} +int __xstat(int ver, const char *p, struct stat *st) { return xstat_common(ver, AT_FDCWD, p, st, 0); } +int __xstat64(int ver, const char *p, struct stat64 *st) { return xstat_common(ver, AT_FDCWD, p, (struct stat *)st, 0); } +int __lxstat(int ver, const char *p, struct stat *st) { return xstat_common(ver, AT_FDCWD, p, st, AT_SYMLINK_NOFOLLOW); } +int __lxstat64(int ver, const char *p, struct stat64 *st) { return xstat_common(ver, AT_FDCWD, p, (struct stat *)st, AT_SYMLINK_NOFOLLOW); } +int __fxstatat(int ver, int d, const char *p, struct stat *st, int f) { return xstat_common(ver, d, p, st, f); } +int __fxstatat64(int ver, int d, const char *p, struct stat64 *st, int f) { return xstat_common(ver, d, p, (struct stat *)st, f); } + int statx(int dirfd, const char *path, int flags, unsigned mask, struct statx *out) { REAL(statx, int (*)(int, const char *, int, unsigned, struct statx *)); char host[PATH_MAX]; @@ -483,8 +503,10 @@ static int access_common(int dirfd, const char *path, int mode, int flags) { REAL(faccessat, int (*)(int, const char *, int, int)); char host[PATH_MAX]; struct stat st; - /* faccessat(2) has no flags: AT_EACCESS and AT_SYMLINK_NOFOLLOW stay with glibc and proot. */ - long rs = flags == 0 ? resolve(dirfd, path, host) : FP_SLOW; + /* faccessat(2) has no flags. AT_EACCESS stays with glibc and proot; AT_SYMLINK_NOFOLLOW (the + * Steam client passes it for every file it reserves) only differs on a symlink, which goes to + * proot as well. */ + long rs = (flags & ~AT_SYMLINK_NOFOLLOW) == 0 ? resolve(dirfd, path, host) : FP_SLOW; if (rs == -ENOENT) { hits++; return ret(rs); } if (rs == 0) { long k = kind(host, &st);