Reorganize MagiskHide code

Prepare for zygote injection hiding
This commit is contained in:
topjohnwu
2021-01-10 17:11:00 -08:00
parent 53c3dd5e8b
commit b36e6d987d
5 changed files with 72 additions and 76 deletions

View File

@@ -121,15 +121,22 @@ int new_daemon_thread(thread_entry entry, void *arg) {
return xpthread_create(&thread, &attr, entry, arg);
}
static void *proxy_routine(void *fp) {
auto fn = reinterpret_cast<std::function<void()>*>(fp);
(*fn)();
delete fn;
return nullptr;
int new_daemon_thread(void(*entry)()) {
thread_entry proxy = [](void *entry) -> void * {
reinterpret_cast<void(*)()>(entry)();
return nullptr;
};
return new_daemon_thread(proxy, (void *) entry);
}
int new_daemon_thread(std::function<void()> &&entry) {
return new_daemon_thread(proxy_routine, new std::function<void()>(std::move(entry)));
thread_entry proxy = [](void *fp) -> void * {
auto fn = reinterpret_cast<std::function<void()>*>(fp);
(*fn)();
delete fn;
return nullptr;
};
return new_daemon_thread(proxy, new std::function<void()>(std::move(entry)));
}
static char *argv0;

View File

@@ -60,6 +60,7 @@ static inline int parse_int(std::string_view s) { return parse_int(s.data()); }
using thread_entry = void *(*)(void *);
int new_daemon_thread(thread_entry entry, void *arg = nullptr);
int new_daemon_thread(void(*entry)());
int new_daemon_thread(std::function<void()> &&entry);
static inline bool str_contains(std::string_view s, std::string_view ss) {