mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-03-22 22:50:51 +00:00
Cleanup xwrap functions
This commit is contained in:
parent
8e73536e02
commit
95d3eac2e0
@ -15,7 +15,6 @@ int xopenat(int dirfd, const char *pathname, int flags, mode_t mode = 0);
|
||||
ssize_t xwrite(int fd, const void *buf, size_t count);
|
||||
ssize_t xread(int fd, void *buf, size_t count);
|
||||
ssize_t xxread(int fd, void *buf, size_t count);
|
||||
off64_t xlseek64(int fd, off64_t offset, int whence);
|
||||
int xsetns(int fd, int nstype);
|
||||
int xunshare(int flags);
|
||||
DIR *xopendir(const char *name);
|
||||
@ -26,33 +25,22 @@ 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);
|
||||
ssize_t xsendmsg(int sockfd, const struct msghdr *msg, int flags);
|
||||
ssize_t xrecvmsg(int sockfd, struct msghdr *msg, int flags);
|
||||
int xaccess(const char *path, int mode);
|
||||
int xfaccessat(int dirfd, const char *pathname, int mode, int flags);
|
||||
int xstat(const char *pathname, struct stat *buf);
|
||||
int xlstat(const char *pathname, struct stat *buf);
|
||||
int xfstat(int fd, struct stat *buf);
|
||||
int xfstatat(int dirfd, const char *pathname, struct stat *buf, int flags);
|
||||
int xdup(int fd);
|
||||
int xdup2(int oldfd, int newfd);
|
||||
int xdup3(int oldfd, int newfd, int flags);
|
||||
ssize_t xreadlink(const char * __restrict__ pathname, char * __restrict__ buf, size_t bufsiz);
|
||||
ssize_t xreadlinkat(
|
||||
int dirfd, const char * __restrict__ pathname, char * __restrict__ buf, size_t bufsiz);
|
||||
int xsymlink(const char *target, const char *linkpath);
|
||||
int xsymlinkat(const char *target, int newdirfd, const char *linkpath);
|
||||
int xlinkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags);
|
||||
int xmount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data);
|
||||
int xumount(const char *target);
|
||||
int xumount2(const char *target, int flags);
|
||||
int xrename(const char *oldpath, const char *newpath);
|
||||
int xmkdir(const char *pathname, mode_t mode);
|
||||
int xmkdirs(const char *pathname, mode_t mode);
|
||||
int xmkdirat(int dirfd, const char *pathname, mode_t mode);
|
||||
void *xmmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
|
||||
ssize_t xsendfile(int out_fd, int in_fd, off_t *offset, size_t count);
|
||||
pid_t xfork();
|
||||
int xpoll(pollfd *fds, nfds_t nfds, int timeout);
|
||||
|
@ -2,15 +2,14 @@
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::ptr;
|
||||
|
||||
use libc::{
|
||||
c_char, c_uint, c_ulong, c_void, dev_t, mode_t, nfds_t, off_t, pollfd, sockaddr, socklen_t,
|
||||
ssize_t, SYS_dup3,
|
||||
ssize_t,
|
||||
};
|
||||
|
||||
use crate::cxx_extern::readlinkat_for_cxx;
|
||||
use crate::{errno, raw_cstr, CxxResultExt, FsPath, Utf8CStr, Utf8CStrBufRef};
|
||||
use crate::{CxxResultExt, FsPath, Utf8CStr, Utf8CStrBufRef, errno, raw_cstr};
|
||||
|
||||
fn ptr_to_str<'a, T>(ptr: *const T) -> &'a str {
|
||||
if ptr.is_null() {
|
||||
@ -222,17 +221,6 @@ fn xxread(fd: RawFd, data: &mut [u8]) -> isize {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn xlseek64(fd: RawFd, offset: i64, whence: i32) -> i64 {
|
||||
unsafe {
|
||||
let r = libc::lseek64(fd, offset, whence);
|
||||
if r < 0 {
|
||||
perror!("lseek64");
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn xpipe2(fds: &mut [i32; 2], flags: i32) -> i32 {
|
||||
unsafe {
|
||||
let r = libc::pipe2(fds.as_mut_ptr(), flags);
|
||||
@ -369,28 +357,6 @@ unsafe extern "C" fn xaccept4(
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xsendmsg(fd: RawFd, msg: *const libc::msghdr, flags: i32) -> ssize_t {
|
||||
unsafe {
|
||||
let r = libc::sendmsg(fd, msg, flags);
|
||||
if r < 0 {
|
||||
perror!("sendmsg");
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xrecvmsg(fd: RawFd, msg: *mut libc::msghdr, flags: i32) -> ssize_t {
|
||||
unsafe {
|
||||
let r = libc::recvmsg(fd, msg, flags);
|
||||
if r < 0 {
|
||||
perror!("recvmsg");
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xaccess(path: *const c_char, mode: i32) -> i32 {
|
||||
unsafe {
|
||||
@ -402,22 +368,6 @@ unsafe extern "C" fn xaccess(path: *const c_char, mode: i32) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xfaccessat(dirfd: RawFd, path: *const c_char, mode: i32, flags: i32) -> i32 {
|
||||
unsafe {
|
||||
#[allow(unused_mut)]
|
||||
let mut r = libc::faccessat(dirfd, path, mode, flags);
|
||||
if r < 0 {
|
||||
perror!("faccessat {}", ptr_to_str(path));
|
||||
}
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
if r > 0 && *errno() == 0 {
|
||||
r = 0
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xstat(path: *const c_char, buf: *mut libc::stat) -> i32 {
|
||||
unsafe {
|
||||
@ -429,17 +379,6 @@ unsafe extern "C" fn xstat(path: *const c_char, buf: *mut libc::stat) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xlstat(path: *const c_char, buf: *mut libc::stat) -> i32 {
|
||||
unsafe {
|
||||
let r = libc::lstat(path, buf);
|
||||
if r < 0 {
|
||||
perror!("lstat {}", ptr_to_str(path));
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xfstat(fd: RawFd, buf: *mut libc::stat) -> i32 {
|
||||
unsafe {
|
||||
@ -451,22 +390,6 @@ unsafe extern "C" fn xfstat(fd: RawFd, buf: *mut libc::stat) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xfstatat(
|
||||
dirfd: RawFd,
|
||||
path: *const c_char,
|
||||
buf: *mut libc::stat,
|
||||
flags: i32,
|
||||
) -> i32 {
|
||||
unsafe {
|
||||
let r = libc::fstatat(dirfd, path, buf, flags);
|
||||
if r < 0 {
|
||||
perror!("fstatat {}", ptr_to_str(path));
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn xdup(oldfd: RawFd) -> RawFd {
|
||||
unsafe {
|
||||
@ -489,17 +412,6 @@ extern "C" fn xdup2(oldfd: RawFd, newfd: RawFd) -> RawFd {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn xdup3(oldfd: RawFd, newfd: RawFd, flags: i32) -> RawFd {
|
||||
unsafe {
|
||||
let fd = libc::syscall(SYS_dup3, oldfd, newfd, flags) as RawFd;
|
||||
if fd < 0 {
|
||||
perror!("dup3");
|
||||
}
|
||||
fd
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xsymlink(target: *const c_char, linkpath: *const c_char) -> i32 {
|
||||
unsafe {
|
||||
@ -511,42 +423,6 @@ unsafe extern "C" fn xsymlink(target: *const c_char, linkpath: *const c_char) ->
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xsymlinkat(
|
||||
target: *const c_char,
|
||||
dirfd: RawFd,
|
||||
linkpath: *const c_char,
|
||||
) -> i32 {
|
||||
unsafe {
|
||||
let r = libc::symlinkat(target, dirfd, linkpath);
|
||||
if r < 0 {
|
||||
perror!(
|
||||
"symlinkat {} -> {}",
|
||||
ptr_to_str(target),
|
||||
ptr_to_str(linkpath)
|
||||
);
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xlinkat(
|
||||
olddirfd: RawFd,
|
||||
target: *const c_char,
|
||||
newdirfd: RawFd,
|
||||
linkpath: *const c_char,
|
||||
flags: i32,
|
||||
) -> i32 {
|
||||
unsafe {
|
||||
let r = libc::linkat(olddirfd, target, newdirfd, linkpath, flags);
|
||||
if r < 0 {
|
||||
perror!("linkat {} -> {}", ptr_to_str(target), ptr_to_str(linkpath));
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xmount(
|
||||
src: *const c_char,
|
||||
@ -564,17 +440,6 @@ unsafe extern "C" fn xmount(
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xumount(target: *const c_char) -> i32 {
|
||||
unsafe {
|
||||
let r = libc::umount(target);
|
||||
if r < 0 {
|
||||
perror!("umount {}", ptr_to_str(target));
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xumount2(target: *const c_char, flags: i32) -> i32 {
|
||||
unsafe {
|
||||
@ -621,17 +486,6 @@ unsafe extern "C" fn xmkdirs(path: *const c_char, mode: mode_t) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xmkdirat(dirfd: RawFd, path: *const c_char, mode: mode_t) -> i32 {
|
||||
unsafe {
|
||||
let r = libc::mkdirat(dirfd, path, mode);
|
||||
if r < 0 && *errno() != libc::EEXIST {
|
||||
perror!("mkdirat {}", ptr_to_str(path));
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xsendfile(
|
||||
out_fd: RawFd,
|
||||
@ -648,25 +502,6 @@ unsafe extern "C" fn xsendfile(
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn xmmap(
|
||||
addr: *mut c_void,
|
||||
len: usize,
|
||||
prot: i32,
|
||||
flags: i32,
|
||||
fd: RawFd,
|
||||
offset: off_t,
|
||||
) -> *mut c_void {
|
||||
unsafe {
|
||||
let r = libc::mmap(addr, len, prot, flags, fd, offset);
|
||||
if r == libc::MAP_FAILED {
|
||||
perror!("mmap");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn xfork() -> i32 {
|
||||
unsafe {
|
||||
|
Loading…
x
Reference in New Issue
Block a user