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
f1d9015e
Commit
f1d9015e
authored
Jun 16, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move load kernel info out of class
parent
e8d900c5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
29 deletions
+31
-29
early_mount.cpp
native/jni/init/early_mount.cpp
+5
-5
getinfo.cpp
native/jni/init/getinfo.cpp
+12
-12
init.cpp
native/jni/init/init.cpp
+10
-8
init.h
native/jni/init/init.h
+3
-3
rootfs.cpp
native/jni/init/rootfs.cpp
+1
-1
No files found.
native/jni/init/early_mount.cpp
View file @
f1d9015e
...
@@ -76,14 +76,14 @@ static void setup_block(const char *partname, char *block_dev) {
...
@@ -76,14 +76,14 @@ static void setup_block(const char *partname, char *block_dev) {
bool
MagiskInit
::
read_dt_fstab
(
const
char
*
name
,
char
*
partname
,
char
*
fstype
)
{
bool
MagiskInit
::
read_dt_fstab
(
const
char
*
name
,
char
*
partname
,
char
*
fstype
)
{
char
path
[
128
];
char
path
[
128
];
int
fd
;
int
fd
;
sprintf
(
path
,
"%s/fstab/%s/dev"
,
cmd
.
dt_dir
,
name
);
sprintf
(
path
,
"%s/fstab/%s/dev"
,
cmd
->
dt_dir
,
name
);
if
((
fd
=
xopen
(
path
,
O_RDONLY
|
O_CLOEXEC
))
>=
0
)
{
if
((
fd
=
xopen
(
path
,
O_RDONLY
|
O_CLOEXEC
))
>=
0
)
{
read
(
fd
,
path
,
sizeof
(
path
));
read
(
fd
,
path
,
sizeof
(
path
));
close
(
fd
);
close
(
fd
);
// Some custom treble use different names, so use what we read
// Some custom treble use different names, so use what we read
char
*
part
=
rtrim
(
strrchr
(
path
,
'/'
)
+
1
);
char
*
part
=
rtrim
(
strrchr
(
path
,
'/'
)
+
1
);
sprintf
(
partname
,
"%s%s"
,
part
,
strend
(
part
,
cmd
.
slot
)
?
cmd
.
slot
:
""
);
sprintf
(
partname
,
"%s%s"
,
part
,
strend
(
part
,
cmd
->
slot
)
?
cmd
->
slot
:
""
);
sprintf
(
path
,
"%s/fstab/%s/type"
,
cmd
.
dt_dir
,
name
);
sprintf
(
path
,
"%s/fstab/%s/type"
,
cmd
->
dt_dir
,
name
);
if
((
fd
=
xopen
(
path
,
O_RDONLY
|
O_CLOEXEC
))
>=
0
)
{
if
((
fd
=
xopen
(
path
,
O_RDONLY
|
O_CLOEXEC
))
>=
0
)
{
read
(
fd
,
fstype
,
32
);
read
(
fd
,
fstype
,
32
);
close
(
fd
);
close
(
fd
);
...
@@ -111,9 +111,9 @@ void MagiskInit::early_mount() {
...
@@ -111,9 +111,9 @@ void MagiskInit::early_mount() {
char
fstype
[
32
];
char
fstype
[
32
];
char
block_dev
[
64
];
char
block_dev
[
64
];
if
(
cmd
.
system_as_root
)
{
if
(
cmd
->
system_as_root
)
{
LOGD
(
"Early mount system_root
\n
"
);
LOGD
(
"Early mount system_root
\n
"
);
sprintf
(
partname
,
"system%s"
,
cmd
.
slot
);
sprintf
(
partname
,
"system%s"
,
cmd
->
slot
);
setup_block
(
partname
,
block_dev
);
setup_block
(
partname
,
block_dev
);
xmkdir
(
"/system_root"
,
0755
);
xmkdir
(
"/system_root"
,
0755
);
if
(
xmount
(
block_dev
,
"/system_root"
,
"ext4"
,
MS_RDONLY
,
nullptr
))
if
(
xmount
(
block_dev
,
"/system_root"
,
"ext4"
,
MS_RDONLY
,
nullptr
))
...
...
native/jni/init/getinfo.cpp
View file @
f1d9015e
...
@@ -92,7 +92,7 @@ static bool check_key_combo() {
...
@@ -92,7 +92,7 @@ static bool check_key_combo() {
return
false
;
return
false
;
}
}
void
MagiskInit
::
load_kernel_info
(
)
{
void
load_kernel_info
(
cmdline
*
cmd
)
{
// Communicate with kernel using procfs and sysfs
// Communicate with kernel using procfs and sysfs
xmkdir
(
"/proc"
,
0755
);
xmkdir
(
"/proc"
,
0755
);
xmount
(
"proc"
,
"/proc"
,
"proc"
,
0
,
nullptr
);
xmount
(
"proc"
,
"/proc"
,
"proc"
,
0
,
nullptr
);
...
@@ -106,14 +106,14 @@ void MagiskInit::load_kernel_info() {
...
@@ -106,14 +106,14 @@ void MagiskInit::load_kernel_info() {
parse_cmdline
([
&
](
auto
key
,
auto
value
)
->
void
{
parse_cmdline
([
&
](
auto
key
,
auto
value
)
->
void
{
LOGD
(
"cmdline: [%s]=[%s]
\n
"
,
key
.
data
(),
value
);
LOGD
(
"cmdline: [%s]=[%s]
\n
"
,
key
.
data
(),
value
);
if
(
key
==
"androidboot.slot_suffix"
)
{
if
(
key
==
"androidboot.slot_suffix"
)
{
strcpy
(
cmd
.
slot
,
value
);
strcpy
(
cmd
->
slot
,
value
);
}
else
if
(
key
==
"androidboot.slot"
)
{
}
else
if
(
key
==
"androidboot.slot"
)
{
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
.
system_as_root
=
true
;
cmd
->
system_as_root
=
true
;
}
else
if
(
key
==
"androidboot.android_dt_dir"
)
{
}
else
if
(
key
==
"androidboot.android_dt_dir"
)
{
strcpy
(
cmd
.
dt_dir
,
value
);
strcpy
(
cmd
->
dt_dir
,
value
);
}
else
if
(
key
==
"enter_recovery"
)
{
}
else
if
(
key
==
"enter_recovery"
)
{
enter_recovery
=
value
[
0
]
==
'1'
;
enter_recovery
=
value
[
0
]
==
'1'
;
}
else
if
(
key
==
"androidboot.hardware"
)
{
}
else
if
(
key
==
"androidboot.hardware"
)
{
...
@@ -140,13 +140,13 @@ void MagiskInit::load_kernel_info() {
...
@@ -140,13 +140,13 @@ void MagiskInit::load_kernel_info() {
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
.
system_as_root
=
!
check_key_combo
();
cmd
->
system_as_root
=
!
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
(
"system_as_root=[%d]
\n
"
,
cmd
.
system_as_root
);
LOGD
(
"system_as_root=[%d]
\n
"
,
cmd
->
system_as_root
);
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 @
f1d9015e
...
@@ -120,7 +120,7 @@ static int dump_manager(const char *path, mode_t mode) {
...
@@ -120,7 +120,7 @@ static int dump_manager(const char *path, mode_t mode) {
void
MagiskInit
::
preset
()
{
void
MagiskInit
::
preset
()
{
root
=
open
(
"/"
,
O_RDONLY
|
O_CLOEXEC
);
root
=
open
(
"/"
,
O_RDONLY
|
O_CLOEXEC
);
if
(
cmd
.
system_as_root
)
{
if
(
cmd
->
system_as_root
)
{
// Clear rootfs
// Clear rootfs
LOGD
(
"Cleaning rootfs
\n
"
);
LOGD
(
"Cleaning rootfs
\n
"
);
frm_rf
(
root
,
{
"overlay"
,
"proc"
,
"sys"
});
frm_rf
(
root
,
{
"overlay"
,
"proc"
,
"sys"
});
...
@@ -171,10 +171,6 @@ void MagiskInit::start() {
...
@@ -171,10 +171,6 @@ void MagiskInit::start() {
if
(
null
>
STDERR_FILENO
)
if
(
null
>
STDERR_FILENO
)
close
(
null
);
close
(
null
);
setup_klog
();
load_kernel_info
();
full_read
(
"/init"
,
&
self
.
buf
,
&
self
.
sz
);
full_read
(
"/init"
,
&
self
.
buf
,
&
self
.
sz
);
full_read
(
"/.backup/.magisk"
,
&
config
.
buf
,
&
config
.
sz
);
full_read
(
"/.backup/.magisk"
,
&
config
.
buf
,
&
config
.
sz
);
...
@@ -192,7 +188,6 @@ void MagiskInit::test() {
...
@@ -192,7 +188,6 @@ void MagiskInit::test() {
chroot
(
"."
);
chroot
(
"."
);
chdir
(
"/"
);
chdir
(
"/"
);
load_kernel_info
();
preset
();
preset
();
early_mount
();
early_mount
();
setup_rootfs
();
setup_rootfs
();
...
@@ -200,7 +195,9 @@ void MagiskInit::test() {
...
@@ -200,7 +195,9 @@ void MagiskInit::test() {
}
}
static
int
test_main
(
int
,
char
*
argv
[])
{
static
int
test_main
(
int
,
char
*
argv
[])
{
MagiskInit
init
(
argv
);
cmdline
cmd
{};
load_kernel_info
(
&
cmd
);
MagiskInit
init
(
argv
,
&
cmd
);
init
.
test
();
init
.
test
();
return
0
;
return
0
;
}
}
...
@@ -223,7 +220,12 @@ int main(int argc, char *argv[]) {
...
@@ -223,7 +220,12 @@ int main(int argc, char *argv[]) {
if
(
getpid
()
!=
1
)
if
(
getpid
()
!=
1
)
return
1
;
return
1
;
MagiskInit
init
(
argv
);
setup_klog
();
cmdline
cmd
{};
load_kernel_info
(
&
cmd
);
MagiskInit
init
(
argv
,
&
cmd
);
// Run the main routine
// Run the main routine
init
.
start
();
init
.
start
();
...
...
native/jni/init/init.h
View file @
f1d9015e
...
@@ -13,7 +13,7 @@ struct raw_data {
...
@@ -13,7 +13,7 @@ struct raw_data {
class
MagiskInit
{
class
MagiskInit
{
private
:
private
:
cmdline
cmd
{}
;
cmdline
*
cmd
;
raw_data
self
{};
raw_data
self
{};
raw_data
config
{};
raw_data
config
{};
int
root
=
-
1
;
int
root
=
-
1
;
...
@@ -24,7 +24,6 @@ private:
...
@@ -24,7 +24,6 @@ private:
bool
mnt_product
=
false
;
bool
mnt_product
=
false
;
bool
mnt_odm
=
false
;
bool
mnt_odm
=
false
;
void
load_kernel_info
();
void
preset
();
void
preset
();
void
early_mount
();
void
early_mount
();
void
setup_rootfs
();
void
setup_rootfs
();
...
@@ -34,7 +33,7 @@ private:
...
@@ -34,7 +33,7 @@ private:
void
re_exec_init
();
void
re_exec_init
();
public
:
public
:
explicit
MagiskInit
(
char
*
argv
[]
)
:
argv
(
argv
)
{}
explicit
MagiskInit
(
char
*
argv
[]
,
cmdline
*
cmd
)
:
cmd
(
cmd
),
argv
(
argv
)
{}
void
start
();
void
start
();
void
test
();
void
test
();
};
};
...
@@ -46,4 +45,5 @@ static inline bool is_lnk(const char *name) {
...
@@ -46,4 +45,5 @@ static inline bool is_lnk(const char *name) {
return
S_ISLNK
(
st
.
st_mode
);
return
S_ISLNK
(
st
.
st_mode
);
}
}
void
load_kernel_info
(
cmdline
*
cmd
);
int
dump_magisk
(
const
char
*
path
,
mode_t
mode
);
int
dump_magisk
(
const
char
*
path
,
mode_t
mode
);
native/jni/init/rootfs.cpp
View file @
f1d9015e
...
@@ -40,7 +40,7 @@ constexpr const char wrapper[] =
...
@@ -40,7 +40,7 @@ constexpr const char wrapper[] =
void
MagiskInit
::
setup_rootfs
()
{
void
MagiskInit
::
setup_rootfs
()
{
bool
patch_init
=
patch_sepolicy
();
bool
patch_init
=
patch_sepolicy
();
if
(
cmd
.
system_as_root
)
{
if
(
cmd
->
system_as_root
)
{
// Clone rootfs
// Clone rootfs
LOGD
(
"Clone root dir from system to rootfs
\n
"
);
LOGD
(
"Clone root dir from system to rootfs
\n
"
);
int
system_root
=
xopen
(
"/system_root"
,
O_RDONLY
|
O_CLOEXEC
);
int
system_root
=
xopen
(
"/system_root"
,
O_RDONLY
|
O_CLOEXEC
);
...
...
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