From 3cda9beb934d581258bdc4efd6220bf3ce62b06e Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 24 Sep 2025 02:38:18 -0700 Subject: [PATCH] Cleanup unused bindings --- native/src/base/xwrap.hpp | 4 ---- native/src/base/xwrap.rs | 47 +------------------------------------- native/src/core/lib.rs | 7 ++---- native/src/core/selinux.rs | 4 ---- 4 files changed, 3 insertions(+), 59 deletions(-) diff --git a/native/src/base/xwrap.hpp b/native/src/base/xwrap.hpp index 4e8ff28fb..d037386ab 100644 --- a/native/src/base/xwrap.hpp +++ b/native/src/base/xwrap.hpp @@ -21,10 +21,6 @@ DIR *xopendir(const char *name); DIR *xfdopendir(int fd); dirent *xreaddir(DIR *dirp); pid_t xsetsid(); -int xsocket(int domain, int type, int protocol); -int xbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); -int xlisten(int sockfd, int backlog); -int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); int xstat(const char *pathname, struct stat *buf); int xfstat(int fd, struct stat *buf); int xdup2(int oldfd, int newfd); diff --git a/native/src/base/xwrap.rs b/native/src/base/xwrap.rs index b5b6c4f7a..496a5868a 100644 --- a/native/src/base/xwrap.rs +++ b/native/src/base/xwrap.rs @@ -2,7 +2,7 @@ use crate::cxx_extern::readlinkat; use crate::{Directory, LibcReturn, ResultExt, Utf8CStr, cstr, slice_from_ptr, slice_from_ptr_mut}; -use libc::{c_char, c_uint, c_ulong, c_void, dev_t, mode_t, off_t, sockaddr, socklen_t}; +use libc::{c_char, c_uint, c_ulong, c_void, dev_t, mode_t, off_t}; use std::ffi::CStr; use std::fs::File; use std::io::{Read, Write}; @@ -201,51 +201,6 @@ extern "C" fn xsetsid() -> i32 { } } -#[unsafe(no_mangle)] -extern "C" fn xsocket(domain: i32, ty: i32, protocol: i32) -> RawFd { - unsafe { - libc::socket(domain, ty, protocol) - .into_os_result("socket", None, None) - .log() - .unwrap_or(-1) - } -} - -#[unsafe(no_mangle)] -unsafe extern "C" fn xbind(socket: i32, address: *const sockaddr, len: socklen_t) -> i32 { - unsafe { - libc::bind(socket, address, len) - .into_os_result("bind", None, None) - .log() - .unwrap_or(-1) - } -} - -#[unsafe(no_mangle)] -extern "C" fn xlisten(socket: i32, backlog: i32) -> i32 { - unsafe { - libc::listen(socket, backlog) - .into_os_result("listen", None, None) - .log() - .unwrap_or(-1) - } -} - -#[unsafe(no_mangle)] -unsafe extern "C" fn xaccept4( - sockfd: RawFd, - addr: *mut sockaddr, - len: *mut socklen_t, - flg: i32, -) -> RawFd { - unsafe { - libc::accept4(sockfd, addr, len, flg) - .into_os_result("accept4", None, None) - .log() - .unwrap_or(-1) - } -} - #[unsafe(no_mangle)] unsafe extern "C" fn xstat(path: *const c_char, buf: *mut libc::stat) -> i32 { unsafe { diff --git a/native/src/core/lib.rs b/native/src/core/lib.rs index 111f11cf5..90cf0d465 100644 --- a/native/src/core/lib.rs +++ b/native/src/core/lib.rs @@ -13,9 +13,9 @@ use daemon::{MagiskD, connect_daemon_for_cxx}; use derive::Decodable; use logging::{android_logging, zygisk_close_logd, zygisk_get_logd, zygisk_logging}; use magisk::magisk_main; -use mount::{find_preinit_device, revert_unmount}; +use mount::revert_unmount; use resetprop::{get_prop, resetprop_main}; -use selinux::{lgetfilecon, lsetfilecon, restorecon, setfilecon}; +use selinux::{lgetfilecon, setfilecon}; use socket::{recv_fd, recv_fds, send_fd}; use std::fs::File; use std::mem::ManuallyDrop; @@ -187,7 +187,6 @@ pub mod ffi { fn zygisk_logging(); fn zygisk_close_logd(); fn zygisk_get_logd() -> i32; - fn find_preinit_device() -> String; fn revert_unmount(pid: i32); fn zygisk_should_load_module(flags: u32) -> bool; fn send_fd(socket: i32, fd: i32) -> bool; @@ -196,10 +195,8 @@ pub mod ffi { fn write_to_fd(self: &SuRequest, fd: i32); fn pump_tty(ptmx: i32, pump_stdin: bool); fn get_pty_num(fd: i32) -> i32; - fn restorecon(); fn lgetfilecon(path: Utf8CStrRef, con: &mut [u8]) -> bool; fn setfilecon(path: Utf8CStrRef, con: Utf8CStrRef) -> bool; - fn lsetfilecon(path: Utf8CStrRef, con: Utf8CStrRef) -> bool; fn get_prop(name: Utf8CStrRef) -> String; unsafe fn resetprop_main(argc: i32, argv: *mut *mut c_char) -> i32; diff --git a/native/src/core/selinux.rs b/native/src/core/selinux.rs index 6fcc87f24..de0c5ec54 100644 --- a/native/src/core/selinux.rs +++ b/native/src/core/selinux.rs @@ -104,7 +104,3 @@ pub(crate) fn lgetfilecon(path: &Utf8CStr, con: &mut [u8]) -> bool { pub(crate) fn setfilecon(path: &Utf8CStr, con: &Utf8CStr) -> bool { path.follow_link().set_secontext(con).is_ok() } - -pub(crate) fn lsetfilecon(path: &Utf8CStr, con: &Utf8CStr) -> bool { - path.set_secontext(con).is_ok() -}