Magisk/native/src
LoveSy a8c2ae223a Avoid hexpatch /init for 2SI when possible
Previous we hexpatch /init from /system/bin/init to /data/magiskinit
to redirect the second stage init. However, some devices like sony
has /init that does not directly invoke /system/bin/init, and thus
the hexpatch fails.

In this patch, we further make use of AOSP `SwitchRoot` to help us
bind mount /data/magisk to /system/bin/init after `SwitchRoot`.

Two important assumption about 2SI are i) that the second stage init
is always /system/bin/init and ii) that the /sdcard (path after
`SwitchRoot`) is always a symlink to `/storage/self/primary`. When
these assumptions hold, during first stage init (before `SwitchRoot`)
we can bind mount magiskinit to /sdcard, and create a symlink
/storage/self/primary to /system/system/bin/init. By these steps,
during `SwitchRoot`, AOSP init will try to mount move /sdcard to
/system/sdcard. And /system/sdcard is symlink to /storage/self/primary,
it will try to mount move /sdcard to /storage/self/primary. And
/storage/self/primary in ramfs is now a symlink that points to
/system/system/bin/init, thus AOSP will try to mount move /sdcard
(which is a bind mount to magiskinit) to /system/system/bin/init.
After chroot done by AOSP init, we then have a magiskinit bind mount
on /system/bin/init, which is the second stage init.

An edge case is that some devices (like meizu) use 2SI but
does not switch root. In this case, they must already have a /sdcard
in the ramfs, thus we can check if /sdcard exists and fallback to
hexpatch.
2024-02-29 23:40:00 -08:00
..
.cargo Remove rust workaround 2024-01-29 15:07:21 -08:00
base Build magiskboot with crt0 2024-02-29 02:36:05 -08:00
boot Build magiskboot with crt0 2024-02-29 02:36:05 -08:00
core Code clean up 2024-01-30 11:07:37 -08:00
external Build magiskboot with crt0 2024-02-29 02:36:05 -08:00
include Move some global state into Rust 2023-11-16 15:38:38 -08:00
init Avoid hexpatch /init for 2SI when possible 2024-02-29 23:40:00 -08:00
sepolicy Build magiskboot with crt0 2024-02-29 02:36:05 -08:00
.gitignore Restructure the native module 2022-07-23 13:51:56 -07:00
Android-rs.mk Restructure project files 2023-11-08 01:46:02 -08:00
Android.mk Build magiskboot with crt0 2024-02-29 02:36:05 -08:00
AndroidManifest.xml Restructure the native module 2022-07-23 13:51:56 -07:00
Application.mk Make crt0 an external submodule 2024-02-26 17:34:17 -08:00
Cargo.lock Use self implemented parse_mount_info 2024-02-27 17:03:22 -08:00
Cargo.toml Use self implemented parse_mount_info 2024-02-27 17:03:22 -08:00
exported_sym.txt One stage zygisk loading 2024-01-11 16:19:39 -08:00
lto_fix.lds Restructure the native module 2022-07-23 13:51:56 -07:00