From 563f0d5ad5b94d3b6e01e4d3ab6bf284f0af554e Mon Sep 17 00:00:00 2001 From: LoveSy Date: Thu, 30 Jan 2025 21:59:42 +0800 Subject: [PATCH] Move BootConfig::print to rust --- native/src/init/getinfo.cpp | 12 ------------ native/src/init/getinfo.rs | 20 ++++++++++++++++++++ native/src/init/lib.rs | 4 +++- 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 native/src/init/getinfo.rs diff --git a/native/src/init/getinfo.cpp b/native/src/init/getinfo.cpp index 5c42b9c47..f08975dd0 100644 --- a/native/src/init/getinfo.cpp +++ b/native/src/init/getinfo.cpp @@ -158,18 +158,6 @@ void BootConfig::set(const kv_pairs &kv) noexcept { } } -void BootConfig::print() const noexcept { - LOGD("skip_initramfs=[%d]\n", skip_initramfs); - LOGD("force_normal_boot=[%d]\n", force_normal_boot); - LOGD("rootwait=[%d]\n", rootwait); - LOGD("slot=[%s]\n", slot.data()); - LOGD("dt_dir=[%s]\n", dt_dir.data()); - LOGD("fstab_suffix=[%s]\n", fstab_suffix.data()); - LOGD("hardware=[%s]\n", hardware.data()); - LOGD("hardware.platform=[%s]\n", hardware_plat.data()); - LOGD("emulator=[%d]\n", emulator); -} - #define read_dt(name, key) \ ssprintf(file_name, sizeof(file_name), "%s/" name, dt_dir.data()); \ if (access(file_name, R_OK) == 0) { \ diff --git a/native/src/init/getinfo.rs b/native/src/init/getinfo.rs new file mode 100644 index 000000000..7c3030144 --- /dev/null +++ b/native/src/init/getinfo.rs @@ -0,0 +1,20 @@ +use std::ffi::CStr; +use base::debug; +use crate::ffi::BootConfig; + +impl BootConfig { + pub(crate) fn print(&self) { + debug!("skip_initramfs=[{}]", self.skip_initramfs); + debug!("force_normal_boot=[{}]", self.force_normal_boot); + debug!("rootwait=[{}]", self.rootwait); + unsafe { + debug!("slot=[{:?}]", CStr::from_ptr(self.slot.as_ptr())); + debug!("dt_dir=[{:?}]", CStr::from_ptr(self.dt_dir.as_ptr())); + debug!("fstab_suffix=[{:?}]", CStr::from_ptr(self.fstab_suffix.as_ptr())); + debug!("hardware=[{:?}]", CStr::from_ptr(self.hardware.as_ptr())); + debug!("hardware.platform=[{:?}]", CStr::from_ptr(self.hardware_plat.as_ptr())); + } + debug!("emulator=[{}]", self.emulator); + debug!("partition_map=[{:?}]", self.partition_map); + } +} \ No newline at end of file diff --git a/native/src/init/lib.rs b/native/src/init/lib.rs index 732b16127..5b62030a5 100644 --- a/native/src/init/lib.rs +++ b/native/src/init/lib.rs @@ -18,9 +18,11 @@ use std::ptr::null as nullptr; mod logging; mod mount; mod rootdir; +mod getinfo; #[cxx::bridge] pub mod ffi { + #[derive(Debug)] struct KeyValue { key: String, value: String, @@ -57,6 +59,7 @@ pub mod ffi { } extern "Rust" { + fn print(self: &BootConfig); fn prepare_data(self: &MagiskInit); fn exec_init(self: &MagiskInit); } @@ -68,7 +71,6 @@ pub mod ffi { #[cxx_name = "Utf8CStr"] type Utf8CStrRef<'a> = base::ffi::Utf8CStrRef<'a>; fn init(self: &mut BootConfig); - fn print(self: &BootConfig); type kv_pairs; fn set(self: &mut BootConfig, config: &kv_pairs);