Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
1e45c63e
Commit
1e45c63e
authored
Nov 08, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scan for zygote periodically
Fix #3417
parent
b14a2608
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
11 deletions
+26
-11
hide_utils.cpp
native/jni/magiskhide/hide_utils.cpp
+1
-1
magiskhide.hpp
native/jni/magiskhide/magiskhide.hpp
+0
-1
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+25
-9
No files found.
native/jni/magiskhide/hide_utils.cpp
View file @
1e45c63e
...
@@ -275,7 +275,7 @@ int stop_magiskhide() {
...
@@ -275,7 +275,7 @@ int stop_magiskhide() {
void
auto_start_magiskhide
()
{
void
auto_start_magiskhide
()
{
if
(
hide_enabled
())
{
if
(
hide_enabled
())
{
pthread_kill
(
proc_monitor_thread
,
SIG
ZYGOTE
);
pthread_kill
(
proc_monitor_thread
,
SIG
ALRM
);
hide_late_sensitive_props
();
hide_late_sensitive_props
();
}
else
if
(
SDK_INT
>=
19
)
{
}
else
if
(
SDK_INT
>=
19
)
{
db_settings
dbs
;
db_settings
dbs
;
...
...
native/jni/magiskhide/magiskhide.hpp
View file @
1e45c63e
...
@@ -13,7 +13,6 @@
...
@@ -13,7 +13,6 @@
#include <daemon.hpp>
#include <daemon.hpp>
#define SIGTERMTHRD SIGUSR1
#define SIGTERMTHRD SIGUSR1
#define SIGZYGOTE SIGUSR2
// CLI entries
// CLI entries
int
launch_magiskhide
();
int
launch_magiskhide
();
...
...
native/jni/magiskhide/proc_monitor.cpp
View file @
1e45c63e
...
@@ -107,6 +107,14 @@ void update_uid_map() {
...
@@ -107,6 +107,14 @@ void update_uid_map() {
}
}
}
}
static
bool
is_zygote_done
()
{
#ifdef __LP64__
return
zygote_map
.
size
()
>=
2
;
#else
return
zygote_map
.
size
()
>=
1
;
#endif
}
static
void
check_zygote
()
{
static
void
check_zygote
()
{
crawl_procfs
([](
int
pid
)
->
bool
{
crawl_procfs
([](
int
pid
)
->
bool
{
char
buf
[
512
];
char
buf
[
512
];
...
@@ -119,6 +127,12 @@ static void check_zygote() {
...
@@ -119,6 +127,12 @@ static void check_zygote() {
}
}
return
true
;
return
true
;
});
});
if
(
is_zygote_done
())
{
// Stop periodic scanning
timeval
val
{
.
tv_sec
=
0
,
.
tv_usec
=
0
};
itimerval
interval
{
.
it_interval
=
val
,
.
it_value
=
val
};
setitimer
(
ITIMER_REAL
,
&
interval
,
nullptr
);
}
}
}
#define APP_PROC "/system/bin/app_process"
#define APP_PROC "/system/bin/app_process"
...
@@ -171,10 +185,6 @@ static void inotify_event(int) {
...
@@ -171,10 +185,6 @@ static void inotify_event(int) {
check_zygote
();
check_zygote
();
}
}
static
void
check_zygote
(
int
)
{
check_zygote
();
}
// Workaround for the lack of pthread_cancel
// Workaround for the lack of pthread_cancel
static
void
term_thread
(
int
)
{
static
void
term_thread
(
int
)
{
LOGD
(
"proc_monitor: cleaning up
\n
"
);
LOGD
(
"proc_monitor: cleaning up
\n
"
);
...
@@ -323,6 +333,7 @@ void proc_monitor() {
...
@@ -323,6 +333,7 @@ void proc_monitor() {
sigemptyset
(
&
block_set
);
sigemptyset
(
&
block_set
);
sigaddset
(
&
block_set
,
SIGTERMTHRD
);
sigaddset
(
&
block_set
,
SIGTERMTHRD
);
sigaddset
(
&
block_set
,
SIGIO
);
sigaddset
(
&
block_set
,
SIGIO
);
sigaddset
(
&
block_set
,
SIGALRM
);
pthread_sigmask
(
SIG_UNBLOCK
,
&
block_set
,
nullptr
);
pthread_sigmask
(
SIG_UNBLOCK
,
&
block_set
,
nullptr
);
struct
sigaction
act
{};
struct
sigaction
act
{};
...
@@ -330,13 +341,19 @@ void proc_monitor() {
...
@@ -330,13 +341,19 @@ void proc_monitor() {
sigaction
(
SIGTERMTHRD
,
&
act
,
nullptr
);
sigaction
(
SIGTERMTHRD
,
&
act
,
nullptr
);
act
.
sa_handler
=
inotify_event
;
act
.
sa_handler
=
inotify_event
;
sigaction
(
SIGIO
,
&
act
,
nullptr
);
sigaction
(
SIGIO
,
&
act
,
nullptr
);
act
.
sa_handler
=
check_zygote
;
act
.
sa_handler
=
[](
int
){
check_zygote
();
}
;
sigaction
(
SIG
ZYGOTE
,
&
act
,
nullptr
);
sigaction
(
SIG
ALRM
,
&
act
,
nullptr
);
setup_inotify
();
setup_inotify
();
// First find existing zygotes
// First
try
find existing zygotes
check_zygote
();
check_zygote
();
if
(
!
is_zygote_done
())
{
// Periodic scan every 250ms
timeval
val
{
.
tv_sec
=
0
,
.
tv_usec
=
250000
};
itimerval
interval
{
.
it_interval
=
val
,
.
it_value
=
val
};
setitimer
(
ITIMER_REAL
,
&
interval
,
nullptr
);
}
int
status
;
int
status
;
...
@@ -344,8 +361,7 @@ void proc_monitor() {
...
@@ -344,8 +361,7 @@ void proc_monitor() {
const
int
pid
=
waitpid
(
-
1
,
&
status
,
__WALL
|
__WNOTHREAD
);
const
int
pid
=
waitpid
(
-
1
,
&
status
,
__WALL
|
__WNOTHREAD
);
if
(
pid
<
0
)
{
if
(
pid
<
0
)
{
if
(
errno
==
ECHILD
)
{
if
(
errno
==
ECHILD
)
{
/* This mean we have nothing to wait, sleep
// Nothing to wait yet, sleep and wait till signal interruption
* and wait till signal interruption */
LOGD
(
"proc_monitor: nothing to monitor, wait for signal
\n
"
);
LOGD
(
"proc_monitor: nothing to monitor, wait for signal
\n
"
);
struct
timespec
ts
=
{
struct
timespec
ts
=
{
.
tv_sec
=
INT_MAX
,
.
tv_sec
=
INT_MAX
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment