1 //! linux_raw syscalls supporting `rustix::event`.
5 //! See the `rustix::backend` module documentation for details.
6 #![allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
9 #[cfg(feature = "alloc")]
10 use crate::backend
::conv
::pass_usize
;
11 use crate::backend
::conv
::{
12 by_ref
, c_int
, c_uint
, raw_fd
, ret
, ret_owned_fd
, ret_usize
, slice_mut
, zero
,
14 use crate::event
::{epoll, EventfdFlags, PollFd}
;
15 use crate::fd
::{BorrowedFd, OwnedFd}
;
17 use linux_raw_sys
::general
::{EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD}
;
18 #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
20 crate::backend
::conv
::{opt_ref, size_of}
,
21 linux_raw_sys
::general
::{__kernel_timespec, kernel_sigset_t}
,
25 pub(crate) fn poll(fds
: &mut [PollFd
<'_
>], timeout
: c
::c_int
) -> io
::Result
<usize> {
26 let (fds_addr_mut
, fds_len
) = slice_mut(fds
);
28 #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
30 let timeout
= if timeout
>= 0 {
31 Some(__kernel_timespec
{
32 tv_sec
: (timeout
as i64) / 1000,
33 tv_nsec
: (timeout
as i64) % 1000 * 1_000_000,
42 opt_ref(timeout
.as_ref()),
44 size_of
::<kernel_sigset_t
, _
>()
47 #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
49 ret_usize(syscall
!(__NR_poll
, fds_addr_mut
, fds_len
, c_int(timeout
)))
54 pub(crate) fn epoll_create(flags
: epoll
::CreateFlags
) -> io
::Result
<OwnedFd
> {
55 unsafe { ret_owned_fd(syscall_readonly!(__NR_epoll_create1, flags)) }
59 pub(crate) unsafe fn epoll_add(
64 ret(syscall_readonly
!(
67 c_uint(EPOLL_CTL_ADD
),
74 pub(crate) unsafe fn epoll_mod(
79 ret(syscall_readonly
!(
82 c_uint(EPOLL_CTL_MOD
),
89 pub(crate) unsafe fn epoll_del(epfd
: BorrowedFd
<'_
>, fd
: c
::c_int
) -> io
::Result
<()> {
90 ret(syscall_readonly
!(
93 c_uint(EPOLL_CTL_DEL
),
99 #[cfg(feature = "alloc")]
101 pub(crate) fn epoll_wait(
102 epfd
: BorrowedFd
<'_
>,
103 events
: *mut epoll
::Event
,
106 ) -> io
::Result
<usize> {
107 #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))]
113 pass_usize(num_events
),
117 #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
123 pass_usize(num_events
),
131 pub(crate) fn eventfd(initval
: u32, flags
: EventfdFlags
) -> io
::Result
<OwnedFd
> {
132 unsafe { ret_owned_fd(syscall_readonly!(__NR_eventfd2, c_uint(initval), flags)) }