From 70cc531e7873fc7419b996228c1257446668f40c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jul 2026 03:46:54 +0000 Subject: [PATCH 1/2] Update syn requirement from 2 to 3 Updates the requirements on [syn](https://github.com/dtolnay/syn) to permit the latest version. - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](https://github.com/dtolnay/syn/compare/2.0.0...3.0.1) --- updated-dependencies: - dependency-name: syn dependency-version: 3.0.1 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 221add9c..b92d2355 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,5 +58,5 @@ num_cpus = "1" uuid = "1" tempfile = "3" cc = "1" -syn = "2" +syn = "3" quote = "1" From d0bda44bcc60d6de1cd76943bb98f2625b164800 Mon Sep 17 00:00:00 2001 From: loongs-zhang <1936978077@qq.com> Date: Fri, 11 Sep 2026 03:14:31 +0800 Subject: [PATCH 2/2] fix clippy --- core/src/coroutine/listener.rs | 91 +++++++++-------- core/src/net/event_loop.rs | 58 +++++++++-- core/src/net/mod.rs | 58 +++++++++-- hook/src/syscall/unix.rs | 179 +++++++++++++++++++++++++++------ hook/src/syscall/windows.rs | 160 +++++++++++++++++++++++++---- 5 files changed, 442 insertions(+), 104 deletions(-) diff --git a/core/src/coroutine/listener.rs b/core/src/coroutine/listener.rs index ce94f35b..6ce44a4e 100644 --- a/core/src/coroutine/listener.rs +++ b/core/src/coroutine/listener.rs @@ -50,7 +50,7 @@ pub trait Listener: Debug { } macro_rules! broadcast { - ($impl_method_name: ident($($arg: ident : $arg_type: ty),*), $method_name:expr) => { + ($impl_method_name: ident($($arg: ident : $arg_type: ty),* $(,)?), $method_name:expr) => { fn $impl_method_name(&self, $($arg: $arg_type),*) { for listener in &self.listeners { _ = $crate::catch!( @@ -68,46 +68,51 @@ where Yield: Debug + Copy, Return: Debug + Copy, { - broadcast!(on_state_changed( - local: &CoroutineLocal, - old_state: CoroutineState, - new_state: CoroutineState - ), "on_state_changed"); - - broadcast!(on_ready( - local: &CoroutineLocal, - old_state: CoroutineState - ), "on_ready"); - - broadcast!(on_running( - local: &CoroutineLocal, - old_state: CoroutineState - ), "on_running"); - - broadcast!(on_suspend( - local: &CoroutineLocal, - old_state: CoroutineState - ), "on_suspend"); - - broadcast!(on_syscall( - local: &CoroutineLocal, - old_state: CoroutineState - ), "on_syscall"); - - broadcast!(on_cancel( - local: &CoroutineLocal, - old_state: CoroutineState - ), "on_cancel"); - - broadcast!(on_complete( - local: &CoroutineLocal, - old_state: CoroutineState, - result: Return - ), "on_complete"); - - broadcast!(on_error( - local: &CoroutineLocal, - old_state: CoroutineState, - message: &str - ), "on_error"); + broadcast!( + on_state_changed( + local: &CoroutineLocal, + old_state: CoroutineState, + new_state: CoroutineState, + ), + "on_state_changed" + ); + + broadcast!( + on_ready(local: &CoroutineLocal, old_state: CoroutineState), + "on_ready" + ); + + broadcast!( + on_running(local: &CoroutineLocal, old_state: CoroutineState), + "on_running" + ); + + broadcast!( + on_suspend(local: &CoroutineLocal, old_state: CoroutineState), + "on_suspend" + ); + + broadcast!( + on_syscall(local: &CoroutineLocal, old_state: CoroutineState), + "on_syscall" + ); + + broadcast!( + on_cancel(local: &CoroutineLocal, old_state: CoroutineState), + "on_cancel" + ); + + broadcast!( + on_complete( + local: &CoroutineLocal, + old_state: CoroutineState, + result: Return, + ), + "on_complete" + ); + + broadcast!( + on_error(local: &CoroutineLocal, old_state: CoroutineState, message: &str), + "on_error" + ); } diff --git a/core/src/net/event_loop.rs b/core/src/net/event_loop.rs index c45c21d1..5247a80d 100644 --- a/core/src/net/event_loop.rs +++ b/core/src/net/event_loop.rs @@ -492,7 +492,7 @@ impl_current_for!(EVENT_LOOP, EventLoop<'e>); impl_display_by_debug!(EventLoop<'e>); macro_rules! impl_io_uring { - ( $syscall: ident($($arg: ident : $arg_type: ty),*) -> $result: ty ) => { + ( $syscall: ident($($arg: ident : $arg_type: ty),* $(,)?) -> $result: ty ) => { #[cfg(all(target_os = "linux", feature = "io_uring"))] impl EventLoop<'_> { pub(super) fn $syscall( @@ -526,7 +526,16 @@ impl_io_uring!(readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t); impl_io_uring!(preadv(fd: c_int, iov: *const iovec, iovcnt: c_int, offset: off_t) -> ssize_t); impl_io_uring!(recvmsg(fd: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t); impl_io_uring!(send(fd: c_int, buf: *const c_void, len: size_t, flags: c_int) -> ssize_t); -impl_io_uring!(sendto(fd: c_int, buf: *const c_void, len: size_t, flags: c_int, addr: *const sockaddr, addrlen: socklen_t) -> ssize_t); +impl_io_uring!( + sendto( + fd: c_int, + buf: *const c_void, + len: size_t, + flags: c_int, + addr: *const sockaddr, + addrlen: socklen_t, + ) -> ssize_t +); impl_io_uring!(write(fd: c_int, buf: *const c_void, count: size_t) -> ssize_t); impl_io_uring!(pwrite(fd: c_int, buf: *const c_void, count: size_t, offset: off_t) -> ssize_t); impl_io_uring!(writev(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t); @@ -534,11 +543,26 @@ impl_io_uring!(pwritev(fd: c_int, iov: *const iovec, iovcnt: c_int, offset: off_ impl_io_uring!(sendmsg(fd: c_int, msg: *const msghdr, flags: c_int) -> ssize_t); impl_io_uring!(fsync(fd: c_int) -> c_int); impl_io_uring!(mkdirat(dirfd: c_int, pathname: *const c_char, mode: mode_t) -> c_int); -impl_io_uring!(renameat(olddirfd: c_int, oldpath: *const c_char, newdirfd: c_int, newpath: *const c_char) -> c_int); -impl_io_uring!(renameat2(olddirfd: c_int, oldpath: *const c_char, newdirfd: c_int, newpath: *const c_char, flags: c_uint) -> c_int); +impl_io_uring!( + renameat( + olddirfd: c_int, + oldpath: *const c_char, + newdirfd: c_int, + newpath: *const c_char, + ) -> c_int +); +impl_io_uring!( + renameat2( + olddirfd: c_int, + oldpath: *const c_char, + newdirfd: c_int, + newpath: *const c_char, + flags: c_uint, + ) -> c_int +); macro_rules! impl_iocp { - ( $syscall: ident($($arg: ident : $arg_type: ty),*) -> $result: ty ) => { + ( $syscall: ident($($arg: ident : $arg_type: ty),* $(,)?) -> $result: ty ) => { #[cfg(all(windows, feature = "iocp"))] impl EventLoop<'_> { #[allow(non_snake_case, clippy::too_many_arguments)] @@ -561,9 +585,29 @@ macro_rules! impl_iocp { impl_iocp!(accept(fd: SOCKET, addr: *mut SOCKADDR, len: *mut c_int) -> c_int); impl_iocp!(recv(fd: SOCKET, buf: PSTR, len: c_int, flags: SEND_RECV_FLAGS) -> c_int); -impl_iocp!(WSARecv(fd: SOCKET, buf: *const WSABUF, dwbuffercount: c_uint, lpnumberofbytesrecvd: *mut c_uint, lpflags : *mut c_uint, lpoverlapped: *mut OVERLAPPED, lpcompletionroutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> c_int); +impl_iocp!( + WSARecv( + fd: SOCKET, + buf: *const WSABUF, + dwbuffercount: c_uint, + lpnumberofbytesrecvd: *mut c_uint, + lpflags: *mut c_uint, + lpoverlapped: *mut OVERLAPPED, + lpcompletionroutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE, + ) -> c_int +); impl_iocp!(send(fd: SOCKET, buf: PCSTR, len: c_int, flags: SEND_RECV_FLAGS) -> c_int); -impl_iocp!(WSASend(fd: SOCKET, buf: *const WSABUF, dwbuffercount: c_uint, lpnumberofbytesrecvd: *mut c_uint, dwflags : c_uint, lpoverlapped: *mut OVERLAPPED, lpcompletionroutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> c_int); +impl_iocp!( + WSASend( + fd: SOCKET, + buf: *const WSABUF, + dwbuffercount: c_uint, + lpnumberofbytesrecvd: *mut c_uint, + dwflags: c_uint, + lpoverlapped: *mut OVERLAPPED, + lpcompletionroutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE, + ) -> c_int +); #[cfg(all(test, not(feature = "preemptive")))] mod tests { diff --git a/core/src/net/mod.rs b/core/src/net/mod.rs index 86d55350..0871dbea 100644 --- a/core/src/net/mod.rs +++ b/core/src/net/mod.rs @@ -262,7 +262,7 @@ impl EventLoops { } macro_rules! impl_io_uring { - ( $syscall: ident($($arg: ident: $arg_type: ty),*) -> $result: ty ) => { + ( $syscall: ident($($arg: ident: $arg_type: ty),* $(,)?) -> $result: ty ) => { #[cfg(all(target_os = "linux", feature = "io_uring"))] impl EventLoops { #[allow(missing_docs)] @@ -289,7 +289,16 @@ impl_io_uring!(readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t); impl_io_uring!(preadv(fd: c_int, iov: *const iovec, iovcnt: c_int, offset: off_t) -> ssize_t); impl_io_uring!(recvmsg(fd: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t); impl_io_uring!(send(fd: c_int, buf: *const c_void, len: size_t, flags: c_int) -> ssize_t); -impl_io_uring!(sendto(fd: c_int, buf: *const c_void, len: size_t, flags: c_int, addr: *const sockaddr, addrlen: socklen_t) -> ssize_t); +impl_io_uring!( + sendto( + fd: c_int, + buf: *const c_void, + len: size_t, + flags: c_int, + addr: *const sockaddr, + addrlen: socklen_t, + ) -> ssize_t +); impl_io_uring!(write(fd: c_int, buf: *const c_void, count: size_t) -> ssize_t); impl_io_uring!(pwrite(fd: c_int, buf: *const c_void, count: size_t, offset: off_t) -> ssize_t); impl_io_uring!(writev(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t); @@ -297,11 +306,26 @@ impl_io_uring!(pwritev(fd: c_int, iov: *const iovec, iovcnt: c_int, offset: off_ impl_io_uring!(sendmsg(fd: c_int, msg: *const msghdr, flags: c_int) -> ssize_t); impl_io_uring!(fsync(fd: c_int) -> c_int); impl_io_uring!(mkdirat(dirfd: c_int, pathname: *const c_char, mode: mode_t) -> c_int); -impl_io_uring!(renameat(olddirfd: c_int, oldpath: *const c_char, newdirfd: c_int, newpath: *const c_char) -> c_int); -impl_io_uring!(renameat2(olddirfd: c_int, oldpath: *const c_char, newdirfd: c_int, newpath: *const c_char, flags: c_uint) -> c_int); +impl_io_uring!( + renameat( + olddirfd: c_int, + oldpath: *const c_char, + newdirfd: c_int, + newpath: *const c_char, + ) -> c_int +); +impl_io_uring!( + renameat2( + olddirfd: c_int, + oldpath: *const c_char, + newdirfd: c_int, + newpath: *const c_char, + flags: c_uint, + ) -> c_int +); macro_rules! impl_iocp { - ( $syscall: ident($($arg: ident : $arg_type: ty),*) -> $result: ty ) => { + ( $syscall: ident($($arg: ident : $arg_type: ty),* $(,)?) -> $result: ty ) => { #[allow(non_snake_case)] #[cfg(all(windows, feature = "iocp"))] impl EventLoops { @@ -317,6 +341,26 @@ macro_rules! impl_iocp { impl_iocp!(accept(fd: SOCKET, addr: *mut SOCKADDR, len: *mut c_int) -> c_int); impl_iocp!(recv(fd: SOCKET, buf: PSTR, len: c_int, flags: SEND_RECV_FLAGS) -> c_int); -impl_iocp!(WSARecv(fd: SOCKET, buf: *const WSABUF, dwbuffercount: c_uint, lpnumberofbytesrecvd: *mut c_uint, lpflags : *mut c_uint, lpoverlapped: *mut OVERLAPPED, lpcompletionroutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> c_int); +impl_iocp!( + WSARecv( + fd: SOCKET, + buf: *const WSABUF, + dwbuffercount: c_uint, + lpnumberofbytesrecvd: *mut c_uint, + lpflags: *mut c_uint, + lpoverlapped: *mut OVERLAPPED, + lpcompletionroutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE, + ) -> c_int +); impl_iocp!(send(fd: SOCKET, buf: PCSTR, len: c_int, flags: SEND_RECV_FLAGS) -> c_int); -impl_iocp!(WSASend(fd: SOCKET, buf: *const WSABUF, dwbuffercount: c_uint, lpnumberofbytesrecvd: *mut c_uint, dwflags : c_uint, lpoverlapped: *mut OVERLAPPED, lpcompletionroutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> c_int); +impl_iocp!( + WSASend( + fd: SOCKET, + buf: *const WSABUF, + dwbuffercount: c_uint, + lpnumberofbytesrecvd: *mut c_uint, + dwflags: c_uint, + lpoverlapped: *mut OVERLAPPED, + lpcompletionroutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE, + ) -> c_int +); diff --git a/hook/src/syscall/unix.rs b/hook/src/syscall/unix.rs index 14682cbc..395fadfa 100644 --- a/hook/src/syscall/unix.rs +++ b/hook/src/syscall/unix.rs @@ -7,7 +7,8 @@ use std::ffi::{c_char, c_int, c_uint, c_void}; // check https://www.rustwiki.org.cn/en/reference/introduction.html for help information #[allow(unused_macros)] macro_rules! impl_hook { - ( $field_name: ident, $syscall: ident($($arg: ident : $arg_type: ty),*) -> $result: ty ) => { + ( $field_name: ident, $syscall: ident($($arg: ident : $arg_type: ty),* $(,)?) -> $result: ty ) => { + #[allow(suspicious_runtime_symbol_definitions)] #[no_mangle] pub extern "C" fn $syscall( $($arg: $arg_type),* @@ -37,48 +38,170 @@ macro_rules! impl_hook { // The following are supported syscall impl_hook!(SLEEP, sleep(secs: c_uint) -> c_uint); impl_hook!(USLEEP, usleep(microseconds: c_uint) -> c_int); -impl_hook!(NANOSLEEP, nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int); -impl_hook!(SELECT, select(nfds: c_int, readfds: *mut fd_set, writefds: *mut fd_set, errorfds: *mut fd_set, timeout: *mut timeval) -> c_int); -impl_hook!(SOCKET, socket(domain: c_int, type_: c_int, protocol: c_int) -> c_int); -impl_hook!(SETSOCKOPT, setsockopt(socket: c_int, level: c_int, name: c_int, value: *const c_void, option_len: socklen_t) -> c_int); -impl_hook!(CONNECT, connect(fd: c_int, address: *const sockaddr, len: socklen_t) -> c_int); +impl_hook!( + NANOSLEEP, + nanosleep(rqtp: *const timespec, rmtp: *mut timespec) -> c_int +); +impl_hook!( + SELECT, + select( + nfds: c_int, + readfds: *mut fd_set, + writefds: *mut fd_set, + errorfds: *mut fd_set, + timeout: *mut timeval, + ) -> c_int +); +impl_hook!( + SOCKET, + socket(domain: c_int, type_: c_int, protocol: c_int) -> c_int +); +impl_hook!( + SETSOCKOPT, + setsockopt( + socket: c_int, + level: c_int, + name: c_int, + value: *const c_void, + option_len: socklen_t, + ) -> c_int +); +impl_hook!( + CONNECT, + connect(fd: c_int, address: *const sockaddr, len: socklen_t) -> c_int +); impl_hook!(LISTEN, listen(fd: c_int, backlog: c_int) -> c_int); -impl_hook!(ACCEPT, accept(fd: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int); +impl_hook!( + ACCEPT, + accept(fd: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int +); #[cfg(any( target_os = "linux", target_os = "l4re", target_os = "android", target_os = "emscripten" ))] -impl_hook!(ACCEPT4, accept4(fd: c_int, addr: *mut sockaddr, len: *mut socklen_t, flg: c_int) -> c_int); +impl_hook!( + ACCEPT4, + accept4(fd: c_int, addr: *mut sockaddr, len: *mut socklen_t, flg: c_int) -> c_int +); impl_hook!(SHUTDOWN, shutdown(fd: c_int, how: c_int) -> c_int); -impl_hook!(RECV, recv(fd: c_int, buf: *mut c_void, len: size_t, flags: c_int) -> ssize_t); -impl_hook!(RECVFROM, recvfrom(fd: c_int, buf: *mut c_void, len: size_t, flags: c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ssize_t); +impl_hook!( + RECV, + recv(fd: c_int, buf: *mut c_void, len: size_t, flags: c_int) -> ssize_t +); +impl_hook!( + RECVFROM, + recvfrom( + fd: c_int, + buf: *mut c_void, + len: size_t, + flags: c_int, + addr: *mut sockaddr, + addrlen: *mut socklen_t, + ) -> ssize_t +); #[cfg(not(all(target_os = "linux", feature = "io_uring")))] -impl_hook!(READ, read(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t); -impl_hook!(PREAD, pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t); -impl_hook!(READV, readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t); -impl_hook!(PREADV, preadv(fd: c_int, iov: *const iovec, iovcnt: c_int, offset: off_t) -> ssize_t); -impl_hook!(RECVMSG, recvmsg(fd: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t); -impl_hook!(SEND, send(fd: c_int, buf: *const c_void, len: size_t, flags: c_int) -> ssize_t); -impl_hook!(SENDTO, sendto(fd: c_int, buf: *const c_void, len: size_t, flags: c_int, addr: *const sockaddr, addrlen: socklen_t) -> ssize_t); -impl_hook!(WRITE, write(fd: c_int, buf: *const c_void, count: size_t) -> ssize_t); -impl_hook!(PWRITE, pwrite(fd: c_int, buf: *const c_void, count: size_t, offset: off_t) -> ssize_t); -impl_hook!(WRITEV, writev(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t); -impl_hook!(PWRITEV, pwritev(fd: c_int, iov: *const iovec, iovcnt: c_int, offset: off_t) -> ssize_t); -impl_hook!(SENDMSG, sendmsg(fd: c_int, msg: *const msghdr, flags: c_int) -> ssize_t); -impl_hook!(PTHREAD_COND_TIMEDWAIT, pthread_cond_timedwait(cond: *mut pthread_cond_t, lock: *mut pthread_mutex_t, abstime: *const timespec) -> c_int); -impl_hook!(PTHREAD_MUTEX_TRYLOCK, pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> c_int); +impl_hook!( + READ, + read(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t +); +impl_hook!( + PREAD, + pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t +); +impl_hook!( + READV, + readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t +); +impl_hook!( + PREADV, + preadv(fd: c_int, iov: *const iovec, iovcnt: c_int, offset: off_t) -> ssize_t +); +impl_hook!( + RECVMSG, + recvmsg(fd: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t +); +impl_hook!( + SEND, + send(fd: c_int, buf: *const c_void, len: size_t, flags: c_int) -> ssize_t +); +impl_hook!( + SENDTO, + sendto( + fd: c_int, + buf: *const c_void, + len: size_t, + flags: c_int, + addr: *const sockaddr, + addrlen: socklen_t, + ) -> ssize_t +); +impl_hook!( + WRITE, + write(fd: c_int, buf: *const c_void, count: size_t) -> ssize_t +); +impl_hook!( + PWRITE, + pwrite(fd: c_int, buf: *const c_void, count: size_t, offset: off_t) -> ssize_t +); +impl_hook!( + WRITEV, + writev(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t +); +impl_hook!( + PWRITEV, + pwritev(fd: c_int, iov: *const iovec, iovcnt: c_int, offset: off_t) -> ssize_t +); +impl_hook!( + SENDMSG, + sendmsg(fd: c_int, msg: *const msghdr, flags: c_int) -> ssize_t +); +impl_hook!( + PTHREAD_COND_TIMEDWAIT, + pthread_cond_timedwait( + cond: *mut pthread_cond_t, + lock: *mut pthread_mutex_t, + abstime: *const timespec, + ) -> c_int +); +impl_hook!( + PTHREAD_MUTEX_TRYLOCK, + pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> c_int +); impl_hook!(MKDIR, mkdir(path: *const c_char, mode: mode_t) -> c_int); impl_hook!(RMDIR, rmdir(path: *const c_char) -> c_int); -impl_hook!(LSEEK, lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t); +impl_hook!( + LSEEK, + lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t +); impl_hook!(LINK, link(src: *const c_char, dst: *const c_char) -> c_int); impl_hook!(UNLINK, unlink(src: *const c_char) -> c_int); impl_hook!(FSYNC, fsync(fd: c_int) -> c_int); -impl_hook!(MKDIRAT, mkdirat(dirfd: c_int, pathname: *const c_char, mode: mode_t) -> c_int); -impl_hook!(RENAMEAT, renameat(olddirfd: c_int, oldpath: *const c_char, newdirfd: c_int, newpath: *const c_char) -> c_int); +impl_hook!( + MKDIRAT, + mkdirat(dirfd: c_int, pathname: *const c_char, mode: mode_t) -> c_int +); +impl_hook!( + RENAMEAT, + renameat( + olddirfd: c_int, + oldpath: *const c_char, + newdirfd: c_int, + newpath: *const c_char, + ) -> c_int +); #[cfg(target_os = "linux")] -impl_hook!(RENAMEAT2, renameat2(olddirfd: c_int, oldpath: *const c_char, newdirfd: c_int, newpath: *const c_char, flags: c_uint) -> c_int); +impl_hook!( + RENAMEAT2, + renameat2( + olddirfd: c_int, + oldpath: *const c_char, + newdirfd: c_int, + newpath: *const c_char, + flags: c_uint, + ) -> c_int +); // NOTE: unhook poll due to mio's poller // impl_hook!(POLL, poll(fds: *mut pollfd, nfds: nfds_t, timeout: c_int) -> c_int); diff --git a/hook/src/syscall/windows.rs b/hook/src/syscall/windows.rs index a4c4d477..fd5a5335 100644 --- a/hook/src/syscall/windows.rs +++ b/hook/src/syscall/windows.rs @@ -18,7 +18,7 @@ use windows_sys::Win32::System::IO::OVERLAPPED; // check https://www.rustwiki.org.cn/en/reference/introduction.html for help information #[allow(unused_macros)] macro_rules! impl_hook { - ( $module_name: expr, $field_name: ident, $syscall: ident($($arg: ident: $arg_type: ty),*) -> $result: ty ) => { + ( $module_name: expr, $field_name: ident, $syscall: ident($($arg: ident: $arg_type: ty),* $(,)?) -> $result: ty ) => { static $field_name: once_cell::sync::OnceCell $result> = once_cell::sync::OnceCell::new(); _ = $field_name.get_or_init(|| unsafe { @@ -28,7 +28,7 @@ macro_rules! impl_hook { assert!(!ptr.is_null(), "syscall \"{syscall}\" not found !"); std::mem::transmute(ptr) }); - #[allow(non_snake_case)] + #[allow(non_snake_case, suspicious_runtime_symbol_definitions)] extern "system" fn $syscall($($arg: $arg_type),*) -> $result { let fn_ptr = $field_name.get().unwrap_or_else(|| { panic!( @@ -71,23 +71,145 @@ pub unsafe extern "system" fn DllMain( unsafe fn attach() -> std::io::Result<()> { // The following are supported syscall impl_hook!("kernel32.dll", SLEEP, Sleep(dw_milliseconds: u32) -> ()); - impl_hook!("kernel32.dll", CREATEFILEW, CreateFileW(lpfilename: PCWSTR, dwdesiredaccess: c_uint, dwsharemode: FILE_SHARE_MODE, lpsecurityattributes: *const SECURITY_ATTRIBUTES, dwcreationdisposition: FILE_CREATION_DISPOSITION, dwflagsandattributes: FILE_FLAGS_AND_ATTRIBUTES, htemplatefile: HANDLE) -> HANDLE); - impl_hook!("kernel32.dll", SETFILEPOINTEREX, SetFilePointerEx(hfile: HANDLE, lidistancetomove: c_longlong, lpnewfilepointer: *mut c_longlong, dwmovemethod: SET_FILE_POINTER_MOVE_METHOD) -> BOOL); - impl_hook!("ws2_32.dll", ACCEPT, accept(fd: SOCKET, address: *mut SOCKADDR, address_len: *mut c_int) -> SOCKET); - impl_hook!("ws2_32.dll", WSAACCEPT, WSAAccept(fd: SOCKET, address: *mut SOCKADDR, address_len: *mut c_int, lpfncondition: LPCONDITIONPROC, dwcallbackdata: usize) -> SOCKET); - impl_hook!("ws2_32.dll", CONNECT, connect(fd: SOCKET, address: *const SOCKADDR, len: c_int) -> c_int); - impl_hook!("ws2_32.dll", IOCTLSOCKET, ioctlsocket(fd: SOCKET, cmd: c_int, argp: *mut c_uint) -> c_int); - impl_hook!("ws2_32.dll", LISTEN, listen(fd: SOCKET, backlog: c_int) -> c_int); - impl_hook!("ws2_32.dll", RECV, recv(fd: SOCKET, buf: PSTR, len: c_int, flags: SEND_RECV_FLAGS) -> c_int); - impl_hook!("ws2_32.dll", SEND, send(fd: SOCKET, buf: PCSTR, len: c_int, flags: SEND_RECV_FLAGS) -> c_int); - impl_hook!("ws2_32.dll", SHUTDOWN, shutdown(fd: SOCKET, how: WINSOCK_SHUTDOWN_HOW) -> c_int); - impl_hook!("ws2_32.dll", SOCKET, socket(domain: c_int, ty: WINSOCK_SOCKET_TYPE, protocol: IPPROTO) -> SOCKET); - impl_hook!("ws2_32.dll", SETSOCKOPT, setsockopt(socket: SOCKET, level: c_int, name: c_int, value: PSTR, option_len: c_int) -> c_int); - impl_hook!("ws2_32.dll", WSARECV, WSARecv(fd: SOCKET, buf: *const WSABUF, dwbuffercount: c_uint, lpnumberofbytesrecvd: *mut c_uint, lpflags: *mut c_uint, lpoverlapped: *mut OVERLAPPED, lpcompletionroutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> c_int); - impl_hook!("ws2_32.dll", WSASEND, WSASend(fd: SOCKET, buf: *const WSABUF, dwbuffercount: c_uint, lpnumberofbytessent: *mut c_uint, dwflags: c_uint, lpoverlapped: *mut OVERLAPPED, lpcompletionroutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> c_int); - impl_hook!("ws2_32.dll", WSASOCKETW, WSASocketW(domain: c_int, ty: WINSOCK_SOCKET_TYPE, protocol: IPPROTO, lpprotocolinfo: *const WSAPROTOCOL_INFOW, g: c_uint, dw_flags: c_uint) -> SOCKET); - impl_hook!("ws2_32.dll", SELECT, select(nfds: c_int, readfds: *mut FD_SET, writefds: *mut FD_SET, errorfds: *mut FD_SET, timeout: *mut TIMEVAL) -> c_int); - impl_hook!("ws2_32.dll", WSAPOLL, WSAPoll(fds: *mut WSAPOLLFD, nfds: c_uint, timeout: c_int) -> c_int); + impl_hook!( + "kernel32.dll", + CREATEFILEW, + CreateFileW( + lpfilename: PCWSTR, + dwdesiredaccess: c_uint, + dwsharemode: FILE_SHARE_MODE, + lpsecurityattributes: *const SECURITY_ATTRIBUTES, + dwcreationdisposition: FILE_CREATION_DISPOSITION, + dwflagsandattributes: FILE_FLAGS_AND_ATTRIBUTES, + htemplatefile: HANDLE, + ) -> HANDLE + ); + impl_hook!( + "kernel32.dll", + SETFILEPOINTEREX, + SetFilePointerEx( + hfile: HANDLE, + lidistancetomove: c_longlong, + lpnewfilepointer: *mut c_longlong, + dwmovemethod: SET_FILE_POINTER_MOVE_METHOD, + ) -> BOOL + ); + impl_hook!( + "ws2_32.dll", + ACCEPT, + accept(fd: SOCKET, address: *mut SOCKADDR, address_len: *mut c_int) -> SOCKET + ); + impl_hook!( + "ws2_32.dll", + WSAACCEPT, + WSAAccept( + fd: SOCKET, + address: *mut SOCKADDR, + address_len: *mut c_int, + lpfncondition: LPCONDITIONPROC, + dwcallbackdata: usize, + ) -> SOCKET + ); + impl_hook!( + "ws2_32.dll", + CONNECT, + connect(fd: SOCKET, address: *const SOCKADDR, len: c_int) -> c_int + ); + impl_hook!( + "ws2_32.dll", + IOCTLSOCKET, + ioctlsocket(fd: SOCKET, cmd: c_int, argp: *mut c_uint) -> c_int + ); + impl_hook!( + "ws2_32.dll", + LISTEN, + listen(fd: SOCKET, backlog: c_int) -> c_int + ); + impl_hook!( + "ws2_32.dll", + RECV, + recv(fd: SOCKET, buf: PSTR, len: c_int, flags: SEND_RECV_FLAGS) -> c_int + ); + impl_hook!( + "ws2_32.dll", + SEND, + send(fd: SOCKET, buf: PCSTR, len: c_int, flags: SEND_RECV_FLAGS) -> c_int + ); + impl_hook!( + "ws2_32.dll", + SHUTDOWN, + shutdown(fd: SOCKET, how: WINSOCK_SHUTDOWN_HOW) -> c_int + ); + impl_hook!( + "ws2_32.dll", + SOCKET, + socket(domain: c_int, ty: WINSOCK_SOCKET_TYPE, protocol: IPPROTO) -> SOCKET + ); + impl_hook!( + "ws2_32.dll", + SETSOCKOPT, + setsockopt( + socket: SOCKET, + level: c_int, + name: c_int, + value: PSTR, + option_len: c_int, + ) -> c_int + ); + impl_hook!( + "ws2_32.dll", + WSARECV, + WSARecv( + fd: SOCKET, + buf: *const WSABUF, + dwbuffercount: c_uint, + lpnumberofbytesrecvd: *mut c_uint, + lpflags: *mut c_uint, + lpoverlapped: *mut OVERLAPPED, + lpcompletionroutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE, + ) -> c_int + ); + impl_hook!( + "ws2_32.dll", + WSASEND, + WSASend( + fd: SOCKET, + buf: *const WSABUF, + dwbuffercount: c_uint, + lpnumberofbytessent: *mut c_uint, + dwflags: c_uint, + lpoverlapped: *mut OVERLAPPED, + lpcompletionroutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE, + ) -> c_int + ); + impl_hook!( + "ws2_32.dll", + WSASOCKETW, + WSASocketW( + domain: c_int, + ty: WINSOCK_SOCKET_TYPE, + protocol: IPPROTO, + lpprotocolinfo: *const WSAPROTOCOL_INFOW, + g: c_uint, + dw_flags: c_uint, + ) -> SOCKET + ); + impl_hook!( + "ws2_32.dll", + SELECT, + select( + nfds: c_int, + readfds: *mut FD_SET, + writefds: *mut FD_SET, + errorfds: *mut FD_SET, + timeout: *mut TIMEVAL, + ) -> c_int + ); + impl_hook!( + "ws2_32.dll", + WSAPOLL, + WSAPoll(fds: *mut WSAPOLLFD, nfds: c_uint, timeout: c_int) -> c_int + ); // NOTE: unhook WaitOnAddress due to stack overflow or bug // impl_hook!("api-ms-win-core-synch-l1-2-0.dll", WAITONADDRESS, WaitOnAddress(address: *const c_void, compareaddress: *const c_void, addresssize: usize, dwmilliseconds: c_uint) -> BOOL);