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
This commit is contained in:
ThePedroo
2025-08-24 14:12:23 -03:00
parent 3688df6450
commit 0f27e455e7

View File

@@ -66,7 +66,6 @@ struct ZygiskContext {
} args; } args;
const char *process; const char *process;
list<ZygiskModule> modules;
int pid; int pid;
bitset<FLAG_MAX> flags; bitset<FLAG_MAX> flags;
@@ -124,6 +123,10 @@ struct ZygiskContext {
// Global variables // Global variables
vector<tuple<dev_t, ino_t, const char *, void **>> *plt_hook_list; vector<tuple<dev_t, ino_t, const char *, void **>> *plt_hook_list;
map<string, vector<JNINativeMethod>> *jni_hook_list; map<string, vector<JNINativeMethod>> *jni_hook_list;
bool modules_loaded = false;
list<ZygiskModule> modules;
bool should_unmap_zygisk = false; bool should_unmap_zygisk = false;
bool enable_unloader = false; bool enable_unloader = false;
bool hooked_unloader = false; bool hooked_unloader = false;
@@ -824,15 +827,6 @@ void ZygiskContext::app_specialize_pre() {
setenv("ZYGISK_ENABLED", "1", 1); 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 /* INFO: Modules only have two "start off" points from Zygisk, preSpecialize and
postSpecialize. In preSpecialize, the process still has privileged postSpecialize. In preSpecialize, the process still has privileged
permissions, and therefore can execute mount/umount/setns functions. permissions, and therefore can execute mount/umount/setns functions.
@@ -908,11 +902,15 @@ void ZygiskContext::nativeForkSystemServer_pre() {
LOGV("pre forkSystemServer"); LOGV("pre forkSystemServer");
flags[SERVER_FORK_AND_SPECIALIZE] = true; flags[SERVER_FORK_AND_SPECIALIZE] = true;
if (!modules_loaded) {
load_modules_only();
modules_loaded = true;
}
fork_pre(); fork_pre();
if (!is_child()) if (!is_child())
return; return;
load_modules_only();
run_modules_pre(); run_modules_pre();
rezygiskd_system_server_started(); rezygiskd_system_server_started();