diff --git a/native/src/Cargo.lock b/native/src/Cargo.lock index ebf6ba778..9abcf7a18 100644 --- a/native/src/Cargo.lock +++ b/native/src/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -61,9 +61,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "base" @@ -109,18 +109,18 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.14.3" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef034f05691a48569bd920a96c81b9d91bbad1ab5ac7c4616c1f6ef36cb79f" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" +checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60" dependencies = [ "proc-macro2", "quote", @@ -135,9 +135,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.0.88" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" [[package]] name = "cfg-if" @@ -176,6 +176,26 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const_format" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "cpufeatures" version = "0.2.12" @@ -341,9 +361,9 @@ dependencies = [ [[package]] name = "flagset" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a7e408202050813e6f1d9addadcaafef3dca7530c7ddfb005d4081cce6779" +checksum = "cdeb3aa5e95cf9aabc17f060cfa0ced7b83f042390760ca53bf09df9968acaa1" [[package]] name = "generic-array" @@ -437,9 +457,9 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "magisk" @@ -447,6 +467,7 @@ version = "0.0.0" dependencies = [ "base", "bytemuck", + "const_format", "cxx", "cxx-gen", "num-derive", @@ -661,9 +682,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -722,9 +743,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", @@ -734,9 +755,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", @@ -854,9 +875,9 @@ checksum = "9fed904c7fb2856d868b92464fc8fa597fce366edea1a9cbfaa8cb5fe080bd6d" [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "spin" @@ -888,9 +909,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" -version = "2.0.51" +version = "2.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" dependencies = [ "proc-macro2", "quote", @@ -917,18 +938,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", @@ -974,6 +995,12 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "vec_map" version = "0.8.2" diff --git a/native/src/Cargo.toml b/native/src/Cargo.toml index 8e38aaf4d..02ba1efd3 100644 --- a/native/src/Cargo.toml +++ b/native/src/Cargo.toml @@ -23,6 +23,7 @@ x509-cert = "0.2" der = "0.7" bytemuck = "1.14" fdt = "0.1" +const_format = "0.2" [workspace.dependencies.argh] git = "https://github.com/google/argh.git" diff --git a/native/src/base/cstr.rs b/native/src/base/cstr.rs index c408c794f..cbdb116cc 100644 --- a/native/src/base/cstr.rs +++ b/native/src/base/cstr.rs @@ -2,10 +2,10 @@ use std::cmp::min; use std::ffi::{CStr, FromBytesWithNulError, OsStr}; use std::fmt::{Arguments, Debug, Display, Formatter, Write}; use std::ops::{Deref, DerefMut}; +use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; use std::str::{Utf8Chunks, Utf8Error}; use std::{fmt, mem, slice, str}; -use std::os::unix::ffi::OsStrExt; use cxx::{type_id, ExternType}; use libc::c_char; @@ -664,6 +664,6 @@ macro_rules! cstr { #[macro_export] macro_rules! raw_cstr { ($($str:tt)*) => {{ - cstr!($($str)*).as_ptr() + $crate::cstr!($($str)*).as_ptr() }}; } diff --git a/native/src/base/xwrap.rs b/native/src/base/xwrap.rs index f3aa50e50..8bd58abea 100644 --- a/native/src/base/xwrap.rs +++ b/native/src/base/xwrap.rs @@ -10,7 +10,7 @@ use libc::{ }; use crate::cxx_extern::readlinkat_for_cxx; -use crate::{cstr, errno, raw_cstr, CxxResultExt, FsPath, Utf8CStr, Utf8CStrBufRef}; +use crate::{errno, raw_cstr, CxxResultExt, FsPath, Utf8CStr, Utf8CStrBufRef}; fn ptr_to_str<'a, T>(ptr: *const T) -> &'a str { if ptr.is_null() { diff --git a/native/src/core/Cargo.toml b/native/src/core/Cargo.toml index f92d5bb3c..93715b90f 100644 --- a/native/src/core/Cargo.toml +++ b/native/src/core/Cargo.toml @@ -17,4 +17,5 @@ cxx = { workspace = true } num-traits = { workspace = true } num-derive = { workspace = true } quick-protobuf = { workspace = true } +const_format = { workspace = true } bytemuck = { workspace = true, features = ["derive"] } diff --git a/native/src/core/daemon.rs b/native/src/core/daemon.rs index 395d63e79..7d3f29c8c 100644 --- a/native/src/core/daemon.rs +++ b/native/src/core/daemon.rs @@ -9,9 +9,10 @@ use base::{ Utf8CStrBufArr, Utf8CStrBufRef, WalkResult, }; +use crate::consts::MAIN_CONFIG; use crate::ffi::{get_magisk_tmp, CxxMagiskD, RequestCode}; +use crate::get_prop; use crate::logging::magisk_logging; -use crate::{get_prop, MAIN_CONFIG}; // Global magiskd singleton pub static MAGISKD: OnceLock = OnceLock::new(); @@ -108,7 +109,7 @@ pub fn daemon_entry() { let mut buf = Utf8CStrBufArr::<64>::new(); let path = FsPathBuf::new(&mut buf) .join(get_magisk_tmp()) - .join(MAIN_CONFIG!()); + .join(MAIN_CONFIG); let mut is_recovery = false; if let Ok(file) = path.open(O_RDONLY | O_CLOEXEC) { let mut file = BufReader::new(file); diff --git a/native/src/core/logging.rs b/native/src/core/logging.rs index f3afad14f..fd55864aa 100644 --- a/native/src/core/logging.rs +++ b/native/src/core/logging.rs @@ -9,6 +9,7 @@ use std::sync::atomic::{AtomicI32, Ordering}; use std::{fs, io}; use bytemuck::{bytes_of, bytes_of_mut, write_zeroes, Pod, Zeroable}; +use const_format::concatcp; use num_derive::{FromPrimitive, ToPrimitive}; use num_traits::FromPrimitive; @@ -17,12 +18,15 @@ use base::libc::{ timespec, tm, CLOCK_REALTIME, O_CLOEXEC, O_RDWR, O_WRONLY, PIPE_BUF, SIGPIPE, SIG_BLOCK, SIG_SETMASK, }; -use base::*; +use base::{ + exit_on_error, libc, raw_cstr, FsPathBuf, LogLevel, Logger, Utf8CStr, Utf8CStrBuf, + Utf8CStrBufArr, Utf8CStrWrite, LOGGER, +}; +use crate::consts::{LOGFILE, LOG_PIPE}; use crate::daemon::{MagiskD, MAGISKD}; use crate::ffi::get_magisk_tmp; use crate::logging::LogFile::{Actual, Buffer}; -use crate::{LOGFILE, LOG_PIPE}; #[allow(dead_code, non_camel_case_types)] #[derive(FromPrimitive, ToPrimitive)] @@ -192,7 +196,7 @@ pub fn zygisk_get_logd() -> i32 { let mut buf = Utf8CStrBufArr::default(); let path = FsPathBuf::new(&mut buf) .join(get_magisk_tmp()) - .join(LOG_PIPE!()); + .join(LOG_PIPE); // Open as RW as sometimes it may block fd = unsafe { libc::open(path.as_ptr(), O_RDWR | O_CLOEXEC) }; if fd >= 0 { @@ -292,9 +296,9 @@ extern "C" fn logfile_writer(arg: *mut c_void) -> *mut c_void { pipe.read_exact(bytes_of_mut(&mut meta))?; if meta.prio < 0 { - if matches!(logfile, LogFile::Buffer(_)) { - fs::rename(LOGFILE!(), concat!(LOGFILE!(), ".bak")).ok(); - let mut out = File::create(LOGFILE!())?; + if matches!(logfile, Buffer(_)) { + fs::rename(LOGFILE, concatcp!(LOGFILE, ".bak")).ok(); + let mut out = File::create(LOGFILE)?; out.write_all(tmp.as_slice())?; tmp = Vec::new(); logfile = Actual(out); @@ -371,7 +375,7 @@ impl MagiskD { let mut buf = Utf8CStrBufArr::default(); let path = FsPathBuf::new(&mut buf) .join(get_magisk_tmp()) - .join(LOG_PIPE!()); + .join(LOG_PIPE); unsafe { libc::mkfifo(path.as_ptr(), 0o666); diff --git a/native/src/include/consts.rs b/native/src/include/consts.rs index ac5ec6b8e..528a66ca0 100644 --- a/native/src/include/consts.rs +++ b/native/src/include/consts.rs @@ -1,29 +1,6 @@ -// Expose constant strings as macros so that we can use concat!() on these values +use const_format::concatcp; -#[macro_export] -macro_rules! LOGFILE { - () => { - "/cache/magisk.log" - }; -} - -#[macro_export] -macro_rules! INTLROOT { - () => { - ".magisk" - }; -} - -#[macro_export] -macro_rules! LOG_PIPE { - () => { - concat!($crate::INTLROOT!(), "/device/log") - }; -} - -#[macro_export] -macro_rules! MAIN_CONFIG { - () => { - concat!($crate::INTLROOT!(), "/config") - }; -} +pub const LOGFILE: &str = "/cache/magisk.log"; +pub const INTLROOT: &str = ".magisk"; +pub const LOG_PIPE: &str = concatcp!(INTLROOT, "/device/log"); +pub const MAIN_CONFIG: &str = concatcp!(INTLROOT, "/config");