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
336f1687
Commit
336f1687
authored
Mar 18, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Be more careful with signals
Fix #4040
parent
d4e2f2df
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
8 deletions
+33
-8
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+33
-8
No files found.
native/jni/magiskhide/proc_monitor.cpp
View file @
336f1687
...
...
@@ -145,13 +145,21 @@ static void inotify_event(int) {
check_zygote
();
}
// Workaround for the lack of pthread_cancel
static
void
term_thread
(
int
)
{
LOGD
(
"proc_monitor: cleaning up
\n
"
);
zygote_map
.
clear
();
attaches
.
reset
();
close
(
inotify_fd
);
inotify_fd
=
-
1
;
// Restore all signal handlers that was set
sigset_t
set
;
sigfillset
(
&
set
);
pthread_sigmask
(
SIG_BLOCK
,
&
set
,
nullptr
);
struct
sigaction
act
{};
act
.
sa_handler
=
SIG_DFL
;
sigaction
(
SIGTERMTHRD
,
&
act
,
nullptr
);
sigaction
(
SIGIO
,
&
act
,
nullptr
);
sigaction
(
SIGALRM
,
&
act
,
nullptr
);
LOGD
(
"proc_monitor: terminate
\n
"
);
pthread_exit
(
nullptr
);
}
...
...
@@ -276,16 +284,29 @@ static void new_zygote(int pid) {
#define DETACH_AND_CONT { detach_pid(pid); continue; }
void
proc_monitor
()
{
// Unblock some signals
sigset_t
block_set
;
sigemptyset
(
&
block_set
);
sigaddset
(
&
block_set
,
SIGTERMTHRD
);
sigaddset
(
&
block_set
,
SIGIO
);
sigaddset
(
&
block_set
,
SIGALRM
);
pthread_sigmask
(
SIG_UNBLOCK
,
&
block_set
,
nullptr
);
monitor_thread
=
pthread_self
();
// Backup original mask
sigset_t
orig_mask
;
pthread_sigmask
(
SIG_SETMASK
,
nullptr
,
&
orig_mask
);
sigset_t
unblock_set
;
sigemptyset
(
&
unblock_set
);
sigaddset
(
&
unblock_set
,
SIGTERMTHRD
);
sigaddset
(
&
unblock_set
,
SIGIO
);
sigaddset
(
&
unblock_set
,
SIGALRM
);
struct
sigaction
act
{};
sigfillset
(
&
act
.
sa_mask
);
act
.
sa_handler
=
SIG_IGN
;
sigaction
(
SIGTERMTHRD
,
&
act
,
nullptr
);
sigaction
(
SIGIO
,
&
act
,
nullptr
);
sigaction
(
SIGALRM
,
&
act
,
nullptr
);
// Temporary unblock to clear pending signals
pthread_sigmask
(
SIG_UNBLOCK
,
&
unblock_set
,
nullptr
);
pthread_sigmask
(
SIG_SETMASK
,
&
orig_mask
,
nullptr
);
act
.
sa_handler
=
term_thread
;
sigaction
(
SIGTERMTHRD
,
&
act
,
nullptr
);
act
.
sa_handler
=
inotify_event
;
...
...
@@ -305,6 +326,8 @@ void proc_monitor() {
}
for
(
int
status
;;)
{
pthread_sigmask
(
SIG_UNBLOCK
,
&
unblock_set
,
nullptr
);
const
int
pid
=
waitpid
(
-
1
,
&
status
,
__WALL
|
__WNOTHREAD
);
if
(
pid
<
0
)
{
if
(
errno
==
ECHILD
)
{
...
...
@@ -319,6 +342,8 @@ void proc_monitor() {
continue
;
}
pthread_sigmask
(
SIG_SETMASK
,
&
orig_mask
,
nullptr
);
if
(
!
WIFSTOPPED
(
status
)
/* Ignore if not ptrace-stop */
)
DETACH_AND_CONT
;
...
...
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