diff --git a/.github/workflows/build-bionic-runtime.yml b/.github/workflows/build-bionic-runtime.yml index 251163fc05..2bc5091fd9 100644 --- a/.github/workflows/build-bionic-runtime.yml +++ b/.github/workflows/build-bionic-runtime.yml @@ -7,6 +7,7 @@ on: - 'tools/gamescope/patches/0117-wsi-cache-present-bypass-check.patch' - 'tools/gamescope/patches/0119-wsi-default-images-under-limiter.patch' - 'app/src/main/cpp/fakeinput_steam.cpp' + - 'tools/gpuload/**' - '.github/workflows/build-bionic-runtime.yml' workflow_dispatch: diff --git a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt index 6839bea32d..146509bba7 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt @@ -207,19 +207,27 @@ object ComponentsManager { if (comp == "fex" && file != null) fetchFexTwin(context, safeName(file)) } + // Twin downloads in flight: one worker per name, so two profile changes cannot share one partial download. + private val twinDownloads = HashSet() + private fun fetchFexTwin(context: Context, file: String) { val twin = fexTwin(file) ?: return - if (isStored(context, twin) || protons(context).all { fexFits(it.dir.name, file) }) return + if (protons(context).all { fexFits(it.dir.name, file) }) return + synchronized(lock) { if (isStored(context, twin) || !twinDownloads.add(twin)) return } val app = context.applicationContext Thread({ - runCatching { - val item = catalogItem(app, twin, if (bionicFex(twin)) DD_BIONIC else "FexCore-Linux") - if (item == null) Log.i(TAG, "$twin is not listed") - else { - download(app, item) {} - republish(app) - } - }.onFailure { Log.w(TAG, "download $twin", it) } + try { + runCatching { + val item = catalogItem(app, twin, if (bionicFex(twin)) DD_BIONIC else "FexCore-Linux") + if (item == null) Log.i(TAG, "$twin is not listed") + else { + download(app, item) {} + republish(app) + } + }.onFailure { Log.w(TAG, "download $twin", it) } + } finally { + synchronized(lock) { twinDownloads.remove(twin) } + } }, "fex-twin").start() } @@ -832,6 +840,18 @@ object ComponentsManager { internal fun liveOnAny(key: String, entry: JSONObject, installs: List?): Boolean = installs?.any { liveSelection(key, entry, it) } == true + // An installed tool that launches with `name` as the stored twin of a game's FEX choice (a Linux choice on + // DroidDeck-Bionic, a -bionic one on another Proton): deleting the twin would drop that choice for that tool. + internal fun twinUser(state: JSONObject, installed: List, name: String): Proton? { + val profiles = state.optJSONObject("profiles") ?: return null + for (scope in profiles.keys()) { + val chosen = profiles.optJSONObject(scope)?.optString("fex")?.takeIf { it.isNotEmpty() } ?: continue + if (fexTwin(chosen) != name) continue + installed.firstOrNull { !fexFits(it.dir.name, chosen) }?.let { return it } + } + return null + } + internal fun packagesInUse(state: JSONObject, installed: List): Set { val byId = installed.groupBy { it.id } val names = HashSet() @@ -1004,6 +1024,8 @@ object ComponentsManager { fun deletePackage(context: Context, file: String): String = synchronized(lock) { val name = safeName(file) val state = loadState(context) + val twinTool = twinUser(state, protons(context), name) + check(twinTool == null) { context.getString(R.string.cmgr_package_in_use, name, twinTool?.name ?: "") } val installed = protons(context).groupBy { it.id } var changed = false for (key in listOf("queued", "active")) { diff --git a/app/src/test/java/com/droiddeck/launcher/session/ComponentsBionicFexTest.kt b/app/src/test/java/com/droiddeck/launcher/session/ComponentsBionicFexTest.kt index f4af8ba682..99bd6ef90e 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/ComponentsBionicFexTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/ComponentsBionicFexTest.kt @@ -84,6 +84,14 @@ class ComponentsBionicFexTest { ComponentsManager.packagesInUse(state, listOf(proton(ownTool), proton(bionicTool)))) } + @Test fun aTwinAGameChoiceStillNeedsCannotBeDeletedAsUnused() { + val state = JSONObject().put("profiles", JSONObject().put("42", JSONObject().put("fex", "FEXCore-2611.1-linux.wcp"))) + assertEquals(bionicTool, ComponentsManager.twinUser(state, listOf(proton(ownTool), proton(bionicTool)), "FEXCore-2611.1-bionic.wcp")?.dir?.name) + assertEquals(null, ComponentsManager.twinUser(state, listOf(proton(ownTool)), "FEXCore-2611.1-bionic.wcp")) + assertEquals(null, ComponentsManager.twinUser(state, listOf(proton(ownTool), proton(bionicTool)), "FEXCore-2610-bionic.wcp")) + assertEquals(null, ComponentsManager.twinUser(JSONObject(), listOf(proton(bionicTool)), "FEXCore-2611.1-bionic.wcp")) + } + @Test fun droidDeckBionicFollowsTheNewestBionicFexAndNothingElse() { val bionic = proton(bionicTool) val own = proton(ownTool) diff --git a/tools/bionic-runtime/check-needed.py b/tools/bionic-runtime/check-needed.py index 0087f07ccf..929b2c9a4b 100755 --- a/tools/bionic-runtime/check-needed.py +++ b/tools/bionic-runtime/check-needed.py @@ -37,15 +37,18 @@ def elf_files(pack): def needed(readelf, path): - out = subprocess.run([readelf, "-d", path], capture_output=True, text=True).stdout - return [l.split("[", 1)[1].split("]", 1)[0] for l in out.splitlines() if "(NEEDED)" in l] + run = subprocess.run([readelf, "-d", path], capture_output=True, text=True) + if run.returncode != 0: # a damaged ELF must fail the check, not pass with no dependencies + raise SystemExit("check-needed: %s -d %s failed (%d): %s" % (readelf, path, run.returncode, run.stderr.strip())) + return [l.split("[", 1)[1].split("]", 1)[0] for l in run.stdout.splitlines() if "(NEEDED)" in l] def names_in(*dirs): names = set() for d in dirs: - for _, _, files in os.walk(d): - names.update(files) + for root, _, files in os.walk(d): + # a link whose target is missing provides nothing + names.update(f for f in files if os.path.isfile(os.path.join(root, f))) return names diff --git a/tools/bionic-runtime/execshim.c b/tools/bionic-runtime/execshim.c index ece81aa605..166b9cb6fd 100644 --- a/tools/bionic-runtime/execshim.c +++ b/tools/bionic-runtime/execshim.c @@ -20,6 +20,7 @@ typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t; #endif #include #include +#include #include #define LINKER "/system/bin/linker64" @@ -29,8 +30,14 @@ enum kind { PASS, VIA_LINKER, VIA_INTERP }; // What starting `path` needs; for scripts, the interpreter and its optional argument. static enum kind classify(const char *path, char *resolved, char *interp, char *iarg) { if (!path || !realpath(path, resolved) || strncmp(resolved, "/data/", 6) != 0) return PASS; - int fd = open(resolved, O_RDONLY | O_CLOEXEC); + // non-blocking, so a FIFO without a writer cannot hang the start; anything but a regular file goes to libc + int fd = open(resolved, O_RDONLY | O_CLOEXEC | O_NONBLOCK); if (fd < 0) return PASS; + struct stat st; + if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) { + close(fd); + return PASS; + } enum kind k = PASS; unsigned char head[256]; ssize_t n = pread(fd, head, sizeof head, 0); @@ -81,7 +88,8 @@ static char **rewrite(const char *path, char *const argv[], const char **file, c enum kind k = classify(path, resolved, interp, iarg); if (k == PASS) return NULL; int argc = argc_of(argv); - char **out = calloc((size_t)argc + 4, sizeof *out); + // up to four leading entries, argc - 1 trailing ones and the terminator (argc may be 0) + char **out = calloc((size_t)(argc > 0 ? argc - 1 : 0) + 5, sizeof *out); if (!out) return NULL; int j = 0; if (k == VIA_LINKER) { @@ -107,11 +115,41 @@ static char **rewrite(const char *path, char *const argv[], const char **file, c return out; } -static ssize_t (*real_readlink)(const char *, char *, size_t); +// libc's functions: bound when the library loads (single-threaded), so execve() in a post-fork child finds them bound. +// A call that comes before that (another library's constructor) binds through an atomic slot: concurrent binders +// store the same pointer, and readers never see a torn one. +typedef ssize_t (*readlink_fn)(const char *, char *, size_t); +typedef char *(*realpath_fn)(const char *, char *); +typedef int (*execve_fn)(const char *, char *const[], char *const[]); +typedef int (*spawn_fn)(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *, + char *const[], char *const[]); +static void *slot_readlink, *slot_realpath, *slot_execve, *slot_spawn, *slot_spawnp; + +static void *bound(void **slot, const char *name) { + void *p = __atomic_load_n(slot, __ATOMIC_ACQUIRE); + if (!p) { + p = dlsym(RTLD_NEXT, name); + __atomic_store_n(slot, p, __ATOMIC_RELEASE); + } + return p; +} +#define real_readlink ((readlink_fn)bound(&slot_readlink, "readlink")) +#define real_realpath ((realpath_fn)bound(&slot_realpath, "realpath")) +#define real_execve ((execve_fn)bound(&slot_execve, "execve")) +#define real_spawn ((spawn_fn)bound(&slot_spawn, "posix_spawn")) +#define real_spawnp ((spawn_fn)bound(&slot_spawnp, "posix_spawnp")) + +__attribute__((constructor)) static void bind_libc(void) { + (void)real_readlink; + (void)real_realpath; + (void)real_execve; + (void)real_spawn; + (void)real_spawnp; +} // The program linker64 runs, when this process is such a start; 0 otherwise. static int linker_program(char *out, size_t n) { - if (!real_readlink) real_readlink = (ssize_t (*)(const char *, char *, size_t))dlsym(RTLD_NEXT, "readlink"); + if (!real_readlink) return 0; char link[PATH_MAX]; ssize_t l = real_readlink("/proc/self/exe", link, sizeof link - 1); if (l <= 0) return 0; @@ -132,32 +170,38 @@ static int linker_program(char *out, size_t n) { } char *realpath(const char *path, char *resolved) { - static char *(*real)(const char *, char *); - if (!real) real = (char *(*)(const char *, char *))dlsym(RTLD_NEXT, "realpath"); + if (!real_realpath) { + errno = ENOSYS; + return NULL; + } char prog[PATH_MAX]; - if (path && strcmp(path, "/proc/self/exe") == 0 && linker_program(prog, sizeof prog)) return real(prog, resolved); - return real(path, resolved); + if (path && strcmp(path, "/proc/self/exe") == 0 && linker_program(prog, sizeof prog)) return real_realpath(prog, resolved); + return real_realpath(path, resolved); } ssize_t readlink(const char *path, char *buf, size_t size) { char prog[PATH_MAX], full[PATH_MAX]; if (path && strcmp(path, "/proc/self/exe") == 0 && linker_program(prog, sizeof prog)) { - static char *(*real_rp)(const char *, char *); - if (!real_rp) real_rp = (char *(*)(const char *, char *))dlsym(RTLD_NEXT, "realpath"); - if (real_rp(prog, full)) { + if (real_realpath && real_realpath(prog, full)) { size_t l = strlen(full); if (l > size) l = size; memcpy(buf, full, l); return (ssize_t)l; } } - if (!real_readlink) real_readlink = (ssize_t (*)(const char *, char *, size_t))dlsym(RTLD_NEXT, "readlink"); + if (!real_readlink) { + errno = ENOSYS; + return -1; + } return real_readlink(path, buf, size); } int execve(const char *path, char *const argv[], char *const envp[]) { - static int (*real)(const char *, char *const[], char *const[]); - if (!real) real = (int (*)(const char *, char *const[], char *const[]))dlsym(RTLD_NEXT, "execve"); + execve_fn real = real_execve; + if (!real) { + errno = ENOSYS; + return -1; + } char storage[6 * PATH_MAX]; // stack only: this may run in posix_spawn's vfork-like child (where it passes) const char *file = path; char **args = rewrite(path, argv, &file, storage); @@ -170,14 +214,13 @@ int execve(const char *path, char *const argv[], char *const envp[]) { int posix_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *actions, const posix_spawnattr_t *attr, char *const argv[], char *const envp[]) { - static int (*real)(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *, - char *const[], char *const[]); - if (!real) - real = (int (*)(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *, - char *const[], char *const[]))dlsym(RTLD_NEXT, "posix_spawn"); + spawn_fn real = real_spawn; + if (!real) return ENOSYS; char storage[6 * PATH_MAX]; const char *file = path; - char **args = rewrite(path, argv, &file, storage); + // file actions can change the child's directory before it starts: a relative path is resolved there by libc, so + // it is left to libc instead of being resolved here against the parent's directory + char **args = (actions && path && path[0] != '/') ? NULL : rewrite(path, argv, &file, storage); int ret = real(pid, file, actions, attr, args ? args : argv, envp); free(args); return ret; @@ -185,11 +228,8 @@ int posix_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t * int posix_spawnp(pid_t *pid, const char *file, const posix_spawn_file_actions_t *actions, const posix_spawnattr_t *attr, char *const argv[], char *const envp[]) { - static int (*real)(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *, - char *const[], char *const[]); - if (strchr(file, '/')) return posix_spawn(pid, file, actions, attr, argv, envp); - if (!real) - real = (int (*)(pid_t *, const char *, const posix_spawn_file_actions_t *, const posix_spawnattr_t *, - char *const[], char *const[]))dlsym(RTLD_NEXT, "posix_spawnp"); + if (file && strchr(file, '/')) return posix_spawn(pid, file, actions, attr, argv, envp); + spawn_fn real = real_spawnp; + if (!real) return ENOSYS; return real(pid, file, actions, attr, argv, envp); } diff --git a/tools/bionic-runtime/gstag.c b/tools/bionic-runtime/gstag.c index db5880e757..5870c2d341 100644 --- a/tools/bionic-runtime/gstag.c +++ b/tools/bionic-runtime/gstag.c @@ -20,7 +20,8 @@ #include #include -static int fd; +static int fd, tconn = -1, cconn = -1; +static uint16_t tseq, cseq; // sequence number of the last request sent on each connection static uint8_t rbuf[1 << 16]; static uint32_t pending[256]; static int npending; static uint32_t tagged[256]; static int ntagged; @@ -36,27 +37,54 @@ static int rd(void *p, size_t n) { return 0; } static size_t pad4(size_t n) { return (n + 3) & ~(size_t)3; } + +// Sends one request on the current connection; its sequence number goes to *seq. 0 when sent. +static int request(const void *p, size_t n, uint16_t *seq) { + if (wr(p, n)) return -1; + uint16_t *last = (fd == cconn && cconn != tconn) ? &cseq : &tseq; + ++*last; + if (seq) *seq = *last; + return 0; +} + +// Reads one whole packet into rbuf; a reply (or generic event) longer than rbuf ends the connection. 0 when read. +static int packet(void) { + if (rd(rbuf, 32)) return -1; + uint8_t type = rbuf[0] & 0x7f; + if (rbuf[0] == 1 || type == 35) { + uint32_t words = *(uint32_t *)(rbuf + 4); + if (words > (sizeof rbuf - 32) / 4) return -1; + if (words && rd(rbuf + 32, words * 4u)) return -1; + } + return 0; +} static int known(uint32_t *list, int n, uint32_t w) { for (int i = 0; i < n; i++) if (list[i] == w) return 1; return 0; } +static void forget(uint32_t *list, int *n, uint32_t w) { + for (int i = 0; i < *n; i++) + if (list[i] == w) { list[i] = list[--*n]; return; } +} + static void note_event(const uint8_t *e) { uint8_t type = e[0] & 0x7f; - uint32_t win = 0; - if (type == 16) win = *(uint32_t *)(e + 8); // CreateNotify - else if (type == 19) win = *(uint32_t *)(e + 8); // MapNotify + uint32_t win = *(uint32_t *)(e + 8); + if (type == 17) { // DestroyNotify: a destroyed window is neither a candidate nor a tagged game window + forget(pending, &npending, win); + forget(tagged, &ntagged, win); + return; + } + if (type != 16 && type != 19) return; // CreateNotify, MapNotify if (win && !known(tagged, ntagged, win) && !known(pending, npending, win) && npending < 256) pending[npending++] = win; } -// Reads one packet. Returns 1 reply, 0 error, -1 io; events are noted and skipped. -static int reply(void) { +// Reads until the answer to request `seq`. Returns 1 reply, 0 error, -1 io. Events are noted; errors of requests +// without a reply (a ChangeProperty on a window that is gone) and other stale packets are skipped. +static int reply(uint16_t seq) { for (;;) { - if (rd(rbuf, 32)) return -1; - if (rbuf[0] == 0) return 0; - if (rbuf[0] == 1) { - uint32_t extra = *(uint32_t *)(rbuf + 4) * 4; - if (extra > sizeof rbuf - 32 || (extra && rd(rbuf + 32, extra))) return -1; - return 1; - } - note_event(rbuf); + if (packet()) return -1; + if (rbuf[0] > 1) { note_event(rbuf); continue; } + if (*(uint16_t *)(rbuf + 2) != seq) continue; + return rbuf[0] == 1; } } @@ -67,8 +95,9 @@ static uint32_t intern(const char *name) { *(uint16_t *)(req + 2) = (uint16_t)(2 + pad4(n) / 4); *(uint16_t *)(req + 4) = (uint16_t)n; memcpy(req + 8, name, n); - if (wr(req, 8 + pad4(n))) return 0; - return reply() == 1 ? *(uint32_t *)(rbuf + 8) : 0; + uint16_t seq; + if (request(req, 8 + pad4(n), &seq)) return 0; + return reply(seq) == 1 ? *(uint32_t *)(rbuf + 8) : 0; } // WM_CLASS of a window into out (both strings joined by '|'); 0 if none. @@ -80,7 +109,8 @@ static int wm_class(uint32_t win, char *out, size_t cap) { *(uint32_t *)(req + 8) = 67; // WM_CLASS *(uint32_t *)(req + 12) = 31; // STRING *(uint32_t *)(req + 20) = 64; - if (wr(req, sizeof req) || reply() != 1) return 0; + uint16_t seq; + if (request(req, sizeof req, &seq) || reply(seq) != 1) return 0; uint32_t n = *(uint32_t *)(rbuf + 16); if (!n || n >= cap) return 0; for (uint32_t i = 0; i < n; i++) out[i] = rbuf[32 + i] ? (char)rbuf[32 + i] : '|'; @@ -99,17 +129,28 @@ static void set_cards(uint32_t win, uint32_t prop, const uint32_t *values, uint3 req[16] = 32; *(uint32_t *)(req + 20) = n; memcpy(req + 24, values, 4 * n); - wr(req, 24 + 4 * n); + request(req, 24 + 4 * n, NULL); } -// First CARDINAL of a root property, or 0 when unset. -static uint32_t first_card(uint32_t root, uint32_t prop) { +// First CARDINAL of a root property into *value (0 when unset). 0 when the property could not be read. +static int first_card(uint32_t root, uint32_t prop, uint32_t *value) { uint8_t gp[24] = {20, 0, 6, 0}; + uint16_t seq; *(uint32_t *)(gp + 4) = root; *(uint32_t *)(gp + 8) = prop; *(uint32_t *)(gp + 20) = 64; - if (wr(gp, sizeof gp) || reply() != 1) return 0; - return *(uint32_t *)(rbuf + 16) ? *(uint32_t *)(rbuf + 32) : 0; + if (request(gp, sizeof gp, &seq) || reply(seq) != 1) return 0; + *value = *(uint32_t *)(rbuf + 16) ? *(uint32_t *)(rbuf + 32) : 0; + return 1; +} + +// 1 when the window still exists (GetWindowAttributes answers), 0 when it is gone, -1 on an io failure. +static int alive(uint32_t win) { + uint8_t ga[8] = {3, 0, 2, 0}; + uint16_t seq; + *(uint32_t *)(ga + 4) = win; + if (request(ga, sizeof ga, &seq)) return -1; + return reply(seq); } static void set_card(uint32_t win, uint32_t prop, uint32_t value) { @@ -122,7 +163,7 @@ static void set_card(uint32_t win, uint32_t prop, uint32_t value) { req[16] = 32; *(uint32_t *)(req + 20) = 1; *(uint32_t *)(req + 24) = value; - wr(req, sizeof req); + request(req, sizeof req, NULL); } // Connects to display : (abstract socket) and returns the socket, its root window in *root; -1 on failure. @@ -162,6 +203,8 @@ int main(int argc, char **argv) { if (c >= 0) cfd = c; else croot = root; } + tconn = tfd; + cconn = cfd; fd = tfd; uint32_t a_game = intern("STEAM_GAME"); @@ -169,11 +212,12 @@ int main(int argc, char **argv) { *(uint32_t *)(cwa + 4) = root; *(uint32_t *)(cwa + 8) = 0x800; *(uint32_t *)(cwa + 12) = 0x80000; - wr(cwa, sizeof cwa); + request(cwa, sizeof cwa, NULL); uint8_t qt[8] = {15, 0, 2, 0}; // QueryTree(root): windows that exist already + uint16_t qseq; *(uint32_t *)(qt + 4) = root; - if (wr(qt, sizeof qt) == 0 && reply() == 1) { + if (request(qt, sizeof qt, &qseq) == 0 && reply(qseq) == 1) { uint16_t nk = *(uint16_t *)(rbuf + 16); uint32_t kids[1024]; if (nk > 1024) nk = 1024; @@ -187,7 +231,7 @@ int main(int argc, char **argv) { uint32_t a_focus = intern("GAMESCOPE_FOCUSED_APP"); uint32_t a_ctrl = intern("GAMESCOPECTRL_BASELAYER_APPID"); fd = tfd; - time_t tagged_at = 0; int focus_checked = 0; + time_t tagged_at = 0; int focus_checked = 0, focus_reads = 0; time_t end = time(NULL) + seconds, next_status = time(NULL) + 3; while (time(NULL) < end) { if (time(NULL) >= next_status) { @@ -201,7 +245,8 @@ int main(int argc, char **argv) { *(uint32_t *)(gp + 4) = croot; *(uint32_t *)(gp + 8) = props[k]; *(uint32_t *)(gp + 20) = 64; - if (wr(gp, sizeof gp) == 0 && reply() == 1) { + uint16_t gseq; + if (request(gp, sizeof gp, &gseq) == 0 && reply(gseq) == 1) { uint32_t cnt = *(uint32_t *)(rbuf + 16); printf(" %s=[", names[k]); for (uint32_t i = 0; i < cnt && i < 16; i++) printf("%s%u", i ? "," : "", ((uint32_t *)(rbuf + 32))[i]); @@ -211,26 +256,42 @@ int main(int argc, char **argv) { fd = tfd; for (int i = 0; i < ntagged; i++) { uint8_t ga[8] = {3, 0, 2, 0}; // GetWindowAttributes + uint16_t aseq, gseq; *(uint32_t *)(ga + 4) = tagged[i]; int map = -1, ovr = -1, w = -1, h = -1; - if (wr(ga, sizeof ga) == 0 && reply() == 1) { map = rbuf[26]; ovr = rbuf[27]; } + if (request(ga, sizeof ga, &aseq) == 0 && reply(aseq) == 1) { map = rbuf[26]; ovr = rbuf[27]; } uint8_t gg[8] = {14, 0, 2, 0}; // GetGeometry *(uint32_t *)(gg + 4) = tagged[i]; - if (wr(gg, sizeof gg) == 0 && reply() == 1) { w = *(uint16_t *)(rbuf + 16); h = *(uint16_t *)(rbuf + 18); } + if (request(gg, sizeof gg, &gseq) == 0 && reply(gseq) == 1) { w = *(uint16_t *)(rbuf + 16); h = *(uint16_t *)(rbuf + 18); } printf(" win0x%x=%dx%d map%d ovr%d", tagged[i], w, h, map, ovr); } printf("\n"); } if (tagged_at && !focus_checked && time(NULL) - tagged_at >= 8) { - focus_checked = 1; + // the override is only for a game that still has a window: a tagged window that was destroyed is gone + // from `tagged` (DestroyNotify), and one that is left must still answer + int live = 0; + for (int i = 0; i < ntagged && !live; i++) live = alive(tagged[i]) == 1; + uint32_t f = 0; fd = cfd; - uint32_t f = first_card(croot, a_focus); - if (f != appid) { - uint32_t ids[2] = {appid, 769}; - set_cards(croot, a_ctrl, ids, 2); - printf("gstag: focus was %u, not %u, 8 s after the tag; set GAMESCOPECTRL_BASELAYER_APPID=%u,769\n", f, appid, appid); - } else printf("gstag: %u has focus\n", appid); + int read_ok = live && first_card(croot, a_focus, &f); fd = tfd; + if (!live) { + focus_checked = 1; + printf("gstag: no tagged window left 8 s after the tag; focus left as it is\n"); + } else if (!read_ok) { + // a failed read says nothing about who has focus: try again on the next pass, a few times + if (++focus_reads >= 3) { focus_checked = 1; printf("gstag: focus could not be read; left as it is\n"); } + } else { + focus_checked = 1; + if (f != appid) { + uint32_t ids[2] = {appid, 769}; + fd = cfd; + set_cards(croot, a_ctrl, ids, 2); + fd = tfd; + printf("gstag: focus was %u, not %u, 8 s after the tag; set GAMESCOPECTRL_BASELAYER_APPID=%u,769\n", f, appid, appid); + } else printf("gstag: %u has focus\n", appid); + } } if (watch && kill(watch, 0) != 0 && errno == ESRCH) { printf("gstag: pid %d gone, stopping\n", watch); break; } for (int i = 0; i < npending; ) { @@ -247,11 +308,22 @@ int main(int argc, char **argv) { fd_set rs; FD_ZERO(&rs); FD_SET(fd, &rs); struct timeval tv = {0, 500000}; if (select(fd + 1, &rs, NULL, NULL, &tv) > 0) { - if (rd(rbuf, 32)) { printf("gstag: connection closed\n"); break; } - if (rbuf[0] == 1) { uint32_t x = *(uint32_t *)(rbuf + 4) * 4; if (x && rd(rbuf + 32, x)) break; } - else if (rbuf[0] != 0) note_event(rbuf); + if (packet()) { printf("gstag: connection closed or a packet too long\n"); break; } + if (rbuf[0] > 1) note_event(rbuf); // replies and errors here belong to no request waiting + } + if (npending > 200) { + // drop only windows that are gone; live candidates may still get WM_CLASS + for (int i = 0; i < npending; ) { + int a = alive(pending[i]); + if (a < 0) break; + if (a == 0) pending[i] = pending[--npending]; + else i++; + } + if (npending > 200) { // still too many: keep the newest + memmove(pending, pending + (npending - 200), 200 * sizeof *pending); + npending = 200; + } } - if (npending > 200) npending = 0; } printf("gstag: done, %d window(s) tagged\n", ntagged); return 0; diff --git a/tools/bionic-runtime/steamshm.c b/tools/bionic-runtime/steamshm.c index 01a60710ce..16eb686b99 100644 --- a/tools/bionic-runtime/steamshm.c +++ b/tools/bionic-runtime/steamshm.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #define EXPORT __attribute__((visibility("default"))) @@ -98,18 +99,33 @@ static int hook_open(const char *name, size_t size, bool *created) return fd; } if (errno != ENOENT) break; - fd = open(path, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0600); - if (fd >= 0) { - if (ftruncate(fd, (off_t)size) == 0) { - if (created) *created = true; - if (notes++ < 64) say("steamshm: %s created (%zu bytes)\n", path, size); - return fd; - } + // made and sized under a private name, then put in place in one step: no other process can open it while it + // is still empty, and an object another process published first is opened instead + char tmp[PATH_MAX]; + int w = snprintf(tmp, sizeof tmp, "%s.%d.%d", path, (int)getpid(), i); + if (w <= 0 || (size_t)w >= sizeof tmp) break; + fd = open(tmp, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, 0600); + if (fd < 0) break; + if (ftruncate(fd, (off_t)size) != 0) { close(fd); - unlink(path); + unlink(tmp); break; } - if (errno != EEXIST) break; + int placed = (int)syscall(SYS_renameat2, AT_FDCWD, tmp, AT_FDCWD, path, 1 /* RENAME_NOREPLACE */); + if (placed != 0 && (errno == ENOSYS || errno == EINVAL)) { // no renameat2: a hard link fails on EEXIST too + placed = link(tmp, path); + unlink(tmp); + } + if (placed == 0) { + if (created) *created = true; + if (notes++ < 64) say("steamshm: %s created (%zu bytes)\n", path, size); + return fd; + } + int err = errno; + close(fd); + unlink(tmp); + errno = err; + if (err != EEXIST) break; } say("steamshm: %s failed (errno %d)\n", path, errno); return -1; @@ -286,30 +302,109 @@ static void *trampoline(uint32_t *fn) if (t == MAP_FAILED) return NULL; memcpy(t, fn, 16); jump_code(t + 4, (uintptr_t)(fn + 4)); - if (mprotect(t, page, PROT_READ | PROT_EXEC)) return NULL; + if (mprotect(t, page, PROT_READ | PROT_EXEC)) { + munmap(t, page); + return NULL; + } flush((uintptr_t)t, 32); return t; } -// The library's code pages are file mappings: write an anonymous copy and move it over the original in one step. -static bool redirect(uint32_t *fn, uintptr_t to) +static void drop_trampoline(void *t) { - size_t page = getauxval(AT_PAGESZ); - uintptr_t lo = (uintptr_t)fn & ~(page - 1), hi = ((uintptr_t)fn + 16 + page - 1) & ~(page - 1); - size_t len = hi - lo; - uint8_t *copy = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (copy == MAP_FAILED) return false; - memcpy(copy, (void *)lo, len); - jump_code((uint32_t *)(copy + ((uintptr_t)fn - lo)), to); - if (mprotect(copy, len, PROT_READ | PROT_EXEC) || - mremap(copy, len, len, MREMAP_MAYMOVE | MREMAP_FIXED, (void *)lo) == MAP_FAILED) { - munmap(copy, len); + if (t) munmap(t, getauxval(AT_PAGESZ)); +} + +// The library's code pages are file mappings: patched anonymous copies are prepared first and then moved over the +// originals in one step each. Both hooks go in or neither: the pages of both functions (one range when they share a +// page) are copied, patched and made executable before anything is replaced, and a copy of the original pages is +// kept, so a failed second replacement puts the first range back. +struct range { + uintptr_t lo; + size_t len; + uint8_t *patched, *saved; +}; + +static bool prepare(struct range *r, uintptr_t lo, uintptr_t hi) +{ + r->lo = lo; + r->len = hi - lo; + r->patched = mmap(NULL, r->len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + r->saved = mmap(NULL, r->len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (r->patched == MAP_FAILED || r->saved == MAP_FAILED) { + if (r->patched != MAP_FAILED) munmap(r->patched, r->len); + if (r->saved != MAP_FAILED) munmap(r->saved, r->len); + r->patched = r->saved = NULL; return false; } - flush(lo, len); + memcpy(r->patched, (void *)lo, r->len); + memcpy(r->saved, (void *)lo, r->len); return true; } +static void patch(struct range *r, uint32_t *fn, uintptr_t to) +{ + if ((uintptr_t)fn >= r->lo && (uintptr_t)fn + 16 <= r->lo + r->len) + jump_code((uint32_t *)(r->patched + ((uintptr_t)fn - r->lo)), to); +} + +static bool seal(struct range *r) +{ + return !mprotect(r->patched, r->len, PROT_READ | PROT_EXEC) && !mprotect(r->saved, r->len, PROT_READ | PROT_EXEC); +} + +static bool commit(struct range *r) +{ + if (mremap(r->patched, r->len, r->len, MREMAP_MAYMOVE | MREMAP_FIXED, (void *)r->lo) == MAP_FAILED) return false; + r->patched = NULL; // now the mapping at lo + flush(r->lo, r->len); + return true; +} + +static void restore(struct range *r) +{ + if (r->saved && mremap(r->saved, r->len, r->len, MREMAP_MAYMOVE | MREMAP_FIXED, (void *)r->lo) != MAP_FAILED) { + r->saved = NULL; + flush(r->lo, r->len); + } +} + +static void release(struct range *r) +{ + if (r->patched) munmap(r->patched, r->len); + if (r->saved) munmap(r->saved, r->len); + r->patched = r->saved = NULL; +} + +static bool redirect_both(uint32_t *fa, uintptr_t ta, uint32_t *fb, uintptr_t tb) +{ + size_t page = getauxval(AT_PAGESZ); + uintptr_t alo = (uintptr_t)fa & ~(page - 1), ahi = ((uintptr_t)fa + 16 + page - 1) & ~(page - 1); + uintptr_t blo = (uintptr_t)fb & ~(page - 1), bhi = ((uintptr_t)fb + 16 + page - 1) & ~(page - 1); + struct range r[2] = {{0}}; + int n = 1; + if (alo < bhi && blo < ahi) { // overlapping pages: one range holds both patches + if (!prepare(&r[0], alo < blo ? alo : blo, ahi > bhi ? ahi : bhi)) return false; + } else if (!prepare(&r[0], alo, ahi) || !prepare(&r[1], blo, bhi)) { + release(&r[0]); + release(&r[1]); + return false; + } else n = 2; + for (int i = 0; i < n; i++) { + patch(&r[i], fa, ta); + patch(&r[i], fb, tb); + } + bool ok = true; + for (int i = 0; i < n && ok; i++) ok = seal(&r[i]); + if (ok && !commit(&r[0])) ok = false; + else if (ok && n == 2 && !commit(&r[1])) { + restore(&r[0]); + ok = false; + } + for (int i = 0; i < n; i++) release(&r[i]); + return ok; +} + static void install(void) { const char *mode = getenv("DROIDDECK_BIONIC_STEAMSHM"); @@ -335,8 +430,12 @@ static void install(void) } orig_open = (shm_open_fn)trampoline(open_fn); orig_unlink = (shm_unlink_fn)trampoline(unlink_fn); - if (!orig_open || !orig_unlink || !redirect(unlink_fn, (uintptr_t)hook_unlink) || - !redirect(open_fn, (uintptr_t)hook_open)) { + if (!orig_open || !orig_unlink || + !redirect_both(unlink_fn, (uintptr_t)hook_unlink, open_fn, (uintptr_t)hook_open)) { + drop_trampoline((void *)orig_open); + drop_trampoline((void *)orig_unlink); + orig_open = NULL; + orig_unlink = NULL; say("steamshm: could not redirect the library's shared memory; left as it is\n"); return; } diff --git a/tools/bionic-runtime/tool/launch.sh b/tools/bionic-runtime/tool/launch.sh index 2cc37ccb0d..c406cfd1d7 100644 --- a/tools/bionic-runtime/tool/launch.sh +++ b/tools/bionic-runtime/tool/launch.sh @@ -253,7 +253,8 @@ programs_left() { # a program of this prefix is still running, apart from Wine's [ "$q" = "$$" ] || [ "$q" = "${GT:-x}" ] && continue c=; read -r c < "$p/comm" 2>/dev/null case "$c" in - ""|wineserver|services.exe|winedevice.exe|plugplay.exe|explorer.exe|svchost.exe|rpcss.exe|conhost.exe|start.exe) continue ;; + ""|wineserver|services.exe|winedevice.exe|plugplay.exe|explorer.exe|svchost.exe|rpcss.exe|conhost.exe|start.exe|\ + winemenubuilder|wineboot.exe|tabtip.exe) continue ;; esac tr '\0' '\n' < "$p/environ" 2>/dev/null | grep -qx "WINEPREFIX=$COMPAT/pfx" && return 0 done @@ -311,15 +312,25 @@ prepare_prefix # runs the prefix next. Code cached by another FEX build (DroidDeck-Proton's, or a different FEX picked in the # Components tab) made this FEX crash in Steam's install-script step, and Wine then looped on the crash, so Steam never # started the game. The cache is cleared when the FEX that runs the prefix is not the one that filled it. +# The stamp holds this FEX's ID and what the caches held when this tool last finished with the prefix, so a cache that +# another FEX wrote to since (DroidDeck-Proton running the same game) is cleared too. fexid=$(cat "$F/lib/wine/aarch64-windows/libarm64ecfex.dll" "$F/lib/wine/aarch64-windows/libwow64fex.dll" \ "$F/lib/wine/aarch64-unix/libarm64ecfex.so" "$F/lib/wine/aarch64-unix/libwow64fex.so" 2>/dev/null | md5sum | cut -c1-16) -if [ "$(cat "$COMPAT/pfx/.droiddeck-fex-cache" 2>/dev/null)" != "$fexid" ]; then +fex_cache_sum() { # names, sizes and times of the files in the prefix's FEX code caches + for u in "$COMPAT/pfx/drive_c/users"/*; do + [ -L "$u" ] && continue + c=$u/AppData/Local/fex-emu/DiskCache + [ -d "$c" ] && find "$c" -type f -exec stat -c '%n %s %Y' {} + 2>/dev/null + done | sort | md5sum | cut -c1-16 +} +save_fex_stamp() { echo "$fexid $(fex_cache_sum)" > "$COMPAT/pfx/.droiddeck-fex-cache" 2>/dev/null; } +if [ "$(cat "$COMPAT/pfx/.droiddeck-fex-cache" 2>/dev/null)" != "$fexid $(fex_cache_sum)" ]; then for u in "$COMPAT/pfx/drive_c/users"/*; do c=$u/AppData/Local/fex-emu/DiskCache [ -L "$u" ] || [ ! -d "$c" ] && continue - rm -rf "$c" && echo "$(date +%H:%M:%S) FEX code cache of ${u##*/} cleared (filled by another FEX build or unknown)" + rm -rf "$c" && echo "$(date +%H:%M:%S) FEX code cache of ${u##*/} cleared (another FEX build wrote to it, or it is unknown)" done - echo "$fexid" > "$COMPAT/pfx/.droiddeck-fex-cache" + save_fex_stamp fi # Steam's Windows client files in the prefix, the ones Proton copies from Steam's legacycompat folder: a game's @@ -373,12 +384,19 @@ case "$EXE" in [A-Za-z]:[\\/]*) ;; *) cd "$(dirname "$EXE")" || exit 1 ;; esac if [ "$verb" = runinprefix ]; then wine_ "$EXE" "$@" - exit $? + rc=$? + save_fex_stamp + exit $rc fi name=${EXE##*/}; name=${name##*\\} comm=$(echo "$name" | cut -c1-15) -game_pids() { grep -lx "$comm" /proc/[0-9]*/comm 2>/dev/null | cut -d/ -f3; } +game_pids() { # processes of this prefix with the game's name (two prefixes can run programs with the same name) + for p in $(grep -lFx "$comm" /proc/[0-9]*/comm 2>/dev/null); do + p=${p%/comm} + tr '\0' '\n' < "$p/environ" 2>/dev/null | grep -qxF "WINEPREFIX=$COMPAT/pfx" && echo "${p#/proc/}" + done +} # The game's windows go straight to gamescope's X server, as with DroidDeck-Proton (no Wine desktop): the game # sees gamescope's real modes and refresh rate, and gamescope manages its windows. wine_ "$EXE" "$@" & @@ -392,7 +410,7 @@ if [ "${SteamAppId:-0}" != 0 ]; then "$LINKER" "$PACK/bin/gstag" "${XD:-0}" "$SteamAppId" .exe 86400 > "$COMPAT/gstag.log" 2>&1 & GT=$! fi -trap 'echo "$(date +%H:%M:%S) stopped by Steam"; [ -n "$GT" ] && kill $GT 2>/dev/null; stop_wine; exit 0' TERM INT HUP +trap 'echo "$(date +%H:%M:%S) stopped by Steam"; [ -n "$GT" ] && kill $GT 2>/dev/null; stop_wine; save_fex_stamp; exit 0' TERM INT HUP n=0 while [ $n -lt 90 ] && [ -z "$(game_pids)" ]; do # A program that ended before it was seen (Steam's install-script step takes about a second) leaves nothing @@ -402,10 +420,15 @@ while [ $n -lt 90 ] && [ -z "$(game_pids)" ]; do done echo "$(date +%H:%M:%S) game process $(game_pids | tr '\n' ' ')after ${n}s" # The program Steam started counts while it runs: a program that names its main thread (Chromium-based games call -# it CrBrowserMain) changes its process name, which Wine copies, and is then no longer found by name. -while [ -n "$(game_pids)" ] || kill -0 $WP 2>/dev/null; do sleep 2; done +# it CrBrowserMain) changes its process name, which Wine copies, and is then no longer found by name. A launcher +# that started the game and ended leaves the game as another program of this prefix, so the wait goes on while any +# program of the prefix runs, apart from Wine's own services (Proton waits for the prefix's programs the same way). +while [ -n "$(game_pids)" ] || kill -0 $WP 2>/dev/null || programs_left; do sleep 2; done echo "$(date +%H:%M:%S) game exited" [ -n "$GT" ] && kill $GT 2>/dev/null stop_wine wait $WP -echo "$(date +%H:%M:%S) done" +rc=$? +save_fex_stamp +echo "$(date +%H:%M:%S) done (exit $rc)" +exit $rc diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index 31e40fe652..e92d6910c9 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -819,6 +819,8 @@ def read_vdf(text): def run_keys(items, appid=""): + # (hasrunkey, value name, MinimumHasRunValue) of each "run process" entry; Steam runs the process unless the + # value is a DWORD of at least that minimum (1 when the script does not say) appid = next((value for name, value in items if name.lower() == "appid" and isinstance(value, str)), appid) found = set() for name, value in items: @@ -827,30 +829,44 @@ def run_keys(items, appid=""): if any(isinstance(v, str) and re.fullmatch(r"process [0-9]+", n.lower()) for n, v in value): key = next((v for n, v in value if n.lower() == "hasrunkey" and isinstance(v, str)), "HKEY_LOCAL_MACHINE\\Software\\Valve\\Steam\\Apps\\" + appid) - found.add((key.lower(), name.lower())) + minimum = next((v for n, v in value if n.lower() == "minimumhasrunvalue" and isinstance(v, str)), "1") + try: + minimum = int(minimum.strip(), 0) + except ValueError: + minimum = int(minimum.strip()) if minimum.strip().isdigit() else 1 + found.add((key.lower(), name.lower(), minimum)) found |= run_keys(value, appid) return found def registry_values(path): - found, section = set(), None + # {(key, value name): DWORD, or None for a value of another type} + found, section = {}, None with open(path, encoding="utf-8", errors="replace") as reg: for line in reg: if line.startswith("["): section = line[1:line.find("]")].replace("\\\\", "\\").lower() if "]" in line else None elif section and line.startswith('"') and '"=' in line: - found.add((section, line[1:line.index('"=')].replace("\\\\", "\\").lower())) + name = line[1:line.index('"=')].replace("\\\\", "\\").lower() + data = line[line.index('"=') + 2:].strip() + dword = None + if data.lower().startswith("dword:"): + try: + dword = int(data[6:], 16) + except ValueError: + pass + found[(section, name)] = dword return found -def has_run(key, value, values): +def has_run(key, value, values, minimum=1): path = key[len("hkey_local_machine\\"):] if key.startswith("hkey_local_machine\\") else None if path is None: return False views = [path] if path.startswith("software\\"): views.append("software\\wow6432node\\" + path[len("software\\"):]) - return any((view, value) in values for view in views) + return any(isinstance(values.get((view, value)), int) and values[(view, value)] >= minimum for view in views) def scripts_digest(scripts): @@ -896,7 +912,7 @@ def install_scripts_done(scripts, env): values = registry_values(prefix / "system.reg") except (OSError, ValueError): return False - if not keys or not all(has_run(key, value, values) for key, value in keys): + if not keys or not all(has_run(key, value, values, minimum) for key, value, minimum in keys): return False try: if (prefix / INSTALL_STAMP).read_text().strip() == scripts_digest(scripts): diff --git a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility index 210e8f7927..deef7298e9 100755 --- a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility +++ b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility @@ -305,6 +305,8 @@ if [ -f "$here/bionic/launch.sh" ] && [ -z "${DDNATV_ROOT:-}" ]; then echo "droiddeck-proton: DroidDeck-Bionic needs Run without proot; this launch uses ${dd_fallback##*/}" >&2 exec "$dd_fallback/droiddeck-proton-wrap" "$verb" "$@" fi + echo "droiddeck-proton: DroidDeck-Bionic needs Run without proot, and no DroidDeck-Proton is installed to run this launch instead; turn on Run without proot or install DroidDeck-Proton" >&2 + exit 1 fi """ diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index 6a48b46425..eb53f4c1d5 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -1147,9 +1147,12 @@ class GameEnvironmentTest(unittest.TestCase): def test_install_script_run_keys_default_to_the_app_key(self): keys = MODULE["run_keys"](MODULE["read_vdf"](self.SCRIPT)) self.assertEqual(keys, { - ("hkey_local_machine\\software\\valve\\steam\\apps\\commonredist\\vcredist\\2019", "x64 14.28.29334.0"), - ("hkey_local_machine\\software\\valve\\steam\\apps\\228980", "setup"), + ("hkey_local_machine\\software\\valve\\steam\\apps\\commonredist\\vcredist\\2019", "x64 14.28.29334.0", 1), + ("hkey_local_machine\\software\\valve\\steam\\apps\\228980", "setup", 1), }) + with_minimum = self.SCRIPT.replace('"Setup" { "process 1"', '"Setup" { "MinimumHasRunValue" "3" "process 1"') + self.assertIn(("hkey_local_machine\\software\\valve\\steam\\apps\\228980", "setup", 3), + MODULE["run_keys"](MODULE["read_vdf"](with_minimum))) with self.assertRaises(ValueError): MODULE["read_vdf"]('"a" { "b" }') @@ -1197,6 +1200,30 @@ class GameEnvironmentTest(unittest.TestCase): '"registry" { "HKEY_LOCAL_MACHINE\\\\Software\\\\Game" { "string" { "Path" "x" } } } "run process" {')) self.assertFalse(done([str(script)], env)) + def test_install_scripts_need_their_dword_guards_satisfied(self): + with tempfile.TemporaryDirectory() as tmp: + script = Path(tmp) / "evaluatorscript_1.vdf" + script.write_text(self.SCRIPT) + prefix = Path(tmp) / "compat/pfx" + prefix.mkdir(parents=True) + env = {"STEAM_COMPAT_DATA_PATH": str(prefix.parent)} + done = MODULE["install_scripts_done"] + MODULE["record_install_scripts"](MODULE["scripts_digest"]([str(script)]), env) + # a guard DWORD of 0 means Steam still runs the process, recorded or not + (prefix / "system.reg").write_text(self.REDIST + self.SETUP.replace("dword:00000001", "dword:00000000")) + self.assertFalse(done([str(script)], env)) + (prefix / MODULE["INSTALL_STAMP"]).unlink() + self.assertFalse(done([str(script)], env)) + # a value that is not a DWORD does not count either + (prefix / "system.reg").write_text(self.REDIST + self.SETUP.replace("dword:00000001", '"1"')) + self.assertFalse(done([str(script)], env)) + # MinimumHasRunValue: below it the process runs again, at or above it the scripts are done + script.write_text(self.SCRIPT.replace('"Setup" { "process 1"', '"Setup" { "MinimumHasRunValue" "2" "process 1"')) + (prefix / "system.reg").write_text(self.REDIST + self.SETUP) + self.assertFalse(done([str(script)], env)) + (prefix / "system.reg").write_text(self.REDIST + self.SETUP.replace("dword:00000001", "dword:00000002")) + self.assertTrue(done([str(script)], env)) + def test_the_evaluator_is_skipped_once_it_finished_the_same_scripts(self): with tempfile.TemporaryDirectory() as tmp: root = Path(tmp)