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
4bb8ad19
Commit
4bb8ad19
authored
Dec 06, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small init refactoring
parent
3e275b7d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
34 deletions
+35
-34
Android.mk
native/jni/Android.mk
+1
-1
getinfo.cpp
native/jni/init/getinfo.cpp
+3
-3
init.cpp
native/jni/init/init.cpp
+30
-29
init.h
native/jni/init/init.h
+1
-1
mount.cpp
native/jni/init/mount.cpp
+0
-0
No files found.
native/jni/Android.mk
View file @
4bb8ad19
...
@@ -106,7 +106,7 @@ LOCAL_C_INCLUDES := \
...
@@ -106,7 +106,7 @@ LOCAL_C_INCLUDES := \
LOCAL_SRC_FILES := \
LOCAL_SRC_FILES := \
init/init.cpp \
init/init.cpp \
init/
early_
mount.cpp \
init/mount.cpp \
init/rootdir.cpp \
init/rootdir.cpp \
init/getinfo.cpp \
init/getinfo.cpp \
magiskpolicy/api.cpp \
magiskpolicy/api.cpp \
...
...
native/jni/init/getinfo.cpp
View file @
4bb8ad19
...
@@ -112,7 +112,7 @@ void load_kernel_info(cmdline *cmd) {
...
@@ -112,7 +112,7 @@ void load_kernel_info(cmdline *cmd) {
cmd
->
slot
[
0
]
=
'_'
;
cmd
->
slot
[
0
]
=
'_'
;
strcpy
(
cmd
->
slot
+
1
,
value
);
strcpy
(
cmd
->
slot
+
1
,
value
);
}
else
if
(
key
==
"skip_initramfs"
)
{
}
else
if
(
key
==
"skip_initramfs"
)
{
cmd
->
s
ystem_as_root
=
true
;
cmd
->
s
kip_initramfs
=
true
;
}
else
if
(
key
==
"androidboot.force_normal_boot"
)
{
}
else
if
(
key
==
"androidboot.force_normal_boot"
)
{
cmd
->
force_normal_boot
=
value
[
0
]
==
'1'
;
cmd
->
force_normal_boot
=
value
[
0
]
==
'1'
;
}
else
if
(
key
==
"androidboot.android_dt_dir"
)
{
}
else
if
(
key
==
"androidboot.android_dt_dir"
)
{
...
@@ -143,13 +143,13 @@ void load_kernel_info(cmdline *cmd) {
...
@@ -143,13 +143,13 @@ void load_kernel_info(cmdline *cmd) {
if
(
recovery_mode
)
{
if
(
recovery_mode
)
{
LOGD
(
"Running in recovery mode, waiting for key...
\n
"
);
LOGD
(
"Running in recovery mode, waiting for key...
\n
"
);
cmd
->
s
ystem_as_root
=
!
check_key_combo
();
cmd
->
s
kip_initramfs
=
!
check_key_combo
();
}
}
if
(
cmd
->
dt_dir
[
0
]
==
'\0'
)
if
(
cmd
->
dt_dir
[
0
]
==
'\0'
)
strcpy
(
cmd
->
dt_dir
,
DEFAULT_DT_DIR
);
strcpy
(
cmd
->
dt_dir
,
DEFAULT_DT_DIR
);
LOGD
(
"s
ystem_as_root=[%d]
\n
"
,
cmd
->
system_as_root
);
LOGD
(
"s
kip_initramfs=[%d]
\n
"
,
cmd
->
skip_initramfs
);
LOGD
(
"force_normal_boot=[%d]
\n
"
,
cmd
->
force_normal_boot
);
LOGD
(
"force_normal_boot=[%d]
\n
"
,
cmd
->
force_normal_boot
);
LOGD
(
"slot=[%s]
\n
"
,
cmd
->
slot
);
LOGD
(
"slot=[%s]
\n
"
,
cmd
->
slot
);
LOGD
(
"dt_dir=[%s]
\n
"
,
cmd
->
dt_dir
);
LOGD
(
"dt_dir=[%s]
\n
"
,
cmd
->
dt_dir
);
...
...
native/jni/init/init.cpp
View file @
4bb8ad19
...
@@ -75,12 +75,12 @@ static bool unxz(int fd, const uint8_t *buf, size_t size) {
...
@@ -75,12 +75,12 @@ static bool unxz(int fd, const uint8_t *buf, size_t size) {
xz_crc32_init
();
xz_crc32_init
();
struct
xz_dec
*
dec
=
xz_dec_init
(
XZ_DYNALLOC
,
1
<<
26
);
struct
xz_dec
*
dec
=
xz_dec_init
(
XZ_DYNALLOC
,
1
<<
26
);
struct
xz_buf
b
=
{
struct
xz_buf
b
=
{
.
in
=
buf
,
.
in
=
buf
,
.
in_pos
=
0
,
.
in_pos
=
0
,
.
in_size
=
size
,
.
in_size
=
size
,
.
out
=
out
,
.
out
=
out
,
.
out_pos
=
0
,
.
out_pos
=
0
,
.
out_size
=
sizeof
(
out
)
.
out_size
=
sizeof
(
out
)
};
};
enum
xz_ret
ret
;
enum
xz_ret
ret
;
do
{
do
{
...
@@ -147,11 +147,11 @@ class TestInit : public BaseInit {
...
@@ -147,11 +147,11 @@ class TestInit : public BaseInit {
public
:
public
:
TestInit
(
char
*
argv
[],
cmdline
*
cmd
)
:
BaseInit
(
argv
,
cmd
)
{};
TestInit
(
char
*
argv
[],
cmdline
*
cmd
)
:
BaseInit
(
argv
,
cmd
)
{};
void
start
()
override
{
void
start
()
override
{
//
Writ
e init tests here
//
Plac
e init tests here
}
}
};
};
static
void
setup_test
(
const
char
*
dir
)
{
[[
maybe_unused
]]
static
int
test_main
(
int
argc
,
char
*
argv
[]
)
{
// Log to console
// Log to console
cmdline_logging
();
cmdline_logging
();
log_cb
.
ex
=
nop_ex
;
log_cb
.
ex
=
nop_ex
;
...
@@ -167,13 +167,21 @@ static void setup_test(const char *dir) {
...
@@ -167,13 +167,21 @@ static void setup_test(const char *dir) {
mounts
.
emplace_back
(
me
->
mnt_dir
);
mounts
.
emplace_back
(
me
->
mnt_dir
);
return
true
;
return
true
;
});
});
for
(
auto
m
=
mounts
.
rbegin
();
m
!=
mounts
.
rend
();
++
m
)
for
(
auto
&
m
:
reversed
(
mounts
)
)
xumount
(
m
->
data
());
xumount
(
m
.
data
());
// chroot jail
// chroot jail
chdir
(
dir
);
chdir
(
dir
name
(
argv
[
0
])
);
chroot
(
"."
);
chroot
(
"."
);
chdir
(
"/"
);
chdir
(
"/"
);
cmdline
cmd
{};
load_kernel_info
(
&
cmd
);
auto
init
=
make_unique
<
TestInit
>
(
argv
,
&
cmd
);
init
->
start
();
return
1
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
...
@@ -184,6 +192,11 @@ int main(int argc, char *argv[]) {
...
@@ -184,6 +192,11 @@ int main(int argc, char *argv[]) {
return
(
*
init_applet_main
[
i
])(
argc
,
argv
);
return
(
*
init_applet_main
[
i
])(
argc
,
argv
);
}
}
#ifdef MAGISK_DEBUG
if
(
getenv
(
"INIT_TEST"
)
!=
nullptr
)
return
test_main
(
argc
,
argv
);
#endif
if
(
argc
>
1
&&
strcmp
(
argv
[
1
],
"-x"
)
==
0
)
{
if
(
argc
>
1
&&
strcmp
(
argv
[
1
],
"-x"
)
==
0
)
{
if
(
strcmp
(
argv
[
2
],
"magisk"
)
==
0
)
if
(
strcmp
(
argv
[
2
],
"magisk"
)
==
0
)
return
dump_magisk
(
argv
[
3
],
0755
);
return
dump_magisk
(
argv
[
3
],
0755
);
...
@@ -191,34 +204,22 @@ int main(int argc, char *argv[]) {
...
@@ -191,34 +204,22 @@ int main(int argc, char *argv[]) {
return
dump_manager
(
argv
[
3
],
0644
);
return
dump_manager
(
argv
[
3
],
0644
);
}
}
if
(
getpid
()
!=
1
)
return
1
;
setup_klog
();
if
(
argc
>
1
&&
argv
[
1
]
==
"selinux_setup"
sv
)
{
if
(
argc
>
1
&&
argv
[
1
]
==
"selinux_setup"
sv
)
{
auto
init
=
make_unique
<
SecondStageInit
>
(
argv
);
auto
init
=
make_unique
<
SecondStageInit
>
(
argv
);
init
->
start
();
init
->
start
();
}
}
#ifdef MAGISK_DEBUG
bool
run_test
=
getenv
(
"INIT_TEST"
)
!=
nullptr
;
#else
constexpr
bool
run_test
=
false
;
#endif
if
(
run_test
)
{
setup_test
(
dirname
(
argv
[
0
]));
}
else
{
if
(
getpid
()
!=
1
)
return
1
;
setup_klog
();
}
cmdline
cmd
{};
cmdline
cmd
{};
load_kernel_info
(
&
cmd
);
load_kernel_info
(
&
cmd
);
unique_ptr
<
BaseInit
>
init
;
unique_ptr
<
BaseInit
>
init
;
if
(
run_test
)
{
if
(
cmd
.
force_normal_boot
)
{
init
=
make_unique
<
TestInit
>
(
argv
,
&
cmd
);
}
else
if
(
cmd
.
force_normal_boot
)
{
init
=
make_unique
<
ABFirstStageInit
>
(
argv
,
&
cmd
);
init
=
make_unique
<
ABFirstStageInit
>
(
argv
,
&
cmd
);
}
else
if
(
cmd
.
s
ystem_as_root
)
{
}
else
if
(
cmd
.
s
kip_initramfs
)
{
if
(
access
(
"/overlay"
,
F_OK
)
==
0
)
/* Compatible mode */
if
(
access
(
"/overlay"
,
F_OK
)
==
0
)
/* Compatible mode */
init
=
make_unique
<
SARCompatInit
>
(
argv
,
&
cmd
);
init
=
make_unique
<
SARCompatInit
>
(
argv
,
&
cmd
);
else
else
...
...
native/jni/init/init.h
View file @
4bb8ad19
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#include <vector>
#include <vector>
struct
cmdline
{
struct
cmdline
{
bool
s
ystem_as_root
;
bool
s
kip_initramfs
;
bool
force_normal_boot
;
bool
force_normal_boot
;
char
slot
[
3
];
char
slot
[
3
];
char
dt_dir
[
128
];
char
dt_dir
[
128
];
...
...
native/jni/init/
early_
mount.cpp
→
native/jni/init/mount.cpp
View file @
4bb8ad19
File moved
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