perf: fast path answers Steam's pre-2.33 stat calls and stays off without the patched proot (#466)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-09 03:14:29 +00:00
1 parent d6ba3d27d8
commit 7c758c817f
3 files changed
+36 -4

No files matched your search

+4 -1
View File
@@ -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)) {
+24 -2
View File
@@ -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);