diff --git a/monoio/src/driver/op.rs b/monoio/src/driver/op.rs index 661fafb4..5ea97032 100644 --- a/monoio/src/driver/op.rs +++ b/monoio/src/driver/op.rs @@ -63,6 +63,12 @@ pub(crate) struct CompletionMeta { pub(crate) flags: u32, } +/// MaybeFd is a wrapper for fd or a normal number. If it is marked as fd, it will close the fd when +/// dropped. +/// Use `into_inner` to take the inner fd or number and skip the drop. +/// +/// This wrapper is designed to be used in the syscall return value. It can prevent fd leak when the +/// operation is cancelled. #[derive(Debug)] pub(crate) struct MaybeFd { is_fd: bool, diff --git a/monoio/src/driver/op/accept.rs b/monoio/src/driver/op/accept.rs index 89672a42..d05b6e14 100644 --- a/monoio/src/driver/op/accept.rs +++ b/monoio/src/driver/op/accept.rs @@ -9,7 +9,6 @@ use std::{ use io_uring::{opcode, types}; #[cfg(windows)] use { - crate::syscall, std::os::windows::prelude::AsRawSocket, windows_sys::Win32::Networking::WinSock::{ accept, socklen_t, INVALID_SOCKET, SOCKADDR_STORAGE, @@ -19,8 +18,6 @@ use { use super::{super::shared_fd::SharedFd, Op, OpAble}; #[cfg(any(feature = "legacy", feature = "poll-io"))] use super::{driver::ready::Direction, MaybeFd}; -#[cfg(all(unix, any(feature = "legacy", feature = "poll-io")))] -use crate::syscall_u32; /// Accept pub(crate) struct Accept { @@ -79,7 +76,7 @@ impl OpAble for Accept { let addr = self.addr.0.as_mut_ptr() as *mut _; let len = &mut self.addr.1; - syscall!(accept@FD(fd as _, addr, len), PartialEq::eq, INVALID_SOCKET) + crate::syscall!(accept@FD(fd as _, addr, len), PartialEq::eq, INVALID_SOCKET) } #[cfg(all(any(feature = "legacy", feature = "poll-io"), unix))] @@ -107,7 +104,7 @@ impl OpAble for Accept { ))] return { let flag = libc::SOCK_CLOEXEC | libc::SOCK_NONBLOCK; - syscall_u32!(accept4@FD(fd, addr, len, flag)) + crate::syscall!(accept4@FD(fd, addr, len, flag)) }; // But not all platforms have the `accept4(2)` call. Luckily BSD (derived) @@ -120,10 +117,10 @@ impl OpAble for Accept { target_os = "redox" ))] return { - let stream_fd = syscall_u32!(accept@FD(fd, addr, len))?; - let fd = stream_fd.fd() as i32; - syscall_u32!(fcntl@RAW(fd, libc::F_SETFD, libc::FD_CLOEXEC))?; - syscall_u32!(fcntl@RAW(fd, libc::F_SETFL, libc::O_NONBLOCK))?; + let stream_fd = crate::syscall!(accept@FD(fd, addr, len))?; + let fd = stream_fd.fd() as libc::c_int; + crate::syscall!(fcntl@RAW(fd, libc::F_SETFD, libc::FD_CLOEXEC))?; + crate::syscall!(fcntl@RAW(fd, libc::F_SETFL, libc::O_NONBLOCK))?; Ok(stream_fd) }; } diff --git a/monoio/src/driver/op/close.rs b/monoio/src/driver/op/close.rs index 5ee6c66e..c5a31cd6 100644 --- a/monoio/src/driver/op/close.rs +++ b/monoio/src/driver/op/close.rs @@ -5,10 +5,7 @@ use std::os::unix::io::RawFd; #[cfg(all(target_os = "linux", feature = "iouring"))] use io_uring::{opcode, types}; #[cfg(windows)] -use { - crate::syscall, std::os::windows::io::RawSocket, - windows_sys::Win32::Networking::WinSock::closesocket, -}; +use {std::os::windows::io::RawSocket, windows_sys::Win32::Networking::WinSock::closesocket}; #[cfg(any(feature = "legacy", feature = "poll-io"))] use super::MaybeFd; @@ -52,9 +49,9 @@ impl OpAble for Close { #[cfg(any(feature = "legacy", feature = "poll-io"))] fn legacy_call(&mut self) -> io::Result { #[cfg(unix)] - return crate::syscall_u32!(close@NON_FD(self.fd)); + return crate::syscall!(close@NON_FD(self.fd)); #[cfg(windows)] - return syscall!(closesocket@NON_FD(self.fd as _), PartialEq::ne, 0); + return crate::syscall!(closesocket@NON_FD(self.fd as _), PartialEq::ne, 0); } } diff --git a/monoio/src/driver/op/connect.rs b/monoio/src/driver/op/connect.rs index 46fd5787..49970e48 100644 --- a/monoio/src/driver/op/connect.rs +++ b/monoio/src/driver/op/connect.rs @@ -70,7 +70,7 @@ impl OpAble for Connect { endpoints.sae_dstaddr = self.socket_addr.as_ptr(); endpoints.sae_dstaddrlen = self.socket_addr_len; - return match crate::syscall_u32!(connectx@RAW( + return match crate::syscall!(connectx@RAW( self.fd.raw_fd(), &endpoints as *const _, libc::SAE_ASSOCID_ANY, @@ -86,7 +86,7 @@ impl OpAble for Connect { } #[cfg(unix)] - match crate::syscall_u32!(connect@RAW( + match crate::syscall!(connect@RAW( self.fd.raw_fd(), self.socket_addr.as_ptr(), self.socket_addr_len, @@ -158,7 +158,7 @@ impl OpAble for ConnectUnix { #[cfg(any(feature = "legacy", feature = "poll-io"))] fn legacy_call(&mut self) -> io::Result { - match crate::syscall_u32!(connect@RAW( + match crate::syscall!(connect@RAW( self.fd.raw_fd(), &self.socket_addr.0 as *const _ as *const _, self.socket_addr.1 diff --git a/monoio/src/driver/op/fsync.rs b/monoio/src/driver/op/fsync.rs index 7bc4f729..a0409b69 100644 --- a/monoio/src/driver/op/fsync.rs +++ b/monoio/src/driver/op/fsync.rs @@ -63,15 +63,13 @@ impl OpAble for Fsync { #[cfg(all(any(feature = "legacy", feature = "poll-io"), unix))] fn legacy_call(&mut self) -> io::Result { - use crate::syscall_u32; - #[cfg(target_os = "linux")] if self.data_sync { - syscall_u32!(fdatasync@NON_FD(self.fd.raw_fd())) + crate::syscall!(fdatasync@NON_FD(self.fd.raw_fd())) } else { - syscall_u32!(fsync@NON_FD(self.fd.raw_fd())) + crate::syscall!(fsync@NON_FD(self.fd.raw_fd())) } #[cfg(not(target_os = "linux"))] - syscall_u32!(fsync@NON_FD(self.fd.raw_fd())) + crate::syscall!(fsync@NON_FD(self.fd.raw_fd())) } } diff --git a/monoio/src/driver/op/mkdir.rs b/monoio/src/driver/op/mkdir.rs index 9ef00fa9..684dfc2c 100644 --- a/monoio/src/driver/op/mkdir.rs +++ b/monoio/src/driver/op/mkdir.rs @@ -37,9 +37,7 @@ impl OpAble for MkDir { #[cfg(all(any(feature = "legacy", feature = "poll-io"), unix))] fn legacy_call(&mut self) -> std::io::Result { - use crate::syscall_u32; - - syscall_u32!(mkdirat@NON_FD( + crate::syscall!(mkdirat@NON_FD( libc::AT_FDCWD, self.path.as_ptr(), self.mode diff --git a/monoio/src/driver/op/open.rs b/monoio/src/driver/op/open.rs index 1673a3ce..21883b10 100644 --- a/monoio/src/driver/op/open.rs +++ b/monoio/src/driver/op/open.rs @@ -6,8 +6,6 @@ use io_uring::{opcode, types}; #[cfg(any(feature = "legacy", feature = "poll-io"))] use super::{driver::ready::Direction, MaybeFd}; use super::{Op, OpAble}; -#[cfg(all(unix, any(feature = "legacy", feature = "poll-io")))] -use crate::syscall_u32; use crate::{driver::util::cstr, fs::OpenOptions}; /// Open a file @@ -69,7 +67,7 @@ impl OpAble for Open { #[cfg(all(any(feature = "legacy", feature = "poll-io"), not(windows)))] fn legacy_call(&mut self) -> io::Result { - syscall_u32!(open@FD( + crate::syscall!(open@FD( self.path.as_c_str().as_ptr(), self.flags, self.mode as libc::c_int diff --git a/monoio/src/driver/op/poll.rs b/monoio/src/driver/op/poll.rs index d9d51e0f..71f56305 100644 --- a/monoio/src/driver/op/poll.rs +++ b/monoio/src/driver/op/poll.rs @@ -85,7 +85,7 @@ impl OpAble for PollAdd { }, revents: 0, }; - let ret = crate::syscall_u32!(poll@RAW(&mut pollfd as *mut _, 1, 0))?; + let ret = crate::syscall!(poll@RAW(&mut pollfd as *mut _, 1, 0))?; if ret == 0 { return Err(ErrorKind::WouldBlock.into()); } diff --git a/monoio/src/driver/op/read.rs b/monoio/src/driver/op/read.rs index 2062edb0..f0fc8b45 100644 --- a/monoio/src/driver/op/read.rs +++ b/monoio/src/driver/op/read.rs @@ -313,11 +313,10 @@ pub(crate) mod impls { use libc::iovec; use super::*; - use crate::syscall_u32; /// A wrapper for [`libc::read`] pub(crate) fn read(fd: i32, buf: *mut u8, len: usize) -> io::Result { - syscall_u32!(read@NON_FD(fd, buf as _, len)) + crate::syscall!(read@NON_FD(fd, buf as _, len)) } /// A wrapper of [`libc::pread`] @@ -325,12 +324,12 @@ pub(crate) mod impls { let offset = libc::off_t::try_from(offset) .map_err(|_| io::Error::new(io::ErrorKind::Other, "offset too big"))?; - syscall_u32!(pread@NON_FD(fd, buf as _, len, offset)) + crate::syscall!(pread@NON_FD(fd, buf as _, len, offset)) } /// A wrapper of [`libc::readv`] pub(crate) fn read_vectored(fd: i32, buf_vec: *mut iovec, len: usize) -> io::Result { - syscall_u32!(readv@NON_FD(fd, buf_vec as _, len as _)) + crate::syscall!(readv@NON_FD(fd, buf_vec as _, len as _)) } /// A wrapper of [`libc::preadv`] @@ -343,7 +342,7 @@ pub(crate) mod impls { let offset = libc::off_t::try_from(offset) .map_err(|_| io::Error::new(io::ErrorKind::Other, "offset too big"))?; - syscall_u32!(preadv@NON_FD(fd, buf_vec as _, len as _, offset)) + crate::syscall!(preadv@NON_FD(fd, buf_vec as _, len as _, offset)) } } diff --git a/monoio/src/driver/op/recv.rs b/monoio/src/driver/op/recv.rs index f7e3a6be..de0624fe 100644 --- a/monoio/src/driver/op/recv.rs +++ b/monoio/src/driver/op/recv.rs @@ -1,3 +1,5 @@ +#[cfg(all(unix, any(feature = "legacy", feature = "poll-io")))] +use std::os::unix::prelude::AsRawFd; use std::{ io, mem::{transmute, MaybeUninit}, @@ -11,8 +13,6 @@ use { crate::net::unix::SocketAddr as UnixSocketAddr, libc::{sockaddr_in, sockaddr_in6, sockaddr_storage, socklen_t, AF_INET, AF_INET6}, }; -#[cfg(all(unix, any(feature = "legacy", feature = "poll-io")))] -use {crate::syscall_u32, std::os::unix::prelude::AsRawFd}; #[cfg(all(windows, any(feature = "legacy", feature = "poll-io")))] use { std::os::windows::io::AsRawSocket, @@ -98,7 +98,7 @@ impl OpAble for Recv { #[cfg(all(any(feature = "legacy", feature = "poll-io"), unix))] fn legacy_call(&mut self) -> io::Result { let fd = self.fd.as_raw_fd(); - syscall_u32!(recv@NON_FD( + crate::syscall!(recv@NON_FD( fd, self.buf.write_ptr() as _, self.buf.bytes_total().min(u32::MAX as usize), @@ -237,7 +237,7 @@ impl OpAble for RecvMsg { #[cfg(all(any(feature = "legacy", feature = "poll-io"), unix))] fn legacy_call(&mut self) -> io::Result { let fd = self.fd.as_raw_fd(); - syscall_u32!(recvmsg@NON_FD(fd, &mut *self.info.2, 0)) + crate::syscall!(recvmsg@NON_FD(fd, &mut *self.info.2, 0)) } #[cfg(all(any(feature = "legacy", feature = "poll-io"), windows))] @@ -355,6 +355,6 @@ impl OpAble for RecvMsgUnix { #[cfg(any(feature = "legacy", feature = "poll-io"))] fn legacy_call(&mut self) -> io::Result { let fd = self.fd.as_raw_fd(); - syscall_u32!(recvmsg@NON_FD(fd, &mut self.info.2 as *mut _, 0)) + crate::syscall!(recvmsg@NON_FD(fd, &mut self.info.2 as *mut _, 0)) } } diff --git a/monoio/src/driver/op/rename.rs b/monoio/src/driver/op/rename.rs index 2bf770ad..fa02ba0c 100644 --- a/monoio/src/driver/op/rename.rs +++ b/monoio/src/driver/op/rename.rs @@ -40,9 +40,7 @@ impl OpAble for Rename { #[cfg(all(any(feature = "legacy", feature = "poll-io"), unix))] fn legacy_call(&mut self) -> std::io::Result { - use crate::syscall_u32; - - syscall_u32!(renameat@NON_FD( + crate::syscall!(renameat@NON_FD( libc::AT_FDCWD, self.from.as_ptr(), libc::AT_FDCWD, diff --git a/monoio/src/driver/op/send.rs b/monoio/src/driver/op/send.rs index d0da1db9..2af5703c 100644 --- a/monoio/src/driver/op/send.rs +++ b/monoio/src/driver/op/send.rs @@ -1,3 +1,5 @@ +#[cfg(all(unix, any(feature = "legacy", feature = "poll-io")))] +use std::os::unix::prelude::AsRawFd; use std::{io, net::SocketAddr}; #[cfg(all(target_os = "linux", feature = "iouring"))] @@ -5,12 +7,9 @@ use io_uring::{opcode, types}; use socket2::SockAddr; #[cfg(all(windows, any(feature = "legacy", feature = "poll-io")))] use { - crate::syscall, std::os::windows::io::AsRawSocket, windows_sys::Win32::Networking::WinSock::{send, WSASendMsg, SOCKET_ERROR}, }; -#[cfg(all(unix, any(feature = "legacy", feature = "poll-io")))] -use {crate::syscall_u32, std::os::unix::prelude::AsRawFd}; use super::{super::shared_fd::SharedFd, Op, OpAble}; #[cfg(any(feature = "legacy", feature = "poll-io"))] @@ -104,7 +103,7 @@ impl OpAble for Send { #[cfg(not(target_os = "linux"))] let flags = 0; - syscall_u32!(send@NON_FD( + crate::syscall!(send@NON_FD( fd, self.buf.read_ptr() as _, self.buf.bytes_init(), @@ -115,7 +114,7 @@ impl OpAble for Send { #[cfg(all(any(feature = "legacy", feature = "poll-io"), windows))] fn legacy_call(&mut self) -> io::Result { let fd = self.fd.as_raw_socket(); - syscall!( + crate::syscall!( send@NON_FD(fd as _, self.buf.read_ptr(), self.buf.bytes_init() as _, 0), PartialOrd::lt, 0 @@ -215,7 +214,7 @@ impl OpAble for SendMsg { #[cfg(not(target_os = "linux"))] const FLAGS: libc::c_int = 0; let fd = self.fd.as_raw_fd(); - syscall_u32!(sendmsg@NON_FD(fd, &*self.info.2, FLAGS)) + crate::syscall!(sendmsg@NON_FD(fd, &*self.info.2, FLAGS)) } #[cfg(all(any(feature = "legacy", feature = "poll-io"), windows))] @@ -319,6 +318,6 @@ impl OpAble for SendMsgUnix { #[cfg(not(target_os = "linux"))] const FLAGS: libc::c_int = 0; let fd = self.fd.as_raw_fd(); - syscall_u32!(sendmsg@NON_FD(fd, &mut self.info.2 as *mut _, FLAGS)) + crate::syscall!(sendmsg@NON_FD(fd, &mut self.info.2 as *mut _, FLAGS)) } } diff --git a/monoio/src/driver/op/splice.rs b/monoio/src/driver/op/splice.rs index 47771b81..3da5b9cc 100644 --- a/monoio/src/driver/op/splice.rs +++ b/monoio/src/driver/op/splice.rs @@ -6,10 +6,7 @@ use std::io; use io_uring::{opcode, types}; #[cfg(all(unix, feature = "legacy"))] use { - crate::{ - driver::{op::MaybeFd, ready::Direction}, - syscall_u32, - }, + crate::driver::{op::MaybeFd, ready::Direction}, std::os::unix::prelude::AsRawFd, }; @@ -97,7 +94,7 @@ impl OpAble for Splice { let fd_out = self.fd_out.as_raw_fd(); let off_in = std::ptr::null_mut::(); let off_out = std::ptr::null_mut::(); - syscall_u32!(splice@NON_FD( + crate::syscall!(splice@NON_FD( fd_in, off_in, fd_out, diff --git a/monoio/src/driver/op/statx.rs b/monoio/src/driver/op/statx.rs index e535fb9d..619de338 100644 --- a/monoio/src/driver/op/statx.rs +++ b/monoio/src/driver/op/statx.rs @@ -86,7 +86,7 @@ impl OpAble for FdStatx { fn legacy_call(&mut self) -> std::io::Result { use std::os::fd::AsRawFd; - crate::syscall_u32!(statx@NON_FD( + crate::syscall!(statx@NON_FD( self.inner.as_raw_fd(), c"".as_ptr(), libc::AT_EMPTY_PATH, @@ -104,7 +104,7 @@ impl OpAble for FdStatx { fn legacy_call(&mut self) -> std::io::Result { use std::os::fd::AsRawFd; - crate::syscall_u32!(fstat@NON_FD( + crate::syscall!(fstat@NON_FD( self.inner.as_raw_fd(), self.stat_buf.as_mut_ptr() as *mut _ )) @@ -173,7 +173,7 @@ impl OpAble for PathStatx { #[cfg(all(any(feature = "legacy", feature = "poll-io"), target_os = "linux"))] fn legacy_call(&mut self) -> std::io::Result { - crate::syscall_u32!(statx@NON_FD( + crate::syscall!(statx@NON_FD( libc::AT_FDCWD, self.inner.as_ptr(), self.flags, @@ -190,12 +190,12 @@ impl OpAble for PathStatx { #[cfg(all(any(feature = "legacy", feature = "poll-io"), target_os = "macos"))] fn legacy_call(&mut self) -> std::io::Result { if self.follow_symlinks { - crate::syscall_u32!(stat@NON_FD( + crate::syscall!(stat@NON_FD( self.inner.as_ptr(), self.stat_buf.as_mut_ptr() as *mut _ )) } else { - crate::syscall_u32!(lstat@NON_FD( + crate::syscall!(lstat@NON_FD( self.inner.as_ptr(), self.stat_buf.as_mut_ptr() as *mut _ )) diff --git a/monoio/src/driver/op/symlink.rs b/monoio/src/driver/op/symlink.rs index fb4cf7ef..bc95376f 100644 --- a/monoio/src/driver/op/symlink.rs +++ b/monoio/src/driver/op/symlink.rs @@ -36,7 +36,7 @@ impl OpAble for Symlink { #[cfg(any(feature = "legacy", feature = "poll-io"))] fn legacy_call(&mut self) -> std::io::Result { - crate::syscall_u32!(symlink@NON_FD( + crate::syscall!(symlink@NON_FD( self.from.as_c_str().as_ptr(), self.to.as_c_str().as_ptr() )) diff --git a/monoio/src/driver/op/unlink.rs b/monoio/src/driver/op/unlink.rs index 8ecd0f97..7f9cb4ae 100644 --- a/monoio/src/driver/op/unlink.rs +++ b/monoio/src/driver/op/unlink.rs @@ -8,10 +8,7 @@ use libc::{AT_FDCWD, AT_REMOVEDIR}; use super::{Op, OpAble}; use crate::driver::util::cstr; #[cfg(any(feature = "legacy", feature = "poll-io"))] -use crate::{ - driver::{op::MaybeFd, ready::Direction}, - syscall_u32, -}; +use crate::driver::{op::MaybeFd, ready::Direction}; pub(crate) struct Unlink { path: CString, @@ -52,9 +49,9 @@ impl OpAble for Unlink { #[cfg(any(feature = "legacy", feature = "poll-io"))] fn legacy_call(&mut self) -> io::Result { if self.remove_dir { - syscall_u32!(rmdir@NON_FD(self.path.as_c_str().as_ptr())) + crate::syscall!(rmdir@NON_FD(self.path.as_c_str().as_ptr())) } else { - syscall_u32!(unlink@NON_FD(self.path.as_c_str().as_ptr())) + crate::syscall!(unlink@NON_FD(self.path.as_c_str().as_ptr())) } } } diff --git a/monoio/src/driver/op/write.rs b/monoio/src/driver/op/write.rs index c3d973aa..ca382183 100644 --- a/monoio/src/driver/op/write.rs +++ b/monoio/src/driver/op/write.rs @@ -252,11 +252,10 @@ pub(crate) mod impls { use libc::iovec; use super::*; - use crate::syscall_u32; /// A wrapper of [`libc::write`] pub(crate) fn write(fd: i32, buf: *const u8, len: usize) -> io::Result { - syscall_u32!(write@NON_FD(fd, buf as _, len)) + crate::syscall!(write@NON_FD(fd, buf as _, len)) } /// A wrapper of [`libc::write`] @@ -269,7 +268,7 @@ pub(crate) mod impls { let offset = libc::off_t::try_from(offset) .map_err(|_| io::Error::new(io::ErrorKind::Other, "offset too big"))?; - syscall_u32!(pwrite@NON_FD(fd, buf as _, len, offset)) + crate::syscall!(pwrite@NON_FD(fd, buf as _, len, offset)) } /// A wrapper of [`libc::writev`] @@ -278,7 +277,7 @@ pub(crate) mod impls { buf_vec: *const iovec, len: usize, ) -> io::Result { - syscall_u32!(writev@NON_FD(fd, buf_vec as _, len as _)) + crate::syscall!(writev@NON_FD(fd, buf_vec as _, len as _)) } /// A wrapper of [`libc::pwritev`] @@ -291,7 +290,7 @@ pub(crate) mod impls { let offset = libc::off_t::try_from(offset) .map_err(|_| io::Error::new(io::ErrorKind::Other, "offset too big"))?; - syscall_u32!(pwritev@NON_FD(fd, buf_vec as _, len as _, offset)) + crate::syscall!(pwritev@NON_FD(fd, buf_vec as _, len as _, offset)) } } diff --git a/monoio/src/driver/util.rs b/monoio/src/driver/util.rs index dec31a07..de06250a 100644 --- a/monoio/src/driver/util.rs +++ b/monoio/src/driver/util.rs @@ -28,6 +28,10 @@ pub(super) fn timespec(duration: std::time::Duration) -> io_uring::types::Timesp } /// Do syscall and return Result +/// If use syscall@FD or syscall@NON_FD, the return value is wrapped in MaybeFd. The `MaybeFd` is +/// designed to close the fd when it is dropped. +/// If use syscall@RAW, the return value is raw value. The requirement to explicitly add @RAW is to +/// avoid misuse. #[cfg(unix)] #[macro_export] macro_rules! syscall { @@ -36,7 +40,7 @@ macro_rules! syscall { if res == -1 { Err(std::io::Error::last_os_error()) } else { - Ok(unsafe { $crate::driver::op::MaybeFd::new_fd(res) }) + Ok(unsafe { $crate::driver::op::MaybeFd::new_fd(res as u32) }) } }}; ($fn: ident @NON_FD ( $($arg: expr),* $(,)* ) ) => {{ @@ -44,7 +48,7 @@ macro_rules! syscall { if res == -1 { Err(std::io::Error::last_os_error()) } else { - Ok($crate::driver::op::MaybeFd::new_non_fd(res)) + Ok($crate::driver::op::MaybeFd::new_non_fd(res as u32)) } }}; ($fn: ident @RAW ( $($arg: expr),* $(,)* ) ) => {{ @@ -58,6 +62,10 @@ macro_rules! syscall { } /// Do syscall and return Result +/// If use syscall@FD or syscall@NON_FD, the return value is wrapped in MaybeFd. The `MaybeFd` is +/// designed to close the fd when it is dropped. +/// If use syscall@RAW, the return value is raw value. The requirement to explicitly add @RAW is to +/// avoid misuse. #[cfg(windows)] #[macro_export] macro_rules! syscall { @@ -87,44 +95,6 @@ macro_rules! syscall { }}; } -/// Do syscall and return Result -#[macro_export] -macro_rules! syscall_u32 { - ($fn: ident @RAW ( $($arg: expr),* $(,)* ) ) => {{ - #[cfg(windows)] - let res = unsafe { $fn($($arg, )*) }; - #[cfg(unix)] - let res = unsafe { ::libc::$fn($($arg, )*) }; - if res < 0 { - Err(::std::io::Error::last_os_error()) - } else { - Ok(res as u32) - } - }}; - ($fn: ident @FD ( $($arg: expr),* $(,)* ) ) => {{ - #[cfg(windows)] - let res = unsafe { $fn($($arg, )*) }; - #[cfg(unix)] - let res = unsafe { ::libc::$fn($($arg, )*) }; - if res < 0 { - Err(::std::io::Error::last_os_error()) - } else { - Ok(unsafe { $crate::driver::op::MaybeFd::new_fd(res as u32) }) - } - }}; - ($fn: ident @NON_FD ( $($arg: expr),* $(,)* ) ) => {{ - #[cfg(windows)] - let res = unsafe { $fn($($arg, )*) }; - #[cfg(unix)] - let res = unsafe { ::libc::$fn($($arg, )*) }; - if res < 0 { - Err(::std::io::Error::last_os_error()) - } else { - Ok($crate::driver::op::MaybeFd::new_non_fd(res as u32)) - } - }}; -} - #[cfg(all( not(all(target_os = "linux", feature = "iouring")), not(feature = "legacy")