From 0f27e455e7aa27cf5152bfa4ff54c6dbe73f7031 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Sun, 24 Aug 2025 14:12:23 -0300 Subject: [PATCH] improve: preload modules globally This commit makes Zygisk modules be preloaded globally in the main Zygote process, so that they don't need to reload all the time. This commit is authored by @nampud, and merged into mainline ReZygisk. Co-authored-by: nampud --- loader/src/injector/hook.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/loader/src/injector/hook.cpp b/loader/src/injector/hook.cpp index c00d832..b29ce23 100644 --- a/loader/src/injector/hook.cpp +++ b/loader/src/injector/hook.cpp @@ -66,7 +66,6 @@ struct ZygiskContext { } args; const char *process; - list modules; int pid; bitset flags; @@ -124,6 +123,10 @@ struct ZygiskContext { // Global variables vector> *plt_hook_list; map> *jni_hook_list; + +bool modules_loaded = false; +list modules; + bool should_unmap_zygisk = false; bool enable_unloader = false; bool hooked_unloader = false; @@ -824,15 +827,6 @@ void ZygiskContext::app_specialize_pre() { setenv("ZYGISK_ENABLED", "1", 1); } - /* INFO: Because we load directly from the file, we need to do it before we umount - the mounts, or else it won't have access to /data/adb anymore. - */ - if (!load_modules_only()) { - LOGE("Failed to load modules"); - - return; - } - /* INFO: Modules only have two "start off" points from Zygisk, preSpecialize and postSpecialize. In preSpecialize, the process still has privileged permissions, and therefore can execute mount/umount/setns functions. @@ -908,11 +902,15 @@ void ZygiskContext::nativeForkSystemServer_pre() { LOGV("pre forkSystemServer"); flags[SERVER_FORK_AND_SPECIALIZE] = true; + if (!modules_loaded) { + load_modules_only(); + modules_loaded = true; + } + fork_pre(); if (!is_child()) return; - load_modules_only(); run_modules_pre(); rezygiskd_system_server_started();