mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
perf: answer chown and bound thermal paths through the proot fast path (#2203)
This commit is contained in:
1 parent
18c7d56409
commit
aba55031c3
7 files changed
+267
-3
No files matched your search
@@ -672,6 +672,18 @@ static int base_of(int dirfd, char *h) {
|
||||
return gone(h, n) ? -1 : 0;
|
||||
}
|
||||
|
||||
static long bound_literal(const char *literal, struct res *r) {
|
||||
struct bind *bd;
|
||||
if (reserved(literal) || bind_of(literal, &bd) < 0 || !bd || bd->glen != strlen(literal) || bd->glen < 2) return FP_SLOW;
|
||||
if (snprintf(r->host, PATH_MAX, "%s", bd->host) >= PATH_MAX) return FP_SLOW;
|
||||
if (sc(SYS_newfstatat, AT_FDCWD, (long)r->host, (long)&r->st, AT_SYMLINK_NOFOLLOW, 0) < 0 || S_ISLNK(r->st.st_mode)) return FP_SLOW;
|
||||
snprintf(r->guest, PATH_MAX, "%s", literal);
|
||||
r->exists = 1;
|
||||
r->moving = 0;
|
||||
r->magic = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long resolve_in(const char *base, const char *path, int follow, struct res *r) {
|
||||
char norm[PATH_MAX];
|
||||
size_t o = 0;
|
||||
@@ -707,6 +719,10 @@ static long resolve_in(const char *base, const char *path, int follow, struct re
|
||||
unsigned h = hash_of(norm);
|
||||
if (!cached(norm, h, r->guest)) {
|
||||
w = walk(r, norm, 1, 0);
|
||||
if (w == FP_SLOW && !trailing) {
|
||||
*slash = '/';
|
||||
return bound_literal(norm, r);
|
||||
}
|
||||
if (w < 0) return w;
|
||||
if (w != GLUE && !S_ISDIR(r->st.st_mode)) return -ENOTDIR;
|
||||
if (!r->moving) remember(norm, h, r->guest);
|
||||
@@ -1204,6 +1220,20 @@ int fchmodat(int dirfd, const char *path, mode_t mode, int flags) {
|
||||
}
|
||||
int chmod(const char *path, mode_t mode) { return fchmodat(AT_FDCWD, path, mode, 0); }
|
||||
|
||||
static long fp_chown(int dirfd, const char *path, uid_t uid, gid_t gid, int flags) {
|
||||
struct res r;
|
||||
long rs = flags & ~AT_SYMLINK_NOFOLLOW ? FP_SLOW : resolve(dirfd, path, (flags & AT_SYMLINK_NOFOLLOW ? 0 : 1) | MAY_BE_UNSEEN, &r);
|
||||
if (rs == 1) rs = -ENOENT;
|
||||
if (rs == 0 || rs == UNSEEN) rs = sc(SYS_fchownat, AT_FDCWD, (long)r.host, (long)uid, (long)gid, flags);
|
||||
return rs;
|
||||
}
|
||||
int fchownat(int dirfd, const char *path, uid_t uid, gid_t gid, int flags) {
|
||||
REAL(fchownat, int (*)(int, const char *, uid_t, gid_t, int));
|
||||
ANSWER(fp_chown(dirfd, path, uid, gid, flags), dirfd, path, real_fchownat(dirfd, path, uid, gid, flags));
|
||||
}
|
||||
int chown(const char *path, uid_t uid, gid_t gid) { return fchownat(AT_FDCWD, path, uid, gid, 0); }
|
||||
int lchown(const char *path, uid_t uid, gid_t gid) { return fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW); }
|
||||
|
||||
static long fp_utimens(int dirfd, const char *path, const struct timespec times[2], int flags) {
|
||||
struct res r;
|
||||
long rs;
|
||||
|
||||
@@ -39,7 +39,7 @@ static int svc_cache_name(const struct dl_phdr_info *info, char *path, size_t si
|
||||
id[2 * j + 1] = hex[b & 15];
|
||||
}
|
||||
id[2 * h.n_descsz] = 0;
|
||||
int n = snprintf(path, size, "/tmp/.droiddeck-svc-v2-%d-%s", svc_android_api, id);
|
||||
int n = snprintf(path, size, "/tmp/.droiddeck-svc-v3-%d-%s", svc_android_api, id);
|
||||
return n > 0 && (size_t)n < size;
|
||||
}
|
||||
at += name + desc;
|
||||
|
||||
@@ -29,7 +29,7 @@ static int svc_supported(int nr) {
|
||||
switch (nr) {
|
||||
case SYS_openat: case SYS_newfstatat: case SYS_statx: case SYS_readlinkat:
|
||||
case SYS_faccessat: case SYS_mkdirat: case SYS_unlinkat: case SYS_renameat:
|
||||
case SYS_renameat2: case SYS_symlinkat: case SYS_fchmodat: case SYS_utimensat:
|
||||
case SYS_renameat2: case SYS_symlinkat: case SYS_fchmodat: case SYS_fchownat: case SYS_utimensat:
|
||||
case SYS_truncate: case SYS_statfs: case SYS_getxattr: case SYS_lgetxattr:
|
||||
case SYS_listxattr: case SYS_llistxattr: case SYS_inotify_add_watch: case SYS_getcwd:
|
||||
return 1;
|
||||
@@ -112,6 +112,7 @@ static long svc_path_call(const long *r) {
|
||||
return fp_rename((int)r[0], path, (int)r[2], other, r[8] == SYS_renameat2 ? (unsigned)r[4] : 0);
|
||||
case SYS_symlinkat: return fp_symlink(path, (int)r[1], other);
|
||||
case SYS_fchmodat: return fp_chmod((int)r[0], path, (mode_t)r[2], 0);
|
||||
case SYS_fchownat: return fp_chown((int)r[0], path, (uid_t)r[2], (gid_t)r[3], (int)r[4]);
|
||||
case SYS_utimensat: return fp_utimens((int)r[0], path, when, (int)r[3]);
|
||||
case SYS_truncate: return fp_truncate(path, (off_t)r[1]);
|
||||
case SYS_statfs: {
|
||||
|
||||
Reference in new issue
Block a user