2024-02-26 00:26:23 -08:00
|
|
|
#![feature(format_args_nl)]
|
2024-12-14 23:53:24 +08:00
|
|
|
#![feature(once_cell_try)]
|
2025-02-01 22:27:36 +08:00
|
|
|
#![feature(try_blocks)]
|
2024-02-26 00:26:23 -08:00
|
|
|
|
2023-06-22 02:23:27 -07:00
|
|
|
use logging::setup_klog;
|
2024-02-27 03:14:26 -08:00
|
|
|
use mount::{is_device_mounted, switch_root};
|
2025-02-01 22:27:36 +08:00
|
|
|
use rootdir::{collect_overlay_contexts, inject_magisk_rc, reset_overlay_contexts};
|
2023-05-24 19:11:56 -07:00
|
|
|
// Has to be pub so all symbols in that crate is included
|
|
|
|
pub use magiskpolicy;
|
2022-07-05 21:13:09 -07:00
|
|
|
|
|
|
|
mod logging;
|
2024-02-27 03:14:26 -08:00
|
|
|
mod mount;
|
2024-02-26 00:26:23 -08:00
|
|
|
mod rootdir;
|
2022-07-05 21:13:09 -07:00
|
|
|
|
2023-05-23 21:50:13 -07:00
|
|
|
#[cxx::bridge]
|
|
|
|
pub mod ffi {
|
2025-01-30 18:39:34 +08:00
|
|
|
struct KeyValue {
|
|
|
|
key: String,
|
|
|
|
value: String,
|
|
|
|
}
|
|
|
|
struct BootConfig {
|
|
|
|
skip_initramfs: bool,
|
|
|
|
force_normal_boot: bool,
|
|
|
|
rootwait: bool,
|
|
|
|
emulator: bool,
|
|
|
|
slot: [c_char; 3],
|
|
|
|
dt_dir: [c_char; 64],
|
|
|
|
fstab_suffix: [c_char; 32],
|
|
|
|
hardware: [c_char; 32],
|
|
|
|
hardware_plat: [c_char; 32],
|
|
|
|
partition_map: Vec<KeyValue>,
|
|
|
|
}
|
|
|
|
|
2023-05-23 21:50:13 -07:00
|
|
|
#[namespace = "rust"]
|
2022-07-05 21:13:09 -07:00
|
|
|
extern "Rust" {
|
|
|
|
fn setup_klog();
|
2024-02-26 00:26:23 -08:00
|
|
|
fn inject_magisk_rc(fd: i32, tmp_dir: Utf8CStrRef);
|
2024-02-27 03:14:26 -08:00
|
|
|
fn switch_root(path: Utf8CStrRef);
|
2024-02-27 22:27:52 +08:00
|
|
|
fn is_device_mounted(dev: u64, target: Pin<&mut CxxString>) -> bool;
|
2024-12-14 23:53:24 +08:00
|
|
|
fn collect_overlay_contexts(src: Utf8CStrRef);
|
|
|
|
fn reset_overlay_contexts();
|
2024-02-26 00:26:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe extern "C++" {
|
|
|
|
include!("../base/include/base.hpp");
|
|
|
|
|
|
|
|
#[namespace = "rust"]
|
|
|
|
#[cxx_name = "Utf8CStr"]
|
|
|
|
type Utf8CStrRef<'a> = base::ffi::Utf8CStrRef<'a>;
|
2025-01-30 18:39:34 +08:00
|
|
|
fn init(self: &mut BootConfig);
|
|
|
|
fn print(self: &BootConfig);
|
|
|
|
type kv_pairs;
|
|
|
|
fn set(self: &mut BootConfig, config: &kv_pairs);
|
2022-07-05 21:13:09 -07:00
|
|
|
}
|
|
|
|
}
|