mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-12 15:04:47 +00:00
Implement logging purely in Rust
This commit is contained in:
9
native/src/base/consts.rs
Normal file
9
native/src/base/consts.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
// We expose constant values as macros so that all constants are literals
|
||||
// An advantage for doing this is that we can use concat!() on these values
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! LOGFILE {
|
||||
() => {
|
||||
"/cache/magisk.log"
|
||||
};
|
||||
}
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
pub use libc;
|
||||
|
||||
pub use consts::*;
|
||||
pub use files::*;
|
||||
pub use logging::*;
|
||||
pub use misc::*;
|
||||
pub use xwrap::*;
|
||||
|
||||
mod consts;
|
||||
mod files;
|
||||
mod logging;
|
||||
mod misc;
|
||||
|
||||
@@ -130,7 +130,7 @@ uint64_t parse_uint64_hex(std::string_view s);
|
||||
int parse_int(std::string_view s);
|
||||
|
||||
using thread_entry = void *(*)(void *);
|
||||
int new_daemon_thread(thread_entry entry, void *arg = nullptr);
|
||||
extern "C" int new_daemon_thread(thread_entry entry, void *arg = nullptr);
|
||||
|
||||
static inline bool str_contains(std::string_view s, std::string_view ss) {
|
||||
return s.find(ss) != std::string::npos;
|
||||
|
||||
@@ -151,3 +151,24 @@ pub unsafe fn slice_from_ptr_mut<'a, T>(buf: *mut T, len: usize) -> &'a mut [T]
|
||||
slice::from_raw_parts_mut(buf, len)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FlatData {
|
||||
fn as_raw_bytes(&self) -> &[u8]
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
unsafe {
|
||||
let self_ptr = self as *const Self as *const u8;
|
||||
slice::from_raw_parts(self_ptr, std::mem::size_of::<Self>())
|
||||
}
|
||||
}
|
||||
fn as_raw_bytes_mut(&mut self) -> &mut [u8]
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
unsafe {
|
||||
let self_ptr = self as *mut Self as *mut u8;
|
||||
slice::from_raw_parts_mut(self_ptr, std::mem::size_of::<Self>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user