diff --git a/native/src/core/daemon.cpp b/native/src/core/daemon.cpp index 3472a1b64..6e739995f 100644 --- a/native/src/core/daemon.cpp +++ b/native/src/core/daemon.cpp @@ -433,6 +433,7 @@ static void daemon_entry() { register_poll(&main_socket_pfd, handle_request); // Loop forever to listen for requests + init_thread_pool(); poll_loop(); } diff --git a/native/src/core/include/core.hpp b/native/src/core/include/core.hpp index 429c70640..3051c36c2 100644 --- a/native/src/core/include/core.hpp +++ b/native/src/core/include/core.hpp @@ -52,6 +52,7 @@ void unregister_poll(int fd, bool auto_close); void clear_poll(); // Thread pool +void init_thread_pool(); void exec_task(std::function &&task); // Daemon handlers diff --git a/native/src/core/thread.cpp b/native/src/core/thread.cpp index d9a2e0c37..fff315839 100644 --- a/native/src/core/thread.cpp +++ b/native/src/core/thread.cpp @@ -42,8 +42,6 @@ static void reset_pool() { } static void *thread_pool_loop(void * const is_core_pool) { - pthread_atfork(nullptr, nullptr, &reset_pool); - // Block all signals sigset_t mask; sigfillset(&mask); @@ -83,6 +81,10 @@ static void *thread_pool_loop(void * const is_core_pool) { } } +void init_thread_pool() { + pthread_atfork(nullptr, nullptr, &reset_pool); +} + void exec_task(function &&task) { mutex_guard g(lock); pending_task.swap(task); diff --git a/native/src/core/zygisk/main.cpp b/native/src/core/zygisk/main.cpp index 85e70d768..f66a857f7 100644 --- a/native/src/core/zygisk/main.cpp +++ b/native/src/core/zygisk/main.cpp @@ -15,6 +15,8 @@ static void zygiskd(int socket) { if (getuid() != 0 || fcntl(socket, F_GETFD) < 0) exit(-1); + init_thread_pool(); + #if defined(__LP64__) set_nice_name("zygiskd64"); LOGI("* Launching zygiskd64\n");