Reduce FFI across C++/Rust

This commit is contained in:
topjohnwu
2025-09-02 11:11:12 -07:00
committed by John Wu
parent 675b5f9565
commit bd657c354c
10 changed files with 127 additions and 158 deletions

View File

@@ -11,7 +11,7 @@ use num_traits::FromPrimitive;
use std::ffi::c_void;
use std::fs::File;
use std::io::{BufReader, BufWriter};
use std::os::fd::{FromRawFd, OwnedFd, RawFd};
use std::os::fd::OwnedFd;
use std::pin::Pin;
use std::ptr;
use std::ptr::NonNull;
@@ -302,7 +302,7 @@ impl MagiskD {
.sql_result()
}
fn db_exec_for_client(&self, fd: OwnedFd) -> LoggedResult<()> {
pub fn db_exec_for_cli(&self, fd: OwnedFd) -> LoggedResult<()> {
let mut file = File::from(fd);
let mut reader = BufReader::new(&mut file);
let sql: String = reader.read_decodable()?;
@@ -328,12 +328,6 @@ impl MagiskD {
pub fn set_db_setting_for_cxx(&self, key: DbEntryKey, value: i32) -> bool {
self.set_db_setting(key, value).log().is_ok()
}
pub fn db_exec_for_cxx(&self, client_fd: RawFd) {
// Take ownership
let fd = unsafe { OwnedFd::from_raw_fd(client_fd) };
self.db_exec_for_client(fd).ok();
}
}
#[unsafe(export_name = "sql_exec_rs")]