mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-05-01 23:14:26 +02:00
Move MagiskInit::MagiskInit to rust
This commit is contained in:
parent
d203a6fff6
commit
a85c4c6528
@ -60,26 +60,6 @@ void restore_ramdisk_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MagiskInit::init() noexcept {
|
|
||||||
// Get kernel data using procfs and sysfs
|
|
||||||
if (access("/proc/cmdline", F_OK) != 0) {
|
|
||||||
xmkdir("/proc", 0755);
|
|
||||||
xmount("proc", "/proc", "proc", 0, nullptr);
|
|
||||||
mount_list.emplace_back("/proc");
|
|
||||||
}
|
|
||||||
if (access("/sys/block", F_OK) != 0) {
|
|
||||||
xmkdir("/sys", 0755);
|
|
||||||
xmount("sysfs", "/sys", "sysfs", 0, nullptr);
|
|
||||||
mount_list.emplace_back("/sys");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log to kernel
|
|
||||||
rust::setup_klog();
|
|
||||||
|
|
||||||
// Load kernel configs
|
|
||||||
config.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void recovery() {
|
static void recovery() {
|
||||||
LOGI("Ramdisk is recovery, abort\n");
|
LOGI("Ramdisk is recovery, abort\n");
|
||||||
restore_ramdisk_init();
|
restore_ramdisk_init();
|
||||||
|
@ -2,12 +2,18 @@
|
|||||||
#![feature(once_cell_try)]
|
#![feature(once_cell_try)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
|
|
||||||
|
use base::{
|
||||||
|
cstr,
|
||||||
|
libc::{mount},
|
||||||
|
raw_cstr, FsPath, LibcReturn, LoggedResult,
|
||||||
|
};
|
||||||
use logging::setup_klog;
|
use logging::setup_klog;
|
||||||
use mount::{is_device_mounted, switch_root};
|
use mount::{is_device_mounted, switch_root};
|
||||||
use rootdir::{collect_overlay_contexts, inject_magisk_rc, reset_overlay_contexts};
|
use rootdir::{collect_overlay_contexts, inject_magisk_rc, reset_overlay_contexts};
|
||||||
// Has to be pub so all symbols in that crate is included
|
// Has to be pub so all symbols in that crate is included
|
||||||
pub use magiskpolicy;
|
|
||||||
use crate::ffi::{BootConfig, MagiskInit};
|
use crate::ffi::{BootConfig, MagiskInit};
|
||||||
|
pub use magiskpolicy;
|
||||||
|
use std::ptr::null as nullptr;
|
||||||
|
|
||||||
mod logging;
|
mod logging;
|
||||||
mod mount;
|
mod mount;
|
||||||
@ -85,28 +91,64 @@ pub mod ffi {
|
|||||||
fn legacy_system_as_root(self: &mut MagiskInit);
|
fn legacy_system_as_root(self: &mut MagiskInit);
|
||||||
fn rootfs(self: &mut MagiskInit);
|
fn rootfs(self: &mut MagiskInit);
|
||||||
fn start(self: &mut MagiskInit);
|
fn start(self: &mut MagiskInit);
|
||||||
fn init(self: &mut MagiskInit);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn start_magisk_init(argv: *mut *mut std::ffi::c_char) {
|
pub(crate) fn start_magisk_init(argv: *mut *mut std::ffi::c_char) {
|
||||||
let mut init = MagiskInit {
|
fn inner(argv: *mut *mut std::ffi::c_char) -> LoggedResult<()> {
|
||||||
preinit_dev: String::new(),
|
let mut init = MagiskInit {
|
||||||
mount_list: Vec::new(),
|
preinit_dev: String::new(),
|
||||||
argv,
|
mount_list: Vec::new(),
|
||||||
config: BootConfig {
|
argv,
|
||||||
skip_initramfs: false,
|
config: BootConfig {
|
||||||
force_normal_boot: false,
|
skip_initramfs: false,
|
||||||
rootwait: false,
|
force_normal_boot: false,
|
||||||
emulator: false,
|
rootwait: false,
|
||||||
slot: [0; 3],
|
emulator: false,
|
||||||
dt_dir: [0; 64],
|
slot: [0; 3],
|
||||||
fstab_suffix: [0; 32],
|
dt_dir: [0; 64],
|
||||||
hardware: [0; 32],
|
fstab_suffix: [0; 32],
|
||||||
hardware_plat: [0; 32],
|
hardware: [0; 32],
|
||||||
partition_map: Vec::new(),
|
hardware_plat: [0; 32],
|
||||||
},
|
partition_map: Vec::new(),
|
||||||
};
|
},
|
||||||
init.init();
|
};
|
||||||
init.start();
|
if !FsPath::from(cstr!("/proc/cmdline")).exists() {
|
||||||
|
FsPath::from(cstr!("/proc")).mkdir(0o755)?;
|
||||||
|
unsafe {
|
||||||
|
mount(
|
||||||
|
raw_cstr!("proc"),
|
||||||
|
raw_cstr!("/proc"),
|
||||||
|
raw_cstr!("proc"),
|
||||||
|
0,
|
||||||
|
nullptr(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.as_os_err()?;
|
||||||
|
init.mount_list.push("/proc".to_string());
|
||||||
|
}
|
||||||
|
if !FsPath::from(cstr!("/sys/block")).exists() {
|
||||||
|
FsPath::from(cstr!("/sys")).mkdir(0o755)?;
|
||||||
|
unsafe {
|
||||||
|
mount(
|
||||||
|
raw_cstr!("sysfs"),
|
||||||
|
raw_cstr!("/sys"),
|
||||||
|
raw_cstr!("sysfs"),
|
||||||
|
0,
|
||||||
|
nullptr(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.as_os_err()?;
|
||||||
|
init.mount_list.push("/sys".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_klog();
|
||||||
|
|
||||||
|
init.config.init();
|
||||||
|
|
||||||
|
init.start();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
inner(argv).ok();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user