Minor cleanup

This commit is contained in:
topjohnwu 2023-12-03 19:32:58 +08:00
parent 4e99997013
commit 1dcf325547
6 changed files with 38 additions and 44 deletions

View File

@ -132,12 +132,12 @@ const MagiskD &MagiskD::get() {
return *reinterpret_cast<const MagiskD*>(&rust::get_magiskd()); return *reinterpret_cast<const MagiskD*>(&rust::get_magiskd());
} }
const rust::MagiskD &MagiskD::as_rust() const { const rust::MagiskD *MagiskD::operator->() const {
return *reinterpret_cast<const rust::MagiskD*>(this); return reinterpret_cast<const rust::MagiskD*>(this);
} }
void MagiskD::boot_stage_handler(int client, int code) const { const rust::MagiskD &MagiskD::as_rust() const {
as_rust().boot_stage_handler(client, code); return *operator->();
} }
void MagiskD::reboot() const { void MagiskD::reboot() const {
@ -196,7 +196,7 @@ static void handle_request_sync(int client, int code) {
write_int(client, MAGISK_VER_CODE); write_int(client, MAGISK_VER_CODE);
break; break;
case +RequestCode::START_DAEMON: case +RequestCode::START_DAEMON:
rust::get_magiskd().setup_logfile(); MagiskD::get()->setup_logfile();
break; break;
case +RequestCode::STOP_DAEMON: { case +RequestCode::STOP_DAEMON: {
// Unmount all overlays // Unmount all overlays
@ -298,7 +298,7 @@ static void handle_request(pollfd *pfd) {
exec_task([=, fd = client.release()] { handle_request_async(fd, code, cred); }); exec_task([=, fd = client.release()] { handle_request_async(fd, code, cred); });
} else { } else {
exec_task([=, fd = client.release()] { exec_task([=, fd = client.release()] {
MagiskD::get().boot_stage_handler(fd, code); MagiskD::get()->boot_stage_handler(fd, code);
}); });
} }
} }

View File

@ -97,16 +97,8 @@ impl MagiskD {
} }
} }
mod cxx_extern {
use base::libc::c_char;
extern "C" {
pub fn get_magisk_tmp() -> *const c_char;
}
}
pub fn get_magisk_tmp() -> &'static Utf8CStr { pub fn get_magisk_tmp() -> &'static Utf8CStr {
unsafe { Utf8CStr::from_ptr(cxx_extern::get_magisk_tmp()).unwrap_unchecked() } unsafe { Utf8CStr::from_ptr(super::ffi::get_magisk_tmp()).unwrap_unchecked() }
} }
pub fn daemon_entry() { pub fn daemon_entry() {

View File

@ -116,7 +116,7 @@ db_settings::db_settings() {
data[SU_MULTIUSER_MODE] = MULTIUSER_MODE_OWNER_ONLY; data[SU_MULTIUSER_MODE] = MULTIUSER_MODE_OWNER_ONLY;
data[SU_MNT_NS] = NAMESPACE_MODE_REQUESTER; data[SU_MNT_NS] = NAMESPACE_MODE_REQUESTER;
data[DENYLIST_CONFIG] = false; data[DENYLIST_CONFIG] = false;
data[ZYGISK_CONFIG] = rust::get_magiskd().is_emulator(); data[ZYGISK_CONFIG] = MagiskD::get()->is_emulator();
} }
int db_settings::get_idx(string_view key) const { int db_settings::get_idx(string_view key) const {

View File

@ -8,6 +8,7 @@
#include <functional> #include <functional>
#include "socket.hpp" #include "socket.hpp"
#include "../core-rs.hpp"
#define AID_ROOT 0 #define AID_ROOT 0
#define AID_SHELL 2000 #define AID_SHELL 2000
@ -18,28 +19,6 @@
#define to_app_id(uid) (uid % AID_USER_OFFSET) #define to_app_id(uid) (uid % AID_USER_OFFSET)
#define to_user_id(uid) (uid / AID_USER_OFFSET) #define to_user_id(uid) (uid / AID_USER_OFFSET)
namespace rust {
struct MagiskD;
}
struct MagiskD {
// Make sure only references can exist
~MagiskD() = delete;
// Binding to Rust
static const MagiskD &get();
void boot_stage_handler(int client, int code) const;
// C++ implementation
void reboot() const;
bool post_fs_data() const;
void late_start() const;
void boot_complete() const;
private:
const rust::MagiskD &as_rust() const;
};
// Return codes for daemon // Return codes for daemon
enum class RespondCode : int { enum class RespondCode : int {
ERROR = -1, ERROR = -1,
@ -61,11 +40,9 @@ extern bool zygisk_enabled;
extern std::vector<module_info> *module_list; extern std::vector<module_info> *module_list;
void reset_zygisk(bool restore); void reset_zygisk(bool restore);
extern "C" const char *get_magisk_tmp();
int connect_daemon(int req, bool create = false); int connect_daemon(int req, bool create = false);
std::string find_preinit_device(); std::string find_preinit_device();
void unlock_blocks(); void unlock_blocks();
void reboot();
// Poll control // Poll control
using poll_callback = void(*)(pollfd*); using poll_callback = void(*)(pollfd*);
@ -115,6 +92,3 @@ int denylist_cli(int argc, char **argv);
void initialize_denylist(); void initialize_denylist();
bool is_deny_target(int uid, std::string_view process); bool is_deny_target(int uid, std::string_view process);
void revert_unmount(); void revert_unmount();
// Include last to prevent recursive include issues
#include "../core-rs.hpp"

View File

@ -0,0 +1,26 @@
#pragma once
namespace rust {
struct MagiskD;
}
struct MagiskD {
// Make sure only references can exist
~MagiskD() = delete;
// Binding to Rust
static const MagiskD &get();
// C++ implementation
void reboot() const;
bool post_fs_data() const;
void late_start() const;
void boot_complete() const;
const rust::MagiskD *operator->() const;
private:
const rust::MagiskD &as_rust() const;
};
const char *get_magisk_tmp();

View File

@ -53,7 +53,9 @@ pub mod ffi {
} }
unsafe extern "C++" { unsafe extern "C++" {
include!("include/core.hpp"); include!("include/daemon.hpp");
fn get_magisk_tmp() -> *const c_char;
#[cxx_name = "MagiskD"] #[cxx_name = "MagiskD"]
type CxxMagiskD; type CxxMagiskD;