Make zygote notifier more reliable

This commit is contained in:
topjohnwu
2019-03-06 18:22:04 -05:00
parent 6226f875ff
commit 82c864d57e
6 changed files with 31 additions and 25 deletions

View File

@ -241,6 +241,32 @@ static void term_thread(int) {
//#define PTRACE_LOG(fmt, args...) LOGD("PID=[%d] " fmt, pid, ##args)
#define PTRACE_LOG(...)
int next_zygote = -1;
void zygote_notify(int client, struct ucred *cred) {
char *path = read_string(client);
xptrace(PTRACE_ATTACH, cred->pid);
// Wait for attach
waitpid(cred->pid, nullptr, __WALL | __WNOTHREAD);
xptrace(PTRACE_CONT, cred->pid);
write_int(client, 0);
close(client);
// Wait for exec
waitpid(cred->pid, nullptr, __WALL | __WNOTHREAD);
xptrace(PTRACE_DETACH, cred->pid);
if (hide_enabled) {
MutexGuard lock(monitor_lock);
next_zygote = cred->pid;
pthread_kill(proc_monitor_thread, SIGZYGOTE);
}
// Remount zygote notifier ASAP
xmount(MAGISKTMP "/app_process", path, nullptr, MS_BIND, nullptr);
free(path);
}
static bool check_pid(int pid) {
char path[128];
char cmdline[1024];