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
82c7662c
Commit
82c7662c
authored
Sep 20, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache Magisk app ID for performance
parent
4f0bced5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
1 deletion
+33
-1
deny.hpp
native/jni/zygisk/deny/deny.hpp
+1
-0
utils.cpp
native/jni/zygisk/deny/utils.cpp
+1
-0
entry.cpp
native/jni/zygisk/entry.cpp
+31
-1
No files found.
native/jni/zygisk/deny/deny.hpp
View file @
82c7662c
...
...
@@ -25,6 +25,7 @@ void revert_daemon(int pid, int client);
void
revert_unmount
(
int
pid
=
-
1
);
extern
std
::
atomic
<
bool
>
denylist_enabled
;
extern
int
cached_manager_app_id
;
enum
:
int
{
ENFORCE_DENY
,
...
...
native/jni/zygisk/deny/utils.cpp
View file @
82c7662c
...
...
@@ -276,6 +276,7 @@ static void inotify_handler(pollfd *pfd) {
}
u
{};
read
(
pfd
->
fd
,
u
.
buf
,
sizeof
(
u
.
buf
));
if
(
u
.
event
.
name
==
"packages.xml"
sv
)
{
cached_manager_app_id
=
-
1
;
exec_task
([]
{
mutex_guard
lock
(
data_lock
);
rebuild_map
();
...
...
native/jni/zygisk/entry.cpp
View file @
82c7662c
...
...
@@ -251,11 +251,41 @@ static void setup_files(int client, ucred *cred) {
write_string
(
client
,
path
);
}
int
cached_manager_app_id
=
-
1
;
static
time_t
last_modified
=
0
;
static
void
get_app_info
(
int
client
)
{
AppInfo
info
{};
int
uid
=
read_int
(
client
);
string
process
=
read_string
(
client
);
if
(
to_app_id
(
uid
)
==
get_manager_app_id
())
{
// This function is called on every single zygote app process specialization,
// so performance is critical. get_manager_app_id() is expensive as it goes
// through a SQLite query and potentially multiple filesystem stats, so we
// really want to cache the app ID value. Check the last modify timestamp of
// packages.xml and only re-fetch the manager app ID if something changed since
// we last checked. Granularity in seconds is good enough.
// If denylist is enabled, inotify will invalidate the app ID cache for us.
// In this case, we can skip the timestamp check all together.
int
manager_app_id
=
cached_manager_app_id
;
// Denylist not enabled, check packages.xml timestamp
if
(
!
denylist_enabled
&&
manager_app_id
>
0
)
{
struct
stat
st
{};
stat
(
"/data/system/packages.xml"
,
&
st
);
if
(
st
.
st_atim
.
tv_sec
>
last_modified
)
{
manager_app_id
=
-
1
;
last_modified
=
st
.
st_atim
.
tv_sec
;
}
}
if
(
manager_app_id
<
0
)
{
manager_app_id
=
get_manager_app_id
();
cached_manager_app_id
=
manager_app_id
;
}
if
(
to_app_id
(
uid
)
==
manager_app_id
)
{
info
.
is_magisk_app
=
true
;
}
else
if
(
denylist_enabled
)
{
info
.
on_denylist
=
is_deny_target
(
uid
,
process
);
...
...
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