mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-29 22:14:27 +02:00
Make sure IPC is arch agnostic
This commit is contained in:
parent
0469817781
commit
88628fdf3c
@ -151,7 +151,7 @@ bool get_client_cred(int fd, sock_cred *cred) {
|
||||
|
||||
bool read_string(int fd, std::string &str) {
|
||||
str.clear();
|
||||
auto len = read_any<size_t>(fd);
|
||||
int len = read_int(fd);
|
||||
str.resize(len);
|
||||
return xxread(fd, str.data(), len) == len;
|
||||
}
|
||||
@ -164,7 +164,7 @@ string read_string(int fd) {
|
||||
|
||||
void write_string(int fd, string_view str) {
|
||||
if (fd < 0) return;
|
||||
write_any(fd, str.size());
|
||||
write_int(fd, str.size());
|
||||
xwrite(fd, str.data(), str.size());
|
||||
}
|
||||
|
||||
|
@ -59,19 +59,6 @@ void write_any(int fd, T val) {
|
||||
xwrite(fd, &val, sizeof(val));
|
||||
}
|
||||
|
||||
template<typename T> requires(std::is_trivially_copyable_v<T>)
|
||||
void write_vector(int fd, const std::vector<T> &vec) {
|
||||
write_any(fd, vec.size());
|
||||
xwrite(fd, vec.data(), vec.size() * sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T> requires(std::is_trivially_copyable_v<T>)
|
||||
bool read_vector(int fd, std::vector<T> &vec) {
|
||||
auto size = read_any<size_t>(fd);
|
||||
vec.resize(size);
|
||||
return xread(fd, vec.data(), size * sizeof(T)) == size * sizeof(T);
|
||||
}
|
||||
|
||||
bool get_client_cred(int fd, sock_cred *cred);
|
||||
static inline int read_int(int fd) { return read_any<int>(fd); }
|
||||
static inline void write_int(int fd, int val) { write_any(fd, val); }
|
||||
@ -79,6 +66,19 @@ std::string read_string(int fd);
|
||||
bool read_string(int fd, std::string &str);
|
||||
void write_string(int fd, std::string_view str);
|
||||
|
||||
template<typename T> requires(std::is_trivially_copyable_v<T>)
|
||||
void write_vector(int fd, const std::vector<T> &vec) {
|
||||
write_int(fd, vec.size());
|
||||
xwrite(fd, vec.data(), vec.size() * sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T> requires(std::is_trivially_copyable_v<T>)
|
||||
bool read_vector(int fd, std::vector<T> &vec) {
|
||||
int size = read_int(fd);
|
||||
vec.resize(size);
|
||||
return xread(fd, vec.data(), size * sizeof(T)) == size * sizeof(T);
|
||||
}
|
||||
|
||||
// Poll control
|
||||
using poll_callback = void(*)(pollfd*);
|
||||
void register_poll(const pollfd *pfd, poll_callback callback);
|
||||
|
@ -65,19 +65,19 @@ impl Decodable for bool {
|
||||
|
||||
impl<T: Decodable> Encodable for Vec<T> {
|
||||
fn encoded_len(&self) -> usize {
|
||||
size_of::<usize>() + size_of::<T>() * self.len()
|
||||
size_of::<i32>() + size_of::<T>() * self.len()
|
||||
}
|
||||
|
||||
fn encode(&self, w: &mut impl Write) -> io::Result<()> {
|
||||
self.len().encode(w)?;
|
||||
(self.len() as i32).encode(w)?;
|
||||
self.iter().try_for_each(|e| e.encode(w))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Decodable> Decodable for Vec<T> {
|
||||
fn decode(r: &mut impl Read) -> io::Result<Self> {
|
||||
let len = usize::decode(r)?;
|
||||
let mut val = Vec::with_capacity(len);
|
||||
let len = i32::decode(r)?;
|
||||
let mut val = Vec::with_capacity(len as usize);
|
||||
for _ in 0..len {
|
||||
val.push(T::decode(r)?);
|
||||
}
|
||||
@ -87,11 +87,11 @@ impl<T: Decodable> Decodable for Vec<T> {
|
||||
|
||||
impl Encodable for str {
|
||||
fn encoded_len(&self) -> usize {
|
||||
size_of::<usize>() + self.len()
|
||||
size_of::<i32>() + self.len()
|
||||
}
|
||||
|
||||
fn encode(&self, w: &mut impl Write) -> io::Result<()> {
|
||||
self.len().encode(w)?;
|
||||
(self.len() as i32).encode(w)?;
|
||||
w.write_all(self.as_bytes())
|
||||
}
|
||||
}
|
||||
@ -108,10 +108,9 @@ impl Encodable for String {
|
||||
|
||||
impl Decodable for String {
|
||||
fn decode(r: &mut impl Read) -> io::Result<String> {
|
||||
let len = usize::decode(r)?;
|
||||
let mut val = String::with_capacity(len);
|
||||
let mut r = r.take(len as u64);
|
||||
r.read_to_string(&mut val)?;
|
||||
let len = i32::decode(r)?;
|
||||
let mut val = String::with_capacity(len as usize);
|
||||
r.take(len as u64).read_to_string(&mut val)?;
|
||||
Ok(val)
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ pub fn zygisk_should_load_module(flags: u32) -> bool {
|
||||
flags & UNMOUNT_MASK != UNMOUNT_MASK && flags & ZygiskStateFlags::ProcessIsMagiskApp.repr == 0
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn exec_zygiskd(is_64_bit: bool, remote: UnixStream) {
|
||||
// This fd has to survive exec
|
||||
unsafe {
|
||||
|
Loading…
x
Reference in New Issue
Block a user