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
20f20481
Commit
20f20481
authored
Mar 10, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use RAII to detach PIDs
parent
4581354e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
9 deletions
+15
-9
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+15
-9
No files found.
native/jni/magiskhide/proc_monitor.cpp
View file @
20f20481
...
@@ -349,6 +349,7 @@ static void new_zygote(int pid) {
...
@@ -349,6 +349,7 @@ static void new_zygote(int pid) {
xptrace
(
PTRACE_CONT
,
pid
);
xptrace
(
PTRACE_CONT
,
pid
);
}
}
#define DETACH_AND_CONT { detach = true; continue; }
void
proc_monitor
()
{
void
proc_monitor
()
{
inotify_fd
=
xinotify_init1
(
IN_CLOEXEC
);
inotify_fd
=
xinotify_init1
(
IN_CLOEXEC
);
if
(
inotify_fd
<
0
)
if
(
inotify_fd
<
0
)
...
@@ -384,15 +385,23 @@ void proc_monitor() {
...
@@ -384,15 +385,23 @@ void proc_monitor() {
int
status
;
int
status
;
for
(;;)
{
for
(;;)
{
int
pid
=
waitpid
(
-
1
,
&
status
,
__WALL
|
__WNOTHREAD
);
const
int
pid
=
waitpid
(
-
1
,
&
status
,
__WALL
|
__WNOTHREAD
);
if
(
pid
<
0
)
if
(
pid
<
0
)
continue
;
continue
;
bool
detach
=
false
;
RunFinally
detach_task
([
&
]()
->
void
{
if
(
detach
)
{
// Non of our business now
attaches
[
pid
]
=
false
;
detaches
[
pid
]
=
false
;
unknowns
[
pid
]
=
false
;
xptrace
(
PTRACE_DETACH
,
pid
);
}
});
if
(
WIFSTOPPED
(
status
))
{
if
(
WIFSTOPPED
(
status
))
{
if
(
detaches
[
pid
])
{
if
(
detaches
[
pid
])
{
PTRACE_LOG
(
"detach
\n
"
);
PTRACE_LOG
(
"detach
\n
"
);
detaches
[
pid
]
=
false
;
DETACH_AND_CONT
;
xptrace
(
PTRACE_DETACH
,
pid
);
continue
;
}
}
if
(
WSTOPSIG
(
status
)
==
SIGTRAP
&&
WEVENT
(
status
))
{
if
(
WSTOPSIG
(
status
)
==
SIGTRAP
&&
WEVENT
(
status
))
{
unsigned
long
msg
;
unsigned
long
msg
;
...
@@ -427,10 +436,7 @@ void proc_monitor() {
...
@@ -427,10 +436,7 @@ void proc_monitor() {
case
PTRACE_EVENT_EXEC
:
case
PTRACE_EVENT_EXEC
:
case
PTRACE_EVENT_EXIT
:
case
PTRACE_EVENT_EXIT
:
PTRACE_LOG
(
"exited or execve
\n
"
,
msg
);
PTRACE_LOG
(
"exited or execve
\n
"
,
msg
);
attaches
[
pid
]
=
false
;
DETACH_AND_CONT
;
unknowns
[
pid
]
=
false
;
xptrace
(
PTRACE_DETACH
,
pid
);
continue
;
default:
default:
PTRACE_LOG
(
"unknown event: %d
\n
"
,
WEVENT
(
status
));
PTRACE_LOG
(
"unknown event: %d
\n
"
,
WEVENT
(
status
));
break
;
break
;
...
@@ -454,8 +460,8 @@ void proc_monitor() {
...
@@ -454,8 +460,8 @@ void proc_monitor() {
}
}
}
else
{
}
else
{
// Nothing to do with us
// Nothing to do with us
ptrace
(
PTRACE_DETACH
,
pid
);
PTRACE_LOG
(
"terminate
\n
"
);
PTRACE_LOG
(
"terminate
\n
"
);
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