-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Expand file tree
/
Copy pathlib.rs
More file actions
107 lines (94 loc) · 3.1 KB
/
lib.rs
File metadata and controls
107 lines (94 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#![allow(clippy::missing_safety_doc)]
use logging::setup_klog;
// Has to be pub so all symbols in that crate is included
pub use magiskpolicy;
use mount::{is_device_mounted, switch_root};
use rootdir::OverlayAttr;
#[path = "../include/consts.rs"]
mod consts;
mod getinfo;
mod init;
mod logging;
mod mount;
mod rootdir;
mod selinux;
mod twostage;
#[cxx::bridge]
pub mod ffi {
#[derive(Debug)]
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],
boot_mode: [c_char; 16],
partition_map: Vec<KeyValue>,
}
struct MagiskInit {
preinit_dev: String,
mount_list: Vec<String>,
rc_list: Vec<String>,
argv: *mut *mut c_char,
config: BootConfig,
overlay_con: Vec<OverlayAttr>,
}
unsafe extern "C++" {
include!("init.hpp");
#[cxx_name = "Utf8CStr"]
type Utf8CStrRef<'a> = base::Utf8CStrRef<'a>;
unsafe fn magisk_proxy_main(argc: i32, argv: *mut *mut c_char) -> i32;
fn backup_init() -> Utf8CStrRef<'static>;
// Constants
fn split_plat_cil() -> Utf8CStrRef<'static>;
fn preload_lib() -> Utf8CStrRef<'static>;
fn preload_policy() -> Utf8CStrRef<'static>;
fn preload_ack() -> Utf8CStrRef<'static>;
}
#[namespace = "rust"]
extern "Rust" {
fn setup_klog();
fn switch_root(path: Utf8CStrRef);
fn is_device_mounted(dev: u64, target: Pin<&mut CxxString>) -> bool;
}
// BootConfig
extern "Rust" {
fn print(self: &BootConfig);
}
unsafe extern "C++" {
fn init(self: &mut BootConfig);
type kv_pairs;
fn set(self: &mut BootConfig, config: &kv_pairs);
}
// MagiskInit
extern "Rust" {
type OverlayAttr;
fn parse_config_file(self: &mut MagiskInit);
fn mount_overlay(self: &mut MagiskInit, dest: Utf8CStrRef);
fn handle_sepolicy(self: &mut MagiskInit);
fn restore_overlay_contexts(self: &MagiskInit);
fn load_overlay_rc(self: &mut MagiskInit, overlay: &Utf8CStrRef, module_path: &Utf8CStrRef);
fn handle_modules_rc(self: &mut MagiskInit, root_dir: &Utf8CStrRef);
fn patch_rc_scripts(self: &mut MagiskInit, src_path: Utf8CStrRef, tmp_path: Utf8CStrRef, writable: bool) -> bool;
fn patch_fissiond(self: &mut MagiskInit, tmp_path: Utf8CStrRef);
}
unsafe extern "C++" {
// Used in Rust
fn mount_system_root(self: &mut MagiskInit) -> bool;
fn patch_rw_root(self: &mut MagiskInit);
fn patch_ro_root(self: &mut MagiskInit);
// Used in C++
unsafe fn setup_tmp(self: &mut MagiskInit, path: *const c_char);
fn collect_devices(self: &MagiskInit);
fn mount_preinit_dir(self: &mut MagiskInit);
unsafe fn find_block(self: &MagiskInit, partname: *const c_char) -> u64;
}
}