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,11 +91,11 @@ 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) {
|
||||||
|
fn inner(argv: *mut *mut std::ffi::c_char) -> LoggedResult<()> {
|
||||||
let mut init = MagiskInit {
|
let mut init = MagiskInit {
|
||||||
preinit_dev: String::new(),
|
preinit_dev: String::new(),
|
||||||
mount_list: Vec::new(),
|
mount_list: Vec::new(),
|
||||||
@ -107,6 +113,42 @@ pub(crate) fn start_magisk_init(argv: *mut *mut std::ffi::c_char) {
|
|||||||
partition_map: Vec::new(),
|
partition_map: Vec::new(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
init.init();
|
if !FsPath::from(cstr!("/proc/cmdline")).exists() {
|
||||||
init.start();
|
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