1b8a62b91Sopenharmony_ci//! Linux [io_uring]. 2b8a62b91Sopenharmony_ci//! 3b8a62b91Sopenharmony_ci//! This API is very low-level. The main adaptations it makes from the raw 4b8a62b91Sopenharmony_ci//! Linux io_uring API are the use of appropriately-sized `bitflags`, `enum`, 5b8a62b91Sopenharmony_ci//! `Result`, `OwnedFd`, `AsFd`, `RawFd`, and `*mut c_void` in place of plain 6b8a62b91Sopenharmony_ci//! integers. 7b8a62b91Sopenharmony_ci//! 8b8a62b91Sopenharmony_ci//! # Safety 9b8a62b91Sopenharmony_ci//! 10b8a62b91Sopenharmony_ci//! io_uring operates on raw pointers and raw file descriptors. Rustix does not 11b8a62b91Sopenharmony_ci//! attempt to provide a safe API for these, because the abstraction level is 12b8a62b91Sopenharmony_ci//! too low for this to be practical. Safety should be introduced in 13b8a62b91Sopenharmony_ci//! higher-level abstraction layers. 14b8a62b91Sopenharmony_ci//! 15b8a62b91Sopenharmony_ci//! # References 16b8a62b91Sopenharmony_ci//! - [Linux] 17b8a62b91Sopenharmony_ci//! 18b8a62b91Sopenharmony_ci//! [Linux]: https://man.archlinux.org/man/io_uring.7.en 19b8a62b91Sopenharmony_ci//! [io_uring]: https://en.wikipedia.org/wiki/Io_uring 20b8a62b91Sopenharmony_ci#![allow(unsafe_code)] 21b8a62b91Sopenharmony_ci 22b8a62b91Sopenharmony_ciuse crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd}; 23b8a62b91Sopenharmony_ciuse crate::{backend, io}; 24b8a62b91Sopenharmony_ciuse core::ffi::c_void; 25b8a62b91Sopenharmony_ciuse core::ptr::null_mut; 26b8a62b91Sopenharmony_ciuse linux_raw_sys::general as sys; 27b8a62b91Sopenharmony_ci 28b8a62b91Sopenharmony_ci/// `io_uring_setup(entries, params)`—Setup a context for performing 29b8a62b91Sopenharmony_ci/// asynchronous I/O. 30b8a62b91Sopenharmony_ci/// 31b8a62b91Sopenharmony_ci/// # References 32b8a62b91Sopenharmony_ci/// - [Linux] 33b8a62b91Sopenharmony_ci/// 34b8a62b91Sopenharmony_ci/// [Linux]: https://man.archlinux.org/man/io_uring_setup.2.en 35b8a62b91Sopenharmony_ci#[inline] 36b8a62b91Sopenharmony_cipub fn io_uring_setup(entries: u32, params: &mut io_uring_params) -> io::Result<OwnedFd> { 37b8a62b91Sopenharmony_ci backend::io_uring::syscalls::io_uring_setup(entries, params) 38b8a62b91Sopenharmony_ci} 39b8a62b91Sopenharmony_ci 40b8a62b91Sopenharmony_ci/// `io_uring_register(fd, opcode, arg, nr_args)`—Register files or user 41b8a62b91Sopenharmony_ci/// buffers for asynchronous I/O. 42b8a62b91Sopenharmony_ci/// 43b8a62b91Sopenharmony_ci/// # Safety 44b8a62b91Sopenharmony_ci/// 45b8a62b91Sopenharmony_ci/// io_uring operates on raw pointers and raw file descriptors. Users are 46b8a62b91Sopenharmony_ci/// responsible for ensuring that memory and resources are only accessed in 47b8a62b91Sopenharmony_ci/// valid ways. 48b8a62b91Sopenharmony_ci/// 49b8a62b91Sopenharmony_ci/// # References 50b8a62b91Sopenharmony_ci/// - [Linux] 51b8a62b91Sopenharmony_ci/// 52b8a62b91Sopenharmony_ci/// [Linux]: https://man.archlinux.org/man/io_uring_register.2.en 53b8a62b91Sopenharmony_ci#[inline] 54b8a62b91Sopenharmony_cipub unsafe fn io_uring_register<Fd: AsFd>( 55b8a62b91Sopenharmony_ci fd: Fd, 56b8a62b91Sopenharmony_ci opcode: IoringRegisterOp, 57b8a62b91Sopenharmony_ci arg: *const c_void, 58b8a62b91Sopenharmony_ci nr_args: u32, 59b8a62b91Sopenharmony_ci) -> io::Result<()> { 60b8a62b91Sopenharmony_ci backend::io_uring::syscalls::io_uring_register(fd.as_fd(), opcode, arg, nr_args) 61b8a62b91Sopenharmony_ci} 62b8a62b91Sopenharmony_ci 63b8a62b91Sopenharmony_ci/// `io_uring_enter(fd, to_submit, min_complete, flags, arg, size)`—Initiate 64b8a62b91Sopenharmony_ci/// and/or complete asynchronous I/O. 65b8a62b91Sopenharmony_ci/// 66b8a62b91Sopenharmony_ci/// # Safety 67b8a62b91Sopenharmony_ci/// 68b8a62b91Sopenharmony_ci/// io_uring operates on raw pointers and raw file descriptors. Users are 69b8a62b91Sopenharmony_ci/// responsible for ensuring that memory and resources are only accessed in 70b8a62b91Sopenharmony_ci/// valid ways. 71b8a62b91Sopenharmony_ci/// 72b8a62b91Sopenharmony_ci/// # References 73b8a62b91Sopenharmony_ci/// - [Linux] 74b8a62b91Sopenharmony_ci/// 75b8a62b91Sopenharmony_ci/// [Linux]: https://man.archlinux.org/man/io_uring_enter.2.en 76b8a62b91Sopenharmony_ci#[inline] 77b8a62b91Sopenharmony_cipub unsafe fn io_uring_enter<Fd: AsFd>( 78b8a62b91Sopenharmony_ci fd: Fd, 79b8a62b91Sopenharmony_ci to_submit: u32, 80b8a62b91Sopenharmony_ci min_complete: u32, 81b8a62b91Sopenharmony_ci flags: IoringEnterFlags, 82b8a62b91Sopenharmony_ci arg: *const c_void, 83b8a62b91Sopenharmony_ci size: usize, 84b8a62b91Sopenharmony_ci) -> io::Result<u32> { 85b8a62b91Sopenharmony_ci backend::io_uring::syscalls::io_uring_enter( 86b8a62b91Sopenharmony_ci fd.as_fd(), 87b8a62b91Sopenharmony_ci to_submit, 88b8a62b91Sopenharmony_ci min_complete, 89b8a62b91Sopenharmony_ci flags, 90b8a62b91Sopenharmony_ci arg, 91b8a62b91Sopenharmony_ci size, 92b8a62b91Sopenharmony_ci ) 93b8a62b91Sopenharmony_ci} 94b8a62b91Sopenharmony_ci 95b8a62b91Sopenharmony_cibitflags::bitflags! { 96b8a62b91Sopenharmony_ci /// `IORING_ENTER_*` flags for use with [`io_uring_enter`]. 97b8a62b91Sopenharmony_ci #[derive(Default)] 98b8a62b91Sopenharmony_ci pub struct IoringEnterFlags: u32 { 99b8a62b91Sopenharmony_ci /// `IORING_ENTER_GETEVENTS` 100b8a62b91Sopenharmony_ci const GETEVENTS = sys::IORING_ENTER_GETEVENTS; 101b8a62b91Sopenharmony_ci 102b8a62b91Sopenharmony_ci /// `IORING_ENTER_SQ_WAKEUP` 103b8a62b91Sopenharmony_ci const SQ_WAKEUP = sys::IORING_ENTER_SQ_WAKEUP; 104b8a62b91Sopenharmony_ci 105b8a62b91Sopenharmony_ci /// `IORING_ENTER_SQ_WAIT` 106b8a62b91Sopenharmony_ci const SQ_WAIT = sys::IORING_ENTER_SQ_WAIT; 107b8a62b91Sopenharmony_ci 108b8a62b91Sopenharmony_ci /// `IORING_ENTER_EXT_ARG` 109b8a62b91Sopenharmony_ci const EXT_ARG = sys::IORING_ENTER_EXT_ARG; 110b8a62b91Sopenharmony_ci } 111b8a62b91Sopenharmony_ci} 112b8a62b91Sopenharmony_ci 113b8a62b91Sopenharmony_ci/// `IORING_REGISTER_*` and `IORING_UNREGISTER_*` constants for use with 114b8a62b91Sopenharmony_ci/// [`io_uring_register`]. 115b8a62b91Sopenharmony_ci#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] 116b8a62b91Sopenharmony_ci#[repr(u8)] 117b8a62b91Sopenharmony_ci#[non_exhaustive] 118b8a62b91Sopenharmony_cipub enum IoringRegisterOp { 119b8a62b91Sopenharmony_ci /// `IORING_REGISTER_BUFFERS` 120b8a62b91Sopenharmony_ci RegisterBuffers = sys::IORING_REGISTER_BUFFERS as _, 121b8a62b91Sopenharmony_ci 122b8a62b91Sopenharmony_ci /// `IORING_UNREGISTER_BUFFERS` 123b8a62b91Sopenharmony_ci UnregisterBuffers = sys::IORING_UNREGISTER_BUFFERS as _, 124b8a62b91Sopenharmony_ci 125b8a62b91Sopenharmony_ci /// `IORING_REGISTER_FILES` 126b8a62b91Sopenharmony_ci RegisterFiles = sys::IORING_REGISTER_FILES as _, 127b8a62b91Sopenharmony_ci 128b8a62b91Sopenharmony_ci /// `IORING_UNREGISTER_FILES` 129b8a62b91Sopenharmony_ci UnregisterFiles = sys::IORING_UNREGISTER_FILES as _, 130b8a62b91Sopenharmony_ci 131b8a62b91Sopenharmony_ci /// `IORING_REGISTER_EVENTFD` 132b8a62b91Sopenharmony_ci RegisterEventfd = sys::IORING_REGISTER_EVENTFD as _, 133b8a62b91Sopenharmony_ci 134b8a62b91Sopenharmony_ci /// `IORING_UNREGISTER_EVENTFD` 135b8a62b91Sopenharmony_ci UnregisterEventfd = sys::IORING_UNREGISTER_EVENTFD as _, 136b8a62b91Sopenharmony_ci 137b8a62b91Sopenharmony_ci /// `IORING_REGISTER_FILES_UPDATE` 138b8a62b91Sopenharmony_ci RegisterFilesUpdate = sys::IORING_REGISTER_FILES_UPDATE as _, 139b8a62b91Sopenharmony_ci 140b8a62b91Sopenharmony_ci /// `IORING_REGISTER_EVENTFD_ASYNC` 141b8a62b91Sopenharmony_ci RegisterEventfdAsync = sys::IORING_REGISTER_EVENTFD_ASYNC as _, 142b8a62b91Sopenharmony_ci 143b8a62b91Sopenharmony_ci /// `IORING_REGISTER_PROBE` 144b8a62b91Sopenharmony_ci RegisterProbe = sys::IORING_REGISTER_PROBE as _, 145b8a62b91Sopenharmony_ci 146b8a62b91Sopenharmony_ci /// `IORING_REGISTER_PERSONALITY` 147b8a62b91Sopenharmony_ci RegisterPersonality = sys::IORING_REGISTER_PERSONALITY as _, 148b8a62b91Sopenharmony_ci 149b8a62b91Sopenharmony_ci /// `IORING_UNREGISTER_PERSONALITY` 150b8a62b91Sopenharmony_ci UnregisterPersonality = sys::IORING_UNREGISTER_PERSONALITY as _, 151b8a62b91Sopenharmony_ci 152b8a62b91Sopenharmony_ci /// `IORING_REGISTER_RESTRICTIONS` 153b8a62b91Sopenharmony_ci RegisterRestrictions = sys::IORING_REGISTER_RESTRICTIONS as _, 154b8a62b91Sopenharmony_ci 155b8a62b91Sopenharmony_ci /// `IORING_REGISTER_ENABLE_RINGS` 156b8a62b91Sopenharmony_ci RegisterEnableRings = sys::IORING_REGISTER_ENABLE_RINGS as _, 157b8a62b91Sopenharmony_ci 158b8a62b91Sopenharmony_ci /// `IORING_REGISTER_BUFFERS2` 159b8a62b91Sopenharmony_ci RegisterBuffers2 = sys::IORING_REGISTER_BUFFERS2 as _, 160b8a62b91Sopenharmony_ci 161b8a62b91Sopenharmony_ci /// `IORING_REGISTER_BUFFERS_UPDATE` 162b8a62b91Sopenharmony_ci RegisterBuffersUpdate = sys::IORING_REGISTER_BUFFERS_UPDATE as _, 163b8a62b91Sopenharmony_ci 164b8a62b91Sopenharmony_ci /// `IORING_REGISTER_FILES2` 165b8a62b91Sopenharmony_ci RegisterFiles2 = sys::IORING_REGISTER_FILES2 as _, 166b8a62b91Sopenharmony_ci 167b8a62b91Sopenharmony_ci /// `IORING_REGISTER_FILES_SKIP` 168b8a62b91Sopenharmony_ci RegisterFilesSkip = sys::IORING_REGISTER_FILES_SKIP as _, 169b8a62b91Sopenharmony_ci 170b8a62b91Sopenharmony_ci /// `IORING_REGISTER_FILES_UPDATE2` 171b8a62b91Sopenharmony_ci RegisterFilesUpdate2 = sys::IORING_REGISTER_FILES_UPDATE2 as _, 172b8a62b91Sopenharmony_ci 173b8a62b91Sopenharmony_ci /// `IORING_REGISTER_IOWQ_AFF` 174b8a62b91Sopenharmony_ci RegisterIowqAff = sys::IORING_REGISTER_IOWQ_AFF as _, 175b8a62b91Sopenharmony_ci 176b8a62b91Sopenharmony_ci /// `IORING_UNREGISTER_IOWQ_AFF` 177b8a62b91Sopenharmony_ci UnregisterIowqAff = sys::IORING_UNREGISTER_IOWQ_AFF as _, 178b8a62b91Sopenharmony_ci 179b8a62b91Sopenharmony_ci /// `IORING_REGISTER_IOWQ_MAX_WORKERS` 180b8a62b91Sopenharmony_ci RegisterIowqMaxWorkers = sys::IORING_REGISTER_IOWQ_MAX_WORKERS as _, 181b8a62b91Sopenharmony_ci} 182b8a62b91Sopenharmony_ci 183b8a62b91Sopenharmony_ci/// `IORING_OP_*` constants for use with [`io_uring_sqe`]. 184b8a62b91Sopenharmony_ci#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] 185b8a62b91Sopenharmony_ci#[repr(u8)] 186b8a62b91Sopenharmony_ci#[non_exhaustive] 187b8a62b91Sopenharmony_cipub enum IoringOp { 188b8a62b91Sopenharmony_ci /// `IORING_OP_NOP` 189b8a62b91Sopenharmony_ci Nop = sys::IORING_OP_NOP as _, 190b8a62b91Sopenharmony_ci 191b8a62b91Sopenharmony_ci /// `IORING_OP_ACCEPT` 192b8a62b91Sopenharmony_ci Accept = sys::IORING_OP_ACCEPT as _, 193b8a62b91Sopenharmony_ci 194b8a62b91Sopenharmony_ci /// `IORING_OP_ASYNC_CANCEL` 195b8a62b91Sopenharmony_ci AsyncCancel = sys::IORING_OP_ASYNC_CANCEL as _, 196b8a62b91Sopenharmony_ci 197b8a62b91Sopenharmony_ci /// `IORING_OP_CLOSE` 198b8a62b91Sopenharmony_ci Close = sys::IORING_OP_CLOSE as _, 199b8a62b91Sopenharmony_ci 200b8a62b91Sopenharmony_ci /// `IORING_OP_CONNECT` 201b8a62b91Sopenharmony_ci Connect = sys::IORING_OP_CONNECT as _, 202b8a62b91Sopenharmony_ci 203b8a62b91Sopenharmony_ci /// `IORING_OP_EPOLL_CTL` 204b8a62b91Sopenharmony_ci EpollCtl = sys::IORING_OP_EPOLL_CTL as _, 205b8a62b91Sopenharmony_ci 206b8a62b91Sopenharmony_ci /// `IORING_OP_FADVISE` 207b8a62b91Sopenharmony_ci Fadvise = sys::IORING_OP_FADVISE as _, 208b8a62b91Sopenharmony_ci 209b8a62b91Sopenharmony_ci /// `IORING_OP_FALLOCATE` 210b8a62b91Sopenharmony_ci Fallocate = sys::IORING_OP_FALLOCATE as _, 211b8a62b91Sopenharmony_ci 212b8a62b91Sopenharmony_ci /// `IORING_OP_FILES_UPDATE` 213b8a62b91Sopenharmony_ci FilesUpdate = sys::IORING_OP_FILES_UPDATE as _, 214b8a62b91Sopenharmony_ci 215b8a62b91Sopenharmony_ci /// `IORING_OP_FSYNC` 216b8a62b91Sopenharmony_ci Fsync = sys::IORING_OP_FSYNC as _, 217b8a62b91Sopenharmony_ci 218b8a62b91Sopenharmony_ci /// `IORING_OP_LINKAT` 219b8a62b91Sopenharmony_ci Linkat = sys::IORING_OP_LINKAT as _, 220b8a62b91Sopenharmony_ci 221b8a62b91Sopenharmony_ci /// `IORING_OP_LINK_TIMEOUT` 222b8a62b91Sopenharmony_ci LinkTimeout = sys::IORING_OP_LINK_TIMEOUT as _, 223b8a62b91Sopenharmony_ci 224b8a62b91Sopenharmony_ci /// `IORING_OP_MADVISE` 225b8a62b91Sopenharmony_ci Madvise = sys::IORING_OP_MADVISE as _, 226b8a62b91Sopenharmony_ci 227b8a62b91Sopenharmony_ci /// `IORING_OP_MKDIRAT` 228b8a62b91Sopenharmony_ci Mkdirat = sys::IORING_OP_MKDIRAT as _, 229b8a62b91Sopenharmony_ci 230b8a62b91Sopenharmony_ci /// `IORING_OP_OPENAT` 231b8a62b91Sopenharmony_ci Openat = sys::IORING_OP_OPENAT as _, 232b8a62b91Sopenharmony_ci 233b8a62b91Sopenharmony_ci /// `IORING_OP_OPENAT2` 234b8a62b91Sopenharmony_ci Openat2 = sys::IORING_OP_OPENAT2 as _, 235b8a62b91Sopenharmony_ci 236b8a62b91Sopenharmony_ci /// `IORING_OP_POLL_ADD` 237b8a62b91Sopenharmony_ci PollAdd = sys::IORING_OP_POLL_ADD as _, 238b8a62b91Sopenharmony_ci 239b8a62b91Sopenharmony_ci /// `IORING_OP_POLL_REMOVE` 240b8a62b91Sopenharmony_ci PollRemove = sys::IORING_OP_POLL_REMOVE as _, 241b8a62b91Sopenharmony_ci 242b8a62b91Sopenharmony_ci /// `IORING_OP_PROVIDE_BUFFERS` 243b8a62b91Sopenharmony_ci ProvideBuffers = sys::IORING_OP_PROVIDE_BUFFERS as _, 244b8a62b91Sopenharmony_ci 245b8a62b91Sopenharmony_ci /// `IORING_OP_READ` 246b8a62b91Sopenharmony_ci Read = sys::IORING_OP_READ as _, 247b8a62b91Sopenharmony_ci 248b8a62b91Sopenharmony_ci /// `IORING_OP_READV` 249b8a62b91Sopenharmony_ci Readv = sys::IORING_OP_READV as _, 250b8a62b91Sopenharmony_ci 251b8a62b91Sopenharmony_ci /// `IORING_OP_READ_FIXED` 252b8a62b91Sopenharmony_ci ReadFixed = sys::IORING_OP_READ_FIXED as _, 253b8a62b91Sopenharmony_ci 254b8a62b91Sopenharmony_ci /// `IORING_OP_RECV` 255b8a62b91Sopenharmony_ci Recv = sys::IORING_OP_RECV as _, 256b8a62b91Sopenharmony_ci 257b8a62b91Sopenharmony_ci /// `IORING_OP_RECVMSG` 258b8a62b91Sopenharmony_ci Recvmsg = sys::IORING_OP_RECVMSG as _, 259b8a62b91Sopenharmony_ci 260b8a62b91Sopenharmony_ci /// `IORING_OP_REMOVE_BUFFERS` 261b8a62b91Sopenharmony_ci RemoveBuffers = sys::IORING_OP_REMOVE_BUFFERS as _, 262b8a62b91Sopenharmony_ci 263b8a62b91Sopenharmony_ci /// `IORING_OP_RENAMEAT` 264b8a62b91Sopenharmony_ci Renameat = sys::IORING_OP_RENAMEAT as _, 265b8a62b91Sopenharmony_ci 266b8a62b91Sopenharmony_ci /// `IORING_OP_SEND` 267b8a62b91Sopenharmony_ci Send = sys::IORING_OP_SEND as _, 268b8a62b91Sopenharmony_ci 269b8a62b91Sopenharmony_ci /// `IORING_OP_SENDMSG` 270b8a62b91Sopenharmony_ci Sendmsg = sys::IORING_OP_SENDMSG as _, 271b8a62b91Sopenharmony_ci 272b8a62b91Sopenharmony_ci /// `IORING_OP_SHUTDOWN` 273b8a62b91Sopenharmony_ci Shutdown = sys::IORING_OP_SHUTDOWN as _, 274b8a62b91Sopenharmony_ci 275b8a62b91Sopenharmony_ci /// `IORING_OP_SPLICE` 276b8a62b91Sopenharmony_ci Splice = sys::IORING_OP_SPLICE as _, 277b8a62b91Sopenharmony_ci 278b8a62b91Sopenharmony_ci /// `IORING_OP_STATX` 279b8a62b91Sopenharmony_ci Statx = sys::IORING_OP_STATX as _, 280b8a62b91Sopenharmony_ci 281b8a62b91Sopenharmony_ci /// `IORING_OP_SYMLINKAT` 282b8a62b91Sopenharmony_ci Symlinkat = sys::IORING_OP_SYMLINKAT as _, 283b8a62b91Sopenharmony_ci 284b8a62b91Sopenharmony_ci /// `IORING_OP_SYNC_FILE_RANGE` 285b8a62b91Sopenharmony_ci SyncFileRange = sys::IORING_OP_SYNC_FILE_RANGE as _, 286b8a62b91Sopenharmony_ci 287b8a62b91Sopenharmony_ci /// `IORING_OP_TEE` 288b8a62b91Sopenharmony_ci Tee = sys::IORING_OP_TEE as _, 289b8a62b91Sopenharmony_ci 290b8a62b91Sopenharmony_ci /// `IORING_OP_TIMEOUT` 291b8a62b91Sopenharmony_ci Timeout = sys::IORING_OP_TIMEOUT as _, 292b8a62b91Sopenharmony_ci 293b8a62b91Sopenharmony_ci /// `IORING_OP_TIMEOUT_REMOVE` 294b8a62b91Sopenharmony_ci TimeoutRemove = sys::IORING_OP_TIMEOUT_REMOVE as _, 295b8a62b91Sopenharmony_ci 296b8a62b91Sopenharmony_ci /// `IORING_OP_UNLINKAT` 297b8a62b91Sopenharmony_ci Unlinkat = sys::IORING_OP_UNLINKAT as _, 298b8a62b91Sopenharmony_ci 299b8a62b91Sopenharmony_ci /// `IORING_OP_WRITE` 300b8a62b91Sopenharmony_ci Write = sys::IORING_OP_WRITE as _, 301b8a62b91Sopenharmony_ci 302b8a62b91Sopenharmony_ci /// `IORING_OP_WRITEV` 303b8a62b91Sopenharmony_ci Writev = sys::IORING_OP_WRITEV as _, 304b8a62b91Sopenharmony_ci 305b8a62b91Sopenharmony_ci /// `IORING_OP_WRITE_FIXED` 306b8a62b91Sopenharmony_ci WriteFixed = sys::IORING_OP_WRITE_FIXED as _, 307b8a62b91Sopenharmony_ci} 308b8a62b91Sopenharmony_ci 309b8a62b91Sopenharmony_ciimpl Default for IoringOp { 310b8a62b91Sopenharmony_ci #[inline] 311b8a62b91Sopenharmony_ci fn default() -> Self { 312b8a62b91Sopenharmony_ci Self::Nop 313b8a62b91Sopenharmony_ci } 314b8a62b91Sopenharmony_ci} 315b8a62b91Sopenharmony_ci 316b8a62b91Sopenharmony_ci/// `IORING_RESTRICTION_*` constants for use with [`io_uring_restriction`]. 317b8a62b91Sopenharmony_ci#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] 318b8a62b91Sopenharmony_ci#[repr(u16)] 319b8a62b91Sopenharmony_ci#[non_exhaustive] 320b8a62b91Sopenharmony_cipub enum IoringRestrictionOp { 321b8a62b91Sopenharmony_ci /// `IORING_RESTRICTION_REGISTER_OP` 322b8a62b91Sopenharmony_ci RegisterOp = sys::IORING_RESTRICTION_REGISTER_OP as _, 323b8a62b91Sopenharmony_ci 324b8a62b91Sopenharmony_ci /// `IORING_RESTRICTION_SQE_FLAGS_ALLOWED` 325b8a62b91Sopenharmony_ci SqeFlagsAllowed = sys::IORING_RESTRICTION_SQE_FLAGS_ALLOWED as _, 326b8a62b91Sopenharmony_ci 327b8a62b91Sopenharmony_ci /// `IORING_RESTRICTION_SQE_FLAGS_REQUIRED` 328b8a62b91Sopenharmony_ci SqeFlagsRequired = sys::IORING_RESTRICTION_SQE_FLAGS_REQUIRED as _, 329b8a62b91Sopenharmony_ci 330b8a62b91Sopenharmony_ci /// `IORING_RESTRICTION_SQE_OP` 331b8a62b91Sopenharmony_ci SqeOp = sys::IORING_RESTRICTION_SQE_OP as _, 332b8a62b91Sopenharmony_ci} 333b8a62b91Sopenharmony_ci 334b8a62b91Sopenharmony_ciimpl Default for IoringRestrictionOp { 335b8a62b91Sopenharmony_ci #[inline] 336b8a62b91Sopenharmony_ci fn default() -> Self { 337b8a62b91Sopenharmony_ci Self::RegisterOp 338b8a62b91Sopenharmony_ci } 339b8a62b91Sopenharmony_ci} 340b8a62b91Sopenharmony_ci 341b8a62b91Sopenharmony_cibitflags::bitflags! { 342b8a62b91Sopenharmony_ci /// `IORING_SETUP_*` flags for use with [`io_uring_params`]. 343b8a62b91Sopenharmony_ci #[derive(Default)] 344b8a62b91Sopenharmony_ci pub struct IoringSetupFlags: u32 { 345b8a62b91Sopenharmony_ci /// `IORING_SETUP_ATTACH_WQ` 346b8a62b91Sopenharmony_ci const ATTACH_WQ = sys::IORING_SETUP_ATTACH_WQ; 347b8a62b91Sopenharmony_ci 348b8a62b91Sopenharmony_ci /// `IORING_SETUP_CLAMP` 349b8a62b91Sopenharmony_ci const CLAMP = sys::IORING_SETUP_CLAMP; 350b8a62b91Sopenharmony_ci 351b8a62b91Sopenharmony_ci /// `IORING_SETUP_CQSIZE` 352b8a62b91Sopenharmony_ci const CQSIZE = sys::IORING_SETUP_CQSIZE; 353b8a62b91Sopenharmony_ci 354b8a62b91Sopenharmony_ci /// `IORING_SETUP_IOPOLL` 355b8a62b91Sopenharmony_ci const IOPOLL = sys::IORING_SETUP_IOPOLL; 356b8a62b91Sopenharmony_ci 357b8a62b91Sopenharmony_ci /// `IORING_SETUP_R_DISABLED` 358b8a62b91Sopenharmony_ci const R_DISABLED = sys::IORING_SETUP_R_DISABLED; 359b8a62b91Sopenharmony_ci 360b8a62b91Sopenharmony_ci /// `IORING_SETUP_SQPOLL` 361b8a62b91Sopenharmony_ci const SQPOLL = sys::IORING_SETUP_SQPOLL; 362b8a62b91Sopenharmony_ci 363b8a62b91Sopenharmony_ci /// `IORING_SETUP_SQ_AFF` 364b8a62b91Sopenharmony_ci const SQ_AFF = sys::IORING_SETUP_SQ_AFF; 365b8a62b91Sopenharmony_ci } 366b8a62b91Sopenharmony_ci} 367b8a62b91Sopenharmony_ci 368b8a62b91Sopenharmony_cibitflags::bitflags! { 369b8a62b91Sopenharmony_ci /// `IOSQE_*` flags for use with [`io_uring_sqe`]. 370b8a62b91Sopenharmony_ci #[derive(Default)] 371b8a62b91Sopenharmony_ci pub struct IoringSqeFlags: u8 { 372b8a62b91Sopenharmony_ci /// `1 << IOSQE_ASYNC_BIT` 373b8a62b91Sopenharmony_ci const ASYNC = 1 << sys::IOSQE_ASYNC_BIT as u8; 374b8a62b91Sopenharmony_ci 375b8a62b91Sopenharmony_ci /// `1 << IOSQE_BUFFER_SELECT_BIT` 376b8a62b91Sopenharmony_ci const BUFFER_SELECT = 1 << sys::IOSQE_BUFFER_SELECT_BIT as u8; 377b8a62b91Sopenharmony_ci 378b8a62b91Sopenharmony_ci /// `1 << IOSQE_FIXED_FILE_BIT` 379b8a62b91Sopenharmony_ci const FIXED_FILE = 1 << sys::IOSQE_FIXED_FILE_BIT as u8; 380b8a62b91Sopenharmony_ci 381b8a62b91Sopenharmony_ci /// 1 << `IOSQE_IO_DRAIN_BIT` 382b8a62b91Sopenharmony_ci const IO_DRAIN = 1 << sys::IOSQE_IO_DRAIN_BIT as u8; 383b8a62b91Sopenharmony_ci 384b8a62b91Sopenharmony_ci /// `1 << IOSQE_IO_HARDLINK_BIT` 385b8a62b91Sopenharmony_ci const IO_HARDLINK = 1 << sys::IOSQE_IO_HARDLINK_BIT as u8; 386b8a62b91Sopenharmony_ci 387b8a62b91Sopenharmony_ci /// `1 << IOSQE_IO_LINK_BIT` 388b8a62b91Sopenharmony_ci const IO_LINK = 1 << sys::IOSQE_IO_LINK_BIT as u8; 389b8a62b91Sopenharmony_ci } 390b8a62b91Sopenharmony_ci} 391b8a62b91Sopenharmony_ci 392b8a62b91Sopenharmony_cibitflags::bitflags! { 393b8a62b91Sopenharmony_ci /// `IORING_CQE_F_*` flags for use with [`io_uring_cqe`]. 394b8a62b91Sopenharmony_ci #[derive(Default)] 395b8a62b91Sopenharmony_ci pub struct IoringCqeFlags: u32 { 396b8a62b91Sopenharmony_ci /// `IORING_CQE_F_BUFFER` 397b8a62b91Sopenharmony_ci const BUFFER = sys::IORING_CQE_F_BUFFER as _; 398b8a62b91Sopenharmony_ci 399b8a62b91Sopenharmony_ci /// `IORING_CQE_F_MORE` 400b8a62b91Sopenharmony_ci const MORE = sys::IORING_CQE_F_MORE as _; 401b8a62b91Sopenharmony_ci } 402b8a62b91Sopenharmony_ci} 403b8a62b91Sopenharmony_ci 404b8a62b91Sopenharmony_cibitflags::bitflags! { 405b8a62b91Sopenharmony_ci /// `IORING_FSYNC_*` flags for use with [`io_uring_sqe`]. 406b8a62b91Sopenharmony_ci #[derive(Default)] 407b8a62b91Sopenharmony_ci pub struct IoringFsyncFlags: u32 { 408b8a62b91Sopenharmony_ci /// `IORING_FSYNC_DATASYNC` 409b8a62b91Sopenharmony_ci const DATASYNC = sys::IORING_FSYNC_DATASYNC; 410b8a62b91Sopenharmony_ci } 411b8a62b91Sopenharmony_ci} 412b8a62b91Sopenharmony_ci 413b8a62b91Sopenharmony_cibitflags::bitflags! { 414b8a62b91Sopenharmony_ci /// `IORING_TIMEOUT_*` and `IORING_LINK_TIMEOUT_UPDATE` flags for use with 415b8a62b91Sopenharmony_ci /// [`io_uring_sqe`]. 416b8a62b91Sopenharmony_ci #[derive(Default)] 417b8a62b91Sopenharmony_ci pub struct IoringTimeoutFlags: u32 { 418b8a62b91Sopenharmony_ci /// `IORING_TIMEOUT_ABS` 419b8a62b91Sopenharmony_ci const ABS = sys::IORING_TIMEOUT_ABS; 420b8a62b91Sopenharmony_ci 421b8a62b91Sopenharmony_ci /// `IORING_TIMEOUT_UPDATE` 422b8a62b91Sopenharmony_ci const UPDATE = sys::IORING_TIMEOUT_UPDATE; 423b8a62b91Sopenharmony_ci 424b8a62b91Sopenharmony_ci /// `IORING_TIMEOUT_BOOTTIME` 425b8a62b91Sopenharmony_ci const BOOTTIME = sys::IORING_TIMEOUT_BOOTTIME; 426b8a62b91Sopenharmony_ci 427b8a62b91Sopenharmony_ci /// `IORING_TIMEOUT_ETIME_SUCCESS` 428b8a62b91Sopenharmony_ci const ETIME_SUCCESS = sys::IORING_TIMEOUT_ETIME_SUCCESS; 429b8a62b91Sopenharmony_ci 430b8a62b91Sopenharmony_ci /// `IORING_TIMEOUT_REALTIME` 431b8a62b91Sopenharmony_ci const REALTIME = sys::IORING_TIMEOUT_REALTIME; 432b8a62b91Sopenharmony_ci 433b8a62b91Sopenharmony_ci /// `IORING_TIMEOUT_CLOCK_MASK` 434b8a62b91Sopenharmony_ci const CLOCK_MASK = sys::IORING_TIMEOUT_CLOCK_MASK; 435b8a62b91Sopenharmony_ci 436b8a62b91Sopenharmony_ci /// `IORING_TIMEOUT_UPDATE_MASK` 437b8a62b91Sopenharmony_ci const UPDATE_MASK = sys::IORING_TIMEOUT_UPDATE_MASK; 438b8a62b91Sopenharmony_ci 439b8a62b91Sopenharmony_ci /// `IORING_LINK_TIMEOUT_UPDATE` 440b8a62b91Sopenharmony_ci const LINK_TIMEOUT_UPDATE = sys::IORING_LINK_TIMEOUT_UPDATE; 441b8a62b91Sopenharmony_ci } 442b8a62b91Sopenharmony_ci} 443b8a62b91Sopenharmony_ci 444b8a62b91Sopenharmony_cibitflags::bitflags! { 445b8a62b91Sopenharmony_ci /// `SPLICE_F_*` flags for use with [`io_uring_sqe`]. 446b8a62b91Sopenharmony_ci #[derive(Default)] 447b8a62b91Sopenharmony_ci pub struct SpliceFlags: u32 { 448b8a62b91Sopenharmony_ci /// `SPLICE_F_FD_IN_FIXED` 449b8a62b91Sopenharmony_ci const FD_IN_FIXED = sys::SPLICE_F_FD_IN_FIXED; 450b8a62b91Sopenharmony_ci } 451b8a62b91Sopenharmony_ci} 452b8a62b91Sopenharmony_ci 453b8a62b91Sopenharmony_cibitflags::bitflags! { 454b8a62b91Sopenharmony_ci /// `IORING_FEAT_*` flags for use with [`io_uring_params`]. 455b8a62b91Sopenharmony_ci #[derive(Default)] 456b8a62b91Sopenharmony_ci pub struct IoringFeatureFlags: u32 { 457b8a62b91Sopenharmony_ci /// `IORING_FEAT_CQE_SKIP` 458b8a62b91Sopenharmony_ci const CQE_SKIP = sys::IORING_FEAT_CQE_SKIP; 459b8a62b91Sopenharmony_ci 460b8a62b91Sopenharmony_ci /// `IORING_FEAT_CUR_PERSONALITY` 461b8a62b91Sopenharmony_ci const CUR_PERSONALITY = sys::IORING_FEAT_CUR_PERSONALITY; 462b8a62b91Sopenharmony_ci 463b8a62b91Sopenharmony_ci /// `IORING_FEAT_EXT_ARG` 464b8a62b91Sopenharmony_ci const EXT_ARG = sys::IORING_FEAT_EXT_ARG; 465b8a62b91Sopenharmony_ci 466b8a62b91Sopenharmony_ci /// `IORING_FEAT_FAST_POLL` 467b8a62b91Sopenharmony_ci const FAST_POLL = sys::IORING_FEAT_FAST_POLL; 468b8a62b91Sopenharmony_ci 469b8a62b91Sopenharmony_ci /// `IORING_FEAT_NATIVE_WORKERS` 470b8a62b91Sopenharmony_ci const NATIVE_WORKERS = sys::IORING_FEAT_NATIVE_WORKERS; 471b8a62b91Sopenharmony_ci 472b8a62b91Sopenharmony_ci /// `IORING_FEAT_NODROP` 473b8a62b91Sopenharmony_ci const NODROP = sys::IORING_FEAT_NODROP; 474b8a62b91Sopenharmony_ci 475b8a62b91Sopenharmony_ci /// `IORING_FEAT_POLL_32BITS` 476b8a62b91Sopenharmony_ci const POLL_32BITS = sys::IORING_FEAT_POLL_32BITS; 477b8a62b91Sopenharmony_ci 478b8a62b91Sopenharmony_ci /// `IORING_FEAT_RSRC_TAGS` 479b8a62b91Sopenharmony_ci const RSRC_TAGS = sys::IORING_FEAT_RSRC_TAGS; 480b8a62b91Sopenharmony_ci 481b8a62b91Sopenharmony_ci /// `IORING_FEAT_RW_CUR_POS` 482b8a62b91Sopenharmony_ci const RW_CUR_POS = sys::IORING_FEAT_RW_CUR_POS; 483b8a62b91Sopenharmony_ci 484b8a62b91Sopenharmony_ci /// `IORING_FEAT_SINGLE_MMAP` 485b8a62b91Sopenharmony_ci const SINGLE_MMAP = sys::IORING_FEAT_SINGLE_MMAP; 486b8a62b91Sopenharmony_ci 487b8a62b91Sopenharmony_ci /// `IORING_FEAT_SQPOLL_NONFIXED` 488b8a62b91Sopenharmony_ci const SQPOLL_NONFIXED = sys::IORING_FEAT_SQPOLL_NONFIXED; 489b8a62b91Sopenharmony_ci 490b8a62b91Sopenharmony_ci /// `IORING_FEAT_SUBMIT_STABLE` 491b8a62b91Sopenharmony_ci const SUBMIT_STABLE = sys::IORING_FEAT_SUBMIT_STABLE; 492b8a62b91Sopenharmony_ci } 493b8a62b91Sopenharmony_ci} 494b8a62b91Sopenharmony_ci 495b8a62b91Sopenharmony_cibitflags::bitflags! { 496b8a62b91Sopenharmony_ci /// `IO_URING_OP_*` flags for use with [`io_uring_probe_op`]. 497b8a62b91Sopenharmony_ci #[derive(Default)] 498b8a62b91Sopenharmony_ci pub struct IoringOpFlags: u16 { 499b8a62b91Sopenharmony_ci /// `IO_URING_OP_SUPPORTED` 500b8a62b91Sopenharmony_ci const SUPPORTED = sys::IO_URING_OP_SUPPORTED as _; 501b8a62b91Sopenharmony_ci } 502b8a62b91Sopenharmony_ci} 503b8a62b91Sopenharmony_ci 504b8a62b91Sopenharmony_cibitflags::bitflags! { 505b8a62b91Sopenharmony_ci /// `IORING_SQ_*` flags. 506b8a62b91Sopenharmony_ci #[derive(Default)] 507b8a62b91Sopenharmony_ci pub struct IoringSqFlags: u32 { 508b8a62b91Sopenharmony_ci /// `IORING_SQ_NEED_WAKEUP` 509b8a62b91Sopenharmony_ci const NEED_WAKEUP = sys::IORING_SQ_NEED_WAKEUP; 510b8a62b91Sopenharmony_ci 511b8a62b91Sopenharmony_ci /// `IORING_SQ_CQ_OVERFLOW` 512b8a62b91Sopenharmony_ci const CQ_OVERFLOW = sys::IORING_SQ_CQ_OVERFLOW; 513b8a62b91Sopenharmony_ci } 514b8a62b91Sopenharmony_ci} 515b8a62b91Sopenharmony_ci 516b8a62b91Sopenharmony_cibitflags::bitflags! { 517b8a62b91Sopenharmony_ci /// `IORING_CQ_*` flags. 518b8a62b91Sopenharmony_ci #[derive(Default)] 519b8a62b91Sopenharmony_ci pub struct IoringCqFlags: u32 { 520b8a62b91Sopenharmony_ci /// `IORING_CQ_EVENTFD_DISABLED` 521b8a62b91Sopenharmony_ci const EVENTFD_DISABLED = sys::IORING_CQ_EVENTFD_DISABLED; 522b8a62b91Sopenharmony_ci } 523b8a62b91Sopenharmony_ci} 524b8a62b91Sopenharmony_ci 525b8a62b91Sopenharmony_cibitflags::bitflags! { 526b8a62b91Sopenharmony_ci /// `IORING_POLL_*` flags. 527b8a62b91Sopenharmony_ci #[derive(Default)] 528b8a62b91Sopenharmony_ci pub struct IoringPollFlags: u32 { 529b8a62b91Sopenharmony_ci /// `IORING_POLL_ADD_MULTI` 530b8a62b91Sopenharmony_ci const ADD_MULTI = sys::IORING_POLL_ADD_MULTI; 531b8a62b91Sopenharmony_ci 532b8a62b91Sopenharmony_ci /// `IORING_POLL_UPDATE_EVENTS` 533b8a62b91Sopenharmony_ci const UPDATE_EVENTS = sys::IORING_POLL_UPDATE_EVENTS; 534b8a62b91Sopenharmony_ci 535b8a62b91Sopenharmony_ci /// `IORING_POLL_UPDATE_USER_DATA` 536b8a62b91Sopenharmony_ci const UPDATE_USER_DATA = sys::IORING_POLL_UPDATE_USER_DATA; 537b8a62b91Sopenharmony_ci } 538b8a62b91Sopenharmony_ci} 539b8a62b91Sopenharmony_ci 540b8a62b91Sopenharmony_ci#[allow(missing_docs)] 541b8a62b91Sopenharmony_cipub const IORING_CQE_BUFFER_SHIFT: u32 = sys::IORING_CQE_BUFFER_SHIFT as _; 542b8a62b91Sopenharmony_ci 543b8a62b91Sopenharmony_ci// Re-export these as `u64`, which is the `offset` type in `rustix::io::mmap`. 544b8a62b91Sopenharmony_ci#[allow(missing_docs)] 545b8a62b91Sopenharmony_cipub const IORING_OFF_SQ_RING: u64 = sys::IORING_OFF_SQ_RING as _; 546b8a62b91Sopenharmony_ci#[allow(missing_docs)] 547b8a62b91Sopenharmony_cipub const IORING_OFF_CQ_RING: u64 = sys::IORING_OFF_CQ_RING as _; 548b8a62b91Sopenharmony_ci#[allow(missing_docs)] 549b8a62b91Sopenharmony_cipub const IORING_OFF_SQES: u64 = sys::IORING_OFF_SQES as _; 550b8a62b91Sopenharmony_ci 551b8a62b91Sopenharmony_ci/// `IORING_REGISTER_FILES_SKIP` 552b8a62b91Sopenharmony_ci#[inline] 553b8a62b91Sopenharmony_ci#[doc(alias = "IORING_REGISTER_FILES_SKIP")] 554b8a62b91Sopenharmony_cipub const fn io_uring_register_files_skip() -> BorrowedFd<'static> { 555b8a62b91Sopenharmony_ci let files_skip = sys::IORING_REGISTER_FILES_SKIP as RawFd; 556b8a62b91Sopenharmony_ci 557b8a62b91Sopenharmony_ci // Safety: `IORING_REGISTER_FILES_SKIP` is a reserved value that is never 558b8a62b91Sopenharmony_ci // dynamically allocated, so it'll remain valid for the duration of 559b8a62b91Sopenharmony_ci // `'static`. 560b8a62b91Sopenharmony_ci unsafe { BorrowedFd::<'static>::borrow_raw(files_skip) } 561b8a62b91Sopenharmony_ci} 562b8a62b91Sopenharmony_ci 563b8a62b91Sopenharmony_ci/// A pointer in the io_uring API. 564b8a62b91Sopenharmony_ci/// 565b8a62b91Sopenharmony_ci/// `io_uring`'s native API represents pointers as `u64` values. In order to 566b8a62b91Sopenharmony_ci/// preserve strict-provenance, use a `*mut c_void`. On platforms where 567b8a62b91Sopenharmony_ci/// pointers are narrower than 64 bits, this requires additional padding. 568b8a62b91Sopenharmony_ci#[repr(C)] 569b8a62b91Sopenharmony_ci#[derive(Copy, Clone)] 570b8a62b91Sopenharmony_cipub struct io_uring_ptr { 571b8a62b91Sopenharmony_ci #[cfg(all(target_pointer_width = "32", target_endian = "big"))] 572b8a62b91Sopenharmony_ci #[doc(hidden)] 573b8a62b91Sopenharmony_ci pub __pad32: u32, 574b8a62b91Sopenharmony_ci #[cfg(all(target_pointer_width = "16", target_endian = "big"))] 575b8a62b91Sopenharmony_ci #[doc(hidden)] 576b8a62b91Sopenharmony_ci pub __pad16: u16, 577b8a62b91Sopenharmony_ci 578b8a62b91Sopenharmony_ci /// The pointer value. 579b8a62b91Sopenharmony_ci pub ptr: *mut c_void, 580b8a62b91Sopenharmony_ci 581b8a62b91Sopenharmony_ci #[cfg(all(target_pointer_width = "16", target_endian = "little"))] 582b8a62b91Sopenharmony_ci #[doc(hidden)] 583b8a62b91Sopenharmony_ci pub __pad16: u16, 584b8a62b91Sopenharmony_ci #[cfg(all(target_pointer_width = "32", target_endian = "little"))] 585b8a62b91Sopenharmony_ci #[doc(hidden)] 586b8a62b91Sopenharmony_ci pub __pad32: u32, 587b8a62b91Sopenharmony_ci} 588b8a62b91Sopenharmony_ci 589b8a62b91Sopenharmony_ciimpl From<*mut c_void> for io_uring_ptr { 590b8a62b91Sopenharmony_ci #[inline] 591b8a62b91Sopenharmony_ci fn from(ptr: *mut c_void) -> Self { 592b8a62b91Sopenharmony_ci Self { 593b8a62b91Sopenharmony_ci ptr, 594b8a62b91Sopenharmony_ci 595b8a62b91Sopenharmony_ci #[cfg(target_pointer_width = "16")] 596b8a62b91Sopenharmony_ci __pad16: Default::default(), 597b8a62b91Sopenharmony_ci #[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))] 598b8a62b91Sopenharmony_ci __pad32: Default::default(), 599b8a62b91Sopenharmony_ci } 600b8a62b91Sopenharmony_ci } 601b8a62b91Sopenharmony_ci} 602b8a62b91Sopenharmony_ci 603b8a62b91Sopenharmony_ciimpl Default for io_uring_ptr { 604b8a62b91Sopenharmony_ci #[inline] 605b8a62b91Sopenharmony_ci fn default() -> Self { 606b8a62b91Sopenharmony_ci Self::from(null_mut()) 607b8a62b91Sopenharmony_ci } 608b8a62b91Sopenharmony_ci} 609b8a62b91Sopenharmony_ci 610b8a62b91Sopenharmony_ci/// User data in the io_uring API. 611b8a62b91Sopenharmony_ci/// 612b8a62b91Sopenharmony_ci/// `io_uring`'s native API represents `user_data` fields as `u64` values. In 613b8a62b91Sopenharmony_ci/// order to preserve strict-provenance, use a union which allows users to 614b8a62b91Sopenharmony_ci/// optionally store pointers. 615b8a62b91Sopenharmony_ci#[repr(C)] 616b8a62b91Sopenharmony_ci#[derive(Copy, Clone)] 617b8a62b91Sopenharmony_cipub union io_uring_user_data { 618b8a62b91Sopenharmony_ci /// An arbitrary `u64`. 619b8a62b91Sopenharmony_ci pub u64_: u64, 620b8a62b91Sopenharmony_ci 621b8a62b91Sopenharmony_ci /// A pointer. 622b8a62b91Sopenharmony_ci pub ptr: io_uring_ptr, 623b8a62b91Sopenharmony_ci} 624b8a62b91Sopenharmony_ci 625b8a62b91Sopenharmony_ciimpl io_uring_user_data { 626b8a62b91Sopenharmony_ci /// Return the `u64` value. 627b8a62b91Sopenharmony_ci #[inline] 628b8a62b91Sopenharmony_ci pub fn u64_(self) -> u64 { 629b8a62b91Sopenharmony_ci // Safety: All the fields have the same underlying representation. 630b8a62b91Sopenharmony_ci unsafe { self.u64_ } 631b8a62b91Sopenharmony_ci } 632b8a62b91Sopenharmony_ci 633b8a62b91Sopenharmony_ci /// Create a `Self` from a `u64` value. 634b8a62b91Sopenharmony_ci #[inline] 635b8a62b91Sopenharmony_ci pub fn from_u64(u64_: u64) -> Self { 636b8a62b91Sopenharmony_ci Self { u64_ } 637b8a62b91Sopenharmony_ci } 638b8a62b91Sopenharmony_ci 639b8a62b91Sopenharmony_ci /// Return the `ptr` pointer value. 640b8a62b91Sopenharmony_ci #[inline] 641b8a62b91Sopenharmony_ci pub fn ptr(self) -> *mut c_void { 642b8a62b91Sopenharmony_ci // Safety: All the fields have the same underlying representation. 643b8a62b91Sopenharmony_ci unsafe { self.ptr }.ptr 644b8a62b91Sopenharmony_ci } 645b8a62b91Sopenharmony_ci 646b8a62b91Sopenharmony_ci /// Create a `Self` from a pointer value. 647b8a62b91Sopenharmony_ci #[inline] 648b8a62b91Sopenharmony_ci pub fn from_ptr(ptr: *mut c_void) -> Self { 649b8a62b91Sopenharmony_ci Self { 650b8a62b91Sopenharmony_ci ptr: io_uring_ptr::from(ptr), 651b8a62b91Sopenharmony_ci } 652b8a62b91Sopenharmony_ci } 653b8a62b91Sopenharmony_ci} 654b8a62b91Sopenharmony_ci 655b8a62b91Sopenharmony_ciimpl Default for io_uring_user_data { 656b8a62b91Sopenharmony_ci #[inline] 657b8a62b91Sopenharmony_ci fn default() -> Self { 658b8a62b91Sopenharmony_ci let mut s = ::core::mem::MaybeUninit::<Self>::uninit(); 659b8a62b91Sopenharmony_ci // Safety: All of Linux's io_uring structs may be zero-initialized. 660b8a62b91Sopenharmony_ci unsafe { 661b8a62b91Sopenharmony_ci ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); 662b8a62b91Sopenharmony_ci s.assume_init() 663b8a62b91Sopenharmony_ci } 664b8a62b91Sopenharmony_ci } 665b8a62b91Sopenharmony_ci} 666b8a62b91Sopenharmony_ci 667b8a62b91Sopenharmony_ciimpl core::fmt::Debug for io_uring_user_data { 668b8a62b91Sopenharmony_ci fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 669b8a62b91Sopenharmony_ci // Safety: Just format as a `u64`, since formatting doesn't preserve 670b8a62b91Sopenharmony_ci // provenance, and we don't have a discriminant. 671b8a62b91Sopenharmony_ci unsafe { self.u64_.fmt(fmt) } 672b8a62b91Sopenharmony_ci } 673b8a62b91Sopenharmony_ci} 674b8a62b91Sopenharmony_ci 675b8a62b91Sopenharmony_ci/// An io_uring Submission Queue Entry. 676b8a62b91Sopenharmony_ci#[allow(missing_docs)] 677b8a62b91Sopenharmony_ci#[repr(C)] 678b8a62b91Sopenharmony_ci#[derive(Copy, Clone, Default)] 679b8a62b91Sopenharmony_cipub struct io_uring_sqe { 680b8a62b91Sopenharmony_ci pub opcode: IoringOp, 681b8a62b91Sopenharmony_ci pub flags: IoringSqeFlags, 682b8a62b91Sopenharmony_ci pub ioprio: u16, 683b8a62b91Sopenharmony_ci pub fd: RawFd, 684b8a62b91Sopenharmony_ci pub off_or_addr2: off_or_addr2_union, 685b8a62b91Sopenharmony_ci pub addr_or_splice_off_in: addr_or_splice_off_in_union, 686b8a62b91Sopenharmony_ci pub len: u32, 687b8a62b91Sopenharmony_ci pub op_flags: op_flags_union, 688b8a62b91Sopenharmony_ci pub user_data: io_uring_user_data, 689b8a62b91Sopenharmony_ci pub buf: buf_union, 690b8a62b91Sopenharmony_ci pub personality: u16, 691b8a62b91Sopenharmony_ci pub splice_fd_in_or_file_index: splice_fd_in_or_file_index_union, 692b8a62b91Sopenharmony_ci pub __pad2: [u64; 2], 693b8a62b91Sopenharmony_ci} 694b8a62b91Sopenharmony_ci 695b8a62b91Sopenharmony_ci#[allow(missing_docs)] 696b8a62b91Sopenharmony_ci#[repr(C)] 697b8a62b91Sopenharmony_ci#[derive(Copy, Clone)] 698b8a62b91Sopenharmony_cipub union off_or_addr2_union { 699b8a62b91Sopenharmony_ci pub off: u64, 700b8a62b91Sopenharmony_ci pub addr2: io_uring_ptr, 701b8a62b91Sopenharmony_ci} 702b8a62b91Sopenharmony_ci 703b8a62b91Sopenharmony_ci#[allow(missing_docs)] 704b8a62b91Sopenharmony_ci#[repr(C)] 705b8a62b91Sopenharmony_ci#[derive(Copy, Clone)] 706b8a62b91Sopenharmony_cipub union addr_or_splice_off_in_union { 707b8a62b91Sopenharmony_ci pub addr: io_uring_ptr, 708b8a62b91Sopenharmony_ci pub splice_off_in: u64, 709b8a62b91Sopenharmony_ci} 710b8a62b91Sopenharmony_ci 711b8a62b91Sopenharmony_ci#[allow(missing_docs)] 712b8a62b91Sopenharmony_ci#[repr(C)] 713b8a62b91Sopenharmony_ci#[derive(Copy, Clone)] 714b8a62b91Sopenharmony_cipub union op_flags_union { 715b8a62b91Sopenharmony_ci pub rw_flags: crate::io::ReadWriteFlags, 716b8a62b91Sopenharmony_ci pub fsync_flags: IoringFsyncFlags, 717b8a62b91Sopenharmony_ci pub poll_events: u16, 718b8a62b91Sopenharmony_ci pub poll32_events: u32, 719b8a62b91Sopenharmony_ci pub sync_range_flags: u32, 720b8a62b91Sopenharmony_ci /// `msg_flags` is split into `send_flags` and `recv_flags`. 721b8a62b91Sopenharmony_ci #[doc(alias = "msg_flags")] 722b8a62b91Sopenharmony_ci pub send_flags: crate::net::SendFlags, 723b8a62b91Sopenharmony_ci /// `msg_flags` is split into `send_flags` and `recv_flags`. 724b8a62b91Sopenharmony_ci #[doc(alias = "msg_flags")] 725b8a62b91Sopenharmony_ci pub recv_flags: crate::net::RecvFlags, 726b8a62b91Sopenharmony_ci pub timeout_flags: IoringTimeoutFlags, 727b8a62b91Sopenharmony_ci pub accept_flags: crate::net::AcceptFlags, 728b8a62b91Sopenharmony_ci pub cancel_flags: u32, 729b8a62b91Sopenharmony_ci pub open_flags: crate::fs::AtFlags, 730b8a62b91Sopenharmony_ci pub statx_flags: crate::fs::AtFlags, 731b8a62b91Sopenharmony_ci pub fadvise_advice: crate::fs::Advice, 732b8a62b91Sopenharmony_ci pub splice_flags: SpliceFlags, 733b8a62b91Sopenharmony_ci pub rename_flags: crate::fs::RenameFlags, 734b8a62b91Sopenharmony_ci pub unlink_flags: crate::fs::AtFlags, 735b8a62b91Sopenharmony_ci pub hardlink_flags: crate::fs::AtFlags, 736b8a62b91Sopenharmony_ci} 737b8a62b91Sopenharmony_ci 738b8a62b91Sopenharmony_ci#[allow(missing_docs)] 739b8a62b91Sopenharmony_ci#[repr(C, packed)] 740b8a62b91Sopenharmony_ci#[derive(Copy, Clone)] 741b8a62b91Sopenharmony_cipub union buf_union { 742b8a62b91Sopenharmony_ci pub buf_index: u16, 743b8a62b91Sopenharmony_ci pub buf_group: u16, 744b8a62b91Sopenharmony_ci} 745b8a62b91Sopenharmony_ci 746b8a62b91Sopenharmony_ci#[allow(missing_docs)] 747b8a62b91Sopenharmony_ci#[repr(C)] 748b8a62b91Sopenharmony_ci#[derive(Copy, Clone)] 749b8a62b91Sopenharmony_cipub union splice_fd_in_or_file_index_union { 750b8a62b91Sopenharmony_ci pub splice_fd_in: i32, 751b8a62b91Sopenharmony_ci pub file_index: u32, 752b8a62b91Sopenharmony_ci} 753b8a62b91Sopenharmony_ci 754b8a62b91Sopenharmony_ci/// An io_uring Completion Queue Entry. 755b8a62b91Sopenharmony_ci#[allow(missing_docs)] 756b8a62b91Sopenharmony_ci#[repr(C)] 757b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 758b8a62b91Sopenharmony_cipub struct io_uring_cqe { 759b8a62b91Sopenharmony_ci pub user_data: io_uring_user_data, 760b8a62b91Sopenharmony_ci pub res: i32, 761b8a62b91Sopenharmony_ci pub flags: IoringCqeFlags, 762b8a62b91Sopenharmony_ci} 763b8a62b91Sopenharmony_ci 764b8a62b91Sopenharmony_ci#[allow(missing_docs)] 765b8a62b91Sopenharmony_ci#[repr(C)] 766b8a62b91Sopenharmony_ci#[derive(Copy, Clone, Default)] 767b8a62b91Sopenharmony_cipub struct io_uring_restriction { 768b8a62b91Sopenharmony_ci pub opcode: IoringRestrictionOp, 769b8a62b91Sopenharmony_ci pub register_or_sqe_op_or_sqe_flags: register_or_sqe_op_or_sqe_flags_union, 770b8a62b91Sopenharmony_ci pub resv: u8, 771b8a62b91Sopenharmony_ci pub resv2: [u32; 3], 772b8a62b91Sopenharmony_ci} 773b8a62b91Sopenharmony_ci 774b8a62b91Sopenharmony_ci#[allow(missing_docs)] 775b8a62b91Sopenharmony_ci#[repr(C)] 776b8a62b91Sopenharmony_ci#[derive(Copy, Clone)] 777b8a62b91Sopenharmony_cipub union register_or_sqe_op_or_sqe_flags_union { 778b8a62b91Sopenharmony_ci pub register_op: IoringRegisterOp, 779b8a62b91Sopenharmony_ci pub sqe_op: IoringOp, 780b8a62b91Sopenharmony_ci pub sqe_flags: IoringSqeFlags, 781b8a62b91Sopenharmony_ci} 782b8a62b91Sopenharmony_ci 783b8a62b91Sopenharmony_ci#[allow(missing_docs)] 784b8a62b91Sopenharmony_ci#[repr(C)] 785b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 786b8a62b91Sopenharmony_cipub struct io_uring_params { 787b8a62b91Sopenharmony_ci pub sq_entries: u32, 788b8a62b91Sopenharmony_ci pub cq_entries: u32, 789b8a62b91Sopenharmony_ci pub flags: IoringSetupFlags, 790b8a62b91Sopenharmony_ci pub sq_thread_cpu: u32, 791b8a62b91Sopenharmony_ci pub sq_thread_idle: u32, 792b8a62b91Sopenharmony_ci pub features: IoringFeatureFlags, 793b8a62b91Sopenharmony_ci pub wq_fd: u32, 794b8a62b91Sopenharmony_ci pub resv: [u32; 3], 795b8a62b91Sopenharmony_ci pub sq_off: io_sqring_offsets, 796b8a62b91Sopenharmony_ci pub cq_off: io_cqring_offsets, 797b8a62b91Sopenharmony_ci} 798b8a62b91Sopenharmony_ci 799b8a62b91Sopenharmony_ci#[allow(missing_docs)] 800b8a62b91Sopenharmony_ci#[repr(C)] 801b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 802b8a62b91Sopenharmony_cipub struct io_sqring_offsets { 803b8a62b91Sopenharmony_ci pub head: u32, 804b8a62b91Sopenharmony_ci pub tail: u32, 805b8a62b91Sopenharmony_ci pub ring_mask: u32, 806b8a62b91Sopenharmony_ci pub ring_entries: u32, 807b8a62b91Sopenharmony_ci pub flags: u32, 808b8a62b91Sopenharmony_ci pub dropped: u32, 809b8a62b91Sopenharmony_ci pub array: u32, 810b8a62b91Sopenharmony_ci pub resv1: u32, 811b8a62b91Sopenharmony_ci pub resv2: u64, 812b8a62b91Sopenharmony_ci} 813b8a62b91Sopenharmony_ci 814b8a62b91Sopenharmony_ci#[allow(missing_docs)] 815b8a62b91Sopenharmony_ci#[repr(C)] 816b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 817b8a62b91Sopenharmony_cipub struct io_cqring_offsets { 818b8a62b91Sopenharmony_ci pub head: u32, 819b8a62b91Sopenharmony_ci pub tail: u32, 820b8a62b91Sopenharmony_ci pub ring_mask: u32, 821b8a62b91Sopenharmony_ci pub ring_entries: u32, 822b8a62b91Sopenharmony_ci pub overflow: u32, 823b8a62b91Sopenharmony_ci pub cqes: u32, 824b8a62b91Sopenharmony_ci pub flags: u32, 825b8a62b91Sopenharmony_ci pub resv1: u32, 826b8a62b91Sopenharmony_ci pub resv2: u64, 827b8a62b91Sopenharmony_ci} 828b8a62b91Sopenharmony_ci 829b8a62b91Sopenharmony_ci#[allow(missing_docs)] 830b8a62b91Sopenharmony_ci#[repr(C)] 831b8a62b91Sopenharmony_ci#[derive(Debug, Default)] 832b8a62b91Sopenharmony_cipub struct io_uring_probe { 833b8a62b91Sopenharmony_ci pub last_op: IoringOp, 834b8a62b91Sopenharmony_ci pub ops_len: u8, 835b8a62b91Sopenharmony_ci pub resv: u16, 836b8a62b91Sopenharmony_ci pub resv2: [u32; 3], 837b8a62b91Sopenharmony_ci pub ops: sys::__IncompleteArrayField<io_uring_probe_op>, 838b8a62b91Sopenharmony_ci} 839b8a62b91Sopenharmony_ci 840b8a62b91Sopenharmony_ci#[allow(missing_docs)] 841b8a62b91Sopenharmony_ci#[repr(C)] 842b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 843b8a62b91Sopenharmony_cipub struct io_uring_probe_op { 844b8a62b91Sopenharmony_ci pub op: IoringOp, 845b8a62b91Sopenharmony_ci pub resv: u8, 846b8a62b91Sopenharmony_ci pub flags: IoringOpFlags, 847b8a62b91Sopenharmony_ci pub resv2: u32, 848b8a62b91Sopenharmony_ci} 849b8a62b91Sopenharmony_ci 850b8a62b91Sopenharmony_ci#[allow(missing_docs)] 851b8a62b91Sopenharmony_ci#[repr(C, align(8))] 852b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 853b8a62b91Sopenharmony_cipub struct io_uring_files_update { 854b8a62b91Sopenharmony_ci pub offset: u32, 855b8a62b91Sopenharmony_ci pub resv: u32, 856b8a62b91Sopenharmony_ci pub fds: u64, 857b8a62b91Sopenharmony_ci} 858b8a62b91Sopenharmony_ci 859b8a62b91Sopenharmony_ci#[allow(missing_docs)] 860b8a62b91Sopenharmony_ci#[repr(C, align(8))] 861b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 862b8a62b91Sopenharmony_cipub struct io_uring_rsrc_register { 863b8a62b91Sopenharmony_ci pub nr: u32, 864b8a62b91Sopenharmony_ci pub resv: u32, 865b8a62b91Sopenharmony_ci pub resv2: u64, 866b8a62b91Sopenharmony_ci pub data: u64, 867b8a62b91Sopenharmony_ci pub tags: u64, 868b8a62b91Sopenharmony_ci} 869b8a62b91Sopenharmony_ci 870b8a62b91Sopenharmony_ci#[allow(missing_docs)] 871b8a62b91Sopenharmony_ci#[repr(C, align(8))] 872b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 873b8a62b91Sopenharmony_cipub struct io_uring_rsrc_update { 874b8a62b91Sopenharmony_ci pub offset: u32, 875b8a62b91Sopenharmony_ci pub resv: u32, 876b8a62b91Sopenharmony_ci pub data: u64, 877b8a62b91Sopenharmony_ci} 878b8a62b91Sopenharmony_ci 879b8a62b91Sopenharmony_ci#[allow(missing_docs)] 880b8a62b91Sopenharmony_ci#[repr(C, align(8))] 881b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 882b8a62b91Sopenharmony_cipub struct io_uring_rsrc_update2 { 883b8a62b91Sopenharmony_ci pub offset: u32, 884b8a62b91Sopenharmony_ci pub resv: u32, 885b8a62b91Sopenharmony_ci pub data: u64, 886b8a62b91Sopenharmony_ci pub tags: u64, 887b8a62b91Sopenharmony_ci pub nr: u32, 888b8a62b91Sopenharmony_ci pub resv2: u32, 889b8a62b91Sopenharmony_ci} 890b8a62b91Sopenharmony_ci 891b8a62b91Sopenharmony_ci#[allow(missing_docs)] 892b8a62b91Sopenharmony_ci#[repr(C)] 893b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 894b8a62b91Sopenharmony_cipub struct io_uring_getevents_arg { 895b8a62b91Sopenharmony_ci pub sigmask: u64, 896b8a62b91Sopenharmony_ci pub sigmask_sz: u32, 897b8a62b91Sopenharmony_ci pub pad: u32, 898b8a62b91Sopenharmony_ci pub ts: u64, 899b8a62b91Sopenharmony_ci} 900b8a62b91Sopenharmony_ci 901b8a62b91Sopenharmony_ci#[allow(missing_docs)] 902b8a62b91Sopenharmony_ci#[repr(C)] 903b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone)] 904b8a62b91Sopenharmony_cipub struct iovec { 905b8a62b91Sopenharmony_ci pub iov_base: *mut c_void, 906b8a62b91Sopenharmony_ci pub iov_len: usize, 907b8a62b91Sopenharmony_ci} 908b8a62b91Sopenharmony_ci 909b8a62b91Sopenharmony_ci#[allow(missing_docs)] 910b8a62b91Sopenharmony_ci#[repr(C)] 911b8a62b91Sopenharmony_ci#[derive(Debug, Copy, Clone, Default)] 912b8a62b91Sopenharmony_cipub struct open_how { 913b8a62b91Sopenharmony_ci /// An [`OFlags`] value represented as a `u64`. 914b8a62b91Sopenharmony_ci /// 915b8a62b91Sopenharmony_ci /// [`OFlags`]: crate::fs::OFlags 916b8a62b91Sopenharmony_ci pub flags: u64, 917b8a62b91Sopenharmony_ci 918b8a62b91Sopenharmony_ci /// A [`Mode`] value represented as a `u64`. 919b8a62b91Sopenharmony_ci /// 920b8a62b91Sopenharmony_ci /// [`Mode`]: crate::fs::Mode 921b8a62b91Sopenharmony_ci pub mode: u64, 922b8a62b91Sopenharmony_ci 923b8a62b91Sopenharmony_ci pub resolve: crate::fs::ResolveFlags, 924b8a62b91Sopenharmony_ci} 925b8a62b91Sopenharmony_ci 926b8a62b91Sopenharmony_ciimpl Default for off_or_addr2_union { 927b8a62b91Sopenharmony_ci #[inline] 928b8a62b91Sopenharmony_ci fn default() -> Self { 929b8a62b91Sopenharmony_ci let mut s = ::core::mem::MaybeUninit::<Self>::uninit(); 930b8a62b91Sopenharmony_ci // Safety: All of Linux's io_uring structs may be zero-initialized. 931b8a62b91Sopenharmony_ci unsafe { 932b8a62b91Sopenharmony_ci ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); 933b8a62b91Sopenharmony_ci s.assume_init() 934b8a62b91Sopenharmony_ci } 935b8a62b91Sopenharmony_ci } 936b8a62b91Sopenharmony_ci} 937b8a62b91Sopenharmony_ci 938b8a62b91Sopenharmony_ciimpl Default for addr_or_splice_off_in_union { 939b8a62b91Sopenharmony_ci #[inline] 940b8a62b91Sopenharmony_ci fn default() -> Self { 941b8a62b91Sopenharmony_ci let mut s = ::core::mem::MaybeUninit::<Self>::uninit(); 942b8a62b91Sopenharmony_ci // Safety: All of Linux's io_uring structs may be zero-initialized. 943b8a62b91Sopenharmony_ci unsafe { 944b8a62b91Sopenharmony_ci ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); 945b8a62b91Sopenharmony_ci s.assume_init() 946b8a62b91Sopenharmony_ci } 947b8a62b91Sopenharmony_ci } 948b8a62b91Sopenharmony_ci} 949b8a62b91Sopenharmony_ci 950b8a62b91Sopenharmony_ciimpl Default for op_flags_union { 951b8a62b91Sopenharmony_ci #[inline] 952b8a62b91Sopenharmony_ci fn default() -> Self { 953b8a62b91Sopenharmony_ci let mut s = ::core::mem::MaybeUninit::<Self>::uninit(); 954b8a62b91Sopenharmony_ci // Safety: All of Linux's io_uring structs may be zero-initialized. 955b8a62b91Sopenharmony_ci unsafe { 956b8a62b91Sopenharmony_ci ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); 957b8a62b91Sopenharmony_ci s.assume_init() 958b8a62b91Sopenharmony_ci } 959b8a62b91Sopenharmony_ci } 960b8a62b91Sopenharmony_ci} 961b8a62b91Sopenharmony_ci 962b8a62b91Sopenharmony_ciimpl Default for buf_union { 963b8a62b91Sopenharmony_ci #[inline] 964b8a62b91Sopenharmony_ci fn default() -> Self { 965b8a62b91Sopenharmony_ci let mut s = ::core::mem::MaybeUninit::<Self>::uninit(); 966b8a62b91Sopenharmony_ci // Safety: All of Linux's io_uring structs may be zero-initialized. 967b8a62b91Sopenharmony_ci unsafe { 968b8a62b91Sopenharmony_ci ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); 969b8a62b91Sopenharmony_ci s.assume_init() 970b8a62b91Sopenharmony_ci } 971b8a62b91Sopenharmony_ci } 972b8a62b91Sopenharmony_ci} 973b8a62b91Sopenharmony_ci 974b8a62b91Sopenharmony_ciimpl Default for splice_fd_in_or_file_index_union { 975b8a62b91Sopenharmony_ci #[inline] 976b8a62b91Sopenharmony_ci fn default() -> Self { 977b8a62b91Sopenharmony_ci let mut s = ::core::mem::MaybeUninit::<Self>::uninit(); 978b8a62b91Sopenharmony_ci // Safety: All of Linux's io_uring structs may be zero-initialized. 979b8a62b91Sopenharmony_ci unsafe { 980b8a62b91Sopenharmony_ci ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); 981b8a62b91Sopenharmony_ci s.assume_init() 982b8a62b91Sopenharmony_ci } 983b8a62b91Sopenharmony_ci } 984b8a62b91Sopenharmony_ci} 985b8a62b91Sopenharmony_ci 986b8a62b91Sopenharmony_ciimpl Default for register_or_sqe_op_or_sqe_flags_union { 987b8a62b91Sopenharmony_ci #[inline] 988b8a62b91Sopenharmony_ci fn default() -> Self { 989b8a62b91Sopenharmony_ci let mut s = ::core::mem::MaybeUninit::<Self>::uninit(); 990b8a62b91Sopenharmony_ci // Safety: All of Linux's io_uring structs may be zero-initialized. 991b8a62b91Sopenharmony_ci unsafe { 992b8a62b91Sopenharmony_ci ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); 993b8a62b91Sopenharmony_ci s.assume_init() 994b8a62b91Sopenharmony_ci } 995b8a62b91Sopenharmony_ci } 996b8a62b91Sopenharmony_ci} 997b8a62b91Sopenharmony_ci 998b8a62b91Sopenharmony_ci/// Check that our custom structs and unions have the same layout as the 999b8a62b91Sopenharmony_ci/// kernel's versions. 1000b8a62b91Sopenharmony_ci#[test] 1001b8a62b91Sopenharmony_cifn io_uring_layouts() { 1002b8a62b91Sopenharmony_ci use core::mem::{align_of, size_of}; 1003b8a62b91Sopenharmony_ci use memoffset::{offset_of, span_of}; 1004b8a62b91Sopenharmony_ci 1005b8a62b91Sopenharmony_ci // Check that the size and alignment of a type match the `sys` bindings. 1006b8a62b91Sopenharmony_ci macro_rules! check_type { 1007b8a62b91Sopenharmony_ci ($struct:ident) => { 1008b8a62b91Sopenharmony_ci assert_eq!( 1009b8a62b91Sopenharmony_ci (size_of::<$struct>(), align_of::<$struct>()), 1010b8a62b91Sopenharmony_ci (size_of::<sys::$struct>(), align_of::<sys::$struct>()) 1011b8a62b91Sopenharmony_ci ); 1012b8a62b91Sopenharmony_ci }; 1013b8a62b91Sopenharmony_ci } 1014b8a62b91Sopenharmony_ci 1015b8a62b91Sopenharmony_ci // The same as `check_type`, but for unions we've renamed to avoid having 1016b8a62b91Sopenharmony_ci // types like "bindgen_ty_1" in the API. 1017b8a62b91Sopenharmony_ci macro_rules! check_renamed_union { 1018b8a62b91Sopenharmony_ci ($to:ident, $from:ident) => { 1019b8a62b91Sopenharmony_ci assert_eq!( 1020b8a62b91Sopenharmony_ci (size_of::<$to>(), align_of::<$to>()), 1021b8a62b91Sopenharmony_ci (size_of::<sys::$from>(), align_of::<sys::$from>()) 1022b8a62b91Sopenharmony_ci ); 1023b8a62b91Sopenharmony_ci }; 1024b8a62b91Sopenharmony_ci } 1025b8a62b91Sopenharmony_ci 1026b8a62b91Sopenharmony_ci // Check that the field of a struct has the same offset as the 1027b8a62b91Sopenharmony_ci // corresponding field in the `sys` bindings. 1028b8a62b91Sopenharmony_ci macro_rules! check_struct_field { 1029b8a62b91Sopenharmony_ci ($struct:ident, $field:ident) => { 1030b8a62b91Sopenharmony_ci assert_eq!( 1031b8a62b91Sopenharmony_ci offset_of!($struct, $field), 1032b8a62b91Sopenharmony_ci offset_of!(sys::$struct, $field) 1033b8a62b91Sopenharmony_ci ); 1034b8a62b91Sopenharmony_ci assert_eq!(span_of!($struct, $field), span_of!(sys::$struct, $field)); 1035b8a62b91Sopenharmony_ci }; 1036b8a62b91Sopenharmony_ci } 1037b8a62b91Sopenharmony_ci 1038b8a62b91Sopenharmony_ci // The same as `check_struct_field`, but for unions we've renamed to avoid 1039b8a62b91Sopenharmony_ci // having types like "bindgen_ty_1" in the API. 1040b8a62b91Sopenharmony_ci macro_rules! check_struct_renamed_union_field { 1041b8a62b91Sopenharmony_ci ($struct:ident, $to:ident, $from:ident) => { 1042b8a62b91Sopenharmony_ci assert_eq!(offset_of!($struct, $to), offset_of!(sys::$struct, $from)); 1043b8a62b91Sopenharmony_ci assert_eq!(span_of!($struct, $to), span_of!(sys::$struct, $from)); 1044b8a62b91Sopenharmony_ci }; 1045b8a62b91Sopenharmony_ci } 1046b8a62b91Sopenharmony_ci 1047b8a62b91Sopenharmony_ci // For the common case of no renaming, check all fields of a struct. 1048b8a62b91Sopenharmony_ci macro_rules! check_struct { 1049b8a62b91Sopenharmony_ci ($name:ident, $($field:ident),*) => { 1050b8a62b91Sopenharmony_ci // Check the size and alignment. 1051b8a62b91Sopenharmony_ci check_type!($name); 1052b8a62b91Sopenharmony_ci 1053b8a62b91Sopenharmony_ci // Check that we have all the fields. 1054b8a62b91Sopenharmony_ci let _test = $name { 1055b8a62b91Sopenharmony_ci // Safety: All of io_uring's types can be zero-initialized. 1056b8a62b91Sopenharmony_ci $($field: unsafe { core::mem::zeroed() }),* 1057b8a62b91Sopenharmony_ci }; 1058b8a62b91Sopenharmony_ci 1059b8a62b91Sopenharmony_ci // Check that the fields have the right sizes and offsets. 1060b8a62b91Sopenharmony_ci $(check_struct_field!($name, $field));* 1061b8a62b91Sopenharmony_ci }; 1062b8a62b91Sopenharmony_ci } 1063b8a62b91Sopenharmony_ci 1064b8a62b91Sopenharmony_ci check_renamed_union!(off_or_addr2_union, io_uring_sqe__bindgen_ty_1); 1065b8a62b91Sopenharmony_ci check_renamed_union!(addr_or_splice_off_in_union, io_uring_sqe__bindgen_ty_2); 1066b8a62b91Sopenharmony_ci check_renamed_union!(op_flags_union, io_uring_sqe__bindgen_ty_3); 1067b8a62b91Sopenharmony_ci check_renamed_union!(buf_union, io_uring_sqe__bindgen_ty_4); 1068b8a62b91Sopenharmony_ci check_renamed_union!(splice_fd_in_or_file_index_union, io_uring_sqe__bindgen_ty_5); 1069b8a62b91Sopenharmony_ci check_renamed_union!( 1070b8a62b91Sopenharmony_ci register_or_sqe_op_or_sqe_flags_union, 1071b8a62b91Sopenharmony_ci io_uring_restriction__bindgen_ty_1 1072b8a62b91Sopenharmony_ci ); 1073b8a62b91Sopenharmony_ci 1074b8a62b91Sopenharmony_ci check_type!(io_uring_sqe); 1075b8a62b91Sopenharmony_ci check_struct_field!(io_uring_sqe, opcode); 1076b8a62b91Sopenharmony_ci check_struct_field!(io_uring_sqe, flags); 1077b8a62b91Sopenharmony_ci check_struct_field!(io_uring_sqe, ioprio); 1078b8a62b91Sopenharmony_ci check_struct_field!(io_uring_sqe, fd); 1079b8a62b91Sopenharmony_ci check_struct_renamed_union_field!(io_uring_sqe, off_or_addr2, __bindgen_anon_1); 1080b8a62b91Sopenharmony_ci check_struct_renamed_union_field!(io_uring_sqe, addr_or_splice_off_in, __bindgen_anon_2); 1081b8a62b91Sopenharmony_ci check_struct_field!(io_uring_sqe, len); 1082b8a62b91Sopenharmony_ci check_struct_renamed_union_field!(io_uring_sqe, op_flags, __bindgen_anon_3); 1083b8a62b91Sopenharmony_ci check_struct_field!(io_uring_sqe, user_data); 1084b8a62b91Sopenharmony_ci check_struct_renamed_union_field!(io_uring_sqe, buf, __bindgen_anon_4); 1085b8a62b91Sopenharmony_ci check_struct_field!(io_uring_sqe, personality); 1086b8a62b91Sopenharmony_ci check_struct_renamed_union_field!(io_uring_sqe, splice_fd_in_or_file_index, __bindgen_anon_5); 1087b8a62b91Sopenharmony_ci check_struct_field!(io_uring_sqe, __pad2); 1088b8a62b91Sopenharmony_ci 1089b8a62b91Sopenharmony_ci check_type!(io_uring_restriction); 1090b8a62b91Sopenharmony_ci check_struct_field!(io_uring_restriction, opcode); 1091b8a62b91Sopenharmony_ci check_struct_renamed_union_field!( 1092b8a62b91Sopenharmony_ci io_uring_restriction, 1093b8a62b91Sopenharmony_ci register_or_sqe_op_or_sqe_flags, 1094b8a62b91Sopenharmony_ci __bindgen_anon_1 1095b8a62b91Sopenharmony_ci ); 1096b8a62b91Sopenharmony_ci check_struct_field!(io_uring_restriction, resv); 1097b8a62b91Sopenharmony_ci check_struct_field!(io_uring_restriction, resv2); 1098b8a62b91Sopenharmony_ci 1099b8a62b91Sopenharmony_ci check_struct!(io_uring_cqe, user_data, res, flags); 1100b8a62b91Sopenharmony_ci check_struct!( 1101b8a62b91Sopenharmony_ci io_uring_params, 1102b8a62b91Sopenharmony_ci sq_entries, 1103b8a62b91Sopenharmony_ci cq_entries, 1104b8a62b91Sopenharmony_ci flags, 1105b8a62b91Sopenharmony_ci sq_thread_cpu, 1106b8a62b91Sopenharmony_ci sq_thread_idle, 1107b8a62b91Sopenharmony_ci features, 1108b8a62b91Sopenharmony_ci wq_fd, 1109b8a62b91Sopenharmony_ci resv, 1110b8a62b91Sopenharmony_ci sq_off, 1111b8a62b91Sopenharmony_ci cq_off 1112b8a62b91Sopenharmony_ci ); 1113b8a62b91Sopenharmony_ci check_struct!( 1114b8a62b91Sopenharmony_ci io_sqring_offsets, 1115b8a62b91Sopenharmony_ci head, 1116b8a62b91Sopenharmony_ci tail, 1117b8a62b91Sopenharmony_ci ring_mask, 1118b8a62b91Sopenharmony_ci ring_entries, 1119b8a62b91Sopenharmony_ci flags, 1120b8a62b91Sopenharmony_ci dropped, 1121b8a62b91Sopenharmony_ci array, 1122b8a62b91Sopenharmony_ci resv1, 1123b8a62b91Sopenharmony_ci resv2 1124b8a62b91Sopenharmony_ci ); 1125b8a62b91Sopenharmony_ci check_struct!( 1126b8a62b91Sopenharmony_ci io_cqring_offsets, 1127b8a62b91Sopenharmony_ci head, 1128b8a62b91Sopenharmony_ci tail, 1129b8a62b91Sopenharmony_ci ring_mask, 1130b8a62b91Sopenharmony_ci ring_entries, 1131b8a62b91Sopenharmony_ci overflow, 1132b8a62b91Sopenharmony_ci cqes, 1133b8a62b91Sopenharmony_ci flags, 1134b8a62b91Sopenharmony_ci resv1, 1135b8a62b91Sopenharmony_ci resv2 1136b8a62b91Sopenharmony_ci ); 1137b8a62b91Sopenharmony_ci check_struct!(io_uring_probe, last_op, ops_len, resv, resv2, ops); 1138b8a62b91Sopenharmony_ci check_struct!(io_uring_probe_op, op, resv, flags, resv2); 1139b8a62b91Sopenharmony_ci check_struct!(io_uring_files_update, offset, resv, fds); 1140b8a62b91Sopenharmony_ci check_struct!(io_uring_rsrc_register, nr, resv, resv2, data, tags); 1141b8a62b91Sopenharmony_ci check_struct!(io_uring_rsrc_update, offset, resv, data); 1142b8a62b91Sopenharmony_ci check_struct!(io_uring_rsrc_update2, offset, resv, data, tags, nr, resv2); 1143b8a62b91Sopenharmony_ci check_struct!(io_uring_getevents_arg, sigmask, sigmask_sz, pad, ts); 1144b8a62b91Sopenharmony_ci check_struct!(iovec, iov_base, iov_len); 1145b8a62b91Sopenharmony_ci check_struct!(open_how, flags, mode, resolve); 1146b8a62b91Sopenharmony_ci} 1147