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
0dad06cd
Commit
0dad06cd
authored
Aug 14, 2021
by
LoveSy
Committed by
John Wu
Aug 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix meizu compatibility
parent
9396288c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
28 deletions
+56
-28
init.hpp
native/jni/init/init.hpp
+31
-21
mount.cpp
native/jni/init/mount.cpp
+14
-4
rootdir.cpp
native/jni/init/rootdir.cpp
+10
-2
files.cpp
native/jni/utils/files.cpp
+1
-1
No files found.
native/jni/init/init.hpp
View file @
0dad06cd
...
...
@@ -42,8 +42,8 @@ void setup_klog();
class
BaseInit
{
protected
:
cmdline
*
cmd
;
char
**
argv
;
cmdline
*
cmd
=
nullptr
;
char
**
argv
=
nullptr
;
[[
noreturn
]]
void
exec_init
();
void
read_dt_fstab
(
std
::
vector
<
fstab_entry
>
&
fstab
);
...
...
@@ -67,7 +67,7 @@ public:
MagiskInit
(
char
*
argv
[],
cmdline
*
cmd
)
:
BaseInit
(
argv
,
cmd
)
{}
};
class
SARBase
:
public
MagiskInit
{
class
SARBase
:
virtual
public
MagiskInit
{
protected
:
std
::
vector
<
raw_file
>
overlays
;
...
...
@@ -75,7 +75,7 @@ protected:
void
patch_rootdir
();
void
mount_system_root
();
public
:
SARBase
(
char
*
argv
[],
cmdline
*
cmd
)
:
MagiskInit
(
argv
,
cmd
)
{}
SARBase
(
)
=
default
;
};
/***************
...
...
@@ -95,20 +95,6 @@ public:
}
};
class
SecondStageInit
:
public
SARBase
{
private
:
void
prepare
();
public
:
SecondStageInit
(
char
*
argv
[])
:
SARBase
(
argv
,
nullptr
)
{
LOGD
(
"%s
\n
"
,
__FUNCTION__
);
};
void
start
()
override
{
prepare
();
patch_rootdir
();
exec_init
();
}
};
/*************
* Legacy SAR
*************/
...
...
@@ -120,7 +106,7 @@ private:
void
early_mount
();
void
first_stage_prep
();
public
:
SARInit
(
char
*
argv
[],
cmdline
*
cmd
)
:
SARBase
(
argv
,
cmd
),
is_two_stage
(
false
)
{
SARInit
(
char
*
argv
[],
cmdline
*
cmd
)
:
MagiskInit
(
argv
,
cmd
),
is_two_stage
(
false
)
{
LOGD
(
"%s
\n
"
,
__FUNCTION__
);
};
void
start
()
override
{
...
...
@@ -137,10 +123,18 @@ public:
* Initramfs
************/
class
RootFSInit
:
public
MagiskInit
{
class
RootFSBase
:
virtual
public
MagiskInit
{
protected
:
void
patch_rootfs
();
public
:
RootFSBase
()
=
default
;
void
start
()
=
0
;
};
class
RootFSInit
:
public
RootFSBase
{
private
:
void
early_mount
();
void
patch_rootfs
();
public
:
RootFSInit
(
char
*
argv
[],
cmdline
*
cmd
)
:
MagiskInit
(
argv
,
cmd
)
{
LOGD
(
"%s
\n
"
,
__FUNCTION__
);
...
...
@@ -152,6 +146,22 @@ public:
}
};
class
SecondStageInit
:
public
RootFSBase
,
public
SARBase
{
private
:
bool
prepare
();
public
:
SecondStageInit
(
char
*
argv
[])
:
MagiskInit
(
argv
,
nullptr
)
{
LOGD
(
"%s
\n
"
,
__FUNCTION__
);
};
void
start
()
override
{
if
(
prepare
())
patch_rootfs
();
else
patch_rootdir
();
exec_init
();
}
};
class
MagiskProxy
:
public
MagiskInit
{
public
:
explicit
MagiskProxy
(
char
*
argv
[])
:
MagiskInit
(
argv
,
nullptr
)
{
...
...
native/jni/init/mount.cpp
View file @
0dad06cd
...
...
@@ -185,7 +185,7 @@ static void switch_root(const string &path) {
});
for
(
auto
&
dir
:
mounts
)
{
auto
new_path
=
path
+
dir
;
mkdir
(
new_path
.
data
(),
0755
);
x
mkdir
(
new_path
.
data
(),
0755
);
xmount
(
dir
.
data
(),
new_path
.
data
(),
nullptr
,
MS_MOVE
,
nullptr
);
}
chdir
(
path
.
data
());
...
...
@@ -355,14 +355,24 @@ void SARInit::early_mount() {
}
}
void
SecondStageInit
::
prepare
()
{
bool
SecondStageInit
::
prepare
()
{
backup_files
();
umount2
(
"/init"
,
MNT_DETACH
);
umount2
(
"/proc/self/exe"
,
MNT_DETACH
);
if
(
access
(
"/system_root"
,
F_OK
)
==
0
)
switch_root
(
"/system_root"
);
// some weird devices, like meizu, embrace two stage init but still have legacy rootfs behaviour
bool
legacy
=
false
;
if
(
access
(
"/system_root"
,
F_OK
)
==
0
)
{
if
(
access
(
"/system_root/proc"
,
F_OK
)
==
0
)
{
switch_root
(
"/system_root"
);
}
else
{
xmount
(
"/system_root"
,
"/system"
,
nullptr
,
MS_MOVE
,
nullptr
);
rmdir
(
"/system_root"
);
legacy
=
true
;
}
}
return
legacy
;
}
void
BaseInit
::
exec_init
()
{
...
...
native/jni/init/rootdir.cpp
View file @
0dad06cd
...
...
@@ -15,6 +15,10 @@ static vector<string> rc_list;
static
void
patch_init_rc
(
const
char
*
src
,
const
char
*
dest
,
const
char
*
tmp_dir
)
{
FILE
*
rc
=
xfopen
(
dest
,
"we"
);
if
(
!
rc
)
{
PLOGE
(
"%s: open %s failed"
,
__PRETTY_FUNCTION__
,
src
);
return
;
}
file_readline
(
src
,
[
=
](
string_view
line
)
->
bool
{
// Do not start vaultkeeper
if
(
str_contains
(
line
,
"start vaultkeeper"
))
{
...
...
@@ -157,6 +161,7 @@ static string magic_mount_list;
static
void
magic_mount
(
const
string
&
sdir
,
const
string
&
ddir
=
""
)
{
auto
dir
=
xopen_dir
(
sdir
.
data
());
if
(
!
dir
)
return
;
for
(
dirent
*
entry
;
(
entry
=
xreaddir
(
dir
.
get
()));)
{
string
src
=
sdir
+
"/"
+
entry
->
d_name
;
string
dest
=
ddir
+
"/"
+
entry
->
d_name
;
...
...
@@ -321,7 +326,7 @@ void SARBase::patch_rootdir() {
#define TMP_MNTDIR "/dev/mnt"
#define TMP_RULESDIR "/.backup/.sepolicy.rules"
void
RootFS
Init
::
patch_rootfs
()
{
void
RootFS
Base
::
patch_rootfs
()
{
// Create hardlink mirror of /sbin to /root
mkdir
(
"/root"
,
0777
);
clone_attr
(
"/sbin"
,
"/root"
);
...
...
@@ -338,8 +343,11 @@ void RootFSInit::patch_rootfs() {
}
if
(
patch_sepolicy
(
"/sepolicy"
))
{
auto
init
=
mmap_data
::
r
w
(
"/init"
);
auto
init
=
mmap_data
::
r
o
(
access
(
"/system/bin/init"
,
F_OK
)
==
0
?
"/system/bin/init"
:
"/init"
);
init
.
patch
({
make_pair
(
SPLIT_PLAT_CIL
,
"xxx"
)
});
int
dest
=
xopen
(
"/init"
,
O_TRUNC
|
O_WRONLY
|
O_CLOEXEC
,
0
);
xwrite
(
dest
,
init
.
buf
,
init
.
sz
);
close
(
dest
);
}
// Handle overlays
...
...
native/jni/utils/files.cpp
View file @
0dad06cd
...
...
@@ -423,7 +423,7 @@ void restore_folder(const char *dir, vector<raw_file> &files) {
mkdirs
(
path
.
data
(),
0
);
}
else
if
(
S_ISREG
(
file
.
attr
.
st
.
st_mode
))
{
auto
fp
=
xopen_file
(
path
.
data
(),
"we"
);
fwrite
(
file
.
buf
,
1
,
file
.
sz
,
fp
.
get
());
if
(
fp
)
fwrite
(
file
.
buf
,
1
,
file
.
sz
,
fp
.
get
());
}
else
if
(
S_ISLNK
(
file
.
attr
.
st
.
st_mode
))
{
symlink
((
char
*
)
file
.
buf
,
path
.
data
());
}
...
...
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