mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-05 03:20:46 -05:00
Update to ONDK r29.5
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
#![feature(try_blocks)]
|
||||
#![feature(fn_traits)]
|
||||
#![feature(unix_socket_ancillary_data)]
|
||||
#![feature(unix_socket_peek)]
|
||||
|
||||
@@ -329,7 +329,7 @@ pub fn start_log_daemon() {
|
||||
0
|
||||
}
|
||||
|
||||
let _: LoggedResult<()> = try {
|
||||
let _ = || -> LoggedResult<()> {
|
||||
path.mkfifo(0o666).log_ok();
|
||||
chown(path.as_utf8_cstr(), Some(Uid::from(0)), Some(Gid::from(0)))?;
|
||||
let read = path.open(OFlag::O_RDWR | OFlag::O_CLOEXEC)?;
|
||||
@@ -338,5 +338,6 @@ pub fn start_log_daemon() {
|
||||
unsafe {
|
||||
new_daemon_thread(logfile_writer_thread, read.into_raw_fd() as usize);
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}();
|
||||
}
|
||||
|
||||
+17
-12
@@ -46,12 +46,13 @@ pub fn setup_preinit_dir() {
|
||||
let target = Utf8CStr::from_string(&mut target);
|
||||
let mut preinit_dir = resolve_preinit_dir(target);
|
||||
let preinit_dir = Utf8CStr::from_string(&mut preinit_dir);
|
||||
let r: LoggedResult<()> = try {
|
||||
let r = || -> LoggedResult<()> {
|
||||
preinit_dir.mkdir(0o700)?;
|
||||
mnt_path.mkdirs(0o755)?;
|
||||
mnt_path.remove().ok();
|
||||
mnt_path.create_symlink_to(preinit_dir)?;
|
||||
};
|
||||
Ok(())
|
||||
}();
|
||||
if r.is_ok() {
|
||||
info!("* Found preinit dir: {}", preinit_dir);
|
||||
return;
|
||||
@@ -68,11 +69,12 @@ pub fn setup_module_mount() {
|
||||
let module_mnt = cstr::buf::default()
|
||||
.join_path(get_magisk_tmp())
|
||||
.join_path(MODULEMNT);
|
||||
let _: LoggedResult<()> = try {
|
||||
let _ = || -> LoggedResult<()> {
|
||||
module_mnt.mkdir(0o755)?;
|
||||
cstr!(MODULEROOT).bind_mount_to(&module_mnt, false)?;
|
||||
module_mnt.remount_mount_point_flags(MsFlags::MS_RDONLY)?;
|
||||
};
|
||||
Ok(())
|
||||
}();
|
||||
}
|
||||
|
||||
pub fn clean_mounts() {
|
||||
@@ -85,10 +87,11 @@ pub fn clean_mounts() {
|
||||
buf.clear();
|
||||
|
||||
let worker_dir = buf.append_path(magisk_tmp).append_path(WORKERDIR);
|
||||
let _: LoggedResult<()> = try {
|
||||
let _ = || -> LoggedResult<()> {
|
||||
worker_dir.set_mount_private(true)?;
|
||||
worker_dir.unmount()?;
|
||||
};
|
||||
Ok(())
|
||||
}();
|
||||
}
|
||||
|
||||
// when partitions have the same fs type, the order is:
|
||||
@@ -146,10 +149,11 @@ pub fn find_preinit_device() -> String {
|
||||
}
|
||||
// use device major number to filter out device-mapper
|
||||
let maj = major(info.device as dev_t) as u32;
|
||||
if maj >= DYNAMIC_MAJOR_MIN && maj <= DYNAMIC_MAJOR_MAX {
|
||||
if !info.source.contains("/vd") && !info.source.contains("/by-name/") {
|
||||
return None;
|
||||
}
|
||||
if (DYNAMIC_MAJOR_MIN..=DYNAMIC_MAJOR_MAX).contains(&maj)
|
||||
&& !info.source.contains("/vd")
|
||||
&& !info.source.contains("/by-name/")
|
||||
{
|
||||
return None;
|
||||
}
|
||||
// take data iff it's not encrypted or file-based encrypted without metadata
|
||||
// other partitions are always taken
|
||||
@@ -196,13 +200,14 @@ pub fn find_preinit_device() -> String {
|
||||
let mut buf = cstr::buf::default();
|
||||
let mirror_dir = buf.append_path(&tmp).append_path(PREINITMIRR);
|
||||
let preinit_dir = Utf8CStr::from_string(&mut preinit_dir);
|
||||
let _: LoggedResult<()> = try {
|
||||
let _ = || -> LoggedResult<()> {
|
||||
preinit_dir.mkdirs(0o700)?;
|
||||
mirror_dir.mkdirs(0o755)?;
|
||||
mirror_dir.unmount().ok();
|
||||
mirror_dir.remove().ok();
|
||||
mirror_dir.create_symlink_to(preinit_dir)?;
|
||||
};
|
||||
Ok(())
|
||||
}();
|
||||
if std::env::var_os("MAKEDEV").is_some() {
|
||||
buf.clear();
|
||||
let dev_path = buf.append_path(&tmp).append_path(PREINITDEV);
|
||||
|
||||
@@ -49,7 +49,7 @@ macro_rules! bad_apk {
|
||||
* within the APK v2 signature block.
|
||||
*/
|
||||
fn read_certificate(apk: &mut File, version: i32) -> Vec<u8> {
|
||||
let res: io::Result<Vec<u8>> = try {
|
||||
let res = || -> io::Result<Vec<u8>> {
|
||||
let mut u32_val = 0u32;
|
||||
let mut u64_val = 0u64;
|
||||
|
||||
@@ -137,7 +137,7 @@ fn read_certificate(apk: &mut File, version: i32) -> Vec<u8> {
|
||||
|
||||
let mut cert = vec![0; u32_val as usize];
|
||||
apk.read_exact(cert.as_mut())?;
|
||||
break cert;
|
||||
break Ok(cert);
|
||||
} else {
|
||||
// Skip this id-value pair
|
||||
apk.seek(SeekFrom::Current(
|
||||
@@ -145,7 +145,7 @@ fn read_certificate(apk: &mut File, version: i32) -> Vec<u8> {
|
||||
))?;
|
||||
}
|
||||
}
|
||||
};
|
||||
}();
|
||||
res.log().unwrap_or(vec![])
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ impl ManagerInfo {
|
||||
if let Some(ref mut stub_fd) = self.stub_apk_fd {
|
||||
// Copy the stub APK
|
||||
let tmp_apk = cstr!("/data/stub.apk");
|
||||
let result: LoggedResult<()> = try {
|
||||
let result = || -> LoggedResult<()> {
|
||||
{
|
||||
let mut tmp_apk_file = tmp_apk.create(
|
||||
OFlag::O_WRONLY | OFlag::O_CREAT | OFlag::O_TRUNC | OFlag::O_CLOEXEC,
|
||||
@@ -325,7 +325,8 @@ impl ManagerInfo {
|
||||
}
|
||||
// Seek the fd back to start
|
||||
stub_fd.seek(SeekFrom::Start(0))?;
|
||||
};
|
||||
Ok(())
|
||||
}();
|
||||
if result.is_ok() {
|
||||
install_apk(tmp_apk);
|
||||
}
|
||||
@@ -478,7 +479,7 @@ impl MagiskD {
|
||||
// app_no range: [0, 9999]
|
||||
pub fn get_app_no_list(&self) -> BitSet {
|
||||
let mut list = BitSet::new();
|
||||
let _: LoggedResult<()> = try {
|
||||
let _ = || -> LoggedResult<()> {
|
||||
let mut app_data_dir = Directory::open(self.app_data_dir())?;
|
||||
// For each user
|
||||
loop {
|
||||
@@ -507,7 +508,8 @@ impl MagiskD {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}();
|
||||
list
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ impl SuAppContext<'_> {
|
||||
))
|
||||
.ok();
|
||||
|
||||
let fd: LoggedResult<File> = try {
|
||||
let fd = || -> LoggedResult<File> {
|
||||
let mut attr = FileAttr::new();
|
||||
attr.st.st_mode = 0o600;
|
||||
attr.st.st_uid = self.info.mgr_uid.as_();
|
||||
@@ -211,8 +211,8 @@ impl SuAppContext<'_> {
|
||||
PollTimeout::try_from(70 * 1000).unwrap_or(PollTimeout::NONE),
|
||||
)
|
||||
.check_os_err("poll", None, None)?;
|
||||
fd
|
||||
};
|
||||
Ok(fd)
|
||||
}();
|
||||
|
||||
fifo.remove().log_ok();
|
||||
|
||||
|
||||
@@ -215,14 +215,14 @@ impl MagiskD {
|
||||
|
||||
#[cfg(feature = "su-check-db")]
|
||||
fn build_su_info(&self, uid: i32) -> Arc<SuInfo> {
|
||||
let result: LoggedResult<Arc<SuInfo>> = try {
|
||||
let result = || -> LoggedResult<Arc<SuInfo>> {
|
||||
let cfg = self.get_db_settings()?;
|
||||
|
||||
// Check multiuser settings
|
||||
let eval_uid = match cfg.multiuser_mode {
|
||||
MultiuserMode::OwnerOnly => {
|
||||
if to_user_id(uid) != 0 {
|
||||
return Arc::new(SuInfo::deny(uid));
|
||||
return Ok(Arc::new(SuInfo::deny(uid)));
|
||||
}
|
||||
uid
|
||||
}
|
||||
@@ -243,25 +243,25 @@ impl MagiskD {
|
||||
|
||||
// If it's the manager, allow it silently
|
||||
if to_app_id(uid) == to_app_id(mgr_uid) {
|
||||
return Arc::new(SuInfo::allow(uid));
|
||||
return Ok(Arc::new(SuInfo::allow(uid)));
|
||||
}
|
||||
|
||||
// Check su access settings
|
||||
match cfg.root_access {
|
||||
RootAccess::Disabled => {
|
||||
warn!("Root access is disabled!");
|
||||
return Arc::new(SuInfo::deny(uid));
|
||||
return Ok(Arc::new(SuInfo::deny(uid)));
|
||||
}
|
||||
RootAccess::AdbOnly => {
|
||||
if uid != AID_SHELL {
|
||||
warn!("Root access limited to ADB only!");
|
||||
return Arc::new(SuInfo::deny(uid));
|
||||
return Ok(Arc::new(SuInfo::deny(uid)));
|
||||
}
|
||||
}
|
||||
RootAccess::AppsOnly => {
|
||||
if uid == AID_SHELL {
|
||||
warn!("Root access is disabled for ADB!");
|
||||
return Arc::new(SuInfo::deny(uid));
|
||||
return Ok(Arc::new(SuInfo::deny(uid)));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@@ -269,19 +269,19 @@ impl MagiskD {
|
||||
|
||||
// If still not determined, check if manager exists
|
||||
if access.policy == SuPolicy::Query && mgr_uid < 0 {
|
||||
return Arc::new(SuInfo::deny(uid));
|
||||
return Ok(Arc::new(SuInfo::deny(uid)));
|
||||
}
|
||||
|
||||
// Finally, the SuInfo
|
||||
Arc::new(SuInfo {
|
||||
Ok(Arc::new(SuInfo {
|
||||
uid,
|
||||
eval_uid,
|
||||
mgr_pkg,
|
||||
mgr_uid,
|
||||
cfg,
|
||||
access: Mutex::new(AccessInfo::new(access)),
|
||||
})
|
||||
};
|
||||
}))
|
||||
}();
|
||||
|
||||
result.unwrap_or(Arc::new(SuInfo::deny(uid)))
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use base::{ResultExt, new_daemon_thread};
|
||||
use nix::sys::signal::SigSet;
|
||||
use nix::unistd::{getpid, gettid};
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::nonpoison::{Condvar, Mutex};
|
||||
use std::sync::{LazyLock, WaitTimeoutResult};
|
||||
use std::time::Duration;
|
||||
|
||||
static THREAD_POOL: LazyLock<ThreadPool> = LazyLock::new(ThreadPool::default);
|
||||
@@ -39,12 +39,10 @@ impl ThreadPool {
|
||||
if info.task.is_none() {
|
||||
if is_core_pool {
|
||||
// Core pool never closes, wait forever.
|
||||
info = self.task_is_some.wait(info);
|
||||
self.task_is_some.wait(&mut info);
|
||||
} else {
|
||||
let dur = Duration::from_secs(THREAD_IDLE_MAX_SEC);
|
||||
let result: WaitTimeoutResult;
|
||||
(info, result) = self.task_is_some.wait_timeout(info, dur);
|
||||
if result.timed_out() {
|
||||
if self.task_is_some.wait_timeout(&mut info, dur).timed_out() {
|
||||
// Terminate thread after timeout
|
||||
info.idle_threads -= 1;
|
||||
info.total_threads -= 1;
|
||||
@@ -76,7 +74,7 @@ impl ThreadPool {
|
||||
let mut info = self.info.lock();
|
||||
while info.task.is_some() {
|
||||
// Wait until task is none
|
||||
info = self.task_is_none.wait(info);
|
||||
self.task_is_none.wait(&mut info);
|
||||
}
|
||||
info.task = Some(Box::new(f));
|
||||
if info.idle_threads == 0 {
|
||||
|
||||
@@ -157,7 +157,7 @@ impl ZygiskState {
|
||||
|
||||
impl MagiskD {
|
||||
pub fn zygisk_handler(&self, mut client: UnixStream) {
|
||||
let _: LoggedResult<()> = try {
|
||||
let _ = || -> LoggedResult<()> {
|
||||
let code = ZygiskRequest {
|
||||
repr: client.read_decodable()?,
|
||||
};
|
||||
@@ -171,7 +171,8 @@ impl MagiskD {
|
||||
ZygiskRequest::GetModDir => self.get_mod_dir(client)?,
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}();
|
||||
}
|
||||
|
||||
fn get_module_fds(&self, is_64_bit: bool) -> Option<Vec<RawFd>> {
|
||||
|
||||
Reference in New Issue
Block a user